Merge branch '3.0' into cpwu/3.0
This commit is contained in:
commit
9964ba4e86
|
@ -7,7 +7,7 @@ project(
|
||||||
)
|
)
|
||||||
|
|
||||||
if (NOT DEFINED TD_SOURCE_DIR)
|
if (NOT DEFINED TD_SOURCE_DIR)
|
||||||
set( TD_SOURCE_DIR ${CMAKE_SOURCE_DIR} )
|
set( TD_SOURCE_DIR ${PROJECT_SOURCE_DIR} )
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(TD_SUPPORT_DIR "${TD_SOURCE_DIR}/cmake")
|
set(TD_SUPPORT_DIR "${TD_SOURCE_DIR}/cmake")
|
||||||
|
|
|
@ -30,6 +30,7 @@ target_link_libraries(demoapi
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(tmq
|
target_include_directories(tmq
|
||||||
|
PUBLIC "${TD_SOURCE_DIR}/include/os"
|
||||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "taos.h"
|
#include "taos.h"
|
||||||
|
#include "osSleep.h"
|
||||||
|
|
||||||
static int running = 1;
|
static int running = 1;
|
||||||
static void msg_process(TAOS_RES* msg) {
|
static void msg_process(TAOS_RES* msg) {
|
||||||
|
@ -101,8 +102,8 @@ int32_t create_topic() {
|
||||||
}
|
}
|
||||||
taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
|
|
||||||
/*pRes = taos_query(pConn, "create topic topic_ctb_column as abc1");*/
|
pRes = taos_query(pConn, "create topic topic_ctb_column as abc1");
|
||||||
pRes = taos_query(pConn, "create topic topic_ctb_column as select ts, c1, c2, c3 from ct1");
|
/*pRes = taos_query(pConn, "create topic topic_ctb_column as select ts, c1, c2, c3 from ct1");*/
|
||||||
if (taos_errno(pRes) != 0) {
|
if (taos_errno(pRes) != 0) {
|
||||||
printf("failed to create topic topic_ctb_column, reason:%s\n", taos_errstr(pRes));
|
printf("failed to create topic topic_ctb_column, reason:%s\n", taos_errstr(pRes));
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -160,9 +161,10 @@ tmq_t* build_consumer() {
|
||||||
tmq_conf_set(conf, "group.id", "tg2");
|
tmq_conf_set(conf, "group.id", "tg2");
|
||||||
tmq_conf_set(conf, "td.connect.user", "root");
|
tmq_conf_set(conf, "td.connect.user", "root");
|
||||||
tmq_conf_set(conf, "td.connect.pass", "taosdata");
|
tmq_conf_set(conf, "td.connect.pass", "taosdata");
|
||||||
tmq_conf_set(conf, "td.connect.db", "abc1");
|
/*tmq_conf_set(conf, "td.connect.db", "abc1");*/
|
||||||
tmq_conf_set_offset_commit_cb(conf, tmq_commit_cb_print);
|
tmq_conf_set_offset_commit_cb(conf, tmq_commit_cb_print);
|
||||||
tmq_t* tmq = tmq_consumer_new(conf, NULL, 0);
|
tmq_t* tmq = tmq_consumer_new(conf, NULL, 0);
|
||||||
|
assert(tmq);
|
||||||
return tmq;
|
return tmq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,10 +267,11 @@ void perf_loop(tmq_t* tmq, tmq_list_t* topics) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
int code;
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
printf("env init\n");
|
printf("env init\n");
|
||||||
code = init_env();
|
if (init_env() < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
create_topic();
|
create_topic();
|
||||||
}
|
}
|
||||||
tmq_t* tmq = build_consumer();
|
tmq_t* tmq = build_consumer();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
PROJECT(TDengine)
|
PROJECT(TDengine)
|
||||||
|
|
||||||
IF (TD_LINUX)
|
IF (TD_LINUX)
|
||||||
INCLUDE_DIRECTORIES(. ${TD_COMMUNITY_DIR}/src/inc ${TD_COMMUNITY_DIR}/src/client/inc ${TD_COMMUNITY_DIR}/inc)
|
INCLUDE_DIRECTORIES(. ${TD_SOURCE_DIR}/src/inc ${TD_SOURCE_DIR}/src/client/inc ${TD_SOURCE_DIR}/inc)
|
||||||
AUX_SOURCE_DIRECTORY(. SRC)
|
AUX_SOURCE_DIRECTORY(. SRC)
|
||||||
ADD_EXECUTABLE(demo apitest.c)
|
ADD_EXECUTABLE(demo apitest.c)
|
||||||
TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread )
|
TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread )
|
||||||
|
@ -13,7 +13,7 @@ IF (TD_LINUX)
|
||||||
TARGET_LINK_LIBRARIES(epoll taos_static trpc tutil pthread lua)
|
TARGET_LINK_LIBRARIES(epoll taos_static trpc tutil pthread lua)
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
IF (TD_DARWIN)
|
IF (TD_DARWIN)
|
||||||
INCLUDE_DIRECTORIES(. ${TD_COMMUNITY_DIR}/src/inc ${TD_COMMUNITY_DIR}/src/client/inc ${TD_COMMUNITY_DIR}/inc)
|
INCLUDE_DIRECTORIES(. ${TD_SOURCE_DIR}/src/inc ${TD_SOURCE_DIR}/src/client/inc ${TD_SOURCE_DIR}/inc)
|
||||||
AUX_SOURCE_DIRECTORY(. SRC)
|
AUX_SOURCE_DIRECTORY(. SRC)
|
||||||
ADD_EXECUTABLE(demo demo.c)
|
ADD_EXECUTABLE(demo demo.c)
|
||||||
TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread lua)
|
TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread lua)
|
||||||
|
|
|
@ -27,10 +27,7 @@ typedef void TAOS;
|
||||||
typedef void TAOS_STMT;
|
typedef void TAOS_STMT;
|
||||||
typedef void TAOS_RES;
|
typedef void TAOS_RES;
|
||||||
typedef void **TAOS_ROW;
|
typedef void **TAOS_ROW;
|
||||||
#if 0
|
typedef void TAOS_SUB;
|
||||||
typedef void TAOS_STREAM;
|
|
||||||
#endif
|
|
||||||
typedef void TAOS_SUB;
|
|
||||||
|
|
||||||
// Data type definition
|
// Data type definition
|
||||||
#define TSDB_DATA_TYPE_NULL 0 // 1 bytes
|
#define TSDB_DATA_TYPE_NULL 0 // 1 bytes
|
||||||
|
@ -88,17 +85,21 @@ typedef struct taosField {
|
||||||
int32_t bytes;
|
int32_t bytes;
|
||||||
} TAOS_FIELD;
|
} TAOS_FIELD;
|
||||||
|
|
||||||
#define DLL_EXPORT
|
#ifdef WINDOWS
|
||||||
|
#define DLL_EXPORT __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define DLL_EXPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef void (*__taos_async_fn_t)(void *param, TAOS_RES *, int code);
|
typedef void (*__taos_async_fn_t)(void *param, TAOS_RES *, int code);
|
||||||
|
|
||||||
typedef struct TAOS_BIND_v2 {
|
typedef struct TAOS_BIND_v2 {
|
||||||
int buffer_type;
|
int buffer_type;
|
||||||
void *buffer;
|
void *buffer;
|
||||||
int32_t buffer_length;
|
int32_t buffer_length;
|
||||||
int32_t *length;
|
int32_t *length;
|
||||||
char *is_null;
|
char *is_null;
|
||||||
int num;
|
int num;
|
||||||
} TAOS_BIND_v2;
|
} TAOS_BIND_v2;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -128,35 +129,35 @@ DLL_EXPORT void taos_close(TAOS *taos);
|
||||||
|
|
||||||
const char *taos_data_type(int type);
|
const char *taos_data_type(int type);
|
||||||
|
|
||||||
DLL_EXPORT TAOS_STMT *taos_stmt_init(TAOS *taos);
|
DLL_EXPORT TAOS_STMT *taos_stmt_init(TAOS *taos);
|
||||||
DLL_EXPORT int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length);
|
DLL_EXPORT int taos_stmt_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_BIND_v2 *tags);
|
DLL_EXPORT int taos_stmt_set_tbname_tags(TAOS_STMT *stmt, const char *name, TAOS_BIND_v2 *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);
|
||||||
DLL_EXPORT int taos_stmt_set_sub_tbname(TAOS_STMT *stmt, const char *name);
|
DLL_EXPORT int taos_stmt_set_sub_tbname(TAOS_STMT *stmt, const char *name);
|
||||||
|
|
||||||
DLL_EXPORT int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert);
|
DLL_EXPORT int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert);
|
||||||
DLL_EXPORT int taos_stmt_num_params(TAOS_STMT *stmt, int *nums);
|
DLL_EXPORT int taos_stmt_num_params(TAOS_STMT *stmt, int *nums);
|
||||||
DLL_EXPORT int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes);
|
DLL_EXPORT int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes);
|
||||||
DLL_EXPORT int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_BIND_v2 *bind);
|
DLL_EXPORT int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_BIND_v2 *bind);
|
||||||
DLL_EXPORT int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_BIND_v2 *bind);
|
DLL_EXPORT int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_BIND_v2 *bind);
|
||||||
DLL_EXPORT int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_BIND_v2 *bind, int colIdx);
|
DLL_EXPORT int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_BIND_v2 *bind, int colIdx);
|
||||||
DLL_EXPORT int taos_stmt_add_batch(TAOS_STMT *stmt);
|
DLL_EXPORT int taos_stmt_add_batch(TAOS_STMT *stmt);
|
||||||
DLL_EXPORT int taos_stmt_execute(TAOS_STMT *stmt);
|
DLL_EXPORT int taos_stmt_execute(TAOS_STMT *stmt);
|
||||||
DLL_EXPORT TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt);
|
DLL_EXPORT TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt);
|
||||||
DLL_EXPORT int taos_stmt_close(TAOS_STMT *stmt);
|
DLL_EXPORT int taos_stmt_close(TAOS_STMT *stmt);
|
||||||
DLL_EXPORT char *taos_stmt_errstr(TAOS_STMT *stmt);
|
DLL_EXPORT char *taos_stmt_errstr(TAOS_STMT *stmt);
|
||||||
DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT *stmt);
|
DLL_EXPORT int taos_stmt_affected_rows(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);
|
||||||
|
|
||||||
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_l(TAOS *taos, const char *sql, int sqlLen);
|
DLL_EXPORT TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen);
|
||||||
|
|
||||||
DLL_EXPORT TAOS_ROW taos_fetch_row(TAOS_RES *res);
|
DLL_EXPORT TAOS_ROW taos_fetch_row(TAOS_RES *res);
|
||||||
DLL_EXPORT int taos_result_precision(TAOS_RES *res); // get the time precision of result
|
DLL_EXPORT int taos_result_precision(TAOS_RES *res); // get the time precision of result
|
||||||
DLL_EXPORT void taos_free_result(TAOS_RES *res);
|
DLL_EXPORT void taos_free_result(TAOS_RES *res);
|
||||||
DLL_EXPORT int taos_field_count(TAOS_RES *res);
|
DLL_EXPORT int taos_field_count(TAOS_RES *res);
|
||||||
DLL_EXPORT int taos_num_fields(TAOS_RES *res);
|
DLL_EXPORT int taos_num_fields(TAOS_RES *res);
|
||||||
DLL_EXPORT int taos_affected_rows(TAOS_RES *res);
|
DLL_EXPORT int taos_affected_rows(TAOS_RES *res);
|
||||||
|
|
||||||
DLL_EXPORT TAOS_FIELD *taos_fetch_fields(TAOS_RES *res);
|
DLL_EXPORT TAOS_FIELD *taos_fetch_fields(TAOS_RES *res);
|
||||||
DLL_EXPORT int taos_select_db(TAOS *taos, const char *db);
|
DLL_EXPORT int taos_select_db(TAOS *taos, const char *db);
|
||||||
|
@ -192,12 +193,6 @@ DLL_EXPORT TAOS_RES *taos_consume(TAOS_SUB *tsub);
|
||||||
DLL_EXPORT void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress);
|
DLL_EXPORT void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 0
|
|
||||||
DLL_EXPORT TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sql, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row),
|
|
||||||
int64_t stime, void *param, void (*callback)(void *));
|
|
||||||
DLL_EXPORT void taos_close_stream(TAOS_STREAM *tstr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
DLL_EXPORT int taos_load_table_info(TAOS *taos, const char *tableNameList);
|
DLL_EXPORT int taos_load_table_info(TAOS *taos, const char *tableNameList);
|
||||||
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);
|
||||||
|
|
||||||
|
@ -234,15 +229,11 @@ DLL_EXPORT tmq_t *tmq_consumer_new(tmq_conf_t *conf, char *errstr, int32_t errst
|
||||||
DLL_EXPORT const char *tmq_err2str(tmq_resp_err_t);
|
DLL_EXPORT const char *tmq_err2str(tmq_resp_err_t);
|
||||||
|
|
||||||
/* ------------------------TMQ CONSUMER INTERFACE------------------------ */
|
/* ------------------------TMQ CONSUMER INTERFACE------------------------ */
|
||||||
DLL_EXPORT tmq_resp_err_t tmq_subscribe(tmq_t *tmq, tmq_list_t *topic_list);
|
DLL_EXPORT tmq_resp_err_t tmq_subscribe(tmq_t *tmq, const tmq_list_t *topic_list);
|
||||||
DLL_EXPORT tmq_resp_err_t tmq_unsubscribe(tmq_t *tmq);
|
DLL_EXPORT tmq_resp_err_t tmq_unsubscribe(tmq_t *tmq);
|
||||||
DLL_EXPORT tmq_resp_err_t tmq_subscription(tmq_t *tmq, tmq_list_t **topics);
|
DLL_EXPORT tmq_resp_err_t tmq_subscription(tmq_t *tmq, tmq_list_t **topics);
|
||||||
DLL_EXPORT TAOS_RES *tmq_consumer_poll(tmq_t *tmq, int64_t blocking_time);
|
DLL_EXPORT TAOS_RES *tmq_consumer_poll(tmq_t *tmq, int64_t wait_time);
|
||||||
DLL_EXPORT tmq_resp_err_t tmq_consumer_close(tmq_t *tmq);
|
DLL_EXPORT tmq_resp_err_t tmq_consumer_close(tmq_t *tmq);
|
||||||
#if 0
|
|
||||||
DLL_EXPORT tmq_resp_err_t tmq_assign(tmq_t* tmq, const tmq_topic_vgroup_list_t* vgroups);
|
|
||||||
DLL_EXPORT tmq_resp_err_t tmq_assignment(tmq_t* tmq, tmq_topic_vgroup_list_t** vgroups);
|
|
||||||
#endif
|
|
||||||
DLL_EXPORT tmq_resp_err_t tmq_commit(tmq_t *tmq, const tmq_topic_vgroup_list_t *offsets, int32_t async);
|
DLL_EXPORT tmq_resp_err_t tmq_commit(tmq_t *tmq, const tmq_topic_vgroup_list_t *offsets, int32_t async);
|
||||||
#if 0
|
#if 0
|
||||||
DLL_EXPORT tmq_resp_err_t tmq_commit_message(tmq_t* tmq, const tmq_message_t* tmqmessage, int32_t async);
|
DLL_EXPORT tmq_resp_err_t tmq_commit_message(tmq_t* tmq, const tmq_message_t* tmqmessage, int32_t async);
|
||||||
|
@ -269,7 +260,7 @@ DLL_EXPORT char *tmq_get_topic_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);
|
||||||
// TODO
|
// TODO
|
||||||
#if 0
|
#if 0
|
||||||
DLL_EXPORT char *tmq_get_block_table_name(TAOS_RES *res);
|
DLL_EXPORT char *tmq_get_table_name(TAOS_RES *res);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
|
@ -99,6 +99,15 @@ typedef struct SColumnInfoData {
|
||||||
};
|
};
|
||||||
} SColumnInfoData;
|
} SColumnInfoData;
|
||||||
|
|
||||||
|
typedef struct SQueryTableDataCond {
|
||||||
|
STimeWindow twindow;
|
||||||
|
int32_t order; // desc|asc order to iterate the data block
|
||||||
|
int32_t numOfCols;
|
||||||
|
SColumnInfo *colList;
|
||||||
|
bool loadExternalRows; // load external rows or not
|
||||||
|
int32_t type; // data block load type:
|
||||||
|
} SQueryTableDataCond;
|
||||||
|
|
||||||
void* blockDataDestroy(SSDataBlock* pBlock);
|
void* blockDataDestroy(SSDataBlock* pBlock);
|
||||||
int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock);
|
int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock);
|
||||||
void* tDecodeDataBlock(const void* buf, SSDataBlock* pBlock);
|
void* tDecodeDataBlock(const void* buf, SSDataBlock* pBlock);
|
||||||
|
@ -229,7 +238,6 @@ typedef struct SResSchame {
|
||||||
char name[TSDB_COL_NAME_LEN];
|
char name[TSDB_COL_NAME_LEN];
|
||||||
} SResSchema;
|
} SResSchema;
|
||||||
|
|
||||||
// TODO move away to executor.h
|
|
||||||
typedef struct SExprBasicInfo {
|
typedef struct SExprBasicInfo {
|
||||||
SResSchema resSchema;
|
SResSchema resSchema;
|
||||||
int16_t numOfParams; // argument value of each function
|
int16_t numOfParams; // argument value of each function
|
||||||
|
|
|
@ -238,10 +238,16 @@ static FORCE_INLINE int32_t blockCompressColData(SColumnInfoData* pColRes, int32
|
||||||
|
|
||||||
static FORCE_INLINE void blockCompressEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_t numOfCols,
|
static FORCE_INLINE void blockCompressEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_t numOfCols,
|
||||||
int8_t needCompress) {
|
int8_t needCompress) {
|
||||||
int32_t* colSizes = (int32_t*)data;
|
int32_t* actualLen = (int32_t*) data;
|
||||||
|
data += sizeof(int32_t);
|
||||||
|
|
||||||
|
uint64_t* groupId = (uint64_t*) data;
|
||||||
|
data += sizeof(uint64_t);
|
||||||
|
|
||||||
|
int32_t* colSizes = (int32_t*)data;
|
||||||
data += numOfCols * sizeof(int32_t);
|
data += numOfCols * sizeof(int32_t);
|
||||||
*dataLen = (numOfCols * sizeof(int32_t));
|
|
||||||
|
*dataLen = (numOfCols * sizeof(int32_t) + sizeof(uint64_t) + sizeof(int32_t));
|
||||||
|
|
||||||
int32_t numOfRows = pBlock->info.rows;
|
int32_t numOfRows = pBlock->info.rows;
|
||||||
for (int32_t col = 0; col < numOfCols; ++col) {
|
for (int32_t col = 0; col < numOfCols; ++col) {
|
||||||
|
@ -273,6 +279,9 @@ static FORCE_INLINE void blockCompressEncode(const SSDataBlock* pBlock, char* da
|
||||||
|
|
||||||
colSizes[col] = htonl(colSizes[col]);
|
colSizes[col] = htonl(colSizes[col]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*actualLen = *dataLen;
|
||||||
|
*groupId = pBlock->info.groupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -123,9 +123,9 @@ extern SDiskCfg tsDiskCfg[];
|
||||||
|
|
||||||
#define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize)
|
#define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize)
|
||||||
|
|
||||||
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile,
|
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char **envCmd, const char *envFile,
|
||||||
const char *apolloUrl, SArray *pArgs, bool tsc);
|
char *apolloUrl, SArray *pArgs, bool tsc);
|
||||||
int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, SArray *pArgs, bool tsc);
|
int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc);
|
||||||
void taosCleanupCfg();
|
void taosCleanupCfg();
|
||||||
void taosCfgDynamicOptions(const char *option, const char *value);
|
void taosCfgDynamicOptions(const char *option, const char *value);
|
||||||
void taosAddDataDir(int32_t index, char *v1, int32_t level, int32_t primary);
|
void taosAddDataDir(int32_t index, char *v1, int32_t level, int32_t primary);
|
||||||
|
|
|
@ -227,8 +227,16 @@ typedef struct {
|
||||||
} SSubmitBlkIter;
|
} SSubmitBlkIter;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t totalLen;
|
int32_t totalLen;
|
||||||
int32_t len;
|
int32_t len;
|
||||||
|
// head of SSubmitBlk
|
||||||
|
int64_t uid; // table unique id
|
||||||
|
int64_t suid; // stable id
|
||||||
|
int32_t sversion; // data schema version
|
||||||
|
int32_t dataLen; // data part length, not including the SSubmitBlk head
|
||||||
|
int32_t schemaLen; // schema length, if length is 0, no schema exists
|
||||||
|
int16_t numOfRows; // total number of rows in current submit block
|
||||||
|
// head of SSubmitBlk
|
||||||
const void* pMsg;
|
const void* pMsg;
|
||||||
} SSubmitMsgIter;
|
} SSubmitMsgIter;
|
||||||
|
|
||||||
|
@ -237,6 +245,15 @@ int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
|
||||||
int32_t tInitSubmitBlkIter(SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
|
int32_t tInitSubmitBlkIter(SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
|
||||||
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
|
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
|
||||||
|
|
||||||
|
// TODO: KEEP one suite of iterator API finally.
|
||||||
|
// 1) use tInitSubmitMsgIterEx firstly as not decrease the merge conflicts
|
||||||
|
// 2) replace tInitSubmitMsgIterEx with tInitSubmitMsgIter later
|
||||||
|
// 3) finally, rename tInitSubmitMsgIterEx to tInitSubmitMsgIter
|
||||||
|
int32_t tInitSubmitMsgIterEx(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
|
||||||
|
int32_t tGetSubmitMsgNextEx(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
|
||||||
|
int32_t tInitSubmitBlkIterEx(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
|
||||||
|
STSRow* tGetSubmitBlkNextEx(SSubmitBlkIter* pIter);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t index; // index of failed block in submit blocks
|
int32_t index; // index of failed block in submit blocks
|
||||||
int32_t vnode; // vnode index of failed block
|
int32_t vnode; // vnode index of failed block
|
||||||
|
@ -275,7 +292,6 @@ typedef struct {
|
||||||
char name[TSDB_TABLE_FNAME_LEN];
|
char name[TSDB_TABLE_FNAME_LEN];
|
||||||
int8_t igExists;
|
int8_t igExists;
|
||||||
float xFilesFactor;
|
float xFilesFactor;
|
||||||
int32_t aggregationMethod;
|
|
||||||
int32_t delay;
|
int32_t delay;
|
||||||
int32_t ttl;
|
int32_t ttl;
|
||||||
int32_t numOfColumns;
|
int32_t numOfColumns;
|
||||||
|
@ -1314,30 +1330,34 @@ typedef struct {
|
||||||
} SMqConsumerLostMsg;
|
} SMqConsumerLostMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t topicNum;
|
|
||||||
int64_t consumerId;
|
int64_t consumerId;
|
||||||
char cgroup[TSDB_CGROUP_LEN];
|
char cgroup[TSDB_CGROUP_LEN];
|
||||||
SArray* topicNames; // SArray<char*>
|
SArray* topicNames; // SArray<char**>
|
||||||
} SCMSubscribeReq;
|
} SCMSubscribeReq;
|
||||||
|
|
||||||
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
|
static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubscribeReq* pReq) {
|
||||||
int32_t tlen = 0;
|
int32_t tlen = 0;
|
||||||
tlen += taosEncodeFixedI32(buf, pReq->topicNum);
|
|
||||||
tlen += taosEncodeFixedI64(buf, pReq->consumerId);
|
tlen += taosEncodeFixedI64(buf, pReq->consumerId);
|
||||||
tlen += taosEncodeString(buf, pReq->cgroup);
|
tlen += taosEncodeString(buf, pReq->cgroup);
|
||||||
|
|
||||||
for (int32_t i = 0; i < pReq->topicNum; i++) {
|
int32_t topicNum = taosArrayGetSize(pReq->topicNames);
|
||||||
|
tlen += taosEncodeFixedI32(buf, topicNum);
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < topicNum; i++) {
|
||||||
tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
|
tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i));
|
||||||
}
|
}
|
||||||
return tlen;
|
return tlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void* tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq) {
|
static FORCE_INLINE void* tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq) {
|
||||||
buf = taosDecodeFixedI32(buf, &pReq->topicNum);
|
|
||||||
buf = taosDecodeFixedI64(buf, &pReq->consumerId);
|
buf = taosDecodeFixedI64(buf, &pReq->consumerId);
|
||||||
buf = taosDecodeStringTo(buf, pReq->cgroup);
|
buf = taosDecodeStringTo(buf, pReq->cgroup);
|
||||||
pReq->topicNames = taosArrayInit(pReq->topicNum, sizeof(void*));
|
|
||||||
for (int32_t i = 0; i < pReq->topicNum; i++) {
|
int32_t topicNum;
|
||||||
|
buf = taosDecodeFixedI32(buf, &topicNum);
|
||||||
|
|
||||||
|
pReq->topicNames = taosArrayInit(topicNum, sizeof(void*));
|
||||||
|
for (int32_t i = 0; i < topicNum; i++) {
|
||||||
char* name;
|
char* name;
|
||||||
buf = taosDecodeString(buf, &name);
|
buf = taosDecodeString(buf, &name);
|
||||||
taosArrayPush(pReq->topicNames, &name);
|
taosArrayPush(pReq->topicNames, &name);
|
||||||
|
@ -1491,10 +1511,8 @@ typedef struct {
|
||||||
int32_t delay;
|
int32_t delay;
|
||||||
int32_t qmsg1Len;
|
int32_t qmsg1Len;
|
||||||
int32_t qmsg2Len;
|
int32_t qmsg2Len;
|
||||||
func_id_t* pFuncIds;
|
char* qmsg1; // pAst1:qmsg1:SRetention1 => trigger aggr task1
|
||||||
char* qmsg1; // not null: pAst1:qmsg1:SRetention1 => trigger aggr task1
|
char* qmsg2; // pAst2:qmsg2:SRetention2 => trigger aggr task2
|
||||||
char* qmsg2; // not null: pAst2:qmsg2:SRetention2 => trigger aggr task2
|
|
||||||
int8_t nFuncIds;
|
|
||||||
} SRSmaParam;
|
} SRSmaParam;
|
||||||
|
|
||||||
typedef struct SVCreateTbReq {
|
typedef struct SVCreateTbReq {
|
||||||
|
@ -1969,7 +1987,6 @@ typedef struct {
|
||||||
int8_t withTbName;
|
int8_t withTbName;
|
||||||
int8_t withSchema;
|
int8_t withSchema;
|
||||||
int8_t withTag;
|
int8_t withTag;
|
||||||
int8_t withTagSchema;
|
|
||||||
char* qmsg;
|
char* qmsg;
|
||||||
} SMqRebVgReq;
|
} SMqRebVgReq;
|
||||||
|
|
||||||
|
@ -1984,7 +2001,6 @@ static FORCE_INLINE int32_t tEncodeSMqRebVgReq(void** buf, const SMqRebVgReq* pR
|
||||||
tlen += taosEncodeFixedI8(buf, pReq->withTbName);
|
tlen += taosEncodeFixedI8(buf, pReq->withTbName);
|
||||||
tlen += taosEncodeFixedI8(buf, pReq->withSchema);
|
tlen += taosEncodeFixedI8(buf, pReq->withSchema);
|
||||||
tlen += taosEncodeFixedI8(buf, pReq->withTag);
|
tlen += taosEncodeFixedI8(buf, pReq->withTag);
|
||||||
tlen += taosEncodeFixedI8(buf, pReq->withTagSchema);
|
|
||||||
if (pReq->subType == TOPIC_SUB_TYPE__TABLE) {
|
if (pReq->subType == TOPIC_SUB_TYPE__TABLE) {
|
||||||
tlen += taosEncodeString(buf, pReq->qmsg);
|
tlen += taosEncodeString(buf, pReq->qmsg);
|
||||||
}
|
}
|
||||||
|
@ -2001,7 +2017,6 @@ static FORCE_INLINE void* tDecodeSMqRebVgReq(const void* buf, SMqRebVgReq* pReq)
|
||||||
buf = taosDecodeFixedI8(buf, &pReq->withTbName);
|
buf = taosDecodeFixedI8(buf, &pReq->withTbName);
|
||||||
buf = taosDecodeFixedI8(buf, &pReq->withSchema);
|
buf = taosDecodeFixedI8(buf, &pReq->withSchema);
|
||||||
buf = taosDecodeFixedI8(buf, &pReq->withTag);
|
buf = taosDecodeFixedI8(buf, &pReq->withTag);
|
||||||
buf = taosDecodeFixedI8(buf, &pReq->withTagSchema);
|
|
||||||
if (pReq->subType == TOPIC_SUB_TYPE__TABLE) {
|
if (pReq->subType == TOPIC_SUB_TYPE__TABLE) {
|
||||||
buf = taosDecodeString(buf, &pReq->qmsg);
|
buf = taosDecodeString(buf, &pReq->qmsg);
|
||||||
}
|
}
|
||||||
|
@ -2051,80 +2066,6 @@ static FORCE_INLINE void* tDecodeSMqSetCVgReq(void* buf, SMqSetCVgReq* pReq) {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int64_t leftForVer;
|
|
||||||
int32_t vgId;
|
|
||||||
int32_t epoch;
|
|
||||||
int64_t consumerId;
|
|
||||||
char topicName[TSDB_TOPIC_FNAME_LEN];
|
|
||||||
} SMqCancelConnReq;
|
|
||||||
|
|
||||||
static FORCE_INLINE int32_t tEncodeSMqCancelConnReq(void** buf, const SMqCancelConnReq* pReq) {
|
|
||||||
int32_t tlen = 0;
|
|
||||||
tlen += taosEncodeFixedI64(buf, pReq->leftForVer);
|
|
||||||
tlen += taosEncodeFixedI32(buf, pReq->vgId);
|
|
||||||
tlen += taosEncodeFixedI32(buf, pReq->epoch);
|
|
||||||
tlen += taosEncodeFixedI64(buf, pReq->consumerId);
|
|
||||||
tlen += taosEncodeString(buf, pReq->topicName);
|
|
||||||
return tlen;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FORCE_INLINE void* tDecodeSMqCancelConnReq(void* buf, SMqCancelConnReq* pReq) {
|
|
||||||
buf = taosDecodeFixedI64(buf, &pReq->leftForVer);
|
|
||||||
buf = taosDecodeFixedI32(buf, &pReq->vgId);
|
|
||||||
buf = taosDecodeFixedI32(buf, &pReq->epoch);
|
|
||||||
buf = taosDecodeFixedI64(buf, &pReq->consumerId);
|
|
||||||
buf = taosDecodeStringTo(buf, pReq->topicName);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int8_t reserved;
|
|
||||||
} SMqCancelConnRsp;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int64_t leftForVer;
|
|
||||||
int32_t vgId;
|
|
||||||
int64_t oldConsumerId;
|
|
||||||
int64_t newConsumerId;
|
|
||||||
char* topic;
|
|
||||||
} SMqMVRebReq;
|
|
||||||
|
|
||||||
static FORCE_INLINE int32_t tEncodeSMqMVRebReq(void** buf, const SMqMVRebReq* pReq) {
|
|
||||||
int32_t tlen = 0;
|
|
||||||
tlen += taosEncodeFixedI64(buf, pReq->leftForVer);
|
|
||||||
tlen += taosEncodeFixedI32(buf, pReq->vgId);
|
|
||||||
tlen += taosEncodeFixedI64(buf, pReq->oldConsumerId);
|
|
||||||
tlen += taosEncodeFixedI64(buf, pReq->newConsumerId);
|
|
||||||
tlen += taosEncodeString(buf, pReq->topic);
|
|
||||||
return tlen;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FORCE_INLINE void* tDecodeSMqMVRebReq(void* buf, SMqMVRebReq* pReq) {
|
|
||||||
buf = taosDecodeFixedI64(buf, &pReq->leftForVer);
|
|
||||||
buf = taosDecodeFixedI32(buf, &pReq->vgId);
|
|
||||||
buf = taosDecodeFixedI64(buf, &pReq->oldConsumerId);
|
|
||||||
buf = taosDecodeFixedI64(buf, &pReq->newConsumerId);
|
|
||||||
buf = taosDecodeString(buf, &pReq->topic);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
SMsgHead header;
|
|
||||||
int32_t vgId;
|
|
||||||
int64_t consumerId;
|
|
||||||
char topicName[TSDB_TOPIC_FNAME_LEN];
|
|
||||||
char cgroup[TSDB_CGROUP_LEN];
|
|
||||||
} SMqSetCVgRsp;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
SMsgHead header;
|
|
||||||
int32_t vgId;
|
|
||||||
int64_t consumerId;
|
|
||||||
char topicName[TSDB_TOPIC_FNAME_LEN];
|
|
||||||
char cgroup[TSDB_CGROUP_LEN];
|
|
||||||
} SMqMVRebRsp;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t vgId;
|
int32_t vgId;
|
||||||
int64_t offset;
|
int64_t offset;
|
||||||
|
@ -2151,6 +2092,24 @@ typedef struct {
|
||||||
SSchema* pSchema;
|
SSchema* pSchema;
|
||||||
} SSchemaWrapper;
|
} SSchemaWrapper;
|
||||||
|
|
||||||
|
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
|
||||||
|
SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
|
||||||
|
if (pSW == NULL) return pSW;
|
||||||
|
pSW->nCols = pSchemaWrapper->nCols;
|
||||||
|
pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
|
||||||
|
if (pSW->pSchema == NULL) {
|
||||||
|
taosMemoryFree(pSW);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
|
||||||
|
return pSW;
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE void tDeleteSSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
|
||||||
|
taosMemoryFree(pSchemaWrapper->pSchema);
|
||||||
|
taosMemoryFree(pSchemaWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
|
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
|
||||||
int32_t tlen = 0;
|
int32_t tlen = 0;
|
||||||
tlen += taosEncodeFixedI8(buf, pSchema->type);
|
tlen += taosEncodeFixedI8(buf, pSchema->type);
|
||||||
|
@ -2161,13 +2120,13 @@ static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema
|
||||||
return tlen;
|
return tlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void* taosDecodeSSchema(void* buf, SSchema* pSchema) {
|
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
|
||||||
buf = taosDecodeFixedI8(buf, &pSchema->type);
|
buf = taosDecodeFixedI8(buf, &pSchema->type);
|
||||||
buf = taosDecodeFixedI8(buf, &pSchema->flags);
|
buf = taosDecodeFixedI8(buf, &pSchema->flags);
|
||||||
buf = taosDecodeFixedI32(buf, &pSchema->bytes);
|
buf = taosDecodeFixedI32(buf, &pSchema->bytes);
|
||||||
buf = taosDecodeFixedI16(buf, &pSchema->colId);
|
buf = taosDecodeFixedI16(buf, &pSchema->colId);
|
||||||
buf = taosDecodeStringTo(buf, pSchema->name);
|
buf = taosDecodeStringTo(buf, pSchema->name);
|
||||||
return buf;
|
return (void*)buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int32_t tEncodeSSchema(SCoder* pEncoder, const SSchema* pSchema) {
|
static FORCE_INLINE int32_t tEncodeSSchema(SCoder* pEncoder, const SSchema* pSchema) {
|
||||||
|
@ -2197,7 +2156,7 @@ static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWr
|
||||||
return tlen;
|
return tlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void* taosDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pSW) {
|
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
|
||||||
buf = taosDecodeFixedU32(buf, &pSW->nCols);
|
buf = taosDecodeFixedU32(buf, &pSW->nCols);
|
||||||
pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
|
pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
|
||||||
if (pSW->pSchema == NULL) {
|
if (pSW->pSchema == NULL) {
|
||||||
|
@ -2207,7 +2166,7 @@ static FORCE_INLINE void* taosDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pS
|
||||||
for (int32_t i = 0; i < pSW->nCols; i++) {
|
for (int32_t i = 0; i < pSW->nCols; i++) {
|
||||||
buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
|
buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
|
||||||
}
|
}
|
||||||
return buf;
|
return (void*)buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SCoder* pEncoder, const SSchemaWrapper* pSW) {
|
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SCoder* pEncoder, const SSchemaWrapper* pSW) {
|
||||||
|
@ -2590,7 +2549,6 @@ typedef struct {
|
||||||
int8_t withTbName;
|
int8_t withTbName;
|
||||||
int8_t withSchema;
|
int8_t withSchema;
|
||||||
int8_t withTag;
|
int8_t withTag;
|
||||||
int8_t withTagSchema;
|
|
||||||
SArray* blockDataLen; // SArray<int32_t>
|
SArray* blockDataLen; // SArray<int32_t>
|
||||||
SArray* blockData; // SArray<SRetrieveTableRsp*>
|
SArray* blockData; // SArray<SRetrieveTableRsp*>
|
||||||
SArray* blockTbName; // SArray<char*>
|
SArray* blockTbName; // SArray<char*>
|
||||||
|
@ -2609,13 +2567,16 @@ static FORCE_INLINE int32_t tEncodeSMqDataBlkRsp(void** buf, const SMqDataBlkRsp
|
||||||
tlen += taosEncodeFixedI8(buf, pRsp->withTbName);
|
tlen += taosEncodeFixedI8(buf, pRsp->withTbName);
|
||||||
tlen += taosEncodeFixedI8(buf, pRsp->withSchema);
|
tlen += taosEncodeFixedI8(buf, pRsp->withSchema);
|
||||||
tlen += taosEncodeFixedI8(buf, pRsp->withTag);
|
tlen += taosEncodeFixedI8(buf, pRsp->withTag);
|
||||||
tlen += taosEncodeFixedI8(buf, pRsp->withTagSchema);
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < pRsp->blockNum; i++) {
|
for (int32_t i = 0; i < pRsp->blockNum; i++) {
|
||||||
int32_t bLen = *(int32_t*)taosArrayGet(pRsp->blockDataLen, i);
|
int32_t bLen = *(int32_t*)taosArrayGet(pRsp->blockDataLen, i);
|
||||||
void* data = taosArrayGetP(pRsp->blockData, i);
|
void* data = taosArrayGetP(pRsp->blockData, i);
|
||||||
tlen += taosEncodeFixedI32(buf, bLen);
|
tlen += taosEncodeFixedI32(buf, bLen);
|
||||||
tlen += taosEncodeBinary(buf, data, bLen);
|
tlen += taosEncodeBinary(buf, data, bLen);
|
||||||
|
if (pRsp->withSchema) {
|
||||||
|
SSchemaWrapper* pSW = (SSchemaWrapper*)taosArrayGetP(pRsp->blockSchema, i);
|
||||||
|
tlen += taosEncodeSSchemaWrapper(buf, pSW);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tlen;
|
return tlen;
|
||||||
|
@ -2628,11 +2589,11 @@ static FORCE_INLINE void* tDecodeSMqDataBlkRsp(const void* buf, SMqDataBlkRsp* p
|
||||||
buf = taosDecodeFixedI32(buf, &pRsp->blockNum);
|
buf = taosDecodeFixedI32(buf, &pRsp->blockNum);
|
||||||
pRsp->blockData = taosArrayInit(pRsp->blockNum, sizeof(void*));
|
pRsp->blockData = taosArrayInit(pRsp->blockNum, sizeof(void*));
|
||||||
pRsp->blockDataLen = taosArrayInit(pRsp->blockNum, sizeof(void*));
|
pRsp->blockDataLen = taosArrayInit(pRsp->blockNum, sizeof(void*));
|
||||||
|
pRsp->blockSchema = taosArrayInit(pRsp->blockNum, sizeof(void*));
|
||||||
if (pRsp->blockNum != 0) {
|
if (pRsp->blockNum != 0) {
|
||||||
buf = taosDecodeFixedI8(buf, &pRsp->withTbName);
|
buf = taosDecodeFixedI8(buf, &pRsp->withTbName);
|
||||||
buf = taosDecodeFixedI8(buf, &pRsp->withSchema);
|
buf = taosDecodeFixedI8(buf, &pRsp->withSchema);
|
||||||
buf = taosDecodeFixedI8(buf, &pRsp->withTag);
|
buf = taosDecodeFixedI8(buf, &pRsp->withTag);
|
||||||
buf = taosDecodeFixedI8(buf, &pRsp->withTagSchema);
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < pRsp->blockNum; i++) {
|
for (int32_t i = 0; i < pRsp->blockNum; i++) {
|
||||||
int32_t bLen = 0;
|
int32_t bLen = 0;
|
||||||
|
@ -2641,6 +2602,11 @@ static FORCE_INLINE void* tDecodeSMqDataBlkRsp(const void* buf, SMqDataBlkRsp* p
|
||||||
buf = taosDecodeBinary(buf, &data, bLen);
|
buf = taosDecodeBinary(buf, &data, bLen);
|
||||||
taosArrayPush(pRsp->blockDataLen, &bLen);
|
taosArrayPush(pRsp->blockDataLen, &bLen);
|
||||||
taosArrayPush(pRsp->blockData, &data);
|
taosArrayPush(pRsp->blockData, &data);
|
||||||
|
if (pRsp->withSchema) {
|
||||||
|
SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
|
||||||
|
buf = taosDecodeSSchemaWrapper(buf, pSW);
|
||||||
|
taosArrayPush(pRsp->blockSchema, &pSW);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (void*)buf;
|
return (void*)buf;
|
||||||
|
|
|
@ -145,7 +145,7 @@ enum {
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_TOPIC, "mnode-alter-topic", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_TOPIC, "mnode-alter-topic", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_TOPIC, "mnode-drop-topic", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_DROP_TOPIC, "mnode-drop-topic", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_SUBSCRIBE, "mnode-subscribe", SCMSubscribeReq, SCMSubscribeRsp)
|
TD_DEF_MSG_TYPE(TDMT_MND_SUBSCRIBE, "mnode-subscribe", SCMSubscribeReq, SCMSubscribeRsp)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_GET_SUB_EP, "mnode-get-sub-ep", SMqCMGetSubEpReq, SMqCMGetSubEpRsp)
|
TD_DEF_MSG_TYPE(TDMT_MND_GET_SUB_EP, "mnode-mq-ask-ep", SMqCMGetSubEpReq, SMqCMGetSubEpRsp)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_TIMER, "mnode-mq-tmr", SMTimerReq, SMTimerReq)
|
TD_DEF_MSG_TYPE(TDMT_MND_MQ_TIMER, "mnode-mq-tmr", SMTimerReq, SMTimerReq)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_CONSUMER_LOST, "mnode-mq-consumer-lost", SMTimerReq, SMTimerReq)
|
TD_DEF_MSG_TYPE(TDMT_MND_MQ_CONSUMER_LOST, "mnode-mq-consumer-lost", SMTimerReq, SMTimerReq)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_DO_REBALANCE, "mnode-mq-do-rebalance", SMqDoRebalanceMsg, SMqDoRebalanceMsg)
|
TD_DEF_MSG_TYPE(TDMT_MND_MQ_DO_REBALANCE, "mnode-mq-do-rebalance", SMqDoRebalanceMsg, SMqDoRebalanceMsg)
|
||||||
|
|
|
@ -221,7 +221,7 @@ int32_t sdbWrite(SSdb *pSdb, SSdbRaw *pRaw);
|
||||||
* @param pRaw The raw data.
|
* @param pRaw The raw data.
|
||||||
* @return int32_t 0 for success, -1 for failure.
|
* @return int32_t 0 for success, -1 for failure.
|
||||||
*/
|
*/
|
||||||
int32_t sdbWriteNotFree(SSdb *pSdb, SSdbRaw *pRaw);
|
int32_t sdbWriteWithoutFree(SSdb *pSdb, SSdbRaw *pRaw);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Acquire a row from sdb
|
* @brief Acquire a row from sdb
|
||||||
|
|
|
@ -51,7 +51,7 @@ typedef struct SMetaData {
|
||||||
SArray *pTableMeta; // STableMeta array
|
SArray *pTableMeta; // STableMeta array
|
||||||
SArray *pVgroupInfo; // SVgroupInfo list
|
SArray *pVgroupInfo; // SVgroupInfo list
|
||||||
SArray *pUdfList; // udf info list
|
SArray *pUdfList; // udf info list
|
||||||
SArray *pEpSetList; // qnode epset list, SArray<SEpSet>
|
SArray *pQnodeList; // qnode list, SArray<SQueryNodeAddr>
|
||||||
} SMetaData;
|
} SMetaData;
|
||||||
|
|
||||||
typedef struct SCatalogCfg {
|
typedef struct SCatalogCfg {
|
||||||
|
|
|
@ -37,7 +37,7 @@ typedef struct SFuncExecEnv {
|
||||||
typedef bool (*FExecGetEnv)(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
typedef bool (*FExecGetEnv)(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||||
typedef bool (*FExecInit)(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo);
|
typedef bool (*FExecInit)(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo);
|
||||||
typedef int32_t (*FExecProcess)(struct SqlFunctionCtx *pCtx);
|
typedef int32_t (*FExecProcess)(struct SqlFunctionCtx *pCtx);
|
||||||
typedef int32_t (*FExecFinalize)(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock, int32_t slotId);
|
typedef int32_t (*FExecFinalize)(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock);
|
||||||
typedef int32_t (*FScalarExecProcess)(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
typedef int32_t (*FScalarExecProcess)(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||||
|
|
||||||
typedef struct SScalarFuncExecFuncs {
|
typedef struct SScalarFuncExecFuncs {
|
||||||
|
@ -141,8 +141,7 @@ struct SResultRowEntryInfo;
|
||||||
|
|
||||||
//for selectivity query, the corresponding tag value is assigned if the data is qualified
|
//for selectivity query, the corresponding tag value is assigned if the data is qualified
|
||||||
typedef struct SSubsidiaryResInfo {
|
typedef struct SSubsidiaryResInfo {
|
||||||
int16_t bufLen; // keep the tags data for top/bottom query result
|
int16_t num;
|
||||||
int16_t numOfCols;
|
|
||||||
struct SqlFunctionCtx **pCtx;
|
struct SqlFunctionCtx **pCtx;
|
||||||
} SSubsidiaryResInfo;
|
} SSubsidiaryResInfo;
|
||||||
|
|
||||||
|
@ -187,8 +186,8 @@ typedef struct SqlFunctionCtx {
|
||||||
uint8_t currentStage; // record current running step, default: 0
|
uint8_t currentStage; // record current running step, default: 0
|
||||||
bool isAggSet;
|
bool isAggSet;
|
||||||
int64_t startTs; // timestamp range of current query when function is executed on a specific data block, TODO remove it
|
int64_t startTs; // timestamp range of current query when function is executed on a specific data block, TODO remove it
|
||||||
/////////////////////////////////////////////////////////////////
|
|
||||||
bool stableQuery;
|
bool stableQuery;
|
||||||
|
/////////////////////////////////////////////////////////////////
|
||||||
int16_t functionId; // function id
|
int16_t functionId; // function id
|
||||||
char * pOutput; // final result output buffer, point to sdata->data
|
char * pOutput; // final result output buffer, point to sdata->data
|
||||||
int32_t numOfParams;
|
int32_t numOfParams;
|
||||||
|
@ -198,11 +197,15 @@ typedef struct SqlFunctionCtx {
|
||||||
int32_t offset;
|
int32_t offset;
|
||||||
SVariant tag;
|
SVariant tag;
|
||||||
struct SResultRowEntryInfo *resultInfo;
|
struct SResultRowEntryInfo *resultInfo;
|
||||||
SSubsidiaryResInfo subsidiaryRes;
|
SSubsidiaryResInfo subsidiaries;
|
||||||
SPoint1 start;
|
SPoint1 start;
|
||||||
SPoint1 end;
|
SPoint1 end;
|
||||||
SFuncExecFuncs fpSet;
|
SFuncExecFuncs fpSet;
|
||||||
SScalarFuncExecFuncs sfp;
|
SScalarFuncExecFuncs sfp;
|
||||||
|
struct SExprInfo *pExpr;
|
||||||
|
struct SDiskbasedBuf *pBuf;
|
||||||
|
struct SSDataBlock *pSrcBlock;
|
||||||
|
int32_t curBufPage;
|
||||||
} SqlFunctionCtx;
|
} SqlFunctionCtx;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
@ -319,6 +322,20 @@ struct SUdfInfo;
|
||||||
void qAddUdfInfo(uint64_t id, struct SUdfInfo* pUdfInfo);
|
void qAddUdfInfo(uint64_t id, struct SUdfInfo* pUdfInfo);
|
||||||
void qRemoveUdfInfo(uint64_t id, struct SUdfInfo* pUdfInfo);
|
void qRemoveUdfInfo(uint64_t id, struct SUdfInfo* pUdfInfo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create udfd proxy, called once in process that call setupUdf/callUdfxxx/teardownUdf
|
||||||
|
* @return error code
|
||||||
|
*/
|
||||||
|
int32_t udfcOpen();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* destroy udfd proxy
|
||||||
|
* @return error code
|
||||||
|
*/
|
||||||
|
int32_t udfcClose();
|
||||||
|
|
||||||
|
typedef void *UdfcFuncHandle;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -125,15 +125,15 @@ typedef struct SFmGetFuncInfoParam {
|
||||||
struct SCatalog* pCtg;
|
struct SCatalog* pCtg;
|
||||||
void *pRpc;
|
void *pRpc;
|
||||||
const SEpSet* pMgmtEps;
|
const SEpSet* pMgmtEps;
|
||||||
|
char* pErrBuf;
|
||||||
|
int32_t errBufLen;
|
||||||
} SFmGetFuncInfoParam;
|
} SFmGetFuncInfoParam;
|
||||||
|
|
||||||
int32_t fmFuncMgtInit();
|
int32_t fmFuncMgtInit();
|
||||||
|
|
||||||
void fmFuncMgtDestroy();
|
void fmFuncMgtDestroy();
|
||||||
|
|
||||||
int32_t fmGetFuncInfo(SFmGetFuncInfoParam* pParam, const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType);
|
int32_t fmGetFuncInfo(SFmGetFuncInfoParam* pParam, SFunctionNode* pFunc);
|
||||||
|
|
||||||
int32_t fmGetFuncResultType(SFunctionNode* pFunc, char* pErrBuf, int32_t len);
|
|
||||||
|
|
||||||
bool fmIsAggFunc(int32_t funcId);
|
bool fmIsAggFunc(int32_t funcId);
|
||||||
bool fmIsScalarFunc(int32_t funcId);
|
bool fmIsScalarFunc(int32_t funcId);
|
||||||
|
|
|
@ -25,14 +25,16 @@ extern "C" {
|
||||||
#include "tvariant.h"
|
#include "tvariant.h"
|
||||||
|
|
||||||
#define TABLE_TOTAL_COL_NUM(pMeta) ((pMeta)->tableInfo.numOfColumns + (pMeta)->tableInfo.numOfTags)
|
#define TABLE_TOTAL_COL_NUM(pMeta) ((pMeta)->tableInfo.numOfColumns + (pMeta)->tableInfo.numOfTags)
|
||||||
#define TABLE_META_SIZE(pMeta) (NULL == (pMeta) ? 0 : (sizeof(STableMeta) + TABLE_TOTAL_COL_NUM((pMeta)) * sizeof(SSchema)))
|
#define TABLE_META_SIZE(pMeta) \
|
||||||
#define VGROUPS_INFO_SIZE(pInfo) (NULL == (pInfo) ? 0 : (sizeof(SVgroupsInfo) + (pInfo)->numOfVgroups * sizeof(SVgroupInfo)))
|
(NULL == (pMeta) ? 0 : (sizeof(STableMeta) + TABLE_TOTAL_COL_NUM((pMeta)) * sizeof(SSchema)))
|
||||||
|
#define VGROUPS_INFO_SIZE(pInfo) \
|
||||||
|
(NULL == (pInfo) ? 0 : (sizeof(SVgroupsInfo) + (pInfo)->numOfVgroups * sizeof(SVgroupInfo)))
|
||||||
|
|
||||||
typedef struct SRawExprNode {
|
typedef struct SRawExprNode {
|
||||||
ENodeType nodeType;
|
ENodeType nodeType;
|
||||||
char* p;
|
char* p;
|
||||||
uint32_t n;
|
uint32_t n;
|
||||||
SNode* pNode;
|
SNode* pNode;
|
||||||
} SRawExprNode;
|
} SRawExprNode;
|
||||||
|
|
||||||
typedef struct SDataType {
|
typedef struct SDataType {
|
||||||
|
@ -45,170 +47,155 @@ typedef struct SDataType {
|
||||||
typedef struct SExprNode {
|
typedef struct SExprNode {
|
||||||
ENodeType type;
|
ENodeType type;
|
||||||
SDataType resType;
|
SDataType resType;
|
||||||
char aliasName[TSDB_COL_NAME_LEN];
|
char aliasName[TSDB_COL_NAME_LEN];
|
||||||
SNodeList* pAssociationList;
|
SArray* pAssociation;
|
||||||
} SExprNode;
|
} SExprNode;
|
||||||
|
|
||||||
typedef enum EColumnType {
|
typedef enum EColumnType { COLUMN_TYPE_COLUMN = 1, COLUMN_TYPE_TAG } EColumnType;
|
||||||
COLUMN_TYPE_COLUMN = 1,
|
|
||||||
COLUMN_TYPE_TAG
|
|
||||||
} EColumnType;
|
|
||||||
|
|
||||||
typedef struct SColumnNode {
|
typedef struct SColumnNode {
|
||||||
SExprNode node; // QUERY_NODE_COLUMN
|
SExprNode node; // QUERY_NODE_COLUMN
|
||||||
uint64_t tableId;
|
uint64_t tableId;
|
||||||
int8_t tableType;
|
int8_t tableType;
|
||||||
col_id_t colId;
|
col_id_t colId;
|
||||||
EColumnType colType; // column or tag
|
EColumnType colType; // column or tag
|
||||||
char dbName[TSDB_DB_NAME_LEN];
|
char dbName[TSDB_DB_NAME_LEN];
|
||||||
char tableName[TSDB_TABLE_NAME_LEN];
|
char tableName[TSDB_TABLE_NAME_LEN];
|
||||||
char tableAlias[TSDB_TABLE_NAME_LEN];
|
char tableAlias[TSDB_TABLE_NAME_LEN];
|
||||||
char colName[TSDB_COL_NAME_LEN];
|
char colName[TSDB_COL_NAME_LEN];
|
||||||
SNode* pProjectRef;
|
SNode* pProjectRef;
|
||||||
int16_t dataBlockId;
|
int16_t dataBlockId;
|
||||||
int16_t slotId;
|
int16_t slotId;
|
||||||
} SColumnNode;
|
} SColumnNode;
|
||||||
|
|
||||||
typedef struct STargetNode {
|
typedef struct STargetNode {
|
||||||
ENodeType type;
|
ENodeType type;
|
||||||
int16_t dataBlockId;
|
int16_t dataBlockId;
|
||||||
int16_t slotId;
|
int16_t slotId;
|
||||||
SNode* pExpr;
|
SNode* pExpr;
|
||||||
} STargetNode;
|
} STargetNode;
|
||||||
|
|
||||||
typedef struct SValueNode {
|
typedef struct SValueNode {
|
||||||
SExprNode node; // QUERY_NODE_VALUE
|
SExprNode node; // QUERY_NODE_VALUE
|
||||||
char* literal;
|
char* literal;
|
||||||
bool isDuration;
|
bool isDuration;
|
||||||
bool translate;
|
bool translate;
|
||||||
bool genByCalc;
|
int16_t placeholderNo;
|
||||||
int16_t placeholderNo;
|
|
||||||
union {
|
union {
|
||||||
bool b;
|
bool b;
|
||||||
int64_t i;
|
int64_t i;
|
||||||
uint64_t u;
|
uint64_t u;
|
||||||
double d;
|
double d;
|
||||||
char* p;
|
char* p;
|
||||||
} datum;
|
} datum;
|
||||||
char unit;
|
char unit;
|
||||||
} SValueNode;
|
} SValueNode;
|
||||||
|
|
||||||
typedef struct SOperatorNode {
|
typedef struct SOperatorNode {
|
||||||
SExprNode node; // QUERY_NODE_OPERATOR
|
SExprNode node; // QUERY_NODE_OPERATOR
|
||||||
EOperatorType opType;
|
EOperatorType opType;
|
||||||
SNode* pLeft;
|
SNode* pLeft;
|
||||||
SNode* pRight;
|
SNode* pRight;
|
||||||
} SOperatorNode;
|
} SOperatorNode;
|
||||||
|
|
||||||
|
|
||||||
typedef struct SLogicConditionNode {
|
typedef struct SLogicConditionNode {
|
||||||
SExprNode node; // QUERY_NODE_LOGIC_CONDITION
|
SExprNode node; // QUERY_NODE_LOGIC_CONDITION
|
||||||
ELogicConditionType condType;
|
ELogicConditionType condType;
|
||||||
SNodeList* pParameterList;
|
SNodeList* pParameterList;
|
||||||
} SLogicConditionNode;
|
} SLogicConditionNode;
|
||||||
|
|
||||||
typedef struct SNodeListNode {
|
typedef struct SNodeListNode {
|
||||||
ENodeType type; // QUERY_NODE_NODE_LIST
|
ENodeType type; // QUERY_NODE_NODE_LIST
|
||||||
SDataType dataType;
|
SDataType dataType;
|
||||||
SNodeList* pNodeList;
|
SNodeList* pNodeList;
|
||||||
} SNodeListNode;
|
} SNodeListNode;
|
||||||
|
|
||||||
typedef struct SFunctionNode {
|
typedef struct SFunctionNode {
|
||||||
SExprNode node; // QUERY_NODE_FUNCTION
|
SExprNode node; // QUERY_NODE_FUNCTION
|
||||||
char functionName[TSDB_FUNC_NAME_LEN];
|
char functionName[TSDB_FUNC_NAME_LEN];
|
||||||
int32_t funcId;
|
int32_t funcId;
|
||||||
int32_t funcType;
|
int32_t funcType;
|
||||||
SNodeList* pParameterList;
|
SNodeList* pParameterList;
|
||||||
|
int32_t udfBufSize;
|
||||||
} SFunctionNode;
|
} SFunctionNode;
|
||||||
|
|
||||||
typedef struct STableNode {
|
typedef struct STableNode {
|
||||||
SExprNode node;
|
SExprNode node;
|
||||||
char dbName[TSDB_DB_NAME_LEN];
|
char dbName[TSDB_DB_NAME_LEN];
|
||||||
char tableName[TSDB_TABLE_NAME_LEN];
|
char tableName[TSDB_TABLE_NAME_LEN];
|
||||||
char tableAlias[TSDB_TABLE_NAME_LEN];
|
char tableAlias[TSDB_TABLE_NAME_LEN];
|
||||||
uint8_t precision;
|
uint8_t precision;
|
||||||
} STableNode;
|
} STableNode;
|
||||||
|
|
||||||
struct STableMeta;
|
struct STableMeta;
|
||||||
|
|
||||||
typedef struct SRealTableNode {
|
typedef struct SRealTableNode {
|
||||||
STableNode table; // QUERY_NODE_REAL_TABLE
|
STableNode table; // QUERY_NODE_REAL_TABLE
|
||||||
struct STableMeta* pMeta;
|
struct STableMeta* pMeta;
|
||||||
SVgroupsInfo* pVgroupList;
|
SVgroupsInfo* pVgroupList;
|
||||||
char useDbName[TSDB_DB_NAME_LEN];
|
char qualDbName[TSDB_DB_NAME_LEN]; // SHOW qualDbName.TABLES
|
||||||
double ratio;
|
double ratio;
|
||||||
} SRealTableNode;
|
} SRealTableNode;
|
||||||
|
|
||||||
typedef struct STempTableNode {
|
typedef struct STempTableNode {
|
||||||
STableNode table; // QUERY_NODE_TEMP_TABLE
|
STableNode table; // QUERY_NODE_TEMP_TABLE
|
||||||
SNode* pSubquery;
|
SNode* pSubquery;
|
||||||
} STempTableNode;
|
} STempTableNode;
|
||||||
|
|
||||||
typedef enum EJoinType {
|
typedef enum EJoinType { JOIN_TYPE_INNER = 1 } EJoinType;
|
||||||
JOIN_TYPE_INNER = 1
|
|
||||||
} EJoinType;
|
|
||||||
|
|
||||||
typedef struct SJoinTableNode {
|
typedef struct SJoinTableNode {
|
||||||
STableNode table; // QUERY_NODE_JOIN_TABLE
|
STableNode table; // QUERY_NODE_JOIN_TABLE
|
||||||
EJoinType joinType;
|
EJoinType joinType;
|
||||||
SNode* pLeft;
|
SNode* pLeft;
|
||||||
SNode* pRight;
|
SNode* pRight;
|
||||||
SNode* pOnCond;
|
SNode* pOnCond;
|
||||||
} SJoinTableNode;
|
} SJoinTableNode;
|
||||||
|
|
||||||
typedef enum EGroupingSetType {
|
typedef enum EGroupingSetType { GP_TYPE_NORMAL = 1 } EGroupingSetType;
|
||||||
GP_TYPE_NORMAL = 1
|
|
||||||
} EGroupingSetType;
|
|
||||||
|
|
||||||
typedef struct SGroupingSetNode {
|
typedef struct SGroupingSetNode {
|
||||||
ENodeType type; // QUERY_NODE_GROUPING_SET
|
ENodeType type; // QUERY_NODE_GROUPING_SET
|
||||||
EGroupingSetType groupingSetType;
|
EGroupingSetType groupingSetType;
|
||||||
SNodeList* pParameterList;
|
SNodeList* pParameterList;
|
||||||
} SGroupingSetNode;
|
} SGroupingSetNode;
|
||||||
|
|
||||||
typedef enum EOrder {
|
typedef enum EOrder { ORDER_ASC = 1, ORDER_DESC } EOrder;
|
||||||
ORDER_ASC = 1,
|
|
||||||
ORDER_DESC
|
|
||||||
} EOrder;
|
|
||||||
|
|
||||||
typedef enum ENullOrder {
|
typedef enum ENullOrder { NULL_ORDER_DEFAULT = 1, NULL_ORDER_FIRST, NULL_ORDER_LAST } ENullOrder;
|
||||||
NULL_ORDER_DEFAULT = 1,
|
|
||||||
NULL_ORDER_FIRST,
|
|
||||||
NULL_ORDER_LAST
|
|
||||||
} ENullOrder;
|
|
||||||
|
|
||||||
typedef struct SOrderByExprNode {
|
typedef struct SOrderByExprNode {
|
||||||
ENodeType type; // QUERY_NODE_ORDER_BY_EXPR
|
ENodeType type; // QUERY_NODE_ORDER_BY_EXPR
|
||||||
SNode* pExpr;
|
SNode* pExpr;
|
||||||
EOrder order;
|
EOrder order;
|
||||||
ENullOrder nullOrder;
|
ENullOrder nullOrder;
|
||||||
} SOrderByExprNode;
|
} SOrderByExprNode;
|
||||||
|
|
||||||
typedef struct SLimitNode {
|
typedef struct SLimitNode {
|
||||||
ENodeType type; // QUERY_NODE_LIMIT
|
ENodeType type; // QUERY_NODE_LIMIT
|
||||||
int64_t limit;
|
int64_t limit;
|
||||||
int64_t offset;
|
int64_t offset;
|
||||||
} SLimitNode;
|
} SLimitNode;
|
||||||
|
|
||||||
typedef struct SStateWindowNode {
|
typedef struct SStateWindowNode {
|
||||||
ENodeType type; // QUERY_NODE_STATE_WINDOW
|
ENodeType type; // QUERY_NODE_STATE_WINDOW
|
||||||
SNode* pCol; // timestamp primary key
|
SNode* pCol; // timestamp primary key
|
||||||
SNode* pExpr;
|
SNode* pExpr;
|
||||||
} SStateWindowNode;
|
} SStateWindowNode;
|
||||||
|
|
||||||
typedef struct SSessionWindowNode {
|
typedef struct SSessionWindowNode {
|
||||||
ENodeType type; // QUERY_NODE_SESSION_WINDOW
|
ENodeType type; // QUERY_NODE_SESSION_WINDOW
|
||||||
SColumnNode* pCol; // timestamp primary key
|
SColumnNode* pCol; // timestamp primary key
|
||||||
SValueNode* pGap; // gap between two session window(in microseconds)
|
SValueNode* pGap; // gap between two session window(in microseconds)
|
||||||
} SSessionWindowNode;
|
} SSessionWindowNode;
|
||||||
|
|
||||||
typedef struct SIntervalWindowNode {
|
typedef struct SIntervalWindowNode {
|
||||||
ENodeType type; // QUERY_NODE_INTERVAL_WINDOW
|
ENodeType type; // QUERY_NODE_INTERVAL_WINDOW
|
||||||
SNode* pCol; // timestamp primary key
|
SNode* pCol; // timestamp primary key
|
||||||
SNode* pInterval; // SValueNode
|
SNode* pInterval; // SValueNode
|
||||||
SNode* pOffset; // SValueNode
|
SNode* pOffset; // SValueNode
|
||||||
SNode* pSliding; // SValueNode
|
SNode* pSliding; // SValueNode
|
||||||
SNode* pFill;
|
SNode* pFill;
|
||||||
} SIntervalWindowNode;
|
} SIntervalWindowNode;
|
||||||
|
|
||||||
typedef enum EFillMode {
|
typedef enum EFillMode {
|
||||||
|
@ -221,42 +208,40 @@ typedef enum EFillMode {
|
||||||
} EFillMode;
|
} EFillMode;
|
||||||
|
|
||||||
typedef struct SFillNode {
|
typedef struct SFillNode {
|
||||||
ENodeType type; // QUERY_NODE_FILL
|
ENodeType type; // QUERY_NODE_FILL
|
||||||
EFillMode mode;
|
EFillMode mode;
|
||||||
SNode* pValues; // SNodeListNode
|
SNode* pValues; // SNodeListNode
|
||||||
} SFillNode;
|
} SFillNode;
|
||||||
|
|
||||||
typedef struct SSelectStmt {
|
typedef struct SSelectStmt {
|
||||||
ENodeType type; // QUERY_NODE_SELECT_STMT
|
ENodeType type; // QUERY_NODE_SELECT_STMT
|
||||||
bool isDistinct;
|
bool isDistinct;
|
||||||
SNodeList* pProjectionList;
|
SNodeList* pProjectionList;
|
||||||
SNode* pFromTable;
|
SNode* pFromTable;
|
||||||
SNode* pWhere;
|
SNode* pWhere;
|
||||||
SNodeList* pPartitionByList;
|
SNodeList* pPartitionByList;
|
||||||
SNode* pWindow;
|
SNode* pWindow;
|
||||||
SNodeList* pGroupByList; // SGroupingSetNode
|
SNodeList* pGroupByList; // SGroupingSetNode
|
||||||
SNode* pHaving;
|
SNode* pHaving;
|
||||||
SNodeList* pOrderByList; // SOrderByExprNode
|
SNodeList* pOrderByList; // SOrderByExprNode
|
||||||
SLimitNode* pLimit;
|
SLimitNode* pLimit;
|
||||||
SLimitNode* pSlimit;
|
SLimitNode* pSlimit;
|
||||||
char stmtName[TSDB_TABLE_NAME_LEN];
|
char stmtName[TSDB_TABLE_NAME_LEN];
|
||||||
uint8_t precision;
|
uint8_t precision;
|
||||||
bool isEmptyResult;
|
bool isEmptyResult;
|
||||||
|
bool hasAggFuncs;
|
||||||
} SSelectStmt;
|
} SSelectStmt;
|
||||||
|
|
||||||
typedef enum ESetOperatorType {
|
typedef enum ESetOperatorType { SET_OP_TYPE_UNION_ALL = 1, SET_OP_TYPE_UNION } ESetOperatorType;
|
||||||
SET_OP_TYPE_UNION_ALL = 1,
|
|
||||||
SET_OP_TYPE_UNION
|
|
||||||
} ESetOperatorType;
|
|
||||||
|
|
||||||
typedef struct SSetOperator {
|
typedef struct SSetOperator {
|
||||||
ENodeType type; // QUERY_NODE_SET_OPERATOR
|
ENodeType type; // QUERY_NODE_SET_OPERATOR
|
||||||
ESetOperatorType opType;
|
ESetOperatorType opType;
|
||||||
SNodeList* pProjectionList;
|
SNodeList* pProjectionList;
|
||||||
SNode* pLeft;
|
SNode* pLeft;
|
||||||
SNode* pRight;
|
SNode* pRight;
|
||||||
SNodeList* pOrderByList; // SOrderByExprNode
|
SNodeList* pOrderByList; // SOrderByExprNode
|
||||||
SNode* pLimit;
|
SNode* pLimit;
|
||||||
} SSetOperator;
|
} SSetOperator;
|
||||||
|
|
||||||
typedef enum ESqlClause {
|
typedef enum ESqlClause {
|
||||||
|
@ -271,7 +256,6 @@ typedef enum ESqlClause {
|
||||||
SQL_CLAUSE_ORDER_BY
|
SQL_CLAUSE_ORDER_BY
|
||||||
} ESqlClause;
|
} ESqlClause;
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PAYLOAD_TYPE_KV = 0,
|
PAYLOAD_TYPE_KV = 0,
|
||||||
PAYLOAD_TYPE_RAW = 1,
|
PAYLOAD_TYPE_RAW = 1,
|
||||||
|
@ -281,29 +265,29 @@ typedef struct SVgDataBlocks {
|
||||||
SVgroupInfo vg;
|
SVgroupInfo vg;
|
||||||
int32_t numOfTables; // number of tables in current submit block
|
int32_t numOfTables; // number of tables in current submit block
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
char *pData; // SMsgDesc + SSubmitReq + SSubmitBlk + ...
|
char* pData; // SMsgDesc + SSubmitReq + SSubmitBlk + ...
|
||||||
} SVgDataBlocks;
|
} SVgDataBlocks;
|
||||||
|
|
||||||
typedef struct SVnodeModifOpStmt {
|
typedef struct SVnodeModifOpStmt {
|
||||||
ENodeType nodeType;
|
ENodeType nodeType;
|
||||||
ENodeType sqlNodeType;
|
ENodeType sqlNodeType;
|
||||||
SArray* pDataBlocks; // data block for each vgroup, SArray<SVgDataBlocks*>.
|
SArray* pDataBlocks; // data block for each vgroup, SArray<SVgDataBlocks*>.
|
||||||
uint8_t payloadType; // EPayloadType. 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert
|
uint8_t payloadType; // EPayloadType. 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert
|
||||||
uint32_t insertType; // insert data from [file|sql statement| bound statement]
|
uint32_t insertType; // insert data from [file|sql statement| bound statement]
|
||||||
const char* sql; // current sql statement position
|
const char* sql; // current sql statement position
|
||||||
} SVnodeModifOpStmt;
|
} SVnodeModifOpStmt;
|
||||||
|
|
||||||
typedef struct SExplainOptions {
|
typedef struct SExplainOptions {
|
||||||
ENodeType type;
|
ENodeType type;
|
||||||
bool verbose;
|
bool verbose;
|
||||||
double ratio;
|
double ratio;
|
||||||
} SExplainOptions;
|
} SExplainOptions;
|
||||||
|
|
||||||
typedef struct SExplainStmt {
|
typedef struct SExplainStmt {
|
||||||
ENodeType type;
|
ENodeType type;
|
||||||
bool analyze;
|
bool analyze;
|
||||||
SExplainOptions* pOptions;
|
SExplainOptions* pOptions;
|
||||||
SNode* pQuery;
|
SNode* pQuery;
|
||||||
} SExplainStmt;
|
} SExplainStmt;
|
||||||
|
|
||||||
void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker walker, void* pContext);
|
void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker walker, void* pContext);
|
||||||
|
@ -324,10 +308,10 @@ bool nodesIsJsonOp(const SOperatorNode* pOp);
|
||||||
bool nodesIsTimeorderQuery(const SNode* pQuery);
|
bool nodesIsTimeorderQuery(const SNode* pQuery);
|
||||||
bool nodesIsTimelineQuery(const SNode* pQuery);
|
bool nodesIsTimelineQuery(const SNode* pQuery);
|
||||||
|
|
||||||
void* nodesGetValueFromNode(SValueNode *pNode);
|
void* nodesGetValueFromNode(SValueNode* pNode);
|
||||||
char* nodesGetStrValueFromNode(SValueNode *pNode);
|
char* nodesGetStrValueFromNode(SValueNode* pNode);
|
||||||
char *getFillModeString(EFillMode mode);
|
char* getFillModeString(EFillMode mode);
|
||||||
void valueNodeToVariant(const SValueNode* pNode, SVariant* pVal);
|
void valueNodeToVariant(const SValueNode* pNode, SVariant* pVal);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,6 +158,8 @@ typedef enum {
|
||||||
|
|
||||||
int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak);
|
int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak);
|
||||||
|
|
||||||
|
bool syncEnvIsStart();
|
||||||
|
|
||||||
extern int32_t sDebugFlag;
|
extern int32_t sDebugFlag;
|
||||||
|
|
||||||
//-----------------------------------------
|
//-----------------------------------------
|
||||||
|
|
|
@ -192,7 +192,13 @@ int32_t walEndSnapshot(SWal *);
|
||||||
SWalReadHandle *walOpenReadHandle(SWal *);
|
SWalReadHandle *walOpenReadHandle(SWal *);
|
||||||
void walCloseReadHandle(SWalReadHandle *);
|
void walCloseReadHandle(SWalReadHandle *);
|
||||||
int32_t walReadWithHandle(SWalReadHandle *pRead, int64_t ver);
|
int32_t walReadWithHandle(SWalReadHandle *pRead, int64_t ver);
|
||||||
int32_t walReadWithHandle_s(SWalReadHandle *pRead, int64_t ver, SWalReadHead **ppHead);
|
|
||||||
|
// only for tq usage
|
||||||
|
// int32_t walReadWithHandle_s(SWalReadHandle *pRead, int64_t ver, SWalReadHead **ppHead);
|
||||||
|
void walSetReaderCapacity(SWalReadHandle *pRead, int32_t capacity);
|
||||||
|
int32_t walFetchHead(SWalReadHandle *pRead, int64_t ver, SWalHead *pHead);
|
||||||
|
int32_t walFetchBody(SWalReadHandle *pRead, SWalHead **ppHead);
|
||||||
|
int32_t walSkipFetchBody(SWalReadHandle *pRead, const SWalHead *pHead);
|
||||||
|
|
||||||
// deprecated
|
// deprecated
|
||||||
#if 0
|
#if 0
|
||||||
|
|
|
@ -139,16 +139,9 @@ int32_t* taosGetErrno();
|
||||||
// mnode-common
|
// mnode-common
|
||||||
#define TSDB_CODE_MND_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x0300)
|
#define TSDB_CODE_MND_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x0300)
|
||||||
#define TSDB_CODE_MND_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0301)
|
#define TSDB_CODE_MND_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0301)
|
||||||
#define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0302)
|
#define TSDB_CODE_MND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0302)
|
||||||
#define TSDB_CODE_MND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0303)
|
#define TSDB_CODE_MND_NO_RIGHTS TAOS_DEF_ERROR_CODE(0, 0x0303)
|
||||||
#define TSDB_CODE_MND_ACTION_NEED_REPROCESSED TAOS_DEF_ERROR_CODE(0, 0x0304)
|
#define TSDB_CODE_MND_INVALID_CONNECTION TAOS_DEF_ERROR_CODE(0, 0x0304)
|
||||||
#define TSDB_CODE_MND_NO_RIGHTS TAOS_DEF_ERROR_CODE(0, 0x0305)
|
|
||||||
#define TSDB_CODE_MND_INVALID_OPTIONS TAOS_DEF_ERROR_CODE(0, 0x0306)
|
|
||||||
#define TSDB_CODE_MND_INVALID_CONNECTION TAOS_DEF_ERROR_CODE(0, 0x0307)
|
|
||||||
#define TSDB_CODE_MND_INVALID_MSG_VERSION TAOS_DEF_ERROR_CODE(0, 0x0308)
|
|
||||||
#define TSDB_CODE_MND_INVALID_MSG_LEN TAOS_DEF_ERROR_CODE(0, 0x0309)
|
|
||||||
#define TSDB_CODE_MND_INVALID_MSG_TYPE TAOS_DEF_ERROR_CODE(0, 0x030A)
|
|
||||||
#define TSDB_CODE_MND_TOO_MANY_SHELL_CONNS TAOS_DEF_ERROR_CODE(0, 0x030B)
|
|
||||||
|
|
||||||
// mnode-show
|
// mnode-show
|
||||||
#define TSDB_CODE_MND_INVALID_SHOWOBJ TAOS_DEF_ERROR_CODE(0, 0x0310)
|
#define TSDB_CODE_MND_INVALID_SHOWOBJ TAOS_DEF_ERROR_CODE(0, 0x0310)
|
||||||
|
@ -252,7 +245,7 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_MND_COLUMN_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03AE)
|
#define TSDB_CODE_MND_COLUMN_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03AE)
|
||||||
|
|
||||||
// mnode-infoSchema
|
// mnode-infoSchema
|
||||||
#define TSDB_CODE_MND_INVALID_INFOS_TBL TAOS_DEF_ERROR_CODE(0, 0x03B0)
|
#define TSDB_CODE_MND_INVALID_SYS_TABLENAME TAOS_DEF_ERROR_CODE(0, 0x03B0)
|
||||||
|
|
||||||
// mnode-func
|
// mnode-func
|
||||||
#define TSDB_CODE_MND_FUNC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03C0)
|
#define TSDB_CODE_MND_FUNC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03C0)
|
||||||
|
@ -573,7 +566,6 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_PAR_TABLE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x2602)
|
#define TSDB_CODE_PAR_TABLE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x2602)
|
||||||
#define TSDB_CODE_PAR_AMBIGUOUS_COLUMN TAOS_DEF_ERROR_CODE(0, 0x2603)
|
#define TSDB_CODE_PAR_AMBIGUOUS_COLUMN TAOS_DEF_ERROR_CODE(0, 0x2603)
|
||||||
#define TSDB_CODE_PAR_WRONG_VALUE_TYPE TAOS_DEF_ERROR_CODE(0, 0x2604)
|
#define TSDB_CODE_PAR_WRONG_VALUE_TYPE TAOS_DEF_ERROR_CODE(0, 0x2604)
|
||||||
#define TSDB_CODE_PAR_INVALID_FUNTION TAOS_DEF_ERROR_CODE(0, 0x2605)
|
|
||||||
#define TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION TAOS_DEF_ERROR_CODE(0, 0x2608)
|
#define TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION TAOS_DEF_ERROR_CODE(0, 0x2608)
|
||||||
#define TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT TAOS_DEF_ERROR_CODE(0, 0x2609)
|
#define TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT TAOS_DEF_ERROR_CODE(0, 0x2609)
|
||||||
#define TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION TAOS_DEF_ERROR_CODE(0, 0x260A)
|
#define TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION TAOS_DEF_ERROR_CODE(0, 0x260A)
|
||||||
|
@ -633,6 +625,7 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_FUNC_FUNTION_PARA_NUM TAOS_DEF_ERROR_CODE(0, 0x2801)
|
#define TSDB_CODE_FUNC_FUNTION_PARA_NUM TAOS_DEF_ERROR_CODE(0, 0x2801)
|
||||||
#define TSDB_CODE_FUNC_FUNTION_PARA_TYPE TAOS_DEF_ERROR_CODE(0, 0x2802)
|
#define TSDB_CODE_FUNC_FUNTION_PARA_TYPE TAOS_DEF_ERROR_CODE(0, 0x2802)
|
||||||
#define TSDB_CODE_FUNC_FUNTION_PARA_VALUE TAOS_DEF_ERROR_CODE(0, 0x2803)
|
#define TSDB_CODE_FUNC_FUNTION_PARA_VALUE TAOS_DEF_ERROR_CODE(0, 0x2803)
|
||||||
|
#define TSDB_CODE_FUNC_INVALID_FUNTION TAOS_DEF_ERROR_CODE(0, 0x2604)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ typedef enum {
|
||||||
CFG_STYPE_CFG_FILE,
|
CFG_STYPE_CFG_FILE,
|
||||||
CFG_STYPE_ENV_FILE,
|
CFG_STYPE_ENV_FILE,
|
||||||
CFG_STYPE_ENV_VAR,
|
CFG_STYPE_ENV_VAR,
|
||||||
|
CFG_STYPE_ENV_CMD,
|
||||||
CFG_STYPE_APOLLO_URL,
|
CFG_STYPE_APOLLO_URL,
|
||||||
CFG_STYPE_ARG_LIST,
|
CFG_STYPE_ARG_LIST,
|
||||||
CFG_STYPE_TAOS_OPTIONS
|
CFG_STYPE_TAOS_OPTIONS
|
||||||
|
@ -82,7 +83,7 @@ typedef struct SConfig {
|
||||||
} SConfig;
|
} SConfig;
|
||||||
|
|
||||||
SConfig *cfgInit();
|
SConfig *cfgInit();
|
||||||
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr);
|
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const void *sourceStr);
|
||||||
int32_t cfgLoadFromArray(SConfig *pCfg, SArray *pArgs); // SConfigPair
|
int32_t cfgLoadFromArray(SConfig *pCfg, SArray *pArgs); // SConfigPair
|
||||||
void cfgCleanup(SConfig *pCfg);
|
void cfgCleanup(SConfig *pCfg);
|
||||||
|
|
||||||
|
@ -105,6 +106,8 @@ const char *cfgDtypeStr(ECfgDataType type);
|
||||||
|
|
||||||
void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump);
|
void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump);
|
||||||
|
|
||||||
|
int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _TD_ENV_H_
|
||||||
|
#define _TD_ENV_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int32_t taosEnvNameToCfgName(const char *envNameStr, char *cfgNameStr, int32_t cfgNameMaxLen);
|
||||||
|
int32_t taosEnvToCfg(const char *envStr, char *cfgStr);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*_TD_ENV_H_*/
|
|
@ -49,6 +49,8 @@ int32_t tjsonAddItemToObject(SJson* pJson, const char* pName, SJson* pItem);
|
||||||
int32_t tjsonAddItemToArray(SJson* pJson, SJson* pItem);
|
int32_t tjsonAddItemToArray(SJson* pJson, SJson* pItem);
|
||||||
|
|
||||||
SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName);
|
SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName);
|
||||||
|
int32_t tjsonGetObjectName(const SJson* pJson, char** pName);
|
||||||
|
int32_t tjsonGetObjectValueString(const SJson* pJson, char** pStringValue);
|
||||||
int32_t tjsonGetStringValue(const SJson* pJson, const char* pName, char* pVal);
|
int32_t tjsonGetStringValue(const SJson* pJson, const char* pName, char* pVal);
|
||||||
int32_t tjsonDupStringValue(const SJson* pJson, const char* pName, char** pVal);
|
int32_t tjsonDupStringValue(const SJson* pJson, const char* pName, char** pVal);
|
||||||
int32_t tjsonGetBigIntValue(const SJson* pJson, const char* pName, int64_t* pVal);
|
int32_t tjsonGetBigIntValue(const SJson* pJson, const char* pName, int64_t* pVal);
|
||||||
|
@ -81,6 +83,7 @@ char* tjsonToUnformattedString(const SJson* pJson);
|
||||||
|
|
||||||
SJson* tjsonParse(const char* pStr);
|
SJson* tjsonParse(const char* pStr);
|
||||||
bool tjsonValidateJson(const char* pJson);
|
bool tjsonValidateJson(const char* pJson);
|
||||||
|
const char* tjsonGetError();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,10 +41,6 @@ bool taosTmrReset(TAOS_TMR_CALLBACK fp, int32_t mseconds, void *param, void *han
|
||||||
|
|
||||||
void taosTmrCleanUp(void *handle);
|
void taosTmrCleanUp(void *handle);
|
||||||
|
|
||||||
int32_t taosInitTimer(void (*callback)(int32_t), int32_t ms);
|
|
||||||
|
|
||||||
void taosUninitTimer();
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
aux_source_directory(src CLIENT_SRC)
|
aux_source_directory(src CLIENT_SRC)
|
||||||
add_library(taos SHARED ${CLIENT_SRC})
|
if(TD_WINDOWS)
|
||||||
|
add_library(taos SHARED ${CLIENT_SRC} ${CMAKE_CURRENT_SOURCE_DIR}/src/taos.rc.in)
|
||||||
|
else()
|
||||||
|
add_library(taos SHARED ${CLIENT_SRC})
|
||||||
|
endif ()
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
taos
|
taos
|
||||||
PUBLIC "${TD_SOURCE_DIR}/include/client"
|
PUBLIC "${TD_SOURCE_DIR}/include/client"
|
||||||
|
@ -10,6 +14,13 @@ target_link_libraries(
|
||||||
INTERFACE api
|
INTERFACE api
|
||||||
PRIVATE os util common transport nodes parser command planner catalog scheduler function qcom
|
PRIVATE os util common transport nodes parser command planner catalog scheduler function qcom
|
||||||
)
|
)
|
||||||
|
if(TD_WINDOWS)
|
||||||
|
set_target_properties(taos
|
||||||
|
PROPERTIES
|
||||||
|
LINK_FLAGS
|
||||||
|
/DEF:${CMAKE_CURRENT_SOURCE_DIR}/src/taos.def
|
||||||
|
)
|
||||||
|
endif ()
|
||||||
|
|
||||||
set_target_properties(
|
set_target_properties(
|
||||||
taos
|
taos
|
||||||
|
|
|
@ -231,6 +231,10 @@ static FORCE_INLINE SReqResultInfo* tmqGetNextResInfo(TAOS_RES* res, bool conver
|
||||||
msg->resIter++;
|
msg->resIter++;
|
||||||
if (msg->resIter < msg->rsp.blockNum) {
|
if (msg->resIter < msg->rsp.blockNum) {
|
||||||
SRetrieveTableRsp* pRetrieve = (SRetrieveTableRsp*)taosArrayGetP(msg->rsp.blockData, msg->resIter);
|
SRetrieveTableRsp* pRetrieve = (SRetrieveTableRsp*)taosArrayGetP(msg->rsp.blockData, msg->resIter);
|
||||||
|
if (msg->rsp.withSchema) {
|
||||||
|
SSchemaWrapper* pSW = (SSchemaWrapper*)taosArrayGetP(msg->rsp.blockSchema, msg->resIter);
|
||||||
|
setResSchemaInfo(&msg->resInfo, pSW->pSchema, pSW->nCols);
|
||||||
|
}
|
||||||
setQueryResultFromRsp(&msg->resInfo, pRetrieve, convertUcs4);
|
setQueryResultFromRsp(&msg->resInfo, pRetrieve, convertUcs4);
|
||||||
return &msg->resInfo;
|
return &msg->resInfo;
|
||||||
}
|
}
|
||||||
|
|
|
@ -254,12 +254,12 @@ void taos_init_imp(void) {
|
||||||
|
|
||||||
deltaToUtcInitOnce();
|
deltaToUtcInitOnce();
|
||||||
|
|
||||||
if (taosCreateLog("taoslog", 10, configDir, NULL, NULL, NULL, 1) != 0) {
|
if (taosCreateLog("taoslog", 10, configDir, NULL, NULL, NULL, NULL, 1) != 0) {
|
||||||
tscInitRes = -1;
|
tscInitRes = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosInitCfg(configDir, NULL, NULL, NULL, 1) != 0) {
|
if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 1) != 0) {
|
||||||
tscInitRes = -1;
|
tscInitRes = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "catalog.h"
|
#include "catalog.h"
|
||||||
#include "scheduler.h"
|
|
||||||
#include "clientInt.h"
|
#include "clientInt.h"
|
||||||
#include "clientLog.h"
|
#include "clientLog.h"
|
||||||
|
#include "scheduler.h"
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
|
|
||||||
static SClientHbMgr clientHbMgr = {0};
|
static SClientHbMgr clientHbMgr = {0};
|
||||||
|
@ -110,7 +110,8 @@ static int32_t hbProcessStbInfoRsp(void *value, int32_t valueLen, struct SCatalo
|
||||||
static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) {
|
static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) {
|
||||||
SHbConnInfo *info = taosHashGet(pAppHbMgr->connInfo, &pRsp->connKey, sizeof(SClientHbKey));
|
SHbConnInfo *info = taosHashGet(pAppHbMgr->connInfo, &pRsp->connKey, sizeof(SClientHbKey));
|
||||||
if (NULL == info) {
|
if (NULL == info) {
|
||||||
tscWarn("fail to get connInfo, may be dropped, refId:%" PRIx64 ", type:%d", pRsp->connKey.tscRid, pRsp->connKey.connType);
|
tscWarn("fail to get connInfo, may be dropped, refId:%" PRIx64 ", type:%d", pRsp->connKey.tscRid,
|
||||||
|
pRsp->connKey.connType);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +122,7 @@ static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) {
|
||||||
} else {
|
} else {
|
||||||
updateEpSet_s(&pTscObj->pAppInfo->mgmtEp, &pRsp->query->epSet);
|
updateEpSet_s(&pTscObj->pAppInfo->mgmtEp, &pRsp->query->epSet);
|
||||||
pTscObj->connId = pRsp->query->connId;
|
pTscObj->connId = pRsp->query->connId;
|
||||||
|
|
||||||
if (pRsp->query->killRid) {
|
if (pRsp->query->killRid) {
|
||||||
SRequestObj *pRequest = acquireRequest(pRsp->query->killRid);
|
SRequestObj *pRequest = acquireRequest(pRsp->query->killRid);
|
||||||
if (NULL == pRequest) {
|
if (NULL == pRequest) {
|
||||||
|
@ -131,7 +132,7 @@ static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) {
|
||||||
releaseRequest(pRsp->query->killRid);
|
releaseRequest(pRsp->query->killRid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pRsp->query->killConnection) {
|
if (pRsp->query->killConnection) {
|
||||||
taos_close(pTscObj);
|
taos_close(pTscObj);
|
||||||
}
|
}
|
||||||
|
@ -139,7 +140,7 @@ static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) {
|
||||||
releaseTscObj(pRsp->connKey.tscRid);
|
releaseTscObj(pRsp->connKey.tscRid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t kvNum = pRsp->info ? taosArrayGetSize(pRsp->info) : 0;
|
int32_t kvNum = pRsp->info ? taosArrayGetSize(pRsp->info) : 0;
|
||||||
|
|
||||||
tscDebug("hb got %d rsp kv", kvNum);
|
tscDebug("hb got %d rsp kv", kvNum);
|
||||||
|
@ -236,24 +237,24 @@ static int32_t hbAsyncCallBack(void *param, const SDataBuf *pMsg, int32_t code)
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t hbBuildQueryDesc(SQueryHbReqBasic *hbBasic, STscObj *pObj) {
|
int32_t hbBuildQueryDesc(SQueryHbReqBasic *hbBasic, STscObj *pObj) {
|
||||||
int64_t now = taosGetTimestampUs();
|
int64_t now = taosGetTimestampUs();
|
||||||
SQueryDesc desc = {0};
|
SQueryDesc desc = {0};
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
void *pIter = taosHashIterate(pObj->pRequests, NULL);
|
void *pIter = taosHashIterate(pObj->pRequests, NULL);
|
||||||
while (pIter != NULL) {
|
while (pIter != NULL) {
|
||||||
int64_t *rid = pIter;
|
int64_t *rid = pIter;
|
||||||
SRequestObj *pRequest = acquireRequest(*rid);
|
SRequestObj *pRequest = acquireRequest(*rid);
|
||||||
if (NULL == pRequest) {
|
if (NULL == pRequest) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
tstrncpy(desc.sql, pRequest->sqlstr, sizeof(desc.sql));
|
tstrncpy(desc.sql, pRequest->sqlstr, sizeof(desc.sql));
|
||||||
desc.stime = pRequest->metric.start;
|
desc.stime = pRequest->metric.start;
|
||||||
desc.queryId = pRequest->requestId;
|
desc.queryId = pRequest->requestId;
|
||||||
desc.useconds = now - pRequest->metric.start;
|
desc.useconds = now - pRequest->metric.start;
|
||||||
desc.reqRid = pRequest->self;
|
desc.reqRid = pRequest->self;
|
||||||
desc.pid = hbBasic->pid;
|
desc.pid = hbBasic->pid;
|
||||||
taosGetFqdn(desc.fqdn);
|
taosGetFqdn(desc.fqdn);
|
||||||
desc.subPlanNum = pRequest->body.pDag ? pRequest->body.pDag->numOfSubplans : 0;
|
desc.subPlanNum = pRequest->body.pDag ? pRequest->body.pDag->numOfSubplans : 0;
|
||||||
|
|
||||||
|
@ -271,9 +272,9 @@ int32_t hbBuildQueryDesc(SQueryHbReqBasic *hbBasic, STscObj *pObj) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
releaseRequest(*rid);
|
releaseRequest(*rid);
|
||||||
taosArrayPush(hbBasic->queryDesc, &desc);
|
taosArrayPush(hbBasic->queryDesc, &desc);
|
||||||
|
|
||||||
pIter = taosHashIterate(pObj->pRequests, pIter);
|
pIter = taosHashIterate(pObj->pRequests, pIter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,14 +287,14 @@ int32_t hbGetQueryBasicInfo(SClientHbKey *connKey, SClientHbReq *req) {
|
||||||
tscWarn("tscObj rid %" PRIx64 " not exist", connKey->tscRid);
|
tscWarn("tscObj rid %" PRIx64 " not exist", connKey->tscRid);
|
||||||
return TSDB_CODE_QRY_APP_ERROR;
|
return TSDB_CODE_QRY_APP_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t numOfQueries = pTscObj->pRequests ? taosHashGetSize(pTscObj->pRequests) : 0;
|
int32_t numOfQueries = pTscObj->pRequests ? taosHashGetSize(pTscObj->pRequests) : 0;
|
||||||
if (numOfQueries <= 0) {
|
if (numOfQueries <= 0) {
|
||||||
releaseTscObj(connKey->tscRid);
|
releaseTscObj(connKey->tscRid);
|
||||||
tscDebug("no queries on connection");
|
tscDebug("no queries on connection");
|
||||||
return TSDB_CODE_QRY_APP_ERROR;
|
return TSDB_CODE_QRY_APP_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
SQueryHbReqBasic *hbBasic = (SQueryHbReqBasic *)taosMemoryCalloc(1, sizeof(SQueryHbReqBasic));
|
SQueryHbReqBasic *hbBasic = (SQueryHbReqBasic *)taosMemoryCalloc(1, sizeof(SQueryHbReqBasic));
|
||||||
if (NULL == hbBasic) {
|
if (NULL == hbBasic) {
|
||||||
tscError("calloc %d failed", (int32_t)sizeof(SQueryHbReqBasic));
|
tscError("calloc %d failed", (int32_t)sizeof(SQueryHbReqBasic));
|
||||||
|
@ -308,7 +309,7 @@ int32_t hbGetQueryBasicInfo(SClientHbKey *connKey, SClientHbReq *req) {
|
||||||
taosMemoryFree(hbBasic);
|
taosMemoryFree(hbBasic);
|
||||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
hbBasic->connId = pTscObj->connId;
|
hbBasic->connId = pTscObj->connId;
|
||||||
hbBasic->pid = taosGetPId();
|
hbBasic->pid = taosGetPId();
|
||||||
taosGetAppName(hbBasic->app, NULL);
|
taosGetAppName(hbBasic->app, NULL);
|
||||||
|
@ -405,7 +406,7 @@ int32_t hbQueryHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req
|
||||||
}
|
}
|
||||||
|
|
||||||
hbGetQueryBasicInfo(connKey, req);
|
hbGetQueryBasicInfo(connKey, req);
|
||||||
|
|
||||||
code = hbGetExpiredDBInfo(connKey, pCatalog, req);
|
code = hbGetExpiredDBInfo(connKey, pCatalog, req);
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
return code;
|
return code;
|
||||||
|
@ -471,10 +472,10 @@ SClientHbBatchReq *hbGatherAllInfo(SAppHbMgr *pAppHbMgr) {
|
||||||
pIter = taosHashIterate(pAppHbMgr->activeInfo, pIter);
|
pIter = taosHashIterate(pAppHbMgr->activeInfo, pIter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (code) {
|
// if (code) {
|
||||||
// taosArrayDestroyEx(pBatchReq->reqs, hbFreeReq);
|
// taosArrayDestroyEx(pBatchReq->reqs, hbFreeReq);
|
||||||
// taosMemoryFreeClear(pBatchReq);
|
// taosMemoryFreeClear(pBatchReq);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
return pBatchReq;
|
return pBatchReq;
|
||||||
}
|
}
|
||||||
|
@ -630,24 +631,23 @@ void appHbMgrCleanup(void) {
|
||||||
int sz = taosArrayGetSize(clientHbMgr.appHbMgrs);
|
int sz = taosArrayGetSize(clientHbMgr.appHbMgrs);
|
||||||
for (int i = 0; i < sz; i++) {
|
for (int i = 0; i < sz; i++) {
|
||||||
SAppHbMgr *pTarget = taosArrayGetP(clientHbMgr.appHbMgrs, i);
|
SAppHbMgr *pTarget = taosArrayGetP(clientHbMgr.appHbMgrs, i);
|
||||||
|
|
||||||
void *pIter = taosHashIterate(pTarget->activeInfo, NULL);
|
void *pIter = taosHashIterate(pTarget->activeInfo, NULL);
|
||||||
while (pIter != NULL) {
|
while (pIter != NULL) {
|
||||||
SClientHbReq *pOneReq = pIter;
|
SClientHbReq *pOneReq = pIter;
|
||||||
hbFreeReq(pOneReq);
|
hbFreeReq(pOneReq);
|
||||||
taosHashCleanup(pOneReq->info);
|
taosHashCleanup(pOneReq->info);
|
||||||
pIter = taosHashIterate(pTarget->activeInfo, pIter);
|
pIter = taosHashIterate(pTarget->activeInfo, pIter);
|
||||||
}
|
}
|
||||||
taosHashCleanup(pTarget->activeInfo);
|
taosHashCleanup(pTarget->activeInfo);
|
||||||
pTarget->activeInfo = NULL;
|
pTarget->activeInfo = NULL;
|
||||||
|
|
||||||
|
|
||||||
pIter = taosHashIterate(pTarget->connInfo, NULL);
|
pIter = taosHashIterate(pTarget->connInfo, NULL);
|
||||||
while (pIter != NULL) {
|
while (pIter != NULL) {
|
||||||
SHbConnInfo *info = pIter;
|
SHbConnInfo *info = pIter;
|
||||||
taosMemoryFree(info->param);
|
taosMemoryFree(info->param);
|
||||||
pIter = taosHashIterate(pTarget->connInfo, pIter);
|
pIter = taosHashIterate(pTarget->connInfo, pIter);
|
||||||
}
|
}
|
||||||
taosHashCleanup(pTarget->connInfo);
|
taosHashCleanup(pTarget->connInfo);
|
||||||
pTarget->connInfo = NULL;
|
pTarget->connInfo = NULL;
|
||||||
|
|
||||||
|
@ -668,13 +668,13 @@ int hbMgrInit() {
|
||||||
hbMgrInitHandle();
|
hbMgrInitHandle();
|
||||||
|
|
||||||
// init backgroud thread
|
// init backgroud thread
|
||||||
//hbCreateThread();
|
/*hbCreateThread();*/
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hbMgrCleanUp() {
|
void hbMgrCleanUp() {
|
||||||
//hbStopThread();
|
// hbStopThread();
|
||||||
|
|
||||||
// destroy all appHbMgr
|
// destroy all appHbMgr
|
||||||
int8_t old = atomic_val_compare_exchange_8(&clientHbMgr.inited, 1, 0);
|
int8_t old = atomic_val_compare_exchange_8(&clientHbMgr.inited, 1, 0);
|
||||||
|
@ -747,11 +747,11 @@ void hbDeregisterConn(SAppHbMgr *pAppHbMgr, SClientHbKey connKey) {
|
||||||
taosMemoryFree(info->param);
|
taosMemoryFree(info->param);
|
||||||
taosHashRemove(pAppHbMgr->connInfo, &connKey, sizeof(SClientHbKey));
|
taosHashRemove(pAppHbMgr->connInfo, &connKey, sizeof(SClientHbKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL == pReq || NULL == info) {
|
if (NULL == pReq || NULL == info) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
atomic_sub_fetch_32(&pAppHbMgr->connKeyCnt, 1);
|
atomic_sub_fetch_32(&pAppHbMgr->connKeyCnt, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,9 +105,9 @@ TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass,
|
||||||
epSet.epSet.eps[0].port = port;
|
epSet.epSet.eps[0].port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* key = getClusterKey(user, secretEncrypt, ip, port);
|
char* key = getClusterKey(user, secretEncrypt, ip, port);
|
||||||
SAppInstInfo** pInst = NULL;
|
|
||||||
|
|
||||||
|
SAppInstInfo** pInst = NULL;
|
||||||
taosThreadMutexLock(&appInfo.mutex);
|
taosThreadMutexLock(&appInfo.mutex);
|
||||||
|
|
||||||
pInst = taosHashGet(appInfo.pInstMap, key, strlen(key));
|
pInst = taosHashGet(appInfo.pInstMap, key, strlen(key));
|
||||||
|
@ -226,17 +226,15 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) {
|
||||||
|
|
||||||
int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList) {
|
int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList) {
|
||||||
pRequest->type = pQuery->msgType;
|
pRequest->type = pQuery->msgType;
|
||||||
SPlanContext cxt = {
|
SPlanContext cxt = {.queryId = pRequest->requestId,
|
||||||
.queryId = pRequest->requestId,
|
.acctId = pRequest->pTscObj->acctId,
|
||||||
.acctId = pRequest->pTscObj->acctId,
|
.mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp),
|
||||||
.mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp),
|
.pAstRoot = pQuery->pRoot,
|
||||||
.pAstRoot = pQuery->pRoot,
|
.showRewrite = pQuery->showRewrite,
|
||||||
.showRewrite = pQuery->showRewrite,
|
.pTransporter = pRequest->pTscObj->pAppInfo->pTransporter,
|
||||||
.pTransporter = pRequest->pTscObj->pAppInfo->pTransporter,
|
.pMsg = pRequest->msgBuf,
|
||||||
.pMsg = pRequest->msgBuf,
|
.msgLen = ERROR_MSG_BUF_DEFAULT_SIZE};
|
||||||
.msgLen = ERROR_MSG_BUF_DEFAULT_SIZE
|
int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &cxt.pCatalog);
|
||||||
};
|
|
||||||
int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &cxt.pCatalog);
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = qCreateQueryPlan(&cxt, pPlan, pNodeList);
|
code = qCreateQueryPlan(&cxt, pPlan, pNodeList);
|
||||||
}
|
}
|
||||||
|
@ -247,6 +245,7 @@ void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t
|
||||||
ASSERT(pSchema != NULL && numOfCols > 0);
|
ASSERT(pSchema != NULL && numOfCols > 0);
|
||||||
|
|
||||||
pResInfo->numOfCols = numOfCols;
|
pResInfo->numOfCols = numOfCols;
|
||||||
|
// TODO handle memory leak
|
||||||
pResInfo->fields = taosMemoryCalloc(numOfCols, sizeof(TAOS_FIELD));
|
pResInfo->fields = taosMemoryCalloc(numOfCols, sizeof(TAOS_FIELD));
|
||||||
pResInfo->userFields = taosMemoryCalloc(numOfCols, sizeof(TAOS_FIELD));
|
pResInfo->userFields = taosMemoryCalloc(numOfCols, sizeof(TAOS_FIELD));
|
||||||
|
|
||||||
|
@ -282,7 +281,7 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList
|
||||||
|
|
||||||
SQueryResult res = {.code = 0, .numOfRows = 0, .msgSize = ERROR_MSG_BUF_DEFAULT_SIZE, .msg = pRequest->msgBuf};
|
SQueryResult res = {.code = 0, .numOfRows = 0, .msgSize = ERROR_MSG_BUF_DEFAULT_SIZE, .msg = pRequest->msgBuf};
|
||||||
int32_t code = schedulerExecJob(pTransporter, pNodeList, pDag, &pRequest->body.queryJob, pRequest->sqlstr,
|
int32_t code = schedulerExecJob(pTransporter, pNodeList, pDag, &pRequest->body.queryJob, pRequest->sqlstr,
|
||||||
pRequest->metric.start, &res);
|
pRequest->metric.start, &res);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
if (pRequest->body.queryJob != 0) {
|
if (pRequest->body.queryJob != 0) {
|
||||||
schedulerFreeJob(pRequest->body.queryJob);
|
schedulerFreeJob(pRequest->body.queryJob);
|
||||||
|
@ -840,10 +839,21 @@ int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t* colLength = (int32_t*)pResultInfo->pData;
|
char* p = (char*)pResultInfo->pData;
|
||||||
char* pStart = ((char*)pResultInfo->pData) + sizeof(int32_t) * numOfCols;
|
|
||||||
|
int32_t dataLen = *(int32_t*)p;
|
||||||
|
p += sizeof(int32_t);
|
||||||
|
|
||||||
|
uint64_t groupId = *(uint64_t*)p;
|
||||||
|
p += sizeof(uint64_t);
|
||||||
|
|
||||||
|
int32_t* colLength = (int32_t*)p;
|
||||||
|
p += sizeof(int32_t) * numOfCols;
|
||||||
|
|
||||||
|
char* pStart = p;
|
||||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||||
colLength[i] = htonl(colLength[i]);
|
colLength[i] = htonl(colLength[i]);
|
||||||
|
ASSERT(colLength[i] < dataLen);
|
||||||
|
|
||||||
if (IS_VAR_DATA_TYPE(pResultInfo->fields[i].type)) {
|
if (IS_VAR_DATA_TYPE(pResultInfo->fields[i].type)) {
|
||||||
pResultInfo->pCol[i].offset = (int32_t*)pStart;
|
pResultInfo->pCol[i].offset = (int32_t*)pStart;
|
||||||
|
|
|
@ -120,7 +120,7 @@ const char *taos_errstr(TAOS_RES *res) {
|
||||||
return (const char *)tstrerror(terrno);
|
return (const char *)tstrerror(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(pRequest->msgBuf) > 0 || pRequest->code == TSDB_CODE_RPC_FQDN_ERROR) {
|
if (NULL != pRequest->msgBuf && (strlen(pRequest->msgBuf) > 0 || pRequest->code == TSDB_CODE_RPC_FQDN_ERROR)) {
|
||||||
return pRequest->msgBuf;
|
return pRequest->msgBuf;
|
||||||
} else {
|
} else {
|
||||||
return (const char *)tstrerror(pRequest->code);
|
return (const char *)tstrerror(pRequest->code);
|
||||||
|
|
|
@ -13,13 +13,13 @@
|
||||||
* 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 "os.h"
|
#include "catalog.h"
|
||||||
#include "tdef.h"
|
|
||||||
#include "tname.h"
|
|
||||||
#include "clientInt.h"
|
#include "clientInt.h"
|
||||||
#include "clientLog.h"
|
#include "clientLog.h"
|
||||||
#include "catalog.h"
|
#include "os.h"
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
|
#include "tdef.h"
|
||||||
|
#include "tname.h"
|
||||||
|
|
||||||
int32_t (*handleRequestRspFp[TDMT_MAX])(void*, const SDataBuf* pMsg, int32_t code);
|
int32_t (*handleRequestRspFp[TDMT_MAX])(void*, const SDataBuf* pMsg, int32_t code);
|
||||||
|
|
||||||
|
@ -50,7 +50,13 @@ int32_t processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
|
|
||||||
SConnectRsp connectRsp = {0};
|
SConnectRsp connectRsp = {0};
|
||||||
tDeserializeSConnectRsp(pMsg->pData, pMsg->len, &connectRsp);
|
tDeserializeSConnectRsp(pMsg->pData, pMsg->len, &connectRsp);
|
||||||
assert(connectRsp.epSet.numOfEps > 0);
|
/*assert(connectRsp.epSet.numOfEps > 0);*/
|
||||||
|
if (connectRsp.epSet.numOfEps == 0) {
|
||||||
|
taosMemoryFree(pMsg->pData);
|
||||||
|
setErrno(pRequest, TSDB_CODE_MND_APP_ERROR);
|
||||||
|
tsem_post(&pRequest->body.rspSem);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
if (!isEpsetEqual(&pTscObj->pAppInfo->mgmtEp.epSet, &connectRsp.epSet)) {
|
if (!isEpsetEqual(&pTscObj->pAppInfo->mgmtEp.epSet, &connectRsp.epSet)) {
|
||||||
updateEpSet_s(&pTscObj->pAppInfo->mgmtEp, &connectRsp.epSet);
|
updateEpSet_s(&pTscObj->pAppInfo->mgmtEp, &connectRsp.epSet);
|
||||||
|
@ -82,18 +88,20 @@ int32_t processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMsgSendInfo* buildMsgInfoImpl(SRequestObj *pRequest) {
|
SMsgSendInfo* buildMsgInfoImpl(SRequestObj* pRequest) {
|
||||||
SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
|
SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
|
||||||
|
|
||||||
pMsgSendInfo->requestObjRefId = pRequest->self;
|
pMsgSendInfo->requestObjRefId = pRequest->self;
|
||||||
pMsgSendInfo->requestId = pRequest->requestId;
|
pMsgSendInfo->requestId = pRequest->requestId;
|
||||||
pMsgSendInfo->param = pRequest;
|
pMsgSendInfo->param = pRequest;
|
||||||
pMsgSendInfo->msgType = pRequest->type;
|
pMsgSendInfo->msgType = pRequest->type;
|
||||||
|
|
||||||
assert(pRequest != NULL);
|
assert(pRequest != NULL);
|
||||||
pMsgSendInfo->msgInfo = pRequest->body.requestMsg;
|
pMsgSendInfo->msgInfo = pRequest->body.requestMsg;
|
||||||
|
|
||||||
pMsgSendInfo->fp = (handleRequestRspFp[TMSG_INDEX(pRequest->type)] == NULL)? genericRspCallback:handleRequestRspFp[TMSG_INDEX(pRequest->type)];
|
pMsgSendInfo->fp = (handleRequestRspFp[TMSG_INDEX(pRequest->type)] == NULL)
|
||||||
|
? genericRspCallback
|
||||||
|
: handleRequestRspFp[TMSG_INDEX(pRequest->type)];
|
||||||
return pMsgSendInfo;
|
return pMsgSendInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +122,7 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
if (TSDB_CODE_MND_DB_NOT_EXIST == code) {
|
if (TSDB_CODE_MND_DB_NOT_EXIST == code) {
|
||||||
SUseDbRsp usedbRsp = {0};
|
SUseDbRsp usedbRsp = {0};
|
||||||
tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp);
|
tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp);
|
||||||
struct SCatalog *pCatalog = NULL;
|
struct SCatalog* pCatalog = NULL;
|
||||||
|
|
||||||
if (usedbRsp.vgVersion >= 0) {
|
if (usedbRsp.vgVersion >= 0) {
|
||||||
int32_t code1 = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
|
int32_t code1 = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
taos_cleanup
|
||||||
|
taos_options
|
||||||
|
taos_set_config
|
||||||
|
taos_connect
|
||||||
|
taos_connect_l
|
||||||
|
taos_connect_auth
|
||||||
|
taos_close
|
||||||
|
taos_data_type
|
||||||
|
taos_stmt_init
|
||||||
|
taos_stmt_prepare
|
||||||
|
taos_stmt_set_tbname_tags
|
||||||
|
taos_stmt_set_tbname
|
||||||
|
taos_stmt_set_sub_tbname
|
||||||
|
taos_stmt_is_insert
|
||||||
|
taos_stmt_num_params
|
||||||
|
taos_stmt_get_param
|
||||||
|
taos_stmt_bind_param
|
||||||
|
taos_stmt_bind_param_batch
|
||||||
|
taos_stmt_bind_single_param_batch
|
||||||
|
taos_stmt_add_batch
|
||||||
|
taos_stmt_execute
|
||||||
|
taos_stmt_use_result
|
||||||
|
taos_stmt_close
|
||||||
|
taos_stmt_errstr
|
||||||
|
taos_stmt_affected_rows
|
||||||
|
taos_stmt_affected_rows_once
|
||||||
|
taos_query
|
||||||
|
taos_query_l
|
||||||
|
taos_fetch_row
|
||||||
|
taos_result_precision
|
||||||
|
taos_free_result
|
||||||
|
taos_field_count
|
||||||
|
taos_num_fields
|
||||||
|
taos_affected_rows
|
||||||
|
taos_fetch_fields
|
||||||
|
taos_select_db
|
||||||
|
taos_print_row
|
||||||
|
taos_stop_query
|
||||||
|
taos_is_null
|
||||||
|
taos_is_update_query
|
||||||
|
taos_fetch_block
|
||||||
|
taos_fetch_block_s
|
||||||
|
taos_fetch_raw_block
|
||||||
|
taos_get_column_data_offset
|
||||||
|
taos_validate_sql
|
||||||
|
taos_reset_current_db
|
||||||
|
taos_fetch_lengths
|
||||||
|
taos_result_block
|
||||||
|
taos_get_server_info
|
||||||
|
taos_get_client_info
|
||||||
|
taos_errstr
|
||||||
|
taos_errno
|
||||||
|
taos_query_a
|
||||||
|
taos_fetch_rows_a
|
||||||
|
taos_subscribe
|
||||||
|
taos_consume
|
||||||
|
taos_unsubscribe
|
||||||
|
taos_load_table_info
|
||||||
|
taos_schemaless_insert
|
||||||
|
tmq_list_new
|
||||||
|
tmq_list_append
|
||||||
|
tmq_list_destroy
|
||||||
|
tmq_list_get_size
|
||||||
|
tmq_list_to_c_array
|
||||||
|
tmq_consumer_new
|
||||||
|
tmq_err2str
|
||||||
|
tmq_subscribe
|
||||||
|
tmq_unsubscribe
|
||||||
|
tmq_subscription
|
||||||
|
tmq_consumer_poll
|
||||||
|
tmq_consumer_close
|
||||||
|
tmq_commit
|
||||||
|
tmq_conf_new
|
||||||
|
tmq_conf_set
|
||||||
|
tmq_conf_destroy
|
||||||
|
tmq_conf_set_offset_commit_cb
|
||||||
|
tmq_get_topic_name
|
||||||
|
tmq_get_vgroup_id
|
||||||
|
tmq_create_stream
|
||||||
|
taos_check_server_status
|
|
@ -0,0 +1,31 @@
|
||||||
|
1 VERSIONINFO
|
||||||
|
FILEVERSION ${TD_VER_NUMBER}
|
||||||
|
PRODUCTVERSION ${TD_VER_NUMBER}
|
||||||
|
FILEFLAGSMASK 0x17L
|
||||||
|
#ifdef _DEBUG
|
||||||
|
FILEFLAGS 0x1L
|
||||||
|
#else
|
||||||
|
FILEFLAGS 0x0L
|
||||||
|
#endif
|
||||||
|
FILEOS 0x4L
|
||||||
|
FILETYPE 0x0L
|
||||||
|
FILESUBTYPE 0x0L
|
||||||
|
BEGIN
|
||||||
|
BLOCK "StringFileInfo"
|
||||||
|
BEGIN
|
||||||
|
BLOCK "040904b0"
|
||||||
|
BEGIN
|
||||||
|
VALUE "FileDescription", "Native C Driver for TDengine"
|
||||||
|
VALUE "FileVersion", "${TD_VER_NUMBER}"
|
||||||
|
VALUE "InternalName", "taos.dll(${TD_VER_CPUTYPE})"
|
||||||
|
VALUE "LegalCopyright", "Copyright (C) 2020 TAOS Data"
|
||||||
|
VALUE "OriginalFilename", ""
|
||||||
|
VALUE "ProductName", "taos.dll(${TD_VER_CPUTYPE})"
|
||||||
|
VALUE "ProductVersion", "${TD_VER_NUMBER}"
|
||||||
|
END
|
||||||
|
END
|
||||||
|
BLOCK "VarFileInfo"
|
||||||
|
BEGIN
|
||||||
|
VALUE "Translation", 0x409, 1200
|
||||||
|
END
|
||||||
|
END
|
|
@ -23,6 +23,9 @@
|
||||||
#include "tmsgtype.h"
|
#include "tmsgtype.h"
|
||||||
#include "tqueue.h"
|
#include "tqueue.h"
|
||||||
#include "tref.h"
|
#include "tref.h"
|
||||||
|
#include "ttimer.h"
|
||||||
|
|
||||||
|
int32_t tmqAskEp(tmq_t* tmq, bool sync);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int8_t tmqRspType;
|
int8_t tmqRspType;
|
||||||
|
@ -53,7 +56,7 @@ struct tmq_conf_t {
|
||||||
int8_t autoCommit;
|
int8_t autoCommit;
|
||||||
int8_t resetOffset;
|
int8_t resetOffset;
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
uint16_t autoCommitInterval;
|
int32_t autoCommitInterval;
|
||||||
char* ip;
|
char* ip;
|
||||||
char* user;
|
char* user;
|
||||||
char* pass;
|
char* pass;
|
||||||
|
@ -61,29 +64,48 @@ struct tmq_conf_t {
|
||||||
tmq_commit_cb* commit_cb;
|
tmq_commit_cb* commit_cb;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int8_t inited;
|
||||||
|
tmr_h timer;
|
||||||
|
} SMqMgmt;
|
||||||
|
|
||||||
|
static SMqMgmt tmqMgmt = {0};
|
||||||
|
|
||||||
struct tmq_t {
|
struct tmq_t {
|
||||||
// conf
|
// conf
|
||||||
char groupId[TSDB_CGROUP_LEN];
|
char groupId[TSDB_CGROUP_LEN];
|
||||||
char clientId[256];
|
char clientId[256];
|
||||||
int8_t autoCommit;
|
int8_t autoCommit;
|
||||||
/*int8_t inWaiting;*/
|
int32_t autoCommitInterval;
|
||||||
int64_t consumerId;
|
|
||||||
int32_t epoch;
|
|
||||||
int32_t resetOffsetCfg;
|
int32_t resetOffsetCfg;
|
||||||
int64_t status;
|
int64_t consumerId;
|
||||||
STscObj* pTscObj;
|
|
||||||
tmq_commit_cb* commit_cb;
|
tmq_commit_cb* commit_cb;
|
||||||
/*int32_t nextTopicIdx;*/
|
|
||||||
|
// status
|
||||||
|
int8_t status;
|
||||||
|
int32_t epoch;
|
||||||
|
#if 0
|
||||||
int8_t epStatus;
|
int8_t epStatus;
|
||||||
int32_t epSkipCnt;
|
int32_t epSkipCnt;
|
||||||
/*int32_t waitingRequest;*/
|
#endif
|
||||||
/*int32_t readyRequest;*/
|
|
||||||
SArray* clientTopics; // SArray<SMqClientTopic>
|
|
||||||
STaosQueue* mqueue; // queue of tmq_message_t
|
|
||||||
STaosQall* qall;
|
|
||||||
tsem_t rspSem;
|
|
||||||
// stat
|
|
||||||
int64_t pollCnt;
|
int64_t pollCnt;
|
||||||
|
|
||||||
|
// timer
|
||||||
|
tmr_h hbTimer;
|
||||||
|
tmr_h reportTimer;
|
||||||
|
tmr_h commitTimer;
|
||||||
|
|
||||||
|
// connection
|
||||||
|
STscObj* pTscObj;
|
||||||
|
|
||||||
|
// container
|
||||||
|
SArray* clientTopics; // SArray<SMqClientTopic>
|
||||||
|
STaosQueue* mqueue; // queue of rsp
|
||||||
|
STaosQall* qall;
|
||||||
|
STaosQueue* delayedTask; // delayed task queue for heartbeat and auto commit
|
||||||
|
|
||||||
|
// ctl
|
||||||
|
tsem_t rspSem;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
@ -93,9 +115,16 @@ enum {
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
TMQ_CONSUMER_STATUS__INIT = 0,
|
TMQ_CONSUMER_STATUS__INIT = 0,
|
||||||
|
TMQ_CONSUMER_STATUS__SUBSCRIBED,
|
||||||
TMQ_CONSUMER_STATUS__READY,
|
TMQ_CONSUMER_STATUS__READY,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
TMQ_DELAYED_TASK__HB = 1,
|
||||||
|
TMQ_DELAYED_TASK__REPORT,
|
||||||
|
TMQ_DELAYED_TASK__COMMIT,
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
// statistics
|
// statistics
|
||||||
int64_t pollCnt;
|
int64_t pollCnt;
|
||||||
|
@ -110,13 +139,11 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
// subscribe info
|
// subscribe info
|
||||||
int32_t sqlLen;
|
char* topicName;
|
||||||
char* sql;
|
|
||||||
char* topicName;
|
SArray* vgs; // SArray<SMqClientVg>
|
||||||
int64_t topicId;
|
|
||||||
SArray* vgs; // SArray<SMqClientVg>
|
|
||||||
int8_t isSchemaAdaptive;
|
int8_t isSchemaAdaptive;
|
||||||
int32_t numOfFields;
|
|
||||||
SSchemaWrapper schema;
|
SSchemaWrapper schema;
|
||||||
} SMqClientTopic;
|
} SMqClientTopic;
|
||||||
|
|
||||||
|
@ -156,7 +183,6 @@ typedef struct {
|
||||||
int32_t async;
|
int32_t async;
|
||||||
tsem_t rspSem;
|
tsem_t rspSem;
|
||||||
tmq_resp_err_t rspErr;
|
tmq_resp_err_t rspErr;
|
||||||
/*SMqClientVg* pVg;*/
|
|
||||||
} SMqCommitCbParam;
|
} SMqCommitCbParam;
|
||||||
|
|
||||||
tmq_conf_t* tmq_conf_new() {
|
tmq_conf_t* tmq_conf_new() {
|
||||||
|
@ -251,13 +277,7 @@ int32_t tmq_list_append(tmq_list_t* list, const char* src) {
|
||||||
|
|
||||||
void tmq_list_destroy(tmq_list_t* list) {
|
void tmq_list_destroy(tmq_list_t* list) {
|
||||||
SArray* container = &list->container;
|
SArray* container = &list->container;
|
||||||
/*taosArrayDestroy(container);*/
|
taosArrayDestroyP(container, taosMemoryFree);
|
||||||
int32_t sz = taosArrayGetSize(container);
|
|
||||||
for (int32_t i = 0; i < sz; i++) {
|
|
||||||
char* str = taosArrayGetP(container, i);
|
|
||||||
taosMemoryFree(str);
|
|
||||||
}
|
|
||||||
taosArrayDestroy(container);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tmq_list_get_size(const tmq_list_t* list) {
|
int32_t tmq_list_get_size(const tmq_list_t* list) {
|
||||||
|
@ -274,6 +294,50 @@ static int32_t tmqMakeTopicVgKey(char* dst, const char* topicName, int32_t vg) {
|
||||||
return sprintf(dst, "%s:%d", topicName, vg);
|
return sprintf(dst, "%s:%d", topicName, vg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tmqAssignDelayedHbTask(void* param, void* tmrId) {
|
||||||
|
tmq_t* tmq = (tmq_t*)param;
|
||||||
|
int8_t* pTaskType = taosAllocateQitem(sizeof(int8_t));
|
||||||
|
*pTaskType = TMQ_DELAYED_TASK__HB;
|
||||||
|
taosWriteQitem(tmq->delayedTask, pTaskType);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tmqAssignDelayedCommitTask(void* param, void* tmrId) {
|
||||||
|
tmq_t* tmq = (tmq_t*)param;
|
||||||
|
int8_t* pTaskType = taosAllocateQitem(sizeof(int8_t));
|
||||||
|
*pTaskType = TMQ_DELAYED_TASK__COMMIT;
|
||||||
|
taosWriteQitem(tmq->delayedTask, pTaskType);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tmqAssignDelayedReportTask(void* param, void* tmrId) {
|
||||||
|
tmq_t* tmq = (tmq_t*)param;
|
||||||
|
int8_t* pTaskType = taosAllocateQitem(sizeof(int8_t));
|
||||||
|
*pTaskType = TMQ_DELAYED_TASK__REPORT;
|
||||||
|
taosWriteQitem(tmq->delayedTask, pTaskType);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tmqHandleAllDelayedTask(tmq_t* tmq) {
|
||||||
|
STaosQall* qall = taosAllocateQall();
|
||||||
|
taosReadAllQitems(tmq->delayedTask, qall);
|
||||||
|
while (1) {
|
||||||
|
int8_t* pTaskType = NULL;
|
||||||
|
taosGetQitem(qall, (void**)&pTaskType);
|
||||||
|
if (pTaskType == NULL) break;
|
||||||
|
|
||||||
|
if (*pTaskType == TMQ_DELAYED_TASK__HB) {
|
||||||
|
tmqAskEp(tmq, false);
|
||||||
|
taosTmrReset(tmqAssignDelayedHbTask, 1000, tmq, tmqMgmt.timer, &tmq->hbTimer);
|
||||||
|
} else if (*pTaskType == TMQ_DELAYED_TASK__COMMIT) {
|
||||||
|
tmq_commit(tmq, NULL, true);
|
||||||
|
taosTmrReset(tmqAssignDelayedCommitTask, tmq->autoCommitInterval, tmq, tmqMgmt.timer, &tmq->commitTimer);
|
||||||
|
} else if (*pTaskType == TMQ_DELAYED_TASK__REPORT) {
|
||||||
|
} else {
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
taosFreeQall(qall);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void tmqClearUnhandleMsg(tmq_t* tmq) {
|
void tmqClearUnhandleMsg(tmq_t* tmq) {
|
||||||
SMqRspWrapper* msg = NULL;
|
SMqRspWrapper* msg = NULL;
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -298,6 +362,8 @@ void tmqClearUnhandleMsg(tmq_t* tmq) {
|
||||||
int32_t tmqSubscribeCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
int32_t tmqSubscribeCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
SMqSubscribeCbParam* pParam = (SMqSubscribeCbParam*)param;
|
SMqSubscribeCbParam* pParam = (SMqSubscribeCbParam*)param;
|
||||||
pParam->rspErr = code;
|
pParam->rspErr = code;
|
||||||
|
tmq_t* tmq = pParam->tmq;
|
||||||
|
atomic_store_8(&tmq->status, TMQ_CONSUMER_STATUS__SUBSCRIBED);
|
||||||
tsem_post(&pParam->rspSem);
|
tsem_post(&pParam->rspSem);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -335,12 +401,9 @@ tmq_t* tmq_consumer_new(void* conn, tmq_conf_t* conf, char* errstr, int32_t errs
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
pTmq->pTscObj = (STscObj*)conn;
|
pTmq->pTscObj = (STscObj*)conn;
|
||||||
/*pTmq->inWaiting = 0;*/
|
|
||||||
pTmq->status = 0;
|
pTmq->status = 0;
|
||||||
pTmq->pollCnt = 0;
|
pTmq->pollCnt = 0;
|
||||||
pTmq->epoch = 0;
|
pTmq->epoch = 0;
|
||||||
/*pTmq->waitingRequest = 0;*/
|
|
||||||
/*pTmq->readyRequest = 0;*/
|
|
||||||
pTmq->epStatus = 0;
|
pTmq->epStatus = 0;
|
||||||
pTmq->epSkipCnt = 0;
|
pTmq->epSkipCnt = 0;
|
||||||
// set conf
|
// set conf
|
||||||
|
@ -367,49 +430,78 @@ tmq_t* tmq_consumer_new(void* conn, tmq_conf_t* conf, char* errstr, int32_t errs
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
|
tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
|
||||||
|
// init timer
|
||||||
|
int8_t inited = atomic_val_compare_exchange_8(&tmqMgmt.inited, 0, 1);
|
||||||
|
if (inited == 0) {
|
||||||
|
tmqMgmt.timer = taosTmrInit(1000, 100, 360000, "TMQ");
|
||||||
|
if (tmqMgmt.timer == NULL) {
|
||||||
|
atomic_store_8(&tmqMgmt.inited, 0);
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tmq_t* pTmq = taosMemoryCalloc(1, sizeof(tmq_t));
|
tmq_t* pTmq = taosMemoryCalloc(1, sizeof(tmq_t));
|
||||||
if (pTmq == NULL) {
|
if (pTmq == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* user = conf->user == NULL ? TSDB_DEFAULT_USER : conf->user;
|
const char* user = conf->user == NULL ? TSDB_DEFAULT_USER : conf->user;
|
||||||
const char* pass = conf->pass == NULL ? TSDB_DEFAULT_PASS : conf->pass;
|
const char* pass = conf->pass == NULL ? TSDB_DEFAULT_PASS : conf->pass;
|
||||||
|
|
||||||
ASSERT(user);
|
ASSERT(user);
|
||||||
ASSERT(pass);
|
ASSERT(pass);
|
||||||
ASSERT(conf->db);
|
|
||||||
ASSERT(conf->groupId[0]);
|
ASSERT(conf->groupId[0]);
|
||||||
|
|
||||||
pTmq->pTscObj = taos_connect_internal(conf->ip, user, pass, NULL, conf->db, conf->port, CONN_TYPE__TMQ);
|
pTmq->clientTopics = taosArrayInit(0, sizeof(SMqClientTopic));
|
||||||
if (pTmq->pTscObj == NULL) return NULL;
|
pTmq->mqueue = taosOpenQueue();
|
||||||
|
pTmq->qall = taosAllocateQall();
|
||||||
|
pTmq->delayedTask = taosOpenQueue();
|
||||||
|
|
||||||
/*pTmq->inWaiting = 0;*/
|
if (pTmq->clientTopics == NULL || pTmq->mqueue == NULL || pTmq->qall == NULL || pTmq->delayedTask == NULL) {
|
||||||
pTmq->status = 0;
|
goto FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// init status
|
||||||
|
pTmq->status = TMQ_CONSUMER_STATUS__INIT;
|
||||||
pTmq->pollCnt = 0;
|
pTmq->pollCnt = 0;
|
||||||
pTmq->epoch = 0;
|
pTmq->epoch = 0;
|
||||||
/*pTmq->waitingRequest = 0;*/
|
/*pTmq->epStatus = 0;*/
|
||||||
/*pTmq->readyRequest = 0;*/
|
/*pTmq->epSkipCnt = 0;*/
|
||||||
pTmq->epStatus = 0;
|
|
||||||
pTmq->epSkipCnt = 0;
|
|
||||||
// set conf
|
// set conf
|
||||||
strcpy(pTmq->clientId, conf->clientId);
|
strcpy(pTmq->clientId, conf->clientId);
|
||||||
strcpy(pTmq->groupId, conf->groupId);
|
strcpy(pTmq->groupId, conf->groupId);
|
||||||
pTmq->autoCommit = conf->autoCommit;
|
/*pTmq->autoCommit = conf->autoCommit;*/
|
||||||
|
pTmq->autoCommit = 0;
|
||||||
|
pTmq->autoCommitInterval = conf->autoCommitInterval;
|
||||||
pTmq->commit_cb = conf->commit_cb;
|
pTmq->commit_cb = conf->commit_cb;
|
||||||
pTmq->resetOffsetCfg = conf->resetOffset;
|
pTmq->resetOffsetCfg = conf->resetOffset;
|
||||||
|
|
||||||
|
// assign consumerId
|
||||||
pTmq->consumerId = tGenIdPI64();
|
pTmq->consumerId = tGenIdPI64();
|
||||||
pTmq->clientTopics = taosArrayInit(0, sizeof(SMqClientTopic));
|
|
||||||
if (pTmq->clientTopics == NULL) {
|
// init semaphore
|
||||||
taosMemoryFree(pTmq);
|
if (tsem_init(&pTmq->rspSem, 0, 0) != 0) {
|
||||||
return NULL;
|
goto FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pTmq->mqueue = taosOpenQueue();
|
// init connection
|
||||||
pTmq->qall = taosAllocateQall();
|
pTmq->pTscObj = taos_connect_internal(conf->ip, user, pass, NULL, NULL, conf->port, CONN_TYPE__TMQ);
|
||||||
|
if (pTmq->pTscObj == NULL) {
|
||||||
tsem_init(&pTmq->rspSem, 0, 0);
|
tsem_destroy(&pTmq->rspSem);
|
||||||
|
goto FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
return pTmq;
|
return pTmq;
|
||||||
|
|
||||||
|
FAIL:
|
||||||
|
if (pTmq->clientTopics) taosArrayDestroy(pTmq->clientTopics);
|
||||||
|
if (pTmq->mqueue) taosCloseQueue(pTmq->mqueue);
|
||||||
|
if (pTmq->delayedTask) taosCloseQueue(pTmq->delayedTask);
|
||||||
|
if (pTmq->qall) taosFreeQall(pTmq->qall);
|
||||||
|
taosMemoryFree(pTmq);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, int32_t async) {
|
tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, int32_t async) {
|
||||||
|
@ -500,81 +592,64 @@ tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, in
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmq_resp_err_t tmq_subscribe(tmq_t* tmq, tmq_list_t* topic_list) {
|
tmq_resp_err_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
|
||||||
SRequestObj* pRequest = NULL;
|
const SArray* container = &topic_list->container;
|
||||||
SArray* container = &topic_list->container;
|
int32_t sz = taosArrayGetSize(container);
|
||||||
int32_t sz = taosArrayGetSize(container);
|
void* buf = NULL;
|
||||||
// destroy ex
|
SCMSubscribeReq req = {0};
|
||||||
taosArrayDestroy(tmq->clientTopics);
|
int32_t code = -1;
|
||||||
tmq->clientTopics = taosArrayInit(sz, sizeof(SMqClientTopic));
|
|
||||||
|
|
||||||
SCMSubscribeReq req;
|
|
||||||
req.topicNum = sz;
|
|
||||||
req.consumerId = tmq->consumerId;
|
req.consumerId = tmq->consumerId;
|
||||||
strcpy(req.cgroup, tmq->groupId);
|
tstrncpy(req.cgroup, tmq->groupId, TSDB_CGROUP_LEN);
|
||||||
req.topicNames = taosArrayInit(sz, sizeof(void*));
|
req.topicNames = taosArrayInit(sz, sizeof(void*));
|
||||||
|
if (req.topicNames == NULL) goto FAIL;
|
||||||
|
|
||||||
for (int i = 0; i < sz; i++) {
|
for (int32_t i = 0; i < sz; i++) {
|
||||||
/*char* topicName = topic_list->elems[i];*/
|
char* topic = taosArrayGetP(container, i);
|
||||||
char* topicName = taosArrayGetP(container, i);
|
|
||||||
|
|
||||||
SName name = {0};
|
SName name = {0};
|
||||||
char* dbName = getDbOfConnection(tmq->pTscObj);
|
tNameSetDbName(&name, tmq->pTscObj->acctId, topic, strlen(topic));
|
||||||
if (dbName == NULL) {
|
|
||||||
return TMQ_RESP_ERR__FAIL;
|
|
||||||
}
|
|
||||||
tNameSetDbName(&name, tmq->pTscObj->acctId, dbName, strlen(dbName));
|
|
||||||
tNameFromString(&name, topicName, T_NAME_TABLE);
|
|
||||||
|
|
||||||
char* topicFname = taosMemoryCalloc(1, TSDB_TOPIC_FNAME_LEN);
|
char* topicFName = taosMemoryCalloc(1, TSDB_TOPIC_FNAME_LEN);
|
||||||
if (topicFname == NULL) {
|
if (topicFName == NULL) {
|
||||||
goto _return;
|
goto FAIL;
|
||||||
}
|
}
|
||||||
tNameExtractFullName(&name, topicFname);
|
tNameExtractFullName(&name, topicFName);
|
||||||
tscDebug("subscribe topic: %s", topicFname);
|
|
||||||
SMqClientTopic topic = {
|
tscDebug("subscribe topic: %s", topicFName);
|
||||||
.sql = NULL,
|
|
||||||
.sqlLen = 0,
|
taosArrayPush(req.topicNames, &topicFName);
|
||||||
.topicId = 0,
|
|
||||||
.topicName = topicFname,
|
|
||||||
.vgs = NULL,
|
|
||||||
};
|
|
||||||
topic.vgs = taosArrayInit(0, sizeof(SMqClientVg));
|
|
||||||
taosArrayPush(tmq->clientTopics, &topic);
|
|
||||||
taosArrayPush(req.topicNames, &topicFname);
|
|
||||||
taosMemoryFree(dbName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int tlen = tSerializeSCMSubscribeReq(NULL, &req);
|
int32_t tlen = tSerializeSCMSubscribeReq(NULL, &req);
|
||||||
void* buf = taosMemoryMalloc(tlen);
|
buf = taosMemoryMalloc(tlen);
|
||||||
if (buf == NULL) {
|
if (buf == NULL) goto FAIL;
|
||||||
goto _return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* abuf = buf;
|
void* abuf = buf;
|
||||||
tSerializeSCMSubscribeReq(&abuf, &req);
|
tSerializeSCMSubscribeReq(&abuf, &req);
|
||||||
/*printf("formatted: %s\n", dagStr);*/
|
|
||||||
|
|
||||||
pRequest = createRequest(tmq->pTscObj, NULL, NULL, TDMT_MND_SUBSCRIBE);
|
SMsgSendInfo* sendInfo = taosMemoryMalloc(sizeof(SMsgSendInfo));
|
||||||
if (pRequest == NULL) {
|
if (sendInfo == NULL) goto FAIL;
|
||||||
tscError("failed to malloc request");
|
|
||||||
}
|
|
||||||
|
|
||||||
SMqSubscribeCbParam param = {
|
SMqSubscribeCbParam param = {
|
||||||
.rspErr = TMQ_RESP_ERR__SUCCESS,
|
.rspErr = TMQ_RESP_ERR__SUCCESS,
|
||||||
.tmq = tmq,
|
.tmq = tmq,
|
||||||
};
|
};
|
||||||
tsem_init(¶m.rspSem, 0, 0);
|
|
||||||
|
|
||||||
pRequest->body.requestMsg = (SDataBuf){
|
if (tsem_init(¶m.rspSem, 0, 0) != 0) goto FAIL;
|
||||||
|
|
||||||
|
sendInfo->msgInfo = (SDataBuf){
|
||||||
.pData = buf,
|
.pData = buf,
|
||||||
.len = tlen,
|
.len = tlen,
|
||||||
.handle = NULL,
|
.handle = NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
SMsgSendInfo* sendInfo = buildMsgInfoImpl(pRequest);
|
sendInfo->requestId = generateRequestId();
|
||||||
|
sendInfo->requestObjRefId = 0;
|
||||||
sendInfo->param = ¶m;
|
sendInfo->param = ¶m;
|
||||||
sendInfo->fp = tmqSubscribeCb;
|
sendInfo->fp = tmqSubscribeCb;
|
||||||
|
sendInfo->msgType = TDMT_MND_SUBSCRIBE;
|
||||||
|
|
||||||
SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp);
|
SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp);
|
||||||
|
|
||||||
int64_t transporterId = 0;
|
int64_t transporterId = 0;
|
||||||
|
@ -583,15 +658,36 @@ tmq_resp_err_t tmq_subscribe(tmq_t* tmq, tmq_list_t* topic_list) {
|
||||||
tsem_wait(¶m.rspSem);
|
tsem_wait(¶m.rspSem);
|
||||||
tsem_destroy(¶m.rspSem);
|
tsem_destroy(¶m.rspSem);
|
||||||
|
|
||||||
_return:
|
code = param.rspErr;
|
||||||
/*if (sendInfo != NULL) {*/
|
if (code != 0) goto FAIL;
|
||||||
/*destroySendMsgInfo(sendInfo);*/
|
|
||||||
/*}*/
|
|
||||||
|
|
||||||
return param.rspErr;
|
// TODO: add max retry cnt
|
||||||
|
while (TSDB_CODE_MND_CONSUMER_NOT_READY == tmqAskEp(tmq, true)) {
|
||||||
|
tscDebug("not ready, retry\n");
|
||||||
|
taosMsleep(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
// init hb timer
|
||||||
|
tmq->hbTimer = taosTmrStart(tmqAssignDelayedHbTask, 1000, tmq, tmqMgmt.timer);
|
||||||
|
|
||||||
|
// init auto commit timer
|
||||||
|
if (tmq->autoCommit) {
|
||||||
|
tmq->commitTimer = taosTmrStart(tmqAssignDelayedCommitTask, tmq->autoCommitInterval, tmq, tmqMgmt.timer);
|
||||||
|
}
|
||||||
|
|
||||||
|
code = 0;
|
||||||
|
FAIL:
|
||||||
|
if (req.topicNames != NULL) taosArrayDestroyP(req.topicNames, taosMemoryFree);
|
||||||
|
if (code != 0) {
|
||||||
|
taosMemoryFree(buf);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tmq_conf_set_offset_commit_cb(tmq_conf_t* conf, tmq_commit_cb* cb) { conf->commit_cb = cb; }
|
void tmq_conf_set_offset_commit_cb(tmq_conf_t* conf, tmq_commit_cb* cb) {
|
||||||
|
//
|
||||||
|
conf->commit_cb = cb;
|
||||||
|
}
|
||||||
|
|
||||||
TAOS_RES* tmq_create_stream(TAOS* taos, const char* streamName, const char* tbName, const char* sql) {
|
TAOS_RES* tmq_create_stream(TAOS* taos, const char* streamName, const char* tbName, const char* sql) {
|
||||||
STscObj* pTscObj = (STscObj*)taos;
|
STscObj* pTscObj = (STscObj*)taos;
|
||||||
|
@ -625,9 +721,6 @@ TAOS_RES* tmq_create_stream(TAOS* taos, const char* streamName, const char* tbNa
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return);
|
CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return);
|
||||||
CHECK_CODE_GOTO(parseSql(pRequest, false, &pQueryNode, NULL), _return);
|
CHECK_CODE_GOTO(parseSql(pRequest, false, &pQueryNode, NULL), _return);
|
||||||
|
|
||||||
// todo check for invalid sql statement and return with error code
|
|
||||||
|
|
||||||
CHECK_CODE_GOTO(nodesNodeToString(pQueryNode->pRoot, false, &astStr, NULL), _return);
|
CHECK_CODE_GOTO(nodesNodeToString(pQueryNode->pRoot, false, &astStr, NULL), _return);
|
||||||
|
|
||||||
/*printf("%s\n", pStr);*/
|
/*printf("%s\n", pStr);*/
|
||||||
|
@ -651,7 +744,6 @@ TAOS_RES* tmq_create_stream(TAOS* taos, const char* streamName, const char* tbNa
|
||||||
}
|
}
|
||||||
|
|
||||||
tSerializeSCMCreateStreamReq(buf, tlen, &req);
|
tSerializeSCMCreateStreamReq(buf, tlen, &req);
|
||||||
/*printf("formatted: %s\n", dagStr);*/
|
|
||||||
|
|
||||||
pRequest->body.requestMsg = (SDataBuf){
|
pRequest->body.requestMsg = (SDataBuf){
|
||||||
.pData = buf,
|
.pData = buf,
|
||||||
|
@ -682,94 +774,6 @@ _return:
|
||||||
return pRequest;
|
return pRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, int sqlLen) {
|
|
||||||
STscObj* pTscObj = (STscObj*)taos;
|
|
||||||
SRequestObj* pRequest = NULL;
|
|
||||||
SQuery* pQueryNode = NULL;
|
|
||||||
char* astStr = NULL;
|
|
||||||
|
|
||||||
terrno = TSDB_CODE_SUCCESS;
|
|
||||||
if (taos == NULL || topicName == NULL || sql == NULL) {
|
|
||||||
tscError("invalid parameters for creating topic, connObj:%p, topic name:%s, sql:%s", taos, topicName, sql);
|
|
||||||
terrno = TSDB_CODE_TSC_INVALID_INPUT;
|
|
||||||
goto _return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strlen(topicName) >= TSDB_TOPIC_NAME_LEN) {
|
|
||||||
tscError("topic name too long, max length:%d", TSDB_TOPIC_NAME_LEN - 1);
|
|
||||||
terrno = TSDB_CODE_TSC_INVALID_INPUT;
|
|
||||||
goto _return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sqlLen > TSDB_MAX_ALLOWED_SQL_LEN) {
|
|
||||||
tscError("sql string exceeds max length:%d", TSDB_MAX_ALLOWED_SQL_LEN);
|
|
||||||
terrno = TSDB_CODE_TSC_EXCEED_SQL_LIMIT;
|
|
||||||
goto _return;
|
|
||||||
}
|
|
||||||
|
|
||||||
tscDebug("start to create topic: %s", topicName);
|
|
||||||
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
|
||||||
CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return);
|
|
||||||
CHECK_CODE_GOTO(parseSql(pRequest, true, &pQueryNode), _return);
|
|
||||||
|
|
||||||
// todo check for invalid sql statement and return with error code
|
|
||||||
|
|
||||||
CHECK_CODE_GOTO(nodesNodeToString(pQueryNode->pRoot, false, &astStr, NULL), _return);
|
|
||||||
|
|
||||||
/*printf("%s\n", pStr);*/
|
|
||||||
|
|
||||||
SName name = {.acctId = pTscObj->acctId, .type = TSDB_TABLE_NAME_T};
|
|
||||||
strcpy(name.dbname, pRequest->pDb);
|
|
||||||
strcpy(name.tname, topicName);
|
|
||||||
|
|
||||||
SCMCreateTopicReq req = {
|
|
||||||
.igExists = 1,
|
|
||||||
.ast = astStr,
|
|
||||||
.sql = (char*)sql,
|
|
||||||
};
|
|
||||||
tNameExtractFullName(&name, req.name);
|
|
||||||
|
|
||||||
int tlen = tSerializeSCMCreateTopicReq(NULL, 0, &req);
|
|
||||||
void* buf = taosMemoryMalloc(tlen);
|
|
||||||
if (buf == NULL) {
|
|
||||||
goto _return;
|
|
||||||
}
|
|
||||||
|
|
||||||
tSerializeSCMCreateTopicReq(buf, tlen, &req);
|
|
||||||
/*printf("formatted: %s\n", dagStr);*/
|
|
||||||
|
|
||||||
pRequest->body.requestMsg = (SDataBuf){
|
|
||||||
.pData = buf,
|
|
||||||
.len = tlen,
|
|
||||||
.handle = NULL,
|
|
||||||
};
|
|
||||||
pRequest->type = TDMT_MND_CREATE_TOPIC;
|
|
||||||
|
|
||||||
SMsgSendInfo* sendInfo = buildMsgInfoImpl(pRequest);
|
|
||||||
SEpSet epSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp);
|
|
||||||
|
|
||||||
int64_t transporterId = 0;
|
|
||||||
asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo);
|
|
||||||
|
|
||||||
tsem_wait(&pRequest->body.rspSem);
|
|
||||||
|
|
||||||
_return:
|
|
||||||
taosMemoryFreeClear(astStr);
|
|
||||||
qDestroyQuery(pQueryNode);
|
|
||||||
/*if (sendInfo != NULL) {*/
|
|
||||||
/*destroySendMsgInfo(sendInfo);*/
|
|
||||||
/*}*/
|
|
||||||
|
|
||||||
if (pRequest != NULL && terrno != TSDB_CODE_SUCCESS) {
|
|
||||||
pRequest->code = terrno;
|
|
||||||
}
|
|
||||||
|
|
||||||
return pRequest;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
int32_t tmqGetSkipLogNum(tmq_message_t* tmq_message) {
|
int32_t tmqGetSkipLogNum(tmq_message_t* tmq_message) {
|
||||||
if (tmq_message == NULL) return 0;
|
if (tmq_message == NULL) return 0;
|
||||||
|
@ -952,7 +956,7 @@ int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
/*printf("rsp epoch %ld sz %ld\n", rsp.epoch, rsp.topics->size);*/
|
/*printf("rsp epoch %ld sz %ld\n", rsp.epoch, rsp.topics->size);*/
|
||||||
/*printf("tmq epoch %ld sz %ld\n", tmq->epoch, tmq->clientTopics->size);*/
|
/*printf("tmq epoch %ld sz %ld\n", tmq->epoch, tmq->clientTopics->size);*/
|
||||||
if (tmqUpdateEp(tmq, head->epoch, &rsp)) {
|
if (tmqUpdateEp(tmq, head->epoch, &rsp)) {
|
||||||
atomic_store_64(&tmq->status, TMQ_CONSUMER_STATUS__READY);
|
atomic_store_8(&tmq->status, TMQ_CONSUMER_STATUS__READY);
|
||||||
}
|
}
|
||||||
tDeleteSMqCMGetSubEpRsp(&rsp);
|
tDeleteSMqCMGetSubEpRsp(&rsp);
|
||||||
} else {
|
} else {
|
||||||
|
@ -973,7 +977,7 @@ int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
}
|
}
|
||||||
|
|
||||||
END:
|
END:
|
||||||
atomic_store_8(&tmq->epStatus, 0);
|
/*atomic_store_8(&tmq->epStatus, 0);*/
|
||||||
if (pParam->sync) {
|
if (pParam->sync) {
|
||||||
tsem_post(&pParam->rspSem);
|
tsem_post(&pParam->rspSem);
|
||||||
}
|
}
|
||||||
|
@ -982,6 +986,7 @@ END:
|
||||||
|
|
||||||
int32_t tmqAskEp(tmq_t* tmq, bool sync) {
|
int32_t tmqAskEp(tmq_t* tmq, bool sync) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
#if 0
|
||||||
int8_t epStatus = atomic_val_compare_exchange_8(&tmq->epStatus, 0, 1);
|
int8_t epStatus = atomic_val_compare_exchange_8(&tmq->epStatus, 0, 1);
|
||||||
if (epStatus == 1) {
|
if (epStatus == 1) {
|
||||||
int32_t epSkipCnt = atomic_add_fetch_32(&tmq->epSkipCnt, 1);
|
int32_t epSkipCnt = atomic_add_fetch_32(&tmq->epSkipCnt, 1);
|
||||||
|
@ -989,11 +994,12 @@ int32_t tmqAskEp(tmq_t* tmq, bool sync) {
|
||||||
if (epSkipCnt < 5000) return 0;
|
if (epSkipCnt < 5000) return 0;
|
||||||
}
|
}
|
||||||
atomic_store_32(&tmq->epSkipCnt, 0);
|
atomic_store_32(&tmq->epSkipCnt, 0);
|
||||||
|
#endif
|
||||||
int32_t tlen = sizeof(SMqCMGetSubEpReq);
|
int32_t tlen = sizeof(SMqCMGetSubEpReq);
|
||||||
SMqCMGetSubEpReq* req = taosMemoryMalloc(tlen);
|
SMqCMGetSubEpReq* req = taosMemoryMalloc(tlen);
|
||||||
if (req == NULL) {
|
if (req == NULL) {
|
||||||
tscError("failed to malloc get subscribe ep buf");
|
tscError("failed to malloc get subscribe ep buf");
|
||||||
atomic_store_8(&tmq->epStatus, 0);
|
/*atomic_store_8(&tmq->epStatus, 0);*/
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
req->consumerId = htobe64(tmq->consumerId);
|
req->consumerId = htobe64(tmq->consumerId);
|
||||||
|
@ -1004,7 +1010,7 @@ int32_t tmqAskEp(tmq_t* tmq, bool sync) {
|
||||||
if (pParam == NULL) {
|
if (pParam == NULL) {
|
||||||
tscError("failed to malloc subscribe param");
|
tscError("failed to malloc subscribe param");
|
||||||
taosMemoryFree(req);
|
taosMemoryFree(req);
|
||||||
atomic_store_8(&tmq->epStatus, 0);
|
/*atomic_store_8(&tmq->epStatus, 0);*/
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
pParam->tmq = tmq;
|
pParam->tmq = tmq;
|
||||||
|
@ -1016,7 +1022,7 @@ int32_t tmqAskEp(tmq_t* tmq, bool sync) {
|
||||||
tsem_destroy(&pParam->rspSem);
|
tsem_destroy(&pParam->rspSem);
|
||||||
taosMemoryFree(pParam);
|
taosMemoryFree(pParam);
|
||||||
taosMemoryFree(req);
|
taosMemoryFree(req);
|
||||||
atomic_store_8(&tmq->epStatus, 0);
|
/*atomic_store_8(&tmq->epStatus, 0);*/
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1116,7 +1122,9 @@ SMqRspObj* tmqBuildRspFromWrapper(SMqPollRspWrapper* pWrapper) {
|
||||||
|
|
||||||
pRspObj->resInfo.totalRows = 0;
|
pRspObj->resInfo.totalRows = 0;
|
||||||
pRspObj->resInfo.precision = TSDB_TIME_PRECISION_MILLI;
|
pRspObj->resInfo.precision = TSDB_TIME_PRECISION_MILLI;
|
||||||
setResSchemaInfo(&pRspObj->resInfo, pWrapper->topicHandle->schema.pSchema, pWrapper->topicHandle->schema.nCols);
|
if (!pWrapper->msg.withSchema) {
|
||||||
|
setResSchemaInfo(&pRspObj->resInfo, pWrapper->topicHandle->schema.pSchema, pWrapper->topicHandle->schema.nCols);
|
||||||
|
}
|
||||||
|
|
||||||
taosFreeQitem(pWrapper);
|
taosFreeQitem(pWrapper);
|
||||||
return pRspObj;
|
return pRspObj;
|
||||||
|
@ -1185,7 +1193,6 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) {
|
||||||
|
|
||||||
int64_t transporterId = 0;
|
int64_t transporterId = 0;
|
||||||
/*printf("send poll\n");*/
|
/*printf("send poll\n");*/
|
||||||
/*atomic_add_fetch_32(&tmq->waitingRequest, 1);*/
|
|
||||||
tscDebug("consumer %ld send poll to %s : vg %d, epoch %d, req offset %ld, reqId %lu", tmq->consumerId,
|
tscDebug("consumer %ld send poll to %s : vg %d, epoch %d, req offset %ld, reqId %lu", tmq->consumerId,
|
||||||
pTopic->topicName, pVg->vgId, tmq->epoch, pVg->currentOffset, pReq->reqId);
|
pTopic->topicName, pVg->vgId, tmq->epoch, pVg->currentOffset, pReq->reqId);
|
||||||
/*printf("send vg %d %ld\n", pVg->vgId, pVg->currentOffset);*/
|
/*printf("send vg %d %ld\n", pVg->vgId, pVg->currentOffset);*/
|
||||||
|
@ -1264,12 +1271,14 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) {
|
||||||
SMqRspObj* rspObj;
|
SMqRspObj* rspObj;
|
||||||
int64_t startTime = taosGetTimestampMs();
|
int64_t startTime = taosGetTimestampMs();
|
||||||
|
|
||||||
// TODO: put into another thread or delayed queue
|
// TODO: put into delayed queue
|
||||||
int64_t status = atomic_load_64(&tmq->status);
|
#if 0
|
||||||
while (0 != tmqAskEp(tmq, status == TMQ_CONSUMER_STATUS__INIT)) {
|
int8_t status = atomic_load_8(&tmq->status);
|
||||||
|
while (0 != tmqAskEp(tmq, status != TMQ_CONSUMER_STATUS__READY)) {
|
||||||
tscDebug("not ready, retry\n");
|
tscDebug("not ready, retry\n");
|
||||||
taosSsleep(1);
|
taosSsleep(1);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
rspObj = tmqHandleAllRsp(tmq, blocking_time, false);
|
rspObj = tmqHandleAllRsp(tmq, blocking_time, false);
|
||||||
if (rspObj) {
|
if (rspObj) {
|
||||||
|
@ -1277,8 +1286,7 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) {
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
/*printf("cycle\n");*/
|
tmqHandleAllDelayedTask(tmq);
|
||||||
tmqAskEp(tmq, false);
|
|
||||||
tmqPollImpl(tmq, blocking_time);
|
tmqPollImpl(tmq, blocking_time);
|
||||||
|
|
||||||
/*tsem_wait(&tmq->rspSem);*/
|
/*tsem_wait(&tmq->rspSem);*/
|
||||||
|
|
|
@ -79,7 +79,11 @@ int32_t colDataGetLength(const SColumnInfoData* pColumnInfoData, int32_t numOfRo
|
||||||
if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) {
|
if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) {
|
||||||
return pColumnInfoData->varmeta.length;
|
return pColumnInfoData->varmeta.length;
|
||||||
} else {
|
} else {
|
||||||
return pColumnInfoData->info.bytes * numOfRows;
|
if (pColumnInfoData->info.type == TSDB_DATA_TYPE_NULL) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return pColumnInfoData->info.bytes * numOfRows;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -644,12 +648,12 @@ size_t blockDataGetRowSize(SSDataBlock* pBlock) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @refitem blockDataToBuf for the meta size
|
* @refitem blockDataToBuf for the meta size
|
||||||
*
|
|
||||||
* @param pBlock
|
* @param pBlock
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
size_t blockDataGetSerialMetaSize(const SSDataBlock* pBlock) {
|
size_t blockDataGetSerialMetaSize(const SSDataBlock* pBlock) {
|
||||||
return sizeof(int32_t) + pBlock->info.numOfCols * sizeof(int32_t);
|
// | total rows/total length | block group id | each column length |
|
||||||
|
return sizeof(int32_t) + sizeof(uint64_t) + pBlock->info.numOfCols * sizeof(int32_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
double blockDataGetSerialRowSize(const SSDataBlock* pBlock) {
|
double blockDataGetSerialRowSize(const SSDataBlock* pBlock) {
|
||||||
|
@ -1219,7 +1223,6 @@ void colDataDestroy(SColumnInfoData* pColData) {
|
||||||
taosMemoryFree(pColData->pData);
|
taosMemoryFree(pColData->pData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void doShiftBitmap(char* nullBitmap, size_t n, size_t total) {
|
static void doShiftBitmap(char* nullBitmap, size_t n, size_t total) {
|
||||||
int32_t len = BitmapLen(total);
|
int32_t len = BitmapLen(total);
|
||||||
|
|
||||||
|
|
|
@ -220,7 +220,7 @@ struct SConfig *taosGetCfg() {
|
||||||
return tsCfg;
|
return tsCfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *envFile, const char *apolloUrl) {
|
static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *inputCfgDir, const char *envFile, char *apolloUrl) {
|
||||||
char cfgDir[PATH_MAX] = {0};
|
char cfgDir[PATH_MAX] = {0};
|
||||||
char cfgFile[PATH_MAX + 100] = {0};
|
char cfgFile[PATH_MAX + 100] = {0};
|
||||||
|
|
||||||
|
@ -231,6 +231,8 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e
|
||||||
tstrncpy(cfgFile, cfgDir, sizeof(cfgDir));
|
tstrncpy(cfgFile, cfgDir, sizeof(cfgDir));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (apolloUrl == NULL || apolloUrl[0] == '\0') cfgGetApollUrl(envCmd, envFile, apolloUrl);
|
||||||
|
|
||||||
if (cfgLoad(pCfg, CFG_STYPE_APOLLO_URL, apolloUrl) != 0) {
|
if (cfgLoad(pCfg, CFG_STYPE_APOLLO_URL, apolloUrl) != 0) {
|
||||||
uError("failed to load from apollo url:%s since %s", apolloUrl, terrstr());
|
uError("failed to load from apollo url:%s since %s", apolloUrl, terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -251,6 +253,11 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cfgLoad(pCfg, CFG_STYPE_ENV_CMD, envCmd) != 0) {
|
||||||
|
uError("failed to load from cmd env variables since %s", terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,8 +332,8 @@ static int32_t taosAddSystemCfg(SConfig *pCfg) {
|
||||||
if (cfgAddFloat(pCfg, "numOfCores", tsNumOfCores, 0, 100000, 1) != 0) return -1;
|
if (cfgAddFloat(pCfg, "numOfCores", tsNumOfCores, 0, 100000, 1) != 0) return -1;
|
||||||
if (cfgAddInt64(pCfg, "openMax", tsOpenMax, 0, INT64_MAX, 1) != 0) return -1;
|
if (cfgAddInt64(pCfg, "openMax", tsOpenMax, 0, INT64_MAX, 1) != 0) return -1;
|
||||||
if (cfgAddInt64(pCfg, "streamMax", tsStreamMax, 0, INT64_MAX, 1) != 0) return -1;
|
if (cfgAddInt64(pCfg, "streamMax", tsStreamMax, 0, INT64_MAX, 1) != 0) return -1;
|
||||||
if (cfgAddInt32(pCfg, "pageSize(KB)", tsPageSizeKB, 0, INT64_MAX, 1) != 0) return -1;
|
if (cfgAddInt32(pCfg, "pageSizeKB", tsPageSizeKB, 0, INT64_MAX, 1) != 0) return -1;
|
||||||
if (cfgAddInt64(pCfg, "totalMemory(KB)", tsTotalMemoryKB, 0, INT64_MAX, 1) != 0) return -1;
|
if (cfgAddInt64(pCfg, "totalMemoryKB", tsTotalMemoryKB, 0, INT64_MAX, 1) != 0) return -1;
|
||||||
if (cfgAddString(pCfg, "os sysname", info.sysname, 1) != 0) return -1;
|
if (cfgAddString(pCfg, "os sysname", info.sysname, 1) != 0) return -1;
|
||||||
if (cfgAddString(pCfg, "os nodename", info.nodename, 1) != 0) return -1;
|
if (cfgAddString(pCfg, "os nodename", info.nodename, 1) != 0) return -1;
|
||||||
if (cfgAddString(pCfg, "os release", info.release, 1) != 0) return -1;
|
if (cfgAddString(pCfg, "os release", info.release, 1) != 0) return -1;
|
||||||
|
@ -572,8 +579,8 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile,
|
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char **envCmd, const char *envFile,
|
||||||
const char *apolloUrl, SArray *pArgs, bool tsc) {
|
char *apolloUrl, SArray *pArgs, bool tsc) {
|
||||||
osDefaultInit();
|
osDefaultInit();
|
||||||
|
|
||||||
SConfig *pCfg = cfgInit();
|
SConfig *pCfg = cfgInit();
|
||||||
|
@ -588,7 +595,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
|
||||||
if (taosAddServerLogCfg(pCfg) != 0) return -1;
|
if (taosAddServerLogCfg(pCfg) != 0) return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosLoadCfg(pCfg, cfgDir, envFile, apolloUrl) != 0) {
|
if (taosLoadCfg(pCfg, envCmd, cfgDir, envFile, apolloUrl) != 0) {
|
||||||
uError("failed to load cfg since %s", terrstr());
|
uError("failed to load cfg since %s", terrstr());
|
||||||
cfgCleanup(pCfg);
|
cfgCleanup(pCfg);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -625,7 +632,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, SArray *pArgs, bool tsc) {
|
int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc) {
|
||||||
if (tsCfg != NULL) return 0;
|
if (tsCfg != NULL) return 0;
|
||||||
tsCfg = cfgInit();
|
tsCfg = cfgInit();
|
||||||
|
|
||||||
|
@ -640,7 +647,7 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU
|
||||||
}
|
}
|
||||||
taosAddSystemCfg(tsCfg);
|
taosAddSystemCfg(tsCfg);
|
||||||
|
|
||||||
if (taosLoadCfg(tsCfg, cfgDir, envFile, apolloUrl) != 0) {
|
if (taosLoadCfg(tsCfg, envCmd, cfgDir, envFile, apolloUrl) != 0) {
|
||||||
uError("failed to load cfg since %s", terrstr());
|
uError("failed to load cfg since %s", terrstr());
|
||||||
cfgCleanup(tsCfg);
|
cfgCleanup(tsCfg);
|
||||||
tsCfg = NULL;
|
tsCfg = NULL;
|
||||||
|
|
|
@ -94,6 +94,86 @@ STSRow *tGetSubmitBlkNext(SSubmitBlkIter *pIter) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: KEEP one suite of iterator API finally.
|
||||||
|
// 1) use tInitSubmitMsgIterEx firstly as not decrease the merge conflicts
|
||||||
|
// 2) replace tInitSubmitMsgIterEx with tInitSubmitMsgIter later
|
||||||
|
// 3) finally, rename tInitSubmitMsgIterEx to tInitSubmitMsgIter
|
||||||
|
|
||||||
|
int32_t tInitSubmitMsgIterEx(const SSubmitReq *pMsg, SSubmitMsgIter *pIter) {
|
||||||
|
if (pMsg == NULL) {
|
||||||
|
terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pIter->totalLen = htonl(pMsg->length);
|
||||||
|
ASSERT(pIter->totalLen > 0);
|
||||||
|
pIter->len = 0;
|
||||||
|
pIter->pMsg = pMsg;
|
||||||
|
if (pIter->totalLen <= sizeof(SSubmitReq)) {
|
||||||
|
terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tGetSubmitMsgNextEx(SSubmitMsgIter *pIter, SSubmitBlk **pPBlock) {
|
||||||
|
ASSERT(pIter->len >= 0);
|
||||||
|
|
||||||
|
if (pIter->len == 0) {
|
||||||
|
pIter->len += sizeof(SSubmitReq);
|
||||||
|
} else {
|
||||||
|
if (pIter->len >= pIter->totalLen) {
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
SSubmitBlk *pSubmitBlk = (SSubmitBlk *)POINTER_SHIFT(pIter->pMsg, pIter->len);
|
||||||
|
pIter->len += (sizeof(SSubmitBlk) + pIter->dataLen + pIter->schemaLen);
|
||||||
|
ASSERT(pIter->len > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pIter->len > pIter->totalLen) {
|
||||||
|
terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP;
|
||||||
|
*pPBlock = NULL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pIter->len == pIter->totalLen) {
|
||||||
|
*pPBlock = NULL;
|
||||||
|
} else {
|
||||||
|
*pPBlock = (SSubmitBlk *)POINTER_SHIFT(pIter->pMsg, pIter->len);
|
||||||
|
pIter->uid = htobe64((*pPBlock)->uid);
|
||||||
|
pIter->suid = htobe64((*pPBlock)->suid);
|
||||||
|
pIter->sversion = htonl((*pPBlock)->sversion);
|
||||||
|
pIter->dataLen = htonl((*pPBlock)->dataLen);
|
||||||
|
pIter->schemaLen = htonl((*pPBlock)->schemaLen);
|
||||||
|
pIter->numOfRows = htons((*pPBlock)->numOfRows);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tInitSubmitBlkIterEx(SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlock, SSubmitBlkIter *pIter) {
|
||||||
|
if (pMsgIter->dataLen <= 0) return -1;
|
||||||
|
pIter->totalLen = pMsgIter->dataLen;
|
||||||
|
pIter->len = 0;
|
||||||
|
pIter->row = (STSRow *)(pBlock->data + pMsgIter->schemaLen);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
STSRow *tGetSubmitBlkNextEx(SSubmitBlkIter *pIter) {
|
||||||
|
STSRow *row = pIter->row;
|
||||||
|
|
||||||
|
if (pIter->len >= pIter->totalLen) {
|
||||||
|
return NULL;
|
||||||
|
} else {
|
||||||
|
pIter->len += TD_ROW_LEN(row);
|
||||||
|
if (pIter->len < pIter->totalLen) {
|
||||||
|
pIter->row = POINTER_SHIFT(row, TD_ROW_LEN(row));
|
||||||
|
}
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int32_t tEncodeSEpSet(SCoder *pEncoder, const SEpSet *pEp) {
|
int32_t tEncodeSEpSet(SCoder *pEncoder, const SEpSet *pEp) {
|
||||||
if (tEncodeI8(pEncoder, pEp->inUse) < 0) return -1;
|
if (tEncodeI8(pEncoder, pEp->inUse) < 0) return -1;
|
||||||
if (tEncodeI8(pEncoder, pEp->numOfEps) < 0) return -1;
|
if (tEncodeI8(pEncoder, pEp->numOfEps) < 0) return -1;
|
||||||
|
@ -126,7 +206,6 @@ int32_t tDecodeSQueryNodeAddr(SCoder *pDecoder, SQueryNodeAddr *pAddr) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t taosEncodeSEpSet(void **buf, const SEpSet *pEp) {
|
int32_t taosEncodeSEpSet(void **buf, const SEpSet *pEp) {
|
||||||
int32_t tlen = 0;
|
int32_t tlen = 0;
|
||||||
tlen += taosEncodeFixedI8(buf, pEp->inUse);
|
tlen += taosEncodeFixedI8(buf, pEp->inUse);
|
||||||
|
@ -443,10 +522,6 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) {
|
||||||
SRSmaParam *param = pReq->stbCfg.pRSmaParam;
|
SRSmaParam *param = pReq->stbCfg.pRSmaParam;
|
||||||
tlen += taosEncodeBinary(buf, (const void *)¶m->xFilesFactor, sizeof(param->xFilesFactor));
|
tlen += taosEncodeBinary(buf, (const void *)¶m->xFilesFactor, sizeof(param->xFilesFactor));
|
||||||
tlen += taosEncodeFixedI32(buf, param->delay);
|
tlen += taosEncodeFixedI32(buf, param->delay);
|
||||||
tlen += taosEncodeFixedI8(buf, param->nFuncIds);
|
|
||||||
for (int8_t i = 0; i < param->nFuncIds; ++i) {
|
|
||||||
tlen += taosEncodeFixedI32(buf, param->pFuncIds[i]);
|
|
||||||
}
|
|
||||||
tlen += taosEncodeFixedI32(buf, param->qmsg1Len);
|
tlen += taosEncodeFixedI32(buf, param->qmsg1Len);
|
||||||
if (param->qmsg1Len > 0) {
|
if (param->qmsg1Len > 0) {
|
||||||
tlen += taosEncodeString(buf, param->qmsg1);
|
tlen += taosEncodeString(buf, param->qmsg1);
|
||||||
|
@ -476,10 +551,6 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) {
|
||||||
SRSmaParam *param = pReq->ntbCfg.pRSmaParam;
|
SRSmaParam *param = pReq->ntbCfg.pRSmaParam;
|
||||||
tlen += taosEncodeBinary(buf, (const void *)¶m->xFilesFactor, sizeof(param->xFilesFactor));
|
tlen += taosEncodeBinary(buf, (const void *)¶m->xFilesFactor, sizeof(param->xFilesFactor));
|
||||||
tlen += taosEncodeFixedI32(buf, param->delay);
|
tlen += taosEncodeFixedI32(buf, param->delay);
|
||||||
tlen += taosEncodeFixedI8(buf, param->nFuncIds);
|
|
||||||
for (int8_t i = 0; i < param->nFuncIds; ++i) {
|
|
||||||
tlen += taosEncodeFixedI32(buf, param->pFuncIds[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -522,13 +593,6 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) {
|
||||||
SRSmaParam *param = pReq->stbCfg.pRSmaParam;
|
SRSmaParam *param = pReq->stbCfg.pRSmaParam;
|
||||||
buf = taosDecodeBinaryTo(buf, (void *)¶m->xFilesFactor, sizeof(param->xFilesFactor));
|
buf = taosDecodeBinaryTo(buf, (void *)¶m->xFilesFactor, sizeof(param->xFilesFactor));
|
||||||
buf = taosDecodeFixedI32(buf, ¶m->delay);
|
buf = taosDecodeFixedI32(buf, ¶m->delay);
|
||||||
buf = taosDecodeFixedI8(buf, ¶m->nFuncIds);
|
|
||||||
if (param->nFuncIds > 0) {
|
|
||||||
param->pFuncIds = (func_id_t *)taosMemoryCalloc(param->nFuncIds, sizeof(func_id_t));
|
|
||||||
for (int8_t i = 0; i < param->nFuncIds; ++i) {
|
|
||||||
buf = taosDecodeFixedI32(buf, param->pFuncIds + i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
buf = taosDecodeFixedI32(buf, ¶m->qmsg1Len);
|
buf = taosDecodeFixedI32(buf, ¶m->qmsg1Len);
|
||||||
if (param->qmsg1Len > 0) {
|
if (param->qmsg1Len > 0) {
|
||||||
buf = taosDecodeString(buf, ¶m->qmsg1);
|
buf = taosDecodeString(buf, ¶m->qmsg1);
|
||||||
|
@ -562,15 +626,6 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) {
|
||||||
SRSmaParam *param = pReq->ntbCfg.pRSmaParam;
|
SRSmaParam *param = pReq->ntbCfg.pRSmaParam;
|
||||||
buf = taosDecodeBinaryTo(buf, (void *)¶m->xFilesFactor, sizeof(param->xFilesFactor));
|
buf = taosDecodeBinaryTo(buf, (void *)¶m->xFilesFactor, sizeof(param->xFilesFactor));
|
||||||
buf = taosDecodeFixedI32(buf, ¶m->delay);
|
buf = taosDecodeFixedI32(buf, ¶m->delay);
|
||||||
buf = taosDecodeFixedI8(buf, ¶m->nFuncIds);
|
|
||||||
if (param->nFuncIds > 0) {
|
|
||||||
param->pFuncIds = (func_id_t *)taosMemoryMalloc(param->nFuncIds * sizeof(func_id_t));
|
|
||||||
for (int8_t i = 0; i < param->nFuncIds; ++i) {
|
|
||||||
buf = taosDecodeFixedI32(buf, param->pFuncIds + i);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
param->pFuncIds = NULL;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
pReq->ntbCfg.pRSmaParam = NULL;
|
pReq->ntbCfg.pRSmaParam = NULL;
|
||||||
}
|
}
|
||||||
|
@ -633,7 +688,6 @@ int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq
|
||||||
if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
|
if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
|
||||||
if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1;
|
if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1;
|
||||||
if (tEncodeFloat(&encoder, pReq->xFilesFactor) < 0) return -1;
|
if (tEncodeFloat(&encoder, pReq->xFilesFactor) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->aggregationMethod) < 0) return -1;
|
|
||||||
if (tEncodeI32(&encoder, pReq->delay) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->delay) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->ttl) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->ttl) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->numOfColumns) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->numOfColumns) < 0) return -1;
|
||||||
|
@ -688,7 +742,6 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR
|
||||||
if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
|
if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
|
||||||
if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1;
|
if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1;
|
||||||
if (tDecodeFloat(&decoder, &pReq->xFilesFactor) < 0) return -1;
|
if (tDecodeFloat(&decoder, &pReq->xFilesFactor) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->aggregationMethod) < 0) return -1;
|
|
||||||
if (tDecodeI32(&decoder, &pReq->delay) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->delay) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->ttl) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->ttl) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &pReq->numOfColumns) < 0) return -1;
|
if (tDecodeI32(&decoder, &pReq->numOfColumns) < 0) return -1;
|
||||||
|
@ -2084,10 +2137,15 @@ int32_t tDeserializeSQnodeListRsp(void *buf, int32_t bufLen, SQnodeListRsp *pRsp
|
||||||
if (tStartDecode(&decoder) < 0) return -1;
|
if (tStartDecode(&decoder) < 0) return -1;
|
||||||
int32_t num = 0;
|
int32_t num = 0;
|
||||||
if (tDecodeI32(&decoder, &num) < 0) return -1;
|
if (tDecodeI32(&decoder, &num) < 0) return -1;
|
||||||
pRsp->addrsList = taosArrayInit(num, sizeof(SQueryNodeAddr));
|
if (NULL == pRsp->addrsList) {
|
||||||
if (NULL == pRsp->addrsList) return -1;
|
pRsp->addrsList = taosArrayInit(num, sizeof(SQueryNodeAddr));
|
||||||
|
if (NULL == pRsp->addrsList) return -1;
|
||||||
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < num; ++i) {
|
for (int32_t i = 0; i < num; ++i) {
|
||||||
if (tDecodeSQueryNodeAddr(&decoder, TARRAY_GET_ELEM(pRsp->addrsList, i)) < 0) return -1;
|
SQueryNodeAddr addr = {0};
|
||||||
|
if (tDecodeSQueryNodeAddr(&decoder, &addr) < 0) return -1;
|
||||||
|
taosArrayPush(pRsp->addrsList, &addr);
|
||||||
}
|
}
|
||||||
tEndDecode(&decoder);
|
tEndDecode(&decoder);
|
||||||
|
|
||||||
|
@ -2740,11 +2798,11 @@ int32_t tSerializeSCMCreateTopicReq(void *buf, int32_t bufLen, const SCMCreateTo
|
||||||
if (tEncodeI8(&encoder, pReq->withTbName) < 0) return -1;
|
if (tEncodeI8(&encoder, pReq->withTbName) < 0) return -1;
|
||||||
if (tEncodeI8(&encoder, pReq->withSchema) < 0) return -1;
|
if (tEncodeI8(&encoder, pReq->withSchema) < 0) return -1;
|
||||||
if (tEncodeI8(&encoder, pReq->withTag) < 0) return -1;
|
if (tEncodeI8(&encoder, pReq->withTag) < 0) return -1;
|
||||||
|
if (tEncodeCStr(&encoder, pReq->subscribeDbName) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, sqlLen) < 0) return -1;
|
if (tEncodeI32(&encoder, sqlLen) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, astLen) < 0) return -1;
|
if (tEncodeI32(&encoder, astLen) < 0) return -1;
|
||||||
if (sqlLen > 0 && tEncodeCStr(&encoder, pReq->sql) < 0) return -1;
|
if (sqlLen > 0 && tEncodeCStr(&encoder, pReq->sql) < 0) return -1;
|
||||||
if (astLen > 0 && tEncodeCStr(&encoder, pReq->ast) < 0) return -1;
|
if (astLen > 0 && tEncodeCStr(&encoder, pReq->ast) < 0) return -1;
|
||||||
if (0 == astLen && tEncodeCStr(&encoder, pReq->subscribeDbName) < 0) return -1;
|
|
||||||
|
|
||||||
tEndEncode(&encoder);
|
tEndEncode(&encoder);
|
||||||
|
|
||||||
|
@ -2766,6 +2824,7 @@ int32_t tDeserializeSCMCreateTopicReq(void *buf, int32_t bufLen, SCMCreateTopicR
|
||||||
if (tDecodeI8(&decoder, &pReq->withTbName) < 0) return -1;
|
if (tDecodeI8(&decoder, &pReq->withTbName) < 0) return -1;
|
||||||
if (tDecodeI8(&decoder, &pReq->withSchema) < 0) return -1;
|
if (tDecodeI8(&decoder, &pReq->withSchema) < 0) return -1;
|
||||||
if (tDecodeI8(&decoder, &pReq->withTag) < 0) return -1;
|
if (tDecodeI8(&decoder, &pReq->withTag) < 0) return -1;
|
||||||
|
if (tDecodeCStrTo(&decoder, pReq->subscribeDbName) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &sqlLen) < 0) return -1;
|
if (tDecodeI32(&decoder, &sqlLen) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &astLen) < 0) return -1;
|
if (tDecodeI32(&decoder, &astLen) < 0) return -1;
|
||||||
|
|
||||||
|
@ -2780,7 +2839,6 @@ int32_t tDeserializeSCMCreateTopicReq(void *buf, int32_t bufLen, SCMCreateTopicR
|
||||||
if (pReq->ast == NULL) return -1;
|
if (pReq->ast == NULL) return -1;
|
||||||
if (tDecodeCStrTo(&decoder, pReq->ast) < 0) return -1;
|
if (tDecodeCStrTo(&decoder, pReq->ast) < 0) return -1;
|
||||||
} else {
|
} else {
|
||||||
if (tDecodeCStrTo(&decoder, pReq->subscribeDbName) < 0) return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tEndDecode(&decoder);
|
tEndDecode(&decoder);
|
||||||
|
|
|
@ -17,13 +17,24 @@
|
||||||
#include "dmImp.h"
|
#include "dmImp.h"
|
||||||
#include "tconfig.h"
|
#include "tconfig.h"
|
||||||
|
|
||||||
|
#define DM_APOLLO_URL "The apollo string to use when configuring the server, such as: -a 'jsonFile:./tests/cfg.json', cfg.json text can be '{\"fqdn\":\"td1\"}'."
|
||||||
|
#define DM_CFG_DIR "Configuration directory."
|
||||||
|
#define DM_DMP_CFG "Dump configuration."
|
||||||
|
#define DM_ENV_CMD "The env cmd variable string to use when configuring the server, such as: -e 'TAOS_FQDN=td1'."
|
||||||
|
#define DM_ENV_FILE "The env variable file path to use when configuring the server, default is './.env', .env text can be 'TAOS_FQDN=td1'."
|
||||||
|
#define DM_NODE_TYPE "Startup type of the node, default is 0."
|
||||||
|
#define DM_MACHINE_CODE "Get machine code."
|
||||||
|
#define DM_VERSION "Print program version."
|
||||||
|
#define DM_EMAIL "<support@taosdata.com>"
|
||||||
static struct {
|
static struct {
|
||||||
bool dumpConfig;
|
bool dumpConfig;
|
||||||
bool generateGrant;
|
bool generateGrant;
|
||||||
bool printAuth;
|
bool printAuth;
|
||||||
bool printVersion;
|
bool printVersion;
|
||||||
|
bool printHelp;
|
||||||
char envFile[PATH_MAX];
|
char envFile[PATH_MAX];
|
||||||
char apolloUrl[PATH_MAX];
|
char apolloUrl[PATH_MAX];
|
||||||
|
const char **envCmd;
|
||||||
SArray *pArgs; // SConfigPair
|
SArray *pArgs; // SConfigPair
|
||||||
SDnode *pDnode;
|
SDnode *pDnode;
|
||||||
EDndNodeType ntype;
|
EDndNodeType ntype;
|
||||||
|
@ -56,6 +67,10 @@ static void dmSetSignalHandle() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
||||||
|
int32_t cmdEnvIndex = 0;
|
||||||
|
if (argc < 2) return 0;
|
||||||
|
global.envCmd = taosMemoryMalloc(argc-1);
|
||||||
|
memset(global.envCmd, 0, argc-1);
|
||||||
for (int32_t i = 1; i < argc; ++i) {
|
for (int32_t i = 1; i < argc; ++i) {
|
||||||
if (strcmp(argv[i], "-c") == 0) {
|
if (strcmp(argv[i], "-c") == 0) {
|
||||||
if (i < argc - 1) {
|
if (i < argc - 1) {
|
||||||
|
@ -70,7 +85,7 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
||||||
}
|
}
|
||||||
} else if (strcmp(argv[i], "-a") == 0) {
|
} else if (strcmp(argv[i], "-a") == 0) {
|
||||||
tstrncpy(global.apolloUrl, argv[++i], PATH_MAX);
|
tstrncpy(global.apolloUrl, argv[++i], PATH_MAX);
|
||||||
} else if (strcmp(argv[i], "-e") == 0) {
|
} else if (strcmp(argv[i], "-E") == 0) {
|
||||||
tstrncpy(global.envFile, argv[++i], PATH_MAX);
|
tstrncpy(global.envFile, argv[++i], PATH_MAX);
|
||||||
} else if (strcmp(argv[i], "-n") == 0) {
|
} else if (strcmp(argv[i], "-n") == 0) {
|
||||||
global.ntype = atoi(argv[++i]);
|
global.ntype = atoi(argv[++i]);
|
||||||
|
@ -84,6 +99,11 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
||||||
global.dumpConfig = true;
|
global.dumpConfig = true;
|
||||||
} else if (strcmp(argv[i], "-V") == 0) {
|
} else if (strcmp(argv[i], "-V") == 0) {
|
||||||
global.printVersion = true;
|
global.printVersion = true;
|
||||||
|
} else if (strcmp(argv[i], "-e") == 0) {
|
||||||
|
global.envCmd[cmdEnvIndex] = argv[++i];
|
||||||
|
cmdEnvIndex++;
|
||||||
|
} else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "--usage") == 0 || strcmp(argv[i], "-?")) {
|
||||||
|
global.printHelp = true;
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,6 +124,21 @@ static void dmPrintVersion() {
|
||||||
printf("buildInfo: %s\n", buildinfo);
|
printf("buildInfo: %s\n", buildinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void dmPrintHelp() {
|
||||||
|
char indent[] = " ";
|
||||||
|
printf("Usage: taosd [OPTION...] \n\n");
|
||||||
|
printf("%s%s%s%s\n", indent, "-a,", indent, DM_APOLLO_URL);
|
||||||
|
printf("%s%s%s%s\n", indent, "-c,", indent, DM_CFG_DIR);
|
||||||
|
printf("%s%s%s%s\n", indent, "-C,", indent, DM_DMP_CFG);
|
||||||
|
printf("%s%s%s%s\n", indent, "-e,", indent, DM_ENV_CMD);
|
||||||
|
printf("%s%s%s%s\n", indent, "-E,", indent, DM_ENV_FILE);
|
||||||
|
printf("%s%s%s%s\n", indent, "-n,", indent, DM_NODE_TYPE);
|
||||||
|
printf("%s%s%s%s\n", indent, "-k,", indent, DM_MACHINE_CODE);
|
||||||
|
printf("%s%s%s%s\n", indent, "-V,", indent, DM_VERSION);
|
||||||
|
|
||||||
|
printf("\n\nReport bugs to %s.\n", DM_EMAIL);
|
||||||
|
}
|
||||||
|
|
||||||
static void dmDumpCfg() {
|
static void dmDumpCfg() {
|
||||||
SConfig *pCfg = taosGetCfg();
|
SConfig *pCfg = taosGetCfg();
|
||||||
cfgDumpCfg(pCfg, 0, true);
|
cfgDumpCfg(pCfg, 0, true);
|
||||||
|
@ -129,7 +164,7 @@ static SDnodeOpt dmGetOpt() {
|
||||||
static int32_t dmInitLog() {
|
static int32_t dmInitLog() {
|
||||||
char logName[12] = {0};
|
char logName[12] = {0};
|
||||||
snprintf(logName, sizeof(logName), "%slog", dmLogName(global.ntype));
|
snprintf(logName, sizeof(logName), "%slog", dmLogName(global.ntype));
|
||||||
return taosCreateLog(logName, 1, configDir, global.envFile, global.apolloUrl, global.pArgs, 0);
|
return taosCreateLog(logName, 1, configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dmSetProcInfo(int32_t argc, char **argv) {
|
static void dmSetProcInfo(int32_t argc, char **argv) {
|
||||||
|
@ -168,6 +203,10 @@ static int32_t dmRunDnode() {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void taosCleanupArgs() {
|
||||||
|
if (global.envCmd != NULL) taosMemoryFree(global.envCmd);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char const *argv[]) {
|
int main(int argc, char const *argv[]) {
|
||||||
if (!taosCheckSystemIsSmallEnd()) {
|
if (!taosCheckSystemIsSmallEnd()) {
|
||||||
printf("failed to start since on non-small-end machines\n");
|
printf("failed to start since on non-small-end machines\n");
|
||||||
|
@ -176,26 +215,37 @@ int main(int argc, char const *argv[]) {
|
||||||
|
|
||||||
if (dmParseArgs(argc, argv) != 0) {
|
if (dmParseArgs(argc, argv) != 0) {
|
||||||
printf("failed to start since parse args error\n");
|
printf("failed to start since parse args error\n");
|
||||||
|
taosCleanupArgs();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (global.generateGrant) {
|
if (global.generateGrant) {
|
||||||
dmGenerateGrant();
|
dmGenerateGrant();
|
||||||
|
taosCleanupArgs();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (global.printHelp) {
|
||||||
|
dmPrintHelp();
|
||||||
|
taosCleanupArgs();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (global.printVersion) {
|
if (global.printVersion) {
|
||||||
dmPrintVersion();
|
dmPrintVersion();
|
||||||
|
taosCleanupArgs();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dmInitLog() != 0) {
|
if (dmInitLog() != 0) {
|
||||||
dError("failed to start since init log error");
|
printf("failed to start since init log error");
|
||||||
|
taosCleanupArgs();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosInitCfg(configDir, global.envFile, global.apolloUrl, global.pArgs, 0) != 0) {
|
if (taosInitCfg(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0) != 0) {
|
||||||
dError("failed to start since read config error");
|
dError("failed to start since read config error");
|
||||||
|
taosCleanupArgs();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,9 +253,11 @@ int main(int argc, char const *argv[]) {
|
||||||
dmDumpCfg();
|
dmDumpCfg();
|
||||||
taosCleanupCfg();
|
taosCleanupCfg();
|
||||||
taosCloseLog();
|
taosCloseLog();
|
||||||
|
taosCleanupArgs();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
dmSetProcInfo(argc, (char **)argv);
|
dmSetProcInfo(argc, (char **)argv);
|
||||||
|
taosCleanupArgs();
|
||||||
return dmRunDnode();
|
return dmRunDnode();
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,7 +124,7 @@ TdFilePtr dmCheckRunning(const char *dataDir) {
|
||||||
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to lock file:%s since %s", filepath, terrstr());
|
dError("failed to open file:%s since %s", filepath, terrstr());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -173,9 +173,13 @@ static void dmGetServerStatus(SDnode *pDnode, SServerStatusRsp *pStatus) {
|
||||||
|
|
||||||
void dmProcessNettestReq(SDnode *pDnode, SRpcMsg *pRpc) {
|
void dmProcessNettestReq(SDnode *pDnode, SRpcMsg *pRpc) {
|
||||||
dDebug("net test req is received");
|
dDebug("net test req is received");
|
||||||
SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = 0};
|
SRpcMsg rsp = {.handle = pRpc->handle, .refId = pRpc->refId, .ahandle = pRpc->ahandle, .code = 0};
|
||||||
rsp.pCont = rpcMallocCont(pRpc->contLen);
|
rsp.pCont = rpcMallocCont(pRpc->contLen);
|
||||||
rsp.contLen = pRpc->contLen;
|
if (rsp.pCont == NULL) {
|
||||||
|
rsp.code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
} else {
|
||||||
|
rsp.contLen = pRpc->contLen;
|
||||||
|
}
|
||||||
rpcSendResponse(&rsp);
|
rpcSendResponse(&rsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -177,6 +177,7 @@ void mmInitMsgHandle(SMgmtWrapper *pWrapper) {
|
||||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_QNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_QNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_QNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_QNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||||
|
dmSetMsgHandle(pWrapper, TDMT_MND_QNODE_LIST, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_SNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_SNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_SNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_SNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_BNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_BNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||||
|
|
|
@ -202,6 +202,17 @@ int32_t vmProcessCreateVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
code = vnodeStart(pImpl);
|
||||||
|
if (code != 0) {
|
||||||
|
tFreeSCreateVnodeReq(&createReq);
|
||||||
|
dError("vgId:%d, failed to start sync since %s", createReq.vgId, terrstr());
|
||||||
|
vnodeClose(pImpl);
|
||||||
|
vnodeDestroy(path, pMgmt->pTfs);
|
||||||
|
terrno = code;
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
code = vmWriteVnodesToFile(pMgmt);
|
code = vmWriteVnodesToFile(pMgmt);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
tFreeSCreateVnodeReq(&createReq);
|
tFreeSCreateVnodeReq(&createReq);
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "vmInt.h"
|
#include "vmInt.h"
|
||||||
|
#include "libs/function/function.h"
|
||||||
|
|
||||||
SVnodeObj *vmAcquireVnode(SVnodesMgmt *pMgmt, int32_t vgId) {
|
SVnodeObj *vmAcquireVnode(SVnodesMgmt *pMgmt, int32_t vgId) {
|
||||||
SVnodeObj *pVnode = NULL;
|
SVnodeObj *pVnode = NULL;
|
||||||
|
@ -73,12 +74,6 @@ int32_t vmOpenVnode(SVnodesMgmt *pMgmt, SWrapperCfg *pCfg, SVnode *pImpl) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// sync integration
|
|
||||||
vnodeSyncSetQ(pImpl, NULL);
|
|
||||||
vnodeSyncSetRpc(pImpl, NULL);
|
|
||||||
int32_t ret = vnodeSyncStart(pImpl);
|
|
||||||
assert(ret == 0);
|
|
||||||
|
|
||||||
taosWLockLatch(&pMgmt->latch);
|
taosWLockLatch(&pMgmt->latch);
|
||||||
int32_t code = taosHashPut(pMgmt->hash, &pVnode->vgId, sizeof(int32_t), &pVnode, sizeof(SVnodeObj *));
|
int32_t code = taosHashPut(pMgmt->hash, &pVnode->vgId, sizeof(int32_t), &pVnode, sizeof(SVnodeObj *));
|
||||||
taosWUnLockLatch(&pMgmt->latch);
|
taosWUnLockLatch(&pMgmt->latch);
|
||||||
|
@ -152,6 +147,7 @@ static void *vmOpenVnodeFunc(void *param) {
|
||||||
pThread->failed++;
|
pThread->failed++;
|
||||||
} else {
|
} else {
|
||||||
vmOpenVnode(pMgmt, pCfg, pImpl);
|
vmOpenVnode(pMgmt, pCfg, pImpl);
|
||||||
|
//vnodeStart(pImpl);
|
||||||
dDebug("vgId:%d, is opened by thread:%d", pCfg->vgId, pThread->threadIndex);
|
dDebug("vgId:%d, is opened by thread:%d", pCfg->vgId, pThread->threadIndex);
|
||||||
pThread->opened++;
|
pThread->opened++;
|
||||||
}
|
}
|
||||||
|
@ -275,7 +271,7 @@ static void vmCleanup(SMgmtWrapper *pWrapper) {
|
||||||
pWrapper->pMgmt = NULL;
|
pWrapper->pMgmt = NULL;
|
||||||
|
|
||||||
// syncCleanUp();
|
// syncCleanUp();
|
||||||
|
udfcClose();
|
||||||
dInfo("vnode-mgmt is cleaned up");
|
dInfo("vnode-mgmt is cleaned up");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,6 +335,10 @@ static int32_t vmInit(SMgmtWrapper *pWrapper) {
|
||||||
}
|
}
|
||||||
dmReportStartup(pDnode, "vnode-vnodes", "initialized");
|
dmReportStartup(pDnode, "vnode-vnodes", "initialized");
|
||||||
|
|
||||||
|
if (udfcOpen() != 0) {
|
||||||
|
dError("failed to open udfc in dnode");
|
||||||
|
}
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
|
@ -359,10 +359,52 @@ static int32_t vmRequire(SMgmtWrapper *pWrapper, bool *required) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t vmStart(SMgmtWrapper *pWrapper) {
|
||||||
|
dDebug("vnode-mgmt start to run");
|
||||||
|
SVnodesMgmt *pMgmt = pWrapper->pMgmt;
|
||||||
|
|
||||||
|
taosRLockLatch(&pMgmt->latch);
|
||||||
|
|
||||||
|
void *pIter = taosHashIterate(pMgmt->hash, NULL);
|
||||||
|
while (pIter) {
|
||||||
|
SVnodeObj **ppVnode = pIter;
|
||||||
|
if (ppVnode == NULL || *ppVnode == NULL) continue;
|
||||||
|
|
||||||
|
SVnodeObj *pVnode = *ppVnode;
|
||||||
|
vnodeStart(pVnode->pImpl);
|
||||||
|
pIter = taosHashIterate(pMgmt->hash, pIter);
|
||||||
|
}
|
||||||
|
|
||||||
|
taosRUnLockLatch(&pMgmt->latch);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vmStop(SMgmtWrapper *pWrapper) {
|
||||||
|
#if 0
|
||||||
|
dDebug("vnode-mgmt start to stop");
|
||||||
|
SVnodesMgmt *pMgmt = pWrapper->pMgmt;
|
||||||
|
taosRLockLatch(&pMgmt->latch);
|
||||||
|
|
||||||
|
void *pIter = taosHashIterate(pMgmt->hash, NULL);
|
||||||
|
while (pIter) {
|
||||||
|
SVnodeObj **ppVnode = pIter;
|
||||||
|
if (ppVnode == NULL || *ppVnode == NULL) continue;
|
||||||
|
|
||||||
|
SVnodeObj *pVnode = *ppVnode;
|
||||||
|
vnodeStop(pVnode->pImpl);
|
||||||
|
pIter = taosHashIterate(pMgmt->hash, pIter);
|
||||||
|
}
|
||||||
|
|
||||||
|
taosRUnLockLatch(&pMgmt->latch);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void vmSetMgmtFp(SMgmtWrapper *pWrapper) {
|
void vmSetMgmtFp(SMgmtWrapper *pWrapper) {
|
||||||
SMgmtFp mgmtFp = {0};
|
SMgmtFp mgmtFp = {0};
|
||||||
mgmtFp.openFp = vmInit;
|
mgmtFp.openFp = vmInit;
|
||||||
mgmtFp.closeFp = vmCleanup;
|
mgmtFp.closeFp = vmCleanup;
|
||||||
|
mgmtFp.startFp = vmStart;
|
||||||
|
mgmtFp.stopFp = vmStop;
|
||||||
mgmtFp.requiredFp = vmRequire;
|
mgmtFp.requiredFp = vmRequire;
|
||||||
|
|
||||||
vmInitMsgHandle(pWrapper);
|
vmInitMsgHandle(pWrapper);
|
||||||
|
@ -391,4 +433,4 @@ void vmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
taosRUnLockLatch(&pMgmt->latch);
|
taosRUnLockLatch(&pMgmt->latch);
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,6 +126,8 @@ typedef enum {
|
||||||
DND_REASON_OTHERS
|
DND_REASON_OTHERS
|
||||||
} EDndReason;
|
} EDndReason;
|
||||||
|
|
||||||
|
typedef void (*TransCbFp)(SMnode* pMnode, void* param);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t id;
|
int32_t id;
|
||||||
ETrnStage stage;
|
ETrnStage stage;
|
||||||
|
@ -148,6 +150,8 @@ typedef struct {
|
||||||
int64_t dbUid;
|
int64_t dbUid;
|
||||||
char dbname[TSDB_DB_FNAME_LEN];
|
char dbname[TSDB_DB_FNAME_LEN];
|
||||||
char lastError[TSDB_TRANS_ERROR_LEN];
|
char lastError[TSDB_TRANS_ERROR_LEN];
|
||||||
|
TransCbFp transCbFp;
|
||||||
|
void* transCbParam;
|
||||||
} STrans;
|
} STrans;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -350,7 +354,6 @@ typedef struct {
|
||||||
int32_t version;
|
int32_t version;
|
||||||
int32_t nextColId;
|
int32_t nextColId;
|
||||||
float xFilesFactor;
|
float xFilesFactor;
|
||||||
int32_t aggregationMethod;
|
|
||||||
int32_t delay;
|
int32_t delay;
|
||||||
int32_t ttl;
|
int32_t ttl;
|
||||||
int32_t numOfColumns;
|
int32_t numOfColumns;
|
||||||
|
@ -450,7 +453,6 @@ typedef struct {
|
||||||
int8_t withTbName;
|
int8_t withTbName;
|
||||||
int8_t withSchema;
|
int8_t withSchema;
|
||||||
int8_t withTag;
|
int8_t withTag;
|
||||||
int8_t withTagSchema;
|
|
||||||
SRWLatch lock;
|
SRWLatch lock;
|
||||||
int32_t sqlLen;
|
int32_t sqlLen;
|
||||||
int32_t astLen;
|
int32_t astLen;
|
||||||
|
@ -517,7 +519,6 @@ typedef struct {
|
||||||
int8_t withTbName;
|
int8_t withTbName;
|
||||||
int8_t withSchema;
|
int8_t withSchema;
|
||||||
int8_t withTag;
|
int8_t withTag;
|
||||||
int8_t withTagSchema;
|
|
||||||
SHashObj* consumerHash; // consumerId -> SMqConsumerEpInSub
|
SHashObj* consumerHash; // consumerId -> SMqConsumerEpInSub
|
||||||
// TODO put -1 into unassignVgs
|
// TODO put -1 into unassignVgs
|
||||||
// SArray* unassignedVgs;
|
// SArray* unassignedVgs;
|
||||||
|
|
|
@ -44,6 +44,7 @@ int32_t mndTransAppendCommitlog(STrans *pTrans, SSdbRaw *pRaw);
|
||||||
int32_t mndTransAppendRedoAction(STrans *pTrans, STransAction *pAction);
|
int32_t mndTransAppendRedoAction(STrans *pTrans, STransAction *pAction);
|
||||||
int32_t mndTransAppendUndoAction(STrans *pTrans, STransAction *pAction);
|
int32_t mndTransAppendUndoAction(STrans *pTrans, STransAction *pAction);
|
||||||
void mndTransSetRpcRsp(STrans *pTrans, void *pCont, int32_t contLen);
|
void mndTransSetRpcRsp(STrans *pTrans, void *pCont, int32_t contLen);
|
||||||
|
void mndTransSetCb(STrans *pTrans, TransCbFp fp, void *param);
|
||||||
void mndTransSetDbInfo(STrans *pTrans, SDbObj *pDb);
|
void mndTransSetDbInfo(STrans *pTrans, SDbObj *pDb);
|
||||||
|
|
||||||
int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans);
|
int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans);
|
||||||
|
|
|
@ -30,7 +30,6 @@ SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup);
|
||||||
int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups);
|
int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups);
|
||||||
SEpSet mndGetVgroupEpset(SMnode *pMnode, const SVgObj *pVgroup);
|
SEpSet mndGetVgroupEpset(SMnode *pMnode, const SVgObj *pVgroup);
|
||||||
int32_t mndGetVnodesNum(SMnode *pMnode, int32_t dnodeId);
|
int32_t mndGetVnodesNum(SMnode *pMnode, int32_t dnodeId);
|
||||||
int32_t mndGetGlobalVgroupVersion(int32_t *vgId);
|
|
||||||
|
|
||||||
void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen);
|
void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen);
|
||||||
void *mndBuildDropVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen);
|
void *mndBuildDropVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen);
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
#include "mndAcct.h"
|
#include "mndAcct.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
|
|
||||||
#define TSDB_ACCT_VER_NUMBER 1
|
#define ACCT_VER_NUMBER 1
|
||||||
#define TSDB_ACCT_RESERVE_SIZE 128
|
#define ACCT_RESERVE_SIZE 128
|
||||||
|
|
||||||
static int32_t mndCreateDefaultAcct(SMnode *pMnode);
|
static int32_t mndCreateDefaultAcct(SMnode *pMnode);
|
||||||
static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct);
|
static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct);
|
||||||
|
@ -55,6 +55,7 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
|
||||||
acctObj.createdTime = taosGetTimestampMs();
|
acctObj.createdTime = taosGetTimestampMs();
|
||||||
acctObj.updateTime = acctObj.createdTime;
|
acctObj.updateTime = acctObj.createdTime;
|
||||||
acctObj.acctId = 1;
|
acctObj.acctId = 1;
|
||||||
|
acctObj.status = 0;
|
||||||
acctObj.cfg = (SAcctCfg){.maxUsers = INT32_MAX,
|
acctObj.cfg = (SAcctCfg){.maxUsers = INT32_MAX,
|
||||||
.maxDbs = INT32_MAX,
|
.maxDbs = INT32_MAX,
|
||||||
.maxStbs = INT32_MAX,
|
.maxStbs = INT32_MAX,
|
||||||
|
@ -79,7 +80,7 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
|
||||||
static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct) {
|
static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_ACCT, TSDB_ACCT_VER_NUMBER, sizeof(SAcctObj) + TSDB_ACCT_RESERVE_SIZE);
|
SSdbRaw *pRaw = sdbAllocRaw(SDB_ACCT, ACCT_VER_NUMBER, sizeof(SAcctObj) + ACCT_RESERVE_SIZE);
|
||||||
if (pRaw == NULL) goto _OVER;
|
if (pRaw == NULL) goto _OVER;
|
||||||
|
|
||||||
int32_t dataPos = 0;
|
int32_t dataPos = 0;
|
||||||
|
@ -100,7 +101,7 @@ static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct) {
|
||||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTopics, _OVER)
|
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTopics, _OVER)
|
||||||
SDB_SET_INT64(pRaw, dataPos, pAcct->cfg.maxStorage, _OVER)
|
SDB_SET_INT64(pRaw, dataPos, pAcct->cfg.maxStorage, _OVER)
|
||||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.accessState, _OVER)
|
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.accessState, _OVER)
|
||||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_ACCT_RESERVE_SIZE, _OVER)
|
SDB_SET_RESERVE(pRaw, dataPos, ACCT_RESERVE_SIZE, _OVER)
|
||||||
SDB_SET_DATALEN(pRaw, dataPos, _OVER)
|
SDB_SET_DATALEN(pRaw, dataPos, _OVER)
|
||||||
|
|
||||||
terrno = 0;
|
terrno = 0;
|
||||||
|
@ -122,7 +123,7 @@ static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw) {
|
||||||
int8_t sver = 0;
|
int8_t sver = 0;
|
||||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
|
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
|
||||||
|
|
||||||
if (sver != TSDB_ACCT_VER_NUMBER) {
|
if (sver != ACCT_VER_NUMBER) {
|
||||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -151,7 +152,7 @@ static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw) {
|
||||||
SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTopics, _OVER)
|
SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTopics, _OVER)
|
||||||
SDB_GET_INT64(pRaw, dataPos, &pAcct->cfg.maxStorage, _OVER)
|
SDB_GET_INT64(pRaw, dataPos, &pAcct->cfg.maxStorage, _OVER)
|
||||||
SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.accessState, _OVER)
|
SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.accessState, _OVER)
|
||||||
SDB_GET_RESERVE(pRaw, dataPos, TSDB_ACCT_RESERVE_SIZE, _OVER)
|
SDB_GET_RESERVE(pRaw, dataPos, ACCT_RESERVE_SIZE, _OVER)
|
||||||
|
|
||||||
terrno = 0;
|
terrno = 0;
|
||||||
|
|
||||||
|
@ -178,7 +179,6 @@ static int32_t mndAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct) {
|
||||||
|
|
||||||
static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOld, SAcctObj *pNew) {
|
static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOld, SAcctObj *pNew) {
|
||||||
mTrace("acct:%s, perform update action, old row:%p new row:%p", pOld->acct, pOld, pNew);
|
mTrace("acct:%s, perform update action, old row:%p new row:%p", pOld->acct, pOld, pNew);
|
||||||
|
|
||||||
pOld->updateTime = pNew->updateTime;
|
pOld->updateTime = pNew->updateTime;
|
||||||
pOld->status = pNew->status;
|
pOld->status = pNew->status;
|
||||||
memcpy(&pOld->cfg, &pNew->cfg, sizeof(SAcctCfg));
|
memcpy(&pOld->cfg, &pNew->cfg, sizeof(SAcctCfg));
|
||||||
|
@ -186,19 +186,19 @@ static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOld, SAcctObj *pNew) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessCreateAcctReq(SNodeMsg *pReq) {
|
static int32_t mndProcessCreateAcctReq(SNodeMsg *pReq) {
|
||||||
terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||||
mError("failed to process create acct request since %s", terrstr());
|
mError("failed to process create acct request since %s", terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessAlterAcctReq(SNodeMsg *pReq) {
|
static int32_t mndProcessAlterAcctReq(SNodeMsg *pReq) {
|
||||||
terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||||
mError("failed to process create acct request since %s", terrstr());
|
mError("failed to process create acct request since %s", terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessDropAcctReq(SNodeMsg *pReq) {
|
static int32_t mndProcessDropAcctReq(SNodeMsg *pReq) {
|
||||||
terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||||
mError("failed to process create acct request since %s", terrstr());
|
mError("failed to process create acct request since %s", terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
|
@ -234,6 +234,8 @@ static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOld, SDbObj *pNew) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t mndGetGlobalVgroupVersion(SMnode *pMnode) { return sdbGetTableVer(pMnode->pSdb, SDB_VGROUP); }
|
||||||
|
|
||||||
SDbObj *mndAcquireDb(SMnode *pMnode, const char *db) {
|
SDbObj *mndAcquireDb(SMnode *pMnode, const char *db) {
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
SDbObj *pDb = sdbAcquire(pSdb, SDB_DB, db);
|
SDbObj *pDb = sdbAcquire(pSdb, SDB_DB, db);
|
||||||
|
@ -618,7 +620,7 @@ static int32_t mndSetAlterDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pOl
|
||||||
SSdbRaw *pRedoRaw = mndDbActionEncode(pOld);
|
SSdbRaw *pRedoRaw = mndDbActionEncode(pOld);
|
||||||
if (pRedoRaw == NULL) return -1;
|
if (pRedoRaw == NULL) return -1;
|
||||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_UPDATING) != 0) return -1;
|
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY) != 0) return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1191,8 +1193,7 @@ static int32_t mndProcessUseDbReq(SNodeMsg *pReq) {
|
||||||
char *p = strchr(usedbReq.db, '.');
|
char *p = strchr(usedbReq.db, '.');
|
||||||
if (p && 0 == strcmp(p + 1, TSDB_INFORMATION_SCHEMA_DB)) {
|
if (p && 0 == strcmp(p + 1, TSDB_INFORMATION_SCHEMA_DB)) {
|
||||||
memcpy(usedbRsp.db, usedbReq.db, TSDB_DB_FNAME_LEN);
|
memcpy(usedbRsp.db, usedbReq.db, TSDB_DB_FNAME_LEN);
|
||||||
//mndGetGlobalVgroupVersion(); TODO
|
int32_t vgVersion = mndGetGlobalVgroupVersion(pMnode);
|
||||||
static int32_t vgVersion = 1;
|
|
||||||
if (usedbReq.vgVersion < vgVersion) {
|
if (usedbReq.vgVersion < vgVersion) {
|
||||||
usedbRsp.pVgroupInfos = taosArrayInit(10, sizeof(SVgroupInfo));
|
usedbRsp.pVgroupInfos = taosArrayInit(10, sizeof(SVgroupInfo));
|
||||||
if (usedbRsp.pVgroupInfos == NULL) {
|
if (usedbRsp.pVgroupInfos == NULL) {
|
||||||
|
|
|
@ -237,7 +237,6 @@ SMqSubscribeObj *tCloneSubscribeObj(const SMqSubscribeObj *pSub) {
|
||||||
pSubNew->withTbName = pSub->withTbName;
|
pSubNew->withTbName = pSub->withTbName;
|
||||||
pSubNew->withSchema = pSub->withSchema;
|
pSubNew->withSchema = pSub->withSchema;
|
||||||
pSubNew->withTag = pSub->withTag;
|
pSubNew->withTag = pSub->withTag;
|
||||||
pSubNew->withTagSchema = pSub->withTagSchema;
|
|
||||||
|
|
||||||
pSubNew->vgNum = pSub->vgNum;
|
pSubNew->vgNum = pSub->vgNum;
|
||||||
pSubNew->consumerHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
|
pSubNew->consumerHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
|
||||||
|
@ -270,7 +269,6 @@ int32_t tEncodeSubscribeObj(void **buf, const SMqSubscribeObj *pSub) {
|
||||||
tlen += taosEncodeFixedI8(buf, pSub->withTbName);
|
tlen += taosEncodeFixedI8(buf, pSub->withTbName);
|
||||||
tlen += taosEncodeFixedI8(buf, pSub->withSchema);
|
tlen += taosEncodeFixedI8(buf, pSub->withSchema);
|
||||||
tlen += taosEncodeFixedI8(buf, pSub->withTag);
|
tlen += taosEncodeFixedI8(buf, pSub->withTag);
|
||||||
tlen += taosEncodeFixedI8(buf, pSub->withTagSchema);
|
|
||||||
|
|
||||||
void *pIter = NULL;
|
void *pIter = NULL;
|
||||||
int32_t sz = taosHashGetSize(pSub->consumerHash);
|
int32_t sz = taosHashGetSize(pSub->consumerHash);
|
||||||
|
@ -297,7 +295,6 @@ void *tDecodeSubscribeObj(const void *buf, SMqSubscribeObj *pSub) {
|
||||||
buf = taosDecodeFixedI8(buf, &pSub->withTbName);
|
buf = taosDecodeFixedI8(buf, &pSub->withTbName);
|
||||||
buf = taosDecodeFixedI8(buf, &pSub->withSchema);
|
buf = taosDecodeFixedI8(buf, &pSub->withSchema);
|
||||||
buf = taosDecodeFixedI8(buf, &pSub->withTag);
|
buf = taosDecodeFixedI8(buf, &pSub->withTag);
|
||||||
buf = taosDecodeFixedI8(buf, &pSub->withTagSchema);
|
|
||||||
|
|
||||||
int32_t sz;
|
int32_t sz;
|
||||||
buf = taosDecodeFixedI32(buf, &sz);
|
buf = taosDecodeFixedI32(buf, &sz);
|
||||||
|
|
|
@ -363,7 +363,7 @@ static int32_t mndProcessStatusReq(SNodeMsg *pReq) {
|
||||||
pDnode->offlineReason = DND_REASON_VERSION_NOT_MATCH;
|
pDnode->offlineReason = DND_REASON_VERSION_NOT_MATCH;
|
||||||
}
|
}
|
||||||
mError("dnode:%d, status msg version:%d not match cluster:%d", statusReq.dnodeId, statusReq.sver, tsVersion);
|
mError("dnode:%d, status msg version:%d not match cluster:%d", statusReq.dnodeId, statusReq.sver, tsVersion);
|
||||||
terrno = TSDB_CODE_MND_INVALID_MSG_VERSION;
|
terrno = TSDB_CODE_VERSION_NOT_COMPATIBLE;
|
||||||
goto PROCESS_STATUS_MSG_OVER;
|
goto PROCESS_STATUS_MSG_OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -325,7 +325,7 @@ static int32_t mndInsInitMeta(SHashObj *hash) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosHashPut(hash, meta.tbName, strlen(meta.tbName) + 1, &meta, sizeof(meta))) {
|
if (taosHashPut(hash, meta.tbName, strlen(meta.tbName), &meta, sizeof(meta))) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -340,10 +340,10 @@ int32_t mndBuildInsTableSchema(SMnode *pMnode, const char *dbFName, const char *
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, tbName, strlen(tbName) + 1);
|
STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, tbName, strlen(tbName));
|
||||||
if (NULL == pMeta) {
|
if (NULL == pMeta) {
|
||||||
mError("invalid information schema table name:%s", tbName);
|
mError("invalid information schema table name:%s", tbName);
|
||||||
terrno = TSDB_CODE_MND_INVALID_INFOS_TBL;
|
terrno = TSDB_CODE_MND_INVALID_SYS_TABLENAME;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -128,7 +128,7 @@ int32_t mndBuildPerfsTableSchema(SMnode *pMnode, const char *dbFName, const char
|
||||||
STableMetaRsp *meta = (STableMetaRsp *)taosHashGet(pMnode->perfsMeta, tbName, strlen(tbName));
|
STableMetaRsp *meta = (STableMetaRsp *)taosHashGet(pMnode->perfsMeta, tbName, strlen(tbName));
|
||||||
if (NULL == meta) {
|
if (NULL == meta) {
|
||||||
mError("invalid performance schema table name:%s", tbName);
|
mError("invalid performance schema table name:%s", tbName);
|
||||||
terrno = TSDB_CODE_MND_INVALID_INFOS_TBL;
|
terrno = TSDB_CODE_MND_INVALID_SYS_TABLENAME;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -451,8 +451,9 @@ static int32_t mndProcessQnodeListReq(SNodeMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *pIter = NULL;
|
||||||
while (1) {
|
while (1) {
|
||||||
void *pIter = sdbFetch(pSdb, SDB_QNODE, NULL, (void **)&pObj);
|
pIter = sdbFetch(pSdb, SDB_QNODE, pIter, (void **)&pObj);
|
||||||
if (pIter == NULL) break;
|
if (pIter == NULL) break;
|
||||||
|
|
||||||
SQueryNodeAddr nodeAddr = {0};
|
SQueryNodeAddr nodeAddr = {0};
|
||||||
|
@ -472,7 +473,7 @@ static int32_t mndProcessQnodeListReq(SNodeMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t rspLen = tSerializeSQnodeListRsp(NULL, 0, &qlistRsp);
|
int32_t rspLen = tSerializeSQnodeListRsp(NULL, 0, &qlistRsp);
|
||||||
void *pRsp = taosMemoryMalloc(rspLen);
|
void *pRsp = rpcMallocCont(rspLen);
|
||||||
if (pRsp == NULL) {
|
if (pRsp == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
|
|
|
@ -476,33 +476,37 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
||||||
int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscribeObj* pSub) {
|
int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscribeObj* pSub) {
|
||||||
SSdb* pSdb = pMnode->pSdb;
|
SSdb* pSdb = pMnode->pSdb;
|
||||||
SVgObj* pVgroup = NULL;
|
SVgObj* pVgroup = NULL;
|
||||||
SQueryPlan* pPlan = qStringToQueryPlan(pTopic->physicalPlan);
|
SQueryPlan* pPlan = NULL;
|
||||||
if (pPlan == NULL) {
|
SSubplan* plan = NULL;
|
||||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
if (pTopic->subType == TOPIC_SUB_TYPE__TABLE) {
|
||||||
return -1;
|
pPlan = qStringToQueryPlan(pTopic->physicalPlan);
|
||||||
|
if (pPlan == NULL) {
|
||||||
|
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSERT(pSub->vgNum == -1);
|
||||||
|
|
||||||
|
pSub->vgNum = 0;
|
||||||
|
|
||||||
|
int32_t levelNum = LIST_LENGTH(pPlan->pSubplans);
|
||||||
|
if (levelNum != 1) {
|
||||||
|
qDestroyQueryPlan(pPlan);
|
||||||
|
terrno = TSDB_CODE_MND_UNSUPPORTED_TOPIC;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNodeListNode* inner = nodesListGetNode(pPlan->pSubplans, 0);
|
||||||
|
|
||||||
|
int32_t opNum = LIST_LENGTH(inner->pNodeList);
|
||||||
|
if (opNum != 1) {
|
||||||
|
qDestroyQueryPlan(pPlan);
|
||||||
|
terrno = TSDB_CODE_MND_UNSUPPORTED_TOPIC;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
plan = nodesListGetNode(inner->pNodeList, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(pSub->vgNum == -1);
|
|
||||||
|
|
||||||
pSub->vgNum = 0;
|
|
||||||
|
|
||||||
int32_t levelNum = LIST_LENGTH(pPlan->pSubplans);
|
|
||||||
if (levelNum != 1) {
|
|
||||||
qDestroyQueryPlan(pPlan);
|
|
||||||
terrno = TSDB_CODE_MND_UNSUPPORTED_TOPIC;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SNodeListNode* inner = nodesListGetNode(pPlan->pSubplans, 0);
|
|
||||||
|
|
||||||
int32_t opNum = LIST_LENGTH(inner->pNodeList);
|
|
||||||
if (opNum != 1) {
|
|
||||||
qDestroyQueryPlan(pPlan);
|
|
||||||
terrno = TSDB_CODE_MND_UNSUPPORTED_TOPIC;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
SSubplan* plan = nodesListGetNode(inner->pNodeList, 0);
|
|
||||||
|
|
||||||
int64_t unexistKey = -1;
|
int64_t unexistKey = -1;
|
||||||
SMqConsumerEpInSub* pEpInSub = taosHashGet(pSub->consumerHash, &unexistKey, sizeof(int64_t));
|
SMqConsumerEpInSub* pEpInSub = taosHashGet(pSub->consumerHash, &unexistKey, sizeof(int64_t));
|
||||||
ASSERT(pEpInSub);
|
ASSERT(pEpInSub);
|
||||||
|
@ -519,38 +523,35 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
|
||||||
}
|
}
|
||||||
|
|
||||||
pSub->vgNum++;
|
pSub->vgNum++;
|
||||||
plan->execNode.nodeId = pVgroup->vgId;
|
|
||||||
plan->execNode.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
|
||||||
|
|
||||||
SMqVgEp* pVgEp = taosMemoryMalloc(sizeof(SMqVgEp));
|
SMqVgEp* pVgEp = taosMemoryMalloc(sizeof(SMqVgEp));
|
||||||
pVgEp->epSet = plan->execNode.epSet;
|
pVgEp->epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||||
pVgEp->vgId = plan->execNode.nodeId;
|
pVgEp->vgId = pVgroup->vgId;
|
||||||
|
taosArrayPush(pEpInSub->vgs, &pVgEp);
|
||||||
#if 0
|
|
||||||
SMqConsumerEp consumerEp = {0};
|
|
||||||
consumerEp.status = 0;
|
|
||||||
consumerEp.consumerId = -1;
|
|
||||||
consumerEp.epSet = plan->execNode.epSet;
|
|
||||||
consumerEp.vgId = plan->execNode.nodeId;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
mDebug("init subscribption %s, assign vg: %d", pSub->key, pVgEp->vgId);
|
mDebug("init subscribption %s, assign vg: %d", pSub->key, pVgEp->vgId);
|
||||||
|
|
||||||
int32_t msgLen;
|
if (pTopic->subType == TOPIC_SUB_TYPE__TABLE) {
|
||||||
if (qSubPlanToString(plan, &pVgEp->qmsg, &msgLen) < 0) {
|
int32_t msgLen;
|
||||||
sdbRelease(pSdb, pVgroup);
|
|
||||||
qDestroyQueryPlan(pPlan);
|
plan->execNode.epSet = pVgEp->epSet;
|
||||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
plan->execNode.nodeId = pVgEp->vgId;
|
||||||
return -1;
|
|
||||||
|
if (qSubPlanToString(plan, &pVgEp->qmsg, &msgLen) < 0) {
|
||||||
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
qDestroyQueryPlan(pPlan);
|
||||||
|
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pVgEp->qmsg = strdup("");
|
||||||
}
|
}
|
||||||
taosArrayPush(pEpInSub->vgs, &pVgEp);
|
|
||||||
|
|
||||||
ASSERT(taosHashGetSize(pSub->consumerHash) == 1);
|
ASSERT(taosHashGetSize(pSub->consumerHash) == 1);
|
||||||
|
|
||||||
/*taosArrayPush(pSub->unassignedVg, &consumerEp);*/
|
/*taosArrayPush(pSub->unassignedVg, &consumerEp);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(pEpInSub->vgs->size > 0);
|
|
||||||
pEpInSub = taosHashGet(pSub->consumerHash, &unexistKey, sizeof(int64_t));
|
pEpInSub = taosHashGet(pSub->consumerHash, &unexistKey, sizeof(int64_t));
|
||||||
|
|
||||||
ASSERT(pEpInSub->vgs->size > 0);
|
ASSERT(pEpInSub->vgs->size > 0);
|
||||||
|
|
|
@ -100,6 +100,8 @@ static int32_t convertToRetrieveType(char* name, int32_t len) {
|
||||||
type = TSDB_MGMT_TABLE_QUERIES;
|
type = TSDB_MGMT_TABLE_QUERIES;
|
||||||
} else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) {
|
} else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, len) == 0) {
|
||||||
type = TSDB_MGMT_TABLE_VNODES;
|
type = TSDB_MGMT_TABLE_VNODES;
|
||||||
|
} else if (strncasecmp(name, TSDB_PERFS_TABLE_TOPICS, len) == 0) {
|
||||||
|
type = TSDB_MGMT_TABLE_TOPICS;
|
||||||
} else {
|
} else {
|
||||||
// ASSERT(0);
|
// ASSERT(0);
|
||||||
}
|
}
|
||||||
|
@ -187,11 +189,14 @@ static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retrieveReq.showId == 0) {
|
if (retrieveReq.showId == 0) {
|
||||||
STableMetaRsp *pMeta = (STableMetaRsp *)taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb) + 1);
|
STableMetaRsp *pMeta = (STableMetaRsp *)taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb));
|
||||||
if (pMeta == NULL) {
|
if (pMeta == NULL) {
|
||||||
terrno = TSDB_CODE_MND_INVALID_INFOS_TBL;
|
pMeta = (STableMetaRsp *)taosHashGet(pMnode->perfsMeta, retrieveReq.tb, strlen(retrieveReq.tb));
|
||||||
mError("failed to process show-retrieve req:%p since %s", pShow, terrstr());
|
if (pMeta == NULL) {
|
||||||
return -1;
|
terrno = TSDB_CODE_MND_INVALID_SYS_TABLENAME;
|
||||||
|
mError("failed to process show-retrieve req:%p since %s", pShow, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pShow = mndCreateShowObj(pMnode, &retrieveReq);
|
pShow = mndCreateShowObj(pMnode, &retrieveReq);
|
||||||
|
|
|
@ -87,7 +87,6 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
|
||||||
SDB_SET_INT32(pRaw, dataPos, pStb->version, _OVER)
|
SDB_SET_INT32(pRaw, dataPos, pStb->version, _OVER)
|
||||||
SDB_SET_INT32(pRaw, dataPos, pStb->nextColId, _OVER)
|
SDB_SET_INT32(pRaw, dataPos, pStb->nextColId, _OVER)
|
||||||
SDB_SET_INT32(pRaw, dataPos, (int32_t)(pStb->xFilesFactor * 10000), _OVER)
|
SDB_SET_INT32(pRaw, dataPos, (int32_t)(pStb->xFilesFactor * 10000), _OVER)
|
||||||
SDB_SET_INT32(pRaw, dataPos, pStb->aggregationMethod, _OVER)
|
|
||||||
SDB_SET_INT32(pRaw, dataPos, pStb->delay, _OVER)
|
SDB_SET_INT32(pRaw, dataPos, pStb->delay, _OVER)
|
||||||
SDB_SET_INT32(pRaw, dataPos, pStb->ttl, _OVER)
|
SDB_SET_INT32(pRaw, dataPos, pStb->ttl, _OVER)
|
||||||
SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns, _OVER)
|
SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns, _OVER)
|
||||||
|
@ -175,7 +174,6 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
|
||||||
int32_t xFilesFactor = 0;
|
int32_t xFilesFactor = 0;
|
||||||
SDB_GET_INT32(pRaw, dataPos, &xFilesFactor, _OVER)
|
SDB_GET_INT32(pRaw, dataPos, &xFilesFactor, _OVER)
|
||||||
pStb->xFilesFactor = xFilesFactor / 10000.0f;
|
pStb->xFilesFactor = xFilesFactor / 10000.0f;
|
||||||
SDB_GET_INT32(pRaw, dataPos, &pStb->aggregationMethod, _OVER)
|
|
||||||
SDB_GET_INT32(pRaw, dataPos, &pStb->delay, _OVER)
|
SDB_GET_INT32(pRaw, dataPos, &pStb->delay, _OVER)
|
||||||
SDB_GET_INT32(pRaw, dataPos, &pStb->ttl, _OVER)
|
SDB_GET_INT32(pRaw, dataPos, &pStb->ttl, _OVER)
|
||||||
SDB_GET_INT32(pRaw, dataPos, &pStb->numOfColumns, _OVER)
|
SDB_GET_INT32(pRaw, dataPos, &pStb->numOfColumns, _OVER)
|
||||||
|
@ -404,7 +402,7 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
|
||||||
req.name = (char *)tNameGetTableName(&name);
|
req.name = (char *)tNameGetTableName(&name);
|
||||||
req.ttl = 0;
|
req.ttl = 0;
|
||||||
req.keep = 0;
|
req.keep = 0;
|
||||||
req.rollup = pStb->aggregationMethod > -1 ? 1 : 0;
|
req.rollup = pStb->pAst1 > 0 ? 1 : 0;
|
||||||
req.type = TD_SUPER_TABLE;
|
req.type = TD_SUPER_TABLE;
|
||||||
req.stbCfg.suid = pStb->uid;
|
req.stbCfg.suid = pStb->uid;
|
||||||
req.stbCfg.nCols = pStb->numOfColumns;
|
req.stbCfg.nCols = pStb->numOfColumns;
|
||||||
|
@ -433,29 +431,15 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
|
||||||
|
|
||||||
pRSmaParam->xFilesFactor = pStb->xFilesFactor;
|
pRSmaParam->xFilesFactor = pStb->xFilesFactor;
|
||||||
pRSmaParam->delay = pStb->delay;
|
pRSmaParam->delay = pStb->delay;
|
||||||
pRSmaParam->nFuncIds = 1; // only 1 aggregation method supported currently
|
|
||||||
pRSmaParam->pFuncIds = (func_id_t *)taosMemoryCalloc(pRSmaParam->nFuncIds, sizeof(func_id_t));
|
|
||||||
if (pRSmaParam->pFuncIds == NULL) {
|
|
||||||
taosMemoryFreeClear(req.stbCfg.pRSmaParam);
|
|
||||||
taosMemoryFreeClear(req.stbCfg.pSchema);
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
for (int32_t f = 0; f < pRSmaParam->nFuncIds; ++f) {
|
|
||||||
*(pRSmaParam->pFuncIds + f) = pStb->aggregationMethod;
|
|
||||||
}
|
|
||||||
if (pStb->ast1Len > 0) {
|
if (pStb->ast1Len > 0) {
|
||||||
if (mndConvertRSmaTask(pStb->pAst1, 0, 0, &pRSmaParam->qmsg1, &pRSmaParam->qmsg1Len) != TSDB_CODE_SUCCESS) {
|
if (mndConvertRSmaTask(pStb->pAst1, 0, 0, &pRSmaParam->qmsg1, &pRSmaParam->qmsg1Len) != TSDB_CODE_SUCCESS) {
|
||||||
taosMemoryFreeClear(pRSmaParam->pFuncIds);
|
|
||||||
taosMemoryFreeClear(req.stbCfg.pRSmaParam);
|
taosMemoryFreeClear(req.stbCfg.pRSmaParam);
|
||||||
taosMemoryFreeClear(req.stbCfg.pSchema);
|
taosMemoryFreeClear(req.stbCfg.pSchema);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pStb->ast2Len > 0) {
|
if (pStb->ast2Len > 0) {
|
||||||
int32_t qmsgLen2 = 0;
|
|
||||||
if (mndConvertRSmaTask(pStb->pAst2, 0, 0, &pRSmaParam->qmsg2, &pRSmaParam->qmsg2Len) != TSDB_CODE_SUCCESS) {
|
if (mndConvertRSmaTask(pStb->pAst2, 0, 0, &pRSmaParam->qmsg2, &pRSmaParam->qmsg2Len) != TSDB_CODE_SUCCESS) {
|
||||||
taosMemoryFreeClear(pRSmaParam->pFuncIds);
|
|
||||||
taosMemoryFreeClear(pRSmaParam->qmsg1);
|
taosMemoryFreeClear(pRSmaParam->qmsg1);
|
||||||
taosMemoryFreeClear(req.stbCfg.pRSmaParam);
|
taosMemoryFreeClear(req.stbCfg.pRSmaParam);
|
||||||
taosMemoryFreeClear(req.stbCfg.pSchema);
|
taosMemoryFreeClear(req.stbCfg.pSchema);
|
||||||
|
@ -470,7 +454,6 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
|
||||||
SMsgHead *pHead = taosMemoryMalloc(contLen);
|
SMsgHead *pHead = taosMemoryMalloc(contLen);
|
||||||
if (pHead == NULL) {
|
if (pHead == NULL) {
|
||||||
if (pRSmaParam) {
|
if (pRSmaParam) {
|
||||||
taosMemoryFreeClear(pRSmaParam->pFuncIds);
|
|
||||||
taosMemoryFreeClear(pRSmaParam->qmsg1);
|
taosMemoryFreeClear(pRSmaParam->qmsg1);
|
||||||
taosMemoryFreeClear(pRSmaParam->qmsg2);
|
taosMemoryFreeClear(pRSmaParam->qmsg2);
|
||||||
taosMemoryFreeClear(pRSmaParam);
|
taosMemoryFreeClear(pRSmaParam);
|
||||||
|
@ -488,7 +471,6 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
|
||||||
|
|
||||||
*pContLen = contLen;
|
*pContLen = contLen;
|
||||||
if (pRSmaParam) {
|
if (pRSmaParam) {
|
||||||
taosMemoryFreeClear(pRSmaParam->pFuncIds);
|
|
||||||
taosMemoryFreeClear(pRSmaParam->qmsg1);
|
taosMemoryFreeClear(pRSmaParam->qmsg1);
|
||||||
taosMemoryFreeClear(pRSmaParam->qmsg2);
|
taosMemoryFreeClear(pRSmaParam->qmsg2);
|
||||||
taosMemoryFreeClear(pRSmaParam);
|
taosMemoryFreeClear(pRSmaParam);
|
||||||
|
@ -706,7 +688,6 @@ static int32_t mndCreateStb(SMnode *pMnode, SNodeMsg *pReq, SMCreateStbReq *pCre
|
||||||
stbObj.version = 1;
|
stbObj.version = 1;
|
||||||
stbObj.nextColId = 1;
|
stbObj.nextColId = 1;
|
||||||
stbObj.xFilesFactor = pCreate->xFilesFactor;
|
stbObj.xFilesFactor = pCreate->xFilesFactor;
|
||||||
stbObj.aggregationMethod = pCreate->aggregationMethod;
|
|
||||||
stbObj.delay = pCreate->delay;
|
stbObj.delay = pCreate->delay;
|
||||||
stbObj.ttl = pCreate->ttl;
|
stbObj.ttl = pCreate->ttl;
|
||||||
stbObj.numOfColumns = pCreate->numOfColumns;
|
stbObj.numOfColumns = pCreate->numOfColumns;
|
||||||
|
|
|
@ -35,11 +35,6 @@
|
||||||
|
|
||||||
#define MND_SUBSCRIBE_REBALANCE_CNT 3
|
#define MND_SUBSCRIBE_REBALANCE_CNT 3
|
||||||
|
|
||||||
enum {
|
|
||||||
MQ_SUBSCRIBE_STATUS__ACTIVE = 1,
|
|
||||||
MQ_SUBSCRIBE_STATUS__DELETED,
|
|
||||||
};
|
|
||||||
|
|
||||||
static SSdbRaw *mndSubActionEncode(SMqSubscribeObj *);
|
static SSdbRaw *mndSubActionEncode(SMqSubscribeObj *);
|
||||||
static SSdbRow *mndSubActionDecode(SSdbRaw *pRaw);
|
static SSdbRow *mndSubActionDecode(SSdbRaw *pRaw);
|
||||||
static int32_t mndSubActionInsert(SSdb *pSdb, SMqSubscribeObj *);
|
static int32_t mndSubActionInsert(SSdb *pSdb, SMqSubscribeObj *);
|
||||||
|
@ -89,7 +84,6 @@ static SMqSubscribeObj *mndCreateSub(SMnode *pMnode, const SMqTopicObj *pTopic,
|
||||||
pSub->withTbName = pTopic->withTbName;
|
pSub->withTbName = pTopic->withTbName;
|
||||||
pSub->withSchema = pTopic->withSchema;
|
pSub->withSchema = pTopic->withSchema;
|
||||||
pSub->withTag = pTopic->withTag;
|
pSub->withTag = pTopic->withTag;
|
||||||
pSub->withTagSchema = pTopic->withTagSchema;
|
|
||||||
|
|
||||||
ASSERT(taosHashGetSize(pSub->consumerHash) == 1);
|
ASSERT(taosHashGetSize(pSub->consumerHash) == 1);
|
||||||
|
|
||||||
|
@ -115,7 +109,6 @@ static int32_t mndBuildSubChangeReq(void **pBuf, int32_t *pLen, const SMqSubscri
|
||||||
req.withTbName = pSub->withTbName;
|
req.withTbName = pSub->withTbName;
|
||||||
req.withSchema = pSub->withSchema;
|
req.withSchema = pSub->withSchema;
|
||||||
req.withTag = pSub->withTag;
|
req.withTag = pSub->withTag;
|
||||||
req.withTagSchema = pSub->withTagSchema;
|
|
||||||
strncpy(req.subKey, pSub->key, TSDB_SUBSCRIBE_KEY_LEN);
|
strncpy(req.subKey, pSub->key, TSDB_SUBSCRIBE_KEY_LEN);
|
||||||
|
|
||||||
int32_t tlen = sizeof(SMsgHead) + tEncodeSMqRebVgReq(NULL, &req);
|
int32_t tlen = sizeof(SMsgHead) + tEncodeSMqRebVgReq(NULL, &req);
|
||||||
|
@ -514,9 +507,11 @@ static int32_t mndProcessRebalanceReq(SNodeMsg *pMsg) {
|
||||||
|
|
||||||
// TODO replace assert with error check
|
// TODO replace assert with error check
|
||||||
ASSERT(mndDoRebalance(pMnode, &rebInput, &rebOutput) == 0);
|
ASSERT(mndDoRebalance(pMnode, &rebInput, &rebOutput) == 0);
|
||||||
|
|
||||||
// if add more consumer to balanced subscribe,
|
// if add more consumer to balanced subscribe,
|
||||||
// possibly no vg is changed
|
// possibly no vg is changed
|
||||||
/*ASSERT(taosArrayGetSize(rebOutput.rebVgs) != 0);*/
|
/*ASSERT(taosArrayGetSize(rebOutput.rebVgs) != 0);*/
|
||||||
|
|
||||||
ASSERT(mndPersistRebResult(pMnode, pMsg, &rebOutput) == 0);
|
ASSERT(mndPersistRebResult(pMnode, pMsg, &rebOutput) == 0);
|
||||||
|
|
||||||
if (rebInput.pTopic) {
|
if (rebInput.pTopic) {
|
||||||
|
@ -673,177 +668,7 @@ void mndReleaseSubscribe(SMnode *pMnode, SMqSubscribeObj *pSub) {
|
||||||
sdbRelease(pSdb, pSub);
|
sdbRelease(pSdb, pSub);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
static int32_t mndProcessSubscribeReq(SNodeMsg *pMsg) {
|
|
||||||
SMnode *pMnode = pMsg->pNode;
|
|
||||||
char *msgStr = pMsg->rpcMsg.pCont;
|
|
||||||
SCMSubscribeReq subscribe;
|
|
||||||
tDeserializeSCMSubscribeReq(msgStr, &subscribe);
|
|
||||||
int64_t consumerId = subscribe.consumerId;
|
|
||||||
char *cgroup = subscribe.consumerGroup;
|
|
||||||
|
|
||||||
SArray *newSub = subscribe.topicNames;
|
|
||||||
int32_t newTopicNum = subscribe.topicNum;
|
|
||||||
|
|
||||||
taosArraySortString(newSub, taosArrayCompareString);
|
|
||||||
|
|
||||||
SArray *oldSub = NULL;
|
|
||||||
int32_t oldTopicNum = 0;
|
|
||||||
bool createConsumer = false;
|
|
||||||
// create consumer if not exist
|
|
||||||
SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, consumerId);
|
|
||||||
if (pConsumer == NULL) {
|
|
||||||
// create consumer
|
|
||||||
pConsumer = mndCreateConsumer(consumerId, cgroup);
|
|
||||||
createConsumer = true;
|
|
||||||
} else {
|
|
||||||
pConsumer->epoch++;
|
|
||||||
oldSub = pConsumer->currentTopics;
|
|
||||||
}
|
|
||||||
pConsumer->currentTopics = newSub;
|
|
||||||
|
|
||||||
if (oldSub != NULL) {
|
|
||||||
oldTopicNum = taosArrayGetSize(oldSub);
|
|
||||||
}
|
|
||||||
|
|
||||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_TYPE_SUBSCRIBE, &pMsg->rpcMsg);
|
|
||||||
if (pTrans == NULL) {
|
|
||||||
// TODO: free memory
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t i = 0, j = 0;
|
|
||||||
while (i < newTopicNum || j < oldTopicNum) {
|
|
||||||
char *newTopicName = NULL;
|
|
||||||
char *oldTopicName = NULL;
|
|
||||||
if (i >= newTopicNum) {
|
|
||||||
// encode unset topic msg to all vnodes related to that topic
|
|
||||||
oldTopicName = taosArrayGetP(oldSub, j);
|
|
||||||
j++;
|
|
||||||
} else if (j >= oldTopicNum) {
|
|
||||||
newTopicName = taosArrayGetP(newSub, i);
|
|
||||||
i++;
|
|
||||||
} else {
|
|
||||||
newTopicName = taosArrayGetP(newSub, i);
|
|
||||||
oldTopicName = taosArrayGetP(oldSub, j);
|
|
||||||
|
|
||||||
int32_t comp = compareLenPrefixedStr(newTopicName, oldTopicName);
|
|
||||||
if (comp == 0) {
|
|
||||||
// do nothing
|
|
||||||
oldTopicName = newTopicName = NULL;
|
|
||||||
i++;
|
|
||||||
j++;
|
|
||||||
continue;
|
|
||||||
} else if (comp < 0) {
|
|
||||||
oldTopicName = NULL;
|
|
||||||
i++;
|
|
||||||
} else {
|
|
||||||
newTopicName = NULL;
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oldTopicName != NULL) {
|
|
||||||
ASSERT(newTopicName == NULL);
|
|
||||||
|
|
||||||
// cancel subscribe of old topic
|
|
||||||
SMqSubscribeObj *pSub = mndAcquireSubscribe(pMnode, cgroup, oldTopicName);
|
|
||||||
ASSERT(pSub);
|
|
||||||
int32_t csz = taosArrayGetSize(pSub->consumers);
|
|
||||||
for (int32_t ci = 0; ci < csz; ci++) {
|
|
||||||
SMqSubConsumer *pSubConsumer = taosArrayGet(pSub->consumers, ci);
|
|
||||||
if (pSubConsumer->consumerId == consumerId) {
|
|
||||||
int32_t vgsz = taosArrayGetSize(pSubConsumer->vgInfo);
|
|
||||||
for (int32_t vgi = 0; vgi < vgsz; vgi++) {
|
|
||||||
SMqConsumerEp *pConsumerEp = taosArrayGet(pSubConsumer->vgInfo, vgi);
|
|
||||||
mndPersistCancelConnReq(pMnode, pTrans, pConsumerEp, oldTopicName);
|
|
||||||
taosArrayPush(pSub->unassignedVg, pConsumerEp);
|
|
||||||
}
|
|
||||||
taosArrayRemove(pSub->consumers, ci);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
char *oldTopicNameDup = strdup(oldTopicName);
|
|
||||||
taosArrayPush(pConsumer->recentRemovedTopics, &oldTopicNameDup);
|
|
||||||
atomic_store_32(&pConsumer->status, MQ_CONSUMER_STATUS__MODIFY);
|
|
||||||
/*pSub->status = MQ_SUBSCRIBE_STATUS__DELETED;*/
|
|
||||||
} else if (newTopicName != NULL) {
|
|
||||||
ASSERT(oldTopicName == NULL);
|
|
||||||
|
|
||||||
SMqTopicObj *pTopic = mndAcquireTopic(pMnode, newTopicName);
|
|
||||||
if (pTopic == NULL) {
|
|
||||||
mError("topic being subscribed not exist: %s", newTopicName);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
SMqSubscribeObj *pSub = mndAcquireSubscribe(pMnode, cgroup, newTopicName);
|
|
||||||
bool createSub = false;
|
|
||||||
if (pSub == NULL) {
|
|
||||||
mDebug("create new subscription by consumer %" PRId64 ", group: %s, topic %s", consumerId, cgroup,
|
|
||||||
newTopicName);
|
|
||||||
pSub = mndCreateSubscription(pMnode, pTopic, cgroup);
|
|
||||||
createSub = true;
|
|
||||||
|
|
||||||
mndCreateOffset(pTrans, cgroup, newTopicName, pSub->unassignedVg);
|
|
||||||
}
|
|
||||||
|
|
||||||
SMqSubConsumer mqSubConsumer;
|
|
||||||
mqSubConsumer.consumerId = consumerId;
|
|
||||||
mqSubConsumer.vgInfo = taosArrayInit(0, sizeof(SMqConsumerEp));
|
|
||||||
taosArrayPush(pSub->consumers, &mqSubConsumer);
|
|
||||||
|
|
||||||
// if have un assigned vg, assign one to the consumer
|
|
||||||
if (taosArrayGetSize(pSub->unassignedVg) > 0) {
|
|
||||||
SMqConsumerEp *pConsumerEp = taosArrayPop(pSub->unassignedVg);
|
|
||||||
pConsumerEp->oldConsumerId = pConsumerEp->consumerId;
|
|
||||||
pConsumerEp->consumerId = consumerId;
|
|
||||||
taosArrayPush(mqSubConsumer.vgInfo, pConsumerEp);
|
|
||||||
if (pConsumerEp->oldConsumerId == -1) {
|
|
||||||
mInfo("mq set conn: assign vgroup %d of topic %s to consumer %" PRId64 "", pConsumerEp->vgId, newTopicName,
|
|
||||||
pConsumerEp->consumerId);
|
|
||||||
mndPersistMqSetConnReq(pMnode, pTrans, pTopic, cgroup, pConsumerEp);
|
|
||||||
} else {
|
|
||||||
mndPersistRebalanceMsg(pMnode, pTrans, pConsumerEp, newTopicName);
|
|
||||||
}
|
|
||||||
// to trigger rebalance at once, do not set status active
|
|
||||||
/*atomic_store_32(&pConsumer->status, MQ_CONSUMER_STATUS__ACTIVE);*/
|
|
||||||
}
|
|
||||||
|
|
||||||
SSdbRaw *pRaw = mndSubActionEncode(pSub);
|
|
||||||
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
|
||||||
mndTransAppendRedolog(pTrans, pRaw);
|
|
||||||
|
|
||||||
if (!createSub) mndReleaseSubscribe(pMnode, pSub);
|
|
||||||
mndReleaseTopic(pMnode, pTopic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*if (oldSub) taosArrayDestroyEx(oldSub, (void (*)(void *))taosMemoryFree);*/
|
|
||||||
|
|
||||||
// persist consumerObj
|
|
||||||
SSdbRaw *pConsumerRaw = mndConsumerActionEncode(pConsumer);
|
|
||||||
sdbSetRawStatus(pConsumerRaw, SDB_STATUS_READY);
|
|
||||||
mndTransAppendRedolog(pTrans, pConsumerRaw);
|
|
||||||
|
|
||||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
|
||||||
mError("mq-subscribe-trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
|
||||||
mndTransDrop(pTrans);
|
|
||||||
if (!createConsumer) mndReleaseConsumer(pMnode, pConsumer);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
mndTransDrop(pTrans);
|
|
||||||
if (!createConsumer) mndReleaseConsumer(pMnode, pConsumer);
|
|
||||||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int32_t mndProcessSubscribeInternalRsp(SNodeMsg *pRsp) {
|
static int32_t mndProcessSubscribeInternalRsp(SNodeMsg *pRsp) {
|
||||||
mndTransProcessRsp(pRsp);
|
mndTransProcessRsp(pRsp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mndCancelGetNextConsumer(SMnode *pMnode, void *pIter) {
|
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
|
||||||
sdbCancelFetch(pSdb, pIter);
|
|
||||||
}
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ static int32_t mndRestoreWal(SMnode *pMnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mTrace("wal:%" PRId64 ", will be restored, content:%p", ver, pHead->head.body);
|
mTrace("wal:%" PRId64 ", will be restored, content:%p", ver, pHead->head.body);
|
||||||
if (sdbWriteNotFree(pSdb, (void *)pHead->head.body) < 0) {
|
if (sdbWriteWithoutFree(pSdb, (void *)pHead->head.body) < 0) {
|
||||||
mError("failed to read wal from sdb since %s, ver:%" PRId64, terrstr(), ver);
|
mError("failed to read wal from sdb since %s, ver:%" PRId64, terrstr(), ver);
|
||||||
goto WAL_RESTORE_OVER;
|
goto WAL_RESTORE_OVER;
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,6 @@ SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) {
|
||||||
SDB_SET_INT8(pRaw, dataPos, pTopic->withTbName, TOPIC_ENCODE_OVER);
|
SDB_SET_INT8(pRaw, dataPos, pTopic->withTbName, TOPIC_ENCODE_OVER);
|
||||||
SDB_SET_INT8(pRaw, dataPos, pTopic->withSchema, TOPIC_ENCODE_OVER);
|
SDB_SET_INT8(pRaw, dataPos, pTopic->withSchema, TOPIC_ENCODE_OVER);
|
||||||
SDB_SET_INT8(pRaw, dataPos, pTopic->withTag, TOPIC_ENCODE_OVER);
|
SDB_SET_INT8(pRaw, dataPos, pTopic->withTag, TOPIC_ENCODE_OVER);
|
||||||
SDB_SET_INT8(pRaw, dataPos, pTopic->withTagSchema, TOPIC_ENCODE_OVER);
|
|
||||||
SDB_SET_INT32(pRaw, dataPos, pTopic->sqlLen, TOPIC_ENCODE_OVER);
|
SDB_SET_INT32(pRaw, dataPos, pTopic->sqlLen, TOPIC_ENCODE_OVER);
|
||||||
SDB_SET_BINARY(pRaw, dataPos, pTopic->sql, pTopic->sqlLen, TOPIC_ENCODE_OVER);
|
SDB_SET_BINARY(pRaw, dataPos, pTopic->sql, pTopic->sqlLen, TOPIC_ENCODE_OVER);
|
||||||
SDB_SET_INT32(pRaw, dataPos, pTopic->astLen, TOPIC_ENCODE_OVER);
|
SDB_SET_INT32(pRaw, dataPos, pTopic->astLen, TOPIC_ENCODE_OVER);
|
||||||
|
@ -146,7 +145,6 @@ SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) {
|
||||||
SDB_GET_INT8(pRaw, dataPos, &pTopic->withTbName, TOPIC_DECODE_OVER);
|
SDB_GET_INT8(pRaw, dataPos, &pTopic->withTbName, TOPIC_DECODE_OVER);
|
||||||
SDB_GET_INT8(pRaw, dataPos, &pTopic->withSchema, TOPIC_DECODE_OVER);
|
SDB_GET_INT8(pRaw, dataPos, &pTopic->withSchema, TOPIC_DECODE_OVER);
|
||||||
SDB_GET_INT8(pRaw, dataPos, &pTopic->withTag, TOPIC_DECODE_OVER);
|
SDB_GET_INT8(pRaw, dataPos, &pTopic->withTag, TOPIC_DECODE_OVER);
|
||||||
SDB_GET_INT8(pRaw, dataPos, &pTopic->withTagSchema, TOPIC_DECODE_OVER);
|
|
||||||
|
|
||||||
SDB_GET_INT32(pRaw, dataPos, &pTopic->sqlLen, TOPIC_DECODE_OVER);
|
SDB_GET_INT32(pRaw, dataPos, &pTopic->sqlLen, TOPIC_DECODE_OVER);
|
||||||
pTopic->sql = taosMemoryCalloc(pTopic->sqlLen, sizeof(char));
|
pTopic->sql = taosMemoryCalloc(pTopic->sqlLen, sizeof(char));
|
||||||
|
@ -234,6 +232,7 @@ void mndReleaseTopic(SMnode *pMnode, SMqTopicObj *pTopic) {
|
||||||
sdbRelease(pSdb, pTopic);
|
sdbRelease(pSdb, pTopic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
static SDbObj *mndAcquireDbByTopic(SMnode *pMnode, char *topicName) {
|
static SDbObj *mndAcquireDbByTopic(SMnode *pMnode, char *topicName) {
|
||||||
SName name = {0};
|
SName name = {0};
|
||||||
tNameFromString(&name, topicName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
tNameFromString(&name, topicName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||||
|
@ -243,6 +242,7 @@ static SDbObj *mndAcquireDbByTopic(SMnode *pMnode, char *topicName) {
|
||||||
|
|
||||||
return mndAcquireDb(pMnode, db);
|
return mndAcquireDb(pMnode, db);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static SDDropTopicReq *mndBuildDropTopicMsg(SMnode *pMnode, SVgObj *pVgroup, SMqTopicObj *pTopic) {
|
static SDDropTopicReq *mndBuildDropTopicMsg(SMnode *pMnode, SVgObj *pVgroup, SMqTopicObj *pTopic) {
|
||||||
int32_t contLen = sizeof(SDDropTopicReq);
|
int32_t contLen = sizeof(SDDropTopicReq);
|
||||||
|
@ -262,15 +262,11 @@ static SDDropTopicReq *mndBuildDropTopicMsg(SMnode *pMnode, SVgObj *pVgroup, SMq
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndCheckCreateTopicReq(SCMCreateTopicReq *pCreate) {
|
static int32_t mndCheckCreateTopicReq(SCMCreateTopicReq *pCreate) {
|
||||||
if (pCreate->name[0] == 0 || pCreate->sql == NULL || pCreate->sql[0] == 0) {
|
if (pCreate->name[0] == 0 || pCreate->sql == NULL || pCreate->sql[0] == 0 || pCreate->subscribeDbName[0] == 0) {
|
||||||
terrno = TSDB_CODE_MND_INVALID_TOPIC_OPTION;
|
terrno = TSDB_CODE_MND_INVALID_TOPIC_OPTION;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pCreate->ast == NULL || pCreate->ast[0] == 0) && pCreate->subscribeDbName[0] == 0) {
|
|
||||||
terrno = TSDB_CODE_MND_INVALID_TOPIC_OPTION;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,10 +282,10 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq
|
||||||
topicObj.version = 1;
|
topicObj.version = 1;
|
||||||
topicObj.sql = strdup(pCreate->sql);
|
topicObj.sql = strdup(pCreate->sql);
|
||||||
topicObj.sqlLen = strlen(pCreate->sql) + 1;
|
topicObj.sqlLen = strlen(pCreate->sql) + 1;
|
||||||
topicObj.ast = strdup(pCreate->ast);
|
|
||||||
topicObj.astLen = strlen(pCreate->ast) + 1;
|
|
||||||
|
|
||||||
if (pCreate->ast && pCreate->ast[0]) {
|
if (pCreate->ast && pCreate->ast[0]) {
|
||||||
|
topicObj.ast = strdup(pCreate->ast);
|
||||||
|
topicObj.astLen = strlen(pCreate->ast) + 1;
|
||||||
topicObj.subType = TOPIC_SUB_TYPE__TABLE;
|
topicObj.subType = TOPIC_SUB_TYPE__TABLE;
|
||||||
topicObj.withTbName = 0;
|
topicObj.withTbName = 0;
|
||||||
topicObj.withSchema = 0;
|
topicObj.withSchema = 0;
|
||||||
|
@ -318,6 +314,9 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
topicObj.ast = strdup("");
|
||||||
|
topicObj.astLen = 1;
|
||||||
|
topicObj.physicalPlan = strdup("");
|
||||||
topicObj.subType = TOPIC_SUB_TYPE__DB;
|
topicObj.subType = TOPIC_SUB_TYPE__DB;
|
||||||
topicObj.withTbName = 1;
|
topicObj.withTbName = 1;
|
||||||
topicObj.withSchema = 1;
|
topicObj.withSchema = 1;
|
||||||
|
@ -386,7 +385,7 @@ static int32_t mndProcessCreateTopicReq(SNodeMsg *pReq) {
|
||||||
goto CREATE_TOPIC_OVER;
|
goto CREATE_TOPIC_OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
pDb = mndAcquireDbByTopic(pMnode, createTopicReq.name);
|
pDb = mndAcquireDb(pMnode, createTopicReq.subscribeDbName);
|
||||||
if (pDb == NULL) {
|
if (pDb == NULL) {
|
||||||
terrno = TSDB_CODE_MND_DB_NOT_SELECTED;
|
terrno = TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||||
goto CREATE_TOPIC_OVER;
|
goto CREATE_TOPIC_OVER;
|
||||||
|
@ -524,8 +523,11 @@ static int32_t mndRetrieveTopic(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pB
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
|
|
||||||
char topicName[TSDB_TOPIC_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
char topicName[TSDB_TOPIC_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||||
tstrncpy(&topicName[VARSTR_HEADER_SIZE], pTopic->name, TSDB_TOPIC_NAME_LEN);
|
|
||||||
varDataSetLen(topicName, strlen(&topicName[VARSTR_HEADER_SIZE]));
|
SName n;
|
||||||
|
tNameFromString(&n, pTopic->name, T_NAME_ACCT|T_NAME_DB);
|
||||||
|
tNameGetDbName(&n, varDataVal(topicName));
|
||||||
|
varDataSetLen(topicName, strlen(varDataVal(topicName)));
|
||||||
|
|
||||||
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
colDataAppend(pColInfo, numOfRows, (const char *)topicName, false);
|
colDataAppend(pColInfo, numOfRows, (const char *)topicName, false);
|
||||||
|
@ -539,7 +541,7 @@ static int32_t mndRetrieveTopic(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pB
|
||||||
varDataSetLen(sql, strlen(&sql[VARSTR_HEADER_SIZE]));
|
varDataSetLen(sql, strlen(&sql[VARSTR_HEADER_SIZE]));
|
||||||
colDataAppend(pColInfo, numOfRows, (const char *)sql, false);
|
colDataAppend(pColInfo, numOfRows, (const char *)sql, false);
|
||||||
|
|
||||||
taosMemoryFree(sql);
|
// taosMemoryFree(sql);
|
||||||
|
|
||||||
numOfRows++;
|
numOfRows++;
|
||||||
sdbRelease(pSdb, pTopic);
|
sdbRelease(pSdb, pTopic);
|
||||||
|
|
|
@ -193,9 +193,9 @@ TRANS_ENCODE_OVER:
|
||||||
static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
|
static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
SSdbRow * pRow = NULL;
|
SSdbRow *pRow = NULL;
|
||||||
STrans * pTrans = NULL;
|
STrans *pTrans = NULL;
|
||||||
char * pData = NULL;
|
char *pData = NULL;
|
||||||
int32_t dataLen = 0;
|
int32_t dataLen = 0;
|
||||||
int8_t sver = 0;
|
int8_t sver = 0;
|
||||||
int32_t redoLogNum = 0;
|
int32_t redoLogNum = 0;
|
||||||
|
@ -456,7 +456,7 @@ static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pOld, STrans *pNew) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static STrans *mndAcquireTrans(SMnode *pMnode, int32_t transId) {
|
static STrans *mndAcquireTrans(SMnode *pMnode, int32_t transId) {
|
||||||
SSdb * pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
STrans *pTrans = sdbAcquire(pSdb, SDB_TRANS, &transId);
|
STrans *pTrans = sdbAcquire(pSdb, SDB_TRANS, &transId);
|
||||||
if (pTrans == NULL) {
|
if (pTrans == NULL) {
|
||||||
terrno = TSDB_CODE_MND_TRANS_NOT_EXIST;
|
terrno = TSDB_CODE_MND_TRANS_NOT_EXIST;
|
||||||
|
@ -574,6 +574,11 @@ void mndTransSetRpcRsp(STrans *pTrans, void *pCont, int32_t contLen) {
|
||||||
pTrans->rpcRspLen = contLen;
|
pTrans->rpcRspLen = contLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mndTransSetCb(STrans *pTrans, TransCbFp fp, void *param) {
|
||||||
|
pTrans->transCbFp = fp;
|
||||||
|
pTrans->transCbParam = param;
|
||||||
|
}
|
||||||
|
|
||||||
void mndTransSetDbInfo(STrans *pTrans, SDbObj *pDb) {
|
void mndTransSetDbInfo(STrans *pTrans, SDbObj *pDb) {
|
||||||
pTrans->dbUid = pDb->uid;
|
pTrans->dbUid = pDb->uid;
|
||||||
memcpy(pTrans->dbname, pDb->name, TSDB_DB_FNAME_LEN);
|
memcpy(pTrans->dbname, pDb->name, TSDB_DB_FNAME_LEN);
|
||||||
|
@ -626,7 +631,7 @@ static int32_t mndCheckTransCanBeStartedInParallel(SMnode *pMnode, STrans *pNewT
|
||||||
if (mndIsBasicTrans(pNewTrans)) return 0;
|
if (mndIsBasicTrans(pNewTrans)) return 0;
|
||||||
|
|
||||||
STrans *pTrans = NULL;
|
STrans *pTrans = NULL;
|
||||||
void * pIter = NULL;
|
void *pIter = NULL;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -707,6 +712,8 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) {
|
||||||
pNew->rpcRefId = pTrans->rpcRefId;
|
pNew->rpcRefId = pTrans->rpcRefId;
|
||||||
pNew->rpcRsp = pTrans->rpcRsp;
|
pNew->rpcRsp = pTrans->rpcRsp;
|
||||||
pNew->rpcRspLen = pTrans->rpcRspLen;
|
pNew->rpcRspLen = pTrans->rpcRspLen;
|
||||||
|
pNew->transCbFp = pTrans->transCbFp;
|
||||||
|
pNew->transCbParam = pTrans->transCbParam;
|
||||||
pTrans->rpcRsp = NULL;
|
pTrans->rpcRsp = NULL;
|
||||||
pTrans->rpcRspLen = 0;
|
pTrans->rpcRspLen = 0;
|
||||||
|
|
||||||
|
@ -830,14 +837,14 @@ HANDLE_ACTION_RSP_OVER:
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndTransExecuteLogs(SMnode *pMnode, SArray *pArray) {
|
static int32_t mndTransExecuteLogs(SMnode *pMnode, SArray *pArray) {
|
||||||
SSdb * pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
int32_t arraySize = taosArrayGetSize(pArray);
|
int32_t arraySize = taosArrayGetSize(pArray);
|
||||||
|
|
||||||
if (arraySize == 0) return 0;
|
if (arraySize == 0) return 0;
|
||||||
|
|
||||||
for (int32_t i = 0; i < arraySize; ++i) {
|
for (int32_t i = 0; i < arraySize; ++i) {
|
||||||
SSdbRaw *pRaw = taosArrayGetP(pArray, i);
|
SSdbRaw *pRaw = taosArrayGetP(pArray, i);
|
||||||
int32_t code = sdbWriteNotFree(pSdb, pRaw);
|
int32_t code = sdbWriteWithoutFree(pSdb, pRaw);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -1117,6 +1124,11 @@ static bool mndTransPerfromFinishedStage(SMnode *pMnode, STrans *pTrans) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mDebug("trans:%d, finished, code:0x%04x, failedTimes:%d", pTrans->id, pTrans->code, pTrans->failedTimes);
|
mDebug("trans:%d, finished, code:0x%04x, failedTimes:%d", pTrans->id, pTrans->code, pTrans->failedTimes);
|
||||||
|
|
||||||
|
if (pTrans->transCbFp != NULL) {
|
||||||
|
(*pTrans->transCbFp)(pMnode, pTrans->transCbParam);
|
||||||
|
}
|
||||||
|
|
||||||
return continueExec;
|
return continueExec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1205,11 +1217,11 @@ static int32_t mndKillTrans(SMnode *pMnode, STrans *pTrans) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessKillTransReq(SNodeMsg *pReq) {
|
static int32_t mndProcessKillTransReq(SNodeMsg *pReq) {
|
||||||
SMnode * pMnode = pReq->pNode;
|
SMnode *pMnode = pReq->pNode;
|
||||||
SKillTransReq killReq = {0};
|
SKillTransReq killReq = {0};
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
SUserObj * pUser = NULL;
|
SUserObj *pUser = NULL;
|
||||||
STrans * pTrans = NULL;
|
STrans *pTrans = NULL;
|
||||||
|
|
||||||
if (tDeserializeSKillTransReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &killReq) != 0) {
|
if (tDeserializeSKillTransReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &killReq) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
terrno = TSDB_CODE_INVALID_MSG;
|
||||||
|
@ -1249,7 +1261,7 @@ KILL_OVER:
|
||||||
|
|
||||||
void mndTransPullup(SMnode *pMnode) {
|
void mndTransPullup(SMnode *pMnode) {
|
||||||
STrans *pTrans = NULL;
|
STrans *pTrans = NULL;
|
||||||
void * pIter = NULL;
|
void *pIter = NULL;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
pIter = sdbFetch(pMnode->pSdb, SDB_TRANS, pIter, (void **)&pTrans);
|
pIter = sdbFetch(pMnode->pSdb, SDB_TRANS, pIter, (void **)&pTrans);
|
||||||
|
@ -1264,11 +1276,11 @@ void mndTransPullup(SMnode *pMnode) {
|
||||||
|
|
||||||
static int32_t mndRetrieveTrans(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
static int32_t mndRetrieveTrans(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||||
SMnode *pMnode = pReq->pNode;
|
SMnode *pMnode = pReq->pNode;
|
||||||
SSdb * pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
int32_t numOfRows = 0;
|
int32_t numOfRows = 0;
|
||||||
STrans *pTrans = NULL;
|
STrans *pTrans = NULL;
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
char * pWrite;
|
char *pWrite;
|
||||||
|
|
||||||
while (numOfRows < rows) {
|
while (numOfRows < rows) {
|
||||||
pShow->pIter = sdbFetch(pSdb, SDB_TRANS, pShow->pIter, (void **)&pTrans);
|
pShow->pIter = sdbFetch(pSdb, SDB_TRANS, pShow->pIter, (void **)&pTrans);
|
||||||
|
|
|
@ -368,7 +368,7 @@ int32_t mndProcessMsg(SNodeMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isReq && (pRpc->contLen == 0 || pRpc->pCont == NULL)) {
|
if (isReq && (pRpc->contLen == 0 || pRpc->pCont == NULL)) {
|
||||||
terrno = TSDB_CODE_MND_INVALID_MSG_LEN;
|
terrno = TSDB_CODE_INVALID_MSG_LEN;
|
||||||
mError("msg:%p, failed to process since %s, app:%p", pMsg, terrstr(), ahandle);
|
mError("msg:%p, failed to process since %s, app:%p", pMsg, terrstr(), ahandle);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ TEST_F(MndTestAcct, 01_Create_Acct) {
|
||||||
|
|
||||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_ACCT, pReq, contLen);
|
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_ACCT, pReq, contLen);
|
||||||
ASSERT_NE(pRsp, nullptr);
|
ASSERT_NE(pRsp, nullptr);
|
||||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MSG_NOT_PROCESSED);
|
ASSERT_EQ(pRsp->code, TSDB_CODE_MSG_NOT_PROCESSED);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MndTestAcct, 02_Alter_Acct) {
|
TEST_F(MndTestAcct, 02_Alter_Acct) {
|
||||||
|
@ -42,7 +42,7 @@ TEST_F(MndTestAcct, 02_Alter_Acct) {
|
||||||
|
|
||||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_ACCT, pReq, contLen);
|
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_ACCT, pReq, contLen);
|
||||||
ASSERT_NE(pRsp, nullptr);
|
ASSERT_NE(pRsp, nullptr);
|
||||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MSG_NOT_PROCESSED);
|
ASSERT_EQ(pRsp->code, TSDB_CODE_MSG_NOT_PROCESSED);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MndTestAcct, 03_Drop_Acct) {
|
TEST_F(MndTestAcct, 03_Drop_Acct) {
|
||||||
|
@ -52,5 +52,5 @@ TEST_F(MndTestAcct, 03_Drop_Acct) {
|
||||||
|
|
||||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_ACCT, pReq, contLen);
|
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_ACCT, pReq, contLen);
|
||||||
ASSERT_NE(pRsp, nullptr);
|
ASSERT_NE(pRsp, nullptr);
|
||||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MSG_NOT_PROCESSED);
|
ASSERT_EQ(pRsp->code, TSDB_CODE_MSG_NOT_PROCESSED);
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,6 @@ TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) {
|
||||||
void* pReq = rpcMallocCont(contLen);
|
void* pReq = rpcMallocCont(contLen);
|
||||||
tSerializeSAlterDbReq(pReq, contLen, &alterdbReq);
|
tSerializeSAlterDbReq(pReq, contLen, &alterdbReq);
|
||||||
|
|
||||||
taosMsleep(1000); // Wait for the vnode to become the leader
|
|
||||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_DB, pReq, contLen);
|
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_DB, pReq, contLen);
|
||||||
ASSERT_NE(pRsp, nullptr);
|
ASSERT_NE(pRsp, nullptr);
|
||||||
ASSERT_EQ(pRsp->code, 0);
|
ASSERT_EQ(pRsp->code, 0);
|
||||||
|
|
|
@ -258,7 +258,6 @@ TEST_F(MndTestSma, 02_Create_Show_Meta_Drop_Restart_BSma) {
|
||||||
pReq = BuildCreateDbReq(dbname, &contLen);
|
pReq = BuildCreateDbReq(dbname, &contLen);
|
||||||
pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||||
ASSERT_EQ(pRsp->code, 0);
|
ASSERT_EQ(pRsp->code, 0);
|
||||||
taosMsleep(1000); // Wait for the vnode to become the leader
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -304,7 +304,6 @@ TEST_F(MndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
||||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||||
ASSERT_NE(pRsp, nullptr);
|
ASSERT_NE(pRsp, nullptr);
|
||||||
ASSERT_EQ(pRsp->code, 0);
|
ASSERT_EQ(pRsp->code, 0);
|
||||||
taosMsleep(2000); // Wait for the vnode to become the leader
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -439,7 +438,6 @@ TEST_F(MndTestStb, 02_Alter_Stb_AddTag) {
|
||||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||||
ASSERT_NE(pRsp, nullptr);
|
ASSERT_NE(pRsp, nullptr);
|
||||||
ASSERT_EQ(pRsp->code, 0);
|
ASSERT_EQ(pRsp->code, 0);
|
||||||
taosMsleep(2000); // Wait for the vnode to become the leader
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -499,7 +497,6 @@ TEST_F(MndTestStb, 03_Alter_Stb_DropTag) {
|
||||||
void* pReq = BuildCreateDbReq(dbname, &contLen);
|
void* pReq = BuildCreateDbReq(dbname, &contLen);
|
||||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||||
ASSERT_EQ(pRsp->code, 0);
|
ASSERT_EQ(pRsp->code, 0);
|
||||||
taosMsleep(2000); // Wait for the vnode to become the leader
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -541,7 +538,6 @@ TEST_F(MndTestStb, 04_Alter_Stb_AlterTagName) {
|
||||||
void* pReq = BuildCreateDbReq(dbname, &contLen);
|
void* pReq = BuildCreateDbReq(dbname, &contLen);
|
||||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||||
ASSERT_EQ(pRsp->code, 0);
|
ASSERT_EQ(pRsp->code, 0);
|
||||||
taosMsleep(2000); // Wait for the vnode to become the leader
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -606,7 +602,6 @@ TEST_F(MndTestStb, 05_Alter_Stb_AlterTagBytes) {
|
||||||
void* pReq = BuildCreateDbReq(dbname, &contLen);
|
void* pReq = BuildCreateDbReq(dbname, &contLen);
|
||||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||||
ASSERT_EQ(pRsp->code, 0);
|
ASSERT_EQ(pRsp->code, 0);
|
||||||
taosMsleep(2000); // Wait for the vnode to become the leader
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -660,7 +655,6 @@ TEST_F(MndTestStb, 06_Alter_Stb_AddColumn) {
|
||||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||||
ASSERT_NE(pRsp, nullptr);
|
ASSERT_NE(pRsp, nullptr);
|
||||||
ASSERT_EQ(pRsp->code, 0);
|
ASSERT_EQ(pRsp->code, 0);
|
||||||
taosMsleep(2000); // Wait for the vnode to become the leader
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -721,7 +715,6 @@ TEST_F(MndTestStb, 07_Alter_Stb_DropColumn) {
|
||||||
void* pReq = BuildCreateDbReq(dbname, &contLen);
|
void* pReq = BuildCreateDbReq(dbname, &contLen);
|
||||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||||
ASSERT_EQ(pRsp->code, 0);
|
ASSERT_EQ(pRsp->code, 0);
|
||||||
taosMsleep(2000); // Wait for the vnode to become the leader
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -782,7 +775,6 @@ TEST_F(MndTestStb, 08_Alter_Stb_AlterTagBytes) {
|
||||||
void* pReq = BuildCreateDbReq(dbname, &contLen);
|
void* pReq = BuildCreateDbReq(dbname, &contLen);
|
||||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||||
ASSERT_EQ(pRsp->code, 0);
|
ASSERT_EQ(pRsp->code, 0);
|
||||||
taosMsleep(2000); // Wait for the vnode to become the leader
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -202,7 +202,7 @@ int32_t sdbReadFile(SSdb *pSdb) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = sdbWriteNotFree(pSdb, pRaw);
|
code = sdbWriteWithoutFree(pSdb, pRaw);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
mError("failed to read file:%s since %s", file, terrstr());
|
mError("failed to read file:%s since %s", file, terrstr());
|
||||||
goto PARSE_SDB_DATA_ERROR;
|
goto PARSE_SDB_DATA_ERROR;
|
||||||
|
@ -263,7 +263,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
sdbPrintOper(pSdb, pRow, "writeFile");
|
sdbPrintOper(pSdb, pRow, "write");
|
||||||
|
|
||||||
SSdbRaw *pRaw = (*encodeFp)(pRow->pObj);
|
SSdbRaw *pRaw = (*encodeFp)(pRow->pObj);
|
||||||
if (pRaw != NULL) {
|
if (pRaw != NULL) {
|
||||||
|
|
|
@ -51,7 +51,9 @@ const char *sdbTableName(ESdbType type) {
|
||||||
case SDB_TOPIC:
|
case SDB_TOPIC:
|
||||||
return "topic";
|
return "topic";
|
||||||
case SDB_VGROUP:
|
case SDB_VGROUP:
|
||||||
return "vgId";
|
return "vgroup";
|
||||||
|
case SDB_SMA:
|
||||||
|
return "sma";
|
||||||
case SDB_STB:
|
case SDB_STB:
|
||||||
return "stb";
|
return "stb";
|
||||||
case SDB_DB:
|
case SDB_DB:
|
||||||
|
@ -86,13 +88,13 @@ void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper) {
|
||||||
EKeyType keyType = pSdb->keyTypes[pRow->type];
|
EKeyType keyType = pSdb->keyTypes[pRow->type];
|
||||||
|
|
||||||
if (keyType == SDB_KEY_BINARY) {
|
if (keyType == SDB_KEY_BINARY) {
|
||||||
mTrace("%s:%s, refCount:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), (char *)pRow->pObj, pRow->refCount,
|
mTrace("%s:%s, ref:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), (char *)pRow->pObj, pRow->refCount, oper,
|
||||||
oper, pRow->pObj, sdbStatusStr(pRow->status));
|
pRow->pObj, sdbStatusStr(pRow->status));
|
||||||
} else if (keyType == SDB_KEY_INT32) {
|
} else if (keyType == SDB_KEY_INT32) {
|
||||||
mTrace("%s:%d, refCount:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), *(int32_t *)pRow->pObj,
|
mTrace("%s:%d, ref:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), *(int32_t *)pRow->pObj, pRow->refCount,
|
||||||
pRow->refCount, oper, pRow->pObj, sdbStatusStr(pRow->status));
|
oper, pRow->pObj, sdbStatusStr(pRow->status));
|
||||||
} else if (keyType == SDB_KEY_INT64) {
|
} else if (keyType == SDB_KEY_INT64) {
|
||||||
mTrace("%s:%" PRId64 ", refCount:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), *(int64_t *)pRow->pObj,
|
mTrace("%s:%" PRId64 ", ref:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), *(int64_t *)pRow->pObj,
|
||||||
pRow->refCount, oper, pRow->pObj, sdbStatusStr(pRow->status));
|
pRow->refCount, oper, pRow->pObj, sdbStatusStr(pRow->status));
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
|
@ -142,7 +144,7 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
|
||||||
|
|
||||||
pRow->refCount = 0;
|
pRow->refCount = 0;
|
||||||
pRow->status = pRaw->status;
|
pRow->status = pRaw->status;
|
||||||
sdbPrintOper(pSdb, pRow, "insertRow");
|
sdbPrintOper(pSdb, pRow, "insert");
|
||||||
|
|
||||||
if (taosHashPut(hash, pRow->pObj, keySize, &pRow, sizeof(void *)) != 0) {
|
if (taosHashPut(hash, pRow->pObj, keySize, &pRow, sizeof(void *)) != 0) {
|
||||||
taosWUnLockLatch(pLock);
|
taosWUnLockLatch(pLock);
|
||||||
|
@ -191,7 +193,7 @@ static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
|
||||||
|
|
||||||
SSdbRow *pOldRow = *ppOldRow;
|
SSdbRow *pOldRow = *ppOldRow;
|
||||||
pOldRow->status = pRaw->status;
|
pOldRow->status = pRaw->status;
|
||||||
sdbPrintOper(pSdb, pOldRow, "updateRow");
|
sdbPrintOper(pSdb, pOldRow, "update");
|
||||||
taosRUnLockLatch(pLock);
|
taosRUnLockLatch(pLock);
|
||||||
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
@ -220,7 +222,7 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
|
||||||
SSdbRow *pOldRow = *ppOldRow;
|
SSdbRow *pOldRow = *ppOldRow;
|
||||||
|
|
||||||
pOldRow->status = pRaw->status;
|
pOldRow->status = pRaw->status;
|
||||||
sdbPrintOper(pSdb, pOldRow, "deleteRow");
|
sdbPrintOper(pSdb, pOldRow, "delete");
|
||||||
|
|
||||||
taosHashRemove(hash, pOldRow->pObj, keySize);
|
taosHashRemove(hash, pOldRow->pObj, keySize);
|
||||||
taosWUnLockLatch(pLock);
|
taosWUnLockLatch(pLock);
|
||||||
|
@ -233,7 +235,7 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbWriteNotFree(SSdb *pSdb, SSdbRaw *pRaw) {
|
int32_t sdbWriteWithoutFree(SSdb *pSdb, SSdbRaw *pRaw) {
|
||||||
SHashObj *hash = sdbGetHash(pSdb, pRaw->type);
|
SHashObj *hash = sdbGetHash(pSdb, pRaw->type);
|
||||||
if (hash == NULL) return terrno;
|
if (hash == NULL) return terrno;
|
||||||
|
|
||||||
|
@ -266,7 +268,7 @@ int32_t sdbWriteNotFree(SSdb *pSdb, SSdbRaw *pRaw) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbWrite(SSdb *pSdb, SSdbRaw *pRaw) {
|
int32_t sdbWrite(SSdb *pSdb, SSdbRaw *pRaw) {
|
||||||
int32_t code = sdbWriteNotFree(pSdb, pRaw);
|
int32_t code = sdbWriteWithoutFree(pSdb, pRaw);
|
||||||
sdbFreeRaw(pRaw);
|
sdbFreeRaw(pRaw);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -296,7 +298,7 @@ void *sdbAcquire(SSdb *pSdb, ESdbType type, const void *pKey) {
|
||||||
case SDB_STATUS_UPDATING:
|
case SDB_STATUS_UPDATING:
|
||||||
atomic_add_fetch_32(&pRow->refCount, 1);
|
atomic_add_fetch_32(&pRow->refCount, 1);
|
||||||
pRet = pRow->pObj;
|
pRet = pRow->pObj;
|
||||||
sdbPrintOper(pSdb, pRow, "acquireRow");
|
sdbPrintOper(pSdb, pRow, "acquire");
|
||||||
break;
|
break;
|
||||||
case SDB_STATUS_CREATING:
|
case SDB_STATUS_CREATING:
|
||||||
terrno = TSDB_CODE_SDB_OBJ_CREATING;
|
terrno = TSDB_CODE_SDB_OBJ_CREATING;
|
||||||
|
@ -318,7 +320,7 @@ static void sdbCheck(SSdb *pSdb, SSdbRow *pRow) {
|
||||||
taosRLockLatch(pLock);
|
taosRLockLatch(pLock);
|
||||||
|
|
||||||
int32_t ref = atomic_load_32(&pRow->refCount);
|
int32_t ref = atomic_load_32(&pRow->refCount);
|
||||||
sdbPrintOper(pSdb, pRow, "checkRow");
|
sdbPrintOper(pSdb, pRow, "check");
|
||||||
if (ref <= 0 && pRow->status == SDB_STATUS_DROPPED) {
|
if (ref <= 0 && pRow->status == SDB_STATUS_DROPPED) {
|
||||||
sdbFreeRow(pSdb, pRow);
|
sdbFreeRow(pSdb, pRow);
|
||||||
}
|
}
|
||||||
|
@ -330,13 +332,13 @@ void sdbRelease(SSdb *pSdb, void *pObj) {
|
||||||
if (pObj == NULL) return;
|
if (pObj == NULL) return;
|
||||||
|
|
||||||
SSdbRow *pRow = (SSdbRow *)((char *)pObj - sizeof(SSdbRow));
|
SSdbRow *pRow = (SSdbRow *)((char *)pObj - sizeof(SSdbRow));
|
||||||
if (pRow->type >= SDB_MAX ) return;
|
if (pRow->type >= SDB_MAX) return;
|
||||||
|
|
||||||
SRWLatch *pLock = &pSdb->locks[pRow->type];
|
SRWLatch *pLock = &pSdb->locks[pRow->type];
|
||||||
taosRLockLatch(pLock);
|
taosRLockLatch(pLock);
|
||||||
|
|
||||||
int32_t ref = atomic_sub_fetch_32(&pRow->refCount, 1);
|
int32_t ref = atomic_sub_fetch_32(&pRow->refCount, 1);
|
||||||
sdbPrintOper(pSdb, pRow, "releaseRow");
|
sdbPrintOper(pSdb, pRow, "release");
|
||||||
if (ref <= 0 && pRow->status == SDB_STATUS_DROPPED) {
|
if (ref <= 0 && pRow->status == SDB_STATUS_DROPPED) {
|
||||||
sdbFreeRow(pSdb, pRow);
|
sdbFreeRow(pSdb, pRow);
|
||||||
}
|
}
|
||||||
|
@ -372,7 +374,7 @@ void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
atomic_add_fetch_32(&pRow->refCount, 1);
|
atomic_add_fetch_32(&pRow->refCount, 1);
|
||||||
sdbPrintOper(pSdb, pRow, "fetchRow");
|
sdbPrintOper(pSdb, pRow, "fetch");
|
||||||
*ppObj = pRow->pObj;
|
*ppObj = pRow->pObj;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen) {
|
||||||
pRaw->sver = sver;
|
pRaw->sver = sver;
|
||||||
pRaw->dataLen = dataLen;
|
pRaw->dataLen = dataLen;
|
||||||
|
|
||||||
mTrace("raw:%p, is created, len:%d", pRaw, dataLen);
|
mTrace("raw:%p, is created, len:%d table:%s", pRaw, dataLen, sdbTableName(type));
|
||||||
return pRaw;
|
return pRaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ void sdbFreeRow(SSdb *pSdb, SSdbRow *pRow) {
|
||||||
(*deleteFp)(pSdb, pRow->pObj);
|
(*deleteFp)(pSdb, pRow->pObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
sdbPrintOper(pSdb, pRow, "freeRow");
|
sdbPrintOper(pSdb, pRow, "free");
|
||||||
|
|
||||||
mTrace("row:%p, is freed", pRow->pObj);
|
mTrace("row:%p, is freed", pRow->pObj);
|
||||||
taosMemoryFreeClear(pRow);
|
taosMemoryFreeClear(pRow);
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "qndInt.h"
|
#include "qndInt.h"
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
#include "qworker.h"
|
#include "qworker.h"
|
||||||
|
//#include "tudf.h"
|
||||||
|
|
||||||
SQnode *qndOpen(const SQnodeOpt *pOption) {
|
SQnode *qndOpen(const SQnodeOpt *pOption) {
|
||||||
SQnode *pQnode = taosMemoryCalloc(1, sizeof(SQnode));
|
SQnode *pQnode = taosMemoryCalloc(1, sizeof(SQnode));
|
||||||
|
@ -25,6 +26,8 @@ SQnode *qndOpen(const SQnodeOpt *pOption) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//udfcOpen();
|
||||||
|
|
||||||
if (qWorkerInit(NODE_TYPE_QNODE, pQnode->qndId, NULL, (void **)&pQnode->pQuery, &pOption->msgCb)) {
|
if (qWorkerInit(NODE_TYPE_QNODE, pQnode->qndId, NULL, (void **)&pQnode->pQuery, &pOption->msgCb)) {
|
||||||
taosMemoryFreeClear(pQnode);
|
taosMemoryFreeClear(pQnode);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -37,13 +40,15 @@ SQnode *qndOpen(const SQnodeOpt *pOption) {
|
||||||
void qndClose(SQnode *pQnode) {
|
void qndClose(SQnode *pQnode) {
|
||||||
qWorkerDestroy((void **)&pQnode->pQuery);
|
qWorkerDestroy((void **)&pQnode->pQuery);
|
||||||
|
|
||||||
|
//udfcClose();
|
||||||
|
|
||||||
taosMemoryFree(pQnode);
|
taosMemoryFree(pQnode);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qndGetLoad(SQnode *pQnode, SQnodeLoad *pLoad) { return 0; }
|
int32_t qndGetLoad(SQnode *pQnode, SQnodeLoad *pLoad) { return 0; }
|
||||||
|
|
||||||
int32_t qndProcessQueryMsg(SQnode *pQnode, SRpcMsg *pMsg) {
|
int32_t qndProcessQueryMsg(SQnode *pQnode, SRpcMsg *pMsg) {
|
||||||
qTrace("message in query queue is processing");
|
qTrace("message in qnode query queue is processing");
|
||||||
SReadHandle handle = {0};
|
SReadHandle handle = {0};
|
||||||
|
|
||||||
switch (pMsg->msgType) {
|
switch (pMsg->msgType) {
|
||||||
|
|
|
@ -61,6 +61,9 @@ int32_t vnodeSync(SVnode *pVnode);
|
||||||
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad);
|
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad);
|
||||||
int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName);
|
int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName);
|
||||||
|
|
||||||
|
int32_t vnodeStart(SVnode *pVnode);
|
||||||
|
void vnodeStop(SVnode *pVnode);
|
||||||
|
|
||||||
int64_t vnodeGetSyncHandle(SVnode *pVnode);
|
int64_t vnodeGetSyncHandle(SVnode *pVnode);
|
||||||
void vnodeGetSnapshot(SVnode *pVnode, SSnapshot *pSnapshot);
|
void vnodeGetSnapshot(SVnode *pVnode, SSnapshot *pSnapshot);
|
||||||
|
|
||||||
|
@ -77,16 +80,15 @@ char *metaTbCursorNext(SMTbCursor *pTbCur);
|
||||||
|
|
||||||
// tsdb
|
// tsdb
|
||||||
typedef struct STsdb STsdb;
|
typedef struct STsdb STsdb;
|
||||||
typedef struct STsdbQueryCond STsdbQueryCond;
|
|
||||||
typedef void *tsdbReaderT;
|
typedef void *tsdbReaderT;
|
||||||
|
|
||||||
#define BLOCK_LOAD_OFFSET_SEQ_ORDER 1
|
#define BLOCK_LOAD_OFFSET_SEQ_ORDER 1
|
||||||
#define BLOCK_LOAD_TABLE_SEQ_ORDER 2
|
#define BLOCK_LOAD_TABLE_SEQ_ORDER 2
|
||||||
#define BLOCK_LOAD_TABLE_RR_ORDER 3
|
#define BLOCK_LOAD_TABLE_RR_ORDER 3
|
||||||
|
|
||||||
tsdbReaderT *tsdbQueryTables(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *tableInfoGroup, uint64_t qId,
|
tsdbReaderT *tsdbQueryTables(STsdb *tsdb, SQueryTableDataCond *pCond, STableGroupInfo *tableInfoGroup, uint64_t qId,
|
||||||
uint64_t taskId);
|
uint64_t taskId);
|
||||||
tsdbReaderT tsdbQueryCacheLast(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList, uint64_t qId,
|
tsdbReaderT tsdbQueryCacheLast(STsdb *tsdb, SQueryTableDataCond *pCond, STableGroupInfo *groupList, uint64_t qId,
|
||||||
void *pMemRef);
|
void *pMemRef);
|
||||||
int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT *pReader, STableBlockDistInfo *pTableBlockInfo);
|
int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT *pReader, STableBlockDistInfo *pTableBlockInfo);
|
||||||
bool isTsdbCacheLastRow(tsdbReaderT *pReader);
|
bool isTsdbCacheLastRow(tsdbReaderT *pReader);
|
||||||
|
@ -98,6 +100,7 @@ bool tsdbNextDataBlock(tsdbReaderT pTsdbReadHandle);
|
||||||
void tsdbRetrieveDataBlockInfo(tsdbReaderT *pTsdbReadHandle, SDataBlockInfo *pBlockInfo);
|
void tsdbRetrieveDataBlockInfo(tsdbReaderT *pTsdbReadHandle, SDataBlockInfo *pBlockInfo);
|
||||||
int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT *pTsdbReadHandle, SColumnDataAgg **pBlockStatis);
|
int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT *pTsdbReadHandle, SColumnDataAgg **pBlockStatis);
|
||||||
SArray *tsdbRetrieveDataBlock(tsdbReaderT *pTsdbReadHandle, SArray *pColumnIdList);
|
SArray *tsdbRetrieveDataBlock(tsdbReaderT *pTsdbReadHandle, SArray *pColumnIdList);
|
||||||
|
void tsdbResetReadHandle(tsdbReaderT queryHandle, SQueryTableDataCond* pCond);
|
||||||
void tsdbDestroyTableGroup(STableGroupInfo *pGroupList);
|
void tsdbDestroyTableGroup(STableGroupInfo *pGroupList);
|
||||||
int32_t tsdbGetOneTableGroup(void *pMeta, uint64_t uid, TSKEY startKey, STableGroupInfo *pGroupInfo);
|
int32_t tsdbGetOneTableGroup(void *pMeta, uint64_t uid, TSKEY startKey, STableGroupInfo *pGroupInfo);
|
||||||
int32_t tsdbGetTableGroupFromIdList(STsdb *tsdb, SArray *pTableIdList, STableGroupInfo *pGroupInfo);
|
int32_t tsdbGetTableGroupFromIdList(STsdb *tsdb, SArray *pTableIdList, STableGroupInfo *pGroupInfo);
|
||||||
|
@ -157,25 +160,11 @@ struct SVnodeCfg {
|
||||||
int8_t hashMethod;
|
int8_t hashMethod;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct STsdbQueryCond {
|
|
||||||
STimeWindow twindow;
|
|
||||||
int32_t order; // desc|asc order to iterate the data block
|
|
||||||
int32_t numOfCols;
|
|
||||||
SColumnInfo *colList;
|
|
||||||
bool loadExternalRows; // load external rows or not
|
|
||||||
int32_t type; // data block load type:
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
TSKEY lastKey;
|
TSKEY lastKey;
|
||||||
uint64_t uid;
|
uint64_t uid;
|
||||||
} STableKeyInfo;
|
} STableKeyInfo;
|
||||||
|
|
||||||
// sync integration
|
|
||||||
void vnodeSyncSetQ(SVnode *pVnode, void *qHandle);
|
|
||||||
void vnodeSyncSetRpc(SVnode *pVnode, void *rpcHandle);
|
|
||||||
int32_t vnodeSyncStart(SVnode *pVnode);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -51,7 +51,7 @@ static FORCE_INLINE tb_uid_t metaGenerateUid(SMeta* pMeta) { return tGenIdPI64()
|
||||||
#define META_CHILD_TABLE TD_CHILD_TABLE
|
#define META_CHILD_TABLE TD_CHILD_TABLE
|
||||||
#define META_NORMAL_TABLE TD_NORMAL_TABLE
|
#define META_NORMAL_TABLE TD_NORMAL_TABLE
|
||||||
|
|
||||||
int metaCreateTable(SMeta* pMeta, STbCfg* pTbCfg);
|
int metaCreateTable(SMeta* pMeta, STbCfg* pTbCfg, STbDdlH* pHandle);
|
||||||
int metaDropTable(SMeta* pMeta, tb_uid_t uid);
|
int metaDropTable(SMeta* pMeta, tb_uid_t uid);
|
||||||
int metaCommit(SMeta* pMeta);
|
int metaCommit(SMeta* pMeta);
|
||||||
int32_t metaCreateTSma(SMeta* pMeta, SSmaCfg* pCfg);
|
int32_t metaCreateTSma(SMeta* pMeta, SSmaCfg* pCfg);
|
||||||
|
@ -74,7 +74,7 @@ tb_uid_t metaCtbCursorNext(SMCtbCursor* pCtbCur);
|
||||||
// SMetaDB
|
// SMetaDB
|
||||||
int metaOpenDB(SMeta* pMeta);
|
int metaOpenDB(SMeta* pMeta);
|
||||||
void metaCloseDB(SMeta* pMeta);
|
void metaCloseDB(SMeta* pMeta);
|
||||||
int metaSaveTableToDB(SMeta* pMeta, STbCfg* pTbCfg);
|
int metaSaveTableToDB(SMeta* pMeta, STbCfg* pTbCfg, STbDdlH* pHandle);
|
||||||
int metaRemoveTableFromDb(SMeta* pMeta, tb_uid_t uid);
|
int metaRemoveTableFromDb(SMeta* pMeta, tb_uid_t uid);
|
||||||
int metaSaveSmaToDB(SMeta* pMeta, STSma* pTbCfg);
|
int metaSaveSmaToDB(SMeta* pMeta, STSma* pTbCfg);
|
||||||
int metaRemoveSmaFromDb(SMeta* pMeta, int64_t indexUid);
|
int metaRemoveSmaFromDb(SMeta* pMeta, int64_t indexUid);
|
||||||
|
|
|
@ -159,7 +159,6 @@ typedef struct {
|
||||||
int8_t withTbName;
|
int8_t withTbName;
|
||||||
int8_t withSchema;
|
int8_t withSchema;
|
||||||
int8_t withTag;
|
int8_t withTag;
|
||||||
int8_t withTagSchema;
|
|
||||||
char* qmsg;
|
char* qmsg;
|
||||||
STqPushHandle pushHandle;
|
STqPushHandle pushHandle;
|
||||||
// SRWLatch lock;
|
// SRWLatch lock;
|
||||||
|
|
|
@ -56,8 +56,6 @@ int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg);
|
||||||
int32_t tsdbDropTSmaData(STsdb *pTsdb, int64_t indexUid);
|
int32_t tsdbDropTSmaData(STsdb *pTsdb, int64_t indexUid);
|
||||||
int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg);
|
int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg);
|
||||||
void tsdbCleanupReadHandle(tsdbReaderT queryHandle);
|
void tsdbCleanupReadHandle(tsdbReaderT queryHandle);
|
||||||
int32_t tdScanAndConvertSubmitMsg(SSubmitReq *pMsg);
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TSDB_FILE_HEAD = 0, // .head
|
TSDB_FILE_HEAD = 0, // .head
|
||||||
TSDB_FILE_DATA, // .data
|
TSDB_FILE_DATA, // .data
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _TD_VNODE_TSDB_SMA_H_
|
||||||
|
#define _TD_VNODE_TSDB_SMA_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
#include "thash.h"
|
||||||
|
#include "tmsg.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef int32_t (*__tb_ddl_fn_t)(void *ahandle, void **result, void *p1, void *p2);
|
||||||
|
|
||||||
|
struct STbDdlH {
|
||||||
|
void *ahandle;
|
||||||
|
void *result;
|
||||||
|
__tb_ddl_fn_t fp;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
tb_uid_t suid;
|
||||||
|
SArray *tbUids;
|
||||||
|
SHashObj *uidHash;
|
||||||
|
} STbUidStore;
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tsdbUidStoreInit(STbUidStore **pStore) {
|
||||||
|
ASSERT(*pStore == NULL);
|
||||||
|
*pStore = taosMemoryCalloc(1, sizeof(STbUidStore));
|
||||||
|
if (*pStore == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tsdbUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid);
|
||||||
|
void tsdbUidStoreDestory(STbUidStore *pStore);
|
||||||
|
void *tsdbUidStoreFree(STbUidStore *pStore);
|
||||||
|
|
||||||
|
int32_t tsdbRegisterRSma(STsdb *pTsdb, SMeta *pMeta, SVCreateTbReq *pReq);
|
||||||
|
int32_t tsdbFetchTbUidList(void *pTsdb, void **result, void *suid, void *uid);
|
||||||
|
int32_t tsdbUpdateTbUidList(STsdb *pTsdb, STbUidStore *pUidStore);
|
||||||
|
int32_t tsdbTriggerRSma(STsdb *pTsdb, SMeta *pMeta, void *pMsg, int32_t inputType);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*_TD_VNODE_TSDB_SMA_H_*/
|
|
@ -103,6 +103,8 @@ struct SVnode {
|
||||||
|
|
||||||
#define TD_VID(PVNODE) (PVNODE)->config.vgId
|
#define TD_VID(PVNODE) (PVNODE)->config.vgId
|
||||||
|
|
||||||
|
typedef struct STbDdlH STbDdlH;
|
||||||
|
|
||||||
// sma
|
// sma
|
||||||
void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data);
|
void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data);
|
||||||
|
|
||||||
|
@ -116,6 +118,8 @@ void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data);
|
||||||
|
|
||||||
#include "vnodeSync.h"
|
#include "vnodeSync.h"
|
||||||
|
|
||||||
|
#include "tsdbSma.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -250,7 +250,7 @@ void metaCloseDB(SMeta *pMeta) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) {
|
int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
|
||||||
tb_uid_t uid;
|
tb_uid_t uid;
|
||||||
SMetaDB *pMetaDb;
|
SMetaDB *pMetaDb;
|
||||||
void *pKey;
|
void *pKey;
|
||||||
|
@ -349,6 +349,12 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) {
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
// child table handle for rsma
|
||||||
|
if (pHandle && pHandle->fp) {
|
||||||
|
if (((*pHandle->fp)(pHandle->ahandle, &pHandle->result, &ctbIdxKey.suid, &uid)) < 0) {
|
||||||
|
return -1;
|
||||||
|
};
|
||||||
|
}
|
||||||
} else if (pTbCfg->type == META_NORMAL_TABLE) {
|
} else if (pTbCfg->type == META_NORMAL_TABLE) {
|
||||||
pKey = &uid;
|
pKey = &uid;
|
||||||
kLen = sizeof(uid);
|
kLen = sizeof(uid);
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#include "vnodeInt.h"
|
#include "vnodeInt.h"
|
||||||
|
|
||||||
int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg) {
|
int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
|
||||||
// Validate the tbOptions
|
// Validate the tbOptions
|
||||||
// if (metaValidateTbCfg(pMeta, pTbCfg) < 0) {
|
// if (metaValidateTbCfg(pMeta, pTbCfg) < 0) {
|
||||||
// // TODO: handle error
|
// // TODO: handle error
|
||||||
|
@ -24,7 +24,7 @@ int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg) {
|
||||||
|
|
||||||
// TODO: add atomicity
|
// TODO: add atomicity
|
||||||
|
|
||||||
if (metaSaveTableToDB(pMeta, pTbCfg) < 0) {
|
if (metaSaveTableToDB(pMeta, pTbCfg, pHandle) < 0) {
|
||||||
// TODO: handle error
|
// TODO: handle error
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal) {
|
||||||
pTq->path = strdup(path);
|
pTq->path = strdup(path);
|
||||||
pTq->pVnode = pVnode;
|
pTq->pVnode = pVnode;
|
||||||
pTq->pWal = pWal;
|
pTq->pWal = pWal;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
pTq->tqMeta = tqStoreOpen(pTq, path, (FTqSerialize)tqSerializeConsumer, (FTqDeserialize)tqDeserializeConsumer,
|
pTq->tqMeta = tqStoreOpen(pTq, path, (FTqSerialize)tqSerializeConsumer, (FTqDeserialize)tqDeserializeConsumer,
|
||||||
(FTqDelete)taosMemoryFree, 0);
|
(FTqDelete)taosMemoryFree, 0);
|
||||||
|
@ -196,10 +197,9 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver)
|
||||||
}
|
}
|
||||||
memcpy(data, msg, msgLen);
|
memcpy(data, msg, msgLen);
|
||||||
|
|
||||||
if (msgType == TDMT_VND_SUBMIT) {
|
// make sure msgType == TDMT_VND_SUBMIT
|
||||||
if (tsdbUpdateSmaWindow(pTq->pVnode->pTsdb, msg, ver) != 0) {
|
if (tsdbUpdateSmaWindow(pTq->pVnode->pTsdb, msg, ver) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SRpcMsg req = {
|
SRpcMsg req = {
|
||||||
|
@ -401,10 +401,19 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
||||||
consumerEpoch = atomic_val_compare_exchange_32(&pExec->epoch, consumerEpoch, reqEpoch);
|
consumerEpoch = atomic_val_compare_exchange_32(&pExec->epoch, consumerEpoch, reqEpoch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SWalHead* pHeadWithCkSum = taosMemoryMalloc(sizeof(SWalHead) + 2048);
|
||||||
|
if (pHeadWithCkSum == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
walSetReaderCapacity(pExec->pWalReader, 2048);
|
||||||
|
|
||||||
SMqDataBlkRsp rsp = {0};
|
SMqDataBlkRsp rsp = {0};
|
||||||
rsp.reqOffset = pReq->currentOffset;
|
rsp.reqOffset = pReq->currentOffset;
|
||||||
|
rsp.withSchema = pExec->withSchema;
|
||||||
rsp.blockData = taosArrayInit(0, sizeof(void*));
|
rsp.blockData = taosArrayInit(0, sizeof(void*));
|
||||||
rsp.blockDataLen = taosArrayInit(0, sizeof(int32_t));
|
rsp.blockDataLen = taosArrayInit(0, sizeof(int32_t));
|
||||||
|
rsp.blockSchema = taosArrayInit(0, sizeof(void*));
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
consumerEpoch = atomic_load_32(&pExec->epoch);
|
consumerEpoch = atomic_load_32(&pExec->epoch);
|
||||||
|
@ -414,6 +423,26 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
taosThreadMutexLock(&pExec->pWalReader->mutex);
|
||||||
|
|
||||||
|
if (walFetchHead(pExec->pWalReader, fetchOffset, pHeadWithCkSum) < 0) {
|
||||||
|
vDebug("tmq poll: consumer %ld (epoch %d) vg %d offset %ld, no more log to return", consumerId, pReq->epoch,
|
||||||
|
TD_VID(pTq->pVnode), fetchOffset);
|
||||||
|
taosThreadMutexUnlock(&pExec->pWalReader->mutex);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pHeadWithCkSum->head.msgType != TDMT_VND_SUBMIT) {
|
||||||
|
walSkipFetchBody(pExec->pWalReader, pHeadWithCkSum);
|
||||||
|
} else {
|
||||||
|
walFetchBody(pExec->pWalReader, &pHeadWithCkSum);
|
||||||
|
}
|
||||||
|
|
||||||
|
SWalReadHead* pHead = &pHeadWithCkSum->head;
|
||||||
|
|
||||||
|
taosThreadMutexUnlock(&pExec->pWalReader->mutex);
|
||||||
|
|
||||||
|
#if 0
|
||||||
SWalReadHead* pHead;
|
SWalReadHead* pHead;
|
||||||
if (walReadWithHandle_s(pExec->pWalReader, fetchOffset, &pHead) < 0) {
|
if (walReadWithHandle_s(pExec->pWalReader, fetchOffset, &pHead) < 0) {
|
||||||
// TODO: no more log, set timer to wait blocking time
|
// TODO: no more log, set timer to wait blocking time
|
||||||
|
@ -443,14 +472,16 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
vDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d offset %ld msgType %d", consumerId, pReq->epoch,
|
vDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d offset %ld msgType %d", consumerId, pReq->epoch,
|
||||||
TD_VID(pTq->pVnode), fetchOffset, pHead->msgType);
|
TD_VID(pTq->pVnode), fetchOffset, pHead->msgType);
|
||||||
|
|
||||||
if (pHead->msgType == TDMT_VND_SUBMIT) {
|
if (pHead->msgType == TDMT_VND_SUBMIT) {
|
||||||
SSubmitReq* pCont = (SSubmitReq*)&pHead->body;
|
SSubmitReq* pCont = (SSubmitReq*)&pHead->body;
|
||||||
|
// table subscribe
|
||||||
if (pExec->subType == TOPIC_SUB_TYPE__TABLE) {
|
if (pExec->subType == TOPIC_SUB_TYPE__TABLE) {
|
||||||
qTaskInfo_t task = pExec->task[workerId];
|
qTaskInfo_t task = pExec->task[workerId];
|
||||||
ASSERT(task);
|
ASSERT(task);
|
||||||
|
@ -482,8 +513,15 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
||||||
ASSERT(actualLen <= dataStrLen);
|
ASSERT(actualLen <= dataStrLen);
|
||||||
taosArrayPush(rsp.blockDataLen, &actualLen);
|
taosArrayPush(rsp.blockDataLen, &actualLen);
|
||||||
taosArrayPush(rsp.blockData, &buf);
|
taosArrayPush(rsp.blockData, &buf);
|
||||||
|
|
||||||
|
if (pExec->withSchema) {
|
||||||
|
SSchemaWrapper* pSW = tCloneSSchemaWrapper(pExec->pExecReader[workerId]->pSchemaWrapper);
|
||||||
|
taosArrayPush(rsp.blockSchema, &pSW);
|
||||||
|
}
|
||||||
|
|
||||||
rsp.blockNum++;
|
rsp.blockNum++;
|
||||||
}
|
}
|
||||||
|
// db subscribe
|
||||||
} else if (pExec->subType == TOPIC_SUB_TYPE__DB) {
|
} else if (pExec->subType == TOPIC_SUB_TYPE__DB) {
|
||||||
STqReadHandle* pReader = pExec->pExecReader[workerId];
|
STqReadHandle* pReader = pExec->pExecReader[workerId];
|
||||||
tqReadHandleSetMsg(pReader, pCont, 0);
|
tqReadHandleSetMsg(pReader, pCont, 0);
|
||||||
|
@ -509,6 +547,10 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
||||||
ASSERT(actualLen <= dataStrLen);
|
ASSERT(actualLen <= dataStrLen);
|
||||||
taosArrayPush(rsp.blockDataLen, &actualLen);
|
taosArrayPush(rsp.blockDataLen, &actualLen);
|
||||||
taosArrayPush(rsp.blockData, &buf);
|
taosArrayPush(rsp.blockData, &buf);
|
||||||
|
|
||||||
|
SSchemaWrapper* pSW = tCloneSSchemaWrapper(pExec->pExecReader[workerId]->pSchemaWrapper);
|
||||||
|
taosArrayPush(rsp.blockSchema, &pSW);
|
||||||
|
|
||||||
rsp.blockNum++;
|
rsp.blockNum++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -555,6 +597,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
||||||
// TODO destroy
|
// TODO destroy
|
||||||
taosArrayDestroy(rsp.blockData);
|
taosArrayDestroy(rsp.blockData);
|
||||||
taosArrayDestroy(rsp.blockDataLen);
|
taosArrayDestroy(rsp.blockDataLen);
|
||||||
|
taosArrayDestroyP(rsp.blockSchema, (FDelete)tDeleteSSchemaWrapper);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -789,7 +833,6 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) {
|
||||||
pExec->withTbName = req.withTbName;
|
pExec->withTbName = req.withTbName;
|
||||||
pExec->withSchema = req.withSchema;
|
pExec->withSchema = req.withSchema;
|
||||||
pExec->withTag = req.withTag;
|
pExec->withTag = req.withTag;
|
||||||
pExec->withTagSchema = req.withTagSchema;
|
|
||||||
|
|
||||||
pExec->qmsg = req.qmsg;
|
pExec->qmsg = req.qmsg;
|
||||||
req.qmsg = NULL;
|
req.qmsg = NULL;
|
||||||
|
@ -797,12 +840,16 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) {
|
||||||
pExec->pWalReader = walOpenReadHandle(pTq->pVnode->pWal);
|
pExec->pWalReader = walOpenReadHandle(pTq->pVnode->pWal);
|
||||||
for (int32_t i = 0; i < 5; i++) {
|
for (int32_t i = 0; i < 5; i++) {
|
||||||
pExec->pExecReader[i] = tqInitSubmitMsgScanner(pTq->pVnode->pMeta);
|
pExec->pExecReader[i] = tqInitSubmitMsgScanner(pTq->pVnode->pMeta);
|
||||||
SReadHandle handle = {
|
if (pExec->subType == TOPIC_SUB_TYPE__TABLE) {
|
||||||
.reader = pExec->pExecReader[i],
|
SReadHandle handle = {
|
||||||
.meta = pTq->pVnode->pMeta,
|
.reader = pExec->pExecReader[i],
|
||||||
};
|
.meta = pTq->pVnode->pMeta,
|
||||||
pExec->task[i] = qCreateStreamExecTaskInfo(pExec->qmsg, &handle);
|
};
|
||||||
ASSERT(pExec->task[i]);
|
pExec->task[i] = qCreateStreamExecTaskInfo(pExec->qmsg, &handle);
|
||||||
|
ASSERT(pExec->task[i]);
|
||||||
|
} else {
|
||||||
|
pExec->task[i] = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
taosHashPut(pTq->execs, req.subKey, strlen(req.subKey), pExec, sizeof(STqExec));
|
taosHashPut(pTq->execs, req.subKey, strlen(req.subKey), pExec, sizeof(STqExec));
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -33,24 +33,24 @@ STqReadHandle* tqInitSubmitMsgScanner(SMeta* pMeta) {
|
||||||
|
|
||||||
int32_t tqReadHandleSetMsg(STqReadHandle* pReadHandle, SSubmitReq* pMsg, int64_t ver) {
|
int32_t tqReadHandleSetMsg(STqReadHandle* pReadHandle, SSubmitReq* pMsg, int64_t ver) {
|
||||||
pReadHandle->pMsg = pMsg;
|
pReadHandle->pMsg = pMsg;
|
||||||
pMsg->length = htonl(pMsg->length);
|
// pMsg->length = htonl(pMsg->length);
|
||||||
pMsg->numOfBlocks = htonl(pMsg->numOfBlocks);
|
// pMsg->numOfBlocks = htonl(pMsg->numOfBlocks);
|
||||||
|
|
||||||
// iterate and convert
|
// iterate and convert
|
||||||
if (tInitSubmitMsgIter(pMsg, &pReadHandle->msgIter) < 0) return -1;
|
if (tInitSubmitMsgIterEx(pMsg, &pReadHandle->msgIter) < 0) return -1;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (tGetSubmitMsgNext(&pReadHandle->msgIter, &pReadHandle->pBlock) < 0) return -1;
|
if (tGetSubmitMsgNextEx(&pReadHandle->msgIter, &pReadHandle->pBlock) < 0) return -1;
|
||||||
if (pReadHandle->pBlock == NULL) break;
|
if (pReadHandle->pBlock == NULL) break;
|
||||||
|
|
||||||
pReadHandle->pBlock->uid = htobe64(pReadHandle->pBlock->uid);
|
// pReadHandle->pBlock->uid = htobe64(pReadHandle->pBlock->uid);
|
||||||
pReadHandle->pBlock->suid = htobe64(pReadHandle->pBlock->suid);
|
// pReadHandle->pBlock->suid = htobe64(pReadHandle->pBlock->suid);
|
||||||
pReadHandle->pBlock->sversion = htonl(pReadHandle->pBlock->sversion);
|
// pReadHandle->pBlock->sversion = htonl(pReadHandle->pBlock->sversion);
|
||||||
pReadHandle->pBlock->dataLen = htonl(pReadHandle->pBlock->dataLen);
|
// pReadHandle->pBlock->dataLen = htonl(pReadHandle->pBlock->dataLen);
|
||||||
pReadHandle->pBlock->schemaLen = htonl(pReadHandle->pBlock->schemaLen);
|
// pReadHandle->pBlock->schemaLen = htonl(pReadHandle->pBlock->schemaLen);
|
||||||
pReadHandle->pBlock->numOfRows = htons(pReadHandle->pBlock->numOfRows);
|
// pReadHandle->pBlock->numOfRows = htons(pReadHandle->pBlock->numOfRows);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tInitSubmitMsgIter(pMsg, &pReadHandle->msgIter) < 0) return -1;
|
if (tInitSubmitMsgIterEx(pMsg, &pReadHandle->msgIter) < 0) return -1;
|
||||||
pReadHandle->ver = ver;
|
pReadHandle->ver = ver;
|
||||||
memset(&pReadHandle->blkIter, 0, sizeof(SSubmitBlkIter));
|
memset(&pReadHandle->blkIter, 0, sizeof(SSubmitBlkIter));
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -58,15 +58,17 @@ int32_t tqReadHandleSetMsg(STqReadHandle* pReadHandle, SSubmitReq* pMsg, int64_t
|
||||||
|
|
||||||
bool tqNextDataBlock(STqReadHandle* pHandle) {
|
bool tqNextDataBlock(STqReadHandle* pHandle) {
|
||||||
while (1) {
|
while (1) {
|
||||||
if (tGetSubmitMsgNext(&pHandle->msgIter, &pHandle->pBlock) < 0) {
|
if (tGetSubmitMsgNextEx(&pHandle->msgIter, &pHandle->pBlock) < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (pHandle->pBlock == NULL) return false;
|
if (pHandle->pBlock == NULL) return false;
|
||||||
|
|
||||||
/*pHandle->pBlock->uid = htobe64(pHandle->pBlock->uid);*/
|
/*pHandle->pBlock->uid = htobe64(pHandle->pBlock->uid);*/
|
||||||
/*if (pHandle->tbUid == pHandle->pBlock->uid) {*/
|
/*if (pHandle->tbUid == pHandle->pBlock->uid) {*/
|
||||||
ASSERT(pHandle->tbIdHash);
|
if (pHandle->tbIdHash == NULL) {
|
||||||
void* ret = taosHashGet(pHandle->tbIdHash, &pHandle->pBlock->uid, sizeof(int64_t));
|
return true;
|
||||||
|
}
|
||||||
|
void* ret = taosHashGet(pHandle->tbIdHash, &pHandle->msgIter.uid, sizeof(int64_t));
|
||||||
if (ret != NULL) {
|
if (ret != NULL) {
|
||||||
/*printf("retrieve one tb %ld\n", pHandle->pBlock->uid);*/
|
/*printf("retrieve one tb %ld\n", pHandle->pBlock->uid);*/
|
||||||
/*pHandle->pBlock->tid = htonl(pHandle->pBlock->tid);*/
|
/*pHandle->pBlock->tid = htonl(pHandle->pBlock->tid);*/
|
||||||
|
@ -88,45 +90,36 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p
|
||||||
// TODO set to real sversion
|
// TODO set to real sversion
|
||||||
int32_t sversion = 0;
|
int32_t sversion = 0;
|
||||||
if (pHandle->sver != sversion) {
|
if (pHandle->sver != sversion) {
|
||||||
pHandle->pSchema = metaGetTbTSchema(pHandle->pVnodeMeta, pHandle->pBlock->uid, sversion);
|
pHandle->pSchema = metaGetTbTSchema(pHandle->pVnodeMeta, pHandle->msgIter.uid, sversion);
|
||||||
|
#if 0
|
||||||
tb_uid_t quid;
|
tb_uid_t quid;
|
||||||
STbCfg* pTbCfg = metaGetTbInfoByUid(pHandle->pVnodeMeta, pHandle->pBlock->uid);
|
STbCfg* pTbCfg = metaGetTbInfoByUid(pHandle->pVnodeMeta, pHandle->msgIter.uid);
|
||||||
if (pTbCfg->type == META_CHILD_TABLE) {
|
if (pTbCfg->type == META_CHILD_TABLE) {
|
||||||
quid = pTbCfg->ctbCfg.suid;
|
quid = pTbCfg->ctbCfg.suid;
|
||||||
} else {
|
} else {
|
||||||
quid = pHandle->pBlock->uid;
|
quid = pHandle->msgIter.uid;
|
||||||
}
|
}
|
||||||
pHandle->pSchemaWrapper = metaGetTableSchema(pHandle->pVnodeMeta, quid, sversion, true);
|
pHandle->pSchemaWrapper = metaGetTableSchema(pHandle->pVnodeMeta, quid, sversion, true);
|
||||||
|
#endif
|
||||||
|
pHandle->pSchemaWrapper = metaGetTableSchema(pHandle->pVnodeMeta, pHandle->msgIter.suid, sversion, true);
|
||||||
pHandle->sver = sversion;
|
pHandle->sver = sversion;
|
||||||
}
|
}
|
||||||
|
|
||||||
STSchema* pTschema = pHandle->pSchema;
|
STSchema* pTschema = pHandle->pSchema;
|
||||||
SSchemaWrapper* pSchemaWrapper = pHandle->pSchemaWrapper;
|
SSchemaWrapper* pSchemaWrapper = pHandle->pSchemaWrapper;
|
||||||
|
|
||||||
*pNumOfRows = pHandle->pBlock->numOfRows;
|
*pNumOfRows = pHandle->msgIter.numOfRows;
|
||||||
int32_t colNumNeed = taosArrayGetSize(pHandle->pColIdList);
|
int32_t colNumNeed = taosArrayGetSize(pHandle->pColIdList);
|
||||||
|
|
||||||
if (colNumNeed > pSchemaWrapper->nCols) {
|
if (colNumNeed == 0) {
|
||||||
colNumNeed = pSchemaWrapper->nCols;
|
*ppCols = taosArrayInit(pSchemaWrapper->nCols, sizeof(SColumnInfoData));
|
||||||
}
|
if (*ppCols == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
*ppCols = taosArrayInit(colNumNeed, sizeof(SColumnInfoData));
|
int32_t colMeta = 0;
|
||||||
if (*ppCols == NULL) {
|
while (colMeta < pSchemaWrapper->nCols) {
|
||||||
return -1;
|
SSchema* pColSchema = &pSchemaWrapper->pSchema[colMeta];
|
||||||
}
|
|
||||||
|
|
||||||
int32_t colMeta = 0;
|
|
||||||
int32_t colNeed = 0;
|
|
||||||
while (colMeta < pSchemaWrapper->nCols && colNeed < colNumNeed) {
|
|
||||||
SSchema* pColSchema = &pSchemaWrapper->pSchema[colMeta];
|
|
||||||
col_id_t colIdSchema = pColSchema->colId;
|
|
||||||
col_id_t colIdNeed = *(col_id_t*)taosArrayGet(pHandle->pColIdList, colNeed);
|
|
||||||
if (colIdSchema < colIdNeed) {
|
|
||||||
colMeta++;
|
|
||||||
} else if (colIdSchema > colIdNeed) {
|
|
||||||
colNeed++;
|
|
||||||
} else {
|
|
||||||
SColumnInfoData colInfo = {0};
|
SColumnInfoData colInfo = {0};
|
||||||
colInfo.info.bytes = pColSchema->bytes;
|
colInfo.info.bytes = pColSchema->bytes;
|
||||||
colInfo.info.colId = pColSchema->colId;
|
colInfo.info.colId = pColSchema->colId;
|
||||||
|
@ -137,7 +130,40 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p
|
||||||
}
|
}
|
||||||
taosArrayPush(*ppCols, &colInfo);
|
taosArrayPush(*ppCols, &colInfo);
|
||||||
colMeta++;
|
colMeta++;
|
||||||
colNeed++;
|
}
|
||||||
|
} else {
|
||||||
|
if (colNumNeed > pSchemaWrapper->nCols) {
|
||||||
|
colNumNeed = pSchemaWrapper->nCols;
|
||||||
|
}
|
||||||
|
|
||||||
|
*ppCols = taosArrayInit(colNumNeed, sizeof(SColumnInfoData));
|
||||||
|
if (*ppCols == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t colMeta = 0;
|
||||||
|
int32_t colNeed = 0;
|
||||||
|
while (colMeta < pSchemaWrapper->nCols && colNeed < colNumNeed) {
|
||||||
|
SSchema* pColSchema = &pSchemaWrapper->pSchema[colMeta];
|
||||||
|
col_id_t colIdSchema = pColSchema->colId;
|
||||||
|
col_id_t colIdNeed = *(col_id_t*)taosArrayGet(pHandle->pColIdList, colNeed);
|
||||||
|
if (colIdSchema < colIdNeed) {
|
||||||
|
colMeta++;
|
||||||
|
} else if (colIdSchema > colIdNeed) {
|
||||||
|
colNeed++;
|
||||||
|
} else {
|
||||||
|
SColumnInfoData colInfo = {0};
|
||||||
|
colInfo.info.bytes = pColSchema->bytes;
|
||||||
|
colInfo.info.colId = pColSchema->colId;
|
||||||
|
colInfo.info.type = pColSchema->type;
|
||||||
|
|
||||||
|
if (colInfoDataEnsureCapacity(&colInfo, 0, *pNumOfRows) < 0) {
|
||||||
|
goto FAIL;
|
||||||
|
}
|
||||||
|
taosArrayPush(*ppCols, &colInfo);
|
||||||
|
colMeta++;
|
||||||
|
colNeed++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,8 +177,8 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p
|
||||||
tdSTSRowIterInit(&iter, pTschema);
|
tdSTSRowIterInit(&iter, pTschema);
|
||||||
STSRow* row;
|
STSRow* row;
|
||||||
int32_t curRow = 0;
|
int32_t curRow = 0;
|
||||||
tInitSubmitBlkIter(pHandle->pBlock, &pHandle->blkIter);
|
tInitSubmitBlkIterEx(&pHandle->msgIter, pHandle->pBlock, &pHandle->blkIter);
|
||||||
while ((row = tGetSubmitBlkNext(&pHandle->blkIter)) != NULL) {
|
while ((row = tGetSubmitBlkNextEx(&pHandle->blkIter)) != NULL) {
|
||||||
tdSTSRowIterReset(&iter, row);
|
tdSTSRowIterReset(&iter, row);
|
||||||
// get all wanted col of that block
|
// get all wanted col of that block
|
||||||
for (int32_t i = 0; i < colActual; i++) {
|
for (int32_t i = 0; i < colActual; i++) {
|
||||||
|
|
|
@ -81,8 +81,8 @@ static STsdb *tsdbNew(const char *path, SVnode *pVnode, const STsdbCfg *pTsdbCfg
|
||||||
|
|
||||||
static void tsdbFree(STsdb *pTsdb) {
|
static void tsdbFree(STsdb *pTsdb) {
|
||||||
if (pTsdb) {
|
if (pTsdb) {
|
||||||
// tsdbFreeSmaEnv(REPO_TSMA_ENV(pTsdb));
|
tsdbFreeSmaEnv(REPO_TSMA_ENV(pTsdb));
|
||||||
// tsdbFreeSmaEnv(REPO_RSMA_ENV(pTsdb));
|
tsdbFreeSmaEnv(REPO_RSMA_ENV(pTsdb));
|
||||||
tsdbFreeFS(pTsdb->fs);
|
tsdbFreeFS(pTsdb->fs);
|
||||||
taosMemoryFreeClear(pTsdb->path);
|
taosMemoryFreeClear(pTsdb->path);
|
||||||
taosMemoryFree(pTsdb);
|
taosMemoryFree(pTsdb);
|
||||||
|
|
|
@ -254,7 +254,7 @@ static SArray* createCheckInfoFromTableGroup(STsdbReadHandle* pTsdbReadHandle, S
|
||||||
|
|
||||||
assert(info.lastKey >= pTsdbReadHandle->window.skey && info.lastKey <= pTsdbReadHandle->window.ekey);
|
assert(info.lastKey >= pTsdbReadHandle->window.skey && info.lastKey <= pTsdbReadHandle->window.ekey);
|
||||||
} else {
|
} else {
|
||||||
assert(info.lastKey >= pTsdbReadHandle->window.ekey && info.lastKey <= pTsdbReadHandle->window.skey);
|
info.lastKey = pTsdbReadHandle->window.skey;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayPush(pTableCheckInfo, &info);
|
taosArrayPush(pTableCheckInfo, &info);
|
||||||
|
@ -317,7 +317,7 @@ static int64_t getEarliestValidTimestamp(STsdb* pTsdb) {
|
||||||
return now - (tsTickPerDay[pCfg->precision] * pCfg->keep2) + 1; // needs to add one tick
|
return now - (tsTickPerDay[pCfg->precision] * pCfg->keep2) + 1; // needs to add one tick
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setQueryTimewindow(STsdbReadHandle* pTsdbReadHandle, STsdbQueryCond* pCond) {
|
static void setQueryTimewindow(STsdbReadHandle* pTsdbReadHandle, SQueryTableDataCond* pCond) {
|
||||||
pTsdbReadHandle->window = pCond->twindow;
|
pTsdbReadHandle->window = pCond->twindow;
|
||||||
|
|
||||||
bool updateTs = false;
|
bool updateTs = false;
|
||||||
|
@ -343,7 +343,7 @@ static void setQueryTimewindow(STsdbReadHandle* pTsdbReadHandle, STsdbQueryCond*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static STsdbReadHandle* tsdbQueryTablesImpl(STsdb* tsdb, STsdbQueryCond* pCond, uint64_t qId, uint64_t taskId) {
|
static STsdbReadHandle* tsdbQueryTablesImpl(STsdb* tsdb, SQueryTableDataCond* pCond, uint64_t qId, uint64_t taskId) {
|
||||||
STsdbReadHandle* pReadHandle = taosMemoryCalloc(1, sizeof(STsdbReadHandle));
|
STsdbReadHandle* pReadHandle = taosMemoryCalloc(1, sizeof(STsdbReadHandle));
|
||||||
if (pReadHandle == NULL) {
|
if (pReadHandle == NULL) {
|
||||||
goto _end;
|
goto _end;
|
||||||
|
@ -422,7 +422,7 @@ _end:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbReaderT* tsdbQueryTables(STsdb* tsdb, STsdbQueryCond* pCond, STableGroupInfo* groupList, uint64_t qId,
|
tsdbReaderT* tsdbQueryTables(STsdb* tsdb, SQueryTableDataCond* pCond, STableGroupInfo* groupList, uint64_t qId,
|
||||||
uint64_t taskId) {
|
uint64_t taskId) {
|
||||||
STsdbReadHandle* pTsdbReadHandle = tsdbQueryTablesImpl(tsdb, pCond, qId, taskId);
|
STsdbReadHandle* pTsdbReadHandle = tsdbQueryTablesImpl(tsdb, pCond, qId, taskId);
|
||||||
if (pTsdbReadHandle == NULL) {
|
if (pTsdbReadHandle == NULL) {
|
||||||
|
@ -448,7 +448,7 @@ tsdbReaderT* tsdbQueryTables(STsdb* tsdb, STsdbQueryCond* pCond, STableGroupInfo
|
||||||
return (tsdbReaderT)pTsdbReadHandle;
|
return (tsdbReaderT)pTsdbReadHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tsdbResetQueryHandle(tsdbReaderT queryHandle, STsdbQueryCond* pCond) {
|
void tsdbResetReadHandle(tsdbReaderT queryHandle, SQueryTableDataCond* pCond) {
|
||||||
STsdbReadHandle* pTsdbReadHandle = queryHandle;
|
STsdbReadHandle* pTsdbReadHandle = queryHandle;
|
||||||
|
|
||||||
if (emptyQueryTimewindow(pTsdbReadHandle)) {
|
if (emptyQueryTimewindow(pTsdbReadHandle)) {
|
||||||
|
@ -460,9 +460,9 @@ void tsdbResetQueryHandle(tsdbReaderT queryHandle, STsdbQueryCond* pCond) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pTsdbReadHandle->order = pCond->order;
|
pTsdbReadHandle->order = pCond->order;
|
||||||
pTsdbReadHandle->window = pCond->twindow;
|
pTsdbReadHandle->window = pCond->twindow;
|
||||||
pTsdbReadHandle->type = TSDB_QUERY_TYPE_ALL;
|
pTsdbReadHandle->type = TSDB_QUERY_TYPE_ALL;
|
||||||
pTsdbReadHandle->cur.fid = -1;
|
pTsdbReadHandle->cur.fid = -1;
|
||||||
pTsdbReadHandle->cur.win = TSWINDOW_INITIALIZER;
|
pTsdbReadHandle->cur.win = TSWINDOW_INITIALIZER;
|
||||||
pTsdbReadHandle->checkFiles = true;
|
pTsdbReadHandle->checkFiles = true;
|
||||||
|
@ -485,7 +485,7 @@ void tsdbResetQueryHandle(tsdbReaderT queryHandle, STsdbQueryCond* pCond) {
|
||||||
resetCheckInfo(pTsdbReadHandle);
|
resetCheckInfo(pTsdbReadHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tsdbResetQueryHandleForNewTable(tsdbReaderT queryHandle, STsdbQueryCond* pCond, STableGroupInfo* groupList) {
|
void tsdbResetQueryHandleForNewTable(tsdbReaderT queryHandle, SQueryTableDataCond* pCond, STableGroupInfo* groupList) {
|
||||||
STsdbReadHandle* pTsdbReadHandle = queryHandle;
|
STsdbReadHandle* pTsdbReadHandle = queryHandle;
|
||||||
|
|
||||||
pTsdbReadHandle->order = pCond->order;
|
pTsdbReadHandle->order = pCond->order;
|
||||||
|
@ -526,7 +526,7 @@ void tsdbResetQueryHandleForNewTable(tsdbReaderT queryHandle, STsdbQueryCond* pC
|
||||||
// pTsdbReadHandle->next = doFreeColumnInfoData(pTsdbReadHandle->next);
|
// pTsdbReadHandle->next = doFreeColumnInfoData(pTsdbReadHandle->next);
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbReaderT tsdbQueryLastRow(STsdb* tsdb, STsdbQueryCond* pCond, STableGroupInfo* groupList, uint64_t qId,
|
tsdbReaderT tsdbQueryLastRow(STsdb* tsdb, SQueryTableDataCond* pCond, STableGroupInfo* groupList, uint64_t qId,
|
||||||
uint64_t taskId) {
|
uint64_t taskId) {
|
||||||
pCond->twindow = updateLastrowForEachGroup(groupList);
|
pCond->twindow = updateLastrowForEachGroup(groupList);
|
||||||
|
|
||||||
|
@ -555,7 +555,7 @@ tsdbReaderT tsdbQueryLastRow(STsdb* tsdb, STsdbQueryCond* pCond, STableGroupInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
tsdbReaderT tsdbQueryCacheLast(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList, uint64_t qId, STsdbMemTable* pMemRef) {
|
tsdbReaderT tsdbQueryCacheLast(STsdb *tsdb, SQueryTableDataCond *pCond, STableGroupInfo *groupList, uint64_t qId, STsdbMemTable* pMemRef) {
|
||||||
STsdbReadHandle *pTsdbReadHandle = (STsdbReadHandle*) tsdbQueryTables(tsdb, pCond, groupList, qId, pMemRef);
|
STsdbReadHandle *pTsdbReadHandle = (STsdbReadHandle*) tsdbQueryTables(tsdb, pCond, groupList, qId, pMemRef);
|
||||||
if (pTsdbReadHandle == NULL) {
|
if (pTsdbReadHandle == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -618,7 +618,7 @@ static STableGroupInfo* trimTableGroup(STimeWindow* window, STableGroupInfo* pGr
|
||||||
return pNew;
|
return pNew;
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbReaderT tsdbQueryRowsInExternalWindow(STsdb* tsdb, STsdbQueryCond* pCond, STableGroupInfo* groupList, uint64_t qId,
|
tsdbReaderT tsdbQueryRowsInExternalWindow(STsdb* tsdb, SQueryTableDataCond* pCond, STableGroupInfo* groupList, uint64_t qId,
|
||||||
uint64_t taskId) {
|
uint64_t taskId) {
|
||||||
STableGroupInfo* pNew = trimTableGroup(&pCond->twindow, groupList);
|
STableGroupInfo* pNew = trimTableGroup(&pCond->twindow, groupList);
|
||||||
|
|
||||||
|
@ -1185,10 +1185,11 @@ static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock*
|
||||||
tsdbDebug("%p no data in mem, %s", pTsdbReadHandle, pTsdbReadHandle->idStr);
|
tsdbDebug("%p no data in mem, %s", pTsdbReadHandle, pTsdbReadHandle->idStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ASCENDING_TRAVERSE(pTsdbReadHandle->order) && (key != TSKEY_INITIAL_VAL && key <= binfo.window.ekey)) ||
|
bool ascScan = ASCENDING_TRAVERSE(pTsdbReadHandle->order);
|
||||||
(!ASCENDING_TRAVERSE(pTsdbReadHandle->order) && (key != TSKEY_INITIAL_VAL && key >= binfo.window.skey))) {
|
|
||||||
if ((ASCENDING_TRAVERSE(pTsdbReadHandle->order) && (key != TSKEY_INITIAL_VAL && key < binfo.window.skey)) ||
|
if ((ascScan && (key != TSKEY_INITIAL_VAL && key <= binfo.window.ekey)) || (!ascScan && (key != TSKEY_INITIAL_VAL && key >= binfo.window.skey))) {
|
||||||
(!ASCENDING_TRAVERSE(pTsdbReadHandle->order) && (key != TSKEY_INITIAL_VAL && key > binfo.window.ekey))) {
|
|
||||||
|
if ((ascScan && (key != TSKEY_INITIAL_VAL && key < binfo.window.skey)) || (!ascScan && (key != TSKEY_INITIAL_VAL && key > binfo.window.ekey))) {
|
||||||
// do not load file block into buffer
|
// do not load file block into buffer
|
||||||
int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1;
|
int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1;
|
||||||
|
|
||||||
|
@ -1225,8 +1226,7 @@ static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock*
|
||||||
assert(pTsdbReadHandle->outputCapacity >= binfo.rows);
|
assert(pTsdbReadHandle->outputCapacity >= binfo.rows);
|
||||||
int32_t endPos = getEndPosInDataBlock(pTsdbReadHandle, &binfo);
|
int32_t endPos = getEndPosInDataBlock(pTsdbReadHandle, &binfo);
|
||||||
|
|
||||||
if ((cur->pos == 0 && endPos == binfo.rows - 1 && ASCENDING_TRAVERSE(pTsdbReadHandle->order)) ||
|
if ((cur->pos == 0 && endPos == binfo.rows - 1 && ascScan) || (cur->pos == (binfo.rows - 1) && endPos == 0 && (!ascScan))) {
|
||||||
(cur->pos == (binfo.rows - 1) && endPos == 0 && (!ASCENDING_TRAVERSE(pTsdbReadHandle->order)))) {
|
|
||||||
pTsdbReadHandle->realNumOfRows = binfo.rows;
|
pTsdbReadHandle->realNumOfRows = binfo.rows;
|
||||||
|
|
||||||
cur->rows = binfo.rows;
|
cur->rows = binfo.rows;
|
||||||
|
@ -1234,7 +1234,7 @@ static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock*
|
||||||
cur->mixBlock = false;
|
cur->mixBlock = false;
|
||||||
cur->blockCompleted = true;
|
cur->blockCompleted = true;
|
||||||
|
|
||||||
if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) {
|
if (ascScan) {
|
||||||
cur->lastKey = binfo.window.ekey + 1;
|
cur->lastKey = binfo.window.ekey + 1;
|
||||||
cur->pos = binfo.rows;
|
cur->pos = binfo.rows;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1382,8 +1382,6 @@ static int doBinarySearchKey(char* pValue, int num, TSKEY key, int order) {
|
||||||
|
|
||||||
static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t capacity, int32_t numOfRows,
|
static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t capacity, int32_t numOfRows,
|
||||||
int32_t start, int32_t end) {
|
int32_t start, int32_t end) {
|
||||||
int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1;
|
|
||||||
|
|
||||||
SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0];
|
SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0];
|
||||||
TSKEY* tsArray = pCols->cols[0].pData;
|
TSKEY* tsArray = pCols->cols[0].pData;
|
||||||
|
|
||||||
|
@ -1394,6 +1392,11 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t
|
||||||
return numOfRows;
|
return numOfRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ascScan = ASCENDING_TRAVERSE(pTsdbReadHandle->order);
|
||||||
|
int32_t trueStart = ascScan ? start : end;
|
||||||
|
int32_t trueEnd = ascScan ? end : start;
|
||||||
|
int32_t step = ascScan ? 1 : -1;
|
||||||
|
|
||||||
int32_t requiredNumOfCols = (int32_t)taosArrayGetSize(pTsdbReadHandle->pColumns);
|
int32_t requiredNumOfCols = (int32_t)taosArrayGetSize(pTsdbReadHandle->pColumns);
|
||||||
|
|
||||||
// data in buffer has greater timestamp, copy data in file block
|
// data in buffer has greater timestamp, copy data in file block
|
||||||
|
@ -1411,7 +1414,7 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t
|
||||||
if (!IS_VAR_DATA_TYPE(pColInfo->info.type)) { // todo opt performance
|
if (!IS_VAR_DATA_TYPE(pColInfo->info.type)) { // todo opt performance
|
||||||
// memmove(pData, (char*)src->pData + bytes * start, bytes * num);
|
// memmove(pData, (char*)src->pData + bytes * start, bytes * num);
|
||||||
int32_t rowIndex = numOfRows;
|
int32_t rowIndex = numOfRows;
|
||||||
for (int32_t k = start; k <= end; ++k, ++rowIndex) {
|
for (int32_t k = trueStart; ((ascScan && k <= trueEnd) || (!ascScan && k >= trueEnd)); k += step, ++rowIndex) {
|
||||||
SCellVal sVal = {0};
|
SCellVal sVal = {0};
|
||||||
if (tdGetColDataOfRow(&sVal, src, k, pCols->bitmapMode) < 0) {
|
if (tdGetColDataOfRow(&sVal, src, k, pCols->bitmapMode) < 0) {
|
||||||
TASSERT(0);
|
TASSERT(0);
|
||||||
|
@ -1427,7 +1430,7 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t
|
||||||
int32_t rowIndex = numOfRows;
|
int32_t rowIndex = numOfRows;
|
||||||
|
|
||||||
// todo refactor, only copy one-by-one
|
// todo refactor, only copy one-by-one
|
||||||
for (int32_t k = start; k < num + start; ++k, ++rowIndex) {
|
for (int32_t k = trueStart; ((ascScan && k <= trueEnd) || (!ascScan && k >= trueEnd)); k += step, ++rowIndex) {
|
||||||
SCellVal sVal = {0};
|
SCellVal sVal = {0};
|
||||||
if (tdGetColDataOfRow(&sVal, src, k, pCols->bitmapMode) < 0) {
|
if (tdGetColDataOfRow(&sVal, src, k, pCols->bitmapMode) < 0) {
|
||||||
TASSERT(0);
|
TASSERT(0);
|
||||||
|
@ -1444,26 +1447,19 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t
|
||||||
j++;
|
j++;
|
||||||
i++;
|
i++;
|
||||||
} else { // pColInfo->info.colId < src->colId, it is a NULL data
|
} else { // pColInfo->info.colId < src->colId, it is a NULL data
|
||||||
int32_t rowIndex = numOfRows;
|
colDataAppendNNULL(pColInfo, numOfRows, num);
|
||||||
for (int32_t k = start; k < num + start; ++k, ++rowIndex) { // TODO opt performance
|
|
||||||
colDataAppend(pColInfo, rowIndex, NULL, true);
|
|
||||||
}
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (i < requiredNumOfCols) { // the remain columns are all null data
|
while (i < requiredNumOfCols) { // the remain columns are all null data
|
||||||
SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i);
|
SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i);
|
||||||
int32_t rowIndex = numOfRows;
|
colDataAppendNNULL(pColInfo, numOfRows, num);
|
||||||
|
|
||||||
for (int32_t k = start; k < num + start; ++k, ++rowIndex) {
|
|
||||||
colDataAppend(pColInfo, rowIndex, NULL, true); // TODO add a fast version to set a number of consecutive NULL value.
|
|
||||||
}
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
pTsdbReadHandle->cur.win.ekey = tsArray[end];
|
pTsdbReadHandle->cur.win.ekey = tsArray[trueEnd];
|
||||||
pTsdbReadHandle->cur.lastKey = tsArray[end] + step;
|
pTsdbReadHandle->cur.lastKey = tsArray[trueEnd] + step;
|
||||||
|
|
||||||
return numOfRows + num;
|
return numOfRows + num;
|
||||||
}
|
}
|
||||||
|
@ -2966,7 +2962,7 @@ bool tsdbNextDataBlock(tsdbReaderT pHandle) {
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// // load the previous row
|
// // load the previous row
|
||||||
// STsdbQueryCond cond = {.numOfCols = numOfCols, .loadExternalRows = false, .type = BLOCK_LOAD_OFFSET_SEQ_ORDER};
|
// SQueryTableDataCond cond = {.numOfCols = numOfCols, .loadExternalRows = false, .type = BLOCK_LOAD_OFFSET_SEQ_ORDER};
|
||||||
// if (type == TSDB_PREV_ROW) {
|
// if (type == TSDB_PREV_ROW) {
|
||||||
// cond.order = TSDB_ORDER_DESC;
|
// cond.order = TSDB_ORDER_DESC;
|
||||||
// cond.twindow = (STimeWindow){pTsdbReadHandle->window.skey, INT64_MIN};
|
// cond.twindow = (STimeWindow){pTsdbReadHandle->window.skey, INT64_MIN};
|
||||||
|
@ -3223,8 +3219,13 @@ void tsdbRetrieveDataBlockInfo(tsdbReaderT* pTsdbReadHandle, SDataBlockInfo* pDa
|
||||||
tsdbDebug("data block generated, uid:%" PRIu64 " numOfRows:%d, tsrange:%" PRId64 " - %" PRId64 " %s", uid, cur->rows,
|
tsdbDebug("data block generated, uid:%" PRIu64 " numOfRows:%d, tsrange:%" PRId64 " - %" PRId64 " %s", uid, cur->rows,
|
||||||
cur->win.skey, cur->win.ekey, pHandle->idStr);
|
cur->win.skey, cur->win.ekey, pHandle->idStr);
|
||||||
|
|
||||||
// pDataBlockInfo->uid = uid; // block Id may be over write by assigning uid fro this data block. Do NOT assign
|
pDataBlockInfo->uid = uid;
|
||||||
// the table uid
|
|
||||||
|
#if 0
|
||||||
|
// for multi-group data query processing test purpose
|
||||||
|
pDataBlockInfo->groupId = uid;
|
||||||
|
#endif
|
||||||
|
|
||||||
pDataBlockInfo->rows = cur->rows;
|
pDataBlockInfo->rows = cur->rows;
|
||||||
pDataBlockInfo->window = cur->win;
|
pDataBlockInfo->window = cur->win;
|
||||||
pDataBlockInfo->numOfCols = (int32_t)(QH_GET_NUM_OF_COLS(pHandle));
|
pDataBlockInfo->numOfCols = (int32_t)(QH_GET_NUM_OF_COLS(pHandle));
|
||||||
|
@ -3325,21 +3326,7 @@ SArray* tsdbRetrieveDataBlock(tsdbReaderT* pTsdbReadHandle, SArray* pIdList) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo refactor
|
|
||||||
int32_t numOfRows = doCopyRowsFromFileBlock(pHandle, pHandle->outputCapacity, 0, 0, pBlock->numOfRows - 1);
|
int32_t numOfRows = doCopyRowsFromFileBlock(pHandle, pHandle->outputCapacity, 0, 0, pBlock->numOfRows - 1);
|
||||||
|
|
||||||
// if the buffer is not full in case of descending order query, move the data in the front of the buffer
|
|
||||||
if (!ASCENDING_TRAVERSE(pHandle->order) && numOfRows < pHandle->outputCapacity) {
|
|
||||||
int32_t emptySize = pHandle->outputCapacity - numOfRows;
|
|
||||||
int32_t reqNumOfCols = (int32_t)taosArrayGetSize(pHandle->pColumns);
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < reqNumOfCols; ++i) {
|
|
||||||
SColumnInfoData* pColInfo = taosArrayGet(pHandle->pColumns, i);
|
|
||||||
memmove((char*)pColInfo->pData, (char*)pColInfo->pData + emptySize * pColInfo->info.bytes,
|
|
||||||
numOfRows * pColInfo->info.bytes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pHandle->pColumns;
|
return pHandle->pColumns;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3631,6 +3618,8 @@ int32_t tsdbQuerySTableByTagCond(void* pMeta, uint64_t uid, TSKEY skey, const ch
|
||||||
tsdbError("%p failed to get stable, uid:%" PRIu64 ", TID:0x%" PRIx64 " QID:0x%" PRIx64, pMeta, uid, taskId, reqId);
|
tsdbError("%p failed to get stable, uid:%" PRIu64 ", TID:0x%" PRIx64 " QID:0x%" PRIx64, pMeta, uid, taskId, reqId);
|
||||||
terrno = TSDB_CODE_TDB_INVALID_TABLE_ID;
|
terrno = TSDB_CODE_TDB_INVALID_TABLE_ID;
|
||||||
goto _error;
|
goto _error;
|
||||||
|
} else {
|
||||||
|
tsdbDebug("%p succeed to get stable, uid:%" PRIu64 ", TID:0x%" PRIx64 " QID:0x%" PRIx64, pMeta, uid, taskId, reqId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTbCfg->type != META_SUPER_TABLE) {
|
if (pTbCfg->type != META_SUPER_TABLE) {
|
||||||
|
|
|
@ -33,6 +33,8 @@ static const char *TSDB_SMA_DNAME[] = {
|
||||||
|
|
||||||
#define SMA_TEST_INDEX_NAME "smaTestIndexName" // TODO: just for test
|
#define SMA_TEST_INDEX_NAME "smaTestIndexName" // TODO: just for test
|
||||||
#define SMA_TEST_INDEX_UID 2000000001 // TODO: just for test
|
#define SMA_TEST_INDEX_UID 2000000001 // TODO: just for test
|
||||||
|
|
||||||
|
typedef struct SRSmaInfo SRSmaInfo;
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SMA_STORAGE_LEVEL_TSDB = 0, // use days of self-defined e.g. vnode${N}/tsdb/tsma/sma_index_uid/v2f200.tsma
|
SMA_STORAGE_LEVEL_TSDB = 0, // use days of self-defined e.g. vnode${N}/tsdb/tsma/sma_index_uid/v2f200.tsma
|
||||||
SMA_STORAGE_LEVEL_DFILESET = 1 // use days of TS data e.g. vnode${N}/tsdb/tsma/sma_index_uid/v2f1906.tsma
|
SMA_STORAGE_LEVEL_DFILESET = 1 // use days of TS data e.g. vnode${N}/tsdb/tsma/sma_index_uid/v2f1906.tsma
|
||||||
|
@ -46,6 +48,7 @@ typedef struct SPoolMem {
|
||||||
|
|
||||||
struct SSmaEnv {
|
struct SSmaEnv {
|
||||||
TdThreadRwlock lock;
|
TdThreadRwlock lock;
|
||||||
|
int8_t type;
|
||||||
TXN txn;
|
TXN txn;
|
||||||
SPoolMem *pPool;
|
SPoolMem *pPool;
|
||||||
SDiskID did;
|
SDiskID did;
|
||||||
|
@ -55,6 +58,7 @@ struct SSmaEnv {
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SMA_ENV_LOCK(env) ((env)->lock)
|
#define SMA_ENV_LOCK(env) ((env)->lock)
|
||||||
|
#define SMA_ENV_TYPE(env) ((env)->type)
|
||||||
#define SMA_ENV_DID(env) ((env)->did)
|
#define SMA_ENV_DID(env) ((env)->did)
|
||||||
#define SMA_ENV_ENV(env) ((env)->dbEnv)
|
#define SMA_ENV_ENV(env) ((env)->dbEnv)
|
||||||
#define SMA_ENV_PATH(env) ((env)->path)
|
#define SMA_ENV_PATH(env) ((env)->path)
|
||||||
|
@ -91,16 +95,45 @@ typedef struct {
|
||||||
* - TSDB_SMA_STAT_EXPIRED: 1) If sma calculation of history TS data is not finished; 2) Or if the TSDB is open,
|
* - TSDB_SMA_STAT_EXPIRED: 1) If sma calculation of history TS data is not finished; 2) Or if the TSDB is open,
|
||||||
* without information about its previous state.
|
* without information about its previous state.
|
||||||
* - TSDB_SMA_STAT_DROPPED: 1)sma dropped
|
* - TSDB_SMA_STAT_DROPPED: 1)sma dropped
|
||||||
|
* N.B. only applicable to tsma
|
||||||
*/
|
*/
|
||||||
int8_t state; // ETsdbSmaStat
|
int8_t state; // ETsdbSmaStat
|
||||||
SHashObj *expiredWindows; // key: skey of time window, value: N/A
|
SHashObj *expiredWindows; // key: skey of time window, value: N/A
|
||||||
STSma *pSma; // cache schema
|
STSma *pSma; // cache schema
|
||||||
} SSmaStatItem;
|
} SSmaStatItem;
|
||||||
|
|
||||||
|
#define RSMA_MAX_LEVEL 2
|
||||||
|
#define RSMA_TASK_INFO_HASH_SLOT 8
|
||||||
|
struct SRSmaInfo {
|
||||||
|
void *taskInfo[RSMA_MAX_LEVEL]; // qTaskInfo_t
|
||||||
|
};
|
||||||
|
|
||||||
struct SSmaStat {
|
struct SSmaStat {
|
||||||
SHashObj *smaStatItems; // key: indexUid, value: SSmaStatItem
|
union {
|
||||||
|
SHashObj *smaStatItems; // key: indexUid, value: SSmaStatItem for tsma
|
||||||
|
SHashObj *rsmaInfoHash; // key: stbUid, value: SRSmaInfo;
|
||||||
|
};
|
||||||
T_REF_DECLARE()
|
T_REF_DECLARE()
|
||||||
};
|
};
|
||||||
|
#define SMA_STAT_ITEMS(s) ((s)->smaStatItems)
|
||||||
|
#define SMA_STAT_INFO_HASH(s) ((s)->rsmaInfoHash)
|
||||||
|
|
||||||
|
static FORCE_INLINE void tsdbFreeTaskHandle(qTaskInfo_t *taskHandle) {
|
||||||
|
// Note: free/kill may in RC
|
||||||
|
qTaskInfo_t otaskHandle = atomic_load_ptr(taskHandle);
|
||||||
|
if (otaskHandle && atomic_val_compare_exchange_ptr(taskHandle, otaskHandle, NULL)) {
|
||||||
|
qDestroyTask(otaskHandle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE void *tsdbFreeRSmaInfo(SRSmaInfo *pInfo) {
|
||||||
|
for (int32_t i = 0; i < RSMA_MAX_LEVEL; ++i) {
|
||||||
|
if (pInfo->taskInfo[i]) {
|
||||||
|
tsdbFreeTaskHandle(pInfo->taskInfo[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// declaration of static functions
|
// declaration of static functions
|
||||||
|
|
||||||
|
@ -108,11 +141,11 @@ struct SSmaStat {
|
||||||
static int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t version);
|
static int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t version);
|
||||||
static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t indexUid, int64_t winSKey,
|
static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t indexUid, int64_t winSKey,
|
||||||
int64_t version);
|
int64_t version);
|
||||||
static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat);
|
static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat, int8_t smaType);
|
||||||
static void *tsdbFreeSmaStatItem(SSmaStatItem *pSmaStatItem);
|
static void *tsdbFreeSmaStatItem(SSmaStatItem *pSmaStatItem);
|
||||||
static int32_t tsdbDestroySmaState(SSmaStat *pSmaStat);
|
static int32_t tsdbDestroySmaState(SSmaStat *pSmaStat, int8_t smaType);
|
||||||
static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did);
|
static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, int8_t smaType, const char *path, SDiskID did);
|
||||||
static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SDiskID did, SSmaEnv **pEnv);
|
static int32_t tsdbInitSmaEnv(STsdb *pTsdb, int8_t smaType, const char *path, SDiskID did, SSmaEnv **pEnv);
|
||||||
static int32_t tsdbResetExpiredWindow(STsdb *pTsdb, SSmaStat *pStat, int64_t indexUid, TSKEY skey);
|
static int32_t tsdbResetExpiredWindow(STsdb *pTsdb, SSmaStat *pStat, int64_t indexUid, TSKEY skey);
|
||||||
static int32_t tsdbRefSmaStat(STsdb *pTsdb, SSmaStat *pStat);
|
static int32_t tsdbRefSmaStat(STsdb *pTsdb, SSmaStat *pStat);
|
||||||
static int32_t tsdbUnRefSmaStat(STsdb *pTsdb, SSmaStat *pStat);
|
static int32_t tsdbUnRefSmaStat(STsdb *pTsdb, SSmaStat *pStat);
|
||||||
|
@ -139,6 +172,7 @@ static void tsdbGetSmaDir(int32_t vgId, ETsdbSmaType smaType, char dirName[])
|
||||||
static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char *msg);
|
static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char *msg);
|
||||||
static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, const char *msg);
|
static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, const char *msg);
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tsdbUpdateTbUidListImpl(STsdb *pTsdb, tb_uid_t *suid, SArray *tbUids);
|
||||||
// mgmt interface
|
// mgmt interface
|
||||||
static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid);
|
static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid);
|
||||||
|
|
||||||
|
@ -229,7 +263,7 @@ static void *poolMalloc(void *arg, size_t size) {
|
||||||
SPoolMem *pMem;
|
SPoolMem *pMem;
|
||||||
|
|
||||||
pMem = (SPoolMem *)tdbOsMalloc(sizeof(*pMem) + size);
|
pMem = (SPoolMem *)tdbOsMalloc(sizeof(*pMem) + size);
|
||||||
if (pMem == NULL) {
|
if (!pMem) {
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,15 +351,17 @@ static void tsdbGetSmaDir(int32_t vgId, ETsdbSmaType smaType, char dirName[]) {
|
||||||
snprintf(dirName, TSDB_FILENAME_LEN, "vnode%svnode%d%s%s", TD_DIRSEP, vgId, TD_DIRSEP, TSDB_SMA_DNAME[smaType]);
|
snprintf(dirName, TSDB_FILENAME_LEN, "vnode%svnode%d%s%s", TD_DIRSEP, vgId, TD_DIRSEP, TSDB_SMA_DNAME[smaType]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did) {
|
static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, int8_t smaType, const char *path, SDiskID did) {
|
||||||
SSmaEnv *pEnv = NULL;
|
SSmaEnv *pEnv = NULL;
|
||||||
|
|
||||||
pEnv = (SSmaEnv *)taosMemoryCalloc(1, sizeof(SSmaEnv));
|
pEnv = (SSmaEnv *)taosMemoryCalloc(1, sizeof(SSmaEnv));
|
||||||
if (pEnv == NULL) {
|
if (!pEnv) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SMA_ENV_TYPE(pEnv) = smaType;
|
||||||
|
|
||||||
int code = taosThreadRwlockInit(&(pEnv->lock), NULL);
|
int code = taosThreadRwlockInit(&(pEnv->lock), NULL);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
terrno = TAOS_SYSTEM_ERROR(code);
|
||||||
|
@ -334,15 +370,15 @@ static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did)
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(path && (strlen(path) > 0));
|
ASSERT(path && (strlen(path) > 0));
|
||||||
pEnv->path = strdup(path);
|
SMA_ENV_PATH(pEnv) = strdup(path);
|
||||||
if (pEnv->path == NULL) {
|
if (!SMA_ENV_PATH(pEnv)) {
|
||||||
tsdbFreeSmaEnv(pEnv);
|
tsdbFreeSmaEnv(pEnv);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pEnv->did = did;
|
SMA_ENV_DID(pEnv) = did;
|
||||||
|
|
||||||
if (tsdbInitSmaStat(&pEnv->pStat) != TSDB_CODE_SUCCESS) {
|
if (tsdbInitSmaStat(&SMA_ENV_STAT(pEnv), smaType) != TSDB_CODE_SUCCESS) {
|
||||||
tsdbFreeSmaEnv(pEnv);
|
tsdbFreeSmaEnv(pEnv);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -354,7 +390,7 @@ static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pEnv->pPool = openPool()) == NULL) {
|
if (!(pEnv->pPool = openPool())) {
|
||||||
tsdbFreeSmaEnv(pEnv);
|
tsdbFreeSmaEnv(pEnv);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -362,14 +398,14 @@ static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did)
|
||||||
return pEnv;
|
return pEnv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SDiskID did, SSmaEnv **pEnv) {
|
static int32_t tsdbInitSmaEnv(STsdb *pTsdb, int8_t smaType, const char *path, SDiskID did, SSmaEnv **pEnv) {
|
||||||
if (!pEnv) {
|
if (!pEnv) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
terrno = TSDB_CODE_INVALID_PTR;
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*pEnv == NULL) {
|
if (!(*pEnv)) {
|
||||||
if ((*pEnv = tsdbNewSmaEnv(pTsdb, path, did)) == NULL) {
|
if (!(*pEnv = tsdbNewSmaEnv(pTsdb, smaType, path, did))) {
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -385,7 +421,7 @@ static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SDiskID did, SSmaE
|
||||||
*/
|
*/
|
||||||
void tsdbDestroySmaEnv(SSmaEnv *pSmaEnv) {
|
void tsdbDestroySmaEnv(SSmaEnv *pSmaEnv) {
|
||||||
if (pSmaEnv) {
|
if (pSmaEnv) {
|
||||||
tsdbDestroySmaState(pSmaEnv->pStat);
|
tsdbDestroySmaState(pSmaEnv->pStat, SMA_ENV_TYPE(pSmaEnv));
|
||||||
taosMemoryFreeClear(pSmaEnv->pStat);
|
taosMemoryFreeClear(pSmaEnv->pStat);
|
||||||
taosMemoryFreeClear(pSmaEnv->path);
|
taosMemoryFreeClear(pSmaEnv->path);
|
||||||
taosThreadRwlockDestroy(&(pSmaEnv->lock));
|
taosThreadRwlockDestroy(&(pSmaEnv->lock));
|
||||||
|
@ -401,7 +437,7 @@ void *tsdbFreeSmaEnv(SSmaEnv *pSmaEnv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tsdbRefSmaStat(STsdb *pTsdb, SSmaStat *pStat) {
|
static int32_t tsdbRefSmaStat(STsdb *pTsdb, SSmaStat *pStat) {
|
||||||
if (pStat == NULL) return 0;
|
if (!pStat) return 0;
|
||||||
|
|
||||||
int ref = T_REF_INC(pStat);
|
int ref = T_REF_INC(pStat);
|
||||||
tsdbDebug("vgId:%d ref sma stat:%p, val:%d", REPO_ID(pTsdb), pStat, ref);
|
tsdbDebug("vgId:%d ref sma stat:%p, val:%d", REPO_ID(pTsdb), pStat, ref);
|
||||||
|
@ -409,17 +445,17 @@ static int32_t tsdbRefSmaStat(STsdb *pTsdb, SSmaStat *pStat) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tsdbUnRefSmaStat(STsdb *pTsdb, SSmaStat *pStat) {
|
static int32_t tsdbUnRefSmaStat(STsdb *pTsdb, SSmaStat *pStat) {
|
||||||
if (pStat == NULL) return 0;
|
if (!pStat) return 0;
|
||||||
|
|
||||||
int ref = T_REF_DEC(pStat);
|
int ref = T_REF_DEC(pStat);
|
||||||
tsdbDebug("vgId:%d unref sma stat:%p, val:%d", REPO_ID(pTsdb), pStat, ref);
|
tsdbDebug("vgId:%d unref sma stat:%p, val:%d", REPO_ID(pTsdb), pStat, ref);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat) {
|
static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat, int8_t smaType) {
|
||||||
ASSERT(pSmaStat != NULL);
|
ASSERT(pSmaStat != NULL);
|
||||||
|
|
||||||
if (*pSmaStat != NULL) { // no lock
|
if (*pSmaStat) { // no lock
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,19 +464,31 @@ static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat) {
|
||||||
* 2. Currently, there is mutex lock when init SSmaEnv, thus no need add lock on SSmaStat, and please add lock if
|
* 2. Currently, there is mutex lock when init SSmaEnv, thus no need add lock on SSmaStat, and please add lock if
|
||||||
* tsdbInitSmaStat invoked in other multithread environment later.
|
* tsdbInitSmaStat invoked in other multithread environment later.
|
||||||
*/
|
*/
|
||||||
if (*pSmaStat == NULL) {
|
if (!(*pSmaStat)) {
|
||||||
*pSmaStat = (SSmaStat *)taosMemoryCalloc(1, sizeof(SSmaStat));
|
*pSmaStat = (SSmaStat *)taosMemoryCalloc(1, sizeof(SSmaStat));
|
||||||
if (*pSmaStat == NULL) {
|
if (!(*pSmaStat)) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*pSmaStat)->smaStatItems =
|
if (smaType == TSDB_SMA_TYPE_ROLLUP) {
|
||||||
taosHashInit(SMA_STATE_HASH_SLOT, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
SMA_STAT_INFO_HASH(*pSmaStat) = taosHashInit(
|
||||||
|
RSMA_TASK_INFO_HASH_SLOT, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK);
|
||||||
|
|
||||||
if ((*pSmaStat)->smaStatItems == NULL) {
|
if (!SMA_STAT_INFO_HASH(*pSmaStat)) {
|
||||||
taosMemoryFreeClear(*pSmaStat);
|
taosMemoryFreeClear(*pSmaStat);
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
} else if (smaType == TSDB_SMA_TYPE_TIME_RANGE) {
|
||||||
|
SMA_STAT_ITEMS(*pSmaStat) =
|
||||||
|
taosHashInit(SMA_STATE_HASH_SLOT, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||||
|
|
||||||
|
if (!SMA_STAT_ITEMS(*pSmaStat)) {
|
||||||
|
taosMemoryFreeClear(*pSmaStat);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ASSERT(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -462,7 +510,7 @@ static SSmaStatItem *tsdbNewSmaStatItem(int8_t state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *tsdbFreeSmaStatItem(SSmaStatItem *pSmaStatItem) {
|
static void *tsdbFreeSmaStatItem(SSmaStatItem *pSmaStatItem) {
|
||||||
if (pSmaStatItem != NULL) {
|
if (pSmaStatItem) {
|
||||||
tdDestroyTSma(pSmaStatItem->pSma);
|
tdDestroyTSma(pSmaStatItem->pSma);
|
||||||
taosMemoryFreeClear(pSmaStatItem->pSma);
|
taosMemoryFreeClear(pSmaStatItem->pSma);
|
||||||
taosHashCleanup(pSmaStatItem->expiredWindows);
|
taosHashCleanup(pSmaStatItem->expiredWindows);
|
||||||
|
@ -477,16 +525,28 @@ static void *tsdbFreeSmaStatItem(SSmaStatItem *pSmaStatItem) {
|
||||||
* @param pSmaStat
|
* @param pSmaStat
|
||||||
* @return int32_t
|
* @return int32_t
|
||||||
*/
|
*/
|
||||||
int32_t tsdbDestroySmaState(SSmaStat *pSmaStat) {
|
int32_t tsdbDestroySmaState(SSmaStat *pSmaStat, int8_t smaType) {
|
||||||
if (pSmaStat) {
|
if (pSmaStat) {
|
||||||
// TODO: use taosHashSetFreeFp when taosHashSetFreeFp is ready.
|
// TODO: use taosHashSetFreeFp when taosHashSetFreeFp is ready.
|
||||||
void *item = taosHashIterate(pSmaStat->smaStatItems, NULL);
|
if (smaType == TSDB_SMA_TYPE_TIME_RANGE) {
|
||||||
while (item != NULL) {
|
void *item = taosHashIterate(SMA_STAT_ITEMS(pSmaStat), NULL);
|
||||||
SSmaStatItem *pItem = *(SSmaStatItem **)item;
|
while (item) {
|
||||||
tsdbFreeSmaStatItem(pItem);
|
SSmaStatItem *pItem = *(SSmaStatItem **)item;
|
||||||
item = taosHashIterate(pSmaStat->smaStatItems, item);
|
tsdbFreeSmaStatItem(pItem);
|
||||||
|
item = taosHashIterate(SMA_STAT_ITEMS(pSmaStat), item);
|
||||||
|
}
|
||||||
|
taosHashCleanup(SMA_STAT_ITEMS(pSmaStat));
|
||||||
|
} else if (smaType == TSDB_SMA_TYPE_ROLLUP) {
|
||||||
|
void *infoHash = taosHashIterate(SMA_STAT_INFO_HASH(pSmaStat), NULL);
|
||||||
|
while (infoHash) {
|
||||||
|
SRSmaInfo *pInfoHash = *(SRSmaInfo **)infoHash;
|
||||||
|
tsdbFreeRSmaInfo(pInfoHash);
|
||||||
|
infoHash = taosHashIterate(SMA_STAT_INFO_HASH(pSmaStat), infoHash);
|
||||||
|
}
|
||||||
|
taosHashCleanup(SMA_STAT_INFO_HASH(pSmaStat));
|
||||||
|
} else {
|
||||||
|
ASSERT(0);
|
||||||
}
|
}
|
||||||
taosHashCleanup(pSmaStat->smaStatItems);
|
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -497,12 +557,12 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
|
||||||
// return if already init
|
// return if already init
|
||||||
switch (smaType) {
|
switch (smaType) {
|
||||||
case TSDB_SMA_TYPE_TIME_RANGE:
|
case TSDB_SMA_TYPE_TIME_RANGE:
|
||||||
if ((pEnv = (SSmaEnv *)atomic_load_ptr(&REPO_TSMA_ENV(pTsdb))) != NULL) {
|
if ((pEnv = (SSmaEnv *)atomic_load_ptr(&REPO_TSMA_ENV(pTsdb)))) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TSDB_SMA_TYPE_ROLLUP:
|
case TSDB_SMA_TYPE_ROLLUP:
|
||||||
if ((pEnv = (SSmaEnv *)atomic_load_ptr(&REPO_RSMA_ENV(pTsdb))) != NULL) {
|
if ((pEnv = (SSmaEnv *)atomic_load_ptr(&REPO_RSMA_ENV(pTsdb)))) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -515,7 +575,7 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
|
||||||
tsdbLockRepo(pTsdb);
|
tsdbLockRepo(pTsdb);
|
||||||
pEnv = (smaType == TSDB_SMA_TYPE_TIME_RANGE) ? atomic_load_ptr(&REPO_TSMA_ENV(pTsdb))
|
pEnv = (smaType == TSDB_SMA_TYPE_TIME_RANGE) ? atomic_load_ptr(&REPO_TSMA_ENV(pTsdb))
|
||||||
: atomic_load_ptr(&REPO_RSMA_ENV(pTsdb));
|
: atomic_load_ptr(&REPO_RSMA_ENV(pTsdb));
|
||||||
if (pEnv == NULL) {
|
if (!pEnv) {
|
||||||
char rname[TSDB_FILENAME_LEN] = {0};
|
char rname[TSDB_FILENAME_LEN] = {0};
|
||||||
|
|
||||||
SDiskID did = {0};
|
SDiskID did = {0};
|
||||||
|
@ -531,7 +591,7 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tsdbInitSmaEnv(pTsdb, rname, did, &pEnv) != TSDB_CODE_SUCCESS) {
|
if (tsdbInitSmaEnv(pTsdb, smaType, rname, did, &pEnv) != TSDB_CODE_SUCCESS) {
|
||||||
tsdbUnlockRepo(pTsdb);
|
tsdbUnlockRepo(pTsdb);
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
@ -547,10 +607,10 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
|
||||||
static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t indexUid, int64_t winSKey,
|
static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t indexUid, int64_t winSKey,
|
||||||
int64_t version) {
|
int64_t version) {
|
||||||
SSmaStatItem *pItem = taosHashGet(pItemsHash, &indexUid, sizeof(indexUid));
|
SSmaStatItem *pItem = taosHashGet(pItemsHash, &indexUid, sizeof(indexUid));
|
||||||
if (pItem == NULL) {
|
if (!pItem) {
|
||||||
// TODO: use TSDB_SMA_STAT_EXPIRED and update by stream computing later
|
// TODO: use TSDB_SMA_STAT_EXPIRED and update by stream computing later
|
||||||
pItem = tsdbNewSmaStatItem(TSDB_SMA_STAT_OK); // TODO use the real state
|
pItem = tsdbNewSmaStatItem(TSDB_SMA_STAT_OK); // TODO use the real state
|
||||||
if (pItem == NULL) {
|
if (!pItem) {
|
||||||
// Response to stream computing: OOM
|
// Response to stream computing: OOM
|
||||||
// For query, if the indexUid not found, the TSDB should tell query module to query raw TS data.
|
// For query, if the indexUid not found, the TSDB should tell query module to query raw TS data.
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
|
@ -558,7 +618,7 @@ static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t
|
||||||
|
|
||||||
// cache smaMeta
|
// cache smaMeta
|
||||||
STSma *pSma = metaGetSmaInfoByIndex(REPO_META(pTsdb), indexUid, true);
|
STSma *pSma = metaGetSmaInfoByIndex(REPO_META(pTsdb), indexUid, true);
|
||||||
if (pSma == NULL) {
|
if (!pSma) {
|
||||||
terrno = TSDB_CODE_TDB_NO_SMA_INDEX_IN_META;
|
terrno = TSDB_CODE_TDB_NO_SMA_INDEX_IN_META;
|
||||||
taosHashCleanup(pItem->expiredWindows);
|
taosHashCleanup(pItem->expiredWindows);
|
||||||
taosMemoryFree(pItem);
|
taosMemoryFree(pItem);
|
||||||
|
@ -574,7 +634,7 @@ static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t
|
||||||
taosMemoryFree(pItem);
|
taosMemoryFree(pItem);
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
} else if ((pItem = *(SSmaStatItem **)pItem) == NULL) {
|
} else if (!(pItem = *(SSmaStatItem **)pItem)) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
terrno = TSDB_CODE_INVALID_PTR;
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
@ -618,9 +678,6 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t vers
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tdScanAndConvertSubmitMsg(pMsg) != TSDB_CODE_SUCCESS) {
|
|
||||||
return TSDB_CODE_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tsdbCheckAndInitSmaEnv(pTsdb, TSDB_SMA_TYPE_TIME_RANGE) != TSDB_CODE_SUCCESS) {
|
if (tsdbCheckAndInitSmaEnv(pTsdb, TSDB_SMA_TYPE_TIME_RANGE) != TSDB_CODE_SUCCESS) {
|
||||||
terrno = TSDB_CODE_TDB_INIT_FAILED;
|
terrno = TSDB_CODE_TDB_INIT_FAILED;
|
||||||
|
@ -634,7 +691,7 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t vers
|
||||||
SSmaStat *pStat = SMA_ENV_STAT(pEnv);
|
SSmaStat *pStat = SMA_ENV_STAT(pEnv);
|
||||||
SHashObj *pItemsHash = SMA_ENV_STAT_ITEMS(pEnv);
|
SHashObj *pItemsHash = SMA_ENV_STAT_ITEMS(pEnv);
|
||||||
|
|
||||||
TASSERT(pEnv != NULL && pStat != NULL && pItemsHash != NULL);
|
TASSERT(pEnv && pStat && pItemsHash);
|
||||||
|
|
||||||
// basic procedure
|
// basic procedure
|
||||||
// TODO: optimization
|
// TODO: optimization
|
||||||
|
@ -645,26 +702,26 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t vers
|
||||||
SInterval interval = {0};
|
SInterval interval = {0};
|
||||||
TSKEY lastWinSKey = INT64_MIN;
|
TSKEY lastWinSKey = INT64_MIN;
|
||||||
|
|
||||||
if (tInitSubmitMsgIter(pMsg, &msgIter) != TSDB_CODE_SUCCESS) {
|
if (tInitSubmitMsgIterEx(pMsg, &msgIter) != TSDB_CODE_SUCCESS) {
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
tGetSubmitMsgNext(&msgIter, &pBlock);
|
tGetSubmitMsgNextEx(&msgIter, &pBlock);
|
||||||
if (pBlock == NULL) break;
|
if (!pBlock) break;
|
||||||
|
|
||||||
STSmaWrapper *pSW = NULL;
|
STSmaWrapper *pSW = NULL;
|
||||||
STSma *pTSma = NULL;
|
STSma *pTSma = NULL;
|
||||||
|
|
||||||
SSubmitBlkIter blkIter = {0};
|
SSubmitBlkIter blkIter = {0};
|
||||||
if (tInitSubmitBlkIter(pBlock, &blkIter) != TSDB_CODE_SUCCESS) {
|
if (tInitSubmitBlkIterEx(&msgIter, pBlock, &blkIter) != TSDB_CODE_SUCCESS) {
|
||||||
pSW = tdFreeTSmaWrapper(pSW);
|
pSW = tdFreeTSmaWrapper(pSW);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
STSRow *row = tGetSubmitBlkNext(&blkIter);
|
STSRow *row = tGetSubmitBlkNextEx(&blkIter);
|
||||||
if (row == NULL) {
|
if (!row) {
|
||||||
tdFreeTSmaWrapper(pSW);
|
tdFreeTSmaWrapper(pSW);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -672,10 +729,10 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t vers
|
||||||
if (pSW) {
|
if (pSW) {
|
||||||
pSW = tdFreeTSmaWrapper(pSW);
|
pSW = tdFreeTSmaWrapper(pSW);
|
||||||
}
|
}
|
||||||
if ((pSW = metaGetSmaInfoByTable(REPO_META(pTsdb), pBlock->suid)) == NULL) {
|
if (!(pSW = metaGetSmaInfoByTable(REPO_META(pTsdb), pBlock->suid))) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ((pSW->number) <= 0 || (pSW->tSma == NULL)) {
|
if ((pSW->number) <= 0 || !pSW->tSma) {
|
||||||
pSW = tdFreeTSmaWrapper(pSW);
|
pSW = tdFreeTSmaWrapper(pSW);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -721,10 +778,10 @@ static int32_t tsdbResetExpiredWindow(STsdb *pTsdb, SSmaStat *pStat, int64_t ind
|
||||||
|
|
||||||
tsdbRefSmaStat(pTsdb, pStat);
|
tsdbRefSmaStat(pTsdb, pStat);
|
||||||
|
|
||||||
if (pStat && pStat->smaStatItems) {
|
if (pStat && SMA_STAT_ITEMS(pStat)) {
|
||||||
pItem = taosHashGet(pStat->smaStatItems, &indexUid, sizeof(indexUid));
|
pItem = taosHashGet(SMA_STAT_ITEMS(pStat), &indexUid, sizeof(indexUid));
|
||||||
}
|
}
|
||||||
if ((pItem != NULL) && ((pItem = *(SSmaStatItem **)pItem) != NULL)) {
|
if ((pItem) && ((pItem = *(SSmaStatItem **)pItem))) {
|
||||||
// pItem resides in hash buffer all the time unless drop sma index
|
// pItem resides in hash buffer all the time unless drop sma index
|
||||||
// TODO: multithread protect
|
// TODO: multithread protect
|
||||||
if (taosHashRemove(pItem->expiredWindows, &skey, sizeof(TSKEY)) != 0) {
|
if (taosHashRemove(pItem->expiredWindows, &skey, sizeof(TSKEY)) != 0) {
|
||||||
|
@ -934,7 +991,7 @@ static void tsdbDestroyTSmaWriteH(STSmaWriteH *pSmaH) {
|
||||||
|
|
||||||
static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, int64_t indexUid, int32_t fid) {
|
static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, int64_t indexUid, int32_t fid) {
|
||||||
STsdb *pTsdb = pSmaH->pTsdb;
|
STsdb *pTsdb = pSmaH->pTsdb;
|
||||||
ASSERT(pSmaH->dFile.path == NULL && pSmaH->dFile.pDB == NULL);
|
ASSERT(!pSmaH->dFile.path && !pSmaH->dFile.pDB);
|
||||||
|
|
||||||
pSmaH->dFile.fid = fid;
|
pSmaH->dFile.fid = fid;
|
||||||
char tSmaFile[TSDB_FILENAME_LEN] = {0};
|
char tSmaFile[TSDB_FILENAME_LEN] = {0};
|
||||||
|
@ -1004,6 +1061,8 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
|
||||||
STsdbCfg *pCfg = REPO_CFG(pTsdb);
|
STsdbCfg *pCfg = REPO_CFG(pTsdb);
|
||||||
const SArray *pDataBlocks = (const SArray *)msg;
|
const SArray *pDataBlocks = (const SArray *)msg;
|
||||||
|
|
||||||
|
// TODO: destroy SSDataBlocks(msg)
|
||||||
|
|
||||||
// For super table aggregation, the sma data is stored in vgroup calculated from the hash value of stable name. Thus
|
// For super table aggregation, the sma data is stored in vgroup calculated from the hash value of stable name. Thus
|
||||||
// the sma data would arrive ahead of the update-expired-window msg.
|
// the sma data would arrive ahead of the update-expired-window msg.
|
||||||
if (tsdbCheckAndInitSmaEnv(pTsdb, TSDB_SMA_TYPE_TIME_RANGE) != TSDB_CODE_SUCCESS) {
|
if (tsdbCheckAndInitSmaEnv(pTsdb, TSDB_SMA_TYPE_TIME_RANGE) != TSDB_CODE_SUCCESS) {
|
||||||
|
@ -1011,7 +1070,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pDataBlocks == NULL) {
|
if (!pDataBlocks) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
terrno = TSDB_CODE_INVALID_PTR;
|
||||||
tsdbWarn("vgId:%d insert tSma data failed since pDataBlocks is NULL", REPO_ID(pTsdb));
|
tsdbWarn("vgId:%d insert tSma data failed since pDataBlocks is NULL", REPO_ID(pTsdb));
|
||||||
return terrno;
|
return terrno;
|
||||||
|
@ -1029,11 +1088,11 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
|
||||||
|
|
||||||
tsdbRefSmaStat(pTsdb, pStat);
|
tsdbRefSmaStat(pTsdb, pStat);
|
||||||
|
|
||||||
if (pStat && pStat->smaStatItems) {
|
if (pStat && SMA_STAT_ITEMS(pStat)) {
|
||||||
pItem = taosHashGet(pStat->smaStatItems, &indexUid, sizeof(indexUid));
|
pItem = taosHashGet(SMA_STAT_ITEMS(pStat), &indexUid, sizeof(indexUid));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pItem == NULL) || ((pItem = *(SSmaStatItem **)pItem) == NULL) || tsdbSmaStatIsDropped(pItem)) {
|
if (!pItem || !(pItem = *(SSmaStatItem **)pItem) || tsdbSmaStatIsDropped(pItem)) {
|
||||||
terrno = TSDB_CODE_TDB_INVALID_SMA_STAT;
|
terrno = TSDB_CODE_TDB_INVALID_SMA_STAT;
|
||||||
tsdbUnRefSmaStat(pTsdb, pStat);
|
tsdbUnRefSmaStat(pTsdb, pStat);
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
|
@ -1061,9 +1120,8 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
|
||||||
int32_t storageLevel = tsdbGetSmaStorageLevel(pSma->interval, pSma->intervalUnit);
|
int32_t storageLevel = tsdbGetSmaStorageLevel(pSma->interval, pSma->intervalUnit);
|
||||||
int32_t daysPerFile = tsdbGetTSmaDays(pTsdb, tSmaH.interval, storageLevel);
|
int32_t daysPerFile = tsdbGetTSmaDays(pTsdb, tSmaH.interval, storageLevel);
|
||||||
|
|
||||||
// key: skey + groupId
|
char smaKey[SMA_KEY_LEN] = {0}; // key: skey + groupId
|
||||||
char smaKey[SMA_KEY_LEN] = {0};
|
char dataBuf[512] = {0}; // val: aggr data // TODO: handle 512 buffer?
|
||||||
char dataBuf[512] = {0};
|
|
||||||
void *pDataBuf = NULL;
|
void *pDataBuf = NULL;
|
||||||
int32_t sz = taosArrayGetSize(pDataBlocks);
|
int32_t sz = taosArrayGetSize(pDataBlocks);
|
||||||
for (int32_t i = 0; i < sz; ++i) {
|
for (int32_t i = 0; i < sz; ++i) {
|
||||||
|
@ -1228,7 +1286,7 @@ static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid) {
|
||||||
tsdbDebug("vgId:%d drop tSma local cache for %" PRIi64, REPO_ID(pTsdb), indexUid);
|
tsdbDebug("vgId:%d drop tSma local cache for %" PRIi64, REPO_ID(pTsdb), indexUid);
|
||||||
|
|
||||||
SSmaStatItem *pItem = taosHashGet(SMA_ENV_STAT_ITEMS(pEnv), &indexUid, sizeof(indexUid));
|
SSmaStatItem *pItem = taosHashGet(SMA_ENV_STAT_ITEMS(pEnv), &indexUid, sizeof(indexUid));
|
||||||
if ((pItem != NULL) || ((pItem = *(SSmaStatItem **)pItem) != NULL)) {
|
if ((pItem) || ((pItem = *(SSmaStatItem **)pItem))) {
|
||||||
if (tsdbSmaStatIsDropped(pItem)) {
|
if (tsdbSmaStatIsDropped(pItem)) {
|
||||||
tsdbDebug("vgId:%d tSma stat is already dropped for %" PRIi64, REPO_ID(pTsdb), indexUid);
|
tsdbDebug("vgId:%d tSma stat is already dropped for %" PRIi64, REPO_ID(pTsdb), indexUid);
|
||||||
return TSDB_CODE_TDB_INVALID_ACTION; // TODO: duplicate drop msg would be intercepted by mnode
|
return TSDB_CODE_TDB_INVALID_ACTION; // TODO: duplicate drop msg would be intercepted by mnode
|
||||||
|
@ -1284,19 +1342,13 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, const char *msg) {
|
||||||
SSmaEnv *pEnv = atomic_load_ptr(&REPO_RSMA_ENV(pTsdb));
|
SSmaEnv *pEnv = atomic_load_ptr(&REPO_RSMA_ENV(pTsdb));
|
||||||
int64_t indexUid = SMA_TEST_INDEX_UID;
|
int64_t indexUid = SMA_TEST_INDEX_UID;
|
||||||
|
|
||||||
if (pEnv == NULL) {
|
if (!pEnv) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
terrno = TSDB_CODE_INVALID_PTR;
|
||||||
tsdbWarn("vgId:%d insert rSma data failed since pTSmaEnv is NULL", REPO_ID(pTsdb));
|
tsdbWarn("vgId:%d insert rSma data failed since pTSmaEnv is NULL", REPO_ID(pTsdb));
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pEnv == NULL) {
|
if (!pDataBlocks) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
|
||||||
tsdbWarn("vgId:%d insert rSma data failed since pTSmaEnv is NULL", REPO_ID(pTsdb));
|
|
||||||
return terrno;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pDataBlocks == NULL) {
|
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
terrno = TSDB_CODE_INVALID_PTR;
|
||||||
tsdbWarn("vgId:%d insert rSma data failed since pDataBlocks is NULL", REPO_ID(pTsdb));
|
tsdbWarn("vgId:%d insert rSma data failed since pDataBlocks is NULL", REPO_ID(pTsdb));
|
||||||
return terrno;
|
return terrno;
|
||||||
|
@ -1313,11 +1365,11 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, const char *msg) {
|
||||||
|
|
||||||
tsdbRefSmaStat(pTsdb, pStat);
|
tsdbRefSmaStat(pTsdb, pStat);
|
||||||
|
|
||||||
if (pStat && pStat->smaStatItems) {
|
if (pStat && SMA_STAT_ITEMS(pStat)) {
|
||||||
pItem = taosHashGet(pStat->smaStatItems, &indexUid, sizeof(indexUid));
|
pItem = taosHashGet(SMA_STAT_ITEMS(pStat), &indexUid, sizeof(indexUid));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pItem == NULL) || ((pItem = *(SSmaStatItem **)pItem) == NULL) || tsdbSmaStatIsDropped(pItem)) {
|
if (!pItem || !(pItem = *(SSmaStatItem **)pItem) || tsdbSmaStatIsDropped(pItem)) {
|
||||||
terrno = TSDB_CODE_TDB_INVALID_SMA_STAT;
|
terrno = TSDB_CODE_TDB_INVALID_SMA_STAT;
|
||||||
tsdbUnRefSmaStat(pTsdb, pStat);
|
tsdbUnRefSmaStat(pTsdb, pStat);
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
|
@ -1438,7 +1490,7 @@ static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey) {
|
||||||
++pReadH->smaFsIter.iter;
|
++pReadH->smaFsIter.iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pReadH->pDFile != NULL) {
|
if (pReadH->pDFile) {
|
||||||
tsdbDebug("vg%d: smaFile %s matched", REPO_ID(pReadH->pTsdb), "[pSmaFile dir]");
|
tsdbDebug("vg%d: smaFile %s matched", REPO_ID(pReadH->pTsdb), "[pSmaFile dir]");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1471,7 +1523,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid,
|
||||||
|
|
||||||
tsdbRefSmaStat(pTsdb, pStat);
|
tsdbRefSmaStat(pTsdb, pStat);
|
||||||
SSmaStatItem *pItem = taosHashGet(SMA_ENV_STAT_ITEMS(pEnv), &indexUid, sizeof(indexUid));
|
SSmaStatItem *pItem = taosHashGet(SMA_ENV_STAT_ITEMS(pEnv), &indexUid, sizeof(indexUid));
|
||||||
if ((pItem == NULL) || ((pItem = *(SSmaStatItem **)pItem) == NULL)) {
|
if (!pItem || !(pItem = *(SSmaStatItem **)pItem)) {
|
||||||
// Normally pItem should not be NULL, mark all windows as expired and notify query module to fetch raw TS data if
|
// Normally pItem should not be NULL, mark all windows as expired and notify query module to fetch raw TS data if
|
||||||
// it's NULL.
|
// it's NULL.
|
||||||
tsdbUnRefSmaStat(pTsdb, pStat);
|
tsdbUnRefSmaStat(pTsdb, pStat);
|
||||||
|
@ -1484,7 +1536,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid,
|
||||||
int32_t nQueryWin = taosArrayGetSize(pQuerySKey);
|
int32_t nQueryWin = taosArrayGetSize(pQuerySKey);
|
||||||
for (int32_t n = 0; n < nQueryWin; ++n) {
|
for (int32_t n = 0; n < nQueryWin; ++n) {
|
||||||
TSKEY skey = taosArrayGet(pQuerySKey, n);
|
TSKEY skey = taosArrayGet(pQuerySKey, n);
|
||||||
if (taosHashGet(pItem->expiredWindows, &skey, sizeof(TSKEY)) != NULL) {
|
if (taosHashGet(pItem->expiredWindows, &skey, sizeof(TSKEY))) {
|
||||||
// TODO: mark this window as expired.
|
// TODO: mark this window as expired.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1500,7 +1552,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid,
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosHashGet(pItem->expiredWindows, &querySKey, sizeof(TSKEY)) != NULL) {
|
if (taosHashGet(pItem->expiredWindows, &querySKey, sizeof(TSKEY))) {
|
||||||
// TODO: mark this window as expired.
|
// TODO: mark this window as expired.
|
||||||
tsdbDebug("vgId:%d skey %" PRIi64 " of window exists in expired window for index %" PRIi64, REPO_ID(pTsdb),
|
tsdbDebug("vgId:%d skey %" PRIi64 " of window exists in expired window for index %" PRIi64, REPO_ID(pTsdb),
|
||||||
querySKey, indexUid);
|
querySKey, indexUid);
|
||||||
|
@ -1534,7 +1586,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid,
|
||||||
|
|
||||||
void *result = NULL;
|
void *result = NULL;
|
||||||
int32_t valueSize = 0;
|
int32_t valueSize = 0;
|
||||||
if ((result = tsdbGetSmaDataByKey(&tReadH.dFile, smaKey, SMA_KEY_LEN, &valueSize)) == NULL) {
|
if (!(result = tsdbGetSmaDataByKey(&tReadH.dFile, smaKey, SMA_KEY_LEN, &valueSize))) {
|
||||||
tsdbWarn("vgId:%d get sma data failed from smaIndex %" PRIi64 ", smaKey %" PRIx64 "-%" PRIx64 " since %s",
|
tsdbWarn("vgId:%d get sma data failed from smaIndex %" PRIi64 ", smaKey %" PRIx64 "-%" PRIx64 " since %s",
|
||||||
REPO_ID(pTsdb), indexUid, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), tstrerror(terrno));
|
REPO_ID(pTsdb), indexUid, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), tstrerror(terrno));
|
||||||
tsdbCloseDBF(&tReadH.dFile);
|
tsdbCloseDBF(&tReadH.dFile);
|
||||||
|
@ -1578,7 +1630,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid,
|
||||||
|
|
||||||
int32_t tsdbCreateTSma(STsdb *pTsdb, char *pMsg) {
|
int32_t tsdbCreateTSma(STsdb *pTsdb, char *pMsg) {
|
||||||
SSmaCfg vCreateSmaReq = {0};
|
SSmaCfg vCreateSmaReq = {0};
|
||||||
if (tDeserializeSVCreateTSmaReq(pMsg, &vCreateSmaReq) == NULL) {
|
if (!tDeserializeSVCreateTSmaReq(pMsg, &vCreateSmaReq)) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
tsdbWarn("vgId:%d TDMT_VND_CREATE_SMA received but deserialize failed since %s", REPO_ID(pTsdb), terrstr(terrno));
|
tsdbWarn("vgId:%d TDMT_VND_CREATE_SMA received but deserialize failed since %s", REPO_ID(pTsdb), terrstr(terrno));
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1604,7 +1656,7 @@ int32_t tsdbCreateTSma(STsdb *pTsdb, char *pMsg) {
|
||||||
|
|
||||||
int32_t tsdbDropTSma(STsdb *pTsdb, char *pMsg) {
|
int32_t tsdbDropTSma(STsdb *pTsdb, char *pMsg) {
|
||||||
SVDropTSmaReq vDropSmaReq = {0};
|
SVDropTSmaReq vDropSmaReq = {0};
|
||||||
if (tDeserializeSVDropTSmaReq(pMsg, &vDropSmaReq) == NULL) {
|
if (!tDeserializeSVDropTSmaReq(pMsg, &vDropSmaReq)) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1632,6 +1684,401 @@ int32_t tsdbDropTSma(STsdb *pTsdb, char *pMsg) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check and init qTaskInfo_t, only applicable to stable with SRSmaParam.
|
||||||
|
*
|
||||||
|
* @param pTsdb
|
||||||
|
* @param pMeta
|
||||||
|
* @param pReq
|
||||||
|
* @return int32_t
|
||||||
|
*/
|
||||||
|
int32_t tsdbRegisterRSma(STsdb *pTsdb, SMeta *pMeta, SVCreateTbReq *pReq) {
|
||||||
|
SRSmaParam *param = pReq->stbCfg.pRSmaParam;
|
||||||
|
|
||||||
|
if (!param) {
|
||||||
|
tsdbDebug("vgId:%d return directly since no rollup for stable %s %" PRIi64, REPO_ID(pTsdb), pReq->name,
|
||||||
|
pReq->stbCfg.suid);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((param->qmsg1Len == 0) && (param->qmsg2Len == 0)) {
|
||||||
|
tsdbWarn("vgId:%d no qmsg1/qmsg2 for rollup stable %s %" PRIi64, REPO_ID(pTsdb), pReq->name, pReq->stbCfg.suid);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tsdbCheckAndInitSmaEnv(pTsdb, TSDB_SMA_TYPE_ROLLUP) != TSDB_CODE_SUCCESS) {
|
||||||
|
terrno = TSDB_CODE_TDB_INIT_FAILED;
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSmaEnv *pEnv = REPO_RSMA_ENV(pTsdb);
|
||||||
|
SSmaStat *pStat = SMA_ENV_STAT(pEnv);
|
||||||
|
SRSmaInfo *pRSmaInfo = NULL;
|
||||||
|
|
||||||
|
pRSmaInfo = taosHashGet(SMA_STAT_INFO_HASH(pStat), &pReq->stbCfg.suid, sizeof(tb_uid_t));
|
||||||
|
if (pRSmaInfo) {
|
||||||
|
tsdbWarn("vgId:%d rsma info already exists for stb: %s, %" PRIi64, REPO_ID(pTsdb), pReq->name, pReq->stbCfg.suid);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
pRSmaInfo = (SRSmaInfo *)taosMemoryCalloc(1, sizeof(SRSmaInfo));
|
||||||
|
if (!pRSmaInfo) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
STqReadHandle *pReadHandle = tqInitSubmitMsgScanner(pMeta);
|
||||||
|
if (!pReadHandle) {
|
||||||
|
taosMemoryFree(pRSmaInfo);
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
SReadHandle handle = {
|
||||||
|
.reader = pReadHandle,
|
||||||
|
.meta = pMeta,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (param->qmsg1) {
|
||||||
|
pRSmaInfo->taskInfo[0] = qCreateStreamExecTaskInfo(param->qmsg1, &handle);
|
||||||
|
if (!pRSmaInfo->taskInfo[0]) {
|
||||||
|
taosMemoryFree(pRSmaInfo);
|
||||||
|
taosMemoryFree(pReadHandle);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param->qmsg2) {
|
||||||
|
pRSmaInfo->taskInfo[1] = qCreateStreamExecTaskInfo(param->qmsg2, &handle);
|
||||||
|
if (!pRSmaInfo->taskInfo[1]) {
|
||||||
|
taosMemoryFree(pRSmaInfo);
|
||||||
|
taosMemoryFree(pReadHandle);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taosHashPut(SMA_STAT_INFO_HASH(pStat), &pReq->stbCfg.suid, sizeof(tb_uid_t), &pRSmaInfo, sizeof(pRSmaInfo)) !=
|
||||||
|
TSDB_CODE_SUCCESS) {
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
} else {
|
||||||
|
tsdbDebug("vgId:%d register rsma info succeed for suid:%" PRIi64, REPO_ID(pTsdb), pReq->stbCfg.suid);
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief store suid/[uids], prefer to use array and then hash
|
||||||
|
*
|
||||||
|
* @param pStore
|
||||||
|
* @param suid
|
||||||
|
* @param uid
|
||||||
|
* @return int32_t
|
||||||
|
*/
|
||||||
|
int32_t tsdbUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid) {
|
||||||
|
// prefer to store suid/uids in array
|
||||||
|
if ((suid == pStore->suid) || (pStore->suid == 0)) {
|
||||||
|
if (pStore->suid == 0) {
|
||||||
|
pStore->suid = suid;
|
||||||
|
}
|
||||||
|
if (uid) {
|
||||||
|
if (!pStore->tbUids) {
|
||||||
|
if (!(pStore->tbUids = taosArrayInit(1, sizeof(tb_uid_t)))) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!taosArrayPush(pStore->tbUids, uid)) {
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// store other suid/uids in hash when multiple stable/table included in 1 batch of request
|
||||||
|
if (!pStore->uidHash) {
|
||||||
|
pStore->uidHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
|
||||||
|
if (!pStore->uidHash) {
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (uid) {
|
||||||
|
SArray *uidArray = taosHashGet(pStore->uidHash, &suid, sizeof(tb_uid_t));
|
||||||
|
if (uidArray && ((uidArray = *(SArray **)uidArray))) {
|
||||||
|
taosArrayPush(uidArray, uid);
|
||||||
|
} else {
|
||||||
|
SArray *pUidArray = taosArrayInit(1, sizeof(tb_uid_t));
|
||||||
|
if (!pUidArray) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
if (!taosArrayPush(pUidArray, uid)) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
if (taosHashPut(pStore->uidHash, &suid, sizeof(suid), &pUidArray, sizeof(pUidArray)) != 0) {
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (taosHashPut(pStore->uidHash, &suid, sizeof(suid), NULL, 0) != 0) {
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tsdbUidStoreDestory(STbUidStore *pStore) {
|
||||||
|
if (pStore) {
|
||||||
|
if (pStore->uidHash) {
|
||||||
|
if (pStore->tbUids) {
|
||||||
|
void *pIter = taosHashIterate(pStore->uidHash, NULL);
|
||||||
|
while (pIter) {
|
||||||
|
SArray *arr = *(SArray **)pIter;
|
||||||
|
taosArrayDestroy(arr);
|
||||||
|
pIter = taosHashIterate(pStore->uidHash, pIter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
taosHashCleanup(pStore->uidHash);
|
||||||
|
}
|
||||||
|
taosArrayDestroy(pStore->tbUids);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void *tsdbUidStoreFree(STbUidStore *pStore) {
|
||||||
|
tsdbUidStoreDestory(pStore);
|
||||||
|
taosMemoryFree(pStore);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief fetch suid/uids when create child tables of rollup SMA
|
||||||
|
*
|
||||||
|
* @param pTsdb
|
||||||
|
* @param ppStore
|
||||||
|
* @param suid
|
||||||
|
* @param uid
|
||||||
|
* @return int32_t
|
||||||
|
*/
|
||||||
|
int32_t tsdbFetchTbUidList(void *pTsdb, void **ppStore, void *suid, void *uid) {
|
||||||
|
SSmaEnv *pEnv = REPO_RSMA_ENV((STsdb *)pTsdb);
|
||||||
|
|
||||||
|
// only applicable to rollup SMA ctables
|
||||||
|
if (!pEnv) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSmaStat *pStat = SMA_ENV_STAT(pEnv);
|
||||||
|
SHashObj *infoHash = NULL;
|
||||||
|
if (!pStat || !(infoHash = SMA_STAT_INFO_HASH(pStat))) {
|
||||||
|
terrno = TSDB_CODE_TDB_INVALID_SMA_STAT;
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
// info cached when create rsma stable and return directly for non-rsma ctables
|
||||||
|
if (!taosHashGet(infoHash, suid, sizeof(tb_uid_t))) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(*ppStore)) {
|
||||||
|
if (tsdbUidStoreInit((STbUidStore **)ppStore) != 0) {
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tsdbUidStorePut(*ppStore, *(tb_uid_t *)suid, (tb_uid_t *)uid) != 0) {
|
||||||
|
*ppStore = tsdbUidStoreFree(*ppStore);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tsdbUpdateTbUidListImpl(STsdb *pTsdb, tb_uid_t *suid, SArray *tbUids) {
|
||||||
|
SSmaEnv *pEnv = REPO_RSMA_ENV(pTsdb);
|
||||||
|
SSmaStat *pStat = SMA_ENV_STAT(pEnv);
|
||||||
|
SRSmaInfo *pRSmaInfo = NULL;
|
||||||
|
|
||||||
|
if (!suid || !tbUids) {
|
||||||
|
terrno = TSDB_CODE_INVALID_PTR;
|
||||||
|
tsdbError("vgId:%d failed to get rsma info for uid:%" PRIi64 " since %s", REPO_ID(pTsdb), *suid, terrstr(terrno));
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
pRSmaInfo = taosHashGet(SMA_STAT_INFO_HASH(pStat), suid, sizeof(tb_uid_t));
|
||||||
|
if (!pRSmaInfo || !(pRSmaInfo = *(SRSmaInfo **)pRSmaInfo)) {
|
||||||
|
tsdbError("vgId:%d failed to get rsma info for uid:%" PRIi64, REPO_ID(pTsdb), *suid);
|
||||||
|
terrno = TSDB_CODE_TDB_INVALID_SMA_STAT;
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pRSmaInfo->taskInfo[0] && (qUpdateQualifiedTableId(pRSmaInfo->taskInfo[0], tbUids, true) != 0)) {
|
||||||
|
tsdbError("vgId:%d update tbUidList failed for uid:%" PRIi64 " since %s", REPO_ID(pTsdb), *suid, terrstr(terrno));
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
} else {
|
||||||
|
tsdbDebug("vgId:%d update tbUidList succeed for qTaskInfo:%p with suid:%" PRIi64 ", uid:%" PRIi64, REPO_ID(pTsdb),
|
||||||
|
pRSmaInfo->taskInfo[0], *suid, *(int64_t *)taosArrayGet(tbUids, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pRSmaInfo->taskInfo[1] && (qUpdateQualifiedTableId(pRSmaInfo->taskInfo[1], tbUids, true) != 0)) {
|
||||||
|
tsdbError("vgId:%d update tbUidList failed for uid:%" PRIi64 " since %s", REPO_ID(pTsdb), *suid, terrstr(terrno));
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
} else {
|
||||||
|
tsdbDebug("vgId:%d update tbUidList succeed for qTaskInfo:%p with suid:%" PRIi64 ", uid:%" PRIi64, REPO_ID(pTsdb),
|
||||||
|
pRSmaInfo->taskInfo[1], *suid, *(int64_t *)taosArrayGet(tbUids, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tsdbUpdateTbUidList(STsdb *pTsdb, STbUidStore *pStore) {
|
||||||
|
if (!pStore || (taosArrayGetSize(pStore->tbUids) == 0)) {
|
||||||
|
tsdbDebug("vgId:%d no need to update tbUids since empty uidStore", REPO_ID(pTsdb));
|
||||||
|
tsdbUidStoreFree(pStore);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tsdbUpdateTbUidListImpl(pTsdb, &pStore->suid, pStore->tbUids) != TSDB_CODE_SUCCESS) {
|
||||||
|
tsdbUidStoreFree(pStore);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *pIter = taosHashIterate(pStore->uidHash, NULL);
|
||||||
|
while (pIter) {
|
||||||
|
tb_uid_t *pTbSuid = (tb_uid_t *)taosHashGetKey(pIter, NULL);
|
||||||
|
SArray *pTbUids = *(SArray **)pIter;
|
||||||
|
|
||||||
|
if (tsdbUpdateTbUidListImpl(pTsdb, pTbSuid, pTbUids) != TSDB_CODE_SUCCESS) {
|
||||||
|
taosHashCancelIterate(pStore->uidHash, pIter);
|
||||||
|
tsdbUidStoreFree(pStore);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
pIter = taosHashIterate(pStore->uidHash, pIter);
|
||||||
|
}
|
||||||
|
|
||||||
|
tsdbUidStoreFree(pStore);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tsdbFetchSubmitReqSuids(SSubmitReq *pMsg, STbUidStore *pStore) {
|
||||||
|
ASSERT(pMsg != NULL);
|
||||||
|
SSubmitMsgIter msgIter = {0};
|
||||||
|
SSubmitBlk *pBlock = NULL;
|
||||||
|
SSubmitBlkIter blkIter = {0};
|
||||||
|
STSRow *row = NULL;
|
||||||
|
|
||||||
|
terrno = TSDB_CODE_SUCCESS;
|
||||||
|
// pMsg->length = htonl(pMsg->length);
|
||||||
|
// pMsg->numOfBlocks = htonl(pMsg->numOfBlocks);
|
||||||
|
|
||||||
|
if (tInitSubmitMsgIterEx(pMsg, &msgIter) < 0) return -1;
|
||||||
|
while (true) {
|
||||||
|
if (tGetSubmitMsgNextEx(&msgIter, &pBlock) < 0) return -1;
|
||||||
|
|
||||||
|
if (!pBlock) break;
|
||||||
|
tsdbUidStorePut(pStore, msgIter.suid, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (terrno != TSDB_CODE_SUCCESS) return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tsdbExecuteRSma(STsdb *pTsdb, SMeta *pMeta, const void *pMsg, int32_t inputType, tb_uid_t *suid) {
|
||||||
|
SSmaEnv *pEnv = REPO_RSMA_ENV(pTsdb);
|
||||||
|
if (!pEnv) {
|
||||||
|
// only applicable when rsma env exists
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSmaStat *pStat = SMA_ENV_STAT(pEnv);
|
||||||
|
SRSmaInfo *pRSmaInfo = NULL;
|
||||||
|
|
||||||
|
pRSmaInfo = taosHashGet(SMA_STAT_INFO_HASH(pStat), suid, sizeof(tb_uid_t));
|
||||||
|
|
||||||
|
if (!pRSmaInfo || !(pRSmaInfo = *(SRSmaInfo **)pRSmaInfo)) {
|
||||||
|
tsdbDebug("vgId:%d no rsma info for suid:%" PRIu64, REPO_ID(pTsdb), *suid);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
SArray *pResult = NULL;
|
||||||
|
|
||||||
|
pResult = taosArrayInit(0, sizeof(SSDataBlock));
|
||||||
|
if (!pResult) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inputType == STREAM_DATA_TYPE_SUBMIT_BLOCK) {
|
||||||
|
if (pRSmaInfo->taskInfo[0]) {
|
||||||
|
tsdbDebug("vgId:%d execute rsma task for qTaskInfo:%p suid:%" PRIu64, REPO_ID(pTsdb), pRSmaInfo->taskInfo[0],
|
||||||
|
*suid);
|
||||||
|
qSetStreamInput(pRSmaInfo->taskInfo[0], pMsg, inputType);
|
||||||
|
while (1) {
|
||||||
|
SSDataBlock *output;
|
||||||
|
uint64_t ts;
|
||||||
|
if (qExecTask(pRSmaInfo->taskInfo[0], &output, &ts) < 0) {
|
||||||
|
ASSERT(false);
|
||||||
|
}
|
||||||
|
if (!output) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
taosArrayPush(pResult, output);
|
||||||
|
}
|
||||||
|
if (taosArrayGetSize(pResult) > 0) {
|
||||||
|
blockDebugShowData(pResult);
|
||||||
|
} else {
|
||||||
|
tsdbWarn("vgId:%d no sma data generated since %s", REPO_ID(pTsdb), tstrerror(terrno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (pRSmaInfo->taskInfo[1]) {
|
||||||
|
// qSetStreamInput(pRSmaInfo->taskInfo[1], pMsg, inputType);
|
||||||
|
// while (1) {
|
||||||
|
// SSDataBlock *output;
|
||||||
|
// uint64_t ts;
|
||||||
|
// if (qExecTask(pRSmaInfo->taskInfo[1], &output, &ts) < 0) {
|
||||||
|
// ASSERT(false);
|
||||||
|
// }
|
||||||
|
// if (!output) {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// taosArrayPush(pResult, output);
|
||||||
|
// }
|
||||||
|
// blockDebugShowData(pResult);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tsdbTriggerRSma(STsdb *pTsdb, SMeta *pMeta, void *pMsg, int32_t inputType) {
|
||||||
|
SSmaEnv *pEnv = REPO_RSMA_ENV(pTsdb);
|
||||||
|
if (!pEnv) {
|
||||||
|
// only applicable when rsma env exists
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inputType == STREAM_DATA_TYPE_SUBMIT_BLOCK) {
|
||||||
|
STbUidStore uidStore = {0};
|
||||||
|
tsdbFetchSubmitReqSuids(pMsg, &uidStore);
|
||||||
|
|
||||||
|
if (uidStore.suid != 0) {
|
||||||
|
tsdbExecuteRSma(pTsdb, pMeta, pMsg, inputType, &uidStore.suid);
|
||||||
|
|
||||||
|
void *pIter = taosHashIterate(uidStore.uidHash, NULL);
|
||||||
|
while (pIter) {
|
||||||
|
tb_uid_t *pTbSuid = (tb_uid_t *)taosHashGetKey(pIter, NULL);
|
||||||
|
tsdbExecuteRSma(pTsdb, pMeta, pMsg, inputType, pTbSuid);
|
||||||
|
pIter = taosHashIterate(uidStore.uidHash, pIter);
|
||||||
|
}
|
||||||
|
|
||||||
|
tsdbUidStoreDestory(&uidStore);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/**
|
/**
|
||||||
* @brief Get the start TS key of the last data block of one interval/sliding.
|
* @brief Get the start TS key of the last data block of one interval/sliding.
|
||||||
|
@ -1674,6 +2121,7 @@ int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg) {
|
||||||
if ((code = tsdbInsertTSmaDataImpl(pTsdb, indexUid, msg)) < 0) {
|
if ((code = tsdbInsertTSmaDataImpl(pTsdb, indexUid, msg)) < 0) {
|
||||||
tsdbWarn("vgId:%d insert tSma data failed since %s", REPO_ID(pTsdb), tstrerror(terrno));
|
tsdbWarn("vgId:%d insert tSma data failed since %s", REPO_ID(pTsdb), tstrerror(terrno));
|
||||||
}
|
}
|
||||||
|
// TODO: destroy SSDataBlocks(msg)
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "vnodeInt.h"
|
#include "vnodeInt.h"
|
||||||
|
#include "vnodeSync.h"
|
||||||
|
|
||||||
int vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) {
|
int vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) {
|
||||||
SVnodeInfo info = {0};
|
SVnodeInfo info = {0};
|
||||||
|
@ -171,6 +172,16 @@ void vnodeClose(SVnode *pVnode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// start the sync timer after the queue is ready
|
||||||
|
int32_t vnodeStart(SVnode *pVnode) {
|
||||||
|
vnodeSyncSetQ(pVnode, NULL);
|
||||||
|
vnodeSyncSetRpc(pVnode, NULL);
|
||||||
|
vnodeSyncStart(pVnode);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void vnodeStop(SVnode *pVnode) {}
|
||||||
|
|
||||||
int64_t vnodeGetSyncHandle(SVnode *pVnode) { return pVnode->sync; }
|
int64_t vnodeGetSyncHandle(SVnode *pVnode) { return pVnode->sync; }
|
||||||
|
|
||||||
void vnodeGetSnapshot(SVnode *pVnode, SSnapshot *pSnapshot) { pSnapshot->lastApplyIndex = pVnode->state.committed; }
|
void vnodeGetSnapshot(SVnode *pVnode, SSnapshot *pSnapshot) { pSnapshot->lastApplyIndex = pVnode->state.committed; }
|
|
@ -81,6 +81,7 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg
|
||||||
case TDMT_VND_DROP_TABLE:
|
case TDMT_VND_DROP_TABLE:
|
||||||
break;
|
break;
|
||||||
case TDMT_VND_SUBMIT:
|
case TDMT_VND_SUBMIT:
|
||||||
|
tsdbTriggerRSma(pVnode->pTsdb, pVnode->pMeta, ptr, STREAM_DATA_TYPE_SUBMIT_BLOCK);
|
||||||
pRsp->msgType = TDMT_VND_SUBMIT_RSP;
|
pRsp->msgType = TDMT_VND_SUBMIT_RSP;
|
||||||
vnodeProcessSubmitReq(pVnode, ptr, pRsp);
|
vnodeProcessSubmitReq(pVnode, ptr, pRsp);
|
||||||
break;
|
break;
|
||||||
|
@ -101,7 +102,6 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case TDMT_VND_CREATE_SMA: { // timeRangeSMA
|
case TDMT_VND_CREATE_SMA: { // timeRangeSMA
|
||||||
|
|
||||||
if (tsdbCreateTSma(pVnode->pTsdb, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) {
|
if (tsdbCreateTSma(pVnode->pTsdb, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||||
vTrace("message in query queue is processing");
|
vTrace("message in vnode query queue is processing");
|
||||||
SReadHandle handle = {.reader = pVnode->pTsdb, .meta = pVnode->pMeta, .config = &pVnode->config};
|
SReadHandle handle = {.reader = pVnode->pTsdb, .meta = pVnode->pMeta, .config = &pVnode->config};
|
||||||
|
|
||||||
switch (pMsg->msgType) {
|
switch (pMsg->msgType) {
|
||||||
|
@ -193,108 +193,105 @@ void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) {
|
||||||
|
|
||||||
// sync integration
|
// sync integration
|
||||||
int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||||
SSyncNode *pSyncNode = syncNodeAcquire(pVnode->sync);
|
|
||||||
assert(pSyncNode != NULL);
|
|
||||||
|
|
||||||
ESyncState state = syncGetMyRole(pVnode->sync);
|
if (syncEnvIsStart()) {
|
||||||
SyncTerm currentTerm = syncGetMyTerm(pVnode->sync);
|
|
||||||
|
|
||||||
SMsgHead *pHead = pMsg->pCont;
|
SSyncNode *pSyncNode = syncNodeAcquire(pVnode->sync);
|
||||||
|
assert(pSyncNode != NULL);
|
||||||
|
|
||||||
char logBuf[512];
|
ESyncState state = syncGetMyRole(pVnode->sync);
|
||||||
char *syncNodeStr = sync2SimpleStr(pVnode->sync);
|
SyncTerm currentTerm = syncGetMyTerm(pVnode->sync);
|
||||||
snprintf(logBuf, sizeof(logBuf), "==vnodeProcessSyncReq== msgType:%d, syncNode: %s", pMsg->msgType, syncNodeStr);
|
|
||||||
syncRpcMsgLog2(logBuf, pMsg);
|
|
||||||
taosMemoryFree(syncNodeStr);
|
|
||||||
|
|
||||||
SRpcMsg *pRpcMsg = pMsg;
|
SMsgHead *pHead = pMsg->pCont;
|
||||||
|
|
||||||
if (pRpcMsg->msgType == TDMT_VND_SYNC_TIMEOUT) {
|
char logBuf[512];
|
||||||
SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pRpcMsg);
|
char *syncNodeStr = sync2SimpleStr(pVnode->sync);
|
||||||
assert(pSyncMsg != NULL);
|
snprintf(logBuf, sizeof(logBuf), "==vnodeProcessSyncReq== msgType:%d, syncNode: %s", pMsg->msgType, syncNodeStr);
|
||||||
|
syncRpcMsgLog2(logBuf, pMsg);
|
||||||
|
taosMemoryFree(syncNodeStr);
|
||||||
|
|
||||||
syncNodeOnTimeoutCb(pSyncNode, pSyncMsg);
|
SRpcMsg *pRpcMsg = pMsg;
|
||||||
syncTimeoutDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pRpcMsg->msgType == TDMT_VND_SYNC_PING) {
|
if (pRpcMsg->msgType == TDMT_VND_SYNC_TIMEOUT) {
|
||||||
SyncPing *pSyncMsg = syncPingFromRpcMsg2(pRpcMsg);
|
SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pRpcMsg);
|
||||||
assert(pSyncMsg != NULL);
|
assert(pSyncMsg != NULL);
|
||||||
|
|
||||||
syncNodeOnPingCb(pSyncNode, pSyncMsg);
|
syncNodeOnTimeoutCb(pSyncNode, pSyncMsg);
|
||||||
syncPingDestroy(pSyncMsg);
|
syncTimeoutDestroy(pSyncMsg);
|
||||||
|
|
||||||
} else if (pRpcMsg->msgType == TDMT_VND_SYNC_PING_REPLY) {
|
} else if (pRpcMsg->msgType == TDMT_VND_SYNC_PING) {
|
||||||
SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pRpcMsg);
|
SyncPing *pSyncMsg = syncPingFromRpcMsg2(pRpcMsg);
|
||||||
assert(pSyncMsg != NULL);
|
assert(pSyncMsg != NULL);
|
||||||
|
|
||||||
syncNodeOnPingReplyCb(pSyncNode, pSyncMsg);
|
syncNodeOnPingCb(pSyncNode, pSyncMsg);
|
||||||
syncPingReplyDestroy(pSyncMsg);
|
syncPingDestroy(pSyncMsg);
|
||||||
|
|
||||||
} else if (pRpcMsg->msgType == TDMT_VND_SYNC_CLIENT_REQUEST) {
|
} else if (pRpcMsg->msgType == TDMT_VND_SYNC_PING_REPLY) {
|
||||||
SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pRpcMsg);
|
SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pRpcMsg);
|
||||||
assert(pSyncMsg != NULL);
|
assert(pSyncMsg != NULL);
|
||||||
|
|
||||||
syncNodeOnClientRequestCb(pSyncNode, pSyncMsg);
|
syncNodeOnPingReplyCb(pSyncNode, pSyncMsg);
|
||||||
syncClientRequestDestroy(pSyncMsg);
|
syncPingReplyDestroy(pSyncMsg);
|
||||||
|
|
||||||
} else if (pRpcMsg->msgType == TDMT_VND_SYNC_REQUEST_VOTE) {
|
} else if (pRpcMsg->msgType == TDMT_VND_SYNC_CLIENT_REQUEST) {
|
||||||
SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pRpcMsg);
|
SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pRpcMsg);
|
||||||
assert(pSyncMsg != NULL);
|
assert(pSyncMsg != NULL);
|
||||||
|
|
||||||
syncNodeOnRequestVoteCb(pSyncNode, pSyncMsg);
|
syncNodeOnClientRequestCb(pSyncNode, pSyncMsg);
|
||||||
syncRequestVoteDestroy(pSyncMsg);
|
syncClientRequestDestroy(pSyncMsg);
|
||||||
|
|
||||||
} else if (pRpcMsg->msgType == TDMT_VND_SYNC_REQUEST_VOTE_REPLY) {
|
} else if (pRpcMsg->msgType == TDMT_VND_SYNC_REQUEST_VOTE) {
|
||||||
SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pRpcMsg);
|
SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pRpcMsg);
|
||||||
assert(pSyncMsg != NULL);
|
assert(pSyncMsg != NULL);
|
||||||
|
|
||||||
syncNodeOnRequestVoteReplyCb(pSyncNode, pSyncMsg);
|
syncNodeOnRequestVoteCb(pSyncNode, pSyncMsg);
|
||||||
syncRequestVoteReplyDestroy(pSyncMsg);
|
syncRequestVoteDestroy(pSyncMsg);
|
||||||
|
|
||||||
} else if (pRpcMsg->msgType == TDMT_VND_SYNC_APPEND_ENTRIES) {
|
} else if (pRpcMsg->msgType == TDMT_VND_SYNC_REQUEST_VOTE_REPLY) {
|
||||||
SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pRpcMsg);
|
SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pRpcMsg);
|
||||||
assert(pSyncMsg != NULL);
|
assert(pSyncMsg != NULL);
|
||||||
|
|
||||||
syncNodeOnAppendEntriesCb(pSyncNode, pSyncMsg);
|
syncNodeOnRequestVoteReplyCb(pSyncNode, pSyncMsg);
|
||||||
syncAppendEntriesDestroy(pSyncMsg);
|
syncRequestVoteReplyDestroy(pSyncMsg);
|
||||||
|
|
||||||
} else if (pRpcMsg->msgType == TDMT_VND_SYNC_APPEND_ENTRIES_REPLY) {
|
} else if (pRpcMsg->msgType == TDMT_VND_SYNC_APPEND_ENTRIES) {
|
||||||
SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pRpcMsg);
|
SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pRpcMsg);
|
||||||
assert(pSyncMsg != NULL);
|
assert(pSyncMsg != NULL);
|
||||||
|
|
||||||
syncNodeOnAppendEntriesReplyCb(pSyncNode, pSyncMsg);
|
syncNodeOnAppendEntriesCb(pSyncNode, pSyncMsg);
|
||||||
syncAppendEntriesReplyDestroy(pSyncMsg);
|
syncAppendEntriesDestroy(pSyncMsg);
|
||||||
|
|
||||||
|
} else if (pRpcMsg->msgType == TDMT_VND_SYNC_APPEND_ENTRIES_REPLY) {
|
||||||
|
SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pRpcMsg);
|
||||||
|
assert(pSyncMsg != NULL);
|
||||||
|
|
||||||
|
syncNodeOnAppendEntriesReplyCb(pSyncNode, pSyncMsg);
|
||||||
|
syncAppendEntriesReplyDestroy(pSyncMsg);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
vError("==vnodeProcessSyncReq== error msg type:%d", pRpcMsg->msgType);
|
||||||
|
}
|
||||||
|
|
||||||
|
syncNodeRelease(pSyncNode);
|
||||||
} else {
|
} else {
|
||||||
vError("==vnodeProcessSyncReq== error msg type:%d", pRpcMsg->msgType);
|
vError("==vnodeProcessSyncReq== error syncEnv stop");
|
||||||
}
|
}
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vnodeProcessCreateStbReq(SVnode *pVnode, void *pReq) {
|
static int vnodeProcessCreateStbReq(SVnode *pVnode, void *pReq) {
|
||||||
SVCreateTbReq vCreateTbReq = {0};
|
SVCreateTbReq vCreateTbReq = {0};
|
||||||
tDeserializeSVCreateTbReq(pReq, &vCreateTbReq);
|
tDeserializeSVCreateTbReq(pReq, &vCreateTbReq);
|
||||||
if (metaCreateTable(pVnode->pMeta, &(vCreateTbReq)) < 0) {
|
if (metaCreateTable(pVnode->pMeta, &(vCreateTbReq), NULL) < 0) {
|
||||||
// TODO
|
// TODO
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove the debug log
|
tsdbRegisterRSma(pVnode->pTsdb, pVnode->pMeta, &vCreateTbReq);
|
||||||
SRSmaParam *param = vCreateTbReq.stbCfg.pRSmaParam;
|
|
||||||
if (param) {
|
|
||||||
printf("qmsg1 len = %d, body = %s\n", param->qmsg1 ? (int32_t)strlen(param->qmsg1) : 0,
|
|
||||||
param->qmsg1 ? param->qmsg1 : "");
|
|
||||||
printf("qmsg1 len = %d, body = %s\n", param->qmsg2 ? (int32_t)strlen(param->qmsg2) : 0,
|
|
||||||
param->qmsg2 ? param->qmsg2 : "");
|
|
||||||
}
|
|
||||||
|
|
||||||
taosMemoryFree(vCreateTbReq.stbCfg.pSchema);
|
taosMemoryFree(vCreateTbReq.stbCfg.pSchema);
|
||||||
taosMemoryFree(vCreateTbReq.stbCfg.pTagSchema);
|
taosMemoryFree(vCreateTbReq.stbCfg.pTagSchema);
|
||||||
if (vCreateTbReq.stbCfg.pRSmaParam) {
|
if (vCreateTbReq.stbCfg.pRSmaParam) {
|
||||||
taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->pFuncIds);
|
|
||||||
taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->qmsg1);
|
taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->qmsg1);
|
||||||
taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->qmsg2);
|
taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->qmsg2);
|
||||||
taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam);
|
taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam);
|
||||||
|
@ -309,6 +306,13 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR
|
||||||
SVCreateTbBatchRsp vCreateTbBatchRsp = {0};
|
SVCreateTbBatchRsp vCreateTbBatchRsp = {0};
|
||||||
tDeserializeSVCreateTbBatchReq(pReq, &vCreateTbBatchReq);
|
tDeserializeSVCreateTbBatchReq(pReq, &vCreateTbBatchReq);
|
||||||
int reqNum = taosArrayGetSize(vCreateTbBatchReq.pArray);
|
int reqNum = taosArrayGetSize(vCreateTbBatchReq.pArray);
|
||||||
|
|
||||||
|
STbDdlH ddlHandle = {
|
||||||
|
.ahandle = pVnode->pTsdb,
|
||||||
|
.result = NULL,
|
||||||
|
.fp = tsdbFetchTbUidList,
|
||||||
|
};
|
||||||
|
|
||||||
for (int i = 0; i < reqNum; i++) {
|
for (int i = 0; i < reqNum; i++) {
|
||||||
SVCreateTbReq *pCreateTbReq = taosArrayGet(vCreateTbBatchReq.pArray, i);
|
SVCreateTbReq *pCreateTbReq = taosArrayGet(vCreateTbBatchReq.pArray, i);
|
||||||
|
|
||||||
|
@ -324,7 +328,7 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR
|
||||||
taosArrayPush(vCreateTbBatchRsp.rspList, &rsp);
|
taosArrayPush(vCreateTbBatchRsp.rspList, &rsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (metaCreateTable(pVnode->pMeta, pCreateTbReq) < 0) {
|
if (metaCreateTable(pVnode->pMeta, pCreateTbReq, &ddlHandle) < 0) {
|
||||||
// TODO: handle error
|
// TODO: handle error
|
||||||
vError("vgId:%d, failed to create table: %s", TD_VID(pVnode), pCreateTbReq->name);
|
vError("vgId:%d, failed to create table: %s", TD_VID(pVnode), pCreateTbReq->name);
|
||||||
}
|
}
|
||||||
|
@ -334,7 +338,6 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR
|
||||||
taosMemoryFree(pCreateTbReq->stbCfg.pSchema);
|
taosMemoryFree(pCreateTbReq->stbCfg.pSchema);
|
||||||
taosMemoryFree(pCreateTbReq->stbCfg.pTagSchema);
|
taosMemoryFree(pCreateTbReq->stbCfg.pTagSchema);
|
||||||
if (pCreateTbReq->stbCfg.pRSmaParam) {
|
if (pCreateTbReq->stbCfg.pRSmaParam) {
|
||||||
taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam->pFuncIds);
|
|
||||||
taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam);
|
taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam);
|
||||||
}
|
}
|
||||||
} else if (pCreateTbReq->type == TD_CHILD_TABLE) {
|
} else if (pCreateTbReq->type == TD_CHILD_TABLE) {
|
||||||
|
@ -342,12 +345,13 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR
|
||||||
} else {
|
} else {
|
||||||
taosMemoryFree(pCreateTbReq->ntbCfg.pSchema);
|
taosMemoryFree(pCreateTbReq->ntbCfg.pSchema);
|
||||||
if (pCreateTbReq->ntbCfg.pRSmaParam) {
|
if (pCreateTbReq->ntbCfg.pRSmaParam) {
|
||||||
taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam->pFuncIds);
|
|
||||||
taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam);
|
taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tsdbUpdateTbUidList(pVnode->pTsdb, ddlHandle.result);
|
||||||
|
|
||||||
vTrace("vgId:%d process create %" PRIzu " tables", TD_VID(pVnode), taosArrayGetSize(vCreateTbBatchReq.pArray));
|
vTrace("vgId:%d process create %" PRIzu " tables", TD_VID(pVnode), taosArrayGetSize(vCreateTbBatchReq.pArray));
|
||||||
taosArrayDestroy(vCreateTbBatchReq.pArray);
|
taosArrayDestroy(vCreateTbBatchReq.pArray);
|
||||||
if (vCreateTbBatchRsp.rspList) {
|
if (vCreateTbBatchRsp.rspList) {
|
||||||
|
@ -371,7 +375,6 @@ static int vnodeProcessAlterStbReq(SVnode *pVnode, void *pReq) {
|
||||||
taosMemoryFree(vAlterTbReq.stbCfg.pSchema);
|
taosMemoryFree(vAlterTbReq.stbCfg.pSchema);
|
||||||
taosMemoryFree(vAlterTbReq.stbCfg.pTagSchema);
|
taosMemoryFree(vAlterTbReq.stbCfg.pTagSchema);
|
||||||
if (vAlterTbReq.stbCfg.pRSmaParam) {
|
if (vAlterTbReq.stbCfg.pRSmaParam) {
|
||||||
taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam->pFuncIds);
|
|
||||||
taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam);
|
taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam);
|
||||||
}
|
}
|
||||||
taosMemoryFree(vAlterTbReq.name);
|
taosMemoryFree(vAlterTbReq.name);
|
||||||
|
|
|
@ -407,7 +407,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPECT_EQ(tdScanAndConvertSubmitMsg(pMsg), TSDB_CODE_SUCCESS);
|
// EXPECT_EQ(tdScanAndConvertSubmitMsg(pMsg), TSDB_CODE_SUCCESS);
|
||||||
|
|
||||||
EXPECT_EQ(tsdbUpdateSmaWindow(pTsdb, pMsg, 0), 0);
|
EXPECT_EQ(tsdbUpdateSmaWindow(pTsdb, pMsg, 0), 0);
|
||||||
|
|
||||||
|
|
|
@ -494,7 +494,7 @@ _return:
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ctgGetQnodeListFromMnode(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, SArray **out) {
|
int32_t ctgGetQnodeListFromMnode(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, SArray *out) {
|
||||||
char *msg = NULL;
|
char *msg = NULL;
|
||||||
int32_t msgLen = 0;
|
int32_t msgLen = 0;
|
||||||
|
|
||||||
|
@ -526,7 +526,7 @@ int32_t ctgGetQnodeListFromMnode(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmt
|
||||||
CTG_ERR_RET(code);
|
CTG_ERR_RET(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
ctgDebug("Got qnode list from mnode, listNum:%d", (int32_t)taosArrayGetSize(*out));
|
ctgDebug("Got qnode list from mnode, listNum:%d", (int32_t)taosArrayGetSize(out));
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -2778,7 +2778,8 @@ int32_t catalogGetAllMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pReq->qNodeRequired) {
|
if (pReq->qNodeRequired) {
|
||||||
CTG_ERR_JRET(ctgGetQnodeListFromMnode(pCtg, pTrans, pMgmtEps, &pRsp->pEpSetList));
|
pRsp->pQnodeList = taosArrayInit(10, sizeof(SQueryNodeAddr));
|
||||||
|
CTG_ERR_JRET(ctgGetQnodeListFromMnode(pCtg, pTrans, pMgmtEps, pRsp->pQnodeList));
|
||||||
}
|
}
|
||||||
|
|
||||||
CTG_API_LEAVE(TSDB_CODE_SUCCESS);
|
CTG_API_LEAVE(TSDB_CODE_SUCCESS);
|
||||||
|
@ -2807,7 +2808,7 @@ int32_t catalogGetQnodeList(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps,
|
||||||
CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT);
|
CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
CTG_ERR_JRET(ctgGetQnodeListFromMnode(pCtg, pRpc, pMgmtEps, &pQnodeList));
|
CTG_ERR_JRET(ctgGetQnodeListFromMnode(pCtg, pRpc, pMgmtEps, pQnodeList));
|
||||||
|
|
||||||
_return:
|
_return:
|
||||||
|
|
||||||
|
|
|
@ -304,8 +304,8 @@ int32_t qExplainResAppendRow(SExplainCtx *ctx, char *tbuf, int32_t len, int32_t
|
||||||
|
|
||||||
memcpy(row.buf, tbuf, len);
|
memcpy(row.buf, tbuf, len);
|
||||||
row.level = level;
|
row.level = level;
|
||||||
row.len = len;
|
row.len = len;
|
||||||
ctx->dataSize += len;
|
ctx->dataSize += row.len;
|
||||||
|
|
||||||
if (NULL == taosArrayPush(ctx->rows, &row)) {
|
if (NULL == taosArrayPush(ctx->rows, &row)) {
|
||||||
qError("taosArrayPush row to explain res rows failed");
|
qError("taosArrayPush row to explain res rows failed");
|
||||||
|
@ -756,7 +756,7 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t colNum = 1;
|
int32_t colNum = 1;
|
||||||
int32_t rspSize = sizeof(SRetrieveTableRsp) + sizeof(int32_t) * colNum + sizeof(int32_t) * rowNum + pCtx->dataSize;
|
int32_t rspSize = sizeof(SRetrieveTableRsp) + sizeof(int32_t) + sizeof(uint64_t) + sizeof(int32_t) * colNum + sizeof(int32_t) * rowNum + pCtx->dataSize;
|
||||||
SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(1, rspSize);
|
SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(1, rspSize);
|
||||||
if (NULL == rsp) {
|
if (NULL == rsp) {
|
||||||
qError("malloc SRetrieveTableRsp failed, size:%d", rspSize);
|
qError("malloc SRetrieveTableRsp failed, size:%d", rspSize);
|
||||||
|
@ -766,29 +766,38 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) {
|
||||||
rsp->completed = 1;
|
rsp->completed = 1;
|
||||||
rsp->numOfRows = htonl(rowNum);
|
rsp->numOfRows = htonl(rowNum);
|
||||||
|
|
||||||
*(int32_t *)rsp->data = htonl(pCtx->dataSize);
|
// payload length
|
||||||
|
*(int32_t *)rsp->data = sizeof(int32_t) + sizeof(uint64_t) + sizeof(int32_t) * colNum + sizeof(int32_t) * rowNum + pCtx->dataSize;
|
||||||
|
|
||||||
int32_t *offset = (int32_t *)((char *)rsp->data + sizeof(int32_t));
|
// group id
|
||||||
|
*(uint64_t*)(rsp->data + sizeof(int32_t)) = 0;
|
||||||
|
|
||||||
|
// column length
|
||||||
|
int32_t* colLength = (int32_t *)(rsp->data + sizeof(int32_t) + sizeof(uint64_t));
|
||||||
|
|
||||||
|
// varchar column offset segment
|
||||||
|
int32_t *offset = (int32_t *)((char *)colLength + sizeof(int32_t));
|
||||||
|
|
||||||
|
// varchar data real payload
|
||||||
char *data = (char *)(offset + rowNum);
|
char *data = (char *)(offset + rowNum);
|
||||||
int32_t tOffset = 0;
|
|
||||||
|
char* start = data;
|
||||||
for (int32_t i = 0; i < rowNum; ++i) {
|
for (int32_t i = 0; i < rowNum; ++i) {
|
||||||
SQueryExplainRowInfo *row = taosArrayGet(pCtx->rows, i);
|
SQueryExplainRowInfo *row = taosArrayGet(pCtx->rows, i);
|
||||||
*offset = tOffset;
|
offset[i] = data - start;
|
||||||
tOffset += row->len;
|
|
||||||
|
|
||||||
memcpy(data, row->buf, row->len);
|
varDataCopy(data, row->buf);
|
||||||
|
ASSERT(varDataTLen(row->buf) == row->len);
|
||||||
++offset;
|
|
||||||
data += row->len;
|
data += row->len;
|
||||||
}
|
}
|
||||||
|
|
||||||
*pRsp = rsp;
|
*colLength = htonl(data - start);
|
||||||
|
rsp->compLen = htonl(rspSize);
|
||||||
|
|
||||||
|
*pRsp = rsp;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t qExplainPrepareCtx(SQueryPlan *pDag, SExplainCtx **pCtx) {
|
int32_t qExplainPrepareCtx(SQueryPlan *pDag, SExplainCtx **pCtx) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SNodeListNode *plans = NULL;
|
SNodeListNode *plans = NULL;
|
||||||
|
@ -895,9 +904,7 @@ int32_t qExplainAppendPlanRows(SExplainCtx *pCtx) {
|
||||||
|
|
||||||
int32_t qExplainGenerateRsp(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp) {
|
int32_t qExplainGenerateRsp(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp) {
|
||||||
QRY_ERR_RET(qExplainAppendGroupResRows(pCtx, pCtx->rootGroupId, 0));
|
QRY_ERR_RET(qExplainAppendGroupResRows(pCtx, pCtx->rootGroupId, 0));
|
||||||
|
|
||||||
QRY_ERR_RET(qExplainAppendPlanRows(pCtx));
|
QRY_ERR_RET(qExplainAppendPlanRows(pCtx));
|
||||||
|
|
||||||
QRY_ERR_RET(qExplainGetRspFromCtx(pCtx, pRsp));
|
QRY_ERR_RET(qExplainGetRspFromCtx(pCtx, pRsp));
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -967,13 +974,10 @@ int32_t qExecStaticExplain(SQueryPlan *pDag, SRetrieveTableRsp **pRsp) {
|
||||||
SExplainCtx *pCtx = NULL;
|
SExplainCtx *pCtx = NULL;
|
||||||
|
|
||||||
QRY_ERR_RET(qExplainPrepareCtx(pDag, &pCtx));
|
QRY_ERR_RET(qExplainPrepareCtx(pDag, &pCtx));
|
||||||
|
|
||||||
QRY_ERR_JRET(qExplainGenerateRsp(pCtx, pRsp));
|
QRY_ERR_JRET(qExplainGenerateRsp(pCtx, pRsp));
|
||||||
|
|
||||||
_return:
|
_return:
|
||||||
|
|
||||||
qExplainFreeCtx(pCtx);
|
qExplainFreeCtx(pCtx);
|
||||||
|
|
||||||
QRY_RET(code);
|
QRY_RET(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,6 @@
|
||||||
|
|
||||||
#define GET_TASKID(_t) (((SExecTaskInfo*)(_t))->id.str)
|
#define GET_TASKID(_t) (((SExecTaskInfo*)(_t))->id.str)
|
||||||
|
|
||||||
#define curTimeWindowIndex(_winres) ((_winres)->curIndex)
|
|
||||||
|
|
||||||
typedef struct SGroupResInfo {
|
typedef struct SGroupResInfo {
|
||||||
int32_t totalGroup;
|
int32_t totalGroup;
|
||||||
int32_t currentGroup;
|
int32_t currentGroup;
|
||||||
|
@ -68,11 +66,16 @@ typedef struct SResultRowPosition {
|
||||||
int32_t offset;
|
int32_t offset;
|
||||||
} SResultRowPosition;
|
} SResultRowPosition;
|
||||||
|
|
||||||
|
typedef struct SResKeyPos {
|
||||||
|
SResultRowPosition pos;
|
||||||
|
uint64_t groupId;
|
||||||
|
char key[];
|
||||||
|
} SResKeyPos;
|
||||||
|
|
||||||
typedef struct SResultRowInfo {
|
typedef struct SResultRowInfo {
|
||||||
SResultRowPosition *pPosition;
|
SResultRowPosition *pPosition;
|
||||||
int32_t size; // number of result set
|
int32_t size; // number of result set
|
||||||
int32_t capacity; // max capacity
|
int32_t capacity; // max capacity
|
||||||
// int32_t curPos; // current active result row index of pResult list
|
|
||||||
SResultRowPosition cur;
|
SResultRowPosition cur;
|
||||||
} SResultRowInfo;
|
} SResultRowInfo;
|
||||||
|
|
||||||
|
@ -135,7 +138,7 @@ typedef struct {
|
||||||
int32_t colId;
|
int32_t colId;
|
||||||
} SStddevInterResult;
|
} SStddevInterResult;
|
||||||
|
|
||||||
void initGroupResInfo(SGroupResInfo* pGroupResInfo, SResultRowInfo* pResultInfo);
|
void initGroupedResultInfo(SGroupResInfo* pGroupResInfo, SHashObj* pHashmap, bool sortGroupResult);
|
||||||
void initMultiResInfoFromArrayList(SGroupResInfo* pGroupResInfo, SArray* pArrayList);
|
void initMultiResInfoFromArrayList(SGroupResInfo* pGroupResInfo, SArray* pArrayList);
|
||||||
|
|
||||||
void cleanupGroupResInfo(SGroupResInfo* pGroupResInfo);
|
void cleanupGroupResInfo(SGroupResInfo* pGroupResInfo);
|
||||||
|
|
|
@ -319,27 +319,32 @@ typedef struct SColMatchInfo {
|
||||||
bool output;
|
bool output;
|
||||||
} SColMatchInfo;
|
} SColMatchInfo;
|
||||||
|
|
||||||
|
typedef struct SScanInfo {
|
||||||
|
int32_t numOfAsc;
|
||||||
|
int32_t numOfDesc;
|
||||||
|
} SScanInfo;
|
||||||
|
|
||||||
typedef struct STableScanInfo {
|
typedef struct STableScanInfo {
|
||||||
void* dataReader;
|
void* dataReader;
|
||||||
|
|
||||||
int32_t numOfBlocks; // extract basic running information.
|
int32_t numOfBlocks; // extract basic running information.
|
||||||
int32_t numOfSkipped;
|
int32_t numOfSkipped;
|
||||||
int32_t numOfBlockStatis;
|
int32_t numOfBlockStatis;
|
||||||
int64_t numOfRows;
|
int64_t numOfRows;
|
||||||
int32_t order; // scan order
|
int64_t elapsedTime;
|
||||||
int32_t times; // repeat counts
|
int32_t prevGroupId; // previous table group id
|
||||||
|
SScanInfo scanInfo;
|
||||||
int32_t current;
|
int32_t current;
|
||||||
int32_t reverseTimes; // 0 by default
|
SNode* pFilterNode; // filter operator info
|
||||||
SNode* pFilterNode; // filter operator info
|
SqlFunctionCtx* pCtx; // next operator query context
|
||||||
SqlFunctionCtx* pCtx; // next operator query context
|
|
||||||
SResultRowInfo* pResultRowInfo;
|
SResultRowInfo* pResultRowInfo;
|
||||||
int32_t* rowCellInfoOffset;
|
int32_t* rowCellInfoOffset;
|
||||||
SExprInfo* pExpr;
|
SExprInfo* pExpr;
|
||||||
SSDataBlock* pResBlock;
|
SSDataBlock* pResBlock;
|
||||||
SArray* pColMatchInfo;
|
SArray* pColMatchInfo;
|
||||||
int32_t numOfOutput;
|
int32_t numOfOutput;
|
||||||
int64_t elapsedTime;
|
|
||||||
int32_t prevGroupId; // previous table group id
|
|
||||||
|
|
||||||
|
SQueryTableDataCond cond;
|
||||||
int32_t scanFlag; // table scan flag to denote if it is a repeat/reverse/main scan
|
int32_t scanFlag; // table scan flag to denote if it is a repeat/reverse/main scan
|
||||||
int32_t dataBlockLoadFlag;
|
int32_t dataBlockLoadFlag;
|
||||||
double sampleRatio; // data block sample ratio, 1 by default
|
double sampleRatio; // data block sample ratio, 1 by default
|
||||||
|
@ -347,10 +352,11 @@ typedef struct STableScanInfo {
|
||||||
} STableScanInfo;
|
} STableScanInfo;
|
||||||
|
|
||||||
typedef struct STagScanInfo {
|
typedef struct STagScanInfo {
|
||||||
SColumnInfo* pCols;
|
SColumnInfo *pCols;
|
||||||
SSDataBlock* pRes;
|
SSDataBlock *pRes;
|
||||||
int32_t totalTables;
|
int32_t totalTables;
|
||||||
int32_t curPos;
|
int32_t curPos;
|
||||||
|
void *pReader;
|
||||||
} STagScanInfo;
|
} STagScanInfo;
|
||||||
|
|
||||||
typedef struct SStreamBlockScanInfo {
|
typedef struct SStreamBlockScanInfo {
|
||||||
|
@ -376,13 +382,11 @@ typedef struct SSysTableScanInfo {
|
||||||
SEpSet epSet;
|
SEpSet epSet;
|
||||||
tsem_t ready;
|
tsem_t ready;
|
||||||
|
|
||||||
int32_t accountId;
|
int32_t accountId;
|
||||||
bool showRewrite;
|
bool showRewrite;
|
||||||
SNode* pCondition; // db_name filter condition, to discard data that are not in current database
|
SNode* pCondition; // db_name filter condition, to discard data that are not in current database
|
||||||
void* pCur; // cursor for iterate the local table meta store.
|
void* pCur; // cursor for iterate the local table meta store.
|
||||||
SArray* scanCols; // SArray<int16_t> scan column id list
|
SArray* scanCols; // SArray<int16_t> scan column id list
|
||||||
|
|
||||||
// int32_t type; // show type, TODO remove it
|
|
||||||
SName name;
|
SName name;
|
||||||
SSDataBlock* pRes;
|
SSDataBlock* pRes;
|
||||||
int32_t capacity;
|
int32_t capacity;
|
||||||
|
@ -400,8 +404,8 @@ typedef struct SOptrBasicInfo {
|
||||||
// TODO move the resultrowsiz together with SOptrBasicInfo:rowCellInfoOffset
|
// TODO move the resultrowsiz together with SOptrBasicInfo:rowCellInfoOffset
|
||||||
typedef struct SAggSupporter {
|
typedef struct SAggSupporter {
|
||||||
SHashObj* pResultRowHashTable; // quick locate the window object for each result
|
SHashObj* pResultRowHashTable; // quick locate the window object for each result
|
||||||
SHashObj* pResultRowListSet; // used to check if current ResultRowInfo has ResultRow object or not
|
// SHashObj* pResultRowListSet; // used to check if current ResultRowInfo has ResultRow object or not
|
||||||
SArray* pResultRowArrayList; // The array list that contains the Result rows
|
// SArray* pResultRowArrayList; // The array list that contains the Result rows
|
||||||
char* keyBuf; // window key buffer
|
char* keyBuf; // window key buffer
|
||||||
SDiskbasedBuf* pResultBuf; // query result buffer based on blocked-wised disk file
|
SDiskbasedBuf* pResultBuf; // query result buffer based on blocked-wised disk file
|
||||||
int32_t resultRowSize; // the result buffer size for each result row, with the meta data size for each row
|
int32_t resultRowSize; // the result buffer size for each result row, with the meta data size for each row
|
||||||
|
@ -621,6 +625,7 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI
|
||||||
int32_t compLen, int32_t numOfOutput, int64_t startTs, uint64_t* total,
|
int32_t compLen, int32_t numOfOutput, int64_t startTs, uint64_t* total,
|
||||||
SArray* pColList);
|
SArray* pColList);
|
||||||
void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key, STimeWindow* win);
|
void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key, STimeWindow* win);
|
||||||
|
int32_t getTableScanOrder(SOperatorInfo* pOperator);
|
||||||
|
|
||||||
void doSetOperatorCompleted(SOperatorInfo* pOperator);
|
void doSetOperatorCompleted(SOperatorInfo* pOperator);
|
||||||
void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock);
|
void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock);
|
||||||
|
@ -628,9 +633,9 @@ SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput,
|
||||||
|
|
||||||
SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo);
|
SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo);
|
||||||
|
|
||||||
SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfCols, int32_t dataLoadFlag, int32_t repeatTime,
|
SOperatorInfo* createTableScanOperatorInfo(void* pDataReader, SQueryTableDataCond* pCond, int32_t numOfOutput, int32_t dataLoadFlag, const uint8_t* scanInfo,
|
||||||
int32_t reverseTime, SArray* pColMatchInfo, SSDataBlock* pResBlock, SNode* pCondition,
|
SArray* pColMatchInfo, SSDataBlock* pResBlock, SNode* pCondition, SInterval* pInterval, double sampleRatio, SExecTaskInfo* pTaskInfo);
|
||||||
SInterval* pInterval, double ratio, SExecTaskInfo* pTaskInfo);
|
|
||||||
SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SExprInfo* pScalarExprInfo,
|
SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SExprInfo* pScalarExprInfo,
|
||||||
int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
||||||
|
|
||||||
|
@ -668,12 +673,12 @@ SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SExprInfo*
|
||||||
SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo);
|
SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo);
|
||||||
|
|
||||||
SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t numOfDownstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SNode* pOnCondition, SExecTaskInfo* pTaskInfo);
|
SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t numOfDownstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SNode* pOnCondition, SExecTaskInfo* pTaskInfo);
|
||||||
|
SOperatorInfo* createTagScanOperatorInfo(void* pReaderHandle, SExprInfo* pExpr, int32_t numOfOutput, SExecTaskInfo* pTaskInfo);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv);
|
SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv);
|
||||||
SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream,
|
SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream,
|
||||||
SExprInfo* pExpr, int32_t numOfOutput);
|
SExprInfo* pExpr, int32_t numOfOutput);
|
||||||
SOperatorInfo* createTagScanOperatorInfo(SReaderHandle* pReaderHandle, SExprInfo* pExpr, int32_t numOfOutput);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx* pCtx,
|
void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx* pCtx,
|
||||||
|
|
|
@ -64,10 +64,10 @@ static bool needCompress(const SSDataBlock* pData, int32_t numOfCols) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// data format:
|
// data format:
|
||||||
// +----------------+--------------------------------------+-------------+-----------+-------------+-----------+
|
// +----------------+--------------+----------+--------------------------------------+-------------+-----------+-------------+-----------+
|
||||||
// |SDataCacheEntry | column#1 length, column#2 length ... | col1 bitmap | col1 data | col2 bitmap | col2 data | ....
|
// |SDataCacheEntry | total length | group id | column#1 length, column#2 length ... | col1 bitmap | col1 data | col2 bitmap | col2 data | ....
|
||||||
// | | sizeof(int32_t) * numOfCols | actual size | | actual size | |
|
// | | (4 bytes) |(8 bytes) | sizeof(int32_t) * numOfCols | actual size | | actual size | |
|
||||||
// +----------------+--------------------------------------+-------------+-----------+-------------+-----------+
|
// +----------------+--------------+----------+--------------------------------------+-------------+-----------+-------------+-----------+
|
||||||
// The length of bitmap is decided by number of rows of this data block, and the length of each column data is
|
// The length of bitmap is decided by number of rows of this data block, and the length of each column data is
|
||||||
// recorded in the first segment, next to the struct header
|
// recorded in the first segment, next to the struct header
|
||||||
static void toDataCacheEntry(const SDataDispatchHandle* pHandle, const SInputData* pInput, SDataDispatchBuf* pBuf) {
|
static void toDataCacheEntry(const SDataDispatchHandle* pHandle, const SInputData* pInput, SDataDispatchBuf* pBuf) {
|
||||||
|
|
|
@ -186,12 +186,50 @@ void cleanupGroupResInfo(SGroupResInfo* pGroupResInfo) {
|
||||||
pGroupResInfo->index = 0;
|
pGroupResInfo->index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initGroupResInfo(SGroupResInfo* pGroupResInfo, SResultRowInfo* pResultInfo) {
|
static int32_t resultrowCompar1(const void* p1, const void* p2) {
|
||||||
|
SResKeyPos* pp1 = *(SResKeyPos**) p1;
|
||||||
|
SResKeyPos* pp2 = *(SResKeyPos**) p2;
|
||||||
|
|
||||||
|
if (pp1->groupId == pp2->groupId) {
|
||||||
|
int64_t pts1 = *(int64_t*) pp1->key;
|
||||||
|
int64_t pts2 = *(int64_t*) pp2->key;
|
||||||
|
|
||||||
|
if (pts1 == pts2) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return pts1 < pts2? -1:1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return pp1->groupId < pp2->groupId? -1:1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void initGroupedResultInfo(SGroupResInfo* pGroupResInfo, SHashObj* pHashmap, bool sortGroupResult) {
|
||||||
if (pGroupResInfo->pRows != NULL) {
|
if (pGroupResInfo->pRows != NULL) {
|
||||||
taosArrayDestroy(pGroupResInfo->pRows);
|
taosArrayDestroy(pGroupResInfo->pRows);
|
||||||
}
|
}
|
||||||
|
|
||||||
pGroupResInfo->pRows = taosArrayFromList(pResultInfo->pPosition, pResultInfo->size, sizeof(SResultRowPosition));
|
// extract the result rows information from the hash map
|
||||||
|
void* pData = NULL;
|
||||||
|
pGroupResInfo->pRows = taosArrayInit(10, POINTER_BYTES);
|
||||||
|
|
||||||
|
size_t keyLen = 0;
|
||||||
|
while((pData = taosHashIterate(pHashmap, pData)) != NULL) {
|
||||||
|
void* key = taosHashGetKey(pData, &keyLen);
|
||||||
|
|
||||||
|
SResKeyPos* p = taosMemoryMalloc(keyLen + sizeof(SResultRowPosition));
|
||||||
|
|
||||||
|
p->groupId = *(uint64_t*) key;
|
||||||
|
p->pos = *(SResultRowPosition*) pData;
|
||||||
|
memcpy(p->key, (char*)key + sizeof(uint64_t), keyLen - sizeof(uint64_t));
|
||||||
|
|
||||||
|
taosArrayPush(pGroupResInfo->pRows, &p);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sortGroupResult) {
|
||||||
|
qsort(pGroupResInfo->pRows->pData, taosArrayGetSize(pGroupResInfo->pRows), POINTER_BYTES, resultrowCompar1);
|
||||||
|
}
|
||||||
|
|
||||||
pGroupResInfo->index = 0;
|
pGroupResInfo->index = 0;
|
||||||
assert(pGroupResInfo->index <= getNumOfTotalRes(pGroupResInfo));
|
assert(pGroupResInfo->index <= getNumOfTotalRes(pGroupResInfo));
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -308,7 +308,7 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator, bool* newgrou
|
||||||
// }
|
// }
|
||||||
|
|
||||||
blockDataEnsureCapacity(pRes, pOperator->resultInfo.capacity);
|
blockDataEnsureCapacity(pRes, pOperator->resultInfo.capacity);
|
||||||
initGroupResInfo(&pInfo->groupResInfo, &pInfo->binfo.resultRowInfo);
|
initGroupedResultInfo(&pInfo->groupResInfo, pInfo->aggSup.pResultRowHashTable, false);
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
doBuildResultDatablock(pRes, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pInfo->binfo.rowCellInfoOffset, pInfo->binfo.pCtx);
|
doBuildResultDatablock(pRes, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pInfo->binfo.rowCellInfoOffset, pInfo->binfo.pCtx);
|
||||||
|
|
|
@ -245,6 +245,9 @@ int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableScanInfo,
|
||||||
|
|
||||||
relocateColumnData(pBlock, pTableScanInfo->pColMatchInfo, pCols);
|
relocateColumnData(pBlock, pTableScanInfo->pColMatchInfo, pCols);
|
||||||
|
|
||||||
|
// reset the block to be 0 by default, this blockId is assigned by physical plan and is used by direct upstream operator.
|
||||||
|
pBlock->info.blockId = 0;
|
||||||
|
|
||||||
doFilter(pTableScanInfo->pFilterNode, pBlock);
|
doFilter(pTableScanInfo->pFilterNode, pBlock);
|
||||||
if (pBlock->info.rows == 0) {
|
if (pBlock->info.rows == 0) {
|
||||||
pCost->filterOutBlocks += 1;
|
pCost->filterOutBlocks += 1;
|
||||||
|
@ -255,25 +258,21 @@ int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableScanInfo,
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setupEnvForReverseScan(STableScanInfo* pTableScanInfo, SqlFunctionCtx* pCtx, int32_t numOfOutput) {
|
static void prepareForDescendingScan(STableScanInfo* pTableScanInfo, SqlFunctionCtx* pCtx, int32_t numOfOutput) {
|
||||||
// reverse order time range
|
|
||||||
SET_REVERSE_SCAN_FLAG(pTableScanInfo);
|
SET_REVERSE_SCAN_FLAG(pTableScanInfo);
|
||||||
|
|
||||||
switchCtxOrder(pCtx, numOfOutput);
|
switchCtxOrder(pCtx, numOfOutput);
|
||||||
SWITCH_ORDER(pTableScanInfo->order);
|
// setupQueryRangeForReverseScan(pTableScanInfo);
|
||||||
setupQueryRangeForReverseScan(pTableScanInfo);
|
|
||||||
|
|
||||||
pTableScanInfo->times = 1;
|
STimeWindow* pTWindow = &pTableScanInfo->cond.twindow;
|
||||||
pTableScanInfo->current = 0;
|
TSWAP(pTWindow->skey, pTWindow->ekey, int64_t);
|
||||||
pTableScanInfo->reverseTimes = 0;
|
pTableScanInfo->cond.order = TSDB_ORDER_DESC;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator, bool* newgroup) {
|
static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator, bool* newgroup) {
|
||||||
STableScanInfo* pTableScanInfo = pOperator->info;
|
STableScanInfo* pTableScanInfo = pOperator->info;
|
||||||
|
|
||||||
SSDataBlock* pBlock = pTableScanInfo->pResBlock;
|
SSDataBlock* pBlock = pTableScanInfo->pResBlock;
|
||||||
STableGroupInfo* pTableGroupInfo = &pOperator->pTaskInfo->tableqinfoGroupInfo;
|
|
||||||
|
|
||||||
*newgroup = false;
|
*newgroup = false;
|
||||||
|
|
||||||
while (tsdbNextDataBlock(pTableScanInfo->dataReader)) {
|
while (tsdbNextDataBlock(pTableScanInfo->dataReader)) {
|
||||||
|
@ -284,18 +283,6 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator, bool* newgroup) {
|
||||||
pTableScanInfo->numOfBlocks += 1;
|
pTableScanInfo->numOfBlocks += 1;
|
||||||
tsdbRetrieveDataBlockInfo(pTableScanInfo->dataReader, &pBlock->info);
|
tsdbRetrieveDataBlockInfo(pTableScanInfo->dataReader, &pBlock->info);
|
||||||
|
|
||||||
// todo opt
|
|
||||||
// if (pTableGroupInfo->numOfTables > 1 || (pRuntimeEnv->current == NULL && pTableGroupInfo->numOfTables == 1)) {
|
|
||||||
// STableQueryInfo** pTableQueryInfo =
|
|
||||||
// (STableQueryInfo**)taosHashGet(pTableGroupInfo->map, &pBlock->info.uid, sizeof(pBlock->info.uid));
|
|
||||||
// if (pTableQueryInfo == NULL) {
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// doTableQueryInfoTimeWindowCheck(pTaskInfo, *pTableQueryInfo, pTableScanInfo->order);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// this function never returns error?
|
|
||||||
uint32_t status = 0;
|
uint32_t status = 0;
|
||||||
int32_t code = loadDataBlock(pOperator, pTableScanInfo, pBlock, &status);
|
int32_t code = loadDataBlock(pOperator, pTableScanInfo, pBlock, &status);
|
||||||
// int32_t code = loadDataBlockOnDemand(pOperator->pRuntimeEnv, pTableScanInfo, pBlock, &status);
|
// int32_t code = loadDataBlockOnDemand(pOperator->pRuntimeEnv, pTableScanInfo, pBlock, &status);
|
||||||
|
@ -323,63 +310,67 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator, bool* newgroup) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SResultRowInfo* pResultRowInfo = pTableScanInfo->pResultRowInfo;
|
|
||||||
*newgroup = false;
|
*newgroup = false;
|
||||||
|
|
||||||
while (pTableScanInfo->current < pTableScanInfo->times) {
|
while (pTableScanInfo->current < pTableScanInfo->scanInfo.numOfAsc) {
|
||||||
SSDataBlock* p = doTableScanImpl(pOperator, newgroup);
|
SSDataBlock* p = doTableScanImpl(pOperator, newgroup);
|
||||||
if (p != NULL) {
|
if (p != NULL) {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (++pTableScanInfo->current >= pTableScanInfo->times) {
|
pTableScanInfo->current += 1;
|
||||||
if (pTableScanInfo->reverseTimes <= 0 /* || isTsdbCacheLastRow(pTableScanInfo->pTsdbReadHandle)*/) {
|
|
||||||
return NULL;
|
if (pTableScanInfo->current < pTableScanInfo->scanInfo.numOfAsc) {
|
||||||
} else {
|
setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED);
|
||||||
break;
|
pTableScanInfo->scanFlag = REPEAT_SCAN;
|
||||||
|
|
||||||
|
STimeWindow* pWin = &pTableScanInfo->cond.twindow;
|
||||||
|
qDebug("%s start to repeat ascending order scan data blocks due to query func required, qrange:%" PRId64 "-%" PRId64,
|
||||||
|
GET_TASKID(pTaskInfo), pWin->skey, pWin->ekey);
|
||||||
|
|
||||||
|
// do prepare for the next round table scan operation
|
||||||
|
tsdbResetReadHandle(pTableScanInfo->dataReader, &pTableScanInfo->cond);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t total = pTableScanInfo->scanInfo.numOfAsc + pTableScanInfo->scanInfo.numOfDesc;
|
||||||
|
if (pTableScanInfo->current < total) {
|
||||||
|
if (pTableScanInfo->cond.order == TSDB_ORDER_ASC) {
|
||||||
|
prepareForDescendingScan(pTableScanInfo, pTableScanInfo->pCtx, pTableScanInfo->numOfOutput);
|
||||||
|
tsdbResetReadHandle(pTableScanInfo->dataReader, &pTableScanInfo->cond);
|
||||||
|
}
|
||||||
|
|
||||||
|
STimeWindow* pWin = &pTableScanInfo->cond.twindow;
|
||||||
|
qDebug("%s start to descending order scan data blocks due to query func required, qrange:%" PRId64 "-%" PRId64,
|
||||||
|
GET_TASKID(pTaskInfo), pWin->skey, pWin->ekey);
|
||||||
|
|
||||||
|
while (pTableScanInfo->current < total) {
|
||||||
|
SSDataBlock* p = doTableScanImpl(pOperator, newgroup);
|
||||||
|
if (p != NULL) {
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
pTableScanInfo->current += 1;
|
||||||
|
|
||||||
|
if (pTableScanInfo->current < pTableScanInfo->scanInfo.numOfAsc) {
|
||||||
|
setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED);
|
||||||
|
pTableScanInfo->scanFlag = REPEAT_SCAN;
|
||||||
|
|
||||||
|
qDebug("%s start to repeat descending order scan data blocks due to query func required, qrange:%" PRId64 "-%" PRId64,
|
||||||
|
GET_TASKID(pTaskInfo), pTaskInfo->window.skey, pTaskInfo->window.ekey);
|
||||||
|
|
||||||
|
// do prepare for the next round table scan operation
|
||||||
|
tsdbResetReadHandle(pTableScanInfo->dataReader, &pTableScanInfo->cond);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// do prepare for the next round table scan operation
|
|
||||||
// STsdbQueryCond cond = createTsdbQueryCond(pQueryAttr, &pQueryAttr->window);
|
|
||||||
// tsdbResetQueryHandle(pTableScanInfo->pTsdbReadHandle, &cond);
|
|
||||||
|
|
||||||
setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED);
|
|
||||||
pTableScanInfo->scanFlag = REPEAT_SCAN;
|
|
||||||
|
|
||||||
// if (pResultRowInfo->size > 0) {
|
|
||||||
// pResultRowInfo->curPos = 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
qDebug("%s start to repeat scan data blocks due to query func required, qrange:%" PRId64 "-%" PRId64,
|
|
||||||
GET_TASKID(pTaskInfo), pTaskInfo->window.skey, pTaskInfo->window.ekey);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SSDataBlock* p = NULL;
|
setTaskStatus(pTaskInfo, TASK_COMPLETED);
|
||||||
// todo refactor
|
return NULL;
|
||||||
if (pTableScanInfo->reverseTimes > 0) {
|
|
||||||
setupEnvForReverseScan(pTableScanInfo, pTableScanInfo->pCtx, pTableScanInfo->numOfOutput);
|
|
||||||
// STsdbQueryCond cond = createTsdbQueryCond(pQueryAttr, &pQueryAttr->window);
|
|
||||||
// tsdbResetQueryHandle(pTableScanInfo->pTsdbReadHandle, &cond);
|
|
||||||
|
|
||||||
qDebug("%s start to reverse scan data blocks due to query func required, qrange:%" PRId64 "-%" PRId64,
|
|
||||||
GET_TASKID(pTaskInfo), pTaskInfo->window.skey, pTaskInfo->window.ekey);
|
|
||||||
|
|
||||||
if (pResultRowInfo->size > 0) {
|
|
||||||
// pResultRowInfo->curPos = pResultRowInfo->size - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
p = doTableScanImpl(pOperator, newgroup);
|
|
||||||
}
|
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SOperatorInfo* createTableScanOperatorInfo(void* pDataReader, int32_t order, int32_t numOfOutput, int32_t dataLoadFlag,
|
SOperatorInfo* createTableScanOperatorInfo(void* pDataReader, SQueryTableDataCond* pCond, int32_t numOfOutput, int32_t dataLoadFlag, const uint8_t* scanInfo,
|
||||||
int32_t repeatTime, int32_t reverseTime, SArray* pColMatchInfo, SSDataBlock* pResBlock,
|
SArray* pColMatchInfo, SSDataBlock* pResBlock, SNode* pCondition, SInterval* pInterval, double sampleRatio, SExecTaskInfo* pTaskInfo) {
|
||||||
SNode* pCondition, SInterval* pInterval, double sampleRatio, SExecTaskInfo* pTaskInfo) {
|
|
||||||
assert(repeatTime > 0);
|
|
||||||
|
|
||||||
STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo));
|
STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo));
|
||||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||||
if (pInfo == NULL || pOperator == NULL) {
|
if (pInfo == NULL || pOperator == NULL) {
|
||||||
|
@ -390,26 +381,27 @@ SOperatorInfo* createTableScanOperatorInfo(void* pDataReader, int32_t order, int
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pInfo->cond = *pCond;
|
||||||
|
pInfo->scanInfo = (SScanInfo) {.numOfAsc = scanInfo[0], .numOfDesc = scanInfo[1]};
|
||||||
|
|
||||||
pInfo->interval = *pInterval;
|
pInfo->interval = *pInterval;
|
||||||
pInfo->sampleRatio = sampleRatio;
|
pInfo->sampleRatio = sampleRatio;
|
||||||
pInfo->dataBlockLoadFlag= dataLoadFlag;
|
pInfo->dataBlockLoadFlag= dataLoadFlag;
|
||||||
pInfo->pResBlock = pResBlock;
|
pInfo->pResBlock = pResBlock;
|
||||||
pInfo->pFilterNode = pCondition;
|
pInfo->pFilterNode = pCondition;
|
||||||
pInfo->dataReader = pDataReader;
|
pInfo->dataReader = pDataReader;
|
||||||
pInfo->times = repeatTime;
|
|
||||||
pInfo->reverseTimes = reverseTime;
|
|
||||||
pInfo->order = order;
|
|
||||||
pInfo->current = 0;
|
pInfo->current = 0;
|
||||||
pInfo->scanFlag = MAIN_SCAN;
|
pInfo->scanFlag = MAIN_SCAN;
|
||||||
pInfo->pColMatchInfo = pColMatchInfo;
|
pInfo->pColMatchInfo = pColMatchInfo;
|
||||||
|
|
||||||
pOperator->name = "TableScanOperator";
|
pOperator->name = "TableScanOperator";
|
||||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN;
|
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN;
|
||||||
pOperator->blockingOptr = false;
|
pOperator->blockingOptr = false;
|
||||||
pOperator->status = OP_NOT_OPENED;
|
pOperator->status = OP_NOT_OPENED;
|
||||||
pOperator->info = pInfo;
|
pOperator->info = pInfo;
|
||||||
pOperator->numOfOutput = numOfOutput;
|
pOperator->numOfOutput = numOfOutput;
|
||||||
pOperator->getNextFn = doTableScan;
|
pOperator->getNextFn = doTableScan;
|
||||||
pOperator->pTaskInfo = pTaskInfo;
|
pOperator->pTaskInfo = pTaskInfo;
|
||||||
|
|
||||||
static int32_t cost = 0;
|
static int32_t cost = 0;
|
||||||
pOperator->cost.openCost = ++cost;
|
pOperator->cost.openCost = ++cost;
|
||||||
|
@ -422,19 +414,17 @@ SOperatorInfo* createTableScanOperatorInfo(void* pDataReader, int32_t order, int
|
||||||
SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle) {
|
SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle) {
|
||||||
STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo));
|
STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo));
|
||||||
|
|
||||||
pInfo->dataReader = pTsdbReadHandle;
|
pInfo->dataReader = pTsdbReadHandle;
|
||||||
pInfo->times = 1;
|
pInfo->current = 0;
|
||||||
pInfo->reverseTimes = 0;
|
|
||||||
pInfo->current = 0;
|
|
||||||
pInfo->prevGroupId = -1;
|
pInfo->prevGroupId = -1;
|
||||||
|
|
||||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||||
pOperator->name = "TableSeqScanOperator";
|
pOperator->name = "TableSeqScanOperator";
|
||||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN;
|
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN;
|
||||||
pOperator->blockingOptr = false;
|
pOperator->blockingOptr = false;
|
||||||
pOperator->status = OP_NOT_OPENED;
|
pOperator->status = OP_NOT_OPENED;
|
||||||
pOperator->info = pInfo;
|
pOperator->info = pInfo;
|
||||||
pOperator->getNextFn = doTableScanImpl;
|
pOperator->getNextFn = doTableScanImpl;
|
||||||
|
|
||||||
return pOperator;
|
return pOperator;
|
||||||
}
|
}
|
||||||
|
@ -824,12 +814,12 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) {
|
||||||
int32_t tableNameSlotId = 1;
|
int32_t tableNameSlotId = 1;
|
||||||
SColumnInfoData* pTableNameCol = taosArrayGet(pInfo->pRes->pDataBlock, tableNameSlotId);
|
SColumnInfoData* pTableNameCol = taosArrayGet(pInfo->pRes->pDataBlock, tableNameSlotId);
|
||||||
|
|
||||||
char* name = NULL;
|
char* tb = NULL;
|
||||||
int32_t numOfRows = 0;
|
int32_t numOfRows = 0;
|
||||||
|
|
||||||
char n[TSDB_TABLE_NAME_LEN] = {0};
|
char n[TSDB_TABLE_NAME_LEN] = {0};
|
||||||
while ((name = metaTbCursorNext(pInfo->pCur)) != NULL) {
|
while ((tb = metaTbCursorNext(pInfo->pCur)) != NULL) {
|
||||||
STR_TO_VARSTR(n, name);
|
STR_TO_VARSTR(n, tb);
|
||||||
colDataAppend(pTableNameCol, numOfRows, n, false);
|
colDataAppend(pTableNameCol, numOfRows, n, false);
|
||||||
numOfRows += 1;
|
numOfRows += 1;
|
||||||
if (numOfRows >= pInfo->capacity) {
|
if (numOfRows >= pInfo->capacity) {
|
||||||
|
@ -992,3 +982,167 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB
|
||||||
|
|
||||||
return pOperator;
|
return pOperator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SSDataBlock* doTagScan(SOperatorInfo* pOperator, bool* newgroup) {
|
||||||
|
#if 0
|
||||||
|
SOperatorInfo* pOperator = (SOperatorInfo*) param;
|
||||||
|
if (pOperator->status == OP_EXEC_DONE) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t maxNumOfTables = (int32_t)pResultInfo->capacity;
|
||||||
|
|
||||||
|
STagScanInfo *pInfo = pOperator->info;
|
||||||
|
SSDataBlock *pRes = pInfo->pRes;
|
||||||
|
*newgroup = false;
|
||||||
|
|
||||||
|
int32_t count = 0;
|
||||||
|
SArray* pa = GET_TABLEGROUP(pRuntimeEnv, 0);
|
||||||
|
|
||||||
|
int32_t functionId = getExprFunctionId(&pOperator->pExpr[0]);
|
||||||
|
if (functionId == FUNCTION_TID_TAG) { // return the tags & table Id
|
||||||
|
assert(pQueryAttr->numOfOutput == 1);
|
||||||
|
|
||||||
|
SExprInfo* pExprInfo = &pOperator->pExpr[0];
|
||||||
|
int32_t rsize = pExprInfo->base.resSchema.bytes;
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
|
||||||
|
int16_t bytes = pExprInfo->base.resSchema.bytes;
|
||||||
|
int16_t type = pExprInfo->base.resSchema.type;
|
||||||
|
|
||||||
|
for(int32_t i = 0; i < pQueryAttr->numOfTags; ++i) {
|
||||||
|
if (pQueryAttr->tagColList[i].colId == pExprInfo->base.pColumns->info.colId) {
|
||||||
|
bytes = pQueryAttr->tagColList[i].bytes;
|
||||||
|
type = pQueryAttr->tagColList[i].type;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SColumnInfoData* pColInfo = taosArrayGet(pRes->pDataBlock, 0);
|
||||||
|
|
||||||
|
while(pInfo->curPos < pInfo->totalTables && count < maxNumOfTables) {
|
||||||
|
int32_t i = pInfo->curPos++;
|
||||||
|
STableQueryInfo *item = taosArrayGetP(pa, i);
|
||||||
|
|
||||||
|
char *output = pColInfo->pData + count * rsize;
|
||||||
|
varDataSetLen(output, rsize - VARSTR_HEADER_SIZE);
|
||||||
|
|
||||||
|
output = varDataVal(output);
|
||||||
|
STableId* id = TSDB_TABLEID(item->pTable);
|
||||||
|
|
||||||
|
*(int16_t *)output = 0;
|
||||||
|
output += sizeof(int16_t);
|
||||||
|
|
||||||
|
*(int64_t *)output = id->uid; // memory align problem, todo serialize
|
||||||
|
output += sizeof(id->uid);
|
||||||
|
|
||||||
|
*(int32_t *)output = id->tid;
|
||||||
|
output += sizeof(id->tid);
|
||||||
|
|
||||||
|
*(int32_t *)output = pQueryAttr->vgId;
|
||||||
|
output += sizeof(pQueryAttr->vgId);
|
||||||
|
|
||||||
|
char* data = NULL;
|
||||||
|
if (pExprInfo->base.pColumns->info.colId == TSDB_TBNAME_COLUMN_INDEX) {
|
||||||
|
data = tsdbGetTableName(item->pTable);
|
||||||
|
} else {
|
||||||
|
data = tsdbGetTableTagVal(item->pTable, pExprInfo->base.pColumns->info.colId, type, bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
doSetTagValueToResultBuf(output, data, type, bytes);
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//qDebug("QInfo:0x%"PRIx64" create (tableId, tag) info completed, rows:%d", GET_TASKID(pRuntimeEnv), count);
|
||||||
|
} else if (functionId == FUNCTION_COUNT) {// handle the "count(tbname)" query
|
||||||
|
SColumnInfoData* pColInfo = taosArrayGet(pRes->pDataBlock, 0);
|
||||||
|
*(int64_t*)pColInfo->pData = pInfo->totalTables;
|
||||||
|
count = 1;
|
||||||
|
|
||||||
|
pOperator->status = OP_EXEC_DONE;
|
||||||
|
//qDebug("QInfo:0x%"PRIx64" create count(tbname) query, res:%d rows:1", GET_TASKID(pRuntimeEnv), count);
|
||||||
|
} else { // return only the tags|table name etc.
|
||||||
|
SExprInfo* pExprInfo = &pOperator->pExpr[0]; // todo use the column list instead of exprinfo
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
while(pInfo->curPos < pInfo->totalTables && count < maxNumOfTables) {
|
||||||
|
int32_t i = pInfo->curPos++;
|
||||||
|
|
||||||
|
STableQueryInfo* item = taosArrayGetP(pa, i);
|
||||||
|
|
||||||
|
char *data = NULL, *dst = NULL;
|
||||||
|
int16_t type = 0, bytes = 0;
|
||||||
|
for(int32_t j = 0; j < pOperator->numOfOutput; ++j) {
|
||||||
|
// not assign value in case of user defined constant output column
|
||||||
|
if (TSDB_COL_IS_UD_COL(pExprInfo[j].base.pColumns->flag)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
SColumnInfoData* pColInfo = taosArrayGet(pRes->pDataBlock, j);
|
||||||
|
type = pExprInfo[j].base.resSchema.type;
|
||||||
|
bytes = pExprInfo[j].base.resSchema.bytes;
|
||||||
|
|
||||||
|
if (pExprInfo[j].base.pColumns->info.colId == TSDB_TBNAME_COLUMN_INDEX) {
|
||||||
|
data = tsdbGetTableName(item->pTable);
|
||||||
|
} else {
|
||||||
|
data = tsdbGetTableTagVal(item->pTable, pExprInfo[j].base.pColumns->info.colId, type, bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
dst = pColInfo->pData + count * pExprInfo[j].base.resSchema.bytes;
|
||||||
|
doSetTagValueToResultBuf(dst, data, type, bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pInfo->curPos >= pInfo->totalTables) {
|
||||||
|
pOperator->status = OP_EXEC_DONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//qDebug("QInfo:0x%"PRIx64" create tag values results completed, rows:%d", GET_TASKID(pRuntimeEnv), count);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pOperator->status == OP_EXEC_DONE) {
|
||||||
|
setTaskStatus(pOperator->pRuntimeEnv, TASK_COMPLETED);
|
||||||
|
}
|
||||||
|
|
||||||
|
pRes->info.rows = count;
|
||||||
|
return (pRes->info.rows == 0)? NULL:pInfo->pRes;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void destroyTagScanOperatorInfo(void* param, int32_t numOfOutput) {
|
||||||
|
STagScanInfo* pInfo = (STagScanInfo*)param;
|
||||||
|
pInfo->pRes = blockDataDestroy(pInfo->pRes);
|
||||||
|
}
|
||||||
|
|
||||||
|
SOperatorInfo* createTagScanOperatorInfo(void* pReaderHandle, SExprInfo* pExpr, int32_t numOfOutput, SExecTaskInfo* pTaskInfo) {
|
||||||
|
STagScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STagScanInfo));
|
||||||
|
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||||
|
if (pInfo == NULL || pOperator == NULL) {
|
||||||
|
goto _error;
|
||||||
|
}
|
||||||
|
|
||||||
|
pInfo->pReader = pReaderHandle;
|
||||||
|
pInfo->curPos = 0;
|
||||||
|
pOperator->name = "TagScanOperator";
|
||||||
|
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN;
|
||||||
|
pOperator->blockingOptr = false;
|
||||||
|
pOperator->status = OP_NOT_OPENED;
|
||||||
|
pOperator->info = pInfo;
|
||||||
|
pOperator->getNextFn = doTagScan;
|
||||||
|
pOperator->pExpr = pExpr;
|
||||||
|
pOperator->numOfOutput = numOfOutput;
|
||||||
|
pOperator->pTaskInfo = pTaskInfo;
|
||||||
|
pOperator->closeFn = destroyTagScanOperatorInfo;
|
||||||
|
|
||||||
|
return pOperator;
|
||||||
|
_error:
|
||||||
|
taosMemoryFree(pInfo);
|
||||||
|
taosMemoryFree(pOperator);
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ extern "C" {
|
||||||
#include "functionMgt.h"
|
#include "functionMgt.h"
|
||||||
|
|
||||||
bool functionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
bool functionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||||
int32_t functionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t slotId);
|
int32_t functionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||||
|
|
||||||
EFuncDataRequired countDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow);
|
EFuncDataRequired countDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow);
|
||||||
bool getCountFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
bool getCountFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||||
|
@ -43,17 +43,17 @@ int32_t maxFunction(SqlFunctionCtx *pCtx);
|
||||||
bool getAvgFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
bool getAvgFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||||
bool avgFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
bool avgFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||||
int32_t avgFunction(SqlFunctionCtx* pCtx);
|
int32_t avgFunction(SqlFunctionCtx* pCtx);
|
||||||
int32_t avgFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t slotId);
|
int32_t avgFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||||
|
|
||||||
bool getStddevFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
bool getStddevFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||||
bool stddevFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
bool stddevFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||||
int32_t stddevFunction(SqlFunctionCtx* pCtx);
|
int32_t stddevFunction(SqlFunctionCtx* pCtx);
|
||||||
int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t slotId);
|
int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||||
|
|
||||||
bool getPercentileFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
bool getPercentileFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||||
bool percentileFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
bool percentileFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||||
int32_t percentileFunction(SqlFunctionCtx *pCtx);
|
int32_t percentileFunction(SqlFunctionCtx *pCtx);
|
||||||
int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t slotId);
|
int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||||
|
|
||||||
bool getDiffFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
bool getDiffFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||||
bool diffFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResInfo);
|
bool diffFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResInfo);
|
||||||
|
@ -65,7 +65,7 @@ int32_t lastFunction(SqlFunctionCtx *pCtx);
|
||||||
|
|
||||||
bool getTopBotFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv);
|
bool getTopBotFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv);
|
||||||
int32_t topFunction(SqlFunctionCtx *pCtx);
|
int32_t topFunction(SqlFunctionCtx *pCtx);
|
||||||
int32_t topBotFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t slotId);
|
int32_t topBotFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,9 @@ extern "C" {
|
||||||
|
|
||||||
#define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0)
|
#define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0)
|
||||||
|
|
||||||
#define FUNC_UDF_ID_START_OFFSET_VAL 5000
|
#define FUNC_UDF_ID_START 5000
|
||||||
|
#define FUNC_AGGREGATE_UDF_ID 5001
|
||||||
|
#define FUNC_SCALAR_UDF_ID 5002
|
||||||
|
|
||||||
extern const int funcMgtUdfNum;
|
extern const int funcMgtUdfNum;
|
||||||
|
|
||||||
|
|
|
@ -42,19 +42,7 @@ enum {
|
||||||
UDFC_CODE_INVALID_STATE = -5
|
UDFC_CODE_INVALID_STATE = -5
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void *UdfcFuncHandle;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* create udfd proxy, called once in process that call setupUdf/callUdfxxx/teardownUdf
|
|
||||||
* @return error code
|
|
||||||
*/
|
|
||||||
int32_t udfcOpen();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* destroy udfd proxy
|
|
||||||
* @return error code
|
|
||||||
*/
|
|
||||||
int32_t udfcClose();
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -14,7 +14,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "builtinsimpl.h"
|
#include "builtinsimpl.h"
|
||||||
#include <libs/nodes/querynodes.h>
|
#include "function.h"
|
||||||
#include "querynodes.h"
|
#include "querynodes.h"
|
||||||
#include "taggfunction.h"
|
#include "taggfunction.h"
|
||||||
#include "tdatablock.h"
|
#include "tdatablock.h"
|
||||||
|
@ -44,8 +44,6 @@ typedef struct STopBotResItem {
|
||||||
} STopBotResItem;
|
} STopBotResItem;
|
||||||
|
|
||||||
typedef struct STopBotRes {
|
typedef struct STopBotRes {
|
||||||
int32_t pageId;
|
|
||||||
// int32_t num;
|
|
||||||
STopBotResItem *pItems;
|
STopBotResItem *pItems;
|
||||||
} STopBotRes;
|
} STopBotRes;
|
||||||
|
|
||||||
|
@ -92,18 +90,6 @@ typedef struct SDiffInfo {
|
||||||
} \
|
} \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
#define DO_UPDATE_SUBSID_RES(ctx, ts) \
|
|
||||||
do { \
|
|
||||||
for (int32_t _i = 0; _i < (ctx)->subsidiaryRes.numOfCols; ++_i) { \
|
|
||||||
SqlFunctionCtx *__ctx = (ctx)->subsidiaryRes.pCtx[_i]; \
|
|
||||||
if (__ctx->functionId == FUNCTION_TS_DUMMY) { \
|
|
||||||
__ctx->tag.i = (ts); \
|
|
||||||
__ctx->tag.nType = TSDB_DATA_TYPE_BIGINT; \
|
|
||||||
} \
|
|
||||||
__ctx->fpSet.process(__ctx); \
|
|
||||||
} \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#define UPDATE_DATA(ctx, left, right, num, sign, _ts) \
|
#define UPDATE_DATA(ctx, left, right, num, sign, _ts) \
|
||||||
do { \
|
do { \
|
||||||
if (((left) < (right)) ^ (sign)) { \
|
if (((left) < (right)) ^ (sign)) { \
|
||||||
|
@ -139,7 +125,8 @@ bool functionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t functionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t slotId) {
|
int32_t functionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
|
int32_t slotId = pCtx->pExpr->base.resSchema.slotId;
|
||||||
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
|
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
|
||||||
|
|
||||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||||
|
@ -406,7 +393,7 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t avgFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t slotId) {
|
int32_t avgFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
SInputColumnInfoData* pInput = &pCtx->input;
|
SInputColumnInfoData* pInput = &pCtx->input;
|
||||||
int32_t type = pInput->pData[0]->info.type;
|
int32_t type = pInput->pData[0]->info.type;
|
||||||
SAvgRes* pAvgRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
SAvgRes* pAvgRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||||
|
@ -416,7 +403,7 @@ int32_t avgFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t slotId) {
|
||||||
pAvgRes->result = pAvgRes->sum.dsum / ((double) pAvgRes->count);
|
pAvgRes->result = pAvgRes->sum.dsum / ((double) pAvgRes->count);
|
||||||
}
|
}
|
||||||
|
|
||||||
return functionFinalize(pCtx, pBlock, slotId);
|
return functionFinalize(pCtx, pBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
EFuncDataRequired statisDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow){
|
EFuncDataRequired statisDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow){
|
||||||
|
@ -521,6 +508,49 @@ bool getMinmaxFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define GET_TS_LIST(x) ((TSKEY*)((x)->ptsList))
|
||||||
|
#define GET_TS_DATA(x, y) (GET_TS_LIST(x)[(y)])
|
||||||
|
|
||||||
|
#define DO_UPDATE_TAG_COLUMNS_WITHOUT_TS(ctx) \
|
||||||
|
do { \
|
||||||
|
for (int32_t _i = 0; _i < (ctx)->tagInfo.numOfTagCols; ++_i) { \
|
||||||
|
SqlFunctionCtx *__ctx = (ctx)->tagInfo.pTagCtxList[_i]; \
|
||||||
|
__ctx->fpSet.process(__ctx); \
|
||||||
|
} \
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
#define DO_UPDATE_SUBSID_RES(ctx, ts) \
|
||||||
|
do { \
|
||||||
|
for (int32_t _i = 0; _i < (ctx)->subsidiaries.num; ++_i) { \
|
||||||
|
SqlFunctionCtx* __ctx = (ctx)->subsidiaries.pCtx[_i]; \
|
||||||
|
if (__ctx->functionId == FUNCTION_TS_DUMMY) { \
|
||||||
|
__ctx->tag.i = (ts); \
|
||||||
|
__ctx->tag.nType = TSDB_DATA_TYPE_BIGINT; \
|
||||||
|
} \
|
||||||
|
__ctx->fpSet.process(__ctx); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define UPDATE_DATA(ctx, left, right, num, sign, _ts) \
|
||||||
|
do { \
|
||||||
|
if (((left) < (right)) ^ (sign)) { \
|
||||||
|
(left) = (right); \
|
||||||
|
DO_UPDATE_SUBSID_RES(ctx, _ts); \
|
||||||
|
(num) += 1; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define LOOPCHECK_N(val, _col, ctx, _t, _nrow, _start, sign, num) \
|
||||||
|
do { \
|
||||||
|
_t *d = (_t *)((_col)->pData); \
|
||||||
|
for (int32_t i = (_start); i < (_nrow) + (_start); ++i) { \
|
||||||
|
if (((_col)->hasNull) && colDataIsNull_f((_col)->nullbitmap, i)) { \
|
||||||
|
continue; \
|
||||||
|
} \
|
||||||
|
TSKEY ts = (ctx)->ptsList != NULL ? GET_TS_DATA(ctx, i) : 0; \
|
||||||
|
UPDATE_DATA(ctx, val, d[i], num, sign, ts); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
int32_t doMinMaxHelper(SqlFunctionCtx *pCtx, int32_t isMinFunc) {
|
int32_t doMinMaxHelper(SqlFunctionCtx *pCtx, int32_t isMinFunc) {
|
||||||
int32_t numOfElems = 0;
|
int32_t numOfElems = 0;
|
||||||
|
@ -564,8 +594,8 @@ int32_t doMinMaxHelper(SqlFunctionCtx *pCtx, int32_t isMinFunc) {
|
||||||
int64_t val = GET_INT64_VAL(tval);
|
int64_t val = GET_INT64_VAL(tval);
|
||||||
if ((prev < val) ^ isMinFunc) {
|
if ((prev < val) ^ isMinFunc) {
|
||||||
*(int64_t*) buf = val;
|
*(int64_t*) buf = val;
|
||||||
for (int32_t i = 0; i < (pCtx)->subsidiaryRes.numOfCols; ++i) {
|
for (int32_t i = 0; i < (pCtx)->subsidiaries.num; ++i) {
|
||||||
SqlFunctionCtx* __ctx = pCtx->subsidiaryRes.pCtx[i];
|
SqlFunctionCtx* __ctx = pCtx->subsidiaries.pCtx[i];
|
||||||
if (__ctx->functionId == FUNCTION_TS_DUMMY) { // TODO refactor
|
if (__ctx->functionId == FUNCTION_TS_DUMMY) { // TODO refactor
|
||||||
__ctx->tag.i = key;
|
__ctx->tag.i = key;
|
||||||
__ctx->tag.nType = TSDB_DATA_TYPE_BIGINT;
|
__ctx->tag.nType = TSDB_DATA_TYPE_BIGINT;
|
||||||
|
@ -581,8 +611,8 @@ int32_t doMinMaxHelper(SqlFunctionCtx *pCtx, int32_t isMinFunc) {
|
||||||
uint64_t val = GET_UINT64_VAL(tval);
|
uint64_t val = GET_UINT64_VAL(tval);
|
||||||
if ((prev < val) ^ isMinFunc) {
|
if ((prev < val) ^ isMinFunc) {
|
||||||
*(uint64_t*) buf = val;
|
*(uint64_t*) buf = val;
|
||||||
for (int32_t i = 0; i < (pCtx)->subsidiaryRes.numOfCols; ++i) {
|
for (int32_t i = 0; i < (pCtx)->subsidiaries.num; ++i) {
|
||||||
SqlFunctionCtx* __ctx = pCtx->subsidiaryRes.pCtx[i];
|
SqlFunctionCtx* __ctx = pCtx->subsidiaries.pCtx[i];
|
||||||
if (__ctx->functionId == FUNCTION_TS_DUMMY) { // TODO refactor
|
if (__ctx->functionId == FUNCTION_TS_DUMMY) { // TODO refactor
|
||||||
__ctx->tag.i = key;
|
__ctx->tag.i = key;
|
||||||
__ctx->tag.nType = TSDB_DATA_TYPE_BIGINT;
|
__ctx->tag.nType = TSDB_DATA_TYPE_BIGINT;
|
||||||
|
@ -797,7 +827,7 @@ int32_t stddevFunction(SqlFunctionCtx* pCtx) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t slotId) {
|
int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
SInputColumnInfoData* pInput = &pCtx->input;
|
SInputColumnInfoData* pInput = &pCtx->input;
|
||||||
int32_t type = pInput->pData[0]->info.type;
|
int32_t type = pInput->pData[0]->info.type;
|
||||||
SStddevRes* pStddevRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
SStddevRes* pStddevRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||||
|
@ -810,7 +840,7 @@ int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t slotId
|
||||||
pStddevRes->result = sqrt(pStddevRes->quadraticDSum/((double)pStddevRes->count) - avg*avg);
|
pStddevRes->result = sqrt(pStddevRes->quadraticDSum/((double)pStddevRes->count) - avg*avg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return functionFinalize(pCtx, pBlock, slotId);
|
return functionFinalize(pCtx, pBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getPercentileFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
bool getPercentileFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
||||||
|
@ -923,7 +953,7 @@ int32_t percentileFunction(SqlFunctionCtx *pCtx) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t slotId) {
|
int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
SVariant* pVal = &pCtx->param[1].param;
|
SVariant* pVal = &pCtx->param[1].param;
|
||||||
double v = pVal->nType == TSDB_DATA_TYPE_INT ? pVal->i : pVal->d;
|
double v = pVal->nType == TSDB_DATA_TYPE_INT ? pVal->i : pVal->d;
|
||||||
|
|
||||||
|
@ -936,7 +966,7 @@ int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t sl
|
||||||
}
|
}
|
||||||
|
|
||||||
tMemBucketDestroy(pMemBucket);
|
tMemBucketDestroy(pMemBucket);
|
||||||
return functionFinalize(pCtx, pBlock, slotId);
|
return functionFinalize(pCtx, pBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getFirstLastFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
bool getFirstLastFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
||||||
|
@ -1353,15 +1383,16 @@ static STopBotRes *getTopBotOutputInfo(SqlFunctionCtx *pCtx) {
|
||||||
return pRes;
|
return pRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void doAddIntoResult(STopBotRes* pRes, int32_t maxSize, void* pData, int32_t rowIndex, SSDataBlock* pSrcBlock,
|
static void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSDataBlock* pSrcBlock,
|
||||||
uint16_t type, uint64_t uid, SResultRowEntryInfo* pEntryInfo);
|
uint16_t type, uint64_t uid, SResultRowEntryInfo* pEntryInfo);
|
||||||
|
|
||||||
|
static void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STopBotResItem* pItem);
|
||||||
|
static void copyTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STopBotResItem* pItem);
|
||||||
|
|
||||||
int32_t topFunction(SqlFunctionCtx *pCtx) {
|
int32_t topFunction(SqlFunctionCtx *pCtx) {
|
||||||
int32_t numOfElems = 0;
|
int32_t numOfElems = 0;
|
||||||
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
|
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
|
||||||
|
|
||||||
STopBotRes *pRes = getTopBotOutputInfo(pCtx);
|
|
||||||
|
|
||||||
// if ((void *)pRes->res[0] != (void *)((char *)pRes + sizeof(STopBotRes) + POINTER_BYTES * pCtx->param[0].i)) {
|
// if ((void *)pRes->res[0] != (void *)((char *)pRes + sizeof(STopBotRes) + POINTER_BYTES * pCtx->param[0].i)) {
|
||||||
// buildTopBotStruct(pRes, pCtx);
|
// buildTopBotStruct(pRes, pCtx);
|
||||||
// }
|
// }
|
||||||
|
@ -1381,7 +1412,7 @@ int32_t topFunction(SqlFunctionCtx *pCtx) {
|
||||||
numOfElems++;
|
numOfElems++;
|
||||||
|
|
||||||
char* data = colDataGetData(pCol, i);
|
char* data = colDataGetData(pCol, i);
|
||||||
doAddIntoResult(pRes, pCtx->param[1].param.i, data, i, NULL, type, pInput->uid, pResInfo);
|
doAddIntoResult(pCtx, data, i, pCtx->pSrcBlock, type, pInput->uid, pResInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -1414,9 +1445,11 @@ static int32_t topBotResComparFn(const void *p1, const void *p2, const void *par
|
||||||
return (val1->v.d > val2->v.d) ? 1 : -1;
|
return (val1->v.d > val2->v.d) ? 1 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSDataBlock* pSrcBlock, uint16_t type,
|
||||||
|
uint64_t uid, SResultRowEntryInfo* pEntryInfo) {
|
||||||
|
STopBotRes *pRes = getTopBotOutputInfo(pCtx);
|
||||||
|
int32_t maxSize = pCtx->param[1].param.i;
|
||||||
|
|
||||||
void doAddIntoResult(STopBotRes *pRes, int32_t maxSize, void *pData, int32_t rowIndex, SSDataBlock* pSrcBlock, uint16_t type,
|
|
||||||
uint64_t uid, SResultRowEntryInfo* pEntryInfo) {
|
|
||||||
SVariant val = {0};
|
SVariant val = {0};
|
||||||
taosVariantCreateFromBinary(&val, pData, tDataTypes[type].bytes, type);
|
taosVariantCreateFromBinary(&val, pData, tDataTypes[type].bytes, type);
|
||||||
|
|
||||||
|
@ -1428,22 +1461,9 @@ void doAddIntoResult(STopBotRes *pRes, int32_t maxSize, void *pData, int32_t row
|
||||||
STopBotResItem* pItem = &pItems[pEntryInfo->numOfRes];
|
STopBotResItem* pItem = &pItems[pEntryInfo->numOfRes];
|
||||||
pItem->v = val;
|
pItem->v = val;
|
||||||
pItem->uid = uid;
|
pItem->uid = uid;
|
||||||
pItem->tuplePos.pageId = -1; // todo set the corresponding tuple data in the disk-based buffer
|
|
||||||
|
|
||||||
if (pRes->pageId == -1) {
|
// save the data of this tuple
|
||||||
SFilePage* pPage = getNewBufPage(NULL, 0, &pRes->pageId);
|
saveTupleData(pCtx, rowIndex, pSrcBlock, pItem);
|
||||||
pPage->num = sizeof(SFilePage);
|
|
||||||
|
|
||||||
// keep the current row data
|
|
||||||
for(int32_t i = 0; i < pSrcBlock->info.numOfCols; ++i) {
|
|
||||||
SColumnInfoData* pCol = taosArrayGet(pSrcBlock->pDataBlock, i);
|
|
||||||
bool isNull = colDataIsNull_s(pCol, rowIndex);
|
|
||||||
|
|
||||||
|
|
||||||
colDataGetData(pCol, rowIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// allocate the buffer and keep the data of this row into the new allocated buffer
|
// allocate the buffer and keep the data of this row into the new allocated buffer
|
||||||
pEntryInfo->numOfRes++;
|
pEntryInfo->numOfRes++;
|
||||||
|
@ -1452,22 +1472,100 @@ void doAddIntoResult(STopBotRes *pRes, int32_t maxSize, void *pData, int32_t row
|
||||||
if ((IS_SIGNED_NUMERIC_TYPE(type) && val.i > pItems[0].v.i) ||
|
if ((IS_SIGNED_NUMERIC_TYPE(type) && val.i > pItems[0].v.i) ||
|
||||||
(IS_UNSIGNED_NUMERIC_TYPE(type) && val.u > pItems[0].v.u) ||
|
(IS_UNSIGNED_NUMERIC_TYPE(type) && val.u > pItems[0].v.u) ||
|
||||||
(IS_FLOAT_TYPE(type) && val.d > pItems[0].v.d)) {
|
(IS_FLOAT_TYPE(type) && val.d > pItems[0].v.d)) {
|
||||||
|
// replace the old data and the coresponding tuple data
|
||||||
STopBotResItem* pItem = &pItems[0];
|
STopBotResItem* pItem = &pItems[0];
|
||||||
pItem->v = val;
|
pItem->v = val;
|
||||||
pItem->uid = uid;
|
pItem->uid = uid;
|
||||||
pItem->tuplePos.pageId = -1; // todo set the corresponding tuple data in the disk-based buffer
|
|
||||||
|
// save the data of this tuple by over writing the old data
|
||||||
|
copyTupleData(pCtx, rowIndex, pSrcBlock, pItem);
|
||||||
|
|
||||||
taosheapadjust((void *) pItems, sizeof(STopBotResItem), 0, pEntryInfo->numOfRes - 1, (const void *) &type, topBotResComparFn, NULL, false);
|
taosheapadjust((void *) pItems, sizeof(STopBotResItem), 0, pEntryInfo->numOfRes - 1, (const void *) &type, topBotResComparFn, NULL, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t topBotFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t slotId) {
|
void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STopBotResItem* pItem) {
|
||||||
|
SFilePage* pPage = NULL;
|
||||||
|
|
||||||
|
int32_t completeRowSize = pSrcBlock->info.rowSize + pSrcBlock->info.numOfCols * sizeof(bool);
|
||||||
|
|
||||||
|
if (pCtx->curBufPage == -1) {
|
||||||
|
pPage = getNewBufPage(pCtx->pBuf, 0, &pCtx->curBufPage);
|
||||||
|
pPage->num = sizeof(SFilePage);
|
||||||
|
} else {
|
||||||
|
pPage = getBufPage(pCtx->pBuf, pCtx->curBufPage);
|
||||||
|
if (pPage->num + completeRowSize > getBufPageSize(pCtx->pBuf)) {
|
||||||
|
pPage = getNewBufPage(pCtx->pBuf, 0, &pCtx->curBufPage);
|
||||||
|
pPage->num = sizeof(SFilePage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pItem->tuplePos.pageId = pCtx->curBufPage;
|
||||||
|
|
||||||
|
// keep the current row data, extract method
|
||||||
|
int32_t offset = 0;
|
||||||
|
bool* nullList = (bool*)((char*)pPage + pPage->num);
|
||||||
|
char* pStart = (char*)(nullList + sizeof(bool) * pSrcBlock->info.numOfCols);
|
||||||
|
for (int32_t i = 0; i < pSrcBlock->info.numOfCols; ++i) {
|
||||||
|
SColumnInfoData* pCol = taosArrayGet(pSrcBlock->pDataBlock, i);
|
||||||
|
bool isNull = colDataIsNull_s(pCol, rowIndex);
|
||||||
|
if (isNull) {
|
||||||
|
nullList[i] = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* p = colDataGetData(pCol, rowIndex);
|
||||||
|
if (IS_VAR_DATA_TYPE(pCol->info.type)) {
|
||||||
|
memcpy(pStart + offset, p, varDataTLen(p));
|
||||||
|
} else {
|
||||||
|
memcpy(pStart + offset, p, pCol->info.bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
offset += pCol->info.bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
pItem->tuplePos.offset = pPage->num;
|
||||||
|
pPage->num += completeRowSize;
|
||||||
|
|
||||||
|
setBufPageDirty(pPage, true);
|
||||||
|
releaseBufPage(pCtx->pBuf, pPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
void copyTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STopBotResItem* pItem) {
|
||||||
|
SFilePage* pPage = getBufPage(pCtx->pBuf, pItem->tuplePos.pageId);
|
||||||
|
|
||||||
|
bool* nullList = (bool*)((char*)pPage + pItem->tuplePos.offset);
|
||||||
|
char* pStart = (char*)(nullList + pSrcBlock->info.numOfCols * sizeof(bool));
|
||||||
|
|
||||||
|
int32_t offset = 0;
|
||||||
|
for(int32_t i = 0; i < pSrcBlock->info.numOfCols; ++i) {
|
||||||
|
SColumnInfoData* pCol = taosArrayGet(pSrcBlock->pDataBlock, i);
|
||||||
|
if ((nullList[i] = colDataIsNull_s(pCol, rowIndex)) == true) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* p = colDataGetData(pCol, rowIndex);
|
||||||
|
if (IS_VAR_DATA_TYPE(pCol->info.type)) {
|
||||||
|
memcpy(pStart + offset, p, varDataTLen(p));
|
||||||
|
} else {
|
||||||
|
memcpy(pStart + offset, p, pCol->info.bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
offset += pCol->info.bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
setBufPageDirty(pPage, true);
|
||||||
|
releaseBufPage(pCtx->pBuf, pPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t topBotFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
SResultRowEntryInfo *pEntryInfo = GET_RES_INFO(pCtx);
|
SResultRowEntryInfo *pEntryInfo = GET_RES_INFO(pCtx);
|
||||||
STopBotRes* pRes = GET_ROWCELL_INTERBUF(pEntryInfo);
|
STopBotRes* pRes = GET_ROWCELL_INTERBUF(pEntryInfo);
|
||||||
pEntryInfo->complete = true;
|
pEntryInfo->complete = true;
|
||||||
|
|
||||||
int32_t type = pCtx->input.pData[0]->info.type;
|
int32_t type = pCtx->input.pData[0]->info.type;
|
||||||
|
int32_t slotId = pCtx->pExpr->base.resSchema.slotId;
|
||||||
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
|
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
|
||||||
|
|
||||||
// todo assign the tag value and the corresponding row data
|
// todo assign the tag value and the corresponding row data
|
||||||
|
@ -1476,19 +1574,45 @@ int32_t topBotFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t slotId
|
||||||
case TSDB_DATA_TYPE_INT: {
|
case TSDB_DATA_TYPE_INT: {
|
||||||
for (int32_t i = 0; i < pEntryInfo->numOfRes; ++i) {
|
for (int32_t i = 0; i < pEntryInfo->numOfRes; ++i) {
|
||||||
STopBotResItem* pItem = &pRes->pItems[i];
|
STopBotResItem* pItem = &pRes->pItems[i];
|
||||||
colDataAppendInt32(pCol, currentRow++, (int32_t*)&pItem->v.i);
|
colDataAppendInt32(pCol, currentRow, (int32_t*)&pItem->v.i);
|
||||||
|
|
||||||
int32_t pageId = pItem->tuplePos.pageId;
|
int32_t pageId = pItem->tuplePos.pageId;
|
||||||
int32_t offset = pItem->tuplePos.offset;
|
int32_t offset = pItem->tuplePos.offset;
|
||||||
if (pageId != -1) {
|
if (pItem->tuplePos.pageId != -1) {
|
||||||
// todo
|
SFilePage* pPage = getBufPage(pCtx->pBuf, pageId);
|
||||||
|
|
||||||
|
bool* nullList = (bool*)((char*)pPage + offset);
|
||||||
|
char* pStart = (char*)(nullList + pCtx->pSrcBlock->info.numOfCols * sizeof(bool));
|
||||||
|
|
||||||
|
// todo set the offset value to optimize the performance.
|
||||||
|
for (int32_t j = 0; j < pCtx->subsidiaries.num; ++j) {
|
||||||
|
SqlFunctionCtx* pc = pCtx->subsidiaries.pCtx[j];
|
||||||
|
|
||||||
|
SFunctParam *pFuncParam = &pc->pExpr->base.pParam[0];
|
||||||
|
int32_t srcSlotId = pFuncParam->pCol->slotId;
|
||||||
|
int32_t dstSlotId = pCtx->pExpr->base.resSchema.slotId;
|
||||||
|
|
||||||
|
int32_t ps = 0;
|
||||||
|
for(int32_t k = 0; k < srcSlotId; ++k) {
|
||||||
|
SColumnInfoData* pSrcCol = taosArrayGet(pCtx->pSrcBlock->pDataBlock, k);
|
||||||
|
ps += pSrcCol->info.bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
SColumnInfoData* pDstCol = taosArrayGet(pBlock->pDataBlock, dstSlotId);
|
||||||
|
if (nullList[srcSlotId]) {
|
||||||
|
colDataAppendNULL(pDstCol, currentRow);
|
||||||
|
} else {
|
||||||
|
colDataAppend(pDstCol, currentRow, (pStart + ps), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentRow += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return pEntryInfo->numOfRes;
|
return pEntryInfo->numOfRes;
|
||||||
|
|
||||||
// return functionFinalize(pCtx, pBlock, slotId);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
|
|
||||||
typedef struct SFuncMgtService {
|
typedef struct SFuncMgtService {
|
||||||
SHashObj* pFuncNameHashTable;
|
SHashObj* pFuncNameHashTable;
|
||||||
SArray* pUdfTable; // SUdfInfo
|
|
||||||
} SFuncMgtService;
|
} SFuncMgtService;
|
||||||
|
|
||||||
typedef struct SUdfInfo {
|
typedef struct SUdfInfo {
|
||||||
|
@ -49,18 +48,12 @@ static void doInitFunctionTable() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gFunMgtService.pUdfTable = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int8_t getUdfType(int32_t funcId) {
|
|
||||||
SUdfInfo* pUdf = taosArrayGet(gFunMgtService.pUdfTable, funcId - FUNC_UDF_ID_START_OFFSET_VAL - 1);
|
|
||||||
return pUdf->funcType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isSpecificClassifyFunc(int32_t funcId, uint64_t classification) {
|
static bool isSpecificClassifyFunc(int32_t funcId, uint64_t classification) {
|
||||||
if (fmIsUserDefinedFunc(funcId)) {
|
if (fmIsUserDefinedFunc(funcId)) {
|
||||||
return getUdfType(funcId);
|
return FUNC_MGT_AGG_FUNC == classification ? FUNC_AGGREGATE_UDF_ID == funcId :
|
||||||
|
(FUNC_MGT_SCALAR_FUNC == classification ? FUNC_SCALAR_UDF_ID == funcId : false);
|
||||||
}
|
}
|
||||||
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -68,33 +61,23 @@ static bool isSpecificClassifyFunc(int32_t funcId, uint64_t classification) {
|
||||||
return FUNC_MGT_TEST_MASK(funcMgtBuiltins[funcId].classification, classification);
|
return FUNC_MGT_TEST_MASK(funcMgtBuiltins[funcId].classification, classification);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t getUdfId(SFmGetFuncInfoParam* pParam, const char* pFuncName) {
|
static int32_t getUdfInfo(SFmGetFuncInfoParam* pParam, SFunctionNode* pFunc) {
|
||||||
SFuncInfo* pInfo = NULL;
|
SFuncInfo* pInfo = NULL;
|
||||||
int32_t code = catalogGetUdfInfo(pParam->pCtg, pParam->pRpc, pParam->pMgmtEps, pFuncName, &pInfo);
|
int32_t code = catalogGetUdfInfo(pParam->pCtg, pParam->pRpc, pParam->pMgmtEps, pFunc->functionName, &pInfo);
|
||||||
if (TSDB_CODE_SUCCESS != code || NULL == pInfo) {
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
if (NULL == gFunMgtService.pUdfTable) {
|
if (NULL == pInfo) {
|
||||||
gFunMgtService.pUdfTable = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SUdfInfo));
|
snprintf(pParam->pErrBuf, pParam->errBufLen, "Invalid function name: %s", pFunc->functionName);
|
||||||
|
return TSDB_CODE_FUNC_INVALID_FUNTION;
|
||||||
}
|
}
|
||||||
SUdfInfo info = { .outputDt.type = pInfo->outputType, .outputDt.bytes = pInfo->outputLen, .funcType = pInfo->funcType };
|
pFunc->funcType = FUNCTION_TYPE_UDF;
|
||||||
taosArrayPush(gFunMgtService.pUdfTable, &info);
|
pFunc->funcId = TSDB_FUNC_TYPE_AGGREGATE == pInfo->funcType ? FUNC_AGGREGATE_UDF_ID : FUNC_SCALAR_UDF_ID;
|
||||||
|
pFunc->node.resType.type = pInfo->outputType;
|
||||||
|
pFunc->node.resType.bytes = pInfo->outputLen;
|
||||||
|
pFunc->udfBufSize = pInfo->bufSize;
|
||||||
tFreeSFuncInfo(pInfo);
|
tFreeSFuncInfo(pInfo);
|
||||||
taosMemoryFree(pInfo);
|
taosMemoryFree(pInfo);
|
||||||
return taosArrayGetSize(gFunMgtService.pUdfTable) + FUNC_UDF_ID_START_OFFSET_VAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t getFuncId(SFmGetFuncInfoParam* pParam, const char* pFuncName) {
|
|
||||||
void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, pFuncName, strlen(pFuncName));
|
|
||||||
if (NULL == pVal) {
|
|
||||||
return getUdfId(pParam, pFuncName);
|
|
||||||
}
|
|
||||||
return *(int32_t*)pVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t getUdfResultType(SFunctionNode* pFunc) {
|
|
||||||
SUdfInfo* pUdf = taosArrayGet(gFunMgtService.pUdfTable, pFunc->funcId - FUNC_UDF_ID_START_OFFSET_VAL - 1);
|
|
||||||
pFunc->node.resType = pUdf->outputDt;
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,28 +86,14 @@ int32_t fmFuncMgtInit() {
|
||||||
return initFunctionCode;
|
return initFunctionCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t fmGetFuncInfo(SFmGetFuncInfoParam* pParam, const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType) {
|
int32_t fmGetFuncInfo(SFmGetFuncInfoParam* pParam, SFunctionNode* pFunc) {
|
||||||
*pFuncId = getFuncId(pParam, pFuncName);
|
void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, pFunc->functionName, strlen(pFunc->functionName));
|
||||||
if (*pFuncId < 0) {
|
if (NULL != pVal) {
|
||||||
return TSDB_CODE_FAILED;
|
pFunc->funcId = *(int32_t*)pVal;
|
||||||
|
pFunc->funcType = funcMgtBuiltins[pFunc->funcId].type;
|
||||||
|
return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, pParam->pErrBuf, pParam->errBufLen);
|
||||||
}
|
}
|
||||||
if (fmIsUserDefinedFunc(*pFuncId)) {
|
return getUdfInfo(pParam, pFunc);
|
||||||
*pFuncType = FUNCTION_TYPE_UDF;
|
|
||||||
} else {
|
|
||||||
*pFuncType = funcMgtBuiltins[*pFuncId].type;
|
|
||||||
}
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t fmGetFuncResultType(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|
||||||
if (fmIsUserDefinedFunc(pFunc->funcId)) {
|
|
||||||
return getUdfResultType(pFunc);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pFunc->funcId < 0 || pFunc->funcId >= funcMgtBuiltinsNum) {
|
|
||||||
return TSDB_CODE_FAILED;
|
|
||||||
}
|
|
||||||
return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, pErrBuf, len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) {
|
EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) {
|
||||||
|
@ -194,7 +163,7 @@ bool fmIsMultiResFunc(int32_t funcId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fmIsUserDefinedFunc(int32_t funcId) {
|
bool fmIsUserDefinedFunc(int32_t funcId) {
|
||||||
return funcId > FUNC_UDF_ID_START_OFFSET_VAL;
|
return funcId > FUNC_UDF_ID_START;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fmFuncMgtDestroy() {
|
void fmFuncMgtDestroy() {
|
||||||
|
|
|
@ -548,7 +548,7 @@ static int32_t udfdParseArgs(int32_t argc, char *argv[]) {
|
||||||
static int32_t udfdInitLog() {
|
static int32_t udfdInitLog() {
|
||||||
char logName[12] = {0};
|
char logName[12] = {0};
|
||||||
snprintf(logName, sizeof(logName), "%slog", "udfd");
|
snprintf(logName, sizeof(logName), "%slog", "udfd");
|
||||||
return taosCreateLog(logName, 1, configDir, NULL, NULL, NULL, 0);
|
return taosCreateLog(logName, 1, configDir, NULL, NULL, NULL, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void udfdCtrlAllocBufCb(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) {
|
void udfdCtrlAllocBufCb(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) {
|
||||||
|
@ -656,7 +656,7 @@ int main(int argc, char *argv[]) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosInitCfg(configDir, NULL, NULL, NULL, 0) != 0) {
|
if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 0) != 0) {
|
||||||
fnError("failed to start since read config error");
|
fnError("failed to start since read config error");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue