Merge remote-tracking branch 'origin/3.0' into fix/TD-31858

This commit is contained in:
yihaoDeng 2024-09-12 10:07:20 +08:00
commit d93d2413b9
278 changed files with 17804 additions and 7247 deletions

View File

@ -4,7 +4,7 @@ sidebar_label: Taos-Explorer
description: User guide about taosExplorer description: User guide about taosExplorer
--- ---
taos-explorer is a web service which provides GUI based interactive database management tool. taos-explorer is a web service which provides GUI based interactive database management tool. To ensure the best experience when accessing taosExplorer, please use Chrome version 79 or higher, Edge version 79 or higher.
## Install ## Install

View File

@ -4,7 +4,7 @@ sidebar_label: taosExplorer
toc_max_heading_level: 4 toc_max_heading_level: 4
--- ---
taosExplorer 是一个为用户提供 TDengine 实例的可视化管理交互工具的 web 服务。本节主要讲述其安装和部署。它的各项功能都是基于简单易上手的图形界面,可以直接尝试,如果有需要也可以考高级功能和运维指南中的相关内容。 taosExplorer 是一个为用户提供 TDengine 实例的可视化管理交互工具的 web 服务。本节主要讲述其安装和部署。它的各项功能都是基于简单易上手的图形界面,可以直接尝试,如果有需要也可以考高级功能和运维指南中的相关内容。为了确保访问 taosExplorer 的最佳体验,请使用 Chrome 79 及以上版本,或 Edge 79 及以上版本。
## 安装 ## 安装

View File

@ -41,15 +41,13 @@ table_option: {
**使用说明** **使用说明**
1. 表(列)名命名规则参见[名称命名规则](./19-limit.md#名称命名规则)。
1. 表名最大长度为 192。
1. 表的第一个字段必须是 TIMESTAMP并且系统自动将其设为主键。 1. 表的第一个字段必须是 TIMESTAMP并且系统自动将其设为主键。
2. 除时间戳主键列之外,还可以通过 PRIMARY KEY 关键字指定第二列为额外的主键列。被指定为主键列的第二列必须为整型或字符串类型varchar 1. 除时间戳主键列之外,还可以通过 PRIMARY KEY 关键字指定第二列为额外的主键列。被指定为主键列的第二列必须为整型或字符串类型varchar
3. 表名最大长度为 192。 1. 表的每行长度不能超过 48KB从 3.0.5.0 版本开始为 64KB;(注意:每个 BINARY/NCHAR/GEOMETRY 类型的列还会额外占用 2 个字节的存储位置)。
4. 表的每行长度不能超过 48KB从 3.0.5.0 版本开始为 64KB;(注意:每个 BINARY/NCHAR/GEOMETRY 类型的列还会额外占用 2 个字节的存储位置)。 1. 使用数据类型 BINARY/NCHAR/GEOMETRY需指定其最长的字节数如 BINARY(20),表示 20 字节。
5. 子表名只能由字母、数字和下划线组成,且不能以数字开头,不区分大小写。 1. 关于 `ENCODE``COMPRESS` 的使用,请参考[按列压缩](../compress)
6. 使用数据类型 BINARY/NCHAR/GEOMETRY需指定其最长的字节数如 BINARY(20),表示 20 字节。
7. 为了兼容支持更多形式的表名TDengine 引入新的转义符 "\`",可以让表名与关键词不冲突,同时不受限于上述表名称合法性约束检查。但是同样具有长度限制要求。使用转义字符以后,不再对转义字符中的内容进行大小写统一,
例如:\`aBc\` 和 \`abc\` 是不同的表名,但是 abc 和 aBc 是相同的表名。
8. 关于 `ENCODE``COMPRESS` 的使用,请参考[按列压缩](../compress)
**参数说明** **参数说明**

View File

@ -6,13 +6,16 @@ description: 合法字符集和命名中的限制规则
## 名称命名规则 ## 名称命名规则
1. 合法字符:英文字符、数字和下划线 1. 合法字符:英文字符、数字和下划线。
2. 允许英文字符或下划线开头,不允许以数字开头 1. 允许英文字符或下划线开头,不允许以数字开头。
3. 不区分大小写 1. 不区分大小写。
4. 转义后表(列)名规则: 1. 不能是[保留关键字](./20-keywords.md)。
为了兼容支持更多形式的表TDengine 引入新的转义符 "`"。使用转义字符以后,不再对转义字符中的内容进行大小写统一,即可以保留用户指定表名中的大小写属性。 1. 转义后表(列)名规则:
为了兼容支持更多形式的表TDengine 引入新的转义符 "`"。使用转义字符以后:
例如:\`aBc\` 和 \`abc\` 是不同的表(列)名,但是 abc 和 aBc 是相同的表(列)名。 - 不再对转义字符中的内容进行大小写统一,即可以保留用户指定表名中的大小写属性,例如:\`aBc\` 和 \`abc\` 是不同的表(列)名,但是 abc 和 aBc 是相同的表(列)名。
- 可以创建包含字母、数字和下划线以外字符的表(列)名,例如:\`abc@TD\`,但是转义后名称中仍然不能包含`.`,否则会提示`The table name cannot contain '.'`。
- 可以创建以数字开头的表(列)名,例如\`1970\`。
- 可以创建以[保留关键字](./20-keywords.md)命名的表(列)名,例如\`select\`。
## 密码合法字符集 ## 密码合法字符集
@ -37,22 +40,3 @@ description: 合法字符集和命名中的限制规则
- 用户密码的最大长度是 31 字节 - 用户密码的最大长度是 31 字节
- 总数据行数取决于可用资源 - 总数据行数取决于可用资源
- 单个数据库的虚拟结点数上限为 1024 - 单个数据库的虚拟结点数上限为 1024
## 表(列)名合法性说明
### TDengine 中的表(列)名命名规则如下:
只能由字母、数字、下划线构成,数字不能在首位,长度不能超过 192 字节,不区分大小写。这里表名称不包括数据库名的前缀和分隔符。
### 转义后表(列)名规则:
为了兼容支持更多形式的表TDengine 引入新的转义符 "`",可以避免表名与关键词的冲突,转义符不计入表名的长度。
转义后的表(列)名同样受到长度限制要求,且长度计算的时候不计算转义符。使用转义字符以后,不再对转义字符中的内容进行大小写统一。
例如:
\`aBc\` 和 \`abc\` 是不同的表(列)名,但是 abc 和 aBc 是相同的表(列)名。
:::note
转义字符中的内容必须符合命名规则中的字符约束。
:::

View File

@ -51,7 +51,7 @@ typedef void TAOS_SUB;
#define TSDB_DATA_TYPE_BLOB 18 // binary #define TSDB_DATA_TYPE_BLOB 18 // binary
#define TSDB_DATA_TYPE_MEDIUMBLOB 19 #define TSDB_DATA_TYPE_MEDIUMBLOB 19
#define TSDB_DATA_TYPE_BINARY TSDB_DATA_TYPE_VARCHAR // string #define TSDB_DATA_TYPE_BINARY TSDB_DATA_TYPE_VARCHAR // string
#define TSDB_DATA_TYPE_GEOMETRY 20 // geometry #define TSDB_DATA_TYPE_GEOMETRY 20 // geometry
#define TSDB_DATA_TYPE_MAX 21 #define TSDB_DATA_TYPE_MAX 21
typedef enum { typedef enum {
@ -168,7 +168,7 @@ DLL_EXPORT const char *taos_data_type(int type);
DLL_EXPORT TAOS_STMT *taos_stmt_init(TAOS *taos); DLL_EXPORT TAOS_STMT *taos_stmt_init(TAOS *taos);
DLL_EXPORT TAOS_STMT *taos_stmt_init_with_reqid(TAOS *taos, int64_t reqid); DLL_EXPORT TAOS_STMT *taos_stmt_init_with_reqid(TAOS *taos, int64_t reqid);
DLL_EXPORT TAOS_STMT *taos_stmt_init_with_options(TAOS *taos, TAOS_STMT_OPTIONS* options); DLL_EXPORT TAOS_STMT *taos_stmt_init_with_options(TAOS *taos, TAOS_STMT_OPTIONS *options);
DLL_EXPORT int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length); 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_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_tbname(TAOS_STMT *stmt, const char *name);
@ -193,6 +193,49 @@ 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(TAOS_STMT *stmt);
DLL_EXPORT int taos_stmt_affected_rows_once(TAOS_STMT *stmt); DLL_EXPORT int taos_stmt_affected_rows_once(TAOS_STMT *stmt);
typedef void TAOS_STMT2;
typedef enum TAOS_FIELD_T {
TAOS_FIELD_COL = 1,
TAOS_FIELD_TAG,
TAOS_FIELD_QUERY,
TAOS_FIELD_TBNAME,
} TAOS_FIELD_T;
typedef struct TAOS_STMT2_OPTION {
int64_t reqid;
bool singleStbInsert;
bool singleTableBindOnce;
__taos_async_fn_t asyncExecFn;
void *userdata;
} TAOS_STMT2_OPTION;
typedef struct TAOS_STMT2_BIND {
int buffer_type;
void *buffer;
int32_t *length;
char *is_null;
int num;
} TAOS_STMT2_BIND;
typedef struct TAOS_STMT2_BINDV {
int count;
char **tbnames;
TAOS_STMT2_BIND **tags;
TAOS_STMT2_BIND **bind_cols;
} TAOS_STMT2_BINDV;
DLL_EXPORT TAOS_STMT2 *taos_stmt2_init(TAOS *taos, TAOS_STMT2_OPTION *option);
DLL_EXPORT int taos_stmt2_prepare(TAOS_STMT2 *stmt, const char *sql, unsigned long length);
DLL_EXPORT int taos_stmt2_bind_param(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t col_idx);
DLL_EXPORT int taos_stmt2_exec(TAOS_STMT2 *stmt, int *affected_rows);
DLL_EXPORT int taos_stmt2_close(TAOS_STMT2 *stmt);
DLL_EXPORT int taos_stmt2_is_insert(TAOS_STMT2 *stmt, int *insert);
DLL_EXPORT int taos_stmt2_get_fields(TAOS_STMT2 *stmt, TAOS_FIELD_T field_type, int *count, TAOS_FIELD_E **fields);
DLL_EXPORT void taos_stmt2_free_fields(TAOS_STMT2 *stmt, TAOS_FIELD_E *fields);
DLL_EXPORT TAOS_RES *taos_stmt2_result(TAOS_STMT2 *stmt);
DLL_EXPORT char *taos_stmt2_error(TAOS_STMT2 *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_RES *taos_query_with_reqid(TAOS *taos, const char *sql, int64_t reqId); DLL_EXPORT TAOS_RES *taos_query_with_reqid(TAOS *taos, const char *sql, int64_t reqId);
@ -246,14 +289,15 @@ DLL_EXPORT void taos_set_hb_quit(int8_t quitByKill);
DLL_EXPORT int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t fp, void *param, int type); DLL_EXPORT int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t fp, void *param, int type);
typedef void (*__taos_async_whitelist_fn_t)(void *param, int code, TAOS *taos, int numOfWhiteLists, uint64_t* pWhiteLists); typedef void (*__taos_async_whitelist_fn_t)(void *param, int code, TAOS *taos, int numOfWhiteLists,
uint64_t *pWhiteLists);
DLL_EXPORT void taos_fetch_whitelist_a(TAOS *taos, __taos_async_whitelist_fn_t fp, void *param); DLL_EXPORT void taos_fetch_whitelist_a(TAOS *taos, __taos_async_whitelist_fn_t fp, void *param);
typedef enum { typedef enum {
TAOS_CONN_MODE_BI = 0, TAOS_CONN_MODE_BI = 0,
} TAOS_CONN_MODE; } TAOS_CONN_MODE;
DLL_EXPORT int taos_set_conn_mode(TAOS* taos, int mode, int value); DLL_EXPORT int taos_set_conn_mode(TAOS *taos, int mode, int value);
/* --------------------------schemaless INTERFACE------------------------------- */ /* --------------------------schemaless INTERFACE------------------------------- */
DLL_EXPORT TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int protocol, int precision); DLL_EXPORT TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int protocol, int precision);
@ -271,10 +315,13 @@ DLL_EXPORT TAOS_RES *taos_schemaless_insert_raw_ttl(TAOS *taos, char *lines, int
int precision, int32_t ttl); int precision, int32_t ttl);
DLL_EXPORT TAOS_RES *taos_schemaless_insert_raw_ttl_with_reqid(TAOS *taos, char *lines, int len, int32_t *totalRows, DLL_EXPORT TAOS_RES *taos_schemaless_insert_raw_ttl_with_reqid(TAOS *taos, char *lines, int len, int32_t *totalRows,
int protocol, int precision, int32_t ttl, int64_t reqid); int protocol, int precision, int32_t ttl, int64_t reqid);
DLL_EXPORT TAOS_RES *taos_schemaless_insert_raw_ttl_with_reqid_tbname_key(TAOS *taos, char *lines, int len, int32_t *totalRows, DLL_EXPORT TAOS_RES *taos_schemaless_insert_raw_ttl_with_reqid_tbname_key(TAOS *taos, char *lines, int len,
int protocol, int precision, int32_t ttl, int64_t reqid, char *tbnameKey); int32_t *totalRows, int protocol,
DLL_EXPORT TAOS_RES *taos_schemaless_insert_ttl_with_reqid_tbname_key(TAOS *taos, char *lines[], int numLines, int protocol, int precision, int32_t ttl, int64_t reqid,
int precision, int32_t ttl, int64_t reqid, char *tbnameKey); char *tbnameKey);
DLL_EXPORT TAOS_RES *taos_schemaless_insert_ttl_with_reqid_tbname_key(TAOS *taos, char *lines[], int numLines,
int protocol, int precision, int32_t ttl,
int64_t reqid, char *tbnameKey);
/* --------------------------TMQ INTERFACE------------------------------- */ /* --------------------------TMQ INTERFACE------------------------------- */
typedef struct tmq_t tmq_t; typedef struct tmq_t tmq_t;
@ -320,14 +367,17 @@ DLL_EXPORT int32_t tmq_unsubscribe(tmq_t *tmq);
DLL_EXPORT int32_t tmq_subscription(tmq_t *tmq, tmq_list_t **topics); DLL_EXPORT int32_t tmq_subscription(tmq_t *tmq, tmq_list_t **topics);
DLL_EXPORT TAOS_RES *tmq_consumer_poll(tmq_t *tmq, int64_t timeout); DLL_EXPORT TAOS_RES *tmq_consumer_poll(tmq_t *tmq, int64_t timeout);
DLL_EXPORT int32_t tmq_consumer_close(tmq_t *tmq); DLL_EXPORT int32_t tmq_consumer_close(tmq_t *tmq);
DLL_EXPORT int32_t tmq_commit_sync(tmq_t *tmq, const TAOS_RES *msg); //Commit the msgs offset + 1 DLL_EXPORT int32_t tmq_commit_sync(tmq_t *tmq, const TAOS_RES *msg); // Commit the msgs offset + 1
DLL_EXPORT void tmq_commit_async(tmq_t *tmq, const TAOS_RES *msg, tmq_commit_cb *cb, void *param); DLL_EXPORT void tmq_commit_async(tmq_t *tmq, const TAOS_RES *msg, tmq_commit_cb *cb, void *param);
DLL_EXPORT int32_t tmq_commit_offset_sync(tmq_t *tmq, const char *pTopicName, int32_t vgId, int64_t offset); DLL_EXPORT int32_t tmq_commit_offset_sync(tmq_t *tmq, const char *pTopicName, int32_t vgId, int64_t offset);
DLL_EXPORT void tmq_commit_offset_async(tmq_t *tmq, const char *pTopicName, int32_t vgId, int64_t offset, tmq_commit_cb *cb, void *param); DLL_EXPORT void tmq_commit_offset_async(tmq_t *tmq, const char *pTopicName, int32_t vgId, int64_t offset,
DLL_EXPORT int32_t tmq_get_topic_assignment(tmq_t *tmq, const char *pTopicName, tmq_topic_assignment **assignment,int32_t *numOfAssignment); tmq_commit_cb *cb, void *param);
DLL_EXPORT void tmq_free_assignment(tmq_topic_assignment* pAssignment); DLL_EXPORT int32_t tmq_get_topic_assignment(tmq_t *tmq, const char *pTopicName, tmq_topic_assignment **assignment,
int32_t *numOfAssignment);
DLL_EXPORT void tmq_free_assignment(tmq_topic_assignment *pAssignment);
DLL_EXPORT int32_t tmq_offset_seek(tmq_t *tmq, const char *pTopicName, int32_t vgId, int64_t offset); DLL_EXPORT int32_t tmq_offset_seek(tmq_t *tmq, const char *pTopicName, int32_t vgId, int64_t offset);
DLL_EXPORT int64_t tmq_position(tmq_t *tmq, const char *pTopicName, int32_t vgId); // The current offset is the offset of the last consumed message + 1 DLL_EXPORT int64_t tmq_position(tmq_t *tmq, const char *pTopicName,
int32_t vgId); // The current offset is the offset of the last consumed message + 1
DLL_EXPORT int64_t tmq_committed(tmq_t *tmq, const char *pTopicName, int32_t vgId); DLL_EXPORT int64_t tmq_committed(tmq_t *tmq, const char *pTopicName, int32_t vgId);
DLL_EXPORT TAOS *tmq_get_connect(tmq_t *tmq); DLL_EXPORT TAOS *tmq_get_connect(tmq_t *tmq);
@ -336,7 +386,7 @@ DLL_EXPORT tmq_res_t tmq_get_res_type(TAOS_RES *res);
DLL_EXPORT const char *tmq_get_topic_name(TAOS_RES *res); DLL_EXPORT const char *tmq_get_topic_name(TAOS_RES *res);
DLL_EXPORT const char *tmq_get_db_name(TAOS_RES *res); DLL_EXPORT const char *tmq_get_db_name(TAOS_RES *res);
DLL_EXPORT int32_t tmq_get_vgroup_id(TAOS_RES *res); DLL_EXPORT int32_t tmq_get_vgroup_id(TAOS_RES *res);
DLL_EXPORT int64_t tmq_get_vgroup_offset(TAOS_RES* res); DLL_EXPORT int64_t tmq_get_vgroup_offset(TAOS_RES *res);
DLL_EXPORT const char *tmq_err2str(int32_t code); DLL_EXPORT const char *tmq_err2str(int32_t code);
/* ------------------------------ TAOSX -----------------------------------*/ /* ------------------------------ TAOSX -----------------------------------*/
@ -346,15 +396,16 @@ typedef struct tmq_raw_data {
uint16_t raw_type; uint16_t raw_type;
} tmq_raw_data; } tmq_raw_data;
DLL_EXPORT int32_t tmq_get_raw(TAOS_RES *res, tmq_raw_data *raw); DLL_EXPORT int32_t tmq_get_raw(TAOS_RES *res, tmq_raw_data *raw);
DLL_EXPORT int32_t tmq_write_raw(TAOS *taos, tmq_raw_data raw); DLL_EXPORT int32_t tmq_write_raw(TAOS *taos, tmq_raw_data raw);
DLL_EXPORT int taos_write_raw_block(TAOS *taos, int numOfRows, char *pData, const char *tbname); DLL_EXPORT int taos_write_raw_block(TAOS *taos, int numOfRows, char *pData, const char *tbname);
DLL_EXPORT int taos_write_raw_block_with_reqid(TAOS *taos, int numOfRows, char *pData, const char *tbname, int64_t reqid); DLL_EXPORT int taos_write_raw_block_with_reqid(TAOS *taos, int numOfRows, char *pData, const char *tbname,
DLL_EXPORT int taos_write_raw_block_with_fields(TAOS *taos, int rows, char *pData, const char *tbname, int64_t reqid);
TAOS_FIELD *fields, int numFields); DLL_EXPORT int taos_write_raw_block_with_fields(TAOS *taos, int rows, char *pData, const char *tbname,
DLL_EXPORT int taos_write_raw_block_with_fields_with_reqid(TAOS *taos, int rows, char *pData, const char *tbname, TAOS_FIELD *fields, int numFields);
TAOS_FIELD *fields, int numFields, int64_t reqid); DLL_EXPORT int taos_write_raw_block_with_fields_with_reqid(TAOS *taos, int rows, char *pData, const char *tbname,
DLL_EXPORT void tmq_free_raw(tmq_raw_data raw); TAOS_FIELD *fields, int numFields, int64_t reqid);
DLL_EXPORT void tmq_free_raw(tmq_raw_data raw);
// Returning null means error. Returned result need to be freed by tmq_free_json_meta // Returning null means error. Returned result need to be freed by tmq_free_json_meta
DLL_EXPORT char *tmq_get_json_meta(TAOS_RES *res); DLL_EXPORT char *tmq_get_json_meta(TAOS_RES *res);
@ -370,7 +421,7 @@ typedef enum {
} TSDB_SERVER_STATUS; } TSDB_SERVER_STATUS;
DLL_EXPORT TSDB_SERVER_STATUS taos_check_server_status(const char *fqdn, int port, char *details, int maxlen); DLL_EXPORT TSDB_SERVER_STATUS taos_check_server_status(const char *fqdn, int port, char *details, int maxlen);
DLL_EXPORT char* getBuildInfo(); DLL_EXPORT char *getBuildInfo();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -110,6 +110,8 @@ typedef struct SFirstLastRes {
int32_t pkBytes; int32_t pkBytes;
int8_t pkType; int8_t pkType;
STuplePos pos; STuplePos pos;
STuplePos nullTuplePos;
bool nullTupleSaved;
char buf[]; char buf[];
} SFirstLastRes; } SFirstLastRes;

View File

@ -41,7 +41,7 @@ typedef struct SBlockOrderInfo {
#define BMCharPos(bm_, r_) ((bm_)[(r_) >> NBIT]) #define BMCharPos(bm_, r_) ((bm_)[(r_) >> NBIT])
#define colDataIsNull_f(bm_, r_) ((BMCharPos(bm_, r_) & (1u << (7u - BitPos(r_)))) == (1u << (7u - BitPos(r_)))) #define colDataIsNull_f(bm_, r_) ((BMCharPos(bm_, r_) & (1u << (7u - BitPos(r_)))) == (1u << (7u - BitPos(r_))))
#define QRY_OPTR_CHECK(_o) \ #define QRY_PARAM_CHECK(_o) \
do { \ do { \
if ((_o) == NULL) { \ if ((_o) == NULL) { \
return TSDB_CODE_INVALID_PARA; \ return TSDB_CODE_INVALID_PARA; \
@ -233,6 +233,7 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo);
* @brief find how many rows already in order start from first row * @brief find how many rows already in order start from first row
*/ */
int32_t blockDataGetSortedRows(SSDataBlock* pDataBlock, SArray* pOrderInfo); int32_t blockDataGetSortedRows(SSDataBlock* pDataBlock, SArray* pOrderInfo);
void blockDataCheck(const SSDataBlock* pDataBlock, bool forceChk);
int32_t colInfoDataEnsureCapacity(SColumnInfoData* pColumn, uint32_t numOfRows, bool clearPayload); int32_t colInfoDataEnsureCapacity(SColumnInfoData* pColumn, uint32_t numOfRows, bool clearPayload);
int32_t blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows); int32_t blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows);

View File

@ -378,6 +378,19 @@ typedef struct {
int32_t tRowBuildFromBind(SBindInfo *infos, int32_t numOfInfos, bool infoSorted, const STSchema *pTSchema, int32_t tRowBuildFromBind(SBindInfo *infos, int32_t numOfInfos, bool infoSorted, const STSchema *pTSchema,
SArray *rowArray); SArray *rowArray);
// stmt2 binding
int32_t tColDataAddValueByBind2(SColData *pColData, TAOS_STMT2_BIND *pBind, int32_t buffMaxLen);
typedef struct {
int32_t columnId;
int32_t type;
int32_t bytes;
TAOS_STMT2_BIND *bind;
} SBindInfo2;
int32_t tRowBuildFromBind2(SBindInfo2 *infos, int32_t numOfInfos, bool infoSorted, const STSchema *pTSchema,
SArray *rowArray);
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -74,26 +74,26 @@ int32_t tGetMachineId(char **result);
#ifdef TD_ENTERPRISE #ifdef TD_ENTERPRISE
#define GRANTS_SCHEMA \ #define GRANTS_SCHEMA \
static const SSysDbTableSchema grantsSchema[] = { \ static const SSysDbTableSchema grantsSchema[] = { \
{.name = "version", .bytes = 32 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "version", .bytes = 64 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
{.name = "expire_time", .bytes = 19 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "expire_time", .bytes = 19 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
{.name = "service_time", .bytes = 19 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "service_time", .bytes = 19 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
{.name = "expired", .bytes = 5 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "expired", .bytes = 5 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
{.name = "state", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "state", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
{.name = "timeseries", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "timeseries", .bytes = 43 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
{.name = "dnodes", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "dnodes", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
{.name = "cpu_cores", .bytes = 13 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "cpu_cores", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
} }
#else #else
#define GRANTS_SCHEMA \ #define GRANTS_SCHEMA \
static const SSysDbTableSchema grantsSchema[] = { \ static const SSysDbTableSchema grantsSchema[] = { \
{.name = "version", .bytes = 32 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "version", .bytes = 64 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
{.name = "expire_time", .bytes = 19 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "expire_time", .bytes = 19 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
{.name = "service_time", .bytes = 19 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "service_time", .bytes = 19 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
{.name = "expired", .bytes = 5 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "expired", .bytes = 5 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
{.name = "state", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "state", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
{.name = "timeseries", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "timeseries", .bytes = 43 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
{.name = "dnodes", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "dnodes", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
{.name = "cpu_cores", .bytes = 13 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \ {.name = "cpu_cores", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
} }
#endif #endif
// #define GRANT_CFG_ADD // #define GRANT_CFG_ADD

View File

@ -286,117 +286,118 @@
#define TK_FOR 268 #define TK_FOR 268
#define TK_NOW 269 #define TK_NOW 269
#define TK_TODAY 270 #define TK_TODAY 270
#define TK_SUBSTR 271 #define TK_RAND 271
#define TK_SUBSTRING 272 #define TK_SUBSTR 272
#define TK_BOTH 273 #define TK_SUBSTRING 273
#define TK_TRAILING 274 #define TK_BOTH 274
#define TK_LEADING 275 #define TK_TRAILING 275
#define TK_TIMEZONE 276 #define TK_LEADING 276
#define TK_CLIENT_VERSION 277 #define TK_TIMEZONE 277
#define TK_SERVER_VERSION 278 #define TK_CLIENT_VERSION 278
#define TK_SERVER_STATUS 279 #define TK_SERVER_VERSION 279
#define TK_CURRENT_USER 280 #define TK_SERVER_STATUS 280
#define TK_PI 281 #define TK_CURRENT_USER 281
#define TK_CASE 282 #define TK_PI 282
#define TK_WHEN 283 #define TK_CASE 283
#define TK_THEN 284 #define TK_WHEN 284
#define TK_ELSE 285 #define TK_THEN 285
#define TK_BETWEEN 286 #define TK_ELSE 286
#define TK_IS 287 #define TK_BETWEEN 287
#define TK_NK_LT 288 #define TK_IS 288
#define TK_NK_GT 289 #define TK_NK_LT 289
#define TK_NK_LE 290 #define TK_NK_GT 290
#define TK_NK_GE 291 #define TK_NK_LE 291
#define TK_NK_NE 292 #define TK_NK_GE 292
#define TK_MATCH 293 #define TK_NK_NE 293
#define TK_NMATCH 294 #define TK_MATCH 294
#define TK_CONTAINS 295 #define TK_NMATCH 295
#define TK_JOIN 296 #define TK_CONTAINS 296
#define TK_INNER 297 #define TK_JOIN 297
#define TK_LEFT 298 #define TK_INNER 298
#define TK_RIGHT 299 #define TK_LEFT 299
#define TK_OUTER 300 #define TK_RIGHT 300
#define TK_SEMI 301 #define TK_OUTER 301
#define TK_ANTI 302 #define TK_SEMI 302
#define TK_ASOF 303 #define TK_ANTI 303
#define TK_WINDOW 304 #define TK_ASOF 304
#define TK_WINDOW_OFFSET 305 #define TK_WINDOW 305
#define TK_JLIMIT 306 #define TK_WINDOW_OFFSET 306
#define TK_SELECT 307 #define TK_JLIMIT 307
#define TK_NK_HINT 308 #define TK_SELECT 308
#define TK_DISTINCT 309 #define TK_NK_HINT 309
#define TK_WHERE 310 #define TK_DISTINCT 310
#define TK_PARTITION 311 #define TK_WHERE 311
#define TK_BY 312 #define TK_PARTITION 312
#define TK_SESSION 313 #define TK_BY 313
#define TK_STATE_WINDOW 314 #define TK_SESSION 314
#define TK_EVENT_WINDOW 315 #define TK_STATE_WINDOW 315
#define TK_COUNT_WINDOW 316 #define TK_EVENT_WINDOW 316
#define TK_SLIDING 317 #define TK_COUNT_WINDOW 317
#define TK_FILL 318 #define TK_SLIDING 318
#define TK_VALUE 319 #define TK_FILL 319
#define TK_VALUE_F 320 #define TK_VALUE 320
#define TK_NONE 321 #define TK_VALUE_F 321
#define TK_PREV 322 #define TK_NONE 322
#define TK_NULL_F 323 #define TK_PREV 323
#define TK_LINEAR 324 #define TK_NULL_F 324
#define TK_NEXT 325 #define TK_LINEAR 325
#define TK_HAVING 326 #define TK_NEXT 326
#define TK_RANGE 327 #define TK_HAVING 327
#define TK_EVERY 328 #define TK_RANGE 328
#define TK_ORDER 329 #define TK_EVERY 329
#define TK_SLIMIT 330 #define TK_ORDER 330
#define TK_SOFFSET 331 #define TK_SLIMIT 331
#define TK_LIMIT 332 #define TK_SOFFSET 332
#define TK_OFFSET 333 #define TK_LIMIT 333
#define TK_ASC 334 #define TK_OFFSET 334
#define TK_NULLS 335 #define TK_ASC 335
#define TK_ABORT 336 #define TK_NULLS 336
#define TK_AFTER 337 #define TK_ABORT 337
#define TK_ATTACH 338 #define TK_AFTER 338
#define TK_BEFORE 339 #define TK_ATTACH 339
#define TK_BEGIN 340 #define TK_BEFORE 340
#define TK_BITAND 341 #define TK_BEGIN 341
#define TK_BITNOT 342 #define TK_BITAND 342
#define TK_BITOR 343 #define TK_BITNOT 343
#define TK_BLOCKS 344 #define TK_BITOR 344
#define TK_CHANGE 345 #define TK_BLOCKS 345
#define TK_COMMA 346 #define TK_CHANGE 346
#define TK_CONCAT 347 #define TK_COMMA 347
#define TK_CONFLICT 348 #define TK_CONCAT 348
#define TK_COPY 349 #define TK_CONFLICT 349
#define TK_DEFERRED 350 #define TK_COPY 350
#define TK_DELIMITERS 351 #define TK_DEFERRED 351
#define TK_DETACH 352 #define TK_DELIMITERS 352
#define TK_DIVIDE 353 #define TK_DETACH 353
#define TK_DOT 354 #define TK_DIVIDE 354
#define TK_EACH 355 #define TK_DOT 355
#define TK_FAIL 356 #define TK_EACH 356
#define TK_GLOB 357 #define TK_FAIL 357
#define TK_ID 358 #define TK_GLOB 358
#define TK_IMMEDIATE 359 #define TK_ID 359
#define TK_IMPORT 360 #define TK_IMMEDIATE 360
#define TK_INITIALLY 361 #define TK_IMPORT 361
#define TK_INSTEAD 362 #define TK_INITIALLY 362
#define TK_ISNULL 363 #define TK_INSTEAD 363
#define TK_MODULES 364 #define TK_ISNULL 364
#define TK_NK_BITNOT 365 #define TK_MODULES 365
#define TK_NK_SEMI 366 #define TK_NK_BITNOT 366
#define TK_NOTNULL 367 #define TK_NK_SEMI 367
#define TK_OF 368 #define TK_NOTNULL 368
#define TK_PLUS 369 #define TK_OF 369
#define TK_PRIVILEGE 370 #define TK_PLUS 370
#define TK_RAISE 371 #define TK_PRIVILEGE 371
#define TK_RESTRICT 372 #define TK_RAISE 372
#define TK_ROW 373 #define TK_RESTRICT 373
#define TK_STAR 374 #define TK_ROW 374
#define TK_STATEMENT 375 #define TK_STAR 375
#define TK_STRICT 376 #define TK_STATEMENT 376
#define TK_STRING 377 #define TK_STRICT 377
#define TK_TIMES 378 #define TK_STRING 378
#define TK_VALUES 379 #define TK_TIMES 379
#define TK_VARIABLE 380 #define TK_VALUES 380
#define TK_WAL 381 #define TK_VARIABLE 381
#define TK_WAL 382
#define TK_NK_SPACE 600 #define TK_NK_SPACE 600
#define TK_NK_COMMENT 601 #define TK_NK_COMMENT 601

View File

@ -29,5 +29,6 @@ int32_t qExecExplainBegin(SQueryPlan *pDag, SExplainCtx **pCtx, int64_t startTs)
int32_t qExecExplainEnd(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp); int32_t qExecExplainEnd(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp);
int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t groupId, SRetrieveTableRsp **pRsp); int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t groupId, SRetrieveTableRsp **pRsp);
void qExplainFreeCtx(SExplainCtx *pCtx); void qExplainFreeCtx(SExplainCtx *pCtx);
int32_t formatDurationOrKeep(char* buffer, int32_t timeInMinutes);
#endif #endif

View File

@ -166,6 +166,8 @@ int32_t qExecTaskOpt(qTaskInfo_t tinfo, SArray* pResList, uint64_t* useconds, bo
int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pBlock, uint64_t* useconds); int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pBlock, uint64_t* useconds);
void qResetTaskCode(qTaskInfo_t tinfo);
void qCleanExecTaskBlockBuf(qTaskInfo_t tinfo); void qCleanExecTaskBlockBuf(qTaskInfo_t tinfo);
/** /**

View File

@ -191,6 +191,8 @@ typedef struct SFunctionNode {
bool hasOriginalFunc; bool hasOriginalFunc;
int32_t originalFuncId; int32_t originalFuncId;
ETrimType trimType; ETrimType trimType;
bool hasSMA;
bool dual; // whether select stmt without from stmt, true for without.
} SFunctionNode; } SFunctionNode;
typedef struct STableNode { typedef struct STableNode {

View File

@ -20,9 +20,9 @@
extern "C" { extern "C" {
#endif #endif
#include "catalog.h"
#include "query.h" #include "query.h"
#include "querynodes.h" #include "querynodes.h"
#include "catalog.h"
typedef struct SStmtCallback { typedef struct SStmtCallback {
TAOS_STMT* pStmt; TAOS_STMT* pStmt;
@ -37,15 +37,15 @@ typedef enum {
} SParseResType; } SParseResType;
typedef struct SParseSchemaRes { typedef struct SParseSchemaRes {
int8_t precision; int8_t precision;
int32_t numOfCols; int32_t numOfCols;
SSchema* pSchema; SSchema* pSchema;
} SParseSchemaRes; } SParseSchemaRes;
typedef struct SParseQueryRes { typedef struct SParseQueryRes {
SNode* pQuery; SNode* pQuery;
SCatalogReq* pCatalogReq; SCatalogReq* pCatalogReq;
SMetaData meta; SMetaData meta;
} SParseQueryRes; } SParseQueryRes;
typedef struct SParseSqlRes { typedef struct SParseSqlRes {
@ -124,11 +124,13 @@ int32_t qSetSTableIdForRsma(SNode* pStmt, int64_t uid);
int32_t qInitKeywordsTable(); int32_t qInitKeywordsTable();
void qCleanupKeywordsTable(); void qCleanupKeywordsTable();
int32_t qAppendStmtTableOutput(SQuery* pQuery, SHashObj* pAllVgHash, STableColsData* pTbData, STableDataCxt* pTbCtx, SStbInterlaceInfo* pBuildInfo); int32_t qAppendStmtTableOutput(SQuery* pQuery, SHashObj* pAllVgHash, STableColsData* pTbData, STableDataCxt* pTbCtx,
int32_t qBuildStmtFinOutput(SQuery* pQuery, SHashObj* pAllVgHash, SArray* pVgDataBlocks); SStbInterlaceInfo* pBuildInfo);
//int32_t qBuildStmtOutputFromTbList(SQuery* pQuery, SHashObj* pVgHash, SArray* pBlockList, STableDataCxt* pTbCtx, int32_t tbNum); int32_t qBuildStmtFinOutput(SQuery* pQuery, SHashObj* pAllVgHash, SArray* pVgDataBlocks);
// int32_t qBuildStmtOutputFromTbList(SQuery* pQuery, SHashObj* pVgHash, SArray* pBlockList, STableDataCxt* pTbCtx,
// int32_t tbNum);
int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash); int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash);
int32_t qResetStmtColumns(SArray* pCols, bool deepClear); int32_t qResetStmtColumns(SArray* pCols, bool deepClear);
int32_t qResetStmtDataBlock(STableDataCxt* block, bool keepBuf); int32_t qResetStmtDataBlock(STableDataCxt* block, bool keepBuf);
int32_t qCloneStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, bool reset); int32_t qCloneStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, bool reset);
int32_t qRebuildStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, uint64_t uid, uint64_t suid, int32_t vgId, int32_t qRebuildStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, uint64_t uid, uint64_t suid, int32_t vgId,
@ -139,39 +141,51 @@ int32_t qCloneCurrentTbData(STableDataCxt* pDataBlock, SSubmitTbData** pData
int32_t qStmtBindParams(SQuery* pQuery, TAOS_MULTI_BIND* pParams, int32_t colIdx); int32_t qStmtBindParams(SQuery* pQuery, TAOS_MULTI_BIND* pParams, int32_t colIdx);
int32_t qStmtParseQuerySql(SParseContext* pCxt, SQuery* pQuery); int32_t qStmtParseQuerySql(SParseContext* pCxt, SQuery* pQuery);
int32_t qBindStmtStbColsValue(void* pBlock, SArray* pCols, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen, STSchema** pTSchema, SBindInfo* pBindInfos); int32_t qBindStmtStbColsValue(void* pBlock, SArray* pCols, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen,
STSchema** pTSchema, SBindInfo* pBindInfos);
int32_t qBindStmtColsValue(void* pBlock, SArray* pCols, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen); int32_t qBindStmtColsValue(void* pBlock, SArray* pCols, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen);
int32_t qBindStmtSingleColValue(void* pBlock, SArray* pCols, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen, int32_t colIdx, int32_t qBindStmtSingleColValue(void* pBlock, SArray* pCols, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen,
int32_t rowNum); int32_t colIdx, int32_t rowNum);
int32_t qBuildStmtColFields(void* pDataBlock, int32_t* fieldNum, TAOS_FIELD_E** fields); int32_t qBuildStmtColFields(void* pDataBlock, int32_t* fieldNum, TAOS_FIELD_E** fields);
int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TAOS_FIELD_E** fields); int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TAOS_FIELD_E** fields);
int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const char* sTableName, char* tName, int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const char* sTableName, char* tName,
TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen); TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen);
int32_t qStmtBindParams2(SQuery* pQuery, TAOS_STMT2_BIND* pParams, int32_t colIdx);
int32_t qBindStmtStbColsValue2(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* bind, char* msgBuf, int32_t msgBufLen,
STSchema** pTSchema, SBindInfo2* pBindInfos);
int32_t qBindStmtColsValue2(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* bind, char* msgBuf, int32_t msgBufLen);
int32_t qBindStmtSingleColValue2(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* bind, char* msgBuf, int32_t msgBufLen,
int32_t colIdx, int32_t rowNum);
int32_t qBindStmtTagsValue2(void* pBlock, void* boundTags, int64_t suid, const char* sTableName, char* tName,
TAOS_STMT2_BIND* bind, char* msgBuf, int32_t msgBufLen);
void destroyBoundColumnInfo(void* pBoundInfo); void destroyBoundColumnInfo(void* pBoundInfo);
int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char* msgBuf, int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char* msgBuf,
int32_t msgBufLen); int32_t msgBufLen);
void qDestroyBoundColInfo(void* pInfo); void qDestroyBoundColInfo(void* pInfo);
int32_t smlInitHandle(SQuery** query); int32_t smlInitHandle(SQuery** query);
int32_t smlBuildRow(STableDataCxt* pTableCxt); int32_t smlBuildRow(STableDataCxt* pTableCxt);
int32_t smlBuildCol(STableDataCxt* pTableCxt, SSchema* schema, void* kv, int32_t index); int32_t smlBuildCol(STableDataCxt* pTableCxt, SSchema* schema, void* kv, int32_t index);
int32_t smlInitTableDataCtx(SQuery* query, STableMeta* pTableMeta, STableDataCxt** cxt); int32_t smlInitTableDataCtx(SQuery* query, STableMeta* pTableMeta, STableDataCxt** cxt);
void clearColValArraySml(SArray* pCols); void clearColValArraySml(SArray* pCols);
int32_t smlBindData(SQuery* handle, bool dataFormat, SArray* tags, SArray* colsSchema, SArray* cols, int32_t smlBindData(SQuery* handle, bool dataFormat, SArray* tags, SArray* colsSchema, SArray* cols,
STableMeta* pTableMeta, char* tableName, const char* sTableName, int32_t sTableNameLen, int32_t ttl, STableMeta* pTableMeta, char* tableName, const char* sTableName, int32_t sTableNameLen, int32_t ttl,
char* msgBuf, int32_t msgBufLen); char* msgBuf, int32_t msgBufLen);
int32_t smlBuildOutput(SQuery* handle, SHashObj* pVgHash); int32_t smlBuildOutput(SQuery* handle, SHashObj* pVgHash);
int rawBlockBindData(SQuery *query, STableMeta* pTableMeta, void* data, SVCreateTbReq** pCreateTb, TAOS_FIELD *fields, int rawBlockBindData(SQuery* query, STableMeta* pTableMeta, void* data, SVCreateTbReq** pCreateTb, TAOS_FIELD* fields,
int numFields, bool needChangeLength, char* errstr, int32_t errstrLen); int numFields, bool needChangeLength, char* errstr, int32_t errstrLen);
int32_t rewriteToVnodeModifyOpStmt(SQuery* pQuery, SArray* pBufArray); int32_t rewriteToVnodeModifyOpStmt(SQuery* pQuery, SArray* pBufArray);
int32_t serializeVgroupsCreateTableBatch(SHashObj* pVgroupHashmap, SArray** pOut); int32_t serializeVgroupsCreateTableBatch(SHashObj* pVgroupHashmap, SArray** pOut);
int32_t serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap, SArray** pOut); int32_t serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap, SArray** pOut);
void destoryCatalogReq(SCatalogReq *pCatalogReq); void destoryCatalogReq(SCatalogReq* pCatalogReq);
bool isPrimaryKeyImpl(SNode* pExpr); bool isPrimaryKeyImpl(SNode* pExpr);
int32_t insAppendStmtTableDataCxt(SHashObj* pAllVgHash, STableColsData* pTbData, STableDataCxt* pTbCtx, SStbInterlaceInfo* pBuildInfo); int32_t insAppendStmtTableDataCxt(SHashObj* pAllVgHash, STableColsData* pTbData, STableDataCxt* pTbCtx,
SStbInterlaceInfo* pBuildInfo);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -348,6 +348,8 @@ extern int32_t (*queryBuildMsg[TDMT_MAX])(void* input, char** msg, int32_t msgSi
void* (*mallocFp)(int64_t)); void* (*mallocFp)(int64_t));
extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t msgSize); extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t msgSize);
void* getTaskPoolWorkerCb();
#define SET_META_TYPE_NULL(t) (t) = META_TYPE_NULL_TABLE #define SET_META_TYPE_NULL(t) (t) = META_TYPE_NULL_TABLE
#define SET_META_TYPE_CTABLE(t) (t) = META_TYPE_CTABLE #define SET_META_TYPE_CTABLE(t) (t) = META_TYPE_CTABLE
#define SET_META_TYPE_TABLE(t) (t) = META_TYPE_TABLE #define SET_META_TYPE_TABLE(t) (t) = META_TYPE_TABLE

View File

@ -72,6 +72,7 @@ typedef struct SQWMsg {
int32_t msgLen; int32_t msgLen;
SQWMsgInfo msgInfo; SQWMsgInfo msgInfo;
SRpcHandleInfo connInfo; SRpcHandleInfo connInfo;
void *pWorkerCb;
} SQWMsg; } SQWMsg;
int32_t qWorkerInit(int8_t nodeType, int32_t nodeId, void **qWorkerMgmt, const SMsgCb *pMsgCb); int32_t qWorkerInit(int8_t nodeType, int32_t nodeId, void **qWorkerMgmt, const SMsgCb *pMsgCb);

View File

@ -70,6 +70,7 @@ int32_t modFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu
int32_t signFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); int32_t signFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
int32_t degreesFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); int32_t degreesFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
int32_t radiansFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); int32_t radiansFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
int32_t randFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
/* String functions */ /* String functions */
int32_t lengthFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); int32_t lengthFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);

View File

@ -67,6 +67,7 @@ typedef struct SSchedulerReq {
SExecResult* pExecRes; SExecResult* pExecRes;
void** pFetchRes; void** pFetchRes;
int8_t source; int8_t source;
void* pWorkerCb;
} SSchedulerReq; } SSchedulerReq;
int32_t schedulerInit(void); int32_t schedulerInit(void);

View File

@ -636,7 +636,7 @@ typedef struct SCheckpointConsensusInfo {
int64_t streamId; int64_t streamId;
} SCheckpointConsensusInfo; } SCheckpointConsensusInfo;
int32_t streamSetupScheduleTrigger(SStreamTask* pTask); void streamSetupScheduleTrigger(SStreamTask* pTask);
// dispatch related // dispatch related
int32_t streamProcessDispatchMsg(SStreamTask* pTask, SStreamDispatchReq* pReq, SRpcMsg* pMsg); int32_t streamProcessDispatchMsg(SStreamTask* pTask, SStreamDispatchReq* pReq, SRpcMsg* pMsg);
@ -793,6 +793,7 @@ void streamTaskSetReqConsenChkptId(SStreamTask* pTask, int64_t ts);
int32_t streamTimerGetInstance(tmr_h* pTmr); int32_t streamTimerGetInstance(tmr_h* pTmr);
void streamTmrReset(TAOS_TMR_CALLBACK fp, int32_t mseconds, void* param, void* handle, tmr_h* pTmrId, int32_t vgId, void streamTmrReset(TAOS_TMR_CALLBACK fp, int32_t mseconds, void* param, void* handle, tmr_h* pTmrId, int32_t vgId,
const char* pMsg); const char* pMsg);
void streamTmrStop(tmr_h tmrId);
// checkpoint // checkpoint
int32_t streamProcessCheckpointSourceReq(SStreamTask* pTask, SStreamCheckpointSourceReq* pReq); int32_t streamProcessCheckpointSourceReq(SStreamTask* pTask, SStreamCheckpointSourceReq* pReq);

View File

@ -143,7 +143,7 @@ int32_t taosWriteMsg(TdSocketPtr pSocket, void *ptr, int32_t nbytes);
int32_t taosReadMsg(TdSocketPtr pSocket, void *ptr, int32_t nbytes); int32_t taosReadMsg(TdSocketPtr pSocket, void *ptr, int32_t nbytes);
int32_t taosNonblockwrite(TdSocketPtr pSocket, char *ptr, int32_t nbytes); int32_t taosNonblockwrite(TdSocketPtr pSocket, char *ptr, int32_t nbytes);
int64_t taosCopyFds(TdSocketPtr pSrcSocket, TdSocketPtr pDestSocket, int64_t len); int64_t taosCopyFds(TdSocketPtr pSrcSocket, TdSocketPtr pDestSocket, int64_t len);
void taosWinSocketInit(); int32_t taosWinSocketInit();
/* /*
* set timeout(ms) * set timeout(ms)

View File

@ -35,6 +35,8 @@ extern STaosError errors[];
#define TAOS_DEF_ERROR_CODE(mod, code) ((int32_t)((0x80000000 | ((mod)<<16) | (code)))) #define TAOS_DEF_ERROR_CODE(mod, code) ((int32_t)((0x80000000 | ((mod)<<16) | (code))))
#define TAOS_SYSTEM_ERROR(code) (0x80ff0000 | (code)) #define TAOS_SYSTEM_ERROR(code) (0x80ff0000 | (code))
#define TAOS_SYSTEM_WINAPI_ERROR(code) (0x81ff0000 | (code))
#define TAOS_SYSTEM_WINSOCKET_ERROR(code) (0x82ff0000 | (code))
#define TAOS_SUCCEEDED(err) ((err) >= 0) #define TAOS_SUCCEEDED(err) ((err) >= 0)
#define TAOS_FAILED(err) ((err) < 0) #define TAOS_FAILED(err) ((err) < 0)
@ -153,6 +155,7 @@ int32_t taosGetErrSize();
#define TSDB_CODE_MSG_PREPROCESSED TAOS_DEF_ERROR_CODE(0, 0x0136) // internal #define TSDB_CODE_MSG_PREPROCESSED TAOS_DEF_ERROR_CODE(0, 0x0136) // internal
#define TSDB_CODE_OUT_OF_BUFFER TAOS_DEF_ERROR_CODE(0, 0x0137) #define TSDB_CODE_OUT_OF_BUFFER TAOS_DEF_ERROR_CODE(0, 0x0137)
#define TSDB_CODE_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x0138) #define TSDB_CODE_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x0138)
#define TSDB_CODE_SOCKET_ERROR TAOS_DEF_ERROR_CODE(0, 0x0139)
//client //client
#define TSDB_CODE_TSC_INVALID_OPERATION TAOS_DEF_ERROR_CODE(0, 0x0200) #define TSDB_CODE_TSC_INVALID_OPERATION TAOS_DEF_ERROR_CODE(0, 0x0200)

View File

@ -0,0 +1,235 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_CLIENTSTMT2_H
#define TDENGINE_CLIENTSTMT2_H
#ifdef __cplusplus
extern "C" {
#endif
#include "catalog.h"
/*
typedef enum {
STMT_TYPE_INSERT = 1,
STMT_TYPE_MULTI_INSERT,
STMT_TYPE_QUERY,
} STMT_TYPE;
typedef enum {
STMT_INIT = 1,
STMT_PREPARE,
STMT_SETTBNAME,
STMT_SETTAGS,
STMT_FETCH_FIELDS,
STMT_BIND,
STMT_BIND_COL,
STMT_ADD_BATCH,
STMT_EXECUTE,
STMT_MAX,
} STMT_STATUS;
#define STMT_TABLE_COLS_NUM 1000
typedef struct SStmtTableCache {
STableDataCxt *pDataCtx;
void *boundTags;
} SStmtTableCache;
typedef struct SStmtQueryResInfo {
TAOS_FIELD *fields;
TAOS_FIELD *userFields;
uint32_t numOfCols;
int32_t precision;
} SStmtQueryResInfo;
typedef struct SStmtBindInfo {
bool needParse;
bool inExecCache;
uint64_t tbUid;
uint64_t tbSuid;
int32_t tbVgId;
int32_t sBindRowNum;
int32_t sBindLastIdx;
int8_t tbType;
bool tagsCached;
void *boundTags;
char tbName[TSDB_TABLE_FNAME_LEN];
char tbFName[TSDB_TABLE_FNAME_LEN];
char stbFName[TSDB_TABLE_FNAME_LEN];
SName sname;
char statbName[TSDB_TABLE_FNAME_LEN];
} SStmtBindInfo;
typedef struct SStmtAsyncParam {
STableColsData *pTbData;
void* pStmt;
} SStmtAsyncParam;
typedef struct SStmtExecInfo {
int32_t affectedRows;
SRequestObj *pRequest;
SHashObj *pBlockHash;
STableDataCxt *pCurrBlock;
SSubmitTbData *pCurrTbData;
} SStmtExecInfo;
*/
typedef struct {
bool stbInterlaceMode;
STMT_TYPE type;
STMT_STATUS status;
uint64_t suid;
uint64_t runTimes;
SHashObj *pTableCache; // SHash<SStmtTableCache>
SQuery *pQuery;
char *sqlStr;
int32_t sqlLen;
SArray *nodeList;
SStmtQueryResInfo queryRes;
bool autoCreateTbl;
SHashObj *pVgHash;
SBindInfo2 *pBindInfo;
SStbInterlaceInfo siInfo;
} SStmtSQLInfo2;
/*
typedef struct SStmtStatInfo {
int64_t ctgGetTbMetaNum;
int64_t getCacheTbInfo;
int64_t parseSqlNum;
int64_t bindDataNum;
int64_t setTbNameUs;
int64_t bindDataUs1;
int64_t bindDataUs2;
int64_t bindDataUs3;
int64_t bindDataUs4;
int64_t addBatchUs;
int64_t execWaitUs;
int64_t execUseUs;
} SStmtStatInfo;
typedef struct SStmtQNode {
bool restoreTbCols;
STableColsData tblData;
struct SStmtQNode* next;
} SStmtQNode;
typedef struct SStmtQueue {
bool stopQueue;
SStmtQNode* head;
SStmtQNode* tail;
uint64_t qRemainNum;
} SStmtQueue;
*/
typedef struct {
STscObj *taos;
SCatalog *pCatalog;
int32_t affectedRows;
uint32_t seqId;
uint32_t seqIds[STMT_MAX];
bool bindThreadInUse;
TdThread bindThread;
TAOS_STMT2_OPTION options;
bool stbInterlaceMode;
SStmtQueue queue;
SStmtSQLInfo2 sql;
SStmtExecInfo exec;
SStmtBindInfo bInfo;
int64_t reqid;
int32_t errCode;
tsem_t asyncQuerySem;
SStmtStatInfo stat;
} STscStmt2;
/*
extern char *gStmtStatusStr[];
#define STMT_LOG_SEQ(n) \
do { \
(pStmt)->seqId++; \
(pStmt)->seqIds[n]++; \
STMT_DLOG("the %dth:%d %s", (pStmt)->seqIds[n], (pStmt)->seqId, gStmtStatusStr[n]); \
} while (0)
#define STMT_STATUS_NE(S) (pStmt->sql.status != STMT_##S)
#define STMT_STATUS_EQ(S) (pStmt->sql.status == STMT_##S)
#define STMT_ERR_RET(c) \
do { \
int32_t _code = c; \
if (_code != TSDB_CODE_SUCCESS) { \
terrno = _code; \
pStmt->errCode = _code; \
return _code; \
} \
} while (0)
#define STMT_RET(c) \
do { \
int32_t _code = c; \
if (_code != TSDB_CODE_SUCCESS) { \
terrno = _code; \
pStmt->errCode = _code; \
} \
return _code; \
} while (0)
#define STMT_ERR_JRET(c) \
do { \
code = c; \
if (code != TSDB_CODE_SUCCESS) { \
terrno = code; \
pStmt->errCode = code; \
goto _return; \
} \
} while (0)
#define STMT_ERRI_JRET(c) \
do { \
code = c; \
if (code != TSDB_CODE_SUCCESS) { \
terrno = code; \
goto _return; \
} \
} while (0)
#define STMT_FLOG(param, ...) qFatal("stmt:%p " param, pStmt, __VA_ARGS__)
#define STMT_ELOG(param, ...) qError("stmt:%p " param, pStmt, __VA_ARGS__)
#define STMT_DLOG(param, ...) qDebug("stmt:%p " param, pStmt, __VA_ARGS__)
#define STMT_ELOG_E(param) qError("stmt:%p " param, pStmt)
#define STMT_DLOG_E(param) qDebug("stmt:%p " param, pStmt)
*/
TAOS_STMT2 *stmtInit2(STscObj *taos, TAOS_STMT2_OPTION *pOptions);
int stmtClose2(TAOS_STMT2 *stmt);
int stmtExec2(TAOS_STMT2 *stmt, int *affected_rows);
int stmtPrepare2(TAOS_STMT2 *stmt, const char *sql, unsigned long length);
int stmtSetTbName2(TAOS_STMT2 *stmt, const char *tbName);
int stmtSetTbTags2(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *tags);
int stmtBindBatch2(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *bind, int32_t colIdx);
int stmtGetTagFields2(TAOS_STMT2 *stmt, int *nums, TAOS_FIELD_E **fields);
int stmtGetColFields2(TAOS_STMT2 *stmt, int *nums, TAOS_FIELD_E **fields);
int stmtGetParamNum2(TAOS_STMT2 *stmt, int *nums);
int stmtGetParamTbName(TAOS_STMT2 *stmt, int *nums);
int stmtIsInsert2(TAOS_STMT2 *stmt, int *insert);
TAOS_RES *stmtUseResult2(TAOS_STMT2 *stmt);
const char *stmtErrstr2(TAOS_STMT2 *stmt);
#ifdef __cplusplus
}
#endif
#endif // TDENGINE_CLIENTSTMT2_H

View File

@ -687,7 +687,9 @@ void doDestroyRequest(void *p) {
taosMemoryFreeClear(pRequest->msgBuf); taosMemoryFreeClear(pRequest->msgBuf);
doFreeReqResultInfo(&pRequest->body.resInfo); doFreeReqResultInfo(&pRequest->body.resInfo);
(void)tsem_destroy(&pRequest->body.rspSem); if (TSDB_CODE_SUCCESS != tsem_destroy(&pRequest->body.rspSem)) {
tscError("failed to destroy semaphore");
}
taosArrayDestroy(pRequest->tableList); taosArrayDestroy(pRequest->tableList);
taosArrayDestroy(pRequest->targetTableList); taosArrayDestroy(pRequest->targetTableList);
@ -700,7 +702,9 @@ void doDestroyRequest(void *p) {
taosMemoryFreeClear(pRequest->pDb); taosMemoryFreeClear(pRequest->pDb);
taosArrayDestroy(pRequest->dbList); taosArrayDestroy(pRequest->dbList);
if (pRequest->body.interParam) { if (pRequest->body.interParam) {
(void)tsem_destroy(&((SSyncQueryParam *)pRequest->body.interParam)->sem); if (TSDB_CODE_SUCCESS != tsem_destroy(&((SSyncQueryParam *)pRequest->body.interParam)->sem)) {
tscError("failed to destroy semaphore in pRequest");
}
} }
taosMemoryFree(pRequest->body.interParam); taosMemoryFree(pRequest->body.interParam);

View File

@ -1636,7 +1636,9 @@ void hbDeregisterConn(STscObj *pTscObj, SClientHbKey connKey) {
SClientHbReq *pReq = taosHashAcquire(pAppHbMgr->activeInfo, &connKey, sizeof(SClientHbKey)); SClientHbReq *pReq = taosHashAcquire(pAppHbMgr->activeInfo, &connKey, sizeof(SClientHbKey));
if (pReq) { if (pReq) {
tFreeClientHbReq(pReq); tFreeClientHbReq(pReq);
(void)taosHashRemove(pAppHbMgr->activeInfo, &connKey, sizeof(SClientHbKey)); if (TSDB_CODE_SUCCESS != taosHashRemove(pAppHbMgr->activeInfo, &connKey, sizeof(SClientHbKey))) {
tscError("failed to remove connKey from activeInfo");
}
taosHashRelease(pAppHbMgr->activeInfo, pReq); taosHashRelease(pAppHbMgr->activeInfo, pReq);
(void)atomic_sub_fetch_32(&pAppHbMgr->connKeyCnt, 1); (void)atomic_sub_fetch_32(&pAppHbMgr->connKeyCnt, 1);
} }

View File

@ -209,7 +209,9 @@ _return:
void freeQueryParam(SSyncQueryParam* param) { void freeQueryParam(SSyncQueryParam* param) {
if (param == NULL) return; if (param == NULL) return;
(void)tsem_destroy(&param->sem); if (TSDB_CODE_SUCCESS != tsem_destroy(&param->sem)) {
tscError("failed to destroy semaphore in freeQueryParam");
}
taosMemoryFree(param); taosMemoryFree(param);
} }
@ -351,7 +353,7 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) {
// int64_t transporterId = 0; // int64_t transporterId = 0;
TSC_ERR_RET(asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &pMsgInfo->epSet, NULL, pSendMsg)); TSC_ERR_RET(asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &pMsgInfo->epSet, NULL, pSendMsg));
(void)tsem_wait(&pRequest->body.rspSem); TSC_ERR_RET(tsem_wait(&pRequest->body.rspSem));
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -839,6 +841,7 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList
.chkKillParam = (void*)pRequest->self, .chkKillParam = (void*)pRequest->self,
.pExecRes = &res, .pExecRes = &res,
.source = pRequest->source, .source = pRequest->source,
.pWorkerCb = getTaskPoolWorkerCb(),
}; };
int32_t code = schedulerExecJob(&req, &pRequest->body.queryJob); int32_t code = schedulerExecJob(&req, &pRequest->body.queryJob);
@ -1065,6 +1068,7 @@ static int32_t createResultBlock(TAOS_RES* pRes, int32_t numOfRows, SSDataBlock*
TAOS_ROW pRow = taos_fetch_row(pRes); TAOS_ROW pRow = taos_fetch_row(pRes);
if (NULL == pRow[0] || NULL == pRow[1] || NULL == pRow[2]) { if (NULL == pRow[0] || NULL == pRow[1] || NULL == pRow[2]) {
tscError("invalid data from vnode"); tscError("invalid data from vnode");
blockDataDestroy(*pBlock);
return TSDB_CODE_TSC_INTERNAL_ERROR; return TSDB_CODE_TSC_INTERNAL_ERROR;
} }
int64_t ts = *(int64_t*)pRow[0]; int64_t ts = *(int64_t*)pRow[0];
@ -1099,8 +1103,11 @@ void postSubQueryFetchCb(void* param, TAOS_RES* res, int32_t rowNum) {
} }
SSDataBlock* pBlock = NULL; SSDataBlock* pBlock = NULL;
if (TSDB_CODE_SUCCESS != createResultBlock(res, rowNum, &pBlock)) { pRequest->code = createResultBlock(res, rowNum, &pBlock);
tscError("0x%" PRIx64 ", create result block failed,QID:0x%" PRIx64, pRequest->self, pRequest->requestId); if (TSDB_CODE_SUCCESS != pRequest->code) {
tscError("0x%" PRIx64 ", create result block failed,QID:0x%" PRIx64 " %s", pRequest->self, pRequest->requestId,
tstrerror(pRequest->code));
returnToUser(pRequest);
return; return;
} }
@ -1165,14 +1172,18 @@ void schedulerExecCb(SExecResult* pResult, void* param, int32_t code) {
if (code != TSDB_CODE_SUCCESS && NEED_CLIENT_HANDLE_ERROR(code) && pRequest->sqlstr != NULL) { if (code != TSDB_CODE_SUCCESS && NEED_CLIENT_HANDLE_ERROR(code) && pRequest->sqlstr != NULL) {
tscDebug("0x%" PRIx64 " client retry to handle the error, code:%s, tryCount:%d,QID:0x%" PRIx64, pRequest->self, tscDebug("0x%" PRIx64 " client retry to handle the error, code:%s, tryCount:%d,QID:0x%" PRIx64, pRequest->self,
tstrerror(code), pRequest->retry, pRequest->requestId); tstrerror(code), pRequest->retry, pRequest->requestId);
(void)removeMeta(pTscObj, pRequest->targetTableList, IS_VIEW_REQUEST(pRequest->type)); if (TSDB_CODE_SUCCESS != removeMeta(pTscObj, pRequest->targetTableList, IS_VIEW_REQUEST(pRequest->type))) {
tscError("0x%" PRIx64 " remove meta failed,QID:0x%" PRIx64, pRequest->self, pRequest->requestId);
}
restartAsyncQuery(pRequest, code); restartAsyncQuery(pRequest, code);
return; return;
} }
tscDebug("schedulerExecCb request type %s", TMSG_INFO(pRequest->type)); tscDebug("schedulerExecCb request type %s", TMSG_INFO(pRequest->type));
if (NEED_CLIENT_RM_TBLMETA_REQ(pRequest->type) && NULL == pRequest->body.resInfo.execRes.res) { if (NEED_CLIENT_RM_TBLMETA_REQ(pRequest->type) && NULL == pRequest->body.resInfo.execRes.res) {
(void)removeMeta(pTscObj, pRequest->targetTableList, IS_VIEW_REQUEST(pRequest->type)); if (TSDB_CODE_SUCCESS != removeMeta(pTscObj, pRequest->targetTableList, IS_VIEW_REQUEST(pRequest->type))) {
tscError("0x%" PRIx64 " remove meta failed,QID:0x%" PRIx64, pRequest->self, pRequest->requestId);
}
} }
pRequest->metric.execCostUs = taosGetTimestampUs() - pRequest->metric.execStart; pRequest->metric.execCostUs = taosGetTimestampUs() - pRequest->metric.execStart;
@ -1266,7 +1277,10 @@ SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, bool keepQue
} }
if (NEED_CLIENT_RM_TBLMETA_REQ(pRequest->type) && NULL == pRequest->body.resInfo.execRes.res) { if (NEED_CLIENT_RM_TBLMETA_REQ(pRequest->type) && NULL == pRequest->body.resInfo.execRes.res) {
(void)removeMeta(pRequest->pTscObj, pRequest->targetTableList, IS_VIEW_REQUEST(pRequest->type)); code = removeMeta(pRequest->pTscObj, pRequest->targetTableList, IS_VIEW_REQUEST(pRequest->type));
if (TSDB_CODE_SUCCESS != code) {
tscError("0x%" PRIx64 " remove meta failed,QID:0x%" PRIx64, pRequest->self, pRequest->requestId);
}
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
@ -1349,6 +1363,7 @@ static int32_t asyncExecSchQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaDat
.chkKillParam = (void*)pRequest->self, .chkKillParam = (void*)pRequest->self,
.pExecRes = NULL, .pExecRes = NULL,
.source = pRequest->source, .source = pRequest->source,
.pWorkerCb = getTaskPoolWorkerCb(),
}; };
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = schedulerExecJob(&req, &pRequest->body.queryJob); code = schedulerExecJob(&req, &pRequest->body.queryJob);
@ -1479,12 +1494,12 @@ int32_t removeMeta(STscObj* pTscObj, SArray* tbList, bool isView) {
continue; continue;
} }
(void)tNameGetFullDbName(pViewName, dbFName); (void)tNameGetFullDbName(pViewName, dbFName);
(void)catalogRemoveViewMeta(pCatalog, dbFName, 0, pViewName->tname, 0); TSC_ERR_RET(catalogRemoveViewMeta(pCatalog, dbFName, 0, pViewName->tname, 0));
} }
} else { } else {
for (int32_t i = 0; i < tbNum; ++i) { for (int32_t i = 0; i < tbNum; ++i) {
SName* pTbName = taosArrayGet(tbList, i); SName* pTbName = taosArrayGet(tbList, i);
(void)catalogRemoveTableMeta(pCatalog, pTbName); TSC_ERR_RET(catalogRemoveTableMeta(pCatalog, pTbName));
} }
} }
@ -1584,7 +1599,11 @@ int32_t taosConnectImpl(const char* user, const char* auth, const char* db, __ta
tscError("failed to send connect msg to server, code:%s", tstrerror(code)); tscError("failed to send connect msg to server, code:%s", tstrerror(code));
return code; return code;
} }
(void)tsem_wait(&pRequest->body.rspSem); if (TSDB_CODE_SUCCESS != tsem_wait(&pRequest->body.rspSem)) {
destroyTscObj(*pTscObj);
tscError("failed to wait sem, code:%s", terrstr());
return terrno;
}
if (pRequest->code != TSDB_CODE_SUCCESS) { if (pRequest->code != TSDB_CODE_SUCCESS) {
const char* errorMsg = (code == TSDB_CODE_RPC_FQDN_ERROR) ? taos_errstr(pRequest) : tstrerror(pRequest->code); const char* errorMsg = (code == TSDB_CODE_RPC_FQDN_ERROR) ? taos_errstr(pRequest) : tstrerror(pRequest->code);
tscError("failed to connect to server, reason: %s", errorMsg); tscError("failed to connect to server, reason: %s", errorMsg);
@ -1736,7 +1755,9 @@ int32_t doProcessMsgFromServer(void* param) {
tscError("doProcessMsgFromServer pRequest->self:%" PRId64 " != pSendInfo->requestObjRefId:%" PRId64, tscError("doProcessMsgFromServer pRequest->self:%" PRId64 " != pSendInfo->requestObjRefId:%" PRId64,
pRequest->self, pSendInfo->requestObjRefId); pRequest->self, pSendInfo->requestObjRefId);
(void)taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId); if (TSDB_CODE_SUCCESS != taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId)) {
tscError("doProcessMsgFromServer taosReleaseRef failed");
}
taosMemoryFree(arg->pEpset); taosMemoryFree(arg->pEpset);
rpcFreeCont(pMsg->pCont); rpcFreeCont(pMsg->pCont);
destroySendMsgInfo(pSendInfo); destroySendMsgInfo(pSendInfo);
@ -1769,7 +1790,12 @@ int32_t doProcessMsgFromServer(void* param) {
(void)pSendInfo->fp(pSendInfo->param, &buf, pMsg->code); (void)pSendInfo->fp(pSendInfo->param, &buf, pMsg->code);
if (pTscObj) { if (pTscObj) {
(void)taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId); int32_t code = taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId);
if (TSDB_CODE_SUCCESS != code) {
tscError("doProcessMsgFromServer taosReleaseRef failed");
terrno = code;
pMsg->code = code;
}
} }
rpcFreeCont(pMsg->pCont); rpcFreeCont(pMsg->pCont);
@ -1946,7 +1972,9 @@ void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4)
static void syncFetchFn(void* param, TAOS_RES* res, int32_t numOfRows) { static void syncFetchFn(void* param, TAOS_RES* res, int32_t numOfRows) {
tsem_t* sem = param; tsem_t* sem = param;
(void)tsem_post(sem); if (TSDB_CODE_SUCCESS != tsem_post(sem)) {
tscError("failed to post sem, code:%s", terrstr());
}
} }
void* doAsyncFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4) { void* doAsyncFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4) {
@ -1965,10 +1993,16 @@ void* doAsyncFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertU
// convert ucs4 to native multi-bytes string // convert ucs4 to native multi-bytes string
pResultInfo->convertUcs4 = convertUcs4; pResultInfo->convertUcs4 = convertUcs4;
tsem_t sem; tsem_t sem;
(void)tsem_init(&sem, 0, 0); if (TSDB_CODE_SUCCESS != tsem_init(&sem, 0, 0)) {
tscError("failed to init sem, code:%s", terrstr());
}
taos_fetch_rows_a(pRequest, syncFetchFn, &sem); taos_fetch_rows_a(pRequest, syncFetchFn, &sem);
(void)tsem_wait(&sem); if (TSDB_CODE_SUCCESS != tsem_wait(&sem)) {
(void)tsem_destroy(&sem); tscError("failed to wait sem, code:%s", terrstr());
}
if (TSDB_CODE_SUCCESS != tsem_destroy(&sem)) {
tscError("failed to destroy sem, code:%s", terrstr());
}
pRequest->inCallback = false; pRequest->inCallback = false;
} }
@ -2742,7 +2776,9 @@ void syncCatalogFn(SMetaData* pResult, void* param, int32_t code) {
SSyncQueryParam* pParam = param; SSyncQueryParam* pParam = param;
pParam->pRequest->code = code; pParam->pRequest->code = code;
(void)tsem_post(&pParam->sem); if (TSDB_CODE_SUCCESS != tsem_post(&pParam->sem)) {
tscError("failed to post semaphore since %s", tstrerror(terrno));
}
} }
void syncQueryFn(void* param, void* res, int32_t code) { void syncQueryFn(void* param, void* res, int32_t code) {
@ -2753,7 +2789,9 @@ void syncQueryFn(void* param, void* res, int32_t code) {
pParam->pRequest->code = code; pParam->pRequest->code = code;
} }
(void)tsem_post(&pParam->sem); if (TSDB_CODE_SUCCESS != tsem_post(&pParam->sem)) {
tscError("failed to post semaphore since %s", tstrerror(terrno));
}
} }
void taosAsyncQueryImpl(uint64_t connId, const char* sql, __taos_async_fn_t fp, void* param, bool validateOnly, void taosAsyncQueryImpl(uint64_t connId, const char* sql, __taos_async_fn_t fp, void* param, bool validateOnly,
@ -2831,10 +2869,20 @@ TAOS_RES* taosQueryImpl(TAOS* taos, const char* sql, bool validateOnly, int8_t s
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL; return NULL;
} }
(void)tsem_init(&param->sem, 0, 0); int32_t code = tsem_init(&param->sem, 0, 0);
if (TSDB_CODE_SUCCESS != code) {
terrno = code;
taosMemoryFree(param);
return NULL;
}
taosAsyncQueryImpl(*(int64_t*)taos, sql, syncQueryFn, param, validateOnly, source); taosAsyncQueryImpl(*(int64_t*)taos, sql, syncQueryFn, param, validateOnly, source);
(void)tsem_wait(&param->sem); code = tsem_wait(&param->sem);
if (TSDB_CODE_SUCCESS != code) {
terrno = code;
taosMemoryFree(param);
return NULL;
}
SRequestObj* pRequest = NULL; SRequestObj* pRequest = NULL;
if (param->pRequest != NULL) { if (param->pRequest != NULL) {
@ -2860,10 +2908,20 @@ TAOS_RES* taosQueryImplWithReqid(TAOS* taos, const char* sql, bool validateOnly,
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL; return NULL;
} }
(void)tsem_init(&param->sem, 0, 0); int32_t code = tsem_init(&param->sem, 0, 0);
if (TSDB_CODE_SUCCESS != code) {
terrno = code;
taosMemoryFree(param);
return NULL;
}
taosAsyncQueryImplWithReqid(*(int64_t*)taos, sql, syncQueryFn, param, validateOnly, reqid); taosAsyncQueryImplWithReqid(*(int64_t*)taos, sql, syncQueryFn, param, validateOnly, reqid);
(void)tsem_wait(&param->sem); code = tsem_wait(&param->sem);
if (TSDB_CODE_SUCCESS != code) {
terrno = code;
taosMemoryFree(param);
return NULL;
}
SRequestObj* pRequest = NULL; SRequestObj* pRequest = NULL;
if (param->pRequest != NULL) { if (param->pRequest != NULL) {
param->pRequest->syncQuery = true; param->pRequest->syncQuery = true;

View File

@ -18,6 +18,7 @@
#include "clientLog.h" #include "clientLog.h"
#include "clientMonitor.h" #include "clientMonitor.h"
#include "clientStmt.h" #include "clientStmt.h"
#include "clientStmt2.h"
#include "functionMgt.h" #include "functionMgt.h"
#include "os.h" #include "os.h"
#include "query.h" #include "query.h"
@ -312,7 +313,9 @@ void taos_close_internal(void *taos) {
STscObj *pTscObj = (STscObj *)taos; STscObj *pTscObj = (STscObj *)taos;
tscDebug("0x%" PRIx64 " try to close connection, numOfReq:%d", pTscObj->id, pTscObj->numOfReqs); tscDebug("0x%" PRIx64 " try to close connection, numOfReq:%d", pTscObj->id, pTscObj->numOfReqs);
(void)taosRemoveRef(clientConnRefPool, pTscObj->id); if (TSDB_CODE_SUCCESS != taosRemoveRef(clientConnRefPool, pTscObj->id)) {
tscError("0x%" PRIx64 " failed to remove ref from conn pool", pTscObj->id);
}
} }
void taos_close(TAOS *taos) { void taos_close(TAOS *taos) {
@ -1313,7 +1316,10 @@ void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) {
if (NEED_CLIENT_HANDLE_ERROR(code)) { if (NEED_CLIENT_HANDLE_ERROR(code)) {
tscDebug("0x%" PRIx64 " client retry to handle the error, code:%d - %s, tryCount:%d,QID:0x%" PRIx64, tscDebug("0x%" PRIx64 " client retry to handle the error, code:%d - %s, tryCount:%d,QID:0x%" PRIx64,
pRequest->self, code, tstrerror(code), pRequest->retry, pRequest->requestId); pRequest->self, code, tstrerror(code), pRequest->retry, pRequest->requestId);
(void)refreshMeta(pRequest->pTscObj, pRequest); // ignore return code,try again if (TSDB_CODE_SUCCESS != refreshMeta(pRequest->pTscObj, pRequest)) {
tscWarn("0x%" PRIx64 " refresh meta failed, code:%d - %s,QID:0x%" PRIx64, pRequest->self, code,
tstrerror(code), pRequest->requestId);
}
pRequest->prevCode = code; pRequest->prevCode = code;
doAsyncQuery(pRequest, true); doAsyncQuery(pRequest, true);
return; return;
@ -1357,6 +1363,19 @@ void restartAsyncQuery(SRequestObj *pRequest, int32_t code) {
doAsyncQuery(pUserReq, true); doAsyncQuery(pUserReq, true);
} }
typedef struct SAsyncFetchParam {
SRequestObj *pReq;
__taos_async_fn_t fp;
void *param;
} SAsyncFetchParam;
static int32_t doAsyncFetch(void* pParam) {
SAsyncFetchParam *param = pParam;
taosAsyncFetchImpl(param->pReq, param->fp, param->param);
taosMemoryFree(param);
return TSDB_CODE_SUCCESS;
}
void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) { void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) {
if (res == NULL || fp == NULL) { if (res == NULL || fp == NULL) {
tscError("taos_fetch_rows_a invalid paras"); tscError("taos_fetch_rows_a invalid paras");
@ -1364,6 +1383,7 @@ void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) {
} }
if (!TD_RES_QUERY(res)) { if (!TD_RES_QUERY(res)) {
tscError("taos_fetch_rows_a res is NULL"); tscError("taos_fetch_rows_a res is NULL");
fp(param, res, TSDB_CODE_APP_ERROR);
return; return;
} }
@ -1373,7 +1393,20 @@ void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) {
return; return;
} }
taosAsyncFetchImpl(pRequest, fp, param); SAsyncFetchParam* pParam = taosMemoryCalloc(1, sizeof(SAsyncFetchParam));
if (!pParam) {
fp(param, res, terrno);
return;
}
pParam->pReq = pRequest;
pParam->fp = fp;
pParam->param = param;
int32_t code = taosAsyncExec(doAsyncFetch, pParam, NULL);
if (TSDB_CODE_SUCCESS != code) {
taosMemoryFree(pParam);
fp(param, res, code);
return;
}
} }
void taos_fetch_raw_block_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) {
@ -1614,8 +1647,11 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) {
} }
SSyncQueryParam *pParam = pRequest->body.interParam; SSyncQueryParam *pParam = pRequest->body.interParam;
(void)tsem_wait(&pParam->sem); code = tsem_wait(&pParam->sem);
if (code) {
tscError("tsem wait failed, code:%d - %s", code, tstrerror(code));
goto _return;
}
_return: _return:
destoryCatalogReq(&catalogReq); destoryCatalogReq(&catalogReq);
destroyRequest(pRequest); destroyRequest(pRequest);
@ -1915,6 +1951,160 @@ int taos_stmt_close(TAOS_STMT *stmt) {
return stmtClose(stmt); return stmtClose(stmt);
} }
TAOS_STMT2 *taos_stmt2_init(TAOS *taos, TAOS_STMT2_OPTION *option) {
STscObj *pObj = acquireTscObj(*(int64_t *)taos);
if (NULL == pObj) {
tscError("invalid parameter for %s", __FUNCTION__);
terrno = TSDB_CODE_TSC_DISCONNECTED;
return NULL;
}
TAOS_STMT2 *pStmt = stmtInit2(pObj, option);
releaseTscObj(*(int64_t *)taos);
return pStmt;
}
int taos_stmt2_prepare(TAOS_STMT2 *stmt, const char *sql, unsigned long length) {
if (stmt == NULL || sql == NULL) {
tscError("NULL parameter for %s", __FUNCTION__);
terrno = TSDB_CODE_INVALID_PARA;
return terrno;
}
return stmtPrepare2(stmt, sql, length);
}
int taos_stmt2_bind_param(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t col_idx) {
if (stmt == NULL) {
tscError("NULL parameter for %s", __FUNCTION__);
terrno = TSDB_CODE_INVALID_PARA;
return terrno;
}
int32_t code = 0;
for (int i = 0; i < bindv->count; ++i) {
if (bindv->tbnames && bindv->tbnames[i]) {
code = stmtSetTbName2(stmt, bindv->tbnames[i]);
if (code) {
return code;
}
}
if (bindv->tags && bindv->tags[i]) {
code = stmtSetTbTags2(stmt, bindv->tags[i]);
if (code) {
return code;
}
}
if (bindv->bind_cols && bindv->bind_cols[i]) {
TAOS_STMT2_BIND *bind = bindv->bind_cols[i];
if (bind->num <= 0 || bind->num > INT16_MAX) {
tscError("invalid bind num %d", bind->num);
terrno = TSDB_CODE_INVALID_PARA;
return terrno;
}
int32_t insert = 0;
(void)stmtIsInsert2(stmt, &insert);
if (0 == insert && bind->num > 1) {
tscError("only one row data allowed for query");
terrno = TSDB_CODE_INVALID_PARA;
return terrno;
}
code = stmtBindBatch2(stmt, bind, col_idx);
if (TSDB_CODE_SUCCESS != code) {
return code;
}
}
}
return TSDB_CODE_SUCCESS;
}
int taos_stmt2_exec(TAOS_STMT2 *stmt, int *affected_rows) {
if (stmt == NULL) {
tscError("NULL parameter for %s", __FUNCTION__);
terrno = TSDB_CODE_INVALID_PARA;
return terrno;
}
return stmtExec2(stmt, affected_rows);
}
int taos_stmt2_close(TAOS_STMT2 *stmt) {
if (stmt == NULL) {
tscError("NULL parameter for %s", __FUNCTION__);
terrno = TSDB_CODE_INVALID_PARA;
return terrno;
}
return stmtClose2(stmt);
}
/*
int taos_stmt2_param_count(TAOS_STMT2 *stmt, int *nums) {
if (stmt == NULL || nums == NULL) {
tscError("NULL parameter for %s", __FUNCTION__);
terrno = TSDB_CODE_INVALID_PARA;
return terrno;
}
return stmtGetParamNum2(stmt, nums);
}
*/
int taos_stmt2_is_insert(TAOS_STMT2 *stmt, int *insert) {
if (stmt == NULL || insert == NULL) {
tscError("NULL parameter for %s", __FUNCTION__);
terrno = TSDB_CODE_INVALID_PARA;
return terrno;
}
return stmtIsInsert2(stmt, insert);
}
int taos_stmt2_get_fields(TAOS_STMT2 *stmt, TAOS_FIELD_T field_type, int *count, TAOS_FIELD_E **fields) {
if (stmt == NULL || NULL == count) {
tscError("NULL parameter for %s", __FUNCTION__);
terrno = TSDB_CODE_INVALID_PARA;
return terrno;
}
if (field_type == TAOS_FIELD_COL) {
return stmtGetColFields2(stmt, count, fields);
} else if (field_type == TAOS_FIELD_TAG) {
return stmtGetTagFields2(stmt, count, fields);
} else if (field_type == TAOS_FIELD_QUERY) {
return stmtGetParamNum2(stmt, count);
} else if (field_type == TAOS_FIELD_TBNAME) {
return stmtGetParamTbName(stmt, count);
} else {
tscError("invalid parameter for %s", __FUNCTION__);
terrno = TSDB_CODE_INVALID_PARA;
return terrno;
}
}
void taos_stmt2_free_fields(TAOS_STMT2 *stmt, TAOS_FIELD_E *fields) {
(void)stmt;
if (!fields) return;
taosMemoryFree(fields);
}
TAOS_RES *taos_stmt2_result(TAOS_STMT2 *stmt) {
if (stmt == NULL) {
tscError("NULL parameter for %s", __FUNCTION__);
terrno = TSDB_CODE_INVALID_PARA;
return NULL;
}
return stmtUseResult2(stmt);
}
char *taos_stmt2_error(TAOS_STMT2 *stmt) { return (char *)stmtErrstr2(stmt); }
int taos_set_conn_mode(TAOS *taos, int mode, int value) { int taos_set_conn_mode(TAOS *taos, int mode, int value) {
if (taos == NULL) { if (taos == NULL) {
terrno = TSDB_CODE_INVALID_PARA; terrno = TSDB_CODE_INVALID_PARA;

View File

@ -34,11 +34,11 @@ static void processFileInTheEnd(TdFilePtr pFile, char* path) {
return; return;
} }
if (taosFtruncateFile(pFile, 0) != 0) { if (taosFtruncateFile(pFile, 0) != 0) {
tscError("failed to truncate file:%s, errno:%d", path, errno); tscError("failed to truncate file:%s, errno:%d", path, terrno);
return; return;
} }
if (taosUnLockFile(pFile) != 0) { if (taosUnLockFile(pFile) != 0) {
tscError("failed to unlock file:%s, errno:%d", path, errno); tscError("failed to unlock file:%s, errno:%d", path, terrno);
return; return;
} }
if (taosCloseFile(&(pFile)) != 0) { if (taosCloseFile(&(pFile)) != 0) {
@ -367,7 +367,7 @@ static void monitorWriteSlowLog2File(MonitorSlowLogData* slowLogData, char* tmpP
tscInfo("[monitor] create slow log file:%s", path); tscInfo("[monitor] create slow log file:%s", path);
pFile = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND | TD_FILE_READ | TD_FILE_TRUNC); pFile = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND | TD_FILE_READ | TD_FILE_TRUNC);
if (pFile == NULL) { if (pFile == NULL) {
tscError("failed to open file:%s since %d", path, errno); tscError("failed to open file:%s since %d", path, terrno);
return; return;
} }
@ -397,7 +397,7 @@ static void monitorWriteSlowLog2File(MonitorSlowLogData* slowLogData, char* tmpP
} }
if (taosLSeekFile(pFile, 0, SEEK_END) < 0) { if (taosLSeekFile(pFile, 0, SEEK_END) < 0) {
tscError("failed to seek file:%p code: %d", pFile, errno); tscError("failed to seek file:%p code: %d", pFile, terrno);
return; return;
} }
if (taosWriteFile(pFile, slowLogData->data, strlen(slowLogData->data) + 1) < 0) { if (taosWriteFile(pFile, slowLogData->data, strlen(slowLogData->data) + 1) < 0) {
@ -409,7 +409,7 @@ static void monitorWriteSlowLog2File(MonitorSlowLogData* slowLogData, char* tmpP
static char* readFile(TdFilePtr pFile, int64_t* offset, int64_t size) { static char* readFile(TdFilePtr pFile, int64_t* offset, int64_t size) {
tscDebug("[monitor] readFile slow begin pFile:%p, offset:%" PRId64 ", size:%" PRId64, pFile, *offset, size); tscDebug("[monitor] readFile slow begin pFile:%p, offset:%" PRId64 ", size:%" PRId64, pFile, *offset, size);
if (taosLSeekFile(pFile, *offset, SEEK_SET) < 0) { if (taosLSeekFile(pFile, *offset, SEEK_SET) < 0) {
tscError("failed to seek file:%p code: %d", pFile, errno); tscError("failed to seek file:%p code: %d", pFile, terrno);
return NULL; return NULL;
} }
@ -549,7 +549,7 @@ static void monitorSendSlowLogAtRunning(int64_t clusterId) {
int64_t size = getFileSize(pClient->path); int64_t size = getFileSize(pClient->path);
if (size <= pClient->offset) { if (size <= pClient->offset) {
if (taosFtruncateFile(pClient->pFile, 0) < 0) { if (taosFtruncateFile(pClient->pFile, 0) < 0) {
tscError("failed to truncate file:%p code: %d", pClient->pFile, errno); tscError("failed to truncate file:%p code: %d", pClient->pFile, terrno);
} }
tscDebug("[monitor] monitorSendSlowLogAtRunning truncate file to 0 file:%p", pClient->pFile); tscDebug("[monitor] monitorSendSlowLogAtRunning truncate file to 0 file:%p", pClient->pFile);
pClient->offset = 0; pClient->offset = 0;
@ -606,7 +606,7 @@ static void monitorSendAllSlowLogAtQuit() {
static void processFileRemoved(SlowLogClient* pClient) { static void processFileRemoved(SlowLogClient* pClient) {
if (taosUnLockFile(pClient->pFile) != 0) { if (taosUnLockFile(pClient->pFile) != 0) {
tscError("failed to unlock file:%s since %d", pClient->path, errno); tscError("failed to unlock file:%s since %d", pClient->path, terrno);
return; return;
} }
(void)taosCloseFile(&(pClient->pFile)); (void)taosCloseFile(&(pClient->pFile));
@ -614,7 +614,7 @@ static void processFileRemoved(SlowLogClient* pClient) {
TdFilePtr pFile = TdFilePtr pFile =
taosOpenFile(pClient->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND | TD_FILE_READ | TD_FILE_TRUNC); taosOpenFile(pClient->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND | TD_FILE_READ | TD_FILE_TRUNC);
if (pFile == NULL) { if (pFile == NULL) {
tscError("failed to open file:%s since %d", pClient->path, errno); tscError("failed to open file:%s since %d", pClient->path, terrno);
} else { } else {
pClient->pFile = pFile; pClient->pFile = pFile;
} }
@ -821,9 +821,10 @@ int32_t monitorInit() {
return code; return code;
} }
if (taosMulModeMkDir(tmpSlowLogPath, 0777, true) != 0) { code = taosMulModeMkDir(tmpSlowLogPath, 0777, true);
if (code != 0) {
tscError("failed to create dir:%s since %s", tmpSlowLogPath, terrstr()); tscError("failed to create dir:%s since %s", tmpSlowLogPath, terrstr());
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY); return code;
} }
if (tsem2_init(&monitorSem, 0, 0) != 0) { if (tsem2_init(&monitorSem, 0, 0) != 0) {

File diff suppressed because it is too large Load Diff

View File

@ -128,15 +128,15 @@ int32_t s3CheckCfg() {
if (!fp) { if (!fp) {
(void)fprintf(stderr, "failed to open test file: %s.\n", path); (void)fprintf(stderr, "failed to open test file: %s.\n", path);
// uError("ERROR: %s Failed to open %s", __func__, path); // uError("ERROR: %s Failed to open %s", __func__, path);
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _next); TAOS_CHECK_GOTO(terrno, &lino, _next);
} }
if (taosWriteFile(fp, testdata, strlen(testdata)) < 0) { if (taosWriteFile(fp, testdata, strlen(testdata)) < 0) {
(void)fprintf(stderr, "failed to write test file: %s.\n", path); (void)fprintf(stderr, "failed to write test file: %s.\n", path);
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _next); TAOS_CHECK_GOTO(terrno, &lino, _next);
} }
if (taosFsyncFile(fp) < 0) { if (taosFsyncFile(fp) < 0) {
(void)fprintf(stderr, "failed to fsync test file: %s.\n", path); (void)fprintf(stderr, "failed to fsync test file: %s.\n", path);
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _next); TAOS_CHECK_GOTO(terrno, &lino, _next);
} }
(void)taosCloseFile(&fp); (void)taosCloseFile(&fp);
@ -872,7 +872,7 @@ upload:
if (i > 0 && cp.parts[i - 1].completed) { if (i > 0 && cp.parts[i - 1].completed) {
if (taosLSeekFile(data->infileFD, cp.parts[i].offset, SEEK_SET) < 0) { if (taosLSeekFile(data->infileFD, cp.parts[i].offset, SEEK_SET) < 0) {
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); TAOS_CHECK_GOTO(terrno, &lino, _exit);
} }
} }
@ -988,12 +988,12 @@ int32_t s3PutObjectFromFile2ByEp(const char *file, const char *object_name, int8
if (taosStatFile(file, (int64_t *)&contentLength, &lmtime, NULL) < 0) { if (taosStatFile(file, (int64_t *)&contentLength, &lmtime, NULL) < 0) {
uError("ERROR: %s Failed to stat file %s: ", __func__, file); uError("ERROR: %s Failed to stat file %s: ", __func__, file);
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); TAOS_RETURN(terrno);
} }
if (!(data.infileFD = taosOpenFile(file, TD_FILE_READ))) { if (!(data.infileFD = taosOpenFile(file, TD_FILE_READ))) {
uError("ERROR: %s Failed to open file %s: ", __func__, file); uError("ERROR: %s Failed to open file %s: ", __func__, file);
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); TAOS_RETURN(terrno);
} }
data.totalContentLength = data.totalOriginalContentLength = data.contentLength = data.originalContentLength = data.totalContentLength = data.totalOriginalContentLength = data.contentLength = data.originalContentLength =
@ -1065,18 +1065,18 @@ static int32_t s3PutObjectFromFileOffsetByEp(const char *file, const char *objec
if (taosStatFile(file, (int64_t *)&contentLength, &lmtime, NULL) < 0) { if (taosStatFile(file, (int64_t *)&contentLength, &lmtime, NULL) < 0) {
uError("ERROR: %s Failed to stat file %s: ", __func__, file); uError("ERROR: %s Failed to stat file %s: ", __func__, file);
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); TAOS_RETURN(terrno);
} }
contentLength = size; contentLength = size;
if (!(data.infileFD = taosOpenFile(file, TD_FILE_READ))) { if (!(data.infileFD = taosOpenFile(file, TD_FILE_READ))) {
uError("ERROR: %s Failed to open file %s: ", __func__, file); uError("ERROR: %s Failed to open file %s: ", __func__, file);
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); TAOS_RETURN(terrno);
} }
if (taosLSeekFile(data.infileFD, offset, SEEK_SET) < 0) { if (taosLSeekFile(data.infileFD, offset, SEEK_SET) < 0) {
(void)taosCloseFile(&data.infileFD); (void)taosCloseFile(&data.infileFD);
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); TAOS_RETURN(terrno);
} }
data.totalContentLength = data.totalOriginalContentLength = data.contentLength = data.originalContentLength = data.totalContentLength = data.totalOriginalContentLength = data.contentLength = data.originalContentLength =
@ -1412,8 +1412,8 @@ static int32_t s3GetObjectToFileByEp(const char *object_name, const char *fileNa
TdFilePtr pFile = taosOpenFile(fileName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); TdFilePtr pFile = taosOpenFile(fileName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
if (pFile == NULL) { if (pFile == NULL) {
uError("[s3] open file error, errno:%d, fileName:%s", TAOS_SYSTEM_ERROR(errno), fileName); uError("[s3] open file error, errno:%d, fileName:%s", terrno, fileName);
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); TAOS_RETURN(terrno);
} }
TS3GetData cbd = {0}; TS3GetData cbd = {0};
@ -1881,7 +1881,6 @@ void s3EvictCache(const char *path, long object_size) {
// 1, list data files' atime under dir(path) // 1, list data files' atime under dir(path)
tdbDirPtr pDir = taosOpenDir(dir_name); tdbDirPtr pDir = taosOpenDir(dir_name);
if (pDir == NULL) { if (pDir == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno);
vError("failed to open %s since %s", dir_name, terrstr()); vError("failed to open %s since %s", dir_name, terrstr());
} }
SArray *evict_files = taosArrayInit(16, sizeof(SEvictFile)); SArray *evict_files = taosArrayInit(16, sizeof(SEvictFile));

View File

@ -10,7 +10,7 @@ int32_t cos_cp_open(char const* cp_path, SCheckpoint* checkpoint) {
TdFilePtr fd = taosOpenFile(cp_path, TD_FILE_WRITE | TD_FILE_CREATE /* | TD_FILE_TRUNC*/ | TD_FILE_WRITE_THROUGH); TdFilePtr fd = taosOpenFile(cp_path, TD_FILE_WRITE | TD_FILE_CREATE /* | TD_FILE_TRUNC*/ | TD_FILE_WRITE_THROUGH);
if (!fd) { if (!fd) {
uError("%s Failed to open %s", __func__, cp_path); uError("%s Failed to open %s", __func__, cp_path);
TAOS_CHECK_RETURN(TAOS_SYSTEM_ERROR(errno)); TAOS_CHECK_RETURN(terrno);
} }
checkpoint->thefile = fd; checkpoint->thefile = fd;
@ -162,7 +162,7 @@ int32_t cos_cp_load(char const* filepath, SCheckpoint* checkpoint) {
TdFilePtr fd = taosOpenFile(filepath, TD_FILE_READ); TdFilePtr fd = taosOpenFile(filepath, TD_FILE_READ);
if (!fd) { if (!fd) {
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); TAOS_CHECK_GOTO(terrno, &lino, _exit);
} }
int64_t size = -1; int64_t size = -1;
@ -175,7 +175,7 @@ int32_t cos_cp_load(char const* filepath, SCheckpoint* checkpoint) {
int64_t n = taosReadFile(fd, cp_body, size); int64_t n = taosReadFile(fd, cp_body, size);
if (n < 0) { if (n < 0) {
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); TAOS_CHECK_GOTO(terrno, &lino, _exit);
} else if (n != size) { } else if (n != size) {
TAOS_CHECK_GOTO(TSDB_CODE_FILE_CORRUPTED, &lino, _exit); TAOS_CHECK_GOTO(TSDB_CODE_FILE_CORRUPTED, &lino, _exit);
} }
@ -207,13 +207,13 @@ static int32_t cos_cp_save_json(cJSON const* json, SCheckpoint* checkpoint) {
TdFilePtr fp = checkpoint->thefile; TdFilePtr fp = checkpoint->thefile;
if (taosFtruncateFile(fp, 0) < 0) { if (taosFtruncateFile(fp, 0) < 0) {
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); TAOS_CHECK_GOTO(terrno, &lino, _exit);
} }
if (taosLSeekFile(fp, 0, SEEK_SET) < 0) { if (taosLSeekFile(fp, 0, SEEK_SET) < 0) {
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); TAOS_CHECK_GOTO(terrno, &lino, _exit);
} }
if (taosWriteFile(fp, data, strlen(data)) < 0) { if (taosWriteFile(fp, data, strlen(data)) < 0) {
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); TAOS_CHECK_GOTO(terrno, &lino, _exit);
} }
if (taosFsyncFile(fp) < 0) { if (taosFsyncFile(fp) < 0) {

View File

@ -58,7 +58,7 @@ static int32_t generateConfigFile(char* confDir) {
TdFilePtr pFile = taosOpenFile(confDir, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); TdFilePtr pFile = taosOpenFile(confDir, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
if (pFile == NULL) { if (pFile == NULL) {
uError("[rsync] open conf file error, dir:%s," ERRNO_ERR_FORMAT, confDir, ERRNO_ERR_DATA); uError("[rsync] open conf file error, dir:%s," ERRNO_ERR_FORMAT, confDir, ERRNO_ERR_DATA);
return TAOS_SYSTEM_ERROR(errno); return terrno;
} }
#ifdef WINDOWS #ifdef WINDOWS
@ -90,10 +90,10 @@ static int32_t generateConfigFile(char* confDir) {
#endif #endif
); );
uDebug("[rsync] conf:%s", confContent); uDebug("[rsync] conf:%s", confContent);
if (taosWriteFile(pFile, confContent, strlen(confContent)) <= 0) { if (taosWriteFile(pFile, confContent, strlen(confContent)) != TSDB_CODE_SUCCESS) {
uError("[rsync] write conf file error," ERRNO_ERR_FORMAT, ERRNO_ERR_DATA); uError("[rsync] write conf file error," ERRNO_ERR_FORMAT, ERRNO_ERR_DATA);
(void)taosCloseFile(&pFile); (void)taosCloseFile(&pFile);
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
return code; return code;
} }

View File

@ -731,6 +731,10 @@ int32_t blockDataMergeNRows(SSDataBlock* pDest, const SSDataBlock* pSrc, int32_t
} }
void blockDataShrinkNRows(SSDataBlock* pBlock, int32_t numOfRows) { void blockDataShrinkNRows(SSDataBlock* pBlock, int32_t numOfRows) {
if (numOfRows == 0) {
return;
}
if (numOfRows >= pBlock->info.rows) { if (numOfRows >= pBlock->info.rows) {
blockDataCleanup(pBlock); blockDataCleanup(pBlock);
return; return;
@ -849,7 +853,7 @@ int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startInd
int32_t blockDataExtractBlock(SSDataBlock* pBlock, int32_t startIndex, int32_t rowCount, SSDataBlock** pResBlock) { int32_t blockDataExtractBlock(SSDataBlock* pBlock, int32_t startIndex, int32_t rowCount, SSDataBlock** pResBlock) {
int32_t code = 0; int32_t code = 0;
QRY_OPTR_CHECK(pResBlock); QRY_PARAM_CHECK(pResBlock);
if (pBlock == NULL || startIndex < 0 || rowCount > pBlock->info.rows || rowCount + startIndex > pBlock->info.rows) { if (pBlock == NULL || startIndex < 0 || rowCount > pBlock->info.rows || rowCount + startIndex > pBlock->info.rows) {
return TSDB_CODE_INVALID_PARA; return TSDB_CODE_INVALID_PARA;
@ -1263,18 +1267,19 @@ static void blockDataAssign(SColumnInfoData* pCols, const SSDataBlock* pDataBloc
} }
static int32_t createHelpColInfoData(const SSDataBlock* pDataBlock, SColumnInfoData** ppCols) { static int32_t createHelpColInfoData(const SSDataBlock* pDataBlock, SColumnInfoData** ppCols) {
*ppCols = NULL;
int32_t code = 0; int32_t code = 0;
int32_t rows = pDataBlock->info.capacity; int32_t rows = pDataBlock->info.capacity;
size_t numOfCols = taosArrayGetSize(pDataBlock->pDataBlock); size_t numOfCols = taosArrayGetSize(pDataBlock->pDataBlock);
int32_t i = 0;
*ppCols = NULL;
SColumnInfoData* pCols = taosMemoryCalloc(numOfCols, sizeof(SColumnInfoData)); SColumnInfoData* pCols = taosMemoryCalloc(numOfCols, sizeof(SColumnInfoData));
if (pCols == NULL) { if (pCols == NULL) {
return terrno; return terrno;
} }
for (int32_t i = 0; i < numOfCols; ++i) { for (i = 0; i < numOfCols; ++i) {
SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, i); SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, i);
if (pColInfoData == NULL) { if (pColInfoData == NULL) {
continue; continue;
@ -1309,6 +1314,10 @@ static int32_t createHelpColInfoData(const SSDataBlock* pDataBlock, SColumnInfoD
return code; return code;
_error: _error:
for(int32_t j = 0; j < i; ++j) {
colDataDestroy(&pCols[j]);
}
taosMemoryFree(pCols); taosMemoryFree(pCols);
return code; return code;
} }
@ -1753,7 +1762,7 @@ int32_t copyDataBlock(SSDataBlock* pDst, const SSDataBlock* pSrc) {
} }
int32_t createSpecialDataBlock(EStreamType type, SSDataBlock** pBlock) { int32_t createSpecialDataBlock(EStreamType type, SSDataBlock** pBlock) {
QRY_OPTR_CHECK(pBlock); QRY_PARAM_CHECK(pBlock);
int32_t code = 0; int32_t code = 0;
SSDataBlock* p = taosMemoryCalloc(1, sizeof(SSDataBlock)); SSDataBlock* p = taosMemoryCalloc(1, sizeof(SSDataBlock));
@ -1846,7 +1855,7 @@ _err:
} }
int32_t blockCopyOneRow(const SSDataBlock* pDataBlock, int32_t rowIdx, SSDataBlock** pResBlock) { int32_t blockCopyOneRow(const SSDataBlock* pDataBlock, int32_t rowIdx, SSDataBlock** pResBlock) {
QRY_OPTR_CHECK(pResBlock); QRY_PARAM_CHECK(pResBlock);
if (pDataBlock == NULL) { if (pDataBlock == NULL) {
return TSDB_CODE_INVALID_PARA; return TSDB_CODE_INVALID_PARA;
@ -1946,7 +1955,7 @@ _end:
} }
int32_t createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData, SSDataBlock** pResBlock) { int32_t createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData, SSDataBlock** pResBlock) {
QRY_OPTR_CHECK(pResBlock); QRY_PARAM_CHECK(pResBlock);
if (pDataBlock == NULL) { if (pDataBlock == NULL) {
return TSDB_CODE_INVALID_PARA; return TSDB_CODE_INVALID_PARA;
} }
@ -2029,7 +2038,7 @@ int32_t createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData, SSDataB
} }
int32_t createDataBlock(SSDataBlock** pResBlock) { int32_t createDataBlock(SSDataBlock** pResBlock) {
QRY_OPTR_CHECK(pResBlock); QRY_PARAM_CHECK(pResBlock);
SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
if (pBlock == NULL) { if (pBlock == NULL) {
return terrno; return terrno;
@ -2080,7 +2089,7 @@ SColumnInfoData createColumnInfoData(int16_t type, int32_t bytes, int16_t colId)
int32_t bdGetColumnInfoData(const SSDataBlock* pBlock, int32_t index, SColumnInfoData** pColInfoData) { int32_t bdGetColumnInfoData(const SSDataBlock* pBlock, int32_t index, SColumnInfoData** pColInfoData) {
int32_t code = 0; int32_t code = 0;
QRY_OPTR_CHECK(pColInfoData); QRY_PARAM_CHECK(pColInfoData);
if (index >= taosArrayGetSize(pBlock->pDataBlock)) { if (index >= taosArrayGetSize(pBlock->pDataBlock)) {
return TSDB_CODE_INVALID_PARA; return TSDB_CODE_INVALID_PARA;
@ -2402,10 +2411,18 @@ void* tDecodeDataBlock(const void* buf, SSDataBlock* pBlock) {
} else { } else {
buf = taosDecodeBinary(buf, (void**)&data.nullbitmap, BitmapLen(pBlock->info.rows)); buf = taosDecodeBinary(buf, (void**)&data.nullbitmap, BitmapLen(pBlock->info.rows));
} }
if(buf == NULL) {
uError("failed to decode null bitmap/offset, type:%d", data.info.type);
goto _error;
}
int32_t len = 0; int32_t len = 0;
buf = taosDecodeFixedI32(buf, &len); buf = taosDecodeFixedI32(buf, &len);
buf = taosDecodeBinary(buf, (void**)&data.pData, len); buf = taosDecodeBinary(buf, (void**)&data.pData, len);
if (buf == NULL) {
uError("failed to decode data, type:%d", data.info.type);
goto _error;
}
if (IS_VAR_DATA_TYPE(data.info.type)) { if (IS_VAR_DATA_TYPE(data.info.type)) {
data.varmeta.length = len; data.varmeta.length = len;
data.varmeta.allocLen = len; data.varmeta.allocLen = len;
@ -2418,6 +2435,15 @@ void* tDecodeDataBlock(const void* buf, SSDataBlock* pBlock) {
} }
return (void*)buf; return (void*)buf;
_error:
for (int32_t i = 0; i < sz; ++i) {
SColumnInfoData* pColInfoData = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, i);
if (pColInfoData == NULL) {
break;
}
colDataDestroy(pColInfoData);
}
return NULL;
} }
static char* formatTimestamp(char* buf, int64_t val, int precision) { static char* formatTimestamp(char* buf, int64_t val, int precision) {
@ -2854,7 +2880,7 @@ bool alreadyAddGroupId(char* ctbName, int64_t groupId) {
} }
int32_t buildCtbNameByGroupId(const char* stbFullName, uint64_t groupId, char** pName) { int32_t buildCtbNameByGroupId(const char* stbFullName, uint64_t groupId, char** pName) {
QRY_OPTR_CHECK(pName); QRY_PARAM_CHECK(pName);
char* pBuf = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN + 1); char* pBuf = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN + 1);
if (!pBuf) { if (!pBuf) {
@ -2914,6 +2940,8 @@ int32_t buildCtbNameByGroupIdImpl(const char* stbFullName, uint64_t groupId, cha
// return length of encoded data, return -1 if failed // return length of encoded data, return -1 if failed
int32_t blockEncode(const SSDataBlock* pBlock, char* data, int32_t numOfCols) { int32_t blockEncode(const SSDataBlock* pBlock, char* data, int32_t numOfCols) {
blockDataCheck(pBlock, false);
int32_t dataLen = 0; int32_t dataLen = 0;
// todo extract method // todo extract method
@ -3155,6 +3183,9 @@ int32_t blockDecode(SSDataBlock* pBlock, const char* pData, const char** pEndPos
} }
*pEndPos = pStart; *pEndPos = pStart;
blockDataCheck(pBlock, false);
return code; return code;
} }
@ -3364,3 +3395,77 @@ int32_t blockDataGetSortedRows(SSDataBlock* pDataBlock, SArray* pOrderInfo) {
return nextRowIdx; return nextRowIdx;
} }
void blockDataCheck(const SSDataBlock* pDataBlock, bool forceChk) {
return;
if (NULL == pDataBlock || pDataBlock->info.rows == 0) {
return;
}
#define BLOCK_DATA_CHECK_TRESSA(o) ;
//#define BLOCK_DATA_CHECK_TRESSA(o) A S S E R T(o)
BLOCK_DATA_CHECK_TRESSA(pDataBlock->info.rows > 0);
if (!pDataBlock->info.dataLoad && !forceChk) {
return;
}
bool isVarType = false;
int32_t colLen = 0;
int32_t nextPos = 0;
int64_t checkRows = 0;
int64_t typeValue = 0;
int32_t colNum = taosArrayGetSize(pDataBlock->pDataBlock);
for (int32_t i = 0; i < colNum; ++i) {
SColumnInfoData* pCol = (SColumnInfoData*)taosArrayGet(pDataBlock->pDataBlock, i);
isVarType = IS_VAR_DATA_TYPE(pCol->info.type);
checkRows = pDataBlock->info.rows;
if (isVarType) {
BLOCK_DATA_CHECK_TRESSA(pCol->varmeta.offset);
} else {
BLOCK_DATA_CHECK_TRESSA(pCol->nullbitmap);
}
nextPos = 0;
for (int64_t r = 0; r < checkRows; ++r) {
if (!colDataIsNull_s(pCol, r)) {
BLOCK_DATA_CHECK_TRESSA(pCol->pData);
BLOCK_DATA_CHECK_TRESSA(pCol->varmeta.length <= pCol->varmeta.allocLen);
if (isVarType) {
BLOCK_DATA_CHECK_TRESSA(pCol->varmeta.allocLen > 0);
BLOCK_DATA_CHECK_TRESSA(pCol->varmeta.offset[r] < pCol->varmeta.length);
if (pCol->reassigned) {
BLOCK_DATA_CHECK_TRESSA(pCol->varmeta.offset[r] >= 0);
} else if (0 == r) {
nextPos = pCol->varmeta.offset[r];
} else {
BLOCK_DATA_CHECK_TRESSA(pCol->varmeta.offset[r] == nextPos);
}
colLen = varDataTLen(pCol->pData + pCol->varmeta.offset[r]);
BLOCK_DATA_CHECK_TRESSA(colLen >= VARSTR_HEADER_SIZE);
BLOCK_DATA_CHECK_TRESSA(colLen <= pCol->info.bytes);
if (pCol->reassigned) {
BLOCK_DATA_CHECK_TRESSA((pCol->varmeta.offset[r] + colLen) <= pCol->varmeta.length);
} else {
nextPos += colLen;
BLOCK_DATA_CHECK_TRESSA(nextPos <= pCol->varmeta.length);
}
typeValue = *(char*)(pCol->pData + pCol->varmeta.offset[r] + colLen - 1);
} else {
GET_TYPED_DATA(typeValue, int64_t, pCol->info.type, colDataGetNumData(pCol, r));
}
}
}
}
return;
}

View File

@ -3124,6 +3124,198 @@ _exit:
return code; return code;
} }
int32_t tColDataAddValueByBind2(SColData *pColData, TAOS_STMT2_BIND *pBind, int32_t buffMaxLen) {
int32_t code = 0;
if (!(pBind->num == 1 && pBind->is_null && *pBind->is_null)) {
if (!(pColData->type == pBind->buffer_type)) {
return TSDB_CODE_INVALID_PARA;
}
}
if (IS_VAR_DATA_TYPE(pColData->type)) { // var-length data type
uint8_t *buf = pBind->buffer;
for (int32_t i = 0; i < pBind->num; ++i) {
if (pBind->is_null && pBind->is_null[i]) {
if (pColData->cflag & COL_IS_KEY) {
code = TSDB_CODE_PAR_PRIMARY_KEY_IS_NULL;
goto _exit;
}
if (pBind->is_null[i] == 1) {
code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_NULL](pColData, NULL, 0);
if (code) goto _exit;
} else {
code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_NONE](pColData, NULL, 0);
if (code) goto _exit;
}
} else if (pBind->length[i] > buffMaxLen) {
uError("var data length too big, len:%d, max:%d", pBind->length[i], buffMaxLen);
return TSDB_CODE_INVALID_PARA;
} else {
code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_VALUE](pColData, buf, pBind->length[i]);
buf += pBind->length[i];
}
}
} else { // fixed-length data type
bool allValue;
bool allNull;
bool allNone;
if (pBind->is_null) {
bool same = (memcmp(pBind->is_null, pBind->is_null + 1, pBind->num - 1) == 0);
allNull = (same && pBind->is_null[0] == 1);
allNone = (same && pBind->is_null[0] > 1);
allValue = (same && pBind->is_null[0] == 0);
} else {
allNull = false;
allNone = false;
allValue = true;
}
if ((pColData->cflag & COL_IS_KEY) && !allValue) {
code = TSDB_CODE_PAR_PRIMARY_KEY_IS_NULL;
goto _exit;
}
if (allValue) {
// optimize (todo)
for (int32_t i = 0; i < pBind->num; ++i) {
uint8_t *val = (uint8_t *)pBind->buffer + TYPE_BYTES[pColData->type] * i;
if (TSDB_DATA_TYPE_BOOL == pColData->type && *val > 1) {
*val = 1;
}
code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_VALUE](pColData, val, TYPE_BYTES[pColData->type]);
}
} else if (allNull) {
// optimize (todo)
for (int32_t i = 0; i < pBind->num; ++i) {
code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_NULL](pColData, NULL, 0);
if (code) goto _exit;
}
} else if (allNone) {
// optimize (todo)
for (int32_t i = 0; i < pBind->num; ++i) {
code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_NONE](pColData, NULL, 0);
if (code) goto _exit;
}
} else {
for (int32_t i = 0; i < pBind->num; ++i) {
if (pBind->is_null[i]) {
if (pBind->is_null[i] == 1) {
code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_NULL](pColData, NULL, 0);
if (code) goto _exit;
} else {
code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_NONE](pColData, NULL, 0);
if (code) goto _exit;
}
} else {
uint8_t *val = (uint8_t *)pBind->buffer + TYPE_BYTES[pColData->type] * i;
if (TSDB_DATA_TYPE_BOOL == pColData->type && *val > 1) {
*val = 1;
}
code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_VALUE](pColData, val, TYPE_BYTES[pColData->type]);
}
}
}
}
_exit:
return code;
}
/* build rows to `rowArray` from bind
* `infos` is the bind information array
* `numOfInfos` is the number of bind information
* `infoSorted` is whether the bind information is sorted by column id
* `pTSchema` is the schema of the table
* `rowArray` is the array to store the rows
*/
int32_t tRowBuildFromBind2(SBindInfo2 *infos, int32_t numOfInfos, bool infoSorted, const STSchema *pTSchema,
SArray *rowArray) {
if (infos == NULL || numOfInfos <= 0 || numOfInfos > pTSchema->numOfCols || pTSchema == NULL || rowArray == NULL) {
return TSDB_CODE_INVALID_PARA;
}
if (!infoSorted) {
taosqsort_r(infos, numOfInfos, sizeof(SBindInfo), NULL, tBindInfoCompare);
}
int32_t code = 0;
int32_t numOfRows = infos[0].bind->num;
SArray *colValArray, *bufArray;
SColVal colVal;
if ((colValArray = taosArrayInit(numOfInfos, sizeof(SColVal))) == NULL) {
return terrno;
}
if ((bufArray = taosArrayInit(numOfInfos, sizeof(uint8_t *))) == NULL) {
taosArrayDestroy(colValArray);
return TSDB_CODE_OUT_OF_MEMORY;
}
for (int i = 0; i < numOfInfos; ++i) {
if (!taosArrayPush(bufArray, &infos[i].bind->buffer)) {
taosArrayDestroy(colValArray);
taosArrayDestroy(bufArray);
return TSDB_CODE_OUT_OF_MEMORY;
}
}
for (int32_t iRow = 0; iRow < numOfRows; iRow++) {
taosArrayClear(colValArray);
for (int32_t iInfo = 0; iInfo < numOfInfos; iInfo++) {
if (infos[iInfo].bind->is_null && infos[iInfo].bind->is_null[iRow]) {
if (infos[iInfo].bind->is_null[iRow] == 1) {
colVal = COL_VAL_NULL(infos[iInfo].columnId, infos[iInfo].type);
} else {
colVal = COL_VAL_NONE(infos[iInfo].columnId, infos[iInfo].type);
}
} else {
SValue value = {
.type = infos[iInfo].type,
};
if (IS_VAR_DATA_TYPE(infos[iInfo].type)) {
int32_t length = infos[iInfo].bind->length[iRow];
uint8_t **data = &((uint8_t **)TARRAY_DATA(bufArray))[iInfo];
value.nData = length;
value.pData = *data;
*data += length;
// value.pData = (uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bind->buffer_length * iRow;
} else {
uint8_t *val = (uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bytes * iRow;
if (TSDB_DATA_TYPE_BOOL == value.type && *val > 1) {
*val = 1;
}
(void)memcpy(&value.val, val,
/*(uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bind->buffer_length * iRow,*/
infos[iInfo].bytes /*bind->buffer_length*/);
}
colVal = COL_VAL_VALUE(infos[iInfo].columnId, value);
}
if (taosArrayPush(colValArray, &colVal) == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
goto _exit;
}
}
SRow *row;
if ((code = tRowBuild(colValArray, pTSchema, &row))) {
goto _exit;
}
if ((taosArrayPush(rowArray, &row)) == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
goto _exit;
}
}
_exit:
taosArrayDestroy(colValArray);
taosArrayDestroy(bufArray);
return code;
}
static int32_t tColDataCopyRowCell(SColData *pFromColData, int32_t iFromRow, SColData *pToColData, int32_t iToRow) { static int32_t tColDataCopyRowCell(SColData *pFromColData, int32_t iFromRow, SColData *pToColData, int32_t iToRow) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;

View File

@ -615,7 +615,7 @@ static int32_t taosAddClientCfg(SConfig *pCfg) {
tsKeepAliveIdle = TRANGE(tsKeepAliveIdle, 1, 72000); tsKeepAliveIdle = TRANGE(tsKeepAliveIdle, 1, 72000);
TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "keepAliveIdle", tsKeepAliveIdle, 1, 7200000, CFG_SCOPE_BOTH, CFG_DYN_ENT_BOTH)); TAOS_CHECK_RETURN(cfgAddInt32(pCfg, "keepAliveIdle", tsKeepAliveIdle, 1, 7200000, CFG_SCOPE_BOTH, CFG_DYN_ENT_BOTH));
tsNumOfTaskQueueThreads = tsNumOfCores; tsNumOfTaskQueueThreads = tsNumOfCores * 2;
tsNumOfTaskQueueThreads = TMAX(tsNumOfTaskQueueThreads, 16); tsNumOfTaskQueueThreads = TMAX(tsNumOfTaskQueueThreads, 16);
TAOS_CHECK_RETURN( TAOS_CHECK_RETURN(

View File

@ -171,8 +171,9 @@ int32_t epsetToStr(const SEpSet* pEpSet, char* pBuf, int32_t cap) {
ret = snprintf(pBuf + nwrite, cap, "}, inUse:%d", pEpSet->inUse); ret = snprintf(pBuf + nwrite, cap, "}, inUse:%d", pEpSet->inUse);
if (ret <= 0 || ret >= cap) { if (ret <= 0 || ret >= cap) {
return TSDB_CODE_OUT_OF_BUFFER; return TSDB_CODE_OUT_OF_BUFFER;
} else {
return TSDB_CODE_SUCCESS;
} }
return TSDB_CODE_SUCCESS;
} }
int32_t taosGenCrashJsonMsg(int signum, char** pMsg, int64_t clusterId, int64_t startTime) { int32_t taosGenCrashJsonMsg(int signum, char** pMsg, int64_t clusterId, int64_t startTime) {

View File

@ -43,22 +43,22 @@
#include "tcol.h" #include "tcol.h"
#include "tlog.h" #include "tlog.h"
#define DECODESQL() \ #define DECODESQL() \
do { \ do { \
if (!tDecodeIsEnd(&decoder)) { \ if (!tDecodeIsEnd(&decoder)) { \
if (tDecodeI32(&decoder, &pReq->sqlLen) < 0) return -1; \ TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pReq->sqlLen)); \
if (pReq->sqlLen > 0) { \ if (pReq->sqlLen > 0) { \
if (tDecodeBinaryAlloc(&decoder, (void **)&pReq->sql, NULL) < 0) return -1; \ TAOS_CHECK_EXIT(tDecodeBinaryAlloc(&decoder, (void **)&pReq->sql, NULL)); \
} \ } \
} \ } \
} while (0) } while (0)
#define ENCODESQL() \ #define ENCODESQL() \
do { \ do { \
if (tEncodeI32(&encoder, pReq->sqlLen) < 0) return -1; \ TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->sqlLen)); \
if (pReq->sqlLen > 0) { \ if (pReq->sqlLen > 0) { \
if (tEncodeBinary(&encoder, pReq->sql, pReq->sqlLen) < 0) return -1; \ TAOS_CHECK_EXIT(tEncodeBinary(&encoder, (const uint8_t *)pReq->sql, pReq->sqlLen)); \
} \ } \
} while (0) } while (0)
#define FREESQL() \ #define FREESQL() \
@ -1243,19 +1243,7 @@ _exit:
tDecoderClear(&decoder); tDecoderClear(&decoder);
return code; return code;
} }
// int32_t tSerializeSDropTagIdxReq(void *buf, int32_t bufLen, SDropTagIndexReq *pReq) {
// SEncoder encoder = {0};
// tEncoderInit(&encoder, buf, bufLen);
// if (tStartEncode(&encoder) < 0) return -1;
// tEndEncode(&encoder);
// if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
// if (tEncodeI8(&encoder, pReq->igNotExists) < 0) return -1;
// int32_t tlen = encoder.pos;
// tEncoderClear(&encoder);
// return tlen;
// }
int32_t tDeserializeSDropTagIdxReq(void *buf, int32_t bufLen, SDropTagIndexReq *pReq) { int32_t tDeserializeSDropTagIdxReq(void *buf, int32_t bufLen, SDropTagIndexReq *pReq) {
SDecoder decoder = {0}; SDecoder decoder = {0};
int32_t code = 0; int32_t code = 0;
@ -1307,32 +1295,6 @@ void tFreeSMCreateFullTextReq(SMCreateFullTextReq *pReq) {
// impl later // impl later
return; return;
} }
// int32_t tSerializeSMDropFullTextReq(void *buf, int32_t bufLen, SMDropFullTextReq *pReq) {
// SEncoder encoder = {0};
// tEncoderInit(&encoder, buf, bufLen);
// if (tStartEncode(&encoder) < 0) return -1;
// if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
// if (tEncodeI8(&encoder, pReq->igNotExists) < 0) return -1;
// tEndEncode(&encoder);
// int32_t tlen = encoder.pos;
// tEncoderClear(&encoder);
// return tlen;
// }
// int32_t tDeserializeSMDropFullTextReq(void *buf, int32_t bufLen, SMDropFullTextReq *pReq) {
// SDecoder decoder = {0};
// tDecoderInit(&decoder, buf, bufLen);
// if (tStartDecode(&decoder) < 0) return -1;
// if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
// if (tDecodeI8(&decoder, &pReq->igNotExists) < 0) return -1;
// tEndDecode(&decoder);
// tDecoderClear(&decoder);
// return 0;
// }
int32_t tSerializeSNotifyReq(void *buf, int32_t bufLen, SNotifyReq *pReq) { int32_t tSerializeSNotifyReq(void *buf, int32_t bufLen, SNotifyReq *pReq) {
SEncoder encoder = {0}; SEncoder encoder = {0};
@ -2108,7 +2070,7 @@ int32_t tSerializeSAlterUserReq(void *buf, int32_t bufLen, SAlterUserReq *pReq)
if (len > 0) { if (len > 0) {
TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->tabName)); TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->tabName));
} }
TAOS_CHECK_EXIT(tEncodeBinary(&encoder, pReq->tagCond, pReq->tagCondLen)); TAOS_CHECK_EXIT(tEncodeBinary(&encoder, (const uint8_t *)pReq->tagCond, pReq->tagCondLen));
TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->numIpRanges)); TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->numIpRanges));
for (int32_t i = 0; i < pReq->numIpRanges; ++i) { for (int32_t i = 0; i < pReq->numIpRanges; ++i) {
TAOS_CHECK_EXIT(tEncodeU32(&encoder, pReq->pIpRanges[i].ip)); TAOS_CHECK_EXIT(tEncodeU32(&encoder, pReq->pIpRanges[i].ip));
@ -3386,6 +3348,8 @@ void tFreeSRetrieveFuncRsp(SRetrieveFuncRsp *pRsp) {
} }
int32_t tSerializeSTableCfgReq(void *buf, int32_t bufLen, STableCfgReq *pReq) { int32_t tSerializeSTableCfgReq(void *buf, int32_t bufLen, STableCfgReq *pReq) {
int32_t code = 0;
int32_t lino;
int32_t headLen = sizeof(SMsgHead); int32_t headLen = sizeof(SMsgHead);
if (buf != NULL) { if (buf != NULL) {
buf = (char *)buf + headLen; buf = (char *)buf + headLen;
@ -3395,26 +3359,34 @@ int32_t tSerializeSTableCfgReq(void *buf, int32_t bufLen, STableCfgReq *pReq) {
SEncoder encoder = {0}; SEncoder encoder = {0};
tEncoderInit(&encoder, buf, bufLen); tEncoderInit(&encoder, buf, bufLen);
if (tStartEncode(&encoder) < 0) return -1; TAOS_CHECK_EXIT(tStartEncode(&encoder));
if (tEncodeCStr(&encoder, pReq->dbFName) < 0) return -1; TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->dbFName));
if (tEncodeCStr(&encoder, pReq->tbName) < 0) return -1; TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->tbName));
tEndEncode(&encoder); tEndEncode(&encoder);
int32_t tlen = encoder.pos; _exit:
tEncoderClear(&encoder); if (code) {
tEncoderClear(&encoder);
return code;
} else {
int32_t tlen = encoder.pos;
tEncoderClear(&encoder);
if (buf != NULL) { if (buf != NULL) {
SMsgHead *pHead = (SMsgHead *)((char *)buf - headLen); SMsgHead *pHead = (SMsgHead *)((char *)buf - headLen);
pHead->vgId = htonl(pReq->header.vgId); pHead->vgId = htonl(pReq->header.vgId);
pHead->contLen = htonl(tlen + headLen); pHead->contLen = htonl(tlen + headLen);
}
return tlen + headLen;
} }
return tlen + headLen;
} }
int32_t tDeserializeSTableCfgReq(void *buf, int32_t bufLen, STableCfgReq *pReq) { int32_t tDeserializeSTableCfgReq(void *buf, int32_t bufLen, STableCfgReq *pReq) {
int32_t headLen = sizeof(SMsgHead); int32_t headLen = sizeof(SMsgHead);
int32_t code = 0;
int32_t lino;
SMsgHead *pHead = buf; SMsgHead *pHead = buf;
pHead->vgId = pReq->header.vgId; pHead->vgId = pReq->header.vgId;
pHead->contLen = pReq->header.contLen; pHead->contLen = pReq->header.contLen;
@ -3422,13 +3394,14 @@ int32_t tDeserializeSTableCfgReq(void *buf, int32_t bufLen, STableCfgReq *pReq)
SDecoder decoder = {0}; SDecoder decoder = {0};
tDecoderInit(&decoder, (char *)buf + headLen, bufLen - headLen); tDecoderInit(&decoder, (char *)buf + headLen, bufLen - headLen);
if (tStartDecode(&decoder) < 0) return -1; TAOS_CHECK_EXIT(tStartDecode(&decoder));
if (tDecodeCStrTo(&decoder, pReq->dbFName) < 0) return -1; TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->dbFName));
if (tDecodeCStrTo(&decoder, pReq->tbName) < 0) return -1; TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->tbName));
tEndDecode(&decoder); tEndDecode(&decoder);
_exit:
tDecoderClear(&decoder); tDecoderClear(&decoder);
return 0; return code;
} }
int32_t tSerializeSTableCfgRsp(void *buf, int32_t bufLen, STableCfgRsp *pRsp) { int32_t tSerializeSTableCfgRsp(void *buf, int32_t bufLen, STableCfgRsp *pRsp) {
@ -4683,14 +4656,22 @@ _exit:
int32_t tSerializeSTrimDbReq(void *buf, int32_t bufLen, STrimDbReq *pReq) { int32_t tSerializeSTrimDbReq(void *buf, int32_t bufLen, STrimDbReq *pReq) {
SEncoder encoder = {0}; SEncoder encoder = {0};
int32_t code = 0;
int32_t lino;
int32_t tlen;
tEncoderInit(&encoder, buf, bufLen); tEncoderInit(&encoder, buf, bufLen);
if (tStartEncode(&encoder) < 0) return -1; TAOS_CHECK_EXIT(tStartEncode(&encoder));
if (tEncodeCStr(&encoder, pReq->db) < 0) return -1; TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->db));
if (tEncodeI32(&encoder, pReq->maxSpeed) < 0) return -1; TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->maxSpeed));
tEndEncode(&encoder); tEndEncode(&encoder);
int32_t tlen = encoder.pos; _exit:
if (code) {
tlen = code;
} else {
tlen = encoder.pos;
}
tEncoderClear(&encoder); tEncoderClear(&encoder);
return tlen; return tlen;
} }
@ -5726,6 +5707,8 @@ void tFreeSSTbHbRsp(SSTbHbRsp *pRsp) {
int32_t tSerializeSTableInfoReq(void *buf, int32_t bufLen, STableInfoReq *pReq) { int32_t tSerializeSTableInfoReq(void *buf, int32_t bufLen, STableInfoReq *pReq) {
int32_t headLen = sizeof(SMsgHead); int32_t headLen = sizeof(SMsgHead);
int32_t code = 0;
int32_t lino;
if (buf != NULL) { if (buf != NULL) {
buf = (char *)buf + headLen; buf = (char *)buf + headLen;
bufLen -= headLen; bufLen -= headLen;
@ -5734,26 +5717,33 @@ int32_t tSerializeSTableInfoReq(void *buf, int32_t bufLen, STableInfoReq *pReq)
SEncoder encoder = {0}; SEncoder encoder = {0};
tEncoderInit(&encoder, buf, bufLen); tEncoderInit(&encoder, buf, bufLen);
if (tStartEncode(&encoder) < 0) return -1; TAOS_CHECK_EXIT(tStartEncode(&encoder));
if (tEncodeCStr(&encoder, pReq->dbFName) < 0) return -1; TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->dbFName));
if (tEncodeCStr(&encoder, pReq->tbName) < 0) return -1; TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->tbName));
tEndEncode(&encoder); tEndEncode(&encoder);
int32_t tlen = encoder.pos; _exit:
tEncoderClear(&encoder); if (code) {
tEncoderClear(&encoder);
return code;
} else {
int32_t tlen = encoder.pos;
tEncoderClear(&encoder);
if (buf != NULL) { if (buf != NULL) {
SMsgHead *pHead = (SMsgHead *)((char *)buf - headLen); SMsgHead *pHead = (SMsgHead *)((char *)buf - headLen);
pHead->vgId = htonl(pReq->header.vgId); pHead->vgId = htonl(pReq->header.vgId);
pHead->contLen = htonl(tlen + headLen); pHead->contLen = htonl(tlen + headLen);
}
return tlen + headLen;
} }
return tlen + headLen;
} }
int32_t tDeserializeSTableInfoReq(void *buf, int32_t bufLen, STableInfoReq *pReq) { int32_t tDeserializeSTableInfoReq(void *buf, int32_t bufLen, STableInfoReq *pReq) {
int32_t headLen = sizeof(SMsgHead); int32_t headLen = sizeof(SMsgHead);
int32_t code = 0;
int32_t lino;
SMsgHead *pHead = buf; SMsgHead *pHead = buf;
pHead->vgId = pReq->header.vgId; pHead->vgId = pReq->header.vgId;
pHead->contLen = pReq->header.contLen; pHead->contLen = pReq->header.contLen;
@ -5761,13 +5751,14 @@ int32_t tDeserializeSTableInfoReq(void *buf, int32_t bufLen, STableInfoReq *pReq
SDecoder decoder = {0}; SDecoder decoder = {0};
tDecoderInit(&decoder, (char *)buf + headLen, bufLen - headLen); tDecoderInit(&decoder, (char *)buf + headLen, bufLen - headLen);
if (tStartDecode(&decoder) < 0) return -1; TAOS_CHECK_EXIT(tStartDecode(&decoder));
if (tDecodeCStrTo(&decoder, pReq->dbFName) < 0) return -1; TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->dbFName));
if (tDecodeCStrTo(&decoder, pReq->tbName) < 0) return -1; TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->tbName));
tEndDecode(&decoder); tEndDecode(&decoder);
_exit:
tDecoderClear(&decoder); tDecoderClear(&decoder);
return 0; return code;
} }
int32_t tSerializeSMDropTopicReq(void *buf, int32_t bufLen, SMDropTopicReq *pReq) { int32_t tSerializeSMDropTopicReq(void *buf, int32_t bufLen, SMDropTopicReq *pReq) {
@ -6393,7 +6384,7 @@ int32_t tSerializeSQueryCompactProgressReq(void *buf, int32_t bufLen, SQueryComp
int32_t tlen; int32_t tlen;
tEncoderInit(&encoder, buf, bufLen); tEncoderInit(&encoder, buf, bufLen);
if (tStartEncode(&encoder) < 0) return -1; TAOS_CHECK_EXIT(tStartEncode(&encoder));
TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->compactId)); TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->compactId));
TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->vgId)); TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->vgId));
@ -7768,7 +7759,9 @@ int32_t tDeserializeSMArbUpdateGroupBatchReq(void *buf, int32_t bufLen, SMArbUpd
TAOS_CHECK_EXIT(tDecodeI32(&decoder, &sz)); TAOS_CHECK_EXIT(tDecodeI32(&decoder, &sz));
SArray *updateArray = taosArrayInit(sz, sizeof(SMArbUpdateGroup)); SArray *updateArray = taosArrayInit(sz, sizeof(SMArbUpdateGroup));
if (!updateArray) return -1; if (!updateArray) {
TAOS_CHECK_EXIT(terrno);
}
for (int32_t i = 0; i < sz; i++) { for (int32_t i = 0; i < sz; i++) {
SMArbUpdateGroup group = {0}; SMArbUpdateGroup group = {0};
@ -7939,6 +7932,8 @@ void tFreeSExplainRsp(SExplainRsp *pRsp) {
} }
int32_t tSerializeSBatchReq(void *buf, int32_t bufLen, SBatchReq *pReq) { int32_t tSerializeSBatchReq(void *buf, int32_t bufLen, SBatchReq *pReq) {
int32_t code = 0;
int32_t lino;
int32_t headLen = sizeof(SMsgHead); int32_t headLen = sizeof(SMsgHead);
if (buf != NULL) { if (buf != NULL) {
buf = (char *)buf + headLen; buf = (char *)buf + headLen;
@ -7947,35 +7942,42 @@ int32_t tSerializeSBatchReq(void *buf, int32_t bufLen, SBatchReq *pReq) {
SEncoder encoder = {0}; SEncoder encoder = {0};
tEncoderInit(&encoder, buf, bufLen); tEncoderInit(&encoder, buf, bufLen);
if (tStartEncode(&encoder) < 0) return -1; TAOS_CHECK_EXIT(tStartEncode(&encoder));
int32_t num = taosArrayGetSize(pReq->pMsgs); int32_t num = taosArrayGetSize(pReq->pMsgs);
if (tEncodeI32(&encoder, num) < 0) return -1; TAOS_CHECK_EXIT(tEncodeI32(&encoder, num));
for (int32_t i = 0; i < num; ++i) { for (int32_t i = 0; i < num; ++i) {
SBatchMsg *pMsg = taosArrayGet(pReq->pMsgs, i); SBatchMsg *pMsg = taosArrayGet(pReq->pMsgs, i);
if (tEncodeI32(&encoder, pMsg->msgIdx) < 0) return -1; TAOS_CHECK_EXIT(tEncodeI32(&encoder, pMsg->msgIdx));
if (tEncodeI32(&encoder, pMsg->msgType) < 0) return -1; TAOS_CHECK_EXIT(tEncodeI32(&encoder, pMsg->msgType));
if (tEncodeI32(&encoder, pMsg->msgLen) < 0) return -1; TAOS_CHECK_EXIT(tEncodeI32(&encoder, pMsg->msgLen));
if (tEncodeBinary(&encoder, pMsg->msg, pMsg->msgLen) < 0) return -1; TAOS_CHECK_EXIT(tEncodeBinary(&encoder, pMsg->msg, pMsg->msgLen));
} }
tEndEncode(&encoder); tEndEncode(&encoder);
int32_t tlen = encoder.pos; _exit:
tEncoderClear(&encoder); if (code) {
tEncoderClear(&encoder);
return code;
} else {
int32_t tlen = encoder.pos;
tEncoderClear(&encoder);
if (buf != NULL) { if (buf != NULL) {
SMsgHead *pHead = (SMsgHead *)((char *)buf - headLen); SMsgHead *pHead = (SMsgHead *)((char *)buf - headLen);
pHead->vgId = htonl(pReq->header.vgId); pHead->vgId = htonl(pReq->header.vgId);
pHead->contLen = htonl(tlen + headLen); pHead->contLen = htonl(tlen + headLen);
}
return tlen + headLen;
} }
return tlen + headLen;
} }
int32_t tDeserializeSBatchReq(void *buf, int32_t bufLen, SBatchReq *pReq) { int32_t tDeserializeSBatchReq(void *buf, int32_t bufLen, SBatchReq *pReq) {
int32_t headLen = sizeof(SMsgHead); int32_t headLen = sizeof(SMsgHead);
int32_t code = 0;
int32_t lino;
SMsgHead *pHead = buf; SMsgHead *pHead = buf;
pHead->vgId = pReq->header.vgId; pHead->vgId = pReq->header.vgId;
pHead->contLen = pReq->header.contLen; pHead->contLen = pReq->header.contLen;
@ -7983,33 +7985,37 @@ int32_t tDeserializeSBatchReq(void *buf, int32_t bufLen, SBatchReq *pReq) {
SDecoder decoder = {0}; SDecoder decoder = {0};
tDecoderInit(&decoder, (char *)buf + headLen, bufLen - headLen); tDecoderInit(&decoder, (char *)buf + headLen, bufLen - headLen);
if (tStartDecode(&decoder) < 0) return -1; TAOS_CHECK_EXIT(tStartDecode(&decoder));
int32_t num = 0; int32_t num = 0;
if (tDecodeI32(&decoder, &num) < 0) return -1; TAOS_CHECK_EXIT(tDecodeI32(&decoder, &num));
if (num <= 0) { if (num <= 0) {
pReq->pMsgs = NULL; pReq->pMsgs = NULL;
tEndDecode(&decoder); tEndDecode(&decoder);
tDecoderClear(&decoder); tDecoderClear(&decoder);
return 0; return 0;
} }
pReq->pMsgs = taosArrayInit(num, sizeof(SBatchMsg)); pReq->pMsgs = taosArrayInit(num, sizeof(SBatchMsg));
if (NULL == pReq->pMsgs) return -1; if (NULL == pReq->pMsgs) {
TAOS_CHECK_EXIT(terrno);
}
for (int32_t i = 0; i < num; ++i) { for (int32_t i = 0; i < num; ++i) {
SBatchMsg msg = {0}; SBatchMsg msg = {0};
if (tDecodeI32(&decoder, &msg.msgIdx) < 0) return -1; TAOS_CHECK_EXIT(tDecodeI32(&decoder, &msg.msgIdx));
if (tDecodeI32(&decoder, &msg.msgType) < 0) return -1; TAOS_CHECK_EXIT(tDecodeI32(&decoder, &msg.msgType));
if (tDecodeI32(&decoder, &msg.msgLen) < 0) return -1; TAOS_CHECK_EXIT(tDecodeI32(&decoder, &msg.msgLen));
if (tDecodeBinaryAlloc(&decoder, &msg.msg, NULL) < 0) return -1; TAOS_CHECK_EXIT(tDecodeBinaryAlloc(&decoder, &msg.msg, NULL));
if (NULL == taosArrayPush(pReq->pMsgs, &msg)) return -1; if (NULL == taosArrayPush(pReq->pMsgs, &msg)) {
TAOS_CHECK_EXIT(terrno);
}
} }
tEndDecode(&decoder); tEndDecode(&decoder);
_exit:
tDecoderClear(&decoder); tDecoderClear(&decoder);
return 0; return code;
} }
int32_t tSerializeSBatchRsp(void *buf, int32_t bufLen, SBatchRsp *pRsp) { int32_t tSerializeSBatchRsp(void *buf, int32_t bufLen, SBatchRsp *pRsp) {
@ -8169,7 +8175,9 @@ int32_t tDeserializeSMqHbRsp(void *buf, int32_t bufLen, SMqHbRsp *pRsp) {
TAOS_CHECK_EXIT(tDecodeI32(&decoder, &sz)); TAOS_CHECK_EXIT(tDecodeI32(&decoder, &sz));
if (sz > 0) { if (sz > 0) {
pRsp->topicPrivileges = taosArrayInit(sz, sizeof(STopicPrivilege)); pRsp->topicPrivileges = taosArrayInit(sz, sizeof(STopicPrivilege));
if (NULL == pRsp->topicPrivileges) return -1; if (NULL == pRsp->topicPrivileges) {
TAOS_CHECK_EXIT(terrno);
}
for (int32_t i = 0; i < sz; ++i) { for (int32_t i = 0; i < sz; ++i) {
STopicPrivilege *data = taosArrayReserve(pRsp->topicPrivileges, 1); STopicPrivilege *data = taosArrayReserve(pRsp->topicPrivileges, 1);
TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, data->topic)); TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, data->topic));
@ -8529,7 +8537,7 @@ int32_t tSerializeSResFetchReq(void *buf, int32_t bufLen, SResFetchReq *pReq) {
TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->execId)); TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->execId));
if (pReq->pOpParam) { if (pReq->pOpParam) {
TAOS_CHECK_EXIT(tEncodeI32(&encoder, 1)); TAOS_CHECK_EXIT(tEncodeI32(&encoder, 1));
if (tSerializeSOperatorParam(&encoder, pReq->pOpParam) < 0) return -1; TAOS_CHECK_EXIT(tSerializeSOperatorParam(&encoder, pReq->pOpParam));
} else { } else {
TAOS_CHECK_EXIT(tEncodeI32(&encoder, 0)); TAOS_CHECK_EXIT(tEncodeI32(&encoder, 0));
} }
@ -9021,7 +9029,9 @@ int32_t tDeserializeSSchedulerHbRsp(void *buf, int32_t bufLen, SSchedulerHbRsp *
TAOS_CHECK_EXIT(tDecodeI32(&decoder, &num)); TAOS_CHECK_EXIT(tDecodeI32(&decoder, &num));
if (num > 0) { if (num > 0) {
pRsp->taskStatus = taosArrayInit(num, sizeof(STaskStatus)); pRsp->taskStatus = taosArrayInit(num, sizeof(STaskStatus));
if (NULL == pRsp->taskStatus) return -1; if (NULL == pRsp->taskStatus) {
TAOS_CHECK_EXIT(terrno);
}
for (int32_t i = 0; i < num; ++i) { for (int32_t i = 0; i < num; ++i) {
STaskStatus status = {0}; STaskStatus status = {0};
TAOS_CHECK_EXIT(tDecodeU64(&decoder, &status.queryId)); TAOS_CHECK_EXIT(tDecodeU64(&decoder, &status.queryId));
@ -9289,8 +9299,12 @@ int32_t tSerializeSCMCreateStreamReq(void *buf, int32_t bufLen, const SCMCreateS
TAOS_CHECK_EXIT(tEncodeI64(&encoder, pReq->maxDelay)); TAOS_CHECK_EXIT(tEncodeI64(&encoder, pReq->maxDelay));
TAOS_CHECK_EXIT(tEncodeI64(&encoder, pReq->watermark)); TAOS_CHECK_EXIT(tEncodeI64(&encoder, pReq->watermark));
TAOS_CHECK_EXIT(tEncodeI8(&encoder, pReq->igExpired)); TAOS_CHECK_EXIT(tEncodeI8(&encoder, pReq->igExpired));
if (sqlLen > 0 && tEncodeCStr(&encoder, pReq->sql) < 0) return -1; if (sqlLen > 0) {
if (astLen > 0 && tEncodeCStr(&encoder, pReq->ast) < 0) return -1; TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->sql));
}
if (astLen > 0) {
TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->ast));
}
TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->numOfTags)); TAOS_CHECK_EXIT(tEncodeI32(&encoder, pReq->numOfTags));
for (int32_t i = 0; i < pReq->numOfTags; ++i) { for (int32_t i = 0; i < pReq->numOfTags; ++i) {
SField *pField = taosArrayGet(pReq->pTags, i); SField *pField = taosArrayGet(pReq->pTags, i);
@ -9735,7 +9749,9 @@ int tDecodeSVCreateTbReq(SDecoder *pCoder, SVCreateTbReq *pReq) {
TAOS_CHECK_EXIT(tDecodeI32(pCoder, &pReq->commentLen)); TAOS_CHECK_EXIT(tDecodeI32(pCoder, &pReq->commentLen));
if (pReq->commentLen > 0) { if (pReq->commentLen > 0) {
pReq->comment = taosMemoryMalloc(pReq->commentLen + 1); pReq->comment = taosMemoryMalloc(pReq->commentLen + 1);
if (pReq->comment == NULL) return -1; if (pReq->comment == NULL) {
TAOS_CHECK_EXIT(terrno);
}
TAOS_CHECK_EXIT(tDecodeCStrTo(pCoder, pReq->comment)); TAOS_CHECK_EXIT(tDecodeCStrTo(pCoder, pReq->comment));
} }
@ -10244,7 +10260,9 @@ int32_t tDecodeSVAlterTbRsp(SDecoder *pDecoder, SVAlterTbRsp *pRsp) {
TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &meta)); TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &meta));
if (meta) { if (meta) {
pRsp->pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp)); pRsp->pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp));
if (NULL == pRsp->pMeta) return -1; if (NULL == pRsp->pMeta) {
TAOS_CHECK_EXIT(terrno);
}
TAOS_CHECK_EXIT(tDecodeSTableMetaRsp(pDecoder, pRsp->pMeta)); TAOS_CHECK_EXIT(tDecodeSTableMetaRsp(pDecoder, pRsp->pMeta));
} }
tEndDecode(pDecoder); tEndDecode(pDecoder);
@ -10275,7 +10293,9 @@ int32_t tDecodeSMAlterStbRsp(SDecoder *pDecoder, SMAlterStbRsp *pRsp) {
TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &meta)); TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &meta));
if (meta) { if (meta) {
pRsp->pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp)); pRsp->pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp));
if (NULL == pRsp->pMeta) return -1; if (NULL == pRsp->pMeta) {
TAOS_CHECK_EXIT(terrno);
}
TAOS_CHECK_EXIT(tDecodeSTableMetaRsp(pDecoder, pRsp->pMeta)); TAOS_CHECK_EXIT(tDecodeSTableMetaRsp(pDecoder, pRsp->pMeta));
} }
tEndDecode(pDecoder); tEndDecode(pDecoder);
@ -10383,8 +10403,8 @@ int32_t tDecodeSTqOffsetVal(SDecoder *pDecoder, STqOffsetVal *pOffsetVal) {
if (offsetVersion >= TQ_OFFSET_VERSION) { if (offsetVersion >= TQ_OFFSET_VERSION) {
TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pOffsetVal->primaryKey.type)); TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pOffsetVal->primaryKey.type));
if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) { if (IS_VAR_DATA_TYPE(pOffsetVal->primaryKey.type)) {
if (tDecodeBinaryAlloc32(pDecoder, (void **)&pOffsetVal->primaryKey.pData, &pOffsetVal->primaryKey.nData) < 0) TAOS_CHECK_EXIT(
return -1; tDecodeBinaryAlloc32(pDecoder, (void **)&pOffsetVal->primaryKey.pData, &pOffsetVal->primaryKey.nData));
} else { } else {
TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pOffsetVal->primaryKey.val)); TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pOffsetVal->primaryKey.val));
} }
@ -11697,7 +11717,9 @@ int32_t tDeserializeSViewHbRsp(void *buf, int32_t bufLen, SViewHbRsp *pRsp) {
for (int32_t i = 0; i < numOfMeta; ++i) { for (int32_t i = 0; i < numOfMeta; ++i) {
SViewMetaRsp *metaRsp = taosMemoryCalloc(1, sizeof(SViewMetaRsp)); SViewMetaRsp *metaRsp = taosMemoryCalloc(1, sizeof(SViewMetaRsp));
if (NULL == metaRsp) return -1; if (NULL == metaRsp) {
TAOS_CHECK_EXIT(terrno);
}
TAOS_CHECK_EXIT(tDecodeSViewMetaRsp(&decoder, metaRsp)); TAOS_CHECK_EXIT(tDecodeSViewMetaRsp(&decoder, metaRsp));
if (taosArrayPush(pRsp->pViewRsp, &metaRsp) == NULL) { if (taosArrayPush(pRsp->pViewRsp, &metaRsp) == NULL) {
TAOS_CHECK_EXIT(terrno); TAOS_CHECK_EXIT(terrno);

View File

@ -147,12 +147,14 @@ static void dmSetSignalHandle() {
(void)taosSetSignal(SIGQUIT, dmStopDnode); (void)taosSetSignal(SIGQUIT, dmStopDnode);
#endif #endif
#if 0
#ifndef WINDOWS #ifndef WINDOWS
(void)taosSetSignal(SIGBUS, dmLogCrash); (void)taosSetSignal(SIGBUS, dmLogCrash);
#endif #endif
(void)taosSetSignal(SIGABRT, dmLogCrash); (void)taosSetSignal(SIGABRT, dmLogCrash);
(void)taosSetSignal(SIGFPE, dmLogCrash); (void)taosSetSignal(SIGFPE, dmLogCrash);
(void)taosSetSignal(SIGSEGV, dmLogCrash); (void)taosSetSignal(SIGSEGV, dmLogCrash);
#endif
} }
static int32_t dmParseArgs(int32_t argc, char const *argv[]) { static int32_t dmParseArgs(int32_t argc, char const *argv[]) {

View File

@ -71,20 +71,20 @@ int32_t mmReadFile(const char *path, SMnodeOpt *pOption) {
} }
if (taosStatFile(file, NULL, NULL, NULL) < 0) { if (taosStatFile(file, NULL, NULL, NULL) < 0) {
dInfo("mnode file:%s not exist, reason:%s", file, tstrerror(TAOS_SYSTEM_ERROR(errno))); dInfo("mnode file:%s not exist, reason:%s", file, tstrerror(terrno));
return 0; return 0;
} }
pFile = taosOpenFile(file, TD_FILE_READ); pFile = taosOpenFile(file, TD_FILE_READ);
if (pFile == NULL) { if (pFile == NULL) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
dError("failed to open mnode file:%s since %s", file, tstrerror(code)); dError("failed to open mnode file:%s since %s", file, tstrerror(code));
goto _OVER; goto _OVER;
} }
int64_t size = 0; int64_t size = 0;
if (taosFStatFile(pFile, &size, NULL) < 0) { code = taosFStatFile(pFile, &size, NULL);
code = TAOS_SYSTEM_ERROR(errno); if (code != 0) {
dError("failed to fstat mnode file:%s since %s", file, tstrerror(code)); dError("failed to fstat mnode file:%s since %s", file, tstrerror(code));
goto _OVER; goto _OVER;
} }
@ -96,7 +96,7 @@ int32_t mmReadFile(const char *path, SMnodeOpt *pOption) {
} }
if (taosReadFile(pFile, pData, size) != size) { if (taosReadFile(pFile, pData, size) != size) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
dError("failed to read mnode file:%s since %s", file, tstrerror(code)); dError("failed to read mnode file:%s since %s", file, tstrerror(code));
goto _OVER; goto _OVER;
} }
@ -197,17 +197,17 @@ int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) {
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
if (pFile == NULL) { if (pFile == NULL) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
goto _OVER; goto _OVER;
} }
int32_t len = strlen(buffer); int32_t len = strlen(buffer);
if (taosWriteFile(pFile, buffer, len) <= 0) { if (taosWriteFile(pFile, buffer, len) <= 0) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
goto _OVER; goto _OVER;
} }
if (taosFsyncFile(pFile) < 0) { if (taosFsyncFile(pFile) < 0) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
goto _OVER; goto _OVER;
} }
@ -215,10 +215,7 @@ int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) {
code = TAOS_SYSTEM_ERROR(errno); code = TAOS_SYSTEM_ERROR(errno);
goto _OVER; goto _OVER;
} }
if (taosRenameFile(file, realfile) != 0) { TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER);
code = TAOS_SYSTEM_ERROR(errno);
goto _OVER;
}
dInfo("succeed to write mnode file:%s, deloyed:%d", realfile, pOption->deploy); dInfo("succeed to write mnode file:%s, deloyed:%d", realfile, pOption->deploy);

View File

@ -106,7 +106,7 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t
snprintf(file, sizeof(file), "%s%svnodes.json", pMgmt->path, TD_DIRSEP); snprintf(file, sizeof(file), "%s%svnodes.json", pMgmt->path, TD_DIRSEP);
if (taosStatFile(file, NULL, NULL, NULL) < 0) { if (taosStatFile(file, NULL, NULL, NULL) < 0) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
dInfo("vnode file:%s not exist, reason:%s", file, tstrerror(code)); dInfo("vnode file:%s not exist, reason:%s", file, tstrerror(code));
code = 0; code = 0;
return code; return code;
@ -114,14 +114,14 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t
pFile = taosOpenFile(file, TD_FILE_READ); pFile = taosOpenFile(file, TD_FILE_READ);
if (pFile == NULL) { if (pFile == NULL) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
dError("failed to open vnode file:%s since %s", file, tstrerror(code)); dError("failed to open vnode file:%s since %s", file, tstrerror(code));
goto _OVER; goto _OVER;
} }
int64_t size = 0; int64_t size = 0;
if (taosFStatFile(pFile, &size, NULL) < 0) { code = taosFStatFile(pFile, &size, NULL);
code = TAOS_SYSTEM_ERROR(errno); if (code != 0) {
dError("failed to fstat mnode file:%s since %s", file, tstrerror(code)); dError("failed to fstat mnode file:%s since %s", file, tstrerror(code));
goto _OVER; goto _OVER;
} }
@ -133,7 +133,7 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t
} }
if (taosReadFile(pFile, pData, size) != size) { if (taosReadFile(pFile, pData, size) != size) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
dError("failed to read vnode file:%s since %s", file, tstrerror(code)); dError("failed to read vnode file:%s since %s", file, tstrerror(code));
goto _OVER; goto _OVER;
} }
@ -234,13 +234,13 @@ int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) {
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
if (pFile == NULL) { if (pFile == NULL) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
goto _OVER; goto _OVER;
} }
int32_t len = strlen(buffer); int32_t len = strlen(buffer);
if (taosWriteFile(pFile, buffer, len) <= 0) { if (taosWriteFile(pFile, buffer, len) <= 0) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
goto _OVER; goto _OVER;
} }
if (taosFsyncFile(pFile) < 0) { if (taosFsyncFile(pFile) < 0) {
@ -253,12 +253,8 @@ int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) {
code = TAOS_SYSTEM_ERROR(errno); code = TAOS_SYSTEM_ERROR(errno);
goto _OVER; goto _OVER;
} }
if (taosRenameFile(file, realfile) != 0) { TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER);
code = TAOS_SYSTEM_ERROR(errno);
goto _OVER;
}
code = 0;
dInfo("succeed to write vnodes file:%s, vnodes:%d", realfile, numOfVnodes); dInfo("succeed to write vnodes file:%s, vnodes:%d", realfile, numOfVnodes);
_OVER: _OVER:

View File

@ -203,14 +203,14 @@ int32_t dmReadEps(SDnodeData *pData) {
pFile = taosOpenFile(file, TD_FILE_READ); pFile = taosOpenFile(file, TD_FILE_READ);
if (pFile == NULL) { if (pFile == NULL) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
dError("failed to open dnode file:%s since %s", file, terrstr()); dError("failed to open dnode file:%s since %s", file, terrstr());
goto _OVER; goto _OVER;
} }
int64_t size = 0; int64_t size = 0;
if (taosFStatFile(pFile, &size, NULL) < 0) { code = taosFStatFile(pFile, &size, NULL);
code = TAOS_SYSTEM_ERROR(errno); if (code != 0) {
dError("failed to fstat dnode file:%s since %s", file, terrstr()); dError("failed to fstat dnode file:%s since %s", file, terrstr());
goto _OVER; goto _OVER;
} }
@ -222,7 +222,7 @@ int32_t dmReadEps(SDnodeData *pData) {
} }
if (taosReadFile(pFile, content, size) != size) { if (taosReadFile(pFile, content, size) != size) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
dError("failed to read dnode file:%s since %s", file, terrstr()); dError("failed to read dnode file:%s since %s", file, terrstr());
goto _OVER; goto _OVER;
} }
@ -333,16 +333,15 @@ int32_t dmWriteEps(SDnodeData *pData) {
} }
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
if (pFile == NULL) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER); if (pFile == NULL) TAOS_CHECK_GOTO(terrno, NULL, _OVER);
int32_t len = strlen(buffer); int32_t len = strlen(buffer);
if (taosWriteFile(pFile, buffer, len) <= 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER); if (taosWriteFile(pFile, buffer, len) <= 0) TAOS_CHECK_GOTO(terrno, NULL, _OVER);
if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER); if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(terrno, NULL, _OVER);
(void)taosCloseFile(&pFile); (void)taosCloseFile(&pFile);
if (taosRenameFile(file, realfile) != 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER); TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER);
code = 0;
pData->updateTime = taosGetTimestampMs(); pData->updateTime = taosGetTimestampMs();
dInfo("succeed to write dnode file:%s, num:%d ver:%" PRId64, realfile, (int32_t)taosArrayGetSize(pData->dnodeEps), dInfo("succeed to write dnode file:%s, num:%d ver:%" PRId64, realfile, (int32_t)taosArrayGetSize(pData->dnodeEps),
pData->dnodeVer); pData->dnodeVer);
@ -599,7 +598,7 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) {
snprintf(file, sizeof(file), "%s%sdnode%sep.json", tsDataDir, TD_DIRSEP, TD_DIRSEP); snprintf(file, sizeof(file), "%s%sdnode%sep.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
if (taosStatFile(file, NULL, NULL, NULL) < 0) { if (taosStatFile(file, NULL, NULL, NULL) < 0) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
dDebug("dnode file:%s not exist, reason:%s", file, tstrerror(code)); dDebug("dnode file:%s not exist, reason:%s", file, tstrerror(code));
code = 0; code = 0;
goto _OVER; goto _OVER;
@ -607,14 +606,14 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) {
pFile = taosOpenFile(file, TD_FILE_READ); pFile = taosOpenFile(file, TD_FILE_READ);
if (pFile == NULL) { if (pFile == NULL) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
dError("failed to open dnode file:%s since %s", file, terrstr()); dError("failed to open dnode file:%s since %s", file, terrstr());
goto _OVER; goto _OVER;
} }
int64_t size = 0; int64_t size = 0;
if (taosFStatFile(pFile, &size, NULL) < 0) { code = taosFStatFile(pFile, &size, NULL);
code = TAOS_SYSTEM_ERROR(errno); if (code != 0) {
dError("failed to fstat dnode file:%s since %s", file, terrstr()); dError("failed to fstat dnode file:%s since %s", file, terrstr());
goto _OVER; goto _OVER;
} }
@ -626,7 +625,7 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) {
} }
if (taosReadFile(pFile, content, size) != size) { if (taosReadFile(pFile, content, size) != size) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = terrno;
dError("failed to read dnode file:%s since %s", file, terrstr()); dError("failed to read dnode file:%s since %s", file, terrstr());
goto _OVER; goto _OVER;
} }

View File

@ -56,14 +56,14 @@ int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) {
pFile = taosOpenFile(file, TD_FILE_READ); pFile = taosOpenFile(file, TD_FILE_READ);
if (pFile == NULL) { if (pFile == NULL) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
dError("failed to open file:%s since %s", file, tstrerror(code)); dError("failed to open file:%s since %s", file, tstrerror(code));
goto _OVER; goto _OVER;
} }
int64_t size = 0; int64_t size = 0;
if (taosFStatFile(pFile, &size, NULL) < 0) { code = taosFStatFile(pFile, &size, NULL);
code = TAOS_SYSTEM_ERROR(errno); if (code != 0) {
dError("failed to fstat file:%s since %s", file, tstrerror(code)); dError("failed to fstat file:%s since %s", file, tstrerror(code));
goto _OVER; goto _OVER;
} }
@ -75,7 +75,7 @@ int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) {
} }
if (taosReadFile(pFile, content, size) != size) { if (taosReadFile(pFile, content, size) != size) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
dError("failed to read file:%s since %s", file, tstrerror(code)); dError("failed to read file:%s since %s", file, tstrerror(code));
goto _OVER; goto _OVER;
} }
@ -148,17 +148,17 @@ int32_t dmWriteFile(const char *path, const char *name, bool deployed) {
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
if (pFile == NULL) { if (pFile == NULL) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
goto _OVER; goto _OVER;
} }
int32_t len = strlen(buffer); int32_t len = strlen(buffer);
if (taosWriteFile(pFile, buffer, len) <= 0) { if (taosWriteFile(pFile, buffer, len) <= 0) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
goto _OVER; goto _OVER;
} }
if (taosFsyncFile(pFile) < 0) { if (taosFsyncFile(pFile) < 0) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
goto _OVER; goto _OVER;
} }
@ -166,12 +166,8 @@ int32_t dmWriteFile(const char *path, const char *name, bool deployed) {
code = TAOS_SYSTEM_ERROR(errno); code = TAOS_SYSTEM_ERROR(errno);
goto _OVER; goto _OVER;
} }
if (taosRenameFile(file, realfile) != 0) { TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER);
code = TAOS_SYSTEM_ERROR(errno);
goto _OVER;
}
code = 0;
dInfo("succeed to write file:%s, deloyed:%d", realfile, deployed); dInfo("succeed to write file:%s, deloyed:%d", realfile, deployed);
_OVER: _OVER:
@ -192,7 +188,7 @@ int32_t dmCheckRunning(const char *dataDir, TdFilePtr *pFile) {
*pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_CLOEXEC); *pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_CLOEXEC);
if (*pFile == NULL) { if (*pFile == NULL) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
dError("failed to open file:%s since %s", filepath, tstrerror(code)); dError("failed to open file:%s since %s", filepath, tstrerror(code));
return code; return code;
} }
@ -203,7 +199,7 @@ int32_t dmCheckRunning(const char *dataDir, TdFilePtr *pFile) {
ret = taosLockFile(*pFile); ret = taosLockFile(*pFile);
if (ret == 0) break; if (ret == 0) break;
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
taosMsleep(1000); taosMsleep(1000);
retryTimes++; retryTimes++;
dError("failed to lock file:%s since %s, retryTimes:%d", filepath, tstrerror(code), retryTimes); dError("failed to lock file:%s since %s, retryTimes:%d", filepath, tstrerror(code), retryTimes);
@ -243,12 +239,12 @@ static int32_t dmWriteCheckCodeFile(char *file, char *realfile, char *key, bool
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
if (pFile == NULL) { if (pFile == NULL) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
goto _OVER; goto _OVER;
} }
if (taosWriteFile(pFile, opts.result, len) <= 0) { if (taosWriteFile(pFile, opts.result, len) <= 0) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
goto _OVER; goto _OVER;
} }
@ -262,10 +258,7 @@ static int32_t dmWriteCheckCodeFile(char *file, char *realfile, char *key, bool
goto _OVER; goto _OVER;
} }
if (taosRenameFile(file, realfile) != 0) { TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER);
code = TAOS_SYSTEM_ERROR(errno);
goto _OVER;
}
encryptDebug("succeed to write checkCode file:%s", realfile); encryptDebug("succeed to write checkCode file:%s", realfile);
@ -283,17 +276,17 @@ static int32_t dmWriteEncryptCodeFile(char *file, char *realfile, char *encryptC
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
if (pFile == NULL) { if (pFile == NULL) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
goto _OVER; goto _OVER;
} }
int32_t len = strlen(encryptCode); int32_t len = strlen(encryptCode);
if (taosWriteFile(pFile, encryptCode, len) <= 0) { if (taosWriteFile(pFile, encryptCode, len) <= 0) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
goto _OVER; goto _OVER;
} }
if (taosFsyncFile(pFile) < 0) { if (taosFsyncFile(pFile) < 0) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
goto _OVER; goto _OVER;
} }
@ -302,10 +295,7 @@ static int32_t dmWriteEncryptCodeFile(char *file, char *realfile, char *encryptC
goto _OVER; goto _OVER;
} }
if (taosRenameFile(file, realfile) != 0) { TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER);
code = TAOS_SYSTEM_ERROR(errno);
goto _OVER;
}
encryptDebug("succeed to write encryptCode file:%s", realfile); encryptDebug("succeed to write encryptCode file:%s", realfile);
@ -325,25 +315,25 @@ static int32_t dmCompareEncryptKey(char *file, char *key, bool toLogFile) {
pFile = taosOpenFile(file, TD_FILE_READ); pFile = taosOpenFile(file, TD_FILE_READ);
if (pFile == NULL) { if (pFile == NULL) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
encryptError("failed to open dnode file:%s since %s", file, tstrerror(code)); encryptError("failed to open dnode file:%s since %s", file, tstrerror(code));
goto _OVER; goto _OVER;
} }
if (taosFStatFile(pFile, &size, NULL) < 0) { code = taosFStatFile(pFile, &size, NULL);
code = TAOS_SYSTEM_ERROR(errno); if (code != 0) {
encryptError("failed to fstat dnode file:%s since %s", file, tstrerror(code)); encryptError("failed to fstat dnode file:%s since %s", file, tstrerror(code));
goto _OVER; goto _OVER;
} }
content = taosMemoryMalloc(size); content = taosMemoryMalloc(size);
if (content == NULL) { if (content == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY; code = terrno;
goto _OVER; goto _OVER;
} }
if (taosReadFile(pFile, content, size) != size) { if (taosReadFile(pFile, content, size) != size) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
encryptError("failed to read dnode file:%s since %s", file, tstrerror(code)); encryptError("failed to read dnode file:%s since %s", file, tstrerror(code));
goto _OVER; goto _OVER;
} }
@ -465,14 +455,14 @@ static int32_t dmReadEncryptCodeFile(char *file, char **output) {
pFile = taosOpenFile(file, TD_FILE_READ); pFile = taosOpenFile(file, TD_FILE_READ);
if (pFile == NULL) { if (pFile == NULL) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
dError("failed to open dnode file:%s since %s", file, tstrerror(code)); dError("failed to open dnode file:%s since %s", file, tstrerror(code));
goto _OVER; goto _OVER;
} }
int64_t size = 0; int64_t size = 0;
if (taosFStatFile(pFile, &size, NULL) < 0) { code = taosFStatFile(pFile, &size, NULL);
code = TAOS_SYSTEM_ERROR(errno); if (code != 0) {
dError("failed to fstat dnode file:%s since %s", file, tstrerror(code)); dError("failed to fstat dnode file:%s since %s", file, tstrerror(code));
goto _OVER; goto _OVER;
} }
@ -484,7 +474,7 @@ static int32_t dmReadEncryptCodeFile(char *file, char **output) {
} }
if (taosReadFile(pFile, content, size) != size) { if (taosReadFile(pFile, content, size) != size) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
dError("failed to read dnode file:%s since %s", file, tstrerror(code)); dError("failed to read dnode file:%s since %s", file, tstrerror(code));
goto _OVER; goto _OVER;
} }

View File

@ -114,7 +114,7 @@ int32_t mndDropStreamByDb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb);
int32_t mndPersistStream(STrans *pTrans, SStreamObj *pStream); int32_t mndPersistStream(STrans *pTrans, SStreamObj *pStream);
int32_t mndStreamRegisterTrans(STrans *pTrans, const char *pTransName, int64_t streamId); int32_t mndStreamRegisterTrans(STrans *pTrans, const char *pTransName, int64_t streamId);
int32_t mndStreamClearFinishedTrans(SMnode *pMnode, int32_t *pNumOfActiveChkpt); int32_t mndStreamClearFinishedTrans(SMnode *pMnode, int32_t *pNumOfActiveChkpt);
bool mndStreamTransConflictCheck(SMnode *pMnode, int64_t streamId, const char *pTransName, bool lock); int32_t mndStreamTransConflictCheck(SMnode *pMnode, int64_t streamId, const char *pTransName, bool lock);
int32_t mndStreamGetRelTrans(SMnode *pMnode, int64_t streamId); int32_t mndStreamGetRelTrans(SMnode *pMnode, int64_t streamId);
int32_t mndGetNumOfStreams(SMnode *pMnode, char *dbName, int32_t *pNumOfStreams); int32_t mndGetNumOfStreams(SMnode *pMnode, char *dbName, int32_t *pNumOfStreams);

View File

@ -55,36 +55,44 @@ void tFreeCompactObj(SCompactObj *pCompact) {}
int32_t tSerializeSCompactObj(void *buf, int32_t bufLen, const SCompactObj *pObj) { int32_t tSerializeSCompactObj(void *buf, int32_t bufLen, const SCompactObj *pObj) {
SEncoder encoder = {0}; SEncoder encoder = {0};
int32_t code = 0;
int32_t lino;
int32_t tlen;
tEncoderInit(&encoder, buf, bufLen); tEncoderInit(&encoder, buf, bufLen);
if (tStartEncode(&encoder) < 0) return -1; TAOS_CHECK_EXIT(tStartEncode(&encoder));
TAOS_CHECK_EXIT(tEncodeI32(&encoder, pObj->compactId));
if (tEncodeI32(&encoder, pObj->compactId) < 0) return -1; TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pObj->dbname));
if (tEncodeCStr(&encoder, pObj->dbname) < 0) return -1; TAOS_CHECK_EXIT(tEncodeI64(&encoder, pObj->startTime));
if (tEncodeI64(&encoder, pObj->startTime) < 0) return -1;
tEndEncode(&encoder); tEndEncode(&encoder);
int32_t tlen = encoder.pos; _exit:
if (code) {
tlen = code;
} else {
tlen = encoder.pos;
}
tEncoderClear(&encoder); tEncoderClear(&encoder);
return tlen; return tlen;
} }
int32_t tDeserializeSCompactObj(void *buf, int32_t bufLen, SCompactObj *pObj) { int32_t tDeserializeSCompactObj(void *buf, int32_t bufLen, SCompactObj *pObj) {
int8_t ex = 0; int32_t code = 0;
int32_t lino;
SDecoder decoder = {0}; SDecoder decoder = {0};
tDecoderInit(&decoder, buf, bufLen); tDecoderInit(&decoder, buf, bufLen);
TAOS_CHECK_RETURN(tStartDecode(&decoder)); TAOS_CHECK_EXIT(tStartDecode(&decoder));
TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pObj->compactId));
TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->compactId)); TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pObj->dbname));
TAOS_CHECK_RETURN(tDecodeCStrTo(&decoder, pObj->dbname)); TAOS_CHECK_EXIT(tDecodeI64(&decoder, &pObj->startTime));
TAOS_CHECK_RETURN(tDecodeI64(&decoder, &pObj->startTime));
tEndDecode(&decoder); tEndDecode(&decoder);
_exit:
tDecoderClear(&decoder); tDecoderClear(&decoder);
return 0; return code;
} }
SSdbRaw *mndCompactActionEncode(SCompactObj *pCompact) { SSdbRaw *mndCompactActionEncode(SCompactObj *pCompact) {
@ -633,8 +641,8 @@ void mndCompactSendProgressReq(SMnode *pMnode, SCompactObj *pCompact) {
static int32_t mndSaveCompactProgress(SMnode *pMnode, int32_t compactId) { static int32_t mndSaveCompactProgress(SMnode *pMnode, int32_t compactId) {
int32_t code = 0; int32_t code = 0;
bool needSave = false; bool needSave = false;
void *pIter = NULL; void *pIter = NULL;
while (1) { while (1) {
SCompactDetailObj *pDetail = NULL; SCompactDetailObj *pDetail = NULL;
pIter = sdbFetch(pMnode->pSdb, SDB_COMPACT_DETAIL, pIter, (void **)&pDetail); pIter = sdbFetch(pMnode->pSdb, SDB_COMPACT_DETAIL, pIter, (void **)&pDetail);

View File

@ -13,9 +13,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "mndCompactDetail.h" #include "mndCompactDetail.h"
#include "mndTrans.h"
#include "mndShow.h"
#include "mndDb.h" #include "mndDb.h"
#include "mndShow.h"
#include "mndTrans.h"
#define MND_COMPACT_VER_NUMBER 1 #define MND_COMPACT_VER_NUMBER 1
@ -35,21 +35,20 @@ int32_t mndInitCompactDetail(SMnode *pMnode) {
return sdbSetTable(pMnode->pSdb, table); return sdbSetTable(pMnode->pSdb, table);
} }
void mndCleanupCompactDetail(SMnode *pMnode) { void mndCleanupCompactDetail(SMnode *pMnode) { mDebug("mnd compact detail cleanup"); }
mDebug("mnd compact detail cleanup");
}
int32_t mndRetrieveCompactDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows){ int32_t mndRetrieveCompactDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
SMnode *pMnode = pReq->info.node; SMnode *pMnode = pReq->info.node;
SSdb *pSdb = pMnode->pSdb; SSdb *pSdb = pMnode->pSdb;
int32_t numOfRows = 0; int32_t numOfRows = 0;
SCompactDetailObj *pCompactDetail = NULL; SCompactDetailObj *pCompactDetail = NULL;
char *sep = NULL; char *sep = NULL;
SDbObj *pDb = NULL; SDbObj *pDb = NULL;
if (strlen(pShow->db) > 0) { if (strlen(pShow->db) > 0) {
sep = strchr(pShow->db, '.'); sep = strchr(pShow->db, '.');
if (sep && ((0 == strcmp(sep + 1, TSDB_INFORMATION_SCHEMA_DB) || (0 == strcmp(sep + 1, TSDB_PERFORMANCE_SCHEMA_DB))))) { if (sep &&
((0 == strcmp(sep + 1, TSDB_INFORMATION_SCHEMA_DB) || (0 == strcmp(sep + 1, TSDB_PERFORMANCE_SCHEMA_DB))))) {
sep++; sep++;
} else { } else {
pDb = mndAcquireDb(pMnode, pShow->db); pDb = mndAcquireDb(pMnode, pShow->db);
@ -57,7 +56,7 @@ int32_t mndRetrieveCompactDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB
} }
} }
while(numOfRows < rows){ while (numOfRows < rows) {
pShow->pIter = sdbFetch(pSdb, SDB_COMPACT_DETAIL, pShow->pIter, (void **)&pCompactDetail); pShow->pIter = sdbFetch(pSdb, SDB_COMPACT_DETAIL, pShow->pIter, (void **)&pCompactDetail);
if (pShow->pIter == NULL) break; if (pShow->pIter == NULL) break;
@ -94,53 +93,60 @@ int32_t mndRetrieveCompactDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB
return numOfRows; return numOfRows;
} }
void tFreeCompactDetailObj(SCompactDetailObj *pCompact) { void tFreeCompactDetailObj(SCompactDetailObj *pCompact) {}
}
int32_t tSerializeSCompactDetailObj(void *buf, int32_t bufLen, const SCompactDetailObj *pObj) { int32_t tSerializeSCompactDetailObj(void *buf, int32_t bufLen, const SCompactDetailObj *pObj) {
SEncoder encoder = {0}; SEncoder encoder = {0};
int32_t code = 0;
int32_t lino;
int32_t tlen;
tEncoderInit(&encoder, buf, bufLen); tEncoderInit(&encoder, buf, bufLen);
if (tStartEncode(&encoder) < 0) return -1; TAOS_CHECK_EXIT(tStartEncode(&encoder));
TAOS_CHECK_EXIT(tEncodeI32(&encoder, pObj->compactDetailId));
if (tEncodeI32(&encoder, pObj->compactDetailId) < 0) return -1; TAOS_CHECK_EXIT(tEncodeI32(&encoder, pObj->compactId));
if (tEncodeI32(&encoder, pObj->compactId) < 0) return -1; TAOS_CHECK_EXIT(tEncodeI32(&encoder, pObj->vgId));
if (tEncodeI32(&encoder, pObj->vgId) < 0) return -1; TAOS_CHECK_EXIT(tEncodeI32(&encoder, pObj->dnodeId));
if (tEncodeI32(&encoder, pObj->dnodeId) < 0) return -1; TAOS_CHECK_EXIT(tEncodeI32(&encoder, pObj->numberFileset));
if (tEncodeI32(&encoder, pObj->numberFileset) < 0) return -1; TAOS_CHECK_EXIT(tEncodeI32(&encoder, pObj->finished));
if (tEncodeI32(&encoder, pObj->finished) < 0) return -1; TAOS_CHECK_EXIT(tEncodeI64(&encoder, pObj->startTime));
if (tEncodeI64(&encoder, pObj->startTime) < 0) return -1; TAOS_CHECK_EXIT(tEncodeI32(&encoder, pObj->newNumberFileset));
if (tEncodeI32(&encoder, pObj->newNumberFileset) < 0) return -1; TAOS_CHECK_EXIT(tEncodeI32(&encoder, pObj->newFinished));
if (tEncodeI32(&encoder, pObj->newFinished) < 0) return -1;
tEndEncode(&encoder); tEndEncode(&encoder);
int32_t tlen = encoder.pos; _exit:
if (code) {
tlen = code;
} else {
tlen = encoder.pos;
}
tEncoderClear(&encoder); tEncoderClear(&encoder);
return tlen; return tlen;
} }
int32_t tDeserializeSCompactDetailObj(void *buf, int32_t bufLen, SCompactDetailObj *pObj) { int32_t tDeserializeSCompactDetailObj(void *buf, int32_t bufLen, SCompactDetailObj *pObj) {
int8_t ex = 0; int32_t code = 0;
int32_t lino;
SDecoder decoder = {0}; SDecoder decoder = {0};
tDecoderInit(&decoder, buf, bufLen); tDecoderInit(&decoder, buf, bufLen);
TAOS_CHECK_RETURN(tStartDecode(&decoder)); TAOS_CHECK_EXIT(tStartDecode(&decoder));
TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pObj->compactDetailId));
TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->compactDetailId)); TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pObj->compactId));
TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->compactId)); TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pObj->vgId));
TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->vgId)); TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pObj->dnodeId));
TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->dnodeId)); TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pObj->numberFileset));
TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->numberFileset)); TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pObj->finished));
TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->finished)); TAOS_CHECK_EXIT(tDecodeI64(&decoder, &pObj->startTime));
TAOS_CHECK_RETURN(tDecodeI64(&decoder, &pObj->startTime)); TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pObj->newNumberFileset));
TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->newNumberFileset)); TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pObj->newFinished));
TAOS_CHECK_RETURN(tDecodeI32(&decoder, &pObj->newFinished));
tEndDecode(&decoder); tEndDecode(&decoder);
_exit:
tDecoderClear(&decoder); tDecoderClear(&decoder);
return 0; return code;
} }
SSdbRaw *mndCompactDetailActionEncode(SCompactDetailObj *pCompact) { SSdbRaw *mndCompactDetailActionEncode(SCompactDetailObj *pCompact) {
@ -148,7 +154,7 @@ SSdbRaw *mndCompactDetailActionEncode(SCompactDetailObj *pCompact) {
int32_t lino = 0; int32_t lino = 0;
terrno = TSDB_CODE_SUCCESS; terrno = TSDB_CODE_SUCCESS;
void *buf = NULL; void *buf = NULL;
SSdbRaw *pRaw = NULL; SSdbRaw *pRaw = NULL;
int32_t tlen = tSerializeSCompactDetailObj(NULL, 0, pCompact); int32_t tlen = tSerializeSCompactDetailObj(NULL, 0, pCompact);
@ -157,7 +163,7 @@ SSdbRaw *mndCompactDetailActionEncode(SCompactDetailObj *pCompact) {
goto OVER; goto OVER;
} }
int32_t size = sizeof(int32_t) + tlen; int32_t size = sizeof(int32_t) + tlen;
pRaw = sdbAllocRaw(SDB_COMPACT_DETAIL, MND_COMPACT_VER_NUMBER, size); pRaw = sdbAllocRaw(SDB_COMPACT_DETAIL, MND_COMPACT_VER_NUMBER, size);
if (pRaw == NULL) { if (pRaw == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
@ -181,7 +187,6 @@ SSdbRaw *mndCompactDetailActionEncode(SCompactDetailObj *pCompact) {
SDB_SET_BINARY(pRaw, dataPos, buf, tlen, OVER); SDB_SET_BINARY(pRaw, dataPos, buf, tlen, OVER);
SDB_SET_DATALEN(pRaw, dataPos, OVER); SDB_SET_DATALEN(pRaw, dataPos, OVER);
OVER: OVER:
taosMemoryFreeClear(buf); taosMemoryFreeClear(buf);
if (terrno != TSDB_CODE_SUCCESS) { if (terrno != TSDB_CODE_SUCCESS) {
@ -263,9 +268,8 @@ int32_t mndCompactDetailActionDelete(SSdb *pSdb, SCompactDetailObj *pCompact) {
} }
int32_t mndCompactDetailActionUpdate(SSdb *pSdb, SCompactDetailObj *pOldCompact, SCompactDetailObj *pNewCompact) { int32_t mndCompactDetailActionUpdate(SSdb *pSdb, SCompactDetailObj *pOldCompact, SCompactDetailObj *pNewCompact) {
mTrace("compact detail:%" PRId32 ", perform update action, old row:%p new row:%p", mTrace("compact detail:%" PRId32 ", perform update action, old row:%p new row:%p", pOldCompact->compactId,
pOldCompact->compactId, pOldCompact, pNewCompact); pOldCompact, pNewCompact);
pOldCompact->numberFileset = pNewCompact->numberFileset; pOldCompact->numberFileset = pNewCompact->numberFileset;
pOldCompact->finished = pNewCompact->finished; pOldCompact->finished = pNewCompact->finished;
@ -273,8 +277,8 @@ int32_t mndCompactDetailActionUpdate(SSdb *pSdb, SCompactDetailObj *pOldCompact,
return 0; return 0;
} }
int32_t mndAddCompactDetailToTran(SMnode *pMnode, STrans *pTrans, SCompactObj* pCompact, SVgObj *pVgroup, int32_t mndAddCompactDetailToTran(SMnode *pMnode, STrans *pTrans, SCompactObj *pCompact, SVgObj *pVgroup,
SVnodeGid *pVgid, int32_t index){ SVnodeGid *pVgid, int32_t index) {
int32_t code = 0; int32_t code = 0;
SCompactDetailObj compactDetail = {0}; SCompactDetailObj compactDetail = {0};
compactDetail.compactDetailId = index; compactDetail.compactDetailId = index;
@ -287,8 +291,8 @@ int32_t mndAddCompactDetailToTran(SMnode *pMnode, STrans *pTrans, SCompactObj* p
compactDetail.newNumberFileset = -1; compactDetail.newNumberFileset = -1;
compactDetail.newFinished = -1; compactDetail.newFinished = -1;
mInfo("compact:%d, add compact detail to trans, index:%d, vgId:%d, dnodeId:%d", mInfo("compact:%d, add compact detail to trans, index:%d, vgId:%d, dnodeId:%d", compactDetail.compactId,
compactDetail.compactId, compactDetail.compactDetailId, compactDetail.vgId, compactDetail.dnodeId); compactDetail.compactDetailId, compactDetail.vgId, compactDetail.dnodeId);
SSdbRaw *pVgRaw = mndCompactDetailActionEncode(&compactDetail); SSdbRaw *pVgRaw = mndCompactDetailActionEncode(&compactDetail);
if (pVgRaw == NULL) return -1; if (pVgRaw == NULL) return -1;

View File

@ -34,6 +34,7 @@
#include "systable.h" #include "systable.h"
#include "thttp.h" #include "thttp.h"
#include "tjson.h" #include "tjson.h"
#include "command.h"
#define DB_VER_NUMBER 1 #define DB_VER_NUMBER 1
#define DB_RESERVE_SIZE 27 #define DB_RESERVE_SIZE 27
@ -2321,18 +2322,25 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb,
(void)colDataSetVal(pColInfo, rows, (const char *)strictVstr, false); (void)colDataSetVal(pColInfo, rows, (const char *)strictVstr, false);
char durationVstr[128] = {0}; char durationVstr[128] = {0};
int32_t len = sprintf(&durationVstr[VARSTR_HEADER_SIZE], "%dm", pDb->cfg.daysPerFile); int32_t len = formatDurationOrKeep(&durationVstr[VARSTR_HEADER_SIZE], pDb->cfg.daysPerFile);
varDataSetLen(durationVstr, len); varDataSetLen(durationVstr, len);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
(void)colDataSetVal(pColInfo, rows, (const char *)durationVstr, false); (void)colDataSetVal(pColInfo, rows, (const char *)durationVstr, false);
char keepVstr[128] = {0}; char keepVstr[512] = {0};
char keep0Str[128] = {0};
char keep1Str[128] = {0};
char keep2Str[128] = {0};
int32_t lenKeep0 = formatDurationOrKeep(keep0Str, pDb->cfg.daysToKeep0);
int32_t lenKeep1 = formatDurationOrKeep(keep1Str, pDb->cfg.daysToKeep1);
int32_t lenKeep2 = formatDurationOrKeep(keep2Str, pDb->cfg.daysToKeep2);
if (pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep1 || pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep2) { if (pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep1 || pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep2) {
len = sprintf(&keepVstr[VARSTR_HEADER_SIZE], "%dm,%dm,%dm", pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2, len = sprintf(&keepVstr[VARSTR_HEADER_SIZE], "%s,%s,%s", keep1Str, keep2Str, keep0Str);
pDb->cfg.daysToKeep0);
} else { } else {
len = sprintf(&keepVstr[VARSTR_HEADER_SIZE], "%dm,%dm,%dm", pDb->cfg.daysToKeep0, pDb->cfg.daysToKeep1, len = sprintf(&keepVstr[VARSTR_HEADER_SIZE], "%s,%s,%s", keep0Str, keep1Str, keep2Str);
pDb->cfg.daysToKeep2);
} }
varDataSetLen(keepVstr, len); varDataSetLen(keepVstr, len);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);

View File

@ -616,7 +616,7 @@ void mndDumpSdb() {
char file[] = "sdb.json"; char file[] = "sdb.json";
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
if (pFile == NULL) { if (pFile == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = terrno;
mError("failed to write %s since %s", file, terrstr()); mError("failed to write %s since %s", file, terrstr());
return; return;
} }

View File

@ -19,8 +19,8 @@
#include "systable.h" #include "systable.h"
#include "mndUser.h" #include "mndUser.h"
#define SHOW_STEP_SIZE 100 #define SHOW_STEP_SIZE 100
#define SHOW_COLS_STEP_SIZE 4096 #define SHOW_COLS_STEP_SIZE 4096
#define SHOW_PRIVILEGES_STEP_SIZE 2048 #define SHOW_PRIVILEGES_STEP_SIZE 2048
static SShowObj *mndCreateShowObj(SMnode *pMnode, SRetrieveTableReq *pReq); static SShowObj *mndCreateShowObj(SMnode *pMnode, SRetrieveTableReq *pReq);

View File

@ -63,8 +63,8 @@ static int32_t mndProcessCheckpointReport(SRpcMsg *pReq);
static int32_t mndProcessConsensusInTmr(SRpcMsg *pMsg); static int32_t mndProcessConsensusInTmr(SRpcMsg *pMsg);
static void doSendQuickRsp(SRpcHandleInfo *pInfo, int32_t msgSize, int32_t vgId, int32_t code); static void doSendQuickRsp(SRpcHandleInfo *pInfo, int32_t msgSize, int32_t vgId, int32_t code);
static int32_t mndProcessDropOrphanTaskReq(SRpcMsg* pReq); static int32_t mndProcessDropOrphanTaskReq(SRpcMsg* pReq);
static int32_t mndFindChangedNodeInfo(SMnode *pMnode, const SArray *pPrevNodeList, const SArray *pNodeList, SVgroupChangeInfo* pInfo);
static SVgroupChangeInfo mndFindChangedNodeInfo(SMnode *pMnode, const SArray *pPrevNodeList, const SArray *pNodeList); static void mndDestroyVgroupChangeInfo(SVgroupChangeInfo *pInfo);
static void addAllStreamTasksIntoBuf(SMnode *pMnode, SStreamExecInfo *pExecInfo); static void addAllStreamTasksIntoBuf(SMnode *pMnode, SStreamExecInfo *pExecInfo);
static void removeExpiredNodeInfo(const SArray *pNodeSnapshot); static void removeExpiredNodeInfo(const SArray *pNodeSnapshot);
@ -220,7 +220,7 @@ STREAM_DECODE_OVER:
taosMemoryFreeClear(buf); taosMemoryFreeClear(buf);
if (terrno != TSDB_CODE_SUCCESS) { if (terrno != TSDB_CODE_SUCCESS) {
char *p = (pStream == NULL) ? "null" : pStream->name; char *p = (pStream == NULL) ? "null" : pStream->name;
mError("stream:%s, failed to decode from raw:%p since %s", p, pRaw, terrstr()); mError("stream:%s, failed to decode from raw:%p since %s", p, pRaw, tstrerror(terrno));
taosMemoryFreeClear(pRow); taosMemoryFreeClear(pRow);
return NULL; return NULL;
} }
@ -282,9 +282,9 @@ int32_t mndStreamSeqActionUpdate(SSdb *pSdb, SStreamSeq *pOldStream, SStreamSeq
static int32_t mndCheckCreateStreamReq(SCMCreateStreamReq *pCreate) { static int32_t mndCheckCreateStreamReq(SCMCreateStreamReq *pCreate) {
if (pCreate->name[0] == 0 || pCreate->sql == NULL || pCreate->sql[0] == 0 || pCreate->sourceDB[0] == 0 || if (pCreate->name[0] == 0 || pCreate->sql == NULL || pCreate->sql[0] == 0 || pCreate->sourceDB[0] == 0 ||
pCreate->targetStbFullName[0] == 0) { pCreate->targetStbFullName[0] == 0) {
return terrno = TSDB_CODE_MND_INVALID_STREAM_OPTION; return TSDB_CODE_MND_INVALID_STREAM_OPTION;
} }
return 0; return TSDB_CODE_SUCCESS;
} }
static int32_t createSchemaByFields(const SArray *pFields, SSchemaWrapper *pWrapper) { static int32_t createSchemaByFields(const SArray *pFields, SSchemaWrapper *pWrapper) {
@ -366,8 +366,8 @@ static int32_t mndBuildStreamObjFromCreateReq(SMnode *pMnode, SStreamObj *pObj,
memcpy(pObj->sourceDb, pCreate->sourceDB, TSDB_DB_FNAME_LEN); memcpy(pObj->sourceDb, pCreate->sourceDB, TSDB_DB_FNAME_LEN);
SDbObj *pSourceDb = mndAcquireDb(pMnode, pCreate->sourceDB); SDbObj *pSourceDb = mndAcquireDb(pMnode, pCreate->sourceDB);
if (pSourceDb == NULL) { if (pSourceDb == NULL) {
mInfo("stream:%s failed to create, source db %s not exist since %s", pCreate->name, pObj->sourceDb, terrstr());
code = terrno; code = terrno;
mInfo("stream:%s failed to create, source db %s not exist since %s", pCreate->name, pObj->sourceDb, tstrerror(code));
goto FAIL; goto FAIL;
} }
@ -378,8 +378,8 @@ static int32_t mndBuildStreamObjFromCreateReq(SMnode *pMnode, SStreamObj *pObj,
SDbObj *pTargetDb = mndAcquireDbByStb(pMnode, pObj->targetSTbName); SDbObj *pTargetDb = mndAcquireDbByStb(pMnode, pObj->targetSTbName);
if (pTargetDb == NULL) { if (pTargetDb == NULL) {
mError("stream:%s failed to create, target db %s not exist since %s", pCreate->name, pObj->targetDb, terrstr());
code = terrno; code = terrno;
mError("stream:%s failed to create, target db %s not exist since %s", pCreate->name, pObj->targetDb, tstrerror(code));
goto FAIL; goto FAIL;
} }
@ -543,8 +543,7 @@ int32_t mndPersistTaskDeployReq(STrans *pTrans, SStreamTask *pTask) {
code = tEncodeStreamTask(&encoder, pTask); code = tEncodeStreamTask(&encoder, pTask);
tEncoderClear(&encoder); tEncoderClear(&encoder);
if (code == -1) { if (code != 0) {
code = TSDB_CODE_INVALID_PARA;
mError("failed to encode stream task, code:%s", tstrerror(code)); mError("failed to encode stream task, code:%s", tstrerror(code));
taosMemoryFree(buf); taosMemoryFree(buf);
return code; return code;
@ -616,8 +615,8 @@ int32_t mndPersistStream(STrans *pTrans, SStreamObj *pStream) {
static int32_t mndCreateStbForStream(SMnode *pMnode, STrans *pTrans, const SStreamObj *pStream, const char *user) { static int32_t mndCreateStbForStream(SMnode *pMnode, STrans *pTrans, const SStreamObj *pStream, const char *user) {
SStbObj *pStb = NULL; SStbObj *pStb = NULL;
SDbObj *pDb = NULL; SDbObj *pDb = NULL;
int32_t code = 0; int32_t code = 0;
int32_t lino = 0; int32_t lino = 0;
SMCreateStbReq createReq = {0}; SMCreateStbReq createReq = {0};
tstrncpy(createReq.name, pStream->targetSTbName, TSDB_TABLE_FNAME_LEN); tstrncpy(createReq.name, pStream->targetSTbName, TSDB_TABLE_FNAME_LEN);
@ -669,19 +668,19 @@ static int32_t mndCreateStbForStream(SMnode *pMnode, STrans *pTrans, const SStre
} }
} }
if (mndCheckCreateStbReq(&createReq) != 0) { if ((code = mndCheckCreateStbReq(&createReq)) != 0) {
goto _OVER; goto _OVER;
} }
pStb = mndAcquireStb(pMnode, createReq.name); pStb = mndAcquireStb(pMnode, createReq.name);
if (pStb != NULL) { if (pStb != NULL) {
terrno = TSDB_CODE_MND_STB_ALREADY_EXIST; code = TSDB_CODE_MND_STB_ALREADY_EXIST;
goto _OVER; goto _OVER;
} }
pDb = mndAcquireDbByStb(pMnode, createReq.name); pDb = mndAcquireDbByStb(pMnode, createReq.name);
if (pDb == NULL) { if (pDb == NULL) {
terrno = TSDB_CODE_MND_DB_NOT_SELECTED; code = TSDB_CODE_MND_DB_NOT_SELECTED;
goto _OVER; goto _OVER;
} }
@ -691,7 +690,7 @@ static int32_t mndCreateStbForStream(SMnode *pMnode, STrans *pTrans, const SStre
} }
if (pDb->cfg.numOfStables == 1 && numOfStbs != 0) { if (pDb->cfg.numOfStables == 1 && numOfStbs != 0) {
terrno = TSDB_CODE_MND_SINGLE_STB_MODE_DB; code = TSDB_CODE_MND_SINGLE_STB_MODE_DB;
goto _OVER; goto _OVER;
} }
@ -720,7 +719,8 @@ _OVER:
mndReleaseStb(pMnode, pStb); mndReleaseStb(pMnode, pStb);
mndReleaseDb(pMnode, pDb); mndReleaseDb(pMnode, pDb);
mDebug("stream:%s failed to create dst stable:%s, code:%s", pStream->name, pStream->targetSTbName, tstrerror(terrno)); mDebug("stream:%s failed to create dst stable:%s, line:%d code:%s", pStream->name, pStream->targetSTbName, lino,
tstrerror(code));
return code; return code;
} }
@ -742,16 +742,14 @@ static int32_t doStreamCheck(SMnode *pMnode, SStreamObj *pStreamObj) {
mError("too many streams, no more than %d for each database, failed to create stream:%s", MND_STREAM_MAX_NUM, mError("too many streams, no more than %d for each database, failed to create stream:%s", MND_STREAM_MAX_NUM,
pStreamObj->name); pStreamObj->name);
sdbCancelFetch(pMnode->pSdb, pIter); sdbCancelFetch(pMnode->pSdb, pIter);
terrno = TSDB_CODE_MND_TOO_MANY_STREAMS; return TSDB_CODE_MND_TOO_MANY_STREAMS;
return terrno;
} }
if (pStream->targetStbUid == pStreamObj->targetStbUid) { if (pStream->targetStbUid == pStreamObj->targetStbUid) {
mError("Cannot write the same stable as other stream:%s, failed to create stream:%s", pStream->name, mError("Cannot write the same stable as other stream:%s, failed to create stream:%s", pStream->name,
pStreamObj->name); pStreamObj->name);
sdbCancelFetch(pMnode->pSdb, pIter); sdbCancelFetch(pMnode->pSdb, pIter);
terrno = TSDB_CODE_MND_INVALID_TARGET_TABLE; return TSDB_CODE_MND_INVALID_TARGET_TABLE;
return terrno;
} }
} }
@ -767,13 +765,11 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) {
const char *pMsg = "create stream tasks on dnodes"; const char *pMsg = "create stream tasks on dnodes";
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
int32_t lino = 0; int32_t lino = 0;
STrans *pTrans = NULL;
terrno = TSDB_CODE_SUCCESS;
SCMCreateStreamReq createReq = {0}; SCMCreateStreamReq createReq = {0};
if (tDeserializeSCMCreateStreamReq(pReq->pCont, pReq->contLen, &createReq) != 0) { code = tDeserializeSCMCreateStreamReq(pReq->pCont, pReq->contLen, &createReq);
code = TSDB_CODE_INVALID_MSG; TSDB_CHECK_CODE(code, lino, _OVER);
goto _OVER;
}
#ifdef WINDOWS #ifdef WINDOWS
code = TSDB_CODE_MND_INVALID_PLATFORM; code = TSDB_CODE_MND_INVALID_PLATFORM;
@ -782,7 +778,7 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) {
mInfo("stream:%s, start to create stream, sql:%s", createReq.name, createReq.sql); mInfo("stream:%s, start to create stream, sql:%s", createReq.name, createReq.sql);
if ((code = mndCheckCreateStreamReq(&createReq)) != 0) { if ((code = mndCheckCreateStreamReq(&createReq)) != 0) {
mError("stream:%s, failed to create since %s", createReq.name, terrstr()); mError("stream:%s, failed to create since %s", createReq.name, tstrerror(code));
goto _OVER; goto _OVER;
} }
@ -790,7 +786,9 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) {
if (pStream != NULL && code == 0) { if (pStream != NULL && code == 0) {
if (createReq.igExists) { if (createReq.igExists) {
mInfo("stream:%s, already exist, ignore exist is set", createReq.name); mInfo("stream:%s, already exist, ignore exist is set", createReq.name);
goto _OVER; mndReleaseStream(pMnode, pStream);
tFreeSCMCreateStreamReq(&createReq);
return code;
} else { } else {
code = TSDB_CODE_MND_STREAM_ALREADY_EXIST; code = TSDB_CODE_MND_STREAM_ALREADY_EXIST;
goto _OVER; goto _OVER;
@ -807,21 +805,20 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) {
sqlLen = strlen(createReq.sql); sqlLen = strlen(createReq.sql);
sql = taosMemoryMalloc(sqlLen + 1); sql = taosMemoryMalloc(sqlLen + 1);
TSDB_CHECK_NULL(sql, code, lino, _OVER, terrno); TSDB_CHECK_NULL(sql, code, lino, _OVER, terrno);
memset(sql, 0, sqlLen + 1); memset(sql, 0, sqlLen + 1);
memcpy(sql, createReq.sql, sqlLen); memcpy(sql, createReq.sql, sqlLen);
} }
// build stream obj from request // build stream obj from request
if ((code = mndBuildStreamObjFromCreateReq(pMnode, &streamObj, &createReq)) < 0) { if ((code = mndBuildStreamObjFromCreateReq(pMnode, &streamObj, &createReq)) < 0) {
mError("stream:%s, failed to create since %s", createReq.name, terrstr()); mError("stream:%s, failed to create since %s", createReq.name, tstrerror(code));
goto _OVER; goto _OVER;
} }
if ((code = doStreamCheck(pMnode, &streamObj)) < 0) { code = doStreamCheck(pMnode, &streamObj);
goto _OVER; TSDB_CHECK_CODE(code, lino, _OVER);
}
STrans *pTrans = NULL;
code = doCreateTrans(pMnode, &streamObj, pReq, TRN_CONFLICT_DB, MND_STREAM_CREATE_NAME, pMsg, &pTrans); code = doCreateTrans(pMnode, &streamObj, pReq, TRN_CONFLICT_DB, MND_STREAM_CREATE_NAME, pMsg, &pTrans);
if (pTrans == NULL || code) { if (pTrans == NULL || code) {
goto _OVER; goto _OVER;
@ -830,7 +827,7 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) {
// create stb for stream // create stb for stream
if (createReq.createStb == STREAM_CREATE_STABLE_TRUE) { if (createReq.createStb == STREAM_CREATE_STABLE_TRUE) {
if ((code = mndCreateStbForStream(pMnode, pTrans, &streamObj, pReq->info.conn.user)) < 0) { if ((code = mndCreateStbForStream(pMnode, pTrans, &streamObj, pReq->info.conn.user)) < 0) {
mError("trans:%d, failed to create stb for stream %s since %s", pTrans->id, createReq.name, terrstr()); mError("trans:%d, failed to create stb for stream %s since %s", pTrans->id, createReq.name, tstrerror(code));
mndTransDrop(pTrans); mndTransDrop(pTrans);
goto _OVER; goto _OVER;
} }
@ -841,7 +838,7 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) {
// schedule stream task for stream obj // schedule stream task for stream obj
code = mndScheduleStream(pMnode, &streamObj, createReq.lastTs, createReq.pVgroupVerList); code = mndScheduleStream(pMnode, &streamObj, createReq.lastTs, createReq.pVgroupVerList);
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) {
mError("stream:%s, failed to schedule since %s", createReq.name, terrstr()); mError("stream:%s, failed to schedule since %s", createReq.name, tstrerror(code));
mndTransDrop(pTrans); mndTransDrop(pTrans);
goto _OVER; goto _OVER;
} }
@ -849,7 +846,7 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) {
// add stream to trans // add stream to trans
code = mndPersistStream(pTrans, &streamObj); code = mndPersistStream(pTrans, &streamObj);
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) {
mError("stream:%s, failed to persist since %s", createReq.name, terrstr()); mError("stream:%s, failed to persist since %s", createReq.name, tstrerror(code));
mndTransDrop(pTrans); mndTransDrop(pTrans);
goto _OVER; goto _OVER;
} }
@ -874,17 +871,13 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) {
// execute creation // execute creation
code = mndTransPrepare(pMnode, pTrans); code = mndTransPrepare(pMnode, pTrans);
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) {
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); mError("trans:%d, failed to prepare since %s", pTrans->id, tstrerror(code));
mndTransDrop(pTrans); mndTransDrop(pTrans);
goto _OVER; goto _OVER;
} }
mndTransDrop(pTrans); mndTransDrop(pTrans);
if (code == 0) {
code = TSDB_CODE_ACTION_IN_PROGRESS;
}
SName dbname = {0}; SName dbname = {0};
code = tNameFromString(&dbname, createReq.sourceDB, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); code = tNameFromString(&dbname, createReq.sourceDB, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
if (code) { if (code) {
@ -910,9 +903,10 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) {
_OVER: _OVER:
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) {
mError("stream:%s, failed to create since %s", createReq.name, terrstr()); mError("stream:%s, failed to create at line:%d since %s", createReq.name, lino, tstrerror(code));
} else { } else {
mDebug("stream:%s create stream completed", createReq.name); mDebug("stream:%s create stream completed", createReq.name);
code = TSDB_CODE_ACTION_IN_PROGRESS;
} }
mndReleaseStream(pMnode, pStream); mndReleaseStream(pMnode, pStream);
@ -1058,23 +1052,24 @@ static int32_t doSetCheckpointAction(SMnode *pMnode, STrans *pTrans, SStreamTask
static int32_t mndProcessStreamCheckpointTrans(SMnode *pMnode, SStreamObj *pStream, int64_t checkpointId, static int32_t mndProcessStreamCheckpointTrans(SMnode *pMnode, SStreamObj *pStream, int64_t checkpointId,
int8_t mndTrigger, bool lock) { int8_t mndTrigger, bool lock) {
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
bool conflict = false;
int64_t ts = taosGetTimestampMs(); int64_t ts = taosGetTimestampMs();
STrans *pTrans = NULL;
if (mndTrigger == 1 && (ts - pStream->checkpointFreq < tsStreamCheckpointInterval * 1000)) { if (mndTrigger == 1 && (ts - pStream->checkpointFreq < tsStreamCheckpointInterval * 1000)) {
return code; return code;
} }
bool conflict = mndStreamTransConflictCheck(pMnode, pStream->uid, MND_STREAM_CHECKPOINT_NAME, lock); code = mndStreamTransConflictCheck(pMnode, pStream->uid, MND_STREAM_CHECKPOINT_NAME, lock);
if (conflict) { if (code) {
mWarn("checkpoint conflict with other trans in %s, ignore the checkpoint for stream:%s %" PRIx64, pStream->sourceDb, mWarn("checkpoint conflict with other trans in %s, code:%s ignore the checkpoint for stream:%s %" PRIx64,
pStream->name, pStream->uid); pStream->sourceDb, tstrerror(code), pStream->name, pStream->uid);
return TSDB_CODE_MND_TRANS_CONFLICT; goto _ERR;
} }
STrans *pTrans = NULL;
code = doCreateTrans(pMnode, pStream, NULL, TRN_CONFLICT_NOTHING, MND_STREAM_CHECKPOINT_NAME, code = doCreateTrans(pMnode, pStream, NULL, TRN_CONFLICT_NOTHING, MND_STREAM_CHECKPOINT_NAME,
"gen checkpoint for stream", &pTrans); "gen checkpoint for stream", &pTrans);
if (pTrans == NULL || code) { if (code) {
code = TSDB_CODE_MND_TRANS_CONFLICT;
mError("failed to checkpoint of stream name%s, checkpointId: %" PRId64 ", reason:%s", pStream->name, checkpointId, mError("failed to checkpoint of stream name%s, checkpointId: %" PRId64 ", reason:%s", pStream->name, checkpointId,
tstrerror(code)); tstrerror(code));
goto _ERR; goto _ERR;
@ -1126,7 +1121,9 @@ static int32_t mndProcessStreamCheckpointTrans(SMnode *pMnode, SStreamObj *pStre
code = mndTransPrepare(pMnode, pTrans); code = mndTransPrepare(pMnode, pTrans);
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) {
mError("failed to prepare checkpoint trans since %s", terrstr()); mError("failed to prepare checkpoint trans since %s", tstrerror(code));
} else {
code = TSDB_CODE_ACTION_IN_PROGRESS;
} }
_ERR: _ERR:
@ -1147,6 +1144,9 @@ int32_t extractStreamNodeList(SMnode *pMnode) {
} }
static bool taskNodeIsUpdated(SMnode *pMnode) { static bool taskNodeIsUpdated(SMnode *pMnode) {
bool allReady = true;
SArray *pNodeSnapshot = NULL;
// check if the node update happens or not // check if the node update happens or not
streamMutexLock(&execInfo.lock); streamMutexLock(&execInfo.lock);
@ -1171,13 +1171,11 @@ static bool taskNodeIsUpdated(SMnode *pMnode) {
} }
} }
bool allReady = true;
SArray *pNodeSnapshot = NULL;
int32_t code = mndTakeVgroupSnapshot(pMnode, &allReady, &pNodeSnapshot); int32_t code = mndTakeVgroupSnapshot(pMnode, &allReady, &pNodeSnapshot);
if (code) { if (code) {
mError("failed to get the vgroup snapshot, ignore it and continue"); mError("failed to get the vgroup snapshot, ignore it and continue");
} }
if (!allReady) { if (!allReady) {
mWarn("not all vnodes ready, quit from vnodes status check"); mWarn("not all vnodes ready, quit from vnodes status check");
taosArrayDestroy(pNodeSnapshot); taosArrayDestroy(pNodeSnapshot);
@ -1185,12 +1183,16 @@ static bool taskNodeIsUpdated(SMnode *pMnode) {
return true; return true;
} }
SVgroupChangeInfo changeInfo = mndFindChangedNodeInfo(pMnode, execInfo.pNodeList, pNodeSnapshot); SVgroupChangeInfo changeInfo = {0};
code = mndFindChangedNodeInfo(pMnode, execInfo.pNodeList, pNodeSnapshot, &changeInfo);
if (code) {
streamMutexUnlock(&execInfo.lock);
return false;
}
bool nodeUpdated = (taosArrayGetSize(changeInfo.pUpdateNodeList) > 0); bool nodeUpdated = (taosArrayGetSize(changeInfo.pUpdateNodeList) > 0);
taosArrayDestroy(changeInfo.pUpdateNodeList); mndDestroyVgroupChangeInfo(&changeInfo);
taosHashCleanup(changeInfo.pDBMap);
taosArrayDestroy(pNodeSnapshot); taosArrayDestroy(pNodeSnapshot);
if (nodeUpdated) { if (nodeUpdated) {
@ -1400,7 +1402,7 @@ static int32_t mndProcessStreamCheckpoint(SRpcMsg *pReq) {
code = mndProcessStreamCheckpointTrans(pMnode, p, checkpointId, 1, true); code = mndProcessStreamCheckpointTrans(pMnode, p, checkpointId, 1, true);
sdbRelease(pSdb, p); sdbRelease(pSdb, p);
if (code != -1) { if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
started += 1; started += 1;
if (started >= capacity) { if (started >= capacity) {
@ -1438,10 +1440,9 @@ static int32_t mndProcessDropStreamReq(SRpcMsg *pReq) {
tFreeMDropStreamReq(&dropReq); tFreeMDropStreamReq(&dropReq);
return 0; return 0;
} else { } else {
code = TSDB_CODE_MND_STREAM_NOT_EXIST;
mError("stream:%s not exist failed to drop it", dropReq.name); mError("stream:%s not exist failed to drop it", dropReq.name);
tFreeMDropStreamReq(&dropReq); tFreeMDropStreamReq(&dropReq);
TAOS_RETURN(code); TAOS_RETURN(TSDB_CODE_MND_STREAM_NOT_EXIST);
} }
} }
@ -1480,17 +1481,17 @@ static int32_t mndProcessDropStreamReq(SRpcMsg *pReq) {
} }
// check if it is conflict with other trans in both sourceDb and targetDb. // check if it is conflict with other trans in both sourceDb and targetDb.
bool conflict = mndStreamTransConflictCheck(pMnode, pStream->uid, MND_STREAM_DROP_NAME, true); code = mndStreamTransConflictCheck(pMnode, pStream->uid, MND_STREAM_DROP_NAME, true);
if (conflict) { if (code) {
sdbRelease(pMnode->pSdb, pStream); sdbRelease(pMnode->pSdb, pStream);
tFreeMDropStreamReq(&dropReq); tFreeMDropStreamReq(&dropReq);
return terrno; return code;
} }
STrans *pTrans = NULL; STrans *pTrans = NULL;
code = doCreateTrans(pMnode, pStream, pReq, TRN_CONFLICT_NOTHING, MND_STREAM_DROP_NAME, "drop stream", &pTrans); code = doCreateTrans(pMnode, pStream, pReq, TRN_CONFLICT_NOTHING, MND_STREAM_DROP_NAME, "drop stream", &pTrans);
if (pTrans == NULL || code) { if (pTrans == NULL || code) {
mError("stream:%s uid:0x%" PRIx64 " failed to drop since %s", dropReq.name, pStream->uid, terrstr()); mError("stream:%s uid:0x%" PRIx64 " failed to drop since %s", dropReq.name, pStream->uid, tstrerror(code));
sdbRelease(pMnode->pSdb, pStream); sdbRelease(pMnode->pSdb, pStream);
tFreeMDropStreamReq(&dropReq); tFreeMDropStreamReq(&dropReq);
TAOS_RETURN(code); TAOS_RETURN(code);
@ -1526,7 +1527,7 @@ static int32_t mndProcessDropStreamReq(SRpcMsg *pReq) {
code = mndTransPrepare(pMnode, pTrans); code = mndTransPrepare(pMnode, pTrans);
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) {
mError("trans:%d, failed to prepare drop stream trans since %s", pTrans->id, terrstr()); mError("trans:%d, failed to prepare drop stream trans since %s", pTrans->id, tstrerror(code));
sdbRelease(pMnode->pSdb, pStream); sdbRelease(pMnode->pSdb, pStream);
mndTransDrop(pTrans); mndTransDrop(pTrans);
tFreeMDropStreamReq(&dropReq); tFreeMDropStreamReq(&dropReq);
@ -1756,16 +1757,16 @@ static int32_t mndProcessPauseStreamReq(SRpcMsg *pReq) {
return 0; return 0;
} }
if (mndCheckDbPrivilegeByName(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pStream->targetDb) != 0) { if ((code = mndCheckDbPrivilegeByName(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pStream->targetDb)) != 0) {
sdbRelease(pMnode->pSdb, pStream); sdbRelease(pMnode->pSdb, pStream);
return -1; return code;
} }
// check if it is conflict with other trans in both sourceDb and targetDb. // check if it is conflict with other trans in both sourceDb and targetDb.
bool conflict = mndStreamTransConflictCheck(pMnode, pStream->uid, MND_STREAM_PAUSE_NAME, true); code = mndStreamTransConflictCheck(pMnode, pStream->uid, MND_STREAM_PAUSE_NAME, true);
if (conflict) { if (code) {
sdbRelease(pMnode->pSdb, pStream); sdbRelease(pMnode->pSdb, pStream);
TAOS_RETURN(TSDB_CODE_MND_TRANS_CONFLICT); TAOS_RETURN(code);
} }
bool updated = taskNodeIsUpdated(pMnode); bool updated = taskNodeIsUpdated(pMnode);
@ -1821,7 +1822,7 @@ static int32_t mndProcessPauseStreamReq(SRpcMsg *pReq) {
STrans *pTrans = NULL; STrans *pTrans = NULL;
code = doCreateTrans(pMnode, pStream, pReq, TRN_CONFLICT_NOTHING, MND_STREAM_PAUSE_NAME, "pause the stream", &pTrans); code = doCreateTrans(pMnode, pStream, pReq, TRN_CONFLICT_NOTHING, MND_STREAM_PAUSE_NAME, "pause the stream", &pTrans);
if (pTrans == NULL || code) { if (pTrans == NULL || code) {
mError("stream:%s failed to pause stream since %s", pauseReq.name, terrstr()); mError("stream:%s failed to pause stream since %s", pauseReq.name, tstrerror(code));
sdbRelease(pMnode->pSdb, pStream); sdbRelease(pMnode->pSdb, pStream);
return code; return code;
} }
@ -1836,7 +1837,7 @@ static int32_t mndProcessPauseStreamReq(SRpcMsg *pReq) {
// if nodeUpdate happened, not send pause trans // if nodeUpdate happened, not send pause trans
code = mndStreamSetPauseAction(pMnode, pTrans, pStream); code = mndStreamSetPauseAction(pMnode, pTrans, pStream);
if (code) { if (code) {
mError("stream:%s, failed to pause task since %s", pauseReq.name, terrstr()); mError("stream:%s, failed to pause task since %s", pauseReq.name, tstrerror(code));
sdbRelease(pMnode->pSdb, pStream); sdbRelease(pMnode->pSdb, pStream);
mndTransDrop(pTrans); mndTransDrop(pTrans);
return code; return code;
@ -1857,7 +1858,7 @@ static int32_t mndProcessPauseStreamReq(SRpcMsg *pReq) {
code = mndTransPrepare(pMnode, pTrans); code = mndTransPrepare(pMnode, pTrans);
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) {
mError("trans:%d, failed to prepare pause stream trans since %s", pTrans->id, terrstr()); mError("trans:%d, failed to prepare pause stream trans since %s", pTrans->id, tstrerror(code));
sdbRelease(pMnode->pSdb, pStream); sdbRelease(pMnode->pSdb, pStream);
mndTransDrop(pTrans); mndTransDrop(pTrans);
return code; return code;
@ -1874,8 +1875,8 @@ static int32_t mndProcessResumeStreamReq(SRpcMsg *pReq) {
SStreamObj *pStream = NULL; SStreamObj *pStream = NULL;
int32_t code = 0; int32_t code = 0;
if ((terrno = grantCheckExpire(TSDB_GRANT_STREAMS)) < 0) { if ((code = grantCheckExpire(TSDB_GRANT_STREAMS)) < 0) {
return terrno; return code;
} }
SMResumeStreamReq resumeReq = {0}; SMResumeStreamReq resumeReq = {0};
@ -1906,17 +1907,17 @@ static int32_t mndProcessResumeStreamReq(SRpcMsg *pReq) {
} }
// check if it is conflict with other trans in both sourceDb and targetDb. // check if it is conflict with other trans in both sourceDb and targetDb.
bool conflict = mndStreamTransConflictCheck(pMnode, pStream->uid, MND_STREAM_RESUME_NAME, true); code = mndStreamTransConflictCheck(pMnode, pStream->uid, MND_STREAM_RESUME_NAME, true);
if (conflict) { if (code) {
sdbRelease(pMnode->pSdb, pStream); sdbRelease(pMnode->pSdb, pStream);
return terrno; return code;
} }
STrans *pTrans = NULL; STrans *pTrans = NULL;
code = code =
doCreateTrans(pMnode, pStream, pReq, TRN_CONFLICT_NOTHING, MND_STREAM_RESUME_NAME, "resume the stream", &pTrans); doCreateTrans(pMnode, pStream, pReq, TRN_CONFLICT_NOTHING, MND_STREAM_RESUME_NAME, "resume the stream", &pTrans);
if (pTrans == NULL || code) { if (pTrans == NULL || code) {
mError("stream:%s, failed to resume stream since %s", resumeReq.name, terrstr()); mError("stream:%s, failed to resume stream since %s", resumeReq.name, tstrerror(code));
sdbRelease(pMnode->pSdb, pStream); sdbRelease(pMnode->pSdb, pStream);
return code; return code;
} }
@ -1929,8 +1930,9 @@ static int32_t mndProcessResumeStreamReq(SRpcMsg *pReq) {
} }
// set the resume action // set the resume action
if (mndStreamSetResumeAction(pTrans, pMnode, pStream, resumeReq.igUntreated) < 0) { code = mndStreamSetResumeAction(pTrans, pMnode, pStream, resumeReq.igUntreated);
mError("stream:%s, failed to drop task since %s", resumeReq.name, terrstr()); if (code) {
mError("stream:%s, failed to drop task since %s", resumeReq.name, tstrerror(code));
sdbRelease(pMnode->pSdb, pStream); sdbRelease(pMnode->pSdb, pStream);
mndTransDrop(pTrans); mndTransDrop(pTrans);
return code; return code;
@ -1950,7 +1952,7 @@ static int32_t mndProcessResumeStreamReq(SRpcMsg *pReq) {
taosWUnLockLatch(&pStream->lock); taosWUnLockLatch(&pStream->lock);
code = mndTransPrepare(pMnode, pTrans); code = mndTransPrepare(pMnode, pTrans);
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) {
mError("trans:%d, failed to prepare pause stream trans since %s", pTrans->id, terrstr()); mError("trans:%d, failed to prepare pause stream trans since %s", pTrans->id, tstrerror(code));
sdbRelease(pMnode->pSdb, pStream); sdbRelease(pMnode->pSdb, pStream);
mndTransDrop(pTrans); mndTransDrop(pTrans);
return code; return code;
@ -1977,11 +1979,22 @@ static bool isNodeEpsetChanged(const SEpSet *pPrevEpset, const SEpSet *pCurrent)
// tasks on the will be removed replica. // tasks on the will be removed replica.
// 3. vgroup redistribution is an combination operation of first increase replica and then decrease replica. So we // 3. vgroup redistribution is an combination operation of first increase replica and then decrease replica. So we
// will handle it as mentioned in 1 & 2 items. // will handle it as mentioned in 1 & 2 items.
static SVgroupChangeInfo mndFindChangedNodeInfo(SMnode *pMnode, const SArray *pPrevNodeList, const SArray *pNodeList) { static int32_t mndFindChangedNodeInfo(SMnode *pMnode, const SArray *pPrevNodeList, const SArray *pNodeList,
SVgroupChangeInfo info = { SVgroupChangeInfo *pInfo) {
.pUpdateNodeList = taosArrayInit(4, sizeof(SNodeUpdateInfo)), int32_t code = 0;
.pDBMap = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, HASH_NO_LOCK), int32_t lino = 0;
};
if (pInfo == NULL) {
return TSDB_CODE_INVALID_PARA;
}
pInfo->pUpdateNodeList = taosArrayInit(4, sizeof(SNodeUpdateInfo)),
pInfo->pDBMap = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, HASH_NO_LOCK);
if (pInfo->pUpdateNodeList == NULL || pInfo->pDBMap == NULL) {
mndDestroyVgroupChangeInfo(pInfo);
return TSDB_CODE_OUT_OF_MEMORY;
}
int32_t numOfNodes = taosArrayGetSize(pPrevNodeList); int32_t numOfNodes = taosArrayGetSize(pPrevNodeList);
for (int32_t i = 0; i < numOfNodes; ++i) { for (int32_t i = 0; i < numOfNodes; ++i) {
@ -2002,7 +2015,11 @@ static SVgroupChangeInfo mndFindChangedNodeInfo(SMnode *pMnode, const SArray *pP
const SEp *pPrevEp = GET_ACTIVE_EP(&pPrevEntry->epset); const SEp *pPrevEp = GET_ACTIVE_EP(&pPrevEntry->epset);
char buf[256] = {0}; char buf[256] = {0};
(void) epsetToStr(&pCurrent->epset, buf, tListLen(buf)); // ignore this error code = epsetToStr(&pCurrent->epset, buf, tListLen(buf)); // ignore this error
if (code) {
mError("failed to convert epset string, code:%s", tstrerror(code));
TSDB_CHECK_CODE(code, lino, _err);
}
mDebug("nodeId:%d restart/epset changed detected, old:%s:%d -> new:%s, stageUpdate:%d", pCurrent->nodeId, mDebug("nodeId:%d restart/epset changed detected, old:%s:%d -> new:%s, stageUpdate:%d", pCurrent->nodeId,
pPrevEp->fqdn, pPrevEp->port, buf, pPrevEntry->stageUpdated); pPrevEp->fqdn, pPrevEp->port, buf, pPrevEntry->stageUpdated);
@ -2011,20 +2028,16 @@ static SVgroupChangeInfo mndFindChangedNodeInfo(SMnode *pMnode, const SArray *pP
epsetAssign(&updateInfo.prevEp, &pPrevEntry->epset); epsetAssign(&updateInfo.prevEp, &pPrevEntry->epset);
epsetAssign(&updateInfo.newEp, &pCurrent->epset); epsetAssign(&updateInfo.newEp, &pCurrent->epset);
void* p = taosArrayPush(info.pUpdateNodeList, &updateInfo); void* p = taosArrayPush(pInfo->pUpdateNodeList, &updateInfo);
if (p == NULL) { TSDB_CHECK_NULL(p, code, lino, _err, terrno);
mError("failed to put update entry into node list, code:%s", tstrerror(TSDB_CODE_OUT_OF_MEMORY));
}
} }
// todo handle the snode info // todo handle the snode info
if (pCurrent->nodeId != SNODE_HANDLE) { if (pCurrent->nodeId != SNODE_HANDLE) {
SVgObj *pVgroup = mndAcquireVgroup(pMnode, pCurrent->nodeId); SVgObj *pVgroup = mndAcquireVgroup(pMnode, pCurrent->nodeId);
int32_t code = taosHashPut(info.pDBMap, pVgroup->dbName, strlen(pVgroup->dbName), NULL, 0); code = taosHashPut(pInfo->pDBMap, pVgroup->dbName, strlen(pVgroup->dbName), NULL, 0);
mndReleaseVgroup(pMnode, pVgroup); mndReleaseVgroup(pMnode, pVgroup);
if (code) { TSDB_CHECK_CODE(code, lino, _err);
mError("failed to put into dbmap, code:out of memory");
}
} }
break; break;
@ -2032,7 +2045,18 @@ static SVgroupChangeInfo mndFindChangedNodeInfo(SMnode *pMnode, const SArray *pP
} }
} }
return info; return code;
_err:
mndDestroyVgroupChangeInfo(pInfo);
return code;
}
static void mndDestroyVgroupChangeInfo(SVgroupChangeInfo* pInfo) {
if (pInfo != NULL) {
taosArrayDestroy(pInfo->pUpdateNodeList);
taosHashCleanup(pInfo->pDBMap);
}
} }
static int32_t mndProcessVgroupChange(SMnode *pMnode, SVgroupChangeInfo *pChangeInfo, bool includeAllNodes) { static int32_t mndProcessVgroupChange(SMnode *pMnode, SVgroupChangeInfo *pChangeInfo, bool includeAllNodes) {
@ -2049,13 +2073,13 @@ static int32_t mndProcessVgroupChange(SMnode *pMnode, SVgroupChangeInfo *pChange
break; break;
} }
bool conflict = mndStreamTransConflictCheck(pMnode, pStream->uid, MND_STREAM_TASK_UPDATE_NAME, false); code = mndStreamTransConflictCheck(pMnode, pStream->uid, MND_STREAM_TASK_UPDATE_NAME, false);
sdbRelease(pSdb, pStream); sdbRelease(pSdb, pStream);
if (conflict) { if (code) {
mError("nodeUpdate conflict with other trans, current nodeUpdate ignored"); mError("nodeUpdate conflict with other trans, current nodeUpdate ignored, code:%s", tstrerror(code));
sdbCancelFetch(pSdb, pIter); sdbCancelFetch(pSdb, pIter);
return terrno; return code;
} }
} }
@ -2119,7 +2143,7 @@ static int32_t mndProcessVgroupChange(SMnode *pMnode, SVgroupChangeInfo *pChange
code = mndTransPrepare(pMnode, pTrans); code = mndTransPrepare(pMnode, pTrans);
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) {
mError("trans:%d, failed to prepare update stream trans since %s", pTrans->id, terrstr()); mError("trans:%d, failed to prepare update stream trans since %s", pTrans->id, tstrerror(code));
sdbRelease(pMnode->pSdb, pStream); sdbRelease(pMnode->pSdb, pStream);
mndTransDrop(pTrans); mndTransDrop(pTrans);
return code; return code;
@ -2276,7 +2300,11 @@ static int32_t mndProcessNodeCheckReq(SRpcMsg *pMsg) {
goto _end; goto _end;
} }
SVgroupChangeInfo changeInfo = mndFindChangedNodeInfo(pMnode, execInfo.pNodeList, pNodeSnapshot); SVgroupChangeInfo changeInfo = {0};
code = mndFindChangedNodeInfo(pMnode, execInfo.pNodeList, pNodeSnapshot, &changeInfo);
if (code) {
goto _end;
}
{ {
if (execInfo.role == NODE_ROLE_LEADER && execInfo.switchFromFollower) { if (execInfo.role == NODE_ROLE_LEADER && execInfo.switchFromFollower) {
@ -2310,8 +2338,7 @@ static int32_t mndProcessNodeCheckReq(SRpcMsg *pMsg) {
mDebug("no update found in nodeList"); mDebug("no update found in nodeList");
} }
taosArrayDestroy(changeInfo.pUpdateNodeList); mndDestroyVgroupChangeInfo(&changeInfo);
taosHashCleanup(changeInfo.pDBMap);
_end: _end:
streamMutexUnlock(&execInfo.lock); streamMutexUnlock(&execInfo.lock);
@ -2640,9 +2667,8 @@ int32_t mndProcessCheckpointReport(SRpcMsg *pReq) {
void *p = taosHashGet(execInfo.pTaskMap, &id, sizeof(id)); void *p = taosHashGet(execInfo.pTaskMap, &id, sizeof(id));
if (p == NULL) { if (p == NULL) {
mError("failed to find the stream:0x%" PRIx64 " in buf, not handle the checkpoint-report", req.streamId); mError("failed to find the stream:0x%" PRIx64 " in buf, not handle the checkpoint-report", req.streamId);
terrno = TSDB_CODE_MND_STREAM_NOT_EXIST;
streamMutexUnlock(&execInfo.lock); streamMutexUnlock(&execInfo.lock);
return terrno; return TSDB_CODE_MND_STREAM_NOT_EXIST;
} else { } else {
mDebug("s-task:0x%" PRIx64 "-0x%x in buf not in mnode/meta, create stream trans may not complete yet", mDebug("s-task:0x%" PRIx64 "-0x%x in buf not in mnode/meta, create stream trans may not complete yet",
req.streamId, req.taskId); req.streamId, req.taskId);
@ -2993,7 +3019,7 @@ int32_t mndCreateStreamChkptInfoUpdateTrans(SMnode *pMnode, SStreamObj *pStream,
code = mndTransPrepare(pMnode, pTrans); code = mndTransPrepare(pMnode, pTrans);
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) {
mError("trans:%d, failed to prepare update checkpoint-info meta trans since %s", pTrans->id, terrstr()); mError("trans:%d, failed to prepare update checkpoint-info meta trans since %s", pTrans->id, tstrerror(code));
sdbRelease(pMnode->pSdb, pStream); sdbRelease(pMnode->pSdb, pStream);
mndTransDrop(pTrans); mndTransDrop(pTrans);
return code; return code;
@ -3038,9 +3064,8 @@ static int32_t mndProcessDropOrphanTaskReq(SRpcMsg *pReq) {
} }
// check if it is conflict with other trans in both sourceDb and targetDb. // check if it is conflict with other trans in both sourceDb and targetDb.
bool conflict = mndStreamTransConflictCheck(pMnode, pTask->streamId, MND_STREAM_DROP_NAME, false); code = mndStreamTransConflictCheck(pMnode, pTask->streamId, MND_STREAM_DROP_NAME, false);
if (conflict) { if (code) {
code = TSDB_CODE_MND_TRANS_CONFLICT;
goto _err; goto _err;
} }
@ -3048,7 +3073,7 @@ static int32_t mndProcessDropOrphanTaskReq(SRpcMsg *pReq) {
code = doCreateTrans(pMnode, &dummyObj, NULL, TRN_CONFLICT_NOTHING, MND_STREAM_DROP_NAME, "drop stream", &pTrans); code = doCreateTrans(pMnode, &dummyObj, NULL, TRN_CONFLICT_NOTHING, MND_STREAM_DROP_NAME, "drop stream", &pTrans);
if (pTrans == NULL || code != 0) { if (pTrans == NULL || code != 0) {
mError("failed to create trans to drop orphan tasks since %s", terrstr()); mError("failed to create trans to drop orphan tasks since %s", tstrerror(code));
goto _err; goto _err;
} }
@ -3059,7 +3084,7 @@ static int32_t mndProcessDropOrphanTaskReq(SRpcMsg *pReq) {
// drop all tasks // drop all tasks
if ((code = mndStreamSetDropActionFromList(pMnode, pTrans, msg.pList)) < 0) { if ((code = mndStreamSetDropActionFromList(pMnode, pTrans, msg.pList)) < 0) {
mError("failed to create trans to drop orphan tasks since %s", terrstr()); mError("failed to create trans to drop orphan tasks since %s", tstrerror(code));
goto _err; goto _err;
} }
@ -3070,7 +3095,7 @@ static int32_t mndProcessDropOrphanTaskReq(SRpcMsg *pReq) {
code = mndTransPrepare(pMnode, pTrans); code = mndTransPrepare(pMnode, pTrans);
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) {
mError("trans:%d, failed to prepare drop stream trans since %s", pTrans->id, terrstr()); mError("trans:%d, failed to prepare drop stream trans since %s", pTrans->id, tstrerror(code));
goto _err; goto _err;
} }

View File

@ -100,7 +100,7 @@ int32_t mndCreateStreamResetStatusTrans(SMnode *pMnode, SStreamObj *pStream) {
code = mndTransPrepare(pMnode, pTrans); code = mndTransPrepare(pMnode, pTrans);
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) {
mError("trans:%d, failed to prepare update stream trans since %s", pTrans->id, terrstr()); mError("trans:%d, failed to prepare update stream trans since %s", pTrans->id, tstrerror(code));
sdbRelease(pMnode->pSdb, pStream); sdbRelease(pMnode->pSdb, pStream);
mndTransDrop(pTrans); mndTransDrop(pTrans);
return code; return code;
@ -109,6 +109,9 @@ int32_t mndCreateStreamResetStatusTrans(SMnode *pMnode, SStreamObj *pStream) {
sdbRelease(pMnode->pSdb, pStream); sdbRelease(pMnode->pSdb, pStream);
mndTransDrop(pTrans); mndTransDrop(pTrans);
if (code == 0) {
code = TSDB_CODE_ACTION_IN_PROGRESS;
}
return code; return code;
} }
@ -221,8 +224,8 @@ int32_t mndProcessResetStatusReq(SRpcMsg *pReq) {
code = TSDB_CODE_STREAM_TASK_NOT_EXIST; code = TSDB_CODE_STREAM_TASK_NOT_EXIST;
mError("failed to acquire the streamObj:0x%" PRIx64 " to reset checkpoint, may have been dropped", pStream->uid); mError("failed to acquire the streamObj:0x%" PRIx64 " to reset checkpoint, may have been dropped", pStream->uid);
} else { } else {
bool conflict = mndStreamTransConflictCheck(pMnode, pStream->uid, MND_STREAM_TASK_RESET_NAME, false); code = mndStreamTransConflictCheck(pMnode, pStream->uid, MND_STREAM_TASK_RESET_NAME, false);
if (conflict) { if (code) {
mError("stream:%s other trans exists in DB:%s, dstTable:%s failed to start reset-status trans", pStream->name, mError("stream:%s other trans exists in DB:%s, dstTable:%s failed to start reset-status trans", pStream->name,
pStream->sourceDb, pStream->targetSTbName); pStream->sourceDb, pStream->targetSTbName);
} else { } else {

View File

@ -50,7 +50,7 @@ int32_t mndStreamClearFinishedTrans(SMnode *pMnode, int32_t *pNumOfActiveChkpt)
pEntry->startTime); pEntry->startTime);
void* p = taosArrayPush(pList, &info); void* p = taosArrayPush(pList, &info);
if (p == NULL) { if (p == NULL) {
return TSDB_CODE_OUT_OF_MEMORY; return terrno;
} }
} else { } else {
if (strcmp(pEntry->name, MND_STREAM_CHECKPOINT_NAME) == 0) { if (strcmp(pEntry->name, MND_STREAM_CHECKPOINT_NAME) == 0) {
@ -77,7 +77,6 @@ int32_t mndStreamClearFinishedTrans(SMnode *pMnode, int32_t *pNumOfActiveChkpt)
mDebug("clear %d finished stream-trans, remained:%d, active checkpoint trans:%d", size, mDebug("clear %d finished stream-trans, remained:%d, active checkpoint trans:%d", size,
taosHashGetSize(execInfo.transMgmt.pDBTrans), num); taosHashGetSize(execInfo.transMgmt.pDBTrans), num);
terrno = TSDB_CODE_SUCCESS;
taosArrayDestroy(pList); taosArrayDestroy(pList);
if (pNumOfActiveChkpt != NULL) { if (pNumOfActiveChkpt != NULL) {
@ -91,7 +90,7 @@ int32_t mndStreamClearFinishedTrans(SMnode *pMnode, int32_t *pNumOfActiveChkpt)
// For a given stream: // For a given stream:
// 1. checkpoint trans is conflict with any other trans except for the drop and reset trans. // 1. checkpoint trans is conflict with any other trans except for the drop and reset trans.
// 2. create/drop/reset/update trans are conflict with any other trans. // 2. create/drop/reset/update trans are conflict with any other trans.
bool mndStreamTransConflictCheck(SMnode *pMnode, int64_t streamId, const char *pTransName, bool lock) { int32_t mndStreamTransConflictCheck(SMnode *pMnode, int64_t streamId, const char *pTransName, bool lock) {
if (lock) { if (lock) {
streamMutexLock(&execInfo.lock); streamMutexLock(&execInfo.lock);
} }
@ -101,7 +100,7 @@ bool mndStreamTransConflictCheck(SMnode *pMnode, int64_t streamId, const char *p
if (lock) { if (lock) {
streamMutexUnlock(&execInfo.lock); streamMutexUnlock(&execInfo.lock);
} }
return false; return 0;
} }
int32_t code = mndStreamClearFinishedTrans(pMnode, NULL); int32_t code = mndStreamClearFinishedTrans(pMnode, NULL);
@ -121,8 +120,7 @@ bool mndStreamTransConflictCheck(SMnode *pMnode, int64_t streamId, const char *p
if ((strcmp(pTransName, MND_STREAM_DROP_NAME) != 0) && (strcmp(pTransName, MND_STREAM_TASK_RESET_NAME) != 0)) { if ((strcmp(pTransName, MND_STREAM_DROP_NAME) != 0) && (strcmp(pTransName, MND_STREAM_TASK_RESET_NAME) != 0)) {
mWarn("conflict with other transId:%d streamUid:0x%" PRIx64 ", trans:%s", tInfo.transId, tInfo.streamId, mWarn("conflict with other transId:%d streamUid:0x%" PRIx64 ", trans:%s", tInfo.transId, tInfo.streamId,
tInfo.name); tInfo.name);
terrno = TSDB_CODE_MND_TRANS_CONFLICT; return TSDB_CODE_MND_TRANS_CONFLICT;
return true;
} else { } else {
mDebug("not conflict with checkpoint trans, name:%s, continue creating trans", pTransName); mDebug("not conflict with checkpoint trans, name:%s, continue creating trans", pTransName);
} }
@ -131,8 +129,7 @@ bool mndStreamTransConflictCheck(SMnode *pMnode, int64_t streamId, const char *p
strcmp(tInfo.name, MND_STREAM_TASK_UPDATE_NAME) == 0) { strcmp(tInfo.name, MND_STREAM_TASK_UPDATE_NAME) == 0) {
mWarn("conflict with other transId:%d streamUid:0x%" PRIx64 ", trans:%s", tInfo.transId, tInfo.streamId, mWarn("conflict with other transId:%d streamUid:0x%" PRIx64 ", trans:%s", tInfo.transId, tInfo.streamId,
tInfo.name); tInfo.name);
terrno = TSDB_CODE_MND_TRANS_CONFLICT; return TSDB_CODE_MND_TRANS_CONFLICT;
return true;
} }
} else { } else {
mDebug("stream:0x%" PRIx64 " no conflict trans existed, continue create trans", streamId); mDebug("stream:0x%" PRIx64 " no conflict trans existed, continue create trans", streamId);
@ -142,7 +139,7 @@ bool mndStreamTransConflictCheck(SMnode *pMnode, int64_t streamId, const char *p
streamMutexUnlock(&execInfo.lock); streamMutexUnlock(&execInfo.lock);
} }
return false; return 0;
} }
int32_t mndStreamGetRelTrans(SMnode *pMnode, int64_t streamId) { int32_t mndStreamGetRelTrans(SMnode *pMnode, int64_t streamId) {
@ -202,47 +199,48 @@ int32_t doCreateTrans(SMnode *pMnode, SStreamObj *pStream, SRpcMsg *pReq, ETrnCo
SSdbRaw *mndStreamActionEncode(SStreamObj *pStream) { SSdbRaw *mndStreamActionEncode(SStreamObj *pStream) {
int32_t code = 0; int32_t code = 0;
int32_t lino = 0; int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY; void *buf = NULL;
void *buf = NULL;
SEncoder encoder; SEncoder encoder;
tEncoderInit(&encoder, NULL, 0); tEncoderInit(&encoder, NULL, 0);
if (tEncodeSStreamObj(&encoder, pStream) < 0) { if ((code = tEncodeSStreamObj(&encoder, pStream)) < 0) {
tEncoderClear(&encoder); tEncoderClear(&encoder);
goto STREAM_ENCODE_OVER; TSDB_CHECK_CODE(code, lino, _over);
} }
int32_t tlen = encoder.pos; int32_t tlen = encoder.pos;
tEncoderClear(&encoder); tEncoderClear(&encoder);
int32_t size = sizeof(int32_t) + tlen + MND_STREAM_RESERVE_SIZE; int32_t size = sizeof(int32_t) + tlen + MND_STREAM_RESERVE_SIZE;
SSdbRaw *pRaw = sdbAllocRaw(SDB_STREAM, MND_STREAM_VER_NUMBER, size); SSdbRaw *pRaw = sdbAllocRaw(SDB_STREAM, MND_STREAM_VER_NUMBER, size);
if (pRaw == NULL) goto STREAM_ENCODE_OVER; TSDB_CHECK_NULL(pRaw, code, lino, _over, terrno);
buf = taosMemoryMalloc(tlen); buf = taosMemoryMalloc(tlen);
if (buf == NULL) goto STREAM_ENCODE_OVER; TSDB_CHECK_NULL(buf, code, lino, _over, terrno);
tEncoderInit(&encoder, buf, tlen); tEncoderInit(&encoder, buf, tlen);
if (tEncodeSStreamObj(&encoder, pStream) < 0) { if ((code = tEncodeSStreamObj(&encoder, pStream)) < 0) {
tEncoderClear(&encoder); tEncoderClear(&encoder);
goto STREAM_ENCODE_OVER; TSDB_CHECK_CODE(code, lino, _over);
} }
tEncoderClear(&encoder); tEncoderClear(&encoder);
int32_t dataPos = 0; int32_t dataPos = 0;
SDB_SET_INT32(pRaw, dataPos, tlen, STREAM_ENCODE_OVER); SDB_SET_INT32(pRaw, dataPos, tlen, _over);
SDB_SET_BINARY(pRaw, dataPos, buf, tlen, STREAM_ENCODE_OVER); SDB_SET_BINARY(pRaw, dataPos, buf, tlen, _over);
SDB_SET_DATALEN(pRaw, dataPos, STREAM_ENCODE_OVER); SDB_SET_DATALEN(pRaw, dataPos, _over);
terrno = TSDB_CODE_SUCCESS; _over:
STREAM_ENCODE_OVER:
taosMemoryFreeClear(buf); taosMemoryFreeClear(buf);
if (terrno != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
mError("stream:%s, failed to encode to raw:%p since %s", pStream->name, pRaw, terrstr()); mError("stream:%s, failed to encode to raw:%p at line:%d since %s", pStream->name, pRaw, lino, tstrerror(code));
sdbFreeRaw(pRaw); sdbFreeRaw(pRaw);
terrno = code;
return NULL; return NULL;
} }
terrno = 0;
mTrace("stream:%s, encode to raw:%p, row:%p, checkpoint:%" PRId64 "", pStream->name, pRaw, pStream, mTrace("stream:%s, encode to raw:%p, row:%p, checkpoint:%" PRId64 "", pStream->name, pRaw, pStream,
pStream->checkpointId); pStream->checkpointId);
return pRaw; return pRaw;

View File

@ -653,7 +653,7 @@ static int32_t doSetUpdateTaskAction(SMnode *pMnode, STrans *pTrans, SStreamTask
return code; return code;
} }
code = setTransAction(pTrans, pBuf, len, TDMT_VND_STREAM_TASK_UPDATE, &epset, TSDB_CODE_VND_INVALID_VGROUP_ID, 0); code = setTransAction(pTrans, pBuf, len, TDMT_VND_STREAM_TASK_UPDATE, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
taosMemoryFree(pBuf); taosMemoryFree(pBuf);
} }
@ -1105,8 +1105,8 @@ int32_t mndScanCheckpointReportInfo(SRpcMsg *pReq) {
mDebug("stream:0x%" PRIx64 " %s all %d tasks send checkpoint-report, start to update checkpoint-info", mDebug("stream:0x%" PRIx64 " %s all %d tasks send checkpoint-report, start to update checkpoint-info",
pStream->uid, pStream->name, total); pStream->uid, pStream->name, total);
bool conflict = mndStreamTransConflictCheck(pMnode, pStream->uid, MND_STREAM_CHKPT_UPDATE_NAME, false); code = mndStreamTransConflictCheck(pMnode, pStream->uid, MND_STREAM_CHKPT_UPDATE_NAME, false);
if (!conflict) { if (code == 0) {
code = mndCreateStreamChkptInfoUpdateTrans(pMnode, pStream, px->pTaskList); code = mndCreateStreamChkptInfoUpdateTrans(pMnode, pStream, px->pTaskList);
if (code == TSDB_CODE_SUCCESS || code == TSDB_CODE_ACTION_IN_PROGRESS) { // remove this entry if (code == TSDB_CODE_SUCCESS || code == TSDB_CODE_ACTION_IN_PROGRESS) { // remove this entry
taosArrayClear(px->pTaskList); taosArrayClear(px->pTaskList);
@ -1859,3 +1859,73 @@ int32_t setTaskAttrInResBlock(SStreamObj *pStream, SStreamTask *pTask, SSDataBlo
} }
return code; return code;
} }
uint32_t seed = 0;
static SRpcMsg createRpcMsg(STransAction* pAction, int64_t traceId, int64_t signature) {
SRpcMsg rpcMsg = {.msgType = pAction->msgType, .contLen = pAction->contLen, .info.ahandle = (void *)signature};
rpcMsg.pCont = rpcMallocCont(pAction->contLen);
if (rpcMsg.pCont == NULL) {
return rpcMsg;
}
rpcMsg.info.traceId.rootId = traceId;
rpcMsg.info.notFreeAhandle = 1;
memcpy(rpcMsg.pCont, pAction->pCont, pAction->contLen);
return rpcMsg;
}
void streamTransRandomErrorGen(STransAction *pAction, STrans *pTrans, int64_t signature) {
if ((pAction->msgType == TDMT_STREAM_TASK_UPDATE_CHKPT && pAction->id > 2) ||
(pAction->msgType == TDMT_STREAM_CONSEN_CHKPT) ||
(pAction->msgType == TDMT_VND_STREAM_CHECK_POINT_SOURCE && pAction->id > 2)) {
if (seed == 0) {
seed = taosGetTimestampSec();
}
uint32_t v = taosRandR(&seed);
int32_t choseItem = v % 5;
if (choseItem == 0) {
// 1. one of update-checkpoint not send, restart and send it again
taosMsleep(5000);
if (pAction->msgType == TDMT_STREAM_TASK_UPDATE_CHKPT) {
mError(
"***sleep 5s and core dump, following tasks will not recv update-checkpoint info, so the checkpoint will "
"rollback***");
exit(-1);
} else if (pAction->msgType == TDMT_STREAM_CONSEN_CHKPT) { // pAction->msgType == TDMT_STREAM_CONSEN_CHKPT
mError(
"***sleep 5s and core dump, following tasks will not recv consen-checkpoint info, so the tasks will "
"not started***");
} else { // pAction->msgType == TDMT_VND_STREAM_CHECK_POINT_SOURCE
mError(
"***sleep 5s and core dump, following tasks will not recv checkpoint-source info, so the tasks will "
"started after restart***");
exit(-1);
}
} else if (choseItem == 1) {
// 2. repeat send update chkpt msg
mError("***repeat send update-checkpoint/consensus/checkpoint trans msg 3times to vnode***");
mError("***repeat 1***");
SRpcMsg rpcMsg1 = createRpcMsg(pAction, pTrans->mTraceId, signature);
int32_t code = tmsgSendReq(&pAction->epSet, &rpcMsg1);
mError("***repeat 2***");
SRpcMsg rpcMsg2 = createRpcMsg(pAction, pTrans->mTraceId, signature);
code = tmsgSendReq(&pAction->epSet, &rpcMsg2);
mError("***repeat 3***");
SRpcMsg rpcMsg3 = createRpcMsg(pAction, pTrans->mTraceId, signature);
code = tmsgSendReq(&pAction->epSet, &rpcMsg3);
} else if (choseItem == 2) {
// 3. sleep 40s and then send msg
mError("***idle for 30s, and then send msg***");
taosMsleep(30000);
} else {
// do nothing
// mInfo("no error triggered");
}
}
}

View File

@ -86,8 +86,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
int64_t sver = 0; int64_t sver = 0;
int32_t ret = taosReadFile(pFile, &sver, sizeof(int64_t)); int32_t ret = taosReadFile(pFile, &sver, sizeof(int64_t));
if (ret < 0) { if (ret < 0) {
code = TAOS_SYSTEM_ERROR(errno); return terrno;
TAOS_RETURN(code);
} }
if (ret != sizeof(int64_t)) { if (ret != sizeof(int64_t)) {
code = TSDB_CODE_FILE_CORRUPTED; code = TSDB_CODE_FILE_CORRUPTED;
@ -100,8 +99,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
ret = taosReadFile(pFile, &pSdb->applyIndex, sizeof(int64_t)); ret = taosReadFile(pFile, &pSdb->applyIndex, sizeof(int64_t));
if (ret < 0) { if (ret < 0) {
code = TAOS_SYSTEM_ERROR(errno); return terrno;
TAOS_RETURN(code);
} }
if (ret != sizeof(int64_t)) { if (ret != sizeof(int64_t)) {
code = TSDB_CODE_FILE_CORRUPTED; code = TSDB_CODE_FILE_CORRUPTED;
@ -110,8 +108,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
ret = taosReadFile(pFile, &pSdb->applyTerm, sizeof(int64_t)); ret = taosReadFile(pFile, &pSdb->applyTerm, sizeof(int64_t));
if (ret < 0) { if (ret < 0) {
code = TAOS_SYSTEM_ERROR(errno); return terrno;
TAOS_RETURN(code);
} }
if (ret != sizeof(int64_t)) { if (ret != sizeof(int64_t)) {
code = TSDB_CODE_FILE_CORRUPTED; code = TSDB_CODE_FILE_CORRUPTED;
@ -120,8 +117,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
ret = taosReadFile(pFile, &pSdb->applyConfig, sizeof(int64_t)); ret = taosReadFile(pFile, &pSdb->applyConfig, sizeof(int64_t));
if (ret < 0) { if (ret < 0) {
code = TAOS_SYSTEM_ERROR(errno); return terrno;
TAOS_RETURN(code);
} }
if (ret != sizeof(int64_t)) { if (ret != sizeof(int64_t)) {
code = TSDB_CODE_FILE_CORRUPTED; code = TSDB_CODE_FILE_CORRUPTED;
@ -132,8 +128,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
int64_t maxId = 0; int64_t maxId = 0;
ret = taosReadFile(pFile, &maxId, sizeof(int64_t)); ret = taosReadFile(pFile, &maxId, sizeof(int64_t));
if (ret < 0) { if (ret < 0) {
code = TAOS_SYSTEM_ERROR(errno); return terrno;
TAOS_RETURN(code);
} }
if (ret != sizeof(int64_t)) { if (ret != sizeof(int64_t)) {
code = TSDB_CODE_FILE_CORRUPTED; code = TSDB_CODE_FILE_CORRUPTED;
@ -148,8 +143,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
int64_t ver = 0; int64_t ver = 0;
ret = taosReadFile(pFile, &ver, sizeof(int64_t)); ret = taosReadFile(pFile, &ver, sizeof(int64_t));
if (ret < 0) { if (ret < 0) {
code = TAOS_SYSTEM_ERROR(errno); return terrno;
TAOS_RETURN(code);
} }
if (ret != sizeof(int64_t)) { if (ret != sizeof(int64_t)) {
code = TSDB_CODE_FILE_CORRUPTED; code = TSDB_CODE_FILE_CORRUPTED;
@ -163,8 +157,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
char reserve[SDB_RESERVE_SIZE] = {0}; char reserve[SDB_RESERVE_SIZE] = {0};
ret = taosReadFile(pFile, reserve, sizeof(reserve)); ret = taosReadFile(pFile, reserve, sizeof(reserve));
if (ret < 0) { if (ret < 0) {
code = TAOS_SYSTEM_ERROR(errno); return terrno;
TAOS_RETURN(code);
} }
if (ret != sizeof(reserve)) { if (ret != sizeof(reserve)) {
code = TSDB_CODE_FILE_CORRUPTED; code = TSDB_CODE_FILE_CORRUPTED;
@ -175,26 +168,21 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
} }
static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) { static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) {
int32_t code = 0;
int64_t sver = SDB_FILE_VER; int64_t sver = SDB_FILE_VER;
if (taosWriteFile(pFile, &sver, sizeof(int64_t)) != sizeof(int64_t)) { if (taosWriteFile(pFile, &sver, sizeof(int64_t)) != sizeof(int64_t)) {
code = TAOS_SYSTEM_ERROR(errno); return terrno;
TAOS_RETURN(code);
} }
if (taosWriteFile(pFile, &pSdb->applyIndex, sizeof(int64_t)) != sizeof(int64_t)) { if (taosWriteFile(pFile, &pSdb->applyIndex, sizeof(int64_t)) != sizeof(int64_t)) {
code = TAOS_SYSTEM_ERROR(errno); return terrno;
TAOS_RETURN(code);
} }
if (taosWriteFile(pFile, &pSdb->applyTerm, sizeof(int64_t)) != sizeof(int64_t)) { if (taosWriteFile(pFile, &pSdb->applyTerm, sizeof(int64_t)) != sizeof(int64_t)) {
code = TAOS_SYSTEM_ERROR(errno); return terrno;
TAOS_RETURN(code);
} }
if (taosWriteFile(pFile, &pSdb->applyConfig, sizeof(int64_t)) != sizeof(int64_t)) { if (taosWriteFile(pFile, &pSdb->applyConfig, sizeof(int64_t)) != sizeof(int64_t)) {
code = TAOS_SYSTEM_ERROR(errno); return terrno;
TAOS_RETURN(code);
} }
for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) { for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) {
@ -203,8 +191,7 @@ static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) {
maxId = pSdb->maxId[i]; maxId = pSdb->maxId[i];
} }
if (taosWriteFile(pFile, &maxId, sizeof(int64_t)) != sizeof(int64_t)) { if (taosWriteFile(pFile, &maxId, sizeof(int64_t)) != sizeof(int64_t)) {
code = TAOS_SYSTEM_ERROR(errno); return terrno;
TAOS_RETURN(code);
} }
} }
@ -214,15 +201,13 @@ static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) {
ver = pSdb->tableVer[i]; ver = pSdb->tableVer[i];
} }
if (taosWriteFile(pFile, &ver, sizeof(int64_t)) != sizeof(int64_t)) { if (taosWriteFile(pFile, &ver, sizeof(int64_t)) != sizeof(int64_t)) {
code = TAOS_SYSTEM_ERROR(errno); return terrno;
TAOS_RETURN(code);
} }
} }
char reserve[SDB_RESERVE_SIZE] = {0}; char reserve[SDB_RESERVE_SIZE] = {0};
if (taosWriteFile(pFile, reserve, sizeof(reserve)) != sizeof(reserve)) { if (taosWriteFile(pFile, reserve, sizeof(reserve)) != sizeof(reserve)) {
code = TAOS_SYSTEM_ERROR(errno); return terrno;
TAOS_RETURN(code);
} }
return 0; return 0;
@ -249,7 +234,7 @@ static int32_t sdbReadFileImp(SSdb *pSdb) {
TdFilePtr pFile = taosOpenFile(file, TD_FILE_READ); TdFilePtr pFile = taosOpenFile(file, TD_FILE_READ);
if (pFile == NULL) { if (pFile == NULL) {
taosMemoryFree(pRaw); taosMemoryFree(pRaw);
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
mInfo("read sdb file:%s finished since %s", file, tstrerror(code)); mInfo("read sdb file:%s finished since %s", file, tstrerror(code));
return 0; return 0;
} }
@ -274,7 +259,7 @@ static int32_t sdbReadFileImp(SSdb *pSdb) {
if (ret == 0) break; if (ret == 0) break;
if (ret < 0) { if (ret < 0) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
mError("failed to read sdb file:%s since %s", file, tstrerror(code)); mError("failed to read sdb file:%s since %s", file, tstrerror(code));
goto _OVER; goto _OVER;
} }
@ -305,7 +290,7 @@ static int32_t sdbReadFileImp(SSdb *pSdb) {
ret = taosReadFile(pFile, pRaw->pData, readLen); ret = taosReadFile(pFile, pRaw->pData, readLen);
if (ret < 0) { if (ret < 0) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
mError("failed to read sdb file:%s since %s, ret:%" PRId64 " readLen:%d", file, tstrerror(code), ret, readLen); mError("failed to read sdb file:%s since %s, ret:%" PRId64 " readLen:%d", file, tstrerror(code), ret, readLen);
goto _OVER; goto _OVER;
} }
@ -401,7 +386,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) {
TdFilePtr pFile = taosOpenFile(tmpfile, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); TdFilePtr pFile = taosOpenFile(tmpfile, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
if (pFile == NULL) { if (pFile == NULL) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
mError("failed to open sdb file:%s for write since %s", tmpfile, tstrerror(code)); mError("failed to open sdb file:%s for write since %s", tmpfile, tstrerror(code));
TAOS_RETURN(code); TAOS_RETURN(code);
} }
@ -447,7 +432,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) {
pRaw->status = pRow->status; pRaw->status = pRow->status;
if (taosWriteFile(pFile, pRaw, sizeof(SSdbRaw)) != sizeof(SSdbRaw)) { if (taosWriteFile(pFile, pRaw, sizeof(SSdbRaw)) != sizeof(SSdbRaw)) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
taosHashCancelIterate(hash, ppRow); taosHashCancelIterate(hash, ppRow);
sdbFreeRaw(pRaw); sdbFreeRaw(pRaw);
break; break;
@ -479,7 +464,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) {
} }
if (taosWriteFile(pFile, newData, newDataLen) != newDataLen) { if (taosWriteFile(pFile, newData, newDataLen) != newDataLen) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
taosHashCancelIterate(hash, ppRow); taosHashCancelIterate(hash, ppRow);
sdbFreeRaw(pRaw); sdbFreeRaw(pRaw);
break; break;
@ -491,7 +476,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) {
int32_t cksum = taosCalcChecksum(0, (const uint8_t *)pRaw, sizeof(SSdbRaw) + pRaw->dataLen); int32_t cksum = taosCalcChecksum(0, (const uint8_t *)pRaw, sizeof(SSdbRaw) + pRaw->dataLen);
if (taosWriteFile(pFile, &cksum, sizeof(int32_t)) != sizeof(int32_t)) { if (taosWriteFile(pFile, &cksum, sizeof(int32_t)) != sizeof(int32_t)) {
code = TAOS_SYSTEM_ERROR(errno); code = errno;
taosHashCancelIterate(hash, ppRow); taosHashCancelIterate(hash, ppRow);
sdbFreeRaw(pRaw); sdbFreeRaw(pRaw);
break; break;
@ -523,7 +508,6 @@ static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) {
if (code == 0) { if (code == 0) {
code = taosRenameFile(tmpfile, curfile); code = taosRenameFile(tmpfile, curfile);
if (code != 0) { if (code != 0) {
code = TAOS_SYSTEM_ERROR(errno);
mError("failed to write sdb file:%s since %s", curfile, tstrerror(code)); mError("failed to write sdb file:%s since %s", curfile, tstrerror(code));
} }
} }
@ -654,8 +638,8 @@ int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *ter
int64_t commitTerm = pSdb->commitTerm; int64_t commitTerm = pSdb->commitTerm;
int64_t commitConfig = pSdb->commitConfig; int64_t commitConfig = pSdb->commitConfig;
if (taosCopyFile(datafile, pIter->name) < 0) { if (taosCopyFile(datafile, pIter->name) < 0) {
code = terrno;
(void)taosThreadMutexUnlock(&pSdb->filelock); (void)taosThreadMutexUnlock(&pSdb->filelock);
code = TAOS_SYSTEM_ERROR(errno);
mError("failed to copy sdb file %s to %s since %s", datafile, pIter->name, tstrerror(code)); mError("failed to copy sdb file %s to %s since %s", datafile, pIter->name, tstrerror(code));
sdbCloseIter(pIter); sdbCloseIter(pIter);
TAOS_RETURN(code); TAOS_RETURN(code);
@ -664,7 +648,7 @@ int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *ter
pIter->file = taosOpenFile(pIter->name, TD_FILE_READ); pIter->file = taosOpenFile(pIter->name, TD_FILE_READ);
if (pIter->file == NULL) { if (pIter->file == NULL) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
mError("failed to open sdb file:%s since %s", pIter->name, tstrerror(code)); mError("failed to open sdb file:%s since %s", pIter->name, tstrerror(code));
sdbCloseIter(pIter); sdbCloseIter(pIter);
TAOS_RETURN(code); TAOS_RETURN(code);
@ -693,7 +677,7 @@ int32_t sdbDoRead(SSdb *pSdb, SSdbIter *pIter, void **ppBuf, int32_t *len) {
int32_t readlen = taosReadFile(pIter->file, pBuf, maxlen); int32_t readlen = taosReadFile(pIter->file, pBuf, maxlen);
if (readlen < 0 || readlen > maxlen) { if (readlen < 0 || readlen > maxlen) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
mError("sdbiter:%p, failed to read snapshot since %s, total:%" PRId64, pIter, tstrerror(code), pIter->total); mError("sdbiter:%p, failed to read snapshot since %s, total:%" PRId64, pIter, tstrerror(code), pIter->total);
*ppBuf = NULL; *ppBuf = NULL;
*len = 0; *len = 0;
@ -724,7 +708,7 @@ int32_t sdbStartWrite(SSdb *pSdb, SSdbIter **ppIter) {
pIter->file = taosOpenFile(pIter->name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); pIter->file = taosOpenFile(pIter->name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
if (pIter->file == NULL) { if (pIter->file == NULL) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
mError("failed to open %s since %s", pIter->name, tstrerror(code)); mError("failed to open %s since %s", pIter->name, tstrerror(code));
sdbCloseIter(pIter); sdbCloseIter(pIter);
TAOS_RETURN(code); TAOS_RETURN(code);
@ -758,8 +742,8 @@ int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply, int64_t index, i
char datafile[PATH_MAX] = {0}; char datafile[PATH_MAX] = {0};
snprintf(datafile, sizeof(datafile), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP); snprintf(datafile, sizeof(datafile), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP);
if (taosRenameFile(pIter->name, datafile) != 0) { code = taosRenameFile(pIter->name, datafile);
code = TAOS_SYSTEM_ERROR(errno); if (code != 0) {
mError("sdbiter:%p, failed to rename file %s to %s since %s", pIter, pIter->name, datafile, tstrerror(code)); mError("sdbiter:%p, failed to rename file %s to %s since %s", pIter, pIter->name, datafile, tstrerror(code));
goto _OVER; goto _OVER;
} }
@ -792,7 +776,7 @@ int32_t sdbDoWrite(SSdb *pSdb, SSdbIter *pIter, void *pBuf, int32_t len) {
int32_t code = 0; int32_t code = 0;
int32_t writelen = taosWriteFile(pIter->file, pBuf, len); int32_t writelen = taosWriteFile(pIter->file, pBuf, len);
if (writelen != len) { if (writelen != len) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
mError("failed to write len:%d since %s, total:%" PRId64, len, tstrerror(code), pIter->total); mError("failed to write len:%d since %s, total:%" PRId64, len, tstrerror(code), pIter->total);
TAOS_RETURN(code); TAOS_RETURN(code);
} }

View File

@ -243,7 +243,7 @@ int32_t tsdbMemTableCreate(STsdb *pTsdb, SMemTable **ppMemTable);
void tsdbMemTableDestroy(SMemTable *pMemTable, bool proactive); void tsdbMemTableDestroy(SMemTable *pMemTable, bool proactive);
STbData *tsdbGetTbDataFromMemTable(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t uid); STbData *tsdbGetTbDataFromMemTable(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t uid);
int32_t tsdbRefMemTable(SMemTable *pMemTable, SQueryNode *pQNode); int32_t tsdbRefMemTable(SMemTable *pMemTable, SQueryNode *pQNode);
int32_t tsdbUnrefMemTable(SMemTable *pMemTable, SQueryNode *pNode, bool proactive); void tsdbUnrefMemTable(SMemTable *pMemTable, SQueryNode *pNode, bool proactive);
// STbDataIter // STbDataIter
int32_t tsdbTbDataIterCreate(STbData *pTbData, STsdbRowKey *pFrom, int8_t backward, STbDataIter **ppIter); int32_t tsdbTbDataIterCreate(STbData *pTbData, STsdbRowKey *pFrom, int8_t backward, STbDataIter **ppIter);
void *tsdbTbDataIterDestroy(STbDataIter *pIter); void *tsdbTbDataIterDestroy(STbDataIter *pIter);
@ -280,19 +280,19 @@ void tsdbGetCurrentFName(STsdb *pTsdb, char *current, char *current_t);
// tsdbReaderWriter.c ============================================================================================== // tsdbReaderWriter.c ==============================================================================================
// SDataFReader // SDataFReader
int32_t tsdbDataFReaderOpen(SDataFReader **ppReader, STsdb *pTsdb, SDFileSet *pSet); int32_t tsdbDataFReaderOpen(SDataFReader **ppReader, STsdb *pTsdb, SDFileSet *pSet);
int32_t tsdbDataFReaderClose(SDataFReader **ppReader); void tsdbDataFReaderClose(SDataFReader **ppReader);
int32_t tsdbReadBlockIdx(SDataFReader *pReader, SArray *aBlockIdx); int32_t tsdbReadBlockIdx(SDataFReader *pReader, SArray *aBlockIdx);
int32_t tsdbReadDataBlk(SDataFReader *pReader, SBlockIdx *pBlockIdx, SMapData *mDataBlk); int32_t tsdbReadDataBlk(SDataFReader *pReader, SBlockIdx *pBlockIdx, SMapData *mDataBlk);
int32_t tsdbReadSttBlk(SDataFReader *pReader, int32_t iStt, SArray *aSttBlk); int32_t tsdbReadSttBlk(SDataFReader *pReader, int32_t iStt, SArray *aSttBlk);
// SDelFReader // SDelFReader
int32_t tsdbDelFReaderOpen(SDelFReader **ppReader, SDelFile *pFile, STsdb *pTsdb); int32_t tsdbDelFReaderOpen(SDelFReader **ppReader, SDelFile *pFile, STsdb *pTsdb);
int32_t tsdbDelFReaderClose(SDelFReader **ppReader); void tsdbDelFReaderClose(SDelFReader **ppReader);
int32_t tsdbReadDelDatav1(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelData, int64_t maxVer); int32_t tsdbReadDelDatav1(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelData, int64_t maxVer);
int32_t tsdbReadDelData(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelData); int32_t tsdbReadDelData(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelData);
int32_t tsdbReadDelIdx(SDelFReader *pReader, SArray *aDelIdx); int32_t tsdbReadDelIdx(SDelFReader *pReader, SArray *aDelIdx);
// tsdbRead.c ============================================================================================== // tsdbRead.c ==============================================================================================
int32_t tsdbTakeReadSnap2(STsdbReader *pReader, _query_reseek_func_t reseek, STsdbReadSnap **ppSnap); int32_t tsdbTakeReadSnap2(STsdbReader *pReader, _query_reseek_func_t reseek, STsdbReadSnap **ppSnap, const char* id);
void tsdbUntakeReadSnap2(STsdbReader *pReader, STsdbReadSnap *pSnap, bool proactive); void tsdbUntakeReadSnap2(STsdbReader *pReader, STsdbReadSnap *pSnap, bool proactive);
int32_t tsdbGetTableSchema(SMeta *pMeta, int64_t uid, STSchema **pSchema, int64_t *suid); int32_t tsdbGetTableSchema(SMeta *pMeta, int64_t uid, STSchema **pSchema, int64_t *suid);
@ -377,7 +377,7 @@ struct STsdb {
struct { struct {
SVHashTable *ht; SVHashTable *ht;
SArray *arr; SArray *arr;
} * commitInfo; } *commitInfo;
}; };
struct TSDBKEY { struct TSDBKEY {
@ -678,8 +678,8 @@ typedef TARRAY2(STFileSet *) TFileSetArray;
typedef struct STFileSetRange STFileSetRange; typedef struct STFileSetRange STFileSetRange;
typedef TARRAY2(STFileSetRange *) TFileSetRangeArray; // disjoint ranges typedef TARRAY2(STFileSetRange *) TFileSetRangeArray; // disjoint ranges
int32_t tsdbTFileSetRangeClear(STFileSetRange **fsr); void tsdbTFileSetRangeClear(STFileSetRange **fsr);
int32_t tsdbTFileSetRangeArrayDestroy(TFileSetRangeArray **ppArr); void tsdbTFileSetRangeArrayDestroy(TFileSetRangeArray **ppArr);
// fset partition // fset partition
enum { enum {
@ -898,7 +898,7 @@ typedef struct SSttDataInfoForTable {
int32_t tMergeTreeOpen2(SMergeTree *pMTree, SMergeTreeConf *pConf, SSttDataInfoForTable *pTableInfo); int32_t tMergeTreeOpen2(SMergeTree *pMTree, SMergeTreeConf *pConf, SSttDataInfoForTable *pTableInfo);
void tMergeTreeAddIter(SMergeTree *pMTree, SLDataIter *pIter); void tMergeTreeAddIter(SMergeTree *pMTree, SLDataIter *pIter);
int32_t tMergeTreeNext(SMergeTree *pMTree, bool* pHasNext); int32_t tMergeTreeNext(SMergeTree *pMTree, bool *pHasNext);
void tMergeTreePinSttBlock(SMergeTree *pMTree); void tMergeTreePinSttBlock(SMergeTree *pMTree);
void tMergeTreeUnpinSttBlock(SMergeTree *pMTree); void tMergeTreeUnpinSttBlock(SMergeTree *pMTree);
bool tMergeTreeIgnoreEarlierTs(SMergeTree *pMTree); bool tMergeTreeIgnoreEarlierTs(SMergeTree *pMTree);
@ -914,13 +914,13 @@ typedef enum {
READER_EXEC_ROWS = 0x2, READER_EXEC_ROWS = 0x2,
} EExecMode; } EExecMode;
#define LAST_COL_VERSION_1 (0x1) // add primary key, version #define LAST_COL_VERSION_1 (0x1) // add primary key, version
#define LAST_COL_VERSION_2 (0x2) // add cache status #define LAST_COL_VERSION_2 (0x2) // add cache status
#define LAST_COL_VERSION LAST_COL_VERSION_2 #define LAST_COL_VERSION LAST_COL_VERSION_2
typedef enum { typedef enum {
TSDB_LAST_CACHE_VALID = 0, // last_cache has valid data TSDB_LAST_CACHE_VALID = 0, // last_cache has valid data
TSDB_LAST_CACHE_NO_CACHE, // last_cache has no data, but tsdb may have data TSDB_LAST_CACHE_NO_CACHE, // last_cache has no data, but tsdb may have data
} ELastCacheStatus; } ELastCacheStatus;
typedef struct { typedef struct {
@ -1069,6 +1069,8 @@ typedef enum {
ETsdbFsState tsdbSnapGetFsState(SVnode *pVnode); ETsdbFsState tsdbSnapGetFsState(SVnode *pVnode);
int32_t tsdbSnapPrepDescription(SVnode *pVnode, SSnapshot *pSnap); int32_t tsdbSnapPrepDescription(SVnode *pVnode, SSnapshot *pSnap);
void tsdbRemoveFile(const char *path);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -56,12 +56,12 @@ typedef enum {
} EVAPriority; } EVAPriority;
int32_t vnodeAsyncOpen(int32_t numOfThreads); int32_t vnodeAsyncOpen(int32_t numOfThreads);
int32_t vnodeAsyncClose(); void vnodeAsyncClose();
int32_t vnodeAChannelInit(int64_t async, SVAChannelID* channelID); int32_t vnodeAChannelInit(int64_t async, SVAChannelID* channelID);
int32_t vnodeAChannelDestroy(SVAChannelID* channelID, bool waitRunning); int32_t vnodeAChannelDestroy(SVAChannelID* channelID, bool waitRunning);
int32_t vnodeAsync(SVAChannelID* channelID, EVAPriority priority, int32_t (*execute)(void*), void (*complete)(void*), int32_t vnodeAsync(SVAChannelID* channelID, EVAPriority priority, int32_t (*execute)(void*), void (*complete)(void*),
void* arg, SVATaskID* taskID); void* arg, SVATaskID* taskID);
int32_t vnodeAWait(SVATaskID* taskID); void vnodeAWait(SVATaskID* taskID);
int32_t vnodeACancel(SVATaskID* taskID); int32_t vnodeACancel(SVATaskID* taskID);
int32_t vnodeAsyncSetWorkers(int64_t async, int32_t numWorkers); int32_t vnodeAsyncSetWorkers(int64_t async, int32_t numWorkers);
@ -95,13 +95,13 @@ struct SVBufPool {
}; };
int32_t vnodeOpenBufPool(SVnode* pVnode); int32_t vnodeOpenBufPool(SVnode* pVnode);
int32_t vnodeCloseBufPool(SVnode* pVnode); void vnodeCloseBufPool(SVnode* pVnode);
void vnodeBufPoolReset(SVBufPool* pPool); void vnodeBufPoolReset(SVBufPool* pPool);
void vnodeBufPoolAddToFreeList(SVBufPool* pPool); void vnodeBufPoolAddToFreeList(SVBufPool* pPool);
int32_t vnodeBufPoolRecycle(SVBufPool* pPool); int32_t vnodeBufPoolRecycle(SVBufPool* pPool);
// vnodeOpen.c // vnodeOpen.c
int32_t vnodeGetPrimaryDir(const char* relPath, int32_t diskPrimary, STfs* pTfs, char* buf, size_t bufLen); void vnodeGetPrimaryDir(const char* relPath, int32_t diskPrimary, STfs* pTfs, char* buf, size_t bufLen);
// vnodeQuery.c // vnodeQuery.c
int32_t vnodeQueryOpen(SVnode* pVnode); int32_t vnodeQueryOpen(SVnode* pVnode);

View File

@ -130,8 +130,8 @@ void vnodeBufPoolRef(SVBufPool* pPool);
void vnodeBufPoolUnRef(SVBufPool* pPool, bool proactive); void vnodeBufPoolUnRef(SVBufPool* pPool, bool proactive);
int vnodeDecodeInfo(uint8_t* pData, SVnodeInfo* pInfo); int vnodeDecodeInfo(uint8_t* pData, SVnodeInfo* pInfo);
int32_t vnodeBufPoolRegisterQuery(SVBufPool* pPool, SQueryNode* pQNode); void vnodeBufPoolRegisterQuery(SVBufPool* pPool, SQueryNode* pQNode);
void vnodeBufPoolDeregisterQuery(SVBufPool* pPool, SQueryNode* pQNode, bool proactive); void vnodeBufPoolDeregisterQuery(SVBufPool* pPool, SQueryNode* pQNode, bool proactive);
// meta // meta
typedef struct SMStbCursor SMStbCursor; typedef struct SMStbCursor SMStbCursor;
@ -161,6 +161,8 @@ int metaTtlFindExpired(SMeta* pMeta, int64_t timePointMs, SArray* tb
int metaAlterTable(SMeta* pMeta, int64_t version, SVAlterTbReq* pReq, STableMetaRsp* pMetaRsp); int metaAlterTable(SMeta* pMeta, int64_t version, SVAlterTbReq* pReq, STableMetaRsp* pMetaRsp);
int metaUpdateChangeTimeWithLock(SMeta* pMeta, tb_uid_t uid, int64_t changeTimeMs); int metaUpdateChangeTimeWithLock(SMeta* pMeta, tb_uid_t uid, int64_t changeTimeMs);
SSchemaWrapper* metaGetTableSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, int lock); SSchemaWrapper* metaGetTableSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, int lock);
int32_t metaGetTbTSchemaNotNull(SMeta* pMeta, tb_uid_t uid, int32_t sver, int lock, STSchema** ppTSchema);
int32_t metaGetTbTSchemaMaybeNull(SMeta* pMeta, tb_uid_t uid, int32_t sver, int lock, STSchema** ppTSchema);
STSchema* metaGetTbTSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, int lock); STSchema* metaGetTbTSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, int lock);
int32_t metaGetTbTSchemaEx(SMeta* pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sver, STSchema** ppTSchema); int32_t metaGetTbTSchemaEx(SMeta* pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sver, STSchema** ppTSchema);
int metaGetTableEntryByName(SMetaReader* pReader, const char* name); int metaGetTableEntryByName(SMetaReader* pReader, const char* name);
@ -221,7 +223,7 @@ int tsdbScanAndConvertSubmitMsg(STsdb* pTsdb, SSubmitReq2* pMsg);
int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq2* pMsg, SSubmitRsp2* pRsp); int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq2* pMsg, SSubmitRsp2* pRsp);
int32_t tsdbInsertTableData(STsdb* pTsdb, int64_t version, SSubmitTbData* pSubmitTbData, int32_t* affectedRows); int32_t tsdbInsertTableData(STsdb* pTsdb, int64_t version, SSubmitTbData* pSubmitTbData, int32_t* affectedRows);
int32_t tsdbDeleteTableData(STsdb* pTsdb, int64_t version, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey); int32_t tsdbDeleteTableData(STsdb* pTsdb, int64_t version, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey);
int32_t tsdbSetKeepCfg(STsdb* pTsdb, STsdbCfg* pCfg); void tsdbSetKeepCfg(STsdb* pTsdb, STsdbCfg* pCfg);
int64_t tsdbGetEarliestTs(STsdb* pTsdb); int64_t tsdbGetEarliestTs(STsdb* pTsdb);
// tq // tq
@ -591,7 +593,7 @@ struct SVHashTable {
#define vHashNumEntries(ht) ((ht)->numEntries) #define vHashNumEntries(ht) ((ht)->numEntries)
int32_t vHashInit(SVHashTable** ht, uint32_t (*hash)(const void*), int32_t (*compare)(const void*, const void*)); int32_t vHashInit(SVHashTable** ht, uint32_t (*hash)(const void*), int32_t (*compare)(const void*, const void*));
int32_t vHashDestroy(SVHashTable** ht); void vHashDestroy(SVHashTable** ht);
int32_t vHashPut(SVHashTable* ht, void* obj); int32_t vHashPut(SVHashTable* ht, void* obj);
int32_t vHashGet(SVHashTable* ht, const void* obj, void** retObj); int32_t vHashGet(SVHashTable* ht, const void* obj, void** retObj);
int32_t vHashDrop(SVHashTable* ht, const void* obj); int32_t vHashDrop(SVHashTable* ht, const void* obj);

View File

@ -48,7 +48,7 @@ int32_t metaOpen(SVnode *pVnode, SMeta **ppMeta, int8_t rollback) {
char indexFullPath[128] = {0}; char indexFullPath[128] = {0};
// create handle // create handle
(void)vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, path, TSDB_FILENAME_LEN); vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pVnode->pTfs, path, TSDB_FILENAME_LEN);
offset = strlen(path); offset = strlen(path);
snprintf(path + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, VNODE_META_DIR); snprintf(path + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, VNODE_META_DIR);

View File

@ -45,6 +45,7 @@ void metaReaderClear(SMetaReader *pReader) {
} }
tDecoderClear(&pReader->coder); tDecoderClear(&pReader->coder);
tdbFree(pReader->pBuf); tdbFree(pReader->pBuf);
pReader->pBuf = NULL;
} }
int metaGetTableEntryByVersion(SMetaReader *pReader, int64_t version, tb_uid_t uid) { int metaGetTableEntryByVersion(SMetaReader *pReader, int64_t version, tb_uid_t uid) {
@ -53,8 +54,8 @@ int metaGetTableEntryByVersion(SMetaReader *pReader, int64_t version, tb_uid_t u
STbDbKey tbDbKey = {.version = version, .uid = uid}; STbDbKey tbDbKey = {.version = version, .uid = uid};
// query table.db // query table.db
if (tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pReader->pBuf, &pReader->szBuf) < 0) { if ((code = tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pReader->pBuf, &pReader->szBuf)) < 0) {
return terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST; return terrno = (TSDB_CODE_NOT_FOUND == code ? TSDB_CODE_PAR_TABLE_NOT_EXIST : code);
} }
// decode the entry // decode the entry
@ -97,8 +98,9 @@ int metaReaderGetTableEntryByUidCache(SMetaReader *pReader, tb_uid_t uid) {
SMeta *pMeta = pReader->pMeta; SMeta *pMeta = pReader->pMeta;
SMetaInfo info; SMetaInfo info;
if (metaGetInfo(pMeta, uid, &info, pReader) == TSDB_CODE_NOT_FOUND) { int32_t code = metaGetInfo(pMeta, uid, &info, pReader);
return terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST; if (TSDB_CODE_SUCCESS != code) {
return terrno = (TSDB_CODE_NOT_FOUND == code ? TSDB_CODE_PAR_TABLE_NOT_EXIST : code);
} }
return metaGetTableEntryByVersion(pReader, info.version, uid); return metaGetTableEntryByVersion(pReader, info.version, uid);
@ -614,6 +616,22 @@ STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, int lock) {
return pTSchema; return pTSchema;
} }
int32_t metaGetTbTSchemaNotNull(SMeta *pMeta, tb_uid_t uid, int32_t sver, int lock, STSchema** ppTSchema) {
*ppTSchema = metaGetTbTSchema(pMeta, uid, sver, lock);
if(*ppTSchema == NULL) {
return terrno;
}
return TSDB_CODE_SUCCESS;
}
int32_t metaGetTbTSchemaMaybeNull(SMeta *pMeta, tb_uid_t uid, int32_t sver, int lock, STSchema** ppTSchema) {
*ppTSchema = metaGetTbTSchema(pMeta, uid, sver, lock);
if(*ppTSchema == NULL && terrno == TSDB_CODE_OUT_OF_MEMORY) {
return terrno;
}
return TSDB_CODE_SUCCESS;
}
int32_t metaGetTbTSchemaEx(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sver, STSchema **ppTSchema) { int32_t metaGetTbTSchemaEx(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sver, STSchema **ppTSchema) {
int32_t code = 0; int32_t code = 0;
int32_t lino; int32_t lino;
@ -1567,10 +1585,9 @@ int32_t metaGetInfo(SMeta *pMeta, int64_t uid, SMetaInfo *pInfo, SMetaReader *pR
} }
// search TDB // search TDB
if (tdbTbGet(pMeta->pUidIdx, &uid, sizeof(uid), &pData, &nData) < 0) { if ((code = tdbTbGet(pMeta->pUidIdx, &uid, sizeof(uid), &pData, &nData)) < 0) {
// not found // not found
if (!lock) metaULock(pMeta); if (!lock) metaULock(pMeta);
code = TSDB_CODE_NOT_FOUND;
goto _exit; goto _exit;
} }

View File

@ -392,10 +392,9 @@ int32_t tdRSmaProcessCreateImpl(SSma *pSma, SRSmaParam *param, int64_t suid, con
return terrno; return terrno;
} }
STSchema *pTSchema = metaGetTbTSchema(SMA_META(pSma), suid, -1, 1); STSchema *pTSchema;
if (!pTSchema) { code = metaGetTbTSchemaNotNull(SMA_META(pSma), suid, -1, 1, &pTSchema);
TAOS_CHECK_EXIT(TSDB_CODE_TDB_IVD_TB_SCHEMA_VERSION); TAOS_CHECK_EXIT(code);
}
pRSmaInfo->pSma = pSma; pRSmaInfo->pSma = pSma;
pRSmaInfo->pTSchema = pTSchema; pRSmaInfo->pTSchema = pTSchema;
pRSmaInfo->suid = suid; pRSmaInfo->suid = suid;

View File

@ -343,11 +343,8 @@ static int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }
pTsmaStat->pTSma = pTSma; pTsmaStat->pTSma = pTSma;
pTsmaStat->pTSchema = metaGetTbTSchema(SMA_META(pSma), pTSma->dstTbUid, -1, 1); code = metaGetTbTSchemaNotNull(SMA_META(pSma), pTSma->dstTbUid, -1, 1, &pTsmaStat->pTSchema);
if (!pTsmaStat->pTSchema) { TSDB_CHECK_CODE(code, lino, _exit);
code = TSDB_CODE_TSMA_INVALID_PTR;
TSDB_CHECK_CODE(code, lino, _exit);
}
} }
if (pTsmaStat->pTSma->indexUid != indexUid) { if (pTsmaStat->pTSma->indexUid != indexUid) {

View File

@ -26,7 +26,7 @@ void tdRSmaGetDirName(SVnode *pVnode, STfs *pTfs, bool endWithSep, char *outputN
int32_t offset = 0; int32_t offset = 0;
// vnode // vnode
(void)vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pTfs, outputName, TSDB_FILENAME_LEN); vnodeGetPrimaryDir(pVnode->path, pVnode->diskPrimary, pTfs, outputName, TSDB_FILENAME_LEN);
offset = strlen(outputName); offset = strlen(outputName);
// rsma // rsma

View File

@ -752,7 +752,7 @@ int32_t tqBuildStreamTask(void* pTqObj, SStreamTask* pTask, int64_t nextProcessV
} }
streamTaskResetUpstreamStageInfo(pTask); streamTaskResetUpstreamStageInfo(pTask);
(void)streamSetupScheduleTrigger(pTask); streamSetupScheduleTrigger(pTask);
SCheckpointInfo* pChkInfo = &pTask->chkInfo; SCheckpointInfo* pChkInfo = &pTask->chkInfo;
tqSetRestoreVersionInfo(pTask); tqSetRestoreVersionInfo(pTask);
@ -802,6 +802,7 @@ static void doStartFillhistoryStep2(SStreamTask* pTask, SStreamTask* pStreamTask
const char* id = pTask->id.idStr; const char* id = pTask->id.idStr;
int64_t nextProcessedVer = pStreamTask->hTaskInfo.haltVer; int64_t nextProcessedVer = pStreamTask->hTaskInfo.haltVer;
SVersionRange* pStep2Range = &pTask->step2Range; SVersionRange* pStep2Range = &pTask->step2Range;
int32_t vgId = pTask->pMeta->vgId;
// if it's an source task, extract the last version in wal. // if it's an source task, extract the last version in wal.
bool done = streamHistoryTaskSetVerRangeStep2(pTask, nextProcessedVer); bool done = streamHistoryTaskSetVerRangeStep2(pTask, nextProcessedVer);
@ -837,12 +838,15 @@ static void doStartFillhistoryStep2(SStreamTask* pTask, SStreamTask* pStreamTask
tqDebug("s-task:%s wal reader start scan WAL verRange:%" PRId64 "-%" PRId64 ", set sched-status:%d", id, dstVer, tqDebug("s-task:%s wal reader start scan WAL verRange:%" PRId64 "-%" PRId64 ", set sched-status:%d", id, dstVer,
pStep2Range->maxVer, TASK_SCHED_STATUS__INACTIVE); pStep2Range->maxVer, TASK_SCHED_STATUS__INACTIVE);
(void)streamTaskSetSchedStatusInactive(pTask); int8_t status = streamTaskSetSchedStatusInactive(pTask);
// now the fill-history task starts to scan data from wal files. // now the fill-history task starts to scan data from wal files.
code = streamTaskHandleEvent(pTask->status.pSM, TASK_EVENT_SCANHIST_DONE); code = streamTaskHandleEvent(pTask->status.pSM, TASK_EVENT_SCANHIST_DONE);
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
(void)tqScanWalAsync(pTq, false); code = tqScanWalAsync(pTq, false);
if (code) {
tqError("vgId:%d failed to start scan wal file, code:%s", vgId, tstrerror(code));
}
} }
} }
} }
@ -1001,7 +1005,10 @@ int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg) {
// let's continue scan data in the wal files // let's continue scan data in the wal files
if (code == 0 && (pReq->reqType >= 0 || pReq->reqType == STREAM_EXEC_T_RESUME_TASK)) { if (code == 0 && (pReq->reqType >= 0 || pReq->reqType == STREAM_EXEC_T_RESUME_TASK)) {
(void)tqScanWalAsync(pTq, false); // it's ok to failed code = tqScanWalAsync(pTq, false); // it's ok to failed
if (code) {
tqError("vgId:%d failed to start scan wal file, code:%s", pTq->pStreamMeta->vgId, tstrerror(code));
}
} }
return code; return code;
@ -1103,7 +1110,11 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp)
tqError("vgId:%d failed to decode checkpoint-source msg, code:%s", vgId, tstrerror(code)); tqError("vgId:%d failed to decode checkpoint-source msg, code:%s", vgId, tstrerror(code));
SRpcMsg rsp = {0}; SRpcMsg rsp = {0};
(void)streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); int32_t ret = streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS);
if (ret) { // suppress the error in build checkpointsource rsp
tqError("s-task:0x%x failed to build checkpoint-source rsp, code:%s", req.taskId, tstrerror(code));
}
tmsgSendRsp(&rsp); // error occurs tmsgSendRsp(&rsp); // error occurs
return TSDB_CODE_SUCCESS; // always return success to mnode, todo: handle failure of build and send msg to mnode return TSDB_CODE_SUCCESS; // always return success to mnode, todo: handle failure of build and send msg to mnode
} }
@ -1112,7 +1123,11 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp)
if (!vnodeIsRoleLeader(pTq->pVnode)) { if (!vnodeIsRoleLeader(pTq->pVnode)) {
tqDebug("vgId:%d not leader, ignore checkpoint-source msg, s-task:0x%x", vgId, req.taskId); tqDebug("vgId:%d not leader, ignore checkpoint-source msg, s-task:0x%x", vgId, req.taskId);
SRpcMsg rsp = {0}; SRpcMsg rsp = {0};
(void)streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); int32_t ret = streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS);
if (ret) { // suppress the error in build checkpointsource rsp
tqError("s-task:0x%x failed to build checkpoint-source rsp, code:%s", req.taskId, tstrerror(code));
}
tmsgSendRsp(&rsp); // error occurs tmsgSendRsp(&rsp); // error occurs
return TSDB_CODE_SUCCESS; // always return success to mnode, todo: handle failure of build and send msg to mnode return TSDB_CODE_SUCCESS; // always return success to mnode, todo: handle failure of build and send msg to mnode
} }
@ -1122,7 +1137,11 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp)
", transId:%d s-task:0x%x ignore it", ", transId:%d s-task:0x%x ignore it",
vgId, req.checkpointId, req.transId, req.taskId); vgId, req.checkpointId, req.transId, req.taskId);
SRpcMsg rsp = {0}; SRpcMsg rsp = {0};
(void)streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); int32_t ret = streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS);
if (ret) { // suppress the error in build checkpointsource rsp
tqError("s-task:0x%x failed to build checkpoint-source rsp, code:%s", req.taskId, tstrerror(code));
}
tmsgSendRsp(&rsp); // error occurs tmsgSendRsp(&rsp); // error occurs
return TSDB_CODE_SUCCESS; // always return success to mnode, , todo: handle failure of build and send msg to mnode return TSDB_CODE_SUCCESS; // always return success to mnode, , todo: handle failure of build and send msg to mnode
} }
@ -1134,7 +1153,10 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp)
" transId:%d it may have been destroyed", " transId:%d it may have been destroyed",
vgId, req.taskId, req.checkpointId, req.transId); vgId, req.taskId, req.checkpointId, req.transId);
SRpcMsg rsp = {0}; SRpcMsg rsp = {0};
(void)streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); int32_t ret = streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS);
if (ret) { // suppress the error in build checkpointsource rsp
tqError("s-task:%s failed to build checkpoint-source rsp, code:%s", pTask->id.idStr, tstrerror(code));
}
tmsgSendRsp(&rsp); // error occurs tmsgSendRsp(&rsp); // error occurs
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -1147,7 +1169,11 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp)
streamMetaReleaseTask(pMeta, pTask); streamMetaReleaseTask(pMeta, pTask);
SRpcMsg rsp = {0}; SRpcMsg rsp = {0};
(void)streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); int32_t ret = streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS);
if (ret) { // suppress the error in build checkpointsource rsp
tqError("s-task:%s failed to build checkpoint-source rsp, code:%s", pTask->id.idStr, tstrerror(code));
}
tmsgSendRsp(&rsp); // error occurs tmsgSendRsp(&rsp); // error occurs
return TSDB_CODE_SUCCESS; // todo retry handle error return TSDB_CODE_SUCCESS; // todo retry handle error
} }
@ -1165,7 +1191,11 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp)
streamMetaReleaseTask(pMeta, pTask); streamMetaReleaseTask(pMeta, pTask);
SRpcMsg rsp = {0}; SRpcMsg rsp = {0};
(void)streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); int32_t ret = streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS);
if (ret) { // suppress the error in build checkpointsource rsp
tqError("s-task:%s failed to build checkpoint-source rsp, code:%s", pTask->id.idStr, tstrerror(code));
}
tmsgSendRsp(&rsp); // error occurs tmsgSendRsp(&rsp); // error occurs
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -1199,7 +1229,11 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp)
streamMetaReleaseTask(pMeta, pTask); streamMetaReleaseTask(pMeta, pTask);
SRpcMsg rsp = {0}; SRpcMsg rsp = {0};
(void)streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); int32_t ret = streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS);
if (ret) { // suppress the error in build checkpointsource rsp
tqError("s-task:%s failed to build checkpoint-source rsp, code:%s", pTask->id.idStr, tstrerror(code));
}
tmsgSendRsp(&rsp); // error occurs tmsgSendRsp(&rsp); // error occurs
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -1228,7 +1262,10 @@ int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp)
code = streamAddCheckpointSourceRspMsg(&req, &pMsg->info, pTask); code = streamAddCheckpointSourceRspMsg(&req, &pMsg->info, pTask);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
SRpcMsg rsp = {0}; SRpcMsg rsp = {0};
(void)streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS); int32_t ret = streamTaskBuildCheckpointSourceRsp(&req, &pMsg->info, &rsp, TSDB_CODE_SUCCESS);
if (ret) { // suppress the error in build checkpointsource rsp
tqError("s-task:%s failed to build checkpoint-source rsp, code:%s", pTask->id.idStr, tstrerror(code));
}
tmsgSendRsp(&rsp); // error occurs tmsgSendRsp(&rsp); // error occurs
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }

View File

@ -16,64 +16,79 @@
#include "tq.h" #include "tq.h"
int32_t tEncodeSTqHandle(SEncoder* pEncoder, const STqHandle* pHandle) { int32_t tEncodeSTqHandle(SEncoder* pEncoder, const STqHandle* pHandle) {
if (tStartEncode(pEncoder) < 0) return -1; int32_t code = 0;
if (tEncodeCStr(pEncoder, pHandle->subKey) < 0) return -1; int32_t lino;
if (tEncodeI8(pEncoder, pHandle->fetchMeta) < 0) return -1;
if (tEncodeI64(pEncoder, pHandle->consumerId) < 0) return -1; TAOS_CHECK_EXIT(tStartEncode(pEncoder));
if (tEncodeI64(pEncoder, pHandle->snapshotVer) < 0) return -1; TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pHandle->subKey));
if (tEncodeI32(pEncoder, pHandle->epoch) < 0) return -1; TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pHandle->fetchMeta));
if (tEncodeI8(pEncoder, pHandle->execHandle.subType) < 0) return -1; TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pHandle->consumerId));
TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pHandle->snapshotVer));
TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pHandle->epoch));
TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pHandle->execHandle.subType));
if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) { if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
if (tEncodeCStr(pEncoder, pHandle->execHandle.execCol.qmsg) < 0) return -1; TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pHandle->execHandle.execCol.qmsg));
} else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__DB) { } else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__DB) {
int32_t size = taosHashGetSize(pHandle->execHandle.execDb.pFilterOutTbUid); int32_t size = taosHashGetSize(pHandle->execHandle.execDb.pFilterOutTbUid);
if (tEncodeI32(pEncoder, size) < 0) return -1; TAOS_CHECK_EXIT(tEncodeI32(pEncoder, size));
void* pIter = NULL; void* pIter = NULL;
pIter = taosHashIterate(pHandle->execHandle.execDb.pFilterOutTbUid, pIter); pIter = taosHashIterate(pHandle->execHandle.execDb.pFilterOutTbUid, pIter);
while (pIter) { while (pIter) {
int64_t* tbUid = (int64_t*)taosHashGetKey(pIter, NULL); int64_t* tbUid = (int64_t*)taosHashGetKey(pIter, NULL);
if (tEncodeI64(pEncoder, *tbUid) < 0) return -1; TAOS_CHECK_EXIT(tEncodeI64(pEncoder, *tbUid));
pIter = taosHashIterate(pHandle->execHandle.execDb.pFilterOutTbUid, pIter); pIter = taosHashIterate(pHandle->execHandle.execDb.pFilterOutTbUid, pIter);
} }
} else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__TABLE) { } else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__TABLE) {
if (tEncodeI64(pEncoder, pHandle->execHandle.execTb.suid) < 0) return -1; TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pHandle->execHandle.execTb.suid));
if (pHandle->execHandle.execTb.qmsg != NULL) { if (pHandle->execHandle.execTb.qmsg != NULL) {
if (tEncodeCStr(pEncoder, pHandle->execHandle.execTb.qmsg) < 0) return -1; TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pHandle->execHandle.execTb.qmsg));
} }
} }
tEndEncode(pEncoder); tEndEncode(pEncoder);
return pEncoder->pos; _exit:
if (code) {
return code;
} else {
return pEncoder->pos;
}
} }
int32_t tDecodeSTqHandle(SDecoder* pDecoder, STqHandle* pHandle) { int32_t tDecodeSTqHandle(SDecoder* pDecoder, STqHandle* pHandle) {
if (tStartDecode(pDecoder) < 0) return -1; int32_t code = 0;
if (tDecodeCStrTo(pDecoder, pHandle->subKey) < 0) return -1; int32_t lino;
if (tDecodeI8(pDecoder, &pHandle->fetchMeta) < 0) return -1;
if (tDecodeI64(pDecoder, &pHandle->consumerId) < 0) return -1; TAOS_CHECK_EXIT(tStartDecode(pDecoder));
if (tDecodeI64(pDecoder, &pHandle->snapshotVer) < 0) return -1; TAOS_CHECK_EXIT(tDecodeCStrTo(pDecoder, pHandle->subKey));
if (tDecodeI32(pDecoder, &pHandle->epoch) < 0) return -1; TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pHandle->fetchMeta));
if (tDecodeI8(pDecoder, &pHandle->execHandle.subType) < 0) return -1; TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pHandle->consumerId));
TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pHandle->snapshotVer));
TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pHandle->epoch));
TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pHandle->execHandle.subType));
if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) { if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
if (tDecodeCStrAlloc(pDecoder, &pHandle->execHandle.execCol.qmsg) < 0) return -1; TAOS_CHECK_EXIT(tDecodeCStrAlloc(pDecoder, &pHandle->execHandle.execCol.qmsg));
} else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__DB) { } else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__DB) {
pHandle->execHandle.execDb.pFilterOutTbUid = pHandle->execHandle.execDb.pFilterOutTbUid =
taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
if (pHandle->execHandle.execDb.pFilterOutTbUid == NULL) return -1; if (pHandle->execHandle.execDb.pFilterOutTbUid == NULL) {
TAOS_CHECK_EXIT(terrno);
}
int32_t size = 0; int32_t size = 0;
if (tDecodeI32(pDecoder, &size) < 0) return -1; TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &size));
for (int32_t i = 0; i < size; i++) { for (int32_t i = 0; i < size; i++) {
int64_t tbUid = 0; int64_t tbUid = 0;
if (tDecodeI64(pDecoder, &tbUid) < 0) return -1; TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &tbUid));
if (taosHashPut(pHandle->execHandle.execDb.pFilterOutTbUid, &tbUid, sizeof(int64_t), NULL, 0) != 0) return -1; TAOS_CHECK_EXIT(taosHashPut(pHandle->execHandle.execDb.pFilterOutTbUid, &tbUid, sizeof(int64_t), NULL, 0));
} }
} else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__TABLE) { } else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__TABLE) {
if (tDecodeI64(pDecoder, &pHandle->execHandle.execTb.suid) < 0) return -1; TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pHandle->execHandle.execTb.suid));
if (!tDecodeIsEnd(pDecoder)) { if (!tDecodeIsEnd(pDecoder)) {
if (tDecodeCStrAlloc(pDecoder, &pHandle->execHandle.execTb.qmsg) < 0) return -1; TAOS_CHECK_EXIT(tDecodeCStrAlloc(pDecoder, &pHandle->execHandle.execTb.qmsg));
} }
} }
tEndDecode(pDecoder); tEndDecode(pDecoder);
return 0;
_exit:
return code;
} }
int32_t tqMetaDecodeCheckInfo(STqCheckInfo* info, void* pVal, int32_t vLen) { int32_t tqMetaDecodeCheckInfo(STqCheckInfo* info, void* pVal, int32_t vLen) {
@ -374,7 +389,10 @@ static int32_t tqMetaTransformInfo(TDB* pMetaDB, TTB* pOld, TTB* pNew) {
END: END:
tdbFree(pKey); tdbFree(pKey);
tdbFree(pVal); tdbFree(pVal);
(void)tdbTbcClose(pCur); int32_t ret = tdbTbcClose(pCur);
if (code == 0 && ret != 0) {
code = ret;
}
return code; return code;
} }
@ -446,7 +464,12 @@ static int32_t tqMetaRestoreCheckInfo(STQ* pTq) {
END: END:
tdbFree(pKey); tdbFree(pKey);
tdbFree(pVal); tdbFree(pVal);
(void)tdbTbcClose(pCur);
int32_t ret = tdbTbcClose(pCur);
if (code == 0) {
code = ret;
}
tDeleteSTqCheckInfo(&info); tDeleteSTqCheckInfo(&info);
return code; return code;
} }
@ -461,13 +484,13 @@ int32_t tqMetaOpen(STQ* pTq) {
TQ_ERR_GO_TO_END(tqMetaOpenTdb(pTq)); TQ_ERR_GO_TO_END(tqMetaOpenTdb(pTq));
} else { } else {
TQ_ERR_GO_TO_END(tqMetaTransform(pTq)); TQ_ERR_GO_TO_END(tqMetaTransform(pTq));
(void)taosRemoveFile(maindb); TQ_ERR_GO_TO_END(taosRemoveFile(maindb));
} }
TQ_ERR_GO_TO_END(tqBuildFName(&offsetNew, pTq->path, TQ_OFFSET_NAME)); TQ_ERR_GO_TO_END(tqBuildFName(&offsetNew, pTq->path, TQ_OFFSET_NAME));
if(taosCheckExistFile(offsetNew)){ if(taosCheckExistFile(offsetNew)){
TQ_ERR_GO_TO_END(tqOffsetRestoreFromFile(pTq, offsetNew)); TQ_ERR_GO_TO_END(tqOffsetRestoreFromFile(pTq, offsetNew));
(void)taosRemoveFile(offsetNew); TQ_ERR_GO_TO_END(taosRemoveFile(offsetNew));
} }
TQ_ERR_GO_TO_END(tqMetaRestoreCheckInfo(pTq)); TQ_ERR_GO_TO_END(tqMetaRestoreCheckInfo(pTq));
@ -503,7 +526,7 @@ int32_t tqMetaTransform(STQ* pTq) {
if (taosCopyFile(offset, offsetNew) < 0) { if (taosCopyFile(offset, offsetNew) < 0) {
tqError("copy offset file error"); tqError("copy offset file error");
} else { } else {
(void)taosRemoveFile(offset); TQ_ERR_GO_TO_END(taosRemoveFile(offset));
} }
} }
@ -512,22 +535,47 @@ END:
taosMemoryFree(offsetNew); taosMemoryFree(offsetNew);
// return 0 always, so ignore // return 0 always, so ignore
(void)tdbTbClose(pExecStore); int32_t ret = tdbTbClose(pExecStore);
(void)tdbTbClose(pCheckStore); if (ret != 0) {
(void)tdbClose(pMetaDB); tqError("vgId:%d failed to close stream exec store, code:%s", pTq->pStreamMeta->vgId, tstrerror(ret));
}
ret = tdbTbClose(pCheckStore);
if (ret != 0) {
tqError("vgId:%d failed to close stream check store, code:%s", pTq->pStreamMeta->vgId, tstrerror(ret));
}
ret = tdbClose(pMetaDB);
if (ret != 0) {
tqError("vgId:%d failed to close stream meta db store, code:%s", pTq->pStreamMeta->vgId, tstrerror(ret));
}
return code; return code;
} }
void tqMetaClose(STQ* pTq) { void tqMetaClose(STQ* pTq) {
int32_t code = 0;
if (pTq->pExecStore) { if (pTq->pExecStore) {
(void)tdbTbClose(pTq->pExecStore); code = tdbTbClose(pTq->pExecStore);
if (code) {
tqError("vgId:%d failed to close tq exec store, code:%s", pTq->pStreamMeta->vgId, tstrerror(code));
}
} }
if (pTq->pCheckStore) { if (pTq->pCheckStore) {
(void)tdbTbClose(pTq->pCheckStore); code = tdbTbClose(pTq->pCheckStore);
if (code) {
tqError("vgId:%d failed to close tq check store, code:%s", pTq->pStreamMeta->vgId, tstrerror(code));
}
} }
if (pTq->pOffsetStore) { if (pTq->pOffsetStore) {
(void)tdbTbClose(pTq->pOffsetStore); code = tdbTbClose(pTq->pOffsetStore);
if (code) {
tqError("vgId:%d failed to close tq offset store, code:%s", pTq->pStreamMeta->vgId, tstrerror(code));
}
}
code = tdbClose(pTq->pMetaDB);
if (code) {
tqError("vgId:%d failed to close tq meta db store, code:%s", pTq->pStreamMeta->vgId, tstrerror(code));
} }
(void)tdbClose(pTq->pMetaDB);
} }

View File

@ -83,18 +83,27 @@ int32_t streamTaskSnapReaderOpen(STQ* pTq, int64_t sver, int64_t ever, SStreamTa
_err: _err:
tqError("vgId:%d, vnode stream-task snapshot reader open failed since %s", TD_VID(pTq->pVnode), tstrerror(code)); tqError("vgId:%d, vnode stream-task snapshot reader open failed since %s", TD_VID(pTq->pVnode), tstrerror(code));
(void)streamTaskSnapReaderClose(pReader); int32_t ret = streamTaskSnapReaderClose(pReader);
*ppReader = NULL; *ppReader = NULL;
return code; return code;
} }
int32_t streamTaskSnapReaderClose(SStreamTaskReader* pReader) { int32_t streamTaskSnapReaderClose(SStreamTaskReader* pReader) {
if (pReader == NULL) return 0; if (pReader == NULL) {
return 0;
}
int32_t code = 0; int32_t code = 0;
tqInfo("vgId:%d, vnode stream-task snapshot reader closed", TD_VID(pReader->pTq->pVnode)); int32_t vgId = TD_VID(pReader->pTq->pVnode);
taosArrayDestroy(pReader->tdbTbList); taosArrayDestroy(pReader->tdbTbList);
(void)tdbTbcClose(pReader->pCur); code = tdbTbcClose(pReader->pCur);
if (code) {
tqError("vgId:%d failed to close stream meta reader, code:%s", vgId, tstrerror(code));
} else {
tqInfo("vgId:%d, vnode stream-task snapshot reader closed", vgId);
}
taosMemoryFree(pReader); taosMemoryFree(pReader);
return code; return code;
} }
@ -113,6 +122,7 @@ int32_t streamTaskSnapRead(SStreamTaskReader* pReader, uint8_t** ppData) {
tqDebug("vgId:%d, vnode stream-task snapshot start read data", TD_VID(pReader->pTq->pVnode)); tqDebug("vgId:%d, vnode stream-task snapshot start read data", TD_VID(pReader->pTq->pVnode));
STablePair* pPair = taosArrayGet(pReader->tdbTbList, pReader->pos); STablePair* pPair = taosArrayGet(pReader->tdbTbList, pReader->pos);
NextTbl: NextTbl:
except = 0; except = 0;
for (;;) { for (;;) {
@ -127,6 +137,7 @@ NextTbl:
code = terrno; code = terrno;
goto _err; goto _err;
} }
memcpy(pVal, tVal, tLen); memcpy(pVal, tVal, tLen);
vLen = tLen; vLen = tLen;
} }
@ -163,8 +174,8 @@ NextTbl:
taosMemoryFree(pVal); taosMemoryFree(pVal);
tqDebug("vgId:%d, vnode stream-task snapshot read data vLen:%d", TD_VID(pReader->pTq->pVnode), vLen); tqDebug("vgId:%d, vnode stream-task snapshot read data vLen:%d", TD_VID(pReader->pTq->pVnode), vLen);
return code; return code;
_err: _err:
tqError("vgId:%d, vnode stream-task snapshot read data failed since %s", TD_VID(pReader->pTq->pVnode), tqError("vgId:%d, vnode stream-task snapshot read data failed since %s", TD_VID(pReader->pTq->pVnode),
tstrerror(code)); tstrerror(code));

View File

@ -207,7 +207,10 @@ int32_t tqStreamTaskProcessUpdateReq(SStreamMeta* pMeta, SMsgCb* cb, SRpcMsg* pM
updated = streamTaskUpdateEpsetInfo(pTask, req.pNodeList); updated = streamTaskUpdateEpsetInfo(pTask, req.pNodeList);
// send the checkpoint-source-rsp for source task to end the checkpoint trans in mnode // send the checkpoint-source-rsp for source task to end the checkpoint trans in mnode
(void)streamTaskSendCheckpointsourceRsp(pTask); code = streamTaskSendCheckpointsourceRsp(pTask);
if (code) {
tqError("%s failed to send checkpoint-source rsp, code:%s", pTask->id.idStr, tstrerror(code));
}
streamTaskResetStatus(pTask); streamTaskResetStatus(pTask);
streamTaskStopMonitorCheckRsp(&pTask->taskCheckInfo, pTask->id.idStr); streamTaskStopMonitorCheckRsp(&pTask->taskCheckInfo, pTask->id.idStr);
@ -806,25 +809,26 @@ int32_t tqStreamTaskProcessRunReq(SStreamMeta* pMeta, SRpcMsg* pMsg, bool isLead
int32_t type = pReq->reqType; int32_t type = pReq->reqType;
int32_t vgId = pMeta->vgId; int32_t vgId = pMeta->vgId;
int32_t code = 0;
if (type == STREAM_EXEC_T_START_ONE_TASK) { if (type == STREAM_EXEC_T_START_ONE_TASK) {
(void)streamMetaStartOneTask(pMeta, pReq->streamId, pReq->taskId); code = streamMetaStartOneTask(pMeta, pReq->streamId, pReq->taskId);
return 0; return 0;
} else if (type == STREAM_EXEC_T_START_ALL_TASKS) { } else if (type == STREAM_EXEC_T_START_ALL_TASKS) {
(void)streamMetaStartAllTasks(pMeta); code = streamMetaStartAllTasks(pMeta);
return 0; return 0;
} else if (type == STREAM_EXEC_T_RESTART_ALL_TASKS) { } else if (type == STREAM_EXEC_T_RESTART_ALL_TASKS) {
(void)restartStreamTasks(pMeta, isLeader); code = restartStreamTasks(pMeta, isLeader);
return 0; return 0;
} else if (type == STREAM_EXEC_T_STOP_ALL_TASKS) { } else if (type == STREAM_EXEC_T_STOP_ALL_TASKS) {
(void)streamMetaStopAllTasks(pMeta); code = streamMetaStopAllTasks(pMeta);
return 0; return 0;
} else if (type == STREAM_EXEC_T_ADD_FAILED_TASK) { } else if (type == STREAM_EXEC_T_ADD_FAILED_TASK) {
int32_t code = streamMetaAddFailedTask(pMeta, pReq->streamId, pReq->taskId); code = streamMetaAddFailedTask(pMeta, pReq->streamId, pReq->taskId);
return code; return code;
} else if (type == STREAM_EXEC_T_RESUME_TASK) { // task resume to run after idle for a while } else if (type == STREAM_EXEC_T_RESUME_TASK) { // task resume to run after idle for a while
SStreamTask* pTask = NULL; SStreamTask* pTask = NULL;
int32_t code = streamMetaAcquireTask(pMeta, pReq->streamId, pReq->taskId, &pTask); code = streamMetaAcquireTask(pMeta, pReq->streamId, pReq->taskId, &pTask);
if (pTask != NULL && (code == 0)) { if (pTask != NULL && (code == 0)) {
char* pStatus = NULL; char* pStatus = NULL;
@ -846,7 +850,7 @@ int32_t tqStreamTaskProcessRunReq(SStreamMeta* pMeta, SRpcMsg* pMsg, bool isLead
} }
SStreamTask* pTask = NULL; SStreamTask* pTask = NULL;
int32_t code = streamMetaAcquireTask(pMeta, pReq->streamId, pReq->taskId, &pTask); code = streamMetaAcquireTask(pMeta, pReq->streamId, pReq->taskId, &pTask);
if ((pTask != NULL) && (code == 0)) { // even in halt status, the data in inputQ must be processed if ((pTask != NULL) && (code == 0)) { // even in halt status, the data in inputQ must be processed
char* p = NULL; char* p = NULL;
if (streamTaskReadyToRun(pTask, &p)) { if (streamTaskReadyToRun(pTask, &p)) {
@ -864,7 +868,7 @@ int32_t tqStreamTaskProcessRunReq(SStreamMeta* pMeta, SRpcMsg* pMsg, bool isLead
} else { // NOTE: pTask->status.schedStatus is not updated since it is not be handled by the run exec. } else { // NOTE: pTask->status.schedStatus is not updated since it is not be handled by the run exec.
// todo add one function to handle this // todo add one function to handle this
tqError("vgId:%d failed to found s-task, taskId:0x%x may have been dropped", vgId, pReq->taskId); tqError("vgId:%d failed to found s-task, taskId:0x%x may have been dropped", vgId, pReq->taskId);
return -1; return code;
} }
} }
@ -1229,7 +1233,8 @@ int32_t tqStreamTaskProcessConsenChkptIdReq(SStreamMeta* pMeta, SRpcMsg* pMsg) {
tqError( tqError(
"vgId:%d process set consensus checkpointId req, failed to acquire task:0x%x, it may have been dropped already", "vgId:%d process set consensus checkpointId req, failed to acquire task:0x%x, it may have been dropped already",
pMeta->vgId, req.taskId); pMeta->vgId, req.taskId);
(void)streamMetaAddFailedTask(pMeta, req.streamId, req.taskId); // ignore this code to avoid error code over write
int32_t ret = streamMetaAddFailedTask(pMeta, req.streamId, req.taskId);
return code; return code;
} }

View File

@ -117,7 +117,7 @@ typedef struct {
static void tsdbGetRocksPath(STsdb *pTsdb, char *path) { static void tsdbGetRocksPath(STsdb *pTsdb, char *path) {
SVnode *pVnode = pTsdb->pVnode; SVnode *pVnode = pTsdb->pVnode;
(void)vnodeGetPrimaryDir(pTsdb->path, pVnode->diskPrimary, pVnode->pTfs, path, TSDB_FILENAME_LEN); vnodeGetPrimaryDir(pTsdb->path, pVnode->diskPrimary, pVnode->pTfs, path, TSDB_FILENAME_LEN);
int32_t offset = strlen(path); int32_t offset = strlen(path);
snprintf(path + offset, TSDB_FILENAME_LEN - offset - 1, "%scache.rdb", TD_DIRSEP); snprintf(path + offset, TSDB_FILENAME_LEN - offset - 1, "%scache.rdb", TD_DIRSEP);
@ -582,6 +582,8 @@ _exit:
taosMemoryFree(pCol->rowKey.pks[j].pData); taosMemoryFree(pCol->rowKey.pks[j].pData);
} }
} }
(void)memset(pCol, 0, sizeof(SLastCol));
} }
TAOS_RETURN(code); TAOS_RETURN(code);
@ -643,7 +645,9 @@ static int32_t tsdbCacheNewTableColumn(STsdb *pTsdb, int64_t uid, int16_t cid, i
LRUStatus status = taosLRUCacheInsert(pCache, pLastKey, ROCKS_KEY_LEN, pLastCol, charge, tsdbCacheDeleter, NULL, LRUStatus status = taosLRUCacheInsert(pCache, pLastKey, ROCKS_KEY_LEN, pLastCol, charge, tsdbCacheDeleter, NULL,
TAOS_LRU_PRIORITY_LOW, &pTsdb->flushState); TAOS_LRU_PRIORITY_LOW, &pTsdb->flushState);
if (status != TAOS_LRU_STATUS_OK) { if (status != TAOS_LRU_STATUS_OK) {
// code = -1; tsdbError("vgId:%d, %s failed at line %d status %d.", TD_VID(pTsdb->pVnode), __func__, __LINE__, status);
tsdbCacheFreeSLastColItem(pLastCol);
code = TSDB_CODE_FAILED;
} }
_exit: _exit:
@ -1015,29 +1019,6 @@ static int32_t tsdbCacheUpdateValue(SValue *pOld, SValue *pNew) {
TAOS_RETURN(TSDB_CODE_SUCCESS); TAOS_RETURN(TSDB_CODE_SUCCESS);
} }
#ifdef BUILD_NO_CALL
static void tsdbCacheUpdateLastCol(SLastCol *pLastCol, SRowKey *pRowKey, SColVal *pColVal) {
// update rowkey
pLastCol->rowKey.ts = pRowKey->ts;
pLastCol->rowKey.numOfPKs = pRowKey->numOfPKs;
for (int8_t i = 0; i < pRowKey->numOfPKs; i++) {
SValue *pPKValue = &pLastCol->rowKey.pks[i];
SValue *pNewPKValue = &pRowKey->pks[i];
(void)tsdbCacheUpdateValue(pPKValue, pNewPKValue);
}
// update colval
pLastCol->colVal.cid = pColVal->cid;
pLastCol->colVal.flag = pColVal->flag;
(void)tsdbCacheUpdateValue(&pLastCol->colVal.value, &pColVal->value);
if (!pLastCol->dirty) {
pLastCol->dirty = 1;
}
}
#endif
static void tsdbCacheUpdateLastColToNone(SLastCol *pLastCol, ELastCacheStatus cacheStatus) { static void tsdbCacheUpdateLastColToNone(SLastCol *pLastCol, ELastCacheStatus cacheStatus) {
// update rowkey // update rowkey
pLastCol->rowKey.ts = TSKEY_MIN; pLastCol->rowKey.ts = TSKEY_MIN;
@ -1104,8 +1085,9 @@ static int32_t tsdbCachePutToLRU(STsdb *pTsdb, SLastKey *pLastKey, SLastCol *pLa
LRUStatus status = taosLRUCacheInsert(pTsdb->lruCache, pLastKey, ROCKS_KEY_LEN, pLRULastCol, charge, tsdbCacheDeleter, LRUStatus status = taosLRUCacheInsert(pTsdb->lruCache, pLastKey, ROCKS_KEY_LEN, pLRULastCol, charge, tsdbCacheDeleter,
NULL, TAOS_LRU_PRIORITY_LOW, &pTsdb->flushState); NULL, TAOS_LRU_PRIORITY_LOW, &pTsdb->flushState);
if (TAOS_LRU_STATUS_OK != status && TAOS_LRU_STATUS_OK_OVERWRITTEN != status) { if (TAOS_LRU_STATUS_OK != status && TAOS_LRU_STATUS_OK_OVERWRITTEN != status) {
tsdbError("tsdb/cache/putlru: vgId:%d, failed to insert status %d.", TD_VID(pTsdb->pVnode), status); tsdbError("vgId:%d, %s failed at line %d status %d.", TD_VID(pTsdb->pVnode), __func__, __LINE__, status);
code = TSDB_CODE_INVALID_DATA_FMT; tsdbCacheFreeSLastColItem(pLRULastCol);
code = TSDB_CODE_FAILED;
} }
_exit: _exit:
@ -1217,23 +1199,23 @@ static int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SArray
tsdbError("tsdb/cache: vgId:%d, deserialize failed since %s.", TD_VID(pTsdb->pVnode), tstrerror(code)); tsdbError("tsdb/cache: vgId:%d, deserialize failed since %s.", TD_VID(pTsdb->pVnode), tstrerror(code));
} }
*/ */
SLastCol *PToFree = pLastCol; SLastCol *pToFree = pLastCol;
if (pLastCol && pLastCol->cacheStatus == TSDB_LAST_CACHE_NO_CACHE) { if (pLastCol && pLastCol->cacheStatus == TSDB_LAST_CACHE_NO_CACHE) {
if ((code = tsdbCachePutToLRU(pTsdb, &idxKey->key, pLastCol)) != TSDB_CODE_SUCCESS) { if ((code = tsdbCachePutToLRU(pTsdb, &idxKey->key, pLastCol)) != TSDB_CODE_SUCCESS) {
tsdbError("tsdb/cache: vgId:%d, put lru failed at line %d since %s.", TD_VID(pTsdb->pVnode), lino, tsdbError("tsdb/cache: vgId:%d, put lru failed at line %d since %s.", TD_VID(pTsdb->pVnode), lino,
tstrerror(code)); tstrerror(code));
taosMemoryFreeClear(PToFree); taosMemoryFreeClear(pToFree);
break; break;
} }
// cache invalid => skip update // cache invalid => skip update
taosMemoryFreeClear(PToFree); taosMemoryFreeClear(pToFree);
continue; continue;
} }
if (IS_LAST_KEY(idxKey->key) && !COL_VAL_IS_VALUE(pColVal)) { if (IS_LAST_KEY(idxKey->key) && !COL_VAL_IS_VALUE(pColVal)) {
taosMemoryFreeClear(PToFree); taosMemoryFreeClear(pToFree);
continue; continue;
} }
@ -1247,18 +1229,18 @@ static int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SArray
if ((code = tsdbCachePutToRocksdb(pTsdb, &idxKey->key, &lastColTmp)) != TSDB_CODE_SUCCESS) { if ((code = tsdbCachePutToRocksdb(pTsdb, &idxKey->key, &lastColTmp)) != TSDB_CODE_SUCCESS) {
tsdbError("tsdb/cache: vgId:%d, put rocks failed at line %d since %s.", TD_VID(pTsdb->pVnode), lino, tsdbError("tsdb/cache: vgId:%d, put rocks failed at line %d since %s.", TD_VID(pTsdb->pVnode), lino,
tstrerror(code)); tstrerror(code));
taosMemoryFreeClear(PToFree); taosMemoryFreeClear(pToFree);
break; break;
} }
if ((code = tsdbCachePutToLRU(pTsdb, &idxKey->key, &lastColTmp)) != TSDB_CODE_SUCCESS) { if ((code = tsdbCachePutToLRU(pTsdb, &idxKey->key, &lastColTmp)) != TSDB_CODE_SUCCESS) {
tsdbError("tsdb/cache: vgId:%d, put lru failed at line %d since %s.", TD_VID(pTsdb->pVnode), lino, tsdbError("tsdb/cache: vgId:%d, put lru failed at line %d since %s.", TD_VID(pTsdb->pVnode), lino,
tstrerror(code)); tstrerror(code));
taosMemoryFreeClear(PToFree); taosMemoryFreeClear(pToFree);
break; break;
} }
} }
taosMemoryFreeClear(PToFree); taosMemoryFreeClear(pToFree);
} }
rocksMayWrite(pTsdb, true, false); rocksMayWrite(pTsdb, true, false);
@ -1586,14 +1568,17 @@ static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArr
pLastCol = pTmpLastCol; pLastCol = pTmpLastCol;
code = tsdbCacheReallocSLastCol(pLastCol, &charge); code = tsdbCacheReallocSLastCol(pLastCol, &charge);
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
taosMemoryFree(pTmpLastCol); taosMemoryFree(pLastCol);
TAOS_CHECK_EXIT(code); TAOS_CHECK_EXIT(code);
} }
LRUStatus status = taosLRUCacheInsert(pCache, &idxKey->key, ROCKS_KEY_LEN, pLastCol, charge, tsdbCacheDeleter, NULL, LRUStatus status = taosLRUCacheInsert(pCache, &idxKey->key, ROCKS_KEY_LEN, pLastCol, charge, tsdbCacheDeleter, NULL,
TAOS_LRU_PRIORITY_LOW, &pTsdb->flushState); TAOS_LRU_PRIORITY_LOW, &pTsdb->flushState);
if (status != TAOS_LRU_STATUS_OK) { if (TAOS_LRU_STATUS_OK != status && TAOS_LRU_STATUS_OK_OVERWRITTEN != status) {
// code = -1; tsdbError("vgId:%d, %s failed at line %d status %d.", TD_VID(pTsdb->pVnode), __func__, __LINE__, status);
tsdbCacheFreeSLastColItem(pLastCol);
taosMemoryFree(pLastCol);
TAOS_CHECK_EXIT(TSDB_CODE_FAILED);
} }
// store result back to rocks cache // store result back to rocks cache
@ -1672,14 +1657,13 @@ static int32_t tsdbCacheLoadFromRocks(STsdb *pTsdb, tb_uid_t uid, SArray *pLastA
} }
(void)tsdbCacheDeserialize(values_list[i], values_list_sizes[i], &pLastCol); (void)tsdbCacheDeserialize(values_list[i], values_list_sizes[i], &pLastCol);
SLastCol *PToFree = pLastCol; SLastCol *pToFree = pLastCol;
SIdxKey *idxKey = &((SIdxKey *)TARRAY_DATA(remainCols))[j]; SIdxKey *idxKey = &((SIdxKey *)TARRAY_DATA(remainCols))[j];
if (pLastCol && pLastCol->cacheStatus != TSDB_LAST_CACHE_NO_CACHE) { if (pLastCol && pLastCol->cacheStatus != TSDB_LAST_CACHE_NO_CACHE) {
SLastCol *pTmpLastCol = taosMemoryCalloc(1, sizeof(SLastCol)); SLastCol *pTmpLastCol = taosMemoryCalloc(1, sizeof(SLastCol));
if (!pTmpLastCol) { if (!pTmpLastCol) {
taosMemoryFreeClear(PToFree); taosMemoryFreeClear(pToFree);
code = terrno; TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY);
goto _exit;
} }
size_t charge = 0; size_t charge = 0;
@ -1687,18 +1671,28 @@ static int32_t tsdbCacheLoadFromRocks(STsdb *pTsdb, tb_uid_t uid, SArray *pLastA
pLastCol = pTmpLastCol; pLastCol = pTmpLastCol;
code = tsdbCacheReallocSLastCol(pLastCol, &charge); code = tsdbCacheReallocSLastCol(pLastCol, &charge);
if (TSDB_CODE_SUCCESS != code) { if (TSDB_CODE_SUCCESS != code) {
taosMemoryFree(pTmpLastCol); taosMemoryFreeClear(pLastCol);
taosMemoryFreeClear(PToFree); taosMemoryFreeClear(pToFree);
goto _exit; TAOS_CHECK_EXIT(code);
} }
SLastCol lastCol = *pLastCol; SLastCol lastCol = *pLastCol;
TAOS_CHECK_EXIT(tsdbCacheReallocSLastCol(&lastCol, NULL)); code = tsdbCacheReallocSLastCol(&lastCol, NULL);
if (TSDB_CODE_SUCCESS != code) {
tsdbCacheFreeSLastColItem(pLastCol);
taosMemoryFreeClear(pLastCol);
taosMemoryFreeClear(pToFree);
TAOS_CHECK_EXIT(code);
}
LRUStatus status = taosLRUCacheInsert(pCache, &idxKey->key, ROCKS_KEY_LEN, pLastCol, charge, tsdbCacheDeleter, LRUStatus status = taosLRUCacheInsert(pCache, &idxKey->key, ROCKS_KEY_LEN, pLastCol, charge, tsdbCacheDeleter,
NULL, TAOS_LRU_PRIORITY_LOW, &pTsdb->flushState); NULL, TAOS_LRU_PRIORITY_LOW, &pTsdb->flushState);
if (status != TAOS_LRU_STATUS_OK) { if (TAOS_LRU_STATUS_OK != status && TAOS_LRU_STATUS_OK_OVERWRITTEN != status) {
code = -1; tsdbError("vgId:%d, %s failed at line %d status %d.", TD_VID(pTsdb->pVnode), __func__, __LINE__, status);
tsdbCacheFreeSLastColItem(pLastCol);
taosMemoryFreeClear(pLastCol);
taosMemoryFreeClear(pToFree);
TAOS_CHECK_EXIT(TSDB_CODE_FAILED);
} }
taosArraySet(pLastArray, idxKey->idx, &lastCol); taosArraySet(pLastArray, idxKey->idx, &lastCol);
@ -1708,7 +1702,7 @@ static int32_t tsdbCacheLoadFromRocks(STsdb *pTsdb, tb_uid_t uid, SArray *pLastA
++j; ++j;
} }
taosMemoryFreeClear(PToFree); taosMemoryFreeClear(pToFree);
} }
if (TARRAY_SIZE(remainCols) > 0) { if (TARRAY_SIZE(remainCols) > 0) {
@ -2158,6 +2152,11 @@ static int32_t loadTombFromBlk(const TTombBlkArray *pTombBlkArray, SCacheRowsRea
uint64_t uid = uidList[j]; uint64_t uid = uidList[j];
STableLoadInfo *pInfo = getTableLoadInfo(pReader, uid); STableLoadInfo *pInfo = getTableLoadInfo(pReader, uid);
if (!pInfo) {
tTombBlockDestroy(&block);
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
}
if (pInfo->pTombData == NULL) { if (pInfo->pTombData == NULL) {
pInfo->pTombData = taosArrayInit(4, sizeof(SDelData)); pInfo->pTombData = taosArrayInit(4, sizeof(SDelData));
} }
@ -2200,8 +2199,18 @@ static int32_t loadTombFromBlk(const TTombBlkArray *pTombBlkArray, SCacheRowsRea
if (newTable) { if (newTable) {
pInfo = getTableLoadInfo(pReader, uid); pInfo = getTableLoadInfo(pReader, uid);
if (!pInfo) {
code = TSDB_CODE_OUT_OF_MEMORY;
finished = true;
break;
}
if (pInfo->pTombData == NULL) { if (pInfo->pTombData == NULL) {
pInfo->pTombData = taosArrayInit(4, sizeof(SDelData)); pInfo->pTombData = taosArrayInit(4, sizeof(SDelData));
if (!pInfo->pTombData) {
code = TSDB_CODE_OUT_OF_MEMORY;
finished = true;
break;
}
} }
} }
@ -2216,7 +2225,7 @@ static int32_t loadTombFromBlk(const TTombBlkArray *pTombBlkArray, SCacheRowsRea
} }
} }
(void)tTombBlockDestroy(&block); tTombBlockDestroy(&block);
if (finished) { if (finished) {
TAOS_RETURN(code); TAOS_RETURN(code);
@ -2523,7 +2532,7 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlie
if (!state->pBrinBlock) { if (!state->pBrinBlock) {
state->pBrinBlock = &state->brinBlock; state->pBrinBlock = &state->brinBlock;
} else { } else {
(void)tBrinBlockClear(&state->brinBlock); tBrinBlockClear(&state->brinBlock);
} }
TAOS_CHECK_GOTO(tsdbDataFileReadBrinBlock(state->pr->pFileReader, pBrinBlk, &state->brinBlock), &lino, _err); TAOS_CHECK_GOTO(tsdbDataFileReadBrinBlock(state->pr->pFileReader, pBrinBlk, &state->brinBlock), &lino, _err);
@ -2535,7 +2544,7 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlie
if (SFSNEXTROW_BRINBLOCK == state->state) { if (SFSNEXTROW_BRINBLOCK == state->state) {
_next_brinrecord: _next_brinrecord:
if (state->iBrinRecord < 0) { // empty brin block, goto _next_brinindex if (state->iBrinRecord < 0) { // empty brin block, goto _next_brinindex
(void)tBrinBlockClear(&state->brinBlock); tBrinBlockClear(&state->brinBlock);
goto _next_brinindex; goto _next_brinindex;
} }
@ -2676,12 +2685,14 @@ static int32_t getNextRowFromMem(void *iter, TSDBROW **ppRow, bool *pIgnoreEarli
switch (state->state) { switch (state->state) {
case SMEMNEXTROW_ENTER: { case SMEMNEXTROW_ENTER: {
if (state->pMem != NULL) { if (state->pMem != NULL) {
/*
if (state->pMem->maxKey <= state->lastTs) { if (state->pMem->maxKey <= state->lastTs) {
*ppRow = NULL; *ppRow = NULL;
*pIgnoreEarlierTs = true; *pIgnoreEarlierTs = true;
TAOS_RETURN(code); TAOS_RETURN(code);
} }
*/
tsdbTbDataIterOpen(state->pMem, NULL, 1, &state->iter); tsdbTbDataIterOpen(state->pMem, NULL, 1, &state->iter);
TSDBROW *pMemRow = tsdbTbDataIterGet(&state->iter); TSDBROW *pMemRow = tsdbTbDataIterGet(&state->iter);
@ -2794,7 +2805,7 @@ int32_t clearNextRowFromFS(void *iter) {
} }
if (state->pBrinBlock) { if (state->pBrinBlock) {
(void)tBrinBlockDestroy(state->pBrinBlock); tBrinBlockDestroy(state->pBrinBlock);
state->pBrinBlock = NULL; state->pBrinBlock = NULL;
} }
@ -2827,7 +2838,7 @@ static void clearLastFileSet(SFSNextRowIter *state) {
} }
if (state->pr->pFileReader) { if (state->pr->pFileReader) {
(void)tsdbDataFileReaderClose(&state->pr->pFileReader); tsdbDataFileReaderClose(&state->pr->pFileReader);
state->pr->pFileReader = NULL; state->pr->pFileReader = NULL;
state->pr->pCurFileSet = NULL; state->pr->pCurFileSet = NULL;
@ -2912,9 +2923,7 @@ _err:
TAOS_RETURN(code); TAOS_RETURN(code);
} }
static int32_t nextRowIterClose(CacheNextRowIter *pIter) { static void nextRowIterClose(CacheNextRowIter *pIter) {
int32_t code = 0;
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
if (pIter->input[i].nextRowClearFn) { if (pIter->input[i].nextRowClearFn) {
(void)pIter->input[i].nextRowClearFn(pIter->input[i].iter); (void)pIter->input[i].nextRowClearFn(pIter->input[i].iter);
@ -2928,9 +2937,6 @@ static int32_t nextRowIterClose(CacheNextRowIter *pIter) {
if (pIter->pMemDelData) { if (pIter->pMemDelData) {
taosArrayDestroy(pIter->pMemDelData); taosArrayDestroy(pIter->pMemDelData);
} }
_err:
TAOS_RETURN(code);
} }
// iterate next row non deleted backward ts, version (from high to low) // iterate next row non deleted backward ts, version (from high to low)
@ -2998,6 +3004,8 @@ static int32_t nextRowIterGet(CacheNextRowIter *pIter, TSDBROW **ppRow, bool *pI
uint64_t uid = pIter->idx.uid; uint64_t uid = pIter->idx.uid;
STableLoadInfo *pInfo = getTableLoadInfo(pIter->pr, uid); STableLoadInfo *pInfo = getTableLoadInfo(pIter->pr, uid);
TSDB_CHECK_NULL(pInfo, code, lino, _err, TSDB_CODE_OUT_OF_MEMORY);
if (pInfo->pTombData == NULL) { if (pInfo->pTombData == NULL) {
pInfo->pTombData = taosArrayInit(4, sizeof(SDelData)); pInfo->pTombData = taosArrayInit(4, sizeof(SDelData));
TSDB_CHECK_NULL(pInfo->pTombData, code, lino, _err, TSDB_CODE_OUT_OF_MEMORY); TSDB_CHECK_NULL(pInfo->pTombData, code, lino, _err, TSDB_CODE_OUT_OF_MEMORY);
@ -3204,6 +3212,10 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
break; break;
} }
// high version's column value // high version's column value
if (slotIds[iCol] > pTSchema->numOfCols - 1) {
continue;
}
SLastCol *lastColVal = (SLastCol *)taosArrayGet(pColArray, iCol); SLastCol *lastColVal = (SLastCol *)taosArrayGet(pColArray, iCol);
if (lastColVal->colVal.cid != pTSchema->columns[slotIds[iCol]].colId) { if (lastColVal->colVal.cid != pTSchema->columns[slotIds[iCol]].colId) {
continue; continue;
@ -3239,7 +3251,7 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
} }
*ppLastArray = pColArray; *ppLastArray = pColArray;
(void)nextRowIterClose(&iter); nextRowIterClose(&iter);
taosArrayDestroy(aColArray); taosArrayDestroy(aColArray);
TAOS_RETURN(code); TAOS_RETURN(code);
@ -3360,7 +3372,7 @@ static int32_t mergeLastRowCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray,
} }
*ppLastArray = pColArray; *ppLastArray = pColArray;
(void)nextRowIterClose(&iter); nextRowIterClose(&iter);
taosArrayDestroy(aColArray); taosArrayDestroy(aColArray);
TAOS_RETURN(code); TAOS_RETURN(code);

View File

@ -237,17 +237,25 @@ static int32_t saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* p
static int32_t setTableSchema(SCacheRowsReader* p, uint64_t suid, const char* idstr) { static int32_t setTableSchema(SCacheRowsReader* p, uint64_t suid, const char* idstr) {
int32_t numOfTables = p->numOfTables; int32_t numOfTables = p->numOfTables;
int32_t code = TSDB_CODE_SUCCESS;
if (suid != 0) { if (suid != 0) {
p->pSchema = metaGetTbTSchema(p->pVnode->pMeta, suid, -1, 1); code = metaGetTbTSchemaNotNull(p->pVnode->pMeta, suid, -1, 1, &p->pSchema);
if (p->pSchema == NULL) { if (TSDB_CODE_SUCCESS != code) {
tsdbWarn("stable:%" PRIu64 " has been dropped, failed to retrieve cached rows, %s", suid, idstr); tsdbWarn("stable:%" PRIu64 " has been dropped, failed to retrieve cached rows, %s", suid, idstr);
return TSDB_CODE_PAR_TABLE_NOT_EXIST; if(code != TSDB_CODE_OUT_OF_MEMORY) {
return TSDB_CODE_PAR_TABLE_NOT_EXIST;
} else {
return code;
}
} }
} else { } else {
for (int32_t i = 0; i < numOfTables; ++i) { for (int32_t i = 0; i < numOfTables; ++i) {
uint64_t uid = p->pTableList[i].uid; uint64_t uid = p->pTableList[i].uid;
p->pSchema = metaGetTbTSchema(p->pVnode->pMeta, uid, -1, 1); code = metaGetTbTSchemaMaybeNull(p->pVnode->pMeta, uid, -1, 1, &p->pSchema);
if(code != TSDB_CODE_SUCCESS) {
return code;
}
if (p->pSchema != NULL) { if (p->pSchema != NULL) {
break; break;
} }
@ -379,7 +387,7 @@ void tsdbCacherowsReaderClose(void* pReader) {
} }
if (p->pFileReader) { if (p->pFileReader) {
(void) tsdbDataFileReaderClose(&p->pFileReader); tsdbDataFileReaderClose(&p->pFileReader);
p->pFileReader = NULL; p->pFileReader = NULL;
} }
@ -465,7 +473,7 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32
} }
(void)taosThreadMutexLock(&pr->readerMutex); (void)taosThreadMutexLock(&pr->readerMutex);
code = tsdbTakeReadSnap2((STsdbReader*)pr, tsdbCacheQueryReseek, &pr->pReadSnap); code = tsdbTakeReadSnap2((STsdbReader*)pr, tsdbCacheQueryReseek, &pr->pReadSnap, pr->idstr);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
goto _end; goto _end;
} }

View File

@ -251,8 +251,8 @@ _exit:
} }
static int32_t tsdbCommitCloseIter(SCommitter2 *committer) { static int32_t tsdbCommitCloseIter(SCommitter2 *committer) {
TAOS_UNUSED(tsdbIterMergerClose(&committer->tombIterMerger)); tsdbIterMergerClose(&committer->tombIterMerger);
TAOS_UNUSED(tsdbIterMergerClose(&committer->dataIterMerger)); tsdbIterMergerClose(&committer->dataIterMerger);
TARRAY2_CLEAR(committer->tombIterArray, tsdbIterClose); TARRAY2_CLEAR(committer->tombIterArray, tsdbIterClose);
TARRAY2_CLEAR(committer->dataIterArray, tsdbIterClose); TARRAY2_CLEAR(committer->dataIterArray, tsdbIterClose);
return 0; return 0;
@ -418,7 +418,7 @@ static int32_t tsdbCommitInfoDestroy(STsdb *pTsdb) {
taosMemoryFree(info); taosMemoryFree(info);
} }
TAOS_UNUSED(vHashDestroy(&pTsdb->commitInfo->ht)); vHashDestroy(&pTsdb->commitInfo->ht);
taosArrayDestroy(pTsdb->commitInfo->arr); taosArrayDestroy(pTsdb->commitInfo->arr);
pTsdb->commitInfo->arr = NULL; pTsdb->commitInfo->arr = NULL;
taosMemoryFreeClear(pTsdb->commitInfo); taosMemoryFreeClear(pTsdb->commitInfo);
@ -572,7 +572,7 @@ static int32_t tsdbCommitInfoBuild(STsdb *tsdb) {
// begin tasks on file set // begin tasks on file set
for (int i = 0; i < taosArrayGetSize(tsdb->commitInfo->arr); i++) { for (int i = 0; i < taosArrayGetSize(tsdb->commitInfo->arr); i++) {
SFileSetCommitInfo *info = *(SFileSetCommitInfo **)taosArrayGet(tsdb->commitInfo->arr, i); SFileSetCommitInfo *info = *(SFileSetCommitInfo **)taosArrayGet(tsdb->commitInfo->arr, i);
TAOS_UNUSED(tsdbBeginTaskOnFileSet(tsdb, info->fid, &fset)); tsdbBeginTaskOnFileSet(tsdb, info->fid, &fset);
if (fset) { if (fset) {
code = tsdbTFileSetInitCopy(tsdb, fset, &info->fset); code = tsdbTFileSetInitCopy(tsdb, fset, &info->fset);
if (code) { if (code) {
@ -669,7 +669,7 @@ int32_t tsdbCommitBegin(STsdb *tsdb, SCommitInfo *info) {
(void)taosThreadMutexLock(&tsdb->mutex); (void)taosThreadMutexLock(&tsdb->mutex);
tsdb->imem = NULL; tsdb->imem = NULL;
(void)taosThreadMutexUnlock(&tsdb->mutex); (void)taosThreadMutexUnlock(&tsdb->mutex);
TAOS_UNUSED(tsdbUnrefMemTable(imem, NULL, true)); tsdbUnrefMemTable(imem, NULL, true);
} else { } else {
SCommitter2 committer = {0}; SCommitter2 committer = {0};
@ -710,14 +710,14 @@ int32_t tsdbCommitCommit(STsdb *tsdb) {
for (int32_t i = 0; i < taosArrayGetSize(tsdb->commitInfo->arr); i++) { for (int32_t i = 0; i < taosArrayGetSize(tsdb->commitInfo->arr); i++) {
SFileSetCommitInfo *info = *(SFileSetCommitInfo **)taosArrayGet(tsdb->commitInfo->arr, i); SFileSetCommitInfo *info = *(SFileSetCommitInfo **)taosArrayGet(tsdb->commitInfo->arr, i);
if (info->fset) { if (info->fset) {
TAOS_UNUSED(tsdbFinishTaskOnFileSet(tsdb, info->fid)); tsdbFinishTaskOnFileSet(tsdb, info->fid);
} }
} }
(void)taosThreadMutexUnlock(&tsdb->mutex); (void)taosThreadMutexUnlock(&tsdb->mutex);
TAOS_UNUSED(tsdbCommitInfoDestroy(tsdb)); TAOS_UNUSED(tsdbCommitInfoDestroy(tsdb));
TAOS_UNUSED(tsdbUnrefMemTable(pMemTable, NULL, true)); tsdbUnrefMemTable(pMemTable, NULL, true);
} }
_exit: _exit:
@ -741,7 +741,7 @@ int32_t tsdbCommitAbort(STsdb *pTsdb) {
for (int32_t i = 0; i < taosArrayGetSize(pTsdb->commitInfo->arr); i++) { for (int32_t i = 0; i < taosArrayGetSize(pTsdb->commitInfo->arr); i++) {
SFileSetCommitInfo *info = *(SFileSetCommitInfo **)taosArrayGet(pTsdb->commitInfo->arr, i); SFileSetCommitInfo *info = *(SFileSetCommitInfo **)taosArrayGet(pTsdb->commitInfo->arr, i);
if (info->fset) { if (info->fset) {
TAOS_UNUSED(tsdbFinishTaskOnFileSet(pTsdb, info->fid)); tsdbFinishTaskOnFileSet(pTsdb, info->fid);
} }
} }
(void)taosThreadMutexUnlock(&pTsdb->mutex); (void)taosThreadMutexUnlock(&pTsdb->mutex);

View File

@ -35,7 +35,7 @@ int32_t tsdbDataFileRAWReaderOpen(const char *fname, const SDataFileRAWReaderCon
} }
} else { } else {
char fname1[TSDB_FILENAME_LEN]; char fname1[TSDB_FILENAME_LEN];
(void)tsdbTFileName(config->tsdb, &config->file, fname1); tsdbTFileName(config->tsdb, &config->file, fname1);
TAOS_CHECK_GOTO(tsdbOpenFile(fname1, config->tsdb, TD_FILE_READ, &reader[0]->fd, lcn), &lino, _exit); TAOS_CHECK_GOTO(tsdbOpenFile(fname1, config->tsdb, TD_FILE_READ, &reader[0]->fd, lcn), &lino, _exit);
} }
@ -117,7 +117,7 @@ static int32_t tsdbDataFileRAWWriterCloseAbort(SDataFileRAWWriter *writer) {
return 0; return 0;
} }
static int32_t tsdbDataFileRAWWriterDoClose(SDataFileRAWWriter *writer) { return 0; } static void tsdbDataFileRAWWriterDoClose(SDataFileRAWWriter *writer) { return; }
static int32_t tsdbDataFileRAWWriterCloseCommit(SDataFileRAWWriter *writer, TFileOpArray *opArr) { static int32_t tsdbDataFileRAWWriterCloseCommit(SDataFileRAWWriter *writer, TFileOpArray *opArr) {
int32_t code = 0; int32_t code = 0;
@ -157,7 +157,7 @@ static int32_t tsdbDataFileRAWWriterOpenDataFD(SDataFileRAWWriter *writer) {
flag |= (TD_FILE_CREATE | TD_FILE_TRUNC); flag |= (TD_FILE_CREATE | TD_FILE_TRUNC);
} }
(void)tsdbTFileName(writer->config->tsdb, &writer->file, fname); tsdbTFileName(writer->config->tsdb, &writer->file, fname);
TAOS_CHECK_GOTO(tsdbOpenFile(fname, writer->config->tsdb, flag, &writer->fd, writer->file.lcn), &lino, _exit); TAOS_CHECK_GOTO(tsdbOpenFile(fname, writer->config->tsdb, flag, &writer->fd, writer->file.lcn), &lino, _exit);
_exit: _exit:
@ -200,7 +200,7 @@ int32_t tsdbDataFileRAWWriterClose(SDataFileRAWWriter **writer, bool abort, TFil
} else { } else {
TAOS_CHECK_GOTO(tsdbDataFileRAWWriterCloseCommit(writer[0], opArr), &lino, _exit); TAOS_CHECK_GOTO(tsdbDataFileRAWWriterCloseCommit(writer[0], opArr), &lino, _exit);
} }
(void)tsdbDataFileRAWWriterDoClose(writer[0]); tsdbDataFileRAWWriterDoClose(writer[0]);
} }
taosMemoryFree(writer[0]); taosMemoryFree(writer[0]);
writer[0] = NULL; writer[0] = NULL;

View File

@ -135,7 +135,7 @@ int32_t tsdbDataFileReaderOpen(const char *fname[], const SDataFileReaderConfig
for (int32_t i = 0; i < TSDB_FTYPE_MAX; ++i) { for (int32_t i = 0; i < TSDB_FTYPE_MAX; ++i) {
if (config->files[i].exist) { if (config->files[i].exist) {
char fname1[TSDB_FILENAME_LEN]; char fname1[TSDB_FILENAME_LEN];
(void)tsdbTFileName(config->tsdb, &config->files[i].file, fname1); tsdbTFileName(config->tsdb, &config->files[i].file, fname1);
int32_t lcn = config->files[i].file.lcn; int32_t lcn = config->files[i].file.lcn;
TAOS_CHECK_GOTO(tsdbOpenFile(fname1, config->tsdb, TD_FILE_READ, &reader[0]->fd[i], lcn), &lino, _exit); TAOS_CHECK_GOTO(tsdbOpenFile(fname1, config->tsdb, TD_FILE_READ, &reader[0]->fd[i], lcn), &lino, _exit);
} }
@ -150,9 +150,9 @@ _exit:
return code; return code;
} }
int32_t tsdbDataFileReaderClose(SDataFileReader **reader) { void tsdbDataFileReaderClose(SDataFileReader **reader) {
if (reader[0] == NULL) { if (reader[0] == NULL) {
return 0; return;
} }
TARRAY2_DESTROY(reader[0]->tombBlkArray, NULL); TARRAY2_DESTROY(reader[0]->tombBlkArray, NULL);
@ -170,7 +170,6 @@ int32_t tsdbDataFileReaderClose(SDataFileReader **reader) {
taosMemoryFree(reader[0]); taosMemoryFree(reader[0]);
reader[0] = NULL; reader[0] = NULL;
return 0;
} }
int32_t tsdbDataFileReadBrinBlk(SDataFileReader *reader, const TBrinBlkArray **brinBlkArray) { int32_t tsdbDataFileReadBrinBlk(SDataFileReader *reader, const TBrinBlkArray **brinBlkArray) {
@ -230,7 +229,7 @@ int32_t tsdbDataFileReadBrinBlock(SDataFileReader *reader, const SBrinBlk *brinB
// decode brin block // decode brin block
SBufferReader br = BUFFER_READER_INITIALIZER(0, buffer); SBufferReader br = BUFFER_READER_INITIALIZER(0, buffer);
(void)tBrinBlockClear(brinBlock); tBrinBlockClear(brinBlock);
brinBlock->numOfPKs = brinBlk->numOfPKs; brinBlock->numOfPKs = brinBlk->numOfPKs;
brinBlock->numOfRecords = brinBlk->numRec; brinBlock->numOfRecords = brinBlk->numRec;
for (int32_t i = 0; i < 10; i++) { // int64_t for (int32_t i = 0; i < 10; i++) { // int64_t
@ -677,20 +676,20 @@ static int32_t tsdbDataFileWriterCloseAbort(SDataFileWriter *writer) {
return 0; return 0;
} }
static int32_t tsdbDataFileWriterDoClose(SDataFileWriter *writer) { static void tsdbDataFileWriterDoClose(SDataFileWriter *writer) {
if (writer->ctx->reader) { if (writer->ctx->reader) {
(void)tsdbDataFileReaderClose(&writer->ctx->reader); tsdbDataFileReaderClose(&writer->ctx->reader);
} }
tTombBlockDestroy(writer->tombBlock); tTombBlockDestroy(writer->tombBlock);
TARRAY2_DESTROY(writer->tombBlkArray, NULL); TARRAY2_DESTROY(writer->tombBlkArray, NULL);
tBlockDataDestroy(writer->blockData); tBlockDataDestroy(writer->blockData);
(void)tBrinBlockDestroy(writer->brinBlock); tBrinBlockDestroy(writer->brinBlock);
TARRAY2_DESTROY(writer->brinBlkArray, NULL); TARRAY2_DESTROY(writer->brinBlkArray, NULL);
tTombBlockDestroy(writer->ctx->tombBlock); tTombBlockDestroy(writer->ctx->tombBlock);
tBlockDataDestroy(writer->ctx->blockData); tBlockDataDestroy(writer->ctx->blockData);
(void)tBrinBlockDestroy(writer->ctx->brinBlock); tBrinBlockDestroy(writer->ctx->brinBlock);
for (int32_t i = 0; i < ARRAY_SIZE(writer->local); ++i) { for (int32_t i = 0; i < ARRAY_SIZE(writer->local); ++i) {
tBufferDestroy(writer->local + i); tBufferDestroy(writer->local + i);
@ -698,7 +697,6 @@ static int32_t tsdbDataFileWriterDoClose(SDataFileWriter *writer) {
tDestroyTSchema(writer->skmRow->pTSchema); tDestroyTSchema(writer->skmRow->pTSchema);
tDestroyTSchema(writer->skmTb->pTSchema); tDestroyTSchema(writer->skmTb->pTSchema);
return 0;
} }
static int32_t tsdbDataFileWriterDoOpenReader(SDataFileWriter *writer) { static int32_t tsdbDataFileWriterDoOpenReader(SDataFileWriter *writer) {
@ -819,10 +817,9 @@ _exit:
return code; return code;
} }
int32_t tsdbWriterUpdVerRange(SVersionRange *range, int64_t minVer, int64_t maxVer) { void tsdbWriterUpdVerRange(SVersionRange *range, int64_t minVer, int64_t maxVer) {
range->minVer = TMIN(range->minVer, minVer); range->minVer = TMIN(range->minVer, minVer);
range->maxVer = TMAX(range->maxVer, maxVer); range->maxVer = TMAX(range->maxVer, maxVer);
return 0;
} }
int32_t tsdbFileWriteBrinBlock(STsdbFD *fd, SBrinBlock *brinBlock, uint32_t cmprAlg, int64_t *fileSize, int32_t tsdbFileWriteBrinBlock(STsdbFD *fd, SBrinBlock *brinBlock, uint32_t cmprAlg, int64_t *fileSize,
@ -850,7 +847,7 @@ int32_t tsdbFileWriteBrinBlock(STsdbFD *fd, SBrinBlock *brinBlock, uint32_t cmpr
for (int i = 0; i < brinBlock->numOfRecords; i++) { for (int i = 0; i < brinBlock->numOfRecords; i++) {
SBrinRecord record; SBrinRecord record;
(void)tBrinBlockGet(brinBlock, i, &record); TAOS_CHECK_RETURN(tBrinBlockGet(brinBlock, i, &record));
if (i == 0) { if (i == 0) {
brinBlk.minTbid.suid = record.suid; brinBlk.minTbid.suid = record.suid;
brinBlk.minTbid.uid = record.uid; brinBlk.minTbid.uid = record.uid;
@ -869,7 +866,7 @@ int32_t tsdbFileWriteBrinBlock(STsdbFD *fd, SBrinBlock *brinBlock, uint32_t cmpr
} }
} }
(void)tsdbWriterUpdVerRange(range, brinBlk.minVer, brinBlk.maxVer); tsdbWriterUpdVerRange(range, brinBlk.minVer, brinBlk.maxVer);
// write to file // write to file
for (int32_t i = 0; i < 10; ++i) { for (int32_t i = 0; i < 10; ++i) {
@ -930,7 +927,7 @@ int32_t tsdbFileWriteBrinBlock(STsdbFD *fd, SBrinBlock *brinBlock, uint32_t cmpr
// append to brinBlkArray // append to brinBlkArray
TAOS_CHECK_RETURN(TARRAY2_APPEND_PTR(brinBlkArray, &brinBlk)); TAOS_CHECK_RETURN(TARRAY2_APPEND_PTR(brinBlkArray, &brinBlk));
(void)tBrinBlockClear(brinBlock); tBrinBlockClear(brinBlock);
return 0; return 0;
} }
@ -1032,7 +1029,7 @@ static int32_t tsdbDataFileDoWriteBlockData(SDataFileWriter *writer, SBlockData
} }
} }
(void)tsdbWriterUpdVerRange(&writer->ctx->range, record->minVer, record->maxVer); tsdbWriterUpdVerRange(&writer->ctx->range, record->minVer, record->maxVer);
code = metaGetColCmpr(writer->config->tsdb->pVnode->pMeta, bData->suid != 0 ? bData->suid : bData->uid, code = metaGetColCmpr(writer->config->tsdb->pVnode->pMeta, bData->suid != 0 ? bData->suid : bData->uid,
&cmprInfo.pColCmpr); &cmprInfo.pColCmpr);
@ -1163,7 +1160,8 @@ static int32_t tsdbDataFileDoWriteTableOldData(SDataFileWriter *writer, const ST
for (; writer->ctx->brinBlockIdx < writer->ctx->brinBlock->numOfRecords; writer->ctx->brinBlockIdx++) { for (; writer->ctx->brinBlockIdx < writer->ctx->brinBlock->numOfRecords; writer->ctx->brinBlockIdx++) {
SBrinRecord record; SBrinRecord record;
(void)tBrinBlockGet(writer->ctx->brinBlock, writer->ctx->brinBlockIdx, &record); code = tBrinBlockGet(writer->ctx->brinBlock, writer->ctx->brinBlockIdx, &record);
TSDB_CHECK_CODE(code, lino, _exit);
if (record.uid != writer->ctx->tbid->uid) { if (record.uid != writer->ctx->tbid->uid) {
writer->ctx->tbHasOldData = false; writer->ctx->tbHasOldData = false;
goto _exit; goto _exit;
@ -1173,7 +1171,8 @@ static int32_t tsdbDataFileDoWriteTableOldData(SDataFileWriter *writer, const ST
goto _exit; goto _exit;
} else { } else {
SBrinRecord record[1]; SBrinRecord record[1];
(void)tBrinBlockGet(writer->ctx->brinBlock, writer->ctx->brinBlockIdx, record); code = tBrinBlockGet(writer->ctx->brinBlock, writer->ctx->brinBlockIdx, record);
TSDB_CHECK_CODE(code, lino, _exit);
if (tsdbRowKeyCmprNullAsLargest(key, &record->lastKey) > 0) { // key > record->lastKey if (tsdbRowKeyCmprNullAsLargest(key, &record->lastKey) > 0) { // key > record->lastKey
if (writer->blockData->nRow > 0) { if (writer->blockData->nRow > 0) {
TAOS_CHECK_GOTO(tsdbDataFileDoWriteBlockData(writer, writer->blockData), &lino, _exit); TAOS_CHECK_GOTO(tsdbDataFileDoWriteBlockData(writer, writer->blockData), &lino, _exit);
@ -1383,7 +1382,7 @@ int32_t tsdbFileWriteTombBlock(STsdbFD *fd, STombBlock *tombBlock, int8_t cmprAl
} }
} }
(void)tsdbWriterUpdVerRange(range, tombBlk.minVer, tombBlk.maxVer); tsdbWriterUpdVerRange(range, tombBlk.minVer, tombBlk.maxVer);
for (int32_t i = 0; i < ARRAY_SIZE(tombBlock->buffers); i++) { for (int32_t i = 0; i < ARRAY_SIZE(tombBlock->buffers); i++) {
tBufferClear(buffer0); tBufferClear(buffer0);
@ -1615,10 +1614,9 @@ _exit:
return code; return code;
} }
int32_t tsdbTFileUpdVerRange(STFile *f, SVersionRange range) { void tsdbTFileUpdVerRange(STFile *f, SVersionRange range) {
f->minVer = TMIN(f->minVer, range.minVer); f->minVer = TMIN(f->minVer, range.minVer);
f->maxVer = TMAX(f->maxVer, range.maxVer); f->maxVer = TMAX(f->maxVer, range.maxVer);
return 0;
} }
static int32_t tsdbDataFileWriterCloseCommit(SDataFileWriter *writer, TFileOpArray *opArr) { static int32_t tsdbDataFileWriterCloseCommit(SDataFileWriter *writer, TFileOpArray *opArr) {
@ -1658,8 +1656,8 @@ static int32_t tsdbDataFileWriterCloseCommit(SDataFileWriter *writer, TFileOpArr
.fid = writer->config->fid, .fid = writer->config->fid,
.nf = writer->files[ftype], .nf = writer->files[ftype],
}; };
(void)tsdbTFileUpdVerRange(&op.nf, ofRange); tsdbTFileUpdVerRange(&op.nf, ofRange);
(void)tsdbTFileUpdVerRange(&op.nf, writer->ctx->range); tsdbTFileUpdVerRange(&op.nf, writer->ctx->range);
TAOS_CHECK_GOTO(TARRAY2_APPEND(opArr, op), &lino, _exit); TAOS_CHECK_GOTO(TARRAY2_APPEND(opArr, op), &lino, _exit);
// .data // .data
@ -1670,7 +1668,7 @@ static int32_t tsdbDataFileWriterCloseCommit(SDataFileWriter *writer, TFileOpArr
.fid = writer->config->fid, .fid = writer->config->fid,
.nf = writer->files[ftype], .nf = writer->files[ftype],
}; };
(void)tsdbTFileUpdVerRange(&op.nf, writer->ctx->range); tsdbTFileUpdVerRange(&op.nf, writer->ctx->range);
TAOS_CHECK_GOTO(TARRAY2_APPEND(opArr, op), &lino, _exit); TAOS_CHECK_GOTO(TARRAY2_APPEND(opArr, op), &lino, _exit);
} else if (writer->config->files[ftype].file.size != writer->files[ftype].size) { } else if (writer->config->files[ftype].file.size != writer->files[ftype].size) {
op = (STFileOp){ op = (STFileOp){
@ -1679,7 +1677,7 @@ static int32_t tsdbDataFileWriterCloseCommit(SDataFileWriter *writer, TFileOpArr
.of = writer->config->files[ftype].file, .of = writer->config->files[ftype].file,
.nf = writer->files[ftype], .nf = writer->files[ftype],
}; };
(void)tsdbTFileUpdVerRange(&op.nf, writer->ctx->range); tsdbTFileUpdVerRange(&op.nf, writer->ctx->range);
TAOS_CHECK_GOTO(TARRAY2_APPEND(opArr, op), &lino, _exit); TAOS_CHECK_GOTO(TARRAY2_APPEND(opArr, op), &lino, _exit);
} }
@ -1691,7 +1689,7 @@ static int32_t tsdbDataFileWriterCloseCommit(SDataFileWriter *writer, TFileOpArr
.fid = writer->config->fid, .fid = writer->config->fid,
.nf = writer->files[ftype], .nf = writer->files[ftype],
}; };
(void)tsdbTFileUpdVerRange(&op.nf, writer->ctx->range); tsdbTFileUpdVerRange(&op.nf, writer->ctx->range);
TAOS_CHECK_GOTO(TARRAY2_APPEND(opArr, op), &lino, _exit); TAOS_CHECK_GOTO(TARRAY2_APPEND(opArr, op), &lino, _exit);
} else if (writer->config->files[ftype].file.size != writer->files[ftype].size) { } else if (writer->config->files[ftype].file.size != writer->files[ftype].size) {
op = (STFileOp){ op = (STFileOp){
@ -1700,7 +1698,7 @@ static int32_t tsdbDataFileWriterCloseCommit(SDataFileWriter *writer, TFileOpArr
.of = writer->config->files[ftype].file, .of = writer->config->files[ftype].file,
.nf = writer->files[ftype], .nf = writer->files[ftype],
}; };
(void)tsdbTFileUpdVerRange(&op.nf, writer->ctx->range); tsdbTFileUpdVerRange(&op.nf, writer->ctx->range);
TAOS_CHECK_GOTO(TARRAY2_APPEND(opArr, op), &lino, _exit); TAOS_CHECK_GOTO(TARRAY2_APPEND(opArr, op), &lino, _exit);
} }
} }
@ -1734,8 +1732,8 @@ static int32_t tsdbDataFileWriterCloseCommit(SDataFileWriter *writer, TFileOpArr
.fid = writer->config->fid, .fid = writer->config->fid,
.nf = writer->files[ftype], .nf = writer->files[ftype],
}; };
(void)tsdbTFileUpdVerRange(&op.nf, ofRange); tsdbTFileUpdVerRange(&op.nf, ofRange);
(void)tsdbTFileUpdVerRange(&op.nf, writer->ctx->tombRange); tsdbTFileUpdVerRange(&op.nf, writer->ctx->tombRange);
TAOS_CHECK_GOTO(TARRAY2_APPEND(opArr, op), &lino, _exit); TAOS_CHECK_GOTO(TARRAY2_APPEND(opArr, op), &lino, _exit);
} }
int32_t encryptAlgorithm = writer->config->tsdb->pVnode->config.tsdbCfg.encryptAlgorithm; int32_t encryptAlgorithm = writer->config->tsdb->pVnode->config.tsdbCfg.encryptAlgorithm;
@ -1772,7 +1770,7 @@ static int32_t tsdbDataFileWriterOpenDataFD(SDataFileWriter *writer) {
} }
int32_t lcn = writer->files[ftype].lcn; int32_t lcn = writer->files[ftype].lcn;
(void)tsdbTFileName(writer->config->tsdb, &writer->files[ftype], fname); tsdbTFileName(writer->config->tsdb, &writer->files[ftype], fname);
TAOS_CHECK_GOTO(tsdbOpenFile(fname, writer->config->tsdb, flag, &writer->fd[ftype], lcn), &lino, _exit); TAOS_CHECK_GOTO(tsdbOpenFile(fname, writer->config->tsdb, flag, &writer->fd[ftype], lcn), &lino, _exit);
if (writer->files[ftype].size == 0) { if (writer->files[ftype].size == 0) {
@ -1822,7 +1820,7 @@ int32_t tsdbDataFileWriterClose(SDataFileWriter **writer, bool abort, TFileOpArr
} else { } else {
TAOS_CHECK_GOTO(tsdbDataFileWriterCloseCommit(writer[0], opArr), &lino, _exit); TAOS_CHECK_GOTO(tsdbDataFileWriterCloseCommit(writer[0], opArr), &lino, _exit);
} }
(void)tsdbDataFileWriterDoClose(writer[0]); tsdbDataFileWriterDoClose(writer[0]);
} }
taosMemoryFree(writer[0]); taosMemoryFree(writer[0]);
writer[0] = NULL; writer[0] = NULL;
@ -1935,7 +1933,7 @@ static int32_t tsdbDataFileWriterOpenTombFD(SDataFileWriter *writer) {
int32_t flag = (TD_FILE_READ | TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC); int32_t flag = (TD_FILE_READ | TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC);
int32_t lcn = writer->files[ftype].lcn; int32_t lcn = writer->files[ftype].lcn;
(void)tsdbTFileName(writer->config->tsdb, writer->files + ftype, fname); tsdbTFileName(writer->config->tsdb, writer->files + ftype, fname);
TAOS_CHECK_GOTO(tsdbOpenFile(fname, writer->config->tsdb, flag, &writer->fd[ftype], lcn), &lino, _exit); TAOS_CHECK_GOTO(tsdbOpenFile(fname, writer->config->tsdb, flag, &writer->fd[ftype], lcn), &lino, _exit);

View File

@ -51,7 +51,7 @@ typedef struct SDataFileReaderConfig {
int32_t tsdbDataFileReaderOpen(const char *fname[/* TSDB_FTYPE_MAX */], const SDataFileReaderConfig *config, int32_t tsdbDataFileReaderOpen(const char *fname[/* TSDB_FTYPE_MAX */], const SDataFileReaderConfig *config,
SDataFileReader **reader); SDataFileReader **reader);
int32_t tsdbDataFileReaderClose(SDataFileReader **reader); void tsdbDataFileReaderClose(SDataFileReader **reader);
// .head // .head
int32_t tsdbDataFileReadBrinBlk(SDataFileReader *reader, const TBrinBlkArray **brinBlkArray); int32_t tsdbDataFileReadBrinBlk(SDataFileReader *reader, const TBrinBlkArray **brinBlkArray);
int32_t tsdbDataFileReadBrinBlock(SDataFileReader *reader, const SBrinBlk *brinBlk, SBrinBlock *brinBlock); int32_t tsdbDataFileReadBrinBlock(SDataFileReader *reader, const SBrinBlk *brinBlk, SBrinBlock *brinBlock);
@ -115,8 +115,8 @@ int32_t tsdbFileWriteTombFooter(STsdbFD *fd, const STombFooter *footer, int64_t
char *encryptKey); char *encryptKey);
// utils // utils
int32_t tsdbWriterUpdVerRange(SVersionRange *range, int64_t minVer, int64_t maxVer); void tsdbWriterUpdVerRange(SVersionRange *range, int64_t minVer, int64_t maxVer);
int32_t tsdbTFileUpdVerRange(STFile *f, SVersionRange range); void tsdbTFileUpdVerRange(STFile *f, SVersionRange range);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -105,18 +105,20 @@ static int32_t tsdbSaveFSToFile(STsdbFS *pFS, const char *fname) {
code = TSDB_CODE_OUT_OF_MEMORY; code = TSDB_CODE_OUT_OF_MEMORY;
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }
(void)tsdbFSToBinary(pData, pFS); int32_t tsize = tsdbFSToBinary(pData, pFS);
(void)taosCalcChecksumAppend(0, pData, size);
code = taosCalcChecksumAppend(0, pData, size);
TSDB_CHECK_CODE(code, lino, _exit);
// save to file // save to file
pFD = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); pFD = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
if (pFD == NULL) { if (pFD == NULL) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); TSDB_CHECK_CODE(code = terrno, lino, _exit);
} }
int64_t n = taosWriteFile(pFD, pData, size); int64_t n = taosWriteFile(pFD, pData, size);
if (n < 0) { if (n < 0) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); TSDB_CHECK_CODE(code = terrno, lino, _exit);
} }
if (taosFsyncFile(pFD) < 0) { if (taosFsyncFile(pFD) < 0) {
@ -176,7 +178,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
if (pTsdb->fs.pDelFile) { if (pTsdb->fs.pDelFile) {
tsdbDelFileName(pTsdb, pTsdb->fs.pDelFile, fname); tsdbDelFileName(pTsdb, pTsdb->fs.pDelFile, fname);
if (taosStatFile(fname, &size, NULL, NULL)) { if (taosStatFile(fname, &size, NULL, NULL)) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }
} }
@ -190,7 +192,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
// head ========= // head =========
tsdbHeadFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pHeadF, fname); tsdbHeadFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pHeadF, fname);
if (taosStatFile(fname, &size, NULL, NULL)) { if (taosStatFile(fname, &size, NULL, NULL)) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }
// if (size != tsdbLogicToFileSize(pSet->pHeadF->size, pTsdb->pVnode->config.tsdbPageSize)) { // if (size != tsdbLogicToFileSize(pSet->pHeadF->size, pTsdb->pVnode->config.tsdbPageSize)) {
@ -201,7 +203,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
// data ========= // data =========
tsdbDataFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pDataF, fname); tsdbDataFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pDataF, fname);
if (taosStatFile(fname, &size, NULL, NULL)) { if (taosStatFile(fname, &size, NULL, NULL)) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }
// if (size < tsdbLogicToFileSize(pSet->pDataF->size, pTsdb->pVnode->config.tsdbPageSize)) { // if (size < tsdbLogicToFileSize(pSet->pDataF->size, pTsdb->pVnode->config.tsdbPageSize)) {
@ -216,7 +218,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
// sma ============= // sma =============
tsdbSmaFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pSmaF, fname); tsdbSmaFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pSmaF, fname);
if (taosStatFile(fname, &size, NULL, NULL)) { if (taosStatFile(fname, &size, NULL, NULL)) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }
// if (size < tsdbLogicToFileSize(pSet->pSmaF->size, pTsdb->pVnode->config.tsdbPageSize)) { // if (size < tsdbLogicToFileSize(pSet->pSmaF->size, pTsdb->pVnode->config.tsdbPageSize)) {
@ -232,7 +234,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) { for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) {
tsdbSttFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSttF[iStt], fname); tsdbSttFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSttF[iStt], fname);
if (taosStatFile(fname, &size, NULL, NULL)) { if (taosStatFile(fname, &size, NULL, NULL)) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }
// if (size != tsdbLogicToFileSize(pSet->aSttF[iStt]->size, pTsdb->pVnode->config.tsdbPageSize)) { // if (size != tsdbLogicToFileSize(pSet->aSttF[iStt]->size, pTsdb->pVnode->config.tsdbPageSize)) {
@ -270,14 +272,14 @@ void tsdbGetCurrentFName(STsdb *pTsdb, char *current, char *current_t) {
// CURRENT // CURRENT
if (current) { if (current) {
(void)vnodeGetPrimaryDir(pTsdb->path, pVnode->diskPrimary, pVnode->pTfs, current, TSDB_FILENAME_LEN); vnodeGetPrimaryDir(pTsdb->path, pVnode->diskPrimary, pVnode->pTfs, current, TSDB_FILENAME_LEN);
offset = strlen(current); offset = strlen(current);
snprintf(current + offset, TSDB_FILENAME_LEN - offset - 1, "%sCURRENT", TD_DIRSEP); snprintf(current + offset, TSDB_FILENAME_LEN - offset - 1, "%sCURRENT", TD_DIRSEP);
} }
// CURRENT.t // CURRENT.t
if (current_t) { if (current_t) {
(void)vnodeGetPrimaryDir(pTsdb->path, pVnode->diskPrimary, pVnode->pTfs, current_t, TSDB_FILENAME_LEN); vnodeGetPrimaryDir(pTsdb->path, pVnode->diskPrimary, pVnode->pTfs, current_t, TSDB_FILENAME_LEN);
offset = strlen(current_t); offset = strlen(current_t);
snprintf(current_t + offset, TSDB_FILENAME_LEN - offset - 1, "%sCURRENT.t", TD_DIRSEP); snprintf(current_t + offset, TSDB_FILENAME_LEN - offset - 1, "%sCURRENT.t", TD_DIRSEP);
} }
@ -291,13 +293,13 @@ static int32_t load_fs(const char *fname, STsdbFS *pFS) {
// load binary // load binary
TdFilePtr pFD = taosOpenFile(fname, TD_FILE_READ); TdFilePtr pFD = taosOpenFile(fname, TD_FILE_READ);
if (pFD == NULL) { if (pFD == NULL) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }
int64_t size; int64_t size;
if (taosFStatFile(pFD, &size, NULL) < 0) { code = taosFStatFile(pFD, &size, NULL);
code = TAOS_SYSTEM_ERROR(errno); if (code != 0) {
(void)taosCloseFile(&pFD); (void)taosCloseFile(&pFD);
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }
@ -310,7 +312,7 @@ static int32_t load_fs(const char *fname, STsdbFS *pFS) {
} }
if (taosReadFile(pFD, pData, size) < 0) { if (taosReadFile(pFD, pData, size) < 0) {
code = TAOS_SYSTEM_ERROR(errno); code = terrno;
(void)taosCloseFile(&pFD); (void)taosCloseFile(&pFD);
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }
@ -340,21 +342,21 @@ static int32_t tsdbRemoveFileSet(STsdb *pTsdb, SDFileSet *pSet) {
int32_t nRef = atomic_sub_fetch_32(&pSet->pHeadF->nRef, 1); int32_t nRef = atomic_sub_fetch_32(&pSet->pHeadF->nRef, 1);
if (nRef == 0) { if (nRef == 0) {
tsdbHeadFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pHeadF, fname); tsdbHeadFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pHeadF, fname);
(void)taosRemoveFile(fname); tsdbRemoveFile(fname);
taosMemoryFree(pSet->pHeadF); taosMemoryFree(pSet->pHeadF);
} }
nRef = atomic_sub_fetch_32(&pSet->pDataF->nRef, 1); nRef = atomic_sub_fetch_32(&pSet->pDataF->nRef, 1);
if (nRef == 0) { if (nRef == 0) {
tsdbDataFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pDataF, fname); tsdbDataFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pDataF, fname);
(void)taosRemoveFile(fname); tsdbRemoveFile(fname);
taosMemoryFree(pSet->pDataF); taosMemoryFree(pSet->pDataF);
} }
nRef = atomic_sub_fetch_32(&pSet->pSmaF->nRef, 1); nRef = atomic_sub_fetch_32(&pSet->pSmaF->nRef, 1);
if (nRef == 0) { if (nRef == 0) {
tsdbSmaFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pSmaF, fname); tsdbSmaFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pSmaF, fname);
(void)taosRemoveFile(fname); tsdbRemoveFile(fname);
taosMemoryFree(pSet->pSmaF); taosMemoryFree(pSet->pSmaF);
} }
@ -362,7 +364,7 @@ static int32_t tsdbRemoveFileSet(STsdb *pTsdb, SDFileSet *pSet) {
nRef = atomic_sub_fetch_32(&pSet->aSttF[iStt]->nRef, 1); nRef = atomic_sub_fetch_32(&pSet->aSttF[iStt]->nRef, 1);
if (nRef == 0) { if (nRef == 0) {
tsdbSttFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSttF[iStt], fname); tsdbSttFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSttF[iStt], fname);
(void)taosRemoveFile(fname); tsdbRemoveFile(fname);
taosMemoryFree(pSet->aSttF[iStt]); taosMemoryFree(pSet->aSttF[iStt]);
} }
} }
@ -449,7 +451,7 @@ static int32_t tsdbMergeFileSet(STsdb *pTsdb, SDFileSet *pSetOld, SDFileSet *pSe
nRef = atomic_sub_fetch_32(&pHeadF->nRef, 1); nRef = atomic_sub_fetch_32(&pHeadF->nRef, 1);
if (nRef == 0) { if (nRef == 0) {
tsdbHeadFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pHeadF, fname); tsdbHeadFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pHeadF, fname);
(void)taosRemoveFile(fname); tsdbRemoveFile(fname);
taosMemoryFree(pHeadF); taosMemoryFree(pHeadF);
} }
} else { } else {
@ -472,7 +474,7 @@ static int32_t tsdbMergeFileSet(STsdb *pTsdb, SDFileSet *pSetOld, SDFileSet *pSe
nRef = atomic_sub_fetch_32(&pDataF->nRef, 1); nRef = atomic_sub_fetch_32(&pDataF->nRef, 1);
if (nRef == 0) { if (nRef == 0) {
tsdbDataFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pDataF, fname); tsdbDataFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pDataF, fname);
(void)taosRemoveFile(fname); tsdbRemoveFile(fname);
taosMemoryFree(pDataF); taosMemoryFree(pDataF);
} }
} else { } else {
@ -493,7 +495,7 @@ static int32_t tsdbMergeFileSet(STsdb *pTsdb, SDFileSet *pSetOld, SDFileSet *pSe
nRef = atomic_sub_fetch_32(&pSmaF->nRef, 1); nRef = atomic_sub_fetch_32(&pSmaF->nRef, 1);
if (nRef == 0) { if (nRef == 0) {
tsdbSmaFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSmaF, fname); tsdbSmaFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSmaF, fname);
(void)taosRemoveFile(fname); tsdbRemoveFile(fname);
taosMemoryFree(pSmaF); taosMemoryFree(pSmaF);
} }
} else { } else {
@ -517,7 +519,7 @@ static int32_t tsdbMergeFileSet(STsdb *pTsdb, SDFileSet *pSetOld, SDFileSet *pSe
nRef = atomic_sub_fetch_32(&pSttFile->nRef, 1); nRef = atomic_sub_fetch_32(&pSttFile->nRef, 1);
if (nRef == 0) { if (nRef == 0) {
tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSttFile, fname); tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSttFile, fname);
(void)taosRemoveFile(fname); tsdbRemoveFile(fname);
taosMemoryFree(pSttFile); taosMemoryFree(pSttFile);
} }
pSetOld->aSttF[iStt] = NULL; pSetOld->aSttF[iStt] = NULL;
@ -538,7 +540,7 @@ static int32_t tsdbMergeFileSet(STsdb *pTsdb, SDFileSet *pSetOld, SDFileSet *pSe
nRef = atomic_sub_fetch_32(&pSttFile->nRef, 1); nRef = atomic_sub_fetch_32(&pSttFile->nRef, 1);
if (nRef == 0) { if (nRef == 0) {
tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSttFile, fname); tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSttFile, fname);
(void)taosRemoveFile(fname); tsdbRemoveFile(fname);
taosMemoryFree(pSttFile); taosMemoryFree(pSttFile);
} }
@ -563,7 +565,7 @@ static int32_t tsdbMergeFileSet(STsdb *pTsdb, SDFileSet *pSetOld, SDFileSet *pSe
nRef = atomic_sub_fetch_32(&pSttFile->nRef, 1); nRef = atomic_sub_fetch_32(&pSttFile->nRef, 1);
if (nRef == 0) { if (nRef == 0) {
tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSttFile, fname); tsdbSttFileName(pTsdb, pSetOld->diskId, pSetOld->fid, pSttFile, fname);
(void)taosRemoveFile(fname); tsdbRemoveFile(fname);
taosMemoryFree(pSttFile); taosMemoryFree(pSttFile);
} }
} }
@ -619,7 +621,7 @@ static int32_t tsdbFSApplyChange(STsdb *pTsdb, STsdbFS *pFS) {
nRef = atomic_sub_fetch_32(&pDelFile->nRef, 1); nRef = atomic_sub_fetch_32(&pDelFile->nRef, 1);
if (nRef == 0) { if (nRef == 0) {
tsdbDelFileName(pTsdb, pDelFile, fname); tsdbDelFileName(pTsdb, pDelFile, fname);
(void)taosRemoveFile(fname); tsdbRemoveFile(fname);
taosMemoryFree(pDelFile); taosMemoryFree(pDelFile);
} }
} }
@ -629,7 +631,7 @@ static int32_t tsdbFSApplyChange(STsdb *pTsdb, STsdbFS *pFS) {
nRef = atomic_sub_fetch_32(&pTsdb->fs.pDelFile->nRef, 1); nRef = atomic_sub_fetch_32(&pTsdb->fs.pDelFile->nRef, 1);
if (nRef == 0) { if (nRef == 0) {
tsdbDelFileName(pTsdb, pTsdb->fs.pDelFile, fname); tsdbDelFileName(pTsdb, pTsdb->fs.pDelFile, fname);
(void)taosRemoveFile(fname); tsdbRemoveFile(fname);
taosMemoryFree(pTsdb->fs.pDelFile); taosMemoryFree(pTsdb->fs.pDelFile);
} }
pTsdb->fs.pDelFile = NULL; pTsdb->fs.pDelFile = NULL;
@ -711,10 +713,7 @@ static int32_t tsdbFSCommit(STsdb *pTsdb) {
if (!taosCheckExistFile(current_t)) goto _exit; if (!taosCheckExistFile(current_t)) goto _exit;
// rename the file // rename the file
if (taosRenameFile(current_t, current) < 0) { TSDB_CHECK_CODE(taosRenameFile(current_t, current), lino, _exit);
code = TAOS_SYSTEM_ERROR(errno);
TSDB_CHECK_CODE(code, lino, _exit);
}
// Load the new FS // Load the new FS
code = tsdbFSCreate(&fs); code = tsdbFSCreate(&fs);
@ -741,7 +740,7 @@ static int32_t tsdbFSRollback(STsdb *pTsdb) {
char current_t[TSDB_FILENAME_LEN] = {0}; char current_t[TSDB_FILENAME_LEN] = {0};
tsdbGetCurrentFName(pTsdb, NULL, current_t); tsdbGetCurrentFName(pTsdb, NULL, current_t);
(void)taosRemoveFile(current_t); tsdbRemoveFile(current_t);
_exit: _exit:
if (code) { if (code) {

View File

@ -20,8 +20,6 @@
#define BLOCK_COMMIT_FACTOR 3 #define BLOCK_COMMIT_FACTOR 3
extern void remove_file(const char *fname);
typedef struct STFileHashEntry { typedef struct STFileHashEntry {
struct STFileHashEntry *next; struct STFileHashEntry *next;
char fname[TSDB_FILENAME_LEN]; char fname[TSDB_FILENAME_LEN];
@ -55,25 +53,22 @@ static int32_t create_fs(STsdb *pTsdb, STFileSystem **fs) {
return 0; return 0;
} }
static int32_t destroy_fs(STFileSystem **fs) { static void destroy_fs(STFileSystem **fs) {
if (fs[0] == NULL) return 0; if (fs[0] == NULL) return;
TARRAY2_DESTROY(fs[0]->fSetArr, NULL); TARRAY2_DESTROY(fs[0]->fSetArr, NULL);
TARRAY2_DESTROY(fs[0]->fSetArrTmp, NULL); TARRAY2_DESTROY(fs[0]->fSetArrTmp, NULL);
(void)tsem_destroy(&fs[0]->canEdit); (void)tsem_destroy(&fs[0]->canEdit);
taosMemoryFree(fs[0]); taosMemoryFree(fs[0]);
fs[0] = NULL; fs[0] = NULL;
return 0;
} }
int32_t current_fname(STsdb *pTsdb, char *fname, EFCurrentT ftype) { void current_fname(STsdb *pTsdb, char *fname, EFCurrentT ftype) {
int32_t offset = 0; int32_t offset = 0;
(void)vnodeGetPrimaryDir(pTsdb->path, pTsdb->pVnode->diskPrimary, pTsdb->pVnode->pTfs, fname, TSDB_FILENAME_LEN); vnodeGetPrimaryDir(pTsdb->path, pTsdb->pVnode->diskPrimary, pTsdb->pVnode->pTfs, fname, TSDB_FILENAME_LEN);
offset = strlen(fname); offset = strlen(fname);
snprintf(fname + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, gCurrentFname[ftype]); snprintf(fname + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, gCurrentFname[ftype]);
return 0;
} }
static int32_t save_json(const cJSON *json, const char *fname) { static int32_t save_json(const cJSON *json, const char *fname) {
@ -89,15 +84,15 @@ static int32_t save_json(const cJSON *json, const char *fname) {
fp = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); fp = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
if (fp == NULL) { if (fp == NULL) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit); TSDB_CHECK_CODE(code = terrno, lino, _exit);
} }
if (taosWriteFile(fp, data, strlen(data)) < 0) { if (taosWriteFile(fp, data, strlen(data)) < 0) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit); TSDB_CHECK_CODE(code = terrno, lino, _exit);
} }
if (taosFsyncFile(fp) < 0) { if (taosFsyncFile(fp) < 0) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit); TSDB_CHECK_CODE(code = terrno, lino, _exit);
} }
_exit: _exit:
@ -116,12 +111,13 @@ static int32_t load_json(const char *fname, cJSON **json) {
TdFilePtr fp = taosOpenFile(fname, TD_FILE_READ); TdFilePtr fp = taosOpenFile(fname, TD_FILE_READ);
if (fp == NULL) { if (fp == NULL) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); TSDB_CHECK_CODE(code = terrno, lino, _exit);
} }
int64_t size; int64_t size;
if (taosFStatFile(fp, &size, NULL) < 0) { code = taosFStatFile(fp, &size, NULL);
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit); if (code != 0) {
TSDB_CHECK_CODE(code, lino, _exit);
} }
data = taosMemoryMalloc(size + 1); data = taosMemoryMalloc(size + 1);
@ -130,7 +126,7 @@ static int32_t load_json(const char *fname, cJSON **json) {
} }
if (taosReadFile(fp, data, size) < 0) { if (taosReadFile(fp, data, size) < 0) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit); TSDB_CHECK_CODE(code = terrno, lino, _exit);
} }
data[size] = '\0'; data[size] = '\0';
@ -257,7 +253,7 @@ static int32_t apply_commit(STFileSystem *fs) {
if (fset1 && fset2) { if (fset1 && fset2) {
if (fset1->fid < fset2->fid) { if (fset1->fid < fset2->fid) {
// delete fset1 // delete fset1
(void)tsdbTFileSetRemove(fset1); tsdbTFileSetRemove(fset1);
i1++; i1++;
} else if (fset1->fid > fset2->fid) { } else if (fset1->fid > fset2->fid) {
// create new file set with fid of fset2->fid // create new file set with fid of fset2->fid
@ -276,7 +272,7 @@ static int32_t apply_commit(STFileSystem *fs) {
} }
} else if (fset1) { } else if (fset1) {
// delete fset1 // delete fset1
(void)tsdbTFileSetRemove(fset1); tsdbTFileSetRemove(fset1);
i1++; i1++;
} else { } else {
// create new file set with fid of fset2->fid // create new file set with fid of fset2->fid
@ -300,19 +296,16 @@ static int32_t commit_edit(STFileSystem *fs) {
char current[TSDB_FILENAME_LEN]; char current[TSDB_FILENAME_LEN];
char current_t[TSDB_FILENAME_LEN]; char current_t[TSDB_FILENAME_LEN];
(void)current_fname(fs->tsdb, current, TSDB_FCURRENT); current_fname(fs->tsdb, current, TSDB_FCURRENT);
if (fs->etype == TSDB_FEDIT_COMMIT) { if (fs->etype == TSDB_FEDIT_COMMIT) {
(void)current_fname(fs->tsdb, current_t, TSDB_FCURRENT_C); current_fname(fs->tsdb, current_t, TSDB_FCURRENT_C);
} else { } else {
(void)current_fname(fs->tsdb, current_t, TSDB_FCURRENT_M); current_fname(fs->tsdb, current_t, TSDB_FCURRENT_M);
} }
int32_t code; int32_t code;
int32_t lino; int32_t lino;
if ((code = taosRenameFile(current_t, current))) { TSDB_CHECK_CODE(taosRenameFile(current_t, current), lino, _exit);
code = TAOS_SYSTEM_ERROR(code);
TSDB_CHECK_CODE(code, lino, _exit);
}
code = apply_commit(fs); code = apply_commit(fs);
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
@ -335,9 +328,9 @@ static int32_t abort_edit(STFileSystem *fs) {
char fname[TSDB_FILENAME_LEN]; char fname[TSDB_FILENAME_LEN];
if (fs->etype == TSDB_FEDIT_COMMIT) { if (fs->etype == TSDB_FEDIT_COMMIT) {
(void)current_fname(fs->tsdb, fname, TSDB_FCURRENT_C); current_fname(fs->tsdb, fname, TSDB_FCURRENT_C);
} else { } else {
(void)current_fname(fs->tsdb, fname, TSDB_FCURRENT_M); current_fname(fs->tsdb, fname, TSDB_FCURRENT_M);
} }
int32_t code; int32_t code;
@ -370,7 +363,7 @@ static int32_t tsdbFSDoScanAndFixFile(STFileSystem *fs, const STFileObj *fobj) {
if (tsS3Enabled && fobj->f->lcn > 1) { if (tsS3Enabled && fobj->f->lcn > 1) {
char fname1[TSDB_FILENAME_LEN]; char fname1[TSDB_FILENAME_LEN];
(void)tsdbTFileLastChunkName(fs->tsdb, fobj->f, fname1); tsdbTFileLastChunkName(fs->tsdb, fobj->f, fname1);
if (!taosCheckExistFile(fname1)) { if (!taosCheckExistFile(fname1)) {
code = TSDB_CODE_FILE_CORRUPTED; code = TSDB_CODE_FILE_CORRUPTED;
tsdbError("vgId:%d %s failed since file:%s does not exist", TD_VID(fs->tsdb->pVnode), __func__, fname1); tsdbError("vgId:%d %s failed since file:%s does not exist", TD_VID(fs->tsdb->pVnode), __func__, fname1);
@ -421,7 +414,7 @@ static int32_t tsdbFSCreateFileObjHash(STFileSystem *fs, STFileHash *hash) {
} }
// vnode.json // vnode.json
(void)current_fname(fs->tsdb, fname, TSDB_FCURRENT); current_fname(fs->tsdb, fname, TSDB_FCURRENT);
code = tsdbFSAddEntryToFileObjHash(hash, fname); code = tsdbFSAddEntryToFileObjHash(hash, fname);
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
@ -538,7 +531,7 @@ static int32_t tsdbFSDoSanAndFix(STFileSystem *fs) {
if (tsdbFSGetFileObjHashEntry(&fobjHash, file->aname) == NULL && if (tsdbFSGetFileObjHashEntry(&fobjHash, file->aname) == NULL &&
strncmp(file->aname + strlen(file->aname) - 3, ".cp", 3) && strncmp(file->aname + strlen(file->aname) - 3, ".cp", 3) &&
strncmp(file->aname + strlen(file->aname) - 5, ".data", 5)) { strncmp(file->aname + strlen(file->aname) - 5, ".data", 5)) {
remove_file(file->aname); tsdbRemoveFile(file->aname);
} }
} }
@ -605,9 +598,9 @@ static int32_t open_fs(STFileSystem *fs, int8_t rollback) {
char cCurrent[TSDB_FILENAME_LEN]; char cCurrent[TSDB_FILENAME_LEN];
char mCurrent[TSDB_FILENAME_LEN]; char mCurrent[TSDB_FILENAME_LEN];
(void)current_fname(pTsdb, fCurrent, TSDB_FCURRENT); current_fname(pTsdb, fCurrent, TSDB_FCURRENT);
(void)current_fname(pTsdb, cCurrent, TSDB_FCURRENT_C); current_fname(pTsdb, cCurrent, TSDB_FCURRENT_C);
(void)current_fname(pTsdb, mCurrent, TSDB_FCURRENT_M); current_fname(pTsdb, mCurrent, TSDB_FCURRENT_M);
if (taosCheckExistFile(fCurrent)) { // current.json exists if (taosCheckExistFile(fCurrent)) { // current.json exists
code = load_fs(pTsdb, fCurrent, fs->fSetArr); code = load_fs(pTsdb, fCurrent, fs->fSetArr);
@ -653,10 +646,9 @@ _exit:
return code; return code;
} }
static int32_t close_file_system(STFileSystem *fs) { static void close_file_system(STFileSystem *fs) {
TARRAY2_CLEAR(fs->fSetArr, tsdbTFileSetClear); TARRAY2_CLEAR(fs->fSetArr, tsdbTFileSetClear);
TARRAY2_CLEAR(fs->fSetArrTmp, tsdbTFileSetClear); TARRAY2_CLEAR(fs->fSetArrTmp, tsdbTFileSetClear);
return 0;
} }
static int32_t fset_cmpr_fn(const struct STFileSet *pSet1, const struct STFileSet *pSet2) { static int32_t fset_cmpr_fn(const struct STFileSet *pSet1, const struct STFileSet *pSet2) {
@ -746,15 +738,15 @@ int32_t tsdbOpenFS(STsdb *pTsdb, STFileSystem **fs, int8_t rollback) {
_exit: _exit:
if (code) { if (code) {
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code));
(void)destroy_fs(fs); destroy_fs(fs);
} else { } else {
tsdbInfo("vgId:%d %s success", TD_VID(pTsdb->pVnode), __func__); tsdbInfo("vgId:%d %s success", TD_VID(pTsdb->pVnode), __func__);
} }
return code; return code;
} }
static int32_t tsdbFSSetBlockCommit(STFileSet *fset, bool block); static void tsdbFSSetBlockCommit(STFileSet *fset, bool block);
extern int32_t tsdbStopAllCompTask(STsdb *tsdb); extern void tsdbStopAllCompTask(STsdb *tsdb);
int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb) { int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb) {
STFileSystem *fs = pTsdb->pFS; STFileSystem *fs = pTsdb->pFS;
@ -779,7 +771,7 @@ int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb) {
} }
fset->channel = (SVAChannelID){0}; fset->channel = (SVAChannelID){0};
fset->mergeScheduled = false; fset->mergeScheduled = false;
(void)tsdbFSSetBlockCommit(fset, false); tsdbFSSetBlockCommit(fset, false);
fset->channelOpened = false; fset->channelOpened = false;
} }
} }
@ -789,30 +781,32 @@ int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb) {
// destroy all channels // destroy all channels
for (int32_t i = 0; i < taosArrayGetSize(channelArray); i++) { for (int32_t i = 0; i < taosArrayGetSize(channelArray); i++) {
SVAChannelID *channel = taosArrayGet(channelArray, i); SVAChannelID *channel = taosArrayGet(channelArray, i);
(void)vnodeAChannelDestroy(channel, true); int32_t code = vnodeAChannelDestroy(channel, true);
if (code) {
tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, tstrerror(code));
}
} }
taosArrayDestroy(channelArray); taosArrayDestroy(channelArray);
#ifdef TD_ENTERPRISE #ifdef TD_ENTERPRISE
(void)tsdbStopAllCompTask(pTsdb); tsdbStopAllCompTask(pTsdb);
#endif #endif
return 0; return 0;
} }
int32_t tsdbEnableBgTask(STsdb *pTsdb) { void tsdbEnableBgTask(STsdb *pTsdb) {
(void)taosThreadMutexLock(&pTsdb->mutex); (void)taosThreadMutexLock(&pTsdb->mutex);
pTsdb->bgTaskDisabled = false; pTsdb->bgTaskDisabled = false;
(void)taosThreadMutexUnlock(&pTsdb->mutex); (void)taosThreadMutexUnlock(&pTsdb->mutex);
return 0;
} }
int32_t tsdbCloseFS(STFileSystem **fs) { void tsdbCloseFS(STFileSystem **fs) {
if (fs[0] == NULL) return 0; if (fs[0] == NULL) return;
(void)tsdbDisableAndCancelAllBgTask((*fs)->tsdb); TAOS_UNUSED(tsdbDisableAndCancelAllBgTask((*fs)->tsdb));
(void)close_file_system(fs[0]); close_file_system(fs[0]);
(void)destroy_fs(fs); destroy_fs(fs);
return 0; return;
} }
int64_t tsdbFSAllocEid(STFileSystem *fs) { int64_t tsdbFSAllocEid(STFileSystem *fs) {
@ -834,9 +828,9 @@ int32_t tsdbFSEditBegin(STFileSystem *fs, const TFileOpArray *opArray, EFEditT e
char current_t[TSDB_FILENAME_LEN]; char current_t[TSDB_FILENAME_LEN];
if (etype == TSDB_FEDIT_COMMIT) { if (etype == TSDB_FEDIT_COMMIT) {
(void)current_fname(fs->tsdb, current_t, TSDB_FCURRENT_C); current_fname(fs->tsdb, current_t, TSDB_FCURRENT_C);
} else { } else {
(void)current_fname(fs->tsdb, current_t, TSDB_FCURRENT_M); current_fname(fs->tsdb, current_t, TSDB_FCURRENT_M);
} }
(void)tsem_wait(&fs->canEdit); (void)tsem_wait(&fs->canEdit);
@ -860,7 +854,7 @@ _exit:
return code; return code;
} }
static int32_t tsdbFSSetBlockCommit(STFileSet *fset, bool block) { static void tsdbFSSetBlockCommit(STFileSet *fset, bool block) {
if (block) { if (block) {
fset->blockCommit = true; fset->blockCommit = true;
} else { } else {
@ -869,13 +863,12 @@ static int32_t tsdbFSSetBlockCommit(STFileSet *fset, bool block) {
(void)taosThreadCondSignal(&fset->canCommit); (void)taosThreadCondSignal(&fset->canCommit);
} }
} }
return 0;
} }
int32_t tsdbFSCheckCommit(STsdb *tsdb, int32_t fid) { int32_t tsdbFSCheckCommit(STsdb *tsdb, int32_t fid) {
(void)taosThreadMutexLock(&tsdb->mutex); (void)taosThreadMutexLock(&tsdb->mutex);
STFileSet *fset; STFileSet *fset;
(void)tsdbFSGetFSet(tsdb->pFS, fid, &fset); tsdbFSGetFSet(tsdb->pFS, fid, &fset);
if (fset) { if (fset) {
while (fset->blockCommit) { while (fset->blockCommit) {
fset->numWaitCommit++; fset->numWaitCommit++;
@ -902,13 +895,13 @@ int32_t tsdbFSEditCommit(STFileSystem *fs) {
STFileSet *fset; STFileSet *fset;
TARRAY2_FOREACH_REVERSE(fs->fSetArr, fset) { TARRAY2_FOREACH_REVERSE(fs->fSetArr, fset) {
if (TARRAY2_SIZE(fset->lvlArr) == 0) { if (TARRAY2_SIZE(fset->lvlArr) == 0) {
(void)tsdbFSSetBlockCommit(fset, false); tsdbFSSetBlockCommit(fset, false);
continue; continue;
} }
SSttLvl *lvl = TARRAY2_FIRST(fset->lvlArr); SSttLvl *lvl = TARRAY2_FIRST(fset->lvlArr);
if (lvl->level != 0) { if (lvl->level != 0) {
(void)tsdbFSSetBlockCommit(fset, false); tsdbFSSetBlockCommit(fset, false);
continue; continue;
} }
@ -933,9 +926,9 @@ int32_t tsdbFSEditCommit(STFileSystem *fs) {
} }
if (numFile >= sttTrigger * BLOCK_COMMIT_FACTOR) { if (numFile >= sttTrigger * BLOCK_COMMIT_FACTOR) {
(void)tsdbFSSetBlockCommit(fset, true); tsdbFSSetBlockCommit(fset, true);
} else { } else {
(void)tsdbFSSetBlockCommit(fset, false); tsdbFSSetBlockCommit(fset, false);
} }
} }
} }
@ -956,12 +949,11 @@ int32_t tsdbFSEditAbort(STFileSystem *fs) {
return code; return code;
} }
int32_t tsdbFSGetFSet(STFileSystem *fs, int32_t fid, STFileSet **fset) { void tsdbFSGetFSet(STFileSystem *fs, int32_t fid, STFileSet **fset) {
STFileSet tfset = {.fid = fid}; STFileSet tfset = {.fid = fid};
STFileSet *pset = &tfset; STFileSet *pset = &tfset;
STFileSet **fsetPtr = TARRAY2_SEARCH(fs->fSetArr, &pset, tsdbTFileSetCmprFn, TD_EQ); STFileSet **fsetPtr = TARRAY2_SEARCH(fs->fSetArr, &pset, tsdbTFileSetCmprFn, TD_EQ);
fset[0] = (fsetPtr == NULL) ? NULL : fsetPtr[0]; fset[0] = (fsetPtr == NULL) ? NULL : fsetPtr[0];
return 0;
} }
int32_t tsdbFSCreateCopySnapshot(STFileSystem *fs, TFileSetArray **fsetArr) { int32_t tsdbFSCreateCopySnapshot(STFileSystem *fs, TFileSetArray **fsetArr) {
@ -992,13 +984,12 @@ int32_t tsdbFSCreateCopySnapshot(STFileSystem *fs, TFileSetArray **fsetArr) {
return code; return code;
} }
int32_t tsdbFSDestroyCopySnapshot(TFileSetArray **fsetArr) { void tsdbFSDestroyCopySnapshot(TFileSetArray **fsetArr) {
if (fsetArr[0]) { if (fsetArr[0]) {
TARRAY2_DESTROY(fsetArr[0], tsdbTFileSetClear); TARRAY2_DESTROY(fsetArr[0], tsdbTFileSetClear);
taosMemoryFree(fsetArr[0]); taosMemoryFree(fsetArr[0]);
fsetArr[0] = NULL; fsetArr[0] = NULL;
} }
return 0;
} }
int32_t tsdbFSCreateRefSnapshot(STFileSystem *fs, TFileSetArray **fsetArr) { int32_t tsdbFSCreateRefSnapshot(STFileSystem *fs, TFileSetArray **fsetArr) {
@ -1034,13 +1025,12 @@ int32_t tsdbFSCreateRefSnapshotWithoutLock(STFileSystem *fs, TFileSetArray **fse
return code; return code;
} }
int32_t tsdbFSDestroyRefSnapshot(TFileSetArray **fsetArr) { void tsdbFSDestroyRefSnapshot(TFileSetArray **fsetArr) {
if (fsetArr[0]) { if (fsetArr[0]) {
TARRAY2_DESTROY(fsetArr[0], tsdbTFileSetClear); TARRAY2_DESTROY(fsetArr[0], tsdbTFileSetClear);
taosMemoryFreeClear(fsetArr[0]); taosMemoryFreeClear(fsetArr[0]);
fsetArr[0] = NULL; fsetArr[0] = NULL;
} }
return 0;
} }
static SHashObj *tsdbFSetRangeArrayToHash(TFileSetRangeArray *pRanges) { static SHashObj *tsdbFSetRangeArrayToHash(TFileSetRangeArray *pRanges) {
@ -1111,7 +1101,7 @@ _out:
return code; return code;
} }
int32_t tsdbFSDestroyCopyRangedSnapshot(TFileSetArray **fsetArr) { return tsdbFSDestroyCopySnapshot(fsetArr); } void tsdbFSDestroyCopyRangedSnapshot(TFileSetArray **fsetArr) { tsdbFSDestroyCopySnapshot(fsetArr); }
int32_t tsdbFSCreateRefRangedSnapshot(STFileSystem *fs, int64_t sver, int64_t ever, TFileSetRangeArray *pRanges, int32_t tsdbFSCreateRefRangedSnapshot(STFileSystem *fs, int64_t sver, int64_t ever, TFileSetRangeArray *pRanges,
TFileSetRangeArray **fsrArr) { TFileSetRangeArray **fsrArr) {
@ -1167,7 +1157,7 @@ int32_t tsdbFSCreateRefRangedSnapshot(STFileSystem *fs, int64_t sver, int64_t ev
(void)taosThreadMutexUnlock(&fs->tsdb->mutex); (void)taosThreadMutexUnlock(&fs->tsdb->mutex);
if (code) { if (code) {
(void)tsdbTFileSetRangeClear(&fsr1); tsdbTFileSetRangeClear(&fsr1);
TARRAY2_DESTROY(fsrArr[0], tsdbTFileSetRangeClear); TARRAY2_DESTROY(fsrArr[0], tsdbTFileSetRangeClear);
fsrArr[0] = NULL; fsrArr[0] = NULL;
} }
@ -1180,12 +1170,12 @@ _out:
return code; return code;
} }
int32_t tsdbFSDestroyRefRangedSnapshot(TFileSetRangeArray **fsrArr) { return tsdbTFileSetRangeArrayDestroy(fsrArr); } void tsdbFSDestroyRefRangedSnapshot(TFileSetRangeArray **fsrArr) { tsdbTFileSetRangeArrayDestroy(fsrArr); }
int32_t tsdbBeginTaskOnFileSet(STsdb *tsdb, int32_t fid, STFileSet **fset) { void tsdbBeginTaskOnFileSet(STsdb *tsdb, int32_t fid, STFileSet **fset) {
int16_t sttTrigger = tsdb->pVnode->config.sttTrigger; int16_t sttTrigger = tsdb->pVnode->config.sttTrigger;
(void)tsdbFSGetFSet(tsdb->pFS, fid, fset); tsdbFSGetFSet(tsdb->pFS, fid, fset);
if (sttTrigger == 1 && (*fset)) { if (sttTrigger == 1 && (*fset)) {
for (;;) { for (;;) {
if ((*fset)->taskRunning) { if ((*fset)->taskRunning) {
@ -1193,7 +1183,7 @@ int32_t tsdbBeginTaskOnFileSet(STsdb *tsdb, int32_t fid, STFileSet **fset) {
(void)taosThreadCondWait(&(*fset)->beginTask, &tsdb->mutex); (void)taosThreadCondWait(&(*fset)->beginTask, &tsdb->mutex);
(void)tsdbFSGetFSet(tsdb->pFS, fid, fset); tsdbFSGetFSet(tsdb->pFS, fid, fset);
(*fset)->numWaitTask--; (*fset)->numWaitTask--;
} else { } else {
@ -1203,15 +1193,13 @@ int32_t tsdbBeginTaskOnFileSet(STsdb *tsdb, int32_t fid, STFileSet **fset) {
} }
tsdbInfo("vgId:%d begin task on file set:%d", TD_VID(tsdb->pVnode), fid); tsdbInfo("vgId:%d begin task on file set:%d", TD_VID(tsdb->pVnode), fid);
} }
return 0;
} }
int32_t tsdbFinishTaskOnFileSet(STsdb *tsdb, int32_t fid) { void tsdbFinishTaskOnFileSet(STsdb *tsdb, int32_t fid) {
int16_t sttTrigger = tsdb->pVnode->config.sttTrigger; int16_t sttTrigger = tsdb->pVnode->config.sttTrigger;
if (sttTrigger == 1) { if (sttTrigger == 1) {
STFileSet *fset = NULL; STFileSet *fset = NULL;
(void)tsdbFSGetFSet(tsdb->pFS, fid, &fset); tsdbFSGetFSet(tsdb->pFS, fid, &fset);
if (fset != NULL && fset->taskRunning) { if (fset != NULL && fset->taskRunning) {
fset->taskRunning = false; fset->taskRunning = false;
if (fset->numWaitTask > 0) { if (fset->numWaitTask > 0) {
@ -1220,6 +1208,4 @@ int32_t tsdbFinishTaskOnFileSet(STsdb *tsdb, int32_t fid) {
tsdbInfo("vgId:%d finish task on file set:%d", TD_VID(tsdb->pVnode), fid); tsdbInfo("vgId:%d finish task on file set:%d", TD_VID(tsdb->pVnode), fid);
} }
} }
return 0;
} }

View File

@ -38,20 +38,20 @@ typedef enum {
/* Exposed APIs */ /* Exposed APIs */
// open/close // open/close
int32_t tsdbOpenFS(STsdb *pTsdb, STFileSystem **fs, int8_t rollback); int32_t tsdbOpenFS(STsdb *pTsdb, STFileSystem **fs, int8_t rollback);
int32_t tsdbCloseFS(STFileSystem **fs); void tsdbCloseFS(STFileSystem **fs);
// snapshot // snapshot
int32_t tsdbFSCreateCopySnapshot(STFileSystem *fs, TFileSetArray **fsetArr); int32_t tsdbFSCreateCopySnapshot(STFileSystem *fs, TFileSetArray **fsetArr);
int32_t tsdbFSDestroyCopySnapshot(TFileSetArray **fsetArr); void tsdbFSDestroyCopySnapshot(TFileSetArray **fsetArr);
int32_t tsdbFSCreateRefSnapshot(STFileSystem *fs, TFileSetArray **fsetArr); int32_t tsdbFSCreateRefSnapshot(STFileSystem *fs, TFileSetArray **fsetArr);
int32_t tsdbFSCreateRefSnapshotWithoutLock(STFileSystem *fs, TFileSetArray **fsetArr); int32_t tsdbFSCreateRefSnapshotWithoutLock(STFileSystem *fs, TFileSetArray **fsetArr);
int32_t tsdbFSDestroyRefSnapshot(TFileSetArray **fsetArr); void tsdbFSDestroyRefSnapshot(TFileSetArray **fsetArr);
int32_t tsdbFSCreateCopyRangedSnapshot(STFileSystem *fs, TFileSetRangeArray *pExclude, TFileSetArray **fsetArr, int32_t tsdbFSCreateCopyRangedSnapshot(STFileSystem *fs, TFileSetRangeArray *pExclude, TFileSetArray **fsetArr,
TFileOpArray *fopArr); TFileOpArray *fopArr);
int32_t tsdbFSDestroyCopyRangedSnapshot(TFileSetArray **fsetArr); void tsdbFSDestroyCopyRangedSnapshot(TFileSetArray **fsetArr);
int32_t tsdbFSCreateRefRangedSnapshot(STFileSystem *fs, int64_t sver, int64_t ever, TFileSetRangeArray *pRanges, int32_t tsdbFSCreateRefRangedSnapshot(STFileSystem *fs, int64_t sver, int64_t ever, TFileSetRangeArray *pRanges,
TFileSetRangeArray **fsrArr); TFileSetRangeArray **fsrArr);
int32_t tsdbFSDestroyRefRangedSnapshot(TFileSetRangeArray **fsrArr); void tsdbFSDestroyRefRangedSnapshot(TFileSetRangeArray **fsrArr);
// txn // txn
int64_t tsdbFSAllocEid(STFileSystem *fs); int64_t tsdbFSAllocEid(STFileSystem *fs);
void tsdbFSUpdateEid(STFileSystem *fs, int64_t cid); void tsdbFSUpdateEid(STFileSystem *fs, int64_t cid);
@ -59,13 +59,13 @@ int32_t tsdbFSEditBegin(STFileSystem *fs, const TFileOpArray *opArray, EFEditT e
int32_t tsdbFSEditCommit(STFileSystem *fs); int32_t tsdbFSEditCommit(STFileSystem *fs);
int32_t tsdbFSEditAbort(STFileSystem *fs); int32_t tsdbFSEditAbort(STFileSystem *fs);
// other // other
int32_t tsdbFSGetFSet(STFileSystem *fs, int32_t fid, STFileSet **fset); void tsdbFSGetFSet(STFileSystem *fs, int32_t fid, STFileSet **fset);
int32_t tsdbFSCheckCommit(STsdb *tsdb, int32_t fid); int32_t tsdbFSCheckCommit(STsdb *tsdb, int32_t fid);
int32_t tsdbBeginTaskOnFileSet(STsdb *tsdb, int32_t fid, STFileSet **fset); void tsdbBeginTaskOnFileSet(STsdb *tsdb, int32_t fid, STFileSet **fset);
int32_t tsdbFinishTaskOnFileSet(STsdb *tsdb, int32_t fid); void tsdbFinishTaskOnFileSet(STsdb *tsdb, int32_t fid);
// utils // utils
int32_t save_fs(const TFileSetArray *arr, const char *fname); int32_t save_fs(const TFileSetArray *arr, const char *fname);
int32_t current_fname(STsdb *pTsdb, char *fname, EFCurrentT ftype); void current_fname(STsdb *pTsdb, char *fname, EFCurrentT ftype);
/* Exposed Structs */ /* Exposed Structs */
struct STFileSystem { struct STFileSystem {

View File

@ -27,13 +27,12 @@ int32_t tsdbSttLvlInit(int32_t level, SSttLvl **lvl) {
static void tsdbSttLvlClearFObj(void *data) { TAOS_UNUSED(tsdbTFileObjUnref(*(STFileObj **)data)); } static void tsdbSttLvlClearFObj(void *data) { TAOS_UNUSED(tsdbTFileObjUnref(*(STFileObj **)data)); }
int32_t tsdbSttLvlClear(SSttLvl **lvl) { void tsdbSttLvlClear(SSttLvl **lvl) {
if (lvl[0] != NULL) { if (lvl[0] != NULL) {
TARRAY2_DESTROY(lvl[0]->fobjArr, tsdbSttLvlClearFObj); TARRAY2_DESTROY(lvl[0]->fobjArr, tsdbSttLvlClearFObj);
taosMemoryFree(lvl[0]); taosMemoryFree(lvl[0]);
lvl[0] = NULL; lvl[0] = NULL;
} }
return 0;
} }
static int32_t tsdbSttLvlInitEx(STsdb *pTsdb, const SSttLvl *lvl1, SSttLvl **lvl) { static int32_t tsdbSttLvlInitEx(STsdb *pTsdb, const SSttLvl *lvl1, SSttLvl **lvl) {
@ -45,12 +44,16 @@ static int32_t tsdbSttLvlInitEx(STsdb *pTsdb, const SSttLvl *lvl1, SSttLvl **lvl
STFileObj *fobj; STFileObj *fobj;
code = tsdbTFileObjInit(pTsdb, fobj1->f, &fobj); code = tsdbTFileObjInit(pTsdb, fobj1->f, &fobj);
if (code) { if (code) {
(void)tsdbSttLvlClear(lvl); tsdbSttLvlClear(lvl);
return code; return code;
} }
code = TARRAY2_APPEND(lvl[0]->fobjArr, fobj); code = TARRAY2_APPEND(lvl[0]->fobjArr, fobj);
if (code) return code; if (code) {
tsdbSttLvlClear(lvl);
taosMemoryFree(fobj);
return code;
}
} }
return 0; return 0;
} }
@ -61,9 +64,16 @@ static int32_t tsdbSttLvlInitRef(STsdb *pTsdb, const SSttLvl *lvl1, SSttLvl **lv
STFileObj *fobj1; STFileObj *fobj1;
TARRAY2_FOREACH(lvl1->fobjArr, fobj1) { TARRAY2_FOREACH(lvl1->fobjArr, fobj1) {
(void)tsdbTFileObjRef(fobj1); code = tsdbTFileObjRef(fobj1);
if (code) {
tsdbSttLvlClear(lvl);
return code;
}
code = TARRAY2_APPEND(lvl[0]->fobjArr, fobj1); code = TARRAY2_APPEND(lvl[0]->fobjArr, fobj1);
if (code) return code; if (code) {
tsdbSttLvlClear(lvl);
return code;
}
} }
return 0; return 0;
} }
@ -79,7 +89,7 @@ static int32_t tsdbSttLvlFilteredInitEx(STsdb *pTsdb, const SSttLvl *lvl1, int64
STFileObj *fobj; STFileObj *fobj;
code = tsdbTFileObjInit(pTsdb, fobj1->f, &fobj); code = tsdbTFileObjInit(pTsdb, fobj1->f, &fobj);
if (code) { if (code) {
(void)tsdbSttLvlClear(lvl); tsdbSttLvlClear(lvl);
return code; return code;
} }
@ -96,7 +106,12 @@ static int32_t tsdbSttLvlFilteredInitEx(STsdb *pTsdb, const SSttLvl *lvl1, int64
return 0; return 0;
} }
static void tsdbSttLvlRemoveFObj(void *data) { (void)tsdbTFileObjRemove(*(STFileObj **)data); } static void tsdbSttLvlRemoveFObj(void *data) {
int32_t code = tsdbTFileObjRemove(*(STFileObj **)data);
if (code) {
tsdbError("failed to remove file obj, code:%d, error:%s", code, tstrerror(code));
}
}
static void tsdbSttLvlRemove(SSttLvl **lvl) { static void tsdbSttLvlRemove(SSttLvl **lvl) {
TARRAY2_DESTROY(lvl[0]->fobjArr, tsdbSttLvlRemoveFObj); TARRAY2_DESTROY(lvl[0]->fobjArr, tsdbSttLvlRemoveFObj);
taosMemoryFree(lvl[0]); taosMemoryFree(lvl[0]);
@ -200,7 +215,7 @@ static int32_t tsdbJsonToSttLvl(STsdb *pTsdb, const cJSON *json, SSttLvl **lvl)
item1 = cJSON_GetObjectItem(json, "files"); item1 = cJSON_GetObjectItem(json, "files");
if (!cJSON_IsArray(item1)) { if (!cJSON_IsArray(item1)) {
(void)tsdbSttLvlClear(lvl); tsdbSttLvlClear(lvl);
return TSDB_CODE_FILE_CORRUPTED; return TSDB_CODE_FILE_CORRUPTED;
} }
@ -208,14 +223,14 @@ static int32_t tsdbJsonToSttLvl(STsdb *pTsdb, const cJSON *json, SSttLvl **lvl)
STFile tf; STFile tf;
code = tsdbJsonToTFile(item2, TSDB_FTYPE_STT, &tf); code = tsdbJsonToTFile(item2, TSDB_FTYPE_STT, &tf);
if (code) { if (code) {
(void)tsdbSttLvlClear(lvl); tsdbSttLvlClear(lvl);
return code; return code;
} }
STFileObj *fobj; STFileObj *fobj;
code = tsdbTFileObjInit(pTsdb, &tf, &fobj); code = tsdbTFileObjInit(pTsdb, &tf, &fobj);
if (code) { if (code) {
(void)tsdbSttLvlClear(lvl); tsdbSttLvlClear(lvl);
return code; return code;
} }
@ -345,7 +360,8 @@ int32_t tsdbTFileSetEdit(STsdb *pTsdb, STFileSet *fset, const STFileOp *op) {
int32_t idx = TARRAY2_SEARCH_IDX(lvl->fobjArr, &tfobjp, tsdbTFileObjCmpr, TD_EQ); int32_t idx = TARRAY2_SEARCH_IDX(lvl->fobjArr, &tfobjp, tsdbTFileObjCmpr, TD_EQ);
TARRAY2_REMOVE(lvl->fobjArr, idx, tsdbSttLvlClearFObj); TARRAY2_REMOVE(lvl->fobjArr, idx, tsdbSttLvlClearFObj);
} else { } else {
(void)tsdbTFileObjUnref(fset->farr[op->of.type]); code = tsdbTFileObjUnref(fset->farr[op->of.type]);
if (code) return code;
fset->farr[op->of.type] = NULL; fset->farr[op->of.type] = NULL;
} }
} else { } else {
@ -388,9 +404,11 @@ int32_t tsdbTFileSetApplyEdit(STsdb *pTsdb, const STFileSet *fset1, STFileSet *f
} }
} else { } else {
if (fobj1->f->cid != fobj2->f->cid) { if (fobj1->f->cid != fobj2->f->cid) {
(void)tsdbTFileObjRemove(fobj2); code = tsdbTFileObjRemove(fobj2);
if (code) return code;
} else { } else {
(void)tsdbTFileObjRemoveUpdateLC(fobj2); code = tsdbTFileObjRemoveUpdateLC(fobj2);
if (code) return code;
} }
code = tsdbTFileObjInit(pTsdb, fobj1->f, &fset2->farr[ftype]); code = tsdbTFileObjInit(pTsdb, fobj1->f, &fset2->farr[ftype]);
if (code) return code; if (code) return code;
@ -401,7 +419,8 @@ int32_t tsdbTFileSetApplyEdit(STsdb *pTsdb, const STFileSet *fset1, STFileSet *f
if (code) return code; if (code) return code;
} else { } else {
// remove the file // remove the file
(void)tsdbTFileObjRemove(fobj2); code = tsdbTFileObjRemove(fobj2);
if (code) return code;
fset2->farr[ftype] = NULL; fset2->farr[ftype] = NULL;
} }
} }
@ -567,7 +586,11 @@ int32_t tsdbTFileSetInitRef(STsdb *pTsdb, const STFileSet *fset1, STFileSet **fs
for (int32_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) { for (int32_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) {
if (fset1->farr[ftype] == NULL) continue; if (fset1->farr[ftype] == NULL) continue;
(void)tsdbTFileObjRef(fset1->farr[ftype]); code = tsdbTFileObjRef(fset1->farr[ftype]);
if (code) {
tsdbTFileSetClear(fset);
return code;
}
fset[0]->farr[ftype] = fset1->farr[ftype]; fset[0]->farr[ftype] = fset1->farr[ftype];
} }
@ -592,29 +615,32 @@ int32_t tsdbTFileSetInitRef(STsdb *pTsdb, const STFileSet *fset1, STFileSet **fs
return 0; return 0;
} }
int32_t tsdbTFileSetRangeClear(STFileSetRange **fsr) { void tsdbTFileSetRangeClear(STFileSetRange **fsr) {
if (!fsr[0]) return 0; if (!fsr[0]) return;
tsdbTFileSetClear(&fsr[0]->fset); tsdbTFileSetClear(&fsr[0]->fset);
taosMemoryFree(fsr[0]); taosMemoryFree(fsr[0]);
fsr[0] = NULL; fsr[0] = NULL;
return 0; return;
} }
int32_t tsdbTFileSetRangeArrayDestroy(TFileSetRangeArray **ppArr) { void tsdbTFileSetRangeArrayDestroy(TFileSetRangeArray **ppArr) {
if (ppArr && ppArr[0]) { if (ppArr && ppArr[0]) {
TARRAY2_DESTROY(ppArr[0], tsdbTFileSetRangeClear); TARRAY2_DESTROY(ppArr[0], tsdbTFileSetRangeClear);
taosMemoryFree(ppArr[0]); taosMemoryFree(ppArr[0]);
ppArr[0] = NULL; ppArr[0] = NULL;
} }
return 0;
} }
void tsdbTFileSetClear(STFileSet **fset) { void tsdbTFileSetClear(STFileSet **fset) {
if (fset && *fset) { if (fset && *fset) {
for (tsdb_ftype_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) { for (tsdb_ftype_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) {
if ((*fset)->farr[ftype] == NULL) continue; if ((*fset)->farr[ftype] == NULL) continue;
(void)tsdbTFileObjUnref((*fset)->farr[ftype]); int32_t code = tsdbTFileObjUnref((*fset)->farr[ftype]);
if (code) {
tsdbError("failed to unref file, fid:%d, ftype:%d", (*fset)->fid, ftype);
}
(*fset)->farr[ftype] = NULL;
} }
TARRAY2_DESTROY((*fset)->lvlArr, tsdbSttLvlClear); TARRAY2_DESTROY((*fset)->lvlArr, tsdbSttLvlClear);
@ -625,19 +651,20 @@ void tsdbTFileSetClear(STFileSet **fset) {
} }
} }
int32_t tsdbTFileSetRemove(STFileSet *fset) { void tsdbTFileSetRemove(STFileSet *fset) {
if (fset == NULL) return 0; if (fset == NULL) return;
for (tsdb_ftype_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) { for (tsdb_ftype_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) {
if (fset->farr[ftype] != NULL) { if (fset->farr[ftype] != NULL) {
(void)tsdbTFileObjRemove(fset->farr[ftype]); int32_t code = tsdbTFileObjRemove(fset->farr[ftype]);
if (code) {
tsdbError("failed to remove file, fid:%d, ftype:%d", fset->fid, ftype);
}
fset->farr[ftype] = NULL; fset->farr[ftype] = NULL;
} }
} }
TARRAY2_DESTROY(fset->lvlArr, tsdbSttLvlRemove); TARRAY2_DESTROY(fset->lvlArr, tsdbSttLvlRemove);
return 0;
} }
SSttLvl *tsdbTFileSetGetSttLvl(STFileSet *fset, int32_t level) { SSttLvl *tsdbTFileSetGetSttLvl(STFileSet *fset, int32_t level) {

View File

@ -43,7 +43,7 @@ int32_t tsdbTFileSetInit(int32_t fid, STFileSet **fset);
int32_t tsdbTFileSetInitCopy(STsdb *pTsdb, const STFileSet *fset1, STFileSet **fset); int32_t tsdbTFileSetInitCopy(STsdb *pTsdb, const STFileSet *fset1, STFileSet **fset);
int32_t tsdbTFileSetInitRef(STsdb *pTsdb, const STFileSet *fset1, STFileSet **fset); int32_t tsdbTFileSetInitRef(STsdb *pTsdb, const STFileSet *fset1, STFileSet **fset);
void tsdbTFileSetClear(STFileSet **fset); void tsdbTFileSetClear(STFileSet **fset);
int32_t tsdbTFileSetRemove(STFileSet *fset); void tsdbTFileSetRemove(STFileSet *fset);
int32_t tsdbTFileSetFilteredInitDup(STsdb *pTsdb, const STFileSet *fset1, int64_t ever, STFileSet **fset, int32_t tsdbTFileSetFilteredInitDup(STsdb *pTsdb, const STFileSet *fset1, int64_t ever, STFileSet **fset,
TFileOpArray *fopArr); TFileOpArray *fopArr);
@ -57,7 +57,6 @@ int32_t tsdbJsonToTFileSet(STsdb *pTsdb, const cJSON *json, STFileSet **fset);
// cmpr // cmpr
int32_t tsdbTFileSetCmprFn(const STFileSet **fset1, const STFileSet **fset2); int32_t tsdbTFileSetCmprFn(const STFileSet **fset1, const STFileSet **fset2);
// edit // edit
int32_t tsdbSttLvlClear(SSttLvl **lvl);
int32_t tsdbTFileSetEdit(STsdb *pTsdb, STFileSet *fset, const STFileOp *op); int32_t tsdbTFileSetEdit(STsdb *pTsdb, STFileSet *fset, const STFileOp *op);
int32_t tsdbTFileSetApplyEdit(STsdb *pTsdb, const STFileSet *fset1, STFileSet *fset); int32_t tsdbTFileSetApplyEdit(STsdb *pTsdb, const STFileSet *fset1, STFileSet *fset);
// max commit id // max commit id
@ -68,7 +67,7 @@ SSttLvl *tsdbTFileSetGetSttLvl(STFileSet *fset, int32_t level);
bool tsdbTFileSetIsEmpty(const STFileSet *fset); bool tsdbTFileSetIsEmpty(const STFileSet *fset);
// stt // stt
int32_t tsdbSttLvlInit(int32_t level, SSttLvl **lvl); int32_t tsdbSttLvlInit(int32_t level, SSttLvl **lvl);
int32_t tsdbSttLvlClear(SSttLvl **lvl); void tsdbSttLvlClear(SSttLvl **lvl);
// open channel // open channel
int32_t tsdbTFileSetOpenChannel(STFileSet *fset); int32_t tsdbTFileSetOpenChannel(STFileSet *fset);

View File

@ -221,7 +221,7 @@ void tsdbDelFileName(STsdb *pTsdb, SDelFile *pFile, char fname[]) {
int32_t offset = 0; int32_t offset = 0;
SVnode *pVnode = pTsdb->pVnode; SVnode *pVnode = pTsdb->pVnode;
(void)vnodeGetPrimaryDir(pTsdb->path, pVnode->diskPrimary, pVnode->pTfs, fname, TSDB_FILENAME_LEN); vnodeGetPrimaryDir(pTsdb->path, pVnode->diskPrimary, pVnode->pTfs, fname, TSDB_FILENAME_LEN);
offset = strlen(fname); offset = strlen(fname);
snprintf((char *)fname + offset, TSDB_FILENAME_LEN - offset - 1, "%sv%dver%" PRId64 ".del", TD_DIRSEP, snprintf((char *)fname + offset, TSDB_FILENAME_LEN - offset - 1, "%sv%dver%" PRId64 ".del", TD_DIRSEP,
TD_VID(pTsdb->pVnode), pFile->commitID); TD_VID(pTsdb->pVnode), pFile->commitID);

View File

@ -43,9 +43,13 @@ static const struct {
[TSDB_FTYPE_STT] = {"stt", stt_to_json, stt_from_json}, [TSDB_FTYPE_STT] = {"stt", stt_to_json, stt_from_json},
}; };
void remove_file(const char *fname) { void tsdbRemoveFile(const char *fname) {
(void)taosRemoveFile(fname); int32_t code = taosRemoveFile(fname);
tsdbInfo("file:%s is removed", fname); if (code) {
tsdbError("failed to remove file:%s, code:%d, error:%s", fname, code, tstrerror(code));
} else {
tsdbInfo("file:%s is removed", fname);
}
} }
static int32_t tfile_to_json(const STFile *file, cJSON *json) { static int32_t tfile_to_json(const STFile *file, cJSON *json) {
@ -234,7 +238,7 @@ int32_t tsdbTFileObjInit(STsdb *pTsdb, const STFile *f, STFileObj **fobj) {
fobj[0]->f[0] = f[0]; fobj[0]->f[0] = f[0];
fobj[0]->state = TSDB_FSTATE_LIVE; fobj[0]->state = TSDB_FSTATE_LIVE;
fobj[0]->ref = 1; fobj[0]->ref = 1;
(void)tsdbTFileName(pTsdb, f, fobj[0]->fname); tsdbTFileName(pTsdb, f, fobj[0]->fname);
// fobj[0]->nlevel = tfsGetLevel(pTsdb->pVnode->pTfs); // fobj[0]->nlevel = tfsGetLevel(pTsdb->pVnode->pTfs);
fobj[0]->nlevel = vnodeNodeId(pTsdb->pVnode); fobj[0]->nlevel = vnodeNodeId(pTsdb->pVnode);
return 0; return 0;
@ -245,8 +249,8 @@ int32_t tsdbTFileObjRef(STFileObj *fobj) {
(void)taosThreadMutexLock(&fobj->mutex); (void)taosThreadMutexLock(&fobj->mutex);
if (fobj->ref <= 0 || fobj->state != TSDB_FSTATE_LIVE) { if (fobj->ref <= 0 || fobj->state != TSDB_FSTATE_LIVE) {
(void)taosThreadMutexUnlock(&fobj->mutex);
tsdbError("file %s, fobj:%p ref %d", fobj->fname, fobj, fobj->ref); tsdbError("file %s, fobj:%p ref %d", fobj->fname, fobj, fobj->ref);
(void)taosThreadMutexUnlock(&fobj->mutex);
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
@ -269,7 +273,7 @@ int32_t tsdbTFileObjUnref(STFileObj *fobj) {
tsdbTrace("unref file %s, fobj:%p ref %d", fobj->fname, fobj, nRef); tsdbTrace("unref file %s, fobj:%p ref %d", fobj->fname, fobj, nRef);
if (nRef == 0) { if (nRef == 0) {
if (fobj->state == TSDB_FSTATE_DEAD) { if (fobj->state == TSDB_FSTATE_DEAD) {
remove_file(fobj->fname); tsdbRemoveFile(fobj->fname);
} }
taosMemoryFree(fobj); taosMemoryFree(fobj);
} }
@ -279,7 +283,7 @@ int32_t tsdbTFileObjUnref(STFileObj *fobj) {
static void tsdbTFileObjRemoveLC(STFileObj *fobj, bool remove_all) { static void tsdbTFileObjRemoveLC(STFileObj *fobj, bool remove_all) {
if (fobj->f->type != TSDB_FTYPE_DATA || fobj->f->lcn < 1) { if (fobj->f->type != TSDB_FTYPE_DATA || fobj->f->lcn < 1) {
remove_file(fobj->fname); tsdbRemoveFile(fobj->fname);
return; return;
} }
@ -295,7 +299,7 @@ static void tsdbTFileObjRemoveLC(STFileObj *fobj, bool remove_all) {
} }
snprintf(dot + 1, TSDB_FQDN_LEN - (dot + 1 - lc_path), "%d.data", fobj->f->lcn); snprintf(dot + 1, TSDB_FQDN_LEN - (dot + 1 - lc_path), "%d.data", fobj->f->lcn);
remove_file(lc_path); tsdbRemoveFile(lc_path);
} else { } else {
// delete by data file prefix // delete by data file prefix
@ -324,15 +328,15 @@ static void tsdbTFileObjRemoveLC(STFileObj *fobj, bool remove_all) {
} }
snprintf(dot + 1, TSDB_FQDN_LEN - (dot + 1 - lc_path), "%d.data", fobj->f->lcn); snprintf(dot + 1, TSDB_FQDN_LEN - (dot + 1 - lc_path), "%d.data", fobj->f->lcn);
remove_file(lc_path); tsdbRemoveFile(lc_path);
} }
} }
int32_t tsdbTFileObjRemove(STFileObj *fobj) { int32_t tsdbTFileObjRemove(STFileObj *fobj) {
(void)taosThreadMutexLock(&fobj->mutex); (void)taosThreadMutexLock(&fobj->mutex);
if (fobj->state != TSDB_FSTATE_LIVE || fobj->ref <= 0) { if (fobj->state != TSDB_FSTATE_LIVE || fobj->ref <= 0) {
(void)taosThreadMutexUnlock(&fobj->mutex);
tsdbError("file %s, fobj:%p ref %d", fobj->fname, fobj, fobj->ref); tsdbError("file %s, fobj:%p ref %d", fobj->fname, fobj, fobj->ref);
(void)taosThreadMutexUnlock(&fobj->mutex);
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
fobj->state = TSDB_FSTATE_DEAD; fobj->state = TSDB_FSTATE_DEAD;
@ -366,7 +370,7 @@ int32_t tsdbTFileObjRemoveUpdateLC(STFileObj *fobj) {
return 0; return 0;
} }
int32_t tsdbTFileName(STsdb *pTsdb, const STFile *f, char fname[]) { void tsdbTFileName(STsdb *pTsdb, const STFile *f, char fname[]) {
SVnode *pVnode = pTsdb->pVnode; SVnode *pVnode = pTsdb->pVnode;
STfs *pTfs = pVnode->pTfs; STfs *pTfs = pVnode->pTfs;
@ -393,10 +397,9 @@ int32_t tsdbTFileName(STsdb *pTsdb, const STFile *f, char fname[]) {
f->cid, // f->cid, //
g_tfile_info[f->type].suffix); g_tfile_info[f->type].suffix);
} }
return 0;
} }
int32_t tsdbTFileLastChunkName(STsdb *pTsdb, const STFile *f, char fname[]) { void tsdbTFileLastChunkName(STsdb *pTsdb, const STFile *f, char fname[]) {
SVnode *pVnode = pTsdb->pVnode; SVnode *pVnode = pTsdb->pVnode;
STfs *pTfs = pVnode->pTfs; STfs *pTfs = pVnode->pTfs;
@ -425,7 +428,6 @@ int32_t tsdbTFileLastChunkName(STsdb *pTsdb, const STFile *f, char fname[]) {
f->lcn, // f->lcn, //
g_tfile_info[f->type].suffix); g_tfile_info[f->type].suffix);
} }
return 0;
} }
bool tsdbIsSameTFile(const STFile *f1, const STFile *f2) { bool tsdbIsSameTFile(const STFile *f1, const STFile *f2) {

View File

@ -44,8 +44,8 @@ enum {
// STFile // STFile
int32_t tsdbTFileToJson(const STFile *f, cJSON *json); int32_t tsdbTFileToJson(const STFile *f, cJSON *json);
int32_t tsdbJsonToTFile(const cJSON *json, tsdb_ftype_t ftype, STFile *f); int32_t tsdbJsonToTFile(const cJSON *json, tsdb_ftype_t ftype, STFile *f);
int32_t tsdbTFileName(STsdb *pTsdb, const STFile *f, char fname[]); void tsdbTFileName(STsdb *pTsdb, const STFile *f, char fname[]);
int32_t tsdbTFileLastChunkName(STsdb *pTsdb, const STFile *f, char fname[]); void tsdbTFileLastChunkName(STsdb *pTsdb, const STFile *f, char fname[]);
bool tsdbIsSameTFile(const STFile *f1, const STFile *f2); bool tsdbIsSameTFile(const STFile *f1, const STFile *f2);
bool tsdbIsTFileChanged(const STFile *f1, const STFile *f2); bool tsdbIsTFileChanged(const STFile *f1, const STFile *f2);

View File

@ -153,7 +153,8 @@ static int32_t tsdbDataIterNext(STsdbIter *iter, const TABLEID *tbid) {
for (; iter->dataData->brinBlockIdx < iter->dataData->brinBlock->numOfRecords; iter->dataData->brinBlockIdx++) { for (; iter->dataData->brinBlockIdx < iter->dataData->brinBlock->numOfRecords; iter->dataData->brinBlockIdx++) {
SBrinRecord record[1]; SBrinRecord record[1];
(void)tBrinBlockGet(iter->dataData->brinBlock, iter->dataData->brinBlockIdx, record); code = tBrinBlockGet(iter->dataData->brinBlock, iter->dataData->brinBlockIdx, record);
if (code) return code;
if (iter->filterByVersion && (record->maxVer < iter->range[0] || record->minVer > iter->range[1])) { if (iter->filterByVersion && (record->maxVer < iter->range[0] || record->minVer > iter->range[1])) {
continue; continue;
@ -224,7 +225,7 @@ static int32_t tsdbMemTableIterNext(STsdbIter *iter, const TABLEID *tbid) {
iter->row->row = row[0]; iter->row->row = row[0];
(void)tsdbTbDataIterNext(iter->memtData->tbIter); TAOS_UNUSED(tsdbTbDataIterNext(iter->memtData->tbIter));
goto _exit; goto _exit;
} }
@ -373,7 +374,8 @@ static int32_t tsdbDataIterOpen(STsdbIter *iter) {
iter->dataData->brinBlkArrayIdx = 0; iter->dataData->brinBlkArrayIdx = 0;
// SBrinBlock // SBrinBlock
(void)tBrinBlockInit(iter->dataData->brinBlock); code = tBrinBlockInit(iter->dataData->brinBlock);
if (code) return code;
iter->dataData->brinBlockIdx = 0; iter->dataData->brinBlockIdx = 0;
// SBlockData // SBlockData
@ -430,7 +432,7 @@ static int32_t tsdbMemTombIterOpen(STsdbIter *iter) {
} }
static int32_t tsdbDataIterClose(STsdbIter *iter) { static int32_t tsdbDataIterClose(STsdbIter *iter) {
(void)tBrinBlockDestroy(iter->dataData->brinBlock); tBrinBlockDestroy(iter->dataData->brinBlock);
tBlockDataDestroy(iter->dataData->blockData); tBlockDataDestroy(iter->dataData->blockData);
return 0; return 0;
} }
@ -699,12 +701,11 @@ int32_t tsdbIterMergerOpen(const TTsdbIterArray *iterArray, SIterMerger **merger
return tsdbIterMergerNext(merger[0]); return tsdbIterMergerNext(merger[0]);
} }
int32_t tsdbIterMergerClose(SIterMerger **merger) { void tsdbIterMergerClose(SIterMerger **merger) {
if (merger[0]) { if (merger[0]) {
taosMemoryFree(merger[0]); taosMemoryFree(merger[0]);
merger[0] = NULL; merger[0] = NULL;
} }
return 0;
} }
int32_t tsdbIterMergerNext(SIterMerger *merger) { int32_t tsdbIterMergerNext(SIterMerger *merger) {

View File

@ -59,7 +59,7 @@ int32_t tsdbIterNext(STsdbIter *iter);
// SIterMerger =============== // SIterMerger ===============
int32_t tsdbIterMergerOpen(const TTsdbIterArray *iterArray, SIterMerger **merger, bool isTomb); int32_t tsdbIterMergerOpen(const TTsdbIterArray *iterArray, SIterMerger **merger, bool isTomb);
int32_t tsdbIterMergerClose(SIterMerger **merger); void tsdbIterMergerClose(SIterMerger **merger);
int32_t tsdbIterMergerNext(SIterMerger *merger); int32_t tsdbIterMergerNext(SIterMerger *merger);
int32_t tsdbIterMergerSkipTableData(SIterMerger *merger, const TABLEID *tbid); int32_t tsdbIterMergerSkipTableData(SIterMerger *merger, const TABLEID *tbid);

View File

@ -403,7 +403,11 @@ static int32_t tsdbGetOrCreateTbData(SMemTable *pMemTable, tb_uid_t suid, tb_uid
pMemTable->aBucket[idx] = pTbData; pMemTable->aBucket[idx] = pTbData;
pMemTable->nTbData++; pMemTable->nTbData++;
(void)tRBTreePut(pMemTable->tbDataTree, pTbData->rbtn); if (tRBTreePut(pMemTable->tbDataTree, pTbData->rbtn) == NULL) {
taosWUnLockLatch(&pMemTable->latch);
code = TSDB_CODE_INTERNAL_ERROR;
goto _exit;
}
taosWUnLockLatch(&pMemTable->latch); taosWUnLockLatch(&pMemTable->latch);
@ -731,15 +735,13 @@ int32_t tsdbRefMemTable(SMemTable *pMemTable, SQueryNode *pQNode) {
tsdbError("vgId:%d, memtable ref count is invalid, ref:%d", TD_VID(pMemTable->pTsdb->pVnode), nRef); tsdbError("vgId:%d, memtable ref count is invalid, ref:%d", TD_VID(pMemTable->pTsdb->pVnode), nRef);
} }
(void)vnodeBufPoolRegisterQuery(pMemTable->pPool, pQNode); vnodeBufPoolRegisterQuery(pMemTable->pPool, pQNode);
_exit: _exit:
return code; return code;
} }
int32_t tsdbUnrefMemTable(SMemTable *pMemTable, SQueryNode *pNode, bool proactive) { void tsdbUnrefMemTable(SMemTable *pMemTable, SQueryNode *pNode, bool proactive) {
int32_t code = 0;
if (pNode) { if (pNode) {
vnodeBufPoolDeregisterQuery(pMemTable->pPool, pNode, proactive); vnodeBufPoolDeregisterQuery(pMemTable->pPool, pNode, proactive);
} }
@ -747,8 +749,6 @@ int32_t tsdbUnrefMemTable(SMemTable *pMemTable, SQueryNode *pNode, bool proactiv
if (atomic_sub_fetch_32(&pMemTable->nRef, 1) == 0) { if (atomic_sub_fetch_32(&pMemTable->nRef, 1) == 0) {
tsdbMemTableDestroy(pMemTable, proactive); tsdbMemTableDestroy(pMemTable, proactive);
} }
return code;
} }
static FORCE_INLINE int32_t tbDataPCmprFn(const void *p1, const void *p2) { static FORCE_INLINE int32_t tbDataPCmprFn(const void *p1, const void *p2) {

View File

@ -77,9 +77,8 @@ static int32_t tsdbMergerClose(SMerger *merger) {
return 0; return 0;
} }
static int32_t tsdbMergeFileSetEndCloseReader(SMerger *merger) { static void tsdbMergeFileSetEndCloseReader(SMerger *merger) {
TARRAY2_CLEAR(merger->sttReaderArr, tsdbSttFileReaderClose); TARRAY2_CLEAR(merger->sttReaderArr, tsdbSttFileReaderClose);
return 0;
} }
static int32_t tsdbMergeFileSetBeginOpenReader(SMerger *merger) { static int32_t tsdbMergeFileSetBeginOpenReader(SMerger *merger) {
@ -204,7 +203,7 @@ static int32_t tsdbMergeFileSetBeginOpenReader(SMerger *merger) {
TAOS_CHECK_GOTO(tsdbSttFileReaderOpen(fobj->fname, &config, &reader), &lino, _exit); TAOS_CHECK_GOTO(tsdbSttFileReaderOpen(fobj->fname, &config, &reader), &lino, _exit);
if ((code = TARRAY2_APPEND(merger->sttReaderArr, reader))) { if ((code = TARRAY2_APPEND(merger->sttReaderArr, reader))) {
(void)tsdbSttFileReaderClose(&reader); tsdbSttFileReaderClose(&reader);
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }
} }
@ -219,7 +218,7 @@ _exit:
if (code) { if (code) {
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(merger->tsdb->pVnode), __func__, __FILE__, lino, tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(merger->tsdb->pVnode), __func__, __FILE__, lino,
tstrerror(code)); tstrerror(code));
(void)tsdbMergeFileSetEndCloseReader(merger); tsdbMergeFileSetEndCloseReader(merger);
} }
return code; return code;
} }
@ -271,7 +270,9 @@ static int32_t tsdbMergeFileSetBeginOpenWriter(SMerger *merger) {
TAOS_CHECK_GOTO(tfsAllocDisk(merger->tsdb->pVnode->pTfs, level, &did), &lino, _exit); TAOS_CHECK_GOTO(tfsAllocDisk(merger->tsdb->pVnode->pTfs, level, &did), &lino, _exit);
(void)tfsMkdirRecurAt(merger->tsdb->pVnode->pTfs, merger->tsdb->path, did); code = tfsMkdirRecurAt(merger->tsdb->pVnode->pTfs, merger->tsdb->path, did);
TSDB_CHECK_CODE(code, lino, _exit);
SFSetWriterConfig config = { SFSetWriterConfig config = {
.tsdb = merger->tsdb, .tsdb = merger->tsdb,
.toSttOnly = true, .toSttOnly = true,
@ -339,9 +340,9 @@ static int32_t tsdbMergeFileSetEndCloseWriter(SMerger *merger) {
} }
static int32_t tsdbMergeFileSetEndCloseIter(SMerger *merger) { static int32_t tsdbMergeFileSetEndCloseIter(SMerger *merger) {
(void)tsdbIterMergerClose(&merger->tombIterMerger); tsdbIterMergerClose(&merger->tombIterMerger);
TARRAY2_CLEAR(merger->tombIterArr, tsdbIterClose); TARRAY2_CLEAR(merger->tombIterArr, tsdbIterClose);
(void)tsdbIterMergerClose(&merger->dataIterMerger); tsdbIterMergerClose(&merger->dataIterMerger);
TARRAY2_CLEAR(merger->dataIterArr, tsdbIterClose); TARRAY2_CLEAR(merger->dataIterArr, tsdbIterClose);
return 0; return 0;
} }
@ -354,7 +355,7 @@ static int32_t tsdbMergeFileSetEnd(SMerger *merger) {
TAOS_CHECK_GOTO(tsdbMergeFileSetEndCloseIter(merger), &lino, _exit); TAOS_CHECK_GOTO(tsdbMergeFileSetEndCloseIter(merger), &lino, _exit);
TAOS_CHECK_GOTO(tsdbMergeFileSetEndCloseReader(merger), &lino, _exit); tsdbMergeFileSetEndCloseReader(merger);
// edit file system // edit file system
TAOS_CHECK_GOTO(tsdbFSEditBegin(merger->tsdb->pFS, merger->fopArr, TSDB_FEDIT_MERGE), &lino, _exit); TAOS_CHECK_GOTO(tsdbFSEditBegin(merger->tsdb->pFS, merger->fopArr, TSDB_FEDIT_MERGE), &lino, _exit);
@ -463,7 +464,7 @@ static int32_t tsdbMergeGetFSet(SMerger *merger) {
STFileSet *fset; STFileSet *fset;
(void)taosThreadMutexLock(&merger->tsdb->mutex); (void)taosThreadMutexLock(&merger->tsdb->mutex);
(void)tsdbFSGetFSet(merger->tsdb->pFS, merger->fid, &fset); tsdbFSGetFSet(merger->tsdb->pFS, merger->fid, &fset);
if (fset == NULL) { if (fset == NULL) {
(void)taosThreadMutexUnlock(&merger->tsdb->mutex); (void)taosThreadMutexUnlock(&merger->tsdb->mutex);
return 0; return 0;

View File

@ -379,6 +379,7 @@ static int32_t loadSttStatisticsBlockData(SSttFileReader *pSttFileReader, SSttBl
int32_t lino = 0; int32_t lino = 0;
void *px = NULL; void *px = NULL;
int32_t startIndex = 0; int32_t startIndex = 0;
int32_t ret = 0;
int32_t numOfBlocks = TARRAY2_SIZE(pStatisBlkArray); int32_t numOfBlocks = TARRAY2_SIZE(pStatisBlkArray);
if (numOfBlocks <= 0) { if (numOfBlocks <= 0) {
@ -408,9 +409,7 @@ static int32_t loadSttStatisticsBlockData(SSttFileReader *pSttFileReader, SSttBl
for (int32_t k = startIndex; k < endIndex; ++k) { for (int32_t k = startIndex; k < endIndex; ++k) {
code = tsdbSttFileReadStatisBlock(pSttFileReader, &pStatisBlkArray->data[k], &block); code = tsdbSttFileReadStatisBlock(pSttFileReader, &pStatisBlkArray->data[k], &block);
if (code) { QUERY_CHECK_CODE(code, lino, _end);
return code;
}
int32_t i = 0; int32_t i = 0;
int32_t rows = block.numOfRecords; int32_t rows = block.numOfRecords;
@ -489,7 +488,9 @@ static int32_t loadSttStatisticsBlockData(SSttFileReader *pSttFileReader, SSttBl
} else { } else {
STbStatisRecord record = {0}; STbStatisRecord record = {0};
while (i < rows) { while (i < rows) {
(void)tStatisBlockGet(&block, i, &record); code = tStatisBlockGet(&block, i, &record);
TSDB_CHECK_CODE(code, lino, _end);
if (record.suid != suid) { if (record.suid != suid) {
break; break;
} }
@ -536,12 +537,15 @@ static int32_t loadSttStatisticsBlockData(SSttFileReader *pSttFileReader, SSttBl
} }
_end: _end:
(void)tStatisBlockDestroy(&block); tStatisBlockDestroy(&block);
if (code != 0) {
tsdbError("%s error happens at:%s line number: %d, code:%s", id, __func__, lino, tstrerror(code));
} else {
double el = (taosGetTimestampUs() - st) / 1000.0;
pBlockLoadInfo->cost.statisElapsedTime += el;
double el = (taosGetTimestampUs() - st) / 1000.0; tsdbDebug("%s load %d statis blocks into buf, elapsed time:%.2fms", id, num, el);
pBlockLoadInfo->cost.statisElapsedTime += el; }
tsdbDebug("%s load %d statis blocks into buf, elapsed time:%.2fms", id, num, el);
return code; return code;
} }
@ -677,7 +681,7 @@ int32_t tLDataIterOpen2(SLDataIter *pIter, SSttFileReader *pSttFileReader, int32
} }
void tLDataIterClose2(SLDataIter *pIter) { void tLDataIterClose2(SLDataIter *pIter) {
(void)tsdbSttFileReaderClose(&pIter->pReader); // always return 0 tsdbSttFileReaderClose(&pIter->pReader);
pIter->pReader = NULL; pIter->pReader = NULL;
} }
@ -953,6 +957,7 @@ int32_t tMergeTreeOpen2(SMergeTree *pMTree, SMergeTreeConf *pConf, SSttDataInfoF
pMTree->pIter = NULL; pMTree->pIter = NULL;
pMTree->backward = pConf->backward; pMTree->backward = pConf->backward;
pMTree->idStr = pConf->idstr; pMTree->idStr = pConf->idstr;
int32_t lino = 0;
if (!pMTree->backward) { // asc if (!pMTree->backward) { // asc
tRBTreeCreate(&pMTree->rbt, tLDataIterCmprFn); tRBTreeCreate(&pMTree->rbt, tLDataIterCmprFn);
@ -1027,9 +1032,8 @@ int32_t tMergeTreeOpen2(SMergeTree *pMTree, SMergeTreeConf *pConf, SSttDataInfoF
// let's record the time window for current table of uid in the stt files // let's record the time window for current table of uid in the stt files
if (pSttDataInfo != NULL && numOfRows > 0) { if (pSttDataInfo != NULL && numOfRows > 0) {
void *px = taosArrayPush(pSttDataInfo->pKeyRangeList, &range); void *px = taosArrayPush(pSttDataInfo->pKeyRangeList, &range);
if (px == NULL) { QUERY_CHECK_NULL(px, code, lino, _end, terrno);
return terrno;
}
pSttDataInfo->numOfRows += numOfRows; pSttDataInfo->numOfRows += numOfRows;
} }
} else { } else {

View File

@ -17,9 +17,9 @@
#include "tsdbFS2.h" #include "tsdbFS2.h"
extern int32_t tsdbOpenCompMonitor(STsdb *tsdb); extern int32_t tsdbOpenCompMonitor(STsdb *tsdb);
extern int32_t tsdbCloseCompMonitor(STsdb *tsdb); extern void tsdbCloseCompMonitor(STsdb *tsdb);
int32_t tsdbSetKeepCfg(STsdb *pTsdb, STsdbCfg *pCfg) { void tsdbSetKeepCfg(STsdb *pTsdb, STsdbCfg *pCfg) {
STsdbKeepCfg *pKeepCfg = &pTsdb->keepCfg; STsdbKeepCfg *pKeepCfg = &pTsdb->keepCfg;
pKeepCfg->precision = pCfg->precision; pKeepCfg->precision = pCfg->precision;
pKeepCfg->days = pCfg->days; pKeepCfg->days = pCfg->days;
@ -27,7 +27,6 @@ int32_t tsdbSetKeepCfg(STsdb *pTsdb, STsdbCfg *pCfg) {
pKeepCfg->keep1 = pCfg->keep1; pKeepCfg->keep1 = pCfg->keep1;
pKeepCfg->keep2 = pCfg->keep2; pKeepCfg->keep2 = pCfg->keep2;
pKeepCfg->keepTimeOffset = pCfg->keepTimeOffset; pKeepCfg->keepTimeOffset = pCfg->keepTimeOffset;
return 0;
} }
int64_t tsdbGetEarliestTs(STsdb *pTsdb) { int64_t tsdbGetEarliestTs(STsdb *pTsdb) {
@ -59,26 +58,30 @@ int32_t tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *
pTsdb->pVnode = pVnode; pTsdb->pVnode = pVnode;
(void)taosThreadMutexInit(&pTsdb->mutex, NULL); (void)taosThreadMutexInit(&pTsdb->mutex, NULL);
if (!pKeepCfg) { if (!pKeepCfg) {
(void)tsdbSetKeepCfg(pTsdb, &pVnode->config.tsdbCfg); tsdbSetKeepCfg(pTsdb, &pVnode->config.tsdbCfg);
} else { } else {
memcpy(&pTsdb->keepCfg, pKeepCfg, sizeof(STsdbKeepCfg)); memcpy(&pTsdb->keepCfg, pKeepCfg, sizeof(STsdbKeepCfg));
} }
// create dir // create dir
if (pVnode->pTfs) { if (pVnode->pTfs) {
(void)tfsMkdir(pVnode->pTfs, pTsdb->path); code = tfsMkdir(pVnode->pTfs, pTsdb->path);
TSDB_CHECK_CODE(code, lino, _exit);
} else { } else {
(void)taosMkDir(pTsdb->path); code = taosMkDir(pTsdb->path);
TSDB_CHECK_CODE(code, lino, _exit);
} }
// open tsdb // open tsdb
TAOS_CHECK_GOTO(tsdbOpenFS(pTsdb, &pTsdb->pFS, rollback), &lino, _exit); code = tsdbOpenFS(pTsdb, &pTsdb->pFS, rollback);
TSDB_CHECK_CODE(code, lino, _exit);
if (pTsdb->pFS->fsstate == TSDB_FS_STATE_INCOMPLETE && force == false) { if (pTsdb->pFS->fsstate == TSDB_FS_STATE_INCOMPLETE && force == false) {
TAOS_CHECK_GOTO(TSDB_CODE_NEED_RETRY, &lino, _exit); TAOS_CHECK_GOTO(TSDB_CODE_NEED_RETRY, &lino, _exit);
} }
TAOS_CHECK_GOTO(tsdbOpenCache(pTsdb), &lino, _exit); code = tsdbOpenCache(pTsdb);
TSDB_CHECK_CODE(code, lino, _exit);
#ifdef TD_ENTERPRISE #ifdef TD_ENTERPRISE
TAOS_CHECK_GOTO(tsdbOpenCompMonitor(pTsdb), &lino, _exit); TAOS_CHECK_GOTO(tsdbOpenCompMonitor(pTsdb), &lino, _exit);
@ -87,7 +90,7 @@ int32_t tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *
_exit: _exit:
if (code) { if (code) {
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(pVnode), __func__, __FILE__, lino, tstrerror(code)); tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(pVnode), __func__, __FILE__, lino, tstrerror(code));
(void)tsdbCloseFS(&pTsdb->pFS); tsdbCloseFS(&pTsdb->pFS);
(void)taosThreadMutexDestroy(&pTsdb->mutex); (void)taosThreadMutexDestroy(&pTsdb->mutex);
taosMemoryFree(pTsdb); taosMemoryFree(pTsdb);
} else { } else {
@ -110,10 +113,10 @@ int32_t tsdbClose(STsdb **pTsdb) {
(*pTsdb)->mem = NULL; (*pTsdb)->mem = NULL;
(void)taosThreadMutexUnlock(&(*pTsdb)->mutex); (void)taosThreadMutexUnlock(&(*pTsdb)->mutex);
(void)tsdbCloseFS(&(*pTsdb)->pFS); tsdbCloseFS(&(*pTsdb)->pFS);
tsdbCloseCache(*pTsdb); tsdbCloseCache(*pTsdb);
#ifdef TD_ENTERPRISE #ifdef TD_ENTERPRISE
(void)tsdbCloseCompMonitor(*pTsdb); tsdbCloseCompMonitor(*pTsdb);
#endif #endif
(void)taosThreadMutexDestroy(&(*pTsdb)->mutex); (void)taosThreadMutexDestroy(&(*pTsdb)->mutex);
taosMemoryFreeClear(*pTsdb); taosMemoryFreeClear(*pTsdb);

View File

@ -308,7 +308,7 @@ static int32_t filesetIteratorNext(SFilesetIter* pIter, STsdbReader* pReader, bo
while (1) { while (1) {
if (pReader->pFileReader != NULL) { if (pReader->pFileReader != NULL) {
(void) tsdbDataFileReaderClose(&pReader->pFileReader); tsdbDataFileReaderClose(&pReader->pFileReader);
} }
pReader->status.pCurrentFileset = pIter->pFilesetList->data[pIter->index]; pReader->status.pCurrentFileset = pIter->pFilesetList->data[pIter->index];
@ -403,7 +403,7 @@ static void initReaderStatus(SReaderStatus* pStatus) {
} }
static int32_t createResBlock(SQueryTableDataCond* pCond, int32_t capacity, SSDataBlock** pResBlock) { static int32_t createResBlock(SQueryTableDataCond* pCond, int32_t capacity, SSDataBlock** pResBlock) {
QRY_OPTR_CHECK(pResBlock); QRY_PARAM_CHECK(pResBlock);
SSDataBlock* pBlock = NULL; SSDataBlock* pBlock = NULL;
int32_t code = createDataBlock(&pBlock); int32_t code = createDataBlock(&pBlock);
@ -449,10 +449,14 @@ static int32_t tsdbUninitReaderLock(STsdbReader* pReader) {
static int32_t tsdbAcquireReader(STsdbReader* pReader) { static int32_t tsdbAcquireReader(STsdbReader* pReader) {
int32_t code = -1; int32_t code = -1;
tsdbTrace("tsdb/read: %p, pre-take read mutex: %p, code: %d", pReader, &pReader->readerMutex, code); tsdbTrace("tsdb/read: %s, pre-take read mutex: %p, code: %d", pReader->idStr, &pReader->readerMutex, code);
code = taosThreadMutexLock(&pReader->readerMutex); code = taosThreadMutexLock(&pReader->readerMutex);
tsdbTrace("tsdb/read: %p, post-take read mutex: %p, code: %d", pReader, &pReader->readerMutex, code); if (code != 0) {
tsdbError("tsdb/read:%p, failed to lock reader mutex, code:%s", pReader->idStr, tstrerror(code));
} else {
tsdbTrace("tsdb/read: %s, post-take read mutex: %p, code: %d", pReader->idStr, &pReader->readerMutex, code);
}
return code; return code;
} }
@ -4574,12 +4578,17 @@ int32_t tsdbSetTableList2(STsdbReader* pReader, const void* pTableList, int32_t
STableBlockScanInfo** p = NULL; STableBlockScanInfo** p = NULL;
int32_t iter = 0; int32_t iter = 0;
(void)tsdbAcquireReader(pReader); code = tsdbAcquireReader(pReader);
if (code) {
return code;
}
while ((p = tSimpleHashIterate(pReader->status.pTableMap, p, &iter)) != NULL) { while ((p = tSimpleHashIterate(pReader->status.pTableMap, p, &iter)) != NULL) {
clearBlockScanInfo(*p); clearBlockScanInfo(*p);
} }
tSimpleHashClear(pReader->status.pTableMap);
if (size < num) { if (size < num) {
code = ensureBlockScanInfoBuf(&pReader->blockInfoBuf, num); code = ensureBlockScanInfoBuf(&pReader->blockInfoBuf, num);
if (code) { if (code) {
@ -4596,7 +4605,6 @@ int32_t tsdbSetTableList2(STsdbReader* pReader, const void* pTableList, int32_t
pReader->status.uidList.tableUidList = (uint64_t*)p1; pReader->status.uidList.tableUidList = (uint64_t*)p1;
} }
tSimpleHashClear(pReader->status.pTableMap);
STableUidList* pUidList = &pReader->status.uidList; STableUidList* pUidList = &pReader->status.uidList;
pUidList->currentIndex = 0; pUidList->currentIndex = 0;
@ -4745,13 +4753,15 @@ int32_t tsdbReaderOpen2(void* pVnode, SQueryTableDataCond* pCond, void* pTableLi
// no valid error code set in metaGetTbTSchema, so let's set the error code here. // no valid error code set in metaGetTbTSchema, so let's set the error code here.
// we should proceed in case of tmq processing. // we should proceed in case of tmq processing.
if (pCond->suid != 0) { if (pCond->suid != 0) {
pReader->info.pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, pReader->info.suid, -1, 1); code = metaGetTbTSchemaMaybeNull(pReader->pTsdb->pVnode->pMeta, pReader->info.suid, -1, 1, &pReader->info.pSchema);
TSDB_CHECK_CODE(code, lino, _err);
if (pReader->info.pSchema == NULL) { if (pReader->info.pSchema == NULL) {
tsdbWarn("failed to get table schema, suid:%" PRIu64 ", ver:-1, %s", pReader->info.suid, pReader->idStr); tsdbWarn("failed to get table schema, suid:%" PRIu64 ", ver:-1, %s", pReader->info.suid, pReader->idStr);
} }
} else if (numOfTables > 0) { } else if (numOfTables > 0) {
STableKeyInfo* pKey = pTableList; STableKeyInfo* pKey = pTableList;
pReader->info.pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, pKey->uid, -1, 1); code = metaGetTbTSchemaMaybeNull(pReader->pTsdb->pVnode->pMeta, pKey->uid, -1, 1, &pReader->info.pSchema);
TSDB_CHECK_CODE(code, lino, _err);
if (pReader->info.pSchema == NULL) { if (pReader->info.pSchema == NULL) {
tsdbWarn("failed to get table schema, uid:%" PRIu64 ", ver:-1, %s", pKey->uid, pReader->idStr); tsdbWarn("failed to get table schema, uid:%" PRIu64 ", ver:-1, %s", pKey->uid, pReader->idStr);
} }
@ -4805,7 +4815,10 @@ void tsdbReaderClose2(STsdbReader* pReader) {
return; return;
} }
(void)tsdbAcquireReader(pReader); int32_t code = tsdbAcquireReader(pReader);
if (code) {
return;
}
{ {
if (pReader->innerReader[0] != NULL || pReader->innerReader[1] != NULL) { if (pReader->innerReader[0] != NULL || pReader->innerReader[1] != NULL) {
@ -4848,7 +4861,7 @@ void tsdbReaderClose2(STsdbReader* pReader) {
clearBlockScanInfoBuf(&pReader->blockInfoBuf); clearBlockScanInfoBuf(&pReader->blockInfoBuf);
if (pReader->pFileReader != NULL) { if (pReader->pFileReader != NULL) {
(void) tsdbDataFileReaderClose(&pReader->pFileReader); tsdbDataFileReaderClose(&pReader->pFileReader);
} }
SReadCostSummary* pCost = &pReader->cost; SReadCostSummary* pCost = &pReader->cost;
@ -4902,7 +4915,7 @@ static int32_t doSuspendCurrentReader(STsdbReader* pCurrentReader) {
SReaderStatus* pStatus = &pCurrentReader->status; SReaderStatus* pStatus = &pCurrentReader->status;
if (pStatus->loadFromFile) { if (pStatus->loadFromFile) {
(void) tsdbDataFileReaderClose(&pCurrentReader->pFileReader); tsdbDataFileReaderClose(&pCurrentReader->pFileReader);
SReadCostSummary* pCost = &pCurrentReader->cost; SReadCostSummary* pCost = &pCurrentReader->cost;
destroySttBlockReader(pStatus->pLDataIterArray, &pCost->sttCost); destroySttBlockReader(pStatus->pLDataIterArray, &pCost->sttCost);
@ -5003,7 +5016,7 @@ int32_t tsdbReaderResume2(STsdbReader* pReader) {
int32_t numOfTables = tSimpleHashGetSize(pReader->status.pTableMap); int32_t numOfTables = tSimpleHashGetSize(pReader->status.pTableMap);
if (numOfTables > 0) { if (numOfTables > 0) {
tsdbTrace("tsdb/reader: %p, take snapshot", pReader); tsdbTrace("tsdb/reader: %p, take snapshot", pReader);
code = tsdbTakeReadSnap2(pReader, tsdbSetQueryReseek, &pReader->pReadSnap); code = tsdbTakeReadSnap2(pReader, tsdbSetQueryReseek, &pReader->pReadSnap, pReader->idStr);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
goto _err; goto _err;
} }
@ -5550,7 +5563,7 @@ int32_t tsdbReaderReset2(STsdbReader* pReader, SQueryTableDataCond* pCond) {
memset(&pReader->suppInfo.tsColAgg, 0, sizeof(SColumnDataAgg)); memset(&pReader->suppInfo.tsColAgg, 0, sizeof(SColumnDataAgg));
pReader->suppInfo.tsColAgg.colId = PRIMARYKEY_TIMESTAMP_COL_ID; pReader->suppInfo.tsColAgg.colId = PRIMARYKEY_TIMESTAMP_COL_ID;
(void) tsdbDataFileReaderClose(&pReader->pFileReader); tsdbDataFileReaderClose(&pReader->pFileReader);
int32_t numOfTables = tSimpleHashGetSize(pStatus->pTableMap); int32_t numOfTables = tSimpleHashGetSize(pStatus->pTableMap);
@ -5849,16 +5862,17 @@ int32_t tsdbGetTableSchema(SMeta* pMeta, int64_t uid, STSchema** pSchema, int64_
return code; return code;
} }
int32_t tsdbTakeReadSnap2(STsdbReader* pReader, _query_reseek_func_t reseek, STsdbReadSnap** ppSnap) { int32_t tsdbTakeReadSnap2(STsdbReader* pReader, _query_reseek_func_t reseek, STsdbReadSnap** ppSnap, const char* id) {
int32_t code = 0; int32_t code = 0;
STsdb* pTsdb = pReader->pTsdb; STsdb* pTsdb = pReader->pTsdb;
SVersionRange* pRange = &pReader->info.verRange; SVersionRange* pRange = &pReader->info.verRange;
int32_t lino = 0;
*ppSnap = NULL; *ppSnap = NULL;
// lock // lock
code = taosThreadMutexLock(&pTsdb->mutex); code = taosThreadMutexLock(&pTsdb->mutex);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
tsdbError("failed to lock tsdb, code:%s", tstrerror(code)); tsdbError("%s failed to lock tsdb, code:%s", id, tstrerror(code));
return code; return code;
} }
@ -5866,8 +5880,7 @@ int32_t tsdbTakeReadSnap2(STsdbReader* pReader, _query_reseek_func_t reseek, STs
STsdbReadSnap* pSnap = (STsdbReadSnap*)taosMemoryCalloc(1, sizeof(STsdbReadSnap)); STsdbReadSnap* pSnap = (STsdbReadSnap*)taosMemoryCalloc(1, sizeof(STsdbReadSnap));
if (pSnap == NULL) { if (pSnap == NULL) {
(void) taosThreadMutexUnlock(&pTsdb->mutex); (void) taosThreadMutexUnlock(&pTsdb->mutex);
code = terrno; TSDB_CHECK_NULL(pSnap, code, lino, _exit, terrno);
goto _exit;
} }
// take snapshot // take snapshot
@ -5876,14 +5889,14 @@ int32_t tsdbTakeReadSnap2(STsdbReader* pReader, _query_reseek_func_t reseek, STs
pSnap->pNode = taosMemoryMalloc(sizeof(*pSnap->pNode)); pSnap->pNode = taosMemoryMalloc(sizeof(*pSnap->pNode));
if (pSnap->pNode == NULL) { if (pSnap->pNode == NULL) {
(void) taosThreadMutexUnlock(&pTsdb->mutex); (void) taosThreadMutexUnlock(&pTsdb->mutex);
code = terrno; TSDB_CHECK_NULL(pSnap->pNode, code, lino, _exit, terrno);
goto _exit;
} }
pSnap->pNode->pQHandle = pReader; pSnap->pNode->pQHandle = pReader;
pSnap->pNode->reseek = reseek; pSnap->pNode->reseek = reseek;
(void)tsdbRefMemTable(pTsdb->mem, pSnap->pNode); code = tsdbRefMemTable(pTsdb->mem, pSnap->pNode);
TSDB_CHECK_CODE(code, lino, _exit);
} }
if (pTsdb->imem && (pRange->minVer <= pTsdb->imem->maxVer && pRange->maxVer >= pTsdb->imem->minVer)) { if (pTsdb->imem && (pRange->minVer <= pTsdb->imem->maxVer && pRange->maxVer >= pTsdb->imem->minVer)) {
@ -5893,7 +5906,7 @@ int32_t tsdbTakeReadSnap2(STsdbReader* pReader, _query_reseek_func_t reseek, STs
code = terrno; code = terrno;
if (pTsdb->mem && pSnap->pNode) { if (pTsdb->mem && pSnap->pNode) {
(void) tsdbUnrefMemTable(pTsdb->mem, pSnap->pNode, true); // unref the previous refed mem tsdbUnrefMemTable(pTsdb->mem, pSnap->pNode, true); // unref the previous refed mem
} }
(void) taosThreadMutexUnlock(&pTsdb->mutex); (void) taosThreadMutexUnlock(&pTsdb->mutex);
@ -5903,33 +5916,35 @@ int32_t tsdbTakeReadSnap2(STsdbReader* pReader, _query_reseek_func_t reseek, STs
pSnap->pINode->pQHandle = pReader; pSnap->pINode->pQHandle = pReader;
pSnap->pINode->reseek = reseek; pSnap->pINode->reseek = reseek;
(void)tsdbRefMemTable(pTsdb->imem, pSnap->pINode); code = tsdbRefMemTable(pTsdb->imem, pSnap->pINode);
TSDB_CHECK_CODE(code, lino, _exit);
} }
// fs // fs
code = tsdbFSCreateRefSnapshotWithoutLock(pTsdb->pFS, &pSnap->pfSetArray); code = tsdbFSCreateRefSnapshotWithoutLock(pTsdb->pFS, &pSnap->pfSetArray);
if (code) { if (code) {
if (pSnap->pNode) { if (pSnap->pNode) {
(void) tsdbUnrefMemTable(pTsdb->mem, pSnap->pNode, true); // unref the previous refed mem tsdbUnrefMemTable(pTsdb->mem, pSnap->pNode, true); // unref the previous refed mem
} }
if (pSnap->pINode) { if (pSnap->pINode) {
(void) tsdbUnrefMemTable(pTsdb->imem, pSnap->pINode, true); tsdbUnrefMemTable(pTsdb->imem, pSnap->pINode, true);
} }
(void) taosThreadMutexUnlock(&pTsdb->mutex); (void) taosThreadMutexUnlock(&pTsdb->mutex);
goto _exit; TSDB_CHECK_CODE(code, lino, _exit);
} }
// unlock // unlock
(void) taosThreadMutexUnlock(&pTsdb->mutex); (void) taosThreadMutexUnlock(&pTsdb->mutex);
*ppSnap = pSnap; *ppSnap = pSnap;
tsdbTrace("vgId:%d, take read snapshot", TD_VID(pTsdb->pVnode)); tsdbTrace("%s vgId:%d, take read snapshot", id, TD_VID(pTsdb->pVnode));
return code; return code;
_exit: _exit:
tsdbError("vgId:%d take read snapshot failed, code:%s", TD_VID(pTsdb->pVnode), tstrerror(code)); tsdbError("%s vgId:%d take read snapshot failed, line:%d code:%s", id, TD_VID(pTsdb->pVnode), lino, tstrerror(code));
if (pSnap) { if (pSnap) {
if (pSnap->pNode) taosMemoryFree(pSnap->pNode); if (pSnap->pNode) taosMemoryFree(pSnap->pNode);
if (pSnap->pINode) taosMemoryFree(pSnap->pINode); if (pSnap->pINode) taosMemoryFree(pSnap->pINode);
@ -5943,17 +5958,17 @@ void tsdbUntakeReadSnap2(STsdbReader* pReader, STsdbReadSnap* pSnap, bool proact
if (pSnap) { if (pSnap) {
if (pSnap->pMem) { if (pSnap->pMem) {
(void) tsdbUnrefMemTable(pSnap->pMem, pSnap->pNode, proactive); tsdbUnrefMemTable(pSnap->pMem, pSnap->pNode, proactive);
} }
if (pSnap->pIMem) { if (pSnap->pIMem) {
(void) tsdbUnrefMemTable(pSnap->pIMem, pSnap->pINode, proactive); tsdbUnrefMemTable(pSnap->pIMem, pSnap->pINode, proactive);
} }
if (pSnap->pNode) taosMemoryFree(pSnap->pNode); if (pSnap->pNode) taosMemoryFree(pSnap->pNode);
if (pSnap->pINode) taosMemoryFree(pSnap->pINode); if (pSnap->pINode) taosMemoryFree(pSnap->pINode);
(void) tsdbFSDestroyRefSnapshot(&pSnap->pfSetArray); tsdbFSDestroyRefSnapshot(&pSnap->pfSetArray);
taosMemoryFree(pSnap); taosMemoryFree(pSnap);
} }

View File

@ -490,7 +490,7 @@ int32_t getNextBrinRecord(SBrinRecordIter* pIter, SBrinRecord** pRecord) {
return TSDB_CODE_INVALID_PARA; return TSDB_CODE_INVALID_PARA;
} }
(void)tBrinBlockClear(&pIter->block); tBrinBlockClear(&pIter->block);
int32_t code = tsdbDataFileReadBrinBlock(pIter->pReader, pIter->pCurrentBlk, &pIter->block); int32_t code = tsdbDataFileReadBrinBlock(pIter->pReader, pIter->pCurrentBlk, &pIter->block);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
tsdbError("failed to read brinBlock from file, code:%s", tstrerror(code)); tsdbError("failed to read brinBlock from file, code:%s", tstrerror(code));
@ -507,7 +507,7 @@ int32_t getNextBrinRecord(SBrinRecordIter* pIter, SBrinRecord** pRecord) {
return code; return code;
} }
void clearBrinBlockIter(SBrinRecordIter* pIter) { (void)tBrinBlockDestroy(&pIter->block); } void clearBrinBlockIter(SBrinRecordIter* pIter) { tBrinBlockDestroy(&pIter->block); }
// initialize the file block access order // initialize the file block access order
// sort the file blocks according to the offset of each data block in the files // sort the file blocks according to the offset of each data block in the files
@ -779,8 +779,9 @@ typedef enum {
BLK_CHECK_QUIT = 0x2, BLK_CHECK_QUIT = 0x2,
} ETombBlkCheckEnum; } ETombBlkCheckEnum;
static void loadNextStatisticsBlock(SSttFileReader* pSttFileReader, STbStatisBlock* pStatisBlock, static int32_t loadNextStatisticsBlock(SSttFileReader* pSttFileReader, STbStatisBlock* pStatisBlock,
const TStatisBlkArray* pStatisBlkArray, int32_t numOfRows, int32_t* i, int32_t* j); const TStatisBlkArray* pStatisBlkArray, int32_t numOfRows, int32_t* i,
int32_t* j);
static int32_t doCheckTombBlock(STombBlock* pBlock, STsdbReader* pReader, int32_t numOfTables, int32_t* j, static int32_t doCheckTombBlock(STombBlock* pBlock, STsdbReader* pReader, int32_t numOfTables, int32_t* j,
ETombBlkCheckEnum* pRet) { ETombBlkCheckEnum* pRet) {
int32_t code = 0; int32_t code = 0;
@ -912,7 +913,7 @@ static int32_t doLoadTombDataFromTombBlk(const TTombBlkArray* pTombBlkArray, STs
ETombBlkCheckEnum ret = 0; ETombBlkCheckEnum ret = 0;
code = doCheckTombBlock(&block, pReader, numOfTables, &j, &ret); code = doCheckTombBlock(&block, pReader, numOfTables, &j, &ret);
(void)tTombBlockDestroy(&block); tTombBlockDestroy(&block);
if (code != TSDB_CODE_SUCCESS || ret == BLK_CHECK_QUIT) { if (code != TSDB_CODE_SUCCESS || ret == BLK_CHECK_QUIT) {
return code; return code;
} }
@ -994,11 +995,17 @@ int32_t loadMemTombData(SArray** ppMemDelData, STbData* pMemTbData, STbData* piM
int32_t getNumOfRowsInSttBlock(SSttFileReader* pSttFileReader, SSttBlockLoadInfo* pBlockLoadInfo, int32_t getNumOfRowsInSttBlock(SSttFileReader* pSttFileReader, SSttBlockLoadInfo* pBlockLoadInfo,
TStatisBlkArray* pStatisBlkArray, uint64_t suid, const uint64_t* pUidList, TStatisBlkArray* pStatisBlkArray, uint64_t suid, const uint64_t* pUidList,
int32_t numOfTables) { int32_t numOfTables, int32_t* pNumOfRows) {
int32_t num = 0; int32_t num = 0;
int32_t code = 0;
int32_t lino = 0;
if (pNumOfRows != 0) {
*pNumOfRows = 0;
}
if (TARRAY2_SIZE(pStatisBlkArray) <= 0) { if (TARRAY2_SIZE(pStatisBlkArray) <= 0) {
return 0; return code;
} }
int32_t i = 0; int32_t i = 0;
@ -1007,18 +1014,19 @@ int32_t getNumOfRowsInSttBlock(SSttFileReader* pSttFileReader, SSttBlockLoadInfo
} }
if (i >= TARRAY2_SIZE(pStatisBlkArray)) { if (i >= TARRAY2_SIZE(pStatisBlkArray)) {
return 0; return code;
} }
SStatisBlk* p = &pStatisBlkArray->data[i]; SStatisBlk* p = &pStatisBlkArray->data[i];
STbStatisBlock* pStatisBlock = taosMemoryCalloc(1, sizeof(STbStatisBlock)); STbStatisBlock* pStatisBlock = taosMemoryCalloc(1, sizeof(STbStatisBlock));
(void)tStatisBlockInit(pStatisBlock); TSDB_CHECK_NULL(pStatisBlock, code, lino, _err, terrno);
code = tStatisBlockInit(pStatisBlock);
TSDB_CHECK_CODE(code, lino, _err);
int64_t st = taosGetTimestampMs(); int64_t st = taosGetTimestampMs();
int32_t code = tsdbSttFileReadStatisBlock(pSttFileReader, p, pStatisBlock); code = tsdbSttFileReadStatisBlock(pSttFileReader, p, pStatisBlock);
if (code != TSDB_CODE_SUCCESS) { TSDB_CHECK_CODE(code, lino, _err);
return 0;
}
double el = (taosGetTimestampMs() - st) / 1000.0; double el = (taosGetTimestampMs() - st) / 1000.0;
pBlockLoadInfo->cost.loadStatisBlocks += 1; pBlockLoadInfo->cost.loadStatisBlocks += 1;
@ -1030,9 +1038,10 @@ int32_t getNumOfRowsInSttBlock(SSttFileReader* pSttFileReader, SSttBlockLoadInfo
} }
if (index >= pStatisBlock->numOfRecords) { if (index >= pStatisBlock->numOfRecords) {
(void)tStatisBlockDestroy(pStatisBlock); tStatisBlockDestroy(pStatisBlock);
taosMemoryFreeClear(pStatisBlock); taosMemoryFreeClear(pStatisBlock);
return num; *pNumOfRows = num;
return code;
} }
int32_t j = index; int32_t j = index;
@ -1040,9 +1049,10 @@ int32_t getNumOfRowsInSttBlock(SSttFileReader* pSttFileReader, SSttBlockLoadInfo
while (i < TARRAY2_SIZE(pStatisBlkArray) && uidIndex < numOfTables) { while (i < TARRAY2_SIZE(pStatisBlkArray) && uidIndex < numOfTables) {
p = &pStatisBlkArray->data[i]; p = &pStatisBlkArray->data[i];
if (p->minTbid.suid > suid) { if (p->minTbid.suid > suid) {
(void)tStatisBlockDestroy(pStatisBlock); tStatisBlockDestroy(pStatisBlock);
taosMemoryFreeClear(pStatisBlock); taosMemoryFreeClear(pStatisBlock);
return num; *pNumOfRows = num;
return code;
} }
uint64_t uid = pUidList[uidIndex]; uint64_t uid = pUidList[uidIndex];
@ -1051,30 +1061,45 @@ int32_t getNumOfRowsInSttBlock(SSttFileReader* pSttFileReader, SSttBlockLoadInfo
num += ((int64_t*)pStatisBlock->counts.data)[j]; num += ((int64_t*)pStatisBlock->counts.data)[j];
uidIndex += 1; uidIndex += 1;
j += 1; j += 1;
loadNextStatisticsBlock(pSttFileReader, pStatisBlock, pStatisBlkArray, pStatisBlock->numOfRecords, &i, &j); code = loadNextStatisticsBlock(pSttFileReader, pStatisBlock, pStatisBlkArray, pStatisBlock->numOfRecords, &i, &j);
TSDB_CHECK_CODE(code, lino, _err);
} else if (((int64_t*)pStatisBlock->uids.data)[j] < uid) { } else if (((int64_t*)pStatisBlock->uids.data)[j] < uid) {
j += 1; j += 1;
loadNextStatisticsBlock(pSttFileReader, pStatisBlock, pStatisBlkArray, pStatisBlock->numOfRecords, &i, &j); code = loadNextStatisticsBlock(pSttFileReader, pStatisBlock, pStatisBlkArray, pStatisBlock->numOfRecords, &i, &j);
TSDB_CHECK_CODE(code, lino, _err);
} else { } else {
uidIndex += 1; uidIndex += 1;
} }
} }
(void)tStatisBlockDestroy(pStatisBlock); tStatisBlockDestroy(pStatisBlock);
taosMemoryFreeClear(pStatisBlock); taosMemoryFreeClear(pStatisBlock);
return num; *pNumOfRows = num;
return code;
_err:
tsdbError("%p failed to get number of rows in stt block, %s at line:%d code:%s", pSttFileReader, __func__, lino,
tstrerror(code));
return code;
} }
// load next stt statistics block // load next stt statistics block
static void loadNextStatisticsBlock(SSttFileReader* pSttFileReader, STbStatisBlock* pStatisBlock, static int32_t loadNextStatisticsBlock(SSttFileReader* pSttFileReader, STbStatisBlock* pStatisBlock,
const TStatisBlkArray* pStatisBlkArray, int32_t numOfRows, int32_t* i, int32_t* j) { const TStatisBlkArray* pStatisBlkArray, int32_t numOfRows, int32_t* i,
int32_t* j) {
if ((*j) >= numOfRows) { if ((*j) >= numOfRows) {
(*i) += 1; (*i) += 1;
(*j) = 0; (*j) = 0;
if ((*i) < TARRAY2_SIZE(pStatisBlkArray)) { if ((*i) < TARRAY2_SIZE(pStatisBlkArray)) {
(void)tsdbSttFileReadStatisBlock(pSttFileReader, &pStatisBlkArray->data[(*i)], pStatisBlock); int32_t code = tsdbSttFileReadStatisBlock(pSttFileReader, &pStatisBlkArray->data[(*i)], pStatisBlock);
if (code != 0) {
tsdbError("%p failed to read statisBlock, code:%s", pSttFileReader, tstrerror(code));
return code;
}
} }
} }
return 0;
} }
int32_t doAdjustValidDataIters(SArray* pLDIterList, int32_t numOfFileObj) { int32_t doAdjustValidDataIters(SArray* pLDIterList, int32_t numOfFileObj) {
@ -1191,8 +1216,13 @@ int32_t tsdbGetRowsInSttFiles(STFileSet* pFileSet, SArray* pSttFileBlockIterArra
STsdbReader* pReader = pConf->pReader; STsdbReader* pReader = pConf->pReader;
int32_t numOfTables = tSimpleHashGetSize(pReader->status.pTableMap); int32_t numOfTables = tSimpleHashGetSize(pReader->status.pTableMap);
uint64_t* pUidList = pReader->status.uidList.tableUidList; uint64_t* pUidList = pReader->status.uidList.tableUidList;
numOfRows += getNumOfRowsInSttBlock(pIter->pReader, pIter->pBlockLoadInfo, pStatisBlkArray, pConf->suid, pUidList, int32_t n = 0;
numOfTables); code = getNumOfRowsInSttBlock(pIter->pReader, pIter->pBlockLoadInfo, pStatisBlkArray, pConf->suid, pUidList,
numOfTables, &n);
numOfRows += n;
if (code) {
tsdbError("%s failed to get rows in stt blocks, code:%s", pstr, tstrerror(code));
}
} }
} }

View File

@ -343,7 +343,7 @@ int32_t loadDataFileTombDataForAll(STsdbReader* pReader);
int32_t loadSttTombDataForAll(STsdbReader* pReader, SSttFileReader* pSttFileReader, SSttBlockLoadInfo* pLoadInfo); int32_t loadSttTombDataForAll(STsdbReader* pReader, SSttFileReader* pSttFileReader, SSttBlockLoadInfo* pLoadInfo);
int32_t getNumOfRowsInSttBlock(SSttFileReader* pSttFileReader, SSttBlockLoadInfo* pBlockLoadInfo, int32_t getNumOfRowsInSttBlock(SSttFileReader* pSttFileReader, SSttBlockLoadInfo* pBlockLoadInfo,
TStatisBlkArray* pStatisBlkArray, uint64_t suid, const uint64_t* pUidList, TStatisBlkArray* pStatisBlkArray, uint64_t suid, const uint64_t* pUidList,
int32_t numOfTables); int32_t numOfTables, int32_t* pNumOfRows);
void recordToBlockInfo(SFileDataBlockInfo* pBlockInfo, SBrinRecord* record); void recordToBlockInfo(SFileDataBlockInfo* pBlockInfo, SBrinRecord* record);
void destroyLDataIter(SLDataIter* pIter); void destroyLDataIter(SLDataIter* pIter);

View File

@ -46,14 +46,14 @@ static int32_t tsdbOpenFileImpl(STsdbFD *pFD) {
pFD->pFD = taosOpenFile(lc_path, flag); pFD->pFD = taosOpenFile(lc_path, flag);
if (pFD->pFD == NULL) { if (pFD->pFD == NULL) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); TSDB_CHECK_CODE(code = terrno, lino, _exit);
} }
if (taosStatFile(lc_path, &lc_size, NULL, NULL) < 0) { if (taosStatFile(lc_path, &lc_size, NULL, NULL) < 0) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); TSDB_CHECK_CODE(code = terrno, lino, _exit);
} }
} else { } else {
tsdbInfo("no file: %s", path); tsdbInfo("no file: %s", path);
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); TSDB_CHECK_CODE(code = terrno, lino, _exit);
} }
pFD->s3File = 1; pFD->s3File = 1;
} }
@ -73,7 +73,7 @@ static int32_t tsdbOpenFileImpl(STsdbFD *pFD) {
// not check file size when reading data files. // not check file size when reading data files.
if (flag != TD_FILE_READ /* && !pFD->s3File*/) { if (flag != TD_FILE_READ /* && !pFD->s3File*/) {
if (!lc_size && taosStatFile(path, &pFD->szFile, NULL, NULL) < 0) { if (!lc_size && taosStatFile(path, &pFD->szFile, NULL, NULL) < 0) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); TSDB_CHECK_CODE(code = terrno, lino, _exit);
} }
} }
@ -125,9 +125,12 @@ void tsdbCloseFile(STsdbFD **ppFD) {
STsdbFD *pFD = *ppFD; STsdbFD *pFD = *ppFD;
if (pFD) { if (pFD) {
taosMemoryFree(pFD->pBuf); taosMemoryFree(pFD->pBuf);
// if (!pFD->s3File) { int32_t code = taosCloseFile(&pFD->pFD);
(void)taosCloseFile(&pFD->pFD); if (code) {
//} tsdbError("failed to close file: %s, code:%d reason:%s", pFD->path, code, tstrerror(code));
} else {
tsdbTrace("close file: %s", pFD->path);
}
taosMemoryFree(pFD); taosMemoryFree(pFD);
*ppFD = NULL; *ppFD = NULL;
} }
@ -154,10 +157,11 @@ static int32_t tsdbWriteFilePage(STsdbFD *pFD, int32_t encryptAlgorithm, char *e
int64_t n = taosLSeekFile(pFD->pFD, offset, SEEK_SET); int64_t n = taosLSeekFile(pFD->pFD, offset, SEEK_SET);
if (n < 0) { if (n < 0) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); TSDB_CHECK_CODE(code = terrno, lino, _exit);
} }
(void)taosCalcChecksumAppend(0, pFD->pBuf, pFD->szPage); code = taosCalcChecksumAppend(0, pFD->pBuf, pFD->szPage);
TSDB_CHECK_CODE(code, lino, _exit);
if (encryptAlgorithm == DND_CA_SM4) { if (encryptAlgorithm == DND_CA_SM4) {
// if(tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_TSDB) == DND_CS_TSDB){ // if(tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_TSDB) == DND_CS_TSDB){
@ -183,7 +187,7 @@ static int32_t tsdbWriteFilePage(STsdbFD *pFD, int32_t encryptAlgorithm, char *e
n = taosWriteFile(pFD->pFD, pFD->pBuf, pFD->szPage); n = taosWriteFile(pFD->pFD, pFD->pBuf, pFD->szPage);
if (n < 0) { if (n < 0) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); TSDB_CHECK_CODE(code = terrno, lino, _exit);
} }
if (pFD->szFile < pFD->pgno) { if (pFD->szFile < pFD->pgno) {
@ -220,13 +224,13 @@ static int32_t tsdbReadFilePage(STsdbFD *pFD, int64_t pgno, int32_t encryptAlgor
// seek // seek
int64_t n = taosLSeekFile(pFD->pFD, offset, SEEK_SET); int64_t n = taosLSeekFile(pFD->pFD, offset, SEEK_SET);
if (n < 0) { if (n < 0) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); TSDB_CHECK_CODE(code = terrno, lino, _exit);
} }
// read // read
n = taosReadFile(pFD->pFD, pFD->pBuf, pFD->szPage); n = taosReadFile(pFD->pFD, pFD->pBuf, pFD->szPage);
if (n < 0) { if (n < 0) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); TSDB_CHECK_CODE(code = terrno, lino, _exit);
} else if (n < pFD->szPage) { } else if (n < pFD->szPage) {
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit); TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
} }
@ -373,12 +377,12 @@ static int32_t tsdbReadFileBlock(STsdbFD *pFD, int64_t offset, int64_t size, boo
// read last chunk // read last chunk
int64_t ret = taosLSeekFile(pFD->pFD, chunksize * (chunkno - pFD->lcn) + cOffset, SEEK_SET); int64_t ret = taosLSeekFile(pFD->pFD, chunksize * (chunkno - pFD->lcn) + cOffset, SEEK_SET);
if (ret < 0) { if (ret < 0) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); TSDB_CHECK_CODE(code = terrno, lino, _exit);
} }
ret = taosReadFile(pFD->pFD, buf + n, nRead); ret = taosReadFile(pFD->pFD, buf + n, nRead);
if (ret < 0) { if (ret < 0) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); TSDB_CHECK_CODE(code = terrno, lino, _exit);
} else if (ret < nRead) { } else if (ret < nRead) {
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit); TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
} }
@ -632,9 +636,8 @@ _exit:
return code; return code;
} }
int32_t tsdbDataFReaderClose(SDataFReader **ppReader) { void tsdbDataFReaderClose(SDataFReader **ppReader) {
int32_t code = 0; if (*ppReader == NULL) return;
if (*ppReader == NULL) return code;
// head // head
tsdbCloseFile(&(*ppReader)->pHeadFD); tsdbCloseFile(&(*ppReader)->pHeadFD);
@ -657,7 +660,6 @@ int32_t tsdbDataFReaderClose(SDataFReader **ppReader) {
} }
taosMemoryFree(*ppReader); taosMemoryFree(*ppReader);
*ppReader = NULL; *ppReader = NULL;
return code;
} }
int32_t tsdbReadBlockIdx(SDataFReader *pReader, SArray *aBlockIdx) { int32_t tsdbReadBlockIdx(SDataFReader *pReader, SArray *aBlockIdx) {
@ -816,7 +818,7 @@ _exit:
return code; return code;
} }
int32_t tsdbDelFReaderClose(SDelFReader **ppReader) { void tsdbDelFReaderClose(SDelFReader **ppReader) {
int32_t code = 0; int32_t code = 0;
SDelFReader *pReader = *ppReader; SDelFReader *pReader = *ppReader;
@ -829,7 +831,6 @@ int32_t tsdbDelFReaderClose(SDelFReader **ppReader) {
} }
*ppReader = NULL; *ppReader = NULL;
return code;
} }
int32_t tsdbReadDelData(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelData) { int32_t tsdbReadDelData(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelData) {

View File

@ -48,7 +48,7 @@ static int32_t tsdbCopyFileWithLimitedSpeed(TdFilePtr from, TdFilePtr to, int64_
int64_t n; int64_t n;
int64_t last = taosGetTimestampMs(); int64_t last = taosGetTimestampMs();
if ((n = taosFSendFile(to, from, &offset, TMIN(limit, remain))) < 0) { if ((n = taosFSendFile(to, from, &offset, TMIN(limit, remain))) < 0) {
TAOS_CHECK_RETURN(TAOS_SYSTEM_ERROR(errno)); TAOS_CHECK_RETURN(terrno);
} }
remain -= n; remain -= n;
@ -71,19 +71,19 @@ static int32_t tsdbDoCopyFileLC(SRTNer *rtner, const STFileObj *from, const STFi
char fname_from[TSDB_FILENAME_LEN]; char fname_from[TSDB_FILENAME_LEN];
char fname_to[TSDB_FILENAME_LEN]; char fname_to[TSDB_FILENAME_LEN];
(void)tsdbTFileLastChunkName(rtner->tsdb, from->f, fname_from); tsdbTFileLastChunkName(rtner->tsdb, from->f, fname_from);
(void)tsdbTFileLastChunkName(rtner->tsdb, to, fname_to); tsdbTFileLastChunkName(rtner->tsdb, to, fname_to);
fdFrom = taosOpenFile(fname_from, TD_FILE_READ); fdFrom = taosOpenFile(fname_from, TD_FILE_READ);
if (fdFrom == NULL) { if (fdFrom == NULL) {
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); TAOS_CHECK_GOTO(terrno, &lino, _exit);
} }
tsdbInfo("vgId: %d, open tofile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname_to, from->f->size); tsdbInfo("vgId: %d, open tofile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname_to, from->f->size);
fdTo = taosOpenFile(fname_to, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC); fdTo = taosOpenFile(fname_to, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC);
if (fdTo == NULL) { if (fdTo == NULL) {
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); TAOS_CHECK_GOTO(terrno, &lino, _exit);
} }
SVnodeCfg *pCfg = &rtner->tsdb->pVnode->config; SVnodeCfg *pCfg = &rtner->tsdb->pVnode->config;
@ -91,7 +91,7 @@ static int32_t tsdbDoCopyFileLC(SRTNer *rtner, const STFileObj *from, const STFi
int64_t lc_size = tsdbLogicToFileSize(to->size, rtner->szPage) - chunksize * (to->lcn - 1); int64_t lc_size = tsdbLogicToFileSize(to->size, rtner->szPage) - chunksize * (to->lcn - 1);
if (taosFSendFile(fdTo, fdFrom, 0, lc_size) < 0) { if (taosFSendFile(fdTo, fdFrom, 0, lc_size) < 0) {
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); TAOS_CHECK_GOTO(terrno, &lino, _exit);
} }
_exit: _exit:
@ -112,18 +112,18 @@ static int32_t tsdbDoCopyFile(SRTNer *rtner, const STFileObj *from, const STFile
TdFilePtr fdFrom = NULL; TdFilePtr fdFrom = NULL;
TdFilePtr fdTo = NULL; TdFilePtr fdTo = NULL;
(void)tsdbTFileName(rtner->tsdb, to, fname); tsdbTFileName(rtner->tsdb, to, fname);
fdFrom = taosOpenFile(from->fname, TD_FILE_READ); fdFrom = taosOpenFile(from->fname, TD_FILE_READ);
if (fdFrom == NULL) { if (fdFrom == NULL) {
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); TAOS_CHECK_GOTO(terrno, &lino, _exit);
} }
tsdbInfo("vgId: %d, open tofile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname, from->f->size); tsdbInfo("vgId: %d, open tofile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname, from->f->size);
fdTo = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC); fdTo = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC);
if (fdTo == NULL) { if (fdTo == NULL) {
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); TAOS_CHECK_GOTO(terrno, &lino, _exit);
} }
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
@ -255,7 +255,8 @@ static int32_t tsdbDoRetention(SRTNer *rtner) {
SDiskID did; SDiskID did;
TAOS_CHECK_GOTO(tfsAllocDisk(rtner->tsdb->pVnode->pTfs, expLevel, &did), &lino, _exit); TAOS_CHECK_GOTO(tfsAllocDisk(rtner->tsdb->pVnode->pTfs, expLevel, &did), &lino, _exit);
(void)tfsMkdirRecurAt(rtner->tsdb->pVnode->pTfs, rtner->tsdb->path, did); code = tfsMkdirRecurAt(rtner->tsdb->pVnode->pTfs, rtner->tsdb->path, did);
TSDB_CHECK_CODE(code, lino, _exit);
// data // data
for (int32_t ftype = 0; ftype < TSDB_FTYPE_MAX && (fobj = fset->farr[ftype], 1); ++ftype) { for (int32_t ftype = 0; ftype < TSDB_FTYPE_MAX && (fobj = fset->farr[ftype], 1); ++ftype) {
@ -316,7 +317,7 @@ static int32_t tsdbRetention(void *arg) {
// begin task // begin task
(void)taosThreadMutexLock(&pTsdb->mutex); (void)taosThreadMutexLock(&pTsdb->mutex);
(void)tsdbBeginTaskOnFileSet(pTsdb, rtnArg->fid, &fset); tsdbBeginTaskOnFileSet(pTsdb, rtnArg->fid, &fset);
if (fset && (code = tsdbTFileSetInitCopy(pTsdb, fset, &rtner.fset))) { if (fset && (code = tsdbTFileSetInitCopy(pTsdb, fset, &rtner.fset))) {
(void)taosThreadMutexUnlock(&pTsdb->mutex); (void)taosThreadMutexUnlock(&pTsdb->mutex);
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
@ -337,7 +338,7 @@ static int32_t tsdbRetention(void *arg) {
_exit: _exit:
if (rtner.fset) { if (rtner.fset) {
(void)taosThreadMutexLock(&pTsdb->mutex); (void)taosThreadMutexLock(&pTsdb->mutex);
(void)tsdbFinishTaskOnFileSet(pTsdb, rtnArg->fid); tsdbFinishTaskOnFileSet(pTsdb, rtnArg->fid);
(void)taosThreadMutexUnlock(&pTsdb->mutex); (void)taosThreadMutexUnlock(&pTsdb->mutex);
} }
@ -425,11 +426,11 @@ static int32_t tsdbCopyFileS3(SRTNer *rtner, const STFileObj *from, const STFile
TdFilePtr fdFrom = NULL; TdFilePtr fdFrom = NULL;
// TdFilePtr fdTo = NULL; // TdFilePtr fdTo = NULL;
(void)tsdbTFileName(rtner->tsdb, to, fname); tsdbTFileName(rtner->tsdb, to, fname);
fdFrom = taosOpenFile(from->fname, TD_FILE_READ); fdFrom = taosOpenFile(from->fname, TD_FILE_READ);
if (fdFrom == NULL) { if (fdFrom == NULL) {
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); TAOS_CHECK_GOTO(terrno, &lino, _exit);
} }
char *object_name = taosDirEntryBaseName(fname); char *object_name = taosDirEntryBaseName(fname);
@ -484,7 +485,7 @@ static int32_t tsdbMigrateDataFileLCS3(SRTNer *rtner, const STFileObj *fobj, int
TAOS_CHECK_GOTO(TARRAY2_APPEND(&rtner->fopArr, op), &lino, _exit); TAOS_CHECK_GOTO(TARRAY2_APPEND(&rtner->fopArr, op), &lino, _exit);
char fname[TSDB_FILENAME_LEN]; char fname[TSDB_FILENAME_LEN];
(void)tsdbTFileName(rtner->tsdb, &op.nf, fname); tsdbTFileName(rtner->tsdb, &op.nf, fname);
char *object_name = taosDirEntryBaseName(fname); char *object_name = taosDirEntryBaseName(fname);
char object_name_prefix[TSDB_FILENAME_LEN]; char object_name_prefix[TSDB_FILENAME_LEN];
int32_t node_id = vnodeNodeId(rtner->tsdb->pVnode); int32_t node_id = vnodeNodeId(rtner->tsdb->pVnode);
@ -519,7 +520,7 @@ static int32_t tsdbMigrateDataFileLCS3(SRTNer *rtner, const STFileObj *fobj, int
fdFrom = taosOpenFile(fname, TD_FILE_READ); fdFrom = taosOpenFile(fname, TD_FILE_READ);
if (fdFrom == NULL) { if (fdFrom == NULL) {
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); TAOS_CHECK_GOTO(terrno, &lino, _exit);
} }
tsdbInfo("vgId:%d, open lcfile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname, lc_size); tsdbInfo("vgId:%d, open lcfile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname, lc_size);
@ -527,12 +528,12 @@ static int32_t tsdbMigrateDataFileLCS3(SRTNer *rtner, const STFileObj *fobj, int
snprintf(dot2 + 1, TSDB_FQDN_LEN - (dot2 + 1 - object_name), "%d.data", lcn); snprintf(dot2 + 1, TSDB_FQDN_LEN - (dot2 + 1 - object_name), "%d.data", lcn);
fdTo = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC); fdTo = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC);
if (fdTo == NULL) { if (fdTo == NULL) {
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); TAOS_CHECK_GOTO(terrno, &lino, _exit);
} }
int64_t n = taosFSendFile(fdTo, fdFrom, &lc_offset, lc_size); int64_t n = taosFSendFile(fdTo, fdFrom, &lc_offset, lc_size);
if (n < 0) { if (n < 0) {
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); TAOS_CHECK_GOTO(terrno, &lino, _exit);
} }
_exit: _exit:
@ -585,7 +586,7 @@ static int32_t tsdbMigrateDataFileS3(SRTNer *rtner, const STFileObj *fobj, int64
TAOS_CHECK_GOTO(TARRAY2_APPEND(&rtner->fopArr, op), &lino, _exit); TAOS_CHECK_GOTO(TARRAY2_APPEND(&rtner->fopArr, op), &lino, _exit);
char fname[TSDB_FILENAME_LEN]; char fname[TSDB_FILENAME_LEN];
(void)tsdbTFileName(rtner->tsdb, &op.nf, fname); tsdbTFileName(rtner->tsdb, &op.nf, fname);
char *object_name = taosDirEntryBaseName(fname); char *object_name = taosDirEntryBaseName(fname);
char object_name_prefix[TSDB_FILENAME_LEN]; char object_name_prefix[TSDB_FILENAME_LEN];
int32_t node_id = vnodeNodeId(rtner->tsdb->pVnode); int32_t node_id = vnodeNodeId(rtner->tsdb->pVnode);
@ -618,19 +619,19 @@ static int32_t tsdbMigrateDataFileS3(SRTNer *rtner, const STFileObj *fobj, int64
fdFrom = taosOpenFile(fobj->fname, TD_FILE_READ); fdFrom = taosOpenFile(fobj->fname, TD_FILE_READ);
if (fdFrom == NULL) { if (fdFrom == NULL) {
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); TAOS_CHECK_GOTO(terrno, &lino, _exit);
} }
tsdbInfo("vgId: %d, open lcfile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname, fobj->f->size); tsdbInfo("vgId: %d, open lcfile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname, fobj->f->size);
fdTo = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC); fdTo = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC);
if (fdTo == NULL) { if (fdTo == NULL) {
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); TAOS_CHECK_GOTO(terrno, &lino, _exit);
} }
int64_t n = taosFSendFile(fdTo, fdFrom, &lc_offset, lc_size); int64_t n = taosFSendFile(fdTo, fdFrom, &lc_offset, lc_size);
if (n < 0) { if (n < 0) {
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); TAOS_CHECK_GOTO(terrno, &lino, _exit);
} }
_exit: _exit:
@ -693,7 +694,7 @@ static int32_t tsdbDoS3Migrate(SRTNer *rtner) {
TAOS_CHECK_GOTO(TSDB_CODE_INVALID_PARA, &lino, _exit); TAOS_CHECK_GOTO(TSDB_CODE_INVALID_PARA, &lino, _exit);
} }
char fname1[TSDB_FILENAME_LEN]; char fname1[TSDB_FILENAME_LEN];
(void)tsdbTFileLastChunkName(rtner->tsdb, fobj->f, fname1); tsdbTFileLastChunkName(rtner->tsdb, fobj->f, fname1);
if (taosCheckExistFile(fname1)) { if (taosCheckExistFile(fname1)) {
int32_t mtime = 0; int32_t mtime = 0;

View File

@ -102,7 +102,11 @@ static int32_t tsdbTFileSetToFSetPartition(STFileSet* fset, STsdbFSetPartition**
} }
count++; count++;
SVersionRange vr = {.minVer = f->minVer, .maxVer = f->maxVer}; SVersionRange vr = {.minVer = f->minVer, .maxVer = f->maxVer};
(void)TARRAY2_SORT_INSERT(&p->verRanges[typ], vr, tVersionRangeCmprFn); code = TARRAY2_SORT_INSERT(&p->verRanges[typ], vr, tVersionRangeCmprFn);
if (code) {
tsdbFSetPartitionClear(&p);
return code;
}
} }
typ = TSDB_FSET_RANGE_TYP_STT; typ = TSDB_FSET_RANGE_TYP_STT;
@ -120,12 +124,20 @@ static int32_t tsdbTFileSetToFSetPartition(STFileSet* fset, STsdbFSetPartition**
} }
count++; count++;
SVersionRange vr = {.minVer = f->minVer, .maxVer = f->maxVer}; SVersionRange vr = {.minVer = f->minVer, .maxVer = f->maxVer};
(void)TARRAY2_SORT_INSERT(&p->verRanges[typ], vr, tVersionRangeCmprFn); code = TARRAY2_SORT_INSERT(&p->verRanges[typ], vr, tVersionRangeCmprFn);
if (code) {
tsdbFSetPartitionClear(&p);
return code;
}
} }
} }
if (corrupt && count == 0) { if (corrupt && count == 0) {
SVersionRange vr = {.minVer = VERSION_MIN, .maxVer = fset->maxVerValid}; SVersionRange vr = {.minVer = VERSION_MIN, .maxVer = fset->maxVerValid};
(void)TARRAY2_SORT_INSERT(&p->verRanges[typ], vr, tVersionRangeCmprFn); code = TARRAY2_SORT_INSERT(&p->verRanges[typ], vr, tVersionRangeCmprFn);
if (code) {
tsdbFSetPartitionClear(&p);
return code;
}
} }
ppSP[0] = p; ppSP[0] = p;
return 0; return 0;
@ -182,7 +194,11 @@ int32_t tsdbFSetPartListToRangeDiff(STsdbFSetPartList* pList, TFileSetRangeArray
r->sver = maxVerValid + 1; r->sver = maxVerValid + 1;
r->ever = VERSION_MAX; r->ever = VERSION_MAX;
tsdbDebug("range diff fid:%" PRId64 ", sver:%" PRId64 ", ever:%" PRId64, part->fid, r->sver, r->ever); tsdbDebug("range diff fid:%" PRId64 ", sver:%" PRId64 ", ever:%" PRId64, part->fid, r->sver, r->ever);
(void)TARRAY2_SORT_INSERT(pDiff, r, tsdbTFileSetRangeCmprFn); code = TARRAY2_SORT_INSERT(pDiff, r, tsdbTFileSetRangeCmprFn);
if (code) {
taosMemoryFree(r);
goto _err;
}
} }
ppRanges[0] = pDiff; ppRanges[0] = pDiff;
@ -191,7 +207,7 @@ int32_t tsdbFSetPartListToRangeDiff(STsdbFSetPartList* pList, TFileSetRangeArray
_err: _err:
if (pDiff) { if (pDiff) {
(void)tsdbTFileSetRangeArrayDestroy(&pDiff); tsdbTFileSetRangeArrayDestroy(&pDiff);
} }
return code; return code;
} }
@ -355,7 +371,11 @@ static STsdbFSetPartList* tsdbSnapGetFSetPartList(STFileSystem* fs) {
terrno = code; terrno = code;
break; break;
} }
(void)TARRAY2_SORT_INSERT(pList, pItem, tsdbFSetPartCmprFn); code = TARRAY2_SORT_INSERT(pList, pItem, tsdbFSetPartCmprFn);
if (code) {
terrno = code;
break;
}
} }
(void)taosThreadMutexUnlock(&fs->tsdb->mutex); (void)taosThreadMutexUnlock(&fs->tsdb->mutex);

View File

@ -59,7 +59,7 @@ struct STsdbSnapReader {
static int32_t tsdbSnapReadFileSetCloseReader(STsdbSnapReader* reader) { static int32_t tsdbSnapReadFileSetCloseReader(STsdbSnapReader* reader) {
TARRAY2_CLEAR(reader->sttReaderArr, tsdbSttFileReaderClose); TARRAY2_CLEAR(reader->sttReaderArr, tsdbSttFileReaderClose);
TAOS_UNUSED(tsdbDataFileReaderClose(&reader->dataReader)); tsdbDataFileReaderClose(&reader->dataReader);
return 0; return 0;
} }
@ -104,7 +104,7 @@ static int32_t tsdbSnapReadFileSetOpenReader(STsdbSnapReader* reader) {
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
if ((code = TARRAY2_APPEND(reader->sttReaderArr, sttReader))) { if ((code = TARRAY2_APPEND(reader->sttReaderArr, sttReader))) {
TAOS_UNUSED(tsdbSttFileReaderClose(&sttReader)); tsdbSttFileReaderClose(&sttReader);
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
} }
} }
@ -191,8 +191,8 @@ _exit:
} }
static int32_t tsdbSnapReadFileSetCloseIter(STsdbSnapReader* reader) { static int32_t tsdbSnapReadFileSetCloseIter(STsdbSnapReader* reader) {
TAOS_UNUSED(tsdbIterMergerClose(&reader->dataIterMerger)); tsdbIterMergerClose(&reader->dataIterMerger);
TAOS_UNUSED(tsdbIterMergerClose(&reader->tombIterMerger)); tsdbIterMergerClose(&reader->tombIterMerger);
TARRAY2_CLEAR(reader->dataIterArr, tsdbIterClose); TARRAY2_CLEAR(reader->dataIterArr, tsdbIterClose);
TARRAY2_CLEAR(reader->tombIterArr, tsdbIterClose); TARRAY2_CLEAR(reader->tombIterArr, tsdbIterClose);
return 0; return 0;
@ -430,7 +430,7 @@ _exit:
if (code) { if (code) {
tsdbError("vgId:%d %s failed at %s:%d since %s, sver:%" PRId64 " ever:%" PRId64 " type:%d", TD_VID(tsdb->pVnode), tsdbError("vgId:%d %s failed at %s:%d since %s, sver:%" PRId64 " ever:%" PRId64 " type:%d", TD_VID(tsdb->pVnode),
__func__, __FILE__, lino, tstrerror(code), sver, ever, type); __func__, __FILE__, lino, tstrerror(code), sver, ever, type);
TAOS_UNUSED(tsdbTFileSetRangeArrayDestroy(&reader[0]->fsrArr)); tsdbTFileSetRangeArrayDestroy(&reader[0]->fsrArr);
taosMemoryFree(reader[0]); taosMemoryFree(reader[0]);
reader[0] = NULL; reader[0] = NULL;
} else { } else {
@ -449,17 +449,17 @@ int32_t tsdbSnapReaderClose(STsdbSnapReader** reader) {
STsdb* tsdb = reader[0]->tsdb; STsdb* tsdb = reader[0]->tsdb;
TAOS_UNUSED(tTombBlockDestroy(reader[0]->tombBlock)); tTombBlockDestroy(reader[0]->tombBlock);
tBlockDataDestroy(reader[0]->blockData); tBlockDataDestroy(reader[0]->blockData);
TAOS_UNUSED(tsdbIterMergerClose(&reader[0]->dataIterMerger)); tsdbIterMergerClose(&reader[0]->dataIterMerger);
TAOS_UNUSED(tsdbIterMergerClose(&reader[0]->tombIterMerger)); tsdbIterMergerClose(&reader[0]->tombIterMerger);
TARRAY2_DESTROY(reader[0]->dataIterArr, tsdbIterClose); TARRAY2_DESTROY(reader[0]->dataIterArr, tsdbIterClose);
TARRAY2_DESTROY(reader[0]->tombIterArr, tsdbIterClose); TARRAY2_DESTROY(reader[0]->tombIterArr, tsdbIterClose);
TARRAY2_DESTROY(reader[0]->sttReaderArr, tsdbSttFileReaderClose); TARRAY2_DESTROY(reader[0]->sttReaderArr, tsdbSttFileReaderClose);
TAOS_UNUSED(tsdbDataFileReaderClose(&reader[0]->dataReader)); tsdbDataFileReaderClose(&reader[0]->dataReader);
TAOS_UNUSED(tsdbFSDestroyRefRangedSnapshot(&reader[0]->fsrArr)); tsdbFSDestroyRefRangedSnapshot(&reader[0]->fsrArr);
tDestroyTSchema(reader[0]->skmTb->pTSchema); tDestroyTSchema(reader[0]->skmTb->pTSchema);
for (int32_t i = 0; i < ARRAY_SIZE(reader[0]->buffers); ++i) { for (int32_t i = 0; i < ARRAY_SIZE(reader[0]->buffers); ++i) {
@ -691,7 +691,7 @@ _exit:
static int32_t tsdbSnapWriteFileSetCloseReader(STsdbSnapWriter* writer) { static int32_t tsdbSnapWriteFileSetCloseReader(STsdbSnapWriter* writer) {
TARRAY2_CLEAR(writer->ctx->sttReaderArr, tsdbSttFileReaderClose); TARRAY2_CLEAR(writer->ctx->sttReaderArr, tsdbSttFileReaderClose);
TAOS_UNUSED(tsdbDataFileReaderClose(&writer->ctx->dataReader)); tsdbDataFileReaderClose(&writer->ctx->dataReader);
return 0; return 0;
} }
@ -767,8 +767,8 @@ _exit:
} }
static int32_t tsdbSnapWriteFileSetCloseIter(STsdbSnapWriter* writer) { static int32_t tsdbSnapWriteFileSetCloseIter(STsdbSnapWriter* writer) {
TAOS_UNUSED(tsdbIterMergerClose(&writer->ctx->dataIterMerger)); tsdbIterMergerClose(&writer->ctx->dataIterMerger);
TAOS_UNUSED(tsdbIterMergerClose(&writer->ctx->tombIterMerger)); tsdbIterMergerClose(&writer->ctx->tombIterMerger);
TARRAY2_CLEAR(writer->ctx->dataIterArr, tsdbIterClose); TARRAY2_CLEAR(writer->ctx->dataIterArr, tsdbIterClose);
TARRAY2_CLEAR(writer->ctx->tombIterArr, tsdbIterClose); TARRAY2_CLEAR(writer->ctx->tombIterArr, tsdbIterClose);
return 0; return 0;
@ -1119,15 +1119,15 @@ int32_t tsdbSnapWriterClose(STsdbSnapWriter** writer, int8_t rollback) {
(void)taosThreadMutexUnlock(&writer[0]->tsdb->mutex); (void)taosThreadMutexUnlock(&writer[0]->tsdb->mutex);
} }
TAOS_UNUSED(tsdbIterMergerClose(&writer[0]->ctx->tombIterMerger)); tsdbIterMergerClose(&writer[0]->ctx->tombIterMerger);
TAOS_UNUSED(tsdbIterMergerClose(&writer[0]->ctx->dataIterMerger)); tsdbIterMergerClose(&writer[0]->ctx->dataIterMerger);
TARRAY2_DESTROY(writer[0]->ctx->tombIterArr, tsdbIterClose); TARRAY2_DESTROY(writer[0]->ctx->tombIterArr, tsdbIterClose);
TARRAY2_DESTROY(writer[0]->ctx->dataIterArr, tsdbIterClose); TARRAY2_DESTROY(writer[0]->ctx->dataIterArr, tsdbIterClose);
TARRAY2_DESTROY(writer[0]->ctx->sttReaderArr, tsdbSttFileReaderClose); TARRAY2_DESTROY(writer[0]->ctx->sttReaderArr, tsdbSttFileReaderClose);
TAOS_UNUSED(tsdbDataFileReaderClose(&writer[0]->ctx->dataReader)); tsdbDataFileReaderClose(&writer[0]->ctx->dataReader);
TARRAY2_DESTROY(writer[0]->fopArr, NULL); TARRAY2_DESTROY(writer[0]->fopArr, NULL);
TAOS_UNUSED(tsdbFSDestroyCopyRangedSnapshot(&writer[0]->fsetArr)); tsdbFSDestroyCopyRangedSnapshot(&writer[0]->fsetArr);
for (int32_t i = 0; i < ARRAY_SIZE(writer[0]->buffers); ++i) { for (int32_t i = 0; i < ARRAY_SIZE(writer[0]->buffers); ++i) {
tBufferDestroy(writer[0]->buffers + i); tBufferDestroy(writer[0]->buffers + i);

View File

@ -18,7 +18,7 @@
#include "tsdbFS2.h" #include "tsdbFS2.h"
#include "tsdbFSetRAW.h" #include "tsdbFSetRAW.h"
static int32_t tsdbSnapRAWReadFileSetCloseReader(STsdbSnapRAWReader* reader); static void tsdbSnapRAWReadFileSetCloseReader(STsdbSnapRAWReader* reader);
// reader // reader
typedef struct SDataFileRAWReaderIter { typedef struct SDataFileRAWReaderIter {
@ -65,7 +65,7 @@ _exit:
if (code) { if (code) {
tsdbError("vgId:%d %s failed at line %d since %s, sver:0, ever:%" PRId64 " type:%d", TD_VID(tsdb->pVnode), __func__, tsdbError("vgId:%d %s failed at line %d since %s, sver:0, ever:%" PRId64 " type:%d", TD_VID(tsdb->pVnode), __func__,
lino, tstrerror(code), ever, type); lino, tstrerror(code), ever, type);
(void)tsdbFSDestroyRefSnapshot(&reader[0]->fsetArr); tsdbFSDestroyRefSnapshot(&reader[0]->fsetArr);
taosMemoryFree(reader[0]); taosMemoryFree(reader[0]);
reader[0] = NULL; reader[0] = NULL;
} else { } else {
@ -84,7 +84,7 @@ int32_t tsdbSnapRAWReaderClose(STsdbSnapRAWReader** reader) {
STsdb* tsdb = reader[0]->tsdb; STsdb* tsdb = reader[0]->tsdb;
TARRAY2_DESTROY(reader[0]->dataReaderArr, tsdbDataFileRAWReaderClose); TARRAY2_DESTROY(reader[0]->dataReaderArr, tsdbDataFileRAWReaderClose);
(void)tsdbFSDestroyRefSnapshot(&reader[0]->fsetArr); tsdbFSDestroyRefSnapshot(&reader[0]->fsetArr);
taosMemoryFree(reader[0]); taosMemoryFree(reader[0]);
reader[0] = NULL; reader[0] = NULL;
@ -141,15 +141,14 @@ static int32_t tsdbSnapRAWReadFileSetOpenReader(STsdbSnapRAWReader* reader) {
_exit: _exit:
if (code) { if (code) {
(void)tsdbSnapRAWReadFileSetCloseReader(reader); tsdbSnapRAWReadFileSetCloseReader(reader);
TSDB_ERROR_LOG(TD_VID(reader->tsdb->pVnode), code, lino); TSDB_ERROR_LOG(TD_VID(reader->tsdb->pVnode), code, lino);
} }
return code; return code;
} }
static int32_t tsdbSnapRAWReadFileSetCloseReader(STsdbSnapRAWReader* reader) { static void tsdbSnapRAWReadFileSetCloseReader(STsdbSnapRAWReader* reader) {
TARRAY2_CLEAR(reader->dataReaderArr, tsdbDataFileRAWReaderClose); TARRAY2_CLEAR(reader->dataReaderArr, tsdbDataFileRAWReaderClose);
return 0;
} }
static int32_t tsdbSnapRAWReadFileSetOpenIter(STsdbSnapRAWReader* reader) { static int32_t tsdbSnapRAWReadFileSetOpenIter(STsdbSnapRAWReader* reader) {
@ -158,10 +157,9 @@ static int32_t tsdbSnapRAWReadFileSetOpenIter(STsdbSnapRAWReader* reader) {
return 0; return 0;
} }
static int32_t tsdbSnapRAWReadFileSetCloseIter(STsdbSnapRAWReader* reader) { static void tsdbSnapRAWReadFileSetCloseIter(STsdbSnapRAWReader* reader) {
reader->dataIter->count = 0; reader->dataIter->count = 0;
reader->dataIter->idx = 0; reader->dataIter->idx = 0;
return 0;
} }
static int64_t tsdbSnapRAWReadPeek(SDataFileRAWReader* reader) { static int64_t tsdbSnapRAWReadPeek(SDataFileRAWReader* reader) {
@ -261,8 +259,8 @@ _exit:
} }
static int32_t tsdbSnapRAWReadEnd(STsdbSnapRAWReader* reader) { static int32_t tsdbSnapRAWReadEnd(STsdbSnapRAWReader* reader) {
(void)tsdbSnapRAWReadFileSetCloseIter(reader); tsdbSnapRAWReadFileSetCloseIter(reader);
(void)tsdbSnapRAWReadFileSetCloseReader(reader); tsdbSnapRAWReadFileSetCloseReader(reader);
reader->ctx->fset = NULL; reader->ctx->fset = NULL;
return 0; return 0;
} }
@ -411,7 +409,9 @@ static int32_t tsdbSnapRAWWriteFileSetBegin(STsdbSnapRAWWriter* writer, int32_t
int32_t level = tsdbFidLevel(fid, &writer->tsdb->keepCfg, taosGetTimestampSec()); int32_t level = tsdbFidLevel(fid, &writer->tsdb->keepCfg, taosGetTimestampSec());
code = tfsAllocDisk(writer->tsdb->pVnode->pTfs, level, &writer->ctx->did); code = tfsAllocDisk(writer->tsdb->pVnode->pTfs, level, &writer->ctx->did);
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
(void)tfsMkdirRecurAt(writer->tsdb->pVnode->pTfs, writer->tsdb->path, writer->ctx->did);
code = tfsMkdirRecurAt(writer->tsdb->pVnode->pTfs, writer->tsdb->path, writer->ctx->did);
TSDB_CHECK_CODE(code, lino, _exit);
code = tsdbSnapRAWWriteFileSetOpenWriter(writer); code = tsdbSnapRAWWriteFileSetOpenWriter(writer);
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
@ -490,7 +490,7 @@ int32_t tsdbSnapRAWWriterClose(STsdbSnapRAWWriter** writer, int8_t rollback) {
} }
TARRAY2_DESTROY(writer[0]->fopArr, NULL); TARRAY2_DESTROY(writer[0]->fopArr, NULL);
(void)tsdbFSDestroyCopySnapshot(&writer[0]->fsetArr); tsdbFSDestroyCopySnapshot(&writer[0]->fsetArr);
taosMemoryFree(writer[0]); taosMemoryFree(writer[0]);
writer[0] = NULL; writer[0] = NULL;

View File

@ -55,7 +55,7 @@ int32_t tsdbSttFileReaderOpen(const char *fname, const SSttFileReaderConfig *con
TAOS_CHECK_GOTO(tsdbOpenFile(fname, config->tsdb, TD_FILE_READ, &reader[0]->fd, 0), &lino, _exit); TAOS_CHECK_GOTO(tsdbOpenFile(fname, config->tsdb, TD_FILE_READ, &reader[0]->fd, 0), &lino, _exit);
} else { } else {
char fname1[TSDB_FILENAME_LEN]; char fname1[TSDB_FILENAME_LEN];
(void)tsdbTFileName(config->tsdb, config->file, fname1); tsdbTFileName(config->tsdb, config->file, fname1);
TAOS_CHECK_GOTO(tsdbOpenFile(fname1, config->tsdb, TD_FILE_READ, &reader[0]->fd, 0), &lino, _exit); TAOS_CHECK_GOTO(tsdbOpenFile(fname1, config->tsdb, TD_FILE_READ, &reader[0]->fd, 0), &lino, _exit);
} }
@ -93,12 +93,12 @@ _exit:
if (code) { if (code) {
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(config->tsdb->pVnode), __func__, __FILE__, lino, tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(config->tsdb->pVnode), __func__, __FILE__, lino,
tstrerror(code)); tstrerror(code));
(void)tsdbSttFileReaderClose(reader); tsdbSttFileReaderClose(reader);
} }
return code; return code;
} }
int32_t tsdbSttFileReaderClose(SSttFileReader **reader) { void tsdbSttFileReaderClose(SSttFileReader **reader) {
if (reader[0]) { if (reader[0]) {
for (int32_t i = 0; i < ARRAY_SIZE(reader[0]->local); ++i) { for (int32_t i = 0; i < ARRAY_SIZE(reader[0]->local); ++i) {
tBufferDestroy(reader[0]->local + i); tBufferDestroy(reader[0]->local + i);
@ -110,7 +110,6 @@ int32_t tsdbSttFileReaderClose(SSttFileReader **reader) {
taosMemoryFree(reader[0]); taosMemoryFree(reader[0]);
reader[0] = NULL; reader[0] = NULL;
} }
return 0;
} }
// SSttFSegReader // SSttFSegReader
@ -524,7 +523,7 @@ static int32_t tsdbFileDoWriteSttBlockData(STsdbFD *fd, SBlockData *blockData, S
if (sttBlk->maxVer < blockData->aVersion[iRow]) sttBlk->maxVer = blockData->aVersion[iRow]; if (sttBlk->maxVer < blockData->aVersion[iRow]) sttBlk->maxVer = blockData->aVersion[iRow];
} }
(void)tsdbWriterUpdVerRange(range, sttBlk->minVer, sttBlk->maxVer); tsdbWriterUpdVerRange(range, sttBlk->minVer, sttBlk->maxVer);
TAOS_CHECK_RETURN(tBlockDataCompress(blockData, info, buffers, buffers + 4)); TAOS_CHECK_RETURN(tBlockDataCompress(blockData, info, buffers, buffers + 4));
sttBlk->bInfo.offset = *fileSize; sttBlk->bInfo.offset = *fileSize;
@ -591,11 +590,13 @@ static int32_t tsdbSttFileDoWriteStatisBlock(SSttFileWriter *writer) {
statisBlk.cmprAlg = writer->config->cmprAlg; statisBlk.cmprAlg = writer->config->cmprAlg;
statisBlk.numOfPKs = statisBlock->numOfPKs; statisBlk.numOfPKs = statisBlock->numOfPKs;
(void)tStatisBlockGet(statisBlock, 0, &record); code = tStatisBlockGet(statisBlock, 0, &record);
TSDB_CHECK_CODE(code, lino, _exit);
statisBlk.minTbid.suid = record.suid; statisBlk.minTbid.suid = record.suid;
statisBlk.minTbid.uid = record.uid; statisBlk.minTbid.uid = record.uid;
(void)tStatisBlockGet(statisBlock, statisBlock->numOfRecords - 1, &record); code = tStatisBlockGet(statisBlock, statisBlock->numOfRecords - 1, &record);
TSDB_CHECK_CODE(code, lino, _exit);
statisBlk.maxTbid.suid = record.suid; statisBlk.maxTbid.suid = record.suid;
statisBlk.maxTbid.uid = record.uid; statisBlk.maxTbid.uid = record.uid;
@ -807,7 +808,7 @@ static int32_t tsdbSttFWriterDoOpen(SSttFileWriter *writer) {
int32_t flag = TD_FILE_READ | TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC; int32_t flag = TD_FILE_READ | TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC;
char fname[TSDB_FILENAME_LEN]; char fname[TSDB_FILENAME_LEN];
(void)tsdbTFileName(writer->config->tsdb, writer->file, fname); tsdbTFileName(writer->config->tsdb, writer->file, fname);
TAOS_CHECK_GOTO(tsdbOpenFile(fname, writer->config->tsdb, flag, &writer->fd, 0), &lino, _exit); TAOS_CHECK_GOTO(tsdbOpenFile(fname, writer->config->tsdb, flag, &writer->fd, 0), &lino, _exit);
uint8_t hdr[TSDB_FHDR_SIZE] = {0}; uint8_t hdr[TSDB_FHDR_SIZE] = {0};
@ -837,7 +838,7 @@ static void tsdbSttFWriterDoClose(SSttFileWriter *writer) {
tDestroyTSchema(writer->skmRow->pTSchema); tDestroyTSchema(writer->skmRow->pTSchema);
tDestroyTSchema(writer->skmTb->pTSchema); tDestroyTSchema(writer->skmTb->pTSchema);
tTombBlockDestroy(writer->tombBlock); tTombBlockDestroy(writer->tombBlock);
(void)tStatisBlockDestroy(writer->staticBlock); tStatisBlockDestroy(writer->staticBlock);
tBlockDataDestroy(writer->blockData); tBlockDataDestroy(writer->blockData);
TARRAY2_DESTROY(writer->tombBlkArray, NULL); TARRAY2_DESTROY(writer->tombBlkArray, NULL);
TARRAY2_DESTROY(writer->statisBlkArray, NULL); TARRAY2_DESTROY(writer->statisBlkArray, NULL);
@ -874,7 +875,7 @@ static int32_t tsdbSttFWriterCloseCommit(SSttFileWriter *writer, TFileOpArray *o
.fid = writer->config->fid, .fid = writer->config->fid,
.nf = writer->file[0], .nf = writer->file[0],
}; };
(void)tsdbTFileUpdVerRange(&op.nf, writer->ctx->range); tsdbTFileUpdVerRange(&op.nf, writer->ctx->range);
TAOS_CHECK_GOTO(TARRAY2_APPEND(opArray, op), &lino, _exit); TAOS_CHECK_GOTO(TARRAY2_APPEND(opArray, op), &lino, _exit);
@ -888,9 +889,9 @@ _exit:
static int32_t tsdbSttFWriterCloseAbort(SSttFileWriter *writer) { static int32_t tsdbSttFWriterCloseAbort(SSttFileWriter *writer) {
char fname[TSDB_FILENAME_LEN]; char fname[TSDB_FILENAME_LEN];
(void)tsdbTFileName(writer->config->tsdb, writer->file, fname); tsdbTFileName(writer->config->tsdb, writer->file, fname);
tsdbCloseFile(&writer->fd); tsdbCloseFile(&writer->fd);
(void)taosRemoveFile(fname); tsdbRemoveFile(fname);
return 0; return 0;
} }

View File

@ -40,7 +40,7 @@ typedef TARRAY2(SSttFileReader *) TSttFileReaderArray;
// SSttFileReader // SSttFileReader
int32_t tsdbSttFileReaderOpen(const char *fname, const SSttFileReaderConfig *config, SSttFileReader **reader); int32_t tsdbSttFileReaderOpen(const char *fname, const SSttFileReaderConfig *config, SSttFileReader **reader);
int32_t tsdbSttFileReaderClose(SSttFileReader **reader); void tsdbSttFileReaderClose(SSttFileReader **reader);
// SSttSegReader // SSttSegReader
int32_t tsdbSttFileReadSttBlk(SSttFileReader *reader, const TSttBlkArray **sttBlkArray); int32_t tsdbSttFileReadSttBlk(SSttFileReader *reader, const TSttBlkArray **sttBlkArray);
@ -72,9 +72,9 @@ int32_t tsdbSttFileWriteTombRecord(SSttFileWriter *writer, const STombRecord *re
bool tsdbSttFileWriterIsOpened(SSttFileWriter *writer); bool tsdbSttFileWriterIsOpened(SSttFileWriter *writer);
int32_t tsdbFileWriteSttBlk(STsdbFD *fd, const TSttBlkArray *sttBlkArray, SFDataPtr *ptr, int64_t *fileSize, int32_t tsdbFileWriteSttBlk(STsdbFD *fd, const TSttBlkArray *sttBlkArray, SFDataPtr *ptr, int64_t *fileSize,
int32_t encryptAlgorithm, char* encryptKey); int32_t encryptAlgorithm, char *encryptKey);
int32_t tsdbFileWriteSttFooter(STsdbFD *fd, const SSttFooter *footer, int64_t *fileSize, int32_t encryptAlgorithm, int32_t tsdbFileWriteSttFooter(STsdbFD *fd, const SSttFooter *footer, int64_t *fileSize, int32_t encryptAlgorithm,
char* encryptKey); char *encryptKey);
struct SSttFileWriterConfig { struct SSttFileWriterConfig {
STsdb *tsdb; STsdb *tsdb;

View File

@ -23,8 +23,6 @@
#include "tsdbDataFileRW.h" #include "tsdbDataFileRW.h"
#include "tsdbFS2.h" #include "tsdbFS2.h"
#include "tsdbSttFileRW.h" #include "tsdbSttFileRW.h"
// extern int32_t save_fs(const TFileSetArray *arr, const char *fname);
// extern int32_t current_fname(STsdb *pTsdb, char *fname, EFCurrentT ftype);
static int32_t tsdbUpgradeHead(STsdb *tsdb, SDFileSet *pDFileSet, SDataFReader *reader, STFileSet *fset) { static int32_t tsdbUpgradeHead(STsdb *tsdb, SDFileSet *pDFileSet, SDataFReader *reader, STFileSet *fset) {
int32_t code = 0; int32_t code = 0;
@ -79,7 +77,7 @@ static int32_t tsdbUpgradeHead(STsdb *tsdb, SDFileSet *pDFileSet, SDataFReader *
// open fd // open fd
char fname[TSDB_FILENAME_LEN]; char fname[TSDB_FILENAME_LEN];
(void)tsdbTFileName(tsdb, &file, fname); tsdbTFileName(tsdb, &file, fname);
TAOS_CHECK_GOTO(tsdbOpenFile(fname, tsdb, TD_FILE_READ | TD_FILE_WRITE, &ctx->fd, 0), &lino, _exit); TAOS_CHECK_GOTO(tsdbOpenFile(fname, tsdb, TD_FILE_READ | TD_FILE_WRITE, &ctx->fd, 0), &lino, _exit);
@ -167,7 +165,7 @@ _exit:
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code));
} }
TARRAY2_DESTROY(ctx->brinBlkArray, NULL); TARRAY2_DESTROY(ctx->brinBlkArray, NULL);
(void)tBrinBlockDestroy(ctx->brinBlock); tBrinBlockDestroy(ctx->brinBlock);
tBlockDataDestroy(ctx->blockData); tBlockDataDestroy(ctx->blockData);
tMapDataClear(ctx->mDataBlk); tMapDataClear(ctx->mDataBlk);
taosArrayDestroy(ctx->aBlockIdx); taosArrayDestroy(ctx->aBlockIdx);
@ -321,7 +319,7 @@ static int32_t tsdbUpgradeStt(STsdb *tsdb, SDFileSet *pDFileSet, SDataFReader *r
if (TARRAY2_SIZE(lvl->fobjArr) > 0) { if (TARRAY2_SIZE(lvl->fobjArr) > 0) {
TAOS_CHECK_GOTO(TARRAY2_APPEND(fset->lvlArr, lvl), &lino, _exit); TAOS_CHECK_GOTO(TARRAY2_APPEND(fset->lvlArr, lvl), &lino, _exit);
} else { } else {
(void)tsdbSttLvlClear(&lvl); tsdbSttLvlClear(&lvl);
} }
_exit: _exit:
@ -358,7 +356,7 @@ static int32_t tsdbUpgradeFileSet(STsdb *tsdb, SDFileSet *pDFileSet, TFileSetArr
TAOS_CHECK_GOTO(tsdbUpgradeStt(tsdb, pDFileSet, reader, fset), &lino, _exit); TAOS_CHECK_GOTO(tsdbUpgradeStt(tsdb, pDFileSet, reader, fset), &lino, _exit);
} }
(void)tsdbDataFReaderClose(&reader); tsdbDataFReaderClose(&reader);
TAOS_CHECK_GOTO(TARRAY2_APPEND(fileSetArray, fset), &lino, _exit); TAOS_CHECK_GOTO(TARRAY2_APPEND(fileSetArray, fset), &lino, _exit);
@ -570,7 +568,7 @@ _exit:
if (code) { if (code) {
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code));
} }
(void)tsdbDelFReaderClose(&reader); tsdbDelFReaderClose(&reader);
taosArrayDestroy(aDelIdx); taosArrayDestroy(aDelIdx);
return code; return code;
} }
@ -612,7 +610,7 @@ static int32_t tsdbUpgradeFileSystem(STsdb *tsdb, int8_t rollback) {
// save new file system // save new file system
char fname[TSDB_FILENAME_LEN]; char fname[TSDB_FILENAME_LEN];
(void)current_fname(tsdb, fname, TSDB_FCURRENT); current_fname(tsdb, fname, TSDB_FCURRENT);
TAOS_CHECK_GOTO(save_fs(fileSetArray, fname), &lino, _exit); TAOS_CHECK_GOTO(save_fs(fileSetArray, fname), &lino, _exit);
_exit: _exit:
@ -632,6 +630,6 @@ int32_t tsdbCheckAndUpgradeFileSystem(STsdb *tsdb, int8_t rollback) {
TAOS_CHECK_RETURN(tsdbUpgradeFileSystem(tsdb, rollback)); TAOS_CHECK_RETURN(tsdbUpgradeFileSystem(tsdb, rollback));
(void)taosRemoveFile(fname); tsdbRemoveFile(fname);
return 0; return 0;
} }

View File

@ -106,7 +106,7 @@ _exit:
#endif #endif
void tMapDataGetItemByIdx(SMapData *pMapData, int32_t idx, void *pItem, int32_t (*tGetItemFn)(uint8_t *, void *)) { void tMapDataGetItemByIdx(SMapData *pMapData, int32_t idx, void *pItem, int32_t (*tGetItemFn)(uint8_t *, void *)) {
(void)tGetItemFn(pMapData->pData + pMapData->aOffset[idx], pItem); TAOS_UNUSED(tGetItemFn(pMapData->pData + pMapData->aOffset[idx], pItem));
} }
#ifdef BUILD_NO_CALL #ifdef BUILD_NO_CALL

View File

@ -84,12 +84,12 @@ int32_t tStatisBlockInit(STbStatisBlock *statisBlock) {
_exit: _exit:
if (code) { if (code) {
TAOS_UNUSED(tStatisBlockDestroy(statisBlock)); tStatisBlockDestroy(statisBlock);
} }
return code; return code;
} }
int32_t tStatisBlockDestroy(STbStatisBlock *statisBlock) { void tStatisBlockDestroy(STbStatisBlock *statisBlock) {
statisBlock->numOfPKs = 0; statisBlock->numOfPKs = 0;
statisBlock->numOfRecords = 0; statisBlock->numOfRecords = 0;
for (int32_t i = 0; i < ARRAY_SIZE(statisBlock->buffers); ++i) { for (int32_t i = 0; i < ARRAY_SIZE(statisBlock->buffers); ++i) {
@ -99,7 +99,6 @@ int32_t tStatisBlockDestroy(STbStatisBlock *statisBlock) {
TAOS_UNUSED(tValueColumnDestroy(&statisBlock->firstKeyPKs[i])); TAOS_UNUSED(tValueColumnDestroy(&statisBlock->firstKeyPKs[i]));
TAOS_UNUSED(tValueColumnDestroy(&statisBlock->lastKeyPKs[i])); TAOS_UNUSED(tValueColumnDestroy(&statisBlock->lastKeyPKs[i]));
} }
return 0;
} }
int32_t tStatisBlockClear(STbStatisBlock *statisBlock) { int32_t tStatisBlockClear(STbStatisBlock *statisBlock) {
@ -244,12 +243,12 @@ int32_t tBrinBlockInit(SBrinBlock *brinBlock) {
_exit: _exit:
if (code) { if (code) {
(void)tBrinBlockDestroy(brinBlock); tBrinBlockDestroy(brinBlock);
} }
return code; return code;
} }
int32_t tBrinBlockDestroy(SBrinBlock *brinBlock) { void tBrinBlockDestroy(SBrinBlock *brinBlock) {
brinBlock->numOfPKs = 0; brinBlock->numOfPKs = 0;
brinBlock->numOfRecords = 0; brinBlock->numOfRecords = 0;
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->buffers); ++i) { for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->buffers); ++i) {
@ -259,10 +258,9 @@ int32_t tBrinBlockDestroy(SBrinBlock *brinBlock) {
TAOS_UNUSED(tValueColumnDestroy(&brinBlock->firstKeyPKs[i])); TAOS_UNUSED(tValueColumnDestroy(&brinBlock->firstKeyPKs[i]));
TAOS_UNUSED(tValueColumnDestroy(&brinBlock->lastKeyPKs[i])); TAOS_UNUSED(tValueColumnDestroy(&brinBlock->lastKeyPKs[i]));
} }
return 0;
} }
int32_t tBrinBlockClear(SBrinBlock *brinBlock) { void tBrinBlockClear(SBrinBlock *brinBlock) {
brinBlock->numOfPKs = 0; brinBlock->numOfPKs = 0;
brinBlock->numOfRecords = 0; brinBlock->numOfRecords = 0;
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->buffers); ++i) { for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->buffers); ++i) {
@ -272,7 +270,6 @@ int32_t tBrinBlockClear(SBrinBlock *brinBlock) {
TAOS_UNUSED(tValueColumnClear(&brinBlock->firstKeyPKs[i])); TAOS_UNUSED(tValueColumnClear(&brinBlock->firstKeyPKs[i]));
TAOS_UNUSED(tValueColumnClear(&brinBlock->lastKeyPKs[i])); TAOS_UNUSED(tValueColumnClear(&brinBlock->lastKeyPKs[i]));
} }
return 0;
} }
int32_t tBrinBlockPut(SBrinBlock *brinBlock, const SBrinRecord *record) { int32_t tBrinBlockPut(SBrinBlock *brinBlock, const SBrinRecord *record) {

View File

@ -112,7 +112,7 @@ typedef struct {
#define STATIS_BLOCK_SIZE(db) ((db)->numOfRecords) #define STATIS_BLOCK_SIZE(db) ((db)->numOfRecords)
int32_t tStatisBlockInit(STbStatisBlock *statisBlock); int32_t tStatisBlockInit(STbStatisBlock *statisBlock);
int32_t tStatisBlockDestroy(STbStatisBlock *statisBlock); void tStatisBlockDestroy(STbStatisBlock *statisBlock);
int32_t tStatisBlockClear(STbStatisBlock *statisBlock); int32_t tStatisBlockClear(STbStatisBlock *statisBlock);
int32_t tStatisBlockPut(STbStatisBlock *statisBlock, SRowInfo *row, int32_t maxRecords); int32_t tStatisBlockPut(STbStatisBlock *statisBlock, SRowInfo *row, int32_t maxRecords);
int32_t tStatisBlockGet(STbStatisBlock *statisBlock, int32_t idx, STbStatisRecord *record); int32_t tStatisBlockGet(STbStatisBlock *statisBlock, int32_t idx, STbStatisRecord *record);
@ -179,8 +179,8 @@ typedef TARRAY2(SBrinBlk) TBrinBlkArray;
#define BRIN_BLOCK_SIZE(db) ((db)->numOfRecords) #define BRIN_BLOCK_SIZE(db) ((db)->numOfRecords)
int32_t tBrinBlockInit(SBrinBlock *brinBlock); int32_t tBrinBlockInit(SBrinBlock *brinBlock);
int32_t tBrinBlockDestroy(SBrinBlock *brinBlock); void tBrinBlockDestroy(SBrinBlock *brinBlock);
int32_t tBrinBlockClear(SBrinBlock *brinBlock); void tBrinBlockClear(SBrinBlock *brinBlock);
int32_t tBrinBlockPut(SBrinBlock *brinBlock, const SBrinRecord *record); int32_t tBrinBlockPut(SBrinBlock *brinBlock, const SBrinRecord *record);
int32_t tBrinBlockGet(SBrinBlock *brinBlock, int32_t idx, SBrinRecord *record); int32_t tBrinBlockGet(SBrinBlock *brinBlock, int32_t idx, SBrinRecord *record);

View File

@ -122,7 +122,7 @@ SVAsync *vnodeAsyncs[3];
#define MIN_ASYNC_ID 1 #define MIN_ASYNC_ID 1
#define MAX_ASYNC_ID (sizeof(vnodeAsyncs) / sizeof(vnodeAsyncs[0]) - 1) #define MAX_ASYNC_ID (sizeof(vnodeAsyncs) / sizeof(vnodeAsyncs[0]) - 1)
static int32_t vnodeAsyncTaskDone(SVAsync *async, SVATask *task) { static void vnodeAsyncTaskDone(SVAsync *async, SVATask *task) {
int32_t ret; int32_t ret;
if (task->channel != NULL && task->channel->scheduled == task) { if (task->channel != NULL && task->channel->scheduled == task) {
@ -176,10 +176,9 @@ static int32_t vnodeAsyncTaskDone(SVAsync *async, SVATask *task) {
} else { } else {
(void)taosThreadCondBroadcast(&task->waitCond); (void)taosThreadCondBroadcast(&task->waitCond);
} }
return 0;
} }
static int32_t vnodeAsyncCancelAllTasks(SVAsync *async, SArray *cancelArray) { static void vnodeAsyncCancelAllTasks(SVAsync *async, SArray *cancelArray) {
while (async->queue[0].next != &async->queue[0] || async->queue[1].next != &async->queue[1] || while (async->queue[0].next != &async->queue[0] || async->queue[1].next != &async->queue[1] ||
async->queue[2].next != &async->queue[2]) { async->queue[2].next != &async->queue[2]) {
for (int32_t i = 0; i < EVA_PRIORITY_MAX; i++) { for (int32_t i = 0; i < EVA_PRIORITY_MAX; i++) {
@ -193,11 +192,10 @@ static int32_t vnodeAsyncCancelAllTasks(SVAsync *async, SArray *cancelArray) {
.arg = task->arg, .arg = task->arg,
})); }));
} }
(void)vnodeAsyncTaskDone(async, task); vnodeAsyncTaskDone(async, task);
} }
} }
} }
return 0;
} }
static void *vnodeAsyncLoop(void *arg) { static void *vnodeAsyncLoop(void *arg) {
@ -215,14 +213,14 @@ static void *vnodeAsyncLoop(void *arg) {
// finish last running task // finish last running task
if (worker->runningTask != NULL) { if (worker->runningTask != NULL) {
(void)vnodeAsyncTaskDone(async, worker->runningTask); vnodeAsyncTaskDone(async, worker->runningTask);
worker->runningTask = NULL; worker->runningTask = NULL;
} }
for (;;) { for (;;) {
if (async->stop || worker->workerId >= async->numWorkers) { if (async->stop || worker->workerId >= async->numWorkers) {
if (async->stop) { // cancel all tasks if (async->stop) { // cancel all tasks
(void)vnodeAsyncCancelAllTasks(async, cancelArray); vnodeAsyncCancelAllTasks(async, cancelArray);
} }
worker->state = EVA_WORKER_STATE_STOP; worker->state = EVA_WORKER_STATE_STOP;
async->numLaunchWorkers--; async->numLaunchWorkers--;
@ -269,7 +267,8 @@ static void *vnodeAsyncLoop(void *arg) {
(void)taosThreadMutexUnlock(&async->mutex); (void)taosThreadMutexUnlock(&async->mutex);
// do run the task // do run the task
(void)worker->runningTask->execute(worker->runningTask->arg); int32_t code = worker->runningTask->execute(worker->runningTask->arg);
TAOS_UNUSED(code);
} }
_exit: _exit:
@ -369,7 +368,7 @@ static int32_t vnodeAsyncInit(SVAsync **async, const char *label) {
} }
ret = vHashInit(&(*async)->taskTable, vnodeAsyncTaskHash, vnodeAsyncTaskCompare); ret = vHashInit(&(*async)->taskTable, vnodeAsyncTaskHash, vnodeAsyncTaskCompare);
if (ret != 0) { if (ret != 0) {
(void)vHashDestroy(&(*async)->channelTable); vHashDestroy(&(*async)->channelTable);
(void)taosThreadMutexDestroy(&(*async)->mutex); (void)taosThreadMutexDestroy(&(*async)->mutex);
(void)taosThreadCondDestroy(&(*async)->hasTask); (void)taosThreadCondDestroy(&(*async)->hasTask);
taosMemoryFree(*async); taosMemoryFree(*async);
@ -418,29 +417,32 @@ static int32_t vnodeAsyncDestroy(SVAsync **async) {
(void)taosThreadMutexDestroy(&(*async)->mutex); (void)taosThreadMutexDestroy(&(*async)->mutex);
(void)taosThreadCondDestroy(&(*async)->hasTask); (void)taosThreadCondDestroy(&(*async)->hasTask);
(void)vHashDestroy(&(*async)->channelTable); vHashDestroy(&(*async)->channelTable);
(void)vHashDestroy(&(*async)->taskTable); vHashDestroy(&(*async)->taskTable);
taosMemoryFree(*async); taosMemoryFree(*async);
*async = NULL; *async = NULL;
return 0; return 0;
} }
static int32_t vnodeAsyncLaunchWorker(SVAsync *async) { static void vnodeAsyncLaunchWorker(SVAsync *async) {
for (int32_t i = 0; i < async->numWorkers; i++) { for (int32_t i = 0; i < async->numWorkers; i++) {
if (async->workers[i].state == EVA_WORKER_STATE_ACTIVE) { if (async->workers[i].state == EVA_WORKER_STATE_ACTIVE) {
continue; continue;
} else if (async->workers[i].state == EVA_WORKER_STATE_STOP) { } else if (async->workers[i].state == EVA_WORKER_STATE_STOP) {
(void)taosThreadJoin(async->workers[i].thread, NULL); TAOS_UNUSED(taosThreadJoin(async->workers[i].thread, NULL));
async->workers[i].state = EVA_WORKER_STATE_UINIT; async->workers[i].state = EVA_WORKER_STATE_UINIT;
} }
(void)taosThreadCreate(&async->workers[i].thread, NULL, vnodeAsyncLoop, &async->workers[i]); int32_t ret = taosThreadCreate(&async->workers[i].thread, NULL, vnodeAsyncLoop, &async->workers[i]);
async->workers[i].state = EVA_WORKER_STATE_ACTIVE; if (ret) {
async->numLaunchWorkers++; vError("failed to create worker thread since %s", tstrerror(ret));
} else {
async->workers[i].state = EVA_WORKER_STATE_ACTIVE;
async->numLaunchWorkers++;
}
break; break;
} }
return 0;
} }
int32_t vnodeAsyncOpen(int32_t numOfThreads) { int32_t vnodeAsyncOpen(int32_t numOfThreads) {
@ -450,21 +452,25 @@ int32_t vnodeAsyncOpen(int32_t numOfThreads) {
// vnode-commit // vnode-commit
code = vnodeAsyncInit(&vnodeAsyncs[1], "vnode-commit"); code = vnodeAsyncInit(&vnodeAsyncs[1], "vnode-commit");
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
(void)vnodeAsyncSetWorkers(1, numOfThreads);
code = vnodeAsyncSetWorkers(1, numOfThreads);
TSDB_CHECK_CODE(code, lino, _exit);
// vnode-merge // vnode-merge
code = vnodeAsyncInit(&vnodeAsyncs[2], "vnode-merge"); code = vnodeAsyncInit(&vnodeAsyncs[2], "vnode-merge");
TSDB_CHECK_CODE(code, lino, _exit); TSDB_CHECK_CODE(code, lino, _exit);
(void)vnodeAsyncSetWorkers(2, numOfThreads);
code = vnodeAsyncSetWorkers(2, numOfThreads);
TSDB_CHECK_CODE(code, lino, _exit);
_exit: _exit:
return code; return code;
} }
int32_t vnodeAsyncClose() { void vnodeAsyncClose() {
(void)vnodeAsyncDestroy(&vnodeAsyncs[1]); int32_t ret;
(void)vnodeAsyncDestroy(&vnodeAsyncs[2]); ret = vnodeAsyncDestroy(&vnodeAsyncs[1]);
return 0; ret = vnodeAsyncDestroy(&vnodeAsyncs[2]);
} }
int32_t vnodeAsync(SVAChannelID *channelID, EVAPriority priority, int32_t (*execute)(void *), void (*cancel)(void *), int32_t vnodeAsync(SVAChannelID *channelID, EVAPriority priority, int32_t (*execute)(void *), void (*cancel)(void *),
@ -474,6 +480,7 @@ int32_t vnodeAsync(SVAChannelID *channelID, EVAPriority priority, int32_t (*exec
return TSDB_CODE_INVALID_PARA; return TSDB_CODE_INVALID_PARA;
} }
int32_t ret;
int64_t id; int64_t id;
SVAsync *async = vnodeAsyncs[channelID->async]; SVAsync *async = vnodeAsyncs[channelID->async];
@ -501,7 +508,8 @@ int32_t vnodeAsync(SVAChannelID *channelID, EVAPriority priority, int32_t (*exec
SVAChannel channel = { SVAChannel channel = {
.channelId = channelID->id, .channelId = channelID->id,
}; };
(void)vHashGet(async->channelTable, &channel, (void **)&task->channel); ret = vHashGet(async->channelTable, &channel, (void **)&task->channel);
TAOS_UNUSED(ret);
if (task->channel == NULL) { if (task->channel == NULL) {
(void)taosThreadMutexUnlock(&async->mutex); (void)taosThreadMutexUnlock(&async->mutex);
(void)taosThreadCondDestroy(&task->waitCond); (void)taosThreadCondDestroy(&task->waitCond);
@ -513,7 +521,7 @@ int32_t vnodeAsync(SVAChannelID *channelID, EVAPriority priority, int32_t (*exec
task->taskId = id = ++async->nextTaskId; task->taskId = id = ++async->nextTaskId;
// add task to hash table // add task to hash table
int32_t ret = vHashPut(async->taskTable, task); ret = vHashPut(async->taskTable, task);
if (ret != 0) { if (ret != 0) {
(void)taosThreadMutexUnlock(&async->mutex); (void)taosThreadMutexUnlock(&async->mutex);
(void)taosThreadCondDestroy(&task->waitCond); (void)taosThreadCondDestroy(&task->waitCond);
@ -539,7 +547,7 @@ int32_t vnodeAsync(SVAChannelID *channelID, EVAPriority priority, int32_t (*exec
if (async->numIdleWorkers > 0) { if (async->numIdleWorkers > 0) {
(void)taosThreadCondSignal(&(async->hasTask)); (void)taosThreadCondSignal(&(async->hasTask));
} else if (async->numLaunchWorkers < async->numWorkers) { } else if (async->numLaunchWorkers < async->numWorkers) {
(void)vnodeAsyncLaunchWorker(async); vnodeAsyncLaunchWorker(async);
} }
} else if (task->channel->scheduled->state == EVA_TASK_STATE_RUNNING || } else if (task->channel->scheduled->state == EVA_TASK_STATE_RUNNING ||
priority >= VATASK_PIORITY(task->channel->scheduled)) { priority >= VATASK_PIORITY(task->channel->scheduled)) {
@ -579,9 +587,9 @@ int32_t vnodeAsync(SVAChannelID *channelID, EVAPriority priority, int32_t (*exec
return 0; return 0;
} }
int32_t vnodeAWait(SVATaskID *taskID) { void vnodeAWait(SVATaskID *taskID) {
if (taskID == NULL || taskID->async < MIN_ASYNC_ID || taskID->async > MAX_ASYNC_ID || taskID->id <= 0) { if (taskID == NULL || taskID->async < MIN_ASYNC_ID || taskID->async > MAX_ASYNC_ID || taskID->id <= 0) {
return TSDB_CODE_INVALID_PARA; return;
} }
SVAsync *async = vnodeAsyncs[taskID->async]; SVAsync *async = vnodeAsyncs[taskID->async];
@ -592,7 +600,7 @@ int32_t vnodeAWait(SVATaskID *taskID) {
(void)taosThreadMutexLock(&async->mutex); (void)taosThreadMutexLock(&async->mutex);
(void)vHashGet(async->taskTable, &task2, (void **)&task); int32_t ret = vHashGet(async->taskTable, &task2, (void **)&task);
if (task) { if (task) {
task->numWait++; task->numWait++;
(void)taosThreadCondWait(&task->waitCond, &async->mutex); (void)taosThreadCondWait(&task->waitCond, &async->mutex);
@ -605,8 +613,6 @@ int32_t vnodeAWait(SVATaskID *taskID) {
} }
(void)taosThreadMutexUnlock(&async->mutex); (void)taosThreadMutexUnlock(&async->mutex);
return 0;
} }
int32_t vnodeACancel(SVATaskID *taskID) { int32_t vnodeACancel(SVATaskID *taskID) {
@ -625,14 +631,14 @@ int32_t vnodeACancel(SVATaskID *taskID) {
(void)taosThreadMutexLock(&async->mutex); (void)taosThreadMutexLock(&async->mutex);
(void)vHashGet(async->taskTable, &task2, (void **)&task); ret = vHashGet(async->taskTable, &task2, (void **)&task);
if (task) { if (task) {
if (task->state == EVA_TASK_STATE_WAITTING) { if (task->state == EVA_TASK_STATE_WAITTING) {
cancel = task->cancel; cancel = task->cancel;
arg = task->arg; arg = task->arg;
task->next->prev = task->prev; task->next->prev = task->prev;
task->prev->next = task->next; task->prev->next = task->next;
(void)vnodeAsyncTaskDone(async, task); vnodeAsyncTaskDone(async, task);
} else { } else {
ret = TSDB_CODE_FAILED; ret = TSDB_CODE_FAILED;
} }
@ -651,6 +657,7 @@ int32_t vnodeAsyncSetWorkers(int64_t asyncID, int32_t numWorkers) {
if (asyncID < MIN_ASYNC_ID || asyncID > MAX_ASYNC_ID || numWorkers <= 0 || numWorkers > VNODE_ASYNC_MAX_WORKERS) { if (asyncID < MIN_ASYNC_ID || asyncID > MAX_ASYNC_ID || numWorkers <= 0 || numWorkers > VNODE_ASYNC_MAX_WORKERS) {
return TSDB_CODE_INVALID_PARA; return TSDB_CODE_INVALID_PARA;
} }
int32_t ret;
SVAsync *async = vnodeAsyncs[asyncID]; SVAsync *async = vnodeAsyncs[asyncID];
(void)taosThreadMutexLock(&async->mutex); (void)taosThreadMutexLock(&async->mutex);
async->numWorkers = numWorkers; async->numWorkers = numWorkers;
@ -725,12 +732,13 @@ int32_t vnodeAChannelDestroy(SVAChannelID *channelID, bool waitRunning) {
(void)taosThreadMutexLock(&async->mutex); (void)taosThreadMutexLock(&async->mutex);
(void)vHashGet(async->channelTable, &channel2, (void **)&channel); int32_t ret = vHashGet(async->channelTable, &channel2, (void **)&channel);
TAOS_UNUSED(ret);
if (channel) { if (channel) {
// unregister channel // unregister channel
channel->next->prev = channel->prev; channel->next->prev = channel->prev;
channel->prev->next = channel->next; channel->prev->next = channel->next;
(void)vHashDrop(async->channelTable, channel); ret = vHashDrop(async->channelTable, channel);
async->numChannels--; async->numChannels--;
// cancel all waiting tasks // cancel all waiting tasks
@ -745,7 +753,7 @@ int32_t vnodeAChannelDestroy(SVAChannelID *channelID, bool waitRunning) {
.arg = task->arg, .arg = task->arg,
})); }));
} }
(void)vnodeAsyncTaskDone(async, task); vnodeAsyncTaskDone(async, task);
} }
} }
@ -760,7 +768,7 @@ int32_t vnodeAChannelDestroy(SVAChannelID *channelID, bool waitRunning) {
.arg = channel->scheduled->arg, .arg = channel->scheduled->arg,
})); }));
} }
(void)vnodeAsyncTaskDone(async, channel->scheduled); vnodeAsyncTaskDone(async, channel->scheduled);
} }
taosMemoryFree(channel); taosMemoryFree(channel);
} else { } else {

View File

@ -58,7 +58,7 @@ static int32_t vnodeBufPoolCreate(SVnode *pVnode, int32_t id, int64_t size, SVBu
return 0; return 0;
} }
static int vnodeBufPoolDestroy(SVBufPool *pPool) { static void vnodeBufPoolDestroy(SVBufPool *pPool) {
vnodeBufPoolReset(pPool); vnodeBufPoolReset(pPool);
if (pPool->lock) { if (pPool->lock) {
(void)taosThreadSpinDestroy(pPool->lock); (void)taosThreadSpinDestroy(pPool->lock);
@ -66,7 +66,6 @@ static int vnodeBufPoolDestroy(SVBufPool *pPool) {
} }
(void)taosThreadMutexDestroy(&pPool->mutex); (void)taosThreadMutexDestroy(&pPool->mutex);
taosMemoryFree(pPool); taosMemoryFree(pPool);
return 0;
} }
int vnodeOpenBufPool(SVnode *pVnode) { int vnodeOpenBufPool(SVnode *pVnode) {
@ -77,7 +76,7 @@ int vnodeOpenBufPool(SVnode *pVnode) {
int32_t code; int32_t code;
if ((code = vnodeBufPoolCreate(pVnode, i, size, &pVnode->aBufPool[i]))) { if ((code = vnodeBufPoolCreate(pVnode, i, size, &pVnode->aBufPool[i]))) {
vError("vgId:%d, failed to open vnode buffer pool since %s", TD_VID(pVnode), tstrerror(terrno)); vError("vgId:%d, failed to open vnode buffer pool since %s", TD_VID(pVnode), tstrerror(terrno));
(void)vnodeCloseBufPool(pVnode); vnodeCloseBufPool(pVnode);
return code; return code;
} }
@ -90,16 +89,15 @@ int vnodeOpenBufPool(SVnode *pVnode) {
return 0; return 0;
} }
int vnodeCloseBufPool(SVnode *pVnode) { void vnodeCloseBufPool(SVnode *pVnode) {
for (int32_t i = 0; i < VNODE_BUFPOOL_SEGMENTS; i++) { for (int32_t i = 0; i < VNODE_BUFPOOL_SEGMENTS; i++) {
if (pVnode->aBufPool[i]) { if (pVnode->aBufPool[i]) {
(void)vnodeBufPoolDestroy(pVnode->aBufPool[i]); vnodeBufPoolDestroy(pVnode->aBufPool[i]);
pVnode->aBufPool[i] = NULL; pVnode->aBufPool[i] = NULL;
} }
} }
vDebug("vgId:%d, vnode buffer pool is closed", TD_VID(pVnode)); vDebug("vgId:%d, vnode buffer pool is closed", TD_VID(pVnode));
return 0;
} }
void vnodeBufPoolReset(SVBufPool *pPool) { void vnodeBufPoolReset(SVBufPool *pPool) {
@ -234,7 +232,7 @@ void vnodeBufPoolAddToFreeList(SVBufPool *pPool) {
vInfo("vgId:%d, buffer pool of id %d size changed from %" PRId64 " to %" PRId64, TD_VID(pVnode), pPool->id, vInfo("vgId:%d, buffer pool of id %d size changed from %" PRId64 " to %" PRId64, TD_VID(pVnode), pPool->id,
pPool->node.size, size); pPool->node.size, size);
(void)vnodeBufPoolDestroy(pPool); vnodeBufPoolDestroy(pPool);
pPool = pNewPool; pPool = pNewPool;
pVnode->aBufPool[pPool->id] = pPool; pVnode->aBufPool[pPool->id] = pPool;
} }
@ -286,7 +284,7 @@ _exit:
return; return;
} }
int32_t vnodeBufPoolRegisterQuery(SVBufPool *pPool, SQueryNode *pQNode) { void vnodeBufPoolRegisterQuery(SVBufPool *pPool, SQueryNode *pQNode) {
(void)taosThreadMutexLock(&pPool->mutex); (void)taosThreadMutexLock(&pPool->mutex);
pQNode->pNext = pPool->qList.pNext; pQNode->pNext = pPool->qList.pNext;
@ -296,7 +294,6 @@ int32_t vnodeBufPoolRegisterQuery(SVBufPool *pPool, SQueryNode *pQNode) {
pPool->nQuery++; pPool->nQuery++;
(void)taosThreadMutexUnlock(&pPool->mutex); (void)taosThreadMutexUnlock(&pPool->mutex);
return 0;
} }
void vnodeBufPoolDeregisterQuery(SVBufPool *pPool, SQueryNode *pQNode, bool proactive) { void vnodeBufPoolDeregisterQuery(SVBufPool *pPool, SQueryNode *pQNode, bool proactive) {

Some files were not shown because too many files have changed in this diff Show More