merge 3.0
This commit is contained in:
commit
52b4b510a8
|
@ -2,7 +2,7 @@
|
|||
# taos-tools
|
||||
ExternalProject_Add(taos-tools
|
||||
GIT_REPOSITORY https://github.com/taosdata/taos-tools.git
|
||||
GIT_TAG cc973e0
|
||||
GIT_TAG bc99376
|
||||
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taos-tools"
|
||||
BINARY_DIR ""
|
||||
#BUILD_IN_SOURCE TRUE
|
||||
|
|
|
@ -40,25 +40,25 @@ ALTER ALL DNODES dnode_option
|
|||
|
||||
dnode_option: {
|
||||
'resetLog'
|
||||
| 'balance' value
|
||||
| 'monitor' value
|
||||
| 'debugFlag' value
|
||||
| 'monDebugFlag' value
|
||||
| 'vDebugFlag' value
|
||||
| 'mDebugFlag' value
|
||||
| 'cDebugFlag' value
|
||||
| 'httpDebugFlag' value
|
||||
| 'qDebugflag' value
|
||||
| 'sdbDebugFlag' value
|
||||
| 'uDebugFlag' value
|
||||
| 'tsdbDebugFlag' value
|
||||
| 'sDebugflag' value
|
||||
| 'rpcDebugFlag' value
|
||||
| 'dDebugFlag' value
|
||||
| 'mqttDebugFlag' value
|
||||
| 'wDebugFlag' value
|
||||
| 'tmrDebugFlag' value
|
||||
| 'cqDebugFlag' value
|
||||
| 'balance' 'value'
|
||||
| 'monitor' 'value'
|
||||
| 'debugFlag' 'value'
|
||||
| 'monDebugFlag' 'value'
|
||||
| 'vDebugFlag' 'value'
|
||||
| 'mDebugFlag' 'value'
|
||||
| 'cDebugFlag' 'value'
|
||||
| 'httpDebugFlag' 'value'
|
||||
| 'qDebugflag' 'value'
|
||||
| 'sdbDebugFlag' 'value'
|
||||
| 'uDebugFlag' 'value'
|
||||
| 'tsdbDebugFlag' 'value'
|
||||
| 'sDebugflag' 'value'
|
||||
| 'rpcDebugFlag' 'value'
|
||||
| 'dDebugFlag' 'value'
|
||||
| 'mqttDebugFlag' 'value'
|
||||
| 'wDebugFlag' 'value'
|
||||
| 'tmrDebugFlag' 'value'
|
||||
| 'cqDebugFlag' 'value'
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -127,11 +127,11 @@ ALTER LOCAL local_option
|
|||
|
||||
local_option: {
|
||||
'resetLog'
|
||||
| 'rpcDebugFlag' value
|
||||
| 'tmrDebugFlag' value
|
||||
| 'cDebugFlag' value
|
||||
| 'uDebugFlag' value
|
||||
| 'debugFlag' value
|
||||
| 'rpcDebugFlag' 'value'
|
||||
| 'tmrDebugFlag' 'value'
|
||||
| 'cDebugFlag' 'value'
|
||||
| 'uDebugFlag' 'value'
|
||||
| 'debugFlag' 'value'
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ The following return value results indicate that the verification passed.
|
|||
## HTTP request URL format
|
||||
|
||||
```text
|
||||
http://<fqdn>:<port>/rest/sql/[db_name]
|
||||
http://<fqdn>:<port>/rest/sql/[db_name][?tz=timezone]
|
||||
```
|
||||
|
||||
Parameter Description:
|
||||
|
@ -75,6 +75,7 @@ Parameter Description:
|
|||
- fqnd: FQDN or IP address of any host in the cluster.
|
||||
- port: httpPort configuration item in the configuration file, default is 6041.
|
||||
- db_name: Optional parameter that specifies the default database name for the executed SQL command.
|
||||
- tz: Optional parameter that specifies the timezone of the returned time, following the IANA Time Zone rules, e.g. `America/New_York`.
|
||||
|
||||
For example, `http://h1.taos.com:6041/rest/sql/test` is a URL to `h1.taos.com:6041` and sets the default database name to `test`.
|
||||
|
||||
|
@ -97,13 +98,13 @@ The HTTP request's BODY is a complete SQL command, and the data table in the SQL
|
|||
Use `curl` to initiate an HTTP request with a custom authentication method, with the following syntax.
|
||||
|
||||
```bash
|
||||
curl -L -H "Authorization: Basic <TOKEN>" -d "<SQL>" <ip>:<PORT>/rest/sql/[db_name]
|
||||
curl -L -H "Authorization: Basic <TOKEN>" -d "<SQL>" <ip>:<PORT>/rest/sql/[db_name][?tz=timezone]
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```bash
|
||||
curl -L -u username:password -d "<SQL>" <ip>:<PORT>/rest/sql/[db_name]
|
||||
curl -L -u username:password -d "<SQL>" <ip>:<PORT>/rest/sql/[db_name][?tz=timezone]
|
||||
```
|
||||
|
||||
where `TOKEN` is the string after Base64 encoding of `{username}:{password}`, e.g. `root:taosdata` is encoded as `cm9vdDp0YW9zZGF0YQ==`..
|
||||
|
|
|
@ -106,11 +106,11 @@ ALTER LOCAL local_option
|
|||
|
||||
local_option: {
|
||||
'resetLog'
|
||||
| 'rpcDebugFlag' value
|
||||
| 'tmrDebugFlag' value
|
||||
| 'cDebugFlag' value
|
||||
| 'uDebugFlag' value
|
||||
| 'debugFlag' value
|
||||
| 'rpcDebugFlag' 'value'
|
||||
| 'tmrDebugFlag' 'value'
|
||||
| 'cDebugFlag' 'value'
|
||||
| 'uDebugFlag' 'value'
|
||||
| 'debugFlag' 'value'
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ curl -L -H "Authorization: Basic cm9vdDp0YW9zZGF0YQ==" \
|
|||
## HTTP 请求格式
|
||||
|
||||
```text
|
||||
http://<fqdn>:<port>/rest/sql/[db_name]
|
||||
http://<fqdn>:<port>/rest/sql/[db_name][?tz=timezone]
|
||||
```
|
||||
|
||||
参数说明:
|
||||
|
@ -77,6 +77,7 @@ http://<fqdn>:<port>/rest/sql/[db_name]
|
|||
- fqdn: 集群中的任一台主机 FQDN 或 IP 地址。
|
||||
- port: 配置文件中 httpPort 配置项,缺省为 6041。
|
||||
- db_name: 可选参数,指定本次所执行的 SQL 语句的默认数据库库名。
|
||||
- tz: 可选参数,指定返回时间的时区,遵照 IANA Time Zone 规则,如 `America/New_York`。
|
||||
|
||||
例如:`http://h1.taos.com:6041/rest/sql/test` 是指向地址为 `h1.taos.com:6041` 的 URL,并将默认使用的数据库库名设置为 `test`。
|
||||
|
||||
|
@ -99,13 +100,13 @@ HTTP 请求的 BODY 里就是一个完整的 SQL 语句,SQL 语句中的数据
|
|||
使用 `curl` 通过自定义身份认证方式来发起一个 HTTP Request,语法如下:
|
||||
|
||||
```bash
|
||||
curl -L -H "Authorization: Basic <TOKEN>" -d "<SQL>" <ip>:<PORT>/rest/sql/[db_name]
|
||||
curl -L -H "Authorization: Basic <TOKEN>" -d "<SQL>" <ip>:<PORT>/rest/sql/[db_name][?tz=timezone]
|
||||
```
|
||||
|
||||
或者,
|
||||
|
||||
```bash
|
||||
curl -L -u username:password -d "<SQL>" <ip>:<PORT>/rest/sql/[db_name]
|
||||
curl -L -u username:password -d "<SQL>" <ip>:<PORT>/rest/sql/[db_name][?tz=timezone]
|
||||
```
|
||||
|
||||
其中,`TOKEN` 为 `{username}:{password}` 经过 Base64 编码之后的字符串,例如 `root:taosdata` 编码后为 `cm9vdDp0YW9zZGF0YQ==`。
|
||||
|
|
|
@ -41,25 +41,25 @@ ALTER ALL DNODES dnode_option
|
|||
|
||||
dnode_option: {
|
||||
'resetLog'
|
||||
| 'balance' value
|
||||
| 'monitor' value
|
||||
| 'debugFlag' value
|
||||
| 'monDebugFlag' value
|
||||
| 'vDebugFlag' value
|
||||
| 'mDebugFlag' value
|
||||
| 'cDebugFlag' value
|
||||
| 'httpDebugFlag' value
|
||||
| 'qDebugflag' value
|
||||
| 'sdbDebugFlag' value
|
||||
| 'uDebugFlag' value
|
||||
| 'tsdbDebugFlag' value
|
||||
| 'sDebugflag' value
|
||||
| 'rpcDebugFlag' value
|
||||
| 'dDebugFlag' value
|
||||
| 'mqttDebugFlag' value
|
||||
| 'wDebugFlag' value
|
||||
| 'tmrDebugFlag' value
|
||||
| 'cqDebugFlag' value
|
||||
| 'balance' 'value'
|
||||
| 'monitor' 'value'
|
||||
| 'debugFlag' 'value'
|
||||
| 'monDebugFlag' 'value'
|
||||
| 'vDebugFlag' 'value'
|
||||
| 'mDebugFlag' 'value'
|
||||
| 'cDebugFlag' 'value'
|
||||
| 'httpDebugFlag' 'value'
|
||||
| 'qDebugflag' 'value'
|
||||
| 'sdbDebugFlag' 'value'
|
||||
| 'uDebugFlag' 'value'
|
||||
| 'tsdbDebugFlag' 'value'
|
||||
| 'sDebugflag' 'value'
|
||||
| 'rpcDebugFlag' 'value'
|
||||
| 'dDebugFlag' 'value'
|
||||
| 'mqttDebugFlag' 'value'
|
||||
| 'wDebugFlag' 'value'
|
||||
| 'tmrDebugFlag' 'value'
|
||||
| 'cqDebugFlag' 'value'
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -128,11 +128,11 @@ ALTER LOCAL local_option
|
|||
|
||||
local_option: {
|
||||
'resetLog'
|
||||
| 'rpcDebugFlag' value
|
||||
| 'tmrDebugFlag' value
|
||||
| 'cDebugFlag' value
|
||||
| 'uDebugFlag' value
|
||||
| 'debugFlag' value
|
||||
| 'rpcDebugFlag' 'value'
|
||||
| 'tmrDebugFlag' 'value'
|
||||
| 'cDebugFlag' 'value'
|
||||
| 'uDebugFlag' 'value'
|
||||
| 'debugFlag' 'value'
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -70,11 +70,11 @@ taos --dump-config
|
|||
|
||||
### serverPort
|
||||
|
||||
| 属性 | 说明 |
|
||||
| -------- | ----------------------------------------------------------------------------------------------------------------------- |
|
||||
| 适用范围 | 仅服务端适用 |
|
||||
| 含义 | taosd 启动后,对外服务的端口号 |
|
||||
| 缺省值 | 6030 |
|
||||
| 属性 | 说明 |
|
||||
| -------- | ------------------------------ |
|
||||
| 适用范围 | 仅服务端适用 |
|
||||
| 含义 | taosd 启动后,对外服务的端口号 |
|
||||
| 缺省值 | 6030 |
|
||||
|
||||
:::note
|
||||
确保集群中所有主机在端口 6030 上的 TCP 协议能够互通。(详细的端口情况请参见下表)
|
||||
|
@ -173,7 +173,6 @@ taos --dump-config
|
|||
|
||||
1: 表示使用 sma index,对符合的语句,直接从预计算的结果进行查询 |
|
||||
|
||||
|
||||
### maxNumOfDistinctRes
|
||||
|
||||
| 属性 | 说明 |
|
||||
|
@ -625,7 +624,7 @@ charset 的有效值是 UTF-8。
|
|||
| 适用范围 | 仅客户端适用 |
|
||||
| 含义 | schemaless tag 为空时默认的 tag 名字 |
|
||||
| 类型 | 字符串 |
|
||||
| 缺省值 | _tag_null |
|
||||
| 缺省值 | \_tag_null |
|
||||
|
||||
### smlDataFormat
|
||||
|
||||
|
@ -658,173 +657,178 @@ charset 的有效值是 UTF-8。
|
|||
| 缺省值 | 1 |
|
||||
|
||||
## 2.X 与 3.0 配置参数对比
|
||||
| # | **参数** | **适用于 2.X 版本** | **适用于 3.0 版本** |
|
||||
| --- | :-----------------: | --------------- | --------------- |
|
||||
| 1 | firstEp | 是 | 是 |
|
||||
| 2 | secondEp | 是 | 是 |
|
||||
| 3 | fqdn | 是 | 是 |
|
||||
| 4 | serverPort | 是 | 是 |
|
||||
| 5 | maxShellConns | 是 | 是 |
|
||||
| 6 | monitor | 是 | 是 |
|
||||
| 7 | monitorFqdn | 否 | 是 |
|
||||
| 8 | monitorPort | 否 | 是 |
|
||||
| 9 | monitorInterval | 是 | 是 |
|
||||
| 10 | monitorMaxLogs | 否 | 是 |
|
||||
| 11 | monitorComp | 否 | 是 |
|
||||
| 12 | telemetryReporting | 是 | 是 |
|
||||
| 13 | telemetryInterval | 否 | 是 |
|
||||
| 14 | telemetryServer | 否 | 是 |
|
||||
| 15 | telemetryPort | 否 | 是 |
|
||||
| 16 | queryPolicy | 否 | 是 |
|
||||
| 17 | querySmaOptimize | 否 | 是 |
|
||||
| 18 | queryRsmaTolerance | 否 | 是 |
|
||||
| 19 | queryBufferSize | 是 | 是 |
|
||||
| 20 | maxNumOfDistinctRes | 是 | 是 |
|
||||
| 21 | minSlidingTime | 是 | 是 |
|
||||
| 22 | minIntervalTime | 是 | 是 |
|
||||
| 23 | countAlwaysReturnValue | 是 | 是 |
|
||||
| 24 | dataDir | 是 | 是 |
|
||||
| 25 | minimalDataDirGB | 是 | 是 |
|
||||
| 26 | supportVnodes | 否 | 是 |
|
||||
| 27 | tempDir | 是 | 是 |
|
||||
| 28 | minimalTmpDirGB | 是 | 是 |
|
||||
| 29 | compressMsgSize | 是 | 是 |
|
||||
| 30 | compressColData | 是 | 是 |
|
||||
| 31 | smlChildTableName | 是 | 是 |
|
||||
| 32 | smlTagName | 是 | 是 |
|
||||
| 33 | smlDataFormat | 否 | 是 |
|
||||
| 34 | statusInterval | 是 | 是 |
|
||||
| 35 | shellActivityTimer | 是 | 是 |
|
||||
| 36 | transPullupInterval | 否 | 是 |
|
||||
| 37 | mqRebalanceInterval | 否 | 是 |
|
||||
| 38 | ttlUnit | 否 | 是 |
|
||||
| 39 | ttlPushInterval | 否 | 是 |
|
||||
| 40 | numOfTaskQueueThreads | 否 | 是 |
|
||||
| 41 | numOfRpcThreads | 否 | 是 |
|
||||
| 42 | numOfCommitThreads | 是 | 是 |
|
||||
| 43 | numOfMnodeReadThreads | 否 | 是 |
|
||||
| 44 | numOfVnodeQueryThreads | 否 | 是 |
|
||||
| 45 | numOfVnodeStreamThreads | 否 | 是 |
|
||||
| 46 | numOfVnodeFetchThreads | 否 | 是 |
|
||||
| 47 | numOfVnodeWriteThreads | 否 | 是 |
|
||||
| 48 | numOfVnodeSyncThreads | 否 | 是 |
|
||||
| 49 | numOfVnodeRsmaThreads | 否 | 是 |
|
||||
| 50 | numOfQnodeQueryThreads | 否 | 是 |
|
||||
| 51 | numOfQnodeFetchThreads | 否 | 是 |
|
||||
| 52 | numOfSnodeSharedThreads | 否 | 是 |
|
||||
| 53 | numOfSnodeUniqueThreads | 否 | 是 |
|
||||
| 54 | rpcQueueMemoryAllowed | 否 | 是 |
|
||||
| 55 | logDir | 是 | 是 |
|
||||
| 56 | minimalLogDirGB | 是 | 是 |
|
||||
| 57 | numOfLogLines | 是 | 是 |
|
||||
| 58 | asyncLog | 是 | 是 |
|
||||
| 59 | logKeepDays | 是 | 是 |
|
||||
| 60 | debugFlag | 是 | 是 |
|
||||
| 61 | tmrDebugFlag | 是 | 是 |
|
||||
| 62 | uDebugFlag | 是 | 是 |
|
||||
| 63 | rpcDebugFlag | 是 | 是 |
|
||||
| 64 | jniDebugFlag | 是 | 是 |
|
||||
| 65 | qDebugFlag | 是 | 是 |
|
||||
| 66 | cDebugFlag | 是 | 是 |
|
||||
| 67 | dDebugFlag | 是 | 是 |
|
||||
| 68 | vDebugFlag | 是 | 是 |
|
||||
| 69 | mDebugFlag | 是 | 是 |
|
||||
| 70 | wDebugFlag | 是 | 是 |
|
||||
| 71 | sDebugFlag | 是 | 是 |
|
||||
| 72 | tsdbDebugFlag | 是 | 是 |
|
||||
| 73 | tqDebugFlag | 否 | 是 |
|
||||
| 74 | fsDebugFlag | 是 | 是 |
|
||||
| 75 | udfDebugFlag | 否 | 是 |
|
||||
| 76 | smaDebugFlag | 否 | 是 |
|
||||
| 77 | idxDebugFlag | 否 | 是 |
|
||||
| 78 | tdbDebugFlag | 否 | 是 |
|
||||
| 79 | metaDebugFlag | 否 | 是 |
|
||||
| 80 | timezone | 是 | 是 |
|
||||
| 81 | locale | 是 | 是 |
|
||||
| 82 | charset | 是 | 是 |
|
||||
| 83 | udf | 是 | 是 |
|
||||
| 84 | enableCoreFile | 是 | 是 |
|
||||
| 85 | arbitrator | 是 | 否 |
|
||||
| 86 | numOfThreadsPerCore | 是 | 否 |
|
||||
| 87 | numOfMnodes | 是 | 否 |
|
||||
| 88 | vnodeBak | 是 | 否 |
|
||||
| 89 | balance | 是 | 否 |
|
||||
| 90 | balanceInterval | 是 | 否 |
|
||||
| 91 | offlineThreshold | 是 | 否 |
|
||||
| 92 | role | 是 | 否 |
|
||||
| 93 | dnodeNopLoop | 是 | 否 |
|
||||
| 94 | keepTimeOffset | 是 | 否 |
|
||||
| 95 | rpcTimer | 是 | 否 |
|
||||
| 96 | rpcMaxTime | 是 | 否 |
|
||||
| 97 | rpcForceTcp | 是 | 否 |
|
||||
| 98 | tcpConnTimeout | 是 | 否 |
|
||||
| 99 | syncCheckInterval | 是 | 否 |
|
||||
| 100 | maxTmrCtrl | 是 | 否 |
|
||||
| 101 | monitorReplica | 是 | 否 |
|
||||
| 102 | smlTagNullName | 是 | 否 |
|
||||
| 103 | keepColumnName | 是 | 否 |
|
||||
| 104 | ratioOfQueryCores | 是 | 否 |
|
||||
| 105 | maxStreamCompDelay | 是 | 否 |
|
||||
| 106 | maxFirstStreamCompDelay | 是 | 否 |
|
||||
| 107 | retryStreamCompDelay | 是 | 否 |
|
||||
| 108 | streamCompDelayRatio | 是 | 否 |
|
||||
| 109 | maxVgroupsPerDb | 是 | 否 |
|
||||
| 110 | maxTablesPerVnode | 是 | 否 |
|
||||
| 111 | minTablesPerVnode | 是 | 否 |
|
||||
| 112 | tableIncStepPerVnode | 是 | 否 |
|
||||
| 113 | cache | 是 | 否 |
|
||||
| 114 | blocks | 是 | 否 |
|
||||
| 115 | days | 是 | 否 |
|
||||
| 116 | keep | 是 | 否 |
|
||||
| 117 | minRows | 是 | 否 |
|
||||
| 118 | maxRows | 是 | 否 |
|
||||
| 119 | quorum | 是 | 否 |
|
||||
| 120 | comp | 是 | 否 |
|
||||
| 121 | walLevel | 是 | 否 |
|
||||
| 122 | fsync | 是 | 否 |
|
||||
| 123 | replica | 是 | 否 |
|
||||
| 124 | partitions | 是 | 否 |
|
||||
| 125 | quorum | 是 | 否 |
|
||||
| 126 | update | 是 | 否 |
|
||||
| 127 | cachelast | 是 | 否 |
|
||||
| 128 | maxSQLLength | 是 | 否 |
|
||||
| 129 | maxWildCardsLength | 是 | 否 |
|
||||
| 130 | maxRegexStringLen | 是 | 否 |
|
||||
| 131 | maxNumOfOrderedRes | 是 | 否 |
|
||||
| 132 | maxConnections | 是 | 否 |
|
||||
| 133 | mnodeEqualVnodeNum | 是 | 否 |
|
||||
| 134 | http | 是 | 否 |
|
||||
| 135 | httpEnableRecordSql | 是 | 否 |
|
||||
| 136 | httpMaxThreads | 是 | 否 |
|
||||
| 137 | restfulRowLimit | 是 | 否 |
|
||||
| 138 | httpDbNameMandatory | 是 | 否 |
|
||||
| 139 | httpKeepAlive | 是 | 否 |
|
||||
| 140 | enableRecordSql | 是 | 否 |
|
||||
| 141 | maxBinaryDisplayWidth | 是 | 否 |
|
||||
| 142 | stream | 是 | 否 |
|
||||
| 143 | retrieveBlockingModel | 是 | 否 |
|
||||
| 144 | tsdbMetaCompactRatio | 是 | 否 |
|
||||
| 145 | defaultJSONStrType | 是 | 否 |
|
||||
| 146 | walFlushSize | 是 | 否 |
|
||||
| 147 | keepTimeOffset | 是 | 否 |
|
||||
| 148 | flowctrl | 是 | 否 |
|
||||
| 149 | slaveQuery | 是 | 否 |
|
||||
| 150 | adjustMaster | 是 | 否 |
|
||||
| 151 | topicBinaryLen | 是 | 否 |
|
||||
| 152 | telegrafUseFieldNum | 是 | 否 |
|
||||
| 153 | deadLockKillQuery | 是 | 否 |
|
||||
| 154 | clientMerge | 是 | 否 |
|
||||
| 155 | sdbDebugFlag | 是 | 否 |
|
||||
| 156 | odbcDebugFlag | 是 | 否 |
|
||||
| 157 | httpDebugFlag | 是 | 否 |
|
||||
| 158 | monDebugFlag | 是 | 否 |
|
||||
| 159 | cqDebugFlag | 是 | 否 |
|
||||
| 160 | shortcutFlag | 是 | 否 |
|
||||
| 161 | probeSeconds | 是 | 否 |
|
||||
| 162 | probeKillSeconds | 是 | 否 |
|
||||
| 163 | probeInterval | 是 | 否 |
|
||||
| 164 | lossyColumns | 是 | 否 |
|
||||
| 165 | fPrecision | 是 | 否 |
|
||||
| 166 | dPrecision | 是 | 否 |
|
||||
| 167 | maxRange | 是 | 否 |
|
||||
| 168 | range | 是 | 否 |
|
||||
|
||||
:::note
|
||||
对于 2.x 版本中适用但在 3.0 版本中废弃的参数,其当前行为会有特别说明
|
||||
|
||||
:::
|
||||
|
||||
| # | **参数** | **适用于 2.X ** | **适用于 3.0 ** | 3.0 版本的当前行为 |
|
||||
| --- | :---------------------: | --------------- | --------------- | ------------------------------------------------- |
|
||||
| 1 | firstEp | 是 | 是 | |
|
||||
| 2 | secondEp | 是 | 是 | |
|
||||
| 3 | fqdn | 是 | 是 | |
|
||||
| 4 | serverPort | 是 | 是 | |
|
||||
| 5 | maxShellConns | 是 | 是 | |
|
||||
| 6 | monitor | 是 | 是 | |
|
||||
| 7 | monitorFqdn | 否 | 是 | |
|
||||
| 8 | monitorPort | 否 | 是 | |
|
||||
| 9 | monitorInterval | 是 | 是 | |
|
||||
| 10 | monitorMaxLogs | 否 | 是 | |
|
||||
| 11 | monitorComp | 否 | 是 | |
|
||||
| 12 | telemetryReporting | 是 | 是 | |
|
||||
| 13 | telemetryInterval | 否 | 是 | |
|
||||
| 14 | telemetryServer | 否 | 是 | |
|
||||
| 15 | telemetryPort | 否 | 是 | |
|
||||
| 16 | queryPolicy | 否 | 是 | |
|
||||
| 17 | querySmaOptimize | 否 | 是 | |
|
||||
| 18 | queryRsmaTolerance | 否 | 是 | |
|
||||
| 19 | queryBufferSize | 是 | 是 | |
|
||||
| 20 | maxNumOfDistinctRes | 是 | 是 | |
|
||||
| 21 | minSlidingTime | 是 | 是 | |
|
||||
| 22 | minIntervalTime | 是 | 是 | |
|
||||
| 23 | countAlwaysReturnValue | 是 | 是 | |
|
||||
| 24 | dataDir | 是 | 是 | |
|
||||
| 25 | minimalDataDirGB | 是 | 是 | |
|
||||
| 26 | supportVnodes | 否 | 是 | |
|
||||
| 27 | tempDir | 是 | 是 | |
|
||||
| 28 | minimalTmpDirGB | 是 | 是 | |
|
||||
| 29 | compressMsgSize | 是 | 是 | |
|
||||
| 30 | compressColData | 是 | 是 | |
|
||||
| 31 | smlChildTableName | 是 | 是 | |
|
||||
| 32 | smlTagName | 是 | 是 | |
|
||||
| 33 | smlDataFormat | 否 | 是 | |
|
||||
| 34 | statusInterval | 是 | 是 | |
|
||||
| 35 | shellActivityTimer | 是 | 是 | |
|
||||
| 36 | transPullupInterval | 否 | 是 | |
|
||||
| 37 | mqRebalanceInterval | 否 | 是 | |
|
||||
| 38 | ttlUnit | 否 | 是 | |
|
||||
| 39 | ttlPushInterval | 否 | 是 | |
|
||||
| 40 | numOfTaskQueueThreads | 否 | 是 | |
|
||||
| 41 | numOfRpcThreads | 否 | 是 | |
|
||||
| 42 | numOfCommitThreads | 是 | 是 | |
|
||||
| 43 | numOfMnodeReadThreads | 否 | 是 | |
|
||||
| 44 | numOfVnodeQueryThreads | 否 | 是 | |
|
||||
| 45 | numOfVnodeStreamThreads | 否 | 是 | |
|
||||
| 46 | numOfVnodeFetchThreads | 否 | 是 | |
|
||||
| 47 | numOfVnodeWriteThreads | 否 | 是 | |
|
||||
| 48 | numOfVnodeSyncThreads | 否 | 是 | |
|
||||
| 49 | numOfVnodeRsmaThreads | 否 | 是 | |
|
||||
| 50 | numOfQnodeQueryThreads | 否 | 是 | |
|
||||
| 51 | numOfQnodeFetchThreads | 否 | 是 | |
|
||||
| 52 | numOfSnodeSharedThreads | 否 | 是 | |
|
||||
| 53 | numOfSnodeUniqueThreads | 否 | 是 | |
|
||||
| 54 | rpcQueueMemoryAllowed | 否 | 是 | |
|
||||
| 55 | logDir | 是 | 是 | |
|
||||
| 56 | minimalLogDirGB | 是 | 是 | |
|
||||
| 57 | numOfLogLines | 是 | 是 | |
|
||||
| 58 | asyncLog | 是 | 是 | |
|
||||
| 59 | logKeepDays | 是 | 是 | |
|
||||
| 60 | debugFlag | 是 | 是 | |
|
||||
| 61 | tmrDebugFlag | 是 | 是 | |
|
||||
| 62 | uDebugFlag | 是 | 是 | |
|
||||
| 63 | rpcDebugFlag | 是 | 是 | |
|
||||
| 64 | jniDebugFlag | 是 | 是 | |
|
||||
| 65 | qDebugFlag | 是 | 是 | |
|
||||
| 66 | cDebugFlag | 是 | 是 | |
|
||||
| 67 | dDebugFlag | 是 | 是 | |
|
||||
| 68 | vDebugFlag | 是 | 是 | |
|
||||
| 69 | mDebugFlag | 是 | 是 | |
|
||||
| 70 | wDebugFlag | 是 | 是 | |
|
||||
| 71 | sDebugFlag | 是 | 是 | |
|
||||
| 72 | tsdbDebugFlag | 是 | 是 | |
|
||||
| 73 | tqDebugFlag | 否 | 是 | |
|
||||
| 74 | fsDebugFlag | 是 | 是 | |
|
||||
| 75 | udfDebugFlag | 否 | 是 | |
|
||||
| 76 | smaDebugFlag | 否 | 是 | |
|
||||
| 77 | idxDebugFlag | 否 | 是 | |
|
||||
| 78 | tdbDebugFlag | 否 | 是 | |
|
||||
| 79 | metaDebugFlag | 否 | 是 | |
|
||||
| 80 | timezone | 是 | 是 | |
|
||||
| 81 | locale | 是 | 是 | |
|
||||
| 82 | charset | 是 | 是 | |
|
||||
| 83 | udf | 是 | 是 | |
|
||||
| 84 | enableCoreFile | 是 | 是 | |
|
||||
| 85 | arbitrator | 是 | 否 | 通过 RAFT 协议选主 |
|
||||
| 86 | numOfThreadsPerCore | 是 | 否 | 有其它参数设置多种线程池的大小 |
|
||||
| 87 | numOfMnodes | 是 | 否 | 通过 create mnode 命令动态创建 mnode |
|
||||
| 88 | vnodeBak | 是 | 否 | 3.0 行为未知 |
|
||||
| 89 | balance | 是 | 否 | 负载均衡功能由 split/merge vgroups 实现 |
|
||||
| 90 | balanceInterval | 是 | 否 | 随着 balance 参数失效 |
|
||||
| 91 | offlineThreshold | 是 | 否 | 3.0 行为未知 |
|
||||
| 92 | role | 是 | 否 | 由 supportVnode 决定是否能够创建 |
|
||||
| 93 | dnodeNopLoop | 是 | 否 | 2.6 文档中未找到此参数 |
|
||||
| 94 | keepTimeOffset | 是 | 否 | 2.6 文档中未找到此参数 |
|
||||
| 95 | rpcTimer | 是 | 否 | 3.0 行为未知 |
|
||||
| 96 | rpcMaxTime | 是 | 否 | 3.0 行为未知 |
|
||||
| 97 | rpcForceTcp | 是 | 否 | 默认为 TCP |
|
||||
| 98 | tcpConnTimeout | 是 | 否 | 3.0 行为未知 |
|
||||
| 99 | syncCheckInterval | 是 | 否 | 3.0 行为未知 |
|
||||
| 100 | maxTmrCtrl | 是 | 否 | 3.0 行为未知 |
|
||||
| 101 | monitorReplica | 是 | 否 | 由 RAFT 协议管理多副本 |
|
||||
| 102 | smlTagNullName | 是 | 否 | 3.0 行为未知 |
|
||||
| 103 | keepColumnName | 是 | 否 | 3.0 行为未知 |
|
||||
| 104 | ratioOfQueryCores | 是 | 否 | 由 线程池 相关配置参数决定 |
|
||||
| 105 | maxStreamCompDelay | 是 | 否 | 3.0 行为未知 |
|
||||
| 106 | maxFirstStreamCompDelay | 是 | 否 | 3.0 行为未知 |
|
||||
| 107 | retryStreamCompDelay | 是 | 否 | 3.0 行为未知 |
|
||||
| 108 | streamCompDelayRatio | 是 | 否 | 3.0 行为未知 |
|
||||
| 109 | maxVgroupsPerDb | 是 | 否 | 由 create db 的参数 vgroups 指定实际 vgroups 数量 |
|
||||
| 110 | maxTablesPerVnode | 是 | 否 | DB 中的所有表近似平均分配到各个 vgroup |
|
||||
| 111 | minTablesPerVnode | 是 | 否 | DB 中的所有表近似平均分配到各个 vgroup |
|
||||
| 112 | tableIncStepPerVnode | 是 | 否 | DB 中的所有表近似平均分配到各个 vgroup |
|
||||
| 113 | cache | 是 | 否 | 由 buffer 代替 cache\*blocks |
|
||||
| 114 | blocks | 是 | 否 | 由 buffer 代替 cache\*blocks |
|
||||
| 115 | days | 是 | 否 | 由 create db 的参数 duration 取代 |
|
||||
| 116 | keep | 是 | 否 | 由 create db 的参数 keep 取代 |
|
||||
| 117 | minRows | 是 | 否 | 由 create db 的参数 minRows 取代 |
|
||||
| 118 | maxRows | 是 | 否 | 由 create db 的参数 maxRows 取代 |
|
||||
| 119 | quorum | 是 | 否 | 由 RAFT 协议决定 |
|
||||
| 120 | comp | 是 | 否 | 由 create db 的参数 comp 取代 |
|
||||
| 121 | walLevel | 是 | 否 | 由 create db 的参数 wal_level 取代 |
|
||||
| 122 | fsync | 是 | 否 | 由 create db 的参数 wal_fsync_period 取代 |
|
||||
| 123 | replica | 是 | 否 | 由 create db 的参数 replica 取代 |
|
||||
| 124 | partitions | 是 | 否 | 3.0 行为未知 |
|
||||
| 125 | update | 是 | 否 | 允许更新部分列 |
|
||||
| 126 | cachelast | 是 | 否 | 由 create db 的参数 cacheModel 取代 |
|
||||
| 127 | maxSQLLength | 是 | 否 | SQL 上限为 1MB,无需参数控制 |
|
||||
| 128 | maxWildCardsLength | 是 | 否 | 3.0 行为未知 |
|
||||
| 129 | maxRegexStringLen | 是 | 否 | 3.0 行为未知 |
|
||||
| 130 | maxNumOfOrderedRes | 是 | 否 | 3.0 行为未知 |
|
||||
| 131 | maxConnections | 是 | 否 | 取决于系统配置和系统处理能力,详见后面的 Note |
|
||||
| 132 | mnodeEqualVnodeNum | 是 | 否 | 3.0 行为未知 |
|
||||
| 133 | http | 是 | 否 | http 服务由 taosAdapter 提供 |
|
||||
| 134 | httpEnableRecordSql | 是 | 否 | taosd 不提供 http 服务 |
|
||||
| 135 | httpMaxThreads | 是 | 否 | taosd 不提供 http 服务 |
|
||||
| 136 | restfulRowLimit | 是 | 否 | taosd 不提供 http 服务 |
|
||||
| 137 | httpDbNameMandatory | 是 | 否 | taosd 不提供 http 服务 |
|
||||
| 138 | httpKeepAlive | 是 | 否 | taosd 不提供 http 服务 |
|
||||
| 139 | enableRecordSql | 是 | 否 | 3.0 行为未知 |
|
||||
| 140 | maxBinaryDisplayWidth | 是 | 否 | 3.0 行为未知 |
|
||||
| 141 | stream | 是 | 否 | 默认启用连续查询 |
|
||||
| 142 | retrieveBlockingModel | 是 | 否 | 3.0 行为未知 |
|
||||
| 143 | tsdbMetaCompactRatio | 是 | 否 | 3.0 行为未知 |
|
||||
| 144 | defaultJSONStrType | 是 | 否 | 3.0 行为未知 |
|
||||
| 145 | walFlushSize | 是 | 否 | 3.0 行为未知 |
|
||||
| 146 | keepTimeOffset | 是 | 否 | 3.0 行为未知 |
|
||||
| 147 | flowctrl | 是 | 否 | 3.0 行为未知 |
|
||||
| 148 | slaveQuery | 是 | 否 | 3.0 行为未知: slave vnode 是否能够处理查询? |
|
||||
| 149 | adjustMaster | 是 | 否 | 3.0 行为未知 |
|
||||
| 150 | topicBinaryLen | 是 | 否 | 3.0 行为未知 |
|
||||
| 151 | telegrafUseFieldNum | 是 | 否 | 3.0 行为未知 |
|
||||
| 152 | deadLockKillQuery | 是 | 否 | 3.0 行为未知 |
|
||||
| 153 | clientMerge | 是 | 否 | 3.0 行为未知 |
|
||||
| 154 | sdbDebugFlag | 是 | 否 | 参考 3.0 的 DebugFlag 系列参数 |
|
||||
| 155 | odbcDebugFlag | 是 | 否 | 参考 3.0 的 DebugFlag 系列参数 |
|
||||
| 156 | httpDebugFlag | 是 | 否 | 参考 3.0 的 DebugFlag 系列参数 |
|
||||
| 157 | monDebugFlag | 是 | 否 | 参考 3.0 的 DebugFlag 系列参数 |
|
||||
| 158 | cqDebugFlag | 是 | 否 | 参考 3.0 的 DebugFlag 系列参数 |
|
||||
| 159 | shortcutFlag | 是 | 否 | 参考 3.0 的 DebugFlag 系列参数 |
|
||||
| 160 | probeSeconds | 是 | 否 | 3.0 行为未知 |
|
||||
| 161 | probeKillSeconds | 是 | 否 | 3.0 行为未知 |
|
||||
| 162 | probeInterval | 是 | 否 | 3.0 行为未知 |
|
||||
| 163 | lossyColumns | 是 | 否 | 3.0 行为未知 |
|
||||
| 164 | fPrecision | 是 | 否 | 3.0 行为未知 |
|
||||
| 165 | dPrecision | 是 | 否 | 3.0 行为未知 |
|
||||
| 166 | maxRange | 是 | 否 | 3.0 行为未知 |
|
||||
| 167 | range | 是 | 否 | 3.0 行为未知 |
|
||||
|
|
|
@ -135,11 +135,11 @@ ALTER LOCAL local_option
|
|||
|
||||
local_option: {
|
||||
'resetLog'
|
||||
| 'rpcDebugFlag' value
|
||||
| 'tmrDebugFlag' value
|
||||
| 'cDebugFlag' value
|
||||
| 'uDebugFlag' value
|
||||
| 'debugFlag' value
|
||||
| 'rpcDebugFlag' 'value'
|
||||
| 'tmrDebugFlag' 'value'
|
||||
| 'cDebugFlag' 'value'
|
||||
| 'uDebugFlag' 'value'
|
||||
| 'debugFlag' 'value'
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -169,7 +169,7 @@ typedef struct {
|
|||
// #define TD_ROW_VER(r) ((r)->ver)
|
||||
#define TD_ROW_KEY_ADDR(r) (r)
|
||||
|
||||
// N.B. If without STSchema, getExtendedRowSize() is used to get the rowMaxBytes and
|
||||
// N.B. If without STSchema, insGetExtendedRowSize() is used to get the rowMaxBytes and
|
||||
// (int32_t)ceil((double)nCols/TD_VTYPE_PARTS) should be added if TD_SUPPORT_BITMAP defined.
|
||||
#define TD_ROW_MAX_BYTES_FROM_SCHEMA(s) ((s)->tlen + TD_ROW_HEAD_LEN)
|
||||
|
||||
|
|
|
@ -164,9 +164,9 @@
|
|||
#define TK_SCORES 146
|
||||
#define TK_TOPICS 147
|
||||
#define TK_VARIABLES 148
|
||||
#define TK_BNODES 149
|
||||
#define TK_SNODES 150
|
||||
#define TK_CLUSTER 151
|
||||
#define TK_CLUSTER 149
|
||||
#define TK_BNODES 150
|
||||
#define TK_SNODES 151
|
||||
#define TK_TRANSACTIONS 152
|
||||
#define TK_DISTRIBUTED 153
|
||||
#define TK_CONSUMERS 154
|
||||
|
|
|
@ -290,6 +290,7 @@ typedef struct {
|
|||
(IS_SIGNED_NUMERIC_TYPE(_t) || (_t) == (TSDB_DATA_TYPE_BOOL) || (_t) == (TSDB_DATA_TYPE_TIMESTAMP))
|
||||
#define IS_CONVERT_AS_UNSIGNED(_t) (IS_UNSIGNED_NUMERIC_TYPE(_t) || (_t) == (TSDB_DATA_TYPE_BOOL))
|
||||
|
||||
#if 0
|
||||
// TODO remove this function
|
||||
static FORCE_INLINE bool isNull(const void *val, int32_t type) {
|
||||
switch (type) {
|
||||
|
@ -325,6 +326,7 @@ static FORCE_INLINE bool isNull(const void *val, int32_t type) {
|
|||
return false;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef struct tDataTypeDescriptor {
|
||||
int16_t type;
|
||||
|
|
|
@ -274,6 +274,7 @@ typedef struct SShowTableDistributedStmt {
|
|||
typedef struct SShowDnodeVariablesStmt {
|
||||
ENodeType type;
|
||||
SNode* pDnodeId;
|
||||
SNode* pLikePattern;
|
||||
} SShowDnodeVariablesStmt;
|
||||
|
||||
typedef struct SShowVnodesStmt {
|
||||
|
|
|
@ -347,11 +347,6 @@ typedef struct SInsertStmt {
|
|||
uint8_t precision;
|
||||
} SInsertStmt;
|
||||
|
||||
typedef enum {
|
||||
PAYLOAD_TYPE_KV = 0,
|
||||
PAYLOAD_TYPE_RAW = 1,
|
||||
} EPayloadType;
|
||||
|
||||
typedef struct SVgDataBlocks {
|
||||
SVgroupInfo vg;
|
||||
int32_t numOfTables; // number of tables in current submit block
|
||||
|
@ -363,7 +358,6 @@ typedef struct SVnodeModifOpStmt {
|
|||
ENodeType nodeType;
|
||||
ENodeType sqlNodeType;
|
||||
SArray* pDataBlocks; // data block for each vgroup, SArray<SVgDataBlocks*>.
|
||||
uint8_t payloadType; // EPayloadType. 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert
|
||||
uint32_t insertType; // insert data from [file|sql statement| bound statement]
|
||||
const char* sql; // current sql statement position
|
||||
} SVnodeModifOpStmt;
|
||||
|
|
|
@ -46,7 +46,6 @@ extern "C" {
|
|||
|
||||
#define ERROR_MSG_BUF_DEFAULT_SIZE 512
|
||||
#define HEARTBEAT_INTERVAL 1500 // ms
|
||||
#define SYNC_ON_TOP_OF_ASYNC 1
|
||||
|
||||
enum {
|
||||
RES_TYPE__QUERY = 1,
|
||||
|
@ -271,9 +270,8 @@ void doFreeReqResultInfo(SReqResultInfo* pResInfo);
|
|||
int32_t transferTableNameList(const char* tbList, int32_t acctId, char* dbName, SArray** pReq);
|
||||
void syncCatalogFn(SMetaData* pResult, void* param, int32_t code);
|
||||
|
||||
SRequestObj* execQuery(uint64_t connId, const char* sql, int sqlLen, bool validateOnly);
|
||||
TAOS_RES* taosQueryImpl(TAOS* taos, const char* sql, bool validateOnly);
|
||||
void taosAsyncQueryImpl(uint64_t connId, const char* sql, __taos_async_fn_t fp, void* param, bool validateOnly);
|
||||
TAOS_RES* taosQueryImpl(TAOS* taos, const char* sql, bool validateOnly);
|
||||
void taosAsyncQueryImpl(uint64_t connId, const char* sql, __taos_async_fn_t fp, void* param, bool validateOnly);
|
||||
|
||||
int32_t getVersion1BlockMetaSize(const char* p, int32_t numOfCols);
|
||||
|
||||
|
@ -349,8 +347,6 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet);
|
|||
STscObj* taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db,
|
||||
uint16_t port, int connType);
|
||||
|
||||
SRequestObj* launchQuery(uint64_t connId, const char* sql, int sqlLen, bool validateOnly, bool inRetry);
|
||||
|
||||
int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtCallback* pStmtCb);
|
||||
|
||||
int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList);
|
||||
|
|
|
@ -1013,28 +1013,6 @@ SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, bool keepQue
|
|||
return pRequest;
|
||||
}
|
||||
|
||||
SRequestObj* launchQuery(uint64_t connId, const char* sql, int sqlLen, bool validateOnly, bool inRetry) {
|
||||
SRequestObj* pRequest = NULL;
|
||||
SQuery* pQuery = NULL;
|
||||
|
||||
int32_t code = buildRequest(connId, sql, sqlLen, NULL, validateOnly, &pRequest);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
terrno = code;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
code = parseSql(pRequest, false, &pQuery, NULL);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pRequest->code = code;
|
||||
return pRequest;
|
||||
}
|
||||
|
||||
pRequest->inRetry = inRetry;
|
||||
pRequest->stableQuery = pQuery->stableQuery;
|
||||
|
||||
return launchQueryImpl(pRequest, pQuery, false, NULL);
|
||||
}
|
||||
|
||||
static int32_t asyncExecSchQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaData* pResultMeta,
|
||||
SSqlCallbackWrapper* pWrapper) {
|
||||
pRequest->type = pQuery->msgType;
|
||||
|
@ -1197,32 +1175,6 @@ int32_t removeMeta(STscObj* pTscObj, SArray* tbList) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
// todo remove it soon
|
||||
SRequestObj* execQuery(uint64_t connId, const char* sql, int sqlLen, bool validateOnly) {
|
||||
SRequestObj* pRequest = NULL;
|
||||
int32_t retryNum = 0;
|
||||
int32_t code = 0;
|
||||
bool inRetry = false;
|
||||
|
||||
do {
|
||||
destroyRequest(pRequest);
|
||||
pRequest = launchQuery(connId, sql, sqlLen, validateOnly, inRetry);
|
||||
if (pRequest == NULL || TSDB_CODE_SUCCESS == pRequest->code || !NEED_CLIENT_HANDLE_ERROR(pRequest->code)) {
|
||||
break;
|
||||
}
|
||||
|
||||
code = refreshMeta(pRequest->pTscObj, pRequest);
|
||||
if (code) {
|
||||
pRequest->code = code;
|
||||
break;
|
||||
}
|
||||
|
||||
inRetry = true;
|
||||
} while (retryNum++ < REQUEST_TOTAL_EXEC_TIMES);
|
||||
|
||||
return pRequest;
|
||||
}
|
||||
|
||||
int initEpSetFromCfg(const char* firstEp, const char* secondEp, SCorEpSet* pEpSet) {
|
||||
pEpSet->version = 0;
|
||||
|
||||
|
@ -2291,7 +2243,6 @@ TAOS_RES* taosQueryImpl(TAOS* taos, const char* sql, bool validateOnly) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#if SYNC_ON_TOP_OF_ASYNC
|
||||
SSyncQueryParam* param = taosMemoryCalloc(1, sizeof(SSyncQueryParam));
|
||||
tsem_init(¶m->sem, 0, 0);
|
||||
|
||||
|
@ -2301,15 +2252,4 @@ TAOS_RES* taosQueryImpl(TAOS* taos, const char* sql, bool validateOnly) {
|
|||
param->pRequest->syncQuery = true;
|
||||
}
|
||||
return param->pRequest;
|
||||
#else
|
||||
size_t sqlLen = strlen(sql);
|
||||
if (sqlLen > (size_t)TSDB_MAX_ALLOWED_SQL_LEN) {
|
||||
tscError("sql string exceeds max length:%d", TSDB_MAX_ALLOWED_SQL_LEN);
|
||||
terrno = TSDB_CODE_TSC_EXCEED_SQL_LIMIT;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TAOS_RES* pRes = execQuery(*(int64_t*)taos, sql, sqlLen, validateOnly);
|
||||
return pRes;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -261,12 +261,7 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#if SYNC_ON_TOP_OF_ASYNC
|
||||
return doAsyncFetchRows(pRequest, true, true);
|
||||
#else
|
||||
return doFetchRows(pRequest, true, true);
|
||||
#endif
|
||||
|
||||
} else if (TD_RES_TMQ(res) || TD_RES_TMQ_METADATA(res)) {
|
||||
SMqRspObj *msg = ((SMqRspObj *)res);
|
||||
SReqResultInfo *pResultInfo;
|
||||
|
@ -549,11 +544,7 @@ int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if SYNC_ON_TOP_OF_ASYNC
|
||||
doAsyncFetchRows(pRequest, false, true);
|
||||
#else
|
||||
doFetchRows(pRequest, true, true);
|
||||
#endif
|
||||
|
||||
// TODO refactor
|
||||
SReqResultInfo *pResultInfo = &pRequest->body.resInfo;
|
||||
|
@ -601,11 +592,7 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if SYNC_ON_TOP_OF_ASYNC
|
||||
doAsyncFetchRows(pRequest, false, false);
|
||||
#else
|
||||
doFetchRows(pRequest, false, false);
|
||||
#endif
|
||||
|
||||
SReqResultInfo *pResultInfo = &pRequest->body.resInfo;
|
||||
|
||||
|
@ -989,7 +976,7 @@ const void *taos_get_raw_block(TAOS_RES *res) {
|
|||
return pRequest->body.resInfo.pData;
|
||||
}
|
||||
|
||||
int taos_get_db_route_info(TAOS* taos, const char* db, TAOS_DB_ROUTE_INFO* dbInfo) {
|
||||
int taos_get_db_route_info(TAOS *taos, const char *db, TAOS_DB_ROUTE_INFO *dbInfo) {
|
||||
if (NULL == taos) {
|
||||
terrno = TSDB_CODE_TSC_DISCONNECTED;
|
||||
return terrno;
|
||||
|
@ -1001,16 +988,16 @@ int taos_get_db_route_info(TAOS* taos, const char* db, TAOS_DB_ROUTE_INFO* dbInf
|
|||
return terrno;
|
||||
}
|
||||
|
||||
int64_t connId = *(int64_t *)taos;
|
||||
SRequestObj *pRequest = NULL;
|
||||
char *sql = "taos_get_db_route_info";
|
||||
int32_t code = buildRequest(connId, sql, strlen(sql), NULL, false, &pRequest);
|
||||
int64_t connId = *(int64_t *)taos;
|
||||
SRequestObj *pRequest = NULL;
|
||||
char *sql = "taos_get_db_route_info";
|
||||
int32_t code = buildRequest(connId, sql, strlen(sql), NULL, false, &pRequest);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
terrno = code;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
STscObj *pTscObj = pRequest->pTscObj;
|
||||
STscObj *pTscObj = pRequest->pTscObj;
|
||||
SCatalog *pCtg = NULL;
|
||||
code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCtg);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -1024,7 +1011,7 @@ int taos_get_db_route_info(TAOS* taos, const char* db, TAOS_DB_ROUTE_INFO* dbInf
|
|||
|
||||
char dbFName[TSDB_DB_FNAME_LEN] = {0};
|
||||
snprintf(dbFName, sizeof(dbFName), "%d.%s", pTscObj->acctId, db);
|
||||
|
||||
|
||||
code = catalogGetDBVgInfo(pCtg, &conn, dbFName, dbInfo);
|
||||
if (code) {
|
||||
goto _return;
|
||||
|
@ -1038,7 +1025,7 @@ _return:
|
|||
return code;
|
||||
}
|
||||
|
||||
int taos_get_table_vgId(TAOS* taos, const char* db, const char* table, int* vgId) {
|
||||
int taos_get_table_vgId(TAOS *taos, const char *db, const char *table, int *vgId) {
|
||||
if (NULL == taos) {
|
||||
terrno = TSDB_CODE_TSC_DISCONNECTED;
|
||||
return terrno;
|
||||
|
@ -1050,15 +1037,15 @@ int taos_get_table_vgId(TAOS* taos, const char* db, const char* table, int* vgId
|
|||
return terrno;
|
||||
}
|
||||
|
||||
int64_t connId = *(int64_t *)taos;
|
||||
SRequestObj *pRequest = NULL;
|
||||
char *sql = "taos_get_table_vgId";
|
||||
int32_t code = buildRequest(connId, sql, strlen(sql), NULL, false, &pRequest);
|
||||
int64_t connId = *(int64_t *)taos;
|
||||
SRequestObj *pRequest = NULL;
|
||||
char *sql = "taos_get_table_vgId";
|
||||
int32_t code = buildRequest(connId, sql, strlen(sql), NULL, false, &pRequest);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
STscObj *pTscObj = pRequest->pTscObj;
|
||||
STscObj *pTscObj = pRequest->pTscObj;
|
||||
SCatalog *pCtg = NULL;
|
||||
code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCtg);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
|
|
@ -1369,7 +1369,6 @@ int taos_write_raw_block(TAOS* taos, int rows, char* pData, const char* tbname)
|
|||
goto end;
|
||||
}
|
||||
SVnodeModifOpStmt* nodeStmt = (SVnodeModifOpStmt*)(pQuery->pRoot);
|
||||
nodeStmt->payloadType = PAYLOAD_TYPE_KV;
|
||||
nodeStmt->pDataBlocks = taosArrayInit(1, POINTER_BYTES);
|
||||
|
||||
SVgDataBlocks* dst = taosMemoryCalloc(1, sizeof(SVgDataBlocks));
|
||||
|
@ -1625,7 +1624,6 @@ static int32_t tmqWriteRawDataImpl(TAOS* taos, void* data, int32_t dataLen) {
|
|||
goto end;
|
||||
}
|
||||
SVnodeModifOpStmt* nodeStmt = (SVnodeModifOpStmt*)(pQuery->pRoot);
|
||||
nodeStmt->payloadType = PAYLOAD_TYPE_KV;
|
||||
|
||||
int32_t numOfVg = taosHashGetSize(pVgHash);
|
||||
nodeStmt->pDataBlocks = taosArrayInit(numOfVg, POINTER_BYTES);
|
||||
|
@ -1929,7 +1927,6 @@ static int32_t tmqWriteRawMetaDataImpl(TAOS* taos, void* data, int32_t dataLen)
|
|||
goto end;
|
||||
}
|
||||
SVnodeModifOpStmt* nodeStmt = (SVnodeModifOpStmt*)(pQuery->pRoot);
|
||||
nodeStmt->payloadType = PAYLOAD_TYPE_KV;
|
||||
|
||||
int32_t numOfVg = taosHashGetSize(pVgHash);
|
||||
nodeStmt->pDataBlocks = taosArrayInit(numOfVg, POINTER_BYTES);
|
||||
|
|
|
@ -1531,7 +1531,6 @@ static SSmlHandle *smlBuildSmlInfo(STscObj *pTscObj, SRequestObj *request, SMLPr
|
|||
uError("SML:0x%" PRIx64 " create info->pQuery->pRoot error", info->id);
|
||||
goto cleanup;
|
||||
}
|
||||
((SVnodeModifOpStmt *)(info->pQuery->pRoot))->payloadType = PAYLOAD_TYPE_KV;
|
||||
|
||||
if (pTscObj) {
|
||||
info->taos = pTscObj;
|
||||
|
@ -2394,7 +2393,7 @@ static int32_t smlParseLine(SSmlHandle *info, char *lines[], char* rawLine, char
|
|||
code = smlParseJSON(info, rawLine);
|
||||
}
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("SML:0x%" PRIx64 " smlParseJSON failed:%s", info->id, *lines);
|
||||
uError("SML:0x%" PRIx64 " smlParseJSON failed:%s", info->id, lines?*lines:rawLine);
|
||||
return code;
|
||||
}
|
||||
return code;
|
||||
|
|
|
@ -230,8 +230,8 @@ static const SSysDbTableSchema transSchema[] = {
|
|||
};
|
||||
|
||||
static const SSysDbTableSchema configSchema[] = {
|
||||
{.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 = "name", .bytes = TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
{.name = "value", .bytes = TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
};
|
||||
|
||||
static const SSysDbTableSchema variablesSchema[] = {
|
||||
|
@ -282,7 +282,7 @@ static const SSysTableMeta infosMeta[] = {
|
|||
{TSDB_INS_TABLE_USERS, userUsersSchema, tListLen(userUsersSchema), false},
|
||||
{TSDB_INS_TABLE_LICENCES, grantsSchema, tListLen(grantsSchema), true},
|
||||
{TSDB_INS_TABLE_VGROUPS, vgroupsSchema, tListLen(vgroupsSchema), true},
|
||||
{TSDB_INS_TABLE_CONFIGS, configSchema, tListLen(configSchema), true},
|
||||
{TSDB_INS_TABLE_CONFIGS, configSchema, tListLen(configSchema), false},
|
||||
{TSDB_INS_TABLE_DNODE_VARIABLES, variablesSchema, tListLen(variablesSchema), true},
|
||||
{TSDB_INS_TABLE_TOPICS, topicSchema, tListLen(topicSchema), false},
|
||||
{TSDB_INS_TABLE_SUBSCRIPTIONS, subscriptionSchema, tListLen(subscriptionSchema), false},
|
||||
|
|
|
@ -5158,7 +5158,7 @@ int tDecodeSVCreateTbReq(SDecoder *pCoder, SVCreateTbReq *pReq) {
|
|||
char name[TSDB_COL_NAME_LEN] = {0};
|
||||
char *tmp = NULL;
|
||||
if (tDecodeCStr(pCoder, &tmp) < 0) return -1;
|
||||
strcpy(name, tmp);
|
||||
strncpy(name, tmp, TSDB_COL_NAME_LEN - 1);
|
||||
taosArrayPush(pReq->ctb.tagName, name);
|
||||
}
|
||||
} else if (pReq->type == TSDB_NORMAL_TABLE) {
|
||||
|
|
|
@ -187,7 +187,9 @@ void* tsBufDestroy(STSBuf* pTSBuf) {
|
|||
|
||||
if (pTSBuf->autoDelete) {
|
||||
// ("tsBuf %p destroyed, delete tmp file:%s", pTSBuf, pTSBuf->path);
|
||||
taosRemoveFile(pTSBuf->path);
|
||||
if (taosRemoveFile(pTSBuf->path) != 0) {
|
||||
// tscError("tsBuf %p destroyed, failed to remove tmp file:%s", pTSBuf, pTSBuf->path);
|
||||
}
|
||||
} else {
|
||||
// tscDebug("tsBuf %p destroyed, tmp file:%s, remains", pTSBuf, pTSBuf->path);
|
||||
}
|
||||
|
|
|
@ -273,7 +273,17 @@ int32_t vmProcessAlterVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
int32_t vgId = alterReq.vgId;
|
||||
dInfo("vgId:%d, start to alter vnode replica", alterReq.vgId);
|
||||
dInfo("vgId:%d, start to alter vnode, replica:%d selfIndex:%d strict:%d", alterReq.vgId, alterReq.replica,
|
||||
alterReq.selfIndex, alterReq.strict);
|
||||
for (int32_t i = 0; i < alterReq.replica; ++i) {
|
||||
dInfo("vgId:%d, replica:%d ep:%s:%u", alterReq.vgId, i, alterReq.replicas[i].fqdn, alterReq.replicas[i].port);
|
||||
}
|
||||
|
||||
if (alterReq.replica <= 0 || alterReq.selfIndex < 0 || alterReq.selfIndex >= alterReq.replica) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
dError("vgId:%d, failed to alter replica since invalid msg", alterReq.vgId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
|
||||
if (pVnode == NULL) {
|
||||
|
|
|
@ -307,6 +307,10 @@ int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
|
|||
}
|
||||
vmReleaseVnode(pMgmt, pVnode);
|
||||
}
|
||||
if (size < 0) {
|
||||
dError("vgId:%d, can't get size from queue since %s, qtype:%d", vgId, terrstr(), qtype);
|
||||
size = 0;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,10 +21,8 @@
|
|||
|
||||
static int32_t mndRetrieveGrant(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||
int32_t numOfRows = 0;
|
||||
char *pWrite;
|
||||
int32_t cols = 0;
|
||||
char tmp[32];
|
||||
char tmp1[32];
|
||||
|
||||
if (pShow->numOfRows < 1) {
|
||||
cols = 0;
|
||||
|
|
|
@ -204,13 +204,21 @@ int32_t mndInitSync(SMnode *pMnode) {
|
|||
taosInitRWLatch(&pMgmt->lock);
|
||||
pMgmt->transId = 0;
|
||||
|
||||
SSyncInfo syncInfo = {.vgId = 1, .FpSendMsg = mndSyncSendMsg, .FpEqMsg = mndSyncEqMsg};
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s%ssync", pMnode->path, TD_DIRSEP);
|
||||
syncInfo.pWal = pMnode->pWal;
|
||||
syncInfo.pFsm = mndSyncMakeFsm(pMnode);
|
||||
syncInfo.snapshotStrategy = SYNC_STRATEGY_STANDARD_SNAPSHOT;
|
||||
SSyncInfo syncInfo = {
|
||||
.snapshotStrategy = SYNC_STRATEGY_STANDARD_SNAPSHOT,
|
||||
.batchSize = 1,
|
||||
.vgId = 1,
|
||||
.pWal = pMnode->pWal,
|
||||
.msgcb = NULL,
|
||||
.FpSendMsg = mndSyncSendMsg,
|
||||
.FpEqMsg = mndSyncEqMsg,
|
||||
.FpEqCtrlMsg = NULL,
|
||||
};
|
||||
|
||||
mInfo("vgId:1, start to open sync, selfIndex:%d replica:%d", pMgmt->selfIndex, pMgmt->numOfReplicas);
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s%ssync", pMnode->path, TD_DIRSEP);
|
||||
syncInfo.pFsm = mndSyncMakeFsm(pMnode);
|
||||
|
||||
mInfo("vgId:1, start to open sync, replica:%d selfIndex:%d", pMgmt->numOfReplicas, pMgmt->selfIndex);
|
||||
SSyncCfg *pCfg = &syncInfo.syncCfg;
|
||||
pCfg->replicaNum = pMgmt->numOfReplicas;
|
||||
pCfg->myIndex = pMgmt->selfIndex;
|
||||
|
|
|
@ -918,13 +918,19 @@ static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) {
|
|||
sendRsp = true;
|
||||
}
|
||||
} else {
|
||||
if (pTrans->stage == TRN_STAGE_REDO_ACTION && pTrans->failedTimes > 6) {
|
||||
if (pTrans->stage == TRN_STAGE_REDO_ACTION && ((code == TSDB_CODE_APP_NOT_READY && pTrans->failedTimes > 60) ||
|
||||
(code != TSDB_CODE_APP_NOT_READY && pTrans->failedTimes > 6))) {
|
||||
if (code == 0) code = TSDB_CODE_MND_TRANS_UNKNOW_ERROR;
|
||||
sendRsp = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!sendRsp) return;
|
||||
if (!sendRsp) {
|
||||
return;
|
||||
} else {
|
||||
mInfo("trans:%d, send rsp, stage:%s failedTimes:%d code:0x%x", pTrans->id, mndTransStr(pTrans->stage),
|
||||
pTrans->failedTimes, code);
|
||||
}
|
||||
|
||||
int32_t size = taosArrayGetSize(pTrans->pRpcArray);
|
||||
if (size <= 0) return;
|
||||
|
|
|
@ -260,6 +260,12 @@ void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVg
|
|||
return NULL;
|
||||
}
|
||||
|
||||
mInfo("vgId:%d, build create vnode req, replica:%d selfIndex:%d strict:%d", createReq.vgId, createReq.replica,
|
||||
createReq.selfIndex, createReq.strict);
|
||||
for (int32_t i = 0; i < createReq.replica; ++i) {
|
||||
mInfo("vgId:%d, replica:%d ep:%s:%u", createReq.vgId, i, createReq.replicas[i].fqdn, createReq.replicas[i].port);
|
||||
}
|
||||
|
||||
int32_t contLen = tSerializeSCreateVnodeReq(NULL, 0, &createReq);
|
||||
if (contLen < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -293,6 +299,7 @@ static void *mndBuildAlterVnodeConfigReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pV
|
|||
alterReq.strict = pDb->cfg.strict;
|
||||
alterReq.cacheLast = pDb->cfg.cacheLast;
|
||||
|
||||
mInfo("vgId:%d, build alter vnode config req", pVgroup->vgId);
|
||||
int32_t contLen = tSerializeSAlterVnodeConfigReq(NULL, 0, &alterReq);
|
||||
if (contLen < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -341,6 +348,12 @@ static void *mndBuildAlterVnodeReplicaReq(SMnode *pMnode, SDbObj *pDb, SVgObj *p
|
|||
alterReq.selfIndex = v;
|
||||
}
|
||||
}
|
||||
alterReq.replica = pVgroup->replica;
|
||||
mInfo("vgId:%d, build alter vnode req, replica:%d selfIndex:%d strict:%d", alterReq.vgId, alterReq.replica,
|
||||
alterReq.selfIndex, alterReq.strict);
|
||||
for (int32_t i = 0; i < alterReq.replica; ++i) {
|
||||
mInfo("vgId:%d, replica:%d ep:%s:%u", alterReq.vgId, i, alterReq.replicas[i].fqdn, alterReq.replicas[i].port);
|
||||
}
|
||||
|
||||
if (alterReq.selfIndex == -1) {
|
||||
terrno = TSDB_CODE_MND_APP_ERROR;
|
||||
|
@ -371,6 +384,7 @@ void *mndBuildDropVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgOb
|
|||
memcpy(dropReq.db, pDb->name, TSDB_DB_FNAME_LEN);
|
||||
dropReq.dbUid = pDb->uid;
|
||||
|
||||
mInfo("vgId:%d, build drop vnode req", dropReq.vgId);
|
||||
int32_t contLen = tSerializeSDropVnodeReq(NULL, 0, &dropReq);
|
||||
if (contLen < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -1179,9 +1193,21 @@ static int32_t mndAddIncVgroupReplicaToTrans(SMnode *pMnode, STrans *pTrans, SDb
|
|||
pGid->dnodeId = newDnodeId;
|
||||
pGid->syncState = TAOS_SYNC_STATE_ERROR;
|
||||
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, pVgroup, pGid) != 0) return -1;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, pVgroup, -1) != 0) return -1;
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, pVgroup) != 0) return -1;
|
||||
if (pVgroup->replica == 2) {
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, pVgroup, pGid) != 0) return -1;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, pVgroup, pVgroup->vnodeGid[0].dnodeId) != 0) return -1;
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, pVgroup) != 0) return -1;
|
||||
} else if (pVgroup->replica == 4) {
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, pVgroup, pGid) != 0) return -1;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, pVgroup, pVgroup->vnodeGid[0].dnodeId) != 0) return -1;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, pVgroup, pVgroup->vnodeGid[1].dnodeId) != 0) return -1;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, pVgroup, pVgroup->vnodeGid[2].dnodeId) != 0) return -1;
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, pVgroup) != 0) return -1;
|
||||
} else {
|
||||
mError("vgId:%d, failed to add 1 vnode since invalid replica:%d", pVgroup->vgId, pVgroup->replica);
|
||||
terrno = TSDB_CODE_MND_APP_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1206,9 +1232,21 @@ static int32_t mndAddDecVgroupReplicaFromTrans(SMnode *pMnode, STrans *pTrans, S
|
|||
memcpy(pGid, &pVgroup->vnodeGid[pVgroup->replica], sizeof(SVnodeGid));
|
||||
memset(&pVgroup->vnodeGid[pVgroup->replica], 0, sizeof(SVnodeGid));
|
||||
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, pVgroup, -1) != 0) return -1;
|
||||
if (mndAddDropVnodeAction(pMnode, pTrans, pDb, pVgroup, &delGid, true) != 0) return -1;
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, pVgroup) != 0) return -1;
|
||||
if (pVgroup->replica == 1) {
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, pVgroup, pVgroup->vnodeGid[0].dnodeId) != 0) return -1;
|
||||
if (mndAddDropVnodeAction(pMnode, pTrans, pDb, pVgroup, &delGid, true) != 0) return -1;
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, pVgroup) != 0) return -1;
|
||||
} else if (pVgroup->replica == 3) {
|
||||
if (mndAddDropVnodeAction(pMnode, pTrans, pDb, pVgroup, &delGid, true) != 0) return -1;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, pVgroup, pVgroup->vnodeGid[0].dnodeId) != 0) return -1;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, pVgroup, pVgroup->vnodeGid[1].dnodeId) != 0) return -1;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, pVgroup, pVgroup->vnodeGid[2].dnodeId) != 0) return -1;
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, pVgroup) != 0) return -1;
|
||||
} else {
|
||||
mError("vgId:%d, failed to remove 1 vnode since invalid replica:%d", pVgroup->vgId, pVgroup->replica);
|
||||
terrno = TSDB_CODE_MND_APP_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1328,9 +1366,6 @@ _OVER:
|
|||
}
|
||||
|
||||
static int32_t mndProcessRedistributeVgroupMsg(SRpcMsg *pReq) {
|
||||
#if 1
|
||||
return TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
#else
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SDnodeObj *pNew1 = NULL;
|
||||
SDnodeObj *pNew2 = NULL;
|
||||
|
@ -1524,7 +1559,6 @@ _OVER:
|
|||
mndReleaseDb(pMnode, pDb);
|
||||
|
||||
return code;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int32_t mndCheckDnodeMemory(SMnode *pMnode, SDbObj *pOldDb, SDbObj *pNewDb, SVgObj *pOldVgroup,
|
||||
|
@ -1580,10 +1614,11 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
|
|||
if (mndAddVnodeToVgroup(pMnode, &newVgroup, pArray) != 0) return -1;
|
||||
if (mndAddVnodeToVgroup(pMnode, &newVgroup, pArray) != 0) return -1;
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &newVgroup.vnodeGid[1]) != 0) return -1;
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &newVgroup.vnodeGid[2]) != 0) return -1;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, &newVgroup, newVgroup.vnodeGid[0].dnodeId) != 0)
|
||||
return -1;
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, &newVgroup) != 0) return -1;
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &newVgroup.vnodeGid[2]) != 0) return -1;
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, &newVgroup) != 0) return -1;
|
||||
} else if (newVgroup.replica == 3 && pNewDb->cfg.replications == 1) {
|
||||
mInfo("db:%s, vgId:%d, will remove 2 vnodes, vn:0 dnode:%d vn:1 dnode:%d vn:2 dnode:%d", pVgroup->dbName,
|
||||
pVgroup->vgId, pVgroup->vnodeGid[0].dnodeId, pVgroup->vnodeGid[1].dnodeId, pVgroup->vnodeGid[2].dnodeId);
|
||||
|
@ -1593,6 +1628,7 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
|
|||
if (mndRemoveVnodeFromVgroup(pMnode, &newVgroup, pArray, &del1) != 0) return -1;
|
||||
if (mndRemoveVnodeFromVgroup(pMnode, &newVgroup, pArray, &del2) != 0) return -1;
|
||||
if (mndAddDropVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &del1, true) != 0) return -1;
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, &newVgroup) != 0) return -1;
|
||||
if (mndAddDropVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &del2, true) != 0) return -1;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, &newVgroup, newVgroup.vnodeGid[0].dnodeId) != 0)
|
||||
return -1;
|
||||
|
@ -1860,7 +1896,7 @@ static int32_t mndProcessBalanceVgroupMsg(SRpcMsg *pReq) {
|
|||
SMnode *pMnode = pReq->info.node;
|
||||
int32_t code = -1;
|
||||
SArray *pArray = NULL;
|
||||
void *pIter = NULL;
|
||||
void *pIter = NULL;
|
||||
int64_t curMs = taosGetTimestampMs();
|
||||
|
||||
SBalanceVgroupReq req = {0};
|
||||
|
|
|
@ -1062,7 +1062,7 @@ int32_t metaFilterCreateTime(SMeta *pMeta, SMetaFltParam *param, SArray *pUids)
|
|||
if (tdbTbcMoveTo(pCursor->pCur, &ctimeKey, sizeof(ctimeKey), &cmp) < 0) {
|
||||
goto END;
|
||||
}
|
||||
bool first = true;
|
||||
|
||||
int32_t valid = 0;
|
||||
while (1) {
|
||||
void *entryKey = NULL;
|
||||
|
@ -1074,7 +1074,13 @@ int32_t metaFilterCreateTime(SMeta *pMeta, SMetaFltParam *param, SArray *pUids)
|
|||
|
||||
int32_t cmp = (*param->filterFunc)((void *)&p->ctime, (void *)&pCtimeKey->ctime, param->type);
|
||||
if (cmp == 0) taosArrayPush(pUids, &p->uid);
|
||||
if (cmp == -1) break;
|
||||
|
||||
if (param->reverse == false) {
|
||||
if (cmp == -1) break;
|
||||
} else if (param->reverse) {
|
||||
if (cmp == 1) break;
|
||||
}
|
||||
|
||||
valid = param->reverse ? tdbTbcMoveToPrev(pCursor->pCur) : tdbTbcMoveToNext(pCursor->pCur);
|
||||
if (valid < 0) break;
|
||||
}
|
||||
|
|
|
@ -572,8 +572,12 @@ static int metaBuildCtimeIdxKey(SCtimeIdxKey *ctimeKey, const SMetaEntry *pME) {
|
|||
}
|
||||
|
||||
static int metaBuildNColIdxKey(SNcolIdxKey *ncolKey, const SMetaEntry *pME) {
|
||||
ncolKey->ncol = pME->ntbEntry.schemaRow.nCols;
|
||||
ncolKey->uid = pME->uid;
|
||||
if (pME->type == TSDB_NORMAL_TABLE) {
|
||||
ncolKey->ncol = pME->ntbEntry.schemaRow.nCols;
|
||||
ncolKey->uid = pME->uid;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -777,9 +781,13 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
terrno = TSDB_CODE_VND_INVALID_TABLE_ACTION;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// search the column to add/drop/update
|
||||
pSchema = &entry.ntbEntry.schemaRow;
|
||||
|
||||
// save old entry
|
||||
SMetaEntry oldEntry = {.type = TSDB_NORMAL_TABLE, .uid = entry.uid};
|
||||
oldEntry.ntbEntry.schemaRow.nCols = pSchema->nCols;
|
||||
|
||||
int32_t iCol = 0;
|
||||
for (;;) {
|
||||
pColumn = NULL;
|
||||
|
@ -853,6 +861,10 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
pColumn->bytes = pAlterTbReq->colModBytes;
|
||||
break;
|
||||
case TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME:
|
||||
if (pAlterTbReq->colNewName == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto _err;
|
||||
}
|
||||
if (pColumn == NULL) {
|
||||
terrno = TSDB_CODE_VND_TABLE_COL_NOT_EXISTS;
|
||||
goto _err;
|
||||
|
@ -868,6 +880,9 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
|
||||
entry.version = version;
|
||||
|
||||
metaDeleteNcolIdx(pMeta, &oldEntry);
|
||||
metaUpdateNcolIdx(pMeta, &entry);
|
||||
|
||||
// do actual write
|
||||
metaWLock(pMeta);
|
||||
|
||||
|
|
|
@ -37,6 +37,8 @@ static void saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* pRea
|
|||
int32_t numOfRows = pBlock->info.rows;
|
||||
|
||||
if (HASTYPE(pReader->type, CACHESCAN_RETRIEVE_LAST)) {
|
||||
bool allNullRow = true;
|
||||
|
||||
for (int32_t i = 0; i < pReader->numOfCols; ++i) {
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
|
||||
SFirstLastRes* p = (SFirstLastRes*)varDataVal(pRes[i]);
|
||||
|
@ -46,12 +48,15 @@ static void saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* pRea
|
|||
p->ts = pColVal->ts;
|
||||
p->bytes = TSDB_KEYSIZE;
|
||||
*(int64_t*)p->buf = pColVal->ts;
|
||||
allNullRow = false;
|
||||
} else {
|
||||
int32_t slotId = slotIds[i];
|
||||
SLastCol* pColVal = (SLastCol*)taosArrayGet(pRow, slotId);
|
||||
|
||||
p->ts = pColVal->ts;
|
||||
p->isNull = !COL_VAL_IS_VALUE(&pColVal->colVal);
|
||||
allNullRow = p->isNull & allNullRow;
|
||||
|
||||
if (!p->isNull) {
|
||||
if (IS_VAR_DATA_TYPE(pColVal->colVal.type)) {
|
||||
varDataSetLen(p->buf, pColVal->colVal.value.nData);
|
||||
|
@ -69,6 +74,8 @@ static void saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* pRea
|
|||
varDataSetLen(pRes[i], pColInfoData->info.bytes - VARSTR_HEADER_SIZE);
|
||||
colDataAppend(pColInfoData, numOfRows, (const char*)pRes[i], false);
|
||||
}
|
||||
|
||||
pBlock->info.rows += allNullRow? 0:1;
|
||||
} else {
|
||||
ASSERT(HASTYPE(pReader->type, CACHESCAN_RETRIEVE_LAST_ROW));
|
||||
|
||||
|
@ -96,9 +103,9 @@ static void saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* pRea
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pBlock->info.rows += 1;
|
||||
pBlock->info.rows += 1;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t tsdbCacherowsReaderOpen(void* pVnode, int32_t type, SArray* pTableIdList, int32_t numOfCols, void** pReader) {
|
||||
|
|
|
@ -111,7 +111,7 @@ typedef struct SDataBlockIter {
|
|||
int32_t index;
|
||||
SArray* blockList; // SArray<SFileDataBlockInfo>
|
||||
int32_t order;
|
||||
SDataBlk block; // current SDataBlk data
|
||||
SDataBlk block; // current SDataBlk data
|
||||
SHashObj* pTableMap;
|
||||
} SDataBlockIter;
|
||||
|
||||
|
@ -1209,19 +1209,19 @@ static int32_t dataBlockPartiallyRequired(STimeWindow* pWindow, SVersionRange* p
|
|||
(pVerRange->maxVer < pBlock->maxVer && pVerRange->maxVer >= pBlock->minVer);
|
||||
}
|
||||
|
||||
static SDataBlk* getNeighborBlockOfSameTable(SFileDataBlockInfo* pFBlockInfo, STableBlockScanInfo* pTableBlockScanInfo,
|
||||
static SDataBlk* getNeighborBlockOfSameTable(SFileDataBlockInfo* pBlockInfo, STableBlockScanInfo* pTableBlockScanInfo,
|
||||
int32_t* nextIndex, int32_t order) {
|
||||
bool asc = ASCENDING_TRAVERSE(order);
|
||||
if (asc && pFBlockInfo->tbBlockIdx >= taosArrayGetSize(pTableBlockScanInfo->pBlockList) - 1) {
|
||||
if (asc && pBlockInfo->tbBlockIdx >= taosArrayGetSize(pTableBlockScanInfo->pBlockList) - 1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!asc && pFBlockInfo->tbBlockIdx == 0) {
|
||||
if (!asc && pBlockInfo->tbBlockIdx == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t step = asc ? 1 : -1;
|
||||
*nextIndex = pFBlockInfo->tbBlockIdx + step;
|
||||
*nextIndex = pBlockInfo->tbBlockIdx + step;
|
||||
|
||||
SDataBlk* pBlock = taosMemoryCalloc(1, sizeof(SDataBlk));
|
||||
int32_t* indexInMapdata = taosArrayGet(pTableBlockScanInfo->pBlockList, *nextIndex);
|
||||
|
@ -1631,7 +1631,7 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
|||
}
|
||||
|
||||
code = doMergeRowsInBuf(pIter, pBlockScanInfo->uid, k.ts, pBlockScanInfo->delSkyline, &merge, pReader);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
if (code != TSDB_CODE_SUCCESS || merge.pTSchema == NULL) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
@ -1910,6 +1910,10 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
|||
|
||||
if (minKey == k.ts) {
|
||||
if (init) {
|
||||
if (merge.pTSchema == NULL) {
|
||||
return code;
|
||||
}
|
||||
|
||||
tRowMerge(&merge, pRow);
|
||||
} else {
|
||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
||||
|
@ -1964,7 +1968,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
|||
tRowMerge(&merge, &fRow1);
|
||||
} else {
|
||||
init = true;
|
||||
int32_t code = tRowMergerInit(&merge, &fRow1, pReader->pSchema);
|
||||
code = tRowMergerInit(&merge, &fRow1, pReader->pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -1975,17 +1979,24 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
|||
if (minKey == key) {
|
||||
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex);
|
||||
if (!init) {
|
||||
int32_t code = tRowMergerInit(&merge, &fRow, pReader->pSchema);
|
||||
code = tRowMergerInit(&merge, &fRow, pReader->pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
} else {
|
||||
if (merge.pTSchema == NULL) {
|
||||
return code;
|
||||
}
|
||||
tRowMerge(&merge, &fRow);
|
||||
}
|
||||
doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge);
|
||||
}
|
||||
}
|
||||
|
||||
if (merge.pTSchema == NULL) {
|
||||
return code;
|
||||
}
|
||||
|
||||
code = tRowMergerGetRow(&merge, &pTSRow);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
|
@ -3232,7 +3243,7 @@ int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* p
|
|||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
||||
|
||||
int32_t code = tRowMergerInit(&merge, pRow, pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
if (code != TSDB_CODE_SUCCESS || merge.pTSchema == NULL) {
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -3757,6 +3768,15 @@ bool tsdbNextDataBlock(STsdbReader* pReader) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool tsdbTableNextDataBlock(STsdbReader* pReader, uint64_t uid) {
|
||||
STableBlockScanInfo* pBlockScanInfo = taosHashGet(pReader->status.pTableMap, &uid, sizeof(uid));
|
||||
if (pBlockScanInfo == NULL) { // no data block for the table of given uid
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void setBlockInfo(STsdbReader* pReader, SDataBlockInfo* pDataBlockInfo) {
|
||||
ASSERT(pDataBlockInfo != NULL && pReader != NULL);
|
||||
pDataBlockInfo->rows = pReader->pResBlock->info.rows;
|
||||
|
|
|
@ -107,7 +107,7 @@ int vnodeSaveInfo(const char *dir, const SVnodeInfo *pInfo) {
|
|||
// free info binary
|
||||
taosMemoryFree(data);
|
||||
|
||||
vInfo("vgId:%d, vnode info is saved, fname:%s", pInfo->config.vgId, fname);
|
||||
vInfo("vgId:%d, vnode info is saved, fname:%s replica:%d", pInfo->config.vgId, fname, pInfo->config.syncCfg.replicaNum);
|
||||
|
||||
return 0;
|
||||
|
||||
|
|
|
@ -87,12 +87,19 @@ int32_t vnodeAlter(const char *path, SAlterVnodeReplicaReq *pReq, STfs *pTfs) {
|
|||
vInfo("vgId:%d, save config, replica:%d ep:%s:%u", pReq->vgId, i, pNode->nodeFqdn, pNode->nodePort);
|
||||
}
|
||||
|
||||
info.config.syncCfg = *pCfg;
|
||||
ret = vnodeSaveInfo(dir, &info);
|
||||
if (ret < 0) {
|
||||
vError("vgId:%d, failed to save vnode config since %s", pReq->vgId, tstrerror(terrno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = vnodeCommitInfo(dir, &info);
|
||||
if (ret < 0) {
|
||||
vError("vgId:%d, failed to commit vnode config since %s", pReq->vgId, tstrerror(terrno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
vInfo("vgId:%d, vnode config is saved", info.config.vgId);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -563,9 +563,7 @@ static int32_t vnodeSnapshotDoWrite(struct SSyncFSM *pFsm, void *pWriter, void *
|
|||
#endif
|
||||
}
|
||||
|
||||
static void vnodeLeaderTransfer(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) {
|
||||
SVnode *pVnode = pFsm->data;
|
||||
}
|
||||
static void vnodeLeaderTransfer(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) {}
|
||||
|
||||
static void vnodeRestoreFinish(struct SSyncFSM *pFsm) {
|
||||
SVnode *pVnode = pFsm->data;
|
||||
|
@ -605,12 +603,14 @@ static void vnodeBecomeLeader(struct SSyncFSM *pFsm) {
|
|||
SVnode *pVnode = pFsm->data;
|
||||
vDebug("vgId:%d, become leader", pVnode->config.vgId);
|
||||
|
||||
// taosThreadMutexLock(&pVnode->lock);
|
||||
// if (pVnode->blocked) {
|
||||
// pVnode->blocked = false;
|
||||
// tsem_post(&pVnode->syncSem);
|
||||
// }
|
||||
// taosThreadMutexUnlock(&pVnode->lock);
|
||||
#if 0
|
||||
taosThreadMutexLock(&pVnode->lock);
|
||||
if (pVnode->blocked) {
|
||||
pVnode->blocked = false;
|
||||
tsem_post(&pVnode->syncSem);
|
||||
}
|
||||
taosThreadMutexUnlock(&pVnode->lock);
|
||||
#endif
|
||||
}
|
||||
|
||||
static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) {
|
||||
|
@ -638,10 +638,8 @@ static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) {
|
|||
int32_t vnodeSyncOpen(SVnode *pVnode, char *path) {
|
||||
SSyncInfo syncInfo = {
|
||||
.snapshotStrategy = SYNC_STRATEGY_WAL_FIRST,
|
||||
//.snapshotStrategy = SYNC_STRATEGY_NO_SNAPSHOT,
|
||||
.batchSize = 1,
|
||||
.vgId = pVnode->config.vgId,
|
||||
.isStandBy = pVnode->config.standby,
|
||||
.syncCfg = pVnode->config.syncCfg,
|
||||
.pWal = pVnode->pWal,
|
||||
.msgcb = NULL,
|
||||
|
@ -653,6 +651,13 @@ int32_t vnodeSyncOpen(SVnode *pVnode, char *path) {
|
|||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s%ssync", path, TD_DIRSEP);
|
||||
syncInfo.pFsm = vnodeSyncMakeFsm(pVnode);
|
||||
|
||||
SSyncCfg *pCfg = &syncInfo.syncCfg;
|
||||
vInfo("vgId:%d, start to open sync, replica:%d selfIndex:%d", pVnode->config.vgId, pCfg->replicaNum, pCfg->myIndex);
|
||||
for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
|
||||
SNodeInfo *pNode = &pCfg->nodeInfo[i];
|
||||
vInfo("vgId:%d, index:%d ep:%s:%u", pVnode->config.vgId, i, pNode->nodeFqdn, pNode->nodePort);
|
||||
}
|
||||
|
||||
pVnode->sync = syncOpen(&syncInfo);
|
||||
if (pVnode->sync <= 0) {
|
||||
vError("vgId:%d, failed to open sync since %s", pVnode->config.vgId, terrstr());
|
||||
|
@ -666,11 +671,15 @@ int32_t vnodeSyncOpen(SVnode *pVnode, char *path) {
|
|||
}
|
||||
|
||||
void vnodeSyncStart(SVnode *pVnode) {
|
||||
vDebug("vgId:%d, start sync", pVnode->config.vgId);
|
||||
syncSetMsgCb(pVnode->sync, &pVnode->msgCb);
|
||||
syncStart(pVnode->sync);
|
||||
}
|
||||
|
||||
void vnodeSyncClose(SVnode *pVnode) { syncStop(pVnode->sync); }
|
||||
void vnodeSyncClose(SVnode *pVnode) {
|
||||
vDebug("vgId:%d, close sync", pVnode->config.vgId);
|
||||
syncStop(pVnode->sync);
|
||||
}
|
||||
|
||||
bool vnodeIsRoleLeader(SVnode *pVnode) { return syncGetMyRole(pVnode->sync) == TAOS_SYNC_STATE_LEADER; }
|
||||
|
||||
|
|
|
@ -685,7 +685,12 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i
|
|||
|
||||
EXPLAIN_ROW_NEW(level + 1, EXPLAIN_ON_CONDITIONS_FORMAT);
|
||||
QRY_ERR_RET(
|
||||
nodesNodeToSQL(pJoinNode->pOnConditions, tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen));
|
||||
nodesNodeToSQL(pJoinNode->pMergeCondition, tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen));
|
||||
if (pJoinNode->pOnConditions) {
|
||||
EXPLAIN_ROW_APPEND(" AND ");
|
||||
QRY_ERR_RET(
|
||||
nodesNodeToSQL(pJoinNode->pOnConditions, tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, &tlen));
|
||||
}
|
||||
EXPLAIN_ROW_END();
|
||||
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1));
|
||||
}
|
||||
|
|
|
@ -74,7 +74,6 @@ typedef struct SResultRowPosition {
|
|||
typedef struct SResKeyPos {
|
||||
SResultRowPosition pos;
|
||||
uint64_t groupId;
|
||||
// char parTbName[TSDB_TABLE_NAME_LEN];
|
||||
char key[];
|
||||
} SResKeyPos;
|
||||
|
||||
|
@ -84,6 +83,18 @@ typedef struct SResultRowInfo {
|
|||
SList* openWindow;
|
||||
} SResultRowInfo;
|
||||
|
||||
typedef struct SColMatchItem {
|
||||
int32_t colId;
|
||||
int32_t srcSlotId;
|
||||
int32_t dstSlotId;
|
||||
bool needOutput;
|
||||
} SColMatchItem;
|
||||
|
||||
typedef struct SColMatchInfo {
|
||||
SArray* pList; // SArray<SColMatchItem>
|
||||
int32_t matchType; // determinate the source according to col id or slot id
|
||||
} SColMatchInfo;
|
||||
|
||||
struct SqlFunctionCtx;
|
||||
|
||||
size_t getResultRowSize(struct SqlFunctionCtx* pCtx, int32_t numOfOutput);
|
||||
|
@ -121,8 +132,8 @@ size_t getTableTagsBufLen(const SNodeList* pGroups);
|
|||
|
||||
SArray* createSortInfo(SNodeList* pNodeList);
|
||||
SArray* extractPartitionColInfo(SNodeList* pNodeList);
|
||||
SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNodeList, int32_t* numOfOutputCols,
|
||||
int32_t type);
|
||||
int32_t extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNodeList, int32_t* numOfOutputCols,
|
||||
int32_t type, SColMatchInfo* pMatchInfo);
|
||||
|
||||
void createExprFromOneNode(SExprInfo* pExp, SNode* pNode, int16_t slotId);
|
||||
void createExprFromTargetNode(SExprInfo* pExp, STargetNode* pTargetNode);
|
||||
|
|
|
@ -46,12 +46,7 @@ extern "C" {
|
|||
|
||||
typedef int32_t (*__block_search_fn_t)(char* data, int32_t num, int64_t key, int32_t order);
|
||||
|
||||
#define IS_QUERY_KILLED(_q) ((_q)->code == TSDB_CODE_TSC_QUERY_CANCELLED)
|
||||
#define Q_STATUS_EQUAL(p, s) (((p) & (s)) != 0u)
|
||||
#define QUERY_IS_ASC_QUERY(q) (GET_FORWARD_DIRECTION_FACTOR((q)->order.order) == QUERY_ASC_FORWARD_STEP)
|
||||
|
||||
#define NEEDTO_COMPRESS_QUERY(size) ((size) > tsCompressColData ? 1 : 0)
|
||||
|
||||
#define Q_STATUS_EQUAL(p, s) (((p) & (s)) != 0u)
|
||||
#define IS_VALID_SESSION_WIN(winInfo) ((winInfo).sessionWin.win.skey > 0)
|
||||
#define SET_SESSION_WIN_INVALID(winInfo) ((winInfo).sessionWin.win.skey = INT64_MIN)
|
||||
#define IS_INVALID_SESSION_WIN_KEY(winKey) ((winKey).win.skey <= 0)
|
||||
|
@ -292,15 +287,6 @@ typedef struct SExchangeInfo {
|
|||
SLimitInfo limitInfo;
|
||||
} SExchangeInfo;
|
||||
|
||||
typedef struct SColMatchInfo {
|
||||
int32_t srcSlotId; // source slot id
|
||||
int32_t colId;
|
||||
int32_t targetSlotId;
|
||||
bool output; // todo remove this?
|
||||
bool reserved;
|
||||
int32_t matchType; // determinate the source according to col id or slot id
|
||||
} SColMatchInfo;
|
||||
|
||||
typedef struct SScanInfo {
|
||||
int32_t numOfAsc;
|
||||
int32_t numOfDesc;
|
||||
|
@ -342,7 +328,7 @@ typedef struct STableScanInfo {
|
|||
SNode* pFilterNode; // filter info, which is push down by optimizer
|
||||
|
||||
SSDataBlock* pResBlock;
|
||||
SArray* pColMatchInfo;
|
||||
SColMatchInfo matchInfo;
|
||||
SExprSupp pseudoSup;
|
||||
SQueryTableDataCond cond;
|
||||
int32_t scanFlag; // table scan flag to denote if it is a repeat/reverse/main scan
|
||||
|
@ -368,10 +354,9 @@ typedef struct STableMergeScanInfo {
|
|||
uint32_t sortBufSize; // max buffer size for in-memory sort
|
||||
SArray* pSortInfo;
|
||||
SSortHandle* pSortHandle;
|
||||
|
||||
SSDataBlock* pSortInputBlock;
|
||||
int64_t startTs; // sort start time
|
||||
SArray* sortSourceParams;
|
||||
SSDataBlock* pSortInputBlock;
|
||||
int64_t startTs; // sort start time
|
||||
SArray* sortSourceParams;
|
||||
|
||||
SFileBlockLoadRecorder readRecorder;
|
||||
int64_t numOfRows;
|
||||
|
@ -383,43 +368,40 @@ typedef struct STableMergeScanInfo {
|
|||
int32_t* rowEntryInfoOffset;
|
||||
SExprInfo* pExpr;
|
||||
SSDataBlock* pResBlock;
|
||||
SArray* pColMatchInfo;
|
||||
SColMatchInfo matchInfo;
|
||||
int32_t numOfOutput;
|
||||
|
||||
SExprSupp pseudoSup;
|
||||
|
||||
SQueryTableDataCond cond;
|
||||
int32_t scanFlag; // table scan flag to denote if it is a repeat/reverse/main scan
|
||||
int32_t dataBlockLoadFlag;
|
||||
SExprSupp pseudoSup;
|
||||
SQueryTableDataCond cond;
|
||||
int32_t scanFlag; // table scan flag to denote if it is a repeat/reverse/main scan
|
||||
int32_t dataBlockLoadFlag;
|
||||
// if the upstream is an interval operator, the interval info is also kept here to get the time
|
||||
// window to check if current data block needs to be loaded.
|
||||
SInterval interval;
|
||||
SSampleExecInfo sample; // sample execution info
|
||||
|
||||
SSortExecInfo sortExecInfo;
|
||||
SSortExecInfo sortExecInfo;
|
||||
} STableMergeScanInfo;
|
||||
|
||||
typedef struct STagScanInfo {
|
||||
SColumnInfo* pCols;
|
||||
SSDataBlock* pRes;
|
||||
SArray* pColMatchInfo;
|
||||
SColMatchInfo matchInfo;
|
||||
int32_t curPos;
|
||||
SReadHandle readHandle;
|
||||
STableListInfo* pTableList;
|
||||
} STagScanInfo;
|
||||
|
||||
typedef struct SLastrowScanInfo {
|
||||
SSDataBlock* pRes;
|
||||
SReadHandle readHandle;
|
||||
void* pLastrowReader;
|
||||
SArray* pColMatchInfo;
|
||||
int32_t* pSlotIds;
|
||||
SExprSupp pseudoExprSup;
|
||||
int32_t retrieveType;
|
||||
int32_t currentGroupIndex;
|
||||
SSDataBlock* pBufferredRes;
|
||||
SArray* pUidList;
|
||||
int32_t indexOfBufferedRes;
|
||||
SSDataBlock* pRes;
|
||||
SReadHandle readHandle;
|
||||
void* pLastrowReader;
|
||||
SColMatchInfo matchInfo;
|
||||
int32_t* pSlotIds;
|
||||
SExprSupp pseudoExprSup;
|
||||
int32_t retrieveType;
|
||||
int32_t currentGroupIndex;
|
||||
SSDataBlock* pBufferredRes;
|
||||
SArray* pUidList;
|
||||
int32_t indexOfBufferedRes;
|
||||
} SLastrowScanInfo;
|
||||
|
||||
typedef enum EStreamScanMode {
|
||||
|
@ -486,16 +468,16 @@ typedef struct STimeWindowAggSupp {
|
|||
} STimeWindowAggSupp;
|
||||
|
||||
typedef struct SStreamScanInfo {
|
||||
uint64_t tableUid; // queried super table uid
|
||||
SExprInfo* pPseudoExpr;
|
||||
int32_t numOfPseudoExpr;
|
||||
SExprSupp tbnameCalSup;
|
||||
SExprSupp tagCalSup;
|
||||
int32_t primaryTsIndex; // primary time stamp slot id
|
||||
SReadHandle readHandle;
|
||||
SInterval interval; // if the upstream is an interval operator, the interval info is also kept here.
|
||||
SArray* pColMatchInfo; //
|
||||
SNode* pCondition;
|
||||
uint64_t tableUid; // queried super table uid
|
||||
SExprInfo* pPseudoExpr;
|
||||
int32_t numOfPseudoExpr;
|
||||
SExprSupp tbnameCalSup;
|
||||
SExprSupp tagCalSup;
|
||||
int32_t primaryTsIndex; // primary time stamp slot id
|
||||
SReadHandle readHandle;
|
||||
SInterval interval; // if the upstream is an interval operator, the interval info is also kept here.
|
||||
SColMatchInfo matchInfo;
|
||||
SNode* pCondition;
|
||||
|
||||
SArray* pBlockLists; // multiple SSDatablock.
|
||||
SSDataBlock* pRes; // result SSDataBlock
|
||||
|
@ -563,7 +545,7 @@ typedef struct SSysTableScanInfo {
|
|||
SNode* pCondition; // db_name filter condition, to discard data that are not in current database
|
||||
SMTbCursor* pCur; // cursor for iterate the local table meta store.
|
||||
SSysTableIndex* pIdx; // idx for local table meta
|
||||
SArray* scanCols; // SArray<int16_t> scan column id list
|
||||
SColMatchInfo matchInfo;
|
||||
SName name;
|
||||
SSDataBlock* pRes;
|
||||
int64_t numOfBlocks; // extract basic running information.
|
||||
|
@ -683,7 +665,7 @@ typedef struct SFillOperatorInfo {
|
|||
SSDataBlock* existNewGroupBlock;
|
||||
STimeWindow win;
|
||||
SNode* pCondition;
|
||||
SArray* pColMatchColInfo;
|
||||
SColMatchInfo matchInfo;
|
||||
int32_t primaryTsCol;
|
||||
int32_t primarySrcSlotId;
|
||||
uint64_t curGroupId; // current handled group id
|
||||
|
@ -822,7 +804,7 @@ typedef struct SStreamFillOperatorInfo {
|
|||
int32_t srcDelRowIndex;
|
||||
SSDataBlock* pDelRes;
|
||||
SNode* pCondition;
|
||||
SArray* pColMatchColInfo;
|
||||
SColMatchInfo matchInfo;
|
||||
int32_t primaryTsCol;
|
||||
int32_t primarySrcSlotId;
|
||||
SStreamFillInfo* pFillInfo;
|
||||
|
@ -866,7 +848,7 @@ typedef struct SSortOperatorInfo {
|
|||
uint32_t sortBufSize; // max buffer size for in-memory sort
|
||||
SArray* pSortInfo;
|
||||
SSortHandle* pSortHandle;
|
||||
SArray* pColMatchInfo; // for index map from table scan output
|
||||
SColMatchInfo matchInfo;
|
||||
int32_t bufPageSize;
|
||||
int64_t startTs; // sort start time
|
||||
uint64_t sortElapsed; // sort elapsed time, time to flush to disk not included.
|
||||
|
@ -899,8 +881,7 @@ typedef struct SJoinOperatorInfo {
|
|||
void doDestroyExchangeOperatorInfo(void* param);
|
||||
|
||||
SOperatorFpSet createOperatorFpSet(__optr_open_fn_t openFn, __optr_fn_t nextFn, __optr_fn_t streamFn,
|
||||
__optr_fn_t cleanup, __optr_close_fn_t closeFn, __optr_encode_fn_t encode,
|
||||
__optr_decode_fn_t decode, __optr_explain_fn_t explain);
|
||||
__optr_fn_t cleanup, __optr_close_fn_t closeFn, __optr_explain_fn_t explain);
|
||||
|
||||
int32_t operatorDummyOpenFn(SOperatorInfo* pOperator);
|
||||
int32_t appendDownstream(SOperatorInfo* p, SOperatorInfo** pDownstream, int32_t num);
|
||||
|
@ -936,7 +917,7 @@ int32_t getTableScanInfo(SOperatorInfo* pOperator, int32_t* order, int32_t* scan
|
|||
int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, uint32_t* defaultBufsz);
|
||||
|
||||
void doSetOperatorCompleted(SOperatorInfo* pOperator);
|
||||
void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock, const SArray* pColMatchInfo, SFilterInfo* pFilterInfo);
|
||||
void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock, SColMatchInfo* pColMatchInfo, SFilterInfo* pFilterInfo);
|
||||
int32_t addTagPseudoColumnData(SReadHandle* pHandle, SExprInfo* pPseudoExpr, int32_t numOfPseudoExpr,
|
||||
SSDataBlock* pBlock, const char* idStr);
|
||||
|
||||
|
|
|
@ -27,7 +27,8 @@
|
|||
|
||||
static SSDataBlock* doScanCache(SOperatorInfo* pOperator);
|
||||
static void destroyLastrowScanOperator(void* param);
|
||||
static int32_t extractTargetSlotId(const SArray* pColMatchInfo, SExecTaskInfo* pTaskInfo, int32_t** pSlotIds);
|
||||
static int32_t extractCacheScanSlotId(const SArray* pColMatchInfo, SExecTaskInfo* pTaskInfo, int32_t** pSlotIds);
|
||||
static int32_t removeRedundantTsCol(SLastRowScanPhysiNode* pScanNode, SColMatchInfo* pColMatchInfo);
|
||||
|
||||
SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SReadHandle* readHandle,
|
||||
SExecTaskInfo* pTaskInfo) {
|
||||
|
@ -40,12 +41,15 @@ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SRe
|
|||
}
|
||||
|
||||
pInfo->readHandle = *readHandle;
|
||||
pInfo->pRes = createResDataBlock(pScanNode->scan.node.pOutputDataBlockDesc);
|
||||
|
||||
SDataBlockDescNode* pDescNode = pScanNode->scan.node.pOutputDataBlockDesc;
|
||||
pInfo->pRes = createResDataBlock(pDescNode);
|
||||
|
||||
int32_t numOfCols = 0;
|
||||
pInfo->pColMatchInfo = extractColMatchInfo(pScanNode->scan.pScanCols, pScanNode->scan.node.pOutputDataBlockDesc,
|
||||
&numOfCols, COL_MATCH_FROM_COL_ID);
|
||||
code = extractTargetSlotId(pInfo->pColMatchInfo, pTaskInfo, &pInfo->pSlotIds);
|
||||
code = extractColMatchInfo(pScanNode->scan.pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID, &pInfo->matchInfo);
|
||||
removeRedundantTsCol(pScanNode, &pInfo->matchInfo);
|
||||
|
||||
code = extractCacheScanSlotId(pInfo->matchInfo.pList, pTaskInfo, &pInfo->pSlotIds);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
@ -60,7 +64,7 @@ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SRe
|
|||
if (taosArrayGetSize(pTableList->pGroupList) == taosArrayGetSize(pTableList->pTableList)) {
|
||||
pInfo->retrieveType = CACHESCAN_RETRIEVE_TYPE_ALL|(pScanNode->ignoreNull? CACHESCAN_RETRIEVE_LAST:CACHESCAN_RETRIEVE_LAST_ROW);
|
||||
code = tsdbCacherowsReaderOpen(pInfo->readHandle.vnode, pInfo->retrieveType, pTableList->pTableList,
|
||||
taosArrayGetSize(pInfo->pColMatchInfo), &pInfo->pLastrowReader);
|
||||
taosArrayGetSize(pInfo->matchInfo.pList), &pInfo->pLastrowReader);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
@ -72,11 +76,9 @@ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SRe
|
|||
}
|
||||
|
||||
if (pScanNode->scan.pScanPseudoCols != NULL) {
|
||||
SExprSupp* pPseudoExpr = &pInfo->pseudoExprSup;
|
||||
|
||||
pPseudoExpr->pExprInfo = createExprInfo(pScanNode->scan.pScanPseudoCols, NULL, &pPseudoExpr->numOfExprs);
|
||||
pPseudoExpr->pCtx =
|
||||
createSqlFunctionCtx(pPseudoExpr->pExprInfo, pPseudoExpr->numOfExprs, &pPseudoExpr->rowEntryInfoOffset);
|
||||
SExprSupp* p = &pInfo->pseudoExprSup;
|
||||
p->pExprInfo = createExprInfo(pScanNode->scan.pScanPseudoCols, NULL, &p->numOfExprs);
|
||||
p->pCtx = createSqlFunctionCtx(p->pExprInfo, p->numOfExprs, &p->rowEntryInfoOffset);
|
||||
}
|
||||
|
||||
pOperator->name = "LastrowScanOperator";
|
||||
|
@ -88,7 +90,7 @@ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SRe
|
|||
pOperator->exprSupp.numOfExprs = taosArrayGetSize(pInfo->pRes->pDataBlock);
|
||||
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(operatorDummyOpenFn, doScanCache, NULL, NULL, destroyLastrowScanOperator, NULL, NULL, NULL);
|
||||
createOperatorFpSet(operatorDummyOpenFn, doScanCache, NULL, NULL, destroyLastrowScanOperator, NULL);
|
||||
|
||||
pOperator->cost.openCost = 0;
|
||||
return pOperator;
|
||||
|
@ -130,14 +132,16 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
|||
|
||||
// check for tag values
|
||||
int32_t resultRows = pInfo->pBufferredRes->info.rows;
|
||||
ASSERT(resultRows == taosArrayGetSize(pInfo->pUidList));
|
||||
|
||||
// the results may be null, if last values are all null
|
||||
ASSERT(resultRows == 0 || resultRows == taosArrayGetSize(pInfo->pUidList));
|
||||
pInfo->indexOfBufferedRes = 0;
|
||||
}
|
||||
|
||||
if (pInfo->indexOfBufferedRes < pInfo->pBufferredRes->info.rows) {
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pInfo->pColMatchInfo); ++i) {
|
||||
SColMatchInfo* pMatchInfo = taosArrayGet(pInfo->pColMatchInfo, i);
|
||||
int32_t slotId = pMatchInfo->targetSlotId;
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pInfo->matchInfo.pList); ++i) {
|
||||
SColMatchItem* pMatchInfo = taosArrayGet(pInfo->matchInfo.pList, i);
|
||||
int32_t slotId = pMatchInfo->dstSlotId;
|
||||
|
||||
SColumnInfoData* pSrc = taosArrayGet(pInfo->pBufferredRes->pDataBlock, slotId);
|
||||
SColumnInfoData* pDst = taosArrayGet(pInfo->pRes->pDataBlock, slotId);
|
||||
|
@ -184,7 +188,7 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
|||
SArray* pGroupTableList = taosArrayGetP(pTableList->pGroupList, pInfo->currentGroupIndex);
|
||||
|
||||
tsdbCacherowsReaderOpen(pInfo->readHandle.vnode, pInfo->retrieveType, pGroupTableList,
|
||||
taosArrayGetSize(pInfo->pColMatchInfo), &pInfo->pLastrowReader);
|
||||
taosArrayGetSize(pInfo->matchInfo.pList), &pInfo->pLastrowReader);
|
||||
taosArrayClear(pInfo->pUidList);
|
||||
|
||||
int32_t code = tsdbRetrieveCacheRows(pInfo->pLastrowReader, pInfo->pRes, pInfo->pSlotIds, pInfo->pUidList);
|
||||
|
@ -231,7 +235,7 @@ void destroyLastrowScanOperator(void* param) {
|
|||
blockDataDestroy(pInfo->pBufferredRes);
|
||||
taosMemoryFree(pInfo->pSlotIds);
|
||||
taosArrayDestroy(pInfo->pUidList);
|
||||
taosArrayDestroy(pInfo->pColMatchInfo);
|
||||
taosArrayDestroy(pInfo->matchInfo.pList);
|
||||
|
||||
if (pInfo->pLastrowReader != NULL) {
|
||||
pInfo->pLastrowReader = tsdbCacherowsReaderClose(pInfo->pLastrowReader);
|
||||
|
@ -240,7 +244,7 @@ void destroyLastrowScanOperator(void* param) {
|
|||
taosMemoryFreeClear(param);
|
||||
}
|
||||
|
||||
int32_t extractTargetSlotId(const SArray* pColMatchInfo, SExecTaskInfo* pTaskInfo, int32_t** pSlotIds) {
|
||||
int32_t extractCacheScanSlotId(const SArray* pColMatchInfo, SExecTaskInfo* pTaskInfo, int32_t** pSlotIds) {
|
||||
size_t numOfCols = taosArrayGetSize(pColMatchInfo);
|
||||
|
||||
*pSlotIds = taosMemoryMalloc(numOfCols * sizeof(int32_t));
|
||||
|
@ -248,21 +252,48 @@ int32_t extractTargetSlotId(const SArray* pColMatchInfo, SExecTaskInfo* pTaskInf
|
|||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SSchemaWrapper* pWrapper = pTaskInfo->schemaInfo.sw;
|
||||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColMatchInfo* pColMatch = taosArrayGet(pColMatchInfo, i);
|
||||
for (int32_t j = 0; j < pTaskInfo->schemaInfo.sw->nCols; ++j) {
|
||||
if (pColMatch->colId == pTaskInfo->schemaInfo.sw->pSchema[j].colId &&
|
||||
SColMatchItem* pColMatch = taosArrayGet(pColMatchInfo, i);
|
||||
for (int32_t j = 0; j < pWrapper->nCols; ++j) {
|
||||
if (pColMatch->colId == pWrapper->pSchema[j].colId &&
|
||||
pColMatch->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
(*pSlotIds)[pColMatch->targetSlotId] = -1;
|
||||
(*pSlotIds)[pColMatch->dstSlotId] = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (pColMatch->colId == pTaskInfo->schemaInfo.sw->pSchema[j].colId) {
|
||||
(*pSlotIds)[pColMatch->targetSlotId] = j;
|
||||
if (pColMatch->colId == pWrapper->pSchema[j].colId) {
|
||||
(*pSlotIds)[pColMatch->dstSlotId] = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t removeRedundantTsCol(SLastRowScanPhysiNode* pScanNode, SColMatchInfo* pColMatchInfo) {
|
||||
if (!pScanNode->ignoreNull) { // retrieve cached last value
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
size_t size = taosArrayGetSize(pColMatchInfo->pList);
|
||||
SArray* pMatchInfo = taosArrayInit(size, sizeof(SColMatchItem));
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SColMatchItem* pColInfo = taosArrayGet(pColMatchInfo->pList, i);
|
||||
|
||||
int32_t slotId = pColInfo->dstSlotId;
|
||||
SNodeList* pList = pScanNode->scan.node.pOutputDataBlockDesc->pSlots;
|
||||
|
||||
SSlotDescNode* pDesc = (SSlotDescNode*)nodesListGetNode(pList, slotId);
|
||||
if (pDesc->dataType.type != TSDB_DATA_TYPE_TIMESTAMP) {
|
||||
taosArrayPush(pMatchInfo, pColInfo);
|
||||
}
|
||||
}
|
||||
|
||||
taosArrayDestroy(pColMatchInfo->pList);
|
||||
pColMatchInfo->pList = pMatchInfo;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
|
@ -53,22 +53,6 @@ typedef struct SDataDeleterHandle {
|
|||
TdThreadMutex mutex;
|
||||
} SDataDeleterHandle;
|
||||
|
||||
static bool needCompress(const SSDataBlock* pData, int32_t numOfCols) {
|
||||
if (tsCompressColData < 0 || 0 == pData->info.rows) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int32_t col = 0; col < numOfCols; ++col) {
|
||||
SColumnInfoData* pColRes = taosArrayGet(pData->pDataBlock, col);
|
||||
int32_t colSize = pColRes->info.bytes * pData->info.rows;
|
||||
if (NEEDTO_COMPRESS_QUERY(colSize)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void toDataCacheEntry(SDataDeleterHandle* pHandle, const SInputData* pInput, SDataDeleterBuf* pBuf) {
|
||||
int32_t numOfCols = LIST_LENGTH(pHandle->pSchema->pSlots);
|
||||
|
||||
|
|
|
@ -51,22 +51,6 @@ typedef struct SDataDispatchHandle {
|
|||
TdThreadMutex mutex;
|
||||
} SDataDispatchHandle;
|
||||
|
||||
static bool needCompress(const SSDataBlock* pData, int32_t numOfCols) {
|
||||
if (tsCompressColData < 0 || 0 == pData->info.rows) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int32_t col = 0; col < numOfCols; ++col) {
|
||||
SColumnInfoData* pColRes = taosArrayGet(pData->pDataBlock, col);
|
||||
int32_t colSize = pColRes->info.bytes * pData->info.rows;
|
||||
if (NEEDTO_COMPRESS_QUERY(colSize)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
// data format:
|
||||
// +----------------+------------------+--------------+--------------+------------------+--------------------------------------------+------------------------------------+-------------+-----------+-------------+-----------+
|
||||
|
@ -86,7 +70,7 @@ static void toDataCacheEntry(SDataDispatchHandle* pHandle, const SInputData* pIn
|
|||
}
|
||||
}
|
||||
SDataCacheEntry* pEntry = (SDataCacheEntry*)pBuf->pData;
|
||||
pEntry->compressed = (int8_t)needCompress(pInput->pData, numOfCols);
|
||||
pEntry->compressed = 0;
|
||||
pEntry->numOfRows = pInput->pData->info.rows;
|
||||
pEntry->numOfCols = numOfCols;
|
||||
pEntry->dataLen = 0;
|
||||
|
|
|
@ -122,7 +122,7 @@ void initGroupedResultInfo(SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap, in
|
|||
|
||||
if (order == TSDB_ORDER_ASC || order == TSDB_ORDER_DESC) {
|
||||
__compar_fn_t fn = (order == TSDB_ORDER_ASC) ? resultrowComparAsc : resultrowComparDesc;
|
||||
int32_t size = POINTER_BYTES;
|
||||
int32_t size = POINTER_BYTES;
|
||||
taosSort(pGroupResInfo->pRows->pData, taosArrayGetSize(pGroupResInfo->pRows), size, fn);
|
||||
}
|
||||
|
||||
|
@ -752,8 +752,8 @@ end:
|
|||
}
|
||||
|
||||
static int tableUidCompare(const void* a, const void* b) {
|
||||
uint64_t u1 = *(uint64_t*)a;
|
||||
uint64_t u2 = *(uint64_t*)b;
|
||||
int64_t u1 = *(uint64_t*)a;
|
||||
int64_t u2 = *(uint64_t*)b;
|
||||
if (u1 == u2) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -1066,13 +1066,17 @@ SArray* extractPartitionColInfo(SNodeList* pNodeList) {
|
|||
return pList;
|
||||
}
|
||||
|
||||
SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNodeList, int32_t* numOfOutputCols,
|
||||
int32_t type) {
|
||||
size_t numOfCols = LIST_LENGTH(pNodeList);
|
||||
SArray* pList = taosArrayInit(numOfCols, sizeof(SColMatchInfo));
|
||||
int32_t extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNodeList, int32_t* numOfOutputCols,
|
||||
int32_t type, SColMatchInfo* pMatchInfo) {
|
||||
size_t numOfCols = LIST_LENGTH(pNodeList);
|
||||
int32_t code = 0;
|
||||
|
||||
pMatchInfo->matchType = type;
|
||||
|
||||
SArray* pList = taosArrayInit(numOfCols, sizeof(SColMatchItem));
|
||||
if (pList == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return code;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
|
@ -1080,12 +1084,10 @@ SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod
|
|||
if (nodeType(pNode->pExpr) == QUERY_NODE_COLUMN) {
|
||||
SColumnNode* pColNode = (SColumnNode*)pNode->pExpr;
|
||||
|
||||
SColMatchInfo c = {0};
|
||||
c.output = true;
|
||||
SColMatchItem c = {.needOutput = true};
|
||||
c.colId = pColNode->colId;
|
||||
c.srcSlotId = pColNode->slotId;
|
||||
c.matchType = type;
|
||||
c.targetSlotId = pNode->slotId;
|
||||
c.dstSlotId = pNode->slotId;
|
||||
taosArrayPush(pList, &c);
|
||||
}
|
||||
}
|
||||
|
@ -1102,10 +1104,10 @@ SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod
|
|||
continue;
|
||||
}
|
||||
|
||||
SColMatchInfo* info = NULL;
|
||||
SColMatchItem* info = NULL;
|
||||
for (int32_t j = 0; j < taosArrayGetSize(pList); ++j) {
|
||||
info = taosArrayGet(pList, j);
|
||||
if (info->targetSlotId == pNode->slotId) {
|
||||
if (info->dstSlotId == pNode->slotId) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1114,11 +1116,12 @@ SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod
|
|||
(*numOfOutputCols) += 1;
|
||||
} else if (info != NULL) {
|
||||
// select distinct tbname from stb where tbname='abc';
|
||||
info->output = false;
|
||||
info->needOutput = false;
|
||||
}
|
||||
}
|
||||
|
||||
return pList;
|
||||
pMatchInfo->pList = pList;
|
||||
return code;
|
||||
}
|
||||
|
||||
static SResSchema createResSchema(int32_t type, int32_t bytes, int32_t slotId, int32_t scale, int32_t precision,
|
||||
|
@ -1407,14 +1410,14 @@ void relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SArray
|
|||
int32_t i = 0, j = 0;
|
||||
while (i < numOfSrcCols && j < taosArrayGetSize(pColMatchInfo)) {
|
||||
SColumnInfoData* p = taosArrayGet(pCols, i);
|
||||
SColMatchInfo* pmInfo = taosArrayGet(pColMatchInfo, j);
|
||||
if (!outputEveryColumn && pmInfo->reserved) {
|
||||
SColMatchItem* pmInfo = taosArrayGet(pColMatchInfo, j);
|
||||
/* if (!outputEveryColumn && pmInfo->reserved) {
|
||||
j++;
|
||||
continue;
|
||||
}
|
||||
}*/
|
||||
|
||||
if (p->info.colId == pmInfo->colId) {
|
||||
SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, pmInfo->targetSlotId);
|
||||
SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, pmInfo->dstSlotId);
|
||||
colDataAssign(pDst, p, pBlock->info.rows, &pBlock->info);
|
||||
i++;
|
||||
j++;
|
||||
|
|
|
@ -355,7 +355,7 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId,
|
|||
goto _error;
|
||||
}
|
||||
|
||||
SDataSinkMgtCfg cfg = {.maxDataBlockNum = 10000, .maxDataBlockNumPerQuery = 5000};
|
||||
SDataSinkMgtCfg cfg = {.maxDataBlockNum = 500, .maxDataBlockNumPerQuery = 50};
|
||||
code = dsDataSinkMgtInit(&cfg);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("failed to dsDataSinkMgtInit, code:%s, %s", tstrerror(code), (*pTask)->id.str);
|
||||
|
@ -672,7 +672,7 @@ int32_t qStreamSourceRecoverStep1(qTaskInfo_t tinfo, int64_t ver) {
|
|||
int32_t qStreamSourceRecoverStep2(qTaskInfo_t tinfo, int64_t ver) {
|
||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||
ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM);
|
||||
pTaskInfo->streamInfo.recoverStartVer = pTask->streamInfo.recoverEndVer;
|
||||
pTaskInfo->streamInfo.recoverStartVer = pTaskInfo->streamInfo.recoverEndVer;
|
||||
pTaskInfo->streamInfo.recoverEndVer = ver;
|
||||
pTaskInfo->streamInfo.recoverStep = STREAM_RECOVER_STEP__PREPARE2;
|
||||
return 0;
|
||||
|
|
|
@ -110,16 +110,13 @@ int32_t operatorDummyOpenFn(SOperatorInfo* pOperator) {
|
|||
}
|
||||
|
||||
SOperatorFpSet createOperatorFpSet(__optr_open_fn_t openFn, __optr_fn_t nextFn, __optr_fn_t streamFn,
|
||||
__optr_fn_t cleanup, __optr_close_fn_t closeFn, __optr_encode_fn_t encode,
|
||||
__optr_decode_fn_t decode, __optr_explain_fn_t explain) {
|
||||
__optr_fn_t cleanup, __optr_close_fn_t closeFn, __optr_explain_fn_t explain) {
|
||||
SOperatorFpSet fpSet = {
|
||||
._openFn = openFn,
|
||||
.getNextFn = nextFn,
|
||||
.getStreamResFn = streamFn,
|
||||
.cleanupFn = cleanup,
|
||||
.closeFn = closeFn,
|
||||
.encodeResultRow = encode,
|
||||
.decodeResultRow = decode,
|
||||
.getExplainFn = explain,
|
||||
};
|
||||
|
||||
|
@ -1089,7 +1086,7 @@ void setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numO
|
|||
static void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, bool keep,
|
||||
int32_t status);
|
||||
|
||||
void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock, const SArray* pColMatchInfo, SFilterInfo* pFilterInfo) {
|
||||
void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock, SColMatchInfo* pColMatchInfo, SFilterInfo* pFilterInfo) {
|
||||
if (pFilterNode == NULL || pBlock->info.rows == 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -1123,12 +1120,12 @@ void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock, const SArray* pColM
|
|||
extractQualifiedTupleByFilterResult(pBlock, p, keep, status);
|
||||
|
||||
if (pColMatchInfo != NULL) {
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pColMatchInfo); ++i) {
|
||||
SColMatchInfo* pInfo = taosArrayGet(pColMatchInfo, i);
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pColMatchInfo->pList); ++i) {
|
||||
SColMatchItem* pInfo = taosArrayGet(pColMatchInfo->pList, i);
|
||||
if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->targetSlotId);
|
||||
SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId);
|
||||
if (pColData->info.type == TSDB_DATA_TYPE_TIMESTAMP) {
|
||||
blockDataUpdateTsWindow(pBlock, pInfo->targetSlotId);
|
||||
blockDataUpdateTsWindow(pBlock, pInfo->dstSlotId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -2304,8 +2301,8 @@ SOperatorInfo* createExchangeOperatorInfo(void* pTransporter, SExchangePhysiNode
|
|||
pOperator->exprSupp.numOfExprs = taosArrayGetSize(pInfo->pDummyBlock->pDataBlock);
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(prepareLoadRemoteData, doLoadRemoteData, NULL, NULL,
|
||||
destroyExchangeOperatorInfo, NULL, NULL, NULL);
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(prepareLoadRemoteData, doLoadRemoteData, NULL, NULL, destroyExchangeOperatorInfo, NULL);
|
||||
return pOperator;
|
||||
|
||||
_error:
|
||||
|
@ -2563,57 +2560,6 @@ int32_t aggEncodeResultRow(SOperatorInfo* pOperator, char** result, int32_t* len
|
|||
return TDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t aggDecodeResultRow(SOperatorInfo* pOperator, char* result) {
|
||||
if (result == NULL) {
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
SOptrBasicInfo* pInfo = (SOptrBasicInfo*)(pOperator->info);
|
||||
SAggSupporter* pSup = (SAggSupporter*)POINTER_SHIFT(pOperator->info, sizeof(SOptrBasicInfo));
|
||||
|
||||
// int32_t size = taosHashGetSize(pSup->pResultRowHashTable);
|
||||
int32_t length = *(int32_t*)(result);
|
||||
int32_t offset = sizeof(int32_t);
|
||||
|
||||
int32_t count = *(int32_t*)(result + offset);
|
||||
offset += sizeof(int32_t);
|
||||
|
||||
while (count-- > 0 && length > offset) {
|
||||
int32_t keyLen = *(int32_t*)(result + offset);
|
||||
offset += sizeof(int32_t);
|
||||
|
||||
uint64_t tableGroupId = *(uint64_t*)(result + offset);
|
||||
SResultRow* resultRow = getNewResultRow(pSup->pResultBuf, &pSup->currentPageId, pSup->resultRowSize);
|
||||
if (!resultRow) {
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
||||
// add a new result set for a new group
|
||||
SResultRowPosition pos = {.pageId = resultRow->pageId, .offset = resultRow->offset};
|
||||
tSimpleHashPut(pSup->pResultRowHashTable, result + offset, keyLen, &pos, sizeof(SResultRowPosition));
|
||||
|
||||
offset += keyLen;
|
||||
int32_t valueLen = *(int32_t*)(result + offset);
|
||||
if (valueLen != pSup->resultRowSize) {
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
offset += sizeof(int32_t);
|
||||
int32_t pageId = resultRow->pageId;
|
||||
int32_t pOffset = resultRow->offset;
|
||||
memcpy(resultRow, result + offset, valueLen);
|
||||
resultRow->pageId = pageId;
|
||||
resultRow->offset = pOffset;
|
||||
offset += valueLen;
|
||||
|
||||
pInfo->resultRowInfo.cur = (SResultRowPosition){.pageId = resultRow->pageId, .offset = resultRow->offset};
|
||||
// releaseBufPage(pSup->pResultBuf, getBufPage(pSup->pResultBuf, pageId));
|
||||
}
|
||||
|
||||
if (offset != length) {
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
return TDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t handleLimitOffset(SOperatorInfo* pOperator, SLimitInfo* pLimitInfo, SSDataBlock* pBlock, bool holdDataInBuf) {
|
||||
if (pLimitInfo->remainGroupOffset > 0) {
|
||||
if (pLimitInfo->currentGroupId == 0) { // it is the first group
|
||||
|
@ -2853,7 +2799,7 @@ static SSDataBlock* doFill(SOperatorInfo* pOperator) {
|
|||
break;
|
||||
}
|
||||
|
||||
doFilter(pInfo->pCondition, fillResult, pInfo->pColMatchColInfo, NULL);
|
||||
doFilter(pInfo->pCondition, fillResult, &pInfo->matchInfo, NULL);
|
||||
if (fillResult->info.rows > 0) {
|
||||
break;
|
||||
}
|
||||
|
@ -3080,8 +3026,8 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SAggPhysiN
|
|||
pOperator->info = pInfo;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(doOpenAggregateOptr, getAggregateResult, NULL, NULL, destroyAggOperatorInfo,
|
||||
aggEncodeResultRow, aggDecodeResultRow, NULL);
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(doOpenAggregateOptr, getAggregateResult, NULL, NULL, destroyAggOperatorInfo, NULL);
|
||||
|
||||
if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
|
||||
STableScanInfo* pTableScanInfo = downstream->info;
|
||||
|
@ -3101,9 +3047,11 @@ _error:
|
|||
destroyAggOperatorInfo(pInfo);
|
||||
}
|
||||
|
||||
cleanupExprSupp(&pOperator->exprSupp);
|
||||
taosMemoryFreeClear(pOperator);
|
||||
if (pOperator != NULL) {
|
||||
cleanupExprSupp(&pOperator->exprSupp);
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(pOperator);
|
||||
pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -3139,7 +3087,7 @@ void destroyFillOperatorInfo(void* param) {
|
|||
cleanupExprSupp(&pInfo->noFillExprSupp);
|
||||
|
||||
taosMemoryFreeClear(pInfo->p);
|
||||
taosArrayDestroy(pInfo->pColMatchColInfo);
|
||||
taosArrayDestroy(pInfo->matchInfo.pList);
|
||||
taosMemoryFreeClear(param);
|
||||
}
|
||||
|
||||
|
@ -3283,8 +3231,8 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode*
|
|||
pInfo->primarySrcSlotId = ((SColumnNode*)((STargetNode*)pPhyFillNode->pWStartTs)->pExpr)->slotId;
|
||||
|
||||
int32_t numOfOutputCols = 0;
|
||||
pInfo->pColMatchColInfo = extractColMatchInfo(pPhyFillNode->pFillExprs, pPhyFillNode->node.pOutputDataBlockDesc,
|
||||
&numOfOutputCols, COL_MATCH_FROM_SLOT_ID);
|
||||
code = extractColMatchInfo(pPhyFillNode->pFillExprs, pPhyFillNode->node.pOutputDataBlockDesc, &numOfOutputCols,
|
||||
COL_MATCH_FROM_SLOT_ID, &pInfo->matchInfo);
|
||||
|
||||
code = initFillInfo(pInfo, pExprInfo, pInfo->numOfExpr, pNoFillSupp->pExprInfo, pNoFillSupp->numOfExprs,
|
||||
(SNodeListNode*)pPhyFillNode->pValues, pPhyFillNode->timeRange, pResultInfo->capacity,
|
||||
|
@ -3305,8 +3253,7 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode*
|
|||
pOperator->info = pInfo;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(operatorDummyOpenFn, doFill, NULL, NULL, destroyFillOperatorInfo, NULL, NULL, NULL);
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doFill, NULL, NULL, destroyFillOperatorInfo, NULL);
|
||||
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
return pOperator;
|
||||
|
@ -4003,7 +3950,7 @@ int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SRead
|
|||
}
|
||||
|
||||
if (pHandle) {
|
||||
(*pTaskInfo)->streamInfo.fillHistoryVer1 = pHandle->fillHistoryVer1;
|
||||
/*(*pTaskInfo)->streamInfo.fillHistoryVer1 = pHandle->fillHistoryVer1;*/
|
||||
if (pHandle->pStateBackend) {
|
||||
(*pTaskInfo)->streamInfo.pState = pHandle->pStateBackend;
|
||||
}
|
||||
|
|
|
@ -443,7 +443,7 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode
|
|||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, hashGroupbyAggregate, NULL, NULL,
|
||||
destroyGroupOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL);
|
||||
destroyGroupOperatorInfo, NULL);
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
|
@ -820,7 +820,7 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition
|
|||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, hashPartition, NULL, NULL, destroyPartitionOperatorInfo,
|
||||
NULL, NULL, NULL);
|
||||
NULL);
|
||||
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
return pOperator;
|
||||
|
@ -1095,7 +1095,7 @@ SOperatorInfo* createStreamPartitionOperatorInfo(SOperatorInfo* downstream, SStr
|
|||
pOperator->info = pInfo;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamHashPartition, NULL, NULL,
|
||||
destroyStreamPartitionOperatorInfo, NULL, NULL, NULL);
|
||||
destroyStreamPartitionOperatorInfo, NULL);
|
||||
|
||||
initParDownStream(downstream, &pInfo->partitionSup, &pInfo->scalarSup);
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
|
|
|
@ -116,7 +116,7 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t
|
|||
}
|
||||
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(operatorDummyOpenFn, doMergeJoin, NULL, NULL, destroyMergeJoinOperator, NULL, NULL, NULL);
|
||||
createOperatorFpSet(operatorDummyOpenFn, doMergeJoin, NULL, NULL, destroyMergeJoinOperator, NULL);
|
||||
code = appendDownstream(pOperator, pDownstream, numOfDownstream);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
|
|
|
@ -105,7 +105,7 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SProjectPhys
|
|||
pOperator->info = pInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doProjectOperation, NULL, NULL,
|
||||
destroyProjectOperatorInfo, NULL, NULL, NULL);
|
||||
destroyProjectOperatorInfo, NULL);
|
||||
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -405,7 +405,7 @@ SOperatorInfo* createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhy
|
|||
pOperator->info = pInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doApplyIndefinitFunction, NULL, NULL,
|
||||
destroyIndefinitOperatorInfo, NULL, NULL, NULL);
|
||||
destroyIndefinitOperatorInfo, NULL);
|
||||
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
|
|
@ -331,12 +331,13 @@ static bool doLoadBlockSMA(STableScanInfo* pTableScanInfo, SSDataBlock* pBlock,
|
|||
}
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pTableScanInfo->pColMatchInfo); ++i) {
|
||||
SColMatchInfo* pColMatchInfo = taosArrayGet(pTableScanInfo->pColMatchInfo, i);
|
||||
if (!pColMatchInfo->output) {
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pTableScanInfo->matchInfo.pList); ++i) {
|
||||
SColMatchItem* pColMatchInfo = taosArrayGet(pTableScanInfo->matchInfo.pList, i);
|
||||
if (!pColMatchInfo->needOutput) {
|
||||
continue;
|
||||
}
|
||||
pBlock->pBlockAgg[pColMatchInfo->targetSlotId] = pColAgg[i];
|
||||
|
||||
pBlock->pBlockAgg[pColMatchInfo->dstSlotId] = pColAgg[i];
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -442,12 +443,12 @@ static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableSca
|
|||
return terrno;
|
||||
}
|
||||
|
||||
relocateColumnData(pBlock, pTableScanInfo->pColMatchInfo, pCols, true);
|
||||
relocateColumnData(pBlock, pTableScanInfo->matchInfo.pList, pCols, true);
|
||||
doSetTagColumnData(pTableScanInfo, pBlock, pTaskInfo);
|
||||
|
||||
if (pTableScanInfo->pFilterNode != NULL) {
|
||||
int64_t st = taosGetTimestampUs();
|
||||
doFilter(pTableScanInfo->pFilterNode, pBlock, pTableScanInfo->pColMatchInfo, pOperator->exprSupp.pFilterInfo);
|
||||
doFilter(pTableScanInfo->pFilterNode, pBlock, &pTableScanInfo->matchInfo, pOperator->exprSupp.pFilterInfo);
|
||||
|
||||
double el = (taosGetTimestampUs() - st) / 1000.0;
|
||||
pTableScanInfo->readRecorder.filterTime += el;
|
||||
|
@ -780,8 +781,8 @@ static void destroyTableScanOperatorInfo(void* param) {
|
|||
tsdbReaderClose(pTableScanInfo->dataReader);
|
||||
pTableScanInfo->dataReader = NULL;
|
||||
|
||||
if (pTableScanInfo->pColMatchInfo != NULL) {
|
||||
taosArrayDestroy(pTableScanInfo->pColMatchInfo);
|
||||
if (pTableScanInfo->matchInfo.pList != NULL) {
|
||||
taosArrayDestroy(pTableScanInfo->matchInfo.pList);
|
||||
}
|
||||
|
||||
cleanupExprSupp(&pTableScanInfo->pseudoSup);
|
||||
|
@ -798,10 +799,10 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode,
|
|||
|
||||
SDataBlockDescNode* pDescNode = pTableScanNode->scan.node.pOutputDataBlockDesc;
|
||||
int32_t numOfCols = 0;
|
||||
pInfo->pColMatchInfo =
|
||||
extractColMatchInfo(pTableScanNode->scan.pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID);
|
||||
int32_t code = extractColMatchInfo(pTableScanNode->scan.pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID,
|
||||
&pInfo->matchInfo);
|
||||
|
||||
int32_t code = initQueryTableDataCond(&pInfo->cond, pTableScanNode);
|
||||
code = initQueryTableDataCond(&pInfo->cond, pTableScanNode);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
@ -839,7 +840,7 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode,
|
|||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableScan, NULL, NULL, destroyTableScanOperatorInfo,
|
||||
NULL, NULL, getTableScannerExecInfo);
|
||||
getTableScannerExecInfo);
|
||||
|
||||
// for non-blocking operator, the open cost is always 0
|
||||
pOperator->cost.openCost = 0;
|
||||
|
@ -867,7 +868,7 @@ SOperatorInfo* createTableSeqScanOperatorInfo(void* pReadHandle, SExecTaskInfo*
|
|||
pOperator->info = pInfo;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableScanImpl, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableScanImpl, NULL, NULL, NULL, NULL);
|
||||
return pOperator;
|
||||
}
|
||||
|
||||
|
@ -988,7 +989,7 @@ SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SReadHandle* re
|
|||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doBlockInfoScan, NULL, NULL,
|
||||
destroyBlockDistScanOperatorInfo, NULL, NULL, NULL);
|
||||
destroyBlockDistScanOperatorInfo, NULL);
|
||||
return pOperator;
|
||||
|
||||
_error:
|
||||
|
@ -1512,9 +1513,9 @@ static int32_t setBlockIntoRes(SStreamScanInfo* pInfo, const SSDataBlock* pBlock
|
|||
}
|
||||
|
||||
// todo extract method
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pInfo->pColMatchInfo); ++i) {
|
||||
SColMatchInfo* pColMatchInfo = taosArrayGet(pInfo->pColMatchInfo, i);
|
||||
if (!pColMatchInfo->output) {
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pInfo->matchInfo.pList); ++i) {
|
||||
SColMatchItem* pColMatchInfo = taosArrayGet(pInfo->matchInfo.pList, i);
|
||||
if (!pColMatchInfo->needOutput) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1522,7 +1523,7 @@ static int32_t setBlockIntoRes(SStreamScanInfo* pInfo, const SSDataBlock* pBlock
|
|||
for (int32_t j = 0; j < blockDataGetNumOfCols(pBlock); ++j) {
|
||||
SColumnInfoData* pResCol = bdGetColumnInfoData(pBlock, j);
|
||||
if (pResCol->info.colId == pColMatchInfo->colId) {
|
||||
SColumnInfoData* pDst = taosArrayGet(pInfo->pRes->pDataBlock, pColMatchInfo->targetSlotId);
|
||||
SColumnInfoData* pDst = taosArrayGet(pInfo->pRes->pDataBlock, pColMatchInfo->dstSlotId);
|
||||
colDataAssign(pDst, pResCol, pBlock->info.rows, &pInfo->pRes->info);
|
||||
colExists = true;
|
||||
break;
|
||||
|
@ -1531,7 +1532,7 @@ static int32_t setBlockIntoRes(SStreamScanInfo* pInfo, const SSDataBlock* pBlock
|
|||
|
||||
// the required column does not exists in submit block, let's set it to be all null value
|
||||
if (!colExists) {
|
||||
SColumnInfoData* pDst = taosArrayGet(pInfo->pRes->pDataBlock, pColMatchInfo->targetSlotId);
|
||||
SColumnInfoData* pDst = taosArrayGet(pInfo->pRes->pDataBlock, pColMatchInfo->dstSlotId);
|
||||
colDataAppendNNULL(pDst, 0, pBlockInfo->rows);
|
||||
}
|
||||
}
|
||||
|
@ -2179,7 +2180,7 @@ SOperatorInfo* createRawScanOperatorInfo(SReadHandle* pHandle, SExecTaskInfo* pT
|
|||
pOperator->info = pInfo;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(NULL, doRawScan, NULL, NULL, destroyRawScanOperatorInfo, NULL, NULL, NULL);
|
||||
pOperator->fpSet = createOperatorFpSet(NULL, doRawScan, NULL, NULL, destroyRawScanOperatorInfo, NULL);
|
||||
return pOperator;
|
||||
|
||||
_end:
|
||||
|
@ -2199,8 +2200,8 @@ static void destroyStreamScanOperatorInfo(void* param) {
|
|||
if (pStreamScan->tqReader) {
|
||||
tqCloseReader(pStreamScan->tqReader);
|
||||
}
|
||||
if (pStreamScan->pColMatchInfo) {
|
||||
taosArrayDestroy(pStreamScan->pColMatchInfo);
|
||||
if (pStreamScan->matchInfo.pList) {
|
||||
taosArrayDestroy(pStreamScan->matchInfo.pList);
|
||||
}
|
||||
if (pStreamScan->pPseudoExpr) {
|
||||
destroyExprInfo(pStreamScan->pPseudoExpr, pStreamScan->numOfPseudoExpr);
|
||||
|
@ -2234,17 +2235,17 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys
|
|||
pInfo->pGroupTags = pTableScanNode->pGroupTags;
|
||||
|
||||
int32_t numOfCols = 0;
|
||||
pInfo->pColMatchInfo = extractColMatchInfo(pScanPhyNode->pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID);
|
||||
int32_t code = extractColMatchInfo(pScanPhyNode->pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID, &pInfo->matchInfo);
|
||||
|
||||
int32_t numOfOutput = taosArrayGetSize(pInfo->pColMatchInfo);
|
||||
int32_t numOfOutput = taosArrayGetSize(pInfo->matchInfo.pList);
|
||||
SArray* pColIds = taosArrayInit(numOfOutput, sizeof(int16_t));
|
||||
for (int32_t i = 0; i < numOfOutput; ++i) {
|
||||
SColMatchInfo* id = taosArrayGet(pInfo->pColMatchInfo, i);
|
||||
SColMatchItem* id = taosArrayGet(pInfo->matchInfo.pList, i);
|
||||
|
||||
int16_t colId = id->colId;
|
||||
taosArrayPush(pColIds, &colId);
|
||||
if (id->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
pInfo->primaryTsIndex = id->targetSlotId;
|
||||
pInfo->primaryTsIndex = id->dstSlotId;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2361,7 +2362,7 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys
|
|||
|
||||
__optr_fn_t nextFn = pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM ? doStreamScan : doQueueScan;
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(operatorDummyOpenFn, nextFn, NULL, NULL, destroyStreamScanOperatorInfo, NULL, NULL, NULL);
|
||||
createOperatorFpSet(operatorDummyOpenFn, nextFn, NULL, NULL, destroyStreamScanOperatorInfo, NULL);
|
||||
|
||||
return pOperator;
|
||||
|
||||
|
@ -2395,7 +2396,7 @@ static void destroySysScanOperator(void* param) {
|
|||
pInfo->pIdx = NULL;
|
||||
}
|
||||
|
||||
taosArrayDestroy(pInfo->scanCols);
|
||||
taosArrayDestroy(pInfo->matchInfo.pList);
|
||||
taosMemoryFreeClear(pInfo->pUser);
|
||||
|
||||
taosMemoryFreeClear(param);
|
||||
|
@ -2760,7 +2761,7 @@ static void relocateAndFilterSysTagsScanResult(SSysTableScanInfo* pInfo, int32_t
|
|||
dataBlock->info.rows = numOfRows;
|
||||
pInfo->pRes->info.rows = numOfRows;
|
||||
|
||||
relocateColumnData(pInfo->pRes, pInfo->scanCols, dataBlock->pDataBlock, false);
|
||||
relocateColumnData(pInfo->pRes, pInfo->matchInfo.pList, dataBlock->pDataBlock, false);
|
||||
doFilterResult(pInfo);
|
||||
|
||||
blockDataCleanup(dataBlock);
|
||||
|
@ -2888,7 +2889,7 @@ int optSysDoCompare(__compar_fn_t func, int8_t comparType, void* a, void* b) {
|
|||
default:
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
return cmp;
|
||||
}
|
||||
|
||||
static int optSysFilterFuncImpl__LowerThan(void* a, void* b, int16_t dtype) {
|
||||
|
@ -2994,10 +2995,6 @@ static int32_t sysFilte__TableName(void* arg, SNode* pNode, SArray* result) {
|
|||
.val = pVal->datum.p,
|
||||
.reverse = reverse,
|
||||
.filterFunc = func};
|
||||
|
||||
int32_t ret = metaFilterCreateTime(pMeta, ¶m, result);
|
||||
if (ret == 0) return 0;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -3009,15 +3006,17 @@ static int32_t sysFilte__CreateTime(void* arg, SNode* pNode, SArray* result) {
|
|||
bool reverse = false;
|
||||
|
||||
__optSysFilter func = optSysGetFilterFunc(pOper->opType, &reverse);
|
||||
SMetaFltParam param = {.suid = 0,
|
||||
.cid = 0,
|
||||
.type = TSDB_DATA_TYPE_BIGINT,
|
||||
.val = &pVal->datum.i,
|
||||
.reverse = reverse,
|
||||
.filterFunc = func};
|
||||
int32_t ret = metaFilterCreateTime(pMeta, ¶m, result);
|
||||
if (func == NULL) return -1;
|
||||
return 0;
|
||||
|
||||
SMetaFltParam param = {.suid = 0,
|
||||
.cid = 0,
|
||||
.type = TSDB_DATA_TYPE_BIGINT,
|
||||
.val = &pVal->datum.i,
|
||||
.reverse = reverse,
|
||||
.filterFunc = func};
|
||||
|
||||
int32_t ret = metaFilterCreateTime(pMeta, ¶m, result);
|
||||
return ret;
|
||||
}
|
||||
static int32_t sysFilte__Ncolumn(void* arg, SNode* pNode, SArray* result) {
|
||||
void* pMeta = ((SSTabFltArg*)arg)->pMeta;
|
||||
|
@ -3080,7 +3079,7 @@ static int32_t sysChkFilter__Comm(SNode* pNode) {
|
|||
SOperatorNode* pOper = (SOperatorNode*)pNode;
|
||||
EOperatorType opType = pOper->opType;
|
||||
if (opType != OP_TYPE_EQUAL && opType != OP_TYPE_LOWER_EQUAL && opType != OP_TYPE_LOWER_THAN &&
|
||||
OP_TYPE_GREATER_EQUAL && opType != OP_TYPE_GREATER_THAN) {
|
||||
opType != OP_TYPE_GREATER_EQUAL && opType != OP_TYPE_GREATER_THAN) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -3199,12 +3198,24 @@ static int32_t optSysCheckOper(SNode* pOpear) {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tableUidCompare(const void* a, const void* b) {
|
||||
int64_t u1 = *(int64_t*)a;
|
||||
int64_t u2 = *(int64_t*)b;
|
||||
if (u1 == u2) {
|
||||
return 0;
|
||||
}
|
||||
return u1 < u2 ? -1 : 1;
|
||||
}
|
||||
static int32_t optSysMergeRslt(SArray* mRslt, SArray* rslt) {
|
||||
// TODO, find comm mem from mRslt
|
||||
for (int i = 0; i < taosArrayGetSize(mRslt); i++) {
|
||||
SArray* aRslt = taosArrayGetP(mRslt, i);
|
||||
taosArrayAddAll(rslt, aRslt);
|
||||
}
|
||||
taosArraySort(rslt, tableUidCompare);
|
||||
taosArrayRemoveDuplicate(rslt, tableUidCompare, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -3437,7 +3448,7 @@ static SSDataBlock* sysTableBuildUserTablesByUids(SOperatorInfo* pOperator) {
|
|||
p->info.rows = numOfRows;
|
||||
pInfo->pRes->info.rows = numOfRows;
|
||||
|
||||
relocateColumnData(pInfo->pRes, pInfo->scanCols, p->pDataBlock, false);
|
||||
relocateColumnData(pInfo->pRes, pInfo->matchInfo.pList, p->pDataBlock, false);
|
||||
doFilterResult(pInfo);
|
||||
|
||||
blockDataCleanup(p);
|
||||
|
@ -3453,7 +3464,7 @@ static SSDataBlock* sysTableBuildUserTablesByUids(SOperatorInfo* pOperator) {
|
|||
p->info.rows = numOfRows;
|
||||
pInfo->pRes->info.rows = numOfRows;
|
||||
|
||||
relocateColumnData(pInfo->pRes, pInfo->scanCols, p->pDataBlock, false);
|
||||
relocateColumnData(pInfo->pRes, pInfo->matchInfo.pList, p->pDataBlock, false);
|
||||
doFilterResult(pInfo);
|
||||
|
||||
blockDataCleanup(p);
|
||||
|
@ -3463,7 +3474,7 @@ static SSDataBlock* sysTableBuildUserTablesByUids(SOperatorInfo* pOperator) {
|
|||
if (i >= taosArrayGetSize(pIdx->uids)) {
|
||||
doSetOperatorCompleted(pOperator);
|
||||
} else {
|
||||
pIdx->lastIdx = i;
|
||||
pIdx->lastIdx = i + 1;
|
||||
}
|
||||
|
||||
blockDataDestroy(p);
|
||||
|
@ -3472,7 +3483,9 @@ static SSDataBlock* sysTableBuildUserTablesByUids(SOperatorInfo* pOperator) {
|
|||
return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes;
|
||||
}
|
||||
static SSDataBlock* sysTableBuildUserTables(SOperatorInfo* pOperator) {
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
||||
qError("%p buildUserTable", pTaskInfo);
|
||||
SSysTableScanInfo* pInfo = pOperator->info;
|
||||
if (pInfo->pCur == NULL) {
|
||||
pInfo->pCur = metaOpenTbCursor(pInfo->readHandle.meta);
|
||||
|
@ -3612,7 +3625,7 @@ static SSDataBlock* sysTableBuildUserTables(SOperatorInfo* pOperator) {
|
|||
p->info.rows = numOfRows;
|
||||
pInfo->pRes->info.rows = numOfRows;
|
||||
|
||||
relocateColumnData(pInfo->pRes, pInfo->scanCols, p->pDataBlock, false);
|
||||
relocateColumnData(pInfo->pRes, pInfo->matchInfo.pList, p->pDataBlock, false);
|
||||
doFilterResult(pInfo);
|
||||
|
||||
blockDataCleanup(p);
|
||||
|
@ -3628,7 +3641,7 @@ static SSDataBlock* sysTableBuildUserTables(SOperatorInfo* pOperator) {
|
|||
p->info.rows = numOfRows;
|
||||
pInfo->pRes->info.rows = numOfRows;
|
||||
|
||||
relocateColumnData(pInfo->pRes, pInfo->scanCols, p->pDataBlock, false);
|
||||
relocateColumnData(pInfo->pRes, pInfo->matchInfo.pList, p->pDataBlock, false);
|
||||
doFilterResult(pInfo);
|
||||
|
||||
blockDataCleanup(p);
|
||||
|
@ -3792,7 +3805,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) {
|
|||
}
|
||||
|
||||
char* pStart = pRsp->data;
|
||||
extractDataBlockFromFetchRsp(pInfo->pRes, pRsp->data, pInfo->scanCols, &pStart);
|
||||
extractDataBlockFromFetchRsp(pInfo->pRes, pRsp->data, pInfo->matchInfo.pList, &pStart);
|
||||
updateLoadRemoteInfo(&pInfo->loadInfo, pRsp->numOfRows, pRsp->compLen, startTs, pOperator);
|
||||
|
||||
// todo log the filter info
|
||||
|
@ -3821,7 +3834,7 @@ int32_t buildSysDbTableInfo(const SSysTableScanInfo* pInfo, int32_t capacity) {
|
|||
p->info.rows = buildDbTableInfoBlock(pInfo->sysInfo, p, pSysDbTableMeta, size, TSDB_PERFORMANCE_SCHEMA_DB);
|
||||
|
||||
pInfo->pRes->info.rows = p->info.rows;
|
||||
relocateColumnData(pInfo->pRes, pInfo->scanCols, p->pDataBlock, false);
|
||||
relocateColumnData(pInfo->pRes, pInfo->matchInfo.pList, p->pDataBlock, false);
|
||||
blockDataDestroy(p);
|
||||
|
||||
return pInfo->pRes->info.rows;
|
||||
|
@ -3883,18 +3896,16 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScan
|
|||
SScanPhysiNode* pScanNode = &pScanPhyNode->scan;
|
||||
|
||||
SDataBlockDescNode* pDescNode = pScanNode->node.pOutputDataBlockDesc;
|
||||
SSDataBlock* pResBlock = createResDataBlock(pDescNode);
|
||||
|
||||
int32_t num = 0;
|
||||
SArray* colList = extractColMatchInfo(pScanNode->pScanCols, pDescNode, &num, COL_MATCH_FROM_COL_ID);
|
||||
int32_t code = extractColMatchInfo(pScanNode->pScanCols, pDescNode, &num, COL_MATCH_FROM_COL_ID, &pInfo->matchInfo);
|
||||
|
||||
pInfo->accountId = pScanPhyNode->accountId;
|
||||
pInfo->pUser = taosMemoryStrDup((void*)pUser);
|
||||
pInfo->sysInfo = pScanPhyNode->sysInfo;
|
||||
pInfo->showRewrite = pScanPhyNode->showRewrite;
|
||||
pInfo->pRes = pResBlock;
|
||||
pInfo->pRes = createResDataBlock(pDescNode);
|
||||
pInfo->pCondition = pScanNode->node.pConditions;
|
||||
pInfo->scanCols = colList;
|
||||
|
||||
initResultSizeInfo(&pOperator->resultInfo, 4096);
|
||||
|
||||
|
@ -3916,11 +3927,11 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScan
|
|||
pOperator->blocking = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->exprSupp.numOfExprs = taosArrayGetSize(pResBlock->pDataBlock);
|
||||
pOperator->exprSupp.numOfExprs = taosArrayGetSize(pInfo->pRes->pDataBlock);
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(operatorDummyOpenFn, doSysTableScan, NULL, NULL, destroySysScanOperator, NULL, NULL, NULL);
|
||||
createOperatorFpSet(operatorDummyOpenFn, doSysTableScan, NULL, NULL, destroySysScanOperator, NULL);
|
||||
|
||||
return pOperator;
|
||||
|
||||
|
@ -4015,7 +4026,7 @@ static SSDataBlock* doTagScan(SOperatorInfo* pOperator) {
|
|||
static void destroyTagScanOperatorInfo(void* param) {
|
||||
STagScanInfo* pInfo = (STagScanInfo*)param;
|
||||
pInfo->pRes = blockDataDestroy(pInfo->pRes);
|
||||
taosArrayDestroy(pInfo->pColMatchInfo);
|
||||
taosArrayDestroy(pInfo->matchInfo.pList);
|
||||
taosMemoryFreeClear(param);
|
||||
}
|
||||
|
||||
|
@ -4032,15 +4043,14 @@ SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysi
|
|||
int32_t num = 0;
|
||||
int32_t numOfExprs = 0;
|
||||
SExprInfo* pExprInfo = createExprInfo(pPhyNode->pScanPseudoCols, NULL, &numOfExprs);
|
||||
SArray* colList = extractColMatchInfo(pPhyNode->pScanPseudoCols, pDescNode, &num, COL_MATCH_FROM_COL_ID);
|
||||
int32_t code = extractColMatchInfo(pPhyNode->pScanPseudoCols, pDescNode, &num, COL_MATCH_FROM_COL_ID, &pInfo->matchInfo);
|
||||
|
||||
int32_t code = initExprSupp(&pOperator->exprSupp, pExprInfo, numOfExprs);
|
||||
code = initExprSupp(&pOperator->exprSupp, pExprInfo, numOfExprs);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
pInfo->pTableList = pTableListInfo;
|
||||
pInfo->pColMatchInfo = colList;
|
||||
pInfo->pRes = createResDataBlock(pDescNode);
|
||||
pInfo->readHandle = *pReadHandle;
|
||||
pInfo->curPos = 0;
|
||||
|
@ -4057,7 +4067,7 @@ SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysi
|
|||
blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity);
|
||||
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(operatorDummyOpenFn, doTagScan, NULL, NULL, destroyTagScanOperatorInfo, NULL, NULL, NULL);
|
||||
createOperatorFpSet(operatorDummyOpenFn, doTagScan, NULL, NULL, destroyTagScanOperatorInfo, NULL);
|
||||
|
||||
return pOperator;
|
||||
|
||||
|
@ -4174,11 +4184,11 @@ static int32_t loadDataBlockFromOneTable(SOperatorInfo* pOperator, STableMergeSc
|
|||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColMatchInfo* pColMatchInfo = taosArrayGet(pTableScanInfo->pColMatchInfo, i);
|
||||
if (!pColMatchInfo->output) {
|
||||
SColMatchItem* pColMatchInfo = taosArrayGet(pTableScanInfo->matchInfo.pList, i);
|
||||
if (!pColMatchInfo->needOutput) {
|
||||
continue;
|
||||
}
|
||||
pBlock->pBlockAgg[pColMatchInfo->targetSlotId] = pColAgg[i];
|
||||
pBlock->pBlockAgg[pColMatchInfo->dstSlotId] = pColAgg[i];
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -4209,7 +4219,7 @@ static int32_t loadDataBlockFromOneTable(SOperatorInfo* pOperator, STableMergeSc
|
|||
return terrno;
|
||||
}
|
||||
|
||||
relocateColumnData(pBlock, pTableScanInfo->pColMatchInfo, pCols, true);
|
||||
relocateColumnData(pBlock, pTableScanInfo->matchInfo.pList, pCols, true);
|
||||
|
||||
// currently only the tbname pseudo column
|
||||
if (pTableScanInfo->pseudoSup.numOfExprs > 0) {
|
||||
|
@ -4222,7 +4232,7 @@ static int32_t loadDataBlockFromOneTable(SOperatorInfo* pOperator, STableMergeSc
|
|||
|
||||
if (pTableScanInfo->pFilterNode != NULL) {
|
||||
int64_t st = taosGetTimestampMs();
|
||||
doFilter(pTableScanInfo->pFilterNode, pBlock, pTableScanInfo->pColMatchInfo, NULL);
|
||||
doFilter(pTableScanInfo->pFilterNode, pBlock, &pTableScanInfo->matchInfo, NULL);
|
||||
|
||||
double el = (taosGetTimestampUs() - st) / 1000.0;
|
||||
pTableScanInfo->readRecorder.filterTime += el;
|
||||
|
@ -4306,9 +4316,9 @@ static SSDataBlock* getTableDataBlock(void* param) {
|
|||
SArray* generateSortByTsInfo(SArray* colMatchInfo, int32_t order) {
|
||||
int32_t tsTargetSlotId = 0;
|
||||
for (int32_t i = 0; i < taosArrayGetSize(colMatchInfo); ++i) {
|
||||
SColMatchInfo* colInfo = taosArrayGet(colMatchInfo, i);
|
||||
SColMatchItem* colInfo = taosArrayGet(colMatchInfo, i);
|
||||
if (colInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
tsTargetSlotId = colInfo->targetSlotId;
|
||||
tsTargetSlotId = colInfo->dstSlotId;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4494,8 +4504,8 @@ void destroyTableMergeScanOperatorInfo(void* param) {
|
|||
}
|
||||
taosArrayDestroy(pTableScanInfo->dataReaders);
|
||||
|
||||
if (pTableScanInfo->pColMatchInfo != NULL) {
|
||||
taosArrayDestroy(pTableScanInfo->pColMatchInfo);
|
||||
if (pTableScanInfo->matchInfo.pList != NULL) {
|
||||
taosArrayDestroy(pTableScanInfo->matchInfo.pList);
|
||||
}
|
||||
|
||||
pTableScanInfo->pResBlock = blockDataDestroy(pTableScanInfo->pResBlock);
|
||||
|
@ -4553,11 +4563,11 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN
|
|||
SDataBlockDescNode* pDescNode = pTableScanNode->scan.node.pOutputDataBlockDesc;
|
||||
|
||||
int32_t numOfCols = 0;
|
||||
SArray* pColList = extractColMatchInfo(pTableScanNode->scan.pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID);
|
||||
int32_t code = extractColMatchInfo(pTableScanNode->scan.pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID, &pInfo->matchInfo);
|
||||
|
||||
int32_t code = initQueryTableDataCond(&pInfo->cond, pTableScanNode);
|
||||
code = initQueryTableDataCond(&pInfo->cond, pTableScanNode);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
taosArrayDestroy(pColList);
|
||||
taosArrayDestroy(pInfo->matchInfo.pList);
|
||||
goto _error;
|
||||
}
|
||||
|
||||
|
@ -4577,12 +4587,11 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN
|
|||
pInfo->pFilterNode = pTableScanNode->scan.node.pConditions;
|
||||
pInfo->tableListInfo = pTableListInfo;
|
||||
pInfo->scanFlag = MAIN_SCAN;
|
||||
pInfo->pColMatchInfo = pColList;
|
||||
|
||||
pInfo->pResBlock = createResDataBlock(pDescNode);
|
||||
pInfo->sortSourceParams = taosArrayInit(64, sizeof(STableMergeScanSortSourceParam));
|
||||
|
||||
pInfo->pSortInfo = generateSortByTsInfo(pInfo->pColMatchInfo, pInfo->cond.order);
|
||||
pInfo->pSortInfo = generateSortByTsInfo(pInfo->matchInfo.pList, pInfo->cond.order);
|
||||
pInfo->pSortInputBlock = createOneDataBlock(pInfo->pResBlock, false);
|
||||
|
||||
int32_t rowSize = pInfo->pResBlock->info.rowSize;
|
||||
|
@ -4597,9 +4606,8 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN
|
|||
pOperator->pTaskInfo = pTaskInfo;
|
||||
initResultSizeInfo(&pOperator->resultInfo, 1024);
|
||||
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(operatorDummyOpenFn, doTableMergeScan, NULL, NULL, destroyTableMergeScanOperatorInfo, NULL,
|
||||
NULL, getTableMergeScanExplainExecInfo);
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableMergeScan, NULL, NULL,
|
||||
destroyTableMergeScanOperatorInfo, getTableMergeScanExplainExecInfo);
|
||||
pOperator->cost.openCost = 0;
|
||||
return pOperator;
|
||||
|
||||
|
|
|
@ -38,8 +38,7 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode*
|
|||
SExprInfo* pExprInfo = createExprInfo(pSortNode->pExprs, NULL, &numOfCols);
|
||||
|
||||
int32_t numOfOutputCols = 0;
|
||||
SArray* pColMatchColInfo =
|
||||
extractColMatchInfo(pSortNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID);
|
||||
int32_t code = extractColMatchInfo(pSortNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID, &pInfo->matchInfo);
|
||||
|
||||
pOperator->exprSupp.pCtx = createSqlFunctionCtx(pExprInfo, numOfCols, &pOperator->exprSupp.rowEntryInfoOffset);
|
||||
|
||||
|
@ -48,7 +47,6 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode*
|
|||
pInfo->binfo.pRes = pResBlock;
|
||||
pInfo->pSortInfo = createSortInfo(pSortNode->pSortKeys);
|
||||
pInfo->pCondition = pSortNode->node.pConditions;
|
||||
pInfo->pColMatchInfo = pColMatchColInfo;
|
||||
initLimitInfo(pSortNode->node.pLimit, pSortNode->node.pSlimit, &pInfo->limitInfo);
|
||||
|
||||
pOperator->name = "SortOperator";
|
||||
|
@ -64,10 +62,10 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode*
|
|||
// there are headers, so pageSize = rowSize + header pInfo->sortBufSize = pInfo->bufPageSize * 16;
|
||||
// TODO dynamic set the available sort buffer
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(doOpenSortOperator, doSort, NULL, NULL, destroyOrderOperatorInfo, NULL, NULL,
|
||||
pOperator->fpSet = createOperatorFpSet(doOpenSortOperator, doSort, NULL, NULL, destroyOrderOperatorInfo,
|
||||
getExplainExecInfo);
|
||||
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
@ -127,11 +125,11 @@ SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, i
|
|||
// todo extract function to handle this
|
||||
int32_t numOfCols = taosArrayGetSize(pColMatchInfo);
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColMatchInfo* pmInfo = taosArrayGet(pColMatchInfo, i);
|
||||
ASSERT(pmInfo->matchType == COL_MATCH_FROM_SLOT_ID);
|
||||
SColMatchItem* pmInfo = taosArrayGet(pColMatchInfo, i);
|
||||
// ASSERT(pmInfo->matchType == COL_MATCH_FROM_SLOT_ID);
|
||||
|
||||
SColumnInfoData* pSrc = taosArrayGet(p->pDataBlock, pmInfo->srcSlotId);
|
||||
SColumnInfoData* pDst = taosArrayGet(pDataBlock->pDataBlock, pmInfo->targetSlotId);
|
||||
SColumnInfoData* pDst = taosArrayGet(pDataBlock->pDataBlock, pmInfo->dstSlotId);
|
||||
colDataAssign(pDst, pSrc, p->info.rows, &pDataBlock->info);
|
||||
}
|
||||
|
||||
|
@ -210,13 +208,13 @@ SSDataBlock* doSort(SOperatorInfo* pOperator) {
|
|||
SSDataBlock* pBlock = NULL;
|
||||
while (1) {
|
||||
pBlock = getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity,
|
||||
pInfo->pColMatchInfo, pInfo);
|
||||
pInfo->matchInfo.pList, pInfo);
|
||||
if (pBlock == NULL) {
|
||||
doSetOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
doFilter(pInfo->pCondition, pBlock, pInfo->pColMatchInfo, NULL);
|
||||
doFilter(pInfo->pCondition, pBlock, &pInfo->matchInfo, NULL);
|
||||
if (blockDataGetNumOfRows(pBlock) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
@ -256,7 +254,7 @@ void destroyOrderOperatorInfo(void* param) {
|
|||
|
||||
tsortDestroySortHandle(pInfo->pSortHandle);
|
||||
taosArrayDestroy(pInfo->pSortInfo);
|
||||
taosArrayDestroy(pInfo->pColMatchInfo);
|
||||
taosArrayDestroy(pInfo->matchInfo.pList);
|
||||
taosMemoryFreeClear(param);
|
||||
}
|
||||
|
||||
|
@ -277,20 +275,17 @@ int32_t getExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExplain, uint32_t*
|
|||
typedef enum EChildOperatorStatus { CHILD_OP_NEW_GROUP, CHILD_OP_SAME_GROUP, CHILD_OP_FINISHED } EChildOperatorStatus;
|
||||
|
||||
typedef struct SGroupSortOperatorInfo {
|
||||
SOptrBasicInfo binfo;
|
||||
SArray* pSortInfo;
|
||||
SArray* pColMatchInfo;
|
||||
|
||||
int64_t startTs;
|
||||
uint64_t sortElapsed;
|
||||
bool hasGroupId;
|
||||
uint64_t currGroupId;
|
||||
|
||||
SOptrBasicInfo binfo;
|
||||
SArray* pSortInfo;
|
||||
SColMatchInfo matchInfo;
|
||||
int64_t startTs;
|
||||
uint64_t sortElapsed;
|
||||
bool hasGroupId;
|
||||
uint64_t currGroupId;
|
||||
SSDataBlock* prefetchedSortInput;
|
||||
SSortHandle* pCurrSortHandle;
|
||||
EChildOperatorStatus childOpStatus;
|
||||
|
||||
SSortExecInfo sortExecInfo;
|
||||
SSortExecInfo sortExecInfo;
|
||||
} SGroupSortOperatorInfo;
|
||||
|
||||
SSDataBlock* getGroupSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity,
|
||||
|
@ -320,11 +315,11 @@ SSDataBlock* getGroupSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlo
|
|||
if (p->info.rows > 0) {
|
||||
int32_t numOfCols = taosArrayGetSize(pColMatchInfo);
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColMatchInfo* pmInfo = taosArrayGet(pColMatchInfo, i);
|
||||
ASSERT(pmInfo->matchType == COL_MATCH_FROM_SLOT_ID);
|
||||
SColMatchItem* pmInfo = taosArrayGet(pColMatchInfo, i);
|
||||
// ASSERT(pmInfo->matchType == COL_MATCH_FROM_SLOT_ID);
|
||||
|
||||
SColumnInfoData* pSrc = taosArrayGet(p->pDataBlock, pmInfo->srcSlotId);
|
||||
SColumnInfoData* pDst = taosArrayGet(pDataBlock->pDataBlock, pmInfo->targetSlotId);
|
||||
SColumnInfoData* pDst = taosArrayGet(pDataBlock->pDataBlock, pmInfo->dstSlotId);
|
||||
colDataAssign(pDst, pSrc, p->info.rows, &pDataBlock->info);
|
||||
}
|
||||
|
||||
|
@ -442,7 +437,7 @@ SSDataBlock* doGroupSort(SOperatorInfo* pOperator) {
|
|||
// beginSortGroup would fetch all child blocks of pInfo->currGroupId;
|
||||
ASSERT(pInfo->childOpStatus != CHILD_OP_SAME_GROUP);
|
||||
pBlock = getGroupSortedBlockData(pInfo->pCurrSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity,
|
||||
pInfo->pColMatchInfo, pInfo);
|
||||
pInfo->matchInfo.pList, pInfo);
|
||||
if (pBlock != NULL) {
|
||||
pBlock->info.groupId = pInfo->currGroupId;
|
||||
pOperator->resultInfo.totalRows += pBlock->info.rows;
|
||||
|
@ -474,7 +469,7 @@ void destroyGroupSortOperatorInfo(void* param) {
|
|||
pInfo->binfo.pRes = blockDataDestroy(pInfo->binfo.pRes);
|
||||
|
||||
taosArrayDestroy(pInfo->pSortInfo);
|
||||
taosArrayDestroy(pInfo->pColMatchInfo);
|
||||
taosArrayDestroy(pInfo->matchInfo.pList);
|
||||
|
||||
taosMemoryFreeClear(param);
|
||||
}
|
||||
|
@ -494,8 +489,8 @@ SOperatorInfo* createGroupSortOperatorInfo(SOperatorInfo* downstream, SGroupSort
|
|||
SExprInfo* pExprInfo = createExprInfo(pSortPhyNode->pExprs, NULL, &numOfCols);
|
||||
|
||||
int32_t numOfOutputCols = 0;
|
||||
SArray* pColMatchColInfo =
|
||||
extractColMatchInfo(pSortPhyNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID);
|
||||
int32_t code = extractColMatchInfo(pSortPhyNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID,
|
||||
&pInfo->matchInfo);
|
||||
|
||||
pOperator->exprSupp.pCtx = createSqlFunctionCtx(pExprInfo, numOfCols, &pOperator->exprSupp.rowEntryInfoOffset);
|
||||
pInfo->binfo.pRes = pResBlock;
|
||||
|
@ -503,8 +498,7 @@ SOperatorInfo* createGroupSortOperatorInfo(SOperatorInfo* downstream, SGroupSort
|
|||
initResultSizeInfo(&pOperator->resultInfo, 1024);
|
||||
|
||||
pInfo->pSortInfo = createSortInfo(pSortPhyNode->pSortKeys);
|
||||
;
|
||||
pInfo->pColMatchInfo = pColMatchColInfo;
|
||||
|
||||
pOperator->name = "GroupSortOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT;
|
||||
pOperator->blocking = false;
|
||||
|
@ -515,9 +509,9 @@ SOperatorInfo* createGroupSortOperatorInfo(SOperatorInfo* downstream, SGroupSort
|
|||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doGroupSort, NULL, NULL, destroyGroupSortOperatorInfo,
|
||||
NULL, NULL, getGroupSortExplainExecInfo);
|
||||
getGroupSortExplainExecInfo);
|
||||
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
@ -535,20 +529,18 @@ _error:
|
|||
// Multiway Sort Merge operator
|
||||
typedef struct SMultiwayMergeOperatorInfo {
|
||||
SOptrBasicInfo binfo;
|
||||
int32_t bufPageSize;
|
||||
uint32_t sortBufSize; // max buffer size for in-memory sort
|
||||
|
||||
int32_t bufPageSize;
|
||||
uint32_t sortBufSize; // max buffer size for in-memory sort
|
||||
|
||||
SArray* pSortInfo;
|
||||
SSortHandle* pSortHandle;
|
||||
SArray* pColMatchInfo; // for index map from table scan output
|
||||
|
||||
SSDataBlock* pInputBlock;
|
||||
int64_t startTs; // sort start time
|
||||
bool groupSort;
|
||||
bool hasGroupId;
|
||||
uint64_t groupId;
|
||||
STupleHandle* prefetchedTuple;
|
||||
SArray* pSortInfo;
|
||||
SSortHandle* pSortHandle;
|
||||
SColMatchInfo matchInfo;
|
||||
SSDataBlock* pInputBlock;
|
||||
int64_t startTs; // sort start time
|
||||
bool groupSort;
|
||||
bool hasGroupId;
|
||||
uint64_t groupId;
|
||||
STupleHandle* prefetchedTuple;
|
||||
} SMultiwayMergeOperatorInfo;
|
||||
|
||||
int32_t doOpenMultiwayMergeOperator(SOperatorInfo* pOperator) {
|
||||
|
@ -645,11 +637,11 @@ SSDataBlock* getMultiwaySortedBlockData(SSortHandle* pHandle, SSDataBlock* pData
|
|||
blockDataEnsureCapacity(pDataBlock, p->info.rows);
|
||||
int32_t numOfCols = taosArrayGetSize(pColMatchInfo);
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColMatchInfo* pmInfo = taosArrayGet(pColMatchInfo, i);
|
||||
ASSERT(pmInfo->matchType == COL_MATCH_FROM_SLOT_ID);
|
||||
SColMatchItem* pmInfo = taosArrayGet(pColMatchInfo, i);
|
||||
// ASSERT(pColMatchInfo-> == COL_MATCH_FROM_SLOT_ID);
|
||||
|
||||
SColumnInfoData* pSrc = taosArrayGet(p->pDataBlock, pmInfo->srcSlotId);
|
||||
SColumnInfoData* pDst = taosArrayGet(pDataBlock->pDataBlock, pmInfo->targetSlotId);
|
||||
SColumnInfoData* pDst = taosArrayGet(pDataBlock->pDataBlock, pmInfo->dstSlotId);
|
||||
colDataAssign(pDst, pSrc, p->info.rows, &pDataBlock->info);
|
||||
}
|
||||
|
||||
|
@ -678,7 +670,7 @@ SSDataBlock* doMultiwayMerge(SOperatorInfo* pOperator) {
|
|||
}
|
||||
|
||||
SSDataBlock* pBlock = getMultiwaySortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes,
|
||||
pOperator->resultInfo.capacity, pInfo->pColMatchInfo, pOperator);
|
||||
pOperator->resultInfo.capacity, pInfo->matchInfo.pList, pOperator);
|
||||
if (pBlock != NULL) {
|
||||
pOperator->resultInfo.totalRows += pBlock->info.rows;
|
||||
} else {
|
||||
|
@ -694,7 +686,7 @@ void destroyMultiwayMergeOperatorInfo(void* param) {
|
|||
|
||||
tsortDestroySortHandle(pInfo->pSortHandle);
|
||||
taosArrayDestroy(pInfo->pSortInfo);
|
||||
taosArrayDestroy(pInfo->pColMatchInfo);
|
||||
taosArrayDestroy(pInfo->matchInfo.pList);
|
||||
|
||||
taosMemoryFreeClear(param);
|
||||
}
|
||||
|
@ -731,15 +723,14 @@ SOperatorInfo* createMultiwayMergeOperatorInfo(SOperatorInfo** downStreams, size
|
|||
|
||||
SArray* pSortInfo = createSortInfo(pMergePhyNode->pMergeKeys);
|
||||
int32_t numOfOutputCols = 0;
|
||||
SArray* pColMatchColInfo =
|
||||
extractColMatchInfo(pMergePhyNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID);
|
||||
|
||||
code = extractColMatchInfo(pMergePhyNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID, &pInfo->matchInfo);
|
||||
SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, 0);
|
||||
SSDataBlock* pInputBlock = createResDataBlock(pChildNode->pOutputDataBlockDesc);
|
||||
initResultSizeInfo(&pOperator->resultInfo, 1024);
|
||||
|
||||
pInfo->groupSort = pMergePhyNode->groupSort;
|
||||
pInfo->pSortInfo = pSortInfo;
|
||||
pInfo->pColMatchInfo = pColMatchColInfo;
|
||||
pInfo->pInputBlock = pInputBlock;
|
||||
pInfo->bufPageSize = getProperSortPageSize(rowSize);
|
||||
pInfo->sortBufSize = pInfo->bufPageSize * (numStreams + 1); // one additional is reserved for merged result.
|
||||
|
@ -752,7 +743,7 @@ SOperatorInfo* createMultiwayMergeOperatorInfo(SOperatorInfo** downStreams, size
|
|||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(doOpenMultiwayMergeOperator, doMultiwayMerge, NULL, NULL,
|
||||
destroyMultiwayMergeOperatorInfo, NULL, NULL, getMultiwayMergeExplainExecInfo);
|
||||
destroyMultiwayMergeOperatorInfo, getMultiwayMergeExplainExecInfo);
|
||||
|
||||
code = appendDownstream(pOperator, downStreams, numStreams);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
|
|
@ -722,7 +722,7 @@ void destroyStreamFillOperatorInfo(void* param) {
|
|||
pInfo->pSrcBlock = blockDataDestroy(pInfo->pSrcBlock);
|
||||
pInfo->pPrevSrcBlock = blockDataDestroy(pInfo->pPrevSrcBlock);
|
||||
pInfo->pDelRes = blockDataDestroy(pInfo->pDelRes);
|
||||
pInfo->pColMatchColInfo = taosArrayDestroy(pInfo->pColMatchColInfo);
|
||||
pInfo->matchInfo.pList = taosArrayDestroy(pInfo->matchInfo.pList);
|
||||
taosMemoryFree(pInfo);
|
||||
}
|
||||
|
||||
|
@ -1499,7 +1499,7 @@ static SSDataBlock* doStreamFill(SOperatorInfo* pOperator) {
|
|||
}
|
||||
|
||||
doStreamFillImpl(pOperator);
|
||||
doFilter(pInfo->pCondition, pInfo->pRes, pInfo->pColMatchColInfo, NULL);
|
||||
doFilter(pInfo->pCondition, pInfo->pRes, &pInfo->matchInfo, NULL);
|
||||
memcpy(pInfo->pRes->info.parTbName, pInfo->pSrcBlock->info.parTbName, TSDB_TABLE_NAME_LEN);
|
||||
pOperator->resultInfo.totalRows += pInfo->pRes->info.rows;
|
||||
if (pInfo->pRes->info.rows > 0) {
|
||||
|
@ -1624,7 +1624,6 @@ SOperatorInfo* createStreamFillOperatorInfo(SOperatorInfo* downstream, SStreamFi
|
|||
goto _error;
|
||||
}
|
||||
|
||||
SResultInfo* pResultInfo = &pOperator->resultInfo;
|
||||
initResultSizeInfo(&pOperator->resultInfo, 4096);
|
||||
pInfo->pRes = createResDataBlock(pPhyFillNode->node.pOutputDataBlockDesc);
|
||||
pInfo->pSrcBlock = createResDataBlock(pPhyFillNode->node.pOutputDataBlockDesc);
|
||||
|
@ -1676,11 +1675,10 @@ SOperatorInfo* createStreamFillOperatorInfo(SOperatorInfo* downstream, SStreamFi
|
|||
pInfo->primarySrcSlotId = ((SColumnNode*)((STargetNode*)pPhyFillNode->pWStartTs)->pExpr)->slotId;
|
||||
|
||||
int32_t numOfOutputCols = 0;
|
||||
SArray* pColMatchColInfo = extractColMatchInfo(pPhyFillNode->pFillExprs, pPhyFillNode->node.pOutputDataBlockDesc,
|
||||
&numOfOutputCols, COL_MATCH_FROM_SLOT_ID);
|
||||
int32_t code = extractColMatchInfo(pPhyFillNode->pFillExprs, pPhyFillNode->node.pOutputDataBlockDesc,
|
||||
&numOfOutputCols, COL_MATCH_FROM_SLOT_ID, &pInfo->matchInfo);
|
||||
pInfo->pCondition = pPhyFillNode->node.pConditions;
|
||||
pInfo->pColMatchColInfo = pColMatchColInfo;
|
||||
int32_t code = initExprSupp(&pOperator->exprSupp, pFillExprInfo, numOfFillCols);
|
||||
code = initExprSupp(&pOperator->exprSupp, pFillExprInfo, numOfFillCols);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
@ -1694,7 +1692,7 @@ SOperatorInfo* createStreamFillOperatorInfo(SOperatorInfo* downstream, SStreamFi
|
|||
pOperator->info = pInfo;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamFill, NULL, NULL, destroyStreamFillOperatorInfo,
|
||||
NULL, NULL, NULL);
|
||||
NULL);
|
||||
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
|
|
@ -1541,7 +1541,8 @@ static void deleteIntervalDiscBuf(SStreamState* pState, SHashObj* pPullDataMap,
|
|||
}
|
||||
}
|
||||
|
||||
if (qDebugFlag & DEBUG_DEBUG) {
|
||||
// for debug
|
||||
if (qDebugFlag & DEBUG_DEBUG && mark > 0) {
|
||||
SStreamStateCur* pCur = streamStateGetCur(pState, key);
|
||||
int32_t code = streamStateCurPrev(pState, pCur);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
|
@ -1831,8 +1832,7 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SIntervalPh
|
|||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(doOpenIntervalAgg, doBuildIntervalResult, NULL, NULL,
|
||||
destroyIntervalOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL);
|
||||
pOperator->fpSet = createOperatorFpSet(doOpenIntervalAgg, doBuildIntervalResult, NULL, NULL, destroyIntervalOperatorInfo, NULL);
|
||||
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -2638,8 +2638,7 @@ SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SPhysiNode
|
|||
pOperator->info = pInfo;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(operatorDummyOpenFn, doTimeslice, NULL, NULL, destroyTimeSliceOperatorInfo, NULL, NULL, NULL);
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTimeslice, NULL, NULL, destroyTimeSliceOperatorInfo, NULL);
|
||||
|
||||
blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity);
|
||||
|
||||
|
@ -2710,7 +2709,7 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SStateWi
|
|||
pOperator->info = pInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(openStateWindowAggOptr, doStateWindowAgg, NULL, NULL,
|
||||
destroyStateWindowOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL);
|
||||
destroyStateWindowOperatorInfo, NULL);
|
||||
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -2784,7 +2783,7 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SSessionW
|
|||
pOperator->info = pInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doSessionWindowAgg, NULL, NULL,
|
||||
destroySWindowOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL);
|
||||
destroySWindowOperatorInfo, NULL);
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -3465,8 +3464,7 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream,
|
|||
pOperator->info = pInfo;
|
||||
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(NULL, doStreamFinalIntervalAgg, NULL, NULL, destroyStreamFinalIntervalOperatorInfo,
|
||||
aggEncodeResultRow, aggDecodeResultRow, NULL);
|
||||
createOperatorFpSet(NULL, doStreamFinalIntervalAgg, NULL, NULL, destroyStreamFinalIntervalOperatorInfo, NULL);
|
||||
if (pPhyNode->type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL) {
|
||||
initIntervalDownStream(downstream, pPhyNode->type, &pInfo->aggSup, &pInfo->interval, &pInfo->twAggSup);
|
||||
}
|
||||
|
@ -4268,7 +4266,7 @@ SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPh
|
|||
pOperator->info = pInfo;
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(operatorDummyOpenFn, doStreamSessionAgg, NULL, NULL, destroyStreamSessionAggOperatorInfo,
|
||||
aggEncodeResultRow, aggDecodeResultRow, NULL);
|
||||
NULL);
|
||||
if (downstream) {
|
||||
initDownStream(downstream, &pInfo->streamAggSup, pInfo->twAggSup.waterMark, pOperator->operatorType,
|
||||
pInfo->primaryTsIndex);
|
||||
|
@ -4415,7 +4413,7 @@ SOperatorInfo* createStreamFinalSessionAggOperatorInfo(SOperatorInfo* downstream
|
|||
pOperator->name = "StreamSessionSemiAggOperator";
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(operatorDummyOpenFn, doStreamSessionSemiAgg, NULL, NULL,
|
||||
destroyStreamSessionAggOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL);
|
||||
destroyStreamSessionAggOperatorInfo, NULL);
|
||||
}
|
||||
|
||||
pInfo->pGroupIdTbNameMap =
|
||||
|
@ -4792,7 +4790,7 @@ SOperatorInfo* createStreamStateAggOperatorInfo(SOperatorInfo* downstream, SPhys
|
|||
pOperator->pTaskInfo = pTaskInfo;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamStateAgg, NULL, NULL,
|
||||
destroyStreamStateOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL);
|
||||
destroyStreamStateOperatorInfo, NULL);
|
||||
initDownStream(downstream, &pInfo->streamAggSup, pInfo->twAggSup.waterMark, pOperator->operatorType,
|
||||
pInfo->primaryTsIndex);
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
|
@ -5069,7 +5067,7 @@ SOperatorInfo* createMergeAlignedIntervalOperatorInfo(SOperatorInfo* downstream,
|
|||
pOperator->info = miaInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, mergeAlignedIntervalAgg, NULL, NULL,
|
||||
destroyMAIOperatorInfo, NULL, NULL, NULL);
|
||||
destroyMAIOperatorInfo, NULL);
|
||||
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -5381,7 +5379,7 @@ SOperatorInfo* createMergeIntervalOperatorInfo(SOperatorInfo* downstream, SMerge
|
|||
pOperator->info = pMergeIntervalInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doMergeIntervalAgg, NULL, NULL,
|
||||
destroyMergeIntervalOperatorInfo, NULL, NULL, NULL);
|
||||
destroyMergeIntervalOperatorInfo, NULL);
|
||||
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -5622,7 +5620,7 @@ SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SPhys
|
|||
pOperator->info = pInfo;
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(operatorDummyOpenFn, doStreamIntervalAgg, NULL, NULL, destroyStreamFinalIntervalOperatorInfo,
|
||||
aggEncodeResultRow, aggDecodeResultRow, NULL);
|
||||
NULL);
|
||||
|
||||
initIntervalDownStream(downstream, pPhyNode->type, &pInfo->aggSup, &pInfo->interval, &pInfo->twAggSup);
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
|
|
|
@ -23,11 +23,6 @@ extern "C" {
|
|||
#include "function.h"
|
||||
#include "functionMgt.h"
|
||||
|
||||
bool dummyGetEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* UNUSED_PARAM(pEnv));
|
||||
bool dummyInit(SqlFunctionCtx* UNUSED_PARAM(pCtx), SResultRowEntryInfo* UNUSED_PARAM(pResultInfo));
|
||||
int32_t dummyProcess(SqlFunctionCtx* UNUSED_PARAM(pCtx));
|
||||
int32_t dummyFinalize(SqlFunctionCtx* UNUSED_PARAM(pCtx), SSDataBlock* UNUSED_PARAM(pBlock));
|
||||
|
||||
bool functionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
int32_t functionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||
int32_t functionFinalizeWithResultBuf(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, char* finalResult);
|
||||
|
|
|
@ -209,7 +209,7 @@ static int32_t countTrailingSpaces(const SValueNode* pVal, bool isLtrim) {
|
|||
return numOfSpaces;
|
||||
}
|
||||
|
||||
void static addTimezoneParam(SNodeList* pList) {
|
||||
static int32_t addTimezoneParam(SNodeList* pList) {
|
||||
char buf[6] = {0};
|
||||
time_t t = taosTime(NULL);
|
||||
struct tm tmInfo;
|
||||
|
@ -218,6 +218,10 @@ void static addTimezoneParam(SNodeList* pList) {
|
|||
int32_t len = (int32_t)strlen(buf);
|
||||
|
||||
SValueNode* pVal = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
||||
if (pVal == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pVal->literal = strndup(buf, len);
|
||||
pVal->isDuration = false;
|
||||
pVal->translate = true;
|
||||
|
@ -229,10 +233,15 @@ void static addTimezoneParam(SNodeList* pList) {
|
|||
strncpy(varDataVal(pVal->datum.p), pVal->literal, len);
|
||||
|
||||
nodesListAppend(pList, (SNode*)pVal);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void static addDbPrecisonParam(SNodeList** pList, uint8_t precision) {
|
||||
static int32_t addDbPrecisonParam(SNodeList** pList, uint8_t precision) {
|
||||
SValueNode* pVal = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
||||
if (pVal == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pVal->literal = NULL;
|
||||
pVal->isDuration = false;
|
||||
pVal->translate = true;
|
||||
|
@ -244,6 +253,7 @@ void static addDbPrecisonParam(SNodeList** pList, uint8_t precision) {
|
|||
pVal->typeData = (int64_t)precision;
|
||||
|
||||
nodesListMakeAppend(pList, (SNode*)pVal);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
// There is only one parameter of numeric type, and the return type is parameter type
|
||||
|
@ -465,7 +475,10 @@ static int32_t translateNowToday(SFunctionNode* pFunc, char* pErrBuf, int32_t le
|
|||
|
||||
// add database precision as param
|
||||
uint8_t dbPrec = pFunc->node.resType.precision;
|
||||
addDbPrecisonParam(&pFunc->pParameterList, dbPrec);
|
||||
int32_t code = addDbPrecisonParam(&pFunc->pParameterList, dbPrec);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
pFunc->node.resType = (SDataType){.bytes = sizeof(int64_t), .type = TSDB_DATA_TYPE_TIMESTAMP};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -1487,7 +1500,10 @@ static int32_t translateIrate(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
|
|||
|
||||
// add database precision as param
|
||||
uint8_t dbPrec = pFunc->node.resType.precision;
|
||||
addDbPrecisonParam(&pFunc->pParameterList, dbPrec);
|
||||
int32_t code = addDbPrecisonParam(&pFunc->pParameterList, dbPrec);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -1497,7 +1513,8 @@ static int32_t translateInterp(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
|
|||
int32_t numOfParams = LIST_LENGTH(pFunc->pParameterList);
|
||||
uint8_t dbPrec = pFunc->node.resType.precision;
|
||||
|
||||
if (1 != numOfParams && 3 != numOfParams && 4 != numOfParams) {
|
||||
//if (1 != numOfParams && 3 != numOfParams && 4 != numOfParams) {
|
||||
if (1 != numOfParams) {
|
||||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
|
@ -1507,6 +1524,7 @@ static int32_t translateInterp(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
|
|||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (3 <= numOfParams) {
|
||||
int64_t timeVal[2] = {0};
|
||||
for (int32_t i = 1; i < 3; ++i) {
|
||||
|
@ -1545,6 +1563,7 @@ static int32_t translateInterp(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
|
|||
"INTERP function time interval parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
pFunc->node.resType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -1810,7 +1829,10 @@ static int32_t translateCast(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|||
|
||||
// add database precision as param
|
||||
uint8_t dbPrec = pFunc->node.resType.precision;
|
||||
addDbPrecisonParam(&pFunc->pParameterList, dbPrec);
|
||||
int32_t code = addDbPrecisonParam(&pFunc->pParameterList, dbPrec);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -1844,7 +1866,10 @@ static int32_t translateToIso8601(SFunctionNode* pFunc, char* pErrBuf, int32_t l
|
|||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, "Invalid timzone format");
|
||||
}
|
||||
} else { // add default client timezone
|
||||
addTimezoneParam(pFunc->pParameterList);
|
||||
int32_t code = addTimezoneParam(pFunc->pParameterList);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
// set result type
|
||||
|
@ -1863,7 +1888,10 @@ static int32_t translateToUnixtimestamp(SFunctionNode* pFunc, char* pErrBuf, int
|
|||
|
||||
// add database precision as param
|
||||
uint8_t dbPrec = pFunc->node.resType.precision;
|
||||
addDbPrecisonParam(&pFunc->pParameterList, dbPrec);
|
||||
int32_t code = addDbPrecisonParam(&pFunc->pParameterList, dbPrec);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -1894,7 +1922,10 @@ static int32_t translateTimeTruncate(SFunctionNode* pFunc, char* pErrBuf, int32_
|
|||
"TIMETRUNCATE function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]");
|
||||
}
|
||||
|
||||
addDbPrecisonParam(&pFunc->pParameterList, dbPrec);
|
||||
int32_t code = addDbPrecisonParam(&pFunc->pParameterList, dbPrec);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
pFunc->node.resType =
|
||||
(SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes, .type = TSDB_DATA_TYPE_TIMESTAMP};
|
||||
|
@ -1935,7 +1966,10 @@ static int32_t translateTimeDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t le
|
|||
}
|
||||
}
|
||||
|
||||
addDbPrecisonParam(&pFunc->pParameterList, dbPrec);
|
||||
int32_t code = addDbPrecisonParam(&pFunc->pParameterList, dbPrec);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -1970,11 +2004,6 @@ static int32_t translateBlockDistInfoFunc(SFunctionNode* pFunc, char* pErrBuf, i
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateGroupKeyFunc(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
pFunc->node.resType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static bool getBlockDistFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
|
||||
pEnv->calcMemSize = sizeof(STableBlockDistInfo);
|
||||
return true;
|
||||
|
@ -2319,6 +2348,8 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.finalizeFunc = elapsedFinalize,
|
||||
.invertFunc = NULL,
|
||||
.combineFunc = elapsedCombine,
|
||||
.pPartialFunc = "_elapsed_partial",
|
||||
.pMergeFunc = "_elapsed_merge"
|
||||
},
|
||||
{
|
||||
.name = "_elapsed_partial",
|
||||
|
|
|
@ -429,14 +429,6 @@ typedef struct SGroupKeyInfo {
|
|||
(_p).val = (_v); \
|
||||
} while (0)
|
||||
|
||||
bool dummyGetEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* UNUSED_PARAM(pEnv)) { return true; }
|
||||
|
||||
bool dummyInit(SqlFunctionCtx* UNUSED_PARAM(pCtx), SResultRowEntryInfo* UNUSED_PARAM(pResultInfo)) { return true; }
|
||||
|
||||
int32_t dummyProcess(SqlFunctionCtx* UNUSED_PARAM(pCtx)) { return 0; }
|
||||
|
||||
int32_t dummyFinalize(SqlFunctionCtx* UNUSED_PARAM(pCtx), SSDataBlock* UNUSED_PARAM(pBlock)) { return 0; }
|
||||
|
||||
bool functionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) {
|
||||
if (pResultInfo->initialized) {
|
||||
return false;
|
||||
|
@ -1861,7 +1853,7 @@ int32_t stddevFunction(SqlFunctionCtx* pCtx) {
|
|||
numOfElem += 1;
|
||||
pStddevRes->count += 1;
|
||||
pStddevRes->usum += plist[i];
|
||||
pStddevRes->quadraticISum += plist[i] * plist[i];
|
||||
pStddevRes->quadraticUSum += plist[i] * plist[i];
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -1877,7 +1869,7 @@ int32_t stddevFunction(SqlFunctionCtx* pCtx) {
|
|||
numOfElem += 1;
|
||||
pStddevRes->count += 1;
|
||||
pStddevRes->usum += plist[i];
|
||||
pStddevRes->quadraticISum += plist[i] * plist[i];
|
||||
pStddevRes->quadraticUSum += plist[i] * plist[i];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1892,7 +1884,7 @@ int32_t stddevFunction(SqlFunctionCtx* pCtx) {
|
|||
numOfElem += 1;
|
||||
pStddevRes->count += 1;
|
||||
pStddevRes->usum += plist[i];
|
||||
pStddevRes->quadraticISum += plist[i] * plist[i];
|
||||
pStddevRes->quadraticUSum += plist[i] * plist[i];
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -1908,7 +1900,7 @@ int32_t stddevFunction(SqlFunctionCtx* pCtx) {
|
|||
numOfElem += 1;
|
||||
pStddevRes->count += 1;
|
||||
pStddevRes->usum += plist[i];
|
||||
pStddevRes->quadraticISum += plist[i] * plist[i];
|
||||
pStddevRes->quadraticUSum += plist[i] * plist[i];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -5359,7 +5351,7 @@ int32_t modeFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
|
||||
int32_t currentRow = pBlock->info.rows;
|
||||
|
||||
int32_t resIndex;
|
||||
int32_t resIndex = -1;
|
||||
int32_t maxCount = 0;
|
||||
for (int32_t i = 0; i < pInfo->numOfPoints; ++i) {
|
||||
SModeItem* pItem = (SModeItem*)(pInfo->pItems + i * (sizeof(SModeItem) + pInfo->colBytes));
|
||||
|
@ -5369,8 +5361,12 @@ int32_t modeFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
}
|
||||
}
|
||||
|
||||
SModeItem* pResItem = (SModeItem*)(pInfo->pItems + resIndex * (sizeof(SModeItem) + pInfo->colBytes));
|
||||
colDataAppend(pCol, currentRow, pResItem->data, (maxCount == 0) ? true : false);
|
||||
if (maxCount != 0) {
|
||||
SModeItem* pResItem = (SModeItem*)(pInfo->pItems + resIndex * (sizeof(SModeItem) + pInfo->colBytes));
|
||||
colDataAppend(pCol, currentRow, pResItem->data, false);
|
||||
} else {
|
||||
colDataAppendNULL(pCol, currentRow);
|
||||
}
|
||||
|
||||
return pResInfo->numOfRes;
|
||||
}
|
||||
|
|
|
@ -495,7 +495,7 @@ double getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction)
|
|||
|
||||
int32_t groupId = getGroupId(pMemBucket->numOfSlots, i, pMemBucket->times - 1);
|
||||
SIDList list = taosHashGet(pMemBucket->groupPagesMap, &groupId, sizeof(groupId));
|
||||
assert(list->size > 0);
|
||||
ASSERT(list != NULL && list->size > 0);
|
||||
|
||||
for (int32_t f = 0; f < list->size; ++f) {
|
||||
SPageInfo *pgInfo = *(SPageInfo **)taosArrayGet(list, f);
|
||||
|
|
|
@ -203,7 +203,6 @@ int32_t nodesReleaseAllocator(int64_t allocatorId) {
|
|||
return taosReleaseRef(g_allocatorReqRefPool, allocatorId);
|
||||
}
|
||||
|
||||
|
||||
int64_t nodesMakeAllocatorWeakRef(int64_t allocatorId) {
|
||||
if (allocatorId <= 0) {
|
||||
return 0;
|
||||
|
@ -936,6 +935,7 @@ void nodesDestroyNode(SNode* pNode) {
|
|||
}
|
||||
case QUERY_NODE_SHOW_DNODE_VARIABLES_STMT:
|
||||
nodesDestroyNode(((SShowDnodeVariablesStmt*)pNode)->pDnodeId);
|
||||
nodesDestroyNode(((SShowDnodeVariablesStmt*)pNode)->pLikePattern);
|
||||
break;
|
||||
case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
|
||||
taosMemoryFreeClear(((SShowCreateDatabaseStmt*)pNode)->pCfg);
|
||||
|
|
|
@ -176,7 +176,7 @@ SNode* createShowStmtWithCond(SAstCreateContext* pCxt, ENodeType type, SNode* pD
|
|||
SNode* createShowCreateDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName);
|
||||
SNode* createShowCreateTableStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pRealTable);
|
||||
SNode* createShowTableDistributedStmt(SAstCreateContext* pCxt, SNode* pRealTable);
|
||||
SNode* createShowDnodeVariablesStmt(SAstCreateContext* pCxt, SNode* pDnodeId);
|
||||
SNode* createShowDnodeVariablesStmt(SAstCreateContext* pCxt, SNode* pDnodeId, SNode* pLikePattern);
|
||||
SNode* createShowVnodesStmt(SAstCreateContext* pCxt, SNode* pDnodeId, SNode* pDnodeEndpoint);
|
||||
SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const SToken* pPassword, int8_t sysinfo);
|
||||
SNode* createAlterUserStmt(SAstCreateContext* pCxt, SToken* pUserName, int8_t alterType, const SToken* pVal);
|
||||
|
|
|
@ -1,148 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_DATABLOCKMGT_H
|
||||
#define TDENGINE_DATABLOCKMGT_H
|
||||
|
||||
#include "catalog.h"
|
||||
#include "os.h"
|
||||
#include "query.h"
|
||||
#include "tname.h"
|
||||
#include "ttypes.h"
|
||||
|
||||
#define IS_DATA_COL_ORDERED(spd) ((spd->orderStatus) == (int8_t)ORDER_STATUS_ORDERED)
|
||||
|
||||
typedef enum EOrderStatus {
|
||||
ORDER_STATUS_UNKNOWN = 0,
|
||||
ORDER_STATUS_ORDERED = 1,
|
||||
ORDER_STATUS_DISORDERED = 2,
|
||||
} EOrderStatus;
|
||||
|
||||
typedef enum EValStat {
|
||||
VAL_STAT_HAS = 0x0, // 0 means has val
|
||||
VAL_STAT_NONE = 0x01, // 1 means no val
|
||||
} EValStat;
|
||||
|
||||
typedef struct SBoundColumn {
|
||||
int32_t offset; // all column offset value
|
||||
int32_t toffset; // first part offset for SDataRow TODO: get offset from STSchema on future
|
||||
uint8_t valStat; // EValStat. denote if current column bound or not(0 means has val, 1 means no val)
|
||||
} SBoundColumn;
|
||||
|
||||
typedef struct {
|
||||
col_id_t schemaColIdx;
|
||||
col_id_t boundIdx;
|
||||
col_id_t finalIdx;
|
||||
} SBoundIdxInfo;
|
||||
|
||||
typedef struct SParsedDataColInfo {
|
||||
col_id_t numOfCols;
|
||||
col_id_t numOfBound;
|
||||
uint16_t flen; // TODO: get from STSchema
|
||||
uint16_t allNullLen; // TODO: get from STSchema(base on SDataRow)
|
||||
uint16_t extendedVarLen;
|
||||
uint16_t boundNullLen; // bound column len with all NULL value(without VarDataOffsetT/SColIdx part)
|
||||
col_id_t *boundColumns; // bound column idx according to schema
|
||||
SBoundColumn *cols;
|
||||
SBoundIdxInfo *colIdxInfo;
|
||||
int8_t orderStatus; // bound columns
|
||||
} SParsedDataColInfo;
|
||||
|
||||
typedef struct {
|
||||
uint8_t rowType; // default is 0, that is SDataRow
|
||||
int32_t rowSize;
|
||||
} SMemRowBuilder;
|
||||
|
||||
typedef struct STableDataBlocks {
|
||||
int8_t tsSource; // where does the UNIX timestamp come from, server or client
|
||||
bool ordered; // if current rows are ordered or not
|
||||
int32_t vgId; // virtual group id
|
||||
int64_t prevTS; // previous timestamp, recorded to decide if the records array is ts ascending
|
||||
int32_t numOfTables; // number of tables in current submit block
|
||||
int32_t rowSize; // row size for current table
|
||||
uint32_t nAllocSize;
|
||||
uint32_t headerSize; // header for table info (uid, tid, submit metadata)
|
||||
uint32_t size;
|
||||
STableMeta *pTableMeta; // the tableMeta of current table, the table meta will be used during submit, keep a ref to
|
||||
// avoid to be removed from cache
|
||||
char *pData;
|
||||
bool cloned;
|
||||
int32_t createTbReqLen;
|
||||
SParsedDataColInfo boundColumnInfo;
|
||||
SRowBuilder rowBuilder;
|
||||
} STableDataBlocks;
|
||||
|
||||
static FORCE_INLINE int32_t getExtendedRowSize(STableDataBlocks *pBlock) {
|
||||
STableComInfo *pTableInfo = &pBlock->pTableMeta->tableInfo;
|
||||
ASSERT(pBlock->rowSize == pTableInfo->rowSize);
|
||||
return pBlock->rowSize + TD_ROW_HEAD_LEN - sizeof(TSKEY) + pBlock->boundColumnInfo.extendedVarLen +
|
||||
(int32_t)TD_BITMAP_BYTES(pTableInfo->numOfColumns - 1);
|
||||
}
|
||||
|
||||
static FORCE_INLINE void getSTSRowAppendInfo(uint8_t rowType, SParsedDataColInfo *spd, col_id_t idx, int32_t *toffset,
|
||||
col_id_t *colIdx) {
|
||||
col_id_t schemaIdx = 0;
|
||||
if (IS_DATA_COL_ORDERED(spd)) {
|
||||
schemaIdx = spd->boundColumns[idx];
|
||||
if (TD_IS_TP_ROW_T(rowType)) {
|
||||
*toffset = (spd->cols + schemaIdx)->toffset; // the offset of firstPart
|
||||
*colIdx = schemaIdx;
|
||||
} else {
|
||||
*toffset = idx * sizeof(SKvRowIdx); // the offset of SKvRowIdx
|
||||
*colIdx = idx;
|
||||
}
|
||||
} else {
|
||||
ASSERT(idx == (spd->colIdxInfo + idx)->boundIdx);
|
||||
schemaIdx = (spd->colIdxInfo + idx)->schemaColIdx;
|
||||
if (TD_IS_TP_ROW_T(rowType)) {
|
||||
*toffset = (spd->cols + schemaIdx)->toffset;
|
||||
*colIdx = schemaIdx;
|
||||
} else {
|
||||
*toffset = ((spd->colIdxInfo + idx)->finalIdx) * sizeof(SKvRowIdx);
|
||||
*colIdx = (spd->colIdxInfo + idx)->finalIdx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t setBlockInfo(SSubmitBlk *pBlocks, STableDataBlocks *dataBuf, int32_t numOfRows) {
|
||||
pBlocks->suid = (TSDB_NORMAL_TABLE == dataBuf->pTableMeta->tableType ? 0 : dataBuf->pTableMeta->suid);
|
||||
pBlocks->uid = dataBuf->pTableMeta->uid;
|
||||
pBlocks->sversion = dataBuf->pTableMeta->sversion;
|
||||
pBlocks->schemaLen = dataBuf->createTbReqLen;
|
||||
|
||||
if (pBlocks->numOfRows + numOfRows >= INT32_MAX) {
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
} else {
|
||||
pBlocks->numOfRows += numOfRows;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t schemaIdxCompar(const void *lhs, const void *rhs);
|
||||
int32_t boundIdxCompar(const void *lhs, const void *rhs);
|
||||
void setBoundColumnInfo(SParsedDataColInfo *pColList, SSchema *pSchema, col_id_t numOfCols);
|
||||
void destroyBlockArrayList(SArray *pDataBlockList);
|
||||
void destroyBlockHashmap(SHashObj *pDataBlockHash);
|
||||
int initRowBuilder(SRowBuilder *pBuilder, int16_t schemaVer, SParsedDataColInfo *pColInfo);
|
||||
int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t *numOfRows);
|
||||
int32_t getDataBlockFromList(SHashObj *pHashList, void *id, int32_t idLen, int32_t size, int32_t startOffset,
|
||||
int32_t rowSize, STableMeta *pTableMeta, STableDataBlocks **dataBlocks, SArray *pBlockList,
|
||||
SVCreateTbReq *pCreateTbReq);
|
||||
int32_t mergeTableDataBlocks(SHashObj *pHashObj, uint8_t payloadType, SArray **pVgDataBlocks);
|
||||
int32_t buildCreateTbMsg(STableDataBlocks *pBlocks, SVCreateTbReq *pCreateTbReq);
|
||||
|
||||
int32_t allocateMemForSize(STableDataBlocks *pDataBlock, int32_t allSize);
|
||||
|
||||
#endif // TDENGINE_DATABLOCKMGT_H
|
|
@ -0,0 +1,167 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_PAR_INSERT_UTIL_H
|
||||
#define TDENGINE_PAR_INSERT_UTIL_H
|
||||
|
||||
#include "parUtil.h"
|
||||
|
||||
struct SToken;
|
||||
|
||||
#define IS_DATA_COL_ORDERED(spd) ((spd->orderStatus) == (int8_t)ORDER_STATUS_ORDERED)
|
||||
|
||||
#define NEXT_TOKEN(pSql, sToken) \
|
||||
do { \
|
||||
int32_t index = 0; \
|
||||
sToken = tStrGetToken(pSql, &index, false); \
|
||||
pSql += index; \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_CODE(expr) \
|
||||
do { \
|
||||
int32_t code = expr; \
|
||||
if (TSDB_CODE_SUCCESS != code) { \
|
||||
return code; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
typedef enum EOrderStatus {
|
||||
ORDER_STATUS_UNKNOWN = 0,
|
||||
ORDER_STATUS_ORDERED = 1,
|
||||
ORDER_STATUS_DISORDERED = 2,
|
||||
} EOrderStatus;
|
||||
|
||||
typedef enum EValStat {
|
||||
VAL_STAT_HAS = 0x0, // 0 means has val
|
||||
VAL_STAT_NONE = 0x01, // 1 means no val
|
||||
} EValStat;
|
||||
|
||||
typedef struct SBoundColumn {
|
||||
int32_t offset; // all column offset value
|
||||
int32_t toffset; // first part offset for SDataRow TODO: get offset from STSchema on future
|
||||
uint8_t valStat; // EValStat. denote if current column bound or not(0 means has val, 1 means no val)
|
||||
} SBoundColumn;
|
||||
|
||||
typedef struct {
|
||||
col_id_t schemaColIdx;
|
||||
col_id_t boundIdx;
|
||||
col_id_t finalIdx;
|
||||
} SBoundIdxInfo;
|
||||
|
||||
typedef struct SParsedDataColInfo {
|
||||
col_id_t numOfCols;
|
||||
col_id_t numOfBound;
|
||||
uint16_t flen; // TODO: get from STSchema
|
||||
uint16_t allNullLen; // TODO: get from STSchema(base on SDataRow)
|
||||
uint16_t extendedVarLen;
|
||||
uint16_t boundNullLen; // bound column len with all NULL value(without VarDataOffsetT/SColIdx part)
|
||||
col_id_t *boundColumns; // bound column idx according to schema
|
||||
SBoundColumn *cols;
|
||||
SBoundIdxInfo *colIdxInfo;
|
||||
int8_t orderStatus; // bound columns
|
||||
} SParsedDataColInfo;
|
||||
|
||||
typedef struct SInsertParseBaseContext {
|
||||
SParseContext *pComCxt;
|
||||
char *pSql;
|
||||
SMsgBuf msg;
|
||||
} SInsertParseBaseContext;
|
||||
|
||||
typedef struct SInsertParseContext {
|
||||
SParseContext *pComCxt; // input
|
||||
char *pSql; // input
|
||||
SMsgBuf msg; // input
|
||||
STableMeta *pTableMeta; // each table
|
||||
SParsedDataColInfo tags; // each table
|
||||
SVCreateTbReq createTblReq; // each table
|
||||
SHashObj *pVgroupsHashObj; // global
|
||||
SHashObj *pTableBlockHashObj; // global
|
||||
SHashObj *pSubTableHashObj; // global
|
||||
SArray *pVgDataBlocks; // global
|
||||
SHashObj *pTableNameHashObj; // global
|
||||
SHashObj *pDbFNameHashObj; // global
|
||||
int32_t totalNum;
|
||||
SVnodeModifOpStmt *pOutput;
|
||||
SStmtCallback *pStmtCb;
|
||||
SParseMetaCache *pMetaCache;
|
||||
char sTableName[TSDB_TABLE_NAME_LEN];
|
||||
char tmpTokenBuf[TSDB_MAX_BYTES_PER_ROW];
|
||||
int64_t memElapsed;
|
||||
int64_t parRowElapsed;
|
||||
} SInsertParseContext;
|
||||
|
||||
typedef struct SInsertParseSyntaxCxt {
|
||||
SParseContext *pComCxt;
|
||||
char *pSql;
|
||||
SMsgBuf msg;
|
||||
SParseMetaCache *pMetaCache;
|
||||
} SInsertParseSyntaxCxt;
|
||||
|
||||
typedef struct SMemParam {
|
||||
SRowBuilder *rb;
|
||||
SSchema *schema;
|
||||
int32_t toffset;
|
||||
col_id_t colIdx;
|
||||
} SMemParam;
|
||||
|
||||
typedef struct {
|
||||
uint8_t rowType; // default is 0, that is SDataRow
|
||||
int32_t rowSize;
|
||||
} SMemRowBuilder;
|
||||
|
||||
typedef struct STableDataBlocks {
|
||||
int8_t tsSource; // where does the UNIX timestamp come from, server or client
|
||||
bool ordered; // if current rows are ordered or not
|
||||
int32_t vgId; // virtual group id
|
||||
int64_t prevTS; // previous timestamp, recorded to decide if the records array is ts ascending
|
||||
int32_t numOfTables; // number of tables in current submit block
|
||||
int32_t rowSize; // row size for current table
|
||||
uint32_t nAllocSize;
|
||||
uint32_t headerSize; // header for table info (uid, tid, submit metadata)
|
||||
uint32_t size;
|
||||
STableMeta *pTableMeta; // the tableMeta of current table, the table meta will be used during submit, keep a ref to
|
||||
// avoid to be removed from cache
|
||||
char *pData;
|
||||
bool cloned;
|
||||
int32_t createTbReqLen;
|
||||
SParsedDataColInfo boundColumnInfo;
|
||||
SRowBuilder rowBuilder;
|
||||
} STableDataBlocks;
|
||||
|
||||
int32_t insGetExtendedRowSize(STableDataBlocks *pBlock);
|
||||
void insGetSTSRowAppendInfo(uint8_t rowType, SParsedDataColInfo *spd, col_id_t idx, int32_t *toffset, col_id_t *colIdx);
|
||||
int32_t insSetBlockInfo(SSubmitBlk *pBlocks, STableDataBlocks *dataBuf, int32_t numOfRows);
|
||||
int32_t insSchemaIdxCompar(const void *lhs, const void *rhs);
|
||||
int32_t insBoundIdxCompar(const void *lhs, const void *rhs);
|
||||
void insSetBoundColumnInfo(SParsedDataColInfo *pColList, SSchema *pSchema, col_id_t numOfCols);
|
||||
void insDestroyBlockArrayList(SArray *pDataBlockList);
|
||||
void insDestroyBlockHashmap(SHashObj *pDataBlockHash);
|
||||
int32_t insInitRowBuilder(SRowBuilder *pBuilder, int16_t schemaVer, SParsedDataColInfo *pColInfo);
|
||||
int32_t insGetDataBlockFromList(SHashObj *pHashList, void *id, int32_t idLen, int32_t size, int32_t startOffset,
|
||||
int32_t rowSize, STableMeta *pTableMeta, STableDataBlocks **dataBlocks,
|
||||
SArray *pBlockList, SVCreateTbReq *pCreateTbReq);
|
||||
int32_t insMergeTableDataBlocks(SHashObj *pHashObj, SArray **pVgDataBlocks);
|
||||
int32_t insBuildCreateTbMsg(STableDataBlocks *pBlocks, SVCreateTbReq *pCreateTbReq);
|
||||
int32_t insAllocateMemForSize(STableDataBlocks *pDataBlock, int32_t allSize);
|
||||
int32_t insCreateSName(SName *pName, struct SToken *pTableName, int32_t acctId, const char *dbName, SMsgBuf *pMsgBuf);
|
||||
int32_t insFindCol(struct SToken *pColname, int32_t start, int32_t end, SSchema *pSchema);
|
||||
void insBuildCreateTbReq(SVCreateTbReq *pTbReq, const char *tname, STag *pTag, int64_t suid, const char *sname,
|
||||
SArray *tagName, uint8_t tagNum);
|
||||
int32_t insMemRowAppend(SMsgBuf *pMsgBuf, const void *value, int32_t len, void *param);
|
||||
int32_t insCheckTimestamp(STableDataBlocks *pDataBlocks, const char *start);
|
||||
int32_t insBuildOutput(SInsertParseContext *pCxt);
|
||||
void insDestroyDataBlock(STableDataBlocks *pDataBlock);
|
||||
|
||||
#endif // TDENGINE_PAR_INSERT_UTIL_H
|
|
@ -410,8 +410,9 @@ cmd ::= SHOW QUERIES.
|
|||
cmd ::= SHOW SCORES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT); }
|
||||
cmd ::= SHOW TOPICS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TOPICS_STMT); }
|
||||
cmd ::= SHOW VARIABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLES_STMT); }
|
||||
cmd ::= SHOW CLUSTER VARIABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLES_STMT); }
|
||||
cmd ::= SHOW LOCAL VARIABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT); }
|
||||
cmd ::= SHOW DNODE NK_INTEGER(A) VARIABLES. { pCxt->pRootNode = createShowDnodeVariablesStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &A)); }
|
||||
cmd ::= SHOW DNODE NK_INTEGER(A) VARIABLES like_pattern_opt(B). { pCxt->pRootNode = createShowDnodeVariablesStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &A), B); }
|
||||
cmd ::= SHOW BNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_BNODES_STMT); }
|
||||
cmd ::= SHOW SNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT); }
|
||||
cmd ::= SHOW CLUSTER. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CLUSTER_STMT); }
|
||||
|
|
|
@ -1372,11 +1372,12 @@ SNode* createShowTableDistributedStmt(SAstCreateContext* pCxt, SNode* pRealTable
|
|||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createShowDnodeVariablesStmt(SAstCreateContext* pCxt, SNode* pDnodeId) {
|
||||
SNode* createShowDnodeVariablesStmt(SAstCreateContext* pCxt, SNode* pDnodeId, SNode* pLikePattern) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SShowDnodeVariablesStmt* pStmt = (SShowDnodeVariablesStmt*)nodesMakeNode(QUERY_NODE_SHOW_DNODE_VARIABLES_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->pDnodeId = pDnodeId;
|
||||
pStmt->pLikePattern = pLikePattern;
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
|
|
|
@ -484,11 +484,6 @@ static int32_t collectMetaKeyFromShowQueries(SCollectMetaKeyCxt* pCxt, SShowStmt
|
|||
pCxt->pMetaCache);
|
||||
}
|
||||
|
||||
static int32_t collectMetaKeyFromShowConfigs(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
|
||||
return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_CONFIGS,
|
||||
pCxt->pMetaCache);
|
||||
}
|
||||
|
||||
static int32_t collectMetaKeyFromShowVariables(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
|
||||
return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_CONFIGS,
|
||||
pCxt->pMetaCache);
|
||||
|
|
|
@ -125,7 +125,6 @@ static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt) {
|
|||
case QUERY_NODE_SHOW_CLUSTER_STMT:
|
||||
case QUERY_NODE_SHOW_LICENCES_STMT:
|
||||
case QUERY_NODE_SHOW_VGROUPS_STMT:
|
||||
case QUERY_NODE_SHOW_VARIABLES_STMT:
|
||||
case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
|
||||
case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:
|
||||
case QUERY_NODE_SHOW_VNODES_STMT:
|
||||
|
|
|
@ -0,0 +1,363 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "parInsertUtil.h"
|
||||
#include "parInt.h"
|
||||
#include "parToken.h"
|
||||
#include "ttime.h"
|
||||
|
||||
int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char* msgBuf,
|
||||
int32_t msgBufLen) {
|
||||
SMsgBuf msg = {.buf = msgBuf, .len = msgBufLen};
|
||||
SToken sToken;
|
||||
int32_t code = 0;
|
||||
char* tbName = NULL;
|
||||
|
||||
NEXT_TOKEN(pTableName, sToken);
|
||||
|
||||
if (sToken.n == 0) {
|
||||
return buildInvalidOperationMsg(&msg, "empty table name");
|
||||
}
|
||||
|
||||
code = insCreateSName(pName, &sToken, acctId, dbName, &msg);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
NEXT_TOKEN(pTableName, sToken);
|
||||
|
||||
if (sToken.n > 0) {
|
||||
return buildInvalidOperationMsg(&msg, "table name format is wrong");
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
typedef struct SmlExecTableHandle {
|
||||
SParsedDataColInfo tags; // each table
|
||||
SVCreateTbReq createTblReq; // each table
|
||||
} SmlExecTableHandle;
|
||||
|
||||
typedef struct SmlExecHandle {
|
||||
SHashObj* pBlockHash;
|
||||
SmlExecTableHandle tableExecHandle;
|
||||
SQuery* pQuery;
|
||||
} SSmlExecHandle;
|
||||
|
||||
static void smlDestroyTableHandle(void* pHandle) {
|
||||
SmlExecTableHandle* handle = (SmlExecTableHandle*)pHandle;
|
||||
destroyBoundColumnInfo(&handle->tags);
|
||||
tdDestroySVCreateTbReq(&handle->createTblReq);
|
||||
}
|
||||
|
||||
static int32_t smlBoundColumnData(SArray* cols, SParsedDataColInfo* pColList, SSchema* pSchema, bool isTag) {
|
||||
col_id_t nCols = pColList->numOfCols;
|
||||
|
||||
pColList->numOfBound = 0;
|
||||
pColList->boundNullLen = 0;
|
||||
memset(pColList->boundColumns, 0, sizeof(col_id_t) * nCols);
|
||||
for (col_id_t i = 0; i < nCols; ++i) {
|
||||
pColList->cols[i].valStat = VAL_STAT_NONE;
|
||||
}
|
||||
|
||||
bool isOrdered = true;
|
||||
col_id_t lastColIdx = -1; // last column found
|
||||
for (int i = 0; i < taosArrayGetSize(cols); ++i) {
|
||||
SSmlKv* kv = taosArrayGetP(cols, i);
|
||||
SToken sToken = {.n = kv->keyLen, .z = (char*)kv->key};
|
||||
col_id_t t = lastColIdx + 1;
|
||||
col_id_t index = ((t == 0 && !isTag) ? 0 : insFindCol(&sToken, t, nCols, pSchema));
|
||||
uDebug("SML, index:%d, t:%d, ncols:%d", index, t, nCols);
|
||||
if (index < 0 && t > 0) {
|
||||
index = insFindCol(&sToken, 0, t, pSchema);
|
||||
isOrdered = false;
|
||||
}
|
||||
if (index < 0) {
|
||||
uError("smlBoundColumnData. index:%d", index);
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
if (pColList->cols[index].valStat == VAL_STAT_HAS) {
|
||||
uError("smlBoundColumnData. already set. index:%d", index);
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
lastColIdx = index;
|
||||
pColList->cols[index].valStat = VAL_STAT_HAS;
|
||||
pColList->boundColumns[pColList->numOfBound] = index;
|
||||
++pColList->numOfBound;
|
||||
switch (pSchema[t].type) {
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
pColList->boundNullLen += (sizeof(VarDataOffsetT) + VARSTR_HEADER_SIZE + CHAR_BYTES);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
pColList->boundNullLen += (sizeof(VarDataOffsetT) + VARSTR_HEADER_SIZE + TSDB_NCHAR_SIZE);
|
||||
break;
|
||||
default:
|
||||
pColList->boundNullLen += TYPE_BYTES[pSchema[t].type];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pColList->orderStatus = isOrdered ? ORDER_STATUS_ORDERED : ORDER_STATUS_DISORDERED;
|
||||
|
||||
if (!isOrdered) {
|
||||
pColList->colIdxInfo = taosMemoryCalloc(pColList->numOfBound, sizeof(SBoundIdxInfo));
|
||||
if (NULL == pColList->colIdxInfo) {
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
SBoundIdxInfo* pColIdx = pColList->colIdxInfo;
|
||||
for (col_id_t i = 0; i < pColList->numOfBound; ++i) {
|
||||
pColIdx[i].schemaColIdx = pColList->boundColumns[i];
|
||||
pColIdx[i].boundIdx = i;
|
||||
}
|
||||
taosSort(pColIdx, pColList->numOfBound, sizeof(SBoundIdxInfo), insSchemaIdxCompar);
|
||||
for (col_id_t i = 0; i < pColList->numOfBound; ++i) {
|
||||
pColIdx[i].finalIdx = i;
|
||||
}
|
||||
taosSort(pColIdx, pColList->numOfBound, sizeof(SBoundIdxInfo), insBoundIdxCompar);
|
||||
}
|
||||
|
||||
if (pColList->numOfCols > pColList->numOfBound) {
|
||||
memset(&pColList->boundColumns[pColList->numOfBound], 0,
|
||||
sizeof(col_id_t) * (pColList->numOfCols - pColList->numOfBound));
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief No json tag for schemaless
|
||||
*
|
||||
* @param cols
|
||||
* @param tags
|
||||
* @param pSchema
|
||||
* @param ppTag
|
||||
* @param msg
|
||||
* @return int32_t
|
||||
*/
|
||||
static int32_t smlBuildTagRow(SArray* cols, SParsedDataColInfo* tags, SSchema* pSchema, STag** ppTag, SArray** tagName,
|
||||
SMsgBuf* msg) {
|
||||
SArray* pTagArray = taosArrayInit(tags->numOfBound, sizeof(STagVal));
|
||||
if (!pTagArray) {
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
*tagName = taosArrayInit(8, TSDB_COL_NAME_LEN);
|
||||
if (!*tagName) {
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
for (int i = 0; i < tags->numOfBound; ++i) {
|
||||
SSchema* pTagSchema = &pSchema[tags->boundColumns[i]];
|
||||
SSmlKv* kv = taosArrayGetP(cols, i);
|
||||
|
||||
taosArrayPush(*tagName, pTagSchema->name);
|
||||
STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
|
||||
// strcpy(val.colName, pTagSchema->name);
|
||||
if (pTagSchema->type == TSDB_DATA_TYPE_BINARY) {
|
||||
val.pData = (uint8_t*)kv->value;
|
||||
val.nData = kv->length;
|
||||
} else if (pTagSchema->type == TSDB_DATA_TYPE_NCHAR) {
|
||||
int32_t output = 0;
|
||||
void* p = taosMemoryCalloc(1, kv->length * TSDB_NCHAR_SIZE);
|
||||
if (p == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
if (!taosMbsToUcs4(kv->value, kv->length, (TdUcs4*)(p), kv->length * TSDB_NCHAR_SIZE, &output)) {
|
||||
if (errno == E2BIG) {
|
||||
taosMemoryFree(p);
|
||||
code = generateSyntaxErrMsg(msg, TSDB_CODE_PAR_VALUE_TOO_LONG, pTagSchema->name);
|
||||
goto end;
|
||||
}
|
||||
char buf[512] = {0};
|
||||
snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(errno));
|
||||
taosMemoryFree(p);
|
||||
code = buildSyntaxErrMsg(msg, buf, kv->value);
|
||||
goto end;
|
||||
}
|
||||
val.pData = p;
|
||||
val.nData = output;
|
||||
} else {
|
||||
memcpy(&val.i64, &(kv->value), kv->length);
|
||||
}
|
||||
taosArrayPush(pTagArray, &val);
|
||||
}
|
||||
|
||||
code = tTagNew(pTagArray, 1, false, ppTag);
|
||||
end:
|
||||
for (int i = 0; i < taosArrayGetSize(pTagArray); ++i) {
|
||||
STagVal* p = (STagVal*)taosArrayGet(pTagArray, i);
|
||||
if (p->type == TSDB_DATA_TYPE_NCHAR) {
|
||||
taosMemoryFree(p->pData);
|
||||
}
|
||||
}
|
||||
taosArrayDestroy(pTagArray);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t smlBindData(void* handle, SArray* tags, SArray* colsSchema, SArray* cols, bool format, STableMeta* pTableMeta,
|
||||
char* tableName, const char* sTableName, int32_t sTableNameLen, char* msgBuf, int16_t msgBufLen) {
|
||||
SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen};
|
||||
|
||||
SSmlExecHandle* smlHandle = (SSmlExecHandle*)handle;
|
||||
smlDestroyTableHandle(&smlHandle->tableExecHandle); // free for each table
|
||||
SSchema* pTagsSchema = getTableTagSchema(pTableMeta);
|
||||
insSetBoundColumnInfo(&smlHandle->tableExecHandle.tags, pTagsSchema, getNumOfTags(pTableMeta));
|
||||
int ret = smlBoundColumnData(tags, &smlHandle->tableExecHandle.tags, pTagsSchema, true);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
buildInvalidOperationMsg(&pBuf, "bound tags error");
|
||||
return ret;
|
||||
}
|
||||
STag* pTag = NULL;
|
||||
SArray* tagName = NULL;
|
||||
ret = smlBuildTagRow(tags, &smlHandle->tableExecHandle.tags, pTagsSchema, &pTag, &tagName, &pBuf);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
taosArrayDestroy(tagName);
|
||||
return ret;
|
||||
}
|
||||
|
||||
insBuildCreateTbReq(&smlHandle->tableExecHandle.createTblReq, tableName, pTag, pTableMeta->suid, NULL, tagName,
|
||||
pTableMeta->tableInfo.numOfTags);
|
||||
taosArrayDestroy(tagName);
|
||||
|
||||
smlHandle->tableExecHandle.createTblReq.ctb.stbName = taosMemoryMalloc(sTableNameLen + 1);
|
||||
memcpy(smlHandle->tableExecHandle.createTblReq.ctb.stbName, sTableName, sTableNameLen);
|
||||
smlHandle->tableExecHandle.createTblReq.ctb.stbName[sTableNameLen] = 0;
|
||||
|
||||
STableDataBlocks* pDataBlock = NULL;
|
||||
ret = insGetDataBlockFromList(smlHandle->pBlockHash, &pTableMeta->uid, sizeof(pTableMeta->uid),
|
||||
TSDB_DEFAULT_PAYLOAD_SIZE, sizeof(SSubmitBlk), getTableInfo(pTableMeta).rowSize,
|
||||
pTableMeta, &pDataBlock, NULL, &smlHandle->tableExecHandle.createTblReq);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
buildInvalidOperationMsg(&pBuf, "create data block error");
|
||||
return ret;
|
||||
}
|
||||
|
||||
SSchema* pSchema = getTableColumnSchema(pTableMeta);
|
||||
|
||||
ret = smlBoundColumnData(colsSchema, &pDataBlock->boundColumnInfo, pSchema, false);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
buildInvalidOperationMsg(&pBuf, "bound cols error");
|
||||
return ret;
|
||||
}
|
||||
int32_t extendedRowSize = insGetExtendedRowSize(pDataBlock);
|
||||
SParsedDataColInfo* spd = &pDataBlock->boundColumnInfo;
|
||||
SRowBuilder* pBuilder = &pDataBlock->rowBuilder;
|
||||
SMemParam param = {.rb = pBuilder};
|
||||
|
||||
insInitRowBuilder(&pDataBlock->rowBuilder, pDataBlock->pTableMeta->sversion, &pDataBlock->boundColumnInfo);
|
||||
|
||||
int32_t rowNum = taosArrayGetSize(cols);
|
||||
if (rowNum <= 0) {
|
||||
return buildInvalidOperationMsg(&pBuf, "cols size <= 0");
|
||||
}
|
||||
ret = insAllocateMemForSize(pDataBlock, extendedRowSize * rowNum);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
buildInvalidOperationMsg(&pBuf, "allocate memory error");
|
||||
return ret;
|
||||
}
|
||||
for (int32_t r = 0; r < rowNum; ++r) {
|
||||
STSRow* row = (STSRow*)(pDataBlock->pData + pDataBlock->size); // skip the SSubmitBlk header
|
||||
tdSRowResetBuf(pBuilder, row);
|
||||
void* rowData = taosArrayGetP(cols, r);
|
||||
size_t rowDataSize = 0;
|
||||
if (format) {
|
||||
rowDataSize = taosArrayGetSize(rowData);
|
||||
}
|
||||
|
||||
// 1. set the parsed value from sql string
|
||||
for (int c = 0, j = 0; c < spd->numOfBound; ++c) {
|
||||
SSchema* pColSchema = &pSchema[spd->boundColumns[c]];
|
||||
|
||||
param.schema = pColSchema;
|
||||
insGetSTSRowAppendInfo(pBuilder->rowType, spd, c, ¶m.toffset, ¶m.colIdx);
|
||||
|
||||
SSmlKv* kv = NULL;
|
||||
if (format) {
|
||||
if (j < rowDataSize) {
|
||||
kv = taosArrayGetP(rowData, j);
|
||||
if (rowDataSize != spd->numOfBound && j != 0 &&
|
||||
(kv->keyLen != strlen(pColSchema->name) || strncmp(kv->key, pColSchema->name, kv->keyLen) != 0)) {
|
||||
kv = NULL;
|
||||
} else {
|
||||
j++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
void** p = taosHashGet(rowData, pColSchema->name, strlen(pColSchema->name));
|
||||
if (p) kv = *p;
|
||||
}
|
||||
|
||||
if (kv) {
|
||||
int32_t colLen = kv->length;
|
||||
if (pColSchema->type == TSDB_DATA_TYPE_TIMESTAMP) {
|
||||
// uError("SML:data before:%" PRId64 ", precision:%d", kv->i, pTableMeta->tableInfo.precision);
|
||||
kv->i = convertTimePrecision(kv->i, TSDB_TIME_PRECISION_NANO, pTableMeta->tableInfo.precision);
|
||||
// uError("SML:data after:%" PRId64 ", precision:%d", kv->i, pTableMeta->tableInfo.precision);
|
||||
}
|
||||
|
||||
if (IS_VAR_DATA_TYPE(kv->type)) {
|
||||
insMemRowAppend(&pBuf, kv->value, colLen, ¶m);
|
||||
} else {
|
||||
insMemRowAppend(&pBuf, &(kv->value), colLen, ¶m);
|
||||
}
|
||||
} else {
|
||||
pBuilder->hasNone = true;
|
||||
}
|
||||
|
||||
if (PRIMARYKEY_TIMESTAMP_COL_ID == pColSchema->colId) {
|
||||
TSKEY tsKey = TD_ROW_KEY(row);
|
||||
insCheckTimestamp(pDataBlock, (const char*)&tsKey);
|
||||
}
|
||||
}
|
||||
|
||||
// set the null value for the columns that do not assign values
|
||||
if ((spd->numOfBound < spd->numOfCols) && TD_IS_TP_ROW(row)) {
|
||||
pBuilder->hasNone = true;
|
||||
}
|
||||
|
||||
tdSRowEnd(pBuilder);
|
||||
pDataBlock->size += extendedRowSize;
|
||||
}
|
||||
|
||||
SSubmitBlk* pBlocks = (SSubmitBlk*)(pDataBlock->pData);
|
||||
if (TSDB_CODE_SUCCESS != insSetBlockInfo(pBlocks, pDataBlock, rowNum)) {
|
||||
return buildInvalidOperationMsg(&pBuf, "too many rows in sql, total number of rows should be less than INT32_MAX");
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void* smlInitHandle(SQuery* pQuery) {
|
||||
SSmlExecHandle* handle = taosMemoryCalloc(1, sizeof(SSmlExecHandle));
|
||||
if (!handle) return NULL;
|
||||
handle->pBlockHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false);
|
||||
handle->pQuery = pQuery;
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
void smlDestroyHandle(void* pHandle) {
|
||||
if (!pHandle) return;
|
||||
SSmlExecHandle* handle = (SSmlExecHandle*)pHandle;
|
||||
insDestroyBlockHashmap(handle->pBlockHash);
|
||||
smlDestroyTableHandle(&handle->tableExecHandle);
|
||||
taosMemoryFree(handle);
|
||||
}
|
||||
|
||||
int32_t smlBuildOutput(void* handle, SHashObj* pVgHash) {
|
||||
SSmlExecHandle* smlHandle = (SSmlExecHandle*)handle;
|
||||
return qBuildStmtOutput(smlHandle->pQuery, pVgHash, smlHandle->pBlockHash);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,485 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "os.h"
|
||||
#include "parInsertUtil.h"
|
||||
#include "parInt.h"
|
||||
#include "parToken.h"
|
||||
#include "query.h"
|
||||
#include "tglobal.h"
|
||||
#include "ttime.h"
|
||||
#include "ttypes.h"
|
||||
|
||||
typedef struct SKvParam {
|
||||
int16_t pos;
|
||||
SArray* pTagVals;
|
||||
SSchema* schema;
|
||||
char buf[TSDB_MAX_TAGS_LEN];
|
||||
} SKvParam;
|
||||
|
||||
int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash) {
|
||||
SVnodeModifOpStmt* modifyNode = (SVnodeModifOpStmt*)pQuery->pRoot;
|
||||
int32_t code = 0;
|
||||
SInsertParseContext insertCtx = {
|
||||
.pVgroupsHashObj = pVgHash,
|
||||
.pTableBlockHashObj = pBlockHash,
|
||||
.pOutput = (SVnodeModifOpStmt*)pQuery->pRoot,
|
||||
};
|
||||
|
||||
// merge according to vgId
|
||||
if (taosHashGetSize(insertCtx.pTableBlockHashObj) > 0) {
|
||||
CHECK_CODE(insMergeTableDataBlocks(insertCtx.pTableBlockHashObj, &insertCtx.pVgDataBlocks));
|
||||
}
|
||||
|
||||
CHECK_CODE(insBuildOutput(&insertCtx));
|
||||
|
||||
insDestroyBlockArrayList(insertCtx.pVgDataBlocks);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const char* sTableName, char* tName,
|
||||
TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen) {
|
||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
||||
SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen};
|
||||
SParsedDataColInfo* tags = (SParsedDataColInfo*)boundTags;
|
||||
if (NULL == tags) {
|
||||
return TSDB_CODE_QRY_APP_ERROR;
|
||||
}
|
||||
|
||||
SArray* pTagArray = taosArrayInit(tags->numOfBound, sizeof(STagVal));
|
||||
if (!pTagArray) {
|
||||
return buildInvalidOperationMsg(&pBuf, "out of memory");
|
||||
}
|
||||
|
||||
SArray* tagName = taosArrayInit(8, TSDB_COL_NAME_LEN);
|
||||
if (!tagName) {
|
||||
return buildInvalidOperationMsg(&pBuf, "out of memory");
|
||||
}
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SSchema* pSchema = getTableTagSchema(pDataBlock->pTableMeta);
|
||||
|
||||
bool isJson = false;
|
||||
STag* pTag = NULL;
|
||||
|
||||
for (int c = 0; c < tags->numOfBound; ++c) {
|
||||
if (bind[c].is_null && bind[c].is_null[0]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SSchema* pTagSchema = &pSchema[tags->boundColumns[c]];
|
||||
int32_t colLen = pTagSchema->bytes;
|
||||
if (IS_VAR_DATA_TYPE(pTagSchema->type)) {
|
||||
colLen = bind[c].length[0];
|
||||
}
|
||||
taosArrayPush(tagName, pTagSchema->name);
|
||||
if (pTagSchema->type == TSDB_DATA_TYPE_JSON) {
|
||||
if (colLen > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
|
||||
code = buildSyntaxErrMsg(&pBuf, "json string too long than 4095", bind[c].buffer);
|
||||
goto end;
|
||||
}
|
||||
|
||||
isJson = true;
|
||||
char* tmp = taosMemoryCalloc(1, colLen + 1);
|
||||
memcpy(tmp, bind[c].buffer, colLen);
|
||||
code = parseJsontoTagData(tmp, pTagArray, &pTag, &pBuf);
|
||||
taosMemoryFree(tmp);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
|
||||
// strcpy(val.colName, pTagSchema->name);
|
||||
if (pTagSchema->type == TSDB_DATA_TYPE_BINARY) {
|
||||
val.pData = (uint8_t*)bind[c].buffer;
|
||||
val.nData = colLen;
|
||||
} else if (pTagSchema->type == TSDB_DATA_TYPE_NCHAR) {
|
||||
int32_t output = 0;
|
||||
void* p = taosMemoryCalloc(1, colLen * TSDB_NCHAR_SIZE);
|
||||
if (p == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
if (!taosMbsToUcs4(bind[c].buffer, colLen, (TdUcs4*)(p), colLen * TSDB_NCHAR_SIZE, &output)) {
|
||||
if (errno == E2BIG) {
|
||||
taosMemoryFree(p);
|
||||
code = generateSyntaxErrMsg(&pBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pTagSchema->name);
|
||||
goto end;
|
||||
}
|
||||
char buf[512] = {0};
|
||||
snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(errno));
|
||||
taosMemoryFree(p);
|
||||
code = buildSyntaxErrMsg(&pBuf, buf, bind[c].buffer);
|
||||
goto end;
|
||||
}
|
||||
val.pData = p;
|
||||
val.nData = output;
|
||||
} else {
|
||||
memcpy(&val.i64, bind[c].buffer, colLen);
|
||||
}
|
||||
taosArrayPush(pTagArray, &val);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isJson && (code = tTagNew(pTagArray, 1, false, &pTag)) != TSDB_CODE_SUCCESS) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
SVCreateTbReq tbReq = {0};
|
||||
insBuildCreateTbReq(&tbReq, tName, pTag, suid, sTableName, tagName, pDataBlock->pTableMeta->tableInfo.numOfTags);
|
||||
code = insBuildCreateTbMsg(pDataBlock, &tbReq);
|
||||
tdDestroySVCreateTbReq(&tbReq);
|
||||
|
||||
end:
|
||||
for (int i = 0; i < taosArrayGetSize(pTagArray); ++i) {
|
||||
STagVal* p = (STagVal*)taosArrayGet(pTagArray, i);
|
||||
if (p->type == TSDB_DATA_TYPE_NCHAR) {
|
||||
taosMemoryFreeClear(p->pData);
|
||||
}
|
||||
}
|
||||
taosArrayDestroy(pTagArray);
|
||||
taosArrayDestroy(tagName);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t qBindStmtColsValue(void* pBlock, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen) {
|
||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
||||
SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta);
|
||||
int32_t extendedRowSize = insGetExtendedRowSize(pDataBlock);
|
||||
SParsedDataColInfo* spd = &pDataBlock->boundColumnInfo;
|
||||
SRowBuilder* pBuilder = &pDataBlock->rowBuilder;
|
||||
SMemParam param = {.rb = pBuilder};
|
||||
SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen};
|
||||
int32_t rowNum = bind->num;
|
||||
|
||||
CHECK_CODE(
|
||||
insInitRowBuilder(&pDataBlock->rowBuilder, pDataBlock->pTableMeta->sversion, &pDataBlock->boundColumnInfo));
|
||||
|
||||
CHECK_CODE(insAllocateMemForSize(pDataBlock, extendedRowSize * bind->num));
|
||||
|
||||
for (int32_t r = 0; r < bind->num; ++r) {
|
||||
STSRow* row = (STSRow*)(pDataBlock->pData + pDataBlock->size); // skip the SSubmitBlk header
|
||||
tdSRowResetBuf(pBuilder, row);
|
||||
|
||||
for (int c = 0; c < spd->numOfBound; ++c) {
|
||||
SSchema* pColSchema = &pSchema[spd->boundColumns[c]];
|
||||
|
||||
if (bind[c].num != rowNum) {
|
||||
return buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same");
|
||||
}
|
||||
|
||||
param.schema = pColSchema;
|
||||
insGetSTSRowAppendInfo(pBuilder->rowType, spd, c, ¶m.toffset, ¶m.colIdx);
|
||||
|
||||
if (bind[c].is_null && bind[c].is_null[r]) {
|
||||
if (pColSchema->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
return buildInvalidOperationMsg(&pBuf, "primary timestamp should not be NULL");
|
||||
}
|
||||
|
||||
CHECK_CODE(insMemRowAppend(&pBuf, NULL, 0, ¶m));
|
||||
} else {
|
||||
if (bind[c].buffer_type != pColSchema->type) {
|
||||
return buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type");
|
||||
}
|
||||
|
||||
int32_t colLen = pColSchema->bytes;
|
||||
if (IS_VAR_DATA_TYPE(pColSchema->type)) {
|
||||
colLen = bind[c].length[r];
|
||||
}
|
||||
|
||||
CHECK_CODE(insMemRowAppend(&pBuf, (char*)bind[c].buffer + bind[c].buffer_length * r, colLen, ¶m));
|
||||
}
|
||||
|
||||
if (PRIMARYKEY_TIMESTAMP_COL_ID == pColSchema->colId) {
|
||||
TSKEY tsKey = TD_ROW_KEY(row);
|
||||
insCheckTimestamp(pDataBlock, (const char*)&tsKey);
|
||||
}
|
||||
}
|
||||
// set the null value for the columns that do not assign values
|
||||
if ((spd->numOfBound < spd->numOfCols) && TD_IS_TP_ROW(row)) {
|
||||
pBuilder->hasNone = true;
|
||||
}
|
||||
tdSRowEnd(pBuilder);
|
||||
#ifdef TD_DEBUG_PRINT_ROW
|
||||
STSchema* pSTSchema = tdGetSTSChemaFromSSChema(pSchema, spd->numOfCols, 1);
|
||||
tdSRowPrint(row, pSTSchema, __func__);
|
||||
taosMemoryFree(pSTSchema);
|
||||
#endif
|
||||
pDataBlock->size += extendedRowSize;
|
||||
}
|
||||
|
||||
SSubmitBlk* pBlocks = (SSubmitBlk*)(pDataBlock->pData);
|
||||
if (TSDB_CODE_SUCCESS != insSetBlockInfo(pBlocks, pDataBlock, bind->num)) {
|
||||
return buildInvalidOperationMsg(&pBuf, "too many rows in sql, total number of rows should be less than INT32_MAX");
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qBindStmtSingleColValue(void* pBlock, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen, int32_t colIdx,
|
||||
int32_t rowNum) {
|
||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
||||
SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta);
|
||||
int32_t extendedRowSize = insGetExtendedRowSize(pDataBlock);
|
||||
SParsedDataColInfo* spd = &pDataBlock->boundColumnInfo;
|
||||
SRowBuilder* pBuilder = &pDataBlock->rowBuilder;
|
||||
SMemParam param = {.rb = pBuilder};
|
||||
SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen};
|
||||
bool rowStart = (0 == colIdx);
|
||||
bool rowEnd = ((colIdx + 1) == spd->numOfBound);
|
||||
|
||||
if (rowStart) {
|
||||
CHECK_CODE(
|
||||
insInitRowBuilder(&pDataBlock->rowBuilder, pDataBlock->pTableMeta->sversion, &pDataBlock->boundColumnInfo));
|
||||
CHECK_CODE(insAllocateMemForSize(pDataBlock, extendedRowSize * bind->num));
|
||||
}
|
||||
|
||||
for (int32_t r = 0; r < bind->num; ++r) {
|
||||
STSRow* row = (STSRow*)(pDataBlock->pData + pDataBlock->size + extendedRowSize * r); // skip the SSubmitBlk header
|
||||
if (rowStart) {
|
||||
tdSRowResetBuf(pBuilder, row);
|
||||
} else {
|
||||
tdSRowGetBuf(pBuilder, row);
|
||||
}
|
||||
|
||||
SSchema* pColSchema = &pSchema[spd->boundColumns[colIdx]];
|
||||
|
||||
if (bind->num != rowNum) {
|
||||
return buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same");
|
||||
}
|
||||
|
||||
param.schema = pColSchema;
|
||||
insGetSTSRowAppendInfo(pBuilder->rowType, spd, colIdx, ¶m.toffset, ¶m.colIdx);
|
||||
|
||||
if (bind->is_null && bind->is_null[r]) {
|
||||
if (pColSchema->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
return buildInvalidOperationMsg(&pBuf, "primary timestamp should not be NULL");
|
||||
}
|
||||
|
||||
CHECK_CODE(insMemRowAppend(&pBuf, NULL, 0, ¶m));
|
||||
} else {
|
||||
if (bind->buffer_type != pColSchema->type) {
|
||||
return buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type");
|
||||
}
|
||||
|
||||
int32_t colLen = pColSchema->bytes;
|
||||
if (IS_VAR_DATA_TYPE(pColSchema->type)) {
|
||||
colLen = bind->length[r];
|
||||
}
|
||||
|
||||
CHECK_CODE(insMemRowAppend(&pBuf, (char*)bind->buffer + bind->buffer_length * r, colLen, ¶m));
|
||||
}
|
||||
|
||||
if (PRIMARYKEY_TIMESTAMP_COL_ID == pColSchema->colId) {
|
||||
TSKEY tsKey = TD_ROW_KEY(row);
|
||||
insCheckTimestamp(pDataBlock, (const char*)&tsKey);
|
||||
}
|
||||
|
||||
// set the null value for the columns that do not assign values
|
||||
if (rowEnd && (spd->numOfBound < spd->numOfCols) && TD_IS_TP_ROW(row)) {
|
||||
pBuilder->hasNone = true;
|
||||
}
|
||||
if (rowEnd) {
|
||||
tdSRowEnd(pBuilder);
|
||||
}
|
||||
#ifdef TD_DEBUG_PRINT_ROW
|
||||
if (rowEnd) {
|
||||
STSchema* pSTSchema = tdGetSTSChemaFromSSChema(pSchema, spd->numOfCols, 1);
|
||||
tdSRowPrint(row, pSTSchema, __func__);
|
||||
taosMemoryFree(pSTSchema);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (rowEnd) {
|
||||
pDataBlock->size += extendedRowSize * bind->num;
|
||||
|
||||
SSubmitBlk* pBlocks = (SSubmitBlk*)(pDataBlock->pData);
|
||||
if (TSDB_CODE_SUCCESS != insSetBlockInfo(pBlocks, pDataBlock, bind->num)) {
|
||||
return buildInvalidOperationMsg(&pBuf,
|
||||
"too many rows in sql, total number of rows should be less than INT32_MAX");
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t buildBoundFields(SParsedDataColInfo* boundInfo, SSchema* pSchema, int32_t* fieldNum, TAOS_FIELD_E** fields,
|
||||
uint8_t timePrec) {
|
||||
if (fields) {
|
||||
*fields = taosMemoryCalloc(boundInfo->numOfBound, sizeof(TAOS_FIELD));
|
||||
if (NULL == *fields) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SSchema* schema = &pSchema[boundInfo->boundColumns[0]];
|
||||
if (TSDB_DATA_TYPE_TIMESTAMP == schema->type) {
|
||||
(*fields)[0].precision = timePrec;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < boundInfo->numOfBound; ++i) {
|
||||
schema = &pSchema[boundInfo->boundColumns[i]];
|
||||
strcpy((*fields)[i].name, schema->name);
|
||||
(*fields)[i].type = schema->type;
|
||||
(*fields)[i].bytes = schema->bytes;
|
||||
}
|
||||
}
|
||||
|
||||
*fieldNum = boundInfo->numOfBound;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TAOS_FIELD_E** fields) {
|
||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
||||
SParsedDataColInfo* tags = (SParsedDataColInfo*)boundTags;
|
||||
if (NULL == tags) {
|
||||
return TSDB_CODE_QRY_APP_ERROR;
|
||||
}
|
||||
|
||||
if (pDataBlock->pTableMeta->tableType != TSDB_SUPER_TABLE && pDataBlock->pTableMeta->tableType != TSDB_CHILD_TABLE) {
|
||||
return TSDB_CODE_TSC_STMT_API_ERROR;
|
||||
}
|
||||
|
||||
SSchema* pSchema = getTableTagSchema(pDataBlock->pTableMeta);
|
||||
if (tags->numOfBound <= 0) {
|
||||
*fieldNum = 0;
|
||||
*fields = NULL;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
CHECK_CODE(buildBoundFields(tags, pSchema, fieldNum, fields, 0));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qBuildStmtColFields(void* pBlock, int32_t* fieldNum, TAOS_FIELD_E** fields) {
|
||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
||||
SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta);
|
||||
if (pDataBlock->boundColumnInfo.numOfBound <= 0) {
|
||||
*fieldNum = 0;
|
||||
if (fields) {
|
||||
*fields = NULL;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
CHECK_CODE(buildBoundFields(&pDataBlock->boundColumnInfo, pSchema, fieldNum, fields,
|
||||
pDataBlock->pTableMeta->tableInfo.precision));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qResetStmtDataBlock(void* block, bool keepBuf) {
|
||||
STableDataBlocks* pBlock = (STableDataBlocks*)block;
|
||||
|
||||
if (keepBuf) {
|
||||
taosMemoryFreeClear(pBlock->pData);
|
||||
pBlock->pData = taosMemoryMalloc(TSDB_PAYLOAD_SIZE);
|
||||
if (NULL == pBlock->pData) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
memset(pBlock->pData, 0, sizeof(SSubmitBlk));
|
||||
} else {
|
||||
pBlock->pData = NULL;
|
||||
}
|
||||
|
||||
pBlock->ordered = true;
|
||||
pBlock->prevTS = INT64_MIN;
|
||||
pBlock->size = sizeof(SSubmitBlk);
|
||||
pBlock->tsSource = -1;
|
||||
pBlock->numOfTables = 1;
|
||||
pBlock->nAllocSize = TSDB_PAYLOAD_SIZE;
|
||||
pBlock->headerSize = pBlock->size;
|
||||
pBlock->createTbReqLen = 0;
|
||||
|
||||
memset(&pBlock->rowBuilder, 0, sizeof(pBlock->rowBuilder));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qCloneStmtDataBlock(void** pDst, void* pSrc) {
|
||||
*pDst = taosMemoryMalloc(sizeof(STableDataBlocks));
|
||||
if (NULL == *pDst) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
memcpy(*pDst, pSrc, sizeof(STableDataBlocks));
|
||||
((STableDataBlocks*)(*pDst))->cloned = true;
|
||||
|
||||
STableDataBlocks* pBlock = (STableDataBlocks*)(*pDst);
|
||||
if (pBlock->pTableMeta) {
|
||||
void* pNewMeta = taosMemoryMalloc(TABLE_META_SIZE(pBlock->pTableMeta));
|
||||
if (NULL == pNewMeta) {
|
||||
taosMemoryFreeClear(*pDst);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
memcpy(pNewMeta, pBlock->pTableMeta, TABLE_META_SIZE(pBlock->pTableMeta));
|
||||
pBlock->pTableMeta = pNewMeta;
|
||||
}
|
||||
|
||||
return qResetStmtDataBlock(*pDst, false);
|
||||
}
|
||||
|
||||
int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc, uint64_t uid, int32_t vgId) {
|
||||
int32_t code = qCloneStmtDataBlock(pDst, pSrc);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
STableDataBlocks* pBlock = (STableDataBlocks*)*pDst;
|
||||
pBlock->pData = taosMemoryMalloc(pBlock->nAllocSize);
|
||||
if (NULL == pBlock->pData) {
|
||||
qFreeStmtDataBlock(pBlock);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pBlock->vgId = vgId;
|
||||
|
||||
if (pBlock->pTableMeta) {
|
||||
pBlock->pTableMeta->uid = uid;
|
||||
pBlock->pTableMeta->vgId = vgId;
|
||||
}
|
||||
|
||||
memset(pBlock->pData, 0, sizeof(SSubmitBlk));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
STableMeta* qGetTableMetaInDataBlock(void* pDataBlock) { return ((STableDataBlocks*)pDataBlock)->pTableMeta; }
|
||||
|
||||
void qFreeStmtDataBlock(void* pDataBlock) {
|
||||
if (pDataBlock == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(((STableDataBlocks*)pDataBlock)->pTableMeta);
|
||||
taosMemoryFreeClear(((STableDataBlocks*)pDataBlock)->pData);
|
||||
taosMemoryFreeClear(pDataBlock);
|
||||
}
|
||||
|
||||
void qDestroyStmtDataBlock(void* pBlock) {
|
||||
if (pBlock == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
||||
|
||||
pDataBlock->cloned = false;
|
||||
insDestroyDataBlock(pDataBlock);
|
||||
}
|
|
@ -13,7 +13,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "parInsertData.h"
|
||||
#include "parInsertUtil.h"
|
||||
|
||||
#include "catalog.h"
|
||||
#include "parInt.h"
|
||||
|
@ -21,9 +21,6 @@
|
|||
#include "querynodes.h"
|
||||
#include "tRealloc.h"
|
||||
|
||||
#define IS_RAW_PAYLOAD(t) \
|
||||
(((int)(t)) == PAYLOAD_TYPE_RAW) // 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert
|
||||
|
||||
typedef struct SBlockKeyTuple {
|
||||
TSKEY skey;
|
||||
void* payloadAddr;
|
||||
|
@ -81,7 +78,53 @@ static int32_t rowDataComparStable(const void* lhs, const void* rhs) {
|
|||
}
|
||||
}
|
||||
|
||||
void setBoundColumnInfo(SParsedDataColInfo* pColList, SSchema* pSchema, col_id_t numOfCols) {
|
||||
int32_t insGetExtendedRowSize(STableDataBlocks* pBlock) {
|
||||
STableComInfo* pTableInfo = &pBlock->pTableMeta->tableInfo;
|
||||
ASSERT(pBlock->rowSize == pTableInfo->rowSize);
|
||||
return pBlock->rowSize + TD_ROW_HEAD_LEN - sizeof(TSKEY) + pBlock->boundColumnInfo.extendedVarLen +
|
||||
(int32_t)TD_BITMAP_BYTES(pTableInfo->numOfColumns - 1);
|
||||
}
|
||||
|
||||
void insGetSTSRowAppendInfo(uint8_t rowType, SParsedDataColInfo* spd, col_id_t idx, int32_t* toffset,
|
||||
col_id_t* colIdx) {
|
||||
col_id_t schemaIdx = 0;
|
||||
if (IS_DATA_COL_ORDERED(spd)) {
|
||||
schemaIdx = spd->boundColumns[idx];
|
||||
if (TD_IS_TP_ROW_T(rowType)) {
|
||||
*toffset = (spd->cols + schemaIdx)->toffset; // the offset of firstPart
|
||||
*colIdx = schemaIdx;
|
||||
} else {
|
||||
*toffset = idx * sizeof(SKvRowIdx); // the offset of SKvRowIdx
|
||||
*colIdx = idx;
|
||||
}
|
||||
} else {
|
||||
ASSERT(idx == (spd->colIdxInfo + idx)->boundIdx);
|
||||
schemaIdx = (spd->colIdxInfo + idx)->schemaColIdx;
|
||||
if (TD_IS_TP_ROW_T(rowType)) {
|
||||
*toffset = (spd->cols + schemaIdx)->toffset;
|
||||
*colIdx = schemaIdx;
|
||||
} else {
|
||||
*toffset = ((spd->colIdxInfo + idx)->finalIdx) * sizeof(SKvRowIdx);
|
||||
*colIdx = (spd->colIdxInfo + idx)->finalIdx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t insSetBlockInfo(SSubmitBlk* pBlocks, STableDataBlocks* dataBuf, int32_t numOfRows) {
|
||||
pBlocks->suid = (TSDB_NORMAL_TABLE == dataBuf->pTableMeta->tableType ? 0 : dataBuf->pTableMeta->suid);
|
||||
pBlocks->uid = dataBuf->pTableMeta->uid;
|
||||
pBlocks->sversion = dataBuf->pTableMeta->sversion;
|
||||
pBlocks->schemaLen = dataBuf->createTbReqLen;
|
||||
|
||||
if (pBlocks->numOfRows + numOfRows >= INT32_MAX) {
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
} else {
|
||||
pBlocks->numOfRows += numOfRows;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
void insSetBoundColumnInfo(SParsedDataColInfo* pColList, SSchema* pSchema, col_id_t numOfCols) {
|
||||
pColList->numOfCols = numOfCols;
|
||||
pColList->numOfBound = numOfCols;
|
||||
pColList->orderStatus = ORDER_STATUS_ORDERED; // default is ORDERED for non-bound mode
|
||||
|
@ -118,7 +161,7 @@ void setBoundColumnInfo(SParsedDataColInfo* pColList, SSchema* pSchema, col_id_t
|
|||
pColList->extendedVarLen = (uint16_t)(nVar * sizeof(VarDataOffsetT));
|
||||
}
|
||||
|
||||
int32_t schemaIdxCompar(const void* lhs, const void* rhs) {
|
||||
int32_t insSchemaIdxCompar(const void* lhs, const void* rhs) {
|
||||
uint16_t left = *(uint16_t*)lhs;
|
||||
uint16_t right = *(uint16_t*)rhs;
|
||||
|
||||
|
@ -129,7 +172,7 @@ int32_t schemaIdxCompar(const void* lhs, const void* rhs) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t boundIdxCompar(const void* lhs, const void* rhs) {
|
||||
int32_t insBoundIdxCompar(const void* lhs, const void* rhs) {
|
||||
uint16_t left = *(uint16_t*)POINTER_SHIFT(lhs, sizeof(uint16_t));
|
||||
uint16_t right = *(uint16_t*)POINTER_SHIFT(rhs, sizeof(uint16_t));
|
||||
|
||||
|
@ -178,7 +221,7 @@ static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t star
|
|||
|
||||
SParsedDataColInfo* pColInfo = &dataBuf->boundColumnInfo;
|
||||
SSchema* pSchema = getTableColumnSchema(dataBuf->pTableMeta);
|
||||
setBoundColumnInfo(pColInfo, pSchema, dataBuf->pTableMeta->tableInfo.numOfColumns);
|
||||
insSetBoundColumnInfo(pColInfo, pSchema, dataBuf->pTableMeta->tableInfo.numOfColumns);
|
||||
|
||||
dataBuf->ordered = true;
|
||||
dataBuf->prevTS = INT64_MIN;
|
||||
|
@ -192,7 +235,7 @@ static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t star
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t buildCreateTbMsg(STableDataBlocks* pBlocks, SVCreateTbReq* pCreateTbReq) {
|
||||
int32_t insBuildCreateTbMsg(STableDataBlocks* pBlocks, SVCreateTbReq* pCreateTbReq) {
|
||||
SEncoder coder = {0};
|
||||
char* pBuf;
|
||||
int32_t len;
|
||||
|
@ -222,7 +265,7 @@ int32_t buildCreateTbMsg(STableDataBlocks* pBlocks, SVCreateTbReq* pCreateTbReq)
|
|||
return code;
|
||||
}
|
||||
|
||||
static void destroyDataBlock(STableDataBlocks* pDataBlock) {
|
||||
void insDestroyDataBlock(STableDataBlocks* pDataBlock) {
|
||||
if (pDataBlock == NULL) {
|
||||
return;
|
||||
}
|
||||
|
@ -237,9 +280,9 @@ static void destroyDataBlock(STableDataBlocks* pDataBlock) {
|
|||
taosMemoryFreeClear(pDataBlock);
|
||||
}
|
||||
|
||||
int32_t getDataBlockFromList(SHashObj* pHashList, void* id, int32_t idLen, int32_t size, int32_t startOffset,
|
||||
int32_t rowSize, STableMeta* pTableMeta, STableDataBlocks** dataBlocks, SArray* pBlockList,
|
||||
SVCreateTbReq* pCreateTbReq) {
|
||||
int32_t insGetDataBlockFromList(SHashObj* pHashList, void* id, int32_t idLen, int32_t size, int32_t startOffset,
|
||||
int32_t rowSize, STableMeta* pTableMeta, STableDataBlocks** dataBlocks,
|
||||
SArray* pBlockList, SVCreateTbReq* pCreateTbReq) {
|
||||
*dataBlocks = NULL;
|
||||
STableDataBlocks** t1 = (STableDataBlocks**)taosHashGet(pHashList, (const char*)id, idLen);
|
||||
if (t1 != NULL) {
|
||||
|
@ -253,9 +296,9 @@ int32_t getDataBlockFromList(SHashObj* pHashList, void* id, int32_t idLen, int32
|
|||
}
|
||||
|
||||
if (NULL != pCreateTbReq && NULL != pCreateTbReq->ctb.pTag) {
|
||||
ret = buildCreateTbMsg(*dataBlocks, pCreateTbReq);
|
||||
ret = insBuildCreateTbMsg(*dataBlocks, pCreateTbReq);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
destroyDataBlock(*dataBlocks);
|
||||
insDestroyDataBlock(*dataBlocks);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -269,7 +312,7 @@ int32_t getDataBlockFromList(SHashObj* pHashList, void* id, int32_t idLen, int32
|
|||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int32_t getRowExpandSize(STableMeta* pTableMeta) {
|
||||
int32_t result = TD_ROW_HEAD_LEN - sizeof(TSKEY);
|
||||
int32_t columns = getNumOfColumns(pTableMeta);
|
||||
|
@ -282,8 +325,9 @@ static int32_t getRowExpandSize(STableMeta* pTableMeta) {
|
|||
result += (int32_t)TD_BITMAP_BYTES(columns - 1);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
void destroyBlockArrayList(SArray* pDataBlockList) {
|
||||
void insDestroyBlockArrayList(SArray* pDataBlockList) {
|
||||
if (pDataBlockList == NULL) {
|
||||
return;
|
||||
}
|
||||
|
@ -291,13 +335,13 @@ void destroyBlockArrayList(SArray* pDataBlockList) {
|
|||
size_t size = taosArrayGetSize(pDataBlockList);
|
||||
for (int32_t i = 0; i < size; i++) {
|
||||
void* p = taosArrayGetP(pDataBlockList, i);
|
||||
destroyDataBlock(p);
|
||||
insDestroyDataBlock(p);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pDataBlockList);
|
||||
}
|
||||
|
||||
void destroyBlockHashmap(SHashObj* pDataBlockHash) {
|
||||
void insDestroyBlockHashmap(SHashObj* pDataBlockHash) {
|
||||
if (pDataBlockHash == NULL) {
|
||||
return;
|
||||
}
|
||||
|
@ -305,7 +349,7 @@ void destroyBlockHashmap(SHashObj* pDataBlockHash) {
|
|||
void** p1 = taosHashIterate(pDataBlockHash, NULL);
|
||||
while (p1) {
|
||||
STableDataBlocks* pBlocks = *p1;
|
||||
destroyDataBlock(pBlocks);
|
||||
insDestroyDataBlock(pBlocks);
|
||||
|
||||
p1 = taosHashIterate(pDataBlockHash, p1);
|
||||
}
|
||||
|
@ -313,6 +357,7 @@ void destroyBlockHashmap(SHashObj* pDataBlockHash) {
|
|||
taosHashCleanup(pDataBlockHash);
|
||||
}
|
||||
|
||||
#if 0
|
||||
// data block is disordered, sort it in ascending order
|
||||
void sortRemoveDataBlockDupRowsRaw(STableDataBlocks* dataBuf) {
|
||||
SSubmitBlk* pBlocks = (SSubmitBlk*)dataBuf->pData;
|
||||
|
@ -355,6 +400,7 @@ void sortRemoveDataBlockDupRowsRaw(STableDataBlocks* dataBuf) {
|
|||
|
||||
dataBuf->prevTS = INT64_MIN;
|
||||
}
|
||||
#endif
|
||||
|
||||
// data block is disordered, sort it in ascending order
|
||||
static int sortRemoveDataBlockDupRows(STableDataBlocks* dataBuf, SBlockKeyInfo* pBlkKeyInfo) {
|
||||
|
@ -375,7 +421,7 @@ static int sortRemoveDataBlockDupRows(STableDataBlocks* dataBuf, SBlockKeyInfo*
|
|||
}
|
||||
memset(pBlkKeyInfo->pKeyTuple, 0, nAlloc);
|
||||
|
||||
int32_t extendedRowSize = getExtendedRowSize(dataBuf);
|
||||
int32_t extendedRowSize = insGetExtendedRowSize(dataBuf);
|
||||
SBlockKeyTuple* pBlkKeyTuple = pBlkKeyInfo->pKeyTuple;
|
||||
char* pBlockData = pBlocks->data + pBlocks->schemaLen;
|
||||
int n = 0;
|
||||
|
@ -545,7 +591,7 @@ static int sortMergeDataBlockDupRows(STableDataBlocks* dataBuf, SBlockKeyInfo* p
|
|||
|
||||
tdResetSBlockRowMerger(*ppBlkRowMerger);
|
||||
|
||||
int32_t extendedRowSize = getExtendedRowSize(dataBuf);
|
||||
int32_t extendedRowSize = insGetExtendedRowSize(dataBuf);
|
||||
SBlockKeyTuple* pBlkKeyTuple = pBlkKeyInfo->pKeyTuple;
|
||||
char* pBlockData = pBlocks->data + pBlocks->schemaLen;
|
||||
int32_t n = 0;
|
||||
|
@ -621,68 +667,31 @@ static int sortMergeDataBlockDupRows(STableDataBlocks* dataBuf, SBlockKeyInfo* p
|
|||
}
|
||||
|
||||
// Erase the empty space reserved for binary data
|
||||
static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SBlockKeyTuple* blkKeyTuple,
|
||||
bool isRawPayload) {
|
||||
static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SBlockKeyTuple* blkKeyTuple) {
|
||||
// TODO: optimize this function, handle the case while binary is not presented
|
||||
STableMeta* pTableMeta = pTableDataBlock->pTableMeta;
|
||||
STableComInfo tinfo = getTableInfo(pTableMeta);
|
||||
SSchema* pSchema = getTableColumnSchema(pTableMeta);
|
||||
|
||||
int32_t nonDataLen = sizeof(SSubmitBlk) + pTableDataBlock->createTbReqLen;
|
||||
SSubmitBlk* pBlock = pDataBlock;
|
||||
memcpy(pDataBlock, pTableDataBlock->pData, nonDataLen);
|
||||
pDataBlock = (char*)pDataBlock + nonDataLen;
|
||||
|
||||
int32_t flen = 0; // original total length of row
|
||||
if (isRawPayload) {
|
||||
for (int32_t j = 0; j < tinfo.numOfColumns; ++j) {
|
||||
flen += TYPE_BYTES[pSchema[j].type];
|
||||
}
|
||||
}
|
||||
pBlock->schemaLen = pTableDataBlock->createTbReqLen;
|
||||
|
||||
char* p = pTableDataBlock->pData + nonDataLen;
|
||||
pBlock->dataLen = 0;
|
||||
|
||||
int32_t numOfRows = pBlock->numOfRows;
|
||||
|
||||
if (isRawPayload) {
|
||||
SRowBuilder builder = {0};
|
||||
|
||||
tdSRowInit(&builder, pTableMeta->sversion);
|
||||
tdSRowSetInfo(&builder, getNumOfColumns(pTableMeta), -1, flen);
|
||||
|
||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||
tdSRowResetBuf(&builder, pDataBlock);
|
||||
int toffset = 0;
|
||||
for (int32_t j = 0; j < tinfo.numOfColumns; ++j) {
|
||||
int8_t colType = pSchema[j].type;
|
||||
uint8_t valType = isNull(p, colType) ? TD_VTYPE_NULL : TD_VTYPE_NORM;
|
||||
tdAppendColValToRow(&builder, pSchema[j].colId, colType, valType, p, true, toffset, j);
|
||||
toffset += TYPE_BYTES[colType];
|
||||
p += pSchema[j].bytes;
|
||||
}
|
||||
tdSRowEnd(&builder);
|
||||
int32_t rowLen = TD_ROW_LEN((STSRow*)pDataBlock);
|
||||
pDataBlock = (char*)pDataBlock + rowLen;
|
||||
pBlock->dataLen += rowLen;
|
||||
}
|
||||
} else {
|
||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||
void* payload = (blkKeyTuple + i)->payloadAddr;
|
||||
TDRowLenT rowTLen = TD_ROW_LEN((STSRow*)payload);
|
||||
memcpy(pDataBlock, payload, rowTLen);
|
||||
pDataBlock = POINTER_SHIFT(pDataBlock, rowTLen);
|
||||
pBlock->dataLen += rowTLen;
|
||||
}
|
||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||
void* payload = (blkKeyTuple + i)->payloadAddr;
|
||||
TDRowLenT rowTLen = TD_ROW_LEN((STSRow*)payload);
|
||||
memcpy(pDataBlock, payload, rowTLen);
|
||||
pDataBlock = POINTER_SHIFT(pDataBlock, rowTLen);
|
||||
pBlock->dataLen += rowTLen;
|
||||
}
|
||||
|
||||
return pBlock->dataLen + pBlock->schemaLen;
|
||||
}
|
||||
|
||||
int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** pVgDataBlocks) {
|
||||
int32_t insMergeTableDataBlocks(SHashObj* pHashObj, SArray** pVgDataBlocks) {
|
||||
const int INSERT_HEAD_SIZE = sizeof(SSubmitReq);
|
||||
int code = 0;
|
||||
bool isRawPayload = IS_RAW_PAYLOAD(payloadType);
|
||||
SHashObj* pVnodeDataBlockHashList = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, false);
|
||||
SArray* pVnodeDataBlockList = taosArrayInit(8, POINTER_BYTES);
|
||||
|
||||
|
@ -696,20 +705,19 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p
|
|||
if (pBlocks->numOfRows > 0) {
|
||||
STableDataBlocks* dataBuf = NULL;
|
||||
pOneTableBlock->pTableMeta->vgId = pOneTableBlock->vgId; // for schemaless, restore origin vgId
|
||||
int32_t ret = getDataBlockFromList(pVnodeDataBlockHashList, &pOneTableBlock->vgId, sizeof(pOneTableBlock->vgId),
|
||||
TSDB_PAYLOAD_SIZE, INSERT_HEAD_SIZE, 0, pOneTableBlock->pTableMeta, &dataBuf,
|
||||
pVnodeDataBlockList, NULL);
|
||||
int32_t ret = insGetDataBlockFromList(pVnodeDataBlockHashList, &pOneTableBlock->vgId,
|
||||
sizeof(pOneTableBlock->vgId), TSDB_PAYLOAD_SIZE, INSERT_HEAD_SIZE, 0,
|
||||
pOneTableBlock->pTableMeta, &dataBuf, pVnodeDataBlockList, NULL);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
tdFreeSBlockRowMerger(pBlkRowMerger);
|
||||
taosHashCleanup(pVnodeDataBlockHashList);
|
||||
destroyBlockArrayList(pVnodeDataBlockList);
|
||||
insDestroyBlockArrayList(pVnodeDataBlockList);
|
||||
taosMemoryFreeClear(blkKeyInfo.pKeyTuple);
|
||||
return ret;
|
||||
}
|
||||
ASSERT(pOneTableBlock->pTableMeta->tableInfo.rowSize > 0);
|
||||
// the maximum expanded size in byte when a row-wise data is converted to SDataRow format
|
||||
int32_t expandSize = isRawPayload ? getRowExpandSize(pOneTableBlock->pTableMeta) : 0;
|
||||
int64_t destSize = dataBuf->size + pOneTableBlock->size + pBlocks->numOfRows * expandSize +
|
||||
int64_t destSize = dataBuf->size + pOneTableBlock->size +
|
||||
sizeof(STColumn) * getNumOfColumns(pOneTableBlock->pTableMeta) +
|
||||
pOneTableBlock->createTbReqLen;
|
||||
|
||||
|
@ -721,30 +729,25 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p
|
|||
} else { // failed to allocate memory, free already allocated memory and return error code
|
||||
tdFreeSBlockRowMerger(pBlkRowMerger);
|
||||
taosHashCleanup(pVnodeDataBlockHashList);
|
||||
destroyBlockArrayList(pVnodeDataBlockList);
|
||||
insDestroyBlockArrayList(pVnodeDataBlockList);
|
||||
taosMemoryFreeClear(dataBuf->pData);
|
||||
taosMemoryFreeClear(blkKeyInfo.pKeyTuple);
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
if (isRawPayload) {
|
||||
sortRemoveDataBlockDupRowsRaw(pOneTableBlock);
|
||||
} else {
|
||||
if ((code = sortMergeDataBlockDupRows(pOneTableBlock, &blkKeyInfo, &pBlkRowMerger)) != 0) {
|
||||
tdFreeSBlockRowMerger(pBlkRowMerger);
|
||||
taosHashCleanup(pVnodeDataBlockHashList);
|
||||
destroyBlockArrayList(pVnodeDataBlockList);
|
||||
taosMemoryFreeClear(dataBuf->pData);
|
||||
taosMemoryFreeClear(blkKeyInfo.pKeyTuple);
|
||||
return code;
|
||||
}
|
||||
ASSERT(blkKeyInfo.pKeyTuple != NULL && pBlocks->numOfRows > 0);
|
||||
if ((code = sortMergeDataBlockDupRows(pOneTableBlock, &blkKeyInfo, &pBlkRowMerger)) != 0) {
|
||||
tdFreeSBlockRowMerger(pBlkRowMerger);
|
||||
taosHashCleanup(pVnodeDataBlockHashList);
|
||||
insDestroyBlockArrayList(pVnodeDataBlockList);
|
||||
taosMemoryFreeClear(dataBuf->pData);
|
||||
taosMemoryFreeClear(blkKeyInfo.pKeyTuple);
|
||||
return code;
|
||||
}
|
||||
ASSERT(blkKeyInfo.pKeyTuple != NULL && pBlocks->numOfRows > 0);
|
||||
|
||||
// erase the empty space reserved for binary data
|
||||
int32_t finalLen =
|
||||
trimDataBlock(dataBuf->pData + dataBuf->size, pOneTableBlock, blkKeyInfo.pKeyTuple, isRawPayload);
|
||||
int32_t finalLen = trimDataBlock(dataBuf->pData + dataBuf->size, pOneTableBlock, blkKeyInfo.pKeyTuple);
|
||||
|
||||
dataBuf->size += (finalLen + sizeof(SSubmitBlk));
|
||||
assert(dataBuf->size <= dataBuf->nAllocSize);
|
||||
|
@ -767,7 +770,7 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t allocateMemForSize(STableDataBlocks* pDataBlock, int32_t allSize) {
|
||||
int32_t insAllocateMemForSize(STableDataBlocks* pDataBlock, int32_t allSize) {
|
||||
size_t remain = pDataBlock->nAllocSize - pDataBlock->size;
|
||||
uint32_t nAllocSizeOld = pDataBlock->nAllocSize;
|
||||
|
||||
|
@ -789,35 +792,7 @@ int32_t allocateMemForSize(STableDataBlocks* pDataBlock, int32_t allSize) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t allocateMemIfNeed(STableDataBlocks* pDataBlock, int32_t rowSize, int32_t* numOfRows) {
|
||||
size_t remain = pDataBlock->nAllocSize - pDataBlock->size;
|
||||
const int factor = 5;
|
||||
uint32_t nAllocSizeOld = pDataBlock->nAllocSize;
|
||||
|
||||
// expand the allocated size
|
||||
if (remain < rowSize * factor) {
|
||||
while (remain < rowSize * factor) {
|
||||
pDataBlock->nAllocSize = (uint32_t)(pDataBlock->nAllocSize * 1.5);
|
||||
remain = pDataBlock->nAllocSize - pDataBlock->size;
|
||||
}
|
||||
|
||||
char* tmp = taosMemoryRealloc(pDataBlock->pData, (size_t)pDataBlock->nAllocSize);
|
||||
if (tmp != NULL) {
|
||||
pDataBlock->pData = tmp;
|
||||
memset(pDataBlock->pData + pDataBlock->size, 0, pDataBlock->nAllocSize - pDataBlock->size);
|
||||
} else {
|
||||
// do nothing, if allocate more memory failed
|
||||
pDataBlock->nAllocSize = nAllocSizeOld;
|
||||
*numOfRows = (int32_t)(pDataBlock->nAllocSize - pDataBlock->headerSize) / rowSize;
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
*numOfRows = (int32_t)(pDataBlock->nAllocSize - pDataBlock->headerSize) / rowSize;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int initRowBuilder(SRowBuilder* pBuilder, int16_t schemaVer, SParsedDataColInfo* pColInfo) {
|
||||
int32_t insInitRowBuilder(SRowBuilder* pBuilder, int16_t schemaVer, SParsedDataColInfo* pColInfo) {
|
||||
ASSERT(pColInfo->numOfCols > 0 && (pColInfo->numOfBound <= pColInfo->numOfCols));
|
||||
tdSRowInit(pBuilder, schemaVer);
|
||||
tdSRowSetExtendedInfo(pBuilder, pColInfo->numOfCols, pColInfo->numOfBound, pColInfo->flen, pColInfo->allNullLen,
|
||||
|
@ -825,101 +800,218 @@ int initRowBuilder(SRowBuilder* pBuilder, int16_t schemaVer, SParsedDataColInfo*
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qResetStmtDataBlock(void* block, bool keepBuf) {
|
||||
STableDataBlocks* pBlock = (STableDataBlocks*)block;
|
||||
static char* tableNameGetPosition(SToken* pToken, char target) {
|
||||
bool inEscape = false;
|
||||
bool inQuote = false;
|
||||
char quotaStr = 0;
|
||||
|
||||
if (keepBuf) {
|
||||
taosMemoryFreeClear(pBlock->pData);
|
||||
pBlock->pData = taosMemoryMalloc(TSDB_PAYLOAD_SIZE);
|
||||
if (NULL == pBlock->pData) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
for (uint32_t i = 0; i < pToken->n; ++i) {
|
||||
if (*(pToken->z + i) == target && (!inEscape) && (!inQuote)) {
|
||||
return pToken->z + i;
|
||||
}
|
||||
memset(pBlock->pData, 0, sizeof(SSubmitBlk));
|
||||
|
||||
if (*(pToken->z + i) == TS_ESCAPE_CHAR) {
|
||||
if (!inQuote) {
|
||||
inEscape = !inEscape;
|
||||
}
|
||||
}
|
||||
|
||||
if (*(pToken->z + i) == '\'' || *(pToken->z + i) == '"') {
|
||||
if (!inEscape) {
|
||||
if (!inQuote) {
|
||||
quotaStr = *(pToken->z + i);
|
||||
inQuote = !inQuote;
|
||||
} else if (quotaStr == *(pToken->z + i)) {
|
||||
inQuote = !inQuote;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t insCreateSName(SName* pName, SToken* pTableName, int32_t acctId, const char* dbName, SMsgBuf* pMsgBuf) {
|
||||
const char* msg1 = "name too long";
|
||||
const char* msg2 = "invalid database name";
|
||||
const char* msg3 = "db is not specified";
|
||||
const char* msg4 = "invalid table name";
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
char* p = tableNameGetPosition(pTableName, TS_PATH_DELIMITER[0]);
|
||||
|
||||
if (p != NULL) { // db has been specified in sql string so we ignore current db path
|
||||
assert(*p == TS_PATH_DELIMITER[0]);
|
||||
|
||||
int32_t dbLen = p - pTableName->z;
|
||||
if (dbLen <= 0) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg2);
|
||||
}
|
||||
char name[TSDB_DB_FNAME_LEN] = {0};
|
||||
strncpy(name, pTableName->z, dbLen);
|
||||
int32_t actualDbLen = strdequote(name);
|
||||
|
||||
code = tNameSetDbName(pName, acctId, name, actualDbLen);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg1);
|
||||
}
|
||||
|
||||
int32_t tbLen = pTableName->n - dbLen - 1;
|
||||
if (tbLen <= 0) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg4);
|
||||
}
|
||||
|
||||
char tbname[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
strncpy(tbname, p + 1, tbLen);
|
||||
/*tbLen = */ strdequote(tbname);
|
||||
|
||||
code = tNameFromString(pName, tbname, T_NAME_TABLE);
|
||||
if (code != 0) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg1);
|
||||
}
|
||||
} else { // get current DB name first, and then set it into path
|
||||
if (pTableName->n >= TSDB_TABLE_NAME_LEN) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg1);
|
||||
}
|
||||
|
||||
assert(pTableName->n < TSDB_TABLE_FNAME_LEN);
|
||||
|
||||
char name[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
strncpy(name, pTableName->z, pTableName->n);
|
||||
strdequote(name);
|
||||
|
||||
if (dbName == NULL) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg3);
|
||||
}
|
||||
|
||||
code = tNameSetDbName(pName, acctId, dbName, strlen(dbName));
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
code = buildInvalidOperationMsg(pMsgBuf, msg2);
|
||||
return code;
|
||||
}
|
||||
|
||||
code = tNameFromString(pName, name, T_NAME_TABLE);
|
||||
if (code != 0) {
|
||||
code = buildInvalidOperationMsg(pMsgBuf, msg1);
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t insFindCol(SToken* pColname, int32_t start, int32_t end, SSchema* pSchema) {
|
||||
while (start < end) {
|
||||
if (strlen(pSchema[start].name) == pColname->n && strncmp(pColname->z, pSchema[start].name, pColname->n) == 0) {
|
||||
return start;
|
||||
}
|
||||
++start;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void insBuildCreateTbReq(SVCreateTbReq* pTbReq, const char* tname, STag* pTag, int64_t suid, const char* sname,
|
||||
SArray* tagName, uint8_t tagNum) {
|
||||
pTbReq->type = TD_CHILD_TABLE;
|
||||
pTbReq->name = strdup(tname);
|
||||
pTbReq->ctb.suid = suid;
|
||||
pTbReq->ctb.tagNum = tagNum;
|
||||
if (sname) pTbReq->ctb.stbName = strdup(sname);
|
||||
pTbReq->ctb.pTag = (uint8_t*)pTag;
|
||||
pTbReq->ctb.tagName = taosArrayDup(tagName);
|
||||
pTbReq->ttl = TSDB_DEFAULT_TABLE_TTL;
|
||||
pTbReq->commentLen = -1;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t insMemRowAppend(SMsgBuf* pMsgBuf, const void* value, int32_t len, void* param) {
|
||||
SMemParam* pa = (SMemParam*)param;
|
||||
SRowBuilder* rb = pa->rb;
|
||||
|
||||
if (value == NULL) { // it is a null data
|
||||
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NULL, value, false, pa->toffset, pa->colIdx);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (TSDB_DATA_TYPE_BINARY == pa->schema->type) {
|
||||
const char* rowEnd = tdRowEnd(rb->pBuf);
|
||||
STR_WITH_SIZE_TO_VARSTR(rowEnd, value, len);
|
||||
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, rowEnd, false, pa->toffset, pa->colIdx);
|
||||
} else if (TSDB_DATA_TYPE_NCHAR == pa->schema->type) {
|
||||
// if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long'
|
||||
int32_t output = 0;
|
||||
const char* rowEnd = tdRowEnd(rb->pBuf);
|
||||
if (!taosMbsToUcs4(value, len, (TdUcs4*)varDataVal(rowEnd), pa->schema->bytes - VARSTR_HEADER_SIZE, &output)) {
|
||||
if (errno == E2BIG) {
|
||||
return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pa->schema->name);
|
||||
}
|
||||
char buf[512] = {0};
|
||||
snprintf(buf, tListLen(buf), "%s", strerror(errno));
|
||||
return buildSyntaxErrMsg(pMsgBuf, buf, value);
|
||||
}
|
||||
varDataSetLen(rowEnd, output);
|
||||
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, rowEnd, false, pa->toffset, pa->colIdx);
|
||||
} else {
|
||||
pBlock->pData = NULL;
|
||||
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, value, false, pa->toffset, pa->colIdx);
|
||||
}
|
||||
|
||||
pBlock->ordered = true;
|
||||
pBlock->prevTS = INT64_MIN;
|
||||
pBlock->size = sizeof(SSubmitBlk);
|
||||
pBlock->tsSource = -1;
|
||||
pBlock->numOfTables = 1;
|
||||
pBlock->nAllocSize = TSDB_PAYLOAD_SIZE;
|
||||
pBlock->headerSize = pBlock->size;
|
||||
pBlock->createTbReqLen = 0;
|
||||
|
||||
memset(&pBlock->rowBuilder, 0, sizeof(pBlock->rowBuilder));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qCloneStmtDataBlock(void** pDst, void* pSrc) {
|
||||
*pDst = taosMemoryMalloc(sizeof(STableDataBlocks));
|
||||
if (NULL == *pDst) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
int32_t insCheckTimestamp(STableDataBlocks* pDataBlocks, const char* start) {
|
||||
// once the data block is disordered, we do NOT keep previous timestamp any more
|
||||
if (!pDataBlocks->ordered) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
memcpy(*pDst, pSrc, sizeof(STableDataBlocks));
|
||||
((STableDataBlocks*)(*pDst))->cloned = true;
|
||||
TSKEY k = *(TSKEY*)start;
|
||||
if (k <= pDataBlocks->prevTS) {
|
||||
pDataBlocks->ordered = false;
|
||||
}
|
||||
|
||||
STableDataBlocks* pBlock = (STableDataBlocks*)(*pDst);
|
||||
if (pBlock->pTableMeta) {
|
||||
void* pNewMeta = taosMemoryMalloc(TABLE_META_SIZE(pBlock->pTableMeta));
|
||||
if (NULL == pNewMeta) {
|
||||
taosMemoryFreeClear(*pDst);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
pDataBlocks->prevTS = k;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void buildMsgHeader(STableDataBlocks* src, SVgDataBlocks* blocks) {
|
||||
SSubmitReq* submit = (SSubmitReq*)blocks->pData;
|
||||
submit->header.vgId = htonl(blocks->vg.vgId);
|
||||
submit->header.contLen = htonl(blocks->size);
|
||||
submit->length = submit->header.contLen;
|
||||
submit->numOfBlocks = htonl(blocks->numOfTables);
|
||||
SSubmitBlk* blk = (SSubmitBlk*)(submit + 1);
|
||||
int32_t numOfBlocks = blocks->numOfTables;
|
||||
while (numOfBlocks--) {
|
||||
int32_t dataLen = blk->dataLen;
|
||||
int32_t schemaLen = blk->schemaLen;
|
||||
blk->uid = htobe64(blk->uid);
|
||||
blk->suid = htobe64(blk->suid);
|
||||
blk->sversion = htonl(blk->sversion);
|
||||
blk->dataLen = htonl(blk->dataLen);
|
||||
blk->schemaLen = htonl(blk->schemaLen);
|
||||
blk->numOfRows = htonl(blk->numOfRows);
|
||||
blk = (SSubmitBlk*)(blk->data + schemaLen + dataLen);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t insBuildOutput(SInsertParseContext* pCxt) {
|
||||
size_t numOfVg = taosArrayGetSize(pCxt->pVgDataBlocks);
|
||||
pCxt->pOutput->pDataBlocks = taosArrayInit(numOfVg, POINTER_BYTES);
|
||||
if (NULL == pCxt->pOutput->pDataBlocks) {
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
for (size_t i = 0; i < numOfVg; ++i) {
|
||||
STableDataBlocks* src = taosArrayGetP(pCxt->pVgDataBlocks, i);
|
||||
SVgDataBlocks* dst = taosMemoryCalloc(1, sizeof(SVgDataBlocks));
|
||||
if (NULL == dst) {
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
memcpy(pNewMeta, pBlock->pTableMeta, TABLE_META_SIZE(pBlock->pTableMeta));
|
||||
pBlock->pTableMeta = pNewMeta;
|
||||
taosHashGetDup(pCxt->pVgroupsHashObj, (const char*)&src->vgId, sizeof(src->vgId), &dst->vg);
|
||||
dst->numOfTables = src->numOfTables;
|
||||
dst->size = src->size;
|
||||
TSWAP(dst->pData, src->pData);
|
||||
buildMsgHeader(src, dst);
|
||||
taosArrayPush(pCxt->pOutput->pDataBlocks, &dst);
|
||||
}
|
||||
|
||||
return qResetStmtDataBlock(*pDst, false);
|
||||
}
|
||||
|
||||
int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc, uint64_t uid, int32_t vgId) {
|
||||
int32_t code = qCloneStmtDataBlock(pDst, pSrc);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
STableDataBlocks* pBlock = (STableDataBlocks*)*pDst;
|
||||
pBlock->pData = taosMemoryMalloc(pBlock->nAllocSize);
|
||||
if (NULL == pBlock->pData) {
|
||||
qFreeStmtDataBlock(pBlock);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pBlock->vgId = vgId;
|
||||
|
||||
if (pBlock->pTableMeta) {
|
||||
pBlock->pTableMeta->uid = uid;
|
||||
pBlock->pTableMeta->vgId = vgId;
|
||||
}
|
||||
|
||||
memset(pBlock->pData, 0, sizeof(SSubmitBlk));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
STableMeta* qGetTableMetaInDataBlock(void* pDataBlock) { return ((STableDataBlocks*)pDataBlock)->pTableMeta; }
|
||||
|
||||
void qFreeStmtDataBlock(void* pDataBlock) {
|
||||
if (pDataBlock == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(((STableDataBlocks*)pDataBlock)->pTableMeta);
|
||||
taosMemoryFreeClear(((STableDataBlocks*)pDataBlock)->pData);
|
||||
taosMemoryFreeClear(pDataBlock);
|
||||
}
|
||||
|
||||
void qDestroyStmtDataBlock(void* pBlock) {
|
||||
if (pBlock == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
||||
|
||||
pDataBlock->cloned = false;
|
||||
destroyDataBlock(pDataBlock);
|
||||
}
|
|
@ -4847,6 +4847,11 @@ static int32_t checkAlterSuperTableBySchema(STranslateContext* pCxt, SAlterTable
|
|||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_ONLY_ONE_JSON_TAG);
|
||||
}
|
||||
|
||||
int32_t tagsLen = 0;
|
||||
for (int32_t i = 0; i < pTableMeta->tableInfo.numOfTags; ++i) {
|
||||
tagsLen += pTagsSchema[i].bytes;
|
||||
}
|
||||
|
||||
if (TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES == pStmt->alterType ||
|
||||
TSDB_ALTER_TABLE_UPDATE_TAG_BYTES == pStmt->alterType) {
|
||||
if (TSDB_SUPER_TABLE != pTableMeta->tableType) {
|
||||
|
@ -4860,7 +4865,38 @@ static int32_t checkAlterSuperTableBySchema(STranslateContext* pCxt, SAlterTable
|
|||
pSchema->bytes >= calcTypeBytes(pStmt->dataType)) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_MODIFY_COL);
|
||||
}
|
||||
|
||||
if (TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES == pStmt->alterType &&
|
||||
pTableMeta->tableInfo.rowSize + calcTypeBytes(pStmt->dataType) - pSchema->bytes > TSDB_MAX_BYTES_PER_ROW) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ROW_LENGTH, TSDB_MAX_BYTES_PER_ROW);
|
||||
}
|
||||
|
||||
if (TSDB_ALTER_TABLE_UPDATE_TAG_BYTES == pStmt->alterType &&
|
||||
tagsLen + calcTypeBytes(pStmt->dataType) - pSchema->bytes > TSDB_MAX_TAGS_LEN) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TAGS_LENGTH, TSDB_MAX_TAGS_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_ALTER_TABLE_ADD_COLUMN == pStmt->alterType) {
|
||||
if (TSDB_MAX_COLUMNS == pTableMeta->tableInfo.numOfColumns) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_TOO_MANY_COLUMNS);
|
||||
}
|
||||
|
||||
if (pTableMeta->tableInfo.rowSize + calcTypeBytes(pStmt->dataType) > TSDB_MAX_BYTES_PER_ROW) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ROW_LENGTH, TSDB_MAX_BYTES_PER_ROW);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_ALTER_TABLE_ADD_TAG == pStmt->alterType) {
|
||||
if (TSDB_MAX_TAGS == pTableMeta->tableInfo.numOfTags) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TAGS_NUM);
|
||||
}
|
||||
|
||||
if (tagsLen + calcTypeBytes(pStmt->dataType) > TSDB_MAX_TAGS_LEN) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TAGS_LENGTH, TSDB_MAX_TAGS_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -6259,16 +6295,28 @@ static int32_t rewriteShowStableTags(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
}
|
||||
|
||||
static int32_t rewriteShowDnodeVariables(STranslateContext* pCxt, SQuery* pQuery) {
|
||||
SSelectStmt* pStmt = NULL;
|
||||
int32_t code = createSelectStmtForShow(nodeType(pQuery->pRoot), &pStmt);
|
||||
SShowDnodeVariablesStmt* pStmt = (SShowDnodeVariablesStmt*)pQuery->pRoot;
|
||||
SNode* pDnodeCond = NULL;
|
||||
SNode* pLikeCond = NULL;
|
||||
SSelectStmt* pSelect = NULL;
|
||||
int32_t code = createSelectStmtForShow(nodeType(pQuery->pRoot), &pSelect);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createOperatorNode(OP_TYPE_EQUAL, "dnode_id", ((SShowDnodeVariablesStmt*)pQuery->pRoot)->pDnodeId,
|
||||
&pStmt->pWhere);
|
||||
code = createOperatorNode(OP_TYPE_EQUAL, "dnode_id", pStmt->pDnodeId, &pDnodeCond);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createOperatorNode(OP_TYPE_LIKE, "name", pStmt->pLikePattern, &pLikeCond);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (NULL != pLikeCond) {
|
||||
code = createLogicCondNode(pDnodeCond, pLikeCond, &pSelect->pWhere);
|
||||
} else {
|
||||
pSelect->pWhere = pDnodeCond;
|
||||
}
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pQuery->showRewrite = true;
|
||||
nodesDestroyNode(pQuery->pRoot);
|
||||
pQuery->pRoot = (SNode*)pStmt;
|
||||
pQuery->pRoot = (SNode*)pSelect;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -7066,6 +7114,14 @@ static int32_t buildAddColReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, S
|
|||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_DUPLICATED_COLUMN);
|
||||
}
|
||||
|
||||
if (TSDB_MAX_COLUMNS == pTableMeta->tableInfo.numOfColumns) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_TOO_MANY_COLUMNS);
|
||||
}
|
||||
|
||||
if (pTableMeta->tableInfo.rowSize + calcTypeBytes(pStmt->dataType) > TSDB_MAX_BYTES_PER_ROW) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ROW_LENGTH, TSDB_MAX_BYTES_PER_ROW);
|
||||
}
|
||||
|
||||
pReq->colName = strdup(pStmt->colName);
|
||||
if (NULL == pReq->colName) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -7073,7 +7129,6 @@ static int32_t buildAddColReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, S
|
|||
|
||||
pReq->type = pStmt->dataType.type;
|
||||
pReq->flags = COL_SMA_ON;
|
||||
// pReq->bytes = pStmt->dataType.bytes;
|
||||
pReq->bytes = calcTypeBytes(pStmt->dataType);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -7111,6 +7166,10 @@ static int32_t buildUpdateColReq(STranslateContext* pCxt, SAlterTableStmt* pStmt
|
|||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_MODIFY_COL);
|
||||
}
|
||||
|
||||
if (pTableMeta->tableInfo.rowSize + pReq->colModBytes - pSchema->bytes > TSDB_MAX_BYTES_PER_ROW) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ROW_LENGTH, TSDB_MAX_BYTES_PER_ROW);
|
||||
}
|
||||
|
||||
pReq->colName = strdup(pStmt->colName);
|
||||
if (NULL == pReq->colName) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -100,6 +100,8 @@ TEST_F(ParserShowToUseTest, showDnodeVariables) {
|
|||
useDb("root", "test");
|
||||
|
||||
run("SHOW DNODE 1 VARIABLES");
|
||||
|
||||
run("SHOW DNODE 1 VARIABLES LIKE '%debug%'");
|
||||
}
|
||||
|
||||
TEST_F(ParserShowToUseTest, showFunctions) {
|
||||
|
|
|
@ -624,8 +624,6 @@ static int32_t createIndefRowsFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt
|
|||
return code;
|
||||
}
|
||||
|
||||
static bool isInterpFunc(int32_t funcId) { return fmIsInterpFunc(funcId) || fmIsInterpPseudoColumnFunc(funcId); }
|
||||
|
||||
static int32_t createInterpFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
||||
if (!pSelect->hasInterpFunc) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -640,7 +638,8 @@ static int32_t createInterpFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt* p
|
|||
pInterpFunc->node.requireDataOrder = getRequireDataOrder(true, pSelect);
|
||||
pInterpFunc->node.resultDataOrder = pInterpFunc->node.requireDataOrder;
|
||||
|
||||
int32_t code = nodesCollectFuncs(pSelect, SQL_CLAUSE_SELECT, isInterpFunc, &pInterpFunc->pFuncs);
|
||||
// interp functions and _group_key functions
|
||||
int32_t code = nodesCollectFuncs(pSelect, SQL_CLAUSE_SELECT, fmIsVectorFunc, &pInterpFunc->pFuncs);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = rewriteExprsForSelect(pInterpFunc->pFuncs, pSelect, SQL_CLAUSE_SELECT);
|
||||
}
|
||||
|
@ -728,7 +727,7 @@ static int32_t createWindowLogicNodeByState(SLogicPlanContext* pCxt, SStateWindo
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode);
|
||||
}
|
||||
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
|
|
@ -2242,6 +2242,26 @@ static EDealRes lastRowScanOptSetColDataType(SNode* pNode, void* pContext) {
|
|||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static void lastRowScanOptSetLastTargets(SNodeList* pTargets, SNodeList* pLastCols) {
|
||||
SNode* pTarget = NULL;
|
||||
WHERE_EACH(pTarget, pTargets) {
|
||||
bool found = false;
|
||||
SNode* pCol = NULL;
|
||||
FOREACH(pCol, pLastCols) {
|
||||
if (nodesEqualNode(pCol, pTarget)) {
|
||||
getLastCacheDataType(&(((SColumnNode*)pTarget)->node.resType));
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
ERASE_NODE(pTargets);
|
||||
continue;
|
||||
}
|
||||
WHERE_NEXT;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t lastRowScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSubplan) {
|
||||
SAggLogicNode* pAgg = (SAggLogicNode*)optFindPossibleNode(pLogicSubplan->pNode, lastRowScanOptMayBeOptimized);
|
||||
|
||||
|
@ -2265,6 +2285,7 @@ static int32_t lastRowScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogic
|
|||
}
|
||||
if (FUNCTION_TYPE_LAST == funcType) {
|
||||
nodesWalkExpr(nodesListGetNode(pFunc->pParameterList, 0), lastRowScanOptSetColDataType, &cxt);
|
||||
nodesListErase(pFunc->pParameterList, nodesListGetCell(pFunc->pParameterList, 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2274,9 +2295,9 @@ static int32_t lastRowScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogic
|
|||
pScan->igLastNull = pAgg->hasLast ? true : false;
|
||||
if (NULL != cxt.pLastCols) {
|
||||
cxt.doAgg = false;
|
||||
nodesWalkExprs(pScan->pScanCols, lastRowScanOptSetColDataType, &cxt);
|
||||
lastRowScanOptSetLastTargets(pScan->pScanCols, cxt.pLastCols);
|
||||
nodesWalkExprs(pScan->pScanPseudoCols, lastRowScanOptSetColDataType, &cxt);
|
||||
nodesWalkExprs(pScan->node.pTargets, lastRowScanOptSetColDataType, &cxt);
|
||||
lastRowScanOptSetLastTargets(pScan->node.pTargets, cxt.pLastCols);
|
||||
nodesClearList(cxt.pLastCols);
|
||||
}
|
||||
pAgg->hasLastRow = false;
|
||||
|
@ -2365,7 +2386,7 @@ static int32_t mergeProjectsOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLog
|
|||
return mergeProjectsOptimizeImpl(pCxt, pLogicSubplan, pProjectNode);
|
||||
}
|
||||
|
||||
static bool tagScanMayBeOptimized(SLogicNode* pNode) {
|
||||
static bool tagScanOptShouldBeOptimized(SLogicNode* pNode) {
|
||||
if (QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(pNode) || (SCAN_TYPE_TAG == ((SScanLogicNode*)pNode)->scanType)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -2397,7 +2418,7 @@ static bool tagScanMayBeOptimized(SLogicNode* pNode) {
|
|||
}
|
||||
|
||||
static int32_t tagScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSubplan) {
|
||||
SScanLogicNode* pScanNode = (SScanLogicNode*)optFindPossibleNode(pLogicSubplan->pNode, tagScanMayBeOptimized);
|
||||
SScanLogicNode* pScanNode = (SScanLogicNode*)optFindPossibleNode(pLogicSubplan->pNode, tagScanOptShouldBeOptimized);
|
||||
if (NULL == pScanNode) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -2440,6 +2461,29 @@ static int32_t tagScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSubp
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static bool pushDownLimitOptShouldBeOptimized(SLogicNode* pNode) {
|
||||
if (NULL == pNode->pLimit || 1 != LIST_LENGTH(pNode->pChildren) ||
|
||||
QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(nodesListGetNode(pNode->pChildren, 0))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static int32_t pushDownLimitOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSubplan) {
|
||||
SLogicNode* pNode = optFindPossibleNode(pLogicSubplan->pNode, pushDownLimitOptShouldBeOptimized);
|
||||
if (NULL == pNode) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SLogicNode* pChild = (SLogicNode*)nodesListGetNode(pNode->pChildren, 0);
|
||||
nodesDestroyNode(pChild->pLimit);
|
||||
pChild->pLimit = pNode->pLimit;
|
||||
pNode->pLimit = NULL;
|
||||
pCxt->optimized = true;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
static const SOptimizeRule optimizeRuleSet[] = {
|
||||
{.pName = "ScanPath", .optimizeFunc = scanPathOptimize},
|
||||
|
@ -2453,7 +2497,8 @@ static const SOptimizeRule optimizeRuleSet[] = {
|
|||
{.pName = "RewriteTail", .optimizeFunc = rewriteTailOptimize},
|
||||
{.pName = "RewriteUnique", .optimizeFunc = rewriteUniqueOptimize},
|
||||
{.pName = "LastRowScan", .optimizeFunc = lastRowScanOptimize},
|
||||
{.pName = "TagScan", .optimizeFunc = tagScanOptimize}
|
||||
{.pName = "TagScan", .optimizeFunc = tagScanOptimize},
|
||||
// {.pName = "PushDownLimit", .optimizeFunc = pushDownLimitOptimize}
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
|
|
|
@ -84,6 +84,7 @@ static int32_t splCreateExchangeNode(SSplitContext* pCxt, SLogicNode* pChild, SE
|
|||
if (NULL == pExchange) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pExchange->srcStartGroupId = pCxt->groupId;
|
||||
pExchange->srcEndGroupId = pCxt->groupId;
|
||||
pExchange->node.precision = pChild->precision;
|
||||
|
@ -91,6 +92,13 @@ static int32_t splCreateExchangeNode(SSplitContext* pCxt, SLogicNode* pChild, SE
|
|||
if (NULL == pExchange->node.pTargets) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if (NULL != pChild->pLimit) {
|
||||
pExchange->node.pLimit = nodesCloneNode(pChild->pLimit);
|
||||
if (NULL == pExchange->node.pLimit) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
((SLimitNode*)pChild->pLimit)->offset = 0;
|
||||
}
|
||||
|
||||
*pOutput = pExchange;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -921,6 +929,13 @@ static int32_t stbSplSplitScanNodeWithoutPartTags(SSplitContext* pCxt, SStableSp
|
|||
if (NULL != pInfo->pSplitNode->pParent && QUERY_NODE_LOGIC_PLAN_PROJECT == nodeType(pInfo->pSplitNode->pParent) &&
|
||||
NULL == pInfo->pSplitNode->pParent->pLimit && NULL == pInfo->pSplitNode->pParent->pSlimit) {
|
||||
pSplitNode = pInfo->pSplitNode->pParent;
|
||||
if (NULL != pInfo->pSplitNode->pLimit) {
|
||||
pSplitNode->pLimit = nodesCloneNode(pInfo->pSplitNode->pLimit);
|
||||
if (NULL == pSplitNode->pLimit) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
((SLimitNode*)pInfo->pSplitNode->pLimit)->offset = 0;
|
||||
}
|
||||
}
|
||||
int32_t code = splCreateExchangeNodeForSubplan(pCxt, pInfo->pSubplan, pSplitNode, SUBPLAN_TYPE_MERGE);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
|
|
@ -103,6 +103,9 @@ TEST_F(PlanBasicTest, interpFunc) {
|
|||
run("SELECT INTERP(c1) FROM t1 RANGE('2017-7-14 18:00:00', '2017-7-14 19:00:00') EVERY(5s) FILL(LINEAR)");
|
||||
|
||||
run("SELECT _IROWTS, INTERP(c1) FROM t1 RANGE('2017-7-14 18:00:00', '2017-7-14 19:00:00') EVERY(5s) FILL(LINEAR)");
|
||||
|
||||
run("SELECT TBNAME, _IROWTS, INTERP(c1) FROM t1 PARTITION BY TBNAME "
|
||||
"RANGE('2017-7-14 18:00:00', '2017-7-14 19:00:00') EVERY(5s) FILL(LINEAR)");
|
||||
}
|
||||
|
||||
TEST_F(PlanBasicTest, lastRowFuncWithoutCache) {
|
||||
|
|
|
@ -95,9 +95,13 @@ TEST_F(PlanOptimizeTest, eliminateProjection) {
|
|||
useDb("root", "test");
|
||||
|
||||
run("SELECT c1, sum(c3) FROM t1 GROUP BY c1");
|
||||
|
||||
run("SELECT c1 FROM t1");
|
||||
|
||||
run("SELECT * FROM st1");
|
||||
|
||||
run("SELECT c1 FROM st1s3");
|
||||
|
||||
// run("select 1-abs(c1) from (select unique(c1) c1 from st1s3) order by 1 nulls first");
|
||||
}
|
||||
|
||||
|
@ -136,4 +140,14 @@ TEST_F(PlanOptimizeTest, tagScan) {
|
|||
run("select tag1 from st1 group by tag1");
|
||||
run("select distinct tag1 from st1");
|
||||
run("select tag1*tag1 from st1 group by tag1*tag1");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(PlanOptimizeTest, pushDownLimit) {
|
||||
useDb("root", "test");
|
||||
|
||||
run("SELECT c1 FROM t1 LIMIT 1");
|
||||
|
||||
run("SELECT c1 FROM st1 LIMIT 1");
|
||||
|
||||
run("SELECT c1 FROM st1 LIMIT 20 OFFSET 10");
|
||||
}
|
||||
|
|
|
@ -85,6 +85,8 @@ TEST_F(PlanOtherTest, show) {
|
|||
|
||||
run("SHOW DNODE 1 VARIABLES");
|
||||
|
||||
run("SHOW DNODE 1 VARIABLES LIKE '%debug%'");
|
||||
|
||||
run("SHOW TAGS FROM st1s1");
|
||||
|
||||
run("SHOW TABLE TAGS FROM st1");
|
||||
|
|
|
@ -1082,7 +1082,12 @@ int32_t filterAddUnitImpl(SFilterInfo *info, uint8_t optr, SFilterFieldId *left,
|
|||
if (info->unitNum >= info->unitSize) {
|
||||
uint32_t psize = info->unitSize;
|
||||
info->unitSize += FILTER_DEFAULT_UNIT_SIZE;
|
||||
info->units = taosMemoryRealloc(info->units, info->unitSize * sizeof(SFilterUnit));
|
||||
|
||||
void *tmp = taosMemoryRealloc(info->units, info->unitSize * sizeof(SFilterUnit));
|
||||
if (tmp == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
info->units = tmp;
|
||||
memset(info->units + psize, 0, sizeof(*info->units) * FILTER_DEFAULT_UNIT_SIZE);
|
||||
}
|
||||
|
||||
|
@ -1135,7 +1140,12 @@ int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFi
|
|||
int32_t filterAddUnitToGroup(SFilterGroup *group, uint32_t unitIdx) {
|
||||
if (group->unitNum >= group->unitSize) {
|
||||
group->unitSize += FILTER_DEFAULT_UNIT_SIZE;
|
||||
group->unitIdxs = taosMemoryRealloc(group->unitIdxs, group->unitSize * sizeof(*group->unitIdxs));
|
||||
|
||||
void *tmp = taosMemoryRealloc(group->unitIdxs, group->unitSize * sizeof(*group->unitIdxs));
|
||||
if (tmp == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
group->unitIdxs = tmp;
|
||||
}
|
||||
|
||||
group->unitIdxs[group->unitNum++] = unitIdx;
|
||||
|
@ -3712,7 +3722,7 @@ EDealRes fltReviseRewriter(SNode **pNode, void *pContext) {
|
|||
SListCell *cell = node->pParameterList->pHead;
|
||||
for (int32_t i = 0; i < node->pParameterList->length; ++i) {
|
||||
if (NULL == cell || NULL == cell->pNode) {
|
||||
fltError("invalid cell, cell:%p, pNode:%p", cell, cell->pNode);
|
||||
fltError("invalid cell");
|
||||
stat->code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
|
@ -4066,6 +4076,10 @@ bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, SColumnInfoData **p, SC
|
|||
*p = output.columnData;
|
||||
output.numOfRows = pSrc->info.rows;
|
||||
|
||||
if (*p == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool keep = (*info->func)(info, pSrc->info.rows, *p, statis, numOfCols, &output.numOfQualified);
|
||||
|
||||
// todo this should be return during filter procedure
|
||||
|
|
|
@ -331,7 +331,10 @@ int32_t sclInitParam(SNode *node, SScalarParam *param, SScalarCtx *ctx, int32_t
|
|||
|
||||
ASSERT(param->columnData == NULL);
|
||||
param->numOfRows = 1;
|
||||
/*int32_t code = */ sclCreateColumnInfoData(&valueNode->node.resType, 1, param);
|
||||
int32_t code = sclCreateColumnInfoData(&valueNode->node.resType, 1, param);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
SCL_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type || valueNode->isNull) {
|
||||
colDataAppendNULL(param->columnData, 0);
|
||||
} else {
|
||||
|
@ -1485,8 +1488,13 @@ static int32_t sclGetMinusOperatorResType(SOperatorNode *pOp) {
|
|||
}
|
||||
|
||||
static int32_t sclGetMathOperatorResType(SOperatorNode *pOp) {
|
||||
if (pOp == NULL || pOp->pLeft == NULL || pOp->pRight == NULL) {
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
|
||||
SDataType ldt = ((SExprNode *)(pOp->pLeft))->resType;
|
||||
SDataType rdt = ((SExprNode *)(pOp->pRight))->resType;
|
||||
|
||||
if ((TSDB_DATA_TYPE_TIMESTAMP == ldt.type && TSDB_DATA_TYPE_TIMESTAMP == rdt.type) ||
|
||||
(TSDB_DATA_TYPE_TIMESTAMP == ldt.type && (IS_VAR_DATA_TYPE(rdt.type) || IS_FLOAT_TYPE(rdt.type))) ||
|
||||
(TSDB_DATA_TYPE_TIMESTAMP == rdt.type && (IS_VAR_DATA_TYPE(ldt.type) || IS_FLOAT_TYPE(ldt.type)))) {
|
||||
|
@ -1507,10 +1515,21 @@ static int32_t sclGetMathOperatorResType(SOperatorNode *pOp) {
|
|||
}
|
||||
|
||||
static int32_t sclGetCompOperatorResType(SOperatorNode *pOp) {
|
||||
if (pOp == NULL || pOp->pLeft == NULL) {
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
|
||||
SDataType ldt = ((SExprNode *)(pOp->pLeft))->resType;
|
||||
|
||||
if (OP_TYPE_IN == pOp->opType || OP_TYPE_NOT_IN == pOp->opType) {
|
||||
if (pOp->pRight == NULL) {
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
((SExprNode *)(pOp->pRight))->resType = ldt;
|
||||
} else if (nodesIsRegularOp(pOp)) {
|
||||
if (pOp->pRight == NULL) {
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
SDataType rdt = ((SExprNode *)(pOp->pRight))->resType;
|
||||
if (!IS_VAR_DATA_TYPE(ldt.type) || QUERY_NODE_VALUE != nodeType(pOp->pRight) ||
|
||||
(!IS_STR_DATA_TYPE(rdt.type) && (rdt.type != TSDB_DATA_TYPE_NULL))) {
|
||||
|
@ -1523,8 +1542,13 @@ static int32_t sclGetCompOperatorResType(SOperatorNode *pOp) {
|
|||
}
|
||||
|
||||
static int32_t sclGetJsonOperatorResType(SOperatorNode *pOp) {
|
||||
if (pOp == NULL || pOp->pLeft == NULL || pOp->pRight == NULL) {
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
|
||||
SDataType ldt = ((SExprNode *)(pOp->pLeft))->resType;
|
||||
SDataType rdt = ((SExprNode *)(pOp->pRight))->resType;
|
||||
|
||||
if (TSDB_DATA_TYPE_JSON != ldt.type || !IS_STR_DATA_TYPE(rdt.type)) {
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
|
|
|
@ -1416,7 +1416,7 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
|
|||
} else if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) {
|
||||
timeVal[k] = timeVal[k] * 1000;
|
||||
} else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) {
|
||||
timeVal[k] = timeVal[k];
|
||||
timeVal[k] = timeVal[k] * 1;
|
||||
} else {
|
||||
hasNull = true;
|
||||
break;
|
||||
|
|
|
@ -344,8 +344,11 @@ static FORCE_INLINE void varToNchar(char *buf, SScalarParam *pOut, int32_t rowIn
|
|||
int32_t outputMaxLen = (inputLen + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
|
||||
|
||||
char *t = taosMemoryCalloc(1, outputMaxLen);
|
||||
/*int32_t resLen = */ taosMbsToUcs4(varDataVal(buf), inputLen, (TdUcs4 *)varDataVal(t),
|
||||
outputMaxLen - VARSTR_HEADER_SIZE, &len);
|
||||
int32_t ret = taosMbsToUcs4(varDataVal(buf), inputLen, (TdUcs4 *)varDataVal(t),
|
||||
outputMaxLen - VARSTR_HEADER_SIZE, &len);
|
||||
if (!ret) {
|
||||
sclError("failed to convert to NCHAR");
|
||||
}
|
||||
varDataSetLen(t, len);
|
||||
|
||||
colDataAppend(pOut->columnData, rowIndex, t, false);
|
||||
|
|
|
@ -440,7 +440,3 @@ FREE:
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t streamDispatchRecoverFinishReq(SStreamTask* pTask) {
|
||||
//
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -136,7 +136,7 @@ int32_t streamMetaAddTask(SStreamMeta* pMeta, int64_t ver, SStreamTask* pTask) {
|
|||
if (code < 0) {
|
||||
return -1;
|
||||
}
|
||||
buf = taosMemoryCalloc(1, sizeof(len));
|
||||
buf = taosMemoryCalloc(1, len);
|
||||
if (buf == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -144,13 +144,13 @@ int32_t streamMetaAddTask(SStreamMeta* pMeta, int64_t ver, SStreamTask* pTask) {
|
|||
SEncoder encoder;
|
||||
tEncoderInit(&encoder, buf, len);
|
||||
tEncodeSStreamTask(&encoder, pTask);
|
||||
tEncoderClear(&encoder);
|
||||
|
||||
if (tdbTbUpsert(pMeta->pTaskDb, &pTask->taskId, sizeof(int32_t), buf, len, &pMeta->txn) < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosMemoryFree(buf);
|
||||
taosHashPut(pMeta->pTasks, &pTask->taskId, sizeof(int32_t), &pTask, sizeof(void*));
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -650,10 +650,10 @@ int32_t streamStateSessionGetKey(SStreamState* pState, const SSessionKey* key, S
|
|||
if (code == 0 && sessionKeyCmpr(key, &tmpKey) == 0) {
|
||||
res = 0;
|
||||
resKey = tmpKey;
|
||||
streamStateCurPrev(pState, pCur);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
streamStateCurPrev(pState, pCur);
|
||||
}
|
||||
*curKey = resKey;
|
||||
streamStateFreeCur(pCur);
|
||||
|
@ -700,9 +700,14 @@ int32_t streamStateStateAddIfNotExist(SStreamState* pState, SSessionKey* key, ch
|
|||
memcpy(tmp, *pVal, valSize);
|
||||
goto _end;
|
||||
}
|
||||
|
||||
streamStateCurNext(pState, pCur);
|
||||
} else {
|
||||
*key = tmpKey;
|
||||
streamStateFreeCur(pCur);
|
||||
pCur = streamStateSessionSeekKeyNext(pState, key);
|
||||
}
|
||||
|
||||
streamStateCurNext(pState, pCur);
|
||||
code = streamStateSessionGetKVByCur(pCur, key, (const void**)pVal, pVLen);
|
||||
if (code == 0) {
|
||||
void* stateKey = (char*)(*pVal) + (valSize - keyDataLen);
|
||||
|
|
|
@ -383,6 +383,8 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
|||
snprintf(logBuf, sizeof(logBuf), "ignore, truncate error, append-index:%" PRId64, appendIndex);
|
||||
syncLogRecvAppendEntries(ths, pMsg, logBuf);
|
||||
|
||||
syncEntryDestory(pLocalEntry);
|
||||
syncEntryDestory(pAppendEntry);
|
||||
goto _IGNORE;
|
||||
}
|
||||
|
||||
|
@ -393,6 +395,8 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
|||
snprintf(logBuf, sizeof(logBuf), "ignore, append error, append-index:%" PRId64, appendIndex);
|
||||
syncLogRecvAppendEntries(ths, pMsg, logBuf);
|
||||
|
||||
syncEntryDestory(pLocalEntry);
|
||||
syncEntryDestory(pAppendEntry);
|
||||
goto _IGNORE;
|
||||
}
|
||||
}
|
||||
|
@ -408,6 +412,8 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
|||
snprintf(logBuf, sizeof(logBuf), "ignore, log not exist, truncate error, append-index:%" PRId64, appendIndex);
|
||||
syncLogRecvAppendEntries(ths, pMsg, logBuf);
|
||||
|
||||
syncEntryDestory(pLocalEntry);
|
||||
syncEntryDestory(pAppendEntry);
|
||||
goto _IGNORE;
|
||||
}
|
||||
|
||||
|
@ -418,6 +424,8 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
|||
snprintf(logBuf, sizeof(logBuf), "ignore, log not exist, append error, append-index:%" PRId64, appendIndex);
|
||||
syncLogRecvAppendEntries(ths, pMsg, logBuf);
|
||||
|
||||
syncEntryDestory(pLocalEntry);
|
||||
syncEntryDestory(pAppendEntry);
|
||||
goto _IGNORE;
|
||||
}
|
||||
|
||||
|
@ -427,33 +435,12 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
|||
snprintf(logBuf, sizeof(logBuf), "ignore, get local entry error, append-index:%" PRId64, appendIndex);
|
||||
syncLogRecvAppendEntries(ths, pMsg, logBuf);
|
||||
|
||||
syncEntryDestory(pLocalEntry);
|
||||
syncEntryDestory(pAppendEntry);
|
||||
goto _IGNORE;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (code != 0 && terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) {
|
||||
code = ths->pLogStore->syncLogTruncate(ths->pLogStore, appendIndex);
|
||||
ASSERT(code == 0);
|
||||
|
||||
code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry);
|
||||
ASSERT(code == 0);
|
||||
|
||||
} else {
|
||||
ASSERT(code == 0);
|
||||
|
||||
if (pLocalEntry->term == pAppendEntry->term) {
|
||||
// do nothing
|
||||
} else {
|
||||
code = ths->pLogStore->syncLogTruncate(ths->pLogStore, appendIndex);
|
||||
ASSERT(code == 0);
|
||||
|
||||
code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry);
|
||||
ASSERT(code == 0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// update match index
|
||||
pReply->matchIndex = pAppendEntry->index;
|
||||
|
||||
|
|
|
@ -45,6 +45,11 @@
|
|||
// /\ UNCHANGED <<messages, serverVars, candidateVars, leaderVars, log>>
|
||||
//
|
||||
void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
|
||||
if (pSyncNode == NULL) {
|
||||
sError("pSyncNode is NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) {
|
||||
syncNodeErrorLog(pSyncNode, "not leader, can not advance commit index");
|
||||
return;
|
||||
|
@ -172,6 +177,7 @@ static inline int64_t syncNodeAbs64(int64_t a, int64_t b) {
|
|||
int32_t syncNodeDynamicQuorum(const SSyncNode* pSyncNode) {
|
||||
return pSyncNode->quorum;
|
||||
|
||||
#if 0
|
||||
int32_t quorum = 1; // self
|
||||
|
||||
int64_t timeNow = taosGetTimestampMs();
|
||||
|
@ -228,6 +234,7 @@ int32_t syncNodeDynamicQuorum(const SSyncNode* pSyncNode) {
|
|||
}
|
||||
|
||||
return quorum;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -90,7 +90,7 @@ void syncCleanUp() {
|
|||
int64_t syncOpen(SSyncInfo* pSyncInfo) {
|
||||
SSyncNode* pSyncNode = syncNodeOpen(pSyncInfo);
|
||||
if (pSyncNode == NULL) {
|
||||
sError("failed to open sync node. vgId:%d", pSyncInfo->vgId);
|
||||
sError("vgId:%d, failed to open sync node", pSyncInfo->vgId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ int64_t syncOpen(SSyncInfo* pSyncInfo) {
|
|||
}
|
||||
|
||||
void syncStart(int64_t rid) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid);
|
||||
if (pSyncNode == NULL) {
|
||||
return;
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ void syncStart(int64_t rid) {
|
|||
}
|
||||
|
||||
void syncStartNormal(int64_t rid) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid);
|
||||
if (pSyncNode == NULL) {
|
||||
return;
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ void syncStartNormal(int64_t rid) {
|
|||
}
|
||||
|
||||
void syncStartStandBy(int64_t rid) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid);
|
||||
if (pSyncNode == NULL) {
|
||||
return;
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ void syncStartStandBy(int64_t rid) {
|
|||
}
|
||||
|
||||
void syncStop(int64_t rid) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid);
|
||||
if (pSyncNode == NULL) return;
|
||||
int32_t vgId = pSyncNode->vgId;
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
|
@ -151,7 +151,7 @@ void syncStop(int64_t rid) {
|
|||
}
|
||||
|
||||
int32_t syncSetStandby(int64_t rid) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid);
|
||||
if (pSyncNode == NULL) {
|
||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||
sError("failed to set standby since accquire ref error, rid:%" PRId64, rid);
|
||||
|
@ -336,7 +336,10 @@ char* syncNodePeerState2Str(const SSyncNode* pSyncNode) {
|
|||
|
||||
for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
|
||||
SPeerState* pState = syncNodeGetPeerState((SSyncNode*)pSyncNode, &(pSyncNode->replicasId[i]));
|
||||
ASSERT(pState != NULL);
|
||||
if (pState == NULL) {
|
||||
sError("vgId:%d, replica maybe dropped", pSyncNode->vgId);
|
||||
break;
|
||||
}
|
||||
|
||||
p = pStr + useLen;
|
||||
use = snprintf(p, leftLen, "%d:%" PRId64 " ,%" PRId64, i, pState->lastSendIndex, pState->lastSendTime);
|
||||
|
@ -832,7 +835,9 @@ void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet) {
|
|||
sInfo("vgId:%d, sync get retry epset: index:%d %s:%d", pSyncNode->vgId, i, pEpSet->eps[i].fqdn,
|
||||
pEpSet->eps[i].port);
|
||||
}
|
||||
pEpSet->inUse = (pSyncNode->pRaftCfg->cfg.myIndex + 1) % pEpSet->numOfEps;
|
||||
if (pEpSet->numOfEps > 0) {
|
||||
pEpSet->inUse = (pSyncNode->pRaftCfg->cfg.myIndex + 1) % pEpSet->numOfEps;
|
||||
}
|
||||
sInfo("vgId:%d, sync get retry epset in-use:%d", pSyncNode->vgId, pEpSet->inUse);
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
|
@ -1089,17 +1094,13 @@ int32_t syncHbTimerStop(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
// open/close --------------
|
||||
SSyncNode* syncNodeOpen(SSyncInfo* pOldSyncInfo) {
|
||||
SSyncInfo* pSyncInfo = (SSyncInfo*)pOldSyncInfo;
|
||||
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosMemoryCalloc(1, sizeof(SSyncNode));
|
||||
SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
|
||||
SSyncNode* pSyncNode = taosMemoryCalloc(1, sizeof(SSyncNode));
|
||||
if (pSyncNode == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _error;
|
||||
}
|
||||
|
||||
int32_t ret = 0;
|
||||
if (!taosDirExist((char*)(pSyncInfo->path))) {
|
||||
if (taosMkDir(pSyncInfo->path) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
|
@ -1111,32 +1112,49 @@ SSyncNode* syncNodeOpen(SSyncInfo* pOldSyncInfo) {
|
|||
snprintf(pSyncNode->configPath, sizeof(pSyncNode->configPath), "%s%sraft_config.json", pSyncInfo->path, TD_DIRSEP);
|
||||
if (!taosCheckExistFile(pSyncNode->configPath)) {
|
||||
// create a new raft config file
|
||||
SRaftCfgMeta meta;
|
||||
SRaftCfgMeta meta = {0};
|
||||
meta.isStandBy = pSyncInfo->isStandBy;
|
||||
meta.snapshotStrategy = pSyncInfo->snapshotStrategy;
|
||||
meta.lastConfigIndex = SYNC_INDEX_INVALID;
|
||||
meta.batchSize = pSyncInfo->batchSize;
|
||||
ret = raftCfgCreateFile((SSyncCfg*)&(pSyncInfo->syncCfg), meta, pSyncNode->configPath);
|
||||
if (ret != 0) {
|
||||
sError("failed to create raft cfg file. configPath: %s", pSyncNode->configPath);
|
||||
if (raftCfgCreateFile(&pSyncInfo->syncCfg, meta, pSyncNode->configPath) != 0) {
|
||||
sError("vgId:%d, failed to create raft cfg file at %s", pSyncNode->vgId, pSyncNode->configPath);
|
||||
goto _error;
|
||||
}
|
||||
if (pSyncInfo->syncCfg.replicaNum == 0) {
|
||||
sInfo("vgId:%d, sync config not input", pSyncNode->vgId);
|
||||
pSyncInfo->syncCfg = pSyncNode->pRaftCfg->cfg;
|
||||
}
|
||||
} else {
|
||||
// update syncCfg by raft_config.json
|
||||
pSyncNode->pRaftCfg = raftCfgOpen(pSyncNode->configPath);
|
||||
if (pSyncNode->pRaftCfg == NULL) {
|
||||
sError("failed to open raft cfg file. path:%s", pSyncNode->configPath);
|
||||
sError("vgId:%d, failed to open raft cfg file at %s", pSyncNode->vgId, pSyncNode->configPath);
|
||||
goto _error;
|
||||
}
|
||||
pSyncInfo->syncCfg = pSyncNode->pRaftCfg->cfg;
|
||||
if (pSyncInfo->syncCfg.replicaNum > 0 && pSyncInfo->syncCfg.replicaNum != pSyncNode->pRaftCfg->cfg.replicaNum) {
|
||||
sInfo("vgId:%d, use sync config from input options and write to cfg file", pSyncNode->vgId);
|
||||
pSyncNode->pRaftCfg->cfg = pSyncInfo->syncCfg;
|
||||
if (raftCfgPersist(pSyncNode->pRaftCfg) != 0) {
|
||||
sError("vgId:%d, failed to persist raft cfg file at %s", pSyncNode->vgId, pSyncNode->configPath);
|
||||
goto _error;
|
||||
}
|
||||
} else {
|
||||
sInfo("vgId:%d, use sync config from raft cfg file", pSyncNode->vgId);
|
||||
pSyncInfo->syncCfg = pSyncNode->pRaftCfg->cfg;
|
||||
}
|
||||
|
||||
raftCfgClose(pSyncNode->pRaftCfg);
|
||||
pSyncNode->pRaftCfg = NULL;
|
||||
}
|
||||
|
||||
SSyncCfg* pCfg = &pSyncInfo->syncCfg;
|
||||
sDebug("vgId:%d, replica:%d selfIndex:%d", pSyncNode->vgId, pCfg->replicaNum, pCfg->myIndex);
|
||||
for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
|
||||
SNodeInfo* pNode = &pCfg->nodeInfo[i];
|
||||
sDebug("vgId:%d, index:%d ep:%s:%u", pSyncNode->vgId, i, pNode->nodeFqdn, pNode->nodePort);
|
||||
}
|
||||
|
||||
// init by SSyncInfo
|
||||
pSyncNode->vgId = pSyncInfo->vgId;
|
||||
memcpy(pSyncNode->path, pSyncInfo->path, sizeof(pSyncNode->path));
|
||||
|
@ -1153,14 +1171,14 @@ SSyncNode* syncNodeOpen(SSyncInfo* pOldSyncInfo) {
|
|||
// init raft config
|
||||
pSyncNode->pRaftCfg = raftCfgOpen(pSyncNode->configPath);
|
||||
if (pSyncNode->pRaftCfg == NULL) {
|
||||
sError("failed to open raft cfg file. path:%s", pSyncNode->configPath);
|
||||
sError("vgId:%d, failed to open raft cfg file at %s", pSyncNode->vgId, pSyncNode->configPath);
|
||||
goto _error;
|
||||
}
|
||||
|
||||
// init internal
|
||||
pSyncNode->myNodeInfo = pSyncNode->pRaftCfg->cfg.nodeInfo[pSyncNode->pRaftCfg->cfg.myIndex];
|
||||
if (!syncUtilnodeInfo2raftId(&pSyncNode->myNodeInfo, pSyncNode->vgId, &pSyncNode->myRaftId)) {
|
||||
sError("failed to determine my raft member id. vgId:%d", pSyncNode->vgId);
|
||||
sError("vgId:%d, failed to determine my raft member id", pSyncNode->vgId);
|
||||
goto _error;
|
||||
}
|
||||
|
||||
|
@ -1175,7 +1193,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pOldSyncInfo) {
|
|||
}
|
||||
for (int i = 0; i < pSyncNode->peersNum; ++i) {
|
||||
if (!syncUtilnodeInfo2raftId(&pSyncNode->peersNodeInfo[i], pSyncNode->vgId, &pSyncNode->peersId[i])) {
|
||||
sError("failed to determine raft member id. vgId:%d, peer:%d", pSyncNode->vgId, i);
|
||||
sError("vgId:%d, failed to determine raft member id, peer:%d", pSyncNode->vgId, i);
|
||||
goto _error;
|
||||
}
|
||||
}
|
||||
|
@ -1184,7 +1202,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pOldSyncInfo) {
|
|||
pSyncNode->replicaNum = pSyncNode->pRaftCfg->cfg.replicaNum;
|
||||
for (int i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) {
|
||||
if (!syncUtilnodeInfo2raftId(&pSyncNode->pRaftCfg->cfg.nodeInfo[i], pSyncNode->vgId, &pSyncNode->replicasId[i])) {
|
||||
sError("failed to determine raft member id. vgId:%d, replica:%d", pSyncNode->vgId, i);
|
||||
sError("vgId:%d, failed to determine raft member id, replica:%d", pSyncNode->vgId, i);
|
||||
goto _error;
|
||||
}
|
||||
}
|
||||
|
@ -1225,38 +1243,38 @@ SSyncNode* syncNodeOpen(SSyncInfo* pOldSyncInfo) {
|
|||
pSyncNode->state = TAOS_SYNC_STATE_FOLLOWER;
|
||||
pSyncNode->pRaftStore = raftStoreOpen(pSyncNode->raftStorePath);
|
||||
if (pSyncNode->pRaftStore == NULL) {
|
||||
sError("failed to open raft store. path: %s", pSyncNode->raftStorePath);
|
||||
sError("vgId:%d, failed to open raft store at path %s", pSyncNode->vgId, pSyncNode->raftStorePath);
|
||||
goto _error;
|
||||
}
|
||||
|
||||
// init TLA+ candidate vars
|
||||
pSyncNode->pVotesGranted = voteGrantedCreate(pSyncNode);
|
||||
if (pSyncNode->pVotesGranted == NULL) {
|
||||
sError("failed to create VotesGranted. vgId:%d", pSyncNode->vgId);
|
||||
sError("vgId:%d, failed to create VotesGranted", pSyncNode->vgId);
|
||||
goto _error;
|
||||
}
|
||||
pSyncNode->pVotesRespond = votesRespondCreate(pSyncNode);
|
||||
if (pSyncNode->pVotesRespond == NULL) {
|
||||
sError("failed to create VotesRespond. vgId:%d", pSyncNode->vgId);
|
||||
sError("vgId:%d, failed to create VotesRespond", pSyncNode->vgId);
|
||||
goto _error;
|
||||
}
|
||||
|
||||
// init TLA+ leader vars
|
||||
pSyncNode->pNextIndex = syncIndexMgrCreate(pSyncNode);
|
||||
if (pSyncNode->pNextIndex == NULL) {
|
||||
sError("failed to create SyncIndexMgr. vgId:%d", pSyncNode->vgId);
|
||||
sError("vgId:%d, failed to create SyncIndexMgr", pSyncNode->vgId);
|
||||
goto _error;
|
||||
}
|
||||
pSyncNode->pMatchIndex = syncIndexMgrCreate(pSyncNode);
|
||||
if (pSyncNode->pMatchIndex == NULL) {
|
||||
sError("failed to create SyncIndexMgr. vgId:%d", pSyncNode->vgId);
|
||||
sError("vgId:%d, failed to create SyncIndexMgr", pSyncNode->vgId);
|
||||
goto _error;
|
||||
}
|
||||
|
||||
// init TLA+ log vars
|
||||
pSyncNode->pLogStore = logStoreCreate(pSyncNode);
|
||||
if (pSyncNode->pLogStore == NULL) {
|
||||
sError("failed to create SyncLogStore. vgId:%d", pSyncNode->vgId);
|
||||
sError("vgId:%d, failed to create SyncLogStore", pSyncNode->vgId);
|
||||
goto _error;
|
||||
}
|
||||
|
||||
|
@ -1265,7 +1283,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pOldSyncInfo) {
|
|||
SSnapshot snapshot = {0};
|
||||
int32_t code = pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot);
|
||||
if (code != 0) {
|
||||
sError("failed to get snapshot info. vgId:%d, code:%d", pSyncNode->vgId, code);
|
||||
sError("vgId:%d, failed to get snapshot info, code:%d", pSyncNode->vgId, code);
|
||||
goto _error;
|
||||
}
|
||||
if (snapshot.lastApplyIndex > commitIndex) {
|
||||
|
@ -1324,7 +1342,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pOldSyncInfo) {
|
|||
// tools
|
||||
pSyncNode->pSyncRespMgr = syncRespMgrCreate(pSyncNode, SYNC_RESP_TTL_MS);
|
||||
if (pSyncNode->pSyncRespMgr == NULL) {
|
||||
sError("failed to create SyncRespMgr. vgId:%d", pSyncNode->vgId);
|
||||
sError("vgId:%d, failed to create SyncRespMgr", pSyncNode->vgId);
|
||||
goto _error;
|
||||
}
|
||||
|
||||
|
@ -1422,12 +1440,13 @@ void syncNodeStartStandBy(SSyncNode* pSyncNode) {
|
|||
}
|
||||
|
||||
void syncNodeClose(SSyncNode* pSyncNode) {
|
||||
syncNodeEventLog(pSyncNode, "sync close");
|
||||
if (pSyncNode == NULL) {
|
||||
return;
|
||||
}
|
||||
int32_t ret;
|
||||
|
||||
syncNodeEventLog(pSyncNode, "sync close");
|
||||
|
||||
ret = raftStoreClose(pSyncNode->pRaftStore);
|
||||
ASSERT(ret == 0);
|
||||
|
||||
|
@ -1863,6 +1882,10 @@ char* syncNode2Str(const SSyncNode* pSyncNode) {
|
|||
}
|
||||
|
||||
inline void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) {
|
||||
if (pSyncNode == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
||||
if (pSyncNode->pFsm != NULL && pSyncNode->pFsm->FpGetSnapshotInfo != NULL) {
|
||||
pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot);
|
||||
|
@ -1938,6 +1961,10 @@ inline void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) {
|
|||
}
|
||||
|
||||
inline void syncNodeErrorLog(const SSyncNode* pSyncNode, char* str) {
|
||||
if (pSyncNode == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t userStrLen = strlen(str);
|
||||
|
||||
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
||||
|
@ -2846,7 +2873,7 @@ static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) {
|
|||
return;
|
||||
}
|
||||
|
||||
//syncNodeEventLog(pSyncNode, "eq peer hb timer");
|
||||
// syncNodeEventLog(pSyncNode, "eq peer hb timer");
|
||||
|
||||
int64_t timerLogicClock = atomic_load_64(&pSyncTimer->logicClock);
|
||||
int64_t msgLogicClock = atomic_load_64(&pData->logicClock);
|
||||
|
@ -2921,6 +2948,7 @@ static int32_t syncNodeEqNoop(SSyncNode* ths) {
|
|||
sTrace("syncNodeEqNoop pSyncNode->FpEqMsg is NULL");
|
||||
}
|
||||
|
||||
syncEntryDestory(pEntry);
|
||||
taosMemoryFree(serialized);
|
||||
syncClientRequestDestroy(pSyncMsg);
|
||||
|
||||
|
@ -2987,13 +3015,14 @@ int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg) {
|
|||
syncPingReply2RpcMsg(pMsgReply, &rpcMsg);
|
||||
|
||||
/*
|
||||
// htonl
|
||||
SMsgHead* pHead = rpcMsg.pCont;
|
||||
pHead->contLen = htonl(pHead->contLen);
|
||||
pHead->vgId = htonl(pHead->vgId);
|
||||
*/
|
||||
// htonl
|
||||
SMsgHead* pHead = rpcMsg.pCont;
|
||||
pHead->contLen = htonl(pHead->contLen);
|
||||
pHead->vgId = htonl(pHead->vgId);
|
||||
*/
|
||||
|
||||
syncNodeSendMsgById(&pMsgReply->destId, ths, &rpcMsg);
|
||||
syncPingReplyDestroy(pMsgReply);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -3042,6 +3071,7 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg) {
|
|||
|
||||
// reply
|
||||
syncNodeSendMsgById(&pMsgReply->destId, ths, &rpcMsg);
|
||||
syncHeartbeatReplyDestroy(pMsgReply);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -3313,17 +3343,23 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde
|
|||
return 0;
|
||||
}
|
||||
|
||||
// advance commit index to sanpshot first
|
||||
SSnapshot snapshot = {0};
|
||||
ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &snapshot);
|
||||
if (snapshot.lastApplyIndex >= 0 && snapshot.lastApplyIndex >= beginIndex) {
|
||||
char eventLog[128];
|
||||
snprintf(eventLog, sizeof(eventLog), "commit by snapshot from index:%" PRId64 " to index:%" PRId64, beginIndex,
|
||||
snapshot.lastApplyIndex);
|
||||
syncNodeEventLog(ths, eventLog);
|
||||
if (ths == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// update begin index
|
||||
beginIndex = snapshot.lastApplyIndex + 1;
|
||||
if (ths->pFsm != NULL && ths->pFsm->FpGetSnapshotInfo != NULL) {
|
||||
// advance commit index to sanpshot first
|
||||
SSnapshot snapshot = {0};
|
||||
ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &snapshot);
|
||||
if (snapshot.lastApplyIndex >= 0 && snapshot.lastApplyIndex >= beginIndex) {
|
||||
char eventLog[128];
|
||||
snprintf(eventLog, sizeof(eventLog), "commit by snapshot from index:%" PRId64 " to index:%" PRId64, beginIndex,
|
||||
snapshot.lastApplyIndex);
|
||||
syncNodeEventLog(ths, eventLog);
|
||||
|
||||
// update begin index
|
||||
beginIndex = snapshot.lastApplyIndex + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
|
@ -3397,8 +3433,10 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde
|
|||
|
||||
// config change finish
|
||||
if (pEntry->originalRpcType == TDMT_SYNC_CONFIG_CHANGE_FINISH) {
|
||||
code = syncNodeConfigChangeFinish(ths, &rpcMsg, pEntry);
|
||||
ASSERT(code == 0);
|
||||
if (rpcMsg.pCont != NULL) {
|
||||
code = syncNodeConfigChangeFinish(ths, &rpcMsg, pEntry);
|
||||
ASSERT(code == 0);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
@ -3482,6 +3520,7 @@ SPeerState* syncNodeGetPeerState(SSyncNode* ths, const SRaftId* pDestId) {
|
|||
bool syncNodeNeedSendAppendEntries(SSyncNode* ths, const SRaftId* pDestId, const SyncAppendEntries* pMsg) {
|
||||
SPeerState* pState = syncNodeGetPeerState(ths, pDestId);
|
||||
if (pState == NULL) {
|
||||
sError("vgId:%d, replica maybe dropped", ths->vgId);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -3511,7 +3550,7 @@ bool syncNodeCanChange(SSyncNode* pSyncNode) {
|
|||
|
||||
for (int i = 0; i < pSyncNode->peersNum; ++i) {
|
||||
SSyncSnapshotSender* pSender = syncNodeGetSnapshotSender(pSyncNode, &(pSyncNode->peersId)[i]);
|
||||
if (pSender->start) {
|
||||
if (pSender != NULL && pSender->start) {
|
||||
sError("sync cannot change3");
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -411,32 +411,40 @@ SyncPing* syncPingDeserialize3(void* buf, int32_t bufLen) {
|
|||
pMsg->bytes = bytes;
|
||||
|
||||
if (tDecodeI32(&decoder, &pMsg->vgId) < 0) {
|
||||
taosMemoryFree(pMsg);
|
||||
return NULL;
|
||||
}
|
||||
if (tDecodeU32(&decoder, &pMsg->msgType) < 0) {
|
||||
taosMemoryFree(pMsg);
|
||||
return NULL;
|
||||
}
|
||||
if (tDecodeU64(&decoder, &pMsg->srcId.addr) < 0) {
|
||||
taosMemoryFree(pMsg);
|
||||
return NULL;
|
||||
}
|
||||
if (tDecodeI32(&decoder, &pMsg->srcId.vgId) < 0) {
|
||||
taosMemoryFree(pMsg);
|
||||
return NULL;
|
||||
}
|
||||
if (tDecodeU64(&decoder, &pMsg->destId.addr) < 0) {
|
||||
taosMemoryFree(pMsg);
|
||||
return NULL;
|
||||
}
|
||||
if (tDecodeI32(&decoder, &pMsg->destId.vgId) < 0) {
|
||||
taosMemoryFree(pMsg);
|
||||
return NULL;
|
||||
}
|
||||
if (tDecodeU32(&decoder, &pMsg->dataLen) < 0) {
|
||||
taosMemoryFree(pMsg);
|
||||
return NULL;
|
||||
}
|
||||
uint32_t len;
|
||||
char* data = NULL;
|
||||
if (tDecodeBinary(&decoder, (uint8_t**)(&data), &len) < 0) {
|
||||
taosMemoryFree(pMsg);
|
||||
return NULL;
|
||||
}
|
||||
ASSERT(len = pMsg->dataLen);
|
||||
ASSERT(len == pMsg->dataLen);
|
||||
memcpy(pMsg->data, data, len);
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
@ -673,32 +681,40 @@ SyncPingReply* syncPingReplyDeserialize3(void* buf, int32_t bufLen) {
|
|||
pMsg->bytes = bytes;
|
||||
|
||||
if (tDecodeI32(&decoder, &pMsg->vgId) < 0) {
|
||||
taosMemoryFree(pMsg);
|
||||
return NULL;
|
||||
}
|
||||
if (tDecodeU32(&decoder, &pMsg->msgType) < 0) {
|
||||
taosMemoryFree(pMsg);
|
||||
return NULL;
|
||||
}
|
||||
if (tDecodeU64(&decoder, &pMsg->srcId.addr) < 0) {
|
||||
taosMemoryFree(pMsg);
|
||||
return NULL;
|
||||
}
|
||||
if (tDecodeI32(&decoder, &pMsg->srcId.vgId) < 0) {
|
||||
taosMemoryFree(pMsg);
|
||||
return NULL;
|
||||
}
|
||||
if (tDecodeU64(&decoder, &pMsg->destId.addr) < 0) {
|
||||
taosMemoryFree(pMsg);
|
||||
return NULL;
|
||||
}
|
||||
if (tDecodeI32(&decoder, &pMsg->destId.vgId) < 0) {
|
||||
taosMemoryFree(pMsg);
|
||||
return NULL;
|
||||
}
|
||||
if (tDecodeU32(&decoder, &pMsg->dataLen) < 0) {
|
||||
taosMemoryFree(pMsg);
|
||||
return NULL;
|
||||
}
|
||||
uint32_t len;
|
||||
char* data = NULL;
|
||||
if (tDecodeBinary(&decoder, (uint8_t**)(&data), &len) < 0) {
|
||||
taosMemoryFree(pMsg);
|
||||
return NULL;
|
||||
}
|
||||
ASSERT(len = pMsg->dataLen);
|
||||
ASSERT(len == pMsg->dataLen);
|
||||
memcpy(pMsg->data, data, len);
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
|
|
@ -355,8 +355,6 @@ char *raftCfg2Str(SRaftCfg *pRaftCfg) {
|
|||
}
|
||||
|
||||
int32_t raftCfgCreateFile(SSyncCfg *pCfg, SRaftCfgMeta meta, const char *path) {
|
||||
ASSERT(pCfg != NULL);
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE);
|
||||
if (pFile == NULL) {
|
||||
int32_t err = terrno;
|
||||
|
|
|
@ -532,7 +532,7 @@ int32_t raftEntryCacheGetEntry(struct SRaftEntryCache* pCache, SyncIndex index,
|
|||
SSyncRaftEntry* pEntry = NULL;
|
||||
int32_t code = raftEntryCacheGetEntryP(pCache, index, &pEntry);
|
||||
if (code == 1) {
|
||||
*ppEntry = taosMemoryMalloc(pEntry->bytes);
|
||||
*ppEntry = taosMemoryMalloc((int64_t)(pEntry->bytes));
|
||||
memcpy(*ppEntry, pEntry, pEntry->bytes);
|
||||
(*ppEntry)->rid = -1;
|
||||
} else {
|
||||
|
|
|
@ -163,7 +163,10 @@ int32_t syncNodeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftI
|
|||
syncNodeSendMsgById(destRaftId, pSyncNode, &rpcMsg);
|
||||
|
||||
SPeerState* pState = syncNodeGetPeerState(pSyncNode, destRaftId);
|
||||
ASSERT(pState != NULL);
|
||||
if (pState == NULL) {
|
||||
sError("vgId:%d, replica maybe dropped", pSyncNode->vgId);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (pMsg->dataLen > 0) {
|
||||
pState->lastSendIndex = pMsg->prevLogIndex + 1;
|
||||
|
|
|
@ -209,7 +209,8 @@ bool syncUtilCanPrint(char c) {
|
|||
}
|
||||
|
||||
char* syncUtilprintBin(char* ptr, uint32_t len) {
|
||||
char* s = taosMemoryMalloc(len + 1);
|
||||
int64_t memLen = (int64_t)(len + 1);
|
||||
char* s = taosMemoryMalloc(memLen);
|
||||
ASSERT(s != NULL);
|
||||
memset(s, 0, len + 1);
|
||||
memcpy(s, ptr, len);
|
||||
|
|
|
@ -741,9 +741,13 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
|
|||
tdbBtreeInitPage(pOldsCopy[i], &iarg, 0);
|
||||
tdbPageCopy(pOlds[i], pOldsCopy[i], 0);
|
||||
}
|
||||
|
||||
for (iNew = 0; iNew < nNews; ++iNew) {
|
||||
tdbBtreeInitPage(pNews[iNew], &iarg, 0);
|
||||
}
|
||||
|
||||
iNew = 0;
|
||||
nNewCells = 0;
|
||||
tdbBtreeInitPage(pNews[iNew], &iarg, 0);
|
||||
|
||||
for (int iOld = 0; iOld < nOlds; iOld++) {
|
||||
SPage *pPage;
|
||||
|
|
|
@ -148,14 +148,22 @@ static FORCE_INLINE void clientRecvCb(uv_stream_t* handle, ssize_t nread, const
|
|||
} else {
|
||||
uTrace("http-report succ to recv %d bytes", (int32_t)nread);
|
||||
}
|
||||
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
|
||||
if (!uv_is_closing((uv_handle_t*)&cli->tcp)) {
|
||||
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
|
||||
} else {
|
||||
destroyHttpClient(cli);
|
||||
}
|
||||
}
|
||||
static void clientSentCb(uv_write_t* req, int32_t status) {
|
||||
SHttpClient* cli = req->data;
|
||||
if (status != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(status);
|
||||
uError("http-report failed to send data %s", uv_strerror(status));
|
||||
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
|
||||
if (!uv_is_closing((uv_handle_t*)&cli->tcp)) {
|
||||
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
|
||||
} else {
|
||||
destroyHttpClient(cli);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
uTrace("http-report succ to send data");
|
||||
|
@ -176,7 +184,11 @@ static void clientConnCb(uv_connect_t* req, int32_t status) {
|
|||
if (status != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(status);
|
||||
uError("http-report failed to conn to server, reason:%s, dst:%s:%d", uv_strerror(status), cli->addr, cli->port);
|
||||
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
|
||||
if (!uv_is_closing((uv_handle_t*)&cli->tcp)) {
|
||||
uv_close((uv_handle_t*)&cli->tcp, clientCloseCb);
|
||||
} else {
|
||||
destroyHttpClient(cli);
|
||||
}
|
||||
return;
|
||||
}
|
||||
status = uv_write(&cli->req, (uv_stream_t*)&cli->tcp, cli->wbuf, 2, clientSentCb);
|
||||
|
|
|
@ -374,7 +374,11 @@ static void uvOnPipeWriteCb(uv_write_t* req, int status) {
|
|||
} else {
|
||||
tError("fail to dispatch conn to work thread");
|
||||
}
|
||||
uv_close((uv_handle_t*)req->data, uvFreeCb);
|
||||
if (!uv_is_closing((uv_handle_t*)req->data)) {
|
||||
uv_close((uv_handle_t*)req->data, uvFreeCb);
|
||||
} else {
|
||||
taosMemoryFree(req->data);
|
||||
}
|
||||
taosMemoryFree(req);
|
||||
}
|
||||
|
||||
|
@ -651,12 +655,14 @@ void uvOnAcceptCb(uv_stream_t* stream, int status) {
|
|||
uv_tcp_init(pObj->loop, cli);
|
||||
|
||||
if (uv_accept(stream, (uv_stream_t*)cli) == 0) {
|
||||
#ifdef WINDOWS
|
||||
if (pObj->numOfWorkerReady < pObj->numOfThreads) {
|
||||
tError("worker-threads are not ready for all, need %d instead of %d.", pObj->numOfThreads,
|
||||
pObj->numOfWorkerReady);
|
||||
uv_close((uv_handle_t*)cli, NULL);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
uv_write_t* wr = (uv_write_t*)taosMemoryMalloc(sizeof(uv_write_t));
|
||||
wr->data = cli;
|
||||
|
@ -668,7 +674,11 @@ void uvOnAcceptCb(uv_stream_t* stream, int status) {
|
|||
|
||||
uv_write2(wr, (uv_stream_t*)&(pObj->pipe[pObj->workerIdx][0]), &buf, 1, (uv_stream_t*)cli, uvOnPipeWriteCb);
|
||||
} else {
|
||||
uv_close((uv_handle_t*)cli, NULL);
|
||||
if (!uv_is_closing((uv_handle_t*)cli)) {
|
||||
uv_close((uv_handle_t*)cli, NULL);
|
||||
} else {
|
||||
taosMemoryFree(cli);
|
||||
}
|
||||
}
|
||||
}
|
||||
void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) {
|
||||
|
@ -681,7 +691,6 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) {
|
|||
tWarn("failed to create connect:%p", q);
|
||||
taosMemoryFree(buf->base);
|
||||
uv_close((uv_handle_t*)q, NULL);
|
||||
// taosMemoryFree(q);
|
||||
return;
|
||||
}
|
||||
// free memory allocated by
|
||||
|
@ -770,7 +779,12 @@ static bool addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName) {
|
|||
return false;
|
||||
}
|
||||
|
||||
#ifdef WINDOWS
|
||||
uv_pipe_init(pThrd->loop, pThrd->pipe, 1);
|
||||
#else
|
||||
uv_pipe_init(pThrd->loop, pThrd->pipe, 1);
|
||||
uv_pipe_open(pThrd->pipe, pThrd->fd);
|
||||
#endif
|
||||
|
||||
pThrd->pipe->data = pThrd;
|
||||
|
||||
|
@ -785,8 +799,11 @@ static bool addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName) {
|
|||
QUEUE_INIT(&pThrd->conn);
|
||||
|
||||
pThrd->asyncPool = transAsyncPoolCreate(pThrd->loop, 5, pThrd, uvWorkerAsyncCb);
|
||||
#ifdef WINDOWS
|
||||
uv_pipe_connect(&pThrd->connect_req, pThrd->pipe, pipeName, uvOnPipeConnectionCb);
|
||||
// uv_read_start((uv_stream_t*)pThrd->pipe, uvAllocConnBufferCb, uvOnConnectionCb);
|
||||
#else
|
||||
uv_read_start((uv_stream_t*)pThrd->pipe, uvAllocConnBufferCb, uvOnConnectionCb);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -958,20 +975,19 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
|||
srv->port = port;
|
||||
uv_loop_init(srv->loop);
|
||||
|
||||
char pipeName[PATH_MAX];
|
||||
#ifdef WINDOWS
|
||||
int ret = uv_pipe_init(srv->loop, &srv->pipeListen, 0);
|
||||
if (ret != 0) {
|
||||
tError("failed to init pipe, errmsg: %s", uv_err_name(ret));
|
||||
goto End;
|
||||
}
|
||||
|
||||
#ifdef WINDOWS
|
||||
char pipeName[64];
|
||||
snprintf(pipeName, sizeof(pipeName), "\\\\?\\pipe\\trans.rpc.%d-%" PRIu64, taosSafeRand(), GetCurrentProcessId());
|
||||
#else
|
||||
char pipeName[PATH_MAX] = {0};
|
||||
snprintf(pipeName, sizeof(pipeName), "%s%spipe.trans.rpc.%08d-%" PRIu64, tsTempDir, TD_DIRSEP, taosSafeRand(),
|
||||
taosGetSelfPthreadId());
|
||||
#endif
|
||||
// char pipeName[PATH_MAX] = {0};
|
||||
// snprintf(pipeName, sizeof(pipeName), "%s%spipe.trans.rpc.%08d-%" PRIu64, tsTempDir, TD_DIRSEP, taosSafeRand(),
|
||||
// taosGetSelfPthreadId());
|
||||
|
||||
ret = uv_pipe_bind(&srv->pipeListen, pipeName);
|
||||
if (ret != 0) {
|
||||
tError("failed to bind pipe, errmsg: %s", uv_err_name(ret));
|
||||
|
@ -997,6 +1013,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
|||
if (false == addHandleToWorkloop(thrd, pipeName)) {
|
||||
goto End;
|
||||
}
|
||||
|
||||
int err = taosThreadCreate(&(thrd->thread), NULL, transWorkerThread, (void*)(thrd));
|
||||
if (err == 0) {
|
||||
tDebug("success to create worker-thread:%d", i);
|
||||
|
@ -1006,14 +1023,54 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
|||
goto End;
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
for (int i = 0; i < srv->numOfThreads; i++) {
|
||||
SWorkThrd* thrd = (SWorkThrd*)taosMemoryCalloc(1, sizeof(SWorkThrd));
|
||||
|
||||
thrd->pTransInst = shandle;
|
||||
thrd->quit = false;
|
||||
thrd->pTransInst = shandle;
|
||||
|
||||
srv->pipe[i] = (uv_pipe_t*)taosMemoryCalloc(2, sizeof(uv_pipe_t));
|
||||
srv->pThreadObj[i] = thrd;
|
||||
|
||||
uv_os_sock_t fds[2];
|
||||
if (uv_socketpair(AF_UNIX, SOCK_STREAM, fds, UV_NONBLOCK_PIPE, UV_NONBLOCK_PIPE) != 0) {
|
||||
goto End;
|
||||
}
|
||||
|
||||
uv_pipe_init(srv->loop, &(srv->pipe[i][0]), 1);
|
||||
uv_pipe_open(&(srv->pipe[i][0]), fds[1]);
|
||||
|
||||
thrd->pipe = &(srv->pipe[i][1]); // init read
|
||||
thrd->fd = fds[0];
|
||||
|
||||
if (false == addHandleToWorkloop(thrd, pipeName)) {
|
||||
goto End;
|
||||
}
|
||||
|
||||
int err = taosThreadCreate(&(thrd->thread), NULL, transWorkerThread, (void*)(thrd));
|
||||
if (err == 0) {
|
||||
tDebug("success to create worker-thread:%d", i);
|
||||
} else {
|
||||
// TODO: clear all other resource later
|
||||
tError("failed to create worker-thread:%d", i);
|
||||
goto End;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
if (false == taosValidIpAndPort(srv->ip, srv->port)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
tError("invalid ip/port, %d:%d, reason:%s", srv->ip, srv->port, terrstr());
|
||||
goto End;
|
||||
}
|
||||
|
||||
if (false == addHandleToAcceptloop(srv)) {
|
||||
goto End;
|
||||
}
|
||||
|
||||
int err = taosThreadCreate(&srv->thread, NULL, transAcceptThread, (void*)srv);
|
||||
if (err == 0) {
|
||||
tDebug("success to create accept-thread");
|
||||
|
@ -1022,6 +1079,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
|||
goto End;
|
||||
// clear all resource later
|
||||
}
|
||||
|
||||
srv->inited = true;
|
||||
return srv;
|
||||
End:
|
||||
|
|
|
@ -191,7 +191,7 @@ int32_t taosRenameFile(const char *oldName, const char *newName) {
|
|||
printf("failed to rename file %s to %s, reason:%s\n", oldName, newName, strerror(errno));
|
||||
}
|
||||
|
||||
return !code;
|
||||
return code ? 0 : -1;
|
||||
#else
|
||||
int32_t code = rename(oldName, newName);
|
||||
if (code < 0) {
|
||||
|
|
|
@ -371,6 +371,7 @@ int32_t tsDecompressBoolImp(const char *const input, const int32_t nelements, ch
|
|||
return nelements;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* Run Length Encoding(RLE) Method */
|
||||
int32_t tsCompressBoolRLEImp(const char *const input, const int32_t nelements, char *const output) {
|
||||
int32_t _pos = 0;
|
||||
|
@ -419,6 +420,7 @@ int32_t tsDecompressBoolRLEImp(const char *const input, const int32_t nelements,
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ----------------------------------------------String Compression
|
||||
* ---------------------------------------------- */
|
||||
|
@ -2274,6 +2276,9 @@ int32_t tsCompressBool(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t
|
|||
return tsCompressBoolImp(pIn, nEle, pOut);
|
||||
} else if (cmprAlg == TWO_STAGE_COMP) {
|
||||
int32_t len = tsCompressBoolImp(pIn, nEle, pBuf);
|
||||
if (len < 0) {
|
||||
return -1;
|
||||
}
|
||||
return tsCompressStringImp(pBuf, len, pOut, nOut);
|
||||
} else {
|
||||
assert(0);
|
||||
|
|
|
@ -183,6 +183,7 @@ void tdigestAdd(TDigest *t, double x, int64_t w) {
|
|||
if (t->num_buffered_pts >= t->threshold) tdigestCompress(t);
|
||||
}
|
||||
|
||||
#if 0
|
||||
double tdigestCDF(TDigest *t, double x) {
|
||||
if (t == NULL) return 0;
|
||||
|
||||
|
@ -233,6 +234,7 @@ double tdigestCDF(TDigest *t, double x) {
|
|||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
double tdigestQuantile(TDigest *t, double q) {
|
||||
if (t == NULL) return 0;
|
||||
|
@ -263,7 +265,7 @@ double tdigestQuantile(TDigest *t, double q) {
|
|||
b = c;
|
||||
right = (b->weight * a->mean + a->weight * b->mean) / (a->weight + b->weight);
|
||||
if (idx < weight_so_far + a->weight) {
|
||||
double p = (idx - weight_so_far) / a->weight;
|
||||
double p = (idx - weight_so_far) / ((a->weight == 0) ? 1 : a->weight);
|
||||
return left * (1 - p) + right * p;
|
||||
}
|
||||
weight_so_far += a->weight;
|
||||
|
|
|
@ -109,7 +109,7 @@ void tEndEncode(SEncoder* pCoder) {
|
|||
pCoder->size = pNode->size;
|
||||
pCoder->pos = pNode->pos;
|
||||
|
||||
tEncodeI32(pCoder, len);
|
||||
(void)tEncodeI32(pCoder, len);
|
||||
|
||||
TD_CODER_MOVE_POS(pCoder, len);
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ int32_t taosEnvNameToCfgName(const char *envNameStr, char *cfgNameStr, int32_t c
|
|||
}
|
||||
|
||||
int32_t taosEnvToCfg(const char *envStr, char *cfgStr) {
|
||||
if (envStr == NULL && cfgStr == NULL) {
|
||||
if (envStr == NULL || cfgStr == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (cfgStr != envStr) strcpy(cfgStr, envStr);
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "tfunctional.h"
|
||||
|
||||
FORCE_INLINE void* genericInvoke(tGenericSavedFunc* const pSavedFunc) { return pSavedFunc->func(pSavedFunc->args); }
|
||||
|
||||
#if 0
|
||||
tGenericSavedFunc* genericSavedFuncInit(GenericVaFunc func, int32_t numOfArgs) {
|
||||
tGenericSavedFunc* pSavedFunc = taosMemoryMalloc(sizeof(tGenericSavedFunc) + numOfArgs * (sizeof(void*)));
|
||||
if (pSavedFunc == NULL) return NULL;
|
||||
|
@ -37,10 +40,9 @@ tVoidSavedFunc* voidSavedFuncInit(VoidVaFunc func, int32_t numOfArgs) {
|
|||
return pSavedFunc;
|
||||
}
|
||||
|
||||
FORCE_INLINE void* genericInvoke(tGenericSavedFunc* const pSavedFunc) { return pSavedFunc->func(pSavedFunc->args); }
|
||||
|
||||
FORCE_INLINE int32_t i32Invoke(tI32SavedFunc* const pSavedFunc) { return pSavedFunc->func(pSavedFunc->args); }
|
||||
|
||||
FORCE_INLINE void voidInvoke(tVoidSavedFunc* const pSavedFunc) {
|
||||
if (pSavedFunc) pSavedFunc->func(pSavedFunc->args);
|
||||
}
|
||||
#endif
|
|
@ -639,7 +639,7 @@ void taosHashTableResize(SHashObj *pHashObj) {
|
|||
}
|
||||
|
||||
int64_t st = taosGetTimestampUs();
|
||||
void *pNewEntryList = taosMemoryRealloc(pHashObj->hashList, sizeof(void *) * newCapacity);
|
||||
SHashEntry **pNewEntryList = taosMemoryRealloc(pHashObj->hashList, sizeof(SHashEntry *) * newCapacity);
|
||||
if (pNewEntryList == NULL) {
|
||||
// uDebug("cache resize failed due to out of memory, capacity remain:%zu", pHashObj->capacity);
|
||||
return;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue