Merge branch '3.0' of https://github.com/taosdata/TDengine into fix/TD-30967
This commit is contained in:
commit
0497224fe7
|
@ -401,7 +401,7 @@ pipeline {
|
|||
}
|
||||
}
|
||||
stage('linux test') {
|
||||
agent{label " slave1_47 || slave1_48 || slave1_49 || slave1_50 || slave1_52 || slave1_59 || slave1_63 || worker03 || slave215 || slave217 || slave219 "}
|
||||
agent{label "slave1_47 || slave1_48 || slave1_49 || slave1_50 || slave1_52 || worker03 || slave215 || slave217 || slave219 "}
|
||||
options { skipDefaultCheckout() }
|
||||
when {
|
||||
changeRequest()
|
||||
|
|
|
@ -49,6 +49,7 @@ table_option: {
|
|||
7. Escape character "\`" can be used to avoid the conflict between table names and reserved keywords, above rules will be bypassed when using escape character on table names, but the upper limit for the name length is still valid. The table names specified using escape character are case sensitive.
|
||||
For example \`aBc\` and \`abc\` are different table names but `abc` and `aBc` are same table names because they are both converted to `abc` internally.
|
||||
Only ASCII visible characters can be used with escape character.
|
||||
8. For the details of using `ENCODE` and `COMPRESS`, please refer to [Encode and Compress for Column](../compress).
|
||||
|
||||
**Parameter description**
|
||||
|
||||
|
|
|
@ -13,17 +13,29 @@ create_definition:
|
|||
col_name column_definition
|
||||
|
||||
column_definition:
|
||||
type_name
|
||||
type_name [comment 'string_value'] [PRIMARY KEY] [ENCODE 'encode_type'] [COMPRESS 'compress_type'] [LEVEL 'level_type']
|
||||
|
||||
table_options:
|
||||
table_option ...
|
||||
|
||||
table_option: {
|
||||
COMMENT 'string_value'
|
||||
| SMA(col_name [, col_name] ...)
|
||||
| TTL value
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
**More explanations**
|
||||
- Each supertable can have a maximum of 4096 columns, including tags. The minimum number of columns is 3: a timestamp column used as the key, one tag column, and one data column.
|
||||
- The TAGS keyword defines the tag columns for the supertable. The following restrictions apply to tag columns:
|
||||
1. Each supertable can have a maximum of 4096 columns, including tags. The minimum number of columns is 3: a timestamp column used as the key, one tag column, and one data column.
|
||||
2. Since version 3.3.0.0, besides the timestamp, you can specify another column as primary key using `PRIMARY KEY` keyword, the column specified using `primary key` must be type of integer or varchar.
|
||||
2. The TAGS keyword defines the tag columns for the supertable. The following restrictions apply to tag columns:
|
||||
- A tag column can use the TIMESTAMP data type, but the values in the column must be fixed numbers. Timestamps including formulae, such as "now + 10s", cannot be stored in a tag column.
|
||||
- The name of a tag column cannot be the same as the name of any other column.
|
||||
- The name of a tag column cannot be a reserved keyword.
|
||||
- Each supertable must contain between 1 and 128 tags. The total length of the TAGS keyword cannot exceed 16 KB.
|
||||
- For more information about table parameters, see Create a Table.
|
||||
3. Regarding how to use `ENCODE` and `COMPRESS`, please refer to [Encode and Compress for Column](../compress).
|
||||
3. For more information about table parameters, see [Create a Table](../table).
|
||||
|
||||
## View a Supertable
|
||||
|
||||
|
|
|
@ -729,6 +729,57 @@ The charset that takes effect is UTF-8.
|
|||
| Value Range | -1: none message is compressed; 0: all messages are compressed; N (N>0): messages exceeding N bytes are compressed |
|
||||
| Default | -1 |
|
||||
|
||||
### fPrecision
|
||||
|
||||
| Attribute | Description |
|
||||
| -------- | -------------------------------- |
|
||||
| Application | Server Only |
|
||||
| Meaning | Compression precision for float data type |
|
||||
| Value Range | 0.1 ~ 0.00000001 |
|
||||
| Default | 0.00000001 |
|
||||
| Note | The floating value below this setting will be cut off |
|
||||
|
||||
### dPrecision
|
||||
|
||||
| Attribute | Description |
|
||||
| -------- | -------------------------------- |
|
||||
| Applicable | Server Only |
|
||||
| Meaning | Compression precision for double data type |
|
||||
| Value Range | 0.1 ~ 0.0000000000000001 |
|
||||
| Default | 0.0000000000000001 |
|
||||
| Note | The floating value below this setting will be cut off |
|
||||
|
||||
### lossyColumn
|
||||
|
||||
| Attribute | Description |
|
||||
| -------- | -------------------------------- |
|
||||
| Applicable | Server Only |
|
||||
| Meaning | Enable TSZ lossy compression for float and/or double |
|
||||
| Value Range | float, double |
|
||||
| Default | none: disable TSZ lossy compression |
|
||||
|
||||
**补充说明**
|
||||
1. It's only available since 3.2.0.0 version, and can't downgrade to previous version once upgrading to 3.2.0.0 and enabling this parameter
|
||||
2. TSZ compression algorithm compresses data based on data prediction technique, so it's more suitable for data with specific pattern
|
||||
3. TSZ compression algorithm may take longer time but it has better compression ratio, so it's suitable when you have enough CPU resources and are more sensitive to disk occupation
|
||||
4. Example: enable TSZ for both float and double
|
||||
```shell
|
||||
lossyColumns float|double
|
||||
```
|
||||
5. After configuring, taosd service needs to restarted. After restarting, if you see the following output in taosd logfile, it means the function has been enabled
|
||||
```sql
|
||||
02/22 10:49:27.607990 00002933 UTL lossyColumns float|double
|
||||
```
|
||||
|
||||
### ifAdtFse
|
||||
|
||||
| Attribute | Description |
|
||||
| -------- | -------------------------------- |
|
||||
| Applicable | Server Only |
|
||||
| Meaning | Replace HUFFMAN with FSE in TSZ, FSE is faster when compressing but slower when uncompressing |
|
||||
| Value Range | 0: Use HUFFMAN, 1: Use FSE |
|
||||
| Default | 0: Use HUFFMAN |
|
||||
|
||||
|
||||
## Other Parameters
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ table_option: {
|
|||
6. 使用数据类型 BINARY/NCHAR/GEOMETRY,需指定其最长的字节数,如 BINARY(20),表示 20 字节。
|
||||
7. 为了兼容支持更多形式的表名,TDengine 引入新的转义符 "\`",可以让表名与关键词不冲突,同时不受限于上述表名称合法性约束检查。但是同样具有长度限制要求。使用转义字符以后,不再对转义字符中的内容进行大小写统一,
|
||||
例如:\`aBc\` 和 \`abc\` 是不同的表名,但是 abc 和 aBc 是相同的表名。
|
||||
8. 关于 `ENCODE` 和 `COMPRESS` 的使用,请参考[按列压缩](../compress)
|
||||
|
||||
**参数说明**
|
||||
|
||||
|
|
|
@ -13,17 +13,28 @@ create_definition:
|
|||
col_name column_definition
|
||||
|
||||
column_definition:
|
||||
type_name
|
||||
type_name [comment 'string_value'] [PRIMARY KEY] [ENCODE 'encode_type'] [COMPRESS 'compress_type'] [LEVEL 'level_type']
|
||||
|
||||
table_options:
|
||||
table_option ...
|
||||
|
||||
table_option: {
|
||||
COMMENT 'string_value'
|
||||
| SMA(col_name [, col_name] ...)
|
||||
| TTL value
|
||||
}
|
||||
```
|
||||
|
||||
**使用说明**
|
||||
- 超级表中列的最大个数为 4096,需要注意,这里的 4096 是包含 TAG 列在内的,最小个数为 3,包含一个时间戳主键、一个 TAG 列和一个数据列。
|
||||
- TAGS语法指定超级表的标签列,标签列需要遵循以下约定:
|
||||
1. 超级表中列的最大个数为 4096,需要注意,这里的 4096 是包含 TAG 列在内的,最小个数为 3,包含一个时间戳主键、一个 TAG 列和一个数据列。
|
||||
2. 除时间戳主键列之外,还可以通过 PRIMARY KEY 关键字指定第二列为额外的主键列。被指定为主键列的第二列必须为整型或字符串类型(varchar)
|
||||
3. TAGS语法指定超级表的标签列,标签列需要遵循以下约定:
|
||||
- TAGS 中的 TIMESTAMP 列写入数据时需要提供给定值,而暂不支持四则运算,例如 NOW + 10s 这类表达式。
|
||||
- TAGS 列名不能与其他列名相同。
|
||||
- TAGS 列名不能为预留关键字。
|
||||
- TAGS 最多允许 128 个,至少 1 个,总长度不超过 16 KB。
|
||||
- 关于表参数的详细说明,参见 CREATE TABLE 中的介绍。
|
||||
4. 关于 `ENCODE` 和 `COMPRESS` 的使用,请参考 [按列压缩](../compress)
|
||||
5. 关于 table_option 中的参数说明,请参考 [建表 SQL 说明](../table)
|
||||
|
||||
## 查看超级表
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
---
|
||||
title: 可配置压缩算法
|
||||
sidebar_label: 可配置压缩
|
||||
description: 可配置压缩算法
|
||||
---
|
||||
|
|
@ -784,6 +784,57 @@ charset 的有效值是 UTF-8。
|
|||
| 取值范围 | -1: 所有消息都不压缩; 0: 所有消息都压缩; N (N>0): 只有大于 N 个字节的消息才压缩 |
|
||||
| 缺省值 | -1 |
|
||||
|
||||
### fPrecision
|
||||
FLOAT 类型压缩精度控制:
|
||||
|
||||
| 属性 | 说明 |
|
||||
| -------- | -------------------------------- |
|
||||
| 适用范围 | 服务器端 |
|
||||
| 含义 | 设置 float 类型浮点数压缩精度 |
|
||||
| 取值范围 | 0.1 ~ 0.00000001 |
|
||||
| 缺省值 | 0.00000001 |
|
||||
| 补充说明 | 小于此值的浮点数尾数部分将被截取 |
|
||||
|
||||
### dPrecision
|
||||
| 属性 | 说明 |
|
||||
| -------- | -------------------------------- |
|
||||
| 适用范围 | 服务器端 |
|
||||
| 含义 | 设置 double 类型浮点数压缩精度 |
|
||||
| 取值范围 | 0.1 ~ 0.0000000000000001 |
|
||||
| 缺省值 | 0.0000000000000001 |
|
||||
| 补充说明 | 小于此值的浮点数尾数部分将被截取 |
|
||||
|
||||
### lossyColumn
|
||||
|
||||
| 属性 | 说明 |
|
||||
| -------- | -------------------------------- |
|
||||
| 适用范围 | 服务器端 |
|
||||
| 含义 | 对 float 和/或 double 类型启用 TSZ 有损压缩 |
|
||||
| 取值范围 | float, double |
|
||||
| 缺省值 | none:表示关闭无损压缩 |
|
||||
|
||||
**补充说明**
|
||||
1. 在 3.2.0.0 ~ 3.3.0.0(不包含)版本生效,启用该参数后不能回退到升级前的版本
|
||||
2. TSZ 压缩算法是通过数据预测技术完成的压缩,所以更适合有规律变化的数据
|
||||
3. TSZ 压缩时间会更长一些,如果您的服务器 CPU 空闲多,存储空间小的情况下适合选用
|
||||
4. 示例:对 float 和 double 类型都启用有损压缩
|
||||
```shell
|
||||
lossyColumns float|double
|
||||
```
|
||||
5. 配置需重启服务生效,重启如果在 taosd 日志中看到以下内容,表明配置已生效:
|
||||
```sql
|
||||
02/22 10:49:27.607990 00002933 UTL lossyColumns float|double
|
||||
```
|
||||
|
||||
### ifAdtFse
|
||||
|
||||
| 属性 | 说明 |
|
||||
| -------- | -------------------------------- |
|
||||
| 适用范围 | 服务器端 |
|
||||
| 含义 | 在启用 TSZ 有损压缩时,使用 FSE 算法替换 HUFFMAN 算法, FSE 算法压缩速度更快,但解压稍慢,追求压缩速度可选用此算法 |
|
||||
| 取值范围 | 0:关闭 1:打开 |
|
||||
| 缺省值 | 0:关闭 |
|
||||
|
||||
## 3.0 中有效的配置参数列表
|
||||
|
||||
| # | **参数** | **适用于 2.X ** | **适用于 3.0 ** | 3.0 版本的当前行为 |
|
||||
|
@ -922,8 +973,5 @@ charset 的有效值是 UTF-8。
|
|||
| 73 | probeSeconds | 是 | 否 | 3.0 行为未知 |
|
||||
| 74 | probeKillSeconds | 是 | 否 | 3.0 行为未知 |
|
||||
| 75 | probeInterval | 是 | 否 | 3.0 行为未知 |
|
||||
| 76 | lossyColumns | 是 | 否 | 3.0 行为未知 |
|
||||
| 77 | fPrecision | 是 | 否 | 3.0 行为未知 |
|
||||
| 78 | dPrecision | 是 | 否 | 3.0 行为未知 |
|
||||
| 79 | maxRange | 是 | 否 | 3.0 行为未知 |
|
||||
| 80 | range | 是 | 否 | 3.0 行为未知 |
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
---
|
||||
title: TSZ 压缩算法
|
||||
description: TDengine 对浮点数进行高效压缩的算法
|
||||
---
|
||||
|
||||
TSZ 压缩算法是 TDengine 为浮点数据类型提供的可选压缩算法,可以实现浮点数有损至无损全状态压缩,相比默认压缩算法, TSZ 压缩算法压缩率更高,即使切至无损状态,压缩率也会比默认压缩高一倍。
|
||||
|
||||
## 适合场景
|
||||
|
||||
- TSZ 压缩算法是通过数据预测技术完成的压缩,所以更适合有规律变化的数据
|
||||
- TSZ 压缩时间会更长一些,如果您的服务器 CPU 空闲多,存储空间小的情况下适合选用
|
||||
|
||||
## 使用步骤
|
||||
- TDengine 支持版本为 3.2.0.0 或以上
|
||||
- 开启选项
|
||||
在 taos.cfg 配置中增加以下内容,即可开启 TSZ 压缩算法,功能打开后,会替换默认算法。
|
||||
以下表示字段类型是 float 及 double 类型都使用此压缩算法,也可以单独只配置一个
|
||||
|
||||
```sql
|
||||
lossyColumns float|double
|
||||
```
|
||||
|
||||
- 配置需重启服务生效
|
||||
- Taosd 日志输出以下内容,表明功能已生效:
|
||||
|
||||
```sql
|
||||
02/22 10:49:27.607990 00002933 UTL lossyColumns float|double
|
||||
```
|
||||
|
||||
## 配置参数
|
||||
|
||||
### fPrecision
|
||||
FLOAT 类型精度控制:
|
||||
|
||||
| 属性 | 说明 |
|
||||
| -------- | -------------------------------- |
|
||||
| 适用范围 | 服务器端 |
|
||||
| 含义 | 设置 float 类型浮点数压缩精度 |
|
||||
| 取值范围 | 0.1 ~ 0.00000001 |
|
||||
| 缺省值 | 0.00000001 |
|
||||
| 补充说明 | 小于此值的浮点数尾数部分将被截取 |
|
||||
|
||||
|
||||
|
||||
### dPrecision
|
||||
DOUBLE 类型精度控制:
|
||||
|
||||
| 属性 | 说明 |
|
||||
| -------- | -------------------------------- |
|
||||
| 适用范围 | 服务器端 |
|
||||
| 含义 | 设置 double 类型浮点数压缩精度 |
|
||||
| 取值范围 | 0.1 ~ 0.0000000000000001 |
|
||||
| 缺省值 | 0.0000000000000001 |
|
||||
| 补充说明 | 小于此值的浮点数尾数部分将被截取 |
|
||||
|
||||
|
||||
### ifAdtFse
|
||||
TSZ 压缩中可选择的算法 FSE,默认为 HUFFMAN:
|
||||
|
||||
| 属性 | 说明 |
|
||||
| -------- | -------------------------------- |
|
||||
| 适用范围 | 服务器端 |
|
||||
| 含义 | 使用 FSE 算法替换 HUFFMAN 算法, FSE 算法压缩速度更快,但解压稍慢,追求压缩速度可选用此算法 |
|
||||
| 取值范围 | 0:关闭 1:打开 |
|
||||
| 缺省值 | 0:关闭 |
|
||||
|
||||
|
||||
## 注意事项
|
||||
- 打开 TSZ 后生成的存储数据格式,回退至 3.2.0.0 之前的版本,数据将不能被识别
|
|
@ -163,8 +163,8 @@ int rawBlockBindData(SQuery *query, STableMeta* pTableMeta, void* data, SVCr
|
|||
int numFields, bool needChangeLength, char* errstr, int32_t errstrLen);
|
||||
|
||||
int32_t rewriteToVnodeModifyOpStmt(SQuery* pQuery, SArray* pBufArray);
|
||||
SArray* serializeVgroupsCreateTableBatch(SHashObj* pVgroupHashmap);
|
||||
SArray* serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap);
|
||||
int32_t serializeVgroupsCreateTableBatch(SHashObj* pVgroupHashmap, SArray** pOut);
|
||||
int32_t serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap, SArray** pOut);
|
||||
void destoryCatalogReq(SCatalogReq *pCatalogReq);
|
||||
bool isPrimaryKeyImpl(SNode* pExpr);
|
||||
int32_t insAppendStmtTableDataCxt(SHashObj* pAllVgHash, STableColsData* pTbData, STableDataCxt* pTbCtx, SStbInterlaceInfo* pBuildInfo);
|
||||
|
|
|
@ -237,6 +237,8 @@ typedef struct {
|
|||
int64_t stbUid;
|
||||
char stbFullName[TSDB_TABLE_FNAME_LEN];
|
||||
SSchemaWrapper* pSchemaWrapper;
|
||||
SSchemaWrapper* pTagSchema;
|
||||
bool autoCreateCtb;
|
||||
void* vnode; // not available to encoder and decoder
|
||||
FTbSink* tbSinkFunc;
|
||||
STSchema* pTSchema;
|
||||
|
|
|
@ -32,9 +32,9 @@ extern "C" {
|
|||
#define TSWAP(a, b) \
|
||||
do { \
|
||||
char *__tmp = (char*)alloca(sizeof(a)); \
|
||||
memcpy(__tmp, &(a), sizeof(a)); \
|
||||
memcpy(&(a), &(b), sizeof(a)); \
|
||||
memcpy(&(b), __tmp, sizeof(a)); \
|
||||
(void)memcpy(__tmp, &(a), sizeof(a)); \
|
||||
(void)memcpy(&(a), &(b), sizeof(a)); \
|
||||
(void)memcpy(&(b), __tmp, sizeof(a)); \
|
||||
} while (0)
|
||||
|
||||
#ifdef WINDOWS
|
||||
|
|
|
@ -54,6 +54,7 @@ void taosMemoryTrim(int32_t size);
|
|||
void *taosMemoryMallocAlign(uint32_t alignment, int64_t size);
|
||||
|
||||
#define TAOS_MEMSET(_s, _c, _n) ((void)memset(_s, _c, _n))
|
||||
#define TAOS_MEMCPY(_d, _s, _n) ((void)memcpy(_d, _s, _n))
|
||||
|
||||
#define taosMemoryFreeClear(ptr) \
|
||||
do { \
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "taoserror.h"
|
||||
#include "tcoding.h"
|
||||
#include "tutil.h"
|
||||
|
||||
struct SBuffer {
|
||||
uint32_t size;
|
||||
|
@ -67,8 +68,7 @@ static FORCE_INLINE int32_t tBufferEnsureCapacity(SBuffer *buffer, uint32_t capa
|
|||
}
|
||||
|
||||
static FORCE_INLINE int32_t tBufferPut(SBuffer *buffer, const void *data, uint32_t size) {
|
||||
int32_t code = tBufferEnsureCapacity(buffer, buffer->size + size);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferEnsureCapacity(buffer, buffer->size + size));
|
||||
memcpy((char *)buffer->data + buffer->size, data, size);
|
||||
buffer->size += size;
|
||||
return 0;
|
||||
|
@ -119,10 +119,8 @@ static FORCE_INLINE int32_t tBufferPutU16v(SBuffer *buffer, uint16_t value) { re
|
|||
static FORCE_INLINE int32_t tBufferPutU32v(SBuffer *buffer, uint32_t value) { return tBufferPutU64v(buffer, value); }
|
||||
|
||||
static FORCE_INLINE int32_t tBufferPutU64v(SBuffer *buffer, uint64_t value) {
|
||||
int32_t code;
|
||||
while (value >= 0x80) {
|
||||
code = tBufferPutU8(buffer, (value & 0x7F) | 0x80);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferPutU8(buffer, (value & 0x7F) | 0x80));
|
||||
value >>= 7;
|
||||
}
|
||||
return tBufferPutU8(buffer, value);
|
||||
|
@ -141,8 +139,7 @@ static FORCE_INLINE int32_t tBufferPutI64v(SBuffer *buffer, int64_t value) {
|
|||
}
|
||||
|
||||
static FORCE_INLINE int32_t tBufferPutBinary(SBuffer *buffer, const void *data, uint32_t size) {
|
||||
int32_t code = tBufferPutU32v(buffer, size);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferPutU32v(buffer, size));
|
||||
return tBufferPut(buffer, data, size);
|
||||
}
|
||||
|
||||
|
@ -324,8 +321,7 @@ static int32_t tBufferGetF32(SBufferReader *reader, float *value) {
|
|||
float f;
|
||||
uint32_t u;
|
||||
} u;
|
||||
int32_t code = tBufferGetU32(reader, &u.u);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetU32(reader, &u.u));
|
||||
if (value) {
|
||||
*value = u.f;
|
||||
}
|
||||
|
@ -337,8 +333,7 @@ static int32_t tBufferGetF64(SBufferReader *reader, double *value) {
|
|||
double f;
|
||||
uint64_t u;
|
||||
} u;
|
||||
int32_t code = tBufferGetU64(reader, &u.u);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetU64(reader, &u.u));
|
||||
if (value) {
|
||||
*value = u.f;
|
||||
}
|
||||
|
|
|
@ -73,10 +73,10 @@ struct STaosQnode {
|
|||
char item[];
|
||||
};
|
||||
|
||||
STaosQueue *taosOpenQueue();
|
||||
int32_t taosOpenQueue(STaosQueue **queue);
|
||||
void taosCloseQueue(STaosQueue *queue);
|
||||
void taosSetQueueFp(STaosQueue *queue, FItem itemFp, FItems itemsFp);
|
||||
void *taosAllocateQitem(int32_t size, EQItype itype, int64_t dataSize);
|
||||
int32_t taosAllocateQitem(int32_t size, EQItype itype, int64_t dataSize, void **item);
|
||||
void taosFreeQitem(void *pItem);
|
||||
int32_t taosWriteQitem(STaosQueue *queue, void *pItem);
|
||||
int32_t taosReadQitem(STaosQueue *queue, void **ppItem);
|
||||
|
@ -87,7 +87,7 @@ int64_t taosQueueMemorySize(STaosQueue *queue);
|
|||
void taosSetQueueCapacity(STaosQueue *queue, int64_t size);
|
||||
void taosSetQueueMemoryCapacity(STaosQueue *queue, int64_t mem);
|
||||
|
||||
STaosQall *taosAllocateQall();
|
||||
int32_t taosAllocateQall(STaosQall **qall);
|
||||
void taosFreeQall(STaosQall *qall);
|
||||
int32_t taosReadAllQitems(STaosQueue *queue, STaosQall *qall);
|
||||
int32_t taosGetQitem(STaosQall *qall, void **ppItem);
|
||||
|
@ -97,7 +97,7 @@ int64_t taosQallMemSize(STaosQall *qll);
|
|||
int64_t taosQallUnAccessedItemSize(STaosQall *qall);
|
||||
int64_t taosQallUnAccessedMemSize(STaosQall *qall);
|
||||
|
||||
STaosQset *taosOpenQset();
|
||||
int32_t taosOpenQset(STaosQset **qset);
|
||||
void taosCloseQset(STaosQset *qset);
|
||||
void taosQsetThreadResume(STaosQset *qset);
|
||||
int32_t taosAddIntoQset(STaosQset *qset, STaosQueue *queue, void *ahandle);
|
||||
|
|
|
@ -172,6 +172,8 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
#define TAOS_UNUSED(expr) (void)(expr)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#include "clientMonitor.h"
|
||||
#include "clientLog.h"
|
||||
#include "os.h"
|
||||
#include "tmisce.h"
|
||||
#include "ttime.h"
|
||||
#include "ttimer.h"
|
||||
#include "tglobal.h"
|
||||
#include "tqueue.h"
|
||||
#include "cJSON.h"
|
||||
#include "clientInt.h"
|
||||
#include "clientLog.h"
|
||||
#include "os.h"
|
||||
#include "tglobal.h"
|
||||
#include "tmisce.h"
|
||||
#include "tqueue.h"
|
||||
#include "ttime.h"
|
||||
#include "ttimer.h"
|
||||
|
||||
SRWLatch monitorLock;
|
||||
void* monitorTimer;
|
||||
|
@ -116,8 +116,12 @@ static int32_t monitorReportAsyncCB(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
if (code != 0) {
|
||||
tscError("failed to send slow log:%s, clusterId:%" PRIx64, p->data, p->clusterId);
|
||||
}
|
||||
MonitorSlowLogData tmp = {.clusterId = p->clusterId, .type = p->type, .fileName = p->fileName,
|
||||
.pFile= p->pFile, .offset = p->offset, .data = NULL};
|
||||
MonitorSlowLogData tmp = {.clusterId = p->clusterId,
|
||||
.type = p->type,
|
||||
.fileName = p->fileName,
|
||||
.pFile = p->pFile,
|
||||
.offset = p->offset,
|
||||
.data = NULL};
|
||||
if (monitorPutData2MonitorQueue(tmp) == 0) {
|
||||
p->fileName = NULL;
|
||||
}
|
||||
|
@ -247,7 +251,8 @@ void monitorCreateClient(int64_t clusterId) {
|
|||
}
|
||||
|
||||
taos_collector_registry_register_collector(pMonitor->registry, pMonitor->colector);
|
||||
pMonitor->counters = (SHashObj*)taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
pMonitor->counters =
|
||||
(SHashObj*)taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
if (pMonitor->counters == NULL) {
|
||||
tscError("failed to create monitor counters");
|
||||
goto fail;
|
||||
|
@ -265,7 +270,8 @@ void monitorCreateClient(int64_t clusterId) {
|
|||
pMonitor = NULL;
|
||||
goto fail;
|
||||
}
|
||||
pMonitor->timer = taosTmrStart(reportSendProcess, pInst->monitorParas.tsMonitorInterval * 1000, (void*)pMonitor, monitorTimer);
|
||||
pMonitor->timer =
|
||||
taosTmrStart(reportSendProcess, pInst->monitorParas.tsMonitorInterval * 1000, (void*)pMonitor, monitorTimer);
|
||||
if (pMonitor->timer == NULL) {
|
||||
tscError("failed to start timer");
|
||||
goto fail;
|
||||
|
@ -283,7 +289,8 @@ fail:
|
|||
taosWUnLockLatch(&monitorLock);
|
||||
}
|
||||
|
||||
void monitorCreateClientCounter(int64_t clusterId, const char* name, const char* help, size_t label_key_count, const char** label_keys) {
|
||||
void monitorCreateClientCounter(int64_t clusterId, const char* name, const char* help, size_t label_key_count,
|
||||
const char** label_keys) {
|
||||
taosWLockLatch(&monitorLock);
|
||||
MonitorClient** ppMonitor = (MonitorClient**)taosHashGet(monitorCounterHash, &clusterId, LONG_BYTES);
|
||||
if (ppMonitor == NULL || *ppMonitor == NULL) {
|
||||
|
@ -291,8 +298,7 @@ void monitorCreateClientCounter(int64_t clusterId, const char* name, const char*
|
|||
goto end;
|
||||
}
|
||||
taos_counter_t* newCounter = taos_counter_new(name, help, label_key_count, label_keys);
|
||||
if (newCounter == NULL)
|
||||
return;
|
||||
if (newCounter == NULL) return;
|
||||
MonitorClient* pMonitor = *ppMonitor;
|
||||
taos_collector_add_metric(pMonitor->colector, newCounter);
|
||||
if (taosHashPut(pMonitor->counters, name, strlen(name), &newCounter, POINTER_BYTES) != 0) {
|
||||
|
@ -300,7 +306,8 @@ void monitorCreateClientCounter(int64_t clusterId, const char* name, const char*
|
|||
taos_counter_destroy(newCounter);
|
||||
goto end;
|
||||
}
|
||||
tscInfo("[monitor] monitorCreateClientCounter %"PRIx64"(%p):%s : %p.", pMonitor->clusterId, pMonitor, name, newCounter);
|
||||
tscInfo("[monitor] monitorCreateClientCounter %" PRIx64 "(%p):%s : %p.", pMonitor->clusterId, pMonitor, name,
|
||||
newCounter);
|
||||
|
||||
end:
|
||||
taosWUnLockLatch(&monitorLock);
|
||||
|
@ -453,7 +460,8 @@ static int64_t getFileSize(char* path){
|
|||
return fileSize;
|
||||
}
|
||||
|
||||
static int32_t sendSlowLog(int64_t clusterId, char* data, TdFilePtr pFile, int64_t offset, SLOW_LOG_QUEUE_TYPE type, char* fileName, void* pTransporter, SEpSet *epSet){
|
||||
static int32_t sendSlowLog(int64_t clusterId, char* data, TdFilePtr pFile, int64_t offset, SLOW_LOG_QUEUE_TYPE type,
|
||||
char* fileName, void* pTransporter, SEpSet* epSet) {
|
||||
if (data == NULL) {
|
||||
taosMemoryFree(fileName);
|
||||
return -1;
|
||||
|
@ -473,7 +481,8 @@ static int32_t sendSlowLog(int64_t clusterId, char* data, TdFilePtr pFile, int64
|
|||
return sendReport(pTransporter, epSet, data, MONITOR_TYPE_SLOW_LOG, pParam);
|
||||
}
|
||||
|
||||
static int32_t monitorReadSend(int64_t clusterId, TdFilePtr pFile, int64_t* offset, int64_t size, SLOW_LOG_QUEUE_TYPE type, char* fileName){
|
||||
static int32_t monitorReadSend(int64_t clusterId, TdFilePtr pFile, int64_t* offset, int64_t size,
|
||||
SLOW_LOG_QUEUE_TYPE type, char* fileName) {
|
||||
SAppInstInfo* pInst = getAppInstByClusterId(clusterId);
|
||||
if (pInst == NULL) {
|
||||
tscError("failed to get app instance by clusterId:%" PRId64, clusterId);
|
||||
|
@ -481,7 +490,8 @@ static int32_t monitorReadSend(int64_t clusterId, TdFilePtr pFile, int64_t* offs
|
|||
}
|
||||
SEpSet ep = getEpSet_s(&pInst->mgmtEp);
|
||||
char* data = readFile(pFile, offset, size);
|
||||
return sendSlowLog(clusterId, data, (type == SLOW_LOG_READ_BEGINNIG ? pFile : NULL), *offset, type, fileName, pInst->pTransporter, &ep);
|
||||
return sendSlowLog(clusterId, data, (type == SLOW_LOG_READ_BEGINNIG ? pFile : NULL), *offset, type, fileName,
|
||||
pInst->pTransporter, &ep);
|
||||
}
|
||||
|
||||
static void monitorSendSlowLogAtBeginning(int64_t clusterId, char** fileName, TdFilePtr pFile, int64_t offset) {
|
||||
|
@ -567,7 +577,8 @@ static void processFileRemoved(SlowLogClient* pClient){
|
|||
taosUnLockFile(pClient->pFile);
|
||||
taosCloseFile(&(pClient->pFile));
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(pClient->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND | TD_FILE_READ | TD_FILE_TRUNC);
|
||||
TdFilePtr pFile =
|
||||
taosOpenFile(pClient->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND | TD_FILE_READ | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
tscError("failed to open file:%s since %s", pClient->path, terrstr());
|
||||
|
@ -640,9 +651,7 @@ static void monitorSendAllSlowLogFromTempDir(int64_t clusterId){
|
|||
}
|
||||
|
||||
char* name = taosGetDirEntryName(de);
|
||||
if (strcmp(name, ".") == 0 ||
|
||||
strcmp(name, "..") == 0 ||
|
||||
strstr(name, namePrefix) == NULL) {
|
||||
if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0 || strstr(name, namePrefix) == NULL) {
|
||||
tscInfo("skip file:%s, for cluster id:%" PRIx64, name, clusterId);
|
||||
continue;
|
||||
}
|
||||
|
@ -702,7 +711,8 @@ static void* monitorThreadFunc(void *param){
|
|||
if (slowLogData != NULL) {
|
||||
if (slowLogData->type == SLOW_LOG_READ_BEGINNIG) {
|
||||
if (slowLogData->pFile != NULL) {
|
||||
monitorSendSlowLogAtBeginning(slowLogData->clusterId, &(slowLogData->fileName), slowLogData->pFile, slowLogData->offset);
|
||||
monitorSendSlowLogAtBeginning(slowLogData->clusterId, &(slowLogData->fileName), slowLogData->pFile,
|
||||
slowLogData->offset);
|
||||
} else {
|
||||
monitorSendAllSlowLogFromTempDir(slowLogData->clusterId);
|
||||
}
|
||||
|
@ -757,8 +767,11 @@ static void tscMonitorStop() {
|
|||
}
|
||||
|
||||
int32_t monitorInit() {
|
||||
int32_t code;
|
||||
|
||||
tscInfo("[monitor] tscMonitor init");
|
||||
monitorCounterHash = (SHashObj*)taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
|
||||
monitorCounterHash =
|
||||
(SHashObj*)taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
|
||||
if (monitorCounterHash == NULL) {
|
||||
tscError("failed to create monitorCounterHash");
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -766,7 +779,8 @@ int32_t monitorInit() {
|
|||
}
|
||||
taosHashSetFreeFp(monitorCounterHash, destroyMonitorClient);
|
||||
|
||||
monitorSlowLogHash = (SHashObj*)taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
|
||||
monitorSlowLogHash =
|
||||
(SHashObj*)taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
|
||||
if (monitorSlowLogHash == NULL) {
|
||||
tscError("failed to create monitorSlowLogHash");
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -798,8 +812,9 @@ int32_t monitorInit() {
|
|||
return -1;
|
||||
}
|
||||
|
||||
monitorQueue = taosOpenQueue();
|
||||
if(monitorQueue == NULL){
|
||||
code = taosOpenQueue(&monitorQueue);
|
||||
if (code) {
|
||||
terrno = code;
|
||||
tscError("open queue error since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
@ -829,17 +844,22 @@ void monitorClose() {
|
|||
}
|
||||
|
||||
int32_t monitorPutData2MonitorQueue(MonitorSlowLogData data) {
|
||||
int32_t code;
|
||||
MonitorSlowLogData* slowLogData;
|
||||
|
||||
if (atomic_load_32(&slowLogFlag) == -2) {
|
||||
tscError("[monitor] slow log thread is exiting");
|
||||
return -1;
|
||||
}
|
||||
MonitorSlowLogData* slowLogData = taosAllocateQitem(sizeof(MonitorSlowLogData), DEF_QITEM, 0);
|
||||
if (slowLogData == NULL) {
|
||||
|
||||
code = taosAllocateQitem(sizeof(MonitorSlowLogData), DEF_QITEM, 0, (void**)&slowLogData);
|
||||
if (code) {
|
||||
tscError("[monitor] failed to allocate slow log data");
|
||||
return -1;
|
||||
return terrno = code;
|
||||
}
|
||||
*slowLogData = data;
|
||||
tscDebug("[monitor] write slow log to queue, clusterId:%"PRIx64 " type:%s, data:%s", slowLogData->clusterId, queueTypeStr[slowLogData->type], slowLogData->data);
|
||||
tscDebug("[monitor] write slow log to queue, clusterId:%" PRIx64 " type:%s, data:%s", slowLogData->clusterId,
|
||||
queueTypeStr[slowLogData->type], slowLogData->data);
|
||||
if (taosWriteQitem(monitorQueue, slowLogData) == 0) {
|
||||
tsem2_post(&monitorSem);
|
||||
} else {
|
||||
|
|
|
@ -1116,9 +1116,9 @@ static int32_t taosCreateTable(TAOS* taos, void* meta, int32_t metaLen) {
|
|||
if (taosHashGetSize(pVgroupHashmap) == 0) {
|
||||
goto end;
|
||||
}
|
||||
SArray* pBufArray = serializeVgroupsCreateTableBatch(pVgroupHashmap);
|
||||
if (NULL == pBufArray) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SArray* pBufArray = NULL;
|
||||
code = serializeVgroupsCreateTableBatch(pVgroupHashmap, &pBufArray);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
@ -1264,9 +1264,9 @@ static int32_t taosDropTable(TAOS* taos, void* meta, int32_t metaLen) {
|
|||
if (taosHashGetSize(pVgroupHashmap) == 0) {
|
||||
goto end;
|
||||
}
|
||||
SArray* pBufArray = serializeVgroupsDropTableBatch(pVgroupHashmap);
|
||||
if (NULL == pBufArray) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SArray* pBufArray = NULL;
|
||||
code = serializeVgroupsDropTableBatch(pVgroupHashmap, &pBufArray);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
|
|
@ -733,11 +733,15 @@ end:
|
|||
}
|
||||
|
||||
static void generateTimedTask(int64_t refId, int32_t type) {
|
||||
tmq_t* tmq = taosAcquireRef(tmqMgmt.rsetId, refId);
|
||||
tmq_t* tmq;
|
||||
int8_t* pTaskType;
|
||||
int32_t code;
|
||||
|
||||
tmq = taosAcquireRef(tmqMgmt.rsetId, refId);
|
||||
if (tmq == NULL) return;
|
||||
|
||||
int8_t* pTaskType = taosAllocateQitem(sizeof(int8_t), DEF_QITEM, 0);
|
||||
if (pTaskType != NULL){
|
||||
code = taosAllocateQitem(sizeof(int8_t), DEF_QITEM, 0, (void**)&pTaskType);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
*pTaskType = type;
|
||||
if (taosWriteQitem(tmq->delayedTask, pTaskType) == 0) {
|
||||
tsem2_post(&tmq->rspSem);
|
||||
|
@ -890,7 +894,12 @@ static void defaultCommitCbFn(tmq_t* pTmq, int32_t code, void* param) {
|
|||
}
|
||||
|
||||
int32_t tmqHandleAllDelayedTask(tmq_t* pTmq) {
|
||||
STaosQall* qall = taosAllocateQall();
|
||||
STaosQall* qall;
|
||||
int32_t code;
|
||||
|
||||
code = taosAllocateQall(&qall);
|
||||
if (code) return code;
|
||||
|
||||
taosReadAllQitems(pTmq->delayedTask, qall);
|
||||
|
||||
int32_t numOfItems = taosQallItemSize(qall);
|
||||
|
@ -914,7 +923,8 @@ int32_t tmqHandleAllDelayedTask(tmq_t* pTmq) {
|
|||
asyncCommitAllOffsets(pTmq, pCallbackFn, pTmq->commitCbUserParam);
|
||||
tscDebug("consumer:0x%" PRIx64 " next commit to vnode(s) in %.2fs", pTmq->consumerId,
|
||||
pTmq->autoCommitInterval / 1000.0);
|
||||
taosTmrReset(tmqAssignDelayedCommitTask, pTmq->autoCommitInterval, (void*)(pTmq->refId), tmqMgmt.timer, &pTmq->commitTimer);
|
||||
taosTmrReset(tmqAssignDelayedCommitTask, pTmq->autoCommitInterval, (void*)(pTmq->refId), tmqMgmt.timer,
|
||||
&pTmq->commitTimer);
|
||||
} else {
|
||||
tscError("consumer:0x%" PRIx64 " invalid task type:%d", pTmq->consumerId, *pTaskType);
|
||||
}
|
||||
|
@ -1101,6 +1111,8 @@ void tmqMgmtClose(void) {
|
|||
if (errstr != NULL) snprintf(errstr, errstrLen, MSG);
|
||||
|
||||
tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
|
||||
int32_t code;
|
||||
|
||||
if (conf == NULL) {
|
||||
SET_ERROR_MSG_TMQ("configure is null")
|
||||
return NULL;
|
||||
|
@ -1124,12 +1136,31 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
|
|||
const char* pass = conf->pass == NULL ? TSDB_DEFAULT_PASS : conf->pass;
|
||||
|
||||
pTmq->clientTopics = taosArrayInit(0, sizeof(SMqClientTopic));
|
||||
pTmq->mqueue = taosOpenQueue();
|
||||
pTmq->delayedTask = taosOpenQueue();
|
||||
pTmq->qall = taosAllocateQall();
|
||||
code = taosOpenQueue(&pTmq->mqueue);
|
||||
if (code) {
|
||||
terrno = code;
|
||||
tscError("consumer:0x%" PRIx64 " setup failed since %s, groupId:%s", pTmq->consumerId, terrstr(), pTmq->groupId);
|
||||
SET_ERROR_MSG_TMQ("open queue failed")
|
||||
goto _failed;
|
||||
}
|
||||
|
||||
if (pTmq->clientTopics == NULL || pTmq->mqueue == NULL || pTmq->qall == NULL || pTmq->delayedTask == NULL ||
|
||||
conf->groupId[0] == 0) {
|
||||
code = taosOpenQueue(&pTmq->delayedTask);
|
||||
if (code) {
|
||||
terrno = code;
|
||||
tscError("consumer:0x%" PRIx64 " setup failed since %s, groupId:%s", pTmq->consumerId, terrstr(), pTmq->groupId);
|
||||
SET_ERROR_MSG_TMQ("open delayed task queue failed")
|
||||
goto _failed;
|
||||
}
|
||||
|
||||
code = taosAllocateQall(&pTmq->qall);
|
||||
if (code) {
|
||||
terrno = code;
|
||||
tscError("consumer:0x%" PRIx64 " setup failed since %s, groupId:%s", pTmq->consumerId, terrstr(), pTmq->groupId);
|
||||
SET_ERROR_MSG_TMQ("allocate qall failed")
|
||||
goto _failed;
|
||||
}
|
||||
|
||||
if (conf->groupId[0] == 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tscError("consumer:0x%" PRIx64 " setup failed since %s, groupId:%s", pTmq->consumerId, terrstr(), pTmq->groupId);
|
||||
SET_ERROR_MSG_TMQ("malloc tmq element failed or group is empty")
|
||||
|
@ -1315,7 +1346,8 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
|
|||
// init ep timer
|
||||
tmq->epTimer = taosTmrStart(tmqAssignAskEpTask, DEFAULT_ASKEP_INTERVAL, (void*)(tmq->refId), tmqMgmt.timer);
|
||||
// init auto commit timer
|
||||
tmq->commitTimer = taosTmrStart(tmqAssignDelayedCommitTask, tmq->autoCommitInterval, (void*)(tmq->refId), tmqMgmt.timer);
|
||||
tmq->commitTimer =
|
||||
taosTmrStart(tmqAssignDelayedCommitTask, tmq->autoCommitInterval, (void*)(tmq->refId), tmqMgmt.timer);
|
||||
|
||||
FAIL:
|
||||
taosArrayDestroyP(req.topicNames, taosMemoryFree);
|
||||
|
@ -1381,11 +1413,11 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
goto FAIL;
|
||||
}
|
||||
|
||||
SMqPollRspWrapper* pRspWrapper = taosAllocateQitem(sizeof(SMqPollRspWrapper), DEF_QITEM, 0);
|
||||
if (pRspWrapper == NULL) {
|
||||
SMqPollRspWrapper* pRspWrapper;
|
||||
code = taosAllocateQitem(sizeof(SMqPollRspWrapper), DEF_QITEM, 0, (void**)&pRspWrapper);
|
||||
if (code) {
|
||||
tscWarn("consumer:0x%" PRIx64 " msg discard from vgId:%d, since out of memory", tmq->consumerId, vgId);
|
||||
taosReleaseRef(tmqMgmt.rsetId, refId);
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
|
@ -2600,9 +2632,9 @@ int32_t askEpCb(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
doUpdateLocalEp(tmq, head->epoch, &rsp);
|
||||
tDeleteSMqAskEpRsp(&rsp);
|
||||
} else {
|
||||
SMqAskEpRspWrapper* pWrapper = taosAllocateQitem(sizeof(SMqAskEpRspWrapper), DEF_QITEM, 0);
|
||||
if (pWrapper == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SMqAskEpRspWrapper* pWrapper;
|
||||
code = taosAllocateQitem(sizeof(SMqAskEpRspWrapper), DEF_QITEM, 0, (void**)&pWrapper);
|
||||
if (code) {
|
||||
goto END;
|
||||
}
|
||||
|
||||
|
|
|
@ -504,7 +504,7 @@ static int32_t taosAddClientCfg(SConfig *pCfg) {
|
|||
if (cfgAddString(pCfg, "secondEp", "", CFG_SCOPE_BOTH, CFG_DYN_CLIENT) != 0) return -1;
|
||||
if (cfgAddString(pCfg, "fqdn", defaultFqdn, CFG_SCOPE_SERVER, CFG_DYN_CLIENT) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "serverPort", defaultServerPort, 1, 65056, CFG_SCOPE_SERVER, CFG_DYN_CLIENT) != 0) return -1;
|
||||
if (cfgAddDir(pCfg, "tempDir", tsTempDir, CFG_SCOPE_BOTH, CFG_DYN_CLIENT) != 0) return -1;
|
||||
if (cfgAddDir(pCfg, "tempDir", tsTempDir, CFG_SCOPE_BOTH, CFG_DYN_NONE) != 0) return -1;
|
||||
if (cfgAddFloat(pCfg, "minimalTmpDirGB", 1.0f, 0.001f, 10000000, CFG_SCOPE_BOTH, CFG_DYN_CLIENT) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "shellActivityTimer", tsShellActivityTimer, 1, 120, CFG_SCOPE_BOTH, CFG_DYN_CLIENT) != 0)
|
||||
return -1;
|
||||
|
|
|
@ -98,7 +98,7 @@ SName* toName(int32_t acctId, const char* pDbName, const char* pTableName, SName
|
|||
int32_t tNameExtractFullName(const SName* name, char* dst) {
|
||||
// invalid full name format, abort
|
||||
if (!tNameIsValid(name)) {
|
||||
return -1;
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
||||
int32_t len = snprintf(dst, TSDB_DB_FNAME_LEN, "%d.%s", name->acctId, name->dbname);
|
||||
|
@ -154,8 +154,7 @@ int32_t tNameGetDbName(const SName* name, char* dst) {
|
|||
const char* tNameGetDbNameP(const SName* name) { return &name->dbname[0]; }
|
||||
|
||||
int32_t tNameGetFullDbName(const SName* name, char* dst) {
|
||||
snprintf(dst, TSDB_DB_FNAME_LEN, "%d.%s", name->acctId, name->dbname);
|
||||
return 0;
|
||||
return snprintf(dst, TSDB_DB_FNAME_LEN, "%d.%s", name->acctId, name->dbname);
|
||||
}
|
||||
|
||||
bool tNameIsEmpty(const SName* name) { return name->type == 0 || name->acctId == 0; }
|
||||
|
|
|
@ -153,6 +153,8 @@ int32_t mmPutMsgToFetchQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
int32_t mmPutMsgToQueue(SMnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||
int32_t code;
|
||||
|
||||
SSingleWorker *pWorker = NULL;
|
||||
switch (qtype) {
|
||||
case WRITE_QUEUE:
|
||||
|
@ -181,13 +183,15 @@ int32_t mmPutMsgToQueue(SMnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
|||
}
|
||||
|
||||
if (pWorker == NULL) return -1;
|
||||
SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM, pRpc->contLen);
|
||||
if (pMsg == NULL) return -1;
|
||||
SRpcMsg *pMsg;
|
||||
code = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM, pRpc->contLen, (void **)&pMsg);
|
||||
if (code) return code;
|
||||
memcpy(pMsg, pRpc, sizeof(SRpcMsg));
|
||||
pRpc->pCont = NULL;
|
||||
|
||||
dTrace("msg:%p, is created and will put into %s queue, type:%s len:%d", pMsg, pWorker->name, TMSG_INFO(pRpc->msgType), pRpc->contLen);
|
||||
int32_t code = mmPutMsgToWorker(pMgmt, pWorker, pMsg);
|
||||
dTrace("msg:%p, is created and will put into %s queue, type:%s len:%d", pMsg, pWorker->name, TMSG_INFO(pRpc->msgType),
|
||||
pRpc->contLen);
|
||||
code = mmPutMsgToWorker(pMgmt, pWorker, pMsg);
|
||||
if (code != 0) {
|
||||
dTrace("msg:%p, is freed", pMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
|
|
@ -58,8 +58,11 @@ int32_t qmPutNodeMsgToFetchQueue(SQnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
int32_t qmPutRpcMsgToQueue(SQnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||
SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM, pRpc->contLen);
|
||||
if (pMsg == NULL) return -1;
|
||||
int32_t code;
|
||||
SRpcMsg *pMsg;
|
||||
|
||||
code = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM, pRpc->contLen, (void **)&pMsg);
|
||||
if (code) return code;
|
||||
memcpy(pMsg, pRpc, sizeof(SRpcMsg));
|
||||
pRpc->pCont = NULL;
|
||||
|
||||
|
|
|
@ -126,8 +126,11 @@ void smStopWorker(SSnodeMgmt *pMgmt) {
|
|||
}
|
||||
|
||||
int32_t smPutMsgToQueue(SSnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||
SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM, pRpc->contLen);
|
||||
if (pMsg == NULL) {
|
||||
int32_t code;
|
||||
SRpcMsg *pMsg;
|
||||
|
||||
code = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM, pRpc->contLen, (void **)&pMsg);
|
||||
if (code) {
|
||||
rpcFreeCont(pRpc->pCont);
|
||||
pRpc->pCont = NULL;
|
||||
return -1;
|
||||
|
|
|
@ -311,6 +311,7 @@ int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||
int32_t code;
|
||||
if (pRpc->contLen < sizeof(SMsgHead)) {
|
||||
dError("invalid rpc msg with no msg head at pCont. pRpc:%p, type:%s, len:%d", pRpc, TMSG_INFO(pRpc->msgType),
|
||||
pRpc->contLen);
|
||||
|
@ -320,8 +321,9 @@ int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
|||
}
|
||||
|
||||
EQItype itype = APPLY_QUEUE == qtype ? DEF_QITEM : RPC_QITEM;
|
||||
SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen);
|
||||
if (pMsg == NULL) {
|
||||
SRpcMsg *pMsg;
|
||||
code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
|
||||
if (code) {
|
||||
rpcFreeCont(pRpc->pCont);
|
||||
pRpc->pCont = NULL;
|
||||
return -1;
|
||||
|
@ -335,7 +337,7 @@ int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
|||
memcpy(pMsg, pRpc, sizeof(SRpcMsg));
|
||||
pRpc->pCont = NULL;
|
||||
|
||||
int32_t code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
|
||||
code = vmPutMsgToQueue(pMgmt, pMsg, qtype);
|
||||
if (code != 0) {
|
||||
dTrace("msg:%p, is freed", pMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
|
|
@ -210,8 +210,8 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
|||
pRpc->info.wrapper = pWrapper;
|
||||
|
||||
EQItype itype = IsReq(pRpc) ? RPC_QITEM : DEF_QITEM; // rsp msg is not restricted by tsRpcQueueMemoryUsed
|
||||
pMsg = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen);
|
||||
if (pMsg == NULL) goto _OVER;
|
||||
code = taosAllocateQitem(sizeof(SRpcMsg), itype, pRpc->contLen, (void **)&pMsg);
|
||||
if (code) goto _OVER;
|
||||
|
||||
memcpy(pMsg, pRpc, sizeof(SRpcMsg));
|
||||
dGTrace("msg:%p, is created, type:%s handle:%p len:%d", pMsg, TMSG_INFO(pRpc->msgType), pMsg->info.handle,
|
||||
|
|
|
@ -54,6 +54,7 @@ int32_t mndInitAcct(SMnode *pMnode) {
|
|||
void mndCleanupAcct(SMnode *pMnode) {}
|
||||
|
||||
static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
|
||||
int32_t code = 0;
|
||||
SAcctObj acctObj = {0};
|
||||
tstrncpy(acctObj.acct, TSDB_DEFAULT_USER, TSDB_USER_LEN);
|
||||
acctObj.createdTime = taosGetTimestampMs();
|
||||
|
@ -76,7 +77,10 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
|
|||
};
|
||||
|
||||
SSdbRaw *pRaw = mndAcctActionEncode(&acctObj);
|
||||
if (pRaw == NULL) return -1;
|
||||
if (pRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
mInfo("acct:%s, will be created when deploying, raw:%p", acctObj.acct, pRaw);
|
||||
|
@ -84,21 +88,24 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
|
|||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "create-acct");
|
||||
if (pTrans == NULL) {
|
||||
sdbFreeRaw(pRaw);
|
||||
mError("acct:%s, failed to create since %s", acctObj.acct, terrstr());
|
||||
return -1;
|
||||
code = terrno;
|
||||
mError("acct:%s, failed to create since %s", acctObj.acct, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
mInfo("trans:%d, used to create acct:%s", pTrans->id, acctObj.acct);
|
||||
|
||||
if (mndTransAppendCommitlog(pTrans, pRaw) != 0) {
|
||||
mError("trans:%d, failed to commit redo log since %s", pTrans->id, terrstr());
|
||||
code = mndTransAppendCommitlog(pTrans, pRaw);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to commit redo log since %s", pTrans->id, tstrerror(code));
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
code = mndTransPrepare(pMnode, pTrans);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, tstrerror(code));
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
mndTransDrop(pTrans);
|
||||
|
@ -216,31 +223,36 @@ static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOld, SAcctObj *pNew) {
|
|||
}
|
||||
|
||||
static int32_t mndProcessCreateAcctReq(SRpcMsg *pReq) {
|
||||
if (mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_CREATE_ACCT) != 0) {
|
||||
return -1;
|
||||
int32_t code = 0;
|
||||
code = mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_CREATE_ACCT);
|
||||
if (code != 0) {
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
terrno = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
mError("failed to process create acct request since %s", terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
mError("failed to process create acct request since %s", tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndProcessAlterAcctReq(SRpcMsg *pReq) {
|
||||
if (mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_ALTER_ACCT) != 0) {
|
||||
return -1;
|
||||
int32_t code = 0;
|
||||
code = mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_ALTER_ACCT);
|
||||
if (code != 0) {
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
terrno = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
mError("failed to process create acct request since %s", terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
mError("failed to process create acct request since %s", tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropAcctReq(SRpcMsg *pReq) {
|
||||
if (mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_DROP_ACCT) != 0) {
|
||||
return -1;
|
||||
int32_t code = 0;
|
||||
if ((code = mndCheckOperPrivilege(pReq->info.node, pReq->info.conn.user, MND_OPER_DROP_ACCT)) != 0) {
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
terrno = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
mError("failed to process create acct request since %s", terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
mError("failed to process create acct request since %s", tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
|
@ -57,6 +57,7 @@ static int32_t mndArbCheckToken(const char *token1, const char *token2) {
|
|||
}
|
||||
|
||||
int32_t mndInitArbGroup(SMnode *pMnode) {
|
||||
int32_t code = 0;
|
||||
SSdbTable table = {
|
||||
.sdbType = SDB_ARBGROUP,
|
||||
.keyType = SDB_KEY_INT32,
|
||||
|
@ -78,6 +79,10 @@ int32_t mndInitArbGroup(SMnode *pMnode) {
|
|||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_ARBGROUP, mndCancelGetNextArbGroup);
|
||||
|
||||
arbUpdateHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK);
|
||||
if (arbUpdateHash == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return sdbSetTable(pMnode->pSdb, table);
|
||||
}
|
||||
|
@ -248,50 +253,74 @@ _OVER:
|
|||
}
|
||||
|
||||
int32_t mndSetCreateArbGroupRedoLogs(STrans *pTrans, SArbGroup *pGroup) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pRedoRaw = mndArbGroupActionEncode(pGroup);
|
||||
if (pRedoRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1;
|
||||
if (pRedoRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if ((code = mndTransAppendRedolog(pTrans, pRedoRaw)) != 0) TAOS_RETURN(code);
|
||||
if ((code = sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING)) != 0) TAOS_RETURN(code);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndSetCreateArbGroupUndoLogs(STrans *pTrans, SArbGroup *pGroup) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pUndoRaw = mndArbGroupActionEncode(pGroup);
|
||||
if (pUndoRaw == NULL) return -1;
|
||||
if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||
if (pUndoRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if ((code = mndTransAppendUndolog(pTrans, pUndoRaw)) != 0) TAOS_RETURN(code);
|
||||
if ((code = sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED)) != 0) TAOS_RETURN(code);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndSetCreateArbGroupCommitLogs(STrans *pTrans, SArbGroup *pGroup) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pCommitRaw = mndArbGroupActionEncode(pGroup);
|
||||
if (pCommitRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1;
|
||||
if (pCommitRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw) != 0)) TAOS_RETURN(code);
|
||||
if ((code = sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY)) != 0) TAOS_RETURN(code);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndSetDropArbGroupPrepareLogs(STrans *pTrans, SArbGroup *pGroup) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pRedoRaw = mndArbGroupActionEncode(pGroup);
|
||||
if (pRedoRaw == NULL) return -1;
|
||||
if (mndTransAppendPrepareLog(pTrans, pRedoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1;
|
||||
if (pRedoRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if ((code = mndTransAppendPrepareLog(pTrans, pRedoRaw)) != 0) TAOS_RETURN(code);
|
||||
if ((code = sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING)) != 0) TAOS_RETURN(code);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetDropArbGroupRedoLogs(STrans *pTrans, SArbGroup *pGroup) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pRedoRaw = mndArbGroupActionEncode(pGroup);
|
||||
if (pRedoRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1;
|
||||
if (pRedoRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if ((code = mndTransAppendRedolog(pTrans, pRedoRaw)) != 0) TAOS_RETURN(code);
|
||||
if ((code = sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING)) != 0) TAOS_RETURN(code);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndSetDropArbGroupCommitLogs(STrans *pTrans, SArbGroup *pGroup) {
|
||||
int32_t code = 0;
|
||||
SSdbRaw *pCommitRaw = mndArbGroupActionEncode(pGroup);
|
||||
if (pCommitRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||
if (pCommitRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) TAOS_RETURN(code);
|
||||
if ((code = sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED)) != 0) TAOS_RETURN(code);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -343,6 +372,7 @@ static int32_t mndSendArbHeartBeatReq(SDnodeObj *pDnode, char *arbToken, int64_t
|
|||
}
|
||||
|
||||
static int32_t mndProcessArbHbTimer(SRpcMsg *pReq) {
|
||||
int32_t code = 0;
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SArbGroup *pArbGroup = NULL;
|
||||
|
@ -377,7 +407,7 @@ static int32_t mndProcessArbHbTimer(SRpcMsg *pReq) {
|
|||
}
|
||||
|
||||
char arbToken[TSDB_ARB_TOKEN_SIZE];
|
||||
if (mndGetArbToken(pMnode, arbToken) != 0) {
|
||||
if ((code = mndGetArbToken(pMnode, arbToken)) != 0) {
|
||||
mError("failed to get arb token for arb-hb timer");
|
||||
pIter = taosHashIterate(pDnodeHash, NULL);
|
||||
while (pIter) {
|
||||
|
@ -386,7 +416,7 @@ static int32_t mndProcessArbHbTimer(SRpcMsg *pReq) {
|
|||
pIter = taosHashIterate(pDnodeHash, pIter);
|
||||
}
|
||||
taosHashCleanup(pDnodeHash);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int64_t nowMs = taosGetTimestampMs();
|
||||
|
@ -447,6 +477,7 @@ static void *mndBuildArbCheckSyncReq(int32_t *pContLen, int32_t vgId, char *arbT
|
|||
|
||||
static int32_t mndSendArbCheckSyncReq(SMnode *pMnode, int32_t vgId, char *arbToken, int64_t term, char *member0Token,
|
||||
char *member1Token) {
|
||||
int32_t code = 0;
|
||||
int32_t contLen = 0;
|
||||
void *pHead = mndBuildArbCheckSyncReq(&contLen, vgId, arbToken, term, member0Token, member1Token);
|
||||
if (!pHead) {
|
||||
|
@ -459,10 +490,12 @@ static int32_t mndSendArbCheckSyncReq(SMnode *pMnode, int32_t vgId, char *arbTok
|
|||
if (epSet.numOfEps == 0) {
|
||||
mError("vgId:%d, failed to send check-sync request since no epSet found", vgId);
|
||||
rpcFreeCont(pHead);
|
||||
return -1;
|
||||
code = -1;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t code = tmsgSendReq(&epSet, &rpcMsg);
|
||||
code = tmsgSendReq(&epSet, &rpcMsg);
|
||||
if (code != 0) {
|
||||
mError("vgId:%d, failed to send check-sync request since 0x%x", vgId, code);
|
||||
} else {
|
||||
|
@ -502,11 +535,14 @@ static void *mndBuildArbSetAssignedLeaderReq(int32_t *pContLen, int32_t vgId, ch
|
|||
|
||||
static int32_t mndSendArbSetAssignedLeaderReq(SMnode *pMnode, int32_t dnodeId, int32_t vgId, char *arbToken,
|
||||
int64_t term, char *memberToken) {
|
||||
int32_t code = 0;
|
||||
int32_t contLen = 0;
|
||||
void *pHead = mndBuildArbSetAssignedLeaderReq(&contLen, vgId, arbToken, term, memberToken);
|
||||
if (!pHead) {
|
||||
mError("vgId:%d, failed to build set-assigned request", vgId);
|
||||
return -1;
|
||||
code = -1;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
SRpcMsg rpcMsg = {.msgType = TDMT_SYNC_SET_ASSIGNED_LEADER, .pCont = pHead, .contLen = contLen};
|
||||
|
||||
|
@ -514,9 +550,11 @@ static int32_t mndSendArbSetAssignedLeaderReq(SMnode *pMnode, int32_t dnodeId, i
|
|||
if (epSet.numOfEps == 0) {
|
||||
mError("dnodeId:%d vgId:%d, failed to send arb-set-assigned request to dnode since no epSet found", dnodeId, vgId);
|
||||
rpcFreeCont(pHead);
|
||||
return -1;
|
||||
code = -1;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
int32_t code = tmsgSendReq(&epSet, &rpcMsg);
|
||||
code = tmsgSendReq(&epSet, &rpcMsg);
|
||||
if (code != 0) {
|
||||
mError("dnodeId:%d vgId:%d, failed to send arb-set-assigned request to dnode since 0x%x", dnodeId, vgId, code);
|
||||
} else {
|
||||
|
@ -526,6 +564,7 @@ static int32_t mndSendArbSetAssignedLeaderReq(SMnode *pMnode, int32_t dnodeId, i
|
|||
}
|
||||
|
||||
static int32_t mndProcessArbCheckSyncTimer(SRpcMsg *pReq) {
|
||||
int32_t code = 0;
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SArbGroup *pArbGroup = NULL;
|
||||
|
@ -533,14 +572,16 @@ static int32_t mndProcessArbCheckSyncTimer(SRpcMsg *pReq) {
|
|||
void *pIter = NULL;
|
||||
|
||||
char arbToken[TSDB_ARB_TOKEN_SIZE];
|
||||
if (mndGetArbToken(pMnode, arbToken) != 0) {
|
||||
if ((code = mndGetArbToken(pMnode, arbToken)) != 0) {
|
||||
mError("failed to get arb token for arb-check-sync timer");
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
int64_t term = mndGetTerm(pMnode);
|
||||
if (term < 0) {
|
||||
mError("arb failed to get term since %s", terrstr());
|
||||
return -1;
|
||||
code = -1;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int64_t roleTimeMs = mndGetRoleTimeMs(pMnode);
|
||||
|
@ -747,13 +788,13 @@ _OVER:
|
|||
}
|
||||
|
||||
static int32_t mndProcessArbUpdateGroupBatchReq(SRpcMsg *pReq) {
|
||||
int ret = -1;
|
||||
int code = -1;
|
||||
size_t sz = 0;
|
||||
|
||||
SMArbUpdateGroupBatchReq req = {0};
|
||||
if (tDeserializeSMArbUpdateGroupBatchReq(pReq->pCont, pReq->contLen, &req) != 0) {
|
||||
if ((code = tDeserializeSMArbUpdateGroupBatchReq(pReq->pCont, pReq->contLen, &req)) != 0) {
|
||||
mError("arb failed to decode arb-update-group request");
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
|
@ -789,7 +830,7 @@ static int32_t mndProcessArbUpdateGroupBatchReq(SRpcMsg *pReq) {
|
|||
|
||||
mndTransAddArbGroupId(pTrans, newGroup.vgId);
|
||||
|
||||
if (mndSetCreateArbGroupCommitLogs(pTrans, &newGroup) != 0) {
|
||||
if ((code = mndSetCreateArbGroupCommitLogs(pTrans, &newGroup)) != 0) {
|
||||
mError("failed to update arbgroup in set commit log, vgId:%d, trans:%d, since %s", newGroup.vgId, pTrans->id,
|
||||
terrstr());
|
||||
goto _OVER;
|
||||
|
@ -803,13 +844,13 @@ static int32_t mndProcessArbUpdateGroupBatchReq(SRpcMsg *pReq) {
|
|||
sdbRelease(pMnode->pSdb, pOldGroup);
|
||||
}
|
||||
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
if ((code = mndTransCheckConflict(pMnode, pTrans)) != 0) goto _OVER;
|
||||
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER;
|
||||
|
||||
ret = 0;
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
if (ret != 0) {
|
||||
if (code != 0) {
|
||||
// failed to update arbgroup
|
||||
for (size_t i = 0; i < sz; i++) {
|
||||
SMArbUpdateGroup *pUpdateGroup = taosArrayGet(req.updateArray, i);
|
||||
|
@ -819,7 +860,7 @@ _OVER:
|
|||
|
||||
mndTransDrop(pTrans);
|
||||
tFreeSMArbUpdateGroupBatchReq(&req);
|
||||
return ret;
|
||||
return code;
|
||||
}
|
||||
|
||||
static void mndArbGroupDupObj(SArbGroup *pGroup, SArbGroup *pNew) {
|
||||
|
@ -841,10 +882,11 @@ static void mndArbGroupResetAssignedLeader(SArbGroup *pGroup) {
|
|||
}
|
||||
|
||||
static int32_t mndArbGroupUpdateTrans(SMnode *pMnode, SArbGroup *pNew) {
|
||||
int32_t ret = -1;
|
||||
int32_t code = -1;
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_ARBGROUP, NULL, "update-arbgroup");
|
||||
if (pTrans == NULL) {
|
||||
mError("failed to update arbgroup in create trans, vgId:%d, since %s", pNew->vgId, terrstr());
|
||||
if (terrno != 0) code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -854,23 +896,22 @@ static int32_t mndArbGroupUpdateTrans(SMnode *pMnode, SArbGroup *pNew) {
|
|||
pNew->assignedLeader.token, pNew->assignedLeader.acked);
|
||||
|
||||
mndTransAddArbGroupId(pTrans, pNew->vgId);
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) {
|
||||
ret = -1;
|
||||
if ((code = mndTransCheckConflict(pMnode, pTrans)) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndSetCreateArbGroupCommitLogs(pTrans, pNew) != 0) {
|
||||
mError("failed to update arbgroup in set commit log, vgId:%d, since %s", pNew->vgId, terrstr());
|
||||
if ((code = mndSetCreateArbGroupCommitLogs(pTrans, pNew)) != 0) {
|
||||
mError("failed to update arbgroup in set commit log, vgId:%d, since %s", pNew->vgId, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) goto _OVER;
|
||||
|
||||
ret = 0;
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
mndTransDrop(pTrans);
|
||||
return ret;
|
||||
return code;
|
||||
}
|
||||
|
||||
bool mndUpdateArbGroupByHeartBeat(SArbGroup *pGroup, SVArbHbRspMember *pRspMember, int64_t nowMs, int32_t dnodeId,
|
||||
|
@ -993,11 +1034,13 @@ _OVER:
|
|||
}
|
||||
|
||||
static int32_t mndUpdateArbSync(SMnode *pMnode, int32_t vgId, char *member0Token, char *member1Token, bool newIsSync) {
|
||||
int32_t code = 0;
|
||||
SArbGroup *pGroup = sdbAcquire(pMnode->pSdb, SDB_ARBGROUP, &vgId);
|
||||
if (pGroup == NULL) {
|
||||
terrno = TSDB_CODE_NOT_FOUND;
|
||||
mInfo("failed to update arb sync, vgId:%d not found", vgId);
|
||||
return -1;
|
||||
code = -1;
|
||||
if (terrno != 0) code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SArbGroup newGroup = {0};
|
||||
|
@ -1018,38 +1061,36 @@ static int32_t mndProcessArbHbRsp(SRpcMsg *pRsp) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t ret = -1;
|
||||
int32_t code = -1;
|
||||
|
||||
SMnode *pMnode = pRsp->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
char arbToken[TSDB_ARB_TOKEN_SIZE];
|
||||
if (mndGetArbToken(pMnode, arbToken) != 0) {
|
||||
if ((code = mndGetArbToken(pMnode, arbToken)) != 0) {
|
||||
mError("failed to get arb token for arb-hb response");
|
||||
terrno = TSDB_CODE_NOT_FOUND;
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SVArbHeartBeatRsp arbHbRsp = {0};
|
||||
if (tDeserializeSVArbHeartBeatRsp(pRsp->pCont, pRsp->contLen, &arbHbRsp) != 0) {
|
||||
if ((code = tDeserializeSVArbHeartBeatRsp(pRsp->pCont, pRsp->contLen, &arbHbRsp)) != 0) {
|
||||
mInfo("arb hb-rsp des failed, since:%s", tstrerror(pRsp->code));
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (mndArbCheckToken(arbToken, arbHbRsp.arbToken) != 0) {
|
||||
mInfo("arb hearbeat skip update for dnodeId:%d, arb token mismatch, local:[%s] msg:[%s]", arbHbRsp.dnodeId,
|
||||
arbToken, arbHbRsp.arbToken);
|
||||
terrno = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
|
||||
code = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
(void)mndUpdateArbHeartBeat(pMnode, arbHbRsp.dnodeId, arbHbRsp.hbMembers);
|
||||
ret = 0;
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
tFreeSVArbHeartBeatRsp(&arbHbRsp);
|
||||
return ret;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessArbCheckSyncRsp(SRpcMsg *pRsp) {
|
||||
|
@ -1058,27 +1099,25 @@ static int32_t mndProcessArbCheckSyncRsp(SRpcMsg *pRsp) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t ret = -1;
|
||||
int32_t code = -1;
|
||||
|
||||
SMnode *pMnode = pRsp->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
char arbToken[TSDB_ARB_TOKEN_SIZE];
|
||||
if (mndGetArbToken(pMnode, arbToken) != 0) {
|
||||
if ((code = mndGetArbToken(pMnode, arbToken)) != 0) {
|
||||
mError("failed to get arb token for arb-check-sync response");
|
||||
terrno = TSDB_CODE_NOT_FOUND;
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SVArbCheckSyncRsp syncRsp = {0};
|
||||
if (tDeserializeSVArbCheckSyncRsp(pRsp->pCont, pRsp->contLen, &syncRsp) != 0) {
|
||||
if ((code = tDeserializeSVArbCheckSyncRsp(pRsp->pCont, pRsp->contLen, &syncRsp)) != 0) {
|
||||
mInfo("arb check-sync-rsp des failed, since:%s", tstrerror(pRsp->code));
|
||||
if (pRsp->code == TSDB_CODE_MND_ARB_TOKEN_MISMATCH) {
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
return 0;
|
||||
}
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (mndArbCheckToken(arbToken, syncRsp.arbToken) != 0) {
|
||||
|
@ -1089,16 +1128,16 @@ static int32_t mndProcessArbCheckSyncRsp(SRpcMsg *pRsp) {
|
|||
}
|
||||
|
||||
bool newIsSync = (syncRsp.errCode == TSDB_CODE_SUCCESS);
|
||||
if (mndUpdateArbSync(pMnode, syncRsp.vgId, syncRsp.member0Token, syncRsp.member1Token, newIsSync) != 0) {
|
||||
if ((code = mndUpdateArbSync(pMnode, syncRsp.vgId, syncRsp.member0Token, syncRsp.member1Token, newIsSync)) != 0) {
|
||||
mInfo("failed to update arb sync for vgId:%d, since:%s", syncRsp.vgId, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
tFreeSVArbCheckSyncRsp(&syncRsp);
|
||||
return ret;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
bool mndUpdateArbGroupBySetAssignedLeader(SArbGroup *pGroup, int32_t vgId, char *memberToken, int32_t errcode,
|
||||
|
@ -1138,35 +1177,35 @@ static int32_t mndProcessArbSetAssignedLeaderRsp(SRpcMsg *pRsp) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t ret = -1;
|
||||
int32_t code = -1;
|
||||
|
||||
SMnode *pMnode = pRsp->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
char arbToken[TSDB_ARB_TOKEN_SIZE];
|
||||
if (mndGetArbToken(pMnode, arbToken) != 0) {
|
||||
if ((code = mndGetArbToken(pMnode, arbToken)) != 0) {
|
||||
mError("failed to get arb token for arb-set-assigned response");
|
||||
terrno = TSDB_CODE_NOT_FOUND;
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SVArbSetAssignedLeaderRsp setAssignedRsp = {0};
|
||||
if (tDeserializeSVArbSetAssignedLeaderRsp(pRsp->pCont, pRsp->contLen, &setAssignedRsp) != 0) {
|
||||
if ((code = tDeserializeSVArbSetAssignedLeaderRsp(pRsp->pCont, pRsp->contLen, &setAssignedRsp)) != 0) {
|
||||
mInfo("arb set-assigned-rsp des failed, since:%s", tstrerror(pRsp->code));
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (mndArbCheckToken(arbToken, setAssignedRsp.arbToken) != 0) {
|
||||
mInfo("skip update arb assigned for vgId:%d, arb token mismatch, local:[%s] msg:[%s]", setAssignedRsp.vgId,
|
||||
arbToken, setAssignedRsp.arbToken);
|
||||
terrno = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
|
||||
code = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
SArbGroup *pGroup = mndAcquireArbGroup(pMnode, setAssignedRsp.vgId);
|
||||
if (!pGroup) {
|
||||
mError("failed to set arb assigned for vgId:%d, since:%s", setAssignedRsp.vgId, terrstr());
|
||||
code = -1;
|
||||
if (terrno != 0) code = terrno;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -1174,17 +1213,17 @@ static int32_t mndProcessArbSetAssignedLeaderRsp(SRpcMsg *pRsp) {
|
|||
bool updateAssigned = mndUpdateArbGroupBySetAssignedLeader(pGroup, setAssignedRsp.vgId, setAssignedRsp.memberToken,
|
||||
pRsp->code, &newGroup);
|
||||
if (updateAssigned) {
|
||||
if (mndPullupArbUpdateGroup(pMnode, &newGroup) != 0) {
|
||||
mInfo("failed to pullup update arb assigned for vgId:%d, since:%s", setAssignedRsp.vgId, terrstr());
|
||||
if ((code = mndPullupArbUpdateGroup(pMnode, &newGroup)) != 0) {
|
||||
mInfo("failed to pullup update arb assigned for vgId:%d, since:%s", setAssignedRsp.vgId, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
tFreeSVArbSetAssignedLeaderRsp(&setAssignedRsp);
|
||||
return ret;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndRetrieveArbGroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "audit.h"
|
||||
#include "mndCluster.h"
|
||||
#include "audit.h"
|
||||
#include "mndGrant.h"
|
||||
#include "mndPrivilege.h"
|
||||
#include "mndShow.h"
|
||||
|
@ -61,11 +61,13 @@ int32_t mndInitCluster(SMnode *pMnode) {
|
|||
void mndCleanupCluster(SMnode *pMnode) {}
|
||||
|
||||
int32_t mndGetClusterName(SMnode *pMnode, char *clusterName, int32_t len) {
|
||||
int32_t code = 0;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
SClusterObj *pCluster = sdbAcquire(pSdb, SDB_CLUSTER, &pMnode->clusterId);
|
||||
if (pCluster == NULL) {
|
||||
return -1;
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
tstrncpy(clusterName, pCluster->name, len);
|
||||
|
@ -247,7 +249,10 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) {
|
|||
mInfo("cluster:%" PRId64 ", name is %s", clusterObj.id, clusterObj.name);
|
||||
|
||||
SSdbRaw *pRaw = mndClusterActionEncode(&clusterObj);
|
||||
if (pRaw == NULL) return -1;
|
||||
if (pRaw == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
mInfo("cluster:%" PRId64 ", will be created when deploying, raw:%p", clusterObj.id, pRaw);
|
||||
|
@ -256,21 +261,22 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) {
|
|||
if (pTrans == NULL) {
|
||||
sdbFreeRaw(pRaw);
|
||||
mError("cluster:%" PRId64 ", failed to create since %s", clusterObj.id, terrstr());
|
||||
return -1;
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
mInfo("trans:%d, used to create cluster:%" PRId64, pTrans->id, clusterObj.id);
|
||||
|
||||
if (mndTransAppendCommitlog(pTrans, pRaw) != 0) {
|
||||
if ((code = mndTransAppendCommitlog(pTrans, pRaw)) != 0) {
|
||||
mError("trans:%d, failed to commit redo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
mndTransDrop(pTrans);
|
||||
|
@ -347,22 +353,33 @@ static int32_t mndProcessUptimeTimer(SRpcMsg *pReq) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
mInfo("update cluster uptime to %d", clusterObj.upTime);
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq, "update-uptime");
|
||||
if (pTrans == NULL) return -1;
|
||||
if (pTrans == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
SSdbRaw *pCommitRaw = mndClusterActionEncode(&clusterObj);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
if (pCommitRaw == NULL) {
|
||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if ((code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
|
||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
mndTransDrop(pTrans);
|
||||
|
@ -374,13 +391,12 @@ int32_t mndProcessConfigClusterReq(SRpcMsg *pReq) {
|
|||
SMnode *pMnode = pReq->info.node;
|
||||
SMCfgClusterReq cfgReq = {0};
|
||||
if (tDeserializeSMCfgClusterReq(pReq->pCont, pReq->contLen, &cfgReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
mInfo("cluster: start to config, option:%s, value:%s", cfgReq.config, cfgReq.value);
|
||||
if (mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONFIG_CLUSTER) != 0) {
|
||||
code = terrno != 0 ? terrno : TSDB_CODE_MND_NO_RIGHTS;
|
||||
if ((code = mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONFIG_CLUSTER)) != 0) {
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
|
@ -410,17 +426,17 @@ int32_t mndProcessConfigClusterReq(SRpcMsg *pReq) {
|
|||
}
|
||||
|
||||
{ // audit
|
||||
auditRecord(pReq, pMnode->clusterId, "alterCluster", "", "", cfgReq.sql, TMIN(cfgReq.sqlLen, GRANT_ACTIVE_HEAD_LEN << 1));
|
||||
auditRecord(pReq, pMnode->clusterId, "alterCluster", "", "", cfgReq.sql,
|
||||
TMIN(cfgReq.sqlLen, GRANT_ACTIVE_HEAD_LEN << 1));
|
||||
}
|
||||
_exit:
|
||||
tFreeSMCfgClusterReq(&cfgReq);
|
||||
if (code != 0) {
|
||||
terrno = code;
|
||||
mError("cluster: failed to config:%s %s since %s", cfgReq.config, cfgReq.value, terrstr());
|
||||
} else {
|
||||
mInfo("cluster: success to config:%s %s", cfgReq.config, cfgReq.value);
|
||||
}
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t mndProcessConfigClusterRsp(SRpcMsg *pRsp) {
|
||||
|
|
|
@ -105,6 +105,7 @@ SArray *mndTakeVgroupSnapshot(SMnode *pMnode, bool *allReady) {
|
|||
mInfo("vgId:%d replica:%d inconsistent with other vgroups replica:%d, not ready for stream operations",
|
||||
pVgroup->vgId, pVgroup->replica, replica);
|
||||
*allReady = false;
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -399,32 +399,32 @@ TEST_F(MndTestSdb, 00_API) {
|
|||
SSdbRaw *pRaw2 = sdbAllocRaw(SDB_USER, 1, -128);
|
||||
ASSERT_EQ(pRaw2 == NULL, 1);
|
||||
|
||||
ASSERT_EQ(sdbSetRawInt8(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawInt8(pRaw1, -128, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawInt32(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawInt32(pRaw1, -128, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawInt16(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawInt16(pRaw1, -128, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawInt64(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawInt64(pRaw1, -128, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawBinary(NULL, 0, "12", 3), -1);
|
||||
ASSERT_EQ(sdbSetRawBinary(pRaw1, 9028, "12", 3), -1);
|
||||
ASSERT_EQ(sdbSetRawDataLen(NULL, 0), -1);
|
||||
ASSERT_EQ(sdbSetRawDataLen(pRaw1, 9000), -1);
|
||||
ASSERT_EQ(sdbSetRawStatus(NULL, SDB_STATUS_READY), -1);
|
||||
ASSERT_EQ(sdbSetRawStatus(pRaw1, SDB_STATUS_INIT), -1);
|
||||
ASSERT_EQ(sdbSetRawInt8(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbSetRawInt8(pRaw1, -128, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbSetRawInt32(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbSetRawInt32(pRaw1, -128, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbSetRawInt16(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbSetRawInt16(pRaw1, -128, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbSetRawInt64(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbSetRawInt64(pRaw1, -128, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbSetRawBinary(NULL, 0, "12", 3), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbSetRawBinary(pRaw1, 9028, "12", 3), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbSetRawDataLen(NULL, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbSetRawDataLen(pRaw1, 9000), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbSetRawStatus(NULL, SDB_STATUS_READY), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbSetRawStatus(pRaw1, SDB_STATUS_INIT), TSDB_CODE_INVALID_PARA);
|
||||
|
||||
ASSERT_EQ(sdbGetRawInt8(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt8(pRaw1, 9000, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt32(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt32(pRaw1, 9000, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt16(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt16(pRaw1, 9000, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt64(NULL, 0, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt64(pRaw1, 9000, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawBinary(NULL, 0, 0, 4096), -1);
|
||||
ASSERT_EQ(sdbGetRawBinary(pRaw1, 9000, 0, 112), -1);
|
||||
ASSERT_EQ(sdbGetRawSoftVer(NULL, 0), -1);
|
||||
ASSERT_EQ(sdbGetRawInt8(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbGetRawInt8(pRaw1, 9000, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbGetRawInt32(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbGetRawInt32(pRaw1, 9000, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbGetRawInt16(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbGetRawInt16(pRaw1, 9000, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbGetRawInt64(NULL, 0, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbGetRawInt64(pRaw1, 9000, 0), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbGetRawBinary(NULL, 0, 0, 4096), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbGetRawBinary(pRaw1, 9000, 0, 112), TSDB_CODE_SDB_INVALID_DATA_LEN);
|
||||
ASSERT_EQ(sdbGetRawSoftVer(NULL, 0), TSDB_CODE_INVALID_PTR);
|
||||
ASSERT_EQ(sdbGetRawTotalSize(NULL), -1);
|
||||
|
||||
// sdbHash.c
|
||||
|
|
|
@ -112,6 +112,8 @@ void sdbCleanup(SSdb *pSdb) {
|
|||
}
|
||||
|
||||
int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
|
||||
int32_t code = 0;
|
||||
|
||||
ESdbType sdbType = table.sdbType;
|
||||
EKeyType keyType = table.keyType;
|
||||
pSdb->keyTypes[sdbType] = table.keyType;
|
||||
|
@ -134,8 +136,8 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
|
|||
|
||||
SHashObj *hash = taosHashInit(64, taosGetDefaultHashFunction(hashType), true, HASH_ENTRY_LOCK);
|
||||
if (hash == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
pSdb->maxId[sdbType] = 0;
|
||||
|
@ -146,16 +148,17 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
|
|||
}
|
||||
|
||||
static int32_t sdbCreateDir(SSdb *pSdb) {
|
||||
int32_t code = 0;
|
||||
if (taosMulMkDir(pSdb->currDir) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to create dir:%s since %s", pSdb->currDir, terrstr());
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to create dir:%s since %s", pSdb->currDir, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (taosMkDir(pSdb->tmpDir) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to create dir:%s since %s", pSdb->tmpDir, terrstr());
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to create dir:%s since %s", pSdb->tmpDir, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -14,18 +14,19 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "crypt.h"
|
||||
#include "sdb.h"
|
||||
#include "sync.h"
|
||||
#include "tchecksum.h"
|
||||
#include "wal.h"
|
||||
#include "tglobal.h"
|
||||
#include "crypt.h"
|
||||
#include "wal.h"
|
||||
|
||||
#define SDB_TABLE_SIZE 24
|
||||
#define SDB_RESERVE_SIZE 512
|
||||
#define SDB_FILE_VER 1
|
||||
|
||||
static int32_t sdbDeployData(SSdb *pSdb) {
|
||||
int32_t code = 0;
|
||||
mInfo("start to deploy sdb");
|
||||
|
||||
for (int32_t i = SDB_MAX - 1; i >= 0; --i) {
|
||||
|
@ -33,8 +34,9 @@ static int32_t sdbDeployData(SSdb *pSdb) {
|
|||
if (fp == NULL) continue;
|
||||
|
||||
mInfo("start to deploy sdb:%s", sdbTableName(i));
|
||||
if ((*fp)(pSdb->pMnode) != 0) {
|
||||
mError("failed to deploy sdb:%s since %s", sdbTableName(i), terrstr());
|
||||
code = (*fp)(pSdb->pMnode);
|
||||
if (code != 0) {
|
||||
mError("failed to deploy sdb:%s since %s", sdbTableName(i), tstrerror(code));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -80,61 +82,62 @@ static void sdbResetData(SSdb *pSdb) {
|
|||
}
|
||||
|
||||
static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
||||
int32_t code = 0;
|
||||
int64_t sver = 0;
|
||||
int32_t ret = taosReadFile(pFile, &sver, sizeof(int64_t));
|
||||
if (ret < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (ret != sizeof(int64_t)) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (sver != SDB_FILE_VER) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
ret = taosReadFile(pFile, &pSdb->applyIndex, sizeof(int64_t));
|
||||
if (ret < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (ret != sizeof(int64_t)) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
ret = taosReadFile(pFile, &pSdb->applyTerm, sizeof(int64_t));
|
||||
if (ret < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (ret != sizeof(int64_t)) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
ret = taosReadFile(pFile, &pSdb->applyConfig, sizeof(int64_t));
|
||||
if (ret < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (ret != sizeof(int64_t)) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) {
|
||||
int64_t maxId = 0;
|
||||
ret = taosReadFile(pFile, &maxId, sizeof(int64_t));
|
||||
if (ret < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (ret != sizeof(int64_t)) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (i < SDB_MAX) {
|
||||
pSdb->maxId[i] = maxId;
|
||||
|
@ -145,12 +148,12 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
|||
int64_t ver = 0;
|
||||
ret = taosReadFile(pFile, &ver, sizeof(int64_t));
|
||||
if (ret < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (ret != sizeof(int64_t)) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (i < SDB_MAX) {
|
||||
pSdb->tableVer[i] = ver;
|
||||
|
@ -160,37 +163,38 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
|||
char reserve[SDB_RESERVE_SIZE] = {0};
|
||||
ret = taosReadFile(pFile, reserve, sizeof(reserve));
|
||||
if (ret < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (ret != sizeof(reserve)) {
|
||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
||||
return -1;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
||||
int32_t code = 0;
|
||||
int64_t sver = SDB_FILE_VER;
|
||||
if (taosWriteFile(pFile, &sver, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (taosWriteFile(pFile, &pSdb->applyIndex, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (taosWriteFile(pFile, &pSdb->applyTerm, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (taosWriteFile(pFile, &pSdb->applyConfig, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) {
|
||||
|
@ -199,8 +203,8 @@ static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
|||
maxId = pSdb->maxId[i];
|
||||
}
|
||||
if (taosWriteFile(pFile, &maxId, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,15 +214,15 @@ static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
|||
ver = pSdb->tableVer[i];
|
||||
}
|
||||
if (taosWriteFile(pFile, &ver, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
}
|
||||
|
||||
char reserve[SDB_RESERVE_SIZE] = {0};
|
||||
if (taosWriteFile(pFile, reserve, sizeof(reserve)) != sizeof(reserve)) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -237,21 +241,22 @@ static int32_t sdbReadFileImp(SSdb *pSdb) {
|
|||
|
||||
SSdbRaw *pRaw = taosMemoryMalloc(bufLen + 100);
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("failed read sdb file since %s", terrstr());
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("failed read sdb file since %s", tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
taosMemoryFree(pRaw);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mInfo("read sdb file:%s finished since %s", file, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mInfo("read sdb file:%s finished since %s", file, tstrerror(code));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (sdbReadFileHead(pSdb, pFile) != 0) {
|
||||
mError("failed to read sdb file:%s head since %s", file, terrstr());
|
||||
code = sdbReadFileHead(pSdb, pFile);
|
||||
if (code != 0) {
|
||||
mError("failed to read sdb file:%s head since %s", file, tstrerror(code));
|
||||
taosMemoryFree(pRaw);
|
||||
taosCloseFile(&pFile);
|
||||
return -1;
|
||||
|
@ -285,7 +290,7 @@ static int32_t sdbReadFileImp(SSdb *pSdb) {
|
|||
bufLen = pRaw->dataLen * 2;
|
||||
SSdbRaw *pNewRaw = taosMemoryMalloc(bufLen + 100);
|
||||
if (pNewRaw == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("failed read sdb file since malloc new sdbRaw size:%d failed", bufLen);
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -312,6 +317,10 @@ static int32_t sdbReadFileImp(SSdb *pSdb) {
|
|||
int32_t count = 0;
|
||||
|
||||
char *plantContent = taosMemoryMalloc(ENCRYPTED_LEN(pRaw->dataLen));
|
||||
if (plantContent == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
SCryptOpts opts;
|
||||
opts.len = ENCRYPTED_LEN(pRaw->dataLen);
|
||||
|
@ -355,8 +364,7 @@ _OVER:
|
|||
taosCloseFile(&pFile);
|
||||
sdbFreeRaw(pRaw);
|
||||
|
||||
terrno = code;
|
||||
return code;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t sdbReadFile(SSdb *pSdb) {
|
||||
|
@ -365,7 +373,7 @@ int32_t sdbReadFile(SSdb *pSdb) {
|
|||
sdbResetData(pSdb);
|
||||
int32_t code = sdbReadFileImp(pSdb);
|
||||
if (code != 0) {
|
||||
mError("failed to read sdb file since %s", terrstr());
|
||||
mError("failed to read sdb file since %s", tstrerror(code));
|
||||
sdbResetData(pSdb);
|
||||
}
|
||||
|
||||
|
@ -388,13 +396,14 @@ static int32_t sdbWriteFileImp(SSdb *pSdb) {
|
|||
|
||||
TdFilePtr pFile = taosOpenFile(tmpfile, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to open sdb file:%s for write since %s", tmpfile, terrstr());
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to open sdb file:%s for write since %s", tmpfile, tstrerror(code));
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (sdbWriteFileHead(pSdb, pFile) != 0) {
|
||||
mError("failed to write sdb file:%s head since %s", tmpfile, terrstr());
|
||||
code = sdbWriteFileHead(pSdb, pFile);
|
||||
if (code != 0) {
|
||||
mError("failed to write sdb file:%s head since %s", tmpfile, tstrerror(code));
|
||||
taosCloseFile(&pFile);
|
||||
return -1;
|
||||
}
|
||||
|
@ -549,19 +558,22 @@ int32_t sdbWriteFile(SSdb *pSdb, int32_t delta) {
|
|||
}
|
||||
}
|
||||
if (code != 0) {
|
||||
mError("failed to write sdb file since %s", terrstr());
|
||||
mError("failed to write sdb file since %s", tstrerror(code));
|
||||
}
|
||||
taosThreadMutexUnlock(&pSdb->filelock);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t sdbDeploy(SSdb *pSdb) {
|
||||
if (sdbDeployData(pSdb) != 0) {
|
||||
return -1;
|
||||
int32_t code = 0;
|
||||
code = sdbDeployData(pSdb);
|
||||
if (code != 0) {
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (sdbWriteFile(pSdb, 0) != 0) {
|
||||
return -1;
|
||||
code = sdbWriteFile(pSdb, 0);
|
||||
if (code != 0) {
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -605,6 +617,7 @@ static void sdbCloseIter(SSdbIter *pIter) {
|
|||
}
|
||||
|
||||
int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *term, int64_t *config) {
|
||||
int32_t code = 0;
|
||||
SSdbIter *pIter = sdbCreateIter(pSdb);
|
||||
if (pIter == NULL) return -1;
|
||||
|
||||
|
@ -617,19 +630,19 @@ int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *ter
|
|||
int64_t commitConfig = pSdb->commitConfig;
|
||||
if (taosCopyFile(datafile, pIter->name) < 0) {
|
||||
taosThreadMutexUnlock(&pSdb->filelock);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to copy sdb file %s to %s since %s", datafile, pIter->name, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to copy sdb file %s to %s since %s", datafile, pIter->name, tstrerror(code));
|
||||
sdbCloseIter(pIter);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
taosThreadMutexUnlock(&pSdb->filelock);
|
||||
|
||||
pIter->file = taosOpenFile(pIter->name, TD_FILE_READ);
|
||||
if (pIter->file == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to open sdb file:%s since %s", pIter->name, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to open sdb file:%s since %s", pIter->name, tstrerror(code));
|
||||
sdbCloseIter(pIter);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*ppIter = pIter;
|
||||
|
@ -645,21 +658,22 @@ int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *ter
|
|||
void sdbStopRead(SSdb *pSdb, SSdbIter *pIter) { sdbCloseIter(pIter); }
|
||||
|
||||
int32_t sdbDoRead(SSdb *pSdb, SSdbIter *pIter, void **ppBuf, int32_t *len) {
|
||||
int32_t code = 0;
|
||||
int32_t maxlen = 4096;
|
||||
void *pBuf = taosMemoryCalloc(1, maxlen);
|
||||
if (pBuf == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
int32_t readlen = taosReadFile(pIter->file, pBuf, maxlen);
|
||||
if (readlen < 0 || readlen > maxlen) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("sdbiter:%p, failed to read snapshot since %s, total:%" PRId64, pIter, terrstr(), pIter->total);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("sdbiter:%p, failed to read snapshot since %s, total:%" PRId64, pIter, tstrerror(code), pIter->total);
|
||||
*ppBuf = NULL;
|
||||
*len = 0;
|
||||
taosMemoryFree(pBuf);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
} else if (readlen == 0) {
|
||||
mInfo("sdbiter:%p, read snapshot to the end, total:%" PRId64, pIter, pIter->total);
|
||||
*ppBuf = NULL;
|
||||
|
@ -676,15 +690,19 @@ int32_t sdbDoRead(SSdb *pSdb, SSdbIter *pIter, void **ppBuf, int32_t *len) {
|
|||
}
|
||||
|
||||
int32_t sdbStartWrite(SSdb *pSdb, SSdbIter **ppIter) {
|
||||
int32_t code = 0;
|
||||
SSdbIter *pIter = sdbCreateIter(pSdb);
|
||||
if (pIter == NULL) return -1;
|
||||
if (pIter == NULL) {
|
||||
code = terrno;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
pIter->file = taosOpenFile(pIter->name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pIter->file == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to open %s since %s", pIter->name, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to open %s since %s", pIter->name, tstrerror(code));
|
||||
sdbCloseIter(pIter);
|
||||
return -1;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*ppIter = pIter;
|
||||
|
@ -702,8 +720,8 @@ int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply, int64_t index, i
|
|||
}
|
||||
|
||||
if (taosFsyncFile(pIter->file) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("sdbiter:%p, failed to fasync file %s since %s", pIter, pIter->name, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("sdbiter:%p, failed to fasync file %s since %s", pIter, pIter->name, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -713,13 +731,14 @@ int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply, int64_t index, i
|
|||
char datafile[PATH_MAX] = {0};
|
||||
snprintf(datafile, sizeof(datafile), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP);
|
||||
if (taosRenameFile(pIter->name, datafile) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("sdbiter:%p, failed to rename file %s to %s since %s", pIter, pIter->name, datafile, terrstr());
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("sdbiter:%p, failed to rename file %s to %s since %s", pIter, pIter->name, datafile, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (sdbReadFile(pSdb) != 0) {
|
||||
mError("sdbiter:%p, failed to read from %s since %s", pIter, datafile, terrstr());
|
||||
code = sdbReadFile(pSdb);
|
||||
if (code != 0) {
|
||||
mError("sdbiter:%p, failed to read from %s since %s", pIter, datafile, tstrerror(code));
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -742,11 +761,12 @@ _OVER:
|
|||
}
|
||||
|
||||
int32_t sdbDoWrite(SSdb *pSdb, SSdbIter *pIter, void *pBuf, int32_t len) {
|
||||
int32_t code = 0;
|
||||
int32_t writelen = taosWriteFile(pIter->file, pBuf, len);
|
||||
if (writelen != len) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to write len:%d since %s, total:%" PRId64, len, terrstr(), pIter->total);
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to write len:%d since %s, total:%" PRId64, len, tstrerror(code), pIter->total);
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
pIter->total += writelen;
|
||||
|
|
|
@ -53,14 +53,15 @@ void sdbFreeRaw(SSdbRaw *pRaw) {
|
|||
}
|
||||
|
||||
int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int8_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*(int8_t *)(pRaw->pData + dataPos) = val;
|
||||
|
@ -68,14 +69,15 @@ int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val) {
|
|||
}
|
||||
|
||||
int32_t sdbSetRawUInt8(SSdbRaw *pRaw, int32_t dataPos, uint8_t val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(uint8_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*(uint8_t *)(pRaw->pData + dataPos) = val;
|
||||
|
@ -83,14 +85,15 @@ int32_t sdbSetRawUInt8(SSdbRaw *pRaw, int32_t dataPos, uint8_t val) {
|
|||
}
|
||||
|
||||
int32_t sdbSetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int32_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*(int32_t *)(pRaw->pData + dataPos) = val;
|
||||
|
@ -98,14 +101,15 @@ int32_t sdbSetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t val) {
|
|||
}
|
||||
|
||||
int32_t sdbSetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int16_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*(int16_t *)(pRaw->pData + dataPos) = val;
|
||||
|
@ -113,14 +117,15 @@ int32_t sdbSetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t val) {
|
|||
}
|
||||
|
||||
int32_t sdbSetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int64_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*(int64_t *)(pRaw->pData + dataPos) = val;
|
||||
|
@ -128,14 +133,15 @@ int32_t sdbSetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t val) {
|
|||
}
|
||||
|
||||
int32_t sdbSetRawBinary(SSdbRaw *pRaw, int32_t dataPos, const char *pVal, int32_t valLen) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + valLen > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (pVal != NULL) {
|
||||
|
@ -145,14 +151,15 @@ int32_t sdbSetRawBinary(SSdbRaw *pRaw, int32_t dataPos, const char *pVal, int32_
|
|||
}
|
||||
|
||||
int32_t sdbSetRawDataLen(SSdbRaw *pRaw, int32_t dataLen) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataLen > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
pRaw->dataLen = dataLen;
|
||||
|
@ -160,14 +167,15 @@ int32_t sdbSetRawDataLen(SSdbRaw *pRaw, int32_t dataLen) {
|
|||
}
|
||||
|
||||
int32_t sdbSetRawStatus(SSdbRaw *pRaw, ESdbStatus status) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (status == SDB_STATUS_INIT) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PARA;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
pRaw->status = status;
|
||||
|
@ -175,14 +183,15 @@ int32_t sdbSetRawStatus(SSdbRaw *pRaw, ESdbStatus status) {
|
|||
}
|
||||
|
||||
int32_t sdbGetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t *val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int8_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*val = *(int8_t *)(pRaw->pData + dataPos);
|
||||
|
@ -190,14 +199,15 @@ int32_t sdbGetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t *val) {
|
|||
}
|
||||
|
||||
int32_t sdbGetRawUInt8(SSdbRaw *pRaw, int32_t dataPos, uint8_t *val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(uint8_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*val = *(uint8_t *)(pRaw->pData + dataPos);
|
||||
|
@ -205,14 +215,15 @@ int32_t sdbGetRawUInt8(SSdbRaw *pRaw, int32_t dataPos, uint8_t *val) {
|
|||
}
|
||||
|
||||
int32_t sdbGetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t *val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int32_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*val = *(int32_t *)(pRaw->pData + dataPos);
|
||||
|
@ -220,14 +231,15 @@ int32_t sdbGetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t *val) {
|
|||
}
|
||||
|
||||
int32_t sdbGetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t *val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int16_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*val = *(int16_t *)(pRaw->pData + dataPos);
|
||||
|
@ -235,14 +247,15 @@ int32_t sdbGetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t *val) {
|
|||
}
|
||||
|
||||
int32_t sdbGetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t *val) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + sizeof(int64_t) > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*val = *(int64_t *)(pRaw->pData + dataPos);
|
||||
|
@ -250,14 +263,15 @@ int32_t sdbGetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t *val) {
|
|||
}
|
||||
|
||||
int32_t sdbGetRawBinary(SSdbRaw *pRaw, int32_t dataPos, char *pVal, int32_t valLen) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
if (dataPos + valLen > pRaw->dataLen) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
return -1;
|
||||
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
if (pVal != NULL) {
|
||||
memcpy(pVal, pRaw->pData + dataPos, valLen);
|
||||
|
@ -266,9 +280,10 @@ int32_t sdbGetRawBinary(SSdbRaw *pRaw, int32_t dataPos, char *pVal, int32_t valL
|
|||
}
|
||||
|
||||
int32_t sdbGetRawSoftVer(SSdbRaw *pRaw, int8_t *sver) {
|
||||
int32_t code = 0;
|
||||
if (pRaw == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
*sver = pRaw->sver;
|
||||
|
|
|
@ -147,7 +147,6 @@ int32_t tsdbRowKeyCmpr(const STsdbRowKey *key1, const STsdbRowKey *key2);
|
|||
void tsdbRowGetKey(TSDBROW *row, STsdbRowKey *key);
|
||||
void tColRowGetPrimaryKey(SBlockData *pBlock, int32_t irow, SRowKey *key);
|
||||
|
||||
|
||||
// STSDBRowIter
|
||||
int32_t tsdbRowIterOpen(STSDBRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema);
|
||||
void tsdbRowClose(STSDBRowIter *pIter);
|
||||
|
|
|
@ -362,6 +362,8 @@ static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat
|
|||
* @return int32_t
|
||||
*/
|
||||
int32_t tdRSmaProcessCreateImpl(SSma *pSma, SRSmaParam *param, int64_t suid, const char *tbName) {
|
||||
int32_t code;
|
||||
|
||||
if ((param->qmsgLen[0] == 0) && (param->qmsgLen[1] == 0)) {
|
||||
smaDebug("vgId:%d, no qmsg1/qmsg2 for rollup table %s %" PRIi64, SMA_VID(pSma), tbName, suid);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -401,8 +403,13 @@ int32_t tdRSmaProcessCreateImpl(SSma *pSma, SRSmaParam *param, int64_t suid, con
|
|||
pRSmaInfo->suid = suid;
|
||||
T_REF_INIT_VAL(pRSmaInfo, 1);
|
||||
|
||||
if (!(pRSmaInfo->queue = taosOpenQueue()) || !(pRSmaInfo->qall = taosAllocateQall()) ||
|
||||
tdSetRSmaInfoItemParams(pSma, param, pStat, pRSmaInfo, 0) < 0 ||
|
||||
code = taosOpenQueue(&pRSmaInfo->queue);
|
||||
if (code) goto _err;
|
||||
|
||||
code = taosAllocateQall(&pRSmaInfo->qall);
|
||||
if (code) goto _err;
|
||||
|
||||
if (tdSetRSmaInfoItemParams(pSma, param, pStat, pRSmaInfo, 0) < 0 ||
|
||||
tdSetRSmaInfoItemParams(pSma, param, pStat, pRSmaInfo, 1) < 0) {
|
||||
goto _err;
|
||||
}
|
||||
|
@ -795,11 +802,13 @@ _exit:
|
|||
*/
|
||||
static int32_t tdExecuteRSmaImplAsync(SSma *pSma, int64_t version, const void *pMsg, int32_t len, int32_t inputType,
|
||||
SRSmaInfo *pInfo, tb_uid_t suid) {
|
||||
int32_t code;
|
||||
int32_t size = RSMA_EXEC_MSG_HLEN + len; // header + payload
|
||||
void * qItem = taosAllocateQitem(size, DEF_QITEM, 0);
|
||||
void *qItem;
|
||||
|
||||
if (!qItem) {
|
||||
return TSDB_CODE_FAILED;
|
||||
code = taosAllocateQitem(size, DEF_QITEM, 0, (void **)&qItem);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
void *pItem = qItem;
|
||||
|
|
|
@ -725,6 +725,7 @@ int32_t setDstTableDataUid(SVnode* pVnode, SStreamTask* pTask, SSDataBlock* pDat
|
|||
if (metaGetTableEntryByName(&mr, dstTableName) < 0) {
|
||||
metaReaderClear(&mr);
|
||||
|
||||
if (pTask->outputInfo.tbSink.autoCreateCtb) {
|
||||
tqDebug("s-task:%s stream write into table:%s, table auto created", id, dstTableName);
|
||||
|
||||
SArray* pTagArray = taosArrayInit(pTSchema->numOfCols + 1, sizeof(STagVal));
|
||||
|
@ -736,13 +737,21 @@ int32_t setDstTableDataUid(SVnode* pVnode, SStreamTask* pTask, SSDataBlock* pDat
|
|||
taosArrayDestroy(pTagArray);
|
||||
|
||||
if (pTableData->pCreateTbReq == NULL) {
|
||||
tqError("s-task:%s failed to build auto create table req, code:%s", id, tstrerror(terrno));
|
||||
tqError("s-task:%s failed to build auto create dst-table req:%s, code:%s", id, dstTableName,
|
||||
tstrerror(terrno));
|
||||
taosMemoryFree(pTableSinkInfo);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
pTableSinkInfo->uid = 0;
|
||||
doPutIntoCache(pTask->outputInfo.tbSink.pTblInfo, pTableSinkInfo, groupId, id);
|
||||
} else {
|
||||
metaReaderClear(&mr);
|
||||
|
||||
tqError("s-task:%s vgId:%d dst-table:%s not auto-created, and not create in tsdb, discard data", id,
|
||||
vgId, dstTableName);
|
||||
return TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
} else {
|
||||
bool isValid = isValidDstChildTable(&mr, vgId, dstTableName, suid);
|
||||
if (!isValid) {
|
||||
|
@ -798,6 +807,24 @@ void tqSinkDataIntoDstTable(SStreamTask* pTask, void* vnode, void* data) {
|
|||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
const char* id = pTask->id.idStr;
|
||||
int64_t earlyTs = tsdbGetEarliestTs(pVnode->pTsdb);
|
||||
STaskOutputInfo* pOutputInfo = &pTask->outputInfo;
|
||||
|
||||
if (pTask->outputInfo.tbSink.pTagSchema == NULL) {
|
||||
SMetaReader mer1 = {0};
|
||||
metaReaderDoInit(&mer1, pVnode->pMeta, META_READER_LOCK);
|
||||
|
||||
code = metaReaderGetTableEntryByUid(&mer1, pOutputInfo->tbSink.stbUid);
|
||||
pOutputInfo->tbSink.pTagSchema = tCloneSSchemaWrapper(&mer1.me.stbEntry.schemaTag);
|
||||
metaReaderClear(&mer1);
|
||||
|
||||
SSchemaWrapper* pTagSchema = pOutputInfo->tbSink.pTagSchema;
|
||||
SSchema* pCol1 = &pTagSchema->pSchema[0];
|
||||
if (pTagSchema->nCols == 1 && pCol1->type == TSDB_DATA_TYPE_UBIGINT && strcmp(pCol1->name, "group_id") == 0) {
|
||||
pOutputInfo->tbSink.autoCreateCtb = true;
|
||||
} else {
|
||||
pOutputInfo->tbSink.autoCreateCtb = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool onlySubmitData = hasOnlySubmitData(pBlocks, numOfBlocks);
|
||||
if (!onlySubmitData) {
|
||||
|
@ -829,6 +856,7 @@ void tqSinkDataIntoDstTable(SStreamTask* pTask, void* vnode, void* data) {
|
|||
SSubmitTbData tbData = {.suid = suid, .uid = 0, .sver = pTSchema->version, .flags = TD_REQ_FROM_APP};
|
||||
code = setDstTableDataUid(pVnode, pTask, pDataBlock, stbFullName, &tbData);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tqError("vgId:%d s-task:%s dst-table not exist, stb:%s discard stream results", vgId, id, stbFullName);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -882,6 +910,7 @@ void tqSinkDataIntoDstTable(SStreamTask* pTask, void* vnode, void* data) {
|
|||
if (index == NULL) { // no data yet, append it
|
||||
code = setDstTableDataUid(pVnode, pTask, pDataBlock, stbFullName, &tbData);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tqError("vgId:%d dst-table gid:%" PRId64 " not exist, discard stream results", vgId, groupId);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -164,7 +164,8 @@ static int32_t extractDataAndRspForNormalSubscribe(STQ* pTq, STqHandle* pHandle,
|
|||
taosWUnLockLatch(&pTq->lock);
|
||||
}
|
||||
|
||||
tOffsetCopy(&dataRsp.common.reqOffset, pOffset); // reqOffset represents the current date offset, may be changed if wal not exists
|
||||
tOffsetCopy(&dataRsp.common.reqOffset,
|
||||
pOffset); // reqOffset represents the current date offset, may be changed if wal not exists
|
||||
code = tqSendDataRsp(pHandle, pMsg, pRequest, &dataRsp, TMQ_MSG_TYPE__POLL_DATA_RSP, vgId);
|
||||
|
||||
end : {
|
||||
|
@ -185,7 +186,8 @@ end : {
|
|||
int32_t len = pHead->bodyLen - sizeof(SMsgHead); \
|
||||
tDecoderInit(&decoder, data, len); \
|
||||
if (DECODE_FUNC(&decoder, &req) == 0 && (req.source & TD_REQ_FROM_TAOX) != 0) { \
|
||||
tqDebug("tmq poll: consumer:0x%" PRIx64 " (epoch %d) iter log, jump meta for, vgId:%d offset %" PRId64 " msgType %d", \
|
||||
tqDebug("tmq poll: consumer:0x%" PRIx64 " (epoch %d) iter log, jump meta for, vgId:%d offset %" PRId64 \
|
||||
" msgType %d", \
|
||||
pRequest->consumerId, pRequest->epoch, vgId, fetchVer, pHead->msgType); \
|
||||
fetchVer++; \
|
||||
DELETE_FUNC(&req); \
|
||||
|
@ -195,8 +197,7 @@ end : {
|
|||
DELETE_FUNC(&req); \
|
||||
tDecoderClear(&decoder);
|
||||
|
||||
static void tDeleteCommon(void* parm) {
|
||||
}
|
||||
static void tDeleteCommon(void* parm) {}
|
||||
|
||||
static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest,
|
||||
SRpcMsg* pMsg, STqOffsetVal* offset) {
|
||||
|
@ -416,8 +417,8 @@ static void initMqRspHead(SMqRspHead* pMsgHead, int32_t type, int32_t epoch, int
|
|||
pMsgHead->walever = ever;
|
||||
}
|
||||
|
||||
int32_t tqSendBatchMetaPollRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqBatchMetaRsp* pRsp,
|
||||
int32_t vgId) {
|
||||
int32_t tqSendBatchMetaPollRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPollReq* pReq,
|
||||
const SMqBatchMetaRsp* pRsp, int32_t vgId) {
|
||||
int32_t len = 0;
|
||||
int32_t code = 0;
|
||||
tEncodeSize(tEncodeMqBatchMetaRsp, pRsp, len, code);
|
||||
|
@ -444,8 +445,8 @@ int32_t tqSendBatchMetaPollRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SM
|
|||
SRpcMsg resp = {.info = pMsg->info, .pCont = buf, .contLen = tlen, .code = 0};
|
||||
|
||||
tmsgSendRsp(&resp);
|
||||
tqDebug("vgId:%d, from consumer:0x%" PRIx64 " (epoch %d) send rsp, res msg type: batch meta, size:%ld offset type:%d", vgId,
|
||||
pReq->consumerId, pReq->epoch, taosArrayGetSize(pRsp->batchMetaReq), pRsp->rspOffset.type);
|
||||
tqDebug("vgId:%d, from consumer:0x%" PRIx64 " (epoch %d) send rsp, res msg type: batch meta, size:%ld offset type:%d",
|
||||
vgId, pReq->consumerId, pReq->epoch, taosArrayGetSize(pRsp->batchMetaReq), pRsp->rspOffset.type);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -527,6 +528,7 @@ int32_t tqDoSendDataRsp(const SRpcHandleInfo* pRpcHandleInfo, const void* pRsp,
|
|||
}
|
||||
|
||||
int32_t tqExtractDelDataBlock(const void* pData, int32_t len, int64_t ver, void** pRefBlock, int32_t type) {
|
||||
int32_t code;
|
||||
SDecoder* pCoder = &(SDecoder){0};
|
||||
SDeleteRes* pRes = &(SDeleteRes){0};
|
||||
|
||||
|
@ -570,11 +572,11 @@ int32_t tqExtractDelDataBlock(const void* pData, int32_t len, int64_t ver, void*
|
|||
|
||||
taosArrayDestroy(pRes->uidList);
|
||||
if (type == 0) {
|
||||
*pRefBlock = taosAllocateQitem(sizeof(SStreamRefDataBlock), DEF_QITEM, 0);
|
||||
if (*pRefBlock == NULL) {
|
||||
code = taosAllocateQitem(sizeof(SStreamRefDataBlock), DEF_QITEM, 0, pRefBlock);
|
||||
if (code) {
|
||||
blockDataCleanup(pDelBlock);
|
||||
taosMemoryFree(pDelBlock);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
return code;
|
||||
}
|
||||
|
||||
((SStreamRefDataBlock*)(*pRefBlock))->type = STREAM_INPUT__REF_DATA_BLOCK;
|
||||
|
|
|
@ -1307,186 +1307,6 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
|
|||
|
||||
static int32_t mergeLastRowCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SCacheRowsReader *pr, int16_t *aCols,
|
||||
int nCols, int16_t *slotIds);
|
||||
#ifdef BUILD_NO_CALL
|
||||
static SLastCol *tsdbCacheLookup(STsdb *pTsdb, tb_uid_t uid, int16_t cid, int8_t ltype) {
|
||||
SLastCol *pLastCol = NULL;
|
||||
|
||||
char *err = NULL;
|
||||
size_t vlen = 0;
|
||||
SLastKey *key = &(SLastKey){.ltype = ltype, .uid = uid, .cid = cid};
|
||||
size_t klen = ROCKS_KEY_LEN;
|
||||
char *value = NULL;
|
||||
value = rocksdb_get(pTsdb->rCache.db, pTsdb->rCache.readoptions, (char *)key, klen, &vlen, &err);
|
||||
if (NULL != err) {
|
||||
tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, err);
|
||||
rocksdb_free(err);
|
||||
}
|
||||
|
||||
pLastCol = tsdbCacheDeserialize(value);
|
||||
|
||||
return pLastCol;
|
||||
}
|
||||
|
||||
int32_t tsdbCacheGetSlow(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArray, SCacheRowsReader *pr, int8_t ltype) {
|
||||
rocksdb_writebatch_t *wb = NULL;
|
||||
int32_t code = 0;
|
||||
|
||||
SArray *pCidList = pr->pCidList;
|
||||
int num_keys = TARRAY_SIZE(pCidList);
|
||||
|
||||
char **keys_list = taosMemoryMalloc(num_keys * sizeof(char *));
|
||||
size_t *keys_list_sizes = taosMemoryMalloc(num_keys * sizeof(size_t));
|
||||
char *key_list = taosMemoryMalloc(num_keys * ROCKS_KEY_LEN);
|
||||
for (int i = 0; i < num_keys; ++i) {
|
||||
int16_t cid = *(int16_t *)taosArrayGet(pCidList, i);
|
||||
|
||||
memcpy(key_list + i * ROCKS_KEY_LEN, &(SLastKey){.ltype = ltype, .uid = uid, .cid = cid}, ROCKS_KEY_LEN);
|
||||
keys_list[i] = key_list + i * ROCKS_KEY_LEN;
|
||||
keys_list_sizes[i] = ROCKS_KEY_LEN;
|
||||
}
|
||||
|
||||
char **values_list = taosMemoryCalloc(num_keys, sizeof(char *));
|
||||
size_t *values_list_sizes = taosMemoryCalloc(num_keys, sizeof(size_t));
|
||||
char **errs = taosMemoryMalloc(num_keys * sizeof(char *));
|
||||
rocksdb_multi_get(pTsdb->rCache.db, pTsdb->rCache.readoptions, num_keys, (const char *const *)keys_list,
|
||||
keys_list_sizes, values_list, values_list_sizes, errs);
|
||||
for (int i = 0; i < num_keys; ++i) {
|
||||
if (errs[i]) {
|
||||
rocksdb_free(errs[i]);
|
||||
}
|
||||
}
|
||||
taosMemoryFree(key_list);
|
||||
taosMemoryFree(keys_list);
|
||||
taosMemoryFree(keys_list_sizes);
|
||||
taosMemoryFree(errs);
|
||||
|
||||
for (int i = 0; i < num_keys; ++i) {
|
||||
bool freeCol = true;
|
||||
SArray *pTmpColArray = NULL;
|
||||
SLastCol *pLastCol = tsdbCacheDeserialize(values_list[i]);
|
||||
int16_t cid = *(int16_t *)taosArrayGet(pCidList, i);
|
||||
SLastCol noneCol = {.ts = TSKEY_MIN, .colVal = COL_VAL_NONE(cid, pr->pSchema->columns[pr->pSlotIds[i]].type)};
|
||||
if (pLastCol) {
|
||||
reallocVarData(&pLastCol->colVal);
|
||||
} else {
|
||||
taosThreadMutexLock(&pTsdb->rCache.rMutex);
|
||||
|
||||
pLastCol = tsdbCacheLookup(pTsdb, uid, cid, ltype);
|
||||
if (!pLastCol) {
|
||||
// recalc: load from tsdb
|
||||
int16_t aCols[1] = {cid};
|
||||
int16_t slotIds[1] = {pr->pSlotIds[i]};
|
||||
pTmpColArray = NULL;
|
||||
|
||||
if (ltype) {
|
||||
mergeLastCid(uid, pTsdb, &pTmpColArray, pr, aCols, 1, slotIds);
|
||||
} else {
|
||||
mergeLastRowCid(uid, pTsdb, &pTmpColArray, pr, aCols, 1, slotIds);
|
||||
}
|
||||
|
||||
if (pTmpColArray && TARRAY_SIZE(pTmpColArray) >= 1) {
|
||||
pLastCol = taosArrayGet(pTmpColArray, 0);
|
||||
freeCol = false;
|
||||
}
|
||||
|
||||
// still null, then make up a none col value
|
||||
if (!pLastCol) {
|
||||
pLastCol = &noneCol;
|
||||
freeCol = false;
|
||||
}
|
||||
|
||||
// store result back to rocks cache
|
||||
wb = pTsdb->rCache.rwritebatch;
|
||||
char *value = NULL;
|
||||
size_t vlen = 0;
|
||||
tsdbCacheSerialize(pLastCol, &value, &vlen);
|
||||
|
||||
SLastKey *key = &(SLastKey){.ltype = ltype, .uid = uid, .cid = pLastCol->colVal.cid};
|
||||
size_t klen = ROCKS_KEY_LEN;
|
||||
rocksdb_writebatch_put(wb, (char *)key, klen, value, vlen);
|
||||
|
||||
taosMemoryFree(value);
|
||||
} else {
|
||||
reallocVarData(&pLastCol->colVal);
|
||||
}
|
||||
|
||||
if (wb) {
|
||||
rocksMayWrite(pTsdb, false, true, false);
|
||||
}
|
||||
|
||||
taosThreadMutexUnlock(&pTsdb->rCache.rMutex);
|
||||
}
|
||||
|
||||
taosArrayPush(pLastArray, pLastCol);
|
||||
taosArrayDestroy(pTmpColArray);
|
||||
if (freeCol) {
|
||||
taosMemoryFree(pLastCol);
|
||||
}
|
||||
}
|
||||
taosMemoryFree(values_list);
|
||||
taosMemoryFree(values_list_sizes);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static SLastCol *tsdbCacheLoadCol(STsdb *pTsdb, SCacheRowsReader *pr, int16_t slotid, tb_uid_t uid, int16_t cid,
|
||||
int8_t ltype) {
|
||||
SLastCol *pLastCol = tsdbCacheLookup(pTsdb, uid, cid, ltype);
|
||||
if (!pLastCol) {
|
||||
rocksdb_writebatch_t *wb = NULL;
|
||||
|
||||
taosThreadMutexLock(&pTsdb->rCache.rMutex);
|
||||
pLastCol = tsdbCacheLookup(pTsdb, uid, cid, ltype);
|
||||
if (!pLastCol) {
|
||||
// recalc: load from tsdb
|
||||
int16_t aCols[1] = {cid};
|
||||
int16_t slotIds[1] = {slotid};
|
||||
SArray *pTmpColArray = NULL;
|
||||
|
||||
if (ltype) {
|
||||
mergeLastCid(uid, pTsdb, &pTmpColArray, pr, aCols, 1, slotIds);
|
||||
} else {
|
||||
mergeLastRowCid(uid, pTsdb, &pTmpColArray, pr, aCols, 1, slotIds);
|
||||
}
|
||||
|
||||
if (pTmpColArray && TARRAY_SIZE(pTmpColArray) >= 1) {
|
||||
pLastCol = taosArrayGet(pTmpColArray, 0);
|
||||
}
|
||||
|
||||
// still null, then make up a none col value
|
||||
SLastCol noneCol = {.ts = TSKEY_MIN, .colVal = COL_VAL_NONE(cid, pr->pSchema->columns[slotid].type)};
|
||||
if (!pLastCol) {
|
||||
pLastCol = &noneCol;
|
||||
}
|
||||
|
||||
// store result back to rocks cache
|
||||
wb = pTsdb->rCache.rwritebatch;
|
||||
char *value = NULL;
|
||||
size_t vlen = 0;
|
||||
tsdbCacheSerialize(pLastCol, &value, &vlen);
|
||||
|
||||
SLastKey *key = &(SLastKey){.ltype = ltype, .uid = uid, .cid = pLastCol->colVal.cid};
|
||||
size_t klen = ROCKS_KEY_LEN;
|
||||
rocksdb_writebatch_put(wb, (char *)key, klen, value, vlen);
|
||||
taosMemoryFree(value);
|
||||
|
||||
SLastCol *pTmpLastCol = taosMemoryCalloc(1, sizeof(SLastCol));
|
||||
*pTmpLastCol = *pLastCol;
|
||||
pLastCol = pTmpLastCol;
|
||||
|
||||
taosArrayDestroy(pTmpColArray);
|
||||
}
|
||||
|
||||
if (wb) {
|
||||
rocksMayWrite(pTsdb, false, true, false);
|
||||
}
|
||||
|
||||
taosThreadMutexUnlock(&pTsdb->rCache.rMutex);
|
||||
}
|
||||
|
||||
return pLastCol;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArray, SArray *remainCols,
|
||||
SCacheRowsReader *pr, int8_t ltype) {
|
||||
|
@ -3453,8 +3273,9 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
|
|||
taosArrayPush(aColArray, &aCols[i]);
|
||||
}
|
||||
|
||||
TSKEY lastRowTs = TSKEY_MAX;
|
||||
STsdbRowKey lastRowKey = {.key.ts = TSKEY_MAX};
|
||||
|
||||
// inverse iterator
|
||||
CacheNextRowIter iter = {0};
|
||||
nextRowIterOpen(&iter, uid, pTsdb, pTSchema, pr->info.suid, pr->pLDataIterArray, pr->pReadSnap, pr->lastTs, pr);
|
||||
|
||||
|
@ -3478,10 +3299,11 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
|
|||
}
|
||||
// int16_t nCol = pTSchema->numOfCols;
|
||||
|
||||
TSKEY rowTs = TSDBROW_TS(pRow);
|
||||
STsdbRowKey rowKey = {0};
|
||||
tsdbRowGetKey(pRow, &rowKey);
|
||||
|
||||
if (lastRowTs == TSKEY_MAX) {
|
||||
lastRowTs = rowTs;
|
||||
if (lastRowKey.key.ts == TSKEY_MAX) { // first time
|
||||
lastRowKey = rowKey;
|
||||
|
||||
for (int16_t iCol = noneCol; iCol < nCols; ++iCol) {
|
||||
if (iCol >= nLastCol) {
|
||||
|
@ -3501,13 +3323,13 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
|
|||
if (slotIds[iCol] == 0) {
|
||||
STColumn *pTColumn = &pTSchema->columns[0];
|
||||
|
||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, ((SValue){.type = pTColumn->type, .val = rowTs}));
|
||||
taosArraySet(pColArray, 0, &(SLastCol){.rowKey.ts = rowTs, .colVal = *pColVal});
|
||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, ((SValue){.type = pTColumn->type, .val = rowKey.key.ts}));
|
||||
taosArraySet(pColArray, 0, &(SLastCol){.rowKey = rowKey.key, .colVal = *pColVal});
|
||||
continue;
|
||||
}
|
||||
tsdbRowGetColVal(pRow, pTSchema, slotIds[iCol], pColVal);
|
||||
|
||||
*pCol = (SLastCol){.rowKey.ts = rowTs, .colVal = *pColVal};
|
||||
*pCol = (SLastCol){.rowKey = rowKey.key, .colVal = *pColVal};
|
||||
if (IS_VAR_DATA_TYPE(pColVal->value.type) /*&& pColVal->value.nData > 0*/) {
|
||||
if (pColVal->value.nData > 0) {
|
||||
pCol->colVal.value.pData = taosMemoryMalloc(pCol->colVal.value.nData);
|
||||
|
@ -3554,10 +3376,11 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
|
|||
continue;
|
||||
}
|
||||
SColVal *tColVal = &lastColVal->colVal;
|
||||
if (COL_VAL_IS_VALUE(tColVal)) continue;
|
||||
|
||||
tsdbRowGetColVal(pRow, pTSchema, slotIds[iCol], pColVal);
|
||||
if (!COL_VAL_IS_VALUE(tColVal) && COL_VAL_IS_VALUE(pColVal)) {
|
||||
SLastCol lastCol = {.rowKey.ts = rowTs, .colVal = *pColVal};
|
||||
if (COL_VAL_IS_VALUE(pColVal)) {
|
||||
SLastCol lastCol = {.rowKey = rowKey.key, .colVal = *pColVal};
|
||||
if (IS_VAR_DATA_TYPE(pColVal->value.type) /* && pColVal->value.nData > 0 */) {
|
||||
SLastCol *pLastCol = (SLastCol *)taosArrayGet(pColArray, iCol);
|
||||
taosMemoryFree(pLastCol->colVal.value.pData);
|
||||
|
@ -3580,7 +3403,7 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
|
|||
if (aColIndex >= 0) {
|
||||
taosArrayRemove(aColArray, aColIndex);
|
||||
}
|
||||
} else if (!COL_VAL_IS_VALUE(tColVal) && !COL_VAL_IS_VALUE(pColVal) && !setNoneCol) {
|
||||
} else if (!COL_VAL_IS_VALUE(pColVal) && !setNoneCol) {
|
||||
noneCol = iCol;
|
||||
setNoneCol = true;
|
||||
}
|
||||
|
@ -3637,8 +3460,7 @@ static int32_t mergeLastRowCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray,
|
|||
taosArrayPush(aColArray, &aCols[i]);
|
||||
}
|
||||
|
||||
TSKEY lastRowTs = TSKEY_MAX;
|
||||
|
||||
// inverse iterator
|
||||
CacheNextRowIter iter = {0};
|
||||
nextRowIterOpen(&iter, uid, pTsdb, pTSchema, pr->info.suid, pr->pLDataIterArray, pr->pReadSnap, pr->lastTs, pr);
|
||||
|
||||
|
@ -3662,9 +3484,8 @@ static int32_t mergeLastRowCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray,
|
|||
}
|
||||
// int16_t nCol = pTSchema->numOfCols;
|
||||
|
||||
TSKEY rowTs = TSDBROW_TS(pRow);
|
||||
|
||||
lastRowTs = rowTs;
|
||||
STsdbRowKey rowKey = {0};
|
||||
tsdbRowGetKey(pRow, &rowKey);
|
||||
|
||||
for (int16_t iCol = noneCol; iCol < nCols; ++iCol) {
|
||||
if (iCol >= nLastCol) {
|
||||
|
@ -3680,13 +3501,13 @@ static int32_t mergeLastRowCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray,
|
|||
if (slotIds[iCol] == 0) {
|
||||
STColumn *pTColumn = &pTSchema->columns[0];
|
||||
|
||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, ((SValue){.type = pTColumn->type, .val = rowTs}));
|
||||
taosArraySet(pColArray, 0, &(SLastCol){.rowKey.ts = rowTs, .colVal = *pColVal});
|
||||
*pColVal = COL_VAL_VALUE(pTColumn->colId, ((SValue){.type = pTColumn->type, .val = rowKey.key.ts}));
|
||||
taosArraySet(pColArray, 0, &(SLastCol){.rowKey = rowKey.key, .colVal = *pColVal});
|
||||
continue;
|
||||
}
|
||||
tsdbRowGetColVal(pRow, pTSchema, slotIds[iCol], pColVal);
|
||||
|
||||
*pCol = (SLastCol){.rowKey.ts = rowTs, .colVal = *pColVal};
|
||||
*pCol = (SLastCol){.rowKey = rowKey.key, .colVal = *pColVal};
|
||||
if (IS_VAR_DATA_TYPE(pColVal->value.type) /*&& pColVal->value.nData > 0*/) {
|
||||
if (pColVal->value.nData > 0) {
|
||||
pCol->colVal.value.pData = taosMemoryMalloc(pCol->colVal.value.nData);
|
||||
|
|
|
@ -139,7 +139,8 @@ static int32_t tsdbUpgradeHead(STsdb *tsdb, SDFileSet *pDFileSet, SDataFReader *
|
|||
|
||||
if (ctx->brinBlock->numOfRecords >= ctx->maxRow) {
|
||||
SVersionRange range = {.minVer = VERSION_MAX, .maxVer = VERSION_MIN};
|
||||
code = tsdbFileWriteBrinBlock(ctx->fd, ctx->brinBlock, ctx->cmprAlg, &fset->farr[TSDB_FTYPE_HEAD]->f->size,
|
||||
code =
|
||||
tsdbFileWriteBrinBlock(ctx->fd, ctx->brinBlock, ctx->cmprAlg, &fset->farr[TSDB_FTYPE_HEAD]->f->size,
|
||||
ctx->brinBlkArray, ctx->buffers, &range, ctx->encryptAlgorithm, ctx->encryptKey);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
@ -542,8 +543,8 @@ static int32_t tsdbDumpTombDataToFSet(STsdb *tsdb, SDelFReader *reader, SArray *
|
|||
ctx->encryptAlgorithm, ctx->encryptKey);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
code = tsdbFileWriteSttFooter(ctx->fd, ctx->sttFooter, &ctx->fobj->f->size, ctx->encryptAlgorithm,
|
||||
ctx->encryptKey);
|
||||
code =
|
||||
tsdbFileWriteSttFooter(ctx->fd, ctx->sttFooter, &ctx->fobj->f->size, ctx->encryptAlgorithm, ctx->encryptKey);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
} else {
|
||||
code = tsdbFileWriteTombBlk(ctx->fd, ctx->tombBlkArray, ctx->tombFooter->tombBlkPtr, &ctx->fobj->f->size,
|
||||
|
|
|
@ -17,17 +17,24 @@
|
|||
|
||||
// SDelBlock ----------
|
||||
int32_t tTombBlockInit(STombBlock *tombBlock) {
|
||||
int32_t code;
|
||||
|
||||
tombBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
||||
tBufferInit(&tombBlock->buffers[i]);
|
||||
TAOS_CHECK_GOTO(tBufferInit(&tombBlock->buffers[i]), NULL, _exit);
|
||||
}
|
||||
return 0;
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TAOS_UNUSED(tTombBlockDestroy(tombBlock));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tTombBlockDestroy(STombBlock *tombBlock) {
|
||||
tombBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
||||
tBufferDestroy(&tombBlock->buffers[i]);
|
||||
TAOS_UNUSED(tBufferDestroy(&tombBlock->buffers[i]));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -35,15 +42,14 @@ int32_t tTombBlockDestroy(STombBlock *tombBlock) {
|
|||
int32_t tTombBlockClear(STombBlock *tombBlock) {
|
||||
tombBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
||||
tBufferClear(&tombBlock->buffers[i]);
|
||||
TAOS_UNUSED(tBufferClear(&tombBlock->buffers[i]));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tTombBlockPut(STombBlock *tombBlock, const STombRecord *record) {
|
||||
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
||||
int32_t code = tBufferPutI64(&tombBlock->buffers[i], record->data[i]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&tombBlock->buffers[i], record->data[i]));
|
||||
}
|
||||
tombBlock->numOfRecords++;
|
||||
return 0;
|
||||
|
@ -56,8 +62,7 @@ int32_t tTombBlockGet(STombBlock *tombBlock, int32_t idx, STombRecord *record) {
|
|||
|
||||
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
||||
SBufferReader br = BUFFER_READER_INITIALIZER(sizeof(int64_t) * idx, &tombBlock->buffers[i]);
|
||||
int32_t code = tBufferGetI64(&br, &record->data[i]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&br, &record->data[i]));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -74,27 +79,34 @@ int32_t tTombRecordCompare(const STombRecord *r1, const STombRecord *r2) {
|
|||
|
||||
// STbStatisBlock ----------
|
||||
int32_t tStatisBlockInit(STbStatisBlock *statisBlock) {
|
||||
int32_t code;
|
||||
|
||||
statisBlock->numOfPKs = 0;
|
||||
statisBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < ARRAY_SIZE(statisBlock->buffers); ++i) {
|
||||
tBufferInit(&statisBlock->buffers[i]);
|
||||
TAOS_CHECK_GOTO(tBufferInit(&statisBlock->buffers[i]), NULL, _exit);
|
||||
}
|
||||
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||
tValueColumnInit(&statisBlock->firstKeyPKs[i]);
|
||||
tValueColumnInit(&statisBlock->lastKeyPKs[i]);
|
||||
TAOS_CHECK_GOTO(tValueColumnInit(&statisBlock->firstKeyPKs[i]), NULL, _exit);
|
||||
TAOS_CHECK_GOTO(tValueColumnInit(&statisBlock->lastKeyPKs[i]), NULL, _exit);
|
||||
}
|
||||
return 0;
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TAOS_UNUSED(tStatisBlockDestroy(statisBlock));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tStatisBlockDestroy(STbStatisBlock *statisBlock) {
|
||||
statisBlock->numOfPKs = 0;
|
||||
statisBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < ARRAY_SIZE(statisBlock->buffers); ++i) {
|
||||
tBufferDestroy(&statisBlock->buffers[i]);
|
||||
TAOS_UNUSED(tBufferDestroy(&statisBlock->buffers[i]));
|
||||
}
|
||||
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||
tValueColumnDestroy(&statisBlock->firstKeyPKs[i]);
|
||||
tValueColumnDestroy(&statisBlock->lastKeyPKs[i]);
|
||||
TAOS_UNUSED(tValueColumnDestroy(&statisBlock->firstKeyPKs[i]));
|
||||
TAOS_UNUSED(tValueColumnDestroy(&statisBlock->lastKeyPKs[i]));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -103,17 +115,16 @@ int32_t tStatisBlockClear(STbStatisBlock *statisBlock) {
|
|||
statisBlock->numOfPKs = 0;
|
||||
statisBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < ARRAY_SIZE(statisBlock->buffers); ++i) {
|
||||
tBufferClear(&statisBlock->buffers[i]);
|
||||
TAOS_UNUSED(tBufferClear(&statisBlock->buffers[i]));
|
||||
}
|
||||
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||
tValueColumnClear(&statisBlock->firstKeyPKs[i]);
|
||||
tValueColumnClear(&statisBlock->lastKeyPKs[i]);
|
||||
TAOS_UNUSED(tValueColumnClear(&statisBlock->firstKeyPKs[i]));
|
||||
TAOS_UNUSED(tValueColumnClear(&statisBlock->lastKeyPKs[i]));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tStatisBlockAppend(STbStatisBlock *block, SRowInfo *row) {
|
||||
int32_t code;
|
||||
STsdbRowKey key;
|
||||
|
||||
tsdbRowGetKey(&row->row, &key);
|
||||
|
@ -129,14 +140,14 @@ static int32_t tStatisBlockAppend(STbStatisBlock *block, SRowInfo *row) {
|
|||
}
|
||||
}
|
||||
|
||||
if ((code = tBufferPutI64(&block->suids, row->suid))) return code;
|
||||
if ((code = tBufferPutI64(&block->uids, row->uid))) return code;
|
||||
if ((code = tBufferPutI64(&block->firstKeyTimestamps, key.key.ts))) return code;
|
||||
if ((code = tBufferPutI64(&block->lastKeyTimestamps, key.key.ts))) return code;
|
||||
if ((code = tBufferPutI64(&block->counts, 1))) return code;
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&block->suids, row->suid));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&block->uids, row->uid));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&block->firstKeyTimestamps, key.key.ts));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&block->lastKeyTimestamps, key.key.ts));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&block->counts, 1));
|
||||
for (int32_t i = 0; i < block->numOfPKs; ++i) {
|
||||
if ((code = tValueColumnAppend(block->firstKeyPKs + i, key.key.pks + i))) return code;
|
||||
if ((code = tValueColumnAppend(block->lastKeyPKs + i, key.key.pks + i))) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnAppend(block->firstKeyPKs + i, key.key.pks + i));
|
||||
TAOS_CHECK_RETURN(tValueColumnAppend(block->lastKeyPKs + i, key.key.pks + i));
|
||||
}
|
||||
|
||||
block->numOfRecords++;
|
||||
|
@ -147,9 +158,8 @@ static int32_t tStatisBlockUpdate(STbStatisBlock *block, SRowInfo *row) {
|
|||
STbStatisRecord record;
|
||||
STsdbRowKey key;
|
||||
int32_t c;
|
||||
int32_t code;
|
||||
|
||||
tStatisBlockGet(block, block->numOfRecords - 1, &record);
|
||||
TAOS_CHECK_RETURN(tStatisBlockGet(block, block->numOfRecords - 1, &record));
|
||||
tsdbRowGetKey(&row->row, &key);
|
||||
|
||||
c = tRowKeyCompare(&record.lastKey, &key.key);
|
||||
|
@ -157,21 +167,18 @@ static int32_t tStatisBlockUpdate(STbStatisBlock *block, SRowInfo *row) {
|
|||
return 0;
|
||||
} else if (c < 0) {
|
||||
// last ts
|
||||
code = tBufferPutAt(&block->lastKeyTimestamps, (block->numOfRecords - 1) * sizeof(record.lastKey.ts), &key.key.ts,
|
||||
sizeof(key.key.ts));
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferPutAt(&block->lastKeyTimestamps, (block->numOfRecords - 1) * sizeof(record.lastKey.ts),
|
||||
&key.key.ts, sizeof(key.key.ts)));
|
||||
|
||||
// last primary keys
|
||||
for (int i = 0; i < block->numOfPKs; i++) {
|
||||
code = tValueColumnUpdate(&block->lastKeyPKs[i], block->numOfRecords - 1, &key.key.pks[i]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnUpdate(&block->lastKeyPKs[i], block->numOfRecords - 1, &key.key.pks[i]));
|
||||
}
|
||||
|
||||
// count
|
||||
record.count++;
|
||||
code = tBufferPutAt(&block->counts, (block->numOfRecords - 1) * sizeof(record.count), &record.count,
|
||||
sizeof(record.count));
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferPutAt(&block->counts, (block->numOfRecords - 1) * sizeof(record.count), &record.count,
|
||||
sizeof(record.count)));
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
@ -183,8 +190,7 @@ int32_t tStatisBlockPut(STbStatisBlock *block, SRowInfo *row, int32_t maxRecords
|
|||
if (block->numOfRecords > 0) {
|
||||
int64_t lastUid;
|
||||
SBufferReader br = BUFFER_READER_INITIALIZER(sizeof(int64_t) * (block->numOfRecords - 1), &block->uids);
|
||||
int32_t code = tBufferGetI64(&br, &lastUid);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&br, &lastUid));
|
||||
|
||||
if (lastUid == row->uid) {
|
||||
return tStatisBlockUpdate(block, row);
|
||||
|
@ -196,7 +202,6 @@ int32_t tStatisBlockPut(STbStatisBlock *block, SRowInfo *row, int32_t maxRecords
|
|||
}
|
||||
|
||||
int32_t tStatisBlockGet(STbStatisBlock *statisBlock, int32_t idx, STbStatisRecord *record) {
|
||||
int32_t code;
|
||||
SBufferReader reader;
|
||||
|
||||
if (idx < 0 || idx >= statisBlock->numOfRecords) {
|
||||
|
@ -204,36 +209,29 @@ int32_t tStatisBlockGet(STbStatisBlock *statisBlock, int32_t idx, STbStatisRecor
|
|||
}
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(record->suid), &statisBlock->suids);
|
||||
code = tBufferGetI64(&reader, &record->suid);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->suid));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(record->uid), &statisBlock->uids);
|
||||
code = tBufferGetI64(&reader, &record->uid);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->uid));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(record->firstKey.ts), &statisBlock->firstKeyTimestamps);
|
||||
code = tBufferGetI64(&reader, &record->firstKey.ts);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->firstKey.ts));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(record->lastKey.ts), &statisBlock->lastKeyTimestamps);
|
||||
code = tBufferGetI64(&reader, &record->lastKey.ts);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->lastKey.ts));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(record->count), &statisBlock->counts);
|
||||
code = tBufferGetI64(&reader, &record->count);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->count));
|
||||
|
||||
// primary keys
|
||||
for (record->firstKey.numOfPKs = 0; record->firstKey.numOfPKs < statisBlock->numOfPKs; record->firstKey.numOfPKs++) {
|
||||
code = tValueColumnGet(&statisBlock->firstKeyPKs[record->firstKey.numOfPKs], idx,
|
||||
&record->firstKey.pks[record->firstKey.numOfPKs]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnGet(&statisBlock->firstKeyPKs[record->firstKey.numOfPKs], idx,
|
||||
&record->firstKey.pks[record->firstKey.numOfPKs]));
|
||||
}
|
||||
|
||||
for (record->lastKey.numOfPKs = 0; record->lastKey.numOfPKs < statisBlock->numOfPKs; record->lastKey.numOfPKs++) {
|
||||
code = tValueColumnGet(&statisBlock->lastKeyPKs[record->lastKey.numOfPKs], idx,
|
||||
&record->lastKey.pks[record->lastKey.numOfPKs]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnGet(&statisBlock->lastKeyPKs[record->lastKey.numOfPKs], idx,
|
||||
&record->lastKey.pks[record->lastKey.numOfPKs]));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -241,27 +239,34 @@ int32_t tStatisBlockGet(STbStatisBlock *statisBlock, int32_t idx, STbStatisRecor
|
|||
|
||||
// SBrinRecord ----------
|
||||
int32_t tBrinBlockInit(SBrinBlock *brinBlock) {
|
||||
int32_t code;
|
||||
|
||||
brinBlock->numOfPKs = 0;
|
||||
brinBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->buffers); ++i) {
|
||||
tBufferInit(&brinBlock->buffers[i]);
|
||||
TAOS_CHECK_GOTO(tBufferInit(&brinBlock->buffers[i]), NULL, _exit);
|
||||
}
|
||||
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||
tValueColumnInit(&brinBlock->firstKeyPKs[i]);
|
||||
tValueColumnInit(&brinBlock->lastKeyPKs[i]);
|
||||
TAOS_CHECK_GOTO(tValueColumnInit(&brinBlock->firstKeyPKs[i]), NULL, _exit);
|
||||
TAOS_CHECK_GOTO(tValueColumnInit(&brinBlock->lastKeyPKs[i]), NULL, _exit);
|
||||
}
|
||||
return 0;
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TAOS_UNUSED(tBrinBlockDestroy(brinBlock));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tBrinBlockDestroy(SBrinBlock *brinBlock) {
|
||||
brinBlock->numOfPKs = 0;
|
||||
brinBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->buffers); ++i) {
|
||||
tBufferDestroy(&brinBlock->buffers[i]);
|
||||
TAOS_UNUSED(tBufferDestroy(&brinBlock->buffers[i]));
|
||||
}
|
||||
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||
tValueColumnDestroy(&brinBlock->firstKeyPKs[i]);
|
||||
tValueColumnDestroy(&brinBlock->lastKeyPKs[i]);
|
||||
TAOS_UNUSED(tValueColumnDestroy(&brinBlock->firstKeyPKs[i]));
|
||||
TAOS_UNUSED(tValueColumnDestroy(&brinBlock->lastKeyPKs[i]));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -270,18 +275,16 @@ int32_t tBrinBlockClear(SBrinBlock *brinBlock) {
|
|||
brinBlock->numOfPKs = 0;
|
||||
brinBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->buffers); ++i) {
|
||||
tBufferClear(&brinBlock->buffers[i]);
|
||||
TAOS_UNUSED(tBufferClear(&brinBlock->buffers[i]));
|
||||
}
|
||||
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||
tValueColumnClear(&brinBlock->firstKeyPKs[i]);
|
||||
tValueColumnClear(&brinBlock->lastKeyPKs[i]);
|
||||
TAOS_UNUSED(tValueColumnClear(&brinBlock->firstKeyPKs[i]));
|
||||
TAOS_UNUSED(tValueColumnClear(&brinBlock->lastKeyPKs[i]));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tBrinBlockPut(SBrinBlock *brinBlock, const SBrinRecord *record) {
|
||||
int32_t code;
|
||||
|
||||
ASSERT(record->firstKey.key.numOfPKs == record->lastKey.key.numOfPKs);
|
||||
|
||||
if (brinBlock->numOfRecords == 0) { // the first row
|
||||
|
@ -298,60 +301,29 @@ int32_t tBrinBlockPut(SBrinBlock *brinBlock, const SBrinRecord *record) {
|
|||
}
|
||||
}
|
||||
|
||||
code = tBufferPutI64(&brinBlock->suids, record->suid);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->uids, record->uid);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->firstKeyTimestamps, record->firstKey.key.ts);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->firstKeyVersions, record->firstKey.version);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->lastKeyTimestamps, record->lastKey.key.ts);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->lastKeyVersions, record->lastKey.version);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->minVers, record->minVer);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->maxVers, record->maxVer);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->blockOffsets, record->blockOffset);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->smaOffsets, record->smaOffset);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI32(&brinBlock->blockSizes, record->blockSize);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI32(&brinBlock->blockKeySizes, record->blockKeySize);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI32(&brinBlock->smaSizes, record->smaSize);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI32(&brinBlock->numRows, record->numRow);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI32(&brinBlock->counts, record->count);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->suids, record->suid));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->uids, record->uid));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->firstKeyTimestamps, record->firstKey.key.ts));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->firstKeyVersions, record->firstKey.version));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->lastKeyTimestamps, record->lastKey.key.ts));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->lastKeyVersions, record->lastKey.version));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->minVers, record->minVer));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->maxVers, record->maxVer));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->blockOffsets, record->blockOffset));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->smaOffsets, record->smaOffset));
|
||||
TAOS_CHECK_RETURN(tBufferPutI32(&brinBlock->blockSizes, record->blockSize));
|
||||
TAOS_CHECK_RETURN(tBufferPutI32(&brinBlock->blockKeySizes, record->blockKeySize));
|
||||
TAOS_CHECK_RETURN(tBufferPutI32(&brinBlock->smaSizes, record->smaSize));
|
||||
TAOS_CHECK_RETURN(tBufferPutI32(&brinBlock->numRows, record->numRow));
|
||||
TAOS_CHECK_RETURN(tBufferPutI32(&brinBlock->counts, record->count));
|
||||
|
||||
if (brinBlock->numOfPKs > 0) {
|
||||
for (int32_t i = 0; i < brinBlock->numOfPKs; ++i) {
|
||||
code = tValueColumnAppend(&brinBlock->firstKeyPKs[i], &record->firstKey.key.pks[i]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnAppend(&brinBlock->firstKeyPKs[i], &record->firstKey.key.pks[i]));
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < brinBlock->numOfPKs; ++i) {
|
||||
code = tValueColumnAppend(&brinBlock->lastKeyPKs[i], &record->lastKey.key.pks[i]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnAppend(&brinBlock->lastKeyPKs[i], &record->lastKey.key.pks[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -361,7 +333,6 @@ int32_t tBrinBlockPut(SBrinBlock *brinBlock, const SBrinRecord *record) {
|
|||
}
|
||||
|
||||
int32_t tBrinBlockGet(SBrinBlock *brinBlock, int32_t idx, SBrinRecord *record) {
|
||||
int32_t code;
|
||||
SBufferReader reader;
|
||||
|
||||
if (idx < 0 || idx >= brinBlock->numOfRecords) {
|
||||
|
@ -369,78 +340,61 @@ int32_t tBrinBlockGet(SBrinBlock *brinBlock, int32_t idx, SBrinRecord *record) {
|
|||
}
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->suids);
|
||||
code = tBufferGetI64(&reader, &record->suid);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->suid));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->uids);
|
||||
code = tBufferGetI64(&reader, &record->uid);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->uid));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->firstKeyTimestamps);
|
||||
code = tBufferGetI64(&reader, &record->firstKey.key.ts);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->firstKey.key.ts));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->firstKeyVersions);
|
||||
code = tBufferGetI64(&reader, &record->firstKey.version);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->firstKey.version));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->lastKeyTimestamps);
|
||||
code = tBufferGetI64(&reader, &record->lastKey.key.ts);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->lastKey.key.ts));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->lastKeyVersions);
|
||||
code = tBufferGetI64(&reader, &record->lastKey.version);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->lastKey.version));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->minVers);
|
||||
code = tBufferGetI64(&reader, &record->minVer);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->minVer));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->maxVers);
|
||||
code = tBufferGetI64(&reader, &record->maxVer);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->maxVer));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->blockOffsets);
|
||||
code = tBufferGetI64(&reader, &record->blockOffset);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->blockOffset));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->smaOffsets);
|
||||
code = tBufferGetI64(&reader, &record->smaOffset);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->smaOffset));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int32_t), &brinBlock->blockSizes);
|
||||
code = tBufferGetI32(&reader, &record->blockSize);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI32(&reader, &record->blockSize));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int32_t), &brinBlock->blockKeySizes);
|
||||
code = tBufferGetI32(&reader, &record->blockKeySize);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI32(&reader, &record->blockKeySize));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int32_t), &brinBlock->smaSizes);
|
||||
code = tBufferGetI32(&reader, &record->smaSize);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI32(&reader, &record->smaSize));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int32_t), &brinBlock->numRows);
|
||||
code = tBufferGetI32(&reader, &record->numRow);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI32(&reader, &record->numRow));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int32_t), &brinBlock->counts);
|
||||
code = tBufferGetI32(&reader, &record->count);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI32(&reader, &record->count));
|
||||
|
||||
// primary keys
|
||||
for (record->firstKey.key.numOfPKs = 0; record->firstKey.key.numOfPKs < brinBlock->numOfPKs;
|
||||
record->firstKey.key.numOfPKs++) {
|
||||
code = tValueColumnGet(&brinBlock->firstKeyPKs[record->firstKey.key.numOfPKs], idx,
|
||||
&record->firstKey.key.pks[record->firstKey.key.numOfPKs]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnGet(&brinBlock->firstKeyPKs[record->firstKey.key.numOfPKs], idx,
|
||||
&record->firstKey.key.pks[record->firstKey.key.numOfPKs]));
|
||||
}
|
||||
|
||||
for (record->lastKey.key.numOfPKs = 0; record->lastKey.key.numOfPKs < brinBlock->numOfPKs;
|
||||
record->lastKey.key.numOfPKs++) {
|
||||
code = tValueColumnGet(&brinBlock->lastKeyPKs[record->lastKey.key.numOfPKs], idx,
|
||||
&record->lastKey.key.pks[record->lastKey.key.numOfPKs]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnGet(&brinBlock->lastKeyPKs[record->lastKey.key.numOfPKs], idx,
|
||||
&record->lastKey.key.pks[record->lastKey.key.numOfPKs]));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -130,9 +130,11 @@ static int32_t getStatus(SDataDeleterHandle* pDeleter) {
|
|||
|
||||
static int32_t putDataBlock(SDataSinkHandle* pHandle, const SInputData* pInput, bool* pContinue) {
|
||||
SDataDeleterHandle* pDeleter = (SDataDeleterHandle*)pHandle;
|
||||
SDataDeleterBuf* pBuf = taosAllocateQitem(sizeof(SDataDeleterBuf), DEF_QITEM, 0);
|
||||
if (NULL == pBuf) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
SDataDeleterBuf* pBuf;
|
||||
|
||||
int32_t code = taosAllocateQitem(sizeof(SDataDeleterBuf), DEF_QITEM, 0, (void**)&pBuf);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
if (!allocBuf(pDeleter, pInput, pBuf)) {
|
||||
|
@ -270,12 +272,11 @@ int32_t createDataDeleter(SDataSinkManager* pManager, const SDataSinkNode* pData
|
|||
deleter->pParam = pParam;
|
||||
deleter->status = DS_BUF_EMPTY;
|
||||
deleter->queryEnd = false;
|
||||
deleter->pDataBlocks = taosOpenQueue();
|
||||
taosThreadMutexInit(&deleter->mutex, NULL);
|
||||
if (NULL == deleter->pDataBlocks) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = taosOpenQueue(&deleter->pDataBlocks);
|
||||
if (code) {
|
||||
goto _end;
|
||||
}
|
||||
taosThreadMutexInit(&deleter->mutex, NULL);
|
||||
|
||||
*pHandle = deleter;
|
||||
return code;
|
||||
|
|
|
@ -104,7 +104,8 @@ static void toDataCacheEntry(SDataDispatchHandle* pHandle, const SInputData* pIn
|
|||
}
|
||||
|
||||
int32_t dataLen = blockEncode(pInput->pData, pHandle->pCompressBuf, numOfCols);
|
||||
int32_t len = tsCompressString(pHandle->pCompressBuf, dataLen, 1, pEntry->data, pBuf->allocSize, ONE_STAGE_COMP, NULL, 0);
|
||||
int32_t len =
|
||||
tsCompressString(pHandle->pCompressBuf, dataLen, 1, pEntry->data, pBuf->allocSize, ONE_STAGE_COMP, NULL, 0);
|
||||
if (len < dataLen) {
|
||||
pEntry->compressed = 1;
|
||||
pEntry->dataLen = len;
|
||||
|
@ -168,9 +169,11 @@ static int32_t getStatus(SDataDispatchHandle* pDispatcher) {
|
|||
static int32_t putDataBlock(SDataSinkHandle* pHandle, const SInputData* pInput, bool* pContinue) {
|
||||
int32_t code = 0;
|
||||
SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
|
||||
SDataDispatchBuf* pBuf = taosAllocateQitem(sizeof(SDataDispatchBuf), DEF_QITEM, 0);
|
||||
if (NULL == pBuf) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
SDataDispatchBuf* pBuf;
|
||||
|
||||
code = taosAllocateQitem(sizeof(SDataDispatchBuf), DEF_QITEM, 0, (void**)&pBuf);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
if (!allocBuf(pDispatcher, pInput, pBuf)) {
|
||||
|
@ -228,7 +231,6 @@ static void getDataLength(SDataSinkHandle* pHandle, int64_t* pLen, int64_t* pRow
|
|||
((SDataCacheEntry*)(pDispatcher->nextOutput.pData))->numOfRows);
|
||||
}
|
||||
|
||||
|
||||
static int32_t getDataBlock(SDataSinkHandle* pHandle, SOutputData* pOutput) {
|
||||
SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
|
||||
if (NULL == pDispatcher->nextOutput.pData) {
|
||||
|
@ -291,6 +293,8 @@ static int32_t getCacheSize(struct SDataSinkHandle* pHandle, uint64_t* size) {
|
|||
}
|
||||
|
||||
int32_t createDataDispatcher(SDataSinkManager* pManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle) {
|
||||
int32_t code;
|
||||
|
||||
SDataDispatchHandle* dispatcher = taosMemoryCalloc(1, sizeof(SDataDispatchHandle));
|
||||
if (NULL == dispatcher) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -309,7 +313,11 @@ int32_t createDataDispatcher(SDataSinkManager* pManager, const SDataSinkNode* pD
|
|||
dispatcher->pSchema = pDataSink->pInputDataBlockDesc;
|
||||
dispatcher->status = DS_BUF_EMPTY;
|
||||
dispatcher->queryEnd = false;
|
||||
dispatcher->pDataBlocks = taosOpenQueue();
|
||||
code = taosOpenQueue(&dispatcher->pDataBlocks);
|
||||
if (code) {
|
||||
terrno = code;
|
||||
goto _return;
|
||||
}
|
||||
taosThreadMutexInit(&dispatcher->mutex, NULL);
|
||||
|
||||
if (NULL == dispatcher->pDataBlocks) {
|
||||
|
|
|
@ -47,7 +47,7 @@ typedef struct STranslateContext {
|
|||
SNode* pPostRoot;
|
||||
} STranslateContext;
|
||||
|
||||
bool biRewriteToTbnameFunc(STranslateContext* pCxt, SNode** ppNode);
|
||||
int32_t biRewriteToTbnameFunc(STranslateContext* pCxt, SNode** ppNode, bool* pRet);
|
||||
int32_t biRewriteSelectStar(STranslateContext* pCxt, SSelectStmt* pSelect);
|
||||
int32_t biCheckCreateTableTbnameCol(STranslateContext* pCxt, SCreateTableStmt* pStmt);
|
||||
int32_t findTable(STranslateContext* pCxt, const char* pTableAlias, STableNode** pOutput);
|
||||
|
|
|
@ -509,7 +509,7 @@ cmd ::= SHOW USERS FULL.
|
|||
cmd ::= SHOW USER PRIVILEGES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USER_PRIVILEGES_STMT); }
|
||||
cmd ::= SHOW db_kind_opt(A) DATABASES. {
|
||||
pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT);
|
||||
setShowKind(pCxt, pCxt->pRootNode, A);
|
||||
(void)setShowKind(pCxt, pCxt->pRootNode, A);
|
||||
}
|
||||
cmd ::= SHOW table_kind_db_name_cond_opt(A) TABLES like_pattern_opt(B). {
|
||||
pCxt->pRootNode = createShowTablesStmt(pCxt, A, B, OP_TYPE_LIKE);
|
||||
|
|
|
@ -101,7 +101,7 @@ static bool checkPassword(SAstCreateContext* pCxt, const SToken* pPasswordToken,
|
|||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG);
|
||||
} else {
|
||||
strncpy(pPassword, pPasswordToken->z, pPasswordToken->n);
|
||||
strdequote(pPassword);
|
||||
(void)strdequote(pPassword);
|
||||
if (strtrim(pPassword) <= 0) {
|
||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_PASSWD_EMPTY);
|
||||
} else if (invalidPassword(pPassword)) {
|
||||
|
@ -126,8 +126,8 @@ static int32_t parseEndpoint(SAstCreateContext* pCxt, const SToken* pEp, char* p
|
|||
|
||||
char ep[TSDB_FQDN_LEN + 1 + 5] = {0};
|
||||
COPY_STRING_FORM_ID_TOKEN(ep, pEp);
|
||||
strdequote(ep);
|
||||
strtrim(ep);
|
||||
(void)strdequote(ep);
|
||||
(void)strtrim(ep);
|
||||
if (NULL == pPort) {
|
||||
strcpy(pFqdn, ep);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -371,7 +371,7 @@ SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken*
|
|||
val->literal = strndup(pLiteral->z, pLiteral->n);
|
||||
if (TK_NK_ID != pLiteral->type && TK_TIMEZONE != pLiteral->type &&
|
||||
(IS_VAR_DATA_TYPE(dataType) || TSDB_DATA_TYPE_TIMESTAMP == dataType)) {
|
||||
trimString(pLiteral->z, pLiteral->n, val->literal, pLiteral->n);
|
||||
(void)trimString(pLiteral->z, pLiteral->n, val->literal, pLiteral->n);
|
||||
}
|
||||
CHECK_OUT_OF_MEM(val->literal);
|
||||
val->node.resType.type = dataType;
|
||||
|
@ -784,7 +784,10 @@ SNode* createPlaceholderValueNode(SAstCreateContext* pCxt, const SToken* pLitera
|
|||
return NULL;
|
||||
}
|
||||
}
|
||||
taosArrayPush(pCxt->pPlaceholderValues, &val);
|
||||
if (NULL == taosArrayPush(pCxt->pPlaceholderValues, &val)) {
|
||||
pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
return (SNode*)val;
|
||||
}
|
||||
|
||||
|
@ -905,7 +908,8 @@ SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType d
|
|||
} else if (TSDB_DATA_TYPE_NCHAR == dt.type) {
|
||||
func->node.resType.bytes = func->node.resType.bytes * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
|
||||
}
|
||||
nodesListMakeAppend(&func->pParameterList, pExpr);
|
||||
pCxt->errCode = nodesListMakeAppend(&func->pParameterList, pExpr);
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
return (SNode*)func;
|
||||
}
|
||||
|
||||
|
@ -923,8 +927,10 @@ SNode* createNodeListNodeEx(SAstCreateContext* pCxt, SNode* p1, SNode* p2) {
|
|||
CHECK_OUT_OF_MEM(list);
|
||||
list->pNodeList = nodesMakeList();
|
||||
CHECK_OUT_OF_MEM(list->pNodeList);
|
||||
nodesListAppend(list->pNodeList, p1);
|
||||
nodesListAppend(list->pNodeList, p2);
|
||||
pCxt->errCode = nodesListAppend(list->pNodeList, p1);
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
pCxt->errCode = nodesListAppend(list->pNodeList, p2);
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
return (SNode*)list;
|
||||
}
|
||||
|
||||
|
@ -1121,7 +1127,8 @@ SNode* createGroupingSetNode(SAstCreateContext* pCxt, SNode* pNode) {
|
|||
CHECK_OUT_OF_MEM(groupingSet);
|
||||
groupingSet->groupingSetType = GP_TYPE_NORMAL;
|
||||
groupingSet->pParameterList = nodesMakeList();
|
||||
nodesListAppend(groupingSet->pParameterList, pNode);
|
||||
pCxt->errCode = nodesListAppend(groupingSet->pParameterList, pNode);
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
return (SNode*)groupingSet;
|
||||
}
|
||||
|
||||
|
@ -1842,7 +1849,7 @@ SNode* createCreateSubTableFromFileClause(SAstCreateContext* pCxt, bool ignoreEx
|
|||
pStmt->ignoreExists = ignoreExists;
|
||||
pStmt->pSpecificTags = pSpecificTags;
|
||||
if (TK_NK_STRING == pFilePath->type) {
|
||||
trimString(pFilePath->z, pFilePath->n, pStmt->filePath, PATH_MAX);
|
||||
(void)trimString(pFilePath->z, pFilePath->n, pStmt->filePath, PATH_MAX);
|
||||
} else {
|
||||
strncpy(pStmt->filePath, pFilePath->z, pFilePath->n);
|
||||
}
|
||||
|
@ -2087,7 +2094,7 @@ SNode* createShowTablesStmt(SAstCreateContext* pCxt, SShowTablesOption option, S
|
|||
pDbName = createIdentifierValueNode(pCxt, &option.dbName);
|
||||
}
|
||||
SNode* pStmt = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TABLES_STMT, pDbName, pTbName, tableCondType);
|
||||
setShowKind(pCxt, pStmt, option.kind);
|
||||
(void)setShowKind(pCxt, pStmt, option.kind);
|
||||
return pStmt;
|
||||
}
|
||||
|
||||
|
@ -2408,9 +2415,9 @@ SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const
|
|||
} else {
|
||||
pStmt->dnodeId = -1;
|
||||
}
|
||||
trimString(pConfig->z, pConfig->n, pStmt->config, sizeof(pStmt->config));
|
||||
(void)trimString(pConfig->z, pConfig->n, pStmt->config, sizeof(pStmt->config));
|
||||
if (NULL != pValue) {
|
||||
trimString(pValue->z, pValue->n, pStmt->value, sizeof(pStmt->value));
|
||||
(void)trimString(pValue->z, pValue->n, pStmt->value, sizeof(pStmt->value));
|
||||
}
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
@ -2591,9 +2598,9 @@ SNode* createAlterClusterStmt(SAstCreateContext* pCxt, const SToken* pConfig, co
|
|||
CHECK_PARSER_STATUS(pCxt);
|
||||
SAlterClusterStmt* pStmt = (SAlterClusterStmt*)nodesMakeNode(QUERY_NODE_ALTER_CLUSTER_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
trimString(pConfig->z, pConfig->n, pStmt->config, sizeof(pStmt->config));
|
||||
(void)trimString(pConfig->z, pConfig->n, pStmt->config, sizeof(pStmt->config));
|
||||
if (NULL != pValue) {
|
||||
trimString(pValue->z, pValue->n, pStmt->value, sizeof(pStmt->value));
|
||||
(void)trimString(pValue->z, pValue->n, pStmt->value, sizeof(pStmt->value));
|
||||
}
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
@ -2602,9 +2609,9 @@ SNode* createAlterLocalStmt(SAstCreateContext* pCxt, const SToken* pConfig, cons
|
|||
CHECK_PARSER_STATUS(pCxt);
|
||||
SAlterLocalStmt* pStmt = (SAlterLocalStmt*)nodesMakeNode(QUERY_NODE_ALTER_LOCAL_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
trimString(pConfig->z, pConfig->n, pStmt->config, sizeof(pStmt->config));
|
||||
(void)trimString(pConfig->z, pConfig->n, pStmt->config, sizeof(pStmt->config));
|
||||
if (NULL != pValue) {
|
||||
trimString(pValue->z, pValue->n, pStmt->value, sizeof(pStmt->value));
|
||||
(void)trimString(pValue->z, pValue->n, pStmt->value, sizeof(pStmt->value));
|
||||
}
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
@ -2869,7 +2876,7 @@ SNode* createKillQueryStmt(SAstCreateContext* pCxt, const SToken* pQueryId) {
|
|||
CHECK_PARSER_STATUS(pCxt);
|
||||
SKillQueryStmt* pStmt = (SKillQueryStmt*)nodesMakeNode(QUERY_NODE_KILL_QUERY_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
trimString(pQueryId->z, pQueryId->n, pStmt->queryId, sizeof(pStmt->queryId) - 1);
|
||||
(void)trimString(pQueryId->z, pQueryId->n, pStmt->queryId, sizeof(pStmt->queryId) - 1);
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -158,7 +158,9 @@ int32_t cleanupTaskQueue() {
|
|||
}
|
||||
|
||||
int32_t taosAsyncExec(__async_exec_fn_t execFn, void* execParam, int32_t* code) {
|
||||
SSchedMsg* pSchedMsg = taosAllocateQitem(sizeof(SSchedMsg), DEF_QITEM, 0);
|
||||
SSchedMsg* pSchedMsg;
|
||||
int32_t rc = taosAllocateQitem(sizeof(SSchedMsg), DEF_QITEM, 0, (void **)&pSchedMsg);
|
||||
if (rc) return rc;
|
||||
pSchedMsg->fp = NULL;
|
||||
pSchedMsg->ahandle = execFn;
|
||||
pSchedMsg->thandle = execParam;
|
||||
|
|
|
@ -336,7 +336,7 @@ extern SSchedulerMgmt schMgmt;
|
|||
((_job)->attr.localExec && SCH_IS_QUERY_JOB(_job) && (!SCH_IS_INSERT_JOB(_job)) && \
|
||||
(!SCH_IS_DATA_BIND_QRY_TASK(_task)))
|
||||
|
||||
#define SCH_UPDATE_REDIRECT_CODE(job, _code) atomic_val_compare_exchange_32(&((job)->redirectCode), 0, _code)
|
||||
#define SCH_UPDATE_REDIRECT_CODE(job, _code) (void)atomic_val_compare_exchange_32(&((job)->redirectCode), 0, _code)
|
||||
#define SCH_GET_REDIRECT_CODE(job, _code) \
|
||||
(((!NO_RET_REDIRECT_ERROR(_code)) || (job)->redirectCode == 0) ? (_code) : (job)->redirectCode)
|
||||
|
||||
|
@ -413,7 +413,7 @@ extern SSchedulerMgmt schMgmt;
|
|||
#define SCH_LOG_TASK_START_TS(_task) \
|
||||
do { \
|
||||
int64_t us = taosGetTimestampUs(); \
|
||||
taosArrayPush((_task)->profile.execTime, &us); \
|
||||
(void)taosArrayPush((_task)->profile.execTime, &us); \
|
||||
if (0 == (_task)->execId) { \
|
||||
(_task)->profile.startTs = us; \
|
||||
} \
|
||||
|
@ -422,7 +422,10 @@ extern SSchedulerMgmt schMgmt;
|
|||
#define SCH_LOG_TASK_WAIT_TS(_task) \
|
||||
do { \
|
||||
int64_t us = taosGetTimestampUs(); \
|
||||
(_task)->profile.waitTime += us - *(int64_t *)taosArrayGet((_task)->profile.execTime, (_task)->execId); \
|
||||
int64_t* startus = (int64_t*)taosArrayGet((_task)->profile.execTime, (_task)->execId); \
|
||||
if (NULL != startus) { \
|
||||
(_task)->profile.waitTime += us - *startus; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define SCH_LOG_TASK_END_TS(_task) \
|
||||
|
@ -430,7 +433,9 @@ extern SSchedulerMgmt schMgmt;
|
|||
int64_t us = taosGetTimestampUs(); \
|
||||
int32_t idx = (_task)->execId % (_task)->maxExecTimes; \
|
||||
int64_t *startts = taosArrayGet((_task)->profile.execTime, (_task)->execId); \
|
||||
if (NULL != startts) { \
|
||||
*startts = us - *startts; \
|
||||
} \
|
||||
(_task)->profile.endTs = us; \
|
||||
} while (0)
|
||||
|
||||
|
@ -538,7 +543,7 @@ void schCleanClusterHb(void *pTrans);
|
|||
int32_t schLaunchTask(SSchJob *job, SSchTask *task);
|
||||
int32_t schDelayLaunchTask(SSchJob *pJob, SSchTask *pTask);
|
||||
int32_t schBuildAndSendMsg(SSchJob *job, SSchTask *task, SQueryNodeAddr *addr, int32_t msgType, void *param);
|
||||
SSchJob *schAcquireJob(int64_t refId);
|
||||
int32_t schAcquireJob(int64_t refId, SSchJob **ppJob);
|
||||
int32_t schReleaseJob(int64_t refId);
|
||||
void schFreeFlowCtrl(SSchJob *pJob);
|
||||
int32_t schChkJobNeedFlowCtrl(SSchJob *pJob, SSchLevel *pLevel);
|
||||
|
@ -578,7 +583,7 @@ int32_t schJobFetchRows(SSchJob *pJob);
|
|||
int32_t schJobFetchRowsA(SSchJob *pJob);
|
||||
int32_t schUpdateTaskHandle(SSchJob *pJob, SSchTask *pTask, bool dropExecNode, void *handle, int32_t execId);
|
||||
int32_t schProcessOnTaskStatusRsp(SQueryNodeEpId *pEpId, SArray *pStatusList);
|
||||
char *schDumpEpSet(SEpSet *pEpSet);
|
||||
int32_t schDumpEpSet(SEpSet *pEpSet, char** ppRes);
|
||||
char *schGetOpStr(SCH_OP_TYPE type);
|
||||
int32_t schBeginOperation(SSchJob *pJob, SCH_OP_TYPE type, bool sync);
|
||||
int32_t schInitJob(int64_t *pJobId, SSchedulerReq *pReq);
|
||||
|
|
|
@ -1165,7 +1165,9 @@ int32_t schProcessOnCbBegin(SSchJob **job, SSchTask **task, uint64_t qId, int64_
|
|||
int8_t status = 0;
|
||||
|
||||
SSchTask *pTask = NULL;
|
||||
SSchJob *pJob = schAcquireJob(rId);
|
||||
SSchJob *pJob = NULL;
|
||||
|
||||
(void)schAcquireJob(rId, &pJob);
|
||||
if (NULL == pJob) {
|
||||
qWarn("QID:0x%" PRIx64 ",TID:0x%" PRIx64 "job no exist, may be dropped, refId:0x%" PRIx64, qId, tId, rId);
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_JOB_NOT_EXIST);
|
||||
|
|
|
@ -113,7 +113,7 @@ int32_t schProcessFetchRsp(SSchJob *pJob, SSchTask *pTask, char *msg, int32_t rs
|
|||
}
|
||||
|
||||
atomic_store_ptr(&pJob->fetchRes, rsp);
|
||||
atomic_add_fetch_64(&pJob->resNumOfRows, htobe64(rsp->numOfRows));
|
||||
(void)atomic_add_fetch_64(&pJob->resNumOfRows, htobe64(rsp->numOfRows));
|
||||
|
||||
if (rsp->completed) {
|
||||
SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_SUCC);
|
||||
|
@ -166,13 +166,27 @@ int32_t schProcessResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SD
|
|||
SCH_LOCK(SCH_WRITE, &pJob->resLock);
|
||||
if (NULL == pJob->execRes.res) {
|
||||
pJob->execRes.res = (void*)taosArrayInit(batchRsp.nRsps, POINTER_BYTES);
|
||||
if (NULL == pJob->execRes.res) {
|
||||
code = terrno;
|
||||
SCH_UNLOCK(SCH_WRITE, &pJob->resLock);
|
||||
|
||||
tDecoderClear(&coder);
|
||||
SCH_ERR_JRET(code);
|
||||
}
|
||||
|
||||
pJob->execRes.msgType = TDMT_VND_CREATE_TABLE;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < batchRsp.nRsps; ++i) {
|
||||
SVCreateTbRsp *rsp = batchRsp.pRsps + i;
|
||||
if (rsp->pMeta) {
|
||||
taosArrayPush((SArray*)pJob->execRes.res, &rsp->pMeta);
|
||||
if (NULL == taosArrayPush((SArray*)pJob->execRes.res, &rsp->pMeta)) {
|
||||
code = terrno;
|
||||
SCH_UNLOCK(SCH_WRITE, &pJob->resLock);
|
||||
|
||||
tDecoderClear(&coder);
|
||||
SCH_ERR_JRET(code);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS != rsp->code) {
|
||||
|
@ -264,7 +278,7 @@ int32_t schProcessResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SD
|
|||
SCH_ERR_JRET(code);
|
||||
}
|
||||
|
||||
atomic_add_fetch_64(&pJob->resNumOfRows, rsp->affectedRows);
|
||||
(void)atomic_add_fetch_64(&pJob->resNumOfRows, rsp->affectedRows);
|
||||
|
||||
int32_t createTbRspNum = taosArrayGetSize(rsp->aCreateTbRsp);
|
||||
SCH_TASK_DLOG("submit succeed, affectedRows:%d, createTbRspNum:%d", rsp->affectedRows, createTbRspNum);
|
||||
|
@ -275,7 +289,12 @@ int32_t schProcessResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SD
|
|||
SSubmitRsp2 *sum = pJob->execRes.res;
|
||||
sum->affectedRows += rsp->affectedRows;
|
||||
if (sum->aCreateTbRsp) {
|
||||
taosArrayAddAll(sum->aCreateTbRsp, rsp->aCreateTbRsp);
|
||||
if (NULL == taosArrayAddAll(sum->aCreateTbRsp, rsp->aCreateTbRsp)) {
|
||||
code = terrno;
|
||||
SCH_UNLOCK(SCH_WRITE, &pJob->resLock);
|
||||
SCH_ERR_JRET(code);
|
||||
}
|
||||
|
||||
taosArrayDestroy(rsp->aCreateTbRsp);
|
||||
} else {
|
||||
TSWAP(sum->aCreateTbRsp, rsp->aCreateTbRsp);
|
||||
|
@ -313,10 +332,14 @@ int32_t schProcessResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SD
|
|||
SDecoder coder = {0};
|
||||
SVDeleteRsp rsp = {0};
|
||||
tDecoderInit(&coder, msg, msgSize);
|
||||
tDecodeSVDeleteRsp(&coder, &rsp);
|
||||
if (tDecodeSVDeleteRsp(&coder, &rsp) < 0) {
|
||||
code = terrno;
|
||||
tDecoderClear(&coder);
|
||||
SCH_ERR_JRET(code);
|
||||
}
|
||||
tDecoderClear(&coder);
|
||||
|
||||
atomic_add_fetch_64(&pJob->resNumOfRows, rsp.affectedRows);
|
||||
(void)atomic_add_fetch_64(&pJob->resNumOfRows, rsp.affectedRows);
|
||||
SCH_TASK_DLOG("delete succeed, affectedRows:%" PRId64, rsp.affectedRows);
|
||||
}
|
||||
|
||||
|
@ -351,7 +374,7 @@ int32_t schProcessResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SD
|
|||
|
||||
SCH_ERR_JRET(schSaveJobExecRes(pJob, &rsp));
|
||||
|
||||
atomic_add_fetch_64(&pJob->resNumOfRows, rsp.affectedRows);
|
||||
(void)atomic_add_fetch_64(&pJob->resNumOfRows, rsp.affectedRows);
|
||||
|
||||
taosMemoryFreeClear(msg);
|
||||
|
||||
|
@ -479,7 +502,7 @@ int32_t schHandleDropCallback(void *param, SDataBuf *pMsg, int32_t code) {
|
|||
qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 " drop task rsp received, code:0x%x", pParam->queryId, pParam->taskId,
|
||||
code);
|
||||
// called if drop task rsp received code
|
||||
rpcReleaseHandle(pMsg->handle, TAOS_CONN_CLIENT);
|
||||
(void)rpcReleaseHandle(pMsg->handle, TAOS_CONN_CLIENT); // ignore error
|
||||
if (pMsg) {
|
||||
taosMemoryFree(pMsg->pData);
|
||||
taosMemoryFree(pMsg->pEpSet);
|
||||
|
@ -501,7 +524,7 @@ int32_t schHandleNotifyCallback(void *param, SDataBuf *pMsg, int32_t code) {
|
|||
|
||||
int32_t schHandleLinkBrokenCallback(void *param, SDataBuf *pMsg, int32_t code) {
|
||||
SSchCallbackParamHeader *head = (SSchCallbackParamHeader *)param;
|
||||
rpcReleaseHandle(pMsg->handle, TAOS_CONN_CLIENT);
|
||||
(void)rpcReleaseHandle(pMsg->handle, TAOS_CONN_CLIENT); // ignore error
|
||||
|
||||
qDebug("handle %p is broken", pMsg->handle);
|
||||
|
||||
|
@ -531,7 +554,7 @@ int32_t schHandleHbCallback(void *param, SDataBuf *pMsg, int32_t code) {
|
|||
|
||||
if (code) {
|
||||
qError("hb rsp error:%s", tstrerror(code));
|
||||
rpcReleaseHandle(pMsg->handle, TAOS_CONN_CLIENT);
|
||||
(void)rpcReleaseHandle(pMsg->handle, TAOS_CONN_CLIENT); // ignore error
|
||||
SCH_ERR_JRET(code);
|
||||
}
|
||||
|
||||
|
@ -585,9 +608,14 @@ int32_t schMakeCallbackParam(SSchJob *pJob, SSchTask *pTask, int32_t msgType, bo
|
|||
param->head.isHbParam = true;
|
||||
|
||||
SQueryNodeAddr *addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx);
|
||||
if (NULL == addr) {
|
||||
taosMemoryFree(param);
|
||||
SCH_TASK_ELOG("fail to get the %dth condidateAddr, totalNum: %d", pTask->candidateIdx, (int32_t)taosArrayGetSize(pTask->candidateAddrs));
|
||||
SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR);
|
||||
}
|
||||
param->nodeEpId.nodeId = addr->nodeId;
|
||||
SEp *pEp = SCH_GET_CUR_EP(addr);
|
||||
strcpy(param->nodeEpId.ep.fqdn, pEp->fqdn);
|
||||
TAOS_STRCPY(param->nodeEpId.ep.fqdn, pEp->fqdn);
|
||||
param->nodeEpId.ep.port = pEp->port;
|
||||
param->pTrans = trans->pTrans;
|
||||
*pParam = param;
|
||||
|
@ -712,7 +740,7 @@ int32_t schMakeHbCallbackParam(SSchJob *pJob, SSchTask *pTask, void **pParam) {
|
|||
|
||||
int32_t schCloneHbRpcCtx(SRpcCtx *pSrc, SRpcCtx *pDst) {
|
||||
int32_t code = 0;
|
||||
memcpy(pDst, pSrc, sizeof(SRpcCtx));
|
||||
TAOS_MEMCPY(pDst, pSrc, sizeof(SRpcCtx));
|
||||
pDst->brokenVal.val = NULL;
|
||||
pDst->args = NULL;
|
||||
|
||||
|
@ -760,7 +788,7 @@ int32_t schMakeHbRpcCtx(SSchJob *pJob, SSchTask *pTask, SRpcCtx *pCtx) {
|
|||
SQueryNodeEpId epId = {0};
|
||||
|
||||
epId.nodeId = addr->nodeId;
|
||||
memcpy(&epId.ep, SCH_GET_CUR_EP(addr), sizeof(SEp));
|
||||
TAOS_MEMCPY(&epId.ep, SCH_GET_CUR_EP(addr), sizeof(SEp));
|
||||
|
||||
pCtx->args = taosHashInit(1, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK);
|
||||
if (NULL == pCtx->args) {
|
||||
|
@ -877,7 +905,7 @@ int32_t schCloneCallbackParam(SSchCallbackParamHeader *pSrc, SSchCallbackParamHe
|
|||
SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
memcpy(dst, pSrc, sizeof(*dst));
|
||||
TAOS_MEMCPY(dst, pSrc, sizeof(*dst));
|
||||
*pDst = (SSchCallbackParamHeader *)dst;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -889,7 +917,7 @@ int32_t schCloneCallbackParam(SSchCallbackParamHeader *pSrc, SSchCallbackParamHe
|
|||
SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
memcpy(dst, pSrc, sizeof(*dst));
|
||||
TAOS_MEMCPY(dst, pSrc, sizeof(*dst));
|
||||
*pDst = (SSchCallbackParamHeader *)dst;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -904,7 +932,7 @@ int32_t schCloneSMsgSendInfo(void *src, void **dst) {
|
|||
SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
memcpy(pDst, pSrc, sizeof(*pSrc));
|
||||
TAOS_MEMCPY(pDst, pSrc, sizeof(*pSrc));
|
||||
pDst->param = NULL;
|
||||
|
||||
SCH_ERR_JRET(schCloneCallbackParam(pSrc->param, (SSchCallbackParamHeader **)&pDst->param));
|
||||
|
@ -948,6 +976,10 @@ int32_t schAsyncSendMsg(SSchJob *pJob, SSchTask *pTask, SSchTrans *trans, SQuery
|
|||
|
||||
if (isHb && persistHandle && trans->pHandle == 0) {
|
||||
trans->pHandle = rpcAllocHandle();
|
||||
if (NULL == trans->pHandle) {
|
||||
SCH_TASK_ELOG("rpcAllocHandle failed, code:%x", terrno);
|
||||
SCH_ERR_JRET(terrno);
|
||||
}
|
||||
}
|
||||
|
||||
if (pJob && pTask) {
|
||||
|
@ -1000,7 +1032,7 @@ int32_t schBuildAndSendHbMsg(SQueryNodeEpId *nodeEpId, SArray *taskAction) {
|
|||
|
||||
req.header.vgId = nodeEpId->nodeId;
|
||||
req.sId = schMgmt.sId;
|
||||
memcpy(&req.epId, nodeEpId, sizeof(SQueryNodeEpId));
|
||||
TAOS_MEMCPY(&req.epId, nodeEpId, sizeof(SQueryNodeEpId));
|
||||
|
||||
SCH_LOCK(SCH_READ, &schMgmt.hbLock);
|
||||
SSchHbTrans *hb = taosHashGet(schMgmt.hbConnections, nodeEpId, sizeof(SQueryNodeEpId));
|
||||
|
@ -1013,7 +1045,7 @@ int32_t schBuildAndSendHbMsg(SQueryNodeEpId *nodeEpId, SArray *taskAction) {
|
|||
|
||||
SCH_LOCK(SCH_WRITE, &hb->lock);
|
||||
code = schCloneHbRpcCtx(&hb->rpcCtx, &rpcCtx);
|
||||
memcpy(&trans, &hb->trans, sizeof(trans));
|
||||
TAOS_MEMCPY(&trans, &hb->trans, sizeof(trans));
|
||||
SCH_UNLOCK(SCH_WRITE, &hb->lock);
|
||||
SCH_UNLOCK(SCH_READ, &schMgmt.hbLock);
|
||||
|
||||
|
@ -1039,7 +1071,7 @@ int32_t schBuildAndSendHbMsg(SQueryNodeEpId *nodeEpId, SArray *taskAction) {
|
|||
SQueryNodeAddr addr = {.nodeId = nodeEpId->nodeId};
|
||||
addr.epSet.inUse = 0;
|
||||
addr.epSet.numOfEps = 1;
|
||||
memcpy(&addr.epSet.eps[0], &nodeEpId->ep, sizeof(nodeEpId->ep));
|
||||
TAOS_MEMCPY(&addr.epSet.eps[0], &nodeEpId->ep, sizeof(nodeEpId->ep));
|
||||
|
||||
code = schAsyncSendMsg(NULL, NULL, &trans, &addr, msgType, msg, msgSize, true, &rpcCtx);
|
||||
msg = NULL;
|
||||
|
@ -1064,6 +1096,11 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr,
|
|||
|
||||
if (NULL == addr) {
|
||||
addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx);
|
||||
if (NULL == addr) {
|
||||
SCH_TASK_ELOG("fail to get condidateAddr, candidateIdx %d, totalNum: %d", pTask->candidateIdx, (int32_t)taosArrayGetSize(pTask->candidateAddrs));
|
||||
SCH_ERR_JRET(terrno);
|
||||
}
|
||||
|
||||
isCandidateAddr = true;
|
||||
SCH_TASK_DLOG("target candidateIdx %d, epInUse %d/%d", pTask->candidateIdx, addr->epSet.inUse,
|
||||
addr->epSet.numOfEps);
|
||||
|
@ -1082,7 +1119,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr,
|
|||
SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
memcpy(msg, pTask->msg, msgSize);
|
||||
TAOS_MEMCPY(msg, pTask->msg, msgSize);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1098,13 +1135,21 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr,
|
|||
req.msg = pTask->msg;
|
||||
req.source = pJob->source;
|
||||
msgSize = tSerializeSVDeleteReq(NULL, 0, &req);
|
||||
if (msgSize < 0) {
|
||||
SCH_TASK_ELOG("tSerializeSVDeleteReq failed, code:%x", terrno);
|
||||
SCH_ERR_JRET(terrno);
|
||||
}
|
||||
msg = taosMemoryCalloc(1, msgSize);
|
||||
if (NULL == msg) {
|
||||
SCH_TASK_ELOG("calloc %d failed", msgSize);
|
||||
SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
SCH_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
tSerializeSVDeleteReq(msg, msgSize, &req);
|
||||
msgSize = tSerializeSVDeleteReq(msg, msgSize, &req);
|
||||
if (msgSize < 0) {
|
||||
SCH_TASK_ELOG("tSerializeSVDeleteReq second failed, code:%x", terrno);
|
||||
SCH_ERR_JRET(terrno);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TDMT_SCH_QUERY:
|
||||
|
@ -1221,7 +1266,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr,
|
|||
req.sId = schMgmt.sId;
|
||||
req.header.vgId = addr->nodeId;
|
||||
req.epId.nodeId = addr->nodeId;
|
||||
memcpy(&req.epId.ep, SCH_GET_CUR_EP(addr), sizeof(SEp));
|
||||
TAOS_MEMCPY(&req.epId.ep, SCH_GET_CUR_EP(addr), sizeof(SEp));
|
||||
|
||||
msgSize = tSerializeSSchedulerHbReq(NULL, 0, &req);
|
||||
if (msgSize < 0) {
|
||||
|
|
|
@ -43,7 +43,7 @@ int32_t schSwitchJobStatus(SSchJob* pJob, int32_t status, void* param) {
|
|||
SCH_RET(schProcessOnJobFailure(pJob, (param ? *(int32_t*)param : 0)));
|
||||
break;
|
||||
case JOB_TASK_STATUS_DROP:
|
||||
schProcessOnJobDropped(pJob, *(int32_t*)param);
|
||||
(void)schProcessOnJobDropped(pJob, *(int32_t*)param); // ignore error
|
||||
|
||||
if (taosRemoveRef(schMgmt.jobRef, pJob->refId)) {
|
||||
SCH_JOB_ELOG("remove job from job list failed, refId:0x%" PRIx64, pJob->refId);
|
||||
|
@ -65,7 +65,8 @@ _return:
|
|||
}
|
||||
|
||||
int32_t schHandleOpBeginEvent(int64_t jobId, SSchJob** job, SCH_OP_TYPE type, SSchedulerReq* pReq) {
|
||||
SSchJob* pJob = schAcquireJob(jobId);
|
||||
SSchJob* pJob = NULL;
|
||||
(void)schAcquireJob(jobId, &pJob);
|
||||
if (NULL == pJob) {
|
||||
qDebug("Acquire sch job failed, may be dropped, jobId:0x%" PRIx64, jobId);
|
||||
SCH_ERR_RET(TSDB_CODE_SCH_JOB_NOT_EXISTS);
|
||||
|
@ -90,7 +91,7 @@ int32_t schHandleOpEndEvent(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq
|
|||
code = pJob->errCode;
|
||||
}
|
||||
|
||||
schReleaseJob(pJob->refId);
|
||||
(void)schReleaseJob(pJob->refId); // ignore error
|
||||
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -165,7 +165,7 @@ int32_t schUpdateTaskHandle(SSchJob *pJob, SSchTask *pTask, bool dropExecNode, v
|
|||
SCH_RET(schDropTaskExecNode(pJob, pTask, handle, execId));
|
||||
}
|
||||
|
||||
schUpdateTaskExecNode(pJob, pTask, handle, execId);
|
||||
SCH_ERR_RET(schUpdateTaskExecNode(pJob, pTask, handle, execId));
|
||||
|
||||
if ((execId != pTask->execId || execId <= pTask->failedExecId) || pTask->waitRetry) { // ignore it
|
||||
SCH_TASK_DLOG("handle not updated since execId %d is already not current execId %d, waitRetry %d", execId,
|
||||
|
@ -297,6 +297,10 @@ int32_t schProcessOnTaskSuccess(SSchJob *pJob, SSchTask *pTask) {
|
|||
|
||||
for (int32_t i = 0; i < parentNum; ++i) {
|
||||
SSchTask *parent = *(SSchTask **)taosArrayGet(pTask->parents, i);
|
||||
if (NULL == parent) {
|
||||
SCH_TASK_ELOG("fail to get task %d parent, parentNum: %d", i, parentNum);
|
||||
SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
SCH_LOCK(SCH_WRITE, &parent->planLock);
|
||||
SDownstreamSourceNode source = {
|
||||
|
@ -308,9 +312,14 @@ int32_t schProcessOnTaskSuccess(SSchJob *pJob, SSchTask *pTask) {
|
|||
.fetchMsgType = SCH_FETCH_TYPE(pTask),
|
||||
.localExec = SCH_IS_LOCAL_EXEC_TASK(pJob, pTask),
|
||||
};
|
||||
qSetSubplanExecutionNode(parent->plan, pTask->plan->id.groupId, &source);
|
||||
code = qSetSubplanExecutionNode(parent->plan, pTask->plan->id.groupId, &source);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
SCH_TASK_ELOG("qSetSubplanExecutionNode failed, groupId: %d", pTask->plan->id.groupId);
|
||||
}
|
||||
SCH_UNLOCK(SCH_WRITE, &parent->planLock);
|
||||
|
||||
SCH_ERR_RET(code);
|
||||
|
||||
int32_t readyNum = atomic_add_fetch_32(&parent->childReady, 1);
|
||||
|
||||
if (SCH_TASK_READY_FOR_LAUNCH(readyNum, parent)) {
|
||||
|
@ -413,16 +422,16 @@ void schResetTaskForRetry(SSchJob *pJob, SSchTask *pTask) {
|
|||
|
||||
schDropTaskOnExecNode(pJob, pTask);
|
||||
if (pTask->delayTimer) {
|
||||
taosTmrStopA(&pTask->delayTimer);
|
||||
(void)taosTmrStopA(&pTask->delayTimer); // ignore error
|
||||
}
|
||||
taosHashClear(pTask->execNodes);
|
||||
schRemoveTaskFromExecList(pJob, pTask);
|
||||
(void)schRemoveTaskFromExecList(pJob, pTask); // ignore error
|
||||
schDeregisterTaskHb(pJob, pTask);
|
||||
taosMemoryFreeClear(pTask->msg);
|
||||
pTask->msgLen = 0;
|
||||
pTask->lastMsgType = 0;
|
||||
pTask->childReady = 0;
|
||||
memset(&pTask->succeedAddr, 0, sizeof(pTask->succeedAddr));
|
||||
TAOS_MEMSET(&pTask->succeedAddr, 0, sizeof(pTask->succeedAddr));
|
||||
}
|
||||
|
||||
int32_t schDoTaskRedirect(SSchJob *pJob, SSchTask *pTask, SDataBuf *pData, int32_t rspCode) {
|
||||
|
@ -443,11 +452,21 @@ int32_t schDoTaskRedirect(SSchJob *pJob, SSchTask *pTask, SDataBuf *pData, int32
|
|||
SCH_ERR_JRET(schUpdateTaskCandidateAddr(pJob, pTask, pData->pEpSet));
|
||||
} else if (SYNC_SELF_LEADER_REDIRECT_ERROR(rspCode)) {
|
||||
SQueryNodeAddr *addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx);
|
||||
if (NULL == addr) {
|
||||
SCH_TASK_ELOG("fail to get the %dth condidateAddr, totalNum:%d", pTask->candidateIdx, (int32_t)taosArrayGetSize(pTask->candidateAddrs));
|
||||
SCH_ERR_JRET(TSDB_CODE_SCH_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
SEp *pEp = &addr->epSet.eps[addr->epSet.inUse];
|
||||
SCH_TASK_DLOG("task retry node %d current ep, idx:%d/%d,%s:%d, code:%s", addr->nodeId, addr->epSet.inUse,
|
||||
addr->epSet.numOfEps, pEp->fqdn, pEp->port, tstrerror(rspCode));
|
||||
} else {
|
||||
SQueryNodeAddr *addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx);
|
||||
if (NULL == addr) {
|
||||
SCH_TASK_ELOG("fail to get the %dth condidateAddr, totalNum:%d", pTask->candidateIdx, (int32_t)taosArrayGetSize(pTask->candidateAddrs));
|
||||
SCH_ERR_JRET(TSDB_CODE_SCH_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
SCH_SWITCH_EPSET(addr);
|
||||
SCH_TASK_DLOG("switch task target node %d epset to %d/%d", addr->nodeId, addr->epSet.inUse, addr->epSet.numOfEps);
|
||||
}
|
||||
|
@ -476,7 +495,7 @@ int32_t schDoTaskRedirect(SSchJob *pJob, SSchTask *pTask, SDataBuf *pData, int32
|
|||
for (int32_t i = 0; i < childrenNum; ++i) {
|
||||
SSchTask *pChild = taosArrayGetP(pTask->children, i);
|
||||
SCH_LOCK_TASK(pChild);
|
||||
schDoTaskRedirect(pJob, pChild, NULL, rspCode);
|
||||
(void)schDoTaskRedirect(pJob, pChild, NULL, rspCode); // error handled internal
|
||||
SCH_UNLOCK_TASK(pChild);
|
||||
}
|
||||
|
||||
|
@ -494,18 +513,23 @@ int32_t schResetTaskSetLevelInfo(SSchJob *pJob, SSchTask *pTask) {
|
|||
atomic_load_32(&pLevel->taskExecDoneNum), atomic_load_32(&pLevel->taskLaunchedNum));
|
||||
|
||||
if (SCH_GET_TASK_STATUS(pTask) >= JOB_TASK_STATUS_PART_SUCC) {
|
||||
atomic_sub_fetch_32(&pLevel->taskExecDoneNum, 1);
|
||||
(void)atomic_sub_fetch_32(&pLevel->taskExecDoneNum, 1);
|
||||
}
|
||||
|
||||
atomic_sub_fetch_32(&pLevel->taskLaunchedNum, 1);
|
||||
(void)atomic_sub_fetch_32(&pLevel->taskLaunchedNum, 1);
|
||||
|
||||
int32_t childrenNum = taosArrayGetSize(pTask->children);
|
||||
for (int32_t i = 0; i < childrenNum; ++i) {
|
||||
SSchTask *pChild = taosArrayGetP(pTask->children, i);
|
||||
if (NULL == pChild) {
|
||||
SCH_TASK_ELOG("fail to get the %dth child, childrenNum:%d", i, childrenNum);
|
||||
SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
SCH_LOCK_TASK(pChild);
|
||||
pLevel = pChild->level;
|
||||
atomic_sub_fetch_32(&pLevel->taskExecDoneNum, 1);
|
||||
atomic_sub_fetch_32(&pLevel->taskLaunchedNum, 1);
|
||||
(void)atomic_sub_fetch_32(&pLevel->taskExecDoneNum, 1);
|
||||
(void)atomic_sub_fetch_32(&pLevel->taskLaunchedNum, 1);
|
||||
SCH_UNLOCK_TASK(pChild);
|
||||
}
|
||||
|
||||
|
@ -711,9 +735,9 @@ int32_t schTaskCheckSetRetry(SSchJob *pJob, SSchTask *pTask, int32_t errCode, bo
|
|||
}
|
||||
|
||||
int32_t schHandleTaskRetry(SSchJob *pJob, SSchTask *pTask) {
|
||||
atomic_sub_fetch_32(&pTask->level->taskLaunchedNum, 1);
|
||||
(void)atomic_sub_fetch_32(&pTask->level->taskLaunchedNum, 1);
|
||||
|
||||
schRemoveTaskFromExecList(pJob, pTask);
|
||||
(void)schRemoveTaskFromExecList(pJob, pTask); // ignore error
|
||||
SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_INIT);
|
||||
|
||||
if (SCH_TASK_NEED_FLOW_CTRL(pJob, pTask)) {
|
||||
|
@ -724,6 +748,11 @@ int32_t schHandleTaskRetry(SSchJob *pJob, SSchTask *pTask) {
|
|||
|
||||
if (SCH_IS_DATA_BIND_TASK(pTask)) {
|
||||
SQueryNodeAddr *addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx);
|
||||
if (NULL == addr) {
|
||||
SCH_TASK_ELOG("fail to the %dth condidateAddr, totalNum:%d", pTask->candidateIdx, (int32_t)taosArrayGetSize(pTask->candidateAddrs));
|
||||
SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
SCH_SWITCH_EPSET(addr);
|
||||
} else {
|
||||
SCH_ERR_RET(schSwitchTaskCandidateAddr(pJob, pTask));
|
||||
|
@ -743,6 +772,11 @@ int32_t schSetAddrsFromNodeList(SSchJob *pJob, SSchTask *pTask) {
|
|||
|
||||
for (int32_t i = 0; i < nodeNum; ++i) {
|
||||
SQueryNodeLoad *nload = taosArrayGet(pJob->nodeList, i);
|
||||
if (NULL == nload) {
|
||||
SCH_TASK_ELOG("fail to get the %dth node in nodeList, nodeNum:%d", i, nodeNum);
|
||||
SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
SQueryNodeAddr *naddr = &nload->addr;
|
||||
|
||||
if (NULL == taosArrayPush(pTask->candidateAddrs, naddr)) {
|
||||
|
@ -810,6 +844,7 @@ int32_t schSetTaskCandidateAddrs(SSchJob *pJob, SSchTask *pTask) {
|
|||
}
|
||||
|
||||
int32_t schUpdateTaskCandidateAddr(SSchJob *pJob, SSchTask *pTask, SEpSet *pEpSet) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
if (NULL == pTask->candidateAddrs || 1 != taosArrayGetSize(pTask->candidateAddrs)) {
|
||||
SCH_TASK_ELOG("not able to update cndidate addr, addr num %d",
|
||||
(int32_t)(pTask->candidateAddrs ? taosArrayGetSize(pTask->candidateAddrs) : 0));
|
||||
|
@ -817,18 +852,27 @@ int32_t schUpdateTaskCandidateAddr(SSchJob *pJob, SSchTask *pTask, SEpSet *pEpSe
|
|||
}
|
||||
|
||||
SQueryNodeAddr *pAddr = taosArrayGet(pTask->candidateAddrs, 0);
|
||||
if (NULL == pAddr) {
|
||||
SCH_TASK_ELOG("fail to get task 0th condidataAddr, totalNum:%d", (int32_t)taosArrayGetSize(pTask->candidateAddrs));
|
||||
SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
char *origEpset = schDumpEpSet(&pAddr->epSet);
|
||||
char *newEpset = schDumpEpSet(pEpSet);
|
||||
char *origEpset = NULL;
|
||||
char *newEpset = NULL;
|
||||
|
||||
SCH_ERR_RET(schDumpEpSet(&pAddr->epSet, &origEpset));
|
||||
SCH_ERR_JRET(schDumpEpSet(pEpSet, &newEpset));
|
||||
|
||||
SCH_TASK_DLOG("update task target node %d epset from %s to %s", pAddr->nodeId, origEpset, newEpset);
|
||||
|
||||
TAOS_MEMCPY(&pAddr->epSet, pEpSet, sizeof(pAddr->epSet));
|
||||
|
||||
_return:
|
||||
|
||||
taosMemoryFree(origEpset);
|
||||
taosMemoryFree(newEpset);
|
||||
|
||||
memcpy(&pAddr->epSet, pEpSet, sizeof(pAddr->epSet));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t schSwitchTaskCandidateAddr(SSchJob *pJob, SSchTask *pTask) {
|
||||
|
@ -877,7 +921,6 @@ void schDropTaskOnExecNode(SSchJob *pJob, SSchTask *pTask) {
|
|||
}
|
||||
|
||||
int32_t size = (int32_t)taosHashGetSize(pTask->execNodes);
|
||||
|
||||
if (size <= 0) {
|
||||
SCH_TASK_DLOG("task has no execNodes, no need to drop it, status:%s", SCH_GET_TASK_STATUS_STR(pTask));
|
||||
return;
|
||||
|
@ -889,7 +932,7 @@ void schDropTaskOnExecNode(SSchJob *pJob, SSchTask *pTask) {
|
|||
if (nodeInfo->handle) {
|
||||
SCH_SET_TASK_HANDLE(pTask, nodeInfo->handle);
|
||||
void *pExecId = taosHashGetKey(nodeInfo, NULL);
|
||||
schBuildAndSendMsg(pJob, pTask, &nodeInfo->addr, TDMT_SCH_DROP_TASK, pExecId);
|
||||
(void)schBuildAndSendMsg(pJob, pTask, &nodeInfo->addr, TDMT_SCH_DROP_TASK, pExecId); // ignore error and continue
|
||||
|
||||
SCH_TASK_DLOG("start to drop task's %dth execNode", i);
|
||||
} else {
|
||||
|
@ -939,6 +982,11 @@ int32_t schProcessOnTaskStatusRsp(SQueryNodeEpId *pEpId, SArray *pStatusList) {
|
|||
|
||||
for (int32_t i = 0; i < taskNum; ++i) {
|
||||
STaskStatus *pStatus = taosArrayGet(pStatusList, i);
|
||||
if (NULL == pStatus) {
|
||||
qError("fail to get the %dth task status in hb rsp, taskNum:%d", i, taskNum);
|
||||
continue;
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
|
||||
qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d task status in server: %s", pStatus->queryId, pStatus->taskId,
|
||||
|
@ -983,10 +1031,15 @@ int32_t schHandleExplainRes(SArray *pExplainRes) {
|
|||
|
||||
for (int32_t i = 0; i < resNum; ++i) {
|
||||
SExplainLocalRsp *localRsp = taosArrayGet(pExplainRes, i);
|
||||
if (NULL == localRsp) {
|
||||
qError("fail to get the %dth LOCAL explain rsp msg, total:%d", i, resNum);
|
||||
continue;
|
||||
}
|
||||
|
||||
qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ", begin to handle LOCAL explain rsp msg", localRsp->qId, localRsp->tId);
|
||||
|
||||
pJob = schAcquireJob(localRsp->rId);
|
||||
pJob = NULL;
|
||||
(void)schAcquireJob(localRsp->rId, &pJob);
|
||||
if (NULL == pJob) {
|
||||
qWarn("QID:0x%" PRIx64 ",TID:0x%" PRIx64 "job no exist, may be dropped, refId:0x%" PRIx64, localRsp->qId,
|
||||
localRsp->tId, localRsp->rId);
|
||||
|
@ -996,7 +1049,7 @@ int32_t schHandleExplainRes(SArray *pExplainRes) {
|
|||
int8_t status = 0;
|
||||
if (schJobNeedToStop(pJob, &status)) {
|
||||
SCH_TASK_DLOG("will not do further processing cause of job status %s", jobTaskStatusStr(status));
|
||||
schReleaseJob(pJob->refId);
|
||||
(void)schReleaseJob(pJob->refId);
|
||||
SCH_ERR_JRET(TSDB_CODE_SCH_IGNORE_ERROR);
|
||||
}
|
||||
|
||||
|
@ -1006,7 +1059,7 @@ int32_t schHandleExplainRes(SArray *pExplainRes) {
|
|||
code = schProcessExplainRsp(pJob, pTask, &localRsp->rsp);
|
||||
}
|
||||
|
||||
schReleaseJob(pJob->refId);
|
||||
(void)schReleaseJob(pJob->refId);
|
||||
|
||||
qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ", end to handle LOCAL explain rsp msg, code:%x", localRsp->qId,
|
||||
localRsp->tId, code);
|
||||
|
@ -1022,6 +1075,11 @@ _return:
|
|||
|
||||
for (int32_t i = 0; i < resNum; ++i) {
|
||||
SExplainLocalRsp *localRsp = taosArrayGet(pExplainRes, i);
|
||||
if (NULL == localRsp) {
|
||||
qError("in _return fail to get the %dth LOCAL explain rsp msg, total:%d", i, resNum);
|
||||
continue;
|
||||
}
|
||||
|
||||
tFreeSExplainRsp(&localRsp->rsp);
|
||||
}
|
||||
|
||||
|
@ -1076,6 +1134,9 @@ int32_t schLaunchLocalTask(SSchJob *pJob, SSchTask *pTask) {
|
|||
|
||||
if (SCH_IS_EXPLAIN_JOB(pJob)) {
|
||||
explainRes = taosArrayInit(pJob->taskNum, sizeof(SExplainLocalRsp));
|
||||
if (NULL == explainRes) {
|
||||
SCH_ERR_RET(terrno);
|
||||
}
|
||||
}
|
||||
|
||||
SCH_ERR_JRET(qWorkerProcessLocalQuery(schMgmt.queryMgmt, schMgmt.sId, pJob->queryId, pTask->taskId, pJob->refId,
|
||||
|
@ -1097,7 +1158,9 @@ _return:
|
|||
|
||||
int32_t schLaunchTaskImpl(void *param) {
|
||||
SSchTaskCtx *pCtx = (SSchTaskCtx *)param;
|
||||
SSchJob *pJob = schAcquireJob(pCtx->jobRid);
|
||||
SSchJob *pJob = NULL;
|
||||
|
||||
(void)schAcquireJob(pCtx->jobRid, &pJob);
|
||||
if (NULL == pJob) {
|
||||
qDebug("job refId 0x%" PRIx64 " already not exist", pCtx->jobRid);
|
||||
taosMemoryFree(param);
|
||||
|
@ -1113,7 +1176,7 @@ int32_t schLaunchTaskImpl(void *param) {
|
|||
int8_t status = 0;
|
||||
int32_t code = 0;
|
||||
|
||||
atomic_add_fetch_32(&pTask->level->taskLaunchedNum, 1);
|
||||
(void)atomic_add_fetch_32(&pTask->level->taskLaunchedNum, 1);
|
||||
pTask->execId++;
|
||||
pTask->retryTimes++;
|
||||
pTask->waitRetry = false;
|
||||
|
@ -1160,7 +1223,7 @@ _return:
|
|||
SCH_UNLOCK_TASK(pTask);
|
||||
}
|
||||
|
||||
schReleaseJob(pJob->refId);
|
||||
(void)schReleaseJob(pJob->refId);
|
||||
|
||||
taosMemoryFree(param);
|
||||
|
||||
|
@ -1178,7 +1241,7 @@ int32_t schAsyncLaunchTaskImpl(SSchJob *pJob, SSchTask *pTask) {
|
|||
|
||||
if (pJob->taskNum >= SCH_MIN_AYSNC_EXEC_NUM) {
|
||||
param->asyncLaunch = true;
|
||||
taosAsyncExec(schLaunchTaskImpl, param, NULL);
|
||||
SCH_ERR_RET(taosAsyncExec(schLaunchTaskImpl, param, NULL));
|
||||
} else {
|
||||
SCH_ERR_RET(schLaunchTaskImpl(param));
|
||||
}
|
||||
|
@ -1252,7 +1315,7 @@ int32_t schDelayLaunchTask(SSchJob *pJob, SSchTask *pTask) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
taosTmrReset(schHandleTimerEvent, pTask->delayExecMs, (void *)param, schMgmt.timer, &pTask->delayTimer);
|
||||
(void)taosTmrReset(schHandleTimerEvent, pTask->delayExecMs, (void *)param, schMgmt.timer, &pTask->delayTimer);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -1283,7 +1346,7 @@ void schDropTaskInHashList(SSchJob *pJob, SHashObj *list) {
|
|||
|
||||
SCH_LOCK_TASK(pTask);
|
||||
if (pTask->delayTimer) {
|
||||
taosTmrStopA(&pTask->delayTimer);
|
||||
(void)taosTmrStopA(&pTask->delayTimer);
|
||||
}
|
||||
schDropTaskOnExecNode(pJob, pTask);
|
||||
SCH_UNLOCK_TASK(pTask);
|
||||
|
@ -1327,6 +1390,9 @@ int32_t schExecLocalFetch(SSchJob *pJob, SSchTask *pTask) {
|
|||
|
||||
if (SCH_IS_EXPLAIN_JOB(pJob)) {
|
||||
explainRes = taosArrayInit(pJob->taskNum, sizeof(SExplainLocalRsp));
|
||||
if (NULL == explainRes) {
|
||||
SCH_ERR_RET(terrno);
|
||||
}
|
||||
}
|
||||
|
||||
SCH_ERR_JRET(qWorkerProcessLocalFetch(schMgmt.queryMgmt, schMgmt.sId, pJob->queryId, pTask->taskId, pJob->refId,
|
||||
|
|
|
@ -22,9 +22,14 @@
|
|||
#include "tref.h"
|
||||
#include "trpc.h"
|
||||
|
||||
FORCE_INLINE SSchJob *schAcquireJob(int64_t refId) {
|
||||
FORCE_INLINE int32_t schAcquireJob(int64_t refId, SSchJob** ppJob) {
|
||||
qDebug("sch acquire jobId:0x%" PRIx64, refId);
|
||||
return (SSchJob *)taosAcquireRef(schMgmt.jobRef, refId);
|
||||
*ppJob = (SSchJob *)taosAcquireRef(schMgmt.jobRef, refId);
|
||||
if (NULL == *ppJob) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
FORCE_INLINE int32_t schReleaseJob(int64_t refId) {
|
||||
|
@ -36,15 +41,16 @@ FORCE_INLINE int32_t schReleaseJob(int64_t refId) {
|
|||
return taosReleaseRef(schMgmt.jobRef, refId);
|
||||
}
|
||||
|
||||
char *schDumpEpSet(SEpSet *pEpSet) {
|
||||
int32_t schDumpEpSet(SEpSet *pEpSet, char** ppRes) {
|
||||
*ppRes = NULL;
|
||||
if (NULL == pEpSet) {
|
||||
return NULL;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t maxSize = 1024;
|
||||
char *str = taosMemoryMalloc(maxSize);
|
||||
if (NULL == str) {
|
||||
return NULL;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
int32_t n = 0;
|
||||
|
@ -54,7 +60,8 @@ char *schDumpEpSet(SEpSet *pEpSet) {
|
|||
n += snprintf(str + n, maxSize - n, "[%s:%d]", pEp->fqdn, pEp->port);
|
||||
}
|
||||
|
||||
return str;
|
||||
*ppRes = str;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
char *schGetOpStr(SCH_OP_TYPE type) {
|
||||
|
@ -73,7 +80,7 @@ char *schGetOpStr(SCH_OP_TYPE type) {
|
|||
}
|
||||
|
||||
void schFreeHbTrans(SSchHbTrans *pTrans) {
|
||||
rpcReleaseHandle((void *)pTrans->trans.pHandleId, TAOS_CONN_CLIENT);
|
||||
(void)rpcReleaseHandle((void *)pTrans->trans.pHandleId, TAOS_CONN_CLIENT);
|
||||
|
||||
schFreeRpcCtx(&pTrans->rpcCtx);
|
||||
}
|
||||
|
@ -86,7 +93,7 @@ void schCleanClusterHb(void *pTrans) {
|
|||
if (hb->trans.pTrans == pTrans) {
|
||||
SQueryNodeEpId *pEpId = taosHashGetKey(hb, NULL);
|
||||
schFreeHbTrans(hb);
|
||||
taosHashRemove(schMgmt.hbConnections, pEpId, sizeof(SQueryNodeEpId));
|
||||
(void)taosHashRemove(schMgmt.hbConnections, pEpId, sizeof(SQueryNodeEpId));
|
||||
}
|
||||
|
||||
hb = taosHashIterate(schMgmt.hbConnections, hb);
|
||||
|
@ -109,7 +116,7 @@ int32_t schRemoveHbConnection(SSchJob *pJob, SSchTask *pTask, SQueryNodeEpId *ep
|
|||
int64_t taskNum = atomic_load_64(&hb->taskNum);
|
||||
if (taskNum <= 0) {
|
||||
schFreeHbTrans(hb);
|
||||
taosHashRemove(schMgmt.hbConnections, epId, sizeof(SQueryNodeEpId));
|
||||
(void)taosHashRemove(schMgmt.hbConnections, epId, sizeof(SQueryNodeEpId));
|
||||
}
|
||||
SCH_UNLOCK(SCH_WRITE, &schMgmt.hbLock);
|
||||
|
||||
|
@ -165,7 +172,7 @@ int32_t schRegisterHbConnection(SSchJob *pJob, SSchTask *pTask, SQueryNodeEpId *
|
|||
break;
|
||||
}
|
||||
|
||||
atomic_add_fetch_64(&hb->taskNum, 1);
|
||||
(void)atomic_add_fetch_64(&hb->taskNum, 1);
|
||||
|
||||
SCH_UNLOCK(SCH_READ, &schMgmt.hbLock);
|
||||
|
||||
|
@ -178,12 +185,17 @@ void schDeregisterTaskHb(SSchJob *pJob, SSchTask *pTask) {
|
|||
}
|
||||
|
||||
SQueryNodeAddr *addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx);
|
||||
if (NULL == addr) {
|
||||
SCH_TASK_ELOG("fail to get the %dth condidateAddr in task, totalNum:%d", pTask->candidateIdx, (int32_t)taosArrayGetSize(pTask->candidateAddrs));
|
||||
return;
|
||||
}
|
||||
|
||||
SQueryNodeEpId epId = {0};
|
||||
|
||||
epId.nodeId = addr->nodeId;
|
||||
|
||||
SEp *pEp = SCH_GET_CUR_EP(addr);
|
||||
strcpy(epId.ep.fqdn, pEp->fqdn);
|
||||
TAOS_STRCPY(epId.ep.fqdn, pEp->fqdn);
|
||||
epId.ep.port = pEp->port;
|
||||
|
||||
SCH_LOCK(SCH_READ, &schMgmt.hbLock);
|
||||
|
@ -197,7 +209,7 @@ void schDeregisterTaskHb(SSchJob *pJob, SSchTask *pTask) {
|
|||
int64_t taskNum = atomic_sub_fetch_64(&hb->taskNum, 1);
|
||||
if (0 == taskNum) {
|
||||
SCH_UNLOCK(SCH_READ, &schMgmt.hbLock);
|
||||
schRemoveHbConnection(pJob, pTask, &epId);
|
||||
(void)schRemoveHbConnection(pJob, pTask, &epId);
|
||||
} else {
|
||||
SCH_UNLOCK(SCH_READ, &schMgmt.hbLock);
|
||||
}
|
||||
|
@ -211,12 +223,17 @@ int32_t schEnsureHbConnection(SSchJob *pJob, SSchTask *pTask) {
|
|||
}
|
||||
|
||||
SQueryNodeAddr *addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx);
|
||||
if (NULL == addr) {
|
||||
SCH_TASK_ELOG("fail to get the %dth condidateAddr in task, totalNum:%d", pTask->candidateIdx, (int32_t)taosArrayGetSize(pTask->candidateAddrs));
|
||||
return TSDB_CODE_SCH_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
SQueryNodeEpId epId = {0};
|
||||
|
||||
epId.nodeId = addr->nodeId;
|
||||
|
||||
SEp *pEp = SCH_GET_CUR_EP(addr);
|
||||
strcpy(epId.ep.fqdn, pEp->fqdn);
|
||||
TAOS_STRCPY(epId.ep.fqdn, pEp->fqdn);
|
||||
epId.ep.port = pEp->port;
|
||||
|
||||
SCH_ERR_RET(schRegisterHbConnection(pJob, pTask, &epId));
|
||||
|
@ -240,7 +257,7 @@ int32_t schUpdateHbConnection(SQueryNodeEpId *epId, SSchTrans *trans) {
|
|||
}
|
||||
|
||||
SCH_LOCK(SCH_WRITE, &hb->lock);
|
||||
memcpy(&hb->trans, trans, sizeof(*trans));
|
||||
TAOS_MEMCPY(&hb->trans, trans, sizeof(*trans));
|
||||
SCH_UNLOCK(SCH_WRITE, &hb->lock);
|
||||
SCH_UNLOCK(SCH_READ, &schMgmt.hbLock);
|
||||
|
||||
|
@ -256,7 +273,7 @@ void schCloseJobRef(void) {
|
|||
}
|
||||
|
||||
if (schMgmt.jobRef >= 0) {
|
||||
taosCloseRef(schMgmt.jobRef);
|
||||
(void)taosCloseRef(schMgmt.jobRef);
|
||||
schMgmt.jobRef = -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -169,7 +169,8 @@ void schedulerFreeJob(int64_t *jobId, int32_t errCode) {
|
|||
return;
|
||||
}
|
||||
|
||||
SSchJob *pJob = schAcquireJob(*jobId);
|
||||
SSchJob *pJob = NULL;
|
||||
(void)schAcquireJob(*jobId, &pJob);
|
||||
if (NULL == pJob) {
|
||||
qWarn("Acquire sch job failed, may be dropped, jobId:0x%" PRIx64, *jobId);
|
||||
return;
|
||||
|
|
|
@ -75,9 +75,7 @@ int32_t schtStartFetch = 0;
|
|||
void schtInitLogFile() {
|
||||
const char *defaultLogFileNamePrefix = "taoslog";
|
||||
const int32_t maxLogFileNum = 10;
|
||||
rpcInit();
|
||||
tsAsyncLog = 0;
|
||||
rpcInit();
|
||||
qDebugFlag = 159;
|
||||
strcpy(tsLogDir, TD_LOG_DIR_PATH);
|
||||
|
||||
|
@ -136,8 +134,13 @@ int32_t schtBuildSubmitRspMsg(uint32_t *msize, void **rspMsg) {
|
|||
|
||||
tEncodeSize(tEncodeSSubmitRsp2, &submitRsp, msgSize, ret);
|
||||
void *msg = taosMemoryCalloc(1, msgSize);
|
||||
if (NULL == msg) {
|
||||
return terrno;
|
||||
}
|
||||
tEncoderInit(&ec, (uint8_t *)msg, msgSize);
|
||||
tEncodeSSubmitRsp2(&ec, &submitRsp);
|
||||
if (tEncodeSSubmitRsp2(&ec, &submitRsp) < 0) {
|
||||
return -1;
|
||||
}
|
||||
tEncoderClear(&ec);
|
||||
|
||||
*rspMsg = msg;
|
||||
|
@ -152,11 +155,26 @@ void schtBuildQueryDag(SQueryPlan *dag) {
|
|||
dag->queryId = qId;
|
||||
dag->numOfSubplans = 2;
|
||||
dag->pSubplans = nodesMakeList();
|
||||
if (NULL == dag->pSubplans) {
|
||||
return;
|
||||
}
|
||||
SNodeListNode *scan = (SNodeListNode *)nodesMakeNode(QUERY_NODE_NODE_LIST);
|
||||
if (NULL == scan) {
|
||||
return;
|
||||
}
|
||||
SNodeListNode *merge = (SNodeListNode *)nodesMakeNode(QUERY_NODE_NODE_LIST);
|
||||
if (NULL == merge) {
|
||||
return;
|
||||
}
|
||||
|
||||
SSubplan *scanPlan = (SSubplan *)nodesMakeNode(QUERY_NODE_PHYSICAL_SUBPLAN);
|
||||
if (NULL == scanPlan) {
|
||||
return;
|
||||
}
|
||||
SSubplan *mergePlan = (SSubplan *)nodesMakeNode(QUERY_NODE_PHYSICAL_SUBPLAN);
|
||||
if (NULL == mergePlan) {
|
||||
return;
|
||||
}
|
||||
|
||||
scanPlan->id.queryId = qId;
|
||||
scanPlan->id.groupId = 0x0000000000000002;
|
||||
|
@ -170,7 +188,13 @@ void schtBuildQueryDag(SQueryPlan *dag) {
|
|||
scanPlan->pChildren = NULL;
|
||||
scanPlan->level = 1;
|
||||
scanPlan->pParents = nodesMakeList();
|
||||
if (NULL == scanPlan->pParents) {
|
||||
return;
|
||||
}
|
||||
scanPlan->pNode = (SPhysiNode *)nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN);
|
||||
if (NULL == scanPlan->pNode) {
|
||||
return;
|
||||
}
|
||||
scanPlan->msgType = TDMT_SCH_QUERY;
|
||||
|
||||
mergePlan->id.queryId = qId;
|
||||
|
@ -181,21 +205,33 @@ void schtBuildQueryDag(SQueryPlan *dag) {
|
|||
mergePlan->execNode.epSet.numOfEps = 0;
|
||||
|
||||
mergePlan->pChildren = nodesMakeList();
|
||||
if (NULL == mergePlan->pChildren) {
|
||||
return;
|
||||
}
|
||||
mergePlan->pParents = NULL;
|
||||
mergePlan->pNode = (SPhysiNode *)nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_MERGE);
|
||||
if (NULL == mergePlan->pNode) {
|
||||
return;
|
||||
}
|
||||
mergePlan->msgType = TDMT_SCH_QUERY;
|
||||
|
||||
merge->pNodeList = nodesMakeList();
|
||||
if (NULL == merge->pNodeList) {
|
||||
return;
|
||||
}
|
||||
scan->pNodeList = nodesMakeList();
|
||||
if (NULL == scan->pNodeList) {
|
||||
return;
|
||||
}
|
||||
|
||||
nodesListAppend(merge->pNodeList, (SNode *)mergePlan);
|
||||
nodesListAppend(scan->pNodeList, (SNode *)scanPlan);
|
||||
(void)nodesListAppend(merge->pNodeList, (SNode *)mergePlan);
|
||||
(void)nodesListAppend(scan->pNodeList, (SNode *)scanPlan);
|
||||
|
||||
nodesListAppend(mergePlan->pChildren, (SNode *)scanPlan);
|
||||
nodesListAppend(scanPlan->pParents, (SNode *)mergePlan);
|
||||
(void)nodesListAppend(mergePlan->pChildren, (SNode *)scanPlan);
|
||||
(void)nodesListAppend(scanPlan->pParents, (SNode *)mergePlan);
|
||||
|
||||
nodesListAppend(dag->pSubplans, (SNode *)merge);
|
||||
nodesListAppend(dag->pSubplans, (SNode *)scan);
|
||||
(void)nodesListAppend(dag->pSubplans, (SNode *)merge);
|
||||
(void)nodesListAppend(dag->pSubplans, (SNode *)scan);
|
||||
}
|
||||
|
||||
void schtBuildQueryFlowCtrlDag(SQueryPlan *dag) {
|
||||
|
@ -205,18 +241,42 @@ void schtBuildQueryFlowCtrlDag(SQueryPlan *dag) {
|
|||
dag->queryId = qId;
|
||||
dag->numOfSubplans = 2;
|
||||
dag->pSubplans = nodesMakeList();
|
||||
if (NULL == dag->pSubplans) {
|
||||
return;
|
||||
}
|
||||
SNodeListNode *scan = (SNodeListNode *)nodesMakeNode(QUERY_NODE_NODE_LIST);
|
||||
if (NULL == scan) {
|
||||
return;
|
||||
}
|
||||
SNodeListNode *merge = (SNodeListNode *)nodesMakeNode(QUERY_NODE_NODE_LIST);
|
||||
if (NULL == merge) {
|
||||
return;
|
||||
}
|
||||
|
||||
SSubplan *mergePlan = (SSubplan *)nodesMakeNode(QUERY_NODE_PHYSICAL_SUBPLAN);
|
||||
if (NULL == mergePlan) {
|
||||
return;
|
||||
}
|
||||
|
||||
merge->pNodeList = nodesMakeList();
|
||||
if (NULL == merge->pNodeList) {
|
||||
return;
|
||||
}
|
||||
scan->pNodeList = nodesMakeList();
|
||||
if (NULL == scan->pNodeList) {
|
||||
return;
|
||||
}
|
||||
|
||||
mergePlan->pChildren = nodesMakeList();
|
||||
if (NULL == mergePlan->pChildren) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < scanPlanNum; ++i) {
|
||||
SSubplan *scanPlan = (SSubplan *)nodesMakeNode(QUERY_NODE_PHYSICAL_SUBPLAN);
|
||||
if (NULL == scanPlan) {
|
||||
return;
|
||||
}
|
||||
scanPlan->id.queryId = qId;
|
||||
scanPlan->id.groupId = 0x0000000000000002;
|
||||
scanPlan->id.subplanId = 0x0000000000000003 + i;
|
||||
|
@ -233,13 +293,19 @@ void schtBuildQueryFlowCtrlDag(SQueryPlan *dag) {
|
|||
scanPlan->pChildren = NULL;
|
||||
scanPlan->level = 1;
|
||||
scanPlan->pParents = nodesMakeList();
|
||||
if (NULL == scanPlan->pParents) {
|
||||
return;
|
||||
}
|
||||
scanPlan->pNode = (SPhysiNode *)nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN);
|
||||
if (NULL == scanPlan->pNode) {
|
||||
return;
|
||||
}
|
||||
scanPlan->msgType = TDMT_SCH_QUERY;
|
||||
|
||||
nodesListAppend(scanPlan->pParents, (SNode *)mergePlan);
|
||||
nodesListAppend(mergePlan->pChildren, (SNode *)scanPlan);
|
||||
(void)nodesListAppend(scanPlan->pParents, (SNode *)mergePlan);
|
||||
(void)nodesListAppend(mergePlan->pChildren, (SNode *)scanPlan);
|
||||
|
||||
nodesListAppend(scan->pNodeList, (SNode *)scanPlan);
|
||||
(void)nodesListAppend(scan->pNodeList, (SNode *)scanPlan);
|
||||
}
|
||||
|
||||
mergePlan->id.queryId = qId;
|
||||
|
@ -251,12 +317,15 @@ void schtBuildQueryFlowCtrlDag(SQueryPlan *dag) {
|
|||
|
||||
mergePlan->pParents = NULL;
|
||||
mergePlan->pNode = (SPhysiNode *)nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_MERGE);
|
||||
if (NULL == mergePlan->pNode) {
|
||||
return;
|
||||
}
|
||||
mergePlan->msgType = TDMT_SCH_QUERY;
|
||||
|
||||
nodesListAppend(merge->pNodeList, (SNode *)mergePlan);
|
||||
(void)nodesListAppend(merge->pNodeList, (SNode *)mergePlan);
|
||||
|
||||
nodesListAppend(dag->pSubplans, (SNode *)merge);
|
||||
nodesListAppend(dag->pSubplans, (SNode *)scan);
|
||||
(void)nodesListAppend(dag->pSubplans, (SNode *)merge);
|
||||
(void)nodesListAppend(dag->pSubplans, (SNode *)scan);
|
||||
}
|
||||
|
||||
void schtFreeQueryDag(SQueryPlan *dag) {}
|
||||
|
@ -267,10 +336,22 @@ void schtBuildInsertDag(SQueryPlan *dag) {
|
|||
dag->queryId = qId;
|
||||
dag->numOfSubplans = 2;
|
||||
dag->pSubplans = nodesMakeList();
|
||||
if (NULL == dag->pSubplans) {
|
||||
return;
|
||||
}
|
||||
SNodeListNode *inserta = (SNodeListNode *)nodesMakeNode(QUERY_NODE_NODE_LIST);
|
||||
if (NULL == inserta) {
|
||||
return;
|
||||
}
|
||||
inserta->pNodeList = nodesMakeList();
|
||||
if (NULL == inserta->pNodeList) {
|
||||
return;
|
||||
}
|
||||
|
||||
SSubplan *insertPlan = (SSubplan *)nodesMakeNode(QUERY_NODE_PHYSICAL_SUBPLAN);
|
||||
if (NULL == insertPlan) {
|
||||
return;
|
||||
}
|
||||
|
||||
insertPlan->id.queryId = qId;
|
||||
insertPlan->id.groupId = 0x0000000000000003;
|
||||
|
@ -286,13 +367,22 @@ void schtBuildInsertDag(SQueryPlan *dag) {
|
|||
insertPlan->pParents = NULL;
|
||||
insertPlan->pNode = NULL;
|
||||
insertPlan->pDataSink = (SDataSinkNode *)nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_INSERT);
|
||||
if (NULL == insertPlan->pDataSink) {
|
||||
return;
|
||||
}
|
||||
((SDataInserterNode *)insertPlan->pDataSink)->size = 1;
|
||||
((SDataInserterNode *)insertPlan->pDataSink)->pData = taosMemoryCalloc(1, 1);
|
||||
if (NULL == ((SDataInserterNode *)insertPlan->pDataSink)->pData) {
|
||||
return;
|
||||
}
|
||||
insertPlan->msgType = TDMT_VND_SUBMIT;
|
||||
|
||||
nodesListAppend(inserta->pNodeList, (SNode *)insertPlan);
|
||||
(void)nodesListAppend(inserta->pNodeList, (SNode *)insertPlan);
|
||||
|
||||
insertPlan = (SSubplan *)nodesMakeNode(QUERY_NODE_PHYSICAL_SUBPLAN);
|
||||
if (NULL == insertPlan) {
|
||||
return;
|
||||
}
|
||||
|
||||
insertPlan->id.queryId = qId;
|
||||
insertPlan->id.groupId = 0x0000000000000003;
|
||||
|
@ -308,22 +398,31 @@ void schtBuildInsertDag(SQueryPlan *dag) {
|
|||
insertPlan->pParents = NULL;
|
||||
insertPlan->pNode = NULL;
|
||||
insertPlan->pDataSink = (SDataSinkNode *)nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_INSERT);
|
||||
if (NULL == insertPlan->pDataSink) {
|
||||
return;
|
||||
}
|
||||
((SDataInserterNode *)insertPlan->pDataSink)->size = 1;
|
||||
((SDataInserterNode *)insertPlan->pDataSink)->pData = taosMemoryCalloc(1, 1);
|
||||
if (NULL == ((SDataInserterNode *)insertPlan->pDataSink)->pData) {
|
||||
return;
|
||||
}
|
||||
insertPlan->msgType = TDMT_VND_SUBMIT;
|
||||
|
||||
nodesListAppend(inserta->pNodeList, (SNode *)insertPlan);
|
||||
(void)nodesListAppend(inserta->pNodeList, (SNode *)insertPlan);
|
||||
|
||||
nodesListAppend(dag->pSubplans, (SNode *)inserta);
|
||||
(void)nodesListAppend(dag->pSubplans, (SNode *)inserta);
|
||||
}
|
||||
|
||||
int32_t schtPlanToString(const SSubplan *subplan, char **str, int32_t *len) {
|
||||
*str = (char *)taosMemoryCalloc(1, 20);
|
||||
if (NULL == *str) {
|
||||
return -1;
|
||||
}
|
||||
*len = 20;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void schtExecNode(SSubplan *subplan, uint64_t groupId, SQueryNodeAddr *ep) {}
|
||||
int32_t schtExecNode(SSubplan *subplan, uint64_t groupId, SQueryNodeAddr *ep) { return 0; }
|
||||
|
||||
void schtRpcSendRequest(void *shandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t *pRid) {}
|
||||
|
||||
|
@ -431,7 +530,10 @@ void *schtSendRsp(void *param) {
|
|||
taosMsleep(1);
|
||||
}
|
||||
|
||||
pJob = schAcquireJob(job);
|
||||
code = schAcquireJob(job, &pJob);
|
||||
if (code) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *pIter = taosHashIterate(pJob->execTasks, NULL);
|
||||
while (pIter) {
|
||||
|
@ -439,16 +541,16 @@ void *schtSendRsp(void *param) {
|
|||
|
||||
SDataBuf msg = {0};
|
||||
void *rmsg = NULL;
|
||||
schtBuildSubmitRspMsg(&msg.len, &rmsg);
|
||||
(void)schtBuildSubmitRspMsg(&msg.len, &rmsg);
|
||||
msg.msgType = TDMT_VND_SUBMIT_RSP;
|
||||
msg.pData = rmsg;
|
||||
|
||||
schHandleResponseMsg(pJob, task, task->execId, &msg, 0);
|
||||
(void)schHandleResponseMsg(pJob, task, task->execId, &msg, 0);
|
||||
|
||||
pIter = taosHashIterate(pJob->execTasks, pIter);
|
||||
}
|
||||
|
||||
schReleaseJob(job);
|
||||
(void)schReleaseJob(job);
|
||||
|
||||
schtJobDone = true;
|
||||
|
||||
|
@ -457,20 +559,25 @@ void *schtSendRsp(void *param) {
|
|||
|
||||
void *schtCreateFetchRspThread(void *param) {
|
||||
int64_t job = *(int64_t *)param;
|
||||
SSchJob *pJob = schAcquireJob(job);
|
||||
SSchJob *pJob = NULL;
|
||||
|
||||
(void)schAcquireJob(job, &pJob);
|
||||
if (NULL == pJob) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
taosSsleep(1);
|
||||
|
||||
int32_t code = 0;
|
||||
SDataBuf msg = {0};
|
||||
void *rmsg = NULL;
|
||||
schtBuildFetchRspMsg(&msg.len, &rmsg);
|
||||
(void)schtBuildFetchRspMsg(&msg.len, &rmsg);
|
||||
msg.msgType = TDMT_SCH_MERGE_FETCH_RSP;
|
||||
msg.pData = rmsg;
|
||||
|
||||
code = schHandleResponseMsg(pJob, pJob->fetchTask, pJob->fetchTask->execId, &msg, 0);
|
||||
|
||||
schReleaseJob(job);
|
||||
(void)schReleaseJob(job);
|
||||
|
||||
assert(code == 0);
|
||||
return NULL;
|
||||
|
@ -488,12 +595,17 @@ void *schtFetchRspThread(void *aa) {
|
|||
taosUsleep(100);
|
||||
|
||||
param = (SSchTaskCallbackParam *)taosMemoryCalloc(1, sizeof(*param));
|
||||
|
||||
if (NULL == param) {
|
||||
return NULL;
|
||||
}
|
||||
param->queryId = schtQueryId;
|
||||
param->taskId = schtFetchTaskId;
|
||||
|
||||
int32_t code = 0;
|
||||
SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(1, sizeof(SRetrieveTableRsp));
|
||||
if (NULL == rsp) {
|
||||
return NULL;
|
||||
}
|
||||
rsp->completed = 1;
|
||||
rsp->numOfRows = 10;
|
||||
|
||||
|
@ -549,12 +661,17 @@ void *schtRunJobThread(void *aa) {
|
|||
schtBuildQueryDag(dag);
|
||||
|
||||
SArray *qnodeList = taosArrayInit(1, sizeof(SQueryNodeLoad));
|
||||
if (NULL == qnodeList) {
|
||||
assert(0);
|
||||
}
|
||||
|
||||
SQueryNodeLoad load = {0};
|
||||
load.addr.epSet.numOfEps = 1;
|
||||
strcpy(load.addr.epSet.eps[0].fqdn, "qnode0.ep");
|
||||
load.addr.epSet.eps[0].port = 6031;
|
||||
taosArrayPush(qnodeList, &load);
|
||||
if (NULL == taosArrayPush(qnodeList, &load)) {
|
||||
assert(0);
|
||||
}
|
||||
|
||||
queryDone = 0;
|
||||
|
||||
|
@ -572,7 +689,9 @@ void *schtRunJobThread(void *aa) {
|
|||
code = schedulerExecJob(&req, &queryJobRefId);
|
||||
assert(code == 0);
|
||||
|
||||
pJob = schAcquireJob(queryJobRefId);
|
||||
pJob = NULL;
|
||||
code = schAcquireJob(queryJobRefId, &pJob);
|
||||
|
||||
if (NULL == pJob) {
|
||||
taosArrayDestroy(qnodeList);
|
||||
schtFreeQueryDag(dag);
|
||||
|
@ -580,16 +699,24 @@ void *schtRunJobThread(void *aa) {
|
|||
}
|
||||
|
||||
execTasks = taosHashInit(5, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_ENTRY_LOCK);
|
||||
if (NULL == execTasks) {
|
||||
assert(0);
|
||||
}
|
||||
void *pIter = taosHashIterate(pJob->execTasks, NULL);
|
||||
while (pIter) {
|
||||
SSchTask *task = *(SSchTask **)pIter;
|
||||
schtFetchTaskId = task->taskId - 1;
|
||||
|
||||
taosHashPut(execTasks, &task->taskId, sizeof(task->taskId), task, sizeof(*task));
|
||||
if (taosHashPut(execTasks, &task->taskId, sizeof(task->taskId), task, sizeof(*task))) {
|
||||
assert(0);
|
||||
}
|
||||
pIter = taosHashIterate(pJob->execTasks, pIter);
|
||||
}
|
||||
|
||||
param = (SSchTaskCallbackParam *)taosMemoryCalloc(1, sizeof(*param));
|
||||
if (NULL == param) {
|
||||
assert(0);
|
||||
}
|
||||
param->refId = queryJobRefId;
|
||||
param->queryId = pJob->queryId;
|
||||
|
||||
|
@ -601,7 +728,9 @@ void *schtRunJobThread(void *aa) {
|
|||
|
||||
SDataBuf msg = {0};
|
||||
void *rmsg = NULL;
|
||||
schtBuildQueryRspMsg(&msg.len, &rmsg);
|
||||
if (schtBuildQueryRspMsg(&msg.len, &rmsg)) {
|
||||
assert(0);
|
||||
}
|
||||
msg.msgType = TDMT_SCH_QUERY_RSP;
|
||||
msg.pData = rmsg;
|
||||
|
||||
|
@ -612,6 +741,9 @@ void *schtRunJobThread(void *aa) {
|
|||
}
|
||||
|
||||
param = (SSchTaskCallbackParam *)taosMemoryCalloc(1, sizeof(*param));
|
||||
if (NULL == param) {
|
||||
assert(0);
|
||||
}
|
||||
param->refId = queryJobRefId;
|
||||
param->queryId = pJob->queryId;
|
||||
|
||||
|
@ -622,7 +754,9 @@ void *schtRunJobThread(void *aa) {
|
|||
param->taskId = task->taskId - 1;
|
||||
SDataBuf msg = {0};
|
||||
void *rmsg = NULL;
|
||||
schtBuildQueryRspMsg(&msg.len, &rmsg);
|
||||
if (schtBuildQueryRspMsg(&msg.len, &rmsg)) {
|
||||
assert(0);
|
||||
}
|
||||
msg.msgType = TDMT_SCH_QUERY_RSP;
|
||||
msg.pData = rmsg;
|
||||
|
||||
|
@ -728,7 +862,9 @@ TEST(queryTest, normalCase) {
|
|||
code = schedulerExecJob(&req, &job);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
SSchJob *pJob = schAcquireJob(job);
|
||||
SSchJob *pJob = NULL;
|
||||
code = schAcquireJob(job, &pJob);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
void *pIter = taosHashIterate(pJob->execTasks, NULL);
|
||||
while (pIter) {
|
||||
|
@ -839,7 +975,9 @@ TEST(queryTest, readyFirstCase) {
|
|||
code = schedulerExecJob(&req, &job);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
SSchJob *pJob = schAcquireJob(job);
|
||||
SSchJob *pJob = NULL;
|
||||
code = schAcquireJob(job, &pJob);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
void *pIter = taosHashIterate(pJob->execTasks, NULL);
|
||||
while (pIter) {
|
||||
|
@ -956,7 +1094,9 @@ TEST(queryTest, flowCtrlCase) {
|
|||
code = schedulerExecJob(&req, &job);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
SSchJob *pJob = schAcquireJob(job);
|
||||
SSchJob *pJob = NULL;
|
||||
code = schAcquireJob(job, &pJob);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
while (!queryDone) {
|
||||
void *pIter = taosHashIterate(pJob->execTasks, NULL);
|
||||
|
@ -1094,13 +1234,17 @@ TEST(otherTest, otherCase) {
|
|||
schReleaseJob(0);
|
||||
schFreeRpcCtx(NULL);
|
||||
|
||||
ASSERT_EQ(schDumpEpSet(NULL), (char *)NULL);
|
||||
char* ep = NULL;
|
||||
ASSERT_EQ(schDumpEpSet(NULL, &ep), TSDB_CODE_SUCCESS);
|
||||
ASSERT_EQ(strcmp(schGetOpStr(SCH_OP_NULL), "NULL"), 0);
|
||||
ASSERT_EQ(strcmp(schGetOpStr((SCH_OP_TYPE)100), "UNKNOWN"), 0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
schtInitLogFile();
|
||||
if (rpcInit()) {
|
||||
assert(0);
|
||||
}
|
||||
taosSeedRand(taosGetTimestampSec());
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
|
|
|
@ -31,9 +31,11 @@ static void checkpointTriggerMonitorFn(void* param, void* tmrId);
|
|||
|
||||
SStreamDataBlock* createChkptTriggerBlock(SStreamTask* pTask, int32_t checkpointType, int64_t checkpointId,
|
||||
int32_t transId, int32_t srcTaskId) {
|
||||
SStreamDataBlock* pChkpoint = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM, sizeof(SSDataBlock));
|
||||
if (pChkpoint == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
SStreamDataBlock* pChkpoint;
|
||||
|
||||
int32_t code = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM, sizeof(SSDataBlock), (void**)&pChkpoint);
|
||||
if (code) {
|
||||
terrno = code;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,11 @@
|
|||
#include "streamInt.h"
|
||||
|
||||
SStreamDataBlock* createStreamBlockFromDispatchMsg(const SStreamDispatchReq* pReq, int32_t blockType, int32_t srcVg) {
|
||||
SStreamDataBlock* pData = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM, pReq->totalLen);
|
||||
if (pData == NULL) {
|
||||
SStreamDataBlock* pData;
|
||||
|
||||
int32_t code = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM, pReq->totalLen, (void**)&pData);
|
||||
if (code) {
|
||||
terrno = code;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -69,10 +72,14 @@ SStreamDataBlock* createStreamBlockFromDispatchMsg(const SStreamDispatchReq* pRe
|
|||
return pData;
|
||||
}
|
||||
|
||||
SStreamDataBlock* createStreamBlockFromResults(SStreamQueueItem* pItem, SStreamTask* pTask, int64_t resultSize, SArray* pRes) {
|
||||
SStreamDataBlock* pStreamBlocks = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM, resultSize);
|
||||
if (pStreamBlocks == NULL) {
|
||||
SStreamDataBlock* createStreamBlockFromResults(SStreamQueueItem* pItem, SStreamTask* pTask, int64_t resultSize,
|
||||
SArray* pRes) {
|
||||
SStreamDataBlock* pStreamBlocks;
|
||||
|
||||
int32_t code = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM, resultSize, (void**)&pStreamBlocks);
|
||||
if (code) {
|
||||
taosArrayClearEx(pRes, (FDelete)blockDataFreeRes);
|
||||
terrno = code;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -132,8 +139,10 @@ int32_t streamRetrieveReqToData(const SStreamRetrieveReq* pReq, SStreamDataBlock
|
|||
}
|
||||
|
||||
SStreamDataSubmit* streamDataSubmitNew(SPackedData* pData, int32_t type) {
|
||||
SStreamDataSubmit* pDataSubmit = (SStreamDataSubmit*)taosAllocateQitem(sizeof(SStreamDataSubmit), DEF_QITEM, pData->msgLen);
|
||||
if (pDataSubmit == NULL) {
|
||||
SStreamDataSubmit* pDataSubmit;
|
||||
int32_t code = taosAllocateQitem(sizeof(SStreamDataSubmit), DEF_QITEM, pData->msgLen, (void**)&pDataSubmit);
|
||||
if (code) {
|
||||
terrno = code;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -151,8 +160,11 @@ void streamDataSubmitDestroy(SStreamDataSubmit* pDataSubmit) {
|
|||
}
|
||||
|
||||
SStreamMergedSubmit* streamMergedSubmitNew() {
|
||||
SStreamMergedSubmit* pMerged = (SStreamMergedSubmit*)taosAllocateQitem(sizeof(SStreamMergedSubmit), DEF_QITEM, 0);
|
||||
if (pMerged == NULL) {
|
||||
SStreamMergedSubmit* pMerged;
|
||||
|
||||
int32_t code = taosAllocateQitem(sizeof(SStreamMergedSubmit), DEF_QITEM, 0, (void**)&pMerged);
|
||||
if (code) {
|
||||
terrno = code;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -212,7 +224,8 @@ SStreamQueueItem* streamQueueMergeQueueItem(SStreamQueueItem* dst, SStreamQueueI
|
|||
taosFreeQitem(pElem);
|
||||
return (SStreamQueueItem*)pMerged;
|
||||
} else {
|
||||
stDebug("block type:%s not merged with existed blocks list, type:%d", streamQueueItemGetTypeStr(pElem->type), dst->type);
|
||||
stDebug("block type:%s not merged with existed blocks list, type:%d", streamQueueItemGetTypeStr(pElem->type),
|
||||
dst->type);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -245,7 +258,8 @@ void streamFreeQitem(SStreamQueueItem* data) {
|
|||
SStreamRefDataBlock* pRefBlock = (SStreamRefDataBlock*)data;
|
||||
blockDataDestroy(pRefBlock->pBlock);
|
||||
taosFreeQitem(pRefBlock);
|
||||
} else if (type == STREAM_INPUT__CHECKPOINT || type == STREAM_INPUT__CHECKPOINT_TRIGGER || type == STREAM_INPUT__TRANS_STATE) {
|
||||
} else if (type == STREAM_INPUT__CHECKPOINT || type == STREAM_INPUT__CHECKPOINT_TRIGGER ||
|
||||
type == STREAM_INPUT__TRANS_STATE) {
|
||||
SStreamDataBlock* pBlock = (SStreamDataBlock*)data;
|
||||
taosArrayDestroyEx(pBlock->blocks, freeItems);
|
||||
taosFreeQitem(pBlock);
|
||||
|
|
|
@ -1162,10 +1162,10 @@ void streamClearChkptReadyMsg(SActiveCheckpointInfo* pActiveInfo) {
|
|||
static int32_t handleDispatchSuccessRsp(SStreamTask* pTask, int32_t downstreamId, int32_t downstreamNodeId) {
|
||||
stDebug("s-task:%s destroy dispatch msg:%p", pTask->id.idStr, pTask->msgInfo.pData);
|
||||
|
||||
bool delayDispatch = (pTask->msgInfo.dispatchMsgType == STREAM_INPUT__CHECKPOINT_TRIGGER);
|
||||
clearBufferedDispatchMsg(pTask);
|
||||
|
||||
int64_t el = taosGetTimestampMs() - pTask->msgInfo.startTs;
|
||||
bool delayDispatch = (pTask->msgInfo.dispatchMsgType == STREAM_INPUT__CHECKPOINT_TRIGGER);
|
||||
|
||||
clearBufferedDispatchMsg(pTask);
|
||||
|
||||
// put data into inputQ of current task is also allowed
|
||||
if (pTask->inputq.status == TASK_INPUT_STATUS__BLOCKED) {
|
||||
|
@ -1189,13 +1189,24 @@ static int32_t handleDispatchSuccessRsp(SStreamTask* pTask, int32_t downstreamId
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t setDispatchRspInfo(SDispatchMsgInfo* pMsgInfo, int32_t vgId, int32_t code, int64_t now, const char* id) {
|
||||
static bool setDispatchRspInfo(SDispatchMsgInfo* pMsgInfo, int32_t vgId, int32_t code, int64_t now, int32_t* pNotRsp, const char* id) {
|
||||
int32_t numOfRsp = 0;
|
||||
bool alreadySet = false;
|
||||
bool updated = false;
|
||||
bool allRsp = false;
|
||||
*pNotRsp = 0;
|
||||
|
||||
taosThreadMutexLock(&pMsgInfo->lock);
|
||||
for (int32_t j = 0; j < taosArrayGetSize(pMsgInfo->pSendInfo); ++j) {
|
||||
int32_t numOfDispatchBranch = taosArrayGetSize(pMsgInfo->pSendInfo);
|
||||
|
||||
for(int32_t i = 0; i < numOfDispatchBranch; ++i) {
|
||||
SDispatchEntry* pEntry = taosArrayGet(pMsgInfo->pSendInfo, i);
|
||||
if (pEntry->rspTs != -1) {
|
||||
numOfRsp += 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t j = 0; j < numOfDispatchBranch; ++j) {
|
||||
SDispatchEntry* pEntry = taosArrayGet(pMsgInfo->pSendInfo, j);
|
||||
if (pEntry->nodeId == vgId) {
|
||||
ASSERT(!alreadySet);
|
||||
|
@ -1203,18 +1214,20 @@ static int32_t setDispatchRspInfo(SDispatchMsgInfo* pMsgInfo, int32_t vgId, int3
|
|||
pEntry->status = code;
|
||||
alreadySet = true;
|
||||
updated = true;
|
||||
stDebug("s-task:%s record the rsp recv, ts:%" PRId64 " code:%d, idx:%d", id, now, code, j);
|
||||
numOfRsp += 1;
|
||||
|
||||
stDebug("s-task:%s record the rsp recv, ts:%" PRId64 " code:%d, idx:%d, total recv:%d/%d", id, now, code, j,
|
||||
numOfRsp, numOfDispatchBranch);
|
||||
}
|
||||
}
|
||||
|
||||
if (pEntry->rspTs != -1) {
|
||||
numOfRsp += 1;
|
||||
}
|
||||
}
|
||||
*pNotRsp = numOfDispatchBranch - numOfRsp;
|
||||
allRsp = (numOfRsp == numOfDispatchBranch);
|
||||
|
||||
taosThreadMutexUnlock(&pMsgInfo->lock);
|
||||
ASSERT(updated);
|
||||
|
||||
return numOfRsp;
|
||||
ASSERT(updated);
|
||||
return allRsp;
|
||||
}
|
||||
|
||||
bool isDispatchRspTimeout(SDispatchEntry* pEntry, int64_t now) {
|
||||
|
@ -1240,7 +1253,8 @@ int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, i
|
|||
int32_t vgId = pTask->pMeta->vgId;
|
||||
SDispatchMsgInfo* pMsgInfo = &pTask->msgInfo;
|
||||
int64_t now = taosGetTimestampMs();
|
||||
int32_t totalRsp = 0;
|
||||
bool allRsp = false;
|
||||
int32_t notRsp = 0;
|
||||
|
||||
taosThreadMutexLock(&pMsgInfo->lock);
|
||||
int32_t msgId = pMsgInfo->msgId;
|
||||
|
@ -1269,18 +1283,18 @@ int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, i
|
|||
if (code == TSDB_CODE_STREAM_TASK_NOT_EXIST) { // destination task does not exist, not retry anymore
|
||||
stError("s-task:%s failed to dispatch msg to task:0x%x(vgId:%d), msgId:%d no retry, since task destroyed already",
|
||||
id, pRsp->downstreamTaskId, pRsp->downstreamNodeId, msgId);
|
||||
totalRsp = setDispatchRspInfo(pMsgInfo, pRsp->downstreamNodeId, TSDB_CODE_SUCCESS, now, id);
|
||||
allRsp = setDispatchRspInfo(pMsgInfo, pRsp->downstreamNodeId, TSDB_CODE_SUCCESS, now, ¬Rsp, id);
|
||||
} else {
|
||||
stError("s-task:%s failed to dispatch msgId:%d to task:0x%x(vgId:%d), code:%s, add to retry list", id, msgId,
|
||||
pRsp->downstreamTaskId, pRsp->downstreamNodeId, tstrerror(code));
|
||||
totalRsp = setDispatchRspInfo(pMsgInfo, pRsp->downstreamNodeId, code, now, id);
|
||||
allRsp = setDispatchRspInfo(pMsgInfo, pRsp->downstreamNodeId, code, now, ¬Rsp, id);
|
||||
}
|
||||
|
||||
} else { // code == 0
|
||||
if (pRsp->inputStatus == TASK_INPUT_STATUS__BLOCKED) {
|
||||
pTask->inputq.status = TASK_INPUT_STATUS__BLOCKED;
|
||||
// block the input of current task, to push pressure to upstream
|
||||
totalRsp = setDispatchRspInfo(pMsgInfo, pRsp->downstreamNodeId, pRsp->inputStatus, now, id);
|
||||
allRsp = setDispatchRspInfo(pMsgInfo, pRsp->downstreamNodeId, pRsp->inputStatus, now, ¬Rsp, id);
|
||||
stTrace("s-task:%s inputQ of downstream task:0x%x(vgId:%d) is full, wait for retry dispatch", id,
|
||||
pRsp->downstreamTaskId, pRsp->downstreamNodeId);
|
||||
} else {
|
||||
|
@ -1292,7 +1306,7 @@ int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, i
|
|||
id, pRsp->downstreamTaskId, pRsp->downstreamNodeId);
|
||||
}
|
||||
|
||||
totalRsp = setDispatchRspInfo(pMsgInfo, pRsp->downstreamNodeId, TSDB_CODE_SUCCESS, now, id);
|
||||
allRsp = setDispatchRspInfo(pMsgInfo, pRsp->downstreamNodeId, TSDB_CODE_SUCCESS, now, ¬Rsp, id);
|
||||
|
||||
{
|
||||
bool delayDispatch = (pMsgInfo->dispatchMsgType == STREAM_INPUT__CHECKPOINT_TRIGGER);
|
||||
|
@ -1317,13 +1331,11 @@ int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, i
|
|||
}
|
||||
}
|
||||
|
||||
int32_t notRsp = taosArrayGetSize(pMsgInfo->pSendInfo) - totalRsp;
|
||||
if (pTask->outputInfo.type == TASK_OUTPUT__SHUFFLE_DISPATCH) {
|
||||
if (notRsp > 0) {
|
||||
if (!allRsp) {
|
||||
stDebug(
|
||||
"s-task:%s recv dispatch rsp, msgId:%d from 0x%x(vgId:%d), downstream task input status:%d code:%s, "
|
||||
"waiting "
|
||||
"for %d rsp",
|
||||
"waiting for %d rsp",
|
||||
id, msgId, pRsp->downstreamTaskId, pRsp->downstreamNodeId, pRsp->inputStatus, tstrerror(code), notRsp);
|
||||
} else {
|
||||
stDebug(
|
||||
|
@ -1337,7 +1349,7 @@ int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, i
|
|||
}
|
||||
|
||||
// all msg rsp already, continue
|
||||
if (notRsp == 0) {
|
||||
if (allRsp) {
|
||||
ASSERT(pTask->outputq.status == TASK_OUTPUT_STATUS__WAIT);
|
||||
|
||||
// we need to re-try send dispatch msg to downstream tasks
|
||||
|
|
|
@ -42,18 +42,26 @@ static void streamQueueCleanup(SStreamQueue* pQueue) {
|
|||
static void* streamQueueCurItem(SStreamQueue* queue) { return queue->qItem; }
|
||||
|
||||
SStreamQueue* streamQueueOpen(int64_t cap) {
|
||||
int32_t code;
|
||||
|
||||
SStreamQueue* pQueue = taosMemoryCalloc(1, sizeof(SStreamQueue));
|
||||
if (pQueue == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pQueue->pQueue = taosOpenQueue();
|
||||
pQueue->qall = taosAllocateQall();
|
||||
code = taosOpenQueue(&pQueue->pQueue);
|
||||
if (code) {
|
||||
taosMemoryFreeClear(pQueue);
|
||||
terrno = code;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pQueue->pQueue == NULL || pQueue->qall == NULL) {
|
||||
if (pQueue->pQueue) taosCloseQueue(pQueue->pQueue);
|
||||
if (pQueue->qall) taosFreeQall(pQueue->qall);
|
||||
code = taosAllocateQall(&pQueue->qall);
|
||||
if (code) {
|
||||
taosCloseQueue(pQueue->pQueue);
|
||||
taosMemoryFree(pQueue);
|
||||
terrno = code;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -64,7 +72,8 @@ SStreamQueue* streamQueueOpen(int64_t cap) {
|
|||
}
|
||||
|
||||
void streamQueueClose(SStreamQueue* pQueue, int32_t taskId) {
|
||||
stDebug("s-task:0x%x free the queue:%p, items in queue:%d", taskId, pQueue->pQueue, taosQueueItemSize(pQueue->pQueue));
|
||||
stDebug("s-task:0x%x free the queue:%p, items in queue:%d", taskId, pQueue->pQueue,
|
||||
taosQueueItemSize(pQueue->pQueue));
|
||||
streamQueueCleanup(pQueue);
|
||||
|
||||
taosFreeQall(pQueue->qall);
|
||||
|
@ -174,7 +183,6 @@ EExtractDataCode streamTaskGetDataFromInputQ(SStreamTask* pTask, SStreamQueueIte
|
|||
|
||||
SStreamQueueItem* qItem = streamQueueNextItem(pTask->inputq.queue);
|
||||
if (qItem == NULL) {
|
||||
|
||||
// restore the token to bucket
|
||||
if (*numOfBlocks > 0) {
|
||||
*blockSize = streamQueueItemGetSize(*pInput);
|
||||
|
@ -332,16 +340,20 @@ int32_t streamTaskPutDataIntoInputQ(SStreamTask* pTask, SStreamQueueItem* pItem)
|
|||
if (type != STREAM_INPUT__GET_RES && type != STREAM_INPUT__CHECKPOINT && type != STREAM_INPUT__CHECKPOINT_TRIGGER &&
|
||||
(pTask->info.delaySchedParam != 0)) {
|
||||
atomic_val_compare_exchange_8(&pTask->schedInfo.status, TASK_TRIGGER_STATUS__INACTIVE, TASK_TRIGGER_STATUS__ACTIVE);
|
||||
stDebug("s-task:%s new data arrived, active the sched-trigger, triggerStatus:%d", pTask->id.idStr, pTask->schedInfo.status);
|
||||
stDebug("s-task:%s new data arrived, active the sched-trigger, triggerStatus:%d", pTask->id.idStr,
|
||||
pTask->schedInfo.status);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t streamTaskPutTranstateIntoInputQ(SStreamTask* pTask) {
|
||||
SStreamDataBlock* pTranstate = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM, sizeof(SSDataBlock));
|
||||
if (pTranstate == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
int32_t code;
|
||||
SStreamDataBlock* pTranstate;
|
||||
|
||||
code = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM, sizeof(SSDataBlock), (void**)&pTranstate);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||
|
@ -460,8 +472,6 @@ void streamTaskPutbackToken(STokenBucket* pBucket) {
|
|||
}
|
||||
|
||||
// size in KB
|
||||
void streamTaskConsumeQuota(STokenBucket* pBucket, int32_t bytes) {
|
||||
pBucket->quotaRemain -= SIZE_IN_MiB(bytes);
|
||||
}
|
||||
void streamTaskConsumeQuota(STokenBucket* pBucket, int32_t bytes) { pBucket->quotaRemain -= SIZE_IN_MiB(bytes); }
|
||||
|
||||
void streamTaskInputFail(SStreamTask* pTask) { atomic_store_8(&pTask->inputq.status, TASK_INPUT_STATUS__FAILED); }
|
|
@ -134,11 +134,14 @@ void streamTaskSchedHelper(void* param, void* tmrId) {
|
|||
stDebug("s-task:%s in checkpoint procedure, not retrieve result, next:%dms", id, nextTrigger);
|
||||
} else {
|
||||
if (status == TASK_TRIGGER_STATUS__ACTIVE) {
|
||||
SStreamTrigger* pTrigger = taosAllocateQitem(sizeof(SStreamTrigger), DEF_QITEM, 0);
|
||||
if (pTrigger == NULL) {
|
||||
SStreamTrigger* pTrigger;
|
||||
|
||||
int32_t code = taosAllocateQitem(sizeof(SStreamTrigger), DEF_QITEM, 0, (void**)&pTrigger);
|
||||
if (code) {
|
||||
stError("s-task:%s failed to prepare retrieve data trigger, code:%s, try again in %dms", id, "out of memory",
|
||||
nextTrigger);
|
||||
taosTmrReset(streamTaskSchedHelper, nextTrigger, pTask, streamTimer, &pTask->schedInfo.pDelayTimer);
|
||||
terrno = code;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -156,7 +159,7 @@ void streamTaskSchedHelper(void* param, void* tmrId) {
|
|||
atomic_store_8(&pTask->schedInfo.status, TASK_TRIGGER_STATUS__INACTIVE);
|
||||
pTrigger->pBlock->info.type = STREAM_GET_ALL;
|
||||
|
||||
int32_t code = streamTaskPutDataIntoInputQ(pTask, (SStreamQueueItem*)pTrigger);
|
||||
code = streamTaskPutDataIntoInputQ(pTask, (SStreamQueueItem*)pTrigger);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
taosTmrReset(streamTaskSchedHelper, nextTrigger, pTask, streamTimer, &pTask->schedInfo.pDelayTimer);
|
||||
return;
|
||||
|
|
|
@ -263,6 +263,7 @@ void tFreeStreamTask(SStreamTask* pTask) {
|
|||
tDeleteSchemaWrapper(pTask->outputInfo.tbSink.pSchemaWrapper);
|
||||
taosMemoryFree(pTask->outputInfo.tbSink.pTSchema);
|
||||
tSimpleHashCleanup(pTask->outputInfo.tbSink.pTblInfo);
|
||||
tDeleteSchemaWrapper(pTask->outputInfo.tbSink.pTagSchema);
|
||||
} else if (pTask->outputInfo.type == TASK_OUTPUT__SHUFFLE_DISPATCH) {
|
||||
taosArrayDestroy(pTask->outputInfo.shuffleDispatcher.dbInfo.pVgroupInfos);
|
||||
}
|
||||
|
@ -979,10 +980,13 @@ char* createStreamTaskIdStr(int64_t streamId, int32_t taskId) {
|
|||
}
|
||||
|
||||
static int32_t streamTaskEnqueueRetrieve(SStreamTask* pTask, SStreamRetrieveReq* pReq) {
|
||||
SStreamDataBlock* pData = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM, sizeof(SStreamDataBlock));
|
||||
if (pData == NULL) {
|
||||
int32_t code;
|
||||
SStreamDataBlock* pData;
|
||||
|
||||
code = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM, sizeof(SStreamDataBlock), (void**)&pData);
|
||||
if (code) {
|
||||
stError("s-task:%s failed to allocated retrieve-block", pTask->id.idStr);
|
||||
return terrno;
|
||||
return terrno = code;
|
||||
}
|
||||
|
||||
// enqueue
|
||||
|
@ -992,7 +996,7 @@ static int32_t streamTaskEnqueueRetrieve(SStreamTask* pTask, SStreamRetrieveReq*
|
|||
pData->type = STREAM_INPUT__DATA_RETRIEVE;
|
||||
pData->srcVgId = 0;
|
||||
|
||||
int32_t code = streamRetrieveReqToData(pReq, pData, pTask->id.idStr);
|
||||
code = streamRetrieveReqToData(pReq, pData, pTask->id.idStr);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
taosFreeQitem(pData);
|
||||
return code;
|
||||
|
|
|
@ -67,7 +67,7 @@ void *processShellMsg(void *arg) {
|
|||
int type;
|
||||
SQueueInfo qinfo = {0};
|
||||
|
||||
qall = taosAllocateQall();
|
||||
taosAllocateQall(&qall);
|
||||
|
||||
while (1) {
|
||||
int numOfMsgs = taosReadAllQitemsFromQset(multiQ->qset[idx], qall, &qinfo);
|
||||
|
@ -129,7 +129,7 @@ void *processShellMsg(void *arg) {
|
|||
void processRequestMsg(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
SRpcMsg *pTemp;
|
||||
|
||||
pTemp = taosAllocateQitem(sizeof(SRpcMsg), DEF_QITEM, 0);
|
||||
taosAllocateQitem(sizeof(SRpcMsg), DEF_QITEM, 0, (void **)&pTemp);
|
||||
memcpy(pTemp, pMsg, sizeof(SRpcMsg));
|
||||
|
||||
int32_t idx = balance % multiQ->numOfThread;
|
||||
|
@ -212,8 +212,8 @@ int main(int argc, char *argv[]) {
|
|||
multiQ->qset = (STaosQset **)taosMemoryMalloc(sizeof(STaosQset *) * numOfAthread);
|
||||
|
||||
for (int i = 0; i < numOfAthread; i++) {
|
||||
multiQ->qhandle[i] = taosOpenQueue();
|
||||
multiQ->qset[i] = taosOpenQset();
|
||||
taosOpenQueue(&multiQ->qhandle[i]);
|
||||
taosOpenQset(&multiQ->qset[i]);
|
||||
taosAddIntoQset(multiQ->qset[i], multiQ->qhandle[i], NULL);
|
||||
}
|
||||
TThread *threads = taosMemoryMalloc(sizeof(TThread) * numOfAthread);
|
||||
|
|
|
@ -675,7 +675,11 @@ void taosHashTableResize(SHashObj *pHashObj) {
|
|||
}
|
||||
|
||||
SHashNode *doCreateHashNode(const void *key, size_t keyLen, const void *pData, size_t dsize, uint32_t hashVal) {
|
||||
#ifdef _TD_LOONGARCH_64
|
||||
SHashNode *pNewNode = taosMemoryCalloc(1, sizeof(SHashNode) + keyLen + dsize + 1);
|
||||
#else
|
||||
SHashNode *pNewNode = taosMemoryMalloc(sizeof(SHashNode) + keyLen + dsize + 1);
|
||||
#endif
|
||||
|
||||
if (pNewNode == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "tqueue.h"
|
||||
#include "taoserror.h"
|
||||
#include "tlog.h"
|
||||
#include "tutil.h"
|
||||
|
||||
int64_t tsRpcQueueMemoryAllowed = 0;
|
||||
int64_t tsRpcQueueMemoryUsed = 0;
|
||||
|
@ -58,20 +59,20 @@ struct STaosQall {
|
|||
void taosSetQueueMemoryCapacity(STaosQueue *queue, int64_t cap) { queue->memLimit = cap; }
|
||||
void taosSetQueueCapacity(STaosQueue *queue, int64_t size) { queue->itemLimit = size; }
|
||||
|
||||
STaosQueue *taosOpenQueue() {
|
||||
STaosQueue *queue = taosMemoryCalloc(1, sizeof(STaosQueue));
|
||||
if (queue == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
int32_t taosOpenQueue(STaosQueue **queue) {
|
||||
*queue = taosMemoryCalloc(1, sizeof(STaosQueue));
|
||||
if (*queue == NULL) {
|
||||
return (terrno = TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
if (taosThreadMutexInit(&queue->mutex, NULL) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
int32_t code = taosThreadMutexInit(&(*queue)->mutex, NULL);
|
||||
if (code) {
|
||||
taosMemoryFreeClear(*queue);
|
||||
return (terrno = TAOS_SYSTEM_ERROR(code));
|
||||
}
|
||||
|
||||
uDebug("queue:%p is opened", queue);
|
||||
return queue;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void taosSetQueueFp(STaosQueue *queue, FItem itemFp, FItems itemsFp) {
|
||||
|
@ -146,11 +147,12 @@ int64_t taosQueueMemorySize(STaosQueue *queue) {
|
|||
return memOfItems;
|
||||
}
|
||||
|
||||
void *taosAllocateQitem(int32_t size, EQItype itype, int64_t dataSize) {
|
||||
int32_t taosAllocateQitem(int32_t size, EQItype itype, int64_t dataSize, void **item) {
|
||||
*item = NULL;
|
||||
|
||||
STaosQnode *pNode = taosMemoryCalloc(1, sizeof(STaosQnode) + size);
|
||||
if (pNode == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pNode->dataSize = dataSize;
|
||||
|
@ -165,15 +167,15 @@ void *taosAllocateQitem(int32_t size, EQItype itype, int64_t dataSize) {
|
|||
tsRpcQueueMemoryAllowed);
|
||||
atomic_sub_fetch_64(&tsRpcQueueMemoryUsed, size + dataSize);
|
||||
taosMemoryFree(pNode);
|
||||
terrno = TSDB_CODE_OUT_OF_RPC_MEMORY_QUEUE;
|
||||
return NULL;
|
||||
return (terrno = TSDB_CODE_OUT_OF_RPC_MEMORY_QUEUE);
|
||||
}
|
||||
uTrace("item:%p, node:%p is allocated, alloc:%" PRId64, pNode->item, pNode, alloced);
|
||||
} else {
|
||||
uTrace("item:%p, node:%p is allocated", pNode->item, pNode);
|
||||
}
|
||||
|
||||
return pNode->item;
|
||||
*item = pNode->item;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void taosFreeQitem(void *pItem) {
|
||||
|
@ -221,13 +223,17 @@ int32_t taosWriteQitem(STaosQueue *queue, void *pItem) {
|
|||
}
|
||||
queue->numOfItems++;
|
||||
queue->memOfItems += (pNode->size + pNode->dataSize);
|
||||
if (queue->qset) atomic_add_fetch_32(&queue->qset->numOfItems, 1);
|
||||
if (queue->qset) {
|
||||
atomic_add_fetch_32(&queue->qset->numOfItems, 1);
|
||||
}
|
||||
|
||||
uTrace("item:%p is put into queue:%p, items:%d mem:%" PRId64, pItem, queue, queue->numOfItems, queue->memOfItems);
|
||||
|
||||
taosThreadMutexUnlock(&queue->mutex);
|
||||
|
||||
if (queue->qset) tsem_post(&queue->qset->sem);
|
||||
if (queue->qset) {
|
||||
tsem_post(&queue->qset->sem);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -241,10 +247,14 @@ int32_t taosReadQitem(STaosQueue *queue, void **ppItem) {
|
|||
pNode = queue->head;
|
||||
*ppItem = pNode->item;
|
||||
queue->head = pNode->next;
|
||||
if (queue->head == NULL) queue->tail = NULL;
|
||||
if (queue->head == NULL) {
|
||||
queue->tail = NULL;
|
||||
}
|
||||
queue->numOfItems--;
|
||||
queue->memOfItems -= (pNode->size + pNode->dataSize);
|
||||
if (queue->qset) atomic_sub_fetch_32(&queue->qset->numOfItems, 1);
|
||||
if (queue->qset) {
|
||||
atomic_sub_fetch_32(&queue->qset->numOfItems, 1);
|
||||
}
|
||||
code = 1;
|
||||
uTrace("item:%p is read out from queue:%p, items:%d mem:%" PRId64, *ppItem, queue, queue->numOfItems,
|
||||
queue->memOfItems);
|
||||
|
@ -255,12 +265,12 @@ int32_t taosReadQitem(STaosQueue *queue, void **ppItem) {
|
|||
return code;
|
||||
}
|
||||
|
||||
STaosQall *taosAllocateQall() {
|
||||
STaosQall *qall = taosMemoryCalloc(1, sizeof(STaosQall));
|
||||
if (qall != NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
int32_t taosAllocateQall(STaosQall **qall) {
|
||||
*qall = taosMemoryCalloc(1, sizeof(STaosQall));
|
||||
if (*qall == NULL) {
|
||||
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
return qall;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void taosFreeQall(STaosQall *qall) { taosMemoryFree(qall); }
|
||||
|
@ -290,7 +300,9 @@ int32_t taosReadAllQitems(STaosQueue *queue, STaosQall *qall) {
|
|||
queue->memOfItems = 0;
|
||||
uTrace("read %d items from queue:%p, items:%d mem:%" PRId64, numOfItems, queue, queue->numOfItems,
|
||||
queue->memOfItems);
|
||||
if (queue->qset) atomic_sub_fetch_32(&queue->qset->numOfItems, qall->numOfItems);
|
||||
if (queue->qset) {
|
||||
atomic_sub_fetch_32(&queue->qset->numOfItems, qall->numOfItems);
|
||||
}
|
||||
}
|
||||
|
||||
taosThreadMutexUnlock(&queue->mutex);
|
||||
|
@ -326,18 +338,17 @@ int32_t taosGetQitem(STaosQall *qall, void **ppItem) {
|
|||
return num;
|
||||
}
|
||||
|
||||
STaosQset *taosOpenQset() {
|
||||
STaosQset *qset = taosMemoryCalloc(sizeof(STaosQset), 1);
|
||||
if (qset == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
int32_t taosOpenQset(STaosQset **qset) {
|
||||
*qset = taosMemoryCalloc(sizeof(STaosQset), 1);
|
||||
if (*qset == NULL) {
|
||||
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
taosThreadMutexInit(&qset->mutex, NULL);
|
||||
tsem_init(&qset->sem, 0, 0);
|
||||
taosThreadMutexInit(&(*qset)->mutex, NULL);
|
||||
tsem_init(&(*qset)->sem, 0, 0);
|
||||
|
||||
uDebug("qset:%p is opened", qset);
|
||||
return qset;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void taosCloseQset(STaosQset *qset) {
|
||||
|
@ -533,9 +544,7 @@ int64_t taosQallUnAccessedMemSize(STaosQall *qall) { return qall->unAccessMemOfI
|
|||
void taosResetQitems(STaosQall *qall) { qall->current = qall->start; }
|
||||
int32_t taosGetQueueNumber(STaosQset *qset) { return qset->numOfQueues; }
|
||||
|
||||
void taosQueueSetThreadId(STaosQueue* pQueue, int64_t threadId) {
|
||||
pQueue->threadId = threadId;
|
||||
}
|
||||
void taosQueueSetThreadId(STaosQueue *pQueue, int64_t threadId) { pQueue->threadId = threadId; }
|
||||
|
||||
int64_t taosQueueGetThreadId(STaosQueue *pQueue) { return pQueue->threadId; }
|
||||
|
||||
|
|
|
@ -16,20 +16,22 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "tworker.h"
|
||||
#include "taoserror.h"
|
||||
#include "tcompare.h"
|
||||
#include "tgeosctx.h"
|
||||
#include "tlog.h"
|
||||
#include "tcompare.h"
|
||||
|
||||
#define QUEUE_THRESHOLD (1000 * 1000)
|
||||
|
||||
typedef void *(*ThreadFp)(void *param);
|
||||
|
||||
int32_t tQWorkerInit(SQWorkerPool *pool) {
|
||||
pool->qset = taosOpenQset();
|
||||
int32_t code = taosOpenQset(&pool->qset);
|
||||
if (code) return code;
|
||||
|
||||
pool->workers = taosMemoryCalloc(pool->max, sizeof(SQueueWorker));
|
||||
if (pool->workers == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
taosCloseQset(pool->qset);
|
||||
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
(void)taosThreadMutexInit(&pool->mutex, NULL);
|
||||
|
@ -109,8 +111,14 @@ static void *tQWorkerThreadFp(SQueueWorker *worker) {
|
|||
}
|
||||
|
||||
STaosQueue *tQWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp) {
|
||||
STaosQueue *queue = taosOpenQueue();
|
||||
if (queue == NULL) return NULL;
|
||||
int32_t code;
|
||||
STaosQueue *queue;
|
||||
|
||||
code = taosOpenQueue(&queue);
|
||||
if (code) {
|
||||
terrno = code;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
taosThreadMutexLock(&pool->mutex);
|
||||
taosSetQueueFp(queue, fp, NULL);
|
||||
|
@ -150,11 +158,17 @@ void tQWorkerFreeQueue(SQWorkerPool *pool, STaosQueue *queue) {
|
|||
}
|
||||
|
||||
int32_t tAutoQWorkerInit(SAutoQWorkerPool *pool) {
|
||||
pool->qset = taosOpenQset();
|
||||
int32_t code;
|
||||
|
||||
code = taosOpenQset(&pool->qset);
|
||||
if (code) {
|
||||
return terrno = code;
|
||||
}
|
||||
|
||||
pool->workers = taosArrayInit(2, sizeof(SQueueWorker *));
|
||||
if (pool->workers == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
taosCloseQset(pool->qset);
|
||||
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
(void)taosThreadMutexInit(&pool->mutex, NULL);
|
||||
|
@ -228,8 +242,14 @@ static void *tAutoQWorkerThreadFp(SQueueWorker *worker) {
|
|||
}
|
||||
|
||||
STaosQueue *tAutoQWorkerAllocQueue(SAutoQWorkerPool *pool, void *ahandle, FItem fp) {
|
||||
STaosQueue *queue = taosOpenQueue();
|
||||
if (queue == NULL) return NULL;
|
||||
int32_t code;
|
||||
STaosQueue *queue;
|
||||
|
||||
code = taosOpenQueue(&queue);
|
||||
if (code) {
|
||||
terrno = code;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
taosThreadMutexLock(&pool->mutex);
|
||||
taosSetQueueFp(queue, fp, NULL);
|
||||
|
@ -377,18 +397,19 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) {
|
|||
taosThreadMutexLock(&pool->mutex);
|
||||
SWWorker *worker = pool->workers + pool->nextId;
|
||||
int32_t code = -1;
|
||||
STaosQueue *queue;
|
||||
|
||||
STaosQueue *queue = taosOpenQueue();
|
||||
if (queue == NULL) goto _OVER;
|
||||
code = taosOpenQueue(&queue);
|
||||
if (code) goto _OVER;
|
||||
|
||||
taosSetQueueFp(queue, NULL, fp);
|
||||
if (worker->qset == NULL) {
|
||||
worker->qset = taosOpenQset();
|
||||
if (worker->qset == NULL) goto _OVER;
|
||||
code = taosOpenQset(&worker->qset);
|
||||
if (code) goto _OVER;
|
||||
|
||||
taosAddIntoQset(worker->qset, queue, ahandle);
|
||||
worker->qall = taosAllocateQall();
|
||||
if (worker->qall == NULL) goto _OVER;
|
||||
code = taosAllocateQall(&worker->qall);
|
||||
if (code) goto _OVER;
|
||||
|
||||
TdThreadAttr thAttr;
|
||||
taosThreadAttrInit(&thAttr);
|
||||
|
@ -406,12 +427,10 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) {
|
|||
pool->nextId = (pool->nextId + 1) % pool->max;
|
||||
}
|
||||
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
taosThreadMutexUnlock(&pool->mutex);
|
||||
|
||||
if (code == -1) {
|
||||
if (code) {
|
||||
if (queue != NULL) taosCloseQueue(queue);
|
||||
if (worker->qset != NULL) taosCloseQset(worker->qset);
|
||||
if (worker->qall != NULL) taosFreeQall(worker->qall);
|
||||
|
@ -758,8 +777,9 @@ bool tQueryAutoQWorkerTryRecycleWorker(SQueryAutoQWorkerPool* pPool, SQueryAutoQ
|
|||
}
|
||||
|
||||
int32_t tQueryAutoQWorkerInit(SQueryAutoQWorkerPool *pool) {
|
||||
pool->qset = taosOpenQset();
|
||||
if (!pool->qset) return terrno;
|
||||
int32_t code;
|
||||
code = taosOpenQset(&pool->qset);
|
||||
if (code) return terrno = code;
|
||||
pool->workers = tdListNew(sizeof(SQueryAutoQWorker));
|
||||
if (!pool->workers) return TSDB_CODE_OUT_OF_MEMORY;
|
||||
pool->backupWorkers = tdListNew(sizeof(SQueryAutoQWorker));
|
||||
|
@ -867,8 +887,12 @@ void tQueryAutoQWorkerCleanup(SQueryAutoQWorkerPool *pPool) {
|
|||
}
|
||||
|
||||
STaosQueue *tQueryAutoQWorkerAllocQueue(SQueryAutoQWorkerPool *pool, void *ahandle, FItem fp) {
|
||||
STaosQueue *queue = taosOpenQueue();
|
||||
if (queue == NULL) return NULL;
|
||||
STaosQueue *queue;
|
||||
int32_t code = taosOpenQueue(&queue);
|
||||
if (code) {
|
||||
terrno = code;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
taosThreadMutexLock(&pool->poolLock);
|
||||
taosSetQueueFp(queue, fp, NULL);
|
||||
|
@ -915,9 +939,7 @@ STaosQueue *tQueryAutoQWorkerAllocQueue(SQueryAutoQWorkerPool *pool, void *ahand
|
|||
return queue;
|
||||
}
|
||||
|
||||
void tQueryAutoQWorkerFreeQueue(SQueryAutoQWorkerPool *pPool, STaosQueue *pQ) {
|
||||
taosCloseQueue(pQ);
|
||||
}
|
||||
void tQueryAutoQWorkerFreeQueue(SQueryAutoQWorkerPool *pPool, STaosQueue *pQ) { taosCloseQueue(pQ); }
|
||||
|
||||
static int32_t tQueryAutoQWorkerAddWorker(SQueryAutoQWorkerPool *pool) {
|
||||
// try backup pool
|
||||
|
|
|
@ -71,7 +71,6 @@ class TDTestCase(TBase):
|
|||
"smlTsDefaultName tsdef",
|
||||
"serverPort 6030",
|
||||
"timezone tz",
|
||||
"tempDir /var/tmp"
|
||||
]
|
||||
# exec
|
||||
for option in options:
|
||||
|
|
|
@ -11,61 +11,216 @@ class TDTestCase(TBase):
|
|||
def init(self, conn, logSql, replicaVar=1):
|
||||
tdLog.debug(f"start to excute {__file__}")
|
||||
tdSql.init(conn.cursor(), True)
|
||||
self.dbname = "cast_db"
|
||||
self._datetime_epoch = datetime.datetime.fromtimestamp(0)
|
||||
|
||||
def cast_without_from(self):
|
||||
def cast_from_int_to_other(self):
|
||||
# int
|
||||
int_num = 2147483648
|
||||
tdSql.query(f"select cast({int_num} as int) re;")
|
||||
tdSql.checkData(0, 0, -int_num)
|
||||
int_num1 = 2147483647
|
||||
int_num2 = 2147483648
|
||||
tdSql.query(f"select cast({int_num1} as int) re;")
|
||||
tdSql.checkData(0, 0, int_num1)
|
||||
|
||||
tdSql.query(f"select cast(2147483647 as int) re;")
|
||||
tdSql.checkData(0, 0, 2147483647)
|
||||
tdSql.query(f"select cast({int_num2} as int) re;")
|
||||
tdSql.checkData(0, 0, -int_num2)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
tdSql.query(f"select cast({int_num2} as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, int_num2)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as bigint) re;")
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
tdSql.query(f"select cast({int_num1} as bigint) re;")
|
||||
tdSql.checkData(0, 0, int_num1)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as bigint unsigned) re;")
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
tdSql.query(f"select cast({int_num1} as bigint unsigned) re;")
|
||||
tdSql.checkData(0, 0, int_num1)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as smallint) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.query(f"select cast({int_num1} as smallint) re;")
|
||||
tdSql.checkData(0, 0, -1)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as smallint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.query(f"select cast({int_num1} as smallint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 65535)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.query(f"select cast({int_num1} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, -1)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as tinyint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.query(f"select cast({int_num1} as tinyint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 255)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as float) re;")
|
||||
tdSql.checkData(0, 0, '2147483648.0')
|
||||
tdSql.query(f"select cast({int_num2} as float) re;")
|
||||
tdSql.checkData(0, 0, "2147483648.0")
|
||||
|
||||
tdSql.query(f"select cast({int_num} as double) re;")
|
||||
tdSql.checkData(0, 0, '2147483648.0')
|
||||
tdSql.query(f"select cast({int_num2} as double) re;")
|
||||
tdSql.checkData(0, 0, "2147483648.0")
|
||||
|
||||
tdSql.query(f"select cast({int_num} as bool) as re;")
|
||||
tdSql.query(f"select cast({int_num2} as bool) as re;")
|
||||
tdSql.checkData(0, 0, True)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as timestamp) as re;")
|
||||
tdSql.checkData(0, 0, self._datetime_epoch + datetime.timedelta(seconds=int(int_num) / 1000))
|
||||
tdSql.query(f"select cast({int_num2} as timestamp) as re;")
|
||||
tdSql.checkData(0, 0, self._datetime_epoch + datetime.timedelta(seconds=int(int_num2) / 1000))
|
||||
|
||||
tdSql.query(f"select cast({int_num} as varchar(10)) as re;")
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
tdSql.query(f"select cast({int_num1} as varchar(5)) as re;")
|
||||
tdSql.checkData(0, 0, "21474")
|
||||
|
||||
tdSql.query(f"select cast({int_num} as binary(10)) as re;")
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
tdSql.query(f"select cast({int_num1} as binary(5)) as re;")
|
||||
tdSql.checkData(0, 0, "21474")
|
||||
|
||||
sql = f"select cast({int_num} as nchar(10));"
|
||||
tdSql.query(sql)
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
tdSql.query(f"select cast({int_num1} as nchar(5));")
|
||||
tdSql.checkData(0, 0, "21474")
|
||||
|
||||
def cast_from_bigint_to_other(self):
|
||||
# bigint
|
||||
bigint_num = 9223372036854775807
|
||||
bigint_num2 = 9223372036854775808
|
||||
tdSql.query(f"select cast({bigint_num} as int) re;")
|
||||
tdSql.checkData(0, 0, -1)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, 4294967295)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as bigint) re;")
|
||||
tdSql.checkData(0, 0, bigint_num)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num2} as bigint) re;")
|
||||
tdSql.checkData(0, 0, -bigint_num2)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num2} as bigint unsigned) re;")
|
||||
tdSql.checkData(0, 0, bigint_num2)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as smallint) re;")
|
||||
tdSql.checkData(0, 0, -1)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as smallint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 65535)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, -1)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as tinyint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 255)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as float) re;")
|
||||
tdSql.checkData(0, 0, 9.2233720e18)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as double) re;")
|
||||
tdSql.checkData(0, 0, 9.2233720e18)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as bool) as re;")
|
||||
tdSql.checkData(0, 0, True)
|
||||
|
||||
# WARN: datetime overflow dont worry
|
||||
tdSql.query(f"select cast({bigint_num} as timestamp) as re;")
|
||||
# tdSql.checkData(0, 0, "292278994-08-17 15:12:55.807")
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as varchar(5)) as re;")
|
||||
tdSql.checkData(0, 0, "92233")
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as binary(5)) as re;")
|
||||
tdSql.checkData(0, 0, "92233")
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as nchar(5));")
|
||||
tdSql.checkData(0, 0, "92233")
|
||||
|
||||
def cast_from_smallint_to_other(self):
|
||||
smallint_num = 32767
|
||||
smallint_num2 = 32768
|
||||
tdSql.query(f"select cast({smallint_num} as int) re;")
|
||||
tdSql.checkData(0, 0, smallint_num)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, smallint_num)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as bigint) re;")
|
||||
tdSql.checkData(0, 0, smallint_num)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num2} as bigint unsigned) re;")
|
||||
tdSql.checkData(0, 0, smallint_num2)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as smallint) re;")
|
||||
tdSql.checkData(0, 0, smallint_num)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num2} as smallint) re;")
|
||||
tdSql.checkData(0, 0, -smallint_num2)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num2} as smallint unsigned) re;")
|
||||
tdSql.checkData(0, 0, smallint_num2)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, -1)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as tinyint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 255)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as float) re;")
|
||||
tdSql.checkData(0, 0, "32767.0")
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as double) re;")
|
||||
tdSql.checkData(0, 0, "32767.0")
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as bool) as re;")
|
||||
tdSql.checkData(0, 0, True)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as timestamp) as re;")
|
||||
tdSql.checkData(0, 0, self._datetime_epoch + datetime.timedelta(seconds=int(smallint_num) / 1000))
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as varchar(3)) as re;")
|
||||
tdSql.checkData(0, 0, "327")
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as binary(3)) as re;")
|
||||
tdSql.checkData(0, 0, "327")
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as nchar(3));")
|
||||
tdSql.checkData(0, 0, "327")
|
||||
|
||||
def cast_from_tinyint_to_other(self):
|
||||
tinyint_num = 127
|
||||
tinyint_num2 = 128
|
||||
tdSql.query(f"select cast({tinyint_num} as int) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as bigint) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num2} as bigint unsigned) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num2)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as smallint) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as smallint unsigned) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num2} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, -tinyint_num2)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num2} as tinyint unsigned) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num2)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as float) re;")
|
||||
tdSql.checkData(0, 0, "127.0")
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as double) re;")
|
||||
tdSql.checkData(0, 0, "127.0")
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as bool) as re;")
|
||||
tdSql.checkData(0, 0, True)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as timestamp) as re;")
|
||||
tdSql.checkData(0, 0, self._datetime_epoch + datetime.timedelta(seconds=int(tinyint_num) / 1000))
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as varchar(2)) as re;")
|
||||
tdSql.checkData(0, 0, "12")
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as binary(2)) as re;")
|
||||
tdSql.checkData(0, 0, "12")
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as nchar(2));")
|
||||
tdSql.checkData(0, 0, "12")
|
||||
|
||||
def cast_from_float_to_other(self):
|
||||
# float
|
||||
float_1001 = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019
|
||||
|
||||
|
@ -116,22 +271,31 @@ class TDTestCase(TBase):
|
|||
tdSql.query(f"select cast({float_1001} as nchar(5));")
|
||||
tdSql.checkData(0, 0, 3.141)
|
||||
|
||||
def cast_from_str_to_other(self):
|
||||
# str
|
||||
str_410 = "bcdefghigk" * 41
|
||||
big_str = "bcdefghigk" * 6552
|
||||
_str = "bcdefghigk"
|
||||
str_410 = _str * 41
|
||||
str_401 = _str * 40 + "b"
|
||||
big_str = _str * 6552
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as binary(3)) as re;")
|
||||
tdSql.checkData(0, 0, "bcd")
|
||||
tdSql.query(f"select cast('{str_410}' as binary(401)) as re;")
|
||||
tdSql.checkData(0, 0, str_401)
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as varchar(2)) as re;")
|
||||
tdSql.checkData(0, 0, "bc")
|
||||
tdSql.query(f"select cast('{str_410}' as varchar(401)) as re;")
|
||||
tdSql.checkData(0, 0, str_401)
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as nchar(10));")
|
||||
tdSql.checkData(0, 0, "bcdefghigk")
|
||||
tdSql.query(f"select cast('{big_str}' as varchar(420)) as re;")
|
||||
tdSql.checkData(0, 0, _str * 42)
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as nchar(401));")
|
||||
tdSql.checkData(0, 0, str_401)
|
||||
|
||||
tdSql.query(f"select cast('北京' as nchar(10));")
|
||||
tdSql.checkData(0, 0, "北京")
|
||||
|
||||
# tdSql.query(f"select cast('北京涛思数据有限公司' as nchar(6));")
|
||||
# tdSql.checkData(0, 0, "北京涛思数据")
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as int) as re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
|
||||
|
@ -168,12 +332,229 @@ class TDTestCase(TBase):
|
|||
tdSql.query(f"select cast('{str_410}' as timestamp) as re")
|
||||
tdSql.checkData(0, 0, "1970-01-01 08:00:00.000")
|
||||
|
||||
def cast_from_bool_to_other(self):
|
||||
true_val = True
|
||||
false_val = False
|
||||
tdSql.query(f"select cast({false_val} as int) re, cast({true_val} as int) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as int unsigned) re, cast({true_val} as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as bigint) re, cast({true_val} as bigint) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(
|
||||
f"select cast({false_val} as bigint unsigned) re, cast({true_val} as bigint unsigned) re;"
|
||||
)
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as smallint) re, cast({true_val} as smallint) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(
|
||||
f"select cast({false_val} as smallint unsigned) re, cast({true_val} as smallint unsigned) re;"
|
||||
)
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as tinyint) re, cast({true_val} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(
|
||||
f"select cast({false_val} as tinyint unsigned) re, cast({true_val} as tinyint unsigned) re;"
|
||||
)
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as smallint) re, cast({true_val} as smallint) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as float) re, cast({true_val} as float) re;")
|
||||
tdSql.checkData(0, 0, 0.0000000)
|
||||
tdSql.checkData(0, 1, 1.0000000)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as double) re, cast({true_val} as double) re;")
|
||||
tdSql.checkData(0, 0, 0.000000000000000)
|
||||
tdSql.checkData(0, 1, 1.000000000000000)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as bool) re, cast({true_val} as bool) re;")
|
||||
tdSql.checkData(0, 0, false_val)
|
||||
tdSql.checkData(0, 1, true_val)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as timestamp) re, cast({true_val} as timestamp) re;")
|
||||
tdSql.checkData(0, 0, "1970-01-01 08:00:00.000")
|
||||
tdSql.checkData(0, 1, "1970-01-01 08:00:00.001")
|
||||
|
||||
tdSql.query(f"select cast({false_val} as varchar(3)) re, cast({true_val} as varchar(3)) re;")
|
||||
tdSql.checkData(0, 0, "fal")
|
||||
tdSql.checkData(0, 1, "tru")
|
||||
|
||||
tdSql.query(f"select cast({false_val} as binary(3)) re, cast({true_val} as binary(3)) re;")
|
||||
tdSql.checkData(0, 0, "fal")
|
||||
tdSql.checkData(0, 1, "tru")
|
||||
|
||||
tdSql.query(f"select cast({false_val} as nchar(3)) re, cast({true_val} as nchar(3)) re;")
|
||||
tdSql.checkData(0, 0, "fal")
|
||||
tdSql.checkData(0, 1, "tru")
|
||||
|
||||
def cast_from_timestamp_to_other(self):
|
||||
# ts = self._datetime_epoch
|
||||
# tdSql.query(f"select cast({ts} as int) re;")
|
||||
# tdSql.checkData(0, 0, None)
|
||||
# todo
|
||||
pass
|
||||
|
||||
def cast_from_null_to_other(self):
|
||||
tdSql.query(f"select cast(null as int) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as bigint) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as bigint unsigned) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as smallint) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as smallint unsigned) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as tinyint) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as tinyint unsigned) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as float) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as double) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as bool) as re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as timestamp) as re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as varchar(55)) as re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as binary(5)) as re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as nchar(5));")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
def cast_from_compute_to_other(self):
|
||||
add1 = 123
|
||||
add2 = 456
|
||||
re = 579
|
||||
tdSql.query(f"select cast({add1}+{add2} as int) re;")
|
||||
tdSql.checkData(0, 0, re)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, re)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as bigint) re;")
|
||||
tdSql.checkData(0, 0, re)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as bigint unsigned) re;")
|
||||
tdSql.checkData(0, 0, re)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as smallint) re;")
|
||||
tdSql.checkData(0, 0, re)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as smallint unsigned) re;")
|
||||
tdSql.checkData(0, 0, re)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, 67)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as tinyint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 67)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as float) re;")
|
||||
tdSql.checkData(0, 0, "579.0")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as double) re;")
|
||||
tdSql.checkData(0, 0, "579.0")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as bool) as re;")
|
||||
tdSql.checkData(0, 0, True)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as timestamp) as re;")
|
||||
tdSql.checkData(0, 0, self._datetime_epoch + datetime.timedelta(seconds=int(re) / 1000))
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as varchar(2)) as re;")
|
||||
tdSql.checkData(0, 0, "57")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as binary(2)) as re;")
|
||||
tdSql.checkData(0, 0, "57")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as nchar(2));")
|
||||
tdSql.checkData(0, 0, "57")
|
||||
|
||||
test_str = "'!@#'"
|
||||
tdSql.query(f"select cast({add1}+{test_str} as int) re;")
|
||||
tdSql.checkData(0, 0, add1)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as bigint) re;")
|
||||
tdSql.checkData(0, 0, add1)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as smallint) re;")
|
||||
tdSql.checkData(0, 0, add1)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, add1)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as float) re;")
|
||||
tdSql.checkData(0, 0, "123.0")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as double) re;")
|
||||
tdSql.checkData(0, 0, "123.0")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as bool) re;")
|
||||
tdSql.checkData(0, 0, True)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as timestamp) re;")
|
||||
tdSql.checkData(0, 0, self._datetime_epoch + datetime.timedelta(seconds=int(add1) / 1000))
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as varchar(2)) re;")
|
||||
tdSql.checkData(0, 0, "12")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as binary(2)) re;")
|
||||
tdSql.checkData(0, 0, "12")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as nchar(2)) re;")
|
||||
tdSql.checkData(0, 0, "12")
|
||||
|
||||
def cast_without_from(self):
|
||||
self.cast_from_int_to_other()
|
||||
self.cast_from_bigint_to_other()
|
||||
self.cast_from_smallint_to_other()
|
||||
self.cast_from_tinyint_to_other()
|
||||
self.cast_from_float_to_other()
|
||||
self.cast_from_str_to_other()
|
||||
self.cast_from_bool_to_other()
|
||||
self.cast_from_timestamp_to_other()
|
||||
self.cast_from_compute_to_other()
|
||||
# self.cast_from_null_to_other()
|
||||
|
||||
def run(self):
|
||||
# self.prepare_data()
|
||||
# self.all_test()
|
||||
# tdSql.execute(f"flush database {self.dbname}")
|
||||
# self.all_test()
|
||||
# 'from table' case see system-test/2-query/cast.py
|
||||
self.cast_without_from()
|
||||
|
||||
tdLog.success(f"{__file__} successfully executed")
|
||||
|
|
|
@ -38,15 +38,16 @@ class TDSimClient:
|
|||
"asyncLog": "0",
|
||||
"rpcDebugFlag": "135",
|
||||
"tmrDebugFlag": "131",
|
||||
"cDebugFlag": "135",
|
||||
"uDebugFlag": "135",
|
||||
"jniDebugFlag": "135",
|
||||
"dDebugFlag":"131",
|
||||
"cDebugFlag": "131",
|
||||
"uDebugFlag": "131",
|
||||
"jniDebugFlag": "131",
|
||||
"qDebugFlag": "135",
|
||||
"supportVnodes": "1024",
|
||||
"enableQueryHb": "1",
|
||||
"telemetryReporting": "0",
|
||||
"tqDebugflag": "135",
|
||||
"wDebugflag":"135",
|
||||
"stDebugflag":"135",
|
||||
}
|
||||
|
||||
def getLogDir(self):
|
||||
|
@ -134,9 +135,9 @@ class TDDnode:
|
|||
"dDebugFlag": "131",
|
||||
"vDebugFlag": "131",
|
||||
"tqDebugFlag": "135",
|
||||
"cDebugFlag": "135",
|
||||
"cDebugFlag": "131",
|
||||
"stDebugFlag": "135",
|
||||
"smaDebugFlag": "135",
|
||||
"smaDebugFlag": "131",
|
||||
"jniDebugFlag": "131",
|
||||
"qDebugFlag": "131",
|
||||
"rpcDebugFlag": "135",
|
||||
|
|
|
@ -307,8 +307,8 @@ class TDSql:
|
|||
return col_name_list, col_type_list
|
||||
return col_name_list
|
||||
|
||||
def waitedQuery(self, sql, expectRows, timeout):
|
||||
tdLog.info("sql: %s, try to retrieve %d rows in %d seconds" % (sql, expectRows, timeout))
|
||||
def waitedQuery(self, sql, expectedRows, timeout):
|
||||
tdLog.info("sql: %s, try to retrieve %d rows in %d seconds" % (sql, expectedRows, timeout))
|
||||
self.sql = sql
|
||||
try:
|
||||
for i in range(timeout):
|
||||
|
@ -316,8 +316,8 @@ class TDSql:
|
|||
self.queryResult = self.cursor.fetchall()
|
||||
self.queryRows = len(self.queryResult)
|
||||
self.queryCols = len(self.cursor.description)
|
||||
tdLog.info("sql: %s, try to retrieve %d rows,get %d rows" % (sql, expectRows, self.queryRows))
|
||||
if self.queryRows >= expectRows:
|
||||
tdLog.info("sql: %s, try to retrieve %d rows,get %d rows" % (sql, expectedRows, self.queryRows))
|
||||
if self.queryRows >= expectedRows:
|
||||
return (self.queryRows, i)
|
||||
time.sleep(1)
|
||||
except Exception as e:
|
||||
|
@ -330,15 +330,26 @@ class TDSql:
|
|||
def getRows(self):
|
||||
return self.queryRows
|
||||
|
||||
def checkRows(self, expectRows):
|
||||
if self.queryRows == expectRows:
|
||||
tdLog.info("sql:%s, queryRows:%d == expect:%d" % (self.sql, self.queryRows, expectRows))
|
||||
def checkRows(self, expectedRows):
|
||||
if self.queryRows == expectedRows:
|
||||
tdLog.info("sql:%s, queryRows:%d == expect:%d" % (self.sql, self.queryRows, expectedRows))
|
||||
return True
|
||||
else:
|
||||
caller = inspect.getframeinfo(inspect.stack()[1][0])
|
||||
args = (caller.filename, caller.lineno, self.sql, self.queryRows, expectRows)
|
||||
args = (caller.filename, caller.lineno, self.sql, self.queryRows, expectedRows)
|
||||
tdLog.exit("%s(%d) failed: sql:%s, queryRows:%d != expect:%d" % args)
|
||||
|
||||
def checkRows_not_exited(self, expectedRows):
|
||||
"""
|
||||
Check if the query rows is equal to the expected rows
|
||||
:param expectedRows: The expected number of rows.
|
||||
:return: Returns True if the actual number of rows matches the expected number, otherwise returns False.
|
||||
"""
|
||||
if self.queryRows == expectedRows:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def checkRows_range(self, excepte_row_list):
|
||||
if self.queryRows in excepte_row_list:
|
||||
tdLog.info(f"sql:{self.sql}, queryRows:{self.queryRows} in expect:{excepte_row_list}")
|
||||
|
@ -508,7 +519,7 @@ class TDSql:
|
|||
|
||||
|
||||
# return true or false replace exit, no print out
|
||||
def checkDataNoExit(self, row, col, data):
|
||||
def checkDataNotExit(self, row, col, data):
|
||||
if self.checkRowColNoExit(row, col) == False:
|
||||
return False
|
||||
if self.queryResult[row][col] != data:
|
||||
|
@ -542,7 +553,7 @@ class TDSql:
|
|||
# loop check util checkData return true
|
||||
for i in range(loopCount):
|
||||
self.query(sql)
|
||||
if self.checkDataNoExit(row, col, data) :
|
||||
if self.checkDataNotExit(row, col, data) :
|
||||
self.checkData(row, col, data)
|
||||
return
|
||||
time.sleep(waitTime)
|
||||
|
@ -551,6 +562,19 @@ class TDSql:
|
|||
self.query(sql)
|
||||
self.checkData(row, col, data)
|
||||
|
||||
def check_rows_loop(self, expectedRows, sql, loopCount, waitTime):
|
||||
# loop check util checkData return true
|
||||
for i in range(loopCount):
|
||||
self.query(sql)
|
||||
if self.checkRows_not_exited(expectedRows):
|
||||
return
|
||||
else:
|
||||
time.sleep(waitTime)
|
||||
continue
|
||||
# last check
|
||||
self.query(sql)
|
||||
self.checkRows(expectedRows)
|
||||
|
||||
|
||||
def getData(self, row, col):
|
||||
self.checkRowCol(row, col)
|
||||
|
|
|
@ -297,7 +297,8 @@ class TDTestCase:
|
|||
'mysql':'MySQL',
|
||||
'postgres':'PostgreSQL',
|
||||
'oracle':'Oracle',
|
||||
'mssql':'SqlServer'
|
||||
'mssql':'SqlServer',
|
||||
'mongodb':'MongoDB',
|
||||
}
|
||||
|
||||
tdSql.execute('drop database if exists db2')
|
||||
|
|
|
@ -177,21 +177,15 @@ class TDTestCase:
|
|||
if stopRole == "mnode":
|
||||
for i in range(mnodeNums):
|
||||
tdDnodes[i].stoptaosd()
|
||||
# sleep(10)
|
||||
tdDnodes[i].starttaosd()
|
||||
# sleep(10)
|
||||
elif stopRole == "vnode":
|
||||
for i in range(vnodeNumbers):
|
||||
tdDnodes[i+mnodeNums].stoptaosd()
|
||||
# sleep(10)
|
||||
tdDnodes[i+mnodeNums].starttaosd()
|
||||
# sleep(10)
|
||||
elif stopRole == "dnode":
|
||||
for i in range(dnodeNumbers):
|
||||
tdDnodes[i].stoptaosd()
|
||||
# sleep(10)
|
||||
tdDnodes[i].starttaosd()
|
||||
# sleep(10)
|
||||
|
||||
# dnodeNumbers don't include database of schema
|
||||
if clusterComCheck.checkDnodes(dnodeNumbers):
|
||||
|
@ -219,7 +213,7 @@ class TDTestCase:
|
|||
tdSql.checkRows(rowsPerStb)
|
||||
def run(self):
|
||||
# print(self.master_dnode.cfgDict)
|
||||
self.fiveDnodeThreeMnode(dnodeNumbers=6,mnodeNums=3,restartNumbers=2,stopRole='dnode')
|
||||
self.fiveDnodeThreeMnode(dnodeNumbers=6,mnodeNums=3,restartNumbers=1,stopRole='dnode')
|
||||
|
||||
def stop(self):
|
||||
tdSql.close()
|
||||
|
|
|
@ -227,7 +227,7 @@ class TDTestCase:
|
|||
|
||||
def run(self):
|
||||
# print(self.master_dnode.cfgDict)
|
||||
self.fiveDnodeThreeMnode(dnodeNumbers=6,mnodeNums=3,restartNumbers=2,stopRole='dnode')
|
||||
self.fiveDnodeThreeMnode(dnodeNumbers=6,mnodeNums=3,restartNumbers=1,stopRole='dnode')
|
||||
|
||||
def stop(self):
|
||||
tdSql.close()
|
||||
|
|
|
@ -168,7 +168,7 @@ class TDTestCase:
|
|||
|
||||
def run(self):
|
||||
# print(self.master_dnode.cfgDict)
|
||||
self.fiveDnodeThreeMnode(dnodeNumbers=5,mnodeNums=3,restartNumbers=2,stopRole='dnode')
|
||||
self.fiveDnodeThreeMnode(dnodeNumbers=5,mnodeNums=3,restartNumbers=1,stopRole='dnode')
|
||||
|
||||
def stop(self):
|
||||
tdSql.close()
|
||||
|
|
|
@ -170,7 +170,7 @@ class TDTestCase:
|
|||
|
||||
def run(self):
|
||||
# print(self.master_dnode.cfgDict)
|
||||
self.fiveDnodeThreeMnode(dnodeNumbers=6,mnodeNums=3,restartNumbers=4,stopRole='mnode')
|
||||
self.fiveDnodeThreeMnode(dnodeNumbers=6,mnodeNums=3,restartNumbers=2,stopRole='mnode')
|
||||
|
||||
def stop(self):
|
||||
tdSql.close()
|
||||
|
|
|
@ -93,7 +93,7 @@ class TDTestCase:
|
|||
# seperate vnode and mnode in different dnodes.
|
||||
# create database and stable
|
||||
stopcount =0
|
||||
while stopcount <= 2:
|
||||
while stopcount <= 1:
|
||||
tdLog.info(" restart loop: %d"%stopcount )
|
||||
for i in range(dnodenumbers):
|
||||
tdDnodes[i].stoptaosd()
|
||||
|
|
|
@ -37,7 +37,7 @@ class ClusterComCheck:
|
|||
tdSql.init(conn.cursor())
|
||||
# tdSql.init(conn.cursor(), logSql) # output sql.txt file
|
||||
|
||||
def checkDnodes(self,dnodeNumbers, timeout=30):
|
||||
def checkDnodes(self,dnodeNumbers, timeout=100):
|
||||
count=0
|
||||
# print(tdSql)
|
||||
while count < timeout:
|
||||
|
|
|
@ -37,26 +37,26 @@ class TDTestCase:
|
|||
def case1(self):
|
||||
tdLog.debug("========case1 start========")
|
||||
|
||||
os.system("nohup taosBenchmark -y -B 1 -t 40 -S 1000 -n 10 -i 1000 -v 5 > /dev/null 2>&1 &")
|
||||
os.system(" taosBenchmark -y -B 1 -t 10 -S 1000 -n 10 -i 1000 -v 5 ")
|
||||
time.sleep(10)
|
||||
tdSql.execute("use test", queryTimes=100)
|
||||
tdSql.query("create stream if not exists s1 trigger at_once ignore expired 0 ignore update 0 fill_history 1 into st1 as select _wstart,sum(voltage),groupid from meters partition by groupid interval(2s)")
|
||||
tdLog.debug("========create stream and insert data ok========")
|
||||
time.sleep(20)
|
||||
|
||||
tdSql.query("select _wstart,sum(voltage),groupid from meters partition by groupid interval(2s) order by groupid,_wstart")
|
||||
rowCnt = tdSql.getRows()
|
||||
results = []
|
||||
for i in range(rowCnt):
|
||||
results.append(tdSql.getData(i,1))
|
||||
results_meters = tdSql.queryResult
|
||||
|
||||
tdSql.query("select * from st1 order by groupid,_wstart")
|
||||
tdSql.checkRows(rowCnt)
|
||||
sql = "select _wstart,`sum(voltage)`,groupid from st1 order by groupid,_wstart"
|
||||
tdSql.check_rows_loop(rowCnt, sql, loopCount=100, waitTime=0.5)
|
||||
|
||||
tdSql.query(sql)
|
||||
results_st1 = tdSql.queryResult
|
||||
for i in range(rowCnt):
|
||||
data1 = tdSql.getData(i,1)
|
||||
data2 = results[i]
|
||||
data1 = results_st1[i]
|
||||
data2 = results_meters[i]
|
||||
if data1 != data2:
|
||||
tdLog.info("num: %d, act data: %d, expect data: %d"%(i, data1, data2))
|
||||
tdLog.info(f"num: {i}, act data: {data1}, expect data: {data2}")
|
||||
tdLog.exit("check data error!")
|
||||
|
||||
tdLog.debug("case1 end")
|
||||
|
@ -64,7 +64,7 @@ class TDTestCase:
|
|||
def case2(self):
|
||||
tdLog.debug("========case2 start========")
|
||||
|
||||
os.system("taosBenchmark -d db -t 20 -v 6 -n 1000 -y > /dev/null 2>&1")
|
||||
os.system("taosBenchmark -d db -t 20 -v 6 -n 1000 -y")
|
||||
# create stream
|
||||
tdSql.execute("use db", queryTimes=100)
|
||||
tdSql.execute("create stream stream1 fill_history 1 into sta as select count(*) as cnt from meters interval(10a);",show=True)
|
||||
|
@ -73,7 +73,7 @@ class TDTestCase:
|
|||
sql = "select count(*) from sta"
|
||||
# loop wait max 60s to check count is ok
|
||||
tdLog.info("loop wait result ...")
|
||||
tdSql.checkDataLoop(0, 0, 100, sql, loopCount=10, waitTime=0.5)
|
||||
tdSql.checkDataLoop(0, 0, 100, sql, loopCount=100, waitTime=0.5)
|
||||
|
||||
# check all data is correct
|
||||
sql = "select * from sta where cnt != 200;"
|
||||
|
|
Loading…
Reference in New Issue