diff --git a/.gitignore b/.gitignore index d684262f9d..8f461f2b02 100644 --- a/.gitignore +++ b/.gitignore @@ -161,4 +161,4 @@ version.h geos_c.h source/libs/parser/src/sql.c include/common/ttokenauto.h - +!packaging/smokeTest/pytest_require.txt diff --git a/Jenkinsfile2 b/Jenkinsfile2 index a9c829660a..7ba9b4a933 100644 --- a/Jenkinsfile2 +++ b/Jenkinsfile2 @@ -1,9 +1,11 @@ import hudson.model.Result import hudson.model.*; import jenkins.model.CauseOfInterruption -docs_only=0 node { } +file_zh_changed = '' +file_en_changed = '' +file_no_doc_changed = '' def abortPreviousBuilds() { def currentJobName = env.JOB_NAME def currentBuildNumber = env.BUILD_NUMBER.toInteger() @@ -29,7 +31,7 @@ def abort_previous(){ if (buildNumber > 1) milestone(buildNumber - 1) milestone(buildNumber) } -def check_docs() { +def check_docs(){ if (env.CHANGE_URL =~ /\/TDengine\//) { sh ''' hostname @@ -40,39 +42,94 @@ def check_docs() { cd ${WKC} git reset --hard git clean -f - rm -rf examples/rust/ git remote prune origin git fetch - ''' - script { - sh ''' - cd ${WKC} - git checkout ''' + env.CHANGE_TARGET + ''' - ''' - } - sh ''' - cd ${WKC} - git remote prune origin + git checkout ''' + env.CHANGE_TARGET + ''' git pull >/dev/null git fetch origin +refs/pull/${CHANGE_ID}/merge - git checkout -qf FETCH_HEAD + git checkout -qf FETCH_HEAD ''' - def file_changed = sh ( + + file_zh_changed = sh ( script: ''' cd ${WKC} - git --no-pager diff --name-only FETCH_HEAD `git merge-base FETCH_HEAD ${CHANGE_TARGET}`|grep -v "^docs/en/"|grep -v "^docs/zh/" || : + git --no-pager diff --name-only FETCH_HEAD `git merge-base FETCH_HEAD ${CHANGE_TARGET}`|grep "^docs/zh/" || : + ''', + returnStdout: true + ) + + file_en_changed = sh ( + script: ''' + cd ${WKC} + git --no-pager diff --name-only FETCH_HEAD `git merge-base FETCH_HEAD ${CHANGE_TARGET}`|grep "^docs/en/" || : + ''', + returnStdout: true + ) + + file_no_doc_changed = sh ( + script: ''' + cd ${WKC} + git --no-pager diff --name-only FETCH_HEAD `git merge-base FETCH_HEAD ${CHANGE_TARGET}`|grep -v "^docs/en/"|grep -v "^docs/zh/"|grep -v "*.md" || : ''', returnStdout: true ).trim() - if (file_changed == '') { - echo "docs PR" - docs_only=1 - } else { - echo file_changed - } - env.FILE_CHANGED = file_changed + echo "file_zh_changed: ${file_zh_changed}" + echo "file_en_changed: ${file_en_changed}" + echo "file_no_doc_changed: ${file_no_doc_changed}" } } + +def build_pre_docs(){ + if (env.CHANGE_URL =~ /\/TDengine\//) { + sh ''' + hostname + date + env + ''' + + sh ''' + cd ${DOC_WKC}/${td_repo} + git reset --hard + git clean -f + git remote prune origin + git fetch + git checkout ''' + env.CHANGE_TARGET + ''' + git pull >/dev/null + git fetch origin +refs/pull/${CHANGE_ID}/merge + git checkout -qf FETCH_HEAD + ''' + + sh ''' + cd ${DOC_WKC}/${tools_repo} + git reset --hard + git clean -f + git fetch + git remote prune origin + git checkout ''' + env.CHANGE_TARGET + ''' + git pull >/dev/null + ''' + } +} + +def build_zh_docs(){ + sh ''' + cd ${DOC_WKC}/${zh_doc_repo} + # git pull + yarn ass local + yarn build + ''' +} + +def build_en_docs(){ + sh ''' + cd ${DOC_WKC}/${en_doc_repo} + # git pull + yarn ass local + yarn build + ''' +} + + def pre_test(){ sh ''' hostname @@ -153,6 +210,7 @@ def pre_test(){ ''' return 1 } + def pre_test_build_mac() { sh ''' hostname @@ -173,6 +231,7 @@ def pre_test_build_mac() { date ''' } + def pre_test_win(){ bat ''' hostname @@ -273,17 +332,8 @@ def pre_test_win(){ cd %WIN_COMMUNITY_ROOT% git submodule update --init --recursive ''' - bat ''' - cd %WIN_CONNECTOR_ROOT% - git branch - git reset --hard - git pull - ''' - bat ''' - cd %WIN_CONNECTOR_ROOT% - git log -5 - ''' } + def pre_test_build_win() { bat ''' echo "building ..." @@ -303,16 +353,14 @@ def pre_test_build_win() { time /t ''' bat ''' - cd %WIN_CONNECTOR_ROOT% - python.exe -m pip install --upgrade pip - python -m pip uninstall taospy -y - python -m pip install taospy==2.7.16 - python -m pip uninstall taos-ws-py -y - python -m pip install taos-ws-py==0.3.3 + cd %WIN_COMMUNITY_ROOT%/tests/ci + pip3 install taospy==2.7.16 + pip3 install taos-ws-py==0.3.3 xcopy /e/y/i/f %WIN_INTERNAL_ROOT%\\debug\\build\\lib\\taos.dll C:\\Windows\\System32 ''' return 1 } + def run_win_ctest() { bat ''' echo "windows ctest ..." @@ -322,10 +370,10 @@ def run_win_ctest() { time /t ''' } + def run_win_test() { bat ''' echo "windows test ..." - cd %WIN_CONNECTOR_ROOT% xcopy /e/y/i/f %WIN_INTERNAL_ROOT%\\debug\\build\\lib\\taos.dll C:\\Windows\\System32 ls -l C:\\Windows\\System32\\taos.dll time /t @@ -343,29 +391,67 @@ pipeline { WKDIR = '/var/lib/jenkins/workspace' WK = '/var/lib/jenkins/workspace/TDinternal' WKC = '/var/lib/jenkins/workspace/TDinternal/community' - WKPY = '/var/lib/jenkins/workspace/taos-connector-python' + DOC_WKC = '/root/doc_ci_work' + td_repo = 'TDengine' + zh_doc_repo = 'docs.taosdata.com' + en_doc_repo = 'docs.tdengine.com' + tools_repo = 'taos-tools' } stages { - stage('check') { + stage ('check doc file changed') { + agent{label " slave1_47 || slave1_48 || slave1_49 || slave1_50 || slave1_52 || slave1_59 || slave1_63 || worker03 || slave215 || slave217 || slave219 || Mac_catalina "} + steps { + check_docs() + } + } + + stage ('pre for build docs') { when { - allOf { - not { expression { env.CHANGE_BRANCH =~ /docs\// }} - } + beforeAgent true + expression { env.CHANGE_BRANCH =~ /(?i)doc.*/ || file_zh_changed != '' || file_en_changed != '' } + } + agent{label "doc_build_0_30"} + steps { + build_pre_docs() + } + } + + stage('build Docs') { + when { + beforeAgent true + expression { env.CHANGE_BRANCH =~ /(?i)doc.*/ || file_zh_changed != '' || file_en_changed != '' } } parallel { - stage('check docs') { - agent{label " slave1_47 || slave1_48 || slave1_49 || slave1_50 || slave1_52 || slave1_59 || slave1_63 || worker03 || slave215 || slave217 || slave219 || Mac_catalina "} + stage('build zh docs') { + agent{label "doc_build_0_30"} + when { + expression { file_zh_changed != '' } + } steps { - check_docs() + build_zh_docs() + } + } + stage('build en docs') { + agent{label "doc_build_0_30"} + when { + expression { file_en_changed != '' } + } + steps { + build_en_docs() } } } + post { + unsuccessful { + error('build docs stage failed, terminating pipeline.') + } + } } + stage('run test') { when { allOf { - not { expression { env.CHANGE_BRANCH =~ /docs\// }} - expression { docs_only == 0 } + not { expression { file_no_doc_changed == '' }} } } parallel { @@ -375,7 +461,6 @@ pipeline { WIN_INTERNAL_ROOT="C:\\workspace\\${env.EXECUTOR_NUMBER}\\TDinternal" WIN_COMMUNITY_ROOT="C:\\workspace\\${env.EXECUTOR_NUMBER}\\TDinternal\\community" WIN_SYSTEM_TEST_ROOT="C:\\workspace\\${env.EXECUTOR_NUMBER}\\TDinternal\\community\\tests\\system-test" - WIN_CONNECTOR_ROOT="C:\\workspace\\${env.EXECUTOR_NUMBER}\\taos-connector-python" } steps { catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') { @@ -420,7 +505,7 @@ pipeline { script { sh ''' mkdir -p ${WKDIR}/tmp/${BRANCH_NAME}_${BUILD_ID} - echo "''' + env.FILE_CHANGED + '''" > ${WKDIR}/tmp/${BRANCH_NAME}_${BUILD_ID}/docs_changed.txt + echo "''' + file_no_doc_changed + '''" > ${WKDIR}/tmp/${BRANCH_NAME}_${BUILD_ID}/docs_changed.txt ''' sh ''' cd ${WKC}/tests/parallel_test @@ -570,4 +655,4 @@ pipeline { ) } } -} +} \ No newline at end of file diff --git a/cmake/cmake.version b/cmake/cmake.version index c600c084fd..710ff87fe0 100644 --- a/cmake/cmake.version +++ b/cmake/cmake.version @@ -2,7 +2,7 @@ IF (DEFINED VERNUMBER) SET(TD_VER_NUMBER ${VERNUMBER}) ELSE () - SET(TD_VER_NUMBER "3.3.4.0.alpha") + SET(TD_VER_NUMBER "3.3.4.3.alpha") ENDIF () IF (DEFINED VERCOMPATIBLE) diff --git a/docs/en/14-reference/03-taos-sql/10-function.md b/docs/en/14-reference/03-taos-sql/10-function.md index d2efd668b0..f6c1ef24d0 100644 --- a/docs/en/14-reference/03-taos-sql/10-function.md +++ b/docs/en/14-reference/03-taos-sql/10-function.md @@ -1149,7 +1149,7 @@ TOP(expr, k) UNIQUE(expr) ``` -**Description**: The values that occur the first time in the specified column. The effect is similar to `distinct` keyword. For a table with composite primary key, only the data with the smallest primary key value is returned. +**Description**: Return the unique values of this column. The effect is similar to `distinct` keyword. Return the row with the earliest timestamp for duplicate data. For a table with composite primary key, only the data with the smallest primary key value is returned. **Return value type**:Same as the data type of the column being operated upon diff --git a/docs/en/28-releases/01-tdengine.md b/docs/en/28-releases/01-tdengine.md index 486fe2c015..b24931b166 100644 --- a/docs/en/28-releases/01-tdengine.md +++ b/docs/en/28-releases/01-tdengine.md @@ -20,6 +20,10 @@ For TDengine 2.x installation packages by version, please visit [here](https://t import Release from "/components/ReleaseV3"; +## 3.3.4.3 + + + ## 3.3.3.0 diff --git a/docs/zh/06-advanced/03-stream.md b/docs/zh/06-advanced/03-stream.md index 7486b3b043..c47831dde3 100644 --- a/docs/zh/06-advanced/03-stream.md +++ b/docs/zh/06-advanced/03-stream.md @@ -228,4 +228,35 @@ PAUSE STREAM [IF EXISTS] stream_name; RESUME STREAM [IF EXISTS] [IGNORE UNTREATED] stream_name; ``` -没有指定 IF EXISTS,如果该 stream 不存在,则报错。如果存在,则恢复流计算。指定了 IF EXISTS,如果 stream 不存在,则返回成功。如果存在,则恢复流计算。如果指定 IGNORE UNTREATED,则恢复流计算时,忽略流计算暂停期间写入的数据。 \ No newline at end of file +没有指定 IF EXISTS,如果该 stream 不存在,则报错。如果存在,则恢复流计算。指定了 IF EXISTS,如果 stream 不存在,则返回成功。如果存在,则恢复流计算。如果指定 IGNORE UNTREATED,则恢复流计算时,忽略流计算暂停期间写入的数据。 + +### 流计算升级故障恢复 + +升级 TDengine 后,如果流计算不兼容,需要删除流计算,然后重新创建流计算。步骤如下: + +1.修改 taos.cfg,添加 disableStream 1 + +2.重启 taosd。如果启动失败,修改 stream 目录的名称,避免 taosd 启动的时候尝试加载 stream 目录下的流计算数据信息。不使用删除操作避免误操作导致的风险。需要修改的文件夹:$dataDir/vnode/vnode*/tq/stream,$dataDir 指 TDengine 存储数据的目录,在 $dataDir/vnode/ 目录下会有多个类似 vnode1 、vnode2...vnode* 的目录,全部需要修改里面的 tq/stream 目录的名字,改为 tq/stream.bk + +3.启动 taos + +```sql +drop stream xxxx; ---- xxx 指stream name +flush database stream_source_db; ---- 流计算读取数据的超级表所在的 database +flush database stream_dest_db; ---- 流计算写入数据的超级表所在的 database +``` + +举例: + +```sql +create stream streams1 into test1.streamst as select _wstart, count(a) c1 from test.st interval(1s) ; +drop database streams1; +flush database test; +flush database test1; +``` + +4.关闭 taosd + +5.修改 taos.cfg,去掉 disableStream 1,或将 disableStream 改为 0 + +6.启动 taosd \ No newline at end of file diff --git a/docs/zh/07-develop/07-tmq.md b/docs/zh/07-develop/07-tmq.md index a91a764c67..8b272bdfff 100644 --- a/docs/zh/07-develop/07-tmq.md +++ b/docs/zh/07-develop/07-tmq.md @@ -16,7 +16,7 @@ TDengine 提供了类似于消息队列产品的数据订阅和消费接口。 **注意** 在 TDengine 连接器实现中,对于订阅查询,有以下限制。 -- 查询语句限制:订阅查询只能使用 select 语句,不支持其他类型的SQL,如 insert、update 或 delete 等。 +- 查询语句限制:订阅查询只能使用 select 语句,并不支持其他类型的SQL,如订阅库,订阅超级表(非 select 方式),insert、update 或 delete 等。 - 原始始数据查询:订阅查询只能查询原始数据,而不能查询聚合或计算结果。 - 时间顺序限制:订阅查询只能按照时间正序查询数据。 diff --git a/docs/zh/08-operation/06-gui.md b/docs/zh/08-operation/06-gui.md index bb99b2cf43..cdf19b3ac1 100644 --- a/docs/zh/08-operation/06-gui.md +++ b/docs/zh/08-operation/06-gui.md @@ -165,6 +165,10 @@ toc_max_heading_level: 4 第一步 填写添加新主题需要的信息,点击“创建”按钮; ![topic-03-addTopicWizard.jpeg](./pic/topic-03-addTopicWizard.jpeg "添加新主题 Wizard 页面") +如上图,您可以选择是否 “同步 meta”。如果同步 meta 信息,则可以订阅到 meta 信息,比如增加或者删除超级表。 + +您需要根据使用场景来选择是否开启,如果您引用 taos 连接器编写业务代码订阅 topic,则不能开启“同步 meta”,只能订阅数据;如果您创建 topic 在 explorer 配置同步任务使用,则可以开启“同步 meta”。 + 第二步 页面出现以下记录,则证明创建成功。 ![topic-05-addTopicSucc1.jpeg](./pic/topic-05-addTopicSucc1.jpeg "查看已创建的流计算") diff --git a/docs/zh/08-operation/16-security.md b/docs/zh/08-operation/16-security.md index 4f47a644f7..e3cd72d9dc 100644 --- a/docs/zh/08-operation/16-security.md +++ b/docs/zh/08-operation/16-security.md @@ -26,6 +26,22 @@ SHOW USERS; ```sql ALTER USER TEST DROP HOST HOST_NAME1 ``` +说明 +- 开源版和企业版本都能添加成功,且可以查询到,但是开源版本不会对 IP 做任何限制。 +- create user u_write pass 'taosdata1' host 'iprange1','iprange2', 可以一次添加多个 iprange, 服务端会做去重,去重的逻辑是需要 iprange 完全一样 +- 默认会把 127.0.0.1 添加到白名单列表,且在白名单列表可以查询 +- 集群的节点 IP 集合会自动添加到白名单列表,但是查询不到。 +- taosadaper 和 taosd 不在一个机器的时候,需要把 taosadaper IP 手动添加到 taosd 白名单列表中 +- 集群情况下,各个节点 enableWhiteList 成一样,或者全为 false,或者全为 true, 要不然集群无法启动 +- 白名单变更生效时间 1s,不超过 2s, 每次变更对收发性能有些微影响(多一次判断,可以忽略),变更完之后、影响忽略不计, 变更过程中对集群没有影响,对正在访问客户端也没有影响(假设这些客户端的 IP 包含在 white list 内) +- 如果添加两个 ip range, 192.168.1.1/16(假设为 A), 192.168.1.1/24(假设为 B), 严格来说,A 包含了 B,但是考虑情况太复杂,并不会对 A 和 B 做合并 +- 要删除的时候,必须严格匹配。 也就是如果添加的是 192.168.1.1/24, 要删除也是 192.168.1.1/24 +- 只有 root 才有权限对其他用户增删 ip white list +- 兼容之前的版本,但是不支持从当前版本回退到之前版本 +- x.x.x.x/32 和 x.x.x.x 属于同一个 iprange, 显示为 x.x.x.x +- 如果客户端拿到的 0.0.0.0/0, 说明没有开启白名单 +- 如果白名单发生了改变, 客户端会在 heartbeat 里检测到。 +- 针对一个 user, 添加的 IP 个数上限是 2048 ## 审计日志 diff --git a/docs/zh/08-operation/pic/topic-03-addTopicWizard.jpeg b/docs/zh/08-operation/pic/topic-03-addTopicWizard.jpeg index e227d161ce..841c0e95ee 100644 Binary files a/docs/zh/08-operation/pic/topic-03-addTopicWizard.jpeg and b/docs/zh/08-operation/pic/topic-03-addTopicWizard.jpeg differ diff --git a/docs/zh/14-reference/01-components/01-taosd.md b/docs/zh/14-reference/01-components/01-taosd.md index 89a97b108d..64ae69528b 100644 --- a/docs/zh/14-reference/01-components/01-taosd.md +++ b/docs/zh/14-reference/01-components/01-taosd.md @@ -26,42 +26,66 @@ taosd 命令行参数如下 ::: ### 连接相关 - -| 参数名称 | 参数说明 | -| :--------------------: | :-------------------------------------------------------------------------------------: | -| firstEp | taosd 启动时,主动连接的集群中首个 dnode 的 end point,缺省值:localhost:6030 | -| secondEp | taosd 启动时,如果 firstEp 连接不上,尝试连接集群中第二个 dnode 的 endpoint,缺省值:无 | -| fqdn | 启动 taosd 后所监听的服务地址,缺省值:所在服务器上配置的第一个 hostname | -| serverPort | 启动 taosd 后所监听的端口,缺省值:6030 | -| numOfRpcSessions | 允许一个 dnode 能发起的最大连接数,取值范围 100-100000,缺省值:30000 | -| timeToGetAvailableConn | 获得可用连接的最长等待时间,取值范围 10-50000000,单位为毫秒,缺省值:500000 | +|参数名称|支持版本|参数含义| +|-----------------------|----------|-| +|firstEp | |taosd 启动时,主动连接的集群中首个 dnode 的 end point,默认值 localhost:6030| +|secondEp | |taosd 启动时,如果 firstEp 连接不上,尝试连接集群中第二个 dnode 的 endpoint,无默认值| +|fqdn | |taosd 监听的服务地址,默认为所在服务器上配置的第一个 hostname| +|serverPort | |taosd 监听的端口,默认值 6030| +|compressMsgSize | |是否对 RPC 消息进行压缩;-1:所有消息都不压缩;0:所有消息都压缩;N (N>0):只有大于 N 个字节的消息才压缩;默认值 -1| +|shellActivityTimer | |客户端向 mnode 发送心跳的时长,单位为秒,取值范围 1-120,默认值 3| +|numOfRpcSessions | |RPC 支持的最大连接数,取值范围 100-100000,默认值 30000| +|numOfRpcThreads | |RPC 线程数目,默认值为 CPU 核数的一半| +|numOfTaskQueueThreads | |dnode 处理 RPC 消息的线程数| +|statusInterval | |dnode 与 mnode 之间的心跳间隔| +|rpcQueueMemoryAllowed | |dnode 允许的 rpc 消息占用的内存最大值,单位 bytes,取值范围 104857600-INT64_MAX,默认值 服务器内存的 1/10 | +|resolveFQDNRetryTime | |FQDN 解析失败时的重试次数| +|timeToGetAvailableConn | |获得可用连接的最长等待时间,取值范围 10-50000000,单位为毫秒,默认值 500000| +|maxShellConns | |允许创建的最大链接数| +|maxRetryWaitTime | |重连最大超时时间| +|shareConnLimit |3.3.4.3 后|内部参数,一个链接可以共享的查询数目,取值范围 1-256,默认值 10| +|readTimeout |3.3.4.3 后|内部参数,最小超时时间,取值范围 64-604800,单位为秒,默认值 900| ### 监控相关 -| 参数名称 | 参数说明 | -| :----------------: | :------------------------------------------------------------------------------------: | -| monitor | 是否收集监控数据并上报,0: 关闭;1:打开;缺省值:0 | -| monitorFqdn | taosKeeper 服务所在服务器的 FQDN,缺省值:无 | -| monitorPort | taosKeeper 服务所监听的端口号,缺省值:6043 | -| monitorInternal | 监控数据库记录系统参数(CPU/内存)的时间间隔,单位是秒,取值范围 1-200000 ,缺省值:30 | -| telemetryReporting | 是否上传 telemetry,0: 不上传,1:上传,缺省值:1 | -| crashReporting | 是否上传 crash 信息;0: 不上传,1: 上传;缺省值: 1 | +|参数名称|支持版本|参数含义| +|-----------------------|----------|-| +|monitor | |是否收集监控数据并上报,0:关闭;1:打开;默认值 0| +|monitorFqdn | |taosKeeper 服务所在服务器的 FQDN,默认值 无| +|monitorPort | |taosKeeper 服务所监听的端口号,默认值 6043| +|monitorInterval | |监控数据库记录系统参数(CPU/内存)的时间间隔,单位是秒,取值范围 1-200000 ,默认值 30| +|monitorMaxLogs | |缓存的待上报日志条数| +|monitorComp | |是否采用压缩方式上报监控日志时| +|monitorLogProtocol | |是否打印监控日志| +|monitorForceV2 | |是否使用 V2 版本协议上报| +|telemetryReporting | |是否上传 telemetry,0:不上传,1:上传,默认值 1| +|telemetryServer | |telemetry 服务器地址| +|telemetryPort | |telemetry 服务器端口编号| +|telemetryInterval | |telemetry 上传时间间隔,单位为秒,默认 43200| +|crashReporting | |是否上传 crash 信息;0:不上传,1:上传;默认值 1| ### 查询相关 - -| 参数名称 | 参数说明 | -| :--------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | -| queryPolicy | 查询策略,1: 只使用 vnode,不使用 qnode; 2: 没有扫描算子的子任务在 qnode 执行,带扫描算子的子任务在 vnode 执行; 3: vnode 只运行扫描算子,其余算子均在 qnode 执行 ;4: 使用客户端聚合模式;缺省值:1 | -| maxNumOfDistinctRes | 允许返回的 distinct 结果最大行数,默认值 10 万,最大允许值 1 亿 | -| countAlwaysReturnValue | count/hyperloglog函数在输入数据为空或者NULL的情况下是否返回值,0: 返回空行,1: 返回;该参数设置为 1 时,如果查询中含有 INTERVAL 子句或者该查询使用了TSMA时, 且相应的组或窗口内数据为空或者NULL, 对应的组或窗口将不返回查询结果. 注意此参数客户端和服务端值应保持一致. | - +|参数名称|支持版本|参数含义| +|------------------------|----------|-| +|countAlwaysReturnValue | |count/hyperloglog 函数在输入数据为空或者 NULL 的情况下是否返回值;0:返回空行,1:返回;默认值 1;该参数设置为 1 时,如果查询中含有 INTERVAL 子句或者该查询使用了 TSMA 时,且相应的组或窗口内数据为空或者 NULL,对应的组或窗口将不返回查询结果;注意此参数客户端和服务端值应保持一致| +|tagFilterCache | |是否缓存标签过滤结果| +|maxNumOfDistinctRes | |允许返回的 distinct 结果最大行数,默认值 10 万,最大允许值 1 亿| +|queryBufferSize | |暂不生效| +|queryRspPolicy | |查询响应策略| +|filterScalarMode | |强制使用标量过滤模式,0:关闭;1:开启,默认值 0| +|queryPlannerTrace | |内部参数,查询计划是否输出详细日志| +|queryNodeChunkSize | |内部参数,查询计划的块大小| +|queryUseNodeAllocator | |内部参数,查询计划的分配方法| +|queryMaxConcurrentTables| |内部参数,查询计划的并发数目| +|queryRsmaTolerance | |内部参数,用于判定查询哪一级 rsma 数据时的容忍时间,单位为毫秒| +|enableQueryHb | |内部参数,是否发送查询心跳消息| +|pqSortMemThreshold | |内部参数,排序使用的内存阈值| ### 区域相关 - -| 参数名称 | 参数说明 | -| :------: | :------------------------------------------------------------------------------------------------------: | -| timezone | 时区,缺省值:当前服务器所配置的时区 | -| locale | 系统区位信息及编码格式 ,缺省值:系统中动态获取,如果自动获取失败,需要用户在配置文件设置或通过 API 设置 | -| charset | 字符集编码,缺省值:系统自动获取 | +|参数名称|支持版本|参数含义| +|-----------------|----------|-| +|timezone | |时区;缺省从系统中动态获取当前的时区设置| +|locale | |系统区位信息及编码格式,缺省从系统中获取| +|charset | |字符集编码,缺省从系统中获取| :::info 1. 为应对多时区的数据写入和查询问题,TDengine 采用 Unix 时间戳(Unix Timestamp)来记录和存储时间戳。Unix 时间戳的特点决定了任一时刻不论在任何时区,产生的时间戳均一致。需要注意的是,Unix 时间戳是在客户端完成转换和记录。为了确保客户端其他形式的时间转换为正确的 Unix 时间戳,需要设置正确的时区。 @@ -101,7 +125,7 @@ SELECT count(*) FROM table_name WHERE TS<1554984068000; 客户端的输入的字符均采用操作系统当前默认的编码格式,在 Linux/macOS 系统上多为 UTF-8,部分中文系统编码则可能是 GB18030 或 GBK 等。在 docker 环境中默认的编码是 POSIX。在中文版 Windows 系统中,编码则是 CP936。客户端需要确保正确设置自己所使用的字符集,即客户端运行的操作系统当前编码字符集,才能保证 nchar 中的数据正确转换为 UCS4-LE 编码格式。 -在 Linux/macOS 中 locale 的命名规则为: \<语言>_\<地区>.\<字符集编码> 如:zh_CN.UTF-8,zh 代表中文,CN 代表大陆地区,UTF-8 表示字符集。字符集编码为客户端正确解析本地字符串提供编码转换的说明。Linux/macOS 可以通过设置 locale 来确定系统的字符编码,由于 Windows 使用的 locale 中不是 POSIX 标准的 locale 格式,因此在 Windows 下需要采用另一个配置参数 charset 来指定字符编码。在 Linux/macOS 中也可以使用 charset 来指定字符编码。 +在 Linux/macOS 中 locale 的命名规则为:\<语言>_\<地区>.\<字符集编码> 如:zh_CN.UTF-8,zh 代表中文,CN 代表大陆地区,UTF-8 表示字符集。字符集编码为客户端正确解析本地字符串提供编码转换的说明。Linux/macOS 可以通过设置 locale 来确定系统的字符编码,由于 Windows 使用的 locale 中不是 POSIX 标准的 locale 格式,因此在 Windows 下需要采用另一个配置参数 charset 来指定字符编码。在 Linux/macOS 中也可以使用 charset 来指定字符编码。 3. 如果配置文件中不设置 charset,在 Linux/macOS 中,taos 在启动时候,自动读取系统当前的 locale 信息,并从 locale 信息中解析提取 charset 编码格式。如果自动读取 locale 信息失败,则尝试读取 charset 配置,如果读取 charset 配置也失败,则中断启动过程。 @@ -139,73 +163,148 @@ charset 的有效值是 UTF-8。 ::: ### 存储相关 - -| 参数名称 | 参数说明 | -| :--------------: | :--------------------------------------------------------------------: | -| dataDir | 数据文件目录,所有的数据文件都将写入该目录,缺省值:/var/lib/taos | -| tempDir | 指定所有系统运行过程中的临时文件生成的目录,缺省值:/tmp | -| minimalTmpDirGB | tempDir 所指定的临时文件目录所需要保留的最小空间,单位 GB,缺省值: 1 | -| minimalDataDirGB | dataDir 指定的时序数据存储目录所需要保留的最小空间,单位 GB,缺省值: 2 | +|参数名称|支持版本|参数含义| +|--------------------|----------|-| +|dataDir | |数据文件目录,所有的数据文件都将写入该目录,默认值 /var/lib/taos| +|tempDir | |指定所有系统运行过程中的临时文件生成的目录,默认值 /tmp| +|minimalDataDirGB | |dataDir 指定的时序数据存储目录所需要保留的最小空间,单位 GB,默认值 2| +|minimalTmpDirGB | |tempDir 所指定的临时文件目录所需要保留的最小空间,单位 GB,默认值 1| +|minDiskFreeSize |3.1.1.0 后|当某块磁盘上的可用空间小于等于这个阈值时,该磁盘将不再被选择用于生成新的数据文件,单位为字节,取值范围 52428800-1073741824,默认值为 52428800;企业版参数| +|s3MigrateIntervalSec|3.3.4.3 后|本地数据文件自动上传 S3 的触发周期,单位为秒。最小值:600;最大值:100000。默认值 3600;企业版参数| +|s3MigrateEnabled |3.3.4.3 后|是否自动进行 S3 迁移,默认值为 0,表示关闭自动 S3 迁移,可配置为 1;企业版参数| +|s3Accesskey |3.3.4.3 后|冒号分隔的用户 SecretId:SecretKey,例如 AKIDsQmwsfKxTo2A6nGVXZN0UlofKn6JRRSJ:lIdoy99ygEacU7iHfogaN2Xq0yumSm1E;企业版参数| +|s3Endpoint |3.3.4.3 后|用户所在地域的 COS 服务域名,支持 http 和 https,bucket 的区域需要与 endpoint 保持一致,否则无法访问;企业版参数| +|s3BucketName |3.3.4.3 后|存储桶名称,减号后面是用户注册 COS 服务的 AppId,其中 AppId 是 COS 特有,AWS 和阿里云都没有,配置时需要作为 bucket name 的一部分,使用减号分隔;参数值均为字符串类型,但不需要引号;例如 test0711-1309024725;企业版参数| +|s3PageCacheSize |3.3.4.3 后|S3 page cache 缓存页数目,取值范围 4-1048576,单位为页,默认值 4096;企业版参数| +|s3UploadDelaySec |3.3.4.3 后|data 文件持续多长时间不再变动后上传至 S3,取值范围 1-2592000 (30天),单位为秒,默认值 60;企业版参数| +|cacheLazyLoadThreshold| |内部参数,缓存的装载策略| ### 集群相关 +|参数名称|支持版本|参数含义| +|--------------------------|----------|-| +|supportVnodes | |dnode 支持的最大 vnode 数目,取值范围 0-4096,默认值 CPU 核数的 2 倍 + 5| +|numOfCommitThreads | |落盘线程的最大数量,取值范围 0-1024,默认值为 4| +|numOfMnodeReadThreads | |mnode 的 Read 线程数目,取值范围 0-1024,默认值为 CPU 核数的四分之一(不超过 4)| +|numOfVnodeQueryThreads | |vnode 的 Query 线程数目,取值范围 0-1024,默认值为 CPU 核数的两倍(不超过 16)| +|numOfVnodeFetchThreads | |vnode 的 Fetch 线程数目,取值范围 0-1024,默认值为 CPU 核数的四分之一(不超过 4)| +|numOfVnodeRsmaThreads | |vnode 的 Rsma 线程数目,取值范围 0-1024,默认值为 CPU 核数的四分之一(不超过 4)| +|numOfQnodeQueryThreads | |qnode 的 Query 线程数目,取值范围 0-1024,默认值为 CPU 核数的两倍(不超过 16)| +|numOfSnodeSharedThreads | |snode 的共享线程数目,取值范围 0-1024,默认值为 CPU 核数的四分之一(不小于 2,不超过 4)| +|numOfSnodeUniqueThreads | |snode 的独占线程数目,取值范围 0-1024,默认值为 CPU 核数的四分之一(不小于 2,不超过 4)| +|ratioOfVnodeStreamThreads | |流计算使用 vnode 线程的比例,取值范围 0.01-4,默认值 4| +|ttlUnit | |ttl 参数的单位,取值范围 1-31572500,单位为秒,默认值 86400| +|ttlPushInterval | |ttl 检测超时频率,取值范围 1-100000,单位为秒,默认值 10| +|ttlChangeOnWrite | |ttl 到期时间是否伴随表的修改操作改变;0:不改变,1:改变;默认值为 0| +|ttlBatchDropNum | |ttl 一批删除子表的数目,最小值为 0,默认值 10000| +|retentionSpeedLimitMB | |数据在不同级别硬盘上迁移时的速度限制,取值范围 0-1024,单位 MB,默认值 0,表示不限制| +|maxTsmaNum | |集群内可创建的TSMA个数;取值范围 0-3;默认值 3| +|tmqMaxTopicNum | |订阅最多可建立的 topic 数量;取值范围 1-10000;默认值为 20| +|tmqRowSize | |订阅数据块的最大记录条数,取值范围 1-1000000,默认值 4096| +|audit | |审计功能开关;企业版参数| +|auditInterval | |审计数据上报的时间间隔;企业版参数| +|auditCreateTable | |是否针对创建子表开启申计功能;企业版参数| +|encryptAlgorithm | |数据加密算法;企业版参数| +|encryptScope | |加密范围;企业版参数| +|enableWhiteList | |白名单功能开关;企业版参数| +|syncLogBufferMemoryAllowed| |一个 dnode 允许的 sync 日志缓存消息占用的内存最大值,单位 bytes,取值范围 104857600-INT64_MAX,默认值 服务器内存的 1/10,3.1.3.2/3.3.2.13 版本开始生效 | +|syncElectInterval | |内部参数,用于同步模块调试| +|syncHeartbeatInterval | |内部参数,用于同步模块调试| +|syncHeartbeatTimeout | |内部参数,用于同步模块调试| +|syncSnapReplMaxWaitN | |内部参数,用于同步模块调试| +|syncSnapReplMaxWaitN | |内部参数,用于同步模块调试| +|arbHeartBeatIntervalSec | |内部参数,用于同步模块调试| +|arbCheckSyncIntervalSec | |内部参数,用于同步模块调试| +|arbSetAssignedTimeoutSec | |内部参数,用于同步模块调试| +|mndSdbWriteDelta | |内部参数,用于 mnode 模块调试| +|mndLogRetention | |内部参数,用于 mnode 模块调试| +|skipGrant | |内部参数,用于授权检查| +|trimVDbIntervalSec | |内部参数,用于删除过期数据| +|ttlFlushThreshold | |内部参数,ttl 定时器的频率| +|compactPullupInterval | |内部参数,数据重整定时器的频率| +|walFsyncDataSizeLimit | |内部参数,WAL 进行 FSYNC 的阈值| +|transPullupInterval | |内部参数,mnode 执行事务的重试间隔| +|mqRebalanceInterval | |内部参数,消费者再平衡的时间间隔| +|uptimeInterval | |内部参数,用于记录系统启动时间| +|timeseriesThreshold | |内部参数,用于统计用量| +|udf | |是否启动 UDF 服务;0:不启动,1:启动;默认值为 0 | +|udfdResFuncs | |内部参数,用于 UDF 结果集设置| +|udfdLdLibPath | |内部参数,表示 UDF 装载的库路径| -| 参数名称 | 参数说明 | -| :-----------: | :-------------------------------------------------------------------------: | -| supportVnodes | dnode 支持的最大 vnode 数目,取值范围:0-4096,缺省值: CPU 核数的 2 倍 + 5 | -### 内存相关 -| 参数名称 | 参数说明 | -| :----------------: | :---------------------------------------------: | -| rpcQueueMemoryAllowed | 一个 dnode 允许的 rpc 消息占用的内存最大值,单位 bytes,取值范围:104857600-INT64_MAX,缺省值:服务器内存的 1/10 | -| syncLogBufferMemoryAllowed | 一个 dnode 允许的 sync 日志缓存消息占用的内存最大值,单位 bytes,取值范围:104857600-INT64_MAX,缺省值:服务器内存的 1/10,3.1.3.2/3.3.2.13 版本开始生效 | - -### 性能调优 - -| 参数名称 | 参数说明 | -| :----------------: | :---------------------------------------------: | -| numOfCommitThreads | 落盘线程的最大数量,取值范围 0-1024,缺省值为 4 | +### 流计算参数 +|参数名称|支持版本|参数含义| +|-----------------------|----------|-| +|disableStream | |流计算的启动开关| +|streamBufferSize | |控制内存中窗口状态缓存的大小,默认值为 128MB| +|streamAggCnt | |内部参数,并发进行聚合计算的数目| +|checkpointInterval | |内部参数,checkponit 同步间隔| +|concurrentCheckpoint | |内部参数,是否并发检查 checkpoint| +|maxStreamBackendCache | |内部参数,流计算使用的最大缓存| +|streamSinkDataRate | |内部参数,用于控制流计算结果的写入速度| ### 日志相关 +|参数名称|支持版本|参数含义| +|----------------|----------|-| +|logDir | |日志文件目录,运行日志将写入该目录,默认值 /var/log/taos| +|minimalLogDirGB | |日志文件夹所在磁盘可用空间大小小于该值时,停止写日志,单位 GB,默认值 1| +|numOfLogLines | |单个日志文件允许的最大行数,默认值 10,000,000| +|asyncLog | |日志写入模式,0:同步,1:异步,默认值 1| +|logKeepDays | |日志文件的最长保存时间,单位:天,默认值 0,意味着无限保存,日志文件不会被重命名,也不会有新的日志文件滚动产生,但日志文件的内容有可能会不断滚动,取决于日志文件大小的设置;当设置为大于 0 的值时,当日志文件大小达到设置的上限时会被重命名为 taosdlog.yyy,其中 yyy 为日志文件最后修改的时间戳,并滚动产生新的日志文件| +|slowLogThreshold|3.3.3.0 后|慢查询门限值,大于等于门限值认为是慢查询,单位秒,默认值 3 | +|slowLogMaxLen |3.3.3.0 后|慢查询日志最大长度,取值范围 1-16384,默认值 4096| +|slowLogScope |3.3.3.0 后|慢查询记录类型,取值范围 ALL/QUERY/INSERT/OTHERS/NONE,默认值 QUERY| +|slowLogExceptDb |3.3.3.0 后|指定的数据库不上报慢查询,仅支持配置换一个数据库| +|debugFlag | |运行日志开关,131(输出错误和警告日志),135(输出错误、警告和调试日志),143(输出错误、警告、调试和跟踪日志);默认值 131 或 135 (取决于不同模块)| +|tmrDebugFlag | |定时器模块的日志开关,取值范围同上| +|uDebugFlag | |共用功能模块的日志开关,取值范围同上| +|rpcDebugFlag | |rpc 模块的日志开关,取值范围同上| +|qDebugFlag | |query 模块的日志开关,取值范围同上| +|dDebugFlag | |dnode 模块的日志开关,取值范围同上| +|vDebugFlag | |vnode 模块的日志开关,取值范围同上| +|mDebugFlag | |mnode 模块的日志开关,取值范围同上| +|azDebugFlag |3.3.4.3 后|S3 模块的日志开关,取值范围同上| +|sDebugFlag | |sync 模块的日志开关,取值范围同上| +|tsdbDebugFlag | |tsdb 模块的日志开关,取值范围同上| +|tqDebugFlag | |tq 模块的日志开关,取值范围同上| +|fsDebugFlag | |fs 模块的日志开关,取值范围同上| +|udfDebugFlag | |udf 模块的日志开关,取值范围同上| +|smaDebugFlag | |sma 模块的日志开关,取值范围同上| +|idxDebugFlag | |index 模块的日志开关,取值范围同上| +|tdbDebugFlag | |tdb 模块的日志开关,取值范围同上| +|metaDebugFlag | |meta 模块的日志开关,取值范围同上| +|stDebugFlag | |stream 模块的日志开关,取值范围同上| +|sndDebugFlag | |snode 模块的日志开关,取值范围同上| -| 参数名称 | 参数说明 | -| :--------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------: | -| logDir | 日志文件目录,运行日志将写入该目录,缺省值:/var/log/taos | -| minimalLogDirGB | 当日志文件夹所在磁盘可用空间大小小于该值时,停止写日志,单位GB,缺省值:1 | -| numOfLogLines | 单个日志文件允许的最大行数,缺省值:10,000,000 | -| asyncLog | 日志写入模式,0: 同步,1: 异步,缺省值: 1 | -| logKeepDays | 日志文件的最长保存时间 ,单位:天,缺省值:0,意味着无限保存,日志文件不会被重命名,也不会有新的日志文件滚动产生,但日志文件的内容有可能会不断滚动,取决于日志文件大小的设置;当设置为大于0 的值时,当日志文件大小达到设置的上限时会被重命名为 taosdlog.xxx,其中 xxx 为日志文件最后修改的时间戳,并滚动产生新的日志文件 | -| slowLogThreshold | 慢查询门限值,大于等于门限值认为是慢查询,单位秒,默认值: 3 | -| slowLogScope | 定启动记录哪些类型的慢查询,可选值:ALL, QUERY, INSERT, OHTERS, NONE; 默认值:ALL | -| debugFlag | 运行日志开关,131(输出错误和警告日志),135(输出错误、警告和调试日志),143(输出错误、警告、调试和跟踪日志); 默认值:131 或 135 (取决于不同模块) | -| tmrDebugFlag | 定时器模块的日志开关,取值范围同上 | -| uDebugFlag | 共用功能模块的日志开关,取值范围同上 | -| rpcDebugFlag | rpc 模块的日志开关,取值范围同上 | -| cDebugFlag | 客户端模块的日志开关,取值范围同上 | -| jniDebugFlag | jni 模块的日志开关,取值范围同上 | -| qDebugFlag | query 模块的日志开关,取值范围同上 | -| dDebugFlag | dnode 模块的日志开关,取值范围同上,缺省值 135 | -| vDebugFlag | vnode 模块的日志开关,取值范围同上 | -| mDebugFlag | mnode 模块的日志开关,取值范围同上 | -| wDebugFlag | wal 模块的日志开关,取值范围同上 | -| sDebugFlag | sync 模块的日志开关,取值范围同上 | -| tsdbDebugFlag | tsdb 模块的日志开关,取值范围同上 | -| tqDebugFlag | tq 模块的日志开关,取值范围同上 | -| fsDebugFlag | fs 模块的日志开关,取值范围同上 | -| udfDebugFlag | udf 模块的日志开关,取值范围同上 | -| smaDebugFlag | sma 模块的日志开关,取值范围同上 | -| idxDebugFlag | index 模块的日志开关,取值范围同上 | -| tdbDebugFlag | tdb 模块的日志开关,取值范围同上 | +### 调试相关 +|参数名称|支持版本|参数含义| +|--------------------|----------|-| +|enableCoreFile | |crash 时是否生成 core 文件,0:不生成,1:生成;默认值 1| +|configDir | |配置文件所在目录| +|scriptDir | |内部测试工具的脚本目录| +|assert | |断言控制开关,默认值 0| +|randErrorChance | |内部参数,用于随机失败测试| +|randErrorDivisor | |内部参数,用于随机失败测试| +|randErrorScope | |内部参数,用于随机失败测试| +|safetyCheckLevel | |内部参数,用于随机失败测试| +|experimental | |内部参数,用于一些实验特性| +|simdEnable |3.3.4.3 后|内部参数,用于测试 SIMD 加速| +|AVX512Enable |3.3.4.3 后|内部参数,用于测试 AVX512 加速| +|rsyncPort | |内部参数,用于调试流计算| +|snodeAddress | |内部参数,用于调试流计算| +|checkpointBackupDir | |内部参数,用于恢复 snode 数据| +|enableAuditDelete | |内部参数,用于测试审计功能| +|slowLogThresholdTest| |内部参数,用于测试慢日志| ### 压缩参数 - -| 参数名称 | 参数说明 | -|:-------------:|:----------------------------------------------------------------:| -| compressMsgSize | 是否对 RPC 消息进行压缩;-1: 所有消息都不压缩; 0: 所有消息都压缩; N (N>0): 只有大于 N 个字节的消息才压缩;缺省值 -1 | -| fPrecision | 设置 float 类型浮点数压缩精度 ,取值范围:0.1 ~ 0.00000001 ,默认值 0.00000001 , 小于此值的浮点数尾数部分将被截断 | -|dPrecision | 设置 double 类型浮点数压缩精度 , 取值范围:0.1 ~ 0.0000000000000001 , 缺省值 0.0000000000000001 , 小于此值的浮点数尾数部分将被截取 | -|lossyColumn | 对 float 和/或 double 类型启用 TSZ 有损压缩;取值范围: float, double, none;缺省值: none,表示关闭无损压缩。**注意:此参数在 3.3.0.0 及更高版本中不再使用** | -|ifAdtFse | 在启用 TSZ 有损压缩时,使用 FSE 算法替换 HUFFMAN 算法, FSE 算法压缩速度更快,但解压稍慢,追求压缩速度可选用此算法; 0: 关闭,1:打开;默认值为 0 | - +|参数名称|支持版本|参数含义| +|------------|----------|-| +|fPrecision | |设置 float 类型浮点数压缩精度 ,取值范围 0.1 ~ 0.00000001 ,默认值 0.00000001 , 小于此值的浮点数尾数部分将被截断| +|dPrecision | |设置 double 类型浮点数压缩精度 , 取值范围 0.1 ~ 0.0000000000000001 , 默认值 0.0000000000000001 , 小于此值的浮点数尾数部分将被截取| +|lossyColumn |3.3.0.0 前|对 float 和/或 double 类型启用 TSZ 有损压缩;取值范围 float/double/none;默认值 none,表示关闭无损压缩| +|ifAdtFse | |在启用 TSZ 有损压缩时,使用 FSE 算法替换 HUFFMAN 算法,FSE 算法压缩速度更快,但解压稍慢,追求压缩速度可选用此算法;0:关闭,1:打开;默认值为 0| +|maxRange | |内部参数,用于有损压缩设置| +|curRange | |内部参数,用于有损压缩设置| +|compressor | |内部参数,用于有损压缩设置| **补充说明** 1. 在 3.2.0.0 ~ 3.3.0.0(不包含)版本生效,启用该参数后不能回退到升级前的版本 @@ -220,16 +319,6 @@ lossyColumns float|double 02/22 10:49:27.607990 00002933 UTL lossyColumns float|double ``` -### 其他参数 - -| 参数名称 | 参数说明 | -| :--------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | -| enableCoreFile | crash 时是否生成 core 文件;0: 不生成,1:生成;默认值为 1; 不同的启动方式,生成 core 文件的目录如下:1、systemctl start taosd 启动:生成的 core 在根目录下
2、手动启动,就在 taosd 执行目录下。 | -| udf | 是否启动 UDF 服务;0: 不启动,1:启动;默认值为 0 | -| ttlChangeOnWrite | ttl 到期时间是否伴随表的修改操作改变; 0: 不改变,1:改变;默认值为 0 | -| tmqMaxTopicNum | 订阅最多可建立的 topic 数量; 取值范围 1-10000;缺省值为20 | -| maxTsmaNum | 集群内可创建的TSMA个数;取值范围:0-3;缺省值为 3 | - ## taosd 监控指标 @@ -282,7 +371,7 @@ taosd 会将监控指标上报给 taosKeeper,这些监控指标会被 taosKeep | :------------- | :-------- | :------ | :--------------------------------------------- | | \_ts | TIMESTAMP | | timestamp | | tables\_num | DOUBLE | | vgroup 中 table 数量 | -| status | DOUBLE | | vgroup 状态, 取值范围:unsynced = 0, ready = 1 | +| status | DOUBLE | | vgroup 状态, 取值范围 unsynced = 0, ready = 1 | | vgroup\_id | VARCHAR | TAG | vgroup id | | database\_name | VARCHAR | TAG | vgroup 所属的 database 名字 | | cluster\_id | VARCHAR | TAG | cluster id | @@ -311,10 +400,10 @@ taosd 会将监控指标上报给 taosKeeper,这些监控指标会被 taosKeep | io\_write\_disk | DOUBLE | | 磁盘 io 吞吐率,从 `/proc//io` 中读取的 write_bytes。单位 byte/s | | vnodes\_num | DOUBLE | | dnode 上 vnodes 数量 | | masters | DOUBLE | | dnode 上 master node 数量 | -| has\_mnode | DOUBLE | | dnode 是否包含 mnode,取值范围:包含=1,不包含=0 | -| has\_qnode | DOUBLE | | dnode 是否包含 qnode,取值范围:包含=1,不包含=0 | -| has\_snode | DOUBLE | | dnode 是否包含 snode,取值范围:包含=1,不包含=0 | -| has\_bnode | DOUBLE | | dnode 是否包含 bnode,取值范围:包含=1,不包含=0 | +| has\_mnode | DOUBLE | | dnode 是否包含 mnode,取值范围 包含=1,不包含=0 | +| has\_qnode | DOUBLE | | dnode 是否包含 qnode,取值范围 包含=1,不包含=0 | +| has\_snode | DOUBLE | | dnode 是否包含 snode,取值范围 包含=1,不包含=0 | +| has\_bnode | DOUBLE | | dnode 是否包含 bnode,取值范围 包含=1,不包含=0 | | error\_log\_count | DOUBLE | | error 总数 | | info\_log\_count | DOUBLE | | info 总数 | | debug\_log\_count | DOUBLE | | debug 总数 | @@ -330,7 +419,7 @@ taosd 会将监控指标上报给 taosKeeper,这些监控指标会被 taosKeep | field | type | is\_tag | comment | | :---------- | :-------- | :------ | :--------------------------------------- | | \_ts | TIMESTAMP | | timestamp | -| status | DOUBLE | | dnode 状态,取值范围:ready=1,offline =0 | +| status | DOUBLE | | dnode 状态,取值范围 ready=1,offline =0 | | dnode\_id | VARCHAR | TAG | dnode id | | dnode\_ep | VARCHAR | TAG | dnode endpoint | | cluster\_id | VARCHAR | TAG | cluster id | @@ -373,7 +462,7 @@ taosd 会将监控指标上报给 taosKeeper,这些监控指标会被 taosKeep | field | type | is\_tag | comment | | :---------- | :-------- | :------ | :------------------------------------------------------------------------------------------------------- | | \_ts | TIMESTAMP | | timestamp | -| role | DOUBLE | | mnode 角色, 取值范围:offline = 0,follower = 100,candidate = 101,leader = 102,error = 103,learner = 104 | +| role | DOUBLE | | mnode 角色, 取值范围 offline = 0,follower = 100,candidate = 101,leader = 102,error = 103,learner = 104 | | mnode\_id | VARCHAR | TAG | master node id | | mnode\_ep | VARCHAR | TAG | master node endpoint | | cluster\_id | VARCHAR | TAG | cluster id | @@ -385,7 +474,7 @@ taosd 会将监控指标上报给 taosKeeper,这些监控指标会被 taosKeep | field | type | is\_tag | comment | | :------------- | :-------- | :------ | :------------------------------------------------------------------------------------------------------ | | \_ts | TIMESTAMP | | timestamp | -| vnode\_role | DOUBLE | | vnode 角色,取值范围:offline = 0,follower = 100,candidate = 101,leader = 102,error = 103,learner = 104 | +| vnode\_role | DOUBLE | | vnode 角色,取值范围 offline = 0,follower = 100,candidate = 101,leader = 102,error = 103,learner = 104 | | vgroup\_id | VARCHAR | TAG | dnode id | | dnode\_id | VARCHAR | TAG | dnode id | | database\_name | VARCHAR | TAG | vgroup 所属的 database 名字 | @@ -399,9 +488,9 @@ taosd 会将监控指标上报给 taosKeeper,这些监控指标会被 taosKeep | :---------- | :-------- | :------ | :--------------------------------------- | | \_ts | TIMESTAMP | | timestamp | | count | DOUBLE | | sql 数量 | -| result | VARCHAR | TAG | sql的执行结果,取值范围:Success, Failed | +| result | VARCHAR | TAG | sql的执行结果,取值范围 Success, Failed | | username | VARCHAR | TAG | 执行sql的user name | -| sql\_type | VARCHAR | TAG | sql类型,取值范围:inserted_rows | +| sql\_type | VARCHAR | TAG | sql类型,取值范围 inserted_rows | | dnode\_id | VARCHAR | TAG | dnode id | | dnode\_ep | VARCHAR | TAG | dnode endpoint | | vgroup\_id | VARCHAR | TAG | dnode id | @@ -415,9 +504,9 @@ taosd 会将监控指标上报给 taosKeeper,这些监控指标会被 taosKeep | :---------- | :-------- | :------ | :---------------------------------------- | | \_ts | TIMESTAMP | | timestamp | | count | DOUBLE | | sql 数量 | -| result | VARCHAR | TAG | sql的执行结果,取值范围:Success, Failed | +| result | VARCHAR | TAG | sql的执行结果,取值范围 Success, Failed | | username | VARCHAR | TAG | 执行sql的user name | -| sql\_type | VARCHAR | TAG | sql类型,取值范围:select, insert,delete | +| sql\_type | VARCHAR | TAG | sql类型,取值范围 select, insert,delete | | cluster\_id | VARCHAR | TAG | cluster id | ### taos\_slow\_sql 表 @@ -428,9 +517,9 @@ taosd 会将监控指标上报给 taosKeeper,这些监控指标会被 taosKeep | :---------- | :-------- | :------ | :---------------------------------------------------- | | \_ts | TIMESTAMP | | timestamp | | count | DOUBLE | | sql 数量 | -| result | VARCHAR | TAG | sql的执行结果,取值范围:Success, Failed | +| result | VARCHAR | TAG | sql的执行结果,取值范围 Success, Failed | | username | VARCHAR | TAG | 执行sql的user name | -| duration | VARCHAR | TAG | sql执行耗时,取值范围:3-10s,10-100s,100-1000s,1000s- | +| duration | VARCHAR | TAG | sql执行耗时,取值范围 3-10s,10-100s,100-1000s,1000s- | | cluster\_id | VARCHAR | TAG | cluster id | ## 日志相关 diff --git a/docs/zh/14-reference/01-components/02-taosc.md b/docs/zh/14-reference/01-components/02-taosc.md index bd1e700041..09653ae3ef 100755 --- a/docs/zh/14-reference/01-components/02-taosc.md +++ b/docs/zh/14-reference/01-components/02-taosc.md @@ -8,38 +8,100 @@ TDengine 客户端驱动提供了应用编程所需要的全部 API,并且在 ## 配置参数 -| 参数名称 | 参数含义 | -|:-----------:|:----------------------------------------------------------:| -|firstEp | taos 启动时,主动连接的集群中首个 dnode 的 endpoint,缺省值:hostname:6030,若无法获取该服务器的 hostname,则赋值为 localhost | -|secondEp | 启动时,如果 firstEp 连接不上,尝试连接集群中第二个 dnode 的 endpoint,没有缺省值 | -|numOfRpcSessions | 一个客户端能创建的最大连接数,取值范围:10-50000000(单位为毫秒);缺省值:500000 | -|telemetryReporting | 是否上传 telemetry,0: 不上传,1: 上传;缺省值:1 | -|crashReporting | 是否上传 telemetry,0: 不上传,1: 上传;缺省值:1 | -|queryPolicy | 查询语句的执行策略,1: 只使用 vnode,不使用 qnode; 2: 没有扫描算子的子任务在 qnode 执行,带扫描算子的子任务在 vnode 执行; 3: vnode 只运行扫描算子,其余算子均在 qnode 执行 ;缺省值:1 | -|querySmaOptimize | sma index 的优化策略,0: 表示不使用 sma index,永远从原始数据进行查询; 1: 表示使用 sma index,对符合的语句,直接从预计算的结果进行查询;缺省值:0 | -|keepColumnName | Last、First、LastRow 函数查询且未指定别名时,自动设置别名为列名(不含函数名),因此 order by 子句如果引用了该列名将自动引用该列对应的函数; 1: 表示自动设置别名为列名(不包含函数名), 0: 表示不自动设置别名; 缺省值: 0 | -|countAlwaysReturnValue | count/hyperloglog函数在输入数据为空或者NULL的情况下是否返回值; 0:返回空行,1:返回; 缺省值 1; 该参数设置为 1 时,如果查询中含有 INTERVAL 子句或者该查询使用了TSMA时, 且相应的组或窗口内数据为空或者NULL, 对应的组或窗口将不返回查询结果. 注意此参数客户端和服务端值应保持一致. | -|multiResultFunctionStarReturnTags | 查询超级表时,last(\*)/last_row(\*)/first(\*) 是否返回标签列;查询普通表、子表时,不受该参数影响; 0:不返回标签列,1:返回标签列 ; 缺省值: 0; 该参数设置为 0 时,last(\*)/last_row(\*)/first(\*) 只返回超级表的普通列;为 1 时,返回超级表的普通列和标签列 | -|maxTsmaCalcDelay| 查询时客户端可允许的tsma计算延迟, 若tsma的计算延迟大于配置值, 则该TSMA将不会被使用.; 取值范围: 600s - 86400s, 即10分钟-1小时 ; 缺省值:600 秒| -|tsmaDataDeleteMark |TSMA计算的历史数据中间结果保存时间, 单位为毫秒; 取值范围:>= 3600000, 即大于等于1h; 缺省值: 86400000, 即1d | -|timezone | 时区; 缺省从系统中动态获取当前的时区设置 | -|locale | 系统区位信息及编码格式, 缺省从系统中获取 | -|charset | 字符集编码,缺省从系统中获取 | -|metaCacheMaxSize | 指定单个客户端元数据缓存大小的最大值, 单位 MB; 缺省值 -1,表示无限制 | -|logDir | 日志文件目录,客户端运行日志将写入该目录, 缺省值: /var/log/taos | -|minimalLogDirGB | 当日志文件夹所在磁盘可用空间大小小于该值时,停止写日志; 缺省值 1 | -|numOfLogLines | 单个日志文件允许的最大行数; 缺省值 10,000,000 | -|asyncLog | 是否异步写入日志,0:同步;1:异步;缺省值:1 | -|logKeepDays | 日志文件的最长保存时间; 缺省值: 0,表示无限保存; 大于 0 时,日志文件会被重命名为 taosdlog.xxx,其中 xxx 为日志文件最后修改的时间戳| -|smlChildTableName | schemaless 自定义的子表名的 key, 无缺省值 | -|smlAutoChildTableNameDelimiter | schemaless tag之间的连接符,连起来作为子表名,无缺省值 | -|smlTagName | schemaless tag 为空时默认的 tag 名字, 缺省值 "_tag_null" | -|smlTsDefaultName | schemaless自动建表的时间列名字通过该配置设置, 缺省值 "_ts" | -|smlDot2Underline | schemaless 把超级表名中的 dot 转成下划线 | -|enableCoreFile | crash 时是否生成 core 文件,0: 不生成, 1: 生成;缺省值:1 | -|enableScience | 是否开启科学计数法显示浮点数; 0: 不开始, 1: 开启;缺省值:1 | -|compressMsgSize | 是否对 RPC 消息进行压缩; -1: 所有消息都不压缩; 0: 所有消息都压缩; N (N>0): 只有大于 N 个字节的消息才压缩; 缺省值 -1| -|queryTableNotExistAsEmpty | 查询表不存在时是否返回空结果集; false: 返回错误; true: 返回空结果集; 缺省值 false| +### 连接相关 +|参数名称|支持版本|参数含义| +|----------------------|----------|-| +|firstEp | |启动时,主动连接的集群中首个 dnode 的 endpoint,缺省值:hostname:6030,若无法获取该服务器的 hostname,则赋值为 localhost| +|secondEp | |启动时,如果 firstEp 连接不上,尝试连接集群中第二个 dnode 的 endpoint,没有缺省值| +|compressMsgSize | |是否对 RPC 消息进行压缩;-1:所有消息都不压缩;0:所有消息都压缩;N (N>0):只有大于 N 个字节的消息才压缩;缺省值 -1| +|shellActivityTimer | |客户端向 mnode 发送心跳的时长,单位为秒,取值范围 1-120,默认值 3| +|numOfRpcSessions | |RPC 支持的最大连接数,取值范围 100-100000,缺省值 30000| +|numOfRpcThreads | |RPC 线程数目,默认值为 CPU 核数的一半| +|timeToGetAvailableConn| |获得可用连接的最长等待时间,取值范围 10-50000000,单位为毫秒,缺省值 500000| +|useAdapter | |内部参数,是否使用 taosadapter,影响 CSV 文件导入| +|shareConnLimit |3.3.4.3 后|内部参数,一个链接可以共享的查询数目,取值范围 1-256,默认值 10| +|readTimeout |3.3.4.3 后|内部参数,最小超时时间,取值范围 64-604800,单位为秒,默认值 900| + +### 查询相关 +|参数名称|支持版本|参数含义| +|---------------------------------|---------|-| +|countAlwaysReturnValue | |count/hyperloglog 函数在输入数据为空或者 NULL 的情况下是否返回值;0:返回空行,1:返回;默认值 1;该参数设置为 1 时,如果查询中含有 INTERVAL 子句或者该查询使用了 TSMA 时,且相应的组或窗口内数据为空或者 NULL,对应的组或窗口将不返回查询结果;注意此参数客户端和服务端值应保持一致| +|keepColumnName | |Last、First、LastRow 函数查询且未指定别名时,自动设置别名为列名(不含函数名),因此 order by 子句如果引用了该列名将自动引用该列对应的函数;1:表示自动设置别名为列名(不包含函数名),0:表示不自动设置别名;缺省值:0| +|multiResultFunctionStarReturnTags|3.3.3.0 后|查询超级表时,last(\*)/last_row(\*)/first(\*) 是否返回标签列;查询普通表、子表时,不受该参数影响;0:不返回标签列,1:返回标签列;缺省值:0;该参数设置为 0 时,last(\*)/last_row(\*)/first(\*) 只返回超级表的普通列;为 1 时,返回超级表的普通列和标签列| +|metaCacheMaxSize | |指定单个客户端元数据缓存大小的最大值,单位 MB;缺省值 -1,表示无限制| +|maxTsmaCalcDelay | |查询时客户端可允许的 tsma 计算延迟,若 tsma 的计算延迟大于配置值,则该 TSMA 将不会被使用;取值范围 600s - 86400s,即 10 分钟 - 1 小时;缺省值:600 秒| +|tsmaDataDeleteMark | |TSMA 计算的历史数据中间结果保存时间,单位为毫秒;取值范围 >= 3600000,即大于等于1h;缺省值:86400000,即 1d | +|queryPolicy | |查询语句的执行策略,1:只使用 vnode,不使用 qnode;2:没有扫描算子的子任务在 qnode 执行,带扫描算子的子任务在 vnode 执行;3:vnode 只运行扫描算子,其余算子均在 qnode 执行;缺省值:1| +|queryTableNotExistAsEmpty | |查询表不存在时是否返回空结果集;false:返回错误;true:返回空结果集;缺省值 false| +|querySmaOptimize | |sma index 的优化策略,0:表示不使用 sma index,永远从原始数据进行查询;1:表示使用 sma index,对符合的语句,直接从预计算的结果进行查询;缺省值:0| +|queryPlannerTrace | |内部参数,查询计划是否输出详细日志| +|queryNodeChunkSize | |内部参数,查询计划的块大小| +|queryUseNodeAllocator | |内部参数,查询计划的分配方法| +|queryMaxConcurrentTables | |内部参数,查询计划的并发数目| +|enableQueryHb | |内部参数,是否发送查询心跳消息| +|minSlidingTime | |内部参数,sliding 的最小允许值| +|minIntervalTime | |内部参数,interval 的最小允许值| + +### 写入相关 +|参数名称|支持版本|参数含义| +|------------------------------|----------|-| +|smlChildTableName | |schemaless 自定义的子表名的 key,无缺省值| +|smlAutoChildTableNameDelimiter| |schemaless tag 之间的连接符,连起来作为子表名,无缺省值| +|smlTagName | |schemaless tag 为空时默认的 tag 名字,缺省值 "_tag_null"| +|smlTsDefaultName | |schemaless 自动建表的时间列名字通过该配置设置,缺省值 "_ts"| +|smlDot2Underline | |schemaless 把超级表名中的 dot 转成下划线| +|maxInsertBatchRows | |内部参数,一批写入的最大条数| + +### 区域相关 +|参数名称|支持版本|参数含义| +|-----------------|----------|-| +|timezone | |时区;缺省从系统中动态获取当前的时区设置| +|locale | |系统区位信息及编码格式,缺省从系统中获取| +|charset | |字符集编码,缺省从系统中获取| + +### 存储相关 +|参数名称|支持版本|参数含义| +|-----------------|----------|-| +|tempDir | |指定所有运行过程中的临时文件生成的目录,Linux 平台默认值为 /tmp| +|minimalTmpDirGB | |tempDir 所指定的临时文件目录所需要保留的最小空间,单位 GB,缺省值:1| + +### 日志相关 +|参数名称|支持版本|参数含义| +|-----------------|----------|-| +|logDir | |日志文件目录,运行日志将写入该目录,缺省值:/var/log/taos| +|minimalLogDirGB | |日志文件夹所在磁盘可用空间大小小于该值时,停止写日志,单位 GB,缺省值:1| +|numOfLogLines | |单个日志文件允许的最大行数,缺省值:10,000,000| +|asyncLog | |日志写入模式,0:同步,1:异步,缺省值:1| +|logKeepDays | |日志文件的最长保存时间,单位:天,缺省值:0,意味着无限保存,日志文件不会被重命名,也不会有新的日志文件滚动产生,但日志文件的内容有可能会不断滚动,取决于日志文件大小的设置;当设置为大于 0 的值时,当日志文件大小达到设置的上限时会被重命名为 taoslogx.yyy,其中 yyy 为日志文件最后修改的时间戳,并滚动产生新的日志文件| +|debugFlag | |运行日志开关,131(输出错误和警告日志),135(输出错误、警告和调试日志),143(输出错误、警告、调试和跟踪日志);默认值 131 或 135 (取决于不同模块)| +|tmrDebugFlag | |定时器模块的日志开关,取值范围同上| +|uDebugFlag | |共用功能模块的日志开关,取值范围同上| +|rpcDebugFlag | |rpc 模块的日志开关,取值范围同上| +|jniDebugFlag | |jni 模块的日志开关,取值范围同上| +|qDebugFlag | |query 模块的日志开关,取值范围同上| +|cDebugFlag | |客户端模块的日志开关,取值范围同上| +|simDebugFlag | |内部参数,测试工具的日志开关,取值范围同上| +|tqClientDebugFlag|3.3.4.3 后|客户端模块的日志开关,取值范围同上| + +### 调试相关 +|参数名称|支持版本|参数含义| +|-----------------|-----------|-| +|crashReporting | |是否上传 crash 到 telemetry,0:不上传,1:上传;缺省值:1| +|enableCoreFile | |crash 时是否生成 core 文件,0:不生成,1:生成;缺省值:1| +|assert | |断言控制开关,缺省值:0| +|configDir | |配置文件所在目录| +|scriptDir | |内部参数,测试用例的目录| +|randErrorChance |3.3.3.0 后|内部参数,用于随机失败测试| +|randErrorDivisor |3.3.3.0 后|内部参数,用于随机失败测试| +|randErrorScope |3.3.3.0 后|内部参数,用于随机失败测试| +|safetyCheckLevel |3.3.3.0 后|内部参数,用于随机失败测试| +|simdEnable |3.3.4.3 后|内部参数,用于测试 SIMD 加速| +|AVX512Enable |3.3.4.3 后|内部参数,用于测试 AVX512 加速| + +### SHELL 相关 +|参数名称|支持版本|参数含义| +|-----------------|----------|-| +|enableScience | |是否开启科学计数法显示浮点数;0:不开始,1:开启;缺省值:1| ## API diff --git a/docs/zh/14-reference/03-taos-sql/02-database.md b/docs/zh/14-reference/03-taos-sql/02-database.md index 24eca97952..91b39976a1 100644 --- a/docs/zh/14-reference/03-taos-sql/02-database.md +++ b/docs/zh/14-reference/03-taos-sql/02-database.md @@ -122,6 +122,7 @@ alter_database_option: { | KEEP value | WAL_RETENTION_PERIOD value | WAL_RETENTION_SIZE value + | MINROWS value } ``` diff --git a/docs/zh/14-reference/03-taos-sql/03-table.md b/docs/zh/14-reference/03-taos-sql/03-table.md index 81ad60e3d2..40e2802fcd 100644 --- a/docs/zh/14-reference/03-taos-sql/03-table.md +++ b/docs/zh/14-reference/03-taos-sql/03-table.md @@ -227,7 +227,7 @@ DROP TABLE [IF EXISTS] [db_name.]tb_name [, [IF EXISTS] [db_name.]tb_name] ... 如下 SQL 语句可以列出当前数据库中的所有表名。 ```sql -SHOW TABLES [LIKE tb_name_wildchar]; +SHOW TABLES [LIKE tb_name_wildcard]; ``` ### 显示表创建语句 diff --git a/docs/zh/14-reference/03-taos-sql/10-function.md b/docs/zh/14-reference/03-taos-sql/10-function.md index bbc6a0b81a..ae256a4ac0 100644 --- a/docs/zh/14-reference/03-taos-sql/10-function.md +++ b/docs/zh/14-reference/03-taos-sql/10-function.md @@ -1988,7 +1988,7 @@ TOP(expr, k) UNIQUE(expr) ``` -**功能说明**:返回该列数据首次出现的值。该函数功能与 distinct 相似。对于存在复合主键的表的查询,若最小时间戳的数据有多条,则只有对应的复合主键最小的数据被返回。 +**功能说明**:返回该列数据去重后的值。该函数功能与 distinct 相似。对于相同的数据,返回时间戳最小的一条,对于存在复合主键的表的查询,若最小时间戳的数据有多条,则只有对应的复合主键最小的数据被返回。 **返回数据类型**:同应用的字段。 diff --git a/docs/zh/14-reference/03-taos-sql/20-keywords.md b/docs/zh/14-reference/03-taos-sql/20-keywords.md index 1ef0d07e14..f7cc5d17c0 100644 --- a/docs/zh/14-reference/03-taos-sql/20-keywords.md +++ b/docs/zh/14-reference/03-taos-sql/20-keywords.md @@ -11,337 +11,470 @@ description: TDengine 保留关键字的详细列表 关键字列表如下: ### A - -- ABORT -- ACCOUNT -- ACCOUNTS -- ADD -- AFTER -- AGGREGATE -- ALIVE -- ALL -- ALTER -- ANALYZE -- AND -- APPS -- AS -- ASC -- AT_ONCE -- ATTACH +|关键字|说明| +|----------------------|-| +| ABORT | | +| ACCOUNT | | +| ACCOUNTS | | +| ADD | | +| AFTER | | +| AGGREGATE | | +| ALIAS | | +| ALIVE | | +| ALL | | +| ALTER | | +| ANALYZE | 3.3.4.3 及后续版本 | +| AND | | +| ANODE | 3.3.4.3 及后续版本 | +| ANODES | 3.3.4.3 及后续版本 | +| ANOMALY_WINDOW | 3.3.4.3 及后续版本 | +| ANTI | | +| APPS | | +| ARBGROUPS | | +| ARROW | | +| AS | | +| ASC | | +| ASOF | | +| AT_ONCE | | +| ATTACH | | ### B - -- BALANCE -- BEFORE -- BEGIN -- BETWEEN -- BIGINT -- BINARY -- BITAND -- BITNOT -- BITOR -- BLOCKS -- BNODE -- BNODES -- BOOL -- BUFFER -- BUFSIZE -- BY +|关键字|说明| +|----------------------|-| +| BALANCE | | +| BEFORE | | +| BEGIN | | +| BETWEEN | | +| BIGINT | | +| BIN | | +| BINARY | | +| BITAND | | +| BITAND | | +| BITNOT | | +| BITOR | | +| BLOB | | +| BLOCKS | | +| BNODE | | +| BNODES | | +| BOOL | | +| BOTH | | +| BUFFER | | +| BUFSIZE | | +| BWLIMIT | | +| BY | | ### C - -- CACHE -- CACHEMODEL -- CACHESIZE -- CASCADE -- CAST -- CHANGE -- CLIENT_VERSION -- CLUSTER -- COLON -- COLUMN -- COMMA -- COMMENT -- COMP -- COMPACT -- CONCAT -- CONFLICT -- CONNECTION -- CONNECTIONS -- CONNS -- CONSUMER -- CONSUMERS -- CONTAINS -- COPY -- COUNT -- CREATE -- CURRENT_USER +|关键字|说明| +|----------------------|-| +| CACHE | | +| CACHEMODEL | | +| CACHESIZE | | +| CASE | | +| CAST | | +| CHANGE | | +| CHILD | | +| CLIENT_VERSION | | +| CLUSTER | | +| COLON | | +| COLUMN | | +| COMMA | | +| COMMENT | | +| COMP | | +| COMPACT | | +| COMPACTS | | +| CONCAT | | +| CONFLICT | | +| CONNECTION | | +| CONNECTIONS | | +| CONNS | | +| CONSUMER | | +| CONSUMERS | | +| CONTAINS | | +| COPY | | +| COUNT | | +| COUNT_WINDOW | | +| CREATE | | +| CREATEDB | | +| CURRENT_USER | | ### D - -- DATABASE -- DATABASES -- DBS -- DEFERRED -- DELETE -- DELIMITERS -- DESC -- DESCRIBE -- DETACH -- DISTINCT -- DISTRIBUTED -- DIVIDE -- DNODE -- DNODES -- DOT -- DOUBLE -- DROP -- DURATION +|关键字|说明| +|----------------------|-| +| DATABASE | | +| DATABASES | | +| DBS | | +| DECIMAL | | +| DEFERRED | | +| DELETE | | +| DELETE_MARK | | +| DELIMITERS | | +| DESC | | +| DESCRIBE | | +| DETACH | | +| DISTINCT | | +| DISTRIBUTED | | +| DIVIDE | | +| DNODE | | +| DNODES | | +| DOT | | +| DOUBLE | | +| DROP | | +| DURATION | | ### E - -- EACH -- ENABLE -- END -- EVERY -- EXISTS -- EXPIRED -- EXPLAIN +|关键字|说明| +|----------------------|-| +| EACH | | +| ELSE | | +| ENABLE | | +| ENCRYPT_ALGORITHM | | +| ENCRYPT_KEY | | +| ENCRYPTIONS | | +| END | | +| EQ | | +| EVENT_WINDOW | | +| EVERY | | +| EXCEPT | | +| EXISTS | | +| EXPIRED | | +| EXPLAIN | | ### F - -- FAIL -- FILE -- FILL -- FIRST -- FLOAT -- FLUSH -- FOR -- FROM -- FUNCTION -- FUNCTIONS +|关键字|说明| +|----------------------|-| +| FAIL | | +| FHIGH | 3.3.4.3 及后续版本 | +| FILE | | +| FILL | | +| FILL_HISTORY | | +| FIRST | | +| FLOAT | | +| FLOW | 3.3.4.3 及后续版本 | +| FLUSH | | +| FOR | | +| FORCE | | +| FORCE_WINDOW_CLOSE | 3.3.4.3 及后续版本 | +| FROM | | +| FROWTS | 3.3.4.3 及后续版本 | +| FULL | | +| FUNCTION | | +| FUNCTIONS | | ### G - -- GLOB -- GRANT -- GRANTS -- GROUP +|关键字|说明| +|----------------------|-| +| GE | | +| GEOMETRY | | +| GLOB | | +| GRANT | | +| GRANTS | | +| GROUP | | +| GT | | ### H - -- HAVING -- HOST +|关键字|说明| +|----------------------|-| +| HAVING | | +| HEX | | +| HOST | | ### I - -- ID -- IF -- IGNORE -- IMMEDIATE -- IMPORT -- IN -- INDEX -- INDEXES -- INITIALLY -- INNER -- INSERT -- INSTEAD -- INT -- INTEGER -- INTERVAL -- INTO -- IS -- IS NULL +|关键字|说明| +|----------------------|-| +| ID | | +| IF | | +| IGNORE | | +| ILLEGAL | | +| IMMEDIATE | | +| IMPORT | | +| IN | | +| INDEX | | +| INDEXES | | +| INITIALLY | | +| INNER | | +| INSERT | | +| INSTEAD | | +| INT | | +| INTEGER | | +| INTERSECT | | +| INTERVAL | | +| INTO | | +| IPTOKEN | | +| IROWTS | | +| IS | | +| IS_IMPORT | | +| ISFILLED | | +| ISNULL | | ### J - -- JOIN -- JSON +|关键字|说明| +|----------------------|-| +| JLIMIT | | +| JOIN | | +| JSON | | ### K - -- KEEP -- KEY -- KILL +|关键字|说明| +|----------------------|-| +| KEEP | | +| KEEP_TIME_OFFSET | | +| KEY | | +| KILL | | ### L - -- LAST -- LAST_ROW -- LICENCES -- LIKE -- LIMIT -- LINEAR -- LOCAL +|关键字|说明| +|----------------------|-| +| LANGUAGE | | +| LAST | | +| LAST_ROW | | +| LE | | +| LEADER | | +| LEADING | | +| LEFT | | +| LICENCES | | +| LIKE | | +| LIMIT | | +| LINEAR | | +| LOCAL | | +| LOGS | | +| LP | | +| LSHIFT | | +| LT | | ### M - -- MATCH -- MAX_DELAY -- BWLIMIT -- MAXROWS -- MAX_SPEED -- MERGE -- META -- MINROWS -- MINUS -- MNODE -- MNODES -- MODIFY -- MODULES +|关键字|说明| +|----------------------|-| +| MACHINES | | +| MATCH | | +| MAX_DELAY | | +| MAXROWS | | +| MEDIUMBLOB | | +| MERGE | | +| META | | +| MINROWS | | +| MINUS | | +| MNODE | | +| MNODES | | +| MODIFY | | +| MODULES | | ### N - -- NCHAR -- NEXT -- NMATCH -- NONE -- NOT -- NOT NULL -- NOW -- NULL -- NULLS +|关键字|说明| +|----------------------|-| +| NCHAR | | +| NE | | +| NEXT | | +| NMATCH | | +| NONE | | +| NORMAL | | +| NOT | | +| NOTNULL | | +| NOW | | +| NULL | | +| NULL_F | | +| NULLS | | ### O - -- OF -- OFFSET -- ON -- OR -- ORDER -- OUTPUTTYPE +|关键字|说明| +|----------------------|-| +| OF | | +| OFFSET | | +| ON | | +| ONLY | | +| OR | | +| ORDER | | +| OUTER | | +| OUTPUTTYPE | | ### P - -- PAGES -- PAGESIZE -- PARTITIONS -- PASS -- PLUS -- PORT -- PPS -- PRECISION -- PREV -- PRIVILEGE +|关键字|说明| +|----------------------|-| +| PAGES | | +| PAGESIZE | | +| PARTITION | | +| PASS | | +| PAUSE | | +| PI | | +| PLUS | | +| PORT | | +| POSITION | | +| PPS | | +| PRECISION | | +| PREV | | +| PRIMARY | | +| PRIVILEGE | | +| PRIVILEGES | | ### Q - -- QNODE -- QNODES -- QTIME -- QUERIES -- QUERY +|关键字|说明| +|----------------------|-| +| QDURATION | | +| QEND | | +| QNODE | | +| QNODES | | +| QSTART | | +| QTAGS | | +| QTIME | | +| QUERIES | | +| QUERY | | +| QUESTION | | ### R - -- RAISE -- RANGE -- RATIO -- READ -- REDISTRIBUTE -- RENAME -- REPLACE -- REPLICA -- RESET -- RESTRICT -- RETENTIONS -- REVOKE -- ROLLUP -- ROW +|关键字|说明| +|----------------------|-| +| RAISE | | +| RAND | | +| RANGE | | +| RATIO | | +| READ | | +| RECURSIVE | | +| REDISTRIBUTE | | +| REM | | +| REPLACE | | +| REPLICA | | +| RESET | | +| RESTORE | | +| RESTRICT | | +| RESUME | | +| RETENTIONS | | +| REVOKE | | +| RIGHT | | +| ROLLUP | | +| ROW | | +| ROWTS | | +| RP | | +| RSHIFT | | ### S - -- SCHEMALESS -- SCORES -- SELECT -- SEMI -- SERVER_STATUS -- SERVER_VERSION -- SESSION -- SET -- SHOW -- SINGLE_STABLE -- SLIDING -- SLIMIT -- SMA -- SMALLINT -- SNODE -- SNODES -- SOFFSET -- SPLIT -- STABLE -- STABLES -- START -- STATE -- STATE_WINDOW -- STATEMENT -- STORAGE -- STREAM -- STREAMS -- STRICT -- STRING -- SUBSCRIPTIONS -- SYNCDB -- SYSINFO +|关键字|说明| +|----------------------|-| +| S3_CHUNKPAGES | | +| S3_COMPACT | | +| S3_KEEPLOCAL | | +| SCHEMALESS | | +| SCORES | | +| SELECT | | +| SEMI | | +| SERVER_STATUS | | +| SERVER_VERSION | | +| SESSION | | +| SET | | +| SHOW | | +| SINGLE_STABLE | | +| SLASH | | +| SLIDING | | +| SLIMIT | | +| SMA | | +| SMALLINT | | +| SMIGRATE | | +| SNODE | | +| SNODES | | +| SOFFSET | | +| SPLIT | | +| STABLE | | +| STABLES | | +| STAR | | +| START | | +| STATE | | +| STATE_WINDOW | | +| STATEMENT | | +| STORAGE | | +| STREAM | | +| STREAMS | | +| STRICT | | +| STRING | | +| STT_TRIGGER | | +| SUBSCRIBE | | +| SUBSCRIPTIONS | | +| SUBSTR | | +| SUBSTRING | | +| SUBTABLE | | +| SYSINFO | | +| SYSTEM | | ### T - -- TABLE -- TABLES -- TAG -- TAGS -- TBNAME -- TIMES -- TIMESTAMP -- TIMEZONE -- TINYINT -- TO -- TODAY -- TOPIC -- TOPICS -- TRANSACTION -- TRANSACTIONS -- TRIGGER -- TRIM -- TSERIES -- TTL +|关键字|说明| +|----------------------|-| +| TABLE | | +| TABLE_PREFIX | | +| TABLE_SUFFIX | | +| TABLES | | +| TAG | | +| TAGS | | +| TBNAME | | +| THEN | | +| TIMES | | +| TIMESTAMP | | +| TIMEZONE | | +| TINYINT | | +| TO | | +| TODAY | | +| TOPIC | | +| TOPICS | | +| TRAILING | | +| TRANSACTION | | +| TRANSACTIONS | | +| TRIGGER | | +| TRIM | | +| TSDB_PAGESIZE | | +| TSERIES | | +| TSMA | | +| TSMAS | | +| TTL | | ### U - -- UNION -- UNSIGNED -- UPDATE -- USE -- USER -- USERS -- USING +|关键字|说明| +|----------------------|-| +| UNION | | +| UNSAFE | | +| UNSIGNED | | +| UNTREATED | | +| UPDATE | | +| USE | | +| USER | | +| USERS | | +| USING | | ### V +|关键字|说明| +|----------------------|-| +| VALUE | | +| VALUE_F | | +| VALUES | | +| VARBINARY | | +| VARCHAR | | +| VARIABLE | | +| VARIABLES | | +| VERBOSE | | +| VGROUP | | +| VGROUPS | | +| VIEW | | +| VIEWS | | +| VNODE | | +| VNODES | | -- VALUE -- VALUES -- VARCHAR -- VARIABLE -- VARIABLES -- VERBOSE -- VGROUP -- VGROUPS -- VIEW -- VNODES ### W - -- WAL -- WAL_FSYNC_PERIOD -- WAL_LEVEL -- WAL_RETENTION_PERIOD -- WAL_RETENTION_SIZE -- WATERMARK -- WHERE -- WINDOW_CLOSE -- WITH -- WRITE +|关键字|说明| +|----------------------|-| +| WAL | | +| WAL_FSYNC_PERIOD | | +| WAL_LEVEL | | +| WAL_RETENTION_PERIOD | | +| WAL_RETENTION_SIZE | | +| WAL_ROLL_PERIOD | | +| WAL_SEGMENT_SIZE | | +| WATERMARK | | +| WDURATION | | +| WEND | | +| WHEN | | +| WHERE | | +| WINDOW | | +| WINDOW_CLOSE | | +| WINDOW_OFFSET | | +| WITH | | +| WRITE | | +| WSTART | | ### \_ diff --git a/docs/zh/28-releases/01-tdengine.md b/docs/zh/28-releases/01-tdengine.md index 0f9ceada50..cf9d7b6878 100644 --- a/docs/zh/28-releases/01-tdengine.md +++ b/docs/zh/28-releases/01-tdengine.md @@ -24,6 +24,10 @@ TDengine 3.x 各版本安装包下载链接如下: import Release from "/components/ReleaseV3"; +## 3.3.4.3 + + + ## 3.3.3.0 diff --git a/docs/zh/28-releases/03-notes/3.3.4.3.md b/docs/zh/28-releases/03-notes/3.3.4.3.md new file mode 100644 index 0000000000..8ffd5802ed --- /dev/null +++ b/docs/zh/28-releases/03-notes/3.3.4.3.md @@ -0,0 +1,69 @@ +--- +title: 3.3.4.3 版本说明 +sidebar_label: 3.3.4.3 +description: 3.3.4.3 版本说明 +--- + +### 行为变更及兼容性 +1. 多副本流计算中必须使用 snode +1. 增加了流计算的兼容性保证机制,避免后续函数变更产生新的兼容性问题,但之前版本的流计算必须重建,具体参见 https://docs.taosdata.com/advanced/stream/#流计算升级故障恢复 +1. 调整 case when 语句结果类型的判断方法 + +### 新特性 +1. 新功能:流计算的 TWA 函数支持时间驱动的结果推送模式 +1. 新功能:流计算的 Interp 函数支持时间驱动的结果推送模式 +1. 新功能:支持微软对象存储 + +### 优化 +1. 优化:提升并发大查询时节点之间互相拉数据的效率 +1. 优化:支持使用 AVX2 和 AVX512 对 double 、timestamp 和 bigint 类型进行解码优化 +1. 优化:调整 case when 语句的结果类型判断方法 +1. 优化:顺序执行 compact 和 split vgroup操作时的日志错误提示 +1. 优化:提升查询 “select ... from ... where ts in (...)” 的数据扫描速度 +1. 优化:增加了流计算的兼容性保证机制,避免后续函数变更产生新的兼容性问题,之前版本的流计算必须重建 +1. 优化:提升 taosX 在交叉写入场景下的数据同步性能 +1. 优化:支持关闭整数/浮点数类型的编码 +1. 优化:多副本流计算中必须使用 snode +1. 优化:客户端生成唯一 ID 标识每一个查询任务,避免重复 ID 导致的内存损坏 +1. 优化:加快数据库的创建时间 +1. 优化:修改 s3MigrateEnabled 默认值为0 +1. 优化:支持在审计数据库中记录删除操作 +1. 优化:支持在指定的 dnode 中创建数据库 [企业版] +1. 优化:调整删除超级表数据列时的报错信息 + +### 修复 +1. 修复:last_row 查询性能在 3.3.3.0 中大幅下降的问题 +1. 修复:WAL 条目不完整时 taosd 无法启动的问题 +1. 修复: partition by 常量时查询结果错误的问题 +1. 修复:标量函数包含 _wstart 且填充方式为 prev 时计算结果错误 +1. 修复:Windows 平台下的时区设置问题 +1. 修复:空数据库进行 compact 操作时,事务无法结束【企业版】 +1. 修复:事务冲突的逻辑错误 +1. 修复:管理节点某些错误会导致事务无法停止 +1. 修复:管理节点某些错误会导致事务无法停止 +1. 修复:dnode 数据清空后 taosc 重试错误的问题 +1. 修复:Data Compact 被异常终止后,中间文件未被清理 +1. 修复:新增列后,Kafka 连接器的 earliest 模式消费不到新列数据 +1. 修复:interp 函数在 fill(prev) 时行为不正确 +1. 修复:TSMA 在高频元数据操作时异常停止的问题 +1. 修复:show create stable 语句执行结果的标签显示错误 +1. 修复:Percentile 函数在大数据量查询时会崩溃。 +1. 修复:partition by 和 having 联合使用时的语法错误问题 +1. 修复:interp 在 partition by tbname,c1 时 tbname 为空的问题 +1. 修复:通过 stmt 写入非法布尔数值时 taosd 可能 crash +1. 修复:库符号 version 与使用相同符号的库冲突的问题 +1. 修复:在 windows 平台下 JDBC 驱动的句柄数持续升高问题 +1. 修复:3.3.3.1 升级至 3.3.4.0 偶现的启动失败问题 +1. 修复:Windows 平台重复增删表的内存泄漏 +1. 修复:无法限制并发拉起 checkpoint 数量导致流计算消耗资源过多 +1. 修复:并发查询时的 too many session 问题 +1. 修复:Windows 平台下 taos shell 在慢查询场景中崩溃的问题 +1. 修复:当打开 dnode日志时,加密数据库无法恢复的问题 +1. 修复:由于 mnode 同步超时,进而导致 taosd 无法启动的问题 +1. 修复:由于在快照同步过程中整理文件组数据的速度过慢,从而导致 Vnode(虚拟节点)无法恢复的问题 +1. 修复:通过行协议向字符串类型的字段中写入带转义符的数据时,taosd 会崩溃 +1. 修复:Error Code 逻辑处理错误导致的元数据文件损坏 +1. 修复:查询语句中包含多个 “not” 条件语句嵌套时,未设置标量模式导致查询错误 +1. 修复:vnode 统计信息上报超时导致的 dnode offline 问题 +1. 修复:在不支持 avx 指令集的服务器上,taosd 启动失败问题 +1. 修复:taosX 数据迁移容错处理 0x09xx 错误码 diff --git a/docs/zh/28-releases/03-notes/index.md b/docs/zh/28-releases/03-notes/index.md index 132a72d9ca..d1a48ab9a8 100644 --- a/docs/zh/28-releases/03-notes/index.md +++ b/docs/zh/28-releases/03-notes/index.md @@ -3,5 +3,7 @@ title: 版本说明 sidebar_label: 版本说明 description: 各版本版本说明 --- + +[3.3.4.3](./3.3.4.3) [3.3.3.0](./3.3.3.0) [3.3.2.0](./3.3.2.0) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 7ff70b243a..70a32cd266 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -2187,8 +2187,9 @@ int32_t tSerializeSShowVariablesReq(void* buf, int32_t bufLen, SShowVariablesReq typedef struct { char name[TSDB_CONFIG_OPTION_LEN + 1]; - char value[TSDB_CONFIG_VALUE_LEN + 1]; + char value[TSDB_CONFIG_PATH_LEN + 1]; char scope[TSDB_CONFIG_SCOPE_LEN + 1]; + char info[TSDB_CONFIG_INFO_LEN + 1]; } SVariablesInfo; typedef struct { @@ -2307,6 +2308,7 @@ typedef struct { typedef struct { SExplainRsp rsp; uint64_t qId; + uint64_t cId; uint64_t tId; int64_t rId; int32_t eId; @@ -2660,6 +2662,7 @@ typedef struct SSubQueryMsg { SMsgHead header; uint64_t sId; uint64_t queryId; + uint64_t clientId; uint64_t taskId; int64_t refId; int32_t execId; @@ -2689,6 +2692,7 @@ typedef struct { SMsgHead header; uint64_t sId; uint64_t queryId; + uint64_t clientId; uint64_t taskId; int32_t execId; } SQueryContinueReq; @@ -2723,6 +2727,7 @@ typedef struct { SMsgHead header; uint64_t sId; uint64_t queryId; + uint64_t clientId; uint64_t taskId; int32_t execId; SOperatorParam* pOpParam; @@ -2738,6 +2743,7 @@ typedef struct { typedef struct { uint64_t queryId; + uint64_t clientId; uint64_t taskId; int64_t refId; int32_t execId; @@ -2784,6 +2790,7 @@ typedef struct { SMsgHead header; uint64_t sId; uint64_t queryId; + uint64_t clientId; uint64_t taskId; int64_t refId; int32_t execId; @@ -2797,6 +2804,7 @@ typedef struct { SMsgHead header; uint64_t sId; uint64_t queryId; + uint64_t clientId; uint64_t taskId; int64_t refId; int32_t execId; @@ -2813,6 +2821,7 @@ typedef struct { SMsgHead header; uint64_t sId; uint64_t queryId; + uint64_t clientId; uint64_t taskId; int64_t refId; int32_t execId; @@ -4261,6 +4270,7 @@ typedef struct { SMsgHead header; uint64_t sId; uint64_t queryId; + uint64_t clientId; uint64_t taskId; uint32_t sqlLen; uint32_t phyLen; diff --git a/include/common/ttime.h b/include/common/ttime.h index 65bb763b1f..1ffcc29eca 100644 --- a/include/common/ttime.h +++ b/include/common/ttime.h @@ -62,7 +62,8 @@ static FORCE_INLINE int64_t taosGetTimestampToday(int32_t precision) { int64_t factor = (precision == TSDB_TIME_PRECISION_MILLI) ? 1000 : (precision == TSDB_TIME_PRECISION_MICRO) ? 1000000 : 1000000000; - time_t t = taosTime(NULL); + time_t t; + (void) taosTime(&t); struct tm tm; (void) taosLocalTime(&t, &tm, NULL, 0); tm.tm_hour = 0; diff --git a/include/libs/executor/executor.h b/include/libs/executor/executor.h index d955a7b3b9..82cb899cb6 100644 --- a/include/libs/executor/executor.h +++ b/include/libs/executor/executor.h @@ -31,7 +31,7 @@ typedef void* DataSinkHandle; struct SRpcMsg; struct SSubplan; -typedef int32_t (*localFetchFp)(void*, uint64_t, uint64_t, uint64_t, int64_t, int32_t, void**, SArray*); +typedef int32_t (*localFetchFp)(void*, uint64_t, uint64_t, uint64_t, uint64_t, int64_t, int32_t, void**, SArray*); typedef struct { void* handle; diff --git a/include/libs/function/tudf.h b/include/libs/function/tudf.h index acdbc09be6..52cb847b6f 100644 --- a/include/libs/function/tudf.h +++ b/include/libs/function/tudf.h @@ -61,6 +61,35 @@ extern "C" { } \ } while (0) +#define TAOS_UDF_CHECK_PTR_RCODE(...) \ + do { \ + const void *ptrs[] = {__VA_ARGS__}; \ + for (int i = 0; i < sizeof(ptrs) / sizeof(ptrs[0]); ++i) { \ + if (ptrs[i] == NULL) { \ + fnError("udfd %dth parameter invalid, NULL PTR.line:%d", i, __LINE__); \ + return TSDB_CODE_INVALID_PARA; \ + } \ + } \ + } while (0) + +#define TAOS_UDF_CHECK_PTR_RVOID(...) \ + do { \ + const void *ptrs[] = {__VA_ARGS__}; \ + for (int i = 0; i < sizeof(ptrs) / sizeof(ptrs[0]); ++i) { \ + if (ptrs[i] == NULL) { \ + fnError("udfd %dth parameter invalid, NULL PTR.line:%d", i, __LINE__); \ + return; \ + } \ + } \ + } while (0) + +#define TAOS_UDF_CHECK_CONDITION(o, code) \ + do { \ + if ((o) == false) { \ + fnError("Condition not met.line:%d", __LINE__); \ + return code; \ + } \ + } while (0) // low level APIs /** diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 514eddbc24..0b617c7ce3 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -42,10 +42,11 @@ extern "C" { #define SHOW_CREATE_VIEW_RESULT_FIELD1_LEN (TSDB_VIEW_FNAME_LEN + 4 + VARSTR_HEADER_SIZE) #define SHOW_CREATE_VIEW_RESULT_FIELD2_LEN (TSDB_MAX_ALLOWED_SQL_LEN + VARSTR_HEADER_SIZE) -#define SHOW_LOCAL_VARIABLES_RESULT_COLS 3 +#define SHOW_LOCAL_VARIABLES_RESULT_COLS 4 #define SHOW_LOCAL_VARIABLES_RESULT_FIELD1_LEN (TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE) -#define SHOW_LOCAL_VARIABLES_RESULT_FIELD2_LEN (TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE) +#define SHOW_LOCAL_VARIABLES_RESULT_FIELD2_LEN (TSDB_CONFIG_PATH_LEN + VARSTR_HEADER_SIZE) #define SHOW_LOCAL_VARIABLES_RESULT_FIELD3_LEN (TSDB_CONFIG_SCOPE_LEN + VARSTR_HEADER_SIZE) +#define SHOW_LOCAL_VARIABLES_RESULT_FIELD4_LEN (TSDB_CONFIG_INFO_LEN + VARSTR_HEADER_SIZE) #define COMPACT_DB_RESULT_COLS 3 #define COMPACT_DB_RESULT_FIELD1_LEN 32 diff --git a/include/libs/nodes/plannodes.h b/include/libs/nodes/plannodes.h index cfd9c1a422..48852e5552 100644 --- a/include/libs/nodes/plannodes.h +++ b/include/libs/nodes/plannodes.h @@ -624,6 +624,7 @@ typedef struct SAggPhysiNode { typedef struct SDownstreamSourceNode { ENodeType type; SQueryNodeAddr addr; + uint64_t clientId; uint64_t taskId; uint64_t schedId; int32_t execId; diff --git a/include/libs/qworker/qworker.h b/include/libs/qworker/qworker.h index 83daf0376c..cb4e359727 100644 --- a/include/libs/qworker/qworker.h +++ b/include/libs/qworker/qworker.h @@ -105,11 +105,11 @@ void qWorkerDestroy(void **qWorkerMgmt); int32_t qWorkerGetStat(SReadHandle *handle, void *qWorkerMgmt, SQWorkerStat *pStat); -int32_t qWorkerProcessLocalQuery(void *pMgmt, uint64_t sId, uint64_t qId, uint64_t tId, int64_t rId, int32_t eId, - SQWMsg *qwMsg, SArray *explainRes); +int32_t qWorkerProcessLocalQuery(void *pMgmt, uint64_t sId, uint64_t qId, uint64_t cId, uint64_t tId, int64_t rId, + int32_t eId, SQWMsg *qwMsg, SArray *explainRes); -int32_t qWorkerProcessLocalFetch(void *pMgmt, uint64_t sId, uint64_t qId, uint64_t tId, int64_t rId, int32_t eId, - void **pRsp, SArray *explainRes); +int32_t qWorkerProcessLocalFetch(void *pMgmt, uint64_t sId, uint64_t qId, uint64_t cId, uint64_t tId, int64_t rId, + int32_t eId, void **pRsp, SArray *explainRes); int32_t qWorkerDbgEnableDebug(char *option); diff --git a/include/libs/scheduler/scheduler.h b/include/libs/scheduler/scheduler.h index af8deff1a0..2988ffc4b1 100644 --- a/include/libs/scheduler/scheduler.h +++ b/include/libs/scheduler/scheduler.h @@ -83,6 +83,9 @@ void schedulerStopQueryHb(void* pTrans); int32_t schedulerUpdatePolicy(int32_t policy); int32_t schedulerEnableReSchedule(bool enableResche); +int32_t initClientId(void); +uint64_t getClientId(void); + /** * Cancel query job * @param pJob diff --git a/include/os/os.h b/include/os/os.h index e3808065dd..4314148685 100644 --- a/include/os/os.h +++ b/include/os/os.h @@ -137,6 +137,14 @@ extern threadlocal bool tsEnableRandErr; terrno = _code; \ } +#define OS_PARAM_CHECK(_o) \ + do { \ + if ((_o) == NULL) { \ + terrno = TSDB_CODE_INVALID_PARA; \ + return terrno; \ + } \ + } while (0) + #ifdef __cplusplus } #endif diff --git a/include/os/osSystem.h b/include/os/osSystem.h index fe181d291a..06f23eec0f 100644 --- a/include/os/osSystem.h +++ b/include/os/osSystem.h @@ -48,8 +48,6 @@ void taosCloseCmd(TdCmdPtr *ppCmd); void *taosLoadDll(const char *filename); -void *taosLoadSym(void *handle, char *name); - void taosCloseDll(void *handle); int32_t taosSetConsoleEcho(bool on); diff --git a/include/os/osTime.h b/include/os/osTime.h index 5d74146e9c..7a65efe28d 100644 --- a/include/os/osTime.h +++ b/include/os/osTime.h @@ -93,7 +93,7 @@ static FORCE_INLINE int64_t taosGetMonoTimestampMs() { char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm); struct tm *taosLocalTime(const time_t *timep, struct tm *result, char *buf, int32_t bufSize); struct tm *taosLocalTimeNolock(struct tm *result, const time_t *timep, int dst); -time_t taosTime(time_t *t); +int32_t taosTime(time_t *t); time_t taosMktime(struct tm *timep); int64_t user_mktime64(const uint32_t year, const uint32_t mon, const uint32_t day, const uint32_t hour, const uint32_t min, const uint32_t sec, int64_t time_zone); diff --git a/include/util/taoserror.h b/include/util/taoserror.h index b563c186c3..e33af33d0e 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -208,6 +208,7 @@ int32_t taosGetErrSize(); #define TSDB_CODE_TSC_COMPRESS_PARAM_ERROR TAOS_DEF_ERROR_CODE(0, 0X0233) #define TSDB_CODE_TSC_COMPRESS_LEVEL_ERROR TAOS_DEF_ERROR_CODE(0, 0X0234) #define TSDB_CODE_TSC_FAIL_GENERATE_JSON TAOS_DEF_ERROR_CODE(0, 0X0235) +#define TSDB_CODE_TSC_STMT_BIND_NUMBER_ERROR TAOS_DEF_ERROR_CODE(0, 0X0236) #define TSDB_CODE_TSC_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0X02FF) // mnode-common diff --git a/include/util/tdef.h b/include/util/tdef.h index ba30e78c59..4e1fb21838 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -195,9 +195,9 @@ static const EOperatorType OPERATOR_ARRAY[] = { OP_TYPE_MULTI, OP_TYPE_DIV, OP_TYPE_REM, - + OP_TYPE_MINUS, - + OP_TYPE_BIT_AND, OP_TYPE_BIT_OR, @@ -213,7 +213,7 @@ static const EOperatorType OPERATOR_ARRAY[] = { OP_TYPE_NOT_LIKE, OP_TYPE_MATCH, OP_TYPE_NMATCH, - + OP_TYPE_IS_NULL, OP_TYPE_IS_NOT_NULL, OP_TYPE_IS_TRUE, @@ -222,7 +222,7 @@ static const EOperatorType OPERATOR_ARRAY[] = { OP_TYPE_IS_NOT_TRUE, OP_TYPE_IS_NOT_FALSE, OP_TYPE_IS_NOT_UNKNOWN, - //OP_TYPE_COMPARE_MAX_VALUE, + //OP_TYPE_COMPARE_MAX_VALUE, OP_TYPE_JSON_GET_VALUE, OP_TYPE_JSON_CONTAINS, @@ -631,6 +631,8 @@ enum { RAND_ERR_MEMORY = 1, RAND_ERR_FILE = 2, RAND_ERR_NETWORK = 4 }; #define TSDB_CONFIG_VALUE_LEN 64 #define TSDB_CONFIG_SCOPE_LEN 8 #define TSDB_CONFIG_NUMBER 16 +#define TSDB_CONFIG_PATH_LEN 4096 +#define TSDB_CONFIG_INFO_LEN 64 #define QUERY_ID_SIZE 20 #define QUERY_OBJ_ID_SIZE 18 diff --git a/include/util/tjson.h b/include/util/tjson.h index 88c2a1efb7..728b6b5585 100644 --- a/include/util/tjson.h +++ b/include/util/tjson.h @@ -25,7 +25,7 @@ extern "C" { #define tjsonGetNumberValue(pJson, pName, val, code) \ do { \ - uint64_t _tmp = 0; \ + int64_t _tmp = 0; \ code = tjsonGetBigIntValue(pJson, pName, &_tmp); \ val = _tmp; \ } while (0) diff --git a/include/util/tutil.h b/include/util/tutil.h index 87710b091d..aa3b774e84 100644 --- a/include/util/tutil.h +++ b/include/util/tutil.h @@ -120,6 +120,18 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen, } } +/* + * LIKELY and UNLIKELY macros for branch predication hints. Use them judiciously + * only in very hot code paths. Misuse or abuse can lead to performance degradation. + */ +#if __GNUC__ >= 3 +#define LIKELY(x) __builtin_expect((x) != 0, 1) +#define UNLIKELY(x) __builtin_expect((x) != 0, 0) +#else +#define LIKELY(x) ((x) != 0) +#define UNLIKELY(x) ((x) != 0) +#endif + #define TAOS_CHECK_ERRNO(CODE) \ do { \ terrno = (CODE); \ @@ -129,25 +141,27 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen, } \ } while (0) -#define TSDB_CHECK_CODE(CODE, LINO, LABEL) \ - do { \ - if (TSDB_CODE_SUCCESS != (CODE)) { \ - LINO = __LINE__; \ - goto LABEL; \ - } \ +#define TSDB_CHECK_CODE(CODE, LINO, LABEL) \ + do { \ + if (UNLIKELY(TSDB_CODE_SUCCESS != (CODE))) { \ + LINO = __LINE__; \ + goto LABEL; \ + } \ } while (0) #define QUERY_CHECK_CODE TSDB_CHECK_CODE -#define QUERY_CHECK_CONDITION(condition, CODE, LINO, LABEL, ERRNO) \ - if (!condition) { \ - (CODE) = (ERRNO); \ - (LINO) = __LINE__; \ - goto LABEL; \ +#define TSDB_CHECK_CONDITION(condition, CODE, LINO, LABEL, ERRNO) \ + if (UNLIKELY(!(condition))) { \ + (CODE) = (ERRNO); \ + (LINO) = __LINE__; \ + goto LABEL; \ } +#define QUERY_CHECK_CONDITION TSDB_CHECK_CONDITION + #define TSDB_CHECK_NULL(ptr, CODE, LINO, LABEL, ERRNO) \ - if ((ptr) == NULL) { \ + if (UNLIKELY((ptr) == NULL)) { \ (CODE) = (ERRNO); \ (LINO) = __LINE__; \ goto LABEL; \ diff --git a/packaging/delete_ref_lock.py b/packaging/delete_ref_lock.py new file mode 100644 index 0000000000..cf0e4cdd05 --- /dev/null +++ b/packaging/delete_ref_lock.py @@ -0,0 +1,59 @@ +import subprocess +import re + +# 执行 git fetch 命令并捕获输出 +def git_fetch(): + result = subprocess.run(['git', 'fetch'], capture_output=True, text=True) + return result + +# 解析分支名称 +def parse_branch_name_type1(error_output): + # 使用正则表达式匹配 'is at' 前的分支名称 + match = re.search(r"error: cannot lock ref '(refs/remotes/origin/[^']+)': is at", error_output) + if match: + return match.group(1) + return None + +# 解析第二种错误中的分支名称 +def parse_branch_name_type2(error_output): + # 使用正则表达式匹配 'exists' 前的第一个引号内的分支名称 + match = re.search(r"'(refs/remotes/origin/[^']+)' exists;", error_output) + if match: + return match.group(1) + return None + +# 执行 git update-ref -d 命令 +def git_update_ref(branch_name): + if branch_name: + subprocess.run(['git', 'update-ref', '-d', f'{branch_name}'], check=True) + +# 解析错误类型并执行相应的修复操作 +def handle_error(error_output): + # 错误类型1:本地引用的提交ID与远程不一致 + if "is at" in error_output and "but expected" in error_output: + branch_name = parse_branch_name_type1(error_output) + if branch_name: + print(f"Detected error type 1, attempting to delete ref for branch: {branch_name}") + git_update_ref(branch_name) + else: + print("Error parsing branch name for type 1.") + # 错误类型2:尝试创建新的远程引用时,本地已经存在同名的引用 + elif "exists; cannot create" in error_output: + branch_name = parse_branch_name_type2(error_output) + if branch_name: + print(f"Detected error type 2, attempting to delete ref for branch: {branch_name}") + git_update_ref(branch_name) + else: + print("Error parsing branch name for type 2.") + +# 主函数 +def main(): + fetch_result = git_fetch() + if fetch_result.returncode != 0: # 如果 git fetch 命令失败 + error_output = fetch_result.stderr + handle_error(error_output) + else: + print("Git fetch successful.") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/packaging/smokeTest/assets/style.css b/packaging/smokeTest/assets/style.css new file mode 100644 index 0000000000..c89d42818c --- /dev/null +++ b/packaging/smokeTest/assets/style.css @@ -0,0 +1,319 @@ +body { + font-family: Helvetica, Arial, sans-serif; + font-size: 12px; + /* do not increase min-width as some may use split screens */ + min-width: 800px; + color: #999; + } + + h1 { + font-size: 24px; + color: black; + } + + h2 { + font-size: 16px; + color: black; + } + + p { + color: black; + } + + a { + color: #999; + } + + table { + border-collapse: collapse; + } + + /****************************** + * SUMMARY INFORMATION + ******************************/ + #environment td { + padding: 5px; + border: 1px solid #e6e6e6; + vertical-align: top; + } + #environment tr:nth-child(odd) { + background-color: #f6f6f6; + } + #environment ul { + margin: 0; + padding: 0 20px; + } + + /****************************** + * TEST RESULT COLORS + ******************************/ + span.passed, + .passed .col-result { + color: green; + } + + span.skipped, + span.xfailed, + span.rerun, + .skipped .col-result, + .xfailed .col-result, + .rerun .col-result { + color: orange; + } + + span.error, + span.failed, + span.xpassed, + .error .col-result, + .failed .col-result, + .xpassed .col-result { + color: red; + } + + .col-links__extra { + margin-right: 3px; + } + + /****************************** + * RESULTS TABLE + * + * 1. Table Layout + * 2. Extra + * 3. Sorting items + * + ******************************/ + /*------------------ + * 1. Table Layout + *------------------*/ + #results-table { + border: 1px solid #e6e6e6; + color: #999; + font-size: 12px; + width: 100%; + } + #results-table th, + #results-table td { + padding: 5px; + border: 1px solid #e6e6e6; + text-align: left; + } + #results-table th { + font-weight: bold; + } + + /*------------------ + * 2. Extra + *------------------*/ + .logwrapper { + max-height: 230px; + overflow-y: scroll; + background-color: #e6e6e6; + } + .logwrapper.expanded { + max-height: none; + } + .logwrapper.expanded .logexpander:after { + content: "collapse [-]"; + } + .logwrapper .logexpander { + z-index: 1; + position: sticky; + top: 10px; + width: max-content; + border: 1px solid; + border-radius: 3px; + padding: 5px 7px; + margin: 10px 0 10px calc(100% - 80px); + cursor: pointer; + background-color: #e6e6e6; + } + .logwrapper .logexpander:after { + content: "expand [+]"; + } + .logwrapper .logexpander:hover { + color: #000; + border-color: #000; + } + .logwrapper .log { + min-height: 40px; + position: relative; + top: -50px; + height: calc(100% + 50px); + border: 1px solid #e6e6e6; + color: black; + display: block; + font-family: "Courier New", Courier, monospace; + padding: 5px; + padding-right: 80px; + white-space: pre-wrap; + } + + div.media { + border: 1px solid #e6e6e6; + float: right; + height: 240px; + margin: 0 5px; + overflow: hidden; + width: 320px; + } + + .media-container { + display: grid; + grid-template-columns: 25px auto 25px; + align-items: center; + flex: 1 1; + overflow: hidden; + height: 200px; + } + + .media-container--fullscreen { + grid-template-columns: 0px auto 0px; + } + + .media-container__nav--right, + .media-container__nav--left { + text-align: center; + cursor: pointer; + } + + .media-container__viewport { + cursor: pointer; + text-align: center; + height: inherit; + } + .media-container__viewport img, + .media-container__viewport video { + object-fit: cover; + width: 100%; + max-height: 100%; + } + + .media__name, + .media__counter { + display: flex; + flex-direction: row; + justify-content: space-around; + flex: 0 0 25px; + align-items: center; + } + + .collapsible td:not(.col-links) { + cursor: pointer; + } + .collapsible td:not(.col-links):hover::after { + color: #bbb; + font-style: italic; + cursor: pointer; + } + + .col-result { + width: 130px; + } + .col-result:hover::after { + content: " (hide details)"; + } + + .col-result.collapsed:hover::after { + content: " (show details)"; + } + + #environment-header h2:hover::after { + content: " (hide details)"; + color: #bbb; + font-style: italic; + cursor: pointer; + font-size: 12px; + } + + #environment-header.collapsed h2:hover::after { + content: " (show details)"; + color: #bbb; + font-style: italic; + cursor: pointer; + font-size: 12px; + } + + /*------------------ + * 3. Sorting items + *------------------*/ + .sortable { + cursor: pointer; + } + .sortable.desc:after { + content: " "; + position: relative; + left: 5px; + bottom: -12.5px; + border: 10px solid #4caf50; + border-bottom: 0; + border-left-color: transparent; + border-right-color: transparent; + } + .sortable.asc:after { + content: " "; + position: relative; + left: 5px; + bottom: 12.5px; + border: 10px solid #4caf50; + border-top: 0; + border-left-color: transparent; + border-right-color: transparent; + } + + .hidden, .summary__reload__button.hidden { + display: none; + } + + .summary__data { + flex: 0 0 550px; + } + .summary__reload { + flex: 1 1; + display: flex; + justify-content: center; + } + .summary__reload__button { + flex: 0 0 300px; + display: flex; + color: white; + font-weight: bold; + background-color: #4caf50; + text-align: center; + justify-content: center; + align-items: center; + border-radius: 3px; + cursor: pointer; + } + .summary__reload__button:hover { + background-color: #46a049; + } + .summary__spacer { + flex: 0 0 550px; + } + + .controls { + display: flex; + justify-content: space-between; + } + + .filters, + .collapse { + display: flex; + align-items: center; + } + .filters button, + .collapse button { + color: #999; + border: none; + background: none; + cursor: pointer; + text-decoration: underline; + } + .filters button:hover, + .collapse button:hover { + color: #ccc; + } + + .filter__label { + margin-right: 10px; + } \ No newline at end of file diff --git a/packaging/smokeTest/conftest.py b/packaging/smokeTest/conftest.py new file mode 100644 index 0000000000..a5f6ebbbe9 --- /dev/null +++ b/packaging/smokeTest/conftest.py @@ -0,0 +1,115 @@ +# conftest.py +import pytest + + +def pytest_addoption(parser): + parser.addoption( + "--verMode", default="enterprise", help="community or enterprise" + ) + parser.addoption( + "--tVersion", default="3.3.2.6", help="the version of taos" + ) + parser.addoption( + "--baseVersion", default="smoking", help="the path of nas" + ) + parser.addoption( + "--sourcePath", default="nas", help="only support nas currently" + ) + + + + +# Collect the setup and teardown of each test case and their std information +setup_stdout_info = {} +teardown_stdout_info = {} + + +@pytest.hookimpl(hookwrapper=True) +def pytest_runtest_makereport(item, call): + outcome = yield + rep = outcome.get_result() + + # Record the std of setup and teardown + if call.when == 'setup': + for i in rep.sections: + if i[0] == "Captured stdout setup": + if not setup_stdout_info: + setup_stdout_info[item.nodeid] = i[1] + elif call.when == 'teardown': + for i in rep.sections: + if i[0] == "Captured stdout teardown": + teardown_stdout_info[item.nodeid] = i[1] + + +# Insert setup and teardown's std in the summary section +def pytest_html_results_summary(prefix, summary, postfix): + if setup_stdout_info or teardown_stdout_info: + rows = [] + + # Insert setup stdout + if setup_stdout_info: + for nodeid, stdout in setup_stdout_info.items(): + html_content = ''' + + Setup: + + Show Setup + + + + '''.format(stdout.strip()) + + # 如果需要在 Python 脚本中生成 HTML,并使用 JavaScript 控制折叠内容的显示,可以这样做: + + html_script = ''' + + ''' + + # 输出完整的 HTML 代码 + final_html = html_content + html_script + rows.append(final_html) + rows.append("
") + # Insert teardown stdout + if teardown_stdout_info: + for nodeid, stdout in teardown_stdout_info.items(): + html_content = ''' + + Teardown: + + Show Teardown + + + + '''.format(stdout.strip()) + + # 如果需要在 Python 脚本中生成 HTML,并使用 JavaScript 控制折叠内容的显示,可以这样做: + + html_script = ''' + + ''' + + # 输出完整的 HTML 代码 + final_html = html_content + html_script + rows.append(final_html) + + prefix.extend(rows) diff --git a/packaging/smokeTest/debRpmAutoInstall.sh b/packaging/smokeTest/debRpmAutoInstall.sh new file mode 100755 index 0000000000..8fadffe4c6 --- /dev/null +++ b/packaging/smokeTest/debRpmAutoInstall.sh @@ -0,0 +1,15 @@ +#!/usr/bin/expect +set packageName [lindex $argv 0] +set packageSuffix [lindex $argv 1] +set timeout 30 +if { ${packageSuffix} == "deb" } { + spawn dpkg -i ${packageName} +} elseif { ${packageSuffix} == "rpm"} { + spawn rpm -ivh ${packageName} +} +expect "*one:" +send "\r" +expect "*skip:" +send "\r" + +expect eof diff --git a/packaging/smokeTest/getAndRunInstaller.bat b/packaging/smokeTest/getAndRunInstaller.bat new file mode 100644 index 0000000000..08b04a0271 --- /dev/null +++ b/packaging/smokeTest/getAndRunInstaller.bat @@ -0,0 +1,57 @@ +set baseVersion=%1% +set version=%2% +set verMode=%3% +set sType=%4% +echo %fileType% +rem stop services +if EXIST C:\TDengine ( + if EXIST C:\TDengine\stop-all.bat ( + call C:\TDengine\stop-all.bat /silent + echo "***************Stop taos services***************" + ) + if exist C:\TDengine\unins000.exe ( + call C:\TDengine\unins000.exe /silent + echo "***************uninstall TDengine***************" + ) + rd /S /q C:\TDengine +) +if EXIST C:\ProDB ( + if EXIST C:\ProDB\stop-all.bat ( + call C:\ProDB\stop-all.bat /silent + echo "***************Stop taos services***************" + ) + if exist C:\ProDB\unins000.exe ( + call C:\ProDB\unins000.exe /silent + echo "***************uninstall TDengine***************" + ) + rd /S /q C:\ProDB +) +if "%verMode%"=="enterprise" ( + if "%sType%"=="client" ( + set fileType=enterprise-client + ) else ( + set fileType=enterprise + ) +) else ( + set fileType=%sType% +) + +if "%baseVersion%"=="ProDB" ( + echo %fileType% + set installer=ProDB-%fileType%-%version%-Windows-x64.exe +) else ( + echo %fileType% + set installer=TDengine-%fileType%-%version%-Windows-x64.exe +) + +if "%baseVersion%"=="ProDB" ( + echo %installer% + scp root@192.168.1.213:/nas/OEM/ProDB/v%version%/%installer% C:\workspace +) else ( + echo %installer% + scp root@192.168.1.213:/nas/TDengine/%baseVersion%/v%version%/%verMode%/%installer% C:\workspace +) + +echo "***************Finish installer transfer!***************" +C:\workspace\%installer% /silent +echo "***************Finish install!***************" \ No newline at end of file diff --git a/packaging/smokeTest/getAndRunInstaller.sh b/packaging/smokeTest/getAndRunInstaller.sh new file mode 100755 index 0000000000..7defe6394c --- /dev/null +++ b/packaging/smokeTest/getAndRunInstaller.sh @@ -0,0 +1,325 @@ +#!/bin/sh + + +function usage() { + echo "$0" + echo -e "\t -f test file type,server/client/tools/" + echo -e "\t -m pacakage version Type,community/enterprise" + echo -e "\t -l package type,lite or not" + echo -e "\t -c operation type,x64/arm64" + echo -e "\t -v pacakage version,3.0.1.7" + echo -e "\t -o pacakage version,3.0.1.7" + echo -e "\t -s source Path,web/nas" + echo -e "\t -t package Type,tar/rpm/deb" + echo -e "\t -h help" +} + + +#parameter +scriptDir=$(dirname $(readlink -f $0)) +version="3.0.1.7" +originversion="smoking" +testFile="server" +verMode="communtity" +sourcePath="nas" +cpuType="x64" +lite="true" +packageType="tar" +subFile="package.tar.gz" +while getopts "m:c:f:l:s:o:t:v:h" opt; do + case $opt in + m) + verMode=$OPTARG + ;; + v) + version=$OPTARG + ;; + f) + testFile=$OPTARG + ;; + l) + lite=$OPTARG + ;; + s) + sourcePath=$OPTARG + ;; + o) + originversion=$OPTARG + ;; + c) + cpuType=$OPTARG + ;; + t) + packageType=$OPTARG + ;; + h) + usage + exit 0 + ;; + ?) + echo "Invalid option: -$OPTARG" + usage + exit 0 + ;; + esac +done + +systemType=`uname` +if [ ${systemType} == "Darwin" ]; then + platform="macOS" +else + platform="Linux" +fi + +echo "testFile:${testFile},verMode:${verMode},lite:${lite},cpuType:${cpuType},packageType:${packageType},version-${version},originversion:${originversion},sourcePath:${sourcePath}" +# Color setting +RED='\033[41;30m' +GREEN='\033[1;32m' +YELLOW='\033[1;33m' +BLUE='\033[1;34m' +GREEN_DARK='\033[0;32m' +YELLOW_DARK='\033[0;33m' +BLUE_DARK='\033[0;34m' +GREEN_UNDERLINE='\033[4;32m' +NC='\033[0m' +if [ "${originversion}" = "ProDB" ]; then + TDengine="ProDB" +else + TDengine="TDengine" +fi +if [[ ${verMode} = "enterprise" ]];then + prePackage="${TDengine}-enterprise" + if [[ ${testFile} = "client" ]];then + prePackage="${TDengine}-enterprise-${testFile}" + fi +elif [ ${verMode} = "community" ];then + prePackage="${TDengine}-${testFile}" +fi +if [ ${lite} = "true" ];then + packageLite="-Lite" +elif [ ${lite} = "false" ];then + packageLite="" +fi +if [[ "$packageType" = "tar" ]] ;then + packageType="tar.gz" +fi + +tdPath="${prePackage}-${version}" + +packageName="${tdPath}-${platform}-${cpuType}${packageLite}.${packageType}" + +if [ "$testFile" == "server" ] ;then + installCmd="install.sh" +elif [ ${testFile} = "client" ];then + installCmd="install_client.sh" +fi + +echo "tdPath:${tdPath},packageName:${packageName}}" +cmdInstall() { +command=$1 +if command -v ${command} ;then + echoColor YD "${command} is already installed" +else + if command -v apt ;then + apt-get install ${command} -y + elif command -v yum ;then + yum -y install ${command} + echoColor YD "you should install ${command} manually" + fi +fi +} + +echoColor() { + color=$1 + command=$2 + if [ ${color} = 'Y' ];then + echo -e "${YELLOW}${command}${NC}" + elif [ ${color} = 'YD' ];then + echo -e "${YELLOW_DARK}${command}${NC}" + elif [ ${color} = 'R' ];then + echo -e "${RED}${command}${NC}" + elif [ ${color} = 'G' ];then + echo -e "${GREEN}${command}${NC}\r\n" + elif [ ${color} = 'B' ];then + echo -e "${BLUE}${command}${NC}" + elif [ ${color} = 'BD' ];then + echo -e "${BLUE_DARK}${command}${NC}" + fi +} + +wgetFile() { + + file=$1 + versionPath=$2 + sourceP=$3 + nasServerIP="192.168.1.213" + if [ "${originversion}" = "ProDB" ]; then + packagePath="/nas/OEM/ProDB/v${versionPath}" + else + packagePath="/nas/TDengine/${originversion}/v${versionPath}/${verMode}" + fi + if [ -f ${file} ];then + echoColor YD "${file} already exists ,it will delete it and download it again " + # rm -rf ${file} + fi + + if [[ ${sourceP} = 'web' ]];then + echoColor BD "====download====:wget https://www.taosdata.com/assets-download/3.0/${file}" + wget https://www.taosdata.com/assets-download/3.0/${file} + elif [[ ${sourceP} = 'nas' ]];then + echoColor BD "====download====:scp root@${nasServerIP}:${packagePath}/${file} ." + scp root@${nasServerIP}:${packagePath}/${file} . + fi +} + +function newPath { + +buildPath=$1 + +if [ ! -d ${buildPath} ] ;then + echoColor BD "mkdir -p ${buildPath}" + mkdir -p ${buildPath} +else + echoColor YD "${buildPath} already exists" +fi + +} + +echoColor G "===== install basesoft =====" +cmdInstall tree +cmdInstall wget +cmdInstall expect + +echoColor G "===== Uninstall all components of TDeingne =====" + +if command -v rmtaos ;then + echoColor YD "uninstall all components of TDeingne:rmtaos" + rmtaos +else + echoColor YD "os doesn't include TDengine" +fi + +if [[ ${packageName} =~ "server" ]] ;then + echoColor BD " pkill -9 taosd " + pkill -9 taosd +fi + +if command -v rmprodb ;then + echoColor YD "uninstall all components of TDeingne:rmprodb" + rmprodb +else + echoColor YD "os doesn't include TDengine" +fi + +if [[ ${packageName} =~ "server" ]] ;then + echoColor BD " pkill -9 prodbd " + pkill -9 prodbd +fi + +echoColor G "===== new workroom path =====" +installPath="/usr/local/src/packageTest" + +if [ ${systemType} == "Darwin" ]; then + installPath="${WORK_DIR}/packageTest" +fi + +newPath ${installPath} + +#if [ -d ${installPath}/${tdPath} ] ;then +# echoColor BD "rm -rf ${installPath}/${tdPath}/*" +# rm -rf ${installPath}/${tdPath}/* +#fi + +echoColor G "===== download installPackage =====" +cd ${installPath} && wgetFile ${packageName} ${version} ${sourcePath} +#cd ${oriInstallPath} && wgetFile ${originPackageName} ${originversion} ${sourcePath} + + +cd ${installPath} +cp -r ${scriptDir}/debRpmAutoInstall.sh . + +packageSuffix=$(echo ${packageName} | awk -F '.' '{print $NF}') + + +if [ ! -f debRpmAutoInstall.sh ];then + echo '#!/usr/bin/expect ' > debRpmAutoInstall.sh + echo 'set packageName [lindex $argv 0]' >> debRpmAutoInstall.sh + echo 'set packageSuffix [lindex $argv 1]' >> debRpmAutoInstall.sh + echo 'set timeout 30 ' >> debRpmAutoInstall.sh + echo 'if { ${packageSuffix} == "deb" } {' >> debRpmAutoInstall.sh + echo ' spawn dpkg -i ${packageName} ' >> debRpmAutoInstall.sh + echo '} elseif { ${packageSuffix} == "rpm"} {' >> debRpmAutoInstall.sh + echo ' spawn rpm -ivh ${packageName}' >> debRpmAutoInstall.sh + echo '}' >> debRpmAutoInstall.sh + echo 'expect "*one:"' >> debRpmAutoInstall.sh + echo 'send "\r"' >> debRpmAutoInstall.sh + echo 'expect "*skip:"' >> debRpmAutoInstall.sh + echo 'send "\r" ' >> debRpmAutoInstall.sh +fi + + +echoColor G "===== install Package =====" + +if [[ ${packageName} =~ "deb" ]];then + cd ${installPath} + dpkg -r taostools + dpkg -r tdengine + if [[ ${packageName} =~ "TDengine" ]];then + echoColor BD "./debRpmAutoInstall.sh ${packageName} ${packageSuffix}" && chmod 755 debRpmAutoInstall.sh && ./debRpmAutoInstall.sh ${packageName} ${packageSuffix} + else + echoColor BD "dpkg -i ${packageName}" && dpkg -i ${packageName} + fi +elif [[ ${packageName} =~ "rpm" ]];then + cd ${installPath} + sudo rpm -e tdengine + sudo rpm -e taostools + if [[ ${packageName} =~ "TDengine" ]];then + echoColor BD "./debRpmAutoInstall.sh ${packageName} ${packageSuffix}" && chmod 755 debRpmAutoInstall.sh && ./debRpmAutoInstall.sh ${packageName} ${packageSuffix} + else + echoColor BD "rpm -ivh ${packageName}" && rpm -ivh ${packageName} + fi +elif [[ ${packageName} =~ "tar" ]];then + echoColor G "===== check installPackage File of tar =====" + + cd ${installPath} + echoColor YD "unzip the new installation package" + echoColor BD "tar -xf ${packageName}" && tar -xf ${packageName} + + cd ${installPath}/${tdPath} && tree -I "driver" > ${installPath}/now_${version}_checkfile + + cd ${installPath} + diff ${installPath}/base_${originversion}_checkfile ${installPath}/now_${version}_checkfile > ${installPath}/diffFile.log + diffNumbers=`cat ${installPath}/diffFile.log |wc -l ` + + if [ ${diffNumbers} != 0 ];then + echoColor R "The number and names of files is different from the previous installation package" + diffLog=`cat ${installPath}/diffFile.log` + echoColor Y "${diffLog}" + exit -1 + else + echoColor G "The number and names of files are the same as previous installation packages" + rm -rf ${installPath}/diffFile.log + fi + echoColor YD "===== install Package of tar =====" + cd ${installPath}/${tdPath} + if [ ${testFile} = "server" ];then + echoColor BD "bash ${installCmd} -e no " + bash ${installCmd} -e no + else + echoColor BD "bash ${installCmd} " + bash ${installCmd} + fi +elif [[ ${packageName} =~ "pkg" ]];then + cd ${installPath} + sudo installer -pkg ${packageName} -target / + echoColor YD "===== install Package successfully! =====" +fi + +#cd ${installPath} +# +#rm -rf ${installPath}/${packageName} +#if [ ${platform} == "Linux" ]; then +# rm -rf ${installPath}/${tdPath}/ +#fi +echoColor YD "===== end of shell file =====" + diff --git a/packaging/smokeTest/lib.py b/packaging/smokeTest/lib.py new file mode 100644 index 0000000000..86c30bf8b1 --- /dev/null +++ b/packaging/smokeTest/lib.py @@ -0,0 +1,12 @@ + +import subprocess + + +def run_cmd(command): + print("CMD:", command) + result = subprocess.run(command, capture_output=True, text=True, shell=True) + print("STDOUT:", result.stdout) + print("STDERR:", result.stderr) + print("Return Code:", result.returncode) + #assert result.returncode == 0 + return result diff --git a/packaging/smokeTest/main.py b/packaging/smokeTest/main.py new file mode 100644 index 0000000000..cb7356f80e --- /dev/null +++ b/packaging/smokeTest/main.py @@ -0,0 +1,21 @@ +import pytest + +# python3 -m pytest test_server.py -v --html=/var/www/html/report.html --json-report --json-report-file="/var/www/html/report.json" --timeout=60 + +# pytest.main(["-s", "-v"]) +import pytest + +import subprocess + + +# define cmd function + + + + +def main(): + pytest.main(['--html=report.html']) + + +if __name__ == '__main__': + main() diff --git a/packaging/smokeTest/pytest_require.txt b/packaging/smokeTest/pytest_require.txt new file mode 100644 index 0000000000..34019c6e8a --- /dev/null +++ b/packaging/smokeTest/pytest_require.txt @@ -0,0 +1,17 @@ +pytest-html +pytest-json-report +pytest-timeout +taospy +numpy +fabric2 +psutil +pandas +toml +distro +requests +pexpect +faker +pyopenssl +taos-ws-py +taospy +tzlocal \ No newline at end of file diff --git a/packaging/smokeTest/runCases.bat b/packaging/smokeTest/runCases.bat new file mode 100644 index 0000000000..922766785c --- /dev/null +++ b/packaging/smokeTest/runCases.bat @@ -0,0 +1,11 @@ +rm -rf %WIN_TDENGINE_ROOT_DIR%\debug +mkdir %WIN_TDENGINE_ROOT_DIR%\debug +mkdir %WIN_TDENGINE_ROOT_DIR%\debug\build +mkdir %WIN_TDENGINE_ROOT_DIR%\debug\build\bin +xcopy C:\TDengine\taos*.exe %WIN_TDENGINE_ROOT_DIR%\debug\build\bin + +set case_out_file=%cd%\case.out + +cd %WIN_TDENGINE_ROOT_DIR%\tests\system-test +python3 .\test.py -f 0-others\taosShell.py +python3 .\test.py -f 6-cluster\5dnode3mnodeSep1VnodeStopDnodeModifyMeta.py -N 6 -M 3 \ No newline at end of file diff --git a/packaging/smokeTest/runCases.sh b/packaging/smokeTest/runCases.sh new file mode 100644 index 0000000000..4de7a7658b --- /dev/null +++ b/packaging/smokeTest/runCases.sh @@ -0,0 +1,29 @@ +#!/bin/bash +ulimit -c unlimited + +rm -rf ${TDENGINE_ROOT_DIR}/debug +mkdir ${TDENGINE_ROOT_DIR}/debug +mkdir ${TDENGINE_ROOT_DIR}/debug/build +mkdir ${TDENGINE_ROOT_DIR}/debug/build/bin + +systemType=`uname` +if [ ${systemType} == "Darwin" ]; then + cp /usr/local/bin/taos* ${TDENGINE_ROOT_DIR}/debug/build/bin/ +else + cp /usr/bin/taos* ${TDENGINE_ROOT_DIR}/debug/build/bin/ +fi + +case_out_file=`pwd`/case.out +python3 -m pip install -r ${TDENGINE_ROOT_DIR}/tests/requirements.txt >> $case_out_file +python3 -m pip install taos-ws-py taospy >> $case_out_file + +cd ${TDENGINE_ROOT_DIR}/tests/army +python3 ./test.py -f query/query_basic.py -N 3 >> $case_out_file + +cd ${TDENGINE_ROOT_DIR}/tests/system-test +python3 ./test.py -f 1-insert/insert_column_value.py >> $case_out_file +python3 ./test.py -f 2-query/primary_ts_base_5.py >> $case_out_file +python3 ./test.py -f 2-query/case_when.py >> $case_out_file +python3 ./test.py -f 2-query/partition_limit_interval.py >> $case_out_file +python3 ./test.py -f 2-query/join.py >> $case_out_file +python3 ./test.py -f 2-query/fill.py >> $case_out_file diff --git a/packaging/smokeTest/smokeTestClient.py b/packaging/smokeTest/smokeTestClient.py new file mode 100644 index 0000000000..eee9667300 --- /dev/null +++ b/packaging/smokeTest/smokeTestClient.py @@ -0,0 +1,251 @@ +#!/usr/bin/python +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### +# install pip +# pip install src/connector/python/ + +# -*- coding: utf-8 -*- +import sys, os +import re +import platform +import getopt +import subprocess +# from this import d +import time + +# input for server + +opts, args = getopt.gnu_getopt(sys.argv[1:], 'h:P:v:u', [ + 'host=', 'Port=', 'version=']) +serverHost = "" +serverPort = 0 +version = "" +uninstall = False +for key, value in opts: + if key in ['--help']: + print('A collection of test cases written using Python') + print('-h serverHost') + print('-P serverPort') + print('-v test client version') + print('-u test uninstall process, will uninstall TDengine') + sys.exit(0) + + if key in ['-h']: + serverHost = value + if key in ['-P']: + serverPort = int(value) + if key in ['-v']: + version = value + if key in ['-u']: + uninstall = True +if not serverHost: + print("Please input use -h to specify your server host.") + sys.exit(0) +if not version: + print("No version specified, will not run version check.") +if serverPort == 0: + serverPort = 6030 + print("No server port specified, use default 6030.") + + +system = platform.system() + +arch = platform.machine() + +databaseName = re.sub(r'[^a-zA-Z0-9]', '', subprocess.getoutput("hostname")).lower() +# install taospy +taospy_version = "" +if system == 'Windows': + taospy_version = subprocess.getoutput("pip3 show taospy|findstr Version") +else: + taospy_version = subprocess.getoutput("pip3 show taospy|grep Version| awk -F ':' '{print $2}' ") + +print("taospy version %s " % taospy_version) +if taospy_version == "": + subprocess.getoutput("pip3 install git+https://github.com/taosdata/taos-connector-python.git") + print("install taos python connector") +else: + subprocess.getoutput("pip3 install taospy") + +# prepare data by taosBenchmark +cmd = "taosBenchmark -y -a 3 -n 100 -t 100 -d %s -h %s -P %d &" % (databaseName, serverHost, serverPort) +process_out = subprocess.getoutput(cmd) +print(cmd) +#os.system("taosBenchmark -y -a 3 -n 100 -t 100 -d %s -h %s -P %d" % (databaseName, serverHost, serverPort)) +taosBenchmark_test_result = True +time.sleep(10) +import taos + +conn = taos.connect(host=serverHost, + user="root", + password="taosdata", + database=databaseName, + port=serverPort, + timezone="Asia/Shanghai") # default your host's timezone + +server_version = conn.server_info +print("server_version", server_version) +client_version = conn.client_info +print("client_version", client_version) # 3.0.0.0 + +# Execute a sql and get its result set. It's useful for SELECT statement +result: taos.TaosResult = conn.query("SELECT count(*) from meters") + +data = result.fetch_all() +print(data) +if data[0][0] !=10000: + print(" taosBenchmark work not as expected ") + print("!!!!!!!!!!!Test Result: taosBenchmark test failed! !!!!!!!!!!") + sys.exit(1) +#else: +# print("**********Test Result: taosBenchmark test passed **********") + + +# drop database of test +taos_test_result = False +print("drop database test") +print("run taos -s 'drop database %s;' -h %s -P %d" % (databaseName, serverHost, serverPort)) +taos_cmd_outpur = subprocess.getoutput('taos -s "drop database %s;" -h %s -P %d' % (databaseName, serverHost, serverPort)) +print(taos_cmd_outpur) +if ("Drop OK" in taos_cmd_outpur): + taos_test_result = True + #print("*******Test Result: taos test passed ************") + +version_test_result = False +if version: + print("Client info is: %s"%conn.client_info) + taos_V_output = "" + if system == "Windows": + taos_V_output = subprocess.getoutput("taos -V | findstr version") + else: + taos_V_output = subprocess.getoutput("taos -V | grep version") + + print("taos -V output is: %s" % taos_V_output) + if version in taos_V_output and version in conn.client_info: + version_test_result = True + #print("*******Test Result: Version check passed ************") + +conn.close() +if uninstall: + print("Start to run rmtaos") + leftFile = False + print("Platform: ", system) + + if system == "Linux": + # 创建一个subprocess.Popen对象,并使用stdin和stdout进行交互 + process = subprocess.Popen(['rmtaos'], + stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True) + # 向子进程发送输入 + process.stdin.write("y\n") + process.stdin.flush() # 确保输入被发送到子进程 + process.stdin.write("I confirm that I would like to delete all data, log and configuration files\n") + process.stdin.flush() # 确保输入被发送到子进程 + # 关闭子进程的stdin,防止它无限期等待更多输入 + process.stdin.close() + # 等待子进程结束 + process.wait() + # 检查目录清除情况 + out = subprocess.getoutput("ls /etc/systemd/system/taos*") + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/bin/taos*") + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/local/bin/taos*") + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/lib/libtaos*") + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/lib64/libtaos*") + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/include/taos*") + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/local/taos") + #print(out) + if "No such file or directory" not in out: + print("Uninstall left some files in /usr/local/taos:%s" % out) + leftFile = True + if not leftFile: + print("*******Test Result: uninstall test passed ************") + + elif system == "Darwin": + # 创建一个subprocess.Popen对象,并使用stdin和stdout进行交互 + process = subprocess.Popen(['sudo', 'rmtaos'], + stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True) + # 向子进程发送输入 + process.stdin.write("y\n") + process.stdin.flush() # 确保输入被发送到子进程 + process.stdin.write("I confirm that I would like to delete all data, log and configuration files\n") + process.stdin.flush() # 确保输入被发送到子进程 + # 关闭子进程的stdin,防止它无限期等待更多输入 + process.stdin.close() + # 等待子进程结束 + process.wait() + # 检查目录清除情况 + out = subprocess.getoutput("ls /usr/local/bin/taos*") + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/local/lib/libtaos*") + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/local/include/taos*") + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + #out = subprocess.getoutput("ls /usr/local/Cellar/tdengine/") + #print(out) + #if out: + # print("Uninstall left some files: /usr/local/Cellar/tdengine/%s" % out) + # leftFile = True + #if not leftFile: + # print("*******Test Result: uninstall test passed ************") + + elif system == "Windows": + process = subprocess.Popen(['unins000','/silent'], + stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True) + process.wait() + time.sleep(10) + out = subprocess.getoutput("ls C:\TDengine") + print(out) + if len(out.split("\n")) > 3: + leftFile = True + print("Uninstall left some files: %s" % out) + +if taosBenchmark_test_result: + print("**********Test Result: taosBenchmark test passed! **********") +if taos_test_result: + print("**********Test Result: taos test passed! **********") +else: + print("!!!!!!!!!!!Test Result: taos test failed! !!!!!!!!!!") +if version_test_result: + print("**********Test Result: version test passed! **********") +else: + print("!!!!!!!!!!!Test Result: version test failed! !!!!!!!!!!") +if not leftFile: + print("**********Test Result: uninstall test passed! **********") +else: + print("!!!!!!!!!!!Test Result: uninstall test failed! !!!!!!!!!!") +if taosBenchmark_test_result and taos_test_result and version_test_result and not leftFile: + sys.exit(0) +else: + sys.exit(1) + diff --git a/packaging/smokeTest/smokeTestJenkinsFile b/packaging/smokeTest/smokeTestJenkinsFile new file mode 100644 index 0000000000..464393d85d --- /dev/null +++ b/packaging/smokeTest/smokeTestJenkinsFile @@ -0,0 +1,380 @@ +def sync_source(branch_name) { + sh ''' + hostname + ip addr|grep 192|awk '{print $2}'|sed "s/\\/.*//" + echo ''' + branch_name + ''' + ''' + sh ''' + cd ${TDENGINE_ROOT_DIR} + set +e + git reset --hard + git fetch || git fetch + git checkout -f '''+branch_name+''' + git reset --hard origin/'''+branch_name+''' + git log | head -n 20 + git clean -fxd + set -e + ''' + return 1 +} +def sync_source_win() { + bat ''' + hostname + taskkill /f /t /im taosd.exe + ipconfig + set + date /t + time /t + ''' + bat ''' + echo %branch_name% + cd %WIN_TDENGINE_ROOT_DIR% + git reset --hard + git fetch || git fetch + git checkout -f ''' + env.BRANCH_NAME + ''' + git reset --hard origin/''' + env.BRANCH_NAME + ''' + git branch + git restore . + git remote prune origin + git pull || git pull + git log | head -n 20 + git clean -fxd + ''' + return 1 +} +pipeline { + agent none + parameters { + choice( + name: 'sourcePath', + choices: ['nas','web'], + description: 'Choice which way to download the installation pacakge;web is Office Web and nas means taos nas server ' + ) + choice( + name: 'verMode', + choices: ['enterprise','community'], + description: 'Choice which types of package you want do check ' + ) + string ( + name:'version', + defaultValue:'3.3.2.0', + description: 'Release version number,eg: 3.0.0.1' + ) + string ( + name:'baseVersion', + defaultValue:'smoking', + description: 'Tnas root path. eg:smoking, 3.3' + ) + choice ( + name:'mode', + choices: ['server','client'], + description: 'Choose which mode of package you want do run ' + ) + choice ( + name:'smoke_branch', + choices: ['test/3.0/smokeTest','test/main/smokeTest','test/3.1/smokeTest'], + description: 'Choose which mode of package you want do run ' + ) + string ( + name:'runPlatforms', + defaultValue:'server_Linux_x64, server_Linux_arm64, server_Windows_x64, server_Mac_x64', + description: 'run package list hotfix usually run: server: server_Linux_x64, server_Linux_arm64 client: client_Linux_x64, client_Linux_arm64 release usually run: enterprise server: server_Linux_x64, server_Linux_arm64, server_Windows_x64 enterprise client: client_Linux_x64, client_Linux_arm64, client_Windows_x64 community server: server_Linux_x64, server_Linux_arm64, server_Mac_x64, server_Mac_arm64(not supported), server_Linux_x64_lite(not supported) community client: client_Linux_x64, client_Linux_arm64, client_Windows_x64, client_Mac_x64, client_Mac_arm64(not supported), client_Linux_x64_lite(not supported)' + ) + } + environment{ + WORK_DIR = "/var/lib/jenkins/workspace" + TDINTERNAL_ROOT_DIR = '/var/lib/jenkins/workspace/TDinternal' + TDENGINE_ROOT_DIR = '/var/lib/jenkins/workspace/TDinternal/community' + BRANCH_NAME = "${smoke_branch}" + } + stages { + stage ('Start Server for Client Test') { + when { + beforeAgent true + expression { mode == 'client' } + } + agent{label " ubuntu18 "} + steps { + timeout(time: 30, unit: 'MINUTES'){ + sync_source("${BRANCH_NAME}") + withEnv(['JENKINS_NODE_COOKIE=dontkillme']) { + sh ''' + cd ${TDENGINE_ROOT_DIR}/packaging/smokeTest + bash getAndRunInstaller.sh -m ${verMode} -f server -l false -c x64 -v ${version} -o ${baseVersion} -s ${sourcePath} -t tar + bash start3NodesServer.sh + ''' + } + } + } + } + stage ('Run SmokeTest') { + parallel { + stage('server_Linux_x64') { + when { + beforeAgent true + allOf { + expression { mode == 'server' } + expression { runPlatforms.contains('server_Linux_x64') } + } + } + agent{label " ubuntu16 "} + steps { + timeout(time: 30, unit: 'MINUTES'){ + sync_source("${BRANCH_NAME}") + sh ''' + mkdir -p /var/www/html/${baseVersion}/${version}/${verMode}/json + cd ${TDENGINE_ROOT_DIR}/packaging/smokeTest + bash getAndRunInstaller.sh -m ${verMode} -f server -l false -c x64 -v ${version} -o ${baseVersion} -s ${sourcePath} -t tar + python3 -m pytest test_server.py -v --html=/var/www/html/${baseVersion}/${version}/${verMode}/${mode}_linux_x64_report.html --json-report --json-report-file=report.json --timeout=300 --verMode=${verMode} --tVersion=${version} --baseVersion=${baseVersion} --sourcePath=${sourcePath} || true + cp report.json /var/www/html/${baseVersion}/${version}/${verMode}/json/${mode}_linux_x64_report.json + curl "http://192.168.0.176/api/addSmoke?version=${version}&tag=${baseVersion}&type=${verMode}&role=server&build=linux_x64" + ''' + } + } + } + stage('server_Linux_arm64') { + when { + beforeAgent true + allOf { + expression { mode == 'server' } + expression { runPlatforms.contains('server_Linux_arm64') } + } + } + agent{label "worker06_arm64"} + steps { + timeout(time: 60, unit: 'MINUTES'){ + sync_source("${BRANCH_NAME}") + sh ''' + cd ${TDENGINE_ROOT_DIR}/packaging/smokeTest + bash getAndRunInstaller.sh -m ${verMode} -f server -l false -c arm64 -v ${version} -o ${baseVersion} -s ${sourcePath} -t tar + python3 -m pytest test_server.py -v --html=${mode}_linux_arm64_report.html --json-report --json-report-file=report.json --timeout=600 --verMode=${verMode} --tVersion=${version} --baseVersion=${baseVersion} --sourcePath=${sourcePath} || true + scp ${mode}_linux_arm64_report.html root@192.168.0.21:/var/www/html/${baseVersion}/${version}/${verMode}/ + scp report.json root@192.168.0.21:/var/www/html/${baseVersion}/${version}/${verMode}/json/${mode}_linux_arm64_report.json + curl "http://192.168.0.176/api/addSmoke?version=${version}&tag=${baseVersion}&type=${verMode}&role=server&build=linux_arm64" + ''' + } + } + } + stage ('server_Mac_x64') { + when { + beforeAgent true + allOf { + expression { mode == 'server' } + expression { runPlatforms.contains('server_Mac_x64') } + } + } + agent{label " release_Darwin_x64 "} + environment{ + WORK_DIR = "/Users/zwen/jenkins/workspace" + TDINTERNAL_ROOT_DIR = '/Users/zwen/jenkins/workspace/TDinternal' + TDENGINE_ROOT_DIR = '/Users/zwen/jenkins/workspace/TDinternal/community' + } + steps { + timeout(time: 30, unit: 'MINUTES'){ + sync_source("${BRANCH_NAME}") + sh ''' + cd ${TDENGINE_ROOT_DIR}/packaging/smokeTest + bash getAndRunInstaller.sh -m ${verMode} -f server -l false -c x64 -v ${version} -o ${baseVersion} -s ${sourcePath} -t pkg + python3 -m pytest -v -k linux --html=${mode}_Mac_x64_report.html --json-report --json-report-file=report.json --timeout=300 --verMode=${verMode} --tVersion=${version} --baseVersion=${baseVersion} --sourcePath=${sourcePath} || true + scp ${mode}_Mac_x64_report.html root@192.168.0.21:/var/www/html/${baseVersion}/${version}/${verMode}/ + scp report.json root@192.168.0.21:/var/www/html/${baseVersion}/${version}/${verMode}/json/${mode}_Mac_x64_report.json + curl "http://192.168.0.176/api/addSmoke?version=${version}&tag=${baseVersion}&type=${verMode}&role=server&build=Mac_x64" + ''' + } + } + } + stage ('server_Mac_arm64') { + when { + beforeAgent true + allOf { + expression { mode == 'server' } + expression { runPlatforms.contains('server_Mac_arm64') } + } + } + agent{label " release_Darwin_arm64 "} + environment{ + WORK_DIR = "/Users/zwen/jenkins/workspace" + TDINTERNAL_ROOT_DIR = '/Users/zwen/jenkins/workspace/TDinternal' + TDENGINE_ROOT_DIR = '/Users/zwen/jenkins/workspace/TDinternal/community' + } + steps { + timeout(time: 30, unit: 'MINUTES'){ + sync_source("${BRANCH_NAME}") + sh ''' + cd ${TDENGINE_ROOT_DIR}/packaging/smokeTest + bash getAndRunInstaller.sh -m ${verMode} -f server -l false -c arm64 -v ${version} -o ${baseVersion} -s ${sourcePath} -t pkg + python3 -m pytest -v -k linux --html=${mode}_Mac_arm64_report.html --json-report --json-report-file=report.json --timeout=300 --verMode=${verMode} --tVersion=${version} --baseVersion=${baseVersion} --sourcePath=${sourcePath} || true + scp ${mode}_Mac_arm64_report.html root@192.168.0.21:/var/www/html/${baseVersion}/${version}/${verMode}/ + scp report.json root@192.168.0.21:/var/www/html/${baseVersion}/${version}/${verMode}/json/${mode}_Mac_arm64_report.json + curl "http://192.168.0.176/api/addSmoke?version=${version}&tag=${baseVersion}&type=${verMode}&role=server&build=Mac_arm64" + ''' + } + } + } + stage('server_Windows_x64') { + when { + beforeAgent true + allOf { + expression { mode == 'server' } + expression { runPlatforms.contains('server_Windows_x64') } + } + } + agent{label " windows11 "} + environment{ + WIN_WORK_DIR="C:\\workspace" + WIN_TDINTERNAL_ROOT_DIR="C:\\workspace\\TDinternal" + WIN_TDENGINE_ROOT_DIR="C:\\workspace\\TDinternal\\community" + } + steps { + timeout(time: 30, unit: 'MINUTES'){ + sync_source_win() + bat ''' + cd %WIN_TDENGINE_ROOT_DIR%\\packaging\\smokeTest + call getAndRunInstaller.bat %baseVersion% %version% %verMode% server + cd %WIN_TDENGINE_ROOT_DIR%\\packaging\\smokeTest + pip3 install -r pytest_require.txt + python3 -m pytest test_server.py -v --html=%mode%_Windows_x64_report.html --json-report --json-report-file=report.json --timeout=300 --verMode=%verMode% --tVersion=%version% --baseVersion=%baseVersion% --sourcePath=%sourcePath% + scp %mode%_Windows_x64_report.html root@192.168.0.21:/var/www/html/%baseVersion%/%version%/%verMode%/ + scp report.json root@192.168.0.21:/var/www/html/%baseVersion%/%version%/%verMode%/json/%mode%_Windows_x64_report.json + curl "http://192.168.0.176/api/addSmoke?version=%version%&tag=%baseVersion%&type=%verMode%&role=server&build=Windows_x64" + ''' + } + } + } + stage('client_Linux_x64') { + when { + beforeAgent true + allOf { + expression { mode == 'client' } + expression { runPlatforms.contains('client_Linux_x64') } + } + } + agent{label " ubuntu16 "} + steps { + timeout(time: 30, unit: 'MINUTES'){ + sync_source("${BRANCH_NAME}") + sh ''' + mkdir -p /var/www/html/${baseVersion}/${version}/${verMode}/json + cd ${TDENGINE_ROOT_DIR}/packaging/smokeTest + bash getAndRunInstaller.sh -m ${verMode} -f client -l false -c x64 -v ${version} -o ${baseVersion} -s ${sourcePath} -t tar + python3 -m pytest test_client.py -v --html=/var/www/html/${baseVersion}/${version}/${verMode}/${mode}_linux_x64_report.html --json-report --json-report-file=report.json --timeout=300 --verMode=${verMode} --tVersion=${version} --baseVersion=${baseVersion} --sourcePath=${sourcePath} || true + cp report.json /var/www/html/${baseVersion}/${version}/${verMode}/json/${mode}_linux_x64_report.json + curl "http://192.168.0.176/api/addSmoke?version=${version}&tag=${baseVersion}&type=${verMode}&role=client&build=linux_x64" + ''' + } + } + } + stage('client_Linux_arm64') { + when { + beforeAgent true + allOf { + expression { mode == 'client' } + expression { runPlatforms.contains('client_Linux_arm64') } + } + } + agent{label " worker06_arm64 "} + steps { + timeout(time: 30, unit: 'MINUTES'){ + sync_source("${BRANCH_NAME}") + sh ''' + cd ${TDENGINE_ROOT_DIR}/packaging/smokeTest + bash getAndRunInstaller.sh -m ${verMode} -f client -l false -c arm64 -v ${version} -o ${baseVersion} -s ${sourcePath} -t tar + python3 -m pytest test_client.py -v --html=${mode}_linux_arm64_report.html --json-report --json-report-file=report.json --timeout=300 --verMode=${verMode} --tVersion=${version} --baseVersion=${baseVersion} --sourcePath=${sourcePath} || true + scp ${mode}_linux_arm64_report.html root@192.168.0.21:/var/www/html/${baseVersion}/${version}/${verMode}/ + scp report.json root@192.168.0.21:/var/www/html/${baseVersion}/${version}/${verMode}/json/${mode}_linux_arm64_report.json + curl "http://192.168.0.176/api/addSmoke?version=${version}&tag=${baseVersion}&type=${verMode}&role=client&build=linux_arm64" + ''' + } + } + } + stage ('client_Mac_x64') { + when { + beforeAgent true + allOf { + expression { mode == 'client' } + expression { runPlatforms.contains('client_Mac_x64') } + } + } + agent{label " release_Darwin_x64 "} + environment{ + WORK_DIR = "/Users/zwen/jenkins/workspace" + TDINTERNAL_ROOT_DIR = '/Users/zwen/jenkins/workspace/TDinternal' + TDENGINE_ROOT_DIR = '/Users/zwen/jenkins/workspace/TDinternal/community' + } + steps { + timeout(time: 30, unit: 'MINUTES'){ + sync_source("${BRANCH_NAME}") + sh ''' + cd ${TDENGINE_ROOT_DIR}/packaging/smokeTest + bash getAndRunInstaller.sh -m ${verMode} -f client -l false -c x64 -v ${version} -o ${baseVersion} -s ${sourcePath} -t pkg + rm -rf /opt/taos/main/TDinternal/debug/* || true + python3 -m pytest test_client.py -v --html=${mode}_Mac_x64_report.html --json-report --json-report-file=report.json --timeout=300 --verMode=${verMode} --tVersion=${version} --baseVersion=${baseVersion} --sourcePath=${sourcePath} || true + scp ${mode}_Mac_x64_report.html root@192.168.0.21:/var/www/html/${baseVersion}/${version}/${verMode}/ + scp report.json root@192.168.0.21:/var/www/html/${baseVersion}/${version}/${verMode}/json/${mode}_Mac_x64_report.json + curl "http://192.168.0.176/api/addSmoke?version=${version}&tag=${baseVersion}&type=${verMode}&role=client&build=Mac_x64" + ''' + } + } + } + stage ('client_Mac_arm64') { + when { + beforeAgent true + allOf { + expression { mode == 'client' } + expression { runPlatforms.contains('client_Mac_arm64') } + } + } + agent{label " release_Darwin_arm64 "} + environment{ + WORK_DIR = "/Users/zwen/jenkins/workspace" + TDINTERNAL_ROOT_DIR = '/Users/zwen/jenkins/workspace/TDinternal' + TDENGINE_ROOT_DIR = '/Users/zwen/jenkins/workspace/TDinternal/community' + } + steps { + timeout(time: 30, unit: 'MINUTES'){ + sync_source("${BRANCH_NAME}") + sh ''' + cd ${TDENGINE_ROOT_DIR}/packaging/smokeTest + bash getAndRunInstaller.sh -m ${verMode} -f client -l false -c arm64 -v ${version} -o ${baseVersion} -s ${sourcePath} -t pkg + rm -rf /opt/taos/main/TDinternal/debug/* || true + python3 -m pytest test_client.py -v --html=${mode}_Mac_arm64_report.html --json-report --json-report-file=report.json --timeout=300 --verMode=${verMode} --tVersion=${version} --baseVersion=${baseVersion} --sourcePath=${sourcePath} || true + scp ${mode}_Mac_arm64_report.html root@192.168.0.21:/var/www/html/${baseVersion}/${version}/${verMode}/ + scp report.json root@192.168.0.21:/var/www/html/${baseVersion}/${version}/${verMode}/json/${mode}_Mac_arm64_report.json + curl "http://192.168.0.176/api/addSmoke?version=${version}&tag=${baseVersion}&type=${verMode}&role=client&build=Mac_arm64" + ''' + } + } + } + stage('client_Windows_x64') { + when { + beforeAgent true + allOf { + expression { mode == 'client' } + expression { runPlatforms.contains('client_Windows_x64') } + } + } + agent{label " windows71 "} + environment{ + WIN_WORK_DIR="C:\\workspace" + WIN_TDINTERNAL_ROOT_DIR="C:\\workspace\\TDinternal" + WIN_TDENGINE_ROOT_DIR="C:\\workspace\\TDinternal\\community" + } + steps { + timeout(time: 30, unit: 'MINUTES'){ + sync_source_win() + bat ''' + cd %WIN_TDENGINE_ROOT_DIR%\\packaging\\smokeTest + call getAndRunInstaller.bat %baseVersion% %version% %verMode% client + pip3 install -r pytest_require.txt + python3 -m pytest test_client.py -v --html=%mode%_Windows_x64_report.html --json-report --json-report-file=report.json --timeout=300 --verMode=%verMode% --tVersion=%version% --baseVersion=%baseVersion% --sourcePath=%sourcePath% + scp %mode%_Windows_x64_report.html root@192.168.0.21:/var/www/html/%baseVersion%/%version%/%verMode%/ + scp report.json root@192.168.0.21:/var/www/html/%baseVersion%/%version%/%verMode%/json/%mode%_Windows_x64_report.json + curl "http://192.168.0.176/api/addSmoke?version=%version%&tag=%baseVersion%&type=%verMode%&role=client&build=Windows_x64" + ''' + } + } + } + } + } + } +} \ No newline at end of file diff --git a/packaging/smokeTest/start3NodesServer.sh b/packaging/smokeTest/start3NodesServer.sh new file mode 100644 index 0000000000..b446a467ef --- /dev/null +++ b/packaging/smokeTest/start3NodesServer.sh @@ -0,0 +1,67 @@ +#!/bin/bash +BUILD_ID=dontKillMe + +#******This script setup 3 nodes env for remote client installer test. Only for Linux ********* + +pwd=`pwd` +hostname=`hostname` +if [ -z $JENKINS_HOME ]; then + workdir="${pwd}/cluster" + echo $workdir +else + workdir="${JENKINS_HOME}/workspace/cluster" + echo $workdir +fi + +name="taos" +if command -v prodb ;then + name="prodb" +fi + +# Stop all taosd processes +for(( i=0; i<3; i++)) +do + pid=$(ps -ef | grep ${name}d | grep -v grep | awk '{print $2}') + if [ -n "$pid" ]; then + ${csudo}kill -9 $pid || : + fi +done + +# Init 3 dnodes workdir and config file +rm -rf ${workdir} +mkdir ${workdir} +mkdir ${workdir}/output +mkdir ${workdir}/dnode1 +mkdir ${workdir}/dnode1/data +mkdir ${workdir}/dnode1/log +mkdir ${workdir}/dnode1/cfg +touch ${workdir}/dnode1/cfg/${name}.cfg +echo -e "firstEp ${hostname}:6031\nsecondEp ${hostname}:6032\nfqdn ${hostname}\nserverPort 6031\nlogDir ${workdir}/dnode1/log\ndataDir ${workdir}/dnode1/data\n" >> ${workdir}/dnode1/cfg/${name}.cfg + +# Start first node +nohup ${name}d -c ${workdir}/dnode1/cfg/${name}.cfg & > /dev/null +sleep 5 + +${name} -P 6031 -s "CREATE DNODE \`${hostname}:6032\`;CREATE DNODE \`${hostname}:6033\`" + +mkdir ${workdir}/dnode2 +mkdir ${workdir}/dnode2/data +mkdir ${workdir}/dnode2/log +mkdir ${workdir}/dnode2/cfg +touch ${workdir}/dnode2/cfg/${name}.cfg +echo -e "firstEp ${hostname}:6031\nsecondEp ${hostname}:6032\nfqdn ${hostname}\nserverPort 6032\nlogDir ${workdir}/dnode2/log\ndataDir ${workdir}/dnode2/data\n" >> ${workdir}/dnode2/cfg/${name}.cfg + +nohup ${name}d -c ${workdir}/dnode2/cfg/${name}.cfg & > /dev/null +sleep 5 + +mkdir ${workdir}/dnode3 +mkdir ${workdir}/dnode3/data +mkdir ${workdir}/dnode3/log +mkdir ${workdir}/dnode3/cfg +touch ${workdir}/dnode3/cfg/${name}.cfg +echo -e "firstEp ${hostname}:6031\nsecondEp ${hostname}:6032\nfqdn ${hostname}\nserverPort 6033\nlogDir ${workdir}/dnode3/log\ndataDir ${workdir}/dnode3/data\n" >> ${workdir}/dnode3/cfg/${name}.cfg + +nohup ${name}d -c ${workdir}/dnode3/cfg/${name}.cfg & > /dev/null +sleep 5 + +${name} -P 6031 -s "CREATE MNODE ON DNODE 2;CREATE MNODE ON DNODE 3;" \ No newline at end of file diff --git a/packaging/smokeTest/test_client.py b/packaging/smokeTest/test_client.py new file mode 100644 index 0000000000..0b1003e370 --- /dev/null +++ b/packaging/smokeTest/test_client.py @@ -0,0 +1,137 @@ +import pytest +import subprocess +import os +import sys +import platform +import getopt +import re +import time +import taos +from versionCheckAndUninstallforPytest import UninstallTaos + +# python3 smokeTestClient.py -h 192.168.0.22 -P 6031 -v ${version} -u + +OEM = ["ProDB"] + + +@pytest.fixture(scope="module") +def get_config(request): + verMode = request.config.getoption("--verMode") + taosVersion = request.config.getoption("--tVersion") + baseVersion = request.config.getoption("--baseVersion") + sourcePath = request.config.getoption("--sourcePath") + config = { + "verMode": verMode, + "taosVersion": taosVersion, + "baseVersion": baseVersion, + "sourcePath": sourcePath, + "system": platform.system(), + "arch": platform.machine(), + "serverHost": "192.168.0.22", + "serverPort": 6031, + "databaseName": re.sub(r'[^a-zA-Z0-9]', '', subprocess.getoutput("hostname")).lower() + } + return config + + +@pytest.fixture(scope="module") +def setup_module(get_config): + config = get_config + # install taospy + if config["system"] == 'Windows': + taospy_version = subprocess.getoutput("pip3 show taospy|findstr Version") + else: + taospy_version = subprocess.getoutput("pip3 show taospy|grep Version| awk -F ':' '{print $2}' ") + + print("taospy version %s " % taospy_version) + if taospy_version == "": + subprocess.getoutput("pip3 install git+https://github.com/taosdata/taos-connector-python.git") + print("install taos python connector") + else: + subprocess.getoutput("pip3 install taospy") + + +def get_connect(host, port, database=None): + conn = taos.connect(host=host, + user="root", + password="taosdata", + database=database, + port=port, + timezone="Asia/Shanghai") # default your host's timezone + return conn + + +def run_cmd(command): + print("CMD: %s" % command) + result = subprocess.run(command, capture_output=True, text=True, shell=True) + print("STDOUT:", result.stdout) + print("STDERR:", result.stderr) + print("Return Code:", result.returncode) + assert result.returncode == 0 + return result + + +class TestClient: + @pytest.mark.all + def test_basic(self, get_config, setup_module): + config = get_config + name = "taos" + + if config["baseVersion"] in OEM: + name = config["baseVersion"].lower() + if config["baseVersion"] in OEM and config["system"] == 'Windows': + cmd = f'{name} -s "create database {config["databaseName"]};" -h {config["serverHost"]} -P {config["serverPort"]}' + run_cmd(cmd) + cmd = f'{name} -s "CREATE STABLE {config["databaseName"]}.meters (`ts` TIMESTAMP,`current` FLOAT, `phase` FLOAT) TAGS (`groupid` INT, `location` VARCHAR(24));" -h {config["serverHost"]} -P {config["serverPort"]}' + run_cmd(cmd) + else: + cmd = f'{name}Benchmark -y -a 3 -n 100 -t 100 -d {config["databaseName"]} -h {config["serverHost"]} -P {config["serverPort"]} &' + run_cmd(cmd) + # os.system("taosBenchmark -y -a 3 -n 100 -t 100 -d %s -h %s -P %d" % (databaseName, serverHost, serverPort)) + time.sleep(5) + conn = get_connect(config["serverHost"], config["serverPort"], config["databaseName"]) + sql = "SELECT count(*) from meters" + result: taos.TaosResult = conn.query(sql) + data = result.fetch_all() + print("SQL: %s" % sql) + print("Result: %s" % data) + if config["system"] == 'Windows' and config["baseVersion"] in OEM: + pass + elif data[0][0] != 10000: + raise f"{name}Benchmark work not as expected " + # drop database of test + cmd = f'{name} -s "drop database {config["databaseName"]};" -h {config["serverHost"]} -P {config["serverPort"]}' + result = run_cmd(cmd) + assert "Drop OK" in result.stdout + conn.close() + + @pytest.mark.all + def test_version(self, get_config, setup_module): + config = get_config + conn = get_connect(config["serverHost"], config["serverPort"]) + server_version = conn.server_info + print("server_version: ", server_version) + client_version = conn.client_info + print("client_version: ", client_version) + name = "taos" + if config["baseVersion"] in OEM: + name = config["baseVersion"].lower() + if config["system"] == "Windows": + taos_V_output = subprocess.getoutput(f"{name} -V | findstr version") + else: + taos_V_output = subprocess.getoutput(f"{name} -V | grep version") + assert config["taosVersion"] in taos_V_output + assert config["taosVersion"] in client_version + if config["taosVersion"] not in server_version: + print("warning: client version is not same as server version") + conn.close() + + @pytest.mark.all + def test_uninstall(self, get_config, setup_module): + config = get_config + name = "taos" + if config["baseVersion"] in OEM: + name = config["baseVersion"].lower() + subprocess.getoutput("rm /usr/local/bin/taos") + subprocess.getoutput("pkill taosd") + UninstallTaos(config["taosVersion"], config["verMode"], True, name) diff --git a/packaging/smokeTest/test_server.py b/packaging/smokeTest/test_server.py new file mode 100644 index 0000000000..04231f122f --- /dev/null +++ b/packaging/smokeTest/test_server.py @@ -0,0 +1,240 @@ +import pytest +import subprocess +import os +from versionCheckAndUninstallforPytest import UninstallTaos +import platform +import re +import time +import signal + +system = platform.system() +current_path = os.path.abspath(os.path.dirname(__file__)) +if system == 'Windows': + with open(r"%s\test_server_windows_case" % current_path) as f: + cases = f.read().splitlines() +else: + with open("%s/test_server_unix_case" % current_path) as f: + cases = f.read().splitlines() + +OEM = ["ProDB"] + + +@pytest.fixture(scope="module") +def get_config(request): + verMode = request.config.getoption("--verMode") + taosVersion = request.config.getoption("--tVersion") + baseVersion = request.config.getoption("--baseVersion") + sourcePath = request.config.getoption("--sourcePath") + config = { + "verMode": verMode, + "taosVersion": taosVersion, + "baseVersion": baseVersion, + "sourcePath": sourcePath, + "system": platform.system(), + "arch": platform.machine() + } + return config + + +@pytest.fixture(scope="module") +def setup_module(get_config): + def run_cmd(command): + print("CMD:", command) + result = subprocess.run(command, capture_output=True, text=True, shell=True) + print("STDOUT:", result.stdout) + print("STDERR:", result.stderr) + print("Return Code:", result.returncode) + assert result.returncode == 0 + return result + + # setup before module tests + config = get_config + # bash getAndRunInstaller.sh -m ${verMode} -f server -l false -c x64 -v ${version} -o ${baseVersion} -s ${sourcePath} -t tar + # t = "tar" + # if config["system"] == "Darwin": + # t = "pkg" + # cmd = "bash getAndRunInstaller.sh -m %s -f server -l false -c x64 -v %s -o %s -s %s -t %s" % ( + # config["verMode"], config["taosVersion"], config["baseVersion"], config["sourcePath"], t) + # run_cmd(cmd) + if config["system"] == "Windows": + cmd = r"mkdir ..\..\debug\build\bin" + else: + cmd = "mkdir -p ../../debug/build/bin/" + subprocess.getoutput(cmd) + if config["system"] == "Linux" or config["system"] == "Darwin" : # add tmq_sim + cmd = "cp -rf ../../../debug/build/bin/tmq_sim ../../debug/build/bin/." + subprocess.getoutput(cmd) + if config["system"] == "Darwin": + cmd = "sudo cp -rf /usr/local/bin/taos* ../../debug/build/bin/" + elif config["system"] == "Windows": + cmd = r"xcopy C:\TDengine\taos*.exe ..\..\debug\build\bin /Y" + else: + if config["baseVersion"] in OEM: + cmd = '''sudo find /usr/bin -name 'prodb*' -exec sh -c 'for file; do cp "$file" "../../debug/build/bin/taos${file##/usr/bin/%s}"; done' sh {} +''' % ( + config["baseVersion"].lower()) + else: + cmd = "sudo cp /usr/bin/taos* ../../debug/build/bin/" + run_cmd(cmd) + if config["baseVersion"] in OEM: # mock OEM + cmd = "sed -i 's/taos.cfg/%s.cfg/g' ../../tests/pytest/util/dnodes.py" % config["baseVersion"].lower() + run_cmd(cmd) + cmd = "sed -i 's/taosdlog.0/%sdlog.0/g' ../../tests/pytest/util/dnodes.py" % config["baseVersion"].lower() + run_cmd(cmd) + cmd = "sed -i 's/taos.cfg/%s.cfg/g' ../../tests/army/frame/server/dnode.py" % config["baseVersion"].lower() + run_cmd(cmd) + cmd = "sed -i 's/taosdlog.0/%sdlog.0/g' ../../tests/army/frame/server/dnode.py" % config["baseVersion"].lower() + run_cmd(cmd) + cmd = "ln -s /usr/bin/prodb /usr/local/bin/taos" + subprocess.getoutput(cmd) + + # yield + # + # name = "taos" + # if config["baseVersion"] in OEM: + # name = config["baseVersion"].lower() + # subprocess.getoutput("rm /usr/local/bin/taos") + # subprocess.getoutput("pkill taosd") + # UninstallTaos(config["taosVersion"], config["verMode"], True, name) + + +# use pytest fixture to exec case +@pytest.fixture(params=cases) +def run_command(request): + commands = request.param + if commands.strip().startswith("#"): + pytest.skip("This case has been marked as skipped") + d, command = commands.strip().split(",") + if system == "Windows": + cmd = r"cd %s\..\..\tests\%s && %s" % (current_path, d, command) + else: + cmd = "cd %s/../../tests/%s&&sudo %s" % (current_path, d, command) + print(cmd) + result = subprocess.run(cmd, capture_output=True, text=True, shell=True) + return { + "command": command, + "stdout": result.stdout, + "stderr": result.stderr, + "returncode": result.returncode + } + + +class TestServer: + @pytest.mark.all + def test_taosd_up(self, setup_module): + # start process + if system == 'Windows': + subprocess.getoutput("taskkill /IM taosd.exe /F") + cmd = "..\\..\\debug\\build\\bin\\taosd.exe" + else: + subprocess.getoutput("pkill taosd") + cmd = "../../debug/build/bin/taosd" + process = subprocess.Popen( + [cmd], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True + ) + # monitor output + while True: + line = process.stdout.readline() + if line: + print(line.strip()) + if "succeed to write dnode" in line: + time.sleep(5) + # 发送终止信号 + os.kill(process.pid, signal.SIGKILL) + # Waiting for the process to be completely killed + time.sleep(5) + break + + @pytest.mark.all + def test_execute_cases(self, setup_module, run_command): + # assert the result + if run_command['returncode'] != 0: + print(f"Running command: {run_command['command']}") + print("STDOUT:", run_command['stdout']) + print("STDERR:", run_command['stderr']) + print("Return Code:", run_command['returncode']) + else: + print(f"Running command: {run_command['command']}") + if len(run_command['stdout']) > 1000: + print("STDOUT:", run_command['stdout'][:1000] + "...") + else: + print("STDOUT:", run_command['stdout']) + print("STDERR:", run_command['stderr']) + print("Return Code:", run_command['returncode']) + + assert run_command[ + 'returncode'] == 0, f"Command '{run_command['command']}' failed with return code {run_command['returncode']}" + + @pytest.mark.all + @pytest.mark.check_version + def test_check_version(self, get_config, setup_module): + config = get_config + databaseName = re.sub(r'[^a-zA-Z0-9]', '', subprocess.getoutput("hostname")).lower() + # install taospy + taospy_version = "" + system = config["system"] + version = config["taosVersion"] + verMode = config["verMode"] + if system == 'Windows': + taospy_version = subprocess.getoutput("pip3 show taospy|findstr Version") + else: + taospy_version = subprocess.getoutput("pip3 show taospy|grep Version| awk -F ':' '{print $2}' ") + + print("taospy version %s " % taospy_version) + if taospy_version == "": + subprocess.getoutput("pip3 install git+https://github.com/taosdata/taos-connector-python.git") + print("install taos python connector") + else: + subprocess.getoutput("pip3 install taospy") + + # start taosd server + if system == 'Windows': + cmd = ["C:\\TDengine\\start-all.bat"] + # elif system == 'Linux': + # cmd = "systemctl start taosd".split(' ') + else: + # cmd = "sudo launchctl start com.tdengine.taosd".split(' ') + cmd = "start-all.sh" + process_out = subprocess.Popen(cmd, + stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True) + print(cmd) + time.sleep(5) + + import taos + conn = taos.connect() + check_list = {} + check_list["server_version"] = conn.server_info + check_list["client_version"] = conn.client_info + # Execute sql get version info + result: taos.TaosResult = conn.query("SELECT server_version()") + check_list["select_server"] = result.fetch_all()[0][0] + result: taos.TaosResult = conn.query("SELECT client_version()") + check_list["select_client"] = result.fetch_all()[0][0] + conn.close() + + binary_files = ["taos", "taosd", "taosadapter", "taoskeeper", "taosBenchmark"] + if verMode.lower() == "enterprise": + binary_files.append("taosx") + if config["baseVersion"] in OEM: + binary_files = [i.replace("taos", config["baseVersion"].lower()) for i in binary_files] + if system == "Windows": + for i in binary_files: + check_list[i] = subprocess.getoutput("%s -V | findstr version" % i) + else: + for i in binary_files: + check_list[i] = subprocess.getoutput("%s -V | grep version | awk -F ' ' '{print $3}'" % i) + for i in check_list: + print("%s version is: %s" % (i, check_list[i])) + assert version in check_list[i] + + @pytest.mark.all + def test_uninstall(self, get_config, setup_module): + config = get_config + name = "taos" + if config["baseVersion"] in OEM: + name = config["baseVersion"].lower() + subprocess.getoutput("rm /usr/local/bin/taos") + subprocess.getoutput("pkill taosd") + UninstallTaos(config["taosVersion"], config["verMode"], True, name) diff --git a/packaging/smokeTest/test_server_unix_case b/packaging/smokeTest/test_server_unix_case new file mode 100644 index 0000000000..1bbde10932 --- /dev/null +++ b/packaging/smokeTest/test_server_unix_case @@ -0,0 +1,10 @@ +system-test,python3 ./test.py -f 2-query/join.py +system-test,python3 ./test.py -f 1-insert/insert_column_value.py +system-test,python3 ./test.py -f 2-query/primary_ts_base_5.py +system-test,python3 ./test.py -f 2-query/case_when.py +system-test,python3 ./test.py -f 2-query/partition_limit_interval.py +system-test,python3 ./test.py -f 2-query/fill.py +army,python3 ./test.py -f query/query_basic.py -N 3 +system-test,python3 ./test.py -f 7-tmq/basic5.py +system-test,python3 ./test.py -f 8-stream/stream_basic.py +system-test,python3 ./test.py -f 6-cluster/5dnode3mnodeStop.py -N 5 -M 3 \ No newline at end of file diff --git a/packaging/smokeTest/test_server_windows_case b/packaging/smokeTest/test_server_windows_case new file mode 100644 index 0000000000..e64213b1ee --- /dev/null +++ b/packaging/smokeTest/test_server_windows_case @@ -0,0 +1,2 @@ +system-test,python3 .\test.py -f 0-others\taosShell.py +system-test,python3 .\test.py -f 6-cluster\5dnode3mnodeSep1VnodeStopDnodeModifyMeta.py -N 6 -M 3 \ No newline at end of file diff --git a/packaging/smokeTest/versionCheckAndUninstall.py b/packaging/smokeTest/versionCheckAndUninstall.py new file mode 100644 index 0000000000..80dea9a15f --- /dev/null +++ b/packaging/smokeTest/versionCheckAndUninstall.py @@ -0,0 +1,260 @@ +#!/usr/bin/python +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### +# install pip +# pip install src/connector/python/ + +# -*- coding: utf-8 -*- +import sys, os +import re +import platform +import getopt +import subprocess +# from this import d +import time + +# input for server + +opts, args = getopt.gnu_getopt(sys.argv[1:], 'v:m:u', ['version=', 'verMode=']) +serverHost = "" +serverPort = 0 +version = "" +uninstall = False +verMode = "" +for key, value in opts: + if key in ['--help']: + print('A collection of test cases written using Python') + print('-v test client version') + print('-u test uninstall process, will uninstall TDengine') + sys.exit(0) + + if key in ['-v']: + version = value + if key in ['-u']: + uninstall = True + if key in ['-m']: + verMode = value +if not version: + print("No version specified, will not run version check.") + + +system = platform.system() +arch = platform.machine() + +databaseName = re.sub(r'[^a-zA-Z0-9]', '', subprocess.getoutput("hostname")).lower() +# install taospy +taospy_version = "" +if system == 'Windows': + taospy_version = subprocess.getoutput("pip3 show taospy|findstr Version") +else: + taospy_version = subprocess.getoutput("pip3 show taospy|grep Version| awk -F ':' '{print $2}' ") + +print("taospy version %s " % taospy_version) +if taospy_version == "": + subprocess.getoutput("pip3 install git+https://github.com/taosdata/taos-connector-python.git") + print("install taos python connector") +else: + subprocess.getoutput("pip3 install taospy") + +# start taosd server +if system == 'Windows': + cmd = ["C:\\TDengine\\start-all.bat"] +elif system == 'Linux': + cmd = "systemctl start taosd".split(' ') +else: + cmd = "sudo launchctl start com.tdengine.taosd".split(' ') +process_out = subprocess.Popen(cmd, + stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True) +print(cmd) +time.sleep(5) + +#get taosc version info +version_test_result = False +if version: + import taos + conn = taos.connect() + server_version = conn.server_info + print("server_version", server_version) + client_version = conn.client_info + print("client_version", client_version) + # Execute sql get version info + result: taos.TaosResult = conn.query("SELECT server_version()") + select_server = result.fetch_all()[0][0] + print("SELECT server_version():" + select_server) + result: taos.TaosResult = conn.query("SELECT client_version()") + select_client = result.fetch_all()[0][0] + print("SELECT client_version():" + select_client) + conn.close() + + taos_V_output = "" + taosd_V_output = "" + taosadapter_V_output = "" + taoskeeper_V_output = "" + taosx_V_output = "" + taosB_V_output = "" + taosxVersion = False + if system == "Windows": + taos_V_output = subprocess.getoutput("taos -V | findstr version") + taosd_V_output = subprocess.getoutput("taosd -V | findstr version") + taosadapter_V_output = subprocess.getoutput("taosadapter -V | findstr version") + taoskeeper_V_output = subprocess.getoutput("taoskeeper -V | findstr version") + taosB_V_output = subprocess.getoutput("taosBenchmark -V | findstr version") + if verMode == "Enterprise": + taosx_V_output = subprocess.getoutput("taosx -V | findstr version") + else: + taos_V_output = subprocess.getoutput("taos -V | grep version | awk -F ' ' '{print $3}'") + taosd_V_output = subprocess.getoutput("taosd -V | grep version | awk -F ' ' '{print $3}'") + taosadapter_V_output = subprocess.getoutput("taosadapter -V | grep version | awk -F ' ' '{print $3}'") + taoskeeper_V_output = subprocess.getoutput("taoskeeper -V | grep version | awk -F ' ' '{print $3}'") + taosB_V_output = subprocess.getoutput("taosBenchmark -V | grep version | awk -F ' ' '{print $3}'") + if verMode == "Enterprise": + taosx_V_output = subprocess.getoutput("taosx -V | grep version | awk -F ' ' '{print $3}'") + + print("taos -V output is: %s" % taos_V_output) + print("taosd -V output is: %s" % taosd_V_output) + print("taosadapter -V output is: %s" % taosadapter_V_output) + print("taoskeeper -V output is: %s" % taoskeeper_V_output) + print("taosBenchmark -V output is: %s" % taosB_V_output) + if verMode == "Enterprise": + print("taosx -V output is: %s" % taosx_V_output) + taosxVersion = version in taosx_V_output + else: + taosxVersion = True + if (version in client_version + and version in server_version + and version in select_server + and version in select_client + and version in taos_V_output + and version in taosd_V_output + and version in taosadapter_V_output + and version in taoskeeper_V_output + and version in taosB_V_output + and taosxVersion + ): + version_test_result = True +leftFile = False +if uninstall: + print("Start to run rmtaos") + print("Platform: ", system) + # stop taosd server + if system == 'Windows': + cmd = "C:\\TDengine\\stop_all.bat" + elif system == 'Linux': + cmd = "systemctl stop taosd" + else: + cmd = "sudo launchctl stop com.tdengine.taosd" + process_out = subprocess.getoutput(cmd) + print(cmd) + time.sleep(10) + if system == "Linux": + # 创建一个subprocess.Popen对象,并使用stdin和stdout进行交互 + process = subprocess.Popen(['rmtaos'], + stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True) + # 向子进程发送输入 + process.stdin.write("y\n") + process.stdin.flush() # 确保输入被发送到子进程 + process.stdin.write("I confirm that I would like to delete all data, log and configuration files\n") + process.stdin.flush() # 确保输入被发送到子进程 + # 关闭子进程的stdin,防止它无限期等待更多输入 + process.stdin.close() + # 等待子进程结束 + process.wait() + # 检查目录清除情况 + out = subprocess.getoutput("ls /etc/systemd/system/taos*") + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/bin/taos*") + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/local/bin/taos*") + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/lib/libtaos*") + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/lib64/libtaos*") + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/include/taos*") + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/local/taos") + #print(out) + if "No such file or directory" not in out: + print("Uninstall left some files in /usr/local/taos:%s" % out) + leftFile = True + if not leftFile: + print("*******Test Result: uninstall test passed ************") + + elif system == "Darwin": + # 创建一个subprocess.Popen对象,并使用stdin和stdout进行交互 + process = subprocess.Popen(['sudo', 'rmtaos'], + stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True) + # 向子进程发送输入 + process.stdin.write("y\n") + process.stdin.flush() # 确保输入被发送到子进程 + process.stdin.write("I confirm that I would like to delete all data, log and configuration files\n") + process.stdin.flush() # 确保输入被发送到子进程 + # 关闭子进程的stdin,防止它无限期等待更多输入 + process.stdin.close() + # 等待子进程结束 + process.wait() + # 检查目录清除情况 + out = subprocess.getoutput("ls /usr/local/bin/taos*") + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/local/lib/libtaos*") + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/local/include/taos*") + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + #out = subprocess.getoutput("ls /usr/local/Cellar/tdengine/") + #print(out) + #if out: + # print("Uninstall left some files: /usr/local/Cellar/tdengine/%s" % out) + # leftFile = True + #if not leftFile: + # print("*******Test Result: uninstall test passed ************") + + elif system == "Windows": + process = subprocess.Popen(['unins000','/silent'], + stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True) + process.wait() + time.sleep(10) + out = subprocess.getoutput("ls C:\TDengine") + print(out) + if len(out.split("\n")) > 3: + leftFile = True + print("Uninstall left some files: %s" % out) + +if version_test_result: + print("**********Test Result: version test passed! **********") +else: + print("!!!!!!!!!!!Test Result: version test failed! !!!!!!!!!!") +if not leftFile: + print("**********Test Result: uninstall test passed! **********") +else: + print("!!!!!!!!!!!Test Result: uninstall test failed! !!!!!!!!!!") +if version_test_result and not leftFile: + sys.exit(0) +else: + sys.exit(1) + diff --git a/packaging/smokeTest/versionCheckAndUninstallforPytest.py b/packaging/smokeTest/versionCheckAndUninstallforPytest.py new file mode 100644 index 0000000000..5b75219554 --- /dev/null +++ b/packaging/smokeTest/versionCheckAndUninstallforPytest.py @@ -0,0 +1,137 @@ +#!/usr/bin/python +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### +# install pip +# pip install src/connector/python/ + +# -*- coding: utf-8 -*- +import sys, os +import re +import platform +import getopt +import subprocess +# from this import d +import time +from lib import run_cmd + + +# input for server +def UninstallTaos(version, verMode, uninstall, name): + if not version: + raise "No version specified, will not run version check." + + system = platform.system() + arch = platform.machine() + leftFile = False + if uninstall: + print("Start to run rm%s" % name) + print("Platform: ", system) + # stop taosd server + if system == 'Windows': + cmd = "C:\\TDengine\\stop_all.bat" + else: + cmd = "stop_all.sh" + process_out = subprocess.getoutput(cmd) + print(cmd) + time.sleep(5) + print("start to rm%s" % name) + if system == "Linux": + # 启动命令 + process = subprocess.Popen(['rm%s' % name], stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, text=True) + + # 发送交互输入 + stdout, stderr = process.communicate( + input="y\nI confirm that I would like to delete all data, log and configuration files\n") + + # 打印输出(可选) + print(stdout) + print(stderr) + # 检查目录清除情况 + out = subprocess.getoutput("ls /etc/systemd/system/%s*" % name) + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/bin/%s*" % name) + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/local/bin/%s*" % name) + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/lib/lib%s*" % name) + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/lib64/lib%s*" % name) + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/include/%s*" % name) + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/local/%s" % name) + # print(out) + if "No such file or directory" not in out: + print("Uninstall left some files in /usr/local/%s:%s" % (name, out)) + leftFile = True + if not leftFile: + print("*******Test Result: uninstall test passed ************") + + elif system == "Darwin": + # 创建一个subprocess.Popen对象,并使用stdin和stdout进行交互 + process = subprocess.Popen(['sudo', 'rm%s' % name], + stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True) + # 向子进程发送输入 + process.stdin.write("y\n") + process.stdin.flush() # 确保输入被发送到子进程 + process.stdin.write("I confirm that I would like to delete all data, log and configuration files\n") + process.stdin.flush() # 确保输入被发送到子进程 + # 关闭子进程的stdin,防止它无限期等待更多输入 + process.stdin.close() + # 等待子进程结束 + process.wait() + # 检查目录清除情况 + out = subprocess.getoutput("ls /usr/local/bin/%s*" % name) + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/local/lib/lib%s*" % name) + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + out = subprocess.getoutput("ls /usr/local/include/%s*" % name) + if "No such file or directory" not in out: + print("Uninstall left some files: %s" % out) + leftFile = True + # out = subprocess.getoutput("ls /usr/local/Cellar/tdengine/") + # print(out) + # if out: + # print("Uninstall left some files: /usr/local/Cellar/tdengine/%s" % out) + # leftFile = True + # if not leftFile: + # print("*******Test Result: uninstall test passed ************") + + elif system == "Windows": + process = subprocess.Popen(['unins000', '/silent'], + stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True) + process.wait() + time.sleep(10) + for file in ["C:\TDengine\\taos.exe", "C:\TDengine\\unins000.exe", "C:\ProDB\prodb.exe", + "C:\ProDB\\unins000.exe"]: + if os.path.exists(file): + leftFile = True + if leftFile: + raise "uninstall %s fail, please check" % name + else: + print("**********Test Result: uninstall test passed! **********") diff --git a/packaging/tools/make_install.sh b/packaging/tools/make_install.sh index 1b8fa2fb70..0874433e94 100755 --- a/packaging/tools/make_install.sh +++ b/packaging/tools/make_install.sh @@ -145,7 +145,14 @@ function kill_taosd() { function install_main_path() { #create install main dir and all sub dir - ${csudo}rm -rf ${install_main_dir} || : + ${csudo}rm -rf ${install_main_dir}/cfg || : + ${csudo}rm -rf ${install_main_dir}/bin || : + ${csudo}rm -rf ${install_main_dir}/driver || : + ${csudo}rm -rf ${install_main_dir}/examples || : + ${csudo}rm -rf ${install_main_dir}/include || : + ${csudo}rm -rf ${install_main_dir}/share || : + ${csudo}rm -rf ${install_main_dir}/log || : + ${csudo}mkdir -p ${install_main_dir} ${csudo}mkdir -p ${install_main_dir}/cfg ${csudo}mkdir -p ${install_main_dir}/bin diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 90505ed25a..da56dcf75e 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -47,10 +47,11 @@ enum { RES_TYPE__TMQ_BATCH_META, }; -#define SHOW_VARIABLES_RESULT_COLS 3 +#define SHOW_VARIABLES_RESULT_COLS 4 #define SHOW_VARIABLES_RESULT_FIELD1_LEN (TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE) #define SHOW_VARIABLES_RESULT_FIELD2_LEN (TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE) #define SHOW_VARIABLES_RESULT_FIELD3_LEN (TSDB_CONFIG_SCOPE_LEN + VARSTR_HEADER_SIZE) +#define SHOW_VARIABLES_RESULT_FIELD4_LEN (TSDB_CONFIG_INFO_LEN + VARSTR_HEADER_SIZE) #define TD_RES_QUERY(res) (*(int8_t*)(res) == RES_TYPE__QUERY) #define TD_RES_TMQ(res) (*(int8_t*)(res) == RES_TYPE__TMQ) diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index c56a627ec7..fa9df5be73 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -983,6 +983,7 @@ void taos_init_imp(void) { SCatalogCfg cfg = {.maxDBCacheNum = 100, .maxTblCacheNum = 100}; ENV_ERR_RET(catalogInit(&cfg), "failed to init catalog"); ENV_ERR_RET(schedulerInit(), "failed to init scheduler"); + ENV_ERR_RET(initClientId(), "failed to init clientId"); tscDebug("starting to initialize TAOS driver"); diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 4a719373f2..9f6be8e45c 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -1803,7 +1803,7 @@ int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) { if (bind->num > 1) { tscError("invalid bind number %d for %s", bind->num, __FUNCTION__); - terrno = TSDB_CODE_INVALID_PARA; + terrno = TSDB_CODE_TSC_STMT_BIND_NUMBER_ERROR; return terrno; } @@ -1819,7 +1819,7 @@ int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) { if (bind->num <= 0 || bind->num > INT16_MAX) { tscError("invalid bind num %d", bind->num); - terrno = TSDB_CODE_INVALID_PARA; + terrno = TSDB_CODE_TSC_STMT_BIND_NUMBER_ERROR; return terrno; } @@ -1831,7 +1831,7 @@ int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) { } if (0 == insert && bind->num > 1) { tscError("only one row data allowed for query"); - terrno = TSDB_CODE_INVALID_PARA; + terrno = TSDB_CODE_TSC_STMT_BIND_NUMBER_ERROR; return terrno; } @@ -1859,7 +1859,7 @@ int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, in } if (0 == insert && bind->num > 1) { tscError("only one row data allowed for query"); - terrno = TSDB_CODE_INVALID_PARA; + terrno = TSDB_CODE_TSC_STMT_BIND_NUMBER_ERROR; return terrno; } @@ -2019,7 +2019,7 @@ int taos_stmt2_bind_param(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t col if (bind->num <= 0 || bind->num > INT16_MAX) { tscError("invalid bind num %d", bind->num); - terrno = TSDB_CODE_INVALID_PARA; + terrno = TSDB_CODE_TSC_STMT_BIND_NUMBER_ERROR; return terrno; } @@ -2027,7 +2027,7 @@ int taos_stmt2_bind_param(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t col (void)stmtIsInsert2(stmt, &insert); if (0 == insert && bind->num > 1) { tscError("only one row data allowed for query"); - terrno = TSDB_CODE_INVALID_PARA; + terrno = TSDB_CODE_TSC_STMT_BIND_NUMBER_ERROR; return terrno; } diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 9a723218ff..e182cd97ee 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -541,6 +541,10 @@ static int32_t buildShowVariablesBlock(SArray* pVars, SSDataBlock** block) { infoData.info.bytes = SHOW_VARIABLES_RESULT_FIELD3_LEN; TSDB_CHECK_NULL(taosArrayPush(pBlock->pDataBlock, &infoData), code, line, END, terrno); + infoData.info.type = TSDB_DATA_TYPE_VARCHAR; + infoData.info.bytes = SHOW_VARIABLES_RESULT_FIELD4_LEN; + TSDB_CHECK_NULL(taosArrayPush(pBlock->pDataBlock, &infoData), code, line, END, terrno); + int32_t numOfCfg = taosArrayGetSize(pVars); code = blockDataEnsureCapacity(pBlock, numOfCfg); TSDB_CHECK_CODE(code, line, END); @@ -569,6 +573,13 @@ static int32_t buildShowVariablesBlock(SArray* pVars, SSDataBlock** block) { TSDB_CHECK_NULL(pColInfo, code, line, END, terrno); code = colDataSetVal(pColInfo, i, scope, false); TSDB_CHECK_CODE(code, line, END); + + char info[TSDB_CONFIG_INFO_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_WITH_MAXSIZE_TO_VARSTR(info, pInfo->info, TSDB_CONFIG_INFO_LEN + VARSTR_HEADER_SIZE); + pColInfo = taosArrayGet(pBlock->pDataBlock, c++); + TSDB_CHECK_NULL(pColInfo, code, line, END, terrno); + code = colDataSetVal(pColInfo, i, info, false); + TSDB_CHECK_CODE(code, line, END); } pBlock->info.rows = numOfCfg; @@ -825,7 +836,7 @@ int32_t processCompactDbRsp(void* param, SDataBuf* pMsg, int32_t code) { tscError("failed to post semaphore"); } } - return code; + return code; } __async_send_cb_fn_t getMsgRspHandle(int32_t msgType) { @@ -845,7 +856,7 @@ __async_send_cb_fn_t getMsgRspHandle(int32_t msgType) { case TDMT_MND_SHOW_VARIABLES: return processShowVariablesRsp; case TDMT_MND_COMPACT_DB: - return processCompactDbRsp; + return processCompactDbRsp; default: return genericRspCallback; } diff --git a/source/common/src/systable.c b/source/common/src/systable.c index dbf91aac69..12b789f14e 100644 --- a/source/common/src/systable.c +++ b/source/common/src/systable.c @@ -327,8 +327,9 @@ static const SSysDbTableSchema configSchema[] = { static const SSysDbTableSchema variablesSchema[] = { {.name = "dnode_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = true}, {.name = "name", .bytes = TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, - {.name = "value", .bytes = TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, + {.name = "value", .bytes = TSDB_CONFIG_PATH_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, {.name = "scope", .bytes = TSDB_CONFIG_SCOPE_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, + {.name = "info", .bytes = TSDB_CONFIG_INFO_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, }; static const SSysDbTableSchema topicSchema[] = { @@ -437,6 +438,7 @@ static const SSysDbTableSchema userGrantsLogsSchema[] = { {.name = "state", .bytes = 1536 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, {.name = "active", .bytes = 512 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, {.name = "machine", .bytes = TSDB_GRANT_LOG_COL_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, + {.name = "active_info", .bytes = 512 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, }; static const SSysDbTableSchema userMachinesSchema[] = { diff --git a/source/common/src/tcol.c b/source/common/src/tcol.c index 923aab12ca..a23385aba0 100644 --- a/source/common/src/tcol.c +++ b/source/common/src/tcol.c @@ -166,6 +166,7 @@ const char* columnCompressStr(uint16_t type) { } uint8_t columnLevelVal(const char* level) { + if (level == NULL) return TSDB_COLVAL_LEVEL_NOCHANGE; uint8_t l = TSDB_COLVAL_LEVEL_MEDIUM; if (0 == strcmp(level, "h") || 0 == strcmp(level, TSDB_COLUMN_LEVEL_HIGH)) { l = TSDB_COLVAL_LEVEL_HIGH; @@ -180,6 +181,7 @@ uint8_t columnLevelVal(const char* level) { } uint16_t columnCompressVal(const char* compress) { + if (compress == NULL) return TSDB_COLVAL_COMPRESS_NOCHANGE; uint16_t c = TSDB_COLVAL_COMPRESS_LZ4; if (0 == strcmp(compress, TSDB_COLUMN_COMPRESS_LZ4)) { c = TSDB_COLVAL_COMPRESS_LZ4; @@ -200,6 +202,7 @@ uint16_t columnCompressVal(const char* compress) { } uint8_t columnEncodeVal(const char* encode) { + if (encode == NULL) return TSDB_COLVAL_ENCODE_NOCHANGE; uint8_t e = TSDB_COLVAL_ENCODE_SIMPLE8B; if (0 == strcmp(encode, TSDB_COLUMN_ENCODE_SIMPLE8B)) { e = TSDB_COLVAL_ENCODE_SIMPLE8B; @@ -311,6 +314,7 @@ void setColLevel(uint32_t* compress, uint8_t level) { int32_t setColCompressByOption(uint8_t type, uint8_t encode, uint16_t compressType, uint8_t level, bool check, uint32_t* compress) { + if(compress == NULL) return TSDB_CODE_TSC_ENCODE_PARAM_ERROR; if (check && !validColEncode(type, encode)) return TSDB_CODE_TSC_ENCODE_PARAM_ERROR; setColEncode(compress, encode); diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 9c72e3b498..95788a7ff0 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -59,7 +59,6 @@ int32_t tsNumOfRpcSessions = 30000; int32_t tsShareConnLimit = 10; int32_t tsReadTimeout = 900; int32_t tsTimeToGetAvailableConn = 500000; -int32_t tsKeepAliveIdle = 60; int32_t tsNumOfCommitThreads = 2; int32_t tsNumOfTaskQueueThreads = 16; @@ -523,7 +522,7 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *input int32_t taosAddClientLogCfg(SConfig *pCfg) { TAOS_CHECK_RETURN(cfgAddDir(pCfg, "configDir", configDir, CFG_SCOPE_BOTH, CFG_DYN_NONE)); - TAOS_CHECK_RETURN(cfgAddDir(pCfg, "scriptDir", configDir, CFG_SCOPE_BOTH, CFG_DYN_NONE)); + TAOS_CHECK_RETURN(cfgAddDir(pCfg, "scriptDir", configDir, CFG_SCOPE_CLIENT, CFG_DYN_NONE)); TAOS_CHECK_RETURN(cfgAddDir(pCfg, "logDir", tsLogDir, CFG_SCOPE_BOTH, CFG_DYN_NONE)); TAOS_CHECK_RETURN(cfgAddFloat(pCfg, "minimalLogDirGB", 1.0f, 0.001f, 10000000, CFG_SCOPE_BOTH, CFG_DYN_CLIENT)); TAOS_CHECK_RETURN( @@ -531,13 +530,14 @@ int32_t taosAddClientLogCfg(SConfig *pCfg) { TAOS_CHECK_RETURN(cfgAddBool(pCfg, "asyncLog", tsAsyncLog, CFG_SCOPE_BOTH, CFG_DYN_BOTH)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "logKeepDays", 0, -365000, 365000, CFG_SCOPE_BOTH, CFG_DYN_ENT_BOTH)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "debugFlag", 0, 0, 255, CFG_SCOPE_BOTH, CFG_DYN_BOTH)); - TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "simDebugFlag", simDebugFlag, 0, 255, CFG_SCOPE_BOTH, CFG_DYN_BOTH)); + TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "simDebugFlag", simDebugFlag, 0, 255, CFG_SCOPE_CLIENT, CFG_DYN_BOTH)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "tmrDebugFlag", tmrDebugFlag, 0, 255, CFG_SCOPE_BOTH, CFG_DYN_BOTH)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "uDebugFlag", uDebugFlag, 0, 255, CFG_SCOPE_BOTH, CFG_DYN_BOTH)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "rpcDebugFlag", rpcDebugFlag, 0, 255, CFG_SCOPE_BOTH, CFG_DYN_BOTH)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "jniDebugFlag", jniDebugFlag, 0, 255, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "qDebugFlag", qDebugFlag, 0, 255, CFG_SCOPE_BOTH, CFG_DYN_BOTH)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "cDebugFlag", cDebugFlag, 0, 255, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); + TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "tqClientDebugFlag", tqClientDebugFlag, 0, 255, CFG_SCOPE_CLIENT, CFG_DYN_SERVER)); TAOS_RETURN(TSDB_CODE_SUCCESS); } @@ -550,7 +550,6 @@ static int32_t taosAddServerLogCfg(SConfig *pCfg) { TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "sDebugFlag", sDebugFlag, 0, 255, CFG_SCOPE_SERVER, CFG_DYN_SERVER)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "tsdbDebugFlag", tsdbDebugFlag, 0, 255, CFG_SCOPE_SERVER, CFG_DYN_SERVER)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "tqDebugFlag", tqDebugFlag, 0, 255, CFG_SCOPE_SERVER, CFG_DYN_SERVER)); - TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "tqClientDebugFlag", tqClientDebugFlag, 0, 255, CFG_SCOPE_SERVER, CFG_DYN_SERVER)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "fsDebugFlag", fsDebugFlag, 0, 255, CFG_SCOPE_SERVER, CFG_DYN_SERVER)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "udfDebugFlag", udfDebugFlag, 0, 255, CFG_SCOPE_SERVER, CFG_DYN_SERVER)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "smaDebugFlag", smaDebugFlag, 0, 255, CFG_SCOPE_SERVER, CFG_DYN_SERVER)); @@ -591,17 +590,18 @@ static int32_t taosAddClientCfg(SConfig *pCfg) { TAOS_CHECK_RETURN( cfgAddBool(pCfg, "queryUseNodeAllocator", tsQueryUseNodeAllocator, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); TAOS_CHECK_RETURN(cfgAddBool(pCfg, "keepColumnName", tsKeepColumnName, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); + TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "minSlidingTime", tsMinSlidingTime, 1, 1000000, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); + TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "minIntervalTime", tsMinIntervalTime, 1, 1000000, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); TAOS_CHECK_RETURN(cfgAddString(pCfg, "smlChildTableName", tsSmlChildTableName, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); TAOS_CHECK_RETURN(cfgAddString(pCfg, "smlAutoChildTableNameDelimiter", tsSmlAutoChildTableNameDelimiter, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); TAOS_CHECK_RETURN(cfgAddString(pCfg, "smlTagName", tsSmlTagName, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); TAOS_CHECK_RETURN(cfgAddString(pCfg, "smlTsDefaultName", tsSmlTsDefaultName, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); TAOS_CHECK_RETURN(cfgAddBool(pCfg, "smlDot2Underline", tsSmlDot2Underline, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); - TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "maxShellConns", tsMaxShellConns, 10, 50000000, CFG_SCOPE_CLIENT, CFG_DYN_NONE)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "maxInsertBatchRows", tsMaxInsertBatchRows, 1, INT32_MAX, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT) != 0); TAOS_CHECK_RETURN( - cfgAddInt32(pCfg, "maxRetryWaitTime", tsMaxRetryWaitTime, 0, 86400000, CFG_SCOPE_BOTH, CFG_DYN_CLIENT)); + cfgAddInt32(pCfg, "maxRetryWaitTime", tsMaxRetryWaitTime, 0, 86400000, CFG_SCOPE_SERVER, CFG_DYN_CLIENT)); TAOS_CHECK_RETURN(cfgAddBool(pCfg, "useAdapter", tsUseAdapter, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); TAOS_CHECK_RETURN(cfgAddBool(pCfg, "crashReporting", tsEnableCrashReport, CFG_SCOPE_BOTH, CFG_DYN_CLIENT)); TAOS_CHECK_RETURN(cfgAddInt64(pCfg, "queryMaxConcurrentTables", tsQueryMaxConcurrentTables, INT64_MIN, INT64_MAX, @@ -631,15 +631,12 @@ static int32_t taosAddClientCfg(SConfig *pCfg) { TAOS_CHECK_RETURN( cfgAddInt32(pCfg, "timeToGetAvailableConn", tsTimeToGetAvailableConn, 20, 1000000, CFG_SCOPE_BOTH, CFG_DYN_NONE)); - tsKeepAliveIdle = TRANGE(tsKeepAliveIdle, 1, 72000); - TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "keepAliveIdle", tsKeepAliveIdle, 1, 7200000, CFG_SCOPE_BOTH, CFG_DYN_NONE)); - tsNumOfTaskQueueThreads = tsNumOfCores * 2; tsNumOfTaskQueueThreads = TMAX(tsNumOfTaskQueueThreads, 16); TAOS_CHECK_RETURN( cfgAddInt32(pCfg, "numOfTaskQueueThreads", tsNumOfTaskQueueThreads, 4, 1024, CFG_SCOPE_CLIENT, CFG_DYN_NONE)); - TAOS_CHECK_RETURN(cfgAddBool(pCfg, "experimental", tsExperimental, CFG_SCOPE_BOTH, CFG_DYN_BOTH)); + TAOS_CHECK_RETURN(cfgAddBool(pCfg, "experimental", tsExperimental, CFG_SCOPE_SERVER, CFG_DYN_SERVER)); TAOS_CHECK_RETURN(cfgAddBool(pCfg, "multiResultFunctionStarReturnTags", tsMultiResultFunctionStarReturnTags, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); @@ -728,8 +725,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { TAOS_CHECK_RETURN(cfgAddString(pCfg, "encryptScope", tsEncryptScope, CFG_SCOPE_SERVER, CFG_DYN_NONE)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "statusInterval", tsStatusInterval, 1, 30, CFG_SCOPE_SERVER, CFG_DYN_NONE)); - TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "minSlidingTime", tsMinSlidingTime, 1, 1000000, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); - TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "minIntervalTime", tsMinIntervalTime, 1, 1000000, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT)); + TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "maxShellConns", tsMaxShellConns, 10, 50000000, CFG_SCOPE_SERVER, CFG_DYN_NONE)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "queryBufferSize", tsQueryBufferSize, -1, 500000000000, CFG_SCOPE_SERVER, CFG_DYN_NONE)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "queryRspPolicy", tsQueryRspPolicy, 0, 1, CFG_SCOPE_SERVER, CFG_DYN_ENT_SERVER)); @@ -747,7 +743,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "numOfSnodeSharedThreads", tsNumOfSnodeStreamThreads, 2, 1024, CFG_SCOPE_SERVER, CFG_DYN_NONE)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "numOfSnodeUniqueThreads", tsNumOfSnodeWriteThreads, 2, 1024, CFG_SCOPE_SERVER, CFG_DYN_NONE)); - TAOS_CHECK_RETURN(cfgAddInt64(pCfg, "rpcQueueMemoryAllowed", tsQueueMemoryAllowed, TSDB_MAX_MSG_SIZE * 10L, INT64_MAX, CFG_SCOPE_BOTH, CFG_DYN_NONE)); + TAOS_CHECK_RETURN(cfgAddInt64(pCfg, "rpcQueueMemoryAllowed", tsQueueMemoryAllowed, TSDB_MAX_MSG_SIZE * 10L, INT64_MAX, CFG_SCOPE_SERVER, CFG_DYN_NONE)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "syncElectInterval", tsElectInterval, 10, 1000 * 60 * 24 * 2, CFG_SCOPE_SERVER, CFG_DYN_NONE)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "syncHeartbeatInterval", tsHeartbeatInterval, 10, 1000 * 60 * 24 * 2, CFG_SCOPE_SERVER, CFG_DYN_NONE)); @@ -784,12 +780,12 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { TAOS_CHECK_RETURN(cfgAddBool(pCfg, "auditCreateTable", tsEnableAuditCreateTable, CFG_SCOPE_SERVER, CFG_DYN_NONE)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "auditInterval", tsAuditInterval, 500, 200000, CFG_SCOPE_SERVER, CFG_DYN_NONE)); - TAOS_CHECK_RETURN(cfgAddBool(pCfg, "telemetryReporting", tsEnableTelem, CFG_SCOPE_BOTH, CFG_DYN_ENT_SERVER)); - TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "telemetryInterval", tsTelemInterval, 1, 200000, CFG_SCOPE_BOTH, CFG_DYN_NONE)); - TAOS_CHECK_RETURN(cfgAddString(pCfg, "telemetryServer", tsTelemServer, CFG_SCOPE_BOTH, CFG_DYN_BOTH)); - TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "telemetryPort", tsTelemPort, 1, 65056, CFG_SCOPE_BOTH, CFG_DYN_NONE)); + TAOS_CHECK_RETURN(cfgAddBool(pCfg, "telemetryReporting", tsEnableTelem, CFG_SCOPE_SERVER, CFG_DYN_ENT_SERVER)); + TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "telemetryInterval", tsTelemInterval, 1, 200000, CFG_SCOPE_SERVER, CFG_DYN_NONE)); + TAOS_CHECK_RETURN(cfgAddString(pCfg, "telemetryServer", tsTelemServer, CFG_SCOPE_SERVER, CFG_DYN_BOTH)); + TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "telemetryPort", tsTelemPort, 1, 65056, CFG_SCOPE_SERVER, CFG_DYN_NONE)); - TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "rsyncPort", tsRsyncPort, 1, 65535, CFG_SCOPE_BOTH, CFG_DYN_SERVER)); + TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "rsyncPort", tsRsyncPort, 1, 65535, CFG_SCOPE_SERVER, CFG_DYN_SERVER)); TAOS_CHECK_RETURN(cfgAddString(pCfg, "snodeAddress", tsSnodeAddress, CFG_SCOPE_SERVER, CFG_DYN_SERVER)); TAOS_CHECK_RETURN(cfgAddString(pCfg, "checkpointBackupDir", tsCheckpointBackupDir, CFG_SCOPE_SERVER, CFG_DYN_SERVER)); @@ -1295,9 +1291,6 @@ static int32_t taosSetClientCfg(SConfig *pCfg) { TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "timeToGetAvailableConn"); tsTimeToGetAvailableConn = pItem->i32; - TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "keepAliveIdle"); - tsKeepAliveIdle = pItem->i32; - TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "experimental"); tsExperimental = pItem->bval; @@ -2036,7 +2029,6 @@ static int32_t taosCfgDynamicOptionsForServer(SConfig *pCfg, const char *name) { {"cacheLazyLoadThreshold", &tsCacheLazyLoadThreshold}, {"checkpointInterval", &tsStreamCheckpointInterval}, - {"keepAliveIdle", &tsKeepAliveIdle}, {"logKeepDays", &tsLogKeepDays}, {"maxStreamBackendCache", &tsMaxStreamBackendCache}, {"mqRebalanceInterval", &tsMqRebalanceInterval}, @@ -2294,7 +2286,6 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) { {"crashReporting", &tsEnableCrashReport}, {"enableQueryHb", &tsEnableQueryHb}, {"keepColumnName", &tsKeepColumnName}, - {"keepAliveIdle", &tsKeepAliveIdle}, {"logKeepDays", &tsLogKeepDays}, {"maxInsertBatchRows", &tsMaxInsertBatchRows}, {"maxRetryWaitTime", &tsMaxRetryWaitTime}, diff --git a/source/common/src/tmisce.c b/source/common/src/tmisce.c index 4df458c2bb..8988fab56a 100644 --- a/source/common/src/tmisce.c +++ b/source/common/src/tmisce.c @@ -267,7 +267,14 @@ int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol) { int8_t locked = 0; - TAOS_CHECK_GOTO(blockDataEnsureCapacity(pBlock, cfgGetSize(pConf)), NULL, _exit); + size_t exSize = 0; + size_t index = 0; + SConfigItem* pDataDirItem = cfgGetItem(pConf, "dataDir"); + if (pDataDirItem) { + exSize = TMAX(taosArrayGetSize(pDataDirItem->array), 1) - 1; + } + + TAOS_CHECK_GOTO(blockDataEnsureCapacity(pBlock, cfgGetSize(pConf) + exSize), NULL, _exit); TAOS_CHECK_GOTO(cfgCreateIter(pConf, &pIter), NULL, _exit); @@ -275,6 +282,7 @@ int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol) { locked = 1; while ((pItem = cfgNextIter(pIter)) != NULL) { +_start: col = startCol; // GRANT_CFG_SKIP; @@ -289,9 +297,18 @@ int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol) { TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, name, false), NULL, _exit); - char value[TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE] = {0}; + char value[TSDB_CONFIG_PATH_LEN + VARSTR_HEADER_SIZE] = {0}; int32_t valueLen = 0; - TAOS_CHECK_GOTO(cfgDumpItemValue(pItem, &value[VARSTR_HEADER_SIZE], TSDB_CONFIG_VALUE_LEN, &valueLen), NULL, _exit); + SDiskCfg* pDiskCfg = NULL; + if (strcasecmp(pItem->name, "dataDir") == 0 && exSize > 0) { + char* buf = &value[VARSTR_HEADER_SIZE]; + pDiskCfg = taosArrayGet(pItem->array, index); + valueLen = tsnprintf(buf, TSDB_CONFIG_PATH_LEN, "%s", pDiskCfg->dir); + index++; + } else { + TAOS_CHECK_GOTO(cfgDumpItemValue(pItem, &value[VARSTR_HEADER_SIZE], TSDB_CONFIG_PATH_LEN, &valueLen), NULL, + _exit); + } varDataSetLen(value, valueLen); pColInfo = taosArrayGet(pBlock->pDataBlock, col++); @@ -313,8 +330,28 @@ int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol) { } TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, scope, false), NULL, _exit); + char info[TSDB_CONFIG_INFO_LEN + VARSTR_HEADER_SIZE] = {0}; + if (strcasecmp(pItem->name, "dataDir") == 0 && pDiskCfg) { + char* buf = &info[VARSTR_HEADER_SIZE]; + valueLen = tsnprintf(buf, TSDB_CONFIG_INFO_LEN, "level %d primary %d disabled %" PRIi8, pDiskCfg->level, + pDiskCfg->primary, pDiskCfg->disable); + } else { + valueLen = 0; + } + varDataSetLen(info, valueLen); + + pColInfo = taosArrayGet(pBlock->pDataBlock, col++); + if (pColInfo == NULL) { + code = terrno; + TAOS_CHECK_GOTO(code, NULL, _exit); + } + TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, info, false), NULL, _exit); + numOfRows++; - } + if (index > 0 && index <= exSize) { + goto _start; + } +} pBlock->info.rows = numOfRows; _exit: if (locked) cfgUnLock(pConf); diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 6d1699b911..bc8830505e 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -5642,6 +5642,12 @@ int32_t tSerializeSShowVariablesRsp(void *buf, int32_t bufLen, SShowVariablesRsp SVariablesInfo *pInfo = taosArrayGet(pRsp->variables, i); TAOS_CHECK_EXIT(tEncodeSVariablesInfo(&encoder, pInfo)); } + + for (int32_t i = 0; i < varNum; ++i) { + SVariablesInfo *pInfo = taosArrayGet(pRsp->variables, i); + TAOS_CHECK_RETURN(tEncodeCStr(&encoder, pInfo->info)); + } + tEndEncode(&encoder); _exit: @@ -5675,6 +5681,13 @@ int32_t tDeserializeSShowVariablesRsp(void *buf, int32_t bufLen, SShowVariablesR TAOS_CHECK_EXIT(terrno); } } + + if (!tDecodeIsEnd(&decoder)) { + for (int32_t i = 0; i < varNum; ++i) { + SVariablesInfo *pInfo = taosArrayGet(pRsp->variables, i); + TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pInfo->info)); + } + } } tEndDecode(&decoder); @@ -8717,6 +8730,7 @@ int32_t tSerializeSSubQueryMsg(void *buf, int32_t bufLen, SSubQueryMsg *pReq) { TAOS_CHECK_EXIT(tEncodeCStrWithLen(&encoder, pReq->sql, pReq->sqlLen)); TAOS_CHECK_EXIT(tEncodeU32(&encoder, pReq->msgLen)); TAOS_CHECK_EXIT(tEncodeBinary(&encoder, (uint8_t *)pReq->msg, pReq->msgLen)); + TAOS_CHECK_EXIT(tEncodeU64(&encoder, pReq->clientId)); tEndEncode(&encoder); @@ -8765,6 +8779,11 @@ int32_t tDeserializeSSubQueryMsg(void *buf, int32_t bufLen, SSubQueryMsg *pReq) TAOS_CHECK_EXIT(tDecodeCStrAlloc(&decoder, &pReq->sql)); TAOS_CHECK_EXIT(tDecodeU32(&decoder, &pReq->msgLen)); TAOS_CHECK_EXIT(tDecodeBinaryAlloc(&decoder, (void **)&pReq->msg, NULL)); + if (!tDecodeIsEnd(&decoder)) { + TAOS_CHECK_EXIT(tDecodeU64(&decoder, &pReq->clientId)); + } else { + pReq->clientId = 0; + } tEndDecode(&decoder); @@ -8894,6 +8913,7 @@ int32_t tSerializeSResFetchReq(void *buf, int32_t bufLen, SResFetchReq *pReq) { } else { TAOS_CHECK_EXIT(tEncodeI32(&encoder, 0)); } + TAOS_CHECK_EXIT(tEncodeU64(&encoder, pReq->clientId)); tEndEncode(&encoder); @@ -8943,6 +8963,11 @@ int32_t tDeserializeSResFetchReq(void *buf, int32_t bufLen, SResFetchReq *pReq) } TAOS_CHECK_EXIT(tDeserializeSOperatorParam(&decoder, pReq->pOpParam)); } + if (!tDecodeIsEnd(&decoder)) { + TAOS_CHECK_EXIT(tDecodeU64(&decoder, &pReq->clientId)); + } else { + pReq->clientId = 0; + } tEndDecode(&decoder); @@ -9055,6 +9080,7 @@ int32_t tSerializeSTaskDropReq(void *buf, int32_t bufLen, STaskDropReq *pReq) { TAOS_CHECK_EXIT(tEncodeU64(&encoder, pReq->taskId)); TAOS_CHECK_EXIT(tEncodeI64(&encoder, pReq->refId)); TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->execId)); + TAOS_CHECK_EXIT(tEncodeU64(&encoder, pReq->clientId)); tEndEncode(&encoder); @@ -9095,6 +9121,11 @@ int32_t tDeserializeSTaskDropReq(void *buf, int32_t bufLen, STaskDropReq *pReq) TAOS_CHECK_EXIT(tDecodeU64(&decoder, &pReq->taskId)); TAOS_CHECK_EXIT(tDecodeI64(&decoder, &pReq->refId)); TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pReq->execId)); + if (!tDecodeIsEnd(&decoder)) { + TAOS_CHECK_EXIT(tDecodeU64(&decoder, &pReq->clientId)); + } else { + pReq->clientId = 0; + } tEndDecode(&decoder); @@ -9123,6 +9154,7 @@ int32_t tSerializeSTaskNotifyReq(void *buf, int32_t bufLen, STaskNotifyReq *pReq TAOS_CHECK_EXIT(tEncodeI64(&encoder, pReq->refId)); TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->execId)); TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->type)); + TAOS_CHECK_EXIT(tEncodeU64(&encoder, pReq->clientId)); tEndEncode(&encoder); @@ -9164,6 +9196,11 @@ int32_t tDeserializeSTaskNotifyReq(void *buf, int32_t bufLen, STaskNotifyReq *pR TAOS_CHECK_EXIT(tDecodeI64(&decoder, &pReq->refId)); TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pReq->execId)); TAOS_CHECK_EXIT(tDecodeI32(&decoder, (int32_t *)&pReq->type)); + if (!tDecodeIsEnd(&decoder)) { + TAOS_CHECK_EXIT(tDecodeU64(&decoder, &pReq->clientId)); + } else { + pReq->clientId = 0; + } tEndDecode(&decoder); @@ -9353,6 +9390,10 @@ int32_t tSerializeSSchedulerHbRsp(void *buf, int32_t bufLen, SSchedulerHbRsp *pR TAOS_CHECK_EXIT(tEncodeI32(&encoder, status->execId)); TAOS_CHECK_EXIT(tEncodeI8(&encoder, status->status)); } + for (int32_t i = 0; i < num; ++i) { + STaskStatus *status = taosArrayGet(pRsp->taskStatus, i); + TAOS_CHECK_EXIT(tEncodeU64(&encoder, status->clientId)); + } } else { TAOS_CHECK_EXIT(tEncodeI32(&encoder, 0)); } @@ -9396,6 +9437,12 @@ int32_t tDeserializeSSchedulerHbRsp(void *buf, int32_t bufLen, SSchedulerHbRsp * TAOS_CHECK_EXIT(terrno); } } + if (!tDecodeIsEnd(&decoder)) { + for (int32_t i = 0; i < num; ++i) { + STaskStatus *status = taosArrayGet(pRsp->taskStatus, i); + TAOS_CHECK_EXIT(tDecodeU64(&decoder, &status->clientId)); + } + } } else { pRsp->taskStatus = NULL; } @@ -9560,6 +9607,7 @@ int32_t tSerializeSVDeleteReq(void *buf, int32_t bufLen, SVDeleteReq *pReq) { TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->sql)); TAOS_CHECK_EXIT(tEncodeBinary(&encoder, pReq->msg, pReq->phyLen)); TAOS_CHECK_EXIT(tEncodeI8(&encoder, pReq->source)); + TAOS_CHECK_EXIT(tEncodeU64(&encoder, pReq->clientId)); tEndEncode(&encoder); _exit: @@ -9608,6 +9656,11 @@ int32_t tDeserializeSVDeleteReq(void *buf, int32_t bufLen, SVDeleteReq *pReq) { if (!tDecodeIsEnd(&decoder)) { TAOS_CHECK_EXIT(tDecodeI8(&decoder, &pReq->source)); } + if (!tDecodeIsEnd(&decoder)) { + TAOS_CHECK_EXIT(tDecodeU64(&decoder, &pReq->clientId)); + } else { + pReq->clientId = 0; + } tEndDecode(&decoder); _exit: diff --git a/source/common/src/ttime.c b/source/common/src/ttime.c index 75624593d9..ecdb3de9a2 100644 --- a/source/common/src/ttime.c +++ b/source/common/src/ttime.c @@ -30,7 +30,7 @@ static int64_t m_deltaUtc = 0; void deltaToUtcInitOnce() { struct tm tm = {0}; - if (taosStrpTime("1970-01-01 00:00:00", (const char*)("%Y-%m-%d %H:%M:%S"), &tm) != 0) { + if (taosStrpTime("1970-01-01 00:00:00", (const char*)("%Y-%m-%d %H:%M:%S"), &tm) == NULL) { uError("failed to parse time string"); } m_deltaUtc = (int64_t)taosMktime(&tm); diff --git a/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h index 989adf84ac..7842077d88 100644 --- a/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h +++ b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h @@ -37,7 +37,9 @@ typedef struct SVnodeMgmt { SSingleWorker mgmtMultiWorker; SHashObj *hash; SHashObj *closedHash; + SHashObj *creatingHash; TdThreadRwlock lock; + TdThreadMutex mutex; SVnodesStat state; STfs *pTfs; TdThread thread; @@ -96,6 +98,7 @@ SVnodeObj *vmAcquireVnodeImpl(SVnodeMgmt *pMgmt, int32_t vgId, bool strict); void vmReleaseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode); int32_t vmOpenVnode(SVnodeMgmt *pMgmt, SWrapperCfg *pCfg, SVnode *pImpl); void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode, bool commitAndRemoveWal, bool keepClosed); +void vmRemoveFromCreatingHash(SVnodeMgmt *pMgmt, int32_t vgId); // vmHandle.c SArray *vmGetMsgHandles(); @@ -113,6 +116,7 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt); int32_t vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes, SVnodeObj ***ppVnodes); int32_t vmGetAllVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes, SVnodeObj ***ppVnodes); +int32_t vmGetAllVnodeListFromHashWithCreating(SVnodeMgmt *pMgmt, int32_t *numOfVnodes, SVnodeObj ***ppVnodes); // vmWorker.c int32_t vmStartWorker(SVnodeMgmt *pMgmt); diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmFile.c b/source/dnode/mgmt/mgmt_vnode/src/vmFile.c index 7566b69c02..b4453ad6fc 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmFile.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmFile.c @@ -67,6 +67,54 @@ int32_t vmGetAllVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes, SVnod return 0; } +int32_t vmGetAllVnodeListFromHashWithCreating(SVnodeMgmt *pMgmt, int32_t *numOfVnodes, SVnodeObj ***ppVnodes) { + (void)taosThreadRwlockRdlock(&pMgmt->lock); + + int32_t num = 0; + int32_t size = taosHashGetSize(pMgmt->hash); + int32_t creatingSize = taosHashGetSize(pMgmt->creatingHash); + size += creatingSize; + SVnodeObj **pVnodes = taosMemoryCalloc(size, sizeof(SVnodeObj *)); + if (pVnodes == NULL) { + (void)taosThreadRwlockUnlock(&pMgmt->lock); + return terrno; + } + + void *pIter = taosHashIterate(pMgmt->hash, NULL); + while (pIter) { + SVnodeObj **ppVnode = pIter; + SVnodeObj *pVnode = *ppVnode; + if (pVnode && num < size) { + int32_t refCount = atomic_add_fetch_32(&pVnode->refCount, 1); + dTrace("vgId:%d,acquire vnode, vnode:%p, ref:%d", pVnode->vgId, pVnode, refCount); + pVnodes[num++] = (*ppVnode); + pIter = taosHashIterate(pMgmt->hash, pIter); + } else { + taosHashCancelIterate(pMgmt->hash, pIter); + } + } + + pIter = taosHashIterate(pMgmt->creatingHash, NULL); + while (pIter) { + SVnodeObj **ppVnode = pIter; + SVnodeObj *pVnode = *ppVnode; + if (pVnode && num < size) { + int32_t refCount = atomic_add_fetch_32(&pVnode->refCount, 1); + dTrace("vgId:%d, acquire vnode, vnode:%p, ref:%d", pVnode->vgId, pVnode, refCount); + pVnodes[num++] = (*ppVnode); + pIter = taosHashIterate(pMgmt->creatingHash, pIter); + } else { + taosHashCancelIterate(pMgmt->creatingHash, pIter); + } + } + (void)taosThreadRwlockUnlock(&pMgmt->lock); + + *numOfVnodes = num; + *ppVnodes = pVnodes; + + return 0; +} + int32_t vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes, SVnodeObj ***ppVnodes) { (void)taosThreadRwlockRdlock(&pMgmt->lock); diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index 006f44b349..90b3f0025d 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -381,6 +381,7 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { if (vnodeCreate(path, &vnodeCfg, diskPrimary, pMgmt->pTfs) < 0) { dError("vgId:%d, failed to create vnode since %s", req.vgId, terrstr()); vmReleaseVnode(pMgmt, pVnode); + vmRemoveFromCreatingHash(pMgmt, req.vgId); (void)tFreeSCreateVnodeReq(&req); code = terrno != 0 ? terrno : -1; return code; @@ -422,6 +423,8 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { } _OVER: + vmRemoveFromCreatingHash(pMgmt, req.vgId); + if (code != 0) { int32_t r = 0; r = taosThreadRwlockWrlock(&pMgmt->lock); diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c index 682c179270..2ee607949d 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c @@ -16,6 +16,7 @@ #define _DEFAULT_SOURCE #include "vmInt.h" #include "libs/function/tudf.h" +#include "osMemory.h" #include "tfs.h" #include "vnd.h" @@ -62,10 +63,20 @@ int32_t vmAllocPrimaryDisk(SVnodeMgmt *pMgmt, int32_t vgId) { int32_t numOfVnodes = 0; SVnodeObj **ppVnodes = NULL; - code = vmGetVnodeListFromHash(pMgmt, &numOfVnodes, &ppVnodes); + code = taosThreadMutexLock(&pMgmt->mutex); if (code != 0) { return code; } + + code = vmGetAllVnodeListFromHashWithCreating(pMgmt, &numOfVnodes, &ppVnodes); + if (code != 0) { + int32_t r = taosThreadMutexUnlock(&pMgmt->mutex); + if (r != 0) { + dError("vgId:%d, failed to unlock mutex since %s", vgId, tstrerror(r)); + } + return code; + } + for (int32_t v = 0; v < numOfVnodes; v++) { SVnodeObj *pVnode = ppVnodes[v]; disks[pVnode->diskPrimary] += 1; @@ -81,6 +92,51 @@ int32_t vmAllocPrimaryDisk(SVnodeMgmt *pMgmt, int32_t vgId) { } } + SVnodeObj *pCreatingVnode = taosMemoryCalloc(1, sizeof(SVnodeObj)); + if (pCreatingVnode == NULL) { + code = -1; + if (terrno != 0) code = terrno; + dError("failed to alloc vnode since %s", tstrerror(code)); + int32_t r = taosThreadMutexUnlock(&pMgmt->mutex); + if (r != 0) { + dError("vgId:%d, failed to unlock mutex since %s", vgId, tstrerror(r)); + } + goto _OVER; + } + (void)memset(pCreatingVnode, 0, sizeof(SVnodeObj)); + + pCreatingVnode->vgId = vgId; + pCreatingVnode->diskPrimary = diskId; + + code = taosThreadRwlockWrlock(&pMgmt->lock); + if (code != 0) { + int32_t r = taosThreadMutexUnlock(&pMgmt->mutex); + if (r != 0) { + dError("vgId:%d, failed to unlock mutex since %s", vgId, tstrerror(r)); + } + taosMemoryFree(pCreatingVnode); + goto _OVER; + } + + dTrace("vgId:%d, put vnode into creating hash, pCreatingVnode:%p", vgId, pCreatingVnode); + code = taosHashPut(pMgmt->creatingHash, &vgId, sizeof(int32_t), &pCreatingVnode, sizeof(SVnodeObj *)); + if (code != 0) { + dError("vgId:%d, failed to put vnode to creatingHash", vgId); + taosMemoryFree(pCreatingVnode); + } + + int32_t r = taosThreadRwlockUnlock(&pMgmt->lock); + if (r != 0) { + dError("vgId:%d, failed to unlock since %s", vgId, tstrerror(r)); + } + + code = taosThreadMutexUnlock(&pMgmt->mutex); + if (code != 0) { + goto _OVER; + } + +_OVER: + for (int32_t i = 0; i < numOfVnodes; ++i) { if (ppVnodes == NULL || ppVnodes[i] == NULL) continue; vmReleaseVnode(pMgmt, ppVnodes[i]); @@ -89,8 +145,13 @@ int32_t vmAllocPrimaryDisk(SVnodeMgmt *pMgmt, int32_t vgId) { taosMemoryFree(ppVnodes); } - dInfo("vgId:%d, alloc disk:%d of level 0. ndisk:%d, vnodes: %d", vgId, diskId, ndisk, numOfVnodes); - return diskId; + if (code != 0) { + dError("vgId:%d, failed to alloc disk since %s", vgId, tstrerror(code)); + return code; + } else { + dInfo("vgId:%d, alloc disk:%d of level 0. ndisk:%d, vnodes: %d", vgId, diskId, ndisk, numOfVnodes); + return diskId; + } } SVnodeObj *vmAcquireVnodeImpl(SVnodeMgmt *pMgmt, int32_t vgId, bool strict) { @@ -216,12 +277,12 @@ void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode, bool commitAndRemoveWal, } if (keepClosed) { SVnodeObj *pClosedVnode = taosMemoryCalloc(1, sizeof(SVnodeObj)); - (void)memset(pClosedVnode, 0, sizeof(SVnodeObj)); - if (pVnode == NULL) { - dError("vgId:%d, failed to alloc vnode since %s", pVnode->vgId, terrstr()); + if (pClosedVnode == NULL) { + dError("failed to alloc vnode since %s", terrstr()); (void)taosThreadRwlockUnlock(&pMgmt->lock); return; } + (void)memset(pClosedVnode, 0, sizeof(SVnodeObj)); pClosedVnode->vgId = pVnode->vgId; pClosedVnode->dropped = pVnode->dropped; @@ -427,11 +488,18 @@ static int32_t vmOpenVnodes(SVnodeMgmt *pMgmt) { pMgmt->closedHash = taosHashInit(TSDB_MIN_VNODES, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK); - if (pMgmt->hash == NULL) { + if (pMgmt->closedHash == NULL) { dError("failed to init vnode closed hash since %s", terrstr()); return TSDB_CODE_OUT_OF_MEMORY; } + pMgmt->creatingHash = + taosHashInit(TSDB_MIN_VNODES, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK); + if (pMgmt->creatingHash == NULL) { + dError("failed to init vnode creatingHash hash since %s", terrstr()); + return TSDB_CODE_OUT_OF_MEMORY; + } + SWrapperCfg *pCfgs = NULL; int32_t numOfVnodes = 0; if (vmGetVnodeListFromFile(pMgmt, &pCfgs, &numOfVnodes) != 0) { @@ -509,6 +577,30 @@ static int32_t vmOpenVnodes(SVnodeMgmt *pMgmt) { return 0; } +void vmRemoveFromCreatingHash(SVnodeMgmt *pMgmt, int32_t vgId) { + (void)taosThreadRwlockWrlock(&pMgmt->lock); + SVnodeObj *pOld = NULL; + int32_t r = taosHashGetDup(pMgmt->creatingHash, &vgId, sizeof(int32_t), (void *)&pOld); + if (r != 0) { + dError("vgId:%d, failed to get vnode from creating Hash", vgId); + } + if (pOld) { + dTrace("vgId:%d, free vnode pOld:%p", vgId, &pOld); + vmFreeVnodeObj(&pOld); + } + dTrace("vgId:%d, remove from creating Hash", vgId); + r = taosHashRemove(pMgmt->creatingHash, &vgId, sizeof(int32_t)); + if (r != 0) { + dError("vgId:%d, failed to remove vnode from hash", vgId); + } + (void)taosThreadRwlockUnlock(&pMgmt->lock); + +_OVER: + if (r != 0) { + dError("vgId:%d, failed to remove vnode from creatingHash since %s", vgId, tstrerror(r)); + } +} + static void *vmCloseVnodeInThread(void *param) { SVnodeThread *pThread = param; SVnodeMgmt *pMgmt = pThread->pMgmt; @@ -614,6 +706,18 @@ static void vmCloseVnodes(SVnodeMgmt *pMgmt) { pMgmt->closedHash = NULL; } + pIter = taosHashIterate(pMgmt->creatingHash, NULL); + while (pIter) { + SVnodeObj **ppVnode = pIter; + vmFreeVnodeObj(ppVnode); + pIter = taosHashIterate(pMgmt->creatingHash, pIter); + } + + if (pMgmt->creatingHash != NULL) { + taosHashCleanup(pMgmt->creatingHash); + pMgmt->creatingHash = NULL; + } + dInfo("total vnodes:%d are all closed", numOfVnodes); } @@ -622,6 +726,7 @@ static void vmCleanup(SVnodeMgmt *pMgmt) { vmStopWorker(pMgmt); vnodeCleanup(); (void)taosThreadRwlockDestroy(&pMgmt->lock); + (void)taosThreadMutexDestroy(&pMgmt->mutex); (void)taosThreadMutexDestroy(&pMgmt->fileLock); taosMemoryFree(pMgmt); } @@ -714,6 +819,12 @@ static int32_t vmInit(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) { goto _OVER; } + code = taosThreadMutexInit(&pMgmt->mutex, NULL); + if (code != 0) { + code = TAOS_SYSTEM_ERROR(errno); + goto _OVER; + } + code = taosThreadMutexInit(&pMgmt->fileLock, NULL); if (code != 0) { code = TAOS_SYSTEM_ERROR(errno); diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 24ae8382f9..8931558874 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -1104,6 +1104,7 @@ static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) { (void)strcpy(info.name, "statusInterval"); (void)snprintf(info.value, TSDB_CONFIG_VALUE_LEN, "%d", tsStatusInterval); (void)strcpy(info.scope, "server"); + // fill info.info if (taosArrayPush(rsp.variables, &info) == NULL) { code = terrno; goto _OVER; diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index 610ba43673..743bfd36d0 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -172,7 +172,7 @@ void tsdbReleaseDataBlock2(STsdbReader *pReader); int32_t tsdbRetrieveDataBlock2(STsdbReader *pReader, SSDataBlock **pBlock, SArray *pIdList); int32_t tsdbReaderReset2(STsdbReader *pReader, SQueryTableDataCond *pCond); int32_t tsdbGetFileBlocksDistInfo2(STsdbReader *pReader, STableBlockDistInfo *pTableBlockInfo); -int64_t tsdbGetNumOfRowsInMemTable2(STsdbReader *pHandle); +int64_t tsdbGetNumOfRowsInMemTable2(STsdbReader *pHandle, uint32_t *rows); void *tsdbGetIdx2(SMeta *pMeta); void *tsdbGetIvtIdx2(SMeta *pMeta); uint64_t tsdbGetReaderMaxVersion2(STsdbReader *pReader); diff --git a/source/dnode/vnode/src/meta/metaOpen.c b/source/dnode/vnode/src/meta/metaOpen.c index 659ba3f777..9a5bea33e3 100644 --- a/source/dnode/vnode/src/meta/metaOpen.c +++ b/source/dnode/vnode/src/meta/metaOpen.c @@ -324,7 +324,11 @@ static int32_t metaGenerateNewMeta(SMeta **ppMeta) { SMetaEntry me = {0}; tDecoderInit(&dc, value, valueSize); if (metaDecodeEntry(&dc, &me) == 0) { - if (metaHandleEntry(pNewMeta, &me) != 0) { + if (me.type == TSDB_CHILD_TABLE && + tdbTbGet(pMeta->pUidIdx, &me.ctbEntry.suid, sizeof(me.ctbEntry.suid), NULL, NULL) != 0) { + metaError("vgId:%d failed to get super table uid:%" PRId64 " for child table uid:%" PRId64, + TD_VID(pVnode), me.ctbEntry.suid, uid); + } else if (metaHandleEntry(pNewMeta, &me) != 0) { metaError("vgId:%d failed to handle entry, uid:%" PRId64, TD_VID(pVnode), uid); } } diff --git a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c index d508d75922..0f524e22d7 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c @@ -25,82 +25,109 @@ #define HASTYPE(_type, _t) (((_type) & (_t)) == (_t)) static int32_t setFirstLastResColToNull(SColumnInfoData* pCol, int32_t row) { - char* buf = taosMemoryCalloc(1, pCol->info.bytes); - if (buf == NULL) { - return terrno; - } + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + char* buf = NULL; + SFirstLastRes* pRes = NULL; - SFirstLastRes* pRes = (SFirstLastRes*)((char*)buf + VARSTR_HEADER_SIZE); + TSDB_CHECK_NULL(pCol, code, lino, _end, TSDB_CODE_INVALID_PARA); + + buf = taosMemoryCalloc(1, pCol->info.bytes); + TSDB_CHECK_NULL(buf, code, lino, _end, terrno); + + pRes = (SFirstLastRes*)((char*)buf + VARSTR_HEADER_SIZE); pRes->bytes = 0; pRes->hasResult = true; pRes->isNull = true; varDataSetLen(buf, pCol->info.bytes - VARSTR_HEADER_SIZE); - int32_t code = colDataSetVal(pCol, row, buf, false); - taosMemoryFree(buf); + code = colDataSetVal(pCol, row, buf, false); + TSDB_CHECK_CODE(code, lino, _end); +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + if (buf != NULL) { + taosMemoryFreeClear(buf); + } return code; } static int32_t saveOneRowForLastRaw(SLastCol* pColVal, SCacheRowsReader* pReader, const int32_t slotId, - SColumnInfoData* pColInfoData, int32_t numOfRows) { - SColVal* pVal = &pColVal->colVal; - int32_t code = 0; + SColumnInfoData* pColInfoData, int32_t numOfRows) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SColVal* pVal = NULL; + + TSDB_CHECK_NULL(pColVal, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pColInfoData, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pVal = &pColVal->colVal; // allNullRow = false; if (IS_VAR_DATA_TYPE(pColVal->colVal.value.type)) { if (!COL_VAL_IS_VALUE(&pColVal->colVal)) { colDataSetNULL(pColInfoData, numOfRows); } else { + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); varDataSetLen(pReader->transferBuf[slotId], pVal->value.nData); memcpy(varDataVal(pReader->transferBuf[slotId]), pVal->value.pData, pVal->value.nData); code = colDataSetVal(pColInfoData, numOfRows, pReader->transferBuf[slotId], false); + TSDB_CHECK_CODE(code, lino, _end); } } else { code = colDataSetVal(pColInfoData, numOfRows, (const char*)&pVal->value.val, !COL_VAL_IS_VALUE(pVal)); + TSDB_CHECK_CODE(code, lino, _end); } +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } static int32_t saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* pReader, const int32_t* slotIds, const int32_t* dstSlotIds, void** pRes, const char* idStr) { - int32_t numOfRows = pBlock->info.rows; - int32_t code = 0; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + int32_t numOfRows = 0; + SArray* funcTypeBlockArray = NULL; + + TSDB_CHECK_NULL(pBlock, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + if (pReader->numOfCols > 0) { + TSDB_CHECK_NULL(slotIds, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(dstSlotIds, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pRes, code, lino, _end, TSDB_CODE_INVALID_PARA); + } + + numOfRows = pBlock->info.rows; if (HASTYPE(pReader->type, CACHESCAN_RETRIEVE_LAST)) { uint64_t ts = TSKEY_MIN; SFirstLastRes* p = NULL; col_id_t colId = -1; - SArray* funcTypeBlockArray = taosArrayInit(pReader->numOfCols, sizeof(int32_t)); - if (funcTypeBlockArray == NULL) { - return terrno; - } + funcTypeBlockArray = taosArrayInit(pReader->numOfCols, sizeof(int32_t)); + TSDB_CHECK_NULL(funcTypeBlockArray, code, lino, _end, terrno); for (int32_t i = 0; i < pReader->numOfCols; ++i) { SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotIds[i]); - if (pColInfoData == NULL) { - return TSDB_CODE_INVALID_PARA; - } + TSDB_CHECK_NULL(pColInfoData, code, lino, _end, TSDB_CODE_INVALID_PARA); int32_t funcType = FUNCTION_TYPE_CACHE_LAST; if (pReader->pFuncTypeList != NULL && taosArrayGetSize(pReader->pFuncTypeList) > i) { void* pVal = taosArrayGet(pReader->pFuncTypeList, i); - if (pVal == NULL) { - return TSDB_CODE_INVALID_PARA; - } + TSDB_CHECK_NULL(pVal, code, lino, _end, TSDB_CODE_INVALID_PARA); - funcType = *(int32_t*) pVal; + funcType = *(int32_t*)pVal; pVal = taosArrayGet(pReader->pFuncTypeList, i); - if (pVal == NULL) { - return TSDB_CODE_INVALID_PARA; - } + TSDB_CHECK_NULL(pVal, code, lino, _end, TSDB_CODE_INVALID_PARA); void* px = taosArrayInsert(funcTypeBlockArray, dstSlotIds[i], pVal); - if (px == NULL) { - return terrno; - } + TSDB_CHECK_NULL(px, code, lino, _end, terrno); } if (slotIds[i] == -1) { @@ -110,24 +137,18 @@ static int32_t saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* p } code = setFirstLastResColToNull(pColInfoData, numOfRows); - if (code) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); continue; } int32_t slotId = slotIds[i]; SLastCol* pColVal = (SLastCol*)taosArrayGet(pRow, i); - if (pColVal == NULL) { - return TSDB_CODE_INVALID_PARA; - } + TSDB_CHECK_NULL(pColVal, code, lino, _end, TSDB_CODE_INVALID_PARA); colId = pColVal->colVal.cid; if (FUNCTION_TYPE_CACHE_LAST_ROW == funcType) { code = saveOneRowForLastRaw(pColVal, pReader, slotId, pColInfoData, numOfRows); - if (code) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); continue; } @@ -154,22 +175,16 @@ static int32_t saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* p p->hasResult = true; varDataSetLen(pRes[i], pColInfoData->info.bytes - VARSTR_HEADER_SIZE); code = colDataSetVal(pColInfoData, numOfRows, (const char*)pRes[i], false); - if (code) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } for (int32_t idx = 0; idx < taosArrayGetSize(pBlock->pDataBlock); ++idx) { SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, idx); - if (pCol == NULL) { - return TSDB_CODE_INVALID_PARA; - } + TSDB_CHECK_NULL(pCol, code, lino, _end, TSDB_CODE_INVALID_PARA); if (idx < funcTypeBlockArray->size) { void* pVal = taosArrayGet(funcTypeBlockArray, idx); - if (pVal == NULL) { - return TSDB_CODE_INVALID_PARA; - } + TSDB_CHECK_NULL(pVal, code, lino, _end, TSDB_CODE_INVALID_PARA); int32_t funcType = *(int32_t*)pVal; if (FUNCTION_TYPE_CACHE_LAST_ROW == funcType) { @@ -182,17 +197,13 @@ static int32_t saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* p colDataSetNULL(pCol, numOfRows); } else { code = colDataSetVal(pCol, numOfRows, (const char*)&ts, false); - if (code) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } continue; } else if (pReader->numOfCols == 1 && idx != dstSlotIds[0] && (pCol->info.colId == colId || colId == -1)) { if (p && !p->isNull) { code = colDataSetVal(pCol, numOfRows, p->buf, false); - if (code) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } else { colDataSetNULL(pCol, numOfRows); } @@ -201,13 +212,10 @@ static int32_t saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* p // pBlock->info.rows += allNullRow ? 0 : 1; ++pBlock->info.rows; - taosArrayDestroy(funcTypeBlockArray); } else if (HASTYPE(pReader->type, CACHESCAN_RETRIEVE_LAST_ROW)) { for (int32_t i = 0; i < pReader->numOfCols; ++i) { SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotIds[i]); - if (pColInfoData == NULL) { - return TSDB_CODE_INVALID_PARA; - } + TSDB_CHECK_NULL(pColInfoData, code, lino, _end, TSDB_CODE_INVALID_PARA); int32_t slotId = slotIds[i]; if (slotId == -1) { @@ -216,47 +224,53 @@ static int32_t saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* p } SLastCol* pColVal = (SLastCol*)taosArrayGet(pRow, i); - if (pColVal == NULL) { - return TSDB_CODE_INVALID_PARA; - } + TSDB_CHECK_NULL(pColVal, code, lino, _end, TSDB_CODE_INVALID_PARA); code = saveOneRowForLastRaw(pColVal, pReader, slotId, pColInfoData, numOfRows); - if (code) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } // pBlock->info.rows += allNullRow ? 0 : 1; ++pBlock->info.rows; } else { tsdbError("invalid retrieve type:%d, %s", pReader->type, idStr); - return TSDB_CODE_INVALID_PARA; + code = TSDB_CODE_INVALID_PARA; + TSDB_CHECK_CODE(code, lino, _end); } +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + if (funcTypeBlockArray != NULL) { + taosArrayDestroy(funcTypeBlockArray); + } return code; } static int32_t setTableSchema(SCacheRowsReader* p, uint64_t suid, const char* idstr) { - int32_t numOfTables = p->numOfTables; - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + int32_t numOfTables = 0; + + TSDB_CHECK_NULL(p, code, lino, _end, TSDB_CODE_INVALID_PARA); + + numOfTables = p->numOfTables; if (suid != 0) { code = metaGetTbTSchemaNotNull(p->pVnode->pMeta, suid, -1, 1, &p->pSchema); if (TSDB_CODE_SUCCESS != code) { tsdbWarn("stable:%" PRIu64 " has been dropped, failed to retrieve cached rows, %s", suid, idstr); - if(code == TSDB_CODE_NOT_FOUND) { - return TSDB_CODE_PAR_TABLE_NOT_EXIST; - } else { - return code; + if (code == TSDB_CODE_NOT_FOUND) { + code = TSDB_CODE_PAR_TABLE_NOT_EXIST; } + TSDB_CHECK_CODE(code, lino, _end); } } else { for (int32_t i = 0; i < numOfTables; ++i) { uint64_t uid = p->pTableList[i].uid; code = metaGetTbTSchemaMaybeNull(p->pVnode->pMeta, uid, -1, 1, &p->pSchema); - if(code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if (p->pSchema != NULL) { break; } @@ -267,33 +281,52 @@ static int32_t setTableSchema(SCacheRowsReader* p, uint64_t suid, const char* id // all queried tables have been dropped already, return immediately. if (p->pSchema == NULL) { tsdbWarn("all queried tables has been dropped, try next group, %s", idstr); - return TSDB_CODE_PAR_TABLE_NOT_EXIST; + code = TSDB_CODE_PAR_TABLE_NOT_EXIST; + TSDB_CHECK_CODE(code, lino, _end); } } - return TSDB_CODE_SUCCESS; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } int32_t tsdbReuseCacherowsReader(void* reader, void* pTableIdList, int32_t numOfTables) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; SCacheRowsReader* pReader = (SCacheRowsReader*)reader; + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + pReader->pTableList = pTableIdList; pReader->numOfTables = numOfTables; pReader->lastTs = INT64_MIN; destroySttBlockReader(pReader->pLDataIterArray, NULL); pReader->pLDataIterArray = taosArrayInit(4, POINTER_BYTES); + TSDB_CHECK_NULL(pReader->pLDataIterArray, code, lino, _end, terrno); - return (pReader->pLDataIterArray != NULL) ? TSDB_CODE_SUCCESS : terrno; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } int32_t tsdbCacherowsReaderOpen(void* pVnode, int32_t type, void* pTableIdList, int32_t numOfTables, int32_t numOfCols, SArray* pCidList, int32_t* pSlotIds, uint64_t suid, void** pReader, const char* idstr, SArray* pFuncTypeList, SColumnInfo* pPkCol, int32_t numOfPks) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SCacheRowsReader* p = NULL; + + TSDB_CHECK_NULL(pVnode, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + *pReader = NULL; - SCacheRowsReader* p = taosMemoryCalloc(1, sizeof(SCacheRowsReader)); - if (p == NULL) { - return terrno; - } + p = taosMemoryCalloc(1, sizeof(SCacheRowsReader)); + TSDB_CHECK_NULL(p, code, lino, _end, terrno); p->type = type; p->pVnode = pVnode; @@ -307,12 +340,13 @@ int32_t tsdbCacherowsReaderOpen(void* pVnode, int32_t type, void* pTableIdList, p->rowKey.numOfPKs = numOfPks; if (numOfPks > 0) { + TSDB_CHECK_NULL(pPkCol, code, lino, _end, TSDB_CODE_INVALID_PARA); p->rowKey.pks[0].type = pPkCol->type; if (IS_VAR_DATA_TYPE(pPkCol->type)) { p->rowKey.pks[0].pData = taosMemoryCalloc(1, pPkCol->bytes); if (p->rowKey.pks[0].pData == NULL) { - taosMemoryFree(p); - return terrno; + taosMemoryFreeClear(p); + TSDB_CHECK_NULL(p->rowKey.pks[0].pData, code, lino, _end, terrno); } } @@ -321,48 +355,46 @@ int32_t tsdbCacherowsReaderOpen(void* pVnode, int32_t type, void* pTableIdList, if (numOfTables == 0) { *pReader = p; - return TSDB_CODE_SUCCESS; + p = NULL; + goto _end; } p->pTableList = pTableIdList; p->numOfTables = numOfTables; - int32_t code = setTableSchema(p, suid, idstr); - if (code != TSDB_CODE_SUCCESS) { - tsdbCacherowsReaderClose(p); - return code; - } + code = setTableSchema(p, suid, idstr); + TSDB_CHECK_CODE(code, lino, _end); p->transferBuf = taosMemoryCalloc(p->pSchema->numOfCols, POINTER_BYTES); - if (p->transferBuf == NULL) { - tsdbCacherowsReaderClose(p); - return terrno; - } + TSDB_CHECK_NULL(p->transferBuf, code, lino, _end, terrno); for (int32_t i = 0; i < p->pSchema->numOfCols; ++i) { if (IS_VAR_DATA_TYPE(p->pSchema->columns[i].type)) { p->transferBuf[i] = taosMemoryMalloc(p->pSchema->columns[i].bytes); - if (p->transferBuf[i] == NULL) { - tsdbCacherowsReaderClose(p); - return terrno; - } + TSDB_CHECK_NULL(p->transferBuf[i], code, lino, _end, terrno); } } - p->idstr = taosStrdup(idstr); - if (idstr != NULL && p->idstr == NULL) { - tsdbCacherowsReaderClose(p); - return terrno; + if (idstr != NULL) { + p->idstr = taosStrdup(idstr); + TSDB_CHECK_NULL(p->idstr, code, lino, _end, terrno); } code = taosThreadMutexInit(&p->readerMutex, NULL); - if (code) { - tsdbCacherowsReaderClose(p); - return code; - } + TSDB_CHECK_CODE(code, lino, _end); p->lastTs = INT64_MIN; *pReader = p; + p = NULL; + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + *pReader = NULL; + } + if (p != NULL) { + tsdbCacherowsReaderClose(p); + } return code; } @@ -393,6 +425,7 @@ void tsdbCacherowsReaderClose(void* pReader) { if (p->pLDataIterArray) { destroySttBlockReader(p->pLDataIterArray, NULL); + p->pLDataIterArray = NULL; } if (p->pFileReader) { @@ -401,7 +434,7 @@ void tsdbCacherowsReaderClose(void* pReader) { } taosMemoryFree((void*)p->idstr); - (void) taosThreadMutexDestroy(&p->readerMutex); + (void)taosThreadMutexDestroy(&p->readerMutex); if (p->pTableMap) { void* pe = NULL; @@ -443,39 +476,32 @@ static int32_t tsdbCacheQueryReseek(void* pQHandle) { int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32_t* slotIds, const int32_t* dstSlotIds, SArray* pTableUidList, bool* pGotAll) { - if (pReader == NULL || pResBlock == NULL) { - return TSDB_CODE_INVALID_PARA; - } - int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; bool hasRes = false; SArray* pRow = NULL; void** pRes = NULL; - SCacheRowsReader* pr = pReader; + SCacheRowsReader* pr = NULL; int32_t pkBufLen = 0; + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pResBlock, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pr = pReader; + pr->pReadSnap = NULL; pRow = taosArrayInit(TARRAY_SIZE(pr->pCidList), sizeof(SLastCol)); - if (pRow == NULL) { - code = terrno; - goto _end; - } + TSDB_CHECK_NULL(pRow, code, lino, _end, terrno); pRes = taosMemoryCalloc(pr->numOfCols, POINTER_BYTES); - if (pRes == NULL) { - code = terrno; - goto _end; - } + TSDB_CHECK_NULL(pRes, code, lino, _end, terrno); pkBufLen = (pr->rowKey.numOfPKs > 0) ? pr->pkColumn.bytes : 0; for (int32_t j = 0; j < pr->numOfCols; ++j) { int32_t bytes = (slotIds[j] == -1) ? 1 : pr->pSchema->columns[slotIds[j]].bytes; pRes[j] = taosMemoryCalloc(1, sizeof(SFirstLastRes) + bytes + pkBufLen + VARSTR_HEADER_SIZE); - if (pRes[j] == NULL) { - code = terrno; - goto _end; - } + TSDB_CHECK_NULL(pRes[j], code, lino, _end, terrno); SFirstLastRes* p = (SFirstLastRes*)varDataVal(pRes[j]); p->ts = INT64_MIN; @@ -483,9 +509,7 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32 (void)taosThreadMutexLock(&pr->readerMutex); code = tsdbTakeReadSnap2((STsdbReader*)pr, tsdbCacheQueryReseek, &pr->pReadSnap, pr->idstr); - if (code != TSDB_CODE_SUCCESS) { - goto _end; - } + TSDB_CHECK_CODE(code, lino, _end); int8_t ltype = (pr->type & CACHESCAN_RETRIEVE_LAST) >> 3; @@ -494,20 +518,14 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32 // retrieve the only one last row of all tables in the uid list. if (HASTYPE(pr->type, CACHESCAN_RETRIEVE_TYPE_SINGLE)) { SArray* pLastCols = taosArrayInit(pr->numOfCols, sizeof(SLastCol)); - if (pLastCols == NULL) { - code = terrno; - goto _end; - } + TSDB_CHECK_NULL(pLastCols, code, lino, _end, terrno); for (int32_t i = 0; i < pr->numOfCols; ++i) { int32_t slotId = slotIds[i]; if (slotId == -1) { SLastCol p = {.rowKey.ts = INT64_MIN, .colVal.value.type = TSDB_DATA_TYPE_BOOL, .colVal.flag = CV_FLAG_NULL}; void* px = taosArrayPush(pLastCols, &p); - if (px == NULL) { - code = terrno; - goto _end; - } + TSDB_CHECK_NULL(px, code, lino, _end, terrno); continue; } struct STColumn* pCol = &pr->pSchema->columns[slotId]; @@ -518,29 +536,19 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32 for (int32_t j = 0; j < pr->rowKey.numOfPKs; j++) { p.rowKey.pks[j].type = pr->pkColumn.type; if (IS_VAR_DATA_TYPE(pr->pkColumn.type)) { - p.rowKey.pks[j].pData = taosMemoryCalloc(1, pr->pkColumn.bytes); - if (p.rowKey.pks[j].pData == NULL) { - code = terrno; - goto _end; - } + TSDB_CHECK_NULL(p.rowKey.pks[j].pData, code, lino, _end, terrno); } } } if (IS_VAR_DATA_TYPE(pCol->type)) { p.colVal.value.pData = taosMemoryCalloc(pCol->bytes, sizeof(char)); - if (p.colVal.value.pData == NULL) { - code = terrno; - goto _end; - } + TSDB_CHECK_NULL(p.colVal.value.pData, code, lino, _end, terrno); } void* px = taosArrayPush(pLastCols, &p); - if (px == NULL) { - code = terrno; - goto _end; - } + TSDB_CHECK_NULL(px, code, lino, _end, terrno); } int64_t st = taosGetTimestampUs(); @@ -549,11 +557,10 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32 tb_uid_t uid = pTableList[i].uid; code = tsdbCacheGetBatch(pr->pTsdb, uid, pRow, pr, ltype); - if (code == -1) {// fix the invalid return code + if (code == -1) { // fix the invalid return code code = 0; - } else if (code != 0) { - goto _end; } + TSDB_CHECK_CODE(code, lino, _end); if (TARRAY_SIZE(pRow) <= 0 || COL_VAL_IS_NONE(&((SLastCol*)TARRAY_DATA(pRow))[0].colVal)) { taosArrayClearEx(pRow, tsdbCacheFreeSLastColItem); @@ -600,10 +607,7 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32 if (k == 0) { if (TARRAY_SIZE(pTableUidList) == 0) { void* px = taosArrayPush(pTableUidList, &uid); - if (px == NULL) { - code = terrno; - goto _end; - } + TSDB_CHECK_NULL(px, code, lino, _end, terrno); } else { taosArraySet(pTableUidList, 0, &uid); } @@ -613,6 +617,16 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32 singleTableLastTs = pColVal->rowKey.ts; } + if (p->colVal.value.type != pColVal->colVal.value.type) { + // check for type/cid mismatch + tsdbError("last cache type mismatch, uid:%" PRIu64 + ", schema-type:%d, slotId:%d, cache-type:%d, cache-col:%d", + uid, p->colVal.value.type, slotIds[k], pColVal->colVal.value.type, pColVal->colVal.cid); + taosArrayClearEx(pRow, tsdbCacheFreeSLastColItem); + code = TSDB_CODE_INVALID_PARA; + goto _end; + } + if (!IS_VAR_DATA_TYPE(pColVal->colVal.value.type)) { p->colVal = pColVal->colVal; } else { @@ -644,9 +658,7 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32 if (hasRes) { code = saveOneRow(pLastCols, pResBlock, pr, slotIds, dstSlotIds, pRes, pr->idstr); - if (code) { - goto _end; - } + TSDB_CHECK_CODE(code, lino, _end); } taosArrayDestroyEx(pLastCols, tsdbCacheFreeSLastColItem); @@ -656,11 +668,10 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32 tb_uid_t uid = pTableList[i].uid; if ((code = tsdbCacheGetBatch(pr->pTsdb, uid, pRow, pr, ltype)) != 0) { - if (code == -1) {// fix the invalid return code + if (code == -1) { // fix the invalid return code code = 0; - } else if (code != 0) { - goto _end; } + TSDB_CHECK_CODE(code, lino, _end); } if (TARRAY_SIZE(pRow) <= 0 || COL_VAL_IS_NONE(&((SLastCol*)TARRAY_DATA(pRow))[0].colVal)) { @@ -669,17 +680,12 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32 } code = saveOneRow(pRow, pResBlock, pr, slotIds, dstSlotIds, pRes, pr->idstr); - if (code) { - goto _end; - } + TSDB_CHECK_CODE(code, lino, _end); taosArrayClearEx(pRow, tsdbCacheFreeSLastColItem); void* px = taosArrayPush(pTableUidList, &uid); - if (px == NULL) { - code = terrno; - goto _end; - } + TSDB_CHECK_NULL(px, code, lino, _end, terrno); ++pr->tableIndex; if (pResBlock->info.rows >= pResBlock->info.capacity) { @@ -692,6 +698,7 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32 } } else { code = TSDB_CODE_INVALID_PARA; + TSDB_CHECK_CODE(code, lino, _end); } _end: @@ -713,5 +720,8 @@ _end: taosMemoryFree(pRes); taosArrayDestroy(pRow); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } diff --git a/source/dnode/vnode/src/tsdb/tsdbRead2.c b/source/dnode/vnode/src/tsdb/tsdbRead2.c index c4971e27cf..f30f7eb310 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead2.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead2.c @@ -24,13 +24,14 @@ #define ASCENDING_TRAVERSE(o) (o == TSDB_ORDER_ASC) #define getCurrentKeyInSttBlock(_r) (&((_r)->currentKey)) -#define tColRowGetKeyDeepCopy(_pBlock, _irow, _slotId, _pKey) \ - do { \ - (_pKey)->ts = (_pBlock)->aTSKEY[(_irow)]; \ - (_pKey)->numOfPKs = 0; \ - if ((_slotId) != -1) { \ - tColRowGetPriamyKeyDeepCopy(_pBlock, _irow, _slotId, _pKey); \ - } \ +#define tColRowGetKeyDeepCopy(_pBlock, _irow, _slotId, _pKey) \ + do { \ + (_pKey)->ts = (_pBlock)->aTSKEY[(_irow)]; \ + (_pKey)->numOfPKs = 0; \ + if ((_slotId) != -1) { \ + code = tColRowGetPriamyKeyDeepCopy(_pBlock, _irow, _slotId, _pKey); \ + TSDB_CHECK_CODE(code, lino, _end); \ + } \ } while (0) #define outOfTimeWindow(_ts, _window) (((_ts) > (_window)->ekey) || ((_ts) < (_window)->skey)) @@ -45,23 +46,23 @@ typedef struct { bool moreThanCapcity; } SDataBlockToLoadInfo; -static int32_t getCurrentBlockInfo(SDataBlockIter* pBlockIter, SFileDataBlockInfo** pInfo, const char* idStr); -static int32_t buildDataBlockFromBufImpl(STableBlockScanInfo* pBlockScanInfo, int64_t endKey, int32_t capacity, - STsdbReader* pReader); -static void getValidMemRow(SIterInfo* pIter, const SArray* pDelList, STsdbReader* pReader, TSDBROW** pRes); -static int32_t doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pScanInfo, SRowKey* pKey, - STsdbReader* pReader); -static int32_t doMergeRowsInSttBlock(SSttBlockReader* pSttBlockReader, STableBlockScanInfo* pScanInfo, - SRowMerger* pMerger, int32_t pkSrcSlot, SVersionRange* pVerRange, const char* id); -static int32_t doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, SRowKey* pCurKey, SArray* pDelList, - STsdbReader* pReader); -static int32_t doAppendRowFromTSRow(SSDataBlock* pBlock, STsdbReader* pReader, SRow* pTSRow, - STableBlockScanInfo* pScanInfo); -static int32_t doAppendRowFromFileBlock(SSDataBlock* pResBlock, STsdbReader* pReader, SBlockData* pBlockData, - int32_t rowIndex); -static void setComposedBlockFlag(STsdbReader* pReader, bool composed); -static bool hasBeenDropped(const SArray* pDelList, int32_t* index, int64_t key, int64_t ver, int32_t order, - SVersionRange* pVerRange, bool hasPk); +static int32_t getCurrentBlockInfo(SDataBlockIter* pBlockIter, SFileDataBlockInfo** pInfo, const char* idStr); +static int32_t buildDataBlockFromBufImpl(STableBlockScanInfo* pBlockScanInfo, int64_t endKey, int32_t capacity, + STsdbReader* pReader); +static int32_t getValidMemRow(SIterInfo* pIter, const SArray* pDelList, STsdbReader* pReader, TSDBROW** pRes); +static int32_t doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pScanInfo, SRowKey* pKey, + STsdbReader* pReader); +static int32_t doMergeRowsInSttBlock(SSttBlockReader* pSttBlockReader, STableBlockScanInfo* pScanInfo, + SRowMerger* pMerger, int32_t pkSrcSlot, SVersionRange* pVerRange, const char* id); +static int32_t doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, SRowKey* pCurKey, SArray* pDelList, + STsdbReader* pReader); +static int32_t doAppendRowFromTSRow(SSDataBlock* pBlock, STsdbReader* pReader, SRow* pTSRow, + STableBlockScanInfo* pScanInfo); +static int32_t doAppendRowFromFileBlock(SSDataBlock* pResBlock, STsdbReader* pReader, SBlockData* pBlockData, + int32_t rowIndex); +static void setComposedBlockFlag(STsdbReader* pReader, bool composed); +static int32_t hasBeenDropped(const SArray* pDelList, int32_t* index, int64_t key, int64_t ver, int32_t order, + SVersionRange* pVerRange, bool hasPk, bool* dropped); static int32_t doMergeMemTableMultiRows(TSDBROW* pRow, SRowKey* pKey, uint64_t uid, SIterInfo* pIter, SArray* pDelList, TSDBROW* pResRow, STsdbReader* pReader, bool* freeTSRow); @@ -77,10 +78,10 @@ static void getTsdbByRetentions(SVnode* pVnode, SQueryTableDataCond* pCond, SRet int8_t* pLevel, STsdb** pTsdb); static SVersionRange getQueryVerRange(SVnode* pVnode, SQueryTableDataCond* pCond, int8_t level); static int32_t doBuildDataBlock(STsdbReader* pReader); -static TSDBKEY getCurrentKeyInBuf(STableBlockScanInfo* pScanInfo, STsdbReader* pReader); +static int32_t getCurrentKeyInBuf(STableBlockScanInfo* pScanInfo, STsdbReader* pReader, TSDBKEY* key); static bool hasDataInFileBlock(const SBlockData* pBlockData, const SFileBlockDumpInfo* pDumpInfo); static bool hasDataInSttBlock(STableBlockScanInfo* pInfo); -static void initBlockDumpInfo(STsdbReader* pReader, SDataBlockIter* pBlockIter); +static int32_t initBlockDumpInfo(STsdbReader* pReader, SDataBlockIter* pBlockIter); static int32_t getInitialDelIndex(const SArray* pDelSkyline, int32_t order); static int32_t resetTableListIndex(SReaderStatus* pStatus, const char* id); static void getMemTableTimeRange(STsdbReader* pReader, int64_t* pMaxKey, int64_t* pMinKey); @@ -111,9 +112,17 @@ FORCE_INLINE int32_t pkCompEx(SRowKey* p1, SRowKey* p2) { } } -static void tColRowGetPriamyKeyDeepCopy(SBlockData* pBlock, int32_t irow, int32_t slotId, SRowKey* pKey) { - SColData* pColData = &pBlock->aColData[slotId]; +static int32_t tColRowGetPriamyKeyDeepCopy(SBlockData* pBlock, int32_t irow, int32_t slotId, SRowKey* pKey) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SColData* pColData = NULL; SColVal cv; + + TSDB_CHECK_CONDITION((pBlock != NULL) && (pBlock->aColData != NULL), code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pKey, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pColData = &pBlock->aColData[slotId]; + tColDataGetValue(pColData, irow, &cv); pKey->numOfPKs = 1; @@ -123,8 +132,14 @@ static void tColRowGetPriamyKeyDeepCopy(SBlockData* pBlock, int32_t irow, int32_ pKey->pks[0].val = cv.value.val; } else { pKey->pks[0].nData = cv.value.nData; - (void)memcpy(pKey->pks[0].pData, cv.value.pData, cv.value.nData); + TAOS_MEMCPY(pKey->pks[0].pData, cv.value.pData, cv.value.nData); } + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } // for test purpose, todo remove it @@ -135,10 +150,20 @@ static int32_t tGetPrimaryKeyIndex(uint8_t* p, SPrimaryKeyIndex* index) { return n; } -static void tRowGetPrimaryKeyDeepCopy(SRow* pRow, SRowKey* pKey) { +static int32_t tRowGetPrimaryKeyDeepCopy(SRow* pRow, SRowKey* pKey) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; SPrimaryKeyIndex indices[TD_MAX_PK_COLS]; + uint8_t* data = NULL; + int32_t len = 0; - uint8_t* data = pRow->data; + TSDB_CHECK_NULL(pRow, code, lino, _end, TSDB_CODE_INVALID_PARA); + if (pRow->numOfPKs > 0) { + TSDB_CHECK_NULL(pRow->data, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pKey, code, lino, _end, TSDB_CODE_INVALID_PARA); + } + + data = pRow->data; for (int32_t i = 0; i < pRow->numOfPKs; i++) { data += tGetPrimaryKeyIndex(data, &indices[i]); } @@ -154,16 +179,29 @@ static void tRowGetPrimaryKeyDeepCopy(SRow* pRow, SRowKey* pKey) { if (IS_VAR_DATA_TYPE(indices[i].type)) { tdata += tGetU32v(tdata, &pKey->pks[i].nData); - (void)memcpy(pKey->pks[i].pData, tdata, pKey->pks[i].nData); + TAOS_MEMCPY(pKey->pks[i].pData, tdata, pKey->pks[i].nData); } else { - (void)memcpy(&pKey->pks[i].val, data + indices[i].offset, tDataTypes[pKey->pks[i].type].bytes); + TAOS_MEMCPY(&pKey->pks[i].val, data + indices[i].offset, tDataTypes[pKey->pks[i].type].bytes); } } + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static int32_t setColumnIdSlotList(SBlockLoadSuppInfo* pSupInfo, SColumnInfo* pCols, const int32_t* pSlotIdList, int32_t numOfCols) { - bool initSucc = true; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + + TSDB_CHECK_NULL(pSupInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + if (numOfCols > 0) { + TSDB_CHECK_NULL(pSlotIdList, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pCols, code, lino, _end, TSDB_CODE_INVALID_PARA); + } pSupInfo->pk.pk = 0; pSupInfo->numOfPks = 0; @@ -173,10 +211,7 @@ static int32_t setColumnIdSlotList(SBlockLoadSuppInfo* pSupInfo, SColumnInfo* pC pSupInfo->numOfCols = numOfCols; pSupInfo->colId = taosMemoryMalloc(numOfCols * (sizeof(int16_t) * 2 + POINTER_BYTES)); - if (pSupInfo->colId == NULL) { - taosMemoryFree(pSupInfo->colId); - return terrno; - } + TSDB_CHECK_NULL(pSupInfo->colId, code, lino, _end, terrno); pSupInfo->slotId = (int16_t*)((char*)pSupInfo->colId + (sizeof(int16_t) * numOfCols)); pSupInfo->buildBuf = (char**)((char*)pSupInfo->slotId + (sizeof(int16_t) * numOfCols)); @@ -184,36 +219,47 @@ static int32_t setColumnIdSlotList(SBlockLoadSuppInfo* pSupInfo, SColumnInfo* pC pSupInfo->colId[i] = pCols[i].colId; pSupInfo->slotId[i] = pSlotIdList[i]; - if (IS_VAR_DATA_TYPE(pCols[i].type)) { - pSupInfo->buildBuf[i] = taosMemoryMalloc(pCols[i].bytes); - if (pSupInfo->buildBuf[i] == NULL) { - tsdbError("failed to prepare memory for set columnId slot list, size:%d, code:out of memory", pCols[i].bytes); - initSucc = false; - } - } else { - pSupInfo->buildBuf[i] = NULL; - } - if (pCols[i].pk) { pSupInfo->pk = pCols[i]; pSupInfo->pkSrcSlot = i - 1; pSupInfo->pkDstSlot = pSlotIdList[i]; pSupInfo->numOfPks += 1; } + + if (IS_VAR_DATA_TYPE(pCols[i].type)) { + pSupInfo->buildBuf[i] = taosMemoryMalloc(pCols[i].bytes); + if (pSupInfo->buildBuf[i] == NULL) { + tsdbError("failed to prepare memory for set columnId slot list, size:%d, code: %s", pCols[i].bytes, + tstrerror(terrno)); + } + TSDB_CHECK_NULL(pSupInfo->buildBuf[i], code, lino, _end, terrno); + } else { + pSupInfo->buildBuf[i] = NULL; + } } - return (initSucc)? TSDB_CODE_SUCCESS:TSDB_CODE_OUT_OF_MEMORY; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static int32_t updateBlockSMAInfo(STSchema* pSchema, SBlockLoadSuppInfo* pSupInfo) { - int32_t i = 0, j = 0; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + int32_t i = 0, j = 0; + STColumn* pTCol = NULL; + + TSDB_CHECK_NULL(pSchema, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pSupInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); while (i < pSchema->numOfCols && j < pSupInfo->numOfCols) { - STColumn* pTCol = &pSchema->columns[i]; + pTCol = &pSchema->columns[i]; if (pTCol->colId == pSupInfo->colId[j]) { if (!IS_BSMA_ON(pTCol) && (PRIMARYKEY_TIMESTAMP_COL_ID != pTCol->colId)) { pSupInfo->smaValid = false; - return TSDB_CODE_SUCCESS; + goto _end; } i += 1; @@ -221,33 +267,62 @@ static int32_t updateBlockSMAInfo(STSchema* pSchema, SBlockLoadSuppInfo* pSupInf } else if (pTCol->colId < pSupInfo->colId[j]) { // do nothing i += 1; } else { - return TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER; + code = TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER; + TSDB_CHECK_CODE(code, lino, _end); } } - return TSDB_CODE_SUCCESS; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } -static bool isEmptyQueryTimeWindow(STimeWindow* pWindow) { return pWindow->skey > pWindow->ekey; } +static bool isEmptyQueryTimeWindow(STimeWindow* pWindow) { + return (pWindow == NULL) || (pWindow->skey > pWindow->ekey); +} // Update the query time window according to the data time to live(TTL) information, in order to avoid to return // the expired data to client, even it is queried already. -static STimeWindow updateQueryTimeWindow(STsdb* pTsdb, STimeWindow* pWindow) { - int64_t earlyTs = tsdbGetEarliestTs(pTsdb); - STimeWindow win = *pWindow; - if (win.skey < earlyTs) { - win.skey = earlyTs; +static int32_t updateQueryTimeWindow(STsdb* pTsdb, STimeWindow* pWindow, STimeWindow* out) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + int64_t earlyTs = 0; + + TSDB_CHECK_NULL(pTsdb, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pWindow, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(out, code, lino, _end, TSDB_CODE_INVALID_PARA); + + earlyTs = tsdbGetEarliestTs(pTsdb); + *out = *pWindow; + if (out->skey < earlyTs) { + out->skey = earlyTs; } - return win; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } // init file iterator static int32_t initFilesetIterator(SFilesetIter* pIter, TFileSetArray* pFileSetArray, STsdbReader* pReader) { - SBlockLoadSuppInfo* pInfo = &pReader->suppInfo; - size_t numOfFileset = TARRAY2_SIZE(pFileSetArray); - bool asc = ASCENDING_TRAVERSE(pReader->info.order); int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SBlockLoadSuppInfo* pInfo = NULL; + SSttBlockReader* pSttReader = NULL; + size_t numOfFileset = 0; + bool asc = false; + + TSDB_CHECK_NULL(pIter, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pFileSetArray, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pInfo = &pReader->suppInfo; + numOfFileset = TARRAY2_SIZE(pFileSetArray); + asc = ASCENDING_TRAVERSE(pReader->info.order); pIter->index = asc ? -1 : numOfFileset; pIter->order = pReader->info.order; @@ -258,11 +333,11 @@ static int32_t initFilesetIterator(SFilesetIter* pIter, TFileSetArray* pFileSetA pIter->pSttBlockReader = taosMemoryCalloc(1, sizeof(struct SSttBlockReader)); if (pIter->pSttBlockReader == NULL) { tsdbError("failed to prepare the last block iterator, since:%s %s", tstrerror(terrno), pReader->idStr); - return terrno; } + TSDB_CHECK_NULL(pIter->pSttBlockReader, code, lino, _end, terrno); } - SSttBlockReader* pSttReader = pIter->pSttBlockReader; + pSttReader = pIter->pSttBlockReader; pSttReader->order = pReader->info.order; pSttReader->window = pReader->info.window; pSttReader->verRange = pReader->info.verRange; @@ -276,31 +351,46 @@ static int32_t initFilesetIterator(SFilesetIter* pIter, TFileSetArray* pFileSetA } else { tsdbDebug("init fileset iterator, total files:%d %s", pIter->numOfFiles, pReader->idStr); } + TSDB_CHECK_CODE(code, lino, _end); +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } static int32_t filesetIteratorNext(SFilesetIter* pIter, STsdbReader* pReader, bool* hasNext) { - bool asc = ASCENDING_TRAVERSE(pIter->order); - int32_t step = asc ? 1 : -1; - int32_t code = 0; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + bool asc = false; + int32_t step = 0; + SReadCostSummary* pCost = NULL; + STFileObj** pFileObj = NULL; + + TSDB_CHECK_NULL(pIter, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(hasNext, code, lino, _end, TSDB_CODE_INVALID_PARA); + + asc = ASCENDING_TRAVERSE(pIter->order); + step = asc ? 1 : -1; + *hasNext = false; pIter->index += step; if ((asc && pIter->index >= pIter->numOfFiles) || ((!asc) && pIter->index < 0)) { *hasNext = false; - return TSDB_CODE_SUCCESS; + goto _end; } - SReadCostSummary* pCost = &pReader->cost; + pCost = &pReader->cost; + TSDB_CHECK_NULL(pIter->pSttBlockReader, code, lino, _end, TSDB_CODE_INVALID_PARA); pIter->pSttBlockReader->uid = 0; tMergeTreeClose(&pIter->pSttBlockReader->mergeTree); destroySttBlockReader(pReader->status.pLDataIterArray, &pCost->sttCost); pReader->status.pLDataIterArray = taosArrayInit(4, POINTER_BYTES); - if (pReader->status.pLDataIterArray == NULL) { - return terrno; - } + TSDB_CHECK_NULL(pReader->status.pLDataIterArray, code, lino, _end, terrno); // check file the time range of coverage STimeWindow win = {0}; @@ -310,9 +400,10 @@ static int32_t filesetIteratorNext(SFilesetIter* pIter, STsdbReader* pReader, bo tsdbDataFileReaderClose(&pReader->pFileReader); } + TSDB_CHECK_CONDITION(pIter->index < pIter->pFilesetList->size, code, lino, _end, TSDB_CODE_INTERNAL_ERROR); pReader->status.pCurrentFileset = pIter->pFilesetList->data[pIter->index]; - STFileObj** pFileObj = pReader->status.pCurrentFileset->farr; + pFileObj = pReader->status.pCurrentFileset->farr; if (pFileObj[0] != NULL || pFileObj[3] != NULL) { SDataFileReaderConfig conf = {.tsdb = pReader->pTsdb, .szPage = pReader->pTsdb->pVnode->config.tsdbPageSize}; @@ -339,9 +430,7 @@ static int32_t filesetIteratorNext(SFilesetIter* pIter, STsdbReader* pReader, bo } code = tsdbDataFileReaderOpen(filesName, &conf, &pReader->pFileReader); - if (code != TSDB_CODE_SUCCESS) { - goto _err; - } + TSDB_CHECK_CODE(code, lino, _end); pReader->cost.headFileLoad += 1; } @@ -354,14 +443,14 @@ static int32_t filesetIteratorNext(SFilesetIter* pIter, STsdbReader* pReader, bo tsdbDebug("%p remain files are not qualified for qrange:%" PRId64 "-%" PRId64 ", ignore, %s", pReader, pReader->info.window.skey, pReader->info.window.ekey, pReader->idStr); *hasNext = false; - return TSDB_CODE_SUCCESS; + break; } if ((asc && (win.ekey < pReader->info.window.skey)) || ((!asc) && (win.skey > pReader->info.window.ekey))) { pIter->index += step; if ((asc && pIter->index >= pIter->numOfFiles) || ((!asc) && pIter->index < 0)) { *hasNext = false; - return TSDB_CODE_SUCCESS; + break; } continue; } @@ -370,17 +459,26 @@ static int32_t filesetIteratorNext(SFilesetIter* pIter, STsdbReader* pReader, bo pReader->info.window.ekey, pReader->idStr); *hasNext = true; - return TSDB_CODE_SUCCESS; + break; } -_err: - *hasNext = false; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } -bool shouldFreePkBuf(SBlockLoadSuppInfo* pSupp) { return (pSupp->numOfPks > 0) && IS_VAR_DATA_TYPE(pSupp->pk.type); } +bool shouldFreePkBuf(SBlockLoadSuppInfo* pSupp) { + return (pSupp != NULL) && (pSupp->numOfPks > 0) && IS_VAR_DATA_TYPE(pSupp->pk.type); +} int32_t resetDataBlockIterator(SDataBlockIter* pIter, int32_t order, bool needFree, const char* id) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + + TSDB_CHECK_NULL(pIter, code, lino, _end, TSDB_CODE_INVALID_PARA); + pIter->order = order; pIter->index = -1; pIter->numOfBlocks = 0; @@ -389,100 +487,165 @@ int32_t resetDataBlockIterator(SDataBlockIter* pIter, int32_t order, bool needFr pIter->blockList = taosArrayInit(4, sizeof(SFileDataBlockInfo)); if (pIter->blockList == NULL) { tsdbError("%s failed to reset block iter, func:%s at line:%d code:%s", id, __func__, __LINE__, tstrerror(terrno)); - return terrno; } + TSDB_CHECK_NULL(pIter->blockList, code, lino, _end, terrno); } else { clearDataBlockIterator(pIter, needFree); } - return TSDB_CODE_SUCCESS; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static void initReaderStatus(SReaderStatus* pStatus) { + if (pStatus == NULL) { + return; + } pStatus->pTableIter = NULL; pStatus->loadFromFile = true; } static int32_t createResBlock(SQueryTableDataCond* pCond, int32_t capacity, SSDataBlock** pResBlock) { - QRY_PARAM_CHECK(pResBlock); - + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; SSDataBlock* pBlock = NULL; - int32_t code = createDataBlock(&pBlock); - if (code != 0) { - return code; - } + + TSDB_CHECK_NULL(pCond, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_CONDITION(capacity >= 0, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pResBlock, code, lino, _end, TSDB_CODE_INVALID_PARA); + + code = createDataBlock(&pBlock); + TSDB_CHECK_CODE(code, lino, _end); for (int32_t i = 0; i < pCond->numOfCols; ++i) { SColumnInfoData colInfo = {0}; colInfo.info = pCond->colList[i]; code = blockDataAppendColInfo(pBlock, &colInfo); - if (code != TSDB_CODE_SUCCESS) { - taosMemoryFree(pBlock); - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } code = blockDataEnsureCapacity(pBlock, capacity); - if (code != TSDB_CODE_SUCCESS) { - taosMemoryFree(pBlock); - } + TSDB_CHECK_CODE(code, lino, _end); *pResBlock = pBlock; + pBlock = NULL; + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + if (pBlock) { + taosArrayDestroy(pBlock->pDataBlock); + taosMemoryFreeClear(pBlock); + } return code; } static int32_t tsdbInitReaderLock(STsdbReader* pReader) { - int32_t code = taosThreadMutexInit(&pReader->readerMutex, NULL); - tsdbTrace("tsdb/read: %p, post-init read mutex: %p, code: %d", pReader, &pReader->readerMutex, code); + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + code = taosThreadMutexInit(&pReader->readerMutex, NULL); + tsdbTrace("tsdb/read: %p, post-init read mutex: %p, code: %d", pReader, &pReader->readerMutex, code); + TSDB_CHECK_CODE(code, lino, _end); + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } static int32_t tsdbUninitReaderLock(STsdbReader* pReader) { int32_t code = TSDB_CODE_SUCCESS; - tsdbTrace("tsdb/read: %p, pre-uninit read mutex: %p, code: %d", pReader, &pReader->readerMutex, code); + int32_t lino = 0; + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + tsdbTrace("tsdb/read: %p, pre-uninit read mutex: %p, code: %d", pReader, &pReader->readerMutex, code); code = taosThreadMutexDestroy(&pReader->readerMutex); tsdbTrace("tsdb/read: %p, post-uninit read mutex: %p, code: %d", pReader, &pReader->readerMutex, code); + TSDB_CHECK_CODE(code, lino, _end); +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } static int32_t tsdbAcquireReader(STsdbReader* pReader) { - int32_t code = -1; - tsdbTrace("tsdb/read: %s, pre-take read mutex: %p, code: %d", pReader->idStr, &pReader->readerMutex, code); + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + TSDB_CHECK_CONDITION((pReader != NULL) && (pReader->idStr != NULL), code, lino, _end, TSDB_CODE_INVALID_PARA); + + tsdbTrace("tsdb/read: %s, pre-take read mutex: %p, code: %d", pReader->idStr, &pReader->readerMutex, code); code = taosThreadMutexLock(&pReader->readerMutex); - if (code != 0) { + if (code != TSDB_CODE_SUCCESS) { tsdbError("tsdb/read:%p, failed to lock reader mutex, code:%s", pReader->idStr, tstrerror(code)); } else { tsdbTrace("tsdb/read: %s, post-take read mutex: %p, code: %d", pReader->idStr, &pReader->readerMutex, code); } + TSDB_CHECK_CODE(code, lino, _end); +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } static int32_t tsdbTryAcquireReader(STsdbReader* pReader) { - int32_t code = taosThreadMutexTryLock(&pReader->readerMutex); + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + code = taosThreadMutexTryLock(&pReader->readerMutex); if (code != TSDB_CODE_SUCCESS) { tsdbError("tsdb/read: %p, post-trytake read mutex: %p, code: %d", pReader, &pReader->readerMutex, code); } else { tsdbTrace("tsdb/read: %p, post-trytask read mutex: %p", pReader, &pReader->readerMutex); } + TSDB_CHECK_CODE(code, lino, _end); + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } static int32_t tsdbReleaseReader(STsdbReader* pReader) { - int32_t code = taosThreadMutexUnlock(&pReader->readerMutex); + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + code = taosThreadMutexUnlock(&pReader->readerMutex); if (code != TSDB_CODE_SUCCESS) { tsdbError("tsdb/read: %p post-untake read mutex:%p failed, code:%d", pReader, &pReader->readerMutex, code); } else { tsdbTrace("tsdb/read: %p, post-untake read mutex: %p", pReader, &pReader->readerMutex); } + TSDB_CHECK_CODE(code, lino, _end); + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } void tsdbReleaseDataBlock2(STsdbReader* pReader) { + if (pReader == NULL) return; + SReaderStatus* pStatus = &pReader->status; if (!pStatus->composedDataBlock) { (void) tsdbReleaseReader(pReader); @@ -491,35 +654,34 @@ void tsdbReleaseDataBlock2(STsdbReader* pReader) { static int32_t initResBlockInfo(SResultBlockInfo* pResBlockInfo, int64_t capacity, SSDataBlock* pResBlock, SQueryTableDataCond* pCond, SBlockLoadSuppInfo* pSup) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SSDataBlock* p = NULL; + + TSDB_CHECK_NULL(pResBlockInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_CONDITION((pResBlockInfo->pResBlock != NULL) || (pSup != NULL), code, lino, _end, TSDB_CODE_INVALID_PARA); + pResBlockInfo->capacity = capacity; pResBlockInfo->pResBlock = pResBlock; - int32_t code = 0; if (pResBlockInfo->pResBlock == NULL) { pResBlockInfo->freeBlock = true; pResBlockInfo->pResBlock = NULL; code = createResBlock(pCond, pResBlockInfo->capacity, &pResBlockInfo->pResBlock); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if (pSup->numOfPks > 0) { - SSDataBlock* p = pResBlockInfo->pResBlock; + p = pResBlockInfo->pResBlock; p->info.pks[0].type = pSup->pk.type; p->info.pks[1].type = pSup->pk.type; if (IS_VAR_DATA_TYPE(pSup->pk.type)) { p->info.pks[0].pData = taosMemoryCalloc(1, pSup->pk.bytes); - if (p->info.pks[0].pData == NULL) { - return terrno; - } + TSDB_CHECK_NULL(p->info.pks[0].pData, code, lino, _end, terrno); p->info.pks[1].pData = taosMemoryCalloc(1, pSup->pk.bytes); - if (p->info.pks[1].pData == NULL) { - taosMemoryFreeClear(p->info.pks[0].pData); - return terrno; - } + TSDB_CHECK_NULL(p->info.pks[0].pData, code, lino, _end, terrno); p->info.pks[0].nData = pSup->pk.bytes; p->info.pks[1].nData = pSup->pk.bytes; @@ -529,18 +691,28 @@ static int32_t initResBlockInfo(SResultBlockInfo* pResBlockInfo, int64_t capacit pResBlockInfo->freeBlock = false; } +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } static int32_t tsdbReaderCreate(SVnode* pVnode, SQueryTableDataCond* pCond, void** ppReader, int32_t capacity, SSDataBlock* pResBlock, const char* idstr) { - int32_t code = 0; - int8_t level = 0; - STsdbReader* pReader = (STsdbReader*)taosMemoryCalloc(1, sizeof(*pReader)); - if (pReader == NULL) { - code = terrno; - goto _end; - } + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + int8_t level = 0; + STsdbReader* pReader = NULL; + SBlockLoadSuppInfo* pSup = NULL; + + TSDB_CHECK_NULL(pVnode, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pCond, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(ppReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + *ppReader = NULL; + pReader = (STsdbReader*)taosMemoryCalloc(1, sizeof(*pReader)); + TSDB_CHECK_NULL(pReader, code, lino, _end, terrno); if (VND_IS_TSMA(pVnode)) { tsdbDebug("vgId:%d, tsma is selected to query, %s", TD_VID(pVnode), idstr); @@ -552,13 +724,14 @@ static int32_t tsdbReaderCreate(SVnode* pVnode, SQueryTableDataCond* pCond, void pReader->info.suid = pCond->suid; pReader->info.order = pCond->order; pReader->info.verRange = getQueryVerRange(pVnode, pCond, level); - pReader->info.window = updateQueryTimeWindow(pReader->pTsdb, &pCond->twindows); + code = updateQueryTimeWindow(pReader->pTsdb, &pCond->twindows, &pReader->info.window); + TSDB_CHECK_CODE(code, lino, _end); - pReader->idStr = (idstr != NULL) ? taosStrdup(idstr) : NULL; - if (idstr != NULL && pReader->idStr == NULL) { - code = terrno; - goto _end; + if (idstr == NULL) { + idstr = ""; } + pReader->idStr = taosStrdup(idstr); + TSDB_CHECK_NULL(pReader->idStr, code, lino, _end, terrno); pReader->type = pCond->type; pReader->bFilesetDelimited = false; @@ -566,81 +739,80 @@ static int32_t tsdbReaderCreate(SVnode* pVnode, SQueryTableDataCond* pCond, void if (pCond->numOfCols <= 0) { tsdbError("vgId:%d, invalid column number %d in query cond, %s", TD_VID(pVnode), pCond->numOfCols, idstr); - code = TSDB_CODE_INVALID_PARA; - goto _end; + TSDB_CHECK_CONDITION(pCond->numOfCols > 0, code, lino, _end, TSDB_CODE_INVALID_PARA); } // allocate buffer in order to load data blocks from file - SBlockLoadSuppInfo* pSup = &pReader->suppInfo; + pSup = &pReader->suppInfo; pSup->tsColAgg.colId = PRIMARYKEY_TIMESTAMP_COL_ID; code = setColumnIdSlotList(pSup, pCond->colList, pCond->pSlotList, pCond->numOfCols); - if (code != TSDB_CODE_SUCCESS) { - goto _end; - } + TSDB_CHECK_CODE(code, lino, _end); code = initResBlockInfo(&pReader->resBlockInfo, capacity, pResBlock, pCond, pSup); - if (code != TSDB_CODE_SUCCESS) { - goto _end; - } + TSDB_CHECK_CODE(code, lino, _end); code = tBlockDataCreate(&pReader->status.fileBlockData); - if (code != TSDB_CODE_SUCCESS) { - goto _end; - } + TSDB_CHECK_CODE(code, lino, _end); if (pReader->suppInfo.colId[0] != PRIMARYKEY_TIMESTAMP_COL_ID) { tsdbError("the first column isn't primary timestamp, %d, %s", pReader->suppInfo.colId[0], pReader->idStr); - code = TSDB_CODE_INVALID_PARA; - goto _end; + TSDB_CHECK_CONDITION(pReader->suppInfo.colId[0] == PRIMARYKEY_TIMESTAMP_COL_ID, code, lino, _end, + TSDB_CODE_INVALID_PARA); } pReader->status.pPrimaryTsCol = taosArrayGet(pReader->resBlockInfo.pResBlock->pDataBlock, pSup->slotId[0]); - if (pReader->status.pPrimaryTsCol == NULL) { - code = terrno; - goto _end; - } + TSDB_CHECK_NULL(pReader->status.pPrimaryTsCol, code, lino, _end, terrno); int32_t type = pReader->status.pPrimaryTsCol->info.type; if (type != TSDB_DATA_TYPE_TIMESTAMP) { tsdbError("the first column isn't primary timestamp in result block, actual: %s, %s", tDataTypes[type].name, pReader->idStr); - code = TSDB_CODE_INVALID_PARA; - goto _end; + TSDB_CHECK_CONDITION(type == TSDB_DATA_TYPE_TIMESTAMP, code, lino, _end, TSDB_CODE_INVALID_PARA); } code = tsdbInitReaderLock(pReader); - if (code != TSDB_CODE_SUCCESS) { - goto _end; - } + TSDB_CHECK_CODE(code, lino, _end); code = tsem_init(&pReader->resumeAfterSuspend, 0, 0); - if (code != TSDB_CODE_SUCCESS) { - goto _end; - } + TSDB_CHECK_CODE(code, lino, _end); *ppReader = pReader; - return code; + pReader = NULL; _end: - tsdbReaderClose2(pReader); - *ppReader = NULL; + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + if (pReader) { + tsdbReaderClose2(pReader); + } return code; } static int32_t doLoadBlockIndex(STsdbReader* pReader, SDataFileReader* pFileReader, SArray* pIndexList) { - int64_t st = taosGetTimestampUs(); - int32_t numOfTables = tSimpleHashGetSize(pReader->status.pTableMap); - if (pFileReader == NULL) { - return TSDB_CODE_SUCCESS; - } - + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + int32_t st = 0; + int32_t et1 = 0; + int32_t et2 = 0; + int32_t numOfTables = 0; const TBrinBlkArray* pBlkArray = NULL; + STableUidList* pList = NULL; + SBrinBlk* pBrinBlk = NULL; - int32_t code = tsdbDataFileReadBrinBlk(pFileReader, &pBlkArray); - if (code != TSDB_CODE_SUCCESS) { - return code; + if (pFileReader == NULL) { + goto _end; } + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pIndexList, code, lino, _end, TSDB_CODE_INVALID_PARA); + + st = taosGetTimestampUs(); + numOfTables = tSimpleHashGetSize(pReader->status.pTableMap); + + code = tsdbDataFileReadBrinBlk(pFileReader, &pBlkArray); + TSDB_CHECK_CODE(code, lino, _end); + #if 0 LRUHandle* handle = NULL; @@ -659,10 +831,9 @@ static int32_t doLoadBlockIndex(STsdbReader* pReader, SDataFileReader* pFileRead #endif // todo binary search to the start position - int64_t et1 = taosGetTimestampUs(); + et1 = taosGetTimestampUs(); - SBrinBlk* pBrinBlk = NULL; - STableUidList* pList = &pReader->status.uidList; + pList = &pReader->status.uidList; int32_t i = 0; while (i < TARRAY2_SIZE(pBlkArray)) { @@ -676,10 +847,10 @@ static int32_t doLoadBlockIndex(STsdbReader* pReader, SDataFileReader* pFileRead break; } - if (!(pBrinBlk->minTbid.suid <= pReader->info.suid && pBrinBlk->maxTbid.suid >= pReader->info.suid)) { - tsdbError("tsdb failed at: %s %d", __func__, __LINE__); - return TSDB_CODE_INTERNAL_ERROR; - } + TSDB_CHECK_CONDITION( + (pBrinBlk->minTbid.suid <= pReader->info.suid) && (pBrinBlk->maxTbid.suid >= pReader->info.suid), code, lino, + _end, TSDB_CODE_INTERNAL_ERROR); + if (pBrinBlk->maxTbid.suid == pReader->info.suid && pBrinBlk->maxTbid.uid < pList->tableUidList[0]) { i += 1; continue; @@ -689,47 +860,55 @@ static int32_t doLoadBlockIndex(STsdbReader* pReader, SDataFileReader* pFileRead break; } - void* p1 = taosArrayPush(pIndexList, pBrinBlk); - if (p1 == NULL) { - return terrno; - } + const void* p1 = taosArrayPush(pIndexList, pBrinBlk); + TSDB_CHECK_NULL(p1, code, lino, _end, terrno); i += 1; } - int64_t et2 = taosGetTimestampUs(); + et2 = taosGetTimestampUs(); tsdbDebug("load block index for %d/%d tables completed, elapsed time:%.2f ms, set BrinBlk:%.2f ms, size:%.2f Kb %s", numOfTables, (int32_t)pBlkArray->size, (et1 - st) / 1000.0, (et2 - et1) / 1000.0, pBlkArray->size * sizeof(SBrinBlk) / 1024.0, pReader->idStr); pReader->cost.headFileLoadTime += (et1 - st) / 1000.0; -//_end: - // tsdbBICacheRelease(pFileReader->pTsdb->biCache, handle); +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } static int32_t loadFileBlockBrinInfo(STsdbReader* pReader, SArray* pIndexList, SBlockNumber* pBlockNum, SArray* pTableScanInfoList) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + int64_t st = 0; + bool asc = false; + STimeWindow w = {0}; + SBrinRecordIter iter = {0}; + int32_t numOfTables = 0; + SBrinRecord* pRecord = NULL; int32_t k = 0; size_t sizeInDisk = 0; - int64_t st = taosGetTimestampUs(); - bool asc = ASCENDING_TRAVERSE(pReader->info.order); - STimeWindow w = pReader->info.window; - SBrinRecord* pRecord = NULL; - int32_t numOfTables = tSimpleHashGetSize(pReader->status.pTableMap); - SBrinRecordIter iter = {0}; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pBlockNum, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pTableScanInfoList, code, lino, _end, TSDB_CODE_INVALID_PARA); + + st = taosGetTimestampUs(); + asc = ASCENDING_TRAVERSE(pReader->info.order); + w = pReader->info.window; + numOfTables = tSimpleHashGetSize(pReader->status.pTableMap); // clear info for the new file cleanupInfoForNextFileset(pReader->status.pTableMap); initBrinRecordIter(&iter, pReader->pFileReader, pIndexList); while (1) { - int32_t code = getNextBrinRecord(&iter, &pRecord); - if (code != TSDB_CODE_SUCCESS) { - clearBrinBlockIter(&iter); - return code; - } + code = getNextBrinRecord(&iter, &pRecord); + TSDB_CHECK_CODE(code, lino, _end); if (pRecord == NULL) { break; @@ -760,18 +939,12 @@ static int32_t loadFileBlockBrinInfo(STsdbReader* pReader, SArray* pIndexList, S continue; } - if (!(pRecord->suid == pReader->info.suid && uid == pRecord->uid)) { - tsdbError("tsdb failed at: %s:%d", __func__, __LINE__); - clearBrinBlockIter(&iter); - return TSDB_CODE_INTERNAL_ERROR; - } + TSDB_CHECK_CONDITION((pRecord->suid == pReader->info.suid) && (uid == pRecord->uid), code, lino, _end, + TSDB_CODE_INTERNAL_ERROR); STableBlockScanInfo* pScanInfo = NULL; code = getTableBlockScanInfo(pReader->status.pTableMap, uid, &pScanInfo, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - clearBrinBlockIter(&iter); - return code; - } + TSDB_CHECK_CODE(code, lino, _end); // here we should find the first timestamp that is greater than the lastProcKey // the window is an open interval NOW. @@ -813,31 +986,21 @@ static int32_t loadFileBlockBrinInfo(STsdbReader* pReader, SArray* pIndexList, S if (pScanInfo->pBlockList == NULL) { pScanInfo->pBlockList = taosArrayInit(4, sizeof(SFileDataBlockInfo)); - if (pScanInfo->pBlockList == NULL) { - clearBrinBlockIter(&iter); - return terrno; - } + TSDB_CHECK_NULL(pScanInfo->pBlockList, code, lino, _end, terrno); } if (pScanInfo->pBlockIdxList == NULL) { pScanInfo->pBlockIdxList = taosArrayInit(4, sizeof(STableDataBlockIdx)); - if (pScanInfo->pBlockIdxList == NULL) { - clearBrinBlockIter(&iter); - return terrno; - } + TSDB_CHECK_NULL(pScanInfo->pBlockIdxList, code, lino, _end, terrno); } SFileDataBlockInfo blockInfo = {.tbBlockIdx = TARRAY_SIZE(pScanInfo->pBlockList)}; code = recordToBlockInfo(&blockInfo, pRecord); - if (code != TSDB_CODE_SUCCESS) { - clearBrinBlockIter(&iter); - return code; - } - void* p1 = taosArrayPush(pScanInfo->pBlockList, &blockInfo); - if (p1 == NULL) { - clearBrinBlockIter(&iter); - return terrno; - } + TSDB_CHECK_CODE(code, lino, _end); + sizeInDisk += blockInfo.blockSize; + + const void* p1 = taosArrayPush(pScanInfo->pBlockList, &blockInfo); + TSDB_CHECK_NULL(p1, code, lino, _end, terrno); // todo: refactor to record the fileset skey/ekey if (pScanInfo->filesetWindow.skey > pRecord->firstKey.key.ts) { @@ -851,27 +1014,18 @@ static int32_t loadFileBlockBrinInfo(STsdbReader* pReader, SArray* pIndexList, S pBlockNum->numOfBlocks += 1; if (taosArrayGetSize(pTableScanInfoList) == 0) { p1 = taosArrayPush(pTableScanInfoList, &pScanInfo); + TSDB_CHECK_NULL(p1, code, lino, _end, terrno); } else { STableBlockScanInfo** p = taosArrayGetLast(pTableScanInfoList); - if (p == NULL) { - clearBrinBlockIter(&iter); - tsdbError("invalid param, empty in tablescanInfoList, %s", pReader->idStr); - return TSDB_CODE_INVALID_PARA; - } + TSDB_CHECK_NULL(p, code, lino, _end, TSDB_CODE_INVALID_PARA); if ((*p)->uid != uid) { p1 = taosArrayPush(pTableScanInfoList, &pScanInfo); + TSDB_CHECK_NULL(p1, code, lino, _end, terrno); } } - - if (p1 == NULL) { - clearBrinBlockIter(&iter); - return terrno; - } } - clearBrinBlockIter(&iter); - pBlockNum->numOfSttFiles = pReader->status.pCurrentFileset->lvlArr->size; int32_t total = pBlockNum->numOfSttFiles + pBlockNum->numOfBlocks; @@ -885,43 +1039,69 @@ static int32_t loadFileBlockBrinInfo(STsdbReader* pReader, SArray* pIndexList, S pReader->cost.numOfBlocks += total; pReader->cost.headFileLoadTime += el; - return TSDB_CODE_SUCCESS; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + clearBrinBlockIter(&iter); + return code; } static void setBlockAllDumped(SFileBlockDumpInfo* pDumpInfo, int64_t maxKey, int32_t order) { - pDumpInfo->allDumped = true; + if (pDumpInfo != NULL) { + pDumpInfo->allDumped = true; + } } -static void updateLastKeyInfo(SRowKey* pKey, SFileDataBlockInfo* pBlockInfo, SDataBlockInfo* pInfo, int32_t numOfPks, - bool asc) { +static int32_t updateLastKeyInfo(SRowKey* pKey, SFileDataBlockInfo* pBlockInfo, SDataBlockInfo* pInfo, int32_t numOfPks, + bool asc) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + + TSDB_CHECK_NULL(pKey, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + pKey->ts = asc ? pInfo->window.ekey : pInfo->window.skey; pKey->numOfPKs = numOfPks; if (pKey->numOfPKs <= 0) { - return; + goto _end; } + TSDB_CHECK_NULL(pBlockInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); if (IS_NUMERIC_TYPE(pKey->pks[0].type)) { pKey->pks[0].val = asc ? pBlockInfo->lastPk.val : pBlockInfo->firstPk.val; } else { uint8_t* p = asc ? pBlockInfo->lastPk.pData : pBlockInfo->firstPk.pData; pKey->pks[0].nData = asc ? varDataLen(pBlockInfo->lastPk.pData) : varDataLen(pBlockInfo->firstPk.pData); - (void)memcpy(pKey->pks[0].pData, p, pKey->pks[0].nData); + TAOS_MEMCPY(pKey->pks[0].pData, p, pKey->pks[0].nData); } + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static int32_t doCopyColVal(SColumnInfoData* pColInfoData, int32_t rowIndex, int32_t colIndex, SColVal* pColVal, SBlockLoadSuppInfo* pSup) { - int32_t code = 0; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + + TSDB_CHECK_NULL(pColInfoData, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pColVal, code, lino, _end, TSDB_CODE_INVALID_PARA); if (IS_VAR_DATA_TYPE(pColVal->value.type)) { if (!COL_VAL_IS_VALUE(pColVal)) { colDataSetNULL(pColInfoData, rowIndex); } else { + TSDB_CHECK_NULL(pSup, code, lino, _end, TSDB_CODE_INVALID_PARA); varDataSetLen(pSup->buildBuf[colIndex], pColVal->value.nData); if ((pColVal->value.nData + VARSTR_HEADER_SIZE) > pColInfoData->info.bytes) { tsdbWarn("column cid:%d actual data len %d is bigger than schema len %d", pColVal->cid, pColVal->value.nData, pColInfoData->info.bytes); - return TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER; + code = TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER; + TSDB_CHECK_CODE(code, lino, _end); } if (pColVal->value.nData > 0) { // pData may be null, if nData is 0 @@ -929,31 +1109,41 @@ static int32_t doCopyColVal(SColumnInfoData* pColInfoData, int32_t rowIndex, int } code = colDataSetVal(pColInfoData, rowIndex, pSup->buildBuf[colIndex], false); + TSDB_CHECK_CODE(code, lino, _end); } } else { code = colDataSetVal(pColInfoData, rowIndex, (const char*)&pColVal->value.val, !COL_VAL_IS_VALUE(pColVal)); + TSDB_CHECK_CODE(code, lino, _end); } +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } static int32_t getCurrentBlockInfo(SDataBlockIter* pBlockIter, SFileDataBlockInfo** pInfo, const char* id) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + + TSDB_CHECK_NULL(pBlockIter, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pBlockIter->blockList, code, lino, _end, TSDB_CODE_INVALID_PARA); + *pInfo = NULL; - if (pBlockIter->blockList == NULL) { - return TSDB_CODE_FAILED; - } - size_t num = TARRAY_SIZE(pBlockIter->blockList); - if (num == 0) { - if (num != pBlockIter->numOfBlocks) { - tsdbError("tsdb read failed at: %s:%d %s", __func__, __LINE__, id); - } - return TSDB_CODE_FAILED; - } + TSDB_CHECK_CONDITION(num != 0, code, lino, _end, TSDB_CODE_INVALID_PARA); *pInfo = taosArrayGet(pBlockIter->blockList, pBlockIter->index); - return (*pInfo) != NULL? TSDB_CODE_SUCCESS:TSDB_CODE_FAILED; + TSDB_CHECK_NULL(*pInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static int32_t doBinarySearchKey(const TSKEY* keyList, int num, int pos, TSKEY key, int order) { @@ -962,7 +1152,7 @@ static int32_t doBinarySearchKey(const TSKEY* keyList, int num, int pos, TSKEY k s = pos; // check - if (!(pos >= 0 && pos < num && num > 0)) { + if (!(keyList != NULL && pos >= 0 && pos < num && num > 0)) { return -1; } if (order == TSDB_ORDER_ASC) { @@ -1025,8 +1215,15 @@ static int32_t findFirstPos(const int64_t* pTsList, int32_t num, int32_t startPo static int32_t getEndPosInDataBlock(STsdbReader* pReader, SBlockData* pBlockData, SBrinRecord* pRecord, int32_t pos) { // NOTE: reverse the order to find the end position in data block + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; int32_t endPos = -1; - bool asc = ASCENDING_TRAVERSE(pReader->info.order); + bool asc = false; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pRecord, code, lino, _end, TSDB_CODE_INVALID_PARA); + + asc = ASCENDING_TRAVERSE(pReader->info.order); if (asc && pReader->info.window.ekey >= pRecord->lastKey.key.ts) { endPos = pRecord->numRow - 1; @@ -1036,7 +1233,7 @@ static int32_t getEndPosInDataBlock(STsdbReader* pReader, SBlockData* pBlockData int64_t key = asc ? pReader->info.window.ekey : pReader->info.window.skey; endPos = doBinarySearchKey(pBlockData->aTSKEY, pRecord->numRow, pos, key, pReader->info.order); if (endPos == -1) { - return endPos; + goto _end; } endPos = findFirstPos(pBlockData->aTSKEY, pRecord->numRow, endPos, asc); @@ -1063,16 +1260,28 @@ static int32_t getEndPosInDataBlock(STsdbReader* pReader, SBlockData* pBlockData endPos = i; } +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return endPos; } -static void copyPrimaryTsCol(const SBlockData* pBlockData, SFileBlockDumpInfo* pDumpInfo, SColumnInfoData* pColData, - int32_t dumpedRows, bool asc) { +static int32_t copyPrimaryTsCol(const SBlockData* pBlockData, SFileBlockDumpInfo* pDumpInfo, SColumnInfoData* pColData, + int32_t dumpedRows, bool asc) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + + TSDB_CHECK_CONDITION((pBlockData != NULL) && (pBlockData->aTSKEY != NULL), code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pDumpInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pColData, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_CONDITION(dumpedRows >= 0, code, lino, _end, TSDB_CODE_INVALID_PARA); + if (asc) { - (void)memcpy(pColData->pData, &pBlockData->aTSKEY[pDumpInfo->rowIndex], dumpedRows * sizeof(int64_t)); + TAOS_MEMCPY(pColData->pData, &pBlockData->aTSKEY[pDumpInfo->rowIndex], dumpedRows * sizeof(int64_t)); } else { int32_t startIndex = pDumpInfo->rowIndex - dumpedRows + 1; - (void)memcpy(pColData->pData, &pBlockData->aTSKEY[startIndex], dumpedRows * sizeof(int64_t)); + TAOS_MEMCPY(pColData->pData, &pBlockData->aTSKEY[startIndex], dumpedRows * sizeof(int64_t)); // todo: opt perf by extract the loop // reverse the array list @@ -1084,12 +1293,28 @@ static void copyPrimaryTsCol(const SBlockData* pBlockData, SFileBlockDumpInfo* p pts[dumpedRows - j - 1] = t; } } + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } // a faster version of copy procedure. -static void copyNumericCols(const SColData* pData, SFileBlockDumpInfo* pDumpInfo, SColumnInfoData* pColData, - int32_t dumpedRows, bool asc) { +static int32_t copyNumericCols(const SColData* pData, SFileBlockDumpInfo* pDumpInfo, SColumnInfoData* pColData, + int32_t dumpedRows, bool asc) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; uint8_t* p = NULL; + int32_t step = asc ? 1 : -1; + + TSDB_CHECK_NULL(pData, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pDumpInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pColData, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_CONDITION(dumpedRows >= 0, code, lino, _end, TSDB_CODE_INVALID_PARA); + + TSDB_CHECK_CONDITION(pData->type < TSDB_DATA_TYPE_MAX, code, lino, _end, TSDB_CODE_INVALID_PARA); if (asc) { p = pData->pData + tDataTypes[pData->type].bytes * pDumpInfo->rowIndex; } else { @@ -1097,12 +1322,10 @@ static void copyNumericCols(const SColData* pData, SFileBlockDumpInfo* pDumpInfo p = pData->pData + tDataTypes[pData->type].bytes * startIndex; } - int32_t step = asc ? 1 : -1; - // make sure it is aligned to 8bit, the allocated memory address is aligned to 256bit // 1. copy data in a batch model - (void)memcpy(pColData->pData, p, dumpedRows * tDataTypes[pData->type].bytes); + TAOS_MEMCPY(pColData->pData, p, dumpedRows * tDataTypes[pData->type].bytes); // 2. reverse the array list in case of descending order scan data block if (!asc) { @@ -1173,6 +1396,12 @@ static void copyNumericCols(const SColData* pData, SFileBlockDumpInfo* pDumpInfo } } } + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static void blockInfoToRecord(SBrinRecord* record, SFileDataBlockInfo* pBlockInfo, SBlockLoadSuppInfo* pSupp) { @@ -1211,38 +1440,54 @@ static void blockInfoToRecord(SBrinRecord* record, SFileDataBlockInfo* pBlockInf } static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader, SRowKey* pLastProcKey) { - SReaderStatus* pStatus = &pReader->status; - SDataBlockIter* pBlockIter = &pStatus->blockIter; - SBlockLoadSuppInfo* pSupInfo = &pReader->suppInfo; - SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; - - SBlockData* pBlockData = &pStatus->fileBlockData; - SFileDataBlockInfo* pBlockInfo = NULL; - SSDataBlock* pResBlock = pReader->resBlockInfo.pResBlock; - int32_t numOfOutputCols = pSupInfo->numOfCols; int32_t code = TSDB_CODE_SUCCESS; - int64_t st = taosGetTimestampUs(); - bool asc = ASCENDING_TRAVERSE(pReader->info.order); - int32_t step = asc ? 1 : -1; + int32_t lino = 0; + SReaderStatus* pStatus = NULL; + SDataBlockIter* pBlockIter = NULL; + SBlockLoadSuppInfo* pSupInfo = NULL; + SFileBlockDumpInfo* pDumpInfo = NULL; + SBlockData* pBlockData = NULL; + SFileDataBlockInfo* pBlockInfo = NULL; + SSDataBlock* pResBlock = NULL; + int32_t numOfOutputCols = 0; + int64_t st = 0; + bool asc = false; + int32_t step = 0; + SColVal cv = {0}; + SBrinRecord tmp; + SBrinRecord* pRecord = NULL; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pStatus = &pReader->status; + pBlockIter = &pStatus->blockIter; + pSupInfo = &pReader->suppInfo; + pDumpInfo = &pReader->status.fBlockDumpInfo; + + pBlockData = &pStatus->fileBlockData; + pResBlock = pReader->resBlockInfo.pResBlock; + numOfOutputCols = pSupInfo->numOfCols; + st = taosGetTimestampUs(); + asc = ASCENDING_TRAVERSE(pReader->info.order); + step = asc ? 1 : -1; code = getCurrentBlockInfo(pBlockIter, &pBlockInfo, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); - SColVal cv = {0}; - SBrinRecord tmp; blockInfoToRecord(&tmp, pBlockInfo, pSupInfo); - SBrinRecord* pRecord = &tmp; + pRecord = &tmp; // no data exists, return directly. if (pBlockData->nRow == 0 || pBlockData->aTSKEY == 0) { tsdbWarn("%p no need to copy since no data in blockData, table uid:%" PRIu64 " has been dropped, %s", pReader, pBlockInfo->uid, pReader->idStr); pResBlock->info.rows = 0; - return 0; + goto _end; } + TSDB_CHECK_CONDITION((pDumpInfo->rowIndex >= 0) && (pDumpInfo->rowIndex < pRecord->numRow), code, lino, _end, + TSDB_CODE_INVALID_PARA); + // row index of dump info remain the initial position, let's find the appropriate start position. if (((pDumpInfo->rowIndex == 0) && asc) || ((pDumpInfo->rowIndex == (pRecord->numRow - 1)) && (!asc))) { if (asc && pReader->info.window.skey <= pRecord->firstKey.key.ts && @@ -1263,14 +1508,15 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader, SRowKey* pLastPro "-%" PRId64 ", minVer:%" PRId64 ", maxVer:%" PRId64 " %s", pReader, pBlockIter->index, pBlockInfo->tbBlockIdx, pRecord->firstKey.key.ts, pRecord->lastKey.key.ts, pRecord->minVer, pRecord->maxVer, pReader->idStr); - return TSDB_CODE_INVALID_PARA; + code = TSDB_CODE_INVALID_PARA; + TSDB_CHECK_CODE(code, lino, _end); } pDumpInfo->rowIndex = findFirstPos(pBlockData->aTSKEY, pRecord->numRow, pDumpInfo->rowIndex, (!asc)); - if (!(pReader->info.verRange.minVer <= pRecord->maxVer && pReader->info.verRange.maxVer >= pRecord->minVer)) { - tsdbError("tsdb failed at: %s:%d", __func__, __LINE__); - return TSDB_CODE_INVALID_PARA; - } + + TSDB_CHECK_CONDITION( + (pReader->info.verRange.minVer <= pRecord->maxVer && pReader->info.verRange.maxVer >= pRecord->minVer), code, + lino, _end, TSDB_CODE_INVALID_PARA); // find the appropriate start position that satisfies the version requirement. if ((pReader->info.verRange.maxVer >= pRecord->minVer && pReader->info.verRange.maxVer < pRecord->maxVer) || @@ -1299,7 +1545,7 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader, SRowKey* pLastPro int32_t endIndex = getEndPosInDataBlock(pReader, pBlockData, pRecord, pDumpInfo->rowIndex); if (endIndex == -1) { setBlockAllDumped(pDumpInfo, pReader->info.window.ekey, pReader->info.order); - return TSDB_CODE_SUCCESS; + goto _end; } endIndex += step; @@ -1308,19 +1554,18 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader, SRowKey* pLastPro dumpedRows = pReader->resBlockInfo.capacity; } else if (dumpedRows <= 0) { // no qualified rows in current data block, quit directly. setBlockAllDumped(pDumpInfo, pReader->info.window.ekey, pReader->info.order); - return TSDB_CODE_SUCCESS; + goto _end; } int32_t i = 0; int32_t rowIndex = 0; SColumnInfoData* pColData = taosArrayGet(pResBlock->pDataBlock, pSupInfo->slotId[i]); - if (pColData == NULL) { - return TSDB_CODE_INVALID_PARA; - } + TSDB_CHECK_NULL(pColData, code, lino, _end, TSDB_CODE_INVALID_PARA); if (pSupInfo->colId[i] == PRIMARYKEY_TIMESTAMP_COL_ID) { - copyPrimaryTsCol(pBlockData, pDumpInfo, pColData, dumpedRows, asc); + code = copyPrimaryTsCol(pBlockData, pDumpInfo, pColData, dumpedRows, asc); + TSDB_CHECK_CODE(code, lino, _end); i += 1; } @@ -1334,22 +1579,19 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader, SRowKey* pLastPro colIndex += 1; } else if (pData->cid == pSupInfo->colId[i]) { pColData = taosArrayGet(pResBlock->pDataBlock, pSupInfo->slotId[i]); - if (pColData == NULL) { - return TSDB_CODE_INVALID_PARA; - } + TSDB_CHECK_NULL(pColData, code, lino, _end, TSDB_CODE_INVALID_PARA); if (pData->flag == HAS_NONE || pData->flag == HAS_NULL || pData->flag == (HAS_NULL | HAS_NONE)) { colDataSetNNULL(pColData, 0, dumpedRows); } else { if (IS_MATHABLE_TYPE(pColData->info.type)) { - copyNumericCols(pData, pDumpInfo, pColData, dumpedRows, asc); + code = copyNumericCols(pData, pDumpInfo, pColData, dumpedRows, asc); + TSDB_CHECK_CODE(code, lino, _end); } else { // varchar/nchar type for (int32_t j = pDumpInfo->rowIndex; rowIndex < dumpedRows; j += step) { tColDataGetValue(pData, j, &cv); code = doCopyColVal(pColData, rowIndex++, i, &cv, pSupInfo); - if (code) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } } } @@ -1358,9 +1600,7 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader, SRowKey* pLastPro i += 1; } else { // the specified column does not exist in file block, fill with null data pColData = taosArrayGet(pResBlock->pDataBlock, pSupInfo->slotId[i]); - if (pColData == NULL) { - return TSDB_CODE_INVALID_PARA; - } + TSDB_CHECK_NULL(pColData, code, lino, _end, TSDB_CODE_INVALID_PARA); colDataSetNNULL(pColData, 0, dumpedRows); i += 1; @@ -1370,9 +1610,7 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader, SRowKey* pLastPro // fill the mis-matched columns with null value while (i < numOfOutputCols) { pColData = taosArrayGet(pResBlock->pDataBlock, pSupInfo->slotId[i]); - if (pColData == NULL) { - return TSDB_CODE_INVALID_PARA; - } + TSDB_CHECK_NULL(pColData, code, lino, _end, TSDB_CODE_INVALID_PARA); colDataSetNNULL(pColData, 0, dumpedRows); i += 1; @@ -1406,63 +1644,76 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader, SRowKey* pLastPro pReader, pBlockIter->index, pBlockInfo->tbBlockIdx, pRecord->firstKey.key.ts, pRecord->lastKey.key.ts, dumpedRows, unDumpedRows, pRecord->minVer, pRecord->maxVer, pBlockInfo->uid, elapsedTime, pReader->idStr); - return TSDB_CODE_SUCCESS; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static FORCE_INLINE STSchema* getTableSchemaImpl(STsdbReader* pReader, uint64_t uid) { - if (pReader->info.pSchema != NULL) { - terrno = TSDB_CODE_INVALID_PARA; - tsdbError("tsdb invalid input param at: %s:%d", __func__, __LINE__); - return NULL; - } + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; - int32_t code = metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, pReader->info.suid, uid, -1, &pReader->info.pSchema); + TSDB_CHECK_CONDITION((pReader != NULL) && (pReader->info.pSchema == NULL), code, lino, _end, TSDB_CODE_INVALID_PARA); + + code = metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, pReader->info.suid, uid, -1, &pReader->info.pSchema); if (code != TSDB_CODE_SUCCESS || pReader->info.pSchema == NULL) { terrno = code; tsdbError("failed to get table schema, uid:%" PRIu64 ", it may have been dropped, ver:-1, %s", uid, pReader->idStr); - return NULL; } + TSDB_CHECK_CODE(code, lino, _end); + TSDB_CHECK_NULL(pReader->info.pSchema, code, lino, _end, TSDB_CODE_INTERNAL_ERROR); code = tsdbRowMergerInit(&pReader->status.merger, pReader->info.pSchema); + TSDB_CHECK_CODE(code, lino, _end); + +_end: if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); terrno = code; - tsdbError("failed to init merger, code:%s, %s", tstrerror(code), pReader->idStr); return NULL; } - return pReader->info.pSchema; } static int32_t doLoadFileBlockData(STsdbReader* pReader, SDataBlockIter* pBlockIter, SBlockData* pBlockData, uint64_t uid) { - int32_t code = 0; - STSchema* pSchema = pReader->info.pSchema; - int64_t st = taosGetTimestampUs(); + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + STSchema* pSchema = NULL; SFileDataBlockInfo* pBlockInfo = NULL; - SBlockLoadSuppInfo* pSup = &pReader->suppInfo; + SBlockLoadSuppInfo* pSup = NULL; + SFileBlockDumpInfo* pDumpInfo = NULL; + int64_t st = 0; + SBrinRecord tmp; + SBrinRecord* pRecord = NULL; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pBlockData, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pSchema = pReader->info.pSchema; + st = taosGetTimestampUs(); + pSup = &pReader->suppInfo; tBlockDataReset(pBlockData); if (pReader->info.pSchema == NULL) { pSchema = getTableSchemaImpl(pReader, uid); if (pSchema == NULL) { - code = terrno; tsdbError("%p table uid:%" PRIu64 " failed to get tableschema, code:%s, %s", pReader, uid, tstrerror(code), pReader->idStr); - return code; + TSDB_CHECK_NULL(pSchema, code, lino, _end, terrno); } } code = getCurrentBlockInfo(pBlockIter, &pBlockInfo, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); - SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; + pDumpInfo = &pReader->status.fBlockDumpInfo; - SBrinRecord tmp; blockInfoToRecord(&tmp, pBlockInfo, pSup); - SBrinRecord* pRecord = &tmp; + pRecord = &tmp; code = tsdbDataFileReadBlockDataByColumn(pReader->pFileReader, pRecord, pBlockData, pSchema, &pSup->colId[1], pSup->numOfCols - 1); if (code != TSDB_CODE_SUCCESS) { @@ -1470,7 +1721,7 @@ static int32_t doLoadFileBlockData(STsdbReader* pReader, SDataBlockIter* pBlockI ", rows:%d, code:%s %s", pReader, pBlockIter->index, pBlockInfo->tbBlockIdx, pBlockInfo->firstKey, pBlockInfo->lastKey, pBlockInfo->numRow, tstrerror(code), pReader->idStr); - return code; + TSDB_CHECK_CODE(code, lino, _end); } double elapsedTime = (taosGetTimestampUs() - st) / 1000.0; @@ -1483,6 +1734,10 @@ static int32_t doLoadFileBlockData(STsdbReader* pReader, SDataBlockIter* pBlockI pReader->cost.blockLoadTime += elapsedTime; pDumpInfo->allDumped = false; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } @@ -1496,69 +1751,83 @@ static int32_t dataBlockPartiallyRequired(STimeWindow* pWindow, SVersionRange* p (pVerRange->maxVer < pBlock->maxVer && pVerRange->maxVer >= pBlock->minVer); } -static bool getNeighborBlockOfTable(SDataBlockIter* pBlockIter, SFileDataBlockInfo* pBlockInfo, - STableBlockScanInfo* pScanInfo, int32_t* nextIndex, int32_t order, - SBrinRecord* pRecord, SBlockLoadSuppInfo* pSupInfo) { - bool asc = ASCENDING_TRAVERSE(order); - int32_t step = asc ? 1 : -1; +static int32_t getNeighborBlockOfTable(SDataBlockIter* pBlockIter, SFileDataBlockInfo* pBlockInfo, + STableBlockScanInfo* pScanInfo, int32_t* nextIndex, int32_t order, + SBrinRecord* pRecord, SBlockLoadSuppInfo* pSupInfo, bool* res) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + bool asc = false; + int32_t step = 0; + STableDataBlockIdx* pTableDataBlockIdx = NULL; + SFileDataBlockInfo* p = NULL; + + TSDB_CHECK_NULL(pBlockInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(res, code, lino, _end, TSDB_CODE_INVALID_PARA); + + *res = false; + asc = ASCENDING_TRAVERSE(order); + step = asc ? 1 : -1; if (asc && pBlockInfo->tbBlockIdx >= taosArrayGetSize(pScanInfo->pBlockIdxList) - 1) { - return false; + *res = false; + } else if (!asc && pBlockInfo->tbBlockIdx == 0) { + *res = false; + } else { + TSDB_CHECK_NULL(pBlockIter, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(nextIndex, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pRecord, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pSupInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pTableDataBlockIdx = taosArrayGet(pScanInfo->pBlockIdxList, pBlockInfo->tbBlockIdx + step); + TSDB_CHECK_NULL(pTableDataBlockIdx, code, lino, _end, TSDB_CODE_INVALID_PARA); + + p = taosArrayGet(pBlockIter->blockList, pTableDataBlockIdx->globalIndex); + TSDB_CHECK_NULL(p, code, lino, _end, TSDB_CODE_INVALID_PARA); + + blockInfoToRecord(pRecord, p, pSupInfo); + + *nextIndex = pBlockInfo->tbBlockIdx + step; + *res = true; } - if (!asc && pBlockInfo->tbBlockIdx == 0) { - return false; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); } - - STableDataBlockIdx* pTableDataBlockIdx = taosArrayGet(pScanInfo->pBlockIdxList, pBlockInfo->tbBlockIdx + step); - if (pTableDataBlockIdx == NULL) { - return TSDB_CODE_INVALID_PARA; - } - - SFileDataBlockInfo* p = taosArrayGet(pBlockIter->blockList, pTableDataBlockIdx->globalIndex); - if (p == NULL) { - return TSDB_CODE_INVALID_PARA; - } - - blockInfoToRecord(pRecord, p, pSupInfo); - - *nextIndex = pBlockInfo->tbBlockIdx + step; - return true; + return code; } static int32_t setFileBlockActiveInBlockIter(STsdbReader* pReader, SDataBlockIter* pBlockIter, int32_t index, int32_t step) { - int32_t code = TSDB_CODE_SUCCESS; - if (index < 0 || index >= pBlockIter->numOfBlocks) { - return TSDB_CODE_FAILED; - } + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + const void* p = NULL; + SFileDataBlockInfo fblock; + SFileDataBlockInfo* pBlockInfo = NULL; + STableBlockScanInfo* pBlockScanInfo = NULL; + STableDataBlockIdx* pTableDataBlockIdx = NULL; - void* p = taosArrayGet(pBlockIter->blockList, index); - if (p == NULL) { - return TSDB_CODE_INVALID_PARA; - } + TSDB_CHECK_NULL(pBlockIter, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_CONDITION((index >= 0) && (index < pBlockIter->numOfBlocks), code, lino, _end, TSDB_CODE_INVALID_PARA); - SFileDataBlockInfo fblock = *(SFileDataBlockInfo*) p; + p = taosArrayGet(pBlockIter->blockList, index); + TSDB_CHECK_NULL(p, code, lino, _end, TSDB_CODE_INVALID_PARA); + + fblock = *(SFileDataBlockInfo*)p; pBlockIter->index += step; if (index != pBlockIter->index) { if (index > pBlockIter->index) { for (int32_t i = index - 1; i >= pBlockIter->index; --i) { - SFileDataBlockInfo* pBlockInfo = taosArrayGet(pBlockIter->blockList, i); - if (pBlockInfo == NULL) { - return TSDB_CODE_INVALID_PARA; - } + pBlockInfo = taosArrayGet(pBlockIter->blockList, i); + TSDB_CHECK_NULL(pBlockInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); - STableBlockScanInfo* pBlockScanInfo = NULL; code = getTableBlockScanInfo(pReader->status.pTableMap, pBlockInfo->uid, &pBlockScanInfo, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); - STableDataBlockIdx* pTableDataBlockIdx = taosArrayGet(pBlockScanInfo->pBlockIdxList, pBlockInfo->tbBlockIdx); - if (pTableDataBlockIdx == NULL) { - return TSDB_CODE_INVALID_PARA; - } + pTableDataBlockIdx = taosArrayGet(pBlockScanInfo->pBlockIdxList, pBlockInfo->tbBlockIdx); + TSDB_CHECK_NULL(pTableDataBlockIdx, code, lino, _end, TSDB_CODE_INVALID_PARA); pTableDataBlockIdx->globalIndex = i + 1; @@ -1566,21 +1835,14 @@ static int32_t setFileBlockActiveInBlockIter(STsdbReader* pReader, SDataBlockIte } } else if (index < pBlockIter->index) { for (int32_t i = index + 1; i <= pBlockIter->index; ++i) { - SFileDataBlockInfo* pBlockInfo = taosArrayGet(pBlockIter->blockList, i); - if (pBlockInfo == NULL) { - return TSDB_CODE_INVALID_PARA; - } + pBlockInfo = taosArrayGet(pBlockIter->blockList, i); + TSDB_CHECK_NULL(pBlockInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); - STableBlockScanInfo* pBlockScanInfo = NULL; code = getTableBlockScanInfo(pReader->status.pTableMap, pBlockInfo->uid, &pBlockScanInfo, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); - STableDataBlockIdx* pTableDataBlockIdx = taosArrayGet(pBlockScanInfo->pBlockIdxList, pBlockInfo->tbBlockIdx); - if (pTableDataBlockIdx == NULL) { - return TSDB_CODE_INVALID_PARA; - } + pTableDataBlockIdx = taosArrayGet(pBlockScanInfo->pBlockIdxList, pBlockInfo->tbBlockIdx); + TSDB_CHECK_NULL(pTableDataBlockIdx, code, lino, _end, TSDB_CODE_INVALID_PARA); pTableDataBlockIdx->globalIndex = i - 1; taosArraySet(pBlockIter->blockList, i - 1, pBlockInfo); @@ -1588,21 +1850,21 @@ static int32_t setFileBlockActiveInBlockIter(STsdbReader* pReader, SDataBlockIte } taosArraySet(pBlockIter->blockList, pBlockIter->index, &fblock); - STableBlockScanInfo* pBlockScanInfo = NULL; + pBlockScanInfo = NULL; code = getTableBlockScanInfo(pReader->status.pTableMap, fblock.uid, &pBlockScanInfo, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); - STableDataBlockIdx* pTableDataBlockIdx = taosArrayGet(pBlockScanInfo->pBlockIdxList, fblock.tbBlockIdx); - if (pTableDataBlockIdx == NULL) { - return TSDB_CODE_INVALID_PARA; - } + pTableDataBlockIdx = taosArrayGet(pBlockScanInfo->pBlockIdxList, fblock.tbBlockIdx); + TSDB_CHECK_NULL(pTableDataBlockIdx, code, lino, _end, TSDB_CODE_INVALID_PARA); pTableDataBlockIdx->globalIndex = pBlockIter->index; } - return TSDB_CODE_SUCCESS; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } // todo: this attribute could be acquired during extractin the global ordered block list. @@ -1672,15 +1934,26 @@ static bool keyOverlapFileBlock(TSDBKEY key, SFileDataBlockInfo* pBlock, SVersio (pBlock->minVer <= pVerRange->maxVer); } -static void getBlockToLoadInfo(SDataBlockToLoadInfo* pInfo, SFileDataBlockInfo* pBlockInfo, - STableBlockScanInfo* pScanInfo, TSDBKEY keyInBuf, STsdbReader* pReader) { +static int32_t getBlockToLoadInfo(SDataBlockToLoadInfo* pInfo, SFileDataBlockInfo* pBlockInfo, + STableBlockScanInfo* pScanInfo, TSDBKEY keyInBuf, STsdbReader* pReader) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; SBrinRecord rec = {0}; int32_t neighborIndex = 0; - int32_t order = pReader->info.order; - SBlockLoadSuppInfo* pSupInfo = &pReader->suppInfo; + int32_t order = 0; + SBlockLoadSuppInfo* pSupInfo = NULL; + SBrinRecord pRecord; + bool hasNeighbor = false; - bool hasNeighbor = - getNeighborBlockOfTable(&pReader->status.blockIter, pBlockInfo, pScanInfo, &neighborIndex, order, &rec, pSupInfo); + TSDB_CHECK_NULL(pInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + order = pReader->info.order; + pSupInfo = &pReader->suppInfo; + + code = getNeighborBlockOfTable(&pReader->status.blockIter, pBlockInfo, pScanInfo, &neighborIndex, order, &rec, + pSupInfo, &hasNeighbor); + TSDB_CHECK_CODE(code, lino, _end); // overlap with neighbor if (hasNeighbor) { @@ -1688,7 +1961,6 @@ static void getBlockToLoadInfo(SDataBlockToLoadInfo* pInfo, SFileDataBlockInfo* overlapWithNeighborBlock2(pBlockInfo, &rec, order, pSupInfo->pk.type, pSupInfo->numOfPks); } - SBrinRecord pRecord; blockInfoToRecord(&pRecord, pBlockInfo, pSupInfo); // has duplicated ts of different version in this block @@ -1704,6 +1976,12 @@ static void getBlockToLoadInfo(SDataBlockToLoadInfo* pInfo, SFileDataBlockInfo* pInfo->moreThanCapcity = pBlockInfo->numRow > pReader->resBlockInfo.capacity; pInfo->partiallyRequired = dataBlockPartiallyRequired(&pReader->info.window, &pReader->info.verRange, pBlockInfo); pInfo->overlapWithKeyInBuf = keyOverlapFileBlock(keyInBuf, pBlockInfo, &pReader->info.verRange); + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } // 1. the version of all rows should be less than the endVersion @@ -1712,17 +1990,23 @@ static void getBlockToLoadInfo(SDataBlockToLoadInfo* pInfo, SFileDataBlockInfo* // 4. output buffer should be large enough to hold all rows in current block // 5. delete info should not overlap with current block data // 6. current block should not contain the duplicated ts -static bool fileBlockShouldLoad(STsdbReader* pReader, SFileDataBlockInfo* pBlockInfo, STableBlockScanInfo* pScanInfo, - TSDBKEY keyInBuf) { +static int32_t fileBlockShouldLoad(STsdbReader* pReader, SFileDataBlockInfo* pBlockInfo, STableBlockScanInfo* pScanInfo, + TSDBKEY keyInBuf, bool* load) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; SDataBlockToLoadInfo info = {0}; - getBlockToLoadInfo(&info, pBlockInfo, pScanInfo, keyInBuf, pReader); - bool loadDataBlock = - (info.overlapWithNeighborBlock || info.hasDupTs || info.partiallyRequired || info.overlapWithKeyInBuf || - info.moreThanCapcity || info.overlapWithDelInfo || info.overlapWithSttBlock); + TSDB_CHECK_NULL(load, code, lino, _end, TSDB_CODE_INVALID_PARA); + + *load = false; + code = getBlockToLoadInfo(&info, pBlockInfo, pScanInfo, keyInBuf, pReader); + TSDB_CHECK_CODE(code, lino, _end); + + *load = (info.overlapWithNeighborBlock || info.hasDupTs || info.partiallyRequired || info.overlapWithKeyInBuf || + info.moreThanCapcity || info.overlapWithDelInfo || info.overlapWithSttBlock); // log the reason why load the datablock for profile - if (loadDataBlock) { + if (*load) { tsdbDebug("%p uid:%" PRIu64 " need to load the datablock, overlapneighbor:%d, hasDup:%d, partiallyRequired:%d, " "overlapWithKey:%d, greaterThanBuf:%d, overlapWithDel:%d, overlapWithSttBlock:%d, %s", @@ -1731,45 +2015,76 @@ static bool fileBlockShouldLoad(STsdbReader* pReader, SFileDataBlockInfo* pBlock pReader->idStr); } - return loadDataBlock; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } -static bool isCleanFileDataBlock(STsdbReader* pReader, SFileDataBlockInfo* pBlockInfo, STableBlockScanInfo* pScanInfo, - TSDBKEY keyInBuf) { +static int32_t isCleanFileDataBlock(STsdbReader* pReader, SFileDataBlockInfo* pBlockInfo, + STableBlockScanInfo* pScanInfo, TSDBKEY keyInBuf, bool* res) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; SDataBlockToLoadInfo info = {0}; - getBlockToLoadInfo(&info, pBlockInfo, pScanInfo, keyInBuf, pReader); - bool isCleanFileBlock = !(info.overlapWithNeighborBlock || info.hasDupTs || info.overlapWithKeyInBuf || - info.overlapWithDelInfo || info.overlapWithSttBlock); - return isCleanFileBlock; + + TSDB_CHECK_NULL(res, code, lino, _end, TSDB_CODE_INVALID_PARA); + + *res = false; + code = getBlockToLoadInfo(&info, pBlockInfo, pScanInfo, keyInBuf, pReader); + TSDB_CHECK_CODE(code, lino, _end); + + *res = !(info.overlapWithNeighborBlock || info.hasDupTs || info.overlapWithKeyInBuf || info.overlapWithDelInfo || + info.overlapWithSttBlock); + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static int32_t initRowMergeIfNeeded(STsdbReader* pReader, int64_t uid) { - SRowMerger* pMerger = &pReader->status.merger; - int32_t code = 0; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SRowMerger* pMerger = NULL; + STSchema* ps = NULL; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pMerger = &pReader->status.merger; if (pMerger->pArray == NULL) { - STSchema* ps = getTableSchemaImpl(pReader, uid); - if (ps == NULL) { - return terrno; - } + ps = getTableSchemaImpl(pReader, uid); + TSDB_CHECK_NULL(ps, code, lino, _end, terrno); } +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } static int32_t buildDataBlockFromBuf(STsdbReader* pReader, STableBlockScanInfo* pBlockScanInfo, int64_t endKey) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + int64_t st = 0; + SSDataBlock* pBlock = NULL; + + TSDB_CHECK_NULL(pBlockScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + if (!(pBlockScanInfo->iiter.hasVal || pBlockScanInfo->iter.hasVal)) { - return TSDB_CODE_SUCCESS; + goto _end; } - int32_t code = initRowMergeIfNeeded(pReader, pBlockScanInfo->uid); - if (code != 0) { - return code; - } + code = initRowMergeIfNeeded(pReader, pBlockScanInfo->uid); + TSDB_CHECK_CODE(code, lino, _end); - int64_t st = taosGetTimestampUs(); - SSDataBlock* pBlock = pReader->resBlockInfo.pResBlock; + st = taosGetTimestampUs(); + pBlock = pReader->resBlockInfo.pResBlock; code = buildDataBlockFromBufImpl(pBlockScanInfo, endKey, pReader->resBlockInfo.capacity, pReader); + TSDB_CHECK_CODE(code, lino, _end); double el = (taosGetTimestampUs() - st) / 1000.0; updateComposedBlockInfo(pReader, el, pBlockScanInfo); @@ -1780,43 +2095,65 @@ static int32_t buildDataBlockFromBuf(STsdbReader* pReader, STableBlockScanInfo* pReader->idStr); pReader->cost.buildmemBlock += el; + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } -static bool tryCopyDistinctRowFromFileBlock(STsdbReader* pReader, SBlockData* pBlockData, SRowKey* pKey, - SFileBlockDumpInfo* pDumpInfo, bool* copied) { +static int32_t tryCopyDistinctRowFromFileBlock(STsdbReader* pReader, SBlockData* pBlockData, SRowKey* pKey, + SFileBlockDumpInfo* pDumpInfo, bool* copied) { // opt version // 1. it is not a border point // 2. the direct next point is not an duplicated timestamp int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + bool asc = false; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pDumpInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(copied, code, lino, _end, TSDB_CODE_INVALID_PARA); *copied = false; - bool asc = (pReader->info.order == TSDB_ORDER_ASC); + asc = (pReader->info.order == TSDB_ORDER_ASC); if ((pDumpInfo->rowIndex < pDumpInfo->totalRows - 1 && asc) || (pDumpInfo->rowIndex > 0 && (!asc))) { int32_t step = ASCENDING_TRAVERSE(pReader->info.order) ? 1 : -1; SRowKey nextRowKey; + TSDB_CHECK_NULL(pBlockData, code, lino, _end, TSDB_CODE_INVALID_PARA); tColRowGetKey(pBlockData, pDumpInfo->rowIndex + step, &nextRowKey); if (pkCompEx(pKey, &nextRowKey) != 0) { // merge is not needed code = doAppendRowFromFileBlock(pReader->resBlockInfo.pResBlock, pReader, pBlockData, pDumpInfo->rowIndex); - if (code) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); pDumpInfo->rowIndex += step; *copied = true; } } +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } static int32_t nextRowFromSttBlocks(SSttBlockReader* pSttBlockReader, STableBlockScanInfo* pScanInfo, int32_t pkSrcSlot, SVersionRange* pVerRange) { - int32_t code = 0; - int32_t order = pSttBlockReader->order; - int32_t step = ASCENDING_TRAVERSE(order) ? 1 : -1; - SRowKey* pNextProc = &pScanInfo->sttKeyInfo.nextProcKey; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + int32_t order = 0; + int32_t step = 0; + SRowKey* pNextProc = NULL; + + TSDB_CHECK_NULL(pSttBlockReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + + order = pSttBlockReader->order; + step = ASCENDING_TRAVERSE(order) ? 1 : -1; + pNextProc = &pScanInfo->sttKeyInfo.nextProcKey; while (1) { bool hasVal = false; @@ -1824,7 +2161,7 @@ static int32_t nextRowFromSttBlocks(SSttBlockReader* pSttBlockReader, STableBloc if (code) { tsdbError("failed to iter the next row in stt-file merge tree, code:%s, %s", tstrerror(code), pSttBlockReader->mergeTree.idStr); - return code; + TSDB_CHECK_CODE(code, lino, _end); } if (!hasVal) { // the next value will be the accessed key in stt @@ -1839,7 +2176,7 @@ static int32_t nextRowFromSttBlocks(SSttBlockReader* pSttBlockReader, STableBloc memset(pNextProc->pks[0].pData, 0, pNextProc->pks[0].nData); } } - return code; + goto _end; } TSDBROW* pRow = tMergeTreeGetRow(&pSttBlockReader->mergeTree); @@ -1855,17 +2192,24 @@ static int32_t nextRowFromSttBlocks(SSttBlockReader* pSttBlockReader, STableBloc tColRowGetKeyDeepCopy(pRow->pBlockData, pRow->iRow, pkSrcSlot, pNextProc); if (pScanInfo->delSkyline != NULL && TARRAY_SIZE(pScanInfo->delSkyline) > 0) { - if (!hasBeenDropped(pScanInfo->delSkyline, &pScanInfo->sttBlockDelIndex, key, ver, order, pVerRange, - pSttBlockReader->numOfPks > 0)) { + bool dropped = false; + code = hasBeenDropped(pScanInfo->delSkyline, &pScanInfo->sttBlockDelIndex, key, ver, order, pVerRange, + pSttBlockReader->numOfPks > 0, &dropped); + TSDB_CHECK_CODE(code, lino, _end); + if (!dropped) { pScanInfo->sttKeyInfo.status = STT_FILE_HAS_DATA; - return code; + goto _end; } } else { pScanInfo->sttKeyInfo.status = STT_FILE_HAS_DATA; - return code; + goto _end; } } +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } @@ -1876,89 +2220,113 @@ static void doUnpinSttBlock(SSttBlockReader* pSttBlockReader) { tMergeTreeUnpinS static int32_t tryCopyDistinctRowFromSttBlock(TSDBROW* fRow, SSttBlockReader* pSttBlockReader, STableBlockScanInfo* pScanInfo, SRowKey* pSttKey, STsdbReader* pReader, bool* copied) { - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SRowKey* pNext = NULL; + + TSDB_CHECK_NULL(pSttBlockReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(copied, code, lino, _end, TSDB_CODE_INVALID_PARA); + *copied = false; // avoid the fetch next row replace the referenced stt block in buffer doPinSttBlock(pSttBlockReader); code = nextRowFromSttBlocks(pSttBlockReader, pScanInfo, pReader->suppInfo.pkSrcSlot, &pReader->info.verRange); doUnpinSttBlock(pSttBlockReader); - - if (code) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if (hasDataInSttBlock(pScanInfo)) { - SRowKey* pNext = getCurrentKeyInSttBlock(pSttBlockReader); + pNext = getCurrentKeyInSttBlock(pSttBlockReader); if (pkCompEx(pSttKey, pNext) != 0) { code = doAppendRowFromFileBlock(pReader->resBlockInfo.pResBlock, pReader, fRow->pBlockData, fRow->iRow); *copied = (code == TSDB_CODE_SUCCESS); - return code; + TSDB_CHECK_CODE(code, lino, _end); } } else { code = doAppendRowFromFileBlock(pReader->resBlockInfo.pResBlock, pReader, fRow->pBlockData, fRow->iRow); *copied = (code == TSDB_CODE_SUCCESS); - return code; + TSDB_CHECK_CODE(code, lino, _end); } +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } static FORCE_INLINE STSchema* doGetSchemaForTSRow(int32_t sversion, STsdbReader* pReader, uint64_t uid) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + STSchema* ps = NULL; + void** p = NULL; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + // always set the newest schema version in pReader->info.pSchema if (pReader->info.pSchema == NULL) { - STSchema* ps = getTableSchemaImpl(pReader, uid); - if (ps == NULL) { - return NULL; - } + ps = getTableSchemaImpl(pReader, uid); + TSDB_CHECK_NULL(ps, code, lino, _end, terrno); } if (pReader->info.pSchema && sversion == pReader->info.pSchema->version) { - return pReader->info.pSchema; + ps = pReader->info.pSchema; + goto _end; } - void** p = tSimpleHashGet(pReader->pSchemaMap, &sversion, sizeof(sversion)); + p = tSimpleHashGet(pReader->pSchemaMap, &sversion, sizeof(sversion)); if (p != NULL) { - return *(STSchema**)p; + ps = *(STSchema**)p; + goto _end; } - STSchema* ptr = NULL; - int32_t code = metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, pReader->info.suid, uid, sversion, &ptr); + code = metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, pReader->info.suid, uid, sversion, &ps); + TSDB_CHECK_CODE(code, lino, _end); + + code = tSimpleHashPut(pReader->pSchemaMap, &sversion, sizeof(sversion), &ps, POINTER_BYTES); + TSDB_CHECK_CODE(code, lino, _end); + +_end: if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); terrno = code; return NULL; - } else { - code = tSimpleHashPut(pReader->pSchemaMap, &sversion, sizeof(sversion), &ptr, POINTER_BYTES); - if (code != TSDB_CODE_SUCCESS) { - terrno = code; - return NULL; - } - return ptr; } + return ps; } static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo* pBlockScanInfo, TSDBROW* pRow, SIterInfo* pIter, SSttBlockReader* pSttBlockReader) { - SRowMerger* pMerger = &pReader->status.merger; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SRowMerger* pMerger = NULL; SRow* pTSRow = NULL; - SBlockData* pBlockData = &pReader->status.fileBlockData; - SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; - int32_t pkSrcSlot = pReader->suppInfo.pkSrcSlot; + SBlockData* pBlockData = NULL; + SFileBlockDumpInfo* pDumpInfo = NULL; + SRowKey* pSttKey = NULL; + int32_t pkSrcSlot = 0; + SRowKey k = {0}; + STSchema* pSchema = NULL; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pBlockScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pRow, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pMerger = &pReader->status.merger; + pBlockData = &pReader->status.fileBlockData; + pDumpInfo = &pReader->status.fBlockDumpInfo; + pkSrcSlot = pReader->suppInfo.pkSrcSlot; - SRowKey* pSttKey = NULL; if (hasDataInSttBlock(pBlockScanInfo) && (!pBlockScanInfo->cleanSttBlocks)) { pSttKey = getCurrentKeyInSttBlock(pSttBlockReader); } - SRowKey k = {0}; tRowGetKeyEx(pRow, &k); - STSchema* pSchema = NULL; if (pRow->type == TSDBROW_ROW_FMT) { pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid); - if (pSchema == NULL) { - return terrno; - } + TSDB_CHECK_NULL(pSchema, code, lino, _end, terrno); } SRowKey* pfKey = &(SRowKey){0}; @@ -1971,10 +2339,8 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo* TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex); // merge is not initialized yet, due to the fact that the pReader->info.pSchema is not initialized - int32_t code = initRowMergeIfNeeded(pReader, pBlockScanInfo->uid); - if (code != 0) { - return code; - } + code = initRowMergeIfNeeded(pReader, pBlockScanInfo->uid); + TSDB_CHECK_CODE(code, lino, _end); SRowKey minKey = k; if (pReader->info.order == TSDB_ORDER_ASC) { @@ -2002,79 +2368,83 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo* // file block ---> stt block -----> mem if (pkCompEx(&minKey, pfKey) == 0) { code = tsdbRowMergerAdd(pMerger, &fRow, NULL); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pfKey, pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } if (pkCompEx(&minKey, pSttKey) == 0) { TSDBROW* fRow1 = tMergeTreeGetRow(&pSttBlockReader->mergeTree); code = tsdbRowMergerAdd(pMerger, fRow1, NULL); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - code = doMergeRowsInSttBlock(pSttBlockReader, pBlockScanInfo, pMerger, pkSrcSlot, &pReader->info.verRange, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); + code = doMergeRowsInSttBlock(pSttBlockReader, pBlockScanInfo, pMerger, pkSrcSlot, &pReader->info.verRange, + pReader->idStr); + TSDB_CHECK_CODE(code, lino, _end); } if (pkCompEx(&minKey, &k) == 0) { code = tsdbRowMergerAdd(pMerger, pRow, pSchema); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = doMergeRowsInBuf(pIter, pBlockScanInfo->uid, &k, pBlockScanInfo->delSkyline, pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } code = tsdbRowMergerGetRow(pMerger, &pTSRow); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = doAppendRowFromTSRow(pReader->resBlockInfo.pResBlock, pReader, pTSRow, pBlockScanInfo); - taosMemoryFree(pTSRow); + taosMemoryFreeClear(pTSRow); tsdbRowMergerClear(pMerger); + TSDB_CHECK_CODE(code, lino, _end); +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } static int32_t mergeFileBlockAndSttBlock(STsdbReader* pReader, SSttBlockReader* pSttBlockReader, SRowKey* pKey, STableBlockScanInfo* pBlockScanInfo, SBlockData* pBlockData) { - SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; - SRowMerger* pMerger = &pReader->status.merger; int32_t code = TSDB_CODE_SUCCESS; - int32_t pkSrcSlot = pReader->suppInfo.pkSrcSlot; + int32_t lino = 0; + SFileBlockDumpInfo* pDumpInfo = NULL; + SRowMerger* pMerger = NULL; + SRow* pTSRow = NULL; + int32_t pkSrcSlot = 0; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pBlockScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pBlockData, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pDumpInfo = &pReader->status.fBlockDumpInfo; + pMerger = &pReader->status.merger; + pkSrcSlot = pReader->suppInfo.pkSrcSlot; // merge is not initialized yet, due to the fact that the pReader->info.pSchema is not initialized code = initRowMergeIfNeeded(pReader, pBlockScanInfo->uid); - if (code != 0) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); bool dataInDataFile = hasDataInFileBlock(pBlockData, pDumpInfo); bool dataInSttFile = hasDataInSttBlock(pBlockScanInfo); if (dataInDataFile && (!dataInSttFile)) { // no stt file block available, only data block exists - return mergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pKey, pReader); + code = mergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pKey, pReader); + TSDB_CHECK_CODE(code, lino, _end); } else if ((!dataInDataFile) && dataInSttFile) { // no data in data file exists - return mergeRowsInSttBlocks(pSttBlockReader, pBlockScanInfo, pReader); + code = mergeRowsInSttBlocks(pSttBlockReader, pBlockScanInfo, pReader); + TSDB_CHECK_CODE(code, lino, _end); } else if (pBlockScanInfo->cleanSttBlocks && pReader->info.execMode == READER_EXEC_ROWS) { // opt model for count data in stt file, which is not overlap with data blocks in files. - return mergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pKey, pReader); + code = mergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pKey, pReader); + TSDB_CHECK_CODE(code, lino, _end); } else { + TSDB_CHECK_NULL(pKey, code, lino, _end, TSDB_CODE_INVALID_PARA); // row in both stt file blocks and data file blocks TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex); SRowKey* pSttKey = getCurrentKeyInSttBlock(pSttBlockReader); @@ -2083,74 +2453,90 @@ static int32_t mergeFileBlockAndSttBlock(STsdbReader* pReader, SSttBlockReader* if (ASCENDING_TRAVERSE(pReader->info.order)) { if (ret < 0) { // asc - return mergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pKey, pReader); + code = mergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pKey, pReader); + TSDB_CHECK_CODE(code, lino, _end); } else if (ret > 0) { - return mergeRowsInSttBlocks(pSttBlockReader, pBlockScanInfo, pReader); + code = mergeRowsInSttBlocks(pSttBlockReader, pBlockScanInfo, pReader); + TSDB_CHECK_CODE(code, lino, _end); } } else { // desc if (ret > 0) { - return mergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pKey, pReader); + code = mergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pKey, pReader); + TSDB_CHECK_CODE(code, lino, _end); } else if (ret < 0) { - return mergeRowsInSttBlocks(pSttBlockReader, pBlockScanInfo, pReader); + code = mergeRowsInSttBlocks(pSttBlockReader, pBlockScanInfo, pReader); + TSDB_CHECK_CODE(code, lino, _end); } } + if (ret != 0) { + goto _end; + } // pKey == pSttKey tRowKeyAssign(&pBlockScanInfo->lastProcKey, pKey); // the following for key == sttKey->key.ts // file block ------> stt block - SRow* pTSRow = NULL; + code = tsdbRowMergerAdd(pMerger, &fRow, NULL); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pKey, pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); TSDBROW* pRow1 = tMergeTreeGetRow(&pSttBlockReader->mergeTree); code = tsdbRowMergerAdd(pMerger, pRow1, NULL); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); // pSttKey will be changed when sttBlockReader iterates to the next row, so use pKey instead. - code = doMergeRowsInSttBlock(pSttBlockReader, pBlockScanInfo, pMerger, pkSrcSlot, &pReader->info.verRange, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + code = doMergeRowsInSttBlock(pSttBlockReader, pBlockScanInfo, pMerger, pkSrcSlot, &pReader->info.verRange, + pReader->idStr); + TSDB_CHECK_CODE(code, lino, _end); code = tsdbRowMergerGetRow(pMerger, &pTSRow); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = doAppendRowFromTSRow(pReader->resBlockInfo.pResBlock, pReader, pTSRow, pBlockScanInfo); - taosMemoryFree(pTSRow); + taosMemoryFreeClear(pTSRow); tsdbRowMergerClear(pMerger); - return code; + TSDB_CHECK_CODE(code, lino, _end); } + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo* pBlockScanInfo, SBlockData* pBlockData, SSttBlockReader* pSttBlockReader) { - SRowMerger* pMerger = &pReader->status.merger; - SRow* pTSRow = NULL; int32_t code = TSDB_CODE_SUCCESS; - SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; - SArray* pDelList = pBlockScanInfo->delSkyline; - int32_t pkSrcSlot = pReader->suppInfo.pkSrcSlot; + int32_t lino = 0; + SRowMerger* pMerger = NULL; + SRow* pTSRow = NULL; + SFileBlockDumpInfo* pDumpInfo = NULL; + SArray* pDelList = NULL; + int32_t pkSrcSlot = 0; TSDBROW* pRow = NULL; TSDBROW* piRow = NULL; + SRowKey* pSttKey = NULL; - getValidMemRow(&pBlockScanInfo->iter, pDelList, pReader, &pRow); - getValidMemRow(&pBlockScanInfo->iiter, pDelList, pReader, &piRow); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pBlockScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pBlockData, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pMerger = &pReader->status.merger; + pDumpInfo = &pReader->status.fBlockDumpInfo; + pDelList = pBlockScanInfo->delSkyline; + pkSrcSlot = pReader->suppInfo.pkSrcSlot; + + code = getValidMemRow(&pBlockScanInfo->iter, pDelList, pReader, &pRow); + TSDB_CHECK_CODE(code, lino, _end); + code = getValidMemRow(&pBlockScanInfo->iiter, pDelList, pReader, &piRow); + TSDB_CHECK_CODE(code, lino, _end); - SRowKey* pSttKey = NULL; if (hasDataInSttBlock(pBlockScanInfo) && (!pBlockScanInfo->cleanSttBlocks)) { pSttKey = getCurrentKeyInSttBlock(pSttBlockReader); } @@ -2169,24 +2555,18 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo* STSchema* pSchema = NULL; if (pRow->type == TSDBROW_ROW_FMT) { pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid); - if (pSchema == NULL) { - return terrno; - } + TSDB_CHECK_NULL(pSchema, code, lino, _end, terrno); } STSchema* piSchema = NULL; if (piRow->type == TSDBROW_ROW_FMT) { piSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(piRow), pReader, pBlockScanInfo->uid); - if (piSchema == NULL) { - return terrno; - } + TSDB_CHECK_NULL(pSchema, code, lino, _end, terrno); } // merge is not initialized yet, due to the fact that the pReader->info.pSchema is not initialized code = initRowMergeIfNeeded(pReader, pBlockScanInfo->uid); - if (code != 0) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); SRowKey minKey = k; if (ASCENDING_TRAVERSE(pReader->info.order)) { @@ -2221,72 +2601,70 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo* if (pkCompEx(&minKey, pfKey) == 0) { TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex); code = tsdbRowMergerAdd(pMerger, &fRow, NULL); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pfKey, pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } if (pkCompEx(&minKey, pSttKey) == 0) { TSDBROW* pRow1 = tMergeTreeGetRow(&pSttBlockReader->mergeTree); code = tsdbRowMergerAdd(pMerger, pRow1, NULL); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); - code = doMergeRowsInSttBlock(pSttBlockReader, pBlockScanInfo, pMerger, pkSrcSlot, &pReader->info.verRange, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + code = doMergeRowsInSttBlock(pSttBlockReader, pBlockScanInfo, pMerger, pkSrcSlot, &pReader->info.verRange, + pReader->idStr); + TSDB_CHECK_CODE(code, lino, _end); } if (pkCompEx(&minKey, &ik) == 0) { code = tsdbRowMergerAdd(pMerger, piRow, piSchema); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, &ik, pBlockScanInfo->delSkyline, pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } if (pkCompEx(&minKey, &k) == 0) { code = tsdbRowMergerAdd(pMerger, pRow, pSchema); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = doMergeRowsInBuf(&pBlockScanInfo->iter, pBlockScanInfo->uid, &k, pBlockScanInfo->delSkyline, pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } code = tsdbRowMergerGetRow(pMerger, &pTSRow); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = doAppendRowFromTSRow(pReader->resBlockInfo.pResBlock, pReader, pTSRow, pBlockScanInfo); - taosMemoryFree(pTSRow); + taosMemoryFreeClear(pTSRow); tsdbRowMergerClear(pMerger); + TSDB_CHECK_CODE(code, lino, _end); + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } int32_t doInitMemDataIter(STsdbReader* pReader, STbData** pData, STableBlockScanInfo* pBlockScanInfo, STsdbRowKey* pKey, SMemTable* pMem, SIterInfo* pIter, const char* type) { int32_t code = TSDB_CODE_SUCCESS; - int32_t backward = (!ASCENDING_TRAVERSE(pReader->info.order)); + int32_t lino = 0; + int32_t backward = false; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pBlockScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pIter, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(type, code, lino, _end, TSDB_CODE_INVALID_PARA); + + backward = (!ASCENDING_TRAVERSE(pReader->info.order)); pIter->hasVal = false; if (pMem != NULL) { + TSDB_CHECK_NULL(pData, code, lino, _end, TSDB_CODE_INVALID_PARA); *pData = tsdbGetTbDataFromMemTable(pMem, pReader->info.suid, pBlockScanInfo->uid); if ((*pData) != NULL) { @@ -2301,23 +2679,30 @@ int32_t doInitMemDataIter(STsdbReader* pReader, STbData** pData, STableBlockScan } else { tsdbError("%p uid:%" PRIu64 ", failed to create iterator for %s, code:%s, %s", pReader, pBlockScanInfo->uid, type, tstrerror(code), pReader->idStr); - return code; + TSDB_CHECK_CODE(code, lino, _end); } } } else { tsdbDebug("%p uid:%" PRIu64 ", no data in %s, %s", pReader, pBlockScanInfo->uid, type, pReader->idStr); } +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } -static void doForwardDataIter(SRowKey* pKey, SIterInfo* pIter, STableBlockScanInfo* pBlockScanInfo, - STsdbReader* pReader) { - SRowKey rowKey = {0}; +static int32_t doForwardDataIter(SRowKey* pKey, SIterInfo* pIter, STableBlockScanInfo* pBlockScanInfo, + STsdbReader* pReader) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SRowKey rowKey = {0}; TSDBROW* pRow = NULL; while (1) { - getValidMemRow(pIter, pBlockScanInfo->delSkyline, pReader, &pRow); + code = getValidMemRow(pIter, pBlockScanInfo->delSkyline, pReader, &pRow); + TSDB_CHECK_CODE(code, lino, _end); if (!pIter->hasVal) { break; } @@ -2330,27 +2715,56 @@ static void doForwardDataIter(SRowKey* pKey, SIterInfo* pIter, STableBlockScanIn break; } } + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } // handle the open interval issue. Find the first row key that is greater than the given one. -static void forwardDataIter(SRowKey* pKey, STableBlockScanInfo* pBlockScanInfo, STsdbReader* pReader) { - doForwardDataIter(pKey, &pBlockScanInfo->iter, pBlockScanInfo, pReader); - doForwardDataIter(pKey, &pBlockScanInfo->iiter, pBlockScanInfo, pReader); +static int32_t forwardDataIter(SRowKey* pKey, STableBlockScanInfo* pBlockScanInfo, STsdbReader* pReader) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + + TSDB_CHECK_NULL(pKey, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pBlockScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + + code = doForwardDataIter(pKey, &pBlockScanInfo->iter, pBlockScanInfo, pReader); + TSDB_CHECK_CODE(code, lino, _end); + code = doForwardDataIter(pKey, &pBlockScanInfo->iiter, pBlockScanInfo, pReader); + TSDB_CHECK_CODE(code, lino, _end); + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static int32_t initMemDataIterator(STableBlockScanInfo* pBlockScanInfo, STsdbReader* pReader) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; STbData* d = NULL; STbData* di = NULL; - bool asc = ASCENDING_TRAVERSE(pReader->info.order); + bool asc = false; bool forward = true; - STsdbReadSnap* pSnap = pReader->pReadSnap; - STimeWindow* pWindow = &pReader->info.window; + STsdbReadSnap* pSnap = NULL; + STimeWindow* pWindow = NULL; + STsdbRowKey startKey; + + TSDB_CHECK_NULL(pBlockScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + asc = ASCENDING_TRAVERSE(pReader->info.order); + pSnap = pReader->pReadSnap; + pWindow = &pReader->info.window; if (pBlockScanInfo->iterInit) { - return TSDB_CODE_SUCCESS; + goto _end; } - STsdbRowKey startKey; startKey.key = pBlockScanInfo->lastProcKey; startKey.version = asc ? pReader->info.verRange.minVer : pReader->info.verRange.maxVer; if ((asc && (startKey.key.ts < pWindow->skey)) || ((!asc) && startKey.key.ts > pWindow->ekey)) { @@ -2358,80 +2772,114 @@ static int32_t initMemDataIterator(STableBlockScanInfo* pBlockScanInfo, STsdbRea forward = false; } - int32_t code = doInitMemDataIter(pReader, &d, pBlockScanInfo, &startKey, pSnap->pMem, &pBlockScanInfo->iter, "mem"); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + code = doInitMemDataIter(pReader, &d, pBlockScanInfo, &startKey, pSnap->pMem, &pBlockScanInfo->iter, "mem"); + TSDB_CHECK_CODE(code, lino, _end); code = doInitMemDataIter(pReader, &di, pBlockScanInfo, &startKey, pSnap->pIMem, &pBlockScanInfo->iiter, "imem"); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = loadMemTombData(&pBlockScanInfo->pMemDelData, d, di, pReader->info.verRange.maxVer); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if (forward) { - forwardDataIter(&startKey.key, pBlockScanInfo, pReader); + code = forwardDataIter(&startKey.key, pBlockScanInfo, pReader); + TSDB_CHECK_CODE(code, lino, _end); } pBlockScanInfo->iterInit = true; - return TSDB_CODE_SUCCESS; + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } -static bool isValidFileBlockRow(SBlockData* pBlockData, int32_t rowIndex, STableBlockScanInfo* pBlockScanInfo, bool asc, - STsdbReaderInfo* pInfo, STsdbReader* pReader) { +static int32_t isValidFileBlockRow(SBlockData* pBlockData, int32_t rowIndex, STableBlockScanInfo* pBlockScanInfo, + bool asc, STsdbReaderInfo* pInfo, STsdbReader* pReader, bool* valid) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + + TSDB_CHECK_NULL(pBlockData, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(valid, code, lino, _end, TSDB_CODE_INVALID_PARA); + + *valid = false; // it is an multi-table data block if (pBlockData->aUid != NULL) { uint64_t uid = pBlockData->aUid[rowIndex]; if (uid != pBlockScanInfo->uid) { // move to next row - return false; + *valid = false; + goto _end; } } + TSDB_CHECK_NULL(pInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); // check for version and time range int64_t ver = pBlockData->aVersion[rowIndex]; if (ver > pInfo->verRange.maxVer || ver < pInfo->verRange.minVer) { - return false; + *valid = false; + goto _end; } int64_t ts = pBlockData->aTSKEY[rowIndex]; if (ts > pInfo->window.ekey || ts < pInfo->window.skey) { - return false; + *valid = false; + goto _end; } + TSDB_CHECK_NULL(pBlockScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); if ((asc && (ts < pBlockScanInfo->lastProcKey.ts)) || ((!asc) && (ts > pBlockScanInfo->lastProcKey.ts))) { - return false; + *valid = false; + goto _end; } if (ts == pBlockScanInfo->lastProcKey.ts) { // todo opt perf SRowKey nextRowKey; // lazy eval tColRowGetKey(pBlockData, rowIndex, &nextRowKey); if (pkCompEx(&pBlockScanInfo->lastProcKey, &nextRowKey) == 0) { - return false; + *valid = false; + goto _end; } } if (pBlockScanInfo->delSkyline != NULL && TARRAY_SIZE(pBlockScanInfo->delSkyline) > 0) { - bool dropped = hasBeenDropped(pBlockScanInfo->delSkyline, &pBlockScanInfo->fileDelIndex, ts, ver, pInfo->order, - &pInfo->verRange, pReader->suppInfo.numOfPks > 0); + bool dropped = false; + code = hasBeenDropped(pBlockScanInfo->delSkyline, &pBlockScanInfo->fileDelIndex, ts, ver, pInfo->order, + &pInfo->verRange, pReader->suppInfo.numOfPks > 0, &dropped); + TSDB_CHECK_CODE(code, lino, _end); if (dropped) { - return false; + *valid = false; + goto _end; } } - return true; + *valid = true; + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static void initSttBlockReader(SSttBlockReader* pSttBlockReader, STableBlockScanInfo* pScanInfo, STsdbReader* pReader) { - int32_t order = pReader->info.order; - bool asc = ASCENDING_TRAVERSE(order); + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + int32_t order = 0; + bool asc = false; + int64_t st = 0; + SSttDataInfoForTable info = (SSttDataInfoForTable){0}; + + TSDB_CHECK_NULL(pSttBlockReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + order = pReader->info.order; + asc = ASCENDING_TRAVERSE(order); // the stt block reader has been initialized for this table. if (pSttBlockReader->uid == pScanInfo->uid) { - return; + goto _end; } if (pSttBlockReader->uid != 0) { @@ -2447,7 +2895,7 @@ static void initSttBlockReader(SSttBlockReader* pSttBlockReader, STableBlockScan pScanInfo->sttKeyInfo.status = STT_FILE_NO_DATA; tsdbDebug("uid:%" PRIu64 " set no stt-file data after stt-block retrieved, %s", pScanInfo->uid, pReader->idStr); } - return; + goto _end; } STimeWindow w = pSttBlockReader->window; @@ -2457,7 +2905,7 @@ static void initSttBlockReader(SSttBlockReader* pSttBlockReader, STableBlockScan w.ekey = pScanInfo->sttKeyInfo.nextProcKey.ts; } - int64_t st = taosGetTimestampUs(); + st = taosGetTimestampUs(); tsdbDebug("init stt block reader, window:%" PRId64 "-%" PRId64 ", uid:%" PRIu64 ", %s", w.skey, w.ekey, pScanInfo->uid, pReader->idStr); @@ -2481,32 +2929,17 @@ static void initSttBlockReader(SSttBlockReader* pSttBlockReader, STableBlockScan .rspRows = (pReader->info.execMode == READER_EXEC_ROWS), }; - SSttDataInfoForTable info = {.pKeyRangeList = taosArrayInit(4, sizeof(SSttKeyRange))}; - if (info.pKeyRangeList == NULL) { - pReader->code = terrno; - return; - } + info.pKeyRangeList = taosArrayInit(4, sizeof(SSttKeyRange)); + TSDB_CHECK_NULL(info.pKeyRangeList, code, lino, _end, terrno); - int32_t code = tMergeTreeOpen2(&pSttBlockReader->mergeTree, &conf, &info); - if (code != TSDB_CODE_SUCCESS) { - taosArrayDestroy(info.pKeyRangeList); - pReader->code = code; - return; - } + code = tMergeTreeOpen2(&pSttBlockReader->mergeTree, &conf, &info); + TSDB_CHECK_CODE(code, lino, _end); code = initMemDataIterator(pScanInfo, pReader); - if (code != TSDB_CODE_SUCCESS) { - taosArrayDestroy(info.pKeyRangeList); - pReader->code = code; - return; - } + TSDB_CHECK_CODE(code, lino, _end); code = initDelSkylineIterator(pScanInfo, pReader->info.order, &pReader->cost); - if (code != TSDB_CODE_SUCCESS) { - taosArrayDestroy(info.pKeyRangeList); - pReader->code = code; - return; - } + TSDB_CHECK_CODE(code, lino, _end); if (conf.rspRows) { pScanInfo->cleanSttBlocks = isCleanSttBlock(info.pKeyRangeList, &pReader->info.window, pScanInfo, order); @@ -2536,23 +2969,35 @@ static void initSttBlockReader(SSttBlockReader* pSttBlockReader, STableBlockScan } else { // not clean stt blocks INIT_KEYRANGE(&pScanInfo->sttRange); // reset the time window code = nextRowFromSttBlocks(pSttBlockReader, pScanInfo, pReader->suppInfo.pkSrcSlot, &pReader->info.verRange); + if (code != TSDB_CODE_SUCCESS) { + pScanInfo->sttBlockReturned = false; + TSDB_CHECK_CODE(code, lino, _end); + } } } else { pScanInfo->cleanSttBlocks = false; INIT_KEYRANGE(&pScanInfo->sttRange); // reset the time window code = nextRowFromSttBlocks(pSttBlockReader, pScanInfo, pReader->suppInfo.pkSrcSlot, &pReader->info.verRange); + if (code != TSDB_CODE_SUCCESS) { + pScanInfo->sttBlockReturned = false; + TSDB_CHECK_CODE(code, lino, _end); + } } pScanInfo->sttBlockReturned = false; - taosArrayDestroy(info.pKeyRangeList); - int64_t el = taosGetTimestampUs() - st; pReader->cost.initSttBlockReader += (el / 1000.0); tsdbDebug("init stt block reader completed, elapsed time:%" PRId64 "us %s", el, pReader->idStr); - if (code != 0) { - pReader->code = code; + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + if (pReader) { + pReader->code = code; + } } + taosArrayDestroy(info.pKeyRangeList); } static bool hasDataInSttBlock(STableBlockScanInfo* pInfo) { return pInfo->sttKeyInfo.status == STT_FILE_HAS_DATA; } @@ -2566,57 +3011,71 @@ bool hasDataInFileBlock(const SBlockData* pBlockData, const SFileBlockDumpInfo* int32_t mergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pBlockScanInfo, SRowKey* pKey, STsdbReader* pReader) { - SRowMerger* pMerger = &pReader->status.merger; - SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SRow* pTSRow = NULL; + SRowMerger* pMerger = NULL; + SFileBlockDumpInfo* pDumpInfo = NULL; bool copied = false; - int32_t code = tryCopyDistinctRowFromFileBlock(pReader, pBlockData, pKey, pDumpInfo, &copied); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_NULL(pBlockScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pKey, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pMerger = &pReader->status.merger; + pDumpInfo = &pReader->status.fBlockDumpInfo; + + code = tryCopyDistinctRowFromFileBlock(pReader, pBlockData, pKey, pDumpInfo, &copied); + TSDB_CHECK_CODE(code, lino, _end); // merge is not initialized yet, due to the fact that the pReader->info.pSchema is not initialized code = initRowMergeIfNeeded(pReader, pBlockScanInfo->uid); - if (code != 0) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); tRowKeyAssign(&pBlockScanInfo->lastProcKey, pKey); if (copied) { - return TSDB_CODE_SUCCESS; - } else { - TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex); - - SRow* pTSRow = NULL; - code = tsdbRowMergerAdd(pMerger, &fRow, NULL); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - - code = doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pKey, pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - - code = tsdbRowMergerGetRow(pMerger, &pTSRow); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - - code = doAppendRowFromTSRow(pReader->resBlockInfo.pResBlock, pReader, pTSRow, pBlockScanInfo); - - taosMemoryFree(pTSRow); - tsdbRowMergerClear(pMerger); - return code; + goto _end; } + + TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex); + + code = tsdbRowMergerAdd(pMerger, &fRow, NULL); + TSDB_CHECK_CODE(code, lino, _end); + + code = doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pKey, pReader); + TSDB_CHECK_CODE(code, lino, _end); + + code = tsdbRowMergerGetRow(pMerger, &pTSRow); + TSDB_CHECK_CODE(code, lino, _end); + + code = doAppendRowFromTSRow(pReader->resBlockInfo.pResBlock, pReader, pTSRow, pBlockScanInfo); + + taosMemoryFreeClear(pTSRow); + tsdbRowMergerClear(pMerger); + TSDB_CHECK_CODE(code, lino, _end); + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } int32_t mergeRowsInSttBlocks(SSttBlockReader* pSttBlockReader, STableBlockScanInfo* pScanInfo, STsdbReader* pReader) { - bool copied = false; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; SRow* pTSRow = NULL; - int32_t pkSrcSlot = pReader->suppInfo.pkSrcSlot; - SRowMerger* pMerger = &pReader->status.merger; + int32_t pkSrcSlot = 0; + SRowMerger* pMerger = NULL; + bool copied = false; + + TSDB_CHECK_NULL(pSttBlockReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pkSrcSlot = pReader->suppInfo.pkSrcSlot; + pMerger = &pReader->status.merger; // let's record the last processed key tRowKeyAssign(&pScanInfo->lastProcKey, getCurrentKeyInSttBlock(pSttBlockReader)); @@ -2630,51 +3089,54 @@ int32_t mergeRowsInSttBlocks(SSttBlockReader* pSttBlockReader, STableBlockScanIn pReader->idStr); } - int32_t code = - tryCopyDistinctRowFromSttBlock(&fRow, pSttBlockReader, pScanInfo, &pScanInfo->lastProcKey, pReader, &copied); - if (code) { - return code; - } + code = tryCopyDistinctRowFromSttBlock(&fRow, pSttBlockReader, pScanInfo, &pScanInfo->lastProcKey, pReader, &copied); + TSDB_CHECK_CODE(code, lino, _end); if (copied) { - return TSDB_CODE_SUCCESS; - } else { - code = tsdbRowMergerAdd(pMerger, &fRow, NULL); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - - TSDBROW* pRow1 = tMergeTreeGetRow(&pSttBlockReader->mergeTree); - code = tsdbRowMergerAdd(pMerger, pRow1, NULL); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - - code = doMergeRowsInSttBlock(pSttBlockReader, pScanInfo, pMerger, pkSrcSlot, &pReader->info.verRange, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - - code = tsdbRowMergerGetRow(pMerger, &pTSRow); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - - code = doAppendRowFromTSRow(pReader->resBlockInfo.pResBlock, pReader, pTSRow, pScanInfo); - - taosMemoryFree(pTSRow); - tsdbRowMergerClear(pMerger); - return code; + goto _end; } + + code = tsdbRowMergerAdd(pMerger, &fRow, NULL); + TSDB_CHECK_CODE(code, lino, _end); + + TSDBROW* pRow1 = tMergeTreeGetRow(&pSttBlockReader->mergeTree); + code = tsdbRowMergerAdd(pMerger, pRow1, NULL); + TSDB_CHECK_CODE(code, lino, _end); + + code = doMergeRowsInSttBlock(pSttBlockReader, pScanInfo, pMerger, pkSrcSlot, &pReader->info.verRange, pReader->idStr); + TSDB_CHECK_CODE(code, lino, _end); + + code = tsdbRowMergerGetRow(pMerger, &pTSRow); + TSDB_CHECK_CODE(code, lino, _end); + + code = doAppendRowFromTSRow(pReader->resBlockInfo.pResBlock, pReader, pTSRow, pScanInfo); + + taosMemoryFreeClear(pTSRow); + tsdbRowMergerClear(pMerger); + TSDB_CHECK_CODE(code, lino, _end); + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static int32_t buildComposedDataBlockImpl(STsdbReader* pReader, STableBlockScanInfo* pBlockScanInfo, SBlockData* pBlockData, SSttBlockReader* pSttBlockReader) { - SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SFileBlockDumpInfo* pDumpInfo = NULL; + TSDBROW* pRow = NULL; + TSDBROW* piRow = NULL; + SRowKey* pKey = &(SRowKey){0}; - TSDBROW *pRow = NULL, *piRow = NULL; + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pBlockScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pBlockData, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pDumpInfo = &pReader->status.fBlockDumpInfo; - SRowKey* pKey = &(SRowKey){0}; if (hasDataInFileBlock(pBlockData, pDumpInfo)) { tColRowGetKey(pBlockData, pDumpInfo->rowIndex, pKey); } else { @@ -2682,46 +3144,65 @@ static int32_t buildComposedDataBlockImpl(STsdbReader* pReader, STableBlockScanI } if (pBlockScanInfo->iter.hasVal) { - getValidMemRow(&pBlockScanInfo->iter, pBlockScanInfo->delSkyline, pReader, &pRow); + code = getValidMemRow(&pBlockScanInfo->iter, pBlockScanInfo->delSkyline, pReader, &pRow); + TSDB_CHECK_CODE(code, lino, _end); } if (pBlockScanInfo->iiter.hasVal) { - getValidMemRow(&pBlockScanInfo->iiter, pBlockScanInfo->delSkyline, pReader, &piRow); + code = getValidMemRow(&pBlockScanInfo->iiter, pBlockScanInfo->delSkyline, pReader, &piRow); + TSDB_CHECK_CODE(code, lino, _end); } - // two levels of mem-table does contain the valid rows if (pRow != NULL && piRow != NULL) { - return doMergeMultiLevelRows(pReader, pBlockScanInfo, pBlockData, pSttBlockReader); + // two levels of mem-table does contain the valid rows + code = doMergeMultiLevelRows(pReader, pBlockScanInfo, pBlockData, pSttBlockReader); + TSDB_CHECK_CODE(code, lino, _end); + } else if (pBlockScanInfo->iiter.hasVal) { + // imem + file + stt block + code = doMergeBufAndFileRows(pReader, pBlockScanInfo, piRow, &pBlockScanInfo->iiter, pSttBlockReader); + TSDB_CHECK_CODE(code, lino, _end); + } else if (pBlockScanInfo->iter.hasVal) { + // mem + file + stt block + code = doMergeBufAndFileRows(pReader, pBlockScanInfo, pRow, &pBlockScanInfo->iter, pSttBlockReader); + TSDB_CHECK_CODE(code, lino, _end); + } else { + // files data blocks + stt block + code = mergeFileBlockAndSttBlock(pReader, pSttBlockReader, pKey, pBlockScanInfo, pBlockData); + TSDB_CHECK_CODE(code, lino, _end); } - // imem + file + stt block - if (pBlockScanInfo->iiter.hasVal) { - return doMergeBufAndFileRows(pReader, pBlockScanInfo, piRow, &pBlockScanInfo->iiter, pSttBlockReader); +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); } - - // mem + file + stt block - if (pBlockScanInfo->iter.hasVal) { - return doMergeBufAndFileRows(pReader, pBlockScanInfo, pRow, &pBlockScanInfo->iter, pSttBlockReader); - } - - // files data blocks + stt block - return mergeFileBlockAndSttBlock(pReader, pSttBlockReader, pKey, pBlockScanInfo, pBlockData); + return code; } static int32_t loadNeighborIfOverlap(SFileDataBlockInfo* pBlockInfo, STableBlockScanInfo* pBlockScanInfo, STsdbReader* pReader, bool* loadNeighbor) { int32_t code = TSDB_CODE_SUCCESS; - int32_t order = pReader->info.order; - SDataBlockIter* pIter = &pReader->status.blockIter; - SBlockLoadSuppInfo* pSupInfo = &pReader->suppInfo; - int32_t step = ASCENDING_TRAVERSE(order) ? 1 : -1; + int32_t lino = 0; + int32_t order = 0; + SDataBlockIter* pIter = NULL; + SBlockLoadSuppInfo* pSupInfo = NULL; + int32_t step = 0; int32_t nextIndex = -1; SBrinRecord rec = {0}; + bool hasNeighbor = false; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(loadNeighbor, code, lino, _end, TSDB_CODE_INVALID_PARA); + + order = pReader->info.order; + pIter = &pReader->status.blockIter; + pSupInfo = &pReader->suppInfo; + step = ASCENDING_TRAVERSE(order) ? 1 : -1; *loadNeighbor = false; - bool hasNeighbor = getNeighborBlockOfTable(pIter, pBlockInfo, pBlockScanInfo, &nextIndex, order, &rec, pSupInfo); + code = getNeighborBlockOfTable(pIter, pBlockInfo, pBlockScanInfo, &nextIndex, order, &rec, pSupInfo, &hasNeighbor); + TSDB_CHECK_CODE(code, lino, _end); if (!hasNeighbor) { // do nothing - return code; + goto _end; } // load next block @@ -2731,28 +3212,27 @@ static int32_t loadNeighborIfOverlap(SFileDataBlockInfo* pBlockInfo, STableBlock // 1. find the next neighbor block in the scan block list STableDataBlockIdx* tableDataBlockIdx = taosArrayGet(pBlockScanInfo->pBlockIdxList, nextIndex); - if (tableDataBlockIdx == NULL) { - return TSDB_CODE_INVALID_PARA; - } + TSDB_CHECK_NULL(tableDataBlockIdx, code, lino, _end, TSDB_CODE_INVALID_PARA); // 2. remove it from the scan block list int32_t neighborIndex = tableDataBlockIdx->globalIndex; code = setFileBlockActiveInBlockIter(pReader, pBlockIter, neighborIndex, step); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); // 3. load the neighbor block, and set it to be the currently accessed file data block code = doLoadFileBlockData(pReader, pBlockIter, &pStatus->fileBlockData, pBlockInfo->uid); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); // 4. check the data values - initBlockDumpInfo(pReader, pBlockIter); + code = initBlockDumpInfo(pReader, pBlockIter); + TSDB_CHECK_CODE(code, lino, _end); *loadNeighbor = true; } +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } @@ -2772,15 +3252,27 @@ void updateComposedBlockInfo(STsdbReader* pReader, double el, STableBlockScanInf } static int32_t buildComposedDataBlock(STsdbReader* pReader) { - int32_t code = TSDB_CODE_SUCCESS; - bool asc = ASCENDING_TRAVERSE(pReader->info.order); - int64_t st = taosGetTimestampUs(); - int32_t step = asc ? 1 : -1; - double el = 0; - SSDataBlock* pResBlock = pReader->resBlockInfo.pResBlock; - SFileDataBlockInfo* pBlockInfo = NULL; - SSttBlockReader* pSttBlockReader = pReader->status.fileIter.pSttBlockReader; - SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + bool asc = false; + int64_t st = 0; + double el = 0; + int32_t step = 0; + SSDataBlock* pResBlock = NULL; + SFileDataBlockInfo* pBlockInfo = NULL; + SSttBlockReader* pSttBlockReader = NULL; + SFileBlockDumpInfo* pDumpInfo = NULL; + STableBlockScanInfo* pBlockScanInfo = NULL; + TSDBKEY keyInBuf; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + asc = ASCENDING_TRAVERSE(pReader->info.order); + st = taosGetTimestampUs(); + step = asc ? 1 : -1; + pResBlock = pReader->resBlockInfo.pResBlock; + pSttBlockReader = pReader->status.fileIter.pSttBlockReader; + pDumpInfo = &pReader->status.fBlockDumpInfo; code = getCurrentBlockInfo(&pReader->status.blockIter, &pBlockInfo, pReader->idStr); if (code != TSDB_CODE_SUCCESS) { @@ -2792,38 +3284,41 @@ static int32_t buildComposedDataBlock(STsdbReader* pReader) { return code; } - STableBlockScanInfo* pBlockScanInfo = NULL; code = getTableBlockScanInfo(pReader->status.pTableMap, pBlockInfo->uid, &pBlockScanInfo, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - goto _end; - } + TSDB_CHECK_CODE(code, lino, _end); - TSDBKEY keyInBuf = getCurrentKeyInBuf(pBlockScanInfo, pReader); + code = getCurrentKeyInBuf(pBlockScanInfo, pReader, &keyInBuf); + TSDB_CHECK_CODE(code, lino, _end); // it is a clean block, load it directly int64_t cap = pReader->resBlockInfo.capacity; - bool directCopy = isCleanFileDataBlock(pReader, pBlockInfo, pBlockScanInfo, keyInBuf) && - (pBlockInfo->numRow <= cap) && (pBlockScanInfo->sttKeyInfo.status == STT_FILE_NO_DATA) && + bool isClean = false; + code = isCleanFileDataBlock(pReader, pBlockInfo, pBlockScanInfo, keyInBuf, &isClean); + TSDB_CHECK_CODE(code, lino, _end); + bool directCopy = isClean && (pBlockInfo->numRow <= cap) && (pBlockScanInfo->sttKeyInfo.status == STT_FILE_NO_DATA) && ((asc && ((pBlockInfo->lastKey < keyInBuf.ts) || (keyInBuf.ts == INT64_MIN))) || (!asc && (pBlockInfo->lastKey > keyInBuf.ts))); if (directCopy) { code = copyBlockDataToSDataBlock(pReader, &pBlockScanInfo->lastProcKey); + TSDB_CHECK_CODE(code, lino, _end); goto _end; } SBlockData* pBlockData = &pReader->status.fileBlockData; initSttBlockReader(pSttBlockReader, pBlockScanInfo, pReader); - if (pReader->code != 0) { - code = pReader->code; - goto _end; - } + code = pReader->code; + TSDB_CHECK_CODE(code, lino, _end); while (1) { bool hasBlockData = false; { while (pBlockData->nRow > 0 && pBlockData->uid == pBlockScanInfo->uid) { // find the first qualified row in data block - if (isValidFileBlockRow(pBlockData, pDumpInfo->rowIndex, pBlockScanInfo, asc, &pReader->info, pReader)) { + bool valid = false; + code = + isValidFileBlockRow(pBlockData, pDumpInfo->rowIndex, pBlockScanInfo, asc, &pReader->info, pReader, &valid); + TSDB_CHECK_CODE(code, lino, _end); + if (valid) { hasBlockData = true; break; } @@ -2833,15 +3328,14 @@ static int32_t buildComposedDataBlock(STsdbReader* pReader) { if (pDumpInfo->rowIndex >= pBlockData->nRow || pDumpInfo->rowIndex < 0) { // NOTE: get the new block info code = getCurrentBlockInfo(&pReader->status.blockIter, &pBlockInfo, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - goto _end; - } + TSDB_CHECK_CODE(code, lino, _end); // continue check for the next file block if the last ts in the current block // is overlapped with the next neighbor block bool loadNeighbor = false; code = loadNeighborIfOverlap(pBlockInfo, pBlockScanInfo, pReader, &loadNeighbor); if ((!loadNeighbor) || (code != 0)) { + lino = __LINE__; setBlockAllDumped(pDumpInfo, pBlockInfo->lastKey, pReader->info.order); break; } @@ -2855,9 +3349,7 @@ static int32_t buildComposedDataBlock(STsdbReader* pReader) { } code = buildComposedDataBlockImpl(pReader, pBlockScanInfo, pBlockData, pSttBlockReader); - if (code) { - goto _end; - } + TSDB_CHECK_CODE(code, lino, _end); // currently loaded file data block is consumed if ((pBlockData->nRow > 0) && (pDumpInfo->rowIndex >= pBlockData->nRow || pDumpInfo->rowIndex < 0)) { @@ -2871,16 +3363,21 @@ static int32_t buildComposedDataBlock(STsdbReader* pReader) { } _end: - el = (taosGetTimestampUs() - st) / 1000.0; - updateComposedBlockInfo(pReader, el, pBlockScanInfo); + if (pReader) { + el = (taosGetTimestampUs() - st) / 1000.0; + updateComposedBlockInfo(pReader, el, pBlockScanInfo); + } - if (pResBlock->info.rows > 0) { + if (pResBlock && pResBlock->info.rows > 0) { tsdbDebug("%p uid:%" PRIu64 ", composed data block created, brange:%" PRIu64 "-%" PRIu64 " rows:%" PRId64 ", elapsed time:%.2f ms %s", pReader, pResBlock->info.id.uid, pResBlock->info.window.skey, pResBlock->info.window.ekey, pResBlock->info.rows, el, pReader->idStr); } + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } @@ -2895,32 +3392,35 @@ int32_t getInitialDelIndex(const SArray* pDelSkyline, int32_t order) { } int32_t initDelSkylineIterator(STableBlockScanInfo* pBlockScanInfo, int32_t order, SReadCostSummary* pCost) { - int32_t code = 0; - int32_t newDelDataInFile = taosArrayGetSize(pBlockScanInfo->pFileDelData); + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + int32_t newDelDataInFile = 0; + int64_t st = 0; + SArray* pSource = NULL; + + TSDB_CHECK_NULL(pBlockScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + + newDelDataInFile = taosArrayGetSize(pBlockScanInfo->pFileDelData); if (newDelDataInFile == 0 && ((pBlockScanInfo->delSkyline != NULL) || (TARRAY_SIZE(pBlockScanInfo->pMemDelData) == 0))) { - return code; + goto _end; } - int64_t st = taosGetTimestampUs(); + st = taosGetTimestampUs(); if (pBlockScanInfo->delSkyline != NULL) { taosArrayClear(pBlockScanInfo->delSkyline); } else { pBlockScanInfo->delSkyline = taosArrayInit(4, sizeof(TSDBKEY)); - if (pBlockScanInfo->delSkyline == NULL) { - return terrno; - } + TSDB_CHECK_NULL(pBlockScanInfo->delSkyline, code, lino, _end, terrno); } - SArray* pSource = pBlockScanInfo->pFileDelData; + pSource = pBlockScanInfo->pFileDelData; if (pSource == NULL) { pSource = pBlockScanInfo->pMemDelData; } else { - void* p1 = taosArrayAddAll(pSource, pBlockScanInfo->pMemDelData); - if (p1 == NULL) { - return terrno; - } + const void* p1 = taosArrayAddAll(pSource, pBlockScanInfo->pMemDelData); + TSDB_CHECK_NULL(p1, code, lino, _end, terrno); } code = tsdbBuildDeleteSkyline(pSource, 0, taosArrayGetSize(pSource) - 1, pBlockScanInfo->delSkyline); @@ -2932,28 +3432,45 @@ int32_t initDelSkylineIterator(STableBlockScanInfo* pBlockScanInfo, int32_t orde pBlockScanInfo->iiter.index = index; pBlockScanInfo->fileDelIndex = index; pBlockScanInfo->sttBlockDelIndex = index; + TSDB_CHECK_CODE(code, lino, _end); + TSDB_CHECK_NULL(pCost, code, lino, _end, TSDB_CODE_INVALID_PARA); double el = taosGetTimestampUs() - st; pCost->createSkylineIterTime = el / 1000.0; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } -TSDBKEY getCurrentKeyInBuf(STableBlockScanInfo* pScanInfo, STsdbReader* pReader) { - bool asc = ASCENDING_TRAVERSE(pReader->info.order); - TSDBKEY key = {.ts = TSKEY_INITIAL_VAL}, ikey = {.ts = TSKEY_INITIAL_VAL}; - - bool hasKey = false, hasIKey = false; +int32_t getCurrentKeyInBuf(STableBlockScanInfo* pScanInfo, STsdbReader* pReader, TSDBKEY* pkey) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + bool asc = false; + bool hasKey = false; + bool hasIKey = false; TSDBROW* pRow = NULL; TSDBROW* pIRow = NULL; + TSDBKEY key = {.ts = TSKEY_INITIAL_VAL}; + TSDBKEY ikey = {.ts = TSKEY_INITIAL_VAL}; - getValidMemRow(&pScanInfo->iter, pScanInfo->delSkyline, pReader, &pRow); + TSDB_CHECK_NULL(pScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pkey, code, lino, _end, TSDB_CODE_INVALID_PARA); + + asc = ASCENDING_TRAVERSE(pReader->info.order); + + code = getValidMemRow(&pScanInfo->iter, pScanInfo->delSkyline, pReader, &pRow); + TSDB_CHECK_CODE(code, lino, _end); if (pRow != NULL) { hasKey = true; key = TSDBROW_KEY(pRow); } - getValidMemRow(&pScanInfo->iiter, pScanInfo->delSkyline, pReader, &pIRow); + code = getValidMemRow(&pScanInfo->iiter, pScanInfo->delSkyline, pReader, &pIRow); + TSDB_CHECK_CODE(code, lino, _end); if (pIRow != NULL) { hasIKey = true; ikey = TSDBROW_KEY(pIRow); @@ -2962,18 +3479,24 @@ TSDBKEY getCurrentKeyInBuf(STableBlockScanInfo* pScanInfo, STsdbReader* pReader) if (hasKey) { if (hasIKey) { // has data in mem & imem if (asc) { - return key.ts <= ikey.ts ? key : ikey; + *pkey = key.ts <= ikey.ts ? key : ikey; } else { - return key.ts <= ikey.ts ? ikey : key; + *pkey = key.ts <= ikey.ts ? ikey : key; } } else { // no data in imem - return key; + *pkey = key; } } else { // no data in mem & imem, return the initial value // only imem has data, return ikey - return ikey; + *pkey = ikey; } + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static void prepareDurationForNextFileSet(STsdbReader* pReader) { @@ -3015,29 +3538,34 @@ static void prepareDurationForNextFileSet(STsdbReader* pReader) { } static int32_t moveToNextFile(STsdbReader* pReader, SBlockNumber* pBlockNum, SArray* pTableList) { - SReaderStatus* pStatus = &pReader->status; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SReaderStatus* pStatus = NULL; + SArray* pIndexList = NULL; + size_t numOfTables = 0; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pBlockNum, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pStatus = &pReader->status; pBlockNum->numOfBlocks = 0; pBlockNum->numOfSttFiles = 0; - size_t numOfTables = tSimpleHashGetSize(pReader->status.pTableMap); - SArray* pIndexList = taosArrayInit(numOfTables, sizeof(SBrinBlk)); - if (pIndexList == NULL) { - return terrno; - } + numOfTables = tSimpleHashGetSize(pReader->status.pTableMap); + pIndexList = taosArrayInit(numOfTables, sizeof(SBrinBlk)); + TSDB_CHECK_NULL(pIndexList, code, lino, _end, terrno); while (1) { // only check here, since the iterate data in memory is very fast. if (pReader->code != TSDB_CODE_SUCCESS) { tsdbWarn("tsdb reader is stopped ASAP, code:%s, %s", tstrerror(pReader->code), pReader->idStr); - return pReader->code; + code = pReader->code; + TSDB_CHECK_CODE(code, lino, _end); } - bool hasNext = false; - int32_t code = filesetIteratorNext(&pStatus->fileIter, pReader, &hasNext); - if (code != TSDB_CODE_SUCCESS) { - taosArrayDestroy(pIndexList); - return code; - } + bool hasNext = false; + code = filesetIteratorNext(&pStatus->fileIter, pReader, &hasNext); + TSDB_CHECK_CODE(code, lino, _end); if (!hasNext) { // no data files on disk break; @@ -3045,17 +3573,11 @@ static int32_t moveToNextFile(STsdbReader* pReader, SBlockNumber* pBlockNum, SAr taosArrayClear(pIndexList); code = doLoadBlockIndex(pReader, pReader->pFileReader, pIndexList); - if (code != TSDB_CODE_SUCCESS) { - taosArrayDestroy(pIndexList); - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if (taosArrayGetSize(pIndexList) > 0 || pReader->status.pCurrentFileset->lvlArr->size > 0) { code = loadFileBlockBrinInfo(pReader, pIndexList, pBlockNum, pTableList); - if (code != TSDB_CODE_SUCCESS) { - taosArrayDestroy(pIndexList); - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if (pBlockNum->numOfBlocks + pBlockNum->numOfSttFiles > 0) { if (pReader->bFilesetDelimited) { @@ -3068,23 +3590,42 @@ static int32_t moveToNextFile(STsdbReader* pReader, SBlockNumber* pBlockNum, SAr // no blocks in current file, try next files } - taosArrayDestroy(pIndexList); - return loadDataFileTombDataForAll(pReader); + code = loadDataFileTombDataForAll(pReader); + TSDB_CHECK_CODE(code, lino, _end); + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + if (pIndexList) { + taosArrayDestroy(pIndexList); + } + return code; } // pTableIter can be NULL, no need to handle the return value static int32_t resetTableListIndex(SReaderStatus* pStatus, const char* id) { - STableUidList* pList = &pStatus->uidList; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + STableUidList* pList = NULL; + + TSDB_CHECK_NULL(pStatus, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pList = &pStatus->uidList; pList->currentIndex = 0; uint64_t uid = pList->tableUidList[0]; pStatus->pTableIter = tSimpleHashGet(pStatus->pTableMap, &uid, sizeof(uid)); if (pStatus->pTableIter == NULL) { - tsdbError("%s failed to load tableBlockScanInfo for uid:%"PRId64", code: internal error", id, uid); - return TSDB_CODE_INTERNAL_ERROR; + tsdbError("%s failed to load tableBlockScanInfo for uid:%" PRId64 ", code: internal error", id, uid); + TSDB_CHECK_NULL(pStatus->pTableIter, code, lino, _end, TSDB_CODE_INTERNAL_ERROR); } - return 0; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static void resetPreFilesetMemTableListIndex(SReaderStatus* pStatus) { @@ -3121,18 +3662,26 @@ static bool moveToNextTableForPreFileSetMem(SReaderStatus* pStatus) { } static int32_t buildCleanBlockFromSttFiles(STsdbReader* pReader, STableBlockScanInfo* pScanInfo) { - SReaderStatus* pStatus = &pReader->status; - SSttBlockReader* pSttBlockReader = pStatus->fileIter.pSttBlockReader; - SSDataBlock* pResBlock = pReader->resBlockInfo.pResBlock; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SReaderStatus* pStatus = NULL; + SSttBlockReader* pSttBlockReader = NULL; + SSDataBlock* pResBlock = NULL; + SDataBlockInfo* pInfo = NULL; + bool asc = false; - bool asc = ASCENDING_TRAVERSE(pReader->info.order); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); - SDataBlockInfo* pInfo = &pResBlock->info; - int32_t code = blockDataEnsureCapacity(pResBlock, pScanInfo->numOfRowsInStt); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + pStatus = &pReader->status; + pSttBlockReader = pStatus->fileIter.pSttBlockReader; + pResBlock = pReader->resBlockInfo.pResBlock; + asc = ASCENDING_TRAVERSE(pReader->info.order); + code = blockDataEnsureCapacity(pResBlock, pScanInfo->numOfRowsInStt); + TSDB_CHECK_CODE(code, lino, _end); + + pInfo = &pResBlock->info; pInfo->rows = pScanInfo->numOfRowsInStt; pInfo->id.uid = pScanInfo->uid; pInfo->dataLoad = 1; @@ -3156,15 +3705,30 @@ static int32_t buildCleanBlockFromSttFiles(STsdbReader* pReader, STableBlockScan tsdbDebug("%p uid:%" PRId64 " return clean stt block as one, brange:%" PRId64 "-%" PRId64 " rows:%" PRId64 " %s", pReader, pResBlock->info.id.uid, pResBlock->info.window.skey, pResBlock->info.window.ekey, pResBlock->info.rows, pReader->idStr); + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } -static void buildCleanBlockFromDataFiles(STsdbReader* pReader, STableBlockScanInfo* pScanInfo, - SFileDataBlockInfo* pBlockInfo, int32_t blockIndex) { +static int32_t buildCleanBlockFromDataFiles(STsdbReader* pReader, STableBlockScanInfo* pScanInfo, + SFileDataBlockInfo* pBlockInfo, int32_t blockIndex) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SReaderStatus* pStatus = NULL; + SDataBlockInfo* pInfo = NULL; + bool asc = false; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pBlockInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + // whole data block is required, return it directly - SReaderStatus* pStatus = &pReader->status; - SDataBlockInfo* pInfo = &pReader->resBlockInfo.pResBlock->info; - bool asc = ASCENDING_TRAVERSE(pReader->info.order); + pStatus = &pReader->status; + pInfo = &pReader->resBlockInfo.pResBlock->info; + asc = ASCENDING_TRAVERSE(pReader->info.order); pInfo->rows = pBlockInfo->numRow; pInfo->id.uid = pScanInfo->uid; @@ -3188,66 +3752,81 @@ static void buildCleanBlockFromDataFiles(STsdbReader* pReader, STableBlockScanIn // update the last key for the corresponding table setComposedBlockFlag(pReader, false); setBlockAllDumped(&pStatus->fBlockDumpInfo, pBlockInfo->lastKey, pReader->info.order); - updateLastKeyInfo(&pScanInfo->lastProcKey, pBlockInfo, pInfo, pReader->suppInfo.numOfPks, asc); + code = updateLastKeyInfo(&pScanInfo->lastProcKey, pBlockInfo, pInfo, pReader->suppInfo.numOfPks, asc); + TSDB_CHECK_CODE(code, lino, _end); tsdbDebug("%p uid:%" PRIu64 " clean file block retrieved from file, global index:%d, " "table index:%d, rows:%d, brange:%" PRId64 "-%" PRId64 ", %s", pReader, pScanInfo->uid, blockIndex, pBlockInfo->tbBlockIdx, pBlockInfo->numRow, pBlockInfo->firstKey, pBlockInfo->lastKey, pReader->idStr); + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static int32_t doLoadSttBlockSequentially(STsdbReader* pReader) { - SReaderStatus* pStatus = &pReader->status; - SSttBlockReader* pSttBlockReader = pStatus->fileIter.pSttBlockReader; - STableUidList* pUidList = &pStatus->uidList; - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SReaderStatus* pStatus = NULL; + SSttBlockReader* pSttBlockReader = NULL; + STableUidList* pUidList = NULL; + SSDataBlock* pResBlock = NULL; + STableBlockScanInfo* pScanInfo = NULL; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pStatus = &pReader->status; + pSttBlockReader = pStatus->fileIter.pSttBlockReader; + pUidList = &pStatus->uidList; if (tSimpleHashGetSize(pStatus->pTableMap) == 0) { - return TSDB_CODE_SUCCESS; + goto _end; } - SSDataBlock* pResBlock = pReader->resBlockInfo.pResBlock; + pResBlock = pReader->resBlockInfo.pResBlock; while (1) { if (pReader->code != TSDB_CODE_SUCCESS) { tsdbWarn("tsdb reader is stopped ASAP, code:%s, %s", tstrerror(pReader->code), pReader->idStr); - return pReader->code; + code = pReader->code; + TSDB_CHECK_CODE(code, lino, _end); } // load the last data block of current table - STableBlockScanInfo* pScanInfo = NULL; if (pStatus->pTableIter == NULL) { tsdbError("table Iter is null, invalid pScanInfo, try next table %s", pReader->idStr); bool hasNexTable = moveToNextTable(pUidList, pStatus); if (!hasNexTable) { - return TSDB_CODE_SUCCESS; + break; } continue; } else { - pScanInfo = *(STableBlockScanInfo**) pStatus->pTableIter; + pScanInfo = *(STableBlockScanInfo**)pStatus->pTableIter; } if (pReader->pIgnoreTables && taosHashGet(*pReader->pIgnoreTables, &pScanInfo->uid, sizeof(pScanInfo->uid))) { // reset the index in last block when handing a new file bool hasNexTable = moveToNextTable(pUidList, pStatus); if (!hasNexTable) { - return TSDB_CODE_SUCCESS; + break; } continue; } initSttBlockReader(pSttBlockReader, pScanInfo, pReader); - if (pReader->code != TSDB_CODE_SUCCESS) { - return pReader->code; - } - + code = pReader->code; + TSDB_CHECK_CODE(code, lino, _end); + if (!hasDataInSttBlock(pScanInfo)) { bool hasNexTable = moveToNextTable(pUidList, pStatus); if (!hasNexTable) { - return TSDB_CODE_SUCCESS; + break; } continue; @@ -3256,7 +3835,8 @@ static int32_t doLoadSttBlockSequentially(STsdbReader* pReader) { // if only require the total rows, no need to load data from stt file if it is clean stt blocks if (pReader->info.execMode == READER_EXEC_ROWS && pScanInfo->cleanSttBlocks) { code = buildCleanBlockFromSttFiles(pReader, pScanInfo); - return code; + TSDB_CHECK_CODE(code, lino, _end); + break; } int64_t st = taosGetTimestampUs(); @@ -3267,9 +3847,7 @@ static int32_t doLoadSttBlockSequentially(STsdbReader* pReader) { } code = buildComposedDataBlockImpl(pReader, pScanInfo, &pReader->status.fileBlockData, pSttBlockReader); - if (code) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if (pResBlock->info.rows >= pReader->resBlockInfo.capacity) { break; @@ -3284,15 +3862,21 @@ static int32_t doLoadSttBlockSequentially(STsdbReader* pReader) { ", elapsed time:%.2f ms %s", pReader, pResBlock->info.id.uid, pResBlock->info.window.skey, pResBlock->info.window.ekey, pResBlock->info.rows, el, pReader->idStr); - return TSDB_CODE_SUCCESS; + break; } // current table is exhausted, let's try next table bool hasNexTable = moveToNextTable(pUidList, pStatus); if (!hasNexTable) { - return TSDB_CODE_SUCCESS; + break; } } + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } // current active data block not overlap with the stt-files/stt-blocks @@ -3306,54 +3890,61 @@ static bool notOverlapWithFiles(SFileDataBlockInfo* pBlockInfo, STableBlockScanI } static int32_t doBuildDataBlock(STsdbReader* pReader) { - SReaderStatus* pStatus = &pReader->status; - SDataBlockIter* pBlockIter = &pStatus->blockIter; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SReaderStatus* pStatus = NULL; + SDataBlockIter* pBlockIter = NULL; STableBlockScanInfo* pScanInfo = NULL; SFileDataBlockInfo* pBlockInfo = NULL; - SSttBlockReader* pSttBlockReader = pReader->status.fileIter.pSttBlockReader; - bool asc = ASCENDING_TRAVERSE(pReader->info.order); - int32_t code = TSDB_CODE_SUCCESS; + SSttBlockReader* pSttBlockReader = NULL; + TSDBKEY keyInBuf; + bool asc = false; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pStatus = &pReader->status; + pBlockIter = &pStatus->blockIter; + pSttBlockReader = pReader->status.fileIter.pSttBlockReader; + asc = ASCENDING_TRAVERSE(pReader->info.order); code = getCurrentBlockInfo(pBlockIter, &pBlockInfo, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if (pReader->pIgnoreTables && taosHashGet(*pReader->pIgnoreTables, &pBlockInfo->uid, sizeof(pBlockInfo->uid))) { setBlockAllDumped(&pStatus->fBlockDumpInfo, pBlockInfo->lastKey, pReader->info.order); - return code; + goto _end; } - if (pReader->code != TSDB_CODE_SUCCESS) { - return pReader->code; - } + code = pReader->code; + TSDB_CHECK_CODE(code, lino, _end); code = getTableBlockScanInfo(pReader->status.pTableMap, pBlockInfo->uid, &pScanInfo, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if (pScanInfo->sttKeyInfo.status == STT_FILE_READER_UNINIT) { initSttBlockReader(pSttBlockReader, pScanInfo, pReader); - if (pReader->code != 0) { - return pReader->code; - } + code = pReader->code; + TSDB_CHECK_CODE(code, lino, _end); } - TSDBKEY keyInBuf = getCurrentKeyInBuf(pScanInfo, pReader); - if (fileBlockShouldLoad(pReader, pBlockInfo, pScanInfo, keyInBuf)) { + code = getCurrentKeyInBuf(pScanInfo, pReader, &keyInBuf); + TSDB_CHECK_CODE(code, lino, _end); + bool load = false; + code = fileBlockShouldLoad(pReader, pBlockInfo, pScanInfo, keyInBuf, &load); + TSDB_CHECK_CODE(code, lino, _end); + if (load) { code = doLoadFileBlockData(pReader, pBlockIter, &pStatus->fileBlockData, pScanInfo->uid); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); // build composed data block code = buildComposedDataBlock(pReader); + TSDB_CHECK_CODE(code, lino, _end); } else if (bufferDataInFileBlockGap(keyInBuf, pBlockInfo, pScanInfo, pReader->info.order)) { // data in memory that are earlier than current file block and stt blocks // rows in buffer should be less than the file block in asc, greater than file block in desc int64_t endKey = getBoarderKeyInFiles(pBlockInfo, pScanInfo, pReader->info.order); code = buildDataBlockFromBuf(pReader, pScanInfo, endKey); + TSDB_CHECK_CODE(code, lino, _end); } else { if (notOverlapWithFiles(pBlockInfo, pScanInfo, asc)) { int64_t keyInStt = pScanInfo->sttKeyInfo.nextProcKey.ts; @@ -3362,14 +3953,13 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) { (!asc && pBlockInfo->firstKey > keyInStt)) { // the stt blocks may located in the gap of different data block, but the whole sttRange may overlap with the // data block, so the overlap check is invalid actually. - buildCleanBlockFromDataFiles(pReader, pScanInfo, pBlockInfo, pBlockIter->index); + code = buildCleanBlockFromDataFiles(pReader, pScanInfo, pBlockInfo, pBlockIter->index); + TSDB_CHECK_CODE(code, lino, _end); } else { // clean stt block - if (!(pReader->info.execMode == READER_EXEC_ROWS && pSttBlockReader->mergeTree.pIter == NULL)) { - tsdbError("tsdb reader failed at: %s:%d", __func__, __LINE__); - return TSDB_CODE_INTERNAL_ERROR; - } + TSDB_CHECK_CONDITION((pReader->info.execMode == READER_EXEC_ROWS) && (pSttBlockReader->mergeTree.pIter == NULL), + code, lino, _end, TSDB_CODE_INTERNAL_ERROR); code = buildCleanBlockFromSttFiles(pReader, pScanInfo); - return code; + TSDB_CHECK_CODE(code, lino, _end); } } else { SBlockData* pBData = &pReader->status.fileBlockData; @@ -3382,21 +3972,16 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) { // let's load data from stt files, make sure clear the cleanStt block flag before load the data from stt files initSttBlockReader(pSttBlockReader, pScanInfo, pReader); - if (pReader->code != 0) { - return pReader->code; - } + code = pReader->code; + TSDB_CHECK_CODE(code, lino, _end); // no data in stt block, no need to proceed. while (hasDataInSttBlock(pScanInfo)) { - if (pScanInfo->sttKeyInfo.status != STT_FILE_HAS_DATA) { - tsdbError("tsdb reader failed at: %s:%d", __func__, __LINE__); - return TSDB_CODE_INTERNAL_ERROR; - } + TSDB_CHECK_CONDITION(pScanInfo->sttKeyInfo.status == STT_FILE_HAS_DATA, code, lino, _end, + TSDB_CODE_INTERNAL_ERROR); code = buildComposedDataBlockImpl(pReader, pScanInfo, &pReader->status.fileBlockData, pSttBlockReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if (pResBlock->info.rows >= pReader->resBlockInfo.capacity) { break; @@ -3423,11 +4008,24 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) { } } - return (pReader->code != TSDB_CODE_SUCCESS) ? pReader->code : code; + code = pReader->code; + TSDB_CHECK_CODE(code, lino, _end); + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static int32_t buildBlockFromBufferSeqForPreFileset(STsdbReader* pReader, int64_t endKey) { - SReaderStatus* pStatus = &pReader->status; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SReaderStatus* pStatus = NULL; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pStatus = &pReader->status; tsdbDebug("seq load data blocks from cache that preceeds fileset %d, %s", pReader->status.pCurrentFileset->fid, pReader->idStr); @@ -3435,7 +4033,8 @@ static int32_t buildBlockFromBufferSeqForPreFileset(STsdbReader* pReader, int64_ while (1) { if (pReader->code != TSDB_CODE_SUCCESS) { tsdbWarn("tsdb reader is stopped ASAP, code:%s, %s", tstrerror(pReader->code), pReader->idStr); - return pReader->code; + code = pReader->code; + TSDB_CHECK_CODE(code, lino, _end); } STableBlockScanInfo** pBlockScanInfo = pStatus->pProcMemTableIter; @@ -3443,150 +4042,172 @@ static int32_t buildBlockFromBufferSeqForPreFileset(STsdbReader* pReader, int64_ taosHashGet(*pReader->pIgnoreTables, &(*pBlockScanInfo)->uid, sizeof((*pBlockScanInfo)->uid))) { bool hasNexTable = moveToNextTableForPreFileSetMem(pStatus); if (!hasNexTable) { - return TSDB_CODE_SUCCESS; + break; } continue; } - int32_t code = initMemDataIterator(*pBlockScanInfo, pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + code = initMemDataIterator(*pBlockScanInfo, pReader); + TSDB_CHECK_CODE(code, lino, _end); code = initDelSkylineIterator(*pBlockScanInfo, pReader->info.order, &pReader->cost); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = buildDataBlockFromBuf(pReader, *pBlockScanInfo, endKey); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if (pReader->resBlockInfo.pResBlock->info.rows > 0) { - return TSDB_CODE_SUCCESS; + break; } // current table is exhausted, let's try next table bool hasNexTable = moveToNextTableForPreFileSetMem(pStatus); if (!hasNexTable) { - return TSDB_CODE_SUCCESS; + break; } } + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static int32_t buildBlockFromBufferSequentially(STsdbReader* pReader, int64_t endKey) { - SReaderStatus* pStatus = &pReader->status; - STableUidList* pUidList = &pStatus->uidList; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SReaderStatus* pStatus = NULL; + STableUidList* pUidList = NULL; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pStatus = &pReader->status; + pUidList = &pStatus->uidList; tsdbDebug("seq load data blocks from cache, %s", pReader->idStr); while (1) { if (pReader->code != TSDB_CODE_SUCCESS) { tsdbWarn("tsdb reader is stopped ASAP, code:%s, %s", tstrerror(pReader->code), pReader->idStr); - return pReader->code; + code = pReader->code; + TSDB_CHECK_CODE(code, lino, _end); } STableBlockScanInfo** pBlockScanInfo = pStatus->pTableIter; if (pBlockScanInfo == NULL || *pBlockScanInfo == NULL) { - return TSDB_CODE_SUCCESS; + break; } if (pReader->pIgnoreTables && taosHashGet(*pReader->pIgnoreTables, &(*pBlockScanInfo)->uid, sizeof((*pBlockScanInfo)->uid))) { bool hasNexTable = moveToNextTable(pUidList, pStatus); if (!hasNexTable) { - return TSDB_CODE_SUCCESS; + break; } continue; } - int32_t code = initMemDataIterator(*pBlockScanInfo, pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + code = initMemDataIterator(*pBlockScanInfo, pReader); + TSDB_CHECK_CODE(code, lino, _end); code = initDelSkylineIterator(*pBlockScanInfo, pReader->info.order, &pReader->cost); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = buildDataBlockFromBuf(pReader, *pBlockScanInfo, endKey); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if (pReader->resBlockInfo.pResBlock->info.rows > 0) { - return TSDB_CODE_SUCCESS; + break; } // current table is exhausted, let's try next table bool hasNexTable = moveToNextTable(pUidList, pStatus); if (!hasNexTable) { - return TSDB_CODE_SUCCESS; + break; } } + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } // set the correct start position in case of the first/last file block, according to the query time window -static void initBlockDumpInfo(STsdbReader* pReader, SDataBlockIter* pBlockIter) { +static int32_t initBlockDumpInfo(STsdbReader* pReader, SDataBlockIter* pBlockIter) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; SFileDataBlockInfo* pBlockInfo = NULL; - SReaderStatus* pStatus = &pReader->status; - SFileBlockDumpInfo* pDumpInfo = &pStatus->fBlockDumpInfo; + SReaderStatus* pStatus = NULL; + SFileBlockDumpInfo* pDumpInfo = NULL; - int32_t code = getCurrentBlockInfo(pBlockIter, &pBlockInfo, pReader->idStr); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pStatus = &pReader->status; + pDumpInfo = &pStatus->fBlockDumpInfo; + + code = getCurrentBlockInfo(pBlockIter, &pBlockInfo, pReader->idStr); if (code == TSDB_CODE_SUCCESS) { pDumpInfo->totalRows = pBlockInfo->numRow; pDumpInfo->rowIndex = ASCENDING_TRAVERSE(pReader->info.order) ? 0 : pBlockInfo->numRow - 1; } else { pDumpInfo->totalRows = 0; pDumpInfo->rowIndex = 0; + code = TSDB_CODE_SUCCESS; } pDumpInfo->allDumped = false; + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static int32_t initForFirstBlockInFile(STsdbReader* pReader, SDataBlockIter* pBlockIter) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; SBlockNumber num = {0}; - SArray* pTableList = taosArrayInit(40, POINTER_BYTES); - if (pTableList == NULL) { - return terrno; - } + SArray* pTableList = NULL; - int32_t code = moveToNextFile(pReader, &num, pTableList); - if (code != TSDB_CODE_SUCCESS) { - taosArrayDestroy(pTableList); - return code; - } + pTableList = taosArrayInit(40, POINTER_BYTES); + TSDB_CHECK_NULL(pTableList, code, lino, _end, terrno); + + code = moveToNextFile(pReader, &num, pTableList); + TSDB_CHECK_CODE(code, lino, _end); // all data files are consumed, try data in buffer if (num.numOfBlocks + num.numOfSttFiles == 0) { pReader->status.loadFromFile = false; - taosArrayDestroy(pTableList); - return code; + goto _end; } // initialize the block iterator for a new fileset if (num.numOfBlocks > 0) { code = initBlockIterator(pReader, pBlockIter, num.numOfBlocks, pTableList); + TSDB_CHECK_CODE(code, lino, _end); } else { // no block data, only last block exists tBlockDataReset(&pReader->status.fileBlockData); code = resetDataBlockIterator(pBlockIter, pReader->info.order, shouldFreePkBuf(&pReader->suppInfo), pReader->idStr); - if (code) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = resetTableListIndex(&pReader->status, pReader->idStr); - if (code) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } - if (code == TSDB_CODE_SUCCESS) { // set the correct start position according to the query time window - initBlockDumpInfo(pReader, pBlockIter); - } + code = initBlockDumpInfo(pReader, pBlockIter); + TSDB_CHECK_CODE(code, lino, _end); - taosArrayDestroy(pTableList); +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + if (pTableList) { + taosArrayDestroy(pTableList); + } return code; } @@ -3602,8 +4223,15 @@ typedef enum { static int32_t doReadDataFromSttFiles(STsdbReader* pReader, ERetrieveType* pReturnType) { int32_t code = TSDB_CODE_SUCCESS; - SSDataBlock* pResBlock = pReader->resBlockInfo.pResBlock; - SDataBlockIter* pBlockIter = &pReader->status.blockIter; + int32_t lino = 0; + SSDataBlock* pResBlock = NULL; + SDataBlockIter* pBlockIter = NULL; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pReturnType, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pResBlock = pReader->resBlockInfo.pResBlock; + pBlockIter = &pReader->status.blockIter; *pReturnType = TSDB_READ_RETURN; @@ -3611,89 +4239,96 @@ static int32_t doReadDataFromSttFiles(STsdbReader* pReader, ERetrieveType* pRetu while (1) { code = doLoadSttBlockSequentially(pReader); - if (code != TSDB_CODE_SUCCESS) { - *pReturnType = TSDB_READ_RETURN; - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if (pResBlock->info.rows > 0) { - *pReturnType = TSDB_READ_RETURN; - return code; + goto _end; } // all data blocks are checked in this stt file, now let's try the next file set - if (pReader->status.pTableIter != NULL) { - code = TSDB_CODE_INTERNAL_ERROR; - tsdbError("tsdb reader failed at: %s:%d, code:%s", __func__, __LINE__, tstrerror(code)); - return code; - } + TSDB_CHECK_CONDITION(pReader->status.pTableIter == NULL, code, lino, _end, TSDB_CODE_INTERNAL_ERROR); code = initForFirstBlockInFile(pReader, pBlockIter); + TSDB_CHECK_CODE(code, lino, _end); - // error happens or all the data files are completely checked - if ((code != TSDB_CODE_SUCCESS) || (pReader->status.loadFromFile == false)) { - *pReturnType = TSDB_READ_RETURN; - return code; + // all the data files are completely checked + if (pReader->status.loadFromFile == false) { + goto _end; } if (pReader->status.bProcMemPreFileset) { code = buildFromPreFilesetBuffer(pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if (pResBlock->info.rows > 0) { pReader->status.processingMemPreFileSet = true; - *pReturnType = TSDB_READ_RETURN; - return code; + goto _end; } } if (pBlockIter->numOfBlocks > 0) { // there are data blocks existed. *pReturnType = TSDB_READ_CONTINUE; - return code; + goto _end; } else { // all blocks in data file are checked, let's check the data in stt-files code = resetTableListIndex(&pReader->status, pReader->idStr); - if (code) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } } + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static int32_t buildBlockFromFiles(STsdbReader* pReader) { - int32_t code = TSDB_CODE_SUCCESS; - bool asc = ASCENDING_TRAVERSE(pReader->info.order); + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SDataBlockIter* pBlockIter = NULL; + SSDataBlock* pResBlock = NULL; + SFileBlockDumpInfo* pDumpInfo = NULL; + SBlockData* pBlockData = NULL; + const char* id = NULL; + bool asc = false; - SDataBlockIter* pBlockIter = &pReader->status.blockIter; - SSDataBlock* pResBlock = pReader->resBlockInfo.pResBlock; - SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; - SBlockData* pBlockData = &pReader->status.fileBlockData; - const char* id = pReader->idStr; + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + asc = ASCENDING_TRAVERSE(pReader->info.order); + + pBlockIter = &pReader->status.blockIter; + pResBlock = pReader->resBlockInfo.pResBlock; + pDumpInfo = &pReader->status.fBlockDumpInfo; + pBlockData = &pReader->status.fileBlockData; + id = pReader->idStr; if (pBlockIter->numOfBlocks == 0) { // let's try to extract data from stt files. ERetrieveType type = 0; code = doReadDataFromSttFiles(pReader, &type); - if (code != 0 || type == TSDB_READ_RETURN) { - return code; + TSDB_CHECK_CODE(code, lino, _end); + if (type == TSDB_READ_RETURN) { + goto _end; } code = doBuildDataBlock(pReader); - if (code != TSDB_CODE_SUCCESS || pResBlock->info.rows > 0) { - return code; + TSDB_CHECK_CODE(code, lino, _end); + if (pResBlock->info.rows > 0) { + goto _end; } } while (1) { if (fileBlockPartiallyRead(pDumpInfo, asc)) { // file data block is partially loaded code = buildComposedDataBlock(pReader); + TSDB_CHECK_CODE(code, lino, _end); } else { // current block are exhausted, try the next file block if (pDumpInfo->allDumped) { // try next data block in current file - bool hasNext = blockIteratorNext(&pReader->status.blockIter, pReader->idStr); + bool hasNext = blockIteratorNext(&pReader->status.blockIter); if (hasNext) { // check for the next block in the block accessed order list - initBlockDumpInfo(pReader, pBlockIter); + code = initBlockDumpInfo(pReader, pBlockIter); + TSDB_CHECK_CODE(code, lino, _end); } else { // all data blocks in files are checked, let's check the data in last files. // data blocks in current file are exhausted, let's try the next file now @@ -3703,30 +4338,34 @@ static int32_t buildBlockFromFiles(STsdbReader* pReader) { tBlockDataReset(pBlockData); code = resetDataBlockIterator(pBlockIter, pReader->info.order, shouldFreePkBuf(&pReader->suppInfo), id); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = resetTableListIndex(&pReader->status, id); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); ERetrieveType type = 0; code = doReadDataFromSttFiles(pReader, &type); - if (code != 0 || type == TSDB_READ_RETURN) { - return code; + TSDB_CHECK_CODE(code, lino, _end); + if (type == TSDB_READ_RETURN) { + break; } } } code = doBuildDataBlock(pReader); + TSDB_CHECK_CODE(code, lino, _end); } - if (code != TSDB_CODE_SUCCESS || pResBlock->info.rows > 0) { - return code; + if (pResBlock->info.rows > 0) { + break; } } + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static void getTsdbByRetentions(SVnode* pVnode, SQueryTableDataCond* pCond, SRetention* retentions, const char* idStr, @@ -3768,7 +4407,7 @@ static void getTsdbByRetentions(SVnode* pVnode, SQueryTableDataCond* pCond, SRet } else if (level == TSDB_RETENTION_L1) { *pLevel = TSDB_RETENTION_L1; tsdbDebug("vgId:%d, rsma level %d is selected to query %s", TD_VID(pVnode), TSDB_RETENTION_L1, str); - *pTsdb = VND_RSMA1(pVnode); + *pTsdb = VND_RSMA1(pVnode); return; } else { *pLevel = TSDB_RETENTION_L2; @@ -3795,86 +4434,100 @@ SVersionRange getQueryVerRange(SVnode* pVnode, SQueryTableDataCond* pCond, int8_ return (SVersionRange){.minVer = startVer, .maxVer = endVer}; } -static int32_t reverseSearchStartPos(const SArray* pDelList, int32_t index, int64_t key, bool asc) { - size_t num = taosArrayGetSize(pDelList); - int32_t start = index; +static int32_t reverseSearchStartPos(const SArray* pDelList, int32_t index, int64_t key, bool asc, int32_t* start) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + size_t num = 0; + + num = taosArrayGetSize(pDelList); + *start = index; if (asc) { - if (start >= num - 1) { - start = num - 1; + if (*start >= num - 1) { + *start = num - 1; } - TSDBKEY* p = taosArrayGet(pDelList, start); - if (p == NULL) { - return TSDB_CODE_INVALID_PARA; - } + TSDBKEY* p = taosArrayGet(pDelList, *start); + TSDB_CHECK_NULL(p, code, lino, _end, TSDB_CODE_INVALID_PARA); - while (p->ts >= key && start > 0) { - start -= 1; + while (p->ts >= key && *start > 0) { + *start -= 1; } } else { if (index <= 0) { - start = 0; + *start = 0; } - TSDBKEY* p = taosArrayGet(pDelList, start); - if (p == NULL) { - return TSDB_CODE_INVALID_PARA; - } + TSDBKEY* p = taosArrayGet(pDelList, *start); + TSDB_CHECK_NULL(p, code, lino, _end, TSDB_CODE_INVALID_PARA); - while (p->ts <= key && start < num - 1) { - start += 1; + while (p->ts <= key && *start < num - 1) { + *start += 1; } } - return start; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } -bool hasBeenDropped(const SArray* pDelList, int32_t* index, int64_t key, int64_t ver, int32_t order, - SVersionRange* pVerRange, bool hasPk) { +int32_t hasBeenDropped(const SArray* pDelList, int32_t* index, int64_t key, int64_t ver, int32_t order, + SVersionRange* pVerRange, bool hasPk, bool* dropped) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + size_t num = 0; + int32_t step = 0; + bool asc = false; + + *dropped = false; + if (pDelList == NULL || (TARRAY_SIZE(pDelList) == 0)) { - return false; + goto _end; } - size_t num = taosArrayGetSize(pDelList); - bool asc = ASCENDING_TRAVERSE(order); - int32_t step = asc ? 1 : -1; + num = taosArrayGetSize(pDelList); + asc = ASCENDING_TRAVERSE(order); + step = asc ? 1 : -1; if (hasPk) { // handle the case where duplicated timestamps existed. - *index = reverseSearchStartPos(pDelList, *index, key, asc); + code = reverseSearchStartPos(pDelList, *index, key, asc, index); + TSDB_CHECK_CODE(code, lino, _end); } if (asc) { if (*index >= num - 1) { TSDBKEY* last = taosArrayGetLast(pDelList); if (last == NULL) { - return false; + goto _end; } if (key > last->ts) { - return false; + goto _end; } else if (key == last->ts) { TSDBKEY* prev = taosArrayGet(pDelList, num - 2); if (prev == NULL) { - return false; + goto _end; } - return (prev->version >= ver && prev->version <= pVerRange->maxVer && prev->version >= pVerRange->minVer); + *dropped = (prev->version >= ver && prev->version <= pVerRange->maxVer && prev->version >= pVerRange->minVer); } } else { TSDBKEY* pCurrent = taosArrayGet(pDelList, *index); TSDBKEY* pNext = taosArrayGet(pDelList, (*index) + 1); if (pCurrent == NULL || pNext == NULL) { - return false; + goto _end; } if (key < pCurrent->ts) { - return false; + goto _end; } if (pCurrent->ts <= key && pNext->ts >= key && pCurrent->version >= ver && pVerRange->maxVer >= pCurrent->version) { - return true; + *dropped = true; + goto _end; } while (pNext->ts <= key && (*index) < num - 1) { @@ -3884,7 +4537,7 @@ bool hasBeenDropped(const SArray* pDelList, int32_t* index, int64_t key, int64_t pCurrent = taosArrayGet(pDelList, *index); pNext = taosArrayGet(pDelList, (*index) + 1); if (pCurrent == NULL || pNext == NULL) { - return false; + break; } // it is not a consecutive deletion range, ignore it @@ -3894,24 +4547,23 @@ bool hasBeenDropped(const SArray* pDelList, int32_t* index, int64_t key, int64_t if (pCurrent->ts <= key && pNext->ts >= key && pCurrent->version >= ver && pVerRange->maxVer >= pCurrent->version) { - return true; + *dropped = true; + break; } } } - - return false; } } else { if (*index <= 0) { TSDBKEY* pFirst = taosArrayGet(pDelList, 0); if (pFirst == NULL) { - return false; + goto _end; } if (key < pFirst->ts) { - return false; + goto _end; } else if (key == pFirst->ts) { - return pFirst->version >= ver; + *dropped = pFirst->version >= ver; } else { tsdbError("unexpected error, key:%" PRId64 ", first:%" PRId64, key, pFirst->ts); } @@ -3919,15 +4571,16 @@ bool hasBeenDropped(const SArray* pDelList, int32_t* index, int64_t key, int64_t TSDBKEY* pCurrent = taosArrayGet(pDelList, *index); TSDBKEY* pPrev = taosArrayGet(pDelList, (*index) - 1); if (pCurrent == NULL || pPrev == NULL) { - return false; + goto _end; } if (key > pCurrent->ts) { - return false; + goto _end; } if (pPrev->ts <= key && pCurrent->ts >= key && pPrev->version >= ver) { - return true; + *dropped = true; + goto _end; } while (pPrev->ts >= key && (*index) > 1) { @@ -3937,7 +4590,7 @@ bool hasBeenDropped(const SArray* pDelList, int32_t* index, int64_t key, int64_t pCurrent = taosArrayGet(pDelList, *index); pPrev = taosArrayGet(pDelList, (*index) - 1); if (pCurrent == NULL || pPrev == NULL) { - return false; + break; } // it is not a consecutive deletion range, ignore it @@ -3946,46 +4599,60 @@ bool hasBeenDropped(const SArray* pDelList, int32_t* index, int64_t key, int64_t } if (pPrev->ts <= key && pCurrent->ts >= key && pPrev->version >= ver) { - return true; + *dropped = true; + break; } } } - - return false; } } - return false; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } -FORCE_INLINE void getValidMemRow(SIterInfo* pIter, const SArray* pDelList, STsdbReader* pReader, TSDBROW** pRes) { +FORCE_INLINE int32_t getValidMemRow(SIterInfo* pIter, const SArray* pDelList, STsdbReader* pReader, TSDBROW** pRes) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + int32_t order = 0; + TSDBROW* pRow = NULL; + TSDBKEY key; + + TSDB_CHECK_NULL(pIter, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pRes, code, lino, _end, TSDB_CODE_INVALID_PARA); + *pRes = NULL; if (!pIter->hasVal) { - return; + goto _end; } - int32_t order = pReader->info.order; - TSDBROW* pRow = tsdbTbDataIterGet(pIter->iter); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + order = pReader->info.order; + pRow = tsdbTbDataIterGet(pIter->iter); - TSDBKEY key; TSDBROW_INIT_KEY(pRow, key); if (outOfTimeWindow(key.ts, &pReader->info.window)) { pIter->hasVal = false; - return; + goto _end; } // it is a valid data version if (key.version <= pReader->info.verRange.maxVer && key.version >= pReader->info.verRange.minVer) { if (pDelList == NULL || TARRAY_SIZE(pDelList) == 0) { *pRes = pRow; - return; + goto _end; } else { - bool dropped = hasBeenDropped(pDelList, &pIter->index, key.ts, key.version, order, &pReader->info.verRange, - pReader->suppInfo.numOfPks > 0); + bool dropped = false; + code = hasBeenDropped(pDelList, &pIter->index, key.ts, key.version, order, &pReader->info.verRange, + pReader->suppInfo.numOfPks > 0, &dropped); + TSDB_CHECK_CODE(code, lino, _end); if (!dropped) { *pRes = pRow; - return; + goto _end; } } } @@ -3993,7 +4660,7 @@ FORCE_INLINE void getValidMemRow(SIterInfo* pIter, const SArray* pDelList, STsdb while (1) { pIter->hasVal = tsdbTbDataIterNext(pIter->iter); if (!pIter->hasVal) { - return; + goto _end; } pRow = tsdbTbDataIterGet(pIter->iter); @@ -4001,28 +4668,42 @@ FORCE_INLINE void getValidMemRow(SIterInfo* pIter, const SArray* pDelList, STsdb TSDBROW_INIT_KEY(pRow, key); if (outOfTimeWindow(key.ts, &pReader->info.window)) { pIter->hasVal = false; - return; + goto _end; } if (key.version <= pReader->info.verRange.maxVer && key.version >= pReader->info.verRange.minVer) { if (pDelList == NULL || TARRAY_SIZE(pDelList) == 0) { *pRes = pRow; - return; + goto _end; } else { - bool dropped = hasBeenDropped(pDelList, &pIter->index, key.ts, key.version, order, &pReader->info.verRange, - pReader->suppInfo.numOfPks > 0); + bool dropped = false; + code = hasBeenDropped(pDelList, &pIter->index, key.ts, key.version, order, &pReader->info.verRange, + pReader->suppInfo.numOfPks > 0, &dropped); + TSDB_CHECK_CODE(code, lino, _end); if (!dropped) { *pRes = pRow; - return; + goto _end; } } } } + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } int32_t doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, SRowKey* pCurKey, SArray* pDelList, STsdbReader* pReader) { - SRowMerger* pMerger = &pReader->status.merger; - int32_t code = 0; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SRowMerger* pMerger = NULL; + + TSDB_CHECK_NULL(pIter, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pMerger = &pReader->status.merger; while (1) { pIter->hasVal = tsdbTbDataIterNext(pIter->iter); @@ -4032,7 +4713,8 @@ int32_t doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, SRowKey* pCurKey, SArra // data exists but not valid TSDBROW* pRow = NULL; - getValidMemRow(pIter, pDelList, pReader, &pRow); + code = getValidMemRow(pIter, pDelList, pReader, &pRow); + TSDB_CHECK_CODE(code, lino, _end); if (pRow == NULL) { break; } @@ -4053,23 +4735,28 @@ int32_t doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, SRowKey* pCurKey, SArra STSchema* pTSchema = NULL; if (pRow->type == TSDBROW_ROW_FMT) { pTSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, uid); - if (pTSchema == NULL) { - return terrno; - } + TSDB_CHECK_NULL(pTSchema, code, lino, _end, terrno); } code = tsdbRowMergerAdd(pMerger, pRow, pTSchema); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } static int32_t doMergeRowsInFileBlockImpl(SBlockData* pBlockData, int32_t* rowIndex, SRowKey* pKey, SRowMerger* pMerger, SVersionRange* pVerRange, int32_t step) { - int32_t code = 0; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + + TSDB_CHECK_NULL(pBlockData, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(rowIndex, code, lino, _end, TSDB_CODE_INVALID_PARA); + while ((*rowIndex) < pBlockData->nRow && (*rowIndex) >= 0) { SRowKey cur; tColRowGetKey(pBlockData, (*rowIndex), &cur); @@ -4085,11 +4772,14 @@ static int32_t doMergeRowsInFileBlockImpl(SBlockData* pBlockData, int32_t* rowIn TSDBROW fRow = tsdbRowFromBlockData(pBlockData, (*rowIndex)); code = tsdbRowMergerAdd(pMerger, &fRow, NULL); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); (*rowIndex) += step; } + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } @@ -4101,92 +4791,120 @@ typedef enum { static int32_t checkForNeighborFileBlock(STsdbReader* pReader, STableBlockScanInfo* pScanInfo, SFileDataBlockInfo* pFBlock, SRowMerger* pMerger, SRowKey* pKey, CHECK_FILEBLOCK_STATE* state) { - SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; - SBlockData* pBlockData = &pReader->status.fileBlockData; - bool asc = ASCENDING_TRAVERSE(pReader->info.order); - SVersionRange* pVerRange = &pReader->info.verRange; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SFileBlockDumpInfo* pDumpInfo = NULL; + SBlockData* pBlockData = NULL; + bool asc = false; + SVersionRange* pVerRange = NULL; bool loadNeighbor = true; - int32_t step = ASCENDING_TRAVERSE(pReader->info.order) ? 1 : -1; + int32_t step = 0; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(state, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pDumpInfo = &pReader->status.fBlockDumpInfo; + pBlockData = &pReader->status.fileBlockData; + asc = ASCENDING_TRAVERSE(pReader->info.order); + pVerRange = &pReader->info.verRange; + ASCENDING_TRAVERSE(pReader->info.order) ? 1 : -1; - int32_t code = loadNeighborIfOverlap(pFBlock, pScanInfo, pReader, &loadNeighbor); *state = CHECK_FILEBLOCK_QUIT; + code = loadNeighborIfOverlap(pFBlock, pScanInfo, pReader, &loadNeighbor); + TSDB_CHECK_CODE(code, lino, _end); - if (loadNeighbor && (code == TSDB_CODE_SUCCESS)) { + if (loadNeighbor) { code = doMergeRowsInFileBlockImpl(pBlockData, &pDumpInfo->rowIndex, pKey, pMerger, pVerRange, step); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if ((pDumpInfo->rowIndex >= pDumpInfo->totalRows && asc) || (pDumpInfo->rowIndex < 0 && !asc)) { *state = CHECK_FILEBLOCK_CONT; } } +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } int32_t doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pScanInfo, SRowKey* pKey, STsdbReader* pReader) { - SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; - SRowMerger* pMerger = &pReader->status.merger; - bool asc = ASCENDING_TRAVERSE(pReader->info.order); - int32_t step = asc ? 1 : -1; - SVersionRange* pRange = &pReader->info.verRange; - int32_t code = 0; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SFileBlockDumpInfo* pDumpInfo = NULL; + SRowMerger* pMerger = NULL; + bool asc = false; + int32_t step = 0; + SVersionRange* pRange = NULL; + + TSDB_CHECK_NULL(pBlockData, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pDumpInfo = &pReader->status.fBlockDumpInfo; + pMerger = &pReader->status.merger; + asc = ASCENDING_TRAVERSE(pReader->info.order); + step = asc ? 1 : -1; + pRange = &pReader->info.verRange; pDumpInfo->rowIndex += step; if ((pDumpInfo->rowIndex <= pBlockData->nRow - 1 && asc) || (pDumpInfo->rowIndex >= 0 && !asc)) { code = doMergeRowsInFileBlockImpl(pBlockData, &pDumpInfo->rowIndex, pKey, pMerger, pRange, step); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } // all rows are consumed, let's try next file block if ((pDumpInfo->rowIndex >= pBlockData->nRow && asc) || (pDumpInfo->rowIndex < 0 && !asc)) { while (1) { - CHECK_FILEBLOCK_STATE st; - SFileDataBlockInfo* pFileBlockInfo = NULL; code = getCurrentBlockInfo(&pReader->status.blockIter, &pFileBlockInfo, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if (pFileBlockInfo == NULL) { - st = CHECK_FILEBLOCK_QUIT; break; } + CHECK_FILEBLOCK_STATE st = CHECK_FILEBLOCK_QUIT; code = checkForNeighborFileBlock(pReader, pScanInfo, pFileBlockInfo, pMerger, pKey, &st); - if (st == CHECK_FILEBLOCK_QUIT || code != TSDB_CODE_SUCCESS) { + TSDB_CHECK_CODE(code, lino, _end); + if (st == CHECK_FILEBLOCK_QUIT) { break; } } } +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } int32_t doMergeRowsInSttBlock(SSttBlockReader* pSttBlockReader, STableBlockScanInfo* pScanInfo, SRowMerger* pMerger, int32_t pkSrcSlot, SVersionRange* pVerRange, const char* idStr) { - SRowKey* pRowKey = &pScanInfo->lastProcKey; - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SRowKey* pRowKey = NULL; + SRowKey* pNextKey = NULL; + + TSDB_CHECK_NULL(pScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pRowKey = &pScanInfo->lastProcKey; while (1) { code = nextRowFromSttBlocks(pSttBlockReader, pScanInfo, pkSrcSlot, pVerRange); - if (code || (!hasDataInSttBlock(pScanInfo))) { - return code; + TSDB_CHECK_CODE(code, lino, _end); + if (!hasDataInSttBlock(pScanInfo)) { + break; } - SRowKey* pNextKey = getCurrentKeyInSttBlock(pSttBlockReader); + pNextKey = getCurrentKeyInSttBlock(pSttBlockReader); int32_t ret = pkCompEx(pRowKey, pNextKey); if (ret == 0) { TSDBROW* pRow1 = tMergeTreeGetRow(&pSttBlockReader->mergeTree); code = tsdbRowMergerAdd(pMerger, pRow1, NULL); - if (code != TSDB_CODE_SUCCESS) { - break; - } + TSDB_CHECK_CODE(code, lino, _end); } else { tsdbTrace("uid:%" PRIu64 " last del index:%d, del range:%d, lastKeyInStt:%" PRId64 ", %s", pScanInfo->uid, pScanInfo->sttBlockDelIndex, (int32_t)taosArrayGetSize(pScanInfo->delSkyline), @@ -4195,14 +4913,31 @@ int32_t doMergeRowsInSttBlock(SSttBlockReader* pSttBlockReader, STableBlockScanI } } +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } int32_t doMergeMemTableMultiRows(TSDBROW* pRow, SRowKey* pKey, uint64_t uid, SIterInfo* pIter, SArray* pDelList, TSDBROW* pResRow, STsdbReader* pReader, bool* freeTSRow) { - SRowMerger* pMerger = &pReader->status.merger; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SRowMerger* pMerger = NULL; TSDBROW* pNextRow = NULL; - TSDBROW current = *pRow; + STSchema* pTSchema = NULL; + STSchema* pTSchema1 = NULL; + TSDBROW current; + + TSDB_CHECK_NULL(pRow, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pIter, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pResRow, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(freeTSRow, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pMerger = &pReader->status.merger; + current = *pRow; { // if the timestamp of the next valid row has a different ts, return current row directly pIter->hasVal = tsdbTbDataIterNext(pIter->iter); @@ -4210,19 +4945,20 @@ int32_t doMergeMemTableMultiRows(TSDBROW* pRow, SRowKey* pKey, uint64_t uid, SIt if (!pIter->hasVal) { *pResRow = *pRow; *freeTSRow = false; - return TSDB_CODE_SUCCESS; + goto _end; } else { // has next point in mem/imem - getValidMemRow(pIter, pDelList, pReader, &pNextRow); + code = getValidMemRow(pIter, pDelList, pReader, &pNextRow); + TSDB_CHECK_CODE(code, lino, _end); if (pNextRow == NULL) { *pResRow = current; *freeTSRow = false; - return TSDB_CODE_SUCCESS; + goto _end; } if (TSDBROW_TS(¤t) != TSDBROW_TS(pNextRow)) { *pResRow = current; *freeTSRow = false; - return TSDB_CODE_SUCCESS; + goto _end; } if (pKey->numOfPKs > 0) { @@ -4231,145 +4967,140 @@ int32_t doMergeMemTableMultiRows(TSDBROW* pRow, SRowKey* pKey, uint64_t uid, SIt if (pkCompEx(pKey, &nextRowKey) != 0) { *pResRow = current; *freeTSRow = false; - return TSDB_CODE_SUCCESS; + goto _end; } } } } - terrno = 0; - int32_t code = 0; - // start to merge duplicated rows - STSchema* pTSchema = NULL; if (current.type == TSDBROW_ROW_FMT) { // get the correct schema for row-wise data in memory pTSchema = doGetSchemaForTSRow(current.pTSRow->sver, pReader, uid); - if (pTSchema == NULL) { - return terrno; - } + TSDB_CHECK_NULL(pTSchema, code, lino, _end, terrno); } code = tsdbRowMergerAdd(pMerger, ¤t, pTSchema); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); - STSchema* pTSchema1 = NULL; if (pNextRow->type == TSDBROW_ROW_FMT) { // get the correct schema for row-wise data in memory pTSchema1 = doGetSchemaForTSRow(pNextRow->pTSRow->sver, pReader, uid); - if (pTSchema1 == NULL) { - return terrno; - } + TSDB_CHECK_NULL(pTSchema1, code, lino, _end, terrno); } code = tsdbRowMergerAdd(pMerger, pNextRow, pTSchema1); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = doMergeRowsInBuf(pIter, uid, pKey, pDelList, pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = tsdbRowMergerGetRow(pMerger, &pResRow->pTSRow); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); pResRow->type = TSDBROW_ROW_FMT; tsdbRowMergerClear(pMerger); *freeTSRow = true; - return TSDB_CODE_SUCCESS; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } int32_t doMergeMemIMemRows(TSDBROW* pRow, SRowKey* pRowKey, TSDBROW* piRow, SRowKey* piRowKey, STableBlockScanInfo* pBlockScanInfo, STsdbReader* pReader, SRow** pTSRow) { - SRowMerger* pMerger = &pReader->status.merger; int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SRowMerger* pMerger = NULL; + STSchema* pSchema = NULL; + STSchema* piSchema = NULL; + + TSDB_CHECK_NULL(pRow, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(piRow, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pBlockScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pMerger = &pReader->status.merger; - STSchema* pSchema = NULL; if (pRow->type == TSDBROW_ROW_FMT) { pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid); - if (pSchema == NULL) { - return terrno; - } + TSDB_CHECK_NULL(pSchema, code, lino, _end, terrno); } - STSchema* piSchema = NULL; if (piRow->type == TSDBROW_ROW_FMT) { piSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(piRow), pReader, pBlockScanInfo->uid); - if (piSchema == NULL) { - return terrno; - } + TSDB_CHECK_NULL(piSchema, code, lino, _end, terrno); } if (ASCENDING_TRAVERSE(pReader->info.order)) { // ascending order imem --> mem code = tsdbRowMergerAdd(pMerger, piRow, piSchema); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, piRowKey, pBlockScanInfo->delSkyline, pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = tsdbRowMergerAdd(pMerger, pRow, pSchema); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = doMergeRowsInBuf(&pBlockScanInfo->iter, pBlockScanInfo->uid, pRowKey, pBlockScanInfo->delSkyline, pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } else { code = tsdbRowMergerAdd(pMerger, pRow, pSchema); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = doMergeRowsInBuf(&pBlockScanInfo->iter, pBlockScanInfo->uid, pRowKey, pBlockScanInfo->delSkyline, pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = tsdbRowMergerAdd(pMerger, piRow, piSchema); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, piRowKey, pBlockScanInfo->delSkyline, pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } tRowKeyAssign(&pBlockScanInfo->lastProcKey, pRowKey); code = tsdbRowMergerGetRow(pMerger, pTSRow); tsdbRowMergerClear(pMerger); + TSDB_CHECK_CODE(code, lino, _end); + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } static int32_t tsdbGetNextRowInMem(STableBlockScanInfo* pBlockScanInfo, STsdbReader* pReader, TSDBROW* pResRow, int64_t endKey, bool* freeTSRow) { - TSDBROW* pRow = NULL; - TSDBROW* piRow = NULL; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + TSDBROW* pRow = NULL; + TSDBROW* piRow = NULL; + SArray* pDelList = NULL; + uint64_t uid = 0; + SIterInfo* piter = NULL; + SIterInfo* piiter = NULL; + SRowKey rowKey = {0}; + SRowKey irowKey = {0}; + bool asc = false; - getValidMemRow(&pBlockScanInfo->iter, pBlockScanInfo->delSkyline, pReader, &pRow); - getValidMemRow(&pBlockScanInfo->iiter, pBlockScanInfo->delSkyline, pReader, &piRow); + TSDB_CHECK_NULL(pBlockScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pResRow, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(freeTSRow, code, lino, _end, TSDB_CODE_INVALID_PARA); - SArray* pDelList = pBlockScanInfo->delSkyline; - uint64_t uid = pBlockScanInfo->uid; - SIterInfo* piter = &pBlockScanInfo->iter; - SIterInfo* piiter = &pBlockScanInfo->iiter; - SRowKey rowKey = {0}, irowKey = {0}; + code = getValidMemRow(&pBlockScanInfo->iter, pBlockScanInfo->delSkyline, pReader, &pRow); + TSDB_CHECK_CODE(code, lino, _end); + code = getValidMemRow(&pBlockScanInfo->iiter, pBlockScanInfo->delSkyline, pReader, &piRow); + TSDB_CHECK_CODE(code, lino, _end); + + pDelList = pBlockScanInfo->delSkyline; + uid = pBlockScanInfo->uid; + piter = &pBlockScanInfo->iter; + piiter = &pBlockScanInfo->iiter; // todo refactor - bool asc = ASCENDING_TRAVERSE(pReader->info.order); + asc = ASCENDING_TRAVERSE(pReader->info.order); if (piter->hasVal) { tRowGetKeyEx(pRow, &rowKey); if ((rowKey.ts >= endKey && asc) || (rowKey.ts <= endKey && !asc)) { @@ -4385,71 +5116,76 @@ static int32_t tsdbGetNextRowInMem(STableBlockScanInfo* pBlockScanInfo, STsdbRea } if (pRow != NULL && piRow != NULL) { - int32_t code = TSDB_CODE_SUCCESS; if (rowKey.numOfPKs == 0) { if ((rowKey.ts > irowKey.ts && asc) || (rowKey.ts < irowKey.ts && (!asc))) { // ik.ts < k.ts code = doMergeMemTableMultiRows(piRow, &irowKey, uid, piiter, pDelList, pResRow, pReader, freeTSRow); + TSDB_CHECK_CODE(code, lino, _end); } else if ((rowKey.ts < irowKey.ts && asc) || (rowKey.ts > irowKey.ts && (!asc))) { code = doMergeMemTableMultiRows(pRow, &rowKey, uid, piter, pDelList, pResRow, pReader, freeTSRow); + TSDB_CHECK_CODE(code, lino, _end); } else { // ik.ts == k.ts - *freeTSRow = true; pResRow->type = TSDBROW_ROW_FMT; code = doMergeMemIMemRows(pRow, &rowKey, piRow, &irowKey, pBlockScanInfo, pReader, &pResRow->pTSRow); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); + *freeTSRow = true; } } else { int32_t ret = pkCompEx(&rowKey, &irowKey); if (ret != 0) { if ((ret > 0 && asc) || (ret < 0 && (!asc))) { // ik.ts < k.ts code = doMergeMemTableMultiRows(piRow, &irowKey, uid, piiter, pDelList, pResRow, pReader, freeTSRow); + TSDB_CHECK_CODE(code, lino, _end); } else if ((ret < 0 && asc) || (ret > 0 && (!asc))) { code = doMergeMemTableMultiRows(pRow, &rowKey, uid, piter, pDelList, pResRow, pReader, freeTSRow); + TSDB_CHECK_CODE(code, lino, _end); } } else { // ik.ts == k.ts - *freeTSRow = true; pResRow->type = TSDBROW_ROW_FMT; code = doMergeMemIMemRows(pRow, &rowKey, piRow, &irowKey, pBlockScanInfo, pReader, &pResRow->pTSRow); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); + *freeTSRow = true; } } - - return code; + } else if (piter->hasVal && pRow != NULL) { + code = doMergeMemTableMultiRows(pRow, &rowKey, uid, piter, pDelList, pResRow, pReader, freeTSRow); + TSDB_CHECK_CODE(code, lino, _end); + } else if (piiter->hasVal && piRow != NULL) { + code = doMergeMemTableMultiRows(piRow, &irowKey, uid, piiter, pDelList, pResRow, pReader, freeTSRow); + TSDB_CHECK_CODE(code, lino, _end); } - if (piter->hasVal && pRow != NULL) { - return doMergeMemTableMultiRows(pRow, &rowKey, uid, piter, pDelList, pResRow, pReader, freeTSRow); +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); } - - if (piiter->hasVal && piRow != NULL) { - return doMergeMemTableMultiRows(piRow, &irowKey, uid, piiter, pDelList, pResRow, pReader, freeTSRow); - } - - return TSDB_CODE_SUCCESS; + return code; } int32_t doAppendRowFromTSRow(SSDataBlock* pBlock, STsdbReader* pReader, SRow* pTSRow, STableBlockScanInfo* pScanInfo) { - int32_t outputRowIndex = pBlock->info.rows; - int64_t uid = pScanInfo->uid; - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + int32_t outputRowIndex = 0; + int64_t uid = 0; + SBlockLoadSuppInfo* pSupInfo = NULL; + STSchema* pSchema = NULL; + SColVal colVal = {0}; + int32_t i = 0, j = 0; - SBlockLoadSuppInfo* pSupInfo = &pReader->suppInfo; - STSchema* pSchema = doGetSchemaForTSRow(pTSRow->sver, pReader, uid); - if (pSchema == NULL) { - return terrno; - } + TSDB_CHECK_NULL(pBlock, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pTSRow, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); - SColVal colVal = {0}; - int32_t i = 0, j = 0; + outputRowIndex = pBlock->info.rows; + uid = pScanInfo->uid; + + pSupInfo = &pReader->suppInfo; + pSchema = doGetSchemaForTSRow(pTSRow->sver, pReader, uid); + TSDB_CHECK_NULL(pSchema, code, lino, _end, terrno); if (pSupInfo->colId[i] == PRIMARYKEY_TIMESTAMP_COL_ID) { SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pSupInfo->slotId[i]); - if (pColData == NULL) { - return TSDB_CODE_INVALID_PARA; - } + TSDB_CHECK_NULL(pColData, code, lino, _end, TSDB_CODE_INVALID_PARA); ((int64_t*)pColData->pData)[outputRowIndex] = pTSRow->ts; i += 1; @@ -4460,26 +5196,18 @@ int32_t doAppendRowFromTSRow(SSDataBlock* pBlock, STsdbReader* pReader, SRow* pT if (colId == pSchema->columns[j].colId) { SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, pSupInfo->slotId[i]); - if (pColInfoData == NULL) { - return TSDB_CODE_INVALID_PARA; - } + TSDB_CHECK_NULL(pColInfoData, code, lino, _end, TSDB_CODE_INVALID_PARA); code = tRowGet(pTSRow, pSchema, j, &colVal); - if (code) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = doCopyColVal(pColInfoData, outputRowIndex, i, &colVal, pSupInfo); - if (code) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); i += 1; j += 1; } else if (colId < pSchema->columns[j].colId) { SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, pSupInfo->slotId[i]); - if (pColInfoData == NULL) { - return TSDB_CODE_INVALID_PARA; - } + TSDB_CHECK_NULL(pColInfoData, code, lino, _end, TSDB_CODE_INVALID_PARA); colDataSetNULL(pColInfoData, outputRowIndex); i += 1; @@ -4491,9 +5219,7 @@ int32_t doAppendRowFromTSRow(SSDataBlock* pBlock, STsdbReader* pReader, SRow* pT // set null value since current column does not exist in the "pSchema" while (i < pSupInfo->numOfCols) { SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, pSupInfo->slotId[i]); - if (pColInfoData == NULL) { - return TSDB_CODE_INVALID_PARA; - } + TSDB_CHECK_NULL(pColInfoData, code, lino, _end, TSDB_CODE_INVALID_PARA); colDataSetNULL(pColInfoData, outputRowIndex); i += 1; @@ -4501,22 +5227,37 @@ int32_t doAppendRowFromTSRow(SSDataBlock* pBlock, STsdbReader* pReader, SRow* pT pBlock->info.dataLoad = 1; pBlock->info.rows += 1; - return TSDB_CODE_SUCCESS; + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } int32_t doAppendRowFromFileBlock(SSDataBlock* pResBlock, STsdbReader* pReader, SBlockData* pBlockData, int32_t rowIndex) { - int32_t i = 0, j = 0; - int32_t outputRowIndex = pResBlock->info.rows; - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + int32_t i = 0, j = 0; + int32_t outputRowIndex = 0; + SBlockLoadSuppInfo* pSupInfo = NULL; + SColVal cv = {0}; + int32_t numOfInputCols = 0; + int32_t numOfOutputCols = 0; - SBlockLoadSuppInfo* pSupInfo = &pReader->suppInfo; + TSDB_CHECK_NULL(pResBlock, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pBlockData, code, lino, _end, TSDB_CODE_INVALID_PARA); + + outputRowIndex = pResBlock->info.rows; + + pSupInfo = &pReader->suppInfo; ((int64_t*)pReader->status.pPrimaryTsCol->pData)[outputRowIndex] = pBlockData->aTSKEY[rowIndex]; i += 1; - SColVal cv = {0}; - int32_t numOfInputCols = pBlockData->nColData; - int32_t numOfOutputCols = pSupInfo->numOfCols; + numOfInputCols = pBlockData->nColData; + numOfOutputCols = pSupInfo->numOfCols; while (i < numOfOutputCols && j < numOfInputCols) { SColData* pData = tBlockDataGetColDataByIdx(pBlockData, j); @@ -4529,9 +5270,7 @@ int32_t doAppendRowFromFileBlock(SSDataBlock* pResBlock, STsdbReader* pReader, S if (pData->cid == pSupInfo->colId[i]) { tColDataGetValue(pData, rowIndex, &cv); code = doCopyColVal(pCol, outputRowIndex, i, &cv, pSupInfo); - if (code) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); j += 1; } else if (pData->cid > pCol->info.colId) { // the specified column does not exist in file block, fill with null data @@ -4543,9 +5282,7 @@ int32_t doAppendRowFromFileBlock(SSDataBlock* pResBlock, STsdbReader* pReader, S while (i < numOfOutputCols) { SColumnInfoData* pCol = taosArrayGet(pResBlock->pDataBlock, pSupInfo->slotId[i]); - if (pCol == NULL) { - return TSDB_CODE_INVALID_PARA; - } + TSDB_CHECK_NULL(pCol, code, lino, _end, TSDB_CODE_INVALID_PARA); colDataSetNULL(pCol, outputRowIndex); i += 1; @@ -4553,21 +5290,29 @@ int32_t doAppendRowFromFileBlock(SSDataBlock* pResBlock, STsdbReader* pReader, S pResBlock->info.dataLoad = 1; pResBlock->info.rows += 1; - return TSDB_CODE_SUCCESS; + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } int32_t buildDataBlockFromBufImpl(STableBlockScanInfo* pBlockScanInfo, int64_t endKey, int32_t capacity, STsdbReader* pReader) { - SSDataBlock* pBlock = pReader->resBlockInfo.pResBlock; int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SSDataBlock* pBlock = NULL; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pBlock = pReader->resBlockInfo.pResBlock; do { TSDBROW row = {.type = -1}; bool freeTSRow = false; code = tsdbGetNextRowInMem(pBlockScanInfo, pReader, &row, endKey, &freeTSRow); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if (row.type == -1) { break; @@ -4575,26 +5320,30 @@ int32_t buildDataBlockFromBufImpl(STableBlockScanInfo* pBlockScanInfo, int64_t e if (row.type == TSDBROW_ROW_FMT) { code = doAppendRowFromTSRow(pBlock, pReader, row.pTSRow, pBlockScanInfo); - if (code == TSDB_CODE_SUCCESS) { - pBlockScanInfo->lastProcKey.ts = row.pTSRow->ts; - pBlockScanInfo->lastProcKey.numOfPKs = row.pTSRow->numOfPKs; - if (row.pTSRow->numOfPKs > 0) { - tRowGetPrimaryKeyDeepCopy(row.pTSRow, &pBlockScanInfo->lastProcKey); + if (code != TSDB_CODE_SUCCESS) { + if (freeTSRow) { + taosMemoryFreeClear(row.pTSRow); + } + TSDB_CHECK_CODE(code, lino, _end); + } + pBlockScanInfo->lastProcKey.ts = row.pTSRow->ts; + pBlockScanInfo->lastProcKey.numOfPKs = row.pTSRow->numOfPKs; + if (row.pTSRow->numOfPKs > 0) { + code = tRowGetPrimaryKeyDeepCopy(row.pTSRow, &pBlockScanInfo->lastProcKey); + if (code != TSDB_CODE_SUCCESS) { + if (freeTSRow) { + taosMemoryFreeClear(row.pTSRow); + } + TSDB_CHECK_CODE(code, lino, _end); } } if (freeTSRow) { - taosMemoryFree(row.pTSRow); - } - - if (code) { - return code; + taosMemoryFreeClear(row.pTSRow); } } else { code = doAppendRowFromFileBlock(pBlock, pReader, row.pBlockData, row.iRow); - if (code) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); tColRowGetKeyDeepCopy(row.pBlockData, row.iRow, pReader->suppInfo.pkSrcSlot, &pBlockScanInfo->lastProcKey); } @@ -4609,21 +5358,30 @@ int32_t buildDataBlockFromBufImpl(STableBlockScanInfo* pBlockScanInfo, int64_t e } } while (1); +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } // TODO refactor: with createDataBlockScanInfo int32_t tsdbSetTableList2(STsdbReader* pReader, const void* pTableList, int32_t num) { - int32_t code = TSDB_CODE_SUCCESS; - int32_t size = tSimpleHashGetSize(pReader->status.pTableMap); - + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + int32_t size = 0; STableBlockScanInfo** p = NULL; + STableUidList* pUidList = NULL; int32_t iter = 0; + bool acquired = false; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + size = tSimpleHashGetSize(pReader->status.pTableMap); code = tsdbAcquireReader(pReader); - if (code) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); + acquired = true; while ((p = tSimpleHashIterate(pReader->status.pTableMap, p, &iter)) != NULL) { clearBlockScanInfo(*p); @@ -4633,21 +5391,15 @@ int32_t tsdbSetTableList2(STsdbReader* pReader, const void* pTableList, int32_t if (size < num) { code = ensureBlockScanInfoBuf(&pReader->blockInfoBuf, num); - if (code) { - (void) tsdbReleaseReader(pReader); - return code; - } + TSDB_CHECK_CODE(code, lino, _end); char* p1 = taosMemoryRealloc(pReader->status.uidList.tableUidList, sizeof(uint64_t) * num); - if (p1 == NULL) { - (void) tsdbReleaseReader(pReader); - return terrno; - } + TSDB_CHECK_NULL(p1, code, lino, _end, terrno); pReader->status.uidList.tableUidList = (uint64_t*)p1; } - STableUidList* pUidList = &pReader->status.uidList; + pUidList = &pReader->status.uidList; pUidList->currentIndex = 0; STableKeyInfo* pList = (STableKeyInfo*)pTableList; @@ -4656,28 +5408,34 @@ int32_t tsdbSetTableList2(STsdbReader* pReader, const void* pTableList, int32_t STableBlockScanInfo* pInfo = NULL; code = getPosInBlockInfoBuf(&pReader->blockInfoBuf, i, &pInfo); - if (code != TSDB_CODE_SUCCESS) { - (void) tsdbReleaseReader(pReader); - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = initTableBlockScanInfo(pInfo, pList[i].uid, pReader->status.pTableMap, pReader); - if (code != TSDB_CODE_SUCCESS) { - (void) tsdbReleaseReader(pReader); - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } - (void) tsdbReleaseReader(pReader); +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + if (acquired) { + (void)tsdbReleaseReader(pReader); + } return code; } uint64_t tsdbGetReaderMaxVersion2(STsdbReader* pReader) { return pReader->info.verRange.maxVer; } static int32_t doOpenReaderImpl(STsdbReader* pReader) { - SReaderStatus* pStatus = &pReader->status; - SDataBlockIter* pBlockIter = &pStatus->blockIter; int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SReaderStatus* pStatus = NULL; + SDataBlockIter* pBlockIter = NULL; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pStatus = &pReader->status; + pBlockIter = &pStatus->blockIter; if (pReader->bFilesetDelimited) { getMemTableTimeRange(pReader, &pReader->status.memTableMaxKey, &pReader->status.memTableMinKey); @@ -4685,15 +5443,11 @@ static int32_t doOpenReaderImpl(STsdbReader* pReader) { } code = initFilesetIterator(&pStatus->fileIter, pReader->pReadSnap->pfSetArray, pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = resetDataBlockIterator(&pStatus->blockIter, pReader->info.order, shouldFreePkBuf(&pReader->suppInfo), pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if (pStatus->fileIter.numOfFiles == 0) { pStatus->loadFromFile = false; @@ -4703,8 +5457,13 @@ static int32_t doOpenReaderImpl(STsdbReader* pReader) { if (!pStatus->loadFromFile) { code = resetTableListIndex(pStatus, pReader->idStr); + TSDB_CHECK_CODE(code, lino, _end); } +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } @@ -4741,25 +5500,30 @@ static int32_t setSharedPtr(STsdbReader* pDst, const STsdbReader* pSrc) { // ====================================== EXPOSED APIs ====================================== int32_t tsdbReaderOpen2(void* pVnode, SQueryTableDataCond* pCond, void* pTableList, int32_t numOfTables, SSDataBlock* pResBlock, void** ppReader, const char* idstr, SHashObj** pIgnoreTables) { - STimeWindow window = pCond->twindows; - SVnodeCfg* pConf = &(((SVnode*)pVnode)->config); - int32_t code = 0; - int32_t lino = 0; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + STimeWindow window = {0}; + SVnodeCfg* pConf = NULL; + STsdbReader* pReader = NULL; + int32_t capacity = 0; - int32_t capacity = pConf->tsdbCfg.maxRows; + window = pCond->twindows; + pConf = &(((SVnode*)pVnode)->config); + + capacity = pConf->tsdbCfg.maxRows; if (pResBlock != NULL) { code = blockDataEnsureCapacity(pResBlock, capacity); - TSDB_CHECK_CODE(code, lino, _err); + TSDB_CHECK_CODE(code, lino, _end); } code = tsdbReaderCreate(pVnode, pCond, ppReader, capacity, pResBlock, idstr); - TSDB_CHECK_CODE(code, lino, _err); + TSDB_CHECK_CODE(code, lino, _end); // check for query time window - STsdbReader* pReader = *ppReader; + pReader = *ppReader; if (isEmptyQueryTimeWindow(&pReader->info.window) && pCond->type == TIMEWINDOW_RANGE_CONTAINED) { tsdbDebug("%p query window not overlaps with the data set, no result returned, %s", pReader, pReader->idStr); - return TSDB_CODE_SUCCESS; + goto _end; } if (pCond->type == TIMEWINDOW_RANGE_EXTERNAL) { @@ -4777,7 +5541,7 @@ int32_t tsdbReaderOpen2(void* pVnode, SQueryTableDataCond* pCond, void* pTableLi // here we only need one more row, so the capacity is set to be ONE. code = tsdbReaderCreate(pVnode, pCond, (void**)&((STsdbReader*)pReader)->innerReader[0], 1, pResBlock, idstr); - TSDB_CHECK_CODE(code, lino, _err); + TSDB_CHECK_CODE(code, lino, _end); if (order == TSDB_ORDER_ASC) { pCond->twindows.skey = window.ekey + 1; @@ -4789,7 +5553,7 @@ int32_t tsdbReaderOpen2(void* pVnode, SQueryTableDataCond* pCond, void* pTableLi pCond->order = order; code = tsdbReaderCreate(pVnode, pCond, (void**)&((STsdbReader*)pReader)->innerReader[1], 1, pResBlock, idstr); - TSDB_CHECK_CODE(code, lino, _err); + TSDB_CHECK_CODE(code, lino, _end); } // NOTE: the endVersion in pCond is the data version not schema version, so pCond->endVersion is not correct here. @@ -4797,14 +5561,14 @@ int32_t tsdbReaderOpen2(void* pVnode, SQueryTableDataCond* pCond, void* pTableLi // we should proceed in case of tmq processing. if (pCond->suid != 0) { code = metaGetTbTSchemaMaybeNull(pReader->pTsdb->pVnode->pMeta, pReader->info.suid, -1, 1, &pReader->info.pSchema); - TSDB_CHECK_CODE(code, lino, _err); + TSDB_CHECK_CODE(code, lino, _end); if (pReader->info.pSchema == NULL) { tsdbWarn("failed to get table schema, suid:%" PRIu64 ", ver:-1, %s", pReader->info.suid, pReader->idStr); } } else if (numOfTables > 0) { STableKeyInfo* pKey = pTableList; code = metaGetTbTSchemaMaybeNull(pReader->pTsdb->pVnode->pMeta, pKey->uid, -1, 1, &pReader->info.pSchema); - TSDB_CHECK_CODE(code, lino, _err); + TSDB_CHECK_CODE(code, lino, _end); if (pReader->info.pSchema == NULL) { tsdbWarn("failed to get table schema, uid:%" PRIu64 ", ver:-1, %s", pKey->uid, pReader->idStr); } @@ -4812,28 +5576,29 @@ int32_t tsdbReaderOpen2(void* pVnode, SQueryTableDataCond* pCond, void* pTableLi if (pReader->info.pSchema != NULL) { code = tsdbRowMergerInit(&pReader->status.merger, pReader->info.pSchema); - TSDB_CHECK_CODE(code, lino, _err); + TSDB_CHECK_CODE(code, lino, _end); } pReader->pSchemaMap = tSimpleHashInit(8, taosFastHash); if (pReader->pSchemaMap == NULL) { tsdbError("failed init schema hash for reader %s", pReader->idStr); - TSDB_CHECK_NULL(pReader->pSchemaMap, code, lino, _err, terrno); + TSDB_CHECK_NULL(pReader->pSchemaMap, code, lino, _end, terrno); } tSimpleHashSetFreeFp(pReader->pSchemaMap, freeSchemaFunc); if (pReader->info.pSchema != NULL) { code = updateBlockSMAInfo(pReader->info.pSchema, &pReader->suppInfo); - TSDB_CHECK_CODE(code, lino, _err); + TSDB_CHECK_CODE(code, lino, _end); } STsdbReader* p = (pReader->innerReader[0] != NULL) ? pReader->innerReader[0] : pReader; - code = createDataBlockScanInfo(p, &pReader->blockInfoBuf, pTableList, &pReader->status.uidList, numOfTables, &pReader->status.pTableMap); - TSDB_CHECK_CODE(code, lino, _err); + code = createDataBlockScanInfo(p, &pReader->blockInfoBuf, pTableList, &pReader->status.uidList, numOfTables, + &pReader->status.pTableMap); + TSDB_CHECK_CODE(code, lino, _end); pReader->status.pLDataIterArray = taosArrayInit(4, POINTER_BYTES); - TSDB_CHECK_NULL(pReader->status.pLDataIterArray, code, lino, _err, terrno); + TSDB_CHECK_NULL(pReader->status.pLDataIterArray, code, lino, _end, terrno); pReader->flag = READER_STATUS_SUSPEND; pReader->info.execMode = pCond->notLoadData ? READER_EXEC_ROWS : READER_EXEC_DATA; @@ -4844,12 +5609,12 @@ int32_t tsdbReaderOpen2(void* pVnode, SQueryTableDataCond* pCond, void* pTableLi pReader, numOfTables, pReader->info.window.skey, pReader->info.window.ekey, pReader->info.verRange.minVer, pReader->info.verRange.maxVer, pReader->idStr); - return code; - -_err: - tsdbError("failed to create data reader, error at:%d code:%s %s", lino, tstrerror(code), idstr); - tsdbReaderClose2(*ppReader); - *ppReader = NULL; // reset the pointer value. +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s, %s", __func__, lino, tstrerror(code), idstr); + tsdbReaderClose2(*ppReader); + *ppReader = NULL; // reset the pointer value. + } return code; } @@ -4898,8 +5663,7 @@ void tsdbReaderClose2(STsdbReader* pReader) { size_t numOfTables = tSimpleHashGetSize(pReader->status.pTableMap); if (pReader->status.pTableMap != NULL) { - destroyAllBlockScanInfo(pReader->status.pTableMap); - pReader->status.pTableMap = NULL; + destroyAllBlockScanInfo(&pReader->status.pTableMap); } clearBlockScanInfoBuf(&pReader->blockInfoBuf); @@ -4918,6 +5682,7 @@ void tsdbReaderClose2(STsdbReader* pReader) { } destroySttBlockReader(pReader->status.pLDataIterArray, &pCost->sttCost); + pReader->status.pLDataIterArray = NULL; taosMemoryFreeClear(pReader->status.uidList.tableUidList); tsdbTrace("tsdb/reader-close: %p, untake snapshot", pReader); @@ -4955,7 +5720,14 @@ void tsdbReaderClose2(STsdbReader* pReader) { } static int32_t doSuspendCurrentReader(STsdbReader* pCurrentReader) { - SReaderStatus* pStatus = &pCurrentReader->status; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SReaderStatus* pStatus = NULL; + STableBlockScanInfo** p = NULL; + + TSDB_CHECK_NULL(pCurrentReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pStatus = &pCurrentReader->status; if (pStatus->loadFromFile) { tsdbDataFileReaderClose(&pCurrentReader->pFileReader); @@ -4963,14 +5735,10 @@ static int32_t doSuspendCurrentReader(STsdbReader* pCurrentReader) { SReadCostSummary* pCost = &pCurrentReader->cost; destroySttBlockReader(pStatus->pLDataIterArray, &pCost->sttCost); pStatus->pLDataIterArray = taosArrayInit(4, POINTER_BYTES); - if (pStatus->pLDataIterArray == NULL) { - return terrno; - } + TSDB_CHECK_NULL(pStatus->pLDataIterArray, code, lino, _end, terrno); } // resetDataBlockScanInfo excluding lastKey - STableBlockScanInfo** p = NULL; - int32_t step = ASCENDING_TRAVERSE(pCurrentReader->info.order) ? 1 : -1; int32_t iter = 0; while ((p = tSimpleHashIterate(pStatus->pTableMap, p, &iter)) != NULL) { @@ -4983,12 +5751,20 @@ static int32_t doSuspendCurrentReader(STsdbReader* pCurrentReader) { pStatus->uidList.currentIndex = 0; initReaderStatus(pStatus); - return TSDB_CODE_SUCCESS; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } int32_t tsdbReaderSuspend2(STsdbReader* pReader) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + // save reader's base state & reset top state to be reconstructed from base state - int32_t code = 0; pReader->status.suspendInvoked = true; // record the suspend status if (pReader->type == TIMEWINDOW_RANGE_EXTERNAL) { @@ -5005,6 +5781,7 @@ int32_t tsdbReaderSuspend2(STsdbReader* pReader) { // make sure only release once void* p = pReader->pReadSnap; + TSDB_CHECK_NULL(p, code, lino, _end, TSDB_CODE_INVALID_PARA); if ((p == atomic_val_compare_exchange_ptr((void**)&pReader->pReadSnap, p, NULL)) && (p != NULL)) { tsdbUntakeReadSnap2(pReader, p, false); pReader->pReadSnap = NULL; @@ -5026,6 +5803,11 @@ int32_t tsdbReaderSuspend2(STsdbReader* pReader) { #endif tsdbDebug("reader: %p suspended in this query %s, step:%d", pReader, pReader->idStr, pReader->step); + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } @@ -5041,7 +5823,7 @@ static int32_t tsdbSetQueryReseek(void* pQHandle) { } code = tsdbReaderSuspend2(pReader); - (void) tsdbReleaseReader(pReader); + (void)tsdbReleaseReader(pReader); return code; } else if (code == EBUSY) { return TSDB_CODE_VND_QUERY_BUSY; @@ -5052,17 +5834,21 @@ static int32_t tsdbSetQueryReseek(void* pQHandle) { } int32_t tsdbReaderResume2(STsdbReader* pReader) { - int32_t code = 0; - STableBlockScanInfo** pBlockScanInfo = pReader->status.pTableIter; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + STableBlockScanInfo** pBlockScanInfo = NULL; + int32_t numOfTables = 0; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pBlockScanInfo = pReader->status.pTableIter; // restore reader's state, task snapshot - int32_t numOfTables = tSimpleHashGetSize(pReader->status.pTableMap); + numOfTables = tSimpleHashGetSize(pReader->status.pTableMap); if (numOfTables > 0) { tsdbTrace("tsdb/reader: %p, take snapshot", pReader); code = tsdbTakeReadSnap2(pReader, tsdbSetQueryReseek, &pReader->pReadSnap, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - goto _err; - } + TSDB_CHECK_CODE(code, lino, _end); // open reader failure may cause the flag still to be READER_STATUS_SUSPEND, which may cause suspend reader failure. // So we need to set it A.S.A.P @@ -5070,9 +5856,7 @@ int32_t tsdbReaderResume2(STsdbReader* pReader) { if (pReader->type == TIMEWINDOW_RANGE_CONTAINED) { code = doOpenReaderImpl(pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } else { STsdbReader* pPrevReader = pReader->innerReader[0]; STsdbReader* pNextReader = pReader->innerReader[1]; @@ -5080,54 +5864,55 @@ int32_t tsdbReaderResume2(STsdbReader* pReader) { // we need only one row pPrevReader->resBlockInfo.capacity = 1; code = setSharedPtr(pPrevReader, pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); pNextReader->resBlockInfo.capacity = 1; code = setSharedPtr(pNextReader, pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if (pReader->step == 0 || pReader->step == EXTERNAL_ROWS_PREV) { code = doOpenReaderImpl(pPrevReader); + TSDB_CHECK_CODE(code, lino, _end); } else if (pReader->step == EXTERNAL_ROWS_MAIN) { code = doOpenReaderImpl(pReader); + TSDB_CHECK_CODE(code, lino, _end); } else { code = doOpenReaderImpl(pNextReader); - } - - if (code != TSDB_CODE_SUCCESS) { - return code; + TSDB_CHECK_CODE(code, lino, _end); } } } tsdbDebug("reader: %p resumed uid %" PRIu64 ", numOfTable:%" PRId32 ", in this query %s", pReader, pBlockScanInfo ? (*pBlockScanInfo)->uid : 0, numOfTables, pReader->idStr); - return code; -_err: - tsdbError("failed to resume data reader, code:%s %s", tstrerror(code), pReader->idStr); +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s, %s", __func__, lino, tstrerror(code), + (pReader && pReader->idStr) ? pReader->idStr : ""); + } return code; } static int32_t buildFromPreFilesetBuffer(STsdbReader* pReader) { int32_t code = TSDB_CODE_SUCCESS; - SReaderStatus* pStatus = &pReader->status; + int32_t lino = 0; + SReaderStatus* pStatus = NULL; + SSDataBlock* pBlock = NULL; + int32_t fid = 0; + STimeWindow win = {0}; - SSDataBlock* pBlock = pReader->resBlockInfo.pResBlock; + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); - int32_t fid = pReader->status.pCurrentFileset->fid; - STimeWindow win = {0}; + pStatus = &pReader->status; + pBlock = pReader->resBlockInfo.pResBlock; + fid = pReader->status.pCurrentFileset->fid; tsdbFidKeyRange(fid, pReader->pTsdb->keepCfg.days, pReader->pTsdb->keepCfg.precision, &win.skey, &win.ekey); int64_t endKey = (ASCENDING_TRAVERSE(pReader->info.order)) ? win.skey : win.ekey; code = buildBlockFromBufferSeqForPreFileset(pReader, endKey); - if (code != TSDB_CODE_SUCCESS || pBlock->info.rows > 0) { - return code; - } else { + TSDB_CHECK_CODE(code, lino, _end); + if (pBlock->info.rows <= 0) { tsdbDebug("finished pre-fileset %d buffer processing. %s", fid, pReader->idStr); pStatus->bProcMemPreFileset = false; pStatus->processingMemPreFileSet = false; @@ -5138,26 +5923,36 @@ static int32_t buildFromPreFilesetBuffer(STsdbReader* pReader) { tsdbDebug("new duration %d start notification when buffer pre-fileset, %s", fid, pReader->idStr); } } + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } static int32_t doTsdbNextDataBlockFilesetDelimited(STsdbReader* pReader) { - SReaderStatus* pStatus = &pReader->status; int32_t code = TSDB_CODE_SUCCESS; - SSDataBlock* pBlock = pReader->resBlockInfo.pResBlock; + int32_t lino = 0; + SReaderStatus* pStatus = NULL; + SSDataBlock* pBlock = NULL; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pStatus = &pReader->status; + pBlock = pReader->resBlockInfo.pResBlock; if (pStatus->loadFromFile) { if (pStatus->bProcMemPreFileset) { code = buildFromPreFilesetBuffer(pReader); - if (code != TSDB_CODE_SUCCESS || pBlock->info.rows > 0) { - return code; + TSDB_CHECK_CODE(code, lino, _end); + if (pBlock->info.rows > 0) { + goto _end; } } code = buildBlockFromFiles(pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); tsdbTrace("block from file rows: %" PRId64 ", will process pre-file set buffer: %d. %s", pBlock->info.rows, pStatus->bProcMemFirstFileset, pReader->idStr); @@ -5176,59 +5971,77 @@ static int32_t doTsdbNextDataBlockFilesetDelimited(STsdbReader* pReader) { if (pBlock->info.rows <= 0) { code = resetTableListIndex(&pReader->status, pReader->idStr); - if (code) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); int64_t endKey = (ASCENDING_TRAVERSE(pReader->info.order)) ? INT64_MAX : INT64_MIN; code = buildBlockFromBufferSequentially(pReader, endKey); + TSDB_CHECK_CODE(code, lino, _end); } } else { // no data in files, let's try the buffer int64_t endKey = (ASCENDING_TRAVERSE(pReader->info.order)) ? INT64_MAX : INT64_MIN; code = buildBlockFromBufferSequentially(pReader, endKey); + TSDB_CHECK_CODE(code, lino, _end); + } + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); } return code; } static int32_t doTsdbNextDataBlockFilesFirst(STsdbReader* pReader) { - SReaderStatus* pStatus = &pReader->status; int32_t code = TSDB_CODE_SUCCESS; - SSDataBlock* pBlock = pReader->resBlockInfo.pResBlock; + int32_t lino = 0; + SReaderStatus* pStatus = NULL; + SSDataBlock* pBlock = NULL; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pStatus = &pReader->status; + pBlock = pReader->resBlockInfo.pResBlock; if (pStatus->loadFromFile) { code = buildBlockFromFiles(pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if (pBlock->info.rows <= 0) { code = resetTableListIndex(&pReader->status, pReader->idStr); - if (code) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); int64_t endKey = (ASCENDING_TRAVERSE(pReader->info.order)) ? INT64_MAX : INT64_MIN; code = buildBlockFromBufferSequentially(pReader, endKey); + TSDB_CHECK_CODE(code, lino, _end); } } else { // no data in files, let's try the buffer int64_t endKey = (ASCENDING_TRAVERSE(pReader->info.order)) ? INT64_MAX : INT64_MIN; code = buildBlockFromBufferSequentially(pReader, endKey); + TSDB_CHECK_CODE(code, lino, _end); + } + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); } return code; } static int32_t doTsdbNextDataBlock2(STsdbReader* pReader, bool* hasNext) { - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SSDataBlock* pBlock = NULL; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); // cleanup the data that belongs to the previous data block - SSDataBlock* pBlock = pReader->resBlockInfo.pResBlock; + pBlock = pReader->resBlockInfo.pResBlock; blockDataCleanup(pBlock); *hasNext = false; SReaderStatus* pStatus = &pReader->status; if (tSimpleHashGetSize(pStatus->pTableMap) == 0) { - return code; + goto _end; } if (!pReader->bFilesetDelimited) { @@ -5238,21 +6051,34 @@ static int32_t doTsdbNextDataBlock2(STsdbReader* pReader, bool* hasNext) { } *hasNext = pBlock->info.rows > 0; + TSDB_CHECK_CODE(code, lino, _end); +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } int32_t tsdbNextDataBlock2(STsdbReader* pReader, bool* hasNext) { - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SReaderStatus* pStatus = NULL; + bool acquired = false; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(hasNext, code, lino, _end, TSDB_CODE_INVALID_PARA); *hasNext = false; - if (isEmptyQueryTimeWindow(&pReader->info.window) || pReader->step == EXTERNAL_ROWS_NEXT || - pReader->code != TSDB_CODE_SUCCESS) { - return (pReader->code != TSDB_CODE_SUCCESS) ? pReader->code : code; + code = pReader->code; + TSDB_CHECK_CODE(code, lino, _end); + + if (isEmptyQueryTimeWindow(&pReader->info.window) || pReader->step == EXTERNAL_ROWS_NEXT) { + goto _end; } - SReaderStatus* pStatus = &pReader->status; + pStatus = &pReader->status; // NOTE: the following codes is used to perform test for suspend/resume for tsdbReader when it blocks the commit // the data should be ingested in round-robin and all the child tables should be createted before ingesting data @@ -5265,27 +6091,19 @@ int32_t tsdbNextDataBlock2(STsdbReader* pReader, bool* hasNext) { #endif code = tsdbAcquireReader(pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); + acquired = true; tsdbTrace("tsdb/read: %p, take read mutex, code: %d", pReader, code); if (pReader->flag == READER_STATUS_SUSPEND) { code = tsdbReaderResume2(pReader); - if (code != TSDB_CODE_SUCCESS) { - // release reader failure should be suppressed here, to avoid over-write the original error code - (void) tsdbReleaseReader(pReader); - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } if (pReader->innerReader[0] != NULL && pReader->step == 0) { code = doTsdbNextDataBlock2(pReader->innerReader[0], hasNext); - if (code) { - (void) tsdbReleaseReader(pReader); - return code; - } + TSDB_CHECK_CODE(code, lino, _end); pReader->step = EXTERNAL_ROWS_PREV; if (*hasNext) { @@ -5293,9 +6111,11 @@ int32_t tsdbNextDataBlock2(STsdbReader* pReader, bool* hasNext) { if (pStatus->composedDataBlock) { tsdbTrace("tsdb/read: %p, unlock read mutex", pReader); code = tsdbReleaseReader(pReader); + acquired = false; + TSDB_CHECK_CODE(code, lino, _end); } - return code; + goto _end; } } @@ -5307,27 +6127,22 @@ int32_t tsdbNextDataBlock2(STsdbReader* pReader, bool* hasNext) { int32_t step = 1; resetAllDataBlockScanInfo(pReader->status.pTableMap, pReader->innerReader[0]->info.window.ekey, step); - - if (code != TSDB_CODE_SUCCESS) { - (void) tsdbReleaseReader(pReader); - return code; - } + TSDB_CHECK_CODE(code, lino, _end); pReader->step = EXTERNAL_ROWS_MAIN; } code = doTsdbNextDataBlock2(pReader, hasNext); - if (code != TSDB_CODE_SUCCESS) { - (void) tsdbReleaseReader(pReader); - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if (*hasNext) { if (pStatus->composedDataBlock) { tsdbTrace("tsdb/read: %p, unlock read mutex", pReader); code = tsdbReleaseReader(pReader); + acquired = false; + TSDB_CHECK_CODE(code, lino, _end); } - return code; + goto _end; } if (pReader->step == EXTERNAL_ROWS_MAIN && pReader->innerReader[1] != NULL) { @@ -5338,16 +6153,10 @@ int32_t tsdbNextDataBlock2(STsdbReader* pReader, bool* hasNext) { int32_t step = -1; resetAllDataBlockScanInfo(pReader->innerReader[1]->status.pTableMap, pReader->info.window.ekey, step); - if (code != TSDB_CODE_SUCCESS) { - (void) tsdbReleaseReader(pReader); - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = doTsdbNextDataBlock2(pReader->innerReader[1], hasNext); - if (code != TSDB_CODE_SUCCESS) { - (void) tsdbReleaseReader(pReader); - return code; - } + TSDB_CHECK_CODE(code, lino, _end); pReader->step = EXTERNAL_ROWS_NEXT; if (*hasNext) { @@ -5355,25 +6164,43 @@ int32_t tsdbNextDataBlock2(STsdbReader* pReader, bool* hasNext) { if (pStatus->composedDataBlock) { tsdbTrace("tsdb/read: %p, unlock read mutex", pReader); code = tsdbReleaseReader(pReader); + acquired = false; + TSDB_CHECK_CODE(code, lino, _end); } - return code; + goto _end; } } tsdbTrace("tsdb/read: %p, unlock read mutex", pReader); code = tsdbReleaseReader(pReader); + acquired = false; + TSDB_CHECK_CODE(code, lino, _end); + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + if (acquired) { + tsdbTrace("tsdb/read: %p, unlock read mutex", pReader); + (void)tsdbReleaseReader(pReader); + } return code; } -static void doFillNullColSMA(SBlockLoadSuppInfo* pSup, int32_t numOfRows, int32_t numOfCols, SColumnDataAgg* pTsAgg) { +static int32_t doFillNullColSMA(SBlockLoadSuppInfo* pSup, int32_t numOfRows, int32_t numOfCols, + SColumnDataAgg* pTsAgg) { // do fill all null column value SMA info + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; int32_t i = 0, j = 0; - int32_t size = (int32_t)TARRAY2_SIZE(&pSup->colAggArray); - int32_t code = TARRAY2_INSERT_PTR(&pSup->colAggArray, 0, pTsAgg); - if (code != TSDB_CODE_SUCCESS) { - return; - } + int32_t size = 0; + + TSDB_CHECK_NULL(pSup, code, lino, _end, TSDB_CODE_INVALID_PARA); + + size = (int32_t)TARRAY2_SIZE(&pSup->colAggArray); + code = TARRAY2_INSERT_PTR(&pSup->colAggArray, 0, pTsAgg); + TSDB_CHECK_CODE(code, lino, _end); size++; @@ -5388,9 +6215,7 @@ static void doFillNullColSMA(SBlockLoadSuppInfo* pSup, int32_t numOfRows, int32_ if (pSup->colId[j] != PRIMARYKEY_TIMESTAMP_COL_ID) { SColumnDataAgg nullColAgg = {.colId = pSup->colId[j], .numOfNull = numOfRows}; code = TARRAY2_INSERT_PTR(&pSup->colAggArray, i, &nullColAgg); - if (code != TSDB_CODE_SUCCESS) { - return; - } + TSDB_CHECK_CODE(code, lino, _end); i += 1; size++; @@ -5403,42 +6228,51 @@ static void doFillNullColSMA(SBlockLoadSuppInfo* pSup, int32_t numOfRows, int32_ if (pSup->colId[j] != PRIMARYKEY_TIMESTAMP_COL_ID) { SColumnDataAgg nullColAgg = {.colId = pSup->colId[j], .numOfNull = numOfRows}; code = TARRAY2_INSERT_PTR(&pSup->colAggArray, i, &nullColAgg); - if (code != TSDB_CODE_SUCCESS) { - return; - } + TSDB_CHECK_CODE(code, lino, _end); i += 1; } j++; } + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } int32_t tsdbRetrieveDatablockSMA2(STsdbReader* pReader, SSDataBlock* pDataBlock, bool* allHave, bool* hasNullSMA) { - SColumnDataAgg** pBlockSMA = &pDataBlock->pBlockAgg; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SColumnDataAgg** pBlockSMA = NULL; SFileDataBlockInfo* pBlockInfo = NULL; - int32_t code = 0; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pDataBlock, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(allHave, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pBlockSMA = &pDataBlock->pBlockAgg; *allHave = false; *pBlockSMA = NULL; if (pReader->type == TIMEWINDOW_RANGE_EXTERNAL) { - return TSDB_CODE_SUCCESS; + goto _end; } // there is no statistics data for composed block if (pReader->status.composedDataBlock || (!pReader->suppInfo.smaValid)) { - return TSDB_CODE_SUCCESS; + goto _end; } code = getCurrentBlockInfo(&pReader->status.blockIter, &pBlockInfo, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); SBlockLoadSuppInfo* pSup = &pReader->suppInfo; SSDataBlock* pResBlock = pReader->resBlockInfo.pResBlock; if (pResBlock->info.id.uid != pBlockInfo->uid) { - return TSDB_CODE_SUCCESS; + goto _end; } // int64_t st = taosGetTimestampUs(); @@ -5450,14 +6284,14 @@ int32_t tsdbRetrieveDatablockSMA2(STsdbReader* pReader, SSDataBlock* pDataBlock, if (code != TSDB_CODE_SUCCESS) { tsdbDebug("vgId:%d, failed to load block SMA for uid %" PRIu64 ", code:%s, %s", 0, pBlockInfo->uid, tstrerror(code), pReader->idStr); - return code; + TSDB_CHECK_CODE(code, lino, _end); } if (pSup->colAggArray.size > 0) { *allHave = true; } else { *pBlockSMA = NULL; - return TSDB_CODE_SUCCESS; + goto _end; } // always load the first primary timestamp column data @@ -5474,16 +6308,15 @@ int32_t tsdbRetrieveDatablockSMA2(STsdbReader* pReader, SSDataBlock* pDataBlock, if (pResBlock->pBlockAgg == NULL) { size_t num = taosArrayGetSize(pResBlock->pDataBlock); pResBlock->pBlockAgg = taosMemoryCalloc(num, sizeof(SColumnDataAgg)); - if (pResBlock->pBlockAgg == NULL) { - return terrno; - } + TSDB_CHECK_NULL(pResBlock->pBlockAgg, code, lino, _end, terrno); for (int i = 0; i < num; ++i) { pResBlock->pBlockAgg[i].colId = -1; } } // do fill all null column value SMA info - doFillNullColSMA(pSup, pBlockInfo->numRow, numOfCols, pTsAgg); + code = doFillNullColSMA(pSup, pBlockInfo->numRow, numOfCols, pTsAgg); + TSDB_CHECK_CODE(code, lino, _end); size_t size = pSup->colAggArray.size; @@ -5510,49 +6343,67 @@ int32_t tsdbRetrieveDatablockSMA2(STsdbReader* pReader, SSDataBlock* pDataBlock, pReader->cost.smaLoadTime += 0; // elapsedTime; tsdbDebug("vgId:%d, succeed to load block SMA for uid %" PRIu64 ", %s", 0, pBlockInfo->uid, pReader->idStr); + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } static int32_t doRetrieveDataBlock(STsdbReader* pReader, SSDataBlock** pBlock) { - SReaderStatus* pStatus = &pReader->status; - int32_t code = TSDB_CODE_SUCCESS; - SFileDataBlockInfo* pBlockInfo = NULL; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SReaderStatus* pStatus = NULL; + SFileDataBlockInfo* pBlockInfo = NULL; + STableBlockScanInfo* pBlockScanInfo = NULL; + bool reset = false; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pBlock, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pStatus = &pReader->status; *pBlock = NULL; code = getCurrentBlockInfo(&pStatus->blockIter, &pBlockInfo, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); - if (pReader->code != TSDB_CODE_SUCCESS) { - return pReader->code; - } + code = pReader->code; + TSDB_CHECK_CODE(code, lino, _end); - STableBlockScanInfo* pBlockScanInfo = NULL; code = getTableBlockScanInfo(pStatus->pTableMap, pBlockInfo->uid, &pBlockScanInfo, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); + reset = true; code = doLoadFileBlockData(pReader, &pStatus->blockIter, &pStatus->fileBlockData, pBlockScanInfo->uid); - if (code != TSDB_CODE_SUCCESS) { - tBlockDataReset(&pStatus->fileBlockData); - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = copyBlockDataToSDataBlock(pReader, &pBlockScanInfo->lastProcKey); - if (code != TSDB_CODE_SUCCESS) { - tBlockDataReset(&pStatus->fileBlockData); - } + TSDB_CHECK_CODE(code, lino, _end); *pBlock = pReader->resBlockInfo.pResBlock; + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + if (reset) { + tBlockDataReset(&pStatus->fileBlockData); + } + } return code; } int32_t tsdbRetrieveDataBlock2(STsdbReader* pReader, SSDataBlock** pBlock, SArray* pIdList) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + STsdbReader* pTReader = NULL; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pBlock, code, lino, _end, TSDB_CODE_INVALID_PARA); + *pBlock = NULL; - STsdbReader* pTReader = pReader; + pTReader = pReader; if (pReader->type == TIMEWINDOW_RANGE_EXTERNAL) { if (pReader->step == EXTERNAL_ROWS_PREV) { pTReader = pReader->innerReader[0]; @@ -5566,47 +6417,55 @@ int32_t tsdbRetrieveDataBlock2(STsdbReader* pReader, SSDataBlock** pBlock, SArra // tsdbReaderSuspend2(pReader); // tsdbReaderResume2(pReader); *pBlock = pTReader->resBlockInfo.pResBlock; - return TSDB_CODE_SUCCESS; + goto _end; } - int32_t code = doRetrieveDataBlock(pTReader, pBlock); + code = doRetrieveDataBlock(pTReader, pBlock); tsdbTrace("tsdb/read-retrieve: %p, unlock read mutex", pReader); (void) tsdbReleaseReader(pReader); + TSDB_CHECK_CODE(code, lino, _end); // tsdbReaderSuspend2(pReader); // tsdbReaderResume2(pReader); +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } int32_t tsdbReaderReset2(STsdbReader* pReader, SQueryTableDataCond* pCond) { int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + bool acquired = false; tsdbTrace("tsdb/reader-reset: %p, take read mutex", pReader); code = tsdbAcquireReader(pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); + acquired = true; if (pReader->flag == READER_STATUS_SUSPEND) { code = tsdbReaderResume2(pReader); - if (code != TSDB_CODE_SUCCESS) { - (void) tsdbReleaseReader(pReader); - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } if (isEmptyQueryTimeWindow(&pReader->info.window) || pReader->pReadSnap == NULL) { tsdbDebug("tsdb reader reset return %p, %s", pReader->pReadSnap, pReader->idStr); - return tsdbReleaseReader(pReader); + code = tsdbReleaseReader(pReader); + acquired = false; + TSDB_CHECK_CODE(code, lino, _end); + goto _end; } SReaderStatus* pStatus = &pReader->status; SDataBlockIter* pBlockIter = &pStatus->blockIter; + TSDB_CHECK_NULL(pCond, code, lino, _end, TSDB_CODE_INVALID_PARA); pReader->info.order = pCond->order; pReader->type = TIMEWINDOW_RANGE_CONTAINED; - pReader->info.window = updateQueryTimeWindow(pReader->pTsdb, &pCond->twindows); + code = updateQueryTimeWindow(pReader->pTsdb, &pCond->twindows, &pReader->info.window); + TSDB_CHECK_CODE(code, lino, _end); pStatus->loadFromFile = true; pStatus->pTableIter = NULL; @@ -5619,22 +6478,13 @@ int32_t tsdbReaderReset2(STsdbReader* pReader, SQueryTableDataCond* pCond) { int32_t numOfTables = tSimpleHashGetSize(pStatus->pTableMap); code = initFilesetIterator(&pStatus->fileIter, pReader->pReadSnap->pfSetArray, pReader); - if (code != TSDB_CODE_SUCCESS) { - (void) tsdbReleaseReader(pReader); - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = resetDataBlockIterator(pBlockIter, pReader->info.order, shouldFreePkBuf(&pReader->suppInfo), pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - (void) tsdbReleaseReader(pReader); - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = resetTableListIndex(&pReader->status, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - (void) tsdbReleaseReader(pReader); - return code; - } + TSDB_CHECK_CODE(code, lino, _end); bool asc = ASCENDING_TRAVERSE(pReader->info.order); int32_t step = asc ? 1 : -1; @@ -5650,18 +6500,13 @@ int32_t tsdbReaderReset2(STsdbReader* pReader, SQueryTableDataCond* pCond) { if (pStatus->fileIter.numOfFiles == 0) { pStatus->loadFromFile = false; code = resetTableListIndex(pStatus, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - (void) tsdbReleaseReader(pReader); - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } else { code = initForFirstBlockInFile(pReader, pBlockIter); if (code != TSDB_CODE_SUCCESS) { tsdbError("%p reset reader failed, numOfTables:%d, query range:%" PRId64 " - %" PRId64 " in query %s", pReader, numOfTables, pReader->info.window.skey, pReader->info.window.ekey, pReader->idStr); - - (void) tsdbReleaseReader(pReader); - return code; + TSDB_CHECK_CODE(code, lino, _end); } } @@ -5671,6 +6516,16 @@ int32_t tsdbReaderReset2(STsdbReader* pReader, SQueryTableDataCond* pCond) { pReader->info.window.ekey, pReader->idStr); code = tsdbReleaseReader(pReader); + acquired = false; + TSDB_CHECK_CODE(code, lino, _end); + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + if (acquired) { + (void)tsdbReleaseReader(pReader); + } return code; } @@ -5687,7 +6542,11 @@ static int32_t getBucketIndex(int32_t startRow, int32_t bucketRange, int32_t num int32_t tsdbGetFileBlocksDistInfo2(STsdbReader* pReader, STableBlockDistInfo* pTableBlockInfo) { int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; const int32_t numOfBuckets = 20.0; + bool acquired = false; + + TSDB_CHECK_NULL(pTableBlockInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); pTableBlockInfo->totalSize = 0; pTableBlockInfo->totalRows = 0; @@ -5695,15 +6554,12 @@ int32_t tsdbGetFileBlocksDistInfo2(STsdbReader* pReader, STableBlockDistInfo* pT // find the start data block in file code = tsdbAcquireReader(pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); + acquired = true; if (pReader->flag == READER_STATUS_SUSPEND) { code = tsdbReaderResume2(pReader); - if (code != TSDB_CODE_SUCCESS) { - return tsdbReleaseReader(pReader); - } + TSDB_CHECK_CODE(code, lino, _end); } SMergeTreeConf conf = { @@ -5744,9 +6600,7 @@ int32_t tsdbGetFileBlocksDistInfo2(STsdbReader* pReader, STableBlockDistInfo* pT if (hasNext) { SFileDataBlockInfo* pBlockInfo = NULL; code = getCurrentBlockInfo(pBlockIter, &pBlockInfo, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - break; - } + TSDB_CHECK_CODE(code, lino, _end); int32_t numOfRows = pBlockInfo->numRow; @@ -5765,10 +6619,11 @@ int32_t tsdbGetFileBlocksDistInfo2(STsdbReader* pReader, STableBlockDistInfo* pT int32_t bucketIndex = getBucketIndex(pTableBlockInfo->defMinRows, bucketRange, numOfRows, numOfBuckets); pTableBlockInfo->blockRowsHisto[bucketIndex]++; - hasNext = blockIteratorNext(&pStatus->blockIter, pReader->idStr); + hasNext = blockIteratorNext(&pStatus->blockIter); } else { code = initForFirstBlockInFile(pReader, pBlockIter); - if ((code != TSDB_CODE_SUCCESS) || (pStatus->loadFromFile == false)) { + TSDB_CHECK_CODE(code, lino, _end); + if (pStatus->loadFromFile == false) { break; } @@ -5784,14 +6639,17 @@ int32_t tsdbGetFileBlocksDistInfo2(STsdbReader* pReader, STableBlockDistInfo* pT } // record the data in stt files - (void) tsdbReleaseReader(pReader); +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + if (acquired) { + (void)tsdbReleaseReader(pReader); + } return code; } static void getMemTableTimeRange(STsdbReader* pReader, int64_t* pMaxKey, int64_t* pMinKey) { - int32_t code = TSDB_CODE_SUCCESS; - int64_t rows = 0; - SReaderStatus* pStatus = &pReader->status; int32_t iter = 0; @@ -5836,22 +6694,24 @@ static void getMemTableTimeRange(STsdbReader* pReader, int64_t* pMaxKey, int64_t *pMinKey = minKey; } -int64_t tsdbGetNumOfRowsInMemTable2(STsdbReader* pReader) { - int32_t code = TSDB_CODE_SUCCESS; - int64_t rows = 0; +int64_t tsdbGetNumOfRowsInMemTable2(STsdbReader* pReader, uint32_t* rows) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SReaderStatus* pStatus = NULL; + bool acquired = false; - SReaderStatus* pStatus = &pReader->status; + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(rows, code, lino, _end, TSDB_CODE_INVALID_PARA); + + *rows = 0; + pStatus = &pReader->status; code = tsdbAcquireReader(pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); + acquired = true; if (pReader->flag == READER_STATUS_SUSPEND) { code = tsdbReaderResume2(pReader); - if (code != TSDB_CODE_SUCCESS) { - (void) tsdbReleaseReader(pReader); - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } int32_t iter = 0; @@ -5864,7 +6724,7 @@ int64_t tsdbGetNumOfRowsInMemTable2(STsdbReader* pReader) { if (pReader->pReadSnap->pMem != NULL) { d = tsdbGetTbDataFromMemTable(pReader->pReadSnap->pMem, pReader->info.suid, pBlockScanInfo->uid); if (d != NULL) { - rows += tsdbGetNRowsInTbData(d); + *rows += tsdbGetNRowsInTbData(d); } } @@ -5872,7 +6732,7 @@ int64_t tsdbGetNumOfRowsInMemTable2(STsdbReader* pReader) { if (pReader->pReadSnap->pIMem != NULL) { di = tsdbGetTbDataFromMemTable(pReader->pReadSnap->pIMem, pReader->info.suid, pBlockScanInfo->uid); if (di != NULL) { - rows += tsdbGetNRowsInTbData(di); + *rows += tsdbGetNRowsInTbData(di); } } @@ -5880,9 +6740,14 @@ int64_t tsdbGetNumOfRowsInMemTable2(STsdbReader* pReader) { pStatus->pTableIter = tSimpleHashIterate(pStatus->pTableMap, pStatus->pTableIter, &iter); } - (void) tsdbReleaseReader(pReader); - - return rows; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + if (acquired) { + (void)tsdbReleaseReader(pReader); + } + return code; } int32_t tsdbGetTableSchema(SMeta* pMeta, int64_t uid, STSchema** pSchema, int64_t* suid) { @@ -6037,17 +6902,23 @@ void tsdbUntakeReadSnap2(STsdbReader* pReader, STsdbReadSnap* pSnap, bool proact // if failed, do nothing int32_t tsdbReaderSetId(void* p, const char* idstr) { - STsdbReader* pReader = (STsdbReader*) p; - taosMemoryFreeClear(pReader->idStr); + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + STsdbReader* pReader = (STsdbReader*)p; + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + taosMemoryFreeClear(pReader->idStr); pReader->idStr = taosStrdup(idstr); - if (pReader->idStr == NULL) { - tsdbError("%s failed to build reader id, code:%s", idstr, tstrerror(terrno)); - return terrno; - } + TSDB_CHECK_NULL(pReader->idStr, code, lino, _end, terrno); pReader->status.fileIter.pSttBlockReader->mergeTree.idStr = pReader->idStr; - return 0; + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } void tsdbReaderSetCloseFlag(STsdbReader* pReader) { /*pReader->code = TSDB_CODE_TSC_QUERY_CANCELLED;*/ } diff --git a/source/dnode/vnode/src/tsdb/tsdbReadUtil.c b/source/dnode/vnode/src/tsdb/tsdbReadUtil.c index a65fc7f3ed..5f77d03efc 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReadUtil.c +++ b/source/dnode/vnode/src/tsdb/tsdbReadUtil.c @@ -25,47 +25,57 @@ static bool overlapWithDelSkylineWithoutVer(STableBlockScanInfo* pBlockScanInfo, int32_t order); static int32_t initBlockScanInfoBuf(SBlockInfoBuf* pBuf, int32_t numOfTables) { - int32_t num = numOfTables / pBuf->numPerBucket; - int32_t remainder = numOfTables % pBuf->numPerBucket; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + int32_t num = 0; + int32_t remainder = 0; + STableBlockScanInfo* p = NULL; + const void* px = NULL; + + TSDB_CHECK_CONDITION(pBuf && pBuf->numPerBucket > 0, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_CONDITION(numOfTables >= 0, code, lino, _end, TSDB_CODE_INVALID_PARA); + + num = numOfTables / pBuf->numPerBucket; + remainder = numOfTables % pBuf->numPerBucket; if (pBuf->pData == NULL) { pBuf->pData = taosArrayInit(num + 1, POINTER_BYTES); - if (pBuf->pData == NULL) { - return terrno; - } + TSDB_CHECK_NULL(pBuf->pData, code, lino, _end, terrno); } for (int32_t i = 0; i < num; ++i) { - char* p = taosMemoryCalloc(pBuf->numPerBucket, sizeof(STableBlockScanInfo)); - if (p == NULL) { - return terrno; - } + p = taosMemoryCalloc(pBuf->numPerBucket, sizeof(STableBlockScanInfo)); + TSDB_CHECK_NULL(p, code, lino, _end, terrno); - void* px = taosArrayPush(pBuf->pData, &p); - if (px == NULL) { - return terrno; - } + px = taosArrayPush(pBuf->pData, &p); + TSDB_CHECK_NULL(px, code, lino, _end, terrno); + p = NULL; } if (remainder > 0) { - char* p = taosMemoryCalloc(remainder, sizeof(STableBlockScanInfo)); - if (p == NULL) { - return terrno; - } - void* px = taosArrayPush(pBuf->pData, &p); - if (px == NULL) { - return terrno; - } + p = taosMemoryCalloc(remainder, sizeof(STableBlockScanInfo)); + TSDB_CHECK_NULL(p, code, lino, _end, terrno); + + px = taosArrayPush(pBuf->pData, &p); + TSDB_CHECK_NULL(px, code, lino, _end, terrno); + p = NULL; } pBuf->numOfTables = numOfTables; - return TSDB_CODE_SUCCESS; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + if (p) { + taosMemoryFreeClear(p); + } + return code; } int32_t uidComparFunc(const void* p1, const void* p2) { - uint64_t pu1 = *(uint64_t*)p1; - uint64_t pu2 = *(uint64_t*)p2; + uint64_t pu1 = *(const uint64_t*)p1; + uint64_t pu2 = *(const uint64_t*)p2; if (pu1 == pu2) { return 0; } else { @@ -74,90 +84,133 @@ int32_t uidComparFunc(const void* p1, const void* p2) { } int32_t ensureBlockScanInfoBuf(SBlockInfoBuf* pBuf, int32_t numOfTables) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + int32_t num = 0; + int32_t remainder = 0; + STableBlockScanInfo* p = NULL; + const void* px = NULL; + + TSDB_CHECK_CONDITION(pBuf && pBuf->numPerBucket > 0 && pBuf->numOfTables >= 0, code, lino, _end, + TSDB_CODE_INVALID_PARA); + TSDB_CHECK_CONDITION(numOfTables >= 0, code, lino, _end, TSDB_CODE_INVALID_PARA); + if (numOfTables <= pBuf->numOfTables) { - return TSDB_CODE_SUCCESS; + goto _end; } - if (pBuf->numOfTables > 0) { - STableBlockScanInfo** p = (STableBlockScanInfo**)taosArrayPop(pBuf->pData); - taosMemoryFree(*p); - pBuf->numOfTables /= pBuf->numPerBucket; + remainder = pBuf->numOfTables % pBuf->numPerBucket; + if (remainder > 0) { + TSDB_CHECK_CONDITION(taosArrayGetSize(pBuf->pData) > 0, code, lino, _end, TSDB_CODE_INVALID_PARA); + px = taosArrayPop(pBuf->pData); + TSDB_CHECK_NULL(px, code, lino, _end, TSDB_CODE_INVALID_PARA); + p = *(STableBlockScanInfo**)px; + taosMemoryFreeClear(p); + pBuf->numOfTables -= remainder; } - int32_t num = (numOfTables - pBuf->numOfTables) / pBuf->numPerBucket; - int32_t remainder = (numOfTables - pBuf->numOfTables) % pBuf->numPerBucket; + num = (numOfTables - pBuf->numOfTables) / pBuf->numPerBucket; + remainder = (numOfTables - pBuf->numOfTables) % pBuf->numPerBucket; + if (pBuf->pData == NULL) { pBuf->pData = taosArrayInit(num + 1, POINTER_BYTES); - if (pBuf->pData == NULL) { - return terrno; - } + TSDB_CHECK_NULL(pBuf->pData, code, lino, _end, terrno); } for (int32_t i = 0; i < num; ++i) { - char* p = taosMemoryCalloc(pBuf->numPerBucket, sizeof(STableBlockScanInfo)); - if (p == NULL) { - return terrno; - } + p = taosMemoryCalloc(pBuf->numPerBucket, sizeof(STableBlockScanInfo)); + TSDB_CHECK_NULL(p, code, lino, _end, terrno); - void* px = taosArrayPush(pBuf->pData, &p); - if (px == NULL) { - return terrno; - } + px = taosArrayPush(pBuf->pData, &p); + TSDB_CHECK_NULL(px, code, lino, _end, terrno); + p = NULL; } if (remainder > 0) { - char* p = taosMemoryCalloc(remainder, sizeof(STableBlockScanInfo)); - if (p == NULL) { - return terrno; - } - void* px = taosArrayPush(pBuf->pData, &p); - if (px == NULL) { - return terrno; - } + p = taosMemoryCalloc(remainder, sizeof(STableBlockScanInfo)); + TSDB_CHECK_NULL(p, code, lino, _end, terrno); + + px = taosArrayPush(pBuf->pData, &p); + TSDB_CHECK_NULL(px, code, lino, _end, terrno); + p = NULL; } pBuf->numOfTables = numOfTables; - return TSDB_CODE_SUCCESS; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + if (p) { + taosMemoryFreeClear(p); + } + return code; } void clearBlockScanInfoBuf(SBlockInfoBuf* pBuf) { - size_t num = taosArrayGetSize(pBuf->pData); - for (int32_t i = 0; i < num; ++i) { - char** p = taosArrayGet(pBuf->pData, i); - if (p != NULL) { - taosMemoryFree(*p); - } + if (pBuf == NULL) return; + if (pBuf->pData != NULL) { + taosArrayDestroyP(pBuf->pData, (FDelete)taosMemoryFree); + pBuf->pData = NULL; } - - taosArrayDestroy(pBuf->pData); } int32_t getPosInBlockInfoBuf(SBlockInfoBuf* pBuf, int32_t index, STableBlockScanInfo** pInfo) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + int32_t bucketIndex = 0; + STableBlockScanInfo** pBucket = NULL; + + TSDB_CHECK_CONDITION(pBuf && pBuf->numPerBucket > 0, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_CONDITION(index >= 0 && index < pBuf->numOfTables, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + *pInfo = NULL; - int32_t bucketIndex = index / pBuf->numPerBucket; - char** pBucket = taosArrayGet(pBuf->pData, bucketIndex); - if (pBucket == NULL) { - return TSDB_CODE_NOT_FOUND; - } + bucketIndex = index / pBuf->numPerBucket; + pBucket = taosArrayGet(pBuf->pData, bucketIndex); + TSDB_CHECK_NULL(pBucket, code, lino, _end, terrno); - *pInfo = (STableBlockScanInfo*)((*pBucket) + (index % pBuf->numPerBucket) * sizeof(STableBlockScanInfo)); - return TSDB_CODE_SUCCESS; + *pInfo = (*pBucket) + (index % pBuf->numPerBucket); + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } int32_t getTableBlockScanInfo(SSHashObj* pTableMap, uint64_t uid, STableBlockScanInfo** pInfo, const char* id) { - *pInfo = *(STableBlockScanInfo**)tSimpleHashGet(pTableMap, &uid, sizeof(uid)); - if (pInfo == NULL) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + STableBlockScanInfo** pVal = NULL; + + TSDB_CHECK_NULL(pInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(id, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pVal = (STableBlockScanInfo**)tSimpleHashGet(pTableMap, &uid, sizeof(uid)); + if (pVal == NULL) { int32_t size = tSimpleHashGetSize(pTableMap); tsdbError("failed to locate the uid:%" PRIu64 " in query table uid list, total tables:%d, %s", uid, size, id); - return TSDB_CODE_INVALID_PARA; + code = TSDB_CODE_INVALID_PARA; + TSDB_CHECK_CODE(code, lino, _end); } + *pInfo = *pVal; + TSDB_CHECK_NULL(*pInfo, code, lino, _end, TSDB_CODE_INTERNAL_ERROR); - return TSDB_CODE_SUCCESS; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } int32_t initRowKey(SRowKey* pKey, int64_t ts, int32_t numOfPks, int32_t type, int32_t len, bool asc) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + + TSDB_CHECK_NULL(pKey, code, lino, _end, TSDB_CODE_INVALID_PARA); + pKey->numOfPKs = numOfPks; pKey->ts = ts; @@ -194,7 +247,8 @@ int32_t initRowKey(SRowKey* pKey, int64_t ts, int32_t numOfPks, int32_t type, in break; } default: - return TSDB_CODE_INVALID_PARA; + code = TSDB_CODE_INVALID_PARA; + TSDB_CHECK_CODE(code, lino, _end); } } else { switch (type) { @@ -223,16 +277,14 @@ int32_t initRowKey(SRowKey* pKey, int64_t ts, int32_t numOfPks, int32_t type, in pKey->pks[0].val = UINT8_MAX; break; default: - return TSDB_CODE_INVALID_PARA; + code = TSDB_CODE_INVALID_PARA; + TSDB_CHECK_CODE(code, lino, _end); } } } else { - pKey->pks[0].pData = taosMemoryCalloc(1, len); pKey->pks[0].nData = 0; - - if (pKey->pks[0].pData == NULL) { - return terrno; - } + pKey->pks[0].pData = taosMemoryCalloc(1, len); + TSDB_CHECK_NULL(pKey->pks[0].pData, code, lino, _end, terrno); if (!asc) { pKey->numOfPKs = 2; @@ -240,7 +292,11 @@ int32_t initRowKey(SRowKey* pKey, int64_t ts, int32_t numOfPks, int32_t type, in } } - return TSDB_CODE_SUCCESS; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } void clearRowKey(SRowKey* pKey) { @@ -250,53 +306,65 @@ void clearRowKey(SRowKey* pKey) { taosMemoryFreeClear(pKey->pks[0].pData); } -static int32_t initLastProcKey(STableBlockScanInfo* pScanInfo, STsdbReader* pReader) { - int32_t code = 0; - int32_t numOfPks = pReader->suppInfo.numOfPks; - bool asc = ASCENDING_TRAVERSE(pReader->info.order); - int8_t type = pReader->suppInfo.pk.type; - int32_t bytes = pReader->suppInfo.pk.bytes; +static int32_t initLastProcKey(STableBlockScanInfo* pScanInfo, const STsdbReader* pReader) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + int32_t numOfPks = 0; + int32_t type = 0; + int32_t bytes = 0; + bool asc = false; + SRowKey* pRowKey = NULL; - SRowKey* pRowKey = &pScanInfo->lastProcKey; + TSDB_CHECK_NULL(pScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + numOfPks = pReader->suppInfo.numOfPks; + asc = ASCENDING_TRAVERSE(pReader->info.order); + type = pReader->suppInfo.pk.type; + bytes = pReader->suppInfo.pk.bytes; + + pRowKey = &pScanInfo->lastProcKey; if (asc) { int64_t skey = pReader->info.window.skey; int64_t ts = (skey > INT64_MIN) ? (skey - 1) : skey; code = initRowKey(pRowKey, ts, numOfPks, type, bytes, asc); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = initRowKey(&pScanInfo->sttKeyInfo.nextProcKey, skey, numOfPks, type, bytes, asc); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } else { int64_t ekey = pReader->info.window.ekey; int64_t ts = (ekey < INT64_MAX) ? (ekey + 1) : ekey; code = initRowKey(pRowKey, ts, numOfPks, type, bytes, asc); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = initRowKey(&pScanInfo->sttKeyInfo.nextProcKey, ekey, numOfPks, type, bytes, asc); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } code = initRowKey(&pScanInfo->sttRange.skey, INT64_MAX, numOfPks, type, bytes, asc); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); code = initRowKey(&pScanInfo->sttRange.ekey, INT64_MIN, numOfPks, type, bytes, asc); + TSDB_CHECK_CODE(code, lino, _end); + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } int32_t initTableBlockScanInfo(STableBlockScanInfo* pScanInfo, uint64_t uid, SSHashObj* pTableMap, STsdbReader* pReader) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + + TSDB_CHECK_NULL(pScanInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + pScanInfo->uid = uid; INIT_KEYRANGE(&pScanInfo->sttRange); INIT_TIMEWINDOW(&pScanInfo->filesetWindow); @@ -304,46 +372,52 @@ int32_t initTableBlockScanInfo(STableBlockScanInfo* pScanInfo, uint64_t uid, SSH pScanInfo->cleanSttBlocks = false; pScanInfo->sttBlockReturned = false; - int32_t code = initLastProcKey(pScanInfo, pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + code = initLastProcKey(pScanInfo, pReader); + TSDB_CHECK_CODE(code, lino, _end); pScanInfo->sttKeyInfo.status = STT_FILE_READER_UNINIT; code = tSimpleHashPut(pTableMap, &pScanInfo->uid, sizeof(uint64_t), &pScanInfo, POINTER_BYTES); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); tsdbTrace("%p check table uid:%" PRId64 " from lastKey:%" PRId64 " %s", pReader, pScanInfo->uid, pScanInfo->lastProcKey.ts, pReader->idStr); + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } // NOTE: speedup the whole processing by preparing the buffer for STableBlockScanInfo in batch model int32_t createDataBlockScanInfo(STsdbReader* pTsdbReader, SBlockInfoBuf* pBuf, const STableKeyInfo* idList, STableUidList* pUidList, int32_t numOfTables, SSHashObj** pHashObj) { - int32_t code = 0; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SSHashObj* pTableMap = NULL; + int64_t st = 0; + + TSDB_CHECK_NULL(pUidList, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pHashObj, code, lino, _end, TSDB_CODE_INVALID_PARA); + *pHashObj = NULL; // allocate buffer in order to load data blocks from file // todo use simple hash instead, optimize the memory consumption - SSHashObj* pTableMap = tSimpleHashInit(numOfTables, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT)); - if (pTableMap == NULL) { - return terrno; - } + pTableMap = tSimpleHashInit(numOfTables, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT)); + TSDB_CHECK_NULL(pTableMap, code, lino, _end, terrno); - int64_t st = taosGetTimestampUs(); + st = taosGetTimestampUs(); code = initBlockScanInfoBuf(pBuf, numOfTables); if (code != TSDB_CODE_SUCCESS) { tSimpleHashCleanup(pTableMap); - return code; + TSDB_CHECK_CODE(code, lino, _end); } pUidList->tableUidList = taosMemoryMalloc(numOfTables * sizeof(uint64_t)); if (pUidList->tableUidList == NULL) { tSimpleHashCleanup(pTableMap); - return terrno; + TSDB_CHECK_NULL(pUidList->tableUidList, code, lino, _end, terrno); } pUidList->currentIndex = 0; @@ -354,11 +428,13 @@ int32_t createDataBlockScanInfo(STsdbReader* pTsdbReader, SBlockInfoBuf* pBuf, c STableBlockScanInfo* pScanInfo = NULL; code = getPosInBlockInfoBuf(pBuf, j, &pScanInfo); if (code != TSDB_CODE_SUCCESS) { + lino = __LINE__; break; } code = initTableBlockScanInfo(pScanInfo, idList[j].uid, pTableMap, pTsdbReader); if (code != TSDB_CODE_SUCCESS) { + lino = __LINE__; break; } } @@ -371,15 +447,23 @@ int32_t createDataBlockScanInfo(STsdbReader* pTsdbReader, SBlockInfoBuf* pBuf, c pTsdbReader->idStr); *pHashObj = pTableMap; + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } void resetAllDataBlockScanInfo(SSHashObj* pTableMap, int64_t ts, int32_t step) { - void* p = NULL; - int32_t iter = 0; + STableBlockScanInfo** p = NULL; + int32_t iter = 0; while ((p = tSimpleHashIterate(pTableMap, p, &iter)) != NULL) { - STableBlockScanInfo* pInfo = *(STableBlockScanInfo**)p; + STableBlockScanInfo* pInfo = *p; + if (pInfo == NULL) { + continue; + } pInfo->iterInit = false; pInfo->iter.hasVal = false; @@ -402,6 +486,10 @@ void resetAllDataBlockScanInfo(SSHashObj* pTableMap, int64_t ts, int32_t step) { } void clearBlockScanInfo(STableBlockScanInfo* p) { + if (p == NULL) { + return; + } + p->iterInit = false; p->iter.hasVal = false; p->iiter.hasVal = false; @@ -432,18 +520,26 @@ void clearBlockScanInfo(STableBlockScanInfo* p) { clearRowKey(&p->sttKeyInfo.nextProcKey); } -void destroyAllBlockScanInfo(SSHashObj* pTableMap) { - void* p = NULL; - int32_t iter = 0; +void destroyAllBlockScanInfo(SSHashObj** pTableMap) { + STableBlockScanInfo** p = NULL; + int32_t iter = 0; - while ((p = tSimpleHashIterate(pTableMap, p, &iter)) != NULL) { - clearBlockScanInfo(*(STableBlockScanInfo**)p); + if (pTableMap == NULL || *pTableMap == NULL) { + return; } - tSimpleHashCleanup(pTableMap); + while ((p = tSimpleHashIterate(*pTableMap, p, &iter)) != NULL) { + clearBlockScanInfo(*p); + } + + tSimpleHashCleanup(*pTableMap); + *pTableMap = NULL; } static void doCleanupInfoForNextFileset(STableBlockScanInfo* pScanInfo) { + if (pScanInfo == NULL) { + return; + } // reset the index in last block when handing a new file taosArrayClear(pScanInfo->pBlockList); taosArrayClear(pScanInfo->pBlockIdxList); @@ -458,8 +554,8 @@ static void doCleanupInfoForNextFileset(STableBlockScanInfo* pScanInfo) { void cleanupInfoForNextFileset(SSHashObj* pTableMap) { STableBlockScanInfo** p = NULL; + int32_t iter = 0; - int32_t iter = 0; while ((p = tSimpleHashIterate(pTableMap, p, &iter)) != NULL) { doCleanupInfoForNextFileset(*p); } @@ -467,6 +563,10 @@ void cleanupInfoForNextFileset(SSHashObj* pTableMap) { // brin records iterator void initBrinRecordIter(SBrinRecordIter* pIter, SDataFileReader* pReader, SArray* pList) { + if (pIter == NULL) { + return; + } + (void)memset(&pIter->block, 0, sizeof(SBrinBlock)); (void)memset(&pIter->record, 0, sizeof(SBrinRecord)); pIter->blockIndex = -1; @@ -477,89 +577,133 @@ void initBrinRecordIter(SBrinRecordIter* pIter, SDataFileReader* pReader, SArray } int32_t getNextBrinRecord(SBrinRecordIter* pIter, SBrinRecord** pRecord) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + + TSDB_CHECK_NULL(pIter, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pRecord, code, lino, _end, TSDB_CODE_INVALID_PARA); + *pRecord = NULL; if (pIter->blockIndex == -1 || (pIter->recordIndex + 1) >= pIter->block.numOfRecords) { pIter->blockIndex += 1; if (pIter->blockIndex >= taosArrayGetSize(pIter->pBrinBlockList)) { - return TSDB_CODE_SUCCESS; + goto _end; } pIter->pCurrentBlk = taosArrayGet(pIter->pBrinBlockList, pIter->blockIndex); - if (pIter->pCurrentBlk == NULL) { - return TSDB_CODE_INVALID_PARA; - } + TSDB_CHECK_NULL(pIter->pCurrentBlk, code, lino, _end, terrno); tBrinBlockClear(&pIter->block); - int32_t code = tsdbDataFileReadBrinBlock(pIter->pReader, pIter->pCurrentBlk, &pIter->block); + TSDB_CHECK_NULL(pIter->pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + code = tsdbDataFileReadBrinBlock(pIter->pReader, pIter->pCurrentBlk, &pIter->block); if (code != TSDB_CODE_SUCCESS) { tsdbError("failed to read brinBlock from file, code:%s", tstrerror(code)); - return code; + TSDB_CHECK_CODE(code, lino, _end); } pIter->recordIndex = -1; } pIter->recordIndex += 1; - int32_t code = tBrinBlockGet(&pIter->block, pIter->recordIndex, &pIter->record); + code = tBrinBlockGet(&pIter->block, pIter->recordIndex, &pIter->record); *pRecord = &pIter->record; + TSDB_CHECK_CODE(code, lino, _end); +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return code; } -void clearBrinBlockIter(SBrinRecordIter* pIter) { tBrinBlockDestroy(&pIter->block); } +void clearBrinBlockIter(SBrinRecordIter* pIter) { + if (pIter != NULL) { + tBrinBlockDestroy(&pIter->block); + } +} // initialize the file block access order // sort the file blocks according to the offset of each data block in the files static void cleanupBlockOrderSupporter(SBlockOrderSupporter* pSup) { + if (pSup == NULL) { + return; + } + taosMemoryFreeClear(pSup->numOfBlocksPerTable); taosMemoryFreeClear(pSup->indexPerTable); - for (int32_t i = 0; i < pSup->numOfTables; ++i) { - SBlockOrderWrapper* pBlockInfo = pSup->pDataBlockInfo[i]; - taosMemoryFreeClear(pBlockInfo); - } + if (pSup->pDataBlockInfo != NULL) { + for (int32_t i = 0; i < pSup->numOfTables; ++i) { + SBlockOrderWrapper* pBlockInfo = pSup->pDataBlockInfo[i]; + taosMemoryFreeClear(pBlockInfo); + } - taosMemoryFreeClear(pSup->pDataBlockInfo); + taosMemoryFreeClear(pSup->pDataBlockInfo); + } } static int32_t initBlockOrderSupporter(SBlockOrderSupporter* pSup, int32_t numOfTables) { - pSup->pDataBlockInfo = taosMemoryCalloc(1, POINTER_BYTES * numOfTables); - pSup->indexPerTable = taosMemoryCalloc(1, sizeof(int32_t) * numOfTables); - pSup->numOfBlocksPerTable = taosMemoryCalloc(1, sizeof(int32_t) * numOfTables); - pSup->numOfTables = 0; - if (pSup->pDataBlockInfo == NULL || pSup->indexPerTable == NULL || pSup->numOfBlocksPerTable == NULL) { - cleanupBlockOrderSupporter(pSup); - return terrno; - } + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; - return TSDB_CODE_SUCCESS; + TSDB_CHECK_NULL(pSup, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_CONDITION(numOfTables >= 0, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pSup->pDataBlockInfo = taosMemoryCalloc(numOfTables, POINTER_BYTES); + TSDB_CHECK_NULL(pSup->pDataBlockInfo, code, lino, _end, terrno); + pSup->indexPerTable = taosMemoryCalloc(numOfTables, sizeof(int32_t)); + TSDB_CHECK_NULL(pSup->indexPerTable, code, lino, _end, terrno); + pSup->numOfBlocksPerTable = taosMemoryCalloc(numOfTables, sizeof(int32_t)); + TSDB_CHECK_NULL(pSup->numOfBlocksPerTable, code, lino, _end, terrno); + pSup->numOfTables = 0; + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static int32_t fileDataBlockOrderCompar(const void* pLeft, const void* pRight, void* param) { - int32_t leftIndex = *(int32_t*)pLeft; - int32_t rightIndex = *(int32_t*)pRight; + int32_t leftIndex = 0; + int32_t rightIndex = 0; + int32_t leftTableBlockIndex = 0; + int32_t rightTableBlockIndex = 0; + const SBlockOrderSupporter* pSupporter = NULL; + const SBlockOrderWrapper* pLeftBlock = NULL; + const SBlockOrderWrapper* pRightBlock = NULL; - SBlockOrderSupporter* pSupporter = (SBlockOrderSupporter*)param; + leftIndex = *(const int32_t*)pLeft; + rightIndex = *(const int32_t*)pRight; + pSupporter = (const SBlockOrderSupporter*)param; - int32_t leftTableBlockIndex = pSupporter->indexPerTable[leftIndex]; - int32_t rightTableBlockIndex = pSupporter->indexPerTable[rightIndex]; + leftTableBlockIndex = pSupporter->indexPerTable[leftIndex]; + rightTableBlockIndex = pSupporter->indexPerTable[rightIndex]; - if (leftTableBlockIndex > pSupporter->numOfBlocksPerTable[leftIndex]) { + if (leftTableBlockIndex >= pSupporter->numOfBlocksPerTable[leftIndex]) { /* left block is empty */ return 1; - } else if (rightTableBlockIndex > pSupporter->numOfBlocksPerTable[rightIndex]) { + } else if (rightTableBlockIndex >= pSupporter->numOfBlocksPerTable[rightIndex]) { /* right block is empty */ return -1; } - SBlockOrderWrapper* pLeftBlock = &pSupporter->pDataBlockInfo[leftIndex][leftTableBlockIndex]; - SBlockOrderWrapper* pRightBlock = &pSupporter->pDataBlockInfo[rightIndex][rightTableBlockIndex]; + pLeftBlock = &pSupporter->pDataBlockInfo[leftIndex][leftTableBlockIndex]; + pRightBlock = &pSupporter->pDataBlockInfo[rightIndex][rightTableBlockIndex]; return pLeftBlock->offset > pRightBlock->offset ? 1 : -1; } int32_t recordToBlockInfo(SFileDataBlockInfo* pBlockInfo, SBrinRecord* record) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + const SRowKey* pFirstKey = NULL; + const SRowKey* pLastKey = NULL; + + TSDB_CHECK_NULL(pBlockInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(record, code, lino, _end, TSDB_CODE_INVALID_PARA); + pBlockInfo->uid = record->uid; pBlockInfo->firstKey = record->firstKey.key.ts; pBlockInfo->lastKey = record->lastKey.key.ts; @@ -573,40 +717,50 @@ int32_t recordToBlockInfo(SFileDataBlockInfo* pBlockInfo, SBrinRecord* record) { pBlockInfo->numRow = record->numRow; pBlockInfo->count = record->count; - SRowKey* pFirstKey = &record->firstKey.key; + pFirstKey = &record->firstKey.key; + pLastKey = &record->lastKey.key; + TSDB_CHECK_CONDITION((pFirstKey->numOfPKs == pLastKey->numOfPKs), code, lino, _end, TSDB_CODE_INVALID_PARA); if (pFirstKey->numOfPKs > 0) { if (IS_NUMERIC_TYPE(pFirstKey->pks[0].type)) { pBlockInfo->firstPk.val = pFirstKey->pks[0].val; - pBlockInfo->lastPk.val = record->lastKey.key.pks[0].val; + pBlockInfo->lastPk.val = pLastKey->pks[0].val; } else { - char* p = taosMemoryCalloc(1, pFirstKey->pks[0].nData + VARSTR_HEADER_SIZE); - if (p == NULL) { - return terrno; - } - memcpy(varDataVal(p), pFirstKey->pks[0].pData, pFirstKey->pks[0].nData); - varDataSetLen(p, pFirstKey->pks[0].nData); + int32_t keyLen = pFirstKey->pks[0].nData; + char* p = taosMemoryMalloc(keyLen + VARSTR_HEADER_SIZE); + TSDB_CHECK_NULL(p, code, lino, _end, terrno); + memcpy(varDataVal(p), pFirstKey->pks[0].pData, keyLen); + varDataSetLen(p, keyLen); pBlockInfo->firstPk.pData = (uint8_t*)p; - int32_t keyLen = record->lastKey.key.pks[0].nData; - p = taosMemoryCalloc(1, keyLen + VARSTR_HEADER_SIZE); - if (p == NULL) { - return terrno; - } - memcpy(varDataVal(p), record->lastKey.key.pks[0].pData, keyLen); + keyLen = pLastKey->pks[0].nData; + p = taosMemoryMalloc(keyLen + VARSTR_HEADER_SIZE); + TSDB_CHECK_NULL(p, code, lino, _end, terrno); + memcpy(varDataVal(p), pLastKey->pks[0].pData, keyLen); varDataSetLen(p, keyLen); pBlockInfo->lastPk.pData = (uint8_t*)p; } } - return TSDB_CODE_SUCCESS; + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } static void freePkItem(void* pItem) { SFileDataBlockInfo* p = pItem; - taosMemoryFreeClear(p->firstPk.pData); - taosMemoryFreeClear(p->lastPk.pData); + if (p != NULL) { + taosMemoryFreeClear(p->firstPk.pData); + taosMemoryFreeClear(p->lastPk.pData); + } } void clearDataBlockIterator(SDataBlockIter* pIter, bool needFree) { + if (pIter == NULL) { + return; + } + pIter->index = -1; pIter->numOfBlocks = 0; @@ -618,6 +772,10 @@ void clearDataBlockIterator(SDataBlockIter* pIter, bool needFree) { } void cleanupDataBlockIterator(SDataBlockIter* pIter, bool needFree) { + if (pIter == NULL) { + return; + } + pIter->index = -1; pIter->numOfBlocks = 0; if (needFree) { @@ -625,159 +783,149 @@ void cleanupDataBlockIterator(SDataBlockIter* pIter, bool needFree) { } else { taosArrayDestroy(pIter->blockList); } + pIter->blockList = NULL; } int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIter, int32_t numOfBlocks, SArray* pTableList) { - bool asc = ASCENDING_TRAVERSE(pReader->info.order); + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + bool asc = false; + int32_t numOfTables = 0; + int64_t st = 0; + int64_t et = 0; + int32_t cnt = 0; + SBlockOrderSupporter sup = {0}; + SMultiwayMergeTreeInfo* pTree = NULL; + STableBlockScanInfo* pTableScanInfo = NULL; + const SFileDataBlockInfo* pBlockInfo = NULL; + const void* px = NULL; - SBlockOrderSupporter sup = {0}; + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pBlockIter, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_CONDITION(numOfBlocks >= 0, code, lino, _end, TSDB_CODE_INVALID_PARA); + + asc = ASCENDING_TRAVERSE(pReader->info.order); clearDataBlockIterator(pBlockIter, shouldFreePkBuf(&pReader->suppInfo)); - pBlockIter->numOfBlocks = numOfBlocks; // access data blocks according to the offset of each block in asc/desc order. - int32_t numOfTables = taosArrayGetSize(pTableList); + numOfTables = taosArrayGetSize(pTableList); - int64_t st = taosGetTimestampUs(); - int32_t code = initBlockOrderSupporter(&sup, numOfTables); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - - int32_t cnt = 0; + st = taosGetTimestampUs(); + code = initBlockOrderSupporter(&sup, numOfTables); + TSDB_CHECK_CODE(code, lino, _end); for (int32_t i = 0; i < numOfTables; ++i) { - STableBlockScanInfo* pTableScanInfo = taosArrayGetP(pTableList, i); + pTableScanInfo = taosArrayGetP(pTableList, i); - size_t num = taosArrayGetSize(pTableScanInfo->pBlockList); + size_t num = taosArrayGetSize(pTableScanInfo->pBlockList); + SBlockOrderWrapper* buf = taosMemoryMalloc(sizeof(SBlockOrderWrapper) * num); + TSDB_CHECK_NULL(buf, code, lino, _end, terrno); sup.numOfBlocksPerTable[sup.numOfTables] = num; - - char* buf = taosMemoryMalloc(sizeof(SBlockOrderWrapper) * num); - if (buf == NULL) { - cleanupBlockOrderSupporter(&sup); - return terrno; - } - - sup.pDataBlockInfo[sup.numOfTables] = (SBlockOrderWrapper*)buf; + sup.pDataBlockInfo[sup.numOfTables] = buf; + sup.numOfTables++; for (int32_t k = 0; k < num; ++k) { - SFileDataBlockInfo* pBlockInfo = taosArrayGet(pTableScanInfo->pBlockList, k); - if (pBlockInfo == NULL) { - return TSDB_CODE_INVALID_PARA; - } + pBlockInfo = taosArrayGet(pTableScanInfo->pBlockList, k); + TSDB_CHECK_NULL(pBlockInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); - sup.pDataBlockInfo[sup.numOfTables][k] = + sup.pDataBlockInfo[i][k] = (SBlockOrderWrapper){.uid = pTableScanInfo->uid, .offset = pBlockInfo->blockOffset, .pInfo = pTableScanInfo}; cnt++; } - - sup.numOfTables += 1; } - if (numOfBlocks != cnt && sup.numOfTables != numOfTables) { - cleanupBlockOrderSupporter(&sup); - return TSDB_CODE_INVALID_PARA; - } + TSDB_CHECK_CONDITION(!(numOfBlocks != cnt && sup.numOfTables != numOfTables), code, lino, _end, + TSDB_CODE_INVALID_PARA); // since there is only one table qualified, blocks are not sorted if (sup.numOfTables == 1) { - STableBlockScanInfo* pTableScanInfo = taosArrayGetP(pTableList, 0); + pTableScanInfo = taosArrayGetP(pTableList, 0); for (int32_t i = 0; i < numOfBlocks; ++i) { STableDataBlockIdx tableDataBlockIdx = {.globalIndex = i}; - void* px = taosArrayPush(pTableScanInfo->pBlockIdxList, &tableDataBlockIdx); - if (px == NULL) { - return terrno; - } + px = taosArrayPush(pTableScanInfo->pBlockIdxList, &tableDataBlockIdx); + TSDB_CHECK_NULL(px, code, lino, _end, terrno); } - void* p = taosArrayAddAll(pBlockIter->blockList, pTableScanInfo->pBlockList); - if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; - } + px = taosArrayAddAll(pBlockIter->blockList, pTableScanInfo->pBlockList); + TSDB_CHECK_NULL(px, code, lino, _end, terrno); taosArrayDestroy(pTableScanInfo->pBlockList); pTableScanInfo->pBlockList = NULL; - int64_t et = taosGetTimestampUs(); + et = taosGetTimestampUs(); tsdbDebug("%p create blocks info struct completed for one table, %d blocks not sorted, elapsed time:%.2f ms %s", pReader, numOfBlocks, (et - st) / 1000.0, pReader->idStr); pBlockIter->index = asc ? 0 : (numOfBlocks - 1); - cleanupBlockOrderSupporter(&sup); - return TSDB_CODE_SUCCESS; + goto _end; } tsdbDebug("%p create data blocks info struct completed, %d blocks in %d tables %s", pReader, cnt, sup.numOfTables, pReader->idStr); - SMultiwayMergeTreeInfo* pTree = NULL; + code = tMergeTreeCreate(&pTree, sup.numOfTables, &sup, fileDataBlockOrderCompar); + TSDB_CHECK_CODE(code, lino, _end); - uint8_t ret = tMergeTreeCreate(&pTree, sup.numOfTables, &sup, fileDataBlockOrderCompar); - if (ret != TSDB_CODE_SUCCESS) { - cleanupBlockOrderSupporter(&sup); - return TSDB_CODE_OUT_OF_MEMORY; - } - - int32_t numOfTotal = 0; - while (numOfTotal < cnt) { + for (int32_t i = 0; i < cnt; ++i) { int32_t pos = tMergeTreeGetChosenIndex(pTree); int32_t index = sup.indexPerTable[pos]++; + pTableScanInfo = sup.pDataBlockInfo[pos][index].pInfo; - SFileDataBlockInfo* pBlockInfo = taosArrayGet(sup.pDataBlockInfo[pos][index].pInfo->pBlockList, index); - if (pBlockInfo == NULL) { - return TSDB_CODE_INVALID_PARA; - } + pBlockInfo = taosArrayGet(pTableScanInfo->pBlockList, index); + TSDB_CHECK_NULL(pBlockInfo, code, lino, _end, terrno); - void* px = taosArrayPush(pBlockIter->blockList, pBlockInfo); - if (px == NULL) { - return terrno; - } - - STableBlockScanInfo* pTableScanInfo = sup.pDataBlockInfo[pos][index].pInfo; - STableDataBlockIdx tableDataBlockIdx = {.globalIndex = numOfTotal}; + px = taosArrayPush(pBlockIter->blockList, pBlockInfo); + TSDB_CHECK_NULL(px, code, lino, _end, terrno); + STableDataBlockIdx tableDataBlockIdx = {.globalIndex = i}; px = taosArrayPush(pTableScanInfo->pBlockIdxList, &tableDataBlockIdx); - if (px == NULL) { - return terrno; - } + TSDB_CHECK_NULL(px, code, lino, _end, terrno); // set data block index overflow, in order to disable the offset comparator if (sup.indexPerTable[pos] >= sup.numOfBlocksPerTable[pos]) { sup.indexPerTable[pos] = sup.numOfBlocksPerTable[pos] + 1; } - numOfTotal += 1; code = tMergeTreeAdjust(pTree, tMergeTreeGetAdjustIndex(pTree)); - if (TSDB_CODE_SUCCESS != code) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } for (int32_t i = 0; i < numOfTables; ++i) { - STableBlockScanInfo* pTableScanInfo = taosArrayGetP(pTableList, i); + pTableScanInfo = taosArrayGetP(pTableList, i); taosArrayDestroy(pTableScanInfo->pBlockList); pTableScanInfo->pBlockList = NULL; } - int64_t et = taosGetTimestampUs(); + et = taosGetTimestampUs(); tsdbDebug("%p %d data blocks access order completed, elapsed time:%.2f ms %s", pReader, numOfBlocks, (et - st) / 1000.0, pReader->idStr); - cleanupBlockOrderSupporter(&sup); - taosMemoryFree(pTree); pBlockIter->index = asc ? 0 : (numOfBlocks - 1); - return TSDB_CODE_SUCCESS; + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + cleanupBlockOrderSupporter(&sup); + if (pTree != NULL) { + tMergeTreeDestroy(&pTree); + } + return code; } -bool blockIteratorNext(SDataBlockIter* pBlockIter, const char* idStr) { - bool asc = ASCENDING_TRAVERSE(pBlockIter->order); +bool blockIteratorNext(SDataBlockIter* pBlockIter) { + bool asc = false; - int32_t step = asc ? 1 : -1; - if ((pBlockIter->index >= pBlockIter->numOfBlocks - 1 && asc) || (pBlockIter->index <= 0 && (!asc))) { + if (pBlockIter == NULL) { return false; } - pBlockIter->index += step; + asc = ASCENDING_TRAVERSE(pBlockIter->order); + if ((pBlockIter->index >= pBlockIter->numOfBlocks - 1 && asc) || (pBlockIter->index <= 0 && (!asc))) { + return false; + } + pBlockIter->index += asc ? 1 : -1; return true; } @@ -791,30 +939,29 @@ static int32_t loadNextStatisticsBlock(SSttFileReader* pSttFileReader, STbStatis int32_t* j); static int32_t doCheckTombBlock(STombBlock* pBlock, STsdbReader* pReader, int32_t numOfTables, int32_t* j, ETombBlkCheckEnum* pRet) { - int32_t code = 0; - STombRecord record = {0}; - - uint64_t uid = pReader->status.uidList.tableUidList[*j]; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + STombRecord record = {0}; + uint64_t uid = 0; STableBlockScanInfo* pScanInfo = NULL; + TSDB_CHECK_NULL(pBlock, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pRet, code, lino, _end, TSDB_CODE_INVALID_PARA); + + *pRet = BLK_CHECK_QUIT; + uid = pReader->status.uidList.tableUidList[*j]; code = getTableBlockScanInfo(pReader->status.pTableMap, uid, &pScanInfo, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if (pScanInfo->pFileDelData == NULL) { pScanInfo->pFileDelData = taosArrayInit(4, sizeof(SDelData)); - if (pScanInfo->pFileDelData == NULL) { - return terrno; - } + TSDB_CHECK_NULL(pScanInfo->pFileDelData, code, lino, _end, terrno); } for (int32_t k = 0; k < pBlock->numOfRecords; ++k) { code = tTombBlockGet(pBlock, k, &record); - if (code != TSDB_CODE_SUCCESS) { - *pRet = BLK_CHECK_QUIT; - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if (record.suid < pReader->info.suid) { continue; @@ -822,7 +969,7 @@ static int32_t doCheckTombBlock(STombBlock* pBlock, STsdbReader* pReader, int32_ if (record.suid > pReader->info.suid) { *pRet = BLK_CHECK_QUIT; - return TSDB_CODE_SUCCESS; + goto _end; } if (uid < record.uid) { @@ -832,20 +979,16 @@ static int32_t doCheckTombBlock(STombBlock* pBlock, STsdbReader* pReader, int32_ if ((*j) >= numOfTables) { *pRet = BLK_CHECK_QUIT; - return TSDB_CODE_SUCCESS; + goto _end; } uid = pReader->status.uidList.tableUidList[*j]; code = getTableBlockScanInfo(pReader->status.pTableMap, uid, &pScanInfo, pReader->idStr); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); if (pScanInfo->pFileDelData == NULL) { pScanInfo->pFileDelData = taosArrayInit(4, sizeof(SDelData)); - if (pScanInfo->pFileDelData == NULL) { - return terrno; - } + TSDB_CHECK_NULL(pScanInfo->pFileDelData, code, lino, _end, terrno); } } @@ -853,30 +996,38 @@ static int32_t doCheckTombBlock(STombBlock* pBlock, STsdbReader* pReader, int32_ continue; } - if (!(record.suid == pReader->info.suid && uid == record.uid)) { - tsdbError("tsdb reader failed at: %s:%d", __func__, __LINE__); - return TSDB_CODE_INTERNAL_ERROR; - } + TSDB_CHECK_CONDITION((record.suid == pReader->info.suid) && (uid == record.uid), code, lino, _end, + TSDB_CODE_INTERNAL_ERROR); if (record.version <= pReader->info.verRange.maxVer) { - SDelData delData = {.version = record.version, .sKey = record.skey, .eKey = record.ekey}; - void* px = taosArrayPush(pScanInfo->pFileDelData, &delData); - if (px == NULL) { - return terrno; - } + SDelData delData = {.version = record.version, .sKey = record.skey, .eKey = record.ekey}; + const void* px = taosArrayPush(pScanInfo->pFileDelData, &delData); + TSDB_CHECK_NULL(px, code, lino, _end, terrno); } } *pRet = BLK_CHECK_CONTINUE; - return TSDB_CODE_SUCCESS; + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } // load tomb data API static int32_t doLoadTombDataFromTombBlk(const TTombBlkArray* pTombBlkArray, STsdbReader* pReader, void* pFileReader, bool isFile) { - int32_t code = 0; - STableUidList* pList = &pReader->status.uidList; - int32_t numOfTables = tSimpleHashGetSize(pReader->status.pTableMap); + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + const STableUidList* pList = NULL; + int32_t numOfTables = 0; + + TSDB_CHECK_NULL(pTombBlkArray, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + pList = &pReader->status.uidList; + numOfTables = tSimpleHashGetSize(pReader->status.pTableMap); int32_t i = 0, j = 0; while (i < pTombBlkArray->size && j < numOfTables) { @@ -890,10 +1041,10 @@ static int32_t doLoadTombDataFromTombBlk(const TTombBlkArray* pTombBlkArray, STs break; } - if (!(pTombBlk->minTbid.suid <= pReader->info.suid && pTombBlk->maxTbid.suid >= pReader->info.suid)) { - tsdbError("tsdb reader failed at: %s:%d", __func__, __LINE__); - return TSDB_CODE_INTERNAL_ERROR; - } + TSDB_CHECK_CONDITION( + (pTombBlk->minTbid.suid <= pReader->info.suid) && (pTombBlk->maxTbid.suid >= pReader->info.suid), code, lino, + _end, TSDB_CODE_INTERNAL_ERROR); + if (pTombBlk->maxTbid.suid == pReader->info.suid && pTombBlk->maxTbid.uid < pList->tableUidList[0]) { i += 1; continue; @@ -906,79 +1057,98 @@ static int32_t doLoadTombDataFromTombBlk(const TTombBlkArray* pTombBlkArray, STs STombBlock block = {0}; code = isFile ? tsdbDataFileReadTombBlock(pFileReader, &pTombBlkArray->data[i], &block) : tsdbSttFileReadTombBlock(pFileReader, &pTombBlkArray->data[i], &block); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - - // uint64_t uid = pReader->status.uidList.tableUidList[j]; - - // STableBlockScanInfo* pScanInfo = getTableBlockScanInfo(pReader->status.pTableMap, uid, pReader->idStr); - // if (pScanInfo->pFileDelData == NULL) { - // pScanInfo->pFileDelData = taosArrayInit(4, sizeof(SDelData)); - // } + TSDB_CHECK_CODE(code, lino, _end); ETombBlkCheckEnum ret = 0; code = doCheckTombBlock(&block, pReader, numOfTables, &j, &ret); tTombBlockDestroy(&block); - if (code != TSDB_CODE_SUCCESS || ret == BLK_CHECK_QUIT) { - return code; + TSDB_CHECK_CODE(code, lino, _end); + if (ret == BLK_CHECK_QUIT) { + break; } i += 1; } - return TSDB_CODE_SUCCESS; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } int32_t loadDataFileTombDataForAll(STsdbReader* pReader) { - if (pReader->status.pCurrentFileset == NULL || pReader->status.pCurrentFileset->farr[3] == NULL) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + const TTombBlkArray* pBlkArray = NULL; + + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + if ((pReader->status.pCurrentFileset == NULL) || (pReader->status.pCurrentFileset->farr[TSDB_FTYPE_TOMB] == NULL)) { return TSDB_CODE_SUCCESS; } - const TTombBlkArray* pBlkArray = NULL; + code = tsdbDataFileReadTombBlk(pReader->pFileReader, &pBlkArray); + TSDB_CHECK_CODE(code, lino, _end); - int32_t code = tsdbDataFileReadTombBlk(pReader->pFileReader, &pBlkArray); + code = doLoadTombDataFromTombBlk(pBlkArray, pReader, pReader->pFileReader, true); + TSDB_CHECK_CODE(code, lino, _end); + +_end: if (code != TSDB_CODE_SUCCESS) { - return code; + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); } - - return doLoadTombDataFromTombBlk(pBlkArray, pReader, pReader->pFileReader, true); + return code; } int32_t loadSttTombDataForAll(STsdbReader* pReader, SSttFileReader* pSttFileReader, SSttBlockLoadInfo* pLoadInfo) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; const TTombBlkArray* pBlkArray = NULL; - int32_t code = tsdbSttFileReadTombBlk(pSttFileReader, &pBlkArray); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - return doLoadTombDataFromTombBlk(pBlkArray, pReader, pSttFileReader, false); + TSDB_CHECK_NULL(pReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + + code = tsdbSttFileReadTombBlk(pSttFileReader, &pBlkArray); + TSDB_CHECK_CODE(code, lino, _end); + + code = doLoadTombDataFromTombBlk(pBlkArray, pReader, pSttFileReader, false); + TSDB_CHECK_CODE(code, lino, _end); + +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } int32_t loadMemTombData(SArray** ppMemDelData, STbData* pMemTbData, STbData* piMemTbData, int64_t ver) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SArray* pMemDelData = NULL; + const SDelData* p = NULL; + const void* px = NULL; + + TSDB_CHECK_NULL(ppMemDelData, code, lino, _end, TSDB_CODE_INVALID_PARA); + if (*ppMemDelData == NULL) { *ppMemDelData = taosArrayInit(4, sizeof(SDelData)); - if (*ppMemDelData == NULL) { - return terrno; - } + TSDB_CHECK_NULL(*ppMemDelData, code, lino, _end, terrno); } - SArray* pMemDelData = *ppMemDelData; + pMemDelData = *ppMemDelData; - SDelData* p = NULL; if (pMemTbData != NULL) { taosRLockLatch(&pMemTbData->lock); p = pMemTbData->pHead; while (p) { if (p->version <= ver) { - void* px = taosArrayPush(pMemDelData, p); + px = taosArrayPush(pMemDelData, p); if (px == NULL) { taosRUnLockLatch(&pMemTbData->lock); - return terrno; + TSDB_CHECK_NULL(px, code, lino, _end, terrno); } } - p = p->pNext; } taosRUnLockLatch(&pMemTbData->lock); @@ -988,28 +1158,36 @@ int32_t loadMemTombData(SArray** ppMemDelData, STbData* pMemTbData, STbData* piM p = piMemTbData->pHead; while (p) { if (p->version <= ver) { - void* px = taosArrayPush(pMemDelData, p); - if (px == NULL) { - return terrno; - } + px = taosArrayPush(pMemDelData, p); + TSDB_CHECK_NULL(px, code, lino, _end, terrno); } p = p->pNext; } } - return TSDB_CODE_SUCCESS; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } int32_t getNumOfRowsInSttBlock(SSttFileReader* pSttFileReader, SSttBlockLoadInfo* pBlockLoadInfo, TStatisBlkArray* pStatisBlkArray, uint64_t suid, const uint64_t* pUidList, int32_t numOfTables, int32_t* pNumOfRows) { - int32_t num = 0; - int32_t code = 0; - int32_t lino = 0; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + int32_t num = 0; + int64_t st = 0; + const SStatisBlk* p = NULL; + STbStatisBlock* pStatisBlock = NULL; - if (pNumOfRows != 0) { - *pNumOfRows = 0; - } + TSDB_CHECK_NULL(pSttFileReader, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pBlockLoadInfo, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pStatisBlkArray, code, lino, _end, TSDB_CODE_INVALID_PARA); + TSDB_CHECK_NULL(pNumOfRows, code, lino, _end, TSDB_CODE_INVALID_PARA); + + *pNumOfRows = 0; if (TARRAY2_SIZE(pStatisBlkArray) <= 0) { return code; @@ -1021,21 +1199,21 @@ int32_t getNumOfRowsInSttBlock(SSttFileReader* pSttFileReader, SSttBlockLoadInfo } if (i >= TARRAY2_SIZE(pStatisBlkArray)) { - return code; + goto _end; } - SStatisBlk* p = &pStatisBlkArray->data[i]; - STbStatisBlock* pStatisBlock = taosMemoryCalloc(1, sizeof(STbStatisBlock)); - TSDB_CHECK_NULL(pStatisBlock, code, lino, _err, terrno); + p = &pStatisBlkArray->data[i]; + pStatisBlock = taosMemoryCalloc(1, sizeof(STbStatisBlock)); + TSDB_CHECK_NULL(pStatisBlock, code, lino, _end, terrno); code = tStatisBlockInit(pStatisBlock); - TSDB_CHECK_CODE(code, lino, _err); + TSDB_CHECK_CODE(code, lino, _end); - int64_t st = taosGetTimestampMs(); + st = taosGetTimestampUs(); code = tsdbSttFileReadStatisBlock(pSttFileReader, p, pStatisBlock); - TSDB_CHECK_CODE(code, lino, _err); + TSDB_CHECK_CODE(code, lino, _end); - double el = (taosGetTimestampMs() - st) / 1000.0; + double el = (taosGetTimestampUs() - st) / 1000.0; pBlockLoadInfo->cost.loadStatisBlocks += 1; pBlockLoadInfo->cost.statisElapsedTime += el; @@ -1045,10 +1223,8 @@ int32_t getNumOfRowsInSttBlock(SSttFileReader* pSttFileReader, SSttBlockLoadInfo } if (index >= pStatisBlock->numOfRecords) { - tStatisBlockDestroy(pStatisBlock); - taosMemoryFreeClear(pStatisBlock); *pNumOfRows = num; - return code; + goto _end; } int32_t j = index; @@ -1056,10 +1232,8 @@ int32_t getNumOfRowsInSttBlock(SSttFileReader* pSttFileReader, SSttBlockLoadInfo while (i < TARRAY2_SIZE(pStatisBlkArray) && uidIndex < numOfTables) { p = &pStatisBlkArray->data[i]; if (p->minTbid.suid > suid) { - tStatisBlockDestroy(pStatisBlock); - taosMemoryFreeClear(pStatisBlock); *pNumOfRows = num; - return code; + goto _end; } uint64_t uid = pUidList[uidIndex]; @@ -1069,24 +1243,26 @@ int32_t getNumOfRowsInSttBlock(SSttFileReader* pSttFileReader, SSttBlockLoadInfo uidIndex += 1; j += 1; code = loadNextStatisticsBlock(pSttFileReader, pStatisBlock, pStatisBlkArray, pStatisBlock->numOfRecords, &i, &j); - TSDB_CHECK_CODE(code, lino, _err); + TSDB_CHECK_CODE(code, lino, _end); } else if (((int64_t*)pStatisBlock->uids.data)[j] < uid) { j += 1; code = loadNextStatisticsBlock(pSttFileReader, pStatisBlock, pStatisBlkArray, pStatisBlock->numOfRecords, &i, &j); - TSDB_CHECK_CODE(code, lino, _err); + TSDB_CHECK_CODE(code, lino, _end); } else { uidIndex += 1; } } - tStatisBlockDestroy(pStatisBlock); - taosMemoryFreeClear(pStatisBlock); *pNumOfRows = num; - return code; -_err: - tsdbError("%p failed to get number of rows in stt block, %s at line:%d code:%s", pSttFileReader, __func__, lino, - tstrerror(code)); +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s with %p failed at line %d since %s", __func__, pSttFileReader, lino, tstrerror(code)); + } + if (pStatisBlock) { + tStatisBlockDestroy(pStatisBlock); + taosMemoryFreeClear(pStatisBlock); + } return code; } @@ -1094,93 +1270,118 @@ _err: static int32_t loadNextStatisticsBlock(SSttFileReader* pSttFileReader, STbStatisBlock* pStatisBlock, const TStatisBlkArray* pStatisBlkArray, int32_t numOfRows, int32_t* i, int32_t* j) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + if ((*j) >= numOfRows) { (*i) += 1; (*j) = 0; if ((*i) < TARRAY2_SIZE(pStatisBlkArray)) { - int32_t code = tsdbSttFileReadStatisBlock(pSttFileReader, &pStatisBlkArray->data[(*i)], pStatisBlock); + code = tsdbSttFileReadStatisBlock(pSttFileReader, &pStatisBlkArray->data[(*i)], pStatisBlock); if (code != 0) { tsdbError("%p failed to read statisBlock, code:%s", pSttFileReader, tstrerror(code)); - return code; + TSDB_CHECK_CODE(code, lino, _end); } } } - return 0; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } int32_t doAdjustValidDataIters(SArray* pLDIterList, int32_t numOfFileObj) { - int32_t size = taosArrayGetSize(pLDIterList); + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + int32_t size = 0; + int32_t inc = 0; + SLDataIter* pIter = NULL; + + size = taosArrayGetSize(pLDIterList); if (size < numOfFileObj) { - int32_t inc = numOfFileObj - size; + inc = numOfFileObj - size; for (int32_t k = 0; k < inc; ++k) { - SLDataIter* pIter = taosMemoryCalloc(1, sizeof(SLDataIter)); - if (!pIter) { - return terrno; - } + pIter = taosMemoryCalloc(1, sizeof(SLDataIter)); + TSDB_CHECK_NULL(pIter, code, lino, _end, terrno); void* px = taosArrayPush(pLDIterList, &pIter); if (px == NULL) { - taosMemoryFree(pIter); - return terrno; + TSDB_CHECK_NULL(px, code, lino, _end, terrno); + taosMemoryFreeClear(pIter); } } } else if (size > numOfFileObj) { // remove unused LDataIter - int32_t inc = size - numOfFileObj; + inc = size - numOfFileObj; - for (int i = 0; i < inc; ++i) { - SLDataIter* pIter = taosArrayPop(pLDIterList); + for (int32_t i = 0; i < inc; ++i) { + pIter = taosArrayPop(pLDIterList); destroyLDataIter(pIter); } } - return TSDB_CODE_SUCCESS; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } int32_t adjustSttDataIters(SArray* pSttFileBlockIterArray, STFileSet* pFileSet) { - int32_t numOfLevels = pFileSet->lvlArr->size; - int32_t code = 0; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + int32_t numOfLevels = 0; + SSttLvl* pSttLevel = NULL; + SArray* pList = NULL; + + TSDB_CHECK_NULL(pFileSet, code, lino, _end, TSDB_CODE_INVALID_PARA); + + numOfLevels = pFileSet->lvlArr->size; // add the list/iter placeholder while (taosArrayGetSize(pSttFileBlockIterArray) < numOfLevels) { - SArray* pList = taosArrayInit(4, POINTER_BYTES); - if (pList == NULL) { - return terrno; - } + pList = taosArrayInit(4, POINTER_BYTES); + TSDB_CHECK_NULL(pList, code, lino, _end, terrno); void* px = taosArrayPush(pSttFileBlockIterArray, &pList); if (px == NULL) { - return terrno; + taosArrayDestroy(pList); + TSDB_CHECK_NULL(px, code, lino, _end, terrno); } } for (int32_t j = 0; j < numOfLevels; ++j) { - SSttLvl* pSttLevel = pFileSet->lvlArr->data[j]; - SArray* pList = taosArrayGetP(pSttFileBlockIterArray, j); + pSttLevel = pFileSet->lvlArr->data[j]; + pList = taosArrayGetP(pSttFileBlockIterArray, j); code = doAdjustValidDataIters(pList, TARRAY2_SIZE(pSttLevel->fobjArr)); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + TSDB_CHECK_CODE(code, lino, _end); } - return TSDB_CODE_SUCCESS; +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } + return code; } int32_t tsdbGetRowsInSttFiles(STFileSet* pFileSet, SArray* pSttFileBlockIterArray, STsdb* pTsdb, SMergeTreeConf* pConf, const char* pstr) { + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; int32_t numOfRows = 0; - int32_t code = 0; + int32_t numOfLevels = 0; + + TSDB_CHECK_NULL(pFileSet, code, lino, _end, TSDB_CODE_INVALID_PARA); // no data exists, go to end - int32_t numOfLevels = pFileSet->lvlArr->size; + numOfLevels = pFileSet->lvlArr->size; if (numOfLevels == 0) { - return numOfRows; + goto _end; } // add the list/iter placeholder code = adjustSttDataIters(pSttFileBlockIterArray, pFileSet); - if (code != TSDB_CODE_SUCCESS) { - return numOfRows; - } + TSDB_CHECK_CODE(code, lino, _end); for (int32_t j = 0; j < numOfLevels; ++j) { SSttLvl* pSttLevel = pFileSet->lvlArr->data[j]; @@ -1233,26 +1434,43 @@ int32_t tsdbGetRowsInSttFiles(STFileSet* pFileSet, SArray* pSttFileBlockIterArra } } +_end: + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + } return numOfRows; } static bool overlapHelper(const STimeWindow* pLeft, TSKEY minKey, TSKEY maxKey) { - return (pLeft->ekey >= minKey) && (pLeft->skey <= maxKey); + return (pLeft != NULL) && (pLeft->ekey >= minKey) && (pLeft->skey <= maxKey); } static bool overlapWithTimeWindow(STimeWindow* p1, STimeWindow* pQueryWindow, STableBlockScanInfo* pBlockScanInfo, int32_t order) { + SIterInfo* pMemIter = NULL; + SIterInfo* pIMemIter = NULL; + STbData* pTbData = NULL; + STimeWindow* pFileWin = NULL; + + if (p1 == NULL || pQueryWindow == NULL) { + return false; + } + // overlap with query window if (!(p1->skey >= pQueryWindow->skey && p1->ekey <= pQueryWindow->ekey)) { return true; } - SIterInfo* pMemIter = &pBlockScanInfo->iter; - SIterInfo* pIMemIter = &pBlockScanInfo->iiter; + if (pBlockScanInfo == NULL) { + return false; + } + + pMemIter = &pBlockScanInfo->iter; + pIMemIter = &pBlockScanInfo->iiter; // overlap with mem data if (pMemIter->hasVal) { - STbData* pTbData = pMemIter->iter->pTbData; + pTbData = pMemIter->iter->pTbData; if (overlapHelper(p1, pTbData->minKey, pTbData->maxKey)) { return true; } @@ -1260,14 +1478,14 @@ static bool overlapWithTimeWindow(STimeWindow* p1, STimeWindow* pQueryWindow, ST // overlap with imem data if (pIMemIter->hasVal) { - STbData* pITbData = pIMemIter->iter->pTbData; - if (overlapHelper(p1, pITbData->minKey, pITbData->maxKey)) { + pTbData = pIMemIter->iter->pTbData; + if (overlapHelper(p1, pTbData->minKey, pTbData->maxKey)) { return true; } } // overlap with data file block - STimeWindow* pFileWin = &pBlockScanInfo->filesetWindow; + pFileWin = &pBlockScanInfo->filesetWindow; if ((taosArrayGetSize(pBlockScanInfo->pBlockIdxList) > 0) && overlapHelper(p1, pFileWin->skey, pFileWin->ekey)) { return true; } @@ -1290,20 +1508,24 @@ static int32_t sortUidComparFn(const void* p1, const void* p2) { } bool isCleanSttBlock(SArray* pKeyRangeList, STimeWindow* pQueryWindow, STableBlockScanInfo* pScanInfo, int32_t order) { - // check if it overlap with del skyline - taosArraySort(pKeyRangeList, sortUidComparFn); + int32_t num = 0; + SSttKeyRange* pRange = NULL; + STimeWindow w; - int32_t num = taosArrayGetSize(pKeyRangeList); + num = taosArrayGetSize(pKeyRangeList); if (num == 0) { return false; } - SSttKeyRange* pRange = taosArrayGet(pKeyRangeList, 0); + // check if it overlap with del skyline + taosArraySort(pKeyRangeList, sortUidComparFn); + + pRange = taosArrayGet(pKeyRangeList, 0); if (pRange == NULL) { return false; } - STimeWindow w = {.skey = pRange->skey.ts, .ekey = pRange->ekey.ts}; + w = (STimeWindow){.skey = pRange->skey.ts, .ekey = pRange->ekey.ts}; if (overlapWithTimeWindow(&w, pQueryWindow, pScanInfo, order)) { return false; } @@ -1319,8 +1541,8 @@ bool isCleanSttBlock(SArray* pKeyRangeList, STimeWindow* pQueryWindow, STableBlo return false; } - STimeWindow w2 = {.skey = p2->skey.ts, .ekey = p2->ekey.ts}; - bool overlap = overlapWithTimeWindow(&w2, pQueryWindow, pScanInfo, order); + w = (STimeWindow){.skey = p2->skey.ts, .ekey = p2->ekey.ts}; + bool overlap = overlapWithTimeWindow(&w, pQueryWindow, pScanInfo, order); if (overlap) { return false; } diff --git a/source/dnode/vnode/src/tsdb/tsdbReadUtil.h b/source/dnode/vnode/src/tsdb/tsdbReadUtil.h index 6ec1f99577..703c548aca 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReadUtil.h +++ b/source/dnode/vnode/src/tsdb/tsdbReadUtil.h @@ -30,13 +30,13 @@ extern "C" { do { \ (_w)->skey = INT64_MAX; \ (_w)->ekey = INT64_MIN; \ - } while (0); + } while (0) #define INIT_KEYRANGE(_k) \ do { \ (_k)->skey.ts = INT64_MAX; \ (_k)->ekey.ts = INT64_MIN; \ - } while (0); + } while (0) #define tRowGetKeyEx(_pRow, _pKey) \ { \ @@ -72,7 +72,6 @@ typedef struct STsdbReaderInfo { } STsdbReaderInfo; typedef struct SBlockInfoBuf { - int32_t currentIndex; SArray* pData; int32_t numPerBucket; int32_t numOfTables; @@ -241,7 +240,6 @@ typedef struct SDataBlockIter { int32_t index; SArray* blockList; // SArray int32_t order; - SDataBlk block; // current SDataBlk data } SDataBlockIter; typedef struct SFileBlockDumpInfo { @@ -321,7 +319,7 @@ int32_t createDataBlockScanInfo(STsdbReader* pTsdbReader, SBlockInfoBuf* pBuf, c int32_t initTableBlockScanInfo(STableBlockScanInfo* pScanInfo, uint64_t uid, SSHashObj* pTableMap, STsdbReader* pReader); void clearBlockScanInfo(STableBlockScanInfo* p); -void destroyAllBlockScanInfo(SSHashObj* pTableMap); +void destroyAllBlockScanInfo(SSHashObj** pTableMap); void resetAllDataBlockScanInfo(SSHashObj* pTableMap, int64_t ts, int32_t step); void cleanupInfoForNextFileset(SSHashObj* pTableMap); int32_t ensureBlockScanInfoBuf(SBlockInfoBuf* pBuf, int32_t numOfTables); @@ -335,7 +333,7 @@ void clearBrinBlockIter(SBrinRecordIter* pIter); // initialize block iterator API int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIter, int32_t numOfBlocks, SArray* pTableList); -bool blockIteratorNext(SDataBlockIter* pBlockIter, const char* idStr); +bool blockIteratorNext(SDataBlockIter* pBlockIter); // load tomb data API (stt/mem only for one table each, tomb data from data files are load for all tables at one time) int32_t loadMemTombData(SArray** ppMemDelData, STbData* pMemTbData, STbData* piMemTbData, int64_t ver); diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 6272ac7049..353bc1fa18 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -35,6 +35,9 @@ extern SConfig* tsCfg; static int32_t buildRetrieveTableRsp(SSDataBlock* pBlock, int32_t numOfCols, SRetrieveTableRsp** pRsp) { + if (NULL == pBlock || NULL == pRsp) { + return TSDB_CODE_INVALID_PARA; + } size_t dataEncodeBufSize = blockGetEncodeSize(pBlock); size_t rspSize = sizeof(SRetrieveTableRsp) + dataEncodeBufSize + PAYLOAD_PREFIX_LEN; *pRsp = taosMemoryCalloc(1, rspSize); @@ -53,6 +56,7 @@ static int32_t buildRetrieveTableRsp(SSDataBlock* pBlock, int32_t numOfCols, SRe int32_t len = blockEncode(pBlock, (*pRsp)->data + PAYLOAD_PREFIX_LEN, dataEncodeBufSize, numOfCols); if(len < 0) { taosMemoryFree(*pRsp); + *pRsp = NULL; return terrno; } SET_PAYLOAD_LEN((*pRsp)->data, len, len); @@ -216,6 +220,9 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock, static int32_t execDescribe(bool sysInfoUser, SNode* pStmt, SRetrieveTableRsp** pRsp, int8_t biMode) { SDescribeStmt* pDesc = (SDescribeStmt*)pStmt; + if (NULL == pDesc || NULL == pDesc->pMeta) { + return TSDB_CODE_INVALID_PARA; + } int32_t numOfRows = TABLE_TOTAL_COL_NUM(pDesc->pMeta); SSDataBlock* pBlock = NULL; @@ -505,7 +512,7 @@ static int32_t buildCreateViewResultDataBlock(SSDataBlock** pOutput) { return code; } -void appendColumnFields(char* buf, int32_t* len, STableCfg* pCfg) { +static void appendColumnFields(char* buf, int32_t* len, STableCfg* pCfg) { for (int32_t i = 0; i < pCfg->numOfColumns; ++i) { SSchema* pSchema = pCfg->pSchemas + i; #define LTYPE_LEN (32 + 60) // 60 byte for compress info @@ -539,7 +546,7 @@ void appendColumnFields(char* buf, int32_t* len, STableCfg* pCfg) { } } -void appendTagFields(char* buf, int32_t* len, STableCfg* pCfg) { +static void appendTagFields(char* buf, int32_t* len, STableCfg* pCfg) { for (int32_t i = 0; i < pCfg->numOfTags; ++i) { SSchema* pSchema = pCfg->pSchemas + pCfg->numOfColumns + i; char type[32]; @@ -558,7 +565,7 @@ void appendTagFields(char* buf, int32_t* len, STableCfg* pCfg) { } } -void appendTagNameFields(char* buf, int32_t* len, STableCfg* pCfg) { +static void appendTagNameFields(char* buf, int32_t* len, STableCfg* pCfg) { for (int32_t i = 0; i < pCfg->numOfTags; ++i) { SSchema* pSchema = pCfg->pSchemas + pCfg->numOfColumns + i; *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len), @@ -566,7 +573,7 @@ void appendTagNameFields(char* buf, int32_t* len, STableCfg* pCfg) { } } -int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) { +static int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) { int32_t code = TSDB_CODE_SUCCESS; SArray* pTagVals = NULL; STag* pTag = (STag*)pCfg->pTags; @@ -643,7 +650,7 @@ _exit: return code; } -void appendTableOptions(char* buf, int32_t* len, SDbCfgInfo* pDbCfg, STableCfg* pCfg) { +static void appendTableOptions(char* buf, int32_t* len, SDbCfgInfo* pDbCfg, STableCfg* pCfg) { if (pCfg->commentLen > 0) { *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len), " COMMENT '%s'", pCfg->pComment); @@ -947,12 +954,18 @@ static int32_t buildLocalVariablesResultDataBlock(SSDataBlock** pOutput) { goto _exit; } + infoData.info.type = TSDB_DATA_TYPE_VARCHAR; + infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD4_LEN; + if (taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) { + goto _exit; + } + *pOutput = pBlock; _exit: if (terrno != TSDB_CODE_SUCCESS) { - taosMemoryFree(pBlock); taosArrayDestroy(pBlock->pDataBlock); + taosMemoryFree(pBlock); } return terrno; } @@ -997,7 +1010,7 @@ static int32_t createSelectResultDataBlock(SNodeList* pProjects, SSDataBlock** p return code; } -int32_t buildSelectResultDataBlock(SNodeList* pProjects, SSDataBlock* pBlock) { +static int32_t buildSelectResultDataBlock(SNodeList* pProjects, SSDataBlock* pBlock) { QRY_ERR_RET(blockDataEnsureCapacity(pBlock, 1)); int32_t index = 0; diff --git a/source/libs/command/src/explain.c b/source/libs/command/src/explain.c index 42c214fac7..24b43ac95b 100644 --- a/source/libs/command/src/explain.c +++ b/source/libs/command/src/explain.c @@ -30,8 +30,8 @@ char *gJoinTypeStr[JOIN_TYPE_MAX_VALUE][JOIN_STYPE_MAX_VALUE] = { /*FULL*/ {"Full Join", "Full Join", NULL, NULL, NULL, NULL}, }; -int32_t qExplainGenerateResNode(SPhysiNode *pNode, SExplainGroup *group, SExplainResNode **pRes); -int32_t qExplainAppendGroupResRows(void *pCtx, int32_t groupId, int32_t level, bool singleChannel); +static int32_t qExplainGenerateResNode(SPhysiNode *pNode, SExplainGroup *group, SExplainResNode **pRes); +static int32_t qExplainAppendGroupResRows(void *pCtx, int32_t groupId, int32_t level, bool singleChannel); char *qExplainGetDynQryCtrlType(EDynQueryType type) { switch (type) { @@ -118,7 +118,7 @@ void qExplainFreeCtx(SExplainCtx *pCtx) { taosMemoryFree(pCtx); } -int32_t qExplainInitCtx(SExplainCtx **pCtx, SHashObj *groupHash, bool verbose, double ratio, EExplainMode mode) { +static int32_t qExplainInitCtx(SExplainCtx **pCtx, SHashObj *groupHash, bool verbose, double ratio, EExplainMode mode) { int32_t code = 0; SExplainCtx *ctx = taosMemoryCalloc(1, sizeof(SExplainCtx)); if (NULL == ctx) { @@ -158,7 +158,7 @@ _return: QRY_RET(code); } -int32_t qExplainGenerateResChildren(SPhysiNode *pNode, SExplainGroup *group, SNodeList **pChildren) { +static int32_t qExplainGenerateResChildren(SPhysiNode *pNode, SExplainGroup *group, SNodeList **pChildren) { int32_t tlen = 0; SNodeList *pPhysiChildren = pNode->pChildren; @@ -180,7 +180,7 @@ int32_t qExplainGenerateResChildren(SPhysiNode *pNode, SExplainGroup *group, SNo return TSDB_CODE_SUCCESS; } -int32_t qExplainGenerateResNodeExecInfo(SPhysiNode *pNode, SArray **pExecInfo, SExplainGroup *group) { +static int32_t qExplainGenerateResNodeExecInfo(SPhysiNode *pNode, SArray **pExecInfo, SExplainGroup *group) { *pExecInfo = taosArrayInit(group->nodeNum, sizeof(SExplainExecInfo)); if (NULL == (*pExecInfo)) { qError("taosArrayInit %d explainExecInfo failed", group->nodeNum); @@ -217,7 +217,7 @@ int32_t qExplainGenerateResNodeExecInfo(SPhysiNode *pNode, SArray **pExecInfo, S return TSDB_CODE_SUCCESS; } -int32_t qExplainGenerateResNode(SPhysiNode *pNode, SExplainGroup *group, SExplainResNode **pResNode) { +static int32_t qExplainGenerateResNode(SPhysiNode *pNode, SExplainGroup *group, SExplainResNode **pResNode) { if (NULL == pNode) { *pResNode = NULL; qError("physical node is NULL"); @@ -250,7 +250,7 @@ _return: QRY_RET(code); } -int32_t qExplainBufAppendExecInfo(SArray *pExecInfo, char *tbuf, int32_t *len) { +static int32_t qExplainBufAppendExecInfo(SArray *pExecInfo, char *tbuf, int32_t *len) { int32_t tlen = *len; int32_t nodeNum = taosArrayGetSize(pExecInfo); SExplainExecInfo maxExecInfo = {0}; @@ -275,7 +275,7 @@ int32_t qExplainBufAppendExecInfo(SArray *pExecInfo, char *tbuf, int32_t *len) { return TSDB_CODE_SUCCESS; } -int32_t qExplainBufAppendVerboseExecInfo(SArray *pExecInfo, char *tbuf, int32_t *len) { +static int32_t qExplainBufAppendVerboseExecInfo(SArray *pExecInfo, char *tbuf, int32_t *len) { int32_t tlen = 0; bool gotVerbose = false; int32_t nodeNum = taosArrayGetSize(pExecInfo); @@ -297,7 +297,7 @@ int32_t qExplainBufAppendVerboseExecInfo(SArray *pExecInfo, char *tbuf, int32_t return TSDB_CODE_SUCCESS; } -int32_t qExplainResAppendRow(SExplainCtx *ctx, char *tbuf, int32_t len, int32_t level) { +static int32_t qExplainResAppendRow(SExplainCtx *ctx, char *tbuf, int32_t len, int32_t level) { SQueryExplainRowInfo row = {0}; row.buf = taosMemoryMalloc(len); if (NULL == row.buf) { @@ -362,7 +362,7 @@ static char* qExplainGetScanDataLoad(STableScanPhysiNode* pScan) { return "unknown"; } -int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, int32_t level) { +static int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, int32_t level) { int32_t tlen = 0; bool isVerboseLine = false; char *tbuf = ctx->tbuf; @@ -1900,7 +1900,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i return TSDB_CODE_SUCCESS; } -int32_t qExplainResNodeToRows(SExplainResNode *pResNode, SExplainCtx *ctx, int32_t level) { +static int32_t qExplainResNodeToRows(SExplainResNode *pResNode, SExplainCtx *ctx, int32_t level) { if (NULL == pResNode) { qError("explain res node is NULL"); QRY_ERR_RET(TSDB_CODE_APP_ERROR); @@ -1915,7 +1915,7 @@ int32_t qExplainResNodeToRows(SExplainResNode *pResNode, SExplainCtx *ctx, int32 return TSDB_CODE_SUCCESS; } -int32_t qExplainAppendGroupResRows(void *pCtx, int32_t groupId, int32_t level, bool singleChannel) { +static int32_t qExplainAppendGroupResRows(void *pCtx, int32_t groupId, int32_t level, bool singleChannel) { SExplainResNode *node = NULL; int32_t code = 0; SExplainCtx *ctx = (SExplainCtx *)pCtx; @@ -1940,7 +1940,7 @@ _return: QRY_RET(code); } -int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) { +static int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) { int32_t code = 0; SSDataBlock *pBlock = NULL; SExplainCtx *pCtx = (SExplainCtx *)ctx; @@ -1997,7 +1997,7 @@ _return: QRY_RET(code); } -int32_t qExplainPrepareCtx(SQueryPlan *pDag, SExplainCtx **pCtx) { +static int32_t qExplainPrepareCtx(SQueryPlan *pDag, SExplainCtx **pCtx) { int32_t code = 0; SNodeListNode *plans = NULL; int32_t taskNum = 0; @@ -2080,7 +2080,7 @@ _return: QRY_RET(code); } -int32_t qExplainAppendPlanRows(SExplainCtx *pCtx) { +static int32_t qExplainAppendPlanRows(SExplainCtx *pCtx) { if (EXPLAIN_MODE_ANALYZE != pCtx->mode) { return TSDB_CODE_SUCCESS; } @@ -2103,7 +2103,7 @@ int32_t qExplainAppendPlanRows(SExplainCtx *pCtx) { return TSDB_CODE_SUCCESS; } -int32_t qExplainGenerateRsp(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp) { +static int32_t qExplainGenerateRsp(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp) { QRY_ERR_RET(qExplainAppendGroupResRows(pCtx, pCtx->rootGroupId, 0, false)); QRY_ERR_RET(qExplainAppendPlanRows(pCtx)); QRY_ERR_RET(qExplainGetRspFromCtx(pCtx, pRsp)); @@ -2112,6 +2112,7 @@ int32_t qExplainGenerateRsp(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp) { } int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t groupId, SRetrieveTableRsp **pRsp) { + if(!pCtx || !pRspMsg || !pRsp) return TSDB_CODE_INVALID_PARA; SExplainResNode *node = NULL; int32_t code = 0; bool groupDone = false; @@ -2176,6 +2177,7 @@ _exit: } int32_t qExecStaticExplain(SQueryPlan *pDag, SRetrieveTableRsp **pRsp) { + if (!pDag || !pRsp) return TSDB_CODE_INVALID_PARA; int32_t code = 0; SExplainCtx *pCtx = NULL; @@ -2188,6 +2190,7 @@ _return: } int32_t qExecExplainBegin(SQueryPlan *pDag, SExplainCtx **pCtx, int64_t startTs) { + if(!pDag || !pCtx) return TSDB_CODE_INVALID_PARA; QRY_ERR_RET(qExplainPrepareCtx(pDag, pCtx)); (*pCtx)->reqStartTs = startTs; @@ -2197,6 +2200,7 @@ int32_t qExecExplainBegin(SQueryPlan *pDag, SExplainCtx **pCtx, int64_t startTs) } int32_t qExecExplainEnd(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp) { + if(!pCtx || !pRsp) return TSDB_CODE_INVALID_PARA; int32_t code = 0; pCtx->jobDoneTs = taosGetTimestampUs(); diff --git a/source/libs/executor/src/exchangeoperator.c b/source/libs/executor/src/exchangeoperator.c index 042fcf0120..7222f2d297 100644 --- a/source/libs/executor/src/exchangeoperator.c +++ b/source/libs/executor/src/exchangeoperator.c @@ -121,10 +121,10 @@ static void concurrentlyLoadRemoteDataImpl(SOperatorInfo* pOperator, SExchangeIn } } else { pDataInfo->status = EX_SOURCE_DATA_EXHAUSTED; - qDebug("%s vgId:%d, taskId:0x%" PRIx64 " execId:%d index:%d completed, rowsOfSource:%" PRIu64 - ", totalRows:%" PRIu64 ", try next %d/%" PRIzu, - GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, i, pDataInfo->totalRows, - pExchangeInfo->loadInfo.totalRows, i + 1, totalSources); + qDebug("%s vgId:%d, clientId:0x%" PRIx64 " taskId:0x%" PRIx64 + " execId:%d index:%d completed, rowsOfSource:%" PRIu64 ", totalRows:%" PRIu64 ", try next %d/%" PRIzu, + GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->clientId, pSource->taskId, pSource->execId, i, + pDataInfo->totalRows, pExchangeInfo->loadInfo.totalRows, i + 1, totalSources); taosMemoryFreeClear(pDataInfo->pRsp); } break; @@ -141,17 +141,17 @@ static void concurrentlyLoadRemoteDataImpl(SOperatorInfo* pOperator, SExchangeIn if (pRsp->completed == 1) { pDataInfo->status = EX_SOURCE_DATA_EXHAUSTED; - qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 + qDebug("%s fetch msg rsp from vgId:%d, clientId:0x%" PRIx64 " taskId:0x%" PRIx64 " execId:%d index:%d completed, blocks:%d, numOfRows:%" PRId64 ", rowsOfSource:%" PRIu64 ", totalRows:%" PRIu64 ", total:%.2f Kb, try next %d/%" PRIzu, - GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, i, pRsp->numOfBlocks, - pRsp->numOfRows, pDataInfo->totalRows, pLoadInfo->totalRows, pLoadInfo->totalSize / 1024.0, i + 1, - totalSources); + GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->clientId, pSource->taskId, pSource->execId, i, + pRsp->numOfBlocks, pRsp->numOfRows, pDataInfo->totalRows, pLoadInfo->totalRows, + pLoadInfo->totalSize / 1024.0, i + 1, totalSources); } else { - qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " execId:%d blocks:%d, numOfRows:%" PRId64 - ", totalRows:%" PRIu64 ", total:%.2f Kb", - GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, pRsp->numOfBlocks, - pRsp->numOfRows, pLoadInfo->totalRows, pLoadInfo->totalSize / 1024.0); + qDebug("%s fetch msg rsp from vgId:%d, clientId:0x%" PRIx64 " taskId:0x%" PRIx64 + " execId:%d blocks:%d, numOfRows:%" PRId64 ", totalRows:%" PRIu64 ", total:%.2f Kb", + GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->clientId, pSource->taskId, pSource->execId, + pRsp->numOfBlocks, pRsp->numOfRows, pLoadInfo->totalRows, pLoadInfo->totalSize / 1024.0); } taosMemoryFreeClear(pDataInfo->pRsp); @@ -640,9 +640,9 @@ int32_t doSendFetchDataRequest(SExchangeInfo* pExchangeInfo, SExecTaskInfo* pTas if (pSource->localExec) { SDataBuf pBuf = {0}; - int32_t code = - (*pTaskInfo->localFetch.fp)(pTaskInfo->localFetch.handle, pSource->schedId, pTaskInfo->id.queryId, - pSource->taskId, 0, pSource->execId, &pBuf.pData, pTaskInfo->localFetch.explainRes); + int32_t code = (*pTaskInfo->localFetch.fp)(pTaskInfo->localFetch.handle, pSource->schedId, pTaskInfo->id.queryId, + pSource->clientId, pSource->taskId, 0, pSource->execId, &pBuf.pData, + pTaskInfo->localFetch.explainRes); code = loadRemoteDataCallback(pWrapper, &pBuf, code); QUERY_CHECK_CODE(code, lino, _end); taosMemoryFree(pWrapper); @@ -650,6 +650,7 @@ int32_t doSendFetchDataRequest(SExchangeInfo* pExchangeInfo, SExecTaskInfo* pTas SResFetchReq req = {0}; req.header.vgId = pSource->addr.nodeId; req.sId = pSource->schedId; + req.clientId = pSource->clientId; req.taskId = pSource->taskId; req.queryId = pTaskInfo->id.queryId; req.execId = pSource->execId; @@ -691,9 +692,10 @@ int32_t doSendFetchDataRequest(SExchangeInfo* pExchangeInfo, SExecTaskInfo* pTas freeOperatorParam(req.pOpParam, OP_GET_PARAM); - qDebug("%s build fetch msg and send to vgId:%d, ep:%s, taskId:0x%" PRIx64 ", execId:%d, %p, %d/%" PRIzu, - GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->addr.epSet.eps[0].fqdn, pSource->taskId, - pSource->execId, pExchangeInfo, sourceIndex, totalSources); + qDebug("%s build fetch msg and send to vgId:%d, ep:%s, clientId:0x%" PRIx64 " taskId:0x%" PRIx64 + ", execId:%d, %p, %d/%" PRIzu, + GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->addr.epSet.eps[0].fqdn, pSource->clientId, + pSource->taskId, pSource->execId, pExchangeInfo, sourceIndex, totalSources); // send the fetch remote task result reques SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); @@ -974,8 +976,9 @@ int32_t seqLoadRemoteData(SOperatorInfo* pOperator) { } if (pDataInfo->code != TSDB_CODE_SUCCESS) { - qError("%s vgId:%d, taskID:0x%" PRIx64 " execId:%d error happens, code:%s", GET_TASKID(pTaskInfo), - pSource->addr.nodeId, pSource->taskId, pSource->execId, tstrerror(pDataInfo->code)); + qError("%s vgId:%d, clientId:0x%" PRIx64 " taskID:0x%" PRIx64 " execId:%d error happens, code:%s", + GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->clientId, pSource->taskId, pSource->execId, + tstrerror(pDataInfo->code)); pOperator->pTaskInfo->code = pDataInfo->code; return pOperator->pTaskInfo->code; } @@ -984,10 +987,10 @@ int32_t seqLoadRemoteData(SOperatorInfo* pOperator) { SLoadRemoteDataInfo* pLoadInfo = &pExchangeInfo->loadInfo; if (pRsp->numOfRows == 0) { - qDebug("%s vgId:%d, taskID:0x%" PRIx64 " execId:%d %d of total completed, rowsOfSource:%" PRIu64 - ", totalRows:%" PRIu64 " try next", - GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, pExchangeInfo->current + 1, - pDataInfo->totalRows, pLoadInfo->totalRows); + qDebug("%s vgId:%d, clientId:0x%" PRIx64 " taskID:0x%" PRIx64 + " execId:%d %d of total completed, rowsOfSource:%" PRIu64 ", totalRows:%" PRIu64 " try next", + GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->clientId, pSource->taskId, pSource->execId, + pExchangeInfo->current + 1, pDataInfo->totalRows, pLoadInfo->totalRows); pDataInfo->status = EX_SOURCE_DATA_EXHAUSTED; pExchangeInfo->current += 1; @@ -1002,19 +1005,19 @@ int32_t seqLoadRemoteData(SOperatorInfo* pOperator) { SRetrieveTableRsp* pRetrieveRsp = pDataInfo->pRsp; if (pRsp->completed == 1) { - qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " execId:%d numOfRows:%" PRId64 + qDebug("%s fetch msg rsp from vgId:%d, clientId:0x%" PRIx64 " taskId:0x%" PRIx64 " execId:%d numOfRows:%" PRId64 ", rowsOfSource:%" PRIu64 ", totalRows:%" PRIu64 ", totalBytes:%" PRIu64 " try next %d/%" PRIzu, - GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, pRetrieveRsp->numOfRows, - pDataInfo->totalRows, pLoadInfo->totalRows, pLoadInfo->totalSize, pExchangeInfo->current + 1, - totalSources); + GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->clientId, pSource->taskId, pSource->execId, + pRetrieveRsp->numOfRows, pDataInfo->totalRows, pLoadInfo->totalRows, pLoadInfo->totalSize, + pExchangeInfo->current + 1, totalSources); pDataInfo->status = EX_SOURCE_DATA_EXHAUSTED; pExchangeInfo->current += 1; } else { - qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " execId:%d numOfRows:%" PRId64 ", totalRows:%" PRIu64 - ", totalBytes:%" PRIu64, - GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, pRetrieveRsp->numOfRows, - pLoadInfo->totalRows, pLoadInfo->totalSize); + qDebug("%s fetch msg rsp from vgId:%d, clientId:0x%" PRIx64 " taskId:0x%" PRIx64 " execId:%d numOfRows:%" PRId64 + ", totalRows:%" PRIu64 ", totalBytes:%" PRIu64, + GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->clientId, pSource->taskId, pSource->execId, + pRetrieveRsp->numOfRows, pLoadInfo->totalRows, pLoadInfo->totalSize); } updateLoadRemoteInfo(pLoadInfo, pRetrieveRsp->numOfRows, pRetrieveRsp->compLen, startTs, pOperator); diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 5b5d5c5d11..ecb6bd7aee 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -3468,11 +3468,6 @@ void streamScanOperatorDecode(void* pBuff, int32_t len, SStreamScanInfo* pInfo) goto _end; } - void* pUpInfo = taosMemoryCalloc(1, sizeof(SUpdateInfo)); - if (!pUpInfo) { - lino = __LINE__; - goto _end; - } SDecoder decoder = {0}; pDeCoder = &decoder; tDecoderInit(pDeCoder, buf, tlen); @@ -3481,14 +3476,21 @@ void streamScanOperatorDecode(void* pBuff, int32_t len, SStreamScanInfo* pInfo) goto _end; } - code = pInfo->stateStore.updateInfoDeserialize(pDeCoder, pUpInfo); - if (code == TSDB_CODE_SUCCESS) { - pInfo->stateStore.updateInfoDestroy(pInfo->pUpdateInfo); - pInfo->pUpdateInfo = pUpInfo; - } else { - taosMemoryFree(pUpInfo); - lino = __LINE__; - goto _end; + if (pInfo->pUpdateInfo != NULL) { + void* pUpInfo = taosMemoryCalloc(1, sizeof(SUpdateInfo)); + if (!pUpInfo) { + lino = __LINE__; + goto _end; + } + code = pInfo->stateStore.updateInfoDeserialize(pDeCoder, pUpInfo); + if (code == TSDB_CODE_SUCCESS) { + pInfo->stateStore.updateInfoDestroy(pInfo->pUpdateInfo); + pInfo->pUpdateInfo = pUpInfo; + } else { + taosMemoryFree(pUpInfo); + lino = __LINE__; + goto _end; + } } if (tDecodeIsEnd(pDeCoder)) { diff --git a/source/libs/executor/src/sysscanoperator.c b/source/libs/executor/src/sysscanoperator.c index 8aad415f70..af5313297e 100644 --- a/source/libs/executor/src/sysscanoperator.c +++ b/source/libs/executor/src/sysscanoperator.c @@ -685,10 +685,10 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) { pAPI->metaFn.pauseTableMetaCursor(pInfo->pCur); break; } - } else { - code = sysTableUserColsFillOneTableCols(pInfo, dbname, &numOfRows, pDataBlock, tableName, schemaRow, typeName); - QUERY_CHECK_CODE(code, lino, _end); } + // if pInfo->pRes->info.rows == 0, also need to add the meta to pDataBlock + code = sysTableUserColsFillOneTableCols(pInfo, dbname, &numOfRows, pDataBlock, tableName, schemaRow, typeName); + QUERY_CHECK_CODE(code, lino, _end); } if (numOfRows > 0) { @@ -761,7 +761,7 @@ static SSDataBlock* sysTableScanUserTags(SOperatorInfo* pOperator) { SMetaReader smrChildTable = {0}; pAPI->metaReaderFn.initReader(&smrChildTable, pInfo->readHandle.vnode, META_READER_LOCK, &pAPI->metaFn); - int32_t code = pAPI->metaReaderFn.getTableEntryByName(&smrChildTable, condTableName); + code = pAPI->metaReaderFn.getTableEntryByName(&smrChildTable, condTableName); if (code != TSDB_CODE_SUCCESS) { // terrno has been set by pAPI->metaReaderFn.getTableEntryByName, therefore, return directly pAPI->metaReaderFn.clearReader(&smrChildTable); @@ -847,18 +847,18 @@ static SSDataBlock* sysTableScanUserTags(SOperatorInfo* pOperator) { pAPI->metaReaderFn.clearReader(&smrSuperTable); break; } - } else { - code = sysTableUserTagsFillOneTableTags(pInfo, &smrSuperTable, &pInfo->pCur->mr, dbname, tableName, &numOfRows, - dataBlock); - if (code != TSDB_CODE_SUCCESS) { - qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); - pAPI->metaReaderFn.clearReader(&smrSuperTable); - pAPI->metaFn.closeTableMetaCursor(pInfo->pCur); - pInfo->pCur = NULL; - blockDataDestroy(dataBlock); - dataBlock = NULL; - T_LONG_JMP(pTaskInfo->env, terrno); - } + } + // if pInfo->pRes->info.rows == 0, also need to add this meta into datablock. + code = sysTableUserTagsFillOneTableTags(pInfo, &smrSuperTable, &pInfo->pCur->mr, dbname, tableName, &numOfRows, + dataBlock); + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + pAPI->metaReaderFn.clearReader(&smrSuperTable); + pAPI->metaFn.closeTableMetaCursor(pInfo->pCur); + pInfo->pCur = NULL; + blockDataDestroy(dataBlock); + dataBlock = NULL; + T_LONG_JMP(pTaskInfo->env, terrno); } pAPI->metaReaderFn.clearReader(&smrSuperTable); } @@ -2792,7 +2792,9 @@ static int32_t doBlockInfoScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes code = pAPI->tsdReader.tsdReaderGetDataBlockDistInfo(pBlockScanInfo->pHandle, &blockDistInfo); QUERY_CHECK_CODE(code, lino, _end); - blockDistInfo.numOfInmemRows = (int32_t)pAPI->tsdReader.tsdReaderGetNumOfInMemRows(pBlockScanInfo->pHandle); + blockDistInfo.numOfInmemRows = 0; + code = pAPI->tsdReader.tsdReaderGetNumOfInMemRows(pBlockScanInfo->pHandle, &blockDistInfo.numOfInmemRows); + QUERY_CHECK_CODE(code, lino, _end); SSDataBlock* pBlock = pBlockScanInfo->pResBlock; diff --git a/source/libs/function/inc/tpercentile.h b/source/libs/function/inc/tpercentile.h index 35067fa3ea..4738301cd3 100644 --- a/source/libs/function/inc/tpercentile.h +++ b/source/libs/function/inc/tpercentile.h @@ -26,7 +26,7 @@ extern "C" { struct tMemBucket; int32_t tMemBucketCreate(int32_t nElemSize, int16_t dataType, double minval, double maxval, bool hasWindowOrGroup, - struct tMemBucket **pBucket); + struct tMemBucket **pBucket, int32_t numOfElements); void tMemBucketDestroy(struct tMemBucket **pBucket); diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 2d68eb9d51..5ce15a32b2 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -188,7 +188,11 @@ static int32_t countTrailingSpaces(const SValueNode* pVal, bool isLtrim) { static int32_t addTimezoneParam(SNodeList* pList) { char buf[TD_TIME_STR_LEN] = {0}; - time_t t = taosTime(NULL); + time_t t; + int32_t code = taosTime(&t); + if (code != 0) { + return code; + } struct tm tmInfo; if (taosLocalTime(&t, &tmInfo, buf, sizeof(buf)) != NULL) { (void)strftime(buf, sizeof(buf), "%z", &tmInfo); @@ -196,7 +200,7 @@ static int32_t addTimezoneParam(SNodeList* pList) { int32_t len = (int32_t)strlen(buf); SValueNode* pVal = NULL; - int32_t code = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&pVal); + code = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&pVal); if (pVal == NULL) { return code; } diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index acdac7cbc3..c2e2e9c17c 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -1805,7 +1805,7 @@ int32_t percentileFunction(SqlFunctionCtx* pCtx) { pResInfo->complete = true; return TSDB_CODE_SUCCESS; } else { - code = tMemBucketCreate(pCol->info.bytes, type, pInfo->minval, pInfo->maxval, pCtx->hasWindowOrGroup, &pInfo->pMemBucket); + code = tMemBucketCreate(pCol->info.bytes, type, pInfo->minval, pInfo->maxval, pCtx->hasWindowOrGroup, &pInfo->pMemBucket, pInfo->numOfElems); if (TSDB_CODE_SUCCESS != code) { return code; } diff --git a/source/libs/function/src/tpercentile.c b/source/libs/function/src/tpercentile.c index 78c16ec7cb..73f400c93e 100644 --- a/source/libs/function/src/tpercentile.c +++ b/source/libs/function/src/tpercentile.c @@ -269,18 +269,16 @@ static void resetSlotInfo(tMemBucket *pBucket) { } int32_t tMemBucketCreate(int32_t nElemSize, int16_t dataType, double minval, double maxval, bool hasWindowOrGroup, - tMemBucket **pBucket) { + tMemBucket **pBucket, int32_t numOfElements) { *pBucket = (tMemBucket *)taosMemoryCalloc(1, sizeof(tMemBucket)); if (*pBucket == NULL) { return terrno; } if (hasWindowOrGroup) { - // With window or group by, we need to shrink page size and reduce page num to save memory. - (*pBucket)->numOfSlots = DEFAULT_NUM_OF_SLOT / 8 ; // 128 bucket + // With window or group by, we need to shrink page size to save memory. (*pBucket)->bufPageSize = 4096; // 4k per page } else { - (*pBucket)->numOfSlots = DEFAULT_NUM_OF_SLOT; (*pBucket)->bufPageSize = 16384 * 4; // 16k per page } @@ -302,6 +300,8 @@ int32_t tMemBucketCreate(int32_t nElemSize, int16_t dataType, double minval, dou } (*pBucket)->elemPerPage = ((*pBucket)->bufPageSize - sizeof(SFilePage)) / (*pBucket)->bytes; + (*pBucket)->numOfSlots = TMIN((int16_t)(numOfElements / ((*pBucket)->elemPerPage * 6)) + 1, DEFAULT_NUM_OF_SLOT); + (*pBucket)->comparFn = getKeyComparFunc((*pBucket)->type, TSDB_ORDER_ASC); (*pBucket)->hashFunc = getHashFunc((*pBucket)->type); @@ -587,7 +587,7 @@ int32_t getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction // try next round tMemBucket *tmpBucket = NULL; int32_t code = tMemBucketCreate(pMemBucket->bytes, pMemBucket->type, pSlot->range.dMinVal, pSlot->range.dMaxVal, - false, &tmpBucket); + false, &tmpBucket, pSlot->info.size); if (TSDB_CODE_SUCCESS != code) { tMemBucketDestroy(&tmpBucket); return code; diff --git a/source/libs/function/src/tudf.c b/source/libs/function/src/tudf.c index a8198a804d..4efa8764e5 100644 --- a/source/libs/function/src/tudf.c +++ b/source/libs/function/src/tudf.c @@ -62,8 +62,13 @@ static void udfUdfdStopAsyncCb(uv_async_t *async); static void udfWatchUdfd(void *args); void udfUdfdExit(uv_process_t *process, int64_t exitStatus, int32_t termSignal) { + TAOS_UDF_CHECK_PTR_RVOID(process); fnInfo("udfd process exited with status %" PRId64 ", signal %d", exitStatus, termSignal); SUdfdData *pData = process->data; + if(pData == NULL) { + fnError("udfd process data is NULL"); + return; + } if (exitStatus == 0 && termSignal == 0 || atomic_load_32(&pData->stopCalled)) { fnInfo("udfd process exit due to SIGINT or dnode-mgmt called stop"); } else { @@ -77,6 +82,7 @@ void udfUdfdExit(uv_process_t *process, int64_t exitStatus, int32_t termSignal) static int32_t udfSpawnUdfd(SUdfdData *pData) { fnInfo("start to init udfd"); + TAOS_UDF_CHECK_PTR_RCODE(pData); int32_t err = 0; uv_process_options_t options = {0}; @@ -267,17 +273,20 @@ _OVER: } static void udfUdfdCloseWalkCb(uv_handle_t *handle, void *arg) { + TAOS_UDF_CHECK_PTR_RVOID(handle); if (!uv_is_closing(handle)) { uv_close(handle, NULL); } } static void udfUdfdStopAsyncCb(uv_async_t *async) { + TAOS_UDF_CHECK_PTR_RVOID(async); SUdfdData *pData = async->data; uv_stop(&pData->loop); } static void udfWatchUdfd(void *args) { + TAOS_UDF_CHECK_PTR_RVOID(args); SUdfdData *pData = args; TAOS_UV_CHECK_ERRNO(uv_loop_init(&pData->loop)); TAOS_UV_CHECK_ERRNO(uv_async_init(&pData->loop, &pData->stopAsync, udfUdfdStopAsyncCb)); @@ -873,6 +882,7 @@ void *decodeUdfResponse(const void *buf, SUdfResponse *rsp) { } void freeUdfColumnData(SUdfColumnData *data, SUdfColumnMeta *meta) { + TAOS_UDF_CHECK_PTR_RVOID(data, meta); if (IS_VAR_DATA_TYPE(meta->type)) { taosMemoryFree(data->varLenCol.varOffsets); data->varLenCol.varOffsets = NULL; @@ -886,9 +896,13 @@ void freeUdfColumnData(SUdfColumnData *data, SUdfColumnMeta *meta) { } } -void freeUdfColumn(SUdfColumn *col) { freeUdfColumnData(&col->colData, &col->colMeta); } +void freeUdfColumn(SUdfColumn *col) { + TAOS_UDF_CHECK_PTR_RVOID(col); + freeUdfColumnData(&col->colData, &col->colMeta); +} void freeUdfDataDataBlock(SUdfDataBlock *block) { + TAOS_UDF_CHECK_PTR_RVOID(block); for (int32_t i = 0; i < block->numOfCols; ++i) { freeUdfColumn(block->udfCols[i]); taosMemoryFree(block->udfCols[i]); @@ -899,11 +913,17 @@ void freeUdfDataDataBlock(SUdfDataBlock *block) { } void freeUdfInterBuf(SUdfInterBuf *buf) { + TAOS_UDF_CHECK_PTR_RVOID(buf); taosMemoryFree(buf->buf); buf->buf = NULL; } int32_t convertDataBlockToUdfDataBlock(SSDataBlock *block, SUdfDataBlock *udfBlock) { + TAOS_UDF_CHECK_PTR_RCODE(block, udfBlock); + int32_t code = blockDataCheck(block); + if (code != TSDB_CODE_SUCCESS) { + return code; + } udfBlock->numOfRows = block->info.rows; udfBlock->numOfCols = taosArrayGetSize(block->pDataBlock); udfBlock->udfCols = taosMemoryCalloc(taosArrayGetSize(block->pDataBlock), sizeof(SUdfColumn *)); @@ -973,6 +993,7 @@ int32_t convertDataBlockToUdfDataBlock(SSDataBlock *block, SUdfDataBlock *udfBlo } int32_t convertUdfColumnToDataBlock(SUdfColumn *udfCol, SSDataBlock *block) { + TAOS_UDF_CHECK_PTR_RCODE(udfCol, block); int32_t code = 0, lino = 0; SUdfColumnMeta *meta = &udfCol->colMeta; @@ -998,6 +1019,8 @@ int32_t convertUdfColumnToDataBlock(SUdfColumn *udfCol, SSDataBlock *block) { } block->info.rows = udfCol->colData.numOfRows; + code = blockDataCheck(block); + TAOS_CHECK_GOTO(code, &lino, _exit); _exit: if (code != 0) { fnError("failed to convert udf column to data block, code:%d, line:%d", code, lino); @@ -1006,6 +1029,7 @@ _exit: } int32_t convertScalarParamToDataBlock(SScalarParam *input, int32_t numOfCols, SSDataBlock *output) { + TAOS_UDF_CHECK_PTR_RCODE(input, output); int32_t code = 0, lino = 0; int32_t numOfRows = 0; for (int32_t i = 0; i < numOfCols; ++i) { @@ -1053,6 +1077,7 @@ _exit: } int32_t convertDataBlockToScalarParm(SSDataBlock *input, SScalarParam *output) { + TAOS_UDF_CHECK_PTR_RCODE(input, output); if (taosArrayGetSize(input->pDataBlock) != 1) { fnError("scalar function only support one column"); return 0; @@ -1131,6 +1156,7 @@ int32_t compareUdfcFuncSub(const void *elem1, const void *elem2) { } int32_t acquireUdfFuncHandle(char *udfName, UdfcFuncHandle *pHandle) { + TAOS_UDF_CHECK_PTR_RCODE(udfName, pHandle); int32_t code = 0, line = 0; uv_mutex_lock(&gUdfcProxy.udfStubsMutex); SUdfcFuncStub key = {0}; @@ -1189,6 +1215,7 @@ _exit: } void releaseUdfFuncHandle(char *udfName, UdfcFuncHandle handle) { + TAOS_UDF_CHECK_PTR_RVOID(udfName); uv_mutex_lock(&gUdfcProxy.udfStubsMutex); SUdfcFuncStub key = {0}; tstrncpy(key.udfName, udfName, TSDB_FUNC_NAME_LEN); @@ -1291,6 +1318,7 @@ int32_t cleanUpUdfs() { } int32_t callUdfScalarFunc(char *udfName, SScalarParam *input, int32_t numOfCols, SScalarParam *output) { + TAOS_UDF_CHECK_PTR_RCODE(udfName, input, output); UdfcFuncHandle handle = NULL; int32_t code = acquireUdfFuncHandle(udfName, &handle); if (code != 0) { @@ -1320,6 +1348,10 @@ int32_t callUdfScalarFunc(char *udfName, SScalarParam *input, int32_t numOfCols, } bool udfAggGetEnv(struct SFunctionNode *pFunc, SFuncExecEnv *pEnv) { + if (pFunc == NULL || pEnv == NULL) { + fnError("udfAggGetEnv: invalid input lint: %d", __LINE__); + return false; + } if (fmIsScalarFunc(pFunc->funcId)) { return false; } @@ -1328,6 +1360,7 @@ bool udfAggGetEnv(struct SFunctionNode *pFunc, SFuncExecEnv *pEnv) { } int32_t udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo *pResultCellInfo) { + TAOS_UDF_CHECK_PTR_RCODE(pCtx, pResultCellInfo); if (pResultCellInfo->initialized) { return TSDB_CODE_SUCCESS; } @@ -1369,6 +1402,7 @@ int32_t udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo *pRes } int32_t udfAggProcess(struct SqlFunctionCtx *pCtx) { + TAOS_UDF_CHECK_PTR_RCODE(pCtx); int32_t udfCode = 0; UdfcFuncHandle handle = 0; if ((udfCode = acquireUdfFuncHandle((char *)pCtx->udfName, &handle)) != 0) { @@ -1440,6 +1474,7 @@ int32_t udfAggProcess(struct SqlFunctionCtx *pCtx) { } int32_t udfAggFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock *pBlock) { + TAOS_UDF_CHECK_PTR_RCODE(pCtx, pBlock); int32_t udfCode = 0; UdfcFuncHandle handle = 0; if ((udfCode = acquireUdfFuncHandle((char *)pCtx->udfName, &handle)) != 0) { @@ -1534,7 +1569,7 @@ int32_t udfcGetUdfTaskResultFromUvTask(SClientUdfTask *task, SClientUvTaskNode * } // TODO: the call buffer is setup and freed by udf invocation - taosMemoryFree(uvTask->rspBuf.base); + taosMemoryFreeClear(uvTask->rspBuf.base); } else { code = uvTask->errCode; if (code != 0) { @@ -1759,7 +1794,7 @@ int32_t udfcInitializeUvTask(SClientUdfTask *task, int8_t uvTaskType, SClientUvT } if (uv_sem_init(&uvTask->taskSem, 0) != 0) { if (uvTaskType == UV_TASK_REQ_RSP) { - taosMemoryFree(uvTask->reqBuf.base); + taosMemoryFreeClear(uvTask->reqBuf.base); } fnError("udfc create uv task, init semaphore failed."); return TSDB_CODE_UDF_UV_EXEC_FAILURE; diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index 6eef99e1f8..0ee14f7820 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -55,6 +55,7 @@ int32_t udfdCPluginOpen(SScriptUdfEnvItem *items, int numItems) { return 0; } int32_t udfdCPluginClose() { return 0; } int32_t udfdCPluginUdfInitLoadInitDestoryFuncs(SUdfCPluginCtx *udfCtx, const char *udfName) { + TAOS_UDF_CHECK_PTR_RCODE(udfCtx, udfName); char initFuncName[TSDB_FUNC_NAME_LEN + 6] = {0}; char *initSuffix = "_init"; snprintf(initFuncName, sizeof(initFuncName), "%s%s", udfName, initSuffix); @@ -68,6 +69,7 @@ int32_t udfdCPluginUdfInitLoadInitDestoryFuncs(SUdfCPluginCtx *udfCtx, const cha } int32_t udfdCPluginUdfInitLoadAggFuncs(SUdfCPluginCtx *udfCtx, const char *udfName) { + TAOS_UDF_CHECK_PTR_RCODE(udfCtx, udfName); char processFuncName[TSDB_FUNC_NAME_LEN] = {0}; snprintf(processFuncName, sizeof(processFuncName), "%s", udfName); TAOS_CHECK_RETURN(uv_dlsym(&udfCtx->lib, processFuncName, (void **)(&udfCtx->aggProcFunc))); @@ -93,6 +95,7 @@ int32_t udfdCPluginUdfInitLoadAggFuncs(SUdfCPluginCtx *udfCtx, const char *udfNa } int32_t udfdCPluginUdfInit(SScriptUdfInfo *udf, void **pUdfCtx) { + TAOS_UDF_CHECK_PTR_RCODE(udf, pUdfCtx); int32_t err = 0; SUdfCPluginCtx *udfCtx = taosMemoryCalloc(1, sizeof(SUdfCPluginCtx)); if (NULL == udfCtx) { @@ -146,6 +149,7 @@ _exit: } int32_t udfdCPluginUdfDestroy(void *udfCtx) { + TAOS_UDF_CHECK_PTR_RCODE(udfCtx); SUdfCPluginCtx *ctx = udfCtx; int32_t code = 0; if (ctx->destroyFunc) { @@ -157,6 +161,7 @@ int32_t udfdCPluginUdfDestroy(void *udfCtx) { } int32_t udfdCPluginUdfScalarProc(SUdfDataBlock *block, SUdfColumn *resultCol, void *udfCtx) { + TAOS_UDF_CHECK_PTR_RCODE(block, resultCol, udfCtx); SUdfCPluginCtx *ctx = udfCtx; if (ctx->scalarProcFunc) { return ctx->scalarProcFunc(block, resultCol); @@ -167,6 +172,7 @@ int32_t udfdCPluginUdfScalarProc(SUdfDataBlock *block, SUdfColumn *resultCol, vo } int32_t udfdCPluginUdfAggStart(SUdfInterBuf *buf, void *udfCtx) { + TAOS_UDF_CHECK_PTR_RCODE(buf, udfCtx); SUdfCPluginCtx *ctx = udfCtx; if (ctx->aggStartFunc) { return ctx->aggStartFunc(buf); @@ -178,6 +184,7 @@ int32_t udfdCPluginUdfAggStart(SUdfInterBuf *buf, void *udfCtx) { } int32_t udfdCPluginUdfAggProc(SUdfDataBlock *block, SUdfInterBuf *interBuf, SUdfInterBuf *newInterBuf, void *udfCtx) { + TAOS_UDF_CHECK_PTR_RCODE(block, interBuf, newInterBuf, udfCtx); SUdfCPluginCtx *ctx = udfCtx; if (ctx->aggProcFunc) { return ctx->aggProcFunc(block, interBuf, newInterBuf); @@ -189,6 +196,7 @@ int32_t udfdCPluginUdfAggProc(SUdfDataBlock *block, SUdfInterBuf *interBuf, SUdf int32_t udfdCPluginUdfAggMerge(SUdfInterBuf *inputBuf1, SUdfInterBuf *inputBuf2, SUdfInterBuf *outputBuf, void *udfCtx) { + TAOS_UDF_CHECK_PTR_RCODE(inputBuf1, inputBuf2, outputBuf, udfCtx); SUdfCPluginCtx *ctx = udfCtx; if (ctx->aggMergeFunc) { return ctx->aggMergeFunc(inputBuf1, inputBuf2, outputBuf); @@ -199,6 +207,7 @@ int32_t udfdCPluginUdfAggMerge(SUdfInterBuf *inputBuf1, SUdfInterBuf *inputBuf2, } int32_t udfdCPluginUdfAggFinish(SUdfInterBuf *buf, SUdfInterBuf *resultData, void *udfCtx) { + TAOS_UDF_CHECK_PTR_RCODE(buf, resultData, udfCtx); SUdfCPluginCtx *ctx = udfCtx; if (ctx->aggFinishFunc) { return ctx->aggFinishFunc(buf, resultData); @@ -360,6 +369,7 @@ int32_t udfdNewUdf(SUdf **pUdf, const char *udfName); void udfdGetFuncBodyPath(const SUdf *udf, char *path); int32_t udfdInitializeCPlugin(SUdfScriptPlugin *plugin) { + TAOS_UDF_CHECK_PTR_RCODE(plugin); plugin->scriptType = TSDB_FUNC_SCRIPT_BIN_LIB; plugin->openFunc = udfdCPluginOpen; plugin->closeFunc = udfdCPluginClose; @@ -378,6 +388,7 @@ int32_t udfdInitializeCPlugin(SUdfScriptPlugin *plugin) { } int32_t udfdLoadSharedLib(char *libPath, uv_lib_t *pLib, const char *funcName[], void **func[], int numOfFuncs) { + TAOS_UDF_CHECK_PTR_RCODE(libPath, pLib, funcName, func); int err = uv_dlopen(libPath, pLib); if (err != 0) { fnError("can not load library %s. error: %s", libPath, uv_strerror(err)); @@ -394,6 +405,7 @@ int32_t udfdLoadSharedLib(char *libPath, uv_lib_t *pLib, const char *funcName[], } int32_t udfdInitializePythonPlugin(SUdfScriptPlugin *plugin) { + TAOS_UDF_CHECK_PTR_RCODE(plugin); plugin->scriptType = TSDB_FUNC_SCRIPT_PYTHON; // todo: windows support snprintf(plugin->libPath, PATH_MAX, "%s", "libtaospyudf.so"); @@ -439,6 +451,7 @@ int32_t udfdInitializePythonPlugin(SUdfScriptPlugin *plugin) { } void udfdDeinitCPlugin(SUdfScriptPlugin *plugin) { + TAOS_UDF_CHECK_PTR_RVOID(plugin); if (plugin->closeFunc) { if (plugin->closeFunc() != 0) { fnError("udf script c plugin close func failed.line:%d", __LINE__); @@ -457,8 +470,9 @@ void udfdDeinitCPlugin(SUdfScriptPlugin *plugin) { } void udfdDeinitPythonPlugin(SUdfScriptPlugin *plugin) { + TAOS_UDF_CHECK_PTR_RVOID(plugin); if (plugin->closeFunc) { - if(plugin->closeFunc() != 0) { + if (plugin->closeFunc() != 0) { fnError("udf script python plugin close func failed.line:%d", __LINE__); } } @@ -517,22 +531,29 @@ void udfdDeinitScriptPlugins() { if (plugin != NULL) { udfdDeinitPythonPlugin(plugin); taosMemoryFree(plugin); + global.scriptPlugins[TSDB_FUNC_SCRIPT_PYTHON] = NULL; } plugin = global.scriptPlugins[TSDB_FUNC_SCRIPT_BIN_LIB]; if (plugin != NULL) { udfdDeinitCPlugin(plugin); taosMemoryFree(plugin); + global.scriptPlugins[TSDB_FUNC_SCRIPT_BIN_LIB] = NULL; } return; } void udfdProcessRequest(uv_work_t *req) { + TAOS_UDF_CHECK_PTR_RVOID(req); SUvUdfWork *uvUdf = (SUvUdfWork *)(req->data); + if (uvUdf == NULL) { + fnError("udf work is NULL"); + return; + } SUdfRequest request = {0}; if(decodeUdfRequest(uvUdf->input.base, &request) == NULL) { - taosMemoryFree(uvUdf->input.base); + taosMemoryFreeClear(uvUdf->input.base); fnError("udf request decode failed"); return; } @@ -557,7 +578,7 @@ void udfdProcessRequest(uv_work_t *req) { } } -void convertUdf2UdfInfo(SUdf *udf, SScriptUdfInfo *udfInfo) { +static void convertUdf2UdfInfo(SUdf *udf, SScriptUdfInfo *udfInfo) { udfInfo->bufSize = udf->bufSize; if (udf->funcType == TSDB_FUNC_TYPE_AGGREGATE) { udfInfo->funcType = UDF_FUNC_TYPE_AGG; @@ -573,7 +594,8 @@ void convertUdf2UdfInfo(SUdf *udf, SScriptUdfInfo *udfInfo) { udfInfo->scriptType = udf->scriptType; } -int32_t udfdInitUdf(char *udfName, SUdf *udf) { +static int32_t udfdInitUdf(char *udfName, SUdf *udf) { + TAOS_UDF_CHECK_PTR_RCODE(udfName, udf); int32_t err = 0; err = udfdFillUdfInfoFromMNode(global.clientRpc, udfName, udf); if (err != 0) { @@ -611,6 +633,7 @@ int32_t udfdInitUdf(char *udfName, SUdf *udf) { } int32_t udfdNewUdf(SUdf **pUdf, const char *udfName) { + TAOS_UDF_CHECK_PTR_RCODE(pUdf, udfName); SUdf *udfNew = taosMemoryCalloc(1, sizeof(SUdf)); if (NULL == udfNew) { return terrno; @@ -654,6 +677,7 @@ void udfdFreeUdf(void *pData) { } int32_t udfdGetOrCreateUdf(SUdf **ppUdf, const char *udfName) { + TAOS_UDF_CHECK_PTR_RCODE(ppUdf, udfName); uv_mutex_lock(&global.udfsMutex); SUdf **pUdfHash = taosHashGet(global.udfsHash, udfName, strlen(udfName)); int64_t currTime = taosGetTimestampMs(); @@ -693,6 +717,7 @@ int32_t udfdGetOrCreateUdf(SUdf **ppUdf, const char *udfName) { } void udfdProcessSetupRequest(SUvUdfWork *uvUdf, SUdfRequest *request) { + TAOS_UDF_CHECK_PTR_RVOID(uvUdf, request); // TODO: tracable id from client. connect, setup, call, teardown fnInfo("setup request. seq num: %" PRId64 ", udf name: %s", request->seqNum, request->setup.udfName); @@ -760,11 +785,55 @@ _send: uvUdf->output = uv_buf_init(bufBegin, len); - taosMemoryFree(uvUdf->input.base); + taosMemoryFreeClear(uvUdf->input.base); return; } +static int32_t checkUDFScalaResult(SSDataBlock *block, SUdfColumn *output) { + if (tsSafetyCheckLevel == TSDB_SAFETY_CHECK_LEVELL_NEVER) { + return TSDB_CODE_SUCCESS; + } + if (output->colData.numOfRows != block->info.rows) { + fnError("udf scala result num of rows %d not equal to input rows %" PRId64, output->colData.numOfRows, block->info.rows); + return TSDB_CODE_UDF_FUNC_EXEC_FAILURE; + } + + if (tsSafetyCheckLevel == TSDB_SAFETY_CHECK_LEVELL_BYROW) { + for (int32_t i = 0; i < output->colData.numOfRows; ++i) { + if (!udfColDataIsNull(output, i)) { + if (IS_VAR_DATA_TYPE(output->colMeta.type)) { + TAOS_UDF_CHECK_CONDITION(output->colData.varLenCol.payload != NULL, TSDB_CODE_UDF_FUNC_EXEC_FAILURE); + TAOS_UDF_CHECK_CONDITION(output->colData.varLenCol.varOffsets[i] >= 0 && + output->colData.varLenCol.varOffsets[i] < output->colData.varLenCol.payloadLen, + TSDB_CODE_UDF_FUNC_EXEC_FAILURE); + } else { + TAOS_UDF_CHECK_CONDITION( + output->colMeta.bytes * output->colData.numOfRows <= output->colData.fixLenCol.dataLen, + TSDB_CODE_UDF_FUNC_EXEC_FAILURE); + break; + } + } + } + } + + return TSDB_CODE_SUCCESS; +} + +static int32_t checkUDFAggResult(SSDataBlock *block, SUdfInterBuf *output) { + if (tsSafetyCheckLevel == TSDB_SAFETY_CHECK_LEVELL_NEVER) { + return TSDB_CODE_SUCCESS; + } + if (output->numOfResult != 1 && output->numOfResult != 0) { + fnError("udf agg result num of rows %d not equal to 1", output->numOfResult); + return TSDB_CODE_UDF_FUNC_EXEC_FAILURE; + } + TAOS_UDF_CHECK_CONDITION(output->buf != NULL, TSDB_CODE_UDF_FUNC_EXEC_FAILURE); + TAOS_UDF_CHECK_CONDITION(output->bufLen > 0, TSDB_CODE_UDF_FUNC_EXEC_FAILURE); + return TSDB_CODE_SUCCESS; +} + void udfdProcessCallRequest(SUvUdfWork *uvUdf, SUdfRequest *request) { + TAOS_UDF_CHECK_PTR_RVOID(uvUdf, request); SUdfCallRequest *call = &request->call; fnDebug("call request. call type %d, handle: %" PRIx64 ", seq num %" PRId64, call->callType, call->udfHandle, request->seqNum); @@ -787,6 +856,7 @@ void udfdProcessCallRequest(SUvUdfWork *uvUdf, SUdfRequest *request) { code = convertDataBlockToUdfDataBlock(&call->block, &input); if (code == TSDB_CODE_SUCCESS) code = udf->scriptPlugin->udfScalarProcFunc(&input, &output, udf->scriptUdfCtx); freeUdfDataDataBlock(&input); + if (code == TSDB_CODE_SUCCESS) code = checkUDFScalaResult(&call->block, &output); if (code == TSDB_CODE_SUCCESS) code = convertUdfColumnToDataBlock(&output, &response.callRsp.resultData); } freeUdfColumn(&output); @@ -809,6 +879,7 @@ void udfdProcessCallRequest(SUvUdfWork *uvUdf, SUdfRequest *request) { if (outBuf.buf != NULL) { code = udf->scriptPlugin->udfAggProcFunc(&input, &call->interBuf, &outBuf, udf->scriptUdfCtx); freeUdfInterBuf(&call->interBuf); + if (code == TSDB_CODE_SUCCESS) code = checkUDFAggResult(&call->block, &outBuf); subRsp->resultBuf = outBuf; } else { code = terrno; @@ -900,11 +971,12 @@ _exit: break; } - taosMemoryFree(uvUdf->input.base); + taosMemoryFreeClear(uvUdf->input.base); return; } void udfdProcessTeardownRequest(SUvUdfWork *uvUdf, SUdfRequest *request) { + TAOS_UDF_CHECK_PTR_RVOID(uvUdf, request); SUdfTeardownRequest *teardown = &request->teardown; fnInfo("teardown. seq number: %" PRId64 ", handle:%" PRIx64, request->seqNum, teardown->udfHandle); SUdfcFuncHandle *handle = (SUdfcFuncHandle *)(teardown->udfHandle); @@ -964,6 +1036,7 @@ _send: } void udfdGetFuncBodyPath(const SUdf *udf, char *path) { + TAOS_UDF_CHECK_PTR_RVOID(udf, path); if (udf->scriptType == TSDB_FUNC_SCRIPT_BIN_LIB) { #ifdef WINDOWS snprintf(path, PATH_MAX, "%s%s_%d_%" PRIx64 ".dll", global.udfDataDir, udf->name, udf->version, udf->createdTime); @@ -987,6 +1060,7 @@ void udfdGetFuncBodyPath(const SUdf *udf, char *path) { } int32_t udfdSaveFuncBodyToFile(SFuncInfo *pFuncInfo, SUdf *udf) { + TAOS_UDF_CHECK_PTR_RCODE(pFuncInfo, udf); if (!osDataSpaceAvailable()) { terrno = TSDB_CODE_NO_DISKSPACE; fnError("udfd create shared library failed since %s", terrstr()); @@ -1022,6 +1096,7 @@ int32_t udfdSaveFuncBodyToFile(SFuncInfo *pFuncInfo, SUdf *udf) { } void udfdProcessRpcRsp(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) { + TAOS_UDF_CHECK_PTR_RVOID(parent, pMsg); SUdfdRpcSendRecvInfo *msgInfo = (SUdfdRpcSendRecvInfo *)pMsg->info.ahandle; if (pEpSet) { @@ -1093,6 +1168,7 @@ _return: } int32_t udfdFillUdfInfoFromMNode(void *clientRpc, char *udfName, SUdf *udf) { + TAOS_UDF_CHECK_PTR_RCODE(clientRpc, udfName, udf); SRetrieveFuncReq retrieveReq = {0}; retrieveReq.numOfFuncs = 1; retrieveReq.pFuncNames = taosArrayInit(1, TSDB_FUNC_NAME_LEN); @@ -1233,6 +1309,7 @@ void udfdCloseClientRpc() { } void udfdOnWrite(uv_write_t *req, int status) { + TAOS_UDF_CHECK_PTR_RVOID(req); SUvUdfWork *work = (SUvUdfWork *)req->data; if (status < 0) { fnError("udfd send response error, length: %zu code: %s", work->output.len, uv_err_name(status)); @@ -1254,6 +1331,7 @@ void udfdOnWrite(uv_write_t *req, int status) { } void udfdSendResponse(uv_work_t *work, int status) { + TAOS_UDF_CHECK_PTR_RVOID(work); SUvUdfWork *udfWork = (SUvUdfWork *)(work->data); if (udfWork->conn != NULL) { @@ -1274,6 +1352,7 @@ void udfdSendResponse(uv_work_t *work, int status) { } void udfdAllocBuffer(uv_handle_t *handle, size_t suggestedSize, uv_buf_t *buf) { + TAOS_UDF_CHECK_PTR_RVOID(handle, buf); SUdfdUvConn *ctx = handle->data; int32_t msgHeadSize = sizeof(int32_t) + sizeof(int64_t); if (ctx->inputCap == 0) { @@ -1307,6 +1386,10 @@ void udfdAllocBuffer(uv_handle_t *handle, size_t suggestedSize, uv_buf_t *buf) { } bool isUdfdUvMsgComplete(SUdfdUvConn *pipe) { + if (pipe == NULL) { + fnError("udfd pipe is NULL, LINE:%d", __LINE__); + return false; + } if (pipe->inputTotal == -1 && pipe->inputLen >= sizeof(int32_t)) { pipe->inputTotal = *(int32_t *)(pipe->inputBuf); } @@ -1318,6 +1401,7 @@ bool isUdfdUvMsgComplete(SUdfdUvConn *pipe) { } void udfdHandleRequest(SUdfdUvConn *conn) { + TAOS_UDF_CHECK_PTR_RVOID(conn); char *inputBuf = conn->inputBuf; int32_t inputLen = conn->inputLen; @@ -1350,6 +1434,7 @@ void udfdHandleRequest(SUdfdUvConn *conn) { } void udfdPipeCloseCb(uv_handle_t *pipe) { + TAOS_UDF_CHECK_PTR_RVOID(pipe); SUdfdUvConn *conn = pipe->data; SUvUdfWork *pWork = conn->pWorkList; while (pWork != NULL) { @@ -1363,6 +1448,7 @@ void udfdPipeCloseCb(uv_handle_t *pipe) { } void udfdPipeRead(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf) { + TAOS_UDF_CHECK_PTR_RVOID(client, buf); fnDebug("udfd read %zd bytes from client", nread); if (nread == 0) return; @@ -1389,6 +1475,7 @@ void udfdPipeRead(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf) { } void udfdOnNewConnection(uv_stream_t *server, int status) { + TAOS_UDF_CHECK_PTR_RVOID(server); if (status < 0) { fnError("udfd new connection error. code: %s", uv_strerror(status)); return; @@ -1434,6 +1521,7 @@ _exit: } void udfdIntrSignalHandler(uv_signal_t *handle, int signum) { + TAOS_UDF_CHECK_PTR_RVOID(handle); fnInfo("udfd signal received: %d\n", signum); uv_fs_t req; int32_t code = uv_fs_unlink(global.loop, &req, global.listenPipeName, NULL); @@ -1482,6 +1570,7 @@ static int32_t udfdInitLog() { } void udfdCtrlAllocBufCb(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) { + TAOS_UDF_CHECK_PTR_RVOID(buf); buf->base = taosMemoryMalloc(suggested_size); if (buf->base == NULL) { fnError("udfd ctrl pipe alloc buffer failed"); @@ -1491,6 +1580,7 @@ void udfdCtrlAllocBufCb(uv_handle_t *handle, size_t suggested_size, uv_buf_t *bu } void udfdCtrlReadCb(uv_stream_t *q, ssize_t nread, const uv_buf_t *buf) { + TAOS_UDF_CHECK_PTR_RVOID(q, buf); if (nread < 0) { fnError("udfd ctrl pipe read error. %s", uv_err_name(nread)); taosMemoryFree(buf->base); @@ -1507,7 +1597,7 @@ static void removeListeningPipe() { int err = uv_fs_unlink(global.loop, &req, global.listenPipeName, NULL); uv_fs_req_cleanup(&req); if(err) { - fnError("remove listening pipe %s failed, reason:%s, lino:%d", global.listenPipeName, uv_strerror(err), __LINE__); + fnInfo("remove listening pipe %s : %s, lino:%d", global.listenPipeName, uv_strerror(err), __LINE__); } } @@ -1580,7 +1670,7 @@ static void udfdGlobalDataDeinit() { taosHashCleanup(global.udfsHash); uv_mutex_destroy(&global.udfsMutex); uv_mutex_destroy(&global.scriptPluginsMutex); - taosMemoryFree(global.loop); + taosMemoryFreeClear(global.loop); fnInfo("udfd global data deinit"); } diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index 1a5785190b..ba87912670 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -851,6 +851,7 @@ static int32_t slotDescCopy(const SSlotDescNode* pSrc, SSlotDescNode* pDst) { static int32_t downstreamSourceCopy(const SDownstreamSourceNode* pSrc, SDownstreamSourceNode* pDst) { COPY_OBJECT_FIELD(addr, sizeof(SQueryNodeAddr)); + COPY_SCALAR_FIELD(clientId); COPY_SCALAR_FIELD(taskId); COPY_SCALAR_FIELD(schedId); COPY_SCALAR_FIELD(execId); diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 3275cfd838..f7f858db78 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -5259,6 +5259,7 @@ static int32_t jsonToColumnDefNode(const SJson* pJson, void* pObj) { } static const char* jkDownstreamSourceAddr = "Addr"; +static const char* jkDownstreamSourceClientId = "ClientId"; static const char* jkDownstreamSourceTaskId = "TaskId"; static const char* jkDownstreamSourceSchedId = "SchedId"; static const char* jkDownstreamSourceExecId = "ExecId"; @@ -5268,6 +5269,9 @@ static int32_t downstreamSourceNodeToJson(const void* pObj, SJson* pJson) { const SDownstreamSourceNode* pNode = (const SDownstreamSourceNode*)pObj; int32_t code = tjsonAddObject(pJson, jkDownstreamSourceAddr, queryNodeAddrToJson, &pNode->addr); + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkDownstreamSourceClientId, pNode->clientId); + } if (TSDB_CODE_SUCCESS == code) { code = tjsonAddIntegerToObject(pJson, jkDownstreamSourceTaskId, pNode->taskId); } @@ -5288,6 +5292,9 @@ static int32_t jsonToDownstreamSourceNode(const SJson* pJson, void* pObj) { SDownstreamSourceNode* pNode = (SDownstreamSourceNode*)pObj; int32_t code = tjsonToObject(pJson, jkDownstreamSourceAddr, jsonToQueryNodeAddr, &pNode->addr); + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetUBigIntValue(pJson, jkDownstreamSourceClientId, &pNode->clientId); + } if (TSDB_CODE_SUCCESS == code) { code = tjsonGetUBigIntValue(pJson, jkDownstreamSourceTaskId, &pNode->taskId); } diff --git a/source/libs/nodes/src/nodesMsgFuncs.c b/source/libs/nodes/src/nodesMsgFuncs.c index 28d0b9fbd4..bf3ea66e47 100644 --- a/source/libs/nodes/src/nodesMsgFuncs.c +++ b/source/libs/nodes/src/nodesMsgFuncs.c @@ -1769,6 +1769,9 @@ static int32_t downstreamSourceNodeInlineToMsg(const void* pObj, STlvEncoder* pE if (TSDB_CODE_SUCCESS == code) { code = tlvEncodeValueI32(pEncoder, pNode->fetchMsgType); } + if (TSDB_CODE_SUCCESS == code) { + code = tlvEncodeValueU64(pEncoder, pNode->clientId); + } return code; } @@ -1793,6 +1796,9 @@ static int32_t msgToDownstreamSourceNodeInlineToMsg(STlvDecoder* pDecoder, void* if (TSDB_CODE_SUCCESS == code) { code = tlvDecodeValueI32(pDecoder, &pNode->fetchMsgType); } + if (TSDB_CODE_SUCCESS == code && !tlvDecodeEnd(pDecoder)) { + code = tlvDecodeValueU64(pDecoder, &pNode->clientId); + } return code; } diff --git a/source/libs/parser/src/parInsertSql.c b/source/libs/parser/src/parInsertSql.c index 4b91f01a8c..750621bf66 100644 --- a/source/libs/parser/src/parInsertSql.c +++ b/source/libs/parser/src/parInsertSql.c @@ -246,7 +246,7 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, const char** pSql, E return code; } -static int parseTimestampOrInterval(const char** end, SToken* pToken, int16_t timePrec, int64_t* ts, int64_t* interval, +static int32_t parseTimestampOrInterval(const char** end, SToken* pToken, int16_t timePrec, int64_t* ts, int64_t* interval, SMsgBuf* pMsgBuf, bool* isTs) { if (pToken->type == TK_NOW) { *isTs = true; diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 99c03c412c..9bea3491c3 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -3311,11 +3311,11 @@ static int32_t selectCommonType(SDataType* commonType, const SDataType* newType) } else { resultType = gDisplyTypes[type2][type1]; } - + if (resultType == -1) { return TSDB_CODE_SCALAR_CONVERT_ERROR; } - + if (commonType->type == newType->type) { commonType->bytes = TMAX(commonType->bytes, newType->bytes); return TSDB_CODE_SUCCESS; @@ -3328,9 +3328,9 @@ static int32_t selectCommonType(SDataType* commonType, const SDataType* newType) } else { commonType->bytes = TMAX(TMAX(commonType->bytes, newType->bytes), TYPE_BYTES[resultType]); } - + commonType->type = resultType; - + return TSDB_CODE_SUCCESS; } @@ -13127,7 +13127,7 @@ static int32_t extractShowCreateViewResultSchema(int32_t* numOfCols, SSchema** p } static int32_t extractShowVariablesResultSchema(int32_t* numOfCols, SSchema** pSchema) { - *numOfCols = 3; + *numOfCols = SHOW_LOCAL_VARIABLES_RESULT_COLS; // SHOW_VARIABLES_RESULT_COLS *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); if (NULL == (*pSchema)) { return terrno; @@ -13138,13 +13138,17 @@ static int32_t extractShowVariablesResultSchema(int32_t* numOfCols, SSchema** pS strcpy((*pSchema)[0].name, "name"); (*pSchema)[1].type = TSDB_DATA_TYPE_BINARY; - (*pSchema)[1].bytes = TSDB_CONFIG_VALUE_LEN; + (*pSchema)[1].bytes = TSDB_CONFIG_PATH_LEN; strcpy((*pSchema)[1].name, "value"); (*pSchema)[2].type = TSDB_DATA_TYPE_BINARY; (*pSchema)[2].bytes = TSDB_CONFIG_SCOPE_LEN; strcpy((*pSchema)[2].name, "scope"); + (*pSchema)[3].type = TSDB_DATA_TYPE_BINARY; + (*pSchema)[3].bytes = TSDB_CONFIG_INFO_LEN; + strcpy((*pSchema)[3].name, "info"); + return TSDB_CODE_SUCCESS; } diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index 885faa5461..39024731ed 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -3491,37 +3491,77 @@ static void eliminateProjPushdownProjIdx(SNodeList* pParentProjects, SNodeList* } } +static int32_t eliminateProjOptFindProjPrefixWithOrderCheck(SProjectLogicNode* pProj, SProjectLogicNode* pChild, SNodeList** pNewChildTargets, bool *orderMatch) { + int32_t code = 0; + SNode* pProjection = NULL, *pChildTarget = NULL; + *orderMatch = true; + FORBOTH(pProjection, pProj->pProjections, pChildTarget, pChild->node.pTargets) { + if (!pProjection) break; + if (0 != strcmp(((SColumnNode*)pProjection)->colName, ((SColumnNode*)pChildTarget)->colName)) { + *orderMatch = false; + break; + } + if (pNewChildTargets) { + SNode* pNew = NULL; + code = nodesCloneNode(pChildTarget, &pNew); + if (TSDB_CODE_SUCCESS == code) { + code = nodesListMakeStrictAppend(pNewChildTargets, pNew); + } + if (TSDB_CODE_SUCCESS != code && pNewChildTargets) { + nodesDestroyList(*pNewChildTargets); + *pNewChildTargets = NULL; + break; + } + } + } + return code; +} + +static int32_t eliminateProjOptPushTargetsToSetOpChildren(SProjectLogicNode* pSetOp) { + SNode* pChildProj = NULL; + int32_t code = 0; + bool orderMatch = false; + FOREACH(pChildProj, pSetOp->node.pChildren) { + if (QUERY_NODE_LOGIC_PLAN_PROJECT == nodeType(pChildProj)) { + SProjectLogicNode* pChildLogic = (SProjectLogicNode*)pChildProj; + SNodeList* pNewChildTargetsForChild = NULL; + code = eliminateProjOptFindProjPrefixWithOrderCheck(pSetOp, pChildLogic, &pNewChildTargetsForChild, &orderMatch); + if (TSDB_CODE_SUCCESS != code) break; + nodesDestroyList(pChildLogic->node.pTargets); + pChildLogic->node.pTargets = pNewChildTargetsForChild; + alignProjectionWithTarget((SLogicNode*)pChildLogic); + if (pChildLogic->isSetOpProj) { + code = eliminateProjOptPushTargetsToSetOpChildren(pChildLogic); + if (TSDB_CODE_SUCCESS != code) break; + } + } + } + return code; +} + static int32_t eliminateProjOptimizeImpl(SOptimizeContext* pCxt, SLogicSubplan* pLogicSubplan, SProjectLogicNode* pProjectNode) { SLogicNode* pChild = (SLogicNode*)nodesListGetNode(pProjectNode->node.pChildren, 0); int32_t code = 0; + bool isSetOpProj = false; + bool orderMatch = false; + bool sizeMatch = LIST_LENGTH(pProjectNode->pProjections) == LIST_LENGTH(pChild->pTargets); + bool needReplaceTargets = true; if (NULL == pProjectNode->node.pParent) { SNodeList* pNewChildTargets = NULL; - code = nodesMakeList(&pNewChildTargets); - if (TSDB_CODE_SUCCESS != code) { - return code; - } SNode * pProjection = NULL, *pChildTarget = NULL; - bool orderMatch = true; - bool needOrderMatch = + isSetOpProj = QUERY_NODE_LOGIC_PLAN_PROJECT == nodeType(pChild) && ((SProjectLogicNode*)pChild)->isSetOpProj; - if (needOrderMatch) { + if (isSetOpProj) { // For sql: select ... from (select ... union all select ...); // When eliminating the outer proj (the outer select), we have to make sure that the outer proj projections and // union all project targets have same columns in the same order. See detail in TD-30188 - FORBOTH(pProjection, pProjectNode->pProjections, pChildTarget, pChild->pTargets) { - if (!pProjection) break; - if (0 != strcmp(((SColumnNode*)pProjection)->colName, ((SColumnNode*)pChildTarget)->colName)) { - orderMatch = false; - break; - } - SNode* pNew = NULL; - code = nodesCloneNode(pChildTarget, &pNew); - if (TSDB_CODE_SUCCESS == code) { - code = nodesListStrictAppend(pNewChildTargets, pNew); - } - if (TSDB_CODE_SUCCESS != code) break; + code = eliminateProjOptFindProjPrefixWithOrderCheck(pProjectNode, (SProjectLogicNode*)pChild, + sizeMatch ? NULL : &pNewChildTargets, &orderMatch); + if (TSDB_CODE_SUCCESS == code && sizeMatch && orderMatch) { + pNewChildTargets = pChild->pTargets; + needReplaceTargets = false; } } else { FOREACH(pProjection, pProjectNode->pProjections) { @@ -3530,7 +3570,7 @@ static int32_t eliminateProjOptimizeImpl(SOptimizeContext* pCxt, SLogicSubplan* SNode* pNew = NULL; code = nodesCloneNode(pChildTarget, &pNew); if (TSDB_CODE_SUCCESS == code) { - code = nodesListStrictAppend(pNewChildTargets, pNew); + code = nodesListMakeStrictAppend(&pNewChildTargets, pNew); } break; } @@ -3545,12 +3585,13 @@ static int32_t eliminateProjOptimizeImpl(SOptimizeContext* pCxt, SLogicSubplan* return code; } - if (eliminateProjOptCanChildConditionUseChildTargets(pChild, pNewChildTargets) && - (!needOrderMatch || (needOrderMatch && orderMatch))) { - nodesDestroyList(pChild->pTargets); - pChild->pTargets = pNewChildTargets; + if (eliminateProjOptCanChildConditionUseChildTargets(pChild, pNewChildTargets) && (!isSetOpProj || orderMatch)) { + if (needReplaceTargets) { + nodesDestroyList(pChild->pTargets); + pChild->pTargets = pNewChildTargets; + } } else { - nodesDestroyList(pNewChildTargets); + if (needReplaceTargets) nodesDestroyList(pNewChildTargets); OPTIMIZE_FLAG_SET_MASK(pProjectNode->node.optimizedFlag, OPTIMIZE_FLAG_ELIMINATE_PROJ); pCxt->optimized = true; return TSDB_CODE_SUCCESS; @@ -3573,7 +3614,11 @@ static int32_t eliminateProjOptimizeImpl(SOptimizeContext* pCxt, SLogicSubplan* NODES_CLEAR_LIST(pProjectNode->node.pChildren); nodesDestroyNode((SNode*)pProjectNode); // if pChild is a project logic node, remove its projection which is not reference by its target. - alignProjectionWithTarget(pChild); + if (needReplaceTargets) { + alignProjectionWithTarget(pChild); + // Since we have eliminated the outer proj, we need to push down the new targets to the children of the set operation. + if (isSetOpProj && orderMatch && !sizeMatch) code = eliminateProjOptPushTargetsToSetOpChildren((SProjectLogicNode*)pChild); + } } pCxt->optimized = true; return code; diff --git a/source/libs/qcom/inc/queryInt.h b/source/libs/qcom/inc/queryInt.h index ee7d4499d2..7820b1390c 100644 --- a/source/libs/qcom/inc/queryInt.h +++ b/source/libs/qcom/inc/queryInt.h @@ -23,7 +23,13 @@ extern "C" { #define VALIDNUMOFCOLS(x) ((x) >= TSDB_MIN_COLUMNS && (x) <= TSDB_MAX_COLUMNS) #define VALIDNUMOFTAGS(x) ((x) >= 0 && (x) <= TSDB_MAX_TAGS) - +#define QUERY_PARAM_CHECK(_p) \ + do { \ + if ((_p) == NULL) { \ + qError("function:%s, param invalid, line:%d", __FUNCTION__, __LINE__); \ + return TSDB_CODE_TSC_INVALID_INPUT; \ + } \ + } while (0) #ifdef __cplusplus } diff --git a/source/libs/qcom/src/queryUtil.c b/source/libs/qcom/src/queryUtil.c index 847fc9b8e9..54e92c6a1b 100644 --- a/source/libs/qcom/src/queryUtil.c +++ b/source/libs/qcom/src/queryUtil.c @@ -59,6 +59,9 @@ const SSchema* tGetTbnameColumnSchema() { } static bool doValidateSchema(SSchema* pSchema, int32_t numOfCols, int32_t maxLen) { + if (!pSchema) { + return false; + } int32_t rowLen = 0; for (int32_t i = 0; i < numOfCols; ++i) { @@ -100,7 +103,7 @@ static bool doValidateSchema(SSchema* pSchema, int32_t numOfCols, int32_t maxLen } bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags) { - if (!VALIDNUMOFCOLS(numOfCols)) { + if (!pSchema || !VALIDNUMOFCOLS(numOfCols)) { return false; } @@ -127,6 +130,7 @@ bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTag static STaskQueue taskQueue = {0}; static void processTaskQueue(SQueueInfo *pInfo, SSchedMsg *pSchedMsg) { + if(!pSchedMsg || !pSchedMsg->ahandle) return; __async_exec_fn_t execFn = (__async_exec_fn_t)pSchedMsg->ahandle; (void)execFn(pSchedMsg->thandle); taosFreeQitem(pSchedMsg); @@ -205,7 +209,11 @@ void destroyAhandle(void *ahandle) { } int32_t asyncSendMsgToServerExt(void* pTransporter, SEpSet* epSet, int64_t* pTransporterId, SMsgSendInfo* pInfo, - bool persistHandle, void* rpcCtx) { + bool persistHandle, void* rpcCtx) { + QUERY_PARAM_CHECK(pTransporter); + QUERY_PARAM_CHECK(epSet); + QUERY_PARAM_CHECK(pInfo); + char* pMsg = rpcMallocCont(pInfo->msgInfo.len); if (NULL == pMsg) { qError("0x%" PRIx64 " msg:%s malloc failed", pInfo->requestId, TMSG_INFO(pInfo->msgType)); @@ -236,6 +244,7 @@ int32_t asyncSendMsgToServer(void* pTransporter, SEpSet* epSet, int64_t* pTransp return asyncSendMsgToServerExt(pTransporter, epSet, pTransporterId, pInfo, false, NULL); } int32_t asyncFreeConnById(void* pTransporter, int64_t pid) { + QUERY_PARAM_CHECK(pTransporter); return rpcFreeConnById(pTransporter, pid); } @@ -314,6 +323,8 @@ void destroyQueryExecRes(SExecResult* pRes) { } // clang-format on int32_t dataConverToStr(char* str, int64_t capacity, int type, void* buf, int32_t bufSize, int32_t* len) { + QUERY_PARAM_CHECK(str); + QUERY_PARAM_CHECK(buf); int32_t n = 0; switch (type) { @@ -420,6 +431,10 @@ int32_t dataConverToStr(char* str, int64_t capacity, int type, void* buf, int32_ } void parseTagDatatoJson(void* p, char** jsonStr) { + if (!p || !jsonStr) { + qError("parseTagDatatoJson invalid input, line:%d", __LINE__); + return; + } char* string = NULL; SArray* pTagVals = NULL; cJSON* json = NULL; @@ -520,6 +535,7 @@ end: } int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst) { + QUERY_PARAM_CHECK(pDst); if (NULL == pSrc) { *pDst = NULL; return TSDB_CODE_SUCCESS; @@ -553,6 +569,7 @@ int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst) { } void getColumnTypeFromMeta(STableMeta* pMeta, char* pName, ETableColumnType* pType) { + if(!pMeta || !pName || !pType) return; int32_t nums = pMeta->tableInfo.numOfTags + pMeta->tableInfo.numOfColumns; for (int32_t i = 0; i < nums; ++i) { if (0 == strcmp(pName, pMeta->schema[i].name)) { @@ -576,6 +593,7 @@ void freeVgInfo(SDBVgInfo* vgInfo) { } int32_t cloneDbVgInfo(SDBVgInfo* pSrc, SDBVgInfo** pDst) { + QUERY_PARAM_CHECK(pDst); if (NULL == pSrc) { *pDst = NULL; return TSDB_CODE_SUCCESS; @@ -617,6 +635,7 @@ int32_t cloneDbVgInfo(SDBVgInfo* pSrc, SDBVgInfo** pDst) { } int32_t cloneSVreateTbReq(SVCreateTbReq* pSrc, SVCreateTbReq** pDst) { + QUERY_PARAM_CHECK(pDst); if (NULL == pSrc) { *pDst = NULL; return TSDB_CODE_SUCCESS; @@ -674,6 +693,7 @@ int32_t cloneSVreateTbReq(SVCreateTbReq* pSrc, SVCreateTbReq** pDst) { _exit: tdDestroySVCreateTbReq(*pDst); taosMemoryFree(*pDst); + *pDst = NULL; return terrno; } diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index 60c760a60e..9d9c169c05 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -29,6 +29,8 @@ int32_t (*queryBuildMsg[TDMT_MAX])(void *input, char **msg, int32_t msgSize, int int32_t (*queryProcessMsgRsp[TDMT_MAX])(void *output, char *msg, int32_t msgSize) = {0}; int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp) { + QUERY_PARAM_CHECK(pOut); + QUERY_PARAM_CHECK(usedbRsp); memcpy(pOut->db, usedbRsp->db, TSDB_DB_FNAME_LEN); pOut->dbId = usedbRsp->uid; @@ -71,10 +73,10 @@ int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp) { int32_t queryBuildTableMetaReqMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { + QUERY_PARAM_CHECK(input); + QUERY_PARAM_CHECK(msg); + QUERY_PARAM_CHECK(msgLen); SBuildTableInput *pInput = input; - if (NULL == input || NULL == msg || NULL == msgLen) { - return TSDB_CODE_TSC_INVALID_INPUT; - } STableInfoReq infoReq = {0}; infoReq.option = pInput->option; @@ -101,10 +103,10 @@ int32_t queryBuildTableMetaReqMsg(void *input, char **msg, int32_t msgSize, int3 } int32_t queryBuildUseDbMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { + QUERY_PARAM_CHECK(input); + QUERY_PARAM_CHECK(msg); + QUERY_PARAM_CHECK(msgLen); SBuildUseDBInput *pInput = input; - if (NULL == pInput || NULL == msg || NULL == msgLen) { - return TSDB_CODE_TSC_INVALID_INPUT; - } SUseDbReq usedbReq = {0}; tstrncpy(usedbReq.db, pInput->db, TSDB_DB_FNAME_LEN); @@ -131,9 +133,8 @@ int32_t queryBuildUseDbMsg(void *input, char **msg, int32_t msgSize, int32_t *ms } int32_t queryBuildQnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { - if (NULL == msg || NULL == msgLen) { - return TSDB_CODE_TSC_INVALID_INPUT; - } + QUERY_PARAM_CHECK(msg); + QUERY_PARAM_CHECK(msgLen); SQnodeListReq qnodeListReq = {0}; qnodeListReq.rowNum = -1; @@ -155,9 +156,8 @@ int32_t queryBuildQnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t } int32_t queryBuildDnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { - if (NULL == msg || NULL == msgLen) { - return TSDB_CODE_TSC_INVALID_INPUT; - } + QUERY_PARAM_CHECK(msg); + QUERY_PARAM_CHECK(msgLen); SDnodeListReq dnodeListReq = {0}; dnodeListReq.rowNum = -1; @@ -179,9 +179,8 @@ int32_t queryBuildDnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t } int32_t queryBuildGetSerVerMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { - if (NULL == msg || NULL == msgLen) { - return TSDB_CODE_TSC_INVALID_INPUT; - } + QUERY_PARAM_CHECK(msg); + QUERY_PARAM_CHECK(msgLen); SServerVerReq req = {0}; @@ -202,9 +201,9 @@ int32_t queryBuildGetSerVerMsg(void *input, char **msg, int32_t msgSize, int32_t } int32_t queryBuildGetDBCfgMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { - if (NULL == msg || NULL == msgLen) { - return TSDB_CODE_TSC_INVALID_INPUT; - } + QUERY_PARAM_CHECK(input); + QUERY_PARAM_CHECK(msg); + QUERY_PARAM_CHECK(msgLen); SDbCfgReq dbCfgReq = {0}; tstrncpy(dbCfgReq.db, input, TSDB_DB_FNAME_LEN); @@ -226,9 +225,9 @@ int32_t queryBuildGetDBCfgMsg(void *input, char **msg, int32_t msgSize, int32_t } int32_t queryBuildGetIndexMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { - if (NULL == msg || NULL == msgLen) { - return TSDB_CODE_TSC_INVALID_INPUT; - } + QUERY_PARAM_CHECK(input); + QUERY_PARAM_CHECK(msg); + QUERY_PARAM_CHECK(msgLen); SUserIndexReq indexReq = {0}; tstrncpy(indexReq.indexFName, input, TSDB_INDEX_FNAME_LEN); @@ -251,9 +250,9 @@ int32_t queryBuildGetIndexMsg(void *input, char **msg, int32_t msgSize, int32_t int32_t queryBuildRetrieveFuncMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { - if (NULL == msg || NULL == msgLen) { - return TSDB_CODE_TSC_INVALID_INPUT; - } + QUERY_PARAM_CHECK(input); + QUERY_PARAM_CHECK(msg); + QUERY_PARAM_CHECK(msgLen); SRetrieveFuncReq funcReq = {0}; funcReq.numOfFuncs = 1; @@ -288,9 +287,9 @@ int32_t queryBuildRetrieveFuncMsg(void *input, char **msg, int32_t msgSize, int3 } int32_t queryBuildGetUserAuthMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { - if (NULL == msg || NULL == msgLen) { - return TSDB_CODE_TSC_INVALID_INPUT; - } + QUERY_PARAM_CHECK(input); + QUERY_PARAM_CHECK(msg); + QUERY_PARAM_CHECK(msgLen); SGetUserAuthReq req = {0}; tstrncpy(req.user, input, TSDB_USER_LEN); @@ -311,9 +310,9 @@ int32_t queryBuildGetUserAuthMsg(void *input, char **msg, int32_t msgSize, int32 } int32_t queryBuildGetTbIndexMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { - if (NULL == msg || NULL == msgLen) { - return TSDB_CODE_TSC_INVALID_INPUT; - } + QUERY_PARAM_CHECK(input); + QUERY_PARAM_CHECK(msg); + QUERY_PARAM_CHECK(msgLen); STableIndexReq indexReq = {0}; tstrncpy(indexReq.tbFName, input, TSDB_TABLE_FNAME_LEN); @@ -335,9 +334,9 @@ int32_t queryBuildGetTbIndexMsg(void *input, char **msg, int32_t msgSize, int32_ } int32_t queryBuildGetTbCfgMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { - if (NULL == msg || NULL == msgLen) { - return TSDB_CODE_TSC_INVALID_INPUT; - } + QUERY_PARAM_CHECK(input); + QUERY_PARAM_CHECK(msg); + QUERY_PARAM_CHECK(msgLen); SBuildTableInput *pInput = input; STableCfgReq cfgReq = {0}; @@ -362,9 +361,9 @@ int32_t queryBuildGetTbCfgMsg(void *input, char **msg, int32_t msgSize, int32_t } int32_t queryBuildGetViewMetaMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { - if (NULL == msg || NULL == msgLen) { - return TSDB_CODE_TSC_INVALID_INPUT; - } + QUERY_PARAM_CHECK(input); + QUERY_PARAM_CHECK(msg); + QUERY_PARAM_CHECK(msgLen); SViewMetaReq req = {0}; tstrncpy(req.fullname, input, TSDB_VIEW_FNAME_LEN); @@ -387,9 +386,9 @@ int32_t queryBuildGetViewMetaMsg(void *input, char **msg, int32_t msgSize, int32 int32_t queryBuildGetTableTSMAMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { - if (NULL == msg || NULL == msgLen) { - return TSDB_CODE_TSC_INVALID_INPUT; - } + QUERY_PARAM_CHECK(input); + QUERY_PARAM_CHECK(msg); + QUERY_PARAM_CHECK(msgLen); STableTSMAInfoReq req = {0}; tstrncpy(req.name, input, TSDB_TABLE_FNAME_LEN); @@ -411,9 +410,9 @@ int32_t queryBuildGetTableTSMAMsg(void *input, char **msg, int32_t msgSize, int3 int32_t queryBuildGetTSMAMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { - if (NULL == msg || NULL == msgLen) { - return TSDB_CODE_TSC_INVALID_INPUT; - } + QUERY_PARAM_CHECK(input); + QUERY_PARAM_CHECK(msg); + QUERY_PARAM_CHECK(msgLen); STableTSMAInfoReq req = {0}; req.fetchingWithTsmaName = true; @@ -436,9 +435,9 @@ int32_t queryBuildGetTSMAMsg(void *input, char **msg, int32_t msgSize, int32_t * } int32_t queryBuildGetStreamProgressMsg(void* input, char** msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int64_t)) { - if (!msg || !msgLen) { - return TSDB_CODE_TSC_INVALID_INPUT; - } + QUERY_PARAM_CHECK(input); + QUERY_PARAM_CHECK(msg); + QUERY_PARAM_CHECK(msgLen); int32_t len = tSerializeStreamProgressReq(NULL, 0, input); void* pBuf = (*mallcFp)(len); @@ -504,6 +503,7 @@ PROCESS_USEDB_OVER: } static int32_t queryConvertTableMetaMsg(STableMetaRsp *pMetaMsg) { + QUERY_PARAM_CHECK(pMetaMsg); if (pMetaMsg->numOfTags < 0 || pMetaMsg->numOfTags > TSDB_MAX_TAGS) { qError("invalid numOfTags[%d] in table meta rsp msg", pMetaMsg->numOfTags); return TSDB_CODE_TSC_INVALID_VALUE; @@ -539,6 +539,8 @@ static int32_t queryConvertTableMetaMsg(STableMetaRsp *pMetaMsg) { } int32_t queryCreateCTableMetaFromMsg(STableMetaRsp *msg, SCTableMeta *pMeta) { + QUERY_PARAM_CHECK(msg); + QUERY_PARAM_CHECK(pMeta); pMeta->vgId = msg->vgId; pMeta->tableType = msg->tableType; pMeta->uid = msg->tuid; @@ -551,6 +553,8 @@ int32_t queryCreateCTableMetaFromMsg(STableMetaRsp *msg, SCTableMeta *pMeta) { } int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta **pMeta) { + QUERY_PARAM_CHECK(msg); + QUERY_PARAM_CHECK(pMeta); int32_t total = msg->numOfColumns + msg->numOfTags; int32_t metaSize = sizeof(STableMeta) + sizeof(SSchema) * total; int32_t schemaExtSize = (useCompress(msg->tableType) && msg->pSchemaExt) ? sizeof(SSchemaExt) * msg->numOfColumns : 0; @@ -605,6 +609,8 @@ int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta * } int32_t queryCreateTableMetaExFromMsg(STableMetaRsp *msg, bool isStb, STableMeta **pMeta) { + QUERY_PARAM_CHECK(msg); + QUERY_PARAM_CHECK(pMeta); int32_t total = msg->numOfColumns + msg->numOfTags; int32_t metaSize = sizeof(STableMeta) + sizeof(SSchema) * total; int32_t schemaExtSize = (useCompress(msg->tableType) && msg->pSchemaExt) ? sizeof(SSchemaExt) * msg->numOfColumns : 0; diff --git a/source/libs/qworker/inc/qwInt.h b/source/libs/qworker/inc/qwInt.h index 7a902bdd66..708c285aea 100644 --- a/source/libs/qworker/inc/qwInt.h +++ b/source/libs/qworker/inc/qwInt.h @@ -215,8 +215,8 @@ typedef struct SQWorkerMgmt { #define QW_CTX_NOT_EXISTS_ERR_CODE(mgmt) \ (atomic_load_8(&(mgmt)->nodeStopped) ? TSDB_CODE_VND_STOPPED : TSDB_CODE_QRY_TASK_CTX_NOT_EXIST) -#define QW_FPARAMS_DEF SQWorker *mgmt, uint64_t sId, uint64_t qId, uint64_t tId, int64_t rId, int32_t eId -#define QW_IDS() sId, qId, tId, rId, eId +#define QW_FPARAMS_DEF SQWorker *mgmt, uint64_t sId, uint64_t qId, uint64_t cId, uint64_t tId, int64_t rId, int32_t eId +#define QW_IDS() sId, qId, cId, tId, rId, eId #define QW_FPARAMS() mgmt, QW_IDS() #define QW_STAT_INC(_item, _n) (void)atomic_add_fetch_64(&(_item), _n) @@ -257,18 +257,20 @@ typedef struct SQWorkerMgmt { #define QW_FETCH_RUNNING(ctx) ((ctx)->inFetch) #define QW_QUERY_NOT_STARTED(ctx) (QW_GET_PHASE(ctx) == -1) -#define QW_SET_QTID(id, qId, tId, eId) \ - do { \ - *(uint64_t *)(id) = (qId); \ - *(uint64_t *)((char *)(id) + sizeof(qId)) = (tId); \ - *(int32_t *)((char *)(id) + sizeof(qId) + sizeof(tId)) = (eId); \ +#define QW_SET_QTID(id, qId, cId, tId, eId) \ + do { \ + *(uint64_t *)(id) = (qId); \ + *(uint64_t *)((char *)(id) + sizeof(qId)) = (cId); \ + *(uint64_t *)((char *)(id) + sizeof(qId) + sizeof(cId)) = (tId); \ + *(int32_t *)((char *)(id) + sizeof(qId) + sizeof(cId) + sizeof(tId)) = (eId); \ } while (0) -#define QW_GET_QTID(id, qId, tId, eId) \ - do { \ - (qId) = *(uint64_t *)(id); \ - (tId) = *(uint64_t *)((char *)(id) + sizeof(qId)); \ - (eId) = *(int32_t *)((char *)(id) + sizeof(qId) + sizeof(tId)); \ +#define QW_GET_QTID(id, qId, cId, tId, eId) \ + do { \ + (qId) = *(uint64_t *)(id); \ + (cId) = *(uint64_t *)((char *)(id) + sizeof(qId)); \ + (tId) = *(uint64_t *)((char *)(id) + sizeof(qId) + sizeof(cId)); \ + (eId) = *(int32_t *)((char *)(id) + sizeof(qId) + sizeof(cId) + sizeof(tId)); \ } while (0) #define QW_ERR_RET(c) \ @@ -310,25 +312,31 @@ typedef struct SQWorkerMgmt { #define QW_SCH_ELOG(param, ...) qError("QW:%p SID:%" PRIx64 " " param, mgmt, sId, __VA_ARGS__) #define QW_SCH_DLOG(param, ...) qDebug("QW:%p SID:%" PRIx64 " " param, mgmt, sId, __VA_ARGS__) -#define QW_TASK_ELOG(param, ...) qError("qid:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, qId, tId, eId, __VA_ARGS__) -#define QW_TASK_WLOG(param, ...) qWarn("qid:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, qId, tId, eId, __VA_ARGS__) -#define QW_TASK_DLOG(param, ...) qDebug("qid:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, qId, tId, eId, __VA_ARGS__) +#define QW_TASK_ELOG(param, ...) \ + qError("qid:0x%" PRIx64 ",CID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, qId, cId, tId, eId, __VA_ARGS__) +#define QW_TASK_WLOG(param, ...) \ + qWarn("qid:0x%" PRIx64 ",CID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, qId, cId, tId, eId, __VA_ARGS__) +#define QW_TASK_DLOG(param, ...) \ + qDebug("qid:0x%" PRIx64 ",CID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, qId, cId, tId, eId, __VA_ARGS__) #define QW_TASK_DLOGL(param, ...) \ - qDebugL("qid:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, qId, tId, eId, __VA_ARGS__) + qDebugL("qid:0x%" PRIx64 ",CID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, qId, cId, tId, eId, __VA_ARGS__) -#define QW_TASK_ELOG_E(param) qError("qid:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, qId, tId, eId) -#define QW_TASK_WLOG_E(param) qWarn("qid:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, qId, tId, eId) -#define QW_TASK_DLOG_E(param) qDebug("qid:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, qId, tId, eId) +#define QW_TASK_ELOG_E(param) \ + qError("qid:0x%" PRIx64 ",CID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, qId, cId, tId, eId) +#define QW_TASK_WLOG_E(param) \ + qWarn("qid:0x%" PRIx64 ",CID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, qId, cId, tId, eId) +#define QW_TASK_DLOG_E(param) \ + qDebug("qid:0x%" PRIx64 ",CID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, qId, cId, tId, eId) -#define QW_SCH_TASK_ELOG(param, ...) \ - qError("QW:%p SID:0x%" PRIx64 ",qid:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, mgmt, sId, qId, tId, eId, \ - __VA_ARGS__) -#define QW_SCH_TASK_WLOG(param, ...) \ - qWarn("QW:%p SID:0x%" PRIx64 ",qid:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, mgmt, sId, qId, tId, eId, \ - __VA_ARGS__) -#define QW_SCH_TASK_DLOG(param, ...) \ - qDebug("QW:%p SID:0x%" PRIx64 ",qid:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, mgmt, sId, qId, tId, eId, \ - __VA_ARGS__) +#define QW_SCH_TASK_ELOG(param, ...) \ + qError("QW:%p SID:0x%" PRIx64 ",qid:0x%" PRIx64 ",CID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, mgmt, sId, \ + qId, cId, tId, eId, __VA_ARGS__) +#define QW_SCH_TASK_WLOG(param, ...) \ + qWarn("QW:%p SID:0x%" PRIx64 ",qid:0x%" PRIx64 ",CID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, mgmt, sId, qId, \ + cId, tId, eId, __VA_ARGS__) +#define QW_SCH_TASK_DLOG(param, ...) \ + qDebug("QW:%p SID:0x%" PRIx64 ",qid:0x%" PRIx64 ",CID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, mgmt, sId, \ + qId, cId, tId, eId, __VA_ARGS__) #define QW_LOCK_DEBUG(...) \ do { \ diff --git a/source/libs/qworker/src/qwDbg.c b/source/libs/qworker/src/qwDbg.c index d3b8d36b25..897080df3e 100644 --- a/source/libs/qworker/src/qwDbg.c +++ b/source/libs/qworker/src/qwDbg.c @@ -96,14 +96,14 @@ void qwDbgDumpSchInfo(SQWorker *mgmt, SQWSchStatus *sch, int32_t i) { int32_t taskNum = taosHashGetSize(sch->tasksHash); QW_DLOG("***The %dth scheduler status, hbBrokenTs:%" PRId64 ",taskNum:%d", i, sch->hbBrokenTs, taskNum); - uint64_t qId, tId; + uint64_t qId, cId, tId; int32_t eId; SQWTaskStatus *pTask = NULL; void *pIter = taosHashIterate(sch->tasksHash, NULL); while (pIter) { pTask = (SQWTaskStatus *)pIter; void *key = taosHashGetKey(pIter, NULL); - QW_GET_QTID(key, qId, tId, eId); + QW_GET_QTID(key, qId, cId, tId, eId); QW_TASK_DLOG("job refId:%" PRIx64 ", code:%x, task status:%d", pTask->refId, pTask->code, pTask->status); @@ -118,13 +118,13 @@ void qwDbgDumpTasksInfo(SQWorker *mgmt) { int32_t i = 0; SQWTaskCtx *ctx = NULL; - uint64_t qId, tId; + uint64_t qId, cId, tId; int32_t eId; void *pIter = taosHashIterate(mgmt->ctxHash, NULL); while (pIter) { ctx = (SQWTaskCtx *)pIter; void *key = taosHashGetKey(pIter, NULL); - QW_GET_QTID(key, qId, tId, eId); + QW_GET_QTID(key, qId, cId, tId, eId); QW_TASK_DLOG("%p lock:%x, phase:%d, type:%d, explain:%d, needFetch:%d, localExec:%d, queryMsgType:%d, " "sId:%" PRId64 ", level:%d, queryGotData:%d, queryRsped:%d, queryEnd:%d, queryContinue:%d, queryInQueue:%d, " diff --git a/source/libs/qworker/src/qwMsg.c b/source/libs/qworker/src/qwMsg.c index 20b81bfc14..7dbad90cc0 100644 --- a/source/libs/qworker/src/qwMsg.c +++ b/source/libs/qworker/src/qwMsg.c @@ -233,6 +233,7 @@ int32_t qwBuildAndSendDropMsg(QW_FPARAMS_DEF, SRpcHandleInfo *pConn) { qMsg.header.contLen = 0; qMsg.sId = sId; qMsg.queryId = qId; + qMsg.clientId = cId; qMsg.taskId = tId; qMsg.refId = rId; qMsg.execId = eId; @@ -284,6 +285,7 @@ int32_t qwBuildAndSendCQueryMsg(QW_FPARAMS_DEF, SRpcHandleInfo *pConn) { req->header.vgId = mgmt->nodeId; req->sId = sId; req->queryId = qId; + req->clientId = cId; req->taskId = tId; req->execId = eId; @@ -312,6 +314,7 @@ int32_t qwRegisterQueryBrokenLinkArg(QW_FPARAMS_DEF, SRpcHandleInfo *pConn) { qMsg.header.contLen = 0; qMsg.sId = sId; qMsg.queryId = qId; + qMsg.clientId = cId; qMsg.taskId = tId; qMsg.refId = rId; qMsg.execId = eId; @@ -416,6 +419,7 @@ int32_t qWorkerPreprocessQueryMsg(void *qWorkerMgmt, SRpcMsg *pMsg, bool chkGran uint64_t sId = msg.sId; uint64_t qId = msg.queryId; + uint64_t cId = msg.clientId; uint64_t tId = msg.taskId; int64_t rId = msg.refId; int32_t eId = msg.execId; @@ -447,6 +451,7 @@ int32_t qWorkerAbortPreprocessQueryMsg(void *qWorkerMgmt, SRpcMsg *pMsg) { uint64_t sId = msg.sId; uint64_t qId = msg.queryId; + uint64_t cId = msg.clientId; uint64_t tId = msg.taskId; int64_t rId = msg.refId; int32_t eId = msg.execId; @@ -479,6 +484,7 @@ int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int uint64_t sId = msg.sId; uint64_t qId = msg.queryId; + uint64_t cId = msg.clientId; uint64_t tId = msg.taskId; int64_t rId = msg.refId; int32_t eId = msg.execId; @@ -524,6 +530,7 @@ int32_t qWorkerProcessCQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, in uint64_t sId = msg->sId; uint64_t qId = msg->queryId; + uint64_t cId = msg->clientId; uint64_t tId = msg->taskId; int64_t rId = 0; int32_t eId = msg->execId; @@ -557,6 +564,7 @@ int32_t qWorkerProcessFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int uint64_t sId = req.sId; uint64_t qId = req.queryId; + uint64_t cId = req.clientId; uint64_t tId = req.taskId; int64_t rId = 0; int32_t eId = req.execId; @@ -604,12 +612,14 @@ int32_t qWorkerProcessCancelMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, in msg->sId = be64toh(msg->sId); msg->queryId = be64toh(msg->queryId); + msg->clientId = be64toh(msg->clientId); msg->taskId = be64toh(msg->taskId); msg->refId = be64toh(msg->refId); msg->execId = ntohl(msg->execId); uint64_t sId = msg->sId; uint64_t qId = msg->queryId; + uint64_t cId = msg->clientId; uint64_t tId = msg->taskId; int64_t rId = msg->refId; int32_t eId = msg->execId; @@ -646,6 +656,7 @@ int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int6 uint64_t sId = msg.sId; uint64_t qId = msg.queryId; + uint64_t cId = msg.clientId; uint64_t tId = msg.taskId; int64_t rId = msg.refId; int32_t eId = msg.execId; @@ -684,6 +695,7 @@ int32_t qWorkerProcessNotifyMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, in uint64_t sId = msg.sId; uint64_t qId = msg.queryId; + uint64_t cId = msg.clientId; uint64_t tId = msg.taskId; int64_t rId = msg.refId; int32_t eId = msg.execId; @@ -753,6 +765,7 @@ int32_t qWorkerProcessDeleteMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SD uint64_t sId = req.sId; uint64_t qId = req.queryId; + uint64_t cId = req.clientId; uint64_t tId = req.taskId; int64_t rId = 0; int32_t eId = -1; diff --git a/source/libs/qworker/src/qwUtil.c b/source/libs/qworker/src/qwUtil.c index ef07a42629..917579deb0 100644 --- a/source/libs/qworker/src/qwUtil.c +++ b/source/libs/qworker/src/qwUtil.c @@ -137,8 +137,8 @@ int32_t qwAcquireScheduler(SQWorker *mgmt, uint64_t sId, int32_t rwType, SQWSchS void qwReleaseScheduler(int32_t rwType, SQWorker *mgmt) { QW_UNLOCK(rwType, &mgmt->schLock); } int32_t qwAcquireTaskStatus(QW_FPARAMS_DEF, int32_t rwType, SQWSchStatus *sch, SQWTaskStatus **task) { - char id[sizeof(qId) + sizeof(tId) + sizeof(eId)] = {0}; - QW_SET_QTID(id, qId, tId, eId); + char id[sizeof(qId) + sizeof(cId) + sizeof(tId) + sizeof(eId)] = {0}; + QW_SET_QTID(id, qId, cId, tId, eId); QW_LOCK(rwType, &sch->tasksLock); *task = taosHashGet(sch->tasksHash, id, sizeof(id)); @@ -153,8 +153,8 @@ int32_t qwAcquireTaskStatus(QW_FPARAMS_DEF, int32_t rwType, SQWSchStatus *sch, S int32_t qwAddTaskStatusImpl(QW_FPARAMS_DEF, SQWSchStatus *sch, int32_t rwType, int32_t status, SQWTaskStatus **task) { int32_t code = 0; - char id[sizeof(qId) + sizeof(tId) + sizeof(eId)] = {0}; - QW_SET_QTID(id, qId, tId, eId); + char id[sizeof(qId) + sizeof(cId) + sizeof(tId) + sizeof(eId)] = {0}; + QW_SET_QTID(id, qId, cId, tId, eId); SQWTaskStatus ntask = {0}; ntask.status = status; @@ -209,8 +209,8 @@ int32_t qwAddAcquireTaskStatus(QW_FPARAMS_DEF, int32_t rwType, SQWSchStatus *sch void qwReleaseTaskStatus(int32_t rwType, SQWSchStatus *sch) { QW_UNLOCK(rwType, &sch->tasksLock); } int32_t qwAcquireTaskCtx(QW_FPARAMS_DEF, SQWTaskCtx **ctx) { - char id[sizeof(qId) + sizeof(tId) + sizeof(eId)] = {0}; - QW_SET_QTID(id, qId, tId, eId); + char id[sizeof(qId) + sizeof(cId) + sizeof(tId) + sizeof(eId)] = {0}; + QW_SET_QTID(id, qId, cId, tId, eId); *ctx = taosHashAcquire(mgmt->ctxHash, id, sizeof(id)); if (NULL == (*ctx)) { @@ -222,8 +222,8 @@ int32_t qwAcquireTaskCtx(QW_FPARAMS_DEF, SQWTaskCtx **ctx) { } int32_t qwGetTaskCtx(QW_FPARAMS_DEF, SQWTaskCtx **ctx) { - char id[sizeof(qId) + sizeof(tId) + sizeof(eId)] = {0}; - QW_SET_QTID(id, qId, tId, eId); + char id[sizeof(qId) + sizeof(cId) + sizeof(tId) + sizeof(eId)] = {0}; + QW_SET_QTID(id, qId, cId, tId, eId); *ctx = taosHashGet(mgmt->ctxHash, id, sizeof(id)); if (NULL == (*ctx)) { @@ -235,8 +235,8 @@ int32_t qwGetTaskCtx(QW_FPARAMS_DEF, SQWTaskCtx **ctx) { } int32_t qwAddTaskCtxImpl(QW_FPARAMS_DEF, bool acquire, SQWTaskCtx **ctx) { - char id[sizeof(qId) + sizeof(tId) + sizeof(eId)] = {0}; - QW_SET_QTID(id, qId, tId, eId); + char id[sizeof(qId) + sizeof(cId) + sizeof(tId) + sizeof(eId)] = {0}; + QW_SET_QTID(id, qId, cId, tId, eId); SQWTaskCtx nctx = {0}; @@ -347,6 +347,7 @@ int32_t qwSendExplainResponse(QW_FPARAMS_DEF, SQWTaskCtx *ctx) { (void)memcpy(pExec, taosArrayGet(execInfoList, 0), localRsp.rsp.numOfPlans * sizeof(SExplainExecInfo)); localRsp.rsp.subplanInfo = pExec; localRsp.qId = qId; + localRsp.cId = cId; localRsp.tId = tId; localRsp.rId = rId; localRsp.eId = eId; @@ -376,8 +377,8 @@ _return: int32_t qwDropTaskCtx(QW_FPARAMS_DEF) { - char id[sizeof(qId) + sizeof(tId) + sizeof(eId)] = {0}; - QW_SET_QTID(id, qId, tId, eId); + char id[sizeof(qId) + sizeof(cId) + sizeof(tId) + sizeof(eId)] = {0}; + QW_SET_QTID(id, qId, cId, tId, eId); SQWTaskCtx octx; SQWTaskCtx *ctx = taosHashGet(mgmt->ctxHash, id, sizeof(id)); @@ -411,8 +412,8 @@ int32_t qwDropTaskStatus(QW_FPARAMS_DEF) { SQWTaskStatus *task = NULL; int32_t code = 0; - char id[sizeof(qId) + sizeof(tId) + sizeof(eId)] = {0}; - QW_SET_QTID(id, qId, tId, eId); + char id[sizeof(qId) + sizeof(cId) + sizeof(tId) + sizeof(eId)] = {0}; + QW_SET_QTID(id, qId, cId, tId, eId); if (qwAcquireScheduler(mgmt, sId, QW_WRITE, &sch)) { QW_TASK_WLOG_E("scheduler does not exist"); @@ -465,8 +466,8 @@ _return: int32_t qwHandleDynamicTaskEnd(QW_FPARAMS_DEF) { - char id[sizeof(qId) + sizeof(tId) + sizeof(eId)] = {0}; - QW_SET_QTID(id, qId, tId, eId); + char id[sizeof(qId) + sizeof(cId) + sizeof(tId) + sizeof(eId)] = {0}; + QW_SET_QTID(id, qId, cId, tId, eId); SQWTaskCtx octx; SQWTaskCtx *ctx = taosHashGet(mgmt->ctxHash, id, sizeof(id)); @@ -588,14 +589,14 @@ void qwDestroyImpl(void *pMgmt) { mgmt->hbTimer = NULL; taosTmrCleanUp(mgmt->timer); - uint64_t qId, tId; + uint64_t qId, cId, tId; int32_t eId; void *pIter = taosHashIterate(mgmt->ctxHash, NULL); while (pIter) { SQWTaskCtx *ctx = (SQWTaskCtx *)pIter; void *key = taosHashGetKey(pIter, NULL); - QW_GET_QTID(key, qId, tId, eId); + QW_GET_QTID(key, qId, cId, tId, eId); qwFreeTaskCtx(ctx); QW_TASK_DLOG_E("task ctx freed"); diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index 9b96c1e519..13e1d0e231 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -19,7 +19,7 @@ SQWorkerMgmt gQwMgmt = { }; void qwStopAllTasks(SQWorker *mgmt) { - uint64_t qId, tId, sId; + uint64_t qId, cId, tId, sId; int32_t eId; int64_t rId = 0; int32_t code = TSDB_CODE_SUCCESS; @@ -28,7 +28,7 @@ void qwStopAllTasks(SQWorker *mgmt) { while (pIter) { SQWTaskCtx *ctx = (SQWTaskCtx *)pIter; void *key = taosHashGetKey(pIter, NULL); - QW_GET_QTID(key, qId, tId, eId); + QW_GET_QTID(key, qId, cId, tId, eId); QW_LOCK(QW_WRITE, &ctx->lock); @@ -288,7 +288,7 @@ int32_t qwGenerateSchHbRsp(SQWorker *mgmt, SQWSchStatus *sch, SQWHbInfo *hbInfo) // TODO GET EXECUTOR API TO GET MORE INFO - QW_GET_QTID(key, status.queryId, status.taskId, status.execId); + QW_GET_QTID(key, status.queryId, status.clientId, status.taskId, status.execId); status.status = taskStatus->status; status.refId = taskStatus->refId; @@ -1473,8 +1473,8 @@ int32_t qWorkerGetStat(SReadHandle *handle, void *qWorkerMgmt, SQWorkerStat *pSt return TSDB_CODE_SUCCESS; } -int32_t qWorkerProcessLocalQuery(void *pMgmt, uint64_t sId, uint64_t qId, uint64_t tId, int64_t rId, int32_t eId, - SQWMsg *qwMsg, SArray *explainRes) { +int32_t qWorkerProcessLocalQuery(void *pMgmt, uint64_t sId, uint64_t qId, uint64_t cId, uint64_t tId, int64_t rId, + int32_t eId, SQWMsg *qwMsg, SArray *explainRes) { SQWorker *mgmt = (SQWorker *)pMgmt; int32_t code = 0; SQWTaskCtx *ctx = NULL; @@ -1538,8 +1538,8 @@ _return: QW_RET(code); } -int32_t qWorkerProcessLocalFetch(void *pMgmt, uint64_t sId, uint64_t qId, uint64_t tId, int64_t rId, int32_t eId, - void **pRsp, SArray *explainRes) { +int32_t qWorkerProcessLocalFetch(void *pMgmt, uint64_t sId, uint64_t qId, uint64_t cId, uint64_t tId, int64_t rId, + int32_t eId, void **pRsp, SArray *explainRes) { SQWorker *mgmt = (SQWorker *)pMgmt; int32_t code = 0; int32_t dataLen = 0; diff --git a/source/libs/scheduler/inc/schInt.h b/source/libs/scheduler/inc/schInt.h index 96b9d2da8d..6a910453f0 100644 --- a/source/libs/scheduler/inc/schInt.h +++ b/source/libs/scheduler/inc/schInt.h @@ -142,8 +142,9 @@ typedef struct SSchedulerCfg { } SSchedulerCfg; typedef struct SSchedulerMgmt { - uint64_t taskId; // sequential taksId - uint64_t sId; // schedulerId + uint64_t clientId; // unique clientId + uint64_t taskId; // sequential taksId + uint64_t sId; // schedulerId SSchedulerCfg cfg; bool exit; int32_t jobRef; @@ -163,6 +164,7 @@ typedef struct SSchTaskCallbackParam { SSchCallbackParamHeader head; uint64_t queryId; int64_t refId; + uint64_t clientId; uint64_t taskId; int32_t execId; void *pTrans; @@ -222,6 +224,7 @@ typedef struct SSchTimerParam { } SSchTimerParam; typedef struct SSchTask { + uint64_t clientId; // current client id uint64_t taskId; // task id SRWLatch lock; // task reentrant lock int32_t maxExecTimes; // task max exec times @@ -329,6 +332,7 @@ extern SSchedulerMgmt schMgmt; #define SCH_LOCK_TASK(_task) SCH_LOCK(SCH_WRITE, &(_task)->lock) #define SCH_UNLOCK_TASK(_task) SCH_UNLOCK(SCH_WRITE, &(_task)->lock) +#define SCH_CLIENT_ID(_task) ((_task) ? (_task)->clientId : -1) #define SCH_TASK_ID(_task) ((_task) ? (_task)->taskId : -1) #define SCH_TASK_EID(_task) ((_task) ? (_task)->execId : -1) @@ -449,21 +453,21 @@ extern SSchedulerMgmt schMgmt; #define SCH_JOB_ELOG(param, ...) qError("qid:0x%" PRIx64 " " param, pJob->queryId, __VA_ARGS__) #define SCH_JOB_DLOG(param, ...) qDebug("qid:0x%" PRIx64 " " param, pJob->queryId, __VA_ARGS__) -#define SCH_TASK_ELOG(param, ...) \ - qError("qid:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_TASK_ID(pTask), SCH_TASK_EID(pTask), \ - __VA_ARGS__) -#define SCH_TASK_DLOG(param, ...) \ - qDebug("qid:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_TASK_ID(pTask), SCH_TASK_EID(pTask), \ - __VA_ARGS__) -#define SCH_TASK_TLOG(param, ...) \ - qTrace("qid:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_TASK_ID(pTask), SCH_TASK_EID(pTask), \ - __VA_ARGS__) -#define SCH_TASK_DLOGL(param, ...) \ - qDebugL("qid:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_TASK_ID(pTask), SCH_TASK_EID(pTask), \ - __VA_ARGS__) -#define SCH_TASK_WLOG(param, ...) \ - qWarn("qid:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_TASK_ID(pTask), SCH_TASK_EID(pTask), \ - __VA_ARGS__) +#define SCH_TASK_ELOG(param, ...) \ + qError("qid:0x%" PRIx64 ",CID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_CLIENT_ID(pTask), \ + SCH_TASK_ID(pTask), SCH_TASK_EID(pTask), __VA_ARGS__) +#define SCH_TASK_DLOG(param, ...) \ + qDebug("qid:0x%" PRIx64 ",CID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_CLIENT_ID(pTask), \ + SCH_TASK_ID(pTask), SCH_TASK_EID(pTask), __VA_ARGS__) +#define SCH_TASK_TLOG(param, ...) \ + qTrace("qid:0x%" PRIx64 ",CID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_CLIENT_ID(pTask), \ + SCH_TASK_ID(pTask), SCH_TASK_EID(pTask), __VA_ARGS__) +#define SCH_TASK_DLOGL(param, ...) \ + qDebugL("qid:0x%" PRIx64 ",CID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_CLIENT_ID(pTask), \ + SCH_TASK_ID(pTask), SCH_TASK_EID(pTask), __VA_ARGS__) +#define SCH_TASK_WLOG(param, ...) \ + qWarn("qid:0x%" PRIx64 ",CID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_CLIENT_ID(pTask), \ + SCH_TASK_ID(pTask), SCH_TASK_EID(pTask), __VA_ARGS__) #define SCH_SET_ERRNO(_err) \ do { \ diff --git a/source/libs/scheduler/src/schRemote.c b/source/libs/scheduler/src/schRemote.c index b15a6a09d3..eefb32f783 100644 --- a/source/libs/scheduler/src/schRemote.c +++ b/source/libs/scheduler/src/schRemote.c @@ -500,8 +500,8 @@ _return: int32_t schHandleDropCallback(void *param, SDataBuf *pMsg, int32_t code) { SSchTaskCallbackParam *pParam = (SSchTaskCallbackParam *)param; - qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 " drop task rsp received, code:0x%x", pParam->queryId, pParam->taskId, - code); + qDebug("QID:0x%" PRIx64 ",CID:0x%" PRIx64 ",TID:0x%" PRIx64 " drop task rsp received, code:0x%x", pParam->queryId, + pParam->clientId, pParam->taskId, code); // called if drop task rsp received code (void)rpcReleaseHandle(pMsg->handle, TAOS_CONN_CLIENT); // ignore error @@ -517,8 +517,8 @@ int32_t schHandleDropCallback(void *param, SDataBuf *pMsg, int32_t code) { int32_t schHandleNotifyCallback(void *param, SDataBuf *pMsg, int32_t code) { SSchTaskCallbackParam *pParam = (SSchTaskCallbackParam *)param; - qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 " task notify rsp received, code:0x%x", pParam->queryId, pParam->taskId, - code); + qDebug("QID:0x%" PRIx64 ",CID:0x%" PRIx64 ",TID:0x%" PRIx64 " task notify rsp received, code:0x%x", pParam->queryId, + pParam->clientId, pParam->taskId, code); if (pMsg) { taosMemoryFree(pMsg->pData); taosMemoryFree(pMsg->pEpSet); @@ -595,6 +595,7 @@ int32_t schMakeCallbackParam(SSchJob *pJob, SSchTask *pTask, int32_t msgType, bo param->queryId = pJob->queryId; param->refId = pJob->refId; + param->clientId = SCH_CLIENT_ID(pTask); param->taskId = SCH_TASK_ID(pTask); param->pTrans = pJob->conn.pTrans; param->execId = pTask->execId; @@ -1138,6 +1139,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, req.header.vgId = addr->nodeId; req.sId = schMgmt.sId; req.queryId = pJob->queryId; + req.clientId = pTask->clientId; req.taskId = pTask->taskId; req.phyLen = pTask->msgLen; req.sqlLen = strlen(pJob->sql); @@ -1171,6 +1173,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, qMsg.header.contLen = 0; qMsg.sId = schMgmt.sId; qMsg.queryId = pJob->queryId; + qMsg.clientId = pTask->clientId; qMsg.taskId = pTask->taskId; qMsg.refId = pJob->refId; qMsg.execId = pTask->execId; @@ -1226,6 +1229,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, req.header.vgId = addr->nodeId; req.sId = schMgmt.sId; req.queryId = pJob->queryId; + req.clientId = pTask->clientId; req.taskId = pTask->taskId; req.execId = pTask->execId; @@ -1253,6 +1257,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, qMsg.header.contLen = 0; qMsg.sId = schMgmt.sId; qMsg.queryId = pJob->queryId; + qMsg.clientId = pTask->clientId; qMsg.taskId = pTask->taskId; qMsg.refId = pJob->refId; qMsg.execId = *(int32_t*)param; @@ -1310,6 +1315,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, qMsg.header.contLen = 0; qMsg.sId = schMgmt.sId; qMsg.queryId = pJob->queryId; + qMsg.clientId = pTask->clientId; qMsg.taskId = pTask->taskId; qMsg.refId = pJob->refId; qMsg.execId = pTask->execId; diff --git a/source/libs/scheduler/src/schTask.c b/source/libs/scheduler/src/schTask.c index fe24633c12..9be0e3fc40 100644 --- a/source/libs/scheduler/src/schTask.c +++ b/source/libs/scheduler/src/schTask.c @@ -66,6 +66,7 @@ int32_t schInitTask(SSchJob *pJob, SSchTask *pTask, SSubplan *pPlan, SSchLevel * pTask->execId = -1; pTask->failedExecId = -2; pTask->timeoutUsec = SCH_DEFAULT_TASK_TIMEOUT_USEC; + pTask->clientId = getClientId(); pTask->taskId = schGenTaskId(); schInitTaskRetryTimes(pJob, pTask, pLevel); @@ -305,6 +306,7 @@ int32_t schProcessOnTaskSuccess(SSchJob *pJob, SSchTask *pTask) { SCH_LOCK(SCH_WRITE, &parent->planLock); SDownstreamSourceNode source = { .type = QUERY_NODE_DOWNSTREAM_SOURCE, + .clientId = pTask->clientId, .taskId = pTask->taskId, .schedId = schMgmt.sId, .execId = pTask->execId, @@ -996,8 +998,8 @@ int32_t schProcessOnTaskStatusRsp(SQueryNodeEpId *pEpId, SArray *pStatusList) { int32_t code = 0; - qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d task status in server: %s", pStatus->queryId, pStatus->taskId, - pStatus->execId, jobTaskStatusStr(pStatus->status)); + qDebug("QID:0x%" PRIx64 ",CID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d task status in server: %s", pStatus->queryId, + pStatus->clientId, pStatus->taskId, pStatus->execId, jobTaskStatusStr(pStatus->status)); if (schProcessOnCbBegin(&pJob, &pTask, pStatus->queryId, pStatus->refId, pStatus->taskId)) { continue; @@ -1043,13 +1045,14 @@ int32_t schHandleExplainRes(SArray *pExplainRes) { continue; } - qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ", begin to handle LOCAL explain rsp msg", localRsp->qId, localRsp->tId); + qDebug("QID:0x%" PRIx64 ",CID:0x%" PRIx64 ",TID:0x%" PRIx64 ", begin to handle LOCAL explain rsp msg", + localRsp->qId, localRsp->cId, localRsp->tId); pJob = NULL; (void)schAcquireJob(localRsp->rId, &pJob); if (NULL == pJob) { - qWarn("QID:0x%" PRIx64 ",TID:0x%" PRIx64 "job no exist, may be dropped, refId:0x%" PRIx64, localRsp->qId, - localRsp->tId, localRsp->rId); + qWarn("QID:0x%" PRIx64 ",CID:0x%" PRIx64 ",TID:0x%" PRIx64 "job no exist, may be dropped, refId:0x%" PRIx64, + localRsp->qId, localRsp->cId, localRsp->tId, localRsp->rId); SCH_ERR_JRET(TSDB_CODE_QRY_JOB_NOT_EXIST); } @@ -1068,8 +1071,8 @@ int32_t schHandleExplainRes(SArray *pExplainRes) { (void)schReleaseJob(pJob->refId); - qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ", end to handle LOCAL explain rsp msg, code:%x", localRsp->qId, - localRsp->tId, code); + qDebug("QID:0x%" PRIx64 ",CID:0x%" PRIx64 ",TID:0x%" PRIx64 ", end to handle LOCAL explain rsp msg, code:%x", + localRsp->qId, localRsp->cId, localRsp->tId, code); SCH_ERR_JRET(code); @@ -1147,8 +1150,8 @@ int32_t schLaunchLocalTask(SSchJob *pJob, SSchTask *pTask) { } } - SCH_ERR_JRET(qWorkerProcessLocalQuery(schMgmt.queryMgmt, schMgmt.sId, pJob->queryId, pTask->taskId, pJob->refId, - pTask->execId, &qwMsg, explainRes)); + SCH_ERR_JRET(qWorkerProcessLocalQuery(schMgmt.queryMgmt, schMgmt.sId, pJob->queryId, pTask->clientId, pTask->taskId, + pJob->refId, pTask->execId, &qwMsg, explainRes)); if (SCH_IS_EXPLAIN_JOB(pJob)) { SCH_ERR_RET(schHandleExplainRes(explainRes)); @@ -1407,8 +1410,8 @@ int32_t schExecLocalFetch(SSchJob *pJob, SSchTask *pTask) { } } - SCH_ERR_JRET(qWorkerProcessLocalFetch(schMgmt.queryMgmt, schMgmt.sId, pJob->queryId, pTask->taskId, pJob->refId, - pTask->execId, &pRsp, explainRes)); + SCH_ERR_JRET(qWorkerProcessLocalFetch(schMgmt.queryMgmt, schMgmt.sId, pJob->queryId, pTask->clientId, pTask->taskId, + pJob->refId, pTask->execId, &pRsp, explainRes)); if (SCH_IS_EXPLAIN_JOB(pJob)) { SCH_ERR_RET(schHandleExplainRes(explainRes)); diff --git a/source/libs/scheduler/src/schUtil.c b/source/libs/scheduler/src/schUtil.c index 4697de6f28..ac34099417 100644 --- a/source/libs/scheduler/src/schUtil.c +++ b/source/libs/scheduler/src/schUtil.c @@ -293,6 +293,18 @@ void schCloseJobRef(void) { } } +int32_t initClientId(void) { + int32_t code = taosGetSystemUUIDU64(&schMgmt.clientId); + if (code != TSDB_CODE_SUCCESS) { + qError("failed to generate clientId since %s", tstrerror(code)); + SCH_ERR_RET(code); + } + qInfo("initialize"); + return TSDB_CODE_SUCCESS; +} + +uint64_t getClientId(void) { return schMgmt.clientId; } + uint64_t schGenTaskId(void) { return atomic_add_fetch_64(&schMgmt.taskId, 1); } #ifdef BUILD_NO_CALL diff --git a/source/libs/sync/inc/syncSnapshot.h b/source/libs/sync/inc/syncSnapshot.h index 540255c200..839b87d500 100644 --- a/source/libs/sync/inc/syncSnapshot.h +++ b/source/libs/sync/inc/syncSnapshot.h @@ -91,6 +91,7 @@ typedef struct SSyncSnapshotReceiver { // update when begin void *pWriter; + TdThreadMutex writerMutex; SSnapshotParam snapshotParam; SSnapshot snapshot; diff --git a/source/libs/sync/src/syncSnapshot.c b/source/libs/sync/src/syncSnapshot.c index 78fda6b093..a89667ad3d 100644 --- a/source/libs/sync/src/syncSnapshot.c +++ b/source/libs/sync/src/syncSnapshot.c @@ -429,6 +429,12 @@ int32_t snapshotReceiverCreate(SSyncNode *pSyncNode, SRaftId fromId, SSyncSnapsh pReceiver->startTime = 0; pReceiver->ack = SYNC_SNAPSHOT_SEQ_BEGIN; pReceiver->pWriter = NULL; + code = taosThreadMutexInit(&pReceiver->writerMutex, NULL); + if (code != 0) { + taosMemoryFree(pReceiver); + pReceiver = NULL; + TAOS_RETURN(code); + } pReceiver->pSyncNode = pSyncNode; pReceiver->fromId = fromId; pReceiver->term = raftStoreGetTerm(pSyncNode); @@ -440,6 +446,10 @@ int32_t snapshotReceiverCreate(SSyncNode *pSyncNode, SRaftId fromId, SSyncSnapsh SSyncSnapBuffer *pRcvBuf = NULL; code = syncSnapBufferCreate(&pRcvBuf); if (pRcvBuf == NULL) { + int32_t ret = taosThreadMutexDestroy(&pReceiver->writerMutex); + if (ret != 0) { + sError("failed to destroy mutex since %s", tstrerror(ret)); + } taosMemoryFree(pReceiver); pReceiver = NULL; TAOS_RETURN(code); @@ -468,6 +478,7 @@ static int32_t snapshotReceiverClearInfoData(SSyncSnapshotReceiver *pReceiver) { void snapshotReceiverDestroy(SSyncSnapshotReceiver *pReceiver) { if (pReceiver == NULL) return; + (void)taosThreadMutexLock(&pReceiver->writerMutex); // close writer if (pReceiver->pWriter != NULL) { int32_t code = pReceiver->pSyncNode->pFsm->FpSnapshotStopWrite(pReceiver->pSyncNode->pFsm, pReceiver->pWriter, @@ -478,6 +489,9 @@ void snapshotReceiverDestroy(SSyncSnapshotReceiver *pReceiver) { } pReceiver->pWriter = NULL; } + (void)taosThreadMutexUnlock(&pReceiver->writerMutex); + + (void)taosThreadMutexDestroy(&pReceiver->writerMutex); // free snap buf if (pReceiver->pRcvBuf) { @@ -556,7 +570,8 @@ void snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver) { int8_t stopped = !atomic_val_compare_exchange_8(&pReceiver->start, true, false); if (stopped) return; - (void)taosThreadMutexLock(&pReceiver->pRcvBuf->mutex); + + (void)taosThreadMutexLock(&pReceiver->writerMutex); { if (pReceiver->pWriter != NULL) { int32_t code = pReceiver->pSyncNode->pFsm->FpSnapshotStopWrite(pReceiver->pSyncNode->pFsm, pReceiver->pWriter, @@ -568,7 +583,11 @@ void snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver) { } else { sRInfo(pReceiver, "snapshot receiver stop, writer is null"); } + } + (void)taosThreadMutexUnlock(&pReceiver->writerMutex); + (void)taosThreadMutexLock(&pReceiver->pRcvBuf->mutex); + { syncSnapBufferReset(pReceiver->pRcvBuf); (void)snapshotReceiverClearInfoData(pReceiver); @@ -600,15 +619,19 @@ static int32_t snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnap raftStoreSetTerm(pReceiver->pSyncNode, pReceiver->snapshot.lastApplyTerm); } - // stop writer, apply data - code = pReceiver->pSyncNode->pFsm->FpSnapshotStopWrite(pReceiver->pSyncNode->pFsm, pReceiver->pWriter, true, - &pReceiver->snapshot); - if (code != 0) { - sRError(pReceiver, "snapshot receiver apply failed since %s", tstrerror(code)); - TAOS_RETURN(code); + (void)taosThreadMutexLock(&pReceiver->writerMutex); + if (pReceiver->pWriter != NULL) { + // stop writer, apply data + code = pReceiver->pSyncNode->pFsm->FpSnapshotStopWrite(pReceiver->pSyncNode->pFsm, pReceiver->pWriter, true, + &pReceiver->snapshot); + if (code != 0) { + sRError(pReceiver, "snapshot receiver apply failed since %s", tstrerror(code)); + TAOS_RETURN(code); + } + pReceiver->pWriter = NULL; + sRInfo(pReceiver, "snapshot receiver write stopped"); } - pReceiver->pWriter = NULL; - sRInfo(pReceiver, "snapshot receiver write stopped"); + (void)taosThreadMutexUnlock(&pReceiver->writerMutex); // update progress pReceiver->ack = SYNC_SNAPSHOT_SEQ_END; diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 2aeffc6395..c03d3418fa 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -254,6 +254,7 @@ static FORCE_INLINE void cliMayUpdateFqdnCache(SHashObj* cache, char* dst); // process data read from server, add decompress etc later // handle except about conn +#define REQS_ON_CONN(conn) (conn ? (transQueueSize(&conn->reqsToSend) + transQueueSize(&conn->reqsSentOut)) : 0) static void doNotifyCb(SCliReq* pReq, SCliThrd* pThrd, int32_t code); // handle req from app static void cliHandleReq(SCliThrd* pThrd, SCliReq* pReq); @@ -289,7 +290,7 @@ int32_t cliMayGetStateByQid(SCliThrd* pThrd, SCliReq* pReq, SCliConn** pConn); static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key); static int32_t addConnToHeapCache(SHashObj* pConnHeapCacahe, SCliConn* pConn); static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn); -static int32_t balanceConnHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn); +static int8_t balanceConnHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn, SCliConn** pNewConn); // thread obj static int32_t createThrdObj(void* trans, SCliThrd** pThrd); @@ -327,14 +328,18 @@ typedef struct { int64_t lastConnFailTs; } SHeap; -int32_t compareHeapNode(const HeapNode* a, const HeapNode* b); -int32_t transHeapInit(SHeap* heap, int32_t (*cmpFunc)(const HeapNode* a, const HeapNode* b)); -void transHeapDestroy(SHeap* heap); -int32_t transHeapGet(SHeap* heap, SCliConn** p); -int32_t transHeapInsert(SHeap* heap, SCliConn* p); -int32_t transHeapDelete(SHeap* heap, SCliConn* p); -int32_t transHeapBalance(SHeap* heap, SCliConn* p); -int32_t transHeapUpdateFailTs(SHeap* heap, SCliConn* p); +static int32_t compareHeapNode(const HeapNode* a, const HeapNode* b); +static int32_t transHeapInit(SHeap* heap, int32_t (*cmpFunc)(const HeapNode* a, const HeapNode* b)); +static void transHeapDestroy(SHeap* heap); + +static int32_t transHeapGet(SHeap* heap, SCliConn** p); +static int32_t transHeapInsert(SHeap* heap, SCliConn* p); +static int32_t transHeapDelete(SHeap* heap, SCliConn* p); +static int32_t transHeapBalance(SHeap* heap, SCliConn* p); +static int32_t transHeapUpdateFailTs(SHeap* heap, SCliConn* p); +static int32_t transHeapMayBalance(SHeap* heap, SCliConn* p); + +static FORCE_INLINE void logConnMissHit(SCliConn* pConn); #define CLI_RELEASE_UV(loop) \ do { \ @@ -494,15 +499,19 @@ int8_t cliMayRecycleConn(SCliConn* conn) { if (transQueueSize(&conn->reqsToSend) == 0 && transQueueSize(&conn->reqsSentOut) == 0 && taosHashGetSize(conn->pQTable) == 0) { cliResetConnTimer(conn); + conn->forceDelFromHeap = 1; code = delConnFromHeapCache(pThrd->connHeapCache, conn); if (code == TSDB_CODE_RPC_ASYNC_IN_PROCESS) { tDebug("%s conn %p failed to remove conn from heap cache since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); + + TAOS_UNUSED(transHeapMayBalance(conn->heap, conn)); return 1; } else { if (code != 0) { tDebug("%s conn %p failed to remove conn from heap cache since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); + return 0; } } addConnToPool(pThrd->pool, conn); @@ -510,31 +519,10 @@ int8_t cliMayRecycleConn(SCliConn* conn) { } else if ((transQueueSize(&conn->reqsToSend) == 0) && (transQueueSize(&conn->reqsSentOut) == 0) && (taosHashGetSize(conn->pQTable) != 0)) { tDebug("%s conn %p do balance directly", CONN_GET_INST_LABEL(conn), conn); - TAOS_UNUSED(transHeapBalance(conn->heap, conn)); + TAOS_UNUSED(transHeapMayBalance(conn->heap, conn)); } else { - SCliConn* topConn = NULL; - if (conn->heap != NULL) { - code = transHeapGet(conn->heap, &topConn); - if (code != 0) { - tDebug("%s conn %p failed to get top conn since %s", CONN_GET_INST_LABEL(conn), conn, tstrerror(code)); - return 0; - } - - if (topConn == conn) { - return 0; - } - int32_t topReqs = transQueueSize(&topConn->reqsSentOut) + transQueueSize(&topConn->reqsToSend); - int32_t currReqs = transQueueSize(&conn->reqsSentOut) + transQueueSize(&conn->reqsToSend); - if (topReqs <= currReqs) { - tTrace("%s conn %p not balance conn heap since top conn has less req, topConnReqs:%d, currConnReqs:%d", - CONN_GET_INST_LABEL(conn), conn, topReqs, currReqs); - return 0; - } else { - tDebug("%s conn %p do balance conn heap since top conn has more reqs, topConnReqs:%d, currConnReqs:%d", - CONN_GET_INST_LABEL(conn), conn, topReqs, currReqs); - TAOS_UNUSED(transHeapBalance(conn->heap, conn)); - } - } + tTrace("%s conn %p may do balance", CONN_GET_INST_LABEL(conn), conn); + TAOS_UNUSED(transHeapMayBalance(conn->heap, conn)); } return 0; } @@ -785,15 +773,8 @@ void cliConnCheckTimoutMsg(SCliConn* conn) { if (transQueueSize(&conn->reqsSentOut) == 0) { return; } - code = cliConnRemoveTimeoutMsg(conn); - if (code != 0) { - tDebug("%s conn %p do remove timeout msg", CONN_GET_INST_LABEL(conn), conn); - if (!cliMayRecycleConn(conn)) { - TAOS_UNUSED(transHeapBalance(conn->heap, conn)); - } - } else { - TAOS_UNUSED(cliMayRecycleConn(conn)); - } + TAOS_UNUSED(cliConnRemoveTimeoutMsg(conn)); + TAOS_UNUSED(cliMayRecycleConn(conn)); } void cliConnTimeout__checkReq(uv_timer_t* handle) { SCliConn* conn = handle->data; @@ -3804,6 +3785,8 @@ static FORCE_INLINE int8_t shouldSWitchToOtherConn(SCliConn* pConn, char* key) { int32_t totalReqs = reqsNum + reqsSentOut; if (totalReqs >= pInst->shareConnLimit) { + logConnMissHit(pConn); + if (pConn->list == NULL && pConn->dstAddr != NULL) { pConn->list = taosHashGet((SHashObj*)pThrd->pool, pConn->dstAddr, strlen(pConn->dstAddr)); if (pConn->list != NULL) { @@ -3860,11 +3843,12 @@ static SCliConn* getConnFromHeapCache(SHashObj* pConnHeapCache, char* key) { } else { tTrace("conn %p get conn from heap cache for key:%s", pConn, key); if (shouldSWitchToOtherConn(pConn, key)) { - code = balanceConnHeapCache(pConnHeapCache, pConn); - if (code != 0) { - tTrace("failed to balance conn heap cache for key:%s", key); + SCliConn* pNewConn = NULL; + code = balanceConnHeapCache(pConnHeapCache, pConn, &pNewConn); + if (code == 1) { + tTrace("conn %p start to handle reqs", pNewConn); + return pNewConn; } - logConnMissHit(pConn); return NULL; } } @@ -3916,15 +3900,19 @@ static int32_t delConnFromHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { return code; } -static int32_t balanceConnHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn) { +static int8_t balanceConnHeapCache(SHashObj* pConnHeapCache, SCliConn* pConn, SCliConn** pNewConn) { + SCliThrd* pThrd = pConn->hostThrd; + STrans* pInst = pThrd->pInst; + SCliConn* pTopConn = NULL; if (pConn->heap != NULL && pConn->inHeap != 0) { - SHeap* heap = pConn->heap; - tTrace("conn %p'heap may should do balance, numOfConn:%d", pConn, (int)(heap->heap->nelts)); - int64_t now = taosGetTimestampMs(); - if (((now - heap->lastUpdateTs) / 1000) > 30) { - heap->lastUpdateTs = now; - tTrace("conn %p'heap do balance, numOfConn:%d", pConn, (int)(heap->heap->nelts)); - return transHeapBalance(pConn->heap, pConn); + TAOS_UNUSED(transHeapBalance(pConn->heap, pConn)); + if (transHeapGet(pConn->heap, &pTopConn) == 0 && pConn != pTopConn) { + int32_t curReqs = REQS_ON_CONN(pConn); + int32_t topReqs = REQS_ON_CONN(pTopConn); + if (curReqs > topReqs && topReqs < pInst->shareConnLimit) { + *pNewConn = pTopConn; + return 1; + } } } return 0; @@ -3934,8 +3922,8 @@ int32_t compareHeapNode(const HeapNode* a, const HeapNode* b) { SCliConn* args1 = container_of(a, SCliConn, node); SCliConn* args2 = container_of(b, SCliConn, node); - int32_t totalReq1 = transQueueSize(&args1->reqsToSend) + transQueueSize(&args1->reqsSentOut); - int32_t totalReq2 = transQueueSize(&args2->reqsToSend) + transQueueSize(&args2->reqsSentOut); + int32_t totalReq1 = REQS_ON_CONN(args1); + int32_t totalReq2 = REQS_ON_CONN(args2); if (totalReq1 > totalReq2) { return 0; } @@ -4016,6 +4004,30 @@ int32_t transHeapUpdateFailTs(SHeap* heap, SCliConn* p) { heap->lastConnFailTs = taosGetTimestampMs(); return 0; } +int32_t transHeapMayBalance(SHeap* heap, SCliConn* p) { + if (p->inHeap == 0 || heap == NULL || heap->heap == NULL) { + return 0; + } + SCliThrd* pThrd = p->hostThrd; + STrans* pInst = pThrd->pInst; + int32_t balanceLimit = pInst->shareConnLimit >= 4 ? pInst->shareConnLimit / 2 : 2; + + SCliConn* topConn = NULL; + int32_t code = transHeapGet(heap, &topConn); + if (code != 0) { + return code; + } + + if (topConn == p) return code; + + int32_t reqsOnTop = REQS_ON_CONN(topConn); + int32_t reqsOnCur = REQS_ON_CONN(p); + + if (reqsOnTop >= balanceLimit && reqsOnCur < balanceLimit) { + TAOS_UNUSED(transHeapBalance(heap, p)); + } + return code; +} int32_t transHeapBalance(SHeap* heap, SCliConn* p) { if (p->inHeap == 0 || heap == NULL || heap->heap == NULL) { diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index 6d52c8d6cb..da26ddae3a 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -424,9 +424,6 @@ static void printFileSet(int32_t vgId, SArray* fileSet, const char* str) { int32_t walCheckAndRepairMeta(SWal* pWal) { // load log files, get first/snapshot/last version info - if (pWal->cfg.level == TAOS_WAL_SKIP) { - return TSDB_CODE_SUCCESS; - } int32_t code = 0; const char* logPattern = "^[0-9]+.log$"; const char* idxPattern = "^[0-9]+.idx$"; diff --git a/source/libs/wal/src/walMgmt.c b/source/libs/wal/src/walMgmt.c index d8a58efe4e..e2c5e66158 100644 --- a/source/libs/wal/src/walMgmt.c +++ b/source/libs/wal/src/walMgmt.c @@ -90,6 +90,45 @@ static int32_t walInitLock(SWal *pWal) { return 0; } +int32_t walInitWriteFileForSkip(SWal *pWal) { + TdFilePtr pIdxTFile = NULL, pLogTFile = NULL; + int64_t fileFirstVer = 0; + int32_t code = 0; + + char fnameStr[WAL_FILE_LEN]; + walBuildIdxName(pWal, fileFirstVer, fnameStr); + pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); + if (pIdxTFile == NULL) { + wError("vgId:%d, failed to open file since %s", pWal->cfg.vgId, tstrerror(terrno)); + code = terrno; + goto _exit; + } + walBuildLogName(pWal, fileFirstVer, fnameStr); + pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); + if (pLogTFile == NULL) { + wError("vgId:%d, failed to open file since %s", pWal->cfg.vgId, tstrerror(terrno)); + code = terrno; + goto _exit; + } + // switch file + pWal->pIdxFile = pIdxTFile; + pWal->pLogFile = pLogTFile; + SWalFileInfo fileInfo; + (void)memset(&fileInfo, -1, sizeof(SWalFileInfo)); + if (!taosArrayPush(pWal->fileInfoSet, &fileInfo)) { + wError("vgId:%d, failed to push fileInfo into array since %s", pWal->cfg.vgId, tstrerror(terrno)); + code = terrno; + goto _exit; + } + pWal->writeCur = 0; +_exit: + if (code != TSDB_CODE_SUCCESS) { + (void)taosCloseFile(&pIdxTFile); + (void)taosCloseFile(&pLogTFile); + } + TAOS_RETURN(code); +} + SWal *walOpen(const char *path, SWalCfg *pCfg) { int32_t code = 0; SWal *pWal = taosMemoryCalloc(1, sizeof(SWal)); @@ -165,17 +204,25 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) { if (code < 0) { wWarn("vgId:%d, failed to load meta since %s", pWal->cfg.vgId, tstrerror(code)); } + if (pWal->cfg.level != TAOS_WAL_SKIP) { + code = walCheckAndRepairMeta(pWal); + if (code < 0) { + wError("vgId:%d, cannot open wal since repair meta file failed since %s", pWal->cfg.vgId, tstrerror(code)); + goto _err; + } - code = walCheckAndRepairMeta(pWal); - if (code < 0) { - wError("vgId:%d, cannot open wal since repair meta file failed since %s", pWal->cfg.vgId, tstrerror(code)); - goto _err; - } - - code = walCheckAndRepairIdx(pWal); - if (code < 0) { - wError("vgId:%d, cannot open wal since repair idx file failed since %s", pWal->cfg.vgId, tstrerror(code)); - goto _err; + code = walCheckAndRepairIdx(pWal); + if (code < 0) { + wError("vgId:%d, cannot open wal since repair idx file failed since %s", pWal->cfg.vgId, tstrerror(code)); + goto _err; + } + } else { + code = walInitWriteFileForSkip(pWal); + if (code < 0) { + wError("vgId:%d, cannot open wal since init write file for wal_level = 0 failed since %s", pWal->cfg.vgId, + tstrerror(code)); + goto _err; + } } // add ref @@ -217,6 +264,14 @@ int32_t walAlter(SWal *pWal, SWalCfg *pCfg) { pWal->cfg.vgId, pWal->cfg.level, pWal->cfg.fsyncPeriod, pWal->cfg.retentionPeriod, pWal->cfg.retentionSize, pCfg->level, pCfg->fsyncPeriod, pCfg->retentionPeriod, pCfg->retentionSize); + if (pWal->cfg.level == TAOS_WAL_SKIP && pCfg->level != TAOS_WAL_SKIP) { + wInfo("vgId:%d, remove all wals, path:%s", pWal->cfg.vgId, pWal->path); + taosRemoveDir(pWal->path); + if (taosMkDir(pWal->path) != 0) { + wError("vgId:%d, path:%s, failed to create directory since %s", pWal->cfg.vgId, pWal->path, tstrerror(terrno)); + } + } + pWal->cfg.level = pCfg->level; pWal->cfg.fsyncPeriod = pCfg->fsyncPeriod; pWal->cfg.retentionPeriod = pCfg->retentionPeriod; diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index 84de563cda..777c6a9216 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -116,7 +116,10 @@ void taosRemoveDir(const char *dirname) { return; } -bool taosDirExist(const char *dirname) { return taosCheckExistFile(dirname); } +bool taosDirExist(const char *dirname) { + if (dirname == NULL || strlen(dirname) >= TDDIRMAXLEN) return false; + return taosCheckExistFile(dirname); +} int32_t taosMkDir(const char *dirname) { if (taosDirExist(dirname)) return 0; @@ -333,6 +336,8 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays) { } int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) { + OS_PARAM_CHECK(dirname); + OS_PARAM_CHECK(outname); wordexp_t full_path; int32_t code = wordexp(dirname, &full_path, 0); switch (code) { @@ -355,6 +360,8 @@ int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen) { } int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen) { + OS_PARAM_CHECK(dirname); + OS_PARAM_CHECK(realPath); char tmp[PATH_MAX] = {0}; #ifdef WINDOWS if (_fullpath(tmp, dirname, maxlen) != NULL) { @@ -386,6 +393,10 @@ bool taosIsDir(const char *dirname) { } char *taosDirName(char *name) { + if(name == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } #ifdef WINDOWS char Drive1[MAX_PATH], Dir1[MAX_PATH]; _splitpath(name, Drive1, Dir1, NULL, NULL); @@ -412,12 +423,16 @@ char *taosDirName(char *name) { } char *taosDirEntryBaseName(char *name) { + if(name == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } #ifdef WINDOWS char Filename1[MAX_PATH], Ext1[MAX_PATH]; _splitpath(name, NULL, NULL, Filename1, Ext1); return name + (strlen(name) - strlen(Filename1) - strlen(Ext1)); #else - if (name == NULL || (name[0] == '/' && name[1] == '\0')) return name; + if ((name[0] == '/' && name[1] == '\0')) return name; char *pPoint = strrchr(name, '/'); if (pPoint != NULL) { if (*(pPoint + 1) == '\0') { @@ -515,9 +530,9 @@ bool taosDirEntryIsDir(TdDirEntryPtr pDirEntry) { } char *taosGetDirEntryName(TdDirEntryPtr pDirEntry) { - /*if (pDirEntry == NULL) {*/ - /*return NULL;*/ - /*}*/ + if (pDirEntry == NULL) { + return NULL; + } #ifdef WINDOWS return pDirEntry->findFileData.cFileName; #else diff --git a/source/os/src/osEnv.c b/source/os/src/osEnv.c index 05c9936c2e..41b34a9030 100644 --- a/source/os/src/osEnv.c +++ b/source/os/src/osEnv.c @@ -127,8 +127,13 @@ bool osTempSpaceSufficient() { return tsTempSpace.size.avail > tsTempSpace.reser int32_t osSetTimezone(const char *tz) { return taosSetSystemTimezone(tz, tsTimezoneStr, &tsDaylight, &tsTimezone); } void osSetSystemLocale(const char *inLocale, const char *inCharSet) { - (void)memcpy(tsLocale, inLocale, strlen(inLocale) + 1); - (void)memcpy(tsCharset, inCharSet, strlen(inCharSet) + 1); + if (inLocale) (void)memcpy(tsLocale, inLocale, strlen(inLocale) + 1); + if (inCharSet) (void)memcpy(tsCharset, inCharSet, strlen(inCharSet) + 1); } -void osSetProcPath(int32_t argc, char **argv) { tsProcPath = argv[0]; } +void osSetProcPath(int32_t argc, char **argv) { + if (argv == NULL || argc < 1) { + return; // no command line arguments + } + tsProcPath = argv[0]; +} diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index 2f18c6e697..c2484860ad 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -80,6 +80,7 @@ typedef struct TdFile { #endif void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, char *dstPath) { + if (inputTmpDir == NULL || fileNamePrefix == NULL) return; #ifdef WINDOWS char tmpPath[PATH_MAX]; @@ -120,6 +121,10 @@ void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, cha } int64_t taosCopyFile(const char *from, const char *to) { + if (from == NULL || to == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return -1; + } #ifdef WINDOWS if (CopyFile(from, to, 0)) { return 1; @@ -133,15 +138,15 @@ int64_t taosCopyFile(const char *from, const char *to) { int64_t bytes; int32_t code = TSDB_CODE_SUCCESS; - // fidfrom = open(from, O_RDONLY); - TdFilePtr pFileFrom = taosOpenFile(from, TD_FILE_READ); + TdFilePtr pFileFrom = NULL; + TdFilePtr pFileTo = NULL; + pFileFrom = taosOpenFile(from, TD_FILE_READ); if (pFileFrom == NULL) { code = terrno; goto _err; } - // fidto = open(to, O_WRONLY | O_CREAT | O_EXCL, 0755); - TdFilePtr pFileTo = taosOpenFile(to, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_EXCL); + pFileTo = taosOpenFile(to, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_EXCL); if (pFileTo == NULL) { code = terrno; goto _err; @@ -193,6 +198,10 @@ _err: } TdFilePtr taosCreateFile(const char *path, int32_t tdFileOptions) { + if(path == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } TdFilePtr fp = taosOpenFile(path, tdFileOptions); if (!fp) { if (terrno == TAOS_SYSTEM_ERROR(ENOENT)) { @@ -213,6 +222,7 @@ TdFilePtr taosCreateFile(const char *path, int32_t tdFileOptions) { } int32_t taosRemoveFile(const char *path) { + OS_PARAM_CHECK(path); int32_t code = remove(path); if (-1 == code) { terrno = TAOS_SYSTEM_ERROR(errno); @@ -222,6 +232,8 @@ int32_t taosRemoveFile(const char *path) { } int32_t taosRenameFile(const char *oldName, const char *newName) { + OS_PARAM_CHECK(oldName); + OS_PARAM_CHECK(newName); #ifdef WINDOWS bool finished = false; @@ -262,6 +274,7 @@ int32_t taosRenameFile(const char *oldName, const char *newName) { } int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime, int32_t *atime) { + OS_PARAM_CHECK(path); #ifdef WINDOWS struct _stati64 fileStat; int32_t code = _stati64(path, &fileStat); @@ -335,6 +348,10 @@ int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno) { } FILE *taosOpenFileForStream(const char *path, int32_t tdFileOptions) { + if (path == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } char *mode = NULL; if (tdFileOptions & TD_FILE_APPEND) { mode = (tdFileOptions & TD_FILE_TEXT) ? "at+" : "ab+"; @@ -358,6 +375,10 @@ FILE *taosOpenFileForStream(const char *path, int32_t tdFileOptions) { #ifdef WINDOWS HANDLE taosOpenFileNotStream(const char *path, int32_t tdFileOptions) { + if (path == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return INVALID_HANDLE_VALUE; + } DWORD openMode = 0; DWORD access = 0; DWORD fileFlag = FILE_ATTRIBUTE_NORMAL; @@ -408,6 +429,10 @@ HANDLE taosOpenFileNotStream(const char *path, int32_t tdFileOptions) { } int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) { + if (pFile == NULL || buf == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } #if FILE_WITH_LOCK (void)taosThreadRwlockRdlock(&(pFile->rwlock)); #endif @@ -435,7 +460,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) { } int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) { - if (pFile == NULL || pFile->hFile == NULL) { + if (pFile == NULL || pFile->hFile == NULL || buf == NULL) { terrno = TSDB_CODE_INVALID_PARA; return 0; } @@ -457,7 +482,7 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) { } int64_t taosPWriteFile(TdFilePtr pFile, const void *buf, int64_t count, int64_t offset) { - if (pFile == NULL) { + if (pFile == NULL || buf == NULL) { terrno = TSDB_CODE_INVALID_PARA; return 0; } @@ -719,6 +744,10 @@ bool lastErrorIsFileNotExist() { #else int taosOpenFileNotStream(const char *path, int32_t tdFileOptions) { + if (path == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return -1; + } int access = O_BINARY; access |= (tdFileOptions & TD_FILE_CREATE) ? O_CREAT : 0; if ((tdFileOptions & TD_FILE_WRITE) && (tdFileOptions & TD_FILE_READ)) { @@ -742,6 +771,10 @@ int taosOpenFileNotStream(const char *path, int32_t tdFileOptions) { } int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) { + if (pFile == NULL || buf == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return -1; + } STUB_RAND_IO_ERR(terrno) #if FILE_WITH_LOCK (void)taosThreadRwlockRdlock(&(pFile->rwlock)); @@ -797,7 +830,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) { int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) { STUB_RAND_IO_ERR(terrno) - if (pFile == NULL) { + if (pFile == NULL || buf == NULL) { terrno = TSDB_CODE_INVALID_PARA; return 0; } @@ -843,7 +876,7 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) { int64_t taosPWriteFile(TdFilePtr pFile, const void *buf, int64_t count, int64_t offset) { STUB_RAND_IO_ERR(terrno) - if (pFile == NULL) { + if (pFile == NULL || buf == NULL) { terrno = TSDB_CODE_INVALID_PARA; return 0; } @@ -1050,6 +1083,10 @@ bool lastErrorIsFileNotExist() { return terrno == TAOS_SYSTEM_ERROR(ENOENT); } #endif // WINDOWS TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) { + if (path == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } STUB_RAND_IO_ERR(NULL) FILE *fp = NULL; #ifdef WINDOWS @@ -1399,6 +1436,10 @@ int32_t taosEOFFile(TdFilePtr pFile) { } bool taosCheckAccessFile(const char *pathname, int32_t tdFileAccessOptions) { + if (pathname == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return false; // invalid parameter + } int flags = 0; if (tdFileAccessOptions & TD_FILE_ACCESS_EXIST_OK) { @@ -1422,6 +1463,8 @@ bool taosCheckAccessFile(const char *pathname, int32_t tdFileAccessOptions) { bool taosCheckExistFile(const char *pathname) { return taosCheckAccessFile(pathname, TD_FILE_ACCESS_EXIST_OK); }; int32_t taosCompressFile(char *srcFileName, char *destFileName) { + OS_PARAM_CHECK(srcFileName); + OS_PARAM_CHECK(destFileName); int32_t compressSize = 163840; int32_t ret = 0; int32_t len = 0; @@ -1516,6 +1559,10 @@ int32_t taosLinkFile(char *src, char *dst) { } FILE *taosOpenCFile(const char *filename, const char *mode) { + if (filename == NULL || mode == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } STUB_RAND_IO_ERR(NULL) FILE *f = fopen(filename, mode); if (NULL == f) { @@ -1525,6 +1572,10 @@ FILE *taosOpenCFile(const char *filename, const char *mode) { } int taosSeekCFile(FILE *file, int64_t offset, int whence) { + if(NULL == file) { + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } #ifdef WINDOWS return _fseeki64(file, offset, whence); #else @@ -1538,6 +1589,10 @@ int taosSeekCFile(FILE *file, int64_t offset, int whence) { } size_t taosReadFromCFile(void *buffer, size_t size, size_t count, FILE *stream) { + if (buffer == NULL || stream == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } STUB_RAND_IO_ERR(terrno) return fread(buffer, size, count, stream); } diff --git a/source/os/src/osLocale.c b/source/os/src/osLocale.c index becf0d5a70..21f781c7e4 100644 --- a/source/os/src/osLocale.c +++ b/source/os/src/osLocale.c @@ -52,6 +52,9 @@ typedef struct CharsetPair { } CharsetPair; char *taosCharsetReplace(char *charsetstr) { + if (charsetstr == NULL) { + return NULL; + } CharsetPair charsetRep[] = { {"utf8", "UTF-8"}, {"936", "CP936"}, @@ -76,6 +79,8 @@ char *taosCharsetReplace(char *charsetstr) { * In case that the setLocale failed to be executed, the right charset needs to be set. */ int32_t taosSetSystemLocale(const char *inLocale, const char *inCharSet) { + OS_PARAM_CHECK(inLocale); + OS_PARAM_CHECK(inCharSet); if (!taosValidateEncodec(inCharSet)) { return terrno; } @@ -90,6 +95,7 @@ int32_t taosSetSystemLocale(const char *inLocale, const char *inCharSet) { } void taosGetSystemLocale(char *outLocale, char *outCharset) { + if (outLocale == NULL || outCharset == NULL) return; #ifdef WINDOWS char *locale = setlocale(LC_CTYPE, "en_US.UTF-8"); if (locale != NULL) { diff --git a/source/os/src/osSemaphore.c b/source/os/src/osSemaphore.c index e61fd627eb..9327b33f79 100644 --- a/source/os/src/osSemaphore.c +++ b/source/os/src/osSemaphore.c @@ -29,7 +29,11 @@ bool taosCheckPthreadValid(TdThread thread) { return thread.p != NULL; } -void taosResetPthread(TdThread* thread) { thread->p = 0; } +void taosResetPthread(TdThread* thread) { + if (thread != NULL) { + thread->p = NULL; + } +} int64_t taosGetPthreadId(TdThread thread) { #ifdef PTW32_VERSION @@ -46,6 +50,7 @@ bool taosComparePthread(TdThread first, TdThread second) { return first.p == sec int32_t taosGetPId() { return GetCurrentProcessId(); } int32_t taosGetAppName(char* name, int32_t* len) { + OS_PARAM_CHECK(name); char filepath[1024] = {0}; if (GetModuleFileName(NULL, filepath, MAX_PATH) == 0) { @@ -75,6 +80,8 @@ int32_t taosGetAppName(char* name, int32_t* len) { int32_t taosGetPIdByName(const char* name, int32_t* pPId) { return -1;} int32_t tsem_wait(tsem_t* sem) { + OS_PARAM_CHECK(sem); + OS_PARAM_CHECK(*sem); DWORD ret = WaitForSingleObject(*sem, INFINITE); if (ret == WAIT_OBJECT_0) { return 0; @@ -84,6 +91,8 @@ int32_t tsem_wait(tsem_t* sem) { } int32_t tsem_timewait(tsem_t* sem, int64_t timeout_ms) { + OS_PARAM_CHECK(sem); + OS_PARAM_CHECK(*sem); DWORD result = WaitForSingleObject(*sem, timeout_ms); if (result == WAIT_OBJECT_0) { return 0; // Semaphore acquired @@ -96,16 +105,21 @@ int32_t tsem_timewait(tsem_t* sem, int64_t timeout_ms) { // Inter-process sharing is not currently supported. The pshared parameter is invalid. int32_t tsem_init(tsem_t* sem, int pshared, unsigned int value) { + OS_PARAM_CHECK(sem); *sem = CreateSemaphore(NULL, value, LONG_MAX, NULL); return (*sem != NULL) ? 0 : TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); } int32_t tsem_post(tsem_t* sem) { + OS_PARAM_CHECK(sem); + OS_PARAM_CHECK(*sem); if (ReleaseSemaphore(*sem, 1, NULL)) return 0; return TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); } int32_t tsem_destroy(tsem_t* sem) { + OS_PARAM_CHECK(sem); + OS_PARAM_CHECK(*sem); if (CloseHandle(*sem)) return 0; return TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); } @@ -115,6 +129,7 @@ int32_t tsem_destroy(tsem_t* sem) { #include int32_t tsem_init(tsem_t *psem, int flags, unsigned int count) { + OS_PARAM_CHECK(psem); *psem = dispatch_semaphore_create(count); if (*psem == NULL) return TAOS_SYSTEM_ERROR(errno); return 0; @@ -128,19 +143,19 @@ int32_t tsem_destroy(tsem_t *psem) { } int32_t tsem_post(tsem_t *psem) { - if (psem == NULL || *psem == NULL) return -1; + if (psem == NULL || *psem == NULL) return TSDB_CODE_INVALID_PARA; (void)dispatch_semaphore_signal(*psem); return 0; } int32_t tsem_wait(tsem_t *psem) { - if (psem == NULL || *psem == NULL) return -1; + if (psem == NULL || *psem == NULL) return TSDB_CODE_INVALID_PARA; dispatch_semaphore_wait(*psem, DISPATCH_TIME_FOREVER); return 0; } int32_t tsem_timewait(tsem_t *psem, int64_t milis) { - if (psem == NULL || *psem == NULL) return -1; + if (psem == NULL || *psem == NULL) return TSDB_CODE_INVALID_PARA; dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(milis * USEC_PER_SEC)); if (dispatch_semaphore_wait(*psem, time) == 0) { return 0; @@ -158,13 +173,18 @@ int64_t taosGetSelfPthreadId() { int64_t taosGetPthreadId(TdThread thread) { return (int64_t)thread; } -void taosResetPthread(TdThread *thread) { *thread = NULL; } +void taosResetPthread(TdThread *thread) { + if (thread) { + *thread = NULL; + } +} bool taosComparePthread(TdThread first, TdThread second) { return taosThreadEqual(first, second) ? true : false; } int32_t taosGetPId() { return (int32_t)getpid(); } int32_t taosGetAppName(char *name, int32_t *len) { + OS_PARAM_CHECK(name); char buf[PATH_MAX + 1]; buf[0] = '\0'; proc_name(getpid(), buf, sizeof(buf) - 1); @@ -196,7 +216,11 @@ int64_t taosGetSelfPthreadId() { } int64_t taosGetPthreadId(TdThread thread) { return (int64_t)thread; } -void taosResetPthread(TdThread* thread) { *thread = 0; } +void taosResetPthread(TdThread* thread) { + if (thread) { + *thread = 0; + } +} bool taosComparePthread(TdThread first, TdThread second) { return first == second; } int32_t taosGetPId() { @@ -207,6 +231,7 @@ int32_t taosGetPId() { } int32_t taosGetAppName(char* name, int32_t* len) { + OS_PARAM_CHECK(name); const char* self = "/proc/self/exe"; char path[PATH_MAX] = {0}; @@ -233,6 +258,8 @@ int32_t taosGetAppName(char* name, int32_t* len) { } int32_t taosGetPIdByName(const char* name, int32_t* pPId) { + OS_PARAM_CHECK(name); + OS_PARAM_CHECK(pPId); DIR* dir = NULL; struct dirent* ptr = NULL; FILE* fp = NULL; @@ -294,6 +321,7 @@ int32_t tsem_init(tsem_t* psem, int flags, unsigned int count) { } int32_t tsem_timewait(tsem_t* sem, int64_t ms) { + OS_PARAM_CHECK(sem); int ret = 0; struct timespec ts = {0}; @@ -322,6 +350,7 @@ int32_t tsem_timewait(tsem_t* sem, int64_t ms) { } int32_t tsem_wait(tsem_t* sem) { + OS_PARAM_CHECK(sem); int ret = 0; do { ret = sem_wait(sem); @@ -336,6 +365,7 @@ int32_t tsem_wait(tsem_t* sem) { } int tsem2_init(tsem2_t* sem, int pshared, unsigned int value) { + OS_PARAM_CHECK(sem); int ret = taosThreadMutexInit(&sem->mutex, NULL); if (ret != 0) return ret; @@ -365,6 +395,7 @@ int tsem2_init(tsem2_t* sem, int pshared, unsigned int value) { } int32_t tsem_post(tsem_t* psem) { + OS_PARAM_CHECK(psem); if (sem_post(psem) == 0) { return 0; } else { @@ -373,6 +404,7 @@ int32_t tsem_post(tsem_t* psem) { } int32_t tsem_destroy(tsem_t* sem) { + OS_PARAM_CHECK(sem); if (sem_destroy(sem) == 0) { return 0; } else { @@ -381,6 +413,7 @@ int32_t tsem_destroy(tsem_t* sem) { } int tsem2_post(tsem2_t* sem) { + OS_PARAM_CHECK(sem); int32_t code = taosThreadMutexLock(&sem->mutex); if (code) { return code; @@ -401,6 +434,7 @@ int tsem2_post(tsem2_t* sem) { } int tsem2_destroy(tsem2_t* sem) { + OS_PARAM_CHECK(sem); (void)taosThreadMutexDestroy(&sem->mutex); (void)taosThreadCondDestroy(&sem->cond); (void)taosThreadCondAttrDestroy(&sem->attr); @@ -409,6 +443,7 @@ int tsem2_destroy(tsem2_t* sem) { } int32_t tsem2_wait(tsem2_t* sem) { + OS_PARAM_CHECK(sem); int32_t code = taosThreadMutexLock(&sem->mutex); if (code) { return code; @@ -434,6 +469,7 @@ int32_t tsem2_wait(tsem2_t* sem) { } int32_t tsem2_timewait(tsem2_t* sem, int64_t ms) { + OS_PARAM_CHECK(sem); int32_t code = 0; code = taosThreadMutexLock(&sem->mutex); diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index 5f983d5480..32b1023ed7 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -233,6 +233,8 @@ int32_t taosBlockSIGPIPE() { } int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t *ip) { + OS_PARAM_CHECK(fqdn); + OS_PARAM_CHECK(ip); #ifdef WINDOWS // Initialize Winsock WSADATA wsaData; @@ -309,6 +311,7 @@ int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t *ip) { } int32_t taosGetFqdn(char *fqdn) { + OS_PARAM_CHECK(fqdn); #ifdef WINDOWS // Initialize Winsock WSADATA wsaData; @@ -384,6 +387,9 @@ int32_t taosGetFqdn(char *fqdn) { } void tinet_ntoa(char *ipstr, uint32_t ip) { + if (ipstr == NULL) { + return; + } (void)snprintf(ipstr, TD_IP_LEN, "%d.%d.%d.%d", ip & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, ip >> 24); } diff --git a/source/os/src/osString.c b/source/os/src/osString.c index 18da778227..0ee4f1c496 100644 --- a/source/os/src/osString.c +++ b/source/os/src/osString.c @@ -25,15 +25,19 @@ extern int wcwidth(wchar_t c); extern int wcswidth(const wchar_t *s, size_t n); char *tstrdup(const char *str) { + if (str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } #ifdef WINDOWS return _strdup(str); #else - char* p = strdup(str); - if (str != NULL && NULL == p) { + char *p = strdup(str); + if (NULL == p) { terrno = TSDB_CODE_OUT_OF_MEMORY; } return p; - + #endif } @@ -41,11 +45,19 @@ char *tstrdup(const char *str) { // No errors are expected to occur char *strsep(char **stringp, const char *delim) { + if (stringp == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } char *s; const char *spanp; int32_t c, sc; char *tok; if ((s = *stringp) == NULL) return (NULL); + if (delim == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } for (tok = s;;) { c = *s++; spanp = delim; @@ -81,6 +93,10 @@ char *taosStrndup(const char *s, int size) { /* Copy no more than N characters of SRC to DEST, returning the address of the terminating '\0' in DEST, if any, or else DEST + N. */ char *stpncpy(char *dest, const char *src, int n) { + if (dest == NULL || src == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } size_t size = strnlen(src, n); memcpy(dest, src, size); dest += size; @@ -117,6 +133,8 @@ int32_t taosStr2int64(const char *str, int64_t *val) { } int32_t taosStr2int16(const char *str, int16_t *val) { + OS_PARAM_CHECK(str); + OS_PARAM_CHECK(val); int64_t tmp = 0; int32_t code = taosStr2int64(str, &tmp); if (code) { @@ -130,6 +148,8 @@ int32_t taosStr2int16(const char *str, int16_t *val) { } int32_t taosStr2int32(const char *str, int32_t *val) { + OS_PARAM_CHECK(str); + OS_PARAM_CHECK(val); int64_t tmp = 0; int32_t code = taosStr2int64(str, &tmp); if (code) { @@ -143,6 +163,8 @@ int32_t taosStr2int32(const char *str, int32_t *val) { } int32_t taosStr2int8(const char *str, int8_t *val) { + OS_PARAM_CHECK(str); + OS_PARAM_CHECK(val); int64_t tmp = 0; int32_t code = taosStr2int64(str, &tmp); if (code) { @@ -156,6 +178,9 @@ int32_t taosStr2int8(const char *str, int8_t *val) { } int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes) { + if ((f1_ucs4 == NULL || f2_ucs4 == NULL)) { + return TSDB_CODE_INVALID_PARA; + } for (int32_t i = 0; i < bytes; i += sizeof(TdUcs4)) { int32_t f1 = *(int32_t *)((char *)f1_ucs4 + i); int32_t f2 = *(int32_t *)((char *)f2_ucs4 + i); @@ -191,6 +216,9 @@ int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes) { } int32_t tasoUcs4Copy(TdUcs4 *target_ucs4, TdUcs4 *source_ucs4, int32_t len_ucs4) { + if (target_ucs4 == NULL || source_ucs4 == NULL || len_ucs4 <= 0) { + return TSDB_CODE_INVALID_PARA; + } if (taosMemorySize(target_ucs4) < len_ucs4 * sizeof(TdUcs4)) { terrno = TSDB_CODE_INVALID_PARA; return terrno; @@ -261,6 +289,10 @@ void taosConvDestroy() { } iconv_t taosAcquireConv(int32_t *idx, ConvType type) { + if(idx == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return (iconv_t)-1; + } if (gConvMaxNum[type] <= 0) { *idx = -1; if (type == M2C) { @@ -321,6 +353,13 @@ void taosReleaseConv(int32_t idx, iconv_t conv, ConvType type) { } bool taosMbsToUcs4(const char *mbs, size_t mbsLength, TdUcs4 *ucs4, int32_t ucs4_max_len, int32_t *len) { + if (ucs4_max_len == 0) { + return true; + } + if(ucs4_max_len < 0 || mbs == NULL || ucs4 == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return false; + } #ifdef DISALLOW_NCHAR_WITHOUT_ICONV printf("Nchar cannot be read and written without iconv, please install iconv library and recompile.\n"); terrno = TSDB_CODE_APP_ERROR; @@ -359,6 +398,13 @@ bool taosMbsToUcs4(const char *mbs, size_t mbsLength, TdUcs4 *ucs4, int32_t ucs4 // if success, return the number of bytes written to mbs ( >= 0) // otherwise return error code ( < 0) int32_t taosUcs4ToMbs(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs) { + if (ucs4_max_len == 0) { + return 0; + } + if(ucs4_max_len < 0 || ucs4 == NULL || mbs == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } #ifdef DISALLOW_NCHAR_WITHOUT_ICONV printf("Nchar cannot be read and written without iconv, please install iconv library and recompile.\n"); terrno = TSDB_CODE_APP_ERROR; @@ -390,6 +436,13 @@ int32_t taosUcs4ToMbs(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs) { // if success, return the number of bytes written to mbs ( >= 0) // otherwise return error code ( < 0) int32_t taosUcs4ToMbsEx(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs, iconv_t conv) { + if (ucs4_max_len == 0) { + return 0; + } + if(ucs4_max_len < 0 || ucs4 == NULL || mbs == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } #ifdef DISALLOW_NCHAR_WITHOUT_ICONV printf("Nchar cannot be read and written without iconv, please install iconv library and recompile.\n"); terrno = TSDB_CODE_APP_ERROR; @@ -408,6 +461,10 @@ int32_t taosUcs4ToMbsEx(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs, iconv_t c } bool taosValidateEncodec(const char *encodec) { + if(encodec == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return false; + } #ifdef DISALLOW_NCHAR_WITHOUT_ICONV printf("Nchar cannot be read and written without iconv, please install iconv library and recompile.\n"); terrno = TSDB_CODE_APP_ERROR; @@ -443,7 +500,7 @@ int32_t taosUcs4len(TdUcs4 *ucs4) { // dst buffer size should be at least 2*len + 1 int32_t taosHexEncode(const unsigned char *src, char *dst, int32_t len, int32_t bufSize) { - if (!dst) { + if (!dst || !src || bufSize <= 0) { terrno = TSDB_CODE_INVALID_PARA; return terrno; } @@ -456,7 +513,7 @@ int32_t taosHexEncode(const unsigned char *src, char *dst, int32_t len, int32_t } int32_t taosHexDecode(const char *src, char *dst, int32_t len) { - if (!dst) { + if(!src || !dst || len <= 0) { terrno = TSDB_CODE_INVALID_PARA; return terrno; } @@ -475,19 +532,42 @@ int32_t taosHexDecode(const char *src, char *dst, int32_t len) { int32_t taosWcharWidth(TdWchar wchar) { return wcwidth(wchar); } -int32_t taosWcharsWidth(TdWchar *pWchar, int32_t size) { return wcswidth(pWchar, size); } +int32_t taosWcharsWidth(TdWchar *pWchar, int32_t size) { + if (pWchar == NULL || size <= 0) { + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + return wcswidth(pWchar, size); +} -int32_t taosMbToWchar(TdWchar *pWchar, const char *pStr, int32_t size) { return mbtowc(pWchar, pStr, size); } +int32_t taosMbToWchar(TdWchar *pWchar, const char *pStr, int32_t size) { + if (pWchar == NULL || pStr == NULL || size <= 0) { + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + return mbtowc(pWchar, pStr, size); +} -int32_t taosMbsToWchars(TdWchar *pWchars, const char *pStrs, int32_t size) { return mbstowcs(pWchars, pStrs, size); } +int32_t taosMbsToWchars(TdWchar *pWchars, const char *pStrs, int32_t size) { + if (pWchars == NULL || pStrs == NULL || size <= 0) { + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + return mbstowcs(pWchars, pStrs, size); +} -int32_t taosWcharToMb(char *pStr, TdWchar wchar) { return wctomb(pStr, wchar); } +int32_t taosWcharToMb(char *pStr, TdWchar wchar) { + OS_PARAM_CHECK(pStr); + return wctomb(pStr, wchar); } char *taosStrCaseStr(const char *str, const char *pattern) { + if (str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } + if (!pattern || !*pattern) return (char *)str; + size_t i; - - if (!*pattern) return (char *)str; - for (; *str; str++) { if (toupper(*str) == toupper(*pattern)) { for (i = 1;; i++) { @@ -500,6 +580,10 @@ char *taosStrCaseStr(const char *str, const char *pattern) { } int64_t taosStr2Int64(const char *str, char **pEnd, int32_t radix) { + if(str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } int64_t tmp = strtoll(str, pEnd, radix); #if defined(DARWIN) || defined(_ALPINE) if (errno == EINVAL) errno = 0; @@ -508,6 +592,10 @@ int64_t taosStr2Int64(const char *str, char **pEnd, int32_t radix) { } uint64_t taosStr2UInt64(const char *str, char **pEnd, int32_t radix) { + if(str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } uint64_t tmp = strtoull(str, pEnd, radix); #if defined(DARWIN) || defined(_ALPINE) if (errno == EINVAL) errno = 0; @@ -516,6 +604,10 @@ uint64_t taosStr2UInt64(const char *str, char **pEnd, int32_t radix) { } int32_t taosStr2Int32(const char *str, char **pEnd, int32_t radix) { + if(str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } int32_t tmp = strtol(str, pEnd, radix); #if defined(DARWIN) || defined(_ALPINE) if (errno == EINVAL) errno = 0; @@ -524,6 +616,10 @@ int32_t taosStr2Int32(const char *str, char **pEnd, int32_t radix) { } uint32_t taosStr2UInt32(const char *str, char **pEnd, int32_t radix) { + if(str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } uint32_t tmp = strtol(str, pEnd, radix); #if defined(DARWIN) || defined(_ALPINE) if (errno == EINVAL) errno = 0; @@ -532,6 +628,10 @@ uint32_t taosStr2UInt32(const char *str, char **pEnd, int32_t radix) { } int16_t taosStr2Int16(const char *str, char **pEnd, int32_t radix) { + if(str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } int32_t tmp = strtol(str, pEnd, radix); #if defined(DARWIN) || defined(_ALPINE) if (errno == EINVAL) errno = 0; @@ -540,6 +640,10 @@ int16_t taosStr2Int16(const char *str, char **pEnd, int32_t radix) { } uint16_t taosStr2UInt16(const char *str, char **pEnd, int32_t radix) { + if(str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } uint32_t tmp = strtoul(str, pEnd, radix); #if defined(DARWIN) || defined(_ALPINE) if (errno == EINVAL) errno = 0; @@ -548,11 +652,19 @@ uint16_t taosStr2UInt16(const char *str, char **pEnd, int32_t radix) { } int8_t taosStr2Int8(const char *str, char **pEnd, int32_t radix) { + if(str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } int32_t tmp = strtol(str, pEnd, radix); return tmp; } uint8_t taosStr2UInt8(const char *str, char **pEnd, int32_t radix) { + if(str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } uint32_t tmp = strtoul(str, pEnd, radix); #if defined(DARWIN) || defined(_ALPINE) if (errno == EINVAL) errno = 0; @@ -561,11 +673,19 @@ uint8_t taosStr2UInt8(const char *str, char **pEnd, int32_t radix) { } double taosStr2Double(const char *str, char **pEnd) { + if(str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } double tmp = strtod(str, pEnd); return tmp; } float taosStr2Float(const char *str, char **pEnd) { + if(str == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } float tmp = strtof(str, pEnd); return tmp; } @@ -578,6 +698,10 @@ bool isHex(const char *z, uint32_t n) { } bool isValidateHex(const char *z, uint32_t n) { + if(!z) { + terrno = TSDB_CODE_INVALID_PARA; + return false; + } if ((n & 1) != 0) return false; for (size_t i = HEX_PREFIX_LEN; i < n; i++) { if (isxdigit(z[i]) == 0) { @@ -588,6 +712,9 @@ bool isValidateHex(const char *z, uint32_t n) { } int32_t taosHex2Ascii(const char *z, uint32_t n, void **data, uint32_t *size) { + OS_PARAM_CHECK(z); + OS_PARAM_CHECK(data); + OS_PARAM_CHECK(size); n -= HEX_PREFIX_LEN; // remove 0x z += HEX_PREFIX_LEN; *size = n / HEX_PREFIX_LEN; @@ -712,6 +839,10 @@ int32_t taosAscii2Hex(const char *z, uint32_t n, void **data, uint32_t *size) { } int64_t tsnprintf(char *dst, int64_t size, const char *format, ...) { + if (dst == NULL || format == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } if (size <= 0) return 0; if (size == 1) { dst[0] = '\0'; diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index bd1a058291..dc3258bf9c 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -154,6 +154,7 @@ static void taosGetProcIOnfos() { #endif static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) { + OS_PARAM_CHECK(cpuInfo); int32_t code = 0; #ifdef WINDOWS FILETIME pre_idleTime = {0}; @@ -206,6 +207,7 @@ static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) { } static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) { + OS_PARAM_CHECK(cpuInfo); int32_t code = 0; #ifdef WINDOWS @@ -287,6 +289,7 @@ void taosGetSystemInfo() { } int32_t taosGetEmail(char *email, int32_t maxLen) { + OS_PARAM_CHECK(email); #ifdef WINDOWS return 0; #elif defined(_TD_DARWIN_64) @@ -330,6 +333,7 @@ int32_t taosGetEmail(char *email, int32_t maxLen) { #ifdef WINDOWS bool getWinVersionReleaseName(char *releaseName, int32_t maxLen) { + if(releaseName == NULL) return false; TCHAR szFileName[MAX_PATH]; DWORD dwHandle; DWORD dwLen; @@ -367,6 +371,7 @@ bool getWinVersionReleaseName(char *releaseName, int32_t maxLen) { #endif int32_t taosGetOsReleaseName(char *releaseName, char* sName, char* ver, int32_t maxLen) { + OS_PARAM_CHECK(releaseName); #ifdef WINDOWS if (!getWinVersionReleaseName(releaseName, maxLen)) { snprintf(releaseName, maxLen, "Windows"); @@ -437,6 +442,8 @@ int32_t taosGetOsReleaseName(char *releaseName, char* sName, char* ver, int32_t } int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) { + OS_PARAM_CHECK(cpuModel); + OS_PARAM_CHECK(numOfCores); #ifdef WINDOWS char value[100]; DWORD bufferSize = sizeof(value); @@ -541,6 +548,7 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) { // Returns the container's CPU quota if successful, otherwise returns the physical CPU cores static int32_t taosCntrGetCpuCores(float *numOfCores) { + OS_PARAM_CHECK(numOfCores); #ifdef WINDOWS return TSDB_CODE_UNSUPPORT_OS; #elif defined(_TD_DARWIN_64) @@ -600,6 +608,7 @@ _end: } int32_t taosGetCpuCores(float *numOfCores, bool physical) { + OS_PARAM_CHECK(numOfCores); #ifdef WINDOWS SYSTEM_INFO info; GetSystemInfo(&info); @@ -702,6 +711,7 @@ int32_t taosGetCpuInstructions(char* sse42, char* avx, char* avx2, char* fma, ch } int32_t taosGetTotalMemory(int64_t *totalKB) { + OS_PARAM_CHECK(totalKB); #ifdef WINDOWS MEMORYSTATUSEX memsStat; memsStat.dwLength = sizeof(memsStat); @@ -723,6 +733,7 @@ int32_t taosGetTotalMemory(int64_t *totalKB) { } int32_t taosGetProcMemory(int64_t *usedKB) { + OS_PARAM_CHECK(usedKB); #ifdef WINDOWS unsigned bytes_used = 0; @@ -769,6 +780,7 @@ int32_t taosGetProcMemory(int64_t *usedKB) { } int32_t taosGetSysMemory(int64_t *usedKB) { + OS_PARAM_CHECK(usedKB); #ifdef WINDOWS MEMORYSTATUSEX memsStat; memsStat.dwLength = sizeof(memsStat); @@ -794,6 +806,8 @@ int32_t taosGetSysMemory(int64_t *usedKB) { } int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) { + OS_PARAM_CHECK(dataDir); + OS_PARAM_CHECK(diskSize); #if defined(WINDOWS) unsigned _int64 i64FreeBytesToCaller; unsigned _int64 i64TotalBytes; @@ -839,21 +853,25 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) { } int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes) { + OS_PARAM_CHECK(rchars); + OS_PARAM_CHECK(wchars); + OS_PARAM_CHECK(read_bytes); + OS_PARAM_CHECK(write_bytes); #ifdef WINDOWS IO_COUNTERS io_counter; if (GetProcessIoCounters(GetCurrentProcess(), &io_counter)) { - if (rchars) *rchars = io_counter.ReadTransferCount; - if (wchars) *wchars = io_counter.WriteTransferCount; - if (read_bytes) *read_bytes = 0; - if (write_bytes) *write_bytes = 0; + *rchars = io_counter.ReadTransferCount; + *wchars = io_counter.WriteTransferCount; + *read_bytes = 0; + *write_bytes = 0; return 0; } return TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); #elif defined(_TD_DARWIN_64) - if (rchars) *rchars = 0; - if (wchars) *wchars = 0; - if (read_bytes) *read_bytes = 0; - if (write_bytes) *write_bytes = 0; + *rchars = 0; + *wchars = 0; + *read_bytes = 0; + *write_bytes = 0; return 0; #else TdFilePtr pFile = taosOpenFile(tsProcIOFile, TD_FILE_READ | TD_FILE_STREAM); @@ -900,6 +918,9 @@ int32_t taosGetProcIO(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int } int32_t taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes) { + if (rchars == NULL || wchars == NULL || read_bytes == NULL || write_bytes == NULL) { + return TSDB_CODE_INVALID_PARA; + } static int64_t last_rchars = -1; static int64_t last_wchars = -1; static int64_t last_read_bytes = -1; @@ -932,13 +953,15 @@ int32_t taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes return 0; } void taosSetDefaultProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, int64_t *write_bytes) { - *rchars = 0; - *wchars = 0; - *read_bytes = 0; - *write_bytes = 0; + if(rchars) *rchars = 0; + if(wchars) *wchars = 0; + if(read_bytes) *read_bytes = 0; + if(write_bytes) *write_bytes = 0; } int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) { + OS_PARAM_CHECK(receive_bytes); + OS_PARAM_CHECK(transmit_bytes); *receive_bytes = 0; *transmit_bytes = 0; @@ -994,6 +1017,8 @@ int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) { } int32_t taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes) { + OS_PARAM_CHECK(receive_bytes); + OS_PARAM_CHECK(transmit_bytes); static int64_t last_receive_bytes = -1; static int64_t last_transmit_bytes = -1; int64_t cur_receive_bytes = 0; @@ -1017,8 +1042,8 @@ int32_t taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes) { return 0; } void taosSetDefaultCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes) { - *receive_bytes = 0; - *transmit_bytes = 0; + if (receive_bytes) *receive_bytes = 0; + if (transmit_bytes) *transmit_bytes = 0; } void taosKillSystem() { @@ -1037,6 +1062,7 @@ void taosKillSystem() { #define UUIDLEN (36) int32_t taosGetSystemUUIDLimit36(char *uid, int32_t uidlen) { + OS_PARAM_CHECK(uid); #ifdef WINDOWS GUID guid; HRESULT h = CoCreateGuid(&guid); @@ -1334,6 +1360,7 @@ int32_t getMacLocalHostNameBySCD(char *hostname, size_t maxLen) { #endif int32_t taosGetlocalhostname(char *hostname, size_t maxLen) { + OS_PARAM_CHECK(hostname); #ifdef _TD_DARWIN_64 int res = getMacLocalHostNameBySCD(hostname, maxLen); if (res != 0) { diff --git a/source/os/src/osSystem.c b/source/os/src/osSystem.c index fe52369a53..fefada2142 100644 --- a/source/os/src/osSystem.c +++ b/source/os/src/osSystem.c @@ -107,26 +107,6 @@ void* taosLoadDll(const char* filename) { #endif } -void* taosLoadSym(void* handle, char* name) { -#if defined(WINDOWS) - return NULL; -#elif defined(_TD_DARWIN_64) - return NULL; -#else - void* sym = dlsym(handle, name); - char* error = NULL; - - if ((error = dlerror()) != NULL) { - // printf("load sym:%s failed, error:%s", name, dlerror()); - return NULL; - } - - // printf("sym %s loaded", name); - - return sym; -#endif -} - void taosCloseDll(void* handle) { #if defined(WINDOWS) return; diff --git a/source/os/src/osThread.c b/source/os/src/osThread.c index 6a8c705cde..f888835d95 100644 --- a/source/os/src/osThread.c +++ b/source/os/src/osThread.c @@ -18,6 +18,8 @@ #include "os.h" int32_t taosThreadCreate(TdThread *tid, const TdThreadAttr *attr, void *(*start)(void *), void *arg) { + OS_PARAM_CHECK(tid); + OS_PARAM_CHECK(start); int32_t code = pthread_create(tid, attr, start, arg); if (code) { taosThreadClear(tid); @@ -28,6 +30,7 @@ int32_t taosThreadCreate(TdThread *tid, const TdThreadAttr *attr, void *(*start) } int32_t taosThreadAttrDestroy(TdThreadAttr *attr) { + OS_PARAM_CHECK(attr); int32_t code = pthread_attr_destroy(attr); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -37,6 +40,8 @@ int32_t taosThreadAttrDestroy(TdThreadAttr *attr) { } int32_t taosThreadAttrGetDetachState(const TdThreadAttr *attr, int32_t *detachstate) { + OS_PARAM_CHECK(attr); + OS_PARAM_CHECK(detachstate); int32_t code = pthread_attr_getdetachstate(attr, detachstate); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -46,6 +51,8 @@ int32_t taosThreadAttrGetDetachState(const TdThreadAttr *attr, int32_t *detachst } int32_t taosThreadAttrGetInheritSched(const TdThreadAttr *attr, int32_t *inheritsched) { + OS_PARAM_CHECK(attr); + OS_PARAM_CHECK(inheritsched); int32_t code = pthread_attr_getinheritsched(attr, inheritsched); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -55,6 +62,8 @@ int32_t taosThreadAttrGetInheritSched(const TdThreadAttr *attr, int32_t *inherit } int32_t taosThreadAttrGetSchedParam(const TdThreadAttr *attr, struct sched_param *param) { + OS_PARAM_CHECK(attr); + OS_PARAM_CHECK(param); int32_t code = pthread_attr_getschedparam(attr, param); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -64,6 +73,8 @@ int32_t taosThreadAttrGetSchedParam(const TdThreadAttr *attr, struct sched_param } int32_t taosThreadAttrGetSchedPolicy(const TdThreadAttr *attr, int32_t *policy) { + OS_PARAM_CHECK(attr); + OS_PARAM_CHECK(policy); int32_t code = pthread_attr_getschedpolicy(attr, policy); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -73,6 +84,8 @@ int32_t taosThreadAttrGetSchedPolicy(const TdThreadAttr *attr, int32_t *policy) } int32_t taosThreadAttrGetScope(const TdThreadAttr *attr, int32_t *contentionscope) { + OS_PARAM_CHECK(attr); + OS_PARAM_CHECK(contentionscope); int32_t code = pthread_attr_getscope(attr, contentionscope); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -82,6 +95,8 @@ int32_t taosThreadAttrGetScope(const TdThreadAttr *attr, int32_t *contentionscop } int32_t taosThreadAttrGetStackSize(const TdThreadAttr *attr, size_t *stacksize) { + OS_PARAM_CHECK(attr); + OS_PARAM_CHECK(stacksize); int32_t code = pthread_attr_getstacksize(attr, stacksize); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -90,7 +105,8 @@ int32_t taosThreadAttrGetStackSize(const TdThreadAttr *attr, size_t *stacksize) return code; } -int32_t taosThreadAttrInit(TdThreadAttr *attr) { +int32_t taosThreadAttrInit(TdThreadAttr *attr) { + OS_PARAM_CHECK(attr); int32_t code = pthread_attr_init(attr); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -100,6 +116,7 @@ int32_t taosThreadAttrInit(TdThreadAttr *attr) { } int32_t taosThreadAttrSetDetachState(TdThreadAttr *attr, int32_t detachstate) { + OS_PARAM_CHECK(attr); int32_t code = pthread_attr_setdetachstate(attr, detachstate); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -109,6 +126,7 @@ int32_t taosThreadAttrSetDetachState(TdThreadAttr *attr, int32_t detachstate) { } int32_t taosThreadAttrSetInheritSched(TdThreadAttr *attr, int32_t inheritsched) { + OS_PARAM_CHECK(attr); int32_t code = pthread_attr_setinheritsched(attr, inheritsched); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -118,6 +136,7 @@ int32_t taosThreadAttrSetInheritSched(TdThreadAttr *attr, int32_t inheritsched) } int32_t taosThreadAttrSetSchedParam(TdThreadAttr *attr, const struct sched_param *param) { + OS_PARAM_CHECK(attr); int32_t code = pthread_attr_setschedparam(attr, param); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -127,6 +146,7 @@ int32_t taosThreadAttrSetSchedParam(TdThreadAttr *attr, const struct sched_param } int32_t taosThreadAttrSetSchedPolicy(TdThreadAttr *attr, int32_t policy) { + OS_PARAM_CHECK(attr); int32_t code = pthread_attr_setschedpolicy(attr, policy); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -136,6 +156,7 @@ int32_t taosThreadAttrSetSchedPolicy(TdThreadAttr *attr, int32_t policy) { } int32_t taosThreadAttrSetScope(TdThreadAttr *attr, int32_t contentionscope) { + OS_PARAM_CHECK(attr); int32_t code = pthread_attr_setscope(attr, contentionscope); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -145,6 +166,7 @@ int32_t taosThreadAttrSetScope(TdThreadAttr *attr, int32_t contentionscope) { } int32_t taosThreadAttrSetStackSize(TdThreadAttr *attr, size_t stacksize) { + OS_PARAM_CHECK(attr); int32_t code = pthread_attr_setstacksize(attr, stacksize); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -163,6 +185,7 @@ int32_t taosThreadCancel(TdThread thread) { } int32_t taosThreadCondDestroy(TdThreadCond *cond) { + OS_PARAM_CHECK(cond); #ifdef __USE_WIN_THREAD return 0; #else @@ -176,6 +199,7 @@ int32_t taosThreadCondDestroy(TdThreadCond *cond) { } int32_t taosThreadCondInit(TdThreadCond *cond, const TdThreadCondAttr *attr) { + OS_PARAM_CHECK(cond); #ifdef __USE_WIN_THREAD InitializeConditionVariable(cond); return 0; @@ -190,6 +214,7 @@ int32_t taosThreadCondInit(TdThreadCond *cond, const TdThreadCondAttr *attr) { } int32_t taosThreadCondSignal(TdThreadCond *cond) { + OS_PARAM_CHECK(cond); #ifdef __USE_WIN_THREAD WakeConditionVariable(cond); return 0; @@ -204,6 +229,7 @@ int32_t taosThreadCondSignal(TdThreadCond *cond) { } int32_t taosThreadCondBroadcast(TdThreadCond *cond) { + OS_PARAM_CHECK(cond); #ifdef __USE_WIN_THREAD WakeAllConditionVariable(cond); return 0; @@ -218,6 +244,8 @@ int32_t taosThreadCondBroadcast(TdThreadCond *cond) { } int32_t taosThreadCondWait(TdThreadCond *cond, TdThreadMutex *mutex) { + OS_PARAM_CHECK(cond); + OS_PARAM_CHECK(mutex); #ifdef __USE_WIN_THREAD if (!SleepConditionVariableCS(cond, mutex, INFINITE)) { return EINVAL; @@ -234,8 +262,10 @@ int32_t taosThreadCondWait(TdThreadCond *cond, TdThreadMutex *mutex) { } int32_t taosThreadCondTimedWait(TdThreadCond *cond, TdThreadMutex *mutex, const struct timespec *abstime) { -#ifdef __USE_WIN_THREAD if (!abstime) return 0; + OS_PARAM_CHECK(cond); + OS_PARAM_CHECK(mutex); +#ifdef __USE_WIN_THREAD if (SleepConditionVariableCS(cond, mutex, (DWORD)(abstime->tv_sec * 1e3 + abstime->tv_nsec / 1e6))) return 0; DWORD error = GetLastError(); if (error == ERROR_TIMEOUT) { @@ -258,6 +288,7 @@ int32_t taosThreadCondAttrDestroy(TdThreadCondAttr *attr) { #ifdef __USE_WIN_THREAD return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_condattr_destroy(attr); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -268,10 +299,12 @@ int32_t taosThreadCondAttrDestroy(TdThreadCondAttr *attr) { } int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr *attr, int32_t *pshared) { + OS_PARAM_CHECK(pshared); #ifdef __USE_WIN_THREAD if (pshared) *pshared = PTHREAD_PROCESS_PRIVATE; return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_condattr_getpshared(attr, pshared); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -285,6 +318,7 @@ int32_t taosThreadCondAttrInit(TdThreadCondAttr *attr) { #ifdef __USE_WIN_THREAD return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_condattr_init(attr); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -300,6 +334,7 @@ int32_t taosThreadCondAttrSetclock(TdThreadCondAttr *attr, int clockId) { #elif defined(__APPLE__) return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_condattr_setclock(attr, clockId); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -310,6 +345,7 @@ int32_t taosThreadCondAttrSetclock(TdThreadCondAttr *attr, int clockId) { } int32_t taosThreadCondAttrSetPshared(TdThreadCondAttr *attr, int32_t pshared) { + OS_PARAM_CHECK(attr); #ifdef __USE_WIN_THREAD return 0; #else @@ -336,10 +372,12 @@ int32_t taosThreadEqual(TdThread t1, TdThread t2) { } void taosThreadExit(void *valuePtr) { - return pthread_exit(valuePtr); + if(valuePtr) return pthread_exit(valuePtr); } int32_t taosThreadGetSchedParam(TdThread thread, int32_t *policy, struct sched_param *param) { + OS_PARAM_CHECK(policy); + OS_PARAM_CHECK(param); int32_t code = pthread_getschedparam(thread, policy, param); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -362,6 +400,7 @@ int32_t taosThreadJoin(TdThread thread, void **valuePtr) { } int32_t taosThreadKeyCreate(TdThreadKey *key, void (*destructor)(void *)) { + OS_PARAM_CHECK(key); int32_t code = pthread_key_create(key, destructor); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -393,6 +432,7 @@ int32_t taosThreadKill(TdThread thread, int32_t sig) { // } int32_t taosThreadMutexDestroy(TdThreadMutex *mutex) { + OS_PARAM_CHECK(mutex); #ifdef __USE_WIN_THREAD DeleteCriticalSection(mutex); return 0; @@ -407,6 +447,7 @@ int32_t taosThreadMutexDestroy(TdThreadMutex *mutex) { } int32_t taosThreadMutexInit(TdThreadMutex *mutex, const TdThreadMutexAttr *attr) { + OS_PARAM_CHECK(mutex); #ifdef __USE_WIN_THREAD /** * Windows Server 2003 and Windows XP: In low memory situations, InitializeCriticalSection can raise a @@ -426,6 +467,7 @@ int32_t taosThreadMutexInit(TdThreadMutex *mutex, const TdThreadMutexAttr *attr) } int32_t taosThreadMutexLock(TdThreadMutex *mutex) { + OS_PARAM_CHECK(mutex); #ifdef __USE_WIN_THREAD EnterCriticalSection(mutex); return 0; @@ -444,6 +486,7 @@ int32_t taosThreadMutexLock(TdThreadMutex *mutex) { // } int32_t taosThreadMutexTryLock(TdThreadMutex *mutex) { + OS_PARAM_CHECK(mutex); #ifdef __USE_WIN_THREAD if (TryEnterCriticalSection(mutex)) return 0; return EBUSY; @@ -457,6 +500,7 @@ int32_t taosThreadMutexTryLock(TdThreadMutex *mutex) { } int32_t taosThreadMutexUnlock(TdThreadMutex *mutex) { + OS_PARAM_CHECK(mutex); #ifdef __USE_WIN_THREAD LeaveCriticalSection(mutex); return 0; @@ -474,6 +518,7 @@ int32_t taosThreadMutexAttrDestroy(TdThreadMutexAttr *attr) { #ifdef __USE_WIN_THREAD return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_mutexattr_destroy(attr); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -484,10 +529,12 @@ int32_t taosThreadMutexAttrDestroy(TdThreadMutexAttr *attr) { } int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr *attr, int32_t *pshared) { + OS_PARAM_CHECK(pshared); #ifdef __USE_WIN_THREAD if (pshared) *pshared = PTHREAD_PROCESS_PRIVATE; return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_mutexattr_getpshared(attr, pshared); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -502,10 +549,12 @@ int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr *attr, int32_t *ps // } int32_t taosThreadMutexAttrGetType(const TdThreadMutexAttr *attr, int32_t *kind) { + OS_PARAM_CHECK(kind); #ifdef __USE_WIN_THREAD if (kind) *kind = PTHREAD_MUTEX_NORMAL; return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_mutexattr_gettype(attr, kind); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -519,6 +568,7 @@ int32_t taosThreadMutexAttrInit(TdThreadMutexAttr *attr) { #ifdef __USE_WIN_THREAD return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_mutexattr_init(attr); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -532,6 +582,7 @@ int32_t taosThreadMutexAttrSetPshared(TdThreadMutexAttr *attr, int32_t pshared) #ifdef __USE_WIN_THREAD return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_mutexattr_setpshared(attr, pshared); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -549,6 +600,7 @@ int32_t taosThreadMutexAttrSetType(TdThreadMutexAttr *attr, int32_t kind) { #ifdef __USE_WIN_THREAD return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_mutexattr_settype(attr, kind); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -574,6 +626,7 @@ int32_t taosThreadRwlockDestroy(TdThreadRwlock *rwlock) { */ return 0; #else + OS_PARAM_CHECK(rwlock); int32_t code = pthread_rwlock_destroy(rwlock); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -584,6 +637,7 @@ int32_t taosThreadRwlockDestroy(TdThreadRwlock *rwlock) { } int32_t taosThreadRwlockInit(TdThreadRwlock *rwlock, const TdThreadRwlockAttr *attr) { + OS_PARAM_CHECK(rwlock); #ifdef __USE_WIN_THREAD memset(rwlock, 0, sizeof(*rwlock)); InitializeSRWLock(&rwlock->lock); @@ -599,6 +653,7 @@ int32_t taosThreadRwlockInit(TdThreadRwlock *rwlock, const TdThreadRwlockAttr *a } int32_t taosThreadRwlockRdlock(TdThreadRwlock *rwlock) { + OS_PARAM_CHECK(rwlock); #ifdef __USE_WIN_THREAD AcquireSRWLockShared(&rwlock->lock); return 0; @@ -621,6 +676,7 @@ int32_t taosThreadRwlockRdlock(TdThreadRwlock *rwlock) { // } int32_t taosThreadRwlockTryRdlock(TdThreadRwlock *rwlock) { + OS_PARAM_CHECK(rwlock); #ifdef __USE_WIN_THREAD if (!TryAcquireSRWLockShared(&rwlock->lock)) return EBUSY; return 0; @@ -635,6 +691,7 @@ int32_t taosThreadRwlockTryRdlock(TdThreadRwlock *rwlock) { } int32_t taosThreadRwlockTryWrlock(TdThreadRwlock *rwlock) { + OS_PARAM_CHECK(rwlock); #ifdef __USE_WIN_THREAD if (!TryAcquireSRWLockExclusive(&rwlock->lock)) return EBUSY; atomic_store_8(&rwlock->excl, 1); @@ -650,6 +707,7 @@ int32_t taosThreadRwlockTryWrlock(TdThreadRwlock *rwlock) { } int32_t taosThreadRwlockUnlock(TdThreadRwlock *rwlock) { + OS_PARAM_CHECK(rwlock); #ifdef __USE_WIN_THREAD if (1 == atomic_val_compare_exchange_8(&rwlock->excl, 1, 0)) { ReleaseSRWLockExclusive(&rwlock->lock); @@ -668,6 +726,7 @@ int32_t taosThreadRwlockUnlock(TdThreadRwlock *rwlock) { } int32_t taosThreadRwlockWrlock(TdThreadRwlock *rwlock) { + OS_PARAM_CHECK(rwlock); #ifdef __USE_WIN_THREAD AcquireSRWLockExclusive(&rwlock->lock); atomic_store_8(&rwlock->excl, 1); @@ -686,6 +745,7 @@ int32_t taosThreadRwlockAttrDestroy(TdThreadRwlockAttr *attr) { #ifdef __USE_WIN_THREAD return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_rwlockattr_destroy(attr); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -696,6 +756,7 @@ int32_t taosThreadRwlockAttrDestroy(TdThreadRwlockAttr *attr) { } int32_t taosThreadRwlockAttrGetPshared(const TdThreadRwlockAttr *attr, int32_t *pshared) { + OS_PARAM_CHECK(pshared); #ifdef __USE_WIN_THREAD if (pshared) *pshared = PTHREAD_PROCESS_PRIVATE; return 0; @@ -713,6 +774,7 @@ int32_t taosThreadRwlockAttrInit(TdThreadRwlockAttr *attr) { #ifdef __USE_WIN_THREAD return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_rwlockattr_init(attr); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -726,6 +788,7 @@ int32_t taosThreadRwlockAttrSetPshared(TdThreadRwlockAttr *attr, int32_t pshared #ifdef __USE_WIN_THREAD return 0; #else + OS_PARAM_CHECK(attr); int32_t code = pthread_rwlockattr_setpshared(attr, pshared); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -756,6 +819,7 @@ int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype) { } int32_t taosThreadSetSchedParam(TdThread thread, int32_t policy, const struct sched_param *param) { + OS_PARAM_CHECK(param); int32_t code = pthread_setschedparam(thread, policy, param); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -765,6 +829,7 @@ int32_t taosThreadSetSchedParam(TdThread thread, int32_t policy, const struct sc } int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) { + OS_PARAM_CHECK(value); int32_t code = pthread_setspecific(key, value); if (code) { terrno = TAOS_SYSTEM_ERROR(code); @@ -774,6 +839,7 @@ int32_t taosThreadSetSpecific(TdThreadKey key, const void *value) { } int32_t taosThreadSpinDestroy(TdThreadSpinlock *lock) { + OS_PARAM_CHECK(lock); #ifdef TD_USE_SPINLOCK_AS_MUTEX return pthread_mutex_destroy((pthread_mutex_t *)lock); #else @@ -787,6 +853,7 @@ int32_t taosThreadSpinDestroy(TdThreadSpinlock *lock) { } int32_t taosThreadSpinInit(TdThreadSpinlock *lock, int32_t pshared) { + OS_PARAM_CHECK(lock); #ifdef TD_USE_SPINLOCK_AS_MUTEX if (pshared != 0) return TSDB_CODE_INVALID_PARA; return pthread_mutex_init((pthread_mutex_t *)lock, NULL); @@ -801,6 +868,7 @@ int32_t taosThreadSpinInit(TdThreadSpinlock *lock, int32_t pshared) { } int32_t taosThreadSpinLock(TdThreadSpinlock *lock) { + OS_PARAM_CHECK(lock); #ifdef TD_USE_SPINLOCK_AS_MUTEX return pthread_mutex_lock((pthread_mutex_t *)lock); #else @@ -814,6 +882,7 @@ int32_t taosThreadSpinLock(TdThreadSpinlock *lock) { } int32_t taosThreadSpinTrylock(TdThreadSpinlock *lock) { + OS_PARAM_CHECK(lock); #ifdef TD_USE_SPINLOCK_AS_MUTEX return pthread_mutex_trylock((pthread_mutex_t *)lock); #else @@ -826,6 +895,7 @@ int32_t taosThreadSpinTrylock(TdThreadSpinlock *lock) { } int32_t taosThreadSpinUnlock(TdThreadSpinlock *lock) { + OS_PARAM_CHECK(lock); #ifdef TD_USE_SPINLOCK_AS_MUTEX return pthread_mutex_unlock((pthread_mutex_t *)lock); #else @@ -843,6 +913,7 @@ void taosThreadTestCancel(void) { } void taosThreadClear(TdThread *thread) { + if (!thread) return; (void)memset(thread, 0, sizeof(TdThread)); } diff --git a/source/os/src/osTime.c b/source/os/src/osTime.c index d4d9936154..60339fc646 100644 --- a/source/os/src/osTime.c +++ b/source/os/src/osTime.c @@ -81,6 +81,7 @@ static const char *am_pm[2] = {"AM", "PM"}; #endif char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm) { + if (!buf || !fmt || !tm) return NULL; #ifdef WINDOWS char c; const char *bp; @@ -345,6 +346,9 @@ char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm) { } int32_t taosGetTimeOfDay(struct timeval *tv) { + if (tv == NULL) { + return TSDB_CODE_INVALID_PARA; + } int32_t code = 0; #ifdef WINDOWS LARGE_INTEGER t; @@ -365,12 +369,15 @@ int32_t taosGetTimeOfDay(struct timeval *tv) { #endif } -time_t taosTime(time_t *t) { +int32_t taosTime(time_t *t) { + if (t == NULL) { + return TSDB_CODE_INVALID_PARA; + } time_t r = time(t); if (r == (time_t)-1) { - terrno = TAOS_SYSTEM_ERROR(errno); + return TAOS_SYSTEM_ERROR(errno); } - return r; + return 0; } /* diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index d6852b0566..d2a2b1fb9a 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -25,7 +25,7 @@ #include "tunit.h" #include "tutil.h" -#define CFG_NAME_PRINT_LEN 24 +#define CFG_NAME_PRINT_LEN 32 #define CFG_SRC_PRINT_LEN 12 struct SConfig { @@ -881,11 +881,26 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) { case CFG_DTYPE_CHARSET: case CFG_DTYPE_TIMEZONE: case CFG_DTYPE_NONE: + if (strcasecmp(pItem->name, "dataDir") == 0) { + size_t sz = taosArrayGetSize(pItem->array); + if (sz > 1) { + for (size_t j = 0; j < sz; ++j) { + SDiskCfg *pCfg = taosArrayGet(pItem->array, j); + if (dump) { + (void)printf("%s %s %s l:%d p:%d d:%"PRIi8"\n", src, name, pCfg->dir, pCfg->level, pCfg->primary, pCfg->disable); + } else { + uInfo("%s %s %s l:%d p:%d d:%"PRIi8, src, name, pCfg->dir, pCfg->level, pCfg->primary, pCfg->disable); + } + } + break; + } + } if (dump) { (void)printf("%s %s %s\n", src, name, pItem->str); } else { uInfo("%s %s %s", src, name, pItem->str); } + break; } } diff --git a/source/util/src/terror.c b/source/util/src/terror.c index ce754e8795..00f72123dc 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -164,6 +164,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TSC_ENCODE_PARAM_NULL, "Not found compress pa TAOS_DEFINE_ERROR(TSDB_CODE_TSC_COMPRESS_PARAM_ERROR, "Invalid compress param") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_COMPRESS_LEVEL_ERROR, "Invalid compress level param") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_FAIL_GENERATE_JSON, "failed to generate JSON") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_STMT_BIND_NUMBER_ERROR, "bind number out of range or not match") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INTERNAL_ERROR, "Internal error") diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 76d0139521..f70b145dbc 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -154,16 +154,26 @@ static int32_t taosStartLog() { return 0; } -static void getDay(char *buf, int32_t bufSize) { - time_t t = taosTime(NULL); +static int32_t getDay(char *buf, int32_t bufSize) { + time_t t; + int32_t code = taosTime(&t); + if(code != 0) { + return code; + } struct tm tmInfo; if (taosLocalTime(&t, &tmInfo, buf, bufSize) != NULL) { TAOS_UNUSED(strftime(buf, bufSize, "%Y-%m-%d", &tmInfo)); } + return 0; } static int64_t getTimestampToday() { - time_t t = taosTime(NULL); + time_t t; + int32_t code = taosTime(&t); + if (code != 0) { + uError("failed to get time, reason:%s", tstrerror(code)); + return 0; + } struct tm tm; if (taosLocalTime(&t, &tm, NULL, 0) == NULL) { return 0; @@ -203,7 +213,11 @@ int32_t taosInitSlowLog() { char name[PATH_MAX + TD_TIME_STR_LEN] = {0}; char day[TD_TIME_STR_LEN] = {0}; - getDay(day, sizeof(day)); + int32_t code = getDay(day, sizeof(day)); + if (code != 0) { + (void)printf("failed to get day, reason:%s\n", tstrerror(code)); + return code; + } (void)snprintf(name, PATH_MAX + TD_TIME_STR_LEN, "%s.%s", tsLogObj.slowLogName, day); tsLogObj.timestampToday = getTimestampToday(); @@ -434,7 +448,12 @@ static void taosOpenNewSlowLogFile() { atomic_store_32(&tsLogObj.slowHandle->lock, 0); char day[TD_TIME_STR_LEN] = {0}; - getDay(day, sizeof(day)); + int32_t code = getDay(day, sizeof(day)); + if (code != 0) { + uError("failed to get day, reason:%s", tstrerror(code)); + (void)taosThreadMutexUnlock(&tsLogObj.logMutex); + return; + } TdFilePtr pFile = NULL; char name[PATH_MAX + TD_TIME_STR_LEN] = {0}; (void)snprintf(name, PATH_MAX + TD_TIME_STR_LEN, "%s.%s", tsLogObj.slowLogName, day); diff --git a/source/util/test/errorCodeTable.ini b/source/util/test/errorCodeTable.ini index 33c9d77c5e..e837954a0b 100644 --- a/source/util/test/errorCodeTable.ini +++ b/source/util/test/errorCodeTable.ini @@ -97,6 +97,7 @@ TSDB_CODE_TSC_ENCODE_PARAM_ERROR = 0x80000231 TSDB_CODE_TSC_ENCODE_PARAM_NULL = 0x80000232 TSDB_CODE_TSC_COMPRESS_PARAM_ERROR = 0x80000233 TSDB_CODE_TSC_COMPRESS_LEVEL_ERROR = 0x80000234 +TSDB_CODE_TSC_STMT_BIND_NUMBER_ERROR = 0x80000236 TSDB_CODE_TSC_INTERNAL_ERROR = 0x800002FF TSDB_CODE_MND_REQ_REJECTED = 0x80000300 TSDB_CODE_MND_NO_RIGHTS = 0x80000303 diff --git a/tests/army/query/function/generate_answer.sh b/tests/army/query/function/generate_answer.sh new file mode 100755 index 0000000000..6b798865bd --- /dev/null +++ b/tests/army/query/function/generate_answer.sh @@ -0,0 +1,44 @@ +#!/bin/bash +set -e +set -x +# 检查是否传入了两个参数 +# echo "参数个数: $#" +# if [ "$#" -ne 4 ]; then +# echo "使用方法: $0 -i -o " +# exit 1 +# fi + +# 读取传入的参数 +while getopts "i:o:" opt; do + case $opt in + i) + sqlfile="$OPTARG" + ;; + o) + query_result_file="$OPTARG" + ;; + \?) + echo "无效选项: -$OPTARG" >&2 + exit 1 + ;; + :) + echo "选项 -$OPTARG 需要一个参数." >&2 + exit 1 + ;; + esac +done + +# 删除sqlfile文件中每一行末尾的分号和空格 +sed -i 's/;\s*$//' "$sqlfile" + +# 执行SQL文件并生成query_result_file文件 +taos -f "$sqlfile" | grep -v 'Query OK' | grep -v 'Copyright' | grep -v 'Welcome to the TDengine Command' > "$query_result_file" +# echo $(cat "$query_result_file") +# echo "1" +# sed -i 's/ ([^()]*)$//' "$query_result_file" +# echo "1" +# 打印输入的文件名 +echo "输入的文件: $sqlfile" + +# 打印输出的文件名 +echo "输出的文件: $query_result_file" \ No newline at end of file diff --git a/tests/ci/Dockerfile b/tests/ci/Dockerfile index 8381f1bb57..d3d574b484 100644 --- a/tests/ci/Dockerfile +++ b/tests/ci/Dockerfile @@ -7,7 +7,7 @@ RUN apt-get install -y locales psmisc sudo tree libgeos-dev libgflags2.2 libgfl RUN sed -i 's/# en_US.UTF-8/en_US.UTF-8/' /etc/locale.gen && locale-gen RUN pip3 config set global.index-url http://admin:123456@192.168.0.212:3141/admin/dev/+simple/ RUN pip3 config set global.trusted-host 192.168.0.212 -RUN pip3 install taospy==2.7.15 taos-ws-py==0.3.1 pandas psutil fabric2 requests faker simplejson toml pexpect tzlocal distro decorator loguru hyperloglog +RUN pip3 install taospy==2.7.16 taos-ws-py==0.3.3 pandas psutil fabric2 requests faker simplejson toml pexpect tzlocal distro decorator loguru hyperloglog ENV LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LC_ALL=en_US.UTF-8 RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 RUN add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/' diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index 151358aec3..ed842f6463 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -327,6 +327,7 @@ ,,y,system-test,./pytest.sh python3 ./test.py -f 99-TDcase/TS-3311.py ,,y,system-test,./pytest.sh python3 ./test.py -f 99-TDcase/TS-3821.py ,,y,system-test,./pytest.sh python3 ./test.py -f 99-TDcase/TS-5130.py +,,y,system-test,./pytest.sh python3 ./test.py -f 99-TDcase/TS-5580.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/balance_vgroups_r1.py -N 6 ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/taosShell.py @@ -350,6 +351,7 @@ ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/user_privilege_all.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/fsync.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/multilevel.py +,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/multilevel_createdb.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/ttl.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/ttlChangeOnWrite.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/compress_tsz1.py @@ -360,6 +362,7 @@ ,,n,system-test,python3 ./test.py -f 0-others/tag_index_basic.py ,,n,system-test,python3 ./test.py -f 0-others/udfpy_main.py ,,n,system-test,python3 ./test.py -N 3 -f 0-others/walRetention.py +,,n,system-test,python3 ./test.py -f 0-others/wal_level_skip.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/splitVGroup.py -N 3 -n 1 ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/splitVGroupWal.py -N 3 -n 1 ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/splitVGroup.py -N 3 -n 3 diff --git a/tests/parallel_test/container_build.sh b/tests/parallel_test/container_build.sh index a386269f85..363f62284a 100755 --- a/tests/parallel_test/container_build.sh +++ b/tests/parallel_test/container_build.sh @@ -83,7 +83,7 @@ docker run \ -v ${REP_REAL_PATH}/community/contrib/xml2/:${REP_DIR}/community/contrib/xml2 \ -v ${REP_REAL_PATH}/community/contrib/zlib/:${REP_DIR}/community/contrib/zlib \ -v ${REP_REAL_PATH}/community/contrib/zstd/:${REP_DIR}/community/contrib/zstd \ - --rm --ulimit core=-1 taos_test:v1.0 sh -c "pip uninstall taospy -y;pip3 install taospy==2.7.2;cd $REP_DIR;rm -rf debug;mkdir -p debug;cd debug;cmake .. -DBUILD_HTTP=false -DBUILD_TOOLS=true -DBUILD_TEST=true -DWEBSOCKET=true -DBUILD_TAOSX=false -DJEMALLOC_ENABLED=0 -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ;make -j|| exit 1" + --rm --ulimit core=-1 taos_test:v1.0 sh -c "cd $REP_DIR;rm -rf debug;mkdir -p debug;cd debug;cmake .. -DBUILD_HTTP=false -DBUILD_TOOLS=true -DBUILD_TEST=true -DWEBSOCKET=true -DBUILD_TAOSX=false -DJEMALLOC_ENABLED=0 -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ;make -j|| exit 1" # -v ${REP_REAL_PATH}/community/contrib/jemalloc/:${REP_DIR}/community/contrib/jemalloc \ if [[ -d ${WORKDIR}/debugNoSan ]] ;then @@ -137,7 +137,7 @@ docker run \ -v ${REP_REAL_PATH}/community/contrib/xml2/:${REP_DIR}/community/contrib/xml2 \ -v ${REP_REAL_PATH}/community/contrib/zlib/:${REP_DIR}/community/contrib/zlib \ -v ${REP_REAL_PATH}/community/contrib/zstd/:${REP_DIR}/community/contrib/zstd \ - --rm --ulimit core=-1 taos_test:v1.0 sh -c "pip uninstall taospy -y;pip3 install taospy==2.7.2;cd $REP_DIR;rm -rf debug;mkdir -p debug;cd debug;cmake .. -DBUILD_HTTP=false -DBUILD_TOOLS=true -DBUILD_TEST=false -DWEBSOCKET=true -DBUILD_SANITIZER=1 -DTOOLS_SANITIZE=true -DCMAKE_BUILD_TYPE=Debug -DTOOLS_BUILD_TYPE=Debug -DBUILD_TAOSX=false -DJEMALLOC_ENABLED=0;make -j|| exit 1 " + --rm --ulimit core=-1 taos_test:v1.0 sh -c "cd $REP_DIR;rm -rf debug;mkdir -p debug;cd debug;cmake .. -DBUILD_HTTP=false -DBUILD_TOOLS=true -DBUILD_TEST=false -DWEBSOCKET=true -DBUILD_SANITIZER=1 -DTOOLS_SANITIZE=true -DCMAKE_BUILD_TYPE=Debug -DTOOLS_BUILD_TYPE=Debug -DBUILD_TAOSX=false -DJEMALLOC_ENABLED=0;make -j|| exit 1 " mv ${REP_REAL_PATH}/debug ${WORKDIR}/debugSan diff --git a/tests/parallel_test/run_case.sh b/tests/parallel_test/run_case.sh index fa8fedbdbe..5b0d34fc0a 100755 --- a/tests/parallel_test/run_case.sh +++ b/tests/parallel_test/run_case.sh @@ -76,16 +76,9 @@ ulimit -c unlimited md5sum /usr/lib/libtaos.so.1 md5sum /home/TDinternal/debug/build/lib/libtaos.so -#define taospy 2.7.16 -pip3 list|grep taospy -pip3 uninstall taospy -y -pip3 install --default-timeout=120 taospy==2.7.16 - -#define taos-ws-py 0.3.1 -pip3 list|grep taos-ws-py -pip3 uninstall taos-ws-py -y -pip3 install --default-timeout=600 taos-ws-py==0.3.3 - +#get python connector and update: taospy 2.7.16 taos-ws-py 0.3.3 +pip3 install taospy==2.7.16 +pip3 install taos-ws-py==0.3.3 $TIMEOUT_CMD $cmd RET=$? echo "cmd exit code: $RET" diff --git a/tests/pytest/util/dnodes.py b/tests/pytest/util/dnodes.py index 3832530218..29fb52e124 100644 --- a/tests/pytest/util/dnodes.py +++ b/tests/pytest/util/dnodes.py @@ -594,8 +594,7 @@ class TDDnode: def forcestop(self): if self.asan: - stopCmd = "%s -s stop -n dnode%d -x SIGKILL" + \ - (self.execPath, self.index) + stopCmd = "%s -s stop -n dnode%d -x SIGKILL" % (self.execPath, self.index) tdLog.info("execute script: " + stopCmd) os.system(stopCmd) return diff --git a/tests/script/api/sameReqidTest.c b/tests/script/api/sameReqidTest.c new file mode 100644 index 0000000000..7507619886 --- /dev/null +++ b/tests/script/api/sameReqidTest.c @@ -0,0 +1,406 @@ +// sample code to verify multiple queries with the same reqid +// to compile: gcc -o sameReqdiTest sameReqidTest.c -ltaos + +#include +#include +#include +#include +#include "taos.h" + +#define NUM_ROUNDS 10 +#define CONST_REQ_ID 12345 +#define TEST_DB "test" + +#define CHECK_CONDITION(condition, prompt, errstr) \ + do { \ + if (!(condition)) { \ + printf("\033[31m[%s:%d] failed to " prompt ", reason: %s\033[0m\n", __func__, __LINE__, errstr); \ + exit(EXIT_FAILURE); \ + } \ + } while (0) + +#define CHECK_RES(res, prompt) CHECK_CONDITION(taos_errno(res) == 0, prompt, taos_errstr(res)) +#define CHECK_CODE(code, prompt) CHECK_CONDITION(code == 0, prompt, taos_errstr(NULL)) + +static TAOS* getNewConnection() { + const char* host = "127.0.0.1"; + const char* user = "root"; + const char* passwd = "taosdata"; + TAOS* taos = NULL; + + taos_options(TSDB_OPTION_TIMEZONE, "GMT-8"); + taos = taos_connect(host, user, passwd, "", 0); + CHECK_CONDITION(taos != NULL, "connect to db", taos_errstr(NULL)); + return taos; +} + +static void prepareData(TAOS* taos) { + TAOS_RES* res = NULL; + int32_t code = 0; + + res = taos_query(taos, "create database if not exists " TEST_DB " precision 'ns'"); + CHECK_RES(res, "create database"); + taos_free_result(res); + usleep(100000); + + code = taos_select_db(taos, TEST_DB); + CHECK_CODE(code, "switch to database"); + + res = taos_query(taos, "create table if not exists meters(ts timestamp, a int) tags(area int)"); + CHECK_RES(res, "create stable meters"); + taos_free_result(res); + + res = taos_query(taos, "create table if not exists t0 using meters tags(0)"); + CHECK_RES(res, "create table t0"); + taos_free_result(res); + + res = taos_query(taos, "create table if not exists t1 using meters tags(1)"); + CHECK_RES(res, "create table t1"); + taos_free_result(res); + + res = taos_query(taos, "create table if not exists t2 using meters tags(2)"); + CHECK_RES(res, "create table t2"); + taos_free_result(res); + + res = taos_query(taos, "create table if not exists t3 using meters tags(3)"); + CHECK_RES(res, "create table t3"); + taos_free_result(res); + + res = taos_query(taos, "create table if not exists t4 using meters tags(4)"); + CHECK_RES(res, "create table t4"); + taos_free_result(res); + + res = taos_query(taos, "create table if not exists t5 using meters tags(5)"); + CHECK_RES(res, "create table t5"); + taos_free_result(res); + + res = taos_query(taos, "create table if not exists t6 using meters tags(6)"); + CHECK_RES(res, "create table t6"); + taos_free_result(res); + + res = taos_query(taos, "create table if not exists t7 using meters tags(7)"); + CHECK_RES(res, "create table t7"); + taos_free_result(res); + + res = taos_query(taos, "create table if not exists t8 using meters tags(8)"); + CHECK_RES(res, "create table t8"); + taos_free_result(res); + + res = taos_query(taos, "create table if not exists t9 using meters tags(9)"); + CHECK_RES(res, "create table t9"); + taos_free_result(res); + + res = taos_query(taos, + "insert into t0 values('2020-01-01 00:00:00.000', 0)" + " ('2020-01-01 00:01:00.000', 0)" + " ('2020-01-01 00:02:00.000', 0)" + " t1 values('2020-01-01 00:00:00.000', 1)" + " ('2020-01-01 00:01:00.000', 1)" + " ('2020-01-01 00:02:00.000', 1)" + " ('2020-01-01 00:03:00.000', 1)" + " t2 values('2020-01-01 00:00:00.000', 2)" + " ('2020-01-01 00:01:00.000', 2)" + " ('2020-01-01 00:01:01.000', 2)" + " ('2020-01-01 00:01:02.000', 2)" + " t3 values('2020-01-01 00:01:02.000', 3)" + " t4 values('2020-01-01 00:01:02.000', 4)" + " t5 values('2020-01-01 00:01:02.000', 5)" + " t6 values('2020-01-01 00:01:02.000', 6)" + " t7 values('2020-01-01 00:01:02.000', 7)" + " t8 values('2020-01-01 00:01:02.000', 8)" + " t9 values('2020-01-01 00:01:02.000', 9)"); + CHECK_RES(res, "insert into meters"); + CHECK_CONDITION(taos_affected_rows(res), "insert into meters", "insufficient count"); + taos_free_result(res); + + res = taos_query( + taos, + "create table if not exists m1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 " + "double, bin binary(40), blob nchar(10))"); + CHECK_RES(res, "create table m1"); + taos_free_result(res); + + usleep(1000000); +} + +static void verifySchemaLess(TAOS* taos) { + TAOS_RES* res = NULL; + char* lines[] = { + "st,t1=3i64,t2=4f64,t3=L\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000", + "st,t1=4i64,t3=L\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000", + "st,t2=5f64,t3=L\"ste\" c1=4i64,c2=true,c3=L\"iam\" 1626056811823316532", + "st,t1=4i64,t2=5f64,t3=L\"t4\" c1=3i64,c3=L\"passitagain\",c2=true,c4=5f64 1626006833642000000", + "st,t2=5f64,t3=L\"ste2\" c3=L\"iamszhou\",c2=false 1626056811843316532", + "st,t2=5f64,t3=L\"ste2\" c3=L\"iamszhou\",c2=false,c5=5f64,c6=7u64,c7=32i32,c8=88.88f32 1626056812843316532", + "st,t1=4i64,t3=L\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 " + "1626006933640000000", + "st,t1=4i64,t3=L\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 " + "1626006933640000000", + "st,t1=4i64,t3=L\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin_stf\",c2=false,c5=5f64,c6=7u64 " + "1626006933641000000"}; + + res = taos_schemaless_insert_with_reqid(taos, lines, sizeof(lines) / sizeof(char*), TSDB_SML_LINE_PROTOCOL, + TSDB_SML_TIMESTAMP_NANO_SECONDS, CONST_REQ_ID); + CHECK_RES(res, "insert schema-less data"); + printf("successfully inserted %d rows\n", taos_affected_rows(res)); + taos_free_result(res); +} + +static int32_t printResult(TAOS_RES* res, int32_t nlimit) { + TAOS_ROW row = NULL; + TAOS_FIELD* fields = NULL; + int32_t numFields = 0; + int32_t nRows = 0; + + numFields = taos_num_fields(res); + fields = taos_fetch_fields(res); + while ((nlimit-- > 0) && (row = taos_fetch_row(res))) { + char temp[256] = {0}; + taos_print_row(temp, row, fields, numFields); + puts(temp); + nRows++; + } + return nRows; +} + +static void verifyQuery(TAOS* taos) { + TAOS_RES* res = NULL; + + res = taos_query_with_reqid(taos, "select * from meters", CONST_REQ_ID); + CHECK_RES(res, "select from meters"); + printResult(res, INT32_MAX); + taos_free_result(res); + + res = taos_query_with_reqid(taos, "select * from t0", CONST_REQ_ID); + CHECK_RES(res, "select from t0"); + printResult(res, INT32_MAX); + taos_free_result(res); + + res = taos_query_with_reqid(taos, "select * from t1", CONST_REQ_ID); + CHECK_RES(res, "select from t1"); + printResult(res, INT32_MAX); + taos_free_result(res); + + res = taos_query_with_reqid(taos, "select * from t2", CONST_REQ_ID); + CHECK_RES(res, "select from t2"); + printResult(res, INT32_MAX); + taos_free_result(res); + + res = taos_query_with_reqid(taos, "select * from t3", CONST_REQ_ID); + CHECK_RES(res, "select from t3"); + printResult(res, INT32_MAX); + taos_free_result(res); + + printf("succeed to read from meters\n"); +} + +void retrieveCallback(void* param, TAOS_RES* res, int32_t nrows) { + if (nrows == 0) { + taos_free_result(res); + } else { + printResult(res, nrows); + taos_fetch_rows_a(res, retrieveCallback, param); + } +} + +void selectCallback(void* param, TAOS_RES* res, int32_t code) { + CHECK_CODE(code, "read async from table"); + taos_fetch_rows_a(res, retrieveCallback, param); +} + +static void verifyQueryAsync(TAOS* taos) { + taos_query_a_with_reqid(taos, "select *from meters", selectCallback, NULL, CONST_REQ_ID); + taos_query_a_with_reqid(taos, "select *from t0", selectCallback, NULL, CONST_REQ_ID); + taos_query_a_with_reqid(taos, "select *from t1", selectCallback, NULL, CONST_REQ_ID); + taos_query_a_with_reqid(taos, "select *from t2", selectCallback, NULL, CONST_REQ_ID); + taos_query_a_with_reqid(taos, "select *from t3", selectCallback, NULL, CONST_REQ_ID); + + sleep(1); +} + +void veriryStmt(TAOS* taos) { + // insert 10 records + struct { + int64_t ts[10]; + int8_t b[10]; + int8_t v1[10]; + int16_t v2[10]; + int32_t v4[10]; + int64_t v8[10]; + float f4[10]; + double f8[10]; + char bin[10][40]; + char blob[10][80]; + } v; + + int32_t* t8_len = malloc(sizeof(int32_t) * 10); + int32_t* t16_len = malloc(sizeof(int32_t) * 10); + int32_t* t32_len = malloc(sizeof(int32_t) * 10); + int32_t* t64_len = malloc(sizeof(int32_t) * 10); + int32_t* float_len = malloc(sizeof(int32_t) * 10); + int32_t* double_len = malloc(sizeof(int32_t) * 10); + int32_t* bin_len = malloc(sizeof(int32_t) * 10); + int32_t* blob_len = malloc(sizeof(int32_t) * 10); + + TAOS_STMT* stmt = taos_stmt_init_with_reqid(taos, CONST_REQ_ID); + TAOS_MULTI_BIND params[10]; + char is_null[10] = {0}; + + params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + params[0].buffer_length = sizeof(v.ts[0]); + params[0].buffer = v.ts; + params[0].length = t64_len; + params[0].is_null = is_null; + params[0].num = 10; + + params[1].buffer_type = TSDB_DATA_TYPE_BOOL; + params[1].buffer_length = sizeof(v.b[0]); + params[1].buffer = v.b; + params[1].length = t8_len; + params[1].is_null = is_null; + params[1].num = 10; + + params[2].buffer_type = TSDB_DATA_TYPE_TINYINT; + params[2].buffer_length = sizeof(v.v1[0]); + params[2].buffer = v.v1; + params[2].length = t8_len; + params[2].is_null = is_null; + params[2].num = 10; + + params[3].buffer_type = TSDB_DATA_TYPE_SMALLINT; + params[3].buffer_length = sizeof(v.v2[0]); + params[3].buffer = v.v2; + params[3].length = t16_len; + params[3].is_null = is_null; + params[3].num = 10; + + params[4].buffer_type = TSDB_DATA_TYPE_INT; + params[4].buffer_length = sizeof(v.v4[0]); + params[4].buffer = v.v4; + params[4].length = t32_len; + params[4].is_null = is_null; + params[4].num = 10; + + params[5].buffer_type = TSDB_DATA_TYPE_BIGINT; + params[5].buffer_length = sizeof(v.v8[0]); + params[5].buffer = v.v8; + params[5].length = t64_len; + params[5].is_null = is_null; + params[5].num = 10; + + params[6].buffer_type = TSDB_DATA_TYPE_FLOAT; + params[6].buffer_length = sizeof(v.f4[0]); + params[6].buffer = v.f4; + params[6].length = float_len; + params[6].is_null = is_null; + params[6].num = 10; + + params[7].buffer_type = TSDB_DATA_TYPE_DOUBLE; + params[7].buffer_length = sizeof(v.f8[0]); + params[7].buffer = v.f8; + params[7].length = double_len; + params[7].is_null = is_null; + params[7].num = 10; + + params[8].buffer_type = TSDB_DATA_TYPE_BINARY; + params[8].buffer_length = sizeof(v.bin[0]); + params[8].buffer = v.bin; + params[8].length = bin_len; + params[8].is_null = is_null; + params[8].num = 10; + + params[9].buffer_type = TSDB_DATA_TYPE_NCHAR; + params[9].buffer_length = sizeof(v.blob[0]); + params[9].buffer = v.blob; + params[9].length = blob_len; + params[9].is_null = is_null; + params[9].num = 10; + + int32_t code = taos_stmt_prepare( + stmt, "insert into ? (ts, b, v1, v2, v4, v8, f4, f8, bin, blob) values(?,?,?,?,?,?,?,?,?,?)", 0); + CHECK_CODE(code, "taos_stmt_prepare"); + + code = taos_stmt_set_tbname(stmt, "m1"); + CHECK_CODE(code, "taos_stmt_set_tbname"); + + int64_t ts = 1591060628000000000; + for (int i = 0; i < 10; ++i) { + v.ts[i] = ts; + ts += 1000000; + is_null[i] = 0; + + v.b[i] = (int8_t)i % 2; + v.v1[i] = (int8_t)i; + v.v2[i] = (int16_t)(i * 2); + v.v4[i] = (int32_t)(i * 4); + v.v8[i] = (int64_t)(i * 8); + v.f4[i] = (float)(i * 40); + v.f8[i] = (double)(i * 80); + for (int j = 0; j < sizeof(v.bin[0]); ++j) { + v.bin[i][j] = (char)(i + '0'); + } + strcpy(v.blob[i], "一二三四五六七八九十"); + + t8_len[i] = sizeof(int8_t); + t16_len[i] = sizeof(int16_t); + t32_len[i] = sizeof(int32_t); + t64_len[i] = sizeof(int64_t); + float_len[i] = sizeof(float); + double_len[i] = sizeof(double); + bin_len[i] = sizeof(v.bin[0]); + blob_len[i] = (int32_t)strlen(v.blob[i]); + } + + code = taos_stmt_bind_param_batch(stmt, params); + CHECK_CODE(code, "taos_stmt_bind_param_batch"); + + code = taos_stmt_add_batch(stmt); + CHECK_CODE(code, "taos_stmt_add_batch"); + + code = taos_stmt_execute(stmt); + CHECK_CODE(code, "taos_stmt_execute"); + + taos_stmt_close(stmt); + + free(t8_len); + free(t16_len); + free(t32_len); + free(t64_len); + free(float_len); + free(double_len); + free(bin_len); + free(blob_len); +} + +int main(int argc, char* argv[]) { + TAOS* taos = NULL; + int32_t code = 0; + + taos = getNewConnection(); + taos_select_db(taos, TEST_DB); + CHECK_CODE(code, "switch to database"); + + printf("************ prepare data *************\n"); + prepareData(taos); + + for (int32_t i = 0; i < NUM_ROUNDS; ++i) { + printf("************ verify schema-less *************\n"); + verifySchemaLess(taos); + + printf("************ verify query *************\n"); + verifyQuery(taos); + + printf("********* verify async query **********\n"); + verifyQueryAsync(taos); + + printf("********* verify stmt query **********\n"); + veriryStmt(taos); + + printf("done\n"); + } + + taos_close(taos); + taos_cleanup(); + + return 0; +} diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py index 01e416bb26..ccf95db563 100644 --- a/tests/system-test/0-others/information_schema.py +++ b/tests/system-test/0-others/information_schema.py @@ -222,7 +222,7 @@ class TDTestCase: tdSql.query("select * from information_schema.ins_columns where db_name ='information_schema'") tdLog.info(len(tdSql.queryResult)) - tdSql.checkEqual(True, len(tdSql.queryResult) in range(280, 281)) + tdSql.checkEqual(True, len(tdSql.queryResult) in range(282, 283)) tdSql.query("select * from information_schema.ins_columns where db_name ='performance_schema'") tdSql.checkEqual(56, len(tdSql.queryResult)) diff --git a/tests/system-test/0-others/multilevel_createdb.py b/tests/system-test/0-others/multilevel_createdb.py new file mode 100644 index 0000000000..70131a760b --- /dev/null +++ b/tests/system-test/0-others/multilevel_createdb.py @@ -0,0 +1,89 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + + +from util.log import * +from util.cases import * +from util.sql import * +from util.common import * +from util.sqlset import * +import glob + +def scanFiles(pattern): + res = [] + for f in glob.iglob(pattern): + res += [f] + return res + +def checkFiles(pattern, state): + res = scanFiles(pattern) + tdLog.info(res) + num = len(res) + if num: + if state: + tdLog.info("%s: %d files exist. expect: files exist" % (pattern, num)) + else: + tdLog.exit("%s: %d files exist. expect: files not exist." % (pattern, num)) + else: + if state: + tdLog.exit("%s: %d files exist. expect: files exist" % (pattern, num)) + else: + tdLog.info("%s: %d files exist. expect: files not exist." % (pattern, num)) + +class TDTestCase: + def init(self, conn, logSql, replicaVar=1): + + self.replicaVar = int(replicaVar) + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + self.setsql = TDSetSql() + + def basic(self): + tdLog.info("============== basic test ===============") + cfg={ + '/mnt/data1 0 1 0' : 'dataDir', + '/mnt/data2 0 0 0' : 'dataDir', + '/mnt/data3 0 0 0' : 'dataDir', + '/mnt/data4 0 0 0' : 'dataDir' + } + tdSql.createDir('/mnt/data1') + tdSql.createDir('/mnt/data2') + tdSql.createDir('/mnt/data3') + tdSql.createDir('/mnt/data4') + + tdDnodes.stop(1) + tdDnodes.deploy(1,cfg) + tdDnodes.start(1) + + checkFiles(r'/mnt/data1/*/*',1) + checkFiles(r'/mnt/data2/*/*',0) + + tdSql.execute('create database nws vgroups 20 stt_trigger 1 wal_level 1 wal_retention_period 0') + + checkFiles(r'/mnt/data1/vnode/*/wal',5) + checkFiles(r'/mnt/data2/vnode/*/wal',5) + checkFiles(r'/mnt/data3/vnode/*/wal',5) + checkFiles(r'/mnt/data4/vnode/*/wal',5) + + def run(self): + self.basic() + + + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file diff --git a/tests/system-test/0-others/wal_level_skip.py b/tests/system-test/0-others/wal_level_skip.py new file mode 100644 index 0000000000..2105ad0ada --- /dev/null +++ b/tests/system-test/0-others/wal_level_skip.py @@ -0,0 +1,170 @@ +import sys +import taos +import os +from util.log import * +from util.cases import * +from util.sql import * +from util.dnodes import * + +class TDTestCase: + + def init(self, conn, logSql,replicaVar=1): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor()) + + def getBuildPath(self): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + for root, dirs, files in os.walk(projPath): + if ("taosd" in files or "taosd.exe" in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + buildPath = root[:len(root) - len("/build/bin")] + break + return buildPath + + def preData(self): + tdSql.execute("drop database if exists db0;") + tdSql.execute("create database db0 KEEP 30 vgroups 1 buffer 3 wal_level 0;") + tdSql.execute("create table if not exists db0.stb (ts timestamp, c1 int, c2 float, c3 double) tags (t1 int unsigned);") + tdSql.execute("create table db0.ct1 using db0.stb tags(1000);") + tdSql.execute("create table db0.ct2 using db0.stb tags(2000);") + tdSql.execute("create table if not exists db0.ntb (ts timestamp, c1 int, c2 float, c3 double) ;") + tdSql.query("show db0.stables;") + tdSql.execute("insert into db0.ct1 values(now+0s, 10, 2.0, 3.0);") + tdSql.execute("insert into db0.ct1 values(now+1s, 11, 2.1, 3.1)(now+2s, 12, 2.2, 3.2)(now+3s, 13, 2.3, 3.3);") + tdSql.execute("insert into db0.ntb values(now+2s, 10, 2.0, 3.0);") + + def insertData(self): + tdSql.execute("insert into db0.ct1 values(now+0s, 10, 2.0, 3.0);") + tdSql.execute("insert into db0.ct1 values(now+1s, 11, 2.1, 3.1)(now+2s, 12, 2.2, 3.2)(now+3s, 13, 2.3, 3.3);") + tdSql.execute("insert into db0.ntb values(now+2s, 10, 2.0, 3.0);") + + def createSubTableAndInsertData(self): + tdSql.execute("create table db0.ct1 using db0.stb tags(1000);") + tdSql.execute("create table db0.ct2 using db0.stb tags(2000);") + tdSql.execute("create table if not exists db0.ntb (ts timestamp, c1 int, c2 float, c3 double) ;") + tdSql.execute("insert into db0.ct1 values(now+0s, 10, 2.0, 3.0);") + tdSql.execute("insert into db0.ct1 values(now+1s, 11, 2.1, 3.1)(now+2s, 12, 2.2, 3.2)(now+3s, 13, 2.3, 3.3);") + tdSql.execute("insert into db0.ntb values(now+2s, 10, 2.0, 3.0);") + + + def alterWalLevel(self,level): + tdSql.execute("alter database db0 wal_level %d;"%level) + + def run(self): + tdSql.prepare() + + tdLog.info("-----------test for stop taosd before alter wal level-----------") + tdLog.info("create database wal_level = 0 and insert data") + self.preData() + tdDnodes.stop(1) + time.sleep(2) + tdLog.info("restart taosd") + tdDnodes.start(1) + + tdLog.info(" alter wal level from 0 to 1") + self.alterWalLevel(1) + self.insertData() + tdDnodes.stop(1) + tdDnodes.start(1) + + tdLog.info("create database wal_level = 0 and insert data") + self.preData() + tdDnodes.stop(1) + time.sleep(2) + tdLog.info("restart taosd") + tdDnodes.start(1) + + tdLog.info(" alter wal level from 0 to 2") + self.alterWalLevel(2) + self.insertData() + tdDnodes.forcestop(1) + tdDnodes.start(1) + + + tdLog.info("-----------test for kill taosd before alter wal level-----------") + tdLog.info("create database wal_level = 0 and insert data") + self.preData() + tdDnodes.forcestop(1) + time.sleep(2) + tdLog.info("restart taosd") + tdDnodes.start(1) + + tdLog.info(" alter wal level from 0 to 1") + self.alterWalLevel(1) + tdDnodes.forcestop(1) + tdDnodes.start(1) + + tdLog.info("create database wal_level = 0 and insert data") + self.preData() + tdDnodes.forcestop(1) + time.sleep(2) + tdLog.info("restart taosd") + tdDnodes.start(1) + + tdLog.info(" alter wal level from 0 to 2") + self.alterWalLevel(2) + tdDnodes.forcestop(1) + tdDnodes.start(1) + + tdLog.info("-----------test for stop taosd after alter wal level-----------") + tdLog.info("create database wal_level = 0 and insert data") + self.preData() + tdLog.info(" alter wal level from 0 to 1") + self.alterWalLevel(1) + time.sleep(1) + self.insertData() + tdDnodes.stop(1) + time.sleep(2) + tdLog.info("restart taosd") + tdDnodes.start(1) + + + tdLog.info("create database wal_level = 0 and insert data") + self.preData() + tdLog.info(" alter wal level from 0 to 2") + self.alterWalLevel(2) + time.sleep(1) + self.insertData() + tdDnodes.stop(1) + time.sleep(2) + tdLog.info("restart taosd") + tdDnodes.start(1) + + tdLog.info("-----------test for kill taosd after alter wal level-----------") + tdLog.info("create database wal_level = 0 and insert data") + self.preData() + tdLog.info(" alter wal level from 0 to 1") + self.alterWalLevel(1) + time.sleep(1) + self.insertData() + tdDnodes.forcestop(1) + time.sleep(2) + tdLog.info("restart taosd") + tdDnodes.start(1) + + + tdLog.info("create database wal_level = 0 and insert data") + self.preData() + tdLog.info(" alter wal level from 0 to 2") + self.alterWalLevel(2) + time.sleep(1) + self.insertData() + tdDnodes.forcestop(1) + time.sleep(2) + tdLog.info("restart taosd") + tdDnodes.start(1) + + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/agg_group_NotReturnValue.py b/tests/system-test/2-query/agg_group_NotReturnValue.py index 83f0acd362..059a5c5f2e 100755 --- a/tests/system-test/2-query/agg_group_NotReturnValue.py +++ b/tests/system-test/2-query/agg_group_NotReturnValue.py @@ -1590,11 +1590,9 @@ class TDTestCase(TDTestCase): self.modify_tables() tdSql.execute('alter local "countAlwaysReturnValue" "0"') - for i in range(2): - self.tag_count_all() - self.tbname_count_all() - self.tbname_agg_all() - + self.tag_count_all() + self.tbname_count_all() + self.tbname_agg_all() endTime = time.time() print("total time %ds" % (endTime - startTime)) diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py index 2aa01f2c02..5104489592 100644 --- a/tests/system-test/2-query/union.py +++ b/tests/system-test/2-query/union.py @@ -369,8 +369,46 @@ class TDTestCase: ''' ) + def test_TS_5630(self): + sql = "CREATE DATABASE `ep_iot` BUFFER 256 CACHESIZE 20 CACHEMODEL 'both' COMP 2 DURATION 14400m WAL_FSYNC_PERIOD 3000 MAXROWS 4096 MINROWS 100 STT_TRIGGER 2 KEEP 5256000m,5256000m,5256000m PAGES 256 PAGESIZE 4 PRECISION 'ms' REPLICA 1 WAL_LEVEL 1 VGROUPS 3 SINGLE_STABLE 0 TABLE_PREFIX 0 TABLE_SUFFIX 0 TSDB_PAGESIZE 4 WAL_RETENTION_PERIOD 3600 WAL_RETENTION_SIZE 0" + tdSql.execute(sql, queryTimes=1) + tdLog.info("database ep_iot created") + sql = "CREATE STABLE `ep_iot`.`sldc_dp` (`ts` TIMESTAMP, `data_write_time` TIMESTAMP, `jz1fdgl` DOUBLE, `jz1ssfdfh` DOUBLE, `jz1fdmh` DOUBLE, `jz1gdmh` DOUBLE, `jz1qjrhl` DOUBLE, `jz1zhcydl` DOUBLE, `jz1zkby` DOUBLE, `jz1zzqyl` DOUBLE, `jz1zzqwda` DOUBLE, `jz1zzqwdb` DOUBLE, `jz1zzqll` DOUBLE, `jz1gswd` DOUBLE, `jz1gsll` DOUBLE, `jz1glxl` DOUBLE, `jz1qjrh` DOUBLE, `jz1zhrxl` DOUBLE, `jz1gmjassllfk` DOUBLE, `jz1gmjasslllj` DOUBLE, `jz1gmjbssllfk` DOUBLE, `jz1gmjbsslllj` DOUBLE, `jz1gmjcssllfk` DOUBLE, `jz1gmjcsslllj` DOUBLE, `jz1gmjdssllfk` DOUBLE, `jz1gmjdsslllj` DOUBLE, `jz1gmjessllfk` DOUBLE, `jz1gmjesslllj` DOUBLE, `jz1gmjfssllfk` DOUBLE, `jz1gmjfsslllj` DOUBLE, `jz1zrqwda` DOUBLE, `jz1zrqwdb` DOUBLE, `jz1zrzqyl` DOUBLE, `jz1mmjadl` DOUBLE, `jz1mmjbdl` DOUBLE, `jz1mmjcdl` DOUBLE, `jz1mmjddl` DOUBLE, `jz1mmjedl` DOUBLE, `jz1mmjfdl` DOUBLE, `jz1cyqckwda` DOUBLE, `jz1cyqckwdb` DOUBLE, `jz1njswd` DOUBLE, `jz1nqqxhsckawd` DOUBLE, `jz1nqqxhsckbwd` DOUBLE, `jz1nqqxhsrkawd` DOUBLE, `jz1nqqxhsrkbwd` DOUBLE, `jz1kyqackyqwdsel` DOUBLE, `jz1kyqbckyqwdsel` DOUBLE, `jz1yfjackyqwd` DOUBLE, `jz1yfjbckyqwd` DOUBLE, `jz1trkyqwd` DOUBLE, `jz1trkyqwd1` DOUBLE, `jz1trkyqwd2` DOUBLE, `jz1trkyqwd3` DOUBLE, `jz1tckjyqwd1` DOUBLE, `jz1tckjyqwd2` DOUBLE, `jz1tckyqwd1` DOUBLE, `jz1bya` DOUBLE, `jz1byb` DOUBLE, `jz1pqwda` DOUBLE, `jz1pqwdb` DOUBLE, `jz1gmjadl` DOUBLE, `jz1gmjbdl` DOUBLE, `jz1gmjcdl` DOUBLE, `jz1gmjddl` DOUBLE, `jz1gmjedl` DOUBLE, `jz1gmjfdl` DOUBLE, `jz1yfjadl` DOUBLE, `jz1yfjbdl` DOUBLE, `jz1ycfjadl` DOUBLE, `jz1ycfjbdl` DOUBLE, `jz1sfjadl` DOUBLE, `jz1sfjbdl` DOUBLE, `jz1fdjyggl` DOUBLE, `jz1fdjwggl` DOUBLE, `jz1sjzs` DOUBLE, `jz1zfl` DOUBLE, `jz1ltyl` DOUBLE, `jz1smb` DOUBLE, `jz1rll` DOUBLE, `jz1grd` DOUBLE, `jz1zjwd` DOUBLE, `jz1yl` DOUBLE, `jz1kyqckwd` DOUBLE, `jz1abmfsybrkcy` DOUBLE, `jz1bbmfsybrkcy` DOUBLE, `jz1abjcsdmfytwdzdz` DOUBLE, `jz1bbjcsdmfytwdzdz` DOUBLE, `jz2fdgl` DOUBLE, `jz2ssfdfh` DOUBLE, `jz2fdmh` DOUBLE, `jz2gdmh` DOUBLE, `jz2qjrhl` DOUBLE, `jz2zhcydl` DOUBLE, `jz2zkby` DOUBLE, `jz2zzqyl` DOUBLE, `jz2zzqwda` DOUBLE, `jz2zzqwdb` DOUBLE, `jz2zzqll` DOUBLE, `jz2gswd` DOUBLE, `jz2gsll` DOUBLE, `jz2glxl` DOUBLE, `jz2qjrh` DOUBLE, `jz2zhrxl` DOUBLE, `jz2gmjassllfk` DOUBLE, `jz2gmjasslllj` DOUBLE, `jz2gmjbssllfk` DOUBLE, `jz2gmjbsslllj` DOUBLE, `jz2gmjcssllfk` DOUBLE, `jz2gmjcsslllj` DOUBLE, `jz2gmjdssllfk` DOUBLE, `jz2gmjdsslllj` DOUBLE, `jz2gmjessllfk` DOUBLE, `jz2gmjesslllj` DOUBLE, `jz2gmjfssllfk` DOUBLE, `jz2gmjfsslllj` DOUBLE, `jz2zrqwda` DOUBLE, `jz2zrqwdb` DOUBLE, `jz2zrzqyl` DOUBLE, `jz2mmjadl` DOUBLE, `jz2mmjbdl` DOUBLE, `jz2mmjcdl` DOUBLE, `jz2mmjddl` DOUBLE, `jz2mmjedl` DOUBLE, `jz2mmjfdl` DOUBLE, `jz2cyqckwda` DOUBLE, `jz2cyqckwdb` DOUBLE, `jz2njswd` DOUBLE, `jz2nqqxhsckawd` DOUBLE, `jz2nqqxhsckbwd` DOUBLE, `jz2nqqxhsrkawd` DOUBLE, `jz2nqqxhsrkbwd` DOUBLE, `jz2kyqackyqwdsel` DOUBLE, `jz2kyqbckyqwdsel` DOUBLE, `jz2yfjackyqwd` DOUBLE, `jz2yfjbckyqwd` DOUBLE, `jz2trkyqwd` DOUBLE, `jz2trkyqwd1` DOUBLE, `jz2trkyqwd2` DOUBLE, `jz2trkyqwd3` DOUBLE, `jz2tckjyqwd1` DOUBLE, `jz2tckjyqwd2` DOUBLE, `jz2tckyqwd1` DOUBLE, `jz2bya` DOUBLE, `jz2byb` DOUBLE, `jz2pqwda` DOUBLE, `jz2pqwdb` DOUBLE, `jz2gmjadl` DOUBLE, `jz2gmjbdl` DOUBLE, `jz2gmjcdl` DOUBLE, `jz2gmjddl` DOUBLE, `jz2gmjedl` DOUBLE, `jz2gmjfdl` DOUBLE, `jz2yfjadl` DOUBLE, `jz2yfjbdl` DOUBLE, `jz2ycfjadl` DOUBLE, `jz2ycfjbdl` DOUBLE, `jz2sfjadl` DOUBLE, `jz2sfjbdl` DOUBLE, `jz2fdjyggl` DOUBLE, `jz2fdjwggl` DOUBLE, `jz2sjzs` DOUBLE, `jz2zfl` DOUBLE, `jz2ltyl` DOUBLE, `jz2smb` DOUBLE, `jz2rll` DOUBLE, `jz2grd` DOUBLE, `jz2zjwd` DOUBLE, `jz2yl` DOUBLE, `jz2kyqckwd` DOUBLE, `jz2abmfsybrkcy` DOUBLE, `jz2bbmfsybrkcy` DOUBLE, `jz2abjcsdmfytwdzdz` DOUBLE, `jz2bbjcsdmfytwdzdz` DOUBLE) TAGS (`iot_hub_id` VARCHAR(100), `device_group_code` VARCHAR(100), `device_code` VARCHAR(100))" + tdLog.info("stable ep_iot.sldc_dp created") + tdSql.execute(sql, queryTimes=1) + sql = "insert into ep_iot.sldc_dp_t1 using ep_iot.sldc_dp tags('a','a','a') values(now, now, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9,0,1);" + tdSql.execute(sql, queryTimes=1) + sql = "insert into ep_iot.sldc_dp_t1 using ep_iot.sldc_dp tags('b','b','b') values(now, now, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9,0,1);" + tdSql.execute(sql, queryTimes=1) + sql = "insert into ep_iot.sldc_dp_t1 using ep_iot.sldc_dp tags('c','c','c') values(now, now, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9,0,1);" + tdSql.execute(sql, queryTimes=1) + sql = "insert into ep_iot.sldc_dp_t1 using ep_iot.sldc_dp tags('d','d','d') values(now, now, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9,0,1);" + tdSql.execute(sql, queryTimes=1) + sql = "insert into ep_iot.sldc_dp_t1 using ep_iot.sldc_dp tags('e','e','e') values(now, now, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9,0,1);" + tdSql.execute(sql, queryTimes=1) + sql = "select scdw_code, scdw_name, jzmc, fdgl, jzzt from ((select '01072016' as scdw_code, '盛鲁电厂' as scdw_name, '机组1' as jzmc, last(jz1fdjyggl) as fdgl, '填报' as jzzt, last(ts) as ts from ep_iot.sldc_dp) union all ( select '01072016' as scdw_code, '盛鲁电厂' as scdw_name, '机组2' as jzmc, last(jz2fdjyggl) as fdgl, '填报' as jzzt, last(ts) as ts from ep_iot.sldc_dp) union all ( select '00103673' as scdw_code, '鲁西电厂' as scdw_name, '机组1'as jzmc, last(jz1fdjyggl) as fdgl, '填报' as jzzt, last(ts) as ts from ep_iot.sldc_dp) union all ( select '00103673' as scdw_code, '鲁西电厂' as scdw_name, '机组2'as jzmc, last(jz2fdjyggl) as fdgl, '填报' as jzzt, last(ts) as ts from ep_iot.sldc_dp) union all ( select '01061584' as scdw_code, '富源热电' as scdw_name, '机组1'as jzmc, last(jz1fdjyggl) as fdgl, '填报' as jzzt ,last(ts) as ts from ep_iot.sldc_dp) union all ( select '01061584' as scdw_code, '富源热电' as scdw_name, '机组2'as jzmc, last(jz2fdjyggl) as fdgl, '填报' as jzzt ,last(ts) as ts from ep_iot.sldc_dp)) where scdw_code like '%%';" + tdSql.query(sql, queryTimes=1) + tdSql.checkCols(5) + tdSql.checkRows(6) + + sql = "select scdw_name, scdw_code, jzmc, fdgl, jzzt from ((select '01072016' as scdw_code, '盛鲁电厂' as scdw_name, '机组1' as jzmc, last(jz1fdjyggl) as fdgl, '填报' as jzzt, last(ts) as ts from ep_iot.sldc_dp) union all ( select '01072016' as scdw_code, '盛鲁电厂' as scdw_name, '机组2' as jzmc, last(jz2fdjyggl) as fdgl, '填报' as jzzt, last(ts) as ts from ep_iot.sldc_dp) union all ( select '00103673' as scdw_code, '鲁西电厂' as scdw_name, '机组1'as jzmc, last(jz1fdjyggl) as fdgl, '填报' as jzzt, last(ts) as ts from ep_iot.sldc_dp) union all ( select '00103673' as scdw_code, '鲁西电厂' as scdw_name, '机组2'as jzmc, last(jz2fdjyggl) as fdgl, '填报' as jzzt, last(ts) as ts from ep_iot.sldc_dp) union all ( select '01061584' as scdw_code, '富源热电' as scdw_name, '机组1'as jzmc, last(jz1fdjyggl) as fdgl, '填报' as jzzt ,last(ts) as ts from ep_iot.sldc_dp) union all ( select '01061584' as scdw_code, '富源热电' as scdw_name, '机组2'as jzmc, last(jz2fdjyggl) as fdgl, '填报' as jzzt ,last(ts) as ts from ep_iot.sldc_dp)) where scdw_code like '%%';" + tdSql.query(sql, queryTimes=1) + tdSql.checkCols(5) + tdSql.checkRows(6) + sql = "select scdw_name, scdw_code, jzzt from ((select '01072016' as scdw_code, '盛鲁电厂' as scdw_name, '机组1' as jzmc, last(jz1fdjyggl) as fdgl, '填报' as jzzt, last(ts) as ts from ep_iot.sldc_dp) union all ( select '01072016' as scdw_code, '盛鲁电厂' as scdw_name, '机组2' as jzmc, last(jz2fdjyggl) as fdgl, '填报' as jzzt, last(ts) as ts from ep_iot.sldc_dp) union all ( select '00103673' as scdw_code, '鲁西电厂' as scdw_name, '机组1'as jzmc, last(jz1fdjyggl) as fdgl, '填报' as jzzt, last(ts) as ts from ep_iot.sldc_dp) union all ( select '00103673' as scdw_code, '鲁西电厂' as scdw_name, '机组2'as jzmc, last(jz2fdjyggl) as fdgl, '填报' as jzzt, last(ts) as ts from ep_iot.sldc_dp) union all ( select '01061584' as scdw_code, '富源热电' as scdw_name, '机组1'as jzmc, last(jz1fdjyggl) as fdgl, '填报' as jzzt ,last(ts) as ts from ep_iot.sldc_dp) union all ( select '01061584' as scdw_code, '富源热电' as scdw_name, '机组2'as jzmc, last(jz2fdjyggl) as fdgl, '填报' as jzzt ,last(ts) as ts from ep_iot.sldc_dp)) where scdw_code like '%%';" + tdSql.query(sql, queryTimes=1) + tdSql.checkRows(6) + tdSql.checkCols(3) + + sql = "select scdw_code, scdw_name, jzmc, fdgl, jzzt,ts from ((select '01072016' as scdw_code, '盛鲁电厂' as scdw_name, '机组1' as jzmc, last(jz1fdjyggl) as fdgl, '填报' as jzzt, last(ts) as ts from ep_iot.sldc_dp) union all ( select '01072016' as scdw_code, '盛鲁电厂' as scdw_name, '机组2' as jzmc, last(jz2fdjyggl) as fdgl, '填报' as jzzt, last(ts) as ts from ep_iot.sldc_dp) union all ( select '00103673' as scdw_code, '鲁西电厂' as scdw_name, '机组1'as jzmc, last(jz1fdjyggl) as fdgl, '填报' as jzzt, last(ts) as ts from ep_iot.sldc_dp) union all ( select '00103673' as scdw_code, '鲁西电厂' as scdw_name, '机组2'as jzmc, last(jz2fdjyggl) as fdgl, '填报' as jzzt, last(ts) as ts from ep_iot.sldc_dp) union all ( select '01061584' as scdw_code, '富源热电' as scdw_name, '机组1'as jzmc, last(jz1fdjyggl) as fdgl, '填报' as jzzt ,last(ts) as ts from ep_iot.sldc_dp) union all ( select '01061584' as scdw_code, '富源热电' as scdw_name, '机组2'as jzmc, last(jz2fdjyggl) as fdgl, '填报' as jzzt ,last(ts) as ts from ep_iot.sldc_dp)) where scdw_code like '%%';" + tdSql.query(sql, queryTimes=1) + tdSql.checkCols(6) + tdSql.checkRows(6) + ##tdSql.execute("drop database ep_iot") + def run(self): tdSql.prepare() + self.test_TS_5630() tdLog.printNoPrefix("==========step1:create table") self.__create_tb() diff --git a/tests/system-test/99-TDcase/TS-5580.py b/tests/system-test/99-TDcase/TS-5580.py new file mode 100644 index 0000000000..84dd44c3b0 --- /dev/null +++ b/tests/system-test/99-TDcase/TS-5580.py @@ -0,0 +1,118 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import time +from util.log import * +from util.cases import * +from util.sql import * +from util.common import * +from util.sqlset import * + +class TDTestCase: + updatecfgDict = {'qDebugFlag':135 , 'mDebugFlag':135} + + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), True) + self.setsql = TDSetSql() + self.dbname = 'db' + self.stbname = 'stb' + self.binary_length = 20 # the length of binary for column_dict + self.nchar_length = 20 # the length of nchar for column_dict + self.ts = 1537146000000 + self.column_dict = { + 'ts' : 'timestamp', + 'col1': 'tinyint', + 'col2': 'smallint', + 'col3': 'int', + 'col4': 'bigint', + 'col5': 'float', + 'col6': 'double', + 'col7': 'double', + 'col8': 'double', + 'col9': 'double', + 'col10': 'double', + 'col11': 'double', + 'col12': 'double', + 'col13': 'double', + 'col14': 'double', + 'col15': 'double', + 'col16': 'double', + 'col17': 'double', + 'col18': 'double', + 'col19': 'double' + } + self.tbnum = 500 + self.rowNum = 10 + self.tag_dict = { + 't0':'int', + 't1':'bigint', + 't2':'float', + 't3':'double', + 't4':'bool', + 't5':'bool', + 't6':'bool', + 't7':'bool', + 't8':'bool', + 't9':'bool', + 't10':'bool', + 't11':'bool', + 't12':'bool', + 't13':'bool', + 't14':'bool', + 't15':'bool', + 't16':'bool', + 't17':'bool', + 't18':'bool', + 't19':'bool', + } + self.tag_values = [ + f'1','1','1','1','true','true','true','true','true','true','true','true','true','true','true','true','true', + 'true','true','true' + ] + def prepare_data(self): + tdSql.execute(f"create database if not exists {self.dbname} vgroups 2") + tdSql.execute(f'use {self.dbname}') + tdSql.execute(self.setsql.set_create_stable_sql(self.stbname,self.column_dict,self.tag_dict)) + for i in range(self.tbnum): + tdSql.execute(f"create table {self.stbname}_{i} using {self.stbname} tags({self.tag_values[0]}, {self.tag_values[1]}, " + f"{self.tag_values[2]}, {self.tag_values[3]}, {self.tag_values[4]}, {self.tag_values[5]}, " + f"{self.tag_values[6]}, {self.tag_values[7]}, {self.tag_values[8]}, {self.tag_values[9]}, " + f"{self.tag_values[10]}, {self.tag_values[11]}, {self.tag_values[12]}, {self.tag_values[13]}, " + f"{self.tag_values[14]}, {self.tag_values[15]}, {self.tag_values[16]}, {self.tag_values[17]}, " + f"{self.tag_values[18]}, {self.tag_values[19]})") + + def test_query_ins_tags(self): + for i in range(self.tbnum): + sql = f'select tag_name, tag_value from information_schema.ins_tags where table_name = "{self.stbname}_{i}"' + tdSql.query(sql) + tdSql.checkRows(20) + + def test_query_ins_columns(self): + for i in range(self.tbnum): + sql = f'select col_name from information_schema.ins_columns where table_name = "{self.stbname}_{i}"' + tdSql.query(sql) + tdSql.checkRows(20) + def run(self): + self.prepare_data() + self.test_query_ins_tags() + self.test_query_ins_columns() + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/test.py b/tests/system-test/test.py index fb3357a2b9..0d40544be8 100644 --- a/tests/system-test/test.py +++ b/tests/system-test/test.py @@ -689,6 +689,9 @@ if __name__ == "__main__": if conn is not None: conn.close() if asan: - #tdDnodes.StopAllSigint() + # tdDnodes.StopAllSigint() tdLog.info("Address sanitizer mode finished") + else: + tdDnodes.stopAll() + tdLog.info("stop all td process finished") sys.exit(0) diff --git a/tools/keeper/go.mod b/tools/keeper/go.mod index f520ceb774..f8edf2709b 100644 --- a/tools/keeper/go.mod +++ b/tools/keeper/go.mod @@ -21,38 +21,39 @@ require ( require ( github.com/beorn7/perks v1.0.1 // indirect - github.com/bytedance/sonic v1.9.1 // indirect + github.com/bytedance/sonic v1.11.2 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect - github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect + github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect + github.com/chenzhuoyu/iasm v0.9.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/fsnotify/fsnotify v1.5.4 // indirect - github.com/gabriel-vasile/mimetype v1.4.2 // indirect - github.com/gin-contrib/cors v1.3.1 // indirect + github.com/gabriel-vasile/mimetype v1.4.3 // indirect + github.com/gin-contrib/cors v1.6.0 // indirect github.com/gin-contrib/gzip v0.0.3 // indirect github.com/gin-contrib/pprof v1.3.0 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-ole/go-ole v1.2.6 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.14.0 // indirect + github.com/go-playground/validator/v10 v10.19.0 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/google/uuid v1.3.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/klauspost/cpuid/v2 v2.2.4 // indirect - github.com/leodido/go-urn v1.2.4 // indirect + github.com/klauspost/cpuid/v2 v2.2.7 // indirect + github.com/leodido/go-urn v1.4.0 // indirect github.com/lestrrat-go/strftime v1.0.6 // indirect github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect github.com/magiconair/properties v1.8.6 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml v1.9.5 // indirect - github.com/pelletier/go-toml/v2 v2.0.8 // indirect + github.com/pelletier/go-toml/v2 v2.1.1 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect @@ -66,14 +67,14 @@ require ( github.com/tklauser/go-sysconf v0.3.10 // indirect github.com/tklauser/numcpus v0.4.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect - github.com/ugorji/go/codec v1.2.11 // indirect + github.com/ugorji/go/codec v1.2.12 // indirect github.com/yusufpapurcu/wmi v1.2.2 // indirect - golang.org/x/arch v0.3.0 // indirect - golang.org/x/crypto v0.9.0 // indirect - golang.org/x/net v0.10.0 // indirect + golang.org/x/arch v0.7.0 // indirect + golang.org/x/crypto v0.21.0 // indirect + golang.org/x/net v0.23.0 // indirect golang.org/x/sys v0.24.0 // indirect - golang.org/x/text v0.9.0 // indirect - google.golang.org/protobuf v1.30.0 // indirect + golang.org/x/text v0.14.0 // indirect + google.golang.org/protobuf v1.33.0 // indirect gopkg.in/ini.v1 v1.66.4 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/tools/keeper/go.sum b/tools/keeper/go.sum index 9c7721c4d7..8f6e9bd13a 100644 --- a/tools/keeper/go.sum +++ b/tools/keeper/go.sum @@ -52,15 +52,20 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= -github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= -github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= +github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= +github.com/bytedance/sonic v1.11.2 h1:ywfwo0a/3j9HR8wsYGWsIWl2mvRsI950HyoxiBERw5A= +github.com/bytedance/sonic v1.11.2/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= -github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= +github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0= +github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA= +github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= +github.com/chenzhuoyu/iasm v0.9.1 h1:tUHQJXo3NhBqw6s33wkGn9SP3bvrWLdlVIJ3hQBL7P0= +github.com/chenzhuoyu/iasm v0.9.1/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= @@ -88,10 +93,11 @@ github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= -github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= -github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= -github.com/gin-contrib/cors v1.3.1 h1:doAsuITavI4IOcd0Y19U4B+O0dNWihRyX//nn4sEmgA= +github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= +github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/gin-contrib/cors v1.3.1/go.mod h1:jjEJ4268OPZUcU7k9Pm653S7lXUGcqMADzFA61xsmDk= +github.com/gin-contrib/cors v1.6.0 h1:0Z7D/bVhE6ja07lI8CTjTonp6SB07o8bNuFyRbsBUQg= +github.com/gin-contrib/cors v1.6.0/go.mod h1:cI+h6iOAyxKRtUtC6iF/Si1KSFvGm/gK+kshxlCi8ro= github.com/gin-contrib/gzip v0.0.3 h1:etUaeesHhEORpZMp18zoOhepboiWnFtXrBZxszWUn4k= github.com/gin-contrib/gzip v0.0.3/go.mod h1:YxxswVZIqOvcHEQpsSn+QF5guQtO1dCfy0shBPy4jFc= github.com/gin-contrib/pprof v1.3.0 h1:G9eK6HnbkSqDZBYbzG4wrjCsA4e+cvYAHUZw6W+W9K0= @@ -127,8 +133,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= -github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= -github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= +github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4= +github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= @@ -235,8 +241,9 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o github.com/klauspost/compress v1.12.2/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= -github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= +github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= +github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= @@ -250,8 +257,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= -github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= -github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc h1:RKf14vYWi2ttpEmkA4aQ3j4u9dStX2t4M8UM6qqNsG8= github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is= github.com/lestrrat-go/strftime v1.0.6 h1:CFGsDEt1pOpFNU+TJB0nhz9jl+K0hZSLE205AhTIGQQ= @@ -262,8 +269,8 @@ github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamh github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI= github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= @@ -290,8 +297,8 @@ github.com/panjf2000/ants/v2 v2.4.6 h1:drmj9mcygn2gawZ155dRbo+NfXEfAssjZNU1qoIb4 github.com/panjf2000/ants/v2 v2.4.6/go.mod h1:f6F0NZVFsGCp5A7QW/Zj/m92atWwOkY0OIhFxRNFr4A= github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8= github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= -github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= -github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= +github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI= +github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/pierrec/lz4 v2.6.0+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -330,7 +337,7 @@ github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1 github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= +github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= github.com/shirou/gopsutil/v3 v3.22.4 h1:srAQaiX6jX/cYL6q29aE0m8lOskT9CurZ9N61YR3yoI= github.com/shirou/gopsutil/v3 v3.22.4/go.mod h1:D01hZJ4pVHPpCTZ3m3T2+wDF2YAGfd+H4ifUguaQzHM= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= @@ -363,8 +370,7 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.3.0 h1:mjC+YW8QpAdXibNi+vNWgzmgBH4+5l5dCXv8cNysBLI= @@ -387,8 +393,8 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= -github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= -github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= +github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/xdg/scram v1.0.3/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I= github.com/xdg/stringprep v1.0.3/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -404,8 +410,8 @@ go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= -golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= -golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc= +golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -418,8 +424,8 @@ golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= -golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -489,8 +495,8 @@ golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= +golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -565,7 +571,7 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= @@ -577,8 +583,8 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -725,8 +731,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= -google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -758,6 +764,7 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=