Merge branch '3.0' of https://github.com/taosdata/TDengine into dev
This commit is contained in:
commit
c376f5604d
|
@ -80,8 +80,9 @@ int32_t create_topic() {
|
||||||
}
|
}
|
||||||
taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
|
|
||||||
const char* sql = "select * from tu1";
|
/*const char* sql = "select * from tu1";*/
|
||||||
pRes = tmq_create_topic(pConn, "test_stb_topic_1", sql, strlen(sql));
|
/*pRes = tmq_create_topic(pConn, "test_stb_topic_1", sql, strlen(sql));*/
|
||||||
|
pRes = taos_query(pConn, "create topic test_stb_topic_1 as select * from tu1");
|
||||||
if (taos_errno(pRes) != 0) {
|
if (taos_errno(pRes) != 0) {
|
||||||
printf("failed to create topic test_stb_topic_1, reason:%s\n", taos_errstr(pRes));
|
printf("failed to create topic test_stb_topic_1, reason:%s\n", taos_errstr(pRes));
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -26,9 +26,11 @@ extern "C" {
|
||||||
typedef void TAOS;
|
typedef void TAOS;
|
||||||
typedef void TAOS_STMT;
|
typedef void TAOS_STMT;
|
||||||
typedef void TAOS_RES;
|
typedef void TAOS_RES;
|
||||||
typedef void TAOS_STREAM;
|
|
||||||
typedef void TAOS_SUB;
|
|
||||||
typedef void **TAOS_ROW;
|
typedef void **TAOS_ROW;
|
||||||
|
#if 0
|
||||||
|
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
|
||||||
|
@ -122,8 +124,25 @@ typedef struct TAOS_MULTI_BIND {
|
||||||
int num;
|
int num;
|
||||||
} TAOS_MULTI_BIND;
|
} TAOS_MULTI_BIND;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
SET_CONF_RET_SUCC = 0,
|
||||||
|
SET_CONF_RET_ERR_PART = -1,
|
||||||
|
SET_CONF_RET_ERR_INNER = -2,
|
||||||
|
SET_CONF_RET_ERR_JSON_INVALID = -3,
|
||||||
|
SET_CONF_RET_ERR_JSON_PARSE = -4,
|
||||||
|
SET_CONF_RET_ERR_ONLY_ONCE = -5,
|
||||||
|
SET_CONF_RET_ERR_TOO_LONG = -6
|
||||||
|
} SET_CONF_RET_CODE;
|
||||||
|
|
||||||
|
#define RET_MSG_LENGTH 1024
|
||||||
|
typedef struct setConfRet {
|
||||||
|
SET_CONF_RET_CODE retCode;
|
||||||
|
char retMsg[RET_MSG_LENGTH];
|
||||||
|
} setConfRet;
|
||||||
|
|
||||||
DLL_EXPORT void taos_cleanup(void);
|
DLL_EXPORT void taos_cleanup(void);
|
||||||
DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...);
|
DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...);
|
||||||
|
DLL_EXPORT setConfRet taos_set_config(const char *config);
|
||||||
DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port);
|
DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port);
|
||||||
DLL_EXPORT TAOS *taos_connect_l(const char *ip, int ipLen, const char *user, int userLen, const char *pass, int passLen,
|
DLL_EXPORT TAOS *taos_connect_l(const char *ip, int ipLen, const char *user, int userLen, const char *pass, int passLen,
|
||||||
const char *db, int dbLen, uint16_t port);
|
const char *db, int dbLen, uint16_t port);
|
||||||
|
@ -149,6 +168,7 @@ 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 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);
|
||||||
|
@ -165,10 +185,13 @@ DLL_EXPORT int taos_select_db(TAOS *taos, const char *db);
|
||||||
DLL_EXPORT int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields);
|
DLL_EXPORT int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields);
|
||||||
DLL_EXPORT void taos_stop_query(TAOS_RES *res);
|
DLL_EXPORT void taos_stop_query(TAOS_RES *res);
|
||||||
DLL_EXPORT bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col);
|
DLL_EXPORT bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col);
|
||||||
|
DLL_EXPORT bool taos_is_update_query(TAOS_RES *res);
|
||||||
DLL_EXPORT int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows);
|
DLL_EXPORT int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows);
|
||||||
DLL_EXPORT int taos_validate_sql(TAOS *taos, const char *sql);
|
DLL_EXPORT int taos_validate_sql(TAOS *taos, const char *sql);
|
||||||
|
DLL_EXPORT void taos_reset_current_db(TAOS *taos);
|
||||||
|
|
||||||
DLL_EXPORT int *taos_fetch_lengths(TAOS_RES *res);
|
DLL_EXPORT int *taos_fetch_lengths(TAOS_RES *res);
|
||||||
|
DLL_EXPORT TAOS_ROW *taos_result_block(TAOS_RES *res);
|
||||||
|
|
||||||
DLL_EXPORT const char *taos_get_server_info(TAOS *taos);
|
DLL_EXPORT const char *taos_get_server_info(TAOS *taos);
|
||||||
DLL_EXPORT const char *taos_get_client_info();
|
DLL_EXPORT const char *taos_get_client_info();
|
||||||
|
@ -179,15 +202,20 @@ DLL_EXPORT int taos_errno(TAOS_RES *tres);
|
||||||
DLL_EXPORT void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param);
|
DLL_EXPORT void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param);
|
||||||
DLL_EXPORT void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param);
|
DLL_EXPORT void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param);
|
||||||
|
|
||||||
|
// Shuduo: temporary enable for app build
|
||||||
|
#if 1
|
||||||
typedef void (*__taos_sub_fn_t)(TAOS_SUB *tsub, TAOS_RES *res, void *param, int code);
|
typedef void (*__taos_sub_fn_t)(TAOS_SUB *tsub, TAOS_RES *res, void *param, int code);
|
||||||
DLL_EXPORT TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char *topic, const char *sql, __taos_sub_fn_t fp,
|
DLL_EXPORT TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char *topic, const char *sql, __taos_sub_fn_t fp,
|
||||||
void *param, int interval);
|
void *param, int interval);
|
||||||
DLL_EXPORT TAOS_RES *taos_consume(TAOS_SUB *tsub);
|
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
|
||||||
|
|
||||||
|
#if 0
|
||||||
DLL_EXPORT TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sql, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row),
|
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 *));
|
int64_t stime, void *param, void (*callback)(void *));
|
||||||
DLL_EXPORT void taos_close_stream(TAOS_STREAM *tstr);
|
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);
|
||||||
|
@ -215,8 +243,12 @@ DLL_EXPORT tmq_list_t *tmq_list_new();
|
||||||
DLL_EXPORT int32_t tmq_list_append(tmq_list_t *, const char *);
|
DLL_EXPORT int32_t tmq_list_append(tmq_list_t *, const char *);
|
||||||
DLL_EXPORT void tmq_list_destroy(tmq_list_t *);
|
DLL_EXPORT void tmq_list_destroy(tmq_list_t *);
|
||||||
|
|
||||||
|
// will be removed in 3.0
|
||||||
DLL_EXPORT tmq_t *tmq_consumer_new(void *conn, tmq_conf_t *conf, char *errstr, int32_t errstrLen);
|
DLL_EXPORT tmq_t *tmq_consumer_new(void *conn, tmq_conf_t *conf, char *errstr, int32_t errstrLen);
|
||||||
|
|
||||||
|
// will replace last one
|
||||||
DLL_EXPORT tmq_t *tmq_consumer_new1(tmq_conf_t *conf, char *errstr, int32_t errstrLen);
|
DLL_EXPORT tmq_t *tmq_consumer_new1(tmq_conf_t *conf, char *errstr, int32_t errstrLen);
|
||||||
|
|
||||||
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------------------------ */
|
||||||
|
@ -257,18 +289,24 @@ int32_t tmqGetSkipLogNum(tmq_message_t *tmq_message);
|
||||||
|
|
||||||
DLL_EXPORT TAOS_ROW tmq_get_row(tmq_message_t *message);
|
DLL_EXPORT TAOS_ROW tmq_get_row(tmq_message_t *message);
|
||||||
DLL_EXPORT char *tmq_get_topic_name(tmq_message_t *message);
|
DLL_EXPORT char *tmq_get_topic_name(tmq_message_t *message);
|
||||||
DLL_EXPORT void *tmq_get_topic_schema(tmq_t *tmq, const char *topic);
|
DLL_EXPORT int32_t tmq_get_vgroup_id(tmq_message_t *message);
|
||||||
|
DLL_EXPORT int64_t tmq_get_request_offset(tmq_message_t *message);
|
||||||
|
DLL_EXPORT int64_t tmq_get_response_offset(tmq_message_t *message);
|
||||||
|
DLL_EXPORT TAOS_FIELD *tmq_get_fields(tmq_t *tmq, const char *topic);
|
||||||
|
DLL_EXPORT int32_t tmq_field_count(tmq_t *tmq, const char *topic);
|
||||||
DLL_EXPORT void tmq_message_destroy(tmq_message_t *tmq_message);
|
DLL_EXPORT void tmq_message_destroy(tmq_message_t *tmq_message);
|
||||||
|
|
||||||
/* --------------------TMPORARY INTERFACE FOR TESTING--------------------- */
|
/* --------------------TMPORARY INTERFACE FOR TESTING--------------------- */
|
||||||
|
#if 0
|
||||||
DLL_EXPORT TAOS_RES *tmq_create_topic(TAOS *taos, const char *name, const char *sql, int sqlLen);
|
DLL_EXPORT TAOS_RES *tmq_create_topic(TAOS *taos, const char *name, const char *sql, int sqlLen);
|
||||||
|
#endif
|
||||||
|
|
||||||
DLL_EXPORT TAOS_RES *tmq_create_stream(TAOS *taos, const char *streamName, const char *tbName, const char *sql);
|
DLL_EXPORT TAOS_RES *tmq_create_stream(TAOS *taos, const char *streamName, const char *tbName, const char *sql);
|
||||||
|
|
||||||
/* -------------------------------- OTHER -------------------------------- */
|
/* ------------------------------ TMQ END -------------------------------- */
|
||||||
|
#if 1 // Shuduo: temporary enable for app build
|
||||||
typedef void (*TAOS_SUBSCRIBE_CALLBACK)(TAOS_SUB *tsub, TAOS_RES *res, void *param, int code);
|
typedef void (*TAOS_SUBSCRIBE_CALLBACK)(TAOS_SUB *tsub, TAOS_RES *res, void *param, int code);
|
||||||
|
#endif
|
||||||
DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT *stmt);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,6 +197,11 @@ typedef struct SGroupbyExpr {
|
||||||
bool groupbyTag; // group by tag or column
|
bool groupbyTag; // group by tag or column
|
||||||
} SGroupbyExpr;
|
} SGroupbyExpr;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
FUNC_PARAM_TYPE_VALUE = 0,
|
||||||
|
FUNC_PARAM_TYPE_COLUMN,
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct SFunctParam {
|
typedef struct SFunctParam {
|
||||||
int32_t type;
|
int32_t type;
|
||||||
SColumn* pCol;
|
SColumn* pCol;
|
||||||
|
|
|
@ -133,7 +133,8 @@ static FORCE_INLINE int32_t colDataAppendInt32(SColumnInfoData* pColumnInfoData,
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int32_t colDataAppendInt64(SColumnInfoData* pColumnInfoData, uint32_t currentRow, int64_t* v) {
|
static FORCE_INLINE int32_t colDataAppendInt64(SColumnInfoData* pColumnInfoData, uint32_t currentRow, int64_t* v) {
|
||||||
ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_BIGINT || pColumnInfoData->info.type == TSDB_DATA_TYPE_UBIGINT);
|
int32_t type = pColumnInfoData->info.type;
|
||||||
|
ASSERT(type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_UBIGINT || type == TSDB_DATA_TYPE_TIMESTAMP);
|
||||||
char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow;
|
char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow;
|
||||||
*(int64_t*)p = *(int64_t*)v;
|
*(int64_t*)p = *(int64_t*)v;
|
||||||
}
|
}
|
||||||
|
@ -175,18 +176,17 @@ size_t blockDataGetRowSize(SSDataBlock* pBlock);
|
||||||
double blockDataGetSerialRowSize(const SSDataBlock* pBlock);
|
double blockDataGetSerialRowSize(const SSDataBlock* pBlock);
|
||||||
size_t blockDataGetSerialMetaSize(const SSDataBlock* pBlock);
|
size_t blockDataGetSerialMetaSize(const SSDataBlock* pBlock);
|
||||||
|
|
||||||
SSchema* blockDataExtractSchema(const SSDataBlock* pBlock, int32_t* numOfCols);
|
|
||||||
|
|
||||||
int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo);
|
int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo);
|
||||||
int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirst);
|
int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirst);
|
||||||
|
|
||||||
int32_t blockDataEnsureColumnCapacity(SColumnInfoData* pColumn, uint32_t numOfRows);
|
int32_t blockDataEnsureColumnCapacity(SColumnInfoData* pColumn, uint32_t numOfRows);
|
||||||
int32_t blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows);
|
int32_t blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows);
|
||||||
void blockDataCleanup(SSDataBlock* pDataBlock);
|
void blockDataCleanup(SSDataBlock* pDataBlock);
|
||||||
SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock);
|
|
||||||
size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize);
|
size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize);
|
||||||
void* blockDataDestroy(SSDataBlock* pBlock);
|
void* blockDataDestroy(SSDataBlock* pBlock);
|
||||||
|
|
||||||
|
SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock);
|
||||||
|
|
||||||
void blockDebugShowData(const SArray* dataBlocks);
|
void blockDebugShowData(const SArray* dataBlocks);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -51,7 +51,7 @@ extern int32_t tsCompatibleModel;
|
||||||
extern bool tsEnableSlaveQuery;
|
extern bool tsEnableSlaveQuery;
|
||||||
extern bool tsPrintAuth;
|
extern bool tsPrintAuth;
|
||||||
extern int64_t tsTickPerDay[3];
|
extern int64_t tsTickPerDay[3];
|
||||||
extern int32_t tsMultiProcess;
|
extern bool tsMultiProcess;
|
||||||
|
|
||||||
// monitor
|
// monitor
|
||||||
extern bool tsEnableMonitor;
|
extern bool tsEnableMonitor;
|
||||||
|
|
|
@ -469,8 +469,7 @@ typedef struct {
|
||||||
int32_t tz; // query client timezone
|
int32_t tz; // query client timezone
|
||||||
char intervalUnit;
|
char intervalUnit;
|
||||||
char slidingUnit;
|
char slidingUnit;
|
||||||
char
|
char offsetUnit; // TODO Remove it, the offset is the number of precision tickle, and it must be a immutable duration.
|
||||||
offsetUnit; // TODO Remove it, the offset is the number of precision tickle, and it must be a immutable duration.
|
|
||||||
int8_t precision;
|
int8_t precision;
|
||||||
int64_t interval;
|
int64_t interval;
|
||||||
int64_t sliding;
|
int64_t sliding;
|
||||||
|
@ -2017,7 +2016,6 @@ typedef struct {
|
||||||
int8_t slidingUnit; // MACRO: TIME_UNIT_XXX
|
int8_t slidingUnit; // MACRO: TIME_UNIT_XXX
|
||||||
int8_t timezoneInt; // sma data expired if timezone changes.
|
int8_t timezoneInt; // sma data expired if timezone changes.
|
||||||
char indexName[TSDB_INDEX_NAME_LEN];
|
char indexName[TSDB_INDEX_NAME_LEN];
|
||||||
char timezone[TD_TIMEZONE_LEN];
|
|
||||||
int32_t exprLen;
|
int32_t exprLen;
|
||||||
int32_t tagsFilterLen;
|
int32_t tagsFilterLen;
|
||||||
int64_t indexUid;
|
int64_t indexUid;
|
||||||
|
@ -2055,32 +2053,6 @@ void* tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
|
||||||
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
|
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
|
||||||
void* tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
|
void* tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
col_id_t colId;
|
|
||||||
uint16_t blockSize; // sma data block size
|
|
||||||
char data[];
|
|
||||||
} STSmaColData;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
tb_uid_t tableUid; // super/child/normal table uid
|
|
||||||
int32_t dataLen; // not including head
|
|
||||||
char data[];
|
|
||||||
} STSmaTbData;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int64_t indexUid;
|
|
||||||
TSKEY skey; // startKey of one interval/sliding window
|
|
||||||
int64_t interval;
|
|
||||||
int32_t dataLen; // not including head
|
|
||||||
int8_t intervalUnit;
|
|
||||||
char data[];
|
|
||||||
} STSmaDataWrapper; // sma data for a interval/sliding window
|
|
||||||
|
|
||||||
// interval/sliding => window
|
|
||||||
|
|
||||||
// => window->table->colId
|
|
||||||
// => 当一个window下所有的表均计算完成时,流计算告知tsdb清除window的过期标记
|
|
||||||
|
|
||||||
// RSma: Rollup SMA
|
// RSma: Rollup SMA
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int64_t interval;
|
int64_t interval;
|
||||||
|
@ -2215,23 +2187,6 @@ static FORCE_INLINE void* tDecodeTSmaWrapper(void* buf, STSmaWrapper* pSW) {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int64_t uid;
|
|
||||||
int32_t numOfRows;
|
|
||||||
char* colData;
|
|
||||||
} SMqTbData;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
char topicName[TSDB_TOPIC_FNAME_LEN];
|
|
||||||
int64_t committedOffset;
|
|
||||||
int64_t reqOffset;
|
|
||||||
int64_t rspOffset;
|
|
||||||
int32_t skipLogNum;
|
|
||||||
int32_t bodyLen;
|
|
||||||
int32_t numOfTb;
|
|
||||||
SMqTbData* tbData;
|
|
||||||
} SMqTopicData;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int8_t mqMsgType;
|
int8_t mqMsgType;
|
||||||
int32_t code;
|
int32_t code;
|
||||||
|
@ -2260,7 +2215,10 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char topic[TSDB_TOPIC_FNAME_LEN];
|
char topic[TSDB_TOPIC_FNAME_LEN];
|
||||||
|
int8_t isSchemaAdaptive;
|
||||||
SArray* vgs; // SArray<SMqSubVgEp>
|
SArray* vgs; // SArray<SMqSubVgEp>
|
||||||
|
int32_t numOfFields;
|
||||||
|
TAOS_FIELD* fields;
|
||||||
} SMqSubTopicEp;
|
} SMqSubTopicEp;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -2281,32 +2239,6 @@ typedef struct {
|
||||||
SArray* topics; // SArray<SMqSubTopicEp>
|
SArray* topics; // SArray<SMqSubTopicEp>
|
||||||
} SMqCMGetSubEpRsp;
|
} SMqCMGetSubEpRsp;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int32_t curBlock;
|
|
||||||
int32_t curRow;
|
|
||||||
void** uData;
|
|
||||||
} SMqRowIter;
|
|
||||||
|
|
||||||
struct tmq_message_t {
|
|
||||||
SMqPollRsp msg;
|
|
||||||
void* vg;
|
|
||||||
SMqRowIter iter;
|
|
||||||
};
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
struct tmq_message_t {
|
|
||||||
SMqRspHead head;
|
|
||||||
union {
|
|
||||||
SMqPollRsp consumeRsp;
|
|
||||||
SMqCMGetSubEpRsp getEpRsp;
|
|
||||||
};
|
|
||||||
void* extra;
|
|
||||||
int32_t curBlock;
|
|
||||||
int32_t curRow;
|
|
||||||
void** uData;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static FORCE_INLINE void tDeleteSMqSubTopicEp(SMqSubTopicEp* pSubTopicEp) { taosArrayDestroy(pSubTopicEp->vgs); }
|
static FORCE_INLINE void tDeleteSMqSubTopicEp(SMqSubTopicEp* pSubTopicEp) { taosArrayDestroy(pSubTopicEp->vgs); }
|
||||||
|
|
||||||
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
|
static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
|
||||||
|
@ -2331,17 +2263,21 @@ static FORCE_INLINE void tDeleteSMqCMGetSubEpRsp(SMqCMGetSubEpRsp* pRsp) {
|
||||||
static FORCE_INLINE int32_t tEncodeSMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp) {
|
static FORCE_INLINE int32_t tEncodeSMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp) {
|
||||||
int32_t tlen = 0;
|
int32_t tlen = 0;
|
||||||
tlen += taosEncodeString(buf, pTopicEp->topic);
|
tlen += taosEncodeString(buf, pTopicEp->topic);
|
||||||
|
tlen += taosEncodeFixedI8(buf, pTopicEp->isSchemaAdaptive);
|
||||||
int32_t sz = taosArrayGetSize(pTopicEp->vgs);
|
int32_t sz = taosArrayGetSize(pTopicEp->vgs);
|
||||||
tlen += taosEncodeFixedI32(buf, sz);
|
tlen += taosEncodeFixedI32(buf, sz);
|
||||||
for (int32_t i = 0; i < sz; i++) {
|
for (int32_t i = 0; i < sz; i++) {
|
||||||
SMqSubVgEp* pVgEp = (SMqSubVgEp*)taosArrayGet(pTopicEp->vgs, i);
|
SMqSubVgEp* pVgEp = (SMqSubVgEp*)taosArrayGet(pTopicEp->vgs, i);
|
||||||
tlen += tEncodeSMqSubVgEp(buf, pVgEp);
|
tlen += tEncodeSMqSubVgEp(buf, pVgEp);
|
||||||
}
|
}
|
||||||
|
tlen += taosEncodeFixedI32(buf, pTopicEp->numOfFields);
|
||||||
|
// tlen += taosEncodeBinary(buf, pTopicEp->fields, pTopicEp->numOfFields * sizeof(TAOS_FIELD));
|
||||||
return tlen;
|
return tlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void* tDecodeSMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp) {
|
static FORCE_INLINE void* tDecodeSMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp) {
|
||||||
buf = taosDecodeStringTo(buf, pTopicEp->topic);
|
buf = taosDecodeStringTo(buf, pTopicEp->topic);
|
||||||
|
buf = taosDecodeFixedI8(buf, &pTopicEp->isSchemaAdaptive);
|
||||||
int32_t sz;
|
int32_t sz;
|
||||||
buf = taosDecodeFixedI32(buf, &sz);
|
buf = taosDecodeFixedI32(buf, &sz);
|
||||||
pTopicEp->vgs = taosArrayInit(sz, sizeof(SMqSubVgEp));
|
pTopicEp->vgs = taosArrayInit(sz, sizeof(SMqSubVgEp));
|
||||||
|
@ -2353,6 +2289,8 @@ static FORCE_INLINE void* tDecodeSMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicE
|
||||||
buf = tDecodeSMqSubVgEp(buf, &vgEp);
|
buf = tDecodeSMqSubVgEp(buf, &vgEp);
|
||||||
taosArrayPush(pTopicEp->vgs, &vgEp);
|
taosArrayPush(pTopicEp->vgs, &vgEp);
|
||||||
}
|
}
|
||||||
|
buf = taosDecodeFixedI32(buf, &pTopicEp->numOfFields);
|
||||||
|
// buf = taosDecodeBinary(buf, (void**)&pTopicEp->fields, pTopicEp->numOfFields * sizeof(TAOS_FIELD));
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,13 +56,14 @@ typedef struct {
|
||||||
ReleaseHandleFp releaseHandleFp;
|
ReleaseHandleFp releaseHandleFp;
|
||||||
} SMsgCb;
|
} SMsgCb;
|
||||||
|
|
||||||
|
void tmsgSetDefaultMsgCb(const SMsgCb* pMsgCb);
|
||||||
int32_t tmsgPutToQueue(const SMsgCb* pMsgCb, EQueueType qtype, SRpcMsg* pReq);
|
int32_t tmsgPutToQueue(const SMsgCb* pMsgCb, EQueueType qtype, SRpcMsg* pReq);
|
||||||
int32_t tmsgGetQueueSize(const SMsgCb* pMsgCb, int32_t vgId, EQueueType qtype);
|
int32_t tmsgGetQueueSize(const SMsgCb* pMsgCb, int32_t vgId, EQueueType qtype);
|
||||||
int32_t tmsgSendReq(const SMsgCb* pMsgCb, const SEpSet* epSet, SRpcMsg* pReq);
|
int32_t tmsgSendReq(const SMsgCb* pMsgCb, const SEpSet* epSet, SRpcMsg* pReq);
|
||||||
int32_t tmsgSendMnodeReq(const SMsgCb* pMsgCb, SRpcMsg* pReq);
|
int32_t tmsgSendMnodeReq(const SMsgCb* pMsgCb, SRpcMsg* pReq);
|
||||||
void tmsgSendRsp(const SMsgCb* pMsgCb, const SRpcMsg* pRsp);
|
void tmsgSendRsp(const SRpcMsg* pRsp);
|
||||||
void tmsgRegisterBrokenLinkArg(const SMsgCb* pMsgCb, SRpcMsg* pMsg);
|
void tmsgRegisterBrokenLinkArg(const SMsgCb* pMsgCb, SRpcMsg* pMsg);
|
||||||
void tmsgReleaseHandle(const SMsgCb* pMsgCb, void* handle, int8_t type);
|
void tmsgReleaseHandle(void* handle, int8_t type);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -937,9 +937,8 @@ static FORCE_INLINE bool tdSTSRowIterNext(STSRowIter *pIter, col_id_t colId, col
|
||||||
STColumn *pCol = NULL;
|
STColumn *pCol = NULL;
|
||||||
STSchema *pSchema = pIter->pSchema;
|
STSchema *pSchema = pIter->pSchema;
|
||||||
while (pIter->colIdx <= pSchema->numOfCols) {
|
while (pIter->colIdx <= pSchema->numOfCols) {
|
||||||
pCol = &pSchema->columns[pIter->colIdx];
|
pCol = &pSchema->columns[pIter->colIdx]; // 1st column of schema is primary TS key
|
||||||
if (colId == pCol->colId) {
|
if (colId == pCol->colId) {
|
||||||
++pIter->colIdx;
|
|
||||||
break;
|
break;
|
||||||
} else if (colId < pCol->colId) {
|
} else if (colId < pCol->colId) {
|
||||||
++pIter->colIdx;
|
++pIter->colIdx;
|
||||||
|
@ -948,7 +947,8 @@ static FORCE_INLINE bool tdSTSRowIterNext(STSRowIter *pIter, col_id_t colId, col
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tdGetTpRowDataOfCol(pIter, pCol->type, pCol->offset - sizeof(TSKEY), pVal);
|
tdGetTpRowDataOfCol(pIter, pCol->type, pCol->offset - sizeof(TSKEY), pVal);
|
||||||
|
++pIter->colIdx;
|
||||||
} else if (TD_IS_KV_ROW(pIter->pRow)) {
|
} else if (TD_IS_KV_ROW(pIter->pRow)) {
|
||||||
return tdGetKvRowValOfColEx(pIter, colId, colType, &pIter->kvIdx, pVal);
|
return tdGetKvRowValOfColEx(pIter, colId, colType, &pIter->kvIdx, pVal);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -138,55 +138,59 @@
|
||||||
#define TK_INTERVAL 120
|
#define TK_INTERVAL 120
|
||||||
#define TK_TOPIC 121
|
#define TK_TOPIC 121
|
||||||
#define TK_AS 122
|
#define TK_AS 122
|
||||||
#define TK_NK_BOOL 123
|
#define TK_EXPLAIN 123
|
||||||
#define TK_NK_VARIABLE 124
|
#define TK_ANALYZE 124
|
||||||
#define TK_NK_UNDERLINE 125
|
#define TK_VERBOSE 125
|
||||||
#define TK_ROWTS 126
|
#define TK_NK_BOOL 126
|
||||||
#define TK_TBNAME 127
|
#define TK_RATIO 127
|
||||||
#define TK_QSTARTTS 128
|
#define TK_NULL 128
|
||||||
#define TK_QENDTS 129
|
#define TK_NK_VARIABLE 129
|
||||||
#define TK_WSTARTTS 130
|
#define TK_NK_UNDERLINE 130
|
||||||
#define TK_WENDTS 131
|
#define TK_ROWTS 131
|
||||||
#define TK_WDURATION 132
|
#define TK_TBNAME 132
|
||||||
#define TK_BETWEEN 133
|
#define TK_QSTARTTS 133
|
||||||
#define TK_IS 134
|
#define TK_QENDTS 134
|
||||||
#define TK_NULL 135
|
#define TK_WSTARTTS 135
|
||||||
#define TK_NK_LT 136
|
#define TK_WENDTS 136
|
||||||
#define TK_NK_GT 137
|
#define TK_WDURATION 137
|
||||||
#define TK_NK_LE 138
|
#define TK_BETWEEN 138
|
||||||
#define TK_NK_GE 139
|
#define TK_IS 139
|
||||||
#define TK_NK_NE 140
|
#define TK_NK_LT 140
|
||||||
#define TK_MATCH 141
|
#define TK_NK_GT 141
|
||||||
#define TK_NMATCH 142
|
#define TK_NK_LE 142
|
||||||
#define TK_IN 143
|
#define TK_NK_GE 143
|
||||||
#define TK_JOIN 144
|
#define TK_NK_NE 144
|
||||||
#define TK_INNER 145
|
#define TK_MATCH 145
|
||||||
#define TK_SELECT 146
|
#define TK_NMATCH 146
|
||||||
#define TK_DISTINCT 147
|
#define TK_IN 147
|
||||||
#define TK_WHERE 148
|
#define TK_JOIN 148
|
||||||
#define TK_PARTITION 149
|
#define TK_INNER 149
|
||||||
#define TK_BY 150
|
#define TK_SELECT 150
|
||||||
#define TK_SESSION 151
|
#define TK_DISTINCT 151
|
||||||
#define TK_STATE_WINDOW 152
|
#define TK_WHERE 152
|
||||||
#define TK_SLIDING 153
|
#define TK_PARTITION 153
|
||||||
#define TK_FILL 154
|
#define TK_BY 154
|
||||||
#define TK_VALUE 155
|
#define TK_SESSION 155
|
||||||
#define TK_NONE 156
|
#define TK_STATE_WINDOW 156
|
||||||
#define TK_PREV 157
|
#define TK_SLIDING 157
|
||||||
#define TK_LINEAR 158
|
#define TK_FILL 158
|
||||||
#define TK_NEXT 159
|
#define TK_VALUE 159
|
||||||
#define TK_GROUP 160
|
#define TK_NONE 160
|
||||||
#define TK_HAVING 161
|
#define TK_PREV 161
|
||||||
#define TK_ORDER 162
|
#define TK_LINEAR 162
|
||||||
#define TK_SLIMIT 163
|
#define TK_NEXT 163
|
||||||
#define TK_SOFFSET 164
|
#define TK_GROUP 164
|
||||||
#define TK_LIMIT 165
|
#define TK_HAVING 165
|
||||||
#define TK_OFFSET 166
|
#define TK_ORDER 166
|
||||||
#define TK_ASC 167
|
#define TK_SLIMIT 167
|
||||||
#define TK_DESC 168
|
#define TK_SOFFSET 168
|
||||||
#define TK_NULLS 169
|
#define TK_LIMIT 169
|
||||||
#define TK_FIRST 170
|
#define TK_OFFSET 170
|
||||||
#define TK_LAST 171
|
#define TK_ASC 171
|
||||||
|
#define TK_DESC 172
|
||||||
|
#define TK_NULLS 173
|
||||||
|
#define TK_FIRST 174
|
||||||
|
#define TK_LAST 175
|
||||||
|
|
||||||
#define TK_NK_SPACE 300
|
#define TK_NK_SPACE 300
|
||||||
#define TK_NK_COMMENT 301
|
#define TK_NK_COMMENT 301
|
||||||
|
|
|
@ -46,11 +46,12 @@ typedef struct {
|
||||||
char localFqdn[TSDB_FQDN_LEN];
|
char localFqdn[TSDB_FQDN_LEN];
|
||||||
char firstEp[TSDB_EP_LEN];
|
char firstEp[TSDB_EP_LEN];
|
||||||
char secondEp[TSDB_EP_LEN];
|
char secondEp[TSDB_EP_LEN];
|
||||||
SDiskCfg *pDisks;
|
SDiskCfg *disks;
|
||||||
int32_t numOfDisks;
|
int32_t numOfDisks;
|
||||||
|
int8_t ntype;
|
||||||
} SDnodeOpt;
|
} SDnodeOpt;
|
||||||
|
|
||||||
typedef enum { DND_EVENT_START, DND_EVENT_STOP = 1, DND_EVENT_RELOAD } EDndEvent;
|
typedef enum { DND_EVENT_START, DND_EVENT_STOP = 1, DND_EVENT_CHILD } EDndEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize and start the dnode.
|
* @brief Initialize and start the dnode.
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "tcommon.h"
|
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
|
#include "tcommon.h"
|
||||||
|
|
||||||
typedef void* qTaskInfo_t;
|
typedef void* qTaskInfo_t;
|
||||||
typedef void* DataSinkHandle;
|
typedef void* DataSinkHandle;
|
||||||
|
@ -37,6 +37,11 @@ typedef struct SReadHandle {
|
||||||
#define STREAM_DATA_TYPE_SUBMIT_BLOCK 0x1
|
#define STREAM_DATA_TYPE_SUBMIT_BLOCK 0x1
|
||||||
#define STREAM_DATA_TYPE_SSDATA_BLOCK 0x2
|
#define STREAM_DATA_TYPE_SSDATA_BLOCK 0x2
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
OPTR_EXEC_MODEL_BATCH = 0x1,
|
||||||
|
OPTR_EXEC_MODEL_STREAM = 0x2,
|
||||||
|
} EOPTR_EXEC_MODEL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the exec task for streaming mode
|
* Create the exec task for streaming mode
|
||||||
* @param pMsg
|
* @param pMsg
|
||||||
|
@ -62,7 +67,7 @@ int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input, int32_t type);
|
||||||
* @param type
|
* @param type
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, void** pBlocks, size_t numOfBlocks, int32_t type);
|
int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks, int32_t type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the table id list, add or remove.
|
* Update the table id list, add or remove.
|
||||||
|
@ -84,7 +89,7 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, SArray* tableIdList, bool isA
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, struct SSubplan* pPlan,
|
int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, struct SSubplan* pPlan,
|
||||||
qTaskInfo_t* pTaskInfo, DataSinkHandle* handle);
|
qTaskInfo_t* pTaskInfo, DataSinkHandle* handle, EOPTR_EXEC_MODEL model);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main task execution function, including query on both table and multiple tables,
|
* The main task execution function, including query on both table and multiple tables,
|
||||||
|
@ -167,7 +172,6 @@ int32_t qUpdateQueriedTableIdList(qTaskInfo_t tinfo, int64_t uid, int32_t type);
|
||||||
*/
|
*/
|
||||||
void** qReleaseTask(void* pMgmt, void* pQInfo, bool freeHandle);
|
void** qReleaseTask(void* pMgmt, void* pQInfo, bool freeHandle);
|
||||||
|
|
||||||
|
|
||||||
void qProcessFetchRsp(void* parent, struct SRpcMsg* pMsg, struct SEpSet* pEpSet);
|
void qProcessFetchRsp(void* parent, struct SRpcMsg* pMsg, struct SEpSet* pEpSet);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -41,6 +41,7 @@ typedef void (*FExecFinalize)(struct SqlFunctionCtx *pCtx);
|
||||||
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 {
|
||||||
|
FExecGetEnv getEnv;
|
||||||
FScalarExecProcess process;
|
FScalarExecProcess process;
|
||||||
} SScalarFuncExecFuncs;
|
} SScalarFuncExecFuncs;
|
||||||
|
|
||||||
|
@ -241,7 +242,6 @@ typedef struct tExprNode {
|
||||||
};
|
};
|
||||||
} tExprNode;
|
} tExprNode;
|
||||||
|
|
||||||
void exprTreeToBinary(SBufferWriter* bw, tExprNode* pExprTree);
|
|
||||||
void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *));
|
void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *));
|
||||||
|
|
||||||
typedef struct SAggFunctionInfo {
|
typedef struct SAggFunctionInfo {
|
||||||
|
@ -267,28 +267,6 @@ struct SScalarParam {
|
||||||
int32_t numOfRows;
|
int32_t numOfRows;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct SMultiFunctionsDesc {
|
|
||||||
bool stableQuery;
|
|
||||||
bool groupbyColumn;
|
|
||||||
bool agg;
|
|
||||||
bool arithmeticOnAgg;
|
|
||||||
bool projectionQuery;
|
|
||||||
bool hasFilter;
|
|
||||||
bool onlyTagQuery;
|
|
||||||
bool orderProjectQuery;
|
|
||||||
bool globalMerge;
|
|
||||||
bool multigroupResult;
|
|
||||||
bool blockDistribution;
|
|
||||||
bool stateWindow;
|
|
||||||
bool timewindow;
|
|
||||||
bool sessionWindow;
|
|
||||||
bool topbotQuery;
|
|
||||||
bool interpQuery;
|
|
||||||
bool distinct;
|
|
||||||
bool join;
|
|
||||||
bool continueQuery;
|
|
||||||
} SMultiFunctionsDesc;
|
|
||||||
|
|
||||||
int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, SResultDataInfo* pInfo, int16_t extLength,
|
int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, SResultDataInfo* pInfo, int16_t extLength,
|
||||||
bool isSuperTable);
|
bool isSuperTable);
|
||||||
|
|
||||||
|
@ -296,8 +274,6 @@ bool qIsValidUdf(SArray* pUdfInfo, const char* name, int32_t len, int32_t* funct
|
||||||
|
|
||||||
tExprNode* exprTreeFromBinary(const void* data, size_t size);
|
tExprNode* exprTreeFromBinary(const void* data, size_t size);
|
||||||
|
|
||||||
void extractFunctionDesc(SArray* pFunctionIdList, SMultiFunctionsDesc* pDesc);
|
|
||||||
|
|
||||||
tExprNode* exprdup(tExprNode* pTree);
|
tExprNode* exprdup(tExprNode* pTree);
|
||||||
|
|
||||||
void resetResultRowEntryResult(SqlFunctionCtx* pCtx, int32_t num);
|
void resetResultRowEntryResult(SqlFunctionCtx* pCtx, int32_t num);
|
||||||
|
|
|
@ -70,6 +70,7 @@ typedef enum ENodeType {
|
||||||
QUERY_NODE_DATABASE_OPTIONS,
|
QUERY_NODE_DATABASE_OPTIONS,
|
||||||
QUERY_NODE_TABLE_OPTIONS,
|
QUERY_NODE_TABLE_OPTIONS,
|
||||||
QUERY_NODE_INDEX_OPTIONS,
|
QUERY_NODE_INDEX_OPTIONS,
|
||||||
|
QUERY_NODE_EXPLAIN_OPTIONS,
|
||||||
|
|
||||||
// Statement nodes are used in parser and planner module.
|
// Statement nodes are used in parser and planner module.
|
||||||
QUERY_NODE_SET_OPERATOR,
|
QUERY_NODE_SET_OPERATOR,
|
||||||
|
@ -99,6 +100,7 @@ typedef enum ENodeType {
|
||||||
QUERY_NODE_CREATE_TOPIC_STMT,
|
QUERY_NODE_CREATE_TOPIC_STMT,
|
||||||
QUERY_NODE_DROP_TOPIC_STMT,
|
QUERY_NODE_DROP_TOPIC_STMT,
|
||||||
QUERY_NODE_ALTER_LOCAL_STMT,
|
QUERY_NODE_ALTER_LOCAL_STMT,
|
||||||
|
QUERY_NODE_EXPLAIN_STMT,
|
||||||
QUERY_NODE_SHOW_DATABASES_STMT,
|
QUERY_NODE_SHOW_DATABASES_STMT,
|
||||||
QUERY_NODE_SHOW_TABLES_STMT,
|
QUERY_NODE_SHOW_TABLES_STMT,
|
||||||
QUERY_NODE_SHOW_STABLES_STMT,
|
QUERY_NODE_SHOW_STABLES_STMT,
|
||||||
|
@ -121,6 +123,7 @@ typedef enum ENodeType {
|
||||||
QUERY_NODE_LOGIC_PLAN_EXCHANGE,
|
QUERY_NODE_LOGIC_PLAN_EXCHANGE,
|
||||||
QUERY_NODE_LOGIC_PLAN_WINDOW,
|
QUERY_NODE_LOGIC_PLAN_WINDOW,
|
||||||
QUERY_NODE_LOGIC_PLAN_SORT,
|
QUERY_NODE_LOGIC_PLAN_SORT,
|
||||||
|
QUERY_NODE_LOGIC_PLAN_PARTITION,
|
||||||
QUERY_NODE_LOGIC_SUBPLAN,
|
QUERY_NODE_LOGIC_SUBPLAN,
|
||||||
QUERY_NODE_LOGIC_PLAN,
|
QUERY_NODE_LOGIC_PLAN,
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ typedef struct SScanLogicNode {
|
||||||
STimeWindow scanRange;
|
STimeWindow scanRange;
|
||||||
SName tableName;
|
SName tableName;
|
||||||
bool showRewrite;
|
bool showRewrite;
|
||||||
|
double ratio;
|
||||||
} SScanLogicNode;
|
} SScanLogicNode;
|
||||||
|
|
||||||
typedef struct SJoinLogicNode {
|
typedef struct SJoinLogicNode {
|
||||||
|
@ -67,6 +68,10 @@ typedef struct SProjectLogicNode {
|
||||||
SLogicNode node;
|
SLogicNode node;
|
||||||
SNodeList* pProjections;
|
SNodeList* pProjections;
|
||||||
char stmtName[TSDB_TABLE_NAME_LEN];
|
char stmtName[TSDB_TABLE_NAME_LEN];
|
||||||
|
int64_t limit;
|
||||||
|
int64_t offset;
|
||||||
|
int64_t slimit;
|
||||||
|
int64_t soffset;
|
||||||
} SProjectLogicNode;
|
} SProjectLogicNode;
|
||||||
|
|
||||||
typedef struct SVnodeModifLogicNode {
|
typedef struct SVnodeModifLogicNode {
|
||||||
|
@ -106,6 +111,11 @@ typedef struct SSortLogicNode {
|
||||||
SNodeList* pSortKeys;
|
SNodeList* pSortKeys;
|
||||||
} SSortLogicNode;
|
} SSortLogicNode;
|
||||||
|
|
||||||
|
typedef struct SPartitionLogicNode {
|
||||||
|
SLogicNode node;
|
||||||
|
SNodeList* pPartitionKeys;
|
||||||
|
} SPartitionLogicNode;
|
||||||
|
|
||||||
typedef enum ESubplanType {
|
typedef enum ESubplanType {
|
||||||
SUBPLAN_TYPE_MERGE = 1,
|
SUBPLAN_TYPE_MERGE = 1,
|
||||||
SUBPLAN_TYPE_PARTIAL,
|
SUBPLAN_TYPE_PARTIAL,
|
||||||
|
@ -150,7 +160,8 @@ typedef struct SDataBlockDescNode {
|
||||||
ENodeType type;
|
ENodeType type;
|
||||||
int16_t dataBlockId;
|
int16_t dataBlockId;
|
||||||
SNodeList* pSlots;
|
SNodeList* pSlots;
|
||||||
int32_t resultRowSize;
|
int32_t totalRowSize;
|
||||||
|
int32_t outputRowSize;
|
||||||
int16_t precision;
|
int16_t precision;
|
||||||
} SDataBlockDescNode;
|
} SDataBlockDescNode;
|
||||||
|
|
||||||
|
@ -187,7 +198,7 @@ typedef struct STableScanPhysiNode {
|
||||||
SScanPhysiNode scan;
|
SScanPhysiNode scan;
|
||||||
uint8_t scanFlag; // denotes reversed scan of data or not
|
uint8_t scanFlag; // denotes reversed scan of data or not
|
||||||
STimeWindow scanRange;
|
STimeWindow scanRange;
|
||||||
SNode* pScanConditions;
|
double ratio;
|
||||||
} STableScanPhysiNode;
|
} STableScanPhysiNode;
|
||||||
|
|
||||||
typedef STableScanPhysiNode STableSeqScanPhysiNode;
|
typedef STableScanPhysiNode STableSeqScanPhysiNode;
|
||||||
|
@ -195,6 +206,10 @@ typedef STableScanPhysiNode STableSeqScanPhysiNode;
|
||||||
typedef struct SProjectPhysiNode {
|
typedef struct SProjectPhysiNode {
|
||||||
SPhysiNode node;
|
SPhysiNode node;
|
||||||
SNodeList* pProjections;
|
SNodeList* pProjections;
|
||||||
|
int64_t limit;
|
||||||
|
int64_t offset;
|
||||||
|
int64_t slimit;
|
||||||
|
int64_t soffset;
|
||||||
} SProjectPhysiNode;
|
} SProjectPhysiNode;
|
||||||
|
|
||||||
typedef struct SJoinPhysiNode {
|
typedef struct SJoinPhysiNode {
|
||||||
|
@ -238,6 +253,7 @@ typedef struct SIntervalPhysiNode {
|
||||||
int64_t sliding;
|
int64_t sliding;
|
||||||
int8_t intervalUnit;
|
int8_t intervalUnit;
|
||||||
int8_t slidingUnit;
|
int8_t slidingUnit;
|
||||||
|
uint8_t precision;
|
||||||
SFillNode* pFill;
|
SFillNode* pFill;
|
||||||
} SIntervalPhysiNode;
|
} SIntervalPhysiNode;
|
||||||
|
|
||||||
|
@ -283,11 +299,23 @@ typedef struct SSubplan {
|
||||||
SDataSinkNode* pDataSink; // data of the subplan flow into the datasink
|
SDataSinkNode* pDataSink; // data of the subplan flow into the datasink
|
||||||
} SSubplan;
|
} SSubplan;
|
||||||
|
|
||||||
|
typedef enum EExplainMode {
|
||||||
|
EXPLAIN_MODE_DISABLE = 1,
|
||||||
|
EXPLAIN_MODE_STATIC,
|
||||||
|
EXPLAIN_MODE_ANALYZE
|
||||||
|
} EExplainMode;
|
||||||
|
|
||||||
|
typedef struct SExplainInfo {
|
||||||
|
EExplainMode mode;
|
||||||
|
bool verbose;
|
||||||
|
} SExplainInfo;
|
||||||
|
|
||||||
typedef struct SQueryPlan {
|
typedef struct SQueryPlan {
|
||||||
ENodeType type;
|
ENodeType type;
|
||||||
uint64_t queryId;
|
uint64_t queryId;
|
||||||
int32_t numOfSubplans;
|
int32_t numOfSubplans;
|
||||||
SNodeList* pSubplans; // Element is SNodeListNode. The execution level of subplan, starting from 0.
|
SNodeList* pSubplans; // Element is SNodeListNode. The execution level of subplan, starting from 0.
|
||||||
|
SExplainInfo explainInfo;
|
||||||
} SQueryPlan;
|
} SQueryPlan;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -131,6 +131,7 @@ typedef struct SRealTableNode {
|
||||||
struct STableMeta* pMeta;
|
struct STableMeta* pMeta;
|
||||||
SVgroupsInfo* pVgroupList;
|
SVgroupsInfo* pVgroupList;
|
||||||
char useDbName[TSDB_DB_NAME_LEN];
|
char useDbName[TSDB_DB_NAME_LEN];
|
||||||
|
double ratio;
|
||||||
} SRealTableNode;
|
} SRealTableNode;
|
||||||
|
|
||||||
typedef struct STempTableNode {
|
typedef struct STempTableNode {
|
||||||
|
@ -180,8 +181,8 @@ typedef struct SOrderByExprNode {
|
||||||
|
|
||||||
typedef struct SLimitNode {
|
typedef struct SLimitNode {
|
||||||
ENodeType type; // QUERY_NODE_LIMIT
|
ENodeType type; // QUERY_NODE_LIMIT
|
||||||
uint64_t limit;
|
int64_t limit;
|
||||||
uint64_t offset;
|
int64_t offset;
|
||||||
} SLimitNode;
|
} SLimitNode;
|
||||||
|
|
||||||
typedef struct SStateWindowNode {
|
typedef struct SStateWindowNode {
|
||||||
|
@ -282,6 +283,19 @@ typedef struct SVnodeModifOpStmt {
|
||||||
const char* sql; // current sql statement position
|
const char* sql; // current sql statement position
|
||||||
} SVnodeModifOpStmt;
|
} SVnodeModifOpStmt;
|
||||||
|
|
||||||
|
typedef struct SExplainOptions {
|
||||||
|
ENodeType type;
|
||||||
|
bool verbose;
|
||||||
|
double ratio;
|
||||||
|
} SExplainOptions;
|
||||||
|
|
||||||
|
typedef struct SExplainStmt {
|
||||||
|
ENodeType type;
|
||||||
|
bool analyze;
|
||||||
|
SExplainOptions* pOptions;
|
||||||
|
SNode* pQuery;
|
||||||
|
} SExplainStmt;
|
||||||
|
|
||||||
void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker walker, void* pContext);
|
void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker walker, void* pContext);
|
||||||
void nodesRewriteSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeRewriter rewriter, void* pContext);
|
void nodesRewriteSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeRewriter rewriter, void* pContext);
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,14 @@ int32_t ceilFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
|
||||||
int32_t floorFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
int32_t floorFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||||
int32_t roundFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
int32_t roundFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||||
|
|
||||||
|
bool getTimePseudoFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||||
|
|
||||||
|
int32_t winStartTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||||
|
int32_t winEndTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||||
|
int32_t winDurFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||||
|
int32_t qStartTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||||
|
int32_t qEndTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -42,6 +42,9 @@ extern "C" {
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <sys/statvfs.h>
|
#include <sys/statvfs.h>
|
||||||
|
#include <sys/prctl.h>
|
||||||
|
#include <sys/shm.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
|
||||||
#if defined(DARWIN)
|
#if defined(DARWIN)
|
||||||
#else
|
#else
|
||||||
|
@ -70,7 +73,6 @@ extern "C" {
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <wctype.h>
|
#include <wctype.h>
|
||||||
|
|
||||||
|
|
||||||
#include "osAtomic.h"
|
#include "osAtomic.h"
|
||||||
#include "osDef.h"
|
#include "osDef.h"
|
||||||
#include "osDir.h"
|
#include "osDir.h"
|
||||||
|
@ -80,10 +82,12 @@ extern "C" {
|
||||||
#include "osLz4.h"
|
#include "osLz4.h"
|
||||||
#include "osMath.h"
|
#include "osMath.h"
|
||||||
#include "osMemory.h"
|
#include "osMemory.h"
|
||||||
|
#include "osProc.h"
|
||||||
#include "osRand.h"
|
#include "osRand.h"
|
||||||
#include "osThread.h"
|
#include "osThread.h"
|
||||||
#include "osSemaphore.h"
|
#include "osSemaphore.h"
|
||||||
#include "osSignal.h"
|
#include "osSignal.h"
|
||||||
|
#include "osShm.h"
|
||||||
#include "osSleep.h"
|
#include "osSleep.h"
|
||||||
#include "osSocket.h"
|
#include "osSocket.h"
|
||||||
#include "osString.h"
|
#include "osString.h"
|
||||||
|
|
|
@ -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_OS_PROC_H_
|
||||||
|
#define _TD_OS_PROC_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// start a copy of itself
|
||||||
|
int32_t taosNewProc(const char *args);
|
||||||
|
|
||||||
|
// the length of the new name must be less than the original name to take effect
|
||||||
|
void taosSetProcName(char **argv, const char *name);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*_TD_OS_PROC_H_*/
|
|
@ -13,4 +13,25 @@
|
||||||
* 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 "consumer.h"
|
#ifndef _TD_OS_SHM_H_
|
||||||
|
#define _TD_OS_SHM_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int32_t id;
|
||||||
|
int32_t size;
|
||||||
|
void* ptr;
|
||||||
|
} SShm;
|
||||||
|
|
||||||
|
int32_t taosCreateShm(SShm *pShm, int32_t shmsize) ;
|
||||||
|
void taosDropShm(SShm *pShm);
|
||||||
|
int32_t taosAttachShm(SShm *pShm);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*_TD_OS_SHM_H_*/
|
|
@ -49,6 +49,8 @@ void taosSetSignal(int32_t signum, FSignalHandler sigfp);
|
||||||
void taosIgnSignal(int32_t signum);
|
void taosIgnSignal(int32_t signum);
|
||||||
void taosDflSignal(int32_t signum);
|
void taosDflSignal(int32_t signum);
|
||||||
|
|
||||||
|
void taosKillChildOnSelfStopped();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -32,6 +32,9 @@ typedef pthread_once_t TdThreadOnce;
|
||||||
typedef pthread_rwlockattr_t TdThreadRwlockAttr;
|
typedef pthread_rwlockattr_t TdThreadRwlockAttr;
|
||||||
typedef pthread_cond_t TdThreadCond;
|
typedef pthread_cond_t TdThreadCond;
|
||||||
typedef pthread_condattr_t TdThreadCondAttr;
|
typedef pthread_condattr_t TdThreadCondAttr;
|
||||||
|
typedef pthread_key_t TdThreadKey;
|
||||||
|
typedef pthread_barrier_t TdThreadBarrier;
|
||||||
|
typedef pthread_barrierattr_t TdThreadBarrierAttr;
|
||||||
|
|
||||||
#define taosThreadCleanupPush pthread_cleanup_push
|
#define taosThreadCleanupPush pthread_cleanup_push
|
||||||
#define taosThreadCleanupPop pthread_cleanup_pop
|
#define taosThreadCleanupPop pthread_cleanup_pop
|
||||||
|
@ -39,78 +42,190 @@ typedef pthread_condattr_t TdThreadCondAttr;
|
||||||
// If the error is in a third-party library, place this header file under the third-party library header file.
|
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||||
// When you want to use this feature, you should find or add the same function in the following section.
|
// When you want to use this feature, you should find or add the same function in the following section.
|
||||||
#ifndef ALLOW_FORBID_FUNC
|
#ifndef ALLOW_FORBID_FUNC
|
||||||
#define pthread_t PTHREAD_T_TYPE_TAOS_FORBID
|
// #define pthread_t PTHREAD_T_TYPE_TAOS_FORBID
|
||||||
#define pthread_spinlock_t PTHREAD_SPINLOCK_T_TYPE_TAOS_FORBID
|
// #define pthread_spinlock_t PTHREAD_SPINLOCK_T_TYPE_TAOS_FORBID
|
||||||
#define pthread_mutex_t PTHREAD_MUTEX_T_TYPE_TAOS_FORBID
|
// #define pthread_mutex_t PTHREAD_MUTEX_T_TYPE_TAOS_FORBID
|
||||||
#define pthread_mutexattr_t PTHREAD_MUTEXATTR_T_TYPE_TAOS_FORBID
|
// #define pthread_mutexattr_t PTHREAD_MUTEXATTR_T_TYPE_TAOS_FORBID
|
||||||
#define pthread_rwlock_t PTHREAD_RWLOCK_T_TYPE_TAOS_FORBID
|
// #define pthread_rwlock_t PTHREAD_RWLOCK_T_TYPE_TAOS_FORBID
|
||||||
#define pthread_attr_t PTHREAD_ATTR_T_TYPE_TAOS_FORBID
|
// #define pthread_attr_t PTHREAD_ATTR_T_TYPE_TAOS_FORBID
|
||||||
#define pthread_once_t PTHREAD_ONCE_T_TYPE_TAOS_FORBID
|
// #define pthread_once_t PTHREAD_ONCE_T_TYPE_TAOS_FORBID
|
||||||
#define pthread_rwlockattr_t PTHREAD_RWLOCKATTR_T_TYPE_TAOS_FORBID
|
// #define pthread_rwlockattr_t PTHREAD_RWLOCKATTR_T_TYPE_TAOS_FORBID
|
||||||
#define pthread_cond_t PTHREAD_COND_T_TYPE_TAOS_FORBID
|
// #define pthread_cond_t PTHREAD_COND_T_TYPE_TAOS_FORBID
|
||||||
#define pthread_condattr_t PTHREAD_CONDATTR_T_TYPE_TAOS_FORBID
|
// #define pthread_condattr_t PTHREAD_CONDATTR_T_TYPE_TAOS_FORBID
|
||||||
#define pthread_spin_init PTHREAD_SPIN_INIT_FUNC_TAOS_FORBID
|
// #define pthread_key_t PTHREAD_KEY_T_TYPE_TAOS_FORBID
|
||||||
#define pthread_mutex_init PTHREAD_MUTEX_INIT_FUNC_TAOS_FORBID
|
// #define pthread_barrier_t PTHREAD_BARRIER_T_TYPE_TAOS_FORBID
|
||||||
#define pthread_spin_destroy PTHREAD_SPIN_DESTROY_FUNC_TAOS_FORBID
|
// #define pthread_barrierattr_t PTHREAD_BARRIERATTR_T_TYPE_TAOS_FORBID
|
||||||
#define pthread_mutex_destroy PTHREAD_MUTEX_DESTROY_FUNC_TAOS_FORBID
|
// #define pthread_create PTHREAD_CREATE_FUNC_TAOS_FORBID
|
||||||
#define pthread_spin_lock PTHREAD_SPIN_LOCK_FUNC_TAOS_FORBID
|
// #define pthread_attr_destroy PTHREAD_ATTR_DESTROY_FUNC_TAOS_FORBID
|
||||||
#define pthread_mutex_lock PTHREAD_MUTEX_LOCK_FUNC_TAOS_FORBID
|
// #define pthread_attr_getdetachstate PTHREAD_ATTR_GETDETACHSTATE_FUNC_TAOS_FORBID
|
||||||
#define pthread_spin_unlock PTHREAD_SPIN_UNLOCK_FUNC_TAOS_FORBID
|
// #define pthread_attr_getinheritsched PTHREAD_ATTR_GETINHERITSCHED_FUNC_TAOS_FORBID
|
||||||
#define pthread_mutex_unlock PTHREAD_MUTEX_UNLOCK_FUNC_TAOS_FORBID
|
// #define pthread_attr_getschedparam PTHREAD_ATTR_GETSCHEDPARAM_FUNC_TAOS_FORBID
|
||||||
#define pthread_rwlock_rdlock PTHREAD_RWLOCK_RDLOCK_FUNC_TAOS_FORBID
|
// #define pthread_attr_getschedpolicy PTHREAD_ATTR_GETSCHEDPOLICY_FUNC_TAOS_FORBID
|
||||||
#define pthread_rwlock_wrlock PTHREAD_RWLOCK_WRLOCK_FUNC_TAOS_FORBID
|
// #define pthread_attr_getscope PTHREAD_ATTR_GETSCOPE_FUNC_TAOS_FORBID
|
||||||
#define pthread_rwlock_unlock PTHREAD_RWLOCK_UNLOCK_FUNC_TAOS_FORBID
|
// #define pthread_attr_getstacksize PTHREAD_ATTR_GETSTACKSIZE_FUNC_TAOS_FORBID
|
||||||
#define pthread_testcancel PTHREAD_TESTCANCEL_FUNC_TAOS_FORBID
|
// #define pthread_attr_init PTHREAD_ATTR_INIT_FUNC_TAOS_FORBID
|
||||||
#define pthread_attr_init PTHREAD_ATTR_INIT_FUNC_TAOS_FORBID
|
// #define pthread_attr_setdetachstate PTHREAD_ATTR_SETDETACHSTATE_FUNC_TAOS_FORBID
|
||||||
#define pthread_create PTHREAD_CREATE_FUNC_TAOS_FORBID
|
// #define pthread_attr_setinheritsched PTHREAD_ATTR_SETINHERITSCHED_FUNC_TAOS_FORBID
|
||||||
#define pthread_once PTHREAD_ONCE_FUNC_TAOS_FORBID
|
// #define pthread_attr_setschedparam PTHREAD_ATTR_SETSCHEDPARAM_FUNC_TAOS_FORBID
|
||||||
#define pthread_attr_setdetachstate PTHREAD_ATTR_SETDETACHSTATE_FUNC_TAOS_FORBID
|
// #define pthread_attr_setschedpolicy PTHREAD_ATTR_SETSCHEDPOLICY_FUNC_TAOS_FORBID
|
||||||
#define pthread_attr_destroy PTHREAD_ATTR_DESTROY_FUNC_TAOS_FORBID
|
// #define pthread_attr_setscope PTHREAD_ATTR_SETSCOPE_FUNC_TAOS_FORBID
|
||||||
#define pthread_join PTHREAD_JOIN_FUNC_TAOS_FORBID
|
// #define pthread_attr_setstacksize PTHREAD_ATTR_SETSTACKSIZE_FUNC_TAOS_FORBID
|
||||||
#define pthread_rwlock_init PTHREAD_RWLOCK_INIT_FUNC_TAOS_FORBID
|
// #define pthread_barrier_destroy PTHREAD_BARRIER_DESTROY_FUNC_TAOS_FORBID
|
||||||
#define pthread_rwlock_destroy PTHREAD_RWLOCK_DESTROY_FUNC_TAOS_FORBID
|
// #define pthread_barrier_init PTHREAD_BARRIER_INIT_FUNC_TAOS_FORBID
|
||||||
#define pthread_cond_signal PTHREAD_COND_SIGNAL_FUNC_TAOS_FORBID
|
// #define pthread_barrier_wait PTHREAD_BARRIER_WAIT_FUNC_TAOS_FORBID
|
||||||
#define pthread_cond_init PTHREAD_COND_INIT_FUNC_TAOS_FORBID
|
// #define pthread_barrierattr_destroy PTHREAD_BARRIERATTR_DESTROY_FUNC_TAOS_FORBID
|
||||||
#define pthread_cond_broadcast PTHREAD_COND_BROADCAST_FUNC_TAOS_FORBID
|
// #define pthread_barrierattr_getpshared PTHREAD_BARRIERATTR_GETPSHARED_FUNC_TAOS_FORBID
|
||||||
#define pthread_cond_destroy PTHREAD_COND_DESTROY_FUNC_TAOS_FORBID
|
// #define pthread_barrierattr_init PTHREAD_BARRIERATTR_INIT_FUNC_TAOS_FORBID
|
||||||
#define pthread_cond_wait PTHREAD_COND_WAIT_FUNC_TAOS_FORBID
|
// #define pthread_barrierattr_setpshared PTHREAD_BARRIERATTR_SETPSHARED_FUNC_TAOS_FORBID
|
||||||
#define pthread_self PTHREAD_SELF_FUNC_TAOS_FORBID
|
// #define pthread_cancel PTHREAD_CANCEL_FUNC_TAOS_FORBID
|
||||||
#define pthread_equal PTHREAD_EQUAL_FUNC_TAOS_FORBID
|
// #define pthread_cond_destroy PTHREAD_COND_DESTROY_FUNC_TAOS_FORBID
|
||||||
#define pthread_sigmask PTHREAD_SIGMASK_FUNC_TAOS_FORBID
|
// #define pthread_cond_init PTHREAD_COND_INIT_FUNC_TAOS_FORBID
|
||||||
#define pthread_cancel PTHREAD_CANCEL_FUNC_TAOS_FORBID
|
// #define pthread_cond_signal PTHREAD_COND_SIGNAL_FUNC_TAOS_FORBID
|
||||||
#define pthread_kill PTHREAD_KILL_FUNC_TAOS_FORBID
|
// #define pthread_cond_broadcast PTHREAD_COND_BROADCAST_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_cond_wait PTHREAD_COND_WAIT_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_cond_timedwait PTHREAD_COND_TIMEDWAIT_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_condattr_destroy PTHREAD_CONDATTR_DESTROY_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_condattr_getpshared PTHREAD_CONDATTR_GETPSHARED_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_condattr_init PTHREAD_CONDATTR_INIT_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_condattr_setpshared PTHREAD_CONDATTR_SETPSHARED_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_detach PTHREAD_DETACH_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_equal PTHREAD_EQUAL_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_exit PTHREAD_EXIT_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_getschedparam PTHREAD_GETSCHEDPARAM_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_getspecific PTHREAD_GETSPECIFIC_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_join PTHREAD_JOIN_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_key_create PTHREAD_KEY_CREATE_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_key_delete PTHREAD_KEY_DELETE_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_kill PTHREAD_KILL_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_mutex_consistent PTHREAD_MUTEX_CONSISTENT_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_mutex_destroy PTHREAD_MUTEX_DESTROY_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_mutex_init PTHREAD_MUTEX_INIT_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_mutex_lock PTHREAD_MUTEX_LOCK_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_mutex_timedlock PTHREAD_MUTEX_TIMEDLOCK_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_mutex_trylock PTHREAD_MUTEX_TRYLOCK_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_mutex_unlock PTHREAD_MUTEX_UNLOCK_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_mutexattr_destroy PTHREAD_MUTEXATTR_DESTROY_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_mutexattr_getpshared PTHREAD_MUTEXATTR_GETPSHARED_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_mutexattr_getrobust PTHREAD_MUTEXATTR_GETROBUST_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_mutexattr_gettype PTHREAD_MUTEXATTR_GETTYPE_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_mutexattr_init PTHREAD_MUTEXATTR_INIT_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_mutexattr_setpshared PTHREAD_MUTEXATTR_SETPSHARED_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_mutexattr_setrobust PTHREAD_MUTEXATTR_SETROBUST_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_mutexattr_settype PTHREAD_MUTEXATTR_SETTYPE_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_once PTHREAD_ONCE_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_rwlock_destroy PTHREAD_RWLOCK_DESTROY_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_rwlock_init PTHREAD_RWLOCK_INIT_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_rwlock_rdlock PTHREAD_RWLOCK_RDLOCK_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_rwlock_timedrdlock PTHREAD_RWLOCK_TIMEDRDLOCK_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_rwlock_timedwrlock PTHREAD_RWLOCK_TIMEDWRLOCK_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_rwlock_tryrdlock PTHREAD_RWLOCK_TRYRDLOCK_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_rwlock_trywrlock PTHREAD_RWLOCK_TRYWRLOCK_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_rwlock_unlock PTHREAD_RWLOCK_UNLOCK_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_rwlock_wrlock PTHREAD_RWLOCK_WRLOCK_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_rwlockattr_destroy PTHREAD_RWLOCKATTR_DESTROY_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_rwlockattr_getpshared PTHREAD_RWLOCKATTR_GETPSHARED_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_rwlockattr_init PTHREAD_RWLOCKATTR_INIT_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_rwlockattr_setpshared PTHREAD_RWLOCKATTR_SETPSHARED_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_self PTHREAD_SELF_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_setcancelstate PTHREAD_SETCANCELSTATE_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_setcanceltype PTHREAD_SETCANCELTYPE_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_setschedparam PTHREAD_SETSCHEDPARAM_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_setspecific PTHREAD_SETSPECIFIC_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_spin_destroy PTHREAD_SPIN_DESTROY_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_spin_init PTHREAD_SPIN_INIT_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_spin_lock PTHREAD_SPIN_LOCK_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_spin_trylock PTHREAD_SPIN_TRYLOCK_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_spin_unlock PTHREAD_SPIN_UNLOCK_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_testcancel PTHREAD_TESTCANCEL_FUNC_TAOS_FORBID
|
||||||
|
// #define pthread_sigmask PTHREAD_SIGMASK_FUNC_TAOS_FORBID
|
||||||
|
// #define sigwait SIGWAIT_FUNC_TAOS_FORBID
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int32_t taosThreadSpinInit(TdThreadSpinlock *lock, int pshared);
|
|
||||||
int32_t taosThreadMutexInit(TdThreadMutex *mutex, const TdThreadMutexAttr *attr);
|
|
||||||
int32_t taosThreadSpinDestroy(TdThreadSpinlock *lock);
|
|
||||||
int32_t taosThreadMutexDestroy(TdThreadMutex * mutex);
|
|
||||||
int32_t taosThreadSpinLock(TdThreadSpinlock *lock);
|
|
||||||
int32_t taosThreadMutexLock(TdThreadMutex *mutex);
|
|
||||||
int32_t taosThreadRwlockRdlock(TdThreadRwlock *rwlock);
|
|
||||||
int32_t taosThreadSpinUnlock(TdThreadSpinlock *lock);
|
|
||||||
int32_t taosThreadMutexUnlock(TdThreadMutex *mutex);
|
|
||||||
int32_t taosThreadRwlockWrlock(TdThreadRwlock *rwlock);
|
|
||||||
int32_t taosThreadRwlockUnlock(TdThreadRwlock *rwlock);
|
|
||||||
void taosThreadTestCancel(void);
|
|
||||||
int32_t taosThreadAttrInit(TdThreadAttr *attr);
|
|
||||||
int32_t taosThreadCreate(TdThread * tid, const TdThreadAttr * attr, void *(*start)(void *), void *arg);
|
int32_t taosThreadCreate(TdThread * tid, const TdThreadAttr * attr, void *(*start)(void *), void *arg);
|
||||||
int32_t taosThreadOnce(TdThreadOnce *onceControl, void(*initRoutine)(void));
|
|
||||||
int32_t taosThreadAttrSetDetachState(TdThreadAttr *attr, int32_t detachState);
|
|
||||||
int32_t taosThreadAttrDestroy(TdThreadAttr * attr);
|
int32_t taosThreadAttrDestroy(TdThreadAttr * attr);
|
||||||
int32_t taosThreadJoin(TdThread thread, void **pValue);
|
int32_t taosThreadAttrGetDetachState(const TdThreadAttr * attr, int32_t *detachstate);
|
||||||
int32_t taosThreadRwlockInit(TdThreadRwlock *rwlock, const TdThreadRwlockAttr *attr);
|
int32_t taosThreadAttrGetInheritSched(const TdThreadAttr * attr, int32_t *inheritsched);
|
||||||
int32_t taosThreadRwlockDestroy(TdThreadRwlock *rwlock);
|
int32_t taosThreadAttrGetSchedParam(const TdThreadAttr * attr, struct sched_param *param);
|
||||||
int32_t taosThreadCondSignal(TdThreadCond *cond);
|
int32_t taosThreadAttrGetSchedPolicy(const TdThreadAttr * attr, int32_t *policy);
|
||||||
int32_t taosThreadCondInit(TdThreadCond *cond, const TdThreadCondAttr *attr);
|
int32_t taosThreadAttrGetScope(const TdThreadAttr * attr, int32_t *contentionscope);
|
||||||
int32_t taosThreadCondBroadcast(TdThreadCond *cond);
|
int32_t taosThreadAttrGetStackSize(const TdThreadAttr * attr, size_t * stacksize);
|
||||||
int32_t taosThreadCondDestroy(TdThreadCond *cond);
|
int32_t taosThreadAttrInit(TdThreadAttr * attr);
|
||||||
int32_t taosThreadCondWait(TdThreadCond *cond, TdThreadMutex *mutex);
|
int32_t taosThreadAttrSetDetachState(TdThreadAttr * attr, int32_t detachstate);
|
||||||
TdThread taosThreadSelf(void);
|
int32_t taosThreadAttrSetInheritSched(TdThreadAttr * attr, int32_t inheritsched);
|
||||||
int32_t taosThreadEqual(TdThread t1, TdThread t2);
|
int32_t taosThreadAttrSetSchedParam(TdThreadAttr * attr, const struct sched_param *param);
|
||||||
int32_t taosThreadSigmask(int how, sigset_t const *set, sigset_t *oset);
|
int32_t taosThreadAttrSetSchedPolicy(TdThreadAttr * attr, int32_t policy);
|
||||||
|
int32_t taosThreadAttrSetScope(TdThreadAttr * attr, int32_t contentionscope);
|
||||||
|
int32_t taosThreadAttrSetStackSize(TdThreadAttr * attr, size_t stacksize);
|
||||||
|
int32_t taosThreadBarrierDestroy(TdThreadBarrier * barrier);
|
||||||
|
int32_t taosThreadBarrierInit(TdThreadBarrier * barrier, const TdThreadBarrierAttr * attr, uint32_t count);
|
||||||
|
int32_t taosThreadBarrierWait(TdThreadBarrier * barrier);
|
||||||
|
int32_t taosThreadBarrierAttrDestroy(TdThreadBarrierAttr * attr);
|
||||||
|
int32_t taosThreadBarrierAttrGetPshared(const TdThreadBarrierAttr * attr, int32_t *pshared);
|
||||||
|
int32_t taosThreadBarrierAttrInit(TdThreadBarrierAttr * attr);
|
||||||
|
int32_t taosThreadBarrierAttrSetPshared(TdThreadBarrierAttr * attr, int32_t pshared);
|
||||||
int32_t taosThreadCancel(TdThread thread);
|
int32_t taosThreadCancel(TdThread thread);
|
||||||
int32_t taosThreadKill(TdThread thread, int sig);
|
int32_t taosThreadCondDestroy(TdThreadCond * cond);
|
||||||
|
int32_t taosThreadCondInit(TdThreadCond * cond, const TdThreadCondAttr * attr);
|
||||||
|
int32_t taosThreadCondSignal(TdThreadCond * cond);
|
||||||
|
int32_t taosThreadCondBroadcast(TdThreadCond * cond);
|
||||||
|
int32_t taosThreadCondWait(TdThreadCond * cond, TdThreadMutex * mutex);
|
||||||
|
int32_t taosThreadCondTimedWait(TdThreadCond * cond, TdThreadMutex * mutex, const struct timespec *abstime);
|
||||||
|
int32_t taosThreadCondAttrDestroy(TdThreadCondAttr * attr);
|
||||||
|
int32_t taosThreadCondAttrGetPshared(const TdThreadCondAttr * attr, int32_t *pshared);
|
||||||
|
int32_t taosThreadCondAttrInit(TdThreadCondAttr * attr);
|
||||||
|
int32_t taosThreadCondAttrSetPshared(TdThreadCondAttr * attr, int32_t pshared);
|
||||||
|
int32_t taosThreadDetach(TdThread thread);
|
||||||
|
int32_t taosThreadEqual(TdThread t1, TdThread t2);
|
||||||
|
void taosThreadExit(void *valuePtr);
|
||||||
|
int32_t taosThreadGetSchedParam(TdThread thread, int32_t *policy, struct sched_param *param);
|
||||||
|
void *taosThreadGetSpecific(TdThreadKey key);
|
||||||
|
int32_t taosThreadJoin(TdThread thread, void **valuePtr);
|
||||||
|
int32_t taosThreadKeyCreate(TdThreadKey * key, void(*destructor)(void *));
|
||||||
|
int32_t taosThreadKeyDelete(TdThreadKey key);
|
||||||
|
int32_t taosThreadKill(TdThread thread, int32_t sig);
|
||||||
|
int32_t taosThreadMutexConsistent(TdThreadMutex* mutex);
|
||||||
|
int32_t taosThreadMutexDestroy(TdThreadMutex * mutex);
|
||||||
|
int32_t taosThreadMutexInit(TdThreadMutex * mutex, const TdThreadMutexAttr * attr);
|
||||||
|
int32_t taosThreadMutexLock(TdThreadMutex * mutex);
|
||||||
|
int32_t taosThreadMutexTimedLock(TdThreadMutex * mutex, const struct timespec *abstime);
|
||||||
|
int32_t taosThreadMutexTryLock(TdThreadMutex * mutex);
|
||||||
|
int32_t taosThreadMutexUnlock(TdThreadMutex * mutex);
|
||||||
|
int32_t taosThreadMutexAttrDestroy(TdThreadMutexAttr * attr);
|
||||||
|
int32_t taosThreadMutexAttrGetPshared(const TdThreadMutexAttr * attr, int32_t *pshared);
|
||||||
|
int32_t taosThreadMutexAttrGetRobust(const TdThreadMutexAttr * attr, int32_t * robust);
|
||||||
|
int32_t taosThreadMutexAttrGetType(const TdThreadMutexAttr * attr, int32_t *kind);
|
||||||
|
int32_t taosThreadMutexAttrInit(TdThreadMutexAttr * attr);
|
||||||
|
int32_t taosThreadMutexAttrSetPshared(TdThreadMutexAttr * attr, int32_t pshared);
|
||||||
|
int32_t taosThreadMutexAttrSetRobust(TdThreadMutexAttr * attr, int32_t robust);
|
||||||
|
int32_t taosThreadMutexAttrSetType(TdThreadMutexAttr * attr, int32_t kind);
|
||||||
|
int32_t taosThreadOnce(TdThreadOnce * onceControl, void(*initRoutine)(void));
|
||||||
|
int32_t taosThreadRwlockDestroy(TdThreadRwlock * rwlock);
|
||||||
|
int32_t taosThreadRwlockInit(TdThreadRwlock * rwlock, const TdThreadRwlockAttr * attr);
|
||||||
|
int32_t taosThreadRwlockRdlock(TdThreadRwlock * rwlock);
|
||||||
|
int32_t taosThreadRwlockTimedRdlock(TdThreadRwlock * rwlock, const struct timespec *abstime);
|
||||||
|
int32_t taosThreadRwlockTimedWrlock(TdThreadRwlock * rwlock, const struct timespec *abstime);
|
||||||
|
int32_t taosThreadRwlockTryRdlock(TdThreadRwlock * rwlock);
|
||||||
|
int32_t taosThreadRwlockTryWrlock(TdThreadRwlock * rwlock);
|
||||||
|
int32_t taosThreadRwlockUnlock(TdThreadRwlock * rwlock);
|
||||||
|
int32_t taosThreadRwlockWrlock(TdThreadRwlock * rwlock);
|
||||||
|
int32_t taosThreadRwlockAttrDestroy(TdThreadRwlockAttr * attr);
|
||||||
|
int32_t taosThreadRwlockAttrGetPshared(const TdThreadRwlockAttr * attr, int32_t *pshared);
|
||||||
|
int32_t taosThreadRwlockAttrInit(TdThreadRwlockAttr * attr);
|
||||||
|
int32_t taosThreadRwlockAttrSetPshared(TdThreadRwlockAttr * attr, int32_t pshared);
|
||||||
|
TdThread taosThreadSelf(void);
|
||||||
|
int32_t taosThreadSetCancelState(int32_t state, int32_t *oldstate);
|
||||||
|
int32_t taosThreadSetCancelType(int32_t type, int32_t *oldtype);
|
||||||
|
int32_t taosThreadSetSchedParam(TdThread thread, int32_t policy, const struct sched_param *param);
|
||||||
|
int32_t taosThreadSetSpecific(TdThreadKey key, const void *value);
|
||||||
|
int32_t taosThreadSpinDestroy(TdThreadSpinlock * lock);
|
||||||
|
int32_t taosThreadSpinInit(TdThreadSpinlock * lock, int32_t pshared);
|
||||||
|
int32_t taosThreadSpinLock(TdThreadSpinlock * lock);
|
||||||
|
int32_t taosThreadSpinTrylock(TdThreadSpinlock * lock);
|
||||||
|
int32_t taosThreadSpinUnlock(TdThreadSpinlock * lock);
|
||||||
|
void taosThreadTestCancel(void);
|
||||||
|
int32_t taosThreadSigMask(int32_t how, sigset_t const *set, sigset_t * oset);
|
||||||
|
int32_t taosThreadSigWait(const sigset_t * set, int32_t *sig);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
// If the error is in a third-party library, place this header file under the third-party library header file.
|
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||||
// When you want to use this feature, you should find or add the same function in the following section.
|
// When you want to use this feature, you should find or add the same function in the following section.
|
||||||
#ifndef ALLOW_FORBID_FUNC
|
#ifndef ALLOW_FORBID_FUNC
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#ifndef _TD_UTIL_TAOS_ERROR_H_
|
#ifndef _TD_UTIL_TAOS_ERROR_H_
|
||||||
#define _TD_UTIL_TAOS_ERROR_H_
|
#define _TD_UTIL_TAOS_ERROR_H_
|
||||||
|
|
||||||
#include "os.h"
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -78,6 +78,7 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_CFG_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x010C)
|
#define TSDB_CODE_CFG_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x010C)
|
||||||
#define TSDB_CODE_INVALID_CFG TAOS_DEF_ERROR_CODE(0, 0x010D)
|
#define TSDB_CODE_INVALID_CFG TAOS_DEF_ERROR_CODE(0, 0x010D)
|
||||||
#define TSDB_CODE_OUT_OF_SHM_MEM TAOS_DEF_ERROR_CODE(0, 0x010E)
|
#define TSDB_CODE_OUT_OF_SHM_MEM TAOS_DEF_ERROR_CODE(0, 0x010E)
|
||||||
|
#define TSDB_CODE_INVALID_SHM_ID TAOS_DEF_ERROR_CODE(0, 0x010F)
|
||||||
#define TSDB_CODE_REF_NO_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0110)
|
#define TSDB_CODE_REF_NO_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0110)
|
||||||
#define TSDB_CODE_REF_FULL TAOS_DEF_ERROR_CODE(0, 0x0111)
|
#define TSDB_CODE_REF_FULL TAOS_DEF_ERROR_CODE(0, 0x0111)
|
||||||
#define TSDB_CODE_REF_ID_REMOVED TAOS_DEF_ERROR_CODE(0, 0x0112)
|
#define TSDB_CODE_REF_ID_REMOVED TAOS_DEF_ERROR_CODE(0, 0x0112)
|
||||||
|
|
|
@ -381,6 +381,14 @@ typedef enum ELogicConditionType {
|
||||||
#define TSDB_MAX_DB_DELAY 10
|
#define TSDB_MAX_DB_DELAY 10
|
||||||
#define TSDB_DEFAULT_DB_DELAY 2
|
#define TSDB_DEFAULT_DB_DELAY 2
|
||||||
|
|
||||||
|
#define TSDB_DEFAULT_EXPLAIN_VERBOSE false
|
||||||
|
|
||||||
|
#define TSDB_MIN_EXPLAIN_RATIO 0
|
||||||
|
#define TSDB_MAX_EXPLAIN_RATIO 1
|
||||||
|
#define TSDB_DEFAULT_EXPLAIN_RATIO 0.001
|
||||||
|
|
||||||
|
#define TSDB_EXPLAIN_RESULT_ROW_SIZE 1024
|
||||||
|
|
||||||
#define TSDB_MAX_JOIN_TABLE_NUM 10
|
#define TSDB_MAX_JOIN_TABLE_NUM 10
|
||||||
#define TSDB_MAX_UNION_CLAUSE 5
|
#define TSDB_MAX_UNION_CLAUSE 5
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef enum { PROC_REQ, PROC_RSP, PROC_REGISTER } ProcFuncType;
|
typedef enum { PROC_REQ, PROC_RSP, PROC_REG, PROC_RELEASE } ProcFuncType;
|
||||||
|
|
||||||
typedef struct SProcQueue SProcQueue;
|
typedef struct SProcQueue SProcQueue;
|
||||||
typedef struct SProcObj SProcObj;
|
typedef struct SProcObj SProcObj;
|
||||||
|
@ -32,29 +32,25 @@ typedef void *(*ProcConsumeFp)(void *pParent, void *pHead, int16_t headLen, void
|
||||||
ProcFuncType ftype);
|
ProcFuncType ftype);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t childQueueSize;
|
|
||||||
ProcConsumeFp childConsumeFp;
|
ProcConsumeFp childConsumeFp;
|
||||||
ProcMallocFp childMallocHeadFp;
|
ProcMallocFp childMallocHeadFp;
|
||||||
ProcFreeFp childFreeHeadFp;
|
ProcFreeFp childFreeHeadFp;
|
||||||
ProcMallocFp childMallocBodyFp;
|
ProcMallocFp childMallocBodyFp;
|
||||||
ProcFreeFp childFreeBodyFp;
|
ProcFreeFp childFreeBodyFp;
|
||||||
int32_t parentQueueSize;
|
|
||||||
ProcConsumeFp parentConsumeFp;
|
ProcConsumeFp parentConsumeFp;
|
||||||
ProcMallocFp parentdMallocHeadFp;
|
ProcMallocFp parentMallocHeadFp;
|
||||||
ProcFreeFp parentFreeHeadFp;
|
ProcFreeFp parentFreeHeadFp;
|
||||||
ProcMallocFp parentMallocBodyFp;
|
ProcMallocFp parentMallocBodyFp;
|
||||||
ProcFreeFp parentFreeBodyFp;
|
ProcFreeFp parentFreeBodyFp;
|
||||||
bool testFlag;
|
SShm shm;
|
||||||
void *pParent;
|
void *pParent;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
bool isChild;
|
||||||
} SProcCfg;
|
} SProcCfg;
|
||||||
|
|
||||||
SProcObj *taosProcInit(const SProcCfg *pCfg);
|
SProcObj *taosProcInit(const SProcCfg *pCfg);
|
||||||
void taosProcCleanup(SProcObj *pProc);
|
void taosProcCleanup(SProcObj *pProc);
|
||||||
int32_t taosProcRun(SProcObj *pProc);
|
int32_t taosProcRun(SProcObj *pProc);
|
||||||
void taosProcStop(SProcObj *pProc);
|
|
||||||
bool taosProcIsChild(SProcObj *pProc);
|
|
||||||
int32_t taosProcChildId(SProcObj *pProc);
|
|
||||||
int32_t taosProcPutToChildQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen,
|
int32_t taosProcPutToChildQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen,
|
||||||
ProcFuncType ftype);
|
ProcFuncType ftype);
|
||||||
int32_t taosProcPutToParentQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen,
|
int32_t taosProcPutToParentQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen,
|
||||||
|
|
|
@ -200,6 +200,9 @@ static void doDestroyRequest(void *p) {
|
||||||
taosArrayDestroy(pRequest->body.showInfo.pArray);
|
taosArrayDestroy(pRequest->body.showInfo.pArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
taosArrayDestroy(pRequest->tableList);
|
||||||
|
taosArrayDestroy(pRequest->dbList);
|
||||||
|
|
||||||
deregisterRequest(pRequest);
|
deregisterRequest(pRequest);
|
||||||
taosMemoryFreeClear(pRequest);
|
taosMemoryFreeClear(pRequest);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,27 @@
|
||||||
#include "os.h"
|
/*
|
||||||
#include "tref.h"
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
#include "trpc.h"
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "catalog.h"
|
||||||
#include "clientInt.h"
|
#include "clientInt.h"
|
||||||
#include "clientLog.h"
|
#include "clientLog.h"
|
||||||
|
#include "os.h"
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
#include "tmsg.h"
|
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
#include "catalog.h"
|
#include "tmsg.h"
|
||||||
|
#include "tref.h"
|
||||||
|
#include "trpc.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
#define TSC_VAR_NOT_RELEASE 1
|
#define TSC_VAR_NOT_RELEASE 1
|
||||||
|
@ -56,6 +71,12 @@ void taos_cleanup(void) {
|
||||||
tscInfo("all local resources released");
|
tscInfo("all local resources released");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setConfRet taos_set_config(const char *config) {
|
||||||
|
// TODO
|
||||||
|
setConfRet ret = {SET_CONF_RET_SUCC, {0}};
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) {
|
TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) {
|
||||||
tscDebug("try to connect to %s:%u, user:%s db:%s", ip, port, user, db);
|
tscDebug("try to connect to %s:%u, user:%s db:%s", ip, port, user, db);
|
||||||
if (user == NULL) {
|
if (user == NULL) {
|
||||||
|
@ -117,9 +138,7 @@ int taos_field_count(TAOS_RES *res) {
|
||||||
return pResInfo->numOfCols;
|
return pResInfo->numOfCols;
|
||||||
}
|
}
|
||||||
|
|
||||||
int taos_num_fields(TAOS_RES *res) {
|
int taos_num_fields(TAOS_RES *res) { return taos_field_count(res); }
|
||||||
return taos_field_count(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) {
|
TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) {
|
||||||
if (taos_num_fields(res) == 0) {
|
if (taos_num_fields(res) == 0) {
|
||||||
|
@ -144,10 +163,8 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SRequestObj *pRequest = (SRequestObj *)res;
|
SRequestObj *pRequest = (SRequestObj *)res;
|
||||||
if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT ||
|
if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT ||
|
||||||
pRequest->type == TSDB_SQL_INSERT ||
|
pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) {
|
||||||
pRequest->code != TSDB_CODE_SUCCESS ||
|
|
||||||
taos_num_fields(res) == 0) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,23 +263,41 @@ int* taos_fetch_lengths(TAOS_RES *res) {
|
||||||
return ((SRequestObj *)res)->body.resInfo.length;
|
return ((SRequestObj *)res)->body.resInfo.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TAOS_ROW *taos_result_block(TAOS_RES *res) {
|
||||||
|
// TODO
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// todo intergrate with tDataTypes
|
// todo intergrate with tDataTypes
|
||||||
const char *taos_data_type(int type) {
|
const char *taos_data_type(int type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TSDB_DATA_TYPE_NULL: return "TSDB_DATA_TYPE_NULL";
|
case TSDB_DATA_TYPE_NULL:
|
||||||
case TSDB_DATA_TYPE_BOOL: return "TSDB_DATA_TYPE_BOOL";
|
return "TSDB_DATA_TYPE_NULL";
|
||||||
case TSDB_DATA_TYPE_TINYINT: return "TSDB_DATA_TYPE_TINYINT";
|
case TSDB_DATA_TYPE_BOOL:
|
||||||
case TSDB_DATA_TYPE_SMALLINT: return "TSDB_DATA_TYPE_SMALLINT";
|
return "TSDB_DATA_TYPE_BOOL";
|
||||||
case TSDB_DATA_TYPE_INT: return "TSDB_DATA_TYPE_INT";
|
case TSDB_DATA_TYPE_TINYINT:
|
||||||
case TSDB_DATA_TYPE_BIGINT: return "TSDB_DATA_TYPE_BIGINT";
|
return "TSDB_DATA_TYPE_TINYINT";
|
||||||
case TSDB_DATA_TYPE_FLOAT: return "TSDB_DATA_TYPE_FLOAT";
|
case TSDB_DATA_TYPE_SMALLINT:
|
||||||
case TSDB_DATA_TYPE_DOUBLE: return "TSDB_DATA_TYPE_DOUBLE";
|
return "TSDB_DATA_TYPE_SMALLINT";
|
||||||
case TSDB_DATA_TYPE_VARCHAR: return "TSDB_DATA_TYPE_VARCHAR";
|
case TSDB_DATA_TYPE_INT:
|
||||||
|
return "TSDB_DATA_TYPE_INT";
|
||||||
|
case TSDB_DATA_TYPE_BIGINT:
|
||||||
|
return "TSDB_DATA_TYPE_BIGINT";
|
||||||
|
case TSDB_DATA_TYPE_FLOAT:
|
||||||
|
return "TSDB_DATA_TYPE_FLOAT";
|
||||||
|
case TSDB_DATA_TYPE_DOUBLE:
|
||||||
|
return "TSDB_DATA_TYPE_DOUBLE";
|
||||||
|
case TSDB_DATA_TYPE_VARCHAR:
|
||||||
|
return "TSDB_DATA_TYPE_VARCHAR";
|
||||||
// case TSDB_DATA_TYPE_BINARY: return "TSDB_DATA_TYPE_VARCHAR";
|
// case TSDB_DATA_TYPE_BINARY: return "TSDB_DATA_TYPE_VARCHAR";
|
||||||
case TSDB_DATA_TYPE_TIMESTAMP: return "TSDB_DATA_TYPE_TIMESTAMP";
|
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
case TSDB_DATA_TYPE_NCHAR: return "TSDB_DATA_TYPE_NCHAR";
|
return "TSDB_DATA_TYPE_TIMESTAMP";
|
||||||
case TSDB_DATA_TYPE_JSON: return "TSDB_DATA_TYPE_JSON";
|
case TSDB_DATA_TYPE_NCHAR:
|
||||||
default: return "UNKNOWN";
|
return "TSDB_DATA_TYPE_NCHAR";
|
||||||
|
case TSDB_DATA_TYPE_JSON:
|
||||||
|
return "TSDB_DATA_TYPE_JSON";
|
||||||
|
default:
|
||||||
|
return "UNKNOWN";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,16 +364,19 @@ bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col) {
|
||||||
return colDataIsNull_f(pCol->nullbitmap, row);
|
return colDataIsNull_f(pCol->nullbitmap, row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool taos_is_update_query(TAOS_RES *res) {
|
||||||
|
// TODO
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) {
|
int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) {
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SRequestObj *pRequest = (SRequestObj *)res;
|
SRequestObj *pRequest = (SRequestObj *)res;
|
||||||
if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT ||
|
if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT ||
|
||||||
pRequest->type == TSDB_SQL_INSERT ||
|
pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) {
|
||||||
pRequest->code != TSDB_CODE_SUCCESS ||
|
|
||||||
taos_num_fields(res) == 0) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,8 +390,11 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) {
|
||||||
return pResultInfo->numOfRows;
|
return pResultInfo->numOfRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
int taos_validate_sql(TAOS *taos, const char *sql) {
|
int taos_validate_sql(TAOS *taos, const char *sql) { return true; }
|
||||||
return true;
|
|
||||||
|
void taos_reset_current_db(TAOS *taos) {
|
||||||
|
// TODO
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *taos_get_server_info(TAOS *taos) {
|
const char *taos_get_server_info(TAOS *taos) {
|
||||||
|
@ -387,6 +428,11 @@ void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int taos_load_table_info(TAOS *taos, const char *tableNameList) {
|
||||||
|
// TODO
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
TAOS_STMT *taos_stmt_init(TAOS *taos) {
|
TAOS_STMT *taos_stmt_init(TAOS *taos) {
|
||||||
// TODO
|
// TODO
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -437,11 +483,26 @@ int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert) {
|
||||||
|
// TODO
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int taos_stmt_num_params(TAOS_STMT *stmt, int *nums) {
|
||||||
|
// TODO
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int taos_stmt_add_batch(TAOS_STMT* stmt) {
|
int taos_stmt_add_batch(TAOS_STMT* stmt) {
|
||||||
// TODO
|
// TODO
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt) {
|
||||||
|
// TODO
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
int taos_stmt_bind_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind) {
|
int taos_stmt_bind_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind) {
|
||||||
// TODO
|
// TODO
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -26,6 +26,18 @@
|
||||||
#include "tqueue.h"
|
#include "tqueue.h"
|
||||||
#include "tref.h"
|
#include "tref.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int32_t curBlock;
|
||||||
|
int32_t curRow;
|
||||||
|
void** uData;
|
||||||
|
} SMqRowIter;
|
||||||
|
|
||||||
|
struct tmq_message_t {
|
||||||
|
SMqPollRsp msg;
|
||||||
|
void* vg;
|
||||||
|
SMqRowIter iter;
|
||||||
|
};
|
||||||
|
|
||||||
struct tmq_list_t {
|
struct tmq_list_t {
|
||||||
SArray container;
|
SArray container;
|
||||||
};
|
};
|
||||||
|
@ -103,9 +115,10 @@ typedef struct {
|
||||||
char* sql;
|
char* sql;
|
||||||
char* topicName;
|
char* topicName;
|
||||||
int64_t topicId;
|
int64_t topicId;
|
||||||
int32_t nextVgIdx;
|
|
||||||
SArray* vgs; // SArray<SMqClientVg>
|
SArray* vgs; // SArray<SMqClientVg>
|
||||||
SSchemaWrapper schema;
|
int8_t isSchemaAdaptive;
|
||||||
|
int32_t numOfFields;
|
||||||
|
TAOS_FIELD* fields;
|
||||||
} SMqClientTopic;
|
} SMqClientTopic;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -131,10 +144,10 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
tmq_t* tmq;
|
tmq_t* tmq;
|
||||||
/*SMqClientVg* pVg;*/
|
|
||||||
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() {
|
||||||
|
@ -228,6 +241,10 @@ void tmq_list_destroy(tmq_list_t* list) {
|
||||||
taosArrayDestroyEx(container, (void (*)(void*))taosMemoryFree);
|
taosArrayDestroyEx(container, (void (*)(void*))taosMemoryFree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t tmqMakeTopicVgKey(char* dst, const char* topicName, int32_t vg) {
|
||||||
|
return sprintf(dst, "%s:%d", topicName, vg);
|
||||||
|
}
|
||||||
|
|
||||||
void tmqClearUnhandleMsg(tmq_t* tmq) {
|
void tmqClearUnhandleMsg(tmq_t* tmq) {
|
||||||
tmq_message_t* msg = NULL;
|
tmq_message_t* msg = NULL;
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -471,7 +488,12 @@ tmq_resp_err_t tmq_subscribe(tmq_t* tmq, tmq_list_t* topic_list) {
|
||||||
tNameExtractFullName(&name, topicFname);
|
tNameExtractFullName(&name, topicFname);
|
||||||
tscDebug("subscribe topic: %s", topicFname);
|
tscDebug("subscribe topic: %s", topicFname);
|
||||||
SMqClientTopic topic = {
|
SMqClientTopic topic = {
|
||||||
.nextVgIdx = 0, .sql = NULL, .sqlLen = 0, .topicId = 0, .topicName = topicFname, .vgs = NULL};
|
.sql = NULL,
|
||||||
|
.sqlLen = 0,
|
||||||
|
.topicId = 0,
|
||||||
|
.topicName = topicFname,
|
||||||
|
.vgs = NULL,
|
||||||
|
};
|
||||||
topic.vgs = taosArrayInit(0, sizeof(SMqClientVg));
|
topic.vgs = taosArrayInit(0, sizeof(SMqClientVg));
|
||||||
taosArrayPush(tmq->clientTopics, &topic);
|
taosArrayPush(tmq->clientTopics, &topic);
|
||||||
taosArrayPush(req.topicNames, &topicFname);
|
taosArrayPush(req.topicNames, &topicFname);
|
||||||
|
@ -615,6 +637,7 @@ _return:
|
||||||
return pRequest;
|
return pRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, int sqlLen) {
|
TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, int sqlLen) {
|
||||||
STscObj* pTscObj = (STscObj*)taos;
|
STscObj* pTscObj = (STscObj*)taos;
|
||||||
SRequestObj* pRequest = NULL;
|
SRequestObj* pRequest = NULL;
|
||||||
|
@ -700,6 +723,7 @@ _return:
|
||||||
|
|
||||||
return pRequest;
|
return pRequest;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static char* formatTimestamp(char* buf, int64_t val, int precision) {
|
static char* formatTimestamp(char* buf, int64_t val, int precision) {
|
||||||
time_t tt;
|
time_t tt;
|
||||||
|
@ -807,7 +831,7 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
SMqClientVg* pVg = pParam->pVg;
|
SMqClientVg* pVg = pParam->pVg;
|
||||||
tmq_t* tmq = pParam->tmq;
|
tmq_t* tmq = pParam->tmq;
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
printf("msg discard, code:%x\n", code);
|
tscWarn("msg discard, code:%x", code);
|
||||||
goto WRITE_QUEUE_FAIL;
|
goto WRITE_QUEUE_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -815,12 +839,12 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
int32_t tmqEpoch = atomic_load_32(&tmq->epoch);
|
int32_t tmqEpoch = atomic_load_32(&tmq->epoch);
|
||||||
if (msgEpoch < tmqEpoch) {
|
if (msgEpoch < tmqEpoch) {
|
||||||
tsem_post(&tmq->rspSem);
|
tsem_post(&tmq->rspSem);
|
||||||
printf("discard rsp epoch %d, current epoch %d\n", msgEpoch, tmqEpoch);
|
tscWarn("discard rsp epoch %d, current epoch %d", msgEpoch, tmqEpoch);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msgEpoch != tmqEpoch) {
|
if (msgEpoch != tmqEpoch) {
|
||||||
printf("mismatch rsp epoch %d, current epoch %d\n", msgEpoch, tmqEpoch);
|
tscWarn("mismatch rsp epoch %d, current epoch %d", msgEpoch, tmqEpoch);
|
||||||
} else {
|
} else {
|
||||||
atomic_sub_fetch_32(&tmq->waitingRequest, 1);
|
atomic_sub_fetch_32(&tmq->waitingRequest, 1);
|
||||||
}
|
}
|
||||||
|
@ -879,19 +903,54 @@ WRITE_QUEUE_FAIL:
|
||||||
bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) {
|
bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) {
|
||||||
/*printf("call update ep %d\n", epoch);*/
|
/*printf("call update ep %d\n", epoch);*/
|
||||||
bool set = false;
|
bool set = false;
|
||||||
int32_t sz = taosArrayGetSize(pRsp->topics);
|
int32_t topicNumGet = taosArrayGetSize(pRsp->topics);
|
||||||
SArray* newTopics = taosArrayInit(sz, sizeof(SMqClientTopic));
|
char vgKey[TSDB_TOPIC_FNAME_LEN + 22];
|
||||||
for (int32_t i = 0; i < sz; i++) {
|
SArray* newTopics = taosArrayInit(topicNumGet, sizeof(SMqClientTopic));
|
||||||
|
if (newTopics == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
SHashObj* pHash = taosHashInit(64, MurmurHash3_32, false, HASH_NO_LOCK);
|
||||||
|
if (pHash == NULL) {
|
||||||
|
taosArrayDestroy(newTopics);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// find topic, build hash
|
||||||
|
for (int32_t i = 0; i < topicNumGet; i++) {
|
||||||
SMqClientTopic topic = {0};
|
SMqClientTopic topic = {0};
|
||||||
SMqSubTopicEp* pTopicEp = taosArrayGet(pRsp->topics, i);
|
SMqSubTopicEp* pTopicEp = taosArrayGet(pRsp->topics, i);
|
||||||
|
taosHashClear(pHash);
|
||||||
topic.topicName = strdup(pTopicEp->topic);
|
topic.topicName = strdup(pTopicEp->topic);
|
||||||
int32_t vgSz = taosArrayGetSize(pTopicEp->vgs);
|
|
||||||
topic.vgs = taosArrayInit(vgSz, sizeof(SMqClientVg));
|
int32_t topicNumCur = taosArrayGetSize(tmq->clientTopics);
|
||||||
for (int32_t j = 0; j < vgSz; j++) {
|
for (int32_t j = 0; j < topicNumCur; j++) {
|
||||||
|
// find old topic
|
||||||
|
SMqClientTopic* pTopicCur = taosArrayGet(tmq->clientTopics, j);
|
||||||
|
if (pTopicCur->vgs && strcmp(pTopicCur->topicName, pTopicEp->topic) == 0) {
|
||||||
|
int32_t vgNumCur = taosArrayGetSize(pTopicCur->vgs);
|
||||||
|
if (vgNumCur == 0) break;
|
||||||
|
for (int32_t k = 0; k < vgNumCur; k++) {
|
||||||
|
SMqClientVg* pVgCur = taosArrayGet(pTopicCur->vgs, k);
|
||||||
|
sprintf(vgKey, "%s:%d", topic.topicName, pVgCur->vgId);
|
||||||
|
taosHashPut(pHash, vgKey, strlen(vgKey), &pVgCur->currentOffset, sizeof(int64_t));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t vgNumGet = taosArrayGetSize(pTopicEp->vgs);
|
||||||
|
topic.vgs = taosArrayInit(vgNumGet, sizeof(SMqClientVg));
|
||||||
|
for (int32_t j = 0; j < vgNumGet; j++) {
|
||||||
SMqSubVgEp* pVgEp = taosArrayGet(pTopicEp->vgs, j);
|
SMqSubVgEp* pVgEp = taosArrayGet(pTopicEp->vgs, j);
|
||||||
|
sprintf(vgKey, "%s:%d", topic.topicName, pVgEp->vgId);
|
||||||
|
int64_t* pOffset = taosHashGet(pHash, vgKey, strlen(vgKey));
|
||||||
|
int64_t offset = pVgEp->offset;
|
||||||
|
if (pOffset != NULL) {
|
||||||
|
offset = *pOffset;
|
||||||
|
}
|
||||||
SMqClientVg clientVg = {
|
SMqClientVg clientVg = {
|
||||||
.pollCnt = 0,
|
.pollCnt = 0,
|
||||||
.currentOffset = pVgEp->offset,
|
.currentOffset = offset,
|
||||||
.vgId = pVgEp->vgId,
|
.vgId = pVgEp->vgId,
|
||||||
.epSet = pVgEp->epSet,
|
.epSet = pVgEp->epSet,
|
||||||
.vgStatus = TMQ_VG_STATUS__IDLE,
|
.vgStatus = TMQ_VG_STATUS__IDLE,
|
||||||
|
@ -902,6 +961,7 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) {
|
||||||
taosArrayPush(newTopics, &topic);
|
taosArrayPush(newTopics, &topic);
|
||||||
}
|
}
|
||||||
if (tmq->clientTopics) taosArrayDestroy(tmq->clientTopics);
|
if (tmq->clientTopics) taosArrayDestroy(tmq->clientTopics);
|
||||||
|
taosHashCleanup(pHash);
|
||||||
tmq->clientTopics = newTopics;
|
tmq->clientTopics = newTopics;
|
||||||
atomic_store_32(&tmq->epoch, epoch);
|
atomic_store_32(&tmq->epoch, epoch);
|
||||||
return set;
|
return set;
|
||||||
|
@ -911,7 +971,7 @@ int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
SMqAskEpCbParam* pParam = (SMqAskEpCbParam*)param;
|
SMqAskEpCbParam* pParam = (SMqAskEpCbParam*)param;
|
||||||
tmq_t* tmq = pParam->tmq;
|
tmq_t* tmq = pParam->tmq;
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
printf("get topic endpoint error, not ready, wait:%d\n", pParam->sync);
|
tscError("get topic endpoint error, not ready, wait:%d\n", pParam->sync);
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1282,6 +1342,7 @@ tmq_message_t* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) {
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
/*printf("cycle\n");*/
|
/*printf("cycle\n");*/
|
||||||
|
tmqAskEp(tmq, false);
|
||||||
tmqPollImpl(tmq, blocking_time);
|
tmqPollImpl(tmq, blocking_time);
|
||||||
|
|
||||||
tsem_wait(&tmq->rspSem);
|
tsem_wait(&tmq->rspSem);
|
||||||
|
|
|
@ -55,8 +55,9 @@ TEST(testCase, create_topic_ctb_Test) {
|
||||||
|
|
||||||
taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
|
|
||||||
char* sql = "select * from tu";
|
// char* sql = "select * from tu";
|
||||||
pRes = tmq_create_topic(pConn, "test_ctb_topic_1", sql, strlen(sql));
|
// pRes = tmq_create_topic(pConn, "test_ctb_topic_1", sql, strlen(sql));
|
||||||
|
pRes = taos_query(pConn, "create test_ctb_topic_1 as select * from tu");
|
||||||
taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
taos_close(pConn);
|
taos_close(pConn);
|
||||||
}
|
}
|
||||||
|
@ -79,8 +80,9 @@ TEST(testCase, create_topic_stb_Test) {
|
||||||
|
|
||||||
taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
|
|
||||||
char* sql = "select * from st1";
|
// char* sql = "select * from st1";
|
||||||
pRes = tmq_create_topic(pConn, "test_stb_topic_1", sql, strlen(sql));
|
// pRes = tmq_create_topic(pConn, "test_stb_topic_1", sql, strlen(sql));
|
||||||
|
pRes = taos_query(pConn, "create test_ctb_topic_1 as select * from st1");
|
||||||
taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
taos_close(pConn);
|
taos_close(pConn);
|
||||||
}
|
}
|
||||||
|
|
|
@ -331,7 +331,6 @@ int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(pColInfoData->nullbitmap == NULL);
|
|
||||||
pDataBlock->info.window.skey = *(TSKEY*)colDataGetData(pColInfoData, 0);
|
pDataBlock->info.window.skey = *(TSKEY*)colDataGetData(pColInfoData, 0);
|
||||||
pDataBlock->info.window.ekey = *(TSKEY*)colDataGetData(pColInfoData, (pDataBlock->info.rows - 1));
|
pDataBlock->info.window.ekey = *(TSKEY*)colDataGetData(pColInfoData, (pDataBlock->info.rows - 1));
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -609,22 +608,6 @@ size_t blockDataGetSerialMetaSize(const SSDataBlock* pBlock) {
|
||||||
return sizeof(int32_t) + pBlock->info.numOfCols * sizeof(int32_t);
|
return sizeof(int32_t) + pBlock->info.numOfCols * sizeof(int32_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
SSchema* blockDataExtractSchema(const SSDataBlock* pBlock, int32_t* numOfCols) {
|
|
||||||
SSchema* pSchema = taosMemoryCalloc(pBlock->info.numOfCols, sizeof(SSchema));
|
|
||||||
for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) {
|
|
||||||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i);
|
|
||||||
pSchema[i].bytes = pColInfoData->info.bytes;
|
|
||||||
pSchema[i].type = pColInfoData->info.type;
|
|
||||||
pSchema[i].colId = pColInfoData->info.colId;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (numOfCols != NULL) {
|
|
||||||
*numOfCols = pBlock->info.numOfCols;
|
|
||||||
}
|
|
||||||
|
|
||||||
return pSchema;
|
|
||||||
}
|
|
||||||
|
|
||||||
double blockDataGetSerialRowSize(const SSDataBlock* pBlock) {
|
double blockDataGetSerialRowSize(const SSDataBlock* pBlock) {
|
||||||
ASSERT(pBlock != NULL);
|
ASSERT(pBlock != NULL);
|
||||||
double rowSize = 0;
|
double rowSize = 0;
|
||||||
|
|
|
@ -45,7 +45,7 @@ float tsRatioOfQueryCores = 1.0f;
|
||||||
int32_t tsMaxBinaryDisplayWidth = 30;
|
int32_t tsMaxBinaryDisplayWidth = 30;
|
||||||
bool tsEnableSlaveQuery = 1;
|
bool tsEnableSlaveQuery = 1;
|
||||||
bool tsPrintAuth = 0;
|
bool tsPrintAuth = 0;
|
||||||
int32_t tsMultiProcess = 0;
|
bool tsMultiProcess = 0;
|
||||||
|
|
||||||
// monitor
|
// monitor
|
||||||
bool tsEnableMonitor = 1;
|
bool tsEnableMonitor = 1;
|
||||||
|
@ -347,7 +347,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
|
||||||
if (cfgAddBool(pCfg, "printAuth", tsPrintAuth, 0) != 0) return -1;
|
if (cfgAddBool(pCfg, "printAuth", tsPrintAuth, 0) != 0) return -1;
|
||||||
if (cfgAddBool(pCfg, "slaveQuery", tsEnableSlaveQuery, 0) != 0) return -1;
|
if (cfgAddBool(pCfg, "slaveQuery", tsEnableSlaveQuery, 0) != 0) return -1;
|
||||||
if (cfgAddBool(pCfg, "deadLockKillQuery", tsDeadLockKillQuery, 0) != 0) return -1;
|
if (cfgAddBool(pCfg, "deadLockKillQuery", tsDeadLockKillQuery, 0) != 0) return -1;
|
||||||
if (cfgAddInt32(pCfg, "multiProcess", tsMultiProcess, 0, 2, 0) != 0) return -1;
|
if (cfgAddBool(pCfg, "multiProcess", tsMultiProcess, 0) != 0) return -1;
|
||||||
|
|
||||||
if (cfgAddBool(pCfg, "monitor", tsEnableMonitor, 0) != 0) return -1;
|
if (cfgAddBool(pCfg, "monitor", tsEnableMonitor, 0) != 0) return -1;
|
||||||
if (cfgAddInt32(pCfg, "monitorInterval", tsMonitorInterval, 1, 360000, 0) != 0) return -1;
|
if (cfgAddInt32(pCfg, "monitorInterval", tsMonitorInterval, 1, 360000, 0) != 0) return -1;
|
||||||
|
@ -466,7 +466,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
|
||||||
tsPrintAuth = cfgGetItem(pCfg, "printAuth")->bval;
|
tsPrintAuth = cfgGetItem(pCfg, "printAuth")->bval;
|
||||||
tsEnableSlaveQuery = cfgGetItem(pCfg, "slaveQuery")->bval;
|
tsEnableSlaveQuery = cfgGetItem(pCfg, "slaveQuery")->bval;
|
||||||
tsDeadLockKillQuery = cfgGetItem(pCfg, "deadLockKillQuery")->bval;
|
tsDeadLockKillQuery = cfgGetItem(pCfg, "deadLockKillQuery")->bval;
|
||||||
tsMultiProcess = cfgGetItem(pCfg, "multiProcess")->i32;
|
tsMultiProcess = cfgGetItem(pCfg, "multiProcess")->bval;
|
||||||
|
|
||||||
tsEnableMonitor = cfgGetItem(pCfg, "monitor")->bval;
|
tsEnableMonitor = cfgGetItem(pCfg, "monitor")->bval;
|
||||||
tsMonitorInterval = cfgGetItem(pCfg, "monitorInterval")->i32;
|
tsMonitorInterval = cfgGetItem(pCfg, "monitorInterval")->i32;
|
||||||
|
|
|
@ -16,6 +16,10 @@
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "tmsgcb.h"
|
#include "tmsgcb.h"
|
||||||
|
|
||||||
|
static SMsgCb tsDefaultMsgCb;
|
||||||
|
|
||||||
|
void tmsgSetDefaultMsgCb(const SMsgCb* pMsgCb) { tsDefaultMsgCb = *pMsgCb; }
|
||||||
|
|
||||||
int32_t tmsgPutToQueue(const SMsgCb* pMsgCb, EQueueType qtype, SRpcMsg* pReq) {
|
int32_t tmsgPutToQueue(const SMsgCb* pMsgCb, EQueueType qtype, SRpcMsg* pReq) {
|
||||||
return (*pMsgCb->queueFps[qtype])(pMsgCb->pWrapper, pReq);
|
return (*pMsgCb->queueFps[qtype])(pMsgCb->pWrapper, pReq);
|
||||||
}
|
}
|
||||||
|
@ -32,12 +36,12 @@ int32_t tmsgSendMnodeReq(const SMsgCb* pMsgCb, SRpcMsg* pReq) {
|
||||||
return (*pMsgCb->sendMnodeReqFp)(pMsgCb->pWrapper, pReq);
|
return (*pMsgCb->sendMnodeReqFp)(pMsgCb->pWrapper, pReq);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tmsgSendRsp(const SMsgCb* pMsgCb, const SRpcMsg* pRsp) { return (*pMsgCb->sendRspFp)(pMsgCb->pWrapper, pRsp); }
|
void tmsgSendRsp(const SRpcMsg* pRsp) { return (*tsDefaultMsgCb.sendRspFp)(tsDefaultMsgCb.pWrapper, pRsp); }
|
||||||
|
|
||||||
void tmsgRegisterBrokenLinkArg(const SMsgCb* pMsgCb, SRpcMsg* pMsg) {
|
void tmsgRegisterBrokenLinkArg(const SMsgCb* pMsgCb, SRpcMsg* pMsg) {
|
||||||
(*pMsgCb->registerBrokenLinkArgFp)(pMsgCb->pWrapper, pMsg);
|
(*pMsgCb->registerBrokenLinkArgFp)(pMsgCb->pWrapper, pMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tmsgReleaseHandle(const SMsgCb* pMsgCb, void* handle, int8_t type) {
|
void tmsgReleaseHandle(void* handle, int8_t type) {
|
||||||
(*pMsgCb->releaseHandleFp)(pMsgCb->pWrapper, handle, type);
|
(*tsDefaultMsgCb.releaseHandleFp)(tsDefaultMsgCb.pWrapper, handle, type);
|
||||||
}
|
}
|
|
@ -1,12 +1,10 @@
|
||||||
aux_source_directory(src DNODE_SRC)
|
aux_source_directory(dm/src DNODE_SRC)
|
||||||
aux_source_directory(dnode/src DNODE_SRC)
|
aux_source_directory(qm/src DNODE_SRC)
|
||||||
aux_source_directory(qnode/src DNODE_SRC)
|
aux_source_directory(bm/src DNODE_SRC)
|
||||||
aux_source_directory(bnode/src DNODE_SRC)
|
aux_source_directory(sm/src DNODE_SRC)
|
||||||
aux_source_directory(snode/src DNODE_SRC)
|
aux_source_directory(vm/src DNODE_SRC)
|
||||||
aux_source_directory(vnode/src DNODE_SRC)
|
aux_source_directory(mm/src DNODE_SRC)
|
||||||
aux_source_directory(mnode/src DNODE_SRC)
|
aux_source_directory(main/src DNODE_SRC)
|
||||||
aux_source_directory(container/src DNODE_SRC)
|
|
||||||
|
|
||||||
add_library(dnode STATIC ${DNODE_SRC})
|
add_library(dnode STATIC ${DNODE_SRC})
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
dnode cjson mnode vnode qnode snode bnode wal sync taos tfs monitor
|
dnode cjson mnode vnode qnode snode bnode wal sync taos tfs monitor
|
||||||
|
@ -14,16 +12,22 @@ target_link_libraries(
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
dnode
|
dnode
|
||||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mgmt"
|
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mgmt"
|
||||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/dnode/inc"
|
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/dm/inc"
|
||||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/qnode/inc"
|
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/qm/inc"
|
||||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/bnode/inc"
|
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/bm/inc"
|
||||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/snode/inc"
|
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/sm/inc"
|
||||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/vnode/inc"
|
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/vm/inc"
|
||||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/mnode/inc"
|
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/mm/inc"
|
||||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/container/inc"
|
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/main/inc"
|
||||||
)
|
)
|
||||||
|
|
||||||
add_subdirectory(main)
|
aux_source_directory(main/exe EXEC_SRC)
|
||||||
|
add_executable(taosd ${EXEC_SRC})
|
||||||
|
target_include_directories(
|
||||||
|
taosd
|
||||||
|
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/main/inc"
|
||||||
|
)
|
||||||
|
target_link_libraries(taosd dnode)
|
||||||
|
|
||||||
if(${BUILD_TEST})
|
if(${BUILD_TEST})
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
|
|
|
@ -1,267 +0,0 @@
|
||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
|
||||||
#include "dndInt.h"
|
|
||||||
|
|
||||||
static void dndResetLog(SMgmtWrapper *pMgmt) {
|
|
||||||
char logname[24] = {0};
|
|
||||||
snprintf(logname, sizeof(logname), "%slog", pMgmt->name);
|
|
||||||
|
|
||||||
dInfo("node:%s, reset log to %s in child process", pMgmt->name, logname);
|
|
||||||
taosCloseLog();
|
|
||||||
taosInitLog(logname, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool dndRequireNode(SMgmtWrapper *pWrapper) {
|
|
||||||
bool required = false;
|
|
||||||
int32_t code =(*pWrapper->fp.requiredFp)(pWrapper, &required);
|
|
||||||
if (!required) {
|
|
||||||
dDebug("node:%s, no need to start", pWrapper->name);
|
|
||||||
} else {
|
|
||||||
dDebug("node:%s, need to start", pWrapper->name);
|
|
||||||
}
|
|
||||||
return required;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t dndOpenNode(SMgmtWrapper *pWrapper) {
|
|
||||||
int32_t code = (*pWrapper->fp.openFp)(pWrapper);
|
|
||||||
if (code != 0) {
|
|
||||||
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
dDebug("node:%s, has been opened", pWrapper->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
pWrapper->deployed = true;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void dndCloseNode(SMgmtWrapper *pWrapper) {
|
|
||||||
dDebug("node:%s, start to close", pWrapper->name);
|
|
||||||
pWrapper->required = false;
|
|
||||||
taosWLockLatch(&pWrapper->latch);
|
|
||||||
if (pWrapper->deployed) {
|
|
||||||
(*pWrapper->fp.closeFp)(pWrapper);
|
|
||||||
pWrapper->deployed = false;
|
|
||||||
}
|
|
||||||
taosWUnLockLatch(&pWrapper->latch);
|
|
||||||
|
|
||||||
while (pWrapper->refCount > 0) {
|
|
||||||
taosMsleep(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pWrapper->pProc) {
|
|
||||||
taosProcCleanup(pWrapper->pProc);
|
|
||||||
pWrapper->pProc = NULL;
|
|
||||||
}
|
|
||||||
dDebug("node:%s, has been closed", pWrapper->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t dndRunInSingleProcess(SDnode *pDnode) {
|
|
||||||
dInfo("dnode run in single process mode");
|
|
||||||
|
|
||||||
for (ENodeType n = 0; n < NODE_MAX; ++n) {
|
|
||||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
|
||||||
pWrapper->required = dndRequireNode(pWrapper);
|
|
||||||
if (!pWrapper->required) continue;
|
|
||||||
|
|
||||||
if (taosMkDir(pWrapper->path) != 0) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
dError("failed to create dir:%s since %s", pWrapper->path, terrstr());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
dInfo("node:%s, will start in single process", pWrapper->name);
|
|
||||||
pWrapper->procType = PROC_SINGLE;
|
|
||||||
if (dndOpenNode(pWrapper) != 0) {
|
|
||||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dndSetStatus(pDnode, DND_STAT_RUNNING);
|
|
||||||
|
|
||||||
for (ENodeType n = 0; n < NODE_MAX; ++n) {
|
|
||||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
|
||||||
if (!pWrapper->required) continue;
|
|
||||||
if (pWrapper->fp.startFp == NULL) continue;
|
|
||||||
if ((*pWrapper->fp.startFp)(pWrapper) != 0) {
|
|
||||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dndClearNodesExecpt(SDnode *pDnode, ENodeType except) {
|
|
||||||
// dndCleanupServer(pDnode);
|
|
||||||
for (ENodeType n = 0; n < NODE_MAX; ++n) {
|
|
||||||
if (except == n) continue;
|
|
||||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
|
||||||
pWrapper->required = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen,
|
|
||||||
ProcFuncType ftype) {
|
|
||||||
SRpcMsg *pRpc = &pMsg->rpcMsg;
|
|
||||||
pRpc->pCont = pCont;
|
|
||||||
dTrace("msg:%p, get from child queue, type:%s handle:%p app:%p", pMsg, TMSG_INFO(pRpc->msgType), pRpc->handle,
|
|
||||||
pRpc->ahandle);
|
|
||||||
|
|
||||||
NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pRpc->msgType)];
|
|
||||||
int32_t code = (*msgFp)(pWrapper, pMsg);
|
|
||||||
|
|
||||||
if (code != 0) {
|
|
||||||
dError("msg:%p, failed to process since code:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code));
|
|
||||||
if (pRpc->msgType & 1U) {
|
|
||||||
SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = terrno};
|
|
||||||
dndSendRsp(pWrapper, &rsp);
|
|
||||||
}
|
|
||||||
|
|
||||||
dTrace("msg:%p, is freed", pMsg);
|
|
||||||
taosFreeQitem(pMsg);
|
|
||||||
rpcFreeCont(pCont);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen,
|
|
||||||
ProcFuncType ftype) {
|
|
||||||
pMsg->pCont = pCont;
|
|
||||||
dTrace("msg:%p, get from parent queue, type:%s handle:%p app:%p", pMsg, TMSG_INFO(pMsg->msgType), pMsg->handle,
|
|
||||||
pMsg->ahandle);
|
|
||||||
|
|
||||||
switch (ftype) {
|
|
||||||
case PROC_REGISTER:
|
|
||||||
rpcRegisterBrokenLinkArg(pMsg);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
dndSendRpcRsp(pWrapper, pMsg);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
taosMemoryFree(pMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t dndRunInMultiProcess(SDnode *pDnode) {
|
|
||||||
dInfo("dnode run in multi process mode");
|
|
||||||
|
|
||||||
for (ENodeType n = 0; n < NODE_MAX; ++n) {
|
|
||||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
|
||||||
pWrapper->required = dndRequireNode(pWrapper);
|
|
||||||
if (!pWrapper->required) continue;
|
|
||||||
|
|
||||||
if (taosMkDir(pWrapper->path) != 0) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
dError("failed to create dir:%s since %s", pWrapper->path, terrstr());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (n == DNODE) {
|
|
||||||
dInfo("node:%s, will start in parent process", pWrapper->name);
|
|
||||||
pWrapper->procType = PROC_SINGLE;
|
|
||||||
if (dndOpenNode(pWrapper) != 0) {
|
|
||||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
SProcCfg cfg = {.childQueueSize = 1024 * 1024 * 2, // size will be a configuration item
|
|
||||||
.childConsumeFp = (ProcConsumeFp)dndConsumeChildQueue,
|
|
||||||
.childMallocHeadFp = (ProcMallocFp)taosAllocateQitem,
|
|
||||||
.childFreeHeadFp = (ProcFreeFp)taosFreeQitem,
|
|
||||||
.childMallocBodyFp = (ProcMallocFp)rpcMallocCont,
|
|
||||||
.childFreeBodyFp = (ProcFreeFp)rpcFreeCont,
|
|
||||||
.parentQueueSize = 1024 * 1024 * 2, // size will be a configuration item
|
|
||||||
.parentConsumeFp = (ProcConsumeFp)dndConsumeParentQueue,
|
|
||||||
.parentdMallocHeadFp = (ProcMallocFp)taosMemoryMalloc,
|
|
||||||
.parentFreeHeadFp = (ProcFreeFp)taosMemoryFree,
|
|
||||||
.parentMallocBodyFp = (ProcMallocFp)rpcMallocCont,
|
|
||||||
.parentFreeBodyFp = (ProcFreeFp)rpcFreeCont,
|
|
||||||
.pParent = pWrapper,
|
|
||||||
.name = pWrapper->name};
|
|
||||||
SProcObj *pProc = taosProcInit(&cfg);
|
|
||||||
if (pProc == NULL) {
|
|
||||||
dError("node:%s, failed to fork since %s", pWrapper->name, terrstr());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
pWrapper->pProc = pProc;
|
|
||||||
|
|
||||||
if (taosProcIsChild(pProc)) {
|
|
||||||
dInfo("node:%s, will start in child process", pWrapper->name);
|
|
||||||
pWrapper->procType = PROC_CHILD;
|
|
||||||
dndResetLog(pWrapper);
|
|
||||||
|
|
||||||
dInfo("node:%s, clean up resources inherited from parent", pWrapper->name);
|
|
||||||
dndClearNodesExecpt(pDnode, n);
|
|
||||||
|
|
||||||
dInfo("node:%s, will be initialized in child process", pWrapper->name);
|
|
||||||
dndOpenNode(pWrapper);
|
|
||||||
} else {
|
|
||||||
dInfo("node:%s, will not start in parent process, child pid:%d", pWrapper->name, taosProcChildId(pProc));
|
|
||||||
pWrapper->procType = PROC_PARENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (taosProcRun(pProc) != 0) {
|
|
||||||
dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dndSetStatus(pDnode, DND_STAT_RUNNING);
|
|
||||||
|
|
||||||
for (ENodeType n = 0; n < NODE_MAX; ++n) {
|
|
||||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
|
||||||
if (!pWrapper->required) continue;
|
|
||||||
if (pWrapper->fp.startFp == NULL) continue;
|
|
||||||
if (pWrapper->procType == PROC_PARENT && n != DNODE) continue;
|
|
||||||
if (pWrapper->procType == PROC_CHILD && n == DNODE) continue;
|
|
||||||
if ((*pWrapper->fp.startFp)(pWrapper) != 0) {
|
|
||||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t dndRun(SDnode *pDnode) {
|
|
||||||
if (tsMultiProcess == 0) {
|
|
||||||
if (dndRunInSingleProcess(pDnode) != 0) {
|
|
||||||
dError("failed to run dnode in single process mode since %s", terrstr());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (dndRunInMultiProcess(pDnode) != 0) {
|
|
||||||
dError("failed to run dnode in multi process mode since %s", terrstr());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dndReportStartup(pDnode, "TDengine", "initialized successfully");
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
if (pDnode->event == DND_EVENT_STOP) {
|
|
||||||
dInfo("dnode is about to stop");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
taosMsleep(100);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,103 +0,0 @@
|
||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
|
||||||
#include "dndInt.h"
|
|
||||||
|
|
||||||
#define MAXLEN 1024
|
|
||||||
|
|
||||||
int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed) {
|
|
||||||
int32_t code = TSDB_CODE_NODE_PARSE_FILE_ERROR;
|
|
||||||
int32_t len = 0;
|
|
||||||
const int32_t maxLen = MAXLEN;
|
|
||||||
char content[MAXLEN + 1] = {0};
|
|
||||||
cJSON *root = NULL;
|
|
||||||
char file[PATH_MAX];
|
|
||||||
TdFilePtr pFile = NULL;
|
|
||||||
|
|
||||||
snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name);
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
|
||||||
if (pFile == NULL) {
|
|
||||||
dDebug("file %s not exist", file);
|
|
||||||
code = 0;
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
len = (int32_t)taosReadFile(pFile, content, maxLen);
|
|
||||||
if (len <= 0) {
|
|
||||||
dError("failed to read %s since content is null", file);
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
content[len] = 0;
|
|
||||||
root = cJSON_Parse(content);
|
|
||||||
if (root == NULL) {
|
|
||||||
dError("failed to read %s since invalid json format", file);
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON *deployed = cJSON_GetObjectItem(root, "deployed");
|
|
||||||
if (!deployed || deployed->type != cJSON_Number) {
|
|
||||||
dError("failed to read %s since deployed not found", file);
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
*pDeployed = deployed->valueint != 0;
|
|
||||||
|
|
||||||
code = 0;
|
|
||||||
dDebug("succcessed to read file %s, deployed:%d", file, *pDeployed);
|
|
||||||
|
|
||||||
_OVER:
|
|
||||||
if (root != NULL) cJSON_Delete(root);
|
|
||||||
if (pFile != NULL) taosCloseFile(&pFile);
|
|
||||||
|
|
||||||
terrno = code;
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed) {
|
|
||||||
char file[PATH_MAX] = {0};
|
|
||||||
snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name);
|
|
||||||
|
|
||||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
|
||||||
if (pFile == NULL) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
dError("failed to write %s since %s", file, terrstr());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t len = 0;
|
|
||||||
const int32_t maxLen = MAXLEN;
|
|
||||||
char content[MAXLEN + 1] = {0};
|
|
||||||
|
|
||||||
len += snprintf(content + len, maxLen - len, "{\n");
|
|
||||||
len += snprintf(content + len, maxLen - len, " \"deployed\": %d\n", deployed);
|
|
||||||
len += snprintf(content + len, maxLen - len, "}\n");
|
|
||||||
|
|
||||||
taosWriteFile(pFile, content, len);
|
|
||||||
taosFsyncFile(pFile);
|
|
||||||
taosCloseFile(&pFile);
|
|
||||||
|
|
||||||
char realfile[PATH_MAX] = {0};
|
|
||||||
snprintf(realfile, sizeof(realfile), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name);
|
|
||||||
|
|
||||||
if (taosRenameFile(file, realfile) != 0) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
dError("failed to rename %s since %s", file, terrstr());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
dInfo("successed to write %s, deployed:%d", realfile, deployed);
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -130,7 +130,7 @@ int32_t dmReadFile(SDnodeMgmt *pMgmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
dInfo("succcessed to read file %s", file);
|
dDebug("succcessed to read file %s", file);
|
||||||
dmPrintDnodes(pMgmt);
|
dmPrintDnodes(pMgmt);
|
||||||
|
|
||||||
PRASE_DNODE_OVER:
|
PRASE_DNODE_OVER:
|
|
@ -112,6 +112,16 @@ int32_t dmInit(SMgmtWrapper *pWrapper) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dndInitServer(pDnode) != 0) {
|
||||||
|
dError("failed to init trans server since %s", terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dndInitClient(pDnode) != 0) {
|
||||||
|
dError("failed to init trans client since %s", terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
pWrapper->pMgmt = pMgmt;
|
pWrapper->pMgmt = pMgmt;
|
||||||
dInfo("dnode-mgmt is initialized");
|
dInfo("dnode-mgmt is initialized");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -122,6 +132,7 @@ void dmCleanup(SMgmtWrapper *pWrapper) {
|
||||||
if (pMgmt == NULL) return;
|
if (pMgmt == NULL) return;
|
||||||
|
|
||||||
dInfo("dnode-mgmt start to clean up");
|
dInfo("dnode-mgmt start to clean up");
|
||||||
|
SDnode *pDnode = pMgmt->pDnode;
|
||||||
dmStopWorker(pMgmt);
|
dmStopWorker(pMgmt);
|
||||||
|
|
||||||
taosWLockLatch(&pMgmt->latch);
|
taosWLockLatch(&pMgmt->latch);
|
||||||
|
@ -140,6 +151,9 @@ void dmCleanup(SMgmtWrapper *pWrapper) {
|
||||||
|
|
||||||
taosMemoryFree(pMgmt);
|
taosMemoryFree(pMgmt);
|
||||||
pWrapper->pMgmt = NULL;
|
pWrapper->pMgmt = NULL;
|
||||||
|
dndCleanupServer(pDnode);
|
||||||
|
dndCleanupClient(pDnode);
|
||||||
|
|
||||||
dInfo("dnode-mgmt is cleaned up");
|
dInfo("dnode-mgmt is cleaned up");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
aux_source_directory(src EXEC_SRC)
|
|
||||||
add_executable(taosd ${EXEC_SRC})
|
|
||||||
|
|
||||||
target_include_directories(
|
|
||||||
taosd
|
|
||||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(taosd dnode)
|
|
|
@ -0,0 +1,218 @@
|
||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "dnd.h"
|
||||||
|
#include "tconfig.h"
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
bool dumpConfig;
|
||||||
|
bool generateGrant;
|
||||||
|
bool printAuth;
|
||||||
|
bool printVersion;
|
||||||
|
char envFile[PATH_MAX];
|
||||||
|
char apolloUrl[PATH_MAX];
|
||||||
|
SArray *pArgs; // SConfigPair
|
||||||
|
SDnode *pDnode;
|
||||||
|
ENodeType ntype;
|
||||||
|
} global = {0};
|
||||||
|
|
||||||
|
static void dndStopDnode(int signum, void *info, void *ctx) {
|
||||||
|
dInfo("signal:%d is received", signum);
|
||||||
|
SDnode *pDnode = atomic_val_compare_exchange_ptr(&global.pDnode, 0, global.pDnode);
|
||||||
|
if (pDnode != NULL) {
|
||||||
|
dndHandleEvent(pDnode, DND_EVENT_STOP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dndHandleChild(int signum, void *info, void *ctx) {
|
||||||
|
dInfo("signal:%d is received", signum);
|
||||||
|
dndHandleEvent(global.pDnode, DND_EVENT_CHILD);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dndSetSignalHandle() {
|
||||||
|
taosSetSignal(SIGTERM, dndStopDnode);
|
||||||
|
taosSetSignal(SIGHUP, dndStopDnode);
|
||||||
|
taosSetSignal(SIGINT, dndStopDnode);
|
||||||
|
taosSetSignal(SIGABRT, dndStopDnode);
|
||||||
|
taosSetSignal(SIGBREAK, dndStopDnode);
|
||||||
|
|
||||||
|
if (!tsMultiProcess) {
|
||||||
|
// Set the single process signal
|
||||||
|
} else if (global.ntype == DNODE) {
|
||||||
|
// When the child process exits, the parent process receives a signal
|
||||||
|
taosSetSignal(SIGCHLD, dndHandleChild);
|
||||||
|
} else {
|
||||||
|
// When the parent process exits, the child process will receive the SIGKILL signal
|
||||||
|
taosKillChildOnSelfStopped();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t dndParseArgs(int32_t argc, char const *argv[]) {
|
||||||
|
for (int32_t i = 1; i < argc; ++i) {
|
||||||
|
if (strcmp(argv[i], "-c") == 0) {
|
||||||
|
if (i < argc - 1) {
|
||||||
|
if (strlen(argv[++i]) >= PATH_MAX) {
|
||||||
|
printf("config file path overflow");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
tstrncpy(configDir, argv[i], PATH_MAX);
|
||||||
|
} else {
|
||||||
|
printf("'-c' requires a parameter, default is %s\n", configDir);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else if (strcmp(argv[i], "-a") == 0) {
|
||||||
|
tstrncpy(global.apolloUrl, argv[++i], PATH_MAX);
|
||||||
|
} else if (strcmp(argv[i], "-e") == 0) {
|
||||||
|
tstrncpy(global.envFile, argv[++i], PATH_MAX);
|
||||||
|
} else if (strcmp(argv[i], "-k") == 0) {
|
||||||
|
global.generateGrant = true;
|
||||||
|
} else if (strcmp(argv[i], "-n") == 0) {
|
||||||
|
global.ntype = atoi(argv[++i]);
|
||||||
|
if (global.ntype <= DNODE || global.ntype > NODE_MAX) {
|
||||||
|
printf("'-n' range is [1-5], default is 0\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else if (strcmp(argv[i], "-C") == 0) {
|
||||||
|
global.dumpConfig = true;
|
||||||
|
} else if (strcmp(argv[i], "-V") == 0) {
|
||||||
|
global.printVersion = true;
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dndGenerateGrant() {
|
||||||
|
// grantParseParameter();
|
||||||
|
printf("this feature is not implemented yet\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dndPrintVersion() {
|
||||||
|
#ifdef TD_ENTERPRISE
|
||||||
|
char *releaseName = "enterprise";
|
||||||
|
#else
|
||||||
|
char *releaseName = "community";
|
||||||
|
#endif
|
||||||
|
printf("%s version: %s compatible_version: %s\n", releaseName, version, compatible_version);
|
||||||
|
printf("gitinfo: %s\n", gitinfo);
|
||||||
|
printf("buildInfo: %s\n", buildinfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dndDumpCfg() {
|
||||||
|
SConfig *pCfg = taosGetCfg();
|
||||||
|
cfgDumpCfg(pCfg, 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static SDnodeOpt dndGetOpt() {
|
||||||
|
SConfig *pCfg = taosGetCfg();
|
||||||
|
SDnodeOpt option = {0};
|
||||||
|
|
||||||
|
option.numOfSupportVnodes = cfgGetItem(pCfg, "supportVnodes")->i32;
|
||||||
|
tstrncpy(option.dataDir, tsDataDir, sizeof(option.dataDir));
|
||||||
|
tstrncpy(option.firstEp, tsFirst, sizeof(option.firstEp));
|
||||||
|
tstrncpy(option.secondEp, tsSecond, sizeof(option.firstEp));
|
||||||
|
option.serverPort = tsServerPort;
|
||||||
|
tstrncpy(option.localFqdn, tsLocalFqdn, sizeof(option.localFqdn));
|
||||||
|
snprintf(option.localEp, sizeof(option.localEp), "%s:%u", option.localFqdn, option.serverPort);
|
||||||
|
option.disks = tsDiskCfg;
|
||||||
|
option.numOfDisks = tsDiskCfgNum;
|
||||||
|
option.ntype = global.ntype;
|
||||||
|
return option;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t dndInitLog() {
|
||||||
|
char logName[12] = {0};
|
||||||
|
snprintf(logName, sizeof(logName), "%slog", dndNodeLogStr(global.ntype));
|
||||||
|
return taosCreateLog(logName, 1, configDir, global.envFile, global.apolloUrl, global.pArgs, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dndSetProcName(char **argv) {
|
||||||
|
if (global.ntype != DNODE) {
|
||||||
|
const char *name = dndNodeProcStr(global.ntype);
|
||||||
|
taosSetProcName(argv, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t dndRunDnode() {
|
||||||
|
if (dndInit() != 0) {
|
||||||
|
dError("failed to initialize environment since %s", terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDnodeOpt option = dndGetOpt();
|
||||||
|
SDnode *pDnode = dndCreate(&option);
|
||||||
|
if (pDnode == NULL) {
|
||||||
|
dError("failed to to create dnode object since %s", terrstr());
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
global.pDnode = pDnode;
|
||||||
|
dndSetSignalHandle();
|
||||||
|
}
|
||||||
|
|
||||||
|
dInfo("start the service");
|
||||||
|
int32_t code = dndRun(pDnode);
|
||||||
|
dInfo("start shutting down the service");
|
||||||
|
|
||||||
|
global.pDnode = NULL;
|
||||||
|
dndClose(pDnode);
|
||||||
|
dndCleanup();
|
||||||
|
taosCloseLog();
|
||||||
|
taosCleanupCfg();
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char const *argv[]) {
|
||||||
|
if (!taosCheckSystemIsSmallEnd()) {
|
||||||
|
printf("failed to start since on non-small-end machines\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dndParseArgs(argc, argv) != 0) {
|
||||||
|
printf("failed to start since parse args error\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (global.generateGrant) {
|
||||||
|
dndGenerateGrant();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (global.printVersion) {
|
||||||
|
dndPrintVersion();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dndInitLog() != 0) {
|
||||||
|
printf("failed to start since init log error\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taosInitCfg(configDir, global.envFile, global.apolloUrl, global.pArgs, 0) != 0) {
|
||||||
|
dError("failed to start since read config error");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (global.dumpConfig) {
|
||||||
|
dndDumpCfg();
|
||||||
|
taosCleanupCfg();
|
||||||
|
taosCloseLog();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
dndSetProcName((char **)argv);
|
||||||
|
return dndRunDnode();
|
||||||
|
}
|
|
@ -33,6 +33,7 @@
|
||||||
#include "tthread.h"
|
#include "tthread.h"
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
#include "tworker.h"
|
#include "tworker.h"
|
||||||
|
#include "tmsgcb.h"
|
||||||
|
|
||||||
#include "dnode.h"
|
#include "dnode.h"
|
||||||
#include "monitor.h"
|
#include "monitor.h"
|
||||||
|
@ -94,12 +95,14 @@ typedef struct SMgmtWrapper {
|
||||||
bool deployed;
|
bool deployed;
|
||||||
bool required;
|
bool required;
|
||||||
EProcType procType;
|
EProcType procType;
|
||||||
|
int32_t procId;
|
||||||
SProcObj *pProc;
|
SProcObj *pProc;
|
||||||
|
SShm shm;
|
||||||
void *pMgmt;
|
void *pMgmt;
|
||||||
SDnode *pDnode;
|
SDnode *pDnode;
|
||||||
NodeMsgFp msgFps[TDMT_MAX];
|
|
||||||
int32_t msgVgIds[TDMT_MAX]; // Handle the case where the same message type is distributed to qnode or vnode
|
|
||||||
SMgmtFp fp;
|
SMgmtFp fp;
|
||||||
|
int8_t msgVgIds[TDMT_MAX]; // Handle the case where the same message type is distributed to qnode or vnode
|
||||||
|
NodeMsgFp msgFps[TDMT_MAX];
|
||||||
} SMgmtWrapper;
|
} SMgmtWrapper;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -118,30 +121,38 @@ typedef struct SDnode {
|
||||||
char *firstEp;
|
char *firstEp;
|
||||||
char *secondEp;
|
char *secondEp;
|
||||||
char *dataDir;
|
char *dataDir;
|
||||||
SDiskCfg *pDisks;
|
SDiskCfg *disks;
|
||||||
int32_t numOfDisks;
|
int32_t numOfDisks;
|
||||||
uint16_t serverPort;
|
uint16_t serverPort;
|
||||||
bool dropped;
|
bool dropped;
|
||||||
|
ENodeType ntype;
|
||||||
EDndStatus status;
|
EDndStatus status;
|
||||||
EDndEvent event;
|
EDndEvent event;
|
||||||
SStartupReq startup;
|
SStartupReq startup;
|
||||||
TdFilePtr pLockFile;
|
TdFilePtr lockfile;
|
||||||
STransMgmt trans;
|
STransMgmt trans;
|
||||||
SMgmtWrapper wrappers[NODE_MAX];
|
SMgmtWrapper wrappers[NODE_MAX];
|
||||||
} SDnode;
|
} SDnode;
|
||||||
|
|
||||||
|
const char *dndNodeLogStr(ENodeType ntype);
|
||||||
|
const char *dndNodeProcStr(ENodeType ntype);
|
||||||
EDndStatus dndGetStatus(SDnode *pDnode);
|
EDndStatus dndGetStatus(SDnode *pDnode);
|
||||||
void dndSetStatus(SDnode *pDnode, EDndStatus stat);
|
void dndSetStatus(SDnode *pDnode, EDndStatus stat);
|
||||||
void dndSetMsgHandle(SMgmtWrapper *pWrapper, int32_t msgType, NodeMsgFp nodeMsgFp, int32_t vgId);
|
void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId);
|
||||||
void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc);
|
void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc);
|
||||||
void dndSendMonitorReport(SDnode *pDnode);
|
void dndSendMonitorReport(SDnode *pDnode);
|
||||||
|
|
||||||
|
int32_t dndInitServer(SDnode *pDnode);
|
||||||
|
void dndCleanupServer(SDnode *pDnode);
|
||||||
|
int32_t dndInitClient(SDnode *pDnode);
|
||||||
|
void dndCleanupClient(SDnode *pDnode);
|
||||||
|
int32_t dndProcessNodeMsg(SDnode *pDnode, SNodeMsg *pMsg);
|
||||||
int32_t dndSendReqToMnode(SMgmtWrapper *pWrapper, SRpcMsg *pMsg);
|
int32_t dndSendReqToMnode(SMgmtWrapper *pWrapper, SRpcMsg *pMsg);
|
||||||
int32_t dndSendReqToDnode(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pMsg);
|
int32_t dndSendReqToDnode(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pMsg);
|
||||||
void dndSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp);
|
void dndSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp);
|
||||||
void dndRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg);
|
void dndRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg);
|
||||||
|
SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper);
|
||||||
|
|
||||||
int32_t dndProcessNodeMsg(SDnode *pDnode, SNodeMsg *pMsg);
|
|
||||||
int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed);
|
int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed);
|
||||||
int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed);
|
int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed);
|
||||||
|
|
|
@ -34,7 +34,6 @@ int32_t dndInit();
|
||||||
void dndCleanup();
|
void dndCleanup();
|
||||||
const char *dndStatStr(EDndStatus stat);
|
const char *dndStatStr(EDndStatus stat);
|
||||||
void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup);
|
void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup);
|
||||||
TdFilePtr dndCheckRunning(const char *dataDir);
|
|
||||||
void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg);
|
void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg);
|
||||||
|
|
||||||
// dndMsg.c
|
// dndMsg.c
|
||||||
|
@ -51,13 +50,14 @@ void dndClose(SDnode *pDnode);
|
||||||
void dndHandleEvent(SDnode *pDnode, EDndEvent event);
|
void dndHandleEvent(SDnode *pDnode, EDndEvent event);
|
||||||
|
|
||||||
// dndTransport.c
|
// dndTransport.c
|
||||||
int32_t dndInitServer(SDnode *pDnode);
|
|
||||||
void dndCleanupServer(SDnode *pDnode);
|
|
||||||
int32_t dndInitClient(SDnode *pDnode);
|
|
||||||
void dndCleanupClient(SDnode *pDnode);
|
|
||||||
int32_t dndInitMsgHandle(SDnode *pDnode);
|
int32_t dndInitMsgHandle(SDnode *pDnode);
|
||||||
void dndSendRpcRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp);
|
void dndSendRpcRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp);
|
||||||
|
|
||||||
|
// dndFile.c
|
||||||
|
TdFilePtr dndCheckRunning(const char *dataDir);
|
||||||
|
int32_t dndReadShmFile(SDnode *pDnode);
|
||||||
|
int32_t dndWriteShmFile(SDnode *pDnode);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
|
@ -1,48 +0,0 @@
|
||||||
|
|
||||||
/*
|
|
||||||
* 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_DND_MAIN_H_
|
|
||||||
#define _TD_DND_MAIN_H_
|
|
||||||
|
|
||||||
#include "dnode.h"
|
|
||||||
|
|
||||||
#include "taoserror.h"
|
|
||||||
#include "tconfig.h"
|
|
||||||
#include "tglobal.h"
|
|
||||||
#include "tlog.h"
|
|
||||||
#include "version.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }}
|
|
||||||
#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }}
|
|
||||||
#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("DND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }}
|
|
||||||
#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("DND ", DEBUG_INFO, 255, __VA_ARGS__); }}
|
|
||||||
#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", DEBUG_DEBUG, dDebugFlag, __VA_ARGS__); }}
|
|
||||||
#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", DEBUG_TRACE, dDebugFlag, __VA_ARGS__); }}
|
|
||||||
|
|
||||||
void dndDumpCfg();
|
|
||||||
void dndPrintVersion();
|
|
||||||
void dndGenerateGrant();
|
|
||||||
SDnodeOpt dndGetOpt();
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*_TD_DND_MAIN_H_*/
|
|
|
@ -0,0 +1,306 @@
|
||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "dndInt.h"
|
||||||
|
|
||||||
|
static bool dndRequireNode(SMgmtWrapper *pWrapper) {
|
||||||
|
bool required = false;
|
||||||
|
int32_t code =(*pWrapper->fp.requiredFp)(pWrapper, &required);
|
||||||
|
if (!required) {
|
||||||
|
dDebug("node:%s, no need to start", pWrapper->name);
|
||||||
|
} else {
|
||||||
|
dDebug("node:%s, need to start", pWrapper->name);
|
||||||
|
}
|
||||||
|
return required;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t dndOpenNode(SMgmtWrapper *pWrapper) {
|
||||||
|
if (taosMkDir(pWrapper->path) != 0) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((*pWrapper->fp.openFp)(pWrapper) != 0) {
|
||||||
|
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dDebug("node:%s, has been opened", pWrapper->name);
|
||||||
|
pWrapper->deployed = true;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dndCloseNode(SMgmtWrapper *pWrapper) {
|
||||||
|
dDebug("node:%s, start to close", pWrapper->name);
|
||||||
|
pWrapper->required = false;
|
||||||
|
taosWLockLatch(&pWrapper->latch);
|
||||||
|
if (pWrapper->deployed) {
|
||||||
|
(*pWrapper->fp.closeFp)(pWrapper);
|
||||||
|
pWrapper->deployed = false;
|
||||||
|
}
|
||||||
|
taosWUnLockLatch(&pWrapper->latch);
|
||||||
|
|
||||||
|
while (pWrapper->refCount > 0) {
|
||||||
|
taosMsleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pWrapper->pProc) {
|
||||||
|
taosProcCleanup(pWrapper->pProc);
|
||||||
|
pWrapper->pProc = NULL;
|
||||||
|
}
|
||||||
|
dDebug("node:%s, has been closed", pWrapper->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t dndRunInSingleProcess(SDnode *pDnode) {
|
||||||
|
dInfo("dnode start to run in single process");
|
||||||
|
|
||||||
|
for (ENodeType n = DNODE; n < NODE_MAX; ++n) {
|
||||||
|
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||||
|
pWrapper->required = dndRequireNode(pWrapper);
|
||||||
|
if (!pWrapper->required) continue;
|
||||||
|
|
||||||
|
if (dndOpenNode(pWrapper) != 0) {
|
||||||
|
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dndSetStatus(pDnode, DND_STAT_RUNNING);
|
||||||
|
|
||||||
|
for (ENodeType n = 0; n < NODE_MAX; ++n) {
|
||||||
|
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||||
|
if (!pWrapper->required) continue;
|
||||||
|
if (pWrapper->fp.startFp == NULL) continue;
|
||||||
|
if ((*pWrapper->fp.startFp)(pWrapper) != 0) {
|
||||||
|
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dInfo("dnode running in single process");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen,
|
||||||
|
ProcFuncType ftype) {
|
||||||
|
SRpcMsg *pRpc = &pMsg->rpcMsg;
|
||||||
|
pRpc->pCont = pCont;
|
||||||
|
dTrace("msg:%p, get from child queue, handle:%p app:%p", pMsg, pRpc->handle, pRpc->ahandle);
|
||||||
|
|
||||||
|
NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pRpc->msgType)];
|
||||||
|
int32_t code = (*msgFp)(pWrapper, pMsg);
|
||||||
|
|
||||||
|
if (code != 0) {
|
||||||
|
dError("msg:%p, failed to process since code:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code));
|
||||||
|
if (pRpc->msgType & 1U) {
|
||||||
|
SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = terrno};
|
||||||
|
dndSendRsp(pWrapper, &rsp);
|
||||||
|
}
|
||||||
|
|
||||||
|
dTrace("msg:%p, is freed", pMsg);
|
||||||
|
taosFreeQitem(pMsg);
|
||||||
|
rpcFreeCont(pCont);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen,
|
||||||
|
ProcFuncType ftype) {
|
||||||
|
pMsg->pCont = pCont;
|
||||||
|
dTrace("msg:%p, get from parent queue, handle:%p app:%p", pMsg, pMsg->handle, pMsg->ahandle);
|
||||||
|
|
||||||
|
switch (ftype) {
|
||||||
|
case PROC_REG:
|
||||||
|
rpcRegisterBrokenLinkArg(pMsg);
|
||||||
|
break;
|
||||||
|
case PROC_RELEASE:
|
||||||
|
rpcReleaseHandle(pMsg->handle, (int8_t)pMsg->code);
|
||||||
|
rpcFreeCont(pCont);
|
||||||
|
break;
|
||||||
|
case PROC_REQ:
|
||||||
|
// todo send to dnode
|
||||||
|
dndSendReqToMnode(pWrapper, pMsg);
|
||||||
|
default:
|
||||||
|
dndSendRpcRsp(pWrapper, pMsg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
taosMemoryFree(pMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t dndRunInParentProcess(SDnode *pDnode) {
|
||||||
|
dInfo("dnode start to run in parent process");
|
||||||
|
SMgmtWrapper *pDWrapper = &pDnode->wrappers[DNODE];
|
||||||
|
if (dndOpenNode(pDWrapper) != 0) {
|
||||||
|
dError("node:%s, failed to start since %s", pDWrapper->name, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ENodeType n = DNODE + 1; n < NODE_MAX; ++n) {
|
||||||
|
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||||
|
pWrapper->required = dndRequireNode(pWrapper);
|
||||||
|
if (!pWrapper->required) continue;
|
||||||
|
|
||||||
|
int64_t shmsize = 1024 * 1024 * 2; // size will be a configuration item
|
||||||
|
if (taosCreateShm(&pWrapper->shm, shmsize) != 0) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(terrno);
|
||||||
|
dError("node:%s, failed to create shm size:%" PRId64 " since %s", pWrapper->name, shmsize, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SProcCfg cfg = {.childConsumeFp = (ProcConsumeFp)dndConsumeChildQueue,
|
||||||
|
.childMallocHeadFp = (ProcMallocFp)taosAllocateQitem,
|
||||||
|
.childFreeHeadFp = (ProcFreeFp)taosFreeQitem,
|
||||||
|
.childMallocBodyFp = (ProcMallocFp)rpcMallocCont,
|
||||||
|
.childFreeBodyFp = (ProcFreeFp)rpcFreeCont,
|
||||||
|
.parentConsumeFp = (ProcConsumeFp)dndConsumeParentQueue,
|
||||||
|
.parentMallocHeadFp = (ProcMallocFp)taosMemoryMalloc,
|
||||||
|
.parentFreeHeadFp = (ProcFreeFp)taosMemoryFree,
|
||||||
|
.parentMallocBodyFp = (ProcMallocFp)rpcMallocCont,
|
||||||
|
.parentFreeBodyFp = (ProcFreeFp)rpcFreeCont,
|
||||||
|
.shm = pWrapper->shm,
|
||||||
|
.pParent = pWrapper,
|
||||||
|
.isChild = false,
|
||||||
|
.name = pWrapper->name};
|
||||||
|
|
||||||
|
pWrapper->procType = PROC_PARENT;
|
||||||
|
pWrapper->pProc = taosProcInit(&cfg);
|
||||||
|
if (pWrapper->pProc == NULL) {
|
||||||
|
dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dndWriteShmFile(pDnode) != 0) {
|
||||||
|
dError("failed to write runtime file since %s", terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ENodeType n = DNODE + 1; n < NODE_MAX; ++n) {
|
||||||
|
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||||
|
if (!pWrapper->required) continue;
|
||||||
|
|
||||||
|
if (pDnode->ntype == NODE_MAX) {
|
||||||
|
dInfo("node:%s, should be started manually", pWrapper->name);
|
||||||
|
} else {
|
||||||
|
char args[PATH_MAX];
|
||||||
|
int32_t pid = taosNewProc(args);
|
||||||
|
if (pid <= 0) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
dError("node:%s, failed to exec in new process since %s", pWrapper->name, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
pWrapper->procId = pid;
|
||||||
|
dInfo("node:%s, run in new process, pid:%d", pWrapper->name, pid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taosProcRun(pWrapper->pProc) != 0) {
|
||||||
|
dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dndSetStatus(pDnode, DND_STAT_RUNNING);
|
||||||
|
|
||||||
|
if ((*pDWrapper->fp.startFp)(pDWrapper) != 0) {
|
||||||
|
dError("node:%s, failed to start since %s", pDWrapper->name, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dInfo("dnode running in parent process");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t dndRunInChildProcess(SDnode *pDnode) {
|
||||||
|
dInfo("dnode start to run in child process");
|
||||||
|
SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype];
|
||||||
|
|
||||||
|
SMsgCb msgCb = dndCreateMsgcb(pWrapper);
|
||||||
|
tmsgSetDefaultMsgCb(&msgCb);
|
||||||
|
pWrapper->procType = PROC_CHILD;
|
||||||
|
|
||||||
|
if (dndOpenNode(pWrapper) != 0) {
|
||||||
|
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SProcCfg cfg = {.childConsumeFp = (ProcConsumeFp)dndConsumeChildQueue,
|
||||||
|
.childMallocHeadFp = (ProcMallocFp)taosAllocateQitem,
|
||||||
|
.childFreeHeadFp = (ProcFreeFp)taosFreeQitem,
|
||||||
|
.childMallocBodyFp = (ProcMallocFp)rpcMallocCont,
|
||||||
|
.childFreeBodyFp = (ProcFreeFp)rpcFreeCont,
|
||||||
|
.parentConsumeFp = (ProcConsumeFp)dndConsumeParentQueue,
|
||||||
|
.parentMallocHeadFp = (ProcMallocFp)taosMemoryMalloc,
|
||||||
|
.parentFreeHeadFp = (ProcFreeFp)taosMemoryFree,
|
||||||
|
.parentMallocBodyFp = (ProcMallocFp)rpcMallocCont,
|
||||||
|
.parentFreeBodyFp = (ProcFreeFp)rpcFreeCont,
|
||||||
|
.shm = pWrapper->shm,
|
||||||
|
.pParent = pWrapper,
|
||||||
|
.isChild = true,
|
||||||
|
.name = pWrapper->name};
|
||||||
|
|
||||||
|
pWrapper->pProc = taosProcInit(&cfg);
|
||||||
|
if (pWrapper->pProc == NULL) {
|
||||||
|
dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pWrapper->fp.startFp != NULL) {
|
||||||
|
if ((*pWrapper->fp.startFp)(pWrapper) != 0) {
|
||||||
|
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taosProcRun(pWrapper->pProc) != 0) {
|
||||||
|
dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dInfo("dnode running in child process");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t dndRun(SDnode * pDnode) {
|
||||||
|
if (!tsMultiProcess) {
|
||||||
|
if (dndRunInSingleProcess(pDnode) != 0) {
|
||||||
|
dError("failed to run dnode since %s", terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else if (pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) {
|
||||||
|
if (dndRunInParentProcess(pDnode) != 0) {
|
||||||
|
dError("failed to run dnode in parent process since %s", terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (dndRunInChildProcess(pDnode) != 0) {
|
||||||
|
dError("failed to run dnode in child process since %s", terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dndReportStartup(pDnode, "TDengine", "initialized successfully");
|
||||||
|
dInfo("TDengine initialized successfully");
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
if (pDnode->event == DND_EVENT_STOP) {
|
||||||
|
dInfo("dnode is about to stop");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
taosMsleep(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,269 @@
|
||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "dndInt.h"
|
||||||
|
|
||||||
|
#define MAXLEN 1024
|
||||||
|
|
||||||
|
int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed) {
|
||||||
|
int32_t code = TSDB_CODE_NODE_PARSE_FILE_ERROR;
|
||||||
|
int64_t len = 0;
|
||||||
|
char content[MAXLEN + 1] = {0};
|
||||||
|
cJSON *root = NULL;
|
||||||
|
char file[PATH_MAX];
|
||||||
|
TdFilePtr pFile = NULL;
|
||||||
|
|
||||||
|
snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name);
|
||||||
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
|
if (pFile == NULL) {
|
||||||
|
dDebug("file %s not exist", file);
|
||||||
|
code = 0;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = taosReadFile(pFile, content, MAXLEN);
|
||||||
|
if (len <= 0) {
|
||||||
|
dError("failed to read %s since content is null", file);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
root = cJSON_Parse(content);
|
||||||
|
if (root == NULL) {
|
||||||
|
dError("failed to read %s since invalid json format", file);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON *deployed = cJSON_GetObjectItem(root, "deployed");
|
||||||
|
if (!deployed || deployed->type != cJSON_Number) {
|
||||||
|
dError("failed to read %s since deployed not found", file);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
*pDeployed = deployed->valueint != 0;
|
||||||
|
|
||||||
|
dDebug("succcessed to read file %s, deployed:%d", file, *pDeployed);
|
||||||
|
code = 0;
|
||||||
|
|
||||||
|
_OVER:
|
||||||
|
if (root != NULL) cJSON_Delete(root);
|
||||||
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
|
||||||
|
terrno = code;
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed) {
|
||||||
|
int32_t code = -1;
|
||||||
|
int32_t len = 0;
|
||||||
|
char content[MAXLEN + 1] = {0};
|
||||||
|
char file[PATH_MAX] = {0};
|
||||||
|
char realfile[PATH_MAX] = {0};
|
||||||
|
TdFilePtr pFile = NULL;
|
||||||
|
|
||||||
|
snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name);
|
||||||
|
snprintf(realfile, sizeof(realfile), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name);
|
||||||
|
|
||||||
|
pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
|
if (pFile == NULL) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
dError("failed to write %s since %s", file, terrstr());
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
len += snprintf(content + len, MAXLEN - len, "{\n");
|
||||||
|
len += snprintf(content + len, MAXLEN - len, " \"deployed\": %d\n", deployed);
|
||||||
|
len += snprintf(content + len, MAXLEN - len, "}\n");
|
||||||
|
|
||||||
|
if (taosWriteFile(pFile, content, len) != len) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
dError("failed to write file:%s since %s", file, terrstr());
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taosFsyncFile(pFile) != 0) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
dError("failed to fsync file:%s since %s", file, terrstr());
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
taosCloseFile(&pFile);
|
||||||
|
|
||||||
|
if (taosRenameFile(file, realfile) != 0) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
dError("failed to rename %s since %s", file, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dInfo("successed to write %s, deployed:%d", realfile, deployed);
|
||||||
|
code = 0;
|
||||||
|
|
||||||
|
_OVER:
|
||||||
|
if (pFile != NULL) {
|
||||||
|
taosCloseFile(&pFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
TdFilePtr dndCheckRunning(const char *dataDir) {
|
||||||
|
char filepath[PATH_MAX] = {0};
|
||||||
|
snprintf(filepath, sizeof(filepath), "%s%s.running", dataDir, TD_DIRSEP);
|
||||||
|
|
||||||
|
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
|
if (pFile == NULL) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
dError("failed to lock file:%s since %s", filepath, terrstr());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t ret = taosLockFile(pFile);
|
||||||
|
if (ret != 0) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
dError("failed to lock file:%s since %s", filepath, terrstr());
|
||||||
|
taosCloseFile(&pFile);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
dDebug("file:%s is locked", filepath);
|
||||||
|
return pFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t dndReadShmFile(SDnode *pDnode) {
|
||||||
|
int32_t code = -1;
|
||||||
|
char itemName[24] = {0};
|
||||||
|
char content[MAXLEN + 1] = {0};
|
||||||
|
char file[PATH_MAX] = {0};
|
||||||
|
cJSON *root = NULL;
|
||||||
|
TdFilePtr pFile = NULL;
|
||||||
|
|
||||||
|
snprintf(file, sizeof(file), "%s%s.shmfile", pDnode->dataDir, TD_DIRSEP);
|
||||||
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
|
if (pFile == NULL) {
|
||||||
|
dDebug("file %s not exist", file);
|
||||||
|
code = 0;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taosReadFile(pFile, content, MAXLEN) > 0) {
|
||||||
|
root = cJSON_Parse(content);
|
||||||
|
if (root == NULL) {
|
||||||
|
terrno = TSDB_CODE_NODE_PARSE_FILE_ERROR;
|
||||||
|
dError("failed to read %s since invalid json format", file);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ENodeType ntype = DNODE + 1; ntype < NODE_MAX; ++ntype) {
|
||||||
|
snprintf(itemName, sizeof(itemName), "%s_shmid", dndNodeProcStr(ntype));
|
||||||
|
cJSON *shmid = cJSON_GetObjectItem(root, itemName);
|
||||||
|
if (shmid && shmid->type == cJSON_Number) {
|
||||||
|
pDnode->wrappers[ntype].shm.id = shmid->valueint;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(itemName, sizeof(itemName), "%s_shmsize", dndNodeProcStr(ntype));
|
||||||
|
cJSON *shmsize = cJSON_GetObjectItem(root, itemName);
|
||||||
|
if (shmsize && shmsize->type == cJSON_Number) {
|
||||||
|
pDnode->wrappers[ntype].shm.size = shmsize->valueint;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tsMultiProcess || pDnode->ntype == DNODE || pDnode->ntype == DNODE) {
|
||||||
|
for (ENodeType ntype = DNODE; ntype < NODE_MAX; ++ntype) {
|
||||||
|
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
|
||||||
|
if (pWrapper->shm.id >= 0) {
|
||||||
|
dDebug("shmid:%d, is closed, size:%d", pWrapper->shm.id, pWrapper->shm.size);
|
||||||
|
taosDropShm(&pWrapper->shm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype];
|
||||||
|
if (taosAttachShm(&pWrapper->shm) != 0) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
dError("shmid:%d, failed to attach shm since %s", pWrapper->shm.id, terrstr());
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
dDebug("shmid:%d, is attached, size:%d", pWrapper->shm.id, pWrapper->shm.size);
|
||||||
|
}
|
||||||
|
|
||||||
|
dDebug("successed to open %s", file);
|
||||||
|
code = 0;
|
||||||
|
|
||||||
|
_OVER:
|
||||||
|
if (root != NULL) cJSON_Delete(root);
|
||||||
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t dndWriteShmFile(SDnode *pDnode) {
|
||||||
|
int32_t code = -1;
|
||||||
|
int32_t len = 0;
|
||||||
|
char content[MAXLEN + 1] = {0};
|
||||||
|
char file[PATH_MAX] = {0};
|
||||||
|
char realfile[PATH_MAX] = {0};
|
||||||
|
TdFilePtr pFile = NULL;
|
||||||
|
|
||||||
|
snprintf(file, sizeof(file), "%s%s.shmfile.bak", pDnode->dataDir, TD_DIRSEP);
|
||||||
|
snprintf(realfile, sizeof(realfile), "%s%s.shmfile", pDnode->dataDir, TD_DIRSEP);
|
||||||
|
|
||||||
|
pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
|
if (pFile == NULL) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
dError("failed to open file:%s since %s", file, terrstr());
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
len += snprintf(content + len, MAXLEN - len, "{\n");
|
||||||
|
for (ENodeType ntype = DNODE + 1; ntype < NODE_MAX; ++ntype) {
|
||||||
|
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
|
||||||
|
len += snprintf(content + len, MAXLEN - len, " \"%s_shmid\":%d,\n", dndNodeProcStr(ntype), pWrapper->shm.id);
|
||||||
|
if (ntype == NODE_MAX - 1) {
|
||||||
|
len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d\n", dndNodeProcStr(ntype), pWrapper->shm.size);
|
||||||
|
} else {
|
||||||
|
len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d,\n", dndNodeProcStr(ntype), pWrapper->shm.size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
len += snprintf(content + len, MAXLEN - len, "}\n");
|
||||||
|
|
||||||
|
if (taosWriteFile(pFile, content, len) != len) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
dError("failed to write file:%s since %s", file, terrstr());
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taosFsyncFile(pFile) != 0) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
dError("failed to fsync file:%s since %s", file, terrstr());
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
taosCloseFile(&pFile);
|
||||||
|
|
||||||
|
if (taosRenameFile(file, realfile) != 0) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
dError("failed to rename %s to %s since %s", file, realfile, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dInfo("successed to write %s", realfile);
|
||||||
|
code = 0;
|
||||||
|
|
||||||
|
_OVER:
|
||||||
|
if (pFile != NULL) {
|
||||||
|
taosCloseFile(&pFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
|
@ -20,7 +20,7 @@
|
||||||
static int8_t once = DND_ENV_INIT;
|
static int8_t once = DND_ENV_INIT;
|
||||||
|
|
||||||
int32_t dndInit() {
|
int32_t dndInit() {
|
||||||
dInfo("start to init dnode env");
|
dDebug("start to init dnode env");
|
||||||
if (atomic_val_compare_exchange_8(&once, DND_ENV_INIT, DND_ENV_READY) != DND_ENV_INIT) {
|
if (atomic_val_compare_exchange_8(&once, DND_ENV_INIT, DND_ENV_READY) != DND_ENV_INIT) {
|
||||||
terrno = TSDB_CODE_REPEAT_INIT;
|
terrno = TSDB_CODE_REPEAT_INIT;
|
||||||
dError("failed to init dnode env since %s", terrstr());
|
dError("failed to init dnode env since %s", terrstr());
|
||||||
|
@ -31,12 +31,6 @@ int32_t dndInit() {
|
||||||
taosBlockSIGPIPE();
|
taosBlockSIGPIPE();
|
||||||
taosResolveCRC();
|
taosResolveCRC();
|
||||||
|
|
||||||
if (rpcInit() != 0) {
|
|
||||||
dError("failed to init rpc since %s", terrstr());
|
|
||||||
dndCleanup();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SMonCfg monCfg = {0};
|
SMonCfg monCfg = {0};
|
||||||
monCfg.maxLogs = tsMonitorMaxLogs;
|
monCfg.maxLogs = tsMonitorMaxLogs;
|
||||||
monCfg.port = tsMonitorPort;
|
monCfg.port = tsMonitorPort;
|
||||||
|
@ -44,7 +38,6 @@ int32_t dndInit() {
|
||||||
monCfg.comp = tsMonitorComp;
|
monCfg.comp = tsMonitorComp;
|
||||||
if (monInit(&monCfg) != 0) {
|
if (monInit(&monCfg) != 0) {
|
||||||
dError("failed to init monitor since %s", terrstr());
|
dError("failed to init monitor since %s", terrstr());
|
||||||
dndCleanup();
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,20 +46,19 @@ int32_t dndInit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void dndCleanup() {
|
void dndCleanup() {
|
||||||
dInfo("start to cleanup dnode env");
|
dDebug("start to cleanup dnode env");
|
||||||
if (atomic_val_compare_exchange_8(&once, DND_ENV_READY, DND_ENV_CLEANUP) != DND_ENV_READY) {
|
if (atomic_val_compare_exchange_8(&once, DND_ENV_READY, DND_ENV_CLEANUP) != DND_ENV_READY) {
|
||||||
dError("dnode env is already cleaned up");
|
dError("dnode env is already cleaned up");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
monCleanup();
|
monCleanup();
|
||||||
rpcCleanup();
|
|
||||||
walCleanUp();
|
walCleanUp();
|
||||||
taosStopCacheRefreshWorker();
|
taosStopCacheRefreshWorker();
|
||||||
dInfo("dnode env is cleaned up");
|
dInfo("dnode env is cleaned up");
|
||||||
}
|
}
|
||||||
|
|
||||||
void dndSetMsgHandle(SMgmtWrapper *pWrapper, int32_t msgType, NodeMsgFp nodeMsgFp, int32_t vgId) {
|
void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId) {
|
||||||
pWrapper->msgFps[TMSG_INDEX(msgType)] = nodeMsgFp;
|
pWrapper->msgFps[TMSG_INDEX(msgType)] = nodeMsgFp;
|
||||||
pWrapper->msgVgIds[TMSG_INDEX(msgType)] = vgId;
|
pWrapper->msgVgIds[TMSG_INDEX(msgType)] = vgId;
|
||||||
}
|
}
|
||||||
|
@ -80,19 +72,6 @@ void dndSetStatus(SDnode *pDnode, EDndStatus status) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *dndStatStr(EDndStatus status) {
|
|
||||||
switch (status) {
|
|
||||||
case DND_STAT_INIT:
|
|
||||||
return "init";
|
|
||||||
case DND_STAT_RUNNING:
|
|
||||||
return "running";
|
|
||||||
case DND_STAT_STOPPED:
|
|
||||||
return "stopped";
|
|
||||||
default:
|
|
||||||
return "unknown";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc) {
|
void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc) {
|
||||||
SStartupReq *pStartup = &pDnode->startup;
|
SStartupReq *pStartup = &pDnode->startup;
|
||||||
tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN);
|
tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN);
|
||||||
|
@ -105,29 +84,6 @@ void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup) {
|
||||||
pStartup->finished = (dndGetStatus(pDnode) == DND_STAT_RUNNING);
|
pStartup->finished = (dndGetStatus(pDnode) == DND_STAT_RUNNING);
|
||||||
}
|
}
|
||||||
|
|
||||||
TdFilePtr dndCheckRunning(const char *dataDir) {
|
|
||||||
char filepath[PATH_MAX] = {0};
|
|
||||||
snprintf(filepath, sizeof(filepath), "%s/.running", dataDir);
|
|
||||||
|
|
||||||
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
|
||||||
if (pFile == NULL) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
dError("failed to lock file:%s since %s", filepath, terrstr());
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t ret = taosLockFile(pFile);
|
|
||||||
if (ret != 0) {
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
dError("failed to lock file:%s since %s", filepath, terrstr());
|
|
||||||
taosCloseFile(&pFile);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
dDebug("file:%s is locked", filepath);
|
|
||||||
return pFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) {
|
void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||||
dDebug("startup req is received");
|
dDebug("startup req is received");
|
||||||
SStartupReq *pStartup = rpcMallocCont(sizeof(SStartupReq));
|
SStartupReq *pStartup = rpcMallocCont(sizeof(SStartupReq));
|
|
@ -1,138 +0,0 @@
|
||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
|
||||||
#include "dndMain.h"
|
|
||||||
|
|
||||||
static struct {
|
|
||||||
bool dumpConfig;
|
|
||||||
bool generateGrant;
|
|
||||||
bool printAuth;
|
|
||||||
bool printVersion;
|
|
||||||
char envFile[PATH_MAX];
|
|
||||||
char apolloUrl[PATH_MAX];
|
|
||||||
SDnode *pDnode;
|
|
||||||
} global = {0};
|
|
||||||
|
|
||||||
static void dndSigintHandle(int signum, void *info, void *ctx) {
|
|
||||||
dInfo("signal:%d is received", signum);
|
|
||||||
SDnode *pDnode = atomic_val_compare_exchange_ptr(&global.pDnode, 0, global.pDnode);
|
|
||||||
if (pDnode != NULL) {
|
|
||||||
dndHandleEvent(pDnode, DND_EVENT_STOP);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dndSetSignalHandle() {
|
|
||||||
taosSetSignal(SIGTERM, dndSigintHandle);
|
|
||||||
taosSetSignal(SIGHUP, dndSigintHandle);
|
|
||||||
taosSetSignal(SIGINT, dndSigintHandle);
|
|
||||||
taosSetSignal(SIGABRT, dndSigintHandle);
|
|
||||||
taosSetSignal(SIGBREAK, dndSigintHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t dndParseOption(int32_t argc, char const *argv[]) {
|
|
||||||
for (int32_t i = 1; i < argc; ++i) {
|
|
||||||
if (strcmp(argv[i], "-c") == 0) {
|
|
||||||
if (i < argc - 1) {
|
|
||||||
if (strlen(argv[++i]) >= PATH_MAX) {
|
|
||||||
printf("config file path overflow");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
tstrncpy(configDir, argv[i], PATH_MAX);
|
|
||||||
} else {
|
|
||||||
printf("'-c' requires a parameter, default is %s\n", configDir);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else if (strcmp(argv[i], "-C") == 0) {
|
|
||||||
global.dumpConfig = true;
|
|
||||||
} else if (strcmp(argv[i], "-k") == 0) {
|
|
||||||
global.generateGrant = true;
|
|
||||||
} else if (strcmp(argv[i], "-V") == 0) {
|
|
||||||
global.printVersion = true;
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t dndRunDnode() {
|
|
||||||
if (dndInit() != 0) {
|
|
||||||
dInfo("failed to initialize dnode environment since %s", terrstr());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDnodeOpt option = dndGetOpt();
|
|
||||||
|
|
||||||
SDnode *pDnode = dndCreate(&option);
|
|
||||||
if (pDnode == NULL) {
|
|
||||||
dError("failed to to create dnode object since %s", terrstr());
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
global.pDnode = pDnode;
|
|
||||||
dndSetSignalHandle();
|
|
||||||
}
|
|
||||||
|
|
||||||
dInfo("start the TDengine service");
|
|
||||||
int32_t code = dndRun(pDnode);
|
|
||||||
dInfo("start shutting down the TDengine service");
|
|
||||||
|
|
||||||
global.pDnode = NULL;
|
|
||||||
dndClose(pDnode);
|
|
||||||
dndCleanup();
|
|
||||||
taosCloseLog();
|
|
||||||
taosCleanupCfg();
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char const *argv[]) {
|
|
||||||
if (!taosCheckSystemIsSmallEnd()) {
|
|
||||||
dError("failed to start TDengine since on non-small-end machines");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dndParseOption(argc, argv) != 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (global.generateGrant) {
|
|
||||||
dndGenerateGrant();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (global.printVersion) {
|
|
||||||
dndPrintVersion();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (taosCreateLog("taosdlog", 1, configDir, global.envFile, global.apolloUrl, NULL, 0) != 0) {
|
|
||||||
dError("failed to start TDengine since read log config error");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (taosInitCfg(configDir, global.envFile, global.apolloUrl, NULL, 0) != 0) {
|
|
||||||
dError("failed to start TDengine since read config error");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (global.dumpConfig) {
|
|
||||||
dndDumpCfg();
|
|
||||||
taosCleanupCfg();
|
|
||||||
taosCloseLog();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return dndRunDnode();
|
|
||||||
}
|
|
|
@ -16,7 +16,7 @@
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "dndInt.h"
|
#include "dndInt.h"
|
||||||
|
|
||||||
static int32_t dndInitMemory(SDnode *pDnode, const SDnodeOpt *pOption) {
|
static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) {
|
||||||
pDnode->numOfSupportVnodes = pOption->numOfSupportVnodes;
|
pDnode->numOfSupportVnodes = pOption->numOfSupportVnodes;
|
||||||
pDnode->serverPort = pOption->serverPort;
|
pDnode->serverPort = pOption->serverPort;
|
||||||
pDnode->dataDir = strdup(pOption->dataDir);
|
pDnode->dataDir = strdup(pOption->dataDir);
|
||||||
|
@ -24,8 +24,9 @@ static int32_t dndInitMemory(SDnode *pDnode, const SDnodeOpt *pOption) {
|
||||||
pDnode->localFqdn = strdup(pOption->localFqdn);
|
pDnode->localFqdn = strdup(pOption->localFqdn);
|
||||||
pDnode->firstEp = strdup(pOption->firstEp);
|
pDnode->firstEp = strdup(pOption->firstEp);
|
||||||
pDnode->secondEp = strdup(pOption->secondEp);
|
pDnode->secondEp = strdup(pOption->secondEp);
|
||||||
pDnode->pDisks = pOption->pDisks;
|
pDnode->disks = pOption->disks;
|
||||||
pDnode->numOfDisks = pOption->numOfDisks;
|
pDnode->numOfDisks = pOption->numOfDisks;
|
||||||
|
pDnode->ntype = pOption->ntype;
|
||||||
pDnode->rebootTime = taosGetTimestampMs();
|
pDnode->rebootTime = taosGetTimestampMs();
|
||||||
|
|
||||||
if (pDnode->dataDir == NULL || pDnode->localEp == NULL || pDnode->localFqdn == NULL || pDnode->firstEp == NULL ||
|
if (pDnode->dataDir == NULL || pDnode->localEp == NULL || pDnode->localFqdn == NULL || pDnode->firstEp == NULL ||
|
||||||
|
@ -33,18 +34,26 @@ static int32_t dndInitMemory(SDnode *pDnode, const SDnodeOpt *pOption) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!tsMultiProcess || pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) {
|
||||||
|
pDnode->lockfile = dndCheckRunning(pDnode->dataDir);
|
||||||
|
if (pDnode->lockfile == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dndClearMemory(SDnode *pDnode) {
|
static void dndClearVars(SDnode *pDnode) {
|
||||||
for (ENodeType n = 0; n < NODE_MAX; ++n) {
|
for (ENodeType n = 0; n < NODE_MAX; ++n) {
|
||||||
SMgmtWrapper *pMgmt = &pDnode->wrappers[n];
|
SMgmtWrapper *pMgmt = &pDnode->wrappers[n];
|
||||||
taosMemoryFreeClear(pMgmt->path);
|
taosMemoryFreeClear(pMgmt->path);
|
||||||
}
|
}
|
||||||
if (pDnode->pLockFile != NULL) {
|
if (pDnode->lockfile != NULL) {
|
||||||
taosUnLockFile(pDnode->pLockFile);
|
taosUnLockFile(pDnode->lockfile);
|
||||||
taosCloseFile(&pDnode->pLockFile);
|
taosCloseFile(&pDnode->lockfile);
|
||||||
pDnode->pLockFile = NULL;
|
pDnode->lockfile = NULL;
|
||||||
}
|
}
|
||||||
taosMemoryFreeClear(pDnode->localEp);
|
taosMemoryFreeClear(pDnode->localEp);
|
||||||
taosMemoryFreeClear(pDnode->localFqdn);
|
taosMemoryFreeClear(pDnode->localFqdn);
|
||||||
|
@ -56,7 +65,7 @@ static void dndClearMemory(SDnode *pDnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SDnode *dndCreate(const SDnodeOpt *pOption) {
|
SDnode *dndCreate(const SDnodeOpt *pOption) {
|
||||||
dInfo("start to create dnode object");
|
dDebug("start to create dnode object");
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
char path[PATH_MAX] = {0};
|
char path[PATH_MAX] = {0};
|
||||||
SDnode *pDnode = NULL;
|
SDnode *pDnode = NULL;
|
||||||
|
@ -67,26 +76,12 @@ SDnode *dndCreate(const SDnodeOpt *pOption) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dndInitMemory(pDnode, pOption) != 0) {
|
if (dndInitVars(pDnode, pOption) != 0) {
|
||||||
|
dError("failed to init variables since %s", terrstr());
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
dndSetStatus(pDnode, DND_STAT_INIT);
|
dndSetStatus(pDnode, DND_STAT_INIT);
|
||||||
pDnode->pLockFile = dndCheckRunning(pDnode->dataDir);
|
|
||||||
if (pDnode->pLockFile == NULL) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dndInitServer(pDnode) != 0) {
|
|
||||||
dError("failed to init trans server since %s", terrstr());
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dndInitClient(pDnode) != 0) {
|
|
||||||
dError("failed to init trans client since %s", terrstr());
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
dmGetMgmtFp(&pDnode->wrappers[DNODE]);
|
dmGetMgmtFp(&pDnode->wrappers[DNODE]);
|
||||||
mmGetMgmtFp(&pDnode->wrappers[MNODE]);
|
mmGetMgmtFp(&pDnode->wrappers[MNODE]);
|
||||||
vmGetMgmtFp(&pDnode->wrappers[VNODES]);
|
vmGetMgmtFp(&pDnode->wrappers[VNODES]);
|
||||||
|
@ -94,14 +89,11 @@ SDnode *dndCreate(const SDnodeOpt *pOption) {
|
||||||
smGetMgmtFp(&pDnode->wrappers[SNODE]);
|
smGetMgmtFp(&pDnode->wrappers[SNODE]);
|
||||||
bmGetMgmtFp(&pDnode->wrappers[BNODE]);
|
bmGetMgmtFp(&pDnode->wrappers[BNODE]);
|
||||||
|
|
||||||
if (dndInitMsgHandle(pDnode) != 0) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ENodeType n = 0; n < NODE_MAX; ++n) {
|
for (ENodeType n = 0; n < NODE_MAX; ++n) {
|
||||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||||
snprintf(path, sizeof(path), "%s%s%s", pDnode->dataDir, TD_DIRSEP, pWrapper->name);
|
snprintf(path, sizeof(path), "%s%s%s", pDnode->dataDir, TD_DIRSEP, pWrapper->name);
|
||||||
pWrapper->path = strdup(path);
|
pWrapper->path = strdup(path);
|
||||||
|
pWrapper->shm.id = -1;
|
||||||
pWrapper->pDnode = pDnode;
|
pWrapper->pDnode = pDnode;
|
||||||
if (pWrapper->path == NULL) {
|
if (pWrapper->path == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -112,15 +104,27 @@ SDnode *dndCreate(const SDnodeOpt *pOption) {
|
||||||
taosInitRWLatch(&pWrapper->latch);
|
taosInitRWLatch(&pWrapper->latch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dndInitMsgHandle(pDnode) != 0) {
|
||||||
|
dError("failed to msg handles since %s", terrstr());
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dndReadShmFile(pDnode) != 0) {
|
||||||
|
dError("failed to read shm file since %s", terrstr());
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
SMsgCb msgCb = dndCreateMsgcb(&pDnode->wrappers[0]);
|
||||||
|
tmsgSetDefaultMsgCb(&msgCb);
|
||||||
|
|
||||||
|
dInfo("dnode object is created, data:%p", pDnode);
|
||||||
code = 0;
|
code = 0;
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
if (code != 0 && pDnode) {
|
if (code != 0 && pDnode) {
|
||||||
dndClearMemory(pDnode);
|
dndClearVars(pDnode);
|
||||||
pDnode = NULL;
|
pDnode = NULL;
|
||||||
dError("failed to create dnode object since %s", terrstr());
|
dError("failed to create dnode object since %s", terrstr());
|
||||||
} else {
|
|
||||||
dInfo("dnode object is created, data:%p", pDnode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return pDnode;
|
return pDnode;
|
||||||
|
@ -137,15 +141,12 @@ void dndClose(SDnode *pDnode) {
|
||||||
dInfo("start to close dnode, data:%p", pDnode);
|
dInfo("start to close dnode, data:%p", pDnode);
|
||||||
dndSetStatus(pDnode, DND_STAT_STOPPED);
|
dndSetStatus(pDnode, DND_STAT_STOPPED);
|
||||||
|
|
||||||
dndCleanupServer(pDnode);
|
|
||||||
dndCleanupClient(pDnode);
|
|
||||||
|
|
||||||
for (ENodeType n = 0; n < NODE_MAX; ++n) {
|
for (ENodeType n = 0; n < NODE_MAX; ++n) {
|
||||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||||
dndCloseNode(pWrapper);
|
dndCloseNode(pWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
dndClearMemory(pDnode);
|
dndClearVars(pDnode);
|
||||||
dInfo("dnode object is closed, data:%p", pDnode);
|
dInfo("dnode object is closed, data:%p", pDnode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "dndInt.h"
|
||||||
|
|
||||||
|
const char *dndStatStr(EDndStatus status) {
|
||||||
|
switch (status) {
|
||||||
|
case DND_STAT_INIT:
|
||||||
|
return "init";
|
||||||
|
case DND_STAT_RUNNING:
|
||||||
|
return "running";
|
||||||
|
case DND_STAT_STOPPED:
|
||||||
|
return "stopped";
|
||||||
|
default:
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *dndNodeLogStr(ENodeType ntype) {
|
||||||
|
switch (ntype) {
|
||||||
|
case VNODES:
|
||||||
|
return "vnode";
|
||||||
|
case QNODE:
|
||||||
|
return "qnode";
|
||||||
|
case SNODE:
|
||||||
|
return "snode";
|
||||||
|
case MNODE:
|
||||||
|
return "mnode";
|
||||||
|
case BNODE:
|
||||||
|
return "bnode";
|
||||||
|
default:
|
||||||
|
return "taosd";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *dndNodeProcStr(ENodeType ntype) {
|
||||||
|
switch (ntype) {
|
||||||
|
case VNODES:
|
||||||
|
return "taosv";
|
||||||
|
case QNODE:
|
||||||
|
return "taosq";
|
||||||
|
case SNODE:
|
||||||
|
return "taoss";
|
||||||
|
case MNODE:
|
||||||
|
return "taosm";
|
||||||
|
case BNODE:
|
||||||
|
return "taosb";
|
||||||
|
default:
|
||||||
|
return "taosd";
|
||||||
|
}
|
||||||
|
}
|
|
@ -320,8 +320,7 @@ static int32_t dndSendRpcReq(STransMgmt *pMgmt, const SEpSet *pEpSet, SRpcMsg *p
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dndSendReqToDnode(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pReq) {
|
int32_t dndSendReqToDnode(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pReq) {
|
||||||
if (pWrapper->procType == PROC_CHILD) {
|
if (pWrapper->procType != PROC_CHILD) {
|
||||||
} else {
|
|
||||||
SDnode *pDnode = pWrapper->pDnode;
|
SDnode *pDnode = pWrapper->pDnode;
|
||||||
if (dndGetStatus(pDnode) != DND_STAT_RUNNING) {
|
if (dndGetStatus(pDnode) != DND_STAT_RUNNING) {
|
||||||
terrno = TSDB_CODE_DND_OFFLINE;
|
terrno = TSDB_CODE_DND_OFFLINE;
|
||||||
|
@ -329,24 +328,25 @@ int32_t dndSendReqToDnode(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return dndSendRpcReq(&pDnode->trans, pEpSet, pReq);
|
return dndSendRpcReq(&pDnode->trans, pEpSet, pReq);
|
||||||
|
} else {
|
||||||
|
while (taosProcPutToParentQ(pWrapper->pProc, pReq, sizeof(SRpcMsg), pReq->pCont, pReq->contLen, PROC_REQ) != 0) {
|
||||||
|
taosMsleep(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dndSendReqToMnode(SMgmtWrapper *pWrapper, SRpcMsg *pReq) {
|
int32_t dndSendReqToMnode(SMgmtWrapper *pWrapper, SRpcMsg *pReq) {
|
||||||
if (pWrapper->procType == PROC_CHILD) {
|
|
||||||
} else {
|
|
||||||
SDnode *pDnode = pWrapper->pDnode;
|
SDnode *pDnode = pWrapper->pDnode;
|
||||||
STransMgmt *pTrans = &pDnode->trans;
|
STransMgmt *pTrans = &pDnode->trans;
|
||||||
SEpSet epSet = {0};
|
SEpSet epSet = {0};
|
||||||
|
|
||||||
SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, DNODE);
|
SMgmtWrapper *pWrapper2 = dndAcquireWrapper(pDnode, DNODE);
|
||||||
if (pWrapper != NULL) {
|
if (pWrapper2 != NULL) {
|
||||||
dmGetMnodeEpSet(pWrapper->pMgmt, &epSet);
|
dmGetMnodeEpSet(pWrapper2->pMgmt, &epSet);
|
||||||
dndReleaseWrapper(pWrapper);
|
dndReleaseWrapper(pWrapper2);
|
||||||
}
|
}
|
||||||
return dndSendRpcReq(pTrans, &epSet, pReq);
|
return dndSendRpcReq(pTrans, &epSet, pReq);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void dndSendRpcRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) {
|
void dndSendRpcRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) {
|
||||||
if (pRsp->code == TSDB_CODE_APP_NOT_READY) {
|
if (pRsp->code == TSDB_CODE_APP_NOT_READY) {
|
||||||
|
@ -363,29 +363,44 @@ void dndSendRpcRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void dndSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) {
|
void dndSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) {
|
||||||
if (pWrapper->procType == PROC_CHILD) {
|
if (pWrapper->procType != PROC_CHILD) {
|
||||||
int32_t code = -1;
|
|
||||||
do {
|
|
||||||
code = taosProcPutToParentQ(pWrapper->pProc, pRsp, sizeof(SRpcMsg), pRsp->pCont, pRsp->contLen, PROC_RSP);
|
|
||||||
if (code != 0) {
|
|
||||||
taosMsleep(10);
|
|
||||||
}
|
|
||||||
} while (code != 0);
|
|
||||||
} else {
|
|
||||||
dndSendRpcRsp(pWrapper, pRsp);
|
dndSendRpcRsp(pWrapper, pRsp);
|
||||||
|
} else {
|
||||||
|
while (taosProcPutToParentQ(pWrapper->pProc, pRsp, sizeof(SRpcMsg), pRsp->pCont, pRsp->contLen, PROC_RSP) != 0) {
|
||||||
|
taosMsleep(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dndRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) {
|
void dndRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) {
|
||||||
if (pWrapper->procType == PROC_CHILD) {
|
if (pWrapper->procType != PROC_CHILD) {
|
||||||
int32_t code = -1;
|
|
||||||
do {
|
|
||||||
code = taosProcPutToParentQ(pWrapper->pProc, pMsg, sizeof(SRpcMsg), pMsg->pCont, pMsg->contLen, PROC_REGISTER);
|
|
||||||
if (code != 0) {
|
|
||||||
taosMsleep(10);
|
|
||||||
}
|
|
||||||
} while (code != 0);
|
|
||||||
} else {
|
|
||||||
rpcRegisterBrokenLinkArg(pMsg);
|
rpcRegisterBrokenLinkArg(pMsg);
|
||||||
|
} else {
|
||||||
|
while (taosProcPutToParentQ(pWrapper->pProc, pMsg, sizeof(SRpcMsg), pMsg->pCont, pMsg->contLen, PROC_REG) != 0) {
|
||||||
|
taosMsleep(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dndReleaseHandle(SMgmtWrapper *pWrapper, void *handle, int8_t type) {
|
||||||
|
if (pWrapper->procType != PROC_CHILD) {
|
||||||
|
rpcReleaseHandle(handle, type);
|
||||||
|
} else {
|
||||||
|
SRpcMsg msg = {.handle = handle, .code = type};
|
||||||
|
while (taosProcPutToParentQ(pWrapper->pProc, &msg, sizeof(SRpcMsg), NULL, 0, PROC_RELEASE) != 0) {
|
||||||
|
taosMsleep(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper) {
|
||||||
|
SMsgCb msgCb = {
|
||||||
|
.pWrapper = pWrapper,
|
||||||
|
.registerBrokenLinkArgFp = dndRegisterBrokenLinkArg,
|
||||||
|
.releaseHandleFp = dndReleaseHandle,
|
||||||
|
.sendMnodeReqFp = dndSendReqToMnode,
|
||||||
|
.sendReqFp = dndSendReqToDnode,
|
||||||
|
.sendRspFp = dndSendRsp,
|
||||||
|
};
|
||||||
|
return msgCb;
|
||||||
|
}
|
|
@ -1,55 +0,0 @@
|
||||||
/*
|
|
||||||
* 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
|
||||||
#include "dndMain.h"
|
|
||||||
|
|
||||||
void dndGenerateGrant() {
|
|
||||||
#if 0
|
|
||||||
grantParseParameter();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void dndPrintVersion() {
|
|
||||||
#ifdef TD_ENTERPRISE
|
|
||||||
char *releaseName = "enterprise";
|
|
||||||
#else
|
|
||||||
char *releaseName = "community";
|
|
||||||
#endif
|
|
||||||
printf("%s version: %s compatible_version: %s\n", releaseName, version, compatible_version);
|
|
||||||
printf("gitinfo: %s\n", gitinfo);
|
|
||||||
printf("builuInfo: %s\n", buildinfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
void dndDumpCfg() {
|
|
||||||
SConfig *pCfg = taosGetCfg();
|
|
||||||
cfgDumpCfg(pCfg, 0, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
SDnodeOpt dndGetOpt() {
|
|
||||||
SConfig *pCfg = taosGetCfg();
|
|
||||||
SDnodeOpt option = {0};
|
|
||||||
|
|
||||||
option.numOfSupportVnodes = cfgGetItem(pCfg, "supportVnodes")->i32;
|
|
||||||
tstrncpy(option.dataDir, tsDataDir, sizeof(option.dataDir));
|
|
||||||
tstrncpy(option.firstEp, tsFirst, sizeof(option.firstEp));
|
|
||||||
tstrncpy(option.secondEp, tsSecond, sizeof(option.firstEp));
|
|
||||||
option.serverPort = tsServerPort;
|
|
||||||
tstrncpy(option.localFqdn, tsLocalFqdn, sizeof(option.localFqdn));
|
|
||||||
snprintf(option.localEp, sizeof(option.localEp), "%s:%u", option.localFqdn, option.serverPort);
|
|
||||||
option.pDisks = tsDiskCfg;
|
|
||||||
option.numOfDisks = tsDiskCfgNum;
|
|
||||||
return option;
|
|
||||||
}
|
|
|
@ -285,7 +285,7 @@ static int32_t vmInit(SMgmtWrapper *pWrapper) {
|
||||||
tstrncpy(dCfg.dir, pDnode->dataDir, TSDB_FILENAME_LEN);
|
tstrncpy(dCfg.dir, pDnode->dataDir, TSDB_FILENAME_LEN);
|
||||||
dCfg.level = 0;
|
dCfg.level = 0;
|
||||||
dCfg.primary = 1;
|
dCfg.primary = 1;
|
||||||
SDiskCfg *pDisks = pDnode->pDisks;
|
SDiskCfg *pDisks = pDnode->disks;
|
||||||
int32_t numOfDisks = pDnode->numOfDisks;
|
int32_t numOfDisks = pDnode->numOfDisks;
|
||||||
if (numOfDisks <= 0 || pDisks == NULL) {
|
if (numOfDisks <= 0 || pDisks == NULL) {
|
||||||
pDisks = &dCfg;
|
pDisks = &dCfg;
|
|
@ -76,7 +76,7 @@ static void vmProcessFetchQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) {
|
||||||
SVnodeObj *pVnode = pInfo->ahandle;
|
SVnodeObj *pVnode = pInfo->ahandle;
|
||||||
|
|
||||||
dTrace("msg:%p, will be processed in vnode-fetch queue", pMsg);
|
dTrace("msg:%p, will be processed in vnode-fetch queue", pMsg);
|
||||||
int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, &pMsg->rpcMsg);
|
int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, &pMsg->rpcMsg, pInfo);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
vmSendRsp(pVnode->pWrapper, pMsg, code);
|
vmSendRsp(pVnode->pWrapper, pMsg, code);
|
||||||
dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code));
|
dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code));
|
||||||
|
@ -168,7 +168,7 @@ static void vmProcessMergeQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO
|
||||||
taosGetQitem(qall, (void **)&pMsg);
|
taosGetQitem(qall, (void **)&pMsg);
|
||||||
|
|
||||||
dTrace("msg:%p, will be processed in vnode-merge queue", pMsg);
|
dTrace("msg:%p, will be processed in vnode-merge queue", pMsg);
|
||||||
int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, &pMsg->rpcMsg);
|
int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, &pMsg->rpcMsg, pInfo);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
vmSendRsp(pVnode->pWrapper, pMsg, code);
|
vmSendRsp(pVnode->pWrapper, pMsg, code);
|
||||||
dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code));
|
dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code));
|
||||||
|
@ -414,8 +414,7 @@ int32_t vmStartWorker(SVnodesMgmt *pMgmt) {
|
||||||
pWPool->max = maxMergeThreads;
|
pWPool->max = maxMergeThreads;
|
||||||
if (tWWorkerInit(pWPool) != 0) return -1;
|
if (tWWorkerInit(pWPool) != 0) return -1;
|
||||||
|
|
||||||
SSingleWorkerCfg cfg = {
|
SSingleWorkerCfg cfg = {.min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
|
||||||
.min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
|
|
||||||
if (tSingleWorkerInit(&pMgmt->mgmtWorker, &cfg) != 0) {
|
if (tSingleWorkerInit(&pMgmt->mgmtWorker, &cfg) != 0) {
|
||||||
dError("failed to start vnode-mgmt worker since %s", terrstr());
|
dError("failed to start vnode-mgmt worker since %s", terrstr());
|
||||||
return -1;
|
return -1;
|
|
@ -20,7 +20,8 @@
|
||||||
#define SYSTABLE_SCH_DB_NAME_LEN ((TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
|
#define SYSTABLE_SCH_DB_NAME_LEN ((TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
|
||||||
|
|
||||||
//!!!! Note: only APPEND columns in below tables, NO insert !!!!
|
//!!!! Note: only APPEND columns in below tables, NO insert !!!!
|
||||||
static const SInfosTableSchema dnodesSchema[] = {{.name = "id", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT},
|
static const SInfosTableSchema dnodesSchema[] = {
|
||||||
|
{.name = "id", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT},
|
||||||
{.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
{.name = "vnodes", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT},
|
{.name = "vnodes", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT},
|
||||||
{.name = "max_vnodes", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT},
|
{.name = "max_vnodes", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT},
|
||||||
|
@ -28,21 +29,25 @@ static const SInfosTableSchema dnodesSchema[] = {{.name = "id", .byt
|
||||||
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
||||||
{.name = "note", .bytes = 256 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "note", .bytes = 256 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
};
|
};
|
||||||
static const SInfosTableSchema mnodesSchema[] = {{.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
static const SInfosTableSchema mnodesSchema[] = {
|
||||||
|
{.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||||
{.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
{.name = "role", .bytes = 12 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "role", .bytes = 12 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
{.name = "role_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
{.name = "role_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
||||||
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
||||||
};
|
};
|
||||||
static const SInfosTableSchema modulesSchema[] = {{.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
static const SInfosTableSchema modulesSchema[] = {
|
||||||
|
{.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||||
{.name = "endpoint", .bytes = 134, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "endpoint", .bytes = 134, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
{.name = "module", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "module", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
};
|
};
|
||||||
static const SInfosTableSchema qnodesSchema[] = {{.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
static const SInfosTableSchema qnodesSchema[] = {
|
||||||
|
{.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||||
{.name = "endpoint", .bytes = 134, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "endpoint", .bytes = 134, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
||||||
};
|
};
|
||||||
static const SInfosTableSchema userDBSchema[] = {{.name = "name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
static const SInfosTableSchema userDBSchema[] = {
|
||||||
|
{.name = "name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
||||||
{.name = "vgroups", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT},
|
{.name = "vgroups", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT},
|
||||||
{.name = "ntables", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT},
|
{.name = "ntables", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT},
|
||||||
|
@ -59,15 +64,18 @@ static const SInfosTableSchema userDBSchema[] = {{.name = "name", .b
|
||||||
{.name = "comp", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT},
|
{.name = "comp", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT},
|
||||||
{.name = "cachelast", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT},
|
{.name = "cachelast", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT},
|
||||||
{.name = "precision", .bytes = 3 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "precision", .bytes = 3 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
// {.name = "update", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, // disable update
|
// {.name = "update", .bytes = 1, .type =
|
||||||
|
// TSDB_DATA_TYPE_TINYINT}, // disable update
|
||||||
};
|
};
|
||||||
static const SInfosTableSchema userFuncSchema[] = {{.name = "name", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY},
|
static const SInfosTableSchema userFuncSchema[] = {
|
||||||
|
{.name = "name", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
||||||
{.name = "ntables", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
{.name = "ntables", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||||
{.name = "precision", .bytes = 2, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "precision", .bytes = 2, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
{.name = "status", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "status", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
};
|
};
|
||||||
static const SInfosTableSchema userIdxSchema[] = {{.name = "db_name", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY},
|
static const SInfosTableSchema userIdxSchema[] = {
|
||||||
|
{.name = "db_name", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
{.name = "table_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "table_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
{.name = "index_database", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "index_database", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
{.name = "index_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "index_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
|
@ -75,7 +83,8 @@ static const SInfosTableSchema userIdxSchema[] = {{.name = "db_name", .
|
||||||
{.name = "index_type", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "index_type", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
{.name = "index_extensions", .bytes = 256, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "index_extensions", .bytes = 256, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
};
|
};
|
||||||
static const SInfosTableSchema userStbsSchema[] = {{.name = "stable_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
static const SInfosTableSchema userStbsSchema[] = {
|
||||||
|
{.name = "stable_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
{.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
||||||
{.name = "columns", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
{.name = "columns", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||||
|
@ -84,7 +93,8 @@ static const SInfosTableSchema userStbsSchema[] = {{.name = "stable_name", .
|
||||||
{.name = "last_update", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
{.name = "last_update", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
||||||
{.name = "table_comment", .bytes = 1024 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_INT},
|
{.name = "table_comment", .bytes = 1024 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_INT},
|
||||||
};
|
};
|
||||||
static const SInfosTableSchema userStreamsSchema[] = {{.name = "stream_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
static const SInfosTableSchema userStreamsSchema[] = {
|
||||||
|
{.name = "stream_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
{.name = "user_name", .bytes = 23, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "user_name", .bytes = 23, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
{.name = "dest_table", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "dest_table", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
||||||
|
@ -101,7 +111,8 @@ static const SInfosTableSchema userTblsSchema[] = {
|
||||||
{.name = "ttl", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
{.name = "ttl", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||||
{.name = "table_comment", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
{.name = "table_comment", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||||
};
|
};
|
||||||
static const SInfosTableSchema userTblDistSchema[] = {{.name = "db_name", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY},
|
static const SInfosTableSchema userTblDistSchema[] = {
|
||||||
|
{.name = "db_name", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
{.name = "table_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "table_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
{.name = "distributed_histogram", .bytes = 500, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "distributed_histogram", .bytes = 500, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
{.name = "min_of_rows", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
{.name = "min_of_rows", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||||
|
@ -115,12 +126,14 @@ static const SInfosTableSchema userTblDistSchema[] = {{.name = "db_name",
|
||||||
{.name = "rows_in_mem", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
{.name = "rows_in_mem", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||||
{.name = "seek_header_time", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
{.name = "seek_header_time", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||||
};
|
};
|
||||||
static const SInfosTableSchema userUsersSchema[] = {{.name = "name", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
static const SInfosTableSchema userUsersSchema[] = {
|
||||||
|
{.name = "name", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
{.name = "privilege", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "privilege", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
||||||
{.name = "account", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "account", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
};
|
};
|
||||||
static const SInfosTableSchema vgroupsSchema[] = {{.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
static const SInfosTableSchema vgroupsSchema[] = {
|
||||||
|
{.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||||
{.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
{.name = "tables", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
{.name = "tables", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||||
{.name = "status", .bytes = 12 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
{.name = "status", .bytes = 12 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
|
@ -136,7 +149,34 @@ static const SInfosTableSchema vgroupsSchema[] = {{.name = "vgroup_id", .
|
||||||
{.name = "file_size", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
{.name = "file_size", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const SInfosTableMeta infosMeta[] = {{TSDB_INS_TABLE_DNODES, dnodesSchema, tListLen(dnodesSchema)},
|
// TODO put into perf schema
|
||||||
|
static const SInfosTableSchema topicSchema[] = {
|
||||||
|
{.name = "topic_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
|
{.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
|
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
||||||
|
{.name = "sql", .bytes = 1024, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
|
{.name = "row_len", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||||
|
};
|
||||||
|
|
||||||
|
static const SInfosTableSchema consumerSchema[] = {
|
||||||
|
{.name = "client_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
|
{.name = "group_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
|
{.name = "pid", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||||
|
{.name = "status", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||||
|
// ep
|
||||||
|
// up time
|
||||||
|
// topics
|
||||||
|
};
|
||||||
|
|
||||||
|
static const SInfosTableSchema subscribeSchema[] = {
|
||||||
|
{.name = "topic_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
|
{.name = "group_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
|
{.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||||
|
{.name = "client_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||||
|
};
|
||||||
|
|
||||||
|
static const SInfosTableMeta infosMeta[] = {
|
||||||
|
{TSDB_INS_TABLE_DNODES, dnodesSchema, tListLen(dnodesSchema)},
|
||||||
{TSDB_INS_TABLE_MNODES, mnodesSchema, tListLen(mnodesSchema)},
|
{TSDB_INS_TABLE_MNODES, mnodesSchema, tListLen(mnodesSchema)},
|
||||||
{TSDB_INS_TABLE_MODULES, modulesSchema, tListLen(modulesSchema)},
|
{TSDB_INS_TABLE_MODULES, modulesSchema, tListLen(modulesSchema)},
|
||||||
{TSDB_INS_TABLE_QNODES, qnodesSchema, tListLen(qnodesSchema)},
|
{TSDB_INS_TABLE_QNODES, qnodesSchema, tListLen(qnodesSchema)},
|
||||||
|
@ -251,5 +291,3 @@ void mndCleanupInfos(SMnode *pMnode) {
|
||||||
pMnode->infosMeta = NULL;
|
pMnode->infosMeta = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -62,8 +62,6 @@ static int32_t mndPersistMqSetConnReq(SMnode *pMnode, STrans *pTrans, const SMqT
|
||||||
|
|
||||||
static int32_t mndPersistRebalanceMsg(SMnode *pMnode, STrans *pTrans, const SMqConsumerEp *pConsumerEp);
|
static int32_t mndPersistRebalanceMsg(SMnode *pMnode, STrans *pTrans, const SMqConsumerEp *pConsumerEp);
|
||||||
|
|
||||||
static int32_t mndInitUnassignedVg(SMnode *pMnode, const SMqTopicObj *pTopic, SMqSubscribeObj *pSub);
|
|
||||||
|
|
||||||
int32_t mndInitSubscribe(SMnode *pMnode) {
|
int32_t mndInitSubscribe(SMnode *pMnode) {
|
||||||
SSdbTable table = {.sdbType = SDB_SUBSCRIBE,
|
SSdbTable table = {.sdbType = SDB_SUBSCRIBE,
|
||||||
.keyType = SDB_KEY_BINARY,
|
.keyType = SDB_KEY_BINARY,
|
||||||
|
@ -98,14 +96,6 @@ static SMqSubscribeObj *mndCreateSubscription(SMnode *pMnode, const SMqTopicObj
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
if (mndInitUnassignedVg(pMnode, pTopic, pSub) < 0) {
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
tDeleteSMqSubscribeObj(pSub);
|
|
||||||
taosMemoryFree(pSub);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
// TODO: disable alter subscribed table
|
// TODO: disable alter subscribed table
|
||||||
return pSub;
|
return pSub;
|
||||||
}
|
}
|
||||||
|
@ -210,45 +200,6 @@ static int32_t mndPersistCancelConnReq(SMnode *pMnode, STrans *pTrans, const SMq
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
static int32_t mndProcessResetOffsetReq(SNodeMsg *pMsg) {
|
|
||||||
SMnode *pMnode = pMsg->pNode;
|
|
||||||
uint8_t *str = pMsg->rpcMsg.pCont;
|
|
||||||
SMqCMResetOffsetReq req;
|
|
||||||
|
|
||||||
SCoder decoder;
|
|
||||||
tCoderInit(&decoder, TD_LITTLE_ENDIAN, str, pMsg->rpcMsg.contLen, TD_DECODER);
|
|
||||||
tDecodeSMqCMResetOffsetReq(&decoder, &req);
|
|
||||||
|
|
||||||
SHashObj *pHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
|
|
||||||
if (pHash == NULL) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < req.num; i++) {
|
|
||||||
SMqOffset *pOffset = &req.offsets[i];
|
|
||||||
SMqVgOffsets *pVgOffset = taosHashGet(pHash, &pOffset->vgId, sizeof(int32_t));
|
|
||||||
if (pVgOffset == NULL) {
|
|
||||||
pVgOffset = taosMemoryMalloc(sizeof(SMqVgOffsets));
|
|
||||||
if (pVgOffset == NULL) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
pVgOffset->offsets = taosArrayInit(0, sizeof(void *));
|
|
||||||
taosArrayPush(pVgOffset->offsets, &pOffset);
|
|
||||||
}
|
|
||||||
taosHashPut(pHash, &pOffset->vgId, sizeof(int32_t), &pVgOffset, sizeof(void *));
|
|
||||||
}
|
|
||||||
|
|
||||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg);
|
|
||||||
if (pTrans == NULL) {
|
|
||||||
mError("mq-reset-offset: failed since %s", terrstr());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int32_t mndProcessGetSubEpReq(SNodeMsg *pMsg) {
|
static int32_t mndProcessGetSubEpReq(SNodeMsg *pMsg) {
|
||||||
SMnode *pMnode = pMsg->pNode;
|
SMnode *pMnode = pMsg->pNode;
|
||||||
SMqCMGetSubEpReq *pReq = (SMqCMGetSubEpReq *)pMsg->rpcMsg.pCont;
|
SMqCMGetSubEpReq *pReq = (SMqCMGetSubEpReq *)pMsg->rpcMsg.pCont;
|
||||||
|
@ -574,251 +525,6 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
for (int32_t j = 0; j < consumerNum; j++) {
|
|
||||||
bool changed = false;
|
|
||||||
bool unfished = false;
|
|
||||||
|
|
||||||
bool canUseLeft = imbalanceSolved < imbalanceVg;
|
|
||||||
bool mustUseLeft = canUseLeft && (imbalanceVg - imbalanceSolved >= consumerNum - j);
|
|
||||||
ASSERT(imbalanceVg - imbalanceSolved <= consumerNum - j);
|
|
||||||
|
|
||||||
int32_t maxVg = vgEachConsumer + canUseLeft;
|
|
||||||
int32_t minVg = vgEachConsumer + mustUseLeft;
|
|
||||||
|
|
||||||
SMqSubConsumer *pSubConsumer = taosArrayGet(pSub->consumers, j);
|
|
||||||
int32_t vgThisConsumerBeforeRb = taosArrayGetSize(pSubConsumer->vgInfo);
|
|
||||||
int32_t vgThisConsumerAfterRb;
|
|
||||||
if (vgThisConsumerBeforeRb > maxVg) {
|
|
||||||
vgThisConsumerAfterRb = maxVg;
|
|
||||||
imbalanceSolved++;
|
|
||||||
changed = true;
|
|
||||||
} else if (vgThisConsumerBeforeRb < minVg) {
|
|
||||||
vgThisConsumerAfterRb = minVg;
|
|
||||||
if (mustUseLeft) imbalanceSolved++;
|
|
||||||
changed = true;
|
|
||||||
} else {
|
|
||||||
vgThisConsumerAfterRb = vgThisConsumerBeforeRb;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vgThisConsumerBeforeRb > vgThisConsumerAfterRb) {
|
|
||||||
while (taosArrayGetSize(pSubConsumer->vgInfo) > vgThisConsumerAfterRb) {
|
|
||||||
// put into unassigned
|
|
||||||
SMqConsumerEp *pConsumerEp = taosArrayPop(pSubConsumer->vgInfo);
|
|
||||||
ASSERT(pConsumerEp != NULL);
|
|
||||||
ASSERT(pConsumerEp->consumerId == pSubConsumer->consumerId);
|
|
||||||
taosArrayPush(unassignedVgStash, pConsumerEp);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (vgThisConsumerBeforeRb < vgThisConsumerAfterRb) {
|
|
||||||
// assign from unassigned
|
|
||||||
while (taosArrayGetSize(pSubConsumer->vgInfo) < vgThisConsumerAfterRb) {
|
|
||||||
// if no unassgined, save j
|
|
||||||
if (taosArrayGetSize(unassignedVgStash) == 0) {
|
|
||||||
taosArrayPush(unassignedConsumerIdx, &j);
|
|
||||||
unfished = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// assign vg to consumer
|
|
||||||
SMqConsumerEp *pConsumerEp = taosArrayPop(unassignedVgStash);
|
|
||||||
ASSERT(pConsumerEp != NULL);
|
|
||||||
pConsumerEp->oldConsumerId = pConsumerEp->consumerId;
|
|
||||||
pConsumerEp->consumerId = pSubConsumer->consumerId;
|
|
||||||
taosArrayPush(pSubConsumer->vgInfo, pConsumerEp);
|
|
||||||
// build msg and persist into trans
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (changed && !unfished) {
|
|
||||||
SMqConsumerObj *pRebConsumer = mndAcquireConsumer(pMnode, pSubConsumer->consumerId);
|
|
||||||
pRebConsumer->epoch++;
|
|
||||||
if (vgThisConsumerAfterRb != 0) {
|
|
||||||
atomic_store_32(&pRebConsumer->status, MQ_CONSUMER_STATUS__ACTIVE);
|
|
||||||
} else {
|
|
||||||
atomic_store_32(&pRebConsumer->status, MQ_CONSUMER_STATUS__IDLE);
|
|
||||||
}
|
|
||||||
SSdbRaw *pConsumerRaw = mndConsumerActionEncode(pRebConsumer);
|
|
||||||
sdbSetRawStatus(pConsumerRaw, SDB_STATUS_READY);
|
|
||||||
mndTransAppendRedolog(pTrans, pConsumerRaw);
|
|
||||||
mndReleaseConsumer(pMnode, pRebConsumer);
|
|
||||||
// TODO: save history
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int32_t j = 0; j < taosArrayGetSize(unassignedConsumerIdx); j++) {
|
|
||||||
bool canUseLeft = imbalanceSolved < imbalanceVg;
|
|
||||||
int32_t consumerIdx = *(int32_t *)taosArrayGet(unassignedConsumerIdx, j);
|
|
||||||
SMqSubConsumer *pSubConsumer = taosArrayGet(pSub->consumers, consumerIdx);
|
|
||||||
if (canUseLeft) imbalanceSolved++;
|
|
||||||
// must use
|
|
||||||
int32_t vgThisConsumerAfterRb = taosArrayGetSize(pSubConsumer->vgInfo) + canUseLeft;
|
|
||||||
while (taosArrayGetSize(pSubConsumer->vgInfo) < vgEachConsumer + canUseLeft) {
|
|
||||||
// assign vg to consumer
|
|
||||||
SMqConsumerEp *pConsumerEp = taosArrayPop(unassignedVgStash);
|
|
||||||
ASSERT(pConsumerEp != NULL);
|
|
||||||
pConsumerEp->oldConsumerId = pConsumerEp->consumerId;
|
|
||||||
pConsumerEp->consumerId = pSubConsumer->consumerId;
|
|
||||||
taosArrayPush(pSubConsumer->vgInfo, pConsumerEp);
|
|
||||||
// build msg and persist into trans
|
|
||||||
}
|
|
||||||
SMqConsumerObj *pRebConsumer = mndAcquireConsumer(pMnode, pSubConsumer->consumerId);
|
|
||||||
pRebConsumer->epoch++;
|
|
||||||
atomic_store_32(&pRebConsumer->status, MQ_CONSUMER_STATUS__ACTIVE);
|
|
||||||
SSdbRaw *pConsumerRaw = mndConsumerActionEncode(pRebConsumer);
|
|
||||||
sdbSetRawStatus(pConsumerRaw, SDB_STATUS_READY);
|
|
||||||
mndTransAppendRedolog(pTrans, pConsumerRaw);
|
|
||||||
mndReleaseConsumer(pMnode, pRebConsumer);
|
|
||||||
// TODO: save history
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
//update consumer status for the subscribption
|
|
||||||
for (int32_t i = 0; i < taosArrayGetSize(pSub->assigned); i++) {
|
|
||||||
SMqConsumerEp *pCEp = taosArrayGet(pSub->assigned, i);
|
|
||||||
int64_t consumerId = pCEp->consumerId;
|
|
||||||
if (pCEp->status != -1) {
|
|
||||||
int32_t consumerHbStatus = atomic_fetch_add_32(&pCEp->consumerHbStatus, 1);
|
|
||||||
if (consumerHbStatus < MND_SUBSCRIBE_REBALANCE_CNT) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// put consumer into lostConsumer
|
|
||||||
SMqConsumerEp* lostConsumer = taosArrayPush(pSub->lostConsumer, pCEp);
|
|
||||||
lostConsumer->qmsg = NULL;
|
|
||||||
// put vg into unassigned
|
|
||||||
taosArrayPush(pSub->unassignedVg, pCEp);
|
|
||||||
// remove from assigned
|
|
||||||
// TODO: swap with last one, reduce size and reset i
|
|
||||||
taosArrayRemove(pSub->assigned, i);
|
|
||||||
// remove from available consumer
|
|
||||||
for (int32_t j = 0; j < taosArrayGetSize(pSub->availConsumer); j++) {
|
|
||||||
if (*(int64_t *)taosArrayGet(pSub->availConsumer, i) == pCEp->consumerId) {
|
|
||||||
taosArrayRemove(pSub->availConsumer, j);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// TODO: acquire consumer, set status to unavail
|
|
||||||
}
|
|
||||||
#if 0
|
|
||||||
SMqConsumerObj* pConsumer = mndAcquireConsumer(pMnode, consumerId);
|
|
||||||
pConsumer->epoch++;
|
|
||||||
printf("current epoch %ld size %ld", pConsumer->epoch, pConsumer->topics->size);
|
|
||||||
SSdbRaw* pRaw = mndConsumerActionEncode(pConsumer);
|
|
||||||
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
|
||||||
sdbWriteNotFree(pMnode->pSdb, pRaw);
|
|
||||||
mndReleaseConsumer(pMnode, pConsumer);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// no available consumer, skip rebalance
|
|
||||||
if (taosArrayGetSize(pSub->availConsumer) == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
taosArrayGet(pSub->availConsumer, 0);
|
|
||||||
// rebalance condition1 : have unassigned vg
|
|
||||||
// assign vg to a consumer, trying to find the least assigned one
|
|
||||||
if ((sz = taosArrayGetSize(pSub->unassignedVg)) > 0) {
|
|
||||||
char *topic = NULL;
|
|
||||||
char *cgroup = NULL;
|
|
||||||
mndSplitSubscribeKey(pSub->key, &topic, &cgroup);
|
|
||||||
|
|
||||||
SMqTopicObj *pTopic = mndAcquireTopic(pMnode, topic);
|
|
||||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg);
|
|
||||||
for (int32_t i = 0; i < sz; i++) {
|
|
||||||
int64_t consumerId = *(int64_t *)taosArrayGet(pSub->availConsumer, pSub->nextConsumerIdx);
|
|
||||||
pSub->nextConsumerIdx = (pSub->nextConsumerIdx + 1) % taosArrayGetSize(pSub->availConsumer);
|
|
||||||
|
|
||||||
SMqConsumerEp *pCEp = taosArrayPop(pSub->unassignedVg);
|
|
||||||
pCEp->oldConsumerId = pCEp->consumerId;
|
|
||||||
pCEp->consumerId = consumerId;
|
|
||||||
taosArrayPush(pSub->assigned, pCEp);
|
|
||||||
|
|
||||||
SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, consumerId);
|
|
||||||
pConsumer->epoch++;
|
|
||||||
SSdbRaw* pConsumerRaw = mndConsumerActionEncode(pConsumer);
|
|
||||||
sdbSetRawStatus(pConsumerRaw, SDB_STATUS_READY);
|
|
||||||
sdbWrite(pMnode->pSdb, pConsumerRaw);
|
|
||||||
mndReleaseConsumer(pMnode, pConsumer);
|
|
||||||
|
|
||||||
void* msg;
|
|
||||||
int32_t msgLen;
|
|
||||||
mndBuildRebalanceMsg(&msg, &msgLen, pTopic, pCEp, cgroup, topic);
|
|
||||||
|
|
||||||
// persist msg
|
|
||||||
STransAction action = {0};
|
|
||||||
action.epSet = pCEp->epSet;
|
|
||||||
action.pCont = msg;
|
|
||||||
action.contLen = sizeof(SMsgHead) + msgLen;
|
|
||||||
action.msgType = TDMT_VND_MQ_SET_CONN;
|
|
||||||
mndTransAppendRedoAction(pTrans, &action);
|
|
||||||
|
|
||||||
// persist data
|
|
||||||
SSdbRaw *pRaw = mndSubActionEncode(pSub);
|
|
||||||
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
|
||||||
mndTransAppendRedolog(pTrans, pRaw);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
|
||||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
|
||||||
}
|
|
||||||
mndReleaseTopic(pMnode, pTopic);
|
|
||||||
mndTransDrop(pTrans);
|
|
||||||
taosMemoryFreeClear(topic);
|
|
||||||
taosMemoryFreeClear(cgroup);
|
|
||||||
}
|
|
||||||
// rebalance condition2 : imbalance assignment
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
static int32_t mndInitUnassignedVg(SMnode *pMnode, const SMqTopicObj *pTopic, SMqSubscribeObj *pSub) {
|
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
|
||||||
SVgObj *pVgroup = NULL;
|
|
||||||
SQueryPlan *pPlan = qStringToQueryPlan(pTopic->physicalPlan);
|
|
||||||
SArray *pArray = NULL;
|
|
||||||
SNodeListNode *inner = (SNodeListNode*)nodesListGetNode(pPlan->pSubplans, 0);
|
|
||||||
SSubplan *plan = (SSubplan*)nodesListGetNode(inner->pNodeList, 0);
|
|
||||||
SArray *unassignedVg = pSub->unassignedVg;
|
|
||||||
|
|
||||||
void *pIter = NULL;
|
|
||||||
while (1) {
|
|
||||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
|
||||||
if (pIter == NULL) break;
|
|
||||||
if (pVgroup->dbUid != pTopic->dbUid) {
|
|
||||||
sdbRelease(pSdb, pVgroup);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
pSub->vgNum++;
|
|
||||||
plan->execNode.nodeId = pVgroup->vgId;
|
|
||||||
plan->execNode.epset = mndGetVgroupEpset(pMnode, pVgroup);
|
|
||||||
|
|
||||||
if (schedulerConvertDagToTaskList(pPlan, &pArray) < 0) {
|
|
||||||
terrno = TSDB_CODE_MND_UNSUPPORTED_TOPIC;
|
|
||||||
mError("unsupport topic: %s, sql: %s", pTopic->name, pTopic->sql);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SMqConsumerEp consumerEp = {0};
|
|
||||||
consumerEp.status = 0;
|
|
||||||
consumerEp.consumerId = -1;
|
|
||||||
STaskInfo *pTaskInfo = taosArrayGet(pArray, 0);
|
|
||||||
consumerEp.epSet = pTaskInfo->addr.epset;
|
|
||||||
consumerEp.vgId = pTaskInfo->addr.nodeId;
|
|
||||||
|
|
||||||
ASSERT(consumerEp.vgId == pVgroup->vgId);
|
|
||||||
consumerEp.qmsg = strdup(pTaskInfo->msg->msg);
|
|
||||||
taosArrayPush(unassignedVg, &consumerEp);
|
|
||||||
// TODO: free taskInfo
|
|
||||||
taosArrayDestroy(pArray);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*qDestroyQueryDag(pDag);*/
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int32_t mndPersistMqSetConnReq(SMnode *pMnode, STrans *pTrans, const SMqTopicObj *pTopic, const char *cgroup,
|
static int32_t mndPersistMqSetConnReq(SMnode *pMnode, STrans *pTrans, const SMqTopicObj *pTopic, const char *cgroup,
|
||||||
const SMqConsumerEp *pConsumerEp) {
|
const SMqConsumerEp *pConsumerEp) {
|
||||||
ASSERT(pConsumerEp->oldConsumerId == -1);
|
ASSERT(pConsumerEp->oldConsumerId == -1);
|
||||||
|
|
|
@ -67,7 +67,9 @@ SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) {
|
||||||
|
|
||||||
int32_t logicalPlanLen = strlen(pTopic->logicalPlan) + 1;
|
int32_t logicalPlanLen = strlen(pTopic->logicalPlan) + 1;
|
||||||
int32_t physicalPlanLen = strlen(pTopic->physicalPlan) + 1;
|
int32_t physicalPlanLen = strlen(pTopic->physicalPlan) + 1;
|
||||||
int32_t size = sizeof(SMqTopicObj) + logicalPlanLen + physicalPlanLen + pTopic->sqlLen + MND_TOPIC_RESERVE_SIZE;
|
int32_t swLen = taosEncodeSSchemaWrapper(NULL, &pTopic->schema);
|
||||||
|
int32_t size =
|
||||||
|
sizeof(SMqTopicObj) + logicalPlanLen + physicalPlanLen + pTopic->sqlLen + swLen + MND_TOPIC_RESERVE_SIZE;
|
||||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_TOPIC, MND_TOPIC_VER_NUMBER, size);
|
SSdbRaw *pRaw = sdbAllocRaw(SDB_TOPIC, MND_TOPIC_VER_NUMBER, size);
|
||||||
if (pRaw == NULL) goto TOPIC_ENCODE_OVER;
|
if (pRaw == NULL) goto TOPIC_ENCODE_OVER;
|
||||||
|
|
||||||
|
@ -86,7 +88,6 @@ SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) {
|
||||||
SDB_SET_INT32(pRaw, dataPos, physicalPlanLen, TOPIC_ENCODE_OVER);
|
SDB_SET_INT32(pRaw, dataPos, physicalPlanLen, TOPIC_ENCODE_OVER);
|
||||||
SDB_SET_BINARY(pRaw, dataPos, pTopic->physicalPlan, physicalPlanLen, TOPIC_ENCODE_OVER);
|
SDB_SET_BINARY(pRaw, dataPos, pTopic->physicalPlan, physicalPlanLen, TOPIC_ENCODE_OVER);
|
||||||
|
|
||||||
int32_t swLen = taosEncodeSSchemaWrapper(NULL, &pTopic->schema);
|
|
||||||
void *swBuf = taosMemoryMalloc(swLen);
|
void *swBuf = taosMemoryMalloc(swLen);
|
||||||
if (swBuf == NULL) {
|
if (swBuf == NULL) {
|
||||||
goto TOPIC_ENCODE_OVER;
|
goto TOPIC_ENCODE_OVER;
|
||||||
|
|
|
@ -771,7 +771,7 @@ static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) {
|
||||||
.ahandle = pTrans->rpcAHandle,
|
.ahandle = pTrans->rpcAHandle,
|
||||||
.pCont = rpcCont,
|
.pCont = rpcCont,
|
||||||
.contLen = pTrans->rpcRspLen};
|
.contLen = pTrans->rpcRspLen};
|
||||||
tmsgSendRsp(&pMnode->msgCb, &rspMsg);
|
tmsgSendRsp(&rspMsg);
|
||||||
pTrans->rpcHandle = NULL;
|
pTrans->rpcHandle = NULL;
|
||||||
pTrans->rpcRsp = NULL;
|
pTrans->rpcRsp = NULL;
|
||||||
pTrans->rpcRspLen = 0;
|
pTrans->rpcRspLen = 0;
|
||||||
|
@ -898,7 +898,7 @@ static int32_t mndTransSendActionMsg(SMnode *pMnode, STrans *pTrans, SArray *pAr
|
||||||
pAction->msgReceived = 0;
|
pAction->msgReceived = 0;
|
||||||
pAction->errCode = 0;
|
pAction->errCode = 0;
|
||||||
} else {
|
} else {
|
||||||
mDebug("trans:%d, action:%d not send since %s", pTrans->id, action, terrstr());
|
mError("trans:%d, action:%d not send since %s", pTrans->id, action, terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -938,7 +938,7 @@ static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pA
|
||||||
return errCode;
|
return errCode;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mDebug("trans:%d, %d of %d actions executed, code:0x%04x", pTrans->id, numOfReceived, numOfActions, errCode & 0XFFFF);
|
mDebug("trans:%d, %d of %d actions executing", pTrans->id, numOfReceived, numOfActions);
|
||||||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,14 +46,11 @@ target_link_libraries(
|
||||||
PUBLIC stream
|
PUBLIC stream
|
||||||
PUBLIC qworker
|
PUBLIC qworker
|
||||||
PUBLIC sync
|
PUBLIC sync
|
||||||
|
# TODO: get rid of BDB
|
||||||
|
PUBLIC bdb
|
||||||
|
PUBLIC tdb
|
||||||
)
|
)
|
||||||
|
|
||||||
if(${META_DB_IMPL} STREQUAL "BDB")
|
|
||||||
target_link_libraries(vnode PUBLIC bdb)
|
|
||||||
elseif(${META_DB_IMPL} STREQUAL "TDB")
|
|
||||||
target_link_libraries(vnode PUBLIC tdb)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(${BUILD_TEST})
|
if(${BUILD_TEST})
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
endif(${BUILD_TEST})
|
endif(${BUILD_TEST})
|
||||||
|
|
|
@ -100,10 +100,11 @@ int32_t tsdbUpdateSmaWindow(STsdb *pTsdb, const char *msg);
|
||||||
* @brief Insert tSma(Time-range-wise SMA) data from stream computing engine
|
* @brief Insert tSma(Time-range-wise SMA) data from stream computing engine
|
||||||
*
|
*
|
||||||
* @param pTsdb
|
* @param pTsdb
|
||||||
|
* @param indexUid
|
||||||
* @param msg
|
* @param msg
|
||||||
* @return int32_t
|
* @return int32_t
|
||||||
*/
|
*/
|
||||||
int32_t tsdbInsertTSmaData(STsdb *pTsdb, char *msg);
|
int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Drop tSma data and local cache.
|
* @brief Drop tSma data and local cache.
|
||||||
|
@ -130,16 +131,11 @@ int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg);
|
||||||
* @param pTsdb
|
* @param pTsdb
|
||||||
* @param pData
|
* @param pData
|
||||||
* @param indexUid
|
* @param indexUid
|
||||||
* @param interval
|
|
||||||
* @param intervalUnit
|
|
||||||
* @param tableUid
|
|
||||||
* @param colId
|
|
||||||
* @param querySKey
|
* @param querySKey
|
||||||
* @param nMaxResult
|
* @param nMaxResult
|
||||||
* @return int32_t
|
* @return int32_t
|
||||||
*/
|
*/
|
||||||
int32_t tsdbGetTSmaData(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval, int8_t intervalUnit,
|
int32_t tsdbGetTSmaData(STsdb *pTsdb, char *pData, int64_t indexUid, TSKEY querySKey, int32_t nMaxResult);
|
||||||
tb_uid_t tableUid, col_id_t colId, TSKEY querySKey, int32_t nMaxResult);
|
|
||||||
|
|
||||||
// STsdbCfg
|
// STsdbCfg
|
||||||
int tsdbOptionsInit(STsdbCfg *);
|
int tsdbOptionsInit(STsdbCfg *);
|
||||||
|
|
|
@ -17,8 +17,9 @@
|
||||||
#define _TD_VNODE_H_
|
#define _TD_VNODE_H_
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "trpc.h"
|
|
||||||
#include "tmsgcb.h"
|
#include "tmsgcb.h"
|
||||||
|
#include "tqueue.h"
|
||||||
|
#include "trpc.h"
|
||||||
|
|
||||||
#include "meta.h"
|
#include "meta.h"
|
||||||
#include "tarray.h"
|
#include "tarray.h"
|
||||||
|
@ -166,7 +167,7 @@ int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg);
|
||||||
* @param pMsg The request message
|
* @param pMsg The request message
|
||||||
* @return int 0 for success, -1 for failure
|
* @return int 0 for success, -1 for failure
|
||||||
*/
|
*/
|
||||||
int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg);
|
int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo);
|
||||||
|
|
||||||
/* ------------------------ SVnodeCfg ------------------------ */
|
/* ------------------------ SVnodeCfg ------------------------ */
|
||||||
/**
|
/**
|
||||||
|
@ -185,7 +186,6 @@ void vnodeOptionsClear(SVnodeCfg *pOptions);
|
||||||
|
|
||||||
int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName);
|
int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName);
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------ FOR COMPILE ------------------------ */
|
/* ------------------------ FOR COMPILE ------------------------ */
|
||||||
|
|
||||||
int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg);
|
int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg);
|
||||||
|
|
|
@ -44,15 +44,14 @@ int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// internal func
|
// internal func
|
||||||
static FORCE_INLINE int32_t tsdbEncodeTSmaKey(tb_uid_t tableUid, col_id_t colId, TSKEY tsKey, void **pData) {
|
static FORCE_INLINE int32_t tsdbEncodeTSmaKey(int64_t groupId, TSKEY tsKey, void **pData) {
|
||||||
int32_t len = 0;
|
int32_t len = 0;
|
||||||
len += taosEncodeFixedI64(pData, tableUid);
|
|
||||||
len += taosEncodeFixedU16(pData, colId);
|
|
||||||
len += taosEncodeFixedI64(pData, tsKey);
|
len += taosEncodeFixedI64(pData, tsKey);
|
||||||
|
len += taosEncodeFixedI64(pData, groupId);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tsdbRLockSma(SSmaEnv *pEnv) {
|
static FORCE_INLINE int32_t tsdbRLockSma(SSmaEnv *pEnv) {
|
||||||
int code = taosThreadRwlockRdlock(&(pEnv->lock));
|
int code = taosThreadRwlockRdlock(&(pEnv->lock));
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
terrno = TAOS_SYSTEM_ERROR(code);
|
||||||
|
@ -61,7 +60,7 @@ static FORCE_INLINE int tsdbRLockSma(SSmaEnv *pEnv) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tsdbWLockSma(SSmaEnv *pEnv) {
|
static FORCE_INLINE int32_t tsdbWLockSma(SSmaEnv *pEnv) {
|
||||||
int code = taosThreadRwlockWrlock(&(pEnv->lock));
|
int code = taosThreadRwlockWrlock(&(pEnv->lock));
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
terrno = TAOS_SYSTEM_ERROR(code);
|
||||||
|
@ -70,7 +69,7 @@ static FORCE_INLINE int tsdbWLockSma(SSmaEnv *pEnv) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tsdbUnLockSma(SSmaEnv *pEnv) {
|
static FORCE_INLINE int32_t tsdbUnLockSma(SSmaEnv *pEnv) {
|
||||||
int code = taosThreadRwlockUnlock(&(pEnv->lock));
|
int code = taosThreadRwlockUnlock(&(pEnv->lock));
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
terrno = TAOS_SYSTEM_ERROR(code);
|
||||||
|
|
|
@ -197,9 +197,9 @@ int tqCommit(STQ*);
|
||||||
int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg);
|
int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg);
|
||||||
int32_t tqProcessSetConnReq(STQ* pTq, char* msg);
|
int32_t tqProcessSetConnReq(STQ* pTq, char* msg);
|
||||||
int32_t tqProcessRebReq(STQ* pTq, char* msg);
|
int32_t tqProcessRebReq(STQ* pTq, char* msg);
|
||||||
int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen);
|
int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen, int32_t workerId);
|
||||||
int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen);
|
int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen);
|
||||||
int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen);
|
int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen, int32_t workerId);
|
||||||
|
|
||||||
// sma
|
// sma
|
||||||
void smaHandleRes(void* pVnode, int64_t smaId, const SArray* data);
|
void smaHandleRes(void* pVnode, int64_t smaId, const SArray* data);
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#include "metaDef.h"
|
#include "metaDef.h"
|
||||||
|
|
||||||
#include "tdb.h"
|
#include "tdbInt.h"
|
||||||
|
|
||||||
struct SMetaDB {
|
struct SMetaDB {
|
||||||
TENV *pEnv;
|
TENV *pEnv;
|
||||||
|
@ -25,121 +25,627 @@ struct SMetaDB {
|
||||||
TDB *pStbIdx;
|
TDB *pStbIdx;
|
||||||
TDB *pNtbIdx;
|
TDB *pNtbIdx;
|
||||||
TDB *pCtbIdx;
|
TDB *pCtbIdx;
|
||||||
// tag index hash table
|
|
||||||
// suid+colid --> TDB *
|
|
||||||
struct {
|
|
||||||
} tagIdxHt;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define A(op, flag) \
|
typedef struct __attribute__((__packed__)) {
|
||||||
do { \
|
tb_uid_t uid;
|
||||||
if ((ret = op) != 0) goto flag; \
|
int32_t sver;
|
||||||
} while (0)
|
} SSchemaDbKey;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *name;
|
||||||
|
tb_uid_t uid;
|
||||||
|
} SNameIdxKey;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
tb_uid_t suid;
|
||||||
|
tb_uid_t uid;
|
||||||
|
} SCtbIdxKey;
|
||||||
|
|
||||||
|
static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg);
|
||||||
|
static void *metaDecodeTbInfo(void *buf, STbCfg *pTbCfg);
|
||||||
|
static int metaEncodeSchema(void **buf, SSchemaWrapper *pSW);
|
||||||
|
static void *metaDecodeSchema(void *buf, SSchemaWrapper *pSW);
|
||||||
|
|
||||||
|
static inline int metaUidCmpr(const void *arg1, int len1, const void *arg2, int len2) {
|
||||||
|
tb_uid_t uid1, uid2;
|
||||||
|
|
||||||
|
ASSERT(len1 == sizeof(tb_uid_t));
|
||||||
|
ASSERT(len2 == sizeof(tb_uid_t));
|
||||||
|
|
||||||
|
uid1 = ((tb_uid_t *)arg1)[0];
|
||||||
|
uid2 = ((tb_uid_t *)arg2)[0];
|
||||||
|
|
||||||
|
if (uid1 < uid2) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (uid1 == uid2) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int metaSchemaKeyCmpr(const void *arg1, int len1, const void *arg2, int len2) {
|
||||||
|
int c;
|
||||||
|
SSchemaDbKey *pKey1 = (SSchemaDbKey *)arg1;
|
||||||
|
SSchemaDbKey *pKey2 = (SSchemaDbKey *)arg2;
|
||||||
|
|
||||||
|
c = metaUidCmpr(arg1, sizeof(tb_uid_t), arg2, sizeof(tb_uid_t));
|
||||||
|
if (c) return c;
|
||||||
|
|
||||||
|
if (pKey1->sver > pKey2->sver) {
|
||||||
|
return 1;
|
||||||
|
} else if (pKey1->sver == pKey2->sver) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int metaNameIdxCmpr(const void *arg1, int len1, const void *arg2, int len2) {
|
||||||
|
return strcmp((char *)arg1, (char *)arg2);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int metaCtbIdxCmpr(const void *arg1, int len1, const void *arg2, int len2) {
|
||||||
|
int c;
|
||||||
|
SCtbIdxKey *pKey1 = (SCtbIdxKey *)arg1;
|
||||||
|
SCtbIdxKey *pKey2 = (SCtbIdxKey *)arg2;
|
||||||
|
|
||||||
|
c = metaUidCmpr(arg1, sizeof(tb_uid_t), arg2, sizeof(tb_uid_t));
|
||||||
|
if (c) return c;
|
||||||
|
|
||||||
|
return metaUidCmpr(&pKey1->uid, sizeof(tb_uid_t), &pKey2->uid, sizeof(tb_uid_t));
|
||||||
|
}
|
||||||
|
|
||||||
int metaOpenDB(SMeta *pMeta) {
|
int metaOpenDB(SMeta *pMeta) {
|
||||||
SMetaDB *pDb;
|
SMetaDB *pMetaDb;
|
||||||
TENV * pEnv;
|
|
||||||
TDB * pTbDB;
|
|
||||||
TDB * pSchemaDB;
|
|
||||||
TDB * pNameIdx;
|
|
||||||
TDB * pStbIdx;
|
|
||||||
TDB * pNtbIdx;
|
|
||||||
TDB * pCtbIdx;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
pDb = (SMetaDB *)taosMemoryCalloc(1, sizeof(*pDb));
|
// allocate DB handle
|
||||||
if (pDb == NULL) {
|
pMetaDb = taosMemoryCalloc(1, sizeof(*pMetaDb));
|
||||||
|
if (pMetaDb == NULL) {
|
||||||
|
// TODO
|
||||||
|
ASSERT(0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create and open the ENV
|
// open the ENV
|
||||||
A((tdbEnvCreate(&pEnv)), _err);
|
ret = tdbEnvOpen(pMeta->path, 4096, 256, &(pMetaDb->pEnv));
|
||||||
#if 0
|
if (ret < 0) {
|
||||||
// Set options of the environment
|
// TODO
|
||||||
A(tdbEnvSetPageSize(pEnv, 8192), _err);
|
ASSERT(0);
|
||||||
A(tdbEnvSetCacheSize(pEnv, 16 * 1024 * 1024), _err);
|
|
||||||
#endif
|
|
||||||
A((tdbEnvOpen(&pEnv)), _err);
|
|
||||||
|
|
||||||
// Create and open each DB
|
|
||||||
A(tdbCreate(&pTbDB), _err);
|
|
||||||
A(tdbOpen(&pTbDB, "table.db", NULL, pEnv), _err);
|
|
||||||
|
|
||||||
A(tdbCreate(&pSchemaDB), _err);
|
|
||||||
A(tdbOpen(&pSchemaDB, "schema.db", NULL, pEnv), _err);
|
|
||||||
|
|
||||||
A(tdbCreate(&pNameIdx), _err);
|
|
||||||
A(tdbOpen(&pNameIdx, "name.db", NULL, pEnv), _err);
|
|
||||||
// tdbAssociate();
|
|
||||||
|
|
||||||
pDb->pEnv = pEnv;
|
|
||||||
pDb->pTbDB = pTbDB;
|
|
||||||
pDb->pSchemaDB = pSchemaDB;
|
|
||||||
pMeta->pDB = pDb;
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
_err:
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// open table DB
|
||||||
|
ret = tdbDbOpen("table.db", sizeof(tb_uid_t), TDB_VARIANT_LEN, metaUidCmpr, pMetaDb->pEnv, &(pMetaDb->pTbDB));
|
||||||
|
if (ret < 0) {
|
||||||
|
// TODO
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// open schema DB
|
||||||
|
ret = tdbDbOpen("schema.db", sizeof(SSchemaDbKey), TDB_VARIANT_LEN, metaSchemaKeyCmpr, pMetaDb->pEnv,
|
||||||
|
&(pMetaDb->pSchemaDB));
|
||||||
|
if (ret < 0) {
|
||||||
|
// TODO
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = tdbDbOpen("name.idx", TDB_VARIANT_LEN, 0, metaNameIdxCmpr, pMetaDb->pEnv, &(pMetaDb->pNameIdx));
|
||||||
|
if (ret < 0) {
|
||||||
|
// TODO
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = tdbDbOpen("stb.idx", sizeof(tb_uid_t), 0, metaUidCmpr, pMetaDb->pEnv, &(pMetaDb->pStbIdx));
|
||||||
|
if (ret < 0) {
|
||||||
|
// TODO
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = tdbDbOpen("ntb.idx", sizeof(tb_uid_t), 0, metaUidCmpr, pMetaDb->pEnv, &(pMetaDb->pNtbIdx));
|
||||||
|
if (ret < 0) {
|
||||||
|
// TODO
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = tdbDbOpen("ctb.idx", sizeof(SCtbIdxKey), 0, metaCtbIdxCmpr, pMetaDb->pEnv, &(pMetaDb->pCtbIdx));
|
||||||
|
if (ret < 0) {
|
||||||
|
// TODO
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pMeta->pDB = pMetaDb;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void metaCloseDB(SMeta *pMeta) {
|
void metaCloseDB(SMeta *pMeta) {
|
||||||
// TODO
|
if (pMeta->pDB) {
|
||||||
|
tdbDbClose(pMeta->pDB->pCtbIdx);
|
||||||
|
tdbDbClose(pMeta->pDB->pNtbIdx);
|
||||||
|
tdbDbClose(pMeta->pDB->pStbIdx);
|
||||||
|
tdbDbClose(pMeta->pDB->pNameIdx);
|
||||||
|
tdbDbClose(pMeta->pDB->pSchemaDB);
|
||||||
|
tdbDbClose(pMeta->pDB->pTbDB);
|
||||||
|
taosMemoryFree(pMeta->pDB);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) {
|
int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) {
|
||||||
// TODO
|
tb_uid_t uid;
|
||||||
|
SMetaDB *pMetaDb;
|
||||||
|
void *pKey;
|
||||||
|
void *pVal;
|
||||||
|
int kLen;
|
||||||
|
int vLen;
|
||||||
|
int ret;
|
||||||
|
char buf[512];
|
||||||
|
void *pBuf;
|
||||||
|
SCtbIdxKey ctbIdxKey;
|
||||||
|
SSchemaDbKey schemaDbKey;
|
||||||
|
SSchemaWrapper schemaWrapper;
|
||||||
|
|
||||||
|
pMetaDb = pMeta->pDB;
|
||||||
|
|
||||||
|
// TODO: make this operation pre-process
|
||||||
|
if (pTbCfg->type == META_SUPER_TABLE) {
|
||||||
|
uid = pTbCfg->stbCfg.suid;
|
||||||
|
} else {
|
||||||
|
uid = metaGenerateUid(pMeta);
|
||||||
|
}
|
||||||
|
|
||||||
|
// save to table.db
|
||||||
|
pKey = &uid;
|
||||||
|
kLen = sizeof(uid);
|
||||||
|
pVal = pBuf = buf;
|
||||||
|
metaEncodeTbInfo(&pBuf, pTbCfg);
|
||||||
|
vLen = POINTER_DISTANCE(pBuf, buf);
|
||||||
|
ret = tdbDbInsert(pMetaDb->pTbDB, pKey, kLen, pVal, vLen);
|
||||||
|
if (ret < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// save to schema.db for META_SUPER_TABLE and META_NORMAL_TABLE
|
||||||
|
if (pTbCfg->type != META_CHILD_TABLE) {
|
||||||
|
schemaDbKey.uid = uid;
|
||||||
|
schemaDbKey.sver = 0; // TODO
|
||||||
|
pKey = &schemaDbKey;
|
||||||
|
kLen = sizeof(schemaDbKey);
|
||||||
|
|
||||||
|
if (pTbCfg->type == META_SUPER_TABLE) {
|
||||||
|
schemaWrapper.nCols = pTbCfg->stbCfg.nCols;
|
||||||
|
schemaWrapper.pSchema = pTbCfg->stbCfg.pSchema;
|
||||||
|
} else {
|
||||||
|
schemaWrapper.nCols = pTbCfg->ntbCfg.nCols;
|
||||||
|
schemaWrapper.pSchema = pTbCfg->ntbCfg.pSchema;
|
||||||
|
}
|
||||||
|
pVal = pBuf = buf;
|
||||||
|
metaEncodeSchema(&pBuf, &schemaWrapper);
|
||||||
|
vLen = POINTER_DISTANCE(pBuf, buf);
|
||||||
|
ret = tdbDbInsert(pMetaDb->pSchemaDB, pKey, kLen, pVal, vLen);
|
||||||
|
if (ret < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// update name.idx
|
||||||
|
int nameLen = strlen(pTbCfg->name);
|
||||||
|
memcpy(buf, pTbCfg->name, nameLen + 1);
|
||||||
|
((tb_uid_t *)(buf + nameLen + 1))[0] = uid;
|
||||||
|
pKey = buf;
|
||||||
|
kLen = nameLen + 1 + sizeof(uid);
|
||||||
|
pVal = NULL;
|
||||||
|
vLen = 0;
|
||||||
|
ret = tdbDbInsert(pMetaDb->pNameIdx, pKey, kLen, pVal, vLen);
|
||||||
|
if (ret < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// update other index
|
||||||
|
if (pTbCfg->type == META_SUPER_TABLE) {
|
||||||
|
pKey = &uid;
|
||||||
|
kLen = sizeof(uid);
|
||||||
|
pVal = NULL;
|
||||||
|
vLen = 0;
|
||||||
|
ret = tdbDbInsert(pMetaDb->pStbIdx, pKey, kLen, pVal, vLen);
|
||||||
|
if (ret < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else if (pTbCfg->type == META_CHILD_TABLE) {
|
||||||
|
ctbIdxKey.suid = pTbCfg->ctbCfg.suid;
|
||||||
|
ctbIdxKey.uid = uid;
|
||||||
|
pKey = &ctbIdxKey;
|
||||||
|
kLen = sizeof(ctbIdxKey);
|
||||||
|
pVal = NULL;
|
||||||
|
vLen = 0;
|
||||||
|
ret = tdbDbInsert(pMetaDb->pCtbIdx, pKey, kLen, pVal, vLen);
|
||||||
|
if (ret < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else if (pTbCfg->type == META_NORMAL_TABLE) {
|
||||||
|
pKey = &uid;
|
||||||
|
kLen = sizeof(uid);
|
||||||
|
pVal = NULL;
|
||||||
|
vLen = 0;
|
||||||
|
ret = tdbDbInsert(pMetaDb->pNtbIdx, pKey, kLen, pVal, vLen);
|
||||||
|
if (ret < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid) {
|
int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid) {
|
||||||
// TODO
|
// TODO
|
||||||
|
ASSERT(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
STbCfg *metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid) {
|
STbCfg *metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid) {
|
||||||
// TODO
|
int ret;
|
||||||
|
SMetaDB *pMetaDb = pMeta->pDB;
|
||||||
|
void *pKey;
|
||||||
|
void *pVal;
|
||||||
|
int kLen;
|
||||||
|
int vLen;
|
||||||
|
STbCfg *pTbCfg;
|
||||||
|
|
||||||
|
// Fetch
|
||||||
|
pKey = &uid;
|
||||||
|
kLen = sizeof(uid);
|
||||||
|
pVal = NULL;
|
||||||
|
ret = tdbDbGet(pMetaDb->pTbDB, pKey, kLen, &pVal, &vLen);
|
||||||
|
if (ret < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Decode
|
||||||
|
pTbCfg = taosMemoryMalloc(sizeof(*pTbCfg));
|
||||||
|
metaDecodeTbInfo(pVal, pTbCfg);
|
||||||
|
|
||||||
|
TDB_FREE(pVal);
|
||||||
|
|
||||||
|
return pTbCfg;
|
||||||
|
}
|
||||||
|
|
||||||
STbCfg *metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid) {
|
STbCfg *metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid) {
|
||||||
// TODO
|
void *pKey;
|
||||||
|
void *pVal;
|
||||||
|
void *ppKey;
|
||||||
|
int pkLen;
|
||||||
|
int kLen;
|
||||||
|
int vLen;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
pKey = tbname;
|
||||||
|
kLen = strlen(tbname) + 1;
|
||||||
|
pVal = NULL;
|
||||||
|
ppKey = NULL;
|
||||||
|
ret = tdbDbPGet(pMeta->pDB->pNameIdx, pKey, kLen, &ppKey, &pkLen, &pVal, &vLen);
|
||||||
|
if (ret < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ASSERT(pkLen == kLen + sizeof(uid));
|
||||||
|
|
||||||
|
*uid = *(tb_uid_t *)POINTER_SHIFT(ppKey, kLen);
|
||||||
|
TDB_FREE(ppKey);
|
||||||
|
TDB_FREE(pVal);
|
||||||
|
|
||||||
|
return metaGetTbInfoByUid(pMeta, *uid);
|
||||||
|
}
|
||||||
|
|
||||||
SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline) {
|
SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline) {
|
||||||
// TODO
|
void *pKey;
|
||||||
|
void *pVal;
|
||||||
|
int kLen;
|
||||||
|
int vLen;
|
||||||
|
int ret;
|
||||||
|
SSchemaDbKey schemaDbKey;
|
||||||
|
SSchemaWrapper *pSchemaWrapper;
|
||||||
|
void *pBuf;
|
||||||
|
|
||||||
|
// fetch
|
||||||
|
schemaDbKey.uid = uid;
|
||||||
|
schemaDbKey.sver = sver;
|
||||||
|
pKey = &schemaDbKey;
|
||||||
|
kLen = sizeof(schemaDbKey);
|
||||||
|
pVal = NULL;
|
||||||
|
ret = tdbDbGet(pMeta->pDB->pSchemaDB, pKey, kLen, &pVal, &vLen);
|
||||||
|
if (ret < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// decode
|
||||||
|
pBuf = pVal;
|
||||||
|
pSchemaWrapper = taosMemoryMalloc(sizeof(*pSchemaWrapper));
|
||||||
|
metaDecodeSchema(pBuf, pSchemaWrapper);
|
||||||
|
|
||||||
|
TDB_FREE(pVal);
|
||||||
|
|
||||||
|
return pSchemaWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) {
|
STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) {
|
||||||
// TODO
|
tb_uid_t quid;
|
||||||
|
SSchemaWrapper *pSW;
|
||||||
|
STSchemaBuilder sb;
|
||||||
|
SSchema *pSchema;
|
||||||
|
STSchema *pTSchema;
|
||||||
|
STbCfg *pTbCfg;
|
||||||
|
|
||||||
|
pTbCfg = metaGetTbInfoByUid(pMeta, uid);
|
||||||
|
if (pTbCfg->type == META_CHILD_TABLE) {
|
||||||
|
quid = pTbCfg->ctbCfg.suid;
|
||||||
|
} else {
|
||||||
|
quid = uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
pSW = metaGetTableSchema(pMeta, quid, sver, true);
|
||||||
|
if (pSW == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tdInitTSchemaBuilder(&sb, 0);
|
||||||
|
for (int i = 0; i < pSW->nCols; i++) {
|
||||||
|
pSchema = pSW->pSchema + i;
|
||||||
|
tdAddColToSchema(&sb, pSchema->type, pSchema->colId, pSchema->bytes);
|
||||||
|
}
|
||||||
|
pTSchema = tdGetSchemaFromBuilder(&sb);
|
||||||
|
tdDestroyTSchemaBuilder(&sb);
|
||||||
|
|
||||||
|
return pTSchema;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SMTbCursor {
|
||||||
|
TDBC *pDbc;
|
||||||
|
};
|
||||||
|
|
||||||
SMTbCursor *metaOpenTbCursor(SMeta *pMeta) {
|
SMTbCursor *metaOpenTbCursor(SMeta *pMeta) {
|
||||||
// TODO
|
SMTbCursor *pTbCur = NULL;
|
||||||
|
SMetaDB *pDB = pMeta->pDB;
|
||||||
|
|
||||||
|
pTbCur = (SMTbCursor *)taosMemoryCalloc(1, sizeof(*pTbCur));
|
||||||
|
if (pTbCur == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tdbDbcOpen(pDB->pTbDB, &pTbCur->pDbc);
|
||||||
|
|
||||||
|
return pTbCur;
|
||||||
|
}
|
||||||
|
|
||||||
void metaCloseTbCursor(SMTbCursor *pTbCur) {
|
void metaCloseTbCursor(SMTbCursor *pTbCur) {
|
||||||
// TODO
|
if (pTbCur) {
|
||||||
|
if (pTbCur->pDbc) {
|
||||||
|
tdbDbcClose(pTbCur->pDbc);
|
||||||
|
}
|
||||||
|
taosMemoryFree(pTbCur);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *metaTbCursorNext(SMTbCursor *pTbCur) {
|
char *metaTbCursorNext(SMTbCursor *pTbCur) {
|
||||||
// TODO
|
void *pKey = NULL;
|
||||||
|
void *pVal = NULL;
|
||||||
|
int kLen;
|
||||||
|
int vLen;
|
||||||
|
int ret;
|
||||||
|
void *pBuf;
|
||||||
|
STbCfg tbCfg;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
ret = tdbDbNext(pTbCur->pDbc, &pKey, &kLen, &pVal, &vLen);
|
||||||
|
if (ret < 0) break;
|
||||||
|
pBuf = pVal;
|
||||||
|
metaDecodeTbInfo(pBuf, &tbCfg);
|
||||||
|
if (tbCfg.type == META_SUPER_TABLE) {
|
||||||
|
taosMemoryFree(tbCfg.name);
|
||||||
|
taosMemoryFree(tbCfg.stbCfg.pTagSchema);
|
||||||
|
continue;
|
||||||
|
;
|
||||||
|
} else if (tbCfg.type == META_CHILD_TABLE) {
|
||||||
|
kvRowFree(tbCfg.ctbCfg.pTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tbCfg.name;
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct SMCtbCursor {
|
||||||
|
TDBC *pCur;
|
||||||
|
tb_uid_t suid;
|
||||||
|
void *pKey;
|
||||||
|
void *pVal;
|
||||||
|
int kLen;
|
||||||
|
int vLen;
|
||||||
|
};
|
||||||
|
|
||||||
SMCtbCursor *metaOpenCtbCursor(SMeta *pMeta, tb_uid_t uid) {
|
SMCtbCursor *metaOpenCtbCursor(SMeta *pMeta, tb_uid_t uid) {
|
||||||
// TODO
|
SMCtbCursor *pCtbCur = NULL;
|
||||||
|
SMetaDB *pDB = pMeta->pDB;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
pCtbCur = (SMCtbCursor *)taosMemoryCalloc(1, sizeof(*pCtbCur));
|
||||||
|
if (pCtbCur == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pCtbCur->suid = uid;
|
||||||
|
ret = tdbDbcOpen(pDB->pCtbIdx, &pCtbCur->pCur);
|
||||||
|
if (ret < 0) {
|
||||||
|
taosMemoryFree(pCtbCur);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: move the cursor to the suid there
|
||||||
|
|
||||||
|
return pCtbCur;
|
||||||
|
}
|
||||||
|
|
||||||
void metaCloseCtbCurosr(SMCtbCursor *pCtbCur) {
|
void metaCloseCtbCurosr(SMCtbCursor *pCtbCur) {
|
||||||
// TODO
|
if (pCtbCur) {
|
||||||
|
if (pCtbCur->pCur) {
|
||||||
|
tdbDbcClose(pCtbCur->pCur);
|
||||||
|
|
||||||
|
TDB_FREE(pCtbCur->pKey);
|
||||||
|
TDB_FREE(pCtbCur->pVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
taosMemoryFree(pCtbCur);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tb_uid_t metaCtbCursorNext(SMCtbCursor *pCtbCur) {
|
tb_uid_t metaCtbCursorNext(SMCtbCursor *pCtbCur) {
|
||||||
// TODO
|
int ret;
|
||||||
|
SCtbIdxKey *pCtbIdxKey;
|
||||||
|
|
||||||
|
ret = tdbDbNext(pCtbCur->pCur, &pCtbCur->pKey, &pCtbCur->kLen, &pCtbCur->pVal, &pCtbCur->vLen);
|
||||||
|
if (ret < 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pCtbIdxKey = pCtbCur->pVal;
|
||||||
|
|
||||||
|
return pCtbIdxKey->uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
int metaGetTbNum(SMeta *pMeta) {
|
||||||
|
// TODO
|
||||||
|
// ASSERT(0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) {
|
||||||
|
// TODO
|
||||||
|
ASSERT(0);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int metaRemoveSmaFromDb(SMeta *pMeta, int64_t indexUid) {
|
||||||
|
// TODO
|
||||||
|
ASSERT(0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int metaSaveSmaToDB(SMeta *pMeta, STSma *pSmaCfg) {
|
||||||
|
// TODO
|
||||||
|
ASSERT(0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
STSma *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid) {
|
||||||
|
// TODO
|
||||||
|
ASSERT(0);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *metaSmaCursorNext(SMSmaCursor *pCur) {
|
||||||
|
// TODO
|
||||||
|
ASSERT(0);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void metaCloseSmaCurosr(SMSmaCursor *pCur) {
|
||||||
|
// TODO
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
SArray *metaGetSmaTbUids(SMeta *pMeta, bool isDup) {
|
||||||
|
// TODO
|
||||||
|
ASSERT(0);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SMSmaCursor *metaOpenSmaCursor(SMeta *pMeta, tb_uid_t uid) {
|
||||||
|
// TODO
|
||||||
|
ASSERT(0);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int metaEncodeSchema(void **buf, SSchemaWrapper *pSW) {
|
||||||
|
int tlen = 0;
|
||||||
|
SSchema *pSchema;
|
||||||
|
|
||||||
|
tlen += taosEncodeFixedU32(buf, pSW->nCols);
|
||||||
|
for (int i = 0; i < pSW->nCols; i++) {
|
||||||
|
pSchema = pSW->pSchema + i;
|
||||||
|
tlen += taosEncodeFixedI8(buf, pSchema->type);
|
||||||
|
tlen += taosEncodeFixedI16(buf, pSchema->colId);
|
||||||
|
tlen += taosEncodeFixedI32(buf, pSchema->bytes);
|
||||||
|
tlen += taosEncodeString(buf, pSchema->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tlen;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *metaDecodeSchema(void *buf, SSchemaWrapper *pSW) {
|
||||||
|
SSchema *pSchema;
|
||||||
|
|
||||||
|
buf = taosDecodeFixedU32(buf, &pSW->nCols);
|
||||||
|
pSW->pSchema = (SSchema *)taosMemoryMalloc(sizeof(SSchema) * pSW->nCols);
|
||||||
|
for (int i = 0; i < pSW->nCols; i++) {
|
||||||
|
pSchema = pSW->pSchema + i;
|
||||||
|
buf = taosDecodeFixedI8(buf, &pSchema->type);
|
||||||
|
buf = taosDecodeFixedI16(buf, &pSchema->colId);
|
||||||
|
buf = taosDecodeFixedI32(buf, &pSchema->bytes);
|
||||||
|
buf = taosDecodeStringTo(buf, pSchema->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg) {
|
||||||
|
int tsize = 0;
|
||||||
|
|
||||||
|
tsize += taosEncodeString(buf, pTbCfg->name);
|
||||||
|
tsize += taosEncodeFixedU32(buf, pTbCfg->ttl);
|
||||||
|
tsize += taosEncodeFixedU32(buf, pTbCfg->keep);
|
||||||
|
tsize += taosEncodeFixedU8(buf, pTbCfg->info);
|
||||||
|
|
||||||
|
if (pTbCfg->type == META_SUPER_TABLE) {
|
||||||
|
SSchemaWrapper sw = {.nCols = pTbCfg->stbCfg.nTagCols, .pSchema = pTbCfg->stbCfg.pTagSchema};
|
||||||
|
tsize += metaEncodeSchema(buf, &sw);
|
||||||
|
} else if (pTbCfg->type == META_CHILD_TABLE) {
|
||||||
|
tsize += taosEncodeFixedU64(buf, pTbCfg->ctbCfg.suid);
|
||||||
|
tsize += tdEncodeKVRow(buf, pTbCfg->ctbCfg.pTag);
|
||||||
|
} else if (pTbCfg->type == META_NORMAL_TABLE) {
|
||||||
|
// TODO
|
||||||
|
} else {
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *metaDecodeTbInfo(void *buf, STbCfg *pTbCfg) {
|
||||||
|
buf = taosDecodeString(buf, &(pTbCfg->name));
|
||||||
|
buf = taosDecodeFixedU32(buf, &(pTbCfg->ttl));
|
||||||
|
buf = taosDecodeFixedU32(buf, &(pTbCfg->keep));
|
||||||
|
buf = taosDecodeFixedU8(buf, &(pTbCfg->info));
|
||||||
|
|
||||||
|
if (pTbCfg->type == META_SUPER_TABLE) {
|
||||||
|
SSchemaWrapper sw;
|
||||||
|
buf = metaDecodeSchema(buf, &sw);
|
||||||
|
pTbCfg->stbCfg.nTagCols = sw.nCols;
|
||||||
|
pTbCfg->stbCfg.pTagSchema = sw.pSchema;
|
||||||
|
} else if (pTbCfg->type == META_CHILD_TABLE) {
|
||||||
|
buf = taosDecodeFixedU64(buf, &(pTbCfg->ctbCfg.suid));
|
||||||
|
buf = tdDecodeKVRow(buf, &(pTbCfg->ctbCfg.pTag));
|
||||||
|
} else if (pTbCfg->type == META_NORMAL_TABLE) {
|
||||||
|
// TODO
|
||||||
|
} else {
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
|
@ -275,7 +275,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
|
||||||
pMsg->pCont = NULL;
|
pMsg->pCont = NULL;
|
||||||
pMsg->contLen = 0;
|
pMsg->contLen = 0;
|
||||||
pMsg->code = -1;
|
pMsg->code = -1;
|
||||||
rpcSendResponse(pMsg);
|
tmsgSendRsp(pMsg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,7 +340,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
|
||||||
pMsg->pCont = buf;
|
pMsg->pCont = buf;
|
||||||
pMsg->contLen = tlen;
|
pMsg->contLen = tlen;
|
||||||
pMsg->code = 0;
|
pMsg->code = 0;
|
||||||
rpcSendResponse(pMsg);
|
tmsgSendRsp(pMsg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -367,7 +367,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
|
||||||
pMsg->pCont = buf;
|
pMsg->pCont = buf;
|
||||||
pMsg->contLen = tlen;
|
pMsg->contLen = tlen;
|
||||||
pMsg->code = 0;
|
pMsg->code = 0;
|
||||||
rpcSendResponse(pMsg);
|
tmsgSendRsp(pMsg);
|
||||||
/*}*/
|
/*}*/
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -489,7 +489,7 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen) {
|
int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen, int32_t workerId) {
|
||||||
void* pIter = NULL;
|
void* pIter = NULL;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -497,14 +497,14 @@ int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen) {
|
||||||
if (pIter == NULL) break;
|
if (pIter == NULL) break;
|
||||||
SStreamTask* pTask = (SStreamTask*)pIter;
|
SStreamTask* pTask = (SStreamTask*)pIter;
|
||||||
|
|
||||||
if (streamExecTask(pTask, &pTq->pVnode->msgCb, data, STREAM_DATA_TYPE_SUBMIT_BLOCK, 0) < 0) {
|
if (streamExecTask(pTask, &pTq->pVnode->msgCb, data, STREAM_DATA_TYPE_SUBMIT_BLOCK, workerId) < 0) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen) {
|
int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen, int32_t workerId) {
|
||||||
SStreamTaskExecReq req;
|
SStreamTaskExecReq req;
|
||||||
tDecodeSStreamTaskExecReq(msg, &req);
|
tDecodeSStreamTaskExecReq(msg, &req);
|
||||||
|
|
||||||
|
@ -514,7 +514,7 @@ int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen) {
|
||||||
SStreamTask* pTask = taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t));
|
SStreamTask* pTask = taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t));
|
||||||
ASSERT(pTask);
|
ASSERT(pTask);
|
||||||
|
|
||||||
if (streamExecTask(pTask, &pTq->pVnode->msgCb, req.data, STREAM_DATA_TYPE_SSDATA_BLOCK, 0) < 0) {
|
if (streamExecTask(pTask, &pTq->pVnode->msgCb, req.data, STREAM_DATA_TYPE_SSDATA_BLOCK, workerId) < 0) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -114,10 +114,9 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) {
|
||||||
SSchemaWrapper* pSchemaWrapper = pHandle->pSchemaWrapper;
|
SSchemaWrapper* pSchemaWrapper = pHandle->pSchemaWrapper;
|
||||||
|
|
||||||
int32_t numOfRows = pHandle->pBlock->numOfRows;
|
int32_t numOfRows = pHandle->pBlock->numOfRows;
|
||||||
int32_t numOfCols = pHandle->pSchema->numOfCols;
|
/*int32_t numOfCols = pHandle->pSchema->numOfCols;*/
|
||||||
int32_t colNumNeed = taosArrayGetSize(pHandle->pColIdList);
|
int32_t colNumNeed = taosArrayGetSize(pHandle->pColIdList);
|
||||||
|
|
||||||
// TODO: stable case
|
|
||||||
if (colNumNeed > pSchemaWrapper->nCols) {
|
if (colNumNeed > pSchemaWrapper->nCols) {
|
||||||
colNumNeed = pSchemaWrapper->nCols;
|
colNumNeed = pSchemaWrapper->nCols;
|
||||||
}
|
}
|
||||||
|
@ -138,58 +137,24 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) {
|
||||||
colNeed++;
|
colNeed++;
|
||||||
} else {
|
} else {
|
||||||
SColumnInfoData colInfo = {0};
|
SColumnInfoData colInfo = {0};
|
||||||
int sz = numOfRows * pColSchema->bytes;
|
/*int sz = numOfRows * pColSchema->bytes;*/
|
||||||
colInfo.info.bytes = pColSchema->bytes;
|
colInfo.info.bytes = pColSchema->bytes;
|
||||||
colInfo.info.colId = pColSchema->colId;
|
colInfo.info.colId = pColSchema->colId;
|
||||||
colInfo.info.type = pColSchema->type;
|
colInfo.info.type = pColSchema->type;
|
||||||
|
|
||||||
colInfo.pData = taosMemoryCalloc(1, sz);
|
if (blockDataEnsureColumnCapacity(&colInfo, numOfRows) < 0) {
|
||||||
if (colInfo.pData == NULL) {
|
taosArrayDestroyEx(pArray, (void (*)(void*))tDeleteSSDataBlock);
|
||||||
// TODO free
|
|
||||||
taosArrayDestroy(pArray);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
blockDataEnsureColumnCapacity(&colInfo, numOfRows);
|
|
||||||
taosArrayPush(pArray, &colInfo);
|
taosArrayPush(pArray, &colInfo);
|
||||||
colMeta++;
|
colMeta++;
|
||||||
colNeed++;
|
colNeed++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
int j = 0;
|
|
||||||
for (int32_t i = 0; i < colNumNeed; i++) {
|
|
||||||
col_id_t colId = *(col_id_t*)taosArrayGet(pHandle->pColIdList, i);
|
|
||||||
while (j < pSchemaWrapper->nCols && pSchemaWrapper->pSchema[j].colId < colId) {
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
if (j >= pSchemaWrapper->nCols) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
SSchema* pColSchema = &pSchemaWrapper->pSchema[j];
|
|
||||||
SColumnInfoData colInfo = {0};
|
|
||||||
int sz = numOfRows * pColSchema->bytes;
|
|
||||||
colInfo.info.bytes = pColSchema->bytes;
|
|
||||||
colInfo.info.colId = colId;
|
|
||||||
colInfo.info.type = pColSchema->type;
|
|
||||||
|
|
||||||
colInfo.pData = taosMemoryCalloc(1, sz);
|
|
||||||
if (colInfo.pData == NULL) {
|
|
||||||
// TODO free
|
|
||||||
taosArrayDestroy(pArray);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
blockDataEnsureColumnCapacity(&colInfo, numOfRows);
|
|
||||||
taosArrayPush(pArray, &colInfo);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
STSRowIter iter = {0};
|
STSRowIter iter = {0};
|
||||||
tdSTSRowIterInit(&iter, pTschema);
|
tdSTSRowIterInit(&iter, pTschema);
|
||||||
STSRow* row;
|
STSRow* row;
|
||||||
// int32_t kvIdx = 0;
|
|
||||||
int32_t curRow = 0;
|
int32_t curRow = 0;
|
||||||
tInitSubmitBlkIter(pHandle->pBlock, &pHandle->blkIter);
|
tInitSubmitBlkIter(pHandle->pBlock, &pHandle->blkIter);
|
||||||
while ((row = tGetSubmitBlkNext(&pHandle->blkIter)) != NULL) {
|
while ((row = tGetSubmitBlkNext(&pHandle->blkIter)) != NULL) {
|
||||||
|
@ -202,25 +167,11 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) {
|
||||||
if (!tdSTSRowIterNext(&iter, pColData->info.colId, pColData->info.type, &sVal)) {
|
if (!tdSTSRowIterNext(&iter, pColData->info.colId, pColData->info.type, &sVal)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
memcpy(POINTER_SHIFT(pColData->pData, curRow * pColData->info.bytes), sVal.val, pColData->info.bytes);
|
if (colDataAppend(pColData, curRow, sVal.val, sVal.valType == TD_VTYPE_NULL) < 0) {
|
||||||
|
taosArrayDestroyEx(pArray, (void (*)(void*))tDeleteSSDataBlock);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
for (int32_t i = 0; i < colNumNeed; i++) {
|
|
||||||
SColumnInfoData* pColData = taosArrayGet(pArray, i);
|
|
||||||
STColumn* pCol = schemaColAt(pTschema, i);
|
|
||||||
// TODO
|
|
||||||
if(pCol->colId != pColData->info.colId) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
// void* val = tdGetMemRowDataOfColEx(row, pCol->colId, pCol->type, TD_DATA_ROW_HEAD_SIZE + pCol->offset, &kvIdx);
|
|
||||||
SCellVal sVal = {0};
|
|
||||||
if (!tdSTSRowIterNext(&iter, pCol->colId, pCol->type, &sVal)) {
|
|
||||||
// TODO: reach end
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
memcpy(POINTER_SHIFT(pColData->pData, curRow * pCol->bytes), sVal.val, pCol->bytes);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
curRow++;
|
curRow++;
|
||||||
}
|
}
|
||||||
return pArray;
|
return pArray;
|
||||||
|
|
|
@ -24,7 +24,7 @@ static const char *TSDB_SMA_DNAME[] = {
|
||||||
#define SMA_STORAGE_TSDB_DAYS 30
|
#define SMA_STORAGE_TSDB_DAYS 30
|
||||||
#define SMA_STORAGE_TSDB_TIMES 10
|
#define SMA_STORAGE_TSDB_TIMES 10
|
||||||
#define SMA_STORAGE_SPLIT_HOURS 24
|
#define SMA_STORAGE_SPLIT_HOURS 24
|
||||||
#define SMA_KEY_LEN 18 // tableUid_colId_TSKEY 8+2+8
|
#define SMA_KEY_LEN 16 // TSKEY+groupId 8+8
|
||||||
#define SMA_DROP_EXPIRED_TIME 10 // default is 10 seconds
|
#define SMA_DROP_EXPIRED_TIME 10 // default is 10 seconds
|
||||||
|
|
||||||
#define SMA_STATE_HASH_SLOT 4
|
#define SMA_STATE_HASH_SLOT 4
|
||||||
|
@ -40,7 +40,7 @@ typedef enum {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
STsdb *pTsdb;
|
STsdb *pTsdb;
|
||||||
SDBFile dFile;
|
SDBFile dFile;
|
||||||
SSDataBlock *pData; // sma data
|
const SArray *pDataBlocks; // sma data
|
||||||
int32_t interval; // interval with the precision of DB
|
int32_t interval; // interval with the precision of DB
|
||||||
} STSmaWriteH;
|
} STSmaWriteH;
|
||||||
|
|
||||||
|
@ -94,26 +94,24 @@ static int32_t tsdbUnRefSmaStat(STsdb *pTsdb, SSmaStat *pStat);
|
||||||
|
|
||||||
// read data
|
// read data
|
||||||
// TODO: This is the basic params, and should wrap the params to a queryHandle.
|
// TODO: This is the basic params, and should wrap the params to a queryHandle.
|
||||||
static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval,
|
static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid, TSKEY querySKey, int32_t nMaxResult);
|
||||||
int8_t intervalUnit, tb_uid_t tableUid, col_id_t colId, TSKEY querySKey,
|
|
||||||
int32_t nMaxResult);
|
|
||||||
|
|
||||||
// insert data
|
// insert data
|
||||||
static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, SSDataBlock *pData, int64_t interval,
|
static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, const SArray *pDataBlocks, int64_t interval,
|
||||||
int8_t intervalUnit);
|
int8_t intervalUnit);
|
||||||
static void tsdbDestroyTSmaWriteH(STSmaWriteH *pSmaH);
|
static void tsdbDestroyTSmaWriteH(STSmaWriteH *pSmaH);
|
||||||
static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, int64_t interval, int8_t intervalUnit);
|
static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, int64_t interval, int8_t intervalUnit);
|
||||||
static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit);
|
static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit);
|
||||||
static int32_t tsdbInsertTSmaDataSection(STSmaWriteH *pSmaH, STSmaDataWrapper *pData);
|
static int32_t tsdbSetRSmaDataFile(STSmaWriteH *pSmaH, int32_t fid);
|
||||||
static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, uint32_t keyLen, void *pData, uint32_t dataLen);
|
static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, uint32_t keyLen, void *pData, uint32_t dataLen);
|
||||||
static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit, int8_t precision);
|
static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit, int8_t precision, bool adjusted);
|
||||||
static int32_t tsdbGetTSmaDays(STsdb *pTsdb, int64_t interval, int32_t storageLevel);
|
static int32_t tsdbGetTSmaDays(STsdb *pTsdb, int64_t interval, int32_t storageLevel);
|
||||||
static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData, int64_t indexUid, int32_t fid);
|
static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, int64_t indexUid, int32_t fid);
|
||||||
static int32_t tsdbInitTSmaFile(STSmaReadH *pSmaH, int64_t indexUid, TSKEY skey);
|
static int32_t tsdbInitTSmaFile(STSmaReadH *pSmaH, int64_t indexUid, TSKEY skey);
|
||||||
static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey);
|
static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey);
|
||||||
static void tsdbGetSmaDir(int32_t vgId, ETsdbSmaType smaType, char dirName[]);
|
static void tsdbGetSmaDir(int32_t vgId, ETsdbSmaType smaType, char dirName[]);
|
||||||
static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg);
|
static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char *msg);
|
||||||
static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg);
|
static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, const char *msg);
|
||||||
|
|
||||||
// mgmt interface
|
// mgmt interface
|
||||||
static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid);
|
static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid);
|
||||||
|
@ -387,7 +385,6 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
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) {
|
||||||
SSmaStatItem *pItem = taosHashGet(pItemsHash, &indexUid, sizeof(indexUid));
|
SSmaStatItem *pItem = taosHashGet(pItemsHash, &indexUid, sizeof(indexUid));
|
||||||
if (pItem == NULL) {
|
if (pItem == NULL) {
|
||||||
|
@ -480,18 +477,15 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, const char *msg) {
|
||||||
TSKEY expiredWindows[SMA_TEST_EXPIRED_WINDOW_SIZE];
|
TSKEY expiredWindows[SMA_TEST_EXPIRED_WINDOW_SIZE];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// Firstly, assume that tSma can only be created on super table/normal table.
|
// Firstly, assume that tSma can only be created on super table/normal table.
|
||||||
// getActiveTimeWindow
|
// getActiveTimeWindow
|
||||||
|
|
||||||
|
|
||||||
SSmaEnv *pEnv = REPO_SMA_ENV(pTsdb, TSDB_SMA_TYPE_TIME_RANGE);
|
SSmaEnv *pEnv = REPO_SMA_ENV(pTsdb, TSDB_SMA_TYPE_TIME_RANGE);
|
||||||
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 != NULL && pStat != NULL && pItemsHash != NULL);
|
||||||
|
|
||||||
|
|
||||||
// basic procedure
|
// basic procedure
|
||||||
// TODO: optimization
|
// TODO: optimization
|
||||||
tsdbRefSmaStat(pTsdb, pStat);
|
tsdbRefSmaStat(pTsdb, pStat);
|
||||||
|
@ -657,9 +651,8 @@ static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit) {
|
||||||
*/
|
*/
|
||||||
static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, uint32_t keyLen, void *pData, uint32_t dataLen) {
|
static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, uint32_t keyLen, void *pData, uint32_t dataLen) {
|
||||||
SDBFile *pDBFile = &pSmaH->dFile;
|
SDBFile *pDBFile = &pSmaH->dFile;
|
||||||
tsdbDebug("vgId:%d insert sma data blocks into %s: smaKey %" PRIx64 "-%" PRIu16 "-%" PRIx64 ", dataLen %d",
|
printf("\nvgId:%d insert sma data blocks into %s: smaKey %" PRIx64 "-%" PRIx64 ", dataLen %" PRIu32 "\n",
|
||||||
REPO_ID(pSmaH->pTsdb), pDBFile->path, *(tb_uid_t *)smaKey, *(uint16_t *)POINTER_SHIFT(smaKey, 8),
|
REPO_ID(pSmaH->pTsdb), pDBFile->path, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), dataLen);
|
||||||
*(int64_t *)POINTER_SHIFT(smaKey, 10), dataLen);
|
|
||||||
|
|
||||||
// TODO: insert sma data blocks into B+Tree(TDB)
|
// TODO: insert sma data blocks into B+Tree(TDB)
|
||||||
if (tsdbSaveSmaToDB(pDBFile, smaKey, keyLen, pData, dataLen) != 0) {
|
if (tsdbSaveSmaToDB(pDBFile, smaKey, keyLen, pData, dataLen) != 0) {
|
||||||
|
@ -683,9 +676,15 @@ static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, uint32_t k
|
||||||
* @param interval
|
* @param interval
|
||||||
* @param intervalUnit
|
* @param intervalUnit
|
||||||
* @param precision
|
* @param precision
|
||||||
|
* @param adjusted Interval already adjusted according to DB precision
|
||||||
* @return int64_t
|
* @return int64_t
|
||||||
*/
|
*/
|
||||||
static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit, int8_t precision) {
|
static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit, int8_t precision, bool adjusted) {
|
||||||
|
|
||||||
|
if (adjusted) {
|
||||||
|
return interval;
|
||||||
|
}
|
||||||
|
|
||||||
switch (intervalUnit) {
|
switch (intervalUnit) {
|
||||||
case TIME_UNIT_YEAR: // approximate value
|
case TIME_UNIT_YEAR: // approximate value
|
||||||
interval *= 365 * 86400 * 1e3;
|
interval *= 365 * 86400 * 1e3;
|
||||||
|
@ -753,59 +752,12 @@ static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit
|
||||||
return interval;
|
return interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, const SArray *pDataBlocks, int64_t interval,
|
||||||
* @brief Split the TSma data blocks into expected size and insert into B+Tree.
|
int8_t intervalUnit) {
|
||||||
*
|
|
||||||
* @param pSmaH
|
|
||||||
* @param pData
|
|
||||||
* @param nOffset The nOffset of blocks since fid changes.
|
|
||||||
* @param nBlocks The nBlocks with the same fid since nOffset.
|
|
||||||
* @return int32_t
|
|
||||||
*/
|
|
||||||
static int32_t tsdbInsertTSmaDataSection(STSmaWriteH *pSmaH, STSmaDataWrapper *pData) {
|
|
||||||
STsdb *pTsdb = pSmaH->pTsdb;
|
|
||||||
|
|
||||||
tsdbDebug("tsdbInsertTSmaDataSection: index %" PRIi64 ", skey %" PRIi64, pData->indexUid, pData->skey);
|
|
||||||
|
|
||||||
// TODO: check the data integrity
|
|
||||||
|
|
||||||
int32_t len = 0;
|
|
||||||
while (true) {
|
|
||||||
if (len >= pData->dataLen) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
assert(pData->dataLen > 0);
|
|
||||||
STSmaTbData *pTbData = (STSmaTbData *)POINTER_SHIFT(pData->data, len);
|
|
||||||
|
|
||||||
int32_t tbLen = 0;
|
|
||||||
while (true) {
|
|
||||||
if (tbLen >= pTbData->dataLen) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
assert(pTbData->dataLen > 0);
|
|
||||||
STSmaColData *pColData = (STSmaColData *)POINTER_SHIFT(pTbData->data, tbLen);
|
|
||||||
char smaKey[SMA_KEY_LEN] = {0};
|
|
||||||
void *pSmaKey = &smaKey;
|
|
||||||
#if 0
|
|
||||||
printf("tsdbInsertTSmaDataSection: index %" PRIi64 ", skey %" PRIi64 " table[%" PRIi64 "]col[%" PRIu16 "]\n",
|
|
||||||
pData->indexUid, pData->skey, pTbData->tableUid, pColData->colId);
|
|
||||||
#endif
|
|
||||||
tsdbEncodeTSmaKey(pTbData->tableUid, pColData->colId, pData->skey, (void **)&pSmaKey);
|
|
||||||
if (tsdbInsertTSmaBlocks(pSmaH, smaKey, SMA_KEY_LEN, pColData->data, pColData->blockSize) < 0) {
|
|
||||||
tsdbWarn("vgId:%d insert tSma blocks failed since %s", REPO_ID(pTsdb), tstrerror(terrno));
|
|
||||||
}
|
|
||||||
tbLen += (sizeof(STSmaColData) + pColData->blockSize);
|
|
||||||
}
|
|
||||||
len += (sizeof(STSmaTbData) + pTbData->dataLen);
|
|
||||||
}
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, SSDataBlock *pData, int64_t interval, int8_t intervalUnit) {
|
|
||||||
pSmaH->pTsdb = pTsdb;
|
pSmaH->pTsdb = pTsdb;
|
||||||
pSmaH->interval = tsdbGetIntervalByPrecision(interval, intervalUnit, REPO_CFG(pTsdb)->precision);
|
pSmaH->interval = tsdbGetIntervalByPrecision(interval, intervalUnit, REPO_CFG(pTsdb)->precision, true);
|
||||||
pSmaH->pData = pData;
|
pSmaH->pDataBlocks = pDataBlocks;
|
||||||
|
pSmaH->dFile.fid = TSDB_IVLD_FID;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -815,7 +767,7 @@ static void tsdbDestroyTSmaWriteH(STSmaWriteH *pSmaH) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData, 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 == NULL && pSmaH->dFile.pDB == NULL);
|
||||||
|
|
||||||
|
@ -859,11 +811,10 @@ static int32_t tsdbGetTSmaDays(STsdb *pTsdb, int64_t interval, int32_t storageLe
|
||||||
* @param msg
|
* @param msg
|
||||||
* @return int32_t
|
* @return int32_t
|
||||||
*/
|
*/
|
||||||
static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) {
|
static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char *msg) {
|
||||||
STsdbCfg *pCfg = REPO_CFG(pTsdb);
|
STsdbCfg *pCfg = REPO_CFG(pTsdb);
|
||||||
SSDataBlock *pData = (SSDataBlock *)msg;
|
const SArray *pDataBlocks = (const SArray *)msg;
|
||||||
SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pTSmaEnv);
|
SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pTSmaEnv);
|
||||||
int64_t indexUid = SMA_TEST_INDEX_UID;
|
|
||||||
|
|
||||||
if (pEnv == NULL) {
|
if (pEnv == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
terrno = TSDB_CODE_INVALID_PTR;
|
||||||
|
@ -871,15 +822,15 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) {
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pData == NULL) {
|
if (pDataBlocks == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
terrno = TSDB_CODE_INVALID_PTR;
|
||||||
tsdbWarn("vgId:%d insert tSma data failed since pData is NULL", REPO_ID(pTsdb));
|
tsdbWarn("vgId:%d insert tSma data failed since pDataBlocks is NULL", REPO_ID(pTsdb));
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosArrayGetSize(pData->pDataBlock) <= 0) {
|
if (taosArrayGetSize(pDataBlocks) <= 0) {
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
tsdbWarn("vgId:%d insert tSma data failed since pDataBlock is empty", REPO_ID(pTsdb));
|
tsdbWarn("vgId:%d insert tSma data failed since pDataBlocks is empty", REPO_ID(pTsdb));
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -899,10 +850,9 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
STSma *pSma = pItem->pSma;
|
STSma *pSma = pItem->pSma;
|
||||||
|
|
||||||
STSmaWriteH tSmaH = {0};
|
STSmaWriteH tSmaH = {0};
|
||||||
|
|
||||||
if (tsdbInitTSmaWriteH(&tSmaH, pTsdb, pData, pSma->interval, pSma->intervalUnit) != 0) {
|
if (tsdbInitTSmaWriteH(&tSmaH, pTsdb, pDataBlocks, pSma->interval, pSma->intervalUnit) != 0) {
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -921,14 +871,101 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) {
|
||||||
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};
|
||||||
|
char dataBuf[512] = {0};
|
||||||
|
void *pDataBuf = &dataBuf;
|
||||||
|
int32_t sz = taosArrayGetSize(pDataBlocks);
|
||||||
|
for (int32_t i = 0; i < sz; ++i) {
|
||||||
|
SSDataBlock *pDataBlock = *(SSDataBlock **)taosArrayGet(pDataBlocks, i);
|
||||||
|
int32_t colNum = pDataBlock->info.numOfCols;
|
||||||
|
int32_t rows = pDataBlock->info.rows;
|
||||||
|
int32_t rowSize = pDataBlock->info.rowSize;
|
||||||
|
int64_t groupId = pDataBlock->info.groupId;
|
||||||
|
for (int32_t j = 0; j < rows; ++j) {
|
||||||
|
printf("|");
|
||||||
|
TSKEY skey = TSKEY_INITIAL_VAL; // the start key of TS window by interval
|
||||||
|
void *pSmaKey = &smaKey;
|
||||||
|
int32_t tlen = 0;
|
||||||
|
for (int32_t k = 0; k < colNum; ++k) {
|
||||||
|
SColumnInfoData *pColInfoData = *(SColumnInfoData **)taosArrayGet(pDataBlock->pDataBlock, k);
|
||||||
|
void *var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes);
|
||||||
|
switch (pColInfoData->info.type) {
|
||||||
|
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
|
skey = *(TSKEY *)var;
|
||||||
|
printf("==> skey = %" PRIi64 " groupId = %" PRId64 "|", skey, groupId);
|
||||||
|
tsdbEncodeTSmaKey(groupId, skey, &pSmaKey);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_BOOL:
|
||||||
|
case TSDB_DATA_TYPE_UTINYINT:
|
||||||
|
printf(" %15d |", *(uint8_t *)var);
|
||||||
|
tlen += taosEncodeFixedU8(&pDataBuf, *(uint8_t *)var);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_TINYINT:
|
||||||
|
printf(" %15d |", *(int8_t *)var);
|
||||||
|
tlen += taosEncodeFixedI8(&pDataBuf, *(int8_t *)var);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_SMALLINT:
|
||||||
|
printf(" %15d |", *(int16_t *)var);
|
||||||
|
tlen += taosEncodeFixedI16(&pDataBuf, *(int16_t *)var);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_USMALLINT:
|
||||||
|
printf(" %15d |", *(uint16_t *)var);
|
||||||
|
tlen += taosEncodeFixedU16(&pDataBuf, *(uint16_t *)var);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_INT:
|
||||||
|
printf(" %15d |", *(int32_t *)var);
|
||||||
|
tlen += taosEncodeFixedI32(&pDataBuf, *(int32_t *)var);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_FLOAT:
|
||||||
|
case TSDB_DATA_TYPE_UINT:
|
||||||
|
printf(" %15u |", *(uint32_t *)var);
|
||||||
|
tlen += taosEncodeFixedU32(&pDataBuf, *(uint32_t *)var);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_BIGINT:
|
||||||
|
printf(" %15ld |", *(int64_t *)var);
|
||||||
|
tlen += taosEncodeFixedI64(&pDataBuf, *(int64_t *)var);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_DOUBLE:
|
||||||
|
case TSDB_DATA_TYPE_UBIGINT:
|
||||||
|
printf(" %15lu |", *(uint64_t *)var);
|
||||||
|
tlen += taosEncodeFixedU64(&pDataBuf, *(uint64_t *)var);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_NCHAR: {
|
||||||
|
char tmpChar[100] = {0};
|
||||||
|
strncpy(tmpChar, varDataVal(var), varDataLen(var));
|
||||||
|
printf(" %s |", tmpChar);
|
||||||
|
tlen += taosEncodeBinary(&pDataBuf, varDataVal(var), varDataLen(var));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TSDB_DATA_TYPE_VARCHAR: { // TSDB_DATA_TYPE_BINARY
|
||||||
|
char tmpChar[100] = {0};
|
||||||
|
strncpy(tmpChar, varDataVal(var), varDataLen(var));
|
||||||
|
printf(" %s |", tmpChar);
|
||||||
|
tlen += taosEncodeBinary(&pDataBuf, varDataVal(var), varDataLen(var));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TSDB_DATA_TYPE_VARBINARY:
|
||||||
|
// TODO: add binary/varbinary
|
||||||
|
TASSERT(0);
|
||||||
|
default:
|
||||||
|
printf("the column type %" PRIi16 " is undefined\n", pColInfoData->info.type);
|
||||||
|
TASSERT(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((tlen > 0) && (skey != TSKEY_INITIAL_VAL)) {
|
||||||
|
int32_t fid = (int32_t)(TSDB_KEY_FID(skey, daysPerFile, pCfg->precision));
|
||||||
|
|
||||||
#if 0
|
// Step 2: Set the DFile for storage of SMA index, and iterate/split the TSma data and store to B+Tree index
|
||||||
int32_t fid = (int32_t)(TSDB_KEY_FID(pData->skey, daysPerFile, pCfg->precision));
|
// file
|
||||||
|
|
||||||
// Step 2: Set the DFile for storage of SMA index, and iterate/split the TSma data and store to B+Tree index file
|
|
||||||
// - Set and open the DFile or the B+Tree file
|
// - Set and open the DFile or the B+Tree file
|
||||||
// TODO: tsdbStartTSmaCommit();
|
// TODO: tsdbStartTSmaCommit();
|
||||||
tsdbSetTSmaDataFile(&tSmaH, pData, indexUid, fid);
|
if (fid != tSmaH.dFile.fid) {
|
||||||
|
if (tSmaH.dFile.fid != TSDB_IVLD_FID) {
|
||||||
|
tsdbCloseDBF(&tSmaH.dFile);
|
||||||
|
}
|
||||||
|
tsdbSetTSmaDataFile(&tSmaH, indexUid, fid);
|
||||||
if (tsdbOpenDBF(pTsdb->pTSmaEnv->dbEnv, &tSmaH.dFile) != 0) {
|
if (tsdbOpenDBF(pTsdb->pTSmaEnv->dbEnv, &tSmaH.dFile) != 0) {
|
||||||
tsdbWarn("vgId:%d open DB file %s failed since %s", REPO_ID(pTsdb),
|
tsdbWarn("vgId:%d open DB file %s failed since %s", REPO_ID(pTsdb),
|
||||||
tSmaH.dFile.path ? tSmaH.dFile.path : "path is NULL", tstrerror(terrno));
|
tSmaH.dFile.path ? tSmaH.dFile.path : "path is NULL", tstrerror(terrno));
|
||||||
|
@ -936,18 +973,32 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) {
|
||||||
tsdbUnRefSmaStat(pTsdb, pStat);
|
tsdbUnRefSmaStat(pTsdb, pStat);
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (tsdbInsertTSmaDataSection(&tSmaH, pData) != 0) {
|
if (tsdbInsertTSmaBlocks(&tSmaH, &smaKey, SMA_KEY_LEN, pDataBuf, tlen) != 0) {
|
||||||
tsdbWarn("vgId:%d insert tSma data section failed since %s", REPO_ID(pTsdb), tstrerror(terrno));
|
tsdbWarn("vgId:%d insert tSma data blocks failed for index %" PRIi64 ", skey %" PRIi64 ", groupId %" PRIi64
|
||||||
|
" since %s",
|
||||||
|
REPO_ID(pTsdb), indexUid, skey, groupId, tstrerror(terrno));
|
||||||
tsdbDestroyTSmaWriteH(&tSmaH);
|
tsdbDestroyTSmaWriteH(&tSmaH);
|
||||||
tsdbUnRefSmaStat(pTsdb, pStat);
|
tsdbUnRefSmaStat(pTsdb, pStat);
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
|
} else {
|
||||||
|
tsdbWarn("vgId:%d insert tSma data blocks success for index %" PRIi64 ", skey %" PRIi64 ", groupId %" PRIi64,
|
||||||
|
REPO_ID(pTsdb), indexUid, skey, groupId);
|
||||||
}
|
}
|
||||||
// TODO:tsdbEndTSmaCommit();
|
// TODO:tsdbEndTSmaCommit();
|
||||||
|
|
||||||
// Step 3: reset the SSmaStat
|
// Step 3: reset the SSmaStat
|
||||||
tsdbResetExpiredWindow(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv), pData->indexUid, pData->skey);
|
tsdbResetExpiredWindow(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv), indexUid, skey);
|
||||||
#endif
|
} else {
|
||||||
|
tsdbWarn("vgId:%d invalid data skey:%" PRIi64 ", tlen %" PRIi32 " during insert tSma data for %" PRIi64,
|
||||||
|
REPO_ID(pTsdb), skey, tlen, indexUid);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tsdbDestroyTSmaWriteH(&tSmaH);
|
tsdbDestroyTSmaWriteH(&tSmaH);
|
||||||
tsdbUnRefSmaStat(pTsdb, pStat);
|
tsdbUnRefSmaStat(pTsdb, pStat);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -1002,7 +1053,7 @@ static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid) {
|
||||||
// TODO:
|
// TODO:
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tsdbSetRSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData, int32_t fid) {
|
static int32_t tsdbSetRSmaDataFile(STSmaWriteH *pSmaH, int32_t fid) {
|
||||||
STsdb *pTsdb = pSmaH->pTsdb;
|
STsdb *pTsdb = pSmaH->pTsdb;
|
||||||
|
|
||||||
char tSmaFile[TSDB_FILENAME_LEN] = {0};
|
char tSmaFile[TSDB_FILENAME_LEN] = {0};
|
||||||
|
@ -1012,9 +1063,9 @@ static int32_t tsdbSetRSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData,
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) {
|
static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, const char *msg) {
|
||||||
STsdbCfg *pCfg = REPO_CFG(pTsdb);
|
STsdbCfg *pCfg = REPO_CFG(pTsdb);
|
||||||
SSDataBlock *pData = (SSDataBlock *)msg;
|
const SArray *pDataBlocks = (const SArray *)msg;
|
||||||
SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pRSmaEnv);
|
SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pRSmaEnv);
|
||||||
int64_t indexUid = SMA_TEST_INDEX_UID;
|
int64_t indexUid = SMA_TEST_INDEX_UID;
|
||||||
|
|
||||||
|
@ -1030,15 +1081,15 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) {
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pData == NULL) {
|
if (pDataBlocks == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
terrno = TSDB_CODE_INVALID_PTR;
|
||||||
tsdbWarn("vgId:%d insert rSma data failed since pData is NULL", REPO_ID(pTsdb));
|
tsdbWarn("vgId:%d insert rSma data failed since pDataBlocks is NULL", REPO_ID(pTsdb));
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosArrayGetSize(pData->pDataBlock) <= 0) {
|
if (taosArrayGetSize(pDataBlocks) <= 0) {
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
tsdbWarn("vgId:%d insert rSma data failed since pDataBlock is empty", REPO_ID(pTsdb));
|
tsdbWarn("vgId:%d insert rSma data failed since pDataBlocks is empty", REPO_ID(pTsdb));
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1061,7 +1112,7 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) {
|
||||||
|
|
||||||
STSmaWriteH tSmaH = {0};
|
STSmaWriteH tSmaH = {0};
|
||||||
|
|
||||||
if (tsdbInitTSmaWriteH(&tSmaH, pTsdb, pData, pSma->interval, pSma->intervalUnit) != 0) {
|
if (tsdbInitTSmaWriteH(&tSmaH, pTsdb, pDataBlocks, pSma->interval, pSma->intervalUnit) != 0) {
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1119,7 +1170,7 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) {
|
||||||
*/
|
*/
|
||||||
static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, int64_t interval, int8_t intervalUnit) {
|
static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, int64_t interval, int8_t intervalUnit) {
|
||||||
pSmaH->pTsdb = pTsdb;
|
pSmaH->pTsdb = pTsdb;
|
||||||
pSmaH->interval = tsdbGetIntervalByPrecision(interval, intervalUnit, REPO_CFG(pTsdb)->precision);
|
pSmaH->interval = tsdbGetIntervalByPrecision(interval, intervalUnit, REPO_CFG(pTsdb)->precision, true);
|
||||||
pSmaH->storageLevel = tsdbGetSmaStorageLevel(interval, intervalUnit);
|
pSmaH->storageLevel = tsdbGetSmaStorageLevel(interval, intervalUnit);
|
||||||
pSmaH->days = tsdbGetTSmaDays(pTsdb, pSmaH->interval, pSmaH->storageLevel);
|
pSmaH->days = tsdbGetTSmaDays(pTsdb, pSmaH->interval, pSmaH->storageLevel);
|
||||||
}
|
}
|
||||||
|
@ -1185,17 +1236,11 @@ static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey) {
|
||||||
* @param pTsdb Return the data between queryWin and fill the pData.
|
* @param pTsdb Return the data between queryWin and fill the pData.
|
||||||
* @param pData
|
* @param pData
|
||||||
* @param indexUid
|
* @param indexUid
|
||||||
* @param interval
|
|
||||||
* @param intervalUnit
|
|
||||||
* @param tableUid
|
|
||||||
* @param colId
|
|
||||||
* @param pQuerySKey
|
* @param pQuerySKey
|
||||||
* @param nMaxResult The query invoker should control the nMaxResult need to return to avoid OOM.
|
* @param nMaxResult The query invoker should control the nMaxResult need to return to avoid OOM.
|
||||||
* @return int32_t
|
* @return int32_t
|
||||||
*/
|
*/
|
||||||
static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval,
|
static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid, TSKEY querySKey, int32_t nMaxResult) {
|
||||||
int8_t intervalUnit, tb_uid_t tableUid, col_id_t colId, TSKEY querySKey,
|
|
||||||
int32_t nMaxResult) {
|
|
||||||
SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pTSmaEnv);
|
SSmaEnv *pEnv = atomic_load_ptr(&pTsdb->pTSmaEnv);
|
||||||
|
|
||||||
if (!pEnv) {
|
if (!pEnv) {
|
||||||
|
@ -1243,14 +1288,19 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_
|
||||||
tsdbDebug("vgId:%d skey %" PRIi64 " of window not in expired window for index %" PRIi64, REPO_ID(pTsdb), querySKey,
|
tsdbDebug("vgId:%d skey %" PRIi64 " of window not in expired window for index %" PRIi64, REPO_ID(pTsdb), querySKey,
|
||||||
indexUid);
|
indexUid);
|
||||||
}
|
}
|
||||||
tsdbUnRefSmaStat(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv));
|
|
||||||
|
STSma *pTSma = pItem->pSma;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
STSmaReadH tReadH = {0};
|
STSmaReadH tReadH = {0};
|
||||||
tsdbInitTSmaReadH(&tReadH, pTsdb, interval, intervalUnit);
|
tsdbInitTSmaReadH(&tReadH, pTsdb, pTSma->interval, pTSma->intervalUnit);
|
||||||
tsdbCloseDBF(&tReadH.dFile);
|
tsdbCloseDBF(&tReadH.dFile);
|
||||||
|
|
||||||
|
tsdbUnRefSmaStat(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv));
|
||||||
|
|
||||||
tsdbInitTSmaFile(&tReadH, indexUid, querySKey);
|
tsdbInitTSmaFile(&tReadH, indexUid, querySKey);
|
||||||
if (tsdbOpenDBF(SMA_ENV_ENV(pTsdb->pTSmaEnv), &tReadH.dFile) != 0) {
|
if (tsdbOpenDBF(SMA_ENV_ENV(pTsdb->pTSmaEnv), &tReadH.dFile) != 0) {
|
||||||
tsdbWarn("vgId:%d open DBF %s failed since %s", REPO_ID(pTsdb), tReadH.dFile.path, tstrerror(terrno));
|
tsdbWarn("vgId:%d open DBF %s failed since %s", REPO_ID(pTsdb), tReadH.dFile.path, tstrerror(terrno));
|
||||||
|
@ -1259,19 +1309,17 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_
|
||||||
|
|
||||||
char smaKey[SMA_KEY_LEN] = {0};
|
char smaKey[SMA_KEY_LEN] = {0};
|
||||||
void *pSmaKey = &smaKey;
|
void *pSmaKey = &smaKey;
|
||||||
tsdbEncodeTSmaKey(tableUid, colId, querySKey, (void **)&pSmaKey);
|
int64_t queryGroupId = 1;
|
||||||
|
tsdbEncodeTSmaKey(queryGroupId, querySKey, (void **)&pSmaKey);
|
||||||
|
|
||||||
tsdbDebug("vgId:%d get sma data from %s: smaKey %" PRIx64 "-%" PRIu16 "-%" PRIx64 ", keyLen %d", REPO_ID(pTsdb),
|
tsdbDebug("vgId:%d get sma data from %s: smaKey %" PRIx64 "-%" PRIx64 ", keyLen %d", REPO_ID(pTsdb),
|
||||||
tReadH.dFile.path, *(tb_uid_t *)smaKey, *(uint16_t *)POINTER_SHIFT(smaKey, 8),
|
tReadH.dFile.path, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), SMA_KEY_LEN);
|
||||||
*(int64_t *)POINTER_SHIFT(smaKey, 10), SMA_KEY_LEN);
|
|
||||||
|
|
||||||
void *result = NULL;
|
void *result = NULL;
|
||||||
uint32_t valueSize = 0;
|
uint32_t valueSize = 0;
|
||||||
if ((result = tsdbGetSmaDataByKey(&tReadH.dFile, smaKey, SMA_KEY_LEN, &valueSize)) == NULL) {
|
if ((result = tsdbGetSmaDataByKey(&tReadH.dFile, smaKey, SMA_KEY_LEN, &valueSize)) == NULL) {
|
||||||
tsdbWarn("vgId:%d get sma data failed from smaIndex %" PRIi64 ", smaKey %" PRIx64 "-%" PRIu16 "-%" PRIx64
|
tsdbWarn("vgId:%d get sma data failed from smaIndex %" PRIi64 ", smaKey %" PRIx64 "-%" PRIx64 " since %s",
|
||||||
" since %s",
|
REPO_ID(pTsdb), indexUid, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), tstrerror(terrno));
|
||||||
REPO_ID(pTsdb), indexUid, *(tb_uid_t *)smaKey, *(uint16_t *)POINTER_SHIFT(smaKey, 8),
|
|
||||||
*(int64_t *)POINTER_SHIFT(smaKey, 10), tstrerror(terrno));
|
|
||||||
tsdbCloseDBF(&tReadH.dFile);
|
tsdbCloseDBF(&tReadH.dFile);
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
@ -1347,11 +1395,10 @@ int32_t tsdbRemoveTSmaData(STsdb *pTsdb, void *smaIndex, STimeWindow *pWin) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// TODO: Who is responsible for resource allocate and release?
|
// TODO: Who is responsible for resource allocate and release?
|
||||||
int32_t tsdbInsertTSmaData(STsdb *pTsdb, char *msg) {
|
int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
if ((code = tsdbInsertTSmaDataImpl(pTsdb, 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));
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
|
@ -1373,18 +1420,14 @@ int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t tsdbGetTSmaData(STsdb *pTsdb, char*pData, int64_t indexUid, TSKEY querySKey, int32_t nMaxResult) {
|
||||||
int32_t tsdbGetTSmaData(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval, int8_t intervalUnit,
|
|
||||||
tb_uid_t tableUid, col_id_t colId, TSKEY querySKey, int32_t nMaxResult) {
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
if ((code = tsdbGetTSmaDataImpl(pTsdb, pData, indexUid, interval, intervalUnit, tableUid, colId, querySKey,
|
if ((code = tsdbGetTSmaDataImpl(pTsdb, pData, indexUid, querySKey, nMaxResult)) < 0) {
|
||||||
nMaxResult)) < 0) {
|
|
||||||
tsdbWarn("vgId:%d get tSma data failed since %s", REPO_ID(pTsdb), tstrerror(terrno));
|
tsdbWarn("vgId:%d get tSma data failed since %s", REPO_ID(pTsdb), tstrerror(terrno));
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t tsdbDropTSmaData(STsdb *pTsdb, int64_t indexUid) {
|
int32_t tsdbDropTSmaData(STsdb *pTsdb, int64_t indexUid) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
if ((code = tsdbDropTSmaDataImpl(pTsdb, indexUid)) < 0) {
|
if ((code = tsdbDropTSmaDataImpl(pTsdb, indexUid)) < 0) {
|
||||||
|
|
|
@ -41,7 +41,7 @@ int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
|
||||||
vTrace("message in fetch queue is processing");
|
vTrace("message in fetch queue is processing");
|
||||||
char *msgstr = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
|
char *msgstr = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
|
||||||
int32_t msgLen = pMsg->contLen - sizeof(SMsgHead);
|
int32_t msgLen = pMsg->contLen - sizeof(SMsgHead);
|
||||||
|
@ -69,9 +69,9 @@ int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||||
return tqProcessPollReq(pVnode->pTq, pMsg);
|
return tqProcessPollReq(pVnode->pTq, pMsg);
|
||||||
case TDMT_VND_TASK_PIPE_EXEC:
|
case TDMT_VND_TASK_PIPE_EXEC:
|
||||||
case TDMT_VND_TASK_MERGE_EXEC:
|
case TDMT_VND_TASK_MERGE_EXEC:
|
||||||
return tqProcessTaskExec(pVnode->pTq, msgstr, msgLen);
|
return tqProcessTaskExec(pVnode->pTq, msgstr, msgLen, pInfo->workerId);
|
||||||
case TDMT_VND_STREAM_TRIGGER:
|
case TDMT_VND_STREAM_TRIGGER:
|
||||||
return tqProcessStreamTrigger(pVnode->pTq, pMsg->pCont, pMsg->contLen);
|
return tqProcessStreamTrigger(pVnode->pTq, pMsg->pCont, pMsg->contLen, pInfo->workerId);
|
||||||
case TDMT_VND_QUERY_HEARTBEAT:
|
case TDMT_VND_QUERY_HEARTBEAT:
|
||||||
return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg);
|
return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg);
|
||||||
default:
|
default:
|
||||||
|
@ -205,8 +205,7 @@ _exit:
|
||||||
rpcMsg.contLen = rspLen;
|
rpcMsg.contLen = rspLen;
|
||||||
rpcMsg.code = code;
|
rpcMsg.code = code;
|
||||||
|
|
||||||
rpcSendResponse(&rpcMsg);
|
tmsgSendRsp(&rpcMsg);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,8 +275,7 @@ static int32_t vnodeGetTableList(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||||
.code = 0,
|
.code = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
rpcSendResponse(&rpcMsg);
|
tmsgSendRsp(&rpcMsg);
|
||||||
|
|
||||||
taosArrayDestroyEx(pArray, freeItemHelper);
|
taosArrayDestroyEx(pArray, freeItemHelper);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,9 @@
|
||||||
|
|
||||||
void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) {
|
void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) {
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
blockDebugShowData(data);
|
blockDebugShowData(data);
|
||||||
|
tsdbInsertTSmaData(((SVnode *)pVnode)->pTsdb, smaId, (const char *)data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) {
|
void vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) {
|
||||||
|
@ -184,8 +186,8 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case TDMT_VND_TASK_WRITE_EXEC: {
|
case TDMT_VND_TASK_WRITE_EXEC: {
|
||||||
if (tqProcessTaskExec(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)),
|
if (tqProcessTaskExec(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), pMsg->contLen - sizeof(SMsgHead),
|
||||||
pMsg->contLen - sizeof(SMsgHead)) < 0) {
|
0) < 0) {
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case TDMT_VND_CREATE_SMA: { // timeRangeSMA
|
case TDMT_VND_CREATE_SMA: { // timeRangeSMA
|
||||||
|
@ -194,14 +196,15 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||||
SSmaCfg vCreateSmaReq = {0};
|
SSmaCfg vCreateSmaReq = {0};
|
||||||
if (tDeserializeSVCreateTSmaReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vCreateSmaReq) == NULL) {
|
if (tDeserializeSVCreateTSmaReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vCreateSmaReq) == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
vWarn("vgId%d: TDMT_VND_CREATE_SMA received but deserialize failed since %s", pVnode->config.vgId, terrstr(terrno));
|
vWarn("vgId%d: TDMT_VND_CREATE_SMA received but deserialize failed since %s", pVnode->config.vgId,
|
||||||
|
terrstr(terrno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
vWarn("vgId%d: TDMT_VND_CREATE_SMA received for %s:%" PRIi64, pVnode->config.vgId, vCreateSmaReq.tSma.indexName,
|
vWarn("vgId%d: TDMT_VND_CREATE_SMA received for %s:%" PRIi64, pVnode->config.vgId, vCreateSmaReq.tSma.indexName,
|
||||||
vCreateSmaReq.tSma.indexUid);
|
vCreateSmaReq.tSma.indexUid);
|
||||||
|
|
||||||
// record current timezone of server side
|
// record current timezone of server side
|
||||||
tstrncpy(vCreateSmaReq.tSma.timezone, tsTimezoneStr, TD_TIMEZONE_LEN);
|
vCreateSmaReq.tSma.timezoneInt = tsTimezone;
|
||||||
|
|
||||||
if (metaCreateTSma(pVnode->pMeta, &vCreateSmaReq) < 0) {
|
if (metaCreateTSma(pVnode->pMeta, &vCreateSmaReq) < 0) {
|
||||||
// TODO: handle error
|
// TODO: handle error
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <tsdbDef.h>
|
#include <tsdbDef.h>
|
||||||
|
|
||||||
#include <taoserror.h>
|
#include <taoserror.h>
|
||||||
#include <tglobal.h>
|
#include <tglobal.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -58,20 +59,21 @@ TEST(testCase, unionEncodeDecodeTest) {
|
||||||
|
|
||||||
void *buf = taosMemoryMalloc(1024);
|
void *buf = taosMemoryMalloc(1024);
|
||||||
void *pBuf = buf;
|
void *pBuf = buf;
|
||||||
|
void *qBuf = buf;
|
||||||
int32_t tlen = 0;
|
int32_t tlen = 0;
|
||||||
tlen += taosEncodeFixedU8(&buf, sut.info);
|
tlen += taosEncodeFixedU8(&pBuf, sut.info);
|
||||||
tlen += taosEncodeFixedI16(&buf, sut.nBSmaCols);
|
tlen += taosEncodeFixedI16(&pBuf, sut.nBSmaCols);
|
||||||
for (col_id_t i = 0; i < sut.nBSmaCols; ++i) {
|
for (col_id_t i = 0; i < sut.nBSmaCols; ++i) {
|
||||||
tlen += taosEncodeFixedI16(&buf, sut.pBSmaCols[i]);
|
tlen += taosEncodeFixedI16(&pBuf, sut.pBSmaCols[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
SUnionTest dut = {0};
|
SUnionTest dut = {0};
|
||||||
pBuf = taosDecodeFixedU8(pBuf, &dut.info);
|
qBuf = taosDecodeFixedU8(qBuf, &dut.info);
|
||||||
pBuf = taosDecodeFixedI16(pBuf, &dut.nBSmaCols);
|
qBuf = taosDecodeFixedI16(qBuf, &dut.nBSmaCols);
|
||||||
if (dut.nBSmaCols > 0) {
|
if (dut.nBSmaCols > 0) {
|
||||||
dut.pBSmaCols = (col_id_t *)taosMemoryMalloc(dut.nBSmaCols * sizeof(col_id_t));
|
dut.pBSmaCols = (col_id_t *)taosMemoryMalloc(dut.nBSmaCols * sizeof(col_id_t));
|
||||||
for (col_id_t i = 0; i < dut.nBSmaCols; ++i) {
|
for (col_id_t i = 0; i < dut.nBSmaCols; ++i) {
|
||||||
pBuf = taosDecodeFixedI16(pBuf, dut.pBSmaCols + i);
|
qBuf = taosDecodeFixedI16(qBuf, dut.pBSmaCols + i);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dut.pBSmaCols = NULL;
|
dut.pBSmaCols = NULL;
|
||||||
|
@ -80,13 +82,17 @@ TEST(testCase, unionEncodeDecodeTest) {
|
||||||
printf("sut.rollup=%" PRIu8 ", type=%" PRIu8 ", info=%" PRIu8 "\n", sut.rollup, sut.type, sut.info);
|
printf("sut.rollup=%" PRIu8 ", type=%" PRIu8 ", info=%" PRIu8 "\n", sut.rollup, sut.type, sut.info);
|
||||||
printf("dut.rollup=%" PRIu8 ", type=%" PRIu8 ", info=%" PRIu8 "\n", dut.rollup, dut.type, dut.info);
|
printf("dut.rollup=%" PRIu8 ", type=%" PRIu8 ", info=%" PRIu8 "\n", dut.rollup, dut.type, dut.info);
|
||||||
|
|
||||||
ASSERT_EQ(sut.rollup, dut.rollup);
|
EXPECT_EQ(sut.rollup, dut.rollup);
|
||||||
ASSERT_EQ(sut.type, dut.type);
|
EXPECT_EQ(sut.type, dut.type);
|
||||||
ASSERT_EQ(sut.nBSmaCols, dut.nBSmaCols);
|
EXPECT_EQ(sut.nBSmaCols, dut.nBSmaCols);
|
||||||
for (col_id_t i = 0; i < sut.nBSmaCols; ++i) {
|
for (col_id_t i = 0; i < sut.nBSmaCols; ++i) {
|
||||||
ASSERT_EQ(*(col_id_t *)(sut.pBSmaCols + i), sut.pBSmaCols[i]);
|
EXPECT_EQ(*(col_id_t *)(sut.pBSmaCols + i), sut.pBSmaCols[i]);
|
||||||
ASSERT_EQ(*(col_id_t *)(sut.pBSmaCols + i), dut.pBSmaCols[i]);
|
EXPECT_EQ(*(col_id_t *)(sut.pBSmaCols + i), dut.pBSmaCols[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
taosMemoryFreeClear(buf);
|
||||||
|
taosMemoryFreeClear(dut.pBSmaCols);
|
||||||
|
taosMemoryFreeClear(sut.pBSmaCols);
|
||||||
}
|
}
|
||||||
#if 1
|
#if 1
|
||||||
TEST(testCase, tSma_Meta_Encode_Decode_Test) {
|
TEST(testCase, tSma_Meta_Encode_Decode_Test) {
|
||||||
|
@ -106,37 +112,37 @@ TEST(testCase, tSma_Meta_Encode_Decode_Test) {
|
||||||
uint32_t bufLen = tEncodeTSmaWrapper(NULL, &tSmaWrapper);
|
uint32_t bufLen = tEncodeTSmaWrapper(NULL, &tSmaWrapper);
|
||||||
|
|
||||||
void *buf = taosMemoryCalloc(1, bufLen);
|
void *buf = taosMemoryCalloc(1, bufLen);
|
||||||
ASSERT_NE(buf, nullptr);
|
EXPECT_NE(buf, nullptr);
|
||||||
|
|
||||||
STSmaWrapper *pSW = (STSmaWrapper *)buf;
|
STSmaWrapper *pSW = (STSmaWrapper *)buf;
|
||||||
uint32_t len = tEncodeTSmaWrapper(&buf, &tSmaWrapper);
|
uint32_t len = tEncodeTSmaWrapper(&buf, &tSmaWrapper);
|
||||||
|
|
||||||
ASSERT_EQ(len, bufLen);
|
EXPECT_EQ(len, bufLen);
|
||||||
|
|
||||||
// decode
|
// decode
|
||||||
STSmaWrapper dstTSmaWrapper = {0};
|
STSmaWrapper dstTSmaWrapper = {0};
|
||||||
void *result = tDecodeTSmaWrapper(pSW, &dstTSmaWrapper);
|
void *result = tDecodeTSmaWrapper(pSW, &dstTSmaWrapper);
|
||||||
ASSERT_NE(result, nullptr);
|
EXPECT_NE(result, nullptr);
|
||||||
|
|
||||||
ASSERT_EQ(tSmaWrapper.number, dstTSmaWrapper.number);
|
EXPECT_EQ(tSmaWrapper.number, dstTSmaWrapper.number);
|
||||||
|
|
||||||
for (int i = 0; i < tSmaWrapper.number; ++i) {
|
for (int i = 0; i < tSmaWrapper.number; ++i) {
|
||||||
STSma *pSma = tSmaWrapper.tSma + i;
|
STSma *pSma = tSmaWrapper.tSma + i;
|
||||||
STSma *qSma = dstTSmaWrapper.tSma + i;
|
STSma *qSma = dstTSmaWrapper.tSma + i;
|
||||||
|
|
||||||
ASSERT_EQ(pSma->version, qSma->version);
|
EXPECT_EQ(pSma->version, qSma->version);
|
||||||
ASSERT_EQ(pSma->intervalUnit, qSma->intervalUnit);
|
EXPECT_EQ(pSma->intervalUnit, qSma->intervalUnit);
|
||||||
ASSERT_EQ(pSma->slidingUnit, qSma->slidingUnit);
|
EXPECT_EQ(pSma->slidingUnit, qSma->slidingUnit);
|
||||||
ASSERT_STRCASEEQ(pSma->indexName, qSma->indexName);
|
EXPECT_STRCASEEQ(pSma->indexName, qSma->indexName);
|
||||||
ASSERT_EQ(pSma->timezoneInt, qSma->timezoneInt);
|
EXPECT_EQ(pSma->timezoneInt, qSma->timezoneInt);
|
||||||
ASSERT_EQ(pSma->indexUid, qSma->indexUid);
|
EXPECT_EQ(pSma->indexUid, qSma->indexUid);
|
||||||
ASSERT_EQ(pSma->tableUid, qSma->tableUid);
|
EXPECT_EQ(pSma->tableUid, qSma->tableUid);
|
||||||
ASSERT_EQ(pSma->interval, qSma->interval);
|
EXPECT_EQ(pSma->interval, qSma->interval);
|
||||||
ASSERT_EQ(pSma->sliding, qSma->sliding);
|
EXPECT_EQ(pSma->sliding, qSma->sliding);
|
||||||
ASSERT_EQ(pSma->exprLen, qSma->exprLen);
|
EXPECT_EQ(pSma->exprLen, qSma->exprLen);
|
||||||
ASSERT_STRCASEEQ(pSma->expr, qSma->expr);
|
EXPECT_STRCASEEQ(pSma->expr, qSma->expr);
|
||||||
ASSERT_EQ(pSma->tagsFilterLen, qSma->tagsFilterLen);
|
EXPECT_EQ(pSma->tagsFilterLen, qSma->tagsFilterLen);
|
||||||
ASSERT_STRCASEEQ(pSma->tagsFilter, qSma->tagsFilter);
|
EXPECT_STRCASEEQ(pSma->tagsFilter, qSma->tagsFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// resource release
|
// resource release
|
||||||
|
@ -172,12 +178,12 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
||||||
|
|
||||||
tSma.exprLen = strlen(expr);
|
tSma.exprLen = strlen(expr);
|
||||||
tSma.expr = (char *)taosMemoryCalloc(1, tSma.exprLen + 1);
|
tSma.expr = (char *)taosMemoryCalloc(1, tSma.exprLen + 1);
|
||||||
ASSERT_NE(tSma.expr, nullptr);
|
EXPECT_NE(tSma.expr, nullptr);
|
||||||
tstrncpy(tSma.expr, expr, tSma.exprLen + 1);
|
tstrncpy(tSma.expr, expr, tSma.exprLen + 1);
|
||||||
|
|
||||||
tSma.tagsFilterLen = strlen(tagsFilter);
|
tSma.tagsFilterLen = strlen(tagsFilter);
|
||||||
tSma.tagsFilter = (char *)taosMemoryCalloc(tSma.tagsFilterLen + 1, 1);
|
tSma.tagsFilter = (char *)taosMemoryCalloc(tSma.tagsFilterLen + 1, 1);
|
||||||
ASSERT_NE(tSma.tagsFilter, nullptr);
|
EXPECT_NE(tSma.tagsFilter, nullptr);
|
||||||
tstrncpy(tSma.tagsFilter, tagsFilter, tSma.tagsFilterLen + 1);
|
tstrncpy(tSma.tagsFilter, tagsFilter, tSma.tagsFilterLen + 1);
|
||||||
|
|
||||||
SMeta *pMeta = NULL;
|
SMeta *pMeta = NULL;
|
||||||
|
@ -189,7 +195,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
||||||
pMeta = metaOpen(smaTestDir, pMetaCfg, NULL);
|
pMeta = metaOpen(smaTestDir, pMetaCfg, NULL);
|
||||||
assert(pMeta != NULL);
|
assert(pMeta != NULL);
|
||||||
// save index 1
|
// save index 1
|
||||||
ASSERT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0);
|
EXPECT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0);
|
||||||
|
|
||||||
pSmaCfg->indexUid = indexUid2;
|
pSmaCfg->indexUid = indexUid2;
|
||||||
tstrncpy(pSmaCfg->indexName, smaIndexName2, TSDB_INDEX_NAME_LEN);
|
tstrncpy(pSmaCfg->indexName, smaIndexName2, TSDB_INDEX_NAME_LEN);
|
||||||
|
@ -200,7 +206,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
||||||
pSmaCfg->sliding = 5;
|
pSmaCfg->sliding = 5;
|
||||||
|
|
||||||
// save index 2
|
// save index 2
|
||||||
ASSERT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0);
|
EXPECT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0);
|
||||||
|
|
||||||
// get value by indexName
|
// get value by indexName
|
||||||
STSma *qSmaCfg = NULL;
|
STSma *qSmaCfg = NULL;
|
||||||
|
@ -210,8 +216,8 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
||||||
printf("timezone1 = %" PRIi8 "\n", qSmaCfg->timezoneInt);
|
printf("timezone1 = %" PRIi8 "\n", qSmaCfg->timezoneInt);
|
||||||
printf("expr1 = %s\n", qSmaCfg->expr != NULL ? qSmaCfg->expr : "");
|
printf("expr1 = %s\n", qSmaCfg->expr != NULL ? qSmaCfg->expr : "");
|
||||||
printf("tagsFilter1 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : "");
|
printf("tagsFilter1 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : "");
|
||||||
ASSERT_STRCASEEQ(qSmaCfg->indexName, smaIndexName1);
|
EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName1);
|
||||||
ASSERT_EQ(qSmaCfg->tableUid, tSma.tableUid);
|
EXPECT_EQ(qSmaCfg->tableUid, tSma.tableUid);
|
||||||
tdDestroyTSma(qSmaCfg);
|
tdDestroyTSma(qSmaCfg);
|
||||||
taosMemoryFreeClear(qSmaCfg);
|
taosMemoryFreeClear(qSmaCfg);
|
||||||
|
|
||||||
|
@ -221,8 +227,8 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
||||||
printf("timezone2 = %" PRIi8 "\n", qSmaCfg->timezoneInt);
|
printf("timezone2 = %" PRIi8 "\n", qSmaCfg->timezoneInt);
|
||||||
printf("expr2 = %s\n", qSmaCfg->expr != NULL ? qSmaCfg->expr : "");
|
printf("expr2 = %s\n", qSmaCfg->expr != NULL ? qSmaCfg->expr : "");
|
||||||
printf("tagsFilter2 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : "");
|
printf("tagsFilter2 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : "");
|
||||||
ASSERT_STRCASEEQ(qSmaCfg->indexName, smaIndexName2);
|
EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName2);
|
||||||
ASSERT_EQ(qSmaCfg->interval, tSma.interval);
|
EXPECT_EQ(qSmaCfg->interval, tSma.interval);
|
||||||
tdDestroyTSma(qSmaCfg);
|
tdDestroyTSma(qSmaCfg);
|
||||||
taosMemoryFreeClear(qSmaCfg);
|
taosMemoryFreeClear(qSmaCfg);
|
||||||
|
|
||||||
|
@ -238,25 +244,25 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
||||||
printf("indexName = %s\n", indexName);
|
printf("indexName = %s\n", indexName);
|
||||||
++indexCnt;
|
++indexCnt;
|
||||||
}
|
}
|
||||||
ASSERT_EQ(indexCnt, nCntTSma);
|
EXPECT_EQ(indexCnt, nCntTSma);
|
||||||
metaCloseSmaCurosr(pSmaCur);
|
metaCloseSmaCurosr(pSmaCur);
|
||||||
|
|
||||||
// get wrapper by table uid
|
// get wrapper by table uid
|
||||||
STSmaWrapper *pSW = metaGetSmaInfoByTable(pMeta, tbUid);
|
STSmaWrapper *pSW = metaGetSmaInfoByTable(pMeta, tbUid);
|
||||||
assert(pSW != NULL);
|
assert(pSW != NULL);
|
||||||
ASSERT_EQ(pSW->number, nCntTSma);
|
EXPECT_EQ(pSW->number, nCntTSma);
|
||||||
ASSERT_STRCASEEQ(pSW->tSma->indexName, smaIndexName1);
|
EXPECT_STRCASEEQ(pSW->tSma->indexName, smaIndexName1);
|
||||||
ASSERT_EQ(pSW->tSma->timezoneInt, timezone);
|
EXPECT_EQ(pSW->tSma->timezoneInt, timezone);
|
||||||
ASSERT_STRCASEEQ(pSW->tSma->expr, expr);
|
EXPECT_STRCASEEQ(pSW->tSma->expr, expr);
|
||||||
ASSERT_STRCASEEQ(pSW->tSma->tagsFilter, tagsFilter);
|
EXPECT_STRCASEEQ(pSW->tSma->tagsFilter, tagsFilter);
|
||||||
ASSERT_EQ(pSW->tSma->indexUid, indexUid1);
|
EXPECT_EQ(pSW->tSma->indexUid, indexUid1);
|
||||||
ASSERT_EQ(pSW->tSma->tableUid, tbUid);
|
EXPECT_EQ(pSW->tSma->tableUid, tbUid);
|
||||||
ASSERT_STRCASEEQ((pSW->tSma + 1)->indexName, smaIndexName2);
|
EXPECT_STRCASEEQ((pSW->tSma + 1)->indexName, smaIndexName2);
|
||||||
ASSERT_EQ((pSW->tSma + 1)->timezoneInt, timezone);
|
EXPECT_EQ((pSW->tSma + 1)->timezoneInt, timezone);
|
||||||
ASSERT_STRCASEEQ((pSW->tSma + 1)->expr, expr);
|
EXPECT_STRCASEEQ((pSW->tSma + 1)->expr, expr);
|
||||||
ASSERT_STRCASEEQ((pSW->tSma + 1)->tagsFilter, tagsFilter);
|
EXPECT_STRCASEEQ((pSW->tSma + 1)->tagsFilter, tagsFilter);
|
||||||
ASSERT_EQ((pSW->tSma + 1)->indexUid, indexUid2);
|
EXPECT_EQ((pSW->tSma + 1)->indexUid, indexUid2);
|
||||||
ASSERT_EQ((pSW->tSma + 1)->tableUid, tbUid);
|
EXPECT_EQ((pSW->tSma + 1)->tableUid, tbUid);
|
||||||
|
|
||||||
tdDestroyTSmaWrapper(pSW);
|
tdDestroyTSmaWrapper(pSW);
|
||||||
taosMemoryFreeClear(pSW);
|
taosMemoryFreeClear(pSW);
|
||||||
|
@ -268,7 +274,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
||||||
printf("metaGetSmaTbUids: uid[%" PRIu32 "] = %" PRIi64 "\n", i, *(tb_uid_t *)taosArrayGet(pUids, i));
|
printf("metaGetSmaTbUids: uid[%" PRIu32 "] = %" PRIi64 "\n", i, *(tb_uid_t *)taosArrayGet(pUids, i));
|
||||||
// printf("metaGetSmaTbUids: index[%" PRIu32 "] = %s", i, (char *)taosArrayGet(pUids, i));
|
// printf("metaGetSmaTbUids: index[%" PRIu32 "] = %s", i, (char *)taosArrayGet(pUids, i));
|
||||||
}
|
}
|
||||||
ASSERT_EQ(taosArrayGetSize(pUids), 1);
|
EXPECT_EQ(taosArrayGetSize(pUids), 1);
|
||||||
taosArrayDestroy(pUids);
|
taosArrayDestroy(pUids);
|
||||||
|
|
||||||
// resource release
|
// resource release
|
||||||
|
@ -280,7 +286,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 0
|
#if 1
|
||||||
TEST(testCase, tSma_Data_Insert_Query_Test) {
|
TEST(testCase, tSma_Data_Insert_Query_Test) {
|
||||||
// step 1: prepare meta
|
// step 1: prepare meta
|
||||||
const char *smaIndexName1 = "sma_index_test_1";
|
const char *smaIndexName1 = "sma_index_test_1";
|
||||||
|
@ -299,9 +305,9 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
||||||
// encode
|
// encode
|
||||||
STSma tSma = {0};
|
STSma tSma = {0};
|
||||||
tSma.version = 0;
|
tSma.version = 0;
|
||||||
tSma.intervalUnit = TIME_UNIT_DAY;
|
tSma.intervalUnit = TIME_UNIT_MINUTE;
|
||||||
tSma.interval = 1;
|
tSma.interval = 1;
|
||||||
tSma.slidingUnit = TIME_UNIT_HOUR;
|
tSma.slidingUnit = TIME_UNIT_MINUTE;
|
||||||
tSma.sliding = 1; // sliding = interval when it's convert window
|
tSma.sliding = 1; // sliding = interval when it's convert window
|
||||||
tSma.indexUid = indexUid1;
|
tSma.indexUid = indexUid1;
|
||||||
tstrncpy(tSma.indexName, smaIndexName1, TSDB_INDEX_NAME_LEN);
|
tstrncpy(tSma.indexName, smaIndexName1, TSDB_INDEX_NAME_LEN);
|
||||||
|
@ -310,12 +316,12 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
||||||
|
|
||||||
tSma.exprLen = strlen(expr);
|
tSma.exprLen = strlen(expr);
|
||||||
tSma.expr = (char *)taosMemoryCalloc(1, tSma.exprLen + 1);
|
tSma.expr = (char *)taosMemoryCalloc(1, tSma.exprLen + 1);
|
||||||
ASSERT_NE(tSma.expr, nullptr);
|
EXPECT_NE(tSma.expr, nullptr);
|
||||||
tstrncpy(tSma.expr, expr, tSma.exprLen + 1);
|
tstrncpy(tSma.expr, expr, tSma.exprLen + 1);
|
||||||
|
|
||||||
tSma.tagsFilterLen = strlen(tagsFilter);
|
tSma.tagsFilterLen = strlen(tagsFilter);
|
||||||
tSma.tagsFilter = (char *)taosMemoryCalloc(1, tSma.tagsFilterLen + 1);
|
tSma.tagsFilter = (char *)taosMemoryCalloc(1, tSma.tagsFilterLen + 1);
|
||||||
ASSERT_NE(tSma.tagsFilter, nullptr);
|
EXPECT_NE(tSma.tagsFilter, nullptr);
|
||||||
tstrncpy(tSma.tagsFilter, tagsFilter, tSma.tagsFilterLen + 1);
|
tstrncpy(tSma.tagsFilter, tagsFilter, tSma.tagsFilterLen + 1);
|
||||||
|
|
||||||
SMeta *pMeta = NULL;
|
SMeta *pMeta = NULL;
|
||||||
|
@ -327,7 +333,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
||||||
pMeta = metaOpen(smaTestDir, pMetaCfg, NULL);
|
pMeta = metaOpen(smaTestDir, pMetaCfg, NULL);
|
||||||
assert(pMeta != NULL);
|
assert(pMeta != NULL);
|
||||||
// save index 1
|
// save index 1
|
||||||
ASSERT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0);
|
EXPECT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0);
|
||||||
|
|
||||||
// step 2: insert data
|
// step 2: insert data
|
||||||
STsdb *pTsdb = (STsdb *)taosMemoryCalloc(1, sizeof(STsdb));
|
STsdb *pTsdb = (STsdb *)taosMemoryCalloc(1, sizeof(STsdb));
|
||||||
|
@ -364,7 +370,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
||||||
strncpy(pDisks.dir, "/var/lib/taos", TSDB_FILENAME_LEN);
|
strncpy(pDisks.dir, "/var/lib/taos", TSDB_FILENAME_LEN);
|
||||||
int32_t numOfDisks = 1;
|
int32_t numOfDisks = 1;
|
||||||
pTsdb->pTfs = tfsOpen(&pDisks, numOfDisks);
|
pTsdb->pTfs = tfsOpen(&pDisks, numOfDisks);
|
||||||
ASSERT_NE(pTsdb->pTfs, nullptr);
|
EXPECT_NE(pTsdb->pTfs, nullptr);
|
||||||
|
|
||||||
// generate SSubmitReq msg and update expired window
|
// generate SSubmitReq msg and update expired window
|
||||||
int16_t schemaVer = 0;
|
int16_t schemaVer = 0;
|
||||||
|
@ -374,7 +380,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
||||||
uint32_t msgLen = sizeof(SSubmitReq) + mockBlkNum * sizeof(SSubmitBlk) + mockBlkNum * mockRowNum * mockRowLen;
|
uint32_t msgLen = sizeof(SSubmitReq) + mockBlkNum * sizeof(SSubmitBlk) + mockBlkNum * mockRowNum * mockRowLen;
|
||||||
|
|
||||||
SSubmitReq *pMsg = (SSubmitReq *)taosMemoryCalloc(1, msgLen);
|
SSubmitReq *pMsg = (SSubmitReq *)taosMemoryCalloc(1, msgLen);
|
||||||
ASSERT_NE(pMsg, nullptr);
|
EXPECT_NE(pMsg, nullptr);
|
||||||
pMsg->version = htobe64(schemaVer);
|
pMsg->version = htobe64(schemaVer);
|
||||||
pMsg->numOfBlocks = htonl(mockBlkNum);
|
pMsg->numOfBlocks = htonl(mockBlkNum);
|
||||||
pMsg->length = htonl(msgLen);
|
pMsg->length = htonl(msgLen);
|
||||||
|
@ -400,20 +406,99 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT_EQ(tdScanAndConvertSubmitMsg(pMsg), TSDB_CODE_SUCCESS);
|
EXPECT_EQ(tdScanAndConvertSubmitMsg(pMsg), TSDB_CODE_SUCCESS);
|
||||||
|
|
||||||
ASSERT_EQ(tsdbUpdateSmaWindow(pTsdb, (const char *)pMsg), 0);
|
EXPECT_EQ(tsdbUpdateSmaWindow(pTsdb, (const char *)pMsg), 0);
|
||||||
|
|
||||||
// init
|
// init
|
||||||
int32_t allocCnt = 0;
|
const int32_t tSmaGroupSize = 4;
|
||||||
int32_t allocStep = 16384;
|
const int32_t tSmaNumOfTags = 2;
|
||||||
int32_t buffer = 1024;
|
const int64_t tSmaGroupId = 12345670;
|
||||||
void *buf = NULL;
|
const col_id_t tSmaNumOfCols = 9; // binary/nchar/varbinary/varchar are only used for tags for group by conditions.
|
||||||
ASSERT_EQ(tsdbMakeRoom(&buf, allocStep), 0);
|
const int32_t tSmaNumOfRows = 2;
|
||||||
int32_t bufSize = taosTSizeof(buf);
|
|
||||||
int32_t numOfTables = 10;
|
SArray *pDataBlocks = taosArrayInit(tSmaGroupSize, sizeof(SSDataBlock *));
|
||||||
col_id_t numOfCols = 4096;
|
EXPECT_NE(pDataBlocks, nullptr);
|
||||||
ASSERT_GT(numOfCols, 0);
|
int32_t tSmaTypeArray[tSmaNumOfCols] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_BOOL, TSDB_DATA_TYPE_INT,
|
||||||
|
TSDB_DATA_TYPE_UBIGINT, TSDB_DATA_TYPE_SMALLINT, TSDB_DATA_TYPE_FLOAT,
|
||||||
|
TSDB_DATA_TYPE_DOUBLE, TSDB_DATA_TYPE_VARCHAR, TSDB_DATA_TYPE_NCHAR};
|
||||||
|
// last 2 columns for group by tags
|
||||||
|
// int32_t tSmaTypeArray[tSmaNumOfCols] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_BOOL};
|
||||||
|
const char *tSmaGroupbyTags[tSmaGroupSize * tSmaNumOfTags] = {"BeiJing", "HaiDian", "BeiJing", "ChaoYang",
|
||||||
|
"ShangHai", "PuDong", "ShangHai", "MinHang"};
|
||||||
|
TSKEY tSmaSKeyMs = (int64_t)1648535332 * 1000;
|
||||||
|
int64_t tSmaIntervalMs = tSma.interval * 60 * 1000;
|
||||||
|
int64_t tSmaInitVal = 0;
|
||||||
|
|
||||||
|
for (int32_t g = 0; g < tSmaGroupSize; ++g) {
|
||||||
|
SSDataBlock *pDataBlock = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||||
|
EXPECT_NE(pDataBlock, nullptr);
|
||||||
|
pDataBlock->pBlockAgg = NULL;
|
||||||
|
pDataBlock->info.numOfCols = tSmaNumOfCols;
|
||||||
|
pDataBlock->info.rows = tSmaNumOfRows;
|
||||||
|
pDataBlock->info.groupId = tSmaGroupId + g;
|
||||||
|
|
||||||
|
pDataBlock->pDataBlock = taosArrayInit(tSmaNumOfCols, sizeof(SColumnInfoData *));
|
||||||
|
EXPECT_NE(pDataBlock->pDataBlock, nullptr);
|
||||||
|
for (int32_t c = 0; c < tSmaNumOfCols; ++c) {
|
||||||
|
|
||||||
|
SColumnInfoData *pColInfoData = (SColumnInfoData *)taosMemoryCalloc(1, sizeof(SColumnInfoData));
|
||||||
|
EXPECT_NE(pColInfoData, nullptr);
|
||||||
|
|
||||||
|
pColInfoData->info.type = tSmaTypeArray[c];
|
||||||
|
if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) {
|
||||||
|
pColInfoData->info.bytes = 100; // update accordingly
|
||||||
|
} else {
|
||||||
|
pColInfoData->info.bytes = TYPE_BYTES[pColInfoData->info.type];
|
||||||
|
}
|
||||||
|
pColInfoData->pData = (char *)taosMemoryCalloc(1, tSmaNumOfRows * pColInfoData->info.bytes);
|
||||||
|
|
||||||
|
for (int32_t r = 0; r < tSmaNumOfRows; ++r) {
|
||||||
|
void *pCellData = pColInfoData->pData + r * pColInfoData->info.bytes;
|
||||||
|
switch (pColInfoData->info.type) {
|
||||||
|
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
|
*(TSKEY *)pCellData = tSmaSKeyMs + tSmaIntervalMs * r;
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_BOOL:
|
||||||
|
*(bool *)pCellData = (bool)tSmaInitVal++;
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_INT:
|
||||||
|
*(int *)pCellData = (int)tSmaInitVal++;
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_UBIGINT:
|
||||||
|
*(uint64_t *)pCellData = (uint64_t)tSmaInitVal++;
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_SMALLINT:
|
||||||
|
*(int16_t *)pCellData = (int16_t)tSmaInitVal++;
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_FLOAT:
|
||||||
|
*(float *)pCellData = (float)tSmaInitVal++;
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_DOUBLE:
|
||||||
|
*(double *)pCellData = (double)tSmaInitVal++;
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_VARCHAR: // city
|
||||||
|
varDataSetLen(pCellData, strlen(tSmaGroupbyTags[g * 2]));
|
||||||
|
memcpy(varDataVal(pCellData), tSmaGroupbyTags[g * 2], varDataLen(pCellData));
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_NCHAR: // district
|
||||||
|
varDataSetLen(pCellData, strlen(tSmaGroupbyTags[g * 2 + 1]));
|
||||||
|
memcpy(varDataVal(pCellData), tSmaGroupbyTags[g * 2 + 1], varDataLen(pCellData));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
EXPECT_EQ(0, 1); // add definition
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// push SColumnInfoData
|
||||||
|
taosArrayPush(pDataBlock->pDataBlock, &pColInfoData);
|
||||||
|
}
|
||||||
|
// push SSDataBlock
|
||||||
|
taosArrayPush(pDataBlocks, &pDataBlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
// execute
|
||||||
|
EXPECT_EQ(tsdbInsertTSmaData(pTsdb, tSma.indexUid, (const char *)pDataBlocks), TSDB_CODE_SUCCESS);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
STSmaDataWrapper *pSmaData = NULL;
|
STSmaDataWrapper *pSmaData = NULL;
|
||||||
|
@ -432,7 +517,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
||||||
int32_t tableDataLen = sizeof(STSmaTbData);
|
int32_t tableDataLen = sizeof(STSmaTbData);
|
||||||
for (col_id_t c = 0; c < numOfCols; ++c) {
|
for (col_id_t c = 0; c < numOfCols; ++c) {
|
||||||
if (bufSize - len - tableDataLen < buffer) {
|
if (bufSize - len - tableDataLen < buffer) {
|
||||||
ASSERT_EQ(tsdbMakeRoom(&buf, bufSize + allocStep), 0);
|
EXPECT_EQ(tsdbMakeRoom(&buf, bufSize + allocStep), 0);
|
||||||
pSmaData = (STSmaDataWrapper *)buf;
|
pSmaData = (STSmaDataWrapper *)buf;
|
||||||
pTbData = (STSmaTbData *)POINTER_SHIFT(pSmaData, len);
|
pTbData = (STSmaTbData *)POINTER_SHIFT(pSmaData, len);
|
||||||
bufSize = taosTSizeof(buf);
|
bufSize = taosTSizeof(buf);
|
||||||
|
@ -459,31 +544,36 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
||||||
}
|
}
|
||||||
pSmaData->dataLen = (len - sizeof(STSmaDataWrapper));
|
pSmaData->dataLen = (len - sizeof(STSmaDataWrapper));
|
||||||
|
|
||||||
ASSERT_GE(bufSize, pSmaData->dataLen);
|
EXPECT_GE(bufSize, pSmaData->dataLen);
|
||||||
// execute
|
// execute
|
||||||
ASSERT_EQ(tsdbInsertTSmaData(pTsdb, (char *)pSmaData), TSDB_CODE_SUCCESS);
|
EXPECT_EQ(tsdbInsertTSmaData(pTsdb, (char *)pSmaData), TSDB_CODE_SUCCESS);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SSDataBlock *pSmaData = (SSDataBlock *)taosMemoryCalloc(1, sizeof(SSDataBlock));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// step 3: query
|
// step 3: query
|
||||||
uint32_t checkDataCnt = 0;
|
uint32_t checkDataCnt = 0;
|
||||||
for (int32_t t = 0; t < numOfTables; ++t) {
|
EXPECT_EQ(tsdbGetTSmaData(pTsdb, NULL, indexUid1, skey1, 1), TSDB_CODE_SUCCESS);
|
||||||
for (col_id_t c = 0; c < numOfCols; ++c) {
|
|
||||||
ASSERT_EQ(tsdbGetTSmaData(pTsdb, NULL, indexUid1, interval1, intervalUnit1, tbUid + t,
|
|
||||||
c + PRIMARYKEY_TIMESTAMP_COL_ID, skey1, 1),
|
|
||||||
TSDB_CODE_SUCCESS);
|
|
||||||
++checkDataCnt;
|
++checkDataCnt;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("%s:%d The sma data check count for insert and query is %" PRIu32 "\n", __FILE__, __LINE__, checkDataCnt);
|
printf("%s:%d The sma data check count for insert and query is %" PRIu32 "\n", __FILE__, __LINE__, checkDataCnt);
|
||||||
|
|
||||||
// release data
|
// release data
|
||||||
taosMemoryFreeClear(pMsg);
|
taosMemoryFreeClear(pMsg);
|
||||||
taosTZfree(buf);
|
|
||||||
|
for (int32_t i = 0; i < taosArrayGetSize(pDataBlocks); ++i) {
|
||||||
|
SSDataBlock *pDataBlock = *(SSDataBlock **)taosArrayGet(pDataBlocks, i);
|
||||||
|
int32_t numOfOutput = taosArrayGetSize(pDataBlock->pDataBlock);
|
||||||
|
for (int32_t j = 0; j < numOfOutput; ++j) {
|
||||||
|
SColumnInfoData *pColInfoData = *(SColumnInfoData **)taosArrayGet(pDataBlock->pDataBlock, j);
|
||||||
|
colDataDestroy(pColInfoData);
|
||||||
|
taosMemoryFreeClear(pColInfoData);
|
||||||
|
}
|
||||||
|
|
||||||
|
taosArrayDestroy(pDataBlock->pDataBlock);
|
||||||
|
taosMemoryFreeClear(pDataBlock->pBlockAgg);
|
||||||
|
taosMemoryFreeClear(pDataBlock);
|
||||||
|
}
|
||||||
|
taosArrayDestroy(pDataBlocks);
|
||||||
|
|
||||||
// release meta
|
// release meta
|
||||||
tdDestroyTSma(&tSma);
|
tdDestroyTSma(&tSma);
|
||||||
tfsClose(pTsdb->pTfs);
|
tfsClose(pTsdb->pTfs);
|
||||||
|
|
|
@ -161,20 +161,8 @@ typedef struct STaskCostInfo {
|
||||||
typedef struct SOperatorCostInfo {
|
typedef struct SOperatorCostInfo {
|
||||||
uint64_t openCost;
|
uint64_t openCost;
|
||||||
uint64_t execCost;
|
uint64_t execCost;
|
||||||
// uint64_t totalRows;
|
|
||||||
// uint64_t totalBytes;
|
|
||||||
} SOperatorCostInfo;
|
} SOperatorCostInfo;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int64_t vgroupLimit;
|
|
||||||
int64_t ts;
|
|
||||||
} SOrderedPrjQueryInfo;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
char* tags;
|
|
||||||
SArray* pResult; // SArray<SStddevInterResult>
|
|
||||||
} SInterResult;
|
|
||||||
|
|
||||||
// The basic query information extracted from the SQueryInfo tree to support the
|
// The basic query information extracted from the SQueryInfo tree to support the
|
||||||
// execution of query in a data node.
|
// execution of query in a data node.
|
||||||
typedef struct STaskAttr {
|
typedef struct STaskAttr {
|
||||||
|
@ -230,7 +218,6 @@ typedef struct STaskAttr {
|
||||||
SColumnInfo* tagColList;
|
SColumnInfo* tagColList;
|
||||||
int32_t numOfFilterCols;
|
int32_t numOfFilterCols;
|
||||||
int64_t* fillVal;
|
int64_t* fillVal;
|
||||||
SOrderedPrjQueryInfo prjInfo; // limit value for each vgroup, only available in global order projection query.
|
|
||||||
|
|
||||||
SSingleColumnFilterInfo* pFilterInfo;
|
SSingleColumnFilterInfo* pFilterInfo;
|
||||||
// SFilterInfo *pFilters;
|
// SFilterInfo *pFilters;
|
||||||
|
@ -245,8 +232,9 @@ struct SOperatorInfo;
|
||||||
|
|
||||||
typedef void (*__optr_encode_fn_t)(struct SOperatorInfo* pOperator, char **result, int32_t *length);
|
typedef void (*__optr_encode_fn_t)(struct SOperatorInfo* pOperator, char **result, int32_t *length);
|
||||||
typedef bool (*__optr_decode_fn_t)(struct SOperatorInfo* pOperator, char *result, int32_t length);
|
typedef bool (*__optr_decode_fn_t)(struct SOperatorInfo* pOperator, char *result, int32_t length);
|
||||||
typedef int32_t (*__optr_open_fn_t)(struct SOperatorInfo* param);
|
|
||||||
typedef SSDataBlock* (*__optr_fn_t)(struct SOperatorInfo* param, bool* newgroup);
|
typedef int32_t (*__optr_open_fn_t)(struct SOperatorInfo* pOptr);
|
||||||
|
typedef SSDataBlock* (*__optr_fn_t)(struct SOperatorInfo* pOptr, bool* newgroup);
|
||||||
typedef void (*__optr_close_fn_t)(void* param, int32_t num);
|
typedef void (*__optr_close_fn_t)(void* param, int32_t num);
|
||||||
|
|
||||||
typedef struct STaskIdInfo {
|
typedef struct STaskIdInfo {
|
||||||
|
@ -267,7 +255,8 @@ typedef struct SExecTaskInfo {
|
||||||
uint64_t totalRows; // total number of rows
|
uint64_t totalRows; // total number of rows
|
||||||
STableGroupInfo tableqinfoGroupInfo; // this is a group array list, including SArray<STableQueryInfo*> structure
|
STableGroupInfo tableqinfoGroupInfo; // this is a group array list, including SArray<STableQueryInfo*> structure
|
||||||
char* sql; // query sql string
|
char* sql; // query sql string
|
||||||
jmp_buf env; //
|
jmp_buf env; // jump to this position when error happens.
|
||||||
|
EOPTR_EXEC_MODEL execModel; // operator execution model [batch model|stream model]
|
||||||
struct SOperatorInfo* pRoot;
|
struct SOperatorInfo* pRoot;
|
||||||
} SExecTaskInfo;
|
} SExecTaskInfo;
|
||||||
|
|
||||||
|
@ -330,11 +319,12 @@ typedef struct SOperatorInfo {
|
||||||
SResultInfo resultInfo;
|
SResultInfo resultInfo;
|
||||||
struct SOperatorInfo** pDownstream; // downstram pointer list
|
struct SOperatorInfo** pDownstream; // downstram pointer list
|
||||||
int32_t numOfDownstream; // number of downstream. The value is always ONE expect for join operator
|
int32_t numOfDownstream; // number of downstream. The value is always ONE expect for join operator
|
||||||
__optr_fn_t getNextFn;
|
|
||||||
__optr_fn_t cleanupFn;
|
|
||||||
__optr_close_fn_t closeFn;
|
|
||||||
__optr_open_fn_t _openFn; // DO NOT invoke this function directly
|
__optr_open_fn_t _openFn; // DO NOT invoke this function directly
|
||||||
__optr_encode_fn_t encodeResultRow; //
|
__optr_fn_t getNextFn;
|
||||||
|
__optr_fn_t getStreamResFn; // execute the aggregate in the stream model.
|
||||||
|
__optr_fn_t cleanupFn; // call this function to release the allocated resources ASAP
|
||||||
|
__optr_close_fn_t closeFn;
|
||||||
|
__optr_encode_fn_t encodeResultRow;
|
||||||
__optr_decode_fn_t decodeResultRow;
|
__optr_decode_fn_t decodeResultRow;
|
||||||
} SOperatorInfo;
|
} SOperatorInfo;
|
||||||
|
|
||||||
|
@ -363,18 +353,18 @@ typedef struct SQInfo {
|
||||||
STaskCostInfo summary;
|
STaskCostInfo summary;
|
||||||
} SQInfo;
|
} SQInfo;
|
||||||
|
|
||||||
enum {
|
typedef enum {
|
||||||
DATA_NOT_READY = 0x1,
|
EX_SOURCE_DATA_NOT_READY = 0x1,
|
||||||
DATA_READY = 0x2,
|
EX_SOURCE_DATA_READY = 0x2,
|
||||||
DATA_EXHAUSTED = 0x3,
|
EX_SOURCE_DATA_EXHAUSTED = 0x3,
|
||||||
};
|
} EX_SOURCE_STATUS;
|
||||||
|
|
||||||
typedef struct SSourceDataInfo {
|
typedef struct SSourceDataInfo {
|
||||||
struct SExchangeInfo *pEx;
|
struct SExchangeInfo *pEx;
|
||||||
int32_t index;
|
int32_t index;
|
||||||
SRetrieveTableRsp *pRsp;
|
SRetrieveTableRsp *pRsp;
|
||||||
uint64_t totalRows;
|
uint64_t totalRows;
|
||||||
int32_t status;
|
EX_SOURCE_STATUS status;
|
||||||
} SSourceDataInfo;
|
} SSourceDataInfo;
|
||||||
|
|
||||||
typedef struct SLoadRemoteDataInfo {
|
typedef struct SLoadRemoteDataInfo {
|
||||||
|
@ -383,12 +373,6 @@ typedef struct SLoadRemoteDataInfo {
|
||||||
uint64_t totalElapsed; // total elapsed time
|
uint64_t totalElapsed; // total elapsed time
|
||||||
} SLoadRemoteDataInfo;
|
} SLoadRemoteDataInfo;
|
||||||
|
|
||||||
enum {
|
|
||||||
EX_SOURCE_DATA_NOT_READY = 0x1,
|
|
||||||
EX_SOURCE_DATA_READY = 0x2,
|
|
||||||
EX_SOURCE_DATA_EXHAUSTED = 0x3,
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct SExchangeInfo {
|
typedef struct SExchangeInfo {
|
||||||
SArray* pSources;
|
SArray* pSources;
|
||||||
SArray* pSourceDataInfo;
|
SArray* pSourceDataInfo;
|
||||||
|
@ -484,16 +468,18 @@ typedef struct SAggSupporter {
|
||||||
} SAggSupporter;
|
} SAggSupporter;
|
||||||
|
|
||||||
typedef struct STableIntervalOperatorInfo {
|
typedef struct STableIntervalOperatorInfo {
|
||||||
SOptrBasicInfo binfo;
|
SOptrBasicInfo binfo; // basic info
|
||||||
SGroupResInfo groupResInfo;
|
SGroupResInfo groupResInfo; // multiple results build supporter
|
||||||
SInterval interval;
|
SInterval interval; // interval info
|
||||||
STimeWindow win;
|
STimeWindow win; // query time range
|
||||||
int32_t precision;
|
bool timeWindowInterpo; // interpolation needed or not
|
||||||
bool timeWindowInterpo;
|
char **pRow; // previous row/tuple of already processed datablock
|
||||||
char **pRow;
|
SAggSupporter aggSup; // aggregate supporter
|
||||||
SAggSupporter aggSup;
|
STableQueryInfo *pCurrent; // current tableQueryInfo struct
|
||||||
STableQueryInfo *pCurrent;
|
int32_t order; // current SSDataBlock scan order
|
||||||
int32_t order;
|
EOPTR_EXEC_MODEL execModel; // operator execution model [batch model|stream model]
|
||||||
|
SArray *pUpdatedWindow; // updated time window due to the input data block from the downstream operator.
|
||||||
|
SColumnInfoData timeWindowData; // query time window info for scalar function execution.
|
||||||
} STableIntervalOperatorInfo;
|
} STableIntervalOperatorInfo;
|
||||||
|
|
||||||
typedef struct SAggOperatorInfo {
|
typedef struct SAggOperatorInfo {
|
||||||
|
@ -695,12 +681,6 @@ SOperatorInfo* createSLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorI
|
||||||
SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pdownstream, int32_t numOfDownstream, SSchema* pSchema,
|
SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pdownstream, int32_t numOfDownstream, SSchema* pSchema,
|
||||||
int32_t numOfOutput);
|
int32_t numOfOutput);
|
||||||
|
|
||||||
void doSetFilterColumnInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilterCols, SSDataBlock* pBlock);
|
|
||||||
bool doFilterDataBlock(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilterCols, int32_t numOfRows, int8_t* p);
|
|
||||||
void doCompactSDataBlock(SSDataBlock* pBlock, int32_t numOfRows, int8_t* p);
|
|
||||||
|
|
||||||
SSDataBlock* createOutputBuf(SExprInfo* pExpr, int32_t numOfOutput, int32_t numOfRows);
|
|
||||||
|
|
||||||
void* doDestroyFilterInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilterCols);
|
void* doDestroyFilterInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilterCols);
|
||||||
|
|
||||||
void setInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t order);
|
void setInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t order);
|
||||||
|
@ -734,7 +714,7 @@ int32_t getMaximumIdleDurationSec();
|
||||||
|
|
||||||
void doInvokeUdf(struct SUdfInfo* pUdfInfo, SqlFunctionCtx* pCtx, int32_t idx, int32_t type);
|
void doInvokeUdf(struct SUdfInfo* pUdfInfo, SqlFunctionCtx* pCtx, int32_t idx, int32_t type);
|
||||||
void setTaskStatus(SExecTaskInfo* pTaskInfo, int8_t status);
|
void setTaskStatus(SExecTaskInfo* pTaskInfo, int8_t status);
|
||||||
int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId);
|
int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId, EOPTR_EXEC_MODEL model);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue