Merge branch '3.0' into feature/TD-11463-3.0
This commit is contained in:
commit
cf06c16379
|
@ -5,7 +5,6 @@ AccessModifierOffset: -1
|
|||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: true
|
||||
AlignConsecutiveMacros: true
|
||||
AlignEscapedNewlinesLeft: true
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
|
|
|
@ -574,11 +574,11 @@ typedef struct SMultiwayMergeInfo {
|
|||
} SMultiwayMergeInfo;
|
||||
|
||||
// todo support the disk-based sort
|
||||
typedef struct SOrderOperatorInfo {
|
||||
typedef struct SSortOperatorInfo {
|
||||
int32_t colIndex;
|
||||
int32_t order;
|
||||
SSDataBlock *pDataBlock;
|
||||
} SOrderOperatorInfo;
|
||||
} SSortOperatorInfo;
|
||||
|
||||
void appendUpstream(SOperatorInfo* p, SOperatorInfo* pUpstream);
|
||||
|
||||
|
@ -609,7 +609,7 @@ SOperatorInfo* createFilterOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperator
|
|||
int32_t numOfOutput, SColumnInfo* pCols, int32_t numOfFilter);
|
||||
|
||||
SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pUpstream, int32_t numOfUpstream, SSchema* pSchema, int32_t numOfOutput);
|
||||
SOperatorInfo* createOrderOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput, SOrderVal* pOrderVal);
|
||||
SOperatorInfo* createSortOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput, SOrderVal* pOrderVal);
|
||||
|
||||
SSDataBlock* doGlobalAggregate(void* param, bool* newgroup);
|
||||
SSDataBlock* doMultiwayMergeSort(void* param, bool* newgroup);
|
||||
|
|
|
@ -2301,7 +2301,7 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf
|
|||
}
|
||||
|
||||
case OP_Order: {
|
||||
pRuntimeEnv->proot = createOrderOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput, &pQueryAttr->order);
|
||||
pRuntimeEnv->proot = createSortOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput, &pQueryAttr->order);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -5516,7 +5516,7 @@ static SSDataBlock* doSort(void* param, bool* newgroup) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SOrderOperatorInfo* pInfo = pOperator->info;
|
||||
SSortOperatorInfo* pInfo = pOperator->info;
|
||||
|
||||
SSDataBlock* pBlock = NULL;
|
||||
while(1) {
|
||||
|
@ -5556,8 +5556,8 @@ static SSDataBlock* doSort(void* param, bool* newgroup) {
|
|||
return (pInfo->pDataBlock->info.rows > 0)? pInfo->pDataBlock:NULL;
|
||||
}
|
||||
|
||||
SOperatorInfo *createOrderOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput, SOrderVal* pOrderVal) {
|
||||
SOrderOperatorInfo* pInfo = calloc(1, sizeof(SOrderOperatorInfo));
|
||||
SOperatorInfo *createSortOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput, SOrderVal* pOrderVal) {
|
||||
SSortOperatorInfo* pInfo = calloc(1, sizeof(SSortOperatorInfo));
|
||||
|
||||
{
|
||||
SSDataBlock* pDataBlock = calloc(1, sizeof(SSDataBlock));
|
||||
|
@ -6611,7 +6611,7 @@ static void destroyTagScanOperatorInfo(void* param, int32_t numOfOutput) {
|
|||
}
|
||||
|
||||
static void destroyOrderOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
SOrderOperatorInfo* pInfo = (SOrderOperatorInfo*) param;
|
||||
SSortOperatorInfo* pInfo = (SSortOperatorInfo*) param;
|
||||
pInfo->pDataBlock = blockDataDestroy(pInfo->pDataBlock);
|
||||
}
|
||||
|
||||
|
|
|
@ -80,8 +80,9 @@ int32_t create_topic() {
|
|||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
const char* sql = "select * from tu1";
|
||||
pRes = tmq_create_topic(pConn, "test_stb_topic_1", sql, strlen(sql));
|
||||
/*const char* sql = "select * from tu1";*/
|
||||
/*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) {
|
||||
printf("failed to create topic test_stb_topic_1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "taos.h"
|
||||
|
||||
int32_t init_env() {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 7010);
|
||||
if (pConn == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ int32_t init_env() {
|
|||
int32_t create_stream() {
|
||||
printf("create stream\n");
|
||||
TAOS_RES* pRes;
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 7010);
|
||||
if (pConn == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -1,78 +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_CONSUMER_H_
|
||||
#define _TD_CONSUMER_H_
|
||||
|
||||
#include "tlist.h"
|
||||
#include "tarray.h"
|
||||
#include "hash.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//consumer handle
|
||||
struct tmq_consumer_t;
|
||||
typedef struct tmq_consumer_t tmq_consumer_t;
|
||||
|
||||
//consumer config
|
||||
struct tmq_consumer_config_t;
|
||||
typedef struct tmq_consumer_config_t tmq_consumer_config_t;
|
||||
|
||||
//response err
|
||||
struct tmq_resp_err_t;
|
||||
typedef struct tmq_resp_err_t tmq_resp_err_t;
|
||||
|
||||
struct tmq_message_t;
|
||||
typedef struct tmq_message_t tmq_message_t;
|
||||
|
||||
struct tmq_col_batch_t;
|
||||
typedef struct tmq_col_batch_t tmq_col_batch_t;
|
||||
|
||||
//get content of message
|
||||
tmq_col_batch_t* tmq_get_msg_col_by_idx(tmq_message_t*, int32_t col_id);
|
||||
tmq_col_batch_t* tmq_get_msg_col_by_name(tmq_message_t*, const char*);
|
||||
|
||||
//consumer config
|
||||
int32_t tmq_conf_set(tmq_consumer_config_t* , const char* config_key, const char* config_value, char* errstr, int32_t errstr_cap);
|
||||
|
||||
//consumer initialization
|
||||
//resouces are supposed to be free by users by calling tmq_consumer_destroy
|
||||
tmq_consumer_t* tmq_consumer_new(tmq_consumer_config_t* , char* errstr, int32_t errstr_cap);
|
||||
|
||||
//subscribe
|
||||
tmq_resp_err_t tmq_subscribe(tmq_consumer_t*, const SList*);
|
||||
tmq_resp_err_t tmq_unsubscribe(tmq_consumer_t*);
|
||||
|
||||
//consume
|
||||
//resouces are supposed to be free by users by calling tmq_message_destroy
|
||||
tmq_message_t* tmq_consume_poll(tmq_consumer_t*, int64_t blocking_time);
|
||||
|
||||
//destroy message and free memory
|
||||
void tmq_message_destroy(tmq_message_t*);
|
||||
|
||||
//close consumer
|
||||
int32_t tmq_consumer_close(tmq_consumer_t*);
|
||||
|
||||
//destroy consumer
|
||||
void tmq_consumer_destroy(tmq_message_t*);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_CONSUMER_H_*/
|
|
@ -26,9 +26,11 @@ extern "C" {
|
|||
typedef void TAOS;
|
||||
typedef void TAOS_STMT;
|
||||
typedef void TAOS_RES;
|
||||
typedef void TAOS_STREAM;
|
||||
typedef void TAOS_SUB;
|
||||
typedef void **TAOS_ROW;
|
||||
#if 0
|
||||
typedef void TAOS_STREAM;
|
||||
#endif
|
||||
typedef void TAOS_SUB;
|
||||
|
||||
// Data type definition
|
||||
#define TSDB_DATA_TYPE_NULL 0 // 1 bytes
|
||||
|
@ -122,8 +124,25 @@ typedef struct TAOS_MULTI_BIND {
|
|||
int num;
|
||||
} 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 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_l(const char *ip, int ipLen, const char *user, int userLen, const char *pass, int passLen,
|
||||
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 int taos_stmt_close(TAOS_STMT *stmt);
|
||||
DLL_EXPORT char *taos_stmt_errstr(TAOS_STMT *stmt);
|
||||
DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT *stmt);
|
||||
|
||||
DLL_EXPORT TAOS_RES *taos_query(TAOS *taos, const char *sql);
|
||||
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 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_update_query(TAOS_RES *res);
|
||||
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 void taos_reset_current_db(TAOS *taos);
|
||||
|
||||
DLL_EXPORT int *taos_fetch_lengths(TAOS_RES *res);
|
||||
DLL_EXPORT TAOS_ROW *taos_result_block(TAOS_RES *res);
|
||||
|
||||
DLL_EXPORT const char *taos_get_server_info(TAOS *taos);
|
||||
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_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);
|
||||
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);
|
||||
DLL_EXPORT TAOS_RES *taos_consume(TAOS_SUB *tsub);
|
||||
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),
|
||||
int64_t stime, void *param, void (*callback)(void *));
|
||||
DLL_EXPORT void taos_close_stream(TAOS_STREAM *tstr);
|
||||
#endif
|
||||
|
||||
DLL_EXPORT int taos_load_table_info(TAOS *taos, const char *tableNameList);
|
||||
DLL_EXPORT 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 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);
|
||||
|
||||
// will replace last one
|
||||
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);
|
||||
|
||||
/* ------------------------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 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);
|
||||
|
||||
/* --------------------TMPORARY INTERFACE FOR TESTING--------------------- */
|
||||
#if 0
|
||||
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);
|
||||
|
||||
/* -------------------------------- 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);
|
||||
|
||||
DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT *stmt);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -197,6 +197,11 @@ typedef struct SGroupbyExpr {
|
|||
bool groupbyTag; // group by tag or column
|
||||
} SGroupbyExpr;
|
||||
|
||||
enum {
|
||||
FUNC_PARAM_TYPE_VALUE = 0,
|
||||
FUNC_PARAM_TYPE_COLUMN,
|
||||
};
|
||||
|
||||
typedef struct SFunctParam {
|
||||
int32_t type;
|
||||
SColumn* pCol;
|
||||
|
|
|
@ -29,8 +29,9 @@ typedef struct SCorEpSet {
|
|||
} SCorEpSet;
|
||||
|
||||
typedef struct SBlockOrderInfo {
|
||||
bool nullFirst;
|
||||
int32_t order;
|
||||
int32_t colIndex;
|
||||
int32_t slotId;
|
||||
SColumnInfoData* pColData;
|
||||
} SBlockOrderInfo;
|
||||
|
||||
|
@ -132,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) {
|
||||
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;
|
||||
*(int64_t*)p = *(int64_t*)v;
|
||||
}
|
||||
|
@ -174,18 +176,17 @@ size_t blockDataGetRowSize(SSDataBlock* pBlock);
|
|||
double blockDataGetSerialRowSize(const SSDataBlock* pBlock);
|
||||
size_t blockDataGetSerialMetaSize(const SSDataBlock* pBlock);
|
||||
|
||||
SSchema* blockDataExtractSchema(const SSDataBlock* pBlock, int32_t* numOfCols);
|
||||
|
||||
int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirst);
|
||||
int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo);
|
||||
int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirst);
|
||||
|
||||
int32_t blockDataEnsureColumnCapacity(SColumnInfoData* pColumn, uint32_t numOfRows);
|
||||
int32_t blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows);
|
||||
void blockDataCleanup(SSDataBlock* pDataBlock);
|
||||
SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock);
|
||||
size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize);
|
||||
void* blockDataDestroy(SSDataBlock* pBlock);
|
||||
|
||||
SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock);
|
||||
|
||||
void blockDebugShowData(const SArray* dataBlocks);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -51,7 +51,7 @@ extern int32_t tsCompatibleModel;
|
|||
extern bool tsEnableSlaveQuery;
|
||||
extern bool tsPrintAuth;
|
||||
extern int64_t tsTickPerDay[3];
|
||||
extern int32_t tsMultiProcess;
|
||||
extern bool tsMultiProcess;
|
||||
|
||||
// monitor
|
||||
extern bool tsEnableMonitor;
|
||||
|
|
|
@ -469,8 +469,7 @@ typedef struct {
|
|||
int32_t tz; // query client timezone
|
||||
char intervalUnit;
|
||||
char slidingUnit;
|
||||
char
|
||||
offsetUnit; // TODO Remove it, the offset is the number of precision tickle, and it must be a immutable duration.
|
||||
char offsetUnit; // TODO Remove it, the offset is the number of precision tickle, and it must be a immutable duration.
|
||||
int8_t precision;
|
||||
int64_t interval;
|
||||
int64_t sliding;
|
||||
|
@ -801,7 +800,10 @@ typedef struct SVgroupInfo {
|
|||
uint32_t hashBegin;
|
||||
uint32_t hashEnd;
|
||||
SEpSet epSet;
|
||||
union {
|
||||
int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT
|
||||
int32_t taskId; // used in stream
|
||||
};
|
||||
} SVgroupInfo;
|
||||
|
||||
typedef struct {
|
||||
|
@ -2185,23 +2187,6 @@ static FORCE_INLINE void* tDecodeTSmaWrapper(void* buf, STSmaWrapper* pSW) {
|
|||
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 {
|
||||
int8_t mqMsgType;
|
||||
int32_t code;
|
||||
|
@ -2230,7 +2215,10 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
char topic[TSDB_TOPIC_FNAME_LEN];
|
||||
int8_t isSchemaAdaptive;
|
||||
SArray* vgs; // SArray<SMqSubVgEp>
|
||||
int32_t numOfFields;
|
||||
TAOS_FIELD* fields;
|
||||
} SMqSubTopicEp;
|
||||
|
||||
typedef struct {
|
||||
|
@ -2251,32 +2239,6 @@ typedef struct {
|
|||
SArray* topics; // SArray<SMqSubTopicEp>
|
||||
} 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 int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) {
|
||||
|
@ -2301,17 +2263,21 @@ static FORCE_INLINE void tDeleteSMqCMGetSubEpRsp(SMqCMGetSubEpRsp* pRsp) {
|
|||
static FORCE_INLINE int32_t tEncodeSMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp) {
|
||||
int32_t tlen = 0;
|
||||
tlen += taosEncodeString(buf, pTopicEp->topic);
|
||||
tlen += taosEncodeFixedI8(buf, pTopicEp->isSchemaAdaptive);
|
||||
int32_t sz = taosArrayGetSize(pTopicEp->vgs);
|
||||
tlen += taosEncodeFixedI32(buf, sz);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SMqSubVgEp* pVgEp = (SMqSubVgEp*)taosArrayGet(pTopicEp->vgs, i);
|
||||
tlen += tEncodeSMqSubVgEp(buf, pVgEp);
|
||||
}
|
||||
tlen += taosEncodeFixedI32(buf, pTopicEp->numOfFields);
|
||||
// tlen += taosEncodeBinary(buf, pTopicEp->fields, pTopicEp->numOfFields * sizeof(TAOS_FIELD));
|
||||
return tlen;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void* tDecodeSMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicEp) {
|
||||
buf = taosDecodeStringTo(buf, pTopicEp->topic);
|
||||
buf = taosDecodeFixedI8(buf, &pTopicEp->isSchemaAdaptive);
|
||||
int32_t sz;
|
||||
buf = taosDecodeFixedI32(buf, &sz);
|
||||
pTopicEp->vgs = taosArrayInit(sz, sizeof(SMqSubVgEp));
|
||||
|
@ -2323,6 +2289,8 @@ static FORCE_INLINE void* tDecodeSMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicE
|
|||
buf = tDecodeSMqSubVgEp(buf, &vgEp);
|
||||
taosArrayPush(pTopicEp->vgs, &vgEp);
|
||||
}
|
||||
buf = taosDecodeFixedI32(buf, &pTopicEp->numOfFields);
|
||||
// buf = taosDecodeBinary(buf, (void**)&pTopicEp->fields, pTopicEp->numOfFields * sizeof(TAOS_FIELD));
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ extern "C" {
|
|||
typedef struct SRpcMsg SRpcMsg;
|
||||
typedef struct SEpSet SEpSet;
|
||||
typedef struct SMgmtWrapper SMgmtWrapper;
|
||||
|
||||
typedef enum {
|
||||
QUERY_QUEUE,
|
||||
FETCH_QUEUE,
|
||||
|
@ -38,9 +39,11 @@ typedef enum {
|
|||
|
||||
typedef int32_t (*PutToQueueFp)(SMgmtWrapper* pWrapper, SRpcMsg* pReq);
|
||||
typedef int32_t (*GetQueueSizeFp)(SMgmtWrapper* pWrapper, int32_t vgId, EQueueType qtype);
|
||||
typedef int32_t (*SendReqFp)(SMgmtWrapper* pWrapper, SEpSet* epSet, SRpcMsg* pReq);
|
||||
typedef int32_t (*SendReqFp)(SMgmtWrapper* pWrapper, const SEpSet* epSet, SRpcMsg* pReq);
|
||||
typedef int32_t (*SendMnodeReqFp)(SMgmtWrapper* pWrapper, SRpcMsg* pReq);
|
||||
typedef void (*SendRspFp)(SMgmtWrapper* pWrapper, SRpcMsg* pRsp);
|
||||
typedef void (*SendRspFp)(SMgmtWrapper* pWrapper, const SRpcMsg* pRsp);
|
||||
typedef void (*RegisterBrokenLinkArgFp)(SMgmtWrapper* pWrapper, SRpcMsg* pMsg);
|
||||
typedef void (*ReleaseHandleFp)(SMgmtWrapper* pWrapper, void* handle, int8_t type);
|
||||
|
||||
typedef struct {
|
||||
SMgmtWrapper* pWrapper;
|
||||
|
@ -49,13 +52,18 @@ typedef struct {
|
|||
SendReqFp sendReqFp;
|
||||
SendMnodeReqFp sendMnodeReqFp;
|
||||
SendRspFp sendRspFp;
|
||||
RegisterBrokenLinkArgFp registerBrokenLinkArgFp;
|
||||
ReleaseHandleFp releaseHandleFp;
|
||||
} SMsgCb;
|
||||
|
||||
void tmsgSetDefaultMsgCb(const SMsgCb* pMsgCb);
|
||||
int32_t tmsgPutToQueue(const SMsgCb* pMsgCb, EQueueType qtype, SRpcMsg* pReq);
|
||||
int32_t tmsgGetQueueSize(const SMsgCb* pMsgCb, int32_t vgId, EQueueType qtype);
|
||||
int32_t tmsgSendReq(const SMsgCb* pMsgCb, SEpSet* epSet, SRpcMsg* pReq);
|
||||
int32_t tmsgSendReq(const SMsgCb* pMsgCb, const SEpSet* epSet, SRpcMsg* pReq);
|
||||
int32_t tmsgSendMnodeReq(const SMsgCb* pMsgCb, SRpcMsg* pReq);
|
||||
void tmsgSendRsp(const SMsgCb* pMsgCb, SRpcMsg* pRsp);
|
||||
void tmsgSendRsp(const SRpcMsg* pRsp);
|
||||
void tmsgRegisterBrokenLinkArg(const SMsgCb* pMsgCb, SRpcMsg* pMsg);
|
||||
void tmsgReleaseHandle(void* handle, int8_t type);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -138,47 +138,59 @@
|
|||
#define TK_INTERVAL 120
|
||||
#define TK_TOPIC 121
|
||||
#define TK_AS 122
|
||||
#define TK_NK_BOOL 123
|
||||
#define TK_NK_VARIABLE 124
|
||||
#define TK_BETWEEN 125
|
||||
#define TK_IS 126
|
||||
#define TK_NULL 127
|
||||
#define TK_NK_LT 128
|
||||
#define TK_NK_GT 129
|
||||
#define TK_NK_LE 130
|
||||
#define TK_NK_GE 131
|
||||
#define TK_NK_NE 132
|
||||
#define TK_MATCH 133
|
||||
#define TK_NMATCH 134
|
||||
#define TK_IN 135
|
||||
#define TK_JOIN 136
|
||||
#define TK_INNER 137
|
||||
#define TK_SELECT 138
|
||||
#define TK_DISTINCT 139
|
||||
#define TK_WHERE 140
|
||||
#define TK_PARTITION 141
|
||||
#define TK_BY 142
|
||||
#define TK_SESSION 143
|
||||
#define TK_STATE_WINDOW 144
|
||||
#define TK_SLIDING 145
|
||||
#define TK_FILL 146
|
||||
#define TK_VALUE 147
|
||||
#define TK_NONE 148
|
||||
#define TK_PREV 149
|
||||
#define TK_LINEAR 150
|
||||
#define TK_NEXT 151
|
||||
#define TK_GROUP 152
|
||||
#define TK_HAVING 153
|
||||
#define TK_ORDER 154
|
||||
#define TK_SLIMIT 155
|
||||
#define TK_SOFFSET 156
|
||||
#define TK_LIMIT 157
|
||||
#define TK_OFFSET 158
|
||||
#define TK_ASC 159
|
||||
#define TK_DESC 160
|
||||
#define TK_NULLS 161
|
||||
#define TK_FIRST 162
|
||||
#define TK_LAST 163
|
||||
#define TK_EXPLAIN 123
|
||||
#define TK_ANALYZE 124
|
||||
#define TK_VERBOSE 125
|
||||
#define TK_NK_BOOL 126
|
||||
#define TK_RATIO 127
|
||||
#define TK_NULL 128
|
||||
#define TK_NK_VARIABLE 129
|
||||
#define TK_NK_UNDERLINE 130
|
||||
#define TK_ROWTS 131
|
||||
#define TK_TBNAME 132
|
||||
#define TK_QSTARTTS 133
|
||||
#define TK_QENDTS 134
|
||||
#define TK_WSTARTTS 135
|
||||
#define TK_WENDTS 136
|
||||
#define TK_WDURATION 137
|
||||
#define TK_BETWEEN 138
|
||||
#define TK_IS 139
|
||||
#define TK_NK_LT 140
|
||||
#define TK_NK_GT 141
|
||||
#define TK_NK_LE 142
|
||||
#define TK_NK_GE 143
|
||||
#define TK_NK_NE 144
|
||||
#define TK_MATCH 145
|
||||
#define TK_NMATCH 146
|
||||
#define TK_IN 147
|
||||
#define TK_JOIN 148
|
||||
#define TK_INNER 149
|
||||
#define TK_SELECT 150
|
||||
#define TK_DISTINCT 151
|
||||
#define TK_WHERE 152
|
||||
#define TK_PARTITION 153
|
||||
#define TK_BY 154
|
||||
#define TK_SESSION 155
|
||||
#define TK_STATE_WINDOW 156
|
||||
#define TK_SLIDING 157
|
||||
#define TK_FILL 158
|
||||
#define TK_VALUE 159
|
||||
#define TK_NONE 160
|
||||
#define TK_PREV 161
|
||||
#define TK_LINEAR 162
|
||||
#define TK_NEXT 163
|
||||
#define TK_GROUP 164
|
||||
#define TK_HAVING 165
|
||||
#define TK_ORDER 166
|
||||
#define TK_SLIMIT 167
|
||||
#define TK_SOFFSET 168
|
||||
#define TK_LIMIT 169
|
||||
#define TK_OFFSET 170
|
||||
#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_COMMENT 301
|
||||
|
|
|
@ -46,11 +46,12 @@ typedef struct {
|
|||
char localFqdn[TSDB_FQDN_LEN];
|
||||
char firstEp[TSDB_EP_LEN];
|
||||
char secondEp[TSDB_EP_LEN];
|
||||
SDiskCfg *pDisks;
|
||||
SDiskCfg *disks;
|
||||
int32_t numOfDisks;
|
||||
int8_t ntype;
|
||||
} 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.
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "tcommon.h"
|
||||
#include "query.h"
|
||||
#include "tcommon.h"
|
||||
|
||||
typedef void* qTaskInfo_t;
|
||||
typedef void* DataSinkHandle;
|
||||
|
@ -37,6 +37,11 @@ typedef struct SReadHandle {
|
|||
#define STREAM_DATA_TYPE_SUBMIT_BLOCK 0x1
|
||||
#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
|
||||
* @param pMsg
|
||||
|
@ -54,6 +59,16 @@ qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, void* streamReadHandle);
|
|||
*/
|
||||
int32_t qSetStreamInput(qTaskInfo_t tinfo, const void* input, int32_t type);
|
||||
|
||||
/**
|
||||
* Set multiple input data blocks for the stream scan.
|
||||
* @param tinfo
|
||||
* @param pBlocks
|
||||
* @param numOfInputBlock
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks, int32_t type);
|
||||
|
||||
/**
|
||||
* Update the table id list, add or remove.
|
||||
*
|
||||
|
@ -74,7 +89,7 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, SArray* tableIdList, bool isA
|
|||
* @return
|
||||
*/
|
||||
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,
|
||||
|
@ -86,16 +101,6 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId,
|
|||
*/
|
||||
int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t* useconds);
|
||||
|
||||
/**
|
||||
* Retrieve the produced results information, if current query is not paused or completed,
|
||||
* this function will be blocked to wait for the query execution completed or paused,
|
||||
* in which case enough results have been produced already.
|
||||
*
|
||||
* @param tinfo
|
||||
* @return
|
||||
*/
|
||||
int32_t qRetrieveQueryResultInfo(qTaskInfo_t tinfo, bool* buildRes, void* pRspContext);
|
||||
|
||||
/**
|
||||
* kill the ongoing query and free the query handle and corresponding resources automatically
|
||||
* @param tinfo qhandle
|
||||
|
@ -158,50 +163,6 @@ int32_t qGetQualifiedTableIdList(void* pTableList, const char* tagCond, int32_t
|
|||
*/
|
||||
int32_t qUpdateQueriedTableIdList(qTaskInfo_t tinfo, int64_t uid, int32_t type);
|
||||
|
||||
//================================================================================================
|
||||
// query handle management
|
||||
/**
|
||||
* Query handle mgmt object
|
||||
* @param vgId
|
||||
* @return
|
||||
*/
|
||||
void* qOpenTaskMgmt(int32_t vgId);
|
||||
|
||||
/**
|
||||
* broadcast the close information and wait for all query stop.
|
||||
* @param pExecutor
|
||||
*/
|
||||
void qTaskMgmtNotifyClosing(void* pExecutor);
|
||||
|
||||
/**
|
||||
* Re-open the query handle management module when opening the vnode again.
|
||||
* @param pExecutor
|
||||
*/
|
||||
void qQueryMgmtReOpen(void* pExecutor);
|
||||
|
||||
/**
|
||||
* Close query mgmt and clean up resources.
|
||||
* @param pExecutor
|
||||
*/
|
||||
void qCleanupTaskMgmt(void* pExecutor);
|
||||
|
||||
/**
|
||||
* Add the query into the query mgmt object
|
||||
* @param pMgmt
|
||||
* @param qId
|
||||
* @param qInfo
|
||||
* @return
|
||||
*/
|
||||
void** qRegisterTask(void* pMgmt, uint64_t qId, void* qInfo);
|
||||
|
||||
/**
|
||||
* acquire the query handle according to the key from query mgmt object.
|
||||
* @param pMgmt
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
void** qAcquireTask(void* pMgmt, uint64_t key);
|
||||
|
||||
/**
|
||||
* release the query handle and decrease the reference count in cache
|
||||
* @param pMgmt
|
||||
|
@ -211,14 +172,6 @@ void** qAcquireTask(void* pMgmt, uint64_t key);
|
|||
*/
|
||||
void** qReleaseTask(void* pMgmt, void* pQInfo, bool freeHandle);
|
||||
|
||||
/**
|
||||
* De-register the query handle from the management module and free it immediately.
|
||||
* @param pMgmt
|
||||
* @param pQInfo
|
||||
* @return
|
||||
*/
|
||||
void** qDeregisterQInfo(void* pMgmt, void* pQInfo);
|
||||
|
||||
void qProcessFetchRsp(void* parent, struct SRpcMsg* pMsg, struct SEpSet* pEpSet);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -41,6 +41,7 @@ typedef void (*FExecFinalize)(struct SqlFunctionCtx *pCtx);
|
|||
typedef int32_t (*FScalarExecProcess)(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
|
||||
typedef struct SScalarFuncExecFuncs {
|
||||
FExecGetEnv getEnv;
|
||||
FScalarExecProcess process;
|
||||
} SScalarFuncExecFuncs;
|
||||
|
||||
|
@ -241,7 +242,6 @@ typedef struct tExprNode {
|
|||
};
|
||||
} tExprNode;
|
||||
|
||||
void exprTreeToBinary(SBufferWriter* bw, tExprNode* pExprTree);
|
||||
void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *));
|
||||
|
||||
typedef struct SAggFunctionInfo {
|
||||
|
@ -267,28 +267,6 @@ struct SScalarParam {
|
|||
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,
|
||||
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);
|
||||
|
||||
void extractFunctionDesc(SArray* pFunctionIdList, SMultiFunctionsDesc* pDesc);
|
||||
|
||||
tExprNode* exprdup(tExprNode* pTree);
|
||||
|
||||
void resetResultRowEntryResult(SqlFunctionCtx* pCtx, int32_t num);
|
||||
|
|
|
@ -96,7 +96,16 @@ typedef enum EFunctionType {
|
|||
FUNCTION_TYPE_SERVER_SERSION,
|
||||
FUNCTION_TYPE_SERVER_STATUS,
|
||||
FUNCTION_TYPE_CURRENT_USER,
|
||||
FUNCTION_TYPE_USER
|
||||
FUNCTION_TYPE_USER,
|
||||
|
||||
// pseudo column function
|
||||
FUNCTION_TYPE_ROWTS = 3500,
|
||||
FUNCTION_TYPE_TBNAME,
|
||||
FUNCTION_TYPE_QSTARTTS,
|
||||
FUNCTION_TYPE_QENDTS,
|
||||
FUNCTION_TYPE_WSTARTTS,
|
||||
FUNCTION_TYPE_WENDTS,
|
||||
FUNCTION_TYPE_WDURATION
|
||||
} EFunctionType;
|
||||
|
||||
struct SqlFunctionCtx;
|
||||
|
@ -118,6 +127,8 @@ bool fmIsStringFunc(int32_t funcId);
|
|||
bool fmIsDatetimeFunc(int32_t funcId);
|
||||
bool fmIsTimelineFunc(int32_t funcId);
|
||||
bool fmIsTimeorderFunc(int32_t funcId);
|
||||
bool fmIsWindowPseudoColumnFunc(int32_t funcId);
|
||||
bool fmIsWindowClauseFunc(int32_t funcId);
|
||||
|
||||
int32_t fmFuncScanType(int32_t funcId);
|
||||
|
||||
|
|
|
@ -70,6 +70,7 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_DATABASE_OPTIONS,
|
||||
QUERY_NODE_TABLE_OPTIONS,
|
||||
QUERY_NODE_INDEX_OPTIONS,
|
||||
QUERY_NODE_EXPLAIN_OPTIONS,
|
||||
|
||||
// Statement nodes are used in parser and planner module.
|
||||
QUERY_NODE_SET_OPERATOR,
|
||||
|
@ -99,6 +100,7 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_CREATE_TOPIC_STMT,
|
||||
QUERY_NODE_DROP_TOPIC_STMT,
|
||||
QUERY_NODE_ALTER_LOCAL_STMT,
|
||||
QUERY_NODE_EXPLAIN_STMT,
|
||||
QUERY_NODE_SHOW_DATABASES_STMT,
|
||||
QUERY_NODE_SHOW_TABLES_STMT,
|
||||
QUERY_NODE_SHOW_STABLES_STMT,
|
||||
|
@ -121,6 +123,7 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_LOGIC_PLAN_EXCHANGE,
|
||||
QUERY_NODE_LOGIC_PLAN_WINDOW,
|
||||
QUERY_NODE_LOGIC_PLAN_SORT,
|
||||
QUERY_NODE_LOGIC_PLAN_PARTITION,
|
||||
QUERY_NODE_LOGIC_SUBPLAN,
|
||||
QUERY_NODE_LOGIC_PLAN,
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ typedef struct SScanLogicNode {
|
|||
STimeWindow scanRange;
|
||||
SName tableName;
|
||||
bool showRewrite;
|
||||
double ratio;
|
||||
} SScanLogicNode;
|
||||
|
||||
typedef struct SJoinLogicNode {
|
||||
|
@ -67,6 +68,10 @@ typedef struct SProjectLogicNode {
|
|||
SLogicNode node;
|
||||
SNodeList* pProjections;
|
||||
char stmtName[TSDB_TABLE_NAME_LEN];
|
||||
int64_t limit;
|
||||
int64_t offset;
|
||||
int64_t slimit;
|
||||
int64_t soffset;
|
||||
} SProjectLogicNode;
|
||||
|
||||
typedef struct SVnodeModifLogicNode {
|
||||
|
@ -106,6 +111,11 @@ typedef struct SSortLogicNode {
|
|||
SNodeList* pSortKeys;
|
||||
} SSortLogicNode;
|
||||
|
||||
typedef struct SPartitionLogicNode {
|
||||
SLogicNode node;
|
||||
SNodeList* pPartitionKeys;
|
||||
} SPartitionLogicNode;
|
||||
|
||||
typedef enum ESubplanType {
|
||||
SUBPLAN_TYPE_MERGE = 1,
|
||||
SUBPLAN_TYPE_PARTIAL,
|
||||
|
@ -150,7 +160,8 @@ typedef struct SDataBlockDescNode {
|
|||
ENodeType type;
|
||||
int16_t dataBlockId;
|
||||
SNodeList* pSlots;
|
||||
int32_t resultRowSize;
|
||||
int32_t totalRowSize;
|
||||
int32_t outputRowSize;
|
||||
int16_t precision;
|
||||
} SDataBlockDescNode;
|
||||
|
||||
|
@ -187,7 +198,7 @@ typedef struct STableScanPhysiNode {
|
|||
SScanPhysiNode scan;
|
||||
uint8_t scanFlag; // denotes reversed scan of data or not
|
||||
STimeWindow scanRange;
|
||||
SNode* pScanConditions;
|
||||
double ratio;
|
||||
} STableScanPhysiNode;
|
||||
|
||||
typedef STableScanPhysiNode STableSeqScanPhysiNode;
|
||||
|
@ -195,6 +206,10 @@ typedef STableScanPhysiNode STableSeqScanPhysiNode;
|
|||
typedef struct SProjectPhysiNode {
|
||||
SPhysiNode node;
|
||||
SNodeList* pProjections;
|
||||
int64_t limit;
|
||||
int64_t offset;
|
||||
int64_t slimit;
|
||||
int64_t soffset;
|
||||
} SProjectPhysiNode;
|
||||
|
||||
typedef struct SJoinPhysiNode {
|
||||
|
@ -238,6 +253,7 @@ typedef struct SIntervalPhysiNode {
|
|||
int64_t sliding;
|
||||
int8_t intervalUnit;
|
||||
int8_t slidingUnit;
|
||||
uint8_t precision;
|
||||
SFillNode* pFill;
|
||||
} SIntervalPhysiNode;
|
||||
|
||||
|
@ -283,11 +299,23 @@ typedef struct SSubplan {
|
|||
SDataSinkNode* pDataSink; // data of the subplan flow into the datasink
|
||||
} 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 {
|
||||
ENodeType type;
|
||||
uint64_t queryId;
|
||||
int32_t numOfSubplans;
|
||||
SNodeList* pSubplans; // Element is SNodeListNode. The execution level of subplan, starting from 0.
|
||||
SExplainInfo explainInfo;
|
||||
} SQueryPlan;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -131,6 +131,7 @@ typedef struct SRealTableNode {
|
|||
struct STableMeta* pMeta;
|
||||
SVgroupsInfo* pVgroupList;
|
||||
char useDbName[TSDB_DB_NAME_LEN];
|
||||
double ratio;
|
||||
} SRealTableNode;
|
||||
|
||||
typedef struct STempTableNode {
|
||||
|
@ -180,8 +181,8 @@ typedef struct SOrderByExprNode {
|
|||
|
||||
typedef struct SLimitNode {
|
||||
ENodeType type; // QUERY_NODE_LIMIT
|
||||
uint64_t limit;
|
||||
uint64_t offset;
|
||||
int64_t limit;
|
||||
int64_t offset;
|
||||
} SLimitNode;
|
||||
|
||||
typedef struct SStateWindowNode {
|
||||
|
@ -282,6 +283,19 @@ typedef struct SVnodeModifOpStmt {
|
|||
const char* sql; // current sql statement position
|
||||
} 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 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 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
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -30,6 +30,11 @@ enum {
|
|||
STREAM_TASK_STATUS__STOP,
|
||||
};
|
||||
|
||||
enum {
|
||||
STREAM_CREATED_BY__USER = 1,
|
||||
STREAM_CREATED_BY__SMA,
|
||||
};
|
||||
|
||||
#if 0
|
||||
// pipe -> fetch/pipe queue
|
||||
// merge -> merge queue
|
||||
|
|
|
@ -50,6 +50,8 @@ typedef struct SRpcMsg {
|
|||
|
||||
typedef struct {
|
||||
char user[TSDB_USER_LEN];
|
||||
uint32_t clientIp;
|
||||
uint16_t clientPort;
|
||||
SRpcMsg rpcMsg;
|
||||
int32_t rspLen;
|
||||
void *pRsp;
|
||||
|
@ -105,20 +107,20 @@ void rpcClose(void *);
|
|||
void * rpcMallocCont(int contLen);
|
||||
void rpcFreeCont(void *pCont);
|
||||
void * rpcReallocCont(void *ptr, int contLen);
|
||||
void rpcSendRequest(void *thandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t *rid);
|
||||
void rpcSendRequestWithCtx(void *thandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t *rid, SRpcCtx *ctx);
|
||||
|
||||
// Because taosd supports multi-process mode
|
||||
// These functions should not be used on the server side
|
||||
// Please use tmsg<xx> functions, which are defined in tmsgcb.h
|
||||
void rpcSendRequest(void *thandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t *rid);
|
||||
void rpcSendResponse(const SRpcMsg *pMsg);
|
||||
void rpcRegisterBrokenLinkArg(SRpcMsg *msg);
|
||||
void rpcReleaseHandle(void *handle, int8_t type); // just release client conn to rpc instance, no close sock
|
||||
|
||||
// These functions will not be called in the child process
|
||||
void rpcSendRedirectRsp(void *pConn, const SEpSet *pEpSet);
|
||||
void rpcSendRequestWithCtx(void *thandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t *rid, SRpcCtx *ctx);
|
||||
int rpcGetConnInfo(void *thandle, SRpcConnInfo *pInfo);
|
||||
void rpcSendRecv(void *shandle, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp);
|
||||
int rpcReportProgress(void *pConn, char *pCont, int contLen);
|
||||
void rpcCancelRequest(int64_t rid);
|
||||
void rpcRegisterBrokenLinkArg(SRpcMsg *msg);
|
||||
// just release client conn to rpc instance, no close sock
|
||||
void rpcReleaseHandle(void *handle, int8_t type); //
|
||||
void rpcRefHandle(void *handle, int8_t type);
|
||||
void rpcUnrefHandle(void *handle, int8_t type);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -42,6 +42,9 @@ extern "C" {
|
|||
#include <sys/types.h>
|
||||
#include <termios.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#if defined(DARWIN)
|
||||
#else
|
||||
|
@ -70,7 +73,6 @@ extern "C" {
|
|||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
|
||||
|
||||
#include "osAtomic.h"
|
||||
#include "osDef.h"
|
||||
#include "osDir.h"
|
||||
|
@ -84,6 +86,7 @@ extern "C" {
|
|||
#include "osThread.h"
|
||||
#include "osSemaphore.h"
|
||||
#include "osSignal.h"
|
||||
#include "osShm.h"
|
||||
#include "osSleep.h"
|
||||
#include "osSocket.h"
|
||||
#include "osString.h"
|
||||
|
|
|
@ -12,21 +12,27 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef TDENGINE_TSCALARFUNCTION_H
|
||||
#define TDENGINE_TSCALARFUNCTION_H
|
||||
|
||||
#ifndef _TD_OS_SHM_H_
|
||||
#define _TD_OS_SHM_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "function.h"
|
||||
#include "scalar.h"
|
||||
|
||||
|
||||
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);
|
||||
void taosDetachShm(SShm *pShm);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TDENGINE_TSCALARFUNCTION_H
|
||||
#endif /*_TD_OS_SHM_H_*/
|
|
@ -16,7 +16,7 @@
|
|||
#ifndef _TD_UTIL_TAOS_ERROR_H_
|
||||
#define _TD_UTIL_TAOS_ERROR_H_
|
||||
|
||||
#include "os.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -381,6 +381,14 @@ typedef enum ELogicConditionType {
|
|||
#define TSDB_MAX_DB_DELAY 10
|
||||
#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_UNION_CLAUSE 5
|
||||
|
||||
|
|
|
@ -22,11 +22,14 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum { PROC_REQ, PROC_RSP, PROC_REG, PROC_RELEASE } ProcFuncType;
|
||||
|
||||
typedef struct SProcQueue SProcQueue;
|
||||
typedef struct SProcObj SProcObj;
|
||||
typedef void *(*ProcMallocFp)(int32_t contLen);
|
||||
typedef void *(*ProcFreeFp)(void *pCont);
|
||||
typedef void *(*ProcConsumeFp)(void *pParent, void *pHead, int32_t headLen, void *pBody, int32_t bodyLen);
|
||||
typedef void *(*ProcConsumeFp)(void *pParent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen,
|
||||
ProcFuncType ftype);
|
||||
|
||||
typedef struct {
|
||||
int32_t childQueueSize;
|
||||
|
@ -52,9 +55,10 @@ int32_t taosProcRun(SProcObj *pProc);
|
|||
void taosProcStop(SProcObj *pProc);
|
||||
bool taosProcIsChild(SProcObj *pProc);
|
||||
int32_t taosProcChildId(SProcObj *pProc);
|
||||
|
||||
int32_t taosProcPutToChildQueue(SProcObj *pProc, void *pHead, int32_t headLen, void *pBody, int32_t bodyLen);
|
||||
int32_t taosProcPutToParentQueue(SProcObj *pProc, void *pHead, int32_t headLen, void *pBody, int32_t bodyLen);
|
||||
int32_t taosProcPutToChildQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen,
|
||||
ProcFuncType ftype);
|
||||
int32_t taosProcPutToParentQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen,
|
||||
ProcFuncType ftype);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,16 +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/>.
|
||||
*/
|
||||
|
||||
#include "consumer.h"
|
|
@ -200,6 +200,9 @@ static void doDestroyRequest(void *p) {
|
|||
taosArrayDestroy(pRequest->body.showInfo.pArray);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pRequest->tableList);
|
||||
taosArrayDestroy(pRequest->dbList);
|
||||
|
||||
deregisterRequest(pRequest);
|
||||
taosMemoryFreeClear(pRequest);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,27 @@
|
|||
#include "os.h"
|
||||
#include "tref.h"
|
||||
#include "trpc.h"
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#include "catalog.h"
|
||||
#include "clientInt.h"
|
||||
#include "clientLog.h"
|
||||
#include "os.h"
|
||||
#include "query.h"
|
||||
#include "tmsg.h"
|
||||
#include "tglobal.h"
|
||||
#include "catalog.h"
|
||||
#include "tmsg.h"
|
||||
#include "tref.h"
|
||||
#include "trpc.h"
|
||||
#include "version.h"
|
||||
|
||||
#define TSC_VAR_NOT_RELEASE 1
|
||||
|
@ -56,6 +71,12 @@ void taos_cleanup(void) {
|
|||
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) {
|
||||
tscDebug("try to connect to %s:%u, user:%s db:%s", ip, port, user, db);
|
||||
if (user == NULL) {
|
||||
|
@ -117,9 +138,7 @@ int taos_field_count(TAOS_RES *res) {
|
|||
return pResInfo->numOfCols;
|
||||
}
|
||||
|
||||
int taos_num_fields(TAOS_RES *res) {
|
||||
return taos_field_count(res);
|
||||
}
|
||||
int taos_num_fields(TAOS_RES *res) { return taos_field_count(res); }
|
||||
|
||||
TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) {
|
||||
if (taos_num_fields(res) == 0) {
|
||||
|
@ -144,10 +163,8 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
|
|||
}
|
||||
|
||||
SRequestObj *pRequest = (SRequestObj *)res;
|
||||
if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT ||
|
||||
pRequest->type == TSDB_SQL_INSERT ||
|
||||
pRequest->code != TSDB_CODE_SUCCESS ||
|
||||
taos_num_fields(res) == 0) {
|
||||
if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT ||
|
||||
pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -246,23 +263,41 @@ int* taos_fetch_lengths(TAOS_RES *res) {
|
|||
return ((SRequestObj *)res)->body.resInfo.length;
|
||||
}
|
||||
|
||||
TAOS_ROW *taos_result_block(TAOS_RES *res) {
|
||||
// TODO
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// todo intergrate with tDataTypes
|
||||
const char *taos_data_type(int type) {
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_NULL: return "TSDB_DATA_TYPE_NULL";
|
||||
case TSDB_DATA_TYPE_BOOL: return "TSDB_DATA_TYPE_BOOL";
|
||||
case TSDB_DATA_TYPE_TINYINT: return "TSDB_DATA_TYPE_TINYINT";
|
||||
case TSDB_DATA_TYPE_SMALLINT: return "TSDB_DATA_TYPE_SMALLINT";
|
||||
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_NULL:
|
||||
return "TSDB_DATA_TYPE_NULL";
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
return "TSDB_DATA_TYPE_BOOL";
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
return "TSDB_DATA_TYPE_TINYINT";
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
return "TSDB_DATA_TYPE_SMALLINT";
|
||||
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_TIMESTAMP: return "TSDB_DATA_TYPE_TIMESTAMP";
|
||||
case TSDB_DATA_TYPE_NCHAR: return "TSDB_DATA_TYPE_NCHAR";
|
||||
case TSDB_DATA_TYPE_JSON: return "TSDB_DATA_TYPE_JSON";
|
||||
default: return "UNKNOWN";
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
return "TSDB_DATA_TYPE_TIMESTAMP";
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
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);
|
||||
}
|
||||
|
||||
bool taos_is_update_query(TAOS_RES *res) {
|
||||
// TODO
|
||||
return true;
|
||||
}
|
||||
|
||||
int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) {
|
||||
if (res == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
SRequestObj *pRequest = (SRequestObj *)res;
|
||||
if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT ||
|
||||
pRequest->type == TSDB_SQL_INSERT ||
|
||||
pRequest->code != TSDB_CODE_SUCCESS ||
|
||||
taos_num_fields(res) == 0) {
|
||||
if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT ||
|
||||
pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -352,8 +390,11 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) {
|
|||
return pResultInfo->numOfRows;
|
||||
}
|
||||
|
||||
int taos_validate_sql(TAOS *taos, const char *sql) {
|
||||
return true;
|
||||
int taos_validate_sql(TAOS *taos, const char *sql) { return true; }
|
||||
|
||||
void taos_reset_current_db(TAOS *taos) {
|
||||
// TODO
|
||||
return;
|
||||
}
|
||||
|
||||
const char *taos_get_server_info(TAOS *taos) {
|
||||
|
@ -387,6 +428,11 @@ void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress) {
|
|||
// TODO
|
||||
}
|
||||
|
||||
int taos_load_table_info(TAOS *taos, const char *tableNameList) {
|
||||
// TODO
|
||||
return -1;
|
||||
}
|
||||
|
||||
TAOS_STMT *taos_stmt_init(TAOS *taos) {
|
||||
// TODO
|
||||
return NULL;
|
||||
|
@ -437,11 +483,26 @@ int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name) {
|
|||
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) {
|
||||
// TODO
|
||||
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) {
|
||||
// TODO
|
||||
return -1;
|
||||
|
|
|
@ -26,6 +26,18 @@
|
|||
#include "tqueue.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 {
|
||||
SArray container;
|
||||
};
|
||||
|
@ -103,9 +115,10 @@ typedef struct {
|
|||
char* sql;
|
||||
char* topicName;
|
||||
int64_t topicId;
|
||||
int32_t nextVgIdx;
|
||||
SArray* vgs; // SArray<SMqClientVg>
|
||||
SSchemaWrapper schema;
|
||||
int8_t isSchemaAdaptive;
|
||||
int32_t numOfFields;
|
||||
TAOS_FIELD* fields;
|
||||
} SMqClientTopic;
|
||||
|
||||
typedef struct {
|
||||
|
@ -131,10 +144,10 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
tmq_t* tmq;
|
||||
/*SMqClientVg* pVg;*/
|
||||
int32_t async;
|
||||
tsem_t rspSem;
|
||||
tmq_resp_err_t rspErr;
|
||||
/*SMqClientVg* pVg;*/
|
||||
} SMqCommitCbParam;
|
||||
|
||||
tmq_conf_t* tmq_conf_new() {
|
||||
|
@ -228,6 +241,10 @@ void tmq_list_destroy(tmq_list_t* list) {
|
|||
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) {
|
||||
tmq_message_t* msg = NULL;
|
||||
while (1) {
|
||||
|
@ -471,7 +488,12 @@ tmq_resp_err_t tmq_subscribe(tmq_t* tmq, tmq_list_t* topic_list) {
|
|||
tNameExtractFullName(&name, topicFname);
|
||||
tscDebug("subscribe topic: %s", topicFname);
|
||||
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));
|
||||
taosArrayPush(tmq->clientTopics, &topic);
|
||||
taosArrayPush(req.topicNames, &topicFname);
|
||||
|
@ -615,6 +637,7 @@ _return:
|
|||
return pRequest;
|
||||
}
|
||||
|
||||
#if 0
|
||||
TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, int sqlLen) {
|
||||
STscObj* pTscObj = (STscObj*)taos;
|
||||
SRequestObj* pRequest = NULL;
|
||||
|
@ -700,6 +723,7 @@ _return:
|
|||
|
||||
return pRequest;
|
||||
}
|
||||
#endif
|
||||
|
||||
static char* formatTimestamp(char* buf, int64_t val, int precision) {
|
||||
time_t tt;
|
||||
|
@ -807,7 +831,7 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
SMqClientVg* pVg = pParam->pVg;
|
||||
tmq_t* tmq = pParam->tmq;
|
||||
if (code != 0) {
|
||||
printf("msg discard, code:%x\n", code);
|
||||
tscWarn("msg discard, code:%x", code);
|
||||
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);
|
||||
if (msgEpoch < tmqEpoch) {
|
||||
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;
|
||||
}
|
||||
|
||||
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 {
|
||||
atomic_sub_fetch_32(&tmq->waitingRequest, 1);
|
||||
}
|
||||
|
@ -879,19 +903,54 @@ WRITE_QUEUE_FAIL:
|
|||
bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) {
|
||||
/*printf("call update ep %d\n", epoch);*/
|
||||
bool set = false;
|
||||
int32_t sz = taosArrayGetSize(pRsp->topics);
|
||||
SArray* newTopics = taosArrayInit(sz, sizeof(SMqClientTopic));
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
int32_t topicNumGet = taosArrayGetSize(pRsp->topics);
|
||||
char vgKey[TSDB_TOPIC_FNAME_LEN + 22];
|
||||
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};
|
||||
SMqSubTopicEp* pTopicEp = taosArrayGet(pRsp->topics, i);
|
||||
taosHashClear(pHash);
|
||||
topic.topicName = strdup(pTopicEp->topic);
|
||||
int32_t vgSz = taosArrayGetSize(pTopicEp->vgs);
|
||||
topic.vgs = taosArrayInit(vgSz, sizeof(SMqClientVg));
|
||||
for (int32_t j = 0; j < vgSz; j++) {
|
||||
|
||||
int32_t topicNumCur = taosArrayGetSize(tmq->clientTopics);
|
||||
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);
|
||||
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 = {
|
||||
.pollCnt = 0,
|
||||
.currentOffset = pVgEp->offset,
|
||||
.currentOffset = offset,
|
||||
.vgId = pVgEp->vgId,
|
||||
.epSet = pVgEp->epSet,
|
||||
.vgStatus = TMQ_VG_STATUS__IDLE,
|
||||
|
@ -902,6 +961,7 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) {
|
|||
taosArrayPush(newTopics, &topic);
|
||||
}
|
||||
if (tmq->clientTopics) taosArrayDestroy(tmq->clientTopics);
|
||||
taosHashCleanup(pHash);
|
||||
tmq->clientTopics = newTopics;
|
||||
atomic_store_32(&tmq->epoch, epoch);
|
||||
return set;
|
||||
|
@ -911,7 +971,7 @@ int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
SMqAskEpCbParam* pParam = (SMqAskEpCbParam*)param;
|
||||
tmq_t* tmq = pParam->tmq;
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1282,6 +1342,7 @@ tmq_message_t* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) {
|
|||
|
||||
while (1) {
|
||||
/*printf("cycle\n");*/
|
||||
tmqAskEp(tmq, false);
|
||||
tmqPollImpl(tmq, blocking_time);
|
||||
|
||||
tsem_wait(&tmq->rspSem);
|
||||
|
|
|
@ -55,8 +55,9 @@ TEST(testCase, create_topic_ctb_Test) {
|
|||
|
||||
taos_free_result(pRes);
|
||||
|
||||
char* sql = "select * from tu";
|
||||
pRes = tmq_create_topic(pConn, "test_ctb_topic_1", sql, strlen(sql));
|
||||
// char* sql = "select * from tu";
|
||||
// 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_close(pConn);
|
||||
}
|
||||
|
@ -79,8 +80,9 @@ TEST(testCase, create_topic_stb_Test) {
|
|||
|
||||
taos_free_result(pRes);
|
||||
|
||||
char* sql = "select * from st1";
|
||||
pRes = tmq_create_topic(pConn, "test_stb_topic_1", sql, strlen(sql));
|
||||
// char* sql = "select * from st1";
|
||||
// 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_close(pConn);
|
||||
}
|
||||
|
|
|
@ -331,7 +331,6 @@ int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
ASSERT(pColInfoData->nullbitmap == NULL);
|
||||
pDataBlock->info.window.skey = *(TSKEY*)colDataGetData(pColInfoData, 0);
|
||||
pDataBlock->info.window.ekey = *(TSKEY*)colDataGetData(pColInfoData, (pDataBlock->info.rows - 1));
|
||||
return 0;
|
||||
|
@ -609,22 +608,6 @@ size_t blockDataGetSerialMetaSize(const SSDataBlock* pBlock) {
|
|||
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) {
|
||||
ASSERT(pBlock != NULL);
|
||||
double rowSize = 0;
|
||||
|
@ -647,7 +630,6 @@ double blockDataGetSerialRowSize(const SSDataBlock* pBlock) {
|
|||
typedef struct SSDataBlockSortHelper {
|
||||
SArray* orderInfo; // SArray<SBlockOrderInfo>
|
||||
SSDataBlock* pDataBlock;
|
||||
bool nullFirst;
|
||||
} SSDataBlockSortHelper;
|
||||
|
||||
int32_t dataBlockCompar(const void* p1, const void* p2, const void* param) {
|
||||
|
@ -672,11 +654,11 @@ int32_t dataBlockCompar(const void* p1, const void* p2, const void* param) {
|
|||
}
|
||||
|
||||
if (rightNull) {
|
||||
return pHelper->nullFirst ? 1 : -1;
|
||||
return pOrder->nullFirst ? 1 : -1;
|
||||
}
|
||||
|
||||
if (leftNull) {
|
||||
return pHelper->nullFirst ? -1 : 1;
|
||||
return pOrder->nullFirst ? -1 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -907,7 +889,7 @@ static __compar_fn_t getComparFn(int32_t type, int32_t order) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirst) {
|
||||
int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo) {
|
||||
ASSERT(pDataBlock != NULL && pOrderInfo != NULL);
|
||||
if (pDataBlock->info.rows <= 1) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -922,7 +904,7 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirs
|
|||
for (int32_t i = 0; i < taosArrayGetSize(pOrderInfo); ++i) {
|
||||
SBlockOrderInfo* pInfo = taosArrayGet(pOrderInfo, i);
|
||||
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, pInfo->colIndex);
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, pInfo->slotId);
|
||||
if (pColInfoData->hasNull) {
|
||||
sortColumnHasNull = true;
|
||||
}
|
||||
|
@ -961,10 +943,10 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirs
|
|||
|
||||
int64_t p0 = taosGetTimestampUs();
|
||||
|
||||
SSDataBlockSortHelper helper = {.nullFirst = nullFirst, .pDataBlock = pDataBlock, .orderInfo = pOrderInfo};
|
||||
SSDataBlockSortHelper helper = {.pDataBlock = pDataBlock, .orderInfo = pOrderInfo};
|
||||
for (int32_t i = 0; i < taosArrayGetSize(helper.orderInfo); ++i) {
|
||||
struct SBlockOrderInfo* pInfo = taosArrayGet(helper.orderInfo, i);
|
||||
pInfo->pColData = taosArrayGet(pDataBlock->pDataBlock, pInfo->colIndex);
|
||||
pInfo->pColData = taosArrayGet(pDataBlock->pDataBlock, pInfo->slotId);
|
||||
}
|
||||
|
||||
taosqsort(index, rows, sizeof(int32_t), &helper, dataBlockCompar);
|
||||
|
@ -1012,7 +994,7 @@ SHelper* createTupleIndex_rv(int32_t numOfRows, SArray* pOrderInfo, SSDataBlock*
|
|||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SBlockOrderInfo* pInfo = taosArrayGet(pOrderInfo, i);
|
||||
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, pInfo->colIndex);
|
||||
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, pInfo->slotId);
|
||||
pInfo->pColData = pColInfo;
|
||||
sortValLengthPerRow += pColInfo->info.bytes;
|
||||
}
|
||||
|
@ -1106,7 +1088,7 @@ int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullF
|
|||
// Allocate the additional buffer.
|
||||
int64_t p0 = taosGetTimestampUs();
|
||||
|
||||
SSDataBlockSortHelper helper = {.nullFirst = nullFirst, .pDataBlock = pDataBlock, .orderInfo = pOrderInfo};
|
||||
SSDataBlockSortHelper helper = {.pDataBlock = pDataBlock, .orderInfo = pOrderInfo};
|
||||
|
||||
uint32_t rows = pDataBlock->info.rows;
|
||||
SHelper* index = createTupleIndex_rv(rows, helper.orderInfo, pDataBlock);
|
||||
|
|
|
@ -45,7 +45,7 @@ float tsRatioOfQueryCores = 1.0f;
|
|||
int32_t tsMaxBinaryDisplayWidth = 30;
|
||||
bool tsEnableSlaveQuery = 1;
|
||||
bool tsPrintAuth = 0;
|
||||
int32_t tsMultiProcess = 0;
|
||||
bool tsMultiProcess = 0;
|
||||
|
||||
// monitor
|
||||
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, "slaveQuery", tsEnableSlaveQuery, 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 (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;
|
||||
tsEnableSlaveQuery = cfgGetItem(pCfg, "slaveQuery")->bval;
|
||||
tsDeadLockKillQuery = cfgGetItem(pCfg, "deadLockKillQuery")->bval;
|
||||
tsMultiProcess = cfgGetItem(pCfg, "multiProcess")->i32;
|
||||
tsMultiProcess = cfgGetItem(pCfg, "multiProcess")->bval;
|
||||
|
||||
tsEnableMonitor = cfgGetItem(pCfg, "monitor")->bval;
|
||||
tsMonitorInterval = cfgGetItem(pCfg, "monitorInterval")->i32;
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "tmsgcb.h"
|
||||
|
||||
static SMsgCb tsDefaultMsgCb;
|
||||
|
||||
void tmsgSetDefaultMsgCb(const SMsgCb* pMsgCb) { tsDefaultMsgCb = *pMsgCb; }
|
||||
|
||||
int32_t tmsgPutToQueue(const SMsgCb* pMsgCb, EQueueType qtype, SRpcMsg* pReq) {
|
||||
return (*pMsgCb->queueFps[qtype])(pMsgCb->pWrapper, pReq);
|
||||
}
|
||||
|
@ -24,7 +28,7 @@ int32_t tmsgGetQueueSize(const SMsgCb* pMsgCb, int32_t vgId, EQueueType qtype) {
|
|||
return (*pMsgCb->qsizeFp)(pMsgCb->pWrapper, vgId, qtype);
|
||||
}
|
||||
|
||||
int32_t tmsgSendReq(const SMsgCb* pMsgCb, SEpSet* epSet, SRpcMsg* pReq) {
|
||||
int32_t tmsgSendReq(const SMsgCb* pMsgCb, const SEpSet* epSet, SRpcMsg* pReq) {
|
||||
return (*pMsgCb->sendReqFp)(pMsgCb->pWrapper, epSet, pReq);
|
||||
}
|
||||
|
||||
|
@ -32,4 +36,12 @@ int32_t tmsgSendMnodeReq(const SMsgCb* pMsgCb, SRpcMsg* pReq) {
|
|||
return (*pMsgCb->sendMnodeReqFp)(pMsgCb->pWrapper, pReq);
|
||||
}
|
||||
|
||||
void tmsgSendRsp(const SMsgCb* pMsgCb, 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) {
|
||||
(*pMsgCb->registerBrokenLinkArgFp)(pMsgCb->pWrapper, pMsg);
|
||||
}
|
||||
|
||||
void tmsgReleaseHandle(void* handle, int8_t type) {
|
||||
(*tsDefaultMsgCb.releaseHandleFp)(tsDefaultMsgCb.pWrapper, handle, type);
|
||||
}
|
|
@ -167,10 +167,10 @@ TEST(testCase, Datablock_test) {
|
|||
printf("the second row of binary:%s, length:%d\n", (char*)varDataVal(pData), varDataLen(pData));
|
||||
|
||||
SArray* pOrderInfo = taosArrayInit(3, sizeof(SBlockOrderInfo));
|
||||
SBlockOrderInfo order = {.order = TSDB_ORDER_ASC, .colIndex = 0};
|
||||
SBlockOrderInfo order = {.nullFirst = true, .order = TSDB_ORDER_ASC, .slotId = 0};
|
||||
taosArrayPush(pOrderInfo, &order);
|
||||
|
||||
blockDataSort(b, pOrderInfo, true);
|
||||
blockDataSort(b, pOrderInfo);
|
||||
blockDataDestroy(b);
|
||||
|
||||
taosArrayDestroy(pOrderInfo);
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
aux_source_directory(src DNODE_SRC)
|
||||
aux_source_directory(dnode/src DNODE_SRC)
|
||||
aux_source_directory(qnode/src DNODE_SRC)
|
||||
aux_source_directory(bnode/src DNODE_SRC)
|
||||
aux_source_directory(snode/src DNODE_SRC)
|
||||
aux_source_directory(vnode/src DNODE_SRC)
|
||||
aux_source_directory(mnode/src DNODE_SRC)
|
||||
aux_source_directory(container/src DNODE_SRC)
|
||||
|
||||
aux_source_directory(dm/src DNODE_SRC)
|
||||
aux_source_directory(qm/src DNODE_SRC)
|
||||
aux_source_directory(bm/src DNODE_SRC)
|
||||
aux_source_directory(sm/src DNODE_SRC)
|
||||
aux_source_directory(vm/src DNODE_SRC)
|
||||
aux_source_directory(mm/src DNODE_SRC)
|
||||
aux_source_directory(main/src DNODE_SRC)
|
||||
add_library(dnode STATIC ${DNODE_SRC})
|
||||
target_link_libraries(
|
||||
dnode cjson mnode vnode qnode snode bnode wal sync taos tfs monitor
|
||||
|
@ -14,16 +12,22 @@ target_link_libraries(
|
|||
target_include_directories(
|
||||
dnode
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/mgmt"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/dnode/inc"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/qnode/inc"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/bnode/inc"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/snode/inc"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/vnode/inc"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/mnode/inc"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/container/inc"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/dm/inc"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/qm/inc"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/bm/inc"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/sm/inc"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/vm/inc"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/mm/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})
|
||||
add_subdirectory(test)
|
||||
|
|
|
@ -24,6 +24,7 @@ static void bmInitOption(SBnodeMgmt *pMgmt, SBnodeOpt *pOption) {
|
|||
msgCb.sendReqFp = dndSendReqToDnode;
|
||||
msgCb.sendMnodeReqFp = dndSendReqToMnode;
|
||||
msgCb.sendRspFp = dndSendRsp;
|
||||
msgCb.registerBrokenLinkArgFp = dndRegisterBrokenLinkArg;
|
||||
pOption->msgCb = msgCb;
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
|
@ -29,7 +29,7 @@ void dmInitMsgHandles(SMgmtWrapper *pWrapper);
|
|||
|
||||
void dmGetMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet);
|
||||
void dmUpdateMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet);
|
||||
void dmSendRedirectRsp(SDnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||
void dmSendRedirectRsp(SDnodeMgmt *pMgmt, const SRpcMsg *pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
|
@ -54,7 +54,7 @@ void dmGetDnodeEp(SMgmtWrapper *pWrapper, int32_t dnodeId, char *pEp, char *pFqd
|
|||
taosRUnLockLatch(&pMgmt->latch);
|
||||
}
|
||||
|
||||
void dmSendRedirectRsp(SDnodeMgmt *pMgmt, SRpcMsg *pReq) {
|
||||
void dmSendRedirectRsp(SDnodeMgmt *pMgmt, const SRpcMsg *pReq) {
|
||||
SDnode *pDnode = pMgmt->pDnode;
|
||||
|
||||
SEpSet epSet = {0};
|
|
@ -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,217 @@
|
|||
/*
|
||||
* 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) {
|
||||
// Set the parent process signal
|
||||
// When the child process exits, the parent process receives a signal
|
||||
taosSetSignal(SIGCHLD, dndHandleChild);
|
||||
} else {
|
||||
// Set child process signal
|
||||
// When the parent process exits, the child process will receive the SIGKILL signal
|
||||
prctl(PR_SET_PDEATHSIG, SIGKILL);
|
||||
}
|
||||
}
|
||||
|
||||
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]);
|
||||
} 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);
|
||||
prctl(PR_SET_NAME, name);
|
||||
strcpy(argv[0], 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 "ttime.h"
|
||||
#include "tworker.h"
|
||||
#include "tmsgcb.h"
|
||||
|
||||
#include "dnode.h"
|
||||
#include "monitor.h"
|
||||
|
@ -95,10 +96,11 @@ typedef struct SMgmtWrapper {
|
|||
bool required;
|
||||
EProcType procType;
|
||||
SProcObj *pProc;
|
||||
SShm shm;
|
||||
void *pMgmt;
|
||||
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
|
||||
int8_t msgVgIds[TDMT_MAX]; // Handle the case where the same message type is distributed to qnode or vnode
|
||||
SMgmtFp fp;
|
||||
} SMgmtWrapper;
|
||||
|
||||
|
@ -118,27 +120,32 @@ typedef struct SDnode {
|
|||
char *firstEp;
|
||||
char *secondEp;
|
||||
char *dataDir;
|
||||
SDiskCfg *pDisks;
|
||||
SDiskCfg *disks;
|
||||
int32_t numOfDisks;
|
||||
uint16_t serverPort;
|
||||
bool dropped;
|
||||
ENodeType ntype;
|
||||
EDndStatus status;
|
||||
EDndEvent event;
|
||||
SStartupReq startup;
|
||||
TdFilePtr pLockFile;
|
||||
TdFilePtr runtimeFile;
|
||||
STransMgmt trans;
|
||||
SMgmtWrapper wrappers[NODE_MAX];
|
||||
} SDnode;
|
||||
|
||||
const char *dndNodeLogStr(ENodeType ntype);
|
||||
const char *dndNodeProcStr(ENodeType ntype);
|
||||
EDndStatus dndGetStatus(SDnode *pDnode);
|
||||
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 dndSendMonitorReport(SDnode *pDnode);
|
||||
|
||||
int32_t dndSendReqToMnode(SMgmtWrapper *pWrapper, SRpcMsg *pMsg);
|
||||
int32_t dndSendReqToDnode(SMgmtWrapper *pWrapper, SEpSet *pEpSet, SRpcMsg *pMsg);
|
||||
void dndSendRsp(SMgmtWrapper *pWrapper, SRpcMsg *pRsp);
|
||||
int32_t dndSendReqToDnode(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pMsg);
|
||||
void dndSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp);
|
||||
void dndRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg);
|
||||
SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper);
|
||||
|
||||
int32_t dndProcessNodeMsg(SDnode *pDnode, SNodeMsg *pMsg);
|
||||
int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed);
|
|
@ -34,7 +34,6 @@ int32_t dndInit();
|
|||
void dndCleanup();
|
||||
const char *dndStatStr(EDndStatus stat);
|
||||
void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup);
|
||||
TdFilePtr dndCheckRunning(const char *dataDir);
|
||||
void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
|
||||
// dndMsg.c
|
||||
|
@ -56,6 +55,12 @@ void dndCleanupServer(SDnode *pDnode);
|
|||
int32_t dndInitClient(SDnode *pDnode);
|
||||
void dndCleanupClient(SDnode *pDnode);
|
||||
int32_t dndInitMsgHandle(SDnode *pDnode);
|
||||
void dndSendRpcRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp);
|
||||
|
||||
// dndFile.c
|
||||
int32_t dndOpenRuntimeFile(SDnode *pDnode);
|
||||
int32_t dndWriteRuntimeFile(SDnode *pDnode);
|
||||
void dndCloseRuntimeFile(SDnode *pDnode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
|
@ -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_*/
|
|
@ -77,6 +77,8 @@ static int32_t dndRunInSingleProcess(SDnode *pDnode) {
|
|||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
pWrapper->required = dndRequireNode(pWrapper);
|
||||
if (!pWrapper->required) continue;
|
||||
SMsgCb msgCb = dndCreateMsgcb(pWrapper);
|
||||
tmsgSetDefaultMsgCb(&msgCb);
|
||||
|
||||
if (taosMkDir(pWrapper->path) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
|
@ -116,11 +118,11 @@ static void dndClearNodesExecpt(SDnode *pDnode, ENodeType except) {
|
|||
}
|
||||
}
|
||||
|
||||
static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int32_t msgLen, void *pCont, int32_t contLen) {
|
||||
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 process queue, type:%s handle:%p app:%p", pMsg, TMSG_INFO(pRpc->msgType),
|
||||
pRpc->handle, pRpc->ahandle);
|
||||
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);
|
||||
|
@ -138,13 +140,27 @@ static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int32_t
|
|||
}
|
||||
}
|
||||
|
||||
static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, int32_t msgLen, void *pCont, int32_t contLen) {
|
||||
pRpc->pCont = pCont;
|
||||
dTrace("msg:%p, get from parent process queue, type:%s handle:%p app:%p", pRpc, TMSG_INFO(pRpc->msgType),
|
||||
pRpc->handle, pRpc->ahandle);
|
||||
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);
|
||||
|
||||
dndSendRsp(pWrapper, pRpc);
|
||||
taosMemoryFree(pRpc);
|
||||
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 dndRunInMultiProcess(SDnode *pDnode) {
|
||||
|
@ -155,6 +171,9 @@ static int32_t dndRunInMultiProcess(SDnode *pDnode) {
|
|||
pWrapper->required = dndRequireNode(pWrapper);
|
||||
if (!pWrapper->required) continue;
|
||||
|
||||
SMsgCb msgCb = dndCreateMsgcb(pWrapper);
|
||||
tmsgSetDefaultMsgCb(&msgCb);
|
||||
|
||||
if (taosMkDir(pWrapper->path) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create dir:%s since %s", pWrapper->path, terrstr());
|
||||
|
@ -202,16 +221,24 @@ static int32_t dndRunInMultiProcess(SDnode *pDnode) {
|
|||
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 (dndOpenNode(pWrapper) != 0) {
|
||||
dInfo("node:%s, failed to init in child process since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosProcRun(pProc) != 0) {
|
||||
dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
} 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);
|
||||
|
@ -232,7 +259,7 @@ static int32_t dndRunInMultiProcess(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
int32_t dndRun(SDnode *pDnode) {
|
||||
if (tsMultiProcess == 0) {
|
||||
if (!tsMultiProcess) {
|
||||
if (dndRunInSingleProcess(pDnode) != 0) {
|
||||
dError("failed to run dnode in single process mode since %s", terrstr());
|
||||
return -1;
|
|
@ -0,0 +1,264 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
int32_t dndOpenRuntimeFile(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.running", 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;
|
||||
}
|
||||
|
||||
if (taosLockFile(pFile) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to lock file:%s since %s", file, terrstr());
|
||||
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) {
|
||||
for (ENodeType ntype = DNODE; ntype < NODE_MAX; ++ntype) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->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 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 (code != 0) {
|
||||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
} else {
|
||||
pDnode->runtimeFile = pFile;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t dndWriteRuntimeFile(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.running.bak", pDnode->dataDir, TD_DIRSEP);
|
||||
snprintf(realfile, sizeof(realfile), "%s%s.running", 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[pDnode->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;
|
||||
}
|
||||
|
||||
dDebug("successed to write %s", realfile);
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
if (pFile != NULL) {
|
||||
taosCloseFile(&pFile);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
void dndCloseRuntimeFile(SDnode *pDnode) {
|
||||
if (pDnode->runtimeFile) {
|
||||
taosUnLockFile(pDnode->runtimeFile);
|
||||
taosCloseFile(&pDnode->runtimeFile);
|
||||
pDnode->runtimeFile = NULL;
|
||||
}
|
||||
}
|
|
@ -20,7 +20,7 @@
|
|||
static int8_t once = DND_ENV_INIT;
|
||||
|
||||
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) {
|
||||
terrno = TSDB_CODE_REPEAT_INIT;
|
||||
dError("failed to init dnode env since %s", terrstr());
|
||||
|
@ -31,12 +31,6 @@ int32_t dndInit() {
|
|||
taosBlockSIGPIPE();
|
||||
taosResolveCRC();
|
||||
|
||||
if (rpcInit() != 0) {
|
||||
dError("failed to init rpc since %s", terrstr());
|
||||
dndCleanup();
|
||||
return -1;
|
||||
}
|
||||
|
||||
SMonCfg monCfg = {0};
|
||||
monCfg.maxLogs = tsMonitorMaxLogs;
|
||||
monCfg.port = tsMonitorPort;
|
||||
|
@ -44,29 +38,27 @@ int32_t dndInit() {
|
|||
monCfg.comp = tsMonitorComp;
|
||||
if (monInit(&monCfg) != 0) {
|
||||
dError("failed to init monitor since %s", terrstr());
|
||||
dndCleanup();
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("dnode env is initialized");
|
||||
dDebug("dnode env is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
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) {
|
||||
dError("dnode env is already cleaned up");
|
||||
return;
|
||||
}
|
||||
|
||||
monCleanup();
|
||||
rpcCleanup();
|
||||
walCleanUp();
|
||||
taosStopCacheRefreshWorker();
|
||||
dInfo("dnode env is cleaned up");
|
||||
dDebug("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->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) {
|
||||
SStartupReq *pStartup = &pDnode->startup;
|
||||
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);
|
||||
}
|
||||
|
||||
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) {
|
||||
dDebug("startup req is received");
|
||||
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();
|
||||
}
|
|
@ -42,6 +42,8 @@ static inline int32_t dndBuildMsg(SNodeMsg *pMsg, SRpcMsg *pRpc) {
|
|||
}
|
||||
|
||||
memcpy(pMsg->user, connInfo.user, TSDB_USER_LEN);
|
||||
pMsg->clientIp = connInfo.clientIp;
|
||||
pMsg->clientPort = connInfo.clientPort;
|
||||
memcpy(&pMsg->rpcMsg, pRpc, sizeof(SRpcMsg));
|
||||
return 0;
|
||||
}
|
||||
|
@ -66,7 +68,7 @@ void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
|||
} else if (pWrapper->procType == PROC_PARENT) {
|
||||
dTrace("msg:%p, is created and will put into child queue, handle:%p app:%p user:%s", pMsg, pRpc->handle,
|
||||
pRpc->ahandle, pMsg->user);
|
||||
code = taosProcPutToChildQueue(pWrapper->pProc, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen);
|
||||
code = taosProcPutToChildQ(pWrapper->pProc, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen, PROC_REQ);
|
||||
} else {
|
||||
dTrace("msg:%p, should not processed in child process, handle:%p app:%p user:%s", pMsg, pRpc->handle, pRpc->ahandle,
|
||||
pMsg->user);
|
|
@ -16,7 +16,7 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#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->serverPort = pOption->serverPort;
|
||||
pDnode->dataDir = strdup(pOption->dataDir);
|
||||
|
@ -24,8 +24,9 @@ static int32_t dndInitMemory(SDnode *pDnode, const SDnodeOpt *pOption) {
|
|||
pDnode->localFqdn = strdup(pOption->localFqdn);
|
||||
pDnode->firstEp = strdup(pOption->firstEp);
|
||||
pDnode->secondEp = strdup(pOption->secondEp);
|
||||
pDnode->pDisks = pOption->pDisks;
|
||||
pDnode->disks = pOption->disks;
|
||||
pDnode->numOfDisks = pOption->numOfDisks;
|
||||
pDnode->ntype = pOption->ntype;
|
||||
pDnode->rebootTime = taosGetTimestampMs();
|
||||
|
||||
if (pDnode->dataDir == NULL || pDnode->localEp == NULL || pDnode->localFqdn == NULL || pDnode->firstEp == NULL ||
|
||||
|
@ -36,16 +37,12 @@ static int32_t dndInitMemory(SDnode *pDnode, const SDnodeOpt *pOption) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void dndClearMemory(SDnode *pDnode) {
|
||||
static void dndClearVars(SDnode *pDnode) {
|
||||
for (ENodeType n = 0; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pMgmt = &pDnode->wrappers[n];
|
||||
taosMemoryFreeClear(pMgmt->path);
|
||||
}
|
||||
if (pDnode->pLockFile != NULL) {
|
||||
taosUnLockFile(pDnode->pLockFile);
|
||||
taosCloseFile(&pDnode->pLockFile);
|
||||
pDnode->pLockFile = NULL;
|
||||
}
|
||||
dndCloseRuntimeFile(pDnode);
|
||||
taosMemoryFreeClear(pDnode->localEp);
|
||||
taosMemoryFreeClear(pDnode->localFqdn);
|
||||
taosMemoryFreeClear(pDnode->firstEp);
|
||||
|
@ -67,13 +64,21 @@ SDnode *dndCreate(const SDnodeOpt *pOption) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
if (dndInitMemory(pDnode, pOption) != 0) {
|
||||
if (dndInitVars(pDnode, pOption) != 0) {
|
||||
dError("failed to init variables since %s", terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
dndSetStatus(pDnode, DND_STAT_INIT);
|
||||
pDnode->pLockFile = dndCheckRunning(pDnode->dataDir);
|
||||
if (pDnode->pLockFile == NULL) {
|
||||
dmGetMgmtFp(&pDnode->wrappers[DNODE]);
|
||||
mmGetMgmtFp(&pDnode->wrappers[MNODE]);
|
||||
vmGetMgmtFp(&pDnode->wrappers[VNODES]);
|
||||
qmGetMgmtFp(&pDnode->wrappers[QNODE]);
|
||||
smGetMgmtFp(&pDnode->wrappers[SNODE]);
|
||||
bmGetMgmtFp(&pDnode->wrappers[BNODE]);
|
||||
|
||||
if (dndOpenRuntimeFile(pDnode) != 0) {
|
||||
dError("failed to open runtime file since %s", terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -87,13 +92,6 @@ SDnode *dndCreate(const SDnodeOpt *pOption) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
dmGetMgmtFp(&pDnode->wrappers[DNODE]);
|
||||
mmGetMgmtFp(&pDnode->wrappers[MNODE]);
|
||||
vmGetMgmtFp(&pDnode->wrappers[VNODES]);
|
||||
qmGetMgmtFp(&pDnode->wrappers[QNODE]);
|
||||
smGetMgmtFp(&pDnode->wrappers[SNODE]);
|
||||
bmGetMgmtFp(&pDnode->wrappers[BNODE]);
|
||||
|
||||
if (dndInitMsgHandle(pDnode) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -116,7 +114,7 @@ SDnode *dndCreate(const SDnodeOpt *pOption) {
|
|||
|
||||
_OVER:
|
||||
if (code != 0 && pDnode) {
|
||||
dndClearMemory(pDnode);
|
||||
dndClearVars(pDnode);
|
||||
pDnode = NULL;
|
||||
dError("failed to create dnode object since %s", terrstr());
|
||||
} else {
|
||||
|
@ -145,7 +143,7 @@ void dndClose(SDnode *pDnode) {
|
|||
dndCloseNode(pWrapper);
|
||||
}
|
||||
|
||||
dndClearMemory(pDnode);
|
||||
dndClearVars(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";
|
||||
}
|
||||
}
|
|
@ -309,7 +309,7 @@ int32_t dndInitMsgHandle(SDnode *pDnode) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndSendRpcReq(STransMgmt *pMgmt, SEpSet *pEpSet, SRpcMsg *pReq) {
|
||||
static int32_t dndSendRpcReq(STransMgmt *pMgmt, const SEpSet *pEpSet, SRpcMsg *pReq) {
|
||||
if (pMgmt->clientRpc == NULL) {
|
||||
terrno = TSDB_CODE_DND_OFFLINE;
|
||||
return -1;
|
||||
|
@ -319,9 +319,8 @@ static int32_t dndSendRpcReq(STransMgmt *pMgmt, SEpSet *pEpSet, SRpcMsg *pReq) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t dndSendReqToDnode(SMgmtWrapper *pWrapper, SEpSet *pEpSet, SRpcMsg *pReq) {
|
||||
if (pWrapper->procType == PROC_CHILD) {
|
||||
} else {
|
||||
int32_t dndSendReqToDnode(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pReq) {
|
||||
if (pWrapper->procType != PROC_CHILD) {
|
||||
SDnode *pDnode = pWrapper->pDnode;
|
||||
if (dndGetStatus(pDnode) != DND_STAT_RUNNING) {
|
||||
terrno = TSDB_CODE_DND_OFFLINE;
|
||||
|
@ -329,26 +328,27 @@ int32_t dndSendReqToDnode(SMgmtWrapper *pWrapper, SEpSet *pEpSet, SRpcMsg *pReq)
|
|||
return -1;
|
||||
}
|
||||
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) {
|
||||
if (pWrapper->procType == PROC_CHILD) {
|
||||
} else {
|
||||
SDnode *pDnode = pWrapper->pDnode;
|
||||
STransMgmt *pTrans = &pDnode->trans;
|
||||
SEpSet epSet = {0};
|
||||
|
||||
SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, DNODE);
|
||||
if (pWrapper != NULL) {
|
||||
dmGetMnodeEpSet(pWrapper->pMgmt, &epSet);
|
||||
dndReleaseWrapper(pWrapper);
|
||||
SMgmtWrapper *pWrapper2 = dndAcquireWrapper(pDnode, DNODE);
|
||||
if (pWrapper2 != NULL) {
|
||||
dmGetMnodeEpSet(pWrapper2->pMgmt, &epSet);
|
||||
dndReleaseWrapper(pWrapper2);
|
||||
}
|
||||
return dndSendRpcReq(pTrans, &epSet, pReq);
|
||||
}
|
||||
}
|
||||
|
||||
static void dndSendRpcRsp(SMgmtWrapper *pWrapper, SRpcMsg *pRsp) {
|
||||
void dndSendRpcRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) {
|
||||
if (pRsp->code == TSDB_CODE_APP_NOT_READY) {
|
||||
SMgmtWrapper *pDnodeWrapper = dndAcquireWrapper(pWrapper->pDnode, DNODE);
|
||||
if (pDnodeWrapper != NULL) {
|
||||
|
@ -362,16 +362,45 @@ static void dndSendRpcRsp(SMgmtWrapper *pWrapper, SRpcMsg *pRsp) {
|
|||
}
|
||||
}
|
||||
|
||||
void dndSendRsp(SMgmtWrapper *pWrapper, SRpcMsg *pRsp) {
|
||||
if (pWrapper->procType == PROC_CHILD) {
|
||||
int32_t code = -1;
|
||||
do {
|
||||
code = taosProcPutToParentQueue(pWrapper->pProc, pRsp, sizeof(SRpcMsg), pRsp->pCont, pRsp->contLen);
|
||||
if (code != 0) {
|
||||
taosMsleep(10);
|
||||
}
|
||||
} while (code != 0);
|
||||
} else {
|
||||
void dndSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) {
|
||||
if (pWrapper->procType != PROC_CHILD) {
|
||||
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) {
|
||||
if (pWrapper->procType != PROC_CHILD) {
|
||||
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;
|
||||
}
|
|
@ -52,6 +52,7 @@ static void mmInitOption(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) {
|
|||
msgCb.sendReqFp = dndSendReqToDnode;
|
||||
msgCb.sendMnodeReqFp = dndSendReqToMnode;
|
||||
msgCb.sendRspFp = dndSendRsp;
|
||||
msgCb.registerBrokenLinkArgFp = dndRegisterBrokenLinkArg;
|
||||
pOption->msgCb = msgCb;
|
||||
}
|
||||
|
|
@ -27,6 +27,7 @@ static void qmInitOption(SQnodeMgmt *pMgmt, SQnodeOpt *pOption) {
|
|||
msgCb.sendReqFp = dndSendReqToDnode;
|
||||
msgCb.sendMnodeReqFp = dndSendReqToMnode;
|
||||
msgCb.sendRspFp = dndSendRsp;
|
||||
msgCb.registerBrokenLinkArgFp = dndRegisterBrokenLinkArg;
|
||||
pOption->msgCb = msgCb;
|
||||
}
|
||||
|
|
@ -24,6 +24,7 @@ static void smInitOption(SSnodeMgmt *pMgmt, SSnodeOpt *pOption) {
|
|||
msgCb.sendReqFp = dndSendReqToDnode;
|
||||
msgCb.sendMnodeReqFp = dndSendReqToMnode;
|
||||
msgCb.sendRspFp = dndSendRsp;
|
||||
msgCb.registerBrokenLinkArgFp = dndRegisterBrokenLinkArg;
|
||||
pOption->msgCb = msgCb;
|
||||
}
|
||||
|
|
@ -137,6 +137,7 @@ static void *vmOpenVnodeFunc(void *param) {
|
|||
msgCb.sendReqFp = dndSendReqToDnode;
|
||||
msgCb.sendMnodeReqFp = dndSendReqToMnode;
|
||||
msgCb.sendRspFp = dndSendRsp;
|
||||
msgCb.registerBrokenLinkArgFp = dndRegisterBrokenLinkArg;
|
||||
SVnodeCfg cfg = {.msgCb = msgCb, .pTfs = pMgmt->pTfs, .vgId = pCfg->vgId, .dbId = pCfg->dbUid};
|
||||
SVnode *pImpl = vnodeOpen(pCfg->path, &cfg);
|
||||
if (pImpl == NULL) {
|
||||
|
@ -284,7 +285,7 @@ static int32_t vmInit(SMgmtWrapper *pWrapper) {
|
|||
tstrncpy(dCfg.dir, pDnode->dataDir, TSDB_FILENAME_LEN);
|
||||
dCfg.level = 0;
|
||||
dCfg.primary = 1;
|
||||
SDiskCfg *pDisks = pDnode->pDisks;
|
||||
SDiskCfg *pDisks = pDnode->disks;
|
||||
int32_t numOfDisks = pDnode->numOfDisks;
|
||||
if (numOfDisks <= 0 || pDisks == NULL) {
|
||||
pDisks = &dCfg;
|
|
@ -91,6 +91,7 @@ int32_t vmProcessCreateVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) {
|
|||
msgCb.sendReqFp = dndSendReqToDnode;
|
||||
msgCb.sendMnodeReqFp = dndSendReqToMnode;
|
||||
msgCb.sendRspFp = dndSendRsp;
|
||||
msgCb.registerBrokenLinkArgFp = dndRegisterBrokenLinkArg;
|
||||
|
||||
vnodeCfg.msgCb = msgCb;
|
||||
vnodeCfg.pTfs = pMgmt->pTfs;
|
||||
|
@ -244,44 +245,45 @@ int32_t vmProcessCompactVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) {
|
|||
|
||||
void vmInitMsgHandles(SMgmtWrapper *pWrapper) {
|
||||
// Requests handled by VNODE
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_SUBMIT, vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, vmProcessQueryMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, vmProcessQueryMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_UPDATE_TAG_VAL, vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_TABLE_META, vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_TABLES_META, vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CONSUME, vmProcessQueryMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_QUERY, vmProcessQueryMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CONNECT, vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_DISCONNECT, vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_RES_READY, vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB, vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB, vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_DROP_STB, vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_TABLE, vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TABLE, vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA, vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_SMA, vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA, vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES, vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES_FETCH, vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN, vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_REB, vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_CONSUME, vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY, vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_TASK_PIPE_EXEC, vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_TASK_MERGE_EXEC, vmProcessMergeMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_STREAM_TRIGGER, vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_SUBMIT, (NodeMsgFp)vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, (NodeMsgFp)vmProcessQueryMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, (NodeMsgFp)vmProcessQueryMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, (NodeMsgFp)vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, (NodeMsgFp)vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, (NodeMsgFp)vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_UPDATE_TAG_VAL, (NodeMsgFp)vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_TABLE_META, (NodeMsgFp)vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_TABLES_META, (NodeMsgFp)vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CONSUME, (NodeMsgFp)vmProcessQueryMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_QUERY, (NodeMsgFp)vmProcessQueryMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CONNECT, (NodeMsgFp)vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_DISCONNECT, (NodeMsgFp)vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, (NodeMsgFp)vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_RES_READY, (NodeMsgFp)vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, (NodeMsgFp)vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, (NodeMsgFp)vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, (NodeMsgFp)vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB, (NodeMsgFp)vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB, (NodeMsgFp)vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_DROP_STB, (NodeMsgFp)vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_TABLE, (NodeMsgFp)vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, (NodeMsgFp)vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TABLE, (NodeMsgFp)vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA, (NodeMsgFp)vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_SMA, (NodeMsgFp)vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA, (NodeMsgFp)vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES, (NodeMsgFp)vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES_FETCH, (NodeMsgFp)vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN, (NodeMsgFp)vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_REB, (NodeMsgFp)vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, (NodeMsgFp)vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_CONSUME, (NodeMsgFp)vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY, (NodeMsgFp)vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, (NodeMsgFp)vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_TASK_PIPE_EXEC, (NodeMsgFp)vmProcessFetchMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_TASK_MERGE_EXEC, (NodeMsgFp)vmProcessMergeMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_TASK_WRITE_EXEC, (NodeMsgFp)vmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_STREAM_TRIGGER, (NodeMsgFp)vmProcessFetchMsg, VND_VGID);
|
||||
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE, vmProcessMgmtMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE, vmProcessMgmtMsg, VND_VGID);
|
|
@ -76,7 +76,7 @@ static void vmProcessFetchQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) {
|
|||
SVnodeObj *pVnode = pInfo->ahandle;
|
||||
|
||||
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) {
|
||||
vmSendRsp(pVnode->pWrapper, pMsg, 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);
|
||||
|
||||
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) {
|
||||
vmSendRsp(pVnode->pWrapper, pMsg, 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;
|
||||
if (tWWorkerInit(pWPool) != 0) return -1;
|
||||
|
||||
SSingleWorkerCfg cfg = {
|
||||
.min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
|
||||
SSingleWorkerCfg cfg = {.min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
|
||||
if (tSingleWorkerInit(&pMgmt->mgmtWorker, &cfg) != 0) {
|
||||
dError("failed to start vnode-mgmt worker since %s", terrstr());
|
||||
return -1;
|
|
@ -731,10 +731,10 @@ typedef struct {
|
|||
int32_t vgNum;
|
||||
SRWLatch lock;
|
||||
int8_t status;
|
||||
int8_t sourceType;
|
||||
int8_t sinkType;
|
||||
// int32_t sqlLen;
|
||||
int32_t sinkVgId; // 0 for automatic
|
||||
int8_t createdBy; // STREAM_CREATED_BY__USER or SMA
|
||||
int32_t fixedSinkVgId; // 0 for shuffle
|
||||
int64_t smaId; // 0 for unused
|
||||
char* sql;
|
||||
char* logicalPlan;
|
||||
char* physicalPlan;
|
||||
|
|
|
@ -27,7 +27,7 @@ void mndCleanupScheduler(SMnode* pMnode);
|
|||
|
||||
int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscribeObj* pSub);
|
||||
|
||||
int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, int64_t smaId);
|
||||
int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ void mndReleaseStream(SMnode *pMnode, SStreamObj *pStream);
|
|||
SSdbRaw *mndStreamActionEncode(SStreamObj *pStream);
|
||||
SSdbRow *mndStreamActionDecode(SSdbRaw *pRaw);
|
||||
|
||||
int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, STrans *pTrans, int64_t smaId);
|
||||
int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, STrans *pTrans);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -26,8 +26,11 @@ int32_t tEncodeSStreamObj(SCoder *pEncoder, const SStreamObj *pObj) {
|
|||
if (tEncodeI64(pEncoder, pObj->dbUid) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, pObj->version) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pObj->status) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pObj->createdBy) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, pObj->fixedSinkVgId) < 0) return -1;
|
||||
if (tEncodeI64(pEncoder, pObj->smaId) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, pObj->sql) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, pObj->logicalPlan) < 0) return -1;
|
||||
/*if (tEncodeCStr(pEncoder, pObj->logicalPlan) < 0) return -1;*/
|
||||
if (tEncodeCStr(pEncoder, pObj->physicalPlan) < 0) return -1;
|
||||
// TODO encode tasks
|
||||
if (pObj->tasks) {
|
||||
|
@ -69,8 +72,11 @@ int32_t tDecodeSStreamObj(SCoder *pDecoder, SStreamObj *pObj) {
|
|||
if (tDecodeI64(pDecoder, &pObj->dbUid) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &pObj->version) < 0) return -1;
|
||||
if (tDecodeI8(pDecoder, &pObj->status) < 0) return -1;
|
||||
if (tDecodeI8(pDecoder, &pObj->createdBy) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &pObj->fixedSinkVgId) < 0) return -1;
|
||||
if (tDecodeI64(pDecoder, &pObj->smaId) < 0) return -1;
|
||||
if (tDecodeCStrAlloc(pDecoder, &pObj->sql) < 0) return -1;
|
||||
if (tDecodeCStrAlloc(pDecoder, &pObj->logicalPlan) < 0) return -1;
|
||||
/*if (tDecodeCStrAlloc(pDecoder, &pObj->logicalPlan) < 0) return -1;*/
|
||||
if (tDecodeCStrAlloc(pDecoder, &pObj->physicalPlan) < 0) return -1;
|
||||
pObj->tasks = NULL;
|
||||
int32_t sz;
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
#define SYSTABLE_SCH_DB_NAME_LEN ((TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
|
||||
|
||||
//!!!! 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 = "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 = "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 = "role", .bytes = 12 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "role_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 = "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 = "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 = "vgroups", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT},
|
||||
{.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 = "cachelast", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT},
|
||||
{.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 = "ntables", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||
{.name = "precision", .bytes = 2, .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 = "index_database", .bytes = 32, .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_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 = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
||||
{.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 = "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 = "dest_table", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.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 = "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 = "distributed_histogram", .bytes = 500, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.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 = "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 = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
||||
{.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 = "tables", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||
{.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},
|
||||
};
|
||||
|
||||
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_MODULES, modulesSchema, tListLen(modulesSchema)},
|
||||
{TSDB_INS_TABLE_QNODES, qnodesSchema, tListLen(qnodesSchema)},
|
||||
|
@ -251,5 +291,3 @@ void mndCleanupInfos(SMnode *pMnode) {
|
|||
pMnode->infosMeta = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -44,7 +44,8 @@ typedef struct {
|
|||
SQueryDesc *pQueries;
|
||||
} SConnObj;
|
||||
|
||||
static SConnObj *mndCreateConn(SMnode *pMnode, SRpcConnInfo *pInfo, int32_t pid, const char *app, int64_t startTime);
|
||||
static SConnObj *mndCreateConn(SMnode *pMnode, const char *user, uint32_t ip, uint16_t port, int32_t pid,
|
||||
const char *app, int64_t startTime);
|
||||
static void mndFreeConn(SConnObj *pConn);
|
||||
static SConnObj *mndAcquireConn(SMnode *pMnode, int32_t connId);
|
||||
static void mndReleaseConn(SMnode *pMnode, SConnObj *pConn);
|
||||
|
@ -94,7 +95,8 @@ void mndCleanupProfile(SMnode *pMnode) {
|
|||
}
|
||||
}
|
||||
|
||||
static SConnObj *mndCreateConn(SMnode *pMnode, SRpcConnInfo *pInfo, int32_t pid, const char *app, int64_t startTime) {
|
||||
static SConnObj *mndCreateConn(SMnode *pMnode, const char *user, uint32_t ip, uint16_t port, int32_t pid,
|
||||
const char *app, int64_t startTime) {
|
||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||
|
||||
int32_t connId = atomic_add_fetch_32(&pMgmt->connId, 1);
|
||||
|
@ -104,8 +106,8 @@ static SConnObj *mndCreateConn(SMnode *pMnode, SRpcConnInfo *pInfo, int32_t pid,
|
|||
SConnObj connObj = {.id = connId,
|
||||
.appStartTimeMs = startTime,
|
||||
.pid = pid,
|
||||
.ip = pInfo->clientIp,
|
||||
.port = pInfo->clientPort,
|
||||
.ip = ip,
|
||||
.port = port,
|
||||
.killed = 0,
|
||||
.loginTimeMs = taosGetTimestampMs(),
|
||||
.lastAccessTimeMs = 0,
|
||||
|
@ -114,17 +116,17 @@ static SConnObj *mndCreateConn(SMnode *pMnode, SRpcConnInfo *pInfo, int32_t pid,
|
|||
.pQueries = NULL};
|
||||
|
||||
connObj.lastAccessTimeMs = connObj.loginTimeMs;
|
||||
tstrncpy(connObj.user, pInfo->user, TSDB_USER_LEN);
|
||||
tstrncpy(connObj.user, user, TSDB_USER_LEN);
|
||||
tstrncpy(connObj.app, app, TSDB_APP_NAME_LEN);
|
||||
|
||||
int32_t keepTime = tsShellActivityTimer * 3;
|
||||
SConnObj *pConn = taosCachePut(pMgmt->cache, &connId, sizeof(int32_t), &connObj, sizeof(connObj), keepTime * 1000);
|
||||
if (pConn == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("conn:%d, failed to put into cache since %s, user:%s", connId, pInfo->user, terrstr());
|
||||
mError("conn:%d, failed to put into cache since %s, user:%s", connId, user, terrstr());
|
||||
return NULL;
|
||||
} else {
|
||||
mTrace("conn:%d, is created, data:%p user:%s", pConn->id, pConn, pInfo->user);
|
||||
mTrace("conn:%d, is created, data:%p user:%s", pConn->id, pConn, user);
|
||||
return pConn;
|
||||
}
|
||||
}
|
||||
|
@ -184,20 +186,14 @@ static int32_t mndProcessConnectReq(SNodeMsg *pReq) {
|
|||
SConnObj *pConn = NULL;
|
||||
int32_t code = -1;
|
||||
SConnectReq connReq = {0};
|
||||
char ip[30] = {0};
|
||||
|
||||
if (tDeserializeSConnectReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &connReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto CONN_OVER;
|
||||
}
|
||||
|
||||
SRpcConnInfo info = {0};
|
||||
if (rpcGetConnInfo(pReq->rpcMsg.handle, &info) != 0) {
|
||||
mError("user:%s, failed to login while get connection info since %s", pReq->user, terrstr());
|
||||
goto CONN_OVER;
|
||||
}
|
||||
|
||||
char ip[30];
|
||||
taosIp2String(info.clientIp, ip);
|
||||
taosIp2String(pReq->clientIp, ip);
|
||||
|
||||
pUser = mndAcquireUser(pMnode, pReq->user);
|
||||
if (pUser == NULL) {
|
||||
|
@ -216,7 +212,8 @@ static int32_t mndProcessConnectReq(SNodeMsg *pReq) {
|
|||
}
|
||||
}
|
||||
|
||||
pConn = mndCreateConn(pMnode, &info, connReq.pid, connReq.app, connReq.startTime);
|
||||
pConn =
|
||||
mndCreateConn(pMnode, pReq->user, pReq->clientIp, pReq->clientPort, connReq.pid, connReq.app, connReq.startTime);
|
||||
if (pConn == NULL) {
|
||||
mError("user:%s, failed to login from %s while create connection since %s", pReq->user, ip, terrstr());
|
||||
goto CONN_OVER;
|
||||
|
@ -241,7 +238,7 @@ static int32_t mndProcessConnectReq(SNodeMsg *pReq) {
|
|||
pReq->rspLen = contLen;
|
||||
pReq->pRsp = pRsp;
|
||||
|
||||
mDebug("user:%s, login from %s, conn:%d, app:%s", info.user, ip, pConn->id, connReq.app);
|
||||
mDebug("user:%s, login from %s, conn:%d, app:%s", pReq->user, ip, pConn->id, connReq.app);
|
||||
|
||||
code = 0;
|
||||
|
||||
|
|
|
@ -14,15 +14,15 @@
|
|||
*/
|
||||
|
||||
#include "mndQuery.h"
|
||||
#include "mndMnode.h"
|
||||
#include "executor.h"
|
||||
#include "mndMnode.h"
|
||||
#include "qworker.h"
|
||||
|
||||
int32_t mndProcessQueryMsg(SNodeMsg *pReq) {
|
||||
mTrace("message in query queue is processing");
|
||||
SMnode *pMnode = pReq->pNode;
|
||||
SReadHandle handle = {0};
|
||||
|
||||
mTrace("msg:%p, in query queue is processing", pReq);
|
||||
switch (pReq->rpcMsg.msgType) {
|
||||
case TDMT_VND_QUERY:
|
||||
return qWorkerProcessQueryMsg(&handle, pMnode->pQuery, &pReq->rpcMsg);
|
||||
|
@ -35,8 +35,8 @@ int32_t mndProcessQueryMsg(SNodeMsg *pReq) {
|
|||
}
|
||||
|
||||
int32_t mndProcessFetchMsg(SNodeMsg *pReq) {
|
||||
mTrace("message in fetch queue is processing");
|
||||
SMnode *pMnode = pReq->pNode;
|
||||
mTrace("msg:%p, in fetch queue is processing", pReq);
|
||||
|
||||
switch (pReq->rpcMsg.msgType) {
|
||||
case TDMT_VND_FETCH:
|
||||
|
@ -52,9 +52,9 @@ int32_t mndProcessFetchMsg(SNodeMsg *pReq) {
|
|||
}
|
||||
|
||||
int32_t mndInitQuery(SMnode *pMnode) {
|
||||
int32_t code = qWorkerInit(NODE_TYPE_MNODE, MND_VGID, NULL, (void **)&pMnode->pQuery, &pMnode->msgCb);
|
||||
if (code) {
|
||||
return code;
|
||||
if (qWorkerInit(NODE_TYPE_MNODE, MND_VGID, NULL, (void **)&pMnode->pQuery, &pMnode->msgCb) != 0) {
|
||||
mError("failed to init qworker in mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
mndSetMsgHandle(pMnode, TDMT_VND_QUERY, mndProcessQueryMsg);
|
||||
|
@ -67,4 +67,3 @@ int32_t mndInitQuery(SMnode *pMnode) {
|
|||
}
|
||||
|
||||
void mndCleanupQuery(SMnode *pMnode) { qWorkerDestroy((void **)&pMnode->pQuery); }
|
||||
|
||||
|
|
|
@ -119,7 +119,92 @@ SVgObj* mndSchedFetchOneVg(SMnode* pMnode, int64_t dbUid) {
|
|||
return pVgroup;
|
||||
}
|
||||
|
||||
int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, int64_t smaId) {
|
||||
int32_t mndAddShuffledSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
||||
SSdb* pSdb = pMnode->pSdb;
|
||||
void* pIter = NULL;
|
||||
SArray* tasks = taosArrayGetP(pStream->tasks, 0);
|
||||
|
||||
ASSERT(taosArrayGetSize(pStream->tasks) == 1);
|
||||
|
||||
while (1) {
|
||||
SVgObj* pVgroup;
|
||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void**)&pVgroup);
|
||||
if (pIter == NULL) break;
|
||||
if (pVgroup->dbUid != pStream->dbUid) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
continue;
|
||||
}
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid);
|
||||
if (pTask == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
taosArrayPush(tasks, &pTask);
|
||||
|
||||
pTask->nodeId = pVgroup->vgId;
|
||||
pTask->epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
|
||||
// source
|
||||
pTask->sourceType = TASK_SOURCE__MERGE;
|
||||
|
||||
// exec
|
||||
pTask->execType = TASK_EXEC__NONE;
|
||||
|
||||
// sink
|
||||
if (pStream->createdBy == STREAM_CREATED_BY__SMA) {
|
||||
pTask->sinkType = TASK_SINK__SMA;
|
||||
pTask->smaSink.smaId = pStream->smaId;
|
||||
} else {
|
||||
pTask->sinkType = TASK_SINK__TABLE;
|
||||
}
|
||||
|
||||
// dispatch
|
||||
pTask->dispatchType = TASK_DISPATCH__NONE;
|
||||
|
||||
mndPersistTaskDeployReq(pTrans, pTask, &pTask->epSet, TDMT_VND_TASK_DEPLOY, pVgroup->vgId);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndAddFixedSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
||||
ASSERT(pStream->fixedSinkVgId != 0);
|
||||
SArray* tasks = taosArrayGetP(pStream->tasks, 0);
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid);
|
||||
if (pTask == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
taosArrayPush(tasks, &pTask);
|
||||
|
||||
pTask->nodeId = pStream->fixedSinkVgId;
|
||||
SVgObj* pVgroup = mndAcquireVgroup(pMnode, pStream->fixedSinkVgId);
|
||||
if (pVgroup == NULL) {
|
||||
return -1;
|
||||
}
|
||||
pTask->epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
// source
|
||||
pTask->sourceType = TASK_SOURCE__MERGE;
|
||||
|
||||
// exec
|
||||
pTask->execType = TASK_EXEC__NONE;
|
||||
|
||||
// sink
|
||||
if (pStream->createdBy == STREAM_CREATED_BY__SMA) {
|
||||
pTask->sinkType = TASK_SINK__SMA;
|
||||
pTask->smaSink.smaId = pStream->smaId;
|
||||
} else {
|
||||
pTask->sinkType = TASK_SINK__TABLE;
|
||||
}
|
||||
//
|
||||
// dispatch
|
||||
pTask->dispatchType = TASK_DISPATCH__NONE;
|
||||
|
||||
mndPersistTaskDeployReq(pTrans, pTask, &pTask->epSet, TDMT_VND_TASK_DEPLOY, pVgroup->vgId);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
||||
SSdb* pSdb = pMnode->pSdb;
|
||||
SQueryPlan* pPlan = qStringToQueryPlan(pStream->physicalPlan);
|
||||
if (pPlan == NULL) {
|
||||
|
@ -132,6 +217,19 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, i
|
|||
ASSERT(totLevel <= 2);
|
||||
pStream->tasks = taosArrayInit(totLevel, sizeof(void*));
|
||||
|
||||
bool hasExtraSink = false;
|
||||
if (totLevel == 2) {
|
||||
SArray* taskOneLevel = taosArrayInit(0, sizeof(void*));
|
||||
taosArrayPush(pStream->tasks, &taskOneLevel);
|
||||
// add extra sink
|
||||
hasExtraSink = true;
|
||||
if (pStream->fixedSinkVgId == 0) {
|
||||
mndAddShuffledSinkToStream(pMnode, pTrans, pStream);
|
||||
} else {
|
||||
mndAddFixedSinkToStream(pMnode, pTrans, pStream);
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t level = 0; level < totLevel; level++) {
|
||||
SArray* taskOneLevel = taosArrayInit(0, sizeof(void*));
|
||||
SNodeListNode* inner = nodesListGetNode(pPlan->pSubplans, level);
|
||||
|
@ -164,9 +262,15 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, i
|
|||
// only for inplace
|
||||
pTask->sinkType = TASK_SINK__SHOW;
|
||||
pTask->showSink.reserved = 0;
|
||||
if (smaId != -1) {
|
||||
if (!hasExtraSink) {
|
||||
#if 1
|
||||
if (pStream->createdBy == STREAM_CREATED_BY__SMA) {
|
||||
pTask->sinkType = TASK_SINK__SMA;
|
||||
pTask->smaSink.smaId = smaId;
|
||||
pTask->smaSink.smaId = pStream->smaId;
|
||||
} else {
|
||||
pTask->sinkType = TASK_SINK__TABLE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
pTask->sinkType = TASK_SINK__NONE;
|
||||
|
@ -175,17 +279,15 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, i
|
|||
// dispatch part
|
||||
if (level == 0) {
|
||||
pTask->dispatchType = TASK_DISPATCH__NONE;
|
||||
// if inplace sink, no dispatcher
|
||||
// if fixed ep, add fixed ep dispatcher
|
||||
// if shuffle, add shuffle dispatcher
|
||||
} else {
|
||||
// add fixed ep dispatcher
|
||||
int32_t lastLevel = level - 1;
|
||||
ASSERT(lastLevel == 0);
|
||||
if (hasExtraSink) lastLevel++;
|
||||
SArray* pArray = taosArrayGetP(pStream->tasks, lastLevel);
|
||||
// one merge only
|
||||
ASSERT(taosArrayGetSize(pArray) == 1);
|
||||
SStreamTask* lastLevelTask = taosArrayGetP(pArray, lastLevel);
|
||||
SStreamTask* lastLevelTask = taosArrayGetP(pArray, 0);
|
||||
pTask->dispatchMsgType = TDMT_VND_TASK_MERGE_EXEC;
|
||||
pTask->dispatchType = TASK_DISPATCH__FIXED;
|
||||
|
||||
|
@ -222,9 +324,15 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, i
|
|||
/*pTask->sinkType = TASK_SINK__NONE;*/
|
||||
|
||||
// dispatch part
|
||||
pTask->dispatchType = TASK_DISPATCH__NONE;
|
||||
#if 0
|
||||
ASSERT(hasExtraSink);
|
||||
/*pTask->dispatchType = TASK_DISPATCH__NONE;*/
|
||||
#if 1
|
||||
|
||||
if (hasExtraSink) {
|
||||
// add dispatcher
|
||||
if (pStream->fixedSinkVgId == 0) {
|
||||
pTask->dispatchType = TASK_DISPATCH__SHUFFLE;
|
||||
|
||||
pTask->dispatchMsgType = TDMT_VND_TASK_WRITE_EXEC;
|
||||
SDbObj* pDb = mndAcquireDb(pMnode, pStream->db);
|
||||
ASSERT(pDb);
|
||||
|
@ -234,6 +342,37 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, i
|
|||
return -1;
|
||||
}
|
||||
sdbRelease(pSdb, pDb);
|
||||
|
||||
// put taskId to useDbRsp
|
||||
// TODO: optimize
|
||||
SArray* pVgs = pTask->shuffleDispatcher.dbInfo.pVgroupInfos;
|
||||
int32_t sz = taosArrayGetSize(pVgs);
|
||||
SArray* sinkLv = taosArrayGetP(pStream->tasks, 0);
|
||||
int32_t sinkLvSize = taosArrayGetSize(sinkLv);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SVgroupInfo* pVgInfo = taosArrayGet(pVgs, i);
|
||||
for (int32_t j = 0; j < sinkLvSize; j++) {
|
||||
SStreamTask* pLastLevelTask = taosArrayGetP(sinkLv, j);
|
||||
/*printf("vgid %d node id %d\n", pVgInfo->vgId, pTask->nodeId);*/
|
||||
if (pLastLevelTask->nodeId == pVgInfo->vgId) {
|
||||
pVgInfo->taskId = pLastLevelTask->taskId;
|
||||
/*printf("taskid %d set to %d\n", pVgInfo->taskId, pTask->taskId);*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pTask->dispatchType = TASK_DISPATCH__FIXED;
|
||||
pTask->dispatchMsgType = TDMT_VND_TASK_WRITE_EXEC;
|
||||
SArray* pArray = taosArrayGetP(pStream->tasks, 0);
|
||||
// one sink only
|
||||
ASSERT(taosArrayGetSize(pArray) == 1);
|
||||
SStreamTask* lastLevelTask = taosArrayGetP(pArray, 0);
|
||||
pTask->fixedEpDispatcher.taskId = lastLevelTask->taskId;
|
||||
pTask->fixedEpDispatcher.nodeId = lastLevelTask->nodeId;
|
||||
pTask->fixedEpDispatcher.epSet = lastLevelTask->epSet;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// exec part
|
||||
|
|
|
@ -415,6 +415,10 @@ static int32_t mndCreateSma(SMnode *pMnode, SNodeMsg *pReq, SMCreateSmaReq *pCre
|
|||
streamObj.dbUid = pDb->uid;
|
||||
streamObj.version = 1;
|
||||
streamObj.sql = pCreate->sql;
|
||||
streamObj.createdBy = STREAM_CREATED_BY__SMA;
|
||||
// TODO
|
||||
streamObj.fixedSinkVgId = 0;
|
||||
streamObj.smaId = smaObj.uid;
|
||||
/*streamObj.physicalPlan = "";*/
|
||||
streamObj.logicalPlan = "not implemented";
|
||||
|
||||
|
@ -428,7 +432,7 @@ static int32_t mndCreateSma(SMnode *pMnode, SNodeMsg *pReq, SMCreateSmaReq *pCre
|
|||
if (mndSetCreateSmaRedoLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER;
|
||||
if (mndSetCreateSmaCommitLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER;
|
||||
if (mndSetCreateSmaRedoActions(pMnode, pTrans, pDb, &smaObj) != 0) goto _OVER;
|
||||
if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, pTrans, smaObj.uid) != 0) goto _OVER;
|
||||
if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, pTrans) != 0) goto _OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
code = 0;
|
||||
|
|
|
@ -246,7 +246,7 @@ static int32_t mndStreamGetPlanString(const char *ast, char **pStr) {
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, STrans *pTrans, int64_t smaId) {
|
||||
int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, STrans *pTrans) {
|
||||
SNode *pAst = NULL;
|
||||
|
||||
if (nodesStringToNode(ast, &pAst) < 0) {
|
||||
|
@ -271,7 +271,7 @@ int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (mndScheduleStream(pMnode, pTrans, pStream, smaId) < 0) {
|
||||
if (mndScheduleStream(pMnode, pTrans, pStream) < 0) {
|
||||
mError("stream:%ld, schedule stream since %s", pStream->uid, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
@ -300,6 +300,10 @@ static int32_t mndCreateStream(SMnode *pMnode, SNodeMsg *pReq, SCMCreateStreamRe
|
|||
streamObj.dbUid = pDb->uid;
|
||||
streamObj.version = 1;
|
||||
streamObj.sql = pCreate->sql;
|
||||
streamObj.createdBy = STREAM_CREATED_BY__USER;
|
||||
// TODO
|
||||
streamObj.fixedSinkVgId = 0;
|
||||
streamObj.smaId = 0;
|
||||
/*streamObj.physicalPlan = "";*/
|
||||
streamObj.logicalPlan = "not implemented";
|
||||
|
||||
|
@ -310,7 +314,7 @@ static int32_t mndCreateStream(SMnode *pMnode, SNodeMsg *pReq, SCMCreateStreamRe
|
|||
}
|
||||
mDebug("trans:%d, used to create stream:%s", pTrans->id, pCreate->name);
|
||||
|
||||
if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, pTrans, -1) != 0) {
|
||||
if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, pTrans) != 0) {
|
||||
mError("trans:%d, failed to add stream since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
|
|
|
@ -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 mndInitUnassignedVg(SMnode *pMnode, const SMqTopicObj *pTopic, SMqSubscribeObj *pSub);
|
||||
|
||||
int32_t mndInitSubscribe(SMnode *pMnode) {
|
||||
SSdbTable table = {.sdbType = SDB_SUBSCRIBE,
|
||||
.keyType = SDB_KEY_BINARY,
|
||||
|
@ -98,14 +96,6 @@ static SMqSubscribeObj *mndCreateSubscription(SMnode *pMnode, const SMqTopicObj
|
|||
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
|
||||
return pSub;
|
||||
}
|
||||
|
@ -210,45 +200,6 @@ static int32_t mndPersistCancelConnReq(SMnode *pMnode, STrans *pTrans, const SMq
|
|||
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) {
|
||||
SMnode *pMnode = pMsg->pNode;
|
||||
SMqCMGetSubEpReq *pReq = (SMqCMGetSubEpReq *)pMsg->rpcMsg.pCont;
|
||||
|
@ -574,251 +525,6 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) {
|
|||
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,
|
||||
const SMqConsumerEp *pConsumerEp) {
|
||||
ASSERT(pConsumerEp->oldConsumerId == -1);
|
||||
|
|
|
@ -67,7 +67,9 @@ SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) {
|
|||
|
||||
int32_t logicalPlanLen = strlen(pTopic->logicalPlan) + 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);
|
||||
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_BINARY(pRaw, dataPos, pTopic->physicalPlan, physicalPlanLen, TOPIC_ENCODE_OVER);
|
||||
|
||||
int32_t swLen = taosEncodeSSchemaWrapper(NULL, &pTopic->schema);
|
||||
void *swBuf = taosMemoryMalloc(swLen);
|
||||
if (swBuf == NULL) {
|
||||
goto TOPIC_ENCODE_OVER;
|
||||
|
|
|
@ -54,7 +54,7 @@ static bool mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans);
|
|||
static bool mndTransPerfromFinishedStage(SMnode *pMnode, STrans *pTrans);
|
||||
|
||||
static void mndTransExecute(SMnode *pMnode, STrans *pTrans);
|
||||
static void mndTransSendRpcRsp(STrans *pTrans);
|
||||
static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans);
|
||||
static int32_t mndProcessTransReq(SNodeMsg *pReq);
|
||||
static int32_t mndProcessKillTransReq(SNodeMsg *pReq);
|
||||
|
||||
|
@ -737,7 +737,7 @@ static int32_t mndTransRollback(SMnode *pMnode, STrans *pTrans) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void mndTransSendRpcRsp(STrans *pTrans) {
|
||||
static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) {
|
||||
bool sendRsp = false;
|
||||
|
||||
if (pTrans->stage == TRN_STAGE_FINISHED) {
|
||||
|
@ -771,7 +771,7 @@ static void mndTransSendRpcRsp(STrans *pTrans) {
|
|||
.ahandle = pTrans->rpcAHandle,
|
||||
.pCont = rpcCont,
|
||||
.contLen = pTrans->rpcRspLen};
|
||||
rpcSendResponse(&rspMsg);
|
||||
tmsgSendRsp(&rspMsg);
|
||||
pTrans->rpcHandle = NULL;
|
||||
pTrans->rpcRsp = NULL;
|
||||
pTrans->rpcRspLen = 0;
|
||||
|
@ -898,7 +898,7 @@ static int32_t mndTransSendActionMsg(SMnode *pMnode, STrans *pTrans, SArray *pAr
|
|||
pAction->msgReceived = 0;
|
||||
pAction->errCode = 0;
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
@ -938,7 +938,7 @@ static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pA
|
|||
return errCode;
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
@ -1158,7 +1158,7 @@ static void mndTransExecute(SMnode *pMnode, STrans *pTrans) {
|
|||
}
|
||||
}
|
||||
|
||||
mndTransSendRpcRsp(pTrans);
|
||||
mndTransSendRpcRsp(pMnode, pTrans);
|
||||
}
|
||||
|
||||
static int32_t mndProcessTransReq(SNodeMsg *pReq) {
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue