Merge branch 'main' into test_main/lihui
This commit is contained in:
commit
474efc4ce8
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
|
||||
set(CMAKE_VERBOSE_MAKEFILE OFF)
|
||||
set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
set(TD_BUILD_TAOSA_INTERNAL FALSE)
|
||||
|
||||
#set output directory
|
||||
|
|
|
@ -188,7 +188,7 @@ if (TD_LINUX)
|
|||
set(TD_DEPS_DIR "x86")
|
||||
ENDIF()
|
||||
endif()
|
||||
MESSAGE(STATUS "DEPS_DIR" ${TD_DEPS_DIR})
|
||||
MESSAGE(STATUS "DEPS_DIR: " ${TD_DEPS_DIR})
|
||||
|
||||
MESSAGE("C Compiler: ${CMAKE_C_COMPILER} (${CMAKE_C_COMPILER_ID}, ${CMAKE_C_COMPILER_VERSION})")
|
||||
MESSAGE("CXX Compiler: ${CMAKE_CXX_COMPILER} (${CMAKE_C_COMPILER_ID}, ${CMAKE_CXX_COMPILER_VERSION})")
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
IF (DEFINED VERNUMBER)
|
||||
SET(TD_VER_NUMBER ${VERNUMBER})
|
||||
ELSE ()
|
||||
SET(TD_VER_NUMBER "3.0.5.2.alpha")
|
||||
SET(TD_VER_NUMBER "3.0.6.0.alpha")
|
||||
ENDIF ()
|
||||
|
||||
IF (DEFINED VERCOMPATIBLE)
|
||||
|
|
|
@ -77,7 +77,6 @@ if(${BUILD_WITH_LEVELDB})
|
|||
cat("${TD_SUPPORT_DIR}/leveldb_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
endif(${BUILD_WITH_LEVELDB})
|
||||
|
||||
|
||||
if (${BUILD_CONTRIB})
|
||||
if(${BUILD_WITH_ROCKSDB})
|
||||
cat("${TD_SUPPORT_DIR}/rocksdb_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
|
@ -96,7 +95,6 @@ else()
|
|||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
# canonical-raft
|
||||
if(${BUILD_WITH_CRAFT})
|
||||
cat("${TD_SUPPORT_DIR}/craft_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
|
|
|
@ -244,6 +244,8 @@ The following SQL statement creates a topic in TDengine:
|
|||
CREATE TOPIC topic_name AS SELECT ts, c1, c2, c3 FROM tmqdb.stb WHERE c1 > 1;
|
||||
```
|
||||
|
||||
- There is an upper limit to the number of topics created, controlled by the parameter tmqMaxTopicNum, with a default of 20
|
||||
|
||||
Multiple subscription types are supported.
|
||||
|
||||
#### Subscribe to a Column
|
||||
|
@ -265,14 +267,15 @@ You can subscribe to a topic through a SELECT statement. Statements that specify
|
|||
Syntax:
|
||||
|
||||
```sql
|
||||
CREATE TOPIC topic_name AS STABLE stb_name
|
||||
CREATE TOPIC topic_name [with meta] AS STABLE stb_name [where_condition]
|
||||
```
|
||||
|
||||
Creating a topic in this manner differs from a `SELECT * from stbName` statement as follows:
|
||||
|
||||
- The table schema can be modified.
|
||||
- Unstructured data is returned. The format of the data returned changes based on the supertable schema.
|
||||
- A different table schema may exist for every data block to be processed.
|
||||
- The 'with meta' parameter is optional. When selected, statements such as creating super tables and sub tables will be returned, mainly used for Taosx to perform super table migration
|
||||
- The 'where_condition' parameter is optional and will be used to filter and subscribe to sub tables that meet the criteria. Where conditions cannot have ordinary columns, only tags or tbnames. Functions can be used in where conditions to filter tags, but cannot be aggregate functions because sub table tag values cannot be aggregated. It can also be a constant expression, such as 2>1 (subscribing to all child tables), Or false (subscribe to 0 sub tables)
|
||||
- The data returned does not include tags.
|
||||
|
||||
### Subscribe to a Database
|
||||
|
@ -280,10 +283,12 @@ Creating a topic in this manner differs from a `SELECT * from stbName` statement
|
|||
Syntax:
|
||||
|
||||
```sql
|
||||
CREATE TOPIC topic_name [WITH META] AS DATABASE db_name;
|
||||
CREATE TOPIC topic_name [with meta] AS DATABASE db_name;
|
||||
```
|
||||
|
||||
This SQL statement creates a subscription to all tables in the database. You can add the `WITH META` parameter to include schema changes in the subscription, including creating and deleting supertables; adding, deleting, and modifying columns; and creating, deleting, and modifying the tags of subtables. Consumers can determine the message type from the API. Note that this differs from Kafka.
|
||||
This SQL statement creates a subscription to all tables in the database.
|
||||
|
||||
- The 'with meta' parameter is optional. When selected, it will return statements for creating all super tables and sub tables in the database, mainly used for Taosx database migration
|
||||
|
||||
## Create a Consumer
|
||||
|
||||
|
@ -295,7 +300,7 @@ You configure the following parameters when creating a consumer:
|
|||
| `td.connect.user` | string | User Name | |
|
||||
| `td.connect.pass` | string | Password | |
|
||||
| `td.connect.port` | string | Port of the server side | |
|
||||
| `group.id` | string | Consumer group ID; consumers with the same ID are in the same group | **Required**. Maximum length: 192. |
|
||||
| `group.id` | string | Consumer group ID; consumers with the same ID are in the same group | **Required**. Maximum length: 192. Each topic can create up to 100 consumer groups. |
|
||||
| `client.id` | string | Client ID | Maximum length: 192. |
|
||||
| `auto.offset.reset` | enum | Initial offset for the consumer group | Specify `earliest`, `latest`, or `none`(default) |
|
||||
| `enable.auto.commit` | boolean | Commit automatically; true: user application doesn't need to explicitly commit; false: user application need to handle commit by itself | Default value is true |
|
||||
|
|
|
@ -55,7 +55,7 @@ window_clause: {
|
|||
| INTERVAL(interval_val [, interval_offset]) [SLIDING (sliding_val)] [WATERMARK(watermark_val)] [FILL(fill_mod_and_val)]
|
||||
|
||||
interp_clause:
|
||||
RANGE(ts_val, ts_val) EVERY(every_val) FILL(fill_mod_and_val)
|
||||
RANGE(ts_val [, ts_val]) EVERY(every_val) FILL(fill_mod_and_val)
|
||||
|
||||
partition_by_clause:
|
||||
PARTITION BY expr [, expr] ...
|
||||
|
|
|
@ -889,9 +889,10 @@ ignore_null_values: {
|
|||
- `INTERP` is used to get the value that matches the specified time slice from a column. If no such value exists an interpolation value will be returned based on `FILL` parameter.
|
||||
- The input data of `INTERP` is the value of the specified column and a `where` clause can be used to filter the original data. If no `where` condition is specified then all original data is the input.
|
||||
- `INTERP` must be used along with `RANGE`, `EVERY`, `FILL` keywords.
|
||||
- The output time range of `INTERP` is specified by `RANGE(timestamp1,timestamp2)` parameter, with timestamp1 <= timestamp2. timestamp1 is the starting point of the output time range and must be specified. timestamp2 is the ending point of the output time range and must be specified.
|
||||
- The output time range of `INTERP` is specified by `RANGE(timestamp1,timestamp2)` parameter, with timestamp1 <= timestamp2. timestamp1 is the starting point of the output time range. timestamp2 is the ending point of the output time range.
|
||||
- The number of rows in the result set of `INTERP` is determined by the parameter `EVERY(time_unit)`. Starting from timestamp1, one interpolation is performed for every time interval specified `time_unit` parameter. The parameter `time_unit` must be an integer, with no quotes, with a time unit of: a(millisecond)), s(second), m(minute), h(hour), d(day), or w(week). For example, `EVERY(500a)` will interpolate every 500 milliseconds.
|
||||
- Interpolation is performed based on `FILL` parameter. For more information about FILL clause, see [FILL Clause](../distinguished/#fill-clause).
|
||||
- When only one timestamp value is specified in `RANGE` clause, `INTERP` is used to generate interpolation at this point in time. In this case, `EVERY` clause can be omitted. For example, SELECT INTERP(col) FROM tb RANGE('2023-01-01 00:00:00') FILL(linear).
|
||||
- `INTERP` can be applied to supertable by interpolating primary key sorted data of all its childtables. It can also be used with `partition by tbname` when applied to supertable to generate interpolation on each single timeline.
|
||||
- Pseudocolumn `_irowts` can be used along with `INTERP` to return the timestamps associated with interpolation points(support after version 3.0.2.0).
|
||||
- Pseudocolumn `_isfilled` can be used along with `INTERP` to indicate whether the results are original records or data points generated by interpolation algorithm(support after version 3.0.3.0).
|
||||
|
@ -902,7 +903,7 @@ ignore_null_values: {
|
|||
- We want to downsample every 1 hour and use a linear fill for missing values. Note the order in which the "partition by" clause and the "range", "every" and "fill" parameters are used.
|
||||
|
||||
```sql
|
||||
SELECT _irowts,INTERP(current) FROM test.meters PARTITION BY TBNAME RANGE('2017-07-22 00:00:00','2017-07-24 12:25:00') EVERY(1h) FILL(LINEAR)
|
||||
SELECT _irowts,INTERP(current) FROM test.meters PARTITION BY TBNAME RANGE('2017-07-22 00:00:00','2017-07-24 12:25:00') EVERY(1h) FILL(LINEAR)
|
||||
```
|
||||
|
||||
### LAST
|
||||
|
|
|
@ -36,7 +36,7 @@ Shows information about connections to the system.
|
|||
SHOW CONSUMERS;
|
||||
```
|
||||
|
||||
Shows information about all active consumers in the system.
|
||||
Shows information about all consumers in the system.
|
||||
|
||||
## SHOW CREATE DATABASE
|
||||
|
||||
|
|
|
@ -243,6 +243,7 @@ TDengine 使用 SQL 创建一个 topic:
|
|||
```sql
|
||||
CREATE TOPIC topic_name AS SELECT ts, c1, c2, c3 FROM tmqdb.stb WHERE c1 > 1;
|
||||
```
|
||||
- topic创建个数有上限,通过参数 tmqMaxTopicNum 控制,默认 20 个
|
||||
|
||||
TMQ 支持多种订阅类型:
|
||||
|
||||
|
@ -265,14 +266,15 @@ CREATE TOPIC topic_name as subquery
|
|||
语法:
|
||||
|
||||
```sql
|
||||
CREATE TOPIC topic_name AS STABLE stb_name
|
||||
CREATE TOPIC topic_name [with meta] AS STABLE stb_name [where_condition]
|
||||
```
|
||||
|
||||
与 `SELECT * from stbName` 订阅的区别是:
|
||||
|
||||
- 不会限制用户的表结构变更。
|
||||
- 返回的是非结构化的数据:返回数据的结构会随之超级表的表结构变化而变化。
|
||||
- 用户对于要处理的每一个数据块都可能有不同的表结构。
|
||||
- with meta 参数可选,选择时将返回创建超级表,子表等语句,主要用于taosx做超级表迁移
|
||||
- where_condition 参数可选,选择时将用来过滤符合条件的子表,订阅这些子表。where 条件里不能有普通列,只能是tag或tbname,where条件里可以用函数,用来过滤tag,但是不能是聚合函数,因为子表tag值无法做聚合。也可以是常量表达式,比如 2 > 1(订阅全部子表),或者 false(订阅0个子表)
|
||||
- 返回数据不包含标签。
|
||||
|
||||
### 数据库订阅
|
||||
|
@ -280,11 +282,13 @@ CREATE TOPIC topic_name AS STABLE stb_name
|
|||
语法:
|
||||
|
||||
```sql
|
||||
CREATE TOPIC topic_name AS DATABASE db_name;
|
||||
CREATE TOPIC topic_name [with meta] AS DATABASE db_name;
|
||||
```
|
||||
|
||||
通过该语句可创建一个包含数据库所有表数据的订阅
|
||||
|
||||
- with meta 参数可选,选择时将返回创建数据库里所有超级表,子表的语句,主要用于taosx做数据库迁移
|
||||
|
||||
## 创建消费者 *consumer*
|
||||
|
||||
消费者需要通过一系列配置选项创建,基础配置项如下表所示:
|
||||
|
@ -295,7 +299,7 @@ CREATE TOPIC topic_name AS DATABASE db_name;
|
|||
| `td.connect.user` | string | 用户名 | |
|
||||
| `td.connect.pass` | string | 密码 | |
|
||||
| `td.connect.port` | integer | 服务端的端口号 | |
|
||||
| `group.id` | string | 消费组 ID,同一消费组共享消费进度 | **必填项**。最大长度:192。 |
|
||||
| `group.id` | string | 消费组 ID,同一消费组共享消费进度 | <br />**必填项**。最大长度:192。<br />每个topic最多可建立100个 consumer group |
|
||||
| `client.id` | string | 客户端 ID | 最大长度:192。 |
|
||||
| `auto.offset.reset` | enum | 消费组订阅的初始位置 | <br />`earliest`: default;从头开始订阅; <br/>`latest`: 仅从最新数据开始订阅; <br/>`none`: 没有提交的 offset 无法订阅 |
|
||||
| `enable.auto.commit` | boolean | 是否启用消费位点自动提交,true: 自动提交,客户端应用无需commit;false:客户端应用需要自行commit | 默认值为 true |
|
||||
|
|
|
@ -55,7 +55,7 @@ window_clause: {
|
|||
| INTERVAL(interval_val [, interval_offset]) [SLIDING (sliding_val)] [WATERMARK(watermark_val)] [FILL(fill_mod_and_val)]
|
||||
|
||||
interp_clause:
|
||||
RANGE(ts_val, ts_val) EVERY(every_val) FILL(fill_mod_and_val)
|
||||
RANGE(ts_val [, ts_val]) EVERY(every_val) FILL(fill_mod_and_val)
|
||||
|
||||
partition_by_clause:
|
||||
PARTITION BY expr [, expr] ...
|
||||
|
|
|
@ -890,9 +890,10 @@ ignore_null_values: {
|
|||
- INTERP 用于在指定时间断面获取指定列的记录值,如果该时间断面不存在符合条件的行数据,那么会根据 FILL 参数的设定进行插值。
|
||||
- INTERP 的输入数据为指定列的数据,可以通过条件语句(where 子句)来对原始列数据进行过滤,如果没有指定过滤条件则输入为全部数据。
|
||||
- INTERP 需要同时与 RANGE,EVERY 和 FILL 关键字一起使用。
|
||||
- INTERP 的输出时间范围根据 RANGE(timestamp1,timestamp2)字段来指定,需满足 timestamp1 <= timestamp2。其中 timestamp1(必选值)为输出时间范围的起始值,即如果 timestamp1 时刻符合插值条件则 timestamp1 为输出的第一条记录,timestamp2(必选值)为输出时间范围的结束值,即输出的最后一条记录的 timestamp 不能大于 timestamp2。
|
||||
- INTERP 的输出时间范围根据 RANGE(timestamp1, timestamp2)字段来指定,需满足 timestamp1 <= timestamp2。其中 timestamp1 为输出时间范围的起始值,即如果 timestamp1 时刻符合插值条件则 timestamp1 为输出的第一条记录,timestamp2 为输出时间范围的结束值,即输出的最后一条记录的 timestamp 不能大于 timestamp2。
|
||||
- INTERP 根据 EVERY(time_unit) 字段来确定输出时间范围内的结果条数,即从 timestamp1 开始每隔固定长度的时间(time_unit 值)进行插值,time_unit 可取值时间单位:1a(毫秒),1s(秒),1m(分),1h(小时),1d(天),1w(周)。例如 EVERY(500a) 将对于指定数据每500毫秒间隔进行一次插值.
|
||||
- INTERP 根据 FILL 字段来决定在每个符合输出条件的时刻如何进行插值。关于 FILL 子句如何使用请参考 [FILL 子句](../distinguished/#fill-子句)
|
||||
- INTERP 可以在 RANGE 字段中只指定唯一的时间戳对单个时间点进行插值,在这种情况下,EVERY 字段可以省略。例如:SELECT INTERP(col) FROM tb RANGE('2023-01-01 00:00:00') FILL(linear).
|
||||
- INTERP 作用于超级表时, 会将该超级表下的所有子表数据按照主键列排序后进行插值计算,也可以搭配 PARTITION BY tbname 使用,将结果强制规约到单个时间线。
|
||||
- INTERP 可以与伪列 _irowts 一起使用,返回插值点所对应的时间戳(3.0.2.0版本以后支持)。
|
||||
- INTERP 可以与伪列 _isfilled 一起使用,显示返回结果是否为原始记录或插值算法产生的数据(3.0.3.0版本以后支持)。
|
||||
|
|
|
@ -36,7 +36,7 @@ SHOW CONNECTIONS;
|
|||
SHOW CONSUMERS;
|
||||
```
|
||||
|
||||
显示当前数据库下所有活跃的消费者的信息。
|
||||
显示当前数据库下所有消费者的信息。
|
||||
|
||||
## SHOW CREATE DATABASE
|
||||
|
||||
|
|
|
@ -198,6 +198,7 @@ typedef struct SDataBlockInfo {
|
|||
SBlockID id;
|
||||
int16_t hasVarCol;
|
||||
int16_t dataLoad; // denote if the data is loaded or not
|
||||
uint8_t scanFlag;
|
||||
|
||||
// TODO: optimize and remove following
|
||||
int64_t version; // used for stream, and need serialization
|
||||
|
|
|
@ -187,6 +187,7 @@ int32_t colDataAssign(SColumnInfoData* pColumnInfoData, const SColumnInfoData* p
|
|||
int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock, int32_t tsColumnIndex);
|
||||
|
||||
int32_t colDataGetLength(const SColumnInfoData* pColumnInfoData, int32_t numOfRows);
|
||||
int32_t colDataGetRowLength(const SColumnInfoData* pColumnInfoData, int32_t rowIdx);
|
||||
void colDataTrim(SColumnInfoData* pColumnInfoData);
|
||||
|
||||
size_t blockDataGetNumOfCols(const SSDataBlock* pBlock);
|
||||
|
@ -248,6 +249,7 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq2** pReq, const SSDataBlock* pData
|
|||
tb_uid_t suid);
|
||||
|
||||
char* buildCtbNameByGroupId(const char* stbName, uint64_t groupId);
|
||||
int32_t buildCtbNameByGroupIdImpl(const char* stbName, uint64_t groupId, char* pBuf);
|
||||
|
||||
static FORCE_INLINE int32_t blockGetEncodeSize(const SSDataBlock* pBlock) {
|
||||
return blockDataGetSerialMetaSize(taosArrayGetSize(pBlock->pDataBlock)) + blockDataGetSize(pBlock);
|
||||
|
|
|
@ -83,6 +83,7 @@ extern int64_t tsVndCommitMaxIntervalMs;
|
|||
extern int64_t tsMndSdbWriteDelta;
|
||||
extern int64_t tsMndLogRetention;
|
||||
extern int8_t tsGrant;
|
||||
extern bool tsMndSkipGrant;
|
||||
|
||||
// monitor
|
||||
extern bool tsEnableMonitor;
|
||||
|
@ -119,6 +120,7 @@ extern bool tsQueryUseNodeAllocator;
|
|||
extern bool tsKeepColumnName;
|
||||
extern bool tsEnableQueryHb;
|
||||
extern bool tsEnableScience;
|
||||
extern bool tsTtlChangeOnWrite;
|
||||
extern int32_t tsRedirectPeriod;
|
||||
extern int32_t tsRedirectFactor;
|
||||
extern int32_t tsRedirectMaxPeriod;
|
||||
|
@ -184,6 +186,7 @@ extern int64_t tsStreamBufferSize;
|
|||
extern int64_t tsCheckpointInterval;
|
||||
extern bool tsFilterScalarMode;
|
||||
extern int32_t tsMaxStreamBackendCache;
|
||||
extern int32_t tsPQSortMemThreshold;
|
||||
|
||||
// #define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize)
|
||||
|
||||
|
|
|
@ -945,7 +945,7 @@ int32_t tSerializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
|
|||
int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int32_t timestamp;
|
||||
int32_t timestampSec;
|
||||
} SVDropTtlTableReq;
|
||||
|
||||
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
|
||||
|
@ -1975,6 +1975,7 @@ typedef struct {
|
|||
SArray* fillNullCols; // array of SColLocation
|
||||
int64_t deleteMark;
|
||||
int8_t igUpdate;
|
||||
int64_t lastTs;
|
||||
} SCMCreateStreamReq;
|
||||
|
||||
typedef struct {
|
||||
|
@ -2033,6 +2034,11 @@ typedef struct {
|
|||
char cgroup[TSDB_CGROUP_LEN];
|
||||
char clientId[256];
|
||||
SArray* topicNames; // SArray<char**>
|
||||
|
||||
int8_t withTbName;
|
||||
int8_t autoCommit;
|
||||
int32_t autoCommitInterval;
|
||||
int8_t resetOffsetCfg;
|
||||
} SCMSubscribeReq;
|
||||
|
||||
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
|
||||
|
@ -2047,6 +2053,12 @@ static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubsc
|
|||
for (int32_t i = 0; i < topicNum; i++) {
|
||||
tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
|
||||
}
|
||||
|
||||
tlen += taosEncodeFixedI8(buf, pReq->withTbName);
|
||||
tlen += taosEncodeFixedI8(buf, pReq->autoCommit);
|
||||
tlen += taosEncodeFixedI32(buf, pReq->autoCommitInterval);
|
||||
tlen += taosEncodeFixedI8(buf, pReq->resetOffsetCfg);
|
||||
|
||||
return tlen;
|
||||
}
|
||||
|
||||
|
@ -2064,6 +2076,11 @@ static FORCE_INLINE void* tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq
|
|||
buf = taosDecodeString(buf, &name);
|
||||
taosArrayPush(pReq->topicNames, &name);
|
||||
}
|
||||
|
||||
buf = taosDecodeFixedI8(buf, &pReq->withTbName);
|
||||
buf = taosDecodeFixedI8(buf, &pReq->autoCommit);
|
||||
buf = taosDecodeFixedI32(buf, &pReq->autoCommitInterval);
|
||||
buf = taosDecodeFixedI8(buf, &pReq->resetOffsetCfg);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
@ -2261,7 +2278,7 @@ typedef struct SVCreateTbReq {
|
|||
int32_t flags;
|
||||
char* name;
|
||||
tb_uid_t uid;
|
||||
int64_t ctime;
|
||||
int64_t btime;
|
||||
int32_t ttl;
|
||||
int32_t commentLen;
|
||||
char* comment;
|
||||
|
@ -2398,10 +2415,12 @@ typedef struct {
|
|||
int32_t newTTL;
|
||||
int32_t newCommentLen;
|
||||
char* newComment;
|
||||
int64_t ctimeMs; // fill by vnode
|
||||
} SVAlterTbReq;
|
||||
|
||||
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
|
||||
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
|
||||
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
|
||||
|
||||
typedef struct {
|
||||
int32_t code;
|
||||
|
@ -2455,15 +2474,6 @@ typedef struct {
|
|||
char cgroup[TSDB_CGROUP_LEN];
|
||||
} SMqAskEpReq;
|
||||
|
||||
typedef struct {
|
||||
int64_t consumerId;
|
||||
int32_t epoch;
|
||||
} SMqHbReq;
|
||||
|
||||
typedef struct {
|
||||
int8_t reserved;
|
||||
} SMqHbRsp;
|
||||
|
||||
typedef struct {
|
||||
int32_t key;
|
||||
int32_t valueLen;
|
||||
|
@ -2487,6 +2497,7 @@ typedef struct {
|
|||
int64_t stime; // timestamp precision ms
|
||||
int64_t reqRid;
|
||||
bool stableQuery;
|
||||
bool isSubQuery;
|
||||
char fqdn[TSDB_FQDN_LEN];
|
||||
int32_t subPlanNum;
|
||||
SArray* subDesc; // SArray<SQuerySubDesc>
|
||||
|
@ -2891,7 +2902,7 @@ int32_t tDecodeSMqCMCommitOffsetReq(SDecoder* decoder, SMqCMCommitOffsetReq* pRe
|
|||
// tqOffset
|
||||
enum {
|
||||
TMQ_OFFSET__RESET_NONE = -3,
|
||||
TMQ_OFFSET__RESET_EARLIEAST = -2,
|
||||
TMQ_OFFSET__RESET_EARLIEST = -2,
|
||||
TMQ_OFFSET__RESET_LATEST = -1,
|
||||
TMQ_OFFSET__LOG = 1,
|
||||
TMQ_OFFSET__SNAPSHOT_DATA = 2,
|
||||
|
@ -3365,6 +3376,16 @@ typedef struct{
|
|||
SArray* offsetRows;
|
||||
}TopicOffsetRows;
|
||||
|
||||
typedef struct {
|
||||
int64_t consumerId;
|
||||
int32_t epoch;
|
||||
SArray* topics;
|
||||
} SMqHbReq;
|
||||
|
||||
typedef struct {
|
||||
int8_t reserved;
|
||||
} SMqHbRsp;
|
||||
|
||||
#define TD_AUTO_CREATE_TABLE 0x1
|
||||
typedef struct {
|
||||
int64_t suid;
|
||||
|
@ -3416,6 +3437,7 @@ typedef struct SDeleteRes {
|
|||
int64_t affectedRows;
|
||||
char tableFName[TSDB_TABLE_NAME_LEN];
|
||||
char tsColName[TSDB_COL_NAME_LEN];
|
||||
int64_t ctimeMs; // fill by vnode
|
||||
} SDeleteRes;
|
||||
|
||||
int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes);
|
||||
|
@ -3434,10 +3456,12 @@ int32_t tDecodeSSingleDeleteReq(SDecoder* pCoder, SSingleDeleteReq* pReq);
|
|||
typedef struct {
|
||||
int64_t suid;
|
||||
SArray* deleteReqs; // SArray<SSingleDeleteReq>
|
||||
int64_t ctimeMs; // fill by vnode
|
||||
} SBatchDeleteReq;
|
||||
|
||||
int32_t tEncodeSBatchDeleteReq(SEncoder* pCoder, const SBatchDeleteReq* pReq);
|
||||
int32_t tDecodeSBatchDeleteReq(SDecoder* pCoder, SBatchDeleteReq* pReq);
|
||||
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder* pDecoder, SBatchDeleteReq* pReq, int64_t ctimeMs);
|
||||
|
||||
typedef struct {
|
||||
int32_t msgIdx;
|
||||
|
@ -3489,10 +3513,8 @@ int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
|
|||
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
|
||||
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
|
||||
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
|
||||
int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
|
||||
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
|
||||
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
|
||||
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
|
||||
int32_t tDeatroySMqHbReq(SMqHbReq* pReq);
|
||||
|
||||
|
||||
#define SUBMIT_REQ_AUTO_CREATE_TABLE 0x1
|
||||
#define SUBMIT_REQ_COLUMN_DATA_FORMAT 0x2
|
||||
|
@ -3507,6 +3529,7 @@ typedef struct {
|
|||
SArray* aRowP;
|
||||
SArray* aCol;
|
||||
};
|
||||
int64_t ctimeMs;
|
||||
} SSubmitTbData;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -150,7 +150,7 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_MND_TMQ_HB, "consumer-hb", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_TMQ_DO_REBALANCE, "do-rebalance", SMqDoRebalanceMsg, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_TMQ_DROP_CGROUP, "drop-cgroup", SMqDropCGroupReq, SMqDropCGroupRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_UNUSED2, "unused2", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_VG, "create-vg", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_TMQ_TIMER, "tmq-tmr", SMTimerReq, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_TELEM_TIMER, "telem-tmr", SMTimerReq, SMTimerReq)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_TRANS_TIMER, "trans-tmr", NULL, NULL)
|
||||
|
|
|
@ -87,6 +87,7 @@ typedef struct SCatalogReq {
|
|||
bool dNodeRequired; // valid dnode
|
||||
bool svrVerRequired;
|
||||
bool forceUpdate;
|
||||
bool cloned;
|
||||
} SCatalogReq;
|
||||
|
||||
typedef struct SMetaRes {
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
#ifndef TDENGINE_STORAGEAPI_H
|
||||
#define TDENGINE_STORAGEAPI_H
|
||||
|
||||
#include "tsimplehash.h"
|
||||
#include "tscalablebf.h"
|
||||
#include "taosdef.h"
|
||||
#include "tmsg.h"
|
||||
#include "tcommon.h"
|
||||
#include "index.h"
|
||||
#include "function.h"
|
||||
#include "index.h"
|
||||
#include "taosdef.h"
|
||||
#include "tcommon.h"
|
||||
#include "tmsg.h"
|
||||
#include "tscalablebf.h"
|
||||
#include "tsimplehash.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -46,7 +46,7 @@ typedef struct SMetaEntry {
|
|||
int8_t type;
|
||||
int8_t flags; // TODO: need refactor?
|
||||
tb_uid_t uid;
|
||||
char * name;
|
||||
char* name;
|
||||
union {
|
||||
struct {
|
||||
SSchemaWrapper schemaRow;
|
||||
|
@ -54,46 +54,48 @@ typedef struct SMetaEntry {
|
|||
SRSmaParam rsmaParam;
|
||||
} stbEntry;
|
||||
struct {
|
||||
int64_t ctime;
|
||||
int64_t btime;
|
||||
int32_t ttlDays;
|
||||
int32_t commentLen;
|
||||
char * comment;
|
||||
char* comment;
|
||||
tb_uid_t suid;
|
||||
uint8_t *pTags;
|
||||
uint8_t* pTags;
|
||||
} ctbEntry;
|
||||
struct {
|
||||
int64_t ctime;
|
||||
int64_t btime;
|
||||
int32_t ttlDays;
|
||||
int32_t commentLen;
|
||||
char * comment;
|
||||
char* comment;
|
||||
int32_t ncid; // next column id
|
||||
SSchemaWrapper schemaRow;
|
||||
} ntbEntry;
|
||||
struct {
|
||||
STSma *tsma;
|
||||
STSma* tsma;
|
||||
} smaEntry;
|
||||
};
|
||||
|
||||
uint8_t *pBuf;
|
||||
uint8_t* pBuf;
|
||||
} SMetaEntry;
|
||||
|
||||
typedef struct SMetaReader {
|
||||
int32_t flags;
|
||||
void * pMeta;
|
||||
SDecoder coder;
|
||||
SMetaEntry me;
|
||||
void * pBuf;
|
||||
int32_t szBuf;
|
||||
struct SStoreMeta* pAPI;
|
||||
int32_t flags;
|
||||
void* pMeta;
|
||||
SDecoder coder;
|
||||
SMetaEntry me;
|
||||
void* pBuf;
|
||||
int32_t szBuf;
|
||||
struct SStoreMeta* pAPI;
|
||||
} SMetaReader;
|
||||
|
||||
typedef struct SMTbCursor {
|
||||
void * pDbc;
|
||||
void * pKey;
|
||||
void * pVal;
|
||||
void* pMeta;
|
||||
void* pDbc;
|
||||
void* pKey;
|
||||
void* pVal;
|
||||
int32_t kLen;
|
||||
int32_t vLen;
|
||||
SMetaReader mr;
|
||||
int8_t paused;
|
||||
} SMTbCursor;
|
||||
|
||||
typedef struct SRowBuffPos {
|
||||
|
@ -107,22 +109,22 @@ typedef struct SRowBuffPos {
|
|||
typedef struct SMetaTableInfo {
|
||||
int64_t suid;
|
||||
int64_t uid;
|
||||
SSchemaWrapper *schema;
|
||||
SSchemaWrapper* schema;
|
||||
char tbName[TSDB_TABLE_NAME_LEN];
|
||||
} SMetaTableInfo;
|
||||
|
||||
typedef struct SSnapContext {
|
||||
SMeta * pMeta; // todo remove it
|
||||
int64_t snapVersion;
|
||||
void * pCur;
|
||||
int64_t suid;
|
||||
int8_t subType;
|
||||
SHashObj * idVersion;
|
||||
SHashObj * suidInfo;
|
||||
SArray * idList;
|
||||
int32_t index;
|
||||
bool withMeta;
|
||||
bool queryMeta; // true-get meta, false-get data
|
||||
SMeta* pMeta; // todo remove it
|
||||
int64_t snapVersion;
|
||||
void* pCur;
|
||||
int64_t suid;
|
||||
int8_t subType;
|
||||
SHashObj* idVersion;
|
||||
SHashObj* suidInfo;
|
||||
SArray* idList;
|
||||
int32_t index;
|
||||
bool withMeta;
|
||||
bool queryMeta; // true-get meta, false-get data
|
||||
} SSnapContext;
|
||||
|
||||
typedef struct {
|
||||
|
@ -139,10 +141,9 @@ typedef struct {
|
|||
// int32_t tqReaderSeek(STqReader *pReader, int64_t ver, const char *id);
|
||||
// bool tqNextBlockInWal(STqReader* pReader, const char* idstr);
|
||||
// bool tqNextBlockImpl(STqReader *pReader, const char* idstr);
|
||||
// int32_t getTableInfoFromSnapshot(SSnapContext *ctx, void **pBuf, int32_t *contLen, int16_t *type, int64_t *uid);
|
||||
// SMetaTableInfo getMetaTableInfoFromSnapshot(SSnapContext *ctx);
|
||||
// int32_t setForSnapShot(SSnapContext *ctx, int64_t uid);
|
||||
// int32_t destroySnapContext(SSnapContext *ctx);
|
||||
// int32_t getTableInfoFromSnapshot(SSnapContext *ctx, void **pBuf, int32_t *contLen, int16_t *type, int64_t
|
||||
// *uid); SMetaTableInfo getMetaTableInfoFromSnapshot(SSnapContext *ctx); int32_t setForSnapShot(SSnapContext
|
||||
// *ctx, int64_t uid); int32_t destroySnapContext(SSnapContext *ctx);
|
||||
|
||||
// clang-format off
|
||||
/*-------------------------------------------------new api format---------------------------------------------------*/
|
||||
|
@ -219,16 +220,16 @@ typedef struct SStoreTqReader {
|
|||
bool (*tqReaderIsQueriedTable)();
|
||||
bool (*tqReaderCurrentBlockConsumed)();
|
||||
|
||||
struct SWalReader *(*tqReaderGetWalReader)(); // todo remove it
|
||||
int32_t (*tqReaderRetrieveTaosXBlock)(); // todo remove it
|
||||
struct SWalReader* (*tqReaderGetWalReader)(); // todo remove it
|
||||
int32_t (*tqReaderRetrieveTaosXBlock)(); // todo remove it
|
||||
|
||||
int32_t (*tqReaderSetSubmitMsg)(); // todo remove it
|
||||
bool (*tqReaderNextBlockFilterOut)();
|
||||
} SStoreTqReader;
|
||||
|
||||
typedef struct SStoreSnapshotFn {
|
||||
int32_t (*createSnapshot)(SSnapContext *ctx, int64_t uid);
|
||||
int32_t (*destroySnapshot)(SSnapContext *ctx);
|
||||
int32_t (*createSnapshot)(SSnapContext* ctx, int64_t uid);
|
||||
int32_t (*destroySnapshot)(SSnapContext* ctx);
|
||||
SMetaTableInfo (*getMetaTableInfoFromSnapshot)(SSnapContext* ctx);
|
||||
int32_t (*getTableInfoFromSnapshot)(SSnapContext* ctx, void** pBuf, int32_t* contLen, int16_t* type, int64_t* uid);
|
||||
} SStoreSnapshotFn;
|
||||
|
@ -252,42 +253,54 @@ int32_t metaUidFilterCachePut(SMeta *pMeta, uint64_t suid, const void *pKey, in
|
|||
int32_t payloadLen, double selectivityRatio);
|
||||
tb_uid_t metaGetTableEntryUidByName(SMeta *pMeta, const char *name);
|
||||
int32_t metaGetCachedTbGroup(SMeta* pMeta, tb_uid_t suid, const uint8_t* pKey, int32_t keyLen, SArray** pList);
|
||||
int32_t metaPutTbGroupToCache(SMeta* pMeta, uint64_t suid, const void* pKey, int32_t keyLen, void* pPayload, int32_t payloadLen);
|
||||
int32_t metaPutTbGroupToCache(SMeta* pMeta, uint64_t suid, const void* pKey, int32_t keyLen, void* pPayload, int32_t
|
||||
payloadLen);
|
||||
*/
|
||||
|
||||
typedef struct SStoreMeta {
|
||||
SMTbCursor *(*openTableMetaCursor)(void *pVnode); // metaOpenTbCursor
|
||||
void (*closeTableMetaCursor)(SMTbCursor *pTbCur); // metaCloseTbCursor
|
||||
int32_t (*cursorNext)(SMTbCursor *pTbCur, ETableType jumpTableType); // metaTbCursorNext
|
||||
int32_t (*cursorPrev)(SMTbCursor *pTbCur, ETableType jumpTableType); // metaTbCursorPrev
|
||||
SMTbCursor* (*openTableMetaCursor)(void* pVnode); // metaOpenTbCursor
|
||||
void (*closeTableMetaCursor)(SMTbCursor* pTbCur); // metaCloseTbCursor
|
||||
void (*pauseTableMetaCursor)(SMTbCursor* pTbCur); // metaPauseTbCursor
|
||||
void (*resumeTableMetaCursor)(SMTbCursor* pTbCur, int8_t first); // metaResumeTbCursor
|
||||
int32_t (*cursorNext)(SMTbCursor* pTbCur, ETableType jumpTableType); // metaTbCursorNext
|
||||
int32_t (*cursorPrev)(SMTbCursor* pTbCur, ETableType jumpTableType); // metaTbCursorPrev
|
||||
|
||||
int32_t (*getTableTags)(void *pVnode, uint64_t suid, SArray *uidList);
|
||||
int32_t (*getTableTagsByUid)(void *pVnode, int64_t suid, SArray *uidList);
|
||||
const void *(*extractTagVal)(const void *tag, int16_t type, STagVal *tagVal); // todo remove it
|
||||
int32_t (*getTableTags)(void* pVnode, uint64_t suid, SArray* uidList);
|
||||
int32_t (*getTableTagsByUid)(void* pVnode, int64_t suid, SArray* uidList);
|
||||
const void* (*extractTagVal)(const void* tag, int16_t type, STagVal* tagVal); // todo remove it
|
||||
|
||||
int32_t (*getTableUidByName)(void *pVnode, char *tbName, uint64_t *uid);
|
||||
int32_t (*getTableTypeByName)(void *pVnode, char *tbName, ETableType *tbType);
|
||||
int32_t (*getTableNameByUid)(void *pVnode, uint64_t uid, char *tbName);
|
||||
bool (*isTableExisted)(void *pVnode, tb_uid_t uid);
|
||||
int32_t (*getTableUidByName)(void* pVnode, char* tbName, uint64_t* uid);
|
||||
int32_t (*getTableTypeByName)(void* pVnode, char* tbName, ETableType* tbType);
|
||||
int32_t (*getTableNameByUid)(void* pVnode, uint64_t uid, char* tbName);
|
||||
bool (*isTableExisted)(void* pVnode, tb_uid_t uid);
|
||||
|
||||
int32_t (*metaGetCachedTbGroup)(void* pVnode, tb_uid_t suid, const uint8_t* pKey, int32_t keyLen, SArray** pList);
|
||||
int32_t (*metaPutTbGroupToCache)(void* pVnode, uint64_t suid, const void* pKey, int32_t keyLen, void* pPayload, int32_t payloadLen);
|
||||
int32_t (*metaGetCachedTbGroup)(void* pVnode, tb_uid_t suid, const uint8_t* pKey, int32_t keyLen, SArray** pList);
|
||||
int32_t (*metaPutTbGroupToCache)(void* pVnode, uint64_t suid, const void* pKey, int32_t keyLen, void* pPayload,
|
||||
int32_t payloadLen);
|
||||
|
||||
int32_t (*getCachedTableList)(void* pVnode, tb_uid_t suid, const uint8_t* pKey, int32_t keyLen, SArray* pList1, bool* acquireRes);
|
||||
int32_t (*putCachedTableList)(void* pVnode, uint64_t suid, const void* pKey, int32_t keyLen, void* pPayload, int32_t payloadLen, double selectivityRatio);
|
||||
int32_t (*getCachedTableList)(void* pVnode, tb_uid_t suid, const uint8_t* pKey, int32_t keyLen, SArray* pList1,
|
||||
bool* acquireRes);
|
||||
int32_t (*putCachedTableList)(void* pVnode, uint64_t suid, const void* pKey, int32_t keyLen, void* pPayload,
|
||||
int32_t payloadLen, double selectivityRatio);
|
||||
|
||||
void *(*storeGetIndexInfo)();
|
||||
void *(*getInvertIndex)(void* pVnode);
|
||||
int32_t (*getChildTableList)(void *pVnode, int64_t suid, SArray *list); // support filter and non-filter cases. [vnodeGetCtbIdList & vnodeGetCtbIdListByFilter]
|
||||
int32_t (*storeGetTableList)(void* pVnode, int8_t type, SArray* pList); // vnodeGetStbIdList & vnodeGetAllTableList
|
||||
void *storeGetVersionRange;
|
||||
void *storeGetLastTimestamp;
|
||||
void* (*storeGetIndexInfo)();
|
||||
void* (*getInvertIndex)(void* pVnode);
|
||||
int32_t (*getChildTableList)(
|
||||
void* pVnode, int64_t suid,
|
||||
SArray* list); // support filter and non-filter cases. [vnodeGetCtbIdList & vnodeGetCtbIdListByFilter]
|
||||
int32_t (*storeGetTableList)(void* pVnode, int8_t type, SArray* pList); // vnodeGetStbIdList & vnodeGetAllTableList
|
||||
void* storeGetVersionRange;
|
||||
void* storeGetLastTimestamp;
|
||||
|
||||
int32_t (*getTableSchema)(void *pVnode, int64_t uid, STSchema **pSchema, int64_t *suid); // tsdbGetTableSchema
|
||||
int32_t (*getTableSchema)(void* pVnode, int64_t uid, STSchema** pSchema, int64_t* suid); // tsdbGetTableSchema
|
||||
|
||||
// db name, vgId, numOfTables, numOfSTables
|
||||
int32_t (*getNumOfChildTables)(void* pVnode, int64_t uid, int64_t* numOfTables); // int32_t metaGetStbStats(SMeta *pMeta, int64_t uid, SMetaStbStats *pInfo);
|
||||
void (*getBasicInfo)(void *pVnode, const char **dbname, int32_t *vgId, int64_t* numOfTables, int64_t* numOfNormalTables);// vnodeGetInfo(void *pVnode, const char **dbname, int32_t *vgId) & metaGetTbNum(SMeta *pMeta) & metaGetNtbNum(SMeta *pMeta);
|
||||
int32_t (*getNumOfChildTables)(
|
||||
void* pVnode, int64_t uid,
|
||||
int64_t* numOfTables); // int32_t metaGetStbStats(SMeta *pMeta, int64_t uid, SMetaStbStats *pInfo);
|
||||
void (*getBasicInfo)(void* pVnode, const char** dbname, int32_t* vgId, int64_t* numOfTables,
|
||||
int64_t* numOfNormalTables); // vnodeGetInfo(void *pVnode, const char **dbname, int32_t *vgId) &
|
||||
// metaGetTbNum(SMeta *pMeta) & metaGetNtbNum(SMeta *pMeta);
|
||||
|
||||
int64_t (*getNumOfRowsInMem)(void* pVnode);
|
||||
/**
|
||||
|
@ -298,24 +311,24 @@ int32_t vnodeGetStbIdList(void *pVnode, int64_t suid, SArray *list);
|
|||
} SStoreMeta;
|
||||
|
||||
typedef struct SStoreMetaReader {
|
||||
void (*initReader)(SMetaReader *pReader, void *pVnode, int32_t flags, SStoreMeta* pAPI);
|
||||
void (*clearReader)(SMetaReader *pReader);
|
||||
void (*readerReleaseLock)(SMetaReader *pReader);
|
||||
int32_t (*getTableEntryByUid)(SMetaReader *pReader, tb_uid_t uid);
|
||||
int32_t (*getTableEntryByName)(SMetaReader *pReader, const char *name);
|
||||
int32_t (*getEntryGetUidCache)(SMetaReader *pReader, tb_uid_t uid);
|
||||
void (*initReader)(SMetaReader* pReader, void* pVnode, int32_t flags, SStoreMeta* pAPI);
|
||||
void (*clearReader)(SMetaReader* pReader);
|
||||
void (*readerReleaseLock)(SMetaReader* pReader);
|
||||
int32_t (*getTableEntryByUid)(SMetaReader* pReader, tb_uid_t uid);
|
||||
int32_t (*getTableEntryByName)(SMetaReader* pReader, const char* name);
|
||||
int32_t (*getEntryGetUidCache)(SMetaReader* pReader, tb_uid_t uid);
|
||||
} SStoreMetaReader;
|
||||
|
||||
typedef struct SUpdateInfo {
|
||||
SArray *pTsBuckets;
|
||||
SArray* pTsBuckets;
|
||||
uint64_t numBuckets;
|
||||
SArray *pTsSBFs;
|
||||
SArray* pTsSBFs;
|
||||
uint64_t numSBFs;
|
||||
int64_t interval;
|
||||
int64_t watermark;
|
||||
TSKEY minTS;
|
||||
SScalableBf *pCloseWinSBF;
|
||||
SHashObj *pMap;
|
||||
SScalableBf* pCloseWinSBF;
|
||||
SHashObj* pMap;
|
||||
uint64_t maxDataVersion;
|
||||
} SUpdateInfo;
|
||||
|
||||
|
@ -334,15 +347,15 @@ typedef struct SStateStore {
|
|||
|
||||
int32_t (*streamStateAddIfNotExist)(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen);
|
||||
int32_t (*streamStateReleaseBuf)(SStreamState* pState, const SWinKey* key, void* pVal);
|
||||
void (*streamStateFreeVal)(void* val);
|
||||
void (*streamStateFreeVal)(void* val);
|
||||
|
||||
int32_t (*streamStatePut)(SStreamState* pState, const SWinKey* key, const void* value, int32_t vLen);
|
||||
int32_t (*streamStateGet)(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen);
|
||||
bool (*streamStateCheck)(SStreamState* pState, const SWinKey* key);
|
||||
bool (*streamStateCheck)(SStreamState* pState, const SWinKey* key);
|
||||
int32_t (*streamStateGetByPos)(SStreamState* pState, void* pos, void** pVal);
|
||||
int32_t (*streamStateDel)(SStreamState* pState, const SWinKey* key);
|
||||
int32_t (*streamStateClear)(SStreamState* pState);
|
||||
void (*streamStateSetNumber)(SStreamState* pState, int32_t number);
|
||||
void (*streamStateSetNumber)(SStreamState* pState, int32_t number);
|
||||
int32_t (*streamStateSaveInfo)(SStreamState* pState, void* pKey, int32_t keyLen, void* pVal, int32_t vLen);
|
||||
int32_t (*streamStateGetInfo)(SStreamState* pState, void* pKey, int32_t keyLen, void** pVal, int32_t* pLen);
|
||||
|
||||
|
@ -353,36 +366,37 @@ typedef struct SStateStore {
|
|||
int32_t (*streamStateCurNext)(SStreamState* pState, SStreamStateCur* pCur);
|
||||
int32_t (*streamStateCurPrev)(SStreamState* pState, SStreamStateCur* pCur);
|
||||
|
||||
SStreamStateCur* (*streamStateGetAndCheckCur)(SStreamState* pState, SWinKey* key);
|
||||
SStreamStateCur* (*streamStateSeekKeyNext)(SStreamState* pState, const SWinKey* key);
|
||||
SStreamStateCur* (*streamStateFillSeekKeyNext)(SStreamState* pState, const SWinKey* key);
|
||||
SStreamStateCur* (*streamStateFillSeekKeyPrev)(SStreamState* pState, const SWinKey* key);
|
||||
void (*streamStateFreeCur)(SStreamStateCur* pCur);
|
||||
SStreamStateCur* (*streamStateGetAndCheckCur)(SStreamState* pState, SWinKey* key);
|
||||
SStreamStateCur* (*streamStateSeekKeyNext)(SStreamState* pState, const SWinKey* key);
|
||||
SStreamStateCur* (*streamStateFillSeekKeyNext)(SStreamState* pState, const SWinKey* key);
|
||||
SStreamStateCur* (*streamStateFillSeekKeyPrev)(SStreamState* pState, const SWinKey* key);
|
||||
void (*streamStateFreeCur)(SStreamStateCur* pCur);
|
||||
|
||||
int32_t (*streamStateGetGroupKVByCur)(SStreamStateCur* pCur, SWinKey* pKey, const void** pVal, int32_t* pVLen);
|
||||
int32_t (*streamStateGetKVByCur)(SStreamStateCur* pCur, SWinKey* pKey, const void** pVal, int32_t* pVLen);
|
||||
|
||||
int32_t (*streamStateSessionAddIfNotExist)(SStreamState* pState, SSessionKey* key, TSKEY gap, void** pVal, int32_t* pVLen);
|
||||
int32_t (*streamStateSessionAddIfNotExist)(SStreamState* pState, SSessionKey* key, TSKEY gap, void** pVal,
|
||||
int32_t* pVLen);
|
||||
int32_t (*streamStateSessionPut)(SStreamState* pState, const SSessionKey* key, const void* value, int32_t vLen);
|
||||
int32_t (*streamStateSessionGet)(SStreamState* pState, SSessionKey* key, void** pVal, int32_t* pVLen);
|
||||
int32_t (*streamStateSessionDel)(SStreamState* pState, const SSessionKey* key);
|
||||
int32_t (*streamStateSessionClear)(SStreamState* pState);
|
||||
int32_t (*streamStateSessionGetKVByCur)(SStreamStateCur* pCur, SSessionKey* pKey, void** pVal, int32_t* pVLen);
|
||||
int32_t (*streamStateStateAddIfNotExist)(SStreamState* pState, SSessionKey* key, char* pKeyData, int32_t keyDataLen,
|
||||
state_key_cmpr_fn fn, void** pVal, int32_t* pVLen);
|
||||
state_key_cmpr_fn fn, void** pVal, int32_t* pVLen);
|
||||
int32_t (*streamStateSessionGetKeyByRange)(SStreamState* pState, const SSessionKey* range, SSessionKey* curKey);
|
||||
|
||||
SUpdateInfo* (*updateInfoInit)(int64_t interval, int32_t precision, int64_t watermark);
|
||||
TSKEY (*updateInfoFillBlockData)(SUpdateInfo *pInfo, SSDataBlock *pBlock, int32_t primaryTsCol);
|
||||
bool (*updateInfoIsUpdated)(SUpdateInfo *pInfo, uint64_t tableId, TSKEY ts);
|
||||
bool (*updateInfoIsTableInserted)(SUpdateInfo *pInfo, int64_t tbUid);
|
||||
void (*updateInfoDestroy)(SUpdateInfo *pInfo);
|
||||
SUpdateInfo* (*updateInfoInit)(int64_t interval, int32_t precision, int64_t watermark);
|
||||
TSKEY (*updateInfoFillBlockData)(SUpdateInfo* pInfo, SSDataBlock* pBlock, int32_t primaryTsCol);
|
||||
bool (*updateInfoIsUpdated)(SUpdateInfo* pInfo, uint64_t tableId, TSKEY ts);
|
||||
bool (*updateInfoIsTableInserted)(SUpdateInfo* pInfo, int64_t tbUid);
|
||||
void (*updateInfoDestroy)(SUpdateInfo* pInfo);
|
||||
|
||||
SUpdateInfo* (*updateInfoInitP)(SInterval *pInterval, int64_t watermark);
|
||||
void (*updateInfoAddCloseWindowSBF)(SUpdateInfo *pInfo);
|
||||
void (*updateInfoDestoryColseWinSBF)(SUpdateInfo *pInfo);
|
||||
int32_t (*updateInfoSerialize)(void *buf, int32_t bufLen, const SUpdateInfo *pInfo);
|
||||
int32_t (*updateInfoDeserialize)(void *buf, int32_t bufLen, SUpdateInfo *pInfo);
|
||||
SUpdateInfo* (*updateInfoInitP)(SInterval* pInterval, int64_t watermark);
|
||||
void (*updateInfoAddCloseWindowSBF)(SUpdateInfo* pInfo);
|
||||
void (*updateInfoDestoryColseWinSBF)(SUpdateInfo* pInfo);
|
||||
int32_t (*updateInfoSerialize)(void* buf, int32_t bufLen, const SUpdateInfo* pInfo);
|
||||
int32_t (*updateInfoDeserialize)(void* buf, int32_t bufLen, SUpdateInfo* pInfo);
|
||||
|
||||
SStreamStateCur* (*streamStateSessionSeekKeyNext)(SStreamState* pState, const SSessionKey* key);
|
||||
SStreamStateCur* (*streamStateSessionSeekKeyCurrentPrev)(SStreamState* pState, const SSessionKey* key);
|
||||
|
@ -396,11 +410,11 @@ typedef struct SStateStore {
|
|||
bool (*needClearDiskBuff)(struct SStreamFileState* pFileState);
|
||||
|
||||
SStreamState* (*streamStateOpen)(char* path, void* pTask, bool specPath, int32_t szPage, int32_t pages);
|
||||
void (*streamStateClose)(SStreamState* pState, bool remove);
|
||||
int32_t (*streamStateBegin)(SStreamState* pState);
|
||||
int32_t (*streamStateCommit)(SStreamState* pState);
|
||||
void (*streamStateDestroy)(SStreamState* pState, bool remove);
|
||||
int32_t (*streamStateDeleteCheckPoint)(SStreamState* pState, TSKEY mark);
|
||||
void (*streamStateClose)(SStreamState* pState, bool remove);
|
||||
int32_t (*streamStateBegin)(SStreamState* pState);
|
||||
int32_t (*streamStateCommit)(SStreamState* pState);
|
||||
void (*streamStateDestroy)(SStreamState* pState, bool remove);
|
||||
int32_t (*streamStateDeleteCheckPoint)(SStreamState* pState, TSKEY mark);
|
||||
} SStateStore;
|
||||
|
||||
typedef struct SStorageAPI {
|
||||
|
|
|
@ -233,6 +233,7 @@ bool fmIsGroupKeyFunc(int32_t funcId);
|
|||
bool fmIsBlockDistFunc(int32_t funcId);
|
||||
|
||||
void getLastCacheDataType(SDataType* pType);
|
||||
SFunctionNode* createFunction(const char* pName, SNodeList* pParameterList);
|
||||
|
||||
int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMergeFunc);
|
||||
|
||||
|
|
|
@ -425,16 +425,18 @@ typedef struct SStreamOptions {
|
|||
} SStreamOptions;
|
||||
|
||||
typedef struct SCreateStreamStmt {
|
||||
ENodeType type;
|
||||
char streamName[TSDB_TABLE_NAME_LEN];
|
||||
char targetDbName[TSDB_DB_NAME_LEN];
|
||||
char targetTabName[TSDB_TABLE_NAME_LEN];
|
||||
bool ignoreExists;
|
||||
SStreamOptions* pOptions;
|
||||
SNode* pQuery;
|
||||
SNodeList* pTags;
|
||||
SNode* pSubtable;
|
||||
SNodeList* pCols;
|
||||
ENodeType type;
|
||||
char streamName[TSDB_TABLE_NAME_LEN];
|
||||
char targetDbName[TSDB_DB_NAME_LEN];
|
||||
char targetTabName[TSDB_TABLE_NAME_LEN];
|
||||
bool ignoreExists;
|
||||
SStreamOptions* pOptions;
|
||||
SNode* pQuery;
|
||||
SNode* pPrevQuery;
|
||||
SNodeList* pTags;
|
||||
SNode* pSubtable;
|
||||
SNodeList* pCols;
|
||||
SCMCreateStreamReq* pReq;
|
||||
} SCreateStreamStmt;
|
||||
|
||||
typedef struct SDropStreamStmt {
|
||||
|
|
|
@ -328,6 +328,8 @@ void nodesListInsertList(SNodeList* pTarget, SListCell* pPos, SNodeList* p
|
|||
SNode* nodesListGetNode(SNodeList* pList, int32_t index);
|
||||
SListCell* nodesListGetCell(SNodeList* pList, int32_t index);
|
||||
void nodesDestroyList(SNodeList* pList);
|
||||
bool nodesListMatch(const SNodeList* pList, const SNodeList* pSubList);
|
||||
|
||||
// Only clear the linked list structure, without releasing the elements inside
|
||||
void nodesClearList(SNodeList* pList);
|
||||
|
||||
|
@ -346,6 +348,7 @@ void nodesRewriteExprPostOrder(SNode** pNode, FNodeRewriter rewriter, void* pCon
|
|||
void nodesRewriteExprsPostOrder(SNodeList* pList, FNodeRewriter rewriter, void* pContext);
|
||||
|
||||
bool nodesEqualNode(const SNode* a, const SNode* b);
|
||||
bool nodesMatchNode(const SNode* pSub, const SNode* pNode);
|
||||
|
||||
SNode* nodesCloneNode(const SNode* pNode);
|
||||
SNodeList* nodesCloneList(const SNodeList* pList);
|
||||
|
|
|
@ -53,6 +53,8 @@ typedef struct SLogicNode {
|
|||
EDataOrderLevel requireDataOrder; // requirements for input data
|
||||
EDataOrderLevel resultDataOrder; // properties of the output data
|
||||
EGroupAction groupAction;
|
||||
EOrder inputTsOrder;
|
||||
EOrder outputTsOrder;
|
||||
} SLogicNode;
|
||||
|
||||
typedef enum EScanType {
|
||||
|
@ -111,7 +113,6 @@ typedef struct SJoinLogicNode {
|
|||
SNode* pMergeCondition;
|
||||
SNode* pOnConditions;
|
||||
bool isSingleTableJoin;
|
||||
EOrder inputTsOrder;
|
||||
SNode* pColEqualOnConditions;
|
||||
} SJoinLogicNode;
|
||||
|
||||
|
@ -229,8 +230,6 @@ typedef struct SWindowLogicNode {
|
|||
int8_t igExpired;
|
||||
int8_t igCheckUpdate;
|
||||
EWindowAlgorithm windowAlgo;
|
||||
EOrder inputTsOrder;
|
||||
EOrder outputTsOrder;
|
||||
} SWindowLogicNode;
|
||||
|
||||
typedef struct SFillLogicNode {
|
||||
|
@ -241,13 +240,13 @@ typedef struct SFillLogicNode {
|
|||
SNode* pWStartTs;
|
||||
SNode* pValues; // SNodeListNode
|
||||
STimeWindow timeRange;
|
||||
EOrder inputTsOrder;
|
||||
} SFillLogicNode;
|
||||
|
||||
typedef struct SSortLogicNode {
|
||||
SLogicNode node;
|
||||
SNodeList* pSortKeys;
|
||||
bool groupSort;
|
||||
int64_t maxRows;
|
||||
} SSortLogicNode;
|
||||
|
||||
typedef struct SPartitionLogicNode {
|
||||
|
@ -310,6 +309,8 @@ typedef struct SDataBlockDescNode {
|
|||
|
||||
typedef struct SPhysiNode {
|
||||
ENodeType type;
|
||||
EOrder inputTsOrder;
|
||||
EOrder outputTsOrder;
|
||||
SDataBlockDescNode* pOutputDataBlockDesc;
|
||||
SNode* pConditions;
|
||||
SNodeList* pChildren;
|
||||
|
@ -406,7 +407,6 @@ typedef struct SSortMergeJoinPhysiNode {
|
|||
SNode* pMergeCondition;
|
||||
SNode* pOnConditions;
|
||||
SNodeList* pTargets;
|
||||
EOrder inputTsOrder;
|
||||
SNode* pColEqualOnConditions;
|
||||
} SSortMergeJoinPhysiNode;
|
||||
|
||||
|
@ -460,8 +460,6 @@ typedef struct SWindowPhysiNode {
|
|||
int64_t watermark;
|
||||
int64_t deleteMark;
|
||||
int8_t igExpired;
|
||||
EOrder inputTsOrder;
|
||||
EOrder outputTsOrder;
|
||||
bool mergeDataBlock;
|
||||
} SWindowPhysiNode;
|
||||
|
||||
|
@ -488,7 +486,6 @@ typedef struct SFillPhysiNode {
|
|||
SNode* pWStartTs; // SColumnNode
|
||||
SNode* pValues; // SNodeListNode
|
||||
STimeWindow timeRange;
|
||||
EOrder inputTsOrder;
|
||||
} SFillPhysiNode;
|
||||
|
||||
typedef SFillPhysiNode SStreamFillPhysiNode;
|
||||
|
@ -527,6 +524,7 @@ typedef struct SSortPhysiNode {
|
|||
SNodeList* pExprs; // these are expression list of order_by_clause and parameter expression of aggregate function
|
||||
SNodeList* pSortKeys; // element is SOrderByExprNode, and SOrderByExprNode::pExpr is SColumnNode
|
||||
SNodeList* pTargets;
|
||||
int64_t maxRows;
|
||||
} SSortPhysiNode;
|
||||
|
||||
typedef SSortPhysiNode SGroupSortPhysiNode;
|
||||
|
@ -617,6 +615,7 @@ typedef struct SQueryPlan {
|
|||
int32_t numOfSubplans;
|
||||
SNodeList* pSubplans; // Element is SNodeListNode. The execution level of subplan, starting from 0.
|
||||
SExplainInfo explainInfo;
|
||||
void* pPostPlan;
|
||||
} SQueryPlan;
|
||||
|
||||
const char* dataOrderStr(EDataOrderLevel order);
|
||||
|
|
|
@ -52,6 +52,7 @@ typedef struct SExprNode {
|
|||
SArray* pAssociation;
|
||||
bool orderAlias;
|
||||
bool asAlias;
|
||||
bool asParam;
|
||||
} SExprNode;
|
||||
|
||||
typedef enum EColumnType {
|
||||
|
@ -69,6 +70,7 @@ typedef struct SColumnNode {
|
|||
uint64_t tableId;
|
||||
int8_t tableType;
|
||||
col_id_t colId;
|
||||
uint16_t projIdx; // the idx in project list, start from 1
|
||||
EColumnType colType; // column or tag
|
||||
bool hasIndex;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
|
@ -241,6 +243,12 @@ typedef enum EFillMode {
|
|||
FILL_MODE_NEXT
|
||||
} EFillMode;
|
||||
|
||||
typedef enum ETimeLineMode {
|
||||
TIME_LINE_NONE = 1,
|
||||
TIME_LINE_MULTI,
|
||||
TIME_LINE_GLOBAL,
|
||||
} ETimeLineMode;
|
||||
|
||||
typedef struct SFillNode {
|
||||
ENodeType type; // QUERY_NODE_FILL
|
||||
EFillMode mode;
|
||||
|
@ -263,50 +271,50 @@ typedef struct SCaseWhenNode {
|
|||
} SCaseWhenNode;
|
||||
|
||||
typedef struct SSelectStmt {
|
||||
ENodeType type; // QUERY_NODE_SELECT_STMT
|
||||
bool isDistinct;
|
||||
SNodeList* pProjectionList;
|
||||
SNode* pFromTable;
|
||||
SNode* pWhere;
|
||||
SNodeList* pPartitionByList;
|
||||
SNodeList* pTags; // for create stream
|
||||
SNode* pSubtable; // for create stream
|
||||
SNode* pWindow;
|
||||
SNodeList* pGroupByList; // SGroupingSetNode
|
||||
SNode* pHaving;
|
||||
SNode* pRange;
|
||||
SNode* pEvery;
|
||||
SNode* pFill;
|
||||
SNodeList* pOrderByList; // SOrderByExprNode
|
||||
SLimitNode* pLimit;
|
||||
SLimitNode* pSlimit;
|
||||
STimeWindow timeRange;
|
||||
char stmtName[TSDB_TABLE_NAME_LEN];
|
||||
uint8_t precision;
|
||||
int32_t selectFuncNum;
|
||||
int32_t returnRows; // EFuncReturnRows
|
||||
bool isEmptyResult;
|
||||
bool isTimeLineResult;
|
||||
bool isSubquery;
|
||||
bool hasAggFuncs;
|
||||
bool hasRepeatScanFuncs;
|
||||
bool hasIndefiniteRowsFunc;
|
||||
bool hasMultiRowsFunc;
|
||||
bool hasSelectFunc;
|
||||
bool hasSelectValFunc;
|
||||
bool hasOtherVectorFunc;
|
||||
bool hasUniqueFunc;
|
||||
bool hasTailFunc;
|
||||
bool hasInterpFunc;
|
||||
bool hasInterpPseudoColFunc;
|
||||
bool hasLastRowFunc;
|
||||
bool hasLastFunc;
|
||||
bool hasTimeLineFunc;
|
||||
bool hasUdaf;
|
||||
bool hasStateKey;
|
||||
bool onlyHasKeepOrderFunc;
|
||||
bool groupSort;
|
||||
bool tagScan;
|
||||
ENodeType type; // QUERY_NODE_SELECT_STMT
|
||||
bool isDistinct;
|
||||
SNodeList* pProjectionList;
|
||||
SNode* pFromTable;
|
||||
SNode* pWhere;
|
||||
SNodeList* pPartitionByList;
|
||||
SNodeList* pTags; // for create stream
|
||||
SNode* pSubtable; // for create stream
|
||||
SNode* pWindow;
|
||||
SNodeList* pGroupByList; // SGroupingSetNode
|
||||
SNode* pHaving;
|
||||
SNode* pRange;
|
||||
SNode* pEvery;
|
||||
SNode* pFill;
|
||||
SNodeList* pOrderByList; // SOrderByExprNode
|
||||
SLimitNode* pLimit;
|
||||
SLimitNode* pSlimit;
|
||||
STimeWindow timeRange;
|
||||
char stmtName[TSDB_TABLE_NAME_LEN];
|
||||
uint8_t precision;
|
||||
int32_t selectFuncNum;
|
||||
int32_t returnRows; // EFuncReturnRows
|
||||
ETimeLineMode timeLineResMode;
|
||||
bool isEmptyResult;
|
||||
bool isSubquery;
|
||||
bool hasAggFuncs;
|
||||
bool hasRepeatScanFuncs;
|
||||
bool hasIndefiniteRowsFunc;
|
||||
bool hasMultiRowsFunc;
|
||||
bool hasSelectFunc;
|
||||
bool hasSelectValFunc;
|
||||
bool hasOtherVectorFunc;
|
||||
bool hasUniqueFunc;
|
||||
bool hasTailFunc;
|
||||
bool hasInterpFunc;
|
||||
bool hasInterpPseudoColFunc;
|
||||
bool hasLastRowFunc;
|
||||
bool hasLastFunc;
|
||||
bool hasTimeLineFunc;
|
||||
bool hasUdaf;
|
||||
bool hasStateKey;
|
||||
bool onlyHasKeepOrderFunc;
|
||||
bool groupSort;
|
||||
bool tagScan;
|
||||
} SSelectStmt;
|
||||
|
||||
typedef enum ESetOperatorType { SET_OP_TYPE_UNION_ALL = 1, SET_OP_TYPE_UNION } ESetOperatorType;
|
||||
|
@ -321,6 +329,7 @@ typedef struct SSetOperator {
|
|||
SNode* pLimit;
|
||||
char stmtName[TSDB_TABLE_NAME_LEN];
|
||||
uint8_t precision;
|
||||
ETimeLineMode timeLineResMode;
|
||||
} SSetOperator;
|
||||
|
||||
typedef enum ESqlClause {
|
||||
|
@ -434,7 +443,9 @@ typedef struct SQuery {
|
|||
EQueryExecStage execStage;
|
||||
EQueryExecMode execMode;
|
||||
bool haveResultSet;
|
||||
SNode* pPrevRoot;
|
||||
SNode* pRoot;
|
||||
SNode* pPostRoot;
|
||||
int32_t numOfResCols;
|
||||
SSchema* pResSchema;
|
||||
int8_t precision;
|
||||
|
|
|
@ -74,6 +74,7 @@ int32_t qAnalyseSqlSemantic(SParseContext* pCxt, const struct SCatalogReq* pCata
|
|||
const struct SMetaData* pMetaData, SQuery* pQuery);
|
||||
int32_t qContinueParseSql(SParseContext* pCxt, struct SCatalogReq* pCatalogReq, const struct SMetaData* pMetaData,
|
||||
SQuery* pQuery);
|
||||
int32_t qContinueParsePostQuery(SParseContext* pCxt, SQuery* pQuery, void** pResRow);
|
||||
|
||||
void qDestroyParseContext(SParseContext* pCxt);
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ int32_t qCreateQueryPlan(SPlanContext* pCxt, SQueryPlan** pPlan, SArray* pExecNo
|
|||
// @groupId id of a group of datasource subplans of this @pSubplan
|
||||
// @pSource one execution location of this group of datasource subplans
|
||||
int32_t qSetSubplanExecutionNode(SSubplan* pSubplan, int32_t groupId, SDownstreamSourceNode* pSource);
|
||||
int32_t qContinuePlanPostQuery(void *pPostPlan);
|
||||
|
||||
void qClearSubplanExecutionNode(SSubplan* pSubplan);
|
||||
|
||||
|
|
|
@ -281,7 +281,8 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t
|
|||
(_code) == TSDB_CODE_PAR_INVALID_DROP_COL || ((_code) == TSDB_CODE_TDB_INVALID_TABLE_ID))
|
||||
#define NEED_CLIENT_REFRESH_VG_ERROR(_code) \
|
||||
((_code) == TSDB_CODE_VND_HASH_MISMATCH || (_code) == TSDB_CODE_VND_INVALID_VGROUP_ID)
|
||||
#define NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code) ((_code) == TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER)
|
||||
#define NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code) \
|
||||
((_code) == TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER || (_code) == TSDB_CODE_MND_INVALID_SCHEMA_VER)
|
||||
#define NEED_CLIENT_HANDLE_ERROR(_code) \
|
||||
(NEED_CLIENT_RM_TBLMETA_ERROR(_code) || NEED_CLIENT_REFRESH_VG_ERROR(_code) || \
|
||||
NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code))
|
||||
|
|
|
@ -327,6 +327,7 @@ struct SStreamTask {
|
|||
int64_t checkpointingId;
|
||||
int32_t checkpointAlignCnt;
|
||||
struct SStreamMeta* pMeta;
|
||||
SSHashObj* pNameMap;
|
||||
};
|
||||
|
||||
// meta
|
||||
|
|
|
@ -154,14 +154,14 @@ typedef struct SSnapshotMeta {
|
|||
typedef struct SSyncFSM {
|
||||
void* data;
|
||||
|
||||
int32_t (*FpCommitCb)(const struct SSyncFSM* pFsm, SRpcMsg* pMsg, const SFsmCbMeta* pMeta);
|
||||
int32_t (*FpCommitCb)(const struct SSyncFSM* pFsm, SRpcMsg* pMsg, SFsmCbMeta* pMeta);
|
||||
SyncIndex (*FpAppliedIndexCb)(const struct SSyncFSM* pFsm);
|
||||
int32_t (*FpPreCommitCb)(const struct SSyncFSM* pFsm, SRpcMsg* pMsg, const SFsmCbMeta* pMeta);
|
||||
void (*FpRollBackCb)(const struct SSyncFSM* pFsm, SRpcMsg* pMsg, const SFsmCbMeta* pMeta);
|
||||
int32_t (*FpPreCommitCb)(const struct SSyncFSM* pFsm, SRpcMsg* pMsg, SFsmCbMeta* pMeta);
|
||||
void (*FpRollBackCb)(const struct SSyncFSM* pFsm, SRpcMsg* pMsg, SFsmCbMeta* pMeta);
|
||||
|
||||
void (*FpRestoreFinishCb)(const struct SSyncFSM* pFsm, const SyncIndex commitIdx);
|
||||
void (*FpReConfigCb)(const struct SSyncFSM* pFsm, SRpcMsg* pMsg, const SReConfigCbMeta* pMeta);
|
||||
void (*FpLeaderTransferCb)(const struct SSyncFSM* pFsm, SRpcMsg* pMsg, const SFsmCbMeta* pMeta);
|
||||
void (*FpReConfigCb)(const struct SSyncFSM* pFsm, SRpcMsg* pMsg, SReConfigCbMeta* pMeta);
|
||||
void (*FpLeaderTransferCb)(const struct SSyncFSM* pFsm, SRpcMsg* pMsg, SFsmCbMeta* pMeta);
|
||||
bool (*FpApplyQueueEmptyCb)(const struct SSyncFSM* pFsm);
|
||||
int32_t (*FpApplyQueueItems)(const struct SSyncFSM* pFsm);
|
||||
|
||||
|
|
|
@ -66,8 +66,8 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_RPC_BROKEN_LINK TAOS_DEF_ERROR_CODE(0, 0x0018) //
|
||||
#define TSDB_CODE_RPC_TIMEOUT TAOS_DEF_ERROR_CODE(0, 0x0019) //
|
||||
#define TSDB_CODE_RPC_SOMENODE_NOT_CONNECTED TAOS_DEF_ERROR_CODE(0, 0x0020) // "Vgroup could not be connected"
|
||||
#define TSDB_CODE_RPC_SOMENODE_BROKEN_LINK TAOS_DEF_ERROR_CODE(0, 0x0021) //
|
||||
#define TSDB_CODE_RPC_MAX_SESSIONS TAOS_DEF_ERROR_CODE(0, 0x0022) //
|
||||
#define TSDB_CODE_RPC_SOMENODE_BROKEN_LINK TAOS_DEF_ERROR_CODE(0, 0x0021) //
|
||||
#define TSDB_CODE_RPC_MAX_SESSIONS TAOS_DEF_ERROR_CODE(0, 0x0022) //
|
||||
|
||||
|
||||
|
||||
|
@ -277,7 +277,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_INVALID_FUNC_COMMENT TAOS_DEF_ERROR_CODE(0, 0x0378)
|
||||
#define TSDB_CODE_MND_INVALID_FUNC_RETRIEVE TAOS_DEF_ERROR_CODE(0, 0x0379)
|
||||
|
||||
|
||||
|
||||
|
||||
// mnode-db
|
||||
#define TSDB_CODE_MND_DB_NOT_SELECTED TAOS_DEF_ERROR_CODE(0, 0x0380)
|
||||
|
@ -288,9 +288,9 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_TOO_MANY_DATABASES TAOS_DEF_ERROR_CODE(0, 0x0385)
|
||||
#define TSDB_CODE_MND_DB_IN_DROPPING TAOS_DEF_ERROR_CODE(0, 0x0386) //
|
||||
// #define TSDB_CODE_MND_VGROUP_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0387) // 2.x
|
||||
#define TSDB_CODE_MND_DB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0388) //
|
||||
#define TSDB_CODE_MND_DB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0388) //
|
||||
#define TSDB_CODE_MND_INVALID_DB_ACCT TAOS_DEF_ERROR_CODE(0, 0x0389) // internal
|
||||
#define TSDB_CODE_MND_DB_OPTION_UNCHANGED TAOS_DEF_ERROR_CODE(0, 0x038A) //
|
||||
#define TSDB_CODE_MND_DB_OPTION_UNCHANGED TAOS_DEF_ERROR_CODE(0, 0x038A) //
|
||||
#define TSDB_CODE_MND_DB_INDEX_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x038B)
|
||||
#define TSDB_CODE_MND_DB_RETENTION_PERIOD_ZERO TAOS_DEF_ERROR_CODE(0, 0x038C)
|
||||
// #define TSDB_CODE_MND_INVALID_DB_OPTION_DAYS TAOS_DEF_ERROR_CODE(0, 0x0390) // 2.x
|
||||
|
@ -345,7 +345,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_TRANS_CLOG_IS_NULL TAOS_DEF_ERROR_CODE(0, 0x03D4)
|
||||
#define TSDB_CODE_MND_TRANS_NETWORK_UNAVAILL TAOS_DEF_ERROR_CODE(0, 0x03D5)
|
||||
#define TSDB_CODE_MND_LAST_TRANS_NOT_FINISHED TAOS_DEF_ERROR_CODE(0, 0x03D6) //internal
|
||||
#define TSDB_CODE_MND_TRNAS_SYNC_TIMEOUT TAOS_DEF_ERROR_CODE(0, 0x03D7)
|
||||
#define TSDB_CODE_MND_TRANS_SYNC_TIMEOUT TAOS_DEF_ERROR_CODE(0, 0x03D7)
|
||||
#define TSDB_CODE_MND_TRANS_UNKNOW_ERROR TAOS_DEF_ERROR_CODE(0, 0x03DF)
|
||||
|
||||
// mnode-mq
|
||||
|
@ -516,6 +516,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_QRY_JSON_IN_GROUP_ERROR TAOS_DEF_ERROR_CODE(0, 0x072E)
|
||||
#define TSDB_CODE_QRY_JOB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x072F)
|
||||
#define TSDB_CODE_QRY_QWORKER_QUIT TAOS_DEF_ERROR_CODE(0, 0x0730)
|
||||
#define TSDB_CODE_QRY_GEO_NOT_SUPPORT_ERROR TAOS_DEF_ERROR_CODE(0, 0x0731)
|
||||
|
||||
// grant
|
||||
#define TSDB_CODE_GRANT_EXPIRED TAOS_DEF_ERROR_CODE(0, 0x0800)
|
||||
|
@ -780,7 +781,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_TDLITE_IVLD_OPEN_DIR TAOS_DEF_ERROR_CODE(0, 0x5101)
|
||||
|
||||
// UTIL
|
||||
#define TSDB_CODE_UTIL_QUEUE_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x6000)
|
||||
#define TSDB_CODE_UTIL_QUEUE_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x6000)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -244,7 +244,7 @@ int32_t taosArraySearchIdx(const SArray* pArray, const void* key, __compar_fn_t
|
|||
void taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void* param);
|
||||
|
||||
int32_t taosEncodeArray(void** buf, const SArray* pArray, FEncode encode);
|
||||
void* taosDecodeArray(const void* buf, SArray** pArray, FDecode decode, int32_t dataSz, int8_t sver);
|
||||
void* taosDecodeArray(const void* buf, SArray** pArray, FDecode decode, int32_t dataSz, int8_t sver);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -79,6 +79,7 @@ int32_t compareDoubleVal(const void *pLeft, const void *pRight);
|
|||
|
||||
int32_t compareLenPrefixedStr(const void *pLeft, const void *pRight);
|
||||
int32_t compareLenPrefixedWStr(const void *pLeft, const void *pRight);
|
||||
int32_t compareLenBinaryVal(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t comparestrRegexMatch(const void *pLeft, const void *pRight);
|
||||
int32_t comparestrRegexNMatch(const void *pLeft, const void *pRight);
|
||||
|
|
|
@ -32,7 +32,7 @@ extern "C" {
|
|||
#define TD_VER_MAX UINT64_MAX // TODO: use the real max version from query handle
|
||||
|
||||
// Bytes for each type.
|
||||
extern const int32_t TYPE_BYTES[17];
|
||||
extern const int32_t TYPE_BYTES[21];
|
||||
|
||||
// TODO: replace and remove code below
|
||||
#define CHAR_BYTES sizeof(char)
|
||||
|
@ -195,6 +195,7 @@ typedef enum ELogicConditionType {
|
|||
#define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string
|
||||
#define TSDB_TOPIC_NAME_LEN 193 // it is a null-terminated string
|
||||
#define TSDB_CGROUP_LEN 193 // it is a null-terminated string
|
||||
#define TSDB_OFFSET_LEN 64 // it is a null-terminated string
|
||||
#define TSDB_USER_CGROUP_LEN (TSDB_USER_LEN + TSDB_CGROUP_LEN) // it is a null-terminated string
|
||||
#define TSDB_STREAM_NAME_LEN 193 // it is a null-terminated string
|
||||
#define TSDB_DB_NAME_LEN 65
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#define _TD_UTIL_HEAP_H_
|
||||
|
||||
#include "os.h"
|
||||
#include "tarray.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -58,6 +59,48 @@ void heapDequeue(Heap* heap);
|
|||
|
||||
size_t heapSize(Heap* heap);
|
||||
|
||||
typedef bool (*pq_comp_fn)(void* l, void* r, void* param);
|
||||
|
||||
typedef struct PriorityQueueNode {
|
||||
void* data;
|
||||
} PriorityQueueNode;
|
||||
|
||||
typedef struct PriorityQueue PriorityQueue;
|
||||
|
||||
PriorityQueue* createPriorityQueue(pq_comp_fn fn, FDelete deleteFn, void* param);
|
||||
|
||||
void taosPQSetFn(PriorityQueue* pq, pq_comp_fn fn);
|
||||
|
||||
void destroyPriorityQueue(PriorityQueue* pq);
|
||||
|
||||
PriorityQueueNode* taosPQTop(PriorityQueue* pq);
|
||||
|
||||
size_t taosPQSize(PriorityQueue* pq);
|
||||
|
||||
void taosPQPush(PriorityQueue* pq, const PriorityQueueNode* node);
|
||||
|
||||
void taosPQPop(PriorityQueue* pq);
|
||||
|
||||
typedef struct BoundedQueue BoundedQueue;
|
||||
|
||||
BoundedQueue* createBoundedQueue(uint32_t maxSize, pq_comp_fn fn, FDelete deleteFn, void* param);
|
||||
|
||||
void taosBQSetFn(BoundedQueue* q, pq_comp_fn fn);
|
||||
|
||||
void destroyBoundedQueue(BoundedQueue* q);
|
||||
|
||||
void taosBQPush(BoundedQueue* q, PriorityQueueNode* n);
|
||||
|
||||
PriorityQueueNode* taosBQTop(BoundedQueue* q);
|
||||
|
||||
size_t taosBQSize(BoundedQueue* q);
|
||||
|
||||
size_t taosBQMaxSize(BoundedQueue* q);
|
||||
|
||||
void taosBQBuildHeap(BoundedQueue* q);
|
||||
|
||||
void taosBQPop(BoundedQueue* q);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -227,6 +227,12 @@ typedef struct {
|
|||
STaosxRsp rsp;
|
||||
} SMqTaosxRspObj;
|
||||
|
||||
typedef struct SReqRelInfo {
|
||||
uint64_t userRefId;
|
||||
uint64_t prevRefId;
|
||||
uint64_t nextRefId;
|
||||
} SReqRelInfo;
|
||||
|
||||
typedef struct SRequestObj {
|
||||
int8_t resType; // query or tmq
|
||||
uint64_t requestId;
|
||||
|
@ -250,10 +256,14 @@ typedef struct SRequestObj {
|
|||
bool validateOnly; // todo refactor
|
||||
bool killed;
|
||||
bool inRetry;
|
||||
bool isSubReq;
|
||||
uint32_t prevCode; // previous error code: todo refactor, add update flag for catalog
|
||||
uint32_t retry;
|
||||
int64_t allocatorRefId;
|
||||
SQuery* pQuery;
|
||||
void* pPostPlan;
|
||||
SReqRelInfo relation;
|
||||
void* pWrapper;
|
||||
} SRequestObj;
|
||||
|
||||
typedef struct SSyncQueryParam {
|
||||
|
@ -279,6 +289,7 @@ TAOS_RES* taosQueryImplWithReqid(TAOS* taos, const char* sql, bool validateOnly,
|
|||
void taosAsyncQueryImpl(uint64_t connId, const char* sql, __taos_async_fn_t fp, void* param, bool validateOnly);
|
||||
void taosAsyncQueryImplWithReqid(uint64_t connId, const char* sql, __taos_async_fn_t fp, void* param, bool validateOnly,
|
||||
int64_t reqid);
|
||||
void taosAsyncFetchImpl(SRequestObj *pRequest, __taos_async_fn_t fp, void *param);
|
||||
|
||||
int32_t getVersion1BlockMetaSize(const char* p, int32_t numOfCols);
|
||||
|
||||
|
@ -368,6 +379,7 @@ typedef struct SSqlCallbackWrapper {
|
|||
SParseContext* pParseCtx;
|
||||
SCatalogReq* pCatalogReq;
|
||||
SRequestObj* pRequest;
|
||||
void* pPlanInfo;
|
||||
} SSqlCallbackWrapper;
|
||||
|
||||
SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, bool keepQuery, void** res);
|
||||
|
@ -382,6 +394,12 @@ int32_t handleCreateTbExecRes(void* res, SCatalog* pCatalog);
|
|||
bool qnodeRequired(SRequestObj* pRequest);
|
||||
void continueInsertFromCsv(SSqlCallbackWrapper* pWrapper, SRequestObj* pRequest);
|
||||
void destorySqlCallbackWrapper(SSqlCallbackWrapper* pWrapper);
|
||||
void handleQueryAnslyseRes(SSqlCallbackWrapper *pWrapper, SMetaData *pResultMeta, int32_t code);
|
||||
void restartAsyncQuery(SRequestObj *pRequest, int32_t code);
|
||||
int32_t buildPreviousRequest(SRequestObj *pRequest, const char* sql, SRequestObj** pNewRequest);
|
||||
int32_t prepareAndParseSqlSyntax(SSqlCallbackWrapper **ppWrapper, SRequestObj *pRequest, bool updateMetaForce);
|
||||
void returnToUser(SRequestObj* pRequest);
|
||||
void stopAllQueries(SRequestObj *pRequest);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -358,6 +358,49 @@ int32_t releaseRequest(int64_t rid) { return taosReleaseRef(clientReqRefPool, ri
|
|||
|
||||
int32_t removeRequest(int64_t rid) { return taosRemoveRef(clientReqRefPool, rid); }
|
||||
|
||||
|
||||
void destroySubRequests(SRequestObj *pRequest) {
|
||||
int32_t reqIdx = -1;
|
||||
SRequestObj *pReqList[16] = {NULL};
|
||||
uint64_t tmpRefId = 0;
|
||||
|
||||
if (pRequest->relation.userRefId && pRequest->relation.userRefId != pRequest->self) {
|
||||
return;
|
||||
}
|
||||
|
||||
SRequestObj* pTmp = pRequest;
|
||||
while (pTmp->relation.prevRefId) {
|
||||
tmpRefId = pTmp->relation.prevRefId;
|
||||
pTmp = acquireRequest(tmpRefId);
|
||||
if (pTmp) {
|
||||
pReqList[++reqIdx] = pTmp;
|
||||
releaseRequest(tmpRefId);
|
||||
} else {
|
||||
tscError("0x%" PRIx64 ", prev req ref 0x%" PRIx64 " is not there, reqId:0x%" PRIx64, pTmp->self,
|
||||
tmpRefId, pTmp->requestId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t i = reqIdx; i >= 0; i--) {
|
||||
removeRequest(pReqList[i]->self);
|
||||
}
|
||||
|
||||
tmpRefId = pRequest->relation.nextRefId;
|
||||
while (tmpRefId) {
|
||||
pTmp = acquireRequest(tmpRefId);
|
||||
if (pTmp) {
|
||||
tmpRefId = pTmp->relation.nextRefId;
|
||||
removeRequest(pTmp->self);
|
||||
releaseRequest(pTmp->self);
|
||||
} else {
|
||||
tscError("0x%" PRIx64 " is not there", tmpRefId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void doDestroyRequest(void *p) {
|
||||
if (NULL == p) {
|
||||
return;
|
||||
|
@ -368,10 +411,14 @@ void doDestroyRequest(void *p) {
|
|||
uint64_t reqId = pRequest->requestId;
|
||||
tscTrace("begin to destroy request %" PRIx64 " p:%p", reqId, pRequest);
|
||||
|
||||
destroySubRequests(pRequest);
|
||||
|
||||
taosHashRemove(pRequest->pTscObj->pRequests, &pRequest->self, sizeof(pRequest->self));
|
||||
|
||||
schedulerFreeJob(&pRequest->body.queryJob, 0);
|
||||
|
||||
destorySqlCallbackWrapper(pRequest->pWrapper);
|
||||
|
||||
taosMemoryFreeClear(pRequest->msgBuf);
|
||||
taosMemoryFreeClear(pRequest->pDb);
|
||||
|
||||
|
@ -412,6 +459,63 @@ void destroyRequest(SRequestObj *pRequest) {
|
|||
removeRequest(pRequest->self);
|
||||
}
|
||||
|
||||
void taosStopQueryImpl(SRequestObj *pRequest) {
|
||||
pRequest->killed = true;
|
||||
|
||||
// It is not a query, no need to stop.
|
||||
if (NULL == pRequest->pQuery || QUERY_EXEC_MODE_SCHEDULE != pRequest->pQuery->execMode) {
|
||||
tscDebug("request 0x%" PRIx64 " no need to be killed since not query", pRequest->requestId);
|
||||
return;
|
||||
}
|
||||
|
||||
schedulerFreeJob(&pRequest->body.queryJob, TSDB_CODE_TSC_QUERY_KILLED);
|
||||
tscDebug("request %" PRIx64 " killed", pRequest->requestId);
|
||||
}
|
||||
|
||||
void stopAllQueries(SRequestObj *pRequest) {
|
||||
int32_t reqIdx = -1;
|
||||
SRequestObj *pReqList[16] = {NULL};
|
||||
uint64_t tmpRefId = 0;
|
||||
|
||||
if (pRequest->relation.userRefId && pRequest->relation.userRefId != pRequest->self) {
|
||||
return;
|
||||
}
|
||||
|
||||
SRequestObj* pTmp = pRequest;
|
||||
while (pTmp->relation.prevRefId) {
|
||||
tmpRefId = pTmp->relation.prevRefId;
|
||||
pTmp = acquireRequest(tmpRefId);
|
||||
if (pTmp) {
|
||||
pReqList[++reqIdx] = pTmp;
|
||||
releaseRequest(tmpRefId);
|
||||
} else {
|
||||
tscError("0x%" PRIx64 ", prev req ref 0x%" PRIx64 " is not there, reqId:0x%" PRIx64, pTmp->self,
|
||||
tmpRefId, pTmp->requestId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t i = reqIdx; i >= 0; i--) {
|
||||
taosStopQueryImpl(pReqList[i]);
|
||||
}
|
||||
|
||||
taosStopQueryImpl(pRequest);
|
||||
|
||||
tmpRefId = pRequest->relation.nextRefId;
|
||||
while (tmpRefId) {
|
||||
pTmp = acquireRequest(tmpRefId);
|
||||
if (pTmp) {
|
||||
tmpRefId = pTmp->relation.nextRefId;
|
||||
taosStopQueryImpl(pTmp);
|
||||
releaseRequest(pTmp->self);
|
||||
} else {
|
||||
tscError("0x%" PRIx64 " is not there", tmpRefId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void crashReportThreadFuncUnexpectedStopped(void) { atomic_store_32(&clientStop, -1); }
|
||||
|
||||
static void *tscCrashReportThreadFp(void *param) {
|
||||
|
|
|
@ -464,6 +464,7 @@ int32_t hbBuildQueryDesc(SQueryHbReqBasic *hbBasic, STscObj *pObj) {
|
|||
desc.useconds = now - pRequest->metric.start;
|
||||
desc.reqRid = pRequest->self;
|
||||
desc.stableQuery = pRequest->stableQuery;
|
||||
desc.isSubQuery = pRequest->isSubReq;
|
||||
taosGetFqdn(desc.fqdn);
|
||||
desc.subPlanNum = pRequest->body.subplanNum;
|
||||
|
||||
|
|
|
@ -237,6 +237,17 @@ int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param,
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t buildPreviousRequest(SRequestObj *pRequest, const char* sql, SRequestObj** pNewRequest) {
|
||||
int32_t code = buildRequest(pRequest->pTscObj->id, sql, strlen(sql), pRequest, pRequest->validateOnly, pNewRequest, 0);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pRequest->relation.prevRefId = (*pNewRequest)->self;
|
||||
(*pNewRequest)->relation.nextRefId = pRequest->self;
|
||||
(*pNewRequest)->relation.userRefId = pRequest->self;
|
||||
(*pNewRequest)->isSubReq = true;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtCallback* pStmtCb) {
|
||||
STscObj* pTscObj = pRequest->pTscObj;
|
||||
|
||||
|
@ -878,6 +889,81 @@ static bool incompletaFileParsing(SNode* pStmt) {
|
|||
return QUERY_NODE_VNODE_MODIFY_STMT != nodeType(pStmt) ? false : ((SVnodeModifyOpStmt*)pStmt)->fileProcessing;
|
||||
}
|
||||
|
||||
void continuePostSubQuery(SRequestObj* pRequest, TAOS_ROW row) {
|
||||
SSqlCallbackWrapper* pWrapper = pRequest->pWrapper;
|
||||
int32_t code = nodesAcquireAllocator(pWrapper->pParseCtx->allocatorId);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
int64_t analyseStart = taosGetTimestampUs();
|
||||
code = qContinueParsePostQuery(pWrapper->pParseCtx, pRequest->pQuery, (void**)row);
|
||||
pRequest->metric.analyseCostUs += taosGetTimestampUs() - analyseStart;
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = qContinuePlanPostQuery(pRequest->pPostPlan);
|
||||
}
|
||||
nodesReleaseAllocator(pWrapper->pParseCtx->allocatorId);
|
||||
|
||||
handleQueryAnslyseRes(pWrapper, NULL, code);
|
||||
}
|
||||
|
||||
void returnToUser(SRequestObj* pRequest) {
|
||||
if (pRequest->relation.userRefId == pRequest->self || 0 == pRequest->relation.userRefId) {
|
||||
// return to client
|
||||
pRequest->body.queryFp(pRequest->body.param, pRequest, pRequest->code);
|
||||
return;
|
||||
}
|
||||
|
||||
SRequestObj* pUserReq = acquireRequest(pRequest->relation.userRefId);
|
||||
if (pUserReq) {
|
||||
pUserReq->code = pRequest->code;
|
||||
// return to client
|
||||
pUserReq->body.queryFp(pUserReq->body.param, pUserReq, pUserReq->code);
|
||||
releaseRequest(pRequest->relation.userRefId);
|
||||
return;
|
||||
} else {
|
||||
tscError("0x%" PRIx64 ", user ref 0x%" PRIx64 " is not there, reqId:0x%" PRIx64, pRequest->self,
|
||||
pRequest->relation.userRefId, pRequest->requestId);
|
||||
}
|
||||
}
|
||||
|
||||
void postSubQueryFetchCb(void* param, TAOS_RES* res, int32_t rowNum) {
|
||||
SRequestObj* pRequest = (SRequestObj*)res;
|
||||
if (pRequest->code) {
|
||||
returnToUser(pRequest);
|
||||
return;
|
||||
}
|
||||
|
||||
TAOS_ROW row = NULL;
|
||||
if (rowNum > 0) {
|
||||
row = taos_fetch_row(res); // for single row only now
|
||||
}
|
||||
|
||||
SRequestObj* pNextReq = acquireRequest(pRequest->relation.nextRefId);
|
||||
if (pNextReq) {
|
||||
continuePostSubQuery(pNextReq, row);
|
||||
releaseRequest(pRequest->relation.nextRefId);
|
||||
} else {
|
||||
tscError("0x%" PRIx64 ", next req ref 0x%" PRIx64 " is not there, reqId:0x%" PRIx64, pRequest->self,
|
||||
pRequest->relation.nextRefId, pRequest->requestId);
|
||||
}
|
||||
}
|
||||
|
||||
void handlePostSubQuery(SSqlCallbackWrapper* pWrapper) {
|
||||
SRequestObj* pRequest = pWrapper->pRequest;
|
||||
if (TD_RES_QUERY(pRequest)) {
|
||||
taosAsyncFetchImpl(pRequest, postSubQueryFetchCb, pWrapper);
|
||||
return;
|
||||
}
|
||||
|
||||
SRequestObj* pNextReq = acquireRequest(pRequest->relation.nextRefId);
|
||||
if (pNextReq) {
|
||||
continuePostSubQuery(pNextReq, NULL);
|
||||
releaseRequest(pRequest->relation.nextRefId);
|
||||
} else {
|
||||
tscError("0x%" PRIx64 ", next req ref 0x%" PRIx64 " is not there, reqId:0x%" PRIx64, pRequest->self,
|
||||
pRequest->relation.nextRefId, pRequest->requestId);
|
||||
}
|
||||
}
|
||||
|
||||
// todo refacto the error code mgmt
|
||||
void schedulerExecCb(SExecResult* pResult, void* param, int32_t code) {
|
||||
SSqlCallbackWrapper* pWrapper = param;
|
||||
|
@ -912,12 +998,7 @@ void schedulerExecCb(SExecResult* pResult, void* param, int32_t code) {
|
|||
if (code != TSDB_CODE_SUCCESS && NEED_CLIENT_HANDLE_ERROR(code) && pRequest->sqlstr != NULL) {
|
||||
tscDebug("0x%" PRIx64 " client retry to handle the error, code:%s, tryCount:%d, reqId:0x%" PRIx64, pRequest->self,
|
||||
tstrerror(code), pRequest->retry, pRequest->requestId);
|
||||
pRequest->prevCode = code;
|
||||
schedulerFreeJob(&pRequest->body.queryJob, 0);
|
||||
qDestroyQuery(pRequest->pQuery);
|
||||
pRequest->pQuery = NULL;
|
||||
destorySqlCallbackWrapper(pWrapper);
|
||||
doAsyncQuery(pRequest, true);
|
||||
restartAsyncQuery(pRequest, code);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -938,10 +1019,15 @@ void schedulerExecCb(SExecResult* pResult, void* param, int32_t code) {
|
|||
return;
|
||||
}
|
||||
|
||||
destorySqlCallbackWrapper(pWrapper);
|
||||
if (pRequest->relation.nextRefId) {
|
||||
handlePostSubQuery(pWrapper);
|
||||
} else {
|
||||
destorySqlCallbackWrapper(pWrapper);
|
||||
pRequest->pWrapper = NULL;
|
||||
|
||||
// return to client
|
||||
pRequest->body.queryFp(pRequest->body.param, pRequest, code);
|
||||
// return to client
|
||||
pRequest->body.queryFp(pRequest->body.param, pRequest, code);
|
||||
}
|
||||
}
|
||||
|
||||
SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, bool keepQuery, void** res) {
|
||||
|
@ -1049,6 +1135,7 @@ static int32_t asyncExecSchQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaDat
|
|||
pRequest->requestId);
|
||||
} else {
|
||||
pRequest->body.subplanNum = pDag->numOfSubplans;
|
||||
TSWAP(pRequest->pPostPlan, pDag->pPostPlan);
|
||||
}
|
||||
|
||||
pRequest->metric.execStart = taosGetTimestampUs();
|
||||
|
@ -1084,6 +1171,7 @@ static int32_t asyncExecSchQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaDat
|
|||
tscDebug("0x%" PRIx64 " plan not executed, code:%s 0x%" PRIx64, pRequest->self, tstrerror(code),
|
||||
pRequest->requestId);
|
||||
destorySqlCallbackWrapper(pWrapper);
|
||||
pRequest->pWrapper = NULL;
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
pRequest->code = terrno;
|
||||
}
|
||||
|
@ -1103,6 +1191,7 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaData* pResultM
|
|||
pRequest->body.execMode = pQuery->execMode;
|
||||
if (QUERY_EXEC_MODE_SCHEDULE != pRequest->body.execMode) {
|
||||
destorySqlCallbackWrapper(pWrapper);
|
||||
pRequest->pWrapper = NULL;
|
||||
}
|
||||
|
||||
if (pQuery->pRoot && !pRequest->inRetry) {
|
||||
|
@ -2404,3 +2493,90 @@ TAOS_RES* taosQueryImplWithReqid(TAOS* taos, const char* sql, bool validateOnly,
|
|||
|
||||
return pRequest;
|
||||
}
|
||||
|
||||
|
||||
static void fetchCallback(void *pResult, void *param, int32_t code) {
|
||||
SRequestObj *pRequest = (SRequestObj *)param;
|
||||
|
||||
SReqResultInfo *pResultInfo = &pRequest->body.resInfo;
|
||||
|
||||
tscDebug("0x%" PRIx64 " enter scheduler fetch cb, code:%d - %s, reqId:0x%" PRIx64, pRequest->self, code,
|
||||
tstrerror(code), pRequest->requestId);
|
||||
|
||||
pResultInfo->pData = pResult;
|
||||
pResultInfo->numOfRows = 0;
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pRequest->code = code;
|
||||
taosMemoryFreeClear(pResultInfo->pData);
|
||||
pRequest->body.fetchFp(pRequest->body.param, pRequest, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pRequest->code != TSDB_CODE_SUCCESS) {
|
||||
taosMemoryFreeClear(pResultInfo->pData);
|
||||
pRequest->body.fetchFp(pRequest->body.param, pRequest, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
pRequest->code =
|
||||
setQueryResultFromRsp(pResultInfo, (const SRetrieveTableRsp *)pResultInfo->pData, pResultInfo->convertUcs4, true);
|
||||
if (pRequest->code != TSDB_CODE_SUCCESS) {
|
||||
pResultInfo->numOfRows = 0;
|
||||
pRequest->code = code;
|
||||
tscError("0x%" PRIx64 " fetch results failed, code:%s, reqId:0x%" PRIx64, pRequest->self, tstrerror(code),
|
||||
pRequest->requestId);
|
||||
} else {
|
||||
tscDebug("0x%" PRIx64 " fetch results, numOfRows:%" PRId64 " total Rows:%" PRId64 ", complete:%d, reqId:0x%" PRIx64,
|
||||
pRequest->self, pResultInfo->numOfRows, pResultInfo->totalRows, pResultInfo->completed,
|
||||
pRequest->requestId);
|
||||
|
||||
STscObj *pTscObj = pRequest->pTscObj;
|
||||
SAppClusterSummary *pActivity = &pTscObj->pAppInfo->summary;
|
||||
atomic_add_fetch_64((int64_t *)&pActivity->fetchBytes, pRequest->body.resInfo.payloadLen);
|
||||
}
|
||||
|
||||
pRequest->body.fetchFp(pRequest->body.param, pRequest, pResultInfo->numOfRows);
|
||||
}
|
||||
|
||||
void taosAsyncFetchImpl(SRequestObj *pRequest, __taos_async_fn_t fp, void *param) {
|
||||
pRequest->body.fetchFp = fp;
|
||||
pRequest->body.param = param;
|
||||
|
||||
SReqResultInfo *pResultInfo = &pRequest->body.resInfo;
|
||||
|
||||
// this query has no results or error exists, return directly
|
||||
if (taos_num_fields(pRequest) == 0 || pRequest->code != TSDB_CODE_SUCCESS) {
|
||||
pResultInfo->numOfRows = 0;
|
||||
pRequest->body.fetchFp(param, pRequest, pResultInfo->numOfRows);
|
||||
return;
|
||||
}
|
||||
|
||||
// all data has returned to App already, no need to try again
|
||||
if (pResultInfo->completed) {
|
||||
// it is a local executed query, no need to do async fetch
|
||||
if (QUERY_EXEC_MODE_SCHEDULE != pRequest->body.execMode) {
|
||||
if (pResultInfo->localResultFetched) {
|
||||
pResultInfo->numOfRows = 0;
|
||||
pResultInfo->current = 0;
|
||||
} else {
|
||||
pResultInfo->localResultFetched = true;
|
||||
}
|
||||
} else {
|
||||
pResultInfo->numOfRows = 0;
|
||||
}
|
||||
|
||||
pRequest->body.fetchFp(param, pRequest, pResultInfo->numOfRows);
|
||||
return;
|
||||
}
|
||||
|
||||
SSchedulerReq req = {
|
||||
.syncReq = false,
|
||||
.fetchFp = fetchCallback,
|
||||
.cbParam = pRequest,
|
||||
};
|
||||
|
||||
schedulerFetchRows(pRequest->body.queryJob, &req);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -563,22 +563,13 @@ int taos_select_db(TAOS *taos, const char *db) {
|
|||
return code;
|
||||
}
|
||||
|
||||
|
||||
void taos_stop_query(TAOS_RES *res) {
|
||||
if (res == NULL || TD_RES_TMQ(res) || TD_RES_TMQ_META(res) || TD_RES_TMQ_METADATA(res)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SRequestObj *pRequest = (SRequestObj *)res;
|
||||
pRequest->killed = true;
|
||||
|
||||
// It is not a query, no need to stop.
|
||||
if (NULL == pRequest->pQuery || QUERY_EXEC_MODE_SCHEDULE != pRequest->pQuery->execMode) {
|
||||
tscDebug("request 0x%" PRIx64 " no need to be killed since not query", pRequest->requestId);
|
||||
return;
|
||||
}
|
||||
|
||||
schedulerFreeJob(&pRequest->body.queryJob, TSDB_CODE_TSC_QUERY_KILLED);
|
||||
tscDebug("request %" PRIx64 " killed", pRequest->requestId);
|
||||
stopAllQueries((SRequestObj*)res);
|
||||
}
|
||||
|
||||
bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col) {
|
||||
|
@ -774,8 +765,13 @@ static void destoryCatalogReq(SCatalogReq *pCatalogReq) {
|
|||
taosArrayDestroy(pCatalogReq->pDbVgroup);
|
||||
taosArrayDestroy(pCatalogReq->pDbCfg);
|
||||
taosArrayDestroy(pCatalogReq->pDbInfo);
|
||||
taosArrayDestroyEx(pCatalogReq->pTableMeta, destoryTablesReq);
|
||||
taosArrayDestroyEx(pCatalogReq->pTableHash, destoryTablesReq);
|
||||
if (pCatalogReq->cloned) {
|
||||
taosArrayDestroy(pCatalogReq->pTableMeta);
|
||||
taosArrayDestroy(pCatalogReq->pTableHash);
|
||||
} else {
|
||||
taosArrayDestroyEx(pCatalogReq->pTableMeta, destoryTablesReq);
|
||||
taosArrayDestroyEx(pCatalogReq->pTableHash, destoryTablesReq);
|
||||
}
|
||||
taosArrayDestroy(pCatalogReq->pUdf);
|
||||
taosArrayDestroy(pCatalogReq->pIndex);
|
||||
taosArrayDestroy(pCatalogReq->pUser);
|
||||
|
@ -794,26 +790,108 @@ void destorySqlCallbackWrapper(SSqlCallbackWrapper *pWrapper) {
|
|||
taosMemoryFree(pWrapper);
|
||||
}
|
||||
|
||||
void destroyCtxInRequest(SRequestObj* pRequest) {
|
||||
schedulerFreeJob(&pRequest->body.queryJob, 0);
|
||||
qDestroyQuery(pRequest->pQuery);
|
||||
pRequest->pQuery = NULL;
|
||||
destorySqlCallbackWrapper(pRequest->pWrapper);
|
||||
pRequest->pWrapper = NULL;
|
||||
}
|
||||
|
||||
|
||||
static void doAsyncQueryFromAnalyse(SMetaData *pResultMeta, void *param, int32_t code) {
|
||||
SSqlCallbackWrapper *pWrapper = (SSqlCallbackWrapper *)param;
|
||||
SRequestObj *pRequest = pWrapper->pRequest;
|
||||
SQuery *pQuery = pRequest->pQuery;
|
||||
|
||||
int64_t analyseStart = taosGetTimestampUs();
|
||||
pRequest->metric.ctgCostUs = analyseStart - pRequest->metric.ctgStart;
|
||||
qDebug("0x%" PRIx64 " start to semantic analysis, reqId:0x%" PRIx64, pRequest->self, pRequest->requestId);
|
||||
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
int64_t analyseStart = taosGetTimestampUs();
|
||||
pRequest->metric.ctgCostUs = analyseStart - pRequest->metric.ctgStart;
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = qAnalyseSqlSemantic(pWrapper->pParseCtx, pWrapper->pCatalogReq, pResultMeta, pQuery);
|
||||
}
|
||||
|
||||
pRequest->metric.analyseCostUs += taosGetTimestampUs() - analyseStart;
|
||||
|
||||
handleQueryAnslyseRes(pWrapper, pResultMeta, code);
|
||||
}
|
||||
|
||||
int32_t cloneCatalogReq(SCatalogReq* * ppTarget, SCatalogReq* pSrc) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SCatalogReq* pTarget = taosMemoryCalloc(1, sizeof(SCatalogReq));
|
||||
if (pTarget == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
} else {
|
||||
pTarget->pDbVgroup = taosArrayDup(pSrc->pDbVgroup, NULL);
|
||||
pTarget->pDbCfg = taosArrayDup(pSrc->pDbCfg, NULL);
|
||||
pTarget->pDbInfo = taosArrayDup(pSrc->pDbInfo, NULL);
|
||||
pTarget->pTableMeta = taosArrayDup(pSrc->pTableMeta, NULL);
|
||||
pTarget->pTableHash = taosArrayDup(pSrc->pTableHash, NULL);
|
||||
pTarget->pUdf = taosArrayDup(pSrc->pUdf, NULL);
|
||||
pTarget->pIndex = taosArrayDup(pSrc->pIndex, NULL);
|
||||
pTarget->pUser = taosArrayDup(pSrc->pUser, NULL);
|
||||
pTarget->pTableIndex = taosArrayDup(pSrc->pTableIndex, NULL);
|
||||
pTarget->pTableCfg = taosArrayDup(pSrc->pTableCfg, NULL);
|
||||
pTarget->pTableTag = taosArrayDup(pSrc->pTableTag, NULL);
|
||||
pTarget->qNodeRequired = pSrc->qNodeRequired;
|
||||
pTarget->dNodeRequired = pSrc->dNodeRequired;
|
||||
pTarget->svrVerRequired = pSrc->svrVerRequired;
|
||||
pTarget->forceUpdate = pSrc->forceUpdate;
|
||||
pTarget->cloned = true;
|
||||
|
||||
*ppTarget = pTarget;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
void handleSubQueryFromAnalyse(SSqlCallbackWrapper *pWrapper, SMetaData *pResultMeta, SNode* pRoot) {
|
||||
SRequestObj* pNewRequest = NULL;
|
||||
SSqlCallbackWrapper* pNewWrapper = NULL;
|
||||
int32_t code = buildPreviousRequest(pWrapper->pRequest, pWrapper->pRequest->sqlstr, &pNewRequest);
|
||||
if (code) {
|
||||
handleQueryAnslyseRes(pWrapper, pResultMeta, code);
|
||||
return;
|
||||
}
|
||||
|
||||
pNewRequest->pQuery = (SQuery*)nodesMakeNode(QUERY_NODE_QUERY);
|
||||
if (NULL == pNewRequest->pQuery) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
} else {
|
||||
pNewRequest->pQuery->pRoot = pRoot;
|
||||
pRoot = NULL;
|
||||
pNewRequest->pQuery->execStage = QUERY_EXEC_STAGE_ANALYSE;
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = prepareAndParseSqlSyntax(&pNewWrapper, pNewRequest, false);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = cloneCatalogReq(&pNewWrapper->pCatalogReq, pWrapper->pCatalogReq);
|
||||
}
|
||||
doAsyncQueryFromAnalyse(pResultMeta, pNewWrapper, code);
|
||||
nodesDestroyNode(pRoot);
|
||||
}
|
||||
|
||||
void handleQueryAnslyseRes(SSqlCallbackWrapper *pWrapper, SMetaData *pResultMeta, int32_t code) {
|
||||
SRequestObj *pRequest = pWrapper->pRequest;
|
||||
SQuery *pQuery = pRequest->pQuery;
|
||||
|
||||
if (code == TSDB_CODE_SUCCESS && pQuery->pPrevRoot) {
|
||||
SNode* prevRoot = pQuery->pPrevRoot;
|
||||
pQuery->pPrevRoot = NULL;
|
||||
handleSubQueryFromAnalyse(pWrapper, pResultMeta, prevRoot);
|
||||
return;
|
||||
}
|
||||
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
pRequest->stableQuery = pQuery->stableQuery;
|
||||
if (pQuery->pRoot) {
|
||||
pRequest->stmtType = pQuery->pRoot->type;
|
||||
}
|
||||
}
|
||||
|
||||
pRequest->metric.analyseCostUs = taosGetTimestampUs() - analyseStart;
|
||||
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
if (pQuery->haveResultSet) {
|
||||
setResSchemaInfo(&pRequest->body.resInfo, pQuery->pResSchema, pQuery->numOfResCols);
|
||||
setResPrecision(&pRequest->body.resInfo, pQuery->precision);
|
||||
|
@ -826,14 +904,14 @@ static void doAsyncQueryFromAnalyse(SMetaData *pResultMeta, void *param, int32_t
|
|||
launchAsyncQuery(pRequest, pQuery, pResultMeta, pWrapper);
|
||||
} else {
|
||||
destorySqlCallbackWrapper(pWrapper);
|
||||
pRequest->pWrapper = NULL;
|
||||
qDestroyQuery(pRequest->pQuery);
|
||||
pRequest->pQuery = NULL;
|
||||
|
||||
if (NEED_CLIENT_HANDLE_ERROR(code)) {
|
||||
tscDebug("0x%" PRIx64 " client retry to handle the error, code:%d - %s, tryCount:%d, reqId:0x%" PRIx64,
|
||||
pRequest->self, code, tstrerror(code), pRequest->retry, pRequest->requestId);
|
||||
pRequest->prevCode = code;
|
||||
doAsyncQuery(pRequest, true);
|
||||
restartAsyncQuery(pRequest, code);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -841,7 +919,7 @@ static void doAsyncQueryFromAnalyse(SMetaData *pResultMeta, void *param, int32_t
|
|||
tscError("0x%" PRIx64 " error occurs, code:%s, return to user app, reqId:0x%" PRIx64, pRequest->self,
|
||||
tstrerror(code), pRequest->requestId);
|
||||
pRequest->code = code;
|
||||
pRequest->body.queryFp(pRequest->body.param, pRequest, code);
|
||||
returnToUser(pRequest);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -904,6 +982,7 @@ static void doAsyncQueryFromParse(SMetaData *pResultMeta, void *param, int32_t c
|
|||
tscError("0x%" PRIx64 " error happens, code:%d - %s, reqId:0x%" PRIx64, pWrapper->pRequest->self, code,
|
||||
tstrerror(code), pWrapper->pRequest->requestId);
|
||||
destorySqlCallbackWrapper(pWrapper);
|
||||
pRequest->pWrapper = NULL;
|
||||
terrno = code;
|
||||
pRequest->code = code;
|
||||
pRequest->body.queryFp(pRequest->body.param, pRequest, code);
|
||||
|
@ -920,6 +999,7 @@ void continueInsertFromCsv(SSqlCallbackWrapper *pWrapper, SRequestObj *pRequest)
|
|||
tscError("0x%" PRIx64 " error happens, code:%d - %s, reqId:0x%" PRIx64, pWrapper->pRequest->self, code,
|
||||
tstrerror(code), pWrapper->pRequest->requestId);
|
||||
destorySqlCallbackWrapper(pWrapper);
|
||||
pRequest->pWrapper = NULL;
|
||||
terrno = code;
|
||||
pRequest->code = code;
|
||||
pRequest->body.queryFp(pRequest->body.param, pRequest, code);
|
||||
|
@ -967,27 +1047,16 @@ int32_t createParseContext(const SRequestObj *pRequest, SParseContext **pCxt) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) {
|
||||
int32_t prepareAndParseSqlSyntax(SSqlCallbackWrapper **ppWrapper, SRequestObj *pRequest, bool updateMetaForce) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
STscObj *pTscObj = pRequest->pTscObj;
|
||||
SSqlCallbackWrapper *pWrapper = NULL;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
if (pRequest->retry++ > REQUEST_TOTAL_EXEC_TIMES) {
|
||||
code = pRequest->prevCode;
|
||||
terrno = code;
|
||||
pRequest->code = code;
|
||||
tscDebug("call sync query cb with code: %s", tstrerror(code));
|
||||
pRequest->body.queryFp(pRequest->body.param, pRequest, code);
|
||||
return;
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pWrapper = taosMemoryCalloc(1, sizeof(SSqlCallbackWrapper));
|
||||
if (pWrapper == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
} else {
|
||||
pWrapper->pRequest = pRequest;
|
||||
}
|
||||
SSqlCallbackWrapper *pWrapper = taosMemoryCalloc(1, sizeof(SSqlCallbackWrapper));
|
||||
if (pWrapper == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
} else {
|
||||
pWrapper->pRequest = pRequest;
|
||||
pRequest->pWrapper = pWrapper;
|
||||
*ppWrapper = pWrapper;
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -999,7 +1068,7 @@ void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) {
|
|||
code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &pWrapper->pParseCtx->pCatalog);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (TSDB_CODE_SUCCESS == code && NULL == pRequest->pQuery) {
|
||||
int64_t syntaxStart = taosGetTimestampUs();
|
||||
|
||||
pWrapper->pCatalogReq = taosMemoryCalloc(1, sizeof(SCatalogReq));
|
||||
|
@ -1014,6 +1083,27 @@ void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) {
|
|||
pRequest->metric.parseCostUs += taosGetTimestampUs() - syntaxStart;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) {
|
||||
SSqlCallbackWrapper *pWrapper = NULL;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
if (pRequest->retry++ > REQUEST_TOTAL_EXEC_TIMES) {
|
||||
code = pRequest->prevCode;
|
||||
terrno = code;
|
||||
pRequest->code = code;
|
||||
tscDebug("call sync query cb with code: %s", tstrerror(code));
|
||||
pRequest->body.queryFp(pRequest->body.param, pRequest, code);
|
||||
return;
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = prepareAndParseSqlSyntax(&pWrapper, pRequest, updateMetaForce);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pRequest->stmtType = pRequest->pQuery->pRoot->type;
|
||||
code = phaseAsyncQuery(pWrapper);
|
||||
|
@ -1023,12 +1113,14 @@ void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) {
|
|||
tscError("0x%" PRIx64 " error happens, code:%d - %s, reqId:0x%" PRIx64, pRequest->self, code, tstrerror(code),
|
||||
pRequest->requestId);
|
||||
destorySqlCallbackWrapper(pWrapper);
|
||||
pRequest->pWrapper = NULL;
|
||||
qDestroyQuery(pRequest->pQuery);
|
||||
pRequest->pQuery = NULL;
|
||||
|
||||
if (NEED_CLIENT_HANDLE_ERROR(code)) {
|
||||
tscDebug("0x%" PRIx64 " client retry to handle the error, code:%d - %s, tryCount:%d, reqId:0x%" PRIx64,
|
||||
pRequest->self, code, tstrerror(code), pRequest->retry, pRequest->requestId);
|
||||
refreshMeta(pRequest->pTscObj, pRequest);
|
||||
pRequest->prevCode = code;
|
||||
doAsyncQuery(pRequest, true);
|
||||
return;
|
||||
|
@ -1040,48 +1132,57 @@ void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) {
|
|||
}
|
||||
}
|
||||
|
||||
static void fetchCallback(void *pResult, void *param, int32_t code) {
|
||||
SRequestObj *pRequest = (SRequestObj *)param;
|
||||
|
||||
SReqResultInfo *pResultInfo = &pRequest->body.resInfo;
|
||||
|
||||
tscDebug("0x%" PRIx64 " enter scheduler fetch cb, code:%d - %s, reqId:0x%" PRIx64, pRequest->self, code,
|
||||
tstrerror(code), pRequest->requestId);
|
||||
|
||||
pResultInfo->pData = pResult;
|
||||
pResultInfo->numOfRows = 0;
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pRequest->code = code;
|
||||
taosMemoryFreeClear(pResultInfo->pData);
|
||||
pRequest->body.fetchFp(pRequest->body.param, pRequest, 0);
|
||||
return;
|
||||
void restartAsyncQuery(SRequestObj *pRequest, int32_t code) {
|
||||
int32_t reqIdx = 0;
|
||||
SRequestObj *pReqList[16] = {NULL};
|
||||
SRequestObj *pUserReq = NULL;
|
||||
pReqList[0] = pRequest;
|
||||
uint64_t tmpRefId = 0;
|
||||
SRequestObj* pTmp = pRequest;
|
||||
while (pTmp->relation.prevRefId) {
|
||||
tmpRefId = pTmp->relation.prevRefId;
|
||||
pTmp = acquireRequest(tmpRefId);
|
||||
if (pTmp) {
|
||||
pReqList[++reqIdx] = pTmp;
|
||||
releaseRequest(tmpRefId);
|
||||
} else {
|
||||
tscError("0x%" PRIx64 ", prev req ref 0x%" PRIx64 " is not there, reqId:0x%" PRIx64, pTmp->self,
|
||||
tmpRefId, pTmp->requestId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pRequest->code != TSDB_CODE_SUCCESS) {
|
||||
taosMemoryFreeClear(pResultInfo->pData);
|
||||
pRequest->body.fetchFp(pRequest->body.param, pRequest, 0);
|
||||
return;
|
||||
tmpRefId = pRequest->relation.nextRefId;
|
||||
while (tmpRefId) {
|
||||
pTmp = acquireRequest(tmpRefId);
|
||||
if (pTmp) {
|
||||
tmpRefId = pTmp->relation.nextRefId;
|
||||
removeRequest(pTmp->self);
|
||||
releaseRequest(pTmp->self);
|
||||
} else {
|
||||
tscError("0x%" PRIx64 " is not there", tmpRefId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pRequest->code =
|
||||
setQueryResultFromRsp(pResultInfo, (const SRetrieveTableRsp *)pResultInfo->pData, pResultInfo->convertUcs4, true);
|
||||
if (pRequest->code != TSDB_CODE_SUCCESS) {
|
||||
pResultInfo->numOfRows = 0;
|
||||
pRequest->code = code;
|
||||
tscError("0x%" PRIx64 " fetch results failed, code:%s, reqId:0x%" PRIx64, pRequest->self, tstrerror(code),
|
||||
pRequest->requestId);
|
||||
for (int32_t i = reqIdx; i >= 0; i--) {
|
||||
destroyCtxInRequest(pReqList[i]);
|
||||
if (pReqList[i]->relation.userRefId == pReqList[i]->self || 0 == pReqList[i]->relation.userRefId) {
|
||||
pUserReq = pReqList[i];
|
||||
} else {
|
||||
removeRequest(pReqList[i]->self);
|
||||
}
|
||||
}
|
||||
|
||||
if (pUserReq) {
|
||||
pUserReq->prevCode = code;
|
||||
memset(&pUserReq->relation, 0, sizeof(pUserReq->relation));
|
||||
} else {
|
||||
tscDebug("0x%" PRIx64 " fetch results, numOfRows:%" PRId64 " total Rows:%" PRId64 ", complete:%d, reqId:0x%" PRIx64,
|
||||
pRequest->self, pResultInfo->numOfRows, pResultInfo->totalRows, pResultInfo->completed,
|
||||
pRequest->requestId);
|
||||
|
||||
STscObj *pTscObj = pRequest->pTscObj;
|
||||
SAppClusterSummary *pActivity = &pTscObj->pAppInfo->summary;
|
||||
atomic_add_fetch_64((int64_t *)&pActivity->fetchBytes, pRequest->body.resInfo.payloadLen);
|
||||
tscError("user req is missing");
|
||||
return;
|
||||
}
|
||||
|
||||
pRequest->body.fetchFp(pRequest->body.param, pRequest, pResultInfo->numOfRows);
|
||||
doAsyncQuery(pUserReq, true);
|
||||
}
|
||||
|
||||
void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) {
|
||||
|
@ -1095,43 +1196,8 @@ void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) {
|
|||
}
|
||||
|
||||
SRequestObj *pRequest = res;
|
||||
pRequest->body.fetchFp = fp;
|
||||
pRequest->body.param = param;
|
||||
|
||||
SReqResultInfo *pResultInfo = &pRequest->body.resInfo;
|
||||
|
||||
// this query has no results or error exists, return directly
|
||||
if (taos_num_fields(pRequest) == 0 || pRequest->code != TSDB_CODE_SUCCESS) {
|
||||
pResultInfo->numOfRows = 0;
|
||||
pRequest->body.fetchFp(param, pRequest, pResultInfo->numOfRows);
|
||||
return;
|
||||
}
|
||||
|
||||
// all data has returned to App already, no need to try again
|
||||
if (pResultInfo->completed) {
|
||||
// it is a local executed query, no need to do async fetch
|
||||
if (QUERY_EXEC_MODE_SCHEDULE != pRequest->body.execMode) {
|
||||
if (pResultInfo->localResultFetched) {
|
||||
pResultInfo->numOfRows = 0;
|
||||
pResultInfo->current = 0;
|
||||
} else {
|
||||
pResultInfo->localResultFetched = true;
|
||||
}
|
||||
} else {
|
||||
pResultInfo->numOfRows = 0;
|
||||
}
|
||||
|
||||
pRequest->body.fetchFp(param, pRequest, pResultInfo->numOfRows);
|
||||
return;
|
||||
}
|
||||
|
||||
SSchedulerReq req = {
|
||||
.syncReq = false,
|
||||
.fetchFp = fetchCallback,
|
||||
.cbParam = pRequest,
|
||||
};
|
||||
|
||||
schedulerFetchRows(pRequest->body.queryJob, &req);
|
||||
taosAsyncFetchImpl(pRequest, fp, param);
|
||||
}
|
||||
|
||||
void taos_fetch_raw_block_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) {
|
||||
|
|
|
@ -77,6 +77,7 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
}
|
||||
|
||||
if ((code = taosCheckVersionCompatibleFromStr(version, connectRsp.sVer, 3)) != 0) {
|
||||
tscError("version not compatible. client version: %s, server version: %s", version, connectRsp.sVer);
|
||||
setErrno(pRequest, code);
|
||||
tsem_post(&pRequest->body.rspSem);
|
||||
goto End;
|
||||
|
|
|
@ -82,7 +82,7 @@ struct tmq_t {
|
|||
int8_t useSnapshot;
|
||||
int8_t autoCommit;
|
||||
int32_t autoCommitInterval;
|
||||
int32_t resetOffsetCfg;
|
||||
int8_t resetOffsetCfg;
|
||||
uint64_t consumerId;
|
||||
bool hbBgEnable;
|
||||
tmq_commit_cb* commitCb;
|
||||
|
@ -99,6 +99,7 @@ struct tmq_t {
|
|||
// poll info
|
||||
int64_t pollCnt;
|
||||
int64_t totalRows;
|
||||
// bool needReportOffsetRows;
|
||||
|
||||
// timer
|
||||
tmr_h hbLiveTimer;
|
||||
|
@ -264,7 +265,7 @@ tmq_conf_t* tmq_conf_new() {
|
|||
conf->withTbName = false;
|
||||
conf->autoCommit = true;
|
||||
conf->autoCommitInterval = DEFAULT_AUTO_COMMIT_INTERVAL;
|
||||
conf->resetOffset = TMQ_OFFSET__RESET_EARLIEAST;
|
||||
conf->resetOffset = TMQ_OFFSET__RESET_EARLIEST;
|
||||
conf->hbBgEnable = true;
|
||||
|
||||
return conf;
|
||||
|
@ -318,7 +319,7 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value
|
|||
conf->resetOffset = TMQ_OFFSET__RESET_NONE;
|
||||
return TMQ_CONF_OK;
|
||||
} else if (strcasecmp(value, "earliest") == 0) {
|
||||
conf->resetOffset = TMQ_OFFSET__RESET_EARLIEAST;
|
||||
conf->resetOffset = TMQ_OFFSET__RESET_EARLIEST;
|
||||
return TMQ_CONF_OK;
|
||||
} else if (strcasecmp(value, "latest") == 0) {
|
||||
conf->resetOffset = TMQ_OFFSET__RESET_LATEST;
|
||||
|
@ -357,7 +358,7 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value
|
|||
return TMQ_CONF_OK;
|
||||
}
|
||||
|
||||
if (strcasecmp(key, "enable.heartbeat.background") == 0) {
|
||||
// if (strcasecmp(key, "enable.heartbeat.background") == 0) {
|
||||
// if (strcasecmp(value, "true") == 0) {
|
||||
// conf->hbBgEnable = true;
|
||||
// return TMQ_CONF_OK;
|
||||
|
@ -365,10 +366,10 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value
|
|||
// conf->hbBgEnable = false;
|
||||
// return TMQ_CONF_OK;
|
||||
// } else {
|
||||
tscError("the default value of enable.heartbeat.background is true, can not be seted");
|
||||
return TMQ_CONF_INVALID;
|
||||
// tscError("the default value of enable.heartbeat.background is true, can not be seted");
|
||||
// return TMQ_CONF_INVALID;
|
||||
// }
|
||||
}
|
||||
// }
|
||||
|
||||
if (strcasecmp(key, "td.connect.ip") == 0) {
|
||||
conf->ip = taosStrdup(value);
|
||||
|
@ -422,30 +423,30 @@ char** tmq_list_to_c_array(const tmq_list_t* list) {
|
|||
return container->pData;
|
||||
}
|
||||
|
||||
static SMqClientVg* foundClientVg(SArray* pTopicList, const char* pName, int32_t vgId, int32_t* index,
|
||||
int32_t* numOfVgroups) {
|
||||
int32_t numOfTopics = taosArrayGetSize(pTopicList);
|
||||
*index = -1;
|
||||
*numOfVgroups = 0;
|
||||
|
||||
for (int32_t i = 0; i < numOfTopics; ++i) {
|
||||
SMqClientTopic* pTopic = taosArrayGet(pTopicList, i);
|
||||
if (strcmp(pTopic->topicName, pName) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
*numOfVgroups = taosArrayGetSize(pTopic->vgs);
|
||||
for (int32_t j = 0; j < (*numOfVgroups); ++j) {
|
||||
SMqClientVg* pClientVg = taosArrayGet(pTopic->vgs, j);
|
||||
if (pClientVg->vgId == vgId) {
|
||||
*index = j;
|
||||
return pClientVg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
//static SMqClientVg* foundClientVg(SArray* pTopicList, const char* pName, int32_t vgId, int32_t* index,
|
||||
// int32_t* numOfVgroups) {
|
||||
// int32_t numOfTopics = taosArrayGetSize(pTopicList);
|
||||
// *index = -1;
|
||||
// *numOfVgroups = 0;
|
||||
//
|
||||
// for (int32_t i = 0; i < numOfTopics; ++i) {
|
||||
// SMqClientTopic* pTopic = taosArrayGet(pTopicList, i);
|
||||
// if (strcmp(pTopic->topicName, pName) != 0) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// *numOfVgroups = taosArrayGetSize(pTopic->vgs);
|
||||
// for (int32_t j = 0; j < (*numOfVgroups); ++j) {
|
||||
// SMqClientVg* pClientVg = taosArrayGet(pTopic->vgs, j);
|
||||
// if (pClientVg->vgId == vgId) {
|
||||
// *index = j;
|
||||
// return pClientVg;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return NULL;
|
||||
//}
|
||||
|
||||
// Two problems do not need to be addressed here
|
||||
// 1. update to of epset. the response of poll request will automatically handle this problem
|
||||
|
@ -567,12 +568,12 @@ static int32_t doSendCommitMsg(tmq_t* tmq, SMqClientVg* pVg, const char* pTopicN
|
|||
atomic_add_fetch_32(&pParamSet->totalRspNum, 1);
|
||||
|
||||
SEp* pEp = GET_ACTIVE_EP(&pVg->epSet);
|
||||
char offsetBuf[80] = {0};
|
||||
char offsetBuf[TSDB_OFFSET_LEN] = {0};
|
||||
tFormatOffset(offsetBuf, tListLen(offsetBuf), &pOffset->offset.val);
|
||||
|
||||
char commitBuf[80] = {0};
|
||||
char commitBuf[TSDB_OFFSET_LEN] = {0};
|
||||
tFormatOffset(commitBuf, tListLen(commitBuf), &pVg->offsetInfo.committedOffset);
|
||||
tscDebug("consumer:0x%" PRIx64 " topic:%s on vgId:%d send offset:%s prev:%s, ep:%s:%d, ordinal:%d/%d, req:0x%" PRIx64,
|
||||
tscInfo("consumer:0x%" PRIx64 " topic:%s on vgId:%d send offset:%s prev:%s, ep:%s:%d, ordinal:%d/%d, req:0x%" PRIx64,
|
||||
tmq->consumerId, pOffset->offset.subKey, pVg->vgId, offsetBuf, commitBuf, pEp->fqdn, pEp->port, index + 1,
|
||||
totalVgroups, pMsgSendInfo->requestId);
|
||||
|
||||
|
@ -798,6 +799,27 @@ void tmqSendHbReq(void* param, void* tmrId) {
|
|||
SMqHbReq req = {0};
|
||||
req.consumerId = tmq->consumerId;
|
||||
req.epoch = tmq->epoch;
|
||||
// if(tmq->needReportOffsetRows){
|
||||
req.topics = taosArrayInit(taosArrayGetSize(tmq->clientTopics), sizeof(TopicOffsetRows));
|
||||
for(int i = 0; i < taosArrayGetSize(tmq->clientTopics); i++){
|
||||
SMqClientTopic* pTopic = taosArrayGet(tmq->clientTopics, i);
|
||||
int32_t numOfVgroups = taosArrayGetSize(pTopic->vgs);
|
||||
TopicOffsetRows* data = taosArrayReserve(req.topics, 1);
|
||||
strcpy(data->topicName, pTopic->topicName);
|
||||
data->offsetRows = taosArrayInit(numOfVgroups, sizeof(OffsetRows));
|
||||
for(int j = 0; j < numOfVgroups; j++){
|
||||
SMqClientVg* pVg = taosArrayGet(pTopic->vgs, j);
|
||||
OffsetRows* offRows = taosArrayReserve(data->offsetRows, 1);
|
||||
offRows->vgId = pVg->vgId;
|
||||
offRows->rows = pVg->numOfRows;
|
||||
offRows->offset = pVg->offsetInfo.currentOffset;
|
||||
char buf[TSDB_OFFSET_LEN] = {0};
|
||||
tFormatOffset(buf, TSDB_OFFSET_LEN, &offRows->offset);
|
||||
tscInfo("consumer:0x%" PRIx64 ",report offset: vgId:%d, offset:%s, rows:%"PRId64, tmq->consumerId, offRows->vgId, buf, offRows->rows);
|
||||
}
|
||||
}
|
||||
// tmq->needReportOffsetRows = false;
|
||||
// }
|
||||
|
||||
int32_t tlen = tSerializeSMqHbReq(NULL, 0, &req);
|
||||
if (tlen < 0) {
|
||||
|
@ -837,13 +859,14 @@ void tmqSendHbReq(void* param, void* tmrId) {
|
|||
asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo);
|
||||
|
||||
OVER:
|
||||
tDeatroySMqHbReq(&req);
|
||||
taosTmrReset(tmqSendHbReq, 1000, param, tmqMgmt.timer, &tmq->hbLiveTimer);
|
||||
taosReleaseRef(tmqMgmt.rsetId, refId);
|
||||
}
|
||||
|
||||
static void defaultCommitCbFn(tmq_t* pTmq, int32_t code, void* param) {
|
||||
if (code != 0) {
|
||||
tscDebug("consumer:0x%" PRIx64 ", failed to commit offset, code:%s", pTmq->consumerId, tstrerror(code));
|
||||
tscError("consumer:0x%" PRIx64 ", failed to commit offset, code:%s", pTmq->consumerId, tstrerror(code));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -971,6 +994,14 @@ int32_t tmq_subscription(tmq_t* tmq, tmq_list_t** topics) {
|
|||
}
|
||||
|
||||
int32_t tmq_unsubscribe(tmq_t* tmq) {
|
||||
if (tmq->autoCommit) {
|
||||
int32_t rsp = tmq_commit_sync(tmq, NULL);
|
||||
if (rsp != 0) {
|
||||
return rsp;
|
||||
}
|
||||
}
|
||||
taosSsleep(2); // sleep 2s for hb to send offset and rows to server
|
||||
|
||||
int32_t rsp;
|
||||
int32_t retryCnt = 0;
|
||||
tmq_list_t* lst = tmq_list_new();
|
||||
|
@ -1065,6 +1096,7 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
|
|||
pTmq->status = TMQ_CONSUMER_STATUS__INIT;
|
||||
pTmq->pollCnt = 0;
|
||||
pTmq->epoch = 0;
|
||||
// pTmq->needReportOffsetRows = true;
|
||||
|
||||
// set conf
|
||||
strcpy(pTmq->clientId, conf->clientId);
|
||||
|
@ -1109,7 +1141,7 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
|
|||
pTmq->hbLiveTimer = taosTmrStart(tmqSendHbReq, 1000, pRefId, tmqMgmt.timer);
|
||||
}
|
||||
|
||||
char buf[80] = {0};
|
||||
char buf[TSDB_OFFSET_LEN] = {0};
|
||||
STqOffsetVal offset = {.type = pTmq->resetOffsetCfg};
|
||||
tFormatOffset(buf, tListLen(buf), &offset);
|
||||
tscInfo("consumer:0x%" PRIx64 " is setup, refId:%" PRId64
|
||||
|
@ -1125,7 +1157,7 @@ _failed:
|
|||
}
|
||||
|
||||
int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
|
||||
const int32_t MAX_RETRY_COUNT = 120 * 60; // let's wait for 2 mins at most
|
||||
const int32_t MAX_RETRY_COUNT = 120 * 2; // let's wait for 2 mins at most
|
||||
const SArray* container = &topic_list->container;
|
||||
int32_t sz = taosArrayGetSize(container);
|
||||
void* buf = NULL;
|
||||
|
@ -1133,7 +1165,7 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
|
|||
SCMSubscribeReq req = {0};
|
||||
int32_t code = 0;
|
||||
|
||||
tscDebug("consumer:0x%" PRIx64 " cgroup:%s, subscribe %d topics", tmq->consumerId, tmq->groupId, sz);
|
||||
tscInfo("consumer:0x%" PRIx64 " cgroup:%s, subscribe %d topics", tmq->consumerId, tmq->groupId, sz);
|
||||
|
||||
req.consumerId = tmq->consumerId;
|
||||
tstrncpy(req.clientId, tmq->clientId, 256);
|
||||
|
@ -1145,6 +1177,11 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
|
|||
goto FAIL;
|
||||
}
|
||||
|
||||
req.withTbName = tmq->withTbName;
|
||||
req.autoCommit = tmq->autoCommit;
|
||||
req.autoCommitInterval = tmq->autoCommitInterval;
|
||||
req.resetOffsetCfg = tmq->resetOffsetCfg;
|
||||
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
char* topic = taosArrayGetP(container, i);
|
||||
|
||||
|
@ -1156,7 +1193,7 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
|
|||
}
|
||||
|
||||
tNameExtractFullName(&name, topicFName);
|
||||
tscDebug("consumer:0x%" PRIx64 " subscribe topic:%s", tmq->consumerId, topicFName);
|
||||
tscInfo("consumer:0x%" PRIx64 " subscribe topic:%s", tmq->consumerId, topicFName);
|
||||
|
||||
taosArrayPush(req.topicNames, &topicFName);
|
||||
}
|
||||
|
@ -1217,7 +1254,7 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
|
|||
goto FAIL;
|
||||
}
|
||||
|
||||
tscDebug("consumer:0x%" PRIx64 ", mnd not ready for subscribe, retry:%d in 500ms", tmq->consumerId, retryCnt);
|
||||
tscInfo("consumer:0x%" PRIx64 ", mnd not ready for subscribe, retry:%d in 500ms", tmq->consumerId, retryCnt);
|
||||
taosMsleep(500);
|
||||
}
|
||||
|
||||
|
@ -1377,8 +1414,8 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
tDecoderClear(&decoder);
|
||||
memcpy(&pRspWrapper->dataRsp, pMsg->pData, sizeof(SMqRspHead));
|
||||
|
||||
char buf[80];
|
||||
tFormatOffset(buf, 80, &pRspWrapper->dataRsp.rspOffset);
|
||||
char buf[TSDB_OFFSET_LEN];
|
||||
tFormatOffset(buf, TSDB_OFFSET_LEN, &pRspWrapper->dataRsp.rspOffset);
|
||||
tscDebug("consumer:0x%" PRIx64 " recv poll rsp, vgId:%d, req ver:%" PRId64 ", rsp:%s type %d, reqId:0x%" PRIx64,
|
||||
tmq->consumerId, vgId, pRspWrapper->dataRsp.reqOffset.version, buf, rspType, requestId);
|
||||
} else if (rspType == TMQ_MSG_TYPE__POLL_META_RSP) {
|
||||
|
@ -1428,7 +1465,8 @@ CREATE_MSG_FAIL:
|
|||
}
|
||||
|
||||
typedef struct SVgroupSaveInfo {
|
||||
STqOffsetVal offset;
|
||||
STqOffsetVal currentOffset;
|
||||
STqOffsetVal commitOffset;
|
||||
int64_t numOfRows;
|
||||
} SVgroupSaveInfo;
|
||||
|
||||
|
@ -1444,7 +1482,7 @@ static void initClientTopicFromRsp(SMqClientTopic* pTopic, SMqSubTopicEp* pTopic
|
|||
tstrncpy(pTopic->topicName, pTopicEp->topic, TSDB_TOPIC_FNAME_LEN);
|
||||
tstrncpy(pTopic->db, pTopicEp->db, TSDB_DB_FNAME_LEN);
|
||||
|
||||
tscDebug("consumer:0x%" PRIx64 ", update topic:%s, new numOfVgs:%d", tmq->consumerId, pTopic->topicName, vgNumGet);
|
||||
tscInfo("consumer:0x%" PRIx64 ", update topic:%s, new numOfVgs:%d", tmq->consumerId, pTopic->topicName, vgNumGet);
|
||||
pTopic->vgs = taosArrayInit(vgNumGet, sizeof(SMqClientVg));
|
||||
|
||||
for (int32_t j = 0; j < vgNumGet; j++) {
|
||||
|
@ -1453,12 +1491,8 @@ static void initClientTopicFromRsp(SMqClientTopic* pTopic, SMqSubTopicEp* pTopic
|
|||
makeTopicVgroupKey(vgKey, pTopic->topicName, pVgEp->vgId);
|
||||
SVgroupSaveInfo* pInfo = taosHashGet(pVgOffsetHashMap, vgKey, strlen(vgKey));
|
||||
|
||||
int64_t numOfRows = 0;
|
||||
STqOffsetVal offsetNew = {.type = tmq->resetOffsetCfg};
|
||||
if (pInfo != NULL) {
|
||||
offsetNew = pInfo->offset;
|
||||
numOfRows = pInfo->numOfRows;
|
||||
}
|
||||
STqOffsetVal offsetNew = {0};
|
||||
offsetNew.type = tmq->resetOffsetCfg;
|
||||
|
||||
SMqClientVg clientVg = {
|
||||
.pollCnt = 0,
|
||||
|
@ -1467,11 +1501,11 @@ static void initClientTopicFromRsp(SMqClientTopic* pTopic, SMqSubTopicEp* pTopic
|
|||
.vgStatus = TMQ_VG_STATUS__IDLE,
|
||||
.vgSkipCnt = 0,
|
||||
.emptyBlockReceiveTs = 0,
|
||||
.numOfRows = numOfRows,
|
||||
.numOfRows = pInfo ? pInfo->numOfRows : 0,
|
||||
};
|
||||
|
||||
clientVg.offsetInfo.currentOffset = offsetNew;
|
||||
clientVg.offsetInfo.committedOffset = offsetNew;
|
||||
clientVg.offsetInfo.currentOffset = pInfo ? pInfo->currentOffset : offsetNew;
|
||||
clientVg.offsetInfo.committedOffset = pInfo ? pInfo->commitOffset : offsetNew;
|
||||
clientVg.offsetInfo.walVerBegin = -1;
|
||||
clientVg.offsetInfo.walVerEnd = -1;
|
||||
clientVg.seekUpdated = false;
|
||||
|
@ -1497,7 +1531,7 @@ static bool doUpdateLocalEp(tmq_t* tmq, int32_t epoch, const SMqAskEpRsp* pRsp)
|
|||
int32_t topicNumGet = taosArrayGetSize(pRsp->topics);
|
||||
|
||||
char vgKey[TSDB_TOPIC_FNAME_LEN + 22];
|
||||
tscDebug("consumer:0x%" PRIx64 " update ep epoch from %d to epoch %d, incoming topics:%d, existed topics:%d",
|
||||
tscInfo("consumer:0x%" PRIx64 " update ep epoch from %d to epoch %d, incoming topics:%d, existed topics:%d",
|
||||
tmq->consumerId, tmq->epoch, epoch, topicNumGet, topicNumCur);
|
||||
if (epoch <= tmq->epoch) {
|
||||
return false;
|
||||
|
@ -1520,17 +1554,17 @@ static bool doUpdateLocalEp(tmq_t* tmq, int32_t epoch, const SMqAskEpRsp* pRsp)
|
|||
SMqClientTopic* pTopicCur = taosArrayGet(tmq->clientTopics, i);
|
||||
if (pTopicCur->vgs) {
|
||||
int32_t vgNumCur = taosArrayGetSize(pTopicCur->vgs);
|
||||
tscDebug("consumer:0x%" PRIx64 ", current vg num: %d", tmq->consumerId, vgNumCur);
|
||||
tscInfo("consumer:0x%" PRIx64 ", current vg num: %d", tmq->consumerId, vgNumCur);
|
||||
for (int32_t j = 0; j < vgNumCur; j++) {
|
||||
SMqClientVg* pVgCur = taosArrayGet(pTopicCur->vgs, j);
|
||||
makeTopicVgroupKey(vgKey, pTopicCur->topicName, pVgCur->vgId);
|
||||
|
||||
char buf[80];
|
||||
tFormatOffset(buf, 80, &pVgCur->offsetInfo.currentOffset);
|
||||
tscDebug("consumer:0x%" PRIx64 ", epoch:%d vgId:%d vgKey:%s, offset:%s", tmq->consumerId, epoch, pVgCur->vgId,
|
||||
char buf[TSDB_OFFSET_LEN];
|
||||
tFormatOffset(buf, TSDB_OFFSET_LEN, &pVgCur->offsetInfo.currentOffset);
|
||||
tscInfo("consumer:0x%" PRIx64 ", epoch:%d vgId:%d vgKey:%s, offset:%s", tmq->consumerId, epoch, pVgCur->vgId,
|
||||
vgKey, buf);
|
||||
|
||||
SVgroupSaveInfo info = {.offset = pVgCur->offsetInfo.currentOffset, .numOfRows = pVgCur->numOfRows};
|
||||
SVgroupSaveInfo info = {.currentOffset = pVgCur->offsetInfo.currentOffset, .commitOffset = pVgCur->offsetInfo.committedOffset, .numOfRows = pVgCur->numOfRows};
|
||||
taosHashPut(pVgOffsetHashMap, vgKey, strlen(vgKey), &info, sizeof(SVgroupSaveInfo));
|
||||
}
|
||||
}
|
||||
|
@ -1557,7 +1591,7 @@ static bool doUpdateLocalEp(tmq_t* tmq, int32_t epoch, const SMqAskEpRsp* pRsp)
|
|||
atomic_store_8(&tmq->status, flag);
|
||||
atomic_store_32(&tmq->epoch, epoch);
|
||||
|
||||
tscDebug("consumer:0x%" PRIx64 " update topic info completed", tmq->consumerId);
|
||||
tscInfo("consumer:0x%" PRIx64 " update topic info completed", tmq->consumerId);
|
||||
return set;
|
||||
}
|
||||
|
||||
|
@ -1593,7 +1627,7 @@ int32_t askEpCallbackFn(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
SMqRspHead* head = pMsg->pData;
|
||||
int32_t epoch = atomic_load_32(&tmq->epoch);
|
||||
if (head->epoch <= epoch) {
|
||||
tscDebug("consumer:0x%" PRIx64 ", recv ep, msg epoch %d, current epoch %d, no need to update local ep",
|
||||
tscInfo("consumer:0x%" PRIx64 ", recv ep, msg epoch %d, current epoch %d, no need to update local ep",
|
||||
tmq->consumerId, head->epoch, epoch);
|
||||
|
||||
if (tmq->status == TMQ_CONSUMER_STATUS__RECOVER) {
|
||||
|
@ -1605,7 +1639,7 @@ int32_t askEpCallbackFn(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
}
|
||||
|
||||
} else {
|
||||
tscDebug("consumer:0x%" PRIx64 ", recv ep, msg epoch %d, current epoch %d, update local ep", tmq->consumerId,
|
||||
tscInfo("consumer:0x%" PRIx64 ", recv ep, msg epoch %d, current epoch %d, update local ep", tmq->consumerId,
|
||||
head->epoch, epoch);
|
||||
}
|
||||
|
||||
|
@ -1675,7 +1709,7 @@ SMqRspObj* tmqBuildRspFromWrapper(SMqPollRspWrapper* pWrapper, SMqClientVg* pVg,
|
|||
return pRspObj;
|
||||
}
|
||||
|
||||
SMqTaosxRspObj* tmqBuildTaosxRspFromWrapper(SMqPollRspWrapper* pWrapper) {
|
||||
SMqTaosxRspObj* tmqBuildTaosxRspFromWrapper(SMqPollRspWrapper* pWrapper, SMqClientVg* pVg, int64_t* numOfRows) {
|
||||
SMqTaosxRspObj* pRspObj = taosMemoryCalloc(1, sizeof(SMqTaosxRspObj));
|
||||
pRspObj->resType = RES_TYPE__TMQ_METADATA;
|
||||
tstrncpy(pRspObj->topic, pWrapper->topicHandle->topicName, TSDB_TOPIC_FNAME_LEN);
|
||||
|
@ -1690,6 +1724,13 @@ SMqTaosxRspObj* tmqBuildTaosxRspFromWrapper(SMqPollRspWrapper* pWrapper) {
|
|||
setResSchemaInfo(&pRspObj->resInfo, pWrapper->topicHandle->schema.pSchema, pWrapper->topicHandle->schema.nCols);
|
||||
}
|
||||
|
||||
// extract the rows in this data packet
|
||||
for (int32_t i = 0; i < pRspObj->rsp.blockNum; ++i) {
|
||||
SRetrieveTableRsp* pRetrieve = (SRetrieveTableRsp*)taosArrayGetP(pRspObj->rsp.blockData, i);
|
||||
int64_t rows = htobe64(pRetrieve->numOfRows);
|
||||
pVg->numOfRows += rows;
|
||||
(*numOfRows) += rows;
|
||||
}
|
||||
return pRspObj;
|
||||
}
|
||||
|
||||
|
@ -1747,7 +1788,7 @@ static int32_t doTmqPollImpl(tmq_t* pTmq, SMqClientTopic* pTopic, SMqClientVg* p
|
|||
sendInfo->msgType = TDMT_VND_TMQ_CONSUME;
|
||||
|
||||
int64_t transporterId = 0;
|
||||
char offsetFormatBuf[80];
|
||||
char offsetFormatBuf[TSDB_OFFSET_LEN];
|
||||
tFormatOffset(offsetFormatBuf, tListLen(offsetFormatBuf), &pVg->offsetInfo.currentOffset);
|
||||
|
||||
tscDebug("consumer:0x%" PRIx64 " send poll to %s vgId:%d, epoch %d, req:%s, reqId:0x%" PRIx64, pTmq->consumerId,
|
||||
|
@ -1884,11 +1925,11 @@ static void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) {
|
|||
pVg->offsetInfo.walVerEnd = pDataRsp->head.walever;
|
||||
pVg->receivedInfoFromVnode = true;
|
||||
|
||||
char buf[80];
|
||||
tFormatOffset(buf, 80, &pDataRsp->rspOffset);
|
||||
char buf[TSDB_OFFSET_LEN];
|
||||
tFormatOffset(buf, TSDB_OFFSET_LEN, &pDataRsp->rspOffset);
|
||||
if (pDataRsp->blockNum == 0) {
|
||||
tscDebug("consumer:0x%" PRIx64 " empty block received, vgId:%d, offset:%s, vg total:%" PRId64
|
||||
" total:%" PRId64 " reqId:0x%" PRIx64,
|
||||
", total:%" PRId64 ", reqId:0x%" PRIx64,
|
||||
tmq->consumerId, pVg->vgId, buf, pVg->numOfRows, tmq->totalRows, pollRspWrapper->reqId);
|
||||
pRspWrapper = tmqFreeRspWrapper(pRspWrapper);
|
||||
pVg->emptyBlockReceiveTs = taosGetTimestampMs();
|
||||
|
@ -1899,7 +1940,7 @@ static void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) {
|
|||
tmq->totalRows += numOfRows;
|
||||
pVg->emptyBlockReceiveTs = 0;
|
||||
tscDebug("consumer:0x%" PRIx64 " process poll rsp, vgId:%d, offset:%s, blocks:%d, rows:%" PRId64
|
||||
" vg total:%" PRId64 " total:%" PRId64 ", reqId:0x%" PRIx64,
|
||||
", vg total:%" PRId64 ", total:%" PRId64 ", reqId:0x%" PRIx64,
|
||||
tmq->consumerId, pVg->vgId, buf, pDataRsp->blockNum, numOfRows, pVg->numOfRows, tmq->totalRows,
|
||||
pollRspWrapper->reqId);
|
||||
taosFreeQitem(pollRspWrapper);
|
||||
|
@ -1971,7 +2012,7 @@ static void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) {
|
|||
atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE);
|
||||
|
||||
if (pollRspWrapper->taosxRsp.blockNum == 0) {
|
||||
tscDebug("consumer:0x%" PRIx64 " taosx empty block received, vgId:%d, vg total:%" PRId64 " reqId:0x%" PRIx64,
|
||||
tscDebug("consumer:0x%" PRIx64 " taosx empty block received, vgId:%d, vg total:%" PRId64 ", reqId:0x%" PRIx64,
|
||||
tmq->consumerId, pVg->vgId, pVg->numOfRows, pollRspWrapper->reqId);
|
||||
pVg->emptyBlockReceiveTs = taosGetTimestampMs();
|
||||
pRspWrapper = tmqFreeRspWrapper(pRspWrapper);
|
||||
|
@ -1987,15 +2028,15 @@ static void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) {
|
|||
if (pollRspWrapper->taosxRsp.createTableNum == 0) {
|
||||
pRsp = tmqBuildRspFromWrapper(pollRspWrapper, pVg, &numOfRows);
|
||||
} else {
|
||||
pRsp = tmqBuildTaosxRspFromWrapper(pollRspWrapper);
|
||||
pRsp = tmqBuildTaosxRspFromWrapper(pollRspWrapper, pVg, &numOfRows);
|
||||
}
|
||||
|
||||
tmq->totalRows += numOfRows;
|
||||
|
||||
char buf[80];
|
||||
tFormatOffset(buf, 80, &pVg->offsetInfo.currentOffset);
|
||||
char buf[TSDB_OFFSET_LEN];
|
||||
tFormatOffset(buf, TSDB_OFFSET_LEN, &pVg->offsetInfo.currentOffset);
|
||||
tscDebug("consumer:0x%" PRIx64 " process taosx poll rsp, vgId:%d, offset:%s, blocks:%d, rows:%" PRId64
|
||||
", vg total:%" PRId64 " total:%" PRId64 " reqId:0x%" PRIx64,
|
||||
", vg total:%" PRId64 ", total:%" PRId64 ", reqId:0x%" PRIx64,
|
||||
tmq->consumerId, pVg->vgId, buf, pollRspWrapper->dataRsp.blockNum, numOfRows, pVg->numOfRows,
|
||||
tmq->totalRows, pollRspWrapper->reqId);
|
||||
|
||||
|
@ -2026,12 +2067,12 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t timeout) {
|
|||
void* rspObj;
|
||||
int64_t startTime = taosGetTimestampMs();
|
||||
|
||||
tscDebug("consumer:0x%" PRIx64 " start to poll at %" PRId64 ", timeout:%" PRId64, tmq->consumerId, startTime,
|
||||
tscInfo("consumer:0x%" PRIx64 " start to poll at %" PRId64 ", timeout:%" PRId64, tmq->consumerId, startTime,
|
||||
timeout);
|
||||
|
||||
// in no topic status, delayed task also need to be processed
|
||||
if (atomic_load_8(&tmq->status) == TMQ_CONSUMER_STATUS__INIT) {
|
||||
tscDebug("consumer:0x%" PRIx64 " poll return since consumer is init", tmq->consumerId);
|
||||
tscInfo("consumer:0x%" PRIx64 " poll return since consumer is init", tmq->consumerId);
|
||||
taosMsleep(500); // sleep for a while
|
||||
return NULL;
|
||||
}
|
||||
|
@ -2043,7 +2084,7 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t timeout) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
tscDebug("consumer:0x%" PRIx64 " not ready, retry:%d/40 in 500ms", tmq->consumerId, retryCnt);
|
||||
tscInfo("consumer:0x%" PRIx64 " not ready, retry:%d/40 in 500ms", tmq->consumerId, retryCnt);
|
||||
taosMsleep(500);
|
||||
}
|
||||
}
|
||||
|
@ -2052,7 +2093,7 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t timeout) {
|
|||
tmqHandleAllDelayedTask(tmq);
|
||||
|
||||
if (tmqPollImpl(tmq, timeout) < 0) {
|
||||
tscDebug("consumer:0x%" PRIx64 " return due to poll error", tmq->consumerId);
|
||||
tscError("consumer:0x%" PRIx64 " return due to poll error", tmq->consumerId);
|
||||
}
|
||||
|
||||
rspObj = tmqHandleAllRsp(tmq, timeout, false);
|
||||
|
@ -2060,7 +2101,7 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t timeout) {
|
|||
tscDebug("consumer:0x%" PRIx64 " return rsp %p", tmq->consumerId, rspObj);
|
||||
return (TAOS_RES*)rspObj;
|
||||
} else if (terrno == TSDB_CODE_TQ_NO_COMMITTED_OFFSET) {
|
||||
tscDebug("consumer:0x%" PRIx64 " return null since no committed offset", tmq->consumerId);
|
||||
tscInfo("consumer:0x%" PRIx64 " return null since no committed offset", tmq->consumerId);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -2068,7 +2109,7 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t timeout) {
|
|||
int64_t currentTime = taosGetTimestampMs();
|
||||
int64_t elapsedTime = currentTime - startTime;
|
||||
if (elapsedTime > timeout) {
|
||||
tscDebug("consumer:0x%" PRIx64 " (epoch %d) timeout, no rsp, start time %" PRId64 ", current time %" PRId64,
|
||||
tscInfo("consumer:0x%" PRIx64 " (epoch %d) timeout, no rsp, start time %" PRId64 ", current time %" PRId64,
|
||||
tmq->consumerId, tmq->epoch, startTime, currentTime);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -2101,7 +2142,7 @@ static void displayConsumeStatistics(const tmq_t* pTmq) {
|
|||
}
|
||||
|
||||
int32_t tmq_consumer_close(tmq_t* tmq) {
|
||||
tscDebug("consumer:0x%" PRIx64 " start to close consumer, status:%d", tmq->consumerId, tmq->status);
|
||||
tscInfo("consumer:0x%" PRIx64 " start to close consumer, status:%d", tmq->consumerId, tmq->status);
|
||||
displayConsumeStatistics(tmq);
|
||||
|
||||
if (tmq->status == TMQ_CONSUMER_STATUS__READY) {
|
||||
|
@ -2112,6 +2153,7 @@ int32_t tmq_consumer_close(tmq_t* tmq) {
|
|||
return rsp;
|
||||
}
|
||||
}
|
||||
taosSsleep(2); // sleep 2s for hb to send offset and rows to server
|
||||
|
||||
int32_t retryCnt = 0;
|
||||
tmq_list_t* lst = tmq_list_new();
|
||||
|
@ -2127,7 +2169,7 @@ int32_t tmq_consumer_close(tmq_t* tmq) {
|
|||
|
||||
tmq_list_destroy(lst);
|
||||
} else {
|
||||
tscWarn("consumer:0x%" PRIx64 " not in ready state, close it directly", tmq->consumerId);
|
||||
tscInfo("consumer:0x%" PRIx64 " not in ready state, close it directly", tmq->consumerId);
|
||||
}
|
||||
|
||||
taosRemoveRef(tmqMgmt.rsetId, tmq->refId);
|
||||
|
@ -2390,7 +2432,7 @@ void asyncAskEp(tmq_t* pTmq, __tmq_askep_fn_t askEpFn, void* param) {
|
|||
sendInfo->msgType = TDMT_MND_TMQ_ASK_EP;
|
||||
|
||||
SEpSet epSet = getEpSet_s(&pTmq->pTscObj->pAppInfo->mgmtEp);
|
||||
tscDebug("consumer:0x%" PRIx64 " ask ep from mnode, reqId:0x%" PRIx64, pTmq->consumerId, sendInfo->requestId);
|
||||
tscInfo("consumer:0x%" PRIx64 " ask ep from mnode, reqId:0x%" PRIx64, pTmq->consumerId, sendInfo->requestId);
|
||||
|
||||
int64_t transporterId = 0;
|
||||
asyncSendMsgToServer(pTmq->pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo);
|
||||
|
@ -2413,6 +2455,7 @@ int32_t tmqCommitDone(SMqCommitCbParamSet* pParamSet) {
|
|||
// if no more waiting rsp
|
||||
pParamSet->callbackFn(tmq, pParamSet->code, pParamSet->userParam);
|
||||
taosMemoryFree(pParamSet);
|
||||
// tmq->needReportOffsetRows = true;
|
||||
|
||||
taosReleaseRef(tmqMgmt.rsetId, refId);
|
||||
return 0;
|
||||
|
@ -2610,10 +2653,10 @@ int32_t tmq_get_topic_assignment(tmq_t* tmq, const char* pTopicName, tmq_topic_a
|
|||
sendInfo->msgType = TDMT_VND_TMQ_VG_WALINFO;
|
||||
|
||||
int64_t transporterId = 0;
|
||||
char offsetFormatBuf[80];
|
||||
char offsetFormatBuf[TSDB_OFFSET_LEN];
|
||||
tFormatOffset(offsetFormatBuf, tListLen(offsetFormatBuf), &pClientVg->offsetInfo.currentOffset);
|
||||
|
||||
tscDebug("consumer:0x%" PRIx64 " %s retrieve wal info vgId:%d, epoch %d, req:%s, reqId:0x%" PRIx64,
|
||||
tscInfo("consumer:0x%" PRIx64 " %s retrieve wal info vgId:%d, epoch %d, req:%s, reqId:0x%" PRIx64,
|
||||
tmq->consumerId, pTopic->topicName, pClientVg->vgId, tmq->epoch, offsetFormatBuf, req.reqId);
|
||||
asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &pClientVg->epSet, &transporterId, sendInfo);
|
||||
}
|
||||
|
@ -2647,10 +2690,10 @@ int32_t tmq_get_topic_assignment(tmq_t* tmq, const char* pTopicName, tmq_topic_a
|
|||
|
||||
pOffsetInfo->currentOffset.type = TMQ_OFFSET__LOG;
|
||||
|
||||
char offsetBuf[80] = {0};
|
||||
char offsetBuf[TSDB_OFFSET_LEN] = {0};
|
||||
tFormatOffset(offsetBuf, tListLen(offsetBuf), &pOffsetInfo->currentOffset);
|
||||
|
||||
tscDebug("vgId:%d offset is update to:%s", p->vgId, offsetBuf);
|
||||
tscInfo("vgId:%d offset is update to:%s", p->vgId, offsetBuf);
|
||||
|
||||
pOffsetInfo->walVerBegin = p->begin;
|
||||
pOffsetInfo->walVerEnd = p->end;
|
||||
|
@ -2729,7 +2772,7 @@ int32_t tmq_offset_seek(tmq_t* tmq, const char* pTopicName, int32_t vgId, int64_
|
|||
SMqRspObj rspObj = {.resType = RES_TYPE__TMQ, .vgId = pVg->vgId};
|
||||
tstrncpy(rspObj.topic, tname, tListLen(rspObj.topic));
|
||||
|
||||
tscDebug("consumer:0x%" PRIx64 " seek to %" PRId64 " on vgId:%d", tmq->consumerId, offset, pVg->vgId);
|
||||
tscInfo("consumer:0x%" PRIx64 " seek to %" PRId64 " on vgId:%d", tmq->consumerId, offset, pVg->vgId);
|
||||
|
||||
SSyncCommitInfo* pInfo = taosMemoryMalloc(sizeof(SSyncCommitInfo));
|
||||
if (pInfo == NULL) {
|
||||
|
|
|
@ -291,6 +291,8 @@ static const SSysDbTableSchema subscriptionSchema[] = {
|
|||
{.name = "consumer_group", .bytes = TSDB_CGROUP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY, .sysInfo = false},
|
||||
{.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
|
||||
{.name = "consumer_id", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY, .sysInfo = false},
|
||||
{.name = "offset", .bytes = TSDB_OFFSET_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY, .sysInfo = false},
|
||||
{.name = "rows", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = false},
|
||||
};
|
||||
|
||||
static const SSysDbTableSchema vnodesSchema[] = {
|
||||
|
@ -359,6 +361,7 @@ static const SSysDbTableSchema consumerSchema[] = {
|
|||
{.name = "up_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false},
|
||||
{.name = "subscribe_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false},
|
||||
{.name = "rebalance_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false},
|
||||
{.name = "parameters", .bytes = 64 + TSDB_OFFSET_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY, .sysInfo = false},
|
||||
};
|
||||
|
||||
static const SSysDbTableSchema offsetSchema[] = {
|
||||
|
@ -381,6 +384,7 @@ static const SSysDbTableSchema querySchema[] = {
|
|||
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false},
|
||||
{.name = "exec_usec", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = false},
|
||||
{.name = "stable_query", .bytes = 1, .type = TSDB_DATA_TYPE_BOOL, .sysInfo = false},
|
||||
{.name = "sub_query", .bytes = 1, .type = TSDB_DATA_TYPE_BOOL, .sysInfo = false},
|
||||
{.name = "sub_num", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
|
||||
{.name = "sub_status", .bytes = TSDB_SHOW_SUBQUERY_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
{.name = "sql", .bytes = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
|
|
|
@ -47,6 +47,17 @@ int32_t colDataGetLength(const SColumnInfoData* pColumnInfoData, int32_t numOfRo
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
int32_t colDataGetRowLength(const SColumnInfoData* pColumnInfoData, int32_t rowIdx) {
|
||||
if (colDataIsNull_s(pColumnInfoData, rowIdx)) return 0;
|
||||
|
||||
if (!IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) return pColumnInfoData->info.bytes;
|
||||
if (pColumnInfoData->info.type == TSDB_DATA_TYPE_JSON)
|
||||
return getJsonValueLen(colDataGetData(pColumnInfoData, rowIdx));
|
||||
else
|
||||
return varDataTLen(colDataGetData(pColumnInfoData, rowIdx));
|
||||
}
|
||||
|
||||
int32_t colDataGetFullLength(const SColumnInfoData* pColumnInfoData, int32_t numOfRows) {
|
||||
if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) {
|
||||
return pColumnInfoData->varmeta.length + sizeof(int32_t) * numOfRows;
|
||||
|
@ -791,8 +802,8 @@ size_t blockDataGetRowSize(SSDataBlock* pBlock) {
|
|||
* @return
|
||||
*/
|
||||
size_t blockDataGetSerialMetaSize(uint32_t numOfCols) {
|
||||
// | version | total length | total rows | total columns | flag seg| block group id | column schema | each column
|
||||
// length |
|
||||
// | version | total length | total rows | total columns | flag seg| block group id | column schema
|
||||
// | each column length |
|
||||
return sizeof(int32_t) + sizeof(int32_t) + sizeof(int32_t) + sizeof(int32_t) + sizeof(int32_t) + sizeof(uint64_t) +
|
||||
numOfCols * (sizeof(int8_t) + sizeof(int32_t)) + numOfCols * sizeof(int32_t);
|
||||
}
|
||||
|
@ -2483,19 +2494,31 @@ _end:
|
|||
}
|
||||
|
||||
char* buildCtbNameByGroupId(const char* stbFullName, uint64_t groupId) {
|
||||
if (stbFullName[0] == 0) {
|
||||
char* pBuf = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN + 1);
|
||||
if (!pBuf) {
|
||||
return NULL;
|
||||
}
|
||||
int32_t code = buildCtbNameByGroupIdImpl(stbFullName, groupId, pBuf);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
taosMemoryFree(pBuf);
|
||||
return NULL;
|
||||
}
|
||||
return pBuf;
|
||||
}
|
||||
|
||||
int32_t buildCtbNameByGroupIdImpl(const char* stbFullName, uint64_t groupId, char* cname) {
|
||||
if (stbFullName[0] == 0) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
SArray* tags = taosArrayInit(0, sizeof(SSmlKv));
|
||||
if (tags == NULL) {
|
||||
return NULL;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
void* cname = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN + 1);
|
||||
if (cname == NULL) {
|
||||
taosArrayDestroy(tags);
|
||||
return NULL;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
SSmlKv pTag = {.key = "group_id",
|
||||
|
@ -2517,9 +2540,9 @@ char* buildCtbNameByGroupId(const char* stbFullName, uint64_t groupId) {
|
|||
taosArrayDestroy(tags);
|
||||
|
||||
if ((rname.ctbShortName && rname.ctbShortName[0]) == 0) {
|
||||
return NULL;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
return rname.ctbShortName;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t blockEncode(const SSDataBlock* pBlock, char* data, int32_t numOfCols) {
|
||||
|
|
|
@ -62,6 +62,7 @@ int32_t tsNumOfQnodeFetchThreads = 1;
|
|||
int32_t tsNumOfSnodeStreamThreads = 4;
|
||||
int32_t tsNumOfSnodeWriteThreads = 1;
|
||||
int32_t tsMaxStreamBackendCache = 128; // M
|
||||
int32_t tsPQSortMemThreshold = 16; // M
|
||||
|
||||
// sync raft
|
||||
int32_t tsElectInterval = 25 * 1000;
|
||||
|
@ -75,6 +76,7 @@ int64_t tsVndCommitMaxIntervalMs = 600 * 1000;
|
|||
int64_t tsMndSdbWriteDelta = 200;
|
||||
int64_t tsMndLogRetention = 2000;
|
||||
int8_t tsGrant = 1;
|
||||
bool tsMndSkipGrant = false;
|
||||
|
||||
// monitor
|
||||
bool tsEnableMonitor = true;
|
||||
|
@ -111,6 +113,7 @@ int32_t tsQueryRspPolicy = 0;
|
|||
int64_t tsQueryMaxConcurrentTables = 200; // unit is TSDB_TABLE_NUM_UNIT
|
||||
bool tsEnableQueryHb = false;
|
||||
bool tsEnableScience = false; // on taos-cli show float and doulbe with scientific notation if true
|
||||
bool tsTtlChangeOnWrite = false; // ttl delete time changes on last write if true
|
||||
int32_t tsQuerySmaOptimize = 0;
|
||||
int32_t tsQueryRsmaTolerance = 1000; // the tolerance time (ms) to judge from which level to query rsma data.
|
||||
bool tsQueryPlannerTrace = false;
|
||||
|
@ -495,6 +498,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
|
|||
|
||||
if (cfgAddInt64(pCfg, "mndSdbWriteDelta", tsMndSdbWriteDelta, 20, 10000, 0) != 0) return -1;
|
||||
if (cfgAddInt64(pCfg, "mndLogRetention", tsMndLogRetention, 500, 10000, 0) != 0) return -1;
|
||||
if (cfgAddBool(pCfg, "skipGrant", tsMndSkipGrant, 0) != 0) return -1;
|
||||
|
||||
if (cfgAddBool(pCfg, "monitor", tsEnableMonitor, 0) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "monitorInterval", tsMonitorInterval, 1, 200000, 0) != 0) return -1;
|
||||
|
@ -515,6 +519,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
|
|||
if (cfgAddInt32(pCfg, "mqRebalanceInterval", tsMqRebalanceInterval, 1, 10000, 1) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "ttlUnit", tsTtlUnit, 1, 86400 * 365, 1) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "ttlPushInterval", tsTtlPushInterval, 1, 100000, 1) != 0) return -1;
|
||||
if (cfgAddBool(pCfg, "ttlChangeOnWrite", tsTtlChangeOnWrite, 0) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "uptimeInterval", tsUptimeInterval, 1, 100000, 1) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "queryRsmaTolerance", tsQueryRsmaTolerance, 0, 900000, 0) != 0) return -1;
|
||||
|
||||
|
@ -533,6 +538,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
|
|||
|
||||
if (cfgAddBool(pCfg, "filterScalarMode", tsFilterScalarMode, 0) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "maxStreamBackendCache", tsMaxStreamBackendCache, 16, 1024, 0) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "pqSortMemThreshold", tsPQSortMemThreshold, 1, 10240, 0) != 0) return -1;
|
||||
|
||||
GRANT_CFG_ADD;
|
||||
return 0;
|
||||
|
@ -875,6 +881,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
|
|||
|
||||
tsEnableTelem = cfgGetItem(pCfg, "telemetryReporting")->bval;
|
||||
tsEnableCrashReport = cfgGetItem(pCfg, "crashReporting")->bval;
|
||||
tsTtlChangeOnWrite = cfgGetItem(pCfg, "ttlChangeOnWrite")->bval;
|
||||
tsTelemInterval = cfgGetItem(pCfg, "telemetryInterval")->i32;
|
||||
tstrncpy(tsTelemServer, cfgGetItem(pCfg, "telemetryServer")->str, TSDB_FQDN_LEN);
|
||||
tsTelemPort = (uint16_t)cfgGetItem(pCfg, "telemetryPort")->i32;
|
||||
|
@ -898,6 +905,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
|
|||
|
||||
tsMndSdbWriteDelta = cfgGetItem(pCfg, "mndSdbWriteDelta")->i64;
|
||||
tsMndLogRetention = cfgGetItem(pCfg, "mndLogRetention")->i64;
|
||||
tsMndSkipGrant = cfgGetItem(pCfg, "skipGrant")->bval;
|
||||
|
||||
tsStartUdfd = cfgGetItem(pCfg, "udf")->bval;
|
||||
tstrncpy(tsUdfdResFuncs, cfgGetItem(pCfg, "udfdResFuncs")->str, sizeof(tsUdfdResFuncs));
|
||||
|
@ -914,6 +922,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
|
|||
|
||||
tsFilterScalarMode = cfgGetItem(pCfg, "filterScalarMode")->bval;
|
||||
tsMaxStreamBackendCache = cfgGetItem(pCfg, "maxStreamBackendCache")->i32;
|
||||
tsPQSortMemThreshold = cfgGetItem(pCfg, "pqSortMemThreshold")->i32;
|
||||
|
||||
GRANT_CFG_GET;
|
||||
return 0;
|
||||
|
@ -981,6 +990,8 @@ int32_t taosApplyLocalCfg(SConfig *pCfg, char *name) {
|
|||
taosSetCoreDump(enableCore);
|
||||
} else if (strcasecmp("enableQueryHb", name) == 0) {
|
||||
tsEnableQueryHb = cfgGetItem(pCfg, "enableQueryHb")->bval;
|
||||
} else if (strcasecmp("ttlChangeOnWrite", name) == 0) {
|
||||
tsTtlChangeOnWrite = cfgGetItem(pCfg, "ttlChangeOnWrite")->bval;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -30,6 +30,9 @@
|
|||
|
||||
#include "tlog.h"
|
||||
|
||||
static int32_t tDecodeSVAlterTbReqCommon(SDecoder *pDecoder, SVAlterTbReq *pReq);
|
||||
static int32_t tDecodeSBatchDeleteReqCommon(SDecoder *pDecoder, SBatchDeleteReq *pReq);
|
||||
|
||||
int32_t tInitSubmitMsgIter(const SSubmitReq *pMsg, SSubmitMsgIter *pIter) {
|
||||
if (pMsg == NULL) {
|
||||
terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP;
|
||||
|
@ -224,6 +227,7 @@ static int32_t tSerializeSClientHbReq(SEncoder *pEncoder, const SClientHbReq *pR
|
|||
if (tEncodeI64(pEncoder, desc->stime) < 0) return -1;
|
||||
if (tEncodeI64(pEncoder, desc->reqRid) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, desc->stableQuery) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, desc->isSubQuery) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, desc->fqdn) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, desc->subPlanNum) < 0) return -1;
|
||||
|
||||
|
@ -291,6 +295,7 @@ static int32_t tDeserializeSClientHbReq(SDecoder *pDecoder, SClientHbReq *pReq)
|
|||
if (tDecodeI64(pDecoder, &desc.stime) < 0) return -1;
|
||||
if (tDecodeI64(pDecoder, &desc.reqRid) < 0) return -1;
|
||||
if (tDecodeI8(pDecoder, (int8_t *)&desc.stableQuery) < 0) return -1;
|
||||
if (tDecodeI8(pDecoder, (int8_t *)&desc.isSubQuery) < 0) return -1;
|
||||
if (tDecodeCStrTo(pDecoder, desc.fqdn) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &desc.subPlanNum) < 0) return -1;
|
||||
|
||||
|
@ -1723,7 +1728,7 @@ int32_t tDeserializeSDropDnodeReq(void *buf, int32_t bufLen, SDropDnodeReq *pReq
|
|||
} else {
|
||||
pReq->unsafe = false;
|
||||
}
|
||||
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
|
@ -3159,7 +3164,7 @@ int32_t tSerializeSVDropTtlTableReq(void *buf, int32_t bufLen, SVDropTtlTableReq
|
|||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->timestamp) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->timestampSec) < 0) return -1;
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
|
@ -3172,7 +3177,7 @@ int32_t tDeserializeSVDropTtlTableReq(void *buf, int32_t bufLen, SVDropTtlTableR
|
|||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->timestamp) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->timestampSec) < 0) return -1;
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
|
@ -3740,8 +3745,8 @@ int32_t tSerializeSSTbHbRsp(void *buf, int32_t bufLen, SSTbHbRsp *pRsp) {
|
|||
if (tEncodeI32(&encoder, pIndexRsp->indexSize) < 0) return -1;
|
||||
int32_t num = taosArrayGetSize(pIndexRsp->pIndex);
|
||||
if (tEncodeI32(&encoder, num) < 0) return -1;
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
STableIndexInfo *pInfo = (STableIndexInfo *)taosArrayGet(pIndexRsp->pIndex, i);
|
||||
for (int32_t j = 0; j < num; ++j) {
|
||||
STableIndexInfo *pInfo = (STableIndexInfo *)taosArrayGet(pIndexRsp->pIndex, j);
|
||||
if (tSerializeSTableIndexInfo(&encoder, pInfo) < 0) return -1;
|
||||
}
|
||||
}
|
||||
|
@ -3807,7 +3812,7 @@ int32_t tDeserializeSSTbHbRsp(void *buf, int32_t bufLen, SSTbHbRsp *pRsp) {
|
|||
tableIndexRsp.pIndex = taosArrayInit(num, sizeof(STableIndexInfo));
|
||||
if (NULL == tableIndexRsp.pIndex) return -1;
|
||||
STableIndexInfo info;
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
for (int32_t j = 0; j < num; ++j) {
|
||||
if (tDeserializeSTableIndexInfo(&decoder, &info) < 0) return -1;
|
||||
if (NULL == taosArrayPush(tableIndexRsp.pIndex, &info)) {
|
||||
taosMemoryFree(info.expr);
|
||||
|
@ -4669,7 +4674,7 @@ int32_t tDeserializeSAlterVnodeReplicaReq(void *buf, int32_t bufLen, SAlterVnode
|
|||
if (tDecodeSReplica(&decoder, pReplica) < 0) return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
tEndDecode(&decoder);
|
||||
tDecoderClear(&decoder);
|
||||
return 0;
|
||||
|
@ -5338,6 +5343,15 @@ int32_t tDeserializeSMqAskEpReq(void *buf, int32_t bufLen, SMqAskEpReq *pReq) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDeatroySMqHbReq(SMqHbReq* pReq){
|
||||
for(int i = 0; i < taosArrayGetSize(pReq->topics); i++){
|
||||
TopicOffsetRows* vgs = taosArrayGet(pReq->topics, i);
|
||||
if(vgs) taosArrayDestroy(vgs->offsetRows);
|
||||
}
|
||||
taosArrayDestroy(pReq->topics);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tSerializeSMqHbReq(void *buf, int32_t bufLen, SMqHbReq *pReq) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
@ -5346,6 +5360,21 @@ int32_t tSerializeSMqHbReq(void *buf, int32_t bufLen, SMqHbReq *pReq) {
|
|||
if (tEncodeI64(&encoder, pReq->consumerId) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->epoch) < 0) return -1;
|
||||
|
||||
int32_t sz = taosArrayGetSize(pReq->topics);
|
||||
if (tEncodeI32(&encoder, sz) < 0) return -1;
|
||||
for (int32_t i = 0; i < sz; ++i) {
|
||||
TopicOffsetRows* vgs = (TopicOffsetRows*)taosArrayGet(pReq->topics, i);
|
||||
if (tEncodeCStr(&encoder, vgs->topicName) < 0) return -1;
|
||||
int32_t szVgs = taosArrayGetSize(vgs->offsetRows);
|
||||
if (tEncodeI32(&encoder, szVgs) < 0) return -1;
|
||||
for (int32_t j = 0; j < szVgs; ++j) {
|
||||
OffsetRows *offRows = taosArrayGet(vgs->offsetRows, j);
|
||||
if (tEncodeI32(&encoder, offRows->vgId) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, offRows->rows) < 0) return -1;
|
||||
if (tEncodeSTqOffsetVal(&encoder, &offRows->offset) < 0) return -1;
|
||||
}
|
||||
}
|
||||
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
|
@ -5362,7 +5391,28 @@ int32_t tDeserializeSMqHbReq(void *buf, int32_t bufLen, SMqHbReq *pReq) {
|
|||
|
||||
if (tDecodeI64(&decoder, &pReq->consumerId) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->epoch) < 0) return -1;
|
||||
|
||||
int32_t sz = 0;
|
||||
if (tDecodeI32(&decoder, &sz) < 0) return -1;
|
||||
if(sz > 0){
|
||||
pReq->topics = taosArrayInit(sz, sizeof(TopicOffsetRows));
|
||||
if (NULL == pReq->topics) return -1;
|
||||
for (int32_t i = 0; i < sz; ++i) {
|
||||
TopicOffsetRows* data = taosArrayReserve(pReq->topics, 1);
|
||||
tDecodeCStrTo(&decoder, data->topicName);
|
||||
int32_t szVgs = 0;
|
||||
if (tDecodeI32(&decoder, &szVgs) < 0) return -1;
|
||||
if(szVgs > 0){
|
||||
data->offsetRows = taosArrayInit(szVgs, sizeof(OffsetRows));
|
||||
if (NULL == data->offsetRows) return -1;
|
||||
for (int32_t j= 0; j < szVgs; ++j) {
|
||||
OffsetRows* offRows = taosArrayReserve(data->offsetRows, 1);
|
||||
if (tDecodeI32(&decoder, &offRows->vgId) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &offRows->rows) < 0) return -1;
|
||||
if (tDecodeSTqOffsetVal(&decoder, &offRows->offset) < 0) return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
|
@ -6122,6 +6172,7 @@ int32_t tSerializeSCMCreateStreamReq(void *buf, int32_t bufLen, const SCMCreateS
|
|||
}
|
||||
if (tEncodeI64(&encoder, pReq->deleteMark) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pReq->igUpdate) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pReq->lastTs) < 0) return -1;
|
||||
|
||||
tEndEncode(&encoder);
|
||||
|
||||
|
@ -6207,6 +6258,7 @@ int32_t tDeserializeSCMCreateStreamReq(void *buf, int32_t bufLen, SCMCreateStrea
|
|||
|
||||
if (tDecodeI64(&decoder, &pReq->deleteMark) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &pReq->igUpdate) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pReq->lastTs) < 0) return -1;
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
||||
|
@ -6273,6 +6325,9 @@ int32_t tDeserializeSMRecoverStreamReq(void *buf, int32_t bufLen, SMRecoverStrea
|
|||
}
|
||||
|
||||
void tFreeSCMCreateStreamReq(SCMCreateStreamReq *pReq) {
|
||||
if (NULL == pReq) {
|
||||
return;
|
||||
}
|
||||
taosArrayDestroy(pReq->pTags);
|
||||
taosMemoryFreeClear(pReq->sql);
|
||||
taosMemoryFreeClear(pReq->ast);
|
||||
|
@ -6357,7 +6412,7 @@ int tEncodeSVCreateTbReq(SEncoder *pCoder, const SVCreateTbReq *pReq) {
|
|||
if (tEncodeI32v(pCoder, pReq->flags) < 0) return -1;
|
||||
if (tEncodeCStr(pCoder, pReq->name) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pReq->uid) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pReq->ctime) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pReq->btime) < 0) return -1;
|
||||
if (tEncodeI32(pCoder, pReq->ttl) < 0) return -1;
|
||||
if (tEncodeI8(pCoder, pReq->type) < 0) return -1;
|
||||
if (tEncodeI32(pCoder, pReq->commentLen) < 0) return -1;
|
||||
|
@ -6392,7 +6447,7 @@ int tDecodeSVCreateTbReq(SDecoder *pCoder, SVCreateTbReq *pReq) {
|
|||
if (tDecodeI32v(pCoder, &pReq->flags) < 0) return -1;
|
||||
if (tDecodeCStr(pCoder, &pReq->name) < 0) return -1;
|
||||
if (tDecodeI64(pCoder, &pReq->uid) < 0) return -1;
|
||||
if (tDecodeI64(pCoder, &pReq->ctime) < 0) return -1;
|
||||
if (tDecodeI64(pCoder, &pReq->btime) < 0) return -1;
|
||||
if (tDecodeI32(pCoder, &pReq->ttl) < 0) return -1;
|
||||
if (tDecodeI8(pCoder, &pReq->type) < 0) return -1;
|
||||
if (tDecodeI32(pCoder, &pReq->commentLen) < 0) return -1;
|
||||
|
@ -6857,14 +6912,13 @@ int32_t tEncodeSVAlterTbReq(SEncoder *pEncoder, const SVAlterTbReq *pReq) {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
if (tEncodeI64(pEncoder, pReq->ctimeMs) < 0) return -1;
|
||||
|
||||
tEndEncode(pEncoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDecodeSVAlterTbReq(SDecoder *pDecoder, SVAlterTbReq *pReq) {
|
||||
if (tStartDecode(pDecoder) < 0) return -1;
|
||||
|
||||
static int32_t tDecodeSVAlterTbReqCommon(SDecoder *pDecoder, SVAlterTbReq *pReq) {
|
||||
if (tDecodeCStr(pDecoder, &pReq->tbName) < 0) return -1;
|
||||
if (tDecodeI8(pDecoder, &pReq->action) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &pReq->colId) < 0) return -1;
|
||||
|
@ -6908,6 +6962,28 @@ int32_t tDecodeSVAlterTbReq(SDecoder *pDecoder, SVAlterTbReq *pReq) {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDecodeSVAlterTbReq(SDecoder *pDecoder, SVAlterTbReq *pReq) {
|
||||
if (tStartDecode(pDecoder) < 0) return -1;
|
||||
if (tDecodeSVAlterTbReqCommon(pDecoder, pReq) < 0) return -1;
|
||||
|
||||
pReq->ctimeMs = 0;
|
||||
if (!tDecodeIsEnd(pDecoder)) {
|
||||
if (tDecodeI64(pDecoder, &pReq->ctimeMs) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndDecode(pDecoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs) {
|
||||
if (tStartDecode(pDecoder) < 0) return -1;
|
||||
if (tDecodeSVAlterTbReqCommon(pDecoder, pReq) < 0) return -1;
|
||||
|
||||
*(int64_t *)(pDecoder->data + pDecoder->pos) = ctimeMs;
|
||||
if (tDecodeI64(pDecoder, &pReq->ctimeMs) < 0) return -1;
|
||||
|
||||
tEndDecode(pDecoder);
|
||||
return 0;
|
||||
|
@ -7086,15 +7162,15 @@ int32_t tDecodeSTqOffsetVal(SDecoder *pDecoder, STqOffsetVal *pOffsetVal) {
|
|||
|
||||
int32_t tFormatOffset(char *buf, int32_t maxLen, const STqOffsetVal *pVal) {
|
||||
if (pVal->type == TMQ_OFFSET__RESET_NONE) {
|
||||
snprintf(buf, maxLen, "offset(reset to none)");
|
||||
} else if (pVal->type == TMQ_OFFSET__RESET_EARLIEAST) {
|
||||
snprintf(buf, maxLen, "offset(reset to earlieast)");
|
||||
snprintf(buf, maxLen, "none");
|
||||
} else if (pVal->type == TMQ_OFFSET__RESET_EARLIEST) {
|
||||
snprintf(buf, maxLen, "earliest");
|
||||
} else if (pVal->type == TMQ_OFFSET__RESET_LATEST) {
|
||||
snprintf(buf, maxLen, "offset(reset to latest)");
|
||||
snprintf(buf, maxLen, "latest");
|
||||
} else if (pVal->type == TMQ_OFFSET__LOG) {
|
||||
snprintf(buf, maxLen, "offset(log) ver:%" PRId64, pVal->version);
|
||||
snprintf(buf, maxLen, "wal:%" PRId64, pVal->version);
|
||||
} else if (pVal->type == TMQ_OFFSET__SNAPSHOT_DATA || pVal->type == TMQ_OFFSET__SNAPSHOT_META) {
|
||||
snprintf(buf, maxLen, "offset(snapshot) uid:%" PRId64 " ts:%" PRId64, pVal->uid, pVal->ts);
|
||||
snprintf(buf, maxLen, "tsdb:%" PRId64 "|%" PRId64, pVal->uid, pVal->ts);
|
||||
} else {
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
|
@ -7112,7 +7188,7 @@ bool tOffsetEqual(const STqOffsetVal *pLeft, const STqOffsetVal *pRight) {
|
|||
return pLeft->uid == pRight->uid;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
/*ASSERT(pLeft->type == TMQ_OFFSET__RESET_NONE || pLeft->type == TMQ_OFFSET__RESET_EARLIEAST ||*/
|
||||
/*ASSERT(pLeft->type == TMQ_OFFSET__RESET_NONE || pLeft->type == TMQ_OFFSET__RESET_EARLIEST ||*/
|
||||
/*pLeft->type == TMQ_OFFSET__RESET_LATEST);*/
|
||||
/*return true;*/
|
||||
}
|
||||
|
@ -7186,6 +7262,7 @@ int32_t tEncodeDeleteRes(SEncoder *pCoder, const SDeleteRes *pRes) {
|
|||
|
||||
if (tEncodeCStr(pCoder, pRes->tableFName) < 0) return -1;
|
||||
if (tEncodeCStr(pCoder, pRes->tsColName) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pRes->ctimeMs) < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -7205,6 +7282,11 @@ int32_t tDecodeDeleteRes(SDecoder *pCoder, SDeleteRes *pRes) {
|
|||
|
||||
if (tDecodeCStrTo(pCoder, pRes->tableFName) < 0) return -1;
|
||||
if (tDecodeCStrTo(pCoder, pRes->tsColName) < 0) return -1;
|
||||
|
||||
pRes->ctimeMs = 0;
|
||||
if (!tDecodeIsEnd(pCoder)) {
|
||||
if (tDecodeI64(pCoder, &pRes->ctimeMs) < 0) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -7428,10 +7510,11 @@ int32_t tEncodeSBatchDeleteReq(SEncoder *pEncoder, const SBatchDeleteReq *pReq)
|
|||
SSingleDeleteReq *pOneReq = taosArrayGet(pReq->deleteReqs, i);
|
||||
if (tEncodeSSingleDeleteReq(pEncoder, pOneReq) < 0) return -1;
|
||||
}
|
||||
if (tEncodeI64(pEncoder, pReq->ctimeMs) < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDecodeSBatchDeleteReq(SDecoder *pDecoder, SBatchDeleteReq *pReq) {
|
||||
static int32_t tDecodeSBatchDeleteReqCommon(SDecoder *pDecoder, SBatchDeleteReq *pReq) {
|
||||
if (tDecodeI64(pDecoder, &pReq->suid) < 0) return -1;
|
||||
int32_t sz;
|
||||
if (tDecodeI32(pDecoder, &sz) < 0) return -1;
|
||||
|
@ -7445,6 +7528,24 @@ int32_t tDecodeSBatchDeleteReq(SDecoder *pDecoder, SBatchDeleteReq *pReq) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDecodeSBatchDeleteReq(SDecoder *pDecoder, SBatchDeleteReq *pReq) {
|
||||
if (tDecodeSBatchDeleteReqCommon(pDecoder, pReq)) return -1;
|
||||
|
||||
pReq->ctimeMs = 0;
|
||||
if (!tDecodeIsEnd(pDecoder)) {
|
||||
if (tDecodeI64(pDecoder, &pReq->ctimeMs) < 0) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDecodeSBatchDeleteReqSetCtime(SDecoder *pDecoder, SBatchDeleteReq *pReq, int64_t ctimeMs) {
|
||||
if (tDecodeSBatchDeleteReqCommon(pDecoder, pReq)) return -1;
|
||||
|
||||
*(int64_t *)(pDecoder->data + pDecoder->pos) = ctimeMs;
|
||||
if (tDecodeI64(pDecoder, &pReq->ctimeMs) < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tEncodeSSubmitTbData(SEncoder *pCoder, const SSubmitTbData *pSubmitTbData) {
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
|
@ -7479,6 +7580,7 @@ static int32_t tEncodeSSubmitTbData(SEncoder *pCoder, const SSubmitTbData *pSubm
|
|||
pCoder->pos += rows[iRow]->len;
|
||||
}
|
||||
}
|
||||
if (tEncodeI64(pCoder, pSubmitTbData->ctimeMs) < 0) return -1;
|
||||
|
||||
tEndEncode(pCoder);
|
||||
return 0;
|
||||
|
@ -7559,6 +7661,14 @@ static int32_t tDecodeSSubmitTbData(SDecoder *pCoder, SSubmitTbData *pSubmitTbDa
|
|||
}
|
||||
}
|
||||
|
||||
pSubmitTbData->ctimeMs = 0;
|
||||
if (!tDecodeIsEnd(pCoder)) {
|
||||
if (tDecodeI64(pCoder, &pSubmitTbData->ctimeMs) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
}
|
||||
|
||||
tEndDecode(pCoder);
|
||||
|
||||
_exit:
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "ttypes.h"
|
||||
#include "tcompression.h"
|
||||
|
||||
const int32_t TYPE_BYTES[17] = {
|
||||
const int32_t TYPE_BYTES[21] = {
|
||||
-1, // TSDB_DATA_TYPE_NULL
|
||||
CHAR_BYTES, // TSDB_DATA_TYPE_BOOL
|
||||
CHAR_BYTES, // TSDB_DATA_TYPE_TINYINT
|
||||
|
@ -34,6 +34,10 @@ const int32_t TYPE_BYTES[17] = {
|
|||
INT_BYTES, // TSDB_DATA_TYPE_UINT
|
||||
sizeof(uint64_t), // TSDB_DATA_TYPE_UBIGINT
|
||||
TSDB_MAX_JSON_TAG_LEN, // TSDB_DATA_TYPE_JSON
|
||||
TSDB_MAX_TAGS_LEN, // TSDB_DATA_TYPE_VARBINARY: placeholder, not implemented
|
||||
TSDB_MAX_TAGS_LEN, // TSDB_DATA_TYPE_DECIMAL: placeholder, not implemented
|
||||
TSDB_MAX_TAGS_LEN, // TSDB_DATA_TYPE_BLOB: placeholder, not implemented
|
||||
TSDB_MAX_TAGS_LEN, // TSDB_DATA_TYPE_MEDIUMBLOB: placeholder, not implemented
|
||||
sizeof(VarDataOffsetT), // TSDB_DATA_TYPE_GEOMETRY
|
||||
};
|
||||
|
||||
|
@ -57,6 +61,10 @@ tDataTypeDescriptor tDataTypes[TSDB_DATA_TYPE_MAX] = {
|
|||
{TSDB_DATA_TYPE_UINT, 12, INT_BYTES, "INT UNSIGNED", 0, UINT32_MAX, tsCompressInt, tsDecompressInt},
|
||||
{TSDB_DATA_TYPE_UBIGINT, 15, LONG_BYTES, "BIGINT UNSIGNED", 0, UINT64_MAX, tsCompressBigint, tsDecompressBigint},
|
||||
{TSDB_DATA_TYPE_JSON, 4, TSDB_MAX_JSON_TAG_LEN, "JSON", 0, 0, tsCompressString, tsDecompressString},
|
||||
{TSDB_DATA_TYPE_VARBINARY, 9, 1, "VARBINARY", 0, 0, NULL, NULL}, // placeholder, not implemented
|
||||
{TSDB_DATA_TYPE_DECIMAL, 7, 1, "DECIMAL", 0, 0, NULL, NULL}, // placeholder, not implemented
|
||||
{TSDB_DATA_TYPE_BLOB, 4, 1, "BLOB", 0, 0, NULL, NULL}, // placeholder, not implemented
|
||||
{TSDB_DATA_TYPE_MEDIUMBLOB, 10, 1, "MEDIUMBLOB", 0, 0, NULL, NULL}, // placeholder, not implemented
|
||||
{TSDB_DATA_TYPE_GEOMETRY, 8, 1, "GEOMETRY", 0, 0, tsCompressString, tsDecompressString},
|
||||
};
|
||||
|
||||
|
|
|
@ -163,7 +163,7 @@ SArray *mmGetMsgHandles() {
|
|||
if (dmSetMgmtHandle(pArray, TDMT_MND_TMQ_DROP_TOPIC, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_TMQ_SUBSCRIBE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_TMQ_ASK_EP, mmPutMsgToReadQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_TMQ_HB, mmPutMsgToReadQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_TMQ_HB, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_TMQ_DROP_CGROUP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_TMQ_DROP_CGROUP_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_KILL_TRANS, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
|
|
|
@ -46,6 +46,7 @@ typedef struct {
|
|||
int32_t vgId;
|
||||
int32_t vgVersion;
|
||||
int8_t dropped;
|
||||
int32_t toVgId;
|
||||
char path[PATH_MAX + 20];
|
||||
} SWrapperCfg;
|
||||
|
||||
|
@ -55,6 +56,7 @@ typedef struct {
|
|||
int32_t refCount;
|
||||
int8_t dropped;
|
||||
int8_t disable;
|
||||
int32_t toVgId;
|
||||
char *path;
|
||||
SVnode *pImpl;
|
||||
SMultiWorker pWriteW;
|
||||
|
@ -70,6 +72,7 @@ typedef struct {
|
|||
int32_t vnodeNum;
|
||||
int32_t opened;
|
||||
int32_t failed;
|
||||
bool updateVnodesList;
|
||||
int32_t threadIndex;
|
||||
TdThread thread;
|
||||
SVnodeMgmt *pMgmt;
|
||||
|
|
|
@ -71,6 +71,8 @@ static int32_t vmDecodeVnodeList(SJson *pJson, SVnodeMgmt *pMgmt, SWrapperCfg **
|
|||
if (code < 0) goto _OVER;
|
||||
tjsonGetInt32ValueFromDouble(vnode, "vgVersion", pCfg->vgVersion, code);
|
||||
if (code < 0) goto _OVER;
|
||||
tjsonGetInt32ValueFromDouble(vnode, "toVgId", pCfg->toVgId, code);
|
||||
if (code < 0) goto _OVER;
|
||||
|
||||
snprintf(pCfg->path, sizeof(pCfg->path), "%s%svnode%d", pMgmt->path, TD_DIRSEP, pCfg->vgId);
|
||||
}
|
||||
|
@ -165,6 +167,7 @@ static int32_t vmEncodeVnodeList(SJson *pJson, SVnodeObj **ppVnodes, int32_t num
|
|||
if (tjsonAddDoubleToObject(vnode, "vgId", pVnode->vgId) < 0) return -1;
|
||||
if (tjsonAddDoubleToObject(vnode, "dropped", pVnode->dropped) < 0) return -1;
|
||||
if (tjsonAddDoubleToObject(vnode, "vgVersion", pVnode->vgVersion) < 0) return -1;
|
||||
if (pVnode->toVgId && tjsonAddDoubleToObject(vnode, "toVgId", pVnode->toVgId) < 0) return -1;
|
||||
if (tjsonAddItemToArray(vnodes, vnode) < 0) return -1;
|
||||
}
|
||||
|
||||
|
@ -179,7 +182,7 @@ int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) {
|
|||
SVnodeObj **ppVnodes = NULL;
|
||||
char file[PATH_MAX] = {0};
|
||||
char realfile[PATH_MAX] = {0};
|
||||
snprintf(file, sizeof(file), "%s%svnodes.json.bak", pMgmt->path, TD_DIRSEP);
|
||||
snprintf(file, sizeof(file), "%s%svnodes_tmp.json", pMgmt->path, TD_DIRSEP);
|
||||
snprintf(realfile, sizeof(realfile), "%s%svnodes.json", pMgmt->path, TD_DIRSEP);
|
||||
|
||||
int32_t numOfVnodes = 0;
|
||||
|
@ -226,4 +229,4 @@ _OVER:
|
|||
dError("failed to write vnodes file:%s since %s, vnodes:%d", realfile, terrstr(), numOfVnodes);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -265,6 +265,7 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
|
||||
snprintf(path, TSDB_FILENAME_LEN, "vnode%svnode%d", TD_DIRSEP, vnodeCfg.vgId);
|
||||
|
||||
#if 0
|
||||
if (pMgmt->pTfs) {
|
||||
if (tfsDirExistAt(pMgmt->pTfs, path, (SDiskID){0})) {
|
||||
terrno = TSDB_CODE_VND_DIR_ALREADY_EXIST;
|
||||
|
@ -278,8 +279,9 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (vnodeCreate(path, &vnodeCfg, pMgmt->pTfs) < 0) {
|
||||
if (vnodeCreate(path, &vnodeCfg, pMgmt->pTfs) < 0) {
|
||||
tFreeSCreateVnodeReq(&req);
|
||||
dError("vgId:%d, failed to create vnode since %s", req.vgId, terrstr());
|
||||
code = terrno;
|
||||
|
@ -482,10 +484,18 @@ int32_t vmProcessAlterHashRangeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
|
||||
int32_t srcVgId = req.srcVgId;
|
||||
int32_t dstVgId = req.dstVgId;
|
||||
|
||||
SVnodeObj *pVnode = vmAcquireVnode(pMgmt, dstVgId);
|
||||
if (pVnode != NULL) {
|
||||
dError("vgId:%d, vnode already exist", dstVgId);
|
||||
vmReleaseVnode(pMgmt, pVnode);
|
||||
terrno = TSDB_CODE_VND_ALREADY_EXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("vgId:%d, start to alter vnode hashrange:[%u, %u], dstVgId:%d", req.srcVgId, req.hashBegin, req.hashEnd,
|
||||
req.dstVgId);
|
||||
|
||||
SVnodeObj *pVnode = vmAcquireVnode(pMgmt, srcVgId);
|
||||
pVnode = vmAcquireVnode(pMgmt, srcVgId);
|
||||
if (pVnode == NULL) {
|
||||
dError("vgId:%d, failed to alter hashrange since %s", srcVgId, terrstr());
|
||||
terrno = TSDB_CODE_VND_NOT_EXIST;
|
||||
|
@ -499,6 +509,13 @@ int32_t vmProcessAlterHashRangeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
};
|
||||
tstrncpy(wrapperCfg.path, pVnode->path, sizeof(wrapperCfg.path));
|
||||
|
||||
// prepare alter
|
||||
pVnode->toVgId = dstVgId;
|
||||
if (vmWriteVnodeListToFile(pMgmt) != 0) {
|
||||
dError("vgId:%d, failed to write vnode list since %s", dstVgId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("vgId:%d, close vnode", srcVgId);
|
||||
vmCloseVnode(pMgmt, pVnode, true);
|
||||
|
||||
|
@ -530,6 +547,7 @@ int32_t vmProcessAlterHashRangeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
// complete alter
|
||||
if (vmWriteVnodeListToFile(pMgmt) != 0) {
|
||||
dError("vgId:%d, failed to write vnode list since %s", dstVgId, terrstr());
|
||||
return -1;
|
||||
|
|
|
@ -158,6 +158,28 @@ void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode, bool commitAndRemoveWal)
|
|||
taosMemoryFree(pVnode);
|
||||
}
|
||||
|
||||
static int32_t vmRestoreVgroupId(SWrapperCfg *pCfg, STfs *pTfs) {
|
||||
int32_t srcVgId = pCfg->vgId;
|
||||
int32_t dstVgId = pCfg->toVgId;
|
||||
if (dstVgId == 0) return 0;
|
||||
|
||||
char srcPath[TSDB_FILENAME_LEN];
|
||||
char dstPath[TSDB_FILENAME_LEN];
|
||||
|
||||
snprintf(srcPath, TSDB_FILENAME_LEN, "vnode%svnode%d", TD_DIRSEP, srcVgId);
|
||||
snprintf(dstPath, TSDB_FILENAME_LEN, "vnode%svnode%d", TD_DIRSEP, dstVgId);
|
||||
|
||||
int32_t vgId = vnodeRestoreVgroupId(srcPath, dstPath, srcVgId, dstVgId, pTfs);
|
||||
if (vgId <= 0) {
|
||||
dError("vgId:%d, failed to restore vgroup id. srcPath: %s", pCfg->vgId, srcPath);
|
||||
return -1;
|
||||
}
|
||||
|
||||
pCfg->vgId = vgId;
|
||||
pCfg->toVgId = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *vmOpenVnodeInThread(void *param) {
|
||||
SVnodeThread *pThread = param;
|
||||
SVnodeMgmt *pMgmt = pThread->pMgmt;
|
||||
|
@ -174,17 +196,33 @@ static void *vmOpenVnodeInThread(void *param) {
|
|||
pMgmt->state.openVnodes, pMgmt->state.totalVnodes);
|
||||
tmsgReportStartup("vnode-open", stepDesc);
|
||||
|
||||
if (pCfg->toVgId) {
|
||||
if (vmRestoreVgroupId(pCfg, pMgmt->pTfs) != 0) {
|
||||
dError("vgId:%d, failed to restore vgroup id by thread:%d", pCfg->vgId, pThread->threadIndex);
|
||||
pThread->failed++;
|
||||
continue;
|
||||
}
|
||||
pThread->updateVnodesList = true;
|
||||
}
|
||||
|
||||
snprintf(path, TSDB_FILENAME_LEN, "vnode%svnode%d", TD_DIRSEP, pCfg->vgId);
|
||||
|
||||
SVnode *pImpl = vnodeOpen(path, pMgmt->pTfs, pMgmt->msgCb);
|
||||
if (pImpl == NULL) {
|
||||
dError("vgId:%d, failed to open vnode by thread:%d", pCfg->vgId, pThread->threadIndex);
|
||||
pThread->failed++;
|
||||
} else {
|
||||
vmOpenVnode(pMgmt, pCfg, pImpl);
|
||||
dInfo("vgId:%d, is opened by thread:%d", pCfg->vgId, pThread->threadIndex);
|
||||
pThread->opened++;
|
||||
atomic_add_fetch_32(&pMgmt->state.openVnodes, 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (vmOpenVnode(pMgmt, pCfg, pImpl) != 0) {
|
||||
dError("vgId:%d, failed to open vnode by thread:%d", pCfg->vgId, pThread->threadIndex);
|
||||
pThread->failed++;
|
||||
continue;
|
||||
}
|
||||
|
||||
dInfo("vgId:%d, is opened by thread:%d", pCfg->vgId, pThread->threadIndex);
|
||||
pThread->opened++;
|
||||
atomic_add_fetch_32(&pMgmt->state.openVnodes, 1);
|
||||
}
|
||||
|
||||
dInfo("thread:%d, numOfVnodes:%d, opened:%d failed:%d", pThread->threadIndex, pThread->vnodeNum, pThread->opened,
|
||||
|
@ -242,6 +280,8 @@ static int32_t vmOpenVnodes(SVnodeMgmt *pMgmt) {
|
|||
taosThreadAttrDestroy(&thAttr);
|
||||
}
|
||||
|
||||
bool updateVnodesList = false;
|
||||
|
||||
for (int32_t t = 0; t < threadNum; ++t) {
|
||||
SVnodeThread *pThread = &threads[t];
|
||||
if (pThread->vnodeNum > 0 && taosCheckPthreadValid(pThread->thread)) {
|
||||
|
@ -249,6 +289,7 @@ static int32_t vmOpenVnodes(SVnodeMgmt *pMgmt) {
|
|||
taosThreadClear(&pThread->thread);
|
||||
}
|
||||
taosMemoryFree(pThread->pCfgs);
|
||||
if (pThread->updateVnodesList) updateVnodesList = true;
|
||||
}
|
||||
taosMemoryFree(threads);
|
||||
taosMemoryFree(pCfgs);
|
||||
|
@ -256,10 +297,15 @@ static int32_t vmOpenVnodes(SVnodeMgmt *pMgmt) {
|
|||
if (pMgmt->state.openVnodes != pMgmt->state.totalVnodes) {
|
||||
dError("there are total vnodes:%d, opened:%d", pMgmt->state.totalVnodes, pMgmt->state.openVnodes);
|
||||
return -1;
|
||||
} else {
|
||||
dInfo("successfully opened %d vnodes", pMgmt->state.totalVnodes);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (updateVnodesList && vmWriteVnodeListToFile(pMgmt) != 0) {
|
||||
dError("failed to write vnode list since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("successfully opened %d vnodes", pMgmt->state.totalVnodes);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *vmCloseVnodeInThread(void *param) {
|
||||
|
|
|
@ -218,6 +218,7 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp
|
|||
if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
|
||||
dDebug("vgId:%d, msg:%p put into vnode-write queue failed since its disable", pVnode->vgId, pMsg);
|
||||
terrno = TSDB_CODE_VND_STOPPED;
|
||||
code = terrno;
|
||||
break;
|
||||
}
|
||||
dGTrace("vgId:%d, msg:%p put into vnode-write queue", pVnode->vgId, pMsg);
|
||||
|
|
|
@ -108,7 +108,7 @@ typedef enum {
|
|||
TRN_STAGE_UNDO_ACTION = 3,
|
||||
TRN_STAGE_COMMIT = 4,
|
||||
TRN_STAGE_COMMIT_ACTION = 5,
|
||||
TRN_STAGE_FINISHED = 6,
|
||||
TRN_STAGE_FINISH = 6,
|
||||
TRN_STAGE_PRE_FINISH = 7
|
||||
} ETrnStage;
|
||||
|
||||
|
@ -157,6 +157,7 @@ typedef struct {
|
|||
void* rpcRsp;
|
||||
int32_t rpcRspLen;
|
||||
int32_t redoActionPos;
|
||||
SArray* prepareActions;
|
||||
SArray* redoActions;
|
||||
SArray* undoActions;
|
||||
SArray* commitActions;
|
||||
|
@ -551,12 +552,17 @@ typedef struct {
|
|||
int64_t createTime;
|
||||
int64_t subscribeTime;
|
||||
int64_t rebalanceTime;
|
||||
|
||||
int8_t withTbName;
|
||||
int8_t autoCommit;
|
||||
int32_t autoCommitInterval;
|
||||
int32_t resetOffsetCfg;
|
||||
} SMqConsumerObj;
|
||||
|
||||
SMqConsumerObj* tNewSMqConsumerObj(int64_t consumerId, char cgroup[TSDB_CGROUP_LEN]);
|
||||
void tDeleteSMqConsumerObj(SMqConsumerObj* pConsumer, bool delete);
|
||||
int32_t tEncodeSMqConsumerObj(void** buf, const SMqConsumerObj* pConsumer);
|
||||
void* tDecodeSMqConsumerObj(const void* buf, SMqConsumerObj* pConsumer);
|
||||
void* tDecodeSMqConsumerObj(const void* buf, SMqConsumerObj* pConsumer, int8_t sver);
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
|
@ -572,11 +578,11 @@ void* tDecodeSMqVgEp(const void* buf, SMqVgEp* pVgEp, int8_t sver);
|
|||
typedef struct {
|
||||
int64_t consumerId; // -1 for unassigned
|
||||
SArray* vgs; // SArray<SMqVgEp*>
|
||||
SArray* offsetRows; // SArray<OffsetRows*>
|
||||
SArray* offsetRows; // SArray<OffsetRows*>
|
||||
} SMqConsumerEp;
|
||||
|
||||
SMqConsumerEp* tCloneSMqConsumerEp(const SMqConsumerEp* pEp);
|
||||
void tDeleteSMqConsumerEp(void* pEp);
|
||||
//SMqConsumerEp* tCloneSMqConsumerEp(const SMqConsumerEp* pEp);
|
||||
//void tDeleteSMqConsumerEp(void* pEp);
|
||||
int32_t tEncodeSMqConsumerEp(void** buf, const SMqConsumerEp* pEp);
|
||||
void* tDecodeSMqConsumerEp(const void* buf, SMqConsumerEp* pEp, int8_t sver);
|
||||
|
||||
|
@ -592,7 +598,7 @@ typedef struct {
|
|||
SArray* unassignedVgs; // SArray<SMqVgEp*>
|
||||
SArray* offsetRows;
|
||||
char dbName[TSDB_DB_FNAME_LEN];
|
||||
char* qmsg; // SubPlanToString
|
||||
char* qmsg; // SubPlanToString
|
||||
} SMqSubscribeObj;
|
||||
|
||||
SMqSubscribeObj* tNewSubscribeObj(const char key[TSDB_SUBSCRIBE_KEY_LEN]);
|
||||
|
@ -691,12 +697,12 @@ int32_t tEncodeSStreamObj(SEncoder* pEncoder, const SStreamObj* pObj);
|
|||
int32_t tDecodeSStreamObj(SDecoder* pDecoder, SStreamObj* pObj, int32_t sver);
|
||||
void tFreeStreamObj(SStreamObj* pObj);
|
||||
|
||||
typedef struct {
|
||||
char streamName[TSDB_STREAM_FNAME_LEN];
|
||||
int64_t uid;
|
||||
int64_t streamUid;
|
||||
SArray* childInfo; // SArray<SStreamChildEpInfo>
|
||||
} SStreamCheckpointObj;
|
||||
//typedef struct {
|
||||
// char streamName[TSDB_STREAM_FNAME_LEN];
|
||||
// int64_t uid;
|
||||
// int64_t streamUid;
|
||||
// SArray* childInfo; // SArray<SStreamChildEpInfo>
|
||||
//} SStreamCheckpointObj;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -40,6 +40,8 @@ int32_t mndPersistDropStreamLog(SMnode *pMnode, STrans *pTrans, SStreamObj *pStr
|
|||
|
||||
int32_t mndDropStreamByDb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb);
|
||||
|
||||
int32_t mndGetNumOfStreams(SMnode *pMnode, char *dbName, int32_t *pNumOfStreams);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -70,6 +70,7 @@ int32_t mndTransAppendRedolog(STrans *pTrans, SSdbRaw *pRaw);
|
|||
int32_t mndTransAppendUndolog(STrans *pTrans, SSdbRaw *pRaw);
|
||||
int32_t mndTransAppendCommitlog(STrans *pTrans, SSdbRaw *pRaw);
|
||||
int32_t mndTransAppendNullLog(STrans *pTrans);
|
||||
int32_t mndTransAppendPrepareAction(STrans *pTrans, STransAction *pAction);
|
||||
int32_t mndTransAppendRedoAction(STrans *pTrans, STransAction *pAction);
|
||||
int32_t mndTransAppendUndoAction(STrans *pTrans, STransAction *pAction);
|
||||
void mndTransSetRpcRsp(STrans *pTrans, void *pCont, int32_t contLen);
|
||||
|
@ -78,15 +79,23 @@ void mndTransSetDbName(STrans *pTrans, const char *dbname, const char *stbnam
|
|||
void mndTransSetSerial(STrans *pTrans);
|
||||
void mndTransSetParallel(STrans *pTrans);
|
||||
void mndTransSetOper(STrans *pTrans, EOperType oper);
|
||||
int32_t mndTrancCheckConflict(SMnode *pMnode, STrans *pTrans);
|
||||
|
||||
int32_t mndTransCheckConflict(SMnode *pMnode, STrans *pTrans);
|
||||
static int32_t mndTrancCheckConflict(SMnode *pMnode, STrans *pTrans) {
|
||||
return mndTransCheckConflict(pMnode, pTrans);
|
||||
}
|
||||
int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans);
|
||||
int32_t mndTransProcessRsp(SRpcMsg *pRsp);
|
||||
void mndTransPullup(SMnode *pMnode);
|
||||
int32_t mndKillTrans(SMnode *pMnode, STrans *pTrans);
|
||||
void mndTransExecute(SMnode *pMnode, STrans *pTrans, bool isLeader);
|
||||
void mndTransExecute(SMnode *pMnode, STrans *pTrans);
|
||||
void mndTransRefresh(SMnode *pMnode, STrans *pTrans);
|
||||
int32_t mndSetRpcInfoForDbTrans(SMnode *pMnode, SRpcMsg *pMsg, EOperType oper, const char *dbname);
|
||||
|
||||
SSdbRaw *mndTransEncode(STrans *pTrans);
|
||||
SSdbRow *mndTransDecode(SSdbRaw *pRaw);
|
||||
void mndTransDropData(STrans *pTrans);
|
||||
|
||||
bool mndTransPerformPrepareStage(SMnode *pMnode, STrans *pTrans);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -40,6 +40,8 @@ int32_t mndValidateUserPassInfo(SMnode *pMnode, SUserPassVersion *pUsers, int3
|
|||
int32_t mndUserRemoveDb(SMnode *pMnode, STrans *pTrans, char *db);
|
||||
int32_t mndUserRemoveTopic(SMnode *pMnode, STrans *pTrans, char *topic);
|
||||
|
||||
int32_t mndUserDupObj(SUserObj *pUser, SUserObj *pNew);
|
||||
void mndUserFreeObj(SUserObj *pUser);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -27,6 +27,7 @@ void mndCleanupVgroup(SMnode *pMnode);
|
|||
SVgObj *mndAcquireVgroup(SMnode *pMnode, int32_t vgId);
|
||||
void mndReleaseVgroup(SMnode *pMnode, SVgObj *pVgroup);
|
||||
SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup);
|
||||
SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw);
|
||||
SEpSet mndGetVgroupEpset(SMnode *pMnode, const SVgObj *pVgroup);
|
||||
int32_t mndGetVnodesNum(SMnode *pMnode, int32_t dnodeId);
|
||||
void mndSortVnodeGid(SVgObj *pVgroup);
|
||||
|
@ -36,6 +37,7 @@ int64_t mndGetVgroupMemory(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup);
|
|||
SArray *mndBuildDnodesArray(SMnode *, int32_t exceptDnodeId);
|
||||
int32_t mndAllocSmaVgroup(SMnode *, SDbObj *pDb, SVgObj *pVgroup);
|
||||
int32_t mndAllocVgroup(SMnode *, SDbObj *pDb, SVgObj **ppVgroups);
|
||||
int32_t mndAddPrepareNewVgAction(SMnode *, STrans *pTrans, SVgObj *pVg);
|
||||
int32_t mndAddCreateVnodeAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid);
|
||||
int32_t mndAddAlterVnodeConfirmAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup);
|
||||
int32_t mndAddAlterVnodeAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, tmsg_t msgType);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include "tcompare.h"
|
||||
#include "tname.h"
|
||||
|
||||
#define MND_CONSUMER_VER_NUMBER 1
|
||||
#define MND_CONSUMER_VER_NUMBER 2
|
||||
#define MND_CONSUMER_RESERVE_SIZE 64
|
||||
|
||||
#define MND_MAX_GROUP_PER_TOPIC 100
|
||||
|
@ -379,12 +379,13 @@ static int32_t mndProcessMqTimerMsg(SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
static int32_t mndProcessMqHbReq(SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SMnode *pMnode = pMsg->info.node;
|
||||
SMqHbReq req = {0};
|
||||
|
||||
if (tDeserializeSMqHbReq(pMsg->pCont, pMsg->contLen, &req) < 0) {
|
||||
if ((code = tDeserializeSMqHbReq(pMsg->pCont, pMsg->contLen, &req)) < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
int64_t consumerId = req.consumerId;
|
||||
|
@ -392,7 +393,8 @@ static int32_t mndProcessMqHbReq(SRpcMsg *pMsg) {
|
|||
if (pConsumer == NULL) {
|
||||
mError("consumer:0x%" PRIx64 " not exist", consumerId);
|
||||
terrno = TSDB_CODE_MND_CONSUMER_NOT_EXIST;
|
||||
return -1;
|
||||
code = -1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
atomic_store_32(&pConsumer->hbStatus, 0);
|
||||
|
@ -412,9 +414,28 @@ static int32_t mndProcessMqHbReq(SRpcMsg *pMsg) {
|
|||
tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &pRpcMsg);
|
||||
}
|
||||
|
||||
for(int i = 0; i < taosArrayGetSize(req.topics); i++){
|
||||
TopicOffsetRows* data = taosArrayGet(req.topics, i);
|
||||
mDebug("heartbeat report offset rows.%s:%s", pConsumer->cgroup, data->topicName);
|
||||
|
||||
SMqSubscribeObj *pSub = mndAcquireSubscribe(pMnode, pConsumer->cgroup, data->topicName);
|
||||
taosWLockLatch(&pSub->lock);
|
||||
SMqConsumerEp *pConsumerEp = taosHashGet(pSub->consumerHash, &consumerId, sizeof(int64_t));
|
||||
if(pConsumerEp){
|
||||
taosArrayDestroy(pConsumerEp->offsetRows);
|
||||
pConsumerEp->offsetRows = data->offsetRows;
|
||||
data->offsetRows = NULL;
|
||||
}
|
||||
taosWUnLockLatch(&pSub->lock);
|
||||
|
||||
mndReleaseSubscribe(pMnode, pSub);
|
||||
}
|
||||
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
|
||||
return 0;
|
||||
end:
|
||||
tDeatroySMqHbReq(&req);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessAskEpReq(SRpcMsg *pMsg) {
|
||||
|
@ -672,6 +693,11 @@ int32_t mndProcessSubscribeReq(SRpcMsg *pMsg) {
|
|||
pConsumerNew = tNewSMqConsumerObj(consumerId, cgroup);
|
||||
tstrncpy(pConsumerNew->clientId, subscribe.clientId, tListLen(pConsumerNew->clientId));
|
||||
|
||||
pConsumerNew->withTbName = subscribe.withTbName;
|
||||
pConsumerNew->autoCommit = subscribe.autoCommit;
|
||||
pConsumerNew->autoCommitInterval = subscribe.autoCommitInterval;
|
||||
pConsumerNew->resetOffsetCfg = subscribe.resetOffsetCfg;
|
||||
|
||||
// pConsumerNew->updateType = CONSUMER_UPDATE_SUB_MODIFY; // use insert logic
|
||||
taosArrayDestroy(pConsumerNew->assignedTopics);
|
||||
pConsumerNew->assignedTopics = taosArrayDup(pTopicList, topicNameDup);
|
||||
|
@ -815,7 +841,7 @@ SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw) {
|
|||
goto CM_DECODE_OVER;
|
||||
}
|
||||
|
||||
if (sver != MND_CONSUMER_VER_NUMBER) {
|
||||
if (sver < 1 || sver > MND_CONSUMER_VER_NUMBER) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
goto CM_DECODE_OVER;
|
||||
}
|
||||
|
@ -842,7 +868,7 @@ SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw) {
|
|||
SDB_GET_BINARY(pRaw, dataPos, buf, len, CM_DECODE_OVER);
|
||||
SDB_GET_RESERVE(pRaw, dataPos, MND_CONSUMER_RESERVE_SIZE, CM_DECODE_OVER);
|
||||
|
||||
if (tDecodeSMqConsumerObj(buf, pConsumer) == NULL) {
|
||||
if (tDecodeSMqConsumerObj(buf, pConsumer, sver) == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY; // TODO set correct error code
|
||||
goto CM_DECODE_OVER;
|
||||
}
|
||||
|
@ -1155,6 +1181,17 @@ static int32_t mndRetrieveConsumer(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *
|
|||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)&pConsumer->rebalanceTime, pConsumer->rebalanceTime == 0);
|
||||
|
||||
char buf[TSDB_OFFSET_LEN] = {0};
|
||||
STqOffsetVal pVal = {.type = pConsumer->resetOffsetCfg};
|
||||
tFormatOffset(buf, TSDB_OFFSET_LEN, &pVal);
|
||||
|
||||
char parasStr[64 + TSDB_OFFSET_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
sprintf(varDataVal(parasStr), "tbname:%d,commit:%d,interval:%dms,reset:%s", pConsumer->withTbName, pConsumer->autoCommit, pConsumer->autoCommitInterval, buf);
|
||||
varDataSetLen(parasStr, strlen(varDataVal(parasStr)));
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)parasStr, false);
|
||||
|
||||
numOfRows++;
|
||||
}
|
||||
|
||||
|
|
|
@ -414,6 +414,13 @@ static void mndSetDefaultDbCfg(SDbCfg *pCfg) {
|
|||
if (pCfg->tsdbPageSize <= 0) pCfg->tsdbPageSize = TSDB_DEFAULT_TSDB_PAGESIZE;
|
||||
}
|
||||
|
||||
static int32_t mndSetPrepareNewVgActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) {
|
||||
for (int32_t v = 0; v < pDb->cfg.numOfVgroups; ++v) {
|
||||
if (mndAddPrepareNewVgAction(pMnode, pTrans, (pVgroups + v)) != 0) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetCreateDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) {
|
||||
SSdbRaw *pDbRaw = mndDbActionEncode(pDb);
|
||||
if (pDbRaw == NULL) return -1;
|
||||
|
@ -424,7 +431,7 @@ static int32_t mndSetCreateDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pD
|
|||
SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v);
|
||||
if (pVgRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pVgRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pVgRaw, SDB_STATUS_CREATING) != 0) return -1;
|
||||
if (sdbSetRawStatus(pVgRaw, SDB_STATUS_UPDATE) != 0) return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -446,7 +453,8 @@ static int32_t mndSetCreateDbUndoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pD
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetCreateDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) {
|
||||
static int32_t mndSetCreateDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups,
|
||||
SUserObj *pUserDuped) {
|
||||
SSdbRaw *pDbRaw = mndDbActionEncode(pDb);
|
||||
if (pDbRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pDbRaw) != 0) return -1;
|
||||
|
@ -459,6 +467,13 @@ static int32_t mndSetCreateDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *
|
|||
if (sdbSetRawStatus(pVgRaw, SDB_STATUS_READY) != 0) return -1;
|
||||
}
|
||||
|
||||
if (pUserDuped) {
|
||||
SSdbRaw *pUserRaw = mndUserActionEncode(pUserDuped);
|
||||
if (pUserRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pUserRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pUserRaw, SDB_STATUS_READY) != 0) return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -565,6 +580,15 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate,
|
|||
return -1;
|
||||
}
|
||||
|
||||
// add database privileges for user
|
||||
SUserObj newUserObj = {0}, *pNewUserDuped = NULL;
|
||||
if (!pUser->superUser) {
|
||||
if (mndUserDupObj(pUser, &newUserObj) != 0) goto _OVER;
|
||||
taosHashPut(newUserObj.readDbs, dbObj.name, strlen(dbObj.name) + 1, dbObj.name, TSDB_FILENAME_LEN);
|
||||
taosHashPut(newUserObj.writeDbs, dbObj.name, strlen(dbObj.name) + 1, dbObj.name, TSDB_FILENAME_LEN);
|
||||
pNewUserDuped = &newUserObj;
|
||||
}
|
||||
|
||||
int32_t code = -1;
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB, pReq, "create-db");
|
||||
if (pTrans == NULL) goto _OVER;
|
||||
|
@ -572,12 +596,13 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate,
|
|||
mInfo("trans:%d, used to create db:%s", pTrans->id, pCreate->db);
|
||||
|
||||
mndTransSetDbName(pTrans, dbObj.name, NULL);
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
mndTransSetOper(pTrans, MND_OPER_CREATE_DB);
|
||||
if (mndSetPrepareNewVgActions(pMnode, pTrans, &dbObj, pVgroups) != 0) goto _OVER;
|
||||
if (mndSetCreateDbRedoLogs(pMnode, pTrans, &dbObj, pVgroups) != 0) goto _OVER;
|
||||
if (mndSetCreateDbUndoLogs(pMnode, pTrans, &dbObj, pVgroups) != 0) goto _OVER;
|
||||
if (mndSetCreateDbCommitLogs(pMnode, pTrans, &dbObj, pVgroups) != 0) goto _OVER;
|
||||
if (mndSetCreateDbCommitLogs(pMnode, pTrans, &dbObj, pVgroups, pNewUserDuped) != 0) goto _OVER;
|
||||
if (mndSetCreateDbRedoActions(pMnode, pTrans, &dbObj, pVgroups) != 0) goto _OVER;
|
||||
if (mndSetCreateDbUndoActions(pMnode, pTrans, &dbObj, pVgroups) != 0) goto _OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
@ -586,6 +611,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate,
|
|||
|
||||
_OVER:
|
||||
taosMemoryFree(pVgroups);
|
||||
mndUserFreeObj(&newUserObj);
|
||||
mndTransDrop(pTrans);
|
||||
return code;
|
||||
}
|
||||
|
@ -814,7 +840,7 @@ static int32_t mndAlterDb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pOld, SDbObj *p
|
|||
|
||||
int32_t code = -1;
|
||||
mndTransSetDbName(pTrans, pOld->name, NULL);
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
if (mndSetAlterDbRedoLogs(pMnode, pTrans, pOld, pNew) != 0) goto _OVER;
|
||||
if (mndSetAlterDbCommitLogs(pMnode, pTrans, pOld, pNew) != 0) goto _OVER;
|
||||
|
@ -1111,7 +1137,7 @@ static int32_t mndDropDb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb) {
|
|||
mInfo("trans:%d start to drop db:%s", pTrans->id, pDb->name);
|
||||
|
||||
mndTransSetDbName(pTrans, pDb->name, NULL);
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) {
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
|
|
@ -329,10 +329,14 @@ int32_t tEncodeSMqConsumerObj(void **buf, const SMqConsumerObj *pConsumer) {
|
|||
tlen += taosEncodeFixedI32(buf, 0);
|
||||
}
|
||||
|
||||
tlen += taosEncodeFixedI8(buf, pConsumer->withTbName);
|
||||
tlen += taosEncodeFixedI8(buf, pConsumer->autoCommit);
|
||||
tlen += taosEncodeFixedI32(buf, pConsumer->autoCommitInterval);
|
||||
tlen += taosEncodeFixedI32(buf, pConsumer->resetOffsetCfg);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
void *tDecodeSMqConsumerObj(const void *buf, SMqConsumerObj *pConsumer) {
|
||||
void *tDecodeSMqConsumerObj(const void *buf, SMqConsumerObj *pConsumer, int8_t sver) {
|
||||
int32_t sz;
|
||||
buf = taosDecodeFixedI64(buf, &pConsumer->consumerId);
|
||||
buf = taosDecodeStringTo(buf, pConsumer->clientId);
|
||||
|
@ -383,21 +387,27 @@ void *tDecodeSMqConsumerObj(const void *buf, SMqConsumerObj *pConsumer) {
|
|||
taosArrayPush(pConsumer->assignedTopics, &topic);
|
||||
}
|
||||
|
||||
if(sver > 1){
|
||||
buf = taosDecodeFixedI8(buf, &pConsumer->withTbName);
|
||||
buf = taosDecodeFixedI8(buf, &pConsumer->autoCommit);
|
||||
buf = taosDecodeFixedI32(buf, &pConsumer->autoCommitInterval);
|
||||
buf = taosDecodeFixedI32(buf, &pConsumer->resetOffsetCfg);
|
||||
}
|
||||
return (void *)buf;
|
||||
}
|
||||
|
||||
SMqConsumerEp *tCloneSMqConsumerEp(const SMqConsumerEp *pConsumerEpOld) {
|
||||
SMqConsumerEp *pConsumerEpNew = taosMemoryMalloc(sizeof(SMqConsumerEp));
|
||||
if (pConsumerEpNew == NULL) return NULL;
|
||||
pConsumerEpNew->consumerId = pConsumerEpOld->consumerId;
|
||||
pConsumerEpNew->vgs = taosArrayDup(pConsumerEpOld->vgs, (__array_item_dup_fn_t)tCloneSMqVgEp);
|
||||
return pConsumerEpNew;
|
||||
}
|
||||
|
||||
void tDeleteSMqConsumerEp(void *data) {
|
||||
SMqConsumerEp *pConsumerEp = (SMqConsumerEp *)data;
|
||||
taosArrayDestroyP(pConsumerEp->vgs, (FDelete)tDeleteSMqVgEp);
|
||||
}
|
||||
//SMqConsumerEp *tCloneSMqConsumerEp(const SMqConsumerEp *pConsumerEpOld) {
|
||||
// SMqConsumerEp *pConsumerEpNew = taosMemoryMalloc(sizeof(SMqConsumerEp));
|
||||
// if (pConsumerEpNew == NULL) return NULL;
|
||||
// pConsumerEpNew->consumerId = pConsumerEpOld->consumerId;
|
||||
// pConsumerEpNew->vgs = taosArrayDup(pConsumerEpOld->vgs, NULL);
|
||||
// return pConsumerEpNew;
|
||||
//}
|
||||
//
|
||||
//void tDeleteSMqConsumerEp(void *data) {
|
||||
// SMqConsumerEp *pConsumerEp = (SMqConsumerEp *)data;
|
||||
// taosArrayDestroy(pConsumerEp->vgs);
|
||||
//}
|
||||
|
||||
int32_t tEncodeSMqConsumerEp(void **buf, const SMqConsumerEp *pConsumerEp) {
|
||||
int32_t tlen = 0;
|
||||
|
@ -419,30 +429,20 @@ int32_t tEncodeSMqConsumerEp(void **buf, const SMqConsumerEp *pConsumerEp) {
|
|||
// do nothing
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
int32_t sz = taosArrayGetSize(pConsumerEp->vgs);
|
||||
tlen += taosEncodeFixedI32(buf, sz);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SMqVgEp *pVgEp = taosArrayGetP(pConsumerEp->vgs, i);
|
||||
tlen += tEncodeSMqVgEp(buf, pVgEp);
|
||||
}
|
||||
#endif
|
||||
//#if 0
|
||||
// int32_t sz = taosArrayGetSize(pConsumerEp->vgs);
|
||||
// tlen += taosEncodeFixedI32(buf, sz);
|
||||
// for (int32_t i = 0; i < sz; i++) {
|
||||
// SMqVgEp *pVgEp = taosArrayGetP(pConsumerEp->vgs, i);
|
||||
// tlen += tEncodeSMqVgEp(buf, pVgEp);
|
||||
// }
|
||||
//#endif
|
||||
return tlen;
|
||||
}
|
||||
|
||||
void *tDecodeSMqConsumerEp(const void *buf, SMqConsumerEp *pConsumerEp, int8_t sver) {
|
||||
buf = taosDecodeFixedI64(buf, &pConsumerEp->consumerId);
|
||||
buf = taosDecodeArray(buf, &pConsumerEp->vgs, (FDecode)tDecodeSMqVgEp, sizeof(SMqVgEp), sver);
|
||||
#if 0
|
||||
int32_t sz;
|
||||
buf = taosDecodeFixedI32(buf, &sz);
|
||||
pConsumerEp->vgs = taosArrayInit(sz, sizeof(void *));
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SMqVgEp *pVgEp = taosMemoryMalloc(sizeof(SMqVgEp));
|
||||
buf = tDecodeSMqVgEp(buf, pVgEp);
|
||||
taosArrayPush(pConsumerEp->vgs, &pVgEp);
|
||||
}
|
||||
#endif
|
||||
if (sver > 1){
|
||||
int32_t szVgs = 0;
|
||||
buf = taosDecodeFixedI32(buf, &szVgs);
|
||||
|
@ -465,6 +465,17 @@ void *tDecodeSMqConsumerEp(const void *buf, SMqConsumerEp *pConsumerEp, int8_t s
|
|||
}
|
||||
}
|
||||
}
|
||||
//#if 0
|
||||
// int32_t sz;
|
||||
// buf = taosDecodeFixedI32(buf, &sz);
|
||||
// pConsumerEp->vgs = taosArrayInit(sz, sizeof(void *));
|
||||
// for (int32_t i = 0; i < sz; i++) {
|
||||
// SMqVgEp *pVgEp = taosMemoryMalloc(sizeof(SMqVgEp));
|
||||
// buf = tDecodeSMqVgEp(buf, pVgEp);
|
||||
// taosArrayPush(pConsumerEp->vgs, &pVgEp);
|
||||
// }
|
||||
//#endif
|
||||
|
||||
return (void *)buf;
|
||||
}
|
||||
|
||||
|
@ -526,6 +537,7 @@ void tDeleteSubscribeObj(SMqSubscribeObj *pSub) {
|
|||
if (pIter == NULL) break;
|
||||
SMqConsumerEp *pConsumerEp = (SMqConsumerEp *)pIter;
|
||||
taosArrayDestroyP(pConsumerEp->vgs, (FDelete)tDeleteSMqVgEp);
|
||||
taosArrayDestroy(pConsumerEp->offsetRows);
|
||||
}
|
||||
taosHashCleanup(pSub->consumerHash);
|
||||
taosArrayDestroyP(pSub->unassignedVgs, (FDelete)tDeleteSMqVgEp);
|
||||
|
@ -557,6 +569,7 @@ int32_t tEncodeSubscribeObj(void **buf, const SMqSubscribeObj *pSub) {
|
|||
if (cnt != sz) return -1;
|
||||
tlen += taosEncodeArray(buf, pSub->unassignedVgs, (FEncode)tEncodeSMqVgEp);
|
||||
tlen += taosEncodeString(buf, pSub->dbName);
|
||||
|
||||
int32_t szVgs = taosArrayGetSize(pSub->offsetRows);
|
||||
tlen += taosEncodeFixedI32(buf, szVgs);
|
||||
for (int32_t j= 0; j < szVgs; ++j) {
|
||||
|
@ -598,6 +611,7 @@ void *tDecodeSubscribeObj(const void *buf, SMqSubscribeObj *pSub, int8_t sver) {
|
|||
|
||||
buf = taosDecodeArray(buf, &pSub->unassignedVgs, (FDecode)tDecodeSMqVgEp, sizeof(SMqVgEp), sver);
|
||||
buf = taosDecodeStringTo(buf, pSub->dbName);
|
||||
|
||||
if (sver > 1){
|
||||
int32_t szVgs = 0;
|
||||
buf = taosDecodeFixedI32(buf, &szVgs);
|
||||
|
@ -637,7 +651,7 @@ void *tDecodeSubscribeObj(const void *buf, SMqSubscribeObj *pSub, int8_t sver) {
|
|||
//void tDeleteSMqSubActionLogEntry(SMqSubActionLogEntry *pEntry) {
|
||||
// taosArrayDestroyEx(pEntry->consumers, (FDelete)tDeleteSMqConsumerEp);
|
||||
//}
|
||||
//
|
||||
|
||||
//int32_t tEncodeSMqSubActionLogEntry(void **buf, const SMqSubActionLogEntry *pEntry) {
|
||||
// int32_t tlen = 0;
|
||||
// tlen += taosEncodeFixedI32(buf, pEntry->epoch);
|
||||
|
@ -650,7 +664,7 @@ void *tDecodeSubscribeObj(const void *buf, SMqSubscribeObj *pSub, int8_t sver) {
|
|||
// buf = taosDecodeArray(buf, &pEntry->consumers, (FDecode)tDecodeSMqSubActionLogEntry, sizeof(SMqSubActionLogEntry));
|
||||
// return (void *)buf;
|
||||
//}
|
||||
//
|
||||
|
||||
//SMqSubActionLogObj *tCloneSMqSubActionLogObj(SMqSubActionLogObj *pLog) {
|
||||
// SMqSubActionLogObj *pLogNew = taosMemoryMalloc(sizeof(SMqSubActionLogObj));
|
||||
// if (pLogNew == NULL) return pLogNew;
|
||||
|
@ -662,7 +676,7 @@ void *tDecodeSubscribeObj(const void *buf, SMqSubscribeObj *pSub, int8_t sver) {
|
|||
//void tDeleteSMqSubActionLogObj(SMqSubActionLogObj *pLog) {
|
||||
// taosArrayDestroyEx(pLog->logs, (FDelete)tDeleteSMqConsumerEp);
|
||||
//}
|
||||
//
|
||||
|
||||
//int32_t tEncodeSMqSubActionLogObj(void **buf, const SMqSubActionLogObj *pLog) {
|
||||
// int32_t tlen = 0;
|
||||
// tlen += taosEncodeString(buf, pLog->key);
|
||||
|
|
|
@ -632,7 +632,7 @@ static int32_t mndCreateDnode(SMnode *pMnode, SRpcMsg *pReq, SCreateDnodeReq *pC
|
|||
pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_GLOBAL, pReq, "create-dnode");
|
||||
if (pTrans == NULL) goto _OVER;
|
||||
mInfo("trans:%d, used to create dnode:%s", pTrans->id, dnodeObj.ep);
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
pRaw = mndDnodeActionEncode(&dnodeObj);
|
||||
if (pRaw == NULL || mndTransAppendCommitlog(pTrans, pRaw) != 0) goto _OVER;
|
||||
|
@ -889,7 +889,7 @@ static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SM
|
|||
if (pTrans == NULL) goto _OVER;
|
||||
mndTransSetSerial(pTrans);
|
||||
mInfo("trans:%d, used to drop dnode:%d, force:%d", pTrans->id, pDnode->id, force);
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
pRaw = mndDnodeActionEncode(pDnode);
|
||||
if (pRaw == NULL) goto _OVER;
|
||||
|
|
|
@ -645,7 +645,7 @@ int32_t mndAddIndexImpl(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SStbObj *pSt
|
|||
|
||||
// mInfo("trans:%d, used to add index to stb:%s", pTrans->id, pStb->name);
|
||||
mndTransSetDbName(pTrans, pDb->name, pStb->name);
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
mndTransSetSerial(pTrans);
|
||||
|
||||
|
@ -721,7 +721,7 @@ static int32_t mndDropIdx(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SIdxObj *p
|
|||
|
||||
mInfo("trans:%d, used to drop idx:%s", pTrans->id, pIdx->name);
|
||||
mndTransSetDbName(pTrans, pDb->name, NULL);
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
mndTransSetSerial(pTrans);
|
||||
if (mndSetDropIdxRedoLogs(pMnode, pTrans, pIdx) != 0) goto _OVER;
|
||||
|
@ -860,4 +860,4 @@ int32_t mndDropIdxsByDb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) {
|
|||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -578,7 +578,7 @@ static int32_t mndCreateMnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode,
|
|||
if (pTrans == NULL) goto _OVER;
|
||||
mndTransSetSerial(pTrans);
|
||||
mInfo("trans:%d, used to create mnode:%d", pTrans->id, pCreate->dnodeId);
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
SMnodeObj mnodeObj = {0};
|
||||
mnodeObj.id = pDnode->id;
|
||||
|
@ -732,7 +732,7 @@ static int32_t mndDropMnode(SMnode *pMnode, SRpcMsg *pReq, SMnodeObj *pObj) {
|
|||
if (pTrans == NULL) goto _OVER;
|
||||
mndTransSetSerial(pTrans);
|
||||
mInfo("trans:%d, used to drop mnode:%d", pTrans->id, pObj->id);
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
if (mndSetDropMnodeInfoToTrans(pMnode, pTrans, pObj, false) != 0) goto _OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
|
|
@ -227,6 +227,7 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) {
|
|||
}
|
||||
|
||||
if ((code = taosCheckVersionCompatibleFromStr(connReq.sVer, version, 3)) != 0) {
|
||||
mGError("version not compatible. client version: %s, server version: %s", connReq.sVer, version);
|
||||
terrno = code;
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -243,8 +244,8 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) {
|
|||
mGError("user:%s, failed to login from %s while acquire user since %s", pReq->info.conn.user, ip, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (strncmp(connReq.passwd, pUser->pass, TSDB_PASSWORD_LEN - 1) != 0) {
|
||||
|
||||
if (strncmp(connReq.passwd, pUser->pass, TSDB_PASSWORD_LEN - 1) != 0 && !tsMndSkipGrant) {
|
||||
mGError("user:%s, failed to login from %s since invalid pass, input:%s", pReq->info.conn.user, ip, connReq.passwd);
|
||||
code = TSDB_CODE_MND_AUTH_FAILURE;
|
||||
goto _OVER;
|
||||
|
|
|
@ -388,7 +388,7 @@ static int32_t mndSetCreateSmaVgroupRedoLogs(SMnode *pMnode, STrans *pTrans, SVg
|
|||
SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroup);
|
||||
if (pVgRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pVgRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pVgRaw, SDB_STATUS_CREATING) != 0) return -1;
|
||||
if (sdbSetRawStatus(pVgRaw, SDB_STATUS_UPDATE) != 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -622,11 +622,11 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea
|
|||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB, pReq, "create-sma");
|
||||
if (pTrans == NULL) goto _OVER;
|
||||
mndTransSetDbName(pTrans, pDb->name, NULL);
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
mndTransSetSerial(pTrans);
|
||||
mInfo("trans:%d, used to create sma:%s stream:%s", pTrans->id, pCreate->name, streamObj.name);
|
||||
|
||||
if (mndAddPrepareNewVgAction(pMnode, pTrans, &streamObj.fixedSinkVg) != 0) goto _OVER;
|
||||
if (mndSetCreateSmaRedoLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER;
|
||||
if (mndSetCreateSmaVgroupRedoLogs(pMnode, pTrans, &streamObj.fixedSinkVg) != 0) goto _OVER;
|
||||
if (mndSetCreateSmaCommitLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER;
|
||||
|
@ -845,7 +845,7 @@ static int32_t mndDropSma(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SSmaObj *p
|
|||
|
||||
mInfo("trans:%d, used to drop sma:%s", pTrans->id, pSma->name);
|
||||
mndTransSetDbName(pTrans, pDb->name, NULL);
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
mndTransSetSerial(pTrans);
|
||||
|
||||
|
|
|
@ -874,7 +874,7 @@ _OVER:
|
|||
|
||||
int32_t mndAddStbToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) {
|
||||
mndTransSetDbName(pTrans, pDb->name, pStb->name);
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) return -1;
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) return -1;
|
||||
if (mndSetCreateStbRedoLogs(pMnode, pTrans, pDb, pStb) != 0) return -1;
|
||||
if (mndSetCreateStbUndoLogs(pMnode, pTrans, pDb, pStb) != 0) return -1;
|
||||
if (mndSetCreateStbCommitLogs(pMnode, pTrans, pDb, pStb) != 0) return -1;
|
||||
|
@ -888,7 +888,7 @@ static int32_t mndProcessTtlTimer(SRpcMsg *pReq) {
|
|||
SSdb *pSdb = pMnode->pSdb;
|
||||
SVgObj *pVgroup = NULL;
|
||||
void *pIter = NULL;
|
||||
SVDropTtlTableReq ttlReq = {.timestamp = taosGetTimestampSec()};
|
||||
SVDropTtlTableReq ttlReq = {.timestampSec = taosGetTimestampSec()};
|
||||
int32_t reqLen = tSerializeSVDropTtlTableReq(NULL, 0, &ttlReq);
|
||||
int32_t contLen = reqLen + sizeof(SMsgHead);
|
||||
|
||||
|
@ -914,7 +914,7 @@ static int32_t mndProcessTtlTimer(SRpcMsg *pReq) {
|
|||
if (code != 0) {
|
||||
mError("vgId:%d, failed to send drop ttl table request to vnode since 0x%x", pVgroup->vgId, code);
|
||||
} else {
|
||||
mInfo("vgId:%d, send drop ttl table request to vnode, time:%d", pVgroup->vgId, ttlReq.timestamp);
|
||||
mInfo("vgId:%d, send drop ttl table request to vnode, time:%" PRId32, pVgroup->vgId, ttlReq.timestampSec);
|
||||
}
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
}
|
||||
|
@ -1188,7 +1188,7 @@ static int32_t mndAddSuperTableTag(const SStbObj *pOld, SStbObj *pNew, SArray *p
|
|||
if (mndAllocStbSchemas(pOld, pNew) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if(pNew->nextColId < 0 || pNew->nextColId >= 0x7fff - ntags){
|
||||
terrno = TSDB_CODE_MND_FIELD_VALUE_OVERFLOW;
|
||||
return -1;
|
||||
|
@ -1968,7 +1968,7 @@ static int32_t mndAlterStbImp(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SStbOb
|
|||
|
||||
mInfo("trans:%d, used to alter stb:%s", pTrans->id, pStb->name);
|
||||
mndTransSetDbName(pTrans, pDb->name, pStb->name);
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
if (needRsp) {
|
||||
void *pCont = NULL;
|
||||
|
@ -1998,7 +1998,7 @@ static int32_t mndAlterStbAndUpdateTagIdxImp(SMnode *pMnode, SRpcMsg *pReq, SDbO
|
|||
mInfo("trans:%d, used to alter stb:%s", pTrans->id, pStb->name);
|
||||
mndTransSetDbName(pTrans, pDb->name, pStb->name);
|
||||
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
if (needRsp) {
|
||||
void *pCont = NULL;
|
||||
|
@ -2242,7 +2242,7 @@ static int32_t mndDropStb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SStbObj *p
|
|||
|
||||
mInfo("trans:%d, used to drop stb:%s", pTrans->id, pStb->name);
|
||||
mndTransSetDbName(pTrans, pDb->name, pStb->name);
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
if (mndSetDropStbRedoLogs(pMnode, pTrans, pStb) != 0) goto _OVER;
|
||||
if (mndSetDropStbCommitLogs(pMnode, pTrans, pStb) != 0) goto _OVER;
|
||||
|
@ -3304,7 +3304,7 @@ static int32_t mndCheckIndexReq(SCreateTagIndexReq *pReq) {
|
|||
|
||||
mInfo("trans:%d, used to add index to stb:%s", pTrans->id, pStb->name);
|
||||
mndTransSetDbName(pTrans, pDb->name, pStb->name);
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
if (mndSetAlterStbRedoLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER;
|
||||
if (mndSetAlterStbCommitLogs(pMnode, pTrans, pDb, pStb) != 0) goto _OVER;
|
||||
|
|
|
@ -735,7 +735,7 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) {
|
|||
mInfo("trans:%d, used to create stream:%s", pTrans->id, createStreamReq.name);
|
||||
|
||||
mndTransSetDbName(pTrans, createStreamReq.sourceDB, streamObj.targetDb);
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) {
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) {
|
||||
mndTransDrop(pTrans);
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -890,7 +890,7 @@ static int32_t mndProcessStreamDoCheckpoint(SRpcMsg *pReq) {
|
|||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB_INSIDE, pReq, "stream-checkpoint");
|
||||
if (pTrans == NULL) return -1;
|
||||
mndTransSetDbName(pTrans, pStream->sourceDb, pStream->targetDb);
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) {
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) {
|
||||
mndReleaseStream(pMnode, pStream);
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
|
@ -1001,7 +1001,7 @@ static int32_t mndProcessDropStreamReq(SRpcMsg *pReq) {
|
|||
mInfo("trans:%d, used to drop stream:%s", pTrans->id, dropReq.name);
|
||||
|
||||
mndTransSetDbName(pTrans, pStream->sourceDb, pStream->targetDb);
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) {
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) {
|
||||
sdbRelease(pMnode->pSdb, pStream);
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
|
@ -1075,7 +1075,7 @@ int32_t mndDropStreamByDb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndGetNumOfStreams(SMnode *pMnode, char *dbName, int32_t *pNumOfStreams) {
|
||||
int32_t mndGetNumOfStreams(SMnode *pMnode, char *dbName, int32_t *pNumOfStreams) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, dbName);
|
||||
if (pDb == NULL) {
|
||||
|
@ -1369,7 +1369,7 @@ static int32_t mndProcessPauseStreamReq(SRpcMsg *pReq) {
|
|||
mInfo("trans:%d, used to pause stream:%s", pTrans->id, pauseReq.name);
|
||||
|
||||
mndTransSetDbName(pTrans, pStream->sourceDb, pStream->targetDb);
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) {
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) {
|
||||
sdbRelease(pMnode->pSdb, pStream);
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
|
@ -1477,7 +1477,7 @@ static int32_t mndProcessResumeStreamReq(SRpcMsg *pReq) {
|
|||
mInfo("trans:%d, used to pause stream:%s", pTrans->id, pauseReq.name);
|
||||
|
||||
mndTransSetDbName(pTrans, pStream->sourceDb, pStream->targetDb);
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) {
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) {
|
||||
sdbRelease(pMnode->pSdb, pStream);
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
|
|
|
@ -463,11 +463,58 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
|
|||
|
||||
SMqRebOutputVg* pRebOutput = (SMqRebOutputVg *)pRemovedIter;
|
||||
taosArrayPush(pOutput->rebVgs, pRebOutput);
|
||||
if(taosHashGetSize(pOutput->pSub->consumerHash) == 0){ // if all consumer is removed, put all vg into unassigned
|
||||
taosArrayPush(pOutput->pSub->unassignedVgs, &pRebOutput->pVgEp);
|
||||
if(taosHashGetSize(pOutput->pSub->consumerHash) == 0){ // if all consumer is removed
|
||||
taosArrayPush(pOutput->pSub->unassignedVgs, &pRebOutput->pVgEp); // put all vg into unassigned
|
||||
}
|
||||
}
|
||||
|
||||
// if(taosHashGetSize(pOutput->pSub->consumerHash) == 0) { // if all consumer is removed
|
||||
SMqSubscribeObj *pSub = mndAcquireSubscribeByKey(pMnode, pInput->pRebInfo->key); // put all offset rows
|
||||
if (pSub) {
|
||||
taosRLockLatch(&pSub->lock);
|
||||
if (pOutput->pSub->offsetRows == NULL) {
|
||||
pOutput->pSub->offsetRows = taosArrayInit(4, sizeof(OffsetRows));
|
||||
}
|
||||
pIter = NULL;
|
||||
while (1) {
|
||||
pIter = taosHashIterate(pSub->consumerHash, pIter);
|
||||
if (pIter == NULL) break;
|
||||
SMqConsumerEp *pConsumerEp = (SMqConsumerEp *)pIter;
|
||||
SMqConsumerEp *pConsumerEpNew = taosHashGet(pOutput->pSub->consumerHash, &pConsumerEp->consumerId, sizeof(int64_t));
|
||||
|
||||
for (int j = 0; j < taosArrayGetSize(pConsumerEp->offsetRows); j++) {
|
||||
OffsetRows *d1 = taosArrayGet(pConsumerEp->offsetRows, j);
|
||||
bool jump = false;
|
||||
for (int i = 0; pConsumerEpNew && i < taosArrayGetSize(pConsumerEpNew->vgs); i++){
|
||||
SMqVgEp *pVgEp = taosArrayGetP(pConsumerEpNew->vgs, i);
|
||||
if(pVgEp->vgId == d1->vgId){
|
||||
jump = true;
|
||||
mInfo("pSub->offsetRows jump, because consumer id:%"PRIx64 " and vgId:%d not change", pConsumerEp->consumerId, pVgEp->vgId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(jump) continue;
|
||||
bool find = false;
|
||||
for (int i = 0; i < taosArrayGetSize(pOutput->pSub->offsetRows); i++) {
|
||||
OffsetRows *d2 = taosArrayGet(pOutput->pSub->offsetRows, i);
|
||||
if (d1->vgId == d2->vgId) {
|
||||
d2->rows += d1->rows;
|
||||
d2->offset = d1->offset;
|
||||
find = true;
|
||||
mInfo("pSub->offsetRows add vgId:%d, after:%"PRId64", before:%"PRId64, d2->vgId, d2->rows, d1->rows);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!find){
|
||||
taosArrayPush(pOutput->pSub->offsetRows, d1);
|
||||
}
|
||||
}
|
||||
}
|
||||
taosRUnLockLatch(&pSub->lock);
|
||||
mndReleaseSubscribe(pMnode, pSub);
|
||||
// }
|
||||
}
|
||||
|
||||
// 8. generate logs
|
||||
mInfo("sub:%s mq re-balance calculation completed, re-balanced vg", pSubKey);
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pOutput->rebVgs); i++) {
|
||||
|
@ -513,7 +560,7 @@ static int32_t mndPersistRebResult(SMnode *pMnode, SRpcMsg *pMsg, const SMqRebOu
|
|||
}
|
||||
|
||||
mndTransSetDbName(pTrans, pOutput->pSub->dbName, NULL);
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) {
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) {
|
||||
mndTransDrop(pTrans);
|
||||
nodesDestroyNode((SNode*)pPlan);
|
||||
return -1;
|
||||
|
@ -724,8 +771,10 @@ static int32_t mndProcessRebalanceReq(SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
static int32_t mndProcessDropCgroupReq(SRpcMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->info.node;
|
||||
SMDropCgroupReq dropReq = {0};
|
||||
SMnode *pMnode = pMsg->info.node;
|
||||
SMDropCgroupReq dropReq = {0};
|
||||
STrans *pTrans = NULL;
|
||||
int32_t code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||
|
||||
if (tDeserializeSMDropCgroupReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
|
@ -744,11 +793,12 @@ static int32_t mndProcessDropCgroupReq(SRpcMsg *pMsg) {
|
|||
}
|
||||
}
|
||||
|
||||
taosWLockLatch(&pSub->lock);
|
||||
if (taosHashGetSize(pSub->consumerHash) != 0) {
|
||||
terrno = TSDB_CODE_MND_CGROUP_USED;
|
||||
mError("cgroup:%s on topic:%s, failed to drop since %s", dropReq.cgroup, dropReq.topic, terrstr());
|
||||
mndReleaseSubscribe(pMnode, pSub);
|
||||
return -1;
|
||||
code = -1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
void *pIter = NULL;
|
||||
|
@ -765,31 +815,32 @@ static int32_t mndProcessDropCgroupReq(SRpcMsg *pMsg) {
|
|||
sdbRelease(pMnode->pSdb, pConsumer);
|
||||
}
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pMsg, "drop-cgroup");
|
||||
pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pMsg, "drop-cgroup");
|
||||
if (pTrans == NULL) {
|
||||
mError("cgroup: %s on topic:%s, failed to drop since %s", dropReq.cgroup, dropReq.topic, terrstr());
|
||||
mndReleaseSubscribe(pMnode, pSub);
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
code = -1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
mInfo("trans:%d, used to drop cgroup:%s on topic %s", pTrans->id, dropReq.cgroup, dropReq.topic);
|
||||
|
||||
if (mndSetDropSubCommitLogs(pMnode, pTrans, pSub) < 0) {
|
||||
mError("cgroup %s on topic:%s, failed to drop since %s", dropReq.cgroup, dropReq.topic, terrstr());
|
||||
mndReleaseSubscribe(pMnode, pSub);
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
code = -1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) < 0) {
|
||||
mndReleaseSubscribe(pMnode, pSub);
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
code = -1;
|
||||
goto end;
|
||||
}
|
||||
mndReleaseSubscribe(pMnode, pSub);
|
||||
|
||||
return TSDB_CODE_ACTION_IN_PROGRESS;
|
||||
end:
|
||||
taosWUnLockLatch(&pSub->lock);
|
||||
mndReleaseSubscribe(pMnode, pSub);
|
||||
mndTransDrop(pTrans);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
void mndCleanupSubscribe(SMnode *pMnode) {}
|
||||
|
@ -920,6 +971,10 @@ static int32_t mndSubActionUpdate(SSdb *pSdb, SMqSubscribeObj *pOldSub, SMqSubsc
|
|||
pOldSub->unassignedVgs = pNewSub->unassignedVgs;
|
||||
pNewSub->unassignedVgs = tmp1;
|
||||
|
||||
SArray *tmp2 = pOldSub->offsetRows;
|
||||
pOldSub->offsetRows = pNewSub->offsetRows;
|
||||
pNewSub->offsetRows = tmp2;
|
||||
|
||||
taosWUnLockLatch(&pOldSub->lock);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1084,6 +1139,65 @@ END:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t buildResult(SSDataBlock *pBlock, int32_t* numOfRows, int64_t consumerId, const char* topic, const char* cgroup, SArray* vgs, SArray *offsetRows){
|
||||
int32_t sz = taosArrayGetSize(vgs);
|
||||
for (int32_t j = 0; j < sz; j++) {
|
||||
SMqVgEp *pVgEp = taosArrayGetP(vgs, j);
|
||||
|
||||
SColumnInfoData *pColInfo;
|
||||
int32_t cols = 0;
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, *numOfRows, (const char *)topic, false);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, *numOfRows, (const char *)cgroup, false);
|
||||
|
||||
// vg id
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, *numOfRows, (const char *)&pVgEp->vgId, false);
|
||||
|
||||
// consumer id
|
||||
char consumerIdHex[32] = {0};
|
||||
sprintf(varDataVal(consumerIdHex), "0x%"PRIx64, consumerId);
|
||||
varDataSetLen(consumerIdHex, strlen(varDataVal(consumerIdHex)));
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, *numOfRows, (const char *)consumerIdHex, consumerId == -1);
|
||||
|
||||
mDebug("mnd show subscriptions: topic %s, consumer:0x%" PRIx64 " cgroup %s vgid %d", varDataVal(topic),
|
||||
consumerId, varDataVal(cgroup), pVgEp->vgId);
|
||||
|
||||
// offset
|
||||
OffsetRows *data = NULL;
|
||||
for(int i = 0; i < taosArrayGetSize(offsetRows); i++){
|
||||
OffsetRows *tmp = taosArrayGet(offsetRows, i);
|
||||
if(tmp->vgId != pVgEp->vgId){
|
||||
continue;
|
||||
}
|
||||
data = tmp;
|
||||
}
|
||||
if(data){
|
||||
// vg id
|
||||
char buf[TSDB_OFFSET_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
tFormatOffset(varDataVal(buf), TSDB_OFFSET_LEN, &data->offset);
|
||||
varDataSetLen(buf, strlen(varDataVal(buf)));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, *numOfRows, (const char *)buf, false);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, *numOfRows, (const char *)&data->rows, false);
|
||||
}else{
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetNULL(pColInfo, *numOfRows);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetNULL(pColInfo, *numOfRows);
|
||||
mError("mnd show subscriptions: do not find vgId:%d in offsetRows", pVgEp->vgId);
|
||||
}
|
||||
(*numOfRows)++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndRetrieveSubscribe(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rowsCapacity) {
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
@ -1104,6 +1218,13 @@ int32_t mndRetrieveSubscribe(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock
|
|||
blockDataEnsureCapacity(pBlock, numOfRows + pSub->vgNum);
|
||||
}
|
||||
|
||||
// topic and cgroup
|
||||
char topic[TSDB_TOPIC_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
char cgroup[TSDB_CGROUP_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
mndSplitSubscribeKey(pSub->key, varDataVal(topic), varDataVal(cgroup), false);
|
||||
varDataSetLen(topic, strlen(varDataVal(topic)));
|
||||
varDataSetLen(cgroup, strlen(varDataVal(cgroup)));
|
||||
|
||||
SMqConsumerEp *pConsumerEp = NULL;
|
||||
void *pIter = NULL;
|
||||
while (1) {
|
||||
|
@ -1111,101 +1232,11 @@ int32_t mndRetrieveSubscribe(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock
|
|||
if (pIter == NULL) break;
|
||||
pConsumerEp = (SMqConsumerEp *)pIter;
|
||||
|
||||
int32_t sz = taosArrayGetSize(pConsumerEp->vgs);
|
||||
for (int32_t j = 0; j < sz; j++) {
|
||||
SMqVgEp *pVgEp = taosArrayGetP(pConsumerEp->vgs, j);
|
||||
|
||||
SColumnInfoData *pColInfo;
|
||||
int32_t cols = 0;
|
||||
|
||||
// topic and cgroup
|
||||
char topic[TSDB_TOPIC_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
char cgroup[TSDB_CGROUP_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
mndSplitSubscribeKey(pSub->key, varDataVal(topic), varDataVal(cgroup), false);
|
||||
varDataSetLen(topic, strlen(varDataVal(topic)));
|
||||
varDataSetLen(cgroup, strlen(varDataVal(cgroup)));
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)topic, false);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)cgroup, false);
|
||||
|
||||
// vg id
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)&pVgEp->vgId, false);
|
||||
|
||||
// consumer id
|
||||
char consumerIdHex[32] = {0};
|
||||
sprintf(varDataVal(consumerIdHex), "0x%"PRIx64, pConsumerEp->consumerId);
|
||||
varDataSetLen(consumerIdHex, strlen(varDataVal(consumerIdHex)));
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)consumerIdHex, false);
|
||||
|
||||
mDebug("mnd show subscriptions: topic %s, consumer:0x%" PRIx64 " cgroup %s vgid %d", varDataVal(topic),
|
||||
pConsumerEp->consumerId, varDataVal(cgroup), pVgEp->vgId);
|
||||
|
||||
// offset
|
||||
#if 0
|
||||
// subscribe time
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)&pSub->subscribeTime, false);
|
||||
|
||||
// rebalance time
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)&pSub->rebalanceTime, pConsumer->rebalanceTime == 0);
|
||||
#endif
|
||||
|
||||
numOfRows++;
|
||||
}
|
||||
buildResult(pBlock, &numOfRows, pConsumerEp->consumerId, topic, cgroup, pConsumerEp->vgs, pConsumerEp->offsetRows);
|
||||
}
|
||||
|
||||
// do not show for cleared subscription
|
||||
int32_t sz = taosArrayGetSize(pSub->unassignedVgs);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SMqVgEp *pVgEp = taosArrayGetP(pSub->unassignedVgs, i);
|
||||
|
||||
SColumnInfoData *pColInfo;
|
||||
int32_t cols = 0;
|
||||
|
||||
// topic and cgroup
|
||||
char topic[TSDB_TOPIC_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
char cgroup[TSDB_CGROUP_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
mndSplitSubscribeKey(pSub->key, varDataVal(topic), varDataVal(cgroup), false);
|
||||
varDataSetLen(topic, strlen(varDataVal(topic)));
|
||||
varDataSetLen(cgroup, strlen(varDataVal(cgroup)));
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)topic, false);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)cgroup, false);
|
||||
|
||||
// vg id
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)&pVgEp->vgId, false);
|
||||
|
||||
// consumer id
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, NULL, true);
|
||||
|
||||
mDebug("mnd show subscriptions(unassigned): topic %s, cgroup %s vgid %d", varDataVal(topic), varDataVal(cgroup),
|
||||
pVgEp->vgId);
|
||||
|
||||
// offset
|
||||
#if 0
|
||||
// subscribe time
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)&pSub->subscribeTime, false);
|
||||
|
||||
// rebalance time
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)&pSub->rebalanceTime, pConsumer->rebalanceTime == 0);
|
||||
#endif
|
||||
|
||||
numOfRows++;
|
||||
}
|
||||
buildResult(pBlock, &numOfRows, -1, topic, cgroup, pSub->unassignedVgs, pSub->offsetRows);
|
||||
|
||||
pBlock->info.rows = numOfRows;
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "mndSync.h"
|
||||
#include "mndCluster.h"
|
||||
#include "mndTrans.h"
|
||||
#include "mndVgroup.h"
|
||||
|
||||
static int32_t mndSyncEqCtrlMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) {
|
||||
if (pMsg == NULL || pMsg->pCont == NULL) {
|
||||
|
@ -73,76 +74,200 @@ static int32_t mndSyncSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t mndProcessWriteMsg(const SSyncFSM *pFsm, SRpcMsg *pMsg, const SFsmCbMeta *pMeta) {
|
||||
SMnode *pMnode = pFsm->data;
|
||||
static int32_t mndTransValidatePrepareAction(SMnode *pMnode, STrans *pTrans, STransAction *pAction) {
|
||||
SSdbRow *pRow = NULL;
|
||||
int32_t code = -1;
|
||||
|
||||
if (pAction->msgType == TDMT_MND_CREATE_VG) {
|
||||
pRow = mndVgroupActionDecode(pAction->pRaw);
|
||||
if (pRow == NULL) goto _OUT;
|
||||
|
||||
SVgObj *pVgroup = sdbGetRowObj(pRow);
|
||||
if (pVgroup == NULL) goto _OUT;
|
||||
|
||||
int32_t maxVgId = sdbGetMaxId(pMnode->pSdb, SDB_VGROUP);
|
||||
if (maxVgId > pVgroup->vgId) {
|
||||
mError("trans:%d, failed to satisfy vgroup id %d of prepare action. maxVgId:%d", pTrans->id, pVgroup->vgId,
|
||||
maxVgId);
|
||||
goto _OUT;
|
||||
}
|
||||
}
|
||||
|
||||
code = 0;
|
||||
_OUT:
|
||||
taosMemoryFreeClear(pRow);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndTransValidatePrepareStage(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = -1;
|
||||
int32_t action = 0;
|
||||
|
||||
int32_t numOfActions = taosArrayGetSize(pTrans->prepareActions);
|
||||
if (numOfActions == 0) {
|
||||
code = 0;
|
||||
goto _OUT;
|
||||
}
|
||||
|
||||
mInfo("trans:%d, validate %d prepare actions.", pTrans->id, numOfActions);
|
||||
|
||||
for (action = 0; action < numOfActions; ++action) {
|
||||
STransAction *pAction = taosArrayGet(pTrans->prepareActions, action);
|
||||
|
||||
if (pAction->actionType != TRANS_ACTION_RAW) {
|
||||
mError("trans:%d, prepare action:%d of unexpected type:%d", pTrans->id, action, pAction->actionType);
|
||||
goto _OUT;
|
||||
}
|
||||
|
||||
code = mndTransValidatePrepareAction(pMnode, pTrans, pAction);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to validate prepare action: %d, numOfActions:%d", pTrans->id, action, numOfActions);
|
||||
goto _OUT;
|
||||
}
|
||||
}
|
||||
|
||||
code = 0;
|
||||
_OUT:
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndTransValidateImp(SMnode *pMnode, STrans *pTrans) {
|
||||
if (pTrans->stage == TRN_STAGE_PREPARE) {
|
||||
if (mndTransCheckConflict(pMnode, pTrans) < 0) {
|
||||
mError("trans:%d, failed to validate trans conflicts.", pTrans->id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return mndTransValidatePrepareStage(pMnode, pTrans);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndTransValidate(SMnode *pMnode, SSdbRaw *pRaw) {
|
||||
STrans *pTrans = NULL;
|
||||
int32_t code = -1;
|
||||
|
||||
SSdbRow *pRow = mndTransDecode(pRaw);
|
||||
if (pRow == NULL) goto _OUT;
|
||||
|
||||
pTrans = sdbGetRowObj(pRow);
|
||||
if (pTrans == NULL) goto _OUT;
|
||||
|
||||
code = mndTransValidateImp(pMnode, pTrans);
|
||||
|
||||
_OUT:
|
||||
if (pTrans) mndTransDropData(pTrans);
|
||||
if (pRow) taosMemoryFreeClear(pRow);
|
||||
if (code) terrno = (terrno ? terrno : TSDB_CODE_MND_TRANS_CONFLICT);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t mndProcessWriteMsg(SMnode *pMnode, SRpcMsg *pMsg, SFsmCbMeta *pMeta) {
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
||||
SSdbRaw *pRaw = pMsg->pCont;
|
||||
|
||||
STrans *pTrans = NULL;
|
||||
int32_t code = -1;
|
||||
int32_t transId = sdbGetIdFromRaw(pMnode->pSdb, pRaw);
|
||||
|
||||
if (transId <= 0) {
|
||||
mError("trans:%d, invalid commit msg, cache transId:%d seq:%" PRId64, transId, pMgmt->transId, pMgmt->transSeq);
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto _OUT;
|
||||
}
|
||||
|
||||
mInfo("trans:%d, is proposed, saved:%d code:0x%x, apply index:%" PRId64 " term:%" PRIu64 " config:%" PRId64
|
||||
" role:%s raw:%p sec:%d seq:%" PRId64,
|
||||
transId, pMgmt->transId, pMeta->code, pMeta->index, pMeta->term, pMeta->lastConfigIndex, syncStr(pMeta->state),
|
||||
pRaw, pMgmt->transSec, pMgmt->transSeq);
|
||||
|
||||
if (pMeta->code == 0) {
|
||||
int32_t code = sdbWriteWithoutFree(pMnode->pSdb, pRaw);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to write to sdb since %s", transId, terrstr());
|
||||
return 0;
|
||||
}
|
||||
sdbSetApplyInfo(pMnode->pSdb, pMeta->index, pMeta->term, pMeta->lastConfigIndex);
|
||||
code = mndTransValidate(pMnode, pRaw);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to validate requested trans since %s", transId, terrstr());
|
||||
code = 0;
|
||||
pMeta->code = terrno;
|
||||
goto _OUT;
|
||||
}
|
||||
|
||||
taosThreadMutexLock(&pMgmt->lock);
|
||||
pMgmt->errCode = pMeta->code;
|
||||
|
||||
if (transId <= 0) {
|
||||
taosThreadMutexUnlock(&pMgmt->lock);
|
||||
mError("trans:%d, invalid commit msg, cache transId:%d seq:%" PRId64, transId, pMgmt->transId, pMgmt->transSeq);
|
||||
} else if (transId == pMgmt->transId) {
|
||||
if (pMgmt->errCode != 0) {
|
||||
mError("trans:%d, failed to propose since %s, post sem", transId, tstrerror(pMgmt->errCode));
|
||||
} else {
|
||||
mInfo("trans:%d, is proposed and post sem, seq:%" PRId64, transId, pMgmt->transSeq);
|
||||
}
|
||||
pMgmt->transId = 0;
|
||||
pMgmt->transSec = 0;
|
||||
pMgmt->transSeq = 0;
|
||||
tsem_post(&pMgmt->syncSem);
|
||||
taosThreadMutexUnlock(&pMgmt->lock);
|
||||
} else {
|
||||
taosThreadMutexUnlock(&pMgmt->lock);
|
||||
STrans *pTrans = mndAcquireTrans(pMnode, transId);
|
||||
if (pTrans != NULL) {
|
||||
mInfo("trans:%d, execute in mnode which not leader or sync timeout, createTime:%" PRId64 " saved trans:%d",
|
||||
transId, pTrans->createdTime, pMgmt->transId);
|
||||
mndTransExecute(pMnode, pTrans, false);
|
||||
mndReleaseTrans(pMnode, pTrans);
|
||||
} else {
|
||||
mError("trans:%d, not found while execute in mnode since %s", transId, terrstr());
|
||||
}
|
||||
code = sdbWriteWithoutFree(pMnode->pSdb, pRaw);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to write to sdb since %s", transId, terrstr());
|
||||
code = 0;
|
||||
pMeta->code = terrno;
|
||||
goto _OUT;
|
||||
}
|
||||
|
||||
pTrans = mndAcquireTrans(pMnode, transId);
|
||||
if (pTrans == NULL) {
|
||||
mError("trans:%d, not found while execute in mnode since %s", transId, terrstr());
|
||||
goto _OUT;
|
||||
}
|
||||
|
||||
if (pTrans->stage == TRN_STAGE_PREPARE) {
|
||||
bool continueExec = mndTransPerformPrepareStage(pMnode, pTrans);
|
||||
if (!continueExec) goto _OUT;
|
||||
}
|
||||
|
||||
if (pTrans->id != pMgmt->transId) {
|
||||
mInfo("trans:%d, execute in mnode which not leader or sync timeout, createTime:%" PRId64 " saved trans:%d",
|
||||
pTrans->id, pTrans->createdTime, pMgmt->transId);
|
||||
mndTransRefresh(pMnode, pTrans);
|
||||
}
|
||||
|
||||
sdbSetApplyInfo(pMnode->pSdb, pMeta->index, pMeta->term, pMeta->lastConfigIndex);
|
||||
sdbWriteFile(pMnode->pSdb, tsMndSdbWriteDelta);
|
||||
code = 0;
|
||||
|
||||
_OUT:
|
||||
if (pTrans) mndReleaseTrans(pMnode, pTrans);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndPostMgmtCode(SMnode *pMnode, int32_t code) {
|
||||
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
||||
taosThreadMutexLock(&pMgmt->lock);
|
||||
if (pMgmt->transId == 0) {
|
||||
goto _OUT;
|
||||
}
|
||||
|
||||
pMgmt->transId = 0;
|
||||
pMgmt->transSec = 0;
|
||||
pMgmt->transSeq = 0;
|
||||
pMgmt->errCode = code;
|
||||
tsem_post(&pMgmt->syncSem);
|
||||
|
||||
if (pMgmt->errCode != 0) {
|
||||
mError("trans:%d, failed to propose since %s, post sem", pMgmt->transId, tstrerror(pMgmt->errCode));
|
||||
} else {
|
||||
mInfo("trans:%d, is proposed and post sem, seq:%" PRId64, pMgmt->transId, pMgmt->transSeq);
|
||||
}
|
||||
|
||||
_OUT:
|
||||
taosThreadMutexUnlock(&pMgmt->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndSyncCommitMsg(const SSyncFSM *pFsm, SRpcMsg *pMsg, const SFsmCbMeta *pMeta) {
|
||||
int32_t code = 0;
|
||||
int32_t mndSyncCommitMsg(const SSyncFSM *pFsm, SRpcMsg *pMsg, SFsmCbMeta *pMeta) {
|
||||
SMnode *pMnode = pFsm->data;
|
||||
int32_t code = pMsg->code;
|
||||
if (code != 0) {
|
||||
goto _OUT;
|
||||
}
|
||||
|
||||
pMsg->info.conn.applyIndex = pMeta->index;
|
||||
pMsg->info.conn.applyTerm = pMeta->term;
|
||||
pMeta->code = 0;
|
||||
|
||||
if (pMsg->code == 0) {
|
||||
SMnode *pMnode = pFsm->data;
|
||||
atomic_store_64(&pMnode->applied, pMsg->info.conn.applyIndex);
|
||||
}
|
||||
atomic_store_64(&pMnode->applied, pMsg->info.conn.applyIndex);
|
||||
|
||||
if (!syncUtilUserCommit(pMsg->msgType)) {
|
||||
goto _out;
|
||||
goto _OUT;
|
||||
}
|
||||
code = mndProcessWriteMsg(pFsm, pMsg, pMeta);
|
||||
|
||||
_out:
|
||||
code = mndProcessWriteMsg(pMnode, pMsg, pMeta);
|
||||
|
||||
_OUT:
|
||||
mndPostMgmtCode(pMnode, code ? code : pMeta->code);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
pMsg->pCont = NULL;
|
||||
return code;
|
||||
|
|
|
@ -377,6 +377,10 @@ static int32_t extractTopicTbInfo(SNode *pAst, SMqTopicObj *pTopic) {
|
|||
static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *pCreate, SDbObj *pDb,
|
||||
const char *userName) {
|
||||
mInfo("start to create topic:%s", pCreate->name);
|
||||
STrans *pTrans = NULL;
|
||||
int32_t code = -1;
|
||||
SNode *pAst = NULL;
|
||||
SQueryPlan *pPlan = NULL;
|
||||
|
||||
SMqTopicObj topicObj = {0};
|
||||
tstrncpy(topicObj.name, pCreate->name, TSDB_TOPIC_FNAME_LEN);
|
||||
|
@ -401,7 +405,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *
|
|||
if (pCreate->withMeta) {
|
||||
terrno = TSDB_CODE_MND_INVALID_TOPIC_OPTION;
|
||||
mError("topic:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
return -1;
|
||||
goto _OUT;
|
||||
}
|
||||
|
||||
topicObj.ast = taosStrdup(pCreate->ast);
|
||||
|
@ -409,32 +413,21 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *
|
|||
|
||||
qDebugL("topic:%s ast %s", topicObj.name, topicObj.ast);
|
||||
|
||||
SNode *pAst = NULL;
|
||||
if (nodesStringToNode(pCreate->ast, &pAst) != 0) {
|
||||
taosMemoryFree(topicObj.ast);
|
||||
taosMemoryFree(topicObj.sql);
|
||||
mError("topic:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
return -1;
|
||||
goto _OUT;
|
||||
}
|
||||
|
||||
SQueryPlan *pPlan = NULL;
|
||||
|
||||
SPlanContext cxt = {.pAstRoot = pAst, .topicQuery = true};
|
||||
if (qCreateQueryPlan(&cxt, &pPlan, NULL) != 0) {
|
||||
mError("failed to create topic:%s since %s", pCreate->name, terrstr());
|
||||
taosMemoryFree(topicObj.ast);
|
||||
taosMemoryFree(topicObj.sql);
|
||||
nodesDestroyNode(pAst);
|
||||
return -1;
|
||||
goto _OUT;
|
||||
}
|
||||
|
||||
topicObj.ntbColIds = taosArrayInit(0, sizeof(int16_t));
|
||||
if (topicObj.ntbColIds == NULL) {
|
||||
taosMemoryFree(topicObj.ast);
|
||||
taosMemoryFree(topicObj.sql);
|
||||
nodesDestroyNode(pAst);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
goto _OUT;
|
||||
}
|
||||
|
||||
extractTopicTbInfo(pAst, &topicObj);
|
||||
|
@ -446,25 +439,18 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *
|
|||
|
||||
if (qExtractResultSchema(pAst, &topicObj.schema.nCols, &topicObj.schema.pSchema) != 0) {
|
||||
mError("topic:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
taosMemoryFree(topicObj.ast);
|
||||
taosMemoryFree(topicObj.sql);
|
||||
nodesDestroyNode(pAst);
|
||||
return -1;
|
||||
goto _OUT;
|
||||
}
|
||||
|
||||
if (nodesNodeToString((SNode *)pPlan, false, &topicObj.physicalPlan, NULL) != 0) {
|
||||
mError("topic:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
taosMemoryFree(topicObj.ast);
|
||||
taosMemoryFree(topicObj.sql);
|
||||
return -1;
|
||||
goto _OUT;
|
||||
}
|
||||
nodesDestroyNode(pAst);
|
||||
nodesDestroyNode((SNode *)pPlan);
|
||||
} else if (pCreate->subType == TOPIC_SUB_TYPE__TABLE) {
|
||||
SStbObj *pStb = mndAcquireStb(pMnode, pCreate->subStbName);
|
||||
if (pStb == NULL) {
|
||||
terrno = TSDB_CODE_MND_STB_NOT_EXIST;
|
||||
return -1;
|
||||
goto _OUT;
|
||||
}
|
||||
|
||||
strcpy(topicObj.stbName, pCreate->subStbName);
|
||||
|
@ -483,23 +469,22 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *
|
|||
/*topicObj.withTbName = 1;*/
|
||||
/*topicObj.withSchema = 1;*/
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq, "create-topic");
|
||||
pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_DB_INSIDE, pReq, "create-topic");
|
||||
if (pTrans == NULL) {
|
||||
mError("topic:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
taosMemoryFreeClear(topicObj.ast);
|
||||
taosMemoryFreeClear(topicObj.sql);
|
||||
taosMemoryFreeClear(topicObj.physicalPlan);
|
||||
return -1;
|
||||
goto _OUT;
|
||||
}
|
||||
|
||||
mndTransSetDbName(pTrans, pDb->name, NULL);
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) {
|
||||
goto _OUT;
|
||||
}
|
||||
mInfo("trans:%d to create topic:%s", pTrans->id, pCreate->name);
|
||||
|
||||
SSdbRaw *pCommitRaw = mndTopicActionEncode(&topicObj);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
||||
taosMemoryFreeClear(topicObj.physicalPlan);
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
goto _OUT;
|
||||
}
|
||||
|
||||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||
|
@ -528,17 +513,16 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *
|
|||
tEncodeSize(tEncodeSTqCheckInfo, &info, len, code);
|
||||
if (code < 0) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
goto _OUT;
|
||||
}
|
||||
void *buf = taosMemoryCalloc(1, sizeof(SMsgHead) + len);
|
||||
void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead));
|
||||
SEncoder encoder;
|
||||
tEncoderInit(&encoder, abuf, len);
|
||||
if (tEncodeSTqCheckInfo(&encoder, &info) < 0) {
|
||||
taosMemoryFree(buf);
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
goto _OUT;
|
||||
}
|
||||
tEncoderClear(&encoder);
|
||||
((SMsgHead *)buf)->vgId = htonl(pVgroup->vgId);
|
||||
|
@ -551,32 +535,32 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *
|
|||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(buf);
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
goto _OUT;
|
||||
}
|
||||
|
||||
buf = NULL;
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
}
|
||||
}
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
taosMemoryFreeClear(topicObj.physicalPlan);
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
goto _OUT;
|
||||
}
|
||||
|
||||
code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||
|
||||
_OUT:
|
||||
taosMemoryFreeClear(topicObj.physicalPlan);
|
||||
taosMemoryFreeClear(topicObj.sql);
|
||||
taosMemoryFreeClear(topicObj.ast);
|
||||
taosArrayDestroy(topicObj.ntbColIds);
|
||||
|
||||
if (topicObj.schema.nCols) {
|
||||
taosMemoryFreeClear(topicObj.schema.pSchema);
|
||||
}
|
||||
|
||||
nodesDestroyNode(pAst);
|
||||
nodesDestroyNode((SNode *)pPlan);
|
||||
mndTransDrop(pTrans);
|
||||
return TSDB_CODE_ACTION_IN_PROGRESS;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateTopicReq(SRpcMsg *pReq) {
|
||||
|
@ -762,7 +746,7 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
|
|||
}
|
||||
|
||||
mndTransSetDbName(pTrans, pTopic->db, NULL);
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) {
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) {
|
||||
mndReleaseTopic(pMnode, pTopic);
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
|
|
|
@ -23,28 +23,25 @@
|
|||
#include "mndSync.h"
|
||||
#include "mndUser.h"
|
||||
|
||||
#define TRANS_VER_NUMBER 1
|
||||
#define TRANS_VER1_NUMBER 1
|
||||
#define TRANS_VER2_NUMBER 2
|
||||
#define TRANS_ARRAY_SIZE 8
|
||||
#define TRANS_RESERVE_SIZE 48
|
||||
|
||||
static SSdbRaw *mndTransActionEncode(STrans *pTrans);
|
||||
static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw);
|
||||
static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans);
|
||||
static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *OldTrans, STrans *pOld);
|
||||
static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans, bool callFunc);
|
||||
static int32_t mndTransDelete(SSdb *pSdb, STrans *pTrans, bool callFunc);
|
||||
|
||||
static int32_t mndTransAppendLog(SArray *pArray, SSdbRaw *pRaw);
|
||||
static int32_t mndTransAppendAction(SArray *pArray, STransAction *pAction);
|
||||
static void mndTransDropLogs(SArray *pArray);
|
||||
static void mndTransDropActions(SArray *pArray);
|
||||
static void mndTransDropData(STrans *pTrans);
|
||||
static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pArray);
|
||||
static int32_t mndTransExecuteRedoLogs(SMnode *pMnode, STrans *pTrans);
|
||||
static int32_t mndTransExecuteUndoLogs(SMnode *pMnode, STrans *pTrans);
|
||||
static int32_t mndTransExecuteRedoActions(SMnode *pMnode, STrans *pTrans);
|
||||
static int32_t mndTransExecuteUndoActions(SMnode *pMnode, STrans *pTrans);
|
||||
static int32_t mndTransExecuteCommitActions(SMnode *pMnode, STrans *pTrans);
|
||||
static bool mndTransPerformPrepareStage(SMnode *pMnode, STrans *pTrans);
|
||||
static bool mndTransPerformRedoLogStage(SMnode *pMnode, STrans *pTrans);
|
||||
static bool mndTransPerformRedoActionStage(SMnode *pMnode, STrans *pTrans);
|
||||
static bool mndTransPerformUndoLogStage(SMnode *pMnode, STrans *pTrans);
|
||||
|
@ -52,7 +49,7 @@ static bool mndTransPerformUndoActionStage(SMnode *pMnode, STrans *pTrans);
|
|||
static bool mndTransPerformCommitActionStage(SMnode *pMnode, STrans *pTrans);
|
||||
static bool mndTransPerformCommitStage(SMnode *pMnode, STrans *pTrans);
|
||||
static bool mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans);
|
||||
static bool mndTransPerfromFinishedStage(SMnode *pMnode, STrans *pTrans);
|
||||
static bool mndTransPerformFinishStage(SMnode *pMnode, STrans *pTrans);
|
||||
static bool mndCannotExecuteTransAction(SMnode *pMnode) { return !pMnode->deploy && !mndIsLeader(pMnode); }
|
||||
|
||||
static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans);
|
||||
|
@ -67,11 +64,11 @@ int32_t mndInitTrans(SMnode *pMnode) {
|
|||
SSdbTable table = {
|
||||
.sdbType = SDB_TRANS,
|
||||
.keyType = SDB_KEY_INT32,
|
||||
.encodeFp = (SdbEncodeFp)mndTransActionEncode,
|
||||
.decodeFp = (SdbDecodeFp)mndTransActionDecode,
|
||||
.encodeFp = (SdbEncodeFp)mndTransEncode,
|
||||
.decodeFp = (SdbDecodeFp)mndTransDecode,
|
||||
.insertFp = (SdbInsertFp)mndTransActionInsert,
|
||||
.updateFp = (SdbUpdateFp)mndTransActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mndTransActionDelete,
|
||||
.deleteFp = (SdbDeleteFp)mndTransDelete,
|
||||
};
|
||||
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_TRANS_TIMER, mndProcessTransTimer);
|
||||
|
@ -103,15 +100,55 @@ static int32_t mndTransGetActionsSize(SArray *pArray) {
|
|||
return rawDataLen;
|
||||
}
|
||||
|
||||
static SSdbRaw *mndTransActionEncode(STrans *pTrans) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
static int32_t mndTransEncodeAction(SSdbRaw *pRaw, int32_t *offset, SArray *pActions, int32_t actionsNum) {
|
||||
int32_t dataPos = *offset;
|
||||
int8_t unused = 0;
|
||||
int32_t ret = -1;
|
||||
|
||||
for (int32_t i = 0; i < actionsNum; ++i) {
|
||||
STransAction *pAction = taosArrayGet(pActions, i);
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->id, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->errCode, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->acceptableCode, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->retryCode, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pAction->actionType, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pAction->stage, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pAction->reserved, _OVER)
|
||||
if (pAction->actionType == TRANS_ACTION_RAW) {
|
||||
int32_t len = sdbGetRawTotalSize(pAction->pRaw);
|
||||
SDB_SET_INT8(pRaw, dataPos, unused /*pAction->rawWritten*/, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, len, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pAction->pRaw, len, _OVER)
|
||||
} else if (pAction->actionType == TRANS_ACTION_MSG) {
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet), _OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, pAction->msgType, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, unused /*pAction->msgSent*/, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, unused /*pAction->msgReceived*/, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->contLen, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pAction->pCont, pAction->contLen, _OVER)
|
||||
} else {
|
||||
// nothing
|
||||
}
|
||||
}
|
||||
ret = 0;
|
||||
|
||||
_OVER:
|
||||
*offset = dataPos;
|
||||
return ret;
|
||||
}
|
||||
|
||||
SSdbRaw *mndTransEncode(STrans *pTrans) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
int8_t sver = taosArrayGetSize(pTrans->prepareActions) ? TRANS_VER2_NUMBER : TRANS_VER1_NUMBER;
|
||||
|
||||
int32_t rawDataLen = sizeof(STrans) + TRANS_RESERVE_SIZE + pTrans->paramLen;
|
||||
rawDataLen += mndTransGetActionsSize(pTrans->prepareActions);
|
||||
rawDataLen += mndTransGetActionsSize(pTrans->redoActions);
|
||||
rawDataLen += mndTransGetActionsSize(pTrans->undoActions);
|
||||
rawDataLen += mndTransGetActionsSize(pTrans->commitActions);
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_TRANS, TRANS_VER_NUMBER, rawDataLen);
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_TRANS, sver, rawDataLen);
|
||||
if (pRaw == NULL) {
|
||||
mError("trans:%d, failed to alloc raw since %s", pTrans->id, terrstr());
|
||||
return NULL;
|
||||
|
@ -131,91 +168,22 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) {
|
|||
SDB_SET_BINARY(pRaw, dataPos, pTrans->stbname, TSDB_TABLE_FNAME_LEN, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pTrans->redoActionPos, _OVER)
|
||||
|
||||
int32_t prepareActionNum = taosArrayGetSize(pTrans->prepareActions);
|
||||
int32_t redoActionNum = taosArrayGetSize(pTrans->redoActions);
|
||||
int32_t undoActionNum = taosArrayGetSize(pTrans->undoActions);
|
||||
int32_t commitActionNum = taosArrayGetSize(pTrans->commitActions);
|
||||
|
||||
if (sver > TRANS_VER1_NUMBER) {
|
||||
SDB_SET_INT32(pRaw, dataPos, prepareActionNum, _OVER)
|
||||
}
|
||||
SDB_SET_INT32(pRaw, dataPos, redoActionNum, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, undoActionNum, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, commitActionNum, _OVER)
|
||||
|
||||
int8_t unused = 0;
|
||||
for (int32_t i = 0; i < redoActionNum; ++i) {
|
||||
STransAction *pAction = taosArrayGet(pTrans->redoActions, i);
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->id, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->errCode, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->acceptableCode, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->retryCode, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pAction->actionType, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pAction->stage, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pAction->reserved, _OVER)
|
||||
if (pAction->actionType == TRANS_ACTION_RAW) {
|
||||
int32_t len = sdbGetRawTotalSize(pAction->pRaw);
|
||||
SDB_SET_INT8(pRaw, dataPos, unused /*pAction->rawWritten*/, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, len, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pAction->pRaw, len, _OVER)
|
||||
} else if (pAction->actionType == TRANS_ACTION_MSG) {
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet), _OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, pAction->msgType, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, unused /*pAction->msgSent*/, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, unused /*pAction->msgReceived*/, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->contLen, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pAction->pCont, pAction->contLen, _OVER)
|
||||
} else {
|
||||
// nothing
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < undoActionNum; ++i) {
|
||||
STransAction *pAction = taosArrayGet(pTrans->undoActions, i);
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->id, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->errCode, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->acceptableCode, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->retryCode, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pAction->actionType, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pAction->stage, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pAction->reserved, _OVER)
|
||||
if (pAction->actionType == TRANS_ACTION_RAW) {
|
||||
int32_t len = sdbGetRawTotalSize(pAction->pRaw);
|
||||
SDB_SET_INT8(pRaw, dataPos, unused /*pAction->rawWritten*/, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, len, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pAction->pRaw, len, _OVER)
|
||||
} else if (pAction->actionType == TRANS_ACTION_MSG) {
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet), _OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, pAction->msgType, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, unused /*pAction->msgSent*/, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, unused /*pAction->msgReceived*/, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->contLen, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pAction->pCont, pAction->contLen, _OVER)
|
||||
} else {
|
||||
// nothing
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < commitActionNum; ++i) {
|
||||
STransAction *pAction = taosArrayGet(pTrans->commitActions, i);
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->id, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->errCode, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->acceptableCode, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->retryCode, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pAction->actionType, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pAction->stage, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pAction->reserved, _OVER)
|
||||
if (pAction->actionType == TRANS_ACTION_RAW) {
|
||||
int32_t len = sdbGetRawTotalSize(pAction->pRaw);
|
||||
SDB_SET_INT8(pRaw, dataPos, unused /*pAction->rawWritten*/, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, len, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pAction->pRaw, len, _OVER)
|
||||
} else if (pAction->actionType == TRANS_ACTION_MSG) {
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet), _OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, pAction->msgType, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, unused /*pAction->msgSent*/, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, unused /*pAction->msgReceived*/, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->contLen, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pAction->pCont, pAction->contLen, _OVER)
|
||||
} else {
|
||||
// nothing
|
||||
}
|
||||
}
|
||||
if (mndTransEncodeAction(pRaw, &dataPos, pTrans->prepareActions, prepareActionNum) < 0) goto _OVER;
|
||||
if (mndTransEncodeAction(pRaw, &dataPos, pTrans->redoActions, redoActionNum) < 0) goto _OVER;
|
||||
if (mndTransEncodeAction(pRaw, &dataPos, pTrans->undoActions, undoActionNum) < 0) goto _OVER;
|
||||
if (mndTransEncodeAction(pRaw, &dataPos, pTrans->commitActions, commitActionNum) < 0) goto _OVER;
|
||||
|
||||
SDB_SET_INT32(pRaw, dataPos, pTrans->startFunc, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pTrans->stopFunc, _OVER)
|
||||
|
@ -242,23 +210,76 @@ _OVER:
|
|||
return pRaw;
|
||||
}
|
||||
|
||||
static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
static int32_t mndTransDecodeAction(SSdbRaw *pRaw, int32_t *offset, SArray *pActions, int32_t actionNum) {
|
||||
STransAction action = {0};
|
||||
int32_t dataPos = *offset;
|
||||
int8_t unused = 0;
|
||||
int8_t stage = 0;
|
||||
int8_t actionType = 0;
|
||||
int32_t dataLen = 0;
|
||||
int32_t ret = -1;
|
||||
|
||||
for (int32_t i = 0; i < actionNum; ++i) {
|
||||
memset(&action, 0, sizeof(action));
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.id, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.errCode, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.acceptableCode, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.retryCode, _OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &actionType, _OVER)
|
||||
action.actionType = actionType;
|
||||
SDB_GET_INT8(pRaw, dataPos, &stage, _OVER)
|
||||
action.stage = stage;
|
||||
SDB_GET_INT8(pRaw, dataPos, &action.reserved, _OVER)
|
||||
if (action.actionType == TRANS_ACTION_RAW) {
|
||||
SDB_GET_INT8(pRaw, dataPos, &unused /*&action.rawWritten*/, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &dataLen, _OVER)
|
||||
action.pRaw = taosMemoryMalloc(dataLen);
|
||||
if (action.pRaw == NULL) goto _OVER;
|
||||
mTrace("raw:%p, is created", action.pRaw);
|
||||
SDB_GET_BINARY(pRaw, dataPos, (void *)action.pRaw, dataLen, _OVER);
|
||||
if (taosArrayPush(pActions, &action) == NULL) goto _OVER;
|
||||
action.pRaw = NULL;
|
||||
} else if (action.actionType == TRANS_ACTION_MSG) {
|
||||
SDB_GET_BINARY(pRaw, dataPos, (void *)&action.epSet, sizeof(SEpSet), _OVER);
|
||||
tmsgUpdateDnodeEpSet(&action.epSet);
|
||||
SDB_GET_INT16(pRaw, dataPos, &action.msgType, _OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &unused /*&action.msgSent*/, _OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &unused /*&action.msgReceived*/, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.contLen, _OVER)
|
||||
action.pCont = taosMemoryMalloc(action.contLen);
|
||||
if (action.pCont == NULL) goto _OVER;
|
||||
SDB_GET_BINARY(pRaw, dataPos, action.pCont, action.contLen, _OVER);
|
||||
if (taosArrayPush(pActions, &action) == NULL) goto _OVER;
|
||||
action.pCont = NULL;
|
||||
} else {
|
||||
if (taosArrayPush(pActions, &action) == NULL) goto _OVER;
|
||||
}
|
||||
}
|
||||
ret = 0;
|
||||
|
||||
_OVER:
|
||||
*offset = dataPos;
|
||||
taosMemoryFreeClear(action.pCont);
|
||||
return ret;
|
||||
}
|
||||
|
||||
SSdbRow *mndTransDecode(SSdbRaw *pRaw) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
|
||||
SSdbRow *pRow = NULL;
|
||||
STrans *pTrans = NULL;
|
||||
char *pData = NULL;
|
||||
int32_t dataLen = 0;
|
||||
int8_t sver = 0;
|
||||
int32_t prepareActionNum = 0;
|
||||
int32_t redoActionNum = 0;
|
||||
int32_t undoActionNum = 0;
|
||||
int32_t commitActionNum = 0;
|
||||
int32_t dataPos = 0;
|
||||
STransAction action = {0};
|
||||
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
|
||||
|
||||
if (sver != TRANS_VER_NUMBER) {
|
||||
if (sver != TRANS_VER1_NUMBER && sver != TRANS_VER2_NUMBER) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -294,127 +315,28 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
|
|||
SDB_GET_BINARY(pRaw, dataPos, pTrans->dbname, TSDB_TABLE_FNAME_LEN, _OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pTrans->stbname, TSDB_TABLE_FNAME_LEN, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pTrans->redoActionPos, _OVER)
|
||||
|
||||
if (sver > TRANS_VER1_NUMBER) {
|
||||
SDB_GET_INT32(pRaw, dataPos, &prepareActionNum, _OVER)
|
||||
}
|
||||
SDB_GET_INT32(pRaw, dataPos, &redoActionNum, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &undoActionNum, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &commitActionNum, _OVER)
|
||||
|
||||
pTrans->prepareActions = taosArrayInit(prepareActionNum, sizeof(STransAction));
|
||||
pTrans->redoActions = taosArrayInit(redoActionNum, sizeof(STransAction));
|
||||
pTrans->undoActions = taosArrayInit(undoActionNum, sizeof(STransAction));
|
||||
pTrans->commitActions = taosArrayInit(commitActionNum, sizeof(STransAction));
|
||||
|
||||
if (pTrans->prepareActions == NULL) goto _OVER;
|
||||
if (pTrans->redoActions == NULL) goto _OVER;
|
||||
if (pTrans->undoActions == NULL) goto _OVER;
|
||||
if (pTrans->commitActions == NULL) goto _OVER;
|
||||
|
||||
int8_t unused = 0;
|
||||
for (int32_t i = 0; i < redoActionNum; ++i) {
|
||||
memset(&action, 0, sizeof(action));
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.id, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.errCode, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.acceptableCode, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.retryCode, _OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &actionType, _OVER)
|
||||
action.actionType = actionType;
|
||||
SDB_GET_INT8(pRaw, dataPos, &stage, _OVER)
|
||||
action.stage = stage;
|
||||
SDB_GET_INT8(pRaw, dataPos, &action.reserved, _OVER)
|
||||
if (action.actionType == TRANS_ACTION_RAW) {
|
||||
SDB_GET_INT8(pRaw, dataPos, &unused /*&action.rawWritten*/, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &dataLen, _OVER)
|
||||
action.pRaw = taosMemoryMalloc(dataLen);
|
||||
if (action.pRaw == NULL) goto _OVER;
|
||||
mTrace("raw:%p, is created", action.pRaw);
|
||||
SDB_GET_BINARY(pRaw, dataPos, (void *)action.pRaw, dataLen, _OVER);
|
||||
if (taosArrayPush(pTrans->redoActions, &action) == NULL) goto _OVER;
|
||||
action.pRaw = NULL;
|
||||
} else if (action.actionType == TRANS_ACTION_MSG) {
|
||||
SDB_GET_BINARY(pRaw, dataPos, (void *)&action.epSet, sizeof(SEpSet), _OVER);
|
||||
tmsgUpdateDnodeEpSet(&action.epSet);
|
||||
SDB_GET_INT16(pRaw, dataPos, &action.msgType, _OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &unused /*&action.msgSent*/, _OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &unused /*&action.msgReceived*/, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.contLen, _OVER)
|
||||
action.pCont = taosMemoryMalloc(action.contLen);
|
||||
if (action.pCont == NULL) goto _OVER;
|
||||
SDB_GET_BINARY(pRaw, dataPos, action.pCont, action.contLen, _OVER);
|
||||
if (taosArrayPush(pTrans->redoActions, &action) == NULL) goto _OVER;
|
||||
action.pCont = NULL;
|
||||
} else {
|
||||
if (taosArrayPush(pTrans->redoActions, &action) == NULL) goto _OVER;
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < undoActionNum; ++i) {
|
||||
memset(&action, 0, sizeof(action));
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.id, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.errCode, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.acceptableCode, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.retryCode, _OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &actionType, _OVER)
|
||||
action.actionType = actionType;
|
||||
SDB_GET_INT8(pRaw, dataPos, &stage, _OVER)
|
||||
action.stage = stage;
|
||||
SDB_GET_INT8(pRaw, dataPos, &action.reserved, _OVER)
|
||||
if (action.actionType == TRANS_ACTION_RAW) {
|
||||
SDB_GET_INT8(pRaw, dataPos, &unused /*&action.rawWritten*/, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &dataLen, _OVER)
|
||||
action.pRaw = taosMemoryMalloc(dataLen);
|
||||
if (action.pRaw == NULL) goto _OVER;
|
||||
mTrace("raw:%p, is created", action.pRaw);
|
||||
SDB_GET_BINARY(pRaw, dataPos, (void *)action.pRaw, dataLen, _OVER);
|
||||
if (taosArrayPush(pTrans->undoActions, &action) == NULL) goto _OVER;
|
||||
action.pRaw = NULL;
|
||||
} else if (action.actionType == TRANS_ACTION_MSG) {
|
||||
SDB_GET_BINARY(pRaw, dataPos, (void *)&action.epSet, sizeof(SEpSet), _OVER);
|
||||
SDB_GET_INT16(pRaw, dataPos, &action.msgType, _OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &unused /*&action.msgSent*/, _OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &unused /*&action.msgReceived*/, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.contLen, _OVER)
|
||||
action.pCont = taosMemoryMalloc(action.contLen);
|
||||
if (action.pCont == NULL) goto _OVER;
|
||||
SDB_GET_BINARY(pRaw, dataPos, action.pCont, action.contLen, _OVER);
|
||||
if (taosArrayPush(pTrans->undoActions, &action) == NULL) goto _OVER;
|
||||
action.pCont = NULL;
|
||||
} else {
|
||||
if (taosArrayPush(pTrans->undoActions, &action) == NULL) goto _OVER;
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < commitActionNum; ++i) {
|
||||
memset(&action, 0, sizeof(action));
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.id, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.errCode, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.acceptableCode, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.retryCode, _OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &actionType, _OVER)
|
||||
action.actionType = actionType;
|
||||
SDB_GET_INT8(pRaw, dataPos, &stage, _OVER)
|
||||
action.stage = stage;
|
||||
SDB_GET_INT8(pRaw, dataPos, &action.reserved, _OVER)
|
||||
if (action.actionType) {
|
||||
SDB_GET_INT8(pRaw, dataPos, &unused /*&action.rawWritten*/, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &dataLen, _OVER)
|
||||
action.pRaw = taosMemoryMalloc(dataLen);
|
||||
if (action.pRaw == NULL) goto _OVER;
|
||||
mTrace("raw:%p, is created", action.pRaw);
|
||||
SDB_GET_BINARY(pRaw, dataPos, (void *)action.pRaw, dataLen, _OVER);
|
||||
if (taosArrayPush(pTrans->commitActions, &action) == NULL) goto _OVER;
|
||||
action.pRaw = NULL;
|
||||
} else if (action.actionType == TRANS_ACTION_MSG) {
|
||||
SDB_GET_BINARY(pRaw, dataPos, (void *)&action.epSet, sizeof(SEpSet), _OVER);
|
||||
SDB_GET_INT16(pRaw, dataPos, &action.msgType, _OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &unused /*&action.msgSent*/, _OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &unused /*&action.msgReceived*/, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.contLen, _OVER)
|
||||
action.pCont = taosMemoryMalloc(action.contLen);
|
||||
if (action.pCont == NULL) goto _OVER;
|
||||
SDB_GET_BINARY(pRaw, dataPos, action.pCont, action.contLen, _OVER);
|
||||
if (taosArrayPush(pTrans->commitActions, &action) == NULL) goto _OVER;
|
||||
action.pCont = NULL;
|
||||
} else {
|
||||
if (taosArrayPush(pTrans->redoActions, &action) == NULL) goto _OVER;
|
||||
}
|
||||
}
|
||||
if (mndTransDecodeAction(pRaw, &dataPos, pTrans->prepareActions, prepareActionNum) < 0) goto _OVER;
|
||||
if (mndTransDecodeAction(pRaw, &dataPos, pTrans->redoActions, redoActionNum) < 0) goto _OVER;
|
||||
if (mndTransDecodeAction(pRaw, &dataPos, pTrans->undoActions, undoActionNum) < 0) goto _OVER;
|
||||
if (mndTransDecodeAction(pRaw, &dataPos, pTrans->commitActions, commitActionNum) < 0) goto _OVER;
|
||||
|
||||
SDB_GET_INT32(pRaw, dataPos, &pTrans->startFunc, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pTrans->stopFunc, _OVER)
|
||||
|
@ -434,7 +356,6 @@ _OVER:
|
|||
mError("trans:%d, failed to parse from raw:%p since %s", pTrans->id, pRaw, terrstr());
|
||||
mndTransDropData(pTrans);
|
||||
taosMemoryFreeClear(pRow);
|
||||
taosMemoryFreeClear(action.pCont);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -458,7 +379,7 @@ static const char *mndTransStr(ETrnStage stage) {
|
|||
return "commit";
|
||||
case TRN_STAGE_COMMIT_ACTION:
|
||||
return "commitAction";
|
||||
case TRN_STAGE_FINISHED:
|
||||
case TRN_STAGE_FINISH:
|
||||
return "finished";
|
||||
case TRN_STAGE_PRE_FINISH:
|
||||
return "pre-finish";
|
||||
|
@ -519,7 +440,11 @@ static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void mndTransDropData(STrans *pTrans) {
|
||||
void mndTransDropData(STrans *pTrans) {
|
||||
if (pTrans->prepareActions != NULL) {
|
||||
mndTransDropActions(pTrans->prepareActions);
|
||||
pTrans->prepareActions = NULL;
|
||||
}
|
||||
if (pTrans->redoActions != NULL) {
|
||||
mndTransDropActions(pTrans->redoActions);
|
||||
pTrans->redoActions = NULL;
|
||||
|
@ -549,7 +474,7 @@ static void mndTransDropData(STrans *pTrans) {
|
|||
(void)taosThreadMutexDestroy(&pTrans->mutex);
|
||||
}
|
||||
|
||||
static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans, bool callFunc) {
|
||||
static int32_t mndTransDelete(SSdb *pSdb, STrans *pTrans, bool callFunc) {
|
||||
mInfo("trans:%d, perform delete action, row:%p stage:%s callfunc:%d, stopFunc:%d", pTrans->id, pTrans,
|
||||
mndTransStr(pTrans->stage), callFunc, pTrans->stopFunc);
|
||||
|
||||
|
@ -586,10 +511,11 @@ static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pOld, STrans *pNew) {
|
|||
pOld->id, pOld, mndTransStr(pOld->stage), pOld->createdTime, pNew, mndTransStr(pNew->stage),
|
||||
pNew->createdTime);
|
||||
// only occured while sync timeout
|
||||
terrno = TSDB_CODE_MND_TRNAS_SYNC_TIMEOUT;
|
||||
terrno = TSDB_CODE_MND_TRANS_SYNC_TIMEOUT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
mndTransUpdateActions(pOld->prepareActions, pNew->prepareActions);
|
||||
mndTransUpdateActions(pOld->redoActions, pNew->redoActions);
|
||||
mndTransUpdateActions(pOld->undoActions, pNew->undoActions);
|
||||
mndTransUpdateActions(pOld->commitActions, pNew->commitActions);
|
||||
|
@ -607,7 +533,7 @@ static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pOld, STrans *pNew) {
|
|||
}
|
||||
|
||||
if (pOld->stage == TRN_STAGE_PRE_FINISH) {
|
||||
pOld->stage = TRN_STAGE_FINISHED;
|
||||
pOld->stage = TRN_STAGE_FINISH;
|
||||
mTrace("trans:%d, stage from pre-finish to finished since perform update action", pNew->id);
|
||||
}
|
||||
|
||||
|
@ -646,6 +572,7 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, ETrnConflct conflict,
|
|||
pTrans->conflict = conflict;
|
||||
pTrans->exec = TRN_EXEC_PARALLEL;
|
||||
pTrans->createdTime = taosGetTimestampMs();
|
||||
pTrans->prepareActions = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(STransAction));
|
||||
pTrans->redoActions = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(STransAction));
|
||||
pTrans->undoActions = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(STransAction));
|
||||
pTrans->commitActions = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(STransAction));
|
||||
|
@ -728,6 +655,13 @@ int32_t mndTransAppendCommitlog(STrans *pTrans, SSdbRaw *pRaw) {
|
|||
return mndTransAppendAction(pTrans->commitActions, &action);
|
||||
}
|
||||
|
||||
int32_t mndTransAppendPrepareAction(STrans *pTrans, STransAction *pAction) {
|
||||
pAction->stage = TRN_STAGE_PREPARE;
|
||||
pAction->actionType = TRANS_ACTION_RAW;
|
||||
pAction->mTraceId = pTrans->mTraceId;
|
||||
return mndTransAppendAction(pTrans->prepareActions, pAction);
|
||||
}
|
||||
|
||||
int32_t mndTransAppendRedoAction(STrans *pTrans, STransAction *pAction) {
|
||||
pAction->stage = TRN_STAGE_REDO_ACTION;
|
||||
pAction->actionType = TRANS_ACTION_MSG;
|
||||
|
@ -800,7 +734,7 @@ void mndTransSetParallel(STrans *pTrans) { pTrans->exec = TRN_EXEC_PARALLEL; }
|
|||
void mndTransSetOper(STrans *pTrans, EOperType oper) { pTrans->oper = oper; }
|
||||
|
||||
static int32_t mndTransSync(SMnode *pMnode, STrans *pTrans) {
|
||||
SSdbRaw *pRaw = mndTransActionEncode(pTrans);
|
||||
SSdbRaw *pRaw = mndTransEncode(pTrans);
|
||||
if (pRaw == NULL) {
|
||||
mError("trans:%d, failed to encode while sync trans since %s", pTrans->id, terrstr());
|
||||
return -1;
|
||||
|
@ -872,7 +806,7 @@ static bool mndCheckTransConflict(SMnode *pMnode, STrans *pNew) {
|
|||
return conflict;
|
||||
}
|
||||
|
||||
int32_t mndTrancCheckConflict(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t mndTransCheckConflict(SMnode *pMnode, STrans *pTrans) {
|
||||
if (pTrans->conflict == TRN_CONFLICT_DB || pTrans->conflict == TRN_CONFLICT_DB_INSIDE) {
|
||||
if (strlen(pTrans->dbname) == 0 && strlen(pTrans->stbname) == 0) {
|
||||
terrno = TSDB_CODE_MND_TRANS_CONFLICT;
|
||||
|
@ -891,7 +825,7 @@ int32_t mndTrancCheckConflict(SMnode *pMnode, STrans *pTrans) {
|
|||
}
|
||||
|
||||
int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) {
|
||||
if (mndTrancCheckConflict(pMnode, pTrans) != 0) {
|
||||
if (mndTransCheckConflict(pMnode, pTrans) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -922,7 +856,7 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) {
|
|||
pTrans->rpcRsp = NULL;
|
||||
pTrans->rpcRspLen = 0;
|
||||
|
||||
mndTransExecute(pMnode, pNew, true);
|
||||
mndTransExecute(pMnode, pNew);
|
||||
mndReleaseTrans(pMnode, pNew);
|
||||
return 0;
|
||||
}
|
||||
|
@ -961,7 +895,7 @@ static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) {
|
|||
bool sendRsp = false;
|
||||
int32_t code = pTrans->code;
|
||||
|
||||
if (pTrans->stage == TRN_STAGE_FINISHED) {
|
||||
if (pTrans->stage == TRN_STAGE_FINISH) {
|
||||
sendRsp = true;
|
||||
}
|
||||
|
||||
|
@ -1003,7 +937,7 @@ static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) {
|
|||
code = TSDB_CODE_MND_TRANS_NETWORK_UNAVAILL;
|
||||
}
|
||||
if (code == TSDB_CODE_SYN_TIMEOUT) {
|
||||
code = TSDB_CODE_MND_TRNAS_SYNC_TIMEOUT;
|
||||
code = TSDB_CODE_MND_TRANS_SYNC_TIMEOUT;
|
||||
}
|
||||
|
||||
if (i != 0 && code == 0) {
|
||||
|
@ -1104,7 +1038,7 @@ int32_t mndTransProcessRsp(SRpcMsg *pRsp) {
|
|||
mInfo("trans:%d, invalid action, index:%d, code:0x%x", transId, action, pRsp->code);
|
||||
}
|
||||
|
||||
mndTransExecute(pMnode, pTrans, true);
|
||||
mndTransExecute(pMnode, pTrans);
|
||||
|
||||
_OVER:
|
||||
mndReleaseTrans(pMnode, pTrans);
|
||||
|
@ -1392,8 +1326,25 @@ static int32_t mndTransExecuteRedoActionsSerial(SMnode *pMnode, STrans *pTrans)
|
|||
return code;
|
||||
}
|
||||
|
||||
static bool mndTransPerformPrepareStage(SMnode *pMnode, STrans *pTrans) {
|
||||
bool mndTransPerformPrepareStage(SMnode *pMnode, STrans *pTrans) {
|
||||
bool continueExec = true;
|
||||
int32_t code = 0;
|
||||
|
||||
int32_t numOfActions = taosArrayGetSize(pTrans->prepareActions);
|
||||
if (numOfActions == 0) goto _OVER;
|
||||
|
||||
mInfo("trans:%d, execute %d prepare actions.", pTrans->id, numOfActions);
|
||||
|
||||
for (int32_t action = 0; action < numOfActions; ++action) {
|
||||
STransAction *pAction = taosArrayGet(pTrans->prepareActions, action);
|
||||
code = mndTransExecSingleAction(pMnode, pTrans, pAction);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to execute prepare action:%d, numOfActions:%d", pTrans->id, action, numOfActions);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
_OVER:
|
||||
pTrans->stage = TRN_STAGE_REDO_ACTION;
|
||||
mInfo("trans:%d, stage from prepare to redoAction", pTrans->id);
|
||||
return continueExec;
|
||||
|
@ -1476,7 +1427,7 @@ static bool mndTransPerformCommitActionStage(SMnode *pMnode, STrans *pTrans) {
|
|||
|
||||
if (code == 0) {
|
||||
pTrans->code = 0;
|
||||
pTrans->stage = TRN_STAGE_FINISHED; // TRN_STAGE_PRE_FINISH is not necessary
|
||||
pTrans->stage = TRN_STAGE_FINISH; // TRN_STAGE_PRE_FINISH is not necessary
|
||||
mInfo("trans:%d, stage from commitAction to finished", pTrans->id);
|
||||
continueExec = true;
|
||||
} else {
|
||||
|
@ -1528,14 +1479,14 @@ static bool mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans) {
|
|||
return continueExec;
|
||||
}
|
||||
|
||||
static bool mndTransPerfromPreFinishedStage(SMnode *pMnode, STrans *pTrans) {
|
||||
static bool mndTransPerformPreFinishStage(SMnode *pMnode, STrans *pTrans) {
|
||||
if (mndCannotExecuteTransAction(pMnode)) return false;
|
||||
|
||||
bool continueExec = true;
|
||||
int32_t code = mndTransPreFinish(pMnode, pTrans);
|
||||
|
||||
if (code == 0) {
|
||||
pTrans->stage = TRN_STAGE_FINISHED;
|
||||
pTrans->stage = TRN_STAGE_FINISH;
|
||||
mInfo("trans:%d, stage from pre-finish to finish", pTrans->id);
|
||||
continueExec = true;
|
||||
} else {
|
||||
|
@ -1547,10 +1498,10 @@ static bool mndTransPerfromPreFinishedStage(SMnode *pMnode, STrans *pTrans) {
|
|||
return continueExec;
|
||||
}
|
||||
|
||||
static bool mndTransPerfromFinishedStage(SMnode *pMnode, STrans *pTrans) {
|
||||
static bool mndTransPerformFinishStage(SMnode *pMnode, STrans *pTrans) {
|
||||
bool continueExec = false;
|
||||
|
||||
SSdbRaw *pRaw = mndTransActionEncode(pTrans);
|
||||
SSdbRaw *pRaw = mndTransEncode(pTrans);
|
||||
if (pRaw == NULL) {
|
||||
mError("trans:%d, failed to encode while finish trans since %s", pTrans->id, terrstr());
|
||||
return false;
|
||||
|
@ -1567,12 +1518,12 @@ static bool mndTransPerfromFinishedStage(SMnode *pMnode, STrans *pTrans) {
|
|||
return continueExec;
|
||||
}
|
||||
|
||||
void mndTransExecute(SMnode *pMnode, STrans *pTrans, bool isLeader) {
|
||||
void mndTransExecuteImp(SMnode *pMnode, STrans *pTrans, bool topHalf) {
|
||||
bool continueExec = true;
|
||||
|
||||
while (continueExec) {
|
||||
mInfo("trans:%d, continue to execute, stage:%s createTime:%" PRId64 " leader:%d", pTrans->id,
|
||||
mndTransStr(pTrans->stage), pTrans->createdTime, isLeader);
|
||||
mInfo("trans:%d, continue to execute, stage:%s createTime:%" PRId64 " topHalf:%d", pTrans->id,
|
||||
mndTransStr(pTrans->stage), pTrans->createdTime, topHalf);
|
||||
pTrans->lastExecTime = taosGetTimestampMs();
|
||||
switch (pTrans->stage) {
|
||||
case TRN_STAGE_PREPARE:
|
||||
|
@ -1582,7 +1533,7 @@ void mndTransExecute(SMnode *pMnode, STrans *pTrans, bool isLeader) {
|
|||
continueExec = mndTransPerformRedoActionStage(pMnode, pTrans);
|
||||
break;
|
||||
case TRN_STAGE_COMMIT:
|
||||
if (isLeader) {
|
||||
if (topHalf) {
|
||||
continueExec = mndTransPerformCommitStage(pMnode, pTrans);
|
||||
} else {
|
||||
mInfo("trans:%d, can not commit since not leader", pTrans->id);
|
||||
|
@ -1593,7 +1544,7 @@ void mndTransExecute(SMnode *pMnode, STrans *pTrans, bool isLeader) {
|
|||
continueExec = mndTransPerformCommitActionStage(pMnode, pTrans);
|
||||
break;
|
||||
case TRN_STAGE_ROLLBACK:
|
||||
if (isLeader) {
|
||||
if (topHalf) {
|
||||
continueExec = mndTransPerformRollbackStage(pMnode, pTrans);
|
||||
} else {
|
||||
mInfo("trans:%d, can not rollback since not leader", pTrans->id);
|
||||
|
@ -1604,15 +1555,15 @@ void mndTransExecute(SMnode *pMnode, STrans *pTrans, bool isLeader) {
|
|||
continueExec = mndTransPerformUndoActionStage(pMnode, pTrans);
|
||||
break;
|
||||
case TRN_STAGE_PRE_FINISH:
|
||||
if (isLeader) {
|
||||
continueExec = mndTransPerfromPreFinishedStage(pMnode, pTrans);
|
||||
if (topHalf) {
|
||||
continueExec = mndTransPerformPreFinishStage(pMnode, pTrans);
|
||||
} else {
|
||||
mInfo("trans:%d, can not pre-finish since not leader", pTrans->id);
|
||||
continueExec = false;
|
||||
}
|
||||
break;
|
||||
case TRN_STAGE_FINISHED:
|
||||
continueExec = mndTransPerfromFinishedStage(pMnode, pTrans);
|
||||
case TRN_STAGE_FINISH:
|
||||
continueExec = mndTransPerformFinishStage(pMnode, pTrans);
|
||||
break;
|
||||
default:
|
||||
continueExec = false;
|
||||
|
@ -1623,6 +1574,16 @@ void mndTransExecute(SMnode *pMnode, STrans *pTrans, bool isLeader) {
|
|||
mndTransSendRpcRsp(pMnode, pTrans);
|
||||
}
|
||||
|
||||
void mndTransExecute(SMnode *pMnode, STrans *pTrans) {
|
||||
bool topHalf = true;
|
||||
return mndTransExecuteImp(pMnode, pTrans, topHalf);
|
||||
}
|
||||
|
||||
void mndTransRefresh(SMnode *pMnode, STrans *pTrans) {
|
||||
bool topHalf = false;
|
||||
return mndTransExecuteImp(pMnode, pTrans, topHalf);
|
||||
}
|
||||
|
||||
static int32_t mndProcessTransTimer(SRpcMsg *pReq) {
|
||||
mTrace("start to process trans timer");
|
||||
mndTransPullup(pReq->info.node);
|
||||
|
@ -1649,7 +1610,7 @@ int32_t mndKillTrans(SMnode *pMnode, STrans *pTrans) {
|
|||
pAction->errCode = 0;
|
||||
}
|
||||
|
||||
mndTransExecute(pMnode, pTrans, true);
|
||||
mndTransExecute(pMnode, pTrans);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1707,7 +1668,7 @@ void mndTransPullup(SMnode *pMnode) {
|
|||
int32_t *pTransId = taosArrayGet(pArray, i);
|
||||
STrans *pTrans = mndAcquireTrans(pMnode, *pTransId);
|
||||
if (pTrans != NULL) {
|
||||
mndTransExecute(pMnode, pTrans, true);
|
||||
mndTransExecute(pMnode, pTrans);
|
||||
}
|
||||
mndReleaseTrans(pMnode, pTrans);
|
||||
}
|
||||
|
|
|
@ -488,7 +488,7 @@ SHashObj *mndDupUseDbHash(SHashObj *pOld) {
|
|||
return pNew;
|
||||
}
|
||||
|
||||
static int32_t mndUserDupObj(SUserObj *pUser, SUserObj *pNew) {
|
||||
int32_t mndUserDupObj(SUserObj *pUser, SUserObj *pNew) {
|
||||
memcpy(pNew, pUser, sizeof(SUserObj));
|
||||
pNew->authVersion++;
|
||||
pNew->updateTime = taosGetTimestampMs();
|
||||
|
@ -508,7 +508,7 @@ static int32_t mndUserDupObj(SUserObj *pUser, SUserObj *pNew) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void mndUserFreeObj(SUserObj *pUser) {
|
||||
void mndUserFreeObj(SUserObj *pUser) {
|
||||
taosHashCleanup(pUser->readDbs);
|
||||
taosHashCleanup(pUser->writeDbs);
|
||||
taosHashCleanup(pUser->topics);
|
||||
|
|
|
@ -20,15 +20,16 @@
|
|||
#include "mndMnode.h"
|
||||
#include "mndPrivilege.h"
|
||||
#include "mndShow.h"
|
||||
#include "mndStb.h"
|
||||
#include "mndStream.h"
|
||||
#include "mndTopic.h"
|
||||
#include "mndTrans.h"
|
||||
#include "mndUser.h"
|
||||
#include "tmisce.h"
|
||||
#include "mndStb.h"
|
||||
|
||||
#define VGROUP_VER_NUMBER 1
|
||||
#define VGROUP_RESERVE_SIZE 64
|
||||
|
||||
static SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw);
|
||||
static int32_t mndVgroupActionInsert(SSdb *pSdb, SVgObj *pVgroup);
|
||||
static int32_t mndVgroupActionDelete(SSdb *pSdb, SVgObj *pVgroup);
|
||||
static int32_t mndVgroupActionUpdate(SSdb *pSdb, SVgObj *pOld, SVgObj *pNew);
|
||||
|
@ -483,15 +484,15 @@ static void *mndBuildDisableVnodeWriteReq(SMnode *pMnode, SDbObj *pDb, int32_t v
|
|||
return pReq;
|
||||
}
|
||||
|
||||
static void *mndBuildAlterVnodeHashRangeReq(SMnode *pMnode, SVgObj *pVgroup, int32_t dstVgId, int32_t *pContLen) {
|
||||
static void *mndBuildAlterVnodeHashRangeReq(SMnode *pMnode, int32_t srcVgId, SVgObj *pVgroup, int32_t *pContLen) {
|
||||
SAlterVnodeHashRangeReq alterReq = {
|
||||
.srcVgId = pVgroup->vgId,
|
||||
.dstVgId = dstVgId,
|
||||
.srcVgId = srcVgId,
|
||||
.dstVgId = pVgroup->vgId,
|
||||
.hashBegin = pVgroup->hashBegin,
|
||||
.hashEnd = pVgroup->hashEnd,
|
||||
};
|
||||
|
||||
mInfo("vgId:%d, build alter vnode hashrange req, dstVgId:%d, hashrange:[%u, %u]", pVgroup->vgId, dstVgId,
|
||||
mInfo("vgId:%d, build alter vnode hashrange req, dstVgId:%d, hashrange:[%u, %u]", srcVgId, pVgroup->vgId,
|
||||
pVgroup->hashBegin, pVgroup->hashEnd);
|
||||
int32_t contLen = tSerializeSAlterVnodeHashRangeReq(NULL, 0, &alterReq);
|
||||
if (contLen < 0) {
|
||||
|
@ -1207,17 +1208,18 @@ int32_t mndAddAlterVnodeConfirmAction(SMnode *pMnode, STrans *pTrans, SDbObj *pD
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndAddAlterVnodeHashRangeAction(SMnode *pMnode, STrans *pTrans, SVgObj *pVgroup, int32_t dstVgId) {
|
||||
static int32_t mndAddAlterVnodeHashRangeAction(SMnode *pMnode, STrans *pTrans, int32_t srcVgId, SVgObj *pVgroup) {
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildAlterVnodeHashRangeReq(pMnode, pVgroup, dstVgId, &contLen);
|
||||
void *pReq = mndBuildAlterVnodeHashRangeReq(pMnode, srcVgId, pVgroup, &contLen);
|
||||
if (pReq == NULL) return -1;
|
||||
|
||||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_VND_ALTER_HASHRANGE;
|
||||
action.acceptableCode = TSDB_CODE_VND_ALREADY_EXIST;
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
|
@ -1247,6 +1249,21 @@ int32_t mndAddAlterVnodeConfigAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndAddPrepareNewVgAction(SMnode *pMnode, STrans *pTrans, SVgObj *pVg) {
|
||||
SSdbRaw *pRaw = mndVgroupActionEncode(pVg);
|
||||
if (pRaw == NULL) goto _err;
|
||||
|
||||
STransAction action = {.pRaw = pRaw, .msgType = TDMT_MND_CREATE_VG};
|
||||
if (mndTransAppendPrepareAction(pTrans, &action) != 0) goto _err;
|
||||
(void)sdbSetRawStatus(pRaw, SDB_STATUS_CREATING);
|
||||
pRaw = NULL;
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
sdbFreeRaw(pRaw);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t mndAddAlterVnodeReplicaAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, int32_t dnodeId) {
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, dnodeId);
|
||||
if (pDnode == NULL) return -1;
|
||||
|
@ -2241,10 +2258,13 @@ static int32_t mndAddAdjustVnodeHashRangeAction(SMnode *pMnode, STrans *pTrans,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndTransCommitVgStatus(STrans *pTrans, SVgObj *pVg, ESdbStatus vgStatus) {
|
||||
typedef int32_t (*FpTransActionCb)(STrans *pTrans, SSdbRaw *pRaw);
|
||||
|
||||
static int32_t mndAddVgStatusAction(STrans *pTrans, SVgObj *pVg, ESdbStatus vgStatus, ETrnStage stage) {
|
||||
FpTransActionCb appendActionCb = (stage == TRN_STAGE_COMMIT_ACTION) ? mndTransAppendCommitlog : mndTransAppendRedolog;
|
||||
SSdbRaw *pRaw = mndVgroupActionEncode(pVg);
|
||||
if (pRaw == NULL) goto _err;
|
||||
if (mndTransAppendCommitlog(pTrans, pRaw) != 0) goto _err;
|
||||
if (appendActionCb(pTrans, pRaw) != 0) goto _err;
|
||||
(void)sdbSetRawStatus(pRaw, vgStatus);
|
||||
pRaw = NULL;
|
||||
return 0;
|
||||
|
@ -2253,18 +2273,50 @@ _err:
|
|||
return -1;
|
||||
}
|
||||
|
||||
static int32_t mndAddDbStatusAction(STrans *pTrans, SDbObj *pDb, ESdbStatus dbStatus, ETrnStage stage) {
|
||||
FpTransActionCb appendActionCb = (stage == TRN_STAGE_COMMIT_ACTION) ? mndTransAppendCommitlog : mndTransAppendRedolog;
|
||||
SSdbRaw *pRaw = mndDbActionEncode(pDb);
|
||||
if (pRaw == NULL) goto _err;
|
||||
if (appendActionCb(pTrans, pRaw) != 0) goto _err;
|
||||
(void)sdbSetRawStatus(pRaw, dbStatus);
|
||||
pRaw = NULL;
|
||||
return 0;
|
||||
_err:
|
||||
sdbFreeRaw(pRaw);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t mndSplitVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SVgObj *pVgroup) {
|
||||
int32_t code = -1;
|
||||
STrans *pTrans = NULL;
|
||||
SSdbRaw *pRaw = NULL;
|
||||
SDbObj dbObj = {0};
|
||||
SArray *pArray = mndBuildDnodesArray(pMnode, 0);
|
||||
|
||||
pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq, "split-vgroup");
|
||||
int32_t numOfTopics = 0;
|
||||
if (mndGetNumOfTopics(pMnode, pDb->name, &numOfTopics) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
if (numOfTopics > 0) {
|
||||
terrno = TSDB_CODE_MND_TOPIC_MUST_BE_DELETED;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
int32_t numOfStreams = 0;
|
||||
if (mndGetNumOfStreams(pMnode, pDb->name, &numOfStreams) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
if (numOfStreams > 0) {
|
||||
terrno = TSDB_CODE_MND_STREAM_MUST_BE_DELETED;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB, pReq, "split-vgroup");
|
||||
if (pTrans == NULL) goto _OVER;
|
||||
mndTransSetSerial(pTrans);
|
||||
mInfo("trans:%d, used to split vgroup, vgId:%d", pTrans->id, pVgroup->vgId);
|
||||
|
||||
mndTransSetDbName(pTrans, pDb->name, NULL);
|
||||
|
||||
SVgObj newVg1 = {0};
|
||||
memcpy(&newVg1, pVgroup, sizeof(SVgObj));
|
||||
mInfo("vgId:%d, vgroup info before split, replica:%d hashBegin:%u hashEnd:%u", newVg1.vgId, newVg1.replica,
|
||||
|
@ -2316,32 +2368,25 @@ int32_t mndSplitVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SVgObj *pVgro
|
|||
|
||||
// alter vgId and hash range
|
||||
int32_t maxVgId = sdbGetMaxId(pMnode->pSdb, SDB_VGROUP);
|
||||
if (mndAddAlterVnodeHashRangeAction(pMnode, pTrans, &newVg1, maxVgId) != 0) goto _OVER;
|
||||
int32_t srcVgId = newVg1.vgId;
|
||||
newVg1.vgId = maxVgId;
|
||||
if (mndAddPrepareNewVgAction(pMnode, pTrans, &newVg1) != 0) goto _OVER;
|
||||
if (mndAddAlterVnodeHashRangeAction(pMnode, pTrans, srcVgId, &newVg1) != 0) goto _OVER;
|
||||
|
||||
maxVgId++;
|
||||
if (mndAddAlterVnodeHashRangeAction(pMnode, pTrans, &newVg2, maxVgId) != 0) goto _OVER;
|
||||
srcVgId = newVg2.vgId;
|
||||
newVg2.vgId = maxVgId;
|
||||
if (mndAddPrepareNewVgAction(pMnode, pTrans, &newVg2) != 0) goto _OVER;
|
||||
if (mndAddAlterVnodeHashRangeAction(pMnode, pTrans, srcVgId, &newVg2) != 0) goto _OVER;
|
||||
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg1) != 0) goto _OVER;
|
||||
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg2) != 0) goto _OVER;
|
||||
|
||||
// adjust vgroup replica
|
||||
if (pDb->cfg.replications != newVg1.replica) {
|
||||
if (mndBuildAlterVgroupAction(pMnode, pTrans, pDb, pDb, &newVg1, pArray) != 0) goto _OVER;
|
||||
} else {
|
||||
if (mndTransCommitVgStatus(pTrans, &newVg1, SDB_STATUS_READY) < 0) goto _OVER;
|
||||
}
|
||||
|
||||
if (pDb->cfg.replications != newVg2.replica) {
|
||||
if (mndBuildAlterVgroupAction(pMnode, pTrans, pDb, pDb, &newVg2, pArray) != 0) goto _OVER;
|
||||
} else {
|
||||
if (mndTransCommitVgStatus(pTrans, &newVg2, SDB_STATUS_READY) < 0) goto _OVER;
|
||||
}
|
||||
|
||||
if (mndTransCommitVgStatus(pTrans, pVgroup, SDB_STATUS_DROPPED) < 0) goto _OVER;
|
||||
if (mndAddVgStatusAction(pTrans, &newVg1, SDB_STATUS_READY, TRN_STAGE_REDO_ACTION) < 0) goto _OVER;
|
||||
if (mndAddVgStatusAction(pTrans, &newVg2, SDB_STATUS_READY, TRN_STAGE_REDO_ACTION) < 0) goto _OVER;
|
||||
if (mndAddVgStatusAction(pTrans, pVgroup, SDB_STATUS_DROPPED, TRN_STAGE_REDO_ACTION) < 0) goto _OVER;
|
||||
|
||||
// update db status
|
||||
memcpy(&dbObj, pDb, sizeof(SDbObj));
|
||||
if (dbObj.cfg.pRetensions != NULL) {
|
||||
dbObj.cfg.pRetensions = taosArrayDup(pDb->cfg.pRetensions, NULL);
|
||||
|
@ -2350,11 +2395,27 @@ int32_t mndSplitVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SVgObj *pVgro
|
|||
dbObj.vgVersion++;
|
||||
dbObj.updateTime = taosGetTimestampMs();
|
||||
dbObj.cfg.numOfVgroups++;
|
||||
pRaw = mndDbActionEncode(&dbObj);
|
||||
if (pRaw == NULL) goto _OVER;
|
||||
if (mndTransAppendCommitlog(pTrans, pRaw) != 0) goto _OVER;
|
||||
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
pRaw = NULL;
|
||||
if (mndAddDbStatusAction(pTrans, &dbObj, SDB_STATUS_READY, TRN_STAGE_REDO_ACTION) < 0) goto _OVER;
|
||||
|
||||
// adjust vgroup replica
|
||||
if (pDb->cfg.replications != newVg1.replica) {
|
||||
if (mndBuildAlterVgroupAction(pMnode, pTrans, pDb, pDb, &newVg1, pArray) != 0) goto _OVER;
|
||||
} else {
|
||||
if (mndAddVgStatusAction(pTrans, &newVg1, SDB_STATUS_READY, TRN_STAGE_COMMIT_ACTION) < 0) goto _OVER;
|
||||
}
|
||||
|
||||
if (pDb->cfg.replications != newVg2.replica) {
|
||||
if (mndBuildAlterVgroupAction(pMnode, pTrans, pDb, pDb, &newVg2, pArray) != 0) goto _OVER;
|
||||
} else {
|
||||
if (mndAddVgStatusAction(pTrans, &newVg2, SDB_STATUS_READY, TRN_STAGE_COMMIT_ACTION) < 0) goto _OVER;
|
||||
}
|
||||
|
||||
if (mndAddVgStatusAction(pTrans, pVgroup, SDB_STATUS_DROPPED, TRN_STAGE_COMMIT_ACTION) < 0) goto _OVER;
|
||||
|
||||
// commit db status
|
||||
dbObj.vgVersion++;
|
||||
dbObj.updateTime = taosGetTimestampMs();
|
||||
if (mndAddDbStatusAction(pTrans, &dbObj, SDB_STATUS_READY, TRN_STAGE_COMMIT_ACTION) < 0) goto _OVER;
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
code = 0;
|
||||
|
@ -2362,7 +2423,6 @@ int32_t mndSplitVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SVgObj *pVgro
|
|||
_OVER:
|
||||
taosArrayDestroy(pArray);
|
||||
mndTransDrop(pTrans);
|
||||
sdbFreeRaw(pRaw);
|
||||
taosArrayDestroy(dbObj.cfg.pRetensions);
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -122,6 +122,7 @@ typedef enum {
|
|||
SDB_STATUS_DROPPING = 2,
|
||||
SDB_STATUS_DROPPED = 3,
|
||||
SDB_STATUS_READY = 4,
|
||||
SDB_STATUS_UPDATE = 5,
|
||||
} ESdbStatus;
|
||||
|
||||
typedef enum {
|
||||
|
|
|
@ -256,6 +256,7 @@ int32_t sdbWriteWithoutFree(SSdb *pSdb, SSdbRaw *pRaw) {
|
|||
code = sdbInsertRow(pSdb, hash, pRaw, pRow, keySize);
|
||||
break;
|
||||
case SDB_STATUS_READY:
|
||||
case SDB_STATUS_UPDATE:
|
||||
case SDB_STATUS_DROPPING:
|
||||
code = sdbUpdateRow(pSdb, hash, pRaw, pRow, keySize);
|
||||
break;
|
||||
|
|
|
@ -27,6 +27,7 @@ target_sources(
|
|||
"src/meta/metaEntry.c"
|
||||
"src/meta/metaSnapshot.c"
|
||||
"src/meta/metaCache.c"
|
||||
"src/meta/metaTtl.c"
|
||||
|
||||
# sma
|
||||
"src/sma/smaEnv.c"
|
||||
|
|
|
@ -54,6 +54,7 @@ void vnodeCleanup();
|
|||
int32_t vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs);
|
||||
int32_t vnodeAlterReplica(const char *path, SAlterVnodeReplicaReq *pReq, STfs *pTfs);
|
||||
int32_t vnodeAlterHashRange(const char *srcPath, const char *dstPath, SAlterVnodeHashRangeReq *pReq, STfs *pTfs);
|
||||
int32_t vnodeRestoreVgroupId(const char *srcPath, const char *dstPath, int32_t srcVgId, int32_t dstVgId, STfs *pTfs);
|
||||
void vnodeDestroy(const char *path, STfs *pTfs);
|
||||
SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb);
|
||||
void vnodePreClose(SVnode *pVnode);
|
||||
|
@ -114,6 +115,7 @@ int metaGetTableNameByUid(void *meta, uint64_t uid, char *tbName);
|
|||
int metaGetTableSzNameByUid(void *meta, uint64_t uid, char *tbName);
|
||||
int metaGetTableUidByName(void *pVnode, char *tbName, uint64_t *uid);
|
||||
int metaGetTableTypeByName(void *meta, char *tbName, ETableType *tbType);
|
||||
int metaGetTableTtlByUid(void *meta, uint64_t uid, int64_t *ttlDays);
|
||||
bool metaIsTableExist(void* pVnode, tb_uid_t uid);
|
||||
int32_t metaGetCachedTableUidList(void *pVnode, tb_uid_t suid, const uint8_t *key, int32_t keyLen, SArray *pList,
|
||||
bool *acquired);
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#define _TD_VNODE_META_H_
|
||||
|
||||
#include "index.h"
|
||||
#include "metaTtl.h"
|
||||
#include "vnodeInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -89,10 +90,10 @@ struct SMeta {
|
|||
// ivt idx and idx
|
||||
void* pTagIvtIdx;
|
||||
|
||||
TTB* pTagIdx;
|
||||
TTB* pTtlIdx;
|
||||
TTB* pTagIdx;
|
||||
STtlManger* pTtlMgr;
|
||||
|
||||
TTB* pCtimeIdx; // table created time idx
|
||||
TTB* pBtimeIdx; // table created time idx
|
||||
TTB* pNcolIdx; // ncol of table idx, normal table only
|
||||
|
||||
TTB* pSmaIdx;
|
||||
|
@ -138,20 +139,15 @@ typedef struct {
|
|||
} STagIdxKey;
|
||||
#pragma pack(pop)
|
||||
|
||||
typedef struct {
|
||||
int64_t dtime;
|
||||
tb_uid_t uid;
|
||||
} STtlIdxKey;
|
||||
|
||||
typedef struct {
|
||||
tb_uid_t uid;
|
||||
int64_t smaUid;
|
||||
} SSmaIdxKey;
|
||||
|
||||
typedef struct {
|
||||
int64_t ctime;
|
||||
int64_t btime;
|
||||
tb_uid_t uid;
|
||||
} SCtimeIdxKey;
|
||||
} SBtimeIdxKey;
|
||||
|
||||
typedef struct {
|
||||
int64_t ncol;
|
||||
|
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_VNODE_TTL_H_
|
||||
#define _TD_VNODE_TTL_H_
|
||||
|
||||
#include "taosdef.h"
|
||||
#include "thash.h"
|
||||
|
||||
#include "tdb.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum DirtyEntryType {
|
||||
ENTRY_TYPE_DEL = 1,
|
||||
ENTRY_TYPE_UPSERT = 2,
|
||||
} DirtyEntryType;
|
||||
|
||||
typedef struct STtlManger {
|
||||
TdThreadRwlock lock;
|
||||
|
||||
TTB* pOldTtlIdx; // btree<{deleteTime, tuid}, NULL>
|
||||
|
||||
SHashObj* pTtlCache; // key: tuid, value: {ttl, ctime}
|
||||
SHashObj* pDirtyUids; // dirty tuid
|
||||
TTB* pTtlIdx; // btree<{deleteTime, tuid}, ttl>
|
||||
} STtlManger;
|
||||
|
||||
typedef struct {
|
||||
int64_t ttlDays;
|
||||
int64_t changeTimeMs;
|
||||
} STtlCacheEntry;
|
||||
|
||||
typedef struct {
|
||||
DirtyEntryType type;
|
||||
} STtlDirtyEntry;
|
||||
|
||||
typedef struct {
|
||||
int64_t deleteTimeSec;
|
||||
tb_uid_t uid;
|
||||
} STtlIdxKey;
|
||||
|
||||
typedef struct {
|
||||
int64_t deleteTimeMs;
|
||||
tb_uid_t uid;
|
||||
} STtlIdxKeyV1;
|
||||
|
||||
typedef struct {
|
||||
int64_t ttlDays;
|
||||
} STtlIdxValue;
|
||||
|
||||
typedef struct {
|
||||
tb_uid_t uid;
|
||||
int64_t changeTimeMs;
|
||||
} STtlUpdCtimeCtx;
|
||||
|
||||
typedef struct {
|
||||
tb_uid_t uid;
|
||||
int64_t changeTimeMs;
|
||||
int64_t ttlDays;
|
||||
} STtlUpdTtlCtx;
|
||||
|
||||
typedef struct {
|
||||
tb_uid_t uid;
|
||||
TXN* pTxn;
|
||||
} STtlDelTtlCtx;
|
||||
|
||||
int ttlMgrOpen(STtlManger** ppTtlMgr, TDB* pEnv, int8_t rollback);
|
||||
int ttlMgrClose(STtlManger* pTtlMgr);
|
||||
int ttlMgrBegin(STtlManger* pTtlMgr, void* pMeta);
|
||||
|
||||
int ttlMgrConvert(TTB* pOldTtlIdx, TTB* pNewTtlIdx, void* pMeta);
|
||||
int ttlMgrFlush(STtlManger* pTtlMgr, TXN* pTxn);
|
||||
|
||||
int ttlMgrInsertTtl(STtlManger* pTtlMgr, const STtlUpdTtlCtx* pUpdCtx);
|
||||
int ttlMgrDeleteTtl(STtlManger* pTtlMgr, const STtlDelTtlCtx* pDelCtx);
|
||||
int ttlMgrUpdateChangeTime(STtlManger* pTtlMgr, const STtlUpdCtimeCtx* pUpdCtimeCtx);
|
||||
int ttlMgrFindExpired(STtlManger* pTtlMgr, int64_t timePointMs, SArray* pTbUids);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_VNODE_TTL_H_*/
|
|
@ -107,10 +107,12 @@ struct SQueryNode {
|
|||
typedef SVCreateTbReq STbCfg;
|
||||
typedef SVCreateTSmaReq SSmaCfg;
|
||||
|
||||
SMTbCursor *metaOpenTbCursor(void *pVnode);
|
||||
void metaCloseTbCursor(SMTbCursor *pTbCur);
|
||||
int32_t metaTbCursorNext(SMTbCursor *pTbCur, ETableType jumpTableType);
|
||||
int32_t metaTbCursorPrev(SMTbCursor *pTbCur, ETableType jumpTableType);
|
||||
SMTbCursor* metaOpenTbCursor(void* pVnode);
|
||||
void metaCloseTbCursor(SMTbCursor* pTbCur);
|
||||
void metaPauseTbCursor(SMTbCursor* pTbCur);
|
||||
void metaResumeTbCursor(SMTbCursor* pTbCur, int8_t first);
|
||||
int32_t metaTbCursorNext(SMTbCursor* pTbCur, ETableType jumpTableType);
|
||||
int32_t metaTbCursorPrev(SMTbCursor* pTbCur, ETableType jumpTableType);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -146,16 +148,18 @@ int metaAlterSTable(SMeta* pMeta, int64_t version, SVCreateStbReq* p
|
|||
int metaDropSTable(SMeta* pMeta, int64_t verison, SVDropStbReq* pReq, SArray* tbUidList);
|
||||
int metaCreateTable(SMeta* pMeta, int64_t version, SVCreateTbReq* pReq, STableMetaRsp** pMetaRsp);
|
||||
int metaDropTable(SMeta* pMeta, int64_t version, SVDropTbReq* pReq, SArray* tbUids, int64_t* tbUid);
|
||||
int metaTtlDropTable(SMeta* pMeta, int64_t ttl, SArray* tbUids);
|
||||
int32_t metaTrimTables(SMeta* pMeta);
|
||||
int metaTtlDropTable(SMeta* pMeta, int64_t timePointMs, SArray* tbUids);
|
||||
int metaAlterTable(SMeta* pMeta, int64_t version, SVAlterTbReq* pReq, STableMetaRsp* pMetaRsp);
|
||||
int metaUpdateChangeTime(SMeta* pMeta, tb_uid_t uid, int64_t changeTimeMs);
|
||||
SSchemaWrapper* metaGetTableSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, int lock);
|
||||
STSchema* metaGetTbTSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, int lock);
|
||||
int32_t metaGetTbTSchemaEx(SMeta* pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sver, STSchema** ppTSchema);
|
||||
int metaGetTableEntryByName(SMetaReader* pReader, const char* name);
|
||||
int metaAlterCache(SMeta* pMeta, int32_t nPage);
|
||||
|
||||
int32_t metaUidCacheClear(SMeta* pMeta, uint64_t suid);
|
||||
int32_t metaTbGroupCacheClear(SMeta *pMeta, uint64_t suid);
|
||||
int32_t metaUidCacheClear(SMeta* pMeta, uint64_t suid);
|
||||
int32_t metaTbGroupCacheClear(SMeta* pMeta, uint64_t suid);
|
||||
|
||||
int metaAddIndexToSTable(SMeta* pMeta, int64_t version, SVCreateStbReq* pReq);
|
||||
int metaDropIndexFromSTable(SMeta* pMeta, int64_t version, SDropIndexReq* pReq);
|
||||
|
@ -173,9 +177,8 @@ SArray* metaGetSmaIdsByTable(SMeta* pMeta, tb_uid_t uid);
|
|||
SArray* metaGetSmaTbUids(SMeta* pMeta);
|
||||
void* metaGetIdx(SMeta* pMeta);
|
||||
void* metaGetIvtIdx(SMeta* pMeta);
|
||||
int metaTtlSmaller(SMeta* pMeta, uint64_t time, SArray* uidList);
|
||||
|
||||
void metaReaderInit(SMetaReader *pReader, SMeta *pMeta, int32_t flags);
|
||||
void metaReaderInit(SMetaReader* pReader, SMeta* pMeta, int32_t flags);
|
||||
|
||||
int32_t metaCreateTSma(SMeta* pMeta, int64_t version, SSmaCfg* pCfg);
|
||||
int32_t metaDropTSma(SMeta* pMeta, int64_t indexUid);
|
||||
|
@ -492,7 +495,6 @@ struct SCompactInfo {
|
|||
|
||||
void initStorageAPI(SStorageAPI* pAPI);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -40,6 +40,12 @@ int metaBegin(SMeta *pMeta, int8_t heap) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (ttlMgrBegin(pMeta->pTtlMgr, pMeta) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tdbCommit(pMeta->pEnv, pMeta->txn);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -50,6 +56,7 @@ int metaFinishCommit(SMeta *pMeta, TXN *txn) { return tdbPostCommit(pMeta->pEnv
|
|||
int metaPrepareAsyncCommit(SMeta *pMeta) {
|
||||
// return tdbPrepareAsyncCommit(pMeta->pEnv, pMeta->txn);
|
||||
int code = 0;
|
||||
code = ttlMgrFlush(pMeta->pTtlMgr, pMeta->txn);
|
||||
code = tdbCommit(pMeta->pEnv, pMeta->txn);
|
||||
|
||||
return code;
|
||||
|
|
|
@ -31,7 +31,7 @@ int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
|
|||
if (tEncodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam) < 0) return -1;
|
||||
}
|
||||
} else if (pME->type == TSDB_CHILD_TABLE) {
|
||||
if (tEncodeI64(pCoder, pME->ctbEntry.ctime) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pME->ctbEntry.btime) < 0) return -1;
|
||||
if (tEncodeI32(pCoder, pME->ctbEntry.ttlDays) < 0) return -1;
|
||||
if (tEncodeI32v(pCoder, pME->ctbEntry.commentLen) < 0) return -1;
|
||||
if (pME->ctbEntry.commentLen > 0) {
|
||||
|
@ -40,7 +40,7 @@ int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
|
|||
if (tEncodeI64(pCoder, pME->ctbEntry.suid) < 0) return -1;
|
||||
if (tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags) < 0) return -1;
|
||||
} else if (pME->type == TSDB_NORMAL_TABLE) {
|
||||
if (tEncodeI64(pCoder, pME->ntbEntry.ctime) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pME->ntbEntry.btime) < 0) return -1;
|
||||
if (tEncodeI32(pCoder, pME->ntbEntry.ttlDays) < 0) return -1;
|
||||
if (tEncodeI32v(pCoder, pME->ntbEntry.commentLen) < 0) return -1;
|
||||
if (pME->ntbEntry.commentLen > 0) {
|
||||
|
@ -76,7 +76,7 @@ int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) {
|
|||
if (tDecodeSRSmaParam(pCoder, &pME->stbEntry.rsmaParam) < 0) return -1;
|
||||
}
|
||||
} else if (pME->type == TSDB_CHILD_TABLE) {
|
||||
if (tDecodeI64(pCoder, &pME->ctbEntry.ctime) < 0) return -1;
|
||||
if (tDecodeI64(pCoder, &pME->ctbEntry.btime) < 0) return -1;
|
||||
if (tDecodeI32(pCoder, &pME->ctbEntry.ttlDays) < 0) return -1;
|
||||
if (tDecodeI32v(pCoder, &pME->ctbEntry.commentLen) < 0) return -1;
|
||||
if (pME->ctbEntry.commentLen > 0) {
|
||||
|
@ -85,7 +85,7 @@ int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) {
|
|||
if (tDecodeI64(pCoder, &pME->ctbEntry.suid) < 0) return -1;
|
||||
if (tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags) < 0) return -1; // (TODO)
|
||||
} else if (pME->type == TSDB_NORMAL_TABLE) {
|
||||
if (tDecodeI64(pCoder, &pME->ntbEntry.ctime) < 0) return -1;
|
||||
if (tDecodeI64(pCoder, &pME->ntbEntry.btime) < 0) return -1;
|
||||
if (tDecodeI32(pCoder, &pME->ntbEntry.ttlDays) < 0) return -1;
|
||||
if (tDecodeI32v(pCoder, &pME->ntbEntry.commentLen) < 0) return -1;
|
||||
if (pME->ntbEntry.commentLen > 0) {
|
||||
|
|
|
@ -19,12 +19,11 @@ static int tbDbKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen
|
|||
static int skmDbKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||
static int ctbIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||
static int tagIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||
static int ttlIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||
static int uidIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||
static int smaIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||
static int taskIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||
|
||||
static int ctimeIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||
static int btimeIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||
static int ncolIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||
|
||||
static int32_t metaInitLock(SMeta *pMeta) { return taosThreadRwlockInit(&pMeta->lock, NULL); }
|
||||
|
@ -128,8 +127,8 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta, int8_t rollback) {
|
|||
goto _err;
|
||||
}
|
||||
|
||||
// open pTtlIdx
|
||||
ret = tdbTbOpen("ttl.idx", sizeof(STtlIdxKey), 0, ttlIdxKeyCmpr, pMeta->pEnv, &pMeta->pTtlIdx, 0);
|
||||
// open pTtlMgr ("ttlv1.idx")
|
||||
ret = ttlMgrOpen(&pMeta->pTtlMgr, pMeta->pEnv, 0);
|
||||
if (ret < 0) {
|
||||
metaError("vgId:%d, failed to open meta ttl index since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
|
@ -143,7 +142,7 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta, int8_t rollback) {
|
|||
}
|
||||
|
||||
// idx table create time
|
||||
ret = tdbTbOpen("ctime.idx", sizeof(SCtimeIdxKey), 0, ctimeIdxCmpr, pMeta->pEnv, &pMeta->pCtimeIdx, 0);
|
||||
ret = tdbTbOpen("ctime.idx", sizeof(SBtimeIdxKey), 0, btimeIdxCmpr, pMeta->pEnv, &pMeta->pBtimeIdx, 0);
|
||||
if (ret < 0) {
|
||||
metaError("vgId:%d, failed to open meta ctime index since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
|
@ -184,9 +183,9 @@ _err:
|
|||
if (pMeta->pIdx) metaCloseIdx(pMeta);
|
||||
if (pMeta->pStreamDb) tdbTbClose(pMeta->pStreamDb);
|
||||
if (pMeta->pNcolIdx) tdbTbClose(pMeta->pNcolIdx);
|
||||
if (pMeta->pCtimeIdx) tdbTbClose(pMeta->pCtimeIdx);
|
||||
if (pMeta->pBtimeIdx) tdbTbClose(pMeta->pBtimeIdx);
|
||||
if (pMeta->pSmaIdx) tdbTbClose(pMeta->pSmaIdx);
|
||||
if (pMeta->pTtlIdx) tdbTbClose(pMeta->pTtlIdx);
|
||||
if (pMeta->pTtlMgr) ttlMgrClose(pMeta->pTtlMgr);
|
||||
if (pMeta->pTagIvtIdx) indexClose(pMeta->pTagIvtIdx);
|
||||
if (pMeta->pTagIdx) tdbTbClose(pMeta->pTagIdx);
|
||||
if (pMeta->pCtbIdx) tdbTbClose(pMeta->pCtbIdx);
|
||||
|
@ -209,9 +208,9 @@ int metaClose(SMeta **ppMeta) {
|
|||
if (pMeta->pIdx) metaCloseIdx(pMeta);
|
||||
if (pMeta->pStreamDb) tdbTbClose(pMeta->pStreamDb);
|
||||
if (pMeta->pNcolIdx) tdbTbClose(pMeta->pNcolIdx);
|
||||
if (pMeta->pCtimeIdx) tdbTbClose(pMeta->pCtimeIdx);
|
||||
if (pMeta->pBtimeIdx) tdbTbClose(pMeta->pBtimeIdx);
|
||||
if (pMeta->pSmaIdx) tdbTbClose(pMeta->pSmaIdx);
|
||||
if (pMeta->pTtlIdx) tdbTbClose(pMeta->pTtlIdx);
|
||||
if (pMeta->pTtlMgr) ttlMgrClose(pMeta->pTtlMgr);
|
||||
if (pMeta->pTagIvtIdx) indexClose(pMeta->pTagIvtIdx);
|
||||
if (pMeta->pTagIdx) tdbTbClose(pMeta->pTagIdx);
|
||||
if (pMeta->pCtbIdx) tdbTbClose(pMeta->pCtbIdx);
|
||||
|
@ -399,37 +398,18 @@ static int tagIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kL
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int ttlIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
|
||||
STtlIdxKey *pTtlIdxKey1 = (STtlIdxKey *)pKey1;
|
||||
STtlIdxKey *pTtlIdxKey2 = (STtlIdxKey *)pKey2;
|
||||
|
||||
if (pTtlIdxKey1->dtime > pTtlIdxKey2->dtime) {
|
||||
static int btimeIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
|
||||
SBtimeIdxKey *pBtimeIdxKey1 = (SBtimeIdxKey *)pKey1;
|
||||
SBtimeIdxKey *pBtimeIdxKey2 = (SBtimeIdxKey *)pKey2;
|
||||
if (pBtimeIdxKey1->btime > pBtimeIdxKey2->btime) {
|
||||
return 1;
|
||||
} else if (pTtlIdxKey1->dtime < pTtlIdxKey2->dtime) {
|
||||
} else if (pBtimeIdxKey1->btime < pBtimeIdxKey2->btime) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pTtlIdxKey1->uid > pTtlIdxKey2->uid) {
|
||||
if (pBtimeIdxKey1->uid > pBtimeIdxKey2->uid) {
|
||||
return 1;
|
||||
} else if (pTtlIdxKey1->uid < pTtlIdxKey2->uid) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ctimeIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
|
||||
SCtimeIdxKey *pCtimeIdxKey1 = (SCtimeIdxKey *)pKey1;
|
||||
SCtimeIdxKey *pCtimeIdxKey2 = (SCtimeIdxKey *)pKey2;
|
||||
if (pCtimeIdxKey1->ctime > pCtimeIdxKey2->ctime) {
|
||||
return 1;
|
||||
} else if (pCtimeIdxKey1->ctime < pCtimeIdxKey2->ctime) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCtimeIdxKey1->uid > pCtimeIdxKey2->uid) {
|
||||
return 1;
|
||||
} else if (pCtimeIdxKey1->uid < pCtimeIdxKey2->uid) {
|
||||
} else if (pBtimeIdxKey1->uid < pBtimeIdxKey2->uid) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
#include "osMemory.h"
|
||||
#include "tencode.h"
|
||||
|
||||
void _metaReaderInit(SMetaReader* pReader, void* pVnode, int32_t flags, SStoreMeta* pAPI) {
|
||||
SMeta* pMeta = ((SVnode*)pVnode)->pMeta;
|
||||
void _metaReaderInit(SMetaReader *pReader, void *pVnode, int32_t flags, SStoreMeta *pAPI) {
|
||||
SMeta *pMeta = ((SVnode *)pVnode)->pMeta;
|
||||
metaReaderInit(pReader, pMeta, flags);
|
||||
pReader->pAPI = pAPI;
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ _err:
|
|||
}
|
||||
|
||||
bool metaIsTableExist(void *pVnode, tb_uid_t uid) {
|
||||
SVnode* pVnodeObj = pVnode;
|
||||
SVnode *pVnodeObj = pVnode;
|
||||
metaRLock(pVnodeObj->pMeta); // query uid.idx
|
||||
|
||||
if (tdbTbGet(pVnodeObj->pMeta->pUidIdx, &uid, sizeof(uid), NULL, NULL) < 0) {
|
||||
|
@ -143,7 +143,7 @@ tb_uid_t metaGetTableEntryUidByName(SMeta *pMeta, const char *name) {
|
|||
int metaGetTableNameByUid(void *pVnode, uint64_t uid, char *tbName) {
|
||||
int code = 0;
|
||||
SMetaReader mr = {0};
|
||||
metaReaderInit(&mr, ((SVnode*)pVnode)->pMeta, 0);
|
||||
metaReaderInit(&mr, ((SVnode *)pVnode)->pMeta, 0);
|
||||
code = metaReaderGetTableEntryByUid(&mr, uid);
|
||||
if (code < 0) {
|
||||
metaReaderClear(&mr);
|
||||
|
@ -179,7 +179,7 @@ int metaGetTableUidByName(void *pVnode, char *tbName, uint64_t *uid) {
|
|||
SMetaReader *pReader = &mr;
|
||||
|
||||
// query name.idx
|
||||
if (tdbTbGet(((SMeta*)pReader->pMeta)->pNameIdx, tbName, strlen(tbName) + 1, &pReader->pBuf, &pReader->szBuf) < 0) {
|
||||
if (tdbTbGet(((SMeta *)pReader->pMeta)->pNameIdx, tbName, strlen(tbName) + 1, &pReader->pBuf, &pReader->szBuf) < 0) {
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
metaReaderClear(&mr);
|
||||
return -1;
|
||||
|
@ -195,7 +195,7 @@ int metaGetTableUidByName(void *pVnode, char *tbName, uint64_t *uid) {
|
|||
int metaGetTableTypeByName(void *pVnode, char *tbName, ETableType *tbType) {
|
||||
int code = 0;
|
||||
SMetaReader mr = {0};
|
||||
metaReaderInit(&mr, ((SVnode*)pVnode)->pMeta, 0);
|
||||
metaReaderInit(&mr, ((SVnode *)pVnode)->pMeta, 0);
|
||||
|
||||
code = metaGetTableEntryByName(&mr, tbName);
|
||||
if (code == 0) *tbType = mr.me.type;
|
||||
|
@ -212,6 +212,29 @@ int metaReadNext(SMetaReader *pReader) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int metaGetTableTtlByUid(void *meta, uint64_t uid, int64_t *ttlDays) {
|
||||
int code = -1;
|
||||
SMetaReader mr = {0};
|
||||
metaReaderInit(&mr, (SMeta *)meta, 0);
|
||||
code = metaReaderGetTableEntryByUid(&mr, uid);
|
||||
if (code < 0) {
|
||||
goto _exit;
|
||||
}
|
||||
if (mr.me.type == TSDB_CHILD_TABLE) {
|
||||
*ttlDays = mr.me.ctbEntry.ttlDays;
|
||||
} else if (mr.me.type == TSDB_NORMAL_TABLE) {
|
||||
*ttlDays = mr.me.ntbEntry.ttlDays;
|
||||
} else {
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
code = 0;
|
||||
|
||||
_exit:
|
||||
metaReaderClear(&mr);
|
||||
return code;
|
||||
}
|
||||
|
||||
#if 1 // ===================================================
|
||||
SMTbCursor *metaOpenTbCursor(void *pVnode) {
|
||||
SMTbCursor *pTbCur = NULL;
|
||||
|
@ -221,12 +244,13 @@ SMTbCursor *metaOpenTbCursor(void *pVnode) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SVnode* pVnodeObj = pVnode;
|
||||
metaReaderInit(&pTbCur->mr, pVnodeObj->pMeta, 0);
|
||||
SVnode *pVnodeObj = pVnode;
|
||||
// metaReaderInit(&pTbCur->mr, pVnodeObj->pMeta, 0);
|
||||
|
||||
tdbTbcOpen(pVnodeObj->pMeta->pUidIdx, (TBC **)&pTbCur->pDbc, NULL);
|
||||
|
||||
tdbTbcMoveToFirst((TBC *)pTbCur->pDbc);
|
||||
// tdbTbcMoveToFirst((TBC *)pTbCur->pDbc);
|
||||
pTbCur->pMeta = pVnodeObj->pMeta;
|
||||
pTbCur->paused = 1;
|
||||
metaResumeTbCursor(pTbCur, 1);
|
||||
return pTbCur;
|
||||
}
|
||||
|
||||
|
@ -234,14 +258,45 @@ void metaCloseTbCursor(SMTbCursor *pTbCur) {
|
|||
if (pTbCur) {
|
||||
tdbFree(pTbCur->pKey);
|
||||
tdbFree(pTbCur->pVal);
|
||||
metaReaderClear(&pTbCur->mr);
|
||||
if (pTbCur->pDbc) {
|
||||
tdbTbcClose((TBC *)pTbCur->pDbc);
|
||||
if (!pTbCur->paused) {
|
||||
metaReaderClear(&pTbCur->mr);
|
||||
if (pTbCur->pDbc) {
|
||||
tdbTbcClose((TBC *)pTbCur->pDbc);
|
||||
}
|
||||
}
|
||||
taosMemoryFree(pTbCur);
|
||||
}
|
||||
}
|
||||
|
||||
void metaPauseTbCursor(SMTbCursor *pTbCur) {
|
||||
if (!pTbCur->paused) {
|
||||
metaReaderClear(&pTbCur->mr);
|
||||
tdbTbcClose((TBC *)pTbCur->pDbc);
|
||||
pTbCur->paused = 1;
|
||||
}
|
||||
}
|
||||
void metaResumeTbCursor(SMTbCursor *pTbCur, int8_t first) {
|
||||
if (pTbCur->paused) {
|
||||
metaReaderInit(&pTbCur->mr, pTbCur->pMeta, 0);
|
||||
|
||||
tdbTbcOpen(((SMeta *)pTbCur->pMeta)->pUidIdx, (TBC **)&pTbCur->pDbc, NULL);
|
||||
|
||||
if (first) {
|
||||
tdbTbcMoveToFirst((TBC *)pTbCur->pDbc);
|
||||
} else {
|
||||
int c = 0;
|
||||
tdbTbcMoveTo(pTbCur->pDbc, pTbCur->pKey, pTbCur->kLen, &c);
|
||||
if (c < 0) {
|
||||
tdbTbcMoveToPrev(pTbCur->pDbc);
|
||||
} else {
|
||||
tdbTbcMoveToNext(pTbCur->pDbc);
|
||||
}
|
||||
}
|
||||
|
||||
pTbCur->paused = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t metaTbCursorNext(SMTbCursor *pTbCur, ETableType jumpTableType) {
|
||||
int ret;
|
||||
void *pBuf;
|
||||
|
@ -355,37 +410,6 @@ _err:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int metaTtlSmaller(SMeta *pMeta, uint64_t ttl, SArray *uidList) {
|
||||
TBC *pCur;
|
||||
int ret = tdbTbcOpen(pMeta->pTtlIdx, &pCur, NULL);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
STtlIdxKey ttlKey = {0};
|
||||
ttlKey.dtime = ttl;
|
||||
ttlKey.uid = INT64_MAX;
|
||||
int c = 0;
|
||||
tdbTbcMoveTo(pCur, &ttlKey, sizeof(ttlKey), &c);
|
||||
if (c < 0) {
|
||||
tdbTbcMoveToPrev(pCur);
|
||||
}
|
||||
|
||||
void *pKey = NULL;
|
||||
int kLen = 0;
|
||||
while (1) {
|
||||
ret = tdbTbcPrev(pCur, &pKey, &kLen, NULL, NULL);
|
||||
if (ret < 0) {
|
||||
break;
|
||||
}
|
||||
ttlKey = *(STtlIdxKey *)pKey;
|
||||
taosArrayPush(uidList, &ttlKey.uid);
|
||||
}
|
||||
tdbFree(pKey);
|
||||
tdbTbcClose(pCur);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct SMCtbCursor {
|
||||
SMeta *pMeta;
|
||||
TBC *pCur;
|
||||
|
@ -974,7 +998,7 @@ typedef struct {
|
|||
} SIdxCursor;
|
||||
|
||||
int32_t metaFilterCreateTime(void *pVnode, SMetaFltParam *arg, SArray *pUids) {
|
||||
SMeta *pMeta = ((SVnode*)pVnode)->pMeta;
|
||||
SMeta *pMeta = ((SVnode *)pVnode)->pMeta;
|
||||
SMetaFltParam *param = arg;
|
||||
int32_t ret = 0;
|
||||
|
||||
|
@ -986,17 +1010,17 @@ int32_t metaFilterCreateTime(void *pVnode, SMetaFltParam *arg, SArray *pUids) {
|
|||
pCursor->type = param->type;
|
||||
|
||||
metaRLock(pMeta);
|
||||
ret = tdbTbcOpen(pMeta->pCtimeIdx, &pCursor->pCur, NULL);
|
||||
ret = tdbTbcOpen(pMeta->pBtimeIdx, &pCursor->pCur, NULL);
|
||||
if (ret != 0) {
|
||||
goto END;
|
||||
}
|
||||
int64_t uidLimit = param->reverse ? INT64_MAX : 0;
|
||||
|
||||
SCtimeIdxKey ctimeKey = {.ctime = *(int64_t *)(param->val), .uid = uidLimit};
|
||||
SCtimeIdxKey *pCtimeKey = &ctimeKey;
|
||||
SBtimeIdxKey btimeKey = {.btime = *(int64_t *)(param->val), .uid = uidLimit};
|
||||
SBtimeIdxKey *pBtimeKey = &btimeKey;
|
||||
|
||||
int cmp = 0;
|
||||
if (tdbTbcMoveTo(pCursor->pCur, &ctimeKey, sizeof(ctimeKey), &cmp) < 0) {
|
||||
if (tdbTbcMoveTo(pCursor->pCur, &btimeKey, sizeof(btimeKey), &cmp) < 0) {
|
||||
goto END;
|
||||
}
|
||||
|
||||
|
@ -1010,10 +1034,10 @@ int32_t metaFilterCreateTime(void *pVnode, SMetaFltParam *arg, SArray *pUids) {
|
|||
valid = tdbTbcGet(pCursor->pCur, (const void **)&entryKey, &nEntryKey, NULL, NULL);
|
||||
if (valid < 0) break;
|
||||
|
||||
SCtimeIdxKey *p = entryKey;
|
||||
SBtimeIdxKey *p = entryKey;
|
||||
if (count > TRY_ERROR_LIMIT) break;
|
||||
|
||||
int32_t cmp = (*param->filterFunc)((void *)&p->ctime, (void *)&pCtimeKey->ctime, param->type);
|
||||
int32_t cmp = (*param->filterFunc)((void *)&p->btime, (void *)&pBtimeKey->btime, param->type);
|
||||
if (cmp == 0)
|
||||
taosArrayPush(pUids, &p->uid);
|
||||
else {
|
||||
|
@ -1034,7 +1058,7 @@ END:
|
|||
}
|
||||
|
||||
int32_t metaFilterTableName(void *pVnode, SMetaFltParam *arg, SArray *pUids) {
|
||||
SMeta *pMeta = ((SVnode*)pVnode)->pMeta;
|
||||
SMeta *pMeta = ((SVnode *)pVnode)->pMeta;
|
||||
SMetaFltParam *param = arg;
|
||||
int32_t ret = 0;
|
||||
char *buf = NULL;
|
||||
|
@ -1101,7 +1125,7 @@ END:
|
|||
return ret;
|
||||
}
|
||||
int32_t metaFilterTtl(void *pVnode, SMetaFltParam *arg, SArray *pUids) {
|
||||
SMeta *pMeta = ((SVnode*)pVnode)->pMeta;
|
||||
SMeta *pMeta = ((SVnode *)pVnode)->pMeta;
|
||||
SMetaFltParam *param = arg;
|
||||
int32_t ret = 0;
|
||||
char *buf = NULL;
|
||||
|
@ -1117,7 +1141,7 @@ int32_t metaFilterTtl(void *pVnode, SMetaFltParam *arg, SArray *pUids) {
|
|||
pCursor->type = param->type;
|
||||
|
||||
metaRLock(pMeta);
|
||||
ret = tdbTbcOpen(pMeta->pTtlIdx, &pCursor->pCur, NULL);
|
||||
//ret = tdbTbcOpen(pMeta->pTtlIdx, &pCursor->pCur, NULL);
|
||||
|
||||
END:
|
||||
if (pCursor->pMeta) metaULock(pCursor->pMeta);
|
||||
|
@ -1132,7 +1156,7 @@ END:
|
|||
return 0;
|
||||
}
|
||||
int32_t metaFilterTableIds(void *pVnode, SMetaFltParam *arg, SArray *pUids) {
|
||||
SMeta *pMeta = ((SVnode*)pVnode)->pMeta;
|
||||
SMeta *pMeta = ((SVnode *)pVnode)->pMeta;
|
||||
SMetaFltParam *param = arg;
|
||||
|
||||
SMetaEntry oStbEntry = {0};
|
||||
|
@ -1318,7 +1342,7 @@ static int32_t metaGetTableTagByUid(SMeta *pMeta, int64_t suid, int64_t uid, voi
|
|||
}
|
||||
|
||||
int32_t metaGetTableTagsByUids(void *pVnode, int64_t suid, SArray *uidList) {
|
||||
SMeta* pMeta = ((SVnode*) pVnode)->pMeta;
|
||||
SMeta *pMeta = ((SVnode *)pVnode)->pMeta;
|
||||
const int32_t LIMIT = 128;
|
||||
|
||||
int32_t isLock = false;
|
||||
|
@ -1350,8 +1374,8 @@ int32_t metaGetTableTagsByUids(void *pVnode, int64_t suid, SArray *uidList) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t metaGetTableTags(void* pVnode, uint64_t suid, SArray *pUidTagInfo) {
|
||||
SMCtbCursor *pCur = metaOpenCtbCursor(((SVnode*)pVnode)->pMeta, suid, 1);
|
||||
int32_t metaGetTableTags(void *pVnode, uint64_t suid, SArray *pUidTagInfo) {
|
||||
SMCtbCursor *pCur = metaOpenCtbCursor(((SVnode *)pVnode)->pMeta, suid, 1);
|
||||
|
||||
// If len > 0 means there already have uids, and we only want the
|
||||
// tags of the specified tables, of which uid in the uid list. Otherwise, all table tags are retrieved and kept
|
||||
|
@ -1456,11 +1480,11 @@ _exit:
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t metaGetStbStats(void *pVnode, int64_t uid, int64_t* numOfTables) {
|
||||
int32_t metaGetStbStats(void *pVnode, int64_t uid, int64_t *numOfTables) {
|
||||
int32_t code = 0;
|
||||
*numOfTables = 0;
|
||||
|
||||
SVnode* pVnodeObj = pVnode;
|
||||
SVnode *pVnodeObj = pVnode;
|
||||
metaRLock(pVnodeObj->pMeta);
|
||||
|
||||
// fast path: search cache
|
||||
|
|
|
@ -20,7 +20,7 @@ static int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, con
|
|||
static int metaSaveToTbDb(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaUpdateUidIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaUpdateNameIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaUpdateTtl(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaUpdateSuidIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
|
@ -28,8 +28,8 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry);
|
|||
static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type);
|
||||
static void metaDestroyTagIdxKey(STagIdxKey *pTagIdxKey);
|
||||
// opt ins_tables query
|
||||
static int metaUpdateCtimeIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaDeleteCtimeIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaUpdateBtimeIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaDeleteBtimeIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaUpdateNcolIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaDeleteNcolIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
|
||||
|
@ -734,7 +734,7 @@ int metaCreateTable(SMeta *pMeta, int64_t ver, SVCreateTbReq *pReq, STableMetaRs
|
|||
me.uid = pReq->uid;
|
||||
me.name = pReq->name;
|
||||
if (me.type == TSDB_CHILD_TABLE) {
|
||||
me.ctbEntry.ctime = pReq->ctime;
|
||||
me.ctbEntry.btime = pReq->btime;
|
||||
me.ctbEntry.ttlDays = pReq->ttl;
|
||||
me.ctbEntry.commentLen = pReq->commentLen;
|
||||
me.ctbEntry.comment = pReq->comment;
|
||||
|
@ -770,7 +770,7 @@ int metaCreateTable(SMeta *pMeta, int64_t ver, SVCreateTbReq *pReq, STableMetaRs
|
|||
metaTbGroupCacheClear(pMeta, me.ctbEntry.suid);
|
||||
metaULock(pMeta);
|
||||
} else {
|
||||
me.ntbEntry.ctime = pReq->ctime;
|
||||
me.ntbEntry.btime = pReq->btime;
|
||||
me.ntbEntry.ttlDays = pReq->ttl;
|
||||
me.ntbEntry.commentLen = pReq->commentLen;
|
||||
me.ntbEntry.comment = pReq->comment;
|
||||
|
@ -838,56 +838,125 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUi
|
|||
return 0;
|
||||
}
|
||||
|
||||
int metaTtlDropTable(SMeta *pMeta, int64_t ttl, SArray *tbUids) {
|
||||
int ret = metaTtlSmaller(pMeta, ttl, tbUids);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
if (taosArrayGetSize(tbUids) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void metaDropTables(SMeta *pMeta, SArray *tbUids) {
|
||||
metaWLock(pMeta);
|
||||
for (int i = 0; i < taosArrayGetSize(tbUids); ++i) {
|
||||
tb_uid_t *uid = (tb_uid_t *)taosArrayGet(tbUids, i);
|
||||
metaDropTableByUid(pMeta, *uid, NULL);
|
||||
metaDebug("ttl drop table:%" PRId64, *uid);
|
||||
for (int i = 0; i < TARRAY_SIZE(tbUids); ++i) {
|
||||
tb_uid_t uid = *(tb_uid_t *)taosArrayGet(tbUids, i);
|
||||
metaDropTableByUid(pMeta, uid, NULL);
|
||||
metaDebug("batch drop table:%" PRId64, uid);
|
||||
}
|
||||
metaULock(pMeta);
|
||||
}
|
||||
|
||||
static int32_t metaFilterTableByHash(SMeta *pMeta, SArray *uidList) {
|
||||
int32_t code = 0;
|
||||
// 1, tranverse table's
|
||||
// 2, validate table name using vnodeValidateTableHash
|
||||
// 3, push invalidated table's uid into uidList
|
||||
|
||||
TBC *pCur;
|
||||
code = tdbTbcOpen(pMeta->pTbDb, &pCur, NULL);
|
||||
if (code < 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
code = tdbTbcMoveToFirst(pCur);
|
||||
if (code) {
|
||||
tdbTbcClose(pCur);
|
||||
return code;
|
||||
}
|
||||
|
||||
void *pData = NULL, *pKey = NULL;
|
||||
int nData = 0, nKey = 0;
|
||||
|
||||
while (1) {
|
||||
int32_t ret = tdbTbcNext(pCur, &pKey, &nKey, &pData, &nData);
|
||||
if (ret < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
SMetaEntry me = {0};
|
||||
SDecoder dc = {0};
|
||||
tDecoderInit(&dc, pData, nData);
|
||||
metaDecodeEntry(&dc, &me);
|
||||
|
||||
if (me.type != TSDB_SUPER_TABLE) {
|
||||
char tbFName[TSDB_TABLE_FNAME_LEN + 1];
|
||||
snprintf(tbFName, sizeof(tbFName), "%s.%s", pMeta->pVnode->config.dbname, me.name);
|
||||
tbFName[TSDB_TABLE_FNAME_LEN] = '\0';
|
||||
int32_t ret = vnodeValidateTableHash(pMeta->pVnode, tbFName);
|
||||
if (ret < 0 && terrno == TSDB_CODE_VND_HASH_MISMATCH) {
|
||||
taosArrayPush(uidList, &me.uid);
|
||||
}
|
||||
}
|
||||
tDecoderClear(&dc);
|
||||
}
|
||||
tdbFree(pData);
|
||||
tdbFree(pKey);
|
||||
tdbTbcClose(pCur);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void metaBuildTtlIdxKey(STtlIdxKey *ttlKey, const SMetaEntry *pME) {
|
||||
int64_t ttlDays = 0;
|
||||
int64_t ctime = 0;
|
||||
if (pME->type == TSDB_CHILD_TABLE) {
|
||||
ctime = pME->ctbEntry.ctime;
|
||||
ttlDays = pME->ctbEntry.ttlDays;
|
||||
} else if (pME->type == TSDB_NORMAL_TABLE) {
|
||||
ctime = pME->ntbEntry.ctime;
|
||||
ttlDays = pME->ntbEntry.ttlDays;
|
||||
} else {
|
||||
metaError("meta/table: invalide table type: %" PRId8 " build ttl idx key failed.", pME->type);
|
||||
return;
|
||||
int32_t metaTrimTables(SMeta *pMeta) {
|
||||
int32_t code = 0;
|
||||
|
||||
SArray *tbUids = taosArrayInit(8, sizeof(int64_t));
|
||||
if (tbUids == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if (ttlDays <= 0) return;
|
||||
code = metaFilterTableByHash(pMeta, tbUids);
|
||||
if (code != 0) {
|
||||
goto end;
|
||||
}
|
||||
if (TARRAY_SIZE(tbUids) == 0) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
ttlKey->dtime = ctime / 1000 + ttlDays * tsTtlUnit;
|
||||
ttlKey->uid = pME->uid;
|
||||
metaInfo("vgId:%d, trim %ld tables", TD_VID(pMeta->pVnode), taosArrayGetSize(tbUids));
|
||||
metaDropTables(pMeta, tbUids);
|
||||
|
||||
end:
|
||||
taosArrayDestroy(tbUids);
|
||||
|
||||
return code;
|
||||
}
|
||||
static int metaBuildCtimeIdxKey(SCtimeIdxKey *ctimeKey, const SMetaEntry *pME) {
|
||||
int64_t ctime;
|
||||
|
||||
int metaTtlDropTable(SMeta *pMeta, int64_t timePointMs, SArray *tbUids) {
|
||||
int ret = ttlMgrFlush(pMeta->pTtlMgr, pMeta->txn);
|
||||
if (ret != 0) {
|
||||
metaError("ttl failed to flush, ret:%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = ttlMgrFindExpired(pMeta->pTtlMgr, timePointMs, tbUids);
|
||||
if (ret != 0) {
|
||||
metaError("ttl failed to find expired table, ret:%d", ret);
|
||||
return ret;
|
||||
}
|
||||
if (TARRAY_SIZE(tbUids) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
metaInfo("ttl find expired table count: %zu" , TARRAY_SIZE(tbUids));
|
||||
|
||||
metaDropTables(pMeta, tbUids);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int metaBuildBtimeIdxKey(SBtimeIdxKey *btimeKey, const SMetaEntry *pME) {
|
||||
int64_t btime;
|
||||
if (pME->type == TSDB_CHILD_TABLE) {
|
||||
ctime = pME->ctbEntry.ctime;
|
||||
btime = pME->ctbEntry.btime;
|
||||
} else if (pME->type == TSDB_NORMAL_TABLE) {
|
||||
ctime = pME->ntbEntry.ctime;
|
||||
btime = pME->ntbEntry.btime;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ctimeKey->ctime = ctime;
|
||||
ctimeKey->uid = pME->uid;
|
||||
btimeKey->btime = btime;
|
||||
btimeKey->uid = pME->uid;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -901,11 +970,9 @@ static int metaBuildNColIdxKey(SNcolIdxKey *ncolKey, const SMetaEntry *pME) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int metaDeleteTtlIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
STtlIdxKey ttlKey = {0};
|
||||
metaBuildTtlIdxKey(&ttlKey, pME);
|
||||
if (ttlKey.dtime == 0) return 0;
|
||||
return tdbTbDelete(pMeta->pTtlIdx, &ttlKey, sizeof(ttlKey), pMeta->txn);
|
||||
static int metaDeleteTtl(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
STtlDelTtlCtx ctx = {.uid = pME->uid, .pTxn = pMeta->txn};
|
||||
return ttlMgrDeleteTtl(pMeta->pTtlMgr, &ctx);
|
||||
}
|
||||
|
||||
static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
|
||||
|
@ -987,10 +1054,10 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
|
|||
tdbTbDelete(pMeta->pNameIdx, e.name, strlen(e.name) + 1, pMeta->txn);
|
||||
tdbTbDelete(pMeta->pUidIdx, &uid, sizeof(uid), pMeta->txn);
|
||||
|
||||
if (e.type == TSDB_CHILD_TABLE || e.type == TSDB_NORMAL_TABLE) metaDeleteCtimeIdx(pMeta, &e);
|
||||
if (e.type == TSDB_CHILD_TABLE || e.type == TSDB_NORMAL_TABLE) metaDeleteBtimeIdx(pMeta, &e);
|
||||
if (e.type == TSDB_NORMAL_TABLE) metaDeleteNcolIdx(pMeta, &e);
|
||||
|
||||
if (e.type != TSDB_SUPER_TABLE) metaDeleteTtlIdx(pMeta, &e);
|
||||
if (e.type != TSDB_SUPER_TABLE) metaDeleteTtl(pMeta, &e);
|
||||
|
||||
if (e.type == TSDB_CHILD_TABLE) {
|
||||
tdbTbDelete(pMeta->pCtbIdx, &(SCtbIdxKey){.suid = e.ctbEntry.suid, .uid = uid}, sizeof(SCtbIdxKey), pMeta->txn);
|
||||
|
@ -999,7 +1066,7 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
|
|||
|
||||
metaUpdateStbStats(pMeta, e.ctbEntry.suid, -1);
|
||||
metaUidCacheClear(pMeta, e.ctbEntry.suid);
|
||||
metaTbGroupCacheClear(pMeta, e.ctbEntry.suid);
|
||||
metaTbGroupCacheClear(pMeta, e.ctbEntry.suid);
|
||||
} else if (e.type == TSDB_NORMAL_TABLE) {
|
||||
// drop schema.db (todo)
|
||||
|
||||
|
@ -1011,7 +1078,7 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
|
|||
|
||||
metaStatsCacheDrop(pMeta, uid);
|
||||
metaUidCacheClear(pMeta, uid);
|
||||
metaTbGroupCacheClear(pMeta, uid);
|
||||
metaTbGroupCacheClear(pMeta, uid);
|
||||
--pMeta->pVnode->config.vndStats.numOfSTables;
|
||||
}
|
||||
|
||||
|
@ -1023,23 +1090,23 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
|
|||
return 0;
|
||||
}
|
||||
// opt ins_tables
|
||||
int metaUpdateCtimeIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
SCtimeIdxKey ctimeKey = {0};
|
||||
if (metaBuildCtimeIdxKey(&ctimeKey, pME) < 0) {
|
||||
int metaUpdateBtimeIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
SBtimeIdxKey btimeKey = {0};
|
||||
if (metaBuildBtimeIdxKey(&btimeKey, pME) < 0) {
|
||||
return 0;
|
||||
}
|
||||
metaTrace("vgId:%d, start to save version:%" PRId64 " uid:%" PRId64 " ctime:%" PRId64, TD_VID(pMeta->pVnode),
|
||||
pME->version, pME->uid, ctimeKey.ctime);
|
||||
metaTrace("vgId:%d, start to save version:%" PRId64 " uid:%" PRId64 " btime:%" PRId64, TD_VID(pMeta->pVnode),
|
||||
pME->version, pME->uid, btimeKey.btime);
|
||||
|
||||
return tdbTbUpsert(pMeta->pCtimeIdx, &ctimeKey, sizeof(ctimeKey), NULL, 0, pMeta->txn);
|
||||
return tdbTbUpsert(pMeta->pBtimeIdx, &btimeKey, sizeof(btimeKey), NULL, 0, pMeta->txn);
|
||||
}
|
||||
|
||||
int metaDeleteCtimeIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
SCtimeIdxKey ctimeKey = {0};
|
||||
if (metaBuildCtimeIdxKey(&ctimeKey, pME) < 0) {
|
||||
int metaDeleteBtimeIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
SBtimeIdxKey btimeKey = {0};
|
||||
if (metaBuildBtimeIdxKey(&btimeKey, pME) < 0) {
|
||||
return 0;
|
||||
}
|
||||
return tdbTbDelete(pMeta->pCtimeIdx, &ctimeKey, sizeof(ctimeKey), pMeta->txn);
|
||||
return tdbTbDelete(pMeta->pBtimeIdx, &btimeKey, sizeof(btimeKey), pMeta->txn);
|
||||
}
|
||||
int metaUpdateNcolIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
SNcolIdxKey ncolKey = {0};
|
||||
|
@ -1249,6 +1316,8 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
|
||||
metaULock(pMeta);
|
||||
|
||||
metaUpdateChangeTime(pMeta, entry.uid, pAlterTbReq->ctimeMs);
|
||||
|
||||
metaUpdateMetaRsp(uid, pAlterTbReq->tbName, pSchema, pMetaRsp);
|
||||
|
||||
if (entry.pBuf) taosMemoryFree(entry.pBuf);
|
||||
|
@ -1432,10 +1501,12 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
|
|||
((STag *)(ctbEntry.ctbEntry.pTags))->len, pMeta->txn);
|
||||
|
||||
metaUidCacheClear(pMeta, ctbEntry.ctbEntry.suid);
|
||||
metaTbGroupCacheClear(pMeta, ctbEntry.ctbEntry.suid);
|
||||
metaTbGroupCacheClear(pMeta, ctbEntry.ctbEntry.suid);
|
||||
|
||||
metaULock(pMeta);
|
||||
|
||||
metaUpdateChangeTime(pMeta, ctbEntry.uid, pAlterTbReq->ctimeMs);
|
||||
|
||||
tDecoderClear(&dc1);
|
||||
tDecoderClear(&dc2);
|
||||
taosMemoryFree((void *)ctbEntry.ctbEntry.pTags);
|
||||
|
@ -1524,9 +1595,9 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p
|
|||
// build SMetaEntry
|
||||
if (entry.type == TSDB_CHILD_TABLE) {
|
||||
if (pAlterTbReq->updateTTL) {
|
||||
metaDeleteTtlIdx(pMeta, &entry);
|
||||
metaDeleteTtl(pMeta, &entry);
|
||||
entry.ctbEntry.ttlDays = pAlterTbReq->newTTL;
|
||||
metaUpdateTtlIdx(pMeta, &entry);
|
||||
metaUpdateTtl(pMeta, &entry);
|
||||
}
|
||||
if (pAlterTbReq->newCommentLen >= 0) {
|
||||
entry.ctbEntry.commentLen = pAlterTbReq->newCommentLen;
|
||||
|
@ -1534,9 +1605,9 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p
|
|||
}
|
||||
} else {
|
||||
if (pAlterTbReq->updateTTL) {
|
||||
metaDeleteTtlIdx(pMeta, &entry);
|
||||
metaDeleteTtl(pMeta, &entry);
|
||||
entry.ntbEntry.ttlDays = pAlterTbReq->newTTL;
|
||||
metaUpdateTtlIdx(pMeta, &entry);
|
||||
metaUpdateTtl(pMeta, &entry);
|
||||
}
|
||||
if (pAlterTbReq->newCommentLen >= 0) {
|
||||
entry.ntbEntry.commentLen = pAlterTbReq->newCommentLen;
|
||||
|
@ -1549,6 +1620,8 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p
|
|||
metaUpdateUidIdx(pMeta, &entry);
|
||||
metaULock(pMeta);
|
||||
|
||||
metaUpdateChangeTime(pMeta, entry.uid, pAlterTbReq->ctimeMs);
|
||||
|
||||
tdbTbcClose(pTbDbc);
|
||||
tdbTbcClose(pUidIdxc);
|
||||
tDecoderClear(&dc);
|
||||
|
@ -1888,11 +1961,28 @@ static int metaUpdateNameIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
|||
return tdbTbUpsert(pMeta->pNameIdx, pME->name, strlen(pME->name) + 1, &pME->uid, sizeof(tb_uid_t), pMeta->txn);
|
||||
}
|
||||
|
||||
static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
STtlIdxKey ttlKey = {0};
|
||||
metaBuildTtlIdxKey(&ttlKey, pME);
|
||||
if (ttlKey.dtime == 0) return 0;
|
||||
return tdbTbUpsert(pMeta->pTtlIdx, &ttlKey, sizeof(ttlKey), NULL, 0, pMeta->txn);
|
||||
static int metaUpdateTtl(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
if (pME->type != TSDB_CHILD_TABLE && pME->type != TSDB_NORMAL_TABLE) return 0;
|
||||
|
||||
STtlUpdTtlCtx ctx = {.uid = pME->uid};
|
||||
|
||||
if (pME->type == TSDB_CHILD_TABLE) {
|
||||
ctx.ttlDays = pME->ctbEntry.ttlDays;
|
||||
ctx.changeTimeMs = pME->ctbEntry.btime;
|
||||
} else {
|
||||
ctx.ttlDays = pME->ntbEntry.ttlDays;
|
||||
ctx.changeTimeMs = pME->ntbEntry.btime;
|
||||
}
|
||||
|
||||
return ttlMgrInsertTtl(pMeta->pTtlMgr, &ctx);
|
||||
}
|
||||
|
||||
int metaUpdateChangeTime(SMeta *pMeta, tb_uid_t uid, int64_t changeTimeMs) {
|
||||
if (!tsTtlChangeOnWrite) return 0;
|
||||
|
||||
STtlUpdCtimeCtx ctx = {.uid = uid, .changeTimeMs = changeTimeMs};
|
||||
|
||||
return ttlMgrUpdateChangeTime(pMeta->pTtlMgr, &ctx);
|
||||
}
|
||||
|
||||
static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
|
@ -2103,7 +2193,7 @@ int metaHandleEntry(SMeta *pMeta, const SMetaEntry *pME) {
|
|||
}
|
||||
}
|
||||
|
||||
code = metaUpdateCtimeIdx(pMeta, pME);
|
||||
code = metaUpdateBtimeIdx(pMeta, pME);
|
||||
VND_CHECK_CODE(code, line, _err);
|
||||
|
||||
if (pME->type == TSDB_NORMAL_TABLE) {
|
||||
|
@ -2112,7 +2202,7 @@ int metaHandleEntry(SMeta *pMeta, const SMetaEntry *pME) {
|
|||
}
|
||||
|
||||
if (pME->type != TSDB_SUPER_TABLE) {
|
||||
code = metaUpdateTtlIdx(pMeta, pME);
|
||||
code = metaUpdateTtl(pMeta, pME);
|
||||
VND_CHECK_CODE(code, line, _err);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,434 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "metaTtl.h"
|
||||
#include "meta.h"
|
||||
|
||||
typedef struct {
|
||||
TTB *pNewTtlIdx;
|
||||
SMeta *pMeta;
|
||||
} SConvertData;
|
||||
|
||||
static void ttlMgrBuildKey(STtlIdxKeyV1 *pTtlKey, int64_t ttlDays, int64_t changeTimeMs, tb_uid_t uid);
|
||||
static int ttlIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||
static int ttlIdxKeyV1Cmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||
static int ttlMgrFillCache(STtlManger *pTtlMgr);
|
||||
static int32_t ttlMgrFillCacheOneEntry(const void *pKey, int keyLen, const void *pVal, int valLen, void *pTtlCache);
|
||||
static int32_t ttlMgrConvertOneEntry(const void *pKey, int keyLen, const void *pVal, int valLen, void *pConvertData);
|
||||
|
||||
static int32_t ttlMgrWLock(STtlManger *pTtlMgr);
|
||||
static int32_t ttlMgrRLock(STtlManger *pTtlMgr);
|
||||
static int32_t ttlMgrULock(STtlManger *pTtlMgr);
|
||||
|
||||
const char *ttlTbname = "ttl.idx";
|
||||
const char *ttlV1Tbname = "ttlv1.idx";
|
||||
|
||||
int ttlMgrOpen(STtlManger **ppTtlMgr, TDB *pEnv, int8_t rollback) {
|
||||
int ret;
|
||||
|
||||
*ppTtlMgr = NULL;
|
||||
|
||||
STtlManger *pTtlMgr = (STtlManger *)tdbOsCalloc(1, sizeof(*pTtlMgr));
|
||||
if (pTtlMgr == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tdbTbExist(ttlTbname, pEnv)) {
|
||||
ret = tdbTbOpen(ttlTbname, sizeof(STtlIdxKey), 0, ttlIdxKeyCmpr, pEnv, &pTtlMgr->pOldTtlIdx, rollback);
|
||||
if (ret < 0) {
|
||||
metaError("failed to open %s index since %s", ttlTbname, tstrerror(terrno));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
ret = tdbTbOpen(ttlV1Tbname, TDB_VARIANT_LEN, TDB_VARIANT_LEN, ttlIdxKeyV1Cmpr, pEnv, &pTtlMgr->pTtlIdx, rollback);
|
||||
if (ret < 0) {
|
||||
metaError("failed to open %s since %s", ttlV1Tbname, tstrerror(terrno));
|
||||
|
||||
tdbOsFree(pTtlMgr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
pTtlMgr->pTtlCache = taosHashInit(8192, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
|
||||
pTtlMgr->pDirtyUids = taosHashInit(8192, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
|
||||
|
||||
taosThreadRwlockInit(&pTtlMgr->lock, NULL);
|
||||
|
||||
*ppTtlMgr = pTtlMgr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ttlMgrClose(STtlManger *pTtlMgr) {
|
||||
taosHashCleanup(pTtlMgr->pTtlCache);
|
||||
taosHashCleanup(pTtlMgr->pDirtyUids);
|
||||
tdbTbClose(pTtlMgr->pTtlIdx);
|
||||
taosThreadRwlockDestroy(&pTtlMgr->lock);
|
||||
tdbOsFree(pTtlMgr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ttlMgrBegin(STtlManger *pTtlMgr, void *pMeta) {
|
||||
metaInfo("ttl mgr start open");
|
||||
int ret;
|
||||
|
||||
int64_t startNs = taosGetTimestampNs();
|
||||
|
||||
SMeta *meta = (SMeta *)pMeta;
|
||||
|
||||
if (pTtlMgr->pOldTtlIdx) {
|
||||
ret = ttlMgrConvert(pTtlMgr->pOldTtlIdx, pTtlMgr->pTtlIdx, pMeta);
|
||||
if (ret < 0) {
|
||||
metaError("failed to convert ttl index since %s", tstrerror(terrno));
|
||||
goto _out;
|
||||
}
|
||||
|
||||
ret = tdbTbDropByName(ttlTbname, meta->pEnv, meta->txn);
|
||||
if (ret < 0) {
|
||||
metaError("failed to drop old ttl index since %s", tstrerror(terrno));
|
||||
goto _out;
|
||||
}
|
||||
|
||||
tdbTbClose(pTtlMgr->pOldTtlIdx);
|
||||
pTtlMgr->pOldTtlIdx = NULL;
|
||||
}
|
||||
|
||||
ret = ttlMgrFillCache(pTtlMgr);
|
||||
if (ret < 0) {
|
||||
metaError("failed to fill hash since %s", tstrerror(terrno));
|
||||
goto _out;
|
||||
}
|
||||
|
||||
int64_t endNs = taosGetTimestampNs();
|
||||
|
||||
metaInfo("ttl mgr open end, hash size: %d, time consumed: %" PRId64 " ns", taosHashGetSize(pTtlMgr->pTtlCache),
|
||||
endNs - startNs);
|
||||
_out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void ttlMgrBuildKey(STtlIdxKeyV1 *pTtlKey, int64_t ttlDays, int64_t changeTimeMs, tb_uid_t uid) {
|
||||
if (ttlDays <= 0) return;
|
||||
|
||||
pTtlKey->deleteTimeMs = changeTimeMs + ttlDays * tsTtlUnit * 1000;
|
||||
pTtlKey->uid = uid;
|
||||
}
|
||||
|
||||
static int ttlIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
|
||||
STtlIdxKey *pTtlIdxKey1 = (STtlIdxKey *)pKey1;
|
||||
STtlIdxKey *pTtlIdxKey2 = (STtlIdxKey *)pKey2;
|
||||
|
||||
if (pTtlIdxKey1->deleteTimeSec > pTtlIdxKey2->deleteTimeSec) {
|
||||
return 1;
|
||||
} else if (pTtlIdxKey1->deleteTimeSec < pTtlIdxKey2->deleteTimeSec) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pTtlIdxKey1->uid > pTtlIdxKey2->uid) {
|
||||
return 1;
|
||||
} else if (pTtlIdxKey1->uid < pTtlIdxKey2->uid) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ttlIdxKeyV1Cmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
|
||||
STtlIdxKeyV1 *pTtlIdxKey1 = (STtlIdxKeyV1 *)pKey1;
|
||||
STtlIdxKeyV1 *pTtlIdxKey2 = (STtlIdxKeyV1 *)pKey2;
|
||||
|
||||
if (pTtlIdxKey1->deleteTimeMs > pTtlIdxKey2->deleteTimeMs) {
|
||||
return 1;
|
||||
} else if (pTtlIdxKey1->deleteTimeMs < pTtlIdxKey2->deleteTimeMs) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pTtlIdxKey1->uid > pTtlIdxKey2->uid) {
|
||||
return 1;
|
||||
} else if (pTtlIdxKey1->uid < pTtlIdxKey2->uid) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ttlMgrFillCache(STtlManger *pTtlMgr) {
|
||||
return tdbTbTraversal(pTtlMgr->pTtlIdx, pTtlMgr->pTtlCache, ttlMgrFillCacheOneEntry);
|
||||
}
|
||||
|
||||
static int32_t ttlMgrFillCacheOneEntry(const void *pKey, int keyLen, const void *pVal, int valLen, void *pTtlCache) {
|
||||
SHashObj *pCache = (SHashObj *)pTtlCache;
|
||||
|
||||
STtlIdxKeyV1 *ttlKey = (STtlIdxKeyV1 *)pKey;
|
||||
tb_uid_t uid = ttlKey->uid;
|
||||
int64_t ttlDays = *(int64_t *)pVal;
|
||||
int64_t changeTimeMs = ttlKey->deleteTimeMs - ttlDays * tsTtlUnit * 1000;
|
||||
|
||||
STtlCacheEntry data = {.ttlDays = ttlDays, .changeTimeMs = changeTimeMs};
|
||||
|
||||
return taosHashPut(pCache, &uid, sizeof(uid), &data, sizeof(data));
|
||||
}
|
||||
|
||||
static int ttlMgrConvertOneEntry(const void *pKey, int keyLen, const void *pVal, int valLen, void *pConvertData) {
|
||||
SConvertData *pData = (SConvertData *)pConvertData;
|
||||
|
||||
STtlIdxKey *ttlKey = (STtlIdxKey *)pKey;
|
||||
tb_uid_t uid = ttlKey->uid;
|
||||
int64_t ttlDays = 0;
|
||||
|
||||
int ret = metaGetTableTtlByUid(pData->pMeta, uid, &ttlDays);
|
||||
if (ret < 0) {
|
||||
metaError("ttlMgr convert failed to get ttl since %s", tstrerror(terrno));
|
||||
goto _out;
|
||||
}
|
||||
|
||||
STtlIdxKeyV1 ttlKeyV1 = {.deleteTimeMs = ttlKey->deleteTimeSec * 1000, .uid = uid};
|
||||
ret = tdbTbUpsert(pData->pNewTtlIdx, &ttlKeyV1, sizeof(ttlKeyV1), &ttlDays, sizeof(ttlDays), pData->pMeta->txn);
|
||||
if (ret < 0) {
|
||||
metaError("ttlMgr convert failed to upsert since %s", tstrerror(terrno));
|
||||
goto _out;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
_out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ttlMgrConvert(TTB *pOldTtlIdx, TTB *pNewTtlIdx, void *pMeta) {
|
||||
SMeta *meta = pMeta;
|
||||
|
||||
metaInfo("ttlMgr convert ttl start.");
|
||||
|
||||
SConvertData cvData = {.pNewTtlIdx = pNewTtlIdx, .pMeta = meta};
|
||||
|
||||
int ret = tdbTbTraversal(pOldTtlIdx, &cvData, ttlMgrConvertOneEntry);
|
||||
if (ret < 0) {
|
||||
metaError("failed to convert ttl since %s", tstrerror(terrno));
|
||||
}
|
||||
|
||||
metaInfo("ttlMgr convert ttl end.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ttlMgrInsertTtl(STtlManger *pTtlMgr, const STtlUpdTtlCtx *updCtx) {
|
||||
if (updCtx->ttlDays == 0) return 0;
|
||||
|
||||
STtlCacheEntry cacheEntry = {.ttlDays = updCtx->ttlDays, .changeTimeMs = updCtx->changeTimeMs};
|
||||
STtlDirtyEntry dirtryEntry = {.type = ENTRY_TYPE_UPSERT};
|
||||
|
||||
ttlMgrWLock(pTtlMgr);
|
||||
|
||||
int ret = taosHashPut(pTtlMgr->pTtlCache, &updCtx->uid, sizeof(updCtx->uid), &cacheEntry, sizeof(cacheEntry));
|
||||
if (ret < 0) {
|
||||
metaError("ttlMgr insert failed to update ttl cache since %s", tstrerror(terrno));
|
||||
goto _out;
|
||||
}
|
||||
|
||||
ret = taosHashPut(pTtlMgr->pDirtyUids, &updCtx->uid, sizeof(updCtx->uid), &dirtryEntry, sizeof(dirtryEntry));
|
||||
if (ret < 0) {
|
||||
metaError("ttlMgr insert failed to update ttl dirty uids since %s", tstrerror(terrno));
|
||||
goto _out;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
_out:
|
||||
ttlMgrULock(pTtlMgr);
|
||||
|
||||
metaDebug("ttl mgr insert ttl, uid: %" PRId64 ", ctime: %" PRId64 ", ttlDays: %" PRId64, updCtx->uid,
|
||||
updCtx->changeTimeMs, updCtx->ttlDays);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ttlMgrDeleteTtl(STtlManger *pTtlMgr, const STtlDelTtlCtx *delCtx) {
|
||||
ttlMgrWLock(pTtlMgr);
|
||||
|
||||
STtlDirtyEntry dirtryEntry = {.type = ENTRY_TYPE_DEL};
|
||||
|
||||
int ret = taosHashPut(pTtlMgr->pDirtyUids, &delCtx->uid, sizeof(delCtx->uid), &dirtryEntry, sizeof(dirtryEntry));
|
||||
if (ret < 0) {
|
||||
metaError("ttlMgr del failed to update ttl dirty uids since %s", tstrerror(terrno));
|
||||
goto _out;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
_out:
|
||||
ttlMgrULock(pTtlMgr);
|
||||
|
||||
metaDebug("ttl mgr delete ttl, uid: %" PRId64, delCtx->uid);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ttlMgrUpdateChangeTime(STtlManger *pTtlMgr, const STtlUpdCtimeCtx *pUpdCtimeCtx) {
|
||||
ttlMgrWLock(pTtlMgr);
|
||||
|
||||
STtlCacheEntry *oldData = taosHashGet(pTtlMgr->pTtlCache, &pUpdCtimeCtx->uid, sizeof(pUpdCtimeCtx->uid));
|
||||
if (oldData == NULL) {
|
||||
goto _out;
|
||||
}
|
||||
|
||||
STtlCacheEntry cacheEntry = {.ttlDays = oldData->ttlDays, .changeTimeMs = pUpdCtimeCtx->changeTimeMs};
|
||||
STtlDirtyEntry dirtryEntry = {.type = ENTRY_TYPE_UPSERT};
|
||||
|
||||
int ret =
|
||||
taosHashPut(pTtlMgr->pTtlCache, &pUpdCtimeCtx->uid, sizeof(pUpdCtimeCtx->uid), &cacheEntry, sizeof(cacheEntry));
|
||||
if (ret < 0) {
|
||||
metaError("ttlMgr update ctime failed to update ttl cache since %s", tstrerror(terrno));
|
||||
goto _out;
|
||||
}
|
||||
|
||||
ret = taosHashPut(pTtlMgr->pDirtyUids, &pUpdCtimeCtx->uid, sizeof(pUpdCtimeCtx->uid), &dirtryEntry,
|
||||
sizeof(dirtryEntry));
|
||||
if (ret < 0) {
|
||||
metaError("ttlMgr update ctime failed to update ttl dirty uids since %s", tstrerror(terrno));
|
||||
goto _out;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
_out:
|
||||
ttlMgrULock(pTtlMgr);
|
||||
|
||||
metaDebug("ttl mgr update ctime, uid: %" PRId64 ", ctime: %" PRId64, pUpdCtimeCtx->uid, pUpdCtimeCtx->changeTimeMs);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ttlMgrFindExpired(STtlManger *pTtlMgr, int64_t timePointMs, SArray *pTbUids) {
|
||||
ttlMgrRLock(pTtlMgr);
|
||||
|
||||
TBC *pCur;
|
||||
int ret = tdbTbcOpen(pTtlMgr->pTtlIdx, &pCur, NULL);
|
||||
if (ret < 0) {
|
||||
goto _out;
|
||||
}
|
||||
|
||||
STtlIdxKeyV1 ttlKey = {0};
|
||||
ttlKey.deleteTimeMs = timePointMs;
|
||||
ttlKey.uid = INT64_MAX;
|
||||
int c = 0;
|
||||
tdbTbcMoveTo(pCur, &ttlKey, sizeof(ttlKey), &c);
|
||||
if (c < 0) {
|
||||
tdbTbcMoveToPrev(pCur);
|
||||
}
|
||||
|
||||
void *pKey = NULL;
|
||||
int kLen = 0;
|
||||
while (1) {
|
||||
ret = tdbTbcPrev(pCur, &pKey, &kLen, NULL, NULL);
|
||||
if (ret < 0) {
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
ttlKey = *(STtlIdxKeyV1 *)pKey;
|
||||
taosArrayPush(pTbUids, &ttlKey.uid);
|
||||
}
|
||||
|
||||
tdbFree(pKey);
|
||||
tdbTbcClose(pCur);
|
||||
|
||||
ret = 0;
|
||||
_out:
|
||||
ttlMgrULock(pTtlMgr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ttlMgrFlush(STtlManger *pTtlMgr, TXN *pTxn) {
|
||||
ttlMgrWLock(pTtlMgr);
|
||||
|
||||
metaInfo("ttl mgr flush start.");
|
||||
|
||||
int ret = -1;
|
||||
|
||||
void *pIter = taosHashIterate(pTtlMgr->pDirtyUids, NULL);
|
||||
while (pIter != NULL) {
|
||||
STtlDirtyEntry *pEntry = (STtlDirtyEntry *)pIter;
|
||||
tb_uid_t *pUid = taosHashGetKey(pIter, NULL);
|
||||
|
||||
STtlCacheEntry *cacheEntry = taosHashGet(pTtlMgr->pTtlCache, pUid, sizeof(*pUid));
|
||||
if (cacheEntry == NULL) {
|
||||
metaError("ttlMgr flush failed to get ttl cache since %s", tstrerror(terrno));
|
||||
goto _out;
|
||||
}
|
||||
|
||||
STtlIdxKeyV1 ttlKey;
|
||||
ttlMgrBuildKey(&ttlKey, cacheEntry->ttlDays, cacheEntry->changeTimeMs, *pUid);
|
||||
|
||||
if (pEntry->type == ENTRY_TYPE_UPSERT) {
|
||||
ret = tdbTbUpsert(pTtlMgr->pTtlIdx, &ttlKey, sizeof(ttlKey), &cacheEntry->ttlDays, sizeof(cacheEntry->ttlDays),
|
||||
pTxn);
|
||||
if (ret < 0) {
|
||||
metaError("ttlMgr flush failed to flush ttl cache upsert since %s", tstrerror(terrno));
|
||||
goto _out;
|
||||
}
|
||||
} else if (pEntry->type == ENTRY_TYPE_DEL) {
|
||||
ret = tdbTbDelete(pTtlMgr->pTtlIdx, &ttlKey, sizeof(ttlKey), pTxn);
|
||||
if (ret < 0) {
|
||||
metaError("ttlMgr flush failed to flush ttl cache del since %s", tstrerror(terrno));
|
||||
goto _out;
|
||||
}
|
||||
|
||||
ret = taosHashRemove(pTtlMgr->pTtlCache, pUid, sizeof(*pUid));
|
||||
if (ret < 0) {
|
||||
metaError("ttlMgr flush failed to delete ttl cache since %s", tstrerror(terrno));
|
||||
goto _out;
|
||||
}
|
||||
} else {
|
||||
metaError("ttlMgr flush failed to flush ttl cache, unknown type: %d", pEntry->type);
|
||||
goto _out;
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(pTtlMgr->pDirtyUids, pIter);
|
||||
}
|
||||
|
||||
taosHashClear(pTtlMgr->pDirtyUids);
|
||||
|
||||
ret = 0;
|
||||
_out:
|
||||
ttlMgrULock(pTtlMgr);
|
||||
|
||||
metaInfo("ttl mgr flush end.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t ttlMgrRLock(STtlManger *pTtlMgr) {
|
||||
int32_t ret = 0;
|
||||
|
||||
metaTrace("ttlMgr rlock %p", &pTtlMgr->lock);
|
||||
|
||||
ret = taosThreadRwlockRdlock(&pTtlMgr->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t ttlMgrWLock(STtlManger *pTtlMgr) {
|
||||
int32_t ret = 0;
|
||||
|
||||
metaTrace("ttlMgr wlock %p", &pTtlMgr->lock);
|
||||
|
||||
ret = taosThreadRwlockWrlock(&pTtlMgr->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t ttlMgrULock(STtlManger *pTtlMgr) {
|
||||
int32_t ret = 0;
|
||||
|
||||
metaTrace("ttlMgr ulock %p", &pTtlMgr->lock);
|
||||
|
||||
ret = taosThreadRwlockUnlock(&pTtlMgr->lock);
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -29,7 +29,7 @@ int32_t tdProcessTSmaInsert(SSma *pSma, int64_t indexUid, const char *msg) {
|
|||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
if ((code = tdProcessTSmaInsertImpl(pSma, indexUid, msg)) < 0) {
|
||||
smaWarn("vgId:%d, insert tsma data failed since %s", SMA_VID(pSma), tstrerror(terrno));
|
||||
smaError("vgId:%d, insert tsma data failed since %s", SMA_VID(pSma), tstrerror(terrno));
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -346,6 +346,43 @@ _end:
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t tsmaProcessDelReq(SSma *pSma, int64_t indexUid, SBatchDeleteReq *pDelReq) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
if (taosArrayGetSize(pDelReq->deleteReqs) > 0) {
|
||||
int32_t len = 0;
|
||||
tEncodeSize(tEncodeSBatchDeleteReq, pDelReq, len, code);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
void *pBuf = rpcMallocCont(len + sizeof(SMsgHead));
|
||||
if (!pBuf) {
|
||||
code = terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
SEncoder encoder;
|
||||
tEncoderInit(&encoder, POINTER_SHIFT(pBuf, sizeof(SMsgHead)), len);
|
||||
tEncodeSBatchDeleteReq(&encoder, pDelReq);
|
||||
tEncoderClear(&encoder);
|
||||
|
||||
((SMsgHead *)pBuf)->vgId = TD_VID(pSma->pVnode);
|
||||
|
||||
SRpcMsg delMsg = {.msgType = TDMT_VND_BATCH_DEL, .pCont = pBuf, .contLen = len + sizeof(SMsgHead)};
|
||||
code = tmsgPutToQueue(&pSma->pVnode->msgCb, WRITE_QUEUE, &delMsg);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
_exit:
|
||||
taosArrayDestroy(pDelReq->deleteReqs);
|
||||
if (code) {
|
||||
smaError("vgId:%d, failed at line %d to process delete req for smaIndex %" PRIi64 " since %s", SMA_VID(pSma), lino,
|
||||
indexUid, tstrerror(code));
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Insert/Update Time-range-wise SMA data.
|
||||
*
|
||||
|
@ -355,7 +392,6 @@ _end:
|
|||
*/
|
||||
static int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char *msg) {
|
||||
const SArray *pDataBlocks = (const SArray *)msg;
|
||||
// TODO: destroy SSDataBlocks(msg)
|
||||
if (!pDataBlocks) {
|
||||
terrno = TSDB_CODE_TSMA_INVALID_PTR;
|
||||
smaWarn("vgId:%d, insert tsma data failed since pDataBlocks is NULL", SMA_VID(pSma));
|
||||
|
@ -419,8 +455,10 @@ static int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char
|
|||
goto _err;
|
||||
}
|
||||
|
||||
// TODO deleteReq
|
||||
taosArrayDestroy(deleteReq.deleteReqs);
|
||||
if ((terrno = tsmaProcessDelReq(pSma, indexUid, &deleteReq)) != 0) {
|
||||
goto _err;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (!strncasecmp("td.tsma.rst.tb", pTsmaStat->pTSma->dstTbName, 14)) {
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
|
|
|
@ -243,8 +243,8 @@ int32_t tqPushDataRsp(STqHandle* pHandle, int32_t vgId) {
|
|||
tqDoSendDataRsp(&pHandle->msg->info, &dataRsp, pHandle->epoch, pHandle->consumerId, TMQ_MSG_TYPE__POLL_RSP, sver,
|
||||
ever);
|
||||
|
||||
char buf1[80] = {0};
|
||||
char buf2[80] = {0};
|
||||
char buf1[TSDB_OFFSET_LEN] = {0};
|
||||
char buf2[TSDB_OFFSET_LEN] = {0};
|
||||
tFormatOffset(buf1, tListLen(buf1), &dataRsp.reqOffset);
|
||||
tFormatOffset(buf2, tListLen(buf2), &dataRsp.rspOffset);
|
||||
tqDebug("vgId:%d, from consumer:0x%" PRIx64 " (epoch %d) push rsp, block num: %d, req:%s, rsp:%s", vgId,
|
||||
|
@ -259,10 +259,10 @@ int32_t tqSendDataRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPollReq*
|
|||
|
||||
tqDoSendDataRsp(&pMsg->info, pRsp, pReq->epoch, pReq->consumerId, type, sver, ever);
|
||||
|
||||
char buf1[80] = {0};
|
||||
char buf2[80] = {0};
|
||||
tFormatOffset(buf1, 80, &pRsp->reqOffset);
|
||||
tFormatOffset(buf2, 80, &pRsp->rspOffset);
|
||||
char buf1[TSDB_OFFSET_LEN] = {0};
|
||||
char buf2[TSDB_OFFSET_LEN] = {0};
|
||||
tFormatOffset(buf1, TSDB_OFFSET_LEN, &pRsp->reqOffset);
|
||||
tFormatOffset(buf2, TSDB_OFFSET_LEN, &pRsp->rspOffset);
|
||||
|
||||
tqDebug("tmq poll vgId:%d consumer:0x%" PRIx64 " (epoch %d) send rsp, block num:%d, req:%s, rsp:%s, reqId:0x%" PRIx64, vgId,
|
||||
pReq->consumerId, pReq->epoch, pRsp->blockNum, buf1, buf2, pReq->reqId);
|
||||
|
@ -510,8 +510,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
|
|||
pHandle->epoch = reqEpoch;
|
||||
}
|
||||
|
||||
char buf[80];
|
||||
tFormatOffset(buf, 80, &reqOffset);
|
||||
char buf[TSDB_OFFSET_LEN];
|
||||
tFormatOffset(buf, TSDB_OFFSET_LEN, &reqOffset);
|
||||
tqDebug("tmq poll: consumer:0x%" PRIx64 " (epoch %d), subkey %s, recv poll req vgId:%d, req:%s, reqId:0x%" PRIx64,
|
||||
consumerId, req.epoch, pHandle->subKey, vgId, buf, req.reqId);
|
||||
|
||||
|
@ -588,7 +588,7 @@ int32_t tqProcessVgWalInfoReq(STQ* pTq, SRpcMsg* pMsg) {
|
|||
} else {
|
||||
dataRsp.rspOffset.version = currentVer; // return current consume offset value
|
||||
}
|
||||
} else if (reqOffset.type == TMQ_OFFSET__RESET_EARLIEAST) {
|
||||
} else if (reqOffset.type == TMQ_OFFSET__RESET_EARLIEST) {
|
||||
dataRsp.rspOffset.version = sver; // not consume yet, set the earliest position
|
||||
} else if (reqOffset.type == TMQ_OFFSET__RESET_LATEST) {
|
||||
dataRsp.rspOffset.version = ever;
|
||||
|
|
|
@ -388,7 +388,7 @@ bool tqNextBlockInWal(STqReader* pReader, const char* id) {
|
|||
|
||||
int32_t numOfBlocks = taosArrayGetSize(pReader->submit.aSubmitTbData);
|
||||
while (pReader->nextBlk < numOfBlocks) {
|
||||
tqDebug("tq reader next data block %d/%d, len:%d %" PRId64 " %d", pReader->nextBlk,
|
||||
tqTrace("tq reader next data block %d/%d, len:%d %" PRId64 " %d", pReader->nextBlk,
|
||||
numOfBlocks, pReader->msg.msgLen, pReader->msg.ver, pReader->nextBlk);
|
||||
|
||||
SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
|
||||
|
@ -403,7 +403,7 @@ bool tqNextBlockInWal(STqReader* pReader, const char* id) {
|
|||
|
||||
void* ret = taosHashGet(pReader->tbIdHash, &pSubmitTbData->uid, sizeof(int64_t));
|
||||
if (ret != NULL) {
|
||||
tqDebug("tq reader return submit block, uid:%" PRId64 ", ver:%" PRId64, pSubmitTbData->uid, pReader->msg.ver);
|
||||
tqTrace("tq reader return submit block, uid:%" PRId64 ", ver:%" PRId64, pSubmitTbData->uid, pReader->msg.ver);
|
||||
|
||||
SSDataBlock* pRes = NULL;
|
||||
int32_t code = tqRetrieveDataBlock(pReader, &pRes, NULL);
|
||||
|
@ -412,11 +412,11 @@ bool tqNextBlockInWal(STqReader* pReader, const char* id) {
|
|||
}
|
||||
} else {
|
||||
pReader->nextBlk += 1;
|
||||
tqDebug("tq reader discard submit block, uid:%" PRId64 ", continue", pSubmitTbData->uid);
|
||||
tqTrace("tq reader discard submit block, uid:%" PRId64 ", continue", pSubmitTbData->uid);
|
||||
}
|
||||
}
|
||||
|
||||
qDebug("stream scan return empty, all %d submit blocks consumed, %s", numOfBlocks, id);
|
||||
qTrace("stream scan return empty, all %d submit blocks consumed, %s", numOfBlocks, id);
|
||||
tDestroySubmitReq(&pReader->submit, TSDB_MSG_FLG_DECODE);
|
||||
|
||||
pReader->msg.msgStr = NULL;
|
||||
|
@ -604,7 +604,7 @@ static int32_t doSetVal(SColumnInfoData* pColumnInfoData, int32_t rowIndex, SCol
|
|||
}
|
||||
|
||||
int32_t tqRetrieveDataBlock(STqReader* pReader, SSDataBlock** pRes, const char* id) {
|
||||
tqDebug("tq reader retrieve data block %p, index:%d", pReader->msg.msgStr, pReader->nextBlk);
|
||||
tqTrace("tq reader retrieve data block %p, index:%d", pReader->msg.msgStr, pReader->nextBlk);
|
||||
SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk++);
|
||||
|
||||
SSDataBlock* pBlock = pReader->pResBlock;
|
||||
|
|
|
@ -298,10 +298,8 @@ void tqSinkToTablePipeline(SStreamTask* pTask, void* vnode, int64_t ver, void* d
|
|||
if (res == TSDB_CODE_SUCCESS) {
|
||||
memcpy(ctbName, pTableSinkInfo->tbName, strlen(pTableSinkInfo->tbName));
|
||||
} else {
|
||||
char* tmp = buildCtbNameByGroupId(stbFullName, pDataBlock->info.id.groupId);
|
||||
memcpy(ctbName, tmp, strlen(tmp));
|
||||
memcpy(pTableSinkInfo->tbName, tmp, strlen(tmp));
|
||||
taosMemoryFree(tmp);
|
||||
buildCtbNameByGroupIdImpl(stbFullName, pDataBlock->info.id.groupId, ctbName);
|
||||
memcpy(pTableSinkInfo->tbName, ctbName, strlen(ctbName));
|
||||
tqDebug("vgId:%d, gropuId:%" PRIu64 " datablock table name is null", TD_VID(pVnode),
|
||||
pDataBlock->info.id.groupId);
|
||||
}
|
||||
|
|
|
@ -99,15 +99,15 @@ static int32_t extractResetOffsetVal(STqOffsetVal* pOffsetVal, STQ* pTq, STqHand
|
|||
if (pOffset != NULL) {
|
||||
*pOffsetVal = pOffset->val;
|
||||
|
||||
char formatBuf[80];
|
||||
tFormatOffset(formatBuf, 80, pOffsetVal);
|
||||
char formatBuf[TSDB_OFFSET_LEN];
|
||||
tFormatOffset(formatBuf, TSDB_OFFSET_LEN, pOffsetVal);
|
||||
tqDebug("tmq poll: consumer:0x%" PRIx64
|
||||
", subkey %s, vgId:%d, existed offset found, offset reset to %s and continue. reqId:0x%" PRIx64,
|
||||
consumerId, pHandle->subKey, vgId, formatBuf, pRequest->reqId);
|
||||
return 0;
|
||||
} else {
|
||||
// no poll occurs in this vnode for this topic, let's seek to the right offset value.
|
||||
if (reqOffset.type == TMQ_OFFSET__RESET_EARLIEAST) {
|
||||
if (reqOffset.type == TMQ_OFFSET__RESET_EARLIEST) {
|
||||
if (pRequest->useSnapshot) {
|
||||
tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey:%s, vgId:%d, (earliest) set offset to be snapshot",
|
||||
consumerId, pHandle->subKey, vgId);
|
||||
|
@ -168,7 +168,7 @@ static int32_t extractDataAndRspForNormalSubscribe(STQ* pTq, STqHandle* pHandle,
|
|||
|
||||
qSetTaskId(pHandle->execHandle.task, consumerId, pRequest->reqId);
|
||||
code = tqScanData(pTq, pHandle, &dataRsp, pOffset);
|
||||
if(code != 0 && terrno != TSDB_CODE_WAL_LOG_NOT_EXIST) {
|
||||
if (code != 0 && terrno != TSDB_CODE_WAL_LOG_NOT_EXIST) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
@ -177,20 +177,27 @@ static int32_t extractDataAndRspForNormalSubscribe(STQ* pTq, STqHandle* pHandle,
|
|||
// lock
|
||||
taosWLockLatch(&pTq->lock);
|
||||
int64_t ver = walGetCommittedVer(pTq->pVnode->pWal);
|
||||
if (pOffset->version >= ver || dataRsp.rspOffset.version >= ver){ //check if there are data again to avoid lost data
|
||||
if (pOffset->version >= ver ||
|
||||
dataRsp.rspOffset.version >= ver) { // check if there are data again to avoid lost data
|
||||
code = tqRegisterPushHandle(pTq, pHandle, pMsg);
|
||||
taosWUnLockLatch(&pTq->lock);
|
||||
goto end;
|
||||
}else{
|
||||
} else {
|
||||
taosWUnLockLatch(&pTq->lock);
|
||||
}
|
||||
}
|
||||
|
||||
code = tqSendDataRsp(pHandle, pMsg, pRequest, (SMqDataRsp*)&dataRsp, TMQ_MSG_TYPE__POLL_RSP, vgId);
|
||||
|
||||
end :
|
||||
end : {
|
||||
char buf[TSDB_OFFSET_LEN] = {0};
|
||||
tFormatOffset(buf, TSDB_OFFSET_LEN, &dataRsp.rspOffset);
|
||||
tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s, vgId:%d, rsp block:%d, rsp offset type:%s, reqId:0x%" PRIx64
|
||||
" code:%d",
|
||||
consumerId, pHandle->subKey, vgId, dataRsp.blockNum, buf, pRequest->reqId, code);
|
||||
tDeleteMqDataRsp(&dataRsp);
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest,
|
||||
|
|
|
@ -325,7 +325,7 @@ int vnodeValidateTableHash(SVnode *pVnode, char *tableFName) {
|
|||
|
||||
if (hashValue < pVnode->config.hashBegin || hashValue > pVnode->config.hashEnd) {
|
||||
terrno = TSDB_CODE_VND_HASH_MISMATCH;
|
||||
return TSDB_CODE_VND_HASH_MISMATCH;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "storageapi.h"
|
||||
#include "vnodeInt.h"
|
||||
#include "tstreamUpdate.h"
|
||||
#include "meta.h"
|
||||
#include "storageapi.h"
|
||||
#include "tstreamUpdate.h"
|
||||
#include "vnodeInt.h"
|
||||
|
||||
static void initTsdbReaderAPI(TsdReader* pReader);
|
||||
static void initMetadataAPI(SStoreMeta* pMeta);
|
||||
|
@ -56,10 +56,10 @@ void initTsdbReaderAPI(TsdReader* pReader) {
|
|||
pReader->tsdReaderResetStatus = tsdbReaderReset;
|
||||
|
||||
pReader->tsdReaderGetDataBlockDistInfo = tsdbGetFileBlocksDistInfo;
|
||||
pReader->tsdReaderGetNumOfInMemRows = tsdbGetNumOfRowsInMemTable; // todo this function should be moved away
|
||||
pReader->tsdReaderGetNumOfInMemRows = tsdbGetNumOfRowsInMemTable; // todo this function should be moved away
|
||||
|
||||
pReader->tsdSetQueryTableList = tsdbSetTableList;
|
||||
pReader->tsdSetReaderTaskId = (void (*)(void *, const char *))tsdbReaderSetId;
|
||||
pReader->tsdSetReaderTaskId = (void (*)(void*, const char*))tsdbReaderSetId;
|
||||
}
|
||||
|
||||
void initMetadataAPI(SStoreMeta* pMeta) {
|
||||
|
@ -67,6 +67,8 @@ void initMetadataAPI(SStoreMeta* pMeta) {
|
|||
|
||||
pMeta->openTableMetaCursor = metaOpenTbCursor;
|
||||
pMeta->closeTableMetaCursor = metaCloseTbCursor;
|
||||
pMeta->pauseTableMetaCursor = metaPauseTbCursor;
|
||||
pMeta->resumeTableMetaCursor = metaResumeTbCursor;
|
||||
pMeta->cursorNext = metaTbCursorNext;
|
||||
pMeta->cursorPrev = metaTbCursorPrev;
|
||||
|
||||
|
@ -78,7 +80,7 @@ void initMetadataAPI(SStoreMeta* pMeta) {
|
|||
pMeta->storeGetIndexInfo = vnodeGetIdx;
|
||||
pMeta->getInvertIndex = vnodeGetIvtIdx;
|
||||
|
||||
pMeta->extractTagVal = (const void *(*)(const void *, int16_t, STagVal *))metaGetTableTagVal;
|
||||
pMeta->extractTagVal = (const void* (*)(const void*, int16_t, STagVal*))metaGetTableTagVal;
|
||||
pMeta->getTableTags = metaGetTableTags;
|
||||
pMeta->getTableTagsByUid = metaGetTableTagsByUids;
|
||||
|
||||
|
@ -86,7 +88,7 @@ void initMetadataAPI(SStoreMeta* pMeta) {
|
|||
pMeta->getTableTypeByName = metaGetTableTypeByName;
|
||||
pMeta->getTableNameByUid = metaGetTableNameByUid;
|
||||
|
||||
pMeta->getTableSchema = tsdbGetTableSchema; // todo refactor
|
||||
pMeta->getTableSchema = tsdbGetTableSchema; // todo refactor
|
||||
pMeta->storeGetTableList = vnodeGetTableList;
|
||||
|
||||
pMeta->getCachedTableList = metaGetCachedTableUidList;
|
||||
|
@ -106,7 +108,7 @@ void initTqAPI(SStoreTqReader* pTq) {
|
|||
|
||||
pTq->tqReaderNextBlockInWal = tqNextBlockInWal;
|
||||
|
||||
pTq->tqNextBlockImpl = tqNextBlockImpl;// todo remove it
|
||||
pTq->tqNextBlockImpl = tqNextBlockImpl; // todo remove it
|
||||
|
||||
pTq->tqReaderAddTables = tqReaderAddTbUidList;
|
||||
pTq->tqReaderSetQueryTableList = tqReaderSetTbUidList;
|
||||
|
@ -116,10 +118,10 @@ void initTqAPI(SStoreTqReader* pTq) {
|
|||
pTq->tqReaderIsQueriedTable = tqReaderIsQueriedTable;
|
||||
pTq->tqReaderCurrentBlockConsumed = tqCurrentBlockConsumed;
|
||||
|
||||
pTq->tqReaderGetWalReader = tqGetWalReader; // todo remove it
|
||||
pTq->tqReaderRetrieveTaosXBlock = tqRetrieveTaosxBlock; // todo remove it
|
||||
pTq->tqReaderGetWalReader = tqGetWalReader; // todo remove it
|
||||
pTq->tqReaderRetrieveTaosXBlock = tqRetrieveTaosxBlock; // todo remove it
|
||||
|
||||
pTq->tqReaderSetSubmitMsg = tqReaderSetSubmitMsg; // todo remove it
|
||||
pTq->tqReaderSetSubmitMsg = tqReaderSetSubmitMsg; // todo remove it
|
||||
pTq->tqGetResultBlock = tqGetResultBlock;
|
||||
|
||||
pTq->tqReaderNextBlockFilterOut = tqNextDataBlockFilterOut;
|
||||
|
@ -199,7 +201,7 @@ void initStateStoreAPI(SStateStore* pStore) {
|
|||
pStore->streamStateClose = streamStateClose;
|
||||
pStore->streamStateBegin = streamStateBegin;
|
||||
pStore->streamStateCommit = streamStateCommit;
|
||||
pStore->streamStateDestroy= streamStateDestroy;
|
||||
pStore->streamStateDestroy = streamStateDestroy;
|
||||
pStore->streamStateDeleteCheckPoint = streamStateDeleteCheckPoint;
|
||||
}
|
||||
|
||||
|
@ -239,4 +241,4 @@ void initSnapshotFn(SStoreSnapshotFn* pSnapshot) {
|
|||
pSnapshot->destroySnapshot = destroySnapContext;
|
||||
pSnapshot->getMetaTableInfoFromSnapshot = getMetaTableInfoFromSnapshot;
|
||||
pSnapshot->getTableInfoFromSnapshot = getTableInfoFromSnapshot;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,15 +129,20 @@ int32_t vnodeAlterReplica(const char *path, SAlterVnodeReplicaReq *pReq, STfs *p
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t vnodeVgroupIdLen(int32_t vgId) {
|
||||
char tmp[TSDB_FILENAME_LEN];
|
||||
sprintf(tmp, "%d", vgId);
|
||||
return strlen(tmp);
|
||||
}
|
||||
|
||||
int32_t vnodeRenameVgroupId(const char *srcPath, const char *dstPath, int32_t srcVgId, int32_t dstVgId, STfs *pTfs) {
|
||||
int32_t ret = tfsRename(pTfs, srcPath, dstPath);
|
||||
if (ret != 0) return ret;
|
||||
int32_t ret = 0;
|
||||
|
||||
char oldRname[TSDB_FILENAME_LEN] = {0};
|
||||
char newRname[TSDB_FILENAME_LEN] = {0};
|
||||
char tsdbPath[TSDB_FILENAME_LEN] = {0};
|
||||
char tsdbFilePrefix[TSDB_FILENAME_LEN] = {0};
|
||||
snprintf(tsdbPath, TSDB_FILENAME_LEN, "%s%stsdb", dstPath, TD_DIRSEP);
|
||||
snprintf(tsdbPath, TSDB_FILENAME_LEN, "%s%stsdb", srcPath, TD_DIRSEP);
|
||||
snprintf(tsdbFilePrefix, TSDB_FILENAME_LEN, "tsdb%sv", TD_DIRSEP);
|
||||
|
||||
STfsDir *tsdbDir = tfsOpendir(pTfs, tsdbPath);
|
||||
|
@ -154,8 +159,7 @@ int32_t vnodeRenameVgroupId(const char *srcPath, const char *dstPath, int32_t sr
|
|||
|
||||
int32_t tsdbFileVgId = atoi(tsdbFilePrefixPos + 6);
|
||||
if (tsdbFileVgId == srcVgId) {
|
||||
char *tsdbFileSurfixPos = strstr(tsdbFilePrefixPos, "f");
|
||||
if (tsdbFileSurfixPos == NULL) continue;
|
||||
char *tsdbFileSurfixPos = tsdbFilePrefixPos + 6 + vnodeVgroupIdLen(srcVgId);
|
||||
|
||||
tsdbFilePrefixPos[6] = 0;
|
||||
snprintf(newRname, TSDB_FILENAME_LEN, "%s%d%s", oldRname, dstVgId, tsdbFileSurfixPos);
|
||||
|
@ -163,7 +167,7 @@ int32_t vnodeRenameVgroupId(const char *srcPath, const char *dstPath, int32_t sr
|
|||
|
||||
ret = tfsRename(pTfs, tsdbFile->rname, newRname);
|
||||
if (ret != 0) {
|
||||
vInfo("vgId:%d, failed to rename file from %s to %s since %s", dstVgId, tsdbFile->rname, newRname, terrstr());
|
||||
vError("vgId:%d, failed to rename file from %s to %s since %s", dstVgId, tsdbFile->rname, newRname, terrstr());
|
||||
tfsClosedir(tsdbDir);
|
||||
return ret;
|
||||
}
|
||||
|
@ -171,6 +175,21 @@ int32_t vnodeRenameVgroupId(const char *srcPath, const char *dstPath, int32_t sr
|
|||
}
|
||||
|
||||
tfsClosedir(tsdbDir);
|
||||
|
||||
vInfo("vgId:%d, rename dir from %s to %s", dstVgId, srcPath, dstPath);
|
||||
ret = tfsRename(pTfs, srcPath, dstPath);
|
||||
if (ret != 0) {
|
||||
vError("vgId:%d, failed to rename dir from %s to %s since %s", dstVgId, srcPath, dstPath, terrstr());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t vnodeGetAbsDir(const char *relPath, STfs *pTfs, char *buf, size_t bufLen) {
|
||||
if (pTfs) {
|
||||
snprintf(buf, bufLen, "%s%s%s", tfsGetPrimaryPath(pTfs), TD_DIRSEP, relPath);
|
||||
} else {
|
||||
snprintf(buf, bufLen, "%s", relPath);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -179,13 +198,7 @@ int32_t vnodeAlterHashRange(const char *srcPath, const char *dstPath, SAlterVnod
|
|||
char dir[TSDB_FILENAME_LEN] = {0};
|
||||
int32_t ret = 0;
|
||||
|
||||
if (pTfs) {
|
||||
snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pTfs), TD_DIRSEP, srcPath);
|
||||
} else {
|
||||
snprintf(dir, TSDB_FILENAME_LEN, "%s", srcPath);
|
||||
}
|
||||
|
||||
// todo add stat file to handle exception while vnode open
|
||||
vnodeGetAbsDir(srcPath, pTfs, dir, TSDB_FILENAME_LEN);
|
||||
|
||||
ret = vnodeLoadInfo(dir, &info);
|
||||
if (ret < 0) {
|
||||
|
@ -240,6 +253,42 @@ int32_t vnodeAlterHashRange(const char *srcPath, const char *dstPath, SAlterVnod
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t vnodeRestoreVgroupId(const char *srcPath, const char *dstPath, int32_t srcVgId, int32_t dstVgId, STfs *pTfs) {
|
||||
SVnodeInfo info = {0};
|
||||
char dir[TSDB_FILENAME_LEN] = {0};
|
||||
|
||||
vnodeGetAbsDir(dstPath, pTfs, dir, TSDB_FILENAME_LEN);
|
||||
if (vnodeLoadInfo(dir, &info) == 0) {
|
||||
if (info.config.vgId != dstVgId) {
|
||||
vError("vgId:%d, unexpected vnode config.vgId:%d", dstVgId, info.config.vgId);
|
||||
return -1;
|
||||
}
|
||||
return dstVgId;
|
||||
}
|
||||
|
||||
vnodeGetAbsDir(srcPath, pTfs, dir, TSDB_FILENAME_LEN);
|
||||
if (vnodeLoadInfo(dir, &info) < 0) {
|
||||
vError("vgId:%d, failed to read vnode config from %s since %s", srcVgId, srcPath, tstrerror(terrno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (info.config.vgId == srcVgId) {
|
||||
vInfo("vgId:%d, rollback alter hashrange", srcVgId);
|
||||
return srcVgId;
|
||||
} else if (info.config.vgId != dstVgId) {
|
||||
vError("vgId:%d, unexpected vnode config.vgId:%d", dstVgId, info.config.vgId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
vInfo("vgId:%d, rename %s to %s", dstVgId, srcPath, dstPath);
|
||||
if (vnodeRenameVgroupId(srcPath, dstPath, srcVgId, dstVgId, pTfs) < 0) {
|
||||
vError("vgId:%d, failed to rename vnode from %s to %s since %s", dstVgId, srcPath, dstPath, tstrerror(terrno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return dstVgId;
|
||||
}
|
||||
|
||||
void vnodeDestroy(const char *path, STfs *pTfs) {
|
||||
vInfo("path:%s is removed while destroy vnode", path);
|
||||
tfsRmdir(pTfs, path);
|
||||
|
|
|
@ -37,7 +37,7 @@ static int32_t vnodeProcessCreateIndexReq(SVnode *pVnode, int64_t ver, void *pRe
|
|||
static int32_t vnodeProcessDropIndexReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
static int32_t vnodeProcessCompactVnodeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
|
||||
static int32_t vnodePreprocessCreateTableReq(SVnode *pVnode, SDecoder *pCoder, int64_t ctime, int64_t *pUid) {
|
||||
static int32_t vnodePreprocessCreateTableReq(SVnode *pVnode, SDecoder *pCoder, int64_t btime, int64_t *pUid) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
|
@ -66,8 +66,8 @@ static int32_t vnodePreprocessCreateTableReq(SVnode *pVnode, SDecoder *pCoder, i
|
|||
}
|
||||
*(int64_t *)(pCoder->data + pCoder->pos) = uid;
|
||||
|
||||
// ctime
|
||||
*(int64_t *)(pCoder->data + pCoder->pos + 8) = ctime;
|
||||
// btime
|
||||
*(int64_t *)(pCoder->data + pCoder->pos + 8) = btime;
|
||||
|
||||
tEndDecode(pCoder);
|
||||
|
||||
|
@ -84,7 +84,7 @@ static int32_t vnodePreProcessCreateTableMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
|||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
int64_t ctime = taosGetTimestampMs();
|
||||
int64_t btime = taosGetTimestampMs();
|
||||
SDecoder dc = {0};
|
||||
int32_t nReqs;
|
||||
|
||||
|
@ -99,7 +99,7 @@ static int32_t vnodePreProcessCreateTableMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
|||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
for (int32_t iReq = 0; iReq < nReqs; iReq++) {
|
||||
code = vnodePreprocessCreateTableReq(pVnode, &dc, ctime, NULL);
|
||||
code = vnodePreprocessCreateTableReq(pVnode, &dc, btime, NULL);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
|
@ -113,8 +113,35 @@ _exit:
|
|||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t vnodePreProcessAlterTableMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||
int32_t code = TSDB_CODE_INVALID_MSG;
|
||||
int32_t lino = 0;
|
||||
|
||||
SDecoder dc = {0};
|
||||
tDecoderInit(&dc, (uint8_t *)pMsg->pCont + sizeof(SMsgHead), pMsg->contLen - sizeof(SMsgHead));
|
||||
|
||||
SVAlterTbReq vAlterTbReq = {0};
|
||||
int64_t ctimeMs = taosGetTimestampMs();
|
||||
if (tDecodeSVAlterTbReqSetCtime(&dc, &vAlterTbReq, ctimeMs) < 0) {
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
code = 0;
|
||||
|
||||
_exit:
|
||||
tDecoderClear(&dc);
|
||||
if (code) {
|
||||
vError("vgId:%d %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code));
|
||||
} else {
|
||||
vTrace("vgId:%d %s done, table:%s ctimeMs generated:%" PRId64, TD_VID(pVnode), __func__, vAlterTbReq.tbName,
|
||||
ctimeMs);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
extern int64_t tsMaxKeyByPrecision[];
|
||||
static int32_t vnodePreProcessSubmitTbData(SVnode *pVnode, SDecoder *pCoder, int64_t ctime) {
|
||||
static int32_t vnodePreProcessSubmitTbData(SVnode *pVnode, SDecoder *pCoder, int64_t btimeMs, int64_t ctimeMs) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
|
@ -131,7 +158,7 @@ static int32_t vnodePreProcessSubmitTbData(SVnode *pVnode, SDecoder *pCoder, int
|
|||
|
||||
int64_t uid;
|
||||
if (submitTbData.flags & SUBMIT_REQ_AUTO_CREATE_TABLE) {
|
||||
code = vnodePreprocessCreateTableReq(pVnode, pCoder, ctime, &uid);
|
||||
code = vnodePreprocessCreateTableReq(pVnode, pCoder, btimeMs, &uid);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
|
@ -157,7 +184,7 @@ static int32_t vnodePreProcessSubmitTbData(SVnode *pVnode, SDecoder *pCoder, int
|
|||
}
|
||||
|
||||
// scan and check
|
||||
TSKEY now = ctime;
|
||||
TSKEY now = btimeMs;
|
||||
if (pVnode->config.tsdbCfg.precision == TSDB_TIME_PRECISION_MICRO) {
|
||||
now *= 1000;
|
||||
} else if (pVnode->config.tsdbCfg.precision == TSDB_TIME_PRECISION_NANO) {
|
||||
|
@ -174,7 +201,6 @@ static int32_t vnodePreProcessSubmitTbData(SVnode *pVnode, SDecoder *pCoder, int
|
|||
|
||||
SColData colData = {0};
|
||||
pCoder->pos += tGetColData(pCoder->data + pCoder->pos, &colData);
|
||||
|
||||
if (colData.flag != HAS_VALUE) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
|
@ -186,6 +212,10 @@ static int32_t vnodePreProcessSubmitTbData(SVnode *pVnode, SDecoder *pCoder, int
|
|||
goto _exit;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint64_t i = 1; i < nColData; i++) {
|
||||
pCoder->pos += tGetColData(pCoder->data + pCoder->pos, &colData);
|
||||
}
|
||||
} else {
|
||||
uint64_t nRow;
|
||||
if (tDecodeU64v(pCoder, &nRow) < 0) {
|
||||
|
@ -204,6 +234,9 @@ static int32_t vnodePreProcessSubmitTbData(SVnode *pVnode, SDecoder *pCoder, int
|
|||
}
|
||||
}
|
||||
|
||||
*(int64_t *)(pCoder->data + pCoder->pos) = ctimeMs;
|
||||
pCoder->pos += sizeof(int64_t);
|
||||
|
||||
tEndDecode(pCoder);
|
||||
|
||||
_exit:
|
||||
|
@ -233,9 +266,10 @@ static int32_t vnodePreProcessSubmitMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
|||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
int64_t ctime = taosGetTimestampMs();
|
||||
int64_t btimeMs = taosGetTimestampMs();
|
||||
int64_t ctimeMs = btimeMs;
|
||||
for (int32_t i = 0; i < nSubmitTbData; i++) {
|
||||
code = vnodePreProcessSubmitTbData(pVnode, pCoder, ctime);
|
||||
code = vnodePreProcessSubmitTbData(pVnode, pCoder, btimeMs, ctimeMs);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
|
@ -265,6 +299,7 @@ static int32_t vnodePreProcessDeleteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
|||
code = qWorkerProcessDeleteMsg(&handle, pVnode->pQuery, pMsg, &res);
|
||||
if (code) goto _exit;
|
||||
|
||||
res.ctimeMs = taosGetTimestampMs();
|
||||
// malloc and encode
|
||||
tEncodeSize(tEncodeDeleteRes, &res, size, ret);
|
||||
pCont = rpcMallocCont(size + sizeof(SMsgHead));
|
||||
|
@ -286,6 +321,31 @@ _exit:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t vnodePreProcessBatchDeleteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
int64_t ctimeMs = taosGetTimestampMs();
|
||||
SBatchDeleteReq pReq = {0};
|
||||
SDecoder *pCoder = &(SDecoder){0};
|
||||
|
||||
tDecoderInit(pCoder, (uint8_t *)pMsg->pCont + sizeof(SMsgHead), pMsg->contLen - sizeof(SMsgHead));
|
||||
|
||||
if (tDecodeSBatchDeleteReqSetCtime(pCoder, &pReq, ctimeMs) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
tDecoderClear(pCoder);
|
||||
taosArrayDestroy(pReq.deleteReqs);
|
||||
|
||||
if (code) {
|
||||
vError("vgId:%d %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code));
|
||||
} else {
|
||||
vTrace("vgId:%d %s done, ctimeMs generated:%" PRId64, TD_VID(pVnode), __func__, ctimeMs);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t vnodePreProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
|
||||
|
@ -293,12 +353,18 @@ int32_t vnodePreProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
|||
case TDMT_VND_CREATE_TABLE: {
|
||||
code = vnodePreProcessCreateTableMsg(pVnode, pMsg);
|
||||
} break;
|
||||
case TDMT_VND_ALTER_TABLE: {
|
||||
code = vnodePreProcessAlterTableMsg(pVnode, pMsg);
|
||||
} break;
|
||||
case TDMT_VND_SUBMIT: {
|
||||
code = vnodePreProcessSubmitMsg(pVnode, pMsg);
|
||||
} break;
|
||||
case TDMT_VND_DELETE: {
|
||||
code = vnodePreProcessDeleteMsg(pVnode, pMsg);
|
||||
} break;
|
||||
case TDMT_VND_BATCH_DEL: {
|
||||
code = vnodePreProcessBatchDeleteMsg(pVnode, pMsg);
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -597,9 +663,7 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: remove the function
|
||||
void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) {
|
||||
// TODO
|
||||
// blockDebugShowDataBlocks(data, __func__);
|
||||
tdProcessTSmaInsert(((SVnode *)pVnode)->pSma, smaId, (const char *)data);
|
||||
}
|
||||
|
@ -647,8 +711,8 @@ static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t ver, void *pReq,
|
|||
goto end;
|
||||
}
|
||||
|
||||
vDebug("vgId:%d, drop ttl table req will be processed, time:%d", pVnode->config.vgId, ttlReq.timestamp);
|
||||
int32_t ret = metaTtlDropTable(pVnode->pMeta, ttlReq.timestamp, tbUids);
|
||||
vDebug("vgId:%d, drop ttl table req will be processed, time:%" PRId32, pVnode->config.vgId, ttlReq.timestampSec);
|
||||
int32_t ret = metaTtlDropTable(pVnode->pMeta, (int64_t)ttlReq.timestampSec * 1000, tbUids);
|
||||
if (ret != 0) {
|
||||
goto end;
|
||||
}
|
||||
|
@ -656,7 +720,7 @@ static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t ver, void *pReq,
|
|||
tqUpdateTbUidList(pVnode->pTq, tbUids, false);
|
||||
}
|
||||
|
||||
vnodeAsyncRentention(pVnode, ttlReq.timestamp);
|
||||
vnodeAsyncRentention(pVnode, ttlReq.timestampSec);
|
||||
|
||||
end:
|
||||
taosArrayDestroy(tbUids);
|
||||
|
@ -1392,6 +1456,9 @@ static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t ver, void *pReq, in
|
|||
code = tsdbInsertTableData(pVnode->pTsdb, ver, pSubmitTbData, &affectedRows);
|
||||
if (code) goto _exit;
|
||||
|
||||
code = metaUpdateChangeTime(pVnode->pMeta, pSubmitTbData->uid, pSubmitTbData->ctimeMs);
|
||||
if (code) goto _exit;
|
||||
|
||||
pSubmitRsp->affectedRows += affectedRows;
|
||||
}
|
||||
|
||||
|
@ -1488,6 +1555,7 @@ static int32_t vnodeConsolidateAlterHashRange(SVnode *pVnode, int64_t ver) {
|
|||
pVnode->config.hashBegin, pVnode->config.hashEnd, ver);
|
||||
|
||||
// TODO: trim meta of tables from TDB per hash range [pVnode->config.hashBegin, pVnode->config.hashEnd]
|
||||
code = metaTrimTables(pVnode->pMeta);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -1645,6 +1713,14 @@ static int32_t vnodeProcessBatchDeleteReq(SVnode *pVnode, int64_t ver, void *pRe
|
|||
TD_VID(pVnode), terrstr(), deleteReq.suid, uid, pOneReq->startTs, pOneReq->endTs);
|
||||
}
|
||||
|
||||
code = metaUpdateChangeTime(pVnode->pMeta, uid, deleteReq.ctimeMs);
|
||||
if (code < 0) {
|
||||
terrno = code;
|
||||
vError("vgId:%d, update change time error since %s, suid:%" PRId64 ", uid:%" PRId64 ", start ts:%" PRId64
|
||||
", end ts:%" PRId64,
|
||||
TD_VID(pVnode), terrstr(), deleteReq.suid, uid, pOneReq->startTs, pOneReq->endTs);
|
||||
}
|
||||
|
||||
tDecoderClear(&mr.coder);
|
||||
}
|
||||
metaReaderClear(&mr);
|
||||
|
@ -1673,8 +1749,10 @@ static int32_t vnodeProcessDeleteReq(SVnode *pVnode, int64_t ver, void *pReq, in
|
|||
ASSERT(taosArrayGetSize(pRes->uidList) == 0 || (pRes->skey != 0 && pRes->ekey != 0));
|
||||
|
||||
for (int32_t iUid = 0; iUid < taosArrayGetSize(pRes->uidList); iUid++) {
|
||||
code = tsdbDeleteTableData(pVnode->pTsdb, ver, pRes->suid, *(uint64_t *)taosArrayGet(pRes->uidList, iUid),
|
||||
pRes->skey, pRes->ekey);
|
||||
uint64_t uid = *(uint64_t *)taosArrayGet(pRes->uidList, iUid);
|
||||
code = tsdbDeleteTableData(pVnode->pTsdb, ver, pRes->suid, uid, pRes->skey, pRes->ekey);
|
||||
if (code) goto _err;
|
||||
code = metaUpdateChangeTime(pVnode->pMeta, uid, pRes->ctimeMs);
|
||||
if (code) goto _err;
|
||||
}
|
||||
|
||||
|
|
|
@ -431,7 +431,7 @@ static int32_t vnodeSyncApplyMsg(const SSyncFSM *pFsm, SRpcMsg *pMsg, const SFsm
|
|||
return tmsgPutToQueue(&pVnode->msgCb, APPLY_QUEUE, pMsg);
|
||||
}
|
||||
|
||||
static int32_t vnodeSyncCommitMsg(const SSyncFSM *pFsm, SRpcMsg *pMsg, const SFsmCbMeta *pMeta) {
|
||||
static int32_t vnodeSyncCommitMsg(const SSyncFSM *pFsm, SRpcMsg *pMsg, SFsmCbMeta *pMeta) {
|
||||
if (pMsg->code == 0) {
|
||||
return vnodeSyncApplyMsg(pFsm, pMsg, pMeta);
|
||||
}
|
||||
|
@ -451,7 +451,7 @@ static int32_t vnodeSyncCommitMsg(const SSyncFSM *pFsm, SRpcMsg *pMsg, const SFs
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t vnodeSyncPreCommitMsg(const SSyncFSM *pFsm, SRpcMsg *pMsg, const SFsmCbMeta *pMeta) {
|
||||
static int32_t vnodeSyncPreCommitMsg(const SSyncFSM *pFsm, SRpcMsg *pMsg, SFsmCbMeta *pMeta) {
|
||||
if (pMeta->isWeak == 1) {
|
||||
return vnodeSyncApplyMsg(pFsm, pMsg, pMeta);
|
||||
}
|
||||
|
@ -463,7 +463,7 @@ static SyncIndex vnodeSyncAppliedIndex(const SSyncFSM *pFSM) {
|
|||
return atomic_load_64(&pVnode->state.applied);
|
||||
}
|
||||
|
||||
static void vnodeSyncRollBackMsg(const SSyncFSM *pFsm, SRpcMsg *pMsg, const SFsmCbMeta *pMeta) {
|
||||
static void vnodeSyncRollBackMsg(const SSyncFSM *pFsm, SRpcMsg *pMsg, SFsmCbMeta *pMeta) {
|
||||
SVnode *pVnode = pFsm->data;
|
||||
vTrace("vgId:%d, rollback-cb is excuted, fsm:%p, index:%" PRId64 ", weak:%d, code:%d, state:%d %s, type:%s",
|
||||
pVnode->config.vgId, pFsm, pMeta->index, pMeta->isWeak, pMeta->code, pMeta->state, syncStr(pMeta->state),
|
||||
|
|
|
@ -1593,10 +1593,13 @@ int32_t ctgChkSetAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res) {
|
|||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
tNameGetFullDbName(&pReq->tbName, dbFName);
|
||||
|
||||
// since that we add read/write previliges when create db, there is no need to check createdDbs
|
||||
#if 0
|
||||
if (pInfo->createdDbs && taosHashGet(pInfo->createdDbs, dbFName, strlen(dbFName))) {
|
||||
pRes->pass = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (pReq->type) {
|
||||
case AUTH_TYPE_READ: {
|
||||
|
|
|
@ -145,7 +145,7 @@ typedef struct SExplainCtx {
|
|||
SHashObj *groupHash; // Hash<SExplainGroup>
|
||||
} SExplainCtx;
|
||||
|
||||
#define EXPLAIN_ORDER_STRING(_order) ((ORDER_ASC == _order) ? "asc" : "desc")
|
||||
#define EXPLAIN_ORDER_STRING(_order) ((ORDER_ASC == _order) ? "asc" : ORDER_DESC == _order ? "desc" : "unknown")
|
||||
#define EXPLAIN_JOIN_STRING(_type) ((JOIN_TYPE_INNER == _type) ? "Inner join" : "Join")
|
||||
|
||||
#define INVERAL_TIME_FROM_PRECISION_TO_UNIT(_t, _u, _p) (((_u) == 'n' || (_u) == 'y') ? (_t) : (convertTimeFromPrecisionToUnit(_t, _p, _u)))
|
||||
|
|
|
@ -499,6 +499,9 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i
|
|||
EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT, pPrjNode->pProjections->length);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pPrjNode->node.pOutputDataBlockDesc->totalRowSize);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_INPUT_ORDER_FORMAT, EXPLAIN_ORDER_STRING(pPrjNode->node.inputTsOrder));
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT);
|
||||
EXPLAIN_ROW_END();
|
||||
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level));
|
||||
|
@ -544,6 +547,9 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i
|
|||
EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT, pJoinNode->pTargets->length);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pJoinNode->node.pOutputDataBlockDesc->totalRowSize);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_INPUT_ORDER_FORMAT, EXPLAIN_ORDER_STRING(pJoinNode->node.inputTsOrder));
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT);
|
||||
EXPLAIN_ROW_END();
|
||||
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level));
|
||||
|
@ -597,6 +603,9 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i
|
|||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_GROUPS_FORMAT, pAggNode->pGroupKeys->length);
|
||||
}
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_INPUT_ORDER_FORMAT, EXPLAIN_ORDER_STRING(pAggNode->node.inputTsOrder));
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT);
|
||||
EXPLAIN_ROW_END();
|
||||
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level));
|
||||
|
@ -716,6 +725,11 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i
|
|||
case QUERY_NODE_PHYSICAL_PLAN_SORT: {
|
||||
SSortPhysiNode *pSortNode = (SSortPhysiNode *)pNode;
|
||||
EXPLAIN_ROW_NEW(level, EXPLAIN_SORT_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_INPUT_ORDER_FORMAT, EXPLAIN_ORDER_STRING(pSortNode->node.inputTsOrder));
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_OUTPUT_ORDER_TYPE_FORMAT, EXPLAIN_ORDER_STRING(pSortNode->node.outputTsOrder));
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_LEFT_PARENTHESIS_FORMAT);
|
||||
if (pResNode->pExecInfo) {
|
||||
QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen));
|
||||
|
@ -796,9 +810,10 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i
|
|||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pIntNode->window.node.pOutputDataBlockDesc->totalRowSize);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_INPUT_ORDER_FORMAT, EXPLAIN_ORDER_STRING(pIntNode->window.inputTsOrder));
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_INPUT_ORDER_FORMAT, EXPLAIN_ORDER_STRING(pIntNode->window.node.inputTsOrder));
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_OUTPUT_ORDER_TYPE_FORMAT, EXPLAIN_ORDER_STRING(pIntNode->window.node.outputTsOrder));
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_OUTPUT_ORDER_TYPE_FORMAT, EXPLAIN_ORDER_STRING(pIntNode->window.outputTsOrder));
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT);
|
||||
EXPLAIN_ROW_END();
|
||||
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level));
|
||||
|
@ -847,6 +862,10 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i
|
|||
EXPLAIN_ROW_APPEND(EXPLAIN_FUNCTIONS_FORMAT, pIntNode->window.pFuncs->length);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pIntNode->window.node.pOutputDataBlockDesc->totalRowSize);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_INPUT_ORDER_FORMAT, EXPLAIN_ORDER_STRING(pIntNode->window.node.inputTsOrder));
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_OUTPUT_ORDER_TYPE_FORMAT, EXPLAIN_ORDER_STRING(pIntNode->window.node.outputTsOrder));
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT);
|
||||
EXPLAIN_ROW_END();
|
||||
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level));
|
||||
|
@ -895,6 +914,9 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i
|
|||
EXPLAIN_ROW_APPEND(EXPLAIN_MODE_FORMAT, nodesGetFillModeString(pFillNode->mode));
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pFillNode->node.pOutputDataBlockDesc->totalRowSize);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_INPUT_ORDER_FORMAT, EXPLAIN_ORDER_STRING(pFillNode->node.inputTsOrder));
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT);
|
||||
EXPLAIN_ROW_END();
|
||||
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level));
|
||||
|
@ -1080,6 +1102,10 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i
|
|||
EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT, nodesGetOutputNumFromSlotList(pDescNode->pSlots));
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pDescNode->totalRowSize);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_INPUT_ORDER_FORMAT, EXPLAIN_ORDER_STRING(pMergeNode->node.inputTsOrder));
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_OUTPUT_ORDER_TYPE_FORMAT, EXPLAIN_ORDER_STRING(pMergeNode->node.outputTsOrder));
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT);
|
||||
EXPLAIN_ROW_END();
|
||||
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level));
|
||||
|
|
|
@ -75,10 +75,11 @@ typedef struct SResultRowInfo {
|
|||
} SResultRowInfo;
|
||||
|
||||
typedef struct SColMatchItem {
|
||||
int32_t colId;
|
||||
int32_t srcSlotId;
|
||||
int32_t dstSlotId;
|
||||
bool needOutput;
|
||||
int32_t colId;
|
||||
int32_t srcSlotId;
|
||||
int32_t dstSlotId;
|
||||
bool needOutput;
|
||||
SDataType dataType;
|
||||
} SColMatchItem;
|
||||
|
||||
typedef struct SColMatchInfo {
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue