Merge remote-tracking branch 'origin/enh/triggerCheckPoint2' into enh/triggerCheckPoint2
# Conflicts: # source/dnode/vnode/src/tq/tq.c
This commit is contained in:
commit
82e356a9b5
|
@ -11,7 +11,7 @@ ExternalProject_Add(aprutil-1
|
|||
BUILD_IN_SOURCE TRUE
|
||||
BUILD_ALWAYS 1
|
||||
#UPDATE_COMMAND ""
|
||||
CONFIGURE_COMMAND ./configure --prefix=$ENV{HOME}/.cos-local.1/ --with-apr=$ENV{HOME}/.cos-local.1
|
||||
CONFIGURE_COMMAND ./configure --prefix=$ENV{HOME}/.cos-local.1/ --with-apr=$ENV{HOME}/.cos-local.1
|
||||
#CONFIGURE_COMMAND ./configure --with-apr=/usr/local/apr
|
||||
BUILD_COMMAND make
|
||||
INSTALL_COMMAND make install
|
||||
|
|
|
@ -9,7 +9,7 @@ ExternalProject_Add(curl
|
|||
BUILD_IN_SOURCE TRUE
|
||||
BUILD_ALWAYS 1
|
||||
#UPDATE_COMMAND ""
|
||||
CONFIGURE_COMMAND ./configure --prefix=$ENV{HOME}/.cos-local.1 --without-ssl --enable-shared=no --disable-ldap --disable-ldaps --without-brotli
|
||||
CONFIGURE_COMMAND ./configure --prefix=$ENV{HOME}/.cos-local.1 --without-ssl --enable-shared=no --disable-ldap --disable-ldaps --without-brotli --without-zstd
|
||||
#CONFIGURE_COMMAND ./configure --without-ssl
|
||||
BUILD_COMMAND make
|
||||
INSTALL_COMMAND make install
|
||||
|
|
|
@ -9,7 +9,7 @@ description: This document describes how to query data in TDengine.
|
|||
```sql
|
||||
SELECT {DATABASE() | CLIENT_VERSION() | SERVER_VERSION() | SERVER_STATUS() | NOW() | TODAY() | TIMEZONE()}
|
||||
|
||||
SELECT [DISTINCT] select_list
|
||||
SELECT [hints] [DISTINCT] select_list
|
||||
from_clause
|
||||
[WHERE condition]
|
||||
[partition_by_clause]
|
||||
|
@ -21,6 +21,11 @@ SELECT [DISTINCT] select_list
|
|||
[LIMIT limit_val [OFFSET offset_val]]
|
||||
[>> export_file]
|
||||
|
||||
hints: /*+ [hint([hint_param_list])] [hint([hint_param_list])] */
|
||||
|
||||
hint:
|
||||
BATCH_SCAN | NO_BATCH_SCAN
|
||||
|
||||
select_list:
|
||||
select_expr [, select_expr] ...
|
||||
|
||||
|
@ -70,6 +75,29 @@ order_expr:
|
|||
{expr | position | c_alias} [DESC | ASC] [NULLS FIRST | NULLS LAST]
|
||||
```
|
||||
|
||||
## Hints
|
||||
|
||||
Hints are a means of user control over query optimization for individual statements. Hints will be ignore automatically if they are not applicable to the current query statement. The specific instructions are as follows:
|
||||
|
||||
- Hints syntax starts with `/*+` and ends with `*/`, spaces are allowed before or after.
|
||||
- Hints syntax can only follow the SELECT keyword.
|
||||
- Each hints can contain multiple hint, separated by spaces. When multiple hints conflict or are identical, whichever comes first takes effect.
|
||||
- When an error occurs with a hint in hints, the effective hint before the error is still valid, and the current and subsequent hints are ignored.
|
||||
- hint_param_list are arguments to each hint, which varies according to each hint.
|
||||
|
||||
The list of currently supported Hints is as follows:
|
||||
|
||||
| **Hint** | **Params** | **Comment** | **Scopt** |
|
||||
| :-----------: | -------------- | -------------------------- | -------------------------- |
|
||||
| BATCH_SCAN | None | Batch table scan | JOIN statment for stable |
|
||||
| NO_BATCH_SCAN | None | Sequential table scan | JOIN statment for stable |
|
||||
|
||||
For example:
|
||||
|
||||
```sql
|
||||
SELECT /*+ BATCH_SCAN() */ a.ts FROM stable1 a, stable2 b where a.tag0 = b.tag0 and a.ts = b.ts;
|
||||
```
|
||||
|
||||
## Lists
|
||||
|
||||
A query can be performed on some or all columns. Data and tag columns can all be included in the SELECT list.
|
||||
|
|
|
@ -10,6 +10,10 @@ For TDengine 2.x installation packages by version, please visit [here](https://t
|
|||
|
||||
import Release from "/components/ReleaseV3";
|
||||
|
||||
## 3.1.0.2
|
||||
|
||||
<Release type="tdengine" version="3.1.0.2" />
|
||||
|
||||
## 3.1.0.0
|
||||
|
||||
:::note IMPORTANT
|
||||
|
|
|
@ -9,7 +9,7 @@ description: 查询数据的详细语法
|
|||
```sql
|
||||
SELECT {DATABASE() | CLIENT_VERSION() | SERVER_VERSION() | SERVER_STATUS() | NOW() | TODAY() | TIMEZONE()}
|
||||
|
||||
SELECT [DISTINCT] select_list
|
||||
SELECT [hints] [DISTINCT] select_list
|
||||
from_clause
|
||||
[WHERE condition]
|
||||
[partition_by_clause]
|
||||
|
@ -21,6 +21,11 @@ SELECT [DISTINCT] select_list
|
|||
[LIMIT limit_val [OFFSET offset_val]]
|
||||
[>> export_file]
|
||||
|
||||
hints: /*+ [hint([hint_param_list])] [hint([hint_param_list])] */
|
||||
|
||||
hint:
|
||||
BATCH_SCAN | NO_BATCH_SCAN
|
||||
|
||||
select_list:
|
||||
select_expr [, select_expr] ...
|
||||
|
||||
|
@ -70,6 +75,29 @@ order_expr:
|
|||
{expr | position | c_alias} [DESC | ASC] [NULLS FIRST | NULLS LAST]
|
||||
```
|
||||
|
||||
## Hints
|
||||
|
||||
Hints 是用户控制单个语句查询优化的一种手段,当 Hint 不适用于当前的查询语句时会被自动忽略,具体说明如下:
|
||||
|
||||
- Hints 语法以`/*+`开始,终于`*/`,前后可有空格。
|
||||
- Hints 语法只能跟随在 SELECT 关键字后。
|
||||
- 每个 Hints 可以包含多个 Hint,Hint 间以空格分开,当多个 Hint 冲突或相同时以先出现的为准。
|
||||
- 当 Hints 中某个 Hint 出现错误时,错误出现之前的有效 Hint 仍然有效,当前及之后的 Hint 被忽略。
|
||||
- hint_param_list 是每个 Hint 的参数,根据每个 Hint 的不同而不同。
|
||||
|
||||
目前支持的 Hints 列表如下:
|
||||
|
||||
| **Hint** | **参数** | **说明** | **适用范围** |
|
||||
| :-----------: | -------------- | -------------------------- | -------------------------- |
|
||||
| BATCH_SCAN | 无 | 采用批量读表的方式 | 超级表 JOIN 语句 |
|
||||
| NO_BATCH_SCAN | 无 | 采用顺序读表的方式 | 超级表 JOIN 语句 |
|
||||
|
||||
举例:
|
||||
|
||||
```sql
|
||||
SELECT /*+ BATCH_SCAN() */ a.ts FROM stable1 a, stable2 b where a.tag0 = b.tag0 and a.ts = b.ts;
|
||||
```
|
||||
|
||||
## 列表
|
||||
|
||||
查询语句可以指定部分或全部列作为返回结果。数据列和标签列都可以出现在列表中。
|
||||
|
|
|
@ -10,6 +10,10 @@ TDengine 2.x 各版本安装包请访问[这里](https://www.taosdata.com/all-do
|
|||
|
||||
import Release from "/components/ReleaseV3";
|
||||
|
||||
## 3.1.0.2
|
||||
|
||||
<Release type="tdengine" version="3.1.0.2" />
|
||||
|
||||
## 3.1.0.0
|
||||
|
||||
<Release type="tdengine" version="3.1.0.0" />
|
||||
|
|
|
@ -130,6 +130,7 @@ extern bool tsKeepColumnName;
|
|||
extern bool tsEnableQueryHb;
|
||||
extern bool tsEnableScience;
|
||||
extern bool tsTtlChangeOnWrite;
|
||||
extern int32_t tsTtlFlushThreshold;
|
||||
extern int32_t tsRedirectPeriod;
|
||||
extern int32_t tsRedirectFactor;
|
||||
extern int32_t tsRedirectMaxPeriod;
|
||||
|
@ -161,6 +162,7 @@ extern char tsCompressor[];
|
|||
// tfs
|
||||
extern int32_t tsDiskCfgNum;
|
||||
extern SDiskCfg tsDiskCfg[];
|
||||
extern int64_t tsMinDiskFreeSize;
|
||||
|
||||
// udf
|
||||
extern bool tsStartUdfd;
|
||||
|
@ -186,7 +188,9 @@ extern int32_t tsMqRebalanceInterval;
|
|||
extern int32_t tsStreamCheckpointTickInterval;
|
||||
extern int32_t tsStreamNodeCheckInterval;
|
||||
extern int32_t tsTtlUnit;
|
||||
extern int32_t tsTtlPushInterval;
|
||||
extern int32_t tsTtlPushIntervalSec;
|
||||
extern int32_t tsTtlBatchDropNum;
|
||||
extern int32_t tsTrimVDbIntervalSec;
|
||||
extern int32_t tsGrantHBInterval;
|
||||
extern int32_t tsUptimeInterval;
|
||||
|
||||
|
|
|
@ -77,7 +77,8 @@ static inline bool tmsgIsValid(tmsg_t type) {
|
|||
}
|
||||
static inline bool vnodeIsMsgBlock(tmsg_t type) {
|
||||
return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
|
||||
(type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT);
|
||||
(type == TDMT_VND_UPDATE_TAG_VAL) || (type == TDMT_VND_ALTER_CONFIRM) || (type == TDMT_VND_COMMIT) ||
|
||||
(type == TDMT_SYNC_CONFIG_CHANGE);
|
||||
}
|
||||
|
||||
static inline bool syncUtilUserCommit(tmsg_t msgType) {
|
||||
|
@ -440,7 +441,6 @@ typedef struct SField {
|
|||
uint8_t type;
|
||||
int8_t flags;
|
||||
int32_t bytes;
|
||||
char comment[TSDB_COL_COMMENT_LEN];
|
||||
} SField;
|
||||
|
||||
typedef struct SRetention {
|
||||
|
@ -519,7 +519,6 @@ struct SSchema {
|
|||
col_id_t colId;
|
||||
int32_t bytes;
|
||||
char name[TSDB_COL_NAME_LEN];
|
||||
char comment[TSDB_COL_COMMENT_LEN];
|
||||
};
|
||||
|
||||
struct SSchema2 {
|
||||
|
@ -1160,6 +1159,9 @@ int32_t tDeserializeSVTrimDbReq(void* buf, int32_t bufLen, SVTrimDbReq* pReq);
|
|||
|
||||
typedef struct {
|
||||
int32_t timestampSec;
|
||||
int32_t ttlDropMaxCount;
|
||||
int32_t nUids;
|
||||
SArray* pTbUids;
|
||||
} SVDropTtlTableReq;
|
||||
|
||||
int32_t tSerializeSVDropTtlTableReq(void* buf, int32_t bufLen, SVDropTtlTableReq* pReq);
|
||||
|
@ -1400,6 +1402,7 @@ typedef struct {
|
|||
int64_t numOfBatchInsertReqs;
|
||||
int64_t numOfBatchInsertSuccessReqs;
|
||||
int32_t numOfCachedTables;
|
||||
int32_t learnerProgress; // use one reservered
|
||||
} SVnodeLoad;
|
||||
|
||||
typedef struct {
|
||||
|
@ -1541,6 +1544,7 @@ typedef struct {
|
|||
int8_t learnerReplica;
|
||||
int8_t learnerSelfIndex;
|
||||
SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
|
||||
int32_t changeVersion;
|
||||
} SCreateVnodeReq;
|
||||
|
||||
int32_t tSerializeSCreateVnodeReq(void* buf, int32_t bufLen, SCreateVnodeReq* pReq);
|
||||
|
@ -1615,7 +1619,8 @@ typedef struct {
|
|||
int8_t learnerSelfIndex;
|
||||
int8_t learnerReplica;
|
||||
SReplica learnerReplicas[TSDB_MAX_LEARNER_REPLICA];
|
||||
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq;
|
||||
int32_t changeVersion;
|
||||
} SAlterVnodeReplicaReq, SAlterVnodeTypeReq, SCheckLearnCatchupReq;
|
||||
|
||||
int32_t tSerializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
|
||||
int32_t tDeserializeSAlterVnodeReplicaReq(void* buf, int32_t bufLen, SAlterVnodeReplicaReq* pReq);
|
||||
|
@ -1633,7 +1638,8 @@ typedef struct {
|
|||
int32_t dstVgId;
|
||||
uint32_t hashBegin;
|
||||
uint32_t hashEnd;
|
||||
int64_t reserved;
|
||||
int32_t changeVersion;
|
||||
int32_t reserved;
|
||||
} SAlterVnodeHashRangeReq;
|
||||
|
||||
int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq);
|
||||
|
@ -2625,9 +2631,6 @@ typedef struct {
|
|||
int8_t type;
|
||||
int8_t flags;
|
||||
int32_t bytes;
|
||||
bool hasColComment;
|
||||
char* colComment;
|
||||
int32_t colCommentLen;
|
||||
// TSDB_ALTER_TABLE_DROP_COLUMN
|
||||
// TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
|
||||
int8_t colModType;
|
||||
|
|
|
@ -65,7 +65,7 @@ enum {
|
|||
#define TD_NEW_MSG_SEG(TYPE) TYPE = ((TYPE##_SEG_CODE) << 8),
|
||||
#define TD_DEF_MSG_TYPE(TYPE, MSG, REQ, RSP) TYPE, TYPE##_RSP,
|
||||
|
||||
enum {
|
||||
enum { // WARN: new msg should be appended to segment tail
|
||||
#endif
|
||||
TD_NEW_MSG_SEG(TDMT_DND_MSG)
|
||||
TD_DEF_MSG_TYPE(TDMT_DND_CREATE_MNODE, "dnode-create-mnode", NULL, NULL)
|
||||
|
@ -85,18 +85,19 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_DND_MAX_MSG, "dnd-max", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_DND_ALTER_MNODE_TYPE, "dnode-alter-mnode-type", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_DND_ALTER_VNODE_TYPE, "dnode-alter-vnode-type", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP, "dnode-check-vnode-learner-catchup", NULL, NULL)
|
||||
|
||||
TD_NEW_MSG_SEG(TDMT_MND_MSG)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_CONNECT, "connect", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_ACCT, "create-acct", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_ACCT, "create-acct", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_ACCT, "alter-acct", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_ACCT, "drop-acct", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_USER, "create-user", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_USER, "create-user", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_USER, "alter-user", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_USER, "drop-user", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_GET_USER_AUTH, "get-user-auth", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_USER, "drop-user", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_GET_USER_AUTH, "get-user-auth", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_DNODE, "create-dnode", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_CONFIG_DNODE, "config-dnode", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_CONFIG_DNODE, "config-dnode", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_DNODE, "drop-dnode", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_MNODE, "create-mnode", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_MNODE, "alter-mnode", NULL, NULL)
|
||||
|
@ -185,6 +186,7 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_MND_STREAM_CHECKPOINT_TIMER, "stream-checkpoint-tmr", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_STREAM_BEGIN_CHECKPOINT, "stream-begin-checkpoint", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_STREAM_NODECHANGE_CHECK, "stream-nodechange-check", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_TRIM_DB_TIMER, "trim-db-tmr", NULL, NULL)
|
||||
|
||||
TD_NEW_MSG_SEG(TDMT_VND_MSG)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_SUBMIT, "submit", SSubmitReq, SSubmitRsp)
|
||||
|
@ -297,7 +299,7 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_SYNC_PRE_SNAPSHOT_REPLY, "sync-pre-snapshot-reply", NULL, NULL) // no longer used
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_MAX_MSG, "sync-max", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_FORCE_FOLLOWER, "sync-force-become-follower", 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_SCAN_HISTORY, "vnode-stream-scan-history", NULL, NULL)
|
||||
|
|
|
@ -130,25 +130,25 @@
|
|||
#define TK_NK_EQ 112
|
||||
#define TK_USING 113
|
||||
#define TK_TAGS 114
|
||||
#define TK_COMMENT 115
|
||||
#define TK_BOOL 116
|
||||
#define TK_TINYINT 117
|
||||
#define TK_SMALLINT 118
|
||||
#define TK_INT 119
|
||||
#define TK_INTEGER 120
|
||||
#define TK_BIGINT 121
|
||||
#define TK_FLOAT 122
|
||||
#define TK_DOUBLE 123
|
||||
#define TK_BINARY 124
|
||||
#define TK_NCHAR 125
|
||||
#define TK_UNSIGNED 126
|
||||
#define TK_JSON 127
|
||||
#define TK_VARCHAR 128
|
||||
#define TK_MEDIUMBLOB 129
|
||||
#define TK_BLOB 130
|
||||
#define TK_VARBINARY 131
|
||||
#define TK_GEOMETRY 132
|
||||
#define TK_DECIMAL 133
|
||||
#define TK_BOOL 115
|
||||
#define TK_TINYINT 116
|
||||
#define TK_SMALLINT 117
|
||||
#define TK_INT 118
|
||||
#define TK_INTEGER 119
|
||||
#define TK_BIGINT 120
|
||||
#define TK_FLOAT 121
|
||||
#define TK_DOUBLE 122
|
||||
#define TK_BINARY 123
|
||||
#define TK_NCHAR 124
|
||||
#define TK_UNSIGNED 125
|
||||
#define TK_JSON 126
|
||||
#define TK_VARCHAR 127
|
||||
#define TK_MEDIUMBLOB 128
|
||||
#define TK_BLOB 129
|
||||
#define TK_VARBINARY 130
|
||||
#define TK_GEOMETRY 131
|
||||
#define TK_DECIMAL 132
|
||||
#define TK_COMMENT 133
|
||||
#define TK_MAX_DELAY 134
|
||||
#define TK_WATERMARK 135
|
||||
#define TK_ROLLUP 136
|
||||
|
|
|
@ -23,11 +23,10 @@ extern "C" {
|
|||
#include "query.h"
|
||||
#include "querynodes.h"
|
||||
|
||||
#define DESCRIBE_RESULT_COLS 5
|
||||
#define DESCRIBE_RESULT_FIELD_LEN (TSDB_COL_NAME_LEN - 1 + VARSTR_HEADER_SIZE)
|
||||
#define DESCRIBE_RESULT_TYPE_LEN (20 + VARSTR_HEADER_SIZE)
|
||||
#define DESCRIBE_RESULT_NOTE_LEN (8 + VARSTR_HEADER_SIZE)
|
||||
#define DESCRIBE_RESULT_COL_COMMENT_LEN (TSDB_COL_COMMENT_LEN)
|
||||
#define DESCRIBE_RESULT_COLS 4
|
||||
#define DESCRIBE_RESULT_FIELD_LEN (TSDB_COL_NAME_LEN - 1 + VARSTR_HEADER_SIZE)
|
||||
#define DESCRIBE_RESULT_TYPE_LEN (20 + VARSTR_HEADER_SIZE)
|
||||
#define DESCRIBE_RESULT_NOTE_LEN (8 + VARSTR_HEADER_SIZE)
|
||||
|
||||
#define SHOW_CREATE_DB_RESULT_COLS 2
|
||||
#define SHOW_CREATE_DB_RESULT_FIELD1_LEN (TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE)
|
||||
|
@ -156,7 +155,7 @@ typedef struct SColumnDefNode {
|
|||
ENodeType type;
|
||||
char colName[TSDB_COL_NAME_LEN];
|
||||
SDataType dataType;
|
||||
char comments[TSDB_COL_COMMENT_LEN];
|
||||
char comments[TSDB_TB_COMMENT_LEN];
|
||||
bool sma;
|
||||
} SColumnDefNode;
|
||||
|
||||
|
@ -215,7 +214,6 @@ typedef struct SAlterTableStmt {
|
|||
char newColName[TSDB_COL_NAME_LEN];
|
||||
STableOptions* pOptions;
|
||||
SDataType dataType;
|
||||
char colComment[TSDB_COL_COMMENT_LEN];
|
||||
SValueNode* pVal;
|
||||
} SAlterTableStmt;
|
||||
|
||||
|
|
|
@ -101,6 +101,7 @@ typedef struct SSyncCfg {
|
|||
int32_t myIndex;
|
||||
SNodeInfo nodeInfo[TSDB_MAX_REPLICA + TSDB_MAX_LEARNER_REPLICA];
|
||||
SyncIndex lastIndex;
|
||||
int32_t changeVersion;
|
||||
} SSyncCfg;
|
||||
|
||||
typedef struct SFsmCbMeta {
|
||||
|
@ -239,20 +240,22 @@ typedef struct SSyncState {
|
|||
ESyncState state;
|
||||
bool restored;
|
||||
bool canRead;
|
||||
int32_t progress;
|
||||
SyncTerm term;
|
||||
int64_t roleTimeMs;
|
||||
int64_t startTimeMs;
|
||||
} SSyncState;
|
||||
|
||||
int32_t syncInit();
|
||||
void syncCleanUp();
|
||||
int64_t syncOpen(SSyncInfo* pSyncInfo);
|
||||
int32_t syncStart(int64_t rid);
|
||||
void syncStop(int64_t rid);
|
||||
void syncPreStop(int64_t rid);
|
||||
void syncPostStop(int64_t rid);
|
||||
int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak, int64_t* seq);
|
||||
int32_t syncIsCatchUp(int64_t rid);
|
||||
int32_t syncInit();
|
||||
void syncCleanUp();
|
||||
int64_t syncOpen(SSyncInfo* pSyncInfo, int32_t vnodeVersion);
|
||||
int32_t syncStart(int64_t rid);
|
||||
void syncStop(int64_t rid);
|
||||
void syncPreStop(int64_t rid);
|
||||
void syncPostStop(int64_t rid);
|
||||
int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak, int64_t* seq);
|
||||
int32_t syncCheckMember(int64_t rid);
|
||||
int32_t syncIsCatchUp(int64_t rid);
|
||||
ESyncRole syncGetRole(int64_t rid);
|
||||
int32_t syncProcessMsg(int64_t rid, SRpcMsg* pMsg);
|
||||
int32_t syncReconfig(int64_t rid, SSyncCfg* pCfg);
|
||||
|
@ -270,6 +273,8 @@ SSyncState syncGetState(int64_t rid);
|
|||
void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet);
|
||||
const char* syncStr(ESyncState state);
|
||||
|
||||
int32_t syncNodeGetConfig(int64_t rid, SSyncCfg *cfg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -200,7 +200,7 @@ typedef enum ELogicConditionType {
|
|||
#define TSDB_STREAM_NAME_LEN 193 // it is a null-terminated string
|
||||
#define TSDB_DB_NAME_LEN 65
|
||||
#define TSDB_DB_FNAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
|
||||
#define TSDB_PRIVILEDGE_CONDITION_LEN 48*1024
|
||||
#define TSDB_PRIVILEDGE_CONDITION_LEN 48 * 1024
|
||||
|
||||
#define TSDB_FUNC_NAME_LEN 65
|
||||
#define TSDB_FUNC_COMMENT_LEN 1024 * 1024
|
||||
|
@ -230,7 +230,6 @@ typedef enum ELogicConditionType {
|
|||
|
||||
#define TSDB_APP_NAME_LEN TSDB_UNI_LEN
|
||||
#define TSDB_TB_COMMENT_LEN 1025
|
||||
#define TSDB_COL_COMMENT_LEN 1025
|
||||
|
||||
#define TSDB_QUERY_ID_LEN 26
|
||||
#define TSDB_TRANS_OPER_LEN 16
|
||||
|
@ -377,12 +376,12 @@ typedef enum ELogicConditionType {
|
|||
#define TSDB_MAX_STT_TRIGGER 1
|
||||
#define TSDB_DEFAULT_SST_TRIGGER 1
|
||||
#endif
|
||||
#define TSDB_MIN_HASH_PREFIX (2 - TSDB_TABLE_NAME_LEN)
|
||||
#define TSDB_MAX_HASH_PREFIX (TSDB_TABLE_NAME_LEN - 2)
|
||||
#define TSDB_DEFAULT_HASH_PREFIX 0
|
||||
#define TSDB_MIN_HASH_SUFFIX (2 - TSDB_TABLE_NAME_LEN)
|
||||
#define TSDB_MAX_HASH_SUFFIX (TSDB_TABLE_NAME_LEN - 2)
|
||||
#define TSDB_DEFAULT_HASH_SUFFIX 0
|
||||
#define TSDB_MIN_HASH_PREFIX (2 - TSDB_TABLE_NAME_LEN)
|
||||
#define TSDB_MAX_HASH_PREFIX (TSDB_TABLE_NAME_LEN - 2)
|
||||
#define TSDB_DEFAULT_HASH_PREFIX 0
|
||||
#define TSDB_MIN_HASH_SUFFIX (2 - TSDB_TABLE_NAME_LEN)
|
||||
#define TSDB_MAX_HASH_SUFFIX (TSDB_TABLE_NAME_LEN - 2)
|
||||
#define TSDB_DEFAULT_HASH_SUFFIX 0
|
||||
|
||||
#define TSDB_DB_MIN_WAL_RETENTION_PERIOD -1
|
||||
#define TSDB_REP_DEF_DB_WAL_RET_PERIOD 3600
|
||||
|
|
|
@ -92,6 +92,10 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqSubscriptionIm
|
|||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqCommitSync(JNIEnv *, jobject, jlong, jlong);
|
||||
|
||||
JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqCommitAllSync(JNIEnv *, jobject, jlong);
|
||||
|
||||
JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqCommitOffsetSyncImp(JNIEnv *, jobject, jlong, jstring,
|
||||
jint, jlong);
|
||||
/*
|
||||
* Class: com_taosdata_jdbc_tmq_TMQConnector
|
||||
* Method: tmqCommitAsync
|
||||
|
@ -102,6 +106,12 @@ JNIEXPORT void JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqCommitAsync(JN
|
|||
JNIEXPORT void JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_consumerCommitAsync(JNIEnv *, jobject, jlong, jlong,
|
||||
jobject);
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_consumerCommitAllAsync(JNIEnv *, jobject, jlong,
|
||||
jobject);
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_consumerCommitOffsetAsync(JNIEnv *, jobject, jlong,
|
||||
jstring, jint, jlong, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_taosdata_jdbc_tmq_TMQConnector
|
||||
* Method: tmqUnsubscribeImp
|
||||
|
@ -179,6 +189,11 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqSeekImp(JNIEnv
|
|||
JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqGetTopicAssignmentImp(JNIEnv *, jobject, jlong,
|
||||
jstring, jobject);
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqCommittedImp(JNIEnv *, jobject, jlong, jstring,
|
||||
jint);
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqPositionImp(JNIEnv *, jobject, jlong, jstring, jint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -291,6 +291,39 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqCommitSync(JNI
|
|||
TAOS_RES *res = (TAOS_RES *)jres;
|
||||
return tmq_commit_sync(tmq, res);
|
||||
}
|
||||
JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqCommitAllSync(JNIEnv *env, jobject jobj, jlong jtmq) {
|
||||
tmq_t *tmq = (tmq_t *)jtmq;
|
||||
if (tmq == NULL) {
|
||||
jniError("jobj:%p, tmq is closed", jobj);
|
||||
return TMQ_CONSUMER_NULL;
|
||||
}
|
||||
|
||||
return tmq_commit_sync(tmq, NULL);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqCommitOffsetSyncImp(JNIEnv *env, jobject jobj,
|
||||
jlong jtmq, jstring jtopic,
|
||||
jint vgId, jlong offset) {
|
||||
tmq_t *tmq = (tmq_t *)jtmq;
|
||||
if (tmq == NULL) {
|
||||
jniDebug("jobj:%p, tmq is closed", jobj);
|
||||
return TMQ_CONSUMER_NULL;
|
||||
}
|
||||
|
||||
if (jtopic == NULL) {
|
||||
jniDebug("jobj:%p, topic is null", jobj);
|
||||
return TMQ_TOPIC_NULL;
|
||||
}
|
||||
const char *topicName = (*env)->GetStringUTFChars(env, jtopic, NULL);
|
||||
|
||||
int code = tmq_commit_offset_sync(tmq, topicName, vgId, offset);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
jniError("jobj:%p, tmq commit offset error, code:%d, msg:%s", jobj, code, tmq_err2str(code));
|
||||
}
|
||||
|
||||
(*env)->ReleaseStringUTFChars(env, jtopic, topicName);
|
||||
return code;
|
||||
}
|
||||
|
||||
// deprecated
|
||||
JNIEXPORT void JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqCommitAsync(JNIEnv *env, jobject jobj, jlong jtmq,
|
||||
|
@ -319,6 +352,27 @@ JNIEXPORT void JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_consumerCommitAsy
|
|||
tmq_commit_async(tmq, res, consumer_callback, offset);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_consumerCommitAllAsync(JNIEnv *env, jobject jobj,
|
||||
jlong jtmq, jobject offset) {
|
||||
tmqGlobalMethod(env);
|
||||
tmq_t *tmq = (tmq_t *)jtmq;
|
||||
|
||||
offset = (*env)->NewGlobalRef(env, offset);
|
||||
tmq_commit_async(tmq, NULL, consumer_callback, offset);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_consumerCommitOffsetAsync(JNIEnv *env, jobject jobj,
|
||||
jlong jtmq, jstring jtopic,
|
||||
jint vgId, jlong offset,
|
||||
jobject callback) {
|
||||
tmqGlobalMethod(env);
|
||||
tmq_t *tmq = (tmq_t *)jtmq;
|
||||
const char *topicName = (*env)->GetStringUTFChars(env, jtopic, NULL);
|
||||
|
||||
callback = (*env)->NewGlobalRef(env, callback);
|
||||
tmq_commit_offset_async(tmq, topicName, vgId, offset, consumer_callback, callback);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqUnsubscribeImp(JNIEnv *env, jobject jobj,
|
||||
jlong jtmq) {
|
||||
tmq_t *tmq = (tmq_t *)jtmq;
|
||||
|
@ -497,9 +551,9 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqGetTopicAssign
|
|||
int32_t res = tmq_get_topic_assignment(tmq, topicName, &pAssign, &numOfAssignment);
|
||||
|
||||
if (res != TSDB_CODE_SUCCESS) {
|
||||
(*env)->ReleaseStringUTFChars(env, jtopic, topicName);
|
||||
jniError("jobj:%p, tmq get topic assignment error, topic:%s, code:%d, msg:%s", jobj, topicName, res,
|
||||
tmq_err2str(res));
|
||||
(*env)->ReleaseStringUTFChars(env, jtopic, topicName);
|
||||
tmq_free_assignment(pAssign);
|
||||
return (jint)res;
|
||||
}
|
||||
|
@ -518,3 +572,55 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqGetTopicAssign
|
|||
tmq_free_assignment(pAssign);
|
||||
return JNI_SUCCESS;
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqCommittedImp(JNIEnv *env, jobject jobj, jlong jtmq,
|
||||
jstring jtopic, jint vgId) {
|
||||
tmq_t *tmq = (tmq_t *)jtmq;
|
||||
if (tmq == NULL) {
|
||||
jniDebug("jobj:%p, tmq is closed", jobj);
|
||||
return TMQ_CONSUMER_NULL;
|
||||
}
|
||||
|
||||
if (jtopic == NULL) {
|
||||
jniDebug("jobj:%p, topic is null", jobj);
|
||||
return TMQ_TOPIC_NULL;
|
||||
}
|
||||
|
||||
const char *topicName = (*env)->GetStringUTFChars(env, jtopic, NULL);
|
||||
|
||||
int64_t offset = tmq_committed(tmq, topicName, vgId);
|
||||
|
||||
if (offset < JNI_SUCCESS && offset != -2147467247) {
|
||||
jniError("jobj:%p, tmq get committed offset error, topic:%s, vgId:%d, code:0x%" PRIx64 ", msg:%s", jobj, topicName,
|
||||
vgId, offset, tmq_err2str(offset));
|
||||
}
|
||||
|
||||
(*env)->ReleaseStringUTFChars(env, jtopic, topicName);
|
||||
return (jlong)offset;
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqPositionImp(JNIEnv *env, jobject jobj, jlong jtmq,
|
||||
jstring jtopic, jint vgId) {
|
||||
tmq_t *tmq = (tmq_t *)jtmq;
|
||||
if (tmq == NULL) {
|
||||
jniDebug("jobj:%p, tmq is closed", jobj);
|
||||
return TMQ_CONSUMER_NULL;
|
||||
}
|
||||
|
||||
if (jtopic == NULL) {
|
||||
jniDebug("jobj:%p, topic is null", jobj);
|
||||
return TMQ_TOPIC_NULL;
|
||||
}
|
||||
|
||||
const char *topicName = (*env)->GetStringUTFChars(env, jtopic, NULL);
|
||||
|
||||
int64_t offset = tmq_position(tmq, topicName, vgId);
|
||||
|
||||
if (offset < JNI_SUCCESS) {
|
||||
jniError("jobj:%p, tmq get position error, topic:%s, vgId:%d, code:0x%" PRIx64 ", msg:%s", jobj, topicName, vgId,
|
||||
offset, tmq_err2str(offset));
|
||||
}
|
||||
|
||||
(*env)->ReleaseStringUTFChars(env, jtopic, topicName);
|
||||
return (jlong)offset;
|
||||
}
|
|
@ -124,7 +124,6 @@ int32_t tsQueryRspPolicy = 0;
|
|||
int64_t tsQueryMaxConcurrentTables = 200; // unit is TSDB_TABLE_NUM_UNIT
|
||||
bool tsEnableQueryHb = true;
|
||||
bool tsEnableScience = false; // on taos-cli show float and doulbe with scientific notation if true
|
||||
bool tsTtlChangeOnWrite = false; // ttl delete time changes on last write if true
|
||||
int32_t tsQuerySmaOptimize = 0;
|
||||
int32_t tsQueryRsmaTolerance = 1000; // the tolerance time (ms) to judge from which level to query rsma data.
|
||||
bool tsQueryPlannerTrace = false;
|
||||
|
@ -186,6 +185,7 @@ int32_t tsCacheLazyLoadThreshold = 500;
|
|||
|
||||
int32_t tsDiskCfgNum = 0;
|
||||
SDiskCfg tsDiskCfg[TFS_MAX_DISKS] = {0};
|
||||
int64_t tsMinDiskFreeSize = TFS_MIN_DISK_FREE_SIZE;
|
||||
|
||||
// stream scheduler
|
||||
bool tsDeployOnSnode = true;
|
||||
|
@ -225,13 +225,21 @@ bool tsStartUdfd = true;
|
|||
// wal
|
||||
int64_t tsWalFsyncDataSizeLimit = (100 * 1024 * 1024L);
|
||||
|
||||
// ttl
|
||||
bool tsTtlChangeOnWrite = false; // if true, ttl delete time changes on last write
|
||||
int32_t tsTtlFlushThreshold = 100; /* maximum number of dirty items in memory.
|
||||
* if -1, flush will not be triggered by write-ops
|
||||
*/
|
||||
int32_t tsTtlBatchDropNum = 10000; // number of tables dropped per batch
|
||||
|
||||
// internal
|
||||
int32_t tsTransPullupInterval = 2;
|
||||
int32_t tsMqRebalanceInterval = 2;
|
||||
int32_t tsStreamCheckpointTickInterval = 20;
|
||||
int32_t tsStreamNodeCheckInterval = 10;
|
||||
int32_t tsTtlUnit = 86400;
|
||||
int32_t tsTtlPushInterval = 3600;
|
||||
int32_t tsTtlPushIntervalSec = 10;
|
||||
int32_t tsTrimVDbIntervalSec = 60 * 60; // interval of trimming db in all vgroups
|
||||
int32_t tsGrantHBInterval = 60;
|
||||
int32_t tsUptimeInterval = 300; // seconds
|
||||
char tsUdfdResFuncs[512] = ""; // udfd resident funcs that teardown when udfd exits
|
||||
|
@ -239,8 +247,8 @@ char tsUdfdLdLibPath[512] = "";
|
|||
bool tsDisableStream = false;
|
||||
int64_t tsStreamBufferSize = 128 * 1024 * 1024;
|
||||
bool tsFilterScalarMode = false;
|
||||
int32_t tsKeepTimeOffset = 0; // latency of data migration
|
||||
int tsResolveFQDNRetryTime = 100; //seconds
|
||||
int32_t tsKeepTimeOffset = 0; // latency of data migration
|
||||
int tsResolveFQDNRetryTime = 100; // seconds
|
||||
|
||||
char tsS3Endpoint[TSDB_FQDN_LEN] = "<endpoint>";
|
||||
char tsS3AccessKey[TSDB_FQDN_LEN] = "<accesskey>";
|
||||
|
@ -307,9 +315,7 @@ int32_t taosSetS3Cfg(SConfig *pCfg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
struct SConfig *taosGetCfg() {
|
||||
return tsCfg;
|
||||
}
|
||||
struct SConfig *taosGetCfg() { return tsCfg; }
|
||||
|
||||
static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *inputCfgDir, const char *envFile,
|
||||
char *apolloUrl) {
|
||||
|
@ -607,8 +613,11 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
|
|||
if (cfgAddInt32(pCfg, "transPullupInterval", tsTransPullupInterval, 1, 10000, CFG_SCOPE_SERVER) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "mqRebalanceInterval", tsMqRebalanceInterval, 1, 10000, CFG_SCOPE_SERVER) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "ttlUnit", tsTtlUnit, 1, 86400 * 365, CFG_SCOPE_SERVER) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "ttlPushInterval", tsTtlPushInterval, 1, 100000, CFG_SCOPE_SERVER) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "ttlPushInterval", tsTtlPushIntervalSec, 1, 100000, CFG_SCOPE_SERVER) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "ttlBatchDropNum", tsTtlBatchDropNum, 0, INT32_MAX, CFG_SCOPE_SERVER) != 0) return -1;
|
||||
if (cfgAddBool(pCfg, "ttlChangeOnWrite", tsTtlChangeOnWrite, CFG_SCOPE_SERVER) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "ttlFlushThreshold", tsTtlFlushThreshold, -1, 1000000, CFG_SCOPE_SERVER) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "trimVDbIntervalSec", tsTrimVDbIntervalSec, 1, 100000, CFG_SCOPE_SERVER) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "uptimeInterval", tsUptimeInterval, 1, 100000, CFG_SCOPE_SERVER) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "queryRsmaTolerance", tsQueryRsmaTolerance, 0, 900000, CFG_SCOPE_SERVER) != 0) return -1;
|
||||
|
||||
|
@ -637,6 +646,11 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
|
|||
if (cfgAddString(pCfg, "s3Endpoint", tsS3Endpoint, CFG_SCOPE_SERVER) != 0) return -1;
|
||||
if (cfgAddString(pCfg, "s3BucketName", tsS3BucketName, CFG_SCOPE_SERVER) != 0) return -1;
|
||||
|
||||
// min free disk space used to check if the disk is full [50MB, 1GB]
|
||||
if (cfgAddInt64(pCfg, "minDiskFreeSize", tsMinDiskFreeSize, TFS_MIN_DISK_FREE_SIZE, 1024 * 1024 * 1024,
|
||||
CFG_SCOPE_SERVER) != 0)
|
||||
return -1;
|
||||
|
||||
GRANT_CFG_ADD;
|
||||
return 0;
|
||||
}
|
||||
|
@ -992,6 +1006,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
|
|||
tsEnableTelem = cfgGetItem(pCfg, "telemetryReporting")->bval;
|
||||
tsEnableCrashReport = cfgGetItem(pCfg, "crashReporting")->bval;
|
||||
tsTtlChangeOnWrite = cfgGetItem(pCfg, "ttlChangeOnWrite")->bval;
|
||||
tsTtlFlushThreshold = cfgGetItem(pCfg, "ttlFlushThreshold")->i32;
|
||||
tsTelemInterval = cfgGetItem(pCfg, "telemetryInterval")->i32;
|
||||
tstrncpy(tsTelemServer, cfgGetItem(pCfg, "telemetryServer")->str, TSDB_FQDN_LEN);
|
||||
tsTelemPort = (uint16_t)cfgGetItem(pCfg, "telemetryPort")->i32;
|
||||
|
@ -1001,7 +1016,9 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
|
|||
tsTransPullupInterval = cfgGetItem(pCfg, "transPullupInterval")->i32;
|
||||
tsMqRebalanceInterval = cfgGetItem(pCfg, "mqRebalanceInterval")->i32;
|
||||
tsTtlUnit = cfgGetItem(pCfg, "ttlUnit")->i32;
|
||||
tsTtlPushInterval = cfgGetItem(pCfg, "ttlPushInterval")->i32;
|
||||
tsTtlPushIntervalSec = cfgGetItem(pCfg, "ttlPushInterval")->i32;
|
||||
tsTtlBatchDropNum = cfgGetItem(pCfg, "ttlBatchDropNum")->i32;
|
||||
tsTrimVDbIntervalSec = cfgGetItem(pCfg, "trimVDbIntervalSec")->i32;
|
||||
tsUptimeInterval = cfgGetItem(pCfg, "uptimeInterval")->i32;
|
||||
tsQueryRsmaTolerance = cfgGetItem(pCfg, "queryRsmaTolerance")->i32;
|
||||
|
||||
|
@ -1035,6 +1052,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
|
|||
tsMaxStreamBackendCache = cfgGetItem(pCfg, "maxStreamBackendCache")->i32;
|
||||
tsPQSortMemThreshold = cfgGetItem(pCfg, "pqSortMemThreshold")->i32;
|
||||
tsResolveFQDNRetryTime = cfgGetItem(pCfg, "resolveFQDNRetryTime")->i32;
|
||||
tsMinDiskFreeSize = cfgGetItem(pCfg, "minDiskFreeSize")->i64;
|
||||
|
||||
GRANT_CFG_GET;
|
||||
return 0;
|
||||
|
@ -1401,13 +1419,19 @@ int32_t taosApplyLocalCfg(SConfig *pCfg, char *name) {
|
|||
} else if (strcasecmp("ttlUnit", name) == 0) {
|
||||
tsTtlUnit = cfgGetItem(pCfg, "ttlUnit")->i32;
|
||||
} else if (strcasecmp("ttlPushInterval", name) == 0) {
|
||||
tsTtlPushInterval = cfgGetItem(pCfg, "ttlPushInterval")->i32;
|
||||
tsTtlPushIntervalSec = cfgGetItem(pCfg, "ttlPushInterval")->i32;
|
||||
} else if (strcasecmp("ttlBatchDropNum", name) == 0) {
|
||||
tsTtlBatchDropNum = cfgGetItem(pCfg, "ttlBatchDropNum")->i32;
|
||||
} else if (strcasecmp("trimVDbIntervalSec", name) == 0) {
|
||||
tsTrimVDbIntervalSec = cfgGetItem(pCfg, "trimVDbIntervalSec")->i32;
|
||||
} else if (strcasecmp("tmrDebugFlag", name) == 0) {
|
||||
tmrDebugFlag = cfgGetItem(pCfg, "tmrDebugFlag")->i32;
|
||||
} else if (strcasecmp("tsdbDebugFlag", name) == 0) {
|
||||
tsdbDebugFlag = cfgGetItem(pCfg, "tsdbDebugFlag")->i32;
|
||||
} else if (strcasecmp("tqDebugFlag", name) == 0) {
|
||||
tqDebugFlag = cfgGetItem(pCfg, "tqDebugFlag")->i32;
|
||||
} else if (strcasecmp("ttlFlushThreshold", name) == 0) {
|
||||
tsTtlFlushThreshold = cfgGetItem(pCfg, "ttlFlushThreshold")->i32;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1609,6 +1633,20 @@ void taosCfgDynamicOptions(const char *option, const char *value) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (strcasecmp(option, "ttlPushInterval") == 0) {
|
||||
int32_t newTtlPushInterval = atoi(value);
|
||||
uInfo("ttlPushInterval set from %d to %d", tsTtlPushIntervalSec, newTtlPushInterval);
|
||||
tsTtlPushIntervalSec = newTtlPushInterval;
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcasecmp(option, "ttlBatchDropNum") == 0) {
|
||||
int32_t newTtlBatchDropNum = atoi(value);
|
||||
uInfo("ttlBatchDropNum set from %d to %d", tsTtlBatchDropNum, newTtlBatchDropNum);
|
||||
tsTtlBatchDropNum = newTtlBatchDropNum;
|
||||
return;
|
||||
}
|
||||
|
||||
const char *options[] = {
|
||||
"dDebugFlag", "vDebugFlag", "mDebugFlag", "wDebugFlag", "sDebugFlag", "tsdbDebugFlag", "tqDebugFlag",
|
||||
"fsDebugFlag", "udfDebugFlag", "smaDebugFlag", "idxDebugFlag", "tdbDebugFlag", "tmrDebugFlag", "uDebugFlag",
|
||||
|
|
|
@ -534,7 +534,6 @@ int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq
|
|||
if (tEncodeI8(&encoder, pField->flags) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pField->bytes) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pField->name) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pField->comment) < 0) return -1;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pReq->numOfTags; ++i) {
|
||||
|
@ -543,7 +542,6 @@ int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq
|
|||
if (tEncodeI8(&encoder, pField->flags) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pField->bytes) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pField->name) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pField->comment) < 0) return -1;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pReq->numOfFuncs; ++i) {
|
||||
|
@ -610,7 +608,6 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR
|
|||
if (tDecodeI8(&decoder, &field.flags) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &field.bytes) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, field.name) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, field.comment) < 0) return -1;
|
||||
if (taosArrayPush(pReq->pColumns, &field) == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
|
@ -623,7 +620,6 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR
|
|||
if (tDecodeI8(&decoder, &field.flags) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &field.bytes) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, field.name) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, field.comment) < 0) return -1;
|
||||
if (taosArrayPush(pReq->pTags, &field) == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
|
@ -1082,7 +1078,7 @@ int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) {
|
|||
if (tEncodeI64(&encoder, pload->compStorage) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pload->pointsWritten) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pload->numOfCachedTables) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, reserved) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pload->learnerProgress) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pload->roleTimeMs) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pload->startTimeMs) < 0) return -1;
|
||||
}
|
||||
|
@ -1163,7 +1159,7 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) {
|
|||
for (int32_t i = 0; i < vlen; ++i) {
|
||||
SVnodeLoad vload = {0};
|
||||
vload.syncTerm = -1;
|
||||
int32_t reserved32 = 0;
|
||||
|
||||
if (tDecodeI32(&decoder, &vload.vgId) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &vload.syncState) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &vload.syncRestore) < 0) return -1;
|
||||
|
@ -1175,7 +1171,7 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) {
|
|||
if (tDecodeI64(&decoder, &vload.compStorage) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &vload.pointsWritten) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &vload.numOfCachedTables) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, (int32_t *)&reserved32) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &vload.learnerProgress) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &vload.roleTimeMs) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &vload.startTimeMs) < 0) return -1;
|
||||
if (taosArrayPush(pReq->pVloads, &vload) == NULL) {
|
||||
|
@ -2327,7 +2323,7 @@ int32_t tDeserializeSTableCfgRsp(void *buf, int32_t bufLen, STableCfgRsp *pRsp)
|
|||
}
|
||||
|
||||
int32_t totalCols = pRsp->numOfTags + pRsp->numOfColumns;
|
||||
pRsp->pSchemas = taosMemoryCalloc(totalCols, sizeof(SSchema));
|
||||
pRsp->pSchemas = taosMemoryMalloc(sizeof(SSchema) * totalCols);
|
||||
if (pRsp->pSchemas == NULL) return -1;
|
||||
|
||||
for (int32_t i = 0; i < totalCols; ++i) {
|
||||
|
@ -3179,6 +3175,12 @@ int32_t tSerializeSVDropTtlTableReq(void *buf, int32_t bufLen, SVDropTtlTableReq
|
|||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->timestampSec) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->ttlDropMaxCount) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->nUids) < 0) return -1;
|
||||
for (int32_t i = 0; i < pReq->nUids; ++i) {
|
||||
tb_uid_t *pTbUid = taosArrayGet(pReq->pTbUids, i);
|
||||
if (tEncodeI64(&encoder, *pTbUid) < 0) return -1;
|
||||
}
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
|
@ -3192,6 +3194,30 @@ int32_t tDeserializeSVDropTtlTableReq(void *buf, int32_t bufLen, SVDropTtlTableR
|
|||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->timestampSec) < 0) return -1;
|
||||
pReq->ttlDropMaxCount = INT32_MAX;
|
||||
pReq->nUids = 0;
|
||||
pReq->pTbUids = NULL;
|
||||
if (!tDecodeIsEnd(&decoder)) {
|
||||
if (tDecodeI32(&decoder, &pReq->ttlDropMaxCount) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->nUids) < 0) return -1;
|
||||
|
||||
if (pReq->nUids > 0) {
|
||||
pReq->pTbUids = taosArrayInit(pReq->nUids, sizeof(tb_uid_t));
|
||||
if (pReq->pTbUids == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
tb_uid_t tbUid = 0;
|
||||
for (int32_t i = 0; i < pReq->nUids; ++i) {
|
||||
if (tDecodeI64(&decoder, &tbUid) < 0) return -1;
|
||||
if (taosArrayPush(pReq->pTbUids, &tbUid) == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
|
@ -3710,7 +3736,7 @@ static int32_t tDecodeSTableMetaRsp(SDecoder *pDecoder, STableMetaRsp *pRsp) {
|
|||
|
||||
int32_t totalCols = pRsp->numOfTags + pRsp->numOfColumns;
|
||||
if (totalCols > 0) {
|
||||
pRsp->pSchemas = taosMemoryCalloc(totalCols, sizeof(SSchema));
|
||||
pRsp->pSchemas = taosMemoryMalloc(sizeof(SSchema) * totalCols);
|
||||
if (pRsp->pSchemas == NULL) return -1;
|
||||
|
||||
for (int32_t i = 0; i < totalCols; ++i) {
|
||||
|
@ -4348,6 +4374,7 @@ int32_t tSerializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq *pR
|
|||
SReplica *pReplica = &pReq->learnerReplicas[i];
|
||||
if (tEncodeSReplica(&encoder, pReplica) < 0) return -1;
|
||||
}
|
||||
if (tEncodeI32(&encoder, pReq->changeVersion) < 0) return -1;
|
||||
|
||||
tEndEncode(&encoder);
|
||||
|
||||
|
@ -4434,6 +4461,9 @@ int32_t tDeserializeSCreateVnodeReq(void *buf, int32_t bufLen, SCreateVnodeReq *
|
|||
if (tDecodeSReplica(&decoder, pReplica) < 0) return -1;
|
||||
}
|
||||
}
|
||||
if (!tDecodeIsEnd(&decoder)) {
|
||||
if (tDecodeI32(&decoder, &pReq->changeVersion) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndDecode(&decoder);
|
||||
tDecoderClear(&decoder);
|
||||
|
@ -4666,6 +4696,7 @@ int32_t tSerializeSAlterVnodeReplicaReq(void *buf, int32_t bufLen, SAlterVnodeRe
|
|||
SReplica *pReplica = &pReq->learnerReplicas[i];
|
||||
if (tEncodeSReplica(&encoder, pReplica) < 0) return -1;
|
||||
}
|
||||
if (tEncodeI32(&encoder, pReq->changeVersion) < 0) return -1;
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
|
@ -4697,6 +4728,9 @@ int32_t tDeserializeSAlterVnodeReplicaReq(void *buf, int32_t bufLen, SAlterVnode
|
|||
if (tDecodeSReplica(&decoder, pReplica) < 0) return -1;
|
||||
}
|
||||
}
|
||||
if (!tDecodeIsEnd(&decoder)){
|
||||
if (tDecodeI32(&decoder, &pReq->changeVersion) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndDecode(&decoder);
|
||||
tDecoderClear(&decoder);
|
||||
|
@ -4740,7 +4774,8 @@ int32_t tSerializeSAlterVnodeHashRangeReq(void *buf, int32_t bufLen, SAlterVnode
|
|||
if (tEncodeI32(&encoder, pReq->dstVgId) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->hashBegin) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->hashEnd) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pReq->reserved) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->changeVersion) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->reserved) < 0) return -1;
|
||||
|
||||
tEndEncode(&encoder);
|
||||
|
||||
|
@ -4758,7 +4793,8 @@ int32_t tDeserializeSAlterVnodeHashRangeReq(void *buf, int32_t bufLen, SAlterVno
|
|||
if (tDecodeI32(&decoder, &pReq->dstVgId) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->hashBegin) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->hashEnd) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pReq->reserved) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->changeVersion) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->reserved) < 0) return -1;
|
||||
|
||||
tEndDecode(&decoder);
|
||||
tDecoderClear(&decoder);
|
||||
|
|
|
@ -108,6 +108,8 @@ SArray *mmGetMsgHandles() {
|
|||
if (dmSetMgmtHandle(pArray, TDMT_DND_CONFIG_DNODE_RSP, mmPutMsgToReadQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_DND_ALTER_MNODE_TYPE_RSP, mmPutMsgToReadQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_DND_ALTER_VNODE_TYPE_RSP, mmPutMsgToReadQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP_RSP, mmPutMsgToReadQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_CONFIG_CHANGE_RSP, mmPutMsgToReadQueue, 0) == NULL) goto _OVER;
|
||||
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_CONNECT, mmPutMsgToReadQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_ACCT, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
|
@ -191,6 +193,7 @@ SArray *mmGetMsgHandles() {
|
|||
if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_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_DROP_TTL_TABLE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_TRIM_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_TMQ_SUBSCRIBE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
|
|
|
@ -97,6 +97,7 @@ int32_t vmProcessAlterVnodeReplicaReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
|||
int32_t vmProcessDisableVnodeWriteReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||
int32_t vmProcessAlterHashRangeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||
int32_t vmProcessAlterVnodeTypeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||
int32_t vmProcessCheckLearnCatchupReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||
|
||||
// vmFile.c
|
||||
int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *numOfVnodes);
|
||||
|
|
|
@ -133,6 +133,7 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) {
|
|||
pCfg->standby = 0;
|
||||
pCfg->syncCfg.replicaNum = 0;
|
||||
pCfg->syncCfg.totalReplicaNum = 0;
|
||||
pCfg->syncCfg.changeVersion = pCreate->changeVersion;
|
||||
|
||||
memset(&pCfg->syncCfg.nodeInfo, 0, sizeof(pCfg->syncCfg.nodeInfo));
|
||||
for (int32_t i = 0; i < pCreate->replica; ++i) {
|
||||
|
@ -211,14 +212,15 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
", days:%d keep0:%d keep1:%d keep2:%d tsma:%d precision:%d compression:%d minRows:%d maxRows:%d"
|
||||
", wal fsync:%d level:%d retentionPeriod:%d retentionSize:%" PRId64 " rollPeriod:%d segSize:%" PRId64
|
||||
", hash method:%d begin:%u end:%u prefix:%d surfix:%d replica:%d selfIndex:%d "
|
||||
"learnerReplica:%d learnerSelfIndex:%d strict:%d",
|
||||
"learnerReplica:%d learnerSelfIndex:%d strict:%d changeVersion:%d",
|
||||
req.vgId, TMSG_INFO(pMsg->msgType), req.pages, req.pageSize, req.buffer, req.pageSize * 1024,
|
||||
(uint64_t)req.buffer * 1024 * 1024, req.cacheLast, req.cacheLastSize, req.sstTrigger, req.tsdbPageSize,
|
||||
req.tsdbPageSize * 1024, req.db, req.dbUid, req.daysPerFile, req.daysToKeep0, req.daysToKeep1, req.daysToKeep2,
|
||||
req.isTsma, req.precision, req.compression, req.minRows, req.maxRows, req.walFsyncPeriod, req.walLevel,
|
||||
req.walRetentionPeriod, req.walRetentionSize, req.walRollPeriod, req.walSegmentSize, req.hashMethod,
|
||||
req.hashBegin, req.hashEnd, req.hashPrefix, req.hashSuffix, req.replica, req.selfIndex, req.learnerReplica,
|
||||
req.learnerSelfIndex, req.strict);
|
||||
req.learnerSelfIndex, req.strict, req.changeVersion);
|
||||
|
||||
for (int32_t i = 0; i < req.replica; ++i) {
|
||||
dInfo("vgId:%d, replica:%d ep:%s:%u dnode:%d", req.vgId, i, req.replicas[i].fqdn, req.replicas[i].port,
|
||||
req.replicas[i].id);
|
||||
|
@ -323,6 +325,7 @@ _OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
//alter replica doesn't use this, but restore dnode still use this
|
||||
int32_t vmProcessAlterVnodeTypeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
SAlterVnodeTypeReq req = {0};
|
||||
if (tDeserializeSAlterVnodeReplicaReq(pMsg->pCont, pMsg->contLen, &req) != 0) {
|
||||
|
@ -363,8 +366,8 @@ int32_t vmProcessAlterVnodeTypeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
dInfo("node:%s, catched up leader, continue to process alter-node-type-request", pMgmt->name);
|
||||
|
||||
int32_t vgId = req.vgId;
|
||||
dInfo("vgId:%d, start to alter vnode type replica:%d selfIndex:%d strict:%d", vgId, req.replica, req.selfIndex,
|
||||
req.strict);
|
||||
dInfo("vgId:%d, start to alter vnode type replica:%d selfIndex:%d strict:%d changeVersion:%d",
|
||||
vgId, req.replica, req.selfIndex, req.strict, req.changeVersion);
|
||||
for (int32_t i = 0; i < req.replica; ++i) {
|
||||
SReplica *pReplica = &req.replicas[i];
|
||||
dInfo("vgId:%d, replica:%d ep:%s:%u dnode:%d", vgId, i, pReplica->fqdn, pReplica->port, pReplica->id);
|
||||
|
@ -424,7 +427,7 @@ int32_t vmProcessAlterVnodeTypeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
dError("vgId:%d, failed to open vnode at %s since %s", vgId, path, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (vmOpenVnode(pMgmt, &wrapperCfg, pImpl) != 0) {
|
||||
dError("vgId:%d, failed to open vnode mgmt since %s", vgId, terrstr());
|
||||
return -1;
|
||||
|
@ -440,6 +443,53 @@ int32_t vmProcessAlterVnodeTypeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t vmProcessCheckLearnCatchupReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
SCheckLearnCatchupReq req = {0};
|
||||
if (tDeserializeSAlterVnodeReplicaReq(pMsg->pCont, pMsg->contLen, &req) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(req.learnerReplicas == 0){
|
||||
req.learnerSelfIndex = -1;
|
||||
}
|
||||
|
||||
dInfo("vgId:%d, vnode management handle msgType:%s, start to process check-learner-catchup-request",
|
||||
req.vgId, TMSG_INFO(pMsg->msgType));
|
||||
|
||||
SVnodeObj *pVnode = vmAcquireVnode(pMgmt, req.vgId);
|
||||
if (pVnode == NULL) {
|
||||
dError("vgId:%d, failed to alter vnode type since %s", req.vgId, terrstr());
|
||||
terrno = TSDB_CODE_VND_NOT_EXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ESyncRole role = vnodeGetRole(pVnode->pImpl);
|
||||
dInfo("vgId:%d, checking node role:%d", req.vgId, role);
|
||||
if(role == TAOS_SYNC_ROLE_VOTER){
|
||||
dError("vgId:%d, failed to alter vnode type since node already is role:%d", req.vgId, role);
|
||||
terrno = TSDB_CODE_VND_ALREADY_IS_VOTER;
|
||||
vmReleaseVnode(pMgmt, pVnode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("vgId:%d, checking node catch up", req.vgId);
|
||||
if(vnodeIsCatchUp(pVnode->pImpl) != 1){
|
||||
terrno = TSDB_CODE_VND_NOT_CATCH_UP;
|
||||
vmReleaseVnode(pMgmt, pVnode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("node:%s, catched up leader, continue to process alter-node-type-request", pMgmt->name);
|
||||
|
||||
vmReleaseVnode(pMgmt, pVnode);
|
||||
|
||||
dInfo("vgId:%d, vnode management handle msgType:%s, end to process check-learner-catchup-request",
|
||||
req.vgId, TMSG_INFO(pMsg->msgType));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t vmProcessDisableVnodeWriteReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
SDisableVnodeWriteReq req = {0};
|
||||
if (tDeserializeSDisableVnodeWriteReq(pMsg->pCont, pMsg->contLen, &req) != 0) {
|
||||
|
@ -520,6 +570,7 @@ int32_t vmProcessAlterHashRangeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
|
||||
dInfo("vgId:%d, open vnode", dstVgId);
|
||||
SVnode *pImpl = vnodeOpen(dstPath, diskPrimary, pMgmt->pTfs, pMgmt->msgCb);
|
||||
|
||||
if (pImpl == NULL) {
|
||||
dError("vgId:%d, failed to open vnode at %s since %s", dstVgId, dstPath, terrstr());
|
||||
return -1;
|
||||
|
@ -559,9 +610,10 @@ int32_t vmProcessAlterVnodeReplicaReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
int32_t vgId = alterReq.vgId;
|
||||
dInfo(
|
||||
"vgId:%d,vnode management handle msgType:%s, start to alter vnode replica:%d selfIndex:%d leanerReplica:%d "
|
||||
"learnerSelfIndex:%d strict:%d",
|
||||
"learnerSelfIndex:%d strict:%d changeVersion:%d",
|
||||
vgId, TMSG_INFO(pMsg->msgType), alterReq.replica, alterReq.selfIndex, alterReq.learnerReplica,
|
||||
alterReq.learnerSelfIndex, alterReq.strict);
|
||||
alterReq.learnerSelfIndex, alterReq.strict, alterReq.changeVersion);
|
||||
|
||||
for (int32_t i = 0; i < alterReq.replica; ++i) {
|
||||
SReplica *pReplica = &alterReq.replicas[i];
|
||||
dInfo("vgId:%d, replica:%d ep:%s:%u dnode:%d", vgId, i, pReplica->fqdn, pReplica->port, pReplica->port);
|
||||
|
@ -759,6 +811,8 @@ SArray *vmGetMsgHandles() {
|
|||
if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_VNODE, vmPutMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_VNODE, vmPutMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_DND_ALTER_VNODE_TYPE, vmPutMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP, vmPutMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_CONFIG_CHANGE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_TIMEOUT_ELECTION, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_CLIENT_REQUEST, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
||||
|
|
|
@ -267,6 +267,7 @@ static void *vmOpenVnodeInThread(void *param) {
|
|||
snprintf(path, TSDB_FILENAME_LEN, "vnode%svnode%d", TD_DIRSEP, pCfg->vgId);
|
||||
|
||||
SVnode *pImpl = vnodeOpen(path, diskPrimary, pMgmt->pTfs, pMgmt->msgCb);
|
||||
|
||||
if (pImpl == NULL) {
|
||||
dError("vgId:%d, failed to open vnode by thread:%d since %s", pCfg->vgId, pThread->threadIndex, terrstr());
|
||||
pThread->failed++;
|
||||
|
|
|
@ -53,6 +53,9 @@ static void vmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
|||
case TDMT_DND_ALTER_VNODE_TYPE:
|
||||
code = vmProcessAlterVnodeTypeReq(pMgmt, pMsg);
|
||||
break;
|
||||
case TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP:
|
||||
code = vmProcessCheckLearnCatchupReq(pMgmt, pMsg);
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
dGError("msg:%p, not processed in vnode-mgmt queue", pMsg);
|
||||
|
|
|
@ -353,6 +353,7 @@ typedef struct {
|
|||
int64_t roleTimeMs;
|
||||
int64_t startTimeMs;
|
||||
ESyncRole nodeRole;
|
||||
int32_t learnerProgress;
|
||||
} SVnodeGid;
|
||||
|
||||
typedef struct {
|
||||
|
@ -376,6 +377,7 @@ typedef struct {
|
|||
SVnodeGid vnodeGid[TSDB_MAX_REPLICA + TSDB_MAX_LEARNER_REPLICA];
|
||||
void* pTsma;
|
||||
int32_t numOfCachedTables;
|
||||
int32_t syncConfChangeVer;
|
||||
} SVgObj;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -47,6 +47,8 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
|
|||
SArray *pArray);
|
||||
int32_t mndBuildCompactVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, int64_t compactTs,
|
||||
STimeWindow tw);
|
||||
int32_t mndBuildRaftAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb, SVgObj *pVgroup,
|
||||
SArray *pArray);
|
||||
|
||||
void *mndBuildCreateVnodeReq(SMnode *, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen);
|
||||
void *mndBuildDropVnodeReq(SMnode *, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen);
|
||||
|
|
|
@ -659,10 +659,10 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate,
|
|||
|
||||
mndTransSetOper(pTrans, MND_OPER_CREATE_DB);
|
||||
if (mndSetCreateDbPrepareAction(pMnode, pTrans, &dbObj) != 0) goto _OVER;
|
||||
if (mndSetCreateDbRedoActions(pMnode, pTrans, &dbObj, pVgroups) != 0) goto _OVER;
|
||||
if (mndSetNewVgPrepareActions(pMnode, pTrans, &dbObj, pVgroups) != 0) goto _OVER;
|
||||
if (mndSetCreateDbUndoLogs(pMnode, pTrans, &dbObj, pVgroups) != 0) goto _OVER;
|
||||
if (mndSetCreateDbCommitLogs(pMnode, pTrans, &dbObj, pVgroups, pNewUserDuped) != 0) goto _OVER;
|
||||
if (mndSetCreateDbRedoActions(pMnode, pTrans, &dbObj, pVgroups) != 0) goto _OVER;
|
||||
if (mndSetCreateDbUndoActions(pMnode, pTrans, &dbObj, pVgroups) != 0) goto _OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
|
@ -882,7 +882,7 @@ static int32_t mndSetAlterDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *
|
|||
if (pIter == NULL) break;
|
||||
|
||||
if (mndVgroupInDb(pVgroup, pNewDb->uid)) {
|
||||
if (mndBuildAlterVgroupAction(pMnode, pTrans, pOldDb, pNewDb, pVgroup, pArray) != 0) {
|
||||
if (mndBuildRaftAlterVgroupAction(pMnode, pTrans, pOldDb, pNewDb, pVgroup, pArray) != 0) {
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
taosArrayDestroy(pArray);
|
||||
|
|
|
@ -1123,6 +1123,36 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) {
|
|||
|
||||
strcpy(dcfgReq.config, "keeptimeoffset");
|
||||
snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%d", flag);
|
||||
} else if (strncasecmp(cfgReq.config, "ttlpushinterval", 14) == 0) {
|
||||
int32_t optLen = strlen("ttlpushinterval");
|
||||
int32_t flag = -1;
|
||||
int32_t code = mndMCfgGetValInt32(&cfgReq, optLen, &flag);
|
||||
if (code < 0) return code;
|
||||
|
||||
if (flag < 0 || flag > 100000) {
|
||||
mError("dnode:%d, failed to config ttlPushInterval since value:%d. Valid range: [0, 100000]", cfgReq.dnodeId,
|
||||
flag);
|
||||
terrno = TSDB_CODE_INVALID_CFG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
strcpy(dcfgReq.config, "ttlpushinterval");
|
||||
snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%d", flag);
|
||||
} else if (strncasecmp(cfgReq.config, "ttlbatchdropnum", 15) == 0) {
|
||||
int32_t optLen = strlen("ttlbatchdropnum");
|
||||
int32_t flag = -1;
|
||||
int32_t code = mndMCfgGetValInt32(&cfgReq, optLen, &flag);
|
||||
if (code < 0) return code;
|
||||
|
||||
if (flag < 0) {
|
||||
mError("dnode:%d, failed to config ttlBatchDropNum since value:%d. Valid range: [0, %d]", cfgReq.dnodeId,
|
||||
flag, INT32_MAX);
|
||||
terrno = TSDB_CODE_INVALID_CFG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
strcpy(dcfgReq.config, "ttlbatchdropnum");
|
||||
snprintf(dcfgReq.value, TSDB_DNODE_VALUE_LEN, "%d", flag);
|
||||
#ifdef TD_ENTERPRISE
|
||||
} else if (strncasecmp(cfgReq.config, "activeCode", 10) == 0 || strncasecmp(cfgReq.config, "cActiveCode", 11) == 0) {
|
||||
int8_t opt = strncasecmp(cfgReq.config, "a", 1) == 0 ? DND_ACTIVE_CODE : DND_CONN_ACTIVE_CODE;
|
||||
|
@ -1376,7 +1406,7 @@ static int32_t mndMCfgGetValInt32(SMCfgDnodeReq *pMCfgReq, int32_t opLen, int32_
|
|||
return 0;
|
||||
|
||||
_err:
|
||||
mError("dnode:%d, failed to config keeptimeoffset since invalid conf:%s", pMCfgReq->dnodeId, pMCfgReq->config);
|
||||
mError("dnode:%d, failed to config since invalid conf:%s", pMCfgReq->dnodeId, pMCfgReq->config);
|
||||
terrno = TSDB_CODE_INVALID_CFG;
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -119,6 +119,14 @@ static void mndPullupTtl(SMnode *pMnode) {
|
|||
tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg);
|
||||
}
|
||||
|
||||
static void mndPullupTrimDb(SMnode *pMnode) {
|
||||
mTrace("pullup trim");
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildTimerMsg(&contLen);
|
||||
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TRIM_DB_TIMER, .pCont = pReq, .contLen = contLen};
|
||||
tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg);
|
||||
}
|
||||
|
||||
static void mndCalMqRebalance(SMnode *pMnode) {
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildTimerMsg(&contLen);
|
||||
|
@ -257,10 +265,14 @@ static void *mndThreadFp(void *param) {
|
|||
if (lastTime % 10 != 0) continue;
|
||||
|
||||
int64_t sec = lastTime / 10;
|
||||
if (sec % tsTtlPushInterval == 0) {
|
||||
if (sec % tsTtlPushIntervalSec == 0) {
|
||||
mndPullupTtl(pMnode);
|
||||
}
|
||||
|
||||
if (sec % tsTrimVDbIntervalSec == 0) {
|
||||
mndPullupTrimDb(pMnode);
|
||||
}
|
||||
|
||||
if (sec % tsTransPullupInterval == 0) {
|
||||
mndPullupTrans(pMnode);
|
||||
}
|
||||
|
@ -665,7 +677,7 @@ static int32_t mndCheckMnodeState(SRpcMsg *pMsg) {
|
|||
_OVER:
|
||||
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_UPTIME_TIMER) {
|
||||
pMsg->msgType == TDMT_MND_TRIM_DB_TIMER || pMsg->msgType == TDMT_MND_UPTIME_TIMER) {
|
||||
mTrace("timer not process since mnode restored:%d stopped:%d, sync restored:%d role:%s ", pMnode->restored,
|
||||
pMnode->stopped, state.restored, syncStr(state.state));
|
||||
return -1;
|
||||
|
|
|
@ -40,10 +40,12 @@ static int32_t mndStbActionInsert(SSdb *pSdb, SStbObj *pStb);
|
|||
static int32_t mndStbActionDelete(SSdb *pSdb, SStbObj *pStb);
|
||||
static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew);
|
||||
static int32_t mndProcessTtlTimer(SRpcMsg *pReq);
|
||||
static int32_t mndProcessTrimDbTimer(SRpcMsg *pReq);
|
||||
static int32_t mndProcessCreateStbReq(SRpcMsg *pReq);
|
||||
static int32_t mndProcessAlterStbReq(SRpcMsg *pReq);
|
||||
static int32_t mndProcessDropStbReq(SRpcMsg *pReq);
|
||||
static int32_t mndProcessDropTtltbReq(SRpcMsg *pReq);
|
||||
static int32_t mndProcessDropTtltbRsp(SRpcMsg *pReq);
|
||||
static int32_t mndProcessTrimDbRsp(SRpcMsg *pReq);
|
||||
static int32_t mndProcessTableMetaReq(SRpcMsg *pReq);
|
||||
static int32_t mndRetrieveStb(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
|
||||
static int32_t mndRetrieveStbCol(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
|
||||
|
@ -72,11 +74,13 @@ int32_t mndInitStb(SMnode *pMnode) {
|
|||
mndSetMsgHandle(pMnode, TDMT_MND_ALTER_STB, mndProcessAlterStbReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_DROP_STB, mndProcessDropStbReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_VND_CREATE_STB_RSP, mndTransProcessRsp);
|
||||
mndSetMsgHandle(pMnode, TDMT_VND_DROP_TTL_TABLE_RSP, mndProcessDropTtltbReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_VND_DROP_TTL_TABLE_RSP, mndProcessDropTtltbRsp);
|
||||
mndSetMsgHandle(pMnode, TDMT_VND_TRIM_RSP, mndProcessTrimDbRsp);
|
||||
mndSetMsgHandle(pMnode, TDMT_VND_ALTER_STB_RSP, mndTransProcessRsp);
|
||||
mndSetMsgHandle(pMnode, TDMT_VND_DROP_STB_RSP, mndTransProcessRsp);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_TABLE_META, mndProcessTableMetaReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_TTL_TIMER, mndProcessTtlTimer);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_TRIM_DB_TIMER, mndProcessTrimDbTimer);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_TABLE_CFG, mndProcessTableCfgReq);
|
||||
// mndSetMsgHandle(pMnode, TDMT_MND_SYSTABLE_RETRIEVE, mndProcessRetrieveStbReq);
|
||||
|
||||
|
@ -835,7 +839,6 @@ int32_t mndBuildStbFromReq(SMnode *pMnode, SStbObj *pDst, SMCreateStbReq *pCreat
|
|||
pSchema->bytes = pField->bytes;
|
||||
pSchema->flags = pField->flags;
|
||||
memcpy(pSchema->name, pField->name, TSDB_COL_NAME_LEN);
|
||||
memcpy(pSchema->comment, pField->comment, TSDB_COL_COMMENT_LEN);
|
||||
pSchema->colId = pDst->nextColId;
|
||||
pDst->nextColId++;
|
||||
}
|
||||
|
@ -849,7 +852,6 @@ int32_t mndBuildStbFromReq(SMnode *pMnode, SStbObj *pDst, SMCreateStbReq *pCreat
|
|||
SSCHMEA_SET_IDX_ON(pSchema);
|
||||
}
|
||||
memcpy(pSchema->name, pField->name, TSDB_COL_NAME_LEN);
|
||||
memcpy(pSchema->comment, pField->comment, TSDB_COL_COMMENT_LEN);
|
||||
pSchema->colId = pDst->nextColId;
|
||||
pDst->nextColId++;
|
||||
}
|
||||
|
@ -919,11 +921,12 @@ static int32_t mndProcessTtlTimer(SRpcMsg *pReq) {
|
|||
SSdb *pSdb = pMnode->pSdb;
|
||||
SVgObj *pVgroup = NULL;
|
||||
void *pIter = NULL;
|
||||
SVDropTtlTableReq ttlReq = {.timestampSec = taosGetTimestampSec()};
|
||||
int32_t reqLen = tSerializeSVDropTtlTableReq(NULL, 0, &ttlReq);
|
||||
int32_t contLen = reqLen + sizeof(SMsgHead);
|
||||
SVDropTtlTableReq ttlReq = {
|
||||
.timestampSec = taosGetTimestampSec(), .ttlDropMaxCount = tsTtlBatchDropNum, .nUids = 0, .pTbUids = NULL};
|
||||
int32_t reqLen = tSerializeSVDropTtlTableReq(NULL, 0, &ttlReq);
|
||||
int32_t contLen = reqLen + sizeof(SMsgHead);
|
||||
|
||||
mInfo("start to process ttl timer");
|
||||
mDebug("start to process ttl timer");
|
||||
|
||||
while (1) {
|
||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||
|
@ -936,7 +939,7 @@ static int32_t mndProcessTtlTimer(SRpcMsg *pReq) {
|
|||
}
|
||||
pHead->contLen = htonl(contLen);
|
||||
pHead->vgId = htonl(pVgroup->vgId);
|
||||
tSerializeSVDropTtlTableReq((char *)pHead + sizeof(SMsgHead), contLen, &ttlReq);
|
||||
tSerializeSVDropTtlTableReq((char *)pHead + sizeof(SMsgHead), reqLen, &ttlReq);
|
||||
|
||||
SRpcMsg rpcMsg = {.msgType = TDMT_VND_DROP_TTL_TABLE, .pCont = pHead, .contLen = contLen, .info = pReq->info};
|
||||
SEpSet epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
|
@ -944,7 +947,44 @@ static int32_t mndProcessTtlTimer(SRpcMsg *pReq) {
|
|||
if (code != 0) {
|
||||
mError("vgId:%d, failed to send drop ttl table request to vnode since 0x%x", pVgroup->vgId, code);
|
||||
} else {
|
||||
mInfo("vgId:%d, send drop ttl table request to vnode, time:%" PRId32, pVgroup->vgId, ttlReq.timestampSec);
|
||||
mDebug("vgId:%d, send drop ttl table request to vnode, time:%" PRId32, pVgroup->vgId, ttlReq.timestampSec);
|
||||
}
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessTrimDbTimer(SRpcMsg *pReq) {
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SVgObj *pVgroup = NULL;
|
||||
void *pIter = NULL;
|
||||
SVTrimDbReq trimReq = {.timestamp = taosGetTimestampSec()};
|
||||
int32_t reqLen = tSerializeSVTrimDbReq(NULL, 0, &trimReq);
|
||||
int32_t contLen = reqLen + sizeof(SMsgHead);
|
||||
|
||||
while (1) {
|
||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
SMsgHead *pHead = rpcMallocCont(contLen);
|
||||
if (pHead == NULL) {
|
||||
sdbCancelFetch(pSdb, pVgroup);
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
continue;
|
||||
}
|
||||
pHead->contLen = htonl(contLen);
|
||||
pHead->vgId = htonl(pVgroup->vgId);
|
||||
tSerializeSVTrimDbReq((char *)pHead + sizeof(SMsgHead), reqLen, &trimReq);
|
||||
|
||||
SRpcMsg rpcMsg = {.msgType = TDMT_VND_TRIM, .pCont = pHead, .contLen = contLen};
|
||||
SEpSet epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
int32_t code = tmsgSendReq(&epSet, &rpcMsg);
|
||||
if (code != 0) {
|
||||
mError("vgId:%d, timer failed to send vnode-trim request to vnode since 0x%x", pVgroup->vgId, code);
|
||||
} else {
|
||||
mInfo("vgId:%d, timer send vnode-trim request to vnode, time:%d", pVgroup->vgId, trimReq.timestamp);
|
||||
}
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
}
|
||||
|
@ -2405,7 +2445,8 @@ static int32_t mndCheckDropStbForStream(SMnode *pMnode, const char *stbFullName,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropTtltbReq(SRpcMsg *pRsp) { return 0; }
|
||||
static int32_t mndProcessDropTtltbRsp(SRpcMsg *pRsp) { return 0; }
|
||||
static int32_t mndProcessTrimDbRsp(SRpcMsg *pRsp) { return 0; }
|
||||
|
||||
static int32_t mndProcessDropStbReq(SRpcMsg *pReq) {
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
|
|
|
@ -475,7 +475,7 @@ int32_t mndInitSync(SMnode *pMnode) {
|
|||
}
|
||||
|
||||
tsem_init(&pMgmt->syncSem, 0, 0);
|
||||
pMgmt->sync = syncOpen(&syncInfo);
|
||||
pMgmt->sync = syncOpen(&syncInfo, true);
|
||||
if (pMgmt->sync <= 0) {
|
||||
mError("failed to open sync since %s", terrstr());
|
||||
return -1;
|
||||
|
|
|
@ -1123,7 +1123,7 @@ static int32_t mndTransSendSingleMsg(SMnode *pMnode, STrans *pTrans, STransActio
|
|||
int32_t code = tmsgSendReq(&pAction->epSet, &rpcMsg);
|
||||
if (code == 0) {
|
||||
pAction->msgSent = 1;
|
||||
pAction->msgReceived = 0;
|
||||
//pAction->msgReceived = 0;
|
||||
pAction->errCode = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||
mInfo("trans:%d, %s:%d is sent, %s", pTrans->id, mndTransStr(pAction->stage), pAction->id, detail);
|
||||
|
||||
|
|
|
@ -67,6 +67,8 @@ int32_t mndInitVgroup(SMnode *pMnode) {
|
|||
mndSetMsgHandle(pMnode, TDMT_VND_DISABLE_WRITE_RSP, mndTransProcessRsp);
|
||||
mndSetMsgHandle(pMnode, TDMT_SYNC_FORCE_FOLLOWER_RSP, mndTransProcessRsp);
|
||||
mndSetMsgHandle(pMnode, TDMT_DND_ALTER_VNODE_TYPE_RSP, mndTransProcessRsp);
|
||||
mndSetMsgHandle(pMnode, TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP_RSP, mndTransProcessRsp);
|
||||
mndSetMsgHandle(pMnode, TDMT_SYNC_CONFIG_CHANGE_RSP, mndTransProcessRsp);
|
||||
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_REDISTRIBUTE_VGROUP, mndProcessRedistributeVgroupMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_SPLIT_VGROUP, mndProcessSplitVgroupMsg);
|
||||
|
@ -105,6 +107,7 @@ SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup) {
|
|||
SVnodeGid *pVgid = &pVgroup->vnodeGid[i];
|
||||
SDB_SET_INT32(pRaw, dataPos, pVgid->dnodeId, _OVER)
|
||||
}
|
||||
SDB_SET_INT32(pRaw, dataPos, pVgroup->syncConfChangeVer, _OVER)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, VGROUP_RESERVE_SIZE, _OVER)
|
||||
SDB_SET_DATALEN(pRaw, dataPos, _OVER)
|
||||
|
||||
|
@ -129,7 +132,7 @@ SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) {
|
|||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
|
||||
|
||||
if (sver != VGROUP_VER_NUMBER) {
|
||||
if (sver < 1 || sver > VGROUP_VER_NUMBER) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -158,6 +161,10 @@ SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) {
|
|||
pVgid->syncState = TAOS_SYNC_STATE_LEADER;
|
||||
}
|
||||
}
|
||||
if(dataPos + sizeof(int32_t) + VGROUP_RESERVE_SIZE <= pRaw->dataLen){
|
||||
SDB_GET_INT32(pRaw, dataPos, &pVgroup->syncConfChangeVer, _OVER)
|
||||
}
|
||||
|
||||
SDB_GET_RESERVE(pRaw, dataPos, VGROUP_RESERVE_SIZE, _OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
@ -220,6 +227,7 @@ static int32_t mndVgroupActionUpdate(SSdb *pSdb, SVgObj *pOld, SVgObj *pNew) {
|
|||
pNew->pointsWritten = pOld->pointsWritten;
|
||||
pNew->compact = pOld->compact;
|
||||
memcpy(pOld->vnodeGid, pNew->vnodeGid, (TSDB_MAX_REPLICA + TSDB_MAX_LEARNER_REPLICA) * sizeof(SVnodeGid));
|
||||
pOld->syncConfChangeVer = pNew->syncConfChangeVer;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -279,6 +287,7 @@ void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVg
|
|||
createReq.hashPrefix = pDb->cfg.hashPrefix;
|
||||
createReq.hashSuffix = pDb->cfg.hashSuffix;
|
||||
createReq.tsdbPageSize = pDb->cfg.tsdbPageSize;
|
||||
createReq.changeVersion= ++(pVgroup->syncConfChangeVer);
|
||||
|
||||
for (int32_t v = 0; v < pVgroup->replica; ++v) {
|
||||
SReplica *pReplica = NULL;
|
||||
|
@ -325,9 +334,12 @@ void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVg
|
|||
return NULL;
|
||||
}
|
||||
|
||||
mInfo("vgId:%d, build create vnode req, replica:%d selfIndex:%d learnerReplica:%d learnerSelfIndex:%d strict:%d",
|
||||
createReq.changeVersion = pVgroup->syncConfChangeVer;
|
||||
|
||||
mInfo("vgId:%d, build create vnode req, replica:%d selfIndex:%d learnerReplica:%d learnerSelfIndex:%d strict:%d "
|
||||
"changeVersion:%d",
|
||||
createReq.vgId, createReq.replica, createReq.selfIndex, createReq.learnerReplica,
|
||||
createReq.learnerReplica, createReq.strict);
|
||||
createReq.learnerReplica, createReq.strict, createReq.changeVersion);
|
||||
for (int32_t i = 0; i < createReq.replica; ++i) {
|
||||
mInfo("vgId:%d, replica:%d ep:%s:%u", createReq.vgId, i, createReq.replicas[i].fqdn, createReq.replicas[i].port);
|
||||
}
|
||||
|
@ -405,6 +417,7 @@ static void *mndBuildAlterVnodeReplicaReq(SMnode *pMnode, SDbObj *pDb, SVgObj *p
|
|||
.learnerReplica = 0,
|
||||
.selfIndex = -1,
|
||||
.learnerSelfIndex = -1,
|
||||
.changeVersion = ++(pVgroup->syncConfChangeVer),
|
||||
};
|
||||
|
||||
for (int32_t v = 0; v < pVgroup->replica; ++v) {
|
||||
|
@ -440,9 +453,10 @@ static void *mndBuildAlterVnodeReplicaReq(SMnode *pMnode, SDbObj *pDb, SVgObj *p
|
|||
}
|
||||
}
|
||||
|
||||
mInfo("vgId:%d, build alter vnode req, replica:%d selfIndex:%d learnerReplica:%d learnerSelfIndex:%d strict:%d",
|
||||
mInfo("vgId:%d, build alter vnode req, replica:%d selfIndex:%d learnerReplica:%d learnerSelfIndex:%d strict:%d "
|
||||
"changeVersion:%d",
|
||||
alterReq.vgId, alterReq.replica, alterReq.selfIndex, alterReq.learnerReplica,
|
||||
alterReq.learnerSelfIndex, alterReq.strict);
|
||||
alterReq.learnerSelfIndex, alterReq.strict, alterReq.changeVersion);
|
||||
for (int32_t i = 0; i < alterReq.replica; ++i) {
|
||||
mInfo("vgId:%d, replica:%d ep:%s:%u", alterReq.vgId, i, alterReq.replicas[i].fqdn, alterReq.replicas[i].port);
|
||||
}
|
||||
|
@ -473,6 +487,83 @@ static void *mndBuildAlterVnodeReplicaReq(SMnode *pMnode, SDbObj *pDb, SVgObj *p
|
|||
return pReq;
|
||||
}
|
||||
|
||||
static void *mndBuildCheckLearnCatchupReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup, int32_t dnodeId,
|
||||
int32_t *pContLen) {
|
||||
SCheckLearnCatchupReq req = {
|
||||
.vgId = pVgroup->vgId,
|
||||
.strict = pDb->cfg.strict,
|
||||
.replica = 0,
|
||||
.learnerReplica = 0,
|
||||
.selfIndex = -1,
|
||||
.learnerSelfIndex = -1,
|
||||
};
|
||||
|
||||
for (int32_t v = 0; v < pVgroup->replica; ++v) {
|
||||
SReplica *pReplica = NULL;
|
||||
|
||||
if(pVgroup->vnodeGid[v].nodeRole == TAOS_SYNC_ROLE_VOTER){
|
||||
pReplica = &req.replicas[req.replica];
|
||||
req.replica++;
|
||||
}
|
||||
else{
|
||||
pReplica = &req.learnerReplicas[req.learnerReplica];
|
||||
req.learnerReplica++;
|
||||
}
|
||||
|
||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[v];
|
||||
SDnodeObj *pVgidDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pVgidDnode == NULL) return NULL;
|
||||
|
||||
pReplica->id = pVgidDnode->id;
|
||||
pReplica->port = pVgidDnode->port;
|
||||
memcpy(pReplica->fqdn, pVgidDnode->fqdn, TSDB_FQDN_LEN);
|
||||
mndReleaseDnode(pMnode, pVgidDnode);
|
||||
|
||||
if(pVgroup->vnodeGid[v].nodeRole == TAOS_SYNC_ROLE_VOTER){
|
||||
if (dnodeId == pVgid->dnodeId) {
|
||||
req.selfIndex = v;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (dnodeId == pVgid->dnodeId) {
|
||||
req.learnerSelfIndex = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mInfo("vgId:%d, build alter vnode req, replica:%d selfIndex:%d learnerReplica:%d learnerSelfIndex:%d strict:%d",
|
||||
req.vgId, req.replica, req.selfIndex, req.learnerReplica,
|
||||
req.learnerSelfIndex, req.strict);
|
||||
for (int32_t i = 0; i < req.replica; ++i) {
|
||||
mInfo("vgId:%d, replica:%d ep:%s:%u", req.vgId, i, req.replicas[i].fqdn, req.replicas[i].port);
|
||||
}
|
||||
for (int32_t i = 0; i < req.learnerReplica; ++i) {
|
||||
mInfo("vgId:%d, learnerReplica:%d ep:%s:%u", req.vgId, i,
|
||||
req.learnerReplicas[i].fqdn, req.learnerReplicas[i].port);
|
||||
}
|
||||
|
||||
if (req.selfIndex == -1 && req.learnerSelfIndex == -1) {
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t contLen = tSerializeSAlterVnodeReplicaReq(NULL, 0, &req);
|
||||
if (contLen < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *pReq = taosMemoryMalloc(contLen);
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tSerializeSAlterVnodeReplicaReq(pReq, contLen, &req);
|
||||
*pContLen = contLen;
|
||||
return pReq;
|
||||
}
|
||||
|
||||
static void *mndBuildDisableVnodeWriteReq(SMnode *pMnode, SDbObj *pDb, int32_t vgId, int32_t *pContLen) {
|
||||
SDisableVnodeWriteReq disableReq = {
|
||||
.vgId = vgId,
|
||||
|
@ -503,6 +594,7 @@ static void *mndBuildAlterVnodeHashRangeReq(SMnode *pMnode, int32_t srcVgId, SVg
|
|||
.dstVgId = pVgroup->vgId,
|
||||
.hashBegin = pVgroup->hashBegin,
|
||||
.hashEnd = pVgroup->hashEnd,
|
||||
.changeVersion = ++(pVgroup->syncConfChangeVer),
|
||||
};
|
||||
|
||||
mInfo("vgId:%d, build alter vnode hashrange req, dstVgId:%d, hashrange:[%u, %u]", srcVgId, pVgroup->vgId,
|
||||
|
@ -861,6 +953,28 @@ static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p
|
|||
}
|
||||
}
|
||||
snprintf(role, sizeof(role), "%s%s", syncStr(pVgroup->vnodeGid[i].syncState), star);
|
||||
/*
|
||||
mInfo("db:%s, learner progress:%d", pDb->name, pVgroup->vnodeGid[i].learnerProgress);
|
||||
|
||||
if (pVgroup->vnodeGid[i].syncState == TAOS_SYNC_STATE_LEARNER) {
|
||||
if(pVgroup->vnodeGid[i].learnerProgress < 0){
|
||||
snprintf(role, sizeof(role), "%s-",
|
||||
syncStr(pVgroup->vnodeGid[i].syncState));
|
||||
|
||||
}
|
||||
else if(pVgroup->vnodeGid[i].learnerProgress >= 100){
|
||||
snprintf(role, sizeof(role), "%s--",
|
||||
syncStr(pVgroup->vnodeGid[i].syncState));
|
||||
}
|
||||
else{
|
||||
snprintf(role, sizeof(role), "%s%d",
|
||||
syncStr(pVgroup->vnodeGid[i].syncState), pVgroup->vnodeGid[i].learnerProgress);
|
||||
}
|
||||
}
|
||||
else{
|
||||
snprintf(role, sizeof(role), "%s%s", syncStr(pVgroup->vnodeGid[i].syncState), star);
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
}
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(buf1, role, pShow->pMeta->pSchemas[cols].bytes);
|
||||
|
@ -1155,6 +1269,51 @@ _OVER:
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndRemoveVnodeFromVgroupWithoutSave(SMnode *pMnode, STrans *pTrans, SVgObj *pVgroup, SArray *pArray,
|
||||
SVnodeGid *pDelVgid) {
|
||||
taosArraySort(pArray, (__compar_fn_t)mndCompareDnodeVnodes);
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
|
||||
SDnodeObj *pDnode = taosArrayGet(pArray, i);
|
||||
mInfo("dnode:%d, equivalent vnodes:%d others:%d", pDnode->id, pDnode->numOfVnodes, pDnode->numOfOtherNodes);
|
||||
}
|
||||
|
||||
int32_t code = -1;
|
||||
for (int32_t d = taosArrayGetSize(pArray) - 1; d >= 0; --d) {
|
||||
SDnodeObj *pDnode = taosArrayGet(pArray, d);
|
||||
|
||||
for (int32_t vn = 0; vn < pVgroup->replica; ++vn) {
|
||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[vn];
|
||||
if (pVgid->dnodeId == pDnode->id) {
|
||||
int64_t vgMem = mndGetVgroupMemory(pMnode, NULL, pVgroup);
|
||||
pDnode->memUsed -= vgMem;
|
||||
mInfo("db:%s, vgId:%d, vn:%d is removed, memory:%" PRId64 ", dnode:%d avail:%" PRId64 " used:%" PRId64,
|
||||
pVgroup->dbName, pVgroup->vgId, vn, vgMem, pVgid->dnodeId, pDnode->memAvail, pDnode->memUsed);
|
||||
pDnode->numOfVnodes--;
|
||||
pVgroup->replica--;
|
||||
*pDelVgid = *pVgid;
|
||||
*pVgid = pVgroup->vnodeGid[pVgroup->replica];
|
||||
memset(&pVgroup->vnodeGid[pVgroup->replica], 0, sizeof(SVnodeGid));
|
||||
code = 0;
|
||||
goto _OVER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_OVER:
|
||||
if (code != 0) {
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
mError("db:%s, failed to remove vnode from vgId:%d since %s", pVgroup->dbName, pVgroup->vgId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int32_t vn = 0; vn < pVgroup->replica; ++vn) {
|
||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[vn];
|
||||
mInfo("db:%s, vgId:%d, vn:%d dnode:%d is reserved", pVgroup->dbName, pVgroup->vgId, vn, pVgid->dnodeId);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndAddCreateVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid) {
|
||||
STransAction action = {0};
|
||||
|
||||
|
@ -1231,6 +1390,42 @@ int32_t mndAddAlterVnodeConfirmAction(SMnode *pMnode, STrans *pTrans, SDbObj *pD
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndAddChangeConfigAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb,
|
||||
SVgObj *pOldVgroup, SVgObj *pNewVgroup, int32_t dnodeId) {
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetVgroupEpset(pMnode, pNewVgroup);
|
||||
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildAlterVnodeReplicaReq(pMnode, pDb, pNewVgroup, dnodeId, &contLen);
|
||||
if (pReq == NULL) return -1;
|
||||
|
||||
int32_t totallen = contLen + sizeof(SMsgHead);
|
||||
|
||||
SMsgHead *pHead = taosMemoryMalloc(totallen);
|
||||
if (pHead == NULL) {
|
||||
taosMemoryFree(pReq);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pHead->contLen = htonl(totallen);
|
||||
pHead->vgId = htonl(pNewVgroup->vgId);
|
||||
|
||||
memcpy((void*)(pHead + 1), pReq, contLen);
|
||||
taosMemoryFree(pReq);
|
||||
|
||||
action.pCont = pHead;
|
||||
action.contLen = totallen;
|
||||
action.msgType = TDMT_SYNC_CONFIG_CHANGE;
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pHead);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndAddAlterVnodeHashRangeAction(SMnode *pMnode, STrans *pTrans, int32_t srcVgId, SVgObj *pVgroup) {
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
|
@ -1310,6 +1505,32 @@ int32_t mndAddAlterVnodeReplicaAction(SMnode *pMnode, STrans *pTrans, SDbObj *pD
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndAddCheckLearnerCatchupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, int32_t dnodeId) {
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, dnodeId);
|
||||
if (pDnode == NULL) return -1;
|
||||
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildCheckLearnCatchupReq(pMnode, pDb, pVgroup, dnodeId, &contLen);
|
||||
if (pReq == NULL) return -1;
|
||||
|
||||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP;
|
||||
action.acceptableCode = TSDB_CODE_VND_ALREADY_IS_VOTER;
|
||||
action.retryCode = TSDB_CODE_VND_NOT_CATCH_UP;
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndAddAlterVnodeTypeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, int32_t dnodeId) {
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, dnodeId);
|
||||
if (pDnode == NULL) return -1;
|
||||
|
@ -2227,6 +2448,133 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndBuildRaftAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb, SVgObj *pVgroup,
|
||||
SArray *pArray) {
|
||||
SVgObj newVgroup = {0};
|
||||
memcpy(&newVgroup, pVgroup, sizeof(SVgObj));
|
||||
|
||||
if (pVgroup->replica <= 0 || pVgroup->replica == pNewDb->cfg.replications) {
|
||||
if (mndAddAlterVnodeConfigAction(pMnode, pTrans, pNewDb, pVgroup) != 0) return -1;
|
||||
if (mndCheckDnodeMemory(pMnode, pOldDb, pNewDb, &newVgroup, pVgroup, pArray) != 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
mndTransSetSerial(pTrans);
|
||||
|
||||
mInfo("trans:%d, vgId:%d, alter vgroup, syncConfChangeVer:%d, version:%d, replica:%d",
|
||||
pTrans->id, pVgroup->vgId, pVgroup->syncConfChangeVer, pVgroup->version, pVgroup->replica);
|
||||
|
||||
if (newVgroup.replica == 1 && pNewDb->cfg.replications == 3) {
|
||||
mInfo("db:%s, vgId:%d, will add 2 vnodes, vn:0 dnode:%d", pVgroup->dbName, pVgroup->vgId,
|
||||
pVgroup->vnodeGid[0].dnodeId);
|
||||
|
||||
//add second
|
||||
if (mndAddVnodeToVgroup(pMnode, pTrans, &newVgroup, pArray) != 0) return -1;
|
||||
//add third
|
||||
if (mndAddVnodeToVgroup(pMnode, pTrans, &newVgroup, pArray) != 0) return -1;
|
||||
|
||||
//add learner stage
|
||||
newVgroup.vnodeGid[0].nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
newVgroup.vnodeGid[1].nodeRole = TAOS_SYNC_ROLE_LEARNER;
|
||||
newVgroup.vnodeGid[2].nodeRole = TAOS_SYNC_ROLE_LEARNER;
|
||||
if (mndAddChangeConfigAction(pMnode, pTrans, pNewDb, pVgroup, &newVgroup, newVgroup.vnodeGid[0].dnodeId) != 0) return -1;
|
||||
mInfo("trans:%d, vgId:%d, add change config, syncConfChangeVer:%d, version:%d, replica:%d",
|
||||
pTrans->id, pVgroup->vgId, newVgroup.syncConfChangeVer, pVgroup->version, pVgroup->replica);
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &newVgroup.vnodeGid[1]) != 0) return -1;
|
||||
mInfo("trans:%d, vgId:%d, create vnode, syncConfChangeVer:%d, version:%d, replica:%d",
|
||||
pTrans->id, pVgroup->vgId, newVgroup.syncConfChangeVer, pVgroup->version, pVgroup->replica);
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &newVgroup.vnodeGid[2]) != 0) return -1;
|
||||
mInfo("trans:%d, vgId:%d, create vnode, syncConfChangeVer:%d, version:%d, replica:%d",
|
||||
pTrans->id, pVgroup->vgId, newVgroup.syncConfChangeVer, pVgroup->version, pVgroup->replica);
|
||||
|
||||
|
||||
//check learner
|
||||
newVgroup.vnodeGid[0].nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
newVgroup.vnodeGid[1].nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
newVgroup.vnodeGid[2].nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
if (mndAddCheckLearnerCatchupAction(pMnode, pTrans, pNewDb, &newVgroup, newVgroup.vnodeGid[1].dnodeId) != 0) return -1;
|
||||
if (mndAddCheckLearnerCatchupAction(pMnode, pTrans, pNewDb, &newVgroup, newVgroup.vnodeGid[2].dnodeId) != 0) return -1;
|
||||
|
||||
//change raft type
|
||||
newVgroup.vnodeGid[0].nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
newVgroup.vnodeGid[1].nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
newVgroup.vnodeGid[2].nodeRole = TAOS_SYNC_ROLE_LEARNER;
|
||||
if (mndAddChangeConfigAction(pMnode, pTrans, pNewDb, pVgroup, &newVgroup, newVgroup.vnodeGid[0].dnodeId) != 0)
|
||||
return -1;
|
||||
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, &newVgroup) != 0) return -1;
|
||||
|
||||
newVgroup.vnodeGid[0].nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
newVgroup.vnodeGid[1].nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
newVgroup.vnodeGid[2].nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
if (mndAddChangeConfigAction(pMnode, pTrans, pNewDb, pVgroup, &newVgroup, newVgroup.vnodeGid[0].dnodeId) != 0)
|
||||
return -1;
|
||||
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, &newVgroup) != 0) return -1;
|
||||
|
||||
SSdbRaw *pVgRaw = mndVgroupActionEncode(&newVgroup);
|
||||
if (pVgRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pVgRaw) != 0) {
|
||||
sdbFreeRaw(pVgRaw);
|
||||
return -1;
|
||||
}
|
||||
(void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY);
|
||||
} else if (newVgroup.replica == 3 && pNewDb->cfg.replications == 1) {
|
||||
mInfo("db:%s, vgId:%d, will remove 2 vnodes, vn:0 dnode:%d vn:1 dnode:%d vn:2 dnode:%d", pVgroup->dbName,
|
||||
pVgroup->vgId, pVgroup->vnodeGid[0].dnodeId, pVgroup->vnodeGid[1].dnodeId, pVgroup->vnodeGid[2].dnodeId);
|
||||
|
||||
SVnodeGid del1 = {0};
|
||||
if (mndRemoveVnodeFromVgroupWithoutSave(pMnode, pTrans, &newVgroup, pArray, &del1) != 0) return -1;
|
||||
|
||||
if (mndAddChangeConfigAction(pMnode, pTrans, pNewDb, pVgroup, &newVgroup, newVgroup.vnodeGid[0].dnodeId) != 0) return -1;
|
||||
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, &newVgroup) != 0) return -1;
|
||||
|
||||
if (mndAddDropVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &del1, true) != 0) return -1;
|
||||
|
||||
SSdbRaw *pVgRaw = mndVgroupActionEncode(&newVgroup);
|
||||
if (pVgRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pVgRaw) != 0) {
|
||||
sdbFreeRaw(pVgRaw);
|
||||
return -1;
|
||||
}
|
||||
(void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY);
|
||||
|
||||
SVnodeGid del2 = {0};
|
||||
if (mndRemoveVnodeFromVgroupWithoutSave(pMnode, pTrans, &newVgroup, pArray, &del2) != 0) return -1;
|
||||
|
||||
if (mndAddChangeConfigAction(pMnode, pTrans, pNewDb, pVgroup, &newVgroup, newVgroup.vnodeGid[0].dnodeId) != 0) return -1;
|
||||
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, &newVgroup) != 0) return -1;
|
||||
|
||||
if (mndAddDropVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &del2, true) != 0) return -1;
|
||||
|
||||
pVgRaw = mndVgroupActionEncode(&newVgroup);
|
||||
if (pVgRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pVgRaw) != 0) {
|
||||
sdbFreeRaw(pVgRaw);
|
||||
return -1;
|
||||
}
|
||||
(void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
mndSortVnodeGid(&newVgroup);
|
||||
|
||||
{
|
||||
SSdbRaw *pVgRaw = mndVgroupActionEncode(&newVgroup);
|
||||
if (pVgRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pVgRaw) != 0) {
|
||||
sdbFreeRaw(pVgRaw);
|
||||
return -1;
|
||||
}
|
||||
(void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndBuildRestoreAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *db, SVgObj *pVgroup,
|
||||
SDnodeObj *pDnode) {
|
||||
SVgObj newVgroup = {0};
|
||||
|
|
|
@ -31,15 +31,14 @@ typedef enum DirtyEntryType {
|
|||
} DirtyEntryType;
|
||||
|
||||
typedef struct STtlManger {
|
||||
TdThreadRwlock lock;
|
||||
TTB* pOldTtlIdx; // btree<{deleteTime, tuid}, NULL>
|
||||
|
||||
TTB* pOldTtlIdx; // btree<{deleteTime, tuid}, NULL>
|
||||
|
||||
SHashObj* pTtlCache; // key: tuid, value: {ttl, ctime}
|
||||
SHashObj* pDirtyUids; // dirty tuid
|
||||
SHashObj* pTtlCache; // hash<tuid, {ttl, ctime}>
|
||||
SHashObj* pDirtyUids; // hash<dirtyTuid, entryType>
|
||||
TTB* pTtlIdx; // btree<{deleteTime, tuid}, ttl>
|
||||
|
||||
char* logPrefix;
|
||||
char* logPrefix;
|
||||
int32_t flushThreshold; // max dirty entry number in memory. if -1, flush will not be triggered by write-ops
|
||||
} STtlManger;
|
||||
|
||||
typedef struct {
|
||||
|
@ -68,23 +67,24 @@ typedef struct {
|
|||
typedef struct {
|
||||
tb_uid_t uid;
|
||||
int64_t changeTimeMs;
|
||||
TXN* pTxn;
|
||||
} STtlUpdCtimeCtx;
|
||||
|
||||
typedef struct {
|
||||
tb_uid_t uid;
|
||||
int64_t changeTimeMs;
|
||||
int64_t ttlDays;
|
||||
TXN* pTxn;
|
||||
} STtlUpdTtlCtx;
|
||||
|
||||
typedef struct {
|
||||
tb_uid_t uid;
|
||||
TXN* pTxn;
|
||||
int64_t ttlDays;
|
||||
TXN* pTxn;
|
||||
} STtlDelTtlCtx;
|
||||
|
||||
int ttlMgrOpen(STtlManger** ppTtlMgr, TDB* pEnv, int8_t rollback, const char* logPrefix);
|
||||
int ttlMgrOpen(STtlManger** ppTtlMgr, TDB* pEnv, int8_t rollback, const char* logPrefix, int32_t flushThreshold);
|
||||
void ttlMgrClose(STtlManger* pTtlMgr);
|
||||
int ttlMgrPostOpen(STtlManger* pTtlMgr, void* pMeta);
|
||||
|
||||
bool ttlMgrNeedUpgrade(TDB* pEnv);
|
||||
int ttlMgrUpgrade(STtlManger* pTtlMgr, void* pMeta);
|
||||
|
@ -94,7 +94,7 @@ int ttlMgrDeleteTtl(STtlManger* pTtlMgr, const STtlDelTtlCtx* pDelCtx);
|
|||
int ttlMgrUpdateChangeTime(STtlManger* pTtlMgr, const STtlUpdCtimeCtx* pUpdCtimeCtx);
|
||||
|
||||
int ttlMgrFlush(STtlManger* pTtlMgr, TXN* pTxn);
|
||||
int ttlMgrFindExpired(STtlManger* pTtlMgr, int64_t timePointMs, SArray* pTbUids);
|
||||
int ttlMgrFindExpired(STtlManger* pTtlMgr, int64_t timePointMs, SArray* pTbUids, int32_t ttlDropMaxCount);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ int32_t vnodeAsyncCommit(SVnode* pVnode);
|
|||
bool vnodeShouldRollback(SVnode* pVnode);
|
||||
|
||||
// vnodeSync.c
|
||||
int32_t vnodeSyncOpen(SVnode* pVnode, char* path);
|
||||
int32_t vnodeSyncOpen(SVnode *pVnode, char *path, int32_t vnodeVersion);
|
||||
int32_t vnodeSyncStart(SVnode* pVnode);
|
||||
void vnodeSyncPreClose(SVnode* pVnode);
|
||||
void vnodeSyncPostClose(SVnode* pVnode);
|
||||
|
|
|
@ -152,9 +152,10 @@ int metaDropSTable(SMeta* pMeta, int64_t verison, SVDropStbReq* pReq
|
|||
int metaCreateTable(SMeta* pMeta, int64_t version, SVCreateTbReq* pReq, STableMetaRsp** pMetaRsp);
|
||||
int metaDropTable(SMeta* pMeta, int64_t version, SVDropTbReq* pReq, SArray* tbUids, int64_t* tbUid);
|
||||
int32_t metaTrimTables(SMeta* pMeta);
|
||||
int metaTtlDropTable(SMeta* pMeta, int64_t timePointMs, SArray* tbUids);
|
||||
void metaDropTables(SMeta* pMeta, SArray* tbUids);
|
||||
int metaTtlFindExpired(SMeta* pMeta, int64_t timePointMs, SArray* tbUids, int32_t ttlDropMaxCount);
|
||||
int metaAlterTable(SMeta* pMeta, int64_t version, SVAlterTbReq* pReq, STableMetaRsp* pMetaRsp);
|
||||
int metaUpdateChangeTime(SMeta* pMeta, tb_uid_t uid, int64_t changeTimeMs);
|
||||
int metaUpdateChangeTimeWithLock(SMeta* pMeta, tb_uid_t uid, int64_t changeTimeMs);
|
||||
SSchemaWrapper* metaGetTableSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, int lock);
|
||||
STSchema* metaGetTbTSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, int lock);
|
||||
int32_t metaGetTbTSchemaEx(SMeta* pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sver, STSchema** ppTSchema);
|
||||
|
|
|
@ -130,7 +130,7 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta, int8_t rollback) {
|
|||
// open pTtlMgr ("ttlv1.idx")
|
||||
char logPrefix[128] = {0};
|
||||
sprintf(logPrefix, "vgId:%d", TD_VID(pVnode));
|
||||
ret = ttlMgrOpen(&pMeta->pTtlMgr, pMeta->pEnv, 0, logPrefix);
|
||||
ret = ttlMgrOpen(&pMeta->pTtlMgr, pMeta->pEnv, 0, logPrefix, tsTtlFlushThreshold);
|
||||
if (ret < 0) {
|
||||
metaError("vgId:%d, failed to open meta ttl index since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
|
|
|
@ -21,6 +21,7 @@ static int metaSaveToTbDb(SMeta *pMeta, const SMetaEntry *pME);
|
|||
static int metaUpdateUidIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaUpdateNameIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaUpdateTtl(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaUpdateChangeTime(SMeta *pMeta, tb_uid_t uid, int64_t changeTimeMs);
|
||||
static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaUpdateSuidIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
|
@ -842,9 +843,11 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUi
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void metaDropTables(SMeta *pMeta, SArray *tbUids) {
|
||||
void metaDropTables(SMeta *pMeta, SArray *tbUids) {
|
||||
if (taosArrayGetSize(tbUids) == 0) return;
|
||||
|
||||
metaWLock(pMeta);
|
||||
for (int i = 0; i < TARRAY_SIZE(tbUids); ++i) {
|
||||
for (int i = 0; i < taosArrayGetSize(tbUids); ++i) {
|
||||
tb_uid_t uid = *(tb_uid_t *)taosArrayGet(tbUids, i);
|
||||
metaDropTableByUid(pMeta, uid, NULL);
|
||||
metaDebug("batch drop table:%" PRId64, uid);
|
||||
|
@ -927,26 +930,23 @@ end:
|
|||
return code;
|
||||
}
|
||||
|
||||
int metaTtlDropTable(SMeta *pMeta, int64_t timePointMs, SArray *tbUids) {
|
||||
int metaTtlFindExpired(SMeta *pMeta, int64_t timePointMs, SArray *tbUids, int32_t ttlDropMaxCount) {
|
||||
metaWLock(pMeta);
|
||||
int ret = ttlMgrFlush(pMeta->pTtlMgr, pMeta->txn);
|
||||
if (ret != 0) {
|
||||
metaError("ttl failed to flush, ret:%d", ret);
|
||||
return ret;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
ret = ttlMgrFindExpired(pMeta->pTtlMgr, timePointMs, tbUids);
|
||||
ret = ttlMgrFindExpired(pMeta->pTtlMgr, timePointMs, tbUids, ttlDropMaxCount);
|
||||
if (ret != 0) {
|
||||
metaError("ttl failed to find expired table, ret:%d", ret);
|
||||
return ret;
|
||||
}
|
||||
if (TARRAY_SIZE(tbUids) == 0) {
|
||||
return 0;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
metaInfo("ttl find expired table count: %zu", TARRAY_SIZE(tbUids));
|
||||
|
||||
metaDropTables(pMeta, tbUids);
|
||||
return 0;
|
||||
_err:
|
||||
metaULock(pMeta);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int metaBuildBtimeIdxKey(SBtimeIdxKey *btimeKey, const SMetaEntry *pME) {
|
||||
|
@ -1326,10 +1326,10 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
|
||||
metaSaveToSkmDb(pMeta, &entry);
|
||||
|
||||
metaULock(pMeta);
|
||||
|
||||
metaUpdateChangeTime(pMeta, entry.uid, pAlterTbReq->ctimeMs);
|
||||
|
||||
metaULock(pMeta);
|
||||
|
||||
metaUpdateMetaRsp(uid, pAlterTbReq->tbName, pSchema, pMetaRsp);
|
||||
|
||||
if (entry.pBuf) taosMemoryFree(entry.pBuf);
|
||||
|
@ -1515,10 +1515,10 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
|
|||
metaUidCacheClear(pMeta, ctbEntry.ctbEntry.suid);
|
||||
metaTbGroupCacheClear(pMeta, ctbEntry.ctbEntry.suid);
|
||||
|
||||
metaULock(pMeta);
|
||||
|
||||
metaUpdateChangeTime(pMeta, ctbEntry.uid, pAlterTbReq->ctimeMs);
|
||||
|
||||
metaULock(pMeta);
|
||||
|
||||
tDecoderClear(&dc1);
|
||||
tDecoderClear(&dc2);
|
||||
taosMemoryFree((void *)ctbEntry.ctbEntry.pTags);
|
||||
|
@ -1630,10 +1630,10 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p
|
|||
// save to table db
|
||||
metaSaveToTbDb(pMeta, &entry);
|
||||
metaUpdateUidIdx(pMeta, &entry);
|
||||
metaULock(pMeta);
|
||||
|
||||
metaUpdateChangeTime(pMeta, entry.uid, pAlterTbReq->ctimeMs);
|
||||
|
||||
metaULock(pMeta);
|
||||
|
||||
tdbTbcClose(pTbDbc);
|
||||
tdbTbcClose(pUidIdxc);
|
||||
tDecoderClear(&dc);
|
||||
|
@ -1981,7 +1981,7 @@ static int metaUpdateNameIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
|||
static int metaUpdateTtl(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
if (pME->type != TSDB_CHILD_TABLE && pME->type != TSDB_NORMAL_TABLE) return 0;
|
||||
|
||||
STtlUpdTtlCtx ctx = {.uid = pME->uid};
|
||||
STtlUpdTtlCtx ctx = {.uid = pME->uid, .pTxn = pMeta->txn};
|
||||
if (pME->type == TSDB_CHILD_TABLE) {
|
||||
ctx.ttlDays = pME->ctbEntry.ttlDays;
|
||||
ctx.changeTimeMs = pME->ctbEntry.btime;
|
||||
|
@ -1993,7 +1993,7 @@ static int metaUpdateTtl(SMeta *pMeta, const SMetaEntry *pME) {
|
|||
return ttlMgrInsertTtl(pMeta->pTtlMgr, &ctx);
|
||||
}
|
||||
|
||||
int metaUpdateChangeTime(SMeta *pMeta, tb_uid_t uid, int64_t changeTimeMs) {
|
||||
static int metaUpdateChangeTime(SMeta *pMeta, tb_uid_t uid, int64_t changeTimeMs) {
|
||||
if (!tsTtlChangeOnWrite) return 0;
|
||||
|
||||
if (changeTimeMs <= 0) {
|
||||
|
@ -2001,11 +2001,20 @@ int metaUpdateChangeTime(SMeta *pMeta, tb_uid_t uid, int64_t changeTimeMs) {
|
|||
return TSDB_CODE_VERSION_NOT_COMPATIBLE;
|
||||
}
|
||||
|
||||
STtlUpdCtimeCtx ctx = {.uid = uid, .changeTimeMs = changeTimeMs};
|
||||
STtlUpdCtimeCtx ctx = {.uid = uid, .changeTimeMs = changeTimeMs, .pTxn = pMeta->txn};
|
||||
|
||||
return ttlMgrUpdateChangeTime(pMeta->pTtlMgr, &ctx);
|
||||
}
|
||||
|
||||
int metaUpdateChangeTimeWithLock(SMeta *pMeta, tb_uid_t uid, int64_t changeTimeMs) {
|
||||
if (!tsTtlChangeOnWrite) return 0;
|
||||
|
||||
metaWLock(pMeta);
|
||||
int ret = metaUpdateChangeTime(pMeta, uid, changeTimeMs);
|
||||
metaULock(pMeta);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
SCtbIdxKey ctbIdxKey = {.suid = pME->ctbEntry.suid, .uid = pME->uid};
|
||||
|
||||
|
|
|
@ -21,6 +21,13 @@ typedef struct {
|
|||
SMeta *pMeta;
|
||||
} SConvertData;
|
||||
|
||||
typedef struct {
|
||||
int32_t ttlDropMaxCount;
|
||||
int32_t count;
|
||||
STtlIdxKeyV1 expiredKey;
|
||||
SArray *pTbUids;
|
||||
} STtlExpiredCtx;
|
||||
|
||||
static void ttlMgrCleanup(STtlManger *pTtlMgr);
|
||||
|
||||
static int ttlMgrConvert(TTB *pOldTtlIdx, TTB *pNewTtlIdx, void *pMeta);
|
||||
|
@ -31,15 +38,15 @@ static int ttlIdxKeyV1Cmpr(const void *pKey1, int kLen1, const void *pKey2,
|
|||
static int ttlMgrFillCache(STtlManger *pTtlMgr);
|
||||
static int32_t ttlMgrFillCacheOneEntry(const void *pKey, int keyLen, const void *pVal, int valLen, void *pTtlCache);
|
||||
static int32_t ttlMgrConvertOneEntry(const void *pKey, int keyLen, const void *pVal, int valLen, void *pConvertData);
|
||||
static int32_t ttlMgrFindExpiredOneEntry(const void *pKey, int keyLen, const void *pVal, int valLen,
|
||||
void *pExpiredInfo);
|
||||
|
||||
static int32_t ttlMgrWLock(STtlManger *pTtlMgr);
|
||||
static int32_t ttlMgrRLock(STtlManger *pTtlMgr);
|
||||
static int32_t ttlMgrULock(STtlManger *pTtlMgr);
|
||||
static bool ttlMgrNeedFlush(STtlManger *pTtlMgr);
|
||||
|
||||
const char *ttlTbname = "ttl.idx";
|
||||
const char *ttlV1Tbname = "ttlv1.idx";
|
||||
|
||||
int ttlMgrOpen(STtlManger **ppTtlMgr, TDB *pEnv, int8_t rollback, const char *logPrefix) {
|
||||
int ttlMgrOpen(STtlManger **ppTtlMgr, TDB *pEnv, int8_t rollback, const char *logPrefix, int32_t flushThreshold) {
|
||||
int ret = TSDB_CODE_SUCCESS;
|
||||
int64_t startNs = taosGetTimestampNs();
|
||||
|
||||
|
@ -55,6 +62,7 @@ int ttlMgrOpen(STtlManger **ppTtlMgr, TDB *pEnv, int8_t rollback, const char *lo
|
|||
}
|
||||
strcpy(logBuffer, logPrefix);
|
||||
pTtlMgr->logPrefix = logBuffer;
|
||||
pTtlMgr->flushThreshold = flushThreshold;
|
||||
|
||||
ret = tdbTbOpen(ttlV1Tbname, TDB_VARIANT_LEN, TDB_VARIANT_LEN, ttlIdxKeyV1Cmpr, pEnv, &pTtlMgr->pTtlIdx, rollback);
|
||||
if (ret < 0) {
|
||||
|
@ -66,8 +74,6 @@ int ttlMgrOpen(STtlManger **ppTtlMgr, TDB *pEnv, int8_t rollback, const char *lo
|
|||
pTtlMgr->pTtlCache = taosHashInit(8192, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
|
||||
pTtlMgr->pDirtyUids = taosHashInit(8192, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
|
||||
|
||||
taosThreadRwlockInit(&pTtlMgr->lock, NULL);
|
||||
|
||||
ret = ttlMgrFillCache(pTtlMgr);
|
||||
if (ret < 0) {
|
||||
metaError("%s, failed to fill hash since %s", pTtlMgr->logPrefix, tstrerror(terrno));
|
||||
|
@ -130,6 +136,7 @@ int ttlMgrUpgrade(STtlManger *pTtlMgr, void *pMeta) {
|
|||
int64_t endNs = taosGetTimestampNs();
|
||||
metaInfo("%s, ttl mgr upgrade end, hash size: %d, time consumed: %" PRId64 " ns", pTtlMgr->logPrefix,
|
||||
taosHashGetSize(pTtlMgr->pTtlCache), endNs - startNs);
|
||||
|
||||
_out:
|
||||
tdbTbClose(pTtlMgr->pOldTtlIdx);
|
||||
pTtlMgr->pOldTtlIdx = NULL;
|
||||
|
@ -142,7 +149,6 @@ static void ttlMgrCleanup(STtlManger *pTtlMgr) {
|
|||
taosHashCleanup(pTtlMgr->pTtlCache);
|
||||
taosHashCleanup(pTtlMgr->pDirtyUids);
|
||||
tdbTbClose(pTtlMgr->pTtlIdx);
|
||||
taosThreadRwlockDestroy(&pTtlMgr->lock);
|
||||
taosMemoryFree(pTtlMgr);
|
||||
}
|
||||
|
||||
|
@ -229,10 +235,25 @@ static int ttlMgrConvertOneEntry(const void *pKey, int keyLen, const void *pVal,
|
|||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
_out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t ttlMgrFindExpiredOneEntry(const void *pKey, int keyLen, const void *pVal, int valLen,
|
||||
void *pExpiredCtx) {
|
||||
STtlExpiredCtx *pCtx = (STtlExpiredCtx *)pExpiredCtx;
|
||||
if (pCtx->count >= pCtx->ttlDropMaxCount) return -1;
|
||||
|
||||
int c = ttlIdxKeyV1Cmpr(&pCtx->expiredKey, sizeof(pCtx->expiredKey), pKey, keyLen);
|
||||
if (c > 0) {
|
||||
taosArrayPush(pCtx->pTbUids, &((STtlIdxKeyV1 *)pKey)->uid);
|
||||
pCtx->count++;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
static int ttlMgrConvert(TTB *pOldTtlIdx, TTB *pNewTtlIdx, void *pMeta) {
|
||||
SMeta *meta = pMeta;
|
||||
|
||||
|
@ -255,8 +276,6 @@ int ttlMgrInsertTtl(STtlManger *pTtlMgr, const STtlUpdTtlCtx *updCtx) {
|
|||
STtlCacheEntry cacheEntry = {.ttlDays = updCtx->ttlDays, .changeTimeMs = updCtx->changeTimeMs};
|
||||
STtlDirtyEntry dirtryEntry = {.type = ENTRY_TYPE_UPSERT};
|
||||
|
||||
ttlMgrWLock(pTtlMgr);
|
||||
|
||||
int ret = taosHashPut(pTtlMgr->pTtlCache, &updCtx->uid, sizeof(updCtx->uid), &cacheEntry, sizeof(cacheEntry));
|
||||
if (ret < 0) {
|
||||
metaError("%s, ttlMgr insert failed to update ttl cache since %s", pTtlMgr->logPrefix, tstrerror(terrno));
|
||||
|
@ -269,10 +288,13 @@ int ttlMgrInsertTtl(STtlManger *pTtlMgr, const STtlUpdTtlCtx *updCtx) {
|
|||
goto _out;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
_out:
|
||||
ttlMgrULock(pTtlMgr);
|
||||
if (ttlMgrNeedFlush(pTtlMgr)) {
|
||||
ttlMgrFlush(pTtlMgr, updCtx->pTxn);
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
_out:
|
||||
metaDebug("%s, ttl mgr insert ttl, uid: %" PRId64 ", ctime: %" PRId64 ", ttlDays: %" PRId64, pTtlMgr->logPrefix,
|
||||
updCtx->uid, updCtx->changeTimeMs, updCtx->ttlDays);
|
||||
|
||||
|
@ -281,7 +303,6 @@ _out:
|
|||
|
||||
int ttlMgrDeleteTtl(STtlManger *pTtlMgr, const STtlDelTtlCtx *delCtx) {
|
||||
if (delCtx->ttlDays == 0) return 0;
|
||||
ttlMgrWLock(pTtlMgr);
|
||||
|
||||
STtlDirtyEntry dirtryEntry = {.type = ENTRY_TYPE_DEL};
|
||||
|
||||
|
@ -291,18 +312,19 @@ int ttlMgrDeleteTtl(STtlManger *pTtlMgr, const STtlDelTtlCtx *delCtx) {
|
|||
goto _out;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
_out:
|
||||
ttlMgrULock(pTtlMgr);
|
||||
if (ttlMgrNeedFlush(pTtlMgr)) {
|
||||
ttlMgrFlush(pTtlMgr, delCtx->pTxn);
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
_out:
|
||||
metaDebug("%s, ttl mgr delete ttl, uid: %" PRId64, pTtlMgr->logPrefix, delCtx->uid);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ttlMgrUpdateChangeTime(STtlManger *pTtlMgr, const STtlUpdCtimeCtx *pUpdCtimeCtx) {
|
||||
ttlMgrWLock(pTtlMgr);
|
||||
|
||||
int ret = 0;
|
||||
|
||||
STtlCacheEntry *oldData = taosHashGet(pTtlMgr->pTtlCache, &pUpdCtimeCtx->uid, sizeof(pUpdCtimeCtx->uid));
|
||||
|
@ -327,59 +349,35 @@ int ttlMgrUpdateChangeTime(STtlManger *pTtlMgr, const STtlUpdCtimeCtx *pUpdCtime
|
|||
goto _out;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
_out:
|
||||
ttlMgrULock(pTtlMgr);
|
||||
if (ttlMgrNeedFlush(pTtlMgr)) {
|
||||
ttlMgrFlush(pTtlMgr, pUpdCtimeCtx->pTxn);
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
_out:
|
||||
metaDebug("%s, ttl mgr update ctime, uid: %" PRId64 ", ctime: %" PRId64, pTtlMgr->logPrefix, pUpdCtimeCtx->uid,
|
||||
pUpdCtimeCtx->changeTimeMs);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ttlMgrFindExpired(STtlManger *pTtlMgr, int64_t timePointMs, SArray *pTbUids) {
|
||||
ttlMgrRLock(pTtlMgr);
|
||||
int ttlMgrFindExpired(STtlManger *pTtlMgr, int64_t timePointMs, SArray *pTbUids, int32_t ttlDropMaxCount) {
|
||||
STtlIdxKeyV1 ttlKey = {.deleteTimeMs = timePointMs, .uid = INT64_MAX};
|
||||
STtlExpiredCtx expiredCtx = {
|
||||
.ttlDropMaxCount = ttlDropMaxCount, .count = 0, .expiredKey = ttlKey, .pTbUids = pTbUids};
|
||||
return tdbTbTraversal(pTtlMgr->pTtlIdx, &expiredCtx, ttlMgrFindExpiredOneEntry);
|
||||
}
|
||||
|
||||
TBC *pCur;
|
||||
int ret = tdbTbcOpen(pTtlMgr->pTtlIdx, &pCur, NULL);
|
||||
if (ret < 0) {
|
||||
goto _out;
|
||||
}
|
||||
|
||||
STtlIdxKeyV1 ttlKey = {0};
|
||||
ttlKey.deleteTimeMs = timePointMs;
|
||||
ttlKey.uid = INT64_MAX;
|
||||
int c = 0;
|
||||
tdbTbcMoveTo(pCur, &ttlKey, sizeof(ttlKey), &c);
|
||||
if (c < 0) {
|
||||
tdbTbcMoveToPrev(pCur);
|
||||
}
|
||||
|
||||
void *pKey = NULL;
|
||||
int kLen = 0;
|
||||
while (1) {
|
||||
ret = tdbTbcPrev(pCur, &pKey, &kLen, NULL, NULL);
|
||||
if (ret < 0) {
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
ttlKey = *(STtlIdxKeyV1 *)pKey;
|
||||
taosArrayPush(pTbUids, &ttlKey.uid);
|
||||
}
|
||||
|
||||
tdbFree(pKey);
|
||||
tdbTbcClose(pCur);
|
||||
|
||||
ret = 0;
|
||||
_out:
|
||||
ttlMgrULock(pTtlMgr);
|
||||
return ret;
|
||||
static bool ttlMgrNeedFlush(STtlManger *pTtlMgr) {
|
||||
return pTtlMgr->flushThreshold > 0 && taosHashGetSize(pTtlMgr->pDirtyUids) > pTtlMgr->flushThreshold;
|
||||
}
|
||||
|
||||
int ttlMgrFlush(STtlManger *pTtlMgr, TXN *pTxn) {
|
||||
ttlMgrWLock(pTtlMgr);
|
||||
int64_t startNs = taosGetTimestampNs();
|
||||
int64_t endNs = startNs;
|
||||
|
||||
metaDebug("%s, ttl mgr flush start. dirty uids:%d", pTtlMgr->logPrefix, taosHashGetSize(pTtlMgr->pDirtyUids));
|
||||
metaTrace("%s, ttl mgr flush start. dirty uids:%d", pTtlMgr->logPrefix, taosHashGetSize(pTtlMgr->pDirtyUids));
|
||||
|
||||
int ret = -1;
|
||||
|
||||
|
@ -430,40 +428,10 @@ int ttlMgrFlush(STtlManger *pTtlMgr, TXN *pTxn) {
|
|||
taosHashClear(pTtlMgr->pDirtyUids);
|
||||
|
||||
ret = 0;
|
||||
|
||||
_out:
|
||||
ttlMgrULock(pTtlMgr);
|
||||
|
||||
metaDebug("%s, ttl mgr flush end.", pTtlMgr->logPrefix);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t ttlMgrRLock(STtlManger *pTtlMgr) {
|
||||
int32_t ret = 0;
|
||||
|
||||
metaTrace("%s, ttlMgr rlock %p", pTtlMgr->logPrefix, &pTtlMgr->lock);
|
||||
|
||||
ret = taosThreadRwlockRdlock(&pTtlMgr->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t ttlMgrWLock(STtlManger *pTtlMgr) {
|
||||
int32_t ret = 0;
|
||||
|
||||
metaTrace("%s, ttlMgr wlock %p", pTtlMgr->logPrefix, &pTtlMgr->lock);
|
||||
|
||||
ret = taosThreadRwlockWrlock(&pTtlMgr->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t ttlMgrULock(STtlManger *pTtlMgr) {
|
||||
int32_t ret = 0;
|
||||
|
||||
metaTrace("%s, ttlMgr ulock %p", pTtlMgr->logPrefix, &pTtlMgr->lock);
|
||||
|
||||
ret = taosThreadRwlockUnlock(&pTtlMgr->lock);
|
||||
endNs = taosGetTimestampNs();
|
||||
metaTrace("%s, ttl mgr flush end, time consumed: %" PRId64 " ns", pTtlMgr->logPrefix, endNs - startNs);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -1800,8 +1800,8 @@ int32_t tqProcessStreamCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg) {
|
|||
|
||||
// set the initial value for generating check point
|
||||
// set the mgmt epset info according to the checkout source msg from mnode, todo opt perf
|
||||
// pMeta->mgmtInfo.epset = req.mgmtEps;
|
||||
// pMeta->mgmtInfo.mnodeId = req.mnodeId;
|
||||
// pMeta->mgmtInfo.epset = req.mgmtEps;
|
||||
// pMeta->mgmtInfo.mnodeId = req.mnodeId;
|
||||
|
||||
if (pMeta->chkptNotReadyTasks == 0) {
|
||||
pMeta->chkptNotReadyTasks = taosArrayGetSize(pMeta->pTaskList);
|
||||
|
@ -1909,9 +1909,9 @@ int32_t tqProcessTaskUpdateReq(STQ* pTq, SRpcMsg* pMsg) {
|
|||
// all tasks are closed, now let's restart the stream meta
|
||||
if (pMeta->closedTask == numOfCount) {
|
||||
tqDebug("vgId:%d all tasks are updated, commit the update nodeInfo", vgId);
|
||||
// if (streamMetaCommit(pMeta) < 0) {
|
||||
// persist to disk
|
||||
// }
|
||||
// if (streamMetaCommit(pMeta) < 0) {
|
||||
// persist to disk
|
||||
// }
|
||||
restartTasks = true;
|
||||
pMeta->closedTask = 0; // reset value
|
||||
} else {
|
||||
|
@ -1922,7 +1922,7 @@ int32_t tqProcessTaskUpdateReq(STQ* pTq, SRpcMsg* pMsg) {
|
|||
|
||||
_end:
|
||||
tDecoderClear(&decoder);
|
||||
// tmsgSendRsp(&rsp);
|
||||
// tmsgSendRsp(&rsp);
|
||||
|
||||
if (restartTasks) {
|
||||
tqDebug("vgId:%d all tasks are stopped, restart them", vgId);
|
||||
|
|
|
@ -13,11 +13,11 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "vnd.h"
|
||||
#include "tq.h"
|
||||
#include "vnd.h"
|
||||
|
||||
static int32_t createStreamTaskRunReq(SStreamMeta* pStreamMeta, bool* pScanIdle);
|
||||
static int32_t doSetOffsetForWalReader(SStreamTask *pTask, int32_t vgId);
|
||||
static int32_t doSetOffsetForWalReader(SStreamTask* pTask, int32_t vgId);
|
||||
|
||||
// this function should be executed by stream threads.
|
||||
// extract submit block from WAL, and add them into the input queue for the sources tasks.
|
||||
|
@ -167,12 +167,12 @@ int32_t tqStartStreamTasks(STQ* pTq) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t doSetOffsetForWalReader(SStreamTask *pTask, int32_t vgId) {
|
||||
int32_t doSetOffsetForWalReader(SStreamTask* pTask, int32_t vgId) {
|
||||
// seek the stored version and extract data from WAL
|
||||
int64_t firstVer = walReaderGetValidFirstVer(pTask->exec.pWalReader);
|
||||
if (pTask->chkInfo.currentVer < firstVer) {
|
||||
tqWarn("vgId:%d s-task:%s ver:%"PRId64" earlier than the first ver of wal range %" PRId64 ", forward to %" PRId64, vgId,
|
||||
pTask->id.idStr, pTask->chkInfo.currentVer, firstVer, firstVer);
|
||||
tqWarn("vgId:%d s-task:%s ver:%" PRId64 " earlier than the first ver of wal range %" PRId64 ", forward to %" PRId64,
|
||||
vgId, pTask->id.idStr, pTask->chkInfo.currentVer, firstVer, firstVer);
|
||||
|
||||
pTask->chkInfo.currentVer = firstVer;
|
||||
|
||||
|
@ -193,7 +193,8 @@ int32_t doSetOffsetForWalReader(SStreamTask *pTask, int32_t vgId) {
|
|||
}
|
||||
|
||||
// append the data for the stream
|
||||
tqDebug("vgId:%d s-task:%s wal reader initial seek to ver:%" PRId64, vgId, pTask->id.idStr, pTask->chkInfo.currentVer);
|
||||
tqDebug("vgId:%d s-task:%s wal reader initial seek to ver:%" PRId64, vgId, pTask->id.idStr,
|
||||
pTask->chkInfo.currentVer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -223,7 +224,7 @@ static void checkForFillHistoryVerRange(SStreamTask* pTask, int64_t ver) {
|
|||
double el = (taosGetTimestampMs() - pTask->tsInfo.step2Start) / 1000.0;
|
||||
qDebug("s-task:%s scan-history from WAL stage(step 2) ended, elapsed time:%.2fs", id, el);
|
||||
appendTranstateIntoInputQ(pTask);
|
||||
/*int32_t code = */streamSchedExec(pTask);
|
||||
/*int32_t code = */ streamSchedExec(pTask);
|
||||
} else {
|
||||
qWarn("s-task:%s fill-history scan WAL, currentVer:%" PRId64 " reach the maximum ver:%" PRId64 ", not scan wal",
|
||||
id, ver, maxVer);
|
||||
|
@ -278,7 +279,7 @@ int32_t createStreamTaskRunReq(SStreamMeta* pStreamMeta, bool* pScanIdle) {
|
|||
ASSERT(status == TASK_STATUS__NORMAL);
|
||||
// the maximum version of data in the WAL has reached already, the step2 is done
|
||||
tqDebug("s-task:%s fill-history reach the maximum ver:%" PRId64 ", not scan wal anymore", pTask->id.idStr,
|
||||
pTask->dataRange.range.maxVer);
|
||||
pTask->dataRange.range.maxVer);
|
||||
streamMetaReleaseTask(pStreamMeta, pTask);
|
||||
continue;
|
||||
}
|
||||
|
@ -306,10 +307,10 @@ int32_t createStreamTaskRunReq(SStreamMeta* pStreamMeta, bool* pScanIdle) {
|
|||
}
|
||||
|
||||
int32_t numOfItems = streamTaskGetInputQItems(pTask);
|
||||
int64_t maxVer = (pTask->info.fillHistory == 1)? pTask->dataRange.range.maxVer:INT64_MAX;
|
||||
int64_t maxVer = (pTask->info.fillHistory == 1) ? pTask->dataRange.range.maxVer : INT64_MAX;
|
||||
|
||||
SStreamQueueItem* pItem = NULL;
|
||||
code = extractMsgFromWal(pTask->exec.pWalReader, (void**) &pItem, maxVer, pTask->id.idStr);
|
||||
code = extractMsgFromWal(pTask->exec.pWalReader, (void**)&pItem, maxVer, pTask->id.idStr);
|
||||
|
||||
if ((code != TSDB_CODE_SUCCESS || pItem == NULL) && (numOfItems == 0)) { // failed, continue
|
||||
checkForFillHistoryVerRange(pTask, walReaderGetCurrentVer(pTask->exec.pWalReader));
|
||||
|
@ -362,4 +363,3 @@ int32_t createStreamTaskRunReq(SStreamMeta* pStreamMeta, bool* pScanIdle) {
|
|||
taosArrayDestroy(pTaskList);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ int32_t tsdbOpenFile(const char *path, int32_t szPage, int32_t flag, STsdbFD **p
|
|||
pFD->flag = flag;
|
||||
pFD->pFD = taosOpenFile(path, flag);
|
||||
if (pFD->pFD == NULL) {
|
||||
int errsv = errno;
|
||||
const char *object_name = taosDirEntryBaseName((char *)path);
|
||||
long s3_size = s3Size(object_name);
|
||||
if (!strncmp(path + strlen(path) - 5, ".data", 5) && s3_size > 0) {
|
||||
|
@ -49,7 +50,7 @@ int32_t tsdbOpenFile(const char *path, int32_t szPage, int32_t flag, STsdbFD **p
|
|||
goto _exit;
|
||||
}
|
||||
} else {
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
code = TAOS_SYSTEM_ERROR(errsv);
|
||||
taosMemoryFree(pFD);
|
||||
goto _exit;
|
||||
}
|
||||
|
|
|
@ -141,6 +141,7 @@ int vnodeEncodeConfig(const void *pObj, SJson *pJson) {
|
|||
|
||||
if (tjsonAddIntegerToObject(pJson, "syncCfg.replicaNum", pCfg->syncCfg.replicaNum) < 0) return -1;
|
||||
if (tjsonAddIntegerToObject(pJson, "syncCfg.myIndex", pCfg->syncCfg.myIndex) < 0) return -1;
|
||||
if (tjsonAddIntegerToObject(pJson, "syncCfg.changeVersion", pCfg->syncCfg.changeVersion) < 0) return -1;
|
||||
|
||||
if (tjsonAddIntegerToObject(pJson, "vndStats.stables", pCfg->vndStats.numOfSTables) < 0) return -1;
|
||||
if (tjsonAddIntegerToObject(pJson, "vndStats.ctables", pCfg->vndStats.numOfCTables) < 0) return -1;
|
||||
|
@ -151,8 +152,9 @@ int vnodeEncodeConfig(const void *pObj, SJson *pJson) {
|
|||
SJson *nodeInfo = tjsonCreateArray();
|
||||
if (nodeInfo == NULL) return -1;
|
||||
if (tjsonAddItemToObject(pJson, "syncCfg.nodeInfo", nodeInfo) < 0) return -1;
|
||||
vDebug("vgId:%d, encode config, replicas:%d totalReplicas:%d selfIndex:%d", pCfg->vgId, pCfg->syncCfg.replicaNum,
|
||||
pCfg->syncCfg.totalReplicaNum, pCfg->syncCfg.myIndex);
|
||||
vDebug("vgId:%d, encode config, replicas:%d totalReplicas:%d selfIndex:%d changeVersion:%d",
|
||||
pCfg->vgId, pCfg->syncCfg.replicaNum,
|
||||
pCfg->syncCfg.totalReplicaNum, pCfg->syncCfg.myIndex, pCfg->syncCfg.changeVersion);
|
||||
for (int i = 0; i < pCfg->syncCfg.totalReplicaNum; ++i) {
|
||||
SJson *info = tjsonCreateObject();
|
||||
SNodeInfo *pNode = (SNodeInfo *)&pCfg->syncCfg.nodeInfo[i];
|
||||
|
@ -263,6 +265,8 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) {
|
|||
if (code < 0) return -1;
|
||||
tjsonGetNumberValue(pJson, "syncCfg.myIndex", pCfg->syncCfg.myIndex, code);
|
||||
if (code < 0) return -1;
|
||||
tjsonGetNumberValue(pJson, "syncCfg.changeVersion", pCfg->syncCfg.changeVersion, code);
|
||||
if (code < 0) return -1;
|
||||
|
||||
tjsonGetNumberValue(pJson, "vndStats.stables", pCfg->vndStats.numOfSTables, code);
|
||||
if (code < 0) return -1;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "vnd.h"
|
||||
#include "vnodeInt.h"
|
||||
#include "sync.h"
|
||||
|
||||
extern int32_t tsdbPreCommit(STsdb *pTsdb);
|
||||
extern int32_t tsdbCommitBegin(STsdb *pTsdb, SCommitInfo *pInfo);
|
||||
|
@ -200,8 +201,10 @@ int vnodeSaveInfo(const char *dir, const SVnodeInfo *pInfo) {
|
|||
// free info binary
|
||||
taosMemoryFree(data);
|
||||
|
||||
vInfo("vgId:%d, vnode info is saved, fname:%s replica:%d selfIndex:%d", pInfo->config.vgId, fname,
|
||||
pInfo->config.syncCfg.replicaNum, pInfo->config.syncCfg.myIndex);
|
||||
vInfo("vgId:%d, vnode info is saved, fname:%s replica:%d selfIndex:%d changeVersion:%d",
|
||||
pInfo->config.vgId, fname,
|
||||
pInfo->config.syncCfg.replicaNum, pInfo->config.syncCfg.myIndex,
|
||||
pInfo->config.syncCfg.changeVersion);
|
||||
|
||||
return 0;
|
||||
|
||||
|
@ -285,6 +288,8 @@ static int32_t vnodePrepareCommit(SVnode *pVnode, SCommitInfo *pInfo) {
|
|||
|
||||
tsem_wait(&pVnode->canCommit);
|
||||
|
||||
if(syncNodeGetConfig(pVnode->sync, &pVnode->config.syncCfg) != 0) goto _exit;
|
||||
|
||||
pVnode->state.commitTerm = pVnode->state.applyTerm;
|
||||
|
||||
pInfo->info.config = pVnode->config;
|
||||
|
|
|
@ -118,9 +118,10 @@ int32_t vnodeAlterReplica(const char *path, SAlterVnodeReplicaReq *pReq, int32_t
|
|||
if (pReq->learnerSelfIndex != -1) {
|
||||
pCfg->myIndex = pReq->replica + pReq->learnerSelfIndex;
|
||||
}
|
||||
pCfg->changeVersion = pReq->changeVersion;
|
||||
|
||||
vInfo("vgId:%d, save config while alter, replicas:%d totalReplicas:%d selfIndex:%d", pReq->vgId, pCfg->replicaNum,
|
||||
pCfg->totalReplicaNum, pCfg->myIndex);
|
||||
vInfo("vgId:%d, save config while alter, replicas:%d totalReplicas:%d selfIndex:%d changeVersion:%d",
|
||||
pReq->vgId, pCfg->replicaNum, pCfg->totalReplicaNum, pCfg->myIndex, pCfg->changeVersion);
|
||||
|
||||
info.config.syncCfg = *pCfg;
|
||||
ret = vnodeSaveInfo(dir, &info);
|
||||
|
@ -217,6 +218,7 @@ int32_t vnodeAlterHashRange(const char *srcPath, const char *dstPath, SAlterVnod
|
|||
info.config.hashEnd = pReq->hashEnd;
|
||||
info.config.hashChange = true;
|
||||
info.config.walCfg.vgId = pReq->dstVgId;
|
||||
info.config.syncCfg.changeVersion = pReq->changeVersion;
|
||||
|
||||
SSyncCfg *pCfg = &info.config.syncCfg;
|
||||
pCfg->myIndex = 0;
|
||||
|
@ -442,7 +444,8 @@ SVnode *vnodeOpen(const char *path, int32_t diskPrimary, STfs *pTfs, SMsgCb msgC
|
|||
}
|
||||
|
||||
// open sync
|
||||
if (vnodeSyncOpen(pVnode, dir)) {
|
||||
vInfo("vgId:%d, start to open sync, changeVersion:%d", TD_VID(pVnode), info.config.syncCfg.changeVersion);
|
||||
if (vnodeSyncOpen(pVnode, dir, info.config.syncCfg.changeVersion)) {
|
||||
vError("vgId:%d, failed to open sync since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
|
@ -474,8 +477,8 @@ _err:
|
|||
}
|
||||
|
||||
void vnodePreClose(SVnode *pVnode) {
|
||||
vnodeQueryPreClose(pVnode);
|
||||
vnodeSyncPreClose(pVnode);
|
||||
vnodeQueryPreClose(pVnode);
|
||||
}
|
||||
|
||||
void vnodePostClose(SVnode *pVnode) { vnodeSyncPostClose(pVnode); }
|
||||
|
|
|
@ -216,7 +216,7 @@ int vnodeGetTableCfg(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
|
|||
|
||||
cfgRsp.numOfTags = schemaTag.nCols;
|
||||
cfgRsp.numOfColumns = schema.nCols;
|
||||
cfgRsp.pSchemas = (SSchema *)taosMemoryCalloc(cfgRsp.numOfColumns + cfgRsp.numOfTags, sizeof(SSchema));
|
||||
cfgRsp.pSchemas = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * (cfgRsp.numOfColumns + cfgRsp.numOfTags));
|
||||
|
||||
memcpy(cfgRsp.pSchemas, schema.pSchema, sizeof(SSchema) * schema.nCols);
|
||||
if (schemaTag.nCols) {
|
||||
|
@ -384,6 +384,7 @@ int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
|
|||
pLoad->roleTimeMs = state.roleTimeMs;
|
||||
pLoad->startTimeMs = state.startTimeMs;
|
||||
pLoad->syncCanRead = state.canRead;
|
||||
pLoad->learnerProgress = state.progress;
|
||||
pLoad->cacheUsage = tsdbCacheGetUsage(pVnode);
|
||||
pLoad->numOfCachedTables = tsdbCacheGetElems(pVnode);
|
||||
pLoad->numOfTables = metaGetTbNum(pVnode->pMeta);
|
||||
|
|
|
@ -37,6 +37,7 @@ static int32_t vnodeProcessBatchDeleteReq(SVnode *pVnode, int64_t ver, void *pRe
|
|||
static int32_t vnodeProcessCreateIndexReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
static int32_t vnodeProcessDropIndexReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
static int32_t vnodeProcessCompactVnodeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
static int32_t vnodeProcessConfigChangeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
|
||||
static int32_t vnodePreprocessCreateTableReq(SVnode *pVnode, SDecoder *pCoder, int64_t btime, int64_t *pUid) {
|
||||
int32_t code = 0;
|
||||
|
@ -141,6 +142,74 @@ _exit:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t vnodePreProcessDropTtlMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||
int32_t code = TSDB_CODE_INVALID_MSG;
|
||||
int32_t lino = 0;
|
||||
|
||||
SMsgHead *pContOld = pMsg->pCont;
|
||||
int32_t reqLenOld = pMsg->contLen - sizeof(SMsgHead);
|
||||
|
||||
SArray *tbUids = NULL;
|
||||
int64_t timestampMs = 0;
|
||||
|
||||
SVDropTtlTableReq ttlReq = {0};
|
||||
if (tDeserializeSVDropTtlTableReq((char *)pContOld + sizeof(SMsgHead), reqLenOld, &ttlReq) != 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
{ // find expired uids
|
||||
tbUids = taosArrayInit(8, sizeof(int64_t));
|
||||
if (tbUids == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
timestampMs = (int64_t)ttlReq.timestampSec * 1000;
|
||||
code = metaTtlFindExpired(pVnode->pMeta, timestampMs, tbUids, ttlReq.ttlDropMaxCount);
|
||||
if (code != 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
ttlReq.nUids = taosArrayGetSize(tbUids);
|
||||
ttlReq.pTbUids = tbUids;
|
||||
}
|
||||
|
||||
{ // prepare new content
|
||||
int32_t reqLenNew = tSerializeSVDropTtlTableReq(NULL, 0, &ttlReq);
|
||||
int32_t contLenNew = reqLenNew + sizeof(SMsgHead);
|
||||
|
||||
SMsgHead *pContNew = rpcMallocCont(contLenNew);
|
||||
if (pContNew == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
tSerializeSVDropTtlTableReq((char *)pContNew + sizeof(SMsgHead), reqLenNew, &ttlReq);
|
||||
pContNew->contLen = htonl(reqLenNew);
|
||||
pContNew->vgId = pContOld->vgId;
|
||||
|
||||
rpcFreeCont(pContOld);
|
||||
pMsg->pCont = pContNew;
|
||||
pMsg->contLen = contLenNew;
|
||||
}
|
||||
|
||||
code = 0;
|
||||
|
||||
_exit:
|
||||
taosArrayDestroy(tbUids);
|
||||
|
||||
if (code) {
|
||||
vError("vgId:%d, %s:%d failed to preprocess drop ttl request since %s, msg type:%s", TD_VID(pVnode), __func__, lino,
|
||||
tstrerror(code), TMSG_INFO(pMsg->msgType));
|
||||
} else {
|
||||
vTrace("vgId:%d, %s done, timestampSec:%d, nUids:%d", TD_VID(pVnode), __func__, ttlReq.timestampSec, ttlReq.nUids);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
extern int64_t tsMaxKeyByPrecision[];
|
||||
static int32_t vnodePreProcessSubmitTbData(SVnode *pVnode, SDecoder *pCoder, int64_t btimeMs, int64_t ctimeMs) {
|
||||
int32_t code = 0;
|
||||
|
@ -370,6 +439,9 @@ int32_t vnodePreProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
|||
case TDMT_VND_ALTER_TABLE: {
|
||||
code = vnodePreProcessAlterTableMsg(pVnode, pMsg);
|
||||
} break;
|
||||
case TDMT_VND_DROP_TTL_TABLE: {
|
||||
code = vnodePreProcessDropTtlMsg(pVnode, pMsg);
|
||||
} break;
|
||||
case TDMT_VND_SUBMIT: {
|
||||
code = vnodePreProcessSubmitMsg(pVnode, pMsg);
|
||||
} break;
|
||||
|
@ -404,10 +476,13 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg
|
|||
return -1;
|
||||
}
|
||||
|
||||
vDebug("vgId:%d, start to process write request %s, index:%" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), ver);
|
||||
vDebug("vgId:%d, start to process write request %s, index:%" PRId64 ", applied:%" PRId64 ", state.applyTerm:%" PRId64
|
||||
", conn.applyTerm:%" PRId64,
|
||||
TD_VID(pVnode), TMSG_INFO(pMsg->msgType), ver, pVnode->state.applied, pVnode->state.applyTerm,
|
||||
pMsg->info.conn.applyTerm);
|
||||
|
||||
ASSERT(pVnode->state.applyTerm <= pMsg->info.conn.applyTerm);
|
||||
ASSERT(pVnode->state.applied + 1 == ver);
|
||||
ASSERTS(pVnode->state.applied + 1 == ver, "applied:%" PRId64 ", ver:%" PRId64, pVnode->state.applied, ver);
|
||||
|
||||
atomic_store_64(&pVnode->state.applied, ver);
|
||||
atomic_store_64(&pVnode->state.applyTerm, pMsg->info.conn.applyTerm);
|
||||
|
@ -532,6 +607,9 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg
|
|||
case TDMT_VND_COMPACT:
|
||||
vnodeProcessCompactVnodeReq(pVnode, ver, pReq, len, pRsp);
|
||||
goto _exit;
|
||||
case TDMT_SYNC_CONFIG_CHANGE:
|
||||
vnodeProcessConfigChangeReq(pVnode, ver, pReq, len, pRsp);
|
||||
break;
|
||||
default:
|
||||
vError("vgId:%d, unprocessed msg, %d", TD_VID(pVnode), pMsg->msgType);
|
||||
return -1;
|
||||
|
@ -728,28 +806,27 @@ _exit:
|
|||
}
|
||||
|
||||
static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
SArray *tbUids = taosArrayInit(8, sizeof(int64_t));
|
||||
if (tbUids == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
SVDropTtlTableReq ttlReq = {0};
|
||||
if (tDeserializeSVDropTtlTableReq(pReq, len, &ttlReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto end;
|
||||
}
|
||||
|
||||
vDebug("vgId:%d, drop ttl table req will be processed, time:%" PRId32, pVnode->config.vgId, ttlReq.timestampSec);
|
||||
int32_t ret = metaTtlDropTable(pVnode->pMeta, (int64_t)ttlReq.timestampSec * 1000, tbUids);
|
||||
if (ret != 0) {
|
||||
goto end;
|
||||
}
|
||||
if (taosArrayGetSize(tbUids) > 0) {
|
||||
tqUpdateTbUidList(pVnode->pTq, tbUids, false);
|
||||
ASSERT(ttlReq.nUids == taosArrayGetSize(ttlReq.pTbUids));
|
||||
|
||||
if (ttlReq.nUids != 0) {
|
||||
vInfo("vgId:%d, drop ttl table req will be processed, time:%d, ntbUids:%d", pVnode->config.vgId,
|
||||
ttlReq.timestampSec, ttlReq.nUids);
|
||||
}
|
||||
|
||||
vnodeDoRetention(pVnode, ttlReq.timestampSec);
|
||||
int ret = 0;
|
||||
if (ttlReq.nUids > 0) {
|
||||
metaDropTables(pVnode->pMeta, ttlReq.pTbUids);
|
||||
tqUpdateTbUidList(pVnode->pTq, ttlReq.pTbUids, false);
|
||||
}
|
||||
|
||||
end:
|
||||
taosArrayDestroy(tbUids);
|
||||
taosArrayDestroy(ttlReq.pTbUids);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1483,7 +1560,7 @@ static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t ver, void *pReq, in
|
|||
code = tsdbInsertTableData(pVnode->pTsdb, ver, pSubmitTbData, &affectedRows);
|
||||
if (code) goto _exit;
|
||||
|
||||
code = metaUpdateChangeTime(pVnode->pMeta, pSubmitTbData->uid, pSubmitTbData->ctimeMs);
|
||||
code = metaUpdateChangeTimeWithLock(pVnode->pMeta, pSubmitTbData->uid, pSubmitTbData->ctimeMs);
|
||||
if (code) goto _exit;
|
||||
|
||||
pSubmitRsp->affectedRows += affectedRows;
|
||||
|
@ -1740,7 +1817,7 @@ static int32_t vnodeProcessBatchDeleteReq(SVnode *pVnode, int64_t ver, void *pRe
|
|||
TD_VID(pVnode), terrstr(), deleteReq.suid, uid, pOneReq->startTs, pOneReq->endTs);
|
||||
}
|
||||
|
||||
code = metaUpdateChangeTime(pVnode->pMeta, uid, deleteReq.ctimeMs);
|
||||
code = metaUpdateChangeTimeWithLock(pVnode->pMeta, uid, deleteReq.ctimeMs);
|
||||
if (code < 0) {
|
||||
terrno = code;
|
||||
vError("vgId:%d, update change time error since %s, suid:%" PRId64 ", uid:%" PRId64 ", start ts:%" PRId64
|
||||
|
@ -1779,7 +1856,7 @@ static int32_t vnodeProcessDeleteReq(SVnode *pVnode, int64_t ver, void *pReq, in
|
|||
uint64_t uid = *(uint64_t *)taosArrayGet(pRes->uidList, iUid);
|
||||
code = tsdbDeleteTableData(pVnode->pTsdb, ver, pRes->suid, uid, pRes->skey, pRes->ekey);
|
||||
if (code) goto _err;
|
||||
code = metaUpdateChangeTime(pVnode->pMeta, uid, pRes->ctimeMs);
|
||||
code = metaUpdateChangeTimeWithLock(pVnode->pMeta, uid, pRes->ctimeMs);
|
||||
if (code) goto _err;
|
||||
}
|
||||
|
||||
|
@ -1850,6 +1927,17 @@ static int32_t vnodeProcessCompactVnodeReq(SVnode *pVnode, int64_t ver, void *pR
|
|||
return vnodeProcessCompactVnodeReqImpl(pVnode, ver, pReq, len, pRsp);
|
||||
}
|
||||
|
||||
static int32_t vnodeProcessConfigChangeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
syncCheckMember(pVnode->sync);
|
||||
|
||||
pRsp->msgType = TDMT_SYNC_CONFIG_CHANGE_RSP;
|
||||
pRsp->code = TSDB_CODE_SUCCESS;
|
||||
pRsp->pCont = NULL;
|
||||
pRsp->contLen = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef TD_ENTERPRISE
|
||||
int32_t vnodeProcessCompactVnodeReqImpl(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
return 0;
|
||||
|
|
|
@ -649,7 +649,7 @@ static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) {
|
|||
return pFsm;
|
||||
}
|
||||
|
||||
int32_t vnodeSyncOpen(SVnode *pVnode, char *path) {
|
||||
int32_t vnodeSyncOpen(SVnode *pVnode, char *path, int32_t vnodeVersion) {
|
||||
SSyncInfo syncInfo = {
|
||||
.snapshotStrategy = SYNC_STRATEGY_WAL_FIRST,
|
||||
.batchSize = 1,
|
||||
|
@ -676,7 +676,7 @@ int32_t vnodeSyncOpen(SVnode *pVnode, char *path) {
|
|||
pNode->nodePort, pNode->nodeId, pNode->clusterId);
|
||||
}
|
||||
|
||||
pVnode->sync = syncOpen(&syncInfo);
|
||||
pVnode->sync = syncOpen(&syncInfo, vnodeVersion);
|
||||
if (pVnode->sync <= 0) {
|
||||
vError("vgId:%d, failed to open sync since %s", pVnode->config.vgId, terrstr());
|
||||
return -1;
|
||||
|
|
|
@ -78,10 +78,6 @@ static int32_t buildDescResultDataBlock(SSDataBlock** pOutput) {
|
|||
infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, DESCRIBE_RESULT_NOTE_LEN, 4);
|
||||
code = blockDataAppendColInfo(pBlock, &infoData);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, DESCRIBE_RESULT_COL_COMMENT_LEN, 5);
|
||||
code = blockDataAppendColInfo(pBlock, &infoData);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pOutput = pBlock;
|
||||
|
@ -103,9 +99,7 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock,
|
|||
SColumnInfoData* pCol3 = taosArrayGet(pBlock->pDataBlock, 2);
|
||||
// Note
|
||||
SColumnInfoData* pCol4 = taosArrayGet(pBlock->pDataBlock, 3);
|
||||
// Comment
|
||||
SColumnInfoData* pCol5 = taosArrayGet(pBlock->pDataBlock, 4);
|
||||
char buf[DESCRIBE_RESULT_COL_COMMENT_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
char buf[DESCRIBE_RESULT_FIELD_LEN] = {0};
|
||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||
if (invisibleColumn(sysInfoUser, pMeta->tableType, pMeta->schema[i].flags)) {
|
||||
continue;
|
||||
|
@ -118,8 +112,6 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock,
|
|||
colDataSetVal(pCol3, pBlock->info.rows, (const char*)&bytes, false);
|
||||
STR_TO_VARSTR(buf, i >= pMeta->tableInfo.numOfColumns ? "TAG" : "");
|
||||
colDataSetVal(pCol4, pBlock->info.rows, buf, false);
|
||||
STR_TO_VARSTR(buf, pMeta->schema[i].comment);
|
||||
colDataSetVal(pCol5, pBlock->info.rows, buf, false);
|
||||
++(pBlock->info.rows);
|
||||
}
|
||||
if (pBlock->info.rows <= 0) {
|
||||
|
@ -464,19 +456,14 @@ void appendColumnFields(char* buf, int32_t* len, STableCfg* pCfg) {
|
|||
for (int32_t i = 0; i < pCfg->numOfColumns; ++i) {
|
||||
SSchema* pSchema = pCfg->pSchemas + i;
|
||||
char type[32];
|
||||
char comments[TSDB_COL_COMMENT_LEN + 16] = {0};
|
||||
sprintf(type, "%s", tDataTypes[pSchema->type].name);
|
||||
if (TSDB_DATA_TYPE_VARCHAR == pSchema->type || TSDB_DATA_TYPE_GEOMETRY == pSchema->type) {
|
||||
sprintf(type + strlen(type), "(%d)", (int32_t)(pSchema->bytes - VARSTR_HEADER_SIZE));
|
||||
} else if (TSDB_DATA_TYPE_NCHAR == pSchema->type) {
|
||||
sprintf(type + strlen(type), "(%d)", (int32_t)((pSchema->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE));
|
||||
}
|
||||
if (pSchema->comment[0]) {
|
||||
sprintf(comments, " COMMENT '%s'", pSchema->comment);
|
||||
}
|
||||
|
||||
*len +=
|
||||
sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s`%s` %s%s", ((i > 0) ? ", " : ""), pSchema->name, type, comments);
|
||||
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s`%s` %s", ((i > 0) ? ", " : ""), pSchema->name, type);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -484,18 +471,14 @@ void appendTagFields(char* buf, int32_t* len, STableCfg* pCfg) {
|
|||
for (int32_t i = 0; i < pCfg->numOfTags; ++i) {
|
||||
SSchema* pSchema = pCfg->pSchemas + pCfg->numOfColumns + i;
|
||||
char type[32];
|
||||
char comments[TSDB_COL_COMMENT_LEN + 16] = {0};
|
||||
sprintf(type, "%s", tDataTypes[pSchema->type].name);
|
||||
if (TSDB_DATA_TYPE_VARCHAR == pSchema->type || TSDB_DATA_TYPE_GEOMETRY == pSchema->type) {
|
||||
sprintf(type + strlen(type), "(%d)", (int32_t)(pSchema->bytes - VARSTR_HEADER_SIZE));
|
||||
} else if (TSDB_DATA_TYPE_NCHAR == pSchema->type) {
|
||||
sprintf(type + strlen(type), "(%d)", (int32_t)((pSchema->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE));
|
||||
}
|
||||
if (pSchema->comment[0]) {
|
||||
sprintf(comments, " COMMENT '%s'", pSchema->comment);
|
||||
}
|
||||
|
||||
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s`%s` %s%s", ((i > 0) ? ", " : ""), pSchema->name, type, comments);
|
||||
*len += sprintf(buf + VARSTR_HEADER_SIZE + *len, "%s`%s` %s", ((i > 0) ? ", " : ""), pSchema->name, type);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -173,7 +173,8 @@ SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNod
|
|||
SNode* createDropTableStmt(SAstCreateContext* pCxt, SNodeList* pTables);
|
||||
SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable);
|
||||
SNode* createAlterTableModifyOptions(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions);
|
||||
SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SNode* pColDefNode);
|
||||
SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SToken* pColName,
|
||||
SDataType dataType);
|
||||
SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SToken* pColName);
|
||||
SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SToken* pOldColName,
|
||||
SToken* pNewColName);
|
||||
|
|
|
@ -312,17 +312,17 @@ cmd ::= ALTER STABLE alter_table_clause(A).
|
|||
|
||||
alter_table_clause(A) ::= full_table_name(B) alter_table_options(C). { A = createAlterTableModifyOptions(pCxt, B, C); }
|
||||
alter_table_clause(A) ::=
|
||||
full_table_name(B) ADD COLUMN column_def(C). { A = createAlterTableAddModifyCol(pCxt, B, TSDB_ALTER_TABLE_ADD_COLUMN, C); }
|
||||
full_table_name(B) ADD COLUMN column_name(C) type_name(D). { A = createAlterTableAddModifyCol(pCxt, B, TSDB_ALTER_TABLE_ADD_COLUMN, &C, D); }
|
||||
alter_table_clause(A) ::= full_table_name(B) DROP COLUMN column_name(C). { A = createAlterTableDropCol(pCxt, B, TSDB_ALTER_TABLE_DROP_COLUMN, &C); }
|
||||
alter_table_clause(A) ::=
|
||||
full_table_name(B) MODIFY COLUMN column_def(C). { A = createAlterTableAddModifyCol(pCxt, B, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, C); }
|
||||
full_table_name(B) MODIFY COLUMN column_name(C) type_name(D). { A = createAlterTableAddModifyCol(pCxt, B, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &C, D); }
|
||||
alter_table_clause(A) ::=
|
||||
full_table_name(B) RENAME COLUMN column_name(C) column_name(D). { A = createAlterTableRenameCol(pCxt, B, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &C, &D); }
|
||||
alter_table_clause(A) ::=
|
||||
full_table_name(B) ADD TAG column_def(C). { A = createAlterTableAddModifyCol(pCxt, B, TSDB_ALTER_TABLE_ADD_TAG, C); }
|
||||
full_table_name(B) ADD TAG column_name(C) type_name(D). { A = createAlterTableAddModifyCol(pCxt, B, TSDB_ALTER_TABLE_ADD_TAG, &C, D); }
|
||||
alter_table_clause(A) ::= full_table_name(B) DROP TAG column_name(C). { A = createAlterTableDropCol(pCxt, B, TSDB_ALTER_TABLE_DROP_TAG, &C); }
|
||||
alter_table_clause(A) ::=
|
||||
full_table_name(B) MODIFY TAG column_def(C). { A = createAlterTableAddModifyCol(pCxt, B, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, C); }
|
||||
full_table_name(B) MODIFY TAG column_name(C) type_name(D). { A = createAlterTableAddModifyCol(pCxt, B, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &C, D); }
|
||||
alter_table_clause(A) ::=
|
||||
full_table_name(B) RENAME TAG column_name(C) column_name(D). { A = createAlterTableRenameCol(pCxt, B, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &C, &D); }
|
||||
alter_table_clause(A) ::=
|
||||
|
@ -358,7 +358,7 @@ column_def_list(A) ::= column_def(B).
|
|||
column_def_list(A) ::= column_def_list(B) NK_COMMA column_def(C). { A = addNodeToList(pCxt, B, C); }
|
||||
|
||||
column_def(A) ::= column_name(B) type_name(C). { A = createColumnDefNode(pCxt, &B, C, NULL); }
|
||||
column_def(A) ::= column_name(B) type_name(C) COMMENT NK_STRING(D). { A = createColumnDefNode(pCxt, &B, C, &D); }
|
||||
//column_def(A) ::= column_name(B) type_name(C) COMMENT NK_STRING(D). { A = createColumnDefNode(pCxt, &B, C, &D); }
|
||||
|
||||
%type type_name { SDataType }
|
||||
%destructor type_name { }
|
||||
|
|
|
@ -1457,15 +1457,17 @@ SNode* createAlterTableModifyOptions(SAstCreateContext* pCxt, SNode* pRealTable,
|
|||
return createAlterTableStmtFinalize(pRealTable, pStmt);
|
||||
}
|
||||
|
||||
SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SNode* pColDefNode) {
|
||||
SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SToken* pColName,
|
||||
SDataType dataType) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SColumnDefNode* pCol = (SColumnDefNode*)pColDefNode;
|
||||
if (!checkColumnName(pCxt, pColName)) {
|
||||
return NULL;
|
||||
}
|
||||
SAlterTableStmt* pStmt = (SAlterTableStmt*)nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->alterType = alterType;
|
||||
strcpy(pStmt->colName, pCol->colName);
|
||||
strcpy(pStmt->colComment, pCol->comments);
|
||||
pStmt->dataType = pCol->dataType;
|
||||
COPY_STRING_FORM_ID_TOKEN(pStmt->colName, pColName);
|
||||
pStmt->dataType = dataType;
|
||||
return createAlterTableStmtFinalize(pRealTable, pStmt);
|
||||
}
|
||||
|
||||
|
|
|
@ -4702,7 +4702,6 @@ static int32_t columnDefNodeToField(SNodeList* pList, SArray** pArray) {
|
|||
SColumnDefNode* pCol = (SColumnDefNode*)pNode;
|
||||
SField field = {.type = pCol->dataType.type, .bytes = calcTypeBytes(pCol->dataType)};
|
||||
strcpy(field.name, pCol->colName);
|
||||
strcpy(field.comment, pCol->comments);
|
||||
if (pCol->sma) {
|
||||
field.flags |= COL_SMA_ON;
|
||||
}
|
||||
|
@ -5050,7 +5049,6 @@ static void toSchema(const SColumnDefNode* pCol, col_id_t colId, SSchema* pSchem
|
|||
pSchema->bytes = calcTypeBytes(pCol->dataType);
|
||||
pSchema->flags = flags;
|
||||
strcpy(pSchema->name, pCol->colName);
|
||||
strcpy(pSchema->comment, pCol->comments);
|
||||
}
|
||||
|
||||
typedef struct SSampleAstInfo {
|
||||
|
@ -7699,10 +7697,6 @@ static int32_t extractDescribeResultSchema(int32_t* numOfCols, SSchema** pSchema
|
|||
(*pSchema)[3].bytes = DESCRIBE_RESULT_NOTE_LEN;
|
||||
strcpy((*pSchema)[3].name, "note");
|
||||
|
||||
(*pSchema)[4].type = TSDB_DATA_TYPE_BINARY;
|
||||
(*pSchema)[4].bytes = DESCRIBE_RESULT_COL_COMMENT_LEN;
|
||||
strcpy((*pSchema)[4].name, "comment");
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -8883,15 +8877,6 @@ static int32_t buildAddColReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, S
|
|||
pReq->type = pStmt->dataType.type;
|
||||
pReq->flags = COL_SMA_ON;
|
||||
pReq->bytes = calcTypeBytes(pStmt->dataType);
|
||||
if (pStmt->colComment[0]) {
|
||||
pReq->colComment = taosStrdup(pStmt->colComment);
|
||||
if (pReq->colComment == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pReq->colCommentLen = strlen(pReq->colComment);
|
||||
} else {
|
||||
pReq->colCommentLen = -1;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -8942,15 +8927,6 @@ static int32_t buildUpdateColReq(STranslateContext* pCxt, SAlterTableStmt* pStmt
|
|||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pReq->colId = pSchema->colId;
|
||||
if (pStmt->colComment[0]) {
|
||||
pReq->colComment = taosStrdup(pStmt->colComment);
|
||||
if (pReq->colComment == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pReq->colCommentLen = strlen(pReq->colComment);
|
||||
} else {
|
||||
pReq->colCommentLen = -1;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3192,7 +3192,7 @@ static bool stbJoinOptShouldBeOptimized(SLogicNode* pNode) {
|
|||
}
|
||||
|
||||
SJoinLogicNode* pJoin = (SJoinLogicNode*)pNode;
|
||||
if (pJoin->isSingleTableJoin || NULL == pJoin->pTagEqCond || pNode->pChildren->length != 2
|
||||
if (pJoin->isSingleTableJoin || NULL == pJoin->pTagEqCond || NULL != pJoin->pTagOnCond || pNode->pChildren->length != 2
|
||||
|| pJoin->hasSubQuery || pJoin->joinAlgo != JOIN_ALGO_UNKNOWN || pJoin->isLowLevelJoin) {
|
||||
if (pJoin->joinAlgo == JOIN_ALGO_UNKNOWN) {
|
||||
pJoin->joinAlgo = JOIN_ALGO_MERGE;
|
||||
|
|
|
@ -314,7 +314,6 @@ void qwFreeTaskCtx(SQWTaskCtx *ctx) {
|
|||
}
|
||||
|
||||
taosArrayDestroy(ctx->tbInfo);
|
||||
ctx->tbInfo = NULL;
|
||||
}
|
||||
|
||||
int32_t qwDropTaskCtx(QW_FPARAMS_DEF) {
|
||||
|
@ -341,6 +340,7 @@ int32_t qwDropTaskCtx(QW_FPARAMS_DEF) {
|
|||
}
|
||||
|
||||
qwFreeTaskCtx(&octx);
|
||||
ctx->tbInfo = NULL;
|
||||
|
||||
QW_TASK_DLOG_E("task ctx dropped");
|
||||
|
||||
|
|
|
@ -439,7 +439,7 @@ int32_t rebuildDirFromCheckpoint(const char* path, int64_t chkpId, char** dst) {
|
|||
if (code != 0) {
|
||||
qError("failed to restart stream backend from %s, reason: %s", chkp, tstrerror(TAOS_SYSTEM_ERROR(errno)));
|
||||
} else {
|
||||
qInfo("succ to restart stream backend at checkpoint path: %s", chkp);
|
||||
qInfo("start to restart stream backend at checkpoint path: %s", chkp);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -510,7 +510,11 @@ void* streamBackendInit(const char* streamPath, int64_t chkpId) {
|
|||
/*
|
||||
list all cf and get prefix
|
||||
*/
|
||||
streamStateOpenBackendCf(pHandle, (char*)backendPath, cfs, nCf);
|
||||
code = streamStateOpenBackendCf(pHandle, (char*)backendPath, cfs, nCf);
|
||||
if (code != 0) {
|
||||
rocksdb_list_column_families_destroy(cfs, nCf);
|
||||
goto _EXIT;
|
||||
}
|
||||
}
|
||||
if (cfs != NULL) {
|
||||
rocksdb_list_column_families_destroy(cfs, nCf);
|
||||
|
@ -545,16 +549,6 @@ void streamBackendCleanup(void* arg) {
|
|||
taosHashCleanup(pHandle->cfInst);
|
||||
|
||||
if (pHandle->db) {
|
||||
// char* err = NULL;
|
||||
// rocksdb_flushoptions_t* flushOpt = rocksdb_flushoptions_create();
|
||||
// rocksdb_flushoptions_set_wait(flushOpt, 1);
|
||||
// rocksdb_flush(pHandle->db, flushOpt, &err);
|
||||
|
||||
// if (err != NULL) {
|
||||
// qError("failed to flush db before streamBackend clean up, reason:%s", err);
|
||||
// taosMemoryFree(err);
|
||||
// }
|
||||
// rocksdb_flushoptions_destroy(flushOpt);
|
||||
rocksdb_close(pHandle->db);
|
||||
}
|
||||
rocksdb_options_destroy(pHandle->dbOpt);
|
||||
|
@ -1480,6 +1474,12 @@ int32_t streamStateOpenBackendCf(void* backend, char* name, char** cfs, int32_t
|
|||
if (err != NULL) {
|
||||
qError("failed to open rocksdb cf, reason:%s", err);
|
||||
taosMemoryFree(err);
|
||||
taosMemoryFree(cfHandle);
|
||||
taosMemoryFree(pCompare);
|
||||
taosMemoryFree(params);
|
||||
taosMemoryFree(cfOpts);
|
||||
// fix other leak
|
||||
return -1;
|
||||
} else {
|
||||
qDebug("succ to open rocksdb cf");
|
||||
}
|
||||
|
@ -2851,7 +2851,7 @@ int32_t streamStatePutBatch_rocksdb(SStreamState* pState, void* pBatch) {
|
|||
taosMemoryFree(err);
|
||||
return -1;
|
||||
} else {
|
||||
qDebug("write batch to backend opt: %p", wrapper->pBackend);
|
||||
qDebug("write batch to backend:%p", wrapper->pBackend);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -112,8 +112,10 @@ SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandF
|
|||
pMeta->streamBackend = streamBackendInit(pMeta->path, pMeta->chkpId);
|
||||
if (pMeta->streamBackend == NULL) {
|
||||
qError("vgId:%d failed to init stream backend", pMeta->vgId);
|
||||
qInfo("vgId:%d retry to init stream backend", pMeta->vgId);
|
||||
}
|
||||
}
|
||||
|
||||
// if (pMeta->streamBackend == NULL) {
|
||||
// goto _err;
|
||||
// }
|
||||
|
@ -177,6 +179,7 @@ int32_t streamMetaReopen(SStreamMeta* pMeta, int64_t chkpId) {
|
|||
pMeta->streamBackend = streamBackendInit(pMeta->path, pMeta->chkpId);
|
||||
if (pMeta->streamBackend == NULL) {
|
||||
qError("vgId:%d failed to init stream backend", pMeta->vgId);
|
||||
qInfo("vgId:%d retry to init stream backend", pMeta->vgId);
|
||||
// return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ void syncIndexMgrDestroy(SSyncIndexMgr *pIndexMgr);
|
|||
void syncIndexMgrClear(SSyncIndexMgr *pIndexMgr);
|
||||
void syncIndexMgrSetIndex(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId, SyncIndex index);
|
||||
SyncIndex syncIndexMgrGetIndex(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId);
|
||||
void syncIndexMgrCopyIfExist(SSyncIndexMgr * pNewIndex, SSyncIndexMgr * pOldIndex, SRaftId *oldReplicasId);
|
||||
|
||||
void syncIndexMgrSetStartTime(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId, int64_t startTime);
|
||||
int64_t syncIndexMgrGetStartTime(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId);
|
||||
|
|
|
@ -228,7 +228,7 @@ typedef struct SSyncNode {
|
|||
} SSyncNode;
|
||||
|
||||
// open/close --------------
|
||||
SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo);
|
||||
SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo, int32_t vnodeVersion);
|
||||
int32_t syncNodeStart(SSyncNode* pSyncNode);
|
||||
int32_t syncNodeStartStandBy(SSyncNode* pSyncNode);
|
||||
void syncNodeClose(SSyncNode* pSyncNode);
|
||||
|
@ -238,6 +238,9 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak, int
|
|||
int32_t syncNodeRestore(SSyncNode* pSyncNode);
|
||||
void syncHbTimerDataFree(SSyncHbTimerData* pData);
|
||||
|
||||
// config
|
||||
int32_t syncNodeChangeConfig(SSyncNode* ths, SSyncRaftEntry* pEntry, char* str);
|
||||
|
||||
// on message ---------------------
|
||||
int32_t syncNodeOnTimeout(SSyncNode* ths, const SRpcMsg* pMsg);
|
||||
int32_t syncNodeOnClientRequest(SSyncNode* ths, SRpcMsg* pMsg, SyncIndex* pRetIndex);
|
||||
|
|
|
@ -105,7 +105,7 @@ bool syncLogBufferIsEmpty(SSyncLogBuffer* pBuf);
|
|||
|
||||
int32_t syncLogBufferAppend(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEntry* pEntry);
|
||||
int32_t syncLogBufferAccept(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEntry* pEntry, SyncTerm prevTerm);
|
||||
int64_t syncLogBufferProceed(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncTerm* pMatchTerm);
|
||||
int64_t syncLogBufferProceed(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncTerm* pMatchTerm, char *str);
|
||||
int32_t syncLogBufferCommit(SSyncLogBuffer* pBuf, SSyncNode* pNode, int64_t commitIndex);
|
||||
int32_t syncLogBufferReset(SSyncLogBuffer* pBuf, SSyncNode* pNode);
|
||||
|
||||
|
@ -115,7 +115,7 @@ int32_t syncLogBufferValidate(SSyncLogBuffer* pBuf);
|
|||
int32_t syncLogBufferRollback(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncIndex toIndex);
|
||||
|
||||
int32_t syncFsmExecute(SSyncNode* pNode, SSyncFSM* pFsm, ESyncState role, SyncTerm term, SSyncRaftEntry* pEntry,
|
||||
int32_t applyCode);
|
||||
int32_t applyCode, bool force);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -46,7 +46,7 @@ void syncEntryDestroy(SSyncRaftEntry* pEntry);
|
|||
void syncEntry2OriginalRpc(const SSyncRaftEntry* pEntry, SRpcMsg* pRpcMsg); // step 7
|
||||
|
||||
static FORCE_INLINE bool syncLogReplBarrier(SSyncRaftEntry* pEntry) {
|
||||
return pEntry->originalRpcType == TDMT_SYNC_NOOP;
|
||||
return pEntry->originalRpcType == TDMT_SYNC_NOOP || pEntry->originalRpcType == TDMT_SYNC_CONFIG_CHANGE;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -151,8 +151,9 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
|||
}
|
||||
|
||||
sTrace("vgId:%d, recv append entries msg. index:%" PRId64 ", term:%" PRId64 ", preLogIndex:%" PRId64
|
||||
", prevLogTerm:%" PRId64 " commitIndex:%" PRId64 "",
|
||||
pMsg->vgId, pMsg->prevLogIndex + 1, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex);
|
||||
", prevLogTerm:%" PRId64 " commitIndex:%" PRId64 " entryterm:%" PRId64,
|
||||
pMsg->vgId, pMsg->prevLogIndex + 1, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex,
|
||||
pEntry->term);
|
||||
|
||||
// accept
|
||||
if (syncLogBufferAccept(ths->pLogBuf, ths, pEntry, pMsg->prevLogTerm) < 0) {
|
||||
|
@ -162,7 +163,7 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
|||
|
||||
_SEND_RESPONSE:
|
||||
pEntry = NULL;
|
||||
pReply->matchIndex = syncLogBufferProceed(ths->pLogBuf, ths, &pReply->lastMatchTerm);
|
||||
pReply->matchIndex = syncLogBufferProceed(ths->pLogBuf, ths, &pReply->lastMatchTerm, "OnAppn");
|
||||
bool matched = (pReply->matchIndex >= pReply->lastSendIndex);
|
||||
if (accepted && matched) {
|
||||
pReply->success = true;
|
||||
|
|
|
@ -70,6 +70,27 @@ void syncIndexMgrSetIndex(SSyncIndexMgr *pIndexMgr, const SRaftId *pRaftId, Sync
|
|||
DID(pRaftId), CID(pRaftId));
|
||||
}
|
||||
|
||||
void syncIndexMgrCopyIfExist(SSyncIndexMgr * pNewIndex, SSyncIndexMgr * pOldIndex, SRaftId *oldReplicasId){
|
||||
for(int j = 0; j < pOldIndex->totalReplicaNum; ++j){
|
||||
sDebug("old Index j:%d, index:%"PRId64, j, pOldIndex->index[j]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < pNewIndex->totalReplicaNum; ++i) {
|
||||
for(int j = 0; j < pOldIndex->totalReplicaNum; ++j){
|
||||
if (syncUtilSameId(/*(const SRaftId*)*/&((oldReplicasId[j])), &((*(pNewIndex->replicas))[i]))) {
|
||||
pNewIndex->index[i] = pOldIndex->index[j];
|
||||
pNewIndex->privateTerm[i] = pOldIndex->privateTerm[j];
|
||||
pNewIndex->startTimeArr[i] = pOldIndex->startTimeArr[j];
|
||||
pNewIndex->recvTimeArr[i] = pOldIndex->recvTimeArr[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < pNewIndex->totalReplicaNum; ++i){
|
||||
sDebug("new index i:%d, index:%"PRId64, i, pNewIndex->index[i]);
|
||||
}
|
||||
}
|
||||
|
||||
SSyncLogReplMgr *syncNodeGetLogReplMgr(SSyncNode *pNode, SRaftId *pRaftId) {
|
||||
for (int i = 0; i < pNode->totalReplicaNum; i++) {
|
||||
if (syncUtilSameId(&pNode->replicasId[i], pRaftId)) {
|
||||
|
|
|
@ -59,8 +59,8 @@ static int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftE
|
|||
|
||||
static ESyncStrategy syncNodeStrategy(SSyncNode* pSyncNode);
|
||||
|
||||
int64_t syncOpen(SSyncInfo* pSyncInfo) {
|
||||
SSyncNode* pSyncNode = syncNodeOpen(pSyncInfo);
|
||||
int64_t syncOpen(SSyncInfo* pSyncInfo, int32_t vnodeVersion) {
|
||||
SSyncNode* pSyncNode = syncNodeOpen(pSyncInfo, vnodeVersion);
|
||||
if (pSyncNode == NULL) {
|
||||
sError("vgId:%d, failed to open sync node", pSyncInfo->vgId);
|
||||
return -1;
|
||||
|
@ -106,6 +106,21 @@ _err:
|
|||
return -1;
|
||||
}
|
||||
|
||||
int32_t syncNodeGetConfig(int64_t rid, SSyncCfg *cfg){
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
|
||||
if (pSyncNode == NULL) {
|
||||
sError("failed to acquire rid:%" PRId64 " of tsNodeReftId for pSyncNode", rid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*cfg = pSyncNode->raftCfg.cfg;
|
||||
|
||||
syncNodeRelease(pSyncNode);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void syncStop(int64_t rid) {
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode != NULL) {
|
||||
|
@ -516,6 +531,20 @@ SSyncState syncGetState(int64_t rid) {
|
|||
} else {
|
||||
state.canRead = state.restored;
|
||||
}
|
||||
/*
|
||||
double progress = 0;
|
||||
if(pSyncNode->pLogBuf->totalIndex > 0 && pSyncNode->pLogBuf->commitIndex > 0){
|
||||
progress = (double)pSyncNode->pLogBuf->commitIndex/(double)pSyncNode->pLogBuf->totalIndex;
|
||||
state.progress = (int32_t)(progress * 100);
|
||||
}
|
||||
else{
|
||||
state.progress = -1;
|
||||
}
|
||||
sDebug("vgId:%d, learner progress state, commitIndex:%" PRId64 " totalIndex:%" PRId64 ", "
|
||||
"progress:%lf, progress:%d",
|
||||
pSyncNode->vgId,
|
||||
pSyncNode->pLogBuf->commitIndex, pSyncNode->pLogBuf->totalIndex, progress, state.progress);
|
||||
*/
|
||||
state.term = raftStoreGetTerm(pSyncNode);
|
||||
syncNodeRelease(pSyncNode);
|
||||
}
|
||||
|
@ -573,6 +602,20 @@ int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak, int64_t* seq) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
int32_t syncCheckMember(int64_t rid) {
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
sError("sync propose error");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(pSyncNode->myNodeInfo.nodeRole == TAOS_SYNC_ROLE_LEARNER){
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t syncIsCatchUp(int64_t rid) {
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
|
@ -634,15 +677,26 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak, int64_
|
|||
}
|
||||
|
||||
// optimized one replica
|
||||
if (syncNodeIsOptimizedOneReplica(pSyncNode, pMsg)) {
|
||||
if (syncNodeIsOptimizedOneReplica(pSyncNode, pMsg)) {
|
||||
SyncIndex retIndex;
|
||||
int32_t code = syncNodeOnClientRequest(pSyncNode, pMsg, &retIndex);
|
||||
if (code == 0) {
|
||||
if (code >= 0) {
|
||||
pMsg->info.conn.applyIndex = retIndex;
|
||||
pMsg->info.conn.applyTerm = raftStoreGetTerm(pSyncNode);
|
||||
sTrace("vgId:%d, propose optimized msg, index:%" PRId64 " type:%s", pSyncNode->vgId, retIndex,
|
||||
TMSG_INFO(pMsg->msgType));
|
||||
return 1;
|
||||
|
||||
//after raft member change, need to handle 1->2 switching point
|
||||
//at this point, need to switch entry handling thread
|
||||
if(pSyncNode->replicaNum == 1){
|
||||
sTrace("vgId:%d, propose optimized msg, index:%" PRId64 " type:%s", pSyncNode->vgId, retIndex,
|
||||
TMSG_INFO(pMsg->msgType));
|
||||
return 1;
|
||||
}
|
||||
else{
|
||||
sTrace("vgId:%d, propose optimized msg, return to normal, index:%" PRId64 " type:%s, "
|
||||
"handle:%p", pSyncNode->vgId, retIndex,
|
||||
TMSG_INFO(pMsg->msgType), pMsg->info.handle);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||
sError("vgId:%d, failed to propose optimized msg, index:%" PRId64 " type:%s", pSyncNode->vgId, retIndex,
|
||||
|
@ -742,7 +796,7 @@ int32_t syncNodeLogStoreRestoreOnNeed(SSyncNode* pNode) {
|
|||
}
|
||||
|
||||
// open/close --------------
|
||||
SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
|
||||
SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo, int32_t vnodeVersion) {
|
||||
SSyncNode* pSyncNode = taosMemoryCalloc(1, sizeof(SSyncNode));
|
||||
if (pSyncNode == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -784,20 +838,27 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
|
|||
goto _error;
|
||||
}
|
||||
|
||||
if (pSyncInfo->syncCfg.totalReplicaNum > 0 && syncIsConfigChanged(&pSyncNode->raftCfg.cfg, &pSyncInfo->syncCfg)) {
|
||||
sInfo("vgId:%d, use sync config from input options and write to cfg file", pSyncNode->vgId);
|
||||
pSyncNode->raftCfg.cfg = pSyncInfo->syncCfg;
|
||||
if (syncWriteCfgFile(pSyncNode) != 0) {
|
||||
sError("vgId:%d, failed to write sync cfg file", pSyncNode->vgId);
|
||||
goto _error;
|
||||
if(vnodeVersion > pSyncNode->raftCfg.cfg.changeVersion){
|
||||
if (pSyncInfo->syncCfg.totalReplicaNum > 0 && syncIsConfigChanged(&pSyncNode->raftCfg.cfg, &pSyncInfo->syncCfg)) {
|
||||
sInfo("vgId:%d, use sync config from input options and write to cfg file", pSyncNode->vgId);
|
||||
pSyncNode->raftCfg.cfg = pSyncInfo->syncCfg;
|
||||
if (syncWriteCfgFile(pSyncNode) != 0) {
|
||||
sError("vgId:%d, failed to write sync cfg file", pSyncNode->vgId);
|
||||
goto _error;
|
||||
}
|
||||
} else {
|
||||
sInfo("vgId:%d, use sync config from sync cfg file", pSyncNode->vgId);
|
||||
pSyncInfo->syncCfg = pSyncNode->raftCfg.cfg;
|
||||
}
|
||||
} else {
|
||||
sInfo("vgId:%d, use sync config from sync cfg file", pSyncNode->vgId);
|
||||
pSyncInfo->syncCfg = pSyncNode->raftCfg.cfg;
|
||||
}
|
||||
else{
|
||||
sInfo("vgId:%d, skip save sync cfg file since request ver:%d <= file ver:%d",
|
||||
pSyncNode->vgId, vnodeVersion, pSyncInfo->syncCfg.changeVersion);
|
||||
}
|
||||
}
|
||||
|
||||
// init by SSyncInfo
|
||||
|
||||
// init by SSyncInfo
|
||||
pSyncNode->vgId = pSyncInfo->vgId;
|
||||
SSyncCfg* pCfg = &pSyncNode->raftCfg.cfg;
|
||||
bool updated = false;
|
||||
|
@ -812,14 +873,16 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
|
|||
pNode->nodeId, pNode->clusterId);
|
||||
}
|
||||
|
||||
if (updated) {
|
||||
sInfo("vgId:%d, save config info since dnode info changed", pSyncNode->vgId);
|
||||
if (syncWriteCfgFile(pSyncNode) != 0) {
|
||||
sError("vgId:%d, failed to write sync cfg file on dnode info updated", pSyncNode->vgId);
|
||||
goto _error;
|
||||
if(vnodeVersion > pSyncInfo->syncCfg.changeVersion){
|
||||
if (updated) {
|
||||
sInfo("vgId:%d, save config info since dnode info changed", pSyncNode->vgId);
|
||||
if (syncWriteCfgFile(pSyncNode) != 0) {
|
||||
sError("vgId:%d, failed to write sync cfg file on dnode info updated", pSyncNode->vgId);
|
||||
goto _error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pSyncNode->pWal = pSyncInfo->pWal;
|
||||
pSyncNode->msgcb = pSyncInfo->msgcb;
|
||||
pSyncNode->syncSendMSg = pSyncInfo->syncSendMSg;
|
||||
|
@ -2256,6 +2319,540 @@ int32_t syncCacheEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry, LRUHand
|
|||
return code;
|
||||
}
|
||||
|
||||
void syncBuildConfigFromReq(SAlterVnodeReplicaReq *pReq, SSyncCfg *cfg){//TODO SAlterVnodeReplicaReq name is proper?
|
||||
cfg->replicaNum = 0;
|
||||
cfg->totalReplicaNum = 0;
|
||||
|
||||
for (int i = 0; i < pReq->replica; ++i) {
|
||||
SNodeInfo *pNode = &cfg->nodeInfo[i];
|
||||
pNode->nodeId = pReq->replicas[i].id;
|
||||
pNode->nodePort = pReq->replicas[i].port;
|
||||
tstrncpy(pNode->nodeFqdn, pReq->replicas[i].fqdn, sizeof(pNode->nodeFqdn));
|
||||
pNode->nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
(void)tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort);
|
||||
sInfo("vgId:%d, replica:%d ep:%s:%u dnode:%d nodeRole:%d", pReq->vgId, i, pNode->nodeFqdn, pNode->nodePort, pNode->nodeId, pNode->nodeRole);
|
||||
cfg->replicaNum++;
|
||||
}
|
||||
if(pReq->selfIndex != -1){
|
||||
cfg->myIndex = pReq->selfIndex;
|
||||
}
|
||||
for (int i = cfg->replicaNum; i < pReq->replica + pReq->learnerReplica; ++i) {
|
||||
SNodeInfo *pNode = &cfg->nodeInfo[i];
|
||||
pNode->nodeId = pReq->learnerReplicas[cfg->totalReplicaNum].id;
|
||||
pNode->nodePort = pReq->learnerReplicas[cfg->totalReplicaNum].port;
|
||||
pNode->nodeRole = TAOS_SYNC_ROLE_LEARNER;
|
||||
tstrncpy(pNode->nodeFqdn, pReq->learnerReplicas[cfg->totalReplicaNum].fqdn, sizeof(pNode->nodeFqdn));
|
||||
(void)tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort);
|
||||
sInfo("vgId:%d, replica:%d ep:%s:%u dnode:%d nodeRole:%d", pReq->vgId, i, pNode->nodeFqdn, pNode->nodePort, pNode->nodeId, pNode->nodeRole);
|
||||
cfg->totalReplicaNum++;
|
||||
}
|
||||
cfg->totalReplicaNum += pReq->replica;
|
||||
if(pReq->learnerSelfIndex != -1){
|
||||
cfg->myIndex = pReq->replica + pReq->learnerSelfIndex;
|
||||
}
|
||||
cfg->changeVersion = pReq->changeVersion;
|
||||
}
|
||||
|
||||
int32_t syncNodeCheckChangeConfig(SSyncNode* ths, SSyncRaftEntry* pEntry){
|
||||
if(pEntry->originalRpcType != TDMT_SYNC_CONFIG_CHANGE){
|
||||
return -1;
|
||||
}
|
||||
|
||||
SMsgHead *head = (SMsgHead *)pEntry->data;
|
||||
void *pReq = POINTER_SHIFT(head, sizeof(SMsgHead));
|
||||
|
||||
SAlterVnodeTypeReq req = {0};
|
||||
if (tDeserializeSAlterVnodeReplicaReq(pReq, head->contLen, &req) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
SSyncCfg cfg = {0};
|
||||
syncBuildConfigFromReq(&req, &cfg);
|
||||
|
||||
if(cfg.totalReplicaNum >= 1 && ths->state == TAOS_SYNC_STATE_LEADER){
|
||||
bool incfg = false;
|
||||
for(int32_t j = 0; j < cfg.totalReplicaNum; ++j){
|
||||
if(strcmp(ths->myNodeInfo.nodeFqdn, cfg.nodeInfo[j].nodeFqdn) == 0
|
||||
&& ths->myNodeInfo.nodePort == cfg.nodeInfo[j].nodePort){
|
||||
incfg = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!incfg){
|
||||
SyncTerm currentTerm = raftStoreGetTerm(ths);
|
||||
syncNodeStepDown(ths, currentTerm);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void syncNodeLogConfigInfo(SSyncNode* ths, SSyncCfg *cfg, char *str){
|
||||
sInfo("vgId:%d, %s. SyncNode, replicaNum:%d, peersNum:%d, lastConfigIndex:%" PRId64 ", changeVersion:%d, "
|
||||
"restoreFinish:%d",
|
||||
ths->vgId, str,
|
||||
ths->replicaNum, ths->peersNum, ths->raftCfg.lastConfigIndex, ths->raftCfg.cfg.changeVersion,
|
||||
ths->restoreFinish);
|
||||
|
||||
sInfo("vgId:%d, %s, myNodeInfo, clusterId:%" PRId64 ", nodeId:%d, Fqdn:%s, port:%d, role:%d",
|
||||
ths->vgId, str, ths->myNodeInfo.clusterId, ths->myNodeInfo.nodeId, ths->myNodeInfo.nodeFqdn,
|
||||
ths->myNodeInfo.nodePort, ths->myNodeInfo.nodeRole);
|
||||
|
||||
for (int32_t i = 0; i < ths->peersNum; ++i){
|
||||
sInfo("vgId:%d, %s, peersNodeInfo%d, clusterId:%" PRId64 ", nodeId:%d, Fqdn:%s, port:%d, role:%d",
|
||||
ths->vgId, str, i, ths->peersNodeInfo[i].clusterId,
|
||||
ths->peersNodeInfo[i].nodeId, ths->peersNodeInfo[i].nodeFqdn,
|
||||
ths->peersNodeInfo[i].nodePort, ths->peersNodeInfo[i].nodeRole);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < ths->peersNum; ++i){
|
||||
char buf[256];
|
||||
int32_t len = 256;
|
||||
int32_t n = 0;
|
||||
n += snprintf(buf + n, len - n, "%s", "{");
|
||||
for (int i = 0; i < ths->peersEpset->numOfEps; i++) {
|
||||
n += snprintf(buf + n, len - n, "%s:%d%s", ths->peersEpset->eps[i].fqdn, ths->peersEpset->eps[i].port,
|
||||
(i + 1 < ths->peersEpset->numOfEps ? ", " : ""));
|
||||
}
|
||||
n += snprintf(buf + n, len - n, "%s", "}");
|
||||
|
||||
sInfo("vgId:%d, %s, peersEpset%d, %s, inUse:%d",
|
||||
ths->vgId, str, i, buf, ths->peersEpset->inUse);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < ths->peersNum; ++i){
|
||||
sInfo("vgId:%d, %s, peersId%d, addr:%"PRId64,
|
||||
ths->vgId, str, i, ths->peersId[i].addr);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < ths->raftCfg.cfg.totalReplicaNum; ++i){
|
||||
sInfo("vgId:%d, %s, nodeInfo%d, clusterId:%" PRId64 ", nodeId:%d, Fqdn:%s, port:%d, role:%d",
|
||||
ths->vgId, str, i, ths->raftCfg.cfg.nodeInfo[i].clusterId,
|
||||
ths->raftCfg.cfg.nodeInfo[i].nodeId, ths->raftCfg.cfg.nodeInfo[i].nodeFqdn,
|
||||
ths->raftCfg.cfg.nodeInfo[i].nodePort, ths->raftCfg.cfg.nodeInfo[i].nodeRole);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < ths->raftCfg.cfg.totalReplicaNum; ++i){
|
||||
sInfo("vgId:%d, %s, replicasId%d, addr:%" PRId64,
|
||||
ths->vgId, str, i, ths->replicasId[i].addr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int32_t syncNodeRebuildPeerAndCfg(SSyncNode* ths, SSyncCfg *cfg){
|
||||
int32_t i = 0;
|
||||
|
||||
//change peersNodeInfo
|
||||
i = 0;
|
||||
for(int32_t j = 0; j < cfg->totalReplicaNum; ++j){
|
||||
if(!(strcmp(ths->myNodeInfo.nodeFqdn, cfg->nodeInfo[j].nodeFqdn) == 0
|
||||
&& ths->myNodeInfo.nodePort == cfg->nodeInfo[j].nodePort)){
|
||||
ths->peersNodeInfo[i].nodeRole = cfg->nodeInfo[j].nodeRole;
|
||||
ths->peersNodeInfo[i].clusterId = cfg->nodeInfo[j].clusterId;
|
||||
tstrncpy(ths->peersNodeInfo[i].nodeFqdn, cfg->nodeInfo[j].nodeFqdn, TSDB_FQDN_LEN);
|
||||
ths->peersNodeInfo[i].nodeId = cfg->nodeInfo[j].nodeId;
|
||||
ths->peersNodeInfo[i].nodePort = cfg->nodeInfo[j].nodePort;
|
||||
|
||||
syncUtilNodeInfo2EpSet(&ths->peersNodeInfo[i], &ths->peersEpset[i]);
|
||||
|
||||
if (!syncUtilNodeInfo2RaftId(&ths->peersNodeInfo[i], ths->vgId, &ths->peersId[i])) {
|
||||
sError("vgId:%d, failed to determine raft member id, peer:%d", ths->vgId, i);
|
||||
return -1;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
ths->peersNum = i;
|
||||
|
||||
//change cfg nodeInfo
|
||||
ths->raftCfg.cfg.replicaNum = 0;
|
||||
i = 0;
|
||||
for(int32_t j = 0; j < cfg->totalReplicaNum; ++j) {
|
||||
if(cfg->nodeInfo[j].nodeRole == TAOS_SYNC_ROLE_VOTER){
|
||||
ths->raftCfg.cfg.replicaNum++;
|
||||
}
|
||||
ths->raftCfg.cfg.nodeInfo[i].nodeRole = cfg->nodeInfo[j].nodeRole;
|
||||
ths->raftCfg.cfg.nodeInfo[i].clusterId = cfg->nodeInfo[j].clusterId;
|
||||
tstrncpy(ths->raftCfg.cfg.nodeInfo[i].nodeFqdn, cfg->nodeInfo[j].nodeFqdn, TSDB_FQDN_LEN);
|
||||
ths->raftCfg.cfg.nodeInfo[i].nodeId = cfg->nodeInfo[j].nodeId;
|
||||
ths->raftCfg.cfg.nodeInfo[i].nodePort = cfg->nodeInfo[j].nodePort;
|
||||
if((strcmp(ths->myNodeInfo.nodeFqdn, cfg->nodeInfo[j].nodeFqdn) == 0
|
||||
&& ths->myNodeInfo.nodePort == cfg->nodeInfo[j].nodePort)){
|
||||
ths->raftCfg.cfg.myIndex = i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
ths->raftCfg.cfg.totalReplicaNum = i;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void syncNodeChangePeerAndCfgToVoter(SSyncNode* ths, SSyncCfg *cfg){
|
||||
//change peersNodeInfo
|
||||
for (int32_t i = 0; i < ths->peersNum; ++i) {
|
||||
for(int32_t j = 0; j < cfg->totalReplicaNum; ++j){
|
||||
if(strcmp(ths->peersNodeInfo[i].nodeFqdn, cfg->nodeInfo[j].nodeFqdn) == 0
|
||||
&& ths->peersNodeInfo[i].nodePort == cfg->nodeInfo[j].nodePort){
|
||||
if(cfg->nodeInfo[j].nodeRole == TAOS_SYNC_ROLE_VOTER){
|
||||
ths->peersNodeInfo[i].nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//change cfg nodeInfo
|
||||
ths->raftCfg.cfg.replicaNum = 0;
|
||||
for (int32_t i = 0; i < ths->raftCfg.cfg.totalReplicaNum; ++i) {
|
||||
for(int32_t j = 0; j < cfg->totalReplicaNum; ++j){
|
||||
if(strcmp(ths->raftCfg.cfg.nodeInfo[i].nodeFqdn, cfg->nodeInfo[j].nodeFqdn) == 0
|
||||
&& ths->raftCfg.cfg.nodeInfo[i].nodePort == cfg->nodeInfo[j].nodePort){
|
||||
if(cfg->nodeInfo[j].nodeRole == TAOS_SYNC_ROLE_VOTER){
|
||||
ths->raftCfg.cfg.nodeInfo[i].nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
ths->raftCfg.cfg.replicaNum++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t syncNodeRebuildAndCopyIfExist(SSyncNode* ths, int32_t oldtotalReplicaNum){
|
||||
//1.rebuild replicasId, remove deleted one
|
||||
SRaftId oldReplicasId[TSDB_MAX_REPLICA + TSDB_MAX_LEARNER_REPLICA];
|
||||
memcpy(oldReplicasId, ths->replicasId, sizeof(oldReplicasId));
|
||||
|
||||
ths->replicaNum = ths->raftCfg.cfg.replicaNum;
|
||||
ths->totalReplicaNum = ths->raftCfg.cfg.totalReplicaNum;
|
||||
for (int32_t i = 0; i < ths->raftCfg.cfg.totalReplicaNum; ++i) {
|
||||
syncUtilNodeInfo2RaftId(&ths->raftCfg.cfg.nodeInfo[i], ths->vgId, &ths->replicasId[i]);
|
||||
}
|
||||
|
||||
|
||||
//2.rebuild MatchIndex, remove deleted one
|
||||
SSyncIndexMgr *oldIndex = ths->pMatchIndex;
|
||||
|
||||
ths->pMatchIndex = syncIndexMgrCreate(ths);
|
||||
|
||||
syncIndexMgrCopyIfExist(ths->pMatchIndex, oldIndex, oldReplicasId);
|
||||
|
||||
syncIndexMgrDestroy(oldIndex);
|
||||
|
||||
|
||||
//3.rebuild NextIndex, remove deleted one
|
||||
SSyncIndexMgr *oldNextIndex = ths->pNextIndex;
|
||||
|
||||
ths->pNextIndex = syncIndexMgrCreate(ths);
|
||||
|
||||
syncIndexMgrCopyIfExist(ths->pNextIndex, oldNextIndex, oldReplicasId);
|
||||
|
||||
syncIndexMgrDestroy(oldNextIndex);
|
||||
|
||||
|
||||
//4.rebuild pVotesGranted, pVotesRespond, no need to keep old vote state, only rebuild
|
||||
voteGrantedUpdate(ths->pVotesGranted, ths);
|
||||
votesRespondUpdate(ths->pVotesRespond, ths);
|
||||
|
||||
|
||||
//5.rebuild logReplMgr
|
||||
for(int i = 0; i < oldtotalReplicaNum; ++i){
|
||||
sDebug("vgId:%d, old logReplMgrs i:%d, peerId:%d, restoreed:%d, [%" PRId64 " %" PRId64 ", %" PRId64 ")", ths->vgId, i,
|
||||
ths->logReplMgrs[i]->peerId, ths->logReplMgrs[i]->restored, ths->logReplMgrs[i]->startIndex,
|
||||
ths->logReplMgrs[i]->matchIndex, ths->logReplMgrs[i]->endIndex);
|
||||
}
|
||||
|
||||
SSyncLogReplMgr oldLogReplMgrs[TSDB_MAX_REPLICA + TSDB_MAX_LEARNER_REPLICA] = {0};
|
||||
|
||||
for(int i = 0; i < oldtotalReplicaNum; i++){
|
||||
oldLogReplMgrs[i] = *(ths->logReplMgrs[i]);
|
||||
}
|
||||
|
||||
syncNodeLogReplDestroy(ths);
|
||||
syncNodeLogReplInit(ths);
|
||||
|
||||
for(int i = 0; i < ths->totalReplicaNum; ++i){
|
||||
for(int j = 0; j < oldtotalReplicaNum; j++){
|
||||
if (syncUtilSameId(&ths->replicasId[i], &oldReplicasId[j])) {
|
||||
*(ths->logReplMgrs[i]) = oldLogReplMgrs[j];
|
||||
ths->logReplMgrs[i]->peerId = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < ths->totalReplicaNum; ++i){
|
||||
sDebug("vgId:%d, new logReplMgrs i:%d, peerId:%d, restoreed:%d, [%" PRId64 " %" PRId64 ", %" PRId64 ")" , ths->vgId, i,
|
||||
ths->logReplMgrs[i]->peerId, ths->logReplMgrs[i]->restored, ths->logReplMgrs[i]->startIndex,
|
||||
ths->logReplMgrs[i]->matchIndex, ths->logReplMgrs[i]->endIndex);
|
||||
}
|
||||
|
||||
//6.rebuild sender
|
||||
for(int i = 0; i < oldtotalReplicaNum; ++i){
|
||||
sDebug("vgId:%d, old sender i:%d, replicaIndex:%d, lastSendTime:%" PRId64,
|
||||
ths->vgId, i, ths->senders[i]->replicaIndex, ths->senders[i]->lastSendTime)
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < TSDB_MAX_REPLICA + TSDB_MAX_LEARNER_REPLICA; ++i) {
|
||||
if (ths->senders[i] != NULL) {
|
||||
sDebug("vgId:%d, snapshot sender destroy while close, data:%p", ths->vgId, ths->senders[i]);
|
||||
|
||||
if (snapshotSenderIsStart(ths->senders[i])) {
|
||||
snapshotSenderStop(ths->senders[i], false);
|
||||
}
|
||||
|
||||
snapshotSenderDestroy(ths->senders[i]);
|
||||
ths->senders[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < TSDB_MAX_REPLICA + TSDB_MAX_LEARNER_REPLICA; ++i) {
|
||||
SSyncSnapshotSender* pSender = snapshotSenderCreate(ths, i);
|
||||
if (pSender == NULL) return -1;
|
||||
|
||||
ths->senders[i] = pSender;
|
||||
sSDebug(pSender, "snapshot sender create while open sync node, data:%p", pSender);
|
||||
}
|
||||
|
||||
for(int i = 0; i < ths->totalReplicaNum; i++){
|
||||
sDebug("vgId:%d, new sender i:%d, replicaIndex:%d, lastSendTime:%" PRId64,
|
||||
ths->vgId, i, ths->senders[i]->replicaIndex, ths->senders[i]->lastSendTime)
|
||||
}
|
||||
|
||||
|
||||
//7.rebuild synctimer
|
||||
syncNodeStopHeartbeatTimer(ths);
|
||||
|
||||
for (int32_t i = 0; i < TSDB_MAX_REPLICA + TSDB_MAX_LEARNER_REPLICA; ++i) {
|
||||
syncHbTimerInit(ths, &ths->peerHeartbeatTimerArr[i], ths->replicasId[i]);
|
||||
}
|
||||
|
||||
syncNodeStartHeartbeatTimer(ths);
|
||||
|
||||
|
||||
//8.rebuild peerStates
|
||||
SPeerState oldState[TSDB_MAX_REPLICA + TSDB_MAX_LEARNER_REPLICA] = {0};
|
||||
for(int i = 0; i < TSDB_MAX_REPLICA + TSDB_MAX_LEARNER_REPLICA; i++){
|
||||
oldState[i] = ths->peerStates[i];
|
||||
}
|
||||
|
||||
for(int i = 0; i < ths->totalReplicaNum; i++){
|
||||
for(int j = 0; j < oldtotalReplicaNum; j++){
|
||||
if (syncUtilSameId(&ths->replicasId[i], &oldReplicasId[j])){
|
||||
ths->peerStates[i] = oldState[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void syncNodeChangeToVoter(SSyncNode* ths){
|
||||
//replicasId, only need to change replicaNum when 1->3
|
||||
ths->replicaNum = ths->raftCfg.cfg.replicaNum;
|
||||
sDebug("vgId:%d, totalReplicaNum:%d", ths->vgId, ths->totalReplicaNum);
|
||||
for (int32_t i = 0; i < ths->totalReplicaNum; ++i){
|
||||
sDebug("vgId:%d, i:%d, replicaId.addr:%" PRIx64, ths->vgId, i, ths->replicasId[i].addr);
|
||||
}
|
||||
|
||||
//pMatchIndex, pNextIndex, only need to change replicaNum when 1->3
|
||||
ths->pMatchIndex->replicaNum = ths->raftCfg.cfg.replicaNum;
|
||||
ths->pNextIndex->replicaNum = ths->raftCfg.cfg.replicaNum;
|
||||
|
||||
sDebug("vgId:%d, pMatchIndex->totalReplicaNum:%d", ths->vgId, ths->pMatchIndex->totalReplicaNum);
|
||||
for (int32_t i = 0; i < ths->pMatchIndex->totalReplicaNum; ++i){
|
||||
sDebug("vgId:%d, i:%d, match.index:%" PRId64, ths->vgId, i, ths->pMatchIndex->index[i]);
|
||||
}
|
||||
|
||||
//pVotesGranted, pVotesRespond
|
||||
voteGrantedUpdate(ths->pVotesGranted, ths);
|
||||
votesRespondUpdate(ths->pVotesRespond, ths);
|
||||
|
||||
//logRepMgrs
|
||||
//no need to change logRepMgrs when 1->3
|
||||
}
|
||||
|
||||
void syncNodeResetPeerAndCfg(SSyncNode* ths){
|
||||
SNodeInfo node = {0};
|
||||
for (int32_t i = 0; i < ths->peersNum; ++i) {
|
||||
memcpy(&ths->peersNodeInfo[i], &node, sizeof(SNodeInfo));
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < ths->raftCfg.cfg.totalReplicaNum; ++i) {
|
||||
memcpy(&ths->raftCfg.cfg.nodeInfo[i], &node, sizeof(SNodeInfo));
|
||||
}
|
||||
}
|
||||
|
||||
int32_t syncNodeChangeConfig(SSyncNode* ths, SSyncRaftEntry* pEntry, char* str){
|
||||
if(pEntry->originalRpcType != TDMT_SYNC_CONFIG_CHANGE){
|
||||
return -1;
|
||||
}
|
||||
|
||||
SMsgHead *head = (SMsgHead *)pEntry->data;
|
||||
void *pReq = POINTER_SHIFT(head, sizeof(SMsgHead));
|
||||
|
||||
SAlterVnodeTypeReq req = {0};
|
||||
if (tDeserializeSAlterVnodeReplicaReq(pReq, head->contLen, &req) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
SSyncCfg cfg = {0};
|
||||
syncBuildConfigFromReq(&req, &cfg);
|
||||
|
||||
if(cfg.changeVersion <= ths->raftCfg.cfg.changeVersion){
|
||||
sInfo("vgId:%d, skip conf change entry since lower version. "
|
||||
"this entry, index:%" PRId64 ", term:%" PRId64 ", totalReplicaNum:%d, changeVersion:%d; "
|
||||
"current node, replicaNum:%d, peersNum:%d, lastConfigIndex:%" PRId64", changeVersion:%d",
|
||||
ths->vgId,
|
||||
pEntry->index, pEntry->term, cfg.totalReplicaNum, cfg.changeVersion,
|
||||
ths->replicaNum, ths->peersNum, ths->raftCfg.lastConfigIndex, ths->raftCfg.cfg.changeVersion);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(strcmp(str, "Commit") == 0){
|
||||
sInfo("vgId:%d, change config from %s. "
|
||||
"this, i:%" PRId64 ", trNum:%d, vers:%d; "
|
||||
"node, rNum:%d, pNum:%d, trNum:%d, "
|
||||
"buffer: [%" PRId64 " %" PRId64 " %" PRId64 ", %" PRId64 "), "
|
||||
"cond:(next i:%" PRId64 ", t:%" PRId64 " ==%s)",
|
||||
ths->vgId, str, pEntry->index - 1, cfg.totalReplicaNum, cfg.changeVersion,
|
||||
ths->replicaNum, ths->peersNum, ths->totalReplicaNum,
|
||||
ths->pLogBuf->startIndex, ths->pLogBuf->commitIndex, ths->pLogBuf->matchIndex, ths->pLogBuf->endIndex,
|
||||
pEntry->index, pEntry->term, TMSG_INFO(pEntry->originalRpcType));
|
||||
}
|
||||
else{
|
||||
sInfo("vgId:%d, change config from %s. "
|
||||
"this, i:%" PRId64 ", t:%" PRId64 ", trNum:%d, vers:%d; "
|
||||
"node, rNum:%d, pNum:%d, trNum:%d, "
|
||||
"buffer: [%" PRId64 " %" PRId64 " %" PRId64 ", %" PRId64 "), "
|
||||
"cond:(pre i:%" PRId64 "==ci:%" PRId64 ", bci:%" PRId64 ")",
|
||||
ths->vgId, str, pEntry->index, pEntry->term, cfg.totalReplicaNum, cfg.changeVersion,
|
||||
ths->replicaNum, ths->peersNum, ths->totalReplicaNum,
|
||||
ths->pLogBuf->startIndex, ths->pLogBuf->commitIndex, ths->pLogBuf->matchIndex, ths->pLogBuf->endIndex,
|
||||
pEntry->index -1, ths->commitIndex, ths->pLogBuf->commitIndex);
|
||||
}
|
||||
|
||||
syncNodeLogConfigInfo(ths, &cfg, "before config change");
|
||||
|
||||
int32_t oldTotalReplicaNum = ths->totalReplicaNum;
|
||||
|
||||
if(cfg.totalReplicaNum == 1 || cfg.totalReplicaNum == 2){//remove replica
|
||||
|
||||
bool incfg = false;
|
||||
for(int32_t j = 0; j < cfg.totalReplicaNum; ++j){
|
||||
if(strcmp(ths->myNodeInfo.nodeFqdn, cfg.nodeInfo[j].nodeFqdn) == 0
|
||||
&& ths->myNodeInfo.nodePort == cfg.nodeInfo[j].nodePort){
|
||||
incfg = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(incfg){//remove other
|
||||
syncNodeResetPeerAndCfg(ths);
|
||||
|
||||
//no need to change myNodeInfo
|
||||
|
||||
if(syncNodeRebuildPeerAndCfg(ths, &cfg) != 0){
|
||||
return -1;
|
||||
};
|
||||
|
||||
if(syncNodeRebuildAndCopyIfExist(ths, oldTotalReplicaNum) != 0){
|
||||
return -1;
|
||||
};
|
||||
}
|
||||
else{//remove myself
|
||||
//no need to do anything actually, to change the following to reduce distruptive server chance
|
||||
|
||||
syncNodeResetPeerAndCfg(ths);
|
||||
|
||||
//change myNodeInfo
|
||||
ths->myNodeInfo.nodeRole = TAOS_SYNC_ROLE_LEARNER;
|
||||
|
||||
//change peer and cfg
|
||||
ths->peersNum = 0;
|
||||
memcpy(&ths->raftCfg.cfg.nodeInfo[0], &ths->myNodeInfo, sizeof(SNodeInfo));
|
||||
ths->raftCfg.cfg.replicaNum = 0;
|
||||
ths->raftCfg.cfg.totalReplicaNum = 1;
|
||||
|
||||
//change other
|
||||
if(syncNodeRebuildAndCopyIfExist(ths, oldTotalReplicaNum) != 0){
|
||||
return -1;
|
||||
}
|
||||
|
||||
//change state
|
||||
ths->state = TAOS_SYNC_STATE_LEARNER;
|
||||
}
|
||||
|
||||
ths->restoreFinish = false;
|
||||
}
|
||||
else{//add replica, or change replica type
|
||||
if(ths->totalReplicaNum == 3){ //change replica type
|
||||
sInfo("vgId:%d, begin change replica type", ths->vgId);
|
||||
|
||||
//change myNodeInfo
|
||||
for(int32_t j = 0; j < cfg.totalReplicaNum; ++j){
|
||||
if(strcmp(ths->myNodeInfo.nodeFqdn, cfg.nodeInfo[j].nodeFqdn) == 0
|
||||
&& ths->myNodeInfo.nodePort == cfg.nodeInfo[j].nodePort){
|
||||
if(cfg.nodeInfo[j].nodeRole == TAOS_SYNC_ROLE_VOTER){
|
||||
ths->myNodeInfo.nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//change peer and cfg
|
||||
syncNodeChangePeerAndCfgToVoter(ths, &cfg);
|
||||
|
||||
//change other
|
||||
syncNodeChangeToVoter(ths);
|
||||
|
||||
//change state
|
||||
if(ths->state ==TAOS_SYNC_STATE_LEARNER){
|
||||
if(ths->myNodeInfo.nodeRole == TAOS_SYNC_ROLE_VOTER ){
|
||||
ths->state = TAOS_SYNC_STATE_FOLLOWER;
|
||||
}
|
||||
}
|
||||
|
||||
ths->restoreFinish = false;
|
||||
}
|
||||
else{//add replica
|
||||
sInfo("vgId:%d, begin add replica", ths->vgId);
|
||||
|
||||
//no need to change myNodeInfo
|
||||
|
||||
//change peer and cfg
|
||||
if(syncNodeRebuildPeerAndCfg(ths, &cfg) != 0){
|
||||
return -1;
|
||||
};
|
||||
|
||||
//change other
|
||||
if(syncNodeRebuildAndCopyIfExist(ths, oldTotalReplicaNum) != 0){
|
||||
return -1;
|
||||
};
|
||||
|
||||
//no need to change state
|
||||
|
||||
if(ths->myNodeInfo.nodeRole == TAOS_SYNC_ROLE_LEARNER){
|
||||
ths->restoreFinish = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ths->quorum = syncUtilQuorum(ths->replicaNum);
|
||||
|
||||
ths->raftCfg.lastConfigIndex = pEntry->index;
|
||||
ths->raftCfg.cfg.lastIndex = pEntry->index;
|
||||
ths->raftCfg.cfg.changeVersion = cfg.changeVersion;
|
||||
|
||||
syncNodeLogConfigInfo(ths, &cfg, "after config change");
|
||||
|
||||
if(syncWriteCfgFile(ths) != 0){
|
||||
sError("vgId:%d, failed to create sync cfg file", ths->vgId);
|
||||
return -1;
|
||||
};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t syncNodeAppend(SSyncNode* ths, SSyncRaftEntry* pEntry) {
|
||||
if (pEntry->dataLen < sizeof(SMsgHead)) {
|
||||
sError("vgId:%d, cannot append an invalid client request with no msg head. type:%s, dataLen:%d", ths->vgId,
|
||||
|
@ -2268,13 +2865,13 @@ int32_t syncNodeAppend(SSyncNode* ths, SSyncRaftEntry* pEntry) {
|
|||
if (syncLogBufferAppend(ths->pLogBuf, ths, pEntry) < 0) {
|
||||
sError("vgId:%d, failed to enqueue sync log buffer, index:%" PRId64, ths->vgId, pEntry->index);
|
||||
ASSERT(terrno != 0);
|
||||
(void)syncFsmExecute(ths, ths->pFsm, ths->state, raftStoreGetTerm(ths), pEntry, terrno);
|
||||
(void)syncFsmExecute(ths, ths->pFsm, ths->state, raftStoreGetTerm(ths), pEntry, terrno, false);
|
||||
syncEntryDestroy(pEntry);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// proceed match index, with replicating on needed
|
||||
SyncIndex matchIndex = syncLogBufferProceed(ths->pLogBuf, ths, NULL);
|
||||
SyncIndex matchIndex = syncLogBufferProceed(ths->pLogBuf, ths, NULL, "Append");
|
||||
|
||||
sTrace("vgId:%d, append raft entry. index:%" PRId64 ", term:%" PRId64 " pBuf: [%" PRId64 " %" PRId64 " %" PRId64
|
||||
", %" PRId64 ")",
|
||||
|
@ -2305,6 +2902,9 @@ bool syncNodeHeartbeatReplyTimeout(SSyncNode* pSyncNode) {
|
|||
int32_t toCount = 0;
|
||||
int64_t tsNow = taosGetTimestampMs();
|
||||
for (int32_t i = 0; i < pSyncNode->peersNum; ++i) {
|
||||
if(pSyncNode->peersNodeInfo[i].nodeRole == TAOS_SYNC_ROLE_LEARNER){
|
||||
continue;
|
||||
}
|
||||
int64_t recvTime = syncIndexMgrGetRecvTime(pSyncNode->pMatchIndex, &(pSyncNode->peersId[i]));
|
||||
if (recvTime == 0 || recvTime == -1) {
|
||||
continue;
|
||||
|
@ -2566,6 +3166,14 @@ int32_t syncNodeOnClientRequest(SSyncNode* ths, SRpcMsg* pMsg, SyncIndex* pRetIn
|
|||
pEntry = syncEntryBuildFromRpcMsg(pMsg, term, index);
|
||||
}
|
||||
|
||||
//1->2, config change is add in write thread, and will continue in sync thread
|
||||
//need save message for it
|
||||
if(pMsg->msgType == TDMT_SYNC_CONFIG_CHANGE){
|
||||
SRespStub stub = {.createTime = taosGetTimestampMs(), .rpcMsg = *pMsg};
|
||||
uint64_t seqNum = syncRespMgrAdd(ths->pSyncRespMgr, &stub);
|
||||
pEntry->seqNum = seqNum;
|
||||
}
|
||||
|
||||
if (pEntry == NULL) {
|
||||
sError("vgId:%d, failed to process client request since %s.", ths->vgId, terrstr());
|
||||
return -1;
|
||||
|
@ -2576,7 +3184,28 @@ int32_t syncNodeOnClientRequest(SSyncNode* ths, SRpcMsg* pMsg, SyncIndex* pRetIn
|
|||
(*pRetIndex) = index;
|
||||
}
|
||||
|
||||
int32_t code = syncNodeAppend(ths, pEntry);
|
||||
if(pEntry->originalRpcType == TDMT_SYNC_CONFIG_CHANGE){
|
||||
int32_t code = syncNodeCheckChangeConfig(ths, pEntry);
|
||||
if(code < 0){
|
||||
sError("vgId:%d, failed to check change config since %s.", ths->vgId, terrstr());
|
||||
syncEntryDestroy(pEntry);
|
||||
pEntry = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(code > 0){
|
||||
SRpcMsg rsp = {.code = pMsg->code, .info = pMsg->info};
|
||||
(void)syncRespMgrGetAndDel(ths->pSyncRespMgr, pEntry->seqNum, &rsp.info);
|
||||
if (rsp.info.handle != NULL) {
|
||||
tmsgSendRsp(&rsp);
|
||||
}
|
||||
syncEntryDestroy(pEntry);
|
||||
pEntry = NULL;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
code = syncNodeAppend(ths, pEntry);
|
||||
return code;
|
||||
} else {
|
||||
syncEntryDestroy(pEntry);
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include "syncRespMgr.h"
|
||||
#include "syncSnapshot.h"
|
||||
#include "syncUtil.h"
|
||||
#include "syncRaftCfg.h"
|
||||
#include "syncVoteMgr.h"
|
||||
|
||||
static bool syncIsMsgBlock(tmsg_t type) {
|
||||
return (type == TDMT_VND_CREATE_TABLE) || (type == TDMT_VND_ALTER_TABLE) || (type == TDMT_VND_DROP_TABLE) ||
|
||||
|
@ -428,7 +430,7 @@ int32_t syncLogStorePersist(SSyncLogStore* pLogStore, SSyncNode* pNode, SSyncRaf
|
|||
return 0;
|
||||
}
|
||||
|
||||
int64_t syncLogBufferProceed(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncTerm* pMatchTerm) {
|
||||
int64_t syncLogBufferProceed(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncTerm* pMatchTerm, char *str) {
|
||||
taosThreadMutexLock(&pBuf->mutex);
|
||||
syncLogBufferValidate(pBuf);
|
||||
|
||||
|
@ -475,9 +477,6 @@ int64_t syncLogBufferProceed(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncTerm* p
|
|||
sTrace("vgId:%d, log buffer proceed. start index:%" PRId64 ", match index:%" PRId64 ", end index:%" PRId64,
|
||||
pNode->vgId, pBuf->startIndex, pBuf->matchIndex, pBuf->endIndex);
|
||||
|
||||
// replicate on demand
|
||||
(void)syncNodeReplicateWithoutLock(pNode);
|
||||
|
||||
// persist
|
||||
if (syncLogStorePersist(pLogStore, pNode, pEntry) < 0) {
|
||||
sError("vgId:%d, failed to persist sync log entry from buffer since %s. index:%" PRId64, pNode->vgId, terrstr(),
|
||||
|
@ -485,6 +484,39 @@ int64_t syncLogBufferProceed(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncTerm* p
|
|||
taosMsleep(1);
|
||||
goto _out;
|
||||
}
|
||||
|
||||
if(pEntry->originalRpcType == TDMT_SYNC_CONFIG_CHANGE){
|
||||
if(pNode->pLogBuf->commitIndex == pEntry->index -1){
|
||||
sInfo("vgId:%d, to change config at %s. "
|
||||
"current entry, index:%" PRId64 ", term:%" PRId64", "
|
||||
"node, restore:%d, commitIndex:%" PRId64 ", "
|
||||
"cond: (pre entry index:%" PRId64 "== buf commit index:%" PRId64 ")",
|
||||
pNode->vgId, str,
|
||||
pEntry->index, pEntry->term,
|
||||
pNode->restoreFinish, pNode->commitIndex,
|
||||
pEntry->index - 1, pNode->pLogBuf->commitIndex);
|
||||
if(syncNodeChangeConfig(pNode, pEntry, str) != 0){
|
||||
sError("vgId:%d, failed to change config from Append since %s. index:%" PRId64, pNode->vgId, terrstr(),
|
||||
pEntry->index);
|
||||
goto _out;
|
||||
}
|
||||
}
|
||||
else{
|
||||
sInfo("vgId:%d, delay change config from Node %s. "
|
||||
"curent entry, index:%" PRId64 ", term:%" PRId64 ", "
|
||||
"node, commitIndex:%" PRId64 ", pBuf: [%" PRId64 " %" PRId64 " %" PRId64 ", %" PRId64 "), "
|
||||
"cond:( pre entry index:%" PRId64" != buf commit index:%" PRId64 ")",
|
||||
pNode->vgId, str,
|
||||
pEntry->index, pEntry->term,
|
||||
pNode->commitIndex, pNode->pLogBuf->startIndex, pNode->pLogBuf->commitIndex,
|
||||
pNode->pLogBuf->matchIndex, pNode->pLogBuf->endIndex,
|
||||
pEntry->index - 1, pNode->pLogBuf->commitIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// replicate on demand
|
||||
(void)syncNodeReplicateWithoutLock(pNode);
|
||||
|
||||
ASSERT(pEntry->index == pBuf->matchIndex);
|
||||
|
||||
// update my match index
|
||||
|
@ -503,8 +535,16 @@ _out:
|
|||
}
|
||||
|
||||
int32_t syncFsmExecute(SSyncNode* pNode, SSyncFSM* pFsm, ESyncState role, SyncTerm term, SSyncRaftEntry* pEntry,
|
||||
int32_t applyCode) {
|
||||
if (pNode->replicaNum == 1 && pNode->restoreFinish && pNode->vgId != 1) {
|
||||
int32_t applyCode, bool force) {
|
||||
//learner need to execute fsm when it catch up entry log
|
||||
//if force is true, keep all contition check to execute fsm
|
||||
if (pNode->replicaNum == 1 && pNode->restoreFinish && pNode->vgId != 1
|
||||
&& pNode->raftCfg.cfg.nodeInfo[pNode->raftCfg.cfg.myIndex].nodeRole != TAOS_SYNC_ROLE_LEARNER
|
||||
&& force == false) {
|
||||
sDebug("vgId:%d, not to execute fsm, index:%" PRId64 ", term:%" PRId64 ", type:%s code:0x%x, replicaNum:%d,"
|
||||
"role:%d, restoreFinish:%d",
|
||||
pNode->vgId, pEntry->index, pEntry->term, TMSG_INFO(pEntry->originalRpcType), applyCode,
|
||||
pNode->replicaNum, pNode->raftCfg.cfg.nodeInfo[pNode->raftCfg.cfg.myIndex].nodeRole, pNode->restoreFinish);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -559,6 +599,8 @@ int32_t syncLogBufferCommit(SSyncLogBuffer* pBuf, SSyncNode* pNode, int64_t comm
|
|||
int64_t upperIndex = TMIN(commitIndex, pBuf->matchIndex);
|
||||
SSyncRaftEntry* pEntry = NULL;
|
||||
bool inBuf = false;
|
||||
SSyncRaftEntry* pNextEntry = NULL;
|
||||
bool nextInBuf = false;
|
||||
|
||||
if (commitIndex <= pBuf->commitIndex) {
|
||||
sDebug("vgId:%d, stale commit index. current:%" PRId64 ", notified:%" PRId64 "", vgId, pBuf->commitIndex,
|
||||
|
@ -584,7 +626,7 @@ int32_t syncLogBufferCommit(SSyncLogBuffer* pBuf, SSyncNode* pNode, int64_t comm
|
|||
pEntry->term, TMSG_INFO(pEntry->originalRpcType));
|
||||
}
|
||||
|
||||
if (syncFsmExecute(pNode, pFsm, role, currentTerm, pEntry, 0) != 0) {
|
||||
if (syncFsmExecute(pNode, pFsm, role, currentTerm, pEntry, 0, false) != 0) {
|
||||
sError("vgId:%d, failed to execute sync log entry. index:%" PRId64 ", term:%" PRId64
|
||||
", role:%d, current term:%" PRId64,
|
||||
vgId, pEntry->index, pEntry->term, role, currentTerm);
|
||||
|
@ -595,10 +637,51 @@ int32_t syncLogBufferCommit(SSyncLogBuffer* pBuf, SSyncNode* pNode, int64_t comm
|
|||
sTrace("vgId:%d, committed index:%" PRId64 ", term:%" PRId64 ", role:%d, current term:%" PRId64 "", pNode->vgId,
|
||||
pEntry->index, pEntry->term, role, currentTerm);
|
||||
|
||||
pNextEntry = syncLogBufferGetOneEntry(pBuf, pNode, index + 1, &nextInBuf);
|
||||
if (pNextEntry != NULL) {
|
||||
if(pNextEntry->originalRpcType == TDMT_SYNC_CONFIG_CHANGE){
|
||||
sInfo("vgId:%d, to change config at Commit. "
|
||||
"current entry, index:%" PRId64 ", term:%" PRId64", "
|
||||
"node, role:%d, current term:%" PRId64 ", restore:%d, "
|
||||
"cond, next entry index:%" PRId64 ", msgType:%s",
|
||||
vgId,
|
||||
pEntry->index, pEntry->term,
|
||||
role, currentTerm, pNode->restoreFinish,
|
||||
pNextEntry->index, TMSG_INFO(pNextEntry->originalRpcType));
|
||||
|
||||
if(syncNodeChangeConfig(pNode, pNextEntry, "Commit") != 0){
|
||||
sError("vgId:%d, failed to change config from Commit. index:%" PRId64 ", term:%" PRId64
|
||||
", role:%d, current term:%" PRId64,
|
||||
vgId, pNextEntry->index, pNextEntry->term, role, currentTerm);
|
||||
goto _out;
|
||||
}
|
||||
|
||||
//for 2->1, need to apply config change entry in sync thread,
|
||||
if(pNode->replicaNum == 1){
|
||||
if (syncFsmExecute(pNode, pFsm, role, currentTerm, pNextEntry, 0, true) != 0) {
|
||||
sError("vgId:%d, failed to execute sync log entry. index:%" PRId64 ", term:%" PRId64
|
||||
", role:%d, current term:%" PRId64,
|
||||
vgId, pNextEntry->index, pNextEntry->term, role, currentTerm);
|
||||
goto _out;
|
||||
}
|
||||
|
||||
index++;
|
||||
pBuf->commitIndex = index;
|
||||
|
||||
sTrace("vgId:%d, committed index:%" PRId64 ", term:%" PRId64 ", role:%d, current term:%" PRId64 "", pNode->vgId,
|
||||
pNextEntry->index, pNextEntry->term, role, currentTerm);
|
||||
}
|
||||
}
|
||||
if (!nextInBuf) {
|
||||
syncEntryDestroy(pNextEntry);
|
||||
pNextEntry = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!inBuf) {
|
||||
syncEntryDestroy(pEntry);
|
||||
pEntry = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// recycle
|
||||
|
@ -626,6 +709,10 @@ _out:
|
|||
syncEntryDestroy(pEntry);
|
||||
pEntry = NULL;
|
||||
}
|
||||
if (!nextInBuf) {
|
||||
syncEntryDestroy(pNextEntry);
|
||||
pNextEntry = NULL;
|
||||
}
|
||||
syncLogBufferValidate(pBuf);
|
||||
taosThreadMutexUnlock(&pBuf->mutex);
|
||||
return ret;
|
||||
|
|
|
@ -44,6 +44,7 @@ static int32_t syncEncodeSyncCfg(const void *pObj, SJson *pJson) {
|
|||
SSyncCfg *pCfg = (SSyncCfg *)pObj;
|
||||
if (tjsonAddDoubleToObject(pJson, "replicaNum", pCfg->replicaNum) < 0) return -1;
|
||||
if (tjsonAddDoubleToObject(pJson, "myIndex", pCfg->myIndex) < 0) return -1;
|
||||
if (tjsonAddDoubleToObject(pJson, "changeVersion", pCfg->changeVersion) < 0) return -1;
|
||||
|
||||
SJson *nodeInfo = tjsonCreateArray();
|
||||
if (nodeInfo == NULL) return -1;
|
||||
|
@ -113,8 +114,9 @@ int32_t syncWriteCfgFile(SSyncNode *pNode) {
|
|||
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
||||
|
||||
code = 0;
|
||||
sInfo("vgId:%d, succeed to write sync cfg file:%s, len:%d, lastConfigIndex:%" PRId64, pNode->vgId,
|
||||
realfile, len, pNode->raftCfg.lastConfigIndex);
|
||||
sInfo("vgId:%d, succeed to write sync cfg file:%s, len:%d, lastConfigIndex:%" PRId64 ", "
|
||||
"changeVersion:%d", pNode->vgId,
|
||||
realfile, len, pNode->raftCfg.lastConfigIndex, pNode->raftCfg.cfg.changeVersion);
|
||||
|
||||
_OVER:
|
||||
if (pJson != NULL) tjsonDelete(pJson);
|
||||
|
@ -136,6 +138,8 @@ static int32_t syncDecodeSyncCfg(const SJson *pJson, void *pObj) {
|
|||
if (code < 0) return -1;
|
||||
tjsonGetInt32ValueFromDouble(pJson, "myIndex", pCfg->myIndex, code);
|
||||
if (code < 0) return -1;
|
||||
tjsonGetInt32ValueFromDouble(pJson, "changeVersion", pCfg->changeVersion, code);
|
||||
if (code < 0) return -1;
|
||||
|
||||
SJson *nodeInfo = tjsonGetObjectItem(pJson, "nodeInfo");
|
||||
if (nodeInfo == NULL) return -1;
|
||||
|
@ -242,7 +246,8 @@ int32_t syncReadCfgFile(SSyncNode *pNode) {
|
|||
}
|
||||
|
||||
code = 0;
|
||||
sInfo("vgId:%d, succceed to read sync cfg file %s", pNode->vgId, file);
|
||||
sInfo("vgId:%d, succceed to read sync cfg file %s, changeVersion:%d",
|
||||
pNode->vgId, file, pCfg->cfg.changeVersion);
|
||||
|
||||
_OVER:
|
||||
if (pData != NULL) taosMemoryFree(pData);
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "tfsInt.h"
|
||||
|
||||
extern int64_t tsMinDiskFreeSize;
|
||||
|
||||
int32_t tfsInitTier(STfsTier *pTier, int32_t level) {
|
||||
memset(pTier, 0, sizeof(STfsTier));
|
||||
|
||||
|
@ -114,7 +116,7 @@ int32_t tfsAllocDiskOnTier(STfsTier *pTier) {
|
|||
|
||||
if (pDisk == NULL) continue;
|
||||
|
||||
if (pDisk->size.avail < TFS_MIN_DISK_FREE_SIZE) continue;
|
||||
if (pDisk->size.avail < tsMinDiskFreeSize) continue;
|
||||
|
||||
retId = diskId;
|
||||
terrno = 0;
|
||||
|
@ -132,7 +134,7 @@ void tfsPosNextId(STfsTier *pTier) {
|
|||
for (int32_t id = 1; id < pTier->ndisk; id++) {
|
||||
STfsDisk *pLDisk = pTier->disks[nextid];
|
||||
STfsDisk *pDisk = pTier->disks[id];
|
||||
if (pDisk->size.avail > TFS_MIN_DISK_FREE_SIZE && pDisk->size.avail > pLDisk->size.avail) {
|
||||
if (pDisk->size.avail > tsMinDiskFreeSize && pDisk->size.avail > pLDisk->size.avail) {
|
||||
nextid = id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -212,7 +212,7 @@ int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime, int32_t *a
|
|||
}
|
||||
|
||||
if (atime != NULL) {
|
||||
*atime = fileStat.st_mtime;
|
||||
*atime = fileStat.st_atime;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -1019,7 +1019,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
|||
|
||||
code = cfgSetItem(pConfig, name, value, CFG_STYPE_APOLLO_URL);
|
||||
if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break;
|
||||
|
||||
|
||||
if (strcasecmp(name, "dataDir") == 0) {
|
||||
code = cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_APOLLO_URL);
|
||||
if (code != 0 && terrno != TSDB_CODE_CFG_NOT_FOUND) break;
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/stbJoin.py -Q 2
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/stbJoin.py -Q 3
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/stbJoin.py -Q 4
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/hint.py
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/hint.py -Q 2
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/hint.py -Q 3
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/hint.py -Q 4
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/nestedQuery.py
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/nestedQuery_str.py
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/nestedQuery_math.py
|
||||
|
|
|
@ -806,21 +806,33 @@ class TDDnodes:
|
|||
psCmd = "for /f %a in ('wmic process where \"name='taosd.exe'\" get processId ^| xargs echo ^| awk '{print $2}' ^&^& echo aa') do @(ps | grep %a | awk '{print $1}' | xargs)"
|
||||
processID = subprocess.check_output(psCmd, shell=True).decode("utf-8").strip()
|
||||
while(processID):
|
||||
print(processID)
|
||||
print(f"pid of taosd.exe:{processID}")
|
||||
killCmd = "kill -9 %s > nul 2>&1" % processID
|
||||
os.system(killCmd)
|
||||
time.sleep(1)
|
||||
processID = subprocess.check_output(
|
||||
psCmd, shell=True).decode("utf-8").strip()
|
||||
psCmd = "for /f %a in ('wmic process where \"name='tmq_sim'\" get processId ^| xargs echo ^| awk '{print $2}' ^&^& echo aa') do @(ps | grep %a | awk '{print $1}' | xargs)"
|
||||
|
||||
psCmd = "for /f %a in ('wmic process where \"name='tmq_sim.exe'\" get processId ^| xargs echo ^| awk '{print $2}' ^&^& echo aa') do @(ps | grep %a | awk '{print $1}' | xargs)"
|
||||
processID = subprocess.check_output(psCmd, shell=True).decode("utf-8").strip()
|
||||
while(processID):
|
||||
print(processID)
|
||||
print(f"pid of tmq_sim.exe:{processID}")
|
||||
killCmd = "kill -9 %s > nul 2>&1" % processID
|
||||
os.system(killCmd)
|
||||
time.sleep(1)
|
||||
processID = subprocess.check_output(
|
||||
psCmd, shell=True).decode("utf-8").strip()
|
||||
|
||||
psCmd = "for /f %a in ('wmic process where \"name='taosBenchmark.exe'\" get processId ^| xargs echo ^| awk '{print $2}' ^&^& echo aa') do @(ps | grep %a | awk '{print $1}' | xargs)"
|
||||
processID = subprocess.check_output(psCmd, shell=True).decode("utf-8").strip()
|
||||
while(processID):
|
||||
print(f"pid of taosBenchmark.exe:{processID}")
|
||||
killCmd = "kill -9 %s > nul 2>&1" % processID
|
||||
os.system(killCmd)
|
||||
time.sleep(1)
|
||||
processID = subprocess.check_output(
|
||||
psCmd, shell=True).decode("utf-8").strip()
|
||||
|
||||
else:
|
||||
psCmd = "ps -ef | grep -w taosd | grep 'root' | grep -v grep| grep -v defunct | awk '{print $2}' | xargs"
|
||||
processID = subprocess.check_output(psCmd, shell=True).decode("utf-8").strip()
|
||||
|
|
|
@ -210,66 +210,6 @@ class TDTestCase:
|
|||
licences_info = tdSql.queryResult
|
||||
tdSql.checkEqual(grants_info,licences_info)
|
||||
|
||||
def show_create_table_with_col_comment(self):
|
||||
tdSql.execute("create database comment_test_db")
|
||||
tdSql.execute("use comment_test_db")
|
||||
tdSql.execute("create table normal_table(ts timestamp, c2 int comment 'c2 comment')")
|
||||
tdSql.execute("create stable super_table(ts timestamp comment 'ts', c2 int comment 'c2 comment') tags(tg int comment 'tg comment')")
|
||||
|
||||
create_sql = "create table `normal_table` (`ts` timestamp, `c2` int)"
|
||||
tdSql.query('show create table normal_table')
|
||||
tdSql.checkEqual(tdSql.queryResult[0][1].lower(), create_sql)
|
||||
tdSql.query('show create table super_table')
|
||||
create_sql = "create stable `super_table` (`ts` timestamp, `c2` int) tags (`tg` int)"
|
||||
tdSql.checkEqual(tdSql.queryResult[0][1].lower(), create_sql)
|
||||
|
||||
tdSql.query("desc normal_table")
|
||||
tdSql.checkCols(5)
|
||||
tdSql.checkData(0, 4, "")
|
||||
|
||||
tdSql.query("desc super_table")
|
||||
tdSql.checkCols(5)
|
||||
tdSql.checkData(0, 4, "")
|
||||
|
||||
tdSql.execute("drop database comment_test_db")
|
||||
|
||||
def alter_table_with_col_comment(self):
|
||||
tdSql.execute("create database comment_test_db")
|
||||
tdSql.execute("use comment_test_db")
|
||||
tdSql.execute("create table normal_table(ts timestamp, c2 int comment 'c2 comment')")
|
||||
tdSql.execute("create stable super_table(ts timestamp comment 'ts', c2 int comment 'c2 comment') tags(tg int comment 'tg comment')")
|
||||
|
||||
create_sql = "create table `normal_table` (`ts` timestamp, `c2` int, `c3` int)"
|
||||
tdSql.execute("alter table normal_table add column c3 int comment 'c3 comment'", queryTimes=1)
|
||||
tdSql.query("show create table normal_table")
|
||||
tdSql.checkEqual(tdSql.queryResult[0][1].lower(), create_sql)
|
||||
|
||||
create_sql = "create table `normal_table` (`ts` timestamp, `c2` int, `c3` int, `c4` varchar(255))"
|
||||
tdSql.execute("alter table normal_table add column c4 varchar(255) comment 'c4 comment'", queryTimes=1)
|
||||
tdSql.query("show create table normal_table")
|
||||
tdSql.checkEqual(tdSql.queryResult[0][1].lower(), create_sql)
|
||||
|
||||
create_sql = "create table `normal_table` (`ts` timestamp, `c2` int, `c3` int, `c4` varchar(255), `c5` varchar(255))"
|
||||
tdSql.execute("alter table normal_table add column c5 varchar(255)", queryTimes=1)
|
||||
tdSql.query("show create table normal_table")
|
||||
tdSql.checkEqual(tdSql.queryResult[0][1].lower(), create_sql)
|
||||
|
||||
create_sql = "create stable `super_table` (`ts` timestamp, `c2` int, `c3` int) tags (`tg` int) sma(`ts`,`c2`)"
|
||||
tdSql.execute("alter table super_table add column c3 int comment 'c3 comment'", queryTimes=1)
|
||||
tdSql.query("show create table super_table")
|
||||
tdSql.checkEqual(tdSql.queryResult[0][1].lower(), create_sql)
|
||||
|
||||
create_sql = "create stable `super_table` (`ts` timestamp, `c2` int, `c3` int, `c4` varchar(255)) tags (`tg` int) sma(`ts`,`c2`)"
|
||||
tdSql.execute("alter table super_table add column c4 varchar(255) comment 'c4 comment'", queryTimes=1)
|
||||
tdSql.query("show create table super_table")
|
||||
tdSql.checkEqual(tdSql.queryResult[0][1].lower(), create_sql)
|
||||
|
||||
create_sql = "create stable `super_table` (`ts` timestamp, `c2` int, `c3` int, `c4` varchar(256)) tags (`tg` int) sma(`ts`,`c2`)"
|
||||
tdSql.execute("alter table super_table modify column c4 varchar(256) comment 'c4 256 comment'", queryTimes=1)
|
||||
tdSql.query("show create table super_table")
|
||||
tdSql.checkEqual(tdSql.queryResult[0][1].lower(), create_sql)
|
||||
tdSql.execute("drop database comment_test_db")
|
||||
|
||||
def run(self):
|
||||
self.check_gitinfo()
|
||||
self.show_base()
|
||||
|
@ -278,8 +218,6 @@ class TDTestCase:
|
|||
self.show_create_sql()
|
||||
self.show_create_sysdb_sql()
|
||||
self.show_create_systb_sql()
|
||||
self.show_create_table_with_col_comment()
|
||||
self.alter_table_with_col_comment()
|
||||
|
||||
def stop(self):
|
||||
tdSql.close()
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
from wsgiref.headers import tspecials
|
||||
from util.log import *
|
||||
from util.cases import *
|
||||
from util.sql import *
|
||||
import numpy as np
|
||||
|
||||
|
||||
class TDTestCase:
|
||||
def init(self, conn, logSql, replicaVar=1):
|
||||
self.replicaVar = int(replicaVar)
|
||||
tdLog.debug("start to execute %s" % __file__)
|
||||
tdSql.init(conn.cursor())
|
||||
|
||||
self.rowNum = 10
|
||||
self.batchNum = 5
|
||||
self.ts = 1537146000000
|
||||
|
||||
def run(self):
|
||||
dbname = "db"
|
||||
tdSql.prepare()
|
||||
|
||||
tdSql.execute(f'''create table sta(ts timestamp, col1 int, col2 bigint) tags(tg1 int, tg2 binary(20))''')
|
||||
tdSql.execute(f"create table sta1 using sta tags(1, 'a')")
|
||||
tdSql.execute(f"create table sta2 using sta tags(2, 'b')")
|
||||
tdSql.execute(f"create table sta3 using sta tags(3, 'c')")
|
||||
tdSql.execute(f"create table sta4 using sta tags(4, 'a')")
|
||||
tdSql.execute(f"insert into sta1 values(1537146000001, 11, 110)")
|
||||
tdSql.execute(f"insert into sta1 values(1537146000002, 12, 120)")
|
||||
tdSql.execute(f"insert into sta1 values(1537146000003, 13, 130)")
|
||||
tdSql.execute(f"insert into sta2 values(1537146000001, 21, 210)")
|
||||
tdSql.execute(f"insert into sta2 values(1537146000002, 22, 220)")
|
||||
tdSql.execute(f"insert into sta2 values(1537146000003, 23, 230)")
|
||||
tdSql.execute(f"insert into sta3 values(1537146000001, 31, 310)")
|
||||
tdSql.execute(f"insert into sta3 values(1537146000002, 32, 320)")
|
||||
tdSql.execute(f"insert into sta3 values(1537146000003, 33, 330)")
|
||||
tdSql.execute(f"insert into sta4 values(1537146000001, 41, 410)")
|
||||
tdSql.execute(f"insert into sta4 values(1537146000002, 42, 420)")
|
||||
tdSql.execute(f"insert into sta4 values(1537146000003, 43, 430)")
|
||||
|
||||
tdSql.execute(f'''create table stb(ts timestamp, col1 int, col2 bigint) tags(tg1 int, tg2 binary(20))''')
|
||||
tdSql.execute(f"create table stb1 using stb tags(1, 'a')")
|
||||
tdSql.execute(f"create table stb2 using stb tags(2, 'b')")
|
||||
tdSql.execute(f"create table stb3 using stb tags(3, 'c')")
|
||||
tdSql.execute(f"create table stb4 using stb tags(4, 'a')")
|
||||
tdSql.execute(f"insert into stb1 values(1537146000001, 911, 9110)")
|
||||
tdSql.execute(f"insert into stb1 values(1537146000002, 912, 9120)")
|
||||
tdSql.execute(f"insert into stb1 values(1537146000003, 913, 9130)")
|
||||
tdSql.execute(f"insert into stb2 values(1537146000001, 921, 9210)")
|
||||
tdSql.execute(f"insert into stb2 values(1537146000002, 922, 9220)")
|
||||
tdSql.execute(f"insert into stb2 values(1537146000003, 923, 9230)")
|
||||
tdSql.execute(f"insert into stb3 values(1537146000001, 931, 9310)")
|
||||
tdSql.execute(f"insert into stb3 values(1537146000002, 932, 9320)")
|
||||
tdSql.execute(f"insert into stb3 values(1537146000003, 933, 9330)")
|
||||
tdSql.execute(f"insert into stb4 values(1537146000001, 941, 9410)")
|
||||
tdSql.execute(f"insert into stb4 values(1537146000002, 942, 9420)")
|
||||
tdSql.execute(f"insert into stb4 values(1537146000003, 943, 9430)")
|
||||
|
||||
tdSql.query(f"select /*+ batch_scan() */ count(*) from sta a, stb b where a.tg1=b.tg1 and a.ts=b.ts and b.tg2 > 'a' interval(1a);")
|
||||
tdSql.checkRows(3)
|
||||
|
||||
tdSql.query(f"select /*+ no_batch_scan() */ count(*) from sta a, stb b where a.tg1=b.tg1 and a.ts=b.ts and b.tg2 > 'a' interval(1a);")
|
||||
tdSql.checkRows(3)
|
||||
|
||||
tdSql.query(f"select /*+ batch_scan(a) */ count(*) from sta a, stb b where a.tg1=b.tg1 and a.ts=b.ts and b.tg2 > 'a' interval(1a);")
|
||||
tdSql.checkRows(3)
|
||||
|
||||
tdSql.query(f"select /*+ batch_scan(a,) */ count(*) from sta a, stb b where a.tg1=b.tg1 and a.ts=b.ts and b.tg2 > 'a' interval(1a);")
|
||||
tdSql.checkRows(3)
|
||||
|
||||
tdSql.query(f"select /*+ a,a */ count(*) from sta a, stb b where a.tg1=b.tg1 and a.ts=b.ts and b.tg2 > 'a' interval(1a);")
|
||||
tdSql.checkRows(3)
|
||||
|
||||
tdSql.query(f"select /*+*/ count(*) from sta a, stb b where a.tg1=b.tg1 and a.ts=b.ts and b.tg2 > 'a' interval(1a);")
|
||||
tdSql.checkRows(3)
|
||||
|
||||
tdSql.query(f"select /*+ batch_scan(),no_batch_scan() */ count(*) from sta a, stb b where a.tg1=b.tg1 and a.ts=b.ts and b.tg2 > 'a' interval(1a);")
|
||||
tdSql.checkRows(3)
|
||||
|
||||
tdSql.query(f"select /*+ no_batch_scan() batch_scan() */ count(*) from sta a, stb b where a.tg1=b.tg1 and a.ts=b.ts and b.tg2 > 'a' interval(1a);")
|
||||
tdSql.checkRows(3)
|
||||
|
||||
def stop(self):
|
||||
tdSql.close()
|
||||
tdLog.success("%s successfully executed" % __file__)
|
||||
|
||||
tdCases.addWindows(__file__, TDTestCase())
|
||||
tdCases.addLinux(__file__, TDTestCase())
|
|
@ -103,6 +103,8 @@ class TDTestCase:
|
|||
tdSql.query(f"select /*+ no_batch_scan() */ count(*) from sta a, stb b where a.tg1=b.tg1 and a.ts=b.ts and b.tg2 > 'a' interval(1a);")
|
||||
tdSql.checkRows(3)
|
||||
|
||||
tdSql.query(f"select a.ts, b.ts from sta a, stb b where a.ts=b.ts and (a.tg1=b.tg1 and a.tg1 > b.tg1);")
|
||||
tdSql.checkRows(0)
|
||||
|
||||
# tdSql.checkData(0,1,10)
|
||||
|
||||
|
|
|
@ -191,7 +191,7 @@ class TDTestCase:
|
|||
if tdSql.cursor.istype(col, "BIGINT UNSIGNED"):
|
||||
return "BIGINT UNSIGNED"
|
||||
|
||||
def union_check(self):
|
||||
def union_check(self, dbname = "db"):
|
||||
sqls = self.sql_list()
|
||||
for i in range(len(sqls)):
|
||||
tdSql.query(sqls[i])
|
||||
|
@ -232,6 +232,32 @@ class TDTestCase:
|
|||
else:
|
||||
tdSql.error(f"{sqls[i]} union {sqls[j+i]}")
|
||||
|
||||
# check union with timeline function
|
||||
tdSql.query(f"select first(c1) from (select * from {dbname}.t1 union select * from {dbname}.t1 order by ts)")
|
||||
tdSql.checkRows(1)
|
||||
tdSql.checkData(0, 0, 9)
|
||||
tdSql.query(f"select last(c1) from (select * from {dbname}.t1 union select * from {dbname}.t1 order by ts desc)")
|
||||
tdSql.checkRows(1)
|
||||
tdSql.checkData(0, 0, 2147450880)
|
||||
tdSql.query(f"select irate(c1) from (select * from {dbname}.t1 union select * from {dbname}.t1 order by ts)")
|
||||
tdSql.checkRows(1)
|
||||
tdSql.checkData(0, 0, 9.102222222222222)
|
||||
tdSql.query(f"select elapsed(ts) from (select * from {dbname}.t1 union select * from {dbname}.t1 order by ts)")
|
||||
tdSql.checkRows(1)
|
||||
tdSql.checkData(0, 0, 46800000.000000000000000)
|
||||
tdSql.query(f"select diff(c1) from (select * from {dbname}.t1 union select * from {dbname}.t1 order by ts)")
|
||||
tdSql.checkRows(14)
|
||||
tdSql.query(f"select derivative(c1, 1s, 0) from (select * from {dbname}.t1 union select * from {dbname}.t1 order by ts)")
|
||||
tdSql.checkRows(11)
|
||||
|
||||
tdSql.error(f"select first(c1) from (select * from {dbname}.t1 union select * from {dbname}.t1)")
|
||||
tdSql.error(f"select last(c1) from (select * from {dbname}.t1 union select * from {dbname}.t1)")
|
||||
tdSql.error(f"select irate(c1) from (select * from {dbname}.t1 union select * from {dbname}.t1)")
|
||||
tdSql.error(f"select elapsed(ts) from (select * from {dbname}.t1 union select * from {dbname}.t1)")
|
||||
tdSql.error(f"select diff(c1) from (select * from {dbname}.t1 union select * from {dbname}.t1)")
|
||||
tdSql.error(f"select derivative(c1, 1s, 0) from (select * from {dbname}.t1 union select * from {dbname}.t1)")
|
||||
|
||||
|
||||
def __test_error(self, dbname="db"):
|
||||
|
||||
tdSql.error( f"show {dbname}.tables union show {dbname}.tables" )
|
||||
|
|
Loading…
Reference in New Issue