Merge branch '3.0' into fix/liao_cov
This commit is contained in:
commit
9f5a0f01ea
|
@ -175,6 +175,7 @@ def pre_test_build_mac() {
|
||||||
cd ${WK}/debug
|
cd ${WK}/debug
|
||||||
cmake .. -DBUILD_TEST=true -DBUILD_HTTPS=false
|
cmake .. -DBUILD_TEST=true -DBUILD_HTTPS=false
|
||||||
make -j10
|
make -j10
|
||||||
|
ctest -j10 || exit 7
|
||||||
'''
|
'''
|
||||||
sh '''
|
sh '''
|
||||||
date
|
date
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
IF (DEFINED VERNUMBER)
|
IF (DEFINED VERNUMBER)
|
||||||
SET(TD_VER_NUMBER ${VERNUMBER})
|
SET(TD_VER_NUMBER ${VERNUMBER})
|
||||||
ELSE ()
|
ELSE ()
|
||||||
SET(TD_VER_NUMBER "3.0.1.5")
|
SET(TD_VER_NUMBER "3.0.1.6")
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
IF (DEFINED VERCOMPATIBLE)
|
IF (DEFINED VERCOMPATIBLE)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# taos-tools
|
# taos-tools
|
||||||
ExternalProject_Add(taos-tools
|
ExternalProject_Add(taos-tools
|
||||||
GIT_REPOSITORY https://github.com/taosdata/taos-tools.git
|
GIT_REPOSITORY https://github.com/taosdata/taos-tools.git
|
||||||
GIT_TAG 719fc88
|
GIT_TAG 16eb34f
|
||||||
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taos-tools"
|
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taos-tools"
|
||||||
BINARY_DIR ""
|
BINARY_DIR ""
|
||||||
#BUILD_IN_SOURCE TRUE
|
#BUILD_IN_SOURCE TRUE
|
||||||
|
|
|
@ -7,12 +7,12 @@ title: Table
|
||||||
You create standard tables and subtables with the `CREATE TABLE` statement.
|
You create standard tables and subtables with the `CREATE TABLE` statement.
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
CREATE TABLE [IF NOT EXISTS] [db_name.]tb_name (create_definition [, create_definitionn] ...) [table_options]
|
CREATE TABLE [IF NOT EXISTS] [db_name.]tb_name (create_definition [, create_definition] ...) [table_options]
|
||||||
|
|
||||||
CREATE TABLE create_subtable_clause
|
CREATE TABLE create_subtable_clause
|
||||||
|
|
||||||
CREATE TABLE [IF NOT EXISTS] [db_name.]tb_name (create_definition [, create_definitionn] ...)
|
CREATE TABLE [IF NOT EXISTS] [db_name.]tb_name (create_definition [, create_definition] ...)
|
||||||
[TAGS (create_definition [, create_definitionn] ...)]
|
[TAGS (create_definition [, create_definition] ...)]
|
||||||
[table_options]
|
[table_options]
|
||||||
|
|
||||||
create_subtable_clause: {
|
create_subtable_clause: {
|
||||||
|
|
|
@ -6,7 +6,7 @@ title: Supertable
|
||||||
## Create a Supertable
|
## Create a Supertable
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
CREATE STABLE [IF NOT EXISTS] stb_name (create_definition [, create_definitionn] ...) TAGS (create_definition [, create_definition] ...) [table_options]
|
CREATE STABLE [IF NOT EXISTS] stb_name (create_definition [, create_definition] ...) TAGS (create_definition [, create_definition] ...) [table_options]
|
||||||
|
|
||||||
create_definition:
|
create_definition:
|
||||||
col_name column_definition
|
col_name column_definition
|
||||||
|
|
|
@ -374,7 +374,11 @@ The configuration parameters for specifying super table tag columns and data col
|
||||||
|
|
||||||
### Query scenario configuration parameters
|
### Query scenario configuration parameters
|
||||||
|
|
||||||
`filetype` must be set to `query` in the query scenario. See [General Configuration Parameters](#General Configuration Parameters) for details of this parameter and other general parameters
|
`filetype` must be set to `query` in the query scenario.
|
||||||
|
|
||||||
|
To control the query scenario by setting `kill_slow_query_threshold` and `kill_slow_query_interval` parameters to kill the execution of slow query statements. Threshold controls exec_usec of query command will be killed by taosBenchmark after the specified time, in seconds; interval controls sleep time to avoid continuous querying of slow queries consuming CPU in seconds.
|
||||||
|
|
||||||
|
See [General Configuration Parameters](#General Configuration Parameters) for details of other general parameters.
|
||||||
|
|
||||||
#### Configuration parameters for executing the specified query statement
|
#### Configuration parameters for executing the specified query statement
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,12 @@ description: 对表的各种管理操作
|
||||||
`CREATE TABLE` 语句用于创建普通表和以超级表为模板创建子表。
|
`CREATE TABLE` 语句用于创建普通表和以超级表为模板创建子表。
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
CREATE TABLE [IF NOT EXISTS] [db_name.]tb_name (create_definition [, create_definitionn] ...) [table_options]
|
CREATE TABLE [IF NOT EXISTS] [db_name.]tb_name (create_definition [, create_definition] ...) [table_options]
|
||||||
|
|
||||||
CREATE TABLE create_subtable_clause
|
CREATE TABLE create_subtable_clause
|
||||||
|
|
||||||
CREATE TABLE [IF NOT EXISTS] [db_name.]tb_name (create_definition [, create_definitionn] ...)
|
CREATE TABLE [IF NOT EXISTS] [db_name.]tb_name (create_definition [, create_definition] ...)
|
||||||
[TAGS (create_definition [, create_definitionn] ...)]
|
[TAGS (create_definition [, create_definition] ...)]
|
||||||
[table_options]
|
[table_options]
|
||||||
|
|
||||||
create_subtable_clause: {
|
create_subtable_clause: {
|
||||||
|
|
|
@ -7,7 +7,7 @@ description: 对超级表的各种管理操作
|
||||||
## 创建超级表
|
## 创建超级表
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
CREATE STABLE [IF NOT EXISTS] stb_name (create_definition [, create_definitionn] ...) TAGS (create_definition [, create_definition] ...) [table_options]
|
CREATE STABLE [IF NOT EXISTS] stb_name (create_definition [, create_definition] ...) TAGS (create_definition [, create_definition] ...) [table_options]
|
||||||
|
|
||||||
create_definition:
|
create_definition:
|
||||||
col_name column_definition
|
col_name column_definition
|
||||||
|
|
|
@ -224,7 +224,7 @@ GROUP BY 子句中的表达式可以包含表或视图中的任何列,这些
|
||||||
该子句对行进行分组,但不保证结果集的顺序。若要对分组进行排序,请使用 ORDER BY 子句
|
该子句对行进行分组,但不保证结果集的顺序。若要对分组进行排序,请使用 ORDER BY 子句
|
||||||
|
|
||||||
|
|
||||||
## PARTITON BY
|
## PARTITION BY
|
||||||
|
|
||||||
PARTITION BY 子句是 TDengine 特色语法,按 part_list 对数据进行切分,在每个切分的分片中进行计算。
|
PARTITION BY 子句是 TDengine 特色语法,按 part_list 对数据进行切分,在每个切分的分片中进行计算。
|
||||||
|
|
||||||
|
|
|
@ -211,10 +211,10 @@ SHOW USERS;
|
||||||
|
|
||||||
显示当前系统中所有用户的信息。包括用户自定义的用户和系统默认用户。
|
显示当前系统中所有用户的信息。包括用户自定义的用户和系统默认用户。
|
||||||
|
|
||||||
## SHOW VARIABLES
|
## SHOW CLUSTER VARIABLES(3.0.1.6 之前为 SHOW VARIABLES)
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
SHOW VARIABLES;
|
SHOW CLUSTER VARIABLES;
|
||||||
SHOW DNODE dnode_id VARIABLES;
|
SHOW DNODE dnode_id VARIABLES;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -374,7 +374,11 @@ taosBenchmark -A INT,DOUBLE,NCHAR,BINARY\(16\)
|
||||||
|
|
||||||
### 查询场景配置参数
|
### 查询场景配置参数
|
||||||
|
|
||||||
查询场景下 `filetype` 必须设置为 `query`,该参数及其它通用参数详见[通用配置参数](#通用配置参数)
|
查询场景下 `filetype` 必须设置为 `query`。
|
||||||
|
|
||||||
|
查询场景可以通过设置 `kill_slow_query_threshold` 和 `kill_slow_query_interval` 参数来控制杀掉慢查询语句的执行,threshold 控制如果 exec_usec 超过指定时间的查询将被 taosBenchmark 杀掉,单位为秒;interval 控制休眠时间,避免持续查询慢查询消耗 CPU ,单位为秒。
|
||||||
|
|
||||||
|
其它通用参数详见[通用配置参数](#通用配置参数)。
|
||||||
|
|
||||||
#### 执行指定查询语句的配置参数
|
#### 执行指定查询语句的配置参数
|
||||||
|
|
||||||
|
|
|
@ -126,6 +126,9 @@ extern char tsSmlChildTableName[];
|
||||||
extern char tsSmlTagName[];
|
extern char tsSmlTagName[];
|
||||||
extern bool tsSmlDataFormat;
|
extern bool tsSmlDataFormat;
|
||||||
|
|
||||||
|
// wal
|
||||||
|
extern int64_t tsWalFsyncDataSizeLimit;
|
||||||
|
|
||||||
// internal
|
// internal
|
||||||
extern int32_t tsTransPullupInterval;
|
extern int32_t tsTransPullupInterval;
|
||||||
extern int32_t tsMqRebalanceInterval;
|
extern int32_t tsMqRebalanceInterval;
|
||||||
|
|
|
@ -57,9 +57,11 @@ extern int32_t tMsgDict[];
|
||||||
#define TMSG_SEG_SEQ(TYPE) ((TYPE)&0xff)
|
#define TMSG_SEG_SEQ(TYPE) ((TYPE)&0xff)
|
||||||
#define TMSG_INFO(TYPE) \
|
#define TMSG_INFO(TYPE) \
|
||||||
((TYPE) < TDMT_DND_MAX_MSG || (TYPE) < TDMT_MND_MAX_MSG || (TYPE) < TDMT_VND_MAX_MSG || (TYPE) < TDMT_SCH_MAX_MSG || \
|
((TYPE) < TDMT_DND_MAX_MSG || (TYPE) < TDMT_MND_MAX_MSG || (TYPE) < TDMT_VND_MAX_MSG || (TYPE) < TDMT_SCH_MAX_MSG || \
|
||||||
(TYPE) < TDMT_STREAM_MAX_MSG || (TYPE) < TDMT_MON_MAX_MSG || (TYPE) < TDMT_SYNC_MAX_MSG) \
|
(TYPE) < TDMT_STREAM_MAX_MSG || (TYPE) < TDMT_MON_MAX_MSG || (TYPE) < TDMT_SYNC_MAX_MSG) || \
|
||||||
|
(TYPE) < TDMT_VND_STREAM_MSG || (TYPE) < TDMT_VND_TMQ_MSG \
|
||||||
? tMsgInfo[tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE)] \
|
? tMsgInfo[tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE)] \
|
||||||
: 0
|
: 0
|
||||||
|
|
||||||
#define TMSG_INDEX(TYPE) (tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE))
|
#define TMSG_INDEX(TYPE) (tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE))
|
||||||
|
|
||||||
typedef uint16_t tmsg_t;
|
typedef uint16_t tmsg_t;
|
||||||
|
|
|
@ -138,18 +138,18 @@ enum {
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_GET_TABLE_INDEX, "get-table-index", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_GET_TABLE_INDEX, "get-table-index", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_BATCH_META, "batch-meta", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_BATCH_META, "batch-meta", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_TABLE_CFG, "table-cfg", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_TABLE_CFG, "table-cfg", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_TOPIC, "create-topic", SMCreateTopicReq, SMCreateTopicRsp)
|
TD_DEF_MSG_TYPE(TDMT_MND_TMQ_CREATE_TOPIC, "create-topic", SMCreateTopicReq, SMCreateTopicRsp)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_TOPIC, "alter-topic", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_UNUSED1, "unused", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_TOPIC, "drop-topic", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_TMQ_DROP_TOPIC, "drop-topic", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_SUBSCRIBE, "subscribe", SCMSubscribeReq, SCMSubscribeRsp)
|
TD_DEF_MSG_TYPE(TDMT_MND_TMQ_SUBSCRIBE, "subscribe", SCMSubscribeReq, SCMSubscribeRsp)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_ASK_EP, "ask-ep", SMqAskEpReq, SMqAskEpRsp)
|
TD_DEF_MSG_TYPE(TDMT_MND_TMQ_ASK_EP, "ask-ep", SMqAskEpReq, SMqAskEpRsp)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_CONSUMER_LOST, "consumer-lost", SMqConsumerLostMsg, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_TMQ_CONSUMER_LOST, "consumer-lost", SMqConsumerLostMsg, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_CONSUMER_RECOVER, "consumer-recover", SMqConsumerRecoverMsg, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_TMQ_CONSUMER_RECOVER, "consumer-recover", SMqConsumerRecoverMsg, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_HB, "consumer-hb", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_TMQ_HB, "consumer-hb", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_DO_REBALANCE, "do-rebalance", SMqDoRebalanceMsg, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_TMQ_DO_REBALANCE, "do-rebalance", SMqDoRebalanceMsg, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_DROP_CGROUP, "drop-cgroup", SMqDropCGroupReq, SMqDropCGroupRsp)
|
TD_DEF_MSG_TYPE(TDMT_MND_TMQ_DROP_CGROUP, "drop-cgroup", SMqDropCGroupReq, SMqDropCGroupRsp)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_COMMIT_OFFSET, "mnode-commit-offset", SMqCMCommitOffsetReq, SMqCMCommitOffsetRsp)
|
TD_DEF_MSG_TYPE(TDMT_MND_UNUSED2, "unused2", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_TIMER, "mq-tmr", SMTimerReq, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_TMQ_TIMER, "mq-tmr", SMTimerReq, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_TELEM_TIMER, "telem-tmr", SMTimerReq, SMTimerReq)
|
TD_DEF_MSG_TYPE(TDMT_MND_TELEM_TIMER, "telem-tmr", SMTimerReq, SMTimerReq)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_TRANS_TIMER, "trans-tmr", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_TRANS_TIMER, "trans-tmr", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_TTL_TIMER, "ttl-tmr", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_TTL_TIMER, "ttl-tmr", NULL, NULL)
|
||||||
|
@ -186,21 +186,21 @@ enum {
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_CREATE_STB, "vnode-create-stb", SVCreateStbReq, NULL)
|
TD_DEF_MSG_TYPE(TDMT_VND_CREATE_STB, "vnode-create-stb", SVCreateStbReq, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_ALTER_STB, "vnode-alter-stb", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_VND_ALTER_STB, "vnode-alter-stb", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_DROP_STB, "vnode-drop-stb", SVDropStbReq, NULL)
|
TD_DEF_MSG_TYPE(TDMT_VND_DROP_STB, "vnode-drop-stb", SVDropStbReq, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_MQ_VG_CHANGE, "vnode-mq-vg-change", SMqRebVgReq, SMqRebVgRsp)
|
TD_DEF_MSG_TYPE(TDMT_VND_UNUSED1, "vnode-unused1", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_MQ_VG_DELETE, "vnode-mq-vg-delete", SMqVDeleteReq, SMqVDeleteRsp)
|
TD_DEF_MSG_TYPE(TDMT_VND_UNUSED2, "vnode-unused2", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_MQ_COMMIT_OFFSET, "vnode-commit-offset", STqOffset, STqOffset)
|
TD_DEF_MSG_TYPE(TDMT_VND_UNUSED3, "vnode-unused3", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_ADD_CHECK_INFO, "vnode-add-check-info", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_VND_UNUSED4, "vnode-unused4", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_DELETE_CHECK_INFO, "vnode-delete-check-info", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_VND_UNUSED5, "vnode-unused5", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_CREATE_TOPIC, "vnode-create-topic", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_VND_UNUSED6, "vnode-unused6", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_ALTER_TOPIC, "vnode-alter-topic", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_VND_UNUSED7, "vnode-unused7", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_DROP_TOPIC, "vnode-drop-topic", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_VND_UNUSED8, "vnode-unused8", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_SUBSCRIBE, "vnode-subscribe", SMVSubscribeReq, SMVSubscribeRsp)
|
TD_DEF_MSG_TYPE(TDMT_VND_UNUSED9, "vnode-unused9", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_CONSUME, "vnode-consume", SMqPollReq, SMqDataBlkRsp)
|
TD_DEF_MSG_TYPE(TDMT_VND_UNUSED10, "vnode-unused10", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_STREAM_TRIGGER, "vnode-stream-trigger", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_VND_UNUSED11, "vnode-unused11", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_STREAM_DISPATCH_WRITE, "vnode-stream-task-dispatch-write", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_VND_UNUSED12, "vnode-unused12", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_STREAM_RECOVER_STEP1, "vnode-stream-recover1", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_VND_UNUSED13, "vnode-unused13", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_STREAM_RECOVER_STEP2, "vnode-stream-recover2", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_VND_UNUSED14, "vnode-unused14", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_STREAM_RECOVER_FINISH, "vnode-stream-finish", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_VND_UNUSED15, "vnode-unused15", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_CREATE_SMA, "vnode-create-sma", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_VND_CREATE_SMA, "vnode-create-sma", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_CANCEL_SMA, "vnode-cancel-sma", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_VND_CANCEL_SMA, "vnode-cancel-sma", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_DROP_SMA, "vnode-drop-sma", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_VND_DROP_SMA, "vnode-drop-sma", NULL, NULL)
|
||||||
|
@ -232,13 +232,15 @@ enum {
|
||||||
TD_DEF_MSG_TYPE(TDMT_SCH_LINK_BROKEN, "link-broken", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_SCH_LINK_BROKEN, "link-broken", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_SCH_MAX_MSG, "sch-max", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_SCH_MAX_MSG, "sch-max", NULL, NULL)
|
||||||
|
|
||||||
|
|
||||||
TD_NEW_MSG_SEG(TDMT_STREAM_MSG)
|
TD_NEW_MSG_SEG(TDMT_STREAM_MSG)
|
||||||
TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_DEPLOY, "stream-task-deploy", SStreamTaskDeployReq, SStreamTaskDeployRsp)
|
TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_DEPLOY, "stream-task-deploy", SStreamTaskDeployReq, SStreamTaskDeployRsp)
|
||||||
TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_DROP, "stream-task-drop", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_DROP, "stream-task-drop", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_RUN, "stream-task-run", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_RUN, "stream-task-run", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_DISPATCH, "stream-task-dispatch", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_DISPATCH, "stream-task-dispatch", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_RECOVER, "stream-task-recover", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_STREAM_UNUSED1, "stream-unused1", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_STREAM_RETRIEVE, "stream-retrieve", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_STREAM_RETRIEVE, "stream-retrieve", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_STREAM_RECOVER_FINISH, "vnode-stream-finish", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_STREAM_MAX_MSG, "stream-max", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_STREAM_MAX_MSG, "stream-max", NULL, NULL)
|
||||||
|
|
||||||
TD_NEW_MSG_SEG(TDMT_MON_MSG)
|
TD_NEW_MSG_SEG(TDMT_MON_MSG)
|
||||||
|
@ -270,8 +272,26 @@ enum {
|
||||||
TD_DEF_MSG_TYPE(TDMT_SYNC_HEARTBEAT, "sync-heartbeat", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_SYNC_HEARTBEAT, "sync-heartbeat", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_SYNC_HEARTBEAT_REPLY, "sync-heartbeat-reply", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_SYNC_HEARTBEAT_REPLY, "sync-heartbeat-reply", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_SYNC_LOCAL_CMD, "sync-local-cmd", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_SYNC_LOCAL_CMD, "sync-local-cmd", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_SYNC_PRE_SNAPSHOT, "sync-pre-snapshot", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_SYNC_PRE_SNAPSHOT_REPLY, "sync-pre-snapshot-reply", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_SYNC_MAX_MSG, "sync-max", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_SYNC_MAX_MSG, "sync-max", NULL, NULL)
|
||||||
|
|
||||||
|
TD_NEW_MSG_SEG(TDMT_VND_STREAM_MSG)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_VND_STREAM_TRIGGER, "vnode-stream-trigger", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_VND_STREAM_RECOVER_STEP1, "vnode-stream-recover1", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_VND_STREAM_RECOVER_STEP2, "vnode-stream-recover2", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_VND_STREAM_MAX_MSG, "vnd-stream-max", NULL, NULL)
|
||||||
|
|
||||||
|
TD_NEW_MSG_SEG(TDMT_VND_TMQ_MSG)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_VND_TMQ_SUBSCRIBE, "vnode-tmq-subscribe", SMqRebVgReq, SMqRebVgRsp)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_VND_TMQ_DELETE_SUB, "vnode-tmq-delete-sub", SMqVDeleteReq, SMqVDeleteRsp)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_VND_TMQ_COMMIT_OFFSET, "vnode-tmq-commit-offset", STqOffset, STqOffset)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_VND_TMQ_ADD_CHECKINFO, "vnode-tmq-add-checkinfo", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_VND_TMQ_DEL_CHECKINFO, "vnode-del-checkinfo", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_VND_TMQ_CONSUME, "vnode-tmq-consume", SMqPollReq, SMqDataBlkRsp)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_VND_TMQ_MAX_MSG, "vnd-tmq-max", NULL, NULL)
|
||||||
|
|
||||||
|
|
||||||
#if defined(TD_MSG_NUMBER_)
|
#if defined(TD_MSG_NUMBER_)
|
||||||
TDMT_MAX
|
TDMT_MAX
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -72,13 +72,13 @@ bool tNameTbNameEqual(SName* left, SName* right);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
// input
|
// input
|
||||||
SArray* tags; // element is SSmlKv
|
SArray* tags; // element is SSmlKv
|
||||||
const char* sTableName; // super table name
|
const char* stbFullName; // super table name
|
||||||
uint8_t sTableNameLen; // the length of super table name
|
uint8_t stbFullNameLen; // the length of super table name
|
||||||
|
|
||||||
// output
|
// output
|
||||||
char* childTableName; // must have size of TSDB_TABLE_NAME_LEN;
|
char* ctbShortName; // must have size of TSDB_TABLE_NAME_LEN;
|
||||||
uint64_t uid; // child table uid, may be useful
|
uint64_t uid; // child table uid, may be useful
|
||||||
} RandTableName;
|
} RandTableName;
|
||||||
|
|
||||||
void buildChildTableName(RandTableName* rName);
|
void buildChildTableName(RandTableName* rName);
|
||||||
|
|
|
@ -99,7 +99,6 @@ int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad);
|
||||||
*/
|
*/
|
||||||
int32_t mndProcessRpcMsg(SRpcMsg *pMsg);
|
int32_t mndProcessRpcMsg(SRpcMsg *pMsg);
|
||||||
int32_t mndProcessSyncMsg(SRpcMsg *pMsg);
|
int32_t mndProcessSyncMsg(SRpcMsg *pMsg);
|
||||||
int32_t mndProcessSyncCtrlMsg(SRpcMsg *pMsg);
|
|
||||||
int32_t mndPreProcessQueryMsg(SRpcMsg *pMsg);
|
int32_t mndPreProcessQueryMsg(SRpcMsg *pMsg);
|
||||||
void mndPostProcessQueryMsg(SRpcMsg *pMsg);
|
void mndPostProcessQueryMsg(SRpcMsg *pMsg);
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,7 @@ qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, SReadHandle* readers);
|
||||||
*/
|
*/
|
||||||
qTaskInfo_t qCreateQueueExecTaskInfo(void* msg, SReadHandle* readers, int32_t* numOfCols, SSchemaWrapper** pSchema);
|
qTaskInfo_t qCreateQueueExecTaskInfo(void* msg, SReadHandle* readers, int32_t* numOfCols, SSchemaWrapper** pSchema);
|
||||||
|
|
||||||
|
int32_t qSetStreamOpOpen(qTaskInfo_t tinfo);
|
||||||
/**
|
/**
|
||||||
* Set multiple input data blocks for the stream scan.
|
* Set multiple input data blocks for the stream scan.
|
||||||
* @param tinfo
|
* @param tinfo
|
||||||
|
|
|
@ -216,6 +216,7 @@ bool fmIsMultiRowsFunc(int32_t funcId);
|
||||||
bool fmIsKeepOrderFunc(int32_t funcId);
|
bool fmIsKeepOrderFunc(int32_t funcId);
|
||||||
bool fmIsCumulativeFunc(int32_t funcId);
|
bool fmIsCumulativeFunc(int32_t funcId);
|
||||||
bool fmIsInterpPseudoColumnFunc(int32_t funcId);
|
bool fmIsInterpPseudoColumnFunc(int32_t funcId);
|
||||||
|
bool fmIsGroupKeyFunc(int32_t funcId);
|
||||||
|
|
||||||
void getLastCacheDataType(SDataType* pType);
|
void getLastCacheDataType(SDataType* pType);
|
||||||
|
|
||||||
|
|
|
@ -242,7 +242,7 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t
|
||||||
#define SET_META_TYPE_BOTH_TABLE(t) (t) = META_TYPE_BOTH_TABLE
|
#define SET_META_TYPE_BOTH_TABLE(t) (t) = META_TYPE_BOTH_TABLE
|
||||||
|
|
||||||
#define NEED_CLIENT_RM_TBLMETA_ERROR(_code) \
|
#define NEED_CLIENT_RM_TBLMETA_ERROR(_code) \
|
||||||
((_code) == TSDB_CODE_PAR_TABLE_NOT_EXIST || (_code) == TSDB_CODE_VND_TB_NOT_EXIST || \
|
((_code) == TSDB_CODE_PAR_TABLE_NOT_EXIST || (_code) == TSDB_CODE_TDB_TABLE_NOT_EXIST || \
|
||||||
(_code) == TSDB_CODE_PAR_INVALID_COLUMNS_NUM || (_code) == TSDB_CODE_PAR_INVALID_COLUMN || \
|
(_code) == TSDB_CODE_PAR_INVALID_COLUMNS_NUM || (_code) == TSDB_CODE_PAR_INVALID_COLUMN || \
|
||||||
(_code) == TSDB_CODE_PAR_TAGS_NOT_MATCHED || (_code) == TSDB_CODE_PAR_VALUE_TOO_LONG || \
|
(_code) == TSDB_CODE_PAR_TAGS_NOT_MATCHED || (_code) == TSDB_CODE_PAR_VALUE_TOO_LONG || \
|
||||||
(_code) == TSDB_CODE_PAR_INVALID_DROP_COL || ((_code) == TSDB_CODE_TDB_INVALID_TABLE_ID))
|
(_code) == TSDB_CODE_PAR_INVALID_DROP_COL || ((_code) == TSDB_CODE_TDB_INVALID_TABLE_ID))
|
||||||
|
|
|
@ -441,8 +441,9 @@ typedef struct {
|
||||||
} SStreamRetrieveRsp;
|
} SStreamRetrieveRsp;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int64_t streamId;
|
SMsgHead msgHead;
|
||||||
int32_t taskId;
|
int64_t streamId;
|
||||||
|
int32_t taskId;
|
||||||
} SStreamRecoverStep1Req, SStreamRecoverStep2Req;
|
} SStreamRecoverStep1Req, SStreamRecoverStep2Req;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
@ -25,8 +25,6 @@ extern "C" {
|
||||||
#include "tlrucache.h"
|
#include "tlrucache.h"
|
||||||
#include "tmsgcb.h"
|
#include "tmsgcb.h"
|
||||||
|
|
||||||
extern bool gRaftDetailLog;
|
|
||||||
|
|
||||||
#define SYNC_RESP_TTL_MS 10000000
|
#define SYNC_RESP_TTL_MS 10000000
|
||||||
#define SYNC_SPEED_UP_HB_TIMER 400
|
#define SYNC_SPEED_UP_HB_TIMER 400
|
||||||
#define SYNC_SPEED_UP_AFTER_MS (1000 * 20)
|
#define SYNC_SPEED_UP_AFTER_MS (1000 * 20)
|
||||||
|
@ -39,6 +37,7 @@ extern bool gRaftDetailLog;
|
||||||
#define SYNC_ADD_QUORUM_COUNT 3
|
#define SYNC_ADD_QUORUM_COUNT 3
|
||||||
#define SYNC_MNODE_LOG_RETENTION 10000
|
#define SYNC_MNODE_LOG_RETENTION 10000
|
||||||
#define SYNC_VNODE_LOG_RETENTION 100
|
#define SYNC_VNODE_LOG_RETENTION 100
|
||||||
|
#define SNAPSHOT_MAX_CLOCK_SKEW_MS 1000 * 10
|
||||||
|
|
||||||
#define SYNC_APPEND_ENTRIES_TIMEOUT_MS 10000
|
#define SYNC_APPEND_ENTRIES_TIMEOUT_MS 10000
|
||||||
|
|
||||||
|
@ -132,27 +131,27 @@ typedef struct SSnapshotMeta {
|
||||||
typedef struct SSyncFSM {
|
typedef struct SSyncFSM {
|
||||||
void* data;
|
void* data;
|
||||||
|
|
||||||
void (*FpCommitCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta);
|
void (*FpCommitCb)(const struct SSyncFSM* pFsm, const SRpcMsg* pMsg, const SFsmCbMeta* pMeta);
|
||||||
void (*FpPreCommitCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta);
|
void (*FpPreCommitCb)(const struct SSyncFSM* pFsm, const SRpcMsg* pMsg, const SFsmCbMeta* pMeta);
|
||||||
void (*FpRollBackCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta);
|
void (*FpRollBackCb)(const struct SSyncFSM* pFsm, const SRpcMsg* pMsg, const SFsmCbMeta* pMeta);
|
||||||
|
|
||||||
void (*FpRestoreFinishCb)(struct SSyncFSM* pFsm);
|
void (*FpRestoreFinishCb)(const struct SSyncFSM* pFsm);
|
||||||
void (*FpReConfigCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta* cbMeta);
|
void (*FpReConfigCb)(const struct SSyncFSM* pFsm, const SRpcMsg* pMsg, const SReConfigCbMeta* pMeta);
|
||||||
void (*FpLeaderTransferCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta);
|
void (*FpLeaderTransferCb)(const struct SSyncFSM* pFsm, const SRpcMsg* pMsg, const SFsmCbMeta* pMeta);
|
||||||
|
|
||||||
void (*FpBecomeLeaderCb)(struct SSyncFSM* pFsm);
|
void (*FpBecomeLeaderCb)(const struct SSyncFSM* pFsm);
|
||||||
void (*FpBecomeFollowerCb)(struct SSyncFSM* pFsm);
|
void (*FpBecomeFollowerCb)(const struct SSyncFSM* pFsm);
|
||||||
|
|
||||||
int32_t (*FpGetSnapshot)(struct SSyncFSM* pFsm, SSnapshot* pSnapshot, void* pReaderParam, void** ppReader);
|
int32_t (*FpGetSnapshot)(const struct SSyncFSM* pFsm, SSnapshot* pSnapshot, void* pReaderParam, void** ppReader);
|
||||||
int32_t (*FpGetSnapshotInfo)(struct SSyncFSM* pFsm, SSnapshot* pSnapshot);
|
int32_t (*FpGetSnapshotInfo)(const struct SSyncFSM* pFsm, SSnapshot* pSnapshot);
|
||||||
|
|
||||||
int32_t (*FpSnapshotStartRead)(struct SSyncFSM* pFsm, void* pReaderParam, void** ppReader);
|
int32_t (*FpSnapshotStartRead)(const struct SSyncFSM* pFsm, void* pReaderParam, void** ppReader);
|
||||||
int32_t (*FpSnapshotStopRead)(struct SSyncFSM* pFsm, void* pReader);
|
int32_t (*FpSnapshotStopRead)(const struct SSyncFSM* pFsm, void* pReader);
|
||||||
int32_t (*FpSnapshotDoRead)(struct SSyncFSM* pFsm, void* pReader, void** ppBuf, int32_t* len);
|
int32_t (*FpSnapshotDoRead)(const struct SSyncFSM* pFsm, void* pReader, void** ppBuf, int32_t* len);
|
||||||
|
|
||||||
int32_t (*FpSnapshotStartWrite)(struct SSyncFSM* pFsm, void* pWriterParam, void** ppWriter);
|
int32_t (*FpSnapshotStartWrite)(const struct SSyncFSM* pFsm, void* pWriterParam, void** ppWriter);
|
||||||
int32_t (*FpSnapshotStopWrite)(struct SSyncFSM* pFsm, void* pWriter, bool isApply, SSnapshot* pSnapshot);
|
int32_t (*FpSnapshotStopWrite)(const struct SSyncFSM* pFsm, void* pWriter, bool isApply, SSnapshot* pSnapshot);
|
||||||
int32_t (*FpSnapshotDoWrite)(struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_t len);
|
int32_t (*FpSnapshotDoWrite)(const struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_t len);
|
||||||
|
|
||||||
} SSyncFSM;
|
} SSyncFSM;
|
||||||
|
|
||||||
|
@ -193,48 +192,36 @@ typedef struct SSyncInfo {
|
||||||
SWal* pWal;
|
SWal* pWal;
|
||||||
SSyncFSM* pFsm;
|
SSyncFSM* pFsm;
|
||||||
SMsgCb* msgcb;
|
SMsgCb* msgcb;
|
||||||
int32_t (*FpSendMsg)(const SEpSet* pEpSet, SRpcMsg* pMsg);
|
int32_t pingMs;
|
||||||
int32_t (*FpEqMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg);
|
int32_t electMs;
|
||||||
int32_t (*FpEqCtrlMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg);
|
int32_t heartbeatMs;
|
||||||
|
|
||||||
|
int32_t (*syncSendMSg)(const SEpSet* pEpSet, SRpcMsg* pMsg);
|
||||||
|
int32_t (*syncEqMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg);
|
||||||
|
int32_t (*syncEqCtrlMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg);
|
||||||
} SSyncInfo;
|
} SSyncInfo;
|
||||||
|
|
||||||
int32_t syncInit();
|
typedef struct SSyncState {
|
||||||
void syncCleanUp();
|
ESyncState state;
|
||||||
bool syncIsInit();
|
bool restored;
|
||||||
int64_t syncOpen(SSyncInfo* pSyncInfo);
|
} SSyncState;
|
||||||
void syncStart(int64_t rid);
|
|
||||||
void syncStop(int64_t rid);
|
|
||||||
ESyncState syncGetMyRole(int64_t rid);
|
|
||||||
bool syncIsReady(int64_t rid);
|
|
||||||
const char* syncGetMyRoleStr(int64_t rid);
|
|
||||||
bool syncRestoreFinish(int64_t rid);
|
|
||||||
SyncTerm syncGetMyTerm(int64_t rid);
|
|
||||||
SyncIndex syncGetLastIndex(int64_t rid);
|
|
||||||
SyncIndex syncGetCommitIndex(int64_t rid);
|
|
||||||
SyncGroupId syncGetVgId(int64_t rid);
|
|
||||||
void syncGetEpSet(int64_t rid, SEpSet* pEpSet);
|
|
||||||
void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet);
|
|
||||||
int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak);
|
|
||||||
// int32_t syncProposeBatch(int64_t rid, SRpcMsg** pMsgPArr, bool* pIsWeakArr, int32_t arrSize);
|
|
||||||
const char* syncStr(ESyncState state);
|
|
||||||
bool syncIsRestoreFinish(int64_t rid);
|
|
||||||
int32_t syncGetSnapshotByIndex(int64_t rid, SyncIndex index, SSnapshot* pSnapshot);
|
|
||||||
|
|
||||||
int32_t syncReconfig(int64_t rid, SSyncCfg* pNewCfg);
|
|
||||||
|
|
||||||
// build SRpcMsg, need to call syncPropose with SRpcMsg
|
|
||||||
int32_t syncReconfigBuild(int64_t rid, const SSyncCfg* pNewCfg, SRpcMsg* pRpcMsg);
|
|
||||||
|
|
||||||
int32_t syncLeaderTransfer(int64_t rid);
|
|
||||||
int32_t syncLeaderTransferTo(int64_t rid, SNodeInfo newLeader);
|
|
||||||
|
|
||||||
|
int32_t syncInit();
|
||||||
|
void syncCleanUp();
|
||||||
|
int64_t syncOpen(SSyncInfo* pSyncInfo);
|
||||||
|
void syncStart(int64_t rid);
|
||||||
|
void syncStop(int64_t rid);
|
||||||
|
int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak);
|
||||||
|
int32_t syncProcessMsg(int64_t rid, SRpcMsg* pMsg);
|
||||||
|
int32_t syncReconfig(int64_t rid, SSyncCfg* pCfg);
|
||||||
int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex);
|
int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex);
|
||||||
int32_t syncEndSnapshot(int64_t rid);
|
int32_t syncEndSnapshot(int64_t rid);
|
||||||
|
int32_t syncLeaderTransfer(int64_t rid);
|
||||||
int32_t syncStepDown(int64_t rid, SyncTerm newTerm);
|
int32_t syncStepDown(int64_t rid, SyncTerm newTerm);
|
||||||
|
|
||||||
SSyncNode* syncNodeAcquire(int64_t rid);
|
SSyncState syncGetState(int64_t rid);
|
||||||
void syncNodeRelease(SSyncNode* pNode);
|
void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet);
|
||||||
|
const char* syncStr(ESyncState state);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,6 @@ extern "C" {
|
||||||
#define WAL_FILE_LEN (WAL_PATH_LEN + 32)
|
#define WAL_FILE_LEN (WAL_PATH_LEN + 32)
|
||||||
#define WAL_MAGIC 0xFAFBFCFDF4F3F2F1ULL
|
#define WAL_MAGIC 0xFAFBFCFDF4F3F2F1ULL
|
||||||
#define WAL_SCAN_BUF_SIZE (1024 * 1024 * 3)
|
#define WAL_SCAN_BUF_SIZE (1024 * 1024 * 3)
|
||||||
#define WAL_RECOV_SIZE_LIMIT (100 * WAL_SCAN_BUF_SIZE)
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TAOS_WAL_WRITE = 1,
|
TAOS_WAL_WRITE = 1,
|
||||||
|
@ -159,6 +158,7 @@ void walCleanUp();
|
||||||
// handle open and ctl
|
// handle open and ctl
|
||||||
SWal *walOpen(const char *path, SWalCfg *pCfg);
|
SWal *walOpen(const char *path, SWalCfg *pCfg);
|
||||||
int32_t walAlter(SWal *, SWalCfg *pCfg);
|
int32_t walAlter(SWal *, SWalCfg *pCfg);
|
||||||
|
int32_t walPersist(SWal *);
|
||||||
void walClose(SWal *);
|
void walClose(SWal *);
|
||||||
|
|
||||||
// write interfaces
|
// write interfaces
|
||||||
|
|
|
@ -244,6 +244,16 @@ void syslog(int unused, const char *format, ...);
|
||||||
#define TD_CHARSET_LEN 64
|
#define TD_CHARSET_LEN 64
|
||||||
#define TD_TIMEZONE_LEN 96
|
#define TD_TIMEZONE_LEN 96
|
||||||
|
|
||||||
|
#ifdef WINDOWS
|
||||||
|
#define TD_PATH_MAX 260
|
||||||
|
#elif defined(PATH_MAX)
|
||||||
|
#define TD_PATH_MAX PATH_MAX
|
||||||
|
#elif defined(_XOPEN_PATH_MAX)
|
||||||
|
#define TD_PATH_MAX _XOPEN_PATH_MAX
|
||||||
|
#else
|
||||||
|
#define TD_PATH_MAX _POSIX_PATH_MAX
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -91,6 +91,7 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_MSG_DECODE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0128)
|
#define TSDB_CODE_MSG_DECODE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0128)
|
||||||
#define TSDB_CODE_NO_AVAIL_DISK TAOS_DEF_ERROR_CODE(0, 0x0129)
|
#define TSDB_CODE_NO_AVAIL_DISK TAOS_DEF_ERROR_CODE(0, 0x0129)
|
||||||
#define TSDB_CODE_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x012A)
|
#define TSDB_CODE_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x012A)
|
||||||
|
#define TSDB_CODE_NO_DISKSPACE TAOS_DEF_ERROR_CODE(0, 0x012B)
|
||||||
|
|
||||||
//client
|
//client
|
||||||
#define TSDB_CODE_TSC_INVALID_OPERATION TAOS_DEF_ERROR_CODE(0, 0x0200)
|
#define TSDB_CODE_TSC_INVALID_OPERATION TAOS_DEF_ERROR_CODE(0, 0x0200)
|
||||||
|
@ -106,7 +107,6 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH TAOS_DEF_ERROR_CODE(0, 0x020A)
|
#define TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH TAOS_DEF_ERROR_CODE(0, 0x020A)
|
||||||
#define TSDB_CODE_TSC_INVALID_CONNECTION TAOS_DEF_ERROR_CODE(0, 0x020B)
|
#define TSDB_CODE_TSC_INVALID_CONNECTION TAOS_DEF_ERROR_CODE(0, 0x020B)
|
||||||
#define TSDB_CODE_TSC_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x020C)
|
#define TSDB_CODE_TSC_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x020C)
|
||||||
#define TSDB_CODE_TSC_NO_DISKSPACE TAOS_DEF_ERROR_CODE(0, 0x020D)
|
|
||||||
#define TSDB_CODE_TSC_QUERY_CACHE_ERASED TAOS_DEF_ERROR_CODE(0, 0x020E)
|
#define TSDB_CODE_TSC_QUERY_CACHE_ERASED TAOS_DEF_ERROR_CODE(0, 0x020E)
|
||||||
#define TSDB_CODE_TSC_QUERY_CANCELLED TAOS_DEF_ERROR_CODE(0, 0x020F)
|
#define TSDB_CODE_TSC_QUERY_CANCELLED TAOS_DEF_ERROR_CODE(0, 0x020F)
|
||||||
#define TSDB_CODE_TSC_SORTED_RES_TOO_MANY TAOS_DEF_ERROR_CODE(0, 0x0210)
|
#define TSDB_CODE_TSC_SORTED_RES_TOO_MANY TAOS_DEF_ERROR_CODE(0, 0x0210)
|
||||||
|
@ -305,34 +305,14 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_NODE_NOT_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x040A)
|
#define TSDB_CODE_NODE_NOT_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x040A)
|
||||||
|
|
||||||
// vnode
|
// vnode
|
||||||
#define TSDB_CODE_VND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0500)
|
|
||||||
#define TSDB_CODE_VND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0501)
|
|
||||||
#define TSDB_CODE_VND_ACTION_NEED_REPROCESSED TAOS_DEF_ERROR_CODE(0, 0x0502)
|
|
||||||
#define TSDB_CODE_VND_INVALID_VGROUP_ID TAOS_DEF_ERROR_CODE(0, 0x0503)
|
#define TSDB_CODE_VND_INVALID_VGROUP_ID TAOS_DEF_ERROR_CODE(0, 0x0503)
|
||||||
#define TSDB_CODE_VND_INIT_FAILED TAOS_DEF_ERROR_CODE(0, 0x0504)
|
|
||||||
#define TSDB_CODE_VND_NO_DISKSPACE TAOS_DEF_ERROR_CODE(0, 0x0505)
|
|
||||||
#define TSDB_CODE_VND_NO_DISK_PERMISSIONS TAOS_DEF_ERROR_CODE(0, 0x0506)
|
|
||||||
#define TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR TAOS_DEF_ERROR_CODE(0, 0x0507)
|
|
||||||
#define TSDB_CODE_VND_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0508)
|
|
||||||
#define TSDB_CODE_VND_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x0509)
|
|
||||||
#define TSDB_CODE_VND_IS_FLOWCTRL TAOS_DEF_ERROR_CODE(0, 0x050C)
|
|
||||||
#define TSDB_CODE_VND_IS_DROPPING TAOS_DEF_ERROR_CODE(0, 0x050D)
|
|
||||||
#define TSDB_CODE_VND_IS_UPDATING TAOS_DEF_ERROR_CODE(0, 0x050E)
|
|
||||||
#define TSDB_CODE_VND_IS_CLOSING TAOS_DEF_ERROR_CODE(0, 0x0510)
|
|
||||||
#define TSDB_CODE_VND_NOT_SYNCED TAOS_DEF_ERROR_CODE(0, 0x0511)
|
|
||||||
#define TSDB_CODE_VND_NO_WRITE_AUTH TAOS_DEF_ERROR_CODE(0, 0x0512)
|
#define TSDB_CODE_VND_NO_WRITE_AUTH TAOS_DEF_ERROR_CODE(0, 0x0512)
|
||||||
#define TSDB_CODE_VND_IS_SYNCING TAOS_DEF_ERROR_CODE(0, 0x0513)
|
|
||||||
#define TSDB_CODE_VND_INVALID_TSDB_STATE TAOS_DEF_ERROR_CODE(0, 0x0514)
|
|
||||||
#define TSDB_CODE_VND_TB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0520)
|
|
||||||
#define TSDB_CODE_VND_SMA_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0521)
|
|
||||||
#define TSDB_CODE_VND_HASH_MISMATCH TAOS_DEF_ERROR_CODE(0, 0x0522)
|
#define TSDB_CODE_VND_HASH_MISMATCH TAOS_DEF_ERROR_CODE(0, 0x0522)
|
||||||
#define TSDB_CODE_VND_TABLE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0523)
|
|
||||||
#define TSDB_CODE_VND_INVALID_TABLE_ACTION TAOS_DEF_ERROR_CODE(0, 0x0524)
|
#define TSDB_CODE_VND_INVALID_TABLE_ACTION TAOS_DEF_ERROR_CODE(0, 0x0524)
|
||||||
#define TSDB_CODE_VND_COL_ALREADY_EXISTS TAOS_DEF_ERROR_CODE(0, 0x0525)
|
#define TSDB_CODE_VND_COL_ALREADY_EXISTS TAOS_DEF_ERROR_CODE(0, 0x0525)
|
||||||
#define TSDB_CODE_VND_TABLE_COL_NOT_EXISTS TAOS_DEF_ERROR_CODE(0, 0x0526)
|
#define TSDB_CODE_VND_COL_NOT_EXISTS TAOS_DEF_ERROR_CODE(0, 0x0526)
|
||||||
#define TSDB_CODE_VND_COL_SUBSCRIBED TAOS_DEF_ERROR_CODE(0, 0x0527)
|
#define TSDB_CODE_VND_COL_SUBSCRIBED TAOS_DEF_ERROR_CODE(0, 0x0527)
|
||||||
#define TSDB_CODE_VND_INVALID_CFG_FILE TAOS_DEF_ERROR_CODE(0, 0x0528)
|
#define TSDB_CODE_VND_NO_AVAIL_BUFPOOL TAOS_DEF_ERROR_CODE(0, 0x0528)
|
||||||
#define TSDB_CODE_VND_INVALID_TERM_FILE TAOS_DEF_ERROR_CODE(0, 0x0529)
|
|
||||||
|
|
||||||
// tsdb
|
// tsdb
|
||||||
#define TSDB_CODE_TDB_INVALID_TABLE_ID TAOS_DEF_ERROR_CODE(0, 0x0600)
|
#define TSDB_CODE_TDB_INVALID_TABLE_ID TAOS_DEF_ERROR_CODE(0, 0x0600)
|
||||||
|
@ -341,7 +321,6 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_TDB_TABLE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0603)
|
#define TSDB_CODE_TDB_TABLE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0603)
|
||||||
#define TSDB_CODE_TDB_INVALID_CONFIG TAOS_DEF_ERROR_CODE(0, 0x0604)
|
#define TSDB_CODE_TDB_INVALID_CONFIG TAOS_DEF_ERROR_CODE(0, 0x0604)
|
||||||
#define TSDB_CODE_TDB_INIT_FAILED TAOS_DEF_ERROR_CODE(0, 0x0605)
|
#define TSDB_CODE_TDB_INIT_FAILED TAOS_DEF_ERROR_CODE(0, 0x0605)
|
||||||
#define TSDB_CODE_TDB_NO_DISKSPACE TAOS_DEF_ERROR_CODE(0, 0x0606)
|
|
||||||
#define TSDB_CODE_TDB_NO_DISK_PERMISSIONS TAOS_DEF_ERROR_CODE(0, 0x0607)
|
#define TSDB_CODE_TDB_NO_DISK_PERMISSIONS TAOS_DEF_ERROR_CODE(0, 0x0607)
|
||||||
#define TSDB_CODE_TDB_FILE_CORRUPTED TAOS_DEF_ERROR_CODE(0, 0x0608)
|
#define TSDB_CODE_TDB_FILE_CORRUPTED TAOS_DEF_ERROR_CODE(0, 0x0608)
|
||||||
#define TSDB_CODE_TDB_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0609)
|
#define TSDB_CODE_TDB_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0609)
|
||||||
|
@ -367,7 +346,6 @@ int32_t* taosGetErrno();
|
||||||
// query
|
// query
|
||||||
#define TSDB_CODE_QRY_INVALID_QHANDLE TAOS_DEF_ERROR_CODE(0, 0x0700)
|
#define TSDB_CODE_QRY_INVALID_QHANDLE TAOS_DEF_ERROR_CODE(0, 0x0700)
|
||||||
#define TSDB_CODE_QRY_INVALID_MSG TAOS_DEF_ERROR_CODE(0, 0x0701)
|
#define TSDB_CODE_QRY_INVALID_MSG TAOS_DEF_ERROR_CODE(0, 0x0701)
|
||||||
#define TSDB_CODE_QRY_NO_DISKSPACE TAOS_DEF_ERROR_CODE(0, 0x0702)
|
|
||||||
#define TSDB_CODE_QRY_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0703)
|
#define TSDB_CODE_QRY_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0703)
|
||||||
#define TSDB_CODE_QRY_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x0704)
|
#define TSDB_CODE_QRY_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x0704)
|
||||||
#define TSDB_CODE_QRY_DUP_JOIN_KEY TAOS_DEF_ERROR_CODE(0, 0x0705)
|
#define TSDB_CODE_QRY_DUP_JOIN_KEY TAOS_DEF_ERROR_CODE(0, 0x0705)
|
||||||
|
@ -430,7 +408,6 @@ int32_t* taosGetErrno();
|
||||||
// tq
|
// tq
|
||||||
#define TSDB_CODE_TQ_INVALID_CONFIG TAOS_DEF_ERROR_CODE(0, 0x0A00)
|
#define TSDB_CODE_TQ_INVALID_CONFIG TAOS_DEF_ERROR_CODE(0, 0x0A00)
|
||||||
#define TSDB_CODE_TQ_INIT_FAILED TAOS_DEF_ERROR_CODE(0, 0x0A01)
|
#define TSDB_CODE_TQ_INIT_FAILED TAOS_DEF_ERROR_CODE(0, 0x0A01)
|
||||||
#define TSDB_CODE_TQ_NO_DISKSPACE TAOS_DEF_ERROR_CODE(0, 0x0A02)
|
|
||||||
#define TSDB_CODE_TQ_NO_DISK_PERMISSIONS TAOS_DEF_ERROR_CODE(0, 0x0A03)
|
#define TSDB_CODE_TQ_NO_DISK_PERMISSIONS TAOS_DEF_ERROR_CODE(0, 0x0A03)
|
||||||
#define TSDB_CODE_TQ_FILE_CORRUPTED TAOS_DEF_ERROR_CODE(0, 0x0A04)
|
#define TSDB_CODE_TQ_FILE_CORRUPTED TAOS_DEF_ERROR_CODE(0, 0x0A04)
|
||||||
#define TSDB_CODE_TQ_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0A05)
|
#define TSDB_CODE_TQ_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0A05)
|
||||||
|
@ -451,6 +428,7 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_WAL_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x1004)
|
#define TSDB_CODE_WAL_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x1004)
|
||||||
#define TSDB_CODE_WAL_LOG_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x1005)
|
#define TSDB_CODE_WAL_LOG_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x1005)
|
||||||
#define TSDB_CODE_WAL_CHKSUM_MISMATCH TAOS_DEF_ERROR_CODE(0, 0x1006)
|
#define TSDB_CODE_WAL_CHKSUM_MISMATCH TAOS_DEF_ERROR_CODE(0, 0x1006)
|
||||||
|
#define TSDB_CODE_WAL_LOG_INCOMPLETE TAOS_DEF_ERROR_CODE(0, 0x1007)
|
||||||
|
|
||||||
// tfs
|
// tfs
|
||||||
#define TSDB_CODE_FS_INVLD_CFG TAOS_DEF_ERROR_CODE(0, 0x2201)
|
#define TSDB_CODE_FS_INVLD_CFG TAOS_DEF_ERROR_CODE(0, 0x2201)
|
||||||
|
|
|
@ -286,7 +286,8 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
// assert to avoid un-initialization error
|
// assert to avoid un-initialization error
|
||||||
ASSERT(0);
|
tscError("invalid result passed to taos_fetch_row");
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1181,7 +1181,7 @@ static int32_t taosAlterTable(TAOS* taos, void* meta, int32_t metaLen) {
|
||||||
pVgData = NULL;
|
pVgData = NULL;
|
||||||
pArray = NULL;
|
pArray = NULL;
|
||||||
code = pRequest->code;
|
code = pRequest->code;
|
||||||
if (code == TSDB_CODE_VND_TABLE_NOT_EXIST) {
|
if (code == TSDB_CODE_TDB_TABLE_NOT_EXIST) {
|
||||||
code = TSDB_CODE_SUCCESS;
|
code = TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -508,7 +508,7 @@ static int32_t tmqSendCommitReq(tmq_t* tmq, SMqClientVg* pVg, SMqClientTopic* pT
|
||||||
pMsgSendInfo->param = pParam;
|
pMsgSendInfo->param = pParam;
|
||||||
pMsgSendInfo->paramFreeFp = taosMemoryFree;
|
pMsgSendInfo->paramFreeFp = taosMemoryFree;
|
||||||
pMsgSendInfo->fp = tmqCommitCb;
|
pMsgSendInfo->fp = tmqCommitCb;
|
||||||
pMsgSendInfo->msgType = TDMT_VND_MQ_COMMIT_OFFSET;
|
pMsgSendInfo->msgType = TDMT_VND_TMQ_COMMIT_OFFSET;
|
||||||
// send msg
|
// send msg
|
||||||
|
|
||||||
atomic_add_fetch_32(&pParamSet->waitingRspNum, 1);
|
atomic_add_fetch_32(&pParamSet->waitingRspNum, 1);
|
||||||
|
@ -750,7 +750,7 @@ void tmqSendHbReq(void* param, void* tmrId) {
|
||||||
sendInfo->requestObjRefId = 0;
|
sendInfo->requestObjRefId = 0;
|
||||||
sendInfo->param = NULL;
|
sendInfo->param = NULL;
|
||||||
sendInfo->fp = tmqHbCb;
|
sendInfo->fp = tmqHbCb;
|
||||||
sendInfo->msgType = TDMT_MND_MQ_HB;
|
sendInfo->msgType = TDMT_MND_TMQ_HB;
|
||||||
|
|
||||||
SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp);
|
SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp);
|
||||||
|
|
||||||
|
@ -1038,7 +1038,7 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
|
||||||
sendInfo->requestObjRefId = 0;
|
sendInfo->requestObjRefId = 0;
|
||||||
sendInfo->param = ¶m;
|
sendInfo->param = ¶m;
|
||||||
sendInfo->fp = tmqSubscribeCb;
|
sendInfo->fp = tmqSubscribeCb;
|
||||||
sendInfo->msgType = TDMT_MND_SUBSCRIBE;
|
sendInfo->msgType = TDMT_MND_TMQ_SUBSCRIBE;
|
||||||
|
|
||||||
SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp);
|
SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp);
|
||||||
|
|
||||||
|
@ -1420,7 +1420,7 @@ int32_t tmqAskEp(tmq_t* tmq, bool async) {
|
||||||
sendInfo->requestObjRefId = 0;
|
sendInfo->requestObjRefId = 0;
|
||||||
sendInfo->param = pParam;
|
sendInfo->param = pParam;
|
||||||
sendInfo->fp = tmqAskEpCb;
|
sendInfo->fp = tmqAskEpCb;
|
||||||
sendInfo->msgType = TDMT_MND_MQ_ASK_EP;
|
sendInfo->msgType = TDMT_MND_TMQ_ASK_EP;
|
||||||
|
|
||||||
SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp);
|
SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp);
|
||||||
|
|
||||||
|
@ -1573,7 +1573,7 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t timeout) {
|
||||||
sendInfo->requestObjRefId = 0;
|
sendInfo->requestObjRefId = 0;
|
||||||
sendInfo->param = pParam;
|
sendInfo->param = pParam;
|
||||||
sendInfo->fp = tmqPollCb;
|
sendInfo->fp = tmqPollCb;
|
||||||
sendInfo->msgType = TDMT_VND_CONSUME;
|
sendInfo->msgType = TDMT_VND_TMQ_CONSUME;
|
||||||
|
|
||||||
int64_t transporterId = 0;
|
int64_t transporterId = 0;
|
||||||
/*printf("send poll\n");*/
|
/*printf("send poll\n");*/
|
||||||
|
|
|
@ -285,7 +285,7 @@ int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, int32_t numOfRow1, int
|
||||||
// ASSERT(finalNumOfRows * pColumnInfoData->info.bytes);
|
// ASSERT(finalNumOfRows * pColumnInfoData->info.bytes);
|
||||||
char* tmp = taosMemoryRealloc(pColumnInfoData->pData, finalNumOfRows * pColumnInfoData->info.bytes);
|
char* tmp = taosMemoryRealloc(pColumnInfoData->pData, finalNumOfRows * pColumnInfoData->info.bytes);
|
||||||
if (tmp == NULL) {
|
if (tmp == NULL) {
|
||||||
return TSDB_CODE_VND_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
pColumnInfoData->pData = tmp;
|
pColumnInfoData->pData = tmp;
|
||||||
|
@ -1913,6 +1913,22 @@ char* dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** pDataBuf)
|
||||||
len += snprintf(dumpBuf + len, size - len, " %25s |", pBuf);
|
len += snprintf(dumpBuf + len, size - len, " %25s |", pBuf);
|
||||||
if (len >= size - 1) return dumpBuf;
|
if (len >= size - 1) return dumpBuf;
|
||||||
break;
|
break;
|
||||||
|
case TSDB_DATA_TYPE_TINYINT:
|
||||||
|
len += snprintf(dumpBuf + len, size - len, " %15d |", *(int8_t*)var);
|
||||||
|
if (len >= size - 1) return dumpBuf;
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_UTINYINT:
|
||||||
|
len += snprintf(dumpBuf + len, size - len, " %15d |", *(uint8_t*)var);
|
||||||
|
if (len >= size - 1) return dumpBuf;
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_SMALLINT:
|
||||||
|
len += snprintf(dumpBuf + len, size - len, " %15d |", *(int16_t*)var);
|
||||||
|
if (len >= size - 1) return dumpBuf;
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_USMALLINT:
|
||||||
|
len += snprintf(dumpBuf + len, size - len, " %15d |", *(uint16_t*)var);
|
||||||
|
if (len >= size - 1) return dumpBuf;
|
||||||
|
break;
|
||||||
case TSDB_DATA_TYPE_INT:
|
case TSDB_DATA_TYPE_INT:
|
||||||
len += snprintf(dumpBuf + len, size - len, " %15d |", *(int32_t*)var);
|
len += snprintf(dumpBuf + len, size - len, " %15d |", *(int32_t*)var);
|
||||||
if (len >= size - 1) return dumpBuf;
|
if (len >= size - 1) return dumpBuf;
|
||||||
|
@ -2068,8 +2084,8 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SSDataBlock* pDataB
|
||||||
default:
|
default:
|
||||||
if (pColInfoData->info.type < TSDB_DATA_TYPE_MAX && pColInfoData->info.type > TSDB_DATA_TYPE_NULL) {
|
if (pColInfoData->info.type < TSDB_DATA_TYPE_MAX && pColInfoData->info.type > TSDB_DATA_TYPE_NULL) {
|
||||||
if (colDataIsNull_s(pColInfoData, j)) {
|
if (colDataIsNull_s(pColInfoData, j)) {
|
||||||
tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pCol->type, TD_VTYPE_NULL, NULL, false, offset,
|
tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pCol->type, TD_VTYPE_NULL, NULL, false,
|
||||||
k);
|
offset, k);
|
||||||
} else if (pCol->type == pColInfoData->info.type) {
|
} else if (pCol->type == pColInfoData->info.type) {
|
||||||
tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pCol->type, TD_VTYPE_NORM, var, true, offset,
|
tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pCol->type, TD_VTYPE_NORM, var, true, offset,
|
||||||
k);
|
k);
|
||||||
|
@ -2142,10 +2158,26 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SSDataBlock* pDataB
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* buildCtbNameByGroupId(const char* stbName, uint64_t groupId) {
|
char* buildCtbNameByGroupId(const char* stbFullName, uint64_t groupId) {
|
||||||
ASSERT(stbName[0] != 0);
|
ASSERT(stbFullName[0] != 0);
|
||||||
SArray* tags = taosArrayInit(0, sizeof(void*));
|
SArray* tags = taosArrayInit(0, sizeof(void*));
|
||||||
|
if (tags == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
SSmlKv* pTag = taosMemoryCalloc(1, sizeof(SSmlKv));
|
SSmlKv* pTag = taosMemoryCalloc(1, sizeof(SSmlKv));
|
||||||
|
if (pTag == NULL) {
|
||||||
|
taosArrayDestroy(tags);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* cname = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN + 1);
|
||||||
|
if (cname == NULL) {
|
||||||
|
taosArrayDestroy(tags);
|
||||||
|
taosMemoryFree(pTag);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
pTag->key = "group_id";
|
pTag->key = "group_id";
|
||||||
pTag->keyLen = strlen(pTag->key);
|
pTag->keyLen = strlen(pTag->key);
|
||||||
pTag->type = TSDB_DATA_TYPE_UBIGINT;
|
pTag->type = TSDB_DATA_TYPE_UBIGINT;
|
||||||
|
@ -2153,13 +2185,11 @@ char* buildCtbNameByGroupId(const char* stbName, uint64_t groupId) {
|
||||||
pTag->length = sizeof(uint64_t);
|
pTag->length = sizeof(uint64_t);
|
||||||
taosArrayPush(tags, &pTag);
|
taosArrayPush(tags, &pTag);
|
||||||
|
|
||||||
void* cname = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN + 1);
|
|
||||||
|
|
||||||
RandTableName rname = {
|
RandTableName rname = {
|
||||||
.tags = tags,
|
.tags = tags,
|
||||||
.sTableName = stbName,
|
.stbFullName = stbFullName,
|
||||||
.sTableNameLen = strlen(stbName),
|
.stbFullNameLen = strlen(stbFullName),
|
||||||
.childTableName = cname,
|
.ctbShortName = cname,
|
||||||
};
|
};
|
||||||
|
|
||||||
buildChildTableName(&rname);
|
buildChildTableName(&rname);
|
||||||
|
@ -2167,8 +2197,8 @@ char* buildCtbNameByGroupId(const char* stbName, uint64_t groupId) {
|
||||||
taosMemoryFree(pTag);
|
taosMemoryFree(pTag);
|
||||||
taosArrayDestroy(tags);
|
taosArrayDestroy(tags);
|
||||||
|
|
||||||
ASSERT(rname.childTableName && rname.childTableName[0]);
|
ASSERT(rname.ctbShortName && rname.ctbShortName[0]);
|
||||||
return rname.childTableName;
|
return rname.ctbShortName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void blockEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_t numOfCols, int8_t needCompress) {
|
void blockEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_t numOfCols, int8_t needCompress) {
|
||||||
|
|
|
@ -156,6 +156,9 @@ char tsCompressor[32] = "ZSTD_COMPRESSOR"; // ZSTD_COMPRESSOR or GZIP_COMPR
|
||||||
// udf
|
// udf
|
||||||
bool tsStartUdfd = true;
|
bool tsStartUdfd = true;
|
||||||
|
|
||||||
|
// wal
|
||||||
|
int64_t tsWalFsyncDataSizeLimit = (100 * 1024 * 1024L);
|
||||||
|
|
||||||
// internal
|
// internal
|
||||||
int32_t tsTransPullupInterval = 2;
|
int32_t tsTransPullupInterval = 2;
|
||||||
int32_t tsMqRebalanceInterval = 2;
|
int32_t tsMqRebalanceInterval = 2;
|
||||||
|
@ -423,6 +426,9 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
|
||||||
if (cfgAddInt32(pCfg, "uptimeInterval", tsUptimeInterval, 1, 100000, 1) != 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;
|
if (cfgAddInt32(pCfg, "queryRsmaTolerance", tsQueryRsmaTolerance, 0, 900000, 0) != 0) return -1;
|
||||||
|
|
||||||
|
if (cfgAddInt64(pCfg, "walFsyncDataSizeLimit", tsWalFsyncDataSizeLimit, 100 * 1024 * 1024, INT64_MAX, 0) != 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (cfgAddBool(pCfg, "udf", tsStartUdfd, 0) != 0) return -1;
|
if (cfgAddBool(pCfg, "udf", tsStartUdfd, 0) != 0) return -1;
|
||||||
if (cfgAddString(pCfg, "udfdResFuncs", tsUdfdResFuncs, 0) != 0) return -1;
|
if (cfgAddString(pCfg, "udfdResFuncs", tsUdfdResFuncs, 0) != 0) return -1;
|
||||||
if (cfgAddString(pCfg, "udfdLdLibPath", tsUdfdLdLibPath, 0) != 0) return -1;
|
if (cfgAddString(pCfg, "udfdLdLibPath", tsUdfdLdLibPath, 0) != 0) return -1;
|
||||||
|
@ -722,6 +728,8 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
|
||||||
tsUptimeInterval = cfgGetItem(pCfg, "uptimeInterval")->i32;
|
tsUptimeInterval = cfgGetItem(pCfg, "uptimeInterval")->i32;
|
||||||
tsQueryRsmaTolerance = cfgGetItem(pCfg, "queryRsmaTolerance")->i32;
|
tsQueryRsmaTolerance = cfgGetItem(pCfg, "queryRsmaTolerance")->i32;
|
||||||
|
|
||||||
|
tsWalFsyncDataSizeLimit = cfgGetItem(pCfg, "walFsyncDataSizeLimit")->i64;
|
||||||
|
|
||||||
tsStartUdfd = cfgGetItem(pCfg, "udf")->bval;
|
tsStartUdfd = cfgGetItem(pCfg, "udf")->bval;
|
||||||
tstrncpy(tsUdfdResFuncs, cfgGetItem(pCfg, "udfdResFuncs")->str, sizeof(tsUdfdResFuncs));
|
tstrncpy(tsUdfdResFuncs, cfgGetItem(pCfg, "udfdResFuncs")->str, sizeof(tsUdfdResFuncs));
|
||||||
tstrncpy(tsUdfdLdLibPath, cfgGetItem(pCfg, "udfdLdLibPath")->str, sizeof(tsUdfdLdLibPath));
|
tstrncpy(tsUdfdLdLibPath, cfgGetItem(pCfg, "udfdLdLibPath")->str, sizeof(tsUdfdLdLibPath));
|
||||||
|
|
|
@ -315,7 +315,7 @@ static int compareKv(const void* p1, const void* p2) {
|
||||||
*/
|
*/
|
||||||
void buildChildTableName(RandTableName* rName) {
|
void buildChildTableName(RandTableName* rName) {
|
||||||
SStringBuilder sb = {0};
|
SStringBuilder sb = {0};
|
||||||
taosStringBuilderAppendStringLen(&sb, rName->sTableName, rName->sTableNameLen);
|
taosStringBuilderAppendStringLen(&sb, rName->stbFullName, rName->stbFullNameLen);
|
||||||
taosArraySort(rName->tags, compareKv);
|
taosArraySort(rName->tags, compareKv);
|
||||||
for (int j = 0; j < taosArrayGetSize(rName->tags); ++j) {
|
for (int j = 0; j < taosArrayGetSize(rName->tags); ++j) {
|
||||||
taosStringBuilderAppendChar(&sb, ',');
|
taosStringBuilderAppendChar(&sb, ',');
|
||||||
|
@ -336,11 +336,11 @@ void buildChildTableName(RandTableName* rName) {
|
||||||
tMD5Final(&context);
|
tMD5Final(&context);
|
||||||
|
|
||||||
char temp[8] = {0};
|
char temp[8] = {0};
|
||||||
rName->childTableName[0] = 't';
|
rName->ctbShortName[0] = 't';
|
||||||
rName->childTableName[1] = '_';
|
rName->ctbShortName[1] = '_';
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
sprintf(temp, "%02x", context.digest[i]);
|
sprintf(temp, "%02x", context.digest[i]);
|
||||||
strcat(rName->childTableName, temp);
|
strcat(rName->ctbShortName, temp);
|
||||||
}
|
}
|
||||||
taosStringBuilderDestroy(&sb);
|
taosStringBuilderDestroy(&sb);
|
||||||
rName->uid = *(uint64_t*)(context.digest);
|
rName->uid = *(uint64_t*)(context.digest);
|
||||||
|
|
|
@ -31,7 +31,7 @@ static int32_t STSBufUpdateHeader(STSBuf* pTSBuf, STSBufFileHeader* pHeader);
|
||||||
*/
|
*/
|
||||||
STSBuf* tsBufCreate(bool autoDelete, int32_t order) {
|
STSBuf* tsBufCreate(bool autoDelete, int32_t order) {
|
||||||
if (!osTempSpaceAvailable()) {
|
if (!osTempSpaceAvailable()) {
|
||||||
terrno = TSDB_CODE_TSC_NO_DISKSPACE;
|
terrno = TSDB_CODE_NO_DISKSPACE;
|
||||||
// tscError("tmp file created failed since %s", terrstr());
|
// tscError("tmp file created failed since %s", terrstr());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,15 +141,13 @@ SArray *mmGetMsgHandles() {
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_STREAM, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_STREAM, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_MND_GET_INDEX, mmPutMsgToReadQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_MND_GET_INDEX, mmPutMsgToReadQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_MND_GET_TABLE_INDEX, mmPutMsgToReadQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_MND_GET_TABLE_INDEX, mmPutMsgToReadQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_TOPIC, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_MND_TMQ_CREATE_TOPIC, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_MND_ALTER_TOPIC, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_MND_TMQ_DROP_TOPIC, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_TOPIC, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_MND_TMQ_SUBSCRIBE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_MND_SUBSCRIBE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_MND_TMQ_ASK_EP, mmPutMsgToReadQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_MND_MQ_ASK_EP, mmPutMsgToReadQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_MND_TMQ_HB, mmPutMsgToReadQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_MND_MQ_HB, mmPutMsgToReadQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_MND_TMQ_DROP_CGROUP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_MND_MQ_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_MQ_DROP_CGROUP_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_MND_MQ_COMMIT_OFFSET, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_MND_KILL_TRANS, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_MND_KILL_TRANS, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_MND_KILL_QUERY, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_MND_KILL_QUERY, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_MND_KILL_CONN, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_MND_KILL_CONN, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
|
@ -171,10 +169,10 @@ SArray *mmGetMsgHandles() {
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_STB_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_STB_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_CREATE_SMA_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_CREATE_SMA_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_SMA_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_SMA_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_CHANGE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_SUBSCRIBE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_DELETE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_DELETE_SUB_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_ADD_CHECK_INFO_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_ADD_CHECKINFO_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_DELETE_CHECK_INFO_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_DEL_CHECKINFO_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_SCH_DROP_TASK, mmPutMsgToFetchQueue, 1) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_SCH_DROP_TASK, mmPutMsgToFetchQueue, 1) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DEPLOY_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DEPLOY_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DROP_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DROP_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
|
@ -197,6 +195,8 @@ SArray *mmGetMsgHandles() {
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_APPEND_ENTRIES_REPLY, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_APPEND_ENTRIES_REPLY, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_SEND, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_SEND, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_RSP, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_RSP, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||||
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_PRE_SNAPSHOT, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||||
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_PRE_SNAPSHOT_REPLY, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||||
|
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_HEARTBEAT, mmPutMsgToSyncCtrlQueue, 1) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_HEARTBEAT, mmPutMsgToSyncCtrlQueue, 1) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_HEARTBEAT_REPLY, mmPutMsgToSyncCtrlQueue, 1) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_HEARTBEAT_REPLY, mmPutMsgToSyncCtrlQueue, 1) == NULL) goto _OVER;
|
||||||
|
|
|
@ -67,24 +67,6 @@ static void mmProcessRpcMsg(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
||||||
taosFreeQitem(pMsg);
|
taosFreeQitem(pMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mmProcessSyncCtrlMsg(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
|
||||||
SMnodeMgmt *pMgmt = pInfo->ahandle;
|
|
||||||
pMsg->info.node = pMgmt->pMnode;
|
|
||||||
|
|
||||||
const STraceId *trace = &pMsg->info.traceId;
|
|
||||||
dGTrace("msg:%p, get from mnode-sync-ctrl queue", pMsg);
|
|
||||||
|
|
||||||
SMsgHead *pHead = pMsg->pCont;
|
|
||||||
pHead->contLen = ntohl(pHead->contLen);
|
|
||||||
pHead->vgId = ntohl(pHead->vgId);
|
|
||||||
|
|
||||||
int32_t code = mndProcessSyncCtrlMsg(pMsg);
|
|
||||||
|
|
||||||
dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
|
|
||||||
rpcFreeCont(pMsg->pCont);
|
|
||||||
taosFreeQitem(pMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mmProcessSyncMsg(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
static void mmProcessSyncMsg(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
||||||
SMnodeMgmt *pMgmt = pInfo->ahandle;
|
SMnodeMgmt *pMgmt = pInfo->ahandle;
|
||||||
pMsg->info.node = pMgmt->pMnode;
|
pMsg->info.node = pMgmt->pMnode;
|
||||||
|
@ -252,7 +234,7 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
||||||
.min = 1,
|
.min = 1,
|
||||||
.max = 1,
|
.max = 1,
|
||||||
.name = "mnode-sync-ctrl",
|
.name = "mnode-sync-ctrl",
|
||||||
.fp = (FItem)mmProcessSyncCtrlMsg,
|
.fp = (FItem)mmProcessSyncMsg,
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
};
|
};
|
||||||
if (tSingleWorkerInit(&pMgmt->syncCtrlWorker, &scCfg) != 0) {
|
if (tSingleWorkerInit(&pMgmt->syncCtrlWorker, &scCfg) != 0) {
|
||||||
|
|
|
@ -72,8 +72,6 @@ SArray *smGetMsgHandles() {
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RUN, smPutNodeMsgToStreamQueue, 1) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RUN, smPutNodeMsgToStreamQueue, 1) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH, smPutNodeMsgToStreamQueue, 1) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH, smPutNodeMsgToStreamQueue, 1) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH_RSP, smPutNodeMsgToStreamQueue, 1) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH_RSP, smPutNodeMsgToStreamQueue, 1) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER, smPutNodeMsgToStreamQueue, 1) == NULL) goto _OVER;
|
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER_RSP, smPutNodeMsgToStreamQueue, 1) == NULL) goto _OVER;
|
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE, smPutNodeMsgToStreamQueue, 1) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE, smPutNodeMsgToStreamQueue, 1) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE_RSP, smPutNodeMsgToStreamQueue, 1) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE_RSP, smPutNodeMsgToStreamQueue, 1) == NULL) goto _OVER;
|
||||||
|
|
||||||
|
|
|
@ -392,12 +392,12 @@ SArray *vmGetMsgHandles() {
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_CANCEL_SMA, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_CANCEL_SMA, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_SMA, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_SMA, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_SUBMIT_RSMA, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_SUBMIT_RSMA, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_CHANGE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_SUBSCRIBE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_DELETE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_DELETE_SUB, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_COMMIT_OFFSET, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_COMMIT_OFFSET, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_ADD_CHECK_INFO, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_ADD_CHECKINFO, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_DELETE_CHECK_INFO, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_DEL_CHECKINFO, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_CONSUME, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_CONSUME, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_DELETE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_DELETE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_BATCH_DEL, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_BATCH_DEL, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_COMMIT, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_COMMIT, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
|
@ -409,10 +409,9 @@ SArray *vmGetMsgHandles() {
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RUN, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RUN, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH_RSP, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH_RSP, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;
|
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER_RSP, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;
|
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE_RSP, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE_RSP, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;
|
||||||
|
if (dmSetMgmtHandle(pArray, TDMT_STREAM_RECOVER_FINISH, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER;
|
||||||
|
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_REPLICA, vmPutMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_REPLICA, vmPutMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_CONFIG, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_CONFIG, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
|
@ -436,6 +435,9 @@ SArray *vmGetMsgHandles() {
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_APPEND_ENTRIES_REPLY, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_APPEND_ENTRIES_REPLY, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_SEND, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_SEND, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_RSP, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_RSP, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
||||||
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_PRE_SNAPSHOT, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
||||||
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_PRE_SNAPSHOT_REPLY, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
||||||
|
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_HEARTBEAT, vmPutMsgToSyncCtrlQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_HEARTBEAT, vmPutMsgToSyncCtrlQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_HEARTBEAT_REPLY, vmPutMsgToSyncCtrlQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_HEARTBEAT_REPLY, vmPutMsgToSyncCtrlQueue, 0) == NULL) goto _OVER;
|
||||||
|
|
||||||
|
|
|
@ -133,22 +133,6 @@ static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vmProcessSyncCtrlQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
|
|
||||||
SVnodeObj *pVnode = pInfo->ahandle;
|
|
||||||
SRpcMsg *pMsg = NULL;
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
|
||||||
if (taosGetQitem(qall, (void **)&pMsg) == 0) continue;
|
|
||||||
const STraceId *trace = &pMsg->info.traceId;
|
|
||||||
dGTrace("vgId:%d, msg:%p get from vnode-sync queue", pVnode->vgId, pMsg);
|
|
||||||
|
|
||||||
int32_t code = vnodeProcessSyncCtrlMsg(pVnode->pImpl, pMsg, NULL); // no response here
|
|
||||||
dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
|
|
||||||
rpcFreeCont(pMsg->pCont);
|
|
||||||
taosFreeQitem(pMsg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
|
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
|
||||||
const STraceId *trace = &pMsg->info.traceId;
|
const STraceId *trace = &pMsg->info.traceId;
|
||||||
SMsgHead *pHead = pMsg->pCont;
|
SMsgHead *pHead = pMsg->pCont;
|
||||||
|
@ -190,7 +174,7 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp
|
||||||
break;
|
break;
|
||||||
case WRITE_QUEUE:
|
case WRITE_QUEUE:
|
||||||
if (!osDataSpaceAvailable()) {
|
if (!osDataSpaceAvailable()) {
|
||||||
terrno = TSDB_CODE_VND_NO_DISKSPACE;
|
terrno = TSDB_CODE_NO_DISKSPACE;
|
||||||
code = terrno;
|
code = terrno;
|
||||||
dError("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, terrstr(code));
|
dError("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, terrstr(code));
|
||||||
} else if ((pMsg->msgType == TDMT_VND_SUBMIT) && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
|
} else if ((pMsg->msgType == TDMT_VND_SUBMIT) && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
|
||||||
|
@ -317,7 +301,7 @@ int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
|
||||||
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
||||||
pVnode->pWriteQ = tWWorkerAllocQueue(&pMgmt->writePool, pVnode->pImpl, (FItems)vnodeProposeWriteMsg);
|
pVnode->pWriteQ = tWWorkerAllocQueue(&pMgmt->writePool, pVnode->pImpl, (FItems)vnodeProposeWriteMsg);
|
||||||
pVnode->pSyncQ = tWWorkerAllocQueue(&pMgmt->syncPool, pVnode, (FItems)vmProcessSyncQueue);
|
pVnode->pSyncQ = tWWorkerAllocQueue(&pMgmt->syncPool, pVnode, (FItems)vmProcessSyncQueue);
|
||||||
pVnode->pSyncCtrlQ = tWWorkerAllocQueue(&pMgmt->syncCtrlPool, pVnode, (FItems)vmProcessSyncCtrlQueue);
|
pVnode->pSyncCtrlQ = tWWorkerAllocQueue(&pMgmt->syncCtrlPool, pVnode, (FItems)vmProcessSyncQueue);
|
||||||
pVnode->pApplyQ = tWWorkerAllocQueue(&pMgmt->applyPool, pVnode->pImpl, (FItems)vnodeApplyWriteMsg);
|
pVnode->pApplyQ = tWWorkerAllocQueue(&pMgmt->applyPool, pVnode->pImpl, (FItems)vnodeApplyWriteMsg);
|
||||||
pVnode->pQueryQ = tQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
|
pVnode->pQueryQ = tQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue);
|
||||||
pVnode->pStreamQ = tQWorkerAllocQueue(&pMgmt->streamPool, pVnode, (FItem)vmProcessStreamQueue);
|
pVnode->pStreamQ = tQWorkerAllocQueue(&pMgmt->streamPool, pVnode, (FItem)vmProcessStreamQueue);
|
||||||
|
|
|
@ -71,17 +71,17 @@ static bool dmCheckDiskSpace() {
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
if (!osDataSpaceAvailable()) {
|
if (!osDataSpaceAvailable()) {
|
||||||
dError("data disk space unavailable, i.e. %s", tsDataDir);
|
dError("data disk space unavailable, i.e. %s", tsDataDir);
|
||||||
terrno = TSDB_CODE_VND_NO_DISKSPACE;
|
terrno = TSDB_CODE_NO_DISKSPACE;
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
if (!osLogSpaceAvailable()) {
|
if (!osLogSpaceAvailable()) {
|
||||||
dError("log disk space unavailable, i.e. %s", tsLogDir);
|
dError("log disk space unavailable, i.e. %s", tsLogDir);
|
||||||
terrno = TSDB_CODE_VND_NO_DISKSPACE;
|
terrno = TSDB_CODE_NO_DISKSPACE;
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
if (!osTempSpaceAvailable()) {
|
if (!osTempSpaceAvailable()) {
|
||||||
dError("temp disk space unavailable, i.e. %s", tsTempDir);
|
dError("temp disk space unavailable, i.e. %s", tsTempDir);
|
||||||
terrno = TSDB_CODE_VND_NO_DISKSPACE;
|
terrno = TSDB_CODE_NO_DISKSPACE;
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -105,6 +105,7 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsReq(pRpc) && pRpc->pCont == NULL) {
|
if (IsReq(pRpc) && pRpc->pCont == NULL) {
|
||||||
|
dGError("msg:%p, type:%s pCont is NULL", pRpc, TMSG_INFO(pRpc->msgType));
|
||||||
terrno = TSDB_CODE_INVALID_MSG_LEN;
|
terrno = TSDB_CODE_INVALID_MSG_LEN;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -133,6 +134,7 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
dGError("msg:%p, type:%s contLen is 0", pRpc, TMSG_INFO(pRpc->msgType));
|
||||||
terrno = TSDB_CODE_INVALID_MSG_LEN;
|
terrno = TSDB_CODE_INVALID_MSG_LEN;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ void *dmSetMgmtHandle(SArray *pArray, tmsg_t msgType, void *nodeMsgFp, bool need
|
||||||
}
|
}
|
||||||
|
|
||||||
void dmGetMonitorSystemInfo(SMonSysInfo *pInfo) {
|
void dmGetMonitorSystemInfo(SMonSysInfo *pInfo) {
|
||||||
taosGetCpuUsage(&pInfo->cpu_engine, &pInfo->cpu_system);
|
taosGetCpuUsage(&pInfo->cpu_system, &pInfo->cpu_engine);
|
||||||
taosGetCpuCores(&pInfo->cpu_cores);
|
taosGetCpuCores(&pInfo->cpu_cores);
|
||||||
taosGetProcMemory(&pInfo->mem_engine);
|
taosGetProcMemory(&pInfo->mem_engine);
|
||||||
taosGetSysMemory(&pInfo->mem_system);
|
taosGetSysMemory(&pInfo->mem_system);
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
|
|
||||||
#include "sdb.h"
|
#include "sdb.h"
|
||||||
#include "sync.h"
|
#include "sync.h"
|
||||||
#include "syncTools.h"
|
|
||||||
#include "tcache.h"
|
#include "tcache.h"
|
||||||
#include "tdatablock.h"
|
#include "tdatablock.h"
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
|
@ -90,7 +89,6 @@ typedef struct {
|
||||||
int32_t errCode;
|
int32_t errCode;
|
||||||
int32_t transId;
|
int32_t transId;
|
||||||
SRWLatch lock;
|
SRWLatch lock;
|
||||||
int8_t leaderTransferFinish;
|
|
||||||
int8_t selfIndex;
|
int8_t selfIndex;
|
||||||
int8_t numOfReplicas;
|
int8_t numOfReplicas;
|
||||||
SReplica replicas[TSDB_MAX_REPLICA];
|
SReplica replicas[TSDB_MAX_REPLICA];
|
||||||
|
|
|
@ -63,12 +63,12 @@ int32_t mndInitConsumer(SMnode *pMnode) {
|
||||||
.deleteFp = (SdbDeleteFp)mndConsumerActionDelete,
|
.deleteFp = (SdbDeleteFp)mndConsumerActionDelete,
|
||||||
};
|
};
|
||||||
|
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_SUBSCRIBE, mndProcessSubscribeReq);
|
mndSetMsgHandle(pMnode, TDMT_MND_TMQ_SUBSCRIBE, mndProcessSubscribeReq);
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_MQ_HB, mndProcessMqHbReq);
|
mndSetMsgHandle(pMnode, TDMT_MND_TMQ_HB, mndProcessMqHbReq);
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_MQ_ASK_EP, mndProcessAskEpReq);
|
mndSetMsgHandle(pMnode, TDMT_MND_TMQ_ASK_EP, mndProcessAskEpReq);
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_MQ_TIMER, mndProcessMqTimerMsg);
|
mndSetMsgHandle(pMnode, TDMT_MND_TMQ_TIMER, mndProcessMqTimerMsg);
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_MQ_CONSUMER_LOST, mndProcessConsumerLostMsg);
|
mndSetMsgHandle(pMnode, TDMT_MND_TMQ_CONSUMER_LOST, mndProcessConsumerLostMsg);
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_MQ_CONSUMER_RECOVER, mndProcessConsumerRecoverMsg);
|
mndSetMsgHandle(pMnode, TDMT_MND_TMQ_CONSUMER_RECOVER, mndProcessConsumerRecoverMsg);
|
||||||
|
|
||||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CONSUMERS, mndRetrieveConsumer);
|
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CONSUMERS, mndRetrieveConsumer);
|
||||||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_CONSUMERS, mndCancelGetNextConsumer);
|
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_CONSUMERS, mndCancelGetNextConsumer);
|
||||||
|
@ -207,7 +207,7 @@ static int32_t mndProcessMqTimerMsg(SRpcMsg *pMsg) {
|
||||||
|
|
||||||
pLostMsg->consumerId = pConsumer->consumerId;
|
pLostMsg->consumerId = pConsumer->consumerId;
|
||||||
SRpcMsg pRpcMsg = {
|
SRpcMsg pRpcMsg = {
|
||||||
.msgType = TDMT_MND_MQ_CONSUMER_LOST,
|
.msgType = TDMT_MND_TMQ_CONSUMER_LOST,
|
||||||
.pCont = pLostMsg,
|
.pCont = pLostMsg,
|
||||||
.contLen = sizeof(SMqConsumerLostMsg),
|
.contLen = sizeof(SMqConsumerLostMsg),
|
||||||
};
|
};
|
||||||
|
@ -256,7 +256,7 @@ static int32_t mndProcessMqTimerMsg(SRpcMsg *pMsg) {
|
||||||
if (taosHashGetSize(pRebMsg->rebSubHash) != 0) {
|
if (taosHashGetSize(pRebMsg->rebSubHash) != 0) {
|
||||||
mInfo("mq rebalance will be triggered");
|
mInfo("mq rebalance will be triggered");
|
||||||
SRpcMsg rpcMsg = {
|
SRpcMsg rpcMsg = {
|
||||||
.msgType = TDMT_MND_MQ_DO_REBALANCE,
|
.msgType = TDMT_MND_TMQ_DO_REBALANCE,
|
||||||
.pCont = pRebMsg,
|
.pCont = pRebMsg,
|
||||||
.contLen = sizeof(SMqDoRebalanceMsg),
|
.contLen = sizeof(SMqDoRebalanceMsg),
|
||||||
};
|
};
|
||||||
|
@ -292,7 +292,7 @@ static int32_t mndProcessMqHbReq(SRpcMsg *pMsg) {
|
||||||
|
|
||||||
pRecoverMsg->consumerId = consumerId;
|
pRecoverMsg->consumerId = consumerId;
|
||||||
SRpcMsg pRpcMsg = {
|
SRpcMsg pRpcMsg = {
|
||||||
.msgType = TDMT_MND_MQ_CONSUMER_RECOVER,
|
.msgType = TDMT_MND_TMQ_CONSUMER_RECOVER,
|
||||||
.pCont = pRecoverMsg,
|
.pCont = pRecoverMsg,
|
||||||
.contLen = sizeof(SMqConsumerRecoverMsg),
|
.contLen = sizeof(SMqConsumerRecoverMsg),
|
||||||
};
|
};
|
||||||
|
@ -331,7 +331,7 @@ static int32_t mndProcessAskEpReq(SRpcMsg *pMsg) {
|
||||||
|
|
||||||
pRecoverMsg->consumerId = consumerId;
|
pRecoverMsg->consumerId = consumerId;
|
||||||
SRpcMsg pRpcMsg = {
|
SRpcMsg pRpcMsg = {
|
||||||
.msgType = TDMT_MND_MQ_CONSUMER_RECOVER,
|
.msgType = TDMT_MND_TMQ_CONSUMER_RECOVER,
|
||||||
.pCont = pRecoverMsg,
|
.pCont = pRecoverMsg,
|
||||||
.contLen = sizeof(SMqConsumerRecoverMsg),
|
.contLen = sizeof(SMqConsumerRecoverMsg),
|
||||||
};
|
};
|
||||||
|
|
|
@ -403,6 +403,11 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
|
||||||
bool reboot = (pDnode->rebootTime != statusReq.rebootTime);
|
bool reboot = (pDnode->rebootTime != statusReq.rebootTime);
|
||||||
bool needCheck = !online || dnodeChanged || reboot;
|
bool needCheck = !online || dnodeChanged || reboot;
|
||||||
|
|
||||||
|
pDnode->accessTimes++;
|
||||||
|
pDnode->lastAccessTime = curMs;
|
||||||
|
mTrace("dnode:%d, status received, access times:%d check:%d online:%d reboot:%d changed:%d", pDnode->id,
|
||||||
|
pDnode->accessTimes, needCheck, online, reboot, dnodeChanged);
|
||||||
|
|
||||||
if (needCheck) {
|
if (needCheck) {
|
||||||
if (statusReq.sver != tsVersion) {
|
if (statusReq.sver != tsVersion) {
|
||||||
if (pDnode != NULL) {
|
if (pDnode != NULL) {
|
||||||
|
@ -424,9 +429,6 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
|
||||||
pMnode->clusterId);
|
pMnode->clusterId);
|
||||||
terrno = TSDB_CODE_MND_INVALID_CLUSTER_ID;
|
terrno = TSDB_CODE_MND_INVALID_CLUSTER_ID;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
} else {
|
|
||||||
pDnode->accessTimes++;
|
|
||||||
mDebug("dnode:%d, status received, access times %d", pDnode->id, pDnode->accessTimes);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,8 +475,6 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
|
||||||
pReq->info.rsp = pHead;
|
pReq->info.rsp = pHead;
|
||||||
}
|
}
|
||||||
|
|
||||||
pDnode->lastAccessTime = curMs;
|
|
||||||
pDnode->accessTimes++;
|
|
||||||
code = 0;
|
code = 0;
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
|
|
|
@ -105,7 +105,7 @@ static void mndCalMqRebalance(SMnode *pMnode) {
|
||||||
int32_t contLen = 0;
|
int32_t contLen = 0;
|
||||||
void *pReq = mndBuildTimerMsg(&contLen);
|
void *pReq = mndBuildTimerMsg(&contLen);
|
||||||
if (pReq != NULL) {
|
if (pReq != NULL) {
|
||||||
SRpcMsg rpcMsg = {.msgType = TDMT_MND_MQ_TIMER, .pCont = pReq, .contLen = contLen};
|
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TMQ_TIMER, .pCont = pReq, .contLen = contLen};
|
||||||
tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg);
|
tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -428,18 +428,7 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
|
||||||
|
|
||||||
void mndPreClose(SMnode *pMnode) {
|
void mndPreClose(SMnode *pMnode) {
|
||||||
if (pMnode != NULL) {
|
if (pMnode != NULL) {
|
||||||
atomic_store_8(&(pMnode->syncMgmt.leaderTransferFinish), 0);
|
|
||||||
syncLeaderTransfer(pMnode->syncMgmt.sync);
|
syncLeaderTransfer(pMnode->syncMgmt.sync);
|
||||||
|
|
||||||
#if 0
|
|
||||||
mInfo("vgId:1, mnode start leader transfer");
|
|
||||||
// wait for leader transfer finish
|
|
||||||
while (!atomic_load_8(&(pMnode->syncMgmt.leaderTransferFinish))) {
|
|
||||||
taosMsleep(10);
|
|
||||||
mInfo("vgId:1, mnode waiting for leader transfer");
|
|
||||||
}
|
|
||||||
mInfo("vgId:1, mnode finish leader transfer");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -474,128 +463,18 @@ void mndStop(SMnode *pMnode) {
|
||||||
mndCleanupTimer(pMnode);
|
mndCleanupTimer(pMnode);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndProcessSyncCtrlMsg(SRpcMsg *pMsg) {
|
|
||||||
SMnode *pMnode = pMsg->info.node;
|
|
||||||
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
mInfo("vgId:%d, process sync ctrl msg", 1);
|
|
||||||
|
|
||||||
if (!syncIsInit()) {
|
|
||||||
mError("failed to process sync msg:%p type:%s since syncEnv stop", pMsg, TMSG_INFO(pMsg->msgType));
|
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SSyncNode *pSyncNode = syncNodeAcquire(pMgmt->sync);
|
|
||||||
if (pSyncNode == NULL) {
|
|
||||||
mError("failed to process sync msg:%p type:%s since syncNode is null", pMsg, TMSG_INFO(pMsg->msgType));
|
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pMsg->msgType == TDMT_SYNC_HEARTBEAT) {
|
|
||||||
SyncHeartbeat *pSyncMsg = syncHeartbeatFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnHeartbeat(pSyncNode, pSyncMsg);
|
|
||||||
syncHeartbeatDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_HEARTBEAT_REPLY) {
|
|
||||||
SyncHeartbeatReply *pSyncMsg = syncHeartbeatReplyFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnHeartbeatReply(pSyncNode, pSyncMsg);
|
|
||||||
syncHeartbeatReplyDestroy(pSyncMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
|
|
||||||
if (code != 0) {
|
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
|
||||||
}
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
|
int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
|
||||||
SMnode *pMnode = pMsg->info.node;
|
SMnode *pMnode = pMsg->info.node;
|
||||||
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
if (!syncIsInit()) {
|
const STraceId *trace = &pMsg->info.traceId;
|
||||||
mError("failed to process sync msg:%p type:%s since syncEnv stop", pMsg, TMSG_INFO(pMsg->msgType));
|
mGTrace("vgId:1, sync msg:%p will be processed, type:%s", pMsg, TMSG_INFO(pMsg->msgType));
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SSyncNode *pSyncNode = syncNodeAcquire(pMgmt->sync);
|
|
||||||
if (pSyncNode == NULL) {
|
|
||||||
mError("failed to process sync msg:%p type:%s since syncNode is null", pMsg, TMSG_INFO(pMsg->msgType));
|
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pMsg->msgType == TDMT_SYNC_TIMEOUT) {
|
|
||||||
SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnTimer(pSyncNode, pSyncMsg);
|
|
||||||
syncTimeoutDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_PING) {
|
|
||||||
SyncPing *pSyncMsg = syncPingFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnPing(pSyncNode, pSyncMsg);
|
|
||||||
syncPingDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) {
|
|
||||||
SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnPingReply(pSyncNode, pSyncMsg);
|
|
||||||
syncPingReplyDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
|
||||||
SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnClientRequest(pSyncNode, pSyncMsg, NULL);
|
|
||||||
syncClientRequestDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) {
|
|
||||||
SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnRequestVote(pSyncNode, pSyncMsg);
|
|
||||||
syncRequestVoteDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) {
|
|
||||||
SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnRequestVoteReply(pSyncNode, pSyncMsg);
|
|
||||||
syncRequestVoteReplyDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) {
|
|
||||||
SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnAppendEntries(pSyncNode, pSyncMsg);
|
|
||||||
syncAppendEntriesDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) {
|
|
||||||
SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnAppendEntriesReply(pSyncNode, pSyncMsg);
|
|
||||||
syncAppendEntriesReplyDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) {
|
|
||||||
SyncSnapshotSend *pSyncMsg = syncSnapshotSendFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnSnapshot(pSyncNode, pSyncMsg);
|
|
||||||
syncSnapshotSendDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) {
|
|
||||||
SyncSnapshotRsp *pSyncMsg = syncSnapshotRspFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnSnapshotReply(pSyncNode, pSyncMsg);
|
|
||||||
syncSnapshotRspDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_LOCAL_CMD) {
|
|
||||||
SyncLocalCmd *pSyncMsg = syncLocalCmdFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnLocalCmd(pSyncNode, pSyncMsg);
|
|
||||||
syncLocalCmdDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
mError("failed to process msg:%p since invalid type:%s", pMsg, TMSG_INFO(pMsg->msgType));
|
|
||||||
code = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
|
|
||||||
|
int32_t code = syncProcessMsg(pMgmt->sync, pMsg);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
mGError("vgId:1, failed to process sync msg:%p type:%s since %s", pMsg, TMSG_INFO(pMsg->msgType), terrstr());
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -608,14 +487,14 @@ static int32_t mndCheckMnodeState(SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
if (mndAcquireRpc(pMsg->info.node) == 0) return 0;
|
if (mndAcquireRpc(pMsg->info.node) == 0) return 0;
|
||||||
|
|
||||||
SMnode *pMnode = pMsg->info.node;
|
SMnode *pMnode = pMsg->info.node;
|
||||||
const char *role = syncGetMyRoleStr(pMnode->syncMgmt.sync);
|
SSyncState state = syncGetState(pMnode->syncMgmt.sync);
|
||||||
bool restored = syncIsRestoreFinish(pMnode->syncMgmt.sync);
|
|
||||||
if (pMsg->msgType == TDMT_MND_MQ_TIMER || pMsg->msgType == TDMT_MND_TELEM_TIMER ||
|
if (pMsg->msgType == TDMT_MND_TMQ_TIMER || pMsg->msgType == TDMT_MND_TELEM_TIMER ||
|
||||||
pMsg->msgType == TDMT_MND_TRANS_TIMER || pMsg->msgType == TDMT_MND_TTL_TIMER ||
|
pMsg->msgType == TDMT_MND_TRANS_TIMER || pMsg->msgType == TDMT_MND_TTL_TIMER ||
|
||||||
pMsg->msgType == TDMT_MND_UPTIME_TIMER) {
|
pMsg->msgType == TDMT_MND_UPTIME_TIMER) {
|
||||||
mTrace("timer not process since mnode restored:%d stopped:%d, sync restored:%d role:%s ", pMnode->restored,
|
mTrace("timer not process since mnode restored:%d stopped:%d, sync restored:%d role:%s ", pMnode->restored,
|
||||||
pMnode->stopped, restored, role);
|
pMnode->stopped, state.restored, syncStr(state.restored));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -626,8 +505,8 @@ static int32_t mndCheckMnodeState(SRpcMsg *pMsg) {
|
||||||
mDebug(
|
mDebug(
|
||||||
"msg:%p, type:%s failed to process since %s, mnode restored:%d stopped:%d, sync restored:%d "
|
"msg:%p, type:%s failed to process since %s, mnode restored:%d stopped:%d, sync restored:%d "
|
||||||
"role:%s, redirect numOfEps:%d inUse:%d",
|
"role:%s, redirect numOfEps:%d inUse:%d",
|
||||||
pMsg, TMSG_INFO(pMsg->msgType), terrstr(), pMnode->restored, pMnode->stopped, restored, role, epSet.numOfEps,
|
pMsg, TMSG_INFO(pMsg->msgType), terrstr(), pMnode->restored, pMnode->stopped, state.restored,
|
||||||
epSet.inUse);
|
syncStr(state.restored), epSet.numOfEps, epSet.inUse);
|
||||||
|
|
||||||
if (epSet.numOfEps > 0) {
|
if (epSet.numOfEps > 0) {
|
||||||
for (int32_t i = 0; i < epSet.numOfEps; ++i) {
|
for (int32_t i = 0; i < epSet.numOfEps; ++i) {
|
||||||
|
@ -850,8 +729,9 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad) {
|
int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad) {
|
||||||
pLoad->syncState = syncGetMyRole(pMnode->syncMgmt.sync);
|
SSyncState state = syncGetState(pMnode->syncMgmt.sync);
|
||||||
pLoad->syncRestore = pMnode->restored;
|
pLoad->syncState = state.state;
|
||||||
|
pLoad->syncRestore = state.restored;
|
||||||
mTrace("mnode current syncState is %s, syncRestore:%d", syncStr(pLoad->syncState), pLoad->syncRestore);
|
mTrace("mnode current syncState is %s, syncRestore:%d", syncStr(pLoad->syncState), pLoad->syncRestore);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ int32_t mndProcessQueryMsg(SRpcMsg *pMsg) {
|
||||||
code = qWorkerProcessHbMsg(pMnode, pMnode->pQuery, pMsg, 0);
|
code = qWorkerProcessHbMsg(pMnode, pMnode->pQuery, pMsg, 0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
terrno = TSDB_CODE_VND_APP_ERROR;
|
terrno = TSDB_CODE_APP_ERROR;
|
||||||
mError("unknown msg type:%d in query queue", pMsg->msgType);
|
mError("unknown msg type:%d in query queue", pMsg->msgType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) {
|
||||||
for (int32_t i = 0; i < msgNum; ++i) {
|
for (int32_t i = 0; i < msgNum; ++i) {
|
||||||
if (offset >= pMsg->contLen) {
|
if (offset >= pMsg->contLen) {
|
||||||
mError("offset %d is bigger than contLen %d", offset, pMsg->contLen);
|
mError("offset %d is bigger than contLen %d", offset, pMsg->contLen);
|
||||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
terrno = TSDB_CODE_INVALID_MSG_LEN;
|
||||||
taosArrayDestroy(batchRsp);
|
taosArrayDestroy(batchRsp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) {
|
||||||
offset += sizeof(req.msgIdx);
|
offset += sizeof(req.msgIdx);
|
||||||
if (offset >= pMsg->contLen) {
|
if (offset >= pMsg->contLen) {
|
||||||
mError("offset %d is bigger than contLen %d", offset, pMsg->contLen);
|
mError("offset %d is bigger than contLen %d", offset, pMsg->contLen);
|
||||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
terrno = TSDB_CODE_INVALID_MSG_LEN;
|
||||||
taosArrayDestroy(batchRsp);
|
taosArrayDestroy(batchRsp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) {
|
||||||
offset += sizeof(req.msgType);
|
offset += sizeof(req.msgType);
|
||||||
if (offset >= pMsg->contLen) {
|
if (offset >= pMsg->contLen) {
|
||||||
mError("offset %d is bigger than contLen %d", offset, pMsg->contLen);
|
mError("offset %d is bigger than contLen %d", offset, pMsg->contLen);
|
||||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
terrno = TSDB_CODE_INVALID_MSG_LEN;
|
||||||
taosArrayDestroy(batchRsp);
|
taosArrayDestroy(batchRsp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) {
|
||||||
offset += sizeof(req.msgLen);
|
offset += sizeof(req.msgLen);
|
||||||
if (offset >= pMsg->contLen) {
|
if (offset >= pMsg->contLen) {
|
||||||
mError("offset %d is bigger than contLen %d", offset, pMsg->contLen);
|
mError("offset %d is bigger than contLen %d", offset, pMsg->contLen);
|
||||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
terrno = TSDB_CODE_INVALID_MSG_LEN;
|
||||||
taosArrayDestroy(batchRsp);
|
taosArrayDestroy(batchRsp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -487,6 +487,7 @@ int32_t mndScheduleStream(SMnode* pMnode, SStreamObj* pStream) {
|
||||||
qDestroyQueryPlan(pPlan);
|
qDestroyQueryPlan(pPlan);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
pTask->fillHistory = pStream->fillHistory;
|
||||||
mndAddTaskToTaskSet(taskOneLevel, pTask);
|
mndAddTaskToTaskSet(taskOneLevel, pTask);
|
||||||
|
|
||||||
// source
|
// source
|
||||||
|
|
|
@ -557,78 +557,6 @@ static int32_t mndPersistTaskDropReq(STrans *pTrans, SStreamTask *pTask) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
static int32_t mndPersistTaskRecoverReq(STrans *pTrans, SStreamTask *pTask) {
|
|
||||||
SMStreamTaskRecoverReq *pReq = taosMemoryCalloc(1, sizeof(SMStreamTaskRecoverReq));
|
|
||||||
if (pReq == NULL) {
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
pReq->streamId = pTask->streamId;
|
|
||||||
pReq->taskId = pTask->taskId;
|
|
||||||
int32_t len;
|
|
||||||
int32_t code;
|
|
||||||
tEncodeSize(tEncodeSMStreamTaskRecoverReq, pReq, len, code);
|
|
||||||
if (code != 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
void *buf = taosMemoryCalloc(1, sizeof(SMsgHead) + len);
|
|
||||||
if (buf == NULL) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead));
|
|
||||||
SEncoder encoder;
|
|
||||||
tEncoderInit(&encoder, abuf, len);
|
|
||||||
tEncodeSMStreamTaskRecoverReq(&encoder, pReq);
|
|
||||||
((SMsgHead *)buf)->vgId = pTask->nodeId;
|
|
||||||
|
|
||||||
STransAction action = {0};
|
|
||||||
memcpy(&action.epSet, &pTask->epSet, sizeof(SEpSet));
|
|
||||||
action.pCont = buf;
|
|
||||||
action.contLen = sizeof(SMsgHead) + len;
|
|
||||||
action.msgType = TDMT_STREAM_TASK_RECOVER;
|
|
||||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
|
||||||
taosMemoryFree(buf);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t mndRecoverStreamTasks(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream) {
|
|
||||||
if (pStream->isDistributed) {
|
|
||||||
int32_t lv = taosArrayGetSize(pStream->tasks);
|
|
||||||
for (int32_t i = 0; i < lv; i++) {
|
|
||||||
SArray *pTasks = taosArrayGetP(pStream->tasks, i);
|
|
||||||
int32_t sz = taosArrayGetSize(pTasks);
|
|
||||||
SStreamTask *pTask = taosArrayGetP(pTasks, 0);
|
|
||||||
if (pTask->taskLevel == TASK_LEVEL__AGG) {
|
|
||||||
ASSERT(sz == 1);
|
|
||||||
if (mndPersistTaskRecoverReq(pTrans, pTask) < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
int32_t lv = taosArrayGetSize(pStream->tasks);
|
|
||||||
for (int32_t i = 0; i < lv; i++) {
|
|
||||||
SArray *pTasks = taosArrayGetP(pStream->tasks, i);
|
|
||||||
int32_t sz = taosArrayGetSize(pTasks);
|
|
||||||
for (int32_t j = 0; j < sz; j++) {
|
|
||||||
SStreamTask *pTask = taosArrayGetP(pTasks, j);
|
|
||||||
if (pTask->taskLevel != TASK_LEVEL__SOURCE) break;
|
|
||||||
ASSERT(pTask->taskLevel != TASK_LEVEL__SINK);
|
|
||||||
if (mndPersistTaskRecoverReq(pTrans, pTask) < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int32_t mndDropStreamTasks(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream) {
|
int32_t mndDropStreamTasks(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream) {
|
||||||
int32_t lv = taosArrayGetSize(pStream->tasks);
|
int32_t lv = taosArrayGetSize(pStream->tasks);
|
||||||
for (int32_t i = 0; i < lv; i++) {
|
for (int32_t i = 0; i < lv; i++) {
|
||||||
|
|
|
@ -73,11 +73,11 @@ int32_t mndInitSubscribe(SMnode *pMnode) {
|
||||||
.deleteFp = (SdbDeleteFp)mndSubActionDelete,
|
.deleteFp = (SdbDeleteFp)mndSubActionDelete,
|
||||||
};
|
};
|
||||||
|
|
||||||
mndSetMsgHandle(pMnode, TDMT_VND_MQ_VG_CHANGE_RSP, mndTransProcessRsp);
|
mndSetMsgHandle(pMnode, TDMT_VND_TMQ_SUBSCRIBE_RSP, mndTransProcessRsp);
|
||||||
mndSetMsgHandle(pMnode, TDMT_VND_MQ_VG_DELETE_RSP, mndTransProcessRsp);
|
mndSetMsgHandle(pMnode, TDMT_VND_TMQ_DELETE_SUB_RSP, mndTransProcessRsp);
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_MQ_DO_REBALANCE, mndProcessRebalanceReq);
|
mndSetMsgHandle(pMnode, TDMT_MND_TMQ_DO_REBALANCE, mndProcessRebalanceReq);
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_MQ_DROP_CGROUP, mndProcessDropCgroupReq);
|
mndSetMsgHandle(pMnode, TDMT_MND_TMQ_DROP_CGROUP, mndProcessDropCgroupReq);
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_MQ_DROP_CGROUP_RSP, mndTransProcessRsp);
|
mndSetMsgHandle(pMnode, TDMT_MND_TMQ_DROP_CGROUP_RSP, mndTransProcessRsp);
|
||||||
|
|
||||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_SUBSCRIPTIONS, mndRetrieveSubscribe);
|
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_SUBSCRIPTIONS, mndRetrieveSubscribe);
|
||||||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TOPICS, mndCancelGetNextSubscribe);
|
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TOPICS, mndCancelGetNextSubscribe);
|
||||||
|
@ -164,7 +164,7 @@ static int32_t mndPersistSubChangeVgReq(SMnode *pMnode, STrans *pTrans, const SM
|
||||||
action.epSet = mndGetVgroupEpset(pMnode, pVgObj);
|
action.epSet = mndGetVgroupEpset(pMnode, pVgObj);
|
||||||
action.pCont = buf;
|
action.pCont = buf;
|
||||||
action.contLen = tlen;
|
action.contLen = tlen;
|
||||||
action.msgType = TDMT_VND_MQ_VG_CHANGE;
|
action.msgType = TDMT_VND_TMQ_SUBSCRIBE;
|
||||||
|
|
||||||
mndReleaseVgroup(pMnode, pVgObj);
|
mndReleaseVgroup(pMnode, pVgObj);
|
||||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||||
|
@ -920,7 +920,7 @@ int32_t mndDropSubByTopic(SMnode *pMnode, STrans *pTrans, const char *topicName)
|
||||||
action.epSet = pVgEp->epSet;
|
action.epSet = pVgEp->epSet;
|
||||||
action.pCont = pReq;
|
action.pCont = pReq;
|
||||||
action.contLen = sizeof(SMqVDeleteReq);
|
action.contLen = sizeof(SMqVDeleteReq);
|
||||||
action.msgType = TDMT_VND_MQ_VG_DELETE;
|
action.msgType = TDMT_VND_TMQ_DELETE_SUB;
|
||||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||||
taosMemoryFree(pReq);
|
taosMemoryFree(pReq);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -72,25 +72,25 @@ static int32_t mndSyncSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mndSyncCommitMsg(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) {
|
void mndSyncCommitMsg(const SSyncFSM *pFsm, const SRpcMsg *pMsg, const SFsmCbMeta *pMeta) {
|
||||||
SMnode *pMnode = pFsm->data;
|
SMnode *pMnode = pFsm->data;
|
||||||
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
||||||
SSdbRaw *pRaw = pMsg->pCont;
|
SSdbRaw *pRaw = pMsg->pCont;
|
||||||
|
|
||||||
// delete msg handle
|
// delete msg handle
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg rpcMsg = {0};
|
||||||
syncGetAndDelRespRpc(pMnode->syncMgmt.sync, cbMeta.seqNum, &rpcMsg.info);
|
rpcMsg.info = pMsg->info;
|
||||||
|
|
||||||
int32_t transId = sdbGetIdFromRaw(pMnode->pSdb, pRaw);
|
int32_t transId = sdbGetIdFromRaw(pMnode->pSdb, pRaw);
|
||||||
pMgmt->errCode = cbMeta.code;
|
pMgmt->errCode = pMeta->code;
|
||||||
mInfo("trans:%d, is proposed, saved:%d code:0x%x, apply index:%" PRId64 " term:%" PRIu64 " config:%" PRId64
|
mInfo("trans:%d, is proposed, saved:%d code:0x%x, apply index:%" PRId64 " term:%" PRIu64 " config:%" PRId64
|
||||||
" role:%s raw:%p",
|
" role:%s raw:%p",
|
||||||
transId, pMgmt->transId, cbMeta.code, cbMeta.index, cbMeta.term, cbMeta.lastConfigIndex, syncStr(cbMeta.state),
|
transId, pMgmt->transId, pMeta->code, pMeta->index, pMeta->term, pMeta->lastConfigIndex, syncStr(pMeta->state),
|
||||||
pRaw);
|
pRaw);
|
||||||
|
|
||||||
if (pMgmt->errCode == 0) {
|
if (pMgmt->errCode == 0) {
|
||||||
sdbWriteWithoutFree(pMnode->pSdb, pRaw);
|
sdbWriteWithoutFree(pMnode->pSdb, pRaw);
|
||||||
sdbSetApplyInfo(pMnode->pSdb, cbMeta.index, cbMeta.term, cbMeta.lastConfigIndex);
|
sdbSetApplyInfo(pMnode->pSdb, pMeta->index, pMeta->term, pMeta->lastConfigIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
taosWLockLatch(&pMgmt->lock);
|
taosWLockLatch(&pMgmt->lock);
|
||||||
|
@ -120,7 +120,7 @@ void mndSyncCommitMsg(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbM
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndSyncGetSnapshot(struct SSyncFSM *pFsm, SSnapshot *pSnapshot, void *pReaderParam, void **ppReader) {
|
int32_t mndSyncGetSnapshot(const SSyncFSM *pFsm, SSnapshot *pSnapshot, void *pReaderParam, void **ppReader) {
|
||||||
mInfo("start to read snapshot from sdb in atomic way");
|
mInfo("start to read snapshot from sdb in atomic way");
|
||||||
SMnode *pMnode = pFsm->data;
|
SMnode *pMnode = pFsm->data;
|
||||||
return sdbStartRead(pMnode->pSdb, (SSdbIter **)ppReader, &pSnapshot->lastApplyIndex, &pSnapshot->lastApplyTerm,
|
return sdbStartRead(pMnode->pSdb, (SSdbIter **)ppReader, &pSnapshot->lastApplyIndex, &pSnapshot->lastApplyTerm,
|
||||||
|
@ -128,13 +128,13 @@ int32_t mndSyncGetSnapshot(struct SSyncFSM *pFsm, SSnapshot *pSnapshot, void *pR
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndSyncGetSnapshotInfo(struct SSyncFSM *pFsm, SSnapshot *pSnapshot) {
|
int32_t mndSyncGetSnapshotInfo(const SSyncFSM *pFsm, SSnapshot *pSnapshot) {
|
||||||
SMnode *pMnode = pFsm->data;
|
SMnode *pMnode = pFsm->data;
|
||||||
sdbGetCommitInfo(pMnode->pSdb, &pSnapshot->lastApplyIndex, &pSnapshot->lastApplyTerm, &pSnapshot->lastConfigIndex);
|
sdbGetCommitInfo(pMnode->pSdb, &pSnapshot->lastApplyIndex, &pSnapshot->lastApplyTerm, &pSnapshot->lastConfigIndex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mndRestoreFinish(struct SSyncFSM *pFsm) {
|
void mndRestoreFinish(const SSyncFSM *pFsm) {
|
||||||
SMnode *pMnode = pFsm->data;
|
SMnode *pMnode = pFsm->data;
|
||||||
|
|
||||||
if (!pMnode->deploy) {
|
if (!pMnode->deploy) {
|
||||||
|
@ -146,32 +146,30 @@ void mndRestoreFinish(struct SSyncFSM *pFsm) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mndReConfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReConfigCbMeta *cbMeta) {}
|
int32_t mndSnapshotStartRead(const SSyncFSM *pFsm, void *pParam, void **ppReader) {
|
||||||
|
|
||||||
int32_t mndSnapshotStartRead(struct SSyncFSM *pFsm, void *pParam, void **ppReader) {
|
|
||||||
mInfo("start to read snapshot from sdb");
|
mInfo("start to read snapshot from sdb");
|
||||||
SMnode *pMnode = pFsm->data;
|
SMnode *pMnode = pFsm->data;
|
||||||
return sdbStartRead(pMnode->pSdb, (SSdbIter **)ppReader, NULL, NULL, NULL);
|
return sdbStartRead(pMnode->pSdb, (SSdbIter **)ppReader, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndSnapshotStopRead(struct SSyncFSM *pFsm, void *pReader) {
|
int32_t mndSnapshotStopRead(const SSyncFSM *pFsm, void *pReader) {
|
||||||
mInfo("stop to read snapshot from sdb");
|
mInfo("stop to read snapshot from sdb");
|
||||||
SMnode *pMnode = pFsm->data;
|
SMnode *pMnode = pFsm->data;
|
||||||
return sdbStopRead(pMnode->pSdb, pReader);
|
return sdbStopRead(pMnode->pSdb, pReader);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndSnapshotDoRead(struct SSyncFSM *pFsm, void *pReader, void **ppBuf, int32_t *len) {
|
int32_t mndSnapshotDoRead(const SSyncFSM *pFsm, void *pReader, void **ppBuf, int32_t *len) {
|
||||||
SMnode *pMnode = pFsm->data;
|
SMnode *pMnode = pFsm->data;
|
||||||
return sdbDoRead(pMnode->pSdb, pReader, ppBuf, len);
|
return sdbDoRead(pMnode->pSdb, pReader, ppBuf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndSnapshotStartWrite(struct SSyncFSM *pFsm, void *pParam, void **ppWriter) {
|
int32_t mndSnapshotStartWrite(const SSyncFSM *pFsm, void *pParam, void **ppWriter) {
|
||||||
mInfo("start to apply snapshot to sdb");
|
mInfo("start to apply snapshot to sdb");
|
||||||
SMnode *pMnode = pFsm->data;
|
SMnode *pMnode = pFsm->data;
|
||||||
return sdbStartWrite(pMnode->pSdb, (SSdbIter **)ppWriter);
|
return sdbStartWrite(pMnode->pSdb, (SSdbIter **)ppWriter);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndSnapshotStopWrite(struct SSyncFSM *pFsm, void *pWriter, bool isApply, SSnapshot *pSnapshot) {
|
int32_t mndSnapshotStopWrite(const SSyncFSM *pFsm, void *pWriter, bool isApply, SSnapshot *pSnapshot) {
|
||||||
mInfo("stop to apply snapshot to sdb, apply:%d, index:%" PRId64 " term:%" PRIu64 " config:%" PRId64, isApply,
|
mInfo("stop to apply snapshot to sdb, apply:%d, index:%" PRId64 " term:%" PRIu64 " config:%" PRId64, isApply,
|
||||||
pSnapshot->lastApplyIndex, pSnapshot->lastApplyTerm, pSnapshot->lastConfigIndex);
|
pSnapshot->lastApplyIndex, pSnapshot->lastApplyTerm, pSnapshot->lastConfigIndex);
|
||||||
SMnode *pMnode = pFsm->data;
|
SMnode *pMnode = pFsm->data;
|
||||||
|
@ -179,18 +177,12 @@ int32_t mndSnapshotStopWrite(struct SSyncFSM *pFsm, void *pWriter, bool isApply,
|
||||||
pSnapshot->lastConfigIndex);
|
pSnapshot->lastConfigIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndSnapshotDoWrite(struct SSyncFSM *pFsm, void *pWriter, void *pBuf, int32_t len) {
|
int32_t mndSnapshotDoWrite(const SSyncFSM *pFsm, void *pWriter, void *pBuf, int32_t len) {
|
||||||
SMnode *pMnode = pFsm->data;
|
SMnode *pMnode = pFsm->data;
|
||||||
return sdbDoWrite(pMnode->pSdb, pWriter, pBuf, len);
|
return sdbDoWrite(pMnode->pSdb, pWriter, pBuf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mndLeaderTransfer(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) {
|
static void mndBecomeFollower(const SSyncFSM *pFsm) {
|
||||||
SMnode *pMnode = pFsm->data;
|
|
||||||
atomic_store_8(&(pMnode->syncMgmt.leaderTransferFinish), 1);
|
|
||||||
mInfo("vgId:1, mnode leader transfer finish");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mndBecomeFollower(struct SSyncFSM *pFsm) {
|
|
||||||
SMnode *pMnode = pFsm->data;
|
SMnode *pMnode = pFsm->data;
|
||||||
mInfo("vgId:1, become follower");
|
mInfo("vgId:1, become follower");
|
||||||
|
|
||||||
|
@ -205,7 +197,7 @@ static void mndBecomeFollower(struct SSyncFSM *pFsm) {
|
||||||
taosWUnLockLatch(&pMnode->syncMgmt.lock);
|
taosWUnLockLatch(&pMnode->syncMgmt.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mndBecomeLeader(struct SSyncFSM *pFsm) {
|
static void mndBecomeLeader(const SSyncFSM *pFsm) {
|
||||||
mInfo("vgId:1, become leader");
|
mInfo("vgId:1, become leader");
|
||||||
SMnode *pMnode = pFsm->data;
|
SMnode *pMnode = pFsm->data;
|
||||||
}
|
}
|
||||||
|
@ -217,8 +209,8 @@ SSyncFSM *mndSyncMakeFsm(SMnode *pMnode) {
|
||||||
pFsm->FpPreCommitCb = NULL;
|
pFsm->FpPreCommitCb = NULL;
|
||||||
pFsm->FpRollBackCb = NULL;
|
pFsm->FpRollBackCb = NULL;
|
||||||
pFsm->FpRestoreFinishCb = mndRestoreFinish;
|
pFsm->FpRestoreFinishCb = mndRestoreFinish;
|
||||||
pFsm->FpLeaderTransferCb = mndLeaderTransfer;
|
pFsm->FpLeaderTransferCb = NULL;
|
||||||
pFsm->FpReConfigCb = mndReConfig;
|
pFsm->FpReConfigCb = NULL;
|
||||||
pFsm->FpBecomeLeaderCb = mndBecomeLeader;
|
pFsm->FpBecomeLeaderCb = mndBecomeLeader;
|
||||||
pFsm->FpBecomeFollowerCb = mndBecomeFollower;
|
pFsm->FpBecomeFollowerCb = mndBecomeFollower;
|
||||||
pFsm->FpGetSnapshot = mndSyncGetSnapshot;
|
pFsm->FpGetSnapshot = mndSyncGetSnapshot;
|
||||||
|
@ -242,10 +234,13 @@ int32_t mndInitSync(SMnode *pMnode) {
|
||||||
.batchSize = 1,
|
.batchSize = 1,
|
||||||
.vgId = 1,
|
.vgId = 1,
|
||||||
.pWal = pMnode->pWal,
|
.pWal = pMnode->pWal,
|
||||||
.msgcb = NULL,
|
.msgcb = &pMnode->msgCb,
|
||||||
.FpSendMsg = mndSyncSendMsg,
|
.syncSendMSg = mndSyncSendMsg,
|
||||||
.FpEqMsg = mndSyncEqMsg,
|
.syncEqMsg = mndSyncEqMsg,
|
||||||
.FpEqCtrlMsg = mndSyncEqCtrlMsg,
|
.syncEqCtrlMsg = mndSyncEqCtrlMsg,
|
||||||
|
.pingMs = 5000,
|
||||||
|
.electMs = 3000,
|
||||||
|
.heartbeatMs = 500,
|
||||||
};
|
};
|
||||||
|
|
||||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s%ssync", pMnode->path, TD_DIRSEP);
|
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s%ssync", pMnode->path, TD_DIRSEP);
|
||||||
|
@ -269,11 +264,6 @@ int32_t mndInitSync(SMnode *pMnode) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// decrease election timer
|
|
||||||
setPingTimerMS(pMgmt->sync, 5000);
|
|
||||||
setElectTimerMS(pMgmt->sync, 3000);
|
|
||||||
setHeartbeatTimerMS(pMgmt->sync, 500);
|
|
||||||
|
|
||||||
mInfo("mnode-sync is opened, id:%" PRId64, pMgmt->sync);
|
mInfo("mnode-sync is opened, id:%" PRId64, pMgmt->sync);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -289,32 +279,26 @@ void mndCleanupSync(SMnode *pMnode) {
|
||||||
|
|
||||||
int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, int32_t transId) {
|
int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, int32_t transId) {
|
||||||
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
||||||
SRpcMsg req = {.msgType = TDMT_MND_APPLY_MSG, .contLen = sdbGetRawTotalSize(pRaw)};
|
pMgmt->errCode = 0;
|
||||||
if (req.contLen <= 0) {
|
|
||||||
terrno = TSDB_CODE_APP_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
SRpcMsg req = {.msgType = TDMT_MND_APPLY_MSG, .contLen = sdbGetRawTotalSize(pRaw)};
|
||||||
req.pCont = rpcMallocCont(req.contLen);
|
req.pCont = rpcMallocCont(req.contLen);
|
||||||
if (req.pCont == NULL) return -1;
|
if (req.pCont == NULL) return -1;
|
||||||
memcpy(req.pCont, pRaw, req.contLen);
|
memcpy(req.pCont, pRaw, req.contLen);
|
||||||
|
|
||||||
pMgmt->errCode = 0;
|
|
||||||
taosWLockLatch(&pMgmt->lock);
|
taosWLockLatch(&pMgmt->lock);
|
||||||
if (pMgmt->transId != 0) {
|
if (pMgmt->transId != 0) {
|
||||||
mError("trans:%d, can't be proposed since trans:%d alrady waiting for confirm", transId, pMgmt->transId);
|
mError("trans:%d, can't be proposed since trans:%d already waiting for confirm", transId, pMgmt->transId);
|
||||||
taosWUnLockLatch(&pMgmt->lock);
|
taosWUnLockLatch(&pMgmt->lock);
|
||||||
terrno = TSDB_CODE_APP_NOT_READY;
|
terrno = TSDB_CODE_APP_NOT_READY;
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
|
||||||
pMgmt->transId = transId;
|
|
||||||
mInfo("trans:%d, will be proposed", pMgmt->transId);
|
|
||||||
taosWUnLockLatch(&pMgmt->lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool isWeak = false;
|
mInfo("trans:%d, will be proposed", transId);
|
||||||
int32_t code = syncPropose(pMgmt->sync, &req, isWeak);
|
pMgmt->transId = transId;
|
||||||
|
taosWUnLockLatch(&pMgmt->lock);
|
||||||
|
|
||||||
|
int32_t code = syncPropose(pMgmt->sync, &req, false);
|
||||||
if (code == 0) {
|
if (code == 0) {
|
||||||
mInfo("trans:%d, is proposing and wait sem", pMgmt->transId);
|
mInfo("trans:%d, is proposing and wait sem", pMgmt->transId);
|
||||||
tsem_wait(&pMgmt->syncSem);
|
tsem_wait(&pMgmt->syncSem);
|
||||||
|
@ -327,8 +311,8 @@ int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, int32_t transId) {
|
||||||
sdbSetApplyInfo(pMnode->pSdb, req.info.conn.applyIndex, req.info.conn.applyTerm, SYNC_INDEX_INVALID);
|
sdbSetApplyInfo(pMnode->pSdb, req.info.conn.applyIndex, req.info.conn.applyTerm, SYNC_INDEX_INVALID);
|
||||||
code = 0;
|
code = 0;
|
||||||
} else {
|
} else {
|
||||||
taosWLockLatch(&pMgmt->lock);
|
|
||||||
mInfo("trans:%d, failed to proposed since %s", transId, terrstr());
|
mInfo("trans:%d, failed to proposed since %s", transId, terrstr());
|
||||||
|
taosWLockLatch(&pMgmt->lock);
|
||||||
pMgmt->transId = 0;
|
pMgmt->transId = 0;
|
||||||
taosWUnLockLatch(&pMgmt->lock);
|
taosWUnLockLatch(&pMgmt->lock);
|
||||||
if (terrno == TSDB_CODE_SYN_NOT_LEADER) {
|
if (terrno == TSDB_CODE_SYN_NOT_LEADER) {
|
||||||
|
@ -344,13 +328,12 @@ int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, int32_t transId) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMgmt->errCode != 0) terrno = pMgmt->errCode;
|
terrno = pMgmt->errCode;
|
||||||
return pMgmt->errCode;
|
return pMgmt->errCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mndSyncStart(SMnode *pMnode) {
|
void mndSyncStart(SMnode *pMnode) {
|
||||||
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
||||||
syncSetMsgCb(pMgmt->sync, &pMnode->msgCb);
|
|
||||||
syncStart(pMgmt->sync);
|
syncStart(pMgmt->sync);
|
||||||
mInfo("vgId:1, sync started, id:%" PRId64, pMgmt->sync);
|
mInfo("vgId:1, sync started, id:%" PRId64, pMgmt->sync);
|
||||||
}
|
}
|
||||||
|
@ -366,11 +349,15 @@ void mndSyncStop(SMnode *pMnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mndIsLeader(SMnode *pMnode) {
|
bool mndIsLeader(SMnode *pMnode) {
|
||||||
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
SSyncState state = syncGetState(pMnode->syncMgmt.sync);
|
||||||
|
|
||||||
if (!syncIsReady(pMgmt->sync)) {
|
if (state.state != TAOS_SYNC_STATE_LEADER || !state.restored) {
|
||||||
// get terrno from syncIsReady
|
if (state.state != TAOS_SYNC_STATE_LEADER) {
|
||||||
// terrno = TSDB_CODE_SYN_NOT_LEADER;
|
terrno = TSDB_CODE_SYN_NOT_LEADER;
|
||||||
|
} else {
|
||||||
|
terrno = TSDB_CODE_APP_NOT_READY;
|
||||||
|
}
|
||||||
|
mDebug("vgId:1, mnode not ready, state:%s, restore:%d", syncStr(state.state), state.restored);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,11 +53,10 @@ int32_t mndInitTopic(SMnode *pMnode) {
|
||||||
.deleteFp = (SdbDeleteFp)mndTopicActionDelete,
|
.deleteFp = (SdbDeleteFp)mndTopicActionDelete,
|
||||||
};
|
};
|
||||||
|
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_TOPIC, mndProcessCreateTopicReq);
|
mndSetMsgHandle(pMnode, TDMT_MND_TMQ_CREATE_TOPIC, mndProcessCreateTopicReq);
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_DROP_TOPIC, mndProcessDropTopicReq);
|
mndSetMsgHandle(pMnode, TDMT_MND_TMQ_DROP_TOPIC, mndProcessDropTopicReq);
|
||||||
mndSetMsgHandle(pMnode, TDMT_VND_DROP_TOPIC_RSP, mndTransProcessRsp);
|
mndSetMsgHandle(pMnode, TDMT_VND_TMQ_ADD_CHECKINFO_RSP, mndTransProcessRsp);
|
||||||
mndSetMsgHandle(pMnode, TDMT_VND_ADD_CHECK_INFO_RSP, mndTransProcessRsp);
|
mndSetMsgHandle(pMnode, TDMT_VND_TMQ_DEL_CHECKINFO_RSP, mndTransProcessRsp);
|
||||||
mndSetMsgHandle(pMnode, TDMT_VND_DELETE_CHECK_INFO_RSP, mndTransProcessRsp);
|
|
||||||
|
|
||||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TOPICS, mndRetrieveTopic);
|
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TOPICS, mndRetrieveTopic);
|
||||||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TOPICS, mndCancelGetNextTopic);
|
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TOPICS, mndCancelGetNextTopic);
|
||||||
|
@ -506,7 +505,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *
|
||||||
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||||
action.pCont = buf;
|
action.pCont = buf;
|
||||||
action.contLen = sizeof(SMsgHead) + len;
|
action.contLen = sizeof(SMsgHead) + len;
|
||||||
action.msgType = TDMT_VND_ADD_CHECK_INFO;
|
action.msgType = TDMT_VND_TMQ_ADD_CHECKINFO;
|
||||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||||
taosMemoryFree(buf);
|
taosMemoryFree(buf);
|
||||||
sdbRelease(pSdb, pVgroup);
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
@ -715,7 +714,7 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
|
||||||
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||||
action.pCont = buf;
|
action.pCont = buf;
|
||||||
action.contLen = sizeof(SMsgHead) + TSDB_TOPIC_FNAME_LEN;
|
action.contLen = sizeof(SMsgHead) + TSDB_TOPIC_FNAME_LEN;
|
||||||
action.msgType = TDMT_VND_DELETE_CHECK_INFO;
|
action.msgType = TDMT_VND_TMQ_DEL_CHECKINFO;
|
||||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||||
taosMemoryFree(buf);
|
taosMemoryFree(buf);
|
||||||
sdbRelease(pSdb, pVgroup);
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
|
|
@ -265,34 +265,47 @@ static int32_t sdbReadFileImp(SSdb *pSdb) {
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
mError("failed to read sdb file:%s since %s", file, tstrerror(code));
|
mError("failed to read sdb file:%s since %s", file, tstrerror(code));
|
||||||
break;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != readLen) {
|
if (ret != readLen) {
|
||||||
code = TSDB_CODE_FILE_CORRUPTED;
|
code = TSDB_CODE_FILE_CORRUPTED;
|
||||||
mError("failed to read sdb file:%s since %s", file, tstrerror(code));
|
mError("failed to read sdb file:%s since %s, ret:%" PRId64 " != readLen:%d", file, tstrerror(code), ret, readLen);
|
||||||
break;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
readLen = pRaw->dataLen + sizeof(int32_t);
|
readLen = pRaw->dataLen + sizeof(int32_t);
|
||||||
|
if (readLen >= pRaw->dataLen) {
|
||||||
|
SSdbRaw *pNewRaw = taosMemoryMalloc(pRaw->dataLen + TSDB_MAX_MSG_SIZE);
|
||||||
|
if (pNewRaw == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
mError("failed read sdb file since malloc new sdbRaw size:%d failed", pRaw->dataLen + TSDB_MAX_MSG_SIZE);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
mInfo("malloc new sdbRaw size:%d, type:%d", pRaw->dataLen + TSDB_MAX_MSG_SIZE, pRaw->type);
|
||||||
|
memcpy(pNewRaw, pRaw, sizeof(SSdbRaw));
|
||||||
|
sdbFreeRaw(pRaw);
|
||||||
|
pRaw = pNewRaw;
|
||||||
|
}
|
||||||
|
|
||||||
ret = taosReadFile(pFile, pRaw->pData, readLen);
|
ret = taosReadFile(pFile, pRaw->pData, readLen);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
mError("failed to read sdb file:%s since %s", file, tstrerror(code));
|
mError("failed to read sdb file:%s since %s, ret:%" PRId64 " readLen:%d", file, tstrerror(code), ret, readLen);
|
||||||
break;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != readLen) {
|
if (ret != readLen) {
|
||||||
code = TSDB_CODE_FILE_CORRUPTED;
|
code = TSDB_CODE_FILE_CORRUPTED;
|
||||||
mError("failed to read sdb file:%s since %s", file, tstrerror(code));
|
mError("failed to read sdb file:%s since %s, ret:%" PRId64 " != readLen:%d", file, tstrerror(code), ret, readLen);
|
||||||
break;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t totalLen = sizeof(SSdbRaw) + pRaw->dataLen + sizeof(int32_t);
|
int32_t totalLen = sizeof(SSdbRaw) + pRaw->dataLen + sizeof(int32_t);
|
||||||
if ((!taosCheckChecksumWhole((const uint8_t *)pRaw, totalLen)) != 0) {
|
if ((!taosCheckChecksumWhole((const uint8_t *)pRaw, totalLen)) != 0) {
|
||||||
code = TSDB_CODE_CHECKSUM_ERROR;
|
code = TSDB_CODE_CHECKSUM_ERROR;
|
||||||
mError("failed to read sdb file:%s since %s", file, tstrerror(code));
|
mError("failed to read sdb file:%s since %s, readLen:%d", file, tstrerror(code), readLen);
|
||||||
break;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = sdbWriteWithoutFree(pSdb, pRaw);
|
code = sdbWriteWithoutFree(pSdb, pRaw);
|
||||||
|
|
|
@ -90,12 +90,12 @@ int32_t qndProcessQueryMsg(SQnode *pQnode, int64_t ts, SRpcMsg *pMsg) {
|
||||||
code = qWorkerProcessFetchMsg(pQnode, pQnode->pQuery, pMsg, ts);
|
code = qWorkerProcessFetchMsg(pQnode, pQnode->pQuery, pMsg, ts);
|
||||||
break;
|
break;
|
||||||
case TDMT_SCH_CANCEL_TASK:
|
case TDMT_SCH_CANCEL_TASK:
|
||||||
//code = qWorkerProcessCancelMsg(pQnode, pQnode->pQuery, pMsg, ts);
|
// code = qWorkerProcessCancelMsg(pQnode, pQnode->pQuery, pMsg, ts);
|
||||||
break;
|
break;
|
||||||
case TDMT_SCH_DROP_TASK:
|
case TDMT_SCH_DROP_TASK:
|
||||||
code = qWorkerProcessDropMsg(pQnode, pQnode->pQuery, pMsg, ts);
|
code = qWorkerProcessDropMsg(pQnode, pQnode->pQuery, pMsg, ts);
|
||||||
break;
|
break;
|
||||||
case TDMT_VND_CONSUME:
|
case TDMT_VND_TMQ_CONSUME:
|
||||||
// code = tqProcessConsumeReq(pQnode->pTq, pMsg);
|
// code = tqProcessConsumeReq(pQnode->pTq, pMsg);
|
||||||
// break;
|
// break;
|
||||||
case TDMT_SCH_QUERY_HEARTBEAT:
|
case TDMT_SCH_QUERY_HEARTBEAT:
|
||||||
|
@ -103,7 +103,7 @@ int32_t qndProcessQueryMsg(SQnode *pQnode, int64_t ts, SRpcMsg *pMsg) {
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
qError("unknown msg type:%d in qnode queue", pMsg->msgType);
|
qError("unknown msg type:%d in qnode queue", pMsg->msgType);
|
||||||
terrno = TSDB_CODE_VND_APP_ERROR;
|
terrno = TSDB_CODE_APP_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code == 0) return TSDB_CODE_ACTION_IN_PROGRESS;
|
if (code == 0) return TSDB_CODE_ACTION_IN_PROGRESS;
|
||||||
|
|
|
@ -261,18 +261,52 @@ int32_t sndProcessWriteMsg(SSnode *pSnode, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t sndProcessTaskRecoverFinishReq(SSnode *pSnode, SRpcMsg *pMsg) {
|
||||||
|
char *msg = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
|
||||||
|
int32_t msgLen = pMsg->contLen - sizeof(SMsgHead);
|
||||||
|
|
||||||
|
// deserialize
|
||||||
|
SStreamRecoverFinishReq req;
|
||||||
|
|
||||||
|
SDecoder decoder;
|
||||||
|
tDecoderInit(&decoder, msg, msgLen);
|
||||||
|
tDecodeSStreamRecoverFinishReq(&decoder, &req);
|
||||||
|
tDecoderClear(&decoder);
|
||||||
|
|
||||||
|
// find task
|
||||||
|
SStreamTask *pTask = streamMetaGetTask(pSnode->pMeta, req.taskId);
|
||||||
|
if (pTask == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
// do process request
|
||||||
|
if (streamProcessRecoverFinishReq(pTask, req.childId) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t sndProcessTaskRecoverFinishRsp(SSnode *pSnode, SRpcMsg *pMsg) {
|
||||||
|
//
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t sndProcessStreamMsg(SSnode *pSnode, SRpcMsg *pMsg) {
|
int32_t sndProcessStreamMsg(SSnode *pSnode, SRpcMsg *pMsg) {
|
||||||
switch (pMsg->msgType) {
|
switch (pMsg->msgType) {
|
||||||
case TDMT_STREAM_TASK_RUN:
|
case TDMT_STREAM_TASK_RUN:
|
||||||
return sndProcessTaskRunReq(pSnode, pMsg);
|
return sndProcessTaskRunReq(pSnode, pMsg);
|
||||||
case TDMT_STREAM_TASK_DISPATCH:
|
case TDMT_STREAM_TASK_DISPATCH:
|
||||||
return sndProcessTaskDispatchReq(pSnode, pMsg, true);
|
return sndProcessTaskDispatchReq(pSnode, pMsg, true);
|
||||||
case TDMT_STREAM_RETRIEVE:
|
|
||||||
return sndProcessTaskRetrieveReq(pSnode, pMsg);
|
|
||||||
case TDMT_STREAM_TASK_DISPATCH_RSP:
|
case TDMT_STREAM_TASK_DISPATCH_RSP:
|
||||||
return sndProcessTaskDispatchRsp(pSnode, pMsg);
|
return sndProcessTaskDispatchRsp(pSnode, pMsg);
|
||||||
|
case TDMT_STREAM_RETRIEVE:
|
||||||
|
return sndProcessTaskRetrieveReq(pSnode, pMsg);
|
||||||
case TDMT_STREAM_RETRIEVE_RSP:
|
case TDMT_STREAM_RETRIEVE_RSP:
|
||||||
return sndProcessTaskRetrieveRsp(pSnode, pMsg);
|
return sndProcessTaskRetrieveRsp(pSnode, pMsg);
|
||||||
|
case TDMT_STREAM_RECOVER_FINISH:
|
||||||
|
return sndProcessTaskRecoverFinishReq(pSnode, pMsg);
|
||||||
|
case TDMT_STREAM_RECOVER_FINISH_RSP:
|
||||||
|
return sndProcessTaskRecoverFinishRsp(pSnode, pMsg);
|
||||||
default:
|
default:
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,6 @@ int32_t vnodePreprocessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg);
|
||||||
|
|
||||||
int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg *pRsp);
|
int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg *pRsp);
|
||||||
int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
||||||
int32_t vnodeProcessSyncCtrlMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
|
||||||
int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg);
|
int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg);
|
||||||
int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo);
|
int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo);
|
||||||
void vnodeProposeWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs);
|
void vnodeProposeWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs);
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
#define _TD_VND_H_
|
#define _TD_VND_H_
|
||||||
|
|
||||||
#include "sync.h"
|
#include "sync.h"
|
||||||
#include "syncTools.h"
|
|
||||||
#include "ttrace.h"
|
#include "ttrace.h"
|
||||||
#include "vnodeInt.h"
|
#include "vnodeInt.h"
|
||||||
|
|
||||||
|
|
|
@ -176,8 +176,8 @@ int32_t tqCheckColModifiable(STQ* pTq, int64_t tbUid, int32_t colId);
|
||||||
// tq-mq
|
// tq-mq
|
||||||
int32_t tqProcessAddCheckInfoReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
|
int32_t tqProcessAddCheckInfoReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
|
||||||
int32_t tqProcessDelCheckInfoReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
|
int32_t tqProcessDelCheckInfoReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
|
||||||
int32_t tqProcessVgChangeReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
|
int32_t tqProcessSubscribeReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
|
||||||
int32_t tqProcessVgDeleteReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
|
int32_t tqProcessDeleteSubReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
|
||||||
int32_t tqProcessOffsetCommitReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
|
int32_t tqProcessOffsetCommitReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
|
||||||
int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg);
|
int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg);
|
||||||
// tq-stream
|
// tq-stream
|
||||||
|
@ -187,11 +187,15 @@ int32_t tqProcessSubmitReq(STQ* pTq, SSubmitReq* data, int64_t ver);
|
||||||
int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver);
|
int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver);
|
||||||
int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg);
|
int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg);
|
||||||
int32_t tqProcessTaskDispatchReq(STQ* pTq, SRpcMsg* pMsg, bool exec);
|
int32_t tqProcessTaskDispatchReq(STQ* pTq, SRpcMsg* pMsg, bool exec);
|
||||||
int32_t tqProcessTaskRecoverReq(STQ* pTq, SRpcMsg* pMsg);
|
|
||||||
int32_t tqProcessTaskDispatchRsp(STQ* pTq, SRpcMsg* pMsg);
|
int32_t tqProcessTaskDispatchRsp(STQ* pTq, SRpcMsg* pMsg);
|
||||||
int32_t tqProcessTaskRecoverRsp(STQ* pTq, SRpcMsg* pMsg);
|
// int32_t tqProcessTaskRecoverReq(STQ* pTq, SRpcMsg* pMsg);
|
||||||
|
// int32_t tqProcessTaskRecoverRsp(STQ* pTq, SRpcMsg* pMsg);
|
||||||
int32_t tqProcessTaskRetrieveReq(STQ* pTq, SRpcMsg* pMsg);
|
int32_t tqProcessTaskRetrieveReq(STQ* pTq, SRpcMsg* pMsg);
|
||||||
int32_t tqProcessTaskRetrieveRsp(STQ* pTq, SRpcMsg* pMsg);
|
int32_t tqProcessTaskRetrieveRsp(STQ* pTq, SRpcMsg* pMsg);
|
||||||
|
int32_t tqProcessTaskRecover1Req(STQ* pTq, SRpcMsg* pMsg);
|
||||||
|
int32_t tqProcessTaskRecover2Req(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
|
||||||
|
int32_t tqProcessTaskRecoverFinishReq(STQ* pTq, SRpcMsg* pMsg);
|
||||||
|
int32_t tqProcessTaskRecoverFinishRsp(STQ* pTq, SRpcMsg* pMsg);
|
||||||
|
|
||||||
SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchema* pSchema,
|
SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchema* pSchema,
|
||||||
SSchemaWrapper* pTagSchemaWrapper, bool createTb, int64_t suid, const char* stbFullName,
|
SSchemaWrapper* pTagSchemaWrapper, bool createTb, int64_t suid, const char* stbFullName,
|
||||||
|
|
|
@ -53,7 +53,7 @@ static void metaGetEntryInfo(const SMetaEntry *pEntry, SMetaInfo *pInfo) {
|
||||||
static int metaUpdateMetaRsp(tb_uid_t uid, char *tbName, SSchemaWrapper *pSchema, STableMetaRsp *pMetaRsp) {
|
static int metaUpdateMetaRsp(tb_uid_t uid, char *tbName, SSchemaWrapper *pSchema, STableMetaRsp *pMetaRsp) {
|
||||||
pMetaRsp->pSchemas = taosMemoryMalloc(pSchema->nCols * sizeof(SSchema));
|
pMetaRsp->pSchemas = taosMemoryMalloc(pSchema->nCols * sizeof(SSchema));
|
||||||
if (NULL == pMetaRsp->pSchemas) {
|
if (NULL == pMetaRsp->pSchemas) {
|
||||||
terrno = TSDB_CODE_VND_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,7 +498,7 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUi
|
||||||
|
|
||||||
rc = tdbTbGet(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, &pData, &nData);
|
rc = tdbTbGet(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, &pData, &nData);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
terrno = TSDB_CODE_VND_TABLE_NOT_EXIST;
|
terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
uid = *(tb_uid_t *)pData;
|
uid = *(tb_uid_t *)pData;
|
||||||
|
@ -743,7 +743,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
||||||
// search name index
|
// search name index
|
||||||
ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal);
|
ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
terrno = TSDB_CODE_VND_TABLE_NOT_EXIST;
|
terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -824,7 +824,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
||||||
break;
|
break;
|
||||||
case TSDB_ALTER_TABLE_DROP_COLUMN:
|
case TSDB_ALTER_TABLE_DROP_COLUMN:
|
||||||
if (pColumn == NULL) {
|
if (pColumn == NULL) {
|
||||||
terrno = TSDB_CODE_VND_TABLE_COL_NOT_EXISTS;
|
terrno = TSDB_CODE_VND_COL_NOT_EXISTS;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
if (pColumn->colId == 0) {
|
if (pColumn->colId == 0) {
|
||||||
|
@ -846,7 +846,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
||||||
break;
|
break;
|
||||||
case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES:
|
case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES:
|
||||||
if (pColumn == NULL) {
|
if (pColumn == NULL) {
|
||||||
terrno = TSDB_CODE_VND_TABLE_COL_NOT_EXISTS;
|
terrno = TSDB_CODE_VND_COL_NOT_EXISTS;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
if (!IS_VAR_DATA_TYPE(pColumn->type) || pColumn->bytes > pAlterTbReq->colModBytes) {
|
if (!IS_VAR_DATA_TYPE(pColumn->type) || pColumn->bytes > pAlterTbReq->colModBytes) {
|
||||||
|
@ -866,7 +866,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
if (pColumn == NULL) {
|
if (pColumn == NULL) {
|
||||||
terrno = TSDB_CODE_VND_TABLE_COL_NOT_EXISTS;
|
terrno = TSDB_CODE_VND_COL_NOT_EXISTS;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
if (tqCheckColModifiable(pMeta->pVnode->pTq, uid, pColumn->colId) != 0) {
|
if (tqCheckColModifiable(pMeta->pVnode->pTq, uid, pColumn->colId) != 0) {
|
||||||
|
@ -934,7 +934,7 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
|
||||||
// search name index
|
// search name index
|
||||||
ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal);
|
ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
terrno = TSDB_CODE_VND_TABLE_NOT_EXIST;
|
terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -990,7 +990,7 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pColumn == NULL) {
|
if (pColumn == NULL) {
|
||||||
terrno = TSDB_CODE_VND_TABLE_COL_NOT_EXISTS;
|
terrno = TSDB_CODE_VND_COL_NOT_EXISTS;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1093,7 +1093,7 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p
|
||||||
// search name index
|
// search name index
|
||||||
ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal);
|
ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
terrno = TSDB_CODE_VND_TABLE_NOT_EXIST;
|
terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -197,7 +197,7 @@ static int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTsmaStat->pTSma->indexUid != indexUid) {
|
if (pTsmaStat->pTSma->indexUid != indexUid) {
|
||||||
terrno = TSDB_CODE_VND_APP_ERROR;
|
terrno = TSDB_CODE_APP_ERROR;
|
||||||
smaError("vgId:%d, tsma insert for smaIndex %" PRIi64 "(!=%" PRIi64 ") failed since %s", SMA_VID(pSma), indexUid,
|
smaError("vgId:%d, tsma insert for smaIndex %" PRIi64 "(!=%" PRIi64 ") failed since %s", SMA_VID(pSma), indexUid,
|
||||||
pTsmaStat->pTSma->indexUid, tstrerror(terrno));
|
pTsmaStat->pTSma->indexUid, tstrerror(terrno));
|
||||||
goto _err;
|
goto _err;
|
||||||
|
|
|
@ -709,7 +709,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tqProcessVgDeleteReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen) {
|
int32_t tqProcessDeleteSubReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen) {
|
||||||
SMqVDeleteReq* pReq = (SMqVDeleteReq*)msg;
|
SMqVDeleteReq* pReq = (SMqVDeleteReq*)msg;
|
||||||
|
|
||||||
taosWLockLatch(&pTq->pushLock);
|
taosWLockLatch(&pTq->pushLock);
|
||||||
|
@ -767,7 +767,7 @@ int32_t tqProcessDelCheckInfoReq(STQ* pTq, int64_t version, char* msg, int32_t m
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tqProcessVgChangeReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen) {
|
int32_t tqProcessSubscribeReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen) {
|
||||||
SMqRebVgReq req = {0};
|
SMqRebVgReq req = {0};
|
||||||
tDecodeSMqRebVgReq(msg, &req);
|
tDecodeSMqRebVgReq(msg, &req);
|
||||||
// todo lock
|
// todo lock
|
||||||
|
@ -982,25 +982,33 @@ int32_t tqProcessTaskDeployReq(STQ* pTq, int64_t version, char* msg, int32_t msg
|
||||||
|
|
||||||
// 3.go through recover steps to fill history
|
// 3.go through recover steps to fill history
|
||||||
if (pTask->fillHistory) {
|
if (pTask->fillHistory) {
|
||||||
streamSetParamForRecover(pTask);
|
|
||||||
if (pTask->taskLevel == TASK_LEVEL__SOURCE) {
|
if (pTask->taskLevel == TASK_LEVEL__SOURCE) {
|
||||||
|
streamSetParamForRecover(pTask);
|
||||||
streamSourceRecoverPrepareStep1(pTask, version);
|
streamSourceRecoverPrepareStep1(pTask, version);
|
||||||
|
|
||||||
SStreamRecoverStep1Req req;
|
SStreamRecoverStep1Req req;
|
||||||
streamBuildSourceRecover1Req(pTask, &req);
|
streamBuildSourceRecover1Req(pTask, &req);
|
||||||
|
|
||||||
void* serialziedReq = (void*)&req;
|
|
||||||
int32_t len = sizeof(SStreamRecoverStep1Req);
|
int32_t len = sizeof(SStreamRecoverStep1Req);
|
||||||
|
|
||||||
|
void* serializedReq = rpcMallocCont(len);
|
||||||
|
if (serializedReq == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(serializedReq, &req, len);
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {
|
SRpcMsg rpcMsg = {
|
||||||
.contLen = len,
|
.contLen = len,
|
||||||
.pCont = serialziedReq,
|
.pCont = serializedReq,
|
||||||
.msgType = TDMT_VND_STREAM_RECOVER_STEP1,
|
.msgType = TDMT_VND_STREAM_RECOVER_STEP1,
|
||||||
};
|
};
|
||||||
|
|
||||||
tmsgPutToQueue(&pTq->pVnode->msgCb, STREAM_QUEUE, &rpcMsg);
|
if (tmsgPutToQueue(&pTq->pVnode->msgCb, STREAM_QUEUE, &rpcMsg) < 0) {
|
||||||
|
/*ASSERT(0);*/
|
||||||
|
}
|
||||||
|
|
||||||
} else if (pTask->taskLevel == TASK_LEVEL__AGG) {
|
} else if (pTask->taskLevel == TASK_LEVEL__AGG) {
|
||||||
|
streamSetParamForRecover(pTask);
|
||||||
streamAggRecoverPrepare(pTask);
|
streamAggRecoverPrepare(pTask);
|
||||||
} else if (pTask->taskLevel == TASK_LEVEL__SINK) {
|
} else if (pTask->taskLevel == TASK_LEVEL__SINK) {
|
||||||
// do nothing
|
// do nothing
|
||||||
|
@ -1010,8 +1018,11 @@ int32_t tqProcessTaskDeployReq(STQ* pTq, int64_t version, char* msg, int32_t msg
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tqProcessTaskRecover1Req(STQ* pTq, char* msg, int32_t msgLen) {
|
int32_t tqProcessTaskRecover1Req(STQ* pTq, SRpcMsg* pMsg) {
|
||||||
int32_t code;
|
int32_t code;
|
||||||
|
char* msg = pMsg->pCont;
|
||||||
|
int32_t msgLen = pMsg->contLen;
|
||||||
|
|
||||||
SStreamRecoverStep1Req* pReq = (SStreamRecoverStep1Req*)msg;
|
SStreamRecoverStep1Req* pReq = (SStreamRecoverStep1Req*)msg;
|
||||||
SStreamTask* pTask = streamMetaGetTask(pTq->pStreamMeta, pReq->taskId);
|
SStreamTask* pTask = streamMetaGetTask(pTq->pStreamMeta, pReq->taskId);
|
||||||
if (pTask == NULL) {
|
if (pTask == NULL) {
|
||||||
|
@ -1035,16 +1046,24 @@ int32_t tqProcessTaskRecover1Req(STQ* pTq, char* msg, int32_t msgLen) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ASSERT(pReq->taskId == pTask->taskId);
|
||||||
|
|
||||||
// serialize msg
|
// serialize msg
|
||||||
int32_t len = sizeof(SStreamRecoverStep2Req);
|
int32_t len = sizeof(SStreamRecoverStep1Req);
|
||||||
void* serializedReq = (void*)&req;
|
|
||||||
|
void* serializedReq = rpcMallocCont(len);
|
||||||
|
if (serializedReq == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(serializedReq, &req, len);
|
||||||
|
|
||||||
// dispatch msg
|
// dispatch msg
|
||||||
SRpcMsg rpcMsg = {
|
SRpcMsg rpcMsg = {
|
||||||
.code = 0,
|
.code = 0,
|
||||||
.contLen = len,
|
.contLen = len,
|
||||||
.msgType = TDMT_VND_STREAM_RECOVER_STEP2,
|
.msgType = TDMT_VND_STREAM_RECOVER_STEP2,
|
||||||
.pCont = (void*)serializedReq,
|
.pCont = serializedReq,
|
||||||
};
|
};
|
||||||
|
|
||||||
tmsgPutToQueue(&pTq->pVnode->msgCb, WRITE_QUEUE, &rpcMsg);
|
tmsgPutToQueue(&pTq->pVnode->msgCb, WRITE_QUEUE, &rpcMsg);
|
||||||
|
@ -1087,15 +1106,15 @@ int32_t tqProcessTaskRecover2Req(STQ* pTq, int64_t version, char* msg, int32_t m
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tqProcessTaskRecoverFinishReq(STQ* pTq, char* msg, int32_t msgLen) {
|
int32_t tqProcessTaskRecoverFinishReq(STQ* pTq, SRpcMsg* pMsg) {
|
||||||
int32_t code;
|
char* msg = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
|
||||||
|
int32_t msgLen = pMsg->contLen - sizeof(SMsgHead);
|
||||||
|
|
||||||
// deserialize
|
// deserialize
|
||||||
int32_t len;
|
|
||||||
SStreamRecoverFinishReq req;
|
SStreamRecoverFinishReq req;
|
||||||
|
|
||||||
SDecoder decoder;
|
SDecoder decoder;
|
||||||
tDecoderInit(&decoder, msg, sizeof(SStreamRecoverFinishReq));
|
tDecoderInit(&decoder, msg, msgLen);
|
||||||
tDecodeSStreamRecoverFinishReq(&decoder, &req);
|
tDecodeSStreamRecoverFinishReq(&decoder, &req);
|
||||||
tDecoderClear(&decoder);
|
tDecoderClear(&decoder);
|
||||||
|
|
||||||
|
@ -1112,6 +1131,11 @@ int32_t tqProcessTaskRecoverFinishReq(STQ* pTq, char* msg, int32_t msgLen) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t tqProcessTaskRecoverFinishRsp(STQ* pTq, SRpcMsg* pMsg) {
|
||||||
|
//
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) {
|
int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) {
|
||||||
bool failed = false;
|
bool failed = false;
|
||||||
SDecoder* pCoder = &(SDecoder){0};
|
SDecoder* pCoder = &(SDecoder){0};
|
||||||
|
@ -1235,7 +1259,7 @@ int32_t tqProcessSubmitReq(STQ* pTq, SSubmitReq* pReq, int64_t ver) {
|
||||||
pSubmit = streamDataSubmitNew(pReq);
|
pSubmit = streamDataSubmitNew(pReq);
|
||||||
if (pSubmit == NULL) {
|
if (pSubmit == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
qError("failed to create data submit for stream since out of memory");
|
tqError("failed to create data submit for stream since out of memory");
|
||||||
failed = true;
|
failed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1244,18 +1268,21 @@ int32_t tqProcessSubmitReq(STQ* pTq, SSubmitReq* pReq, int64_t ver) {
|
||||||
if (pIter == NULL) break;
|
if (pIter == NULL) break;
|
||||||
SStreamTask* pTask = *(SStreamTask**)pIter;
|
SStreamTask* pTask = *(SStreamTask**)pIter;
|
||||||
if (pTask->taskLevel != TASK_LEVEL__SOURCE) continue;
|
if (pTask->taskLevel != TASK_LEVEL__SOURCE) continue;
|
||||||
if (pTask->taskStatus == TASK_STATUS__RECOVER_PREPARE || pTask->taskStatus == TASK_STATUS__RECOVER1) continue;
|
if (pTask->taskStatus == TASK_STATUS__RECOVER_PREPARE) {
|
||||||
|
tqDebug("skip push task %d, task status %d", pTask->taskId, pTask->taskStatus);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
qDebug("data submit enqueue stream task: %d, ver: %" PRId64, pTask->taskId, ver);
|
tqDebug("data submit enqueue stream task: %d, ver: %" PRId64, pTask->taskId, ver);
|
||||||
|
|
||||||
if (!failed) {
|
if (!failed) {
|
||||||
if (streamTaskInput(pTask, (SStreamQueueItem*)pSubmit) < 0) {
|
if (streamTaskInput(pTask, (SStreamQueueItem*)pSubmit) < 0) {
|
||||||
qError("stream task input failed, task id %d", pTask->taskId);
|
tqError("stream task input failed, task id %d", pTask->taskId);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (streamSchedExec(pTask) < 0) {
|
if (streamSchedExec(pTask) < 0) {
|
||||||
qError("stream task launch failed, task id %d", pTask->taskId);
|
tqError("stream task launch failed, task id %d", pTask->taskId);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1306,33 +1333,6 @@ int32_t tqProcessTaskDispatchReq(STQ* pTq, SRpcMsg* pMsg, bool exec) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
int32_t tqProcessTaskRecoverReq(STQ* pTq, SRpcMsg* pMsg) {
|
|
||||||
SStreamTaskRecoverReq* pReq = pMsg->pCont;
|
|
||||||
int32_t taskId = pReq->taskId;
|
|
||||||
SStreamTask* pTask = streamMetaGetTask(pTq->pStreamMeta, taskId);
|
|
||||||
if (pTask) {
|
|
||||||
streamProcessRecoverReq(pTask, pReq, pMsg);
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t tqProcessTaskRecoverRsp(STQ* pTq, SRpcMsg* pMsg) {
|
|
||||||
SStreamTaskRecoverRsp* pRsp = pMsg->pCont;
|
|
||||||
int32_t taskId = pRsp->rspTaskId;
|
|
||||||
|
|
||||||
SStreamTask* pTask = streamMetaGetTask(pTq->pStreamMeta, taskId);
|
|
||||||
if (pTask) {
|
|
||||||
streamProcessRecoverRsp(pTask, pRsp);
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int32_t tqProcessTaskDispatchRsp(STQ* pTq, SRpcMsg* pMsg) {
|
int32_t tqProcessTaskDispatchRsp(STQ* pTq, SRpcMsg* pMsg) {
|
||||||
SStreamDispatchRsp* pRsp = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
|
SStreamDispatchRsp* pRsp = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
|
||||||
int32_t taskId = pRsp->taskId;
|
int32_t taskId = pRsp->taskId;
|
||||||
|
|
|
@ -199,6 +199,9 @@ int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalCkHea
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tqDebug("vgId:%d, taosx get msg ver %" PRId64 ", type: %s", pTq->pVnode->config.vgId, offset,
|
||||||
|
TMSG_INFO((*ppCkHead)->head.msgType));
|
||||||
|
|
||||||
if ((*ppCkHead)->head.msgType == TDMT_VND_SUBMIT) {
|
if ((*ppCkHead)->head.msgType == TDMT_VND_SUBMIT) {
|
||||||
code = walFetchBody(pHandle->pWalReader, ppCkHead);
|
code = walFetchBody(pHandle->pWalReader, ppCkHead);
|
||||||
|
|
||||||
|
@ -216,17 +219,20 @@ int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalCkHea
|
||||||
SWalCont* pHead = &((*ppCkHead)->head);
|
SWalCont* pHead = &((*ppCkHead)->head);
|
||||||
if (IS_META_MSG(pHead->msgType)) {
|
if (IS_META_MSG(pHead->msgType)) {
|
||||||
code = walFetchBody(pHandle->pWalReader, ppCkHead);
|
code = walFetchBody(pHandle->pWalReader, ppCkHead);
|
||||||
|
|
||||||
if (code < 0) {
|
if (code < 0) {
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
*fetchOffset = offset;
|
*fetchOffset = offset;
|
||||||
code = -1;
|
code = -1;
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isValValidForTable(pHandle, pHead)) {
|
if (isValValidForTable(pHandle, pHead)) {
|
||||||
*fetchOffset = offset;
|
*fetchOffset = offset;
|
||||||
code = 0;
|
code = 0;
|
||||||
goto END;
|
goto END;
|
||||||
|
} else {
|
||||||
|
offset++;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -586,8 +592,39 @@ int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd) {
|
||||||
taosHashPut(pExec->execHandle.execDb.pFilterOutTbUid, &tbUid, sizeof(int64_t), NULL, 0);
|
taosHashPut(pExec->execHandle.execDb.pFilterOutTbUid, &tbUid, sizeof(int64_t), NULL, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (pExec->execHandle.subType == TOPIC_SUB_TYPE__TABLE) {
|
||||||
|
if (isAdd) {
|
||||||
|
SArray* qa = taosArrayInit(4, sizeof(tb_uid_t));
|
||||||
|
SMetaReader mr = {0};
|
||||||
|
metaReaderInit(&mr, pTq->pVnode->pMeta, 0);
|
||||||
|
for (int32_t i = 0; i < taosArrayGetSize(tbUidList); ++i) {
|
||||||
|
uint64_t* id = (uint64_t*)taosArrayGet(tbUidList, i);
|
||||||
|
|
||||||
|
int32_t code = metaGetTableEntryByUid(&mr, *id);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("failed to get table meta, uid:%" PRIu64 " code:%s", *id, tstrerror(terrno));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
tDecoderClear(&mr.coder);
|
||||||
|
|
||||||
|
if (mr.me.type != TSDB_CHILD_TABLE || mr.me.ctbEntry.suid != pExec->execHandle.execTb.suid) {
|
||||||
|
tqDebug("table uid %" PRId64 " does not add to tq handle", *id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
tqDebug("table uid %" PRId64 " add to tq handle", *id);
|
||||||
|
taosArrayPush(qa, id);
|
||||||
|
}
|
||||||
|
metaReaderClear(&mr);
|
||||||
|
if (taosArrayGetSize(qa) > 0) {
|
||||||
|
tqReaderAddTbUidList(pExec->execHandle.pExecReader, qa);
|
||||||
|
}
|
||||||
|
taosArrayDestroy(qa);
|
||||||
|
} else {
|
||||||
|
// TODO handle delete table from stb
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// tq update id
|
ASSERT(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
|
@ -684,7 +684,7 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow) {
|
||||||
if (*state->pDataFReader != NULL) {
|
if (*state->pDataFReader != NULL) {
|
||||||
tsdbDataFReaderClose(state->pDataFReader);
|
tsdbDataFReaderClose(state->pDataFReader);
|
||||||
|
|
||||||
resetLastBlockLoadInfo(state->pLoadInfo);
|
// resetLastBlockLoadInfo(state->pLoadInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
code = tsdbDataFReaderOpen(state->pDataFReader, state->pTsdb, pFileSet);
|
code = tsdbDataFReaderOpen(state->pDataFReader, state->pTsdb, pFileSet);
|
||||||
|
@ -764,7 +764,7 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow) {
|
||||||
if (--state->iBlock < 0) {
|
if (--state->iBlock < 0) {
|
||||||
tsdbDataFReaderClose(state->pDataFReader);
|
tsdbDataFReaderClose(state->pDataFReader);
|
||||||
*state->pDataFReader = NULL;
|
*state->pDataFReader = NULL;
|
||||||
resetLastBlockLoadInfo(state->pLoadInfo);
|
// resetLastBlockLoadInfo(state->pLoadInfo);
|
||||||
|
|
||||||
if (state->aBlockIdx) {
|
if (state->aBlockIdx) {
|
||||||
taosArrayDestroy(state->aBlockIdx);
|
taosArrayDestroy(state->aBlockIdx);
|
||||||
|
|
|
@ -48,7 +48,7 @@ int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *pKee
|
||||||
}
|
}
|
||||||
|
|
||||||
pTsdb->path = (char *)&pTsdb[1];
|
pTsdb->path = (char *)&pTsdb[1];
|
||||||
sprintf(pTsdb->path, "%s%s%s", pVnode->path, TD_DIRSEP, dir);
|
snprintf(pTsdb->path, TD_PATH_MAX, "%s%s%s", pVnode->path, TD_DIRSEP, dir);
|
||||||
taosRealPath(pTsdb->path, NULL, slen);
|
taosRealPath(pTsdb->path, NULL, slen);
|
||||||
pTsdb->pVnode = pVnode;
|
pTsdb->pVnode = pVnode;
|
||||||
taosThreadRwlockInit(&pTsdb->rwLock, NULL);
|
taosThreadRwlockInit(&pTsdb->rwLock, NULL);
|
||||||
|
|
|
@ -78,6 +78,7 @@ typedef struct SIOCostSummary {
|
||||||
double lastBlockLoadTime;
|
double lastBlockLoadTime;
|
||||||
int64_t composedBlocks;
|
int64_t composedBlocks;
|
||||||
double buildComposedBlockTime;
|
double buildComposedBlockTime;
|
||||||
|
double createScanInfoList;
|
||||||
} SIOCostSummary;
|
} SIOCostSummary;
|
||||||
|
|
||||||
typedef struct SBlockLoadSuppInfo {
|
typedef struct SBlockLoadSuppInfo {
|
||||||
|
@ -137,7 +138,7 @@ typedef struct SReaderStatus {
|
||||||
bool loadFromFile; // check file stage
|
bool loadFromFile; // check file stage
|
||||||
bool composedDataBlock; // the returned data block is a composed block or not
|
bool composedDataBlock; // the returned data block is a composed block or not
|
||||||
SHashObj* pTableMap; // SHash<STableBlockScanInfo>
|
SHashObj* pTableMap; // SHash<STableBlockScanInfo>
|
||||||
STableBlockScanInfo* pTableIter; // table iterator used in building in-memory buffer data blocks.
|
STableBlockScanInfo** pTableIter; // table iterator used in building in-memory buffer data blocks.
|
||||||
SUidOrderCheckInfo uidCheckInfo; // check all table in uid order
|
SUidOrderCheckInfo uidCheckInfo; // check all table in uid order
|
||||||
SFileBlockDumpInfo fBlockDumpInfo;
|
SFileBlockDumpInfo fBlockDumpInfo;
|
||||||
SDFileSet* pCurrentFileset; // current opened file set
|
SDFileSet* pCurrentFileset; // current opened file set
|
||||||
|
@ -146,6 +147,12 @@ typedef struct SReaderStatus {
|
||||||
SDataBlockIter blockIter;
|
SDataBlockIter blockIter;
|
||||||
} SReaderStatus;
|
} SReaderStatus;
|
||||||
|
|
||||||
|
typedef struct SBlockInfoBuf {
|
||||||
|
int32_t currentIndex;
|
||||||
|
SArray* pData;
|
||||||
|
int32_t numPerBucket;
|
||||||
|
} SBlockInfoBuf;
|
||||||
|
|
||||||
struct STsdbReader {
|
struct STsdbReader {
|
||||||
STsdb* pTsdb;
|
STsdb* pTsdb;
|
||||||
uint64_t suid;
|
uint64_t suid;
|
||||||
|
@ -163,9 +170,9 @@ struct STsdbReader {
|
||||||
STSchema* pMemSchema; // the previous schema for in-memory data, to avoid load schema too many times
|
STSchema* pMemSchema; // the previous schema for in-memory data, to avoid load schema too many times
|
||||||
SDataFReader* pFileReader;
|
SDataFReader* pFileReader;
|
||||||
SVersionRange verRange;
|
SVersionRange verRange;
|
||||||
|
SBlockInfoBuf blockInfoBuf;
|
||||||
int32_t step;
|
int32_t step;
|
||||||
STsdbReader* innerReader[2];
|
STsdbReader* innerReader[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
static SFileDataBlockInfo* getCurrentBlockInfo(SDataBlockIter* pBlockIter);
|
static SFileDataBlockInfo* getCurrentBlockInfo(SDataBlockIter* pBlockIter);
|
||||||
|
@ -231,6 +238,50 @@ static int32_t setColumnIdSlotList(STsdbReader* pReader, SSDataBlock* pBlock) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t initBlockScanInfoBuf(SBlockInfoBuf* pBuf, int32_t numOfTables) {
|
||||||
|
int32_t num = numOfTables / pBuf->numPerBucket;
|
||||||
|
int32_t remainder = numOfTables % pBuf->numPerBucket;
|
||||||
|
if (pBuf->pData == NULL) {
|
||||||
|
pBuf->pData = taosArrayInit(num + 1, POINTER_BYTES);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int32_t i = 0; i < num; ++i) {
|
||||||
|
char* p = taosMemoryCalloc(pBuf->numPerBucket, sizeof(STableBlockScanInfo));
|
||||||
|
if (p == NULL) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
taosArrayPush(pBuf->pData, &p);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (remainder > 0) {
|
||||||
|
char* p = taosMemoryCalloc(remainder, sizeof(STableBlockScanInfo));
|
||||||
|
if (p == NULL) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
taosArrayPush(pBuf->pData, &p);
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void clearBlockScanInfoBuf(SBlockInfoBuf* pBuf) {
|
||||||
|
size_t num = taosArrayGetSize(pBuf->pData);
|
||||||
|
for(int32_t i = 0; i < num; ++i) {
|
||||||
|
char** p = taosArrayGet(pBuf->pData, i);
|
||||||
|
taosMemoryFree(*p);
|
||||||
|
}
|
||||||
|
|
||||||
|
taosArrayDestroy(pBuf->pData);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void* getPosInBlockInfoBuf(SBlockInfoBuf* pBuf, int32_t index) {
|
||||||
|
int32_t bucketIndex = index / pBuf->numPerBucket;
|
||||||
|
char** pBucket = taosArrayGet(pBuf->pData, bucketIndex);
|
||||||
|
return (*pBucket) + (index % pBuf->numPerBucket) * sizeof(STableBlockScanInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: speedup the whole processing by preparing the buffer for STableBlockScanInfo in batch model
|
||||||
static SHashObj* createDataBlockScanInfo(STsdbReader* pTsdbReader, const STableKeyInfo* idList, int32_t numOfTables) {
|
static SHashObj* createDataBlockScanInfo(STsdbReader* pTsdbReader, const STableKeyInfo* idList, int32_t numOfTables) {
|
||||||
// allocate buffer in order to load data blocks from file
|
// allocate buffer in order to load data blocks from file
|
||||||
// todo use simple hash instead, optimize the memory consumption
|
// todo use simple hash instead, optimize the memory consumption
|
||||||
|
@ -240,8 +291,24 @@ static SHashObj* createDataBlockScanInfo(STsdbReader* pTsdbReader, const STableK
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t st = taosGetTimestampUs();
|
||||||
|
initBlockScanInfoBuf(&pTsdbReader->blockInfoBuf, numOfTables);
|
||||||
|
|
||||||
for (int32_t j = 0; j < numOfTables; ++j) {
|
for (int32_t j = 0; j < numOfTables; ++j) {
|
||||||
STableBlockScanInfo info = {.lastKey = 0, .uid = idList[j].uid};
|
STableBlockScanInfo* pScanInfo = getPosInBlockInfoBuf(&pTsdbReader->blockInfoBuf, j);
|
||||||
|
pScanInfo->uid = idList[j].uid;
|
||||||
|
if (ASCENDING_TRAVERSE(pTsdbReader->order)) {
|
||||||
|
int64_t skey = pTsdbReader->window.skey;
|
||||||
|
pScanInfo->lastKey = (skey > INT64_MIN) ? (skey - 1) : skey;
|
||||||
|
} else {
|
||||||
|
int64_t ekey = pTsdbReader->window.ekey;
|
||||||
|
pScanInfo->lastKey = (ekey < INT64_MAX) ? (ekey + 1) : ekey;
|
||||||
|
}
|
||||||
|
|
||||||
|
taosHashPut(pTableMap, &pScanInfo->uid, sizeof(uint64_t), &pScanInfo, POINTER_BYTES);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// STableBlockScanInfo info = {.lastKey = 0, .uid = idList[j].uid};
|
||||||
if (ASCENDING_TRAVERSE(pTsdbReader->order)) {
|
if (ASCENDING_TRAVERSE(pTsdbReader->order)) {
|
||||||
int64_t skey = pTsdbReader->window.skey;
|
int64_t skey = pTsdbReader->window.skey;
|
||||||
info.lastKey = (skey > INT64_MIN) ? (skey - 1) : skey;
|
info.lastKey = (skey > INT64_MIN) ? (skey - 1) : skey;
|
||||||
|
@ -251,28 +318,33 @@ static SHashObj* createDataBlockScanInfo(STsdbReader* pTsdbReader, const STableK
|
||||||
}
|
}
|
||||||
|
|
||||||
taosHashPut(pTableMap, &info.uid, sizeof(uint64_t), &info, sizeof(info));
|
taosHashPut(pTableMap, &info.uid, sizeof(uint64_t), &info, sizeof(info));
|
||||||
tsdbDebug("%p check table uid:%" PRId64 " from lastKey:%" PRId64 " %s", pTsdbReader, info.uid, info.lastKey,
|
#endif
|
||||||
|
|
||||||
|
tsdbTrace("%p check table uid:%" PRId64 " from lastKey:%" PRId64 " %s", pTsdbReader, pScanInfo->uid, pScanInfo->lastKey,
|
||||||
pTsdbReader->idStr);
|
pTsdbReader->idStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbDebug("%p create %d tables scan-info, size:%.2f Kb, %s", pTsdbReader, numOfTables,
|
pTsdbReader->cost.createScanInfoList = (taosGetTimestampUs() - st) / 1000.0;
|
||||||
(sizeof(STableBlockScanInfo) * numOfTables) / 1024.0, pTsdbReader->idStr);
|
tsdbDebug("%p create %d tables scan-info, size:%.2f Kb, elapsed time:%.2f ms, %s", pTsdbReader, numOfTables,
|
||||||
|
(sizeof(STableBlockScanInfo) * numOfTables) / 1024.0, pTsdbReader->cost.createScanInfoList,
|
||||||
|
pTsdbReader->idStr);
|
||||||
|
|
||||||
return pTableMap;
|
return pTableMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void resetDataBlockScanInfo(SHashObj* pTableMap, int64_t ts) {
|
static void resetAllDataBlockScanInfo(SHashObj* pTableMap, int64_t ts) {
|
||||||
STableBlockScanInfo* p = NULL;
|
STableBlockScanInfo** p = NULL;
|
||||||
|
|
||||||
while ((p = taosHashIterate(pTableMap, p)) != NULL) {
|
while ((p = taosHashIterate(pTableMap, p)) != NULL) {
|
||||||
p->iterInit = false;
|
STableBlockScanInfo* pInfo = *(STableBlockScanInfo**) p;
|
||||||
p->iiter.hasVal = false;
|
|
||||||
if (p->iter.iter != NULL) {
|
pInfo->iterInit = false;
|
||||||
p->iter.iter = tsdbTbDataIterDestroy(p->iter.iter);
|
pInfo->iiter.hasVal = false;
|
||||||
|
if (pInfo->iter.iter != NULL) {
|
||||||
|
pInfo->iter.iter = tsdbTbDataIterDestroy(pInfo->iter.iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
p->delSkyline = taosArrayDestroy(p->delSkyline);
|
pInfo->delSkyline = taosArrayDestroy(pInfo->delSkyline);
|
||||||
p->lastKey = ts;
|
pInfo->lastKey = ts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,10 +365,10 @@ static void clearBlockScanInfo(STableBlockScanInfo* p) {
|
||||||
tMapDataClear(&p->mapData);
|
tMapDataClear(&p->mapData);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void destroyBlockScanInfo(SHashObj* pTableMap) {
|
static void destroyAllBlockScanInfo(SHashObj* pTableMap) {
|
||||||
STableBlockScanInfo* p = NULL;
|
void* p = NULL;
|
||||||
while ((p = taosHashIterate(pTableMap, p)) != NULL) {
|
while ((p = taosHashIterate(pTableMap, p)) != NULL) {
|
||||||
clearBlockScanInfo(p);
|
clearBlockScanInfo(*(STableBlockScanInfo**)p);
|
||||||
}
|
}
|
||||||
|
|
||||||
taosHashCleanup(pTableMap);
|
taosHashCleanup(pTableMap);
|
||||||
|
@ -501,7 +573,7 @@ static int32_t tsdbReaderCreate(SVnode* pVnode, SQueryTableDataCond* pCond, STsd
|
||||||
pReader->verRange = getQueryVerRange(pVnode, pCond, level);
|
pReader->verRange = getQueryVerRange(pVnode, pCond, level);
|
||||||
pReader->type = pCond->type;
|
pReader->type = pCond->type;
|
||||||
pReader->window = updateQueryTimeWindow(pReader->pTsdb, &pCond->twindows);
|
pReader->window = updateQueryTimeWindow(pReader->pTsdb, &pCond->twindows);
|
||||||
|
pReader->blockInfoBuf.numPerBucket = 1000; // 1000 tables per bucket
|
||||||
ASSERT(pCond->numOfCols > 0);
|
ASSERT(pCond->numOfCols > 0);
|
||||||
|
|
||||||
limitOutputBufferSize(pCond, &pReader->capacity);
|
limitOutputBufferSize(pCond, &pReader->capacity);
|
||||||
|
@ -572,7 +644,7 @@ static int32_t doLoadBlockIndex(STsdbReader* pReader, SDataFReader* pFileReader,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
STableBlockScanInfo* pScanInfo = p;
|
STableBlockScanInfo* pScanInfo = *(STableBlockScanInfo**)p;
|
||||||
if (pScanInfo->pBlockList == NULL) {
|
if (pScanInfo->pBlockList == NULL) {
|
||||||
pScanInfo->pBlockList = taosArrayInit(4, sizeof(SBlockIndex));
|
pScanInfo->pBlockList = taosArrayInit(4, sizeof(SBlockIndex));
|
||||||
}
|
}
|
||||||
|
@ -592,7 +664,7 @@ _end:
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cleanupTableScanInfo(SHashObj* pTableMap) {
|
static void cleanupTableScanInfo(SHashObj* pTableMap) {
|
||||||
STableBlockScanInfo* px = NULL;
|
STableBlockScanInfo** px = NULL;
|
||||||
while (1) {
|
while (1) {
|
||||||
px = taosHashIterate(pTableMap, px);
|
px = taosHashIterate(pTableMap, px);
|
||||||
if (px == NULL) {
|
if (px == NULL) {
|
||||||
|
@ -600,8 +672,8 @@ static void cleanupTableScanInfo(SHashObj* pTableMap) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset the index in last block when handing a new file
|
// reset the index in last block when handing a new file
|
||||||
tMapDataClear(&px->mapData);
|
tMapDataClear(&(*px)->mapData);
|
||||||
taosArrayClear(px->pBlockList);
|
taosArrayClear((*px)->pBlockList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -616,7 +688,8 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN
|
||||||
for (int32_t i = 0; i < numOfTables; ++i) {
|
for (int32_t i = 0; i < numOfTables; ++i) {
|
||||||
SBlockIdx* pBlockIdx = taosArrayGet(pIndexList, i);
|
SBlockIdx* pBlockIdx = taosArrayGet(pIndexList, i);
|
||||||
|
|
||||||
STableBlockScanInfo* pScanInfo = taosHashGet(pReader->status.pTableMap, &pBlockIdx->uid, sizeof(int64_t));
|
STableBlockScanInfo* pScanInfo =
|
||||||
|
*(STableBlockScanInfo**)taosHashGet(pReader->status.pTableMap, &pBlockIdx->uid, sizeof(int64_t));
|
||||||
|
|
||||||
tMapDataReset(&pScanInfo->mapData);
|
tMapDataReset(&pScanInfo->mapData);
|
||||||
tsdbReadDataBlk(pReader->pFileReader, pBlockIdx, &pScanInfo->mapData);
|
tsdbReadDataBlk(pReader->pFileReader, pBlockIdx, &pScanInfo->mapData);
|
||||||
|
@ -1064,14 +1137,14 @@ static int32_t fileDataBlockOrderCompar(const void* pLeft, const void* pRight, v
|
||||||
static int32_t doSetCurrentBlock(SDataBlockIter* pBlockIter, const char* idStr) {
|
static int32_t doSetCurrentBlock(SDataBlockIter* pBlockIter, const char* idStr) {
|
||||||
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(pBlockIter);
|
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(pBlockIter);
|
||||||
if (pBlockInfo != NULL) {
|
if (pBlockInfo != NULL) {
|
||||||
STableBlockScanInfo* pScanInfo = taosHashGet(pBlockIter->pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid));
|
STableBlockScanInfo** pScanInfo = taosHashGet(pBlockIter->pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid));
|
||||||
if (pScanInfo == NULL) {
|
if (pScanInfo == NULL) {
|
||||||
tsdbError("failed to locate the uid:%" PRIu64 " in query table uid list, %s", pBlockInfo->uid, idStr);
|
tsdbError("failed to locate the uid:%" PRIu64 " in query table uid list, %s", pBlockInfo->uid, idStr);
|
||||||
return TSDB_CODE_INVALID_PARA;
|
return TSDB_CODE_INVALID_PARA;
|
||||||
}
|
}
|
||||||
|
|
||||||
SBlockIndex* pIndex = taosArrayGet(pScanInfo->pBlockList, pBlockInfo->tbBlockIdx);
|
SBlockIndex* pIndex = taosArrayGet((*pScanInfo)->pBlockList, pBlockInfo->tbBlockIdx);
|
||||||
tMapDataGetItemByIdx(&pScanInfo->mapData, pIndex->ordinalIndex, &pBlockIter->block, tGetDataBlk);
|
tMapDataGetItemByIdx(&(*pScanInfo)->mapData, pIndex->ordinalIndex, &pBlockIter->block, tGetDataBlk);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -1106,7 +1179,7 @@ static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIte
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
STableBlockScanInfo* pTableScanInfo = (STableBlockScanInfo*)ptr;
|
STableBlockScanInfo* pTableScanInfo = *(STableBlockScanInfo**)ptr;
|
||||||
if (pTableScanInfo->pBlockList == NULL || taosArrayGetSize(pTableScanInfo->pBlockList) == 0) {
|
if (pTableScanInfo->pBlockList == NULL || taosArrayGetSize(pTableScanInfo->pBlockList) == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1294,10 +1367,10 @@ static bool keyOverlapFileBlock(TSDBKEY key, SDataBlk* pBlock, SVersionRange* pV
|
||||||
(pBlock->minVer <= pVerRange->maxVer);
|
(pBlock->minVer <= pVerRange->maxVer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool doCheckforDatablockOverlap(STableBlockScanInfo* pBlockScanInfo, const SDataBlk* pBlock) {
|
static bool doCheckforDatablockOverlap(STableBlockScanInfo* pBlockScanInfo, const SDataBlk* pBlock, int32_t startIndex) {
|
||||||
size_t num = taosArrayGetSize(pBlockScanInfo->delSkyline);
|
size_t num = taosArrayGetSize(pBlockScanInfo->delSkyline);
|
||||||
|
|
||||||
for (int32_t i = pBlockScanInfo->fileDelIndex; i < num; i += 1) {
|
for (int32_t i = startIndex; i < num; i += 1) {
|
||||||
TSDBKEY* p = taosArrayGet(pBlockScanInfo->delSkyline, i);
|
TSDBKEY* p = taosArrayGet(pBlockScanInfo->delSkyline, i);
|
||||||
if (p->ts >= pBlock->minKey.ts && p->ts <= pBlock->maxKey.ts) {
|
if (p->ts >= pBlock->minKey.ts && p->ts <= pBlock->maxKey.ts) {
|
||||||
if (p->version >= pBlock->minVer) {
|
if (p->version >= pBlock->minVer) {
|
||||||
|
@ -1336,7 +1409,7 @@ static bool overlapWithDelSkyline(STableBlockScanInfo* pBlockScanInfo, const SDa
|
||||||
|
|
||||||
// version is not overlap
|
// version is not overlap
|
||||||
if (ASCENDING_TRAVERSE(order)) {
|
if (ASCENDING_TRAVERSE(order)) {
|
||||||
return doCheckforDatablockOverlap(pBlockScanInfo, pBlock);
|
return doCheckforDatablockOverlap(pBlockScanInfo, pBlock, pBlockScanInfo->fileDelIndex);
|
||||||
} else {
|
} else {
|
||||||
int32_t index = pBlockScanInfo->fileDelIndex;
|
int32_t index = pBlockScanInfo->fileDelIndex;
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -1348,7 +1421,7 @@ static bool overlapWithDelSkyline(STableBlockScanInfo* pBlockScanInfo, const SDa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return doCheckforDatablockOverlap(pBlockScanInfo, pBlock);
|
return doCheckforDatablockOverlap(pBlockScanInfo, pBlock, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2230,7 +2303,7 @@ static int32_t buildComposedDataBlock(STsdbReader* pReader) {
|
||||||
|
|
||||||
STableBlockScanInfo* pBlockScanInfo = NULL;
|
STableBlockScanInfo* pBlockScanInfo = NULL;
|
||||||
if (pBlockInfo != NULL) {
|
if (pBlockInfo != NULL) {
|
||||||
pBlockScanInfo = taosHashGet(pReader->status.pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid));
|
pBlockScanInfo = *(STableBlockScanInfo**)taosHashGet(pReader->status.pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid));
|
||||||
if (pBlockScanInfo == NULL) {
|
if (pBlockScanInfo == NULL) {
|
||||||
code = TSDB_CODE_INVALID_PARA;
|
code = TSDB_CODE_INVALID_PARA;
|
||||||
tsdbError("failed to locate the uid:%" PRIu64 " in query table uid list, total tables:%d, %s", pBlockInfo->uid,
|
tsdbError("failed to locate the uid:%" PRIu64 " in query table uid list, total tables:%d, %s", pBlockInfo->uid,
|
||||||
|
@ -2253,7 +2326,7 @@ static int32_t buildComposedDataBlock(STsdbReader* pReader) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { // file blocks not exist
|
} else { // file blocks not exist
|
||||||
pBlockScanInfo = pReader->status.pTableIter;
|
pBlockScanInfo = *pReader->status.pTableIter;
|
||||||
}
|
}
|
||||||
|
|
||||||
SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
|
SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
|
||||||
|
@ -2478,7 +2551,7 @@ static void extractOrderedTableUidList(SUidOrderCheckInfo* pOrderCheckInfo, SRea
|
||||||
|
|
||||||
void* p = taosHashIterate(pStatus->pTableMap, NULL);
|
void* p = taosHashIterate(pStatus->pTableMap, NULL);
|
||||||
while (p != NULL) {
|
while (p != NULL) {
|
||||||
STableBlockScanInfo* pScanInfo = p;
|
STableBlockScanInfo* pScanInfo = *(STableBlockScanInfo**) p;
|
||||||
pOrderCheckInfo->tableUidList[index++] = pScanInfo->uid;
|
pOrderCheckInfo->tableUidList[index++] = pScanInfo->uid;
|
||||||
p = taosHashIterate(pStatus->pTableMap, p);
|
p = taosHashIterate(pStatus->pTableMap, p);
|
||||||
}
|
}
|
||||||
|
@ -2552,7 +2625,7 @@ static int32_t doLoadLastBlockSequentially(STsdbReader* pReader) {
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
// load the last data block of current table
|
// load the last data block of current table
|
||||||
STableBlockScanInfo* pScanInfo = pStatus->pTableIter;
|
STableBlockScanInfo* pScanInfo = *(STableBlockScanInfo**) pStatus->pTableIter;
|
||||||
bool hasVal = initLastBlockReader(pLastBlockReader, pScanInfo, pReader);
|
bool hasVal = initLastBlockReader(pLastBlockReader, pScanInfo, pReader);
|
||||||
if (!hasVal) {
|
if (!hasVal) {
|
||||||
bool hasNexTable = moveToNextTable(pOrderedCheckInfo, pStatus);
|
bool hasNexTable = moveToNextTable(pOrderedCheckInfo, pStatus);
|
||||||
|
@ -2590,9 +2663,9 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) {
|
||||||
SLastBlockReader* pLastBlockReader = pReader->status.fileIter.pLastBlockReader;
|
SLastBlockReader* pLastBlockReader = pReader->status.fileIter.pLastBlockReader;
|
||||||
|
|
||||||
if (pBlockInfo != NULL) {
|
if (pBlockInfo != NULL) {
|
||||||
pScanInfo = taosHashGet(pReader->status.pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid));
|
pScanInfo = *(STableBlockScanInfo**)taosHashGet(pReader->status.pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid));
|
||||||
} else {
|
} else {
|
||||||
pScanInfo = pReader->status.pTableIter;
|
pScanInfo = *pReader->status.pTableIter;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pScanInfo == NULL) {
|
if (pScanInfo == NULL) {
|
||||||
|
@ -2660,11 +2733,11 @@ static int32_t buildBlockFromBufferSequentially(STsdbReader* pReader) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STableBlockScanInfo* pBlockScanInfo = pStatus->pTableIter;
|
STableBlockScanInfo** pBlockScanInfo = pStatus->pTableIter;
|
||||||
initMemDataIterator(pBlockScanInfo, pReader);
|
initMemDataIterator(*pBlockScanInfo, pReader);
|
||||||
|
|
||||||
int64_t endKey = (ASCENDING_TRAVERSE(pReader->order)) ? INT64_MAX : INT64_MIN;
|
int64_t endKey = (ASCENDING_TRAVERSE(pReader->order)) ? INT64_MAX : INT64_MIN;
|
||||||
int32_t code = buildDataBlockFromBuf(pReader, pBlockScanInfo, endKey);
|
int32_t code = buildDataBlockFromBuf(pReader, *pBlockScanInfo, endKey);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -3466,18 +3539,23 @@ int32_t buildDataBlockFromBufImpl(STableBlockScanInfo* pBlockScanInfo, int64_t e
|
||||||
// TODO refactor: with createDataBlockScanInfo
|
// TODO refactor: with createDataBlockScanInfo
|
||||||
int32_t tsdbSetTableList(STsdbReader* pReader, const void* pTableList, int32_t num) {
|
int32_t tsdbSetTableList(STsdbReader* pReader, const void* pTableList, int32_t num) {
|
||||||
ASSERT(pReader != NULL);
|
ASSERT(pReader != NULL);
|
||||||
|
int32_t size = taosHashGetSize(pReader->status.pTableMap);
|
||||||
|
|
||||||
STableBlockScanInfo* p = NULL;
|
STableBlockScanInfo** p = NULL;
|
||||||
while ((p = taosHashIterate(pReader->status.pTableMap, p)) != NULL) {
|
while ((p = taosHashIterate(pReader->status.pTableMap, p)) != NULL) {
|
||||||
clearBlockScanInfo(p);
|
clearBlockScanInfo(*p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo handle the case where size is less than the value of num
|
||||||
|
ASSERT(size >= num);
|
||||||
|
|
||||||
taosHashClear(pReader->status.pTableMap);
|
taosHashClear(pReader->status.pTableMap);
|
||||||
|
|
||||||
STableKeyInfo* pList = (STableKeyInfo*) pTableList;
|
STableKeyInfo* pList = (STableKeyInfo*) pTableList;
|
||||||
for(int32_t i = 0; i < num; ++i) {
|
for(int32_t i = 0; i < num; ++i) {
|
||||||
STableBlockScanInfo info = {.lastKey = 0, .uid = pList[i].uid};
|
STableBlockScanInfo* pInfo = getPosInBlockInfoBuf(&pReader->blockInfoBuf, i);
|
||||||
taosHashPut(pReader->status.pTableMap, &info.uid, sizeof(uint64_t), &info, sizeof(info));
|
pInfo->uid = pList[i].uid;
|
||||||
|
taosHashPut(pReader->status.pTableMap, &pInfo->uid, sizeof(uint64_t), &pInfo, POINTER_BYTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TDB_CODE_SUCCESS;
|
return TDB_CODE_SUCCESS;
|
||||||
|
@ -3681,8 +3759,9 @@ void tsdbReaderClose(STsdbReader* pReader) {
|
||||||
cleanupDataBlockIterator(&pReader->status.blockIter);
|
cleanupDataBlockIterator(&pReader->status.blockIter);
|
||||||
|
|
||||||
size_t numOfTables = taosHashGetSize(pReader->status.pTableMap);
|
size_t numOfTables = taosHashGetSize(pReader->status.pTableMap);
|
||||||
destroyBlockScanInfo(pReader->status.pTableMap);
|
destroyAllBlockScanInfo(pReader->status.pTableMap);
|
||||||
blockDataDestroy(pReader->pResBlock);
|
blockDataDestroy(pReader->pResBlock);
|
||||||
|
clearBlockScanInfoBuf(&pReader->blockInfoBuf);
|
||||||
|
|
||||||
if (pReader->pFileReader != NULL) {
|
if (pReader->pFileReader != NULL) {
|
||||||
tsdbDataFReaderClose(&pReader->pFileReader);
|
tsdbDataFReaderClose(&pReader->pFileReader);
|
||||||
|
@ -3704,15 +3783,16 @@ void tsdbReaderClose(STsdbReader* pReader) {
|
||||||
taosMemoryFree(pLReader);
|
taosMemoryFree(pLReader);
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbDebug(
|
tsdbDebug("%p :io-cost summary: head-file:%" PRIu64 ", head-file time:%.2f ms, SMA:%" PRId64
|
||||||
"%p :io-cost summary: head-file:%" PRIu64 ", head-file time:%.2f ms, SMA:%" PRId64
|
" SMA-time:%.2f ms, fileBlocks:%" PRId64
|
||||||
" SMA-time:%.2f ms, fileBlocks:%" PRId64
|
", fileBlocks-load-time:%.2f ms, "
|
||||||
", fileBlocks-load-time:%.2f ms, "
|
"build in-memory-block-time:%.2f ms, lastBlocks:%" PRId64
|
||||||
"build in-memory-block-time:%.2f ms, lastBlocks:%" PRId64 ", lastBlocks-time:%.2f ms, composed-blocks:%" PRId64
|
", lastBlocks-time:%.2f ms, composed-blocks:%" PRId64
|
||||||
", composed-blocks-time:%.2fms, STableBlockScanInfo size:%.2f Kb %s",
|
", composed-blocks-time:%.2fms, STableBlockScanInfo size:%.2f Kb, creatTime:%.2f ms, %s",
|
||||||
pReader, pCost->headFileLoad, pCost->headFileLoadTime, pCost->smaDataLoad, pCost->smaLoadTime, pCost->numOfBlocks,
|
pReader, pCost->headFileLoad, pCost->headFileLoadTime, pCost->smaDataLoad, pCost->smaLoadTime,
|
||||||
pCost->blockLoadTime, pCost->buildmemBlock, pCost->lastBlockLoad, pCost->lastBlockLoadTime, pCost->composedBlocks,
|
pCost->numOfBlocks, pCost->blockLoadTime, pCost->buildmemBlock, pCost->lastBlockLoad,
|
||||||
pCost->buildComposedBlockTime, numOfTables * sizeof(STableBlockScanInfo) / 1000.0, pReader->idStr);
|
pCost->lastBlockLoadTime, pCost->composedBlocks, pCost->buildComposedBlockTime,
|
||||||
|
numOfTables * sizeof(STableBlockScanInfo) / 1000.0, pCost->createScanInfoList, pReader->idStr);
|
||||||
|
|
||||||
taosMemoryFree(pReader->idStr);
|
taosMemoryFree(pReader->idStr);
|
||||||
taosMemoryFree(pReader->pSchema);
|
taosMemoryFree(pReader->pSchema);
|
||||||
|
@ -3765,7 +3845,7 @@ bool tsdbNextDataBlock(STsdbReader* pReader) {
|
||||||
if (pReader->step == EXTERNAL_ROWS_PREV) {
|
if (pReader->step == EXTERNAL_ROWS_PREV) {
|
||||||
// prepare for the main scan
|
// prepare for the main scan
|
||||||
int32_t code = doOpenReaderImpl(pReader);
|
int32_t code = doOpenReaderImpl(pReader);
|
||||||
resetDataBlockScanInfo(pReader->status.pTableMap, pReader->innerReader[0]->window.ekey);
|
resetAllDataBlockScanInfo(pReader->status.pTableMap, pReader->innerReader[0]->window.ekey);
|
||||||
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
|
@ -3782,7 +3862,7 @@ bool tsdbNextDataBlock(STsdbReader* pReader) {
|
||||||
if (pReader->innerReader[1] != NULL && pReader->step == EXTERNAL_ROWS_MAIN) {
|
if (pReader->innerReader[1] != NULL && pReader->step == EXTERNAL_ROWS_MAIN) {
|
||||||
// prepare for the next row scan
|
// prepare for the next row scan
|
||||||
int32_t code = doOpenReaderImpl(pReader->innerReader[1]);
|
int32_t code = doOpenReaderImpl(pReader->innerReader[1]);
|
||||||
resetDataBlockScanInfo(pReader->innerReader[1]->status.pTableMap, pReader->window.ekey);
|
resetAllDataBlockScanInfo(pReader->innerReader[1]->status.pTableMap, pReader->window.ekey);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -3798,7 +3878,7 @@ bool tsdbNextDataBlock(STsdbReader* pReader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tsdbTableNextDataBlock(STsdbReader* pReader, uint64_t uid) {
|
bool tsdbTableNextDataBlock(STsdbReader* pReader, uint64_t uid) {
|
||||||
STableBlockScanInfo* pBlockScanInfo = taosHashGet(pReader->status.pTableMap, &uid, sizeof(uid));
|
STableBlockScanInfo* pBlockScanInfo = *(STableBlockScanInfo**)taosHashGet(pReader->status.pTableMap, &uid, sizeof(uid));
|
||||||
if (pBlockScanInfo == NULL) { // no data block for the table of given uid
|
if (pBlockScanInfo == NULL) { // no data block for the table of given uid
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -3911,7 +3991,7 @@ static SArray* doRetrieveDataBlock(STsdbReader* pReader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(&pStatus->blockIter);
|
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(&pStatus->blockIter);
|
||||||
STableBlockScanInfo* pBlockScanInfo = taosHashGet(pStatus->pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid));
|
STableBlockScanInfo* pBlockScanInfo = *(STableBlockScanInfo**)taosHashGet(pStatus->pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid));
|
||||||
if (pBlockScanInfo == NULL) {
|
if (pBlockScanInfo == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
tsdbError("failed to locate the uid:%" PRIu64 " in query table uid list, total tables:%d, %s", pBlockInfo->uid,
|
tsdbError("failed to locate the uid:%" PRIu64 " in query table uid list, total tables:%d, %s", pBlockInfo->uid,
|
||||||
|
@ -3947,6 +4027,8 @@ int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDataBlockIter* pBlockIter = &pReader->status.blockIter;
|
||||||
|
|
||||||
pReader->order = pCond->order;
|
pReader->order = pCond->order;
|
||||||
pReader->type = TIMEWINDOW_RANGE_CONTAINED;
|
pReader->type = TIMEWINDOW_RANGE_CONTAINED;
|
||||||
pReader->status.loadFromFile = true;
|
pReader->status.loadFromFile = true;
|
||||||
|
@ -3963,13 +4045,12 @@ int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond) {
|
||||||
int32_t numOfTables = taosHashGetSize(pReader->status.pTableMap);
|
int32_t numOfTables = taosHashGetSize(pReader->status.pTableMap);
|
||||||
|
|
||||||
initFilesetIterator(&pReader->status.fileIter, pReader->pReadSnap->fs.aDFileSet, pReader);
|
initFilesetIterator(&pReader->status.fileIter, pReader->pReadSnap->fs.aDFileSet, pReader);
|
||||||
resetDataBlockIterator(&pReader->status.blockIter, pReader->order);
|
resetDataBlockIterator(pBlockIter, pReader->order);
|
||||||
|
|
||||||
int64_t ts = ASCENDING_TRAVERSE(pReader->order) ? pReader->window.skey - 1 : pReader->window.ekey + 1;
|
int64_t ts = ASCENDING_TRAVERSE(pReader->order) ? pReader->window.skey - 1 : pReader->window.ekey + 1;
|
||||||
resetDataBlockScanInfo(pReader->status.pTableMap, ts);
|
resetAllDataBlockScanInfo(pReader->status.pTableMap, ts);
|
||||||
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SDataBlockIter* pBlockIter = &pReader->status.blockIter;
|
|
||||||
|
|
||||||
// no data in files, let's try buffer in memory
|
// no data in files, let's try buffer in memory
|
||||||
if (pReader->status.fileIter.numOfFiles == 0) {
|
if (pReader->status.fileIter.numOfFiles == 0) {
|
||||||
|
@ -4071,7 +4152,7 @@ int64_t tsdbGetNumOfRowsInMemTable(STsdbReader* pReader) {
|
||||||
pStatus->pTableIter = taosHashIterate(pStatus->pTableMap, NULL);
|
pStatus->pTableIter = taosHashIterate(pStatus->pTableMap, NULL);
|
||||||
|
|
||||||
while (pStatus->pTableIter != NULL) {
|
while (pStatus->pTableIter != NULL) {
|
||||||
STableBlockScanInfo* pBlockScanInfo = pStatus->pTableIter;
|
STableBlockScanInfo* pBlockScanInfo = *(STableBlockScanInfo**)pStatus->pTableIter;
|
||||||
|
|
||||||
STbData* d = NULL;
|
STbData* d = NULL;
|
||||||
if (pReader->pTsdb->mem != NULL) {
|
if (pReader->pTsdb->mem != NULL) {
|
||||||
|
|
|
@ -212,6 +212,12 @@ int vnodeCommit(SVnode *pVnode) {
|
||||||
vInfo("vgId:%d, start to commit, commit ID:%" PRId64 " version:%" PRId64, TD_VID(pVnode), pVnode->state.commitID,
|
vInfo("vgId:%d, start to commit, commit ID:%" PRId64 " version:%" PRId64, TD_VID(pVnode), pVnode->state.commitID,
|
||||||
pVnode->state.applied);
|
pVnode->state.applied);
|
||||||
|
|
||||||
|
// persist wal before starting
|
||||||
|
if (walPersist(pVnode->pWal) < 0) {
|
||||||
|
vError("vgId:%d, failed to persist wal since %s", TD_VID(pVnode), terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
pVnode->state.commitTerm = pVnode->state.applyTerm;
|
pVnode->state.commitTerm = pVnode->state.applyTerm;
|
||||||
|
|
||||||
// save info
|
// save info
|
||||||
|
|
|
@ -290,7 +290,7 @@ int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||||
for (int32_t i = 0; i < msgNum; ++i) {
|
for (int32_t i = 0; i < msgNum; ++i) {
|
||||||
if (offset >= pMsg->contLen) {
|
if (offset >= pMsg->contLen) {
|
||||||
qError("vnode offset %d is bigger than contLen %d", offset, pMsg->contLen);
|
qError("vnode offset %d is bigger than contLen %d", offset, pMsg->contLen);
|
||||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
terrno = TSDB_CODE_INVALID_MSG_LEN;
|
||||||
taosArrayDestroy(batchRsp);
|
taosArrayDestroy(batchRsp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,7 @@ int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||||
|
|
||||||
if (offset >= pMsg->contLen) {
|
if (offset >= pMsg->contLen) {
|
||||||
qError("vnode offset %d is bigger than contLen %d", offset, pMsg->contLen);
|
qError("vnode offset %d is bigger than contLen %d", offset, pMsg->contLen);
|
||||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
terrno = TSDB_CODE_INVALID_MSG_LEN;
|
||||||
taosArrayDestroy(batchRsp);
|
taosArrayDestroy(batchRsp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -310,7 +310,7 @@ int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||||
|
|
||||||
if (offset >= pMsg->contLen) {
|
if (offset >= pMsg->contLen) {
|
||||||
qError("vnode offset %d is bigger than contLen %d", offset, pMsg->contLen);
|
qError("vnode offset %d is bigger than contLen %d", offset, pMsg->contLen);
|
||||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
terrno = TSDB_CODE_INVALID_MSG_LEN;
|
||||||
taosArrayDestroy(batchRsp);
|
taosArrayDestroy(batchRsp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -320,7 +320,7 @@ int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||||
|
|
||||||
if (offset >= pMsg->contLen) {
|
if (offset >= pMsg->contLen) {
|
||||||
qError("vnode offset %d is bigger than contLen %d", offset, pMsg->contLen);
|
qError("vnode offset %d is bigger than contLen %d", offset, pMsg->contLen);
|
||||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
terrno = TSDB_CODE_INVALID_MSG_LEN;
|
||||||
taosArrayDestroy(batchRsp);
|
taosArrayDestroy(batchRsp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -362,6 +362,7 @@ int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||||
offset = 0;
|
offset = 0;
|
||||||
|
|
||||||
if (rspSize > MAX_META_BATCH_RSP_SIZE) {
|
if (rspSize > MAX_META_BATCH_RSP_SIZE) {
|
||||||
|
qError("rspSize:%d overload", rspSize);
|
||||||
code = TSDB_CODE_INVALID_MSG_LEN;
|
code = TSDB_CODE_INVALID_MSG_LEN;
|
||||||
goto _exit;
|
goto _exit;
|
||||||
}
|
}
|
||||||
|
@ -414,9 +415,11 @@ _exit:
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
|
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
|
||||||
|
SSyncState state = syncGetState(pVnode->sync);
|
||||||
|
|
||||||
pLoad->vgId = TD_VID(pVnode);
|
pLoad->vgId = TD_VID(pVnode);
|
||||||
pLoad->syncState = syncGetMyRole(pVnode->sync);
|
pLoad->syncState = state.state;
|
||||||
pLoad->syncRestore = pVnode->restored;
|
pLoad->syncRestore = state.restored;
|
||||||
pLoad->cacheUsage = tsdbCacheGetUsage(pVnode);
|
pLoad->cacheUsage = tsdbCacheGetUsage(pVnode);
|
||||||
pLoad->numOfTables = metaGetTbNum(pVnode->pMeta);
|
pLoad->numOfTables = metaGetTbNum(pVnode->pMeta);
|
||||||
pLoad->numOfTimeSeries = metaGetTimeSeriesNum(pVnode->pMeta);
|
pLoad->numOfTimeSeries = metaGetTimeSeriesNum(pVnode->pMeta);
|
||||||
|
|
|
@ -173,7 +173,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp
|
||||||
int32_t ret;
|
int32_t ret;
|
||||||
|
|
||||||
if (!pVnode->inUse) {
|
if (!pVnode->inUse) {
|
||||||
terrno = TSDB_CODE_VND_NOT_SYNCED;
|
terrno = TSDB_CODE_VND_NO_AVAIL_BUFPOOL;
|
||||||
vError("vgId:%d, not ready to write since %s", TD_VID(pVnode), terrstr());
|
vError("vgId:%d, not ready to write since %s", TD_VID(pVnode), terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -228,30 +228,30 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp
|
||||||
if (vnodeProcessBatchDeleteReq(pVnode, version, pReq, len, pRsp) < 0) goto _err;
|
if (vnodeProcessBatchDeleteReq(pVnode, version, pReq, len, pRsp) < 0) goto _err;
|
||||||
break;
|
break;
|
||||||
/* TQ */
|
/* TQ */
|
||||||
case TDMT_VND_MQ_VG_CHANGE:
|
case TDMT_VND_TMQ_SUBSCRIBE:
|
||||||
if (tqProcessVgChangeReq(pVnode->pTq, version, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)),
|
if (tqProcessSubscribeReq(pVnode->pTq, version, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)),
|
||||||
pMsg->contLen - sizeof(SMsgHead)) < 0) {
|
pMsg->contLen - sizeof(SMsgHead)) < 0) {
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TDMT_VND_MQ_VG_DELETE:
|
case TDMT_VND_TMQ_DELETE_SUB:
|
||||||
if (tqProcessVgDeleteReq(pVnode->pTq, version, pMsg->pCont, pMsg->contLen) < 0) {
|
if (tqProcessDeleteSubReq(pVnode->pTq, version, pMsg->pCont, pMsg->contLen) < 0) {
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TDMT_VND_MQ_COMMIT_OFFSET:
|
case TDMT_VND_TMQ_COMMIT_OFFSET:
|
||||||
if (tqProcessOffsetCommitReq(pVnode->pTq, version, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)),
|
if (tqProcessOffsetCommitReq(pVnode->pTq, version, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)),
|
||||||
pMsg->contLen - sizeof(SMsgHead)) < 0) {
|
pMsg->contLen - sizeof(SMsgHead)) < 0) {
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TDMT_VND_ADD_CHECK_INFO:
|
case TDMT_VND_TMQ_ADD_CHECKINFO:
|
||||||
if (tqProcessAddCheckInfoReq(pVnode->pTq, version, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)),
|
if (tqProcessAddCheckInfoReq(pVnode->pTq, version, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)),
|
||||||
pMsg->contLen - sizeof(SMsgHead)) < 0) {
|
pMsg->contLen - sizeof(SMsgHead)) < 0) {
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TDMT_VND_DELETE_CHECK_INFO:
|
case TDMT_VND_TMQ_DEL_CHECKINFO:
|
||||||
if (tqProcessDelCheckInfoReq(pVnode->pTq, version, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)),
|
if (tqProcessDelCheckInfoReq(pVnode->pTq, version, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)),
|
||||||
pMsg->contLen - sizeof(SMsgHead)) < 0) {
|
pMsg->contLen - sizeof(SMsgHead)) < 0) {
|
||||||
goto _err;
|
goto _err;
|
||||||
|
@ -268,6 +268,11 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
case TDMT_VND_STREAM_RECOVER_STEP2: {
|
||||||
|
if (tqProcessTaskRecover2Req(pVnode->pTq, version, pMsg->pCont, pMsg->contLen) < 0) {
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
case TDMT_VND_ALTER_CONFIRM:
|
case TDMT_VND_ALTER_CONFIRM:
|
||||||
vnodeProcessAlterConfirmReq(pVnode, version, pReq, len, pRsp);
|
vnodeProcessAlterConfirmReq(pVnode, version, pReq, len, pRsp);
|
||||||
break;
|
break;
|
||||||
|
@ -280,8 +285,8 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp
|
||||||
case TDMT_VND_COMMIT:
|
case TDMT_VND_COMMIT:
|
||||||
goto _do_commit;
|
goto _do_commit;
|
||||||
default:
|
default:
|
||||||
ASSERT(0);
|
vError("vgId:%d, unprocessed msg, %d", TD_VID(pVnode), pMsg->msgType);
|
||||||
break;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
vTrace("vgId:%d, process %s request, code:0x%x index:%" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), pRsp->code,
|
vTrace("vgId:%d, process %s request, code:0x%x index:%" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), pRsp->code,
|
||||||
|
@ -343,7 +348,7 @@ int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||||
return qWorkerProcessCQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
|
return qWorkerProcessCQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
|
||||||
default:
|
default:
|
||||||
vError("unknown msg type:%d in query queue", pMsg->msgType);
|
vError("unknown msg type:%d in query queue", pMsg->msgType);
|
||||||
return TSDB_CODE_VND_APP_ERROR;
|
return TSDB_CODE_APP_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,14 +361,11 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMsg->msgType == TDMT_VND_CONSUME && !pVnode->restored) {
|
if (pMsg->msgType == TDMT_VND_TMQ_CONSUME && !pVnode->restored) {
|
||||||
vnodeRedirectRpcMsg(pVnode, pMsg);
|
vnodeRedirectRpcMsg(pVnode, pMsg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *msgstr = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
|
|
||||||
int32_t msgLen = pMsg->contLen - sizeof(SMsgHead);
|
|
||||||
|
|
||||||
switch (pMsg->msgType) {
|
switch (pMsg->msgType) {
|
||||||
case TDMT_SCH_FETCH:
|
case TDMT_SCH_FETCH:
|
||||||
case TDMT_SCH_MERGE_FETCH:
|
case TDMT_SCH_MERGE_FETCH:
|
||||||
|
@ -382,7 +384,7 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
|
||||||
return vnodeGetTableCfg(pVnode, pMsg, true);
|
return vnodeGetTableCfg(pVnode, pMsg, true);
|
||||||
case TDMT_VND_BATCH_META:
|
case TDMT_VND_BATCH_META:
|
||||||
return vnodeGetBatchMeta(pVnode, pMsg);
|
return vnodeGetBatchMeta(pVnode, pMsg);
|
||||||
case TDMT_VND_CONSUME:
|
case TDMT_VND_TMQ_CONSUME:
|
||||||
return tqProcessPollReq(pVnode->pTq, pMsg);
|
return tqProcessPollReq(pVnode->pTq, pMsg);
|
||||||
case TDMT_STREAM_TASK_RUN:
|
case TDMT_STREAM_TASK_RUN:
|
||||||
return tqProcessTaskRunReq(pVnode->pTq, pMsg);
|
return tqProcessTaskRunReq(pVnode->pTq, pMsg);
|
||||||
|
@ -390,19 +392,21 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
|
||||||
case TDMT_STREAM_TASK_DISPATCH:
|
case TDMT_STREAM_TASK_DISPATCH:
|
||||||
return tqProcessTaskDispatchReq(pVnode->pTq, pMsg, true);
|
return tqProcessTaskDispatchReq(pVnode->pTq, pMsg, true);
|
||||||
#endif
|
#endif
|
||||||
/*case TDMT_STREAM_TASK_RECOVER:*/
|
|
||||||
/*return tqProcessTaskRecoverReq(pVnode->pTq, pMsg);*/
|
|
||||||
case TDMT_STREAM_RETRIEVE:
|
|
||||||
return tqProcessTaskRetrieveReq(pVnode->pTq, pMsg);
|
|
||||||
case TDMT_STREAM_TASK_DISPATCH_RSP:
|
case TDMT_STREAM_TASK_DISPATCH_RSP:
|
||||||
return tqProcessTaskDispatchRsp(pVnode->pTq, pMsg);
|
return tqProcessTaskDispatchRsp(pVnode->pTq, pMsg);
|
||||||
/*case TDMT_STREAM_TASK_RECOVER_RSP:*/
|
case TDMT_STREAM_RETRIEVE:
|
||||||
/*return tqProcessTaskRecoverRsp(pVnode->pTq, pMsg);*/
|
return tqProcessTaskRetrieveReq(pVnode->pTq, pMsg);
|
||||||
case TDMT_STREAM_RETRIEVE_RSP:
|
case TDMT_STREAM_RETRIEVE_RSP:
|
||||||
return tqProcessTaskRetrieveRsp(pVnode->pTq, pMsg);
|
return tqProcessTaskRetrieveRsp(pVnode->pTq, pMsg);
|
||||||
|
case TDMT_VND_STREAM_RECOVER_STEP1:
|
||||||
|
return tqProcessTaskRecover1Req(pVnode->pTq, pMsg);
|
||||||
|
case TDMT_STREAM_RECOVER_FINISH:
|
||||||
|
return tqProcessTaskRecoverFinishReq(pVnode->pTq, pMsg);
|
||||||
|
case TDMT_STREAM_RECOVER_FINISH_RSP:
|
||||||
|
return tqProcessTaskRecoverFinishRsp(pVnode->pTq, pMsg);
|
||||||
default:
|
default:
|
||||||
vError("unknown msg type:%d in fetch queue", pMsg->msgType);
|
vError("unknown msg type:%d in fetch queue", pMsg->msgType);
|
||||||
return TSDB_CODE_VND_APP_ERROR;
|
return TSDB_CODE_APP_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -768,7 +772,7 @@ static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t version, void *pReq
|
||||||
/* code */
|
/* code */
|
||||||
ret = metaDropTable(pVnode->pMeta, version, pDropTbReq, tbUids, &tbUid);
|
ret = metaDropTable(pVnode->pMeta, version, pDropTbReq, tbUids, &tbUid);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (pDropTbReq->igNotExists && terrno == TSDB_CODE_VND_TABLE_NOT_EXIST) {
|
if (pDropTbReq->igNotExists && terrno == TSDB_CODE_TDB_TABLE_NOT_EXIST) {
|
||||||
dropTbRsp.code = TSDB_CODE_SUCCESS;
|
dropTbRsp.code = TSDB_CODE_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
dropTbRsp.code = terrno;
|
dropTbRsp.code = terrno;
|
||||||
|
|
|
@ -230,142 +230,16 @@ void vnodeApplyWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vnodeProcessSyncCtrlMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
|
||||||
int32_t code = 0;
|
|
||||||
const STraceId *trace = &pMsg->info.traceId;
|
|
||||||
|
|
||||||
if (!syncIsInit()) {
|
|
||||||
vGError("vgId:%d, msg:%p failed to process since sync env not start", pVnode->config.vgId, pMsg);
|
|
||||||
terrno = TSDB_CODE_APP_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SSyncNode *pSyncNode = syncNodeAcquire(pVnode->sync);
|
|
||||||
if (pSyncNode == NULL) {
|
|
||||||
vGError("vgId:%d, msg:%p failed to process since invalid sync node", pVnode->config.vgId, pMsg);
|
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
vGTrace("vgId:%d, sync msg:%p will be processed, type:%s", pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType));
|
|
||||||
|
|
||||||
if (pMsg->msgType == TDMT_SYNC_HEARTBEAT) {
|
|
||||||
SyncHeartbeat *pSyncMsg = syncHeartbeatFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnHeartbeat(pSyncNode, pSyncMsg);
|
|
||||||
syncHeartbeatDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_HEARTBEAT_REPLY) {
|
|
||||||
SyncHeartbeatReply *pSyncMsg = syncHeartbeatReplyFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnHeartbeatReply(pSyncNode, pSyncMsg);
|
|
||||||
syncHeartbeatReplyDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
vGError("vgId:%d, msg:%p failed to process since error msg type:%d", pVnode->config.vgId, pMsg, pMsg->msgType);
|
|
||||||
code = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
vTrace("vgId:%d, sync msg:%p is processed, type:%s code:0x%x", pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType),
|
|
||||||
code);
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
if (code != 0 && terrno == 0) {
|
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
|
||||||
}
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||||
int32_t code = 0;
|
|
||||||
const STraceId *trace = &pMsg->info.traceId;
|
const STraceId *trace = &pMsg->info.traceId;
|
||||||
|
|
||||||
if (!syncIsInit()) {
|
|
||||||
vGError("vgId:%d, msg:%p failed to process since sync env not start", pVnode->config.vgId, pMsg);
|
|
||||||
terrno = TSDB_CODE_APP_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SSyncNode *pSyncNode = syncNodeAcquire(pVnode->sync);
|
|
||||||
if (pSyncNode == NULL) {
|
|
||||||
vGError("vgId:%d, msg:%p failed to process since invalid sync node", pVnode->config.vgId, pMsg);
|
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
vGTrace("vgId:%d, sync msg:%p will be processed, type:%s", pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType));
|
vGTrace("vgId:%d, sync msg:%p will be processed, type:%s", pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType));
|
||||||
|
|
||||||
if (pMsg->msgType == TDMT_SYNC_TIMEOUT) {
|
int32_t code = syncProcessMsg(pVnode->sync, pMsg);
|
||||||
SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pMsg);
|
if (code != 0) {
|
||||||
ASSERT(pSyncMsg != NULL);
|
vGError("vgId:%d, failed to process sync msg:%p type:%s since %s", pVnode->config.vgId, pMsg,
|
||||||
code = syncNodeOnTimer(pSyncNode, pSyncMsg);
|
TMSG_INFO(pMsg->msgType), terrstr());
|
||||||
syncTimeoutDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_PING) {
|
|
||||||
SyncPing *pSyncMsg = syncPingFromRpcMsg2(pMsg);
|
|
||||||
ASSERT(pSyncMsg != NULL);
|
|
||||||
code = syncNodeOnPing(pSyncNode, pSyncMsg);
|
|
||||||
syncPingDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) {
|
|
||||||
SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pMsg);
|
|
||||||
ASSERT(pSyncMsg != NULL);
|
|
||||||
code = syncNodeOnPingReply(pSyncNode, pSyncMsg);
|
|
||||||
syncPingReplyDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
|
||||||
SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pMsg);
|
|
||||||
ASSERT(pSyncMsg != NULL);
|
|
||||||
code = syncNodeOnClientRequest(pSyncNode, pSyncMsg, NULL);
|
|
||||||
syncClientRequestDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) {
|
|
||||||
SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg);
|
|
||||||
ASSERT(pSyncMsg != NULL);
|
|
||||||
code = syncNodeOnRequestVote(pSyncNode, pSyncMsg);
|
|
||||||
syncRequestVoteDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) {
|
|
||||||
SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pMsg);
|
|
||||||
ASSERT(pSyncMsg != NULL);
|
|
||||||
code = syncNodeOnRequestVoteReply(pSyncNode, pSyncMsg);
|
|
||||||
syncRequestVoteReplyDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) {
|
|
||||||
SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pMsg);
|
|
||||||
ASSERT(pSyncMsg != NULL);
|
|
||||||
code = syncNodeOnAppendEntries(pSyncNode, pSyncMsg);
|
|
||||||
syncAppendEntriesDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) {
|
|
||||||
SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg);
|
|
||||||
ASSERT(pSyncMsg != NULL);
|
|
||||||
code = syncNodeOnAppendEntriesReply(pSyncNode, pSyncMsg);
|
|
||||||
syncAppendEntriesReplyDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) {
|
|
||||||
SyncSnapshotSend *pSyncMsg = syncSnapshotSendFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnSnapshot(pSyncNode, pSyncMsg);
|
|
||||||
syncSnapshotSendDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) {
|
|
||||||
SyncSnapshotRsp *pSyncMsg = syncSnapshotRspFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnSnapshotReply(pSyncNode, pSyncMsg);
|
|
||||||
syncSnapshotRspDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_LOCAL_CMD) {
|
|
||||||
SyncLocalCmd *pSyncMsg = syncLocalCmdFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnLocalCmd(pSyncNode, pSyncMsg);
|
|
||||||
syncLocalCmdDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
vGError("vgId:%d, msg:%p failed to process since error msg type:%d", pVnode->config.vgId, pMsg, pMsg->msgType);
|
|
||||||
code = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vTrace("vgId:%d, sync msg:%p is processed, type:%s code:0x%x", pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType),
|
|
||||||
code);
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
if (code != 0 && terrno == 0) {
|
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
|
||||||
}
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,78 +290,61 @@ static int32_t vnodeSyncSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t vnodeSyncGetSnapshot(SSyncFSM *pFsm, SSnapshot *pSnapshot) {
|
static int32_t vnodeSyncGetSnapshot(const SSyncFSM *pFsm, SSnapshot *pSnapshot) {
|
||||||
vnodeGetSnapshot(pFsm->data, pSnapshot);
|
vnodeGetSnapshot(pFsm->data, pSnapshot);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vnodeSyncReconfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReConfigCbMeta *cbMeta) {}
|
static void vnodeSyncApplyMsg(const SSyncFSM *pFsm, const SRpcMsg *pMsg, const SFsmCbMeta *pMeta) {
|
||||||
|
SVnode *pVnode = pFsm->data;
|
||||||
|
|
||||||
static void vnodeSyncCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) {
|
if (pMeta->code == 0) {
|
||||||
if (cbMeta.isWeak == 0) {
|
SRpcMsg rpcMsg = {.msgType = pMsg->msgType, .contLen = pMsg->contLen};
|
||||||
SVnode *pVnode = pFsm->data;
|
rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen);
|
||||||
|
memcpy(rpcMsg.pCont, pMsg->pCont, pMsg->contLen);
|
||||||
|
rpcMsg.info = pMsg->info;
|
||||||
|
rpcMsg.info.conn.applyIndex = pMeta->index;
|
||||||
|
rpcMsg.info.conn.applyTerm = pMeta->term;
|
||||||
|
|
||||||
if (cbMeta.code == 0) {
|
const STraceId *trace = &pMsg->info.traceId;
|
||||||
SRpcMsg rpcMsg = {.msgType = pMsg->msgType, .contLen = pMsg->contLen};
|
vGTrace("vgId:%d, commit-cb is excuted, fsm:%p, index:%" PRId64 ", term:%" PRIu64 ", msg-index:%" PRId64
|
||||||
rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen);
|
|
||||||
memcpy(rpcMsg.pCont, pMsg->pCont, pMsg->contLen);
|
|
||||||
syncGetAndDelRespRpc(pVnode->sync, cbMeta.seqNum, &rpcMsg.info);
|
|
||||||
rpcMsg.info.conn.applyIndex = cbMeta.index;
|
|
||||||
rpcMsg.info.conn.applyTerm = cbMeta.term;
|
|
||||||
|
|
||||||
vInfo("vgId:%d, commit-cb is excuted, fsm:%p, index:%" PRId64 ", term:%" PRIu64 ", msg-index:%" PRId64
|
|
||||||
", weak:%d, code:%d, state:%d %s, type:%s",
|
", weak:%d, code:%d, state:%d %s, type:%s",
|
||||||
syncGetVgId(pVnode->sync), pFsm, cbMeta.index, cbMeta.term, rpcMsg.info.conn.applyIndex, cbMeta.isWeak,
|
pVnode->config.vgId, pFsm, pMeta->index, pMeta->term, rpcMsg.info.conn.applyIndex, pMeta->isWeak,
|
||||||
cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), TMSG_INFO(pMsg->msgType));
|
pMeta->code, pMeta->state, syncStr(pMeta->state), TMSG_INFO(pMsg->msgType));
|
||||||
|
|
||||||
tmsgPutToQueue(&pVnode->msgCb, APPLY_QUEUE, &rpcMsg);
|
tmsgPutToQueue(&pVnode->msgCb, APPLY_QUEUE, &rpcMsg);
|
||||||
} else {
|
} else {
|
||||||
SRpcMsg rsp = {.code = cbMeta.code, .info = pMsg->info};
|
SRpcMsg rsp = {.code = pMeta->code, .info = pMsg->info};
|
||||||
vError("vgId:%d, commit-cb execute error, type:%s, index:%" PRId64 ", error:0x%x %s", syncGetVgId(pVnode->sync),
|
vError("vgId:%d, commit-cb execute error, type:%s, index:%" PRId64 ", error:0x%x %s", pVnode->config.vgId,
|
||||||
TMSG_INFO(pMsg->msgType), cbMeta.index, cbMeta.code, tstrerror(cbMeta.code));
|
TMSG_INFO(pMsg->msgType), pMeta->index, pMeta->code, tstrerror(pMeta->code));
|
||||||
if (rsp.info.handle != NULL) {
|
if (rsp.info.handle != NULL) {
|
||||||
tmsgSendRsp(&rsp);
|
tmsgSendRsp(&rsp);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vnodeSyncPreCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) {
|
static void vnodeSyncCommitMsg(const SSyncFSM *pFsm, const SRpcMsg *pMsg, const SFsmCbMeta *pMeta) {
|
||||||
if (cbMeta.isWeak == 1) {
|
if (pMeta->isWeak == 0) {
|
||||||
SVnode *pVnode = pFsm->data;
|
vnodeSyncApplyMsg(pFsm, pMsg, pMeta);
|
||||||
vTrace("vgId:%d, pre-commit-cb is excuted, fsm:%p, index:%" PRId64 ", weak:%d, code:%d, state:%d %s, type:%s",
|
|
||||||
syncGetVgId(pVnode->sync), pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state,
|
|
||||||
syncUtilState2String(cbMeta.state), TMSG_INFO(pMsg->msgType));
|
|
||||||
|
|
||||||
if (cbMeta.code == 0) {
|
|
||||||
SRpcMsg rpcMsg = {.msgType = pMsg->msgType, .contLen = pMsg->contLen};
|
|
||||||
rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen);
|
|
||||||
memcpy(rpcMsg.pCont, pMsg->pCont, pMsg->contLen);
|
|
||||||
syncGetAndDelRespRpc(pVnode->sync, cbMeta.seqNum, &rpcMsg.info);
|
|
||||||
rpcMsg.info.conn.applyIndex = cbMeta.index;
|
|
||||||
rpcMsg.info.conn.applyTerm = cbMeta.term;
|
|
||||||
tmsgPutToQueue(&pVnode->msgCb, APPLY_QUEUE, &rpcMsg);
|
|
||||||
} else {
|
|
||||||
SRpcMsg rsp = {.code = cbMeta.code, .info = pMsg->info};
|
|
||||||
vError("vgId:%d, pre-commit-cb execute error, type:%s, error:0x%x %s", syncGetVgId(pVnode->sync),
|
|
||||||
TMSG_INFO(pMsg->msgType), cbMeta.code, tstrerror(cbMeta.code));
|
|
||||||
if (rsp.info.handle != NULL) {
|
|
||||||
tmsgSendRsp(&rsp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vnodeSyncRollBackMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) {
|
static void vnodeSyncPreCommitMsg(const SSyncFSM *pFsm, const SRpcMsg *pMsg, const SFsmCbMeta *pMeta) {
|
||||||
|
if (pMeta->isWeak == 1) {
|
||||||
|
vnodeSyncApplyMsg(pFsm, pMsg, pMeta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vnodeSyncRollBackMsg(const SSyncFSM *pFsm, const SRpcMsg *pMsg, const SFsmCbMeta *pMeta) {
|
||||||
SVnode *pVnode = pFsm->data;
|
SVnode *pVnode = pFsm->data;
|
||||||
vTrace("vgId:%d, rollback-cb is excuted, fsm:%p, index:%" PRId64 ", weak:%d, code:%d, state:%d %s, type:%s",
|
vTrace("vgId:%d, rollback-cb is excuted, fsm:%p, index:%" PRId64 ", weak:%d, code:%d, state:%d %s, type:%s",
|
||||||
syncGetVgId(pVnode->sync), pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state,
|
pVnode->config.vgId, pFsm, pMeta->index, pMeta->isWeak, pMeta->code, pMeta->state, syncStr(pMeta->state),
|
||||||
syncUtilState2String(cbMeta.state), TMSG_INFO(pMsg->msgType));
|
TMSG_INFO(pMsg->msgType));
|
||||||
}
|
}
|
||||||
|
|
||||||
#define USE_TSDB_SNAPSHOT
|
#define USE_TSDB_SNAPSHOT
|
||||||
|
|
||||||
static int32_t vnodeSnapshotStartRead(struct SSyncFSM *pFsm, void *pParam, void **ppReader) {
|
static int32_t vnodeSnapshotStartRead(const SSyncFSM *pFsm, void *pParam, void **ppReader) {
|
||||||
#ifdef USE_TSDB_SNAPSHOT
|
#ifdef USE_TSDB_SNAPSHOT
|
||||||
SVnode *pVnode = pFsm->data;
|
SVnode *pVnode = pFsm->data;
|
||||||
SSnapshotParam *pSnapshotParam = pParam;
|
SSnapshotParam *pSnapshotParam = pParam;
|
||||||
|
@ -499,7 +356,7 @@ static int32_t vnodeSnapshotStartRead(struct SSyncFSM *pFsm, void *pParam, void
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t vnodeSnapshotStopRead(struct SSyncFSM *pFsm, void *pReader) {
|
static int32_t vnodeSnapshotStopRead(const SSyncFSM *pFsm, void *pReader) {
|
||||||
#ifdef USE_TSDB_SNAPSHOT
|
#ifdef USE_TSDB_SNAPSHOT
|
||||||
SVnode *pVnode = pFsm->data;
|
SVnode *pVnode = pFsm->data;
|
||||||
int32_t code = vnodeSnapReaderClose(pReader);
|
int32_t code = vnodeSnapReaderClose(pReader);
|
||||||
|
@ -510,7 +367,7 @@ static int32_t vnodeSnapshotStopRead(struct SSyncFSM *pFsm, void *pReader) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t vnodeSnapshotDoRead(struct SSyncFSM *pFsm, void *pReader, void **ppBuf, int32_t *len) {
|
static int32_t vnodeSnapshotDoRead(const SSyncFSM *pFsm, void *pReader, void **ppBuf, int32_t *len) {
|
||||||
#ifdef USE_TSDB_SNAPSHOT
|
#ifdef USE_TSDB_SNAPSHOT
|
||||||
SVnode *pVnode = pFsm->data;
|
SVnode *pVnode = pFsm->data;
|
||||||
int32_t code = vnodeSnapRead(pReader, (uint8_t **)ppBuf, len);
|
int32_t code = vnodeSnapRead(pReader, (uint8_t **)ppBuf, len);
|
||||||
|
@ -529,7 +386,7 @@ static int32_t vnodeSnapshotDoRead(struct SSyncFSM *pFsm, void *pReader, void **
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t vnodeSnapshotStartWrite(struct SSyncFSM *pFsm, void *pParam, void **ppWriter) {
|
static int32_t vnodeSnapshotStartWrite(const SSyncFSM *pFsm, void *pParam, void **ppWriter) {
|
||||||
#ifdef USE_TSDB_SNAPSHOT
|
#ifdef USE_TSDB_SNAPSHOT
|
||||||
SVnode *pVnode = pFsm->data;
|
SVnode *pVnode = pFsm->data;
|
||||||
SSnapshotParam *pSnapshotParam = pParam;
|
SSnapshotParam *pSnapshotParam = pParam;
|
||||||
|
@ -553,7 +410,7 @@ static int32_t vnodeSnapshotStartWrite(struct SSyncFSM *pFsm, void *pParam, void
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t vnodeSnapshotStopWrite(struct SSyncFSM *pFsm, void *pWriter, bool isApply, SSnapshot *pSnapshot) {
|
static int32_t vnodeSnapshotStopWrite(const SSyncFSM *pFsm, void *pWriter, bool isApply, SSnapshot *pSnapshot) {
|
||||||
#ifdef USE_TSDB_SNAPSHOT
|
#ifdef USE_TSDB_SNAPSHOT
|
||||||
SVnode *pVnode = pFsm->data;
|
SVnode *pVnode = pFsm->data;
|
||||||
vInfo("vgId:%d, stop write vnode snapshot, apply:%d, index:%" PRId64 " term:%" PRIu64 " config:%" PRId64,
|
vInfo("vgId:%d, stop write vnode snapshot, apply:%d, index:%" PRId64 " term:%" PRIu64 " config:%" PRId64,
|
||||||
|
@ -568,7 +425,7 @@ static int32_t vnodeSnapshotStopWrite(struct SSyncFSM *pFsm, void *pWriter, bool
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t vnodeSnapshotDoWrite(struct SSyncFSM *pFsm, void *pWriter, void *pBuf, int32_t len) {
|
static int32_t vnodeSnapshotDoWrite(const SSyncFSM *pFsm, void *pWriter, void *pBuf, int32_t len) {
|
||||||
#ifdef USE_TSDB_SNAPSHOT
|
#ifdef USE_TSDB_SNAPSHOT
|
||||||
SVnode *pVnode = pFsm->data;
|
SVnode *pVnode = pFsm->data;
|
||||||
vDebug("vgId:%d, continue write vnode snapshot, len:%d", pVnode->config.vgId, len);
|
vDebug("vgId:%d, continue write vnode snapshot, len:%d", pVnode->config.vgId, len);
|
||||||
|
@ -580,9 +437,7 @@ static int32_t vnodeSnapshotDoWrite(struct SSyncFSM *pFsm, void *pWriter, void *
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vnodeLeaderTransfer(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) {}
|
static void vnodeRestoreFinish(const SSyncFSM *pFsm) {
|
||||||
|
|
||||||
static void vnodeRestoreFinish(struct SSyncFSM *pFsm) {
|
|
||||||
SVnode *pVnode = pFsm->data;
|
SVnode *pVnode = pFsm->data;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
@ -602,7 +457,7 @@ static void vnodeRestoreFinish(struct SSyncFSM *pFsm) {
|
||||||
vDebug("vgId:%d, sync restore finished", pVnode->config.vgId);
|
vDebug("vgId:%d, sync restore finished", pVnode->config.vgId);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vnodeBecomeFollower(struct SSyncFSM *pFsm) {
|
static void vnodeBecomeFollower(const SSyncFSM *pFsm) {
|
||||||
SVnode *pVnode = pFsm->data;
|
SVnode *pVnode = pFsm->data;
|
||||||
vDebug("vgId:%d, become follower", pVnode->config.vgId);
|
vDebug("vgId:%d, become follower", pVnode->config.vgId);
|
||||||
|
|
||||||
|
@ -616,7 +471,7 @@ static void vnodeBecomeFollower(struct SSyncFSM *pFsm) {
|
||||||
taosThreadMutexUnlock(&pVnode->lock);
|
taosThreadMutexUnlock(&pVnode->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vnodeBecomeLeader(struct SSyncFSM *pFsm) {
|
static void vnodeBecomeLeader(const SSyncFSM *pFsm) {
|
||||||
SVnode *pVnode = pFsm->data;
|
SVnode *pVnode = pFsm->data;
|
||||||
vDebug("vgId:%d, become leader", pVnode->config.vgId);
|
vDebug("vgId:%d, become leader", pVnode->config.vgId);
|
||||||
|
|
||||||
|
@ -638,10 +493,10 @@ static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) {
|
||||||
pFsm->FpRollBackCb = vnodeSyncRollBackMsg;
|
pFsm->FpRollBackCb = vnodeSyncRollBackMsg;
|
||||||
pFsm->FpGetSnapshotInfo = vnodeSyncGetSnapshot;
|
pFsm->FpGetSnapshotInfo = vnodeSyncGetSnapshot;
|
||||||
pFsm->FpRestoreFinishCb = vnodeRestoreFinish;
|
pFsm->FpRestoreFinishCb = vnodeRestoreFinish;
|
||||||
pFsm->FpLeaderTransferCb = vnodeLeaderTransfer;
|
pFsm->FpLeaderTransferCb = NULL;
|
||||||
pFsm->FpBecomeLeaderCb = vnodeBecomeLeader;
|
pFsm->FpBecomeLeaderCb = vnodeBecomeLeader;
|
||||||
pFsm->FpBecomeFollowerCb = vnodeBecomeFollower;
|
pFsm->FpBecomeFollowerCb = vnodeBecomeFollower;
|
||||||
pFsm->FpReConfigCb = vnodeSyncReconfig;
|
pFsm->FpReConfigCb = NULL;
|
||||||
pFsm->FpSnapshotStartRead = vnodeSnapshotStartRead;
|
pFsm->FpSnapshotStartRead = vnodeSnapshotStartRead;
|
||||||
pFsm->FpSnapshotStopRead = vnodeSnapshotStopRead;
|
pFsm->FpSnapshotStopRead = vnodeSnapshotStopRead;
|
||||||
pFsm->FpSnapshotDoRead = vnodeSnapshotDoRead;
|
pFsm->FpSnapshotDoRead = vnodeSnapshotDoRead;
|
||||||
|
@ -659,10 +514,13 @@ int32_t vnodeSyncOpen(SVnode *pVnode, char *path) {
|
||||||
.vgId = pVnode->config.vgId,
|
.vgId = pVnode->config.vgId,
|
||||||
.syncCfg = pVnode->config.syncCfg,
|
.syncCfg = pVnode->config.syncCfg,
|
||||||
.pWal = pVnode->pWal,
|
.pWal = pVnode->pWal,
|
||||||
.msgcb = NULL,
|
.msgcb = &pVnode->msgCb,
|
||||||
.FpSendMsg = vnodeSyncSendMsg,
|
.syncSendMSg = vnodeSyncSendMsg,
|
||||||
.FpEqMsg = vnodeSyncEqMsg,
|
.syncEqMsg = vnodeSyncEqMsg,
|
||||||
.FpEqCtrlMsg = vnodeSyncEqCtrlMsg,
|
.syncEqCtrlMsg = vnodeSyncEqCtrlMsg,
|
||||||
|
.pingMs = 5000,
|
||||||
|
.electMs = 4000,
|
||||||
|
.heartbeatMs = 700,
|
||||||
};
|
};
|
||||||
|
|
||||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s%ssync", path, TD_DIRSEP);
|
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s%ssync", path, TD_DIRSEP);
|
||||||
|
@ -681,15 +539,11 @@ int32_t vnodeSyncOpen(SVnode *pVnode, char *path) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
setPingTimerMS(pVnode->sync, 5000);
|
|
||||||
setElectTimerMS(pVnode->sync, 4000);
|
|
||||||
setHeartbeatTimerMS(pVnode->sync, 700);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vnodeSyncStart(SVnode *pVnode) {
|
void vnodeSyncStart(SVnode *pVnode) {
|
||||||
vDebug("vgId:%d, start sync", pVnode->config.vgId);
|
vDebug("vgId:%d, start sync", pVnode->config.vgId);
|
||||||
syncSetMsgCb(pVnode->sync, &pVnode->msgCb);
|
|
||||||
syncStart(pVnode->sync);
|
syncStart(pVnode->sync);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -698,12 +552,21 @@ void vnodeSyncClose(SVnode *pVnode) {
|
||||||
syncStop(pVnode->sync);
|
syncStop(pVnode->sync);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool vnodeIsRoleLeader(SVnode *pVnode) { return syncGetMyRole(pVnode->sync) == TAOS_SYNC_STATE_LEADER; }
|
bool vnodeIsRoleLeader(SVnode *pVnode) {
|
||||||
|
SSyncState state = syncGetState(pVnode->sync);
|
||||||
|
return state.state == TAOS_SYNC_STATE_LEADER;
|
||||||
|
}
|
||||||
|
|
||||||
bool vnodeIsLeader(SVnode *pVnode) {
|
bool vnodeIsLeader(SVnode *pVnode) {
|
||||||
if (!syncIsReady(pVnode->sync)) {
|
SSyncState state = syncGetState(pVnode->sync);
|
||||||
vDebug("vgId:%d, vnode not ready, state:%s, restore:%d", pVnode->config.vgId, syncGetMyRoleStr(pVnode->sync),
|
|
||||||
syncRestoreFinish(pVnode->sync));
|
if (state.state != TAOS_SYNC_STATE_LEADER || !state.restored) {
|
||||||
|
if (state.state != TAOS_SYNC_STATE_LEADER) {
|
||||||
|
terrno = TSDB_CODE_SYN_NOT_LEADER;
|
||||||
|
} else {
|
||||||
|
terrno = TSDB_CODE_APP_NOT_READY;
|
||||||
|
}
|
||||||
|
vDebug("vgId:%d, vnode not ready, state:%s, restore:%d", pVnode->config.vgId, syncStr(state.state), state.restored);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,11 +96,12 @@ typedef struct SColMatchInfo {
|
||||||
int32_t matchType; // determinate the source according to col id or slot id
|
int32_t matchType; // determinate the source according to col id or slot id
|
||||||
} SColMatchInfo;
|
} SColMatchInfo;
|
||||||
|
|
||||||
|
typedef struct SExecTaskInfo SExecTaskInfo;
|
||||||
typedef struct STableListInfo STableListInfo;
|
typedef struct STableListInfo STableListInfo;
|
||||||
struct SqlFunctionCtx;
|
struct SqlFunctionCtx;
|
||||||
|
|
||||||
int32_t createScanTableListInfo(SScanPhysiNode* pScanNode, SNodeList* pGroupTags, bool groupSort, SReadHandle* pHandle,
|
int32_t createScanTableListInfo(SScanPhysiNode* pScanNode, SNodeList* pGroupTags, bool groupSort, SReadHandle* pHandle,
|
||||||
STableListInfo* pTableListInfo, SNode* pTagCond, SNode* pTagIndexCond, const char* id);
|
STableListInfo* pTableListInfo, SNode* pTagCond, SNode* pTagIndexCond, SExecTaskInfo* pTaskInfo);
|
||||||
|
|
||||||
STableListInfo* tableListCreate();
|
STableListInfo* tableListCreate();
|
||||||
void* tableListDestroy(STableListInfo* pTableListInfo);
|
void* tableListDestroy(STableListInfo* pTableListInfo);
|
||||||
|
|
|
@ -89,25 +89,10 @@ typedef struct STableScanAnalyzeInfo SFileBlockLoadRecorder;
|
||||||
typedef struct STaskCostInfo {
|
typedef struct STaskCostInfo {
|
||||||
int64_t created;
|
int64_t created;
|
||||||
int64_t start;
|
int64_t start;
|
||||||
uint64_t loadStatisTime;
|
uint64_t elapsedTime;
|
||||||
uint64_t loadFileBlockTime;
|
double extractListTime;
|
||||||
uint64_t loadDataInCacheTime;
|
double groupIdMapTime;
|
||||||
uint64_t loadStatisSize;
|
|
||||||
uint64_t loadFileBlockSize;
|
|
||||||
uint64_t loadDataInCacheSize;
|
|
||||||
|
|
||||||
uint64_t loadDataTime;
|
|
||||||
|
|
||||||
SFileBlockLoadRecorder* pRecoder;
|
SFileBlockLoadRecorder* pRecoder;
|
||||||
uint64_t elapsedTime;
|
|
||||||
|
|
||||||
uint64_t winInfoSize;
|
|
||||||
uint64_t tableInfoSize;
|
|
||||||
uint64_t hashSize;
|
|
||||||
uint64_t numOfTimeWindows;
|
|
||||||
|
|
||||||
SArray* queryProfEvents; // SArray<SQueryProfEvent>
|
|
||||||
SHashObj* operatorProfResults; // map<operator_type, SQueryProfEvent>
|
|
||||||
} STaskCostInfo;
|
} STaskCostInfo;
|
||||||
|
|
||||||
typedef struct SOperatorCostInfo {
|
typedef struct SOperatorCostInfo {
|
||||||
|
@ -150,18 +135,13 @@ typedef struct {
|
||||||
|
|
||||||
SSchemaWrapper* schema;
|
SSchemaWrapper* schema;
|
||||||
char tbName[TSDB_TABLE_NAME_LEN];
|
char tbName[TSDB_TABLE_NAME_LEN];
|
||||||
SSDataBlock* pullOverBlk; // for streaming
|
|
||||||
SWalFilterCond cond;
|
|
||||||
int64_t lastScanUid;
|
|
||||||
int8_t recoverStep;
|
int8_t recoverStep;
|
||||||
SQueryTableDataCond tableCond;
|
SQueryTableDataCond tableCond;
|
||||||
int64_t recoverStartVer;
|
|
||||||
int64_t recoverEndVer;
|
|
||||||
int64_t fillHistoryVer1;
|
int64_t fillHistoryVer1;
|
||||||
int64_t fillHistoryVer2;
|
int64_t fillHistoryVer2;
|
||||||
|
|
||||||
int8_t triggerSaved;
|
// int8_t triggerSaved;
|
||||||
int64_t deleteMarkSaved;
|
// int64_t deleteMarkSaved;
|
||||||
SStreamState* pState;
|
SStreamState* pState;
|
||||||
} SStreamTaskInfo;
|
} SStreamTaskInfo;
|
||||||
|
|
||||||
|
@ -461,8 +441,10 @@ typedef struct SPartitionDataInfo {
|
||||||
|
|
||||||
typedef struct STimeWindowAggSupp {
|
typedef struct STimeWindowAggSupp {
|
||||||
int8_t calTrigger;
|
int8_t calTrigger;
|
||||||
int64_t waterMark;
|
int8_t calTriggerSaved;
|
||||||
int64_t deleteMark;
|
int64_t deleteMark;
|
||||||
|
int64_t deleteMarkSaved;
|
||||||
|
int64_t waterMark;
|
||||||
TSKEY maxTs;
|
TSKEY maxTs;
|
||||||
TSKEY minTs;
|
TSKEY minTs;
|
||||||
SColumnInfoData timeWindowData; // query time window info for scalar function execution.
|
SColumnInfoData timeWindowData; // query time window info for scalar function execution.
|
||||||
|
|
|
@ -1884,8 +1884,9 @@ int32_t buildGroupIdMapForAllTables(STableListInfo* pTableListInfo, SReadHandle*
|
||||||
|
|
||||||
int32_t createScanTableListInfo(SScanPhysiNode* pScanNode, SNodeList* pGroupTags, bool groupSort, SReadHandle* pHandle,
|
int32_t createScanTableListInfo(SScanPhysiNode* pScanNode, SNodeList* pGroupTags, bool groupSort, SReadHandle* pHandle,
|
||||||
STableListInfo* pTableListInfo, SNode* pTagCond, SNode* pTagIndexCond,
|
STableListInfo* pTableListInfo, SNode* pTagCond, SNode* pTagIndexCond,
|
||||||
const char* idStr) {
|
struct SExecTaskInfo* pTaskInfo) {
|
||||||
int64_t st = taosGetTimestampUs();
|
int64_t st = taosGetTimestampUs();
|
||||||
|
const char* idStr = GET_TASKID(pTaskInfo);
|
||||||
|
|
||||||
if (pHandle == NULL) {
|
if (pHandle == NULL) {
|
||||||
qError("invalid handle, in creating operator tree, %s", idStr);
|
qError("invalid handle, in creating operator tree, %s", idStr);
|
||||||
|
@ -1901,7 +1902,8 @@ int32_t createScanTableListInfo(SScanPhysiNode* pScanNode, SNodeList* pGroupTags
|
||||||
ASSERT(pTableListInfo->numOfOuputGroups == 1);
|
ASSERT(pTableListInfo->numOfOuputGroups == 1);
|
||||||
|
|
||||||
int64_t st1 = taosGetTimestampUs();
|
int64_t st1 = taosGetTimestampUs();
|
||||||
qDebug("generate queried table list completed, elapsed time:%.2f ms %s", (st1 - st) / 1000.0, idStr);
|
pTaskInfo->cost.extractListTime = (st1 - st) / 1000.0;
|
||||||
|
qDebug("extract queried table list completed, elapsed time:%.2f ms %s", pTaskInfo->cost.extractListTime, idStr);
|
||||||
|
|
||||||
if (taosArrayGetSize(pTableListInfo->pTableList) == 0) {
|
if (taosArrayGetSize(pTableListInfo->pTableList) == 0) {
|
||||||
qDebug("no table qualified for query, %s" PRIx64, idStr);
|
qDebug("no table qualified for query, %s" PRIx64, idStr);
|
||||||
|
@ -1913,8 +1915,8 @@ int32_t createScanTableListInfo(SScanPhysiNode* pScanNode, SNodeList* pGroupTags
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t st2 = taosGetTimestampUs();
|
pTaskInfo->cost.groupIdMapTime = (taosGetTimestampUs() - st1)/1000.0;
|
||||||
qDebug("generate group id map completed, elapsed time:%.2f ms %s", (st2 - st1) / 1000.0, idStr);
|
qDebug("generate group id map completed, elapsed time:%.2f ms %s", pTaskInfo->cost.groupIdMapTime, idStr);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,26 @@ static int32_t doSetSMABlock(SOperatorInfo* pOperator, void* input, size_t numOf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t doSetStreamOpOpen(SOperatorInfo* pOperator, char* id) {
|
||||||
|
{
|
||||||
|
ASSERT(pOperator != NULL);
|
||||||
|
if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
||||||
|
if (pOperator->numOfDownstream == 0) {
|
||||||
|
qError("failed to find stream scan operator to set the input data block, %s" PRIx64, id);
|
||||||
|
return TSDB_CODE_QRY_APP_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pOperator->numOfDownstream > 1) { // not handle this in join query
|
||||||
|
qError("join not supported for stream block scan, %s" PRIx64, id);
|
||||||
|
return TSDB_CODE_QRY_APP_ERROR;
|
||||||
|
}
|
||||||
|
pOperator->status = OP_NOT_OPENED;
|
||||||
|
return doSetStreamOpOpen(pOperator->pDownstream[0], id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t numOfBlocks, int32_t type, char* id) {
|
static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t numOfBlocks, int32_t type, char* id) {
|
||||||
ASSERT(pOperator != NULL);
|
ASSERT(pOperator != NULL);
|
||||||
if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
||||||
|
@ -117,7 +137,22 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t nu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void streamInputBlockDataDestory(void* pBlock) { blockDataDestroy((SSDataBlock*)pBlock); }
|
int32_t qSetStreamOpOpen(qTaskInfo_t tinfo) {
|
||||||
|
if (tinfo == NULL) {
|
||||||
|
return TSDB_CODE_QRY_APP_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||||
|
|
||||||
|
int32_t code = doSetStreamOpOpen(pTaskInfo->pRoot, GET_TASKID(pTaskInfo));
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
qError("%s failed to set the stream block data", GET_TASKID(pTaskInfo));
|
||||||
|
} else {
|
||||||
|
qDebug("%s set the stream block successfully", GET_TASKID(pTaskInfo));
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks, int32_t type) {
|
int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks, int32_t type) {
|
||||||
if (tinfo == NULL) {
|
if (tinfo == NULL) {
|
||||||
|
@ -706,8 +741,7 @@ int32_t qStreamInput(qTaskInfo_t tinfo, void* pItem) {
|
||||||
int32_t qStreamSourceRecoverStep1(qTaskInfo_t tinfo, int64_t ver) {
|
int32_t qStreamSourceRecoverStep1(qTaskInfo_t tinfo, int64_t ver) {
|
||||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||||
ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM);
|
ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM);
|
||||||
pTaskInfo->streamInfo.recoverStartVer = 0;
|
pTaskInfo->streamInfo.fillHistoryVer1 = ver;
|
||||||
pTaskInfo->streamInfo.recoverEndVer = ver;
|
|
||||||
pTaskInfo->streamInfo.recoverStep = STREAM_RECOVER_STEP__PREPARE1;
|
pTaskInfo->streamInfo.recoverStep = STREAM_RECOVER_STEP__PREPARE1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -715,8 +749,7 @@ int32_t qStreamSourceRecoverStep1(qTaskInfo_t tinfo, int64_t ver) {
|
||||||
int32_t qStreamSourceRecoverStep2(qTaskInfo_t tinfo, int64_t ver) {
|
int32_t qStreamSourceRecoverStep2(qTaskInfo_t tinfo, int64_t ver) {
|
||||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||||
ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM);
|
ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM);
|
||||||
pTaskInfo->streamInfo.recoverStartVer = pTaskInfo->streamInfo.recoverEndVer;
|
pTaskInfo->streamInfo.fillHistoryVer2 = ver;
|
||||||
pTaskInfo->streamInfo.recoverEndVer = ver;
|
|
||||||
pTaskInfo->streamInfo.recoverStep = STREAM_RECOVER_STEP__PREPARE2;
|
pTaskInfo->streamInfo.recoverStep = STREAM_RECOVER_STEP__PREPARE2;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -737,22 +770,44 @@ int32_t qStreamSetParamForRecover(qTaskInfo_t tinfo) {
|
||||||
pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL ||
|
pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL ||
|
||||||
pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL) {
|
pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL) {
|
||||||
SStreamIntervalOperatorInfo* pInfo = pOperator->info;
|
SStreamIntervalOperatorInfo* pInfo = pOperator->info;
|
||||||
pTaskInfo->streamInfo.triggerSaved = pInfo->twAggSup.calTrigger;
|
ASSERT(pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE ||
|
||||||
pTaskInfo->streamInfo.deleteMarkSaved = pInfo->twAggSup.deleteMark;
|
pInfo->twAggSup.calTrigger == STREAM_TRIGGER_WINDOW_CLOSE);
|
||||||
|
ASSERT(pInfo->twAggSup.calTriggerSaved == 0);
|
||||||
|
ASSERT(pInfo->twAggSup.deleteMarkSaved == 0);
|
||||||
|
|
||||||
|
qInfo("save stream param for interval: %d, %" PRId64, pInfo->twAggSup.calTrigger, pInfo->twAggSup.deleteMark);
|
||||||
|
|
||||||
|
pInfo->twAggSup.calTriggerSaved = pInfo->twAggSup.calTrigger;
|
||||||
|
pInfo->twAggSup.deleteMarkSaved = pInfo->twAggSup.deleteMark;
|
||||||
pInfo->twAggSup.calTrigger = STREAM_TRIGGER_AT_ONCE;
|
pInfo->twAggSup.calTrigger = STREAM_TRIGGER_AT_ONCE;
|
||||||
pInfo->twAggSup.deleteMark = INT64_MAX;
|
pInfo->twAggSup.deleteMark = INT64_MAX;
|
||||||
|
|
||||||
} else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION ||
|
} else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION ||
|
||||||
pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION ||
|
pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION ||
|
||||||
pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION) {
|
pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION) {
|
||||||
SStreamSessionAggOperatorInfo* pInfo = pOperator->info;
|
SStreamSessionAggOperatorInfo* pInfo = pOperator->info;
|
||||||
pTaskInfo->streamInfo.triggerSaved = pInfo->twAggSup.calTrigger;
|
ASSERT(pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE ||
|
||||||
pTaskInfo->streamInfo.deleteMarkSaved = pInfo->twAggSup.deleteMark;
|
pInfo->twAggSup.calTrigger == STREAM_TRIGGER_WINDOW_CLOSE);
|
||||||
|
ASSERT(pInfo->twAggSup.calTriggerSaved == 0);
|
||||||
|
ASSERT(pInfo->twAggSup.deleteMarkSaved == 0);
|
||||||
|
|
||||||
|
qInfo("save stream param for session: %d, %" PRId64, pInfo->twAggSup.calTrigger, pInfo->twAggSup.deleteMark);
|
||||||
|
|
||||||
|
pInfo->twAggSup.calTriggerSaved = pInfo->twAggSup.calTrigger;
|
||||||
|
pInfo->twAggSup.deleteMarkSaved = pInfo->twAggSup.deleteMark;
|
||||||
pInfo->twAggSup.calTrigger = STREAM_TRIGGER_AT_ONCE;
|
pInfo->twAggSup.calTrigger = STREAM_TRIGGER_AT_ONCE;
|
||||||
pInfo->twAggSup.deleteMark = INT64_MAX;
|
pInfo->twAggSup.deleteMark = INT64_MAX;
|
||||||
} else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE) {
|
} else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE) {
|
||||||
SStreamStateAggOperatorInfo* pInfo = pOperator->info;
|
SStreamStateAggOperatorInfo* pInfo = pOperator->info;
|
||||||
pTaskInfo->streamInfo.triggerSaved = pInfo->twAggSup.calTrigger;
|
ASSERT(pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE ||
|
||||||
pTaskInfo->streamInfo.deleteMarkSaved = pInfo->twAggSup.deleteMark;
|
pInfo->twAggSup.calTrigger == STREAM_TRIGGER_WINDOW_CLOSE);
|
||||||
|
ASSERT(pInfo->twAggSup.calTriggerSaved == 0);
|
||||||
|
ASSERT(pInfo->twAggSup.deleteMarkSaved == 0);
|
||||||
|
|
||||||
|
qInfo("save stream param for state: %d, %" PRId64, pInfo->twAggSup.calTrigger, pInfo->twAggSup.deleteMark);
|
||||||
|
|
||||||
|
pInfo->twAggSup.calTriggerSaved = pInfo->twAggSup.calTrigger;
|
||||||
|
pInfo->twAggSup.deleteMarkSaved = pInfo->twAggSup.deleteMark;
|
||||||
pInfo->twAggSup.calTrigger = STREAM_TRIGGER_AT_ONCE;
|
pInfo->twAggSup.calTrigger = STREAM_TRIGGER_AT_ONCE;
|
||||||
pInfo->twAggSup.deleteMark = INT64_MAX;
|
pInfo->twAggSup.deleteMark = INT64_MAX;
|
||||||
}
|
}
|
||||||
|
@ -782,21 +837,36 @@ int32_t qStreamRestoreParam(qTaskInfo_t tinfo) {
|
||||||
pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL ||
|
pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL ||
|
||||||
pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL) {
|
pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL) {
|
||||||
SStreamIntervalOperatorInfo* pInfo = pOperator->info;
|
SStreamIntervalOperatorInfo* pInfo = pOperator->info;
|
||||||
|
ASSERT(pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE);
|
||||||
|
ASSERT(pInfo->twAggSup.deleteMark == INT64_MAX);
|
||||||
|
|
||||||
pInfo->twAggSup.calTrigger = pTaskInfo->streamInfo.triggerSaved;
|
pInfo->twAggSup.calTrigger = pInfo->twAggSup.calTriggerSaved;
|
||||||
pInfo->twAggSup.deleteMark = pTaskInfo->streamInfo.deleteMarkSaved;
|
pInfo->twAggSup.deleteMark = pInfo->twAggSup.deleteMarkSaved;
|
||||||
|
ASSERT(pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE ||
|
||||||
|
pInfo->twAggSup.calTrigger == STREAM_TRIGGER_WINDOW_CLOSE);
|
||||||
|
qInfo("restore stream param for interval: %d, %" PRId64, pInfo->twAggSup.calTrigger, pInfo->twAggSup.deleteMark);
|
||||||
} else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION ||
|
} else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION ||
|
||||||
pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION ||
|
pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION ||
|
||||||
pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION) {
|
pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION) {
|
||||||
SStreamSessionAggOperatorInfo* pInfo = pOperator->info;
|
SStreamSessionAggOperatorInfo* pInfo = pOperator->info;
|
||||||
|
ASSERT(pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE);
|
||||||
|
ASSERT(pInfo->twAggSup.deleteMark == INT64_MAX);
|
||||||
|
|
||||||
pInfo->twAggSup.calTrigger = pTaskInfo->streamInfo.triggerSaved;
|
pInfo->twAggSup.calTrigger = pInfo->twAggSup.calTriggerSaved;
|
||||||
pInfo->twAggSup.deleteMark = pTaskInfo->streamInfo.deleteMarkSaved;
|
pInfo->twAggSup.deleteMark = pInfo->twAggSup.deleteMarkSaved;
|
||||||
|
ASSERT(pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE ||
|
||||||
|
pInfo->twAggSup.calTrigger == STREAM_TRIGGER_WINDOW_CLOSE);
|
||||||
|
qInfo("restore stream param for session: %d, %" PRId64, pInfo->twAggSup.calTrigger, pInfo->twAggSup.deleteMark);
|
||||||
} else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE) {
|
} else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE) {
|
||||||
SStreamStateAggOperatorInfo* pInfo = pOperator->info;
|
SStreamStateAggOperatorInfo* pInfo = pOperator->info;
|
||||||
|
ASSERT(pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE);
|
||||||
|
ASSERT(pInfo->twAggSup.deleteMark == INT64_MAX);
|
||||||
|
|
||||||
pInfo->twAggSup.calTrigger = pTaskInfo->streamInfo.triggerSaved;
|
pInfo->twAggSup.calTrigger = pInfo->twAggSup.calTriggerSaved;
|
||||||
pInfo->twAggSup.deleteMark = pTaskInfo->streamInfo.deleteMarkSaved;
|
pInfo->twAggSup.deleteMark = pInfo->twAggSup.deleteMarkSaved;
|
||||||
|
ASSERT(pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE ||
|
||||||
|
pInfo->twAggSup.calTrigger == STREAM_TRIGGER_WINDOW_CLOSE);
|
||||||
|
qInfo("restore stream param for state: %d, %" PRId64, pInfo->twAggSup.calTrigger, pInfo->twAggSup.deleteMark);
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterate operator tree
|
// iterate operator tree
|
||||||
|
|
|
@ -1400,40 +1400,18 @@ void doBuildResultDatablock(SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SG
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t compressQueryColData(SColumnInfoData* pColRes, int32_t numOfRows, char* data, int8_t compressed) {
|
|
||||||
int32_t colSize = pColRes->info.bytes * numOfRows;
|
|
||||||
return (*(tDataTypes[pColRes->info.type].compFunc))(pColRes->pData, colSize, numOfRows, data,
|
|
||||||
colSize + COMP_OVERFLOW_BYTES, compressed, NULL, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void queryCostStatis(SExecTaskInfo* pTaskInfo) {
|
void queryCostStatis(SExecTaskInfo* pTaskInfo) {
|
||||||
STaskCostInfo* pSummary = &pTaskInfo->cost;
|
STaskCostInfo* pSummary = &pTaskInfo->cost;
|
||||||
|
|
||||||
// uint64_t hashSize = taosHashGetMemSize(pQInfo->runtimeEnv.pResultRowHashTable);
|
|
||||||
// hashSize += taosHashGetMemSize(pRuntimeEnv->tableqinfoGroupInfo.map);
|
|
||||||
// pSummary->hashSize = hashSize;
|
|
||||||
|
|
||||||
// SResultRowPool* p = pTaskInfo->pool;
|
|
||||||
// if (p != NULL) {
|
|
||||||
// pSummary->winInfoSize = getResultRowPoolMemSize(p);
|
|
||||||
// pSummary->numOfTimeWindows = getNumOfAllocatedResultRows(p);
|
|
||||||
// } else {
|
|
||||||
// pSummary->winInfoSize = 0;
|
|
||||||
// pSummary->numOfTimeWindows = 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
SFileBlockLoadRecorder* pRecorder = pSummary->pRecoder;
|
SFileBlockLoadRecorder* pRecorder = pSummary->pRecoder;
|
||||||
if (pSummary->pRecoder != NULL) {
|
if (pSummary->pRecoder != NULL) {
|
||||||
qDebug(
|
qDebug(
|
||||||
"%s :cost summary: elapsed time:%.2f ms, total blocks:%d, load block SMA:%d, load data block:%d, total "
|
"%s :cost summary: elapsed time:%.2f ms, extract tableList:%.2f ms, createGroupIdMap:%.2f ms, total blocks:%d, "
|
||||||
"rows:%" PRId64 ", check rows:%" PRId64,
|
"load block SMA:%d, load data block:%d, total rows:%" PRId64 ", check rows:%" PRId64,
|
||||||
GET_TASKID(pTaskInfo), pSummary->elapsedTime / 1000.0, pRecorder->totalBlocks, pRecorder->loadBlockStatis,
|
GET_TASKID(pTaskInfo), pSummary->elapsedTime / 1000.0, pSummary->extractListTime, pSummary->groupIdMapTime,
|
||||||
pRecorder->loadBlocks, pRecorder->totalRows, pRecorder->totalCheckedRows);
|
pRecorder->totalBlocks, pRecorder->loadBlockStatis, pRecorder->loadBlocks, pRecorder->totalRows,
|
||||||
|
pRecorder->totalCheckedRows);
|
||||||
}
|
}
|
||||||
|
|
||||||
// qDebug("QInfo:0x%"PRIx64" :cost summary: winResPool size:%.2f Kb, numOfWin:%"PRId64", tableInfoSize:%.2f Kb,
|
|
||||||
// hashTable:%.2f Kb", pQInfo->qId, pSummary->winInfoSize/1024.0,
|
|
||||||
// pSummary->numOfTimeWindows, pSummary->tableInfoSize/1024.0, pSummary->hashSize/1024.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// static void updateOffsetVal(STaskRuntimeEnv *pRuntimeEnv, SDataBlockInfo *pBlockInfo) {
|
// static void updateOffsetVal(STaskRuntimeEnv *pRuntimeEnv, SDataBlockInfo *pBlockInfo) {
|
||||||
|
@ -3220,6 +3198,11 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode*
|
||||||
|
|
||||||
static SExecTaskInfo* createExecTaskInfo(uint64_t queryId, uint64_t taskId, EOPTR_EXEC_MODEL model, char* dbFName) {
|
static SExecTaskInfo* createExecTaskInfo(uint64_t queryId, uint64_t taskId, EOPTR_EXEC_MODEL model, char* dbFName) {
|
||||||
SExecTaskInfo* pTaskInfo = taosMemoryCalloc(1, sizeof(SExecTaskInfo));
|
SExecTaskInfo* pTaskInfo = taosMemoryCalloc(1, sizeof(SExecTaskInfo));
|
||||||
|
if (pTaskInfo == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED);
|
setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED);
|
||||||
|
|
||||||
pTaskInfo->schemaInfo.dbname = strdup(dbFName);
|
pTaskInfo->schemaInfo.dbname = strdup(dbFName);
|
||||||
|
@ -3350,7 +3333,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
||||||
|
|
||||||
int32_t code =
|
int32_t code =
|
||||||
createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, pTableScanNode->groupSort, pHandle,
|
createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, pTableScanNode->groupSort, pHandle,
|
||||||
pTableListInfo, pTagCond, pTagIndexCond, idstr);
|
pTableListInfo, pTagCond, pTagIndexCond, pTaskInfo);
|
||||||
if (code) {
|
if (code) {
|
||||||
pTaskInfo->code = code;
|
pTaskInfo->code = code;
|
||||||
qError("failed to createScanTableListInfo, code:%s, %s", tstrerror(code), idstr);
|
qError("failed to createScanTableListInfo, code:%s, %s", tstrerror(code), idstr);
|
||||||
|
@ -3368,9 +3351,9 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
||||||
pTaskInfo->cost.pRecoder = &pScanInfo->readRecorder;
|
pTaskInfo->cost.pRecoder = &pScanInfo->readRecorder;
|
||||||
} else if (QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == type) {
|
} else if (QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == type) {
|
||||||
STableMergeScanPhysiNode* pTableScanNode = (STableMergeScanPhysiNode*)pPhyNode;
|
STableMergeScanPhysiNode* pTableScanNode = (STableMergeScanPhysiNode*)pPhyNode;
|
||||||
int32_t code =
|
|
||||||
createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, /*pTableScanNode->groupSort*/true, pHandle,
|
int32_t code = createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, true, pHandle,
|
||||||
pTableListInfo, pTagCond, pTagIndexCond, idstr);
|
pTableListInfo, pTagCond, pTagIndexCond, pTaskInfo);
|
||||||
if (code) {
|
if (code) {
|
||||||
pTaskInfo->code = code;
|
pTaskInfo->code = code;
|
||||||
qError("failed to createScanTableListInfo, code: %s", tstrerror(code));
|
qError("failed to createScanTableListInfo, code: %s", tstrerror(code));
|
||||||
|
@ -3395,7 +3378,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
||||||
if (pHandle->vnode) {
|
if (pHandle->vnode) {
|
||||||
int32_t code =
|
int32_t code =
|
||||||
createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, pTableScanNode->groupSort,
|
createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, pTableScanNode->groupSort,
|
||||||
pHandle, pTableListInfo, pTagCond, pTagIndexCond, idstr);
|
pHandle, pTableListInfo, pTagCond, pTagIndexCond, pTaskInfo);
|
||||||
if (code) {
|
if (code) {
|
||||||
pTaskInfo->code = code;
|
pTaskInfo->code = code;
|
||||||
qError("failed to createScanTableListInfo, code: %s", tstrerror(code));
|
qError("failed to createScanTableListInfo, code: %s", tstrerror(code));
|
||||||
|
@ -3422,7 +3405,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
||||||
STagScanPhysiNode* pScanPhyNode = (STagScanPhysiNode*)pPhyNode;
|
STagScanPhysiNode* pScanPhyNode = (STagScanPhysiNode*)pPhyNode;
|
||||||
|
|
||||||
int32_t code = createScanTableListInfo(pScanPhyNode, NULL, false, pHandle, pTableListInfo, pTagCond,
|
int32_t code = createScanTableListInfo(pScanPhyNode, NULL, false, pHandle, pTableListInfo, pTagCond,
|
||||||
pTagIndexCond, idstr);
|
pTagIndexCond, pTaskInfo);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
pTaskInfo->code = code;
|
pTaskInfo->code = code;
|
||||||
qError("failed to getTableList, code: %s", tstrerror(code));
|
qError("failed to getTableList, code: %s", tstrerror(code));
|
||||||
|
@ -3455,7 +3438,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
||||||
SLastRowScanPhysiNode* pScanNode = (SLastRowScanPhysiNode*)pPhyNode;
|
SLastRowScanPhysiNode* pScanNode = (SLastRowScanPhysiNode*)pPhyNode;
|
||||||
|
|
||||||
int32_t code = createScanTableListInfo(&pScanNode->scan, pScanNode->pGroupTags, true, pHandle, pTableListInfo,
|
int32_t code = createScanTableListInfo(&pScanNode->scan, pScanNode->pGroupTags, true, pHandle, pTableListInfo,
|
||||||
pTagCond, pTagIndexCond, idstr);
|
pTagCond, pTagIndexCond, pTaskInfo);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
pTaskInfo->code = code;
|
pTaskInfo->code = code;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -3787,10 +3770,8 @@ int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SRead
|
||||||
char* sql, EOPTR_EXEC_MODEL model) {
|
char* sql, EOPTR_EXEC_MODEL model) {
|
||||||
uint64_t queryId = pPlan->id.queryId;
|
uint64_t queryId = pPlan->id.queryId;
|
||||||
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
|
||||||
*pTaskInfo = createExecTaskInfo(queryId, taskId, model, pPlan->dbFName);
|
*pTaskInfo = createExecTaskInfo(queryId, taskId, model, pPlan->dbFName);
|
||||||
if (*pTaskInfo == NULL) {
|
if (*pTaskInfo == NULL) {
|
||||||
code = TSDB_CODE_QRY_OUT_OF_MEMORY;
|
|
||||||
goto _complete;
|
goto _complete;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3809,17 +3790,16 @@ int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SRead
|
||||||
createOperatorTree(pPlan->pNode, *pTaskInfo, pHandle, pPlan->pTagCond, pPlan->pTagIndexCond, pPlan->user);
|
createOperatorTree(pPlan->pNode, *pTaskInfo, pHandle, pPlan->pTagCond, pPlan->pTagIndexCond, pPlan->user);
|
||||||
|
|
||||||
if (NULL == (*pTaskInfo)->pRoot) {
|
if (NULL == (*pTaskInfo)->pRoot) {
|
||||||
code = (*pTaskInfo)->code;
|
terrno = (*pTaskInfo)->code;
|
||||||
goto _complete;
|
goto _complete;
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
_complete:
|
_complete:
|
||||||
taosMemoryFree(sql);
|
taosMemoryFree(sql);
|
||||||
doDestroyTask(*pTaskInfo);
|
doDestroyTask(*pTaskInfo);
|
||||||
terrno = code;
|
return terrno;
|
||||||
return code;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void doDestroyTask(SExecTaskInfo* pTaskInfo) {
|
void doDestroyTask(SExecTaskInfo* pTaskInfo) {
|
||||||
|
|
|
@ -621,9 +621,10 @@ int32_t* setupColumnOffset(const SSDataBlock* pBlock, int32_t rowCapacity) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void clearPartitionOperator(SPartitionOperatorInfo* pInfo) {
|
static void clearPartitionOperator(SPartitionOperatorInfo* pInfo) {
|
||||||
void* ite = NULL;
|
int32_t size = taosArrayGetSize(pInfo->sortedGroupArray);
|
||||||
while ((ite = taosHashIterate(pInfo->pGroupSet, ite)) != NULL) {
|
for (int32_t i = 0; i < size; i++) {
|
||||||
taosArrayDestroy(((SDataGroupInfo*)ite)->pPageList);
|
SDataGroupInfo* pGp = taosArrayGet(pInfo->sortedGroupArray, i);
|
||||||
|
taosArrayDestroy(pGp->pPageList);
|
||||||
}
|
}
|
||||||
taosArrayClear(pInfo->sortedGroupArray);
|
taosArrayClear(pInfo->sortedGroupArray);
|
||||||
clearDiskbasedBuf(pInfo->pBuf);
|
clearDiskbasedBuf(pInfo->pBuf);
|
||||||
|
|
|
@ -344,7 +344,8 @@ static bool doLoadBlockSMA(STableScanInfo* pTableScanInfo, SSDataBlock* pBlock,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void doSetTagColumnData(STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo, int32_t rows) {
|
static void doSetTagColumnData(STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo,
|
||||||
|
int32_t rows) {
|
||||||
if (pTableScanInfo->pseudoSup.numOfExprs > 0) {
|
if (pTableScanInfo->pseudoSup.numOfExprs > 0) {
|
||||||
SExprSupp* pSup = &pTableScanInfo->pseudoSup;
|
SExprSupp* pSup = &pTableScanInfo->pseudoSup;
|
||||||
|
|
||||||
|
@ -1878,7 +1879,6 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 1
|
|
||||||
if (pTaskInfo->streamInfo.recoverStep == STREAM_RECOVER_STEP__PREPARE1 ||
|
if (pTaskInfo->streamInfo.recoverStep == STREAM_RECOVER_STEP__PREPARE1 ||
|
||||||
pTaskInfo->streamInfo.recoverStep == STREAM_RECOVER_STEP__PREPARE2) {
|
pTaskInfo->streamInfo.recoverStep == STREAM_RECOVER_STEP__PREPARE2) {
|
||||||
STableScanInfo* pTSInfo = pInfo->pTableScanOp->info;
|
STableScanInfo* pTSInfo = pInfo->pTableScanOp->info;
|
||||||
|
@ -1890,6 +1890,11 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
|
||||||
pTSInfo->cond.startVersion = pTaskInfo->streamInfo.fillHistoryVer1 + 1;
|
pTSInfo->cond.startVersion = pTaskInfo->streamInfo.fillHistoryVer1 + 1;
|
||||||
pTSInfo->cond.endVersion = pTaskInfo->streamInfo.fillHistoryVer2;
|
pTSInfo->cond.endVersion = pTaskInfo->streamInfo.fillHistoryVer2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*resetTableScanInfo(pTSInfo, pWin);*/
|
||||||
|
tsdbReaderClose(pTSInfo->dataReader);
|
||||||
|
pTSInfo->dataReader = NULL;
|
||||||
|
|
||||||
pTSInfo->scanTimes = 0;
|
pTSInfo->scanTimes = 0;
|
||||||
pTSInfo->currentGroupId = -1;
|
pTSInfo->currentGroupId = -1;
|
||||||
pTaskInfo->streamInfo.recoverStep = STREAM_RECOVER_STEP__SCAN;
|
pTaskInfo->streamInfo.recoverStep = STREAM_RECOVER_STEP__SCAN;
|
||||||
|
@ -1903,9 +1908,12 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
|
||||||
return pBlock;
|
return pBlock;
|
||||||
}
|
}
|
||||||
pTaskInfo->streamInfo.recoverStep = STREAM_RECOVER_STEP__NONE;
|
pTaskInfo->streamInfo.recoverStep = STREAM_RECOVER_STEP__NONE;
|
||||||
|
STableScanInfo* pTSInfo = pInfo->pTableScanOp->info;
|
||||||
|
pTSInfo->cond.startVersion = 0;
|
||||||
|
pTSInfo->cond.endVersion = -1;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
size_t total = taosArrayGetSize(pInfo->pBlockLists);
|
size_t total = taosArrayGetSize(pInfo->pBlockLists);
|
||||||
// TODO: refactor
|
// TODO: refactor
|
||||||
|
@ -2287,7 +2295,7 @@ SOperatorInfo* createRawScanOperatorInfo(SReadHandle* pHandle, SExecTaskInfo* pT
|
||||||
pInfo->vnode = pHandle->vnode;
|
pInfo->vnode = pHandle->vnode;
|
||||||
|
|
||||||
pInfo->sContext = pHandle->sContext;
|
pInfo->sContext = pHandle->sContext;
|
||||||
pOperator->name = "RawStreamScanOperator";
|
pOperator->name = "RawScanOperator";
|
||||||
pOperator->info = pInfo;
|
pOperator->info = pInfo;
|
||||||
pOperator->pTaskInfo = pTaskInfo;
|
pOperator->pTaskInfo = pTaskInfo;
|
||||||
|
|
||||||
|
@ -4375,8 +4383,9 @@ static int32_t loadDataBlockFromOneTable2(SOperatorInfo* pOperator, STableMergeS
|
||||||
|
|
||||||
// currently only the tbname pseudo column
|
// currently only the tbname pseudo column
|
||||||
if (pTableScanInfo->pseudoSup.numOfExprs > 0) {
|
if (pTableScanInfo->pseudoSup.numOfExprs > 0) {
|
||||||
int32_t code = addTagPseudoColumnData(&pTableScanInfo->readHandle, pTableScanInfo->pseudoSup.pExprInfo,
|
int32_t code =
|
||||||
pTableScanInfo->pseudoSup.numOfExprs, pBlock, pBlock->info.rows, GET_TASKID(pTaskInfo));
|
addTagPseudoColumnData(&pTableScanInfo->readHandle, pTableScanInfo->pseudoSup.pExprInfo,
|
||||||
|
pTableScanInfo->pseudoSup.numOfExprs, pBlock, pBlock->info.rows, GET_TASKID(pTaskInfo));
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
T_LONG_JMP(pTaskInfo->env, code);
|
T_LONG_JMP(pTaskInfo->env, code);
|
||||||
}
|
}
|
||||||
|
@ -4492,8 +4501,9 @@ static int32_t loadDataBlockFromOneTable(SOperatorInfo* pOperator, STableMergeSc
|
||||||
|
|
||||||
// currently only the tbname pseudo column
|
// currently only the tbname pseudo column
|
||||||
if (pTableScanInfo->pseudoSup.numOfExprs > 0) {
|
if (pTableScanInfo->pseudoSup.numOfExprs > 0) {
|
||||||
int32_t code = addTagPseudoColumnData(&pTableScanInfo->readHandle, pTableScanInfo->pseudoSup.pExprInfo,
|
int32_t code =
|
||||||
pTableScanInfo->pseudoSup.numOfExprs, pBlock, pBlock->info.rows, GET_TASKID(pTaskInfo));
|
addTagPseudoColumnData(&pTableScanInfo->readHandle, pTableScanInfo->pseudoSup.pExprInfo,
|
||||||
|
pTableScanInfo->pseudoSup.numOfExprs, pBlock, pBlock->info.rows, GET_TASKID(pTaskInfo));
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
T_LONG_JMP(pTaskInfo->env, code);
|
T_LONG_JMP(pTaskInfo->env, code);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3303,6 +3303,8 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream,
|
||||||
// for test 315360000000
|
// for test 315360000000
|
||||||
.deleteMark = 1000LL * 60LL * 60LL * 24LL * 365LL * 10LL,
|
.deleteMark = 1000LL * 60LL * 60LL * 24LL * 365LL * 10LL,
|
||||||
// .deleteMark = INT64_MAX,
|
// .deleteMark = INT64_MAX,
|
||||||
|
.deleteMarkSaved = 0,
|
||||||
|
.calTriggerSaved = 0,
|
||||||
};
|
};
|
||||||
ASSERT(pInfo->twAggSup.calTrigger != STREAM_TRIGGER_MAX_DELAY);
|
ASSERT(pInfo->twAggSup.calTrigger != STREAM_TRIGGER_MAX_DELAY);
|
||||||
pInfo->primaryTsIndex = ((SColumnNode*)pIntervalPhyNode->window.pTspk)->slotId;
|
pInfo->primaryTsIndex = ((SColumnNode*)pIntervalPhyNode->window.pTspk)->slotId;
|
||||||
|
|
|
@ -2194,6 +2194,56 @@ int32_t leastSQRFunction(SqlFunctionCtx* pCtx) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case TSDB_DATA_TYPE_UTINYINT: {
|
||||||
|
uint8_t* plist = (uint8_t*)pCol->pData;
|
||||||
|
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
||||||
|
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
numOfElem++;
|
||||||
|
LEASTSQR_CAL(param, x, plist, i, pInfo->stepVal);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TSDB_DATA_TYPE_USMALLINT: {
|
||||||
|
uint16_t* plist = (uint16_t*)pCol->pData;
|
||||||
|
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
||||||
|
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
numOfElem++;
|
||||||
|
LEASTSQR_CAL(param, x, plist, i, pInfo->stepVal);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case TSDB_DATA_TYPE_UINT: {
|
||||||
|
uint32_t* plist = (uint32_t*)pCol->pData;
|
||||||
|
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
||||||
|
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
numOfElem++;
|
||||||
|
LEASTSQR_CAL(param, x, plist, i, pInfo->stepVal);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case TSDB_DATA_TYPE_UBIGINT: {
|
||||||
|
uint64_t* plist = (uint64_t*)pCol->pData;
|
||||||
|
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
||||||
|
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
numOfElem++;
|
||||||
|
LEASTSQR_CAL(param, x, plist, i, pInfo->stepVal);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_FLOAT: {
|
case TSDB_DATA_TYPE_FLOAT: {
|
||||||
float* plist = (float*)pCol->pData;
|
float* plist = (float*)pCol->pData;
|
||||||
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
||||||
|
@ -2257,6 +2307,12 @@ int32_t leastSQRFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
|
|
||||||
double param00 = param[0][0] - param[1][0] * (param[0][1] / param[1][1]);
|
double param00 = param[0][0] - param[1][0] * (param[0][1] / param[1][1]);
|
||||||
double param02 = param[0][2] - param[1][2] * (param[0][1] / param[1][1]);
|
double param02 = param[0][2] - param[1][2] * (param[0][1] / param[1][1]);
|
||||||
|
|
||||||
|
if (0 == param00) {
|
||||||
|
colDataAppendNULL(pCol, currentRow);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// param[0][1] = 0;
|
// param[0][1] = 0;
|
||||||
double param12 = param[1][2] - param02 * (param[1][0] / param00);
|
double param12 = param[1][2] - param02 * (param[1][0] / param00);
|
||||||
// param[1][0] = 0;
|
// param[1][0] = 0;
|
||||||
|
@ -2657,7 +2713,9 @@ int32_t apercentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
taosMemoryFree(res);
|
taosMemoryFree(res);
|
||||||
} else { // no need to free
|
} else { // no need to free
|
||||||
// setNull(pCtx->pOutput, pCtx->outputType, pCtx->outputBytes);
|
// setNull(pCtx->pOutput, pCtx->outputType, pCtx->outputBytes);
|
||||||
return TSDB_CODE_SUCCESS;
|
// return TSDB_CODE_SUCCESS;
|
||||||
|
qDebug("%s get the final res, elements:%" PRId64 ", numOfEntry:%d. result is null", __FUNCTION__,
|
||||||
|
pInfo->pHisto->numOfElems, pInfo->pHisto->numOfEntries);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -251,6 +251,13 @@ bool fmIsSelectValueFunc(int32_t funcId) {
|
||||||
return FUNCTION_TYPE_SELECT_VALUE == funcMgtBuiltins[funcId].type;
|
return FUNCTION_TYPE_SELECT_VALUE == funcMgtBuiltins[funcId].type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool fmIsGroupKeyFunc(int32_t funcId) {
|
||||||
|
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return FUNCTION_TYPE_GROUP_KEY == funcMgtBuiltins[funcId].type;
|
||||||
|
}
|
||||||
|
|
||||||
void fmFuncMgtDestroy() {
|
void fmFuncMgtDestroy() {
|
||||||
void* m = gFunMgtService.pFuncNameHashTable;
|
void* m = gFunMgtService.pFuncNameHashTable;
|
||||||
if (m != NULL && atomic_val_compare_exchange_ptr((void**)&gFunMgtService.pFuncNameHashTable, m, 0) == m) {
|
if (m != NULL && atomic_val_compare_exchange_ptr((void**)&gFunMgtService.pFuncNameHashTable, m, 0) == m) {
|
||||||
|
|
|
@ -124,13 +124,16 @@ static int32_t udfSpawnUdfd(SUdfdData *pData) {
|
||||||
|
|
||||||
char pathTaosdLdLib[512] = {0};
|
char pathTaosdLdLib[512] = {0};
|
||||||
size_t taosdLdLibPathLen = sizeof(pathTaosdLdLib);
|
size_t taosdLdLibPathLen = sizeof(pathTaosdLdLib);
|
||||||
uv_os_getenv("LD_LIBRARY_PATH", pathTaosdLdLib, &taosdLdLibPathLen);
|
int ret = uv_os_getenv("LD_LIBRARY_PATH", pathTaosdLdLib, &taosdLdLibPathLen);
|
||||||
|
if (ret != UV_ENOBUFS) {
|
||||||
|
taosdLdLibPathLen = strlen(pathTaosdLdLib);
|
||||||
|
}
|
||||||
|
|
||||||
char udfdPathLdLib[1024] = {0};
|
char udfdPathLdLib[1024] = {0};
|
||||||
size_t udfdLdLibPathLen = strlen(tsUdfdLdLibPath);
|
size_t udfdLdLibPathLen = strlen(tsUdfdLdLibPath);
|
||||||
strncpy(udfdPathLdLib, tsUdfdLdLibPath, udfdLdLibPathLen);
|
strncpy(udfdPathLdLib, tsUdfdLdLibPath, udfdLdLibPathLen);
|
||||||
udfdPathLdLib[udfdLdLibPathLen] = ':';
|
udfdPathLdLib[udfdLdLibPathLen] = ':';
|
||||||
strncpy(udfdPathLdLib + udfdLdLibPathLen + 1, pathTaosdLdLib, sizeof(udfdPathLdLib) - udfdLdLibPathLen);
|
strncpy(udfdPathLdLib + udfdLdLibPathLen + 1, pathTaosdLdLib, sizeof(udfdPathLdLib) - udfdLdLibPathLen - 1);
|
||||||
if (udfdLdLibPathLen + taosdLdLibPathLen < 1024) {
|
if (udfdLdLibPathLen + taosdLdLibPathLen < 1024) {
|
||||||
fnInfo("udfd LD_LIBRARY_PATH: %s", udfdPathLdLib);
|
fnInfo("udfd LD_LIBRARY_PATH: %s", udfdPathLdLib);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -152,7 +152,7 @@ IFileCtx* idxFileCtxCreate(WriterType type, const char* path, bool readOnly, int
|
||||||
if (ctx->type == TFILE) {
|
if (ctx->type == TFILE) {
|
||||||
// ugly code, refactor later
|
// ugly code, refactor later
|
||||||
ctx->file.readOnly = readOnly;
|
ctx->file.readOnly = readOnly;
|
||||||
memcpy(ctx->file.buf, path, sizeof(ctx->file.buf));
|
memcpy(ctx->file.buf, path, strlen(path));
|
||||||
if (readOnly == false) {
|
if (readOnly == false) {
|
||||||
ctx->file.pFile = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
ctx->file.pFile = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||||
taosFtruncateFile(ctx->file.pFile, 0);
|
taosFtruncateFile(ctx->file.pFile, 0);
|
||||||
|
|
|
@ -5160,7 +5160,7 @@ static int32_t translateCreateIndex(STranslateContext* pCxt, SCreateIndexStmt* p
|
||||||
static int32_t translateDropIndex(STranslateContext* pCxt, SDropIndexStmt* pStmt) {
|
static int32_t translateDropIndex(STranslateContext* pCxt, SDropIndexStmt* pStmt) {
|
||||||
SMDropSmaReq dropSmaReq = {0};
|
SMDropSmaReq dropSmaReq = {0};
|
||||||
SName name;
|
SName name;
|
||||||
tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pCxt->pParseCxt->db, pStmt->indexName, &name), dropSmaReq.name);
|
tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->indexDbName, pStmt->indexName, &name), dropSmaReq.name);
|
||||||
dropSmaReq.igNotExists = pStmt->ignoreNotExists;
|
dropSmaReq.igNotExists = pStmt->ignoreNotExists;
|
||||||
return buildCmdMsg(pCxt, TDMT_MND_DROP_SMA, (FSerializeFunc)tSerializeSMDropSmaReq, &dropSmaReq);
|
return buildCmdMsg(pCxt, TDMT_MND_DROP_SMA, (FSerializeFunc)tSerializeSMDropSmaReq, &dropSmaReq);
|
||||||
}
|
}
|
||||||
|
@ -5281,7 +5281,7 @@ static int32_t translateCreateTopic(STranslateContext* pCxt, SCreateTopicStmt* p
|
||||||
code = buildCreateTopicReq(pCxt, pStmt, &createReq);
|
code = buildCreateTopicReq(pCxt, pStmt, &createReq);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = buildCmdMsg(pCxt, TDMT_MND_CREATE_TOPIC, (FSerializeFunc)tSerializeSCMCreateTopicReq, &createReq);
|
code = buildCmdMsg(pCxt, TDMT_MND_TMQ_CREATE_TOPIC, (FSerializeFunc)tSerializeSCMCreateTopicReq, &createReq);
|
||||||
}
|
}
|
||||||
tFreeSCMCreateTopicReq(&createReq);
|
tFreeSCMCreateTopicReq(&createReq);
|
||||||
return code;
|
return code;
|
||||||
|
@ -5295,7 +5295,7 @@ static int32_t translateDropTopic(STranslateContext* pCxt, SDropTopicStmt* pStmt
|
||||||
tNameGetFullDbName(&name, dropReq.name);
|
tNameGetFullDbName(&name, dropReq.name);
|
||||||
dropReq.igNotExists = pStmt->ignoreNotExists;
|
dropReq.igNotExists = pStmt->ignoreNotExists;
|
||||||
|
|
||||||
return buildCmdMsg(pCxt, TDMT_MND_DROP_TOPIC, (FSerializeFunc)tSerializeSMDropTopicReq, &dropReq);
|
return buildCmdMsg(pCxt, TDMT_MND_TMQ_DROP_TOPIC, (FSerializeFunc)tSerializeSMDropTopicReq, &dropReq);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t translateDropCGroup(STranslateContext* pCxt, SDropCGroupStmt* pStmt) {
|
static int32_t translateDropCGroup(STranslateContext* pCxt, SDropCGroupStmt* pStmt) {
|
||||||
|
@ -5307,7 +5307,7 @@ static int32_t translateDropCGroup(STranslateContext* pCxt, SDropCGroupStmt* pSt
|
||||||
dropReq.igNotExists = pStmt->ignoreNotExists;
|
dropReq.igNotExists = pStmt->ignoreNotExists;
|
||||||
strcpy(dropReq.cgroup, pStmt->cgroup);
|
strcpy(dropReq.cgroup, pStmt->cgroup);
|
||||||
|
|
||||||
return buildCmdMsg(pCxt, TDMT_MND_MQ_DROP_CGROUP, (FSerializeFunc)tSerializeSMDropCgroupReq, &dropReq);
|
return buildCmdMsg(pCxt, TDMT_MND_TMQ_DROP_CGROUP, (FSerializeFunc)tSerializeSMDropCgroupReq, &dropReq);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t translateAlterLocal(STranslateContext* pCxt, SAlterLocalStmt* pStmt) {
|
static int32_t translateAlterLocal(STranslateContext* pCxt, SAlterLocalStmt* pStmt) {
|
||||||
|
|
|
@ -587,6 +587,10 @@ static int32_t createIndefRowsFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool isInterpFunc(int32_t funcId) {
|
||||||
|
return fmIsInterpFunc(funcId) || fmIsInterpPseudoColumnFunc(funcId) || fmIsGroupKeyFunc(funcId);
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t createInterpFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
static int32_t createInterpFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
||||||
if (!pSelect->hasInterpFunc) {
|
if (!pSelect->hasInterpFunc) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -602,7 +606,7 @@ static int32_t createInterpFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt* p
|
||||||
pInterpFunc->node.resultDataOrder = pInterpFunc->node.requireDataOrder;
|
pInterpFunc->node.resultDataOrder = pInterpFunc->node.requireDataOrder;
|
||||||
|
|
||||||
// interp functions and _group_key functions
|
// interp functions and _group_key functions
|
||||||
int32_t code = nodesCollectFuncs(pSelect, SQL_CLAUSE_SELECT, fmIsVectorFunc, &pInterpFunc->pFuncs);
|
int32_t code = nodesCollectFuncs(pSelect, SQL_CLAUSE_SELECT, isInterpFunc, &pInterpFunc->pFuncs);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = rewriteExprsForSelect(pInterpFunc->pFuncs, pSelect, SQL_CLAUSE_SELECT);
|
code = rewriteExprsForSelect(pInterpFunc->pFuncs, pSelect, SQL_CLAUSE_SELECT);
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,9 @@ int32_t streamBroadcastToChildren(SStreamTask* pTask, const SSDataBlock* pBlock)
|
||||||
|
|
||||||
int32_t tEncodeStreamRetrieveReq(SEncoder* pEncoder, const SStreamRetrieveReq* pReq);
|
int32_t tEncodeStreamRetrieveReq(SEncoder* pEncoder, const SStreamRetrieveReq* pReq);
|
||||||
|
|
||||||
|
int32_t streamDispatchOneRecoverFinishReq(SStreamTask* pTask, const SStreamRecoverFinishReq* pReq, int32_t vgId,
|
||||||
|
SEpSet* pEpSet);
|
||||||
|
|
||||||
SStreamQueueItem* streamMergeQueueItem(SStreamQueueItem* dst, SStreamQueueItem* elem);
|
SStreamQueueItem* streamMergeQueueItem(SStreamQueueItem* dst, SStreamQueueItem* elem);
|
||||||
void streamFreeQitem(SStreamQueueItem* data);
|
void streamFreeQitem(SStreamQueueItem* data);
|
||||||
|
|
||||||
|
|
|
@ -239,7 +239,7 @@ int32_t streamDispatchOneRecoverFinishReq(SStreamTask* pTask, const SStreamRecov
|
||||||
|
|
||||||
msg.contLen = tlen + sizeof(SMsgHead);
|
msg.contLen = tlen + sizeof(SMsgHead);
|
||||||
msg.pCont = buf;
|
msg.pCont = buf;
|
||||||
msg.msgType = TDMT_VND_STREAM_RECOVER_FINISH;
|
msg.msgType = TDMT_STREAM_RECOVER_FINISH;
|
||||||
|
|
||||||
tmsgSendReq(pEpSet, &msg);
|
tmsgSendReq(pEpSet, &msg);
|
||||||
|
|
||||||
|
@ -250,7 +250,7 @@ FAIL:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t streamDispatchOneReq(SStreamTask* pTask, const SStreamDispatchReq* pReq, int32_t vgId, SEpSet* pEpSet) {
|
int32_t streamDispatchOneDataReq(SStreamTask* pTask, const SStreamDispatchReq* pReq, int32_t vgId, SEpSet* pEpSet) {
|
||||||
void* buf = NULL;
|
void* buf = NULL;
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
SRpcMsg msg = {0};
|
SRpcMsg msg = {0};
|
||||||
|
@ -292,13 +292,19 @@ FAIL:
|
||||||
|
|
||||||
int32_t streamSearchAndAddBlock(SStreamTask* pTask, SStreamDispatchReq* pReqs, SSDataBlock* pDataBlock, int32_t vgSz,
|
int32_t streamSearchAndAddBlock(SStreamTask* pTask, SStreamDispatchReq* pReqs, SSDataBlock* pDataBlock, int32_t vgSz,
|
||||||
int64_t groupId) {
|
int64_t groupId) {
|
||||||
char* ctbName;
|
char* ctbName = taosMemoryCalloc(1, TSDB_TABLE_FNAME_LEN);
|
||||||
|
if (ctbName == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (pDataBlock->info.parTbName[0]) {
|
if (pDataBlock->info.parTbName[0]) {
|
||||||
ctbName = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN);
|
|
||||||
snprintf(ctbName, TSDB_TABLE_NAME_LEN, "%s.%s", pTask->shuffleDispatcher.dbInfo.db, pDataBlock->info.parTbName);
|
snprintf(ctbName, TSDB_TABLE_NAME_LEN, "%s.%s", pTask->shuffleDispatcher.dbInfo.db, pDataBlock->info.parTbName);
|
||||||
} else {
|
} else {
|
||||||
ctbName = buildCtbNameByGroupId(pTask->shuffleDispatcher.stbFullName, groupId);
|
char* ctbShortName = buildCtbNameByGroupId(pTask->shuffleDispatcher.stbFullName, groupId);
|
||||||
|
snprintf(ctbName, TSDB_TABLE_NAME_LEN, "%s.%s", pTask->shuffleDispatcher.dbInfo.db, ctbShortName);
|
||||||
|
taosMemoryFree(ctbShortName);
|
||||||
}
|
}
|
||||||
|
|
||||||
SArray* vgInfo = pTask->shuffleDispatcher.dbInfo.pVgroupInfos;
|
SArray* vgInfo = pTask->shuffleDispatcher.dbInfo.pVgroupInfos;
|
||||||
|
|
||||||
/*uint32_t hashValue = MurmurHash3_32(ctbName, strlen(ctbName));*/
|
/*uint32_t hashValue = MurmurHash3_32(ctbName, strlen(ctbName));*/
|
||||||
|
@ -365,7 +371,7 @@ int32_t streamDispatchAllBlocks(SStreamTask* pTask, const SStreamDataBlock* pDat
|
||||||
qDebug("dispatch from task %d (child id %d) to down stream task %d in vnode %d", pTask->taskId, pTask->selfChildId,
|
qDebug("dispatch from task %d (child id %d) to down stream task %d in vnode %d", pTask->taskId, pTask->selfChildId,
|
||||||
downstreamTaskId, vgId);
|
downstreamTaskId, vgId);
|
||||||
|
|
||||||
if (streamDispatchOneReq(pTask, &req, vgId, pEpSet) < 0) {
|
if (streamDispatchOneDataReq(pTask, &req, vgId, pEpSet) < 0) {
|
||||||
goto FAIL_FIXED_DISPATCH;
|
goto FAIL_FIXED_DISPATCH;
|
||||||
}
|
}
|
||||||
code = 0;
|
code = 0;
|
||||||
|
@ -427,7 +433,7 @@ int32_t streamDispatchAllBlocks(SStreamTask* pTask, const SStreamDataBlock* pDat
|
||||||
if (pReqs[i].blockNum > 0) {
|
if (pReqs[i].blockNum > 0) {
|
||||||
// send
|
// send
|
||||||
SVgroupInfo* pVgInfo = taosArrayGet(vgInfo, i);
|
SVgroupInfo* pVgInfo = taosArrayGet(vgInfo, i);
|
||||||
if (streamDispatchOneReq(pTask, &pReqs[i], pVgInfo->vgId, &pVgInfo->epSet) < 0) {
|
if (streamDispatchOneDataReq(pTask, &pReqs[i], pVgInfo->vgId, &pVgInfo->epSet) < 0) {
|
||||||
goto FAIL_SHUFFLE_DISPATCH;
|
goto FAIL_SHUFFLE_DISPATCH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,6 +90,8 @@ int32_t streamScanExec(SStreamTask* pTask, int32_t batchSz) {
|
||||||
|
|
||||||
void* exec = pTask->exec.executor;
|
void* exec = pTask->exec.executor;
|
||||||
|
|
||||||
|
qSetStreamOpOpen(exec);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
SArray* pRes = taosArrayInit(0, sizeof(SSDataBlock));
|
SArray* pRes = taosArrayInit(0, sizeof(SSDataBlock));
|
||||||
if (pRes == NULL) {
|
if (pRes == NULL) {
|
||||||
|
@ -127,7 +129,10 @@ int32_t streamScanExec(SStreamTask* pTask, int32_t batchSz) {
|
||||||
qRes->type = STREAM_INPUT__DATA_BLOCK;
|
qRes->type = STREAM_INPUT__DATA_BLOCK;
|
||||||
qRes->blocks = pRes;
|
qRes->blocks = pRes;
|
||||||
streamTaskOutput(pTask, qRes);
|
streamTaskOutput(pTask, qRes);
|
||||||
// TODO stream sched dispatch
|
|
||||||
|
if (pTask->outputType == TASK_OUTPUT__FIXED_DISPATCH || pTask->outputType == TASK_OUTPUT__SHUFFLE_DISPATCH) {
|
||||||
|
streamDispatch(pTask);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ int32_t streamSourceRecoverPrepareStep1(SStreamTask* pTask, int64_t ver) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t streamBuildSourceRecover1Req(SStreamTask* pTask, SStreamRecoverStep1Req* pReq) {
|
int32_t streamBuildSourceRecover1Req(SStreamTask* pTask, SStreamRecoverStep1Req* pReq) {
|
||||||
|
pReq->msgHead.vgId = pTask->nodeId;
|
||||||
pReq->streamId = pTask->streamId;
|
pReq->streamId = pTask->streamId;
|
||||||
pReq->taskId = pTask->taskId;
|
pReq->taskId = pTask->taskId;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -44,10 +45,10 @@ int32_t streamBuildSourceRecover1Req(SStreamTask* pTask, SStreamRecoverStep1Req*
|
||||||
int32_t streamSourceRecoverScanStep1(SStreamTask* pTask) {
|
int32_t streamSourceRecoverScanStep1(SStreamTask* pTask) {
|
||||||
//
|
//
|
||||||
return streamScanExec(pTask, 100);
|
return streamScanExec(pTask, 100);
|
||||||
// TODO next: dispatch msg to launch scan step2
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t streamBuildSourceRecover2Req(SStreamTask* pTask, SStreamRecoverStep2Req* pReq) {
|
int32_t streamBuildSourceRecover2Req(SStreamTask* pTask, SStreamRecoverStep2Req* pReq) {
|
||||||
|
pReq->msgHead.vgId = pTask->nodeId;
|
||||||
pReq->streamId = pTask->streamId;
|
pReq->streamId = pTask->streamId;
|
||||||
pReq->taskId = pTask->taskId;
|
pReq->taskId = pTask->taskId;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -64,11 +65,20 @@ int32_t streamSourceRecoverScanStep2(SStreamTask* pTask, int64_t ver) {
|
||||||
int32_t streamDispatchRecoverFinishReq(SStreamTask* pTask) {
|
int32_t streamDispatchRecoverFinishReq(SStreamTask* pTask) {
|
||||||
SStreamRecoverFinishReq req = {
|
SStreamRecoverFinishReq req = {
|
||||||
.streamId = pTask->streamId,
|
.streamId = pTask->streamId,
|
||||||
.taskId = pTask->taskId,
|
|
||||||
.childId = pTask->selfChildId,
|
.childId = pTask->selfChildId,
|
||||||
};
|
};
|
||||||
|
// serialize
|
||||||
if (pTask->outputType == TASK_OUTPUT__FIXED_DISPATCH) {
|
if (pTask->outputType == TASK_OUTPUT__FIXED_DISPATCH) {
|
||||||
|
req.taskId = pTask->fixedEpDispatcher.taskId;
|
||||||
|
streamDispatchOneRecoverFinishReq(pTask, &req, pTask->fixedEpDispatcher.nodeId, &pTask->fixedEpDispatcher.epSet);
|
||||||
} else if (pTask->outputType == TASK_OUTPUT__SHUFFLE_DISPATCH) {
|
} else if (pTask->outputType == TASK_OUTPUT__SHUFFLE_DISPATCH) {
|
||||||
|
SArray* vgInfo = pTask->shuffleDispatcher.dbInfo.pVgroupInfos;
|
||||||
|
int32_t vgSz = taosArrayGetSize(vgInfo);
|
||||||
|
for (int32_t i = 0; i < vgSz; i++) {
|
||||||
|
SVgroupInfo* pVgInfo = taosArrayGet(vgInfo, i);
|
||||||
|
req.taskId = pVgInfo->taskId;
|
||||||
|
streamDispatchOneRecoverFinishReq(pTask, &req, pVgInfo->vgId, &pVgInfo->epSet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -76,9 +86,9 @@ int32_t streamDispatchRecoverFinishReq(SStreamTask* pTask) {
|
||||||
// agg
|
// agg
|
||||||
int32_t streamAggRecoverPrepare(SStreamTask* pTask) {
|
int32_t streamAggRecoverPrepare(SStreamTask* pTask) {
|
||||||
void* exec = pTask->exec.executor;
|
void* exec = pTask->exec.executor;
|
||||||
if (qStreamSetParamForRecover(exec) < 0) {
|
/*if (qStreamSetParamForRecover(exec) < 0) {*/
|
||||||
return -1;
|
/*return -1;*/
|
||||||
}
|
/*}*/
|
||||||
pTask->recoverWaitingChild = taosArrayGetSize(pTask->childEpInfo);
|
pTask->recoverWaitingChild = taosArrayGetSize(pTask->childEpInfo);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -96,10 +106,12 @@ int32_t streamAggChildrenRecoverFinish(SStreamTask* pTask) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t streamProcessRecoverFinishReq(SStreamTask* pTask, int32_t childId) {
|
int32_t streamProcessRecoverFinishReq(SStreamTask* pTask, int32_t childId) {
|
||||||
int32_t left = atomic_sub_fetch_32(&pTask->recoverWaitingChild, 1);
|
if (pTask->taskLevel == TASK_LEVEL__AGG) {
|
||||||
ASSERT(left >= 0);
|
int32_t left = atomic_sub_fetch_32(&pTask->recoverWaitingChild, 1);
|
||||||
if (left == 0) {
|
ASSERT(left >= 0);
|
||||||
streamAggChildrenRecoverFinish(pTask);
|
if (left == 0) {
|
||||||
|
streamAggChildrenRecoverFinish(pTask);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ typedef struct SSyncEnv {
|
||||||
} SSyncEnv;
|
} SSyncEnv;
|
||||||
|
|
||||||
SSyncEnv* syncEnv();
|
SSyncEnv* syncEnv();
|
||||||
|
bool syncIsInit();
|
||||||
|
|
||||||
int64_t syncNodeAdd(SSyncNode* pNode);
|
int64_t syncNodeAdd(SSyncNode* pNode);
|
||||||
void syncNodeRemove(int64_t rid);
|
void syncNodeRemove(int64_t rid);
|
||||||
|
|
|
@ -22,9 +22,9 @@ extern "C" {
|
||||||
|
|
||||||
#include "sync.h"
|
#include "sync.h"
|
||||||
#include "syncTools.h"
|
#include "syncTools.h"
|
||||||
#include "tlog.h"
|
|
||||||
#include "ttimer.h"
|
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
|
#include "tlog.h"
|
||||||
|
#include "trpc.h"
|
||||||
#include "ttimer.h"
|
#include "ttimer.h"
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
@ -107,9 +107,9 @@ typedef struct SSyncNode {
|
||||||
// sync io
|
// sync io
|
||||||
SWal* pWal;
|
SWal* pWal;
|
||||||
const SMsgCb* msgcb;
|
const SMsgCb* msgcb;
|
||||||
int32_t (*FpSendMsg)(const SEpSet* pEpSet, SRpcMsg* pMsg);
|
int32_t (*syncSendMSg)(const SEpSet* pEpSet, SRpcMsg* pMsg);
|
||||||
int32_t (*FpEqMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg);
|
int32_t (*syncEqMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg);
|
||||||
int32_t (*FpEqCtrlMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg);
|
int32_t (*syncEqCtrlMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg);
|
||||||
|
|
||||||
// init internal
|
// init internal
|
||||||
SNodeInfo myNodeInfo;
|
SNodeInfo myNodeInfo;
|
||||||
|
@ -302,7 +302,6 @@ int32_t syncGetSnapshotMeta(int64_t rid, struct SSnapshotMeta* sMeta);
|
||||||
int32_t syncGetSnapshotMetaByIndex(int64_t rid, SyncIndex snapshotIndex, struct SSnapshotMeta* sMeta);
|
int32_t syncGetSnapshotMetaByIndex(int64_t rid, SyncIndex snapshotIndex, struct SSnapshotMeta* sMeta);
|
||||||
|
|
||||||
bool syncNodeCanChange(SSyncNode* pSyncNode);
|
bool syncNodeCanChange(SSyncNode* pSyncNode);
|
||||||
bool syncNodeCheckNewConfig(SSyncNode* pSyncNode, const SSyncCfg* pNewCfg);
|
|
||||||
|
|
||||||
int32_t syncNodeLeaderTransfer(SSyncNode* pSyncNode);
|
int32_t syncNodeLeaderTransfer(SSyncNode* pSyncNode);
|
||||||
int32_t syncNodeLeaderTransferTo(SSyncNode* pSyncNode, SNodeInfo newLeader);
|
int32_t syncNodeLeaderTransferTo(SSyncNode* pSyncNode, SNodeInfo newLeader);
|
||||||
|
@ -315,6 +314,7 @@ int32_t syncNodePeerStateInit(SSyncNode* pSyncNode);
|
||||||
|
|
||||||
// trace log
|
// trace log
|
||||||
void syncLogRecvTimer(SSyncNode* pSyncNode, const SyncTimeout* pMsg, const char* s);
|
void syncLogRecvTimer(SSyncNode* pSyncNode, const SyncTimeout* pMsg, const char* s);
|
||||||
|
void syncLogRecvLocalCmd(SSyncNode* pSyncNode, const SyncLocalCmd* pMsg, const char* s);
|
||||||
|
|
||||||
void syncLogSendRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s);
|
void syncLogSendRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s);
|
||||||
void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s);
|
void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s);
|
||||||
|
@ -337,7 +337,17 @@ void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const
|
||||||
void syncLogSendHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s);
|
void syncLogSendHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s);
|
||||||
void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s);
|
void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s);
|
||||||
|
|
||||||
void syncLogRecvLocalCmd(SSyncNode* pSyncNode, const SyncLocalCmd* pMsg, const char* s);
|
void syncLogSendSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s);
|
||||||
|
void syncLogRecvSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s);
|
||||||
|
|
||||||
|
void syncLogSendSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshotReply* pMsg, const char* s);
|
||||||
|
void syncLogRecvSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshotReply* pMsg, const char* s);
|
||||||
|
|
||||||
|
void syncLogSendSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s);
|
||||||
|
void syncLogRecvSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s);
|
||||||
|
|
||||||
|
void syncLogSendSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s);
|
||||||
|
void syncLogRecvSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s);
|
||||||
|
|
||||||
// for debug --------------
|
// for debug --------------
|
||||||
void syncNodePrint(SSyncNode* pObj);
|
void syncNodePrint(SSyncNode* pObj);
|
||||||
|
|
|
@ -28,10 +28,11 @@ extern "C" {
|
||||||
#include "syncMessage.h"
|
#include "syncMessage.h"
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
|
|
||||||
#define SYNC_SNAPSHOT_SEQ_INVALID -1
|
#define SYNC_SNAPSHOT_SEQ_INVALID -2
|
||||||
#define SYNC_SNAPSHOT_SEQ_FORCE_CLOSE -2
|
#define SYNC_SNAPSHOT_SEQ_FORCE_CLOSE -3
|
||||||
#define SYNC_SNAPSHOT_SEQ_BEGIN 0
|
#define SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT -1
|
||||||
#define SYNC_SNAPSHOT_SEQ_END 0x7FFFFFFF
|
#define SYNC_SNAPSHOT_SEQ_BEGIN 0
|
||||||
|
#define SYNC_SNAPSHOT_SEQ_END 0x7FFFFFFF
|
||||||
|
|
||||||
#define SYNC_SNAPSHOT_RETRY_MS 5000
|
#define SYNC_SNAPSHOT_RETRY_MS 5000
|
||||||
|
|
||||||
|
@ -47,19 +48,19 @@ typedef struct SSyncSnapshotSender {
|
||||||
SSnapshot snapshot;
|
SSnapshot snapshot;
|
||||||
SSyncCfg lastConfig;
|
SSyncCfg lastConfig;
|
||||||
int64_t sendingMS;
|
int64_t sendingMS;
|
||||||
SSyncNode *pSyncNode;
|
|
||||||
int32_t replicaIndex;
|
|
||||||
SyncTerm term;
|
SyncTerm term;
|
||||||
SyncTerm privateTerm;
|
|
||||||
int64_t startTime;
|
int64_t startTime;
|
||||||
bool finish;
|
bool finish;
|
||||||
|
|
||||||
|
// init when create
|
||||||
|
SSyncNode *pSyncNode;
|
||||||
|
int32_t replicaIndex;
|
||||||
} SSyncSnapshotSender;
|
} SSyncSnapshotSender;
|
||||||
|
|
||||||
SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaIndex);
|
SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaIndex);
|
||||||
void snapshotSenderDestroy(SSyncSnapshotSender *pSender);
|
void snapshotSenderDestroy(SSyncSnapshotSender *pSender);
|
||||||
bool snapshotSenderIsStart(SSyncSnapshotSender *pSender);
|
bool snapshotSenderIsStart(SSyncSnapshotSender *pSender);
|
||||||
int32_t snapshotSenderStart(SSyncSnapshotSender *pSender, SSnapshotParam snapshotParam, SSnapshot snapshot,
|
int32_t snapshotSenderStart(SSyncSnapshotSender *pSender);
|
||||||
void *pReader);
|
|
||||||
int32_t snapshotSenderStop(SSyncSnapshotSender *pSender, bool finish);
|
int32_t snapshotSenderStop(SSyncSnapshotSender *pSender, bool finish);
|
||||||
int32_t snapshotSend(SSyncSnapshotSender *pSender);
|
int32_t snapshotSend(SSyncSnapshotSender *pSender);
|
||||||
int32_t snapshotReSend(SSyncSnapshotSender *pSender);
|
int32_t snapshotReSend(SSyncSnapshotSender *pSender);
|
||||||
|
@ -76,11 +77,13 @@ typedef struct SSyncSnapshotReceiver {
|
||||||
int32_t ack;
|
int32_t ack;
|
||||||
void *pWriter;
|
void *pWriter;
|
||||||
SyncTerm term;
|
SyncTerm term;
|
||||||
SyncTerm privateTerm;
|
|
||||||
SSnapshotParam snapshotParam;
|
SSnapshotParam snapshotParam;
|
||||||
SSnapshot snapshot;
|
SSnapshot snapshot;
|
||||||
SRaftId fromId;
|
SRaftId fromId;
|
||||||
SSyncNode *pSyncNode;
|
int64_t startTime;
|
||||||
|
|
||||||
|
// init when create
|
||||||
|
SSyncNode *pSyncNode;
|
||||||
|
|
||||||
} SSyncSnapshotReceiver;
|
} SSyncSnapshotReceiver;
|
||||||
|
|
||||||
|
|
|
@ -20,30 +20,17 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "trpc.h"
|
|
||||||
|
|
||||||
// ------------------ ds -------------------
|
// ------------------ ds -------------------
|
||||||
typedef struct SRaftId {
|
typedef struct SRaftId {
|
||||||
SyncNodeId addr;
|
SyncNodeId addr;
|
||||||
SyncGroupId vgId;
|
SyncGroupId vgId;
|
||||||
} SRaftId;
|
} SRaftId;
|
||||||
|
|
||||||
int32_t syncGetRespRpc(int64_t rid, uint64_t index, SRpcMsg* msg);
|
char* sync2SimpleStr(int64_t rid);
|
||||||
int32_t syncGetAndDelRespRpc(int64_t rid, uint64_t index, SRpcHandleInfo* pInfo);
|
|
||||||
void syncSetMsgCb(int64_t rid, const SMsgCb* msgcb);
|
|
||||||
char* sync2SimpleStr(int64_t rid);
|
|
||||||
|
|
||||||
// set timer ms
|
|
||||||
void setPingTimerMS(int64_t rid, int32_t pingTimerMS);
|
|
||||||
void setElectTimerMS(int64_t rid, int32_t electTimerMS);
|
|
||||||
void setHeartbeatTimerMS(int64_t rid, int32_t hbTimerMS);
|
|
||||||
|
|
||||||
// for compatibility, the same as syncPropose
|
// for compatibility, the same as syncPropose
|
||||||
int32_t syncForwardToPeer(int64_t rid, SRpcMsg* pMsg, bool isWeak);
|
int32_t syncForwardToPeer(int64_t rid, SRpcMsg* pMsg, bool isWeak);
|
||||||
|
|
||||||
// utils
|
|
||||||
const char* syncUtilState2String(ESyncState state);
|
|
||||||
|
|
||||||
// ------------------ for debug -------------------
|
// ------------------ for debug -------------------
|
||||||
void syncRpcMsgPrint(SRpcMsg* pMsg);
|
void syncRpcMsgPrint(SRpcMsg* pMsg);
|
||||||
void syncRpcMsgPrint2(char* s, SRpcMsg* pMsg);
|
void syncRpcMsgPrint2(char* s, SRpcMsg* pMsg);
|
||||||
|
@ -509,6 +496,69 @@ void syncHeartbeatReplyPrint2(char* s, const SyncHeartbeatReply* pMsg);
|
||||||
void syncHeartbeatReplyLog(const SyncHeartbeatReply* pMsg);
|
void syncHeartbeatReplyLog(const SyncHeartbeatReply* pMsg);
|
||||||
void syncHeartbeatReplyLog2(char* s, const SyncHeartbeatReply* pMsg);
|
void syncHeartbeatReplyLog2(char* s, const SyncHeartbeatReply* pMsg);
|
||||||
|
|
||||||
|
// ---------------------------------------------
|
||||||
|
typedef struct SyncPreSnapshot {
|
||||||
|
uint32_t bytes;
|
||||||
|
int32_t vgId;
|
||||||
|
uint32_t msgType;
|
||||||
|
SRaftId srcId;
|
||||||
|
SRaftId destId;
|
||||||
|
|
||||||
|
// private data
|
||||||
|
SyncTerm term;
|
||||||
|
|
||||||
|
} SyncPreSnapshot;
|
||||||
|
|
||||||
|
SyncPreSnapshot* syncPreSnapshotBuild(int32_t vgId);
|
||||||
|
void syncPreSnapshotDestroy(SyncPreSnapshot* pMsg);
|
||||||
|
void syncPreSnapshotSerialize(const SyncPreSnapshot* pMsg, char* buf, uint32_t bufLen);
|
||||||
|
void syncPreSnapshotDeserialize(const char* buf, uint32_t len, SyncPreSnapshot* pMsg);
|
||||||
|
char* syncPreSnapshotSerialize2(const SyncPreSnapshot* pMsg, uint32_t* len);
|
||||||
|
SyncPreSnapshot* syncPreSnapshotDeserialize2(const char* buf, uint32_t len);
|
||||||
|
void syncPreSnapshot2RpcMsg(const SyncPreSnapshot* pMsg, SRpcMsg* pRpcMsg);
|
||||||
|
void syncPreSnapshotFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPreSnapshot* pMsg);
|
||||||
|
SyncPreSnapshot* syncPreSnapshotFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||||
|
cJSON* syncPreSnapshot2Json(const SyncPreSnapshot* pMsg);
|
||||||
|
char* syncPreSnapshot2Str(const SyncPreSnapshot* pMsg);
|
||||||
|
|
||||||
|
// for debug ----------------------
|
||||||
|
void syncPreSnapshotPrint(const SyncPreSnapshot* pMsg);
|
||||||
|
void syncPreSnapshotPrint2(char* s, const SyncPreSnapshot* pMsg);
|
||||||
|
void syncPreSnapshotLog(const SyncPreSnapshot* pMsg);
|
||||||
|
void syncPreSnapshotLog2(char* s, const SyncPreSnapshot* pMsg);
|
||||||
|
|
||||||
|
// ---------------------------------------------
|
||||||
|
typedef struct SyncPreSnapshotReply {
|
||||||
|
uint32_t bytes;
|
||||||
|
int32_t vgId;
|
||||||
|
uint32_t msgType;
|
||||||
|
SRaftId srcId;
|
||||||
|
SRaftId destId;
|
||||||
|
|
||||||
|
// private data
|
||||||
|
SyncTerm term;
|
||||||
|
SyncIndex snapStart;
|
||||||
|
|
||||||
|
} SyncPreSnapshotReply;
|
||||||
|
|
||||||
|
SyncPreSnapshotReply* syncPreSnapshotReplyBuild(int32_t vgId);
|
||||||
|
void syncPreSnapshotReplyDestroy(SyncPreSnapshotReply* pMsg);
|
||||||
|
void syncPreSnapshotReplySerialize(const SyncPreSnapshotReply* pMsg, char* buf, uint32_t bufLen);
|
||||||
|
void syncPreSnapshotReplyDeserialize(const char* buf, uint32_t len, SyncPreSnapshotReply* pMsg);
|
||||||
|
char* syncPreSnapshotReplySerialize2(const SyncPreSnapshotReply* pMsg, uint32_t* len);
|
||||||
|
SyncPreSnapshotReply* syncPreSnapshotReplyDeserialize2(const char* buf, uint32_t len);
|
||||||
|
void syncPreSnapshotReply2RpcMsg(const SyncPreSnapshotReply* pMsg, SRpcMsg* pRpcMsg);
|
||||||
|
void syncPreSnapshotReplyFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPreSnapshotReply* pMsg);
|
||||||
|
SyncPreSnapshotReply* syncPreSnapshotReplyFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||||
|
cJSON* syncPreSnapshotReply2Json(const SyncPreSnapshotReply* pMsg);
|
||||||
|
char* syncPreSnapshotReply2Str(const SyncPreSnapshotReply* pMsg);
|
||||||
|
|
||||||
|
// for debug ----------------------
|
||||||
|
void syncPreSnapshotReplyPrint(const SyncPreSnapshotReply* pMsg);
|
||||||
|
void syncPreSnapshotReplyPrint2(char* s, const SyncPreSnapshotReply* pMsg);
|
||||||
|
void syncPreSnapshotReplyLog(const SyncPreSnapshotReply* pMsg);
|
||||||
|
void syncPreSnapshotReplyLog2(char* s, const SyncPreSnapshotReply* pMsg);
|
||||||
|
|
||||||
// ---------------------------------------------
|
// ---------------------------------------------
|
||||||
typedef struct SyncApplyMsg {
|
typedef struct SyncApplyMsg {
|
||||||
uint32_t bytes;
|
uint32_t bytes;
|
||||||
|
@ -554,7 +604,7 @@ typedef struct SyncSnapshotSend {
|
||||||
SyncTerm lastTerm; // snapshot.lastTerm
|
SyncTerm lastTerm; // snapshot.lastTerm
|
||||||
SyncIndex lastConfigIndex; // snapshot.lastConfigIndex
|
SyncIndex lastConfigIndex; // snapshot.lastConfigIndex
|
||||||
SSyncCfg lastConfig;
|
SSyncCfg lastConfig;
|
||||||
SyncTerm privateTerm;
|
int64_t startTime;
|
||||||
int32_t seq;
|
int32_t seq;
|
||||||
uint32_t dataLen;
|
uint32_t dataLen;
|
||||||
char data[];
|
char data[];
|
||||||
|
@ -589,9 +639,10 @@ typedef struct SyncSnapshotRsp {
|
||||||
SyncTerm term;
|
SyncTerm term;
|
||||||
SyncIndex lastIndex;
|
SyncIndex lastIndex;
|
||||||
SyncTerm lastTerm;
|
SyncTerm lastTerm;
|
||||||
SyncTerm privateTerm;
|
int64_t startTime;
|
||||||
int32_t ack;
|
int32_t ack;
|
||||||
int32_t code;
|
int32_t code;
|
||||||
|
SyncIndex snapBeginIndex; // when ack = SYNC_SNAPSHOT_SEQ_BEGIN, it's valid
|
||||||
} SyncSnapshotRsp;
|
} SyncSnapshotRsp;
|
||||||
|
|
||||||
SyncSnapshotRsp* syncSnapshotRspBuild(int32_t vgId);
|
SyncSnapshotRsp* syncSnapshotRspBuild(int32_t vgId);
|
||||||
|
@ -722,6 +773,9 @@ int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, SyncRequestVoteReply* pMsg);
|
||||||
int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg);
|
int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg);
|
||||||
int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
||||||
|
|
||||||
|
int32_t syncNodeOnPreSnapshot(SSyncNode* ths, SyncPreSnapshot* pMsg);
|
||||||
|
int32_t syncNodeOnPreSnapshotReply(SSyncNode* ths, SyncPreSnapshotReply* pMsg);
|
||||||
|
|
||||||
int32_t syncNodeOnSnapshot(SSyncNode* ths, SyncSnapshotSend* pMsg);
|
int32_t syncNodeOnSnapshot(SSyncNode* ths, SyncSnapshotSend* pMsg);
|
||||||
int32_t syncNodeOnSnapshotReply(SSyncNode* ths, SyncSnapshotRsp* pMsg);
|
int32_t syncNodeOnSnapshotReply(SSyncNode* ths, SyncSnapshotRsp* pMsg);
|
||||||
|
|
|
@ -49,7 +49,7 @@ int32_t syncUtilQuorum(int32_t replicaNum);
|
||||||
cJSON* syncUtilNodeInfo2Json(const SNodeInfo* p);
|
cJSON* syncUtilNodeInfo2Json(const SNodeInfo* p);
|
||||||
cJSON* syncUtilRaftId2Json(const SRaftId* p);
|
cJSON* syncUtilRaftId2Json(const SRaftId* p);
|
||||||
char* syncUtilRaftId2Str(const SRaftId* p);
|
char* syncUtilRaftId2Str(const SRaftId* p);
|
||||||
const char* syncUtilState2String(ESyncState state);
|
const char* syncStr(ESyncState state);
|
||||||
bool syncUtilCanPrint(char c);
|
bool syncUtilCanPrint(char c);
|
||||||
char* syncUtilprintBin(char* ptr, uint32_t len);
|
char* syncUtilprintBin(char* ptr, uint32_t len);
|
||||||
char* syncUtilprintBin2(char* ptr, uint32_t len);
|
char* syncUtilprintBin2(char* ptr, uint32_t len);
|
||||||
|
|
|
@ -142,7 +142,6 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
||||||
// pReply->matchIndex = ths->pLogStore->syncLogLastIndex(ths->pLogStore);
|
// pReply->matchIndex = ths->pLogStore->syncLogLastIndex(ths->pLogStore);
|
||||||
pReply->matchIndex = SYNC_INDEX_INVALID;
|
pReply->matchIndex = SYNC_INDEX_INVALID;
|
||||||
pReply->lastSendIndex = pMsg->prevLogIndex + 1;
|
pReply->lastSendIndex = pMsg->prevLogIndex + 1;
|
||||||
pReply->privateTerm = ths->pNewNodeReceiver->privateTerm;
|
|
||||||
pReply->startTime = ths->startTime;
|
pReply->startTime = ths->startTime;
|
||||||
|
|
||||||
if (pMsg->term < ths->pRaftStore->currentTerm) {
|
if (pMsg->term < ths->pRaftStore->currentTerm) {
|
||||||
|
|
|
@ -73,6 +73,7 @@ static void syncNodeStartSnapshotOnce(SSyncNode* ths, SyncIndex beginIndex, Sync
|
||||||
int32_t code = ths->pFsm->FpSnapshotStartRead(ths->pFsm, &readerParam, &pReader);
|
int32_t code = ths->pFsm->FpSnapshotStartRead(ths->pFsm, &readerParam, &pReader);
|
||||||
ASSERT(code == 0);
|
ASSERT(code == 0);
|
||||||
|
|
||||||
|
#if 0
|
||||||
if (pMsg->privateTerm < pSender->privateTerm) {
|
if (pMsg->privateTerm < pSender->privateTerm) {
|
||||||
ASSERT(pReader != NULL);
|
ASSERT(pReader != NULL);
|
||||||
snapshotSenderStart(pSender, readerParam, snapshot, pReader);
|
snapshotSenderStart(pSender, readerParam, snapshot, pReader);
|
||||||
|
@ -82,6 +83,7 @@ static void syncNodeStartSnapshotOnce(SSyncNode* ths, SyncIndex beginIndex, Sync
|
||||||
ths->pFsm->FpSnapshotStopRead(ths->pFsm, pReader);
|
ths->pFsm->FpSnapshotStopRead(ths->pFsm, pReader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, SyncAppendEntriesReply* pMsg) {
|
int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, SyncAppendEntriesReply* pMsg) {
|
||||||
|
|
|
@ -80,6 +80,7 @@ SSyncNode *syncNodeAcquire(int64_t rid) {
|
||||||
SSyncNode *pNode = taosAcquireRef(gNodeRefId, rid);
|
SSyncNode *pNode = taosAcquireRef(gNodeRefId, rid);
|
||||||
if (pNode == NULL) {
|
if (pNode == NULL) {
|
||||||
sTrace("failed to acquire node from refId:%" PRId64, rid);
|
sTrace("failed to acquire node from refId:%" PRId64, rid);
|
||||||
|
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pNode;
|
return pNode;
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
#include "sync.h"
|
#include "sync.h"
|
||||||
#include "syncAppendEntries.h"
|
#include "syncAppendEntries.h"
|
||||||
#include "syncAppendEntriesReply.h"
|
#include "syncAppendEntriesReply.h"
|
||||||
|
@ -34,8 +35,6 @@
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
#include "syncVoteMgr.h"
|
#include "syncVoteMgr.h"
|
||||||
|
|
||||||
// ------ local funciton ---------
|
|
||||||
// enqueue message ----
|
|
||||||
static void syncNodeEqPingTimer(void* param, void* tmrId);
|
static void syncNodeEqPingTimer(void* param, void* tmrId);
|
||||||
static void syncNodeEqElectTimer(void* param, void* tmrId);
|
static void syncNodeEqElectTimer(void* param, void* tmrId);
|
||||||
static void syncNodeEqHeartbeatTimer(void* param, void* tmrId);
|
static void syncNodeEqHeartbeatTimer(void* param, void* tmrId);
|
||||||
|
@ -44,162 +43,155 @@ static int32_t syncNodeAppendNoop(SSyncNode* ths);
|
||||||
static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId);
|
static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId);
|
||||||
static bool syncIsConfigChanged(const SSyncCfg* pOldCfg, const SSyncCfg* pNewCfg);
|
static bool syncIsConfigChanged(const SSyncCfg* pOldCfg, const SSyncCfg* pNewCfg);
|
||||||
|
|
||||||
// process message ----
|
|
||||||
int32_t syncNodeOnPing(SSyncNode* ths, SyncPing* pMsg);
|
|
||||||
int32_t syncNodeOnPingReply(SSyncNode* ths, SyncPingReply* pMsg);
|
|
||||||
|
|
||||||
int64_t syncOpen(SSyncInfo* pSyncInfo) {
|
int64_t syncOpen(SSyncInfo* pSyncInfo) {
|
||||||
SSyncNode* pNode = syncNodeOpen(pSyncInfo);
|
SSyncNode* pSyncNode = syncNodeOpen(pSyncInfo);
|
||||||
if (pNode == NULL) {
|
if (pSyncNode == NULL) {
|
||||||
sError("vgId:%d, failed to open sync node", pSyncInfo->vgId);
|
sError("vgId:%d, failed to open sync node", pSyncInfo->vgId);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pNode->rid = syncNodeAdd(pNode);
|
pSyncNode->rid = syncNodeAdd(pSyncNode);
|
||||||
if (pNode->rid < 0) {
|
if (pSyncNode->rid < 0) {
|
||||||
syncNodeClose(pNode);
|
syncNodeClose(pSyncNode);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pNode->rid;
|
pSyncNode->pingBaseLine = pSyncInfo->pingMs;
|
||||||
|
pSyncNode->pingTimerMS = pSyncInfo->pingMs;
|
||||||
|
pSyncNode->electBaseLine = pSyncInfo->electMs;
|
||||||
|
pSyncNode->hbBaseLine = pSyncInfo->heartbeatMs;
|
||||||
|
pSyncNode->heartbeatTimerMS = pSyncInfo->heartbeatMs;
|
||||||
|
pSyncNode->msgcb = pSyncInfo->msgcb;
|
||||||
|
return pSyncNode->rid;
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncStart(int64_t rid) {
|
void syncStart(int64_t rid) {
|
||||||
SSyncNode* pNode = syncNodeAcquire(rid);
|
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||||
if (pNode != NULL) {
|
if (pSyncNode != NULL) {
|
||||||
syncNodeStart(pNode);
|
syncNodeStart(pSyncNode);
|
||||||
syncNodeRelease(pNode);
|
syncNodeRelease(pSyncNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncStop(int64_t rid) {
|
void syncStop(int64_t rid) {
|
||||||
SSyncNode* pNode = syncNodeAcquire(rid);
|
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||||
if (pNode != NULL) {
|
if (pSyncNode != NULL) {
|
||||||
syncNodeRelease(pNode);
|
syncNodeRelease(pSyncNode);
|
||||||
syncNodeRemove(rid);
|
syncNodeRemove(rid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool syncNodeCheckNewConfig(SSyncNode* pSyncNode, const SSyncCfg* pNewCfg) {
|
static bool syncNodeCheckNewConfig(SSyncNode* pSyncNode, const SSyncCfg* pCfg) {
|
||||||
bool IamInNew = syncNodeInConfig(pSyncNode, pNewCfg);
|
if (!syncNodeInConfig(pSyncNode, pCfg)) return false;
|
||||||
if (!IamInNew) {
|
return abs(pCfg->replicaNum - pSyncNode->replicaNum) <= 1;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pNewCfg->replicaNum > pSyncNode->replicaNum + 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pNewCfg->replicaNum < pSyncNode->replicaNum - 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t syncReconfigBuild(int64_t rid, const SSyncCfg* pNewCfg, SRpcMsg* pRpcMsg) {
|
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
|
||||||
if (pSyncNode == NULL) {
|
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
ASSERT(rid == pSyncNode->rid);
|
|
||||||
int32_t ret = 0;
|
|
||||||
|
|
||||||
if (!syncNodeCheckNewConfig(pSyncNode, pNewCfg)) {
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
terrno = TSDB_CODE_SYN_NEW_CONFIG_ERROR;
|
|
||||||
sError("invalid new config. vgId:%d", pSyncNode->vgId);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* newconfig = syncCfg2Str((SSyncCfg*)pNewCfg);
|
|
||||||
pRpcMsg->msgType = TDMT_SYNC_CONFIG_CHANGE;
|
|
||||||
pRpcMsg->info.noResp = 1;
|
|
||||||
pRpcMsg->contLen = strlen(newconfig) + 1;
|
|
||||||
pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
|
|
||||||
snprintf(pRpcMsg->pCont, pRpcMsg->contLen, "%s", newconfig);
|
|
||||||
taosMemoryFree(newconfig);
|
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncReconfig(int64_t rid, SSyncCfg* pNewCfg) {
|
int32_t syncReconfig(int64_t rid, SSyncCfg* pNewCfg) {
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||||
if (pSyncNode == NULL) {
|
if (pSyncNode == NULL) return -1;
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
ASSERT(rid == pSyncNode->rid);
|
|
||||||
|
|
||||||
if (!syncNodeCheckNewConfig(pSyncNode, pNewCfg)) {
|
if (!syncNodeCheckNewConfig(pSyncNode, pNewCfg)) {
|
||||||
syncNodeRelease(pSyncNode);
|
syncNodeRelease(pSyncNode);
|
||||||
terrno = TSDB_CODE_SYN_NEW_CONFIG_ERROR;
|
terrno = TSDB_CODE_SYN_NEW_CONFIG_ERROR;
|
||||||
sError("invalid new config. vgId:%d", pSyncNode->vgId);
|
sError("vgId:%d, failed to reconfig since invalid new config", pSyncNode->vgId);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
char* newconfig = syncCfg2Str((SSyncCfg*)pNewCfg);
|
|
||||||
int32_t ret = 0;
|
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
|
||||||
rpcMsg.msgType = TDMT_SYNC_CONFIG_CHANGE;
|
|
||||||
rpcMsg.info.noResp = 1;
|
|
||||||
rpcMsg.contLen = strlen(newconfig) + 1;
|
|
||||||
rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen);
|
|
||||||
snprintf(rpcMsg.pCont, rpcMsg.contLen, "%s", newconfig);
|
|
||||||
taosMemoryFree(newconfig);
|
|
||||||
ret = syncNodePropose(pSyncNode, &rpcMsg, false);
|
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
return ret;
|
|
||||||
#else
|
|
||||||
syncNodeUpdateNewConfigIndex(pSyncNode, pNewCfg);
|
syncNodeUpdateNewConfigIndex(pSyncNode, pNewCfg);
|
||||||
syncNodeDoConfigChange(pSyncNode, pNewCfg, SYNC_INDEX_INVALID);
|
syncNodeDoConfigChange(pSyncNode, pNewCfg, SYNC_INDEX_INVALID);
|
||||||
|
|
||||||
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
|
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
|
||||||
syncNodeStopHeartbeatTimer(pSyncNode);
|
syncNodeStopHeartbeatTimer(pSyncNode);
|
||||||
|
|
||||||
for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
|
for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
|
||||||
syncHbTimerInit(pSyncNode, &(pSyncNode->peerHeartbeatTimerArr[i]), (pSyncNode->replicasId)[i]);
|
syncHbTimerInit(pSyncNode, &pSyncNode->peerHeartbeatTimerArr[i], pSyncNode->replicasId[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
syncNodeStartHeartbeatTimer(pSyncNode);
|
syncNodeStartHeartbeatTimer(pSyncNode);
|
||||||
|
|
||||||
syncNodeReplicate(pSyncNode);
|
syncNodeReplicate(pSyncNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
syncNodeRelease(pSyncNode);
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
}
|
||||||
|
|
||||||
|
int32_t syncProcessMsg(int64_t rid, SRpcMsg* pMsg) {
|
||||||
|
int32_t code = -1;
|
||||||
|
if (!syncIsInit()) return code;
|
||||||
|
|
||||||
|
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||||
|
if (pSyncNode == NULL) return code;
|
||||||
|
|
||||||
|
if (pMsg->msgType == TDMT_SYNC_HEARTBEAT) {
|
||||||
|
SyncHeartbeat* pSyncMsg = syncHeartbeatFromRpcMsg2(pMsg);
|
||||||
|
code = syncNodeOnHeartbeat(pSyncNode, pSyncMsg);
|
||||||
|
syncHeartbeatDestroy(pSyncMsg);
|
||||||
|
} else if (pMsg->msgType == TDMT_SYNC_HEARTBEAT_REPLY) {
|
||||||
|
SyncHeartbeatReply* pSyncMsg = syncHeartbeatReplyFromRpcMsg2(pMsg);
|
||||||
|
code = syncNodeOnHeartbeatReply(pSyncNode, pSyncMsg);
|
||||||
|
syncHeartbeatReplyDestroy(pSyncMsg);
|
||||||
|
} else if (pMsg->msgType == TDMT_SYNC_TIMEOUT) {
|
||||||
|
SyncTimeout* pSyncMsg = syncTimeoutFromRpcMsg2(pMsg);
|
||||||
|
code = syncNodeOnTimer(pSyncNode, pSyncMsg);
|
||||||
|
syncTimeoutDestroy(pSyncMsg);
|
||||||
|
} else if (pMsg->msgType == TDMT_SYNC_PING) {
|
||||||
|
SyncPing* pSyncMsg = syncPingFromRpcMsg2(pMsg);
|
||||||
|
code = syncNodeOnPing(pSyncNode, pSyncMsg);
|
||||||
|
syncPingDestroy(pSyncMsg);
|
||||||
|
} else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) {
|
||||||
|
SyncPingReply* pSyncMsg = syncPingReplyFromRpcMsg2(pMsg);
|
||||||
|
code = syncNodeOnPingReply(pSyncNode, pSyncMsg);
|
||||||
|
syncPingReplyDestroy(pSyncMsg);
|
||||||
|
} else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
||||||
|
SyncClientRequest* pSyncMsg = syncClientRequestFromRpcMsg2(pMsg);
|
||||||
|
code = syncNodeOnClientRequest(pSyncNode, pSyncMsg, NULL);
|
||||||
|
syncClientRequestDestroy(pSyncMsg);
|
||||||
|
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) {
|
||||||
|
SyncRequestVote* pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg);
|
||||||
|
code = syncNodeOnRequestVote(pSyncNode, pSyncMsg);
|
||||||
|
syncRequestVoteDestroy(pSyncMsg);
|
||||||
|
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) {
|
||||||
|
SyncRequestVoteReply* pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pMsg);
|
||||||
|
code = syncNodeOnRequestVoteReply(pSyncNode, pSyncMsg);
|
||||||
|
syncRequestVoteReplyDestroy(pSyncMsg);
|
||||||
|
} else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) {
|
||||||
|
SyncAppendEntries* pSyncMsg = syncAppendEntriesFromRpcMsg2(pMsg);
|
||||||
|
code = syncNodeOnAppendEntries(pSyncNode, pSyncMsg);
|
||||||
|
syncAppendEntriesDestroy(pSyncMsg);
|
||||||
|
} else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) {
|
||||||
|
SyncAppendEntriesReply* pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg);
|
||||||
|
code = syncNodeOnAppendEntriesReply(pSyncNode, pSyncMsg);
|
||||||
|
syncAppendEntriesReplyDestroy(pSyncMsg);
|
||||||
|
} else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) {
|
||||||
|
SyncSnapshotSend* pSyncMsg = syncSnapshotSendFromRpcMsg2(pMsg);
|
||||||
|
code = syncNodeOnSnapshot(pSyncNode, pSyncMsg);
|
||||||
|
syncSnapshotSendDestroy(pSyncMsg);
|
||||||
|
} else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) {
|
||||||
|
SyncSnapshotRsp* pSyncMsg = syncSnapshotRspFromRpcMsg2(pMsg);
|
||||||
|
code = syncNodeOnSnapshotReply(pSyncNode, pSyncMsg);
|
||||||
|
syncSnapshotRspDestroy(pSyncMsg);
|
||||||
|
} else if (pMsg->msgType == TDMT_SYNC_LOCAL_CMD) {
|
||||||
|
SyncLocalCmd* pSyncMsg = syncLocalCmdFromRpcMsg2(pMsg);
|
||||||
|
code = syncNodeOnLocalCmd(pSyncNode, pSyncMsg);
|
||||||
|
syncLocalCmdDestroy(pSyncMsg);
|
||||||
|
} else {
|
||||||
|
sError("vgId:%d, failed to process msg:%p since invalid type:%s", pSyncNode->vgId, pMsg, TMSG_INFO(pMsg->msgType));
|
||||||
|
code = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
syncNodeRelease(pSyncNode);
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncLeaderTransfer(int64_t rid) {
|
int32_t syncLeaderTransfer(int64_t rid) {
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||||
if (pSyncNode == NULL) {
|
if (pSyncNode == NULL) return -1;
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
ASSERT(rid == pSyncNode->rid);
|
|
||||||
|
|
||||||
int32_t ret = syncNodeLeaderTransfer(pSyncNode);
|
int32_t ret = syncNodeLeaderTransfer(pSyncNode);
|
||||||
syncNodeRelease(pSyncNode);
|
syncNodeRelease(pSyncNode);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncLeaderTransferTo(int64_t rid, SNodeInfo newLeader) {
|
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
|
||||||
if (pSyncNode == NULL) {
|
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
ASSERT(rid == pSyncNode->rid);
|
|
||||||
|
|
||||||
int32_t ret = syncNodeLeaderTransferTo(pSyncNode, newLeader);
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncIndex syncMinMatchIndex(SSyncNode* pSyncNode) {
|
SyncIndex syncMinMatchIndex(SSyncNode* pSyncNode) {
|
||||||
SyncIndex minMatchIndex = SYNC_INDEX_INVALID;
|
SyncIndex minMatchIndex = SYNC_INDEX_INVALID;
|
||||||
|
|
||||||
|
@ -513,50 +505,20 @@ int32_t syncForwardToPeer(int64_t rid, SRpcMsg* pMsg, bool isWeak) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ESyncState syncGetMyRole(int64_t rid) {
|
SSyncState syncGetState(int64_t rid) {
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
SSyncState state = {.state = TAOS_SYNC_STATE_ERROR};
|
||||||
if (pSyncNode == NULL) {
|
|
||||||
return TAOS_SYNC_STATE_ERROR;
|
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||||
}
|
if (pSyncNode != NULL) {
|
||||||
ASSERT(rid == pSyncNode->rid);
|
state.state = pSyncNode->state;
|
||||||
ESyncState state = pSyncNode->state;
|
state.restored = pSyncNode->restoreFinish;
|
||||||
|
syncNodeRelease(pSyncNode);
|
||||||
|
}
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool syncIsReady(int64_t rid) {
|
#if 0
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
|
||||||
if (pSyncNode == NULL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
ASSERT(rid == pSyncNode->rid);
|
|
||||||
bool b = (pSyncNode->state == TAOS_SYNC_STATE_LEADER) && pSyncNode->restoreFinish;
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
|
|
||||||
// if false, set error code
|
|
||||||
if (false == b) {
|
|
||||||
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) {
|
|
||||||
terrno = TSDB_CODE_SYN_NOT_LEADER;
|
|
||||||
} else {
|
|
||||||
terrno = TSDB_CODE_APP_NOT_READY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool syncIsRestoreFinish(int64_t rid) {
|
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
|
||||||
if (pSyncNode == NULL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
ASSERT(rid == pSyncNode->rid);
|
|
||||||
bool b = pSyncNode->restoreFinish;
|
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t syncGetSnapshotByIndex(int64_t rid, SyncIndex index, SSnapshot* pSnapshot) {
|
int32_t syncGetSnapshotByIndex(int64_t rid, SyncIndex index, SSnapshot* pSnapshot) {
|
||||||
if (index < SYNC_INDEX_BEGIN) {
|
if (index < SYNC_INDEX_BEGIN) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -626,6 +588,7 @@ int32_t syncGetSnapshotMetaByIndex(int64_t rid, SyncIndex snapshotIndex, struct
|
||||||
syncNodeRelease(pSyncNode);
|
syncNodeRelease(pSyncNode);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
SyncIndex syncNodeGetSnapshotConfigIndex(SSyncNode* pSyncNode, SyncIndex snapshotLastApplyIndex) {
|
SyncIndex syncNodeGetSnapshotConfigIndex(SSyncNode* pSyncNode, SyncIndex snapshotLastApplyIndex) {
|
||||||
ASSERT(pSyncNode->pRaftCfg->configIndexCount >= 1);
|
ASSERT(pSyncNode->pRaftCfg->configIndexCount >= 1);
|
||||||
|
@ -643,23 +606,7 @@ SyncIndex syncNodeGetSnapshotConfigIndex(SSyncNode* pSyncNode, SyncIndex snapsho
|
||||||
return lastIndex;
|
return lastIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* syncGetMyRoleStr(int64_t rid) {
|
#if 0
|
||||||
const char* s = syncUtilState2String(syncGetMyRole(rid));
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool syncRestoreFinish(int64_t rid) {
|
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
|
||||||
if (pSyncNode == NULL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
ASSERT(rid == pSyncNode->rid);
|
|
||||||
bool restoreFinish = pSyncNode->restoreFinish;
|
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
return restoreFinish;
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncTerm syncGetMyTerm(int64_t rid) {
|
SyncTerm syncGetMyTerm(int64_t rid) {
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||||
if (pSyncNode == NULL) {
|
if (pSyncNode == NULL) {
|
||||||
|
@ -727,6 +674,7 @@ void syncGetEpSet(int64_t rid, SEpSet* pEpSet) {
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
syncNodeRelease(pSyncNode);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet) {
|
void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet) {
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||||
|
@ -750,31 +698,7 @@ void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet) {
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
syncNodeRelease(pSyncNode);
|
||||||
}
|
}
|
||||||
|
static void syncGetAndDelRespRpc(SSyncNode* pSyncNode, uint64_t index, SRpcHandleInfo* pInfo) {
|
||||||
int32_t syncGetRespRpc(int64_t rid, uint64_t index, SRpcMsg* msg) {
|
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
|
||||||
if (pSyncNode == NULL) {
|
|
||||||
return TAOS_SYNC_STATE_ERROR;
|
|
||||||
}
|
|
||||||
ASSERT(rid == pSyncNode->rid);
|
|
||||||
|
|
||||||
SRespStub stub;
|
|
||||||
int32_t ret = syncRespMgrGet(pSyncNode->pSyncRespMgr, index, &stub);
|
|
||||||
if (ret == 1) {
|
|
||||||
memcpy(msg, &(stub.rpcMsg), sizeof(SRpcMsg));
|
|
||||||
}
|
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t syncGetAndDelRespRpc(int64_t rid, uint64_t index, SRpcHandleInfo* pInfo) {
|
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
|
||||||
if (pSyncNode == NULL) {
|
|
||||||
return TAOS_SYNC_STATE_ERROR;
|
|
||||||
}
|
|
||||||
ASSERT(rid == pSyncNode->rid);
|
|
||||||
|
|
||||||
SRespStub stub;
|
SRespStub stub;
|
||||||
int32_t ret = syncRespMgrGetAndDel(pSyncNode->pSyncRespMgr, index, &stub);
|
int32_t ret = syncRespMgrGetAndDel(pSyncNode->pSyncRespMgr, index, &stub);
|
||||||
if (ret == 1) {
|
if (ret == 1) {
|
||||||
|
@ -782,20 +706,6 @@ int32_t syncGetAndDelRespRpc(int64_t rid, uint64_t index, SRpcHandleInfo* pInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
sTrace("vgId:%d, get seq:%" PRIu64 " rpc handle:%p", pSyncNode->vgId, index, pInfo->handle);
|
sTrace("vgId:%d, get seq:%" PRIu64 " rpc handle:%p", pSyncNode->vgId, index, pInfo->handle);
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncSetMsgCb(int64_t rid, const SMsgCb* msgcb) {
|
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
|
||||||
if (pSyncNode == NULL) {
|
|
||||||
sTrace("syncSetQ get pSyncNode is NULL, rid:%" PRId64, rid);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ASSERT(rid == pSyncNode->rid);
|
|
||||||
pSyncNode->msgcb = msgcb;
|
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char* sync2SimpleStr(int64_t rid) {
|
char* sync2SimpleStr(int64_t rid) {
|
||||||
|
@ -811,41 +721,6 @@ char* sync2SimpleStr(int64_t rid) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPingTimerMS(int64_t rid, int32_t pingTimerMS) {
|
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
|
||||||
if (pSyncNode == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ASSERT(rid == pSyncNode->rid);
|
|
||||||
pSyncNode->pingBaseLine = pingTimerMS;
|
|
||||||
pSyncNode->pingTimerMS = pingTimerMS;
|
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setElectTimerMS(int64_t rid, int32_t electTimerMS) {
|
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
|
||||||
if (pSyncNode == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ASSERT(rid == pSyncNode->rid);
|
|
||||||
pSyncNode->electBaseLine = electTimerMS;
|
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setHeartbeatTimerMS(int64_t rid, int32_t hbTimerMS) {
|
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
|
||||||
if (pSyncNode == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ASSERT(rid == pSyncNode->rid);
|
|
||||||
pSyncNode->hbBaseLine = hbTimerMS;
|
|
||||||
pSyncNode->heartbeatTimerMS = hbTimerMS;
|
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak) {
|
int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak) {
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||||
if (pSyncNode == NULL) {
|
if (pSyncNode == NULL) {
|
||||||
|
@ -942,7 +817,7 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (pSyncNode->FpEqMsg != NULL && (*pSyncNode->FpEqMsg)(pSyncNode->msgcb, &rpcMsg) == 0) {
|
if (pSyncNode->syncEqMsg != NULL && (*pSyncNode->syncEqMsg)(pSyncNode->msgcb, &rpcMsg) == 0) {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
} else {
|
} else {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
@ -957,7 +832,7 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) {
|
||||||
} else {
|
} else {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
terrno = TSDB_CODE_SYN_NOT_LEADER;
|
terrno = TSDB_CODE_SYN_NOT_LEADER;
|
||||||
sError("vgId:%d, sync propose not leader, %s, type:%s", pSyncNode->vgId, syncUtilState2String(pSyncNode->state),
|
sError("vgId:%d, sync propose not leader, %s, type:%s", pSyncNode->vgId, syncStr(pSyncNode->state),
|
||||||
TMSG_INFO(pMsg->msgType));
|
TMSG_INFO(pMsg->msgType));
|
||||||
goto _END;
|
goto _END;
|
||||||
}
|
}
|
||||||
|
@ -1073,9 +948,9 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
|
||||||
|
|
||||||
pSyncNode->pWal = pSyncInfo->pWal;
|
pSyncNode->pWal = pSyncInfo->pWal;
|
||||||
pSyncNode->msgcb = pSyncInfo->msgcb;
|
pSyncNode->msgcb = pSyncInfo->msgcb;
|
||||||
pSyncNode->FpSendMsg = pSyncInfo->FpSendMsg;
|
pSyncNode->syncSendMSg = pSyncInfo->syncSendMSg;
|
||||||
pSyncNode->FpEqMsg = pSyncInfo->FpEqMsg;
|
pSyncNode->syncEqMsg = pSyncInfo->syncEqMsg;
|
||||||
pSyncNode->FpEqCtrlMsg = pSyncInfo->FpEqCtrlMsg;
|
pSyncNode->syncEqCtrlMsg = pSyncInfo->syncEqCtrlMsg;
|
||||||
|
|
||||||
// init raft config
|
// init raft config
|
||||||
pSyncNode->pRaftCfg = raftCfgOpen(pSyncNode->configPath);
|
pSyncNode->pRaftCfg = raftCfgOpen(pSyncNode->configPath);
|
||||||
|
@ -1591,12 +1466,12 @@ int32_t syncNodeRestartHeartbeatTimer(SSyncNode* pSyncNode) {
|
||||||
int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRpcMsg* pMsg) {
|
int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRpcMsg* pMsg) {
|
||||||
SEpSet epSet;
|
SEpSet epSet;
|
||||||
syncUtilraftId2EpSet(destRaftId, &epSet);
|
syncUtilraftId2EpSet(destRaftId, &epSet);
|
||||||
if (pSyncNode->FpSendMsg != NULL) {
|
if (pSyncNode->syncSendMSg != NULL) {
|
||||||
// htonl
|
// htonl
|
||||||
syncUtilMsgHtoN(pMsg->pCont);
|
syncUtilMsgHtoN(pMsg->pCont);
|
||||||
|
|
||||||
pMsg->info.noResp = 1;
|
pMsg->info.noResp = 1;
|
||||||
pSyncNode->FpSendMsg(&epSet, pMsg);
|
pSyncNode->syncSendMSg(&epSet, pMsg);
|
||||||
} else {
|
} else {
|
||||||
sError("vgId:%d, sync send msg by id error, fp-send-msg is null", pSyncNode->vgId);
|
sError("vgId:%d, sync send msg by id error, fp-send-msg is null", pSyncNode->vgId);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1608,12 +1483,12 @@ int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRp
|
||||||
int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, SRpcMsg* pMsg) {
|
int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, SRpcMsg* pMsg) {
|
||||||
SEpSet epSet;
|
SEpSet epSet;
|
||||||
syncUtilnodeInfo2EpSet(nodeInfo, &epSet);
|
syncUtilnodeInfo2EpSet(nodeInfo, &epSet);
|
||||||
if (pSyncNode->FpSendMsg != NULL) {
|
if (pSyncNode->syncSendMSg != NULL) {
|
||||||
// htonl
|
// htonl
|
||||||
syncUtilMsgHtoN(pMsg->pCont);
|
syncUtilMsgHtoN(pMsg->pCont);
|
||||||
|
|
||||||
pMsg->info.noResp = 1;
|
pMsg->info.noResp = 1;
|
||||||
pSyncNode->FpSendMsg(&epSet, pMsg);
|
pSyncNode->syncSendMSg(&epSet, pMsg);
|
||||||
} else {
|
} else {
|
||||||
sError("vgId:%d, sync send msg by info error, fp-send-msg is null", pSyncNode->vgId);
|
sError("vgId:%d, sync send msg by info error, fp-send-msg is null", pSyncNode->vgId);
|
||||||
}
|
}
|
||||||
|
@ -1637,13 +1512,13 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->msgcb);
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->msgcb);
|
||||||
cJSON_AddStringToObject(pRoot, "rpcClient", u64buf);
|
cJSON_AddStringToObject(pRoot, "rpcClient", u64buf);
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpSendMsg);
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->syncSendMSg);
|
||||||
cJSON_AddStringToObject(pRoot, "FpSendMsg", u64buf);
|
cJSON_AddStringToObject(pRoot, "syncSendMSg", u64buf);
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->msgcb);
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->msgcb);
|
||||||
cJSON_AddStringToObject(pRoot, "queue", u64buf);
|
cJSON_AddStringToObject(pRoot, "queue", u64buf);
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpEqMsg);
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->syncEqMsg);
|
||||||
cJSON_AddStringToObject(pRoot, "FpEqMsg", u64buf);
|
cJSON_AddStringToObject(pRoot, "syncEqMsg", u64buf);
|
||||||
|
|
||||||
// init internal
|
// init internal
|
||||||
cJSON* pMe = syncUtilNodeInfo2Json(&pSyncNode->myNodeInfo);
|
cJSON* pMe = syncUtilNodeInfo2Json(&pSyncNode->myNodeInfo);
|
||||||
|
@ -1683,7 +1558,7 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
|
||||||
|
|
||||||
// tla+ server vars
|
// tla+ server vars
|
||||||
cJSON_AddNumberToObject(pRoot, "state", pSyncNode->state);
|
cJSON_AddNumberToObject(pRoot, "state", pSyncNode->state);
|
||||||
cJSON_AddStringToObject(pRoot, "state_str", syncUtilState2String(pSyncNode->state));
|
cJSON_AddStringToObject(pRoot, "state_str", syncStr(pSyncNode->state));
|
||||||
cJSON_AddItemToObject(pRoot, "pRaftStore", raftStore2Json(pSyncNode->pRaftStore));
|
cJSON_AddItemToObject(pRoot, "pRaftStore", raftStore2Json(pSyncNode->pRaftStore));
|
||||||
|
|
||||||
// tla+ candidate vars
|
// tla+ candidate vars
|
||||||
|
@ -1823,7 +1698,7 @@ inline void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) {
|
||||||
"stgy:%d, bch:%d, "
|
"stgy:%d, bch:%d, "
|
||||||
"r-num:%d, "
|
"r-num:%d, "
|
||||||
"lcfg:%" PRId64 ", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s, %s",
|
"lcfg:%" PRId64 ", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s, %s",
|
||||||
pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm,
|
pSyncNode->vgId, syncStr(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm,
|
||||||
pSyncNode->commitIndex, logBeginIndex, logLastIndex, pSyncNode->minMatchIndex, snapshot.lastApplyIndex,
|
pSyncNode->commitIndex, logBeginIndex, logLastIndex, pSyncNode->minMatchIndex, snapshot.lastApplyIndex,
|
||||||
snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy,
|
snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy,
|
||||||
pSyncNode->pRaftCfg->batchSize, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex,
|
pSyncNode->pRaftCfg->batchSize, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex,
|
||||||
|
@ -1847,7 +1722,7 @@ inline void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) {
|
||||||
"stgy:%d, bch:%d, "
|
"stgy:%d, bch:%d, "
|
||||||
"r-num:%d, "
|
"r-num:%d, "
|
||||||
"lcfg:%" PRId64 ", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s, %s",
|
"lcfg:%" PRId64 ", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s, %s",
|
||||||
pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm,
|
pSyncNode->vgId, syncStr(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm,
|
||||||
pSyncNode->commitIndex, logBeginIndex, logLastIndex, pSyncNode->minMatchIndex, snapshot.lastApplyIndex,
|
pSyncNode->commitIndex, logBeginIndex, logLastIndex, pSyncNode->minMatchIndex, snapshot.lastApplyIndex,
|
||||||
snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy,
|
snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy,
|
||||||
pSyncNode->pRaftCfg->batchSize, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex,
|
pSyncNode->pRaftCfg->batchSize, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex,
|
||||||
|
@ -1901,7 +1776,7 @@ inline void syncNodeErrorLog(const SSyncNode* pSyncNode, char* str) {
|
||||||
"stgy:%d, bch:%d, "
|
"stgy:%d, bch:%d, "
|
||||||
"r-num:%d, "
|
"r-num:%d, "
|
||||||
"lcfg:%" PRId64 ", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s",
|
"lcfg:%" PRId64 ", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s",
|
||||||
pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm,
|
pSyncNode->vgId, syncStr(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm,
|
||||||
pSyncNode->commitIndex, logBeginIndex, logLastIndex, pSyncNode->minMatchIndex, snapshot.lastApplyIndex,
|
pSyncNode->commitIndex, logBeginIndex, logLastIndex, pSyncNode->minMatchIndex, snapshot.lastApplyIndex,
|
||||||
snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy,
|
snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy,
|
||||||
pSyncNode->pRaftCfg->batchSize, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex,
|
pSyncNode->pRaftCfg->batchSize, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex,
|
||||||
|
@ -1923,7 +1798,7 @@ inline void syncNodeErrorLog(const SSyncNode* pSyncNode, char* str) {
|
||||||
"stgy:%d, bch:%d, "
|
"stgy:%d, bch:%d, "
|
||||||
"r-num:%d, "
|
"r-num:%d, "
|
||||||
"lcfg:%" PRId64 ", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s",
|
"lcfg:%" PRId64 ", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s",
|
||||||
pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm,
|
pSyncNode->vgId, syncStr(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm,
|
||||||
pSyncNode->commitIndex, logBeginIndex, logLastIndex, pSyncNode->minMatchIndex, snapshot.lastApplyIndex,
|
pSyncNode->commitIndex, logBeginIndex, logLastIndex, pSyncNode->minMatchIndex, snapshot.lastApplyIndex,
|
||||||
snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy,
|
snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy,
|
||||||
pSyncNode->pRaftCfg->batchSize, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex,
|
pSyncNode->pRaftCfg->batchSize, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex,
|
||||||
|
@ -1955,9 +1830,9 @@ inline char* syncNode2SimpleStr(const SSyncNode* pSyncNode) {
|
||||||
", sby:%d, "
|
", sby:%d, "
|
||||||
"r-num:%d, "
|
"r-num:%d, "
|
||||||
"lcfg:%" PRId64 ", chging:%d, rsto:%d",
|
"lcfg:%" PRId64 ", chging:%d, rsto:%d",
|
||||||
pSyncNode->vgId, syncUtilState2String(pSyncNode->state), pSyncNode->pRaftStore->currentTerm,
|
pSyncNode->vgId, syncStr(pSyncNode->state), pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex,
|
||||||
pSyncNode->commitIndex, logBeginIndex, logLastIndex, snapshot.lastApplyIndex, pSyncNode->pRaftCfg->isStandBy,
|
logBeginIndex, logLastIndex, snapshot.lastApplyIndex, pSyncNode->pRaftCfg->isStandBy, pSyncNode->replicaNum,
|
||||||
pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, pSyncNode->changing, pSyncNode->restoreFinish);
|
pSyncNode->pRaftCfg->lastConfigIndex, pSyncNode->changing, pSyncNode->restoreFinish);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -2237,7 +2112,13 @@ void syncNodeUpdateTermWithoutStepDown(SSyncNode* pSyncNode, SyncTerm term) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncNodeStepDown(SSyncNode* pSyncNode, SyncTerm newTerm) {
|
void syncNodeStepDown(SSyncNode* pSyncNode, SyncTerm newTerm) {
|
||||||
ASSERT(pSyncNode->pRaftStore->currentTerm <= newTerm);
|
if (pSyncNode->pRaftStore->currentTerm > newTerm) {
|
||||||
|
char logBuf[128];
|
||||||
|
snprintf(logBuf, sizeof(logBuf), "step down, ignore, new-term:%" PRIu64 ", current-term:%" PRIu64, newTerm,
|
||||||
|
pSyncNode->pRaftStore->currentTerm);
|
||||||
|
syncNodeEventLog(pSyncNode, logBuf);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
char logBuf[128];
|
char logBuf[128];
|
||||||
|
@ -2355,6 +2236,7 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) {
|
||||||
// init peer mgr
|
// init peer mgr
|
||||||
syncNodePeerStateInit(pSyncNode);
|
syncNodePeerStateInit(pSyncNode);
|
||||||
|
|
||||||
|
#if 0
|
||||||
// update sender private term
|
// update sender private term
|
||||||
SSyncSnapshotSender* pMySender = syncNodeGetSnapshotSender(pSyncNode, &(pSyncNode->myRaftId));
|
SSyncSnapshotSender* pMySender = syncNodeGetSnapshotSender(pSyncNode, &(pSyncNode->myRaftId));
|
||||||
if (pMySender != NULL) {
|
if (pMySender != NULL) {
|
||||||
|
@ -2365,6 +2247,7 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) {
|
||||||
}
|
}
|
||||||
(pMySender->privateTerm) += 100;
|
(pMySender->privateTerm) += 100;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// close receiver
|
// close receiver
|
||||||
if (snapshotReceiverIsStart(pSyncNode->pNewNodeReceiver)) {
|
if (snapshotReceiverIsStart(pSyncNode->pNewNodeReceiver)) {
|
||||||
|
@ -2656,8 +2539,8 @@ static void syncNodeEqPingTimer(void* param, void* tmrId) {
|
||||||
SRpcMsg rpcMsg;
|
SRpcMsg rpcMsg;
|
||||||
syncTimeout2RpcMsg(pSyncMsg, &rpcMsg);
|
syncTimeout2RpcMsg(pSyncMsg, &rpcMsg);
|
||||||
syncRpcMsgLog2((char*)"==syncNodeEqPingTimer==", &rpcMsg);
|
syncRpcMsgLog2((char*)"==syncNodeEqPingTimer==", &rpcMsg);
|
||||||
if (pSyncNode->FpEqMsg != NULL) {
|
if (pSyncNode->syncEqMsg != NULL) {
|
||||||
int32_t code = pSyncNode->FpEqMsg(pSyncNode->msgcb, &rpcMsg);
|
int32_t code = pSyncNode->syncEqMsg(pSyncNode->msgcb, &rpcMsg);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
sError("vgId:%d, sync enqueue ping msg error, code:%d", pSyncNode->vgId, code);
|
sError("vgId:%d, sync enqueue ping msg error, code:%d", pSyncNode->vgId, code);
|
||||||
rpcFreeCont(rpcMsg.pCont);
|
rpcFreeCont(rpcMsg.pCont);
|
||||||
|
@ -2665,7 +2548,7 @@ static void syncNodeEqPingTimer(void* param, void* tmrId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sTrace("syncNodeEqPingTimer pSyncNode->FpEqMsg is NULL");
|
sTrace("syncNodeEqPingTimer pSyncNode->syncEqMsg is NULL");
|
||||||
}
|
}
|
||||||
syncTimeoutDestroy(pSyncMsg);
|
syncTimeoutDestroy(pSyncMsg);
|
||||||
|
|
||||||
|
@ -2690,8 +2573,8 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) {
|
||||||
pSyncNode->vgId, pSyncNode);
|
pSyncNode->vgId, pSyncNode);
|
||||||
SRpcMsg rpcMsg;
|
SRpcMsg rpcMsg;
|
||||||
syncTimeout2RpcMsg(pSyncMsg, &rpcMsg);
|
syncTimeout2RpcMsg(pSyncMsg, &rpcMsg);
|
||||||
if (pSyncNode->FpEqMsg != NULL && pSyncNode->msgcb != NULL && pSyncNode->msgcb->putToQueueFp != NULL) {
|
if (pSyncNode->syncEqMsg != NULL && pSyncNode->msgcb != NULL && pSyncNode->msgcb->putToQueueFp != NULL) {
|
||||||
int32_t code = pSyncNode->FpEqMsg(pSyncNode->msgcb, &rpcMsg);
|
int32_t code = pSyncNode->syncEqMsg(pSyncNode->msgcb, &rpcMsg);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
sError("vgId:%d, sync enqueue elect msg error, code:%d", pSyncNode->vgId, code);
|
sError("vgId:%d, sync enqueue elect msg error, code:%d", pSyncNode->vgId, code);
|
||||||
rpcFreeCont(rpcMsg.pCont);
|
rpcFreeCont(rpcMsg.pCont);
|
||||||
|
@ -2707,7 +2590,7 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) {
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
sTrace("syncNodeEqElectTimer FpEqMsg is NULL");
|
sTrace("syncNodeEqElectTimer syncEqMsg is NULL");
|
||||||
}
|
}
|
||||||
|
|
||||||
syncTimeoutDestroy(pSyncMsg);
|
syncTimeoutDestroy(pSyncMsg);
|
||||||
|
@ -2739,8 +2622,8 @@ static void syncNodeEqHeartbeatTimer(void* param, void* tmrId) {
|
||||||
SRpcMsg rpcMsg;
|
SRpcMsg rpcMsg;
|
||||||
syncTimeout2RpcMsg(pSyncMsg, &rpcMsg);
|
syncTimeout2RpcMsg(pSyncMsg, &rpcMsg);
|
||||||
syncRpcMsgLog2((char*)"==syncNodeEqHeartbeatTimer==", &rpcMsg);
|
syncRpcMsgLog2((char*)"==syncNodeEqHeartbeatTimer==", &rpcMsg);
|
||||||
if (pSyncNode->FpEqMsg != NULL) {
|
if (pSyncNode->syncEqMsg != NULL) {
|
||||||
int32_t code = pSyncNode->FpEqMsg(pSyncNode->msgcb, &rpcMsg);
|
int32_t code = pSyncNode->syncEqMsg(pSyncNode->msgcb, &rpcMsg);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
sError("vgId:%d, sync enqueue timer msg error, code:%d", pSyncNode->vgId, code);
|
sError("vgId:%d, sync enqueue timer msg error, code:%d", pSyncNode->vgId, code);
|
||||||
rpcFreeCont(rpcMsg.pCont);
|
rpcFreeCont(rpcMsg.pCont);
|
||||||
|
@ -2748,7 +2631,7 @@ static void syncNodeEqHeartbeatTimer(void* param, void* tmrId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sError("vgId:%d, enqueue msg cb ptr (i.e. FpEqMsg) not set.", pSyncNode->vgId);
|
sError("vgId:%d, enqueue msg cb ptr (i.e. syncEqMsg) not set.", pSyncNode->vgId);
|
||||||
}
|
}
|
||||||
syncTimeoutDestroy(pSyncMsg);
|
syncTimeoutDestroy(pSyncMsg);
|
||||||
|
|
||||||
|
@ -2795,8 +2678,8 @@ static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) {
|
||||||
|
|
||||||
// eq msg
|
// eq msg
|
||||||
#if 0
|
#if 0
|
||||||
if (pSyncNode->FpEqCtrlMsg != NULL) {
|
if (pSyncNode->syncEqCtrlMsg != NULL) {
|
||||||
int32_t code = pSyncNode->FpEqCtrlMsg(pSyncNode->msgcb, &rpcMsg);
|
int32_t code = pSyncNode->syncEqCtrlMsg(pSyncNode->msgcb, &rpcMsg);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
sError("vgId:%d, sync ctrl enqueue timer msg error, code:%d", pSyncNode->vgId, code);
|
sError("vgId:%d, sync ctrl enqueue timer msg error, code:%d", pSyncNode->vgId, code);
|
||||||
rpcFreeCont(rpcMsg.pCont);
|
rpcFreeCont(rpcMsg.pCont);
|
||||||
|
@ -2804,7 +2687,7 @@ static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sError("vgId:%d, enqueue ctrl msg cb ptr (i.e. FpEqMsg) not set.", pSyncNode->vgId);
|
sError("vgId:%d, enqueue ctrl msg cb ptr (i.e. syncEqMsg) not set.", pSyncNode->vgId);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -2844,10 +2727,10 @@ static int32_t syncNodeEqNoop(SSyncNode* ths) {
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg rpcMsg = {0};
|
||||||
syncClientRequest2RpcMsg(pSyncMsg, &rpcMsg);
|
syncClientRequest2RpcMsg(pSyncMsg, &rpcMsg);
|
||||||
if (ths->FpEqMsg != NULL) {
|
if (ths->syncEqMsg != NULL) {
|
||||||
ths->FpEqMsg(ths->msgcb, &rpcMsg);
|
ths->syncEqMsg(ths->msgcb, &rpcMsg);
|
||||||
} else {
|
} else {
|
||||||
sTrace("syncNodeEqNoop pSyncNode->FpEqMsg is NULL");
|
sTrace("syncNodeEqNoop pSyncNode->syncEqMsg is NULL");
|
||||||
}
|
}
|
||||||
|
|
||||||
syncEntryDestory(pEntry);
|
syncEntryDestory(pEntry);
|
||||||
|
@ -2958,8 +2841,8 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg) {
|
||||||
SRpcMsg rpcMsgLocalCmd;
|
SRpcMsg rpcMsgLocalCmd;
|
||||||
syncLocalCmd2RpcMsg(pSyncMsg, &rpcMsgLocalCmd);
|
syncLocalCmd2RpcMsg(pSyncMsg, &rpcMsgLocalCmd);
|
||||||
|
|
||||||
if (ths->FpEqMsg != NULL && ths->msgcb != NULL) {
|
if (ths->syncEqMsg != NULL && ths->msgcb != NULL) {
|
||||||
int32_t code = ths->FpEqMsg(ths->msgcb, &rpcMsgLocalCmd);
|
int32_t code = ths->syncEqMsg(ths->msgcb, &rpcMsgLocalCmd);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
sError("vgId:%d, sync enqueue step-down msg error, code:%d", ths->vgId, code);
|
sError("vgId:%d, sync enqueue step-down msg error, code:%d", ths->vgId, code);
|
||||||
rpcFreeCont(rpcMsgLocalCmd.pCont);
|
rpcFreeCont(rpcMsgLocalCmd.pCont);
|
||||||
|
@ -3141,17 +3024,18 @@ int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* p
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ths->pFsm->FpLeaderTransferCb != NULL) {
|
if (ths->pFsm->FpLeaderTransferCb != NULL) {
|
||||||
SFsmCbMeta cbMeta = {0};
|
SFsmCbMeta cbMeta = {
|
||||||
cbMeta.code = 0;
|
cbMeta.code = 0,
|
||||||
cbMeta.currentTerm = ths->pRaftStore->currentTerm;
|
cbMeta.currentTerm = ths->pRaftStore->currentTerm,
|
||||||
cbMeta.flag = 0;
|
cbMeta.flag = 0,
|
||||||
cbMeta.index = pEntry->index;
|
cbMeta.index = pEntry->index,
|
||||||
cbMeta.lastConfigIndex = syncNodeGetSnapshotConfigIndex(ths, cbMeta.index);
|
cbMeta.lastConfigIndex = syncNodeGetSnapshotConfigIndex(ths, pEntry->index),
|
||||||
cbMeta.isWeak = pEntry->isWeak;
|
cbMeta.isWeak = pEntry->isWeak,
|
||||||
cbMeta.seqNum = pEntry->seqNum;
|
cbMeta.seqNum = pEntry->seqNum,
|
||||||
cbMeta.state = ths->state;
|
cbMeta.state = ths->state,
|
||||||
cbMeta.term = pEntry->term;
|
cbMeta.term = pEntry->term,
|
||||||
ths->pFsm->FpLeaderTransferCb(ths->pFsm, pRpcMsg, cbMeta);
|
};
|
||||||
|
ths->pFsm->FpLeaderTransferCb(ths->pFsm, pRpcMsg, &cbMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
syncLeaderTransferDestroy(pSyncLeaderTransfer);
|
syncLeaderTransferDestroy(pSyncLeaderTransfer);
|
||||||
|
@ -3329,18 +3213,20 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde
|
||||||
|
|
||||||
// execute fsm in apply thread, or execute outside syncPropose
|
// execute fsm in apply thread, or execute outside syncPropose
|
||||||
if (internalExecute) {
|
if (internalExecute) {
|
||||||
SFsmCbMeta cbMeta = {0};
|
SFsmCbMeta cbMeta = {
|
||||||
cbMeta.index = pEntry->index;
|
.index = pEntry->index,
|
||||||
cbMeta.lastConfigIndex = syncNodeGetSnapshotConfigIndex(ths, cbMeta.index);
|
.lastConfigIndex = syncNodeGetSnapshotConfigIndex(ths, pEntry->index),
|
||||||
cbMeta.isWeak = pEntry->isWeak;
|
.isWeak = pEntry->isWeak,
|
||||||
cbMeta.code = 0;
|
.code = 0,
|
||||||
cbMeta.state = ths->state;
|
.state = ths->state,
|
||||||
cbMeta.seqNum = pEntry->seqNum;
|
.seqNum = pEntry->seqNum,
|
||||||
cbMeta.term = pEntry->term;
|
.term = pEntry->term,
|
||||||
cbMeta.currentTerm = ths->pRaftStore->currentTerm;
|
.currentTerm = ths->pRaftStore->currentTerm,
|
||||||
cbMeta.flag = flag;
|
.flag = flag,
|
||||||
|
};
|
||||||
|
|
||||||
ths->pFsm->FpCommitCb(ths->pFsm, &rpcMsg, cbMeta);
|
syncGetAndDelRespRpc(ths, cbMeta.seqNum, &rpcMsg.info);
|
||||||
|
ths->pFsm->FpCommitCb(ths->pFsm, &rpcMsg, &cbMeta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3677,3 +3563,52 @@ void syncLogRecvLocalCmd(SSyncNode* pSyncNode, const SyncLocalCmd* pMsg, const c
|
||||||
syncLocalCmdGetStr(pMsg->cmd), pMsg->sdNewTerm, s);
|
syncLocalCmdGetStr(pMsg->cmd), pMsg->sdNewTerm, s);
|
||||||
syncNodeEventLog(pSyncNode, logBuf);
|
syncNodeEventLog(pSyncNode, logBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void syncLogSendSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s) {
|
||||||
|
char host[64];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||||
|
char logBuf[256];
|
||||||
|
snprintf(logBuf, sizeof(logBuf), "send sync-pre-snapshot to %s:%d {term:%" PRIu64 "}, %s", host, port, pMsg->term, s);
|
||||||
|
syncNodeEventLog(pSyncNode, logBuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncLogRecvSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s) {
|
||||||
|
char host[64];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||||
|
char logBuf[256];
|
||||||
|
snprintf(logBuf, sizeof(logBuf), "recv sync-pre-snapshot from %s:%d {term:%" PRIu64 "}, %s", host, port, pMsg->term,
|
||||||
|
s);
|
||||||
|
syncNodeEventLog(pSyncNode, logBuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncLogSendSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshotReply* pMsg, const char* s) {
|
||||||
|
char host[64];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||||
|
char logBuf[256];
|
||||||
|
snprintf(logBuf, sizeof(logBuf),
|
||||||
|
"send sync-pre-snapshot-reply to %s:%d {term:%" PRIu64 ", snap-start:%" PRId64 "}, %s", host, port,
|
||||||
|
pMsg->term, pMsg->snapStart, s);
|
||||||
|
syncNodeEventLog(pSyncNode, logBuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncLogRecvSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshotReply* pMsg, const char* s) {
|
||||||
|
char host[64];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||||
|
char logBuf[256];
|
||||||
|
snprintf(logBuf, sizeof(logBuf),
|
||||||
|
"recv sync-pre-snapshot-reply from %s:%d {term:%" PRIu64 ", snap-start:%" PRId64 "}, %s", host, port,
|
||||||
|
pMsg->term, pMsg->snapStart, s);
|
||||||
|
syncNodeEventLog(pSyncNode, logBuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncLogSendSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s) {}
|
||||||
|
|
||||||
|
void syncLogRecvSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s) {}
|
||||||
|
|
||||||
|
void syncLogSendSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s) {}
|
||||||
|
|
||||||
|
void syncLogRecvSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s) {}
|
||||||
|
|
|
@ -2315,6 +2315,303 @@ void syncHeartbeatReplyLog2(char* s, const SyncHeartbeatReply* pMsg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---- message process SyncPreSnapshot----
|
||||||
|
SyncPreSnapshot* syncPreSnapshotBuild(int32_t vgId) {
|
||||||
|
uint32_t bytes = sizeof(SyncPreSnapshot);
|
||||||
|
SyncPreSnapshot* pMsg = taosMemoryMalloc(bytes);
|
||||||
|
memset(pMsg, 0, bytes);
|
||||||
|
pMsg->bytes = bytes;
|
||||||
|
pMsg->vgId = vgId;
|
||||||
|
pMsg->msgType = TDMT_SYNC_PRE_SNAPSHOT;
|
||||||
|
return pMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncPreSnapshotDestroy(SyncPreSnapshot* pMsg) {
|
||||||
|
if (pMsg != NULL) {
|
||||||
|
taosMemoryFree(pMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncPreSnapshotSerialize(const SyncPreSnapshot* pMsg, char* buf, uint32_t bufLen) {
|
||||||
|
ASSERT(pMsg->bytes <= bufLen);
|
||||||
|
memcpy(buf, pMsg, pMsg->bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncPreSnapshotDeserialize(const char* buf, uint32_t len, SyncPreSnapshot* pMsg) {
|
||||||
|
memcpy(pMsg, buf, len);
|
||||||
|
ASSERT(len == pMsg->bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
char* syncPreSnapshotSerialize2(const SyncPreSnapshot* pMsg, uint32_t* len) {
|
||||||
|
char* buf = taosMemoryMalloc(pMsg->bytes);
|
||||||
|
ASSERT(buf != NULL);
|
||||||
|
syncPreSnapshotSerialize(pMsg, buf, pMsg->bytes);
|
||||||
|
if (len != NULL) {
|
||||||
|
*len = pMsg->bytes;
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
SyncPreSnapshot* syncPreSnapshotDeserialize2(const char* buf, uint32_t len) {
|
||||||
|
uint32_t bytes = *((uint32_t*)buf);
|
||||||
|
SyncPreSnapshot* pMsg = taosMemoryMalloc(bytes);
|
||||||
|
ASSERT(pMsg != NULL);
|
||||||
|
syncPreSnapshotDeserialize(buf, len, pMsg);
|
||||||
|
ASSERT(len == pMsg->bytes);
|
||||||
|
return pMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncPreSnapshot2RpcMsg(const SyncPreSnapshot* pMsg, SRpcMsg* pRpcMsg) {
|
||||||
|
memset(pRpcMsg, 0, sizeof(*pRpcMsg));
|
||||||
|
pRpcMsg->msgType = pMsg->msgType;
|
||||||
|
pRpcMsg->contLen = pMsg->bytes;
|
||||||
|
pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
|
||||||
|
syncPreSnapshotSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncPreSnapshotFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPreSnapshot* pMsg) {
|
||||||
|
syncPreSnapshotDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
SyncPreSnapshot* syncPreSnapshotFromRpcMsg2(const SRpcMsg* pRpcMsg) {
|
||||||
|
SyncPreSnapshot* pMsg = syncPreSnapshotDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||||
|
ASSERT(pMsg != NULL);
|
||||||
|
return pMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON* syncPreSnapshot2Json(const SyncPreSnapshot* pMsg) {
|
||||||
|
char u64buf[128] = {0};
|
||||||
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
|
|
||||||
|
if (pMsg != NULL) {
|
||||||
|
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
||||||
|
|
||||||
|
cJSON* pSrcId = cJSON_CreateObject();
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
|
||||||
|
cJSON_AddStringToObject(pSrcId, "addr", u64buf);
|
||||||
|
{
|
||||||
|
uint64_t u64 = pMsg->srcId.addr;
|
||||||
|
cJSON* pTmp = pSrcId;
|
||||||
|
char host[128] = {0};
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||||
|
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
||||||
|
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
||||||
|
}
|
||||||
|
cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
|
||||||
|
cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
|
||||||
|
|
||||||
|
cJSON* pDestId = cJSON_CreateObject();
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
|
||||||
|
cJSON_AddStringToObject(pDestId, "addr", u64buf);
|
||||||
|
{
|
||||||
|
uint64_t u64 = pMsg->destId.addr;
|
||||||
|
cJSON* pTmp = pDestId;
|
||||||
|
char host[128] = {0};
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||||
|
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
||||||
|
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
||||||
|
}
|
||||||
|
cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
|
||||||
|
cJSON_AddItemToObject(pRoot, "destId", pDestId);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
|
||||||
|
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
|
cJSON_AddItemToObject(pJson, "SyncPreSnapshot", pRoot);
|
||||||
|
return pJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* syncPreSnapshot2Str(const SyncPreSnapshot* pMsg) {
|
||||||
|
cJSON* pJson = syncPreSnapshot2Json(pMsg);
|
||||||
|
char* serialized = cJSON_Print(pJson);
|
||||||
|
cJSON_Delete(pJson);
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncPreSnapshotPrint(const SyncPreSnapshot* pMsg) {
|
||||||
|
char* serialized = syncPreSnapshot2Str(pMsg);
|
||||||
|
printf("syncPreSnapshotPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncPreSnapshotPrint2(char* s, const SyncPreSnapshot* pMsg) {
|
||||||
|
char* serialized = syncPreSnapshot2Str(pMsg);
|
||||||
|
printf("syncPreSnapshotPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncPreSnapshotLog(const SyncPreSnapshot* pMsg) {
|
||||||
|
char* serialized = syncPreSnapshot2Str(pMsg);
|
||||||
|
sTrace("syncPreSnapshotLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncPreSnapshotLog2(char* s, const SyncPreSnapshot* pMsg) {
|
||||||
|
if (gRaftDetailLog) {
|
||||||
|
char* serialized = syncPreSnapshot2Str(pMsg);
|
||||||
|
sTrace("syncPreSnapshotLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- message process SyncPreSnapshotReply----
|
||||||
|
SyncPreSnapshotReply* syncPreSnapshotReplyBuild(int32_t vgId) {
|
||||||
|
uint32_t bytes = sizeof(SyncPreSnapshotReply);
|
||||||
|
SyncPreSnapshotReply* pMsg = taosMemoryMalloc(bytes);
|
||||||
|
memset(pMsg, 0, bytes);
|
||||||
|
pMsg->bytes = bytes;
|
||||||
|
pMsg->vgId = vgId;
|
||||||
|
pMsg->msgType = TDMT_SYNC_PRE_SNAPSHOT_REPLY;
|
||||||
|
return pMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncPreSnapshotReplyDestroy(SyncPreSnapshotReply* pMsg) {
|
||||||
|
if (pMsg != NULL) {
|
||||||
|
taosMemoryFree(pMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncPreSnapshotReplySerialize(const SyncPreSnapshotReply* pMsg, char* buf, uint32_t bufLen) {
|
||||||
|
ASSERT(pMsg->bytes <= bufLen);
|
||||||
|
memcpy(buf, pMsg, pMsg->bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncPreSnapshotReplyDeserialize(const char* buf, uint32_t len, SyncPreSnapshotReply* pMsg) {
|
||||||
|
memcpy(pMsg, buf, len);
|
||||||
|
ASSERT(len == pMsg->bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
char* syncPreSnapshotReplySerialize2(const SyncPreSnapshotReply* pMsg, uint32_t* len) {
|
||||||
|
char* buf = taosMemoryMalloc(pMsg->bytes);
|
||||||
|
ASSERT(buf != NULL);
|
||||||
|
syncPreSnapshotReplySerialize(pMsg, buf, pMsg->bytes);
|
||||||
|
if (len != NULL) {
|
||||||
|
*len = pMsg->bytes;
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
SyncPreSnapshotReply* syncPreSnapshotReplyDeserialize2(const char* buf, uint32_t len) {
|
||||||
|
uint32_t bytes = *((uint32_t*)buf);
|
||||||
|
SyncPreSnapshotReply* pMsg = taosMemoryMalloc(bytes);
|
||||||
|
ASSERT(pMsg != NULL);
|
||||||
|
syncPreSnapshotReplyDeserialize(buf, len, pMsg);
|
||||||
|
ASSERT(len == pMsg->bytes);
|
||||||
|
return pMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncPreSnapshotReply2RpcMsg(const SyncPreSnapshotReply* pMsg, SRpcMsg* pRpcMsg) {
|
||||||
|
memset(pRpcMsg, 0, sizeof(*pRpcMsg));
|
||||||
|
pRpcMsg->msgType = pMsg->msgType;
|
||||||
|
pRpcMsg->contLen = pMsg->bytes;
|
||||||
|
pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
|
||||||
|
syncPreSnapshotReplySerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncPreSnapshotReplyFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPreSnapshotReply* pMsg) {
|
||||||
|
syncPreSnapshotReplyDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
SyncPreSnapshotReply* syncPreSnapshotReplyFromRpcMsg2(const SRpcMsg* pRpcMsg) {
|
||||||
|
SyncPreSnapshotReply* pMsg = syncPreSnapshotReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||||
|
ASSERT(pMsg != NULL);
|
||||||
|
return pMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON* syncPreSnapshotReply2Json(const SyncPreSnapshotReply* pMsg) {
|
||||||
|
char u64buf[128] = {0};
|
||||||
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
|
|
||||||
|
if (pMsg != NULL) {
|
||||||
|
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
||||||
|
|
||||||
|
cJSON* pSrcId = cJSON_CreateObject();
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
|
||||||
|
cJSON_AddStringToObject(pSrcId, "addr", u64buf);
|
||||||
|
{
|
||||||
|
uint64_t u64 = pMsg->srcId.addr;
|
||||||
|
cJSON* pTmp = pSrcId;
|
||||||
|
char host[128] = {0};
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||||
|
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
||||||
|
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
||||||
|
}
|
||||||
|
cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
|
||||||
|
cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
|
||||||
|
|
||||||
|
cJSON* pDestId = cJSON_CreateObject();
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
|
||||||
|
cJSON_AddStringToObject(pDestId, "addr", u64buf);
|
||||||
|
{
|
||||||
|
uint64_t u64 = pMsg->destId.addr;
|
||||||
|
cJSON* pTmp = pDestId;
|
||||||
|
char host[128] = {0};
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||||
|
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
||||||
|
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
||||||
|
}
|
||||||
|
cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
|
||||||
|
cJSON_AddItemToObject(pRoot, "destId", pDestId);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
|
||||||
|
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->snapStart);
|
||||||
|
cJSON_AddStringToObject(pRoot, "snap-start", u64buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
|
cJSON_AddItemToObject(pJson, "SyncPreSnapshotReply", pRoot);
|
||||||
|
return pJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* syncPreSnapshotReply2Str(const SyncPreSnapshotReply* pMsg) {
|
||||||
|
cJSON* pJson = syncPreSnapshotReply2Json(pMsg);
|
||||||
|
char* serialized = cJSON_Print(pJson);
|
||||||
|
cJSON_Delete(pJson);
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncPreSnapshotReplyPrint(const SyncPreSnapshotReply* pMsg) {
|
||||||
|
char* serialized = syncPreSnapshotReply2Str(pMsg);
|
||||||
|
printf("syncPreSnapshotReplyPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncPreSnapshotReplyPrint2(char* s, const SyncPreSnapshotReply* pMsg) {
|
||||||
|
char* serialized = syncPreSnapshotReply2Str(pMsg);
|
||||||
|
printf("syncPreSnapshotReplyPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncPreSnapshotReplyLog(const SyncPreSnapshotReply* pMsg) {
|
||||||
|
char* serialized = syncPreSnapshotReply2Str(pMsg);
|
||||||
|
sTrace("syncPreSnapshotReplyLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncPreSnapshotReplyLog2(char* s, const SyncPreSnapshotReply* pMsg) {
|
||||||
|
if (gRaftDetailLog) {
|
||||||
|
char* serialized = syncPreSnapshotReply2Str(pMsg);
|
||||||
|
sTrace("syncPreSnapshotReplyLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ---- message process SyncApplyMsg----
|
// ---- message process SyncApplyMsg----
|
||||||
SyncApplyMsg* syncApplyMsgBuild(uint32_t dataLen) {
|
SyncApplyMsg* syncApplyMsgBuild(uint32_t dataLen) {
|
||||||
uint32_t bytes = sizeof(SyncApplyMsg) + dataLen;
|
uint32_t bytes = sizeof(SyncApplyMsg) + dataLen;
|
||||||
|
@ -2413,7 +2710,7 @@ cJSON* syncApplyMsg2Json(const SyncApplyMsg* pMsg) {
|
||||||
cJSON_AddNumberToObject(pRoot, "fsmMeta.isWeak", pMsg->fsmMeta.isWeak);
|
cJSON_AddNumberToObject(pRoot, "fsmMeta.isWeak", pMsg->fsmMeta.isWeak);
|
||||||
cJSON_AddNumberToObject(pRoot, "fsmMeta.code", pMsg->fsmMeta.code);
|
cJSON_AddNumberToObject(pRoot, "fsmMeta.code", pMsg->fsmMeta.code);
|
||||||
cJSON_AddNumberToObject(pRoot, "fsmMeta.state", pMsg->fsmMeta.state);
|
cJSON_AddNumberToObject(pRoot, "fsmMeta.state", pMsg->fsmMeta.state);
|
||||||
cJSON_AddStringToObject(pRoot, "fsmMeta.state.str", syncUtilState2String(pMsg->fsmMeta.state));
|
cJSON_AddStringToObject(pRoot, "fsmMeta.state.str", syncStr(pMsg->fsmMeta.state));
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->fsmMeta.seqNum);
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->fsmMeta.seqNum);
|
||||||
cJSON_AddStringToObject(pRoot, "fsmMeta.seqNum", u64buf);
|
cJSON_AddStringToObject(pRoot, "fsmMeta.seqNum", u64buf);
|
||||||
|
|
||||||
|
@ -2576,8 +2873,8 @@ cJSON* syncSnapshotSend2Json(const SyncSnapshotSend* pMsg) {
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
|
||||||
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->privateTerm);
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->startTime);
|
||||||
cJSON_AddStringToObject(pRoot, "privateTerm", u64buf);
|
cJSON_AddStringToObject(pRoot, "startTime", u64buf);
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->beginIndex);
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->beginIndex);
|
||||||
cJSON_AddStringToObject(pRoot, "beginIndex", u64buf);
|
cJSON_AddStringToObject(pRoot, "beginIndex", u64buf);
|
||||||
|
@ -2751,8 +3048,8 @@ cJSON* syncSnapshotRsp2Json(const SyncSnapshotRsp* pMsg) {
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
|
||||||
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->privateTerm);
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->startTime);
|
||||||
cJSON_AddStringToObject(pRoot, "privateTerm", u64buf);
|
cJSON_AddStringToObject(pRoot, "startTime", u64buf);
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->lastIndex);
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->lastIndex);
|
||||||
cJSON_AddStringToObject(pRoot, "lastIndex", u64buf);
|
cJSON_AddStringToObject(pRoot, "lastIndex", u64buf);
|
||||||
|
@ -2762,6 +3059,9 @@ cJSON* syncSnapshotRsp2Json(const SyncSnapshotRsp* pMsg) {
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "ack", pMsg->ack);
|
cJSON_AddNumberToObject(pRoot, "ack", pMsg->ack);
|
||||||
cJSON_AddNumberToObject(pRoot, "code", pMsg->code);
|
cJSON_AddNumberToObject(pRoot, "code", pMsg->code);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->snapBeginIndex);
|
||||||
|
cJSON_AddStringToObject(pRoot, "snap-begin", u64buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
|
|
|
@ -62,8 +62,8 @@ int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId) {
|
||||||
syncNodeEventLog(pSyncNode, logBuf);
|
syncNodeEventLog(pSyncNode, logBuf);
|
||||||
|
|
||||||
// start snapshot
|
// start snapshot
|
||||||
int32_t code = syncNodeStartSnapshot(pSyncNode, pDestId);
|
// int32_t code = syncNodeStartSnapshot(pSyncNode, pDestId);
|
||||||
ASSERT(code == 0);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,16 +145,17 @@ void syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl, bool rsp) {
|
||||||
taosArrayPush(delIndexArray, pSeqNum);
|
taosArrayPush(delIndexArray, pSeqNum);
|
||||||
cnt++;
|
cnt++;
|
||||||
|
|
||||||
SFsmCbMeta cbMeta = {0};
|
SFsmCbMeta cbMeta = {
|
||||||
cbMeta.index = SYNC_INDEX_INVALID;
|
cbMeta.index = SYNC_INDEX_INVALID,
|
||||||
cbMeta.lastConfigIndex = SYNC_INDEX_INVALID;
|
cbMeta.lastConfigIndex = SYNC_INDEX_INVALID,
|
||||||
cbMeta.isWeak = false;
|
cbMeta.isWeak = false,
|
||||||
cbMeta.code = TSDB_CODE_SYN_TIMEOUT;
|
cbMeta.code = TSDB_CODE_SYN_TIMEOUT,
|
||||||
cbMeta.state = pSyncNode->state;
|
cbMeta.state = pSyncNode->state,
|
||||||
cbMeta.seqNum = *pSeqNum;
|
cbMeta.seqNum = *pSeqNum,
|
||||||
cbMeta.term = SYNC_TERM_INVALID;
|
cbMeta.term = SYNC_TERM_INVALID,
|
||||||
cbMeta.currentTerm = pSyncNode->pRaftStore->currentTerm;
|
cbMeta.currentTerm = pSyncNode->pRaftStore->currentTerm,
|
||||||
cbMeta.flag = 0;
|
cbMeta.flag = 0,
|
||||||
|
};
|
||||||
|
|
||||||
pStub->rpcMsg.pCont = NULL;
|
pStub->rpcMsg.pCont = NULL;
|
||||||
pStub->rpcMsg.contLen = 0;
|
pStub->rpcMsg.contLen = 0;
|
||||||
|
|
|
@ -41,8 +41,6 @@ SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaI
|
||||||
}
|
}
|
||||||
memset(pSender, 0, sizeof(*pSender));
|
memset(pSender, 0, sizeof(*pSender));
|
||||||
|
|
||||||
int64_t timeNow = taosGetTimestampMs();
|
|
||||||
|
|
||||||
pSender->start = false;
|
pSender->start = false;
|
||||||
pSender->seq = SYNC_SNAPSHOT_SEQ_INVALID;
|
pSender->seq = SYNC_SNAPSHOT_SEQ_INVALID;
|
||||||
pSender->ack = SYNC_SNAPSHOT_SEQ_INVALID;
|
pSender->ack = SYNC_SNAPSHOT_SEQ_INVALID;
|
||||||
|
@ -53,8 +51,7 @@ SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaI
|
||||||
pSender->pSyncNode = pSyncNode;
|
pSender->pSyncNode = pSyncNode;
|
||||||
pSender->replicaIndex = replicaIndex;
|
pSender->replicaIndex = replicaIndex;
|
||||||
pSender->term = pSyncNode->pRaftStore->currentTerm;
|
pSender->term = pSyncNode->pRaftStore->currentTerm;
|
||||||
pSender->privateTerm = timeNow + 100;
|
pSender->startTime = 0;
|
||||||
pSender->startTime = timeNow;
|
|
||||||
pSender->pSyncNode->pFsm->FpGetSnapshotInfo(pSender->pSyncNode->pFsm, &(pSender->snapshot));
|
pSender->pSyncNode->pFsm->FpGetSnapshotInfo(pSender->pSyncNode->pFsm, &(pSender->snapshot));
|
||||||
pSender->finish = false;
|
pSender->finish = false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -88,88 +85,30 @@ void snapshotSenderDestroy(SSyncSnapshotSender *pSender) {
|
||||||
|
|
||||||
bool snapshotSenderIsStart(SSyncSnapshotSender *pSender) { return pSender->start; }
|
bool snapshotSenderIsStart(SSyncSnapshotSender *pSender) { return pSender->start; }
|
||||||
|
|
||||||
// begin send snapshot by param, snapshot, pReader
|
int32_t snapshotSenderStart(SSyncSnapshotSender *pSender) {
|
||||||
//
|
|
||||||
// action:
|
|
||||||
// 1. assert reader not start
|
|
||||||
// 2. update state
|
|
||||||
// 3. send first snapshot block
|
|
||||||
int32_t snapshotSenderStart(SSyncSnapshotSender *pSender, SSnapshotParam snapshotParam, SSnapshot snapshot,
|
|
||||||
void *pReader) {
|
|
||||||
ASSERT(!snapshotSenderIsStart(pSender));
|
ASSERT(!snapshotSenderIsStart(pSender));
|
||||||
|
|
||||||
// init snapshot, parm, reader
|
|
||||||
ASSERT(pSender->pReader == NULL);
|
|
||||||
pSender->pReader = pReader;
|
|
||||||
pSender->snapshot = snapshot;
|
|
||||||
pSender->snapshotParam = snapshotParam;
|
|
||||||
|
|
||||||
// init current block
|
|
||||||
if (pSender->pCurrentBlock != NULL) {
|
|
||||||
taosMemoryFree(pSender->pCurrentBlock);
|
|
||||||
}
|
|
||||||
pSender->blockLen = 0;
|
|
||||||
|
|
||||||
// update term
|
|
||||||
pSender->term = pSender->pSyncNode->pRaftStore->currentTerm;
|
|
||||||
++(pSender->privateTerm); // increase private term
|
|
||||||
|
|
||||||
// update state
|
|
||||||
pSender->finish = false;
|
|
||||||
pSender->start = true;
|
pSender->start = true;
|
||||||
pSender->seq = SYNC_SNAPSHOT_SEQ_BEGIN;
|
pSender->seq = SYNC_SNAPSHOT_SEQ_BEGIN;
|
||||||
pSender->ack = SYNC_SNAPSHOT_SEQ_INVALID;
|
pSender->ack = SYNC_SNAPSHOT_SEQ_INVALID;
|
||||||
|
pSender->pReader = NULL;
|
||||||
|
pSender->pCurrentBlock = NULL;
|
||||||
|
pSender->blockLen = 0;
|
||||||
|
|
||||||
// init last config
|
pSender->snapshotParam.start = SYNC_INDEX_INVALID;
|
||||||
if (pSender->snapshot.lastConfigIndex != SYNC_INDEX_INVALID) {
|
pSender->snapshotParam.end = SYNC_INDEX_INVALID;
|
||||||
int32_t code = 0;
|
|
||||||
SSyncRaftEntry *pEntry = NULL;
|
|
||||||
bool getLastConfig = false;
|
|
||||||
|
|
||||||
code = pSender->pSyncNode->pLogStore->syncLogGetEntry(pSender->pSyncNode->pLogStore,
|
pSender->snapshot.data = NULL;
|
||||||
pSender->snapshot.lastConfigIndex, &pEntry);
|
pSender->snapshotParam.end = SYNC_INDEX_INVALID;
|
||||||
if (code == 0 && pEntry != NULL) {
|
pSender->snapshot.lastApplyIndex = SYNC_INDEX_INVALID;
|
||||||
SRpcMsg rpcMsg;
|
pSender->snapshot.lastApplyTerm = SYNC_TERM_INVALID;
|
||||||
syncEntry2OriginalRpc(pEntry, &rpcMsg);
|
pSender->snapshot.lastConfigIndex = SYNC_INDEX_INVALID;
|
||||||
|
|
||||||
SSyncCfg lastConfig;
|
memset(&(pSender->lastConfig), 0, sizeof(pSender->lastConfig));
|
||||||
int32_t ret = syncCfgFromStr(rpcMsg.pCont, &lastConfig);
|
pSender->sendingMS = 0;
|
||||||
ASSERT(ret == 0);
|
pSender->term = pSender->pSyncNode->pRaftStore->currentTerm;
|
||||||
pSender->lastConfig = lastConfig;
|
pSender->startTime = taosGetTimestampMs();
|
||||||
getLastConfig = true;
|
pSender->finish = false;
|
||||||
|
|
||||||
rpcFreeCont(rpcMsg.pCont);
|
|
||||||
syncEntryDestory(pEntry);
|
|
||||||
} else {
|
|
||||||
if (pSender->snapshot.lastConfigIndex == pSender->pSyncNode->pRaftCfg->lastConfigIndex) {
|
|
||||||
sTrace("vgId:%d, sync sender get cfg from local", pSender->pSyncNode->vgId);
|
|
||||||
pSender->lastConfig = pSender->pSyncNode->pRaftCfg->cfg;
|
|
||||||
getLastConfig = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// last config not found in wal, update to -1
|
|
||||||
if (!getLastConfig) {
|
|
||||||
SyncIndex oldLastConfigIndex = pSender->snapshot.lastConfigIndex;
|
|
||||||
SyncIndex newLastConfigIndex = SYNC_INDEX_INVALID;
|
|
||||||
pSender->snapshot.lastConfigIndex = SYNC_INDEX_INVALID;
|
|
||||||
memset(&(pSender->lastConfig), 0, sizeof(SSyncCfg));
|
|
||||||
|
|
||||||
// event log
|
|
||||||
do {
|
|
||||||
char logBuf[128];
|
|
||||||
snprintf(logBuf, sizeof(logBuf), "snapshot sender update lcindex from %" PRId64 " to %" PRId64,
|
|
||||||
oldLastConfigIndex, newLastConfigIndex);
|
|
||||||
char *eventLog = snapshotSender2SimpleStr(pSender, logBuf);
|
|
||||||
syncNodeEventLog(pSender->pSyncNode, eventLog);
|
|
||||||
taosMemoryFree(eventLog);
|
|
||||||
} while (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// no last config
|
|
||||||
memset(&(pSender->lastConfig), 0, sizeof(SSyncCfg));
|
|
||||||
}
|
|
||||||
|
|
||||||
// build begin msg
|
// build begin msg
|
||||||
SyncSnapshotSend *pMsg = syncSnapshotSendBuild(0, pSender->pSyncNode->vgId);
|
SyncSnapshotSend *pMsg = syncSnapshotSendBuild(0, pSender->pSyncNode->vgId);
|
||||||
|
@ -181,8 +120,8 @@ int32_t snapshotSenderStart(SSyncSnapshotSender *pSender, SSnapshotParam snapsho
|
||||||
pMsg->lastTerm = pSender->snapshot.lastApplyTerm;
|
pMsg->lastTerm = pSender->snapshot.lastApplyTerm;
|
||||||
pMsg->lastConfigIndex = pSender->snapshot.lastConfigIndex;
|
pMsg->lastConfigIndex = pSender->snapshot.lastConfigIndex;
|
||||||
pMsg->lastConfig = pSender->lastConfig;
|
pMsg->lastConfig = pSender->lastConfig;
|
||||||
pMsg->seq = pSender->seq; // SYNC_SNAPSHOT_SEQ_BEGIN
|
pMsg->startTime = pSender->startTime;
|
||||||
pMsg->privateTerm = pSender->privateTerm;
|
pMsg->seq = SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT;
|
||||||
|
|
||||||
// send msg
|
// send msg
|
||||||
SRpcMsg rpcMsg;
|
SRpcMsg rpcMsg;
|
||||||
|
@ -201,6 +140,10 @@ int32_t snapshotSenderStart(SSyncSnapshotSender *pSender, SSnapshotParam snapsho
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t snapshotSenderStop(SSyncSnapshotSender *pSender, bool finish) {
|
int32_t snapshotSenderStop(SSyncSnapshotSender *pSender, bool finish) {
|
||||||
|
// update flag
|
||||||
|
pSender->start = false;
|
||||||
|
pSender->finish = finish;
|
||||||
|
|
||||||
// close reader
|
// close reader
|
||||||
if (pSender->pReader != NULL) {
|
if (pSender->pReader != NULL) {
|
||||||
int32_t ret = pSender->pSyncNode->pFsm->FpSnapshotStopRead(pSender->pSyncNode->pFsm, pSender->pReader);
|
int32_t ret = pSender->pSyncNode->pFsm->FpSnapshotStopRead(pSender->pSyncNode->pFsm, pSender->pReader);
|
||||||
|
@ -215,12 +158,6 @@ int32_t snapshotSenderStop(SSyncSnapshotSender *pSender, bool finish) {
|
||||||
pSender->blockLen = 0;
|
pSender->blockLen = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update flag
|
|
||||||
pSender->start = false;
|
|
||||||
pSender->finish = finish;
|
|
||||||
|
|
||||||
// do not update term, maybe print
|
|
||||||
|
|
||||||
// event log
|
// event log
|
||||||
do {
|
do {
|
||||||
char *eventLog = snapshotSender2SimpleStr(pSender, "snapshot sender stop");
|
char *eventLog = snapshotSender2SimpleStr(pSender, "snapshot sender stop");
|
||||||
|
@ -263,7 +200,9 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) {
|
||||||
pMsg->lastConfigIndex = pSender->snapshot.lastConfigIndex;
|
pMsg->lastConfigIndex = pSender->snapshot.lastConfigIndex;
|
||||||
pMsg->lastConfig = pSender->lastConfig;
|
pMsg->lastConfig = pSender->lastConfig;
|
||||||
pMsg->seq = pSender->seq;
|
pMsg->seq = pSender->seq;
|
||||||
pMsg->privateTerm = pSender->privateTerm;
|
|
||||||
|
// pMsg->privateTerm = pSender->privateTerm;
|
||||||
|
|
||||||
memcpy(pMsg->data, pSender->pCurrentBlock, pSender->blockLen);
|
memcpy(pMsg->data, pSender->pCurrentBlock, pSender->blockLen);
|
||||||
|
|
||||||
// send msg
|
// send msg
|
||||||
|
@ -302,7 +241,9 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender) {
|
||||||
pMsg->lastConfigIndex = pSender->snapshot.lastConfigIndex;
|
pMsg->lastConfigIndex = pSender->snapshot.lastConfigIndex;
|
||||||
pMsg->lastConfig = pSender->lastConfig;
|
pMsg->lastConfig = pSender->lastConfig;
|
||||||
pMsg->seq = pSender->seq;
|
pMsg->seq = pSender->seq;
|
||||||
pMsg->privateTerm = pSender->privateTerm;
|
|
||||||
|
// pMsg->privateTerm = pSender->privateTerm;
|
||||||
|
|
||||||
memcpy(pMsg->data, pSender->pCurrentBlock, pSender->blockLen);
|
memcpy(pMsg->data, pSender->pCurrentBlock, pSender->blockLen);
|
||||||
|
|
||||||
// send msg
|
// send msg
|
||||||
|
@ -367,8 +308,10 @@ cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender) {
|
||||||
cJSON_AddNumberToObject(pRoot, "replicaIndex", pSender->replicaIndex);
|
cJSON_AddNumberToObject(pRoot, "replicaIndex", pSender->replicaIndex);
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSender->term);
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSender->term);
|
||||||
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSender->privateTerm);
|
|
||||||
cJSON_AddStringToObject(pRoot, "privateTerm", u64buf);
|
// snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSender->privateTerm);
|
||||||
|
// cJSON_AddStringToObject(pRoot, "privateTerm", u64buf);
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "finish", pSender->finish);
|
cJSON_AddNumberToObject(pRoot, "finish", pSender->finish);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,30 +338,38 @@ char *snapshotSender2SimpleStr(SSyncSnapshotSender *pSender, char *event) {
|
||||||
|
|
||||||
snprintf(s, len,
|
snprintf(s, len,
|
||||||
"%s {%p s-param:%" PRId64 " e-param:%" PRId64 " laindex:%" PRId64 " laterm:%" PRIu64 " lcindex:%" PRId64
|
"%s {%p s-param:%" PRId64 " e-param:%" PRId64 " laindex:%" PRId64 " laterm:%" PRIu64 " lcindex:%" PRId64
|
||||||
" seq:%d ack:%d finish:%d pterm:%" PRIu64
|
" seq:%d ack:%d finish:%d replica-index:%d %s:%d}",
|
||||||
" "
|
|
||||||
"replica-index:%d %s:%d}",
|
|
||||||
event, pSender, pSender->snapshotParam.start, pSender->snapshotParam.end, pSender->snapshot.lastApplyIndex,
|
event, pSender, pSender->snapshotParam.start, pSender->snapshotParam.end, pSender->snapshot.lastApplyIndex,
|
||||||
pSender->snapshot.lastApplyTerm, pSender->snapshot.lastConfigIndex, pSender->seq, pSender->ack,
|
pSender->snapshot.lastApplyTerm, pSender->snapshot.lastConfigIndex, pSender->seq, pSender->ack,
|
||||||
pSender->finish, pSender->privateTerm, pSender->replicaIndex, host, port);
|
pSender->finish, pSender->replicaIndex, host, port);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodeStartSnapshot(SSyncNode *pSyncNode, SRaftId *pDestId) {
|
int32_t syncNodeStartSnapshot(SSyncNode *pSyncNode, SRaftId *pDestId) {
|
||||||
// calculate <start, end> index
|
syncNodeEventLog(pSyncNode, "starting snapshot ...");
|
||||||
|
|
||||||
syncNodeEventLog(pSyncNode, "start snapshot ...");
|
|
||||||
|
|
||||||
SSyncSnapshotSender *pSender = syncNodeGetSnapshotSender(pSyncNode, pDestId);
|
SSyncSnapshotSender *pSender = syncNodeGetSnapshotSender(pSyncNode, pDestId);
|
||||||
if (pSender == NULL) {
|
if (pSender == NULL) {
|
||||||
// create sender
|
syncNodeErrorLog(pSyncNode, "start snapshot error, sender is null");
|
||||||
} else {
|
return -1;
|
||||||
// if <start, end> is same
|
|
||||||
// return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// send begin msg
|
int32_t code = 0;
|
||||||
|
|
||||||
|
if (snapshotSenderIsStart(pSender)) {
|
||||||
|
code = snapshotSenderStop(pSender, false);
|
||||||
|
if (code != 0) {
|
||||||
|
syncNodeErrorLog(pSyncNode, "snapshot sender stop error");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
code = snapshotSenderStart(pSender);
|
||||||
|
if (code != 0) {
|
||||||
|
syncNodeErrorLog(pSyncNode, "snapshot sender start error");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -440,7 +391,6 @@ SSyncSnapshotReceiver *snapshotReceiverCreate(SSyncNode *pSyncNode, SRaftId from
|
||||||
pReceiver->pSyncNode = pSyncNode;
|
pReceiver->pSyncNode = pSyncNode;
|
||||||
pReceiver->fromId = fromId;
|
pReceiver->fromId = fromId;
|
||||||
pReceiver->term = pSyncNode->pRaftStore->currentTerm;
|
pReceiver->term = pSyncNode->pRaftStore->currentTerm;
|
||||||
pReceiver->privateTerm = 0;
|
|
||||||
pReceiver->snapshot.data = NULL;
|
pReceiver->snapshot.data = NULL;
|
||||||
pReceiver->snapshot.lastApplyIndex = SYNC_INDEX_INVALID;
|
pReceiver->snapshot.lastApplyIndex = SYNC_INDEX_INVALID;
|
||||||
pReceiver->snapshot.lastApplyTerm = 0;
|
pReceiver->snapshot.lastApplyTerm = 0;
|
||||||
|
@ -474,19 +424,8 @@ bool snapshotReceiverIsStart(SSyncSnapshotReceiver *pReceiver) { return pReceive
|
||||||
// receive first snapshot data
|
// receive first snapshot data
|
||||||
// write first block data
|
// write first block data
|
||||||
static void snapshotReceiverDoStart(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pBeginMsg) {
|
static void snapshotReceiverDoStart(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pBeginMsg) {
|
||||||
// update state
|
|
||||||
pReceiver->term = pReceiver->pSyncNode->pRaftStore->currentTerm;
|
|
||||||
pReceiver->privateTerm = pBeginMsg->privateTerm;
|
|
||||||
pReceiver->ack = SYNC_SNAPSHOT_SEQ_BEGIN;
|
|
||||||
pReceiver->fromId = pBeginMsg->srcId;
|
|
||||||
pReceiver->start = true;
|
pReceiver->start = true;
|
||||||
|
pReceiver->ack = SYNC_SNAPSHOT_SEQ_BEGIN;
|
||||||
// update snapshot
|
|
||||||
pReceiver->snapshot.lastApplyIndex = pBeginMsg->lastIndex;
|
|
||||||
pReceiver->snapshot.lastApplyTerm = pBeginMsg->lastTerm;
|
|
||||||
pReceiver->snapshot.lastConfigIndex = pBeginMsg->lastConfigIndex;
|
|
||||||
pReceiver->snapshotParam.start = pBeginMsg->beginIndex;
|
|
||||||
pReceiver->snapshotParam.end = pBeginMsg->lastIndex;
|
|
||||||
|
|
||||||
// start writer
|
// start writer
|
||||||
ASSERT(pReceiver->pWriter == NULL);
|
ASSERT(pReceiver->pWriter == NULL);
|
||||||
|
@ -494,6 +433,19 @@ static void snapshotReceiverDoStart(SSyncSnapshotReceiver *pReceiver, SyncSnapsh
|
||||||
&(pReceiver->snapshotParam), &(pReceiver->pWriter));
|
&(pReceiver->snapshotParam), &(pReceiver->pWriter));
|
||||||
ASSERT(ret == 0);
|
ASSERT(ret == 0);
|
||||||
|
|
||||||
|
pReceiver->term = pReceiver->pSyncNode->pRaftStore->currentTerm;
|
||||||
|
pReceiver->snapshotParam.start = pBeginMsg->beginIndex;
|
||||||
|
pReceiver->snapshotParam.end = pBeginMsg->lastIndex;
|
||||||
|
|
||||||
|
pReceiver->fromId = pBeginMsg->srcId;
|
||||||
|
|
||||||
|
// update snapshot
|
||||||
|
pReceiver->snapshot.lastApplyIndex = pBeginMsg->lastIndex;
|
||||||
|
pReceiver->snapshot.lastApplyTerm = pBeginMsg->lastTerm;
|
||||||
|
pReceiver->snapshot.lastConfigIndex = pBeginMsg->lastConfigIndex;
|
||||||
|
|
||||||
|
pReceiver->startTime = pBeginMsg->startTime;
|
||||||
|
|
||||||
// event log
|
// event log
|
||||||
do {
|
do {
|
||||||
char *eventLog = snapshotReceiver2SimpleStr(pReceiver, "snapshot receiver start");
|
char *eventLog = snapshotReceiver2SimpleStr(pReceiver, "snapshot receiver start");
|
||||||
|
@ -523,22 +475,9 @@ void snapshotReceiverForceStop(SSyncSnapshotReceiver *pReceiver) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if receiver receive msg from seq = SYNC_SNAPSHOT_SEQ_BEGIN, start receiver
|
// if receiver receive msg from seq = SYNC_SNAPSHOT_SEQ_BEGIN, start receiver
|
||||||
// if already start, force close, start again
|
|
||||||
int32_t snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pBeginMsg) {
|
int32_t snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pBeginMsg) {
|
||||||
if (!snapshotReceiverIsStart(pReceiver)) {
|
ASSERT(!snapshotReceiverIsStart(pReceiver));
|
||||||
// first start
|
snapshotReceiverDoStart(pReceiver, pBeginMsg);
|
||||||
snapshotReceiverDoStart(pReceiver, pBeginMsg);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// already start
|
|
||||||
sInfo("vgId:%d, snapshot recv, receiver already start", pReceiver->pSyncNode->vgId);
|
|
||||||
|
|
||||||
// force close, abandon incomplete data
|
|
||||||
snapshotReceiverForceStop(pReceiver);
|
|
||||||
|
|
||||||
// start again
|
|
||||||
snapshotReceiverDoStart(pReceiver, pBeginMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -698,8 +637,8 @@ cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver) {
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pReceiver->term);
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pReceiver->term);
|
||||||
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pReceiver->privateTerm);
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pReceiver->startTime);
|
||||||
cJSON_AddStringToObject(pRoot, "privateTerm", u64buf);
|
cJSON_AddStringToObject(pRoot, "startTime", u64buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON *pJson = cJSON_CreateObject();
|
cJSON *pJson = cJSON_CreateObject();
|
||||||
|
@ -724,38 +663,204 @@ char *snapshotReceiver2SimpleStr(SSyncSnapshotReceiver *pReceiver, char *event)
|
||||||
syncUtilU642Addr(fromId.addr, host, sizeof(host), &port);
|
syncUtilU642Addr(fromId.addr, host, sizeof(host), &port);
|
||||||
|
|
||||||
snprintf(s, len,
|
snprintf(s, len,
|
||||||
"%s {%p start:%d ack:%d term:%" PRIu64 " pterm:%" PRIu64 " from:%s:%d s-param:%" PRId64 " e-param:%" PRId64
|
"%s {%p start:%d ack:%d term:%" PRIu64 " start-time:%" PRId64 " from:%s:%d s-param:%" PRId64
|
||||||
" laindex:%" PRId64 " laterm:%" PRIu64
|
" e-param:%" PRId64 " laindex:%" PRId64 " laterm:%" PRIu64
|
||||||
" "
|
" "
|
||||||
"lcindex:%" PRId64 "}",
|
"lcindex:%" PRId64 "}",
|
||||||
event, pReceiver, pReceiver->start, pReceiver->ack, pReceiver->term, pReceiver->privateTerm, host, port,
|
event, pReceiver, pReceiver->start, pReceiver->ack, pReceiver->term, pReceiver->startTime, host, port,
|
||||||
pReceiver->snapshotParam.start, pReceiver->snapshotParam.end, pReceiver->snapshot.lastApplyIndex,
|
pReceiver->snapshotParam.start, pReceiver->snapshotParam.end, pReceiver->snapshot.lastApplyIndex,
|
||||||
pReceiver->snapshot.lastApplyTerm, pReceiver->snapshot.lastConfigIndex);
|
pReceiver->snapshot.lastApplyTerm, pReceiver->snapshot.lastConfigIndex);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SyncIndex syncNodeGetSnapBeginIndex(SSyncNode *ths) {
|
||||||
|
SyncIndex snapStart = SYNC_INDEX_INVALID;
|
||||||
|
|
||||||
|
if (syncNodeIsMnode(ths)) {
|
||||||
|
snapStart = SYNC_INDEX_BEGIN;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
SSyncLogStoreData *pData = ths->pLogStore->data;
|
||||||
|
SWal *pWal = pData->pWal;
|
||||||
|
|
||||||
|
bool isEmpty = ths->pLogStore->syncLogIsEmpty(ths->pLogStore);
|
||||||
|
int64_t walCommitVer = walGetCommittedVer(pWal);
|
||||||
|
|
||||||
|
if (!isEmpty && ths->commitIndex != walCommitVer) {
|
||||||
|
char logBuf[128];
|
||||||
|
snprintf(logBuf, sizeof(logBuf), "commit not same, wal-commit:%" PRId64 ", commit:%" PRId64 ", ignore",
|
||||||
|
walCommitVer, ths->commitIndex);
|
||||||
|
syncNodeErrorLog(ths, logBuf);
|
||||||
|
|
||||||
|
snapStart = walCommitVer + 1;
|
||||||
|
} else {
|
||||||
|
snapStart = ths->commitIndex + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return snapStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t syncNodeOnSnapshotPre(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
||||||
|
SSyncSnapshotReceiver *pReceiver = pSyncNode->pNewNodeReceiver;
|
||||||
|
|
||||||
|
if (snapshotReceiverIsStart(pReceiver)) {
|
||||||
|
// already start
|
||||||
|
|
||||||
|
if (pMsg->startTime > pReceiver->startTime) {
|
||||||
|
goto _START_RECEIVER;
|
||||||
|
|
||||||
|
} else if (pMsg->startTime == pReceiver->startTime) {
|
||||||
|
goto _SEND_REPLY;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// ignore
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// start new
|
||||||
|
goto _START_RECEIVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
_START_RECEIVER:
|
||||||
|
if (taosGetTimestampMs() - pMsg->startTime > SNAPSHOT_MAX_CLOCK_SKEW_MS) {
|
||||||
|
syncNodeErrorLog(pSyncNode, "snapshot receiver time skew too much");
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
// waiting for clock match
|
||||||
|
while (taosGetTimestampMs() > pMsg->startTime) {
|
||||||
|
taosMsleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
snapshotReceiverStart(pReceiver, pMsg); // set start-time same with sender
|
||||||
|
}
|
||||||
|
|
||||||
|
_SEND_REPLY:
|
||||||
|
// build msg
|
||||||
|
; // make complier happy
|
||||||
|
SyncSnapshotRsp *pRspMsg = syncSnapshotRspBuild(pSyncNode->vgId);
|
||||||
|
pRspMsg->srcId = pSyncNode->myRaftId;
|
||||||
|
pRspMsg->destId = pMsg->srcId;
|
||||||
|
pRspMsg->term = pSyncNode->pRaftStore->currentTerm;
|
||||||
|
pRspMsg->lastIndex = pMsg->lastIndex;
|
||||||
|
pRspMsg->lastTerm = pMsg->lastTerm;
|
||||||
|
pRspMsg->startTime = pReceiver->startTime;
|
||||||
|
pRspMsg->ack = pMsg->seq; // receiver maybe already closed
|
||||||
|
pRspMsg->code = 0;
|
||||||
|
pRspMsg->snapBeginIndex = syncNodeGetSnapBeginIndex(pSyncNode);
|
||||||
|
|
||||||
|
// send msg
|
||||||
|
SRpcMsg rpcMsg;
|
||||||
|
syncSnapshotRsp2RpcMsg(pRspMsg, &rpcMsg);
|
||||||
|
syncNodeSendMsgById(&(pRspMsg->destId), pSyncNode, &rpcMsg);
|
||||||
|
syncSnapshotRspDestroy(pRspMsg);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t syncNodeOnSnapshotBegin(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
||||||
|
// condition 1
|
||||||
|
SSyncSnapshotReceiver *pReceiver = pSyncNode->pNewNodeReceiver;
|
||||||
|
|
||||||
|
if (snapshotReceiverIsStart(pReceiver)) {
|
||||||
|
if (pMsg->startTime > pReceiver->startTime) {
|
||||||
|
snapshotReceiverStop(pReceiver);
|
||||||
|
|
||||||
|
} else if (pMsg->startTime == pReceiver->startTime) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
// ignore
|
||||||
|
syncNodeEventLog(pSyncNode, "msg ignore");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_START_RECEIVER:
|
||||||
|
if (taosGetTimestampMs() - pMsg->startTime > SNAPSHOT_MAX_CLOCK_SKEW_MS) {
|
||||||
|
syncNodeErrorLog(pSyncNode, "snapshot receiver time skew too much");
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
// waiting for clock match
|
||||||
|
while (taosGetTimestampMs() > pMsg->startTime) {
|
||||||
|
taosMsleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
snapshotReceiverStart(pReceiver, pMsg);
|
||||||
|
|
||||||
|
// build msg
|
||||||
|
SyncSnapshotRsp *pRspMsg = syncSnapshotRspBuild(pSyncNode->vgId);
|
||||||
|
pRspMsg->srcId = pSyncNode->myRaftId;
|
||||||
|
pRspMsg->destId = pMsg->srcId;
|
||||||
|
pRspMsg->term = pSyncNode->pRaftStore->currentTerm;
|
||||||
|
pRspMsg->lastIndex = pMsg->lastIndex;
|
||||||
|
pRspMsg->lastTerm = pMsg->lastTerm;
|
||||||
|
pRspMsg->ack = pReceiver->ack; // receiver maybe already closed
|
||||||
|
pRspMsg->code = 0;
|
||||||
|
|
||||||
|
// send msg
|
||||||
|
SRpcMsg rpcMsg;
|
||||||
|
syncSnapshotRsp2RpcMsg(pRspMsg, &rpcMsg);
|
||||||
|
syncNodeSendMsgById(&(pRspMsg->destId), pSyncNode, &rpcMsg);
|
||||||
|
syncSnapshotRspDestroy(pRspMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t syncNodeOnSnapshotTransfer(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) { return 0; }
|
||||||
|
|
||||||
|
static int32_t syncNodeOnSnapshotEnd(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) { return 0; }
|
||||||
|
|
||||||
// receiver on message
|
// receiver on message
|
||||||
//
|
//
|
||||||
// condition 1, recv SYNC_SNAPSHOT_SEQ_BEGIN, start receiver, update privateTerm
|
// condition 1, recv SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT
|
||||||
// condition 2, recv SYNC_SNAPSHOT_SEQ_END, finish receiver(apply snapshot data, update commit index, maybe reconfig)
|
// if receiver already start
|
||||||
// condition 3, recv SYNC_SNAPSHOT_SEQ_FORCE_CLOSE, force close
|
// if sender.start-time > receiver.start-time, restart receiver(reply snapshot start)
|
||||||
// condition 4, got data, update ack
|
// if sender.start-time = receiver.start-time, maybe duplicate msg
|
||||||
|
// if sender.start-time < receiver.start-time, ignore
|
||||||
|
// else
|
||||||
|
// waiting for clock match
|
||||||
|
// start receiver(reply snapshot start)
|
||||||
|
//
|
||||||
|
// condition 2, recv SYNC_SNAPSHOT_SEQ_BEGIN
|
||||||
|
// a. create writer with <begin, end>
|
||||||
|
//
|
||||||
|
// condition 3, recv SYNC_SNAPSHOT_SEQ_END, finish receiver(apply snapshot data, update commit index, maybe reconfig)
|
||||||
|
//
|
||||||
|
// condition 4, recv SYNC_SNAPSHOT_SEQ_FORCE_CLOSE, force close
|
||||||
|
//
|
||||||
|
// condition 5, got data, update ack
|
||||||
//
|
//
|
||||||
int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
||||||
// get receiver
|
// if already drop replica, do not process
|
||||||
SSyncSnapshotReceiver *pReceiver = pSyncNode->pNewNodeReceiver;
|
if (!syncNodeInRaftGroup(pSyncNode, &(pMsg->srcId))) {
|
||||||
bool needRsp = false;
|
syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "not in my config");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pMsg->term < pSyncNode->pRaftStore->currentTerm) {
|
||||||
|
syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "reject, small term");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pMsg->term > pSyncNode->pRaftStore->currentTerm) {
|
||||||
|
syncNodeStepDown(pSyncNode, pMsg->term);
|
||||||
|
}
|
||||||
|
syncNodeResetElectTimer(pSyncNode);
|
||||||
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
SSyncSnapshotReceiver *pReceiver = pSyncNode->pNewNodeReceiver;
|
||||||
|
|
||||||
// state, term, seq/ack
|
// state, term, seq/ack
|
||||||
if (pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER) {
|
if (pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER) {
|
||||||
if (pMsg->term == pSyncNode->pRaftStore->currentTerm) {
|
if (pMsg->term == pSyncNode->pRaftStore->currentTerm) {
|
||||||
if (pMsg->seq == SYNC_SNAPSHOT_SEQ_BEGIN) {
|
if (pMsg->seq == SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT) {
|
||||||
// condition 1
|
syncNodeOnSnapshotPre(pSyncNode, pMsg);
|
||||||
// begin, no data
|
|
||||||
snapshotReceiverStart(pReceiver, pMsg);
|
} else if (pMsg->seq == SYNC_SNAPSHOT_SEQ_BEGIN) {
|
||||||
needRsp = true;
|
syncNodeOnSnapshotBegin(pSyncNode, pMsg);
|
||||||
|
|
||||||
} else if (pMsg->seq == SYNC_SNAPSHOT_SEQ_END) {
|
} else if (pMsg->seq == SYNC_SNAPSHOT_SEQ_END) {
|
||||||
// condition 2
|
// condition 2
|
||||||
|
@ -764,7 +869,7 @@ int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
||||||
if (code == 0) {
|
if (code == 0) {
|
||||||
snapshotReceiverStop(pReceiver);
|
snapshotReceiverStop(pReceiver);
|
||||||
}
|
}
|
||||||
needRsp = true;
|
bool needRsp = true;
|
||||||
|
|
||||||
// maybe update lastconfig
|
// maybe update lastconfig
|
||||||
if (pMsg->lastConfigIndex >= SYNC_INDEX_BEGIN) {
|
if (pMsg->lastConfigIndex >= SYNC_INDEX_BEGIN) {
|
||||||
|
@ -782,7 +887,7 @@ int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
||||||
// condition 3
|
// condition 3
|
||||||
// force close
|
// force close
|
||||||
snapshotReceiverForceStop(pReceiver);
|
snapshotReceiverForceStop(pReceiver);
|
||||||
needRsp = false;
|
bool needRsp = false;
|
||||||
|
|
||||||
} else if (pMsg->seq > SYNC_SNAPSHOT_SEQ_BEGIN && pMsg->seq < SYNC_SNAPSHOT_SEQ_END) {
|
} else if (pMsg->seq > SYNC_SNAPSHOT_SEQ_BEGIN && pMsg->seq < SYNC_SNAPSHOT_SEQ_END) {
|
||||||
// condition 4
|
// condition 4
|
||||||
|
@ -790,7 +895,7 @@ int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
||||||
if (pMsg->seq == pReceiver->ack + 1) {
|
if (pMsg->seq == pReceiver->ack + 1) {
|
||||||
snapshotReceiverGotData(pReceiver, pMsg);
|
snapshotReceiverGotData(pReceiver, pMsg);
|
||||||
}
|
}
|
||||||
needRsp = true;
|
bool needRsp = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// error log
|
// error log
|
||||||
|
@ -805,26 +910,6 @@ int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// send ack
|
|
||||||
if (needRsp) {
|
|
||||||
// build msg
|
|
||||||
SyncSnapshotRsp *pRspMsg = syncSnapshotRspBuild(pSyncNode->vgId);
|
|
||||||
pRspMsg->srcId = pSyncNode->myRaftId;
|
|
||||||
pRspMsg->destId = pMsg->srcId;
|
|
||||||
pRspMsg->term = pSyncNode->pRaftStore->currentTerm;
|
|
||||||
pRspMsg->lastIndex = pMsg->lastIndex;
|
|
||||||
pRspMsg->lastTerm = pMsg->lastTerm;
|
|
||||||
pRspMsg->ack = pReceiver->ack; // receiver maybe already closed
|
|
||||||
pRspMsg->code = 0;
|
|
||||||
pRspMsg->privateTerm = pReceiver->privateTerm; // receiver maybe already closed
|
|
||||||
|
|
||||||
// send msg
|
|
||||||
SRpcMsg rpcMsg;
|
|
||||||
syncSnapshotRsp2RpcMsg(pRspMsg, &rpcMsg);
|
|
||||||
syncNodeSendMsgById(&(pRspMsg->destId), pSyncNode, &rpcMsg);
|
|
||||||
syncSnapshotRspDestroy(pRspMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// error log
|
// error log
|
||||||
do {
|
do {
|
||||||
|
@ -849,6 +934,52 @@ int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t syncNodeOnSnapshotReplyPre(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) {
|
||||||
|
// get sender
|
||||||
|
SSyncSnapshotSender *pSender = syncNodeGetSnapshotSender(pSyncNode, &(pMsg->srcId));
|
||||||
|
ASSERT(pSender != NULL);
|
||||||
|
|
||||||
|
SSnapshot snapshot;
|
||||||
|
pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot);
|
||||||
|
|
||||||
|
// prepare <begin, end>
|
||||||
|
pSender->snapshotParam.start = pMsg->snapBeginIndex;
|
||||||
|
pSender->snapshotParam.end = snapshot.lastApplyIndex;
|
||||||
|
|
||||||
|
if (pMsg->snapBeginIndex > snapshot.lastApplyIndex) {
|
||||||
|
syncNodeErrorLog(pSyncNode, "snapshot last index too small");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// start reader
|
||||||
|
int32_t code = pSyncNode->pFsm->FpSnapshotStartRead(pSyncNode->pFsm, &(pSender->snapshotParam), &(pSender->pReader));
|
||||||
|
if (code != 0) {
|
||||||
|
syncNodeErrorLog(pSyncNode, "create snapshot reader error");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// build begin msg
|
||||||
|
SyncSnapshotSend *pSendMsg = syncSnapshotSendBuild(0, pSender->pSyncNode->vgId);
|
||||||
|
pSendMsg->srcId = pSender->pSyncNode->myRaftId;
|
||||||
|
pSendMsg->destId = (pSender->pSyncNode->replicasId)[pSender->replicaIndex];
|
||||||
|
pSendMsg->term = pSender->pSyncNode->pRaftStore->currentTerm;
|
||||||
|
pSendMsg->beginIndex = pSender->snapshotParam.start;
|
||||||
|
pSendMsg->lastIndex = pSender->snapshot.lastApplyIndex;
|
||||||
|
pSendMsg->lastTerm = pSender->snapshot.lastApplyTerm;
|
||||||
|
pSendMsg->lastConfigIndex = pSender->snapshot.lastConfigIndex;
|
||||||
|
pSendMsg->lastConfig = pSender->lastConfig;
|
||||||
|
pSendMsg->startTime = pSender->startTime;
|
||||||
|
pSendMsg->seq = SYNC_SNAPSHOT_SEQ_BEGIN;
|
||||||
|
|
||||||
|
// send msg
|
||||||
|
SRpcMsg rpcMsg;
|
||||||
|
syncSnapshotSend2RpcMsg(pSendMsg, &rpcMsg);
|
||||||
|
syncNodeSendMsgById(&(pSendMsg->destId), pSender->pSyncNode, &rpcMsg);
|
||||||
|
syncSnapshotSendDestroy(pSendMsg);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// sender on message
|
// sender on message
|
||||||
//
|
//
|
||||||
// condition 1 sender receives SYNC_SNAPSHOT_SEQ_END, close sender
|
// condition 1 sender receives SYNC_SNAPSHOT_SEQ_END, close sender
|
||||||
|
@ -857,8 +988,8 @@ int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
||||||
//
|
//
|
||||||
int32_t syncNodeOnSnapshotReply(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) {
|
int32_t syncNodeOnSnapshotReply(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) {
|
||||||
// if already drop replica, do not process
|
// if already drop replica, do not process
|
||||||
if (!syncNodeInRaftGroup(pSyncNode, &(pMsg->srcId)) && pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
|
if (!syncNodeInRaftGroup(pSyncNode, &(pMsg->srcId))) {
|
||||||
sError("vgId:%d, recv sync-snapshot-rsp, maybe replica already dropped", pSyncNode->vgId);
|
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "maybe replica already dropped");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -866,17 +997,26 @@ int32_t syncNodeOnSnapshotReply(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) {
|
||||||
SSyncSnapshotSender *pSender = syncNodeGetSnapshotSender(pSyncNode, &(pMsg->srcId));
|
SSyncSnapshotSender *pSender = syncNodeGetSnapshotSender(pSyncNode, &(pMsg->srcId));
|
||||||
ASSERT(pSender != NULL);
|
ASSERT(pSender != NULL);
|
||||||
|
|
||||||
|
if (pMsg->startTime != pSender->startTime) {
|
||||||
|
syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "sender/receiver start time not match");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// state, term, seq/ack
|
// state, term, seq/ack
|
||||||
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
|
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
|
||||||
if (pMsg->term == pSyncNode->pRaftStore->currentTerm) {
|
if (pMsg->term == pSyncNode->pRaftStore->currentTerm) {
|
||||||
// condition 1
|
// prepare <begin, end>, send begin msg
|
||||||
|
if (pMsg->ack == SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT) {
|
||||||
|
syncNodeOnSnapshotReplyPre(pSyncNode, pMsg);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// receive ack is finish, close sender
|
// receive ack is finish, close sender
|
||||||
if (pMsg->ack == SYNC_SNAPSHOT_SEQ_END) {
|
if (pMsg->ack == SYNC_SNAPSHOT_SEQ_END) {
|
||||||
snapshotSenderStop(pSender, true);
|
snapshotSenderStop(pSender, true);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// condition 2
|
|
||||||
// send next msg
|
// send next msg
|
||||||
if (pMsg->ack == pSender->seq) {
|
if (pMsg->ack == pSender->seq) {
|
||||||
// update sender ack
|
// update sender ack
|
||||||
|
@ -922,3 +1062,63 @@ int32_t syncNodeOnSnapshotReply(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t syncNodeOnPreSnapshot(SSyncNode *ths, SyncPreSnapshot *pMsg) {
|
||||||
|
syncLogRecvSyncPreSnapshot(ths, pMsg, "");
|
||||||
|
|
||||||
|
SyncPreSnapshotReply *pMsgReply = syncPreSnapshotReplyBuild(ths->vgId);
|
||||||
|
pMsgReply->srcId = ths->myRaftId;
|
||||||
|
pMsgReply->destId = pMsg->srcId;
|
||||||
|
pMsgReply->term = ths->pRaftStore->currentTerm;
|
||||||
|
|
||||||
|
SSyncLogStoreData *pData = ths->pLogStore->data;
|
||||||
|
SWal *pWal = pData->pWal;
|
||||||
|
|
||||||
|
if (syncNodeIsMnode(ths)) {
|
||||||
|
pMsgReply->snapStart = SYNC_INDEX_BEGIN;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
bool isEmpty = ths->pLogStore->syncLogIsEmpty(ths->pLogStore);
|
||||||
|
int64_t walCommitVer = walGetCommittedVer(pWal);
|
||||||
|
|
||||||
|
if (!isEmpty && ths->commitIndex != walCommitVer) {
|
||||||
|
char logBuf[128];
|
||||||
|
snprintf(logBuf, sizeof(logBuf), "commit not same, wal-commit:%" PRId64 ", commit:%" PRId64 ", ignore",
|
||||||
|
walCommitVer, ths->commitIndex);
|
||||||
|
syncNodeErrorLog(ths, logBuf);
|
||||||
|
|
||||||
|
goto _IGNORE;
|
||||||
|
}
|
||||||
|
|
||||||
|
pMsgReply->snapStart = ths->commitIndex + 1;
|
||||||
|
|
||||||
|
// make local log clean
|
||||||
|
int32_t code = ths->pLogStore->syncLogTruncate(ths->pLogStore, pMsgReply->snapStart);
|
||||||
|
if (code != 0) {
|
||||||
|
syncNodeErrorLog(ths, "truncate wal error");
|
||||||
|
goto _IGNORE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// can not write behind _RESPONSE
|
||||||
|
SRpcMsg rpcMsg;
|
||||||
|
|
||||||
|
_RESPONSE:
|
||||||
|
syncPreSnapshotReply2RpcMsg(pMsgReply, &rpcMsg);
|
||||||
|
syncNodeSendMsgById(&pMsgReply->destId, ths, &rpcMsg);
|
||||||
|
|
||||||
|
syncPreSnapshotReplyDestroy(pMsgReply);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
_IGNORE:
|
||||||
|
syncPreSnapshotReplyDestroy(pMsgReply);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t syncNodeOnPreSnapshotReply(SSyncNode *ths, SyncPreSnapshotReply *pMsg) {
|
||||||
|
syncLogRecvSyncPreSnapshotReply(ths, pMsg, "");
|
||||||
|
|
||||||
|
// start snapshot
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -176,30 +176,6 @@ char* syncUtilRaftId2Str(const SRaftId* p) {
|
||||||
return serialized;
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* syncUtilState2String(ESyncState state) {
|
|
||||||
/*
|
|
||||||
if (state == TAOS_SYNC_STATE_FOLLOWER) {
|
|
||||||
return "TAOS_SYNC_STATE_FOLLOWER";
|
|
||||||
} else if (state == TAOS_SYNC_STATE_CANDIDATE) {
|
|
||||||
return "TAOS_SYNC_STATE_CANDIDATE";
|
|
||||||
} else if (state == TAOS_SYNC_STATE_LEADER) {
|
|
||||||
return "TAOS_SYNC_STATE_LEADER";
|
|
||||||
} else {
|
|
||||||
return "TAOS_SYNC_STATE_UNKNOWN";
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (state == TAOS_SYNC_STATE_FOLLOWER) {
|
|
||||||
return "follower";
|
|
||||||
} else if (state == TAOS_SYNC_STATE_CANDIDATE) {
|
|
||||||
return "candidate";
|
|
||||||
} else if (state == TAOS_SYNC_STATE_LEADER) {
|
|
||||||
return "leader";
|
|
||||||
} else {
|
|
||||||
return "state_error";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool syncUtilCanPrint(char c) {
|
bool syncUtilCanPrint(char c) {
|
||||||
if (c >= 32 && c <= 126) {
|
if (c >= 32 && c <= 126) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -60,6 +60,8 @@ add_executable(syncRaftCfgIndexTest "")
|
||||||
add_executable(syncHeartbeatTest "")
|
add_executable(syncHeartbeatTest "")
|
||||||
add_executable(syncHeartbeatReplyTest "")
|
add_executable(syncHeartbeatReplyTest "")
|
||||||
add_executable(syncLocalCmdTest "")
|
add_executable(syncLocalCmdTest "")
|
||||||
|
add_executable(syncPreSnapshotTest "")
|
||||||
|
add_executable(syncPreSnapshotReplyTest "")
|
||||||
|
|
||||||
|
|
||||||
target_sources(syncTest
|
target_sources(syncTest
|
||||||
|
@ -310,6 +312,14 @@ target_sources(syncLocalCmdTest
|
||||||
PRIVATE
|
PRIVATE
|
||||||
"syncLocalCmdTest.cpp"
|
"syncLocalCmdTest.cpp"
|
||||||
)
|
)
|
||||||
|
target_sources(syncPreSnapshotTest
|
||||||
|
PRIVATE
|
||||||
|
"syncPreSnapshotTest.cpp"
|
||||||
|
)
|
||||||
|
target_sources(syncPreSnapshotReplyTest
|
||||||
|
PRIVATE
|
||||||
|
"syncPreSnapshotReplyTest.cpp"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
target_include_directories(syncTest
|
target_include_directories(syncTest
|
||||||
|
@ -622,6 +632,16 @@ target_include_directories(syncLocalCmdTest
|
||||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
|
target_include_directories(syncPreSnapshotTest
|
||||||
|
PUBLIC
|
||||||
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
|
)
|
||||||
|
target_include_directories(syncPreSnapshotReplyTest
|
||||||
|
PUBLIC
|
||||||
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
target_link_libraries(syncTest
|
target_link_libraries(syncTest
|
||||||
|
@ -872,6 +892,14 @@ target_link_libraries(syncLocalCmdTest
|
||||||
sync
|
sync
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
|
target_link_libraries(syncPreSnapshotTest
|
||||||
|
sync
|
||||||
|
gtest_main
|
||||||
|
)
|
||||||
|
target_link_libraries(syncPreSnapshotReplyTest
|
||||||
|
sync
|
||||||
|
gtest_main
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
|
@ -47,8 +47,8 @@ void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) {
|
||||||
snprintf(logBuf, sizeof(logBuf),
|
snprintf(logBuf, sizeof(logBuf),
|
||||||
"==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s, flag:%" PRIu64
|
"==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s, flag:%" PRIu64
|
||||||
", term:%" PRIu64 " \n",
|
", term:%" PRIu64 " \n",
|
||||||
pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state),
|
pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncStr(cbMeta.state), cbMeta.flag,
|
||||||
cbMeta.flag, cbMeta.term);
|
cbMeta.term);
|
||||||
syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg);
|
syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg);
|
||||||
} else {
|
} else {
|
||||||
sTrace("==callback== ==CommitCb== do not apply again %" PRId64, cbMeta.index);
|
sTrace("==callback== ==CommitCb== do not apply again %" PRId64, cbMeta.index);
|
||||||
|
@ -57,10 +57,10 @@ void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) {
|
||||||
|
|
||||||
void PreCommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) {
|
void PreCommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) {
|
||||||
char logBuf[256] = {0};
|
char logBuf[256] = {0};
|
||||||
snprintf(
|
snprintf(logBuf, sizeof(logBuf),
|
||||||
logBuf, sizeof(logBuf),
|
"==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64
|
||||||
"==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 "\n",
|
"\n",
|
||||||
pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag);
|
pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncStr(cbMeta.state), cbMeta.flag);
|
||||||
syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg);
|
syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,8 +68,7 @@ void RollBackCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) {
|
||||||
char logBuf[256];
|
char logBuf[256];
|
||||||
snprintf(logBuf, sizeof(logBuf),
|
snprintf(logBuf, sizeof(logBuf),
|
||||||
"==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 "\n",
|
"==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 "\n",
|
||||||
pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state),
|
pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncStr(cbMeta.state), cbMeta.flag);
|
||||||
cbMeta.flag);
|
|
||||||
syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg);
|
syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,6 +157,7 @@ SSyncFSM* createFsm() {
|
||||||
SSyncFSM* pFsm = (SSyncFSM*)taosMemoryMalloc(sizeof(SSyncFSM));
|
SSyncFSM* pFsm = (SSyncFSM*)taosMemoryMalloc(sizeof(SSyncFSM));
|
||||||
memset(pFsm, 0, sizeof(*pFsm));
|
memset(pFsm, 0, sizeof(*pFsm));
|
||||||
|
|
||||||
|
#if 0
|
||||||
pFsm->FpCommitCb = CommitCb;
|
pFsm->FpCommitCb = CommitCb;
|
||||||
pFsm->FpPreCommitCb = PreCommitCb;
|
pFsm->FpPreCommitCb = PreCommitCb;
|
||||||
pFsm->FpRollBackCb = RollBackCb;
|
pFsm->FpRollBackCb = RollBackCb;
|
||||||
|
@ -172,6 +172,7 @@ SSyncFSM* createFsm() {
|
||||||
pFsm->FpSnapshotDoWrite = SnapshotDoWrite;
|
pFsm->FpSnapshotDoWrite = SnapshotDoWrite;
|
||||||
|
|
||||||
pFsm->FpReConfigCb = ReConfigCb;
|
pFsm->FpReConfigCb = ReConfigCb;
|
||||||
|
#endif
|
||||||
|
|
||||||
return pFsm;
|
return pFsm;
|
||||||
}
|
}
|
||||||
|
@ -195,8 +196,8 @@ int64_t createSyncNode(int32_t replicaNum, int32_t myIndex, int32_t vgId, SWal*
|
||||||
SSyncInfo syncInfo;
|
SSyncInfo syncInfo;
|
||||||
syncInfo.vgId = vgId;
|
syncInfo.vgId = vgId;
|
||||||
syncInfo.msgcb = &gSyncIO->msgcb;
|
syncInfo.msgcb = &gSyncIO->msgcb;
|
||||||
syncInfo.FpSendMsg = syncIOSendMsg;
|
syncInfo.syncSendMSg = syncIOSendMsg;
|
||||||
syncInfo.FpEqMsg = syncIOEqMsg;
|
syncInfo.syncEqMsg = syncIOEqMsg;
|
||||||
syncInfo.pFsm = createFsm();
|
syncInfo.pFsm = createFsm();
|
||||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s_sync_replica%d_index%d", path, replicaNum, myIndex);
|
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s_sync_replica%d_index%d", path, replicaNum, myIndex);
|
||||||
syncInfo.pWal = pWal;
|
syncInfo.pWal = pWal;
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue