Merge branch '3.0' into test/jcy
This commit is contained in:
commit
4ea8ab664d
|
@ -0,0 +1,43 @@
|
|||
---
|
||||
sidebar_label: 删除数据
|
||||
description: "删除指定表或超级表中的数据记录"
|
||||
title: "删除数据"
|
||||
---
|
||||
|
||||
删除数据是 TDengine 提供的根据指定时间段删除指定表或超级表中数据记录的功能,方便用户清理由于设备故障等原因产生的异常数据。
|
||||
注意:本功能只在企业版 2.6.0.0 及以后的版本中提供,如需此功能请点击下面的链接访问[企业版产品](https://www.taosdata.com/products#enterprise-edition-link)
|
||||
|
||||
|
||||
**语法:**
|
||||
|
||||
```sql
|
||||
DELETE FROM [ db_name. ] tb_name [WHERE condition];
|
||||
```
|
||||
|
||||
**功能:** 删除指定表或超级表中的数据记录
|
||||
|
||||
**参数:**
|
||||
|
||||
- `db_name` : 可选参数,指定要删除表所在的数据库名,不填写则在当前数据库中
|
||||
- `tb_name` : 必填参数,指定要删除数据的表名,可以是普通表、子表,也可以是超级表。
|
||||
- `condition`: 可选参数,指定删除数据的过滤条件,不指定过滤条件则为表中所有数据,请慎重使用。特别说明,这里的where 条件中只支持对第一列时间列的过滤,如果是超级表,支持对 tag 列过滤。
|
||||
|
||||
**特别说明:**
|
||||
|
||||
数据删除后不可恢复,请慎重使用。为了确保删除的数据确实是自己要删除的,建议可以先使用 `select` 语句加 `where` 后的删除条件查看要删除的数据内容,确认无误后再执行 `delete` 命令。
|
||||
|
||||
**示例:**
|
||||
|
||||
`meters` 是一个超级表,`groupid` 是 int 类型的 tag 列,现在要删除 `meters` 表中时间小于 2021-10-01 10:40:00.100 且 tag 列 `groupid` 值为 1 的所有数据,sql 如下:
|
||||
|
||||
```sql
|
||||
delete from meters where ts < '2021-10-01 10:40:00.100' and groupid=1 ;
|
||||
```
|
||||
|
||||
执行后显示结果为:
|
||||
|
||||
```
|
||||
Deleted 102000 row(s) from 1020 table(s) (0.421950s)
|
||||
```
|
||||
|
||||
表示从 1020 个子表中共删除了 102000 行数据
|
|
@ -0,0 +1,42 @@
|
|||
---
|
||||
sidebar_label: Delete Data
|
||||
description: "Delete data from table or Stable"
|
||||
title: Delete Data
|
||||
---
|
||||
|
||||
TDengine provides the functionality of deleting data from a table or STable according to specified time range, it can be used to cleanup abnormal data generated due to device failure. Please be noted that this functionality is only available in Enterprise version, please refer to [TDengine Enterprise Edition](https://tdengine.com/products#enterprise-edition-link)
|
||||
|
||||
|
||||
**Syntax:**
|
||||
|
||||
```sql
|
||||
DELETE FROM [ db_name. ] tb_name [WHERE condition];
|
||||
```
|
||||
|
||||
**Description:** Delete data from a table or STable
|
||||
|
||||
**Parameters:**
|
||||
|
||||
- `db_name`: Optional parameter, specifies the database in which the table exists; if not specified, the current database will be used.
|
||||
- `tb_name`: Mandatory parameter, specifies the table name from which data will be deleted, it can be normal table, subtable or STable.
|
||||
- `condition`: Optional parameter, specifies the data filter condition. If no condition is specified all data will be deleted, so please be cautions to delete data without any condition. The condition used here is only applicable to the first column, i.e. the timestamp column. If the table is a STable, the condition is also applicable to tag columns.
|
||||
|
||||
**More Explanations:**
|
||||
|
||||
The data can't be recovered once deleted, so please be cautious to use the functionality of deleting data. It's better to firstly make sure the data to be deleted using `select` then execute `delete`.
|
||||
|
||||
**Example:**
|
||||
|
||||
`meters` is a STable, in which `groupid` is a tag column of int type. Now we want to delete the data older than 2021-10-01 10:40:00.100 and `groupid` is 1. The SQL for this purpose is like below:
|
||||
|
||||
```sql
|
||||
delete from meters where ts < '2021-10-01 10:40:00.100' and groupid=1 ;
|
||||
```
|
||||
|
||||
The output is:
|
||||
|
||||
```
|
||||
Deleted 102000 row(s) from 1020 table(s) (0.421950s)
|
||||
```
|
||||
|
||||
It means totally 102,000 rows of data have been deleted from 1,020 sub tables.
|
|
@ -99,7 +99,7 @@ typedef struct TAOS_FIELD_E {
|
|||
#define DLL_EXPORT
|
||||
#endif
|
||||
|
||||
typedef void (*__taos_async_fn_t)(void *param, TAOS_RES *, int code);
|
||||
typedef void (*__taos_async_fn_t)(void *param, TAOS_RES *res, int code);
|
||||
|
||||
typedef struct TAOS_MULTI_BIND {
|
||||
int buffer_type;
|
||||
|
@ -126,49 +126,47 @@ typedef struct setConfRet {
|
|||
char retMsg[RET_MSG_LENGTH];
|
||||
} setConfRet;
|
||||
|
||||
DLL_EXPORT void taos_cleanup(void);
|
||||
DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...);
|
||||
DLL_EXPORT setConfRet taos_set_config(const char *config);
|
||||
DLL_EXPORT int taos_init(void);
|
||||
DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port);
|
||||
DLL_EXPORT TAOS *taos_connect_l(const char *ip, int ipLen, const char *user, int userLen, const char *pass, int passLen,
|
||||
const char *db, int dbLen, uint16_t port);
|
||||
DLL_EXPORT TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port);
|
||||
DLL_EXPORT void taos_close(TAOS *taos);
|
||||
DLL_EXPORT void taos_cleanup(void);
|
||||
DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...);
|
||||
DLL_EXPORT setConfRet taos_set_config(const char *config);
|
||||
DLL_EXPORT int taos_init(void);
|
||||
DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port);
|
||||
DLL_EXPORT TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port);
|
||||
DLL_EXPORT void taos_close(TAOS *taos);
|
||||
|
||||
const char *taos_data_type(int type);
|
||||
const char *taos_data_type(int type);
|
||||
|
||||
DLL_EXPORT TAOS_STMT *taos_stmt_init(TAOS *taos);
|
||||
DLL_EXPORT int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length);
|
||||
DLL_EXPORT int taos_stmt_set_tbname_tags(TAOS_STMT *stmt, const char *name, TAOS_MULTI_BIND *tags);
|
||||
DLL_EXPORT int taos_stmt_set_tbname(TAOS_STMT *stmt, const char *name);
|
||||
DLL_EXPORT int taos_stmt_set_tags(TAOS_STMT *stmt, TAOS_MULTI_BIND *tags);
|
||||
DLL_EXPORT int taos_stmt_set_sub_tbname(TAOS_STMT *stmt, const char *name);
|
||||
DLL_EXPORT int taos_stmt_get_tag_fields(TAOS_STMT *stmt, int *fieldNum, TAOS_FIELD_E **fields);
|
||||
DLL_EXPORT int taos_stmt_get_col_fields(TAOS_STMT *stmt, int *fieldNum, TAOS_FIELD_E **fields);
|
||||
DLL_EXPORT TAOS_STMT *taos_stmt_init(TAOS *taos);
|
||||
DLL_EXPORT int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length);
|
||||
DLL_EXPORT int taos_stmt_set_tbname_tags(TAOS_STMT *stmt, const char *name, TAOS_MULTI_BIND *tags);
|
||||
DLL_EXPORT int taos_stmt_set_tbname(TAOS_STMT *stmt, const char *name);
|
||||
DLL_EXPORT int taos_stmt_set_tags(TAOS_STMT *stmt, TAOS_MULTI_BIND *tags);
|
||||
DLL_EXPORT int taos_stmt_set_sub_tbname(TAOS_STMT *stmt, const char *name);
|
||||
DLL_EXPORT int taos_stmt_get_tag_fields(TAOS_STMT *stmt, int *fieldNum, TAOS_FIELD_E **fields);
|
||||
DLL_EXPORT int taos_stmt_get_col_fields(TAOS_STMT *stmt, int *fieldNum, TAOS_FIELD_E **fields);
|
||||
|
||||
DLL_EXPORT int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert);
|
||||
DLL_EXPORT int taos_stmt_num_params(TAOS_STMT *stmt, int *nums);
|
||||
DLL_EXPORT int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes);
|
||||
DLL_EXPORT int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind);
|
||||
DLL_EXPORT int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind);
|
||||
DLL_EXPORT int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int colIdx);
|
||||
DLL_EXPORT int taos_stmt_add_batch(TAOS_STMT *stmt);
|
||||
DLL_EXPORT int taos_stmt_execute(TAOS_STMT *stmt);
|
||||
DLL_EXPORT TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt);
|
||||
DLL_EXPORT int taos_stmt_close(TAOS_STMT *stmt);
|
||||
DLL_EXPORT char *taos_stmt_errstr(TAOS_STMT *stmt);
|
||||
DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT *stmt);
|
||||
DLL_EXPORT int taos_stmt_affected_rows_once(TAOS_STMT *stmt);
|
||||
DLL_EXPORT int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert);
|
||||
DLL_EXPORT int taos_stmt_num_params(TAOS_STMT *stmt, int *nums);
|
||||
DLL_EXPORT int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes);
|
||||
DLL_EXPORT int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind);
|
||||
DLL_EXPORT int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind);
|
||||
DLL_EXPORT int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int colIdx);
|
||||
DLL_EXPORT int taos_stmt_add_batch(TAOS_STMT *stmt);
|
||||
DLL_EXPORT int taos_stmt_execute(TAOS_STMT *stmt);
|
||||
DLL_EXPORT TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt);
|
||||
DLL_EXPORT int taos_stmt_close(TAOS_STMT *stmt);
|
||||
DLL_EXPORT char *taos_stmt_errstr(TAOS_STMT *stmt);
|
||||
DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT *stmt);
|
||||
DLL_EXPORT int taos_stmt_affected_rows_once(TAOS_STMT *stmt);
|
||||
|
||||
DLL_EXPORT TAOS_RES *taos_query(TAOS *taos, const char *sql);
|
||||
DLL_EXPORT TAOS_RES *taos_query(TAOS *taos, const char *sql);
|
||||
|
||||
DLL_EXPORT TAOS_ROW taos_fetch_row(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_result_precision(TAOS_RES *res); // get the time precision of result
|
||||
DLL_EXPORT void taos_free_result(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_field_count(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_num_fields(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_affected_rows(TAOS_RES *res);
|
||||
DLL_EXPORT TAOS_ROW taos_fetch_row(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_result_precision(TAOS_RES *res); // get the time precision of result
|
||||
DLL_EXPORT void taos_free_result(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_field_count(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_num_fields(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_affected_rows(TAOS_RES *res);
|
||||
|
||||
DLL_EXPORT TAOS_FIELD *taos_fetch_fields(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_select_db(TAOS *taos, const char *db);
|
||||
|
@ -183,8 +181,8 @@ DLL_EXPORT int *taos_get_column_data_offset(TAOS_RES *res, int columnInde
|
|||
DLL_EXPORT int taos_validate_sql(TAOS *taos, const char *sql);
|
||||
DLL_EXPORT void taos_reset_current_db(TAOS *taos);
|
||||
|
||||
DLL_EXPORT int *taos_fetch_lengths(TAOS_RES *res);
|
||||
DLL_EXPORT TAOS_ROW *taos_result_block(TAOS_RES *res);
|
||||
DLL_EXPORT int *taos_fetch_lengths(TAOS_RES *res);
|
||||
DLL_EXPORT TAOS_ROW *taos_result_block(TAOS_RES *res);
|
||||
|
||||
DLL_EXPORT const char *taos_get_server_info(TAOS *taos);
|
||||
DLL_EXPORT const char *taos_get_client_info();
|
||||
|
@ -192,9 +190,10 @@ DLL_EXPORT const char *taos_get_client_info();
|
|||
DLL_EXPORT const char *taos_errstr(TAOS_RES *tres);
|
||||
DLL_EXPORT int taos_errno(TAOS_RES *tres);
|
||||
|
||||
DLL_EXPORT void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param);
|
||||
DLL_EXPORT void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param);
|
||||
DLL_EXPORT void taos_fetch_raw_block_a(TAOS_RES* res, __taos_async_fn_t fp, void* param);
|
||||
DLL_EXPORT void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param);
|
||||
DLL_EXPORT void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param);
|
||||
DLL_EXPORT void taos_fetch_raw_block_a(TAOS_RES* res, __taos_async_fn_t fp, void* param);
|
||||
DLL_EXPORT const void *taos_get_raw_block(TAOS_RES* res);
|
||||
|
||||
// Shuduo: temporary enable for app build
|
||||
#if 1
|
||||
|
@ -241,7 +240,10 @@ DLL_EXPORT const char *tmq_err2str(tmq_resp_err_t);
|
|||
DLL_EXPORT tmq_resp_err_t tmq_subscribe(tmq_t *tmq, const tmq_list_t *topic_list);
|
||||
DLL_EXPORT tmq_resp_err_t tmq_unsubscribe(tmq_t *tmq);
|
||||
DLL_EXPORT tmq_resp_err_t tmq_subscription(tmq_t *tmq, tmq_list_t **topics);
|
||||
DLL_EXPORT TAOS_RES *tmq_consumer_poll(tmq_t *tmq, int64_t timeout);
|
||||
|
||||
// timeout: -1 means infinitely waiting
|
||||
DLL_EXPORT TAOS_RES *tmq_consumer_poll(tmq_t *tmq, int64_t timeout);
|
||||
|
||||
DLL_EXPORT tmq_resp_err_t tmq_consumer_close(tmq_t *tmq);
|
||||
DLL_EXPORT tmq_resp_err_t tmq_commit_sync(tmq_t *tmq, const tmq_topic_vgroup_list_t *offsets);
|
||||
DLL_EXPORT void tmq_commit_async(tmq_t *tmq, const tmq_topic_vgroup_list_t *offsets, tmq_commit_cb *cb, void *param);
|
||||
|
|
|
@ -116,6 +116,8 @@ typedef struct SQueryTableDataCond {
|
|||
int32_t type; // data block load type:
|
||||
int32_t numOfTWindows;
|
||||
STimeWindow* twindows;
|
||||
int32_t startVersion;
|
||||
int32_t endVersion;
|
||||
} SQueryTableDataCond;
|
||||
|
||||
void* blockDataDestroy(SSDataBlock* pBlock);
|
||||
|
@ -159,19 +161,25 @@ typedef struct SColumn {
|
|||
} SColumn;
|
||||
|
||||
typedef struct STableBlockDistInfo {
|
||||
uint16_t rowSize;
|
||||
uint32_t rowSize;
|
||||
uint16_t numOfFiles;
|
||||
uint32_t numOfTables;
|
||||
uint32_t numOfBlocks;
|
||||
uint64_t totalSize;
|
||||
uint64_t totalRows;
|
||||
int32_t maxRows;
|
||||
int32_t minRows;
|
||||
int32_t defMinRows;
|
||||
int32_t defMaxRows;
|
||||
int32_t firstSeekTimeUs;
|
||||
uint32_t numOfRowsInMemTable;
|
||||
uint32_t numOfInmemRows;
|
||||
uint32_t numOfSmallBlocks;
|
||||
SArray* dataBlockInfos;
|
||||
int32_t blockRowsHisto[20];
|
||||
} STableBlockDistInfo;
|
||||
|
||||
int32_t tSerializeBlockDistInfo(void* buf, int32_t bufLen, const STableBlockDistInfo* pInfo);
|
||||
int32_t tDeserializeBlockDistInfo(void* buf, int32_t bufLen, STableBlockDistInfo* pInfo);
|
||||
|
||||
enum {
|
||||
FUNC_PARAM_TYPE_VALUE = 0x1,
|
||||
FUNC_PARAM_TYPE_COLUMN = 0x2,
|
||||
|
|
|
@ -1205,6 +1205,7 @@ typedef struct {
|
|||
int8_t completed; // all results are returned to client
|
||||
int8_t precision;
|
||||
int8_t compressed;
|
||||
int8_t streamBlockType;
|
||||
int32_t compLen;
|
||||
int32_t numOfRows;
|
||||
int32_t numOfCols;
|
||||
|
@ -1340,6 +1341,13 @@ typedef struct {
|
|||
int32_t tSerializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
|
||||
int32_t tDeserializeSRedistributeVgroupReq(void* buf, int32_t bufLen, SRedistributeVgroupReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
} SSplitVgroupReq;
|
||||
|
||||
int32_t tSerializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
|
||||
int32_t tDeserializeSSplitVgroupReq(void* buf, int32_t bufLen, SSplitVgroupReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
char user[TSDB_USER_LEN];
|
||||
char spi;
|
||||
|
@ -2493,15 +2501,15 @@ int32_t tSerializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq
|
|||
int32_t tDeserializeSTableIndexReq(void* buf, int32_t bufLen, STableIndexReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int8_t intervalUnit;
|
||||
int8_t slidingUnit;
|
||||
int64_t interval;
|
||||
int64_t offset;
|
||||
int64_t sliding;
|
||||
int64_t dstTbUid;
|
||||
int32_t dstVgId; // for stream
|
||||
SEpSet epSet;
|
||||
char* expr;
|
||||
int8_t intervalUnit;
|
||||
int8_t slidingUnit;
|
||||
int64_t interval;
|
||||
int64_t offset;
|
||||
int64_t sliding;
|
||||
int64_t dstTbUid;
|
||||
int32_t dstVgId; // for stream
|
||||
SEpSet epSet;
|
||||
char* expr;
|
||||
} STableIndexInfo;
|
||||
|
||||
typedef struct {
|
||||
|
@ -2510,8 +2518,7 @@ typedef struct {
|
|||
|
||||
int32_t tSerializeSTableIndexRsp(void* buf, int32_t bufLen, const STableIndexRsp* pRsp);
|
||||
int32_t tDeserializeSTableIndexRsp(void* buf, int32_t bufLen, STableIndexRsp* pRsp);
|
||||
void tFreeSTableIndexInfo(void *pInfo);
|
||||
|
||||
void tFreeSTableIndexInfo(void* pInfo);
|
||||
|
||||
typedef struct {
|
||||
int8_t mqMsgType;
|
||||
|
@ -2753,8 +2760,8 @@ typedef struct {
|
|||
char* msg;
|
||||
} SVDeleteReq;
|
||||
|
||||
int32_t tSerializeSVDeleteReq(void *buf, int32_t bufLen, SVDeleteReq *pReq);
|
||||
int32_t tDeserializeSVDeleteReq(void *buf, int32_t bufLen, SVDeleteReq *pReq);
|
||||
int32_t tSerializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
|
||||
int32_t tDeserializeSVDeleteReq(void* buf, int32_t bufLen, SVDeleteReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int64_t affectedRows;
|
||||
|
|
|
@ -157,6 +157,7 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_MND_BALANCE_VGROUP, "balance-vgroup", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_MERGE_VGROUP, "merge-vgroup", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_REDISTRIBUTE_VGROUP, "redistribute-vgroup", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_SPLIT_VGROUP, "split-vgroup", NULL, NULL)
|
||||
|
||||
TD_NEW_MSG_SEG(TDMT_VND_MSG)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_SUBMIT, "submit", SSubmitReq, SSubmitRsp)
|
||||
|
|
|
@ -192,67 +192,68 @@
|
|||
#define TK_VGROUP 174
|
||||
#define TK_MERGE 175
|
||||
#define TK_REDISTRIBUTE 176
|
||||
#define TK_SYNCDB 177
|
||||
#define TK_DELETE 178
|
||||
#define TK_NULL 179
|
||||
#define TK_NK_QUESTION 180
|
||||
#define TK_NK_ARROW 181
|
||||
#define TK_ROWTS 182
|
||||
#define TK_TBNAME 183
|
||||
#define TK_QSTARTTS 184
|
||||
#define TK_QENDTS 185
|
||||
#define TK_WSTARTTS 186
|
||||
#define TK_WENDTS 187
|
||||
#define TK_WDURATION 188
|
||||
#define TK_CAST 189
|
||||
#define TK_NOW 190
|
||||
#define TK_TODAY 191
|
||||
#define TK_TIMEZONE 192
|
||||
#define TK_COUNT 193
|
||||
#define TK_FIRST 194
|
||||
#define TK_LAST 195
|
||||
#define TK_LAST_ROW 196
|
||||
#define TK_BETWEEN 197
|
||||
#define TK_IS 198
|
||||
#define TK_NK_LT 199
|
||||
#define TK_NK_GT 200
|
||||
#define TK_NK_LE 201
|
||||
#define TK_NK_GE 202
|
||||
#define TK_NK_NE 203
|
||||
#define TK_MATCH 204
|
||||
#define TK_NMATCH 205
|
||||
#define TK_CONTAINS 206
|
||||
#define TK_JOIN 207
|
||||
#define TK_INNER 208
|
||||
#define TK_SELECT 209
|
||||
#define TK_DISTINCT 210
|
||||
#define TK_WHERE 211
|
||||
#define TK_PARTITION 212
|
||||
#define TK_BY 213
|
||||
#define TK_SESSION 214
|
||||
#define TK_STATE_WINDOW 215
|
||||
#define TK_SLIDING 216
|
||||
#define TK_FILL 217
|
||||
#define TK_VALUE 218
|
||||
#define TK_NONE 219
|
||||
#define TK_PREV 220
|
||||
#define TK_LINEAR 221
|
||||
#define TK_NEXT 222
|
||||
#define TK_HAVING 223
|
||||
#define TK_ORDER 224
|
||||
#define TK_SLIMIT 225
|
||||
#define TK_SOFFSET 226
|
||||
#define TK_LIMIT 227
|
||||
#define TK_OFFSET 228
|
||||
#define TK_ASC 229
|
||||
#define TK_NULLS 230
|
||||
#define TK_ID 231
|
||||
#define TK_NK_BITNOT 232
|
||||
#define TK_INSERT 233
|
||||
#define TK_VALUES 234
|
||||
#define TK_IMPORT 235
|
||||
#define TK_NK_SEMI 236
|
||||
#define TK_FILE 237
|
||||
#define TK_SPLIT 177
|
||||
#define TK_SYNCDB 178
|
||||
#define TK_DELETE 179
|
||||
#define TK_NULL 180
|
||||
#define TK_NK_QUESTION 181
|
||||
#define TK_NK_ARROW 182
|
||||
#define TK_ROWTS 183
|
||||
#define TK_TBNAME 184
|
||||
#define TK_QSTARTTS 185
|
||||
#define TK_QENDTS 186
|
||||
#define TK_WSTARTTS 187
|
||||
#define TK_WENDTS 188
|
||||
#define TK_WDURATION 189
|
||||
#define TK_CAST 190
|
||||
#define TK_NOW 191
|
||||
#define TK_TODAY 192
|
||||
#define TK_TIMEZONE 193
|
||||
#define TK_COUNT 194
|
||||
#define TK_FIRST 195
|
||||
#define TK_LAST 196
|
||||
#define TK_LAST_ROW 197
|
||||
#define TK_BETWEEN 198
|
||||
#define TK_IS 199
|
||||
#define TK_NK_LT 200
|
||||
#define TK_NK_GT 201
|
||||
#define TK_NK_LE 202
|
||||
#define TK_NK_GE 203
|
||||
#define TK_NK_NE 204
|
||||
#define TK_MATCH 205
|
||||
#define TK_NMATCH 206
|
||||
#define TK_CONTAINS 207
|
||||
#define TK_JOIN 208
|
||||
#define TK_INNER 209
|
||||
#define TK_SELECT 210
|
||||
#define TK_DISTINCT 211
|
||||
#define TK_WHERE 212
|
||||
#define TK_PARTITION 213
|
||||
#define TK_BY 214
|
||||
#define TK_SESSION 215
|
||||
#define TK_STATE_WINDOW 216
|
||||
#define TK_SLIDING 217
|
||||
#define TK_FILL 218
|
||||
#define TK_VALUE 219
|
||||
#define TK_NONE 220
|
||||
#define TK_PREV 221
|
||||
#define TK_LINEAR 222
|
||||
#define TK_NEXT 223
|
||||
#define TK_HAVING 224
|
||||
#define TK_ORDER 225
|
||||
#define TK_SLIMIT 226
|
||||
#define TK_SOFFSET 227
|
||||
#define TK_LIMIT 228
|
||||
#define TK_OFFSET 229
|
||||
#define TK_ASC 230
|
||||
#define TK_NULLS 231
|
||||
#define TK_ID 232
|
||||
#define TK_NK_BITNOT 233
|
||||
#define TK_INSERT 234
|
||||
#define TK_VALUES 235
|
||||
#define TK_IMPORT 236
|
||||
#define TK_NK_SEMI 237
|
||||
#define TK_FILE 238
|
||||
|
||||
#define TK_NK_SPACE 300
|
||||
#define TK_NK_COMMENT 301
|
||||
|
|
|
@ -58,7 +58,6 @@ typedef struct SFileBlockInfo {
|
|||
int32_t numBlocksOfStep;
|
||||
} SFileBlockInfo;
|
||||
|
||||
#define TSDB_BLOCK_DIST_STEP_ROWS 8
|
||||
#define MAX_INTERVAL_TIME_WINDOW 1000000 // maximum allowed time windows in final results
|
||||
|
||||
#define TOP_BOTTOM_QUERY_LIMIT 100
|
||||
|
|
|
@ -121,6 +121,7 @@ typedef enum EFunctionType {
|
|||
|
||||
// internal function
|
||||
FUNCTION_TYPE_SELECT_VALUE,
|
||||
FUNCTION_TYPE_BLOCK_DIST, // block distribution aggregate function
|
||||
|
||||
// distributed splitting functions
|
||||
FUNCTION_TYPE_APERCENTILE_PARTIAL,
|
||||
|
@ -131,6 +132,8 @@ typedef enum EFunctionType {
|
|||
FUNCTION_TYPE_HISTOGRAM_MERGE,
|
||||
FUNCTION_TYPE_HYPERLOGLOG_PARTIAL,
|
||||
FUNCTION_TYPE_HYPERLOGLOG_MERGE,
|
||||
FUNCTION_TYPE_ELAPSED_PARTIAL,
|
||||
FUNCTION_TYPE_ELAPSED_MERGE,
|
||||
|
||||
// user defined funcion
|
||||
FUNCTION_TYPE_UDF = 10000
|
||||
|
|
|
@ -141,8 +141,7 @@ void* streamDataBlockDecode(const void* buf, SStreamDataBlock* pInput);
|
|||
#endif
|
||||
|
||||
typedef struct {
|
||||
int8_t parallelizable;
|
||||
char* qmsg;
|
||||
char* qmsg;
|
||||
// followings are not applicable to encoder and decoder
|
||||
void* inputHandle;
|
||||
void* executor;
|
||||
|
@ -267,7 +266,7 @@ struct SStreamTask {
|
|||
// void* ahandle;
|
||||
};
|
||||
|
||||
SStreamTask* tNewSStreamTask(int64_t streamId, int32_t childId);
|
||||
SStreamTask* tNewSStreamTask(int64_t streamId);
|
||||
int32_t tEncodeSStreamTask(SEncoder* pEncoder, const SStreamTask* pTask);
|
||||
int32_t tDecodeSStreamTask(SDecoder* pDecoder, SStreamTask* pTask);
|
||||
void tFreeSStreamTask(SStreamTask* pTask);
|
||||
|
|
|
@ -83,8 +83,10 @@ typedef struct SReConfigCbMeta {
|
|||
SyncTerm term;
|
||||
SyncTerm currentTerm;
|
||||
SSyncCfg oldCfg;
|
||||
SSyncCfg newCfg;
|
||||
bool isDrop;
|
||||
uint64_t flag;
|
||||
uint64_t seqNum;
|
||||
} SReConfigCbMeta;
|
||||
|
||||
typedef struct SSnapshot {
|
||||
|
@ -106,7 +108,7 @@ typedef struct SSyncFSM {
|
|||
void (*FpRollBackCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta);
|
||||
|
||||
void (*FpRestoreFinishCb)(struct SSyncFSM* pFsm);
|
||||
void (*FpReConfigCb)(struct SSyncFSM* pFsm, SSyncCfg newCfg, SReConfigCbMeta cbMeta);
|
||||
void (*FpReConfigCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta cbMeta);
|
||||
|
||||
int32_t (*FpGetSnapshot)(struct SSyncFSM* pFsm, SSnapshot* pSnapshot);
|
||||
|
||||
|
@ -184,7 +186,6 @@ int64_t syncOpen(const SSyncInfo* pSyncInfo);
|
|||
void syncStart(int64_t rid);
|
||||
void syncStop(int64_t rid);
|
||||
int32_t syncSetStandby(int64_t rid);
|
||||
int32_t syncReconfig(int64_t rid, const SSyncCfg* pSyncCfg);
|
||||
ESyncState syncGetMyRole(int64_t rid);
|
||||
const char* syncGetMyRoleStr(int64_t rid);
|
||||
SyncTerm syncGetMyTerm(int64_t rid);
|
||||
|
@ -194,8 +195,10 @@ int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak);
|
|||
bool syncEnvIsStart();
|
||||
const char* syncStr(ESyncState state);
|
||||
bool syncIsRestoreFinish(int64_t rid);
|
||||
int32_t syncGetSnapshotMeta(int64_t rid, struct SSnapshotMeta* sMeta);
|
||||
|
||||
int32_t syncGetSnapshotMeta(int64_t rid, struct SSnapshotMeta* sMeta);
|
||||
int32_t syncReconfig(int64_t rid, const SSyncCfg* pNewCfg);
|
||||
int32_t syncReconfigRaw(int64_t rid, const SSyncCfg* pNewCfg, SRpcMsg* pRpcMsg);
|
||||
|
||||
// to be moved to static
|
||||
void syncStartNormal(int64_t rid);
|
||||
|
|
|
@ -85,7 +85,6 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_RPC_NETWORK_UNAVAIL TAOS_DEF_ERROR_CODE(0, 0x0102)
|
||||
#define TSDB_CODE_RPC_FQDN_ERROR TAOS_DEF_ERROR_CODE(0, 0x0103)
|
||||
#define TSDB_CODE_RPC_PORT_EADDRINUSE TAOS_DEF_ERROR_CODE(0, 0x0104)
|
||||
#define TSDB_CODE_RPC_INDIRECT_NETWORK_UNAVAIL TAOS_DEF_ERROR_CODE(0, 0x0105)
|
||||
|
||||
//client
|
||||
#define TSDB_CODE_TSC_INVALID_OPERATION TAOS_DEF_ERROR_CODE(0, 0x0200)
|
||||
|
@ -220,6 +219,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_VGROUP_ALREADY_IN_DNODE TAOS_DEF_ERROR_CODE(0, 0x0392)
|
||||
#define TSDB_CODE_MND_VGROUP_UN_CHANGED TAOS_DEF_ERROR_CODE(0, 0x0393)
|
||||
#define TSDB_CODE_MND_HAS_OFFLINE_DNODE TAOS_DEF_ERROR_CODE(0, 0x0394)
|
||||
#define TSDB_CODE_MND_INVALID_REPLICA TAOS_DEF_ERROR_CODE(0, 0x0395)
|
||||
|
||||
// mnode-stable
|
||||
#define TSDB_CODE_MND_STB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03A0)
|
||||
|
@ -260,6 +260,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_TRANS_CONFLICT TAOS_DEF_ERROR_CODE(0, 0x03D3)
|
||||
#define TSDB_CODE_MND_TRANS_UNKNOW_ERROR TAOS_DEF_ERROR_CODE(0, 0x03D4)
|
||||
#define TSDB_CODE_MND_TRANS_CLOG_IS_NULL TAOS_DEF_ERROR_CODE(0, 0x03D5)
|
||||
#define TSDB_CODE_MND_TRANS_NETWORK_UNAVAILL TAOS_DEF_ERROR_CODE(0, 0x03D6)
|
||||
|
||||
// mnode-mq
|
||||
#define TSDB_CODE_MND_TOPIC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E0)
|
||||
|
|
|
@ -692,6 +692,7 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery) {
|
|||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = qCreateQueryPlan(&cxt, &pRequest->body.pDag, pNodeList);
|
||||
tscError("0x%"PRIx64" failed to create query plan, code:%s 0x%"PRIx64, pRequest->self, tstrerror(code), pRequest->requestId);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
|
|
@ -822,10 +822,18 @@ void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) {
|
|||
void taos_fetch_raw_block_a(TAOS_RES* res, __taos_async_fn_t fp, void* param) {
|
||||
ASSERT(res != NULL && fp != NULL);
|
||||
SRequestObj *pRequest = res;
|
||||
|
||||
pRequest->body.resInfo.convertUcs4 = false;
|
||||
taos_fetch_rows_a(res, fp, param);
|
||||
}
|
||||
|
||||
const void* taos_get_raw_block(TAOS_RES* res) {
|
||||
ASSERT(res != NULL);
|
||||
SRequestObj* pRequest = res;
|
||||
|
||||
return pRequest->body.resInfo.pData;
|
||||
}
|
||||
|
||||
TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char *topic, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp,
|
||||
void *param, int interval) {
|
||||
// TODO
|
||||
|
|
|
@ -17,6 +17,9 @@
|
|||
#include "tname.h"
|
||||
#include "cJSON.h"
|
||||
#include "tglobal.h"
|
||||
#include "osSemaphore.h"
|
||||
#include "osThread.h"
|
||||
|
||||
//=================================================================================================
|
||||
|
||||
#define SPACE ' '
|
||||
|
@ -67,6 +70,9 @@ for (int i = 1; i < keyLen; ++i) { \
|
|||
|
||||
#define BINARY_ADD_LEN 2 // "binary" 2 means " "
|
||||
#define NCHAR_ADD_LEN 3 // L"nchar" 3 means L" "
|
||||
|
||||
#define MAX_RETRY_TIMES 5
|
||||
#define LINE_BATCH 20
|
||||
//=================================================================================================
|
||||
typedef TSDB_SML_PROTOCOL_TYPE SMLProtocolType;
|
||||
|
||||
|
@ -153,8 +159,17 @@ typedef struct {
|
|||
int64_t endTime;
|
||||
} SSmlCostInfo;
|
||||
|
||||
typedef struct{
|
||||
SRequestObj* request;
|
||||
SCatalog* catalog;
|
||||
tsem_t sem;
|
||||
TdThreadSpinlock lock;
|
||||
} Params;
|
||||
|
||||
typedef struct {
|
||||
int64_t id;
|
||||
Params *params;
|
||||
bool isLast;
|
||||
|
||||
SMLProtocolType protocol;
|
||||
int8_t precision;
|
||||
|
@ -303,7 +318,7 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) {
|
|||
uError("SML:0x%" PRIx64 " apply schema action. reset query cache. error: %s", info->id, taos_errstr(res2));
|
||||
}
|
||||
taos_free_result(res2);
|
||||
taosMsleep(10);
|
||||
taosMsleep(500);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -327,7 +342,7 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) {
|
|||
uError("SML:0x%" PRIx64 " apply schema action. reset query cache. error: %s", info->id, taos_errstr(res2));
|
||||
}
|
||||
taos_free_result(res2);
|
||||
taosMsleep(10);
|
||||
taosMsleep(500);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -350,7 +365,7 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) {
|
|||
uError("SML:0x%" PRIx64 " apply schema action. reset query cache. error: %s", info->id, taos_errstr(res2));
|
||||
}
|
||||
taos_free_result(res2);
|
||||
taosMsleep(10);
|
||||
taosMsleep(500);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -373,7 +388,7 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) {
|
|||
uError("SML:0x%" PRIx64 " apply schema action. reset query cache. error: %s", info->id, taos_errstr(res2));
|
||||
}
|
||||
taos_free_result(res2);
|
||||
taosMsleep(10);
|
||||
taosMsleep(500);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -424,7 +439,7 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) {
|
|||
uError("SML:0x%" PRIx64 " apply schema action. reset query cache. error: %s", info->id, taos_errstr(res2));
|
||||
}
|
||||
taos_free_result(res2);
|
||||
taosMsleep(10);
|
||||
taosMsleep(500);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -541,56 +556,6 @@ end:
|
|||
return code;
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
|
||||
/* Field Escape charaters
|
||||
1: measurement Comma,Space
|
||||
2: tag_key, tag_value, field_key Comma,Equal Sign,Space
|
||||
3: field_value Double quote,Backslash
|
||||
*/
|
||||
//static void escapeSpecialCharacter(uint8_t field, const char **pos) {
|
||||
// const char *cur = *pos;
|
||||
// if (*cur != '\\') {
|
||||
// return;
|
||||
// }
|
||||
// switch (field) {
|
||||
// case 1:
|
||||
// switch (*(cur + 1)) {
|
||||
// case ',':
|
||||
// case ' ':
|
||||
// cur++;
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// break;
|
||||
// case 2:
|
||||
// switch (*(cur + 1)) {
|
||||
// case ',':
|
||||
// case ' ':
|
||||
// case '=':
|
||||
// cur++;
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// break;
|
||||
// case 3:
|
||||
// switch (*(cur + 1)) {
|
||||
// case '"':
|
||||
// case '\\':
|
||||
// cur++;
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// *pos = cur;
|
||||
//}
|
||||
|
||||
static bool smlParseNumber(SSmlKv *kvVal, SSmlMsgBuf *msg){
|
||||
const char *pVal = kvVal->value;
|
||||
int32_t len = kvVal->length;
|
||||
|
@ -1426,6 +1391,7 @@ static void smlDestroyInfo(SSmlHandle* info){
|
|||
if(!info->dataFormat){
|
||||
taosArrayDestroy(info->colsContainer);
|
||||
}
|
||||
destroyRequest(info->pRequest);
|
||||
taosMemoryFreeClear(info);
|
||||
}
|
||||
|
||||
|
@ -1453,11 +1419,6 @@ static SSmlHandle* smlBuildSmlInfo(TAOS* taos, SRequestObj* request, SMLProtocol
|
|||
((SVnodeModifOpStmt*)(info->pQuery->pRoot))->payloadType = PAYLOAD_TYPE_KV;
|
||||
|
||||
info->taos = (STscObj *)taos;
|
||||
code = catalogGetHandle(info->taos->pAppInfo->clusterId, &info->pCatalog);
|
||||
if(code != TSDB_CODE_SUCCESS){
|
||||
uError("SML:0x%"PRIx64" get catalog error %d", info->id, code);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
info->precision = precision;
|
||||
info->protocol = protocol;
|
||||
|
@ -2206,7 +2167,6 @@ end:
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int32_t smlInsertData(SSmlHandle* info) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
|
@ -2248,10 +2208,12 @@ static int32_t smlInsertData(SSmlHandle* info) {
|
|||
}
|
||||
info->cost.insertRpcTime = taosGetTimestampUs();
|
||||
|
||||
launchQueryImpl(info->pRequest, info->pQuery, true, NULL);
|
||||
//launchQueryImpl(info->pRequest, info->pQuery, false, NULL);
|
||||
// info->affectedRows = taos_affected_rows(info->pRequest);
|
||||
// return info->pRequest->code;
|
||||
|
||||
info->affectedRows = taos_affected_rows(info->pRequest);
|
||||
return info->pRequest->code;
|
||||
launchAsyncQuery(info->pRequest, info->pQuery);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void smlPrintStatisticInfo(SSmlHandle *info){
|
||||
|
@ -2311,7 +2273,7 @@ static int smlProcess(SSmlHandle *info, char* lines[], int numLines) {
|
|||
do{
|
||||
code = smlModifyDBSchemas(info);
|
||||
if (code == 0) break;
|
||||
} while (retryNum++ < taosHashGetSize(info->superTables));
|
||||
} while (retryNum++ < taosHashGetSize(info->superTables) * MAX_RETRY_TIMES);
|
||||
|
||||
if (code != 0) {
|
||||
uError("SML:0x%"PRIx64" smlModifyDBSchemas error : %s", info->id, tstrerror(code));
|
||||
|
@ -2332,30 +2294,48 @@ cleanup:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t isSchemalessDb(SSmlHandle* info){
|
||||
static int32_t isSchemalessDb(STscObj *taos, SCatalog *catalog){
|
||||
SName name;
|
||||
tNameSetDbName(&name, info->taos->acctId, info->taos->db, strlen(info->taos->db));
|
||||
tNameSetDbName(&name, taos->acctId, taos->db, strlen(taos->db));
|
||||
char dbFname[TSDB_DB_FNAME_LEN] = {0};
|
||||
tNameGetFullDbName(&name, dbFname);
|
||||
SDbCfgInfo pInfo = {0};
|
||||
SEpSet ep = getEpSet_s(&info->taos->pAppInfo->mgmtEp);
|
||||
SEpSet ep = getEpSet_s(&taos->pAppInfo->mgmtEp);
|
||||
|
||||
int32_t code = catalogGetDBCfg(info->pCatalog, info->taos->pAppInfo->pTransporter, &ep, dbFname, &pInfo);
|
||||
int32_t code = catalogGetDBCfg(catalog, taos->pAppInfo->pTransporter, &ep, dbFname, &pInfo);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
info->pRequest->code = code;
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "catalogGetDBCfg error, code:", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
taosArrayDestroy(pInfo.pRetensions);
|
||||
|
||||
if (!pInfo.schemaless){
|
||||
info->pRequest->code = TSDB_CODE_SML_INVALID_DB_CONF;
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "can not insert into schemaless db:", dbFname);
|
||||
return TSDB_CODE_SML_INVALID_DB_CONF;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void smlInsertCallback(void* param, void* res, int32_t code) {
|
||||
SRequestObj *pRequest = (SRequestObj *)res;
|
||||
SSmlHandle* info = (SSmlHandle *)param;
|
||||
|
||||
// lock
|
||||
if(code != TSDB_CODE_SUCCESS){
|
||||
taosThreadSpinLock(&info->params->lock);
|
||||
info->params->request->code = code;
|
||||
taosThreadSpinUnlock(&info->params->lock);
|
||||
}
|
||||
// unlock
|
||||
|
||||
printf("SML:0x%" PRIx64 " insert finished, code: %d, total: %d\n", info->id, code, info->affectedRows);
|
||||
Params *pParam = info->params;
|
||||
bool isLast = info->isLast;
|
||||
smlDestroyInfo(info);
|
||||
|
||||
if(isLast){
|
||||
tsem_post(&pParam->sem);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* taos_schemaless_insert() parse and insert data points into database according to
|
||||
* different protocol.
|
||||
|
@ -2384,48 +2364,95 @@ TAOS_RES* taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int pr
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SSmlHandle* info = smlBuildSmlInfo(taos, request, (SMLProtocolType)protocol, precision);
|
||||
if(!info){
|
||||
return (TAOS_RES*)request;
|
||||
}
|
||||
((STscObj *)taos)->schemalessType = 1;
|
||||
SSmlMsgBuf msg = {ERROR_MSG_BUF_DEFAULT_SIZE, request->msgBuf};
|
||||
|
||||
info->taos->schemalessType = 1;
|
||||
if(request->pDb == NULL){
|
||||
request->code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "Database not specified", NULL);
|
||||
int cnt = ceil(((double)numLines)/LINE_BATCH);
|
||||
Params params;
|
||||
params.request = request;
|
||||
tsem_init(¶ms.sem, 0, 0);
|
||||
taosThreadSpinInit(&(params.lock), 0);
|
||||
|
||||
int32_t code = catalogGetHandle(((STscObj *)taos)->pAppInfo->clusterId, ¶ms.catalog);
|
||||
if(code != TSDB_CODE_SUCCESS){
|
||||
uError("SML get catalog error %d", code);
|
||||
request->code = code;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if(isSchemalessDb(info) != TSDB_CODE_SUCCESS){
|
||||
if(request->pDb == NULL){
|
||||
request->code = TSDB_CODE_PAR_DB_NOT_SPECIFIED;
|
||||
smlBuildInvalidDataMsg(&msg, "Database not specified", NULL);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if(isSchemalessDb(((STscObj *)taos), params.catalog) != TSDB_CODE_SUCCESS){
|
||||
request->code = TSDB_CODE_SML_INVALID_DB_CONF;
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "Cannot write data to a non schemaless database", NULL);
|
||||
smlBuildInvalidDataMsg(&msg, "Cannot write data to a non schemaless database", NULL);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!lines) {
|
||||
request->code = TSDB_CODE_SML_INVALID_DATA;
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "lines is null", NULL);
|
||||
smlBuildInvalidDataMsg(&msg, "lines is null", NULL);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if(protocol < TSDB_SML_LINE_PROTOCOL || protocol > TSDB_SML_JSON_PROTOCOL){
|
||||
request->code = TSDB_CODE_SML_INVALID_PROTOCOL_TYPE;
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "protocol invalidate", NULL);
|
||||
smlBuildInvalidDataMsg(&msg, "protocol invalidate", NULL);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if(protocol == TSDB_SML_LINE_PROTOCOL && (precision < TSDB_SML_TIMESTAMP_NOT_CONFIGURED || precision > TSDB_SML_TIMESTAMP_NANO_SECONDS)){
|
||||
request->code = TSDB_CODE_SML_INVALID_PRECISION_TYPE;
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "precision invalidate for line protocol", NULL);
|
||||
smlBuildInvalidDataMsg(&msg, "precision invalidate for line protocol", NULL);
|
||||
goto end;
|
||||
}
|
||||
|
||||
info->pRequest->code = smlProcess(info, lines, numLines);
|
||||
for (int i = 0; i < cnt; ++i) {
|
||||
SRequestObj* req = (SRequestObj*)createRequest((STscObj *)taos, TSDB_SQL_INSERT);
|
||||
if(!req){
|
||||
request->code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
uError("SML:taos_schemaless_insert error request is null");
|
||||
goto end;
|
||||
}
|
||||
SSmlHandle* info = smlBuildSmlInfo(taos, req, (SMLProtocolType)protocol, precision);
|
||||
if(!info){
|
||||
request->code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
uError("SML:taos_schemaless_insert error SSmlHandle is null");
|
||||
goto end;
|
||||
}
|
||||
|
||||
int32_t perBatch = LINE_BATCH;
|
||||
|
||||
if(numLines > perBatch){
|
||||
numLines -= perBatch;
|
||||
info->isLast = false;
|
||||
}else{
|
||||
perBatch = numLines;
|
||||
numLines = 0;
|
||||
info->isLast = true;
|
||||
}
|
||||
|
||||
info->params = ¶ms;
|
||||
info->pCatalog = params.catalog;
|
||||
info->affectedRows = perBatch;
|
||||
info->pRequest->body.queryFp = smlInsertCallback;
|
||||
info->pRequest->body.param = info;
|
||||
code = smlProcess(info, lines, perBatch);
|
||||
lines += perBatch;
|
||||
if (code != TSDB_CODE_SUCCESS){
|
||||
info->pRequest->body.queryFp(info, req, code);
|
||||
}
|
||||
}
|
||||
tsem_wait(¶ms.sem);
|
||||
|
||||
end:
|
||||
info->taos->schemalessType = 0;
|
||||
uDebug("result:%s", info->msgBuf.buf);
|
||||
smlDestroyInfo(info);
|
||||
taosThreadSpinDestroy(¶ms.lock);
|
||||
tsem_destroy(¶ms.sem);
|
||||
((STscObj *)taos)->schemalessType = 0;
|
||||
uDebug("result:%s", request->msgBuf);
|
||||
return (TAOS_RES*)request;
|
||||
}
|
||||
|
||||
|
|
|
@ -1281,7 +1281,7 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t timeout) {
|
|||
if (rspObj) {
|
||||
return (TAOS_RES*)rspObj;
|
||||
}
|
||||
if (timeout != 0) {
|
||||
if (timeout != -1) {
|
||||
int64_t endTime = taosGetTimestampMs();
|
||||
int64_t leftTime = endTime - startTime;
|
||||
if (leftTime > timeout) {
|
||||
|
|
|
@ -1325,7 +1325,7 @@ TEST(testCase, sml_oom_Test) {
|
|||
pRes = taos_query(taos, "use oom");
|
||||
taos_free_result(pRes);
|
||||
|
||||
TAOS_RES* res = taos_schemaless_insert(taos, (char**)sql, 100, TSDB_SML_LINE_PROTOCOL, 0);
|
||||
TAOS_RES* res = taos_schemaless_insert(taos, (char**)sql, sizeof(sql)/sizeof(sql[0]), TSDB_SML_LINE_PROTOCOL, 0);
|
||||
ASSERT_EQ(taos_errno(res), 0);
|
||||
taos_free_result(pRes);
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@ static const SSysDbTableSchema transSchema[] = {
|
|||
{.name = "db", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
{.name = "failed_times", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||
{.name = "last_exec_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
||||
{.name = "last_error", .bytes = (TSDB_TRANS_ERROR_LEN - 1) + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
{.name = "last_action_info", .bytes = (TSDB_TRANS_ERROR_LEN - 1) + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
};
|
||||
|
||||
static const SSysDbTableSchema configSchema[] = {
|
||||
|
|
|
@ -1219,6 +1219,8 @@ SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData) {
|
|||
pBlock->info.hasVarCol = pDataBlock->info.hasVarCol;
|
||||
pBlock->info.rowSize = pDataBlock->info.rowSize;
|
||||
pBlock->info.groupId = pDataBlock->info.groupId;
|
||||
pBlock->info.childId = pDataBlock->info.childId;
|
||||
pBlock->info.type = pDataBlock->info.type;
|
||||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData colInfo = {0};
|
||||
|
@ -1499,6 +1501,7 @@ void blockDebugShowData(const SArray* dataBlocks, const char* flag) {
|
|||
SSDataBlock* pDataBlock = taosArrayGet(dataBlocks, i);
|
||||
int32_t colNum = pDataBlock->info.numOfCols;
|
||||
int32_t rows = pDataBlock->info.rows;
|
||||
printf("%s |block type %d |child id %d|\n", flag, (int32_t)pDataBlock->info.type, pDataBlock->info.childId);
|
||||
for (int32_t j = 0; j < rows; j++) {
|
||||
printf("%s |", flag);
|
||||
for (int32_t k = 0; k < colNum; k++) {
|
||||
|
|
|
@ -2419,7 +2419,7 @@ int32_t tDeserializeSTableIndexReq(void *buf, int32_t bufLen, STableIndexReq *pR
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tSerializeSTableIndexInfo(SEncoder *pEncoder, STableIndexInfo* pInfo) {
|
||||
int32_t tSerializeSTableIndexInfo(SEncoder *pEncoder, STableIndexInfo *pInfo) {
|
||||
if (tEncodeI8(pEncoder, pInfo->intervalUnit) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pInfo->slidingUnit) < 0) return -1;
|
||||
if (tEncodeI64(pEncoder, pInfo->interval) < 0) return -1;
|
||||
|
@ -2441,7 +2441,7 @@ int32_t tSerializeSTableIndexRsp(void *buf, int32_t bufLen, const STableIndexRsp
|
|||
if (tEncodeI32(&encoder, num) < 0) return -1;
|
||||
if (num > 0) {
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
STableIndexInfo* pInfo = (STableIndexInfo*)taosArrayGet(pRsp->pIndex, i);
|
||||
STableIndexInfo *pInfo = (STableIndexInfo *)taosArrayGet(pRsp->pIndex, i);
|
||||
if (tSerializeSTableIndexInfo(&encoder, pInfo) < 0) return -1;
|
||||
}
|
||||
}
|
||||
|
@ -2491,12 +2491,12 @@ int32_t tDeserializeSTableIndexRsp(void *buf, int32_t bufLen, STableIndexRsp *pR
|
|||
return 0;
|
||||
}
|
||||
|
||||
void tFreeSTableIndexInfo(void* info) {
|
||||
void tFreeSTableIndexInfo(void *info) {
|
||||
if (NULL == info) {
|
||||
return;
|
||||
}
|
||||
|
||||
STableIndexInfo *pInfo = (STableIndexInfo*)info;
|
||||
STableIndexInfo *pInfo = (STableIndexInfo *)info;
|
||||
|
||||
taosMemoryFree(pInfo->expr);
|
||||
}
|
||||
|
@ -3448,6 +3448,31 @@ int32_t tDeserializeSRedistributeVgroupReq(void *buf, int32_t bufLen, SRedistrib
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tSerializeSSplitVgroupReq(void *buf, int32_t bufLen, SSplitVgroupReq *pReq) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->vgId) < 0) return -1;
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tEncoderClear(&encoder);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSSplitVgroupReq(void *buf, int32_t bufLen, SSplitVgroupReq *pReq) {
|
||||
SDecoder decoder = {0};
|
||||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->vgId) < 0) return -1;
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tSerializeSDCreateMnodeReq(void *buf, int32_t bufLen, SDCreateMnodeReq *pReq) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
|
|
@ -170,6 +170,9 @@ SArray *mmGetMsgHandles() {
|
|||
if (dmSetMgmtHandle(pArray, TDMT_MND_COMPACT_DB, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_GET_DB_CFG, mmPutNodeMsgToReadQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_VGROUP_LIST, mmPutNodeMsgToReadQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_REDISTRIBUTE_VGROUP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_MERGE_VGROUP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_BALANCE_VGROUP, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_FUNC, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_RETRIEVE_FUNC, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_FUNC, mmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
|
|
|
@ -120,10 +120,10 @@ typedef struct {
|
|||
SArray* commitActions;
|
||||
int64_t createdTime;
|
||||
int64_t lastExecTime;
|
||||
int32_t lastErrorAction;
|
||||
int32_t lastAction;
|
||||
int32_t lastErrorNo;
|
||||
tmsg_t lastErrorMsgType;
|
||||
SEpSet lastErrorEpset;
|
||||
tmsg_t lastMsgType;
|
||||
SEpSet lastEpset;
|
||||
char dbname[TSDB_DB_FNAME_LEN];
|
||||
int32_t startFunc;
|
||||
int32_t stopFunc;
|
||||
|
@ -484,6 +484,7 @@ typedef struct {
|
|||
int64_t stbUid;
|
||||
SHashObj* consumerHash; // consumerId -> SMqConsumerEp
|
||||
SArray* unassignedVgs; // SArray<SMqVgEp*>
|
||||
char dbName[TSDB_DB_FNAME_LEN];
|
||||
} SMqSubscribeObj;
|
||||
|
||||
SMqSubscribeObj* tNewSubscribeObj(const char key[TSDB_SUBSCRIBE_KEY_LEN]);
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
|
||||
#define MND_CONSUMER_LOST_HB_CNT 3
|
||||
|
||||
static int8_t mqRebLock = 0;
|
||||
static int8_t mqRebInExecCnt = 0;
|
||||
|
||||
static const char *mndConsumerStatusName(int status);
|
||||
|
||||
|
@ -76,15 +76,15 @@ int32_t mndInitConsumer(SMnode *pMnode) {
|
|||
void mndCleanupConsumer(SMnode *pMnode) {}
|
||||
|
||||
bool mndRebTryStart() {
|
||||
int8_t old = atomic_val_compare_exchange_8(&mqRebLock, 0, 1);
|
||||
int8_t old = atomic_val_compare_exchange_8(&mqRebInExecCnt, 0, 1);
|
||||
return old == 0;
|
||||
}
|
||||
|
||||
void mndRebEnd() { atomic_sub_fetch_8(&mqRebLock, 1); }
|
||||
void mndRebEnd() { atomic_sub_fetch_8(&mqRebInExecCnt, 1); }
|
||||
|
||||
void mndRebCntInc() { atomic_add_fetch_8(&mqRebLock, 1); }
|
||||
void mndRebCntInc() { atomic_add_fetch_8(&mqRebInExecCnt, 1); }
|
||||
|
||||
void mndRebCntDec() { atomic_sub_fetch_8(&mqRebLock, 1); }
|
||||
void mndRebCntDec() { atomic_sub_fetch_8(&mqRebInExecCnt, 1); }
|
||||
|
||||
static int32_t mndProcessConsumerLostMsg(SRpcMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->info.node;
|
||||
|
@ -92,7 +92,6 @@ static int32_t mndProcessConsumerLostMsg(SRpcMsg *pMsg) {
|
|||
SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, pLostMsg->consumerId);
|
||||
ASSERT(pConsumer);
|
||||
|
||||
|
||||
mInfo("receive consumer lost msg, consumer id %ld, status %s", pLostMsg->consumerId,
|
||||
mndConsumerStatusName(pConsumer->status));
|
||||
|
||||
|
@ -106,7 +105,7 @@ static int32_t mndProcessConsumerLostMsg(SRpcMsg *pMsg) {
|
|||
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, pMsg);
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pMsg);
|
||||
if (pTrans == NULL) goto FAIL;
|
||||
if (mndSetConsumerCommitLogs(pMnode, pTrans, pConsumerNew) != 0) goto FAIL;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto FAIL;
|
||||
|
@ -125,6 +124,14 @@ static int32_t mndProcessConsumerRecoverMsg(SRpcMsg *pMsg) {
|
|||
SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, pRecoverMsg->consumerId);
|
||||
ASSERT(pConsumer);
|
||||
|
||||
mInfo("receive consumer recover msg, consumer id %ld, status %s", pRecoverMsg->consumerId,
|
||||
mndConsumerStatusName(pConsumer->status));
|
||||
|
||||
if (pConsumer->status != MQ_CONSUMER_STATUS__READY) {
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
SMqConsumerObj *pConsumerNew = tNewSMqConsumerObj(pConsumer->consumerId, pConsumer->cgroup);
|
||||
pConsumerNew->updateType = CONSUMER_UPDATE__RECOVER;
|
||||
|
||||
|
@ -844,10 +851,11 @@ static int32_t mndRetrieveConsumer(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *
|
|||
topicSz = 1;
|
||||
}
|
||||
|
||||
if (numOfRows + topicSz > rowsCapacity) {
|
||||
blockDataEnsureCapacity(pBlock, numOfRows + topicSz);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < topicSz; i++) {
|
||||
if (numOfRows + topicSz > rowsCapacity) {
|
||||
blockDataEnsureCapacity(pBlock, numOfRows + topicSz);
|
||||
}
|
||||
SColumnInfoData *pColInfo;
|
||||
int32_t cols = 0;
|
||||
|
||||
|
|
|
@ -415,6 +415,7 @@ SMqSubscribeObj *tCloneSubscribeObj(const SMqSubscribeObj *pSub) {
|
|||
taosHashPut(pSubNew->consumerHash, &newEp.consumerId, sizeof(int64_t), &newEp, sizeof(SMqConsumerEp));
|
||||
}
|
||||
pSubNew->unassignedVgs = taosArrayDeepCopy(pSub->unassignedVgs, (FCopy)tCloneSMqVgEp);
|
||||
memcpy(pSubNew->dbName, pSub->dbName, TSDB_DB_FNAME_LEN);
|
||||
return pSubNew;
|
||||
}
|
||||
|
||||
|
@ -445,6 +446,7 @@ int32_t tEncodeSubscribeObj(void **buf, const SMqSubscribeObj *pSub) {
|
|||
}
|
||||
ASSERT(cnt == sz);
|
||||
tlen += taosEncodeArray(buf, pSub->unassignedVgs, (FEncode)tEncodeSMqVgEp);
|
||||
tlen += taosEncodeString(buf, pSub->dbName);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
|
@ -467,6 +469,7 @@ void *tDecodeSubscribeObj(const void *buf, SMqSubscribeObj *pSub) {
|
|||
}
|
||||
|
||||
buf = taosDecodeArray(buf, &pSub->unassignedVgs, (FDecode)tDecodeSMqVgEp, sizeof(SMqVgEp));
|
||||
buf = taosDecodeStringTo(buf, pSub->dbName);
|
||||
return (void *)buf;
|
||||
}
|
||||
|
||||
|
|
|
@ -217,8 +217,8 @@ static int32_t mndInitSteps(SMnode *pMnode) {
|
|||
if (mndAllocStep(pMnode, "mnode-cluster", mndInitCluster, mndCleanupCluster) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-mnode", mndInitMnode, mndCleanupMnode) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-qnode", mndInitQnode, mndCleanupQnode) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-qnode", mndInitSnode, mndCleanupSnode) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-qnode", mndInitBnode, mndCleanupBnode) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-snode", mndInitSnode, mndCleanupSnode) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-bnode", mndInitBnode, mndCleanupBnode) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-dnode", mndInitDnode, mndCleanupDnode) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-user", mndInitUser, mndCleanupUser) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-grant", mndInitGrant, mndCleanupGrant) != 0) return -1;
|
||||
|
|
|
@ -35,6 +35,13 @@
|
|||
|
||||
extern bool tsStreamSchedV;
|
||||
|
||||
static int32_t mndAddTaskToTaskSet(SArray* pArray, SStreamTask* pTask) {
|
||||
int32_t childId = taosArrayGetSize(pArray);
|
||||
pTask->childId = childId;
|
||||
taosArrayPush(pArray, &pTask);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndConvertRSmaTask(const char* ast, int64_t uid, int8_t triggerType, int64_t watermark, char** pStr,
|
||||
int32_t* pLen, double filesFactor) {
|
||||
SNode* pAst = NULL;
|
||||
|
@ -190,12 +197,12 @@ int32_t mndAddShuffledSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* p
|
|||
sdbRelease(pSdb, pVgroup);
|
||||
continue;
|
||||
}
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid, 0);
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid);
|
||||
if (pTask == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
taosArrayPush(tasks, &pTask);
|
||||
mndAddTaskToTaskSet(tasks, pTask);
|
||||
|
||||
pTask->nodeId = pVgroup->vgId;
|
||||
pTask->epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
|
@ -230,12 +237,12 @@ int32_t mndAddShuffledSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* p
|
|||
int32_t mndAddFixedSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
||||
ASSERT(pStream->fixedSinkVgId != 0);
|
||||
SArray* tasks = taosArrayGetP(pStream->tasks, 0);
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid, 0);
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid);
|
||||
if (pTask == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
taosArrayPush(tasks, &pTask);
|
||||
mndAddTaskToTaskSet(tasks, pTask);
|
||||
|
||||
pTask->nodeId = pStream->fixedSinkVgId;
|
||||
#if 0
|
||||
|
@ -322,7 +329,8 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
|||
sdbRelease(pSdb, pVgroup);
|
||||
continue;
|
||||
}
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid, 0);
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid);
|
||||
mndAddTaskToTaskSet(taskOneLevel, pTask);
|
||||
// source part
|
||||
pTask->sourceType = TASK_SOURCE__SCAN;
|
||||
pTask->inputType = TASK_INPUT_TYPE__SUMBIT_BLOCK;
|
||||
|
@ -371,14 +379,12 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
|||
|
||||
// exec part
|
||||
pTask->execType = TASK_EXEC__PIPE;
|
||||
pTask->exec.parallelizable = 1;
|
||||
if (mndAssignTaskToVg(pMnode, pTrans, pTask, plan, pVgroup) < 0) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
qDestroyQueryPlan(pPlan);
|
||||
return -1;
|
||||
}
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
taosArrayPush(taskOneLevel, &pTask);
|
||||
}
|
||||
} else {
|
||||
// merge plan
|
||||
|
@ -387,7 +393,8 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
|||
|
||||
// else, assign to vnode
|
||||
ASSERT(plan->subplanType == SUBPLAN_TYPE_MERGE);
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid, 0);
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid);
|
||||
mndAddTaskToTaskSet(taskOneLevel, pTask);
|
||||
|
||||
// source part, currently only support multi source
|
||||
pTask->sourceType = TASK_SOURCE__PIPE;
|
||||
|
@ -449,7 +456,6 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
|||
|
||||
// exec part
|
||||
pTask->execType = TASK_EXEC__MERGE;
|
||||
pTask->exec.parallelizable = 0;
|
||||
SVgObj* pVgroup = mndSchedFetchOneVg(pMnode, pStream->dbUid);
|
||||
ASSERT(pVgroup);
|
||||
if (mndAssignTaskToVg(pMnode, pTrans, pTask, plan, pVgroup) < 0) {
|
||||
|
@ -458,12 +464,12 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
|||
return -1;
|
||||
}
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
taosArrayPush(taskOneLevel, &pTask);
|
||||
}
|
||||
|
||||
taosArrayPush(pStream->tasks, &taskOneLevel);
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (totLevel == 2) {
|
||||
void* pIter = NULL;
|
||||
while (1) {
|
||||
|
@ -474,7 +480,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
|||
sdbRelease(pSdb, pVgroup);
|
||||
continue;
|
||||
}
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid, 0);
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid);
|
||||
|
||||
// source part
|
||||
pTask->sourceType = TASK_SOURCE__MERGE;
|
||||
|
@ -488,9 +494,9 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
|||
|
||||
// exec part
|
||||
pTask->execType = TASK_EXEC__NONE;
|
||||
pTask->exec.parallelizable = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// free memory
|
||||
qDestroyQueryPlan(pPlan);
|
||||
|
|
|
@ -402,7 +402,8 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
|
|||
}
|
||||
|
||||
static int32_t mndPersistRebResult(SMnode *pMnode, SRpcMsg *pMsg, const SMqRebOutputObj *pOutput) {
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pMsg);
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_DB_INSIDE, pMsg);
|
||||
mndTransSetDbName(pTrans, pOutput->pSub->dbName);
|
||||
if (pTrans == NULL) return -1;
|
||||
|
||||
// make txn:
|
||||
|
@ -547,6 +548,7 @@ static int32_t mndProcessRebalanceReq(SRpcMsg *pMsg) {
|
|||
taosRLockLatch(&pTopic->lock);
|
||||
|
||||
rebOutput.pSub = mndCreateSub(pMnode, pTopic, pRebInfo->key);
|
||||
memcpy(rebOutput.pSub->dbName, pTopic->db, TSDB_DB_FNAME_LEN);
|
||||
ASSERT(taosHashGetSize(rebOutput.pSub->consumerHash) == 0);
|
||||
|
||||
taosRUnLockLatch(&pTopic->lock);
|
||||
|
|
|
@ -96,10 +96,18 @@ void mndRestoreFinish(struct SSyncFSM *pFsm) {
|
|||
}
|
||||
}
|
||||
|
||||
void mndReConfig(struct SSyncFSM *pFsm, SSyncCfg newCfg, SReConfigCbMeta cbMeta) {
|
||||
void mndReConfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReConfigCbMeta cbMeta) {
|
||||
SMnode *pMnode = pFsm->data;
|
||||
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
||||
|
||||
#if 0
|
||||
// send response
|
||||
SRpcMsg rpcMsg = {.msgType = pMsg->msgType, .contLen = pMsg->contLen, .conn.applyIndex = cbMeta.index};
|
||||
rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen);
|
||||
memcpy(rpcMsg.pCont, pMsg->pCont, pMsg->contLen);
|
||||
syncGetAndDelRespRpc(pMnode->syncMgmt.sync, cbMeta.seqNum, &rpcMsg.info);
|
||||
#endif
|
||||
|
||||
pMgmt->errCode = cbMeta.code;
|
||||
mInfo("trans:-1, sync reconfig is proposed, saved:%d code:0x%x, index:%" PRId64 " term:%" PRId64, pMgmt->transId,
|
||||
cbMeta.code, cbMeta.index, cbMeta.term);
|
||||
|
|
|
@ -87,30 +87,22 @@ int32_t mndCheckColAndTagModifiable(SMnode *pMnode, int64_t suid, col_id_t colId
|
|||
SNode *pAst = NULL;
|
||||
if (nodesStringToNode(pTopic->ast, &pAst) != 0) {
|
||||
ASSERT(0);
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
SHashObj *pColHash = NULL;
|
||||
SNodeList *pNodeList = NULL;
|
||||
nodesCollectColumns((SSelectStmt *)pAst, SQL_CLAUSE_FROM, NULL, COLLECT_COL_TYPE_ALL, &pNodeList);
|
||||
SNode *pNode = NULL;
|
||||
FOREACH(pNode, pNodeList) {
|
||||
SColumnNode *pCol = (SColumnNode *)pNode;
|
||||
if (pCol->tableId != suid) goto NEXT;
|
||||
if (pColHash == NULL) {
|
||||
pColHash = taosHashInit(0, taosGetDefaultHashFunction(TSDB_DATA_TYPE_SMALLINT), false, HASH_NO_LOCK);
|
||||
}
|
||||
if (pCol->colId > 0) {
|
||||
taosHashPut(pColHash, &pCol->colId, sizeof(int16_t), NULL, 0);
|
||||
if (pCol->colId > 0 && pCol->colId == colId) {
|
||||
found = true;
|
||||
goto NEXT;
|
||||
}
|
||||
mTrace("topic:%s, colId:%d is used", pTopic->name, pCol->colId);
|
||||
}
|
||||
|
||||
if (taosHashGet(pColHash, &colId, sizeof(int16_t)) != NULL) {
|
||||
found = true;
|
||||
goto NEXT;
|
||||
}
|
||||
|
||||
NEXT:
|
||||
sdbRelease(pSdb, pTopic);
|
||||
nodesDestroyNode(pAst);
|
||||
|
@ -563,7 +555,7 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
|
|||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
mndReleaseTopic(pMnode, pTopic);
|
||||
terrno = TSDB_CODE_MND_TOPIC_SUBSCRIBED;
|
||||
mError("topic:%s, failed to drop since subscribed by consumer %ld from cgroup %s", dropReq.name,
|
||||
mError("topic:%s, failed to drop since subscribed by consumer %ld in consumer group %s", dropReq.name,
|
||||
pConsumer->consumerId, pConsumer->cgroup);
|
||||
return -1;
|
||||
}
|
||||
|
@ -580,7 +572,8 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
|
|||
}
|
||||
#endif
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq);
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_DB_INSIDE, pReq);
|
||||
mndTransSetDbName(pTrans, pTopic->db);
|
||||
if (pTrans == NULL) {
|
||||
mError("topic:%s, failed to drop since %s", pTopic->name, terrstr());
|
||||
return -1;
|
||||
|
|
|
@ -781,7 +781,7 @@ static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) {
|
|||
sendRsp = true;
|
||||
}
|
||||
} else {
|
||||
if (pTrans->stage == TRN_STAGE_REDO_ACTION && pTrans->failedTimes > 3) {
|
||||
if (pTrans->stage == TRN_STAGE_REDO_ACTION && pTrans->failedTimes > 2) {
|
||||
if (code == 0) code = TSDB_CODE_MND_TRANS_UNKNOW_ERROR;
|
||||
sendRsp = true;
|
||||
}
|
||||
|
@ -791,7 +791,7 @@ static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) {
|
|||
mDebug("trans:%d, send rsp, code:0x%x stage:%s app:%p", pTrans->id, code, mndTransStr(pTrans->stage),
|
||||
pTrans->rpcInfo.ahandle);
|
||||
if (code == TSDB_CODE_RPC_NETWORK_UNAVAIL) {
|
||||
code = TSDB_CODE_RPC_INDIRECT_NETWORK_UNAVAIL;
|
||||
code = TSDB_CODE_MND_TRANS_NETWORK_UNAVAILL;
|
||||
}
|
||||
SRpcMsg rspMsg = {.code = code, .info = pTrans->rpcInfo};
|
||||
|
||||
|
@ -894,10 +894,19 @@ static int32_t mndTransWriteSingleLog(SMnode *pMnode, STrans *pTrans, STransActi
|
|||
code = 0;
|
||||
mDebug("trans:%d, %s:%d write to sdb, type:%s status:%s", pTrans->id, mndTransStr(pAction->stage), pAction->id,
|
||||
sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status));
|
||||
|
||||
pTrans->lastAction = pAction->id;
|
||||
pTrans->lastMsgType = pAction->msgType;
|
||||
pTrans->lastEpset = pAction->epSet;
|
||||
pTrans->lastErrorNo = 0;
|
||||
} else {
|
||||
pAction->errCode = (terrno != 0) ? terrno : code;
|
||||
mError("trans:%d, %s:%d failed to write sdb since %s, type:%s status:%s", pTrans->id, mndTransStr(pAction->stage),
|
||||
pAction->id, terrstr(), sdbTableName(pAction->pRaw->type), sdbStatusName(pAction->pRaw->status));
|
||||
pTrans->lastAction = pAction->id;
|
||||
pTrans->lastMsgType = pAction->msgType;
|
||||
pTrans->lastEpset = pAction->epSet;
|
||||
pTrans->lastErrorNo = pAction->errCode;
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -933,27 +942,48 @@ static int32_t mndTransSendSingleMsg(SMnode *pMnode, STrans *pTrans, STransActio
|
|||
pAction->msgReceived = 0;
|
||||
pAction->errCode = 0;
|
||||
mDebug("trans:%d, %s:%d is sent, %s", pTrans->id, mndTransStr(pAction->stage), pAction->id, detail);
|
||||
|
||||
pTrans->lastAction = pAction->id;
|
||||
pTrans->lastMsgType = pAction->msgType;
|
||||
pTrans->lastEpset = pAction->epSet;
|
||||
if (pTrans->lastErrorNo == 0) {
|
||||
pTrans->lastErrorNo = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||
}
|
||||
} else {
|
||||
pAction->msgSent = 0;
|
||||
pAction->msgReceived = 0;
|
||||
pAction->errCode = (terrno != 0) ? terrno : code;
|
||||
mError("trans:%d, %s:%d not send since %s, %s", pTrans->id, mndTransStr(pAction->stage), pAction->id, terrstr(),
|
||||
detail);
|
||||
|
||||
pTrans->lastAction = pAction->id;
|
||||
pTrans->lastMsgType = pAction->msgType;
|
||||
pTrans->lastEpset = pAction->epSet;
|
||||
pTrans->lastErrorNo = pAction->errCode;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndTransExecNullMsg(SMnode *pMnode, STrans *pTrans, STransAction *pAction) {
|
||||
pAction->rawWritten = 0;
|
||||
pAction->errCode = 0;
|
||||
mDebug("trans:%d, %s:%d null action executed", pTrans->id, mndTransStr(pAction->stage), pAction->id);
|
||||
|
||||
pTrans->lastAction = pAction->id;
|
||||
pTrans->lastMsgType = pAction->msgType;
|
||||
pTrans->lastEpset = pAction->epSet;
|
||||
pTrans->lastErrorNo == 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndTransExecSingleAction(SMnode *pMnode, STrans *pTrans, STransAction *pAction) {
|
||||
if (pAction->actionType == TRANS_ACTION_RAW) {
|
||||
return mndTransWriteSingleLog(pMnode, pTrans, pAction);
|
||||
} else if (pAction->actionType == TRANS_ACTION_MSG) {
|
||||
return mndTransSendSingleMsg(pMnode, pTrans, pAction);
|
||||
} else {
|
||||
pAction->rawWritten = 0;
|
||||
pAction->errCode = 0;
|
||||
mDebug("trans:%d, %s:%d null action executed", pTrans->id, mndTransStr(pAction->stage), pAction->id);
|
||||
return 0;
|
||||
return mndTransExecNullMsg(pMnode, pTrans, pAction);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -994,19 +1024,19 @@ static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pA
|
|||
|
||||
if (numOfExecuted == numOfActions) {
|
||||
if (errCode == 0) {
|
||||
pTrans->lastErrorAction = 0;
|
||||
pTrans->lastAction = 0;
|
||||
pTrans->lastErrorNo = 0;
|
||||
pTrans->lastErrorMsgType = 0;
|
||||
memset(&pTrans->lastErrorEpset, 0, sizeof(pTrans->lastErrorEpset));
|
||||
pTrans->lastMsgType = 0;
|
||||
memset(&pTrans->lastEpset, 0, sizeof(pTrans->lastEpset));
|
||||
mDebug("trans:%d, all %d actions execute successfully", pTrans->id, numOfActions);
|
||||
return 0;
|
||||
} else {
|
||||
mError("trans:%d, all %d actions executed, code:0x%x", pTrans->id, numOfActions, errCode & 0XFFFF);
|
||||
if (pErrAction != NULL) {
|
||||
pTrans->lastErrorMsgType = pErrAction->msgType;
|
||||
pTrans->lastErrorAction = pErrAction->id;
|
||||
pTrans->lastMsgType = pErrAction->msgType;
|
||||
pTrans->lastAction = pErrAction->id;
|
||||
pTrans->lastErrorNo = pErrAction->errCode;
|
||||
pTrans->lastErrorEpset = pErrAction->epSet;
|
||||
pTrans->lastEpset = pErrAction->epSet;
|
||||
}
|
||||
mndTransResetActions(pMnode, pTrans, pArray);
|
||||
terrno = errCode;
|
||||
|
@ -1073,15 +1103,15 @@ static int32_t mndTransExecuteRedoActionsSerial(SMnode *pMnode, STrans *pTrans)
|
|||
}
|
||||
|
||||
if (code == 0) {
|
||||
pTrans->lastErrorAction = 0;
|
||||
pTrans->lastAction = 0;
|
||||
pTrans->lastErrorNo = 0;
|
||||
pTrans->lastErrorMsgType = 0;
|
||||
memset(&pTrans->lastErrorEpset, 0, sizeof(pTrans->lastErrorEpset));
|
||||
pTrans->lastMsgType = 0;
|
||||
memset(&pTrans->lastEpset, 0, sizeof(pTrans->lastEpset));
|
||||
} else {
|
||||
pTrans->lastErrorMsgType = pAction->msgType;
|
||||
pTrans->lastErrorAction = action;
|
||||
pTrans->lastErrorNo = pAction->errCode;
|
||||
pTrans->lastErrorEpset = pAction->epSet;
|
||||
pTrans->lastMsgType = pAction->msgType;
|
||||
pTrans->lastAction = action;
|
||||
pTrans->lastErrorNo = code;
|
||||
pTrans->lastEpset = pAction->epSet;
|
||||
}
|
||||
|
||||
if (code == 0) {
|
||||
|
@ -1432,23 +1462,21 @@ static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
|
|||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pTrans->lastExecTime, false);
|
||||
|
||||
char lastError[TSDB_TRANS_ERROR_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
char detail[TSDB_TRANS_ERROR_LEN] = {0};
|
||||
if (pTrans->lastErrorNo != 0) {
|
||||
int32_t len = snprintf(detail, sizeof(detail), "action:%d errno:0x%x(%s) ", pTrans->lastErrorAction,
|
||||
pTrans->lastErrorNo & 0xFFFF, tstrerror(pTrans->lastErrorNo));
|
||||
SEpSet epset = pTrans->lastErrorEpset;
|
||||
if (epset.numOfEps > 0) {
|
||||
len += snprintf(detail + len, sizeof(detail) - len, "msgType:%s numOfEps:%d inUse:%d ",
|
||||
TMSG_INFO(pTrans->lastErrorMsgType), epset.numOfEps, epset.inUse);
|
||||
for (int32_t i = 0; i < pTrans->lastErrorEpset.numOfEps; ++i) {
|
||||
len += snprintf(detail + len, sizeof(detail) - len, "ep:%d-%s:%u ", i, epset.eps[i].fqdn, epset.eps[i].port);
|
||||
}
|
||||
char lastInfo[TSDB_TRANS_ERROR_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
char detail[TSDB_TRANS_ERROR_LEN] = {0};
|
||||
int32_t len = snprintf(detail, sizeof(detail), "action:%d code:0x%x(%s) ", pTrans->lastAction,
|
||||
pTrans->lastErrorNo & 0xFFFF, tstrerror(pTrans->lastErrorNo));
|
||||
SEpSet epset = pTrans->lastEpset;
|
||||
if (epset.numOfEps > 0) {
|
||||
len += snprintf(detail + len, sizeof(detail) - len, "msgType:%s numOfEps:%d inUse:%d ",
|
||||
TMSG_INFO(pTrans->lastMsgType), epset.numOfEps, epset.inUse);
|
||||
for (int32_t i = 0; i < pTrans->lastEpset.numOfEps; ++i) {
|
||||
len += snprintf(detail + len, sizeof(detail) - len, "ep:%d-%s:%u ", i, epset.eps[i].fqdn, epset.eps[i].port);
|
||||
}
|
||||
}
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(lastError, detail, pShow->pMeta->pSchemas[cols].bytes);
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(lastInfo, detail, pShow->pMeta->pSchemas[cols].bytes);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)lastError, false);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)lastInfo, false);
|
||||
|
||||
numOfRows++;
|
||||
sdbRelease(pSdb, pTrans);
|
||||
|
|
|
@ -59,6 +59,10 @@ int32_t mndInitVgroup(SMnode *pMnode) {
|
|||
mndSetMsgHandle(pMnode, TDMT_DND_DROP_VNODE_RSP, mndTransProcessRsp);
|
||||
mndSetMsgHandle(pMnode, TDMT_VND_COMPACT_RSP, mndTransProcessRsp);
|
||||
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_REDISTRIBUTE_VGROUP, mndProcessRedistributeVgroupMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_MERGE_VGROUP, mndProcessSplitVgroupMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_BALANCE_VGROUP, mndProcessBalanceVgroupMsg);
|
||||
|
||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_VGROUP, mndRetrieveVgroups);
|
||||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_VGROUP, mndCancelGetNextVgroup);
|
||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_VNODES, mndRetrieveVnodes);
|
||||
|
@ -1009,10 +1013,10 @@ static int32_t mndAddDecVgroupReplicaFromTrans(SMnode *pMnode, STrans *pTrans, S
|
|||
|
||||
if (pGid == NULL) return 0;
|
||||
|
||||
pVgroup->replica--;
|
||||
memcpy(&delGid, pGid, sizeof(SVnodeGid));
|
||||
memcpy(pGid, &pVgroup->vnodeGid[pVgroup->replica], sizeof(SVnodeGid));
|
||||
memset(&pVgroup->vnodeGid[pVgroup->replica], 0, sizeof(SVnodeGid));
|
||||
pVgroup->replica--;
|
||||
|
||||
if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, pVgroup, TDMT_VND_ALTER_REPLICA) != 0) return -1;
|
||||
if (mndAddDropVnodeAction(pMnode, pTrans, pDb, pVgroup, &delGid, true) != 0) return -1;
|
||||
|
@ -1040,11 +1044,36 @@ static int32_t mndRedistributeVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb,
|
|||
mInfo("vgId:%d, vnode:%d dnode:%d", newVg.vgId, i, newVg.vnodeGid[i].dnodeId);
|
||||
}
|
||||
|
||||
if (mndAddIncVgroupReplicaToTrans(pMnode, pTrans, pDb, &newVg, pNew1->id) != 0) goto _OVER;
|
||||
if (mndAddDecVgroupReplicaFromTrans(pMnode, pTrans, pDb, &newVg, pOld1->id) != 0) goto _OVER;
|
||||
if (pNew2 != NULL) {
|
||||
if (pNew1 != pOld1) {
|
||||
int32_t numOfVnodes = mndGetVnodesNum(pMnode, pNew1->id);
|
||||
if (numOfVnodes >= pNew1->numOfSupportVnodes) {
|
||||
mError("vgId:%d, no enough vnodes in dnode:%d, numOfVnodes:%d support:%d", newVg.vgId, pNew1->id, numOfVnodes,
|
||||
pNew1->numOfSupportVnodes);
|
||||
terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
||||
goto _OVER;
|
||||
}
|
||||
if (mndAddIncVgroupReplicaToTrans(pMnode, pTrans, pDb, &newVg, pNew1->id) != 0) goto _OVER;
|
||||
if (mndAddDecVgroupReplicaFromTrans(pMnode, pTrans, pDb, &newVg, pOld1->id) != 0) goto _OVER;
|
||||
}
|
||||
if (pNew2 != pOld2) {
|
||||
int32_t numOfVnodes = mndGetVnodesNum(pMnode, pNew2->id);
|
||||
if (numOfVnodes >= pNew2->numOfSupportVnodes) {
|
||||
mError("vgId:%d, no enough vnodes in dnode:%d, numOfVnodes:%d support:%d", newVg.vgId, pNew2->id, numOfVnodes,
|
||||
pNew2->numOfSupportVnodes);
|
||||
terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
||||
goto _OVER;
|
||||
}
|
||||
if (mndAddIncVgroupReplicaToTrans(pMnode, pTrans, pDb, &newVg, pNew2->id) != 0) goto _OVER;
|
||||
if (mndAddDecVgroupReplicaFromTrans(pMnode, pTrans, pDb, &newVg, pOld2->id) != 0) goto _OVER;
|
||||
}
|
||||
if (pNew3 != pOld3) {
|
||||
int32_t numOfVnodes = mndGetVnodesNum(pMnode, pNew3->id);
|
||||
if (numOfVnodes >= pNew3->numOfSupportVnodes) {
|
||||
mError("vgId:%d, no enough vnodes in dnode:%d, numOfVnodes:%d support:%d", newVg.vgId, pNew3->id, numOfVnodes,
|
||||
pNew3->numOfSupportVnodes);
|
||||
terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
||||
goto _OVER;
|
||||
}
|
||||
if (mndAddIncVgroupReplicaToTrans(pMnode, pTrans, pDb, &newVg, pNew3->id) != 0) goto _OVER;
|
||||
if (mndAddDecVgroupReplicaFromTrans(pMnode, pTrans, pDb, &newVg, pOld3->id) != 0) goto _OVER;
|
||||
}
|
||||
|
@ -1070,88 +1099,105 @@ _OVER:
|
|||
}
|
||||
|
||||
static int32_t mndProcessRedistributeVgroupMsg(SRpcMsg *pReq) {
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SUserObj *pUser = NULL;
|
||||
SDnodeObj *pNew1 = NULL;
|
||||
SDnodeObj *pNew2 = NULL;
|
||||
SDnodeObj *pNew3 = NULL;
|
||||
SDnodeObj *pOld1 = NULL;
|
||||
SDnodeObj *pOld2 = NULL;
|
||||
SDnodeObj *pOld3 = NULL;
|
||||
SVgObj *pVgroup = NULL;
|
||||
SDbObj *pDb = NULL;
|
||||
int32_t code = -1;
|
||||
int64_t curMs = taosGetTimestampMs();
|
||||
SMDropMnodeReq redReq = {0};
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SUserObj *pUser = NULL;
|
||||
SDnodeObj *pNew1 = NULL;
|
||||
SDnodeObj *pNew2 = NULL;
|
||||
SDnodeObj *pNew3 = NULL;
|
||||
SDnodeObj *pOld1 = NULL;
|
||||
SDnodeObj *pOld2 = NULL;
|
||||
SDnodeObj *pOld3 = NULL;
|
||||
SVgObj *pVgroup = NULL;
|
||||
SDbObj *pDb = NULL;
|
||||
int32_t code = -1;
|
||||
int64_t curMs = taosGetTimestampMs();
|
||||
|
||||
#if 0
|
||||
if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
|
||||
SRedistributeVgroupReq redReq = {0};
|
||||
if (tDeserializeSRedistributeVgroupReq(pReq->pCont, pReq->contLen, &redReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto _OVER;
|
||||
}
|
||||
#endif
|
||||
|
||||
mDebug("vgId:%d, start to redistribute", 2);
|
||||
mInfo("vgId:%d, start to redistribute to dnode %d:%d:%d", redReq.vgId, redReq.dnodeId1, redReq.dnodeId2,
|
||||
redReq.dnodeId3);
|
||||
pUser = mndAcquireUser(pMnode, pReq->conn.user);
|
||||
if (pUser == NULL) {
|
||||
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndCheckNodeAuth(pUser) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
if (mndCheckNodeAuth(pUser) != 0) goto _OVER;
|
||||
|
||||
pVgroup = mndAcquireVgroup(pMnode, 2);
|
||||
pVgroup = mndAcquireVgroup(pMnode, redReq.vgId);
|
||||
if (pVgroup == NULL) goto _OVER;
|
||||
|
||||
pDb = mndAcquireDb(pMnode, pVgroup->dbName);
|
||||
if (pDb == NULL) goto _OVER;
|
||||
|
||||
if (pVgroup->replica == 1) {
|
||||
pNew1 = mndAcquireDnode(pMnode, 1);
|
||||
if (redReq.dnodeId2 != -1 || redReq.dnodeId3 != -1) {
|
||||
terrno = TSDB_CODE_MND_INVALID_REPLICA;
|
||||
goto _OVER;
|
||||
}
|
||||
pNew1 = mndAcquireDnode(pMnode, redReq.dnodeId1);
|
||||
pOld1 = mndAcquireDnode(pMnode, pVgroup->vnodeGid[0].dnodeId);
|
||||
if (pNew1 == NULL || pOld1 == NULL) goto _OVER;
|
||||
if (!mndIsDnodeOnline(pNew1, curMs) || !mndIsDnodeOnline(pOld1, curMs)) {
|
||||
terrno = TSDB_CODE_NODE_OFFLINE;
|
||||
if (pNew1 == NULL || pOld1 == NULL) {
|
||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
goto _OVER;
|
||||
}
|
||||
if (pNew1 == pOld1) {
|
||||
terrno = TSDB_CODE_MND_VGROUP_UN_CHANGED;
|
||||
goto _OVER;
|
||||
}
|
||||
if (mndRedistributeVgroup(pMnode, pReq, pDb, pVgroup, pNew1, pOld1, NULL, NULL, NULL, NULL) != 0) goto _OVER;
|
||||
}
|
||||
|
||||
if (pVgroup->replica == 3) {
|
||||
pNew1 = mndAcquireDnode(pMnode, 1);
|
||||
pNew2 = mndAcquireDnode(pMnode, 2);
|
||||
pNew3 = mndAcquireDnode(pMnode, 3);
|
||||
if (!mndIsDnodeOnline(pNew1, curMs) || !mndIsDnodeOnline(pOld1, curMs)) {
|
||||
terrno = TSDB_CODE_MND_HAS_OFFLINE_DNODE;
|
||||
goto _OVER;
|
||||
}
|
||||
code = mndRedistributeVgroup(pMnode, pReq, pDb, pVgroup, pNew1, pOld1, NULL, NULL, NULL, NULL);
|
||||
} else if (pVgroup->replica == 3) {
|
||||
if (redReq.dnodeId2 == -1 || redReq.dnodeId3 == -1) {
|
||||
terrno = TSDB_CODE_MND_INVALID_REPLICA;
|
||||
goto _OVER;
|
||||
}
|
||||
pNew1 = mndAcquireDnode(pMnode, redReq.dnodeId1);
|
||||
pNew2 = mndAcquireDnode(pMnode, redReq.dnodeId2);
|
||||
pNew3 = mndAcquireDnode(pMnode, redReq.dnodeId3);
|
||||
pOld1 = mndAcquireDnode(pMnode, pVgroup->vnodeGid[0].dnodeId);
|
||||
pOld2 = mndAcquireDnode(pMnode, pVgroup->vnodeGid[1].dnodeId);
|
||||
pOld3 = mndAcquireDnode(pMnode, pVgroup->vnodeGid[2].dnodeId);
|
||||
if (pNew1 == NULL || pOld1 == NULL || pNew2 == NULL || pOld2 == NULL || pNew3 == NULL || pOld3 == NULL) goto _OVER;
|
||||
if (!mndIsDnodeOnline(pNew1, curMs) || !mndIsDnodeOnline(pOld1, curMs) || !mndIsDnodeOnline(pNew2, curMs) ||
|
||||
!mndIsDnodeOnline(pOld2, curMs) || !mndIsDnodeOnline(pNew3, curMs) || !mndIsDnodeOnline(pOld3, curMs)) {
|
||||
terrno = TSDB_CODE_NODE_OFFLINE;
|
||||
if (pNew1 == NULL || pOld1 == NULL || pNew2 == NULL || pOld2 == NULL || pNew3 == NULL || pOld3 == NULL) {
|
||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
goto _OVER;
|
||||
}
|
||||
bool changed = true;
|
||||
if (pNew1 != pOld1 || pNew1 != pOld2 || pNew1 != pOld3) changed = true;
|
||||
if (pNew2 != pOld1 || pNew2 != pOld2 || pNew2 != pOld3) changed = true;
|
||||
if (pNew3 != pOld1 || pNew3 != pOld2 || pNew3 != pOld3) changed = true;
|
||||
if (pNew1 == pNew2 || pNew1 == pNew3 || pNew2 == pNew3) {
|
||||
terrno = TSDB_CODE_MND_INVALID_REPLICA;
|
||||
goto _OVER;
|
||||
}
|
||||
bool changed = false;
|
||||
if (pNew1 != pOld1 && pNew1 != pOld2 && pNew1 != pOld3) changed = true;
|
||||
if (pNew2 != pOld1 && pNew2 != pOld2 && pNew2 != pOld3) changed = true;
|
||||
if (pNew3 != pOld1 && pNew3 != pOld2 && pNew3 != pOld3) changed = true;
|
||||
if (!changed) {
|
||||
terrno = TSDB_CODE_MND_VGROUP_UN_CHANGED;
|
||||
goto _OVER;
|
||||
}
|
||||
if (mndRedistributeVgroup(pMnode, pReq, pDb, pVgroup, pNew1, pOld1, pNew2, pOld2, pNew3, pOld3) != 0) goto _OVER;
|
||||
if (!mndIsDnodeOnline(pNew1, curMs) || !mndIsDnodeOnline(pOld1, curMs) || !mndIsDnodeOnline(pNew2, curMs) ||
|
||||
!mndIsDnodeOnline(pOld2, curMs) || !mndIsDnodeOnline(pNew3, curMs) || !mndIsDnodeOnline(pOld3, curMs)) {
|
||||
terrno = TSDB_CODE_MND_HAS_OFFLINE_DNODE;
|
||||
goto _OVER;
|
||||
}
|
||||
code = mndRedistributeVgroup(pMnode, pReq, pDb, pVgroup, pNew1, pOld1, pNew2, pOld2, pNew3, pOld3);
|
||||
} else {
|
||||
terrno = TSDB_CODE_MND_INVALID_REPLICA;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||
|
||||
_OVER:
|
||||
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
|
||||
mDebug("vgId:%d, failed to redistribute since %s", 1, terrstr());
|
||||
mError("vgId:%d, failed to redistribute to dnode %d %d %d since %s", redReq.vgId, redReq.dnodeId1, redReq.dnodeId2,
|
||||
redReq.dnodeId3, terrstr());
|
||||
}
|
||||
|
||||
mndReleaseDnode(pMnode, pNew1);
|
||||
|
@ -1303,9 +1349,7 @@ static int32_t mndProcessSplitVgroupMsg(SRpcMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndCheckNodeAuth(pUser) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
if (mndCheckNodeAuth(pUser) != 0) goto _OVER;
|
||||
|
||||
code = mndSplitVgroup(pMnode, pReq, pDb, pVgroup);
|
||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||
|
|
|
@ -357,7 +357,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb) {
|
|||
SdbEncodeFp encodeFp = pSdb->encodeFps[i];
|
||||
if (encodeFp == NULL) continue;
|
||||
|
||||
mTrace("write %s to sdb file, total %d rows", sdbTableName(i), sdbGetSize(pSdb, i));
|
||||
mDebug("write %s to sdb file, total %d rows", sdbTableName(i), sdbGetSize(pSdb, i));
|
||||
|
||||
SHashObj *hash = pSdb->hashObjs[i];
|
||||
TdThreadRwlock *pLock = &pSdb->locks[i];
|
||||
|
|
|
@ -83,6 +83,7 @@ const char *sdbStatusName(ESdbStatus status) {
|
|||
}
|
||||
|
||||
void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper) {
|
||||
#if 0
|
||||
EKeyType keyType = pSdb->keyTypes[pRow->type];
|
||||
|
||||
if (keyType == SDB_KEY_BINARY) {
|
||||
|
@ -96,6 +97,7 @@ void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper) {
|
|||
pRow->refCount, oper, pRow->pObj, sdbStatusName(pRow->status));
|
||||
} else {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static SHashObj *sdbGetHash(SSdb *pSdb, int32_t type) {
|
||||
|
|
|
@ -37,13 +37,17 @@ SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen) {
|
|||
pRaw->sver = sver;
|
||||
pRaw->dataLen = dataLen;
|
||||
|
||||
#if 0
|
||||
mTrace("raw:%p, is created, len:%d table:%s", pRaw, dataLen, sdbTableName(type));
|
||||
#endif
|
||||
return pRaw;
|
||||
}
|
||||
|
||||
void sdbFreeRaw(SSdbRaw *pRaw) {
|
||||
if (pRaw != NULL) {
|
||||
#if 0
|
||||
mTrace("raw:%p, is freed", pRaw);
|
||||
#endif
|
||||
taosMemoryFree(pRaw);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,9 @@ SSdbRow *sdbAllocRow(int32_t objSize) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#if 0
|
||||
mTrace("row:%p, is created, len:%d", pRow->pObj, objSize);
|
||||
#endif
|
||||
return pRow;
|
||||
}
|
||||
|
||||
|
@ -45,6 +47,8 @@ void sdbFreeRow(SSdb *pSdb, SSdbRow *pRow, bool callFunc) {
|
|||
|
||||
sdbPrintOper(pSdb, pRow, "free");
|
||||
|
||||
#if 0
|
||||
mTrace("row:%p, is freed", pRow->pObj);
|
||||
#endif
|
||||
taosMemoryFreeClear(pRow);
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ typedef struct SMetaFltParam {
|
|||
tb_uid_t suid;
|
||||
int16_t cid;
|
||||
int16_t type;
|
||||
char * val;
|
||||
char *val;
|
||||
bool reverse;
|
||||
int (*filterFunc)(void *a, void *b, int16_t type);
|
||||
|
||||
|
@ -116,16 +116,16 @@ typedef void *tsdbReaderT;
|
|||
#define BLOCK_LOAD_TABLE_SEQ_ORDER 2
|
||||
#define BLOCK_LOAD_TABLE_RR_ORDER 3
|
||||
|
||||
tsdbReaderT *tsdbQueryTables(SVnode *pVnode, SQueryTableDataCond *pCond, STableListInfo *tableInfoGroup, uint64_t qId,
|
||||
uint64_t taskId);
|
||||
tsdbReaderT *tsdbReaderOpen(SVnode *pVnode, SQueryTableDataCond *pCond, STableListInfo *tableInfoGroup, uint64_t qId,
|
||||
uint64_t taskId);
|
||||
tsdbReaderT tsdbQueryCacheLast(SVnode *pVnode, SQueryTableDataCond *pCond, STableListInfo *groupList, uint64_t qId,
|
||||
void *pMemRef);
|
||||
int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT *pReader, STableBlockDistInfo *pTableBlockInfo);
|
||||
bool isTsdbCacheLastRow(tsdbReaderT *pReader);
|
||||
int32_t tsdbGetAllTableList(SMeta *pMeta, uint64_t uid, SArray *list);
|
||||
int32_t tsdbGetCtbIdList(SMeta *pMeta, int64_t suid, SArray *list);
|
||||
void * tsdbGetIdx(SMeta *pMeta);
|
||||
void * tsdbGetIvtIdx(SMeta *pMeta);
|
||||
void *tsdbGetIdx(SMeta *pMeta);
|
||||
void *tsdbGetIvtIdx(SMeta *pMeta);
|
||||
int64_t tsdbGetNumOfRowsInMemTable(tsdbReaderT *pHandle);
|
||||
|
||||
bool tsdbNextDataBlock(tsdbReaderT pTsdbReadHandle);
|
||||
|
@ -201,7 +201,7 @@ struct SMetaEntry {
|
|||
int64_t version;
|
||||
int8_t type;
|
||||
tb_uid_t uid;
|
||||
char * name;
|
||||
char *name;
|
||||
union {
|
||||
struct {
|
||||
SSchemaWrapper schemaRow;
|
||||
|
@ -229,17 +229,17 @@ struct SMetaEntry {
|
|||
|
||||
struct SMetaReader {
|
||||
int32_t flags;
|
||||
SMeta * pMeta;
|
||||
SMeta *pMeta;
|
||||
SDecoder coder;
|
||||
SMetaEntry me;
|
||||
void * pBuf;
|
||||
void *pBuf;
|
||||
int32_t szBuf;
|
||||
};
|
||||
|
||||
struct SMTbCursor {
|
||||
TBC * pDbc;
|
||||
void * pKey;
|
||||
void * pVal;
|
||||
TBC *pDbc;
|
||||
void *pKey;
|
||||
void *pVal;
|
||||
int32_t kLen;
|
||||
int32_t vLen;
|
||||
SMetaReader mr;
|
||||
|
|
|
@ -119,8 +119,8 @@ int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq* pMsg, SSu
|
|||
int32_t tsdbInsertTableData(STsdb* pTsdb, int64_t version, SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock,
|
||||
SSubmitBlkRsp* pRsp);
|
||||
int32_t tsdbDeleteTableData(STsdb* pTsdb, int64_t version, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey);
|
||||
tsdbReaderT* tsdbQueryTables(SVnode* pVnode, SQueryTableDataCond* pCond, STableListInfo* tableList, uint64_t qId,
|
||||
uint64_t taskId);
|
||||
tsdbReaderT* tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, STableListInfo* tableList, uint64_t qId,
|
||||
uint64_t taskId);
|
||||
tsdbReaderT tsdbQueryCacheLastT(STsdb* tsdb, SQueryTableDataCond* pCond, STableListInfo* tableList, uint64_t qId,
|
||||
void* pMemRef);
|
||||
int32_t tsdbSnapshotReaderOpen(STsdb* pTsdb, STsdbSnapshotReader** ppReader, int64_t sver, int64_t ever);
|
||||
|
|
|
@ -364,6 +364,7 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) {
|
|||
tdGetSTSChemaFromSSChema(&pTask->tbSink.pSchemaWrapper->pSchema, pTask->tbSink.pSchemaWrapper->nCols);
|
||||
ASSERT(pTask->tbSink.pTSchema);
|
||||
}
|
||||
tqInfo("deploy stream task id %d child id %d on vg %d", pTask->taskId, pTask->childId, pTq->pVnode->config.vgId);
|
||||
|
||||
taosHashPut(pTq->pStreamTasks, &pTask->taskId, sizeof(int32_t), pTask, sizeof(SStreamTask));
|
||||
|
||||
|
|
|
@ -500,8 +500,8 @@ static int32_t setCurrentSchema(SVnode* pVnode, STsdbReadHandle* pTsdbReadHandle
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
tsdbReaderT* tsdbQueryTables(SVnode* pVnode, SQueryTableDataCond* pCond, STableListInfo* tableList, uint64_t qId,
|
||||
uint64_t taskId) {
|
||||
tsdbReaderT* tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, STableListInfo* tableList, uint64_t qId,
|
||||
uint64_t taskId) {
|
||||
STsdbReadHandle* pTsdbReadHandle = tsdbQueryTablesImpl(pVnode, pCond, qId, taskId);
|
||||
if (pTsdbReadHandle == NULL) {
|
||||
return NULL;
|
||||
|
@ -642,7 +642,7 @@ tsdbReaderT tsdbQueryLastRow(SVnode* pVnode, SQueryTableDataCond* pCond, STableL
|
|||
return NULL;
|
||||
}
|
||||
|
||||
STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)tsdbQueryTables(pVnode, pCond, pList, qId, taskId);
|
||||
STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)tsdbReaderOpen(pVnode, pCond, pList, qId, taskId);
|
||||
if (pTsdbReadHandle == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -2557,6 +2557,10 @@ static void moveToNextDataBlockInCurrentFile(STsdbReadHandle* pTsdbReadHandle) {
|
|||
cur->blockCompleted = false;
|
||||
}
|
||||
|
||||
static int32_t getBucketIndex(int32_t startRow, int32_t bucketRange, int32_t numOfRows) {
|
||||
return (numOfRows - startRow) / bucketRange;
|
||||
}
|
||||
|
||||
int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* queryHandle, STableBlockDistInfo* pTableBlockInfo) {
|
||||
STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)queryHandle;
|
||||
|
||||
|
@ -2575,16 +2579,20 @@ int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* queryHandle, STableBlockDistInfo*
|
|||
tsdbFSIterSeek(&pTsdbReadHandle->fileIter, fid);
|
||||
tsdbUnLockFS(pFileHandle);
|
||||
|
||||
STsdbCfg* pc = REPO_CFG(pTsdbReadHandle->pTsdb);
|
||||
pTableBlockInfo->defMinRows = pc->minRows;
|
||||
pTableBlockInfo->defMaxRows = pc->maxRows;
|
||||
|
||||
int32_t bucketRange = ceil((pc->maxRows - pc->minRows) / 20.0);
|
||||
|
||||
pTableBlockInfo->numOfFiles += 1;
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t numOfBlocks = 0;
|
||||
int32_t numOfTables = (int32_t)taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo);
|
||||
int defaultRows = 4096; // TSDB_DEFAULT_BLOCK_ROWS(pCfg->maxRowsPerFileBlock);
|
||||
int defaultRows = 4096;
|
||||
STimeWindow win = TSWINDOW_INITIALIZER;
|
||||
|
||||
bool ascTraverse = ASCENDING_TRAVERSE(pTsdbReadHandle->order);
|
||||
|
||||
while (true) {
|
||||
numOfBlocks = 0;
|
||||
tsdbRLockFS(REPO_FS(pTsdbReadHandle->pTsdb));
|
||||
|
@ -2597,8 +2605,7 @@ int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* queryHandle, STableBlockDistInfo*
|
|||
tsdbGetFidKeyRange(pCfg->days, pCfg->precision, pTsdbReadHandle->pFileGroup->fid, &win.skey, &win.ekey);
|
||||
|
||||
// current file are not overlapped with query time window, ignore remain files
|
||||
if ((ascTraverse && win.skey > pTsdbReadHandle->window.ekey) ||
|
||||
(!ascTraverse && win.ekey < pTsdbReadHandle->window.ekey)) {
|
||||
if ((win.skey > pTsdbReadHandle->window.ekey)/* || (!ascTraverse && win.ekey < pTsdbReadHandle->window.ekey)*/) {
|
||||
tsdbUnLockFS(REPO_FS(pTsdbReadHandle->pTsdb));
|
||||
tsdbDebug("%p remain files are not qualified for qrange:%" PRId64 "-%" PRId64 ", ignore, %s", pTsdbReadHandle,
|
||||
pTsdbReadHandle->window.skey, pTsdbReadHandle->window.ekey, pTsdbReadHandle->idStr);
|
||||
|
@ -2631,15 +2638,19 @@ int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* queryHandle, STableBlockDistInfo*
|
|||
continue;
|
||||
}
|
||||
|
||||
pTableBlockInfo->numOfBlocks += numOfBlocks;
|
||||
|
||||
for (int32_t i = 0; i < numOfTables; ++i) {
|
||||
STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i);
|
||||
|
||||
SBlock* pBlock = pCheckInfo->pCompInfo->blocks;
|
||||
|
||||
for (int32_t j = 0; j < pCheckInfo->numOfBlocks; ++j) {
|
||||
pTableBlockInfo->totalSize += pBlock[j].len;
|
||||
|
||||
int32_t numOfRows = pBlock[j].numOfRows;
|
||||
pTableBlockInfo->totalRows += numOfRows;
|
||||
|
||||
if (numOfRows > pTableBlockInfo->maxRows) {
|
||||
pTableBlockInfo->maxRows = numOfRows;
|
||||
}
|
||||
|
@ -2651,13 +2662,14 @@ int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* queryHandle, STableBlockDistInfo*
|
|||
if (numOfRows < defaultRows) {
|
||||
pTableBlockInfo->numOfSmallBlocks += 1;
|
||||
}
|
||||
// int32_t stepIndex = (numOfRows-1)/TSDB_BLOCK_DIST_STEP_ROWS;
|
||||
// SFileBlockInfo *blockInfo = (SFileBlockInfo*)taosArrayGet(pTableBlockInfo->dataBlockInfos, stepIndex);
|
||||
// blockInfo->numBlocksOfStep++;
|
||||
|
||||
int32_t bucketIndex = getBucketIndex(pTableBlockInfo->defMinRows, bucketRange, numOfRows);
|
||||
pTableBlockInfo->blockRowsHisto[bucketIndex]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pTableBlockInfo->numOfTables = numOfTables;
|
||||
return code;
|
||||
}
|
||||
|
||||
|
|
|
@ -180,13 +180,22 @@ static int32_t vnodeSyncGetSnapshot(SSyncFSM *pFsm, SSnapshot *pSnapshot) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void vnodeSyncReconfig(struct SSyncFSM *pFsm, SSyncCfg newCfg, SReConfigCbMeta cbMeta) {
|
||||
static void vnodeSyncReconfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReConfigCbMeta cbMeta) {
|
||||
SVnode *pVnode = pFsm->data;
|
||||
vInfo("vgId:%d, sync reconfig is confirmed", TD_VID(pVnode));
|
||||
|
||||
#if 0
|
||||
// send response
|
||||
SRpcMsg rpcMsg = {.msgType = pMsg->msgType, .contLen = pMsg->contLen, .conn.applyIndex = cbMeta.index};
|
||||
rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen);
|
||||
memcpy(rpcMsg.pCont, pMsg->pCont, pMsg->contLen);
|
||||
syncGetAndDelRespRpc(pVnode->sync, cbMeta.seqNum, &rpcMsg.info);
|
||||
#endif
|
||||
|
||||
// todo rpc response here
|
||||
// build rpc msg
|
||||
// put into apply queue
|
||||
vnodePostBlockMsg(pVnode, TDMT_VND_ALTER_REPLICA);
|
||||
}
|
||||
|
||||
static void vnodeSyncCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) {
|
||||
|
@ -212,6 +221,7 @@ static void vnodeSyncCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta c
|
|||
memcpy(rpcMsg.pCont, pMsg->pCont, pMsg->contLen);
|
||||
syncGetAndDelRespRpc(pVnode->sync, cbMeta.seqNum, &rpcMsg.info);
|
||||
tmsgPutToQueue(&pVnode->msgCb, APPLY_QUEUE, &rpcMsg);
|
||||
|
||||
} else {
|
||||
char logBuf[256] = {0};
|
||||
snprintf(logBuf, sizeof(logBuf),
|
||||
|
|
|
@ -421,19 +421,23 @@ typedef struct SSysTableScanInfo {
|
|||
SRetrieveTableReq req;
|
||||
SEpSet epSet;
|
||||
tsem_t ready;
|
||||
|
||||
SReadHandle readHandle;
|
||||
int32_t accountId;
|
||||
bool showRewrite;
|
||||
SNode* pCondition; // db_name filter condition, to discard data that are not in current database
|
||||
SMTbCursor* pCur; // cursor for iterate the local table meta store.
|
||||
SArray* scanCols; // SArray<int16_t> scan column id list
|
||||
SName name;
|
||||
SSDataBlock* pRes;
|
||||
int64_t numOfBlocks; // extract basic running information.
|
||||
SLoadRemoteDataInfo loadInfo;
|
||||
SReadHandle readHandle;
|
||||
int32_t accountId;
|
||||
bool showRewrite;
|
||||
SNode* pCondition; // db_name filter condition, to discard data that are not in current database
|
||||
SMTbCursor* pCur; // cursor for iterate the local table meta store.
|
||||
SArray* scanCols; // SArray<int16_t> scan column id list
|
||||
SName name;
|
||||
SSDataBlock* pRes;
|
||||
int64_t numOfBlocks; // extract basic running information.
|
||||
SLoadRemoteDataInfo loadInfo;
|
||||
} SSysTableScanInfo;
|
||||
|
||||
typedef struct SBlockDistInfo {
|
||||
SSDataBlock* pResBlock;
|
||||
void* pHandle;
|
||||
} SBlockDistInfo;
|
||||
|
||||
typedef struct SOptrBasicInfo {
|
||||
SResultRowInfo resultRowInfo;
|
||||
int32_t* rowCellInfoOffset; // offset value for each row result cell info
|
||||
|
|
|
@ -449,7 +449,7 @@ int32_t mergeIntoGroupResult(SGroupResInfo* pGroupResInfo, STaskRuntimeEnv* pRun
|
|||
// tbufWriteUint64(bw, pDist->totalRows);
|
||||
// tbufWriteInt32(bw, pDist->maxRows);
|
||||
// tbufWriteInt32(bw, pDist->minRows);
|
||||
// tbufWriteUint32(bw, pDist->numOfRowsInMemTable);
|
||||
// tbufWriteUint32(bw, pDist->numOfInmemRows);
|
||||
// tbufWriteUint32(bw, pDist->numOfSmallBlocks);
|
||||
// tbufWriteUint64(bw, taosArrayGetSize(pDist->dataBlockInfos));
|
||||
//
|
||||
|
@ -488,7 +488,7 @@ int32_t mergeIntoGroupResult(SGroupResInfo* pGroupResInfo, STaskRuntimeEnv* pRun
|
|||
// pDist->totalRows = tbufReadUint64(&br);
|
||||
// pDist->maxRows = tbufReadInt32(&br);
|
||||
// pDist->minRows = tbufReadInt32(&br);
|
||||
// pDist->numOfRowsInMemTable = tbufReadUint32(&br);
|
||||
// pDist->numOfInmemRows = tbufReadUint32(&br);
|
||||
// pDist->numOfSmallBlocks = tbufReadUint32(&br);
|
||||
// int64_t numSteps = tbufReadUint64(&br);
|
||||
//
|
||||
|
|
|
@ -2010,9 +2010,9 @@ int32_t doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprI
|
|||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, slotId);
|
||||
char* in = GET_ROWCELL_INTERBUF(pCtx[j].resultInfo);
|
||||
if (pCtx[j].increase) {
|
||||
int64_t ts = *(int64_t*) in;
|
||||
int64_t ts = *(int64_t*)in;
|
||||
for (int32_t k = 0; k < pRow->numOfRows; ++k) {
|
||||
colDataAppend(pColInfoData, pBlock->info.rows + k, (const char *)&ts, pCtx[j].resultInfo->isNullRes);
|
||||
colDataAppend(pColInfoData, pBlock->info.rows + k, (const char*)&ts, pCtx[j].resultInfo->isNullRes);
|
||||
ts++;
|
||||
}
|
||||
} else {
|
||||
|
@ -3112,8 +3112,8 @@ static SSDataBlock* doMerge(SOperatorInfo* pOperator) {
|
|||
return (pInfo->binfo.pRes->info.rows > 0) ? pInfo->binfo.pRes : NULL;
|
||||
}
|
||||
|
||||
SSDataBlock* getSortedMergeBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity, SArray* pColMatchInfo,
|
||||
SSortedMergeOperatorInfo *pInfo) {
|
||||
SSDataBlock* getSortedMergeBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity,
|
||||
SArray* pColMatchInfo, SSortedMergeOperatorInfo* pInfo) {
|
||||
blockDataCleanup(pDataBlock);
|
||||
|
||||
SSDataBlock* p = tsortGetSortedDataBlock(pHandle);
|
||||
|
@ -4575,7 +4575,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
SScanPhysiNode* pScanPhyNode = (SScanPhysiNode*)pPhyNode; // simple child table.
|
||||
STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode;
|
||||
STimeWindowAggSupp twSup = {
|
||||
.waterMark = pTableScanNode->watermark, .calTrigger = pTableScanNode->triggerType, .maxTs = INT64_MIN};
|
||||
.waterMark = pTableScanNode->watermark, .calTrigger = pTableScanNode->triggerType, .maxTs = INT64_MIN};
|
||||
tsdbReaderT pDataReader = NULL;
|
||||
if (pHandle->vnode) {
|
||||
pDataReader = doCreateDataReader(pTableScanNode, pHandle, pTableListInfo, (uint64_t)queryId, taskId, pTagCond);
|
||||
|
@ -4602,7 +4602,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
} else if (QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN == type) {
|
||||
STagScanPhysiNode* pScanPhyNode = (STagScanPhysiNode*)pPhyNode;
|
||||
|
||||
int32_t code = getTableList(pHandle->meta, pScanPhyNode->tableType, pScanPhyNode->uid, pTableListInfo, pTagCond);
|
||||
int32_t code = getTableList(pHandle->meta, pScanPhyNode->tableType, pScanPhyNode->uid, pTableListInfo, pScanPhyNode->node.pConditions);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -4685,14 +4685,17 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
}
|
||||
|
||||
int32_t tsSlotId = ((SColumnNode*)pIntervalPhyNode->window.pTspk)->slotId;
|
||||
bool isStream = (QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL == type);
|
||||
pOptr = createIntervalOperatorInfo(ops[0], pExprInfo, num, pResBlock, &interval, tsSlotId, &as, pTaskInfo, isStream);
|
||||
bool isStream = (QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL == type);
|
||||
pOptr =
|
||||
createIntervalOperatorInfo(ops[0], pExprInfo, num, pResBlock, &interval, tsSlotId, &as, pTaskInfo, isStream);
|
||||
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL == type) {
|
||||
int32_t children = 8;
|
||||
qDebug("[******]create Semi");
|
||||
int32_t children = 0;
|
||||
pOptr = createStreamFinalIntervalOperatorInfo(ops[0], pPhyNode, pTaskInfo, children);
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL == type) {
|
||||
int32_t children = 0;
|
||||
qDebug("[******]create Final");
|
||||
int32_t children = 1;
|
||||
pOptr = createStreamFinalIntervalOperatorInfo(ops[0], pPhyNode, pTaskInfo, children);
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_SORT == type) {
|
||||
SSortPhysiNode* pSortPhyNode = (SSortPhysiNode*)pPhyNode;
|
||||
|
@ -4720,7 +4723,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
int32_t numOfOutputCols = 0;
|
||||
SArray* pColList =
|
||||
extractColMatchInfo(pMergePhyNode->pTargets, pDescNode, &numOfOutputCols, pTaskInfo, COL_MATCH_FROM_SLOT_ID);
|
||||
SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, 0);
|
||||
SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, 0);
|
||||
SSDataBlock* pInputDataBlock = createResDataBlock(pChildNode->pOutputDataBlockDesc);
|
||||
pOptr = createMultiwaySortMergeOperatorInfo(ops, size, pInputDataBlock, pResBlock, sortInfo, pColList, pTaskInfo);
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION == type) {
|
||||
|
@ -5067,7 +5070,7 @@ tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle*
|
|||
goto _error;
|
||||
}
|
||||
|
||||
return tsdbQueryTables(pHandle->vnode, &cond, pTableListInfo, queryId, taskId);
|
||||
return tsdbReaderOpen(pHandle->vnode, &cond, pTableListInfo, queryId, taskId);
|
||||
|
||||
_error:
|
||||
terrno = code;
|
||||
|
@ -5349,7 +5352,8 @@ int32_t getOperatorExplainExecInfo(SOperatorInfo* operatorInfo, SExplainExecInfo
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t initStreamAggSupporter(SStreamAggSupporter* pSup, const char* pKey, SqlFunctionCtx* pCtx, int32_t numOfOutput, size_t size) {
|
||||
int32_t initStreamAggSupporter(SStreamAggSupporter* pSup, const char* pKey, SqlFunctionCtx* pCtx, int32_t numOfOutput,
|
||||
size_t size) {
|
||||
pSup->resultRowSize = getResultRowSize(pCtx, numOfOutput);
|
||||
pSup->keySize = sizeof(int64_t) + sizeof(TSKEY);
|
||||
pSup->pKeyBuf = taosMemoryCalloc(1, pSup->keySize);
|
||||
|
@ -5370,7 +5374,7 @@ int32_t initStreamAggSupporter(SStreamAggSupporter* pSup, const char* pKey, SqlF
|
|||
bufSize = pageSize * 4;
|
||||
}
|
||||
int32_t code = createDiskbasedBuf(&pSup->pResultBuf, pageSize, bufSize, pKey, TD_TMP_DIR_PATH);
|
||||
for(int32_t i = 0; i < numOfOutput; ++i) {
|
||||
for (int32_t i = 0; i < numOfOutput; ++i) {
|
||||
pCtx[i].pBuf = pSup->pResultBuf;
|
||||
}
|
||||
return code;
|
||||
|
|
|
@ -641,72 +641,61 @@ static SSDataBlock* doBlockInfoScan(SOperatorInfo* pOperator) {
|
|||
|
||||
STableScanInfo* pTableScanInfo = pOperator->info;
|
||||
|
||||
STableBlockDistInfo tableBlockDist = {0};
|
||||
tableBlockDist.numOfTables = 1; // TODO set the correct number of tables
|
||||
STableBlockDistInfo blockDistInfo = {0};
|
||||
blockDistInfo.maxRows = INT_MIN;
|
||||
blockDistInfo.minRows = INT_MAX;
|
||||
|
||||
int32_t numRowSteps = TSDB_DEFAULT_MAXROWS_FBLOCK / TSDB_BLOCK_DIST_STEP_ROWS;
|
||||
if (TSDB_DEFAULT_MAXROWS_FBLOCK % TSDB_BLOCK_DIST_STEP_ROWS != 0) {
|
||||
++numRowSteps;
|
||||
}
|
||||
|
||||
tableBlockDist.dataBlockInfos = taosArrayInit(numRowSteps, sizeof(SFileBlockInfo));
|
||||
taosArraySetSize(tableBlockDist.dataBlockInfos, numRowSteps);
|
||||
|
||||
tableBlockDist.maxRows = INT_MIN;
|
||||
tableBlockDist.minRows = INT_MAX;
|
||||
|
||||
tsdbGetFileBlocksDistInfo(pTableScanInfo->dataReader, &tableBlockDist);
|
||||
tableBlockDist.numOfRowsInMemTable = (int32_t)tsdbGetNumOfRowsInMemTable(pTableScanInfo->dataReader);
|
||||
tsdbGetFileBlocksDistInfo(pTableScanInfo->dataReader, &blockDistInfo);
|
||||
blockDistInfo.numOfInmemRows = (int32_t)tsdbGetNumOfRowsInMemTable(pTableScanInfo->dataReader);
|
||||
|
||||
SSDataBlock* pBlock = pTableScanInfo->pResBlock;
|
||||
pBlock->info.rows = 1;
|
||||
pBlock->info.numOfCols = 1;
|
||||
|
||||
// SBufferWriter bw = tbufInitWriter(NULL, false);
|
||||
// blockDistInfoToBinary(&tableBlockDist, &bw);
|
||||
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, 0);
|
||||
|
||||
// int32_t len = (int32_t) tbufTell(&bw);
|
||||
// pColInfo->pData = taosMemoryMalloc(len + sizeof(int32_t));
|
||||
// *(int32_t*) pColInfo->pData = len;
|
||||
// memcpy(pColInfo->pData + sizeof(int32_t), tbufGetData(&bw, false), len);
|
||||
//
|
||||
// tbufCloseWriter(&bw);
|
||||
int32_t len = tSerializeBlockDistInfo(NULL, 0, &blockDistInfo);
|
||||
char* p = taosMemoryCalloc(1, len + VARSTR_HEADER_SIZE);
|
||||
tSerializeBlockDistInfo(varDataVal(p), len, &blockDistInfo);
|
||||
varDataSetLen(p, len);
|
||||
|
||||
// SArray* g = GET_TABLEGROUP(pOperator->, 0);
|
||||
// pOperator->pRuntimeEnv->current = taosArrayGetP(g, 0);
|
||||
colDataAppend(pColInfo, 0, p, false);
|
||||
taosMemoryFree(p);
|
||||
|
||||
pOperator->status = OP_EXEC_DONE;
|
||||
return pBlock;
|
||||
}
|
||||
|
||||
static void destroyBlockDistScanOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
SBlockDistInfo* pDistInfo = (SBlockDistInfo*) param;
|
||||
blockDataDestroy(pDistInfo->pResBlock);
|
||||
}
|
||||
|
||||
SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SExecTaskInfo* pTaskInfo) {
|
||||
STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo));
|
||||
SBlockDistInfo* pInfo = taosMemoryCalloc(1, sizeof(SBlockDistInfo));
|
||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||
if (pInfo == NULL || pOperator == NULL) {
|
||||
pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _error;
|
||||
}
|
||||
|
||||
pInfo->dataReader = dataReader;
|
||||
// pInfo->block.pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData));
|
||||
pInfo->pHandle = dataReader;
|
||||
|
||||
pInfo->pResBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||
|
||||
SColumnInfoData infoData = {0};
|
||||
infoData.info.type = TSDB_DATA_TYPE_BINARY;
|
||||
infoData.info.bytes = 1024;
|
||||
infoData.info.colId = 0;
|
||||
// taosArrayPush(pInfo->block.pDataBlock, &infoData);
|
||||
infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
|
||||
infoData.info.bytes = 1024;
|
||||
|
||||
pOperator->name = "DataBlockInfoScanOperator";
|
||||
taosArrayPush(pInfo->pResBlock->pDataBlock, &infoData);
|
||||
|
||||
pOperator->name = "DataBlockInfoScanOperator";
|
||||
// pOperator->operatorType = OP_TableBlockInfoScan;
|
||||
pOperator->blocking = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->fpSet._openFn = operatorDummyOpenFn;
|
||||
pOperator->fpSet.getNextFn = doBlockInfoScan;
|
||||
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->blocking = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doBlockInfoScan, NULL, NULL, destroyBlockDistScanOperatorInfo, NULL, NULL, NULL);
|
||||
return pOperator;
|
||||
|
||||
_error:
|
||||
|
@ -820,11 +809,18 @@ static void getUpdateDataBlock(SStreamBlockScanInfo* pInfo, bool invertible, SSD
|
|||
// return p;
|
||||
SColumnInfoData* pCol = (SColumnInfoData*)taosArrayGet(pUpdateBlock->pDataBlock, pInfo->primaryTsIndex);
|
||||
ASSERT(pCol->info.type == TSDB_DATA_TYPE_TIMESTAMP);
|
||||
colInfoDataEnsureCapacity(pCol, 0, size);
|
||||
blockDataEnsureCapacity(pUpdateBlock, size);
|
||||
for (int32_t i = 0; i < size; i++) {
|
||||
TSKEY* pTs = (TSKEY*)taosArrayGet(pInfo->tsArray, i);
|
||||
colDataAppend(pCol, i, (char*)pTs, false);
|
||||
}
|
||||
for (int32_t i = 0; i < pUpdateBlock->info.numOfCols; i++) {
|
||||
if (i == pInfo->primaryTsIndex) {
|
||||
continue;
|
||||
}
|
||||
SColumnInfoData* pCol = (SColumnInfoData*)taosArrayGet(pUpdateBlock->pDataBlock, i);
|
||||
colDataAppendNNULL(pCol, 0, size);
|
||||
}
|
||||
pUpdateBlock->info.rows = size;
|
||||
pUpdateBlock->info.type = STREAM_REPROCESS;
|
||||
blockDataUpdateTsWindow(pUpdateBlock, 0);
|
||||
|
@ -852,7 +848,9 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) {
|
|||
}
|
||||
|
||||
int32_t current = pInfo->validBlockIndex++;
|
||||
return taosArrayGetP(pInfo->pBlockLists, current);
|
||||
SSDataBlock* pBlock = taosArrayGetP(pInfo->pBlockLists, current);
|
||||
blockDataUpdateTsWindow(pBlock, 0);
|
||||
return pBlock;
|
||||
} else {
|
||||
if (pInfo->scanMode == STREAM_SCAN_FROM_RES) {
|
||||
blockDataDestroy(pInfo->pUpdateRes);
|
||||
|
@ -951,7 +949,7 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) {
|
|||
}
|
||||
|
||||
doFilter(pInfo->pCondition, pInfo->pRes, false);
|
||||
blockDataUpdateTsWindow(pInfo->pRes, 0);
|
||||
blockDataUpdateTsWindow(pInfo->pRes, pInfo->primaryTsIndex);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -1925,6 +1925,7 @@ static void doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataBloc
|
|||
doApplyFunctions(pTaskInfo, pInfo->binfo.pCtx, &nextWin, &pInfo->twAggSup.timeWindowData, startPos, forwardRows,
|
||||
tsCols, pSDataBlock->info.rows, numOfOutput, TSDB_ORDER_ASC);
|
||||
int32_t prevEndPos = (forwardRows - 1) * step + startPos;
|
||||
ASSERT(pSDataBlock->info.window.skey > 0 && pSDataBlock->info.window.ekey > 0);
|
||||
startPos = getNextQualifiedWindow(&pInfo->interval, &nextWin, &pSDataBlock->info, tsCols, prevEndPos, pInfo->order);
|
||||
if (startPos < 0) {
|
||||
break;
|
||||
|
@ -2003,10 +2004,7 @@ static void copyUpdateDataBlock(SSDataBlock* pDest, SSDataBlock* pSource, int32_
|
|||
}
|
||||
|
||||
static int32_t getChildIndex(SSDataBlock* pBlock) {
|
||||
// if (pBlock->info.type != STREAM_INVALID && pBlock->info.rows < 4) { // for test
|
||||
// return pBlock->info.rows - 1;
|
||||
// }
|
||||
return 0;
|
||||
return pBlock->info.childId;
|
||||
}
|
||||
|
||||
static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
|
||||
|
|
|
@ -116,7 +116,10 @@ int32_t getSpreadInfoSize();
|
|||
bool getElapsedFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
bool elapsedFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
int32_t elapsedFunction(SqlFunctionCtx* pCtx);
|
||||
int32_t elapsedFunctionMerge(SqlFunctionCtx* pCtx);
|
||||
int32_t elapsedFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||
int32_t elapsedPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||
int32_t getElapsedInfoSize();
|
||||
|
||||
bool getHistogramFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
bool histogramFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
|
@ -148,17 +151,14 @@ int32_t mavgFunction(SqlFunctionCtx* pCtx);
|
|||
bool getSampleFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
bool sampleFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
int32_t sampleFunction(SqlFunctionCtx* pCtx);
|
||||
//int32_t sampleFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||
|
||||
bool getTailFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
bool tailFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
int32_t tailFunction(SqlFunctionCtx* pCtx);
|
||||
//int32_t tailFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||
|
||||
bool getUniqueFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
bool uniqueFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
int32_t uniqueFunction(SqlFunctionCtx *pCtx);
|
||||
//int32_t uniqueFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||
|
||||
bool getTwaFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
bool twaFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
|
@ -166,6 +166,8 @@ int32_t twaFunction(SqlFunctionCtx *pCtx);
|
|||
int32_t twaFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock);
|
||||
|
||||
bool getSelectivityFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
int32_t blockDistFunction(SqlFunctionCtx *pCtx);
|
||||
int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -444,6 +444,64 @@ static int32_t translateElapsed(SFunctionNode* pFunc, char* pErrBuf, int32_t len
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateElapsedImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, bool isPartial) {
|
||||
int32_t numOfParams = LIST_LENGTH(pFunc->pParameterList);
|
||||
|
||||
if (isPartial) {
|
||||
if (1 != numOfParams && 2 != numOfParams) {
|
||||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
|
||||
if (TSDB_DATA_TYPE_TIMESTAMP != paraType) {
|
||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
// param1
|
||||
if (2 == numOfParams) {
|
||||
SNode* pParamNode1 = nodesListGetNode(pFunc->pParameterList, 1);
|
||||
if (QUERY_NODE_VALUE != nodeType(pParamNode1)) {
|
||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
SValueNode* pValue = (SValueNode*)pParamNode1;
|
||||
|
||||
pValue->notReserved = true;
|
||||
|
||||
paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type;
|
||||
if (!IS_INTEGER_TYPE(paraType)) {
|
||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
if (pValue->datum.i == 0) {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
"ELAPSED function time unit parameter should be greater than db precision");
|
||||
}
|
||||
}
|
||||
|
||||
pFunc->node.resType = (SDataType){.bytes = getElapsedInfoSize() + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY};
|
||||
} else {
|
||||
if (1 != numOfParams) {
|
||||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
|
||||
if (TSDB_DATA_TYPE_BINARY != paraType) {
|
||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE};
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateElapsedPartial(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
return translateElapsedImpl(pFunc, pErrBuf, len, true);
|
||||
}
|
||||
|
||||
static int32_t translateElapsedMerge(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
return translateElapsedImpl(pFunc, pErrBuf, len, false);
|
||||
}
|
||||
|
||||
static int32_t translateLeastSQR(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
int32_t numOfParams = LIST_LENGTH(pFunc->pParameterList);
|
||||
if (3 != numOfParams) {
|
||||
|
@ -1054,7 +1112,7 @@ static bool validateHourRange(int8_t hour) {
|
|||
}
|
||||
|
||||
static bool validateMinuteRange(int8_t hour, int8_t minute, char sign) {
|
||||
if (minute == 0 || (minute == 30 && (hour == 3 || hour == 5) && sign == '-')) {
|
||||
if (minute == 0 || (minute == 30 && (hour == 3 || hour == 5) && sign == '+')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1261,6 +1319,17 @@ static int32_t translateSelectValue(SFunctionNode* pFunc, char* pErrBuf, int32_t
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateBlockDistFunc(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
pFunc->node.resType = (SDataType) {.bytes = 128, .type = TSDB_DATA_TYPE_VARCHAR};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static bool getBlockDistFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
|
||||
pEnv->calcMemSize = sizeof(STableBlockDistInfo);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// clang-format off
|
||||
const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||
{
|
||||
|
@ -1468,6 +1537,30 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.getEnvFunc = getElapsedFuncEnv,
|
||||
.initFunc = elapsedFunctionSetup,
|
||||
.processFunc = elapsedFunction,
|
||||
.finalizeFunc = elapsedFinalize,
|
||||
.pPartialFunc = "_elapsed_partial",
|
||||
.pMergeFunc = "_elapsed_merge"
|
||||
},
|
||||
{
|
||||
.name = "_elapsed_partial",
|
||||
.type = FUNCTION_TYPE_ELAPSED,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.dataRequiredFunc = statisDataRequired,
|
||||
.translateFunc = translateElapsedPartial,
|
||||
.getEnvFunc = getElapsedFuncEnv,
|
||||
.initFunc = elapsedFunctionSetup,
|
||||
.processFunc = elapsedFunction,
|
||||
.finalizeFunc = elapsedPartialFinalize
|
||||
},
|
||||
{
|
||||
.name = "_elapsed_merge",
|
||||
.type = FUNCTION_TYPE_ELAPSED,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.dataRequiredFunc = statisDataRequired,
|
||||
.translateFunc = translateElapsedMerge,
|
||||
.getEnvFunc = getElapsedFuncEnv,
|
||||
.initFunc = elapsedFunctionSetup,
|
||||
.processFunc = elapsedFunctionMerge,
|
||||
.finalizeFunc = elapsedFinalize
|
||||
},
|
||||
{
|
||||
|
@ -2035,6 +2128,15 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.initFunc = functionSetup,
|
||||
.processFunc = NULL,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "_block_dist",
|
||||
.type = FUNCTION_TYPE_BLOCK_DIST,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.translateFunc = translateBlockDistFunc,
|
||||
.getEnvFunc = getBlockDistFuncEnv,
|
||||
.processFunc = blockDistFunction,
|
||||
.finalizeFunc = blockDistFinalize
|
||||
}
|
||||
};
|
||||
// clang-format on
|
||||
|
|
|
@ -3101,6 +3101,10 @@ int32_t spreadPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
return pResInfo->numOfRes;
|
||||
}
|
||||
|
||||
int32_t getElapsedInfoSize() {
|
||||
return (int32_t)sizeof(SElapsedInfo);
|
||||
}
|
||||
|
||||
bool getElapsedFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
|
||||
pEnv->calcMemSize = sizeof(SElapsedInfo);
|
||||
return true;
|
||||
|
@ -3202,6 +3206,30 @@ _elapsed_over:
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t elapsedFunctionMerge(SqlFunctionCtx *pCtx) {
|
||||
SInputColumnInfoData* pInput = &pCtx->input;
|
||||
SColumnInfoData* pCol = pInput->pData[0];
|
||||
ASSERT(pCol->info.type == TSDB_DATA_TYPE_BINARY);
|
||||
|
||||
SElapsedInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||
|
||||
int32_t start = pInput->startRowIndex;
|
||||
char* data = colDataGetData(pCol, start);
|
||||
SElapsedInfo* pInputInfo = (SElapsedInfo *)varDataVal(data);
|
||||
|
||||
pInfo->timeUnit = pInputInfo->timeUnit;
|
||||
if (pInfo->min > pInputInfo->min) {
|
||||
pInfo->min = pInputInfo->min;
|
||||
}
|
||||
|
||||
if (pInfo->max < pInputInfo->max) {
|
||||
pInfo->max = pInputInfo->max;
|
||||
}
|
||||
|
||||
SET_VAL(GET_RES_INFO(pCtx), 1, 1);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t elapsedFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||
SElapsedInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||
double result = (double)pInfo->max - (double)pInfo->min;
|
||||
|
@ -3210,6 +3238,24 @@ int32_t elapsedFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
return functionFinalize(pCtx, pBlock);
|
||||
}
|
||||
|
||||
int32_t elapsedPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||
SElapsedInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||
int32_t resultBytes = getElapsedInfoSize();
|
||||
char *res = taosMemoryCalloc(resultBytes + VARSTR_HEADER_SIZE, sizeof(char));
|
||||
|
||||
memcpy(varDataVal(res), pInfo, resultBytes);
|
||||
varDataSetLen(res, resultBytes);
|
||||
|
||||
int32_t slotId = pCtx->pExpr->base.resSchema.slotId;
|
||||
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
|
||||
|
||||
colDataAppend(pCol, pBlock->info.rows, res, false);
|
||||
|
||||
taosMemoryFree(res);
|
||||
return pResInfo->numOfRes;
|
||||
}
|
||||
|
||||
int32_t getHistogramInfoSize() {
|
||||
return (int32_t)sizeof(SHistoFuncInfo) + HISTOGRAM_MAX_BINS_NUM * sizeof(SHistoFuncBin);
|
||||
}
|
||||
|
@ -4581,7 +4627,6 @@ int32_t twaFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock) {
|
|||
if (pResInfo->numOfRes == 0) {
|
||||
pResInfo->isNullRes = 1;
|
||||
} else {
|
||||
// assert(pInfo->win.ekey == pInfo->p.key && pInfo->hasResult == pResInfo->hasResult);
|
||||
if (pInfo->win.ekey == pInfo->win.skey) {
|
||||
pInfo->dOutput = pInfo->p.val;
|
||||
} else {
|
||||
|
@ -4594,3 +4639,175 @@ int32_t twaFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock) {
|
|||
return functionFinalize(pCtx, pBlock);
|
||||
}
|
||||
|
||||
int32_t blockDistFunction(SqlFunctionCtx *pCtx) {
|
||||
SInputColumnInfoData* pInput = &pCtx->input;
|
||||
SColumnInfoData* pInputCol = pInput->pData[0];
|
||||
|
||||
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
|
||||
|
||||
STableBlockDistInfo* pDistInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
|
||||
STableBlockDistInfo p1 = {0};
|
||||
tDeserializeBlockDistInfo(varDataVal(pInputCol->pData), varDataLen(pInputCol->pData), &p1);
|
||||
|
||||
pDistInfo->numOfBlocks += p1.numOfBlocks;
|
||||
pDistInfo->numOfTables += p1.numOfTables;
|
||||
pDistInfo->numOfInmemRows += p1.numOfInmemRows;
|
||||
pDistInfo->totalSize += p1.totalSize;
|
||||
pDistInfo->totalRows += p1.totalRows;
|
||||
pDistInfo->numOfFiles += p1.numOfFiles;
|
||||
|
||||
if (pDistInfo->minRows > p1.minRows) {
|
||||
pDistInfo->minRows = p1.minRows;
|
||||
}
|
||||
if (pDistInfo->maxRows < p1.maxRows) {
|
||||
pDistInfo->maxRows = p1.maxRows;
|
||||
}
|
||||
|
||||
for(int32_t i = 0; i < tListLen(pDistInfo->blockRowsHisto); ++i) {
|
||||
pDistInfo->blockRowsHisto[i] += p1.blockRowsHisto[i];
|
||||
}
|
||||
|
||||
pResInfo->numOfRes = 1;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tSerializeBlockDistInfo(void* buf, int32_t bufLen, const STableBlockDistInfo* pInfo) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeU32(&encoder, pInfo->rowSize) < 0) return -1;
|
||||
|
||||
if (tEncodeU16(&encoder, pInfo->numOfFiles) < 0) return -1;
|
||||
if (tEncodeU32(&encoder, pInfo->rowSize) < 0) return -1;
|
||||
if (tEncodeU32(&encoder, pInfo->numOfTables) < 0) return -1;
|
||||
|
||||
if (tEncodeU64(&encoder, pInfo->totalSize) < 0) return -1;
|
||||
if (tEncodeU64(&encoder, pInfo->totalRows) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pInfo->maxRows) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pInfo->minRows) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pInfo->defMaxRows) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pInfo->defMinRows) < 0) return -1;
|
||||
if (tEncodeU32(&encoder, pInfo->numOfInmemRows) < 0) return -1;
|
||||
if (tEncodeU32(&encoder, pInfo->numOfSmallBlocks) < 0) return -1;
|
||||
|
||||
for(int32_t i = 0; i < tListLen(pInfo->blockRowsHisto); ++i) {
|
||||
if (tEncodeI32(&encoder, pInfo->blockRowsHisto[i]) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tEncoderClear(&encoder);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeBlockDistInfo(void* buf, int32_t bufLen, STableBlockDistInfo* pInfo) {
|
||||
SDecoder decoder = {0};
|
||||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeU32(&decoder, &pInfo->rowSize) < 0) return -1;
|
||||
|
||||
if (tDecodeU16(&decoder, &pInfo->numOfFiles) < 0) return -1;
|
||||
if (tDecodeU32(&decoder, &pInfo->rowSize) < 0) return -1;
|
||||
if (tDecodeU32(&decoder, &pInfo->numOfTables) < 0) return -1;
|
||||
|
||||
if (tDecodeU64(&decoder, &pInfo->totalSize) < 0) return -1;
|
||||
if (tDecodeU64(&decoder, &pInfo->totalRows) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pInfo->maxRows) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pInfo->minRows) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pInfo->defMaxRows) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pInfo->defMinRows) < 0) return -1;
|
||||
if (tDecodeU32(&decoder, &pInfo->numOfInmemRows) < 0) return -1;
|
||||
if (tDecodeU32(&decoder, &pInfo->numOfSmallBlocks) < 0) return -1;
|
||||
|
||||
for(int32_t i = 0; i < tListLen(pInfo->blockRowsHisto); ++i) {
|
||||
if (tDecodeI32(&decoder, &pInfo->blockRowsHisto[i]) < 0) return -1;
|
||||
}
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
|
||||
char *pData = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
|
||||
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, 0);
|
||||
|
||||
int32_t row = 0;
|
||||
|
||||
STableBlockDistInfo info = {0};
|
||||
tDeserializeBlockDistInfo(varDataVal(pData), varDataLen(pData), &info);
|
||||
|
||||
char st[256] = {0};
|
||||
int32_t len = sprintf(st+VARSTR_HEADER_SIZE, "Blocks=[%d] Size=[%.3fKb] Average_Block_size=[%.3fKb] Compression_Ratio=[%.3f]", info.numOfBlocks,
|
||||
info.totalSize/1024.0,
|
||||
info.totalSize/(info.numOfBlocks*1024.0),
|
||||
info.totalSize/(info.totalRows*info.rowSize*1.0)
|
||||
);
|
||||
|
||||
varDataSetLen(st, len);
|
||||
colDataAppend(pColInfo, row++, st, false);
|
||||
|
||||
len = sprintf(st+VARSTR_HEADER_SIZE, "Total_Rows=[%ld] MinRows=[%d] MaxRows=[%d] Averge_Rows=[%ld] Inmem_Rows=[%d]",
|
||||
info.totalRows,
|
||||
info.minRows,
|
||||
info.maxRows,
|
||||
info.totalRows/info.numOfBlocks,
|
||||
info.numOfInmemRows
|
||||
);
|
||||
|
||||
varDataSetLen(st, len);
|
||||
colDataAppend(pColInfo, row++, st, false);
|
||||
|
||||
len = sprintf(st + VARSTR_HEADER_SIZE, "Total_Tables=[%d] Total_Files=[%d] Total_Vgroups=[%d]",
|
||||
info.numOfTables,
|
||||
info.numOfFiles, 0);
|
||||
|
||||
varDataSetLen(st, len);
|
||||
colDataAppend(pColInfo, row++, st, false);
|
||||
|
||||
len = sprintf(st+VARSTR_HEADER_SIZE, "--------------------------------------------------------------------------------");
|
||||
varDataSetLen(st, len);
|
||||
colDataAppend(pColInfo, row++, st, false);
|
||||
|
||||
int32_t maxVal = 0;
|
||||
int32_t minVal = INT32_MAX;
|
||||
for(int32_t i = 0; i < sizeof(info.blockRowsHisto)/sizeof(info.blockRowsHisto[0]); ++i) {
|
||||
if (maxVal < info.blockRowsHisto[i]) {
|
||||
maxVal = info.blockRowsHisto[i];
|
||||
}
|
||||
|
||||
if (minVal > info.blockRowsHisto[i]) {
|
||||
minVal = info.blockRowsHisto[i];
|
||||
}
|
||||
}
|
||||
|
||||
int32_t delta = maxVal - minVal;
|
||||
int32_t step = delta / 50;
|
||||
|
||||
int32_t numOfBuckets = sizeof(info.blockRowsHisto)/sizeof(info.blockRowsHisto[0]);
|
||||
int32_t bucketRange = (info.maxRows - info.minRows) / numOfBuckets;
|
||||
|
||||
for(int32_t i = 0; i < 20; ++i) {
|
||||
len += sprintf(st + VARSTR_HEADER_SIZE, "%04d |", info.defMinRows + bucketRange * (i + 1));
|
||||
|
||||
int32_t num = (info.blockRowsHisto[i] + step - 1) / step;
|
||||
for (int32_t j = 0; j < num; ++j) {
|
||||
int32_t x = sprintf(st + VARSTR_HEADER_SIZE + len, "%c", '|');
|
||||
len += x;
|
||||
}
|
||||
|
||||
double v = info.blockRowsHisto[i] * 100.0 / info.numOfBlocks;
|
||||
len += sprintf(st+ VARSTR_HEADER_SIZE + len, " %d (%.3f%c)", info.blockRowsHisto[i], v, '%');
|
||||
printf("%s\n", st);
|
||||
|
||||
varDataSetLen(st, len);
|
||||
colDataAppend(pColInfo, row++, st, false);
|
||||
}
|
||||
|
||||
return row;
|
||||
}
|
||||
|
|
|
@ -200,6 +200,21 @@ bool fmIsInvertible(int32_t funcId) {
|
|||
return res;
|
||||
}
|
||||
|
||||
static int32_t getFuncInfo(SFunctionNode* pFunc) {
|
||||
char msg[64] = {0};
|
||||
if (NULL != gFunMgtService.pFuncNameHashTable) {
|
||||
return fmGetFuncInfo(pFunc, msg, sizeof(msg));
|
||||
}
|
||||
for (int32_t i = 0; i < funcMgtBuiltinsNum; ++i) {
|
||||
if (0 == strcmp(funcMgtBuiltins[i].name, pFunc->functionName)) {
|
||||
pFunc->funcId = i;
|
||||
pFunc->funcType = funcMgtBuiltins[pFunc->funcId].type;
|
||||
return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, msg, sizeof(msg));
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_FUNC_NOT_BUILTIN_FUNTION;
|
||||
}
|
||||
|
||||
static SFunctionNode* createFunction(const char* pName, SNodeList* pParameterList) {
|
||||
SFunctionNode* pFunc = nodesMakeNode(QUERY_NODE_FUNCTION);
|
||||
if (NULL == pFunc) {
|
||||
|
@ -207,8 +222,8 @@ static SFunctionNode* createFunction(const char* pName, SNodeList* pParameterLis
|
|||
}
|
||||
strcpy(pFunc->functionName, pName);
|
||||
pFunc->pParameterList = pParameterList;
|
||||
char msg[64] = {0};
|
||||
if (TSDB_CODE_SUCCESS != fmGetFuncInfo(pFunc, msg, sizeof(msg))) {
|
||||
if (TSDB_CODE_SUCCESS != getFuncInfo(pFunc)) {
|
||||
pFunc->pParameterList = NULL;
|
||||
nodesDestroyNode(pFunc);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -3684,7 +3684,7 @@ static void blockDistInfoFromBinary(const char* data, int32_t len, STableBlockDi
|
|||
pDist->totalRows = tbufReadUint64(&br);
|
||||
pDist->maxRows = tbufReadInt32(&br);
|
||||
pDist->minRows = tbufReadInt32(&br);
|
||||
pDist->numOfRowsInMemTable = tbufReadUint32(&br);
|
||||
pDist->numOfInmemRows = tbufReadUint32(&br);
|
||||
pDist->numOfSmallBlocks = tbufReadUint32(&br);
|
||||
int64_t numSteps = tbufReadUint64(&br);
|
||||
|
||||
|
@ -3732,7 +3732,7 @@ static void mergeTableBlockDist(SResultRowEntryInfo* pResInfo, const STableBlock
|
|||
assert(pDist != NULL && pSrc != NULL);
|
||||
|
||||
pDist->numOfTables += pSrc->numOfTables;
|
||||
pDist->numOfRowsInMemTable += pSrc->numOfRowsInMemTable;
|
||||
pDist->numOfInmemRows += pSrc->numOfInmemRows;
|
||||
pDist->numOfSmallBlocks += pSrc->numOfSmallBlocks;
|
||||
pDist->numOfFiles += pSrc->numOfFiles;
|
||||
pDist->totalSize += pSrc->totalSize;
|
||||
|
@ -3862,7 +3862,7 @@ void generateBlockDistResult(STableBlockDistInfo *pTableBlockDist, char* result)
|
|||
percentiles[6], percentiles[7], percentiles[8], percentiles[9], percentiles[10], percentiles[11],
|
||||
min, max, avg, stdDev,
|
||||
totalRows, totalBlocks, smallBlocks, totalLen/1024.0, compRatio,
|
||||
pTableBlockDist->numOfRowsInMemTable);
|
||||
pTableBlockDist->numOfInmemRows);
|
||||
varDataSetLen(result, sz);
|
||||
UNUSED(sz);
|
||||
}
|
||||
|
|
|
@ -127,9 +127,11 @@ int32_t tBucketIntHash(tMemBucket *pBucket, const void *value) {
|
|||
int64_t delta = v - pBucket->range.i64MinVal;
|
||||
index = (delta % pBucket->numOfSlots);
|
||||
} else {
|
||||
double slotSpan = (double)span / pBucket->numOfSlots;
|
||||
index = (int32_t)((v - pBucket->range.i64MinVal) / slotSpan);
|
||||
if (v == pBucket->range.i64MaxVal) {
|
||||
double slotSpan = ((double)span) / pBucket->numOfSlots;
|
||||
uint64_t delta = v - pBucket->range.i64MinVal;
|
||||
|
||||
index = (int32_t)(delta / slotSpan);
|
||||
if (v == pBucket->range.i64MaxVal || index == pBucket->numOfSlots) {
|
||||
index -= 1;
|
||||
}
|
||||
}
|
||||
|
@ -324,7 +326,6 @@ int32_t tMemBucketPut(tMemBucket *pBucket, const void *data, size_t size) {
|
|||
int32_t bytes = pBucket->bytes;
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
char *d = (char *) data + i * bytes;
|
||||
|
||||
int32_t index = (pBucket->hashFunc)(pBucket, d);
|
||||
if (index < 0) {
|
||||
continue;
|
||||
|
|
|
@ -62,25 +62,25 @@ typedef struct CacheTerm {
|
|||
} CacheTerm;
|
||||
//
|
||||
|
||||
IndexCache* indexCacheCreate(SIndex* idx, uint64_t suid, const char* colName, int8_t type);
|
||||
IndexCache* idxCacheCreate(SIndex* idx, uint64_t suid, const char* colName, int8_t type);
|
||||
|
||||
void indexCacheForceToMerge(void* cache);
|
||||
void indexCacheDestroy(void* cache);
|
||||
void indexCacheBroadcast(void* cache);
|
||||
void indexCacheWait(void* cache);
|
||||
void idxCacheForceToMerge(void* cache);
|
||||
void idxCacheDestroy(void* cache);
|
||||
void idxCacheBroadcast(void* cache);
|
||||
void idxCacheWait(void* cache);
|
||||
|
||||
Iterate* indexCacheIteratorCreate(IndexCache* cache);
|
||||
Iterate* idxCacheIteratorCreate(IndexCache* cache);
|
||||
void idxCacheIteratorDestroy(Iterate* iiter);
|
||||
|
||||
int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid);
|
||||
int idxCachePut(void* cache, SIndexTerm* term, uint64_t uid);
|
||||
|
||||
// int indexCacheGet(void *cache, uint64_t *rst);
|
||||
int indexCacheSearch(void* cache, SIndexTermQuery* query, SIdxTRslt* tr, STermValueType* s);
|
||||
int idxCacheSearch(void* cache, SIndexTermQuery* query, SIdxTRslt* tr, STermValueType* s);
|
||||
|
||||
void indexCacheRef(IndexCache* cache);
|
||||
void indexCacheUnRef(IndexCache* cache);
|
||||
void idxCacheRef(IndexCache* cache);
|
||||
void idxCacheUnRef(IndexCache* cache);
|
||||
|
||||
void indexCacheDebug(IndexCache* cache);
|
||||
void idxCacheDebug(IndexCache* cache);
|
||||
|
||||
void idxCacheDestroyImm(IndexCache* cache);
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -34,11 +34,11 @@ typedef enum { MATCH, CONTINUE, BREAK } TExeCond;
|
|||
|
||||
typedef TExeCond (*_cache_range_compare)(void* a, void* b, int8_t type);
|
||||
|
||||
__compar_fn_t indexGetCompar(int8_t type);
|
||||
__compar_fn_t idxGetCompar(int8_t type);
|
||||
TExeCond tCompare(__compar_fn_t func, int8_t cmpType, void* a, void* b, int8_t dType);
|
||||
TExeCond tDoCompare(__compar_fn_t func, int8_t cmpType, void* a, void* b);
|
||||
|
||||
_cache_range_compare indexGetCompare(RangeType ty);
|
||||
_cache_range_compare idxGetCompare(RangeType ty);
|
||||
|
||||
int32_t idxConvertData(void* src, int8_t type, void** dst);
|
||||
int32_t idxConvertDataToStr(void* src, int8_t type, void** dst);
|
||||
|
|
|
@ -133,24 +133,24 @@ typedef struct TFileCacheKey {
|
|||
} ICacheKey;
|
||||
int idxFlushCacheToTFile(SIndex* sIdx, void*, bool quit);
|
||||
|
||||
int64_t indexAddRef(void* p);
|
||||
int32_t indexRemoveRef(int64_t ref);
|
||||
void indexAcquireRef(int64_t ref);
|
||||
void indexReleaseRef(int64_t ref);
|
||||
int64_t idxAddRef(void* p);
|
||||
int32_t idxRemoveRef(int64_t ref);
|
||||
void idxAcquireRef(int64_t ref);
|
||||
void idxReleaseRef(int64_t ref);
|
||||
|
||||
int32_t indexSerialCacheKey(ICacheKey* key, char* buf);
|
||||
int32_t idxSerialCacheKey(ICacheKey* key, char* buf);
|
||||
// int32_t indexSerialKey(ICacheKey* key, char* buf);
|
||||
// int32_t indexSerialTermKey(SIndexTerm* itm, char* buf);
|
||||
|
||||
#define INDEX_TYPE_CONTAIN_EXTERN_TYPE(ty, exTy) (((ty >> 4) & (exTy)) != 0)
|
||||
#define IDX_TYPE_CONTAIN_EXTERN_TYPE(ty, exTy) (((ty >> 4) & (exTy)) != 0)
|
||||
|
||||
#define INDEX_TYPE_GET_TYPE(ty) (ty & 0x0F)
|
||||
#define IDX_TYPE_GET_TYPE(ty) (ty & 0x0F)
|
||||
|
||||
#define INDEX_TYPE_ADD_EXTERN_TYPE(ty, exTy) \
|
||||
do { \
|
||||
uint8_t oldTy = ty; \
|
||||
ty = (ty >> 4) | exTy; \
|
||||
ty = (ty << 4) | oldTy; \
|
||||
#define IDX_TYPE_ADD_EXTERN_TYPE(ty, exTy) \
|
||||
do { \
|
||||
uint8_t oldTy = ty; \
|
||||
ty = (ty >> 4) | exTy; \
|
||||
ty = (ty << 4) | oldTy; \
|
||||
} while (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -117,10 +117,10 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order);
|
|||
int tfileWriterFinish(TFileWriter* tw);
|
||||
|
||||
//
|
||||
IndexTFile* indexTFileCreate(const char* path);
|
||||
void indexTFileDestroy(IndexTFile* tfile);
|
||||
int indexTFilePut(void* tfile, SIndexTerm* term, uint64_t uid);
|
||||
int indexTFileSearch(void* tfile, SIndexTermQuery* query, SIdxTRslt* tr);
|
||||
IndexTFile* idxTFileCreate(const char* path);
|
||||
void idxTFileDestroy(IndexTFile* tfile);
|
||||
int idxTFilePut(void* tfile, SIndexTerm* term, uint64_t uid);
|
||||
int idxTFileSearch(void* tfile, SIndexTermQuery* query, SIdxTRslt* tr);
|
||||
|
||||
Iterate* tfileIteratorCreate(TFileReader* reader);
|
||||
void tfileIteratorDestroy(Iterate* iterator);
|
||||
|
|
|
@ -90,7 +90,7 @@ static void idxMergeCacheAndTFile(SArray* result, IterateValue* icache, IterateV
|
|||
// static int32_t indexSerialTermKey(SIndexTerm* itm, char* buf);
|
||||
// int32_t indexSerialKey(ICacheKey* key, char* buf);
|
||||
|
||||
static void indexPost(void* idx) {
|
||||
static void idxPost(void* idx) {
|
||||
SIndex* pIdx = idx;
|
||||
tsem_post(&pIdx->sem);
|
||||
}
|
||||
|
@ -106,8 +106,8 @@ int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
// sIdx->cache = (void*)indexCacheCreate(sIdx);
|
||||
sIdx->tindex = indexTFileCreate(path);
|
||||
// sIdx->cache = (void*)idxCacheCreate(sIdx);
|
||||
sIdx->tindex = idxTFileCreate(path);
|
||||
if (sIdx->tindex == NULL) {
|
||||
goto END;
|
||||
}
|
||||
|
@ -118,8 +118,8 @@ int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) {
|
|||
taosThreadMutexInit(&sIdx->mtx, NULL);
|
||||
tsem_init(&sIdx->sem, 0, 0);
|
||||
|
||||
sIdx->refId = indexAddRef(sIdx);
|
||||
indexAcquireRef(sIdx->refId);
|
||||
sIdx->refId = idxAddRef(sIdx);
|
||||
idxAcquireRef(sIdx->refId);
|
||||
|
||||
*index = sIdx;
|
||||
return 0;
|
||||
|
@ -136,7 +136,7 @@ void indexDestroy(void* handle) {
|
|||
SIndex* sIdx = handle;
|
||||
taosThreadMutexDestroy(&sIdx->mtx);
|
||||
tsem_destroy(&sIdx->sem);
|
||||
indexTFileDestroy(sIdx->tindex);
|
||||
idxTFileDestroy(sIdx->tindex);
|
||||
taosMemoryFree(sIdx->path);
|
||||
taosMemoryFree(sIdx);
|
||||
return;
|
||||
|
@ -147,33 +147,33 @@ void indexClose(SIndex* sIdx) {
|
|||
void* iter = taosHashIterate(sIdx->colObj, NULL);
|
||||
while (iter) {
|
||||
IndexCache** pCache = iter;
|
||||
indexCacheForceToMerge((void*)(*pCache));
|
||||
idxCacheForceToMerge((void*)(*pCache));
|
||||
indexInfo("%s wait to merge", (*pCache)->colName);
|
||||
indexWait((void*)(sIdx));
|
||||
indexInfo("%s finish to wait", (*pCache)->colName);
|
||||
iter = taosHashIterate(sIdx->colObj, iter);
|
||||
indexCacheUnRef(*pCache);
|
||||
idxCacheUnRef(*pCache);
|
||||
}
|
||||
taosHashCleanup(sIdx->colObj);
|
||||
sIdx->colObj = NULL;
|
||||
}
|
||||
indexReleaseRef(sIdx->refId);
|
||||
indexRemoveRef(sIdx->refId);
|
||||
idxReleaseRef(sIdx->refId);
|
||||
idxRemoveRef(sIdx->refId);
|
||||
}
|
||||
int64_t indexAddRef(void* p) {
|
||||
int64_t idxAddRef(void* p) {
|
||||
// impl
|
||||
return taosAddRef(indexRefMgt, p);
|
||||
}
|
||||
int32_t indexRemoveRef(int64_t ref) {
|
||||
int32_t idxRemoveRef(int64_t ref) {
|
||||
// impl later
|
||||
return taosRemoveRef(indexRefMgt, ref);
|
||||
}
|
||||
|
||||
void indexAcquireRef(int64_t ref) {
|
||||
void idxAcquireRef(int64_t ref) {
|
||||
// impl
|
||||
taosAcquireRef(indexRefMgt, ref);
|
||||
}
|
||||
void indexReleaseRef(int64_t ref) {
|
||||
void idxReleaseRef(int64_t ref) {
|
||||
// impl
|
||||
taosReleaseRef(indexRefMgt, ref);
|
||||
}
|
||||
|
@ -186,11 +186,11 @@ int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) {
|
|||
|
||||
char buf[128] = {0};
|
||||
ICacheKey key = {.suid = p->suid, .colName = p->colName, .nColName = strlen(p->colName), .colType = p->colType};
|
||||
int32_t sz = indexSerialCacheKey(&key, buf);
|
||||
int32_t sz = idxSerialCacheKey(&key, buf);
|
||||
|
||||
IndexCache** cache = taosHashGet(index->colObj, buf, sz);
|
||||
if (cache == NULL) {
|
||||
IndexCache* pCache = indexCacheCreate(index, p->suid, p->colName, p->colType);
|
||||
IndexCache* pCache = idxCacheCreate(index, p->suid, p->colName, p->colType);
|
||||
taosHashPut(index->colObj, buf, sz, &pCache, sizeof(void*));
|
||||
}
|
||||
}
|
||||
|
@ -201,12 +201,12 @@ int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) {
|
|||
|
||||
char buf[128] = {0};
|
||||
ICacheKey key = {.suid = p->suid, .colName = p->colName, .nColName = strlen(p->colName), .colType = p->colType};
|
||||
int32_t sz = indexSerialCacheKey(&key, buf);
|
||||
int32_t sz = idxSerialCacheKey(&key, buf);
|
||||
indexDebug("w suid: %" PRIu64 ", colName: %s, colType: %d", key.suid, key.colName, key.colType);
|
||||
|
||||
IndexCache** cache = taosHashGet(index->colObj, buf, sz);
|
||||
assert(*cache != NULL);
|
||||
int ret = indexCachePut(*cache, p, uid);
|
||||
int ret = idxCachePut(*cache, p, uid);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, uint8_t colTy
|
|||
tm->nColName = nColName;
|
||||
|
||||
char* buf = NULL;
|
||||
int32_t len = idxConvertDataToStr((void*)colVal, INDEX_TYPE_GET_TYPE(colType), (void**)&buf);
|
||||
int32_t len = idxConvertDataToStr((void*)colVal, IDX_TYPE_GET_TYPE(colType), (void**)&buf);
|
||||
assert(len != -1);
|
||||
|
||||
tm->colVal = buf;
|
||||
|
@ -331,7 +331,7 @@ static int idxTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result)
|
|||
ICacheKey key = {
|
||||
.suid = term->suid, .colName = term->colName, .nColName = strlen(term->colName), .colType = term->colType};
|
||||
indexDebug("r suid: %" PRIu64 ", colName: %s, colType: %d", key.suid, key.colName, key.colType);
|
||||
int32_t sz = indexSerialCacheKey(&key, buf);
|
||||
int32_t sz = idxSerialCacheKey(&key, buf);
|
||||
|
||||
taosThreadMutexLock(&sIdx->mtx);
|
||||
IndexCache** pCache = taosHashGet(sIdx->colObj, buf, sz);
|
||||
|
@ -345,14 +345,14 @@ static int idxTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result)
|
|||
int64_t st = taosGetTimestampUs();
|
||||
|
||||
SIdxTRslt* tr = idxTRsltCreate();
|
||||
if (0 == indexCacheSearch(cache, query, tr, &s)) {
|
||||
if (0 == idxCacheSearch(cache, query, tr, &s)) {
|
||||
if (s == kTypeDeletion) {
|
||||
indexInfo("col: %s already drop by", term->colName);
|
||||
// coloum already drop by other oper, no need to query tindex
|
||||
return 0;
|
||||
} else {
|
||||
st = taosGetTimestampUs();
|
||||
if (0 != indexTFileSearch(sIdx->tindex, query, tr)) {
|
||||
if (0 != idxTFileSearch(sIdx->tindex, query, tr)) {
|
||||
indexError("corrupt at index(TFile) col:%s val: %s", term->colName, term->colVal);
|
||||
goto END;
|
||||
}
|
||||
|
@ -465,23 +465,23 @@ int idxFlushCacheToTFile(SIndex* sIdx, void* cache, bool quit) {
|
|||
|
||||
IndexCache* pCache = (IndexCache*)cache;
|
||||
|
||||
while (quit && atomic_load_32(&pCache->merging) == 1) {
|
||||
}
|
||||
while (quit && atomic_load_32(&pCache->merging) == 1)
|
||||
;
|
||||
TFileReader* pReader = tfileGetReaderByCol(sIdx->tindex, pCache->suid, pCache->colName);
|
||||
if (pReader == NULL) {
|
||||
indexWarn("empty tfile reader found");
|
||||
}
|
||||
// handle flush
|
||||
Iterate* cacheIter = indexCacheIteratorCreate(pCache);
|
||||
Iterate* cacheIter = idxCacheIteratorCreate(pCache);
|
||||
if (cacheIter == NULL) {
|
||||
indexError("%p immtable is empty, ignore merge opera", pCache);
|
||||
idxCacheDestroyImm(pCache);
|
||||
tfileReaderUnRef(pReader);
|
||||
atomic_store_32(&pCache->merging, 0);
|
||||
if (quit) {
|
||||
indexPost(sIdx);
|
||||
idxPost(sIdx);
|
||||
}
|
||||
indexReleaseRef(sIdx->refId);
|
||||
idxReleaseRef(sIdx->refId);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -532,7 +532,7 @@ int idxFlushCacheToTFile(SIndex* sIdx, void* cache, bool quit) {
|
|||
tfileIteratorDestroy(tfileIter);
|
||||
|
||||
tfileReaderUnRef(pReader);
|
||||
indexCacheUnRef(pCache);
|
||||
idxCacheUnRef(pCache);
|
||||
|
||||
int64_t cost = taosGetTimestampUs() - st;
|
||||
if (ret != 0) {
|
||||
|
@ -542,9 +542,9 @@ int idxFlushCacheToTFile(SIndex* sIdx, void* cache, bool quit) {
|
|||
}
|
||||
atomic_store_32(&pCache->merging, 0);
|
||||
if (quit) {
|
||||
indexPost(sIdx);
|
||||
idxPost(sIdx);
|
||||
}
|
||||
indexReleaseRef(sIdx->refId);
|
||||
idxReleaseRef(sIdx->refId);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -561,7 +561,7 @@ void iterateValueDestroy(IterateValue* value, bool destroy) {
|
|||
value->colVal = NULL;
|
||||
}
|
||||
|
||||
static int64_t indexGetAvaialbleVer(SIndex* sIdx, IndexCache* cache) {
|
||||
static int64_t idxGetAvailableVer(SIndex* sIdx, IndexCache* cache) {
|
||||
ICacheKey key = {.suid = cache->suid, .colName = cache->colName, .nColName = strlen(cache->colName)};
|
||||
int64_t ver = CACHE_VERSION(cache);
|
||||
|
||||
|
@ -579,7 +579,7 @@ static int64_t indexGetAvaialbleVer(SIndex* sIdx, IndexCache* cache) {
|
|||
return ver;
|
||||
}
|
||||
static int idxGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) {
|
||||
int64_t version = indexGetAvaialbleVer(sIdx, cache);
|
||||
int64_t version = idxGetAvailableVer(sIdx, cache);
|
||||
indexInfo("file name version: %" PRId64 "", version);
|
||||
uint8_t colType = cache->type;
|
||||
|
||||
|
@ -620,8 +620,8 @@ END:
|
|||
return -1;
|
||||
}
|
||||
|
||||
int32_t indexSerialCacheKey(ICacheKey* key, char* buf) {
|
||||
bool hasJson = INDEX_TYPE_CONTAIN_EXTERN_TYPE(key->colType, TSDB_DATA_TYPE_JSON);
|
||||
int32_t idxSerialCacheKey(ICacheKey* key, char* buf) {
|
||||
bool hasJson = IDX_TYPE_CONTAIN_EXTERN_TYPE(key->colType, TSDB_DATA_TYPE_JSON);
|
||||
|
||||
char* p = buf;
|
||||
char tbuf[65] = {0};
|
||||
|
|
|
@ -68,7 +68,7 @@ static int32_t (*cacheSearch[][QUERY_MAX])(void* cache, SIndexTerm* ct, SIdxTRsl
|
|||
cacheSearchLessThan_JSON, cacheSearchLessEqual_JSON, cacheSearchGreaterThan_JSON, cacheSearchGreaterEqual_JSON,
|
||||
cacheSearchRange_JSON}};
|
||||
|
||||
static void doMergeWork(SSchedMsg* msg);
|
||||
static void idxDoMergeWork(SSchedMsg* msg);
|
||||
static bool idxCacheIteratorNext(Iterate* itera);
|
||||
|
||||
static int32_t cacheSearchTerm(void* cache, SIndexTerm* term, SIdxTRslt* tr, STermValueType* s) {
|
||||
|
@ -127,7 +127,7 @@ static int32_t cacheSearchCompareFunc(void* cache, SIndexTerm* term, SIdxTRslt*
|
|||
MemTable* mem = cache;
|
||||
IndexCache* pCache = mem->pCache;
|
||||
|
||||
_cache_range_compare cmpFn = indexGetCompare(type);
|
||||
_cache_range_compare cmpFn = idxGetCompare(type);
|
||||
|
||||
CacheTerm* pCt = taosMemoryCalloc(1, sizeof(CacheTerm));
|
||||
pCt->colVal = term->colVal;
|
||||
|
@ -187,7 +187,7 @@ static int32_t cacheSearchTerm_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr
|
|||
pCt->version = atomic_load_64(&pCache->version);
|
||||
|
||||
char* exBuf = NULL;
|
||||
if (INDEX_TYPE_CONTAIN_EXTERN_TYPE(term->colType, TSDB_DATA_TYPE_JSON)) {
|
||||
if (IDX_TYPE_CONTAIN_EXTERN_TYPE(term->colType, TSDB_DATA_TYPE_JSON)) {
|
||||
exBuf = idxPackJsonData(term);
|
||||
pCt->colVal = exBuf;
|
||||
}
|
||||
|
@ -257,7 +257,7 @@ static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, SIdxTR
|
|||
if (cache == NULL) {
|
||||
return 0;
|
||||
}
|
||||
_cache_range_compare cmpFn = indexGetCompare(type);
|
||||
_cache_range_compare cmpFn = idxGetCompare(type);
|
||||
|
||||
MemTable* mem = cache;
|
||||
IndexCache* pCache = mem->pCache;
|
||||
|
@ -266,7 +266,7 @@ static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, SIdxTR
|
|||
pCt->colVal = term->colVal;
|
||||
pCt->version = atomic_load_64(&pCache->version);
|
||||
|
||||
int8_t dType = INDEX_TYPE_GET_TYPE(term->colType);
|
||||
int8_t dType = IDX_TYPE_GET_TYPE(term->colType);
|
||||
int skip = 0;
|
||||
char* exBuf = NULL;
|
||||
if (type == CONTAINS) {
|
||||
|
@ -331,9 +331,9 @@ static int32_t cacheSearchRange(void* cache, SIndexTerm* term, SIdxTRslt* tr, ST
|
|||
// impl later
|
||||
return 0;
|
||||
}
|
||||
static IterateValue* indexCacheIteratorGetValue(Iterate* iter);
|
||||
static IterateValue* idxCacheIteratorGetValue(Iterate* iter);
|
||||
|
||||
IndexCache* indexCacheCreate(SIndex* idx, uint64_t suid, const char* colName, int8_t type) {
|
||||
IndexCache* idxCacheCreate(SIndex* idx, uint64_t suid, const char* colName, int8_t type) {
|
||||
IndexCache* cache = taosMemoryCalloc(1, sizeof(IndexCache));
|
||||
if (cache == NULL) {
|
||||
indexError("failed to create index cache");
|
||||
|
@ -342,7 +342,7 @@ IndexCache* indexCacheCreate(SIndex* idx, uint64_t suid, const char* colName, in
|
|||
|
||||
cache->mem = idxInternalCacheCreate(type);
|
||||
cache->mem->pCache = cache;
|
||||
cache->colName = INDEX_TYPE_CONTAIN_EXTERN_TYPE(type, TSDB_DATA_TYPE_JSON) ? tstrdup(JSON_COLUMN) : tstrdup(colName);
|
||||
cache->colName = IDX_TYPE_CONTAIN_EXTERN_TYPE(type, TSDB_DATA_TYPE_JSON) ? tstrdup(JSON_COLUMN) : tstrdup(colName);
|
||||
cache->type = type;
|
||||
cache->index = idx;
|
||||
cache->version = 0;
|
||||
|
@ -352,13 +352,13 @@ IndexCache* indexCacheCreate(SIndex* idx, uint64_t suid, const char* colName, in
|
|||
taosThreadMutexInit(&cache->mtx, NULL);
|
||||
taosThreadCondInit(&cache->finished, NULL);
|
||||
|
||||
indexCacheRef(cache);
|
||||
idxCacheRef(cache);
|
||||
if (idx != NULL) {
|
||||
indexAcquireRef(idx->refId);
|
||||
idxAcquireRef(idx->refId);
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
void indexCacheDebug(IndexCache* cache) {
|
||||
void idxCacheDebug(IndexCache* cache) {
|
||||
MemTable* tbl = NULL;
|
||||
|
||||
taosThreadMutexLock(&cache->mtx);
|
||||
|
@ -405,7 +405,7 @@ void indexCacheDebug(IndexCache* cache) {
|
|||
}
|
||||
}
|
||||
|
||||
void indexCacheDestroySkiplist(SSkipList* slt) {
|
||||
void idxCacheDestroySkiplist(SSkipList* slt) {
|
||||
SSkipListIterator* iter = tSkipListCreateIter(slt);
|
||||
while (iter != NULL && tSkipListIterNext(iter)) {
|
||||
SSkipListNode* node = tSkipListIterGet(iter);
|
||||
|
@ -418,11 +418,11 @@ void indexCacheDestroySkiplist(SSkipList* slt) {
|
|||
tSkipListDestroyIter(iter);
|
||||
tSkipListDestroy(slt);
|
||||
}
|
||||
void indexCacheBroadcast(void* cache) {
|
||||
void idxCacheBroadcast(void* cache) {
|
||||
IndexCache* pCache = cache;
|
||||
taosThreadCondBroadcast(&pCache->finished);
|
||||
}
|
||||
void indexCacheWait(void* cache) {
|
||||
void idxCacheWait(void* cache) {
|
||||
IndexCache* pCache = cache;
|
||||
taosThreadCondWait(&pCache->finished, &pCache->mtx);
|
||||
}
|
||||
|
@ -435,14 +435,14 @@ void idxCacheDestroyImm(IndexCache* cache) {
|
|||
|
||||
tbl = cache->imm;
|
||||
cache->imm = NULL; // or throw int bg thread
|
||||
indexCacheBroadcast(cache);
|
||||
idxCacheBroadcast(cache);
|
||||
|
||||
taosThreadMutexUnlock(&cache->mtx);
|
||||
|
||||
idxMemUnRef(tbl);
|
||||
idxMemUnRef(tbl);
|
||||
}
|
||||
void indexCacheDestroy(void* cache) {
|
||||
void idxCacheDestroy(void* cache) {
|
||||
IndexCache* pCache = cache;
|
||||
if (pCache == NULL) {
|
||||
return;
|
||||
|
@ -455,12 +455,12 @@ void indexCacheDestroy(void* cache) {
|
|||
taosThreadMutexDestroy(&pCache->mtx);
|
||||
taosThreadCondDestroy(&pCache->finished);
|
||||
if (pCache->index != NULL) {
|
||||
indexReleaseRef(((SIndex*)pCache->index)->refId);
|
||||
idxReleaseRef(((SIndex*)pCache->index)->refId);
|
||||
}
|
||||
taosMemoryFree(pCache);
|
||||
}
|
||||
|
||||
Iterate* indexCacheIteratorCreate(IndexCache* cache) {
|
||||
Iterate* idxCacheIteratorCreate(IndexCache* cache) {
|
||||
if (cache->imm == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -477,7 +477,7 @@ Iterate* indexCacheIteratorCreate(IndexCache* cache) {
|
|||
iiter->val.colVal = NULL;
|
||||
iiter->iter = tbl != NULL ? tSkipListCreateIter(tbl->mem) : NULL;
|
||||
iiter->next = idxCacheIteratorNext;
|
||||
iiter->getValue = indexCacheIteratorGetValue;
|
||||
iiter->getValue = idxCacheIteratorGetValue;
|
||||
|
||||
taosThreadMutexUnlock(&cache->mtx);
|
||||
|
||||
|
@ -492,30 +492,30 @@ void idxCacheIteratorDestroy(Iterate* iter) {
|
|||
taosMemoryFree(iter);
|
||||
}
|
||||
|
||||
int indexCacheSchedToMerge(IndexCache* pCache, bool notify) {
|
||||
int idxCacheSchedToMerge(IndexCache* pCache, bool notify) {
|
||||
SSchedMsg schedMsg = {0};
|
||||
schedMsg.fp = doMergeWork;
|
||||
schedMsg.fp = idxDoMergeWork;
|
||||
schedMsg.ahandle = pCache;
|
||||
if (notify) {
|
||||
schedMsg.thandle = taosMemoryMalloc(1);
|
||||
}
|
||||
schedMsg.msg = NULL;
|
||||
indexAcquireRef(pCache->index->refId);
|
||||
idxAcquireRef(pCache->index->refId);
|
||||
taosScheduleTask(indexQhandle, &schedMsg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void indexCacheMakeRoomForWrite(IndexCache* cache) {
|
||||
static void idxCacheMakeRoomForWrite(IndexCache* cache) {
|
||||
while (true) {
|
||||
if (cache->occupiedMem * MEM_ESTIMATE_RADIO < MEM_THRESHOLD) {
|
||||
break;
|
||||
} else if (cache->imm != NULL) {
|
||||
// TODO: wake up by condition variable
|
||||
indexCacheWait(cache);
|
||||
idxCacheWait(cache);
|
||||
} else {
|
||||
bool quit = cache->occupiedMem >= MEM_SIGNAL_QUIT ? true : false;
|
||||
|
||||
indexCacheRef(cache);
|
||||
idxCacheRef(cache);
|
||||
cache->imm = cache->mem;
|
||||
cache->mem = idxInternalCacheCreate(cache->type);
|
||||
cache->mem->pCache = cache;
|
||||
|
@ -525,18 +525,18 @@ static void indexCacheMakeRoomForWrite(IndexCache* cache) {
|
|||
}
|
||||
// sched to merge
|
||||
// unref cache in bgwork
|
||||
indexCacheSchedToMerge(cache, quit);
|
||||
idxCacheSchedToMerge(cache, quit);
|
||||
}
|
||||
}
|
||||
}
|
||||
int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) {
|
||||
int idxCachePut(void* cache, SIndexTerm* term, uint64_t uid) {
|
||||
if (cache == NULL) {
|
||||
return -1;
|
||||
}
|
||||
bool hasJson = INDEX_TYPE_CONTAIN_EXTERN_TYPE(term->colType, TSDB_DATA_TYPE_JSON);
|
||||
bool hasJson = IDX_TYPE_CONTAIN_EXTERN_TYPE(term->colType, TSDB_DATA_TYPE_JSON);
|
||||
|
||||
IndexCache* pCache = cache;
|
||||
indexCacheRef(pCache);
|
||||
idxCacheRef(pCache);
|
||||
// encode data
|
||||
CacheTerm* ct = taosMemoryCalloc(1, sizeof(CacheTerm));
|
||||
if (cache == NULL) {
|
||||
|
@ -559,7 +559,7 @@ int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) {
|
|||
|
||||
taosThreadMutexLock(&pCache->mtx);
|
||||
pCache->occupiedMem += estimate;
|
||||
indexCacheMakeRoomForWrite(pCache);
|
||||
idxCacheMakeRoomForWrite(pCache);
|
||||
MemTable* tbl = pCache->mem;
|
||||
idxMemRef(tbl);
|
||||
tSkipListPut(tbl->mem, (char*)ct);
|
||||
|
@ -567,29 +567,29 @@ int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) {
|
|||
|
||||
taosThreadMutexUnlock(&pCache->mtx);
|
||||
|
||||
indexCacheUnRef(pCache);
|
||||
idxCacheUnRef(pCache);
|
||||
return 0;
|
||||
// encode end
|
||||
}
|
||||
void indexCacheForceToMerge(void* cache) {
|
||||
void idxCacheForceToMerge(void* cache) {
|
||||
IndexCache* pCache = cache;
|
||||
indexCacheRef(pCache);
|
||||
idxCacheRef(pCache);
|
||||
taosThreadMutexLock(&pCache->mtx);
|
||||
|
||||
indexInfo("%p is forced to merge into tfile", pCache);
|
||||
pCache->occupiedMem += MEM_SIGNAL_QUIT;
|
||||
indexCacheMakeRoomForWrite(pCache);
|
||||
idxCacheMakeRoomForWrite(pCache);
|
||||
|
||||
taosThreadMutexUnlock(&pCache->mtx);
|
||||
indexCacheUnRef(pCache);
|
||||
idxCacheUnRef(pCache);
|
||||
return;
|
||||
}
|
||||
int indexCacheDel(void* cache, const char* fieldValue, int32_t fvlen, uint64_t uid, int8_t operType) {
|
||||
int idxCacheDel(void* cache, const char* fieldValue, int32_t fvlen, uint64_t uid, int8_t operType) {
|
||||
IndexCache* pCache = cache;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t indexQueryMem(MemTable* mem, SIndexTermQuery* query, SIdxTRslt* tr, STermValueType* s) {
|
||||
static int32_t idxQueryMem(MemTable* mem, SIndexTermQuery* query, SIdxTRslt* tr, STermValueType* s) {
|
||||
if (mem == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -597,13 +597,13 @@ static int32_t indexQueryMem(MemTable* mem, SIndexTermQuery* query, SIdxTRslt* t
|
|||
SIndexTerm* term = query->term;
|
||||
EIndexQueryType qtype = query->qType;
|
||||
|
||||
if (INDEX_TYPE_CONTAIN_EXTERN_TYPE(term->colType, TSDB_DATA_TYPE_JSON)) {
|
||||
if (IDX_TYPE_CONTAIN_EXTERN_TYPE(term->colType, TSDB_DATA_TYPE_JSON)) {
|
||||
return cacheSearch[1][qtype](mem, term, tr, s);
|
||||
} else {
|
||||
return cacheSearch[0][qtype](mem, term, tr, s);
|
||||
}
|
||||
}
|
||||
int indexCacheSearch(void* cache, SIndexTermQuery* query, SIdxTRslt* result, STermValueType* s) {
|
||||
int idxCacheSearch(void* cache, SIndexTermQuery* query, SIdxTRslt* result, STermValueType* s) {
|
||||
int64_t st = taosGetTimestampUs();
|
||||
if (cache == NULL) {
|
||||
return 0;
|
||||
|
@ -618,10 +618,10 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SIdxTRslt* result, STe
|
|||
idxMemRef(imm);
|
||||
taosThreadMutexUnlock(&pCache->mtx);
|
||||
|
||||
int ret = (mem && mem->mem) ? indexQueryMem(mem, query, result, s) : 0;
|
||||
int ret = (mem && mem->mem) ? idxQueryMem(mem, query, result, s) : 0;
|
||||
if (ret == 0 && *s != kTypeDeletion) {
|
||||
// continue search in imm
|
||||
ret = (imm && imm->mem) ? indexQueryMem(imm, query, result, s) : 0;
|
||||
ret = (imm && imm->mem) ? idxQueryMem(imm, query, result, s) : 0;
|
||||
}
|
||||
|
||||
idxMemUnRef(mem);
|
||||
|
@ -631,20 +631,20 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SIdxTRslt* result, STe
|
|||
return ret;
|
||||
}
|
||||
|
||||
void indexCacheRef(IndexCache* cache) {
|
||||
void idxCacheRef(IndexCache* cache) {
|
||||
if (cache == NULL) {
|
||||
return;
|
||||
}
|
||||
int ref = T_REF_INC(cache);
|
||||
UNUSED(ref);
|
||||
}
|
||||
void indexCacheUnRef(IndexCache* cache) {
|
||||
void idxCacheUnRef(IndexCache* cache) {
|
||||
if (cache == NULL) {
|
||||
return;
|
||||
}
|
||||
int ref = T_REF_DEC(cache);
|
||||
if (ref == 0) {
|
||||
indexCacheDestroy(cache);
|
||||
idxCacheDestroy(cache);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -662,7 +662,7 @@ void idxMemUnRef(MemTable* tbl) {
|
|||
int ref = T_REF_DEC(tbl);
|
||||
if (ref == 0) {
|
||||
SSkipList* slt = tbl->mem;
|
||||
indexCacheDestroySkiplist(slt);
|
||||
idxCacheDestroySkiplist(slt);
|
||||
taosMemoryFree(tbl);
|
||||
}
|
||||
}
|
||||
|
@ -693,15 +693,15 @@ static int32_t idxCacheTermCompare(const void* l, const void* r) {
|
|||
return cmp;
|
||||
}
|
||||
|
||||
static int indexFindCh(char* a, char c) {
|
||||
static int idxFindCh(char* a, char c) {
|
||||
char* p = a;
|
||||
while (*p != 0 && *p++ != c) {
|
||||
}
|
||||
return p - a;
|
||||
}
|
||||
static int idxCacheJsonTermCompareImpl(char* a, char* b) {
|
||||
// int alen = indexFindCh(a, '&');
|
||||
// int blen = indexFindCh(b, '&');
|
||||
// int alen = idxFindCh(a, '&');
|
||||
// int blen = idxFindCh(b, '&');
|
||||
|
||||
// int cmp = strncmp(a, b, MIN(alen, blen));
|
||||
// if (cmp == 0) {
|
||||
|
@ -730,9 +730,9 @@ static int32_t idxCacheJsonTermCompare(const void* l, const void* r) {
|
|||
return cmp;
|
||||
}
|
||||
static MemTable* idxInternalCacheCreate(int8_t type) {
|
||||
int ttype = INDEX_TYPE_CONTAIN_EXTERN_TYPE(type, TSDB_DATA_TYPE_JSON) ? TSDB_DATA_TYPE_BINARY : TSDB_DATA_TYPE_BINARY;
|
||||
int ttype = IDX_TYPE_CONTAIN_EXTERN_TYPE(type, TSDB_DATA_TYPE_JSON) ? TSDB_DATA_TYPE_BINARY : TSDB_DATA_TYPE_BINARY;
|
||||
int32_t (*cmpFn)(const void* l, const void* r) =
|
||||
INDEX_TYPE_CONTAIN_EXTERN_TYPE(type, TSDB_DATA_TYPE_JSON) ? idxCacheJsonTermCompare : idxCacheTermCompare;
|
||||
IDX_TYPE_CONTAIN_EXTERN_TYPE(type, TSDB_DATA_TYPE_JSON) ? idxCacheJsonTermCompare : idxCacheTermCompare;
|
||||
|
||||
MemTable* tbl = taosMemoryCalloc(1, sizeof(MemTable));
|
||||
idxMemRef(tbl);
|
||||
|
@ -742,7 +742,7 @@ static MemTable* idxInternalCacheCreate(int8_t type) {
|
|||
return tbl;
|
||||
}
|
||||
|
||||
static void doMergeWork(SSchedMsg* msg) {
|
||||
static void idxDoMergeWork(SSchedMsg* msg) {
|
||||
IndexCache* pCache = msg->ahandle;
|
||||
SIndex* sidx = (SIndex*)pCache->index;
|
||||
|
||||
|
@ -771,7 +771,7 @@ static bool idxCacheIteratorNext(Iterate* itera) {
|
|||
return next;
|
||||
}
|
||||
|
||||
static IterateValue* indexCacheIteratorGetValue(Iterate* iter) {
|
||||
static IterateValue* idxCacheIteratorGetValue(Iterate* iter) {
|
||||
// opt later
|
||||
return &iter->val;
|
||||
}
|
||||
|
|
|
@ -75,35 +75,35 @@ char* idxInt2str(int64_t val, char* dst, int radix) {
|
|||
;
|
||||
return dst - 1;
|
||||
}
|
||||
__compar_fn_t indexGetCompar(int8_t type) {
|
||||
__compar_fn_t idxGetCompar(int8_t type) {
|
||||
if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) {
|
||||
return (__compar_fn_t)strcmp;
|
||||
}
|
||||
return getComparFunc(type, 0);
|
||||
}
|
||||
static TExeCond tCompareLessThan(void* a, void* b, int8_t type) {
|
||||
__compar_fn_t func = indexGetCompar(type);
|
||||
__compar_fn_t func = idxGetCompar(type);
|
||||
return tCompare(func, QUERY_LESS_THAN, a, b, type);
|
||||
}
|
||||
static TExeCond tCompareLessEqual(void* a, void* b, int8_t type) {
|
||||
__compar_fn_t func = indexGetCompar(type);
|
||||
__compar_fn_t func = idxGetCompar(type);
|
||||
return tCompare(func, QUERY_LESS_EQUAL, a, b, type);
|
||||
}
|
||||
static TExeCond tCompareGreaterThan(void* a, void* b, int8_t type) {
|
||||
__compar_fn_t func = indexGetCompar(type);
|
||||
__compar_fn_t func = idxGetCompar(type);
|
||||
return tCompare(func, QUERY_GREATER_THAN, a, b, type);
|
||||
}
|
||||
static TExeCond tCompareGreaterEqual(void* a, void* b, int8_t type) {
|
||||
__compar_fn_t func = indexGetCompar(type);
|
||||
__compar_fn_t func = idxGetCompar(type);
|
||||
return tCompare(func, QUERY_GREATER_EQUAL, a, b, type);
|
||||
}
|
||||
|
||||
static TExeCond tCompareContains(void* a, void* b, int8_t type) {
|
||||
__compar_fn_t func = indexGetCompar(type);
|
||||
__compar_fn_t func = idxGetCompar(type);
|
||||
return tCompare(func, QUERY_TERM, a, b, type);
|
||||
}
|
||||
static TExeCond tCompareEqual(void* a, void* b, int8_t type) {
|
||||
__compar_fn_t func = indexGetCompar(type);
|
||||
__compar_fn_t func = idxGetCompar(type);
|
||||
return tCompare(func, QUERY_TERM, a, b, type);
|
||||
}
|
||||
TExeCond tCompare(__compar_fn_t func, int8_t cmptype, void* a, void* b, int8_t dtype) {
|
||||
|
@ -205,14 +205,14 @@ TExeCond tDoCompare(__compar_fn_t func, int8_t comparType, void* a, void* b) {
|
|||
static TExeCond (*rangeCompare[])(void* a, void* b, int8_t type) = {
|
||||
tCompareLessThan, tCompareLessEqual, tCompareGreaterThan, tCompareGreaterEqual, tCompareContains, tCompareEqual};
|
||||
|
||||
_cache_range_compare indexGetCompare(RangeType ty) { return rangeCompare[ty]; }
|
||||
_cache_range_compare idxGetCompare(RangeType ty) { return rangeCompare[ty]; }
|
||||
|
||||
char* idxPackJsonData(SIndexTerm* itm) {
|
||||
/*
|
||||
* |<-----colname---->|<-----dataType---->|<--------colVal---------->|
|
||||
* |<-----string----->|<-----uint8_t----->|<----depend on dataType-->|
|
||||
*/
|
||||
uint8_t ty = INDEX_TYPE_GET_TYPE(itm->colType);
|
||||
uint8_t ty = IDX_TYPE_GET_TYPE(itm->colType);
|
||||
|
||||
int32_t sz = itm->nColName + itm->nColVal + sizeof(uint8_t) + sizeof(JSON_VALUE_DELIM) * 2 + 1;
|
||||
char* buf = (char*)taosMemoryCalloc(1, sz);
|
||||
|
@ -240,7 +240,7 @@ char* idxPackJsonDataPrefix(SIndexTerm* itm, int32_t* skip) {
|
|||
* |<-----colname---->|<-----dataType---->|<--------colVal---------->|
|
||||
* |<-----string----->|<-----uint8_t----->|<----depend on dataType-->|
|
||||
*/
|
||||
uint8_t ty = INDEX_TYPE_GET_TYPE(itm->colType);
|
||||
uint8_t ty = IDX_TYPE_GET_TYPE(itm->colType);
|
||||
|
||||
int32_t sz = itm->nColName + itm->nColVal + sizeof(uint8_t) + sizeof(JSON_VALUE_DELIM) * 2 + 1;
|
||||
char* buf = (char*)taosMemoryCalloc(1, sz);
|
||||
|
@ -267,7 +267,7 @@ char* idxPackJsonDataPrefixNoType(SIndexTerm* itm, int32_t* skip) {
|
|||
* |<-----colname---->|<-----dataType---->|<--------colVal---------->|
|
||||
* |<-----string----->|<-----uint8_t----->|<----depend on dataType-->|
|
||||
*/
|
||||
uint8_t ty = INDEX_TYPE_GET_TYPE(itm->colType);
|
||||
uint8_t ty = IDX_TYPE_GET_TYPE(itm->colType);
|
||||
|
||||
int32_t sz = itm->nColName + itm->nColVal + sizeof(uint8_t) + sizeof(JSON_VALUE_DELIM) * 2 + 1;
|
||||
char* buf = (char*)taosMemoryCalloc(1, sz);
|
||||
|
|
|
@ -318,7 +318,7 @@ int sifLessThan(void *a, void *b, int16_t dtype) {
|
|||
}
|
||||
int sifEqual(void *a, void *b, int16_t dtype) {
|
||||
__compar_fn_t func = getComparFunc(dtype, 0);
|
||||
//__compar_fn_t func = indexGetCompar(dtype);
|
||||
//__compar_fn_t func = idxGetCompar(dtype);
|
||||
return (int)tDoCompare(func, QUERY_TERM, a, b);
|
||||
}
|
||||
static Filter sifGetFilterFunc(EIndexQueryType type, bool *reverse) {
|
||||
|
|
|
@ -30,7 +30,7 @@ int indexJsonPut(SIndexJson *index, SIndexJsonMultiTerm *terms, uint64_t uid) {
|
|||
} else {
|
||||
p->colType = TSDB_DATA_TYPE_DOUBLE;
|
||||
}
|
||||
INDEX_TYPE_ADD_EXTERN_TYPE(p->colType, TSDB_DATA_TYPE_JSON);
|
||||
IDX_TYPE_ADD_EXTERN_TYPE(p->colType, TSDB_DATA_TYPE_JSON);
|
||||
}
|
||||
// handle put
|
||||
return indexPut(index, terms, uid);
|
||||
|
@ -48,7 +48,7 @@ int indexJsonSearch(SIndexJson *index, SIndexJsonMultiTermQuery *tq, SArray *res
|
|||
} else {
|
||||
p->colType = TSDB_DATA_TYPE_DOUBLE;
|
||||
}
|
||||
INDEX_TYPE_ADD_EXTERN_TYPE(p->colType, TSDB_DATA_TYPE_JSON);
|
||||
IDX_TYPE_ADD_EXTERN_TYPE(p->colType, TSDB_DATA_TYPE_JSON);
|
||||
}
|
||||
// handle search
|
||||
return indexSearch(index, tq, result);
|
||||
|
|
|
@ -118,7 +118,7 @@ TFileCache* tfileCacheCreate(const char* path) {
|
|||
ICacheKey key = {.suid = header->suid, .colName = header->colName, .nColName = (int32_t)strlen(header->colName)};
|
||||
|
||||
char buf[128] = {0};
|
||||
int32_t sz = indexSerialCacheKey(&key, buf);
|
||||
int32_t sz = idxSerialCacheKey(&key, buf);
|
||||
assert(sz < sizeof(buf));
|
||||
taosHashPut(tcache->tableCache, buf, sz, &reader, sizeof(void*));
|
||||
tfileReaderRef(reader);
|
||||
|
@ -149,7 +149,7 @@ void tfileCacheDestroy(TFileCache* tcache) {
|
|||
|
||||
TFileReader* tfileCacheGet(TFileCache* tcache, ICacheKey* key) {
|
||||
char buf[128] = {0};
|
||||
int32_t sz = indexSerialCacheKey(key, buf);
|
||||
int32_t sz = idxSerialCacheKey(key, buf);
|
||||
assert(sz < sizeof(buf));
|
||||
TFileReader** reader = taosHashGet(tcache->tableCache, buf, sz);
|
||||
if (reader == NULL || *reader == NULL) {
|
||||
|
@ -161,7 +161,7 @@ TFileReader* tfileCacheGet(TFileCache* tcache, ICacheKey* key) {
|
|||
}
|
||||
void tfileCachePut(TFileCache* tcache, ICacheKey* key, TFileReader* reader) {
|
||||
char buf[128] = {0};
|
||||
int32_t sz = indexSerialCacheKey(key, buf);
|
||||
int32_t sz = idxSerialCacheKey(key, buf);
|
||||
// remove last version index reader
|
||||
TFileReader** p = taosHashGet(tcache->tableCache, buf, sz);
|
||||
if (p != NULL && *p != NULL) {
|
||||
|
@ -281,7 +281,7 @@ static int32_t tfSearchSuffix(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
|
|||
return 0;
|
||||
}
|
||||
static int32_t tfSearchRegex(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
|
||||
bool hasJson = INDEX_TYPE_CONTAIN_EXTERN_TYPE(tem->colType, TSDB_DATA_TYPE_JSON);
|
||||
bool hasJson = IDX_TYPE_CONTAIN_EXTERN_TYPE(tem->colType, TSDB_DATA_TYPE_JSON);
|
||||
|
||||
int ret = 0;
|
||||
char* p = tem->colVal;
|
||||
|
@ -305,7 +305,7 @@ static int32_t tfSearchCompareFunc(void* reader, SIndexTerm* tem, SIdxTRslt* tr,
|
|||
int ret = 0;
|
||||
char* p = tem->colVal;
|
||||
int skip = 0;
|
||||
_cache_range_compare cmpFn = indexGetCompare(type);
|
||||
_cache_range_compare cmpFn = idxGetCompare(type);
|
||||
|
||||
SArray* offsets = taosArrayInit(16, sizeof(uint64_t));
|
||||
|
||||
|
@ -431,7 +431,7 @@ static int32_t tfSearchCompareFunc_JSON(void* reader, SIndexTerm* tem, SIdxTRslt
|
|||
p = idxPackJsonDataPrefix(tem, &skip);
|
||||
}
|
||||
|
||||
_cache_range_compare cmpFn = indexGetCompare(ctype);
|
||||
_cache_range_compare cmpFn = idxGetCompare(ctype);
|
||||
|
||||
SArray* offsets = taosArrayInit(16, sizeof(uint64_t));
|
||||
|
||||
|
@ -457,7 +457,7 @@ static int32_t tfSearchCompareFunc_JSON(void* reader, SIndexTerm* tem, SIdxTRslt
|
|||
} else if (0 != strncmp(ch, p, skip)) {
|
||||
continue;
|
||||
}
|
||||
cond = cmpFn(ch + skip, tem->colVal, INDEX_TYPE_GET_TYPE(tem->colType));
|
||||
cond = cmpFn(ch + skip, tem->colVal, IDX_TYPE_GET_TYPE(tem->colType));
|
||||
}
|
||||
if (MATCH == cond) {
|
||||
tfileReaderLoadTableIds((TFileReader*)reader, rt->out.out, tr->total);
|
||||
|
@ -476,7 +476,7 @@ int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SIdxTRslt* tr
|
|||
SIndexTerm* term = query->term;
|
||||
EIndexQueryType qtype = query->qType;
|
||||
int ret = 0;
|
||||
if (INDEX_TYPE_CONTAIN_EXTERN_TYPE(term->colType, TSDB_DATA_TYPE_JSON)) {
|
||||
if (IDX_TYPE_CONTAIN_EXTERN_TYPE(term->colType, TSDB_DATA_TYPE_JSON)) {
|
||||
ret = tfSearch[1][qtype](reader, term, tr);
|
||||
} else {
|
||||
ret = tfSearch[0][qtype](reader, term, tr);
|
||||
|
@ -536,7 +536,7 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) {
|
|||
__compar_fn_t fn;
|
||||
|
||||
int8_t colType = tw->header.colType;
|
||||
colType = INDEX_TYPE_GET_TYPE(colType);
|
||||
colType = IDX_TYPE_GET_TYPE(colType);
|
||||
if (colType == TSDB_DATA_TYPE_BINARY || colType == TSDB_DATA_TYPE_NCHAR) {
|
||||
fn = tfileStrCompare;
|
||||
} else {
|
||||
|
@ -620,7 +620,7 @@ void tfileWriterDestroy(TFileWriter* tw) {
|
|||
taosMemoryFree(tw);
|
||||
}
|
||||
|
||||
IndexTFile* indexTFileCreate(const char* path) {
|
||||
IndexTFile* idxTFileCreate(const char* path) {
|
||||
TFileCache* cache = tfileCacheCreate(path);
|
||||
if (cache == NULL) {
|
||||
return NULL;
|
||||
|
@ -635,7 +635,7 @@ IndexTFile* indexTFileCreate(const char* path) {
|
|||
tfile->cache = cache;
|
||||
return tfile;
|
||||
}
|
||||
void indexTFileDestroy(IndexTFile* tfile) {
|
||||
void idxTFileDestroy(IndexTFile* tfile) {
|
||||
if (tfile == NULL) {
|
||||
return;
|
||||
}
|
||||
|
@ -644,7 +644,7 @@ void indexTFileDestroy(IndexTFile* tfile) {
|
|||
taosMemoryFree(tfile);
|
||||
}
|
||||
|
||||
int indexTFileSearch(void* tfile, SIndexTermQuery* query, SIdxTRslt* result) {
|
||||
int idxTFileSearch(void* tfile, SIndexTermQuery* query, SIdxTRslt* result) {
|
||||
int ret = -1;
|
||||
if (tfile == NULL) {
|
||||
return ret;
|
||||
|
@ -667,7 +667,7 @@ int indexTFileSearch(void* tfile, SIndexTermQuery* query, SIdxTRslt* result) {
|
|||
|
||||
return tfileReaderSearch(reader, query, result);
|
||||
}
|
||||
int indexTFilePut(void* tfile, SIndexTerm* term, uint64_t uid) {
|
||||
int idxTFilePut(void* tfile, SIndexTerm* term, uint64_t uid) {
|
||||
// TFileWriterOpt wOpt = {.suid = term->suid, .colType = term->colType, .colName = term->colName, .nColName =
|
||||
// term->nColName, .version = 1};
|
||||
|
||||
|
@ -845,7 +845,7 @@ static int tfileWriteData(TFileWriter* write, TFileValue* tval) {
|
|||
TFileHeader* header = &write->header;
|
||||
uint8_t colType = header->colType;
|
||||
|
||||
colType = INDEX_TYPE_GET_TYPE(colType);
|
||||
colType = IDX_TYPE_GET_TYPE(colType);
|
||||
FstSlice key = fstSliceCreate((uint8_t*)(tval->colVal), (size_t)strlen(tval->colVal));
|
||||
if (fstBuilderInsert(write->fb, key, tval->offset)) {
|
||||
fstSliceDestroy(&key);
|
||||
|
|
|
@ -521,10 +521,10 @@ class CacheObj {
|
|||
public:
|
||||
CacheObj() {
|
||||
// TODO
|
||||
cache = indexCacheCreate(NULL, 0, "voltage", TSDB_DATA_TYPE_BINARY);
|
||||
cache = idxCacheCreate(NULL, 0, "voltage", TSDB_DATA_TYPE_BINARY);
|
||||
}
|
||||
int Put(SIndexTerm* term, int16_t colId, int32_t version, uint64_t uid) {
|
||||
int ret = indexCachePut(cache, term, uid);
|
||||
int ret = idxCachePut(cache, term, uid);
|
||||
if (ret != 0) {
|
||||
//
|
||||
std::cout << "failed to put into cache: " << ret << std::endl;
|
||||
|
@ -533,12 +533,12 @@ class CacheObj {
|
|||
}
|
||||
void Debug() {
|
||||
//
|
||||
indexCacheDebug(cache);
|
||||
idxCacheDebug(cache);
|
||||
}
|
||||
int Get(SIndexTermQuery* query, int16_t colId, int32_t version, SArray* result, STermValueType* s) {
|
||||
SIdxTRslt* tr = idxTRsltCreate();
|
||||
|
||||
int ret = indexCacheSearch(cache, query, tr, s);
|
||||
int ret = idxCacheSearch(cache, query, tr, s);
|
||||
idxTRsltMergeTo(tr, result);
|
||||
idxTRsltDestroy(tr);
|
||||
|
||||
|
@ -549,7 +549,7 @@ class CacheObj {
|
|||
}
|
||||
~CacheObj() {
|
||||
// TODO
|
||||
indexCacheDestroy(cache);
|
||||
idxCacheDestroy(cache);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -678,6 +678,7 @@ static int32_t jsonToLogicExchangeNode(const SJson* pJson, void* pObj) {
|
|||
}
|
||||
|
||||
static const char* jkMergeLogicPlanMergeKeys = "MergeKeys";
|
||||
static const char* jkMergeLogicPlanInputs = "Inputs";
|
||||
static const char* jkMergeLogicPlanNumOfChannels = "NumOfChannels";
|
||||
static const char* jkMergeLogicPlanSrcGroupId = "SrcGroupId";
|
||||
|
||||
|
@ -688,6 +689,9 @@ static int32_t logicMergeNodeToJson(const void* pObj, SJson* pJson) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodeListToJson(pJson, jkMergeLogicPlanMergeKeys, pNode->pMergeKeys);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodeListToJson(pJson, jkMergeLogicPlanInputs, pNode->pInputs);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkMergeLogicPlanNumOfChannels, pNode->numOfChannels);
|
||||
}
|
||||
|
@ -705,6 +709,9 @@ static int32_t jsonToLogicMergeNode(const SJson* pJson, void* pObj) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkMergeLogicPlanMergeKeys, &pNode->pMergeKeys);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkMergeLogicPlanInputs, &pNode->pInputs);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetIntValue(pJson, jkMergeLogicPlanNumOfChannels, &pNode->numOfChannels);
|
||||
}
|
||||
|
|
|
@ -472,7 +472,7 @@ cmd ::= KILL TRANSACTION NK_INTEGER(A).
|
|||
cmd ::= BALANCE VGROUP. { pCxt->pRootNode = createBalanceVgroupStmt(pCxt); }
|
||||
cmd ::= MERGE VGROUP NK_INTEGER(A) NK_INTEGER(B). { pCxt->pRootNode = createMergeVgroupStmt(pCxt, &A, &B); }
|
||||
cmd ::= REDISTRIBUTE VGROUP NK_INTEGER(A) dnode_list(B). { pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &A, B); }
|
||||
//cmd ::= SPLIT VGROUP NK_INTEGER(A). { pCxt->pRootNode = createSplitVgroupStmt(pCxt, &A); }
|
||||
cmd ::= SPLIT VGROUP NK_INTEGER(A). { pCxt->pRootNode = createSplitVgroupStmt(pCxt, &A); }
|
||||
|
||||
%type dnode_list { SNodeList* }
|
||||
%destructor dnode_list { nodesDestroyList($$); }
|
||||
|
|
|
@ -248,6 +248,9 @@ static int32_t collectMetaKeyFromCreateIndex(SCollectMetaKeyCxt* pCxt, SCreateIn
|
|||
code =
|
||||
reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->db, pStmt->tableName, pCxt->pMetaCache);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->db, pCxt->pMetaCache);
|
||||
}
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -174,7 +174,7 @@ static SKeyword keywordTable[] = {
|
|||
{"SNODE", TK_SNODE},
|
||||
{"SNODES", TK_SNODES},
|
||||
{"SOFFSET", TK_SOFFSET},
|
||||
// {"SPLIT", TK_SPLIT},
|
||||
{"SPLIT", TK_SPLIT},
|
||||
{"STABLE", TK_STABLE},
|
||||
{"STABLES", TK_STABLES},
|
||||
{"STATE", TK_STATE},
|
||||
|
|
|
@ -824,9 +824,9 @@ static EDealRes translateComparisonOperator(STranslateContext* pCxt, SOperatorNo
|
|||
}
|
||||
if (OP_TYPE_IN == pOp->opType || OP_TYPE_NOT_IN == pOp->opType) {
|
||||
SNodeListNode* pRight = (SNodeListNode*)pOp->pRight;
|
||||
bool first = true;
|
||||
SDataType targetDt = {0};
|
||||
SNode* pNode = NULL;
|
||||
bool first = true;
|
||||
SDataType targetDt = {0};
|
||||
SNode* pNode = NULL;
|
||||
FOREACH(pNode, pRight->pNodeList) {
|
||||
SDataType dt = ((SExprNode*)pNode)->resType;
|
||||
if (first) {
|
||||
|
@ -3672,6 +3672,11 @@ static int32_t translateRedistributeVgroup(STranslateContext* pCxt, SRedistribut
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t translateSplitVgroup(STranslateContext* pCxt, SSplitVgroupStmt* pStmt) {
|
||||
SSplitVgroupReq req = {.vgId = pStmt->vgId};
|
||||
return buildCmdMsg(pCxt, TDMT_MND_SPLIT_VGROUP, (FSerializeFunc)tSerializeSSplitVgroupReq, &req);
|
||||
}
|
||||
|
||||
static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
switch (nodeType(pNode)) {
|
||||
|
@ -3803,6 +3808,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
|||
case QUERY_NODE_REDISTRIBUTE_VGROUP_STMT:
|
||||
code = translateRedistributeVgroup(pCxt, (SRedistributeVgroupStmt*)pNode);
|
||||
break;
|
||||
case QUERY_NODE_SPLIT_VGROUP_STMT:
|
||||
code = translateSplitVgroup(pCxt, (SSplitVgroupStmt*)pNode);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -267,10 +267,12 @@ TEST_F(ParserInitialCTest, createFunction) {
|
|||
// run("CREATE AGGREGATE FUNCTION IF NOT EXISTS udf2 AS './build/lib/libudf2.so' OUTPUTTYPE DOUBLE BUFSIZE 8");
|
||||
}
|
||||
|
||||
TEST_F(ParserInitialCTest, createIndexSma) {
|
||||
TEST_F(ParserInitialCTest, createSmaIndex) {
|
||||
useDb("root", "test");
|
||||
|
||||
run("CREATE SMA INDEX index1 ON t1 FUNCTION(MAX(c1), MIN(c3 + 10), SUM(c4)) INTERVAL(10s)");
|
||||
|
||||
run("CREATE SMA INDEX index2 ON st1 FUNCTION(MAX(c1), MIN(tag1)) INTERVAL(10s)");
|
||||
}
|
||||
|
||||
TEST_F(ParserInitialCTest, createMnode) {
|
||||
|
|
|
@ -19,7 +19,7 @@ using namespace std;
|
|||
|
||||
namespace ParserTest {
|
||||
|
||||
class ParserShowToUseTest : public ParserTestBase {};
|
||||
class ParserShowToUseTest : public ParserDdlTest {};
|
||||
|
||||
// todo SHOW accounts
|
||||
// todo SHOW apps
|
||||
|
@ -133,7 +133,24 @@ TEST_F(ParserShowToUseTest, showVgroups) {
|
|||
|
||||
// todo SHOW vnodes
|
||||
|
||||
// todo split vgroup
|
||||
TEST_F(ParserShowToUseTest, splitVgroup) {
|
||||
useDb("root", "test");
|
||||
|
||||
SSplitVgroupReq expect = {0};
|
||||
|
||||
auto setSplitVgroupReqFunc = [&](int32_t vgId) { expect.vgId = vgId; };
|
||||
|
||||
setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
|
||||
ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_SPLIT_VGROUP_STMT);
|
||||
ASSERT_EQ(pQuery->pCmdMsg->msgType, TDMT_MND_SPLIT_VGROUP);
|
||||
SSplitVgroupReq req = {0};
|
||||
ASSERT_EQ(tDeserializeSSplitVgroupReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req), TSDB_CODE_SUCCESS);
|
||||
ASSERT_EQ(req.vgId, expect.vgId);
|
||||
});
|
||||
|
||||
setSplitVgroupReqFunc(15);
|
||||
run("SPLIT VGROUP 15");
|
||||
}
|
||||
|
||||
TEST_F(ParserShowToUseTest, useDatabase) {
|
||||
useDb("root", "test");
|
||||
|
|
|
@ -135,7 +135,8 @@ typedef struct SStableSplitInfo {
|
|||
static bool stbSplHasGatherExecFunc(const SNodeList* pFuncs) {
|
||||
SNode* pFunc = NULL;
|
||||
FOREACH(pFunc, pFuncs) {
|
||||
if (!fmIsDistExecFunc(((SFunctionNode*)pFunc)->funcId)) {
|
||||
if (!fmIsWindowPseudoColumnFunc(((SFunctionNode*)pFunc)->funcId) &&
|
||||
!fmIsDistExecFunc(((SFunctionNode*)pFunc)->funcId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -314,7 +315,12 @@ static int32_t stbSplCreateMergeNode(SSplitContext* pCxt, SLogicSubplan* pSubpla
|
|||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
pMerge->pInputs = nodesCloneList(pPartChild->pTargets);
|
||||
pMerge->node.pTargets = nodesCloneList(pSplitNode->pTargets);
|
||||
// NULL == pSubplan means 'merge node' replaces 'split node'.
|
||||
if (NULL == pSubplan) {
|
||||
pMerge->node.pTargets = nodesCloneList(pPartChild->pTargets);
|
||||
} else {
|
||||
pMerge->node.pTargets = nodesCloneList(pSplitNode->pTargets);
|
||||
}
|
||||
if (NULL == pMerge->node.pTargets || NULL == pMerge->pInputs) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -340,6 +346,21 @@ static int32_t stbSplCreateExchangeNode(SSplitContext* pCxt, SLogicNode* pParent
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t stbSplCreateMergeKeysForInterval(SNode* pWStartTs, SNodeList** pMergeKeys) {
|
||||
SOrderByExprNode* pMergeKey = nodesMakeNode(QUERY_NODE_ORDER_BY_EXPR);
|
||||
if (NULL == pMergeKey) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pMergeKey->pExpr = nodesCloneNode(pWStartTs);
|
||||
if (NULL == pMergeKey->pExpr) {
|
||||
nodesDestroyNode(pMergeKey);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pMergeKey->order = ORDER_ASC;
|
||||
pMergeKey->nullOrder = NULL_ORDER_FIRST;
|
||||
return nodesListMakeStrictAppend(pMergeKeys, pMergeKey);
|
||||
}
|
||||
|
||||
static int32_t stbSplSplitIntervalForBatch(SSplitContext* pCxt, SStableSplitInfo* pInfo) {
|
||||
SLogicNode* pPartWindow = NULL;
|
||||
int32_t code = stbSplCreatePartWindowNode((SWindowLogicNode*)pInfo->pSplitNode, &pPartWindow);
|
||||
|
@ -347,7 +368,7 @@ static int32_t stbSplSplitIntervalForBatch(SSplitContext* pCxt, SStableSplitInfo
|
|||
((SWindowLogicNode*)pPartWindow)->intervalAlgo = INTERVAL_ALGO_HASH;
|
||||
((SWindowLogicNode*)pInfo->pSplitNode)->intervalAlgo = INTERVAL_ALGO_MERGE;
|
||||
SNodeList* pMergeKeys = NULL;
|
||||
code = nodesListMakeStrictAppend(&pMergeKeys, nodesCloneNode(((SWindowLogicNode*)pInfo->pSplitNode)->pTspk));
|
||||
code = stbSplCreateMergeKeysForInterval(((SWindowLogicNode*)pInfo->pSplitNode)->pTspk, &pMergeKeys);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = stbSplCreateMergeNode(pCxt, NULL, pInfo->pSplitNode, pMergeKeys, pPartWindow);
|
||||
}
|
||||
|
|
|
@ -58,4 +58,6 @@ TEST_F(PlanIntervalTest, stable) {
|
|||
useDb("root", "test");
|
||||
|
||||
run("SELECT COUNT(*) FROM st1 INTERVAL(10s)");
|
||||
|
||||
run("SELECT _WSTARTTS, COUNT(*) FROM st1 INTERVAL(10s)");
|
||||
}
|
||||
|
|
|
@ -38,5 +38,5 @@ TEST_F(PlanSuperTableTest, pseudoColOnChildTable) {
|
|||
TEST_F(PlanSuperTableTest, orderBy) {
|
||||
useDb("root", "test");
|
||||
|
||||
run("SELECT -1*c1, c1 FROM st1 ORDER BY -1*c1");
|
||||
run("SELECT -1 * c1, c1 FROM st1 ORDER BY -1 * c1");
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@ int32_t streamDispatchReqToData(const SStreamDispatchReq* pReq, SStreamDataBlock
|
|||
SSDataBlock* pDataBlock = taosArrayGet(pArray, i);
|
||||
blockCompressDecode(pDataBlock, htonl(pRetrieve->numOfCols), htonl(pRetrieve->numOfRows), pRetrieve->data);
|
||||
// TODO: refactor
|
||||
pDataBlock->info.type = pRetrieve->streamBlockType;
|
||||
pDataBlock->info.childId = pReq->sourceChildId;
|
||||
}
|
||||
pData->blocks = pArray;
|
||||
|
|
|
@ -72,6 +72,7 @@ static int32_t streamAddBlockToDispatchMsg(const SSDataBlock* pBlock, SStreamDis
|
|||
pRetrieve->precision = TSDB_DEFAULT_PRECISION;
|
||||
pRetrieve->compressed = 0;
|
||||
pRetrieve->completed = 1;
|
||||
pRetrieve->streamBlockType = pBlock->info.type;
|
||||
pRetrieve->numOfRows = htonl(pBlock->info.rows);
|
||||
pRetrieve->numOfCols = htonl(pBlock->info.numOfCols);
|
||||
|
||||
|
@ -99,6 +100,7 @@ int32_t streamBuildDispatchMsg(SStreamTask* pTask, SStreamDataBlock* data, SRpcM
|
|||
.upstreamNodeId = pTask->nodeId,
|
||||
.blockNum = blockNum,
|
||||
};
|
||||
qInfo("dispatch from task %d (child id %d)", pTask->taskId, pTask->childId);
|
||||
|
||||
req.data = taosArrayInit(blockNum, sizeof(void*));
|
||||
req.dataLen = taosArrayInit(blockNum, sizeof(int32_t));
|
||||
|
|
|
@ -16,14 +16,13 @@
|
|||
#include "executor.h"
|
||||
#include "tstream.h"
|
||||
|
||||
SStreamTask* tNewSStreamTask(int64_t streamId, int32_t childId) {
|
||||
SStreamTask* tNewSStreamTask(int64_t streamId) {
|
||||
SStreamTask* pTask = (SStreamTask*)taosMemoryCalloc(1, sizeof(SStreamTask));
|
||||
if (pTask == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
pTask->taskId = tGenIdPI32();
|
||||
pTask->streamId = streamId;
|
||||
pTask->childId = childId;
|
||||
pTask->status = TASK_STATUS__IDLE;
|
||||
pTask->inputStatus = TASK_INPUT_STATUS__NORMAL;
|
||||
pTask->outputStatus = TASK_OUTPUT_STATUS__NORMAL;
|
||||
|
@ -48,7 +47,6 @@ int32_t tEncodeSStreamTask(SEncoder* pEncoder, const SStreamTask* pTask) {
|
|||
if (tEncodeSEpSet(pEncoder, &pTask->epSet) < 0) return -1;
|
||||
|
||||
if (pTask->execType != TASK_EXEC__NONE) {
|
||||
if (tEncodeI8(pEncoder, pTask->exec.parallelizable) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, pTask->exec.qmsg) < 0) return -1;
|
||||
}
|
||||
|
||||
|
@ -96,7 +94,6 @@ int32_t tDecodeSStreamTask(SDecoder* pDecoder, SStreamTask* pTask) {
|
|||
if (tDecodeSEpSet(pDecoder, &pTask->epSet) < 0) return -1;
|
||||
|
||||
if (pTask->execType != TASK_EXEC__NONE) {
|
||||
if (tDecodeI8(pDecoder, &pTask->exec.parallelizable) < 0) return -1;
|
||||
if (tDecodeCStrAlloc(pDecoder, &pTask->exec.qmsg) < 0) return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -201,8 +201,8 @@ void syncNodeRelease(SSyncNode* pNode);
|
|||
|
||||
// raft state change --------------
|
||||
void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term);
|
||||
void syncNodeBecomeFollower(SSyncNode* pSyncNode);
|
||||
void syncNodeBecomeLeader(SSyncNode* pSyncNode);
|
||||
void syncNodeBecomeFollower(SSyncNode* pSyncNode, const char* debugStr);
|
||||
void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr);
|
||||
|
||||
void syncNodeCandidate2Leader(SSyncNode* pSyncNode);
|
||||
void syncNodeFollower2Candidate(SSyncNode* pSyncNode);
|
||||
|
|
|
@ -49,8 +49,8 @@ void raftStoreClearVote(SRaftStore *pRaftStore);
|
|||
void raftStoreNextTerm(SRaftStore *pRaftStore);
|
||||
void raftStoreSetTerm(SRaftStore *pRaftStore, SyncTerm term);
|
||||
int32_t raftStoreFromJson(SRaftStore *pRaftStore, cJSON *pJson);
|
||||
cJSON *raftStore2Json(SRaftStore *pRaftStore);
|
||||
char *raftStore2Str(SRaftStore *pRaftStore);
|
||||
cJSON * raftStore2Json(SRaftStore *pRaftStore);
|
||||
char * raftStore2Str(SRaftStore *pRaftStore);
|
||||
|
||||
// for debug -------------------
|
||||
void raftStorePrint(SRaftStore *pObj);
|
||||
|
|
|
@ -39,8 +39,8 @@ typedef struct SSyncSnapshotSender {
|
|||
bool start;
|
||||
int32_t seq;
|
||||
int32_t ack;
|
||||
void *pReader;
|
||||
void *pCurrentBlock;
|
||||
void * pReader;
|
||||
void * pCurrentBlock;
|
||||
int32_t blockLen;
|
||||
SSnapshot snapshot;
|
||||
int64_t sendingMS;
|
||||
|
@ -58,28 +58,29 @@ void snapshotSenderStart(SSyncSnapshotSender *pSender);
|
|||
void snapshotSenderStop(SSyncSnapshotSender *pSender);
|
||||
int32_t snapshotSend(SSyncSnapshotSender *pSender);
|
||||
int32_t snapshotReSend(SSyncSnapshotSender *pSender);
|
||||
cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender);
|
||||
char *snapshotSender2Str(SSyncSnapshotSender *pSender);
|
||||
cJSON * snapshotSender2Json(SSyncSnapshotSender *pSender);
|
||||
char * snapshotSender2Str(SSyncSnapshotSender *pSender);
|
||||
|
||||
typedef struct SSyncSnapshotReceiver {
|
||||
bool start;
|
||||
|
||||
int32_t ack;
|
||||
void *pWriter;
|
||||
void * pWriter;
|
||||
SyncTerm term;
|
||||
SyncTerm privateTerm;
|
||||
|
||||
SSyncNode *pSyncNode;
|
||||
int32_t replicaIndex;
|
||||
SRaftId fromId;
|
||||
|
||||
} SSyncSnapshotReceiver;
|
||||
|
||||
SSyncSnapshotReceiver *snapshotReceiverCreate(SSyncNode *pSyncNode, int32_t replicaIndex);
|
||||
SSyncSnapshotReceiver *snapshotReceiverCreate(SSyncNode *pSyncNode, SRaftId fromId);
|
||||
void snapshotReceiverDestroy(SSyncSnapshotReceiver *pReceiver);
|
||||
void snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncTerm privateTerm);
|
||||
void snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncTerm privateTerm, SRaftId fromId);
|
||||
bool snapshotReceiverIsStart(SSyncSnapshotReceiver *pReceiver);
|
||||
void snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver, bool apply);
|
||||
cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver);
|
||||
char *snapshotReceiver2Str(SSyncSnapshotReceiver *pReceiver);
|
||||
cJSON * snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver);
|
||||
char * snapshotReceiver2Str(SSyncSnapshotReceiver *pReceiver);
|
||||
|
||||
int32_t syncNodeOnSnapshotSendCb(SSyncNode *ths, SyncSnapshotSend *pMsg);
|
||||
int32_t syncNodeOnSnapshotRspCb(SSyncNode *ths, SyncSnapshotRsp *pMsg);
|
||||
|
|
|
@ -150,7 +150,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
|||
"ths->state:%d, logOK:%d",
|
||||
pMsg->term, ths->pRaftStore->currentTerm, ths->state, logOK);
|
||||
|
||||
syncNodeBecomeFollower(ths);
|
||||
syncNodeBecomeFollower(ths, "from candidate by append entries");
|
||||
|
||||
// ret or reply?
|
||||
return ret;
|
||||
|
@ -380,17 +380,19 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
|||
// change isStandBy to normal
|
||||
if (!isDrop) {
|
||||
if (ths->state == TAOS_SYNC_STATE_LEADER) {
|
||||
syncNodeBecomeLeader(ths);
|
||||
syncNodeBecomeLeader(ths, "config change");
|
||||
} else {
|
||||
syncNodeBecomeFollower(ths);
|
||||
syncNodeBecomeFollower(ths, "config change");
|
||||
}
|
||||
}
|
||||
|
||||
char* sOld = syncCfg2Str(&oldSyncCfg);
|
||||
char* sNew = syncCfg2Str(&newSyncCfg);
|
||||
sInfo("==config change== 0x11 old:%s new:%s isDrop:%d \n", sOld, sNew, isDrop);
|
||||
taosMemoryFree(sOld);
|
||||
taosMemoryFree(sNew);
|
||||
if (gRaftDetailLog) {
|
||||
char* sOld = syncCfg2Str(&oldSyncCfg);
|
||||
char* sNew = syncCfg2Str(&newSyncCfg);
|
||||
sInfo("==config change== 0x11 old:%s new:%s isDrop:%d \n", sOld, sNew, isDrop);
|
||||
taosMemoryFree(sOld);
|
||||
taosMemoryFree(sNew);
|
||||
}
|
||||
}
|
||||
|
||||
// always call FpReConfigCb
|
||||
|
@ -399,10 +401,12 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
|||
cbMeta.currentTerm = ths->pRaftStore->currentTerm;
|
||||
cbMeta.index = pEntry->index;
|
||||
cbMeta.term = pEntry->term;
|
||||
cbMeta.newCfg = newSyncCfg;
|
||||
cbMeta.oldCfg = oldSyncCfg;
|
||||
cbMeta.seqNum = pEntry->seqNum;
|
||||
cbMeta.flag = 0x11;
|
||||
cbMeta.isDrop = isDrop;
|
||||
ths->pFsm->FpReConfigCb(ths->pFsm, newSyncCfg, cbMeta);
|
||||
ths->pFsm->FpReConfigCb(ths->pFsm, &rpcMsg, cbMeta);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -469,7 +473,7 @@ static int32_t syncNodeMakeLogSame(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
|||
// delete confict entries
|
||||
code = ths->pLogStore->syncLogTruncate(ths->pLogStore, delBegin);
|
||||
ASSERT(code == 0);
|
||||
sInfo("sync event log truncate, from %ld to %ld", delBegin, delEnd);
|
||||
sInfo("sync event vgId:%d log truncate, from %ld to %ld", ths->vgId, delBegin, delEnd);
|
||||
logStoreSimpleLog2("after syncNodeMakeLogSame", ths->pLogStore);
|
||||
|
||||
return code;
|
||||
|
@ -571,7 +575,7 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
|
|||
if (condition) {
|
||||
sTrace("recv SyncAppendEntries, candidate to follower");
|
||||
|
||||
syncNodeBecomeFollower(ths);
|
||||
syncNodeBecomeFollower(ths, "from candidate by append entries");
|
||||
// do not reply?
|
||||
return ret;
|
||||
}
|
||||
|
@ -742,6 +746,18 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
|
|||
if (pMsg->commitIndex > ths->commitIndex) {
|
||||
// has commit entry in local
|
||||
if (pMsg->commitIndex <= ths->pLogStore->syncLogLastIndex(ths->pLogStore)) {
|
||||
// advance commit index to sanpshot first
|
||||
SSnapshot snapshot;
|
||||
ths->pFsm->FpGetSnapshot(ths->pFsm, &snapshot);
|
||||
if (snapshot.lastApplyIndex >= 0 && snapshot.lastApplyIndex > ths->commitIndex) {
|
||||
SyncIndex commitBegin = ths->commitIndex;
|
||||
SyncIndex commitEnd = snapshot.lastApplyIndex;
|
||||
ths->commitIndex = snapshot.lastApplyIndex;
|
||||
|
||||
sInfo("sync event vgId:%d commit by snapshot from index:%ld to index:%ld, %s", ths->vgId, commitBegin,
|
||||
commitEnd, syncUtilState2String(ths->state));
|
||||
}
|
||||
|
||||
SyncIndex beginIndex = ths->commitIndex + 1;
|
||||
SyncIndex endIndex = pMsg->commitIndex;
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries
|
|||
|
||||
syncIndexMgrLog2("recv SyncAppendEntriesReply, before pNextIndex:", ths->pNextIndex);
|
||||
syncIndexMgrLog2("recv SyncAppendEntriesReply, before pMatchIndex:", ths->pMatchIndex);
|
||||
{
|
||||
if (gRaftDetailLog) {
|
||||
SSnapshot snapshot;
|
||||
ths->pFsm->FpGetSnapshot(ths->pFsm, &snapshot);
|
||||
sTrace("recv SyncAppendEntriesReply, before snapshot.lastApplyIndex:%ld, snapshot.lastApplyTerm:%lu",
|
||||
|
@ -147,7 +147,10 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries
|
|||
if (pMsg->success) {
|
||||
// nextIndex' = [nextIndex EXCEPT ![i][j] = m.mmatchIndex + 1]
|
||||
syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), pMsg->matchIndex + 1);
|
||||
sTrace("update next match, index:%ld, success:%d", pMsg->matchIndex + 1, pMsg->success);
|
||||
|
||||
if (gRaftDetailLog) {
|
||||
sTrace("update next match, index:%ld, success:%d", pMsg->matchIndex + 1, pMsg->success);
|
||||
}
|
||||
|
||||
// matchIndex' = [matchIndex EXCEPT ![i][j] = m.mmatchIndex]
|
||||
syncIndexMgrSetIndex(ths->pMatchIndex, &(pMsg->srcId), pMsg->matchIndex);
|
||||
|
@ -159,7 +162,9 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries
|
|||
|
||||
} else {
|
||||
SyncIndex nextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId));
|
||||
sTrace("update next not match, begin, index:%ld, success:%d", nextIndex, pMsg->success);
|
||||
if (gRaftDetailLog) {
|
||||
sTrace("update next index not match, begin, index:%ld, success:%d", nextIndex, pMsg->success);
|
||||
}
|
||||
|
||||
// notice! int64, uint64
|
||||
if (nextIndex > SYNC_INDEX_BEGIN) {
|
||||
|
@ -178,9 +183,23 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries
|
|||
pMsg->privateTerm < pSender->privateTerm) {
|
||||
snapshotSenderStart(pSender);
|
||||
|
||||
char* s = snapshotSender2Str(pSender);
|
||||
sInfo("sync event snapshot send start sender first time, sender:%s", s);
|
||||
taosMemoryFree(s);
|
||||
char host[128];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pSender->pSyncNode->replicasId[pSender->replicaIndex].addr, host, sizeof(host), &port);
|
||||
|
||||
if (gRaftDetailLog) {
|
||||
char* s = snapshotSender2Str(pSender);
|
||||
sInfo(
|
||||
"sync event vgId:%d snapshot send to %s:%d start sender first time, lastApplyIndex:%ld lastApplyTerm:%lu "
|
||||
"sender:%s",
|
||||
ths->vgId, host, port, pSender->snapshot.lastApplyIndex, pSender->snapshot.lastApplyTerm, s);
|
||||
taosMemoryFree(s);
|
||||
} else {
|
||||
sInfo(
|
||||
"sync event vgId:%d snapshot send to %s:%d start sender first time, lastApplyIndex:%ld "
|
||||
"lastApplyTerm:%lu",
|
||||
ths->vgId, host, port, pSender->snapshot.lastApplyIndex, pSender->snapshot.lastApplyTerm);
|
||||
}
|
||||
}
|
||||
|
||||
SyncIndex sentryIndex = pSender->snapshot.lastApplyIndex + 1;
|
||||
|
@ -195,12 +214,14 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries
|
|||
}
|
||||
|
||||
syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), nextIndex);
|
||||
sTrace("update next not match, end, index:%ld, success:%d", nextIndex, pMsg->success);
|
||||
if (gRaftDetailLog) {
|
||||
sTrace("update next index not match, end, index:%ld, success:%d", nextIndex, pMsg->success);
|
||||
}
|
||||
}
|
||||
|
||||
syncIndexMgrLog2("recv SyncAppendEntriesReply, after pNextIndex:", ths->pNextIndex);
|
||||
syncIndexMgrLog2("recv SyncAppendEntriesReply, after pMatchIndex:", ths->pMatchIndex);
|
||||
{
|
||||
if (gRaftDetailLog) {
|
||||
SSnapshot snapshot;
|
||||
ths->pFsm->FpGetSnapshot(ths->pFsm, &snapshot);
|
||||
sTrace("recv SyncAppendEntriesReply, after snapshot.lastApplyIndex:%ld, snapshot.lastApplyTerm:%lu",
|
||||
|
|
|
@ -48,13 +48,28 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
|
|||
syncIndexMgrLog2("==syncNodeMaybeAdvanceCommitIndex== pNextIndex", pSyncNode->pNextIndex);
|
||||
syncIndexMgrLog2("==syncNodeMaybeAdvanceCommitIndex== pMatchIndex", pSyncNode->pMatchIndex);
|
||||
|
||||
// advance commit index to sanpshot first
|
||||
SSnapshot snapshot;
|
||||
pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot);
|
||||
if (snapshot.lastApplyIndex > 0 && snapshot.lastApplyIndex > pSyncNode->commitIndex) {
|
||||
SyncIndex commitBegin = pSyncNode->commitIndex;
|
||||
SyncIndex commitEnd = snapshot.lastApplyIndex;
|
||||
pSyncNode->commitIndex = snapshot.lastApplyIndex;
|
||||
|
||||
sInfo("sync event vgId:%d commit by snapshot from index:%ld to index:%ld, %s", pSyncNode->vgId,
|
||||
pSyncNode->commitIndex, snapshot.lastApplyIndex, syncUtilState2String(pSyncNode->state));
|
||||
}
|
||||
|
||||
// update commit index
|
||||
SyncIndex newCommitIndex = pSyncNode->commitIndex;
|
||||
for (SyncIndex index = pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore); index > pSyncNode->commitIndex;
|
||||
--index) {
|
||||
for (SyncIndex index = syncNodeGetLastIndex(pSyncNode); index > pSyncNode->commitIndex; --index) {
|
||||
bool agree = syncAgree(pSyncNode, index);
|
||||
sTrace("syncMaybeAdvanceCommitIndex syncAgree:%d, index:%ld, pSyncNode->commitIndex:%ld", agree, index,
|
||||
pSyncNode->commitIndex);
|
||||
|
||||
if (gRaftDetailLog) {
|
||||
sTrace("syncMaybeAdvanceCommitIndex syncAgree:%d, index:%ld, pSyncNode->commitIndex:%ld", agree, index,
|
||||
pSyncNode->commitIndex);
|
||||
}
|
||||
|
||||
if (agree) {
|
||||
// term
|
||||
SSyncRaftEntry* pEntry = pSyncNode->pLogStore->getEntry(pSyncNode->pLogStore, index);
|
||||
|
@ -64,16 +79,21 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
|
|||
if (pEntry->term == pSyncNode->pRaftStore->currentTerm) {
|
||||
// update commit index
|
||||
newCommitIndex = index;
|
||||
sTrace("syncMaybeAdvanceCommitIndex maybe to update, newCommitIndex:%ld commit, pSyncNode->commitIndex:%ld",
|
||||
newCommitIndex, pSyncNode->commitIndex);
|
||||
|
||||
if (gRaftDetailLog) {
|
||||
sTrace("syncMaybeAdvanceCommitIndex maybe to update, newCommitIndex:%ld commit, pSyncNode->commitIndex:%ld",
|
||||
newCommitIndex, pSyncNode->commitIndex);
|
||||
}
|
||||
|
||||
syncEntryDestory(pEntry);
|
||||
break;
|
||||
} else {
|
||||
sTrace(
|
||||
"syncMaybeAdvanceCommitIndex can not commit due to term not equal, pEntry->term:%lu, "
|
||||
"pSyncNode->pRaftStore->currentTerm:%lu",
|
||||
pEntry->term, pSyncNode->pRaftStore->currentTerm);
|
||||
if (gRaftDetailLog) {
|
||||
sTrace(
|
||||
"syncMaybeAdvanceCommitIndex can not commit due to term not equal, pEntry->term:%lu, "
|
||||
"pSyncNode->pRaftStore->currentTerm:%lu",
|
||||
pEntry->term, pSyncNode->pRaftStore->currentTerm);
|
||||
}
|
||||
}
|
||||
|
||||
syncEntryDestory(pEntry);
|
||||
|
@ -84,7 +104,9 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
|
|||
SyncIndex beginIndex = pSyncNode->commitIndex + 1;
|
||||
SyncIndex endIndex = newCommitIndex;
|
||||
|
||||
sTrace("syncMaybeAdvanceCommitIndex sync commit %ld", newCommitIndex);
|
||||
if (gRaftDetailLog) {
|
||||
sTrace("syncMaybeAdvanceCommitIndex sync commit %ld", newCommitIndex);
|
||||
}
|
||||
|
||||
// update commit index
|
||||
pSyncNode->commitIndex = newCommitIndex;
|
||||
|
|
|
@ -40,7 +40,7 @@ int32_t syncEnvStart() {
|
|||
// gSyncEnv = doSyncEnvStart(gSyncEnv);
|
||||
gSyncEnv = doSyncEnvStart();
|
||||
assert(gSyncEnv != NULL);
|
||||
sTrace("syncEnvStart ok!");
|
||||
sTrace("sync env start ok");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) {
|
|||
|
||||
char *syncIndexMgr2Str(SSyncIndexMgr *pSyncIndexMgr) {
|
||||
cJSON *pJson = syncIndexMgr2Json(pSyncIndexMgr);
|
||||
char *serialized = cJSON_Print(pJson);
|
||||
char * serialized = cJSON_Print(pJson);
|
||||
cJSON_Delete(pJson);
|
||||
return serialized;
|
||||
}
|
||||
|
|
|
@ -87,7 +87,9 @@ int64_t syncOpen(const SSyncInfo* pSyncInfo) {
|
|||
SSyncNode* pSyncNode = syncNodeOpen(pSyncInfo);
|
||||
assert(pSyncNode != NULL);
|
||||
|
||||
syncNodeLog2("syncNodeOpen open success", pSyncNode);
|
||||
if (gRaftDetailLog) {
|
||||
syncNodeLog2("syncNodeOpen open success", pSyncNode);
|
||||
}
|
||||
|
||||
pSyncNode->rid = taosAddRef(tsNodeRefId, pSyncNode);
|
||||
if (pSyncNode->rid < 0) {
|
||||
|
@ -173,20 +175,37 @@ int32_t syncSetStandby(int64_t rid) {
|
|||
|
||||
int32_t syncReconfig(int64_t rid, const SSyncCfg* pSyncCfg) {
|
||||
int32_t ret = 0;
|
||||
char* configChange = syncCfg2Str((SSyncCfg*)pSyncCfg);
|
||||
sInfo("==syncReconfig== newconfig:%s", configChange);
|
||||
char* newconfig = syncCfg2Str((SSyncCfg*)pSyncCfg);
|
||||
|
||||
if (gRaftDetailLog) {
|
||||
sInfo("==syncReconfig== newconfig:%s", newconfig);
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.msgType = TDMT_SYNC_CONFIG_CHANGE;
|
||||
rpcMsg.info.noResp = 1;
|
||||
rpcMsg.contLen = strlen(configChange) + 1;
|
||||
rpcMsg.contLen = strlen(newconfig) + 1;
|
||||
rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen);
|
||||
snprintf(rpcMsg.pCont, rpcMsg.contLen, "%s", configChange);
|
||||
taosMemoryFree(configChange);
|
||||
snprintf(rpcMsg.pCont, rpcMsg.contLen, "%s", newconfig);
|
||||
taosMemoryFree(newconfig);
|
||||
ret = syncPropose(rid, &rpcMsg, false);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t syncReconfigRaw(int64_t rid, const SSyncCfg* pNewCfg, SRpcMsg* pRpcMsg) {
|
||||
int32_t ret = 0;
|
||||
char* newconfig = syncCfg2Str((SSyncCfg*)pNewCfg);
|
||||
|
||||
pRpcMsg->msgType = TDMT_SYNC_CONFIG_CHANGE;
|
||||
pRpcMsg->info.noResp = 1;
|
||||
pRpcMsg->contLen = strlen(newconfig) + 1;
|
||||
pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
|
||||
snprintf(pRpcMsg->pCont, pRpcMsg->contLen, "%s", newconfig);
|
||||
taosMemoryFree(newconfig);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pMsg, bool isWeak) {
|
||||
int32_t ret = syncPropose(rid, pMsg, isWeak);
|
||||
return ret;
|
||||
|
@ -374,13 +393,14 @@ void setHeartbeatTimerMS(int64_t rid, int32_t hbTimerMS) {
|
|||
}
|
||||
|
||||
int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak) {
|
||||
sTrace("syncPropose msgType:%d ", pMsg->msgType);
|
||||
int32_t ret = TAOS_SYNC_PROPOSE_SUCCESS;
|
||||
|
||||
int32_t ret = TAOS_SYNC_PROPOSE_SUCCESS;
|
||||
SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid);
|
||||
if (pSyncNode == NULL) return TAOS_SYNC_PROPOSE_OTHER_ERROR;
|
||||
|
||||
if (pSyncNode == NULL) {
|
||||
return TAOS_SYNC_PROPOSE_OTHER_ERROR;
|
||||
}
|
||||
assert(rid == pSyncNode->rid);
|
||||
sTrace("sync event vgId:%d propose msgType:%s", pSyncNode->vgId, TMSG_INFO(pMsg->msgType));
|
||||
|
||||
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
|
||||
SRespStub stub;
|
||||
|
@ -411,6 +431,8 @@ int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak) {
|
|||
SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) {
|
||||
SSyncInfo* pSyncInfo = (SSyncInfo*)pOldSyncInfo;
|
||||
|
||||
sInfo("sync event vgId:%d sync open", pSyncInfo->vgId);
|
||||
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosMemoryMalloc(sizeof(SSyncNode));
|
||||
assert(pSyncNode != NULL);
|
||||
memset(pSyncNode, 0, sizeof(SSyncNode));
|
||||
|
@ -439,9 +461,11 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) {
|
|||
assert(pSyncNode->pRaftCfg != NULL);
|
||||
pSyncInfo->syncCfg = pSyncNode->pRaftCfg->cfg;
|
||||
|
||||
char* seralized = raftCfg2Str(pSyncNode->pRaftCfg);
|
||||
sInfo("syncNodeOpen update config :%s", seralized);
|
||||
taosMemoryFree(seralized);
|
||||
if (gRaftDetailLog) {
|
||||
char* seralized = raftCfg2Str(pSyncNode->pRaftCfg);
|
||||
sInfo("syncNodeOpen update config :%s", seralized);
|
||||
taosMemoryFree(seralized);
|
||||
}
|
||||
|
||||
raftCfgClose(pSyncNode->pRaftCfg);
|
||||
}
|
||||
|
@ -612,7 +636,7 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) {
|
|||
}
|
||||
|
||||
// snapshot receivers
|
||||
pSyncNode->pNewNodeReceiver = snapshotReceiverCreate(pSyncNode, 100);
|
||||
pSyncNode->pNewNodeReceiver = snapshotReceiverCreate(pSyncNode, EMPTY_RAFT_ID);
|
||||
|
||||
// start in syncNodeStart
|
||||
// start raft
|
||||
|
@ -628,9 +652,7 @@ void syncNodeStart(SSyncNode* pSyncNode) {
|
|||
// start raft
|
||||
if (pSyncNode->replicaNum == 1) {
|
||||
raftStoreNextTerm(pSyncNode->pRaftStore);
|
||||
syncNodeBecomeLeader(pSyncNode);
|
||||
|
||||
syncNodeLog2("==state change become leader immediately==", pSyncNode);
|
||||
syncNodeBecomeLeader(pSyncNode, "one replica start");
|
||||
|
||||
// Raft 3.6.2 Committing entries from previous terms
|
||||
|
||||
|
@ -638,41 +660,22 @@ void syncNodeStart(SSyncNode* pSyncNode) {
|
|||
syncNodeAppendNoop(pSyncNode);
|
||||
syncMaybeAdvanceCommitIndex(pSyncNode); // maybe only one replica
|
||||
|
||||
/*
|
||||
sInfo("==syncNodeStart== RestoreFinish begin 1 replica tsem_wait %p", pSyncNode);
|
||||
tsem_wait(&pSyncNode->restoreSem);
|
||||
sInfo("==syncNodeStart== RestoreFinish end 1 replica tsem_wait %p", pSyncNode);
|
||||
*/
|
||||
|
||||
/*
|
||||
while (pSyncNode->restoreFinish != true) {
|
||||
taosMsleep(10);
|
||||
if (gRaftDetailLog) {
|
||||
syncNodeLog2("==state change become leader immediately==", pSyncNode);
|
||||
}
|
||||
*/
|
||||
|
||||
sInfo("==syncNodeStart== restoreFinish ok 1 replica %p vgId:%d", pSyncNode, pSyncNode->vgId);
|
||||
return;
|
||||
}
|
||||
|
||||
syncNodeBecomeFollower(pSyncNode);
|
||||
syncNodeBecomeFollower(pSyncNode, "first start");
|
||||
|
||||
// for test
|
||||
int32_t ret = 0;
|
||||
// int32_t ret = 0;
|
||||
// ret = syncNodeStartPingTimer(pSyncNode);
|
||||
assert(ret == 0);
|
||||
// assert(ret == 0);
|
||||
|
||||
/*
|
||||
sInfo("==syncNodeStart== RestoreFinish begin multi replica tsem_wait %p", pSyncNode);
|
||||
tsem_wait(&pSyncNode->restoreSem);
|
||||
sInfo("==syncNodeStart== RestoreFinish end multi replica tsem_wait %p", pSyncNode);
|
||||
*/
|
||||
|
||||
/*
|
||||
while (pSyncNode->restoreFinish != true) {
|
||||
taosMsleep(10);
|
||||
if (gRaftDetailLog) {
|
||||
syncNodeLog2("==state change become leader immediately==", pSyncNode);
|
||||
}
|
||||
*/
|
||||
sInfo("==syncNodeStart== restoreFinish ok multi replica %p vgId:%d", pSyncNode, pSyncNode->vgId);
|
||||
}
|
||||
|
||||
void syncNodeStartStandBy(SSyncNode* pSyncNode) {
|
||||
|
@ -687,6 +690,8 @@ void syncNodeStartStandBy(SSyncNode* pSyncNode) {
|
|||
}
|
||||
|
||||
void syncNodeClose(SSyncNode* pSyncNode) {
|
||||
sInfo("sync event vgId:%d sync close", pSyncNode->vgId);
|
||||
|
||||
int32_t ret;
|
||||
assert(pSyncNode != NULL);
|
||||
|
||||
|
@ -1131,7 +1136,10 @@ void syncNodeUpdateConfig(SSyncNode* pSyncNode, SSyncCfg* newConfig, bool* isDro
|
|||
}
|
||||
|
||||
raftCfgPersist(pSyncNode->pRaftCfg);
|
||||
syncNodeLog2("==syncNodeUpdateConfig==", pSyncNode);
|
||||
|
||||
if (gRaftDetailLog) {
|
||||
syncNodeLog2("==syncNodeUpdateConfig==", pSyncNode);
|
||||
}
|
||||
}
|
||||
|
||||
SSyncNode* syncNodeAcquire(int64_t rid) {
|
||||
|
@ -1149,12 +1157,14 @@ void syncNodeRelease(SSyncNode* pNode) { taosReleaseRef(tsNodeRefId, pNode->rid)
|
|||
void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term) {
|
||||
if (term > pSyncNode->pRaftStore->currentTerm) {
|
||||
raftStoreSetTerm(pSyncNode->pRaftStore, term);
|
||||
syncNodeBecomeFollower(pSyncNode);
|
||||
syncNodeBecomeFollower(pSyncNode, "update term");
|
||||
raftStoreClearVote(pSyncNode->pRaftStore);
|
||||
}
|
||||
}
|
||||
|
||||
void syncNodeBecomeFollower(SSyncNode* pSyncNode) {
|
||||
void syncNodeBecomeFollower(SSyncNode* pSyncNode, const char* debugStr) {
|
||||
sInfo("sync event vgId:%d become follower, %s", pSyncNode->vgId, debugStr);
|
||||
|
||||
// maybe clear leader cache
|
||||
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
|
||||
pSyncNode->leaderCache = EMPTY_RAFT_ID;
|
||||
|
@ -1186,7 +1196,9 @@ void syncNodeBecomeFollower(SSyncNode* pSyncNode) {
|
|||
// evoterLog |-> voterLog[i]]}
|
||||
// /\ UNCHANGED <<messages, currentTerm, votedFor, candidateVars, logVars>>
|
||||
//
|
||||
void syncNodeBecomeLeader(SSyncNode* pSyncNode) {
|
||||
void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) {
|
||||
sInfo("sync event vgId:%d become leader, %s", pSyncNode->vgId, debugStr);
|
||||
|
||||
// state change
|
||||
pSyncNode->state = TAOS_SYNC_STATE_LEADER;
|
||||
|
||||
|
@ -1237,7 +1249,7 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode) {
|
|||
void syncNodeCandidate2Leader(SSyncNode* pSyncNode) {
|
||||
assert(pSyncNode->state == TAOS_SYNC_STATE_CANDIDATE);
|
||||
assert(voteGrantedMajority(pSyncNode->pVotesGranted));
|
||||
syncNodeBecomeLeader(pSyncNode);
|
||||
syncNodeBecomeLeader(pSyncNode, "candidate to leader");
|
||||
|
||||
syncNodeLog2("==state change syncNodeCandidate2Leader==", pSyncNode);
|
||||
|
||||
|
@ -1260,14 +1272,14 @@ void syncNodeFollower2Candidate(SSyncNode* pSyncNode) {
|
|||
|
||||
void syncNodeLeader2Follower(SSyncNode* pSyncNode) {
|
||||
assert(pSyncNode->state == TAOS_SYNC_STATE_LEADER);
|
||||
syncNodeBecomeFollower(pSyncNode);
|
||||
syncNodeBecomeFollower(pSyncNode, "leader to follower");
|
||||
|
||||
syncNodeLog2("==state change syncNodeLeader2Follower==", pSyncNode);
|
||||
}
|
||||
|
||||
void syncNodeCandidate2Follower(SSyncNode* pSyncNode) {
|
||||
assert(pSyncNode->state == TAOS_SYNC_STATE_CANDIDATE);
|
||||
syncNodeBecomeFollower(pSyncNode);
|
||||
syncNodeBecomeFollower(pSyncNode, "candidate to follower");
|
||||
|
||||
syncNodeLog2("==state change syncNodeCandidate2Follower==", pSyncNode);
|
||||
}
|
||||
|
@ -1467,9 +1479,11 @@ void syncNodeLog(SSyncNode* pObj) {
|
|||
}
|
||||
|
||||
void syncNodeLog2(char* s, SSyncNode* pObj) {
|
||||
char* serialized = syncNode2Str(pObj);
|
||||
sTraceLong("syncNodeLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
||||
taosMemoryFree(serialized);
|
||||
if (gRaftDetailLog) {
|
||||
char* serialized = syncNode2Str(pObj);
|
||||
sTraceLong("syncNodeLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
||||
taosMemoryFree(serialized);
|
||||
}
|
||||
}
|
||||
|
||||
// ------ local funciton ---------
|
||||
|
@ -1724,17 +1738,19 @@ const char* syncStr(ESyncState state) {
|
|||
int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, uint64_t flag) {
|
||||
int32_t code = 0;
|
||||
ESyncState state = flag;
|
||||
sInfo("sync event commit from index:%" PRId64 " to index:%" PRId64 ", %s", beginIndex, endIndex,
|
||||
syncUtilState2String(state));
|
||||
sInfo("sync event vgId:%d commit by wal from index:%" PRId64 " to index:%" PRId64 ", %s", ths->vgId, beginIndex,
|
||||
endIndex, syncUtilState2String(state));
|
||||
|
||||
// maybe execute by leader, skip snapshot
|
||||
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
||||
if (ths->pFsm->FpGetSnapshot != NULL) {
|
||||
ths->pFsm->FpGetSnapshot(ths->pFsm, &snapshot);
|
||||
}
|
||||
if (beginIndex <= snapshot.lastApplyIndex) {
|
||||
beginIndex = snapshot.lastApplyIndex + 1;
|
||||
}
|
||||
/*
|
||||
// maybe execute by leader, skip snapshot
|
||||
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
||||
if (ths->pFsm->FpGetSnapshot != NULL) {
|
||||
ths->pFsm->FpGetSnapshot(ths->pFsm, &snapshot);
|
||||
}
|
||||
if (beginIndex <= snapshot.lastApplyIndex) {
|
||||
beginIndex = snapshot.lastApplyIndex + 1;
|
||||
}
|
||||
*/
|
||||
|
||||
// execute fsm
|
||||
if (ths->pFsm != NULL) {
|
||||
|
@ -1791,17 +1807,19 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex,
|
|||
// change isStandBy to normal
|
||||
if (!isDrop) {
|
||||
if (ths->state == TAOS_SYNC_STATE_LEADER) {
|
||||
syncNodeBecomeLeader(ths);
|
||||
syncNodeBecomeLeader(ths, "config change");
|
||||
} else {
|
||||
syncNodeBecomeFollower(ths);
|
||||
syncNodeBecomeFollower(ths, "config change");
|
||||
}
|
||||
}
|
||||
|
||||
char* sOld = syncCfg2Str(&oldSyncCfg);
|
||||
char* sNew = syncCfg2Str(&newSyncCfg);
|
||||
sInfo("==config change== 0x11 old:%s new:%s isDrop:%d \n", sOld, sNew, isDrop);
|
||||
taosMemoryFree(sOld);
|
||||
taosMemoryFree(sNew);
|
||||
if (gRaftDetailLog) {
|
||||
char* sOld = syncCfg2Str(&oldSyncCfg);
|
||||
char* sNew = syncCfg2Str(&newSyncCfg);
|
||||
sInfo("==config change== 0x11 old:%s new:%s isDrop:%d \n", sOld, sNew, isDrop);
|
||||
taosMemoryFree(sOld);
|
||||
taosMemoryFree(sNew);
|
||||
}
|
||||
}
|
||||
|
||||
// always call FpReConfigCb
|
||||
|
@ -1810,10 +1828,12 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex,
|
|||
cbMeta.currentTerm = ths->pRaftStore->currentTerm;
|
||||
cbMeta.index = pEntry->index;
|
||||
cbMeta.term = pEntry->term;
|
||||
cbMeta.newCfg = newSyncCfg;
|
||||
cbMeta.oldCfg = oldSyncCfg;
|
||||
cbMeta.seqNum = pEntry->seqNum;
|
||||
cbMeta.flag = 0x11;
|
||||
cbMeta.isDrop = isDrop;
|
||||
ths->pFsm->FpReConfigCb(ths->pFsm, newSyncCfg, cbMeta);
|
||||
ths->pFsm->FpReConfigCb(ths->pFsm, &rpcMsg, cbMeta);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1824,7 +1844,7 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex,
|
|||
ths->pFsm->FpRestoreFinishCb(ths->pFsm);
|
||||
}
|
||||
ths->restoreFinish = true;
|
||||
sInfo("restore finish %p vgId:%d", ths, ths->vgId);
|
||||
sInfo("sync event vgId:%d restore finish", ths->vgId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
|
||||
#include "syncRaftLog.h"
|
||||
#include "syncRaftCfg.h"
|
||||
#include "wal.h"
|
||||
|
||||
// refactor, log[0 .. n] ==> log[m .. n]
|
||||
|
@ -161,7 +162,9 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr
|
|||
|
||||
walFsync(pWal, true);
|
||||
|
||||
sTrace("sync event write index:%" PRId64, pEntry->index);
|
||||
sTrace("sync event vgId:%d write index:%ld, %s, isStandBy:%d, msgType:%s, originalRpcType:%s", pData->pSyncNode->vgId,
|
||||
pEntry->index, syncUtilState2String(pData->pSyncNode->state), pData->pSyncNode->pRaftCfg->isStandBy,
|
||||
TMSG_INFO(pEntry->msgType), TMSG_INFO(pEntry->originalRpcType));
|
||||
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ int32_t syncNodeAppendEntriesPeersSnapshot(SSyncNode* pSyncNode) {
|
|||
syncIndexMgrLog2("begin append entries peers pNextIndex:", pSyncNode->pNextIndex);
|
||||
syncIndexMgrLog2("begin append entries peers pMatchIndex:", pSyncNode->pMatchIndex);
|
||||
logStoreSimpleLog2("begin append entries peers LogStore:", pSyncNode->pLogStore);
|
||||
{
|
||||
if (gRaftDetailLog) {
|
||||
SSnapshot snapshot;
|
||||
pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot);
|
||||
sTrace("begin append entries peers, snapshot.lastApplyIndex:%ld, snapshot.lastApplyTerm:%lu",
|
||||
|
@ -201,7 +201,6 @@ int32_t syncNodeReplicate(SSyncNode* pSyncNode) {
|
|||
}
|
||||
|
||||
int32_t syncNodeAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncAppendEntries* pMsg) {
|
||||
sTrace("syncNodeAppendEntries pSyncNode:%p ", pSyncNode);
|
||||
int32_t ret = 0;
|
||||
|
||||
SRpcMsg rpcMsg;
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "syncUtil.h"
|
||||
#include "wal.h"
|
||||
|
||||
static void snapshotReceiverDoStart(SSyncSnapshotReceiver *pReceiver, SyncTerm privateTerm);
|
||||
static void snapshotReceiverDoStart(SSyncSnapshotReceiver *pReceiver, SyncTerm privateTerm, SRaftId fromId);
|
||||
|
||||
//----------------------------------
|
||||
SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaIndex) {
|
||||
|
@ -105,13 +105,23 @@ void snapshotSenderStart(SSyncSnapshotSender *pSender) {
|
|||
syncSnapshotSend2RpcMsg(pMsg, &rpcMsg);
|
||||
syncNodeSendMsgById(&(pMsg->destId), pSender->pSyncNode, &rpcMsg);
|
||||
|
||||
char *msgStr = syncSnapshotSend2Str(pMsg);
|
||||
char host[128];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pSender->pSyncNode->replicasId[pSender->replicaIndex].addr, host, sizeof(host), &port);
|
||||
sTrace("sync event snapshot send to %s:%d begin seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu send msg:%s", host,
|
||||
port, pSender->seq, pSender->ack, pSender->snapshot.lastApplyIndex, pSender->snapshot.lastApplyTerm, msgStr);
|
||||
taosMemoryFree(msgStr);
|
||||
|
||||
if (gRaftDetailLog) {
|
||||
char *msgStr = syncSnapshotSend2Str(pMsg);
|
||||
sTrace(
|
||||
"sync event vgId:%d snapshot send to %s:%d begin seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu send "
|
||||
"msg:%s",
|
||||
pSender->pSyncNode->vgId, host, port, pSender->seq, pSender->ack, pSender->snapshot.lastApplyIndex,
|
||||
pSender->snapshot.lastApplyTerm, msgStr);
|
||||
taosMemoryFree(msgStr);
|
||||
} else {
|
||||
sTrace("sync event vgId:%d snapshot send to %s:%d begin seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu",
|
||||
pSender->pSyncNode->vgId, host, port, pSender->seq, pSender->ack, pSender->snapshot.lastApplyIndex,
|
||||
pSender->snapshot.lastApplyTerm);
|
||||
}
|
||||
|
||||
syncSnapshotSendDestroy(pMsg);
|
||||
}
|
||||
|
@ -183,9 +193,11 @@ void snapshotSenderStop(SSyncSnapshotSender *pSender) {
|
|||
|
||||
pSender->start = false;
|
||||
|
||||
char *s = snapshotSender2Str(pSender);
|
||||
sInfo("snapshotSenderStop %s", s);
|
||||
taosMemoryFree(s);
|
||||
if (gRaftDetailLog) {
|
||||
char *s = snapshotSender2Str(pSender);
|
||||
sInfo("snapshotSenderStop %s", s);
|
||||
taosMemoryFree(s);
|
||||
}
|
||||
}
|
||||
|
||||
// when sender receiver ack, call this function to send msg from seq
|
||||
|
@ -225,20 +237,29 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) {
|
|||
syncSnapshotSend2RpcMsg(pMsg, &rpcMsg);
|
||||
syncNodeSendMsgById(&(pMsg->destId), pSender->pSyncNode, &rpcMsg);
|
||||
|
||||
char *msgStr = syncSnapshotSend2Str(pMsg);
|
||||
char host[128];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pSender->pSyncNode->replicasId[pSender->replicaIndex].addr, host, sizeof(host), &port);
|
||||
|
||||
if (pSender->seq == SYNC_SNAPSHOT_SEQ_END) {
|
||||
sTrace("sync event snapshot send to %s:%d finish seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu send msg:%s",
|
||||
host, port, pSender->seq, pSender->ack, pSender->snapshot.lastApplyIndex, pSender->snapshot.lastApplyTerm,
|
||||
msgStr);
|
||||
if (gRaftDetailLog) {
|
||||
char *msgStr = syncSnapshotSend2Str(pMsg);
|
||||
sTrace(
|
||||
"sync event vgId:%d snapshot send to %s:%d finish seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu send "
|
||||
"msg:%s",
|
||||
pSender->pSyncNode->vgId, host, port, pSender->seq, pSender->ack, pSender->snapshot.lastApplyIndex,
|
||||
pSender->snapshot.lastApplyTerm, msgStr);
|
||||
taosMemoryFree(msgStr);
|
||||
} else {
|
||||
sTrace("sync event vgId:%d snapshot send to %s:%d finish seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu",
|
||||
pSender->pSyncNode->vgId, host, port, pSender->seq, pSender->ack, pSender->snapshot.lastApplyIndex,
|
||||
pSender->snapshot.lastApplyTerm);
|
||||
}
|
||||
} else {
|
||||
sTrace("sync event snapshot send to %s:%d sending seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu send msg:%s",
|
||||
host, port, pSender->seq, pSender->ack, pSender->snapshot.lastApplyIndex, pSender->snapshot.lastApplyTerm,
|
||||
msgStr);
|
||||
sTrace("sync event vgId:%d snapshot send to %s:%d sending seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu",
|
||||
pSender->pSyncNode->vgId, host, port, pSender->seq, pSender->ack, pSender->snapshot.lastApplyIndex,
|
||||
pSender->snapshot.lastApplyTerm);
|
||||
}
|
||||
taosMemoryFree(msgStr);
|
||||
|
||||
syncSnapshotSendDestroy(pMsg);
|
||||
return 0;
|
||||
|
@ -260,13 +281,19 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender) {
|
|||
syncSnapshotSend2RpcMsg(pMsg, &rpcMsg);
|
||||
syncNodeSendMsgById(&(pMsg->destId), pSender->pSyncNode, &rpcMsg);
|
||||
|
||||
char *msgStr = syncSnapshotSend2Str(pMsg);
|
||||
char host[128];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pSender->pSyncNode->replicasId[pSender->replicaIndex].addr, host, sizeof(host), &port);
|
||||
sTrace("sync event snapshot send to %s:%d resend seq:%d ack:%d send msg:%s", host, port, pSender->seq, pSender->ack,
|
||||
msgStr);
|
||||
taosMemoryFree(msgStr);
|
||||
|
||||
if (gRaftDetailLog) {
|
||||
char *msgStr = syncSnapshotSend2Str(pMsg);
|
||||
sTrace("sync event vgId:%d snapshot send to %s:%d resend seq:%d ack:%d send msg:%s", pSender->pSyncNode->vgId,
|
||||
host, port, pSender->seq, pSender->ack, msgStr);
|
||||
taosMemoryFree(msgStr);
|
||||
} else {
|
||||
sTrace("sync event vgId:%d snapshot send to %s:%d resend seq:%d ack:%d", pSender->pSyncNode->vgId, host, port,
|
||||
pSender->seq, pSender->ack);
|
||||
}
|
||||
|
||||
syncSnapshotSendDestroy(pMsg);
|
||||
}
|
||||
|
@ -331,7 +358,7 @@ char *snapshotSender2Str(SSyncSnapshotSender *pSender) {
|
|||
}
|
||||
|
||||
// -------------------------------------
|
||||
SSyncSnapshotReceiver *snapshotReceiverCreate(SSyncNode *pSyncNode, int32_t replicaIndex) {
|
||||
SSyncSnapshotReceiver *snapshotReceiverCreate(SSyncNode *pSyncNode, SRaftId fromId) {
|
||||
bool condition = (pSyncNode->pFsm->FpSnapshotStartWrite != NULL) && (pSyncNode->pFsm->FpSnapshotStopWrite != NULL) &&
|
||||
(pSyncNode->pFsm->FpSnapshotDoWrite != NULL);
|
||||
|
||||
|
@ -345,7 +372,7 @@ SSyncSnapshotReceiver *snapshotReceiverCreate(SSyncNode *pSyncNode, int32_t repl
|
|||
pReceiver->ack = SYNC_SNAPSHOT_SEQ_BEGIN;
|
||||
pReceiver->pWriter = NULL;
|
||||
pReceiver->pSyncNode = pSyncNode;
|
||||
pReceiver->replicaIndex = replicaIndex;
|
||||
pReceiver->fromId = fromId;
|
||||
pReceiver->term = pSyncNode->pRaftStore->currentTerm;
|
||||
pReceiver->privateTerm = 0;
|
||||
|
||||
|
@ -365,10 +392,11 @@ void snapshotReceiverDestroy(SSyncSnapshotReceiver *pReceiver) {
|
|||
bool snapshotReceiverIsStart(SSyncSnapshotReceiver *pReceiver) { return pReceiver->start; }
|
||||
|
||||
// begin receive snapshot msg (current term, seq begin)
|
||||
static void snapshotReceiverDoStart(SSyncSnapshotReceiver *pReceiver, SyncTerm privateTerm) {
|
||||
static void snapshotReceiverDoStart(SSyncSnapshotReceiver *pReceiver, SyncTerm privateTerm, SRaftId fromId) {
|
||||
pReceiver->term = pReceiver->pSyncNode->pRaftStore->currentTerm;
|
||||
pReceiver->privateTerm = privateTerm;
|
||||
pReceiver->ack = SYNC_SNAPSHOT_SEQ_BEGIN;
|
||||
pReceiver->fromId = fromId;
|
||||
|
||||
ASSERT(pReceiver->pWriter == NULL);
|
||||
int32_t ret = pReceiver->pSyncNode->pFsm->FpSnapshotStartWrite(pReceiver->pSyncNode->pFsm, &(pReceiver->pWriter));
|
||||
|
@ -377,14 +405,15 @@ static void snapshotReceiverDoStart(SSyncSnapshotReceiver *pReceiver, SyncTerm p
|
|||
|
||||
// if receiver receive msg from seq = SYNC_SNAPSHOT_SEQ_BEGIN, start receiver
|
||||
// if already start, force close, start again
|
||||
void snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncTerm privateTerm) {
|
||||
void snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncTerm privateTerm, SRaftId fromId) {
|
||||
if (!snapshotReceiverIsStart(pReceiver)) {
|
||||
// start
|
||||
snapshotReceiverDoStart(pReceiver, privateTerm);
|
||||
snapshotReceiverDoStart(pReceiver, privateTerm, fromId);
|
||||
pReceiver->start = true;
|
||||
|
||||
} else {
|
||||
// already start
|
||||
sInfo("snapshot recv, receiver already start");
|
||||
|
||||
// force close, abandon incomplete data
|
||||
int32_t ret =
|
||||
|
@ -393,15 +422,15 @@ void snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncTerm privateTer
|
|||
pReceiver->pWriter = NULL;
|
||||
|
||||
// start again
|
||||
snapshotReceiverDoStart(pReceiver, privateTerm);
|
||||
snapshotReceiverDoStart(pReceiver, privateTerm, fromId);
|
||||
pReceiver->start = true;
|
||||
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
char *s = snapshotReceiver2Str(pReceiver);
|
||||
sInfo("snapshotReceiverStart %s", s);
|
||||
taosMemoryFree(s);
|
||||
if (gRaftDetailLog) {
|
||||
char *s = snapshotReceiver2Str(pReceiver);
|
||||
sInfo("snapshotReceiverStart %s", s);
|
||||
taosMemoryFree(s);
|
||||
}
|
||||
}
|
||||
|
||||
void snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver, bool apply) {
|
||||
|
@ -418,9 +447,11 @@ void snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver, bool apply) {
|
|||
++(pReceiver->privateTerm);
|
||||
}
|
||||
|
||||
char *s = snapshotReceiver2Str(pReceiver);
|
||||
sInfo("snapshotReceiverStop %s", s);
|
||||
taosMemoryFree(s);
|
||||
if (gRaftDetailLog) {
|
||||
char *s = snapshotReceiver2Str(pReceiver);
|
||||
sInfo("snapshotReceiverStop %s", s);
|
||||
taosMemoryFree(s);
|
||||
}
|
||||
}
|
||||
|
||||
cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver) {
|
||||
|
@ -436,7 +467,22 @@ cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver) {
|
|||
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pReceiver->pSyncNode);
|
||||
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
||||
cJSON_AddNumberToObject(pRoot, "replicaIndex", pReceiver->replicaIndex);
|
||||
|
||||
cJSON *pFromId = cJSON_CreateObject();
|
||||
snprintf(u64buf, sizeof(u64buf), "%lu", pReceiver->fromId.addr);
|
||||
cJSON_AddStringToObject(pFromId, "addr", u64buf);
|
||||
{
|
||||
uint64_t u64 = pReceiver->fromId.addr;
|
||||
cJSON *pTmp = pFromId;
|
||||
char host[128] = {0};
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
||||
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
||||
}
|
||||
cJSON_AddNumberToObject(pFromId, "vgId", pReceiver->fromId.vgId);
|
||||
cJSON_AddItemToObject(pRoot, "fromId", pFromId);
|
||||
|
||||
snprintf(u64buf, sizeof(u64buf), "%lu", pReceiver->term);
|
||||
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
||||
|
||||
|
@ -468,17 +514,23 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
|||
if (pMsg->term == pSyncNode->pRaftStore->currentTerm) {
|
||||
if (pMsg->seq == SYNC_SNAPSHOT_SEQ_BEGIN) {
|
||||
// begin
|
||||
snapshotReceiverStart(pReceiver, pMsg->privateTerm);
|
||||
snapshotReceiverStart(pReceiver, pMsg->privateTerm, pMsg->srcId);
|
||||
pReceiver->ack = pMsg->seq;
|
||||
needRsp = true;
|
||||
|
||||
char *msgStr = syncSnapshotSend2Str(pMsg);
|
||||
char host[128];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
sTrace("sync event snapshot recv from %s:%d begin ack:%d, lastIndex:%ld, lastTerm:%lu, recv msg:%s", host, port,
|
||||
pReceiver->ack, pMsg->lastIndex, pMsg->lastTerm, msgStr);
|
||||
taosMemoryFree(msgStr);
|
||||
|
||||
if (gRaftDetailLog) {
|
||||
char *msgStr = syncSnapshotSend2Str(pMsg);
|
||||
sTrace("sync event vgId:%d snapshot recv from %s:%d begin ack:%d, lastIndex:%ld, lastTerm:%lu, recv msg:%s",
|
||||
pSyncNode->vgId, host, port, pReceiver->ack, pMsg->lastIndex, pMsg->lastTerm, msgStr);
|
||||
taosMemoryFree(msgStr);
|
||||
} else {
|
||||
sTrace("sync event vgId:%d snapshot recv from %s:%d begin ack:%d, lastIndex:%ld, lastTerm:%lu",
|
||||
pSyncNode->vgId, host, port, pReceiver->ack, pMsg->lastIndex, pMsg->lastTerm);
|
||||
}
|
||||
|
||||
} else if (pMsg->seq == SYNC_SNAPSHOT_SEQ_END) {
|
||||
// end, finish FSM
|
||||
|
@ -486,29 +538,46 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
|||
ASSERT(writeCode == 0);
|
||||
|
||||
pSyncNode->pFsm->FpSnapshotStopWrite(pSyncNode->pFsm, pReceiver->pWriter, true);
|
||||
|
||||
pSyncNode->pLogStore->syncLogSetBeginIndex(pSyncNode->pLogStore, pMsg->lastIndex + 1);
|
||||
char *logSimpleStr = logStoreSimple2Str(pSyncNode->pLogStore);
|
||||
|
||||
SSnapshot snapshot;
|
||||
pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot);
|
||||
|
||||
char host[128];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
sInfo(
|
||||
"sync event snapshot recv from %s:%d finish, update log begin index:%ld, snapshot.lastApplyIndex:%ld, "
|
||||
"snapshot.lastApplyTerm:%lu, raft log:%s",
|
||||
host, port, pMsg->lastIndex + 1, snapshot.lastApplyIndex, snapshot.lastApplyTerm, logSimpleStr);
|
||||
taosMemoryFree(logSimpleStr);
|
||||
|
||||
if (gRaftDetailLog) {
|
||||
char *logSimpleStr = logStoreSimple2Str(pSyncNode->pLogStore);
|
||||
sInfo(
|
||||
"sync event vgId:%d snapshot recv from %s:%d finish, update log begin index:%ld, "
|
||||
"snapshot.lastApplyIndex:%ld, "
|
||||
"snapshot.lastApplyTerm:%lu, raft log:%s",
|
||||
pSyncNode->vgId, host, port, pMsg->lastIndex + 1, snapshot.lastApplyIndex, snapshot.lastApplyTerm,
|
||||
logSimpleStr);
|
||||
taosMemoryFree(logSimpleStr);
|
||||
} else {
|
||||
sInfo(
|
||||
"sync event vgId:%d snapshot recv from %s:%d finish, update log begin index:%ld, "
|
||||
"snapshot.lastApplyIndex:%ld, "
|
||||
"snapshot.lastApplyTerm:%lu",
|
||||
pSyncNode->vgId, host, port, pMsg->lastIndex + 1, snapshot.lastApplyIndex, snapshot.lastApplyTerm);
|
||||
}
|
||||
|
||||
pReceiver->pWriter = NULL;
|
||||
snapshotReceiverStop(pReceiver, true);
|
||||
pReceiver->ack = pMsg->seq;
|
||||
needRsp = true;
|
||||
|
||||
char *msgStr = syncSnapshotSend2Str(pMsg);
|
||||
sTrace("sync event snapshot recv from %s:%d end ack:%d, lastIndex:%ld, lastTerm:%lu, recv msg:%s", host, port,
|
||||
pReceiver->ack, pMsg->lastIndex, pMsg->lastTerm, msgStr);
|
||||
taosMemoryFree(msgStr);
|
||||
if (gRaftDetailLog) {
|
||||
char *msgStr = syncSnapshotSend2Str(pMsg);
|
||||
sTrace("sync event vgId:%d snapshot recv from %s:%d end ack:%d, lastIndex:%ld, lastTerm:%lu, recv msg:%s",
|
||||
pReceiver->pSyncNode->vgId, host, port, pReceiver->ack, pMsg->lastIndex, pMsg->lastTerm, msgStr);
|
||||
taosMemoryFree(msgStr);
|
||||
} else {
|
||||
sTrace("sync event vgId:%d snapshot recv from %s:%d end ack:%d, lastIndex:%ld, lastTerm:%lu",
|
||||
pReceiver->pSyncNode->vgId, host, port, pReceiver->ack, pMsg->lastIndex, pMsg->lastTerm);
|
||||
}
|
||||
|
||||
} else if (pMsg->seq == SYNC_SNAPSHOT_SEQ_FORCE_CLOSE) {
|
||||
pSyncNode->pFsm->FpSnapshotStopWrite(pSyncNode->pFsm, pReceiver->pWriter, false);
|
||||
|
@ -519,11 +588,17 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
|||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
|
||||
char *msgStr = syncSnapshotSend2Str(pMsg);
|
||||
sTrace("sync event snapshot recv from %s:%d force close ack:%d, lastIndex:%ld, lastTerm:%lu, recv msg:%s", host,
|
||||
port, pReceiver->ack, pMsg->lastIndex, pMsg->lastTerm, msgStr);
|
||||
|
||||
taosMemoryFree(msgStr);
|
||||
if (gRaftDetailLog) {
|
||||
char *msgStr = syncSnapshotSend2Str(pMsg);
|
||||
sTrace(
|
||||
"sync event vgId:%d snapshot recv from %s:%d force close ack:%d, lastIndex:%ld, lastTerm:%lu, recv "
|
||||
"msg:%s",
|
||||
pReceiver->pSyncNode->vgId, host, port, pReceiver->ack, pMsg->lastIndex, pMsg->lastTerm, msgStr);
|
||||
taosMemoryFree(msgStr);
|
||||
} else {
|
||||
sTrace("sync event vgId:%d snapshot recv from %s:%d force close ack:%d, lastIndex:%ld, lastTerm:%lu",
|
||||
pReceiver->pSyncNode->vgId, host, port, pReceiver->ack, pMsg->lastIndex, pMsg->lastTerm);
|
||||
}
|
||||
|
||||
} else if (pMsg->seq > SYNC_SNAPSHOT_SEQ_BEGIN && pMsg->seq < SYNC_SNAPSHOT_SEQ_END) {
|
||||
// transfering
|
||||
|
@ -535,13 +610,20 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
|||
}
|
||||
needRsp = true;
|
||||
|
||||
char *msgStr = syncSnapshotSend2Str(pMsg);
|
||||
char host[128];
|
||||
uint16_t port;
|
||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||
sTrace("sync event snapshot recv from %s:%d receiving ack:%d, lastIndex:%ld, lastTerm:%lu, recv msg:%s", host,
|
||||
port, pReceiver->ack, pMsg->lastIndex, pMsg->lastTerm, msgStr);
|
||||
taosMemoryFree(msgStr);
|
||||
|
||||
if (gRaftDetailLog) {
|
||||
char *msgStr = syncSnapshotSend2Str(pMsg);
|
||||
sTrace(
|
||||
"sync event vgId:%d snapshot recv from %s:%d receiving ack:%d, lastIndex:%ld, lastTerm:%lu, recv msg:%s",
|
||||
pSyncNode->vgId, host, port, pReceiver->ack, pMsg->lastIndex, pMsg->lastTerm, msgStr);
|
||||
taosMemoryFree(msgStr);
|
||||
} else {
|
||||
sTrace("sync event vgId:%d snapshot recv from %s:%d receiving ack:%d, lastIndex:%ld, lastTerm:%lu",
|
||||
pSyncNode->vgId, host, port, pReceiver->ack, pMsg->lastIndex, pMsg->lastTerm);
|
||||
}
|
||||
|
||||
} else {
|
||||
ASSERT(0);
|
||||
|
|
|
@ -146,7 +146,7 @@ int32_t SnapshotDoWrite(struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_
|
|||
|
||||
void RestoreFinishCb(struct SSyncFSM* pFsm) { sTrace("==callback== ==RestoreFinishCb=="); }
|
||||
|
||||
void ReConfigCb(struct SSyncFSM* pFsm, SSyncCfg newCfg, SReConfigCbMeta cbMeta) {
|
||||
void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta cbMeta) {
|
||||
sTrace("==callback== ==ReConfigCb== flag:0x%lX, isDrop:%d, index:%ld, code:%d, currentTerm:%lu, term:%lu",
|
||||
cbMeta.flag, cbMeta.isDrop, cbMeta.index, cbMeta.code, cbMeta.currentTerm, cbMeta.term);
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ int32_t GetSnapshotCb(struct SSyncFSM* pFsm, SSnapshot* pSnapshot) {
|
|||
|
||||
void RestoreFinishCb(struct SSyncFSM* pFsm) { sTrace("==callback== ==RestoreFinishCb=="); }
|
||||
|
||||
void ReConfigCb(struct SSyncFSM* pFsm, SSyncCfg newCfg, SReConfigCbMeta cbMeta) {
|
||||
void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta cbMeta) {
|
||||
sTrace("==callback== ==ReConfigCb== flag:0x%lX, isDrop:%d, index:%ld, code:%d, currentTerm:%lu, term:%lu",
|
||||
cbMeta.flag, cbMeta.isDrop, cbMeta.index, cbMeta.code, cbMeta.currentTerm, cbMeta.term);
|
||||
}
|
||||
|
|
|
@ -41,7 +41,11 @@ SSyncSnapshotReceiver* createReceiver() {
|
|||
pSyncNode->pFsm->FpSnapshotStopWrite = SnapshotStopWrite;
|
||||
pSyncNode->pFsm->FpSnapshotDoWrite = SnapshotDoWrite;
|
||||
|
||||
SSyncSnapshotReceiver* pReceiver = snapshotReceiverCreate(pSyncNode, 2);
|
||||
SRaftId id;
|
||||
id.addr = syncUtilAddr2U64("1.2.3.4", 99);
|
||||
id.vgId = 100;
|
||||
|
||||
SSyncSnapshotReceiver* pReceiver = snapshotReceiverCreate(pSyncNode, id);
|
||||
pReceiver->start = true;
|
||||
pReceiver->ack = 20;
|
||||
pReceiver->pWriter = (void*)0x11;
|
||||
|
|
|
@ -146,8 +146,8 @@ int32_t SnapshotDoWrite(struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_
|
|||
|
||||
void RestoreFinishCb(struct SSyncFSM* pFsm) { sTrace("==callback== ==RestoreFinishCb== pFsm:%p", pFsm); }
|
||||
|
||||
void ReConfigCb(struct SSyncFSM* pFsm, SSyncCfg newCfg, SReConfigCbMeta cbMeta) {
|
||||
char* s = syncCfg2Str(&newCfg);
|
||||
void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta cbMeta) {
|
||||
char* s = syncCfg2Str(&(cbMeta.newCfg));
|
||||
sTrace("==callback== ==ReConfigCb== flag:0x%lX, isDrop:%d, index:%ld, code:%d, currentTerm:%lu, term:%lu, newCfg:%s",
|
||||
cbMeta.flag, cbMeta.isDrop, cbMeta.index, cbMeta.code, cbMeta.currentTerm, cbMeta.term, s);
|
||||
taosMemoryFree(s);
|
||||
|
@ -235,7 +235,6 @@ int64_t createSyncNode(int32_t replicaNum, int32_t myIndex, int32_t vgId, SWal*
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
int64_t rid = syncOpen(&syncInfo);
|
||||
assert(rid > 0);
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue