Merge branch '3.0' into cpwu/3.0
This commit is contained in:
commit
ad85c93b0b
|
@ -121,7 +121,7 @@ def pre_test_win(){
|
|||
set
|
||||
date /t
|
||||
time /t
|
||||
rd /s /Q C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal\\debug
|
||||
rd /s /Q C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal\\debug || exit 0
|
||||
'''
|
||||
bat '''
|
||||
cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDinternal
|
||||
|
|
|
@ -46,11 +46,17 @@ ENDIF ()
|
|||
|
||||
IF (TD_WINDOWS)
|
||||
MESSAGE("${Yellow} set compiler flag for Windows! ${ColourReset}")
|
||||
SET(COMMON_FLAGS "/W3 /D_WIN32")
|
||||
SET(COMMON_FLAGS "/w /D_WIN32")
|
||||
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
|
||||
# IF (MSVC AND (MSVC_VERSION GREATER_EQUAL 1900))
|
||||
# SET(COMMON_FLAGS "${COMMON_FLAGS} /Wv:18")
|
||||
# ENDIF ()
|
||||
IF (CMAKE_DEPFILE_FLAGS_C)
|
||||
SET(CMAKE_DEPFILE_FLAGS_C "")
|
||||
ENDIF ()
|
||||
IF (CMAKE_DEPFILE_FLAGS_CXX)
|
||||
SET(CMAKE_DEPFILE_FLAGS_CXX "")
|
||||
ENDIF ()
|
||||
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAGS}")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_FLAGS}")
|
||||
|
|
|
@ -46,6 +46,18 @@ IF(${TD_WINDOWS})
|
|||
ON
|
||||
)
|
||||
|
||||
option(
|
||||
BUILD_TEST
|
||||
"If build unit tests using googletest"
|
||||
OFF
|
||||
)
|
||||
ELSE ()
|
||||
|
||||
option(
|
||||
BUILD_TEST
|
||||
"If build unit tests using googletest"
|
||||
ON
|
||||
)
|
||||
ENDIF ()
|
||||
|
||||
option(
|
||||
|
@ -54,12 +66,6 @@ option(
|
|||
OFF
|
||||
)
|
||||
|
||||
option(
|
||||
BUILD_TEST
|
||||
"If build unit tests using googletest"
|
||||
ON
|
||||
)
|
||||
|
||||
option(
|
||||
BUILD_WITH_LEVELDB
|
||||
"If build with leveldb"
|
||||
|
|
|
@ -2589,18 +2589,6 @@ static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
|
|||
taosArrayDestroyEx(pRsp->topics, (void (*)(void*))tDeleteSMqSubTopicEp);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
int64_t streamId;
|
||||
int32_t taskId;
|
||||
int32_t sourceVg;
|
||||
int64_t sourceVer;
|
||||
SArray* data; // SArray<SSDataBlock>
|
||||
} SStreamDispatchReq;
|
||||
|
||||
typedef struct {
|
||||
int8_t inputStatus;
|
||||
} SStreamDispatchRsp;
|
||||
|
||||
#define TD_AUTO_CREATE_TABLE 0x1
|
||||
typedef struct {
|
||||
int64_t suid;
|
||||
|
|
|
@ -200,6 +200,10 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_VND_TASK_WRITE_EXEC, "vnode-task-write-exec", SStreamTaskExecReq, SStreamTaskExecRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_STREAM_TRIGGER, "vnode-stream-trigger", NULL, NULL)
|
||||
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_TASK_RUN, "vnode-stream-task-run", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_TASK_DISPATCH, "vnode-stream-task-dispatch", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_TASK_RECOVER, "vnode-stream-task-recover", NULL, NULL)
|
||||
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_CREATE_SMA, "vnode-create-sma", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_CANCEL_SMA, "vnode-cancel-sma", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_DROP_SMA, "vnode-drop-sma", NULL, NULL)
|
||||
|
|
|
@ -236,6 +236,7 @@ typedef struct SSelectStmt {
|
|||
bool isTimeOrderQuery;
|
||||
bool hasAggFuncs;
|
||||
bool hasRepeatScanFuncs;
|
||||
bool hasNonstdSQLFunc;
|
||||
} SSelectStmt;
|
||||
|
||||
typedef enum ESetOperatorType { SET_OP_TYPE_UNION_ALL = 1, SET_OP_TYPE_UNION } ESetOperatorType;
|
||||
|
@ -350,9 +351,6 @@ bool nodesIsComparisonOp(const SOperatorNode* pOp);
|
|||
bool nodesIsJsonOp(const SOperatorNode* pOp);
|
||||
bool nodesIsRegularOp(const SOperatorNode* pOp);
|
||||
|
||||
bool nodesIsTimeorderQuery(const SNode* pQuery);
|
||||
bool nodesIsTimelineQuery(const SNode* pQuery);
|
||||
|
||||
void* nodesGetValueFromNode(SValueNode* pNode);
|
||||
int32_t nodesSetValueNodeValue(SValueNode* pNode, void* value);
|
||||
char* nodesGetStrValueFromNode(SValueNode* pNode);
|
||||
|
|
|
@ -182,8 +182,10 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t
|
|||
#define SET_META_TYPE_TABLE(t) (t) = META_TYPE_TABLE
|
||||
#define SET_META_TYPE_BOTH_TABLE(t) (t) = META_TYPE_BOTH_TABLE
|
||||
|
||||
#define NEED_CLIENT_RM_TBLMETA_ERROR(_code) \
|
||||
((_code) == TSDB_CODE_PAR_TABLE_NOT_EXIST || (_code) == TSDB_CODE_VND_TB_NOT_EXIST)
|
||||
#define NEED_CLIENT_RM_TBLMETA_ERROR(_code) \
|
||||
((_code) == TSDB_CODE_PAR_TABLE_NOT_EXIST || (_code) == TSDB_CODE_VND_TB_NOT_EXIST || \
|
||||
(_code) == TSDB_CODE_PAR_INVALID_COLUMNS_NUM || (_code) == TSDB_CODE_PAR_INVALID_COLUMN || \
|
||||
(_code) == TSDB_CODE_PAR_TAGS_NOT_MATCHED)
|
||||
#define NEED_CLIENT_REFRESH_VG_ERROR(_code) \
|
||||
((_code) == TSDB_CODE_VND_HASH_MISMATCH || (_code) == TSDB_CODE_VND_INVALID_VGROUP_ID)
|
||||
#define NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code) ((_code) == TSDB_CODE_TDB_TABLE_RECREATED)
|
||||
|
@ -194,7 +196,7 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t
|
|||
#define NEED_SCHEDULER_RETRY_ERROR(_code) \
|
||||
((_code) == TSDB_CODE_RPC_REDIRECT || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL)
|
||||
|
||||
#define REQUEST_MAX_TRY_TIMES 5
|
||||
#define REQUEST_MAX_TRY_TIMES 1
|
||||
|
||||
#define qFatal(...) \
|
||||
do { \
|
||||
|
|
|
@ -107,6 +107,7 @@ static FORCE_INLINE void streamDataSubmitRefDec(SStreamDataSubmit* pDataSubmit)
|
|||
if (ref == 0) {
|
||||
taosMemoryFree(pDataSubmit->data);
|
||||
taosMemoryFree(pDataSubmit->dataRef);
|
||||
// taosFreeQitem(pDataSubmit);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -279,6 +280,42 @@ typedef struct {
|
|||
SArray* res; // SArray<SSDataBlock>
|
||||
} SStreamSinkReq;
|
||||
|
||||
typedef struct {
|
||||
SMsgHead head;
|
||||
int64_t streamId;
|
||||
int32_t taskId;
|
||||
} SStreamTaskRunReq;
|
||||
|
||||
typedef struct {
|
||||
int64_t streamId;
|
||||
int32_t taskId;
|
||||
int32_t sourceTaskId;
|
||||
int32_t sourceVg;
|
||||
#if 0
|
||||
int64_t sourceVer;
|
||||
#endif
|
||||
SArray* data; // SArray<SSDataBlock>
|
||||
} SStreamDispatchReq;
|
||||
|
||||
typedef struct {
|
||||
int64_t streamId;
|
||||
int32_t taskId;
|
||||
int8_t inputStatus;
|
||||
} SStreamDispatchRsp;
|
||||
|
||||
typedef struct {
|
||||
int64_t streamId;
|
||||
int32_t taskId;
|
||||
int32_t sourceTaskId;
|
||||
int32_t sourceVg;
|
||||
} SStreamTaskRecoverReq;
|
||||
|
||||
typedef struct {
|
||||
int64_t streamId;
|
||||
int32_t taskId;
|
||||
int8_t inputStatus;
|
||||
} SStreamTaskRecoverRsp;
|
||||
|
||||
int32_t streamEnqueueDataSubmit(SStreamTask* pTask, SStreamDataSubmit* input);
|
||||
int32_t streamEnqueueDataBlk(SStreamTask* pTask, SStreamDataBlock* input);
|
||||
int32_t streamDequeueOutput(SStreamTask* pTask, void** output);
|
||||
|
@ -289,6 +326,12 @@ int32_t streamTaskRun(SStreamTask* pTask);
|
|||
|
||||
int32_t streamTaskHandleInput(SStreamTask* pTask, void* data);
|
||||
|
||||
int32_t streamTaskProcessRunReq(SStreamTask* pTask, SMsgCb* pMsgCb);
|
||||
int32_t streamTaskProcessDispatchReq(SStreamTask* pTask, SMsgCb* pMsgCb, SStreamDispatchReq* pReq, SRpcMsg* pMsg);
|
||||
int32_t streamTaskProcessDispatchRsp(SStreamTask* pTask, SMsgCb* pMsgCb, SStreamDispatchRsp* pRsp);
|
||||
int32_t streamTaskProcessRecoverReq(SStreamTask* pTask, SMsgCb* pMsgCb, SStreamTaskRecoverReq* pReq, SRpcMsg* pMsg);
|
||||
int32_t streamTaskProcessRecoverRsp(SStreamTask* pTask, SStreamTaskRecoverRsp* pRsp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -20,20 +20,23 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
//#include <tdatablock.h>
|
||||
#include "cJSON.h"
|
||||
#include "tdef.h"
|
||||
//#include "taosdef.h"
|
||||
//#include "trpc.h"
|
||||
//#include "wal.h"
|
||||
#include "tmsgcb.h"
|
||||
|
||||
#define SYNC_INDEX_BEGIN 0
|
||||
#define SYNC_INDEX_INVALID -1
|
||||
|
||||
typedef uint64_t SyncNodeId;
|
||||
typedef int32_t SyncGroupId;
|
||||
typedef int64_t SyncIndex;
|
||||
typedef uint64_t SyncTerm;
|
||||
|
||||
typedef struct SSyncNode SSyncNode;
|
||||
typedef struct SSyncBuffer SSyncBuffer;
|
||||
typedef struct SWal SWal;
|
||||
typedef struct SSyncRaftEntry SSyncRaftEntry;
|
||||
|
||||
typedef enum {
|
||||
TAOS_SYNC_STATE_FOLLOWER = 100,
|
||||
TAOS_SYNC_STATE_CANDIDATE = 101,
|
||||
|
@ -41,6 +44,17 @@ typedef enum {
|
|||
TAOS_SYNC_STATE_ERROR = 103,
|
||||
} ESyncState;
|
||||
|
||||
typedef enum {
|
||||
TAOS_SYNC_PROPOSE_SUCCESS = 0,
|
||||
TAOS_SYNC_PROPOSE_NOT_LEADER = 1,
|
||||
TAOS_SYNC_PROPOSE_OTHER_ERROR = 2,
|
||||
} ESyncProposeCode;
|
||||
|
||||
typedef enum {
|
||||
TAOS_SYNC_FSM_CB_SUCCESS = 0,
|
||||
TAOS_SYNC_FSM_CB_OTHER_ERROR = 1,
|
||||
} ESyncFsmCbCode;
|
||||
|
||||
typedef struct SNodeInfo {
|
||||
uint16_t nodePort;
|
||||
char nodeFqdn[TSDB_FQDN_LEN];
|
||||
|
@ -58,11 +72,6 @@ typedef struct SSnapshot {
|
|||
SyncTerm lastApplyTerm;
|
||||
} SSnapshot;
|
||||
|
||||
typedef enum {
|
||||
TAOS_SYNC_FSM_CB_SUCCESS = 0,
|
||||
TAOS_SYNC_FSM_CB_OTHER_ERROR,
|
||||
} ESyncFsmCbCode;
|
||||
|
||||
typedef struct SFsmCbMeta {
|
||||
SyncIndex index;
|
||||
bool isWeak;
|
||||
|
@ -71,27 +80,15 @@ typedef struct SFsmCbMeta {
|
|||
uint64_t seqNum;
|
||||
} SFsmCbMeta;
|
||||
|
||||
struct SRpcMsg;
|
||||
typedef struct SRpcMsg SRpcMsg;
|
||||
|
||||
typedef struct SSyncFSM {
|
||||
void* data;
|
||||
|
||||
void (*FpCommitCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta);
|
||||
void (*FpPreCommitCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta);
|
||||
void (*FpRollBackCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta);
|
||||
|
||||
int32_t (*FpGetSnapshot)(struct SSyncFSM* pFsm, SSnapshot* pSnapshot);
|
||||
int32_t (*FpRestoreSnapshot)(struct SSyncFSM* pFsm, const SSnapshot* snapshot);
|
||||
|
||||
} SSyncFSM;
|
||||
|
||||
struct SSyncRaftEntry;
|
||||
typedef struct SSyncRaftEntry SSyncRaftEntry;
|
||||
|
||||
#define SYNC_INDEX_BEGIN 0
|
||||
#define SYNC_INDEX_INVALID -1
|
||||
|
||||
// abstract definition of log store in raft
|
||||
// SWal implements it
|
||||
typedef struct SSyncLogStore {
|
||||
|
@ -120,11 +117,6 @@ typedef struct SSyncLogStore {
|
|||
|
||||
} SSyncLogStore;
|
||||
|
||||
struct SWal;
|
||||
typedef struct SWal SWal;
|
||||
|
||||
struct SEpSet;
|
||||
typedef struct SEpSet SEpSet;
|
||||
|
||||
typedef struct SSyncInfo {
|
||||
SyncGroupId vgId;
|
||||
|
@ -132,12 +124,9 @@ typedef struct SSyncInfo {
|
|||
char path[TSDB_FILENAME_LEN];
|
||||
SWal* pWal;
|
||||
SSyncFSM* pFsm;
|
||||
|
||||
void* rpcClient;
|
||||
int32_t (*FpSendMsg)(void* rpcClient, const SEpSet* pEpSet, SRpcMsg* pMsg);
|
||||
void* queue;
|
||||
int32_t (*FpEqMsg)(void* queue, SRpcMsg* pMsg);
|
||||
|
||||
SMsgCb* msgcb;
|
||||
int32_t (*FpSendMsg)(const SEpSet* pEpSet, SRpcMsg* pMsg);
|
||||
int32_t (*FpEqMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg);
|
||||
} SSyncInfo;
|
||||
|
||||
int32_t syncInit();
|
||||
|
@ -152,27 +141,8 @@ const char* syncGetMyRoleStr(int64_t rid);
|
|||
SyncTerm syncGetMyTerm(int64_t rid);
|
||||
void syncGetEpSet(int64_t rid, SEpSet* pEpSet);
|
||||
int32_t syncGetVgId(int64_t rid);
|
||||
|
||||
typedef enum {
|
||||
TAOS_SYNC_PROPOSE_SUCCESS = 0,
|
||||
TAOS_SYNC_PROPOSE_NOT_LEADER,
|
||||
TAOS_SYNC_PROPOSE_OTHER_ERROR,
|
||||
} ESyncProposeCode;
|
||||
|
||||
int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak);
|
||||
|
||||
bool syncEnvIsStart();
|
||||
|
||||
extern int32_t sDebugFlag;
|
||||
|
||||
//-----------------------------------------
|
||||
struct SSyncNode;
|
||||
typedef struct SSyncNode SSyncNode;
|
||||
|
||||
struct SSyncBuffer;
|
||||
typedef struct SSyncBuffer SSyncBuffer;
|
||||
//-----------------------------------------
|
||||
|
||||
int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak);
|
||||
bool syncEnvIsStart();
|
||||
const char* syncStr(ESyncState state);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -20,13 +20,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
//#include <tdatablock.h>
|
||||
#include "cJSON.h"
|
||||
//#include "taosdef.h"
|
||||
#include "trpc.h"
|
||||
//#include "wal.h"
|
||||
|
||||
// ------------------ ds -------------------
|
||||
typedef struct SRaftId {
|
||||
|
@ -35,16 +29,12 @@ typedef struct SRaftId {
|
|||
} SRaftId;
|
||||
|
||||
// ------------------ control -------------------
|
||||
struct SSyncNode;
|
||||
typedef struct SSyncNode SSyncNode;
|
||||
|
||||
SSyncNode* syncNodeAcquire(int64_t rid);
|
||||
void syncNodeRelease(SSyncNode* pNode);
|
||||
|
||||
int32_t syncGetRespRpc(int64_t rid, uint64_t index, SRpcMsg* msg);
|
||||
int32_t syncGetAndDelRespRpc(int64_t rid, uint64_t index, SRpcMsg* msg);
|
||||
void syncSetQ(int64_t rid, void* queueHandle);
|
||||
void syncSetRpc(int64_t rid, void* rpcHandle);
|
||||
void syncSetMsgCb(int64_t rid, const SMsgCb* msgcb);
|
||||
char* sync2SimpleStr(int64_t rid);
|
||||
|
||||
// set timer ms
|
||||
|
|
|
@ -38,7 +38,7 @@ typedef struct {
|
|||
|
||||
typedef struct SRpcHandleInfo {
|
||||
// rpc info
|
||||
void *handle; // rpc handle returned to app
|
||||
void * handle; // rpc handle returned to app
|
||||
int64_t refId; // refid, used by server
|
||||
int32_t noResp; // has response or not(default 0, 0: resp, 1: no resp);
|
||||
int32_t persistHandle; // persist handle or not
|
||||
|
@ -49,13 +49,13 @@ typedef struct SRpcHandleInfo {
|
|||
void *node; // node mgmt handle
|
||||
|
||||
// resp info
|
||||
void *rsp;
|
||||
void * rsp;
|
||||
int32_t rspLen;
|
||||
} SRpcHandleInfo;
|
||||
|
||||
typedef struct SRpcMsg {
|
||||
tmsg_t msgType;
|
||||
void *pCont;
|
||||
void * pCont;
|
||||
int32_t contLen;
|
||||
int32_t code;
|
||||
SRpcHandleInfo info;
|
||||
|
@ -63,11 +63,6 @@ typedef struct SRpcMsg {
|
|||
} SRpcMsg;
|
||||
|
||||
typedef void (*RpcCfp)(void *parent, SRpcMsg *, SEpSet *rf);
|
||||
typedef int (*RpcAfp)(void *parent, char *tableId, char *spi, char *encrypt, char *secret, char *ckey);
|
||||
///
|
||||
// // SRpcMsg code
|
||||
// REDIERE,
|
||||
// NOT READY, EpSet
|
||||
typedef bool (*RpcRfp)(int32_t code);
|
||||
|
||||
typedef struct SRpcInit {
|
||||
|
@ -80,18 +75,11 @@ typedef struct SRpcInit {
|
|||
int idleTime; // milliseconds, 0 means idle timer is disabled
|
||||
|
||||
// the following is for client app ecurity only
|
||||
char *user; // user name
|
||||
char spi; // security parameter index
|
||||
char encrypt; // encrypt algorithm
|
||||
char *secret; // key for authentication
|
||||
char *ckey; // ciphering key
|
||||
char *user; // user name
|
||||
|
||||
// call back to process incoming msg, code shall be ignored by server app
|
||||
RpcCfp cfp;
|
||||
|
||||
// call back to retrieve the client auth info, for server app only
|
||||
RpcAfp afp;
|
||||
|
||||
// user defined retry func
|
||||
RpcRfp rfp;
|
||||
|
||||
|
|
|
@ -649,6 +649,8 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_PAR_INVALID_TBNAME TAOS_DEF_ERROR_CODE(0, 0x264C)
|
||||
#define TSDB_CODE_PAR_INVALID_FUNCTION_NAME TAOS_DEF_ERROR_CODE(0, 0x264D)
|
||||
#define TSDB_CODE_PAR_COMMENT_TOO_LONG TAOS_DEF_ERROR_CODE(0, 0x264E)
|
||||
#define TSDB_CODE_PAR_NOT_ALLOWED_FUNC TAOS_DEF_ERROR_CODE(0, 0x264F)
|
||||
#define TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY TAOS_DEF_ERROR_CODE(0, 0x2650)
|
||||
|
||||
//planner
|
||||
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
|
||||
|
|
|
@ -60,7 +60,7 @@ static void registerRequest(SRequestObj *pRequest) {
|
|||
static void deregisterRequest(SRequestObj *pRequest) {
|
||||
assert(pRequest != NULL);
|
||||
|
||||
STscObj *pTscObj = pRequest->pTscObj;
|
||||
STscObj * pTscObj = pRequest->pTscObj;
|
||||
SInstanceSummary *pActivity = &pTscObj->pAppInfo->summary;
|
||||
|
||||
int32_t currentInst = atomic_sub_fetch_64((int64_t *)&pActivity->currentRequests, 1);
|
||||
|
@ -91,7 +91,6 @@ static bool clientRpcRfp(int32_t code) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO refactor
|
||||
void *openTransporter(const char *user, const char *auth, int32_t numOfThread) {
|
||||
SRpcInit rpcInit;
|
||||
|
@ -105,10 +104,6 @@ void *openTransporter(const char *user, const char *auth, int32_t numOfThread) {
|
|||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
rpcInit.user = (char *)user;
|
||||
rpcInit.idleTime = tsShellActivityTimer * 1000;
|
||||
rpcInit.ckey = "key";
|
||||
rpcInit.spi = 1;
|
||||
rpcInit.secret = (char *)auth;
|
||||
|
||||
void *pDnodeConn = rpcOpen(&rpcInit);
|
||||
if (pDnodeConn == NULL) {
|
||||
tscError("failed to init connection to server");
|
||||
|
@ -318,7 +313,7 @@ int taos_options_imp(TSDB_OPTION option, const char *str) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
SConfig *pCfg = taosGetCfg();
|
||||
SConfig * pCfg = taosGetCfg();
|
||||
SConfigItem *pItem = NULL;
|
||||
|
||||
switch (option) {
|
||||
|
|
|
@ -13,11 +13,13 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "cJSON.h"
|
||||
#include "clientInt.h"
|
||||
#include "clientLog.h"
|
||||
#include "command.h"
|
||||
#include "scheduler.h"
|
||||
#include "tdatablock.h"
|
||||
#include "tdataformat.h"
|
||||
#include "tdef.h"
|
||||
#include "tglobal.h"
|
||||
#include "tmsgtype.h"
|
||||
|
@ -187,7 +189,8 @@ int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtC
|
|||
setResSchemaInfo(&pRequest->body.resInfo, (*pQuery)->pResSchema, (*pQuery)->numOfResCols);
|
||||
setResPrecision(&pRequest->body.resInfo, (*pQuery)->precision);
|
||||
}
|
||||
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code || NEED_CLIENT_HANDLE_ERROR(code)) {
|
||||
TSWAP(pRequest->dbList, (*pQuery)->pDbList);
|
||||
TSWAP(pRequest->tableList, (*pQuery)->pTableList);
|
||||
}
|
||||
|
@ -268,7 +271,7 @@ void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t
|
|||
|
||||
if (pSchema[i].type == TSDB_DATA_TYPE_VARCHAR) {
|
||||
pResInfo->userFields[i].bytes -= VARSTR_HEADER_SIZE;
|
||||
} else if (pSchema[i].type == TSDB_DATA_TYPE_NCHAR) {
|
||||
} else if (pSchema[i].type == TSDB_DATA_TYPE_NCHAR || pSchema[i].type == TSDB_DATA_TYPE_JSON) {
|
||||
pResInfo->userFields[i].bytes = (pResInfo->userFields[i].bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
|
||||
}
|
||||
|
||||
|
@ -339,12 +342,11 @@ int32_t validateSversion(SRequestObj* pRequest, void* res) {
|
|||
}
|
||||
|
||||
for (int32_t i = 0; i < pRsp->nBlocks; ++i) {
|
||||
SSubmitBlkRsp *blk = pRsp->pBlocks + i;
|
||||
STbSVersion tbSver = {.tbFName = blk->tblFName, .sver = blk->sver};
|
||||
SSubmitBlkRsp* blk = pRsp->pBlocks + i;
|
||||
STbSVersion tbSver = {.tbFName = blk->tblFName, .sver = blk->sver};
|
||||
taosArrayPush(pArray, &tbSver);
|
||||
}
|
||||
} else if (TDMT_VND_QUERY == pRequest->type) {
|
||||
|
||||
}
|
||||
|
||||
SCatalog* pCatalog = NULL;
|
||||
|
@ -369,7 +371,6 @@ void freeRequestRes(SRequestObj* pRequest, void* res) {
|
|||
if (TDMT_VND_SUBMIT == pRequest->type) {
|
||||
tFreeSSubmitRsp((SSubmitRsp*)res);
|
||||
} else if (TDMT_VND_QUERY == pRequest->type) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -483,7 +484,8 @@ SRequestObj* execQuery(STscObj* pTscObj, const char* sql, int sqlLen) {
|
|||
int32_t retryNum = 0;
|
||||
int32_t code = 0;
|
||||
|
||||
while (retryNum++ < REQUEST_MAX_TRY_TIMES) {
|
||||
do {
|
||||
destroyRequest(pRequest);
|
||||
pRequest = launchQuery(pTscObj, sql, sqlLen);
|
||||
if (pRequest == NULL || TSDB_CODE_SUCCESS == pRequest->code || !NEED_CLIENT_HANDLE_ERROR(pRequest->code)) {
|
||||
break;
|
||||
|
@ -494,9 +496,7 @@ SRequestObj* execQuery(STscObj* pTscObj, const char* sql, int sqlLen) {
|
|||
pRequest->code = code;
|
||||
break;
|
||||
}
|
||||
|
||||
destroyRequest(pRequest);
|
||||
}
|
||||
} while (retryNum++ < REQUEST_MAX_TRY_TIMES);
|
||||
|
||||
return pRequest;
|
||||
}
|
||||
|
@ -805,6 +805,95 @@ static int32_t doPrepareResPtr(SReqResultInfo* pResInfo) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static char* parseTagDatatoJson(void* p) {
|
||||
char* string = NULL;
|
||||
cJSON* json = cJSON_CreateObject();
|
||||
if (json == NULL) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
int16_t nCols = kvRowNCols(p);
|
||||
char tagJsonKey[256] = {0};
|
||||
for (int j = 0; j < nCols; ++j) {
|
||||
SColIdx* pColIdx = kvRowColIdxAt(p, j);
|
||||
char* val = (char*)(kvRowColVal(p, pColIdx));
|
||||
if (j == 0) {
|
||||
if (*val == TSDB_DATA_TYPE_NULL) {
|
||||
string = taosMemoryCalloc(1, 8);
|
||||
sprintf(varDataVal(string), "%s", TSDB_DATA_NULL_STR_L);
|
||||
varDataSetLen(string, strlen(varDataVal(string)));
|
||||
goto end;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// json key encode by binary
|
||||
memset(tagJsonKey, 0, sizeof(tagJsonKey));
|
||||
memcpy(tagJsonKey, varDataVal(val), varDataLen(val));
|
||||
// json value
|
||||
val += varDataTLen(val);
|
||||
char* realData = POINTER_SHIFT(val, CHAR_BYTES);
|
||||
char type = *val;
|
||||
if (type == TSDB_DATA_TYPE_NULL) {
|
||||
cJSON* value = cJSON_CreateNull();
|
||||
if (value == NULL) {
|
||||
goto end;
|
||||
}
|
||||
cJSON_AddItemToObject(json, tagJsonKey, value);
|
||||
} else if (type == TSDB_DATA_TYPE_NCHAR) {
|
||||
cJSON* value = NULL;
|
||||
if (varDataLen(realData) > 0) {
|
||||
char* tagJsonValue = taosMemoryCalloc(varDataLen(realData), 1);
|
||||
int32_t length = taosUcs4ToMbs((TdUcs4*)varDataVal(realData), varDataLen(realData), tagJsonValue);
|
||||
if (length < 0) {
|
||||
tscError("charset:%s to %s. val:%s convert json value failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, val);
|
||||
taosMemoryFree(tagJsonValue);
|
||||
goto end;
|
||||
}
|
||||
value = cJSON_CreateString(tagJsonValue);
|
||||
taosMemoryFree(tagJsonValue);
|
||||
if (value == NULL) {
|
||||
goto end;
|
||||
}
|
||||
} else if (varDataLen(realData) == 0) {
|
||||
value = cJSON_CreateString("");
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(json, tagJsonKey, value);
|
||||
} else if (type == TSDB_DATA_TYPE_DOUBLE) {
|
||||
double jsonVd = *(double*)(realData);
|
||||
cJSON* value = cJSON_CreateNumber(jsonVd);
|
||||
if (value == NULL) {
|
||||
goto end;
|
||||
}
|
||||
cJSON_AddItemToObject(json, tagJsonKey, value);
|
||||
// }else if(type == TSDB_DATA_TYPE_BIGINT){
|
||||
// int64_t jsonVd = *(int64_t*)(realData);
|
||||
// cJSON* value = cJSON_CreateNumber((double)jsonVd);
|
||||
// if (value == NULL)
|
||||
// {
|
||||
// goto end;
|
||||
// }
|
||||
// cJSON_AddItemToObject(json, tagJsonKey, value);
|
||||
} else if (type == TSDB_DATA_TYPE_BOOL) {
|
||||
char jsonVd = *(char*)(realData);
|
||||
cJSON* value = cJSON_CreateBool(jsonVd);
|
||||
if (value == NULL) {
|
||||
goto end;
|
||||
}
|
||||
cJSON_AddItemToObject(json, tagJsonKey, value);
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
}
|
||||
string = cJSON_PrintUnformatted(json);
|
||||
end:
|
||||
cJSON_Delete(json);
|
||||
return string;
|
||||
}
|
||||
|
||||
static int32_t doConvertUCS4(SReqResultInfo* pResultInfo, int32_t numOfRows, int32_t numOfCols, int32_t* colLength) {
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
int32_t type = pResultInfo->fields[i].type;
|
||||
|
@ -835,9 +924,7 @@ static int32_t doConvertUCS4(SReqResultInfo* pResultInfo, int32_t numOfRows, int
|
|||
|
||||
pResultInfo->pCol[i].pData = pResultInfo->convertBuf[i];
|
||||
pResultInfo->row[i] = pResultInfo->pCol[i].pData;
|
||||
}
|
||||
|
||||
if (type == TSDB_DATA_TYPE_JSON) {
|
||||
} else if (type == TSDB_DATA_TYPE_JSON && colLength[i] > 0) {
|
||||
char* p = taosMemoryRealloc(pResultInfo->convertBuf[i], colLength[i]);
|
||||
if (p == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -857,15 +944,9 @@ static int32_t doConvertUCS4(SReqResultInfo* pResultInfo, int32_t numOfRows, int
|
|||
sprintf(varDataVal(dst), "%s", TSDB_DATA_NULL_STR_L);
|
||||
varDataSetLen(dst, strlen(varDataVal(dst)));
|
||||
} else if (jsonInnerType == TSDB_DATA_TYPE_JSON) {
|
||||
int32_t length =
|
||||
taosUcs4ToMbs((TdUcs4*)varDataVal(jsonInnerData), varDataLen(jsonInnerData), varDataVal(dst));
|
||||
|
||||
if (length <= 0) {
|
||||
tscError("charset:%s to %s. val:%s convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset,
|
||||
varDataVal(jsonInnerData));
|
||||
length = 0;
|
||||
}
|
||||
varDataSetLen(dst, length);
|
||||
char* jsonString = parseTagDatatoJson(jsonInnerData);
|
||||
STR_TO_VARSTR(dst, jsonString);
|
||||
taosMemoryFree(jsonString);
|
||||
} else if (jsonInnerType == TSDB_DATA_TYPE_NCHAR) { // value -> "value"
|
||||
*(char*)varDataVal(dst) = '\"';
|
||||
int32_t length = taosUcs4ToMbs((TdUcs4*)varDataVal(jsonInnerData), varDataLen(jsonInnerData),
|
||||
|
@ -1022,7 +1103,6 @@ TSDB_SERVER_STATUS taos_check_server_status(const char* fqdn, int port, char* de
|
|||
SRpcInit rpcInit = {0};
|
||||
char pass[TSDB_PASSWORD_LEN + 1] = {0};
|
||||
|
||||
taosEncryptPass_c((uint8_t*)("_pwd"), strlen("_pwd"), pass);
|
||||
rpcInit.label = "CHK";
|
||||
rpcInit.numOfThreads = 1;
|
||||
rpcInit.cfp = NULL;
|
||||
|
@ -1030,9 +1110,6 @@ TSDB_SERVER_STATUS taos_check_server_status(const char* fqdn, int port, char* de
|
|||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
rpcInit.idleTime = tsShellActivityTimer * 1000;
|
||||
rpcInit.user = "_dnd";
|
||||
rpcInit.ckey = "_key";
|
||||
rpcInit.spi = 1;
|
||||
rpcInit.secret = pass;
|
||||
|
||||
clientRpc = rpcOpen(&rpcInit);
|
||||
if (clientRpc == NULL) {
|
||||
|
|
|
@ -58,19 +58,17 @@ for (int i = 1; i < keyLen; ++i) { \
|
|||
#define IS_INVALID_COL_LEN(len) ((len) <= 0 || (len) >= TSDB_COL_NAME_LEN)
|
||||
#define IS_INVALID_TABLE_LEN(len) ((len) <= 0 || (len) >= TSDB_TABLE_NAME_LEN)
|
||||
|
||||
#define OTD_MAX_FIELDS_NUM 2
|
||||
#define OTD_JSON_SUB_FIELDS_NUM 2
|
||||
#define OTD_JSON_FIELDS_NUM 4
|
||||
|
||||
#define OTD_TIMESTAMP_COLUMN_NAME "ts"
|
||||
#define OTD_METRIC_VALUE_COLUMN_NAME "value"
|
||||
|
||||
#define TS "_ts"
|
||||
#define TS_LEN 3
|
||||
#define TAG "_tagNone"
|
||||
#define TAG_LEN 8
|
||||
#define VALUE "value"
|
||||
#define VALUE_LEN 5
|
||||
#define TS "_ts"
|
||||
#define TS_LEN 3
|
||||
#define TAG "_tag"
|
||||
#define TAG_LEN 4
|
||||
#define TAG_VALUE "NULL"
|
||||
#define TAG_VALUE_LEN 4
|
||||
#define VALUE "value"
|
||||
#define VALUE_LEN 5
|
||||
|
||||
#define BINARY_ADD_LEN 2 // "binary" 2 means " "
|
||||
#define NCHAR_ADD_LEN 3 // L"nchar" 3 means L" "
|
||||
|
@ -598,25 +596,33 @@ static bool smlParseNumber(SSmlKv *kvVal, SSmlMsgBuf *msg){
|
|||
kvVal->type = TSDB_DATA_TYPE_FLOAT;
|
||||
kvVal->f = (float)result;
|
||||
}else if ((left == 1 && *endptr == 'i') || (left == 3 && strncasecmp(endptr, "i64", left) == 0)){
|
||||
if(result >= (double)INT64_MAX){
|
||||
kvVal->i = INT64_MAX;
|
||||
}else if(result <= (double)INT64_MIN){
|
||||
kvVal->i = INT64_MIN;
|
||||
}else{
|
||||
kvVal->i = result;
|
||||
if(smlDoubleToInt64OverFlow(result)){
|
||||
errno = 0;
|
||||
int64_t tmp = taosStr2Int64(pVal, &endptr, 10);
|
||||
if(errno == ERANGE){
|
||||
smlBuildInvalidDataMsg(msg, "big int out of range[-9223372036854775808,9223372036854775807]", pVal);
|
||||
return false;
|
||||
}
|
||||
kvVal->type = TSDB_DATA_TYPE_BIGINT;
|
||||
kvVal->i = tmp;
|
||||
return true;
|
||||
}
|
||||
kvVal->type = TSDB_DATA_TYPE_BIGINT;
|
||||
kvVal->i = (int64_t)result;
|
||||
}else if ((left == 3 && strncasecmp(endptr, "u64", left) == 0)){
|
||||
if(result < 0){
|
||||
smlBuildInvalidDataMsg(msg, "unsigned big int is too large, out of precision", pVal);
|
||||
return false;
|
||||
}
|
||||
if(result >= (double)UINT64_MAX){
|
||||
kvVal->u = UINT64_MAX;
|
||||
}else{
|
||||
kvVal->u = result;
|
||||
if(result >= (double)UINT64_MAX || result < 0){
|
||||
errno = 0;
|
||||
uint64_t tmp = taosStr2UInt64(pVal, &endptr, 10);
|
||||
if(errno == ERANGE || result < 0){
|
||||
smlBuildInvalidDataMsg(msg, "unsigned big int out of range[0,18446744073709551615]", pVal);
|
||||
return false;
|
||||
}
|
||||
kvVal->type = TSDB_DATA_TYPE_UBIGINT;
|
||||
kvVal->u = tmp;
|
||||
return true;
|
||||
}
|
||||
kvVal->type = TSDB_DATA_TYPE_UBIGINT;
|
||||
kvVal->u = result;
|
||||
}else if (left == 3 && strncasecmp(endptr, "i32", left) == 0){
|
||||
if(!IS_VALID_INT(result)){
|
||||
smlBuildInvalidDataMsg(msg, "int out of range[-2147483648,2147483647]", pVal);
|
||||
|
@ -718,57 +724,43 @@ static int64_t smlGetTimeValue(const char *value, int32_t len, int8_t type) {
|
|||
if(value + len != endPtr){
|
||||
return -1;
|
||||
}
|
||||
if(tsInt64 == 0){
|
||||
return taosGetTimestampNs();
|
||||
}
|
||||
double ts = tsInt64;
|
||||
switch (type) {
|
||||
case TSDB_TIME_PRECISION_HOURS:
|
||||
ts *= (3600 * 1e9);
|
||||
tsInt64 *= (3600 * 1e9);
|
||||
ts *= NANOSECOND_PER_HOUR;
|
||||
tsInt64 *= NANOSECOND_PER_HOUR;
|
||||
break;
|
||||
case TSDB_TIME_PRECISION_MINUTES:
|
||||
ts *= (60 * 1e9);
|
||||
tsInt64 *= (60 * 1e9);
|
||||
ts *= NANOSECOND_PER_MINUTE;
|
||||
tsInt64 *= NANOSECOND_PER_MINUTE;
|
||||
break;
|
||||
case TSDB_TIME_PRECISION_SECONDS:
|
||||
ts *= (1e9);
|
||||
tsInt64 *= (1e9);
|
||||
ts *= NANOSECOND_PER_SEC;
|
||||
tsInt64 *= NANOSECOND_PER_SEC;
|
||||
break;
|
||||
case TSDB_TIME_PRECISION_MILLI:
|
||||
ts *= (1e6);
|
||||
tsInt64 *= (1e6);
|
||||
ts *= NANOSECOND_PER_MSEC;
|
||||
tsInt64 *= NANOSECOND_PER_MSEC;
|
||||
break;
|
||||
case TSDB_TIME_PRECISION_MICRO:
|
||||
ts *= (1e3);
|
||||
tsInt64 *= (1e3);
|
||||
ts *= NANOSECOND_PER_USEC;
|
||||
tsInt64 *= NANOSECOND_PER_USEC;
|
||||
break;
|
||||
case TSDB_TIME_PRECISION_NANO:
|
||||
break;
|
||||
default:
|
||||
ASSERT(0);
|
||||
}
|
||||
if(ts >= (double)INT64_MAX || ts <= 0){
|
||||
if(ts >= (double)INT64_MAX || ts < 0){
|
||||
return -1;
|
||||
}
|
||||
|
||||
return tsInt64;
|
||||
}
|
||||
|
||||
static int64_t smlGetTimeNow(int8_t precision) {
|
||||
switch (precision) {
|
||||
case TSDB_TIME_PRECISION_HOURS:
|
||||
return taosGetTimestampMs()/1000/3600;
|
||||
case TSDB_TIME_PRECISION_MINUTES:
|
||||
return taosGetTimestampMs()/1000/60;
|
||||
case TSDB_TIME_PRECISION_SECONDS:
|
||||
return taosGetTimestampMs()/1000;
|
||||
case TSDB_TIME_PRECISION_MILLI:
|
||||
case TSDB_TIME_PRECISION_MICRO:
|
||||
case TSDB_TIME_PRECISION_NANO:
|
||||
return taosGetTimestamp(precision);
|
||||
default:
|
||||
ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
static int8_t smlGetTsTypeByLen(int32_t len) {
|
||||
if (len == TSDB_TIME_PRECISION_SEC_DIGITS) {
|
||||
return TSDB_TIME_PRECISION_SECONDS;
|
||||
|
@ -800,14 +792,15 @@ static int8_t smlGetTsTypeByPrecision(int8_t precision) {
|
|||
}
|
||||
|
||||
static int64_t smlParseInfluxTime(SSmlHandle* info, const char* data, int32_t len){
|
||||
if(len == 0){
|
||||
return taosGetTimestamp(TSDB_TIME_PRECISION_NANO);
|
||||
}
|
||||
|
||||
int8_t tsType = smlGetTsTypeByPrecision(info->precision);
|
||||
if (tsType == -1) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "invalid timestamp precision", NULL);
|
||||
return -1;
|
||||
}
|
||||
if(len == 0){
|
||||
return smlGetTimeNow(tsType);
|
||||
}
|
||||
|
||||
int64_t ts = smlGetTimeValue(data, len, tsType);
|
||||
if(ts == -1){
|
||||
|
@ -1103,8 +1096,7 @@ static int32_t smlParseTelnetString(SSmlHandle *info, const char* sql, SSmlTable
|
|||
kv->keyLen = VALUE_LEN;
|
||||
kv->value = value;
|
||||
kv->length = valueLen;
|
||||
if(!smlParseValue(kv, &info->msgBuf) || kv->type == TSDB_DATA_TYPE_BINARY
|
||||
|| kv->type == TSDB_DATA_TYPE_NCHAR || kv->type == TSDB_DATA_TYPE_BOOL){
|
||||
if(!smlParseValue(kv, &info->msgBuf)){
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
|
||||
|
@ -1124,8 +1116,8 @@ static int32_t smlParseCols(const char* data, int32_t len, SArray *cols, char *c
|
|||
if(!kv) return TSDB_CODE_OUT_OF_MEMORY;
|
||||
kv->key = TAG;
|
||||
kv->keyLen = TAG_LEN;
|
||||
kv->value = TAG;
|
||||
kv->length = TAG_LEN;
|
||||
kv->value = TAG_VALUE;
|
||||
kv->length = TAG_VALUE_LEN;
|
||||
kv->type = TSDB_DATA_TYPE_NCHAR;
|
||||
if(cols) taosArrayPush(cols, &kv);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -1610,7 +1602,8 @@ static int32_t smlParseTSFromJSON(SSmlHandle *info, cJSON *root, SArray *cols) {
|
|||
smlBuildInvalidDataMsg(&info->msgBuf, "timestamp is too large", NULL);
|
||||
return TSDB_CODE_TSC_INVALID_TIME_STAMP;
|
||||
}
|
||||
if(timeDouble <= 0){
|
||||
|
||||
if(timeDouble < 0){
|
||||
return TSDB_CODE_TSC_INVALID_TIME_STAMP;
|
||||
}
|
||||
uint8_t tsLen = smlGetTimestampLen((int64_t)timeDouble);
|
||||
|
@ -1628,7 +1621,9 @@ static int32_t smlParseTSFromJSON(SSmlHandle *info, cJSON *root, SArray *cols) {
|
|||
return TSDB_CODE_TSC_INVALID_TIME_STAMP;
|
||||
}
|
||||
tsVal = timeDouble;
|
||||
} else {
|
||||
} else if(timeDouble == 0){
|
||||
tsVal = taosGetTimestampNs();
|
||||
}else {
|
||||
return TSDB_CODE_TSC_INVALID_TIME_STAMP;
|
||||
}
|
||||
} else if (cJSON_IsObject(timestamp)) {
|
||||
|
@ -2264,6 +2259,7 @@ static int32_t smlParseLine(SSmlHandle *info, char* lines[], int numLines){
|
|||
uError("SML:0x%" PRIx64 " smlParseJSON failed:%s", info->id, *lines);
|
||||
return code;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numLines; ++i) {
|
||||
|
|
|
@ -567,6 +567,7 @@ TEST(testCase, insert_test) {
|
|||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST(testCase, projection_query_tables) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
|
@ -605,7 +606,7 @@ TEST(testCase, projection_query_tables) {
|
|||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
for(int32_t i = 0; i < 10000000; i += 20) {
|
||||
for(int32_t i = 0; i < 100000; i += 20) {
|
||||
char sql[1024] = {0};
|
||||
sprintf(sql,
|
||||
"insert into tu values(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)"
|
||||
|
@ -625,7 +626,7 @@ TEST(testCase, projection_query_tables) {
|
|||
|
||||
printf("start to insert next table\n");
|
||||
|
||||
for(int32_t i = 0; i < 10000000; i += 20) {
|
||||
for(int32_t i = 0; i < 100000; i += 20) {
|
||||
char sql[1024] = {0};
|
||||
sprintf(sql,
|
||||
"insert into tu2 values(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)"
|
||||
|
@ -692,8 +693,6 @@ TEST(testCase, projection_query_stables) {
|
|||
taos_close(pConn);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
TEST(testCase, agg_query_tables) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(pConn, nullptr);
|
||||
|
|
|
@ -208,6 +208,7 @@ TEST(testCase, smlParseCols_Error_Test) {
|
|||
memcpy(sql, data[i], len + 1);
|
||||
SArray *cols = taosArrayInit(8, POINTER_BYTES);
|
||||
int32_t ret = smlParseCols(sql, len, cols, NULL, false, dumplicateKey, &msgBuf);
|
||||
printf("i:%d\n",i);
|
||||
ASSERT_NE(ret, TSDB_CODE_SUCCESS);
|
||||
taosHashClear(dumplicateKey);
|
||||
taosMemoryFree(sql);
|
||||
|
@ -272,11 +273,11 @@ TEST(testCase, smlParseCols_tag_Test) {
|
|||
|
||||
// nchar
|
||||
kv = (SSmlKv *)taosArrayGetP(cols, 0);
|
||||
ASSERT_EQ(strncasecmp(kv->key, TAG, strlen(TAG)), 0);
|
||||
ASSERT_EQ(kv->keyLen, strlen(TAG));
|
||||
ASSERT_EQ(strncasecmp(kv->key, TAG, TAG_LEN), 0);
|
||||
ASSERT_EQ(kv->keyLen, TAG_LEN);
|
||||
ASSERT_EQ(kv->type, TSDB_DATA_TYPE_NCHAR);
|
||||
ASSERT_EQ(kv->length, strlen(TAG));
|
||||
ASSERT_EQ(strncasecmp(kv->value, TAG, strlen(TAG)), 0);
|
||||
ASSERT_EQ(kv->length, TAG_LEN);
|
||||
ASSERT_EQ(strncasecmp(kv->value, TAG_VALUE, TAG_VALUE_LEN), 0);
|
||||
taosMemoryFree(kv);
|
||||
|
||||
taosArrayDestroy(cols);
|
||||
|
@ -506,7 +507,7 @@ TEST(testCase, smlProcess_influx_Test) {
|
|||
"readings,name=truck_0,fleet=South,driver=Trish,model=H-2,device_version=v2.3 load_capacity=1500,fuel_capacity=150,nominal_fuel_consumption=12,latitude=52.31854,longitude=4.72037,elevation=124,heading=221,grade=0,fuel_consumption=25 1451608403000000000",
|
||||
"readings,name=truck_0,fleet=South,driver=Trish,model=H-2,device_version=v2.3 fuel_capacity=150,nominal_fuel_consumption=12,latitude=52.31854,longitude=4.72037,elevation=124,velocity=0,heading=221,grade=0,fuel_consumption=25 1451609404000000000",
|
||||
"readings,name=truck_0,fleet=South,driver=Trish,model=H-2,device_version=v2.3 fuel_consumption=25,grade=0 1451619405000000000",
|
||||
"readings,name=truck_1,fleet=South,driver=Albert,model=F-150,device_version=v1.5 load_capacity=2000,fuel_capacity=200,nominal_fuel_consumption=15,latitude=72.45258,longitude=68.83761,elevation=255,velocity=0,heading=181,grade=0,fuel_consumption=25 145160640600000000",
|
||||
"readings,name=truck_1,fleet=South,driver=Albert,model=F-150,device_version=v1.5 load_capacity=2000,fuel_capacity=200,nominal_fuel_consumption=15,latitude=72.45258,longitude=68.83761,elevation=255,velocity=0,heading=181,grade=0,fuel_consumption=25 1451606406000000000",
|
||||
"readings,name=truck_2,driver=Derek,model=F-150,device_version=v1.5 load_capacity=2000,fuel_capacity=200,nominal_fuel_consumption=15,latitude=24.5208,longitude=28.09377,elevation=428,velocity=0,heading=304,grade=0,fuel_consumption=25 1451606407000000000",
|
||||
"readings,name=truck_2,fleet=North,driver=Derek,model=F-150 load_capacity=2000,fuel_capacity=200,nominal_fuel_consumption=15,latitude=24.5208,longitude=28.09377,elevation=428,velocity=0,heading=304,grade=0,fuel_consumption=25 1451609408000000000",
|
||||
"readings,fleet=South,name=truck_0,driver=Trish,model=H-2,device_version=v2.3 fuel_consumption=25,grade=0 1451629409000000000",
|
||||
|
@ -745,7 +746,7 @@ TEST(testCase, smlProcess_json1_Test) {
|
|||
" }\n"
|
||||
" }\n"
|
||||
"]";
|
||||
int ret = smlProcess(info, (char **)(&sql), -1);
|
||||
int ret = smlProcess(info, (char **)(&sql), 1);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
// case 1
|
||||
|
@ -1202,22 +1203,67 @@ TEST(testCase, sml_TD15662_Test) {
|
|||
SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, NULL, NULL, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_MILLI_SECONDS);
|
||||
ASSERT_NE(info, nullptr);
|
||||
|
||||
const char *sql[] = {
|
||||
"iyyyje,id=iyyyje_41943_1303,t0=t,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"binaryTagValue\",t8=L\"ncharTagValue\" c0=false,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"binaryColValue\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000",
|
||||
"hetrey,id=sub_table_0123456,t0=f,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"binaryTagValue\",t8=L\"ncharTagValue\" c0=f,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"binaryColValue\",c8=L\"ncharColValue\",c9=7u64",
|
||||
};
|
||||
int ret = smlProcess(info, (char **)sql, sizeof(sql) / sizeof(sql[0]));
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
// case 1
|
||||
TAOS_RES *res = taos_query(taos, "select * from t_a5615048edae55218a22a149edebdc82");
|
||||
ASSERT_NE(res, nullptr);
|
||||
|
||||
TAOS_ROW row = taos_fetch_row(res);
|
||||
int64_t ts = *(int64_t*)row[0];
|
||||
ASSERT_EQ(ts, 1626006833639000000);
|
||||
|
||||
taos_free_result(res);
|
||||
destroyRequest(request);
|
||||
smlDestroyInfo(info);
|
||||
}
|
||||
|
||||
TEST(testCase, sml_TD15735_Test) {
|
||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(taos, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists sml_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(taos, "use sml_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, NULL, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
ASSERT_NE(info, nullptr);
|
||||
|
||||
const char *sql[1] = {
|
||||
"{'metric': 'pekoiw', 'timestamp': {'value': 1626006833639000000, 'type': 'ns'}, 'value': {'value': False, 'type': 'bool'}, 'tags': {'t0': {'value': True, 'type': 'bool'}, 't1': {'value': 127, 'type': 'tinyint'}, 't2': {'value': 32767, 'type': 'smallint'}, 't3': {'value': 2147483647, 'type': 'int'}, 't4': {'value': 9223372036854775807, 'type': 'bigint'}, 't5': {'value': 11.12345027923584, 'type': 'float'}, 't6': {'value': 22.123456789, 'type': 'double'}, 't7': {'value': 'binaryTagValue', 'type': 'binary'}, 't8': {'value': 'ncharTagValue', 'type': 'nchar'}}}",
|
||||
};
|
||||
int32_t ret = smlProcess(info, (char**)sql, sizeof(sql)/sizeof(sql[0]));
|
||||
ASSERT_NE(ret, 0);
|
||||
|
||||
destroyRequest(request);
|
||||
smlDestroyInfo(info);
|
||||
}
|
||||
|
||||
TEST(testCase, sml_TD15742_Test) {
|
||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(taos, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(taos, "create database if not exists TD15742");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(taos, "use TD15742");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, NULL, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_MILLI_SECONDS);
|
||||
ASSERT_NE(info, nullptr);
|
||||
|
||||
const char *sql[] = {
|
||||
"test_ms,t0=t c0=f 1626006833641",
|
||||
};
|
||||
int ret = smlProcess(info, (char**)sql, sizeof(sql)/sizeof(sql[0]));
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
destroyRequest(request);
|
||||
smlDestroyInfo(info);
|
||||
}
|
|
@ -122,10 +122,14 @@ int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, con
|
|||
dataLen = 0;
|
||||
} else if (*pData == TSDB_DATA_TYPE_NCHAR) {
|
||||
dataLen = varDataTLen(pData + CHAR_BYTES);
|
||||
} else if (*pData == TSDB_DATA_TYPE_BIGINT || *pData == TSDB_DATA_TYPE_DOUBLE) {
|
||||
dataLen = LONG_BYTES;
|
||||
} else if (*pData == TSDB_DATA_TYPE_DOUBLE) {
|
||||
dataLen = DOUBLE_BYTES;
|
||||
} else if (*pData == TSDB_DATA_TYPE_BOOL) {
|
||||
dataLen = CHAR_BYTES;
|
||||
} else if (*pData == TSDB_DATA_TYPE_JSON) {
|
||||
dataLen = kvRowLen(pData + CHAR_BYTES);
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
dataLen += CHAR_BYTES;
|
||||
}
|
||||
|
|
|
@ -40,11 +40,11 @@ bool tsPrintAuth = false;
|
|||
|
||||
// multi process
|
||||
int32_t tsMultiProcess = 0;
|
||||
int32_t tsMnodeShmSize = TSDB_MAX_WAL_SIZE * 2 + 128;
|
||||
int32_t tsVnodeShmSize = TSDB_MAX_WAL_SIZE * 10 + 128;
|
||||
int32_t tsQnodeShmSize = TSDB_MAX_WAL_SIZE * 4 + 128;
|
||||
int32_t tsSnodeShmSize = TSDB_MAX_WAL_SIZE * 4 + 128;
|
||||
int32_t tsBnodeShmSize = TSDB_MAX_WAL_SIZE * 4 + 128;
|
||||
int32_t tsMnodeShmSize = TSDB_MAX_WAL_SIZE * 2 + 1024;
|
||||
int32_t tsVnodeShmSize = TSDB_MAX_WAL_SIZE * 10 + 1024;
|
||||
int32_t tsQnodeShmSize = TSDB_MAX_WAL_SIZE * 4 + 1024;
|
||||
int32_t tsSnodeShmSize = TSDB_MAX_WAL_SIZE * 4 + 1024;
|
||||
int32_t tsBnodeShmSize = TSDB_MAX_WAL_SIZE * 4 + 1024;
|
||||
int32_t tsNumOfShmThreads = 1;
|
||||
|
||||
// queue & threads
|
||||
|
@ -380,11 +380,11 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
|
|||
if (cfgAddBool(pCfg, "deadLockKillQuery", tsDeadLockKillQuery, 0) != 0) return -1;
|
||||
|
||||
if (cfgAddInt32(pCfg, "multiProcess", tsMultiProcess, 0, 2, 0) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "mnodeShmSize", tsMnodeShmSize, TSDB_MAX_WAL_SIZE + 128, INT32_MAX, 0) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "vnodeShmSize", tsVnodeShmSize, TSDB_MAX_WAL_SIZE + 128, INT32_MAX, 0) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "qnodeShmSize", tsQnodeShmSize, TSDB_MAX_WAL_SIZE + 128, INT32_MAX, 0) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "snodeShmSize", tsSnodeShmSize, TSDB_MAX_WAL_SIZE + 128, INT32_MAX, 0) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "bnodeShmSize", tsBnodeShmSize, TSDB_MAX_WAL_SIZE + 128, INT32_MAX, 0) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "mnodeShmSize", tsMnodeShmSize, TSDB_MAX_WAL_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "vnodeShmSize", tsVnodeShmSize, TSDB_MAX_WAL_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "qnodeShmSize", tsQnodeShmSize, TSDB_MAX_WAL_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "snodeShmSize", tsSnodeShmSize, TSDB_MAX_WAL_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "bnodeShmSize", tsBnodeShmSize, TSDB_MAX_WAL_SIZE * 2 + 1024, INT32_MAX, 0) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "mumOfShmThreads", tsNumOfShmThreads, 1, 1024, 0) != 0) return -1;
|
||||
|
||||
tsNumOfRpcThreads = tsNumOfCores / 2;
|
||||
|
|
|
@ -126,7 +126,9 @@ int32_t mmPutRpcMsgToReadQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
return mmPutRpcMsgToWorker(&pMgmt->readWorker, pMsg);
|
||||
}
|
||||
|
||||
int32_t mmPutRpcMsgToSyncQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) { return mmPutRpcMsgToWorker(&pMgmt->syncWorker, pMsg); }
|
||||
int32_t mmPutRpcMsgToSyncQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
return mmPutRpcMsgToWorker(&pMgmt->syncWorker, pMsg);
|
||||
}
|
||||
|
||||
int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
||||
SSingleWorkerCfg qCfg = {
|
||||
|
|
|
@ -314,6 +314,10 @@ SArray *vmGetMsgHandles() {
|
|||
if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_MERGE_EXEC, vmPutNodeMsgToMergeQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_WRITE_EXEC, vmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_STREAM_TRIGGER, vmPutNodeMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_RUN, vmPutNodeMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_DISPATCH, vmPutNodeMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_RECOVER, vmPutNodeMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_VNODE, vmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_COMPACT_VNODE, vmPutNodeMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_VNODE, vmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||
|
|
|
@ -22,21 +22,19 @@
|
|||
static inline void vmSendRsp(SRpcMsg *pMsg, int32_t code) {
|
||||
SRpcMsg rsp = {
|
||||
.code = code,
|
||||
.info = pMsg->info,
|
||||
.pCont = pMsg->info.rsp,
|
||||
.contLen = pMsg->info.rspLen,
|
||||
.info = pMsg->info,
|
||||
};
|
||||
tmsgSendRsp(&rsp);
|
||||
}
|
||||
|
||||
static void vmProcessMgmtMonitorQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
||||
SVnodeMgmt *pMgmt = pInfo->ahandle;
|
||||
int32_t code = -1;
|
||||
dTrace("msg:%p, get from vnode queue, type:%s", pMsg, TMSG_INFO(pMsg->msgType));
|
||||
|
||||
int32_t code = -1;
|
||||
tmsg_t msgType = pMsg->msgType;
|
||||
dTrace("msg:%p, get from vnode queue, type:%s", pMsg, TMSG_INFO(msgType));
|
||||
|
||||
switch (msgType) {
|
||||
switch (pMsg->msgType) {
|
||||
case TDMT_MON_VM_INFO:
|
||||
code = vmProcessGetMonitorInfoReq(pMgmt, pMsg);
|
||||
break;
|
||||
|
@ -54,7 +52,7 @@ static void vmProcessMgmtMonitorQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
|||
dError("msg:%p, not processed in vnode queue", pMsg);
|
||||
}
|
||||
|
||||
if (msgType & 1u) {
|
||||
if (IsReq(pMsg)) {
|
||||
if (code != 0 && terrno != 0) code = terrno;
|
||||
vmSendRsp(pMsg, code);
|
||||
}
|
||||
|
@ -72,11 +70,10 @@ static void vmProcessQueryQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
|||
if (code != 0) {
|
||||
if (terrno != 0) code = terrno;
|
||||
vmSendRsp(pMsg, code);
|
||||
|
||||
dTrace("msg:%p, is freed, code:0x%x", pMsg, code);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
dTrace("msg:%p, is freed, code:0x%x", pMsg, code);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
|
||||
static void vmProcessFetchQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
||||
|
@ -87,17 +84,15 @@ static void vmProcessFetchQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
|||
if (code != 0) {
|
||||
if (terrno != 0) code = terrno;
|
||||
vmSendRsp(pMsg, code);
|
||||
|
||||
dTrace("msg:%p, is freed, code:0x%x", pMsg, code);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
dTrace("msg:%p, is freed, code:0x%x", pMsg, code);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
|
||||
static void vmProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
|
||||
SVnodeObj *pVnode = pInfo->ahandle;
|
||||
|
||||
SArray *pArray = taosArrayInit(numOfMsgs, sizeof(SRpcMsg *));
|
||||
SArray * pArray = taosArrayInit(numOfMsgs, sizeof(SRpcMsg *));
|
||||
if (pArray == NULL) {
|
||||
dError("failed to process %d msgs in write-queue since %s", numOfMsgs, terrstr());
|
||||
return;
|
||||
|
@ -116,7 +111,7 @@ static void vmProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO
|
|||
|
||||
for (int i = 0; i < taosArrayGetSize(pArray); i++) {
|
||||
SRpcMsg *pMsg = *(SRpcMsg **)taosArrayGet(pArray, i);
|
||||
SRpcMsg rsp = {.info = pMsg->info, .pCont = NULL, .contLen = 0};
|
||||
SRpcMsg rsp = {.info = pMsg->info};
|
||||
|
||||
int32_t ret = syncPropose(vnodeGetSyncHandle(pVnode->pImpl), pMsg, false);
|
||||
if (ret == TAOS_SYNC_PROPOSE_NOT_LEADER) {
|
||||
|
@ -126,12 +121,10 @@ static void vmProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO
|
|||
syncGetEpSet(vnodeGetSyncHandle(pVnode->pImpl), &newEpSet);
|
||||
newEpSet.inUse = (newEpSet.inUse + 1) % newEpSet.numOfEps;
|
||||
tmsgSendRedirectRsp(&rsp, &newEpSet);
|
||||
|
||||
} else if (ret == TAOS_SYNC_PROPOSE_OTHER_ERROR) {
|
||||
rsp.code = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||
tmsgSendRsp(&rsp);
|
||||
} else if (ret == TAOS_SYNC_PROPOSE_SUCCESS) {
|
||||
// ok
|
||||
// send response in applyQ
|
||||
} else {
|
||||
assert(0);
|
||||
|
@ -150,16 +143,13 @@ static void vmProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO
|
|||
|
||||
static void vmProcessApplyQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
|
||||
SVnodeObj *pVnode = pInfo->ahandle;
|
||||
SRpcMsg *pMsg = NULL;
|
||||
SRpcMsg rsp;
|
||||
|
||||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
||||
SRpcMsg *pMsg = NULL;
|
||||
taosGetQitem(qall, (void **)&pMsg);
|
||||
|
||||
// init response rpc msg
|
||||
rsp.code = 0;
|
||||
rsp.pCont = NULL;
|
||||
rsp.contLen = 0;
|
||||
SRpcMsg rsp = {0};
|
||||
|
||||
// get original rpc msg
|
||||
assert(pMsg->msgType == TDMT_VND_SYNC_APPLY_MSG);
|
||||
|
@ -178,7 +168,6 @@ static void vmProcessApplyQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO
|
|||
rpcFreeCont(originalRpcMsg.pCont);
|
||||
|
||||
// if leader, send response
|
||||
// if (pMsg->rpcMsg.handle != NULL && pMsg->rpcMsg.ahandle != NULL) {
|
||||
if (pMsg->info.handle != NULL) {
|
||||
rsp.info = pMsg->info;
|
||||
tmsgSendRsp(&rsp);
|
||||
|
@ -191,21 +180,19 @@ static void vmProcessApplyQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO
|
|||
|
||||
static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
|
||||
SVnodeObj *pVnode = pInfo->ahandle;
|
||||
SRpcMsg *pMsg = NULL;
|
||||
|
||||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
||||
SRpcMsg *pMsg = NULL;
|
||||
taosGetQitem(qall, (void **)&pMsg);
|
||||
|
||||
// todo
|
||||
SRpcMsg *pRsp = NULL;
|
||||
int32_t ret = vnodeProcessSyncReq(pVnode->pImpl, pMsg, &pRsp);
|
||||
if (ret != 0) {
|
||||
// if leader, send response
|
||||
int32_t code = vnodeProcessSyncReq(pVnode->pImpl, pMsg, NULL);
|
||||
if (code != 0) {
|
||||
if (pMsg->info.handle != NULL) {
|
||||
SRpcMsg rsp = {0};
|
||||
rsp.code = terrno;
|
||||
rsp.info = pMsg->info;
|
||||
dTrace("msg:%p, process sync queue error since code:%s", pMsg, terrstr());
|
||||
SRpcMsg rsp = {
|
||||
.code = (terrno < 0) ? terrno : code,
|
||||
.info = pMsg->info,
|
||||
};
|
||||
dTrace("msg:%p, failed to process sync queue since %s", pMsg, terrstr());
|
||||
tmsgSendRsp(&rsp);
|
||||
}
|
||||
}
|
||||
|
@ -217,9 +204,9 @@ static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOf
|
|||
|
||||
static void vmProcessMergeQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
|
||||
SVnodeObj *pVnode = pInfo->ahandle;
|
||||
SRpcMsg *pMsg = NULL;
|
||||
|
||||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
||||
SRpcMsg *pMsg = NULL;
|
||||
taosGetQitem(qall, (void **)&pMsg);
|
||||
|
||||
dTrace("msg:%p, get from vnode-merge queue", pMsg);
|
||||
|
@ -227,16 +214,15 @@ static void vmProcessMergeQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO
|
|||
if (code != 0) {
|
||||
if (terrno != 0) code = terrno;
|
||||
vmSendRsp(pMsg, code);
|
||||
|
||||
dTrace("msg:%p, is freed, code:0x%x", pMsg, code);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
dTrace("msg:%p, is freed, code:0x%x", pMsg, code);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t vmPutNodeMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
|
||||
SRpcMsg *pRpc = pMsg;
|
||||
SRpcMsg * pRpc = pMsg;
|
||||
SMsgHead *pHead = pRpc->pCont;
|
||||
int32_t code = 0;
|
||||
|
||||
|
@ -309,22 +295,24 @@ int32_t vmPutNodeMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
|
||||
int32_t vmPutNodeMsgToMonitorQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
SSingleWorker *pWorker = &pMgmt->monitorWorker;
|
||||
|
||||
dTrace("msg:%p, put into vnode-monitor worker, type:%s", pMsg, TMSG_INFO(pMsg->msgType));
|
||||
taosWriteQitem(pWorker->queue, pMsg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pRpc, EQueueType qtype) {
|
||||
SMsgHead *pHead = pRpc->pCont;
|
||||
|
||||
SMsgHead * pHead = pRpc->pCont;
|
||||
SVnodeObj *pVnode = vmAcquireVnode(pMgmt, pHead->vgId);
|
||||
if (pVnode == NULL) return -1;
|
||||
|
||||
SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM);
|
||||
int32_t code = 0;
|
||||
|
||||
if (pMsg != NULL) {
|
||||
if (pMsg == NULL) {
|
||||
rpcFreeCont(pRpc->pCont);
|
||||
pRpc->pCont = NULL;
|
||||
code = -1;
|
||||
} else {
|
||||
memcpy(pMsg, pRpc, sizeof(SRpcMsg));
|
||||
switch (qtype) {
|
||||
case WRITE_QUEUE:
|
||||
|
@ -429,7 +417,7 @@ int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
dDebug("vgId:%d, vnode queue is alloced", pVnode->vgId);
|
||||
dDebug("vgId:%d, queue is alloced", pVnode->vgId);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -446,7 +434,7 @@ void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
|||
pVnode->pQueryQ = NULL;
|
||||
pVnode->pFetchQ = NULL;
|
||||
pVnode->pMergeQ = NULL;
|
||||
dDebug("vgId:%d, vnode queue is freed", pVnode->vgId);
|
||||
dDebug("vgId:%d, queue is freed", pVnode->vgId);
|
||||
}
|
||||
|
||||
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
|
||||
|
@ -497,7 +485,7 @@ int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
|
|||
.param = pMgmt,
|
||||
};
|
||||
if (tSingleWorkerInit(&pMgmt->monitorWorker, &mCfg) != 0) {
|
||||
dError("failed to start mnode vnode-monitor worker since %s", terrstr());
|
||||
dError("failed to start vnode-monitor worker since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -161,10 +161,12 @@ void dmGetVnodeLoads(SMonVloadInfo *pInfo) {
|
|||
void dmGetMnodeLoads(SMonMloadInfo *pInfo) {
|
||||
SDnode *pDnode = dmInstance();
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[MNODE];
|
||||
if (tsMultiProcess) {
|
||||
dmSendLocalRecv(pDnode, TDMT_MON_MM_LOAD, tDeserializeSMonMloadInfo, pInfo);
|
||||
} else if (pWrapper->pMgmt != NULL) {
|
||||
mmGetMnodeLoads(pWrapper->pMgmt, pInfo);
|
||||
if (dmMarkWrapper(pWrapper) == 0) {
|
||||
if (tsMultiProcess) {
|
||||
dmSendLocalRecv(pDnode, TDMT_MON_MM_LOAD, tDeserializeSMonMloadInfo, pInfo);
|
||||
} else if (pWrapper->pMgmt != NULL) {
|
||||
mmGetMnodeLoads(pWrapper->pMgmt, pInfo);
|
||||
}
|
||||
dmReleaseWrapper(pWrapper);
|
||||
}
|
||||
dmReleaseWrapper(pWrapper);
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ static inline int32_t dmPushToProcQueue(SProc *proc, SProcQueue *queue, SRpcMsg
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (ftype == DND_FUNC_REQ && IsReq(pMsg) && pMsg->code == 0 && handle != 0) {
|
||||
if (ftype == DND_FUNC_REQ && IsReq(pMsg) && pMsg->code == 0 && handle != 0 && pMsg->info.noResp == 0) {
|
||||
if (taosHashPut(proc->hash, &handle, sizeof(int64_t), &pMsg->info, sizeof(SRpcConnInfo)) != 0) {
|
||||
taosThreadMutexUnlock(&queue->mutex);
|
||||
return -1;
|
||||
|
|
|
@ -49,9 +49,9 @@ int32_t dmProcessNodeMsg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
||||
SDnodeTrans *pTrans = &pDnode->trans;
|
||||
SDnodeTrans * pTrans = &pDnode->trans;
|
||||
int32_t code = -1;
|
||||
SRpcMsg *pMsg = NULL;
|
||||
SRpcMsg * pMsg = NULL;
|
||||
bool needRelease = false;
|
||||
SDnodeHandle *pHandle = &pTrans->msgHandles[TMSG_INDEX(pRpc->msgType)];
|
||||
SMgmtWrapper *pWrapper = NULL;
|
||||
|
@ -179,11 +179,11 @@ int32_t dmInitMsgHandle(SDnode *pDnode) {
|
|||
|
||||
for (EDndNodeType ntype = DNODE; ntype < NODE_END; ++ntype) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
|
||||
SArray *pArray = (*pWrapper->func.getHandlesFp)();
|
||||
SArray * pArray = (*pWrapper->func.getHandlesFp)();
|
||||
if (pArray == NULL) return -1;
|
||||
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
|
||||
SMgmtHandle *pMgmt = taosArrayGet(pArray, i);
|
||||
SMgmtHandle * pMgmt = taosArrayGet(pArray, i);
|
||||
SDnodeHandle *pHandle = &pTrans->msgHandles[TMSG_INDEX(pMgmt->msgType)];
|
||||
if (pMgmt->needCheckVgId) {
|
||||
pHandle->needCheckVgId = pMgmt->needCheckVgId;
|
||||
|
@ -200,47 +200,6 @@ int32_t dmInitMsgHandle(SDnode *pDnode) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void dmSendRpcRedirectRsp(const SRpcMsg *pMsg) {
|
||||
SDnode *pDnode = dmInstance();
|
||||
SEpSet epSet = {0};
|
||||
dmGetMnodeEpSet(&pDnode->data, &epSet);
|
||||
|
||||
dDebug("RPC %p, req is redirected, num:%d use:%d", pMsg->info.handle, epSet.numOfEps, epSet.inUse);
|
||||
for (int32_t i = 0; i < epSet.numOfEps; ++i) {
|
||||
dDebug("mnode index:%d %s:%u", i, epSet.eps[i].fqdn, epSet.eps[i].port);
|
||||
if (strcmp(epSet.eps[i].fqdn, tsLocalFqdn) == 0 && epSet.eps[i].port == tsServerPort) {
|
||||
epSet.inUse = (i + 1) % epSet.numOfEps;
|
||||
}
|
||||
|
||||
epSet.eps[i].port = htons(epSet.eps[i].port);
|
||||
}
|
||||
|
||||
SMEpSet msg = {.epSet = epSet};
|
||||
int32_t len = tSerializeSMEpSet(NULL, 0, &msg);
|
||||
|
||||
SRpcMsg rsp = {
|
||||
.code = TSDB_CODE_RPC_REDIRECT,
|
||||
.info = pMsg->info,
|
||||
.contLen = len,
|
||||
};
|
||||
rsp.pCont = rpcMallocCont(len);
|
||||
tSerializeSMEpSet(rsp.pCont, len, &msg);
|
||||
rpcSendResponse(&rsp);
|
||||
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
|
||||
static inline void dmSendRecv(SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp) {
|
||||
SDnode *pDnode = dmInstance();
|
||||
if (pDnode->status != DND_STAT_RUNNING) {
|
||||
pRsp->code = TSDB_CODE_NODE_OFFLINE;
|
||||
rpcFreeCont(pReq->pCont);
|
||||
pReq->pCont = NULL;
|
||||
} else {
|
||||
rpcSendRecv(pDnode->trans.clientRpc, pEpSet, pReq, pRsp);
|
||||
}
|
||||
}
|
||||
|
||||
static inline int32_t dmSendReq(const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||
SDnode *pDnode = dmInstance();
|
||||
if (pDnode->status != DND_STAT_RUNNING) {
|
||||
|
@ -257,39 +216,38 @@ static inline int32_t dmSendReq(const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
|||
|
||||
static inline void dmSendRsp(SRpcMsg *pMsg) {
|
||||
SMgmtWrapper *pWrapper = pMsg->info.wrapper;
|
||||
if (pMsg->code == TSDB_CODE_NODE_REDIRECT) {
|
||||
dmSendRpcRedirectRsp(pMsg);
|
||||
if (InChildProc(pWrapper)) {
|
||||
dmPutToProcPQueue(&pWrapper->proc, pMsg, DND_FUNC_RSP);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
pMsg->pCont = NULL;
|
||||
} else {
|
||||
if (InChildProc(pWrapper)) {
|
||||
dmPutToProcPQueue(&pWrapper->proc, pMsg, DND_FUNC_RSP);
|
||||
} else {
|
||||
rpcSendResponse(pMsg);
|
||||
}
|
||||
rpcSendResponse(pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void dmSendRedirectRsp(SRpcMsg *pMsg, const SEpSet *pNewEpSet) {
|
||||
SMgmtWrapper *pWrapper = pMsg->info.wrapper;
|
||||
if (InChildProc(pWrapper)) {
|
||||
dmPutToProcPQueue(&pWrapper->proc, pMsg, DND_FUNC_RSP);
|
||||
} else {
|
||||
SRpcMsg rsp = {0};
|
||||
SMEpSet msg = {.epSet = *pNewEpSet};
|
||||
int32_t len = tSerializeSMEpSet(NULL, 0, &msg);
|
||||
rsp.pCont = rpcMallocCont(len);
|
||||
rsp.contLen = len;
|
||||
tSerializeSMEpSet(rsp.pCont, len, &msg);
|
||||
SRpcMsg rsp = {.code = TSDB_CODE_RPC_REDIRECT, .info = pMsg->info};
|
||||
SMEpSet msg = {.epSet = *pNewEpSet};
|
||||
int32_t contLen = tSerializeSMEpSet(NULL, 0, &msg);
|
||||
|
||||
rsp.code = TSDB_CODE_RPC_REDIRECT;
|
||||
rsp.info = pMsg->info;
|
||||
rpcSendResponse(&rsp);
|
||||
rsp.pCont = rpcMallocCont(contLen);
|
||||
if (rsp.pCont == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
} else {
|
||||
tSerializeSMEpSet(rsp.pCont, contLen, &msg);
|
||||
rsp.contLen = contLen;
|
||||
}
|
||||
dmSendRsp(&rsp);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
pMsg->pCont = NULL;
|
||||
}
|
||||
|
||||
static inline void dmRegisterBrokenLinkArg(SRpcMsg *pMsg) {
|
||||
SMgmtWrapper *pWrapper = pMsg->info.wrapper;
|
||||
if (InChildProc(pWrapper)) {
|
||||
dmPutToProcPQueue(&pWrapper->proc, pMsg, DND_FUNC_REGIST);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
pMsg->pCont = NULL;
|
||||
} else {
|
||||
rpcRegisterBrokenLinkArg(pMsg);
|
||||
}
|
||||
|
@ -318,15 +276,9 @@ int32_t dmInitClient(SDnode *pDnode) {
|
|||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
rpcInit.idleTime = tsShellActivityTimer * 1000;
|
||||
rpcInit.user = INTERNAL_USER;
|
||||
rpcInit.ckey = INTERNAL_CKEY;
|
||||
rpcInit.spi = 1;
|
||||
rpcInit.parent = pDnode;
|
||||
rpcInit.rfp = rpcRfp;
|
||||
|
||||
char pass[TSDB_PASSWORD_LEN + 1] = {0};
|
||||
taosEncryptPass_c((uint8_t *)(INTERNAL_SECRET), strlen(INTERNAL_SECRET), pass);
|
||||
rpcInit.secret = pass;
|
||||
|
||||
pTrans->clientRpc = rpcOpen(&rpcInit);
|
||||
if (pTrans->clientRpc == NULL) {
|
||||
dError("failed to init dnode rpc client");
|
||||
|
@ -391,3 +343,34 @@ SMsgCb dmGetMsgcb(SDnode *pDnode) {
|
|||
};
|
||||
return msgCb;
|
||||
}
|
||||
|
||||
static void dmSendMnodeRedirectRsp(SRpcMsg *pMsg) {
|
||||
SDnode *pDnode = dmInstance();
|
||||
SEpSet epSet = {0};
|
||||
dmGetMnodeEpSet(&pDnode->data, &epSet);
|
||||
|
||||
dDebug("msg:%p, is redirected, num:%d use:%d", pMsg, epSet.numOfEps, epSet.inUse);
|
||||
for (int32_t i = 0; i < epSet.numOfEps; ++i) {
|
||||
dDebug("mnode index:%d %s:%u", i, epSet.eps[i].fqdn, epSet.eps[i].port);
|
||||
if (strcmp(epSet.eps[i].fqdn, tsLocalFqdn) == 0 && epSet.eps[i].port == tsServerPort) {
|
||||
epSet.inUse = (i + 1) % epSet.numOfEps;
|
||||
}
|
||||
|
||||
epSet.eps[i].port = htons(epSet.eps[i].port);
|
||||
}
|
||||
|
||||
SRpcMsg rsp = {.code = TSDB_CODE_RPC_REDIRECT, .info = pMsg->info};
|
||||
SMEpSet msg = {.epSet = epSet};
|
||||
int32_t contLen = tSerializeSMEpSet(NULL, 0, &msg);
|
||||
rsp.pCont = rpcMallocCont(contLen);
|
||||
if (rsp.pCont == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
} else {
|
||||
tSerializeSMEpSet(rsp.pCont, contLen, &msg);
|
||||
rsp.contLen = contLen;
|
||||
}
|
||||
|
||||
dmSendRsp(&rsp);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
pMsg->pCont = NULL;
|
||||
}
|
||||
|
|
|
@ -48,10 +48,10 @@ void TestClient::DoInit() {
|
|||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
rpcInit.idleTime = 30 * 1000;
|
||||
rpcInit.user = (char*)this->user;
|
||||
rpcInit.ckey = (char*)"key";
|
||||
// rpcInit.ckey = (char*)"key";
|
||||
rpcInit.parent = this;
|
||||
rpcInit.secret = (char*)secretEncrypt;
|
||||
rpcInit.spi = 1;
|
||||
// rpcInit.secret = (char*)secretEncrypt;
|
||||
// rpcInit.spi = 1;
|
||||
|
||||
clientRpc = rpcOpen(&rpcInit);
|
||||
ASSERT(clientRpc);
|
||||
|
|
|
@ -45,20 +45,20 @@ typedef struct SVnodeCfg SVnodeCfg;
|
|||
|
||||
extern const SVnodeCfg vnodeCfgDefault;
|
||||
|
||||
int vnodeInit(int nthreads);
|
||||
int32_t vnodeInit(int32_t nthreads);
|
||||
void vnodeCleanup();
|
||||
int vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs);
|
||||
int32_t vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs);
|
||||
void vnodeDestroy(const char *path, STfs *pTfs);
|
||||
SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb);
|
||||
void vnodeClose(SVnode *pVnode);
|
||||
int vnodePreprocessWriteReqs(SVnode *pVnode, SArray *pMsgs, int64_t *version);
|
||||
int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg *pRsp);
|
||||
int vnodeProcessCMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
||||
int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
||||
int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg);
|
||||
int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo);
|
||||
int32_t vnodePreprocessWriteReqs(SVnode *pVnode, SArray *pMsgs, int64_t *version);
|
||||
int32_t vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg *pRsp);
|
||||
int32_t vnodeProcessCMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
||||
int32_t vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
||||
int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg);
|
||||
int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo);
|
||||
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad);
|
||||
int vnodeValidateTableHash(SVnode *pVnode, char *tableFName);
|
||||
int32_t vnodeValidateTableHash(SVnode *pVnode, char *tableFName);
|
||||
|
||||
int32_t vnodeStart(SVnode *pVnode);
|
||||
void vnodeStop(SVnode *pVnode);
|
||||
|
@ -74,8 +74,8 @@ typedef struct SMetaEntry SMetaEntry;
|
|||
|
||||
void metaReaderInit(SMetaReader *pReader, SMeta *pMeta, int32_t flags);
|
||||
void metaReaderClear(SMetaReader *pReader);
|
||||
int metaGetTableEntryByUid(SMetaReader *pReader, tb_uid_t uid);
|
||||
int metaReadNext(SMetaReader *pReader);
|
||||
int32_t metaGetTableEntryByUid(SMetaReader *pReader, tb_uid_t uid);
|
||||
int32_t metaReadNext(SMetaReader *pReader);
|
||||
const void *metaGetTableTagVal(SMetaEntry *pEntry, int16_t cid);
|
||||
|
||||
#if 1 // refact APIs below (TODO)
|
||||
|
@ -86,7 +86,7 @@ typedef struct SMTbCursor SMTbCursor;
|
|||
|
||||
SMTbCursor *metaOpenTbCursor(SMeta *pMeta);
|
||||
void metaCloseTbCursor(SMTbCursor *pTbCur);
|
||||
int metaTbCursorNext(SMTbCursor *pTbCur);
|
||||
int32_t metaTbCursorNext(SMTbCursor *pTbCur);
|
||||
#endif
|
||||
|
||||
// tsdb
|
||||
|
@ -124,8 +124,10 @@ typedef struct STqReadHandle STqReadHandle;
|
|||
STqReadHandle *tqInitSubmitMsgScanner(SMeta *pMeta);
|
||||
|
||||
void tqReadHandleSetColIdList(STqReadHandle *pReadHandle, SArray *pColIdList);
|
||||
int tqReadHandleSetTbUidList(STqReadHandle *pHandle, const SArray *tbUidList);
|
||||
int tqReadHandleAddTbUidList(STqReadHandle *pHandle, const SArray *tbUidList);
|
||||
int32_t tqReadHandleSetTbUidList(STqReadHandle *pHandle, const SArray *tbUidList);
|
||||
int32_t tqReadHandleAddTbUidList(STqReadHandle *pHandle, const SArray *tbUidList);
|
||||
int32_t tqReadHandleRemoveTbUidList(STqReadHandle* pHandle, const SArray* tbUidList);
|
||||
|
||||
int32_t tqReadHandleSetMsg(STqReadHandle *pHandle, SSubmitReq *pMsg, int64_t ver);
|
||||
bool tqNextDataBlock(STqReadHandle *pHandle);
|
||||
bool tqNextDataBlockFilterOut(STqReadHandle *pHandle, SHashObj *filterOutUids);
|
||||
|
@ -207,15 +209,15 @@ struct SMetaReader {
|
|||
SDecoder coder;
|
||||
SMetaEntry me;
|
||||
void *pBuf;
|
||||
int szBuf;
|
||||
int32_t szBuf;
|
||||
};
|
||||
|
||||
struct SMTbCursor {
|
||||
TBC *pDbc;
|
||||
void *pKey;
|
||||
void *pVal;
|
||||
int kLen;
|
||||
int vLen;
|
||||
int32_t kLen;
|
||||
int32_t vLen;
|
||||
SMetaReader mr;
|
||||
};
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
// vnodeDebug ====================
|
||||
// clang-format off
|
||||
#define vFatal(...) do { if (vDebugFlag & DEBUG_FATAL) { taosPrintLog("VND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0)
|
||||
#define vError(...) do { if (vDebugFlag & DEBUG_ERROR) { taosPrintLog("VND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0)
|
||||
|
@ -34,17 +33,17 @@ extern "C" {
|
|||
#define vTrace(...) do { if (vDebugFlag & DEBUG_TRACE) { taosPrintLog("VND ", DEBUG_TRACE, vDebugFlag, __VA_ARGS__); }} while(0)
|
||||
// clang-format on
|
||||
|
||||
// vnodeCfg ====================
|
||||
// vnodeCfg.c
|
||||
extern const SVnodeCfg vnodeCfgDefault;
|
||||
|
||||
int vnodeCheckCfg(const SVnodeCfg*);
|
||||
int vnodeEncodeConfig(const void* pObj, SJson* pJson);
|
||||
int vnodeDecodeConfig(const SJson* pJson, void* pObj);
|
||||
int32_t vnodeCheckCfg(const SVnodeCfg*);
|
||||
int32_t vnodeEncodeConfig(const void* pObj, SJson* pJson);
|
||||
int32_t vnodeDecodeConfig(const SJson* pJson, void* pObj);
|
||||
|
||||
// vnodeModule ====================
|
||||
int vnodeScheduleTask(int (*execute)(void*), void* arg);
|
||||
// vnodeModule.c
|
||||
int32_t vnodeScheduleTask(int32_t (*execute)(void*), void* arg);
|
||||
|
||||
// vnodeBufPool ====================
|
||||
// vnodeBufPool.c
|
||||
typedef struct SVBufPoolNode SVBufPoolNode;
|
||||
struct SVBufPoolNode {
|
||||
SVBufPoolNode* prev;
|
||||
|
@ -62,38 +61,29 @@ struct SVBufPool {
|
|||
SVBufPoolNode node;
|
||||
};
|
||||
|
||||
int vnodeOpenBufPool(SVnode* pVnode, int64_t size);
|
||||
int vnodeCloseBufPool(SVnode* pVnode);
|
||||
void vnodeBufPoolReset(SVBufPool* pPool);
|
||||
int32_t vnodeOpenBufPool(SVnode* pVnode, int64_t size);
|
||||
int32_t vnodeCloseBufPool(SVnode* pVnode);
|
||||
void vnodeBufPoolReset(SVBufPool* pPool);
|
||||
|
||||
// vnodeQuery ====================
|
||||
int vnodeQueryOpen(SVnode* pVnode);
|
||||
void vnodeQueryClose(SVnode* pVnode);
|
||||
int vnodeGetTableMeta(SVnode* pVnode, SRpcMsg* pMsg);
|
||||
// vnodeQuery.c
|
||||
int32_t vnodeQueryOpen(SVnode* pVnode);
|
||||
void vnodeQueryClose(SVnode* pVnode);
|
||||
int32_t vnodeGetTableMeta(SVnode* pVnode, SRpcMsg* pMsg);
|
||||
|
||||
// vnodeCommit ====================
|
||||
int vnodeBegin(SVnode* pVnode);
|
||||
int vnodeShouldCommit(SVnode* pVnode);
|
||||
int vnodeCommit(SVnode* pVnode);
|
||||
int vnodeSaveInfo(const char* dir, const SVnodeInfo* pCfg);
|
||||
int vnodeCommitInfo(const char* dir, const SVnodeInfo* pInfo);
|
||||
int vnodeLoadInfo(const char* dir, SVnodeInfo* pInfo);
|
||||
int vnodeSyncCommit(SVnode* pVnode);
|
||||
int vnodeAsyncCommit(SVnode* pVnode);
|
||||
// vnodeCommit.c
|
||||
int32_t vnodeBegin(SVnode* pVnode);
|
||||
int32_t vnodeShouldCommit(SVnode* pVnode);
|
||||
int32_t vnodeCommit(SVnode* pVnode);
|
||||
int32_t vnodeSaveInfo(const char* dir, const SVnodeInfo* pCfg);
|
||||
int32_t vnodeCommitInfo(const char* dir, const SVnodeInfo* pInfo);
|
||||
int32_t vnodeLoadInfo(const char* dir, SVnodeInfo* pInfo);
|
||||
int32_t vnodeSyncCommit(SVnode* pVnode);
|
||||
int32_t vnodeAsyncCommit(SVnode* pVnode);
|
||||
|
||||
// vnodeCommit ====================
|
||||
// vnodeSync.c
|
||||
int32_t vnodeSyncOpen(SVnode* pVnode, char* path);
|
||||
int32_t vnodeSyncStart(SVnode* pVnode);
|
||||
void vnodeSyncStart(SVnode* pVnode);
|
||||
void vnodeSyncClose(SVnode* pVnode);
|
||||
void vnodeSyncSetQ(SVnode* pVnode, void* qHandle);
|
||||
void vnodeSyncSetRpc(SVnode* pVnode, void* rpcHandle);
|
||||
int32_t vnodeSyncEqMsg(void* qHandle, SRpcMsg* pMsg);
|
||||
int32_t vnodeSendMsg(void* rpcHandle, const SEpSet* pEpSet, SRpcMsg* pMsg);
|
||||
void vnodeSyncCommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta);
|
||||
void vnodeSyncPreCommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta);
|
||||
void vnodeSyncRollBackCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta);
|
||||
int32_t vnodeSyncGetSnapshotCb(struct SSyncFSM* pFsm, SSnapshot* pSnapshot);
|
||||
SSyncFSM* syncVnodeMakeFsm();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -121,10 +121,18 @@ int tqCommit(STQ*);
|
|||
int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd);
|
||||
int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen);
|
||||
int32_t tqProcessVgDeleteReq(STQ* pTq, char* msg, int32_t msgLen);
|
||||
int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen, int32_t workerId);
|
||||
int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen);
|
||||
int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen, int32_t workerId);
|
||||
int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId);
|
||||
int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen);
|
||||
#if 0
|
||||
int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen, int32_t workerId);
|
||||
int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen, int32_t workerId);
|
||||
#endif
|
||||
int32_t tqProcessStreamTriggerNew(STQ* pTq, SSubmitReq* data);
|
||||
int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg);
|
||||
int32_t tqProcessTaskDispatchReq(STQ* pTq, SRpcMsg* pMsg);
|
||||
int32_t tqProcessTaskRecoverReq(STQ* pTq, SRpcMsg* pMsg);
|
||||
int32_t tqProcessTaskDispatchRsp(STQ* pTq, SRpcMsg* pMsg);
|
||||
int32_t tqProcessTaskRecoverRsp(STQ* pTq, SRpcMsg* pMsg);
|
||||
|
||||
// sma
|
||||
int32_t smaOpen(SVnode* pVnode);
|
||||
|
|
|
@ -56,8 +56,8 @@ int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) {
|
|||
if (tDecodeCStr(pCoder, &pME->name) < 0) return -1;
|
||||
|
||||
if (pME->type == TSDB_SUPER_TABLE) {
|
||||
if (tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schema) < 0) return -1;
|
||||
if (tDecodeSSchemaWrapperEx(pCoder, &pME->stbEntry.schemaTag) < 0) return -1;
|
||||
if (tDecodeSSchemaWrapper(pCoder, &pME->stbEntry.schema) < 0) return -1;
|
||||
if (tDecodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag) < 0) return -1;
|
||||
} else if (pME->type == TSDB_CHILD_TABLE) {
|
||||
if (tDecodeI64(pCoder, &pME->ctbEntry.ctime) < 0) return -1;
|
||||
if (tDecodeI32(pCoder, &pME->ctbEntry.ttlDays) < 0) return -1;
|
||||
|
@ -67,10 +67,10 @@ int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) {
|
|||
if (tDecodeI64(pCoder, &pME->ntbEntry.ctime) < 0) return -1;
|
||||
if (tDecodeI32(pCoder, &pME->ntbEntry.ttlDays) < 0) return -1;
|
||||
if (tDecodeI32v(pCoder, &pME->ntbEntry.ncid) < 0) return -1;
|
||||
if (tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schema) < 0) return -1;
|
||||
if (tDecodeSSchemaWrapper(pCoder, &pME->ntbEntry.schema) < 0) return -1;
|
||||
} else if (pME->type == TSDB_TSMA_TABLE) {
|
||||
pME->smaEntry.tsma = tDecoderMalloc(pCoder, sizeof(STSma));
|
||||
if(!pME->smaEntry.tsma) {
|
||||
if (!pME->smaEntry.tsma) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -105,32 +105,30 @@ static void tdSRowDemo() {
|
|||
}
|
||||
|
||||
int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd) {
|
||||
void* pIter = NULL;
|
||||
STqExec* pExec = NULL;
|
||||
void* pIter = NULL;
|
||||
while (1) {
|
||||
pIter = taosHashIterate(pTq->execs, pIter);
|
||||
if (pIter == NULL) break;
|
||||
pExec = (STqExec*)pIter;
|
||||
STqExec* pExec = (STqExec*)pIter;
|
||||
if (pExec->subType == TOPIC_SUB_TYPE__DB) {
|
||||
if (isAdd) {
|
||||
continue;
|
||||
} else {
|
||||
if (!isAdd) {
|
||||
int32_t sz = taosArrayGetSize(tbUidList);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
int64_t tbUid = *(int64_t*)taosArrayGet(tbUidList, i);
|
||||
taosHashPut(pExec->pDropTbUid, &tbUid, sizeof(int64_t), NULL, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int32_t i = 0; i < 5; i++) {
|
||||
int32_t code = qUpdateQualifiedTableId(pExec->task[i], tbUidList, isAdd);
|
||||
ASSERT(code == 0);
|
||||
} else {
|
||||
for (int32_t i = 0; i < 5; i++) {
|
||||
int32_t code = qUpdateQualifiedTableId(pExec->task[i], tbUidList, isAdd);
|
||||
ASSERT(code == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqPushMsgNew(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver) {
|
||||
int32_t tqPushMsgNew(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver, SRpcHandleInfo handleInfo) {
|
||||
if (msgType != TDMT_VND_SUBMIT) return 0;
|
||||
void* pIter = NULL;
|
||||
STqExec* pExec = NULL;
|
||||
|
@ -240,10 +238,9 @@ int32_t tqPushMsgNew(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_
|
|||
|
||||
void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
|
||||
tEncodeSMqDataBlkRsp(&abuf, &rsp);
|
||||
pMsg->pCont = buf;
|
||||
pMsg->contLen = tlen;
|
||||
pMsg->code = 0;
|
||||
tmsgSendRsp(pMsg);
|
||||
|
||||
SRpcMsg resp = {.info = handleInfo, .pCont = buf, .contLen = tlen, .code = 0};
|
||||
tmsgSendRsp(&resp);
|
||||
|
||||
atomic_store_ptr(&pExec->pushHandle.handle, NULL);
|
||||
taosWUnLockLatch(&pExec->pushHandle.lock);
|
||||
|
@ -276,6 +273,9 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver)
|
|||
}
|
||||
memcpy(data, msg, msgLen);
|
||||
|
||||
tqProcessStreamTriggerNew(pTq, data);
|
||||
|
||||
#if 0
|
||||
SRpcMsg req = {
|
||||
.msgType = TDMT_VND_STREAM_TRIGGER,
|
||||
.pCont = data,
|
||||
|
@ -283,6 +283,7 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver)
|
|||
};
|
||||
|
||||
tmsgPutToQueue(&pTq->pVnode->msgCb, FETCH_QUEUE, &req);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -408,9 +409,9 @@ int32_t tqDeserializeConsumer(STQ* pTq, const STqSerializedHead* pHead, STqConsu
|
|||
pTopic->buffer.output[j].status = 0;
|
||||
STqReadHandle* pReadHandle = tqInitSubmitMsgScanner(pTq->pVnode->pMeta);
|
||||
SReadHandle handle = {
|
||||
.reader = pReadHandle,
|
||||
.meta = pTq->pVnode->pMeta,
|
||||
.pMsgCb = &pTq->pVnode->msgCb,
|
||||
.reader = pReadHandle,
|
||||
.meta = pTq->pVnode->pMeta,
|
||||
.pMsgCb = &pTq->pVnode->msgCb,
|
||||
};
|
||||
pTopic->buffer.output[j].pReadHandle = pReadHandle;
|
||||
pTopic->buffer.output[j].task = qCreateStreamExecTaskInfo(pTopic->qmsg, &handle);
|
||||
|
@ -664,10 +665,9 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
|
||||
void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
|
||||
tEncodeSMqDataBlkRsp(&abuf, &rsp);
|
||||
pMsg->pCont = buf;
|
||||
pMsg->contLen = tlen;
|
||||
pMsg->code = 0;
|
||||
tmsgSendRsp(pMsg);
|
||||
|
||||
SRpcMsg resp = {.info = pMsg->info, .pCont = buf, .contLen = tlen, .code = 0};
|
||||
tmsgSendRsp(&resp);
|
||||
|
||||
tqDebug("vg %d offset %ld from consumer %ld (epoch %d) send rsp, block num: %d, reqOffset: %ld, rspOffset: %ld",
|
||||
TD_VID(pTq->pVnode), fetchOffset, consumerId, pReq->epoch, rsp.blockNum, rsp.reqOffset, rsp.rspOffset);
|
||||
|
@ -846,12 +846,10 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
/*rsp.pBlockData = pRes;*/
|
||||
|
||||
/*taosArrayDestroyEx(rsp.pBlockData, (void (*)(void*))tDeleteSSDataBlock);*/
|
||||
pMsg->pCont = buf;
|
||||
pMsg->contLen = msgLen;
|
||||
pMsg->code = 0;
|
||||
SRpcMsg resp = {.info = pMsg->info, pCont = buf, .contLen = msgLen, .code = 0};
|
||||
tqDebug("vg %d offset %ld msgType %d from consumer %ld (epoch %d) actual rsp", TD_VID(pTq->pVnode), fetchOffset,
|
||||
pHead->msgType, consumerId, pReq->epoch);
|
||||
tmsgSendRsp(pMsg);
|
||||
tmsgSendRsp(&resp);
|
||||
taosMemoryFree(pHead);
|
||||
return 0;
|
||||
} else {
|
||||
|
@ -879,10 +877,9 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
|
||||
void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
|
||||
tEncodeSMqPollRspV2(&abuf, &rspV2);
|
||||
pMsg->pCont = buf;
|
||||
pMsg->contLen = tlen;
|
||||
pMsg->code = 0;
|
||||
tmsgSendRsp(pMsg);
|
||||
|
||||
SRpcMsg resp = {.info = pMsg->info, .pCont = buf, .contLen = tlen, .code = 0};
|
||||
tmsgSendRsp(&resp);
|
||||
tqDebug("vg %d offset %ld from consumer %ld (epoch %d) not rsp", TD_VID(pTq->pVnode), fetchOffset, consumerId,
|
||||
pReq->epoch);
|
||||
/*}*/
|
||||
|
@ -981,20 +978,32 @@ void tqTableSink(SStreamTask* pTask, void* vnode, int64_t ver, void* data) {
|
|||
}
|
||||
|
||||
int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int32_t parallel) {
|
||||
pTask->status = TASK_STATUS__IDLE;
|
||||
pTask->inputStatus = TASK_INPUT_STATUS__NORMAL;
|
||||
pTask->outputStatus = TASK_OUTPUT_STATUS__NORMAL;
|
||||
|
||||
pTask->inputQ = taosOpenQueue();
|
||||
pTask->outputQ = taosOpenQueue();
|
||||
pTask->inputQAll = taosAllocateQall();
|
||||
pTask->outputQAll = taosAllocateQall();
|
||||
|
||||
if (pTask->inputQ == NULL || pTask->outputQ == NULL || pTask->inputQAll == NULL || pTask->outputQAll == NULL)
|
||||
goto FAIL;
|
||||
|
||||
if (pTask->execType != TASK_EXEC__NONE) {
|
||||
// expand runners
|
||||
pTask->exec.numOfRunners = parallel;
|
||||
pTask->exec.runners = taosMemoryCalloc(parallel, sizeof(SStreamRunner));
|
||||
if (pTask->exec.runners == NULL) {
|
||||
return -1;
|
||||
goto FAIL;
|
||||
}
|
||||
for (int32_t i = 0; i < parallel; i++) {
|
||||
STqReadHandle* pStreamReader = tqInitSubmitMsgScanner(pTq->pVnode->pMeta);
|
||||
SReadHandle handle = {
|
||||
.reader = pStreamReader,
|
||||
.meta = pTq->pVnode->pMeta,
|
||||
.pMsgCb = &pTq->pVnode->msgCb,
|
||||
.vnode = pTq->pVnode,
|
||||
.reader = pStreamReader,
|
||||
.meta = pTq->pVnode->pMeta,
|
||||
.pMsgCb = &pTq->pVnode->msgCb,
|
||||
.vnode = pTq->pVnode,
|
||||
};
|
||||
pTask->exec.runners[i].inputHandle = pStreamReader;
|
||||
pTask->exec.runners[i].executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, &handle);
|
||||
|
@ -1008,6 +1017,13 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int32_t parallel) {
|
|||
}
|
||||
|
||||
return 0;
|
||||
FAIL:
|
||||
if (pTask->inputQ) taosCloseQueue(pTask->inputQ);
|
||||
if (pTask->outputQ) taosCloseQueue(pTask->outputQ);
|
||||
if (pTask->inputQAll) taosFreeQall(pTask->inputQAll);
|
||||
if (pTask->outputQAll) taosFreeQall(pTask->outputQAll);
|
||||
if (pTask) taosMemoryFree(pTask);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) {
|
||||
|
@ -1059,6 +1075,59 @@ int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen, int32_t wo
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int32_t tqProcessStreamTriggerNew(STQ* pTq, SSubmitReq* data) {
|
||||
SStreamDataSubmit* pSubmit = NULL;
|
||||
|
||||
// build data
|
||||
pSubmit = taosAllocateQitem(sizeof(SStreamDataSubmit), DEF_QITEM);
|
||||
if (pSubmit == NULL) return -1;
|
||||
pSubmit->dataRef = taosMemoryMalloc(sizeof(int32_t));
|
||||
if (pSubmit->dataRef == NULL) goto FAIL;
|
||||
*pSubmit->dataRef = 1;
|
||||
pSubmit->data = data;
|
||||
pSubmit->type = STREAM_INPUT__DATA_BLOCK;
|
||||
|
||||
void* pIter = NULL;
|
||||
while (1) {
|
||||
pIter = taosHashIterate(pTq->pStreamTasks, pIter);
|
||||
if (pIter == NULL) break;
|
||||
SStreamTask* pTask = (SStreamTask*)pIter;
|
||||
if (pTask->inputType == TASK_INPUT_TYPE__SUMBIT_BLOCK) {
|
||||
streamEnqueueDataSubmit(pTask, pSubmit);
|
||||
// TODO cal back pressure
|
||||
}
|
||||
// check run
|
||||
int8_t execStatus = atomic_load_8(&pTask->status);
|
||||
if (execStatus == TASK_STATUS__IDLE || execStatus == TASK_STATUS__CLOSING) {
|
||||
SStreamTaskRunReq* pReq = taosMemoryMalloc(sizeof(SStreamTaskRunReq));
|
||||
if (pReq == NULL) continue;
|
||||
// TODO: do we need htonl?
|
||||
pReq->head.vgId = pTq->pVnode->config.vgId;
|
||||
pReq->streamId = pTask->streamId;
|
||||
pReq->taskId = pTask->taskId;
|
||||
SRpcMsg msg = {
|
||||
.msgType = 0,
|
||||
.pCont = pReq,
|
||||
.contLen = sizeof(SStreamTaskRunReq),
|
||||
};
|
||||
tmsgPutToQueue(&pTq->pVnode->msgCb, FETCH_QUEUE, &msg);
|
||||
}
|
||||
}
|
||||
streamDataSubmitRefDec(pSubmit);
|
||||
|
||||
return 0;
|
||||
FAIL:
|
||||
if (pSubmit) {
|
||||
if (pSubmit->dataRef) {
|
||||
taosMemoryFree(pSubmit->dataRef);
|
||||
}
|
||||
taosFreeQitem(pSubmit);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen, int32_t workerId) {
|
||||
SStreamTaskExecReq req;
|
||||
tDecodeSStreamTaskExecReq(msg, &req);
|
||||
|
@ -1075,25 +1144,28 @@ int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen, int32_t workerId)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqProcessStreamTrigger2(STQ* pTq, SSubmitReq* pReq, int64_t ver) {
|
||||
int32_t tqProcessStreamTriggerNew(STQ* pTq, SSubmitReq* pReq) {
|
||||
void* pIter = NULL;
|
||||
bool failed = false;
|
||||
|
||||
SStreamDataSubmit* pSubmit = taosAllocateQitem(sizeof(SStreamDataSubmit), DEF_QITEM);
|
||||
if (pSubmit == NULL) {
|
||||
failed = true;
|
||||
goto SET_TASK_FAIL;
|
||||
}
|
||||
pSubmit->dataRef = taosMemoryMalloc(sizeof(int32_t));
|
||||
if (pSubmit->dataRef == NULL) {
|
||||
failed = true;
|
||||
goto SET_TASK_FAIL;
|
||||
}
|
||||
|
||||
pSubmit->type = STREAM_DATA_TYPE_SUBMIT_BLOCK;
|
||||
pSubmit->sourceVer = ver;
|
||||
pSubmit->sourceVg = pTq->pVnode->config.vgId;
|
||||
pSubmit->type = STREAM_INPUT__DATA_SUBMIT;
|
||||
/*pSubmit->sourceVer = ver;*/
|
||||
/*pSubmit->sourceVg = pTq->pVnode->config.vgId;*/
|
||||
pSubmit->data = pReq;
|
||||
*pSubmit->dataRef = 1;
|
||||
|
||||
SET_TASK_FAIL:
|
||||
while (1) {
|
||||
pIter = taosHashIterate(pTq->pStreamTasks, pIter);
|
||||
if (pIter == NULL) break;
|
||||
|
@ -1112,7 +1184,18 @@ int32_t tqProcessStreamTrigger2(STQ* pTq, SSubmitReq* pReq, int64_t ver) {
|
|||
|
||||
int8_t execStatus = atomic_load_8(&pTask->status);
|
||||
if (execStatus == TASK_STATUS__IDLE || execStatus == TASK_STATUS__CLOSING) {
|
||||
// TODO dispatch task launch msg to fetch queue
|
||||
SStreamTaskRunReq* pRunReq = taosMemoryMalloc(sizeof(SStreamTaskRunReq));
|
||||
if (pRunReq == NULL) continue;
|
||||
// TODO: do we need htonl?
|
||||
pRunReq->head.vgId = pTq->pVnode->config.vgId;
|
||||
pRunReq->streamId = pTask->streamId;
|
||||
pRunReq->taskId = pTask->taskId;
|
||||
SRpcMsg msg = {
|
||||
.msgType = TDMT_VND_TASK_RUN,
|
||||
.pCont = pRunReq,
|
||||
.contLen = sizeof(SStreamTaskRunReq),
|
||||
};
|
||||
tmsgPutToQueue(&pTq->pVnode->msgCb, FETCH_QUEUE, &msg);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -1124,11 +1207,53 @@ int32_t tqProcessStreamTrigger2(STQ* pTq, SSubmitReq* pReq, int64_t ver) {
|
|||
streamDataSubmitRefDec(pSubmit);
|
||||
return 0;
|
||||
} else {
|
||||
if (pSubmit) {
|
||||
if (pSubmit->dataRef) {
|
||||
taosMemoryFree(pSubmit->dataRef);
|
||||
}
|
||||
taosFreeQitem(pSubmit);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t tqProcessTaskExec2(STQ* pTq, char* msg, int32_t msgLen) {
|
||||
int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg) {
|
||||
//
|
||||
SStreamTaskRunReq* pReq = pMsg->pCont;
|
||||
int32_t taskId = pReq->taskId;
|
||||
SStreamTask* pTask = taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t));
|
||||
streamTaskProcessRunReq(pTask, &pTq->pVnode->msgCb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqProcessTaskDispatchReq(STQ* pTq, SRpcMsg* pMsg) {
|
||||
SStreamDispatchReq* pReq = pMsg->pCont;
|
||||
int32_t taskId = pReq->taskId;
|
||||
SStreamTask* pTask = taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t));
|
||||
streamTaskProcessDispatchReq(pTask, &pTq->pVnode->msgCb, pReq, pMsg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqProcessTaskRecoverReq(STQ* pTq, SRpcMsg* pMsg) {
|
||||
SStreamTaskRecoverReq* pReq = pMsg->pCont;
|
||||
int32_t taskId = pReq->taskId;
|
||||
SStreamTask* pTask = taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t));
|
||||
streamTaskProcessRecoverReq(pTask, &pTq->pVnode->msgCb, pReq, pMsg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqProcessTaskDispatchRsp(STQ* pTq, SRpcMsg* pMsg) {
|
||||
SStreamDispatchRsp* pRsp = pMsg->pCont;
|
||||
int32_t taskId = pRsp->taskId;
|
||||
SStreamTask* pTask = taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t));
|
||||
streamTaskProcessDispatchRsp(pTask, &pTq->pVnode->msgCb, pRsp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqProcessTaskRecoverRsp(STQ* pTq, SRpcMsg* pMsg) {
|
||||
SStreamTaskRecoverRsp* pRsp = pMsg->pCont;
|
||||
int32_t taskId = pRsp->taskId;
|
||||
SStreamTask* pTask = taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t));
|
||||
streamTaskProcessRecoverRsp(pTask, pRsp);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -34,21 +34,11 @@ STqReadHandle* tqInitSubmitMsgScanner(SMeta* pMeta) {
|
|||
|
||||
int32_t tqReadHandleSetMsg(STqReadHandle* pReadHandle, SSubmitReq* pMsg, int64_t ver) {
|
||||
pReadHandle->pMsg = pMsg;
|
||||
// pMsg->length = htonl(pMsg->length);
|
||||
// pMsg->numOfBlocks = htonl(pMsg->numOfBlocks);
|
||||
|
||||
// iterate and convert
|
||||
if (tInitSubmitMsgIter(pMsg, &pReadHandle->msgIter) < 0) return -1;
|
||||
while (true) {
|
||||
if (tGetSubmitMsgNext(&pReadHandle->msgIter, &pReadHandle->pBlock) < 0) return -1;
|
||||
if (pReadHandle->pBlock == NULL) break;
|
||||
|
||||
// pReadHandle->pBlock->uid = htobe64(pReadHandle->pBlock->uid);
|
||||
// pReadHandle->pBlock->suid = htobe64(pReadHandle->pBlock->suid);
|
||||
// pReadHandle->pBlock->sversion = htonl(pReadHandle->pBlock->sversion);
|
||||
// pReadHandle->pBlock->dataLen = htonl(pReadHandle->pBlock->dataLen);
|
||||
// pReadHandle->pBlock->schemaLen = htonl(pReadHandle->pBlock->schemaLen);
|
||||
// pReadHandle->pBlock->numOfRows = htons(pReadHandle->pBlock->numOfRows);
|
||||
}
|
||||
|
||||
if (tInitSubmitMsgIter(pMsg, &pReadHandle->msgIter) < 0) return -1;
|
||||
|
@ -241,3 +231,14 @@ int tqReadHandleAddTbUidList(STqReadHandle* pHandle, const SArray* tbUidList) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tqReadHandleRemoveTbUidList(STqReadHandle* pHandle, const SArray* tbUidList) {
|
||||
ASSERT(pHandle->tbIdHash != NULL);
|
||||
|
||||
for(int32_t i = 0; i < taosArrayGetSize(tbUidList); i++) {
|
||||
int64_t* pKey = (int64_t*) taosArrayGet(tbUidList, i);
|
||||
taosHashRemove(pHandle->tbIdHash, pKey, sizeof(int64_t));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -425,6 +425,12 @@ static STsdbReadHandle* tsdbQueryTablesImpl(SVnode* pVnode, SQueryTableDataCond*
|
|||
rowLen += pCond->colList[i].bytes;
|
||||
}
|
||||
|
||||
// make sure the output SSDataBlock size be less than 2MB.
|
||||
int32_t TWOMB = 2 * 1024 * 1024;
|
||||
if (pReadHandle->outputCapacity * rowLen > TWOMB) {
|
||||
pReadHandle->outputCapacity = TWOMB / rowLen;
|
||||
}
|
||||
|
||||
// allocate buffer in order to load data blocks from file
|
||||
pReadHandle->suppInfo.pstatis = taosMemoryCalloc(pCond->numOfCols, sizeof(SColumnDataAgg));
|
||||
if (pReadHandle->suppInfo.pstatis == NULL) {
|
||||
|
@ -1302,20 +1308,22 @@ static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock*
|
|||
|
||||
if ((ascScan && (key != TSKEY_INITIAL_VAL && key <= binfo.window.ekey)) ||
|
||||
(!ascScan && (key != TSKEY_INITIAL_VAL && key >= binfo.window.skey))) {
|
||||
if ((ascScan && (key != TSKEY_INITIAL_VAL && key < binfo.window.skey)) ||
|
||||
(!ascScan && (key != TSKEY_INITIAL_VAL && key > binfo.window.ekey))) {
|
||||
|
||||
bool cacheDataInFileBlockHole = (ascScan && (key != TSKEY_INITIAL_VAL && key < binfo.window.skey)) ||
|
||||
(!ascScan && (key != TSKEY_INITIAL_VAL && key > binfo.window.ekey));
|
||||
if (cacheDataInFileBlockHole) {
|
||||
// do not load file block into buffer
|
||||
int32_t step = ascScan ? 1 : -1;
|
||||
|
||||
TSKEY maxKey =
|
||||
ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? (binfo.window.skey - step) : (binfo.window.ekey - step);
|
||||
TSKEY maxKey = ascScan ? (binfo.window.skey - step) : (binfo.window.ekey - step);
|
||||
cur->rows =
|
||||
tsdbReadRowsFromCache(pCheckInfo, maxKey, pTsdbReadHandle->outputCapacity, &cur->win, pTsdbReadHandle);
|
||||
pTsdbReadHandle->realNumOfRows = cur->rows;
|
||||
|
||||
// update the last key value
|
||||
pCheckInfo->lastKey = cur->win.ekey + step;
|
||||
if (!ASCENDING_TRAVERSE(pTsdbReadHandle->order)) {
|
||||
|
||||
if (!ascScan) {
|
||||
TSWAP(cur->win.skey, cur->win.ekey);
|
||||
}
|
||||
|
||||
|
@ -1334,18 +1342,16 @@ static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock*
|
|||
/*
|
||||
* no data in cache, only load data from file
|
||||
* during the query processing, data in cache will not be checked anymore.
|
||||
*
|
||||
* Here the buffer is not enough, so only part of file block can be loaded into memory buffer
|
||||
*/
|
||||
assert(pTsdbReadHandle->outputCapacity >= binfo.rows);
|
||||
int32_t endPos = getEndPosInDataBlock(pTsdbReadHandle, &binfo);
|
||||
|
||||
if ((cur->pos == 0 && endPos == binfo.rows - 1 && ascScan) ||
|
||||
(cur->pos == (binfo.rows - 1) && endPos == 0 && (!ascScan))) {
|
||||
bool wholeBlockReturned = ((abs(cur->pos - endPos) + 1) == binfo.rows);
|
||||
if (wholeBlockReturned) {
|
||||
pTsdbReadHandle->realNumOfRows = binfo.rows;
|
||||
|
||||
cur->rows = binfo.rows;
|
||||
cur->win = binfo.window;
|
||||
cur->win = binfo.window;
|
||||
cur->mixBlock = false;
|
||||
cur->blockCompleted = true;
|
||||
|
||||
|
@ -1356,12 +1362,24 @@ static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock*
|
|||
cur->lastKey = binfo.window.skey - 1;
|
||||
cur->pos = -1;
|
||||
}
|
||||
} else { // partially copy to dest buffer
|
||||
} else { // partially copy to dest buffer
|
||||
// make sure to only load once
|
||||
bool firstTimeExtract = ((cur->pos == 0 && ascScan) || (cur->pos == binfo.rows -1 && (!ascScan)));
|
||||
if (pTsdbReadHandle->outputCapacity < binfo.rows && firstTimeExtract) {
|
||||
code = doLoadFileDataBlock(pTsdbReadHandle, pBlock, pCheckInfo, cur->slot);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
copyAllRemainRowsFromFileBlock(pTsdbReadHandle, pCheckInfo, &binfo, endPos);
|
||||
cur->mixBlock = true;
|
||||
}
|
||||
|
||||
assert(cur->blockCompleted);
|
||||
if (pTsdbReadHandle->outputCapacity >= binfo.rows) {
|
||||
ASSERT(cur->blockCompleted);
|
||||
}
|
||||
|
||||
if (cur->rows == binfo.rows) {
|
||||
tsdbDebug("%p whole file block qualified, brange:%" PRId64 "-%" PRId64 ", rows:%d, lastKey:%" PRId64 ", %s",
|
||||
pTsdbReadHandle, cur->win.skey, cur->win.ekey, cur->rows, cur->lastKey, pTsdbReadHandle->idStr);
|
||||
|
@ -1858,15 +1876,14 @@ static void copyAllRemainRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, STa
|
|||
SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0];
|
||||
TSKEY* tsArray = pCols->cols[0].pData;
|
||||
|
||||
int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1;
|
||||
int32_t numOfCols = (int32_t)(QH_GET_NUM_OF_COLS(pTsdbReadHandle));
|
||||
bool ascScan = ASCENDING_TRAVERSE(pTsdbReadHandle->order);
|
||||
|
||||
int32_t pos = cur->pos;
|
||||
int32_t step = ascScan? 1 : -1;
|
||||
|
||||
int32_t start = cur->pos;
|
||||
int32_t end = endPos;
|
||||
|
||||
if (!ASCENDING_TRAVERSE(pTsdbReadHandle->order)) {
|
||||
if (!ascScan) {
|
||||
TSWAP(start, end);
|
||||
}
|
||||
|
||||
|
@ -1876,11 +1893,11 @@ static void copyAllRemainRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, STa
|
|||
// the time window should always be ascending order: skey <= ekey
|
||||
cur->win = (STimeWindow){.skey = tsArray[start], .ekey = tsArray[end]};
|
||||
cur->mixBlock = (numOfRows != pBlockInfo->rows);
|
||||
cur->lastKey = tsArray[endPos] + step;
|
||||
cur->blockCompleted = true;
|
||||
cur->lastKey = tsArray[endPos] + step;
|
||||
cur->blockCompleted = (ascScan? (endPos == pBlockInfo->rows - 1):(endPos == 0));
|
||||
|
||||
// The value of pos may be -1 or pBlockInfo->rows, and it is invalid in both cases.
|
||||
pos = endPos + step;
|
||||
int32_t pos = endPos + step;
|
||||
updateInfoAfterMerge(pTsdbReadHandle, pCheckInfo, numOfRows, pos);
|
||||
doCheckGeneratedBlockRange(pTsdbReadHandle);
|
||||
|
||||
|
@ -1892,20 +1909,44 @@ static void copyAllRemainRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, STa
|
|||
int32_t getEndPosInDataBlock(STsdbReadHandle* pTsdbReadHandle, SDataBlockInfo* pBlockInfo) {
|
||||
// NOTE: reverse the order to find the end position in data block
|
||||
int32_t endPos = -1;
|
||||
int32_t order = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? TSDB_ORDER_DESC : TSDB_ORDER_ASC;
|
||||
bool ascScan = ASCENDING_TRAVERSE(pTsdbReadHandle->order);
|
||||
int32_t order = ascScan? TSDB_ORDER_DESC : TSDB_ORDER_ASC;
|
||||
|
||||
SQueryFilePos* cur = &pTsdbReadHandle->cur;
|
||||
SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0];
|
||||
|
||||
if (ASCENDING_TRAVERSE(pTsdbReadHandle->order) && pTsdbReadHandle->window.ekey >= pBlockInfo->window.ekey) {
|
||||
endPos = pBlockInfo->rows - 1;
|
||||
cur->mixBlock = (cur->pos != 0);
|
||||
} else if (!ASCENDING_TRAVERSE(pTsdbReadHandle->order) && pTsdbReadHandle->window.ekey <= pBlockInfo->window.skey) {
|
||||
endPos = 0;
|
||||
cur->mixBlock = (cur->pos != pBlockInfo->rows - 1);
|
||||
if (pTsdbReadHandle->outputCapacity >= pBlockInfo->rows) {
|
||||
if (ascScan && pTsdbReadHandle->window.ekey >= pBlockInfo->window.ekey) {
|
||||
endPos = pBlockInfo->rows - 1;
|
||||
cur->mixBlock = (cur->pos != 0);
|
||||
} else if ((!ascScan) && pTsdbReadHandle->window.ekey <= pBlockInfo->window.skey) {
|
||||
endPos = 0;
|
||||
cur->mixBlock = (cur->pos != pBlockInfo->rows - 1);
|
||||
} else {
|
||||
assert(pCols->numOfRows > 0);
|
||||
endPos = doBinarySearchKey(pCols->cols[0].pData, pCols->numOfRows, pTsdbReadHandle->window.ekey, order);
|
||||
cur->mixBlock = true;
|
||||
}
|
||||
} else {
|
||||
assert(pCols->numOfRows > 0);
|
||||
endPos = doBinarySearchKey(pCols->cols[0].pData, pCols->numOfRows, pTsdbReadHandle->window.ekey, order);
|
||||
if (ascScan && pTsdbReadHandle->window.ekey >= pBlockInfo->window.ekey) {
|
||||
endPos = TMIN(cur->pos + pTsdbReadHandle->outputCapacity - 1, pBlockInfo->rows - 1);
|
||||
} else if ((!ascScan) && pTsdbReadHandle->window.ekey <= pBlockInfo->window.skey) {
|
||||
endPos = TMAX(cur->pos - pTsdbReadHandle->outputCapacity + 1, 0);
|
||||
} else {
|
||||
ASSERT(pCols->numOfRows > 0);
|
||||
endPos = doBinarySearchKey(pCols->cols[0].pData, pCols->numOfRows, pTsdbReadHandle->window.ekey, order);
|
||||
|
||||
// current data is more than the capacity
|
||||
int32_t size = abs(cur->pos - endPos) + 1;
|
||||
if (size > pTsdbReadHandle->outputCapacity) {
|
||||
int32_t delta = size - pTsdbReadHandle->outputCapacity;
|
||||
if (ascScan) {
|
||||
endPos -= delta;
|
||||
} else {
|
||||
endPos += delta;
|
||||
}
|
||||
}
|
||||
}
|
||||
cur->mixBlock = true;
|
||||
}
|
||||
|
||||
|
@ -2035,8 +2076,14 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
|
|||
}
|
||||
#endif
|
||||
if (TD_SUPPORT_UPDATE(pCfg->update)) {
|
||||
if (lastKeyAppend != key) {
|
||||
if (lastKeyAppend != TSKEY_INITIAL_VAL) {
|
||||
++curRow;
|
||||
}
|
||||
lastKeyAppend = key;
|
||||
}
|
||||
// load data from file firstly
|
||||
numOfRows = doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, curRow, pos, pos);
|
||||
lastKeyAppend = key;
|
||||
|
||||
if (rv1 != TD_ROW_SVER(row1)) {
|
||||
rv1 = TD_ROW_SVER(row1);
|
||||
|
@ -2046,7 +2093,7 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
|
|||
}
|
||||
|
||||
// still assign data into current row
|
||||
mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, &curRow, row1, row2, numOfCols,
|
||||
numOfRows += mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, &curRow, row1, row2, numOfCols,
|
||||
pCheckInfo->tableId, pSchema1, pSchema2, pCfg->update, &lastKeyAppend);
|
||||
|
||||
if (cur->win.skey == TSKEY_INITIAL_VAL) {
|
||||
|
@ -2058,7 +2105,6 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
|
|||
cur->mixBlock = true;
|
||||
|
||||
moveToNextRowInMem(pCheckInfo);
|
||||
++curRow;
|
||||
|
||||
pos += step;
|
||||
} else {
|
||||
|
@ -2369,7 +2415,7 @@ static int32_t createDataBlocksInfo(STsdbReadHandle* pTsdbReadHandle, int32_t nu
|
|||
|
||||
static int32_t getFirstFileDataBlock(STsdbReadHandle* pTsdbReadHandle, bool* exists);
|
||||
|
||||
static int32_t getDataBlockRv(STsdbReadHandle* pTsdbReadHandle, STableBlockInfo* pNext, bool* exists) {
|
||||
static int32_t getDataBlock(STsdbReadHandle* pTsdbReadHandle, STableBlockInfo* pNext, bool* exists) {
|
||||
int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1;
|
||||
SQueryFilePos* cur = &pTsdbReadHandle->cur;
|
||||
|
||||
|
@ -2478,7 +2524,7 @@ static int32_t getFirstFileDataBlock(STsdbReadHandle* pTsdbReadHandle, bool* exi
|
|||
cur->fid = pTsdbReadHandle->pFileGroup->fid;
|
||||
|
||||
STableBlockInfo* pBlockInfo = &pTsdbReadHandle->pDataBlockInfo[cur->slot];
|
||||
return getDataBlockRv(pTsdbReadHandle, pBlockInfo, exists);
|
||||
return getDataBlock(pTsdbReadHandle, pBlockInfo, exists);
|
||||
}
|
||||
|
||||
static bool isEndFileDataBlock(SQueryFilePos* cur, int32_t numOfBlocks, bool ascTrav) {
|
||||
|
@ -2643,7 +2689,7 @@ static int32_t getDataBlocksInFiles(STsdbReadHandle* pTsdbReadHandle, bool* exis
|
|||
} else {
|
||||
moveToNextDataBlockInCurrentFile(pTsdbReadHandle);
|
||||
STableBlockInfo* pNext = &pTsdbReadHandle->pDataBlockInfo[cur->slot];
|
||||
return getDataBlockRv(pTsdbReadHandle, pNext, exists);
|
||||
return getDataBlock(pTsdbReadHandle, pNext, exists);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -180,8 +180,6 @@ void vnodeClose(SVnode *pVnode) {
|
|||
|
||||
// start the sync timer after the queue is ready
|
||||
int32_t vnodeStart(SVnode *pVnode) {
|
||||
vnodeSyncSetQ(pVnode, NULL);
|
||||
vnodeSyncSetRpc(pVnode, NULL);
|
||||
vnodeSyncStart(pVnode);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -106,11 +106,13 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg
|
|||
pMsg->contLen - sizeof(SMsgHead)) < 0) {
|
||||
}
|
||||
} break;
|
||||
#if 0
|
||||
case TDMT_VND_TASK_WRITE_EXEC: {
|
||||
if (tqProcessTaskExec(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), pMsg->contLen - sizeof(SMsgHead),
|
||||
0) < 0) {
|
||||
}
|
||||
} break;
|
||||
#endif
|
||||
case TDMT_VND_ALTER_VNODE:
|
||||
break;
|
||||
default:
|
||||
|
@ -181,11 +183,32 @@ int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
|
|||
return vnodeGetTableMeta(pVnode, pMsg);
|
||||
case TDMT_VND_CONSUME:
|
||||
return tqProcessPollReq(pVnode->pTq, pMsg, pInfo->workerId);
|
||||
|
||||
case TDMT_VND_TASK_RUN: {
|
||||
int32_t code = tqProcessTaskRunReq(pVnode->pTq, pMsg);
|
||||
pMsg->pCont = NULL;
|
||||
return code;
|
||||
}
|
||||
case TDMT_VND_TASK_DISPATCH:
|
||||
return tqProcessTaskDispatchReq(pVnode->pTq, pMsg);
|
||||
case TDMT_VND_TASK_RECOVER:
|
||||
return tqProcessTaskRecoverReq(pVnode->pTq, pMsg);
|
||||
case TDMT_VND_TASK_DISPATCH_RSP:
|
||||
return tqProcessTaskDispatchRsp(pVnode->pTq, pMsg);
|
||||
case TDMT_VND_TASK_RECOVER_RSP:
|
||||
return tqProcessTaskRecoverRsp(pVnode->pTq, pMsg);
|
||||
|
||||
#if 0
|
||||
case TDMT_VND_TASK_PIPE_EXEC:
|
||||
case TDMT_VND_TASK_MERGE_EXEC:
|
||||
return tqProcessTaskExec(pVnode->pTq, msgstr, msgLen, 0);
|
||||
case TDMT_VND_STREAM_TRIGGER:
|
||||
return tqProcessStreamTrigger(pVnode->pTq, pMsg->pCont, pMsg->contLen, 0);
|
||||
case TDMT_VND_STREAM_TRIGGER:{
|
||||
// refactor, avoid double free
|
||||
int code = tqProcessStreamTrigger(pVnode->pTq, pMsg->pCont, pMsg->contLen, 0);
|
||||
pMsg->pCont = NULL;
|
||||
return code;
|
||||
}
|
||||
#endif
|
||||
case TDMT_VND_QUERY_HEARTBEAT:
|
||||
return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg);
|
||||
default:
|
||||
|
@ -682,7 +705,7 @@ static int vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, in
|
|||
|
||||
submitBlkRsp.uid = createTbReq.uid;
|
||||
submitBlkRsp.tblFName = taosMemoryMalloc(strlen(pVnode->config.dbname) + strlen(createTbReq.name) + 2);
|
||||
sprintf(submitBlkRsp.tblFName, "%s.%s", pVnode->config.dbname, createTbReq.name);
|
||||
sprintf(submitBlkRsp.tblFName, "%s.", pVnode->config.dbname);
|
||||
|
||||
msgIter.uid = createTbReq.uid;
|
||||
if (createTbReq.type == TSDB_CHILD_TABLE) {
|
||||
|
|
|
@ -13,90 +13,62 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "vnd.h"
|
||||
|
||||
static int32_t vnodeSyncEqMsg(const SMsgCb *msgcb, SRpcMsg *pMsg);
|
||||
static int32_t vnodeSyncSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg);
|
||||
static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode);
|
||||
static void vnodeSyncCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta);
|
||||
static void vnodeSyncPreCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta);
|
||||
static void vnodeSyncRollBackMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta);
|
||||
static int32_t vnodeSyncGetSnapshot(SSyncFSM *pFsm, SSnapshot *pSnapshot);
|
||||
|
||||
int32_t vnodeSyncOpen(SVnode *pVnode, char *path) {
|
||||
SSyncInfo syncInfo;
|
||||
syncInfo.vgId = pVnode->config.vgId;
|
||||
SSyncCfg *pCfg = &(syncInfo.syncCfg);
|
||||
pCfg->replicaNum = pVnode->config.syncCfg.replicaNum;
|
||||
pCfg->myIndex = pVnode->config.syncCfg.myIndex;
|
||||
memcpy(pCfg->nodeInfo, pVnode->config.syncCfg.nodeInfo, sizeof(pCfg->nodeInfo));
|
||||
SSyncInfo syncInfo = {
|
||||
.vgId = pVnode->config.vgId,
|
||||
.syncCfg = pVnode->config.syncCfg,
|
||||
.pWal = pVnode->pWal,
|
||||
.msgcb = NULL,
|
||||
.FpSendMsg = vnodeSyncSendMsg,
|
||||
.FpEqMsg = vnodeSyncEqMsg,
|
||||
};
|
||||
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s/sync", path);
|
||||
syncInfo.pWal = pVnode->pWal;
|
||||
|
||||
syncInfo.pFsm = syncVnodeMakeFsm(pVnode);
|
||||
syncInfo.rpcClient = NULL;
|
||||
syncInfo.FpSendMsg = vnodeSendMsg;
|
||||
syncInfo.queue = NULL;
|
||||
syncInfo.FpEqMsg = vnodeSyncEqMsg;
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s%ssync", path, TD_DIRSEP);
|
||||
syncInfo.pFsm = vnodeSyncMakeFsm(pVnode);
|
||||
|
||||
pVnode->sync = syncOpen(&syncInfo);
|
||||
assert(pVnode->sync > 0);
|
||||
if (pVnode->sync <= 0) {
|
||||
vError("vgId:%d, failed to open sync since %s", pVnode->config.vgId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
// for test
|
||||
setPingTimerMS(pVnode->sync, 3000);
|
||||
setElectTimerMS(pVnode->sync, 500);
|
||||
setHeartbeatTimerMS(pVnode->sync, 100);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t vnodeSyncStart(SVnode *pVnode) {
|
||||
void vnodeSyncStart(SVnode *pVnode) {
|
||||
syncSetMsgCb(pVnode->sync, &pVnode->msgCb);
|
||||
syncStart(pVnode->sync);
|
||||
}
|
||||
|
||||
void vnodeSyncClose(SVnode *pVnode) { syncStop(pVnode->sync); }
|
||||
|
||||
int32_t vnodeSyncEqMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) { return tmsgPutToQueue(msgcb, SYNC_QUEUE, pMsg); }
|
||||
|
||||
int32_t vnodeSyncSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg) { return tmsgSendReq(pEpSet, pMsg); }
|
||||
|
||||
int32_t vnodeSyncGetSnapshot(SSyncFSM *pFsm, SSnapshot *pSnapshot) {
|
||||
vnodeGetSnapshot(pFsm->data, pSnapshot);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void vnodeSyncClose(SVnode *pVnode) {
|
||||
// stop by ref id
|
||||
syncStop(pVnode->sync);
|
||||
}
|
||||
|
||||
void vnodeSyncSetQ(SVnode *pVnode, void *qHandle) { syncSetQ(pVnode->sync, (void *)(&(pVnode->msgCb))); }
|
||||
|
||||
void vnodeSyncSetRpc(SVnode *pVnode, void *rpcHandle) { syncSetRpc(pVnode->sync, (void *)(&(pVnode->msgCb))); }
|
||||
|
||||
int32_t vnodeSyncEqMsg(void *qHandle, SRpcMsg *pMsg) {
|
||||
int32_t ret = 0;
|
||||
SMsgCb *pMsgCb = qHandle;
|
||||
if (pMsgCb->queueFps[SYNC_QUEUE] != NULL) {
|
||||
tmsgPutToQueue(qHandle, SYNC_QUEUE, pMsg);
|
||||
} else {
|
||||
vError("vnodeSyncEqMsg queue is NULL, SYNC_QUEUE:%d", SYNC_QUEUE);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t vnodeSendMsg(void *rpcHandle, const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||
int32_t ret = 0;
|
||||
SMsgCb *pMsgCb = rpcHandle;
|
||||
if (pMsgCb->queueFps[SYNC_QUEUE] != NULL) {
|
||||
pMsg->info.noResp = 1;
|
||||
tmsgSendReq(pEpSet, pMsg);
|
||||
} else {
|
||||
vError("vnodeSendMsg queue is NULL, SYNC_QUEUE:%d", SYNC_QUEUE);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t vnodeSyncGetSnapshotCb(struct SSyncFSM *pFsm, SSnapshot *pSnapshot) {
|
||||
SVnode *pVnode = (SVnode *)(pFsm->data);
|
||||
vnodeGetSnapshot(pVnode, pSnapshot);
|
||||
|
||||
/*
|
||||
pSnapshot->data = NULL;
|
||||
pSnapshot->lastApplyIndex = 0;
|
||||
pSnapshot->lastApplyTerm = 0;
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void vnodeSyncCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) {
|
||||
void vnodeSyncCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) {
|
||||
SyncIndex beginIndex = SYNC_INDEX_INVALID;
|
||||
if (pFsm->FpGetSnapshot != NULL) {
|
||||
SSnapshot snapshot;
|
||||
SSnapshot snapshot = {0};
|
||||
pFsm->FpGetSnapshot(pFsm, &snapshot);
|
||||
beginIndex = snapshot.lastApplyIndex;
|
||||
}
|
||||
|
@ -147,7 +119,7 @@ void vnodeSyncCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cb
|
|||
}
|
||||
}
|
||||
|
||||
void vnodeSyncPreCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) {
|
||||
void vnodeSyncPreCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) {
|
||||
char logBuf[256];
|
||||
snprintf(logBuf, sizeof(logBuf),
|
||||
"==callback== ==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n", pFsm, cbMeta.index,
|
||||
|
@ -155,19 +127,19 @@ void vnodeSyncPreCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta
|
|||
syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg);
|
||||
}
|
||||
|
||||
void vnodeSyncRollBackCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) {
|
||||
void vnodeSyncRollBackMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) {
|
||||
char logBuf[256];
|
||||
snprintf(logBuf, sizeof(logBuf), "==callback== ==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s \n",
|
||||
pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state));
|
||||
syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg);
|
||||
}
|
||||
|
||||
SSyncFSM *syncVnodeMakeFsm(SVnode *pVnode) {
|
||||
SSyncFSM *pFsm = (SSyncFSM *)taosMemoryMalloc(sizeof(SSyncFSM));
|
||||
SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) {
|
||||
SSyncFSM *pFsm = taosMemoryCalloc(1, sizeof(SSyncFSM));
|
||||
pFsm->data = pVnode;
|
||||
pFsm->FpCommitCb = vnodeSyncCommitCb;
|
||||
pFsm->FpPreCommitCb = vnodeSyncPreCommitCb;
|
||||
pFsm->FpRollBackCb = vnodeSyncRollBackCb;
|
||||
pFsm->FpGetSnapshot = vnodeSyncGetSnapshotCb;
|
||||
pFsm->FpCommitCb = vnodeSyncCommitMsg;
|
||||
pFsm->FpPreCommitCb = vnodeSyncPreCommitMsg;
|
||||
pFsm->FpRollBackCb = vnodeSyncRollBackMsg;
|
||||
pFsm->FpGetSnapshot = vnodeSyncGetSnapshot;
|
||||
return pFsm;
|
||||
}
|
|
@ -125,6 +125,33 @@ qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, void* streamReadHandle) {
|
|||
return pTaskInfo;
|
||||
}
|
||||
|
||||
static SArray* filterQualifiedChildTables(const SStreamBlockScanInfo* pScanInfo, const SArray* tableIdList) {
|
||||
SArray* qa = taosArrayInit(4, sizeof(tb_uid_t));
|
||||
|
||||
// let's discard the tables those are not created according to the queried super table.
|
||||
SMetaReader mr = {0};
|
||||
metaReaderInit(&mr, pScanInfo->readHandle.meta, 0);
|
||||
for (int32_t i = 0; i < taosArrayGetSize(tableIdList); ++i) {
|
||||
int64_t* id = (int64_t*)taosArrayGet(tableIdList, i);
|
||||
|
||||
int32_t code = metaGetTableEntryByUid(&mr, *id);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("failed to get table meta, uid:%" PRIu64 " code:%s", *id, tstrerror(terrno));
|
||||
continue;
|
||||
}
|
||||
|
||||
ASSERT(mr.me.type == TSDB_CHILD_TABLE);
|
||||
if (mr.me.ctbEntry.suid != pScanInfo->tableUid) {
|
||||
continue;
|
||||
}
|
||||
|
||||
taosArrayPush(qa, id);
|
||||
}
|
||||
|
||||
metaReaderClear(&mr);
|
||||
return qa;
|
||||
}
|
||||
|
||||
int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bool isAdd) {
|
||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||
|
||||
|
@ -134,41 +161,24 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo
|
|||
pInfo = pInfo->pDownstream[0];
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
SStreamBlockScanInfo* pScanInfo = pInfo->info;
|
||||
if (isAdd) {
|
||||
SArray* qa = taosArrayInit(4, sizeof(tb_uid_t));
|
||||
|
||||
SMetaReader mr = {0};
|
||||
metaReaderInit(&mr, pScanInfo->readHandle.meta, 0);
|
||||
for (int32_t i = 0; i < taosArrayGetSize(tableIdList); ++i) {
|
||||
int64_t* id = (int64_t*)taosArrayGet(tableIdList, i);
|
||||
|
||||
int32_t code = metaGetTableEntryByUid(&mr, *id);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("failed to get table meta, uid:%" PRIu64 " code:%s", *id, tstrerror(terrno));
|
||||
continue;
|
||||
}
|
||||
|
||||
ASSERT(mr.me.type == TSDB_CHILD_TABLE);
|
||||
if (mr.me.ctbEntry.suid != pScanInfo->tableUid) {
|
||||
continue;
|
||||
}
|
||||
|
||||
taosArrayPush(qa, id);
|
||||
}
|
||||
|
||||
metaReaderClear(&mr);
|
||||
if (isAdd) { // add new table id
|
||||
SArray* qa = filterQualifiedChildTables(pScanInfo, tableIdList);
|
||||
|
||||
qDebug(" %d qualified child tables added into stream scanner", (int32_t)taosArrayGetSize(qa));
|
||||
int32_t code = tqReadHandleAddTbUidList(pScanInfo->streamBlockReader, qa);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
} else {
|
||||
assert(0);
|
||||
code = tqReadHandleAddTbUidList(pScanInfo->streamBlockReader, qa);
|
||||
taosArrayDestroy(qa);
|
||||
|
||||
} else { // remove the table id in current list
|
||||
SArray* qa = filterQualifiedChildTables(pScanInfo, tableIdList);
|
||||
|
||||
qDebug(" %d remove child tables from the stream scanner", (int32_t)taosArrayGetSize(tableIdList));
|
||||
code = tqReadHandleAddTbUidList(pScanInfo->streamBlockReader, tableIdList);
|
||||
taosArrayDestroy(qa);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t qGetQueriedTableSchemaVersion(qTaskInfo_t tinfo, char* dbName, char* tableName, int32_t* sversion, int32_t* tversion) {
|
||||
|
|
|
@ -2062,15 +2062,7 @@ void setExecutionContext(int32_t numOfOutput, uint64_t groupId, SExecTaskInfo* p
|
|||
pAggInfo->groupId = groupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* For interval query of both super table and table, copy the data in ascending order, since the output results are
|
||||
* ordered in SWindowResutl already. While handling the group by query for both table and super table,
|
||||
* all group result are completed already.
|
||||
*
|
||||
* @param pQInfo
|
||||
* @param result
|
||||
*/
|
||||
int32_t doCopyToSDataBlock(SExecTaskInfo* taskInfo, SSDataBlock* pBlock, SExprInfo* pExprInfo, SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResInfo,
|
||||
int32_t doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprInfo* pExprInfo, SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResInfo,
|
||||
int32_t* rowCellOffset, SqlFunctionCtx* pCtx, int32_t numOfExprs) {
|
||||
int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
|
||||
int32_t start = pGroupResInfo->index;
|
||||
|
@ -2087,6 +2079,15 @@ int32_t doCopyToSDataBlock(SExecTaskInfo* taskInfo, SSDataBlock* pBlock, SExprIn
|
|||
continue;
|
||||
}
|
||||
|
||||
if (pBlock->info.groupId == 0) {
|
||||
pBlock->info.groupId = pPos->groupId;
|
||||
} else {
|
||||
// current value belongs to different group, it can't be packed into one datablock
|
||||
if (pBlock->info.groupId != pPos->groupId) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pBlock->info.rows + pRow->numOfRows > pBlock->info.capacity) {
|
||||
break;
|
||||
}
|
||||
|
@ -2100,9 +2101,8 @@ int32_t doCopyToSDataBlock(SExecTaskInfo* taskInfo, SSDataBlock* pBlock, SExprIn
|
|||
if (pCtx[j].fpSet.finalize) {
|
||||
int32_t code = pCtx[j].fpSet.finalize(&pCtx[j], pBlock);
|
||||
if (TAOS_FAILED(code)) {
|
||||
qError("%s build result data block error, code %s", GET_TASKID(taskInfo), tstrerror(code));
|
||||
taskInfo->code = code;
|
||||
longjmp(taskInfo->env, code);
|
||||
qError("%s build result data block error, code %s", GET_TASKID(pTaskInfo), tstrerror(code));
|
||||
longjmp(pTaskInfo->env, code);
|
||||
}
|
||||
} else if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_select_value") == 0) {
|
||||
// do nothing, todo refactor
|
||||
|
@ -2124,7 +2124,7 @@ int32_t doCopyToSDataBlock(SExecTaskInfo* taskInfo, SSDataBlock* pBlock, SExprIn
|
|||
}
|
||||
}
|
||||
|
||||
// qDebug("QInfo:0x%"PRIx64" copy data to query buf completed", GET_TASKID(pRuntimeEnv));
|
||||
qDebug("%s result generated, rows:%d, groupId:%"PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows, pBlock->info.groupId);
|
||||
blockDataUpdateTsWindow(pBlock);
|
||||
return 0;
|
||||
}
|
||||
|
@ -2145,10 +2145,9 @@ void doBuildResultDatablock(SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SG
|
|||
return;
|
||||
}
|
||||
|
||||
// clear the existed group id
|
||||
pBlock->info.groupId = 0;
|
||||
doCopyToSDataBlock(pTaskInfo, pBlock, pExprInfo, pBuf, pGroupResInfo, rowCellOffset, pCtx, numOfExprs);
|
||||
|
||||
// add condition (pBlock->info.rows >= 1) just to runtime happy
|
||||
blockDataUpdateTsWindow(pBlock);
|
||||
}
|
||||
|
||||
static void updateNumOfRowsInResultRows(SqlFunctionCtx* pCtx, int32_t numOfOutput, SResultRowInfo* pResultRowInfo,
|
||||
|
@ -3546,11 +3545,12 @@ _error:
|
|||
|
||||
int32_t getTableScanInfo(SOperatorInfo* pOperator, int32_t *order, int32_t* scanFlag) {
|
||||
// todo add more information about exchange operation
|
||||
if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_EXCHANGE) {
|
||||
int32_t type = pOperator->operatorType;
|
||||
if (type == QUERY_NODE_PHYSICAL_PLAN_EXCHANGE || type == QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN || type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
||||
*order = TSDB_ORDER_ASC;
|
||||
*scanFlag = MAIN_SCAN;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
} else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
|
||||
} else if (type == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
|
||||
STableScanInfo* pTableScanInfo = pOperator->info;
|
||||
*order = pTableScanInfo->cond.order;
|
||||
*scanFlag = pTableScanInfo->scanFlag;
|
||||
|
@ -3655,7 +3655,6 @@ static SSDataBlock* getAggregateResult(SOperatorInfo* pOperator) {
|
|||
doSetOperatorCompleted(pOperator);
|
||||
}
|
||||
|
||||
doSetOperatorCompleted(pOperator);
|
||||
return (blockDataGetNumOfRows(pInfo->pRes) != 0) ? pInfo->pRes : NULL;
|
||||
}
|
||||
|
||||
|
@ -3910,6 +3909,9 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) {
|
|||
|
||||
// the pDataBlock are always the same one, no need to call this again
|
||||
int32_t code = getTableScanInfo(pOperator->pDownstream[0], &order, &scanFlag);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
longjmp(pTaskInfo->env, code);
|
||||
}
|
||||
|
||||
setInputDataBlock(pOperator, pInfo->pCtx, pBlock, order, scanFlag, false);
|
||||
blockDataEnsureCapacity(pInfo->pRes, pInfo->pRes->info.rows + pBlock->info.rows);
|
||||
|
@ -4203,7 +4205,7 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo*
|
|||
pInfo->pScalarExprInfo = pScalarExprInfo;
|
||||
pInfo->numOfScalarExpr = numOfScalarExpr;
|
||||
if (pInfo->pScalarExprInfo != NULL) {
|
||||
pInfo->pScalarCtx = createSqlFunctionCtx(pScalarExprInfo, numOfCols, &pInfo->rowCellInfoOffset);
|
||||
pInfo->pScalarCtx = createSqlFunctionCtx(pScalarExprInfo, numOfScalarExpr, &pInfo->rowCellInfoOffset);
|
||||
}
|
||||
|
||||
pOperator->name = "TableAggregate";
|
||||
|
@ -4311,23 +4313,29 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* p
|
|||
int32_t numOfRows = 4096;
|
||||
size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
|
||||
|
||||
// Make sure the size of SSDataBlock will never exceed the size of 2MB.
|
||||
int32_t TWOMB = 2 * 1024 * 1024;
|
||||
if (numOfRows * pResBlock->info.rowSize > TWOMB) {
|
||||
numOfRows = TWOMB / pResBlock->info.rowSize;
|
||||
}
|
||||
initResultSizeInfo(pOperator, numOfRows);
|
||||
|
||||
initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, pResBlock, keyBufSize, pTaskInfo->id.str);
|
||||
setFunctionResultOutput(&pInfo->binfo, &pInfo->aggSup, MAIN_SCAN, numOfCols, pTaskInfo);
|
||||
pInfo->pPseudoColInfo = setRowTsColumnOutputInfo(pInfo->binfo.pCtx, numOfCols);
|
||||
|
||||
pOperator->name = "ProjectOperator";
|
||||
pInfo->pPseudoColInfo = setRowTsColumnOutputInfo(pInfo->binfo.pCtx, numOfCols);
|
||||
pOperator->name = "ProjectOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_PROJECT;
|
||||
pOperator->blocking = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pExpr = pExprInfo;
|
||||
pOperator->numOfExprs = num;
|
||||
pOperator->blocking = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pExpr = pExprInfo;
|
||||
pOperator->numOfExprs = num;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doProjectOperation, NULL, NULL,
|
||||
destroyProjectOperatorInfo, NULL, NULL, NULL);
|
||||
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
|
|
|
@ -300,10 +300,26 @@ void addTagPseudoColumnData(STableScanInfo* pTableScanInfo, SSDataBlock* pBlock)
|
|||
if (fmIsScanPseudoColumnFunc(functionId)) {
|
||||
setTbNameColData(pTableScanInfo->readHandle.meta, pBlock, pColInfoData, functionId);
|
||||
} else { // these are tags
|
||||
const char* p = metaGetTableTagVal(&mr.me, pExpr->base.pParam[0].pCol->colId);
|
||||
const char* p = NULL;
|
||||
if(pColInfoData->info.type == TSDB_DATA_TYPE_JSON){
|
||||
const uint8_t *tmp = mr.me.ctbEntry.pTags;
|
||||
char *data = taosMemoryCalloc(kvRowLen(tmp) + 1, 1);
|
||||
if(data == NULL){
|
||||
qError("doTagScan calloc error:%d", kvRowLen(tmp) + 1);
|
||||
return;
|
||||
}
|
||||
*data = TSDB_DATA_TYPE_JSON;
|
||||
memcpy(data+1, tmp, kvRowLen(tmp));
|
||||
p = data;
|
||||
}else{
|
||||
p = metaGetTableTagVal(&mr.me, pExpr->base.pParam[0].pCol->colId);
|
||||
}
|
||||
for (int32_t i = 0; i < pBlock->info.rows; ++i) {
|
||||
colDataAppend(pColInfoData, i, p, (p == NULL));
|
||||
}
|
||||
if(pColInfoData->info.type == TSDB_DATA_TYPE_JSON){
|
||||
taosMemoryFree((void*)p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1587,8 +1603,21 @@ static SSDataBlock* doTagScan(SOperatorInfo* pOperator) {
|
|||
STR_TO_VARSTR(str, mr.me.name);
|
||||
colDataAppend(pDst, count, str, false);
|
||||
} else { // it is a tag value
|
||||
const char* p = metaGetTableTagVal(&mr.me, pExprInfo[j].base.pParam[0].pCol->colId);
|
||||
colDataAppend(pDst, count, p, (p == NULL));
|
||||
if(pDst->info.type == TSDB_DATA_TYPE_JSON){
|
||||
const uint8_t *tmp = mr.me.ctbEntry.pTags;
|
||||
char *data = taosMemoryCalloc(kvRowLen(tmp) + 1, 1);
|
||||
if(data == NULL){
|
||||
qError("doTagScan calloc error:%d", kvRowLen(tmp) + 1);
|
||||
return NULL;
|
||||
}
|
||||
*data = TSDB_DATA_TYPE_JSON;
|
||||
memcpy(data+1, tmp, kvRowLen(tmp));
|
||||
colDataAppend(pDst, count, data, false);
|
||||
taosMemoryFree(data);
|
||||
}else{
|
||||
const char* p = metaGetTableTagVal(&mr.me, pExprInfo[j].base.pParam[0].pCol->colId);
|
||||
colDataAppend(pDst, count, p, (p == NULL));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -120,7 +120,13 @@ int32_t sampleFunction(SqlFunctionCtx* pCtx);
|
|||
bool getTailFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
bool tailFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
int32_t tailFunction(SqlFunctionCtx* pCtx);
|
||||
int32_t tailFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||
//int32_t tailFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||
|
||||
bool getUniqueFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
bool uniqueFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
int32_t uniqueFunction(SqlFunctionCtx *pCtx);
|
||||
//int32_t uniqueFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||
|
||||
|
||||
bool getSelectivityFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
|
||||
|
|
|
@ -493,6 +493,21 @@ static int32_t translateFirstLast(SFunctionNode* pFunc, char* pErrBuf, int32_t l
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateUnique(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
if (1 != LIST_LENGTH(pFunc->pParameterList)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SNode* pPara = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (QUERY_NODE_COLUMN != nodeType(pPara)) {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
"The parameters of UNIQUE can only be columns");
|
||||
}
|
||||
|
||||
pFunc->node.resType = ((SExprNode*)pPara)->resType;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
int32_t paraLen = LIST_LENGTH(pFunc->pParameterList);
|
||||
if (paraLen == 0 || paraLen > 2) {
|
||||
|
@ -877,16 +892,6 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.processFunc = lastFunction,
|
||||
.finalizeFunc = lastFinalize
|
||||
},
|
||||
{
|
||||
.name = "diff",
|
||||
.type = FUNCTION_TYPE_DIFF,
|
||||
.classification = FUNC_MGT_NONSTANDARD_SQL_FUNC | FUNC_MGT_TIMELINE_FUNC,
|
||||
.translateFunc = translateDiff,
|
||||
.getEnvFunc = getDiffFuncEnv,
|
||||
.initFunc = diffFunctionSetup,
|
||||
.processFunc = diffFunction,
|
||||
.finalizeFunc = functionFinalize
|
||||
},
|
||||
{
|
||||
.name = "histogram",
|
||||
.type = FUNCTION_TYPE_HISTOGRAM,
|
||||
|
@ -907,6 +912,16 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.processFunc = hllFunction,
|
||||
.finalizeFunc = hllFinalize
|
||||
},
|
||||
{
|
||||
.name = "diff",
|
||||
.type = FUNCTION_TYPE_DIFF,
|
||||
.classification = FUNC_MGT_NONSTANDARD_SQL_FUNC | FUNC_MGT_TIMELINE_FUNC,
|
||||
.translateFunc = translateDiff,
|
||||
.getEnvFunc = getDiffFuncEnv,
|
||||
.initFunc = diffFunctionSetup,
|
||||
.processFunc = diffFunction,
|
||||
.finalizeFunc = functionFinalize
|
||||
},
|
||||
{
|
||||
.name = "state_count",
|
||||
.type = FUNCTION_TYPE_STATE_COUNT,
|
||||
|
@ -965,7 +980,17 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.getEnvFunc = getTailFuncEnv,
|
||||
.initFunc = tailFunctionSetup,
|
||||
.processFunc = tailFunction,
|
||||
.finalizeFunc = tailFinalize
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "unique",
|
||||
.type = FUNCTION_TYPE_UNIQUE,
|
||||
.classification = FUNC_MGT_NONSTANDARD_SQL_FUNC | FUNC_MGT_TIMELINE_FUNC,
|
||||
.translateFunc = translateUnique,
|
||||
.getEnvFunc = getUniqueFuncEnv,
|
||||
.initFunc = uniqueFunctionSetup,
|
||||
.processFunc = uniqueFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "abs",
|
||||
|
|
|
@ -28,12 +28,15 @@
|
|||
#define TAIL_MAX_POINTS_NUM 100
|
||||
#define TAIL_MAX_OFFSET 100
|
||||
|
||||
#define UNIQUE_MAX_RESULT_SIZE (1024*1024*10)
|
||||
|
||||
#define HLL_BUCKET_BITS 14 // The bits of the bucket
|
||||
#define HLL_DATA_BITS (64-HLL_BUCKET_BITS)
|
||||
#define HLL_BUCKETS (1<<HLL_BUCKET_BITS)
|
||||
#define HLL_BUCKET_MASK (HLL_BUCKETS-1)
|
||||
#define HLL_ALPHA_INF 0.721347520444481703680 // constant for 0.5/ln(2)
|
||||
|
||||
|
||||
typedef struct SSumRes {
|
||||
union {
|
||||
int64_t isum;
|
||||
|
@ -197,6 +200,20 @@ typedef struct STailInfo {
|
|||
STailItem **pItems;
|
||||
} STailInfo;
|
||||
|
||||
typedef struct SUniqueItem {
|
||||
int64_t timestamp;
|
||||
bool isNull;
|
||||
char data[];
|
||||
} SUniqueItem;
|
||||
|
||||
typedef struct SUniqueInfo {
|
||||
int32_t numOfPoints;
|
||||
uint8_t colType;
|
||||
int16_t colBytes;
|
||||
SHashObj *pHash;
|
||||
char pItems[];
|
||||
} SUniqueInfo;
|
||||
|
||||
#define SET_VAL(_info, numOfElem, res) \
|
||||
do { \
|
||||
if ((numOfElem) <= 0) { \
|
||||
|
@ -216,6 +233,18 @@ typedef struct STailInfo {
|
|||
} \
|
||||
} while (0);
|
||||
|
||||
#define DO_UPDATE_SUBSID_RES(ctx, ts) \
|
||||
do { \
|
||||
for (int32_t _i = 0; _i < (ctx)->subsidiaries.num; ++_i) { \
|
||||
SqlFunctionCtx* __ctx = (ctx)->subsidiaries.pCtx[_i]; \
|
||||
if (__ctx->functionId == FUNCTION_TS_DUMMY) { \
|
||||
__ctx->tag.i = (ts); \
|
||||
__ctx->tag.nType = TSDB_DATA_TYPE_BIGINT; \
|
||||
} \
|
||||
__ctx->fpSet.process(__ctx); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define UPDATE_DATA(ctx, left, right, num, sign, _ts) \
|
||||
do { \
|
||||
if (((left) < (right)) ^ (sign)) { \
|
||||
|
@ -748,50 +777,6 @@ bool getMinmaxFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
|
|||
return true;
|
||||
}
|
||||
|
||||
#define GET_TS_LIST(x) ((TSKEY*)((x)->ptsList))
|
||||
#define GET_TS_DATA(x, y) (GET_TS_LIST(x)[(y)])
|
||||
|
||||
#define DO_UPDATE_TAG_COLUMNS_WITHOUT_TS(ctx) \
|
||||
do { \
|
||||
for (int32_t _i = 0; _i < (ctx)->tagInfo.numOfTagCols; ++_i) { \
|
||||
SqlFunctionCtx* __ctx = (ctx)->tagInfo.pTagCtxList[_i]; \
|
||||
__ctx->fpSet.process(__ctx); \
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
#define DO_UPDATE_SUBSID_RES(ctx, ts) \
|
||||
do { \
|
||||
for (int32_t _i = 0; _i < (ctx)->subsidiaries.num; ++_i) { \
|
||||
SqlFunctionCtx* __ctx = (ctx)->subsidiaries.pCtx[_i]; \
|
||||
if (__ctx->functionId == FUNCTION_TS_DUMMY) { \
|
||||
__ctx->tag.i = (ts); \
|
||||
__ctx->tag.nType = TSDB_DATA_TYPE_BIGINT; \
|
||||
} \
|
||||
__ctx->fpSet.process(__ctx); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define UPDATE_DATA(ctx, left, right, num, sign, _ts) \
|
||||
do { \
|
||||
if (((left) < (right)) ^ (sign)) { \
|
||||
(left) = (right); \
|
||||
DO_UPDATE_SUBSID_RES(ctx, _ts); \
|
||||
(num) += 1; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define LOOPCHECK_N(val, _col, ctx, _t, _nrow, _start, sign, num) \
|
||||
do { \
|
||||
_t* d = (_t*)((_col)->pData); \
|
||||
for (int32_t i = (_start); i < (_nrow) + (_start); ++i) { \
|
||||
if (((_col)->hasNull) && colDataIsNull_f((_col)->nullbitmap, i)) { \
|
||||
continue; \
|
||||
} \
|
||||
TSKEY ts = (ctx)->ptsList != NULL ? GET_TS_DATA(ctx, i) : 0; \
|
||||
UPDATE_DATA(ctx, val, d[i], num, sign, ts); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STuplePos* pPos);
|
||||
static void copyTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STuplePos* pPos);
|
||||
|
||||
|
@ -2106,7 +2091,7 @@ static void doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv, SCo
|
|||
default:
|
||||
ASSERT(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t diffFunction(SqlFunctionCtx* pCtx) {
|
||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||
|
@ -3581,3 +3566,92 @@ int32_t tailFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
|
||||
return pEntryInfo->numOfRes;
|
||||
}
|
||||
|
||||
bool getUniqueFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
||||
pEnv->calcMemSize = sizeof(SUniqueInfo) + UNIQUE_MAX_RESULT_SIZE;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool uniqueFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResInfo) {
|
||||
if (!functionSetup(pCtx, pResInfo)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SUniqueInfo* pInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
pInfo->numOfPoints = 0;
|
||||
pInfo->colType = pCtx->resDataInfo.type;
|
||||
pInfo->colBytes = pCtx->resDataInfo.bytes;
|
||||
if (pInfo->pHash != NULL) {
|
||||
taosHashClear(pInfo->pHash);
|
||||
} else {
|
||||
pInfo->pHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void doUniqueAdd(SUniqueInfo* pInfo, char *data, TSKEY ts, bool isNull) {
|
||||
int32_t hashKeyBytes = IS_VAR_DATA_TYPE(pInfo->colType) ? varDataTLen(data) : pInfo->colBytes;
|
||||
|
||||
SUniqueItem *pHashItem = taosHashGet(pInfo->pHash, data, hashKeyBytes);
|
||||
if (pHashItem == NULL) {
|
||||
int32_t size = sizeof(SUniqueItem) + pInfo->colBytes;
|
||||
SUniqueItem *pItem = (SUniqueItem *)(pInfo->pItems + pInfo->numOfPoints * size);
|
||||
pItem->timestamp = ts;
|
||||
memcpy(pItem->data, data, pInfo->colBytes);
|
||||
|
||||
taosHashPut(pInfo->pHash, data, hashKeyBytes, (char *)pItem, sizeof(SUniqueItem*));
|
||||
pInfo->numOfPoints++;
|
||||
} else if (pHashItem->timestamp > ts) {
|
||||
pHashItem->timestamp = ts;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int32_t uniqueFunction(SqlFunctionCtx* pCtx) {
|
||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||
SUniqueInfo* pInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
|
||||
SInputColumnInfoData* pInput = &pCtx->input;
|
||||
TSKEY* tsList = (int64_t*)pInput->pPTS->pData;
|
||||
|
||||
SColumnInfoData* pInputCol = pInput->pData[0];
|
||||
SColumnInfoData* pTsOutput = pCtx->pTsOutput;
|
||||
SColumnInfoData* pOutput = (SColumnInfoData*)pCtx->pOutput;
|
||||
|
||||
int32_t startOffset = pCtx->offset;
|
||||
for (int32_t i = pInput->startRowIndex; i < pInput->numOfRows + pInput->startRowIndex; ++i) {
|
||||
char* data = colDataGetData(pInputCol, i);
|
||||
doUniqueAdd(pInfo, data, tsList[i], colDataIsNull_s(pInputCol, i));
|
||||
|
||||
if (sizeof(SUniqueInfo) + pInfo->numOfPoints * (sizeof(SUniqueItem) + pInfo->colBytes) >= UNIQUE_MAX_RESULT_SIZE) {
|
||||
taosHashCleanup(pInfo->pHash);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pInfo->numOfPoints; ++i) {
|
||||
SUniqueItem *pItem = (SUniqueItem *)(pInfo->pItems + i * (sizeof(SUniqueItem) + pInfo->colBytes));
|
||||
colDataAppend(pOutput, i, pItem->data, false);
|
||||
if (pTsOutput != NULL) {
|
||||
colDataAppendInt64(pTsOutput, i, &pItem->timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
return pInfo->numOfPoints;
|
||||
}
|
||||
|
||||
int32_t uniqueFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||
SUniqueInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||
int32_t slotId = pCtx->pExpr->base.resSchema.slotId;
|
||||
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
|
||||
|
||||
for (int32_t i = 0; i < pResInfo->numOfRes; ++i) {
|
||||
SUniqueItem *pItem = (SUniqueItem *)(pInfo->pItems + i * (sizeof(SUniqueItem) + pInfo->colBytes));
|
||||
colDataAppend(pCol, i, pItem->data, false);
|
||||
//TODO: handle ts output
|
||||
}
|
||||
|
||||
return pResInfo->numOfRes;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,16 +27,16 @@
|
|||
#include "trpc.h"
|
||||
|
||||
typedef struct SUdfdContext {
|
||||
uv_loop_t *loop;
|
||||
uv_loop_t * loop;
|
||||
uv_pipe_t ctrlPipe;
|
||||
uv_signal_t intrSignal;
|
||||
char listenPipeName[PATH_MAX + UDF_LISTEN_PIPE_NAME_LEN + 2];
|
||||
uv_pipe_t listeningPipe;
|
||||
|
||||
void *clientRpc;
|
||||
void * clientRpc;
|
||||
SCorEpSet mgmtEp;
|
||||
uv_mutex_t udfsMutex;
|
||||
SHashObj *udfsHash;
|
||||
SHashObj * udfsHash;
|
||||
|
||||
bool printVersion;
|
||||
} SUdfdContext;
|
||||
|
@ -45,7 +45,7 @@ SUdfdContext global;
|
|||
|
||||
typedef struct SUdfdUvConn {
|
||||
uv_stream_t *client;
|
||||
char *inputBuf;
|
||||
char * inputBuf;
|
||||
int32_t inputLen;
|
||||
int32_t inputCap;
|
||||
int32_t inputTotal;
|
||||
|
@ -65,25 +65,25 @@ typedef struct SUdf {
|
|||
uv_mutex_t lock;
|
||||
uv_cond_t condReady;
|
||||
|
||||
char name[TSDB_FUNC_NAME_LEN];
|
||||
int8_t funcType;
|
||||
int8_t scriptType;
|
||||
int8_t outputType;
|
||||
char name[TSDB_FUNC_NAME_LEN];
|
||||
int8_t funcType;
|
||||
int8_t scriptType;
|
||||
int8_t outputType;
|
||||
int32_t outputLen;
|
||||
int32_t bufSize;
|
||||
|
||||
char path[PATH_MAX];
|
||||
char path[PATH_MAX];
|
||||
|
||||
uv_lib_t lib;
|
||||
uv_lib_t lib;
|
||||
|
||||
TUdfScalarProcFunc scalarProcFunc;
|
||||
TUdfScalarProcFunc scalarProcFunc;
|
||||
|
||||
TUdfAggStartFunc aggStartFunc;
|
||||
TUdfAggProcessFunc aggProcFunc;
|
||||
TUdfAggFinishFunc aggFinishFunc;
|
||||
TUdfAggStartFunc aggStartFunc;
|
||||
TUdfAggProcessFunc aggProcFunc;
|
||||
TUdfAggFinishFunc aggFinishFunc;
|
||||
|
||||
TUdfInitFunc initFunc;
|
||||
TUdfDestroyFunc destroyFunc;
|
||||
TUdfInitFunc initFunc;
|
||||
TUdfDestroyFunc destroyFunc;
|
||||
} SUdf;
|
||||
|
||||
// TODO: add private udf structure.
|
||||
|
@ -98,9 +98,9 @@ typedef enum EUdfdRpcReqRspType {
|
|||
|
||||
typedef struct SUdfdRpcSendRecvInfo {
|
||||
EUdfdRpcReqRspType rpcType;
|
||||
int32_t code;
|
||||
void* param;
|
||||
uv_sem_t resultSem;
|
||||
int32_t code;
|
||||
void * param;
|
||||
uv_sem_t resultSem;
|
||||
} SUdfdRpcSendRecvInfo;
|
||||
|
||||
void udfdProcessRpcRsp(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
|
@ -136,7 +136,7 @@ void udfdProcessRpcRsp(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
|||
tDeserializeSRetrieveFuncRsp(pMsg->pCont, pMsg->contLen, &retrieveRsp);
|
||||
|
||||
SFuncInfo *pFuncInfo = (SFuncInfo *)taosArrayGet(retrieveRsp.pFuncInfos, 0);
|
||||
SUdf* udf = msgInfo->param;
|
||||
SUdf * udf = msgInfo->param;
|
||||
udf->funcType = pFuncInfo->funcType;
|
||||
udf->scriptType = pFuncInfo->scriptType;
|
||||
udf->outputType = pFuncInfo->outputType;
|
||||
|
@ -145,7 +145,8 @@ void udfdProcessRpcRsp(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
|||
|
||||
char path[PATH_MAX] = {0};
|
||||
snprintf(path, sizeof(path), "%s/lib%s.so", "/tmp", pFuncInfo->name);
|
||||
TdFilePtr file = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC | TD_FILE_AUTO_DEL);
|
||||
TdFilePtr file =
|
||||
taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC | TD_FILE_AUTO_DEL);
|
||||
// TODO check for failure of flush to disk
|
||||
taosWriteFile(file, pFuncInfo->pCode, pFuncInfo->codeSize);
|
||||
taosCloseFile(&file);
|
||||
|
@ -168,11 +169,11 @@ int32_t udfdFillUdfInfoFromMNode(void *clientRpc, char *udfName, SUdf *udf) {
|
|||
taosArrayPush(retrieveReq.pFuncNames, udfName);
|
||||
|
||||
int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq);
|
||||
void *pReq = rpcMallocCont(contLen);
|
||||
void * pReq = rpcMallocCont(contLen);
|
||||
tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq);
|
||||
taosArrayDestroy(retrieveReq.pFuncNames);
|
||||
|
||||
SUdfdRpcSendRecvInfo* msgInfo = taosMemoryCalloc(1, sizeof(SUdfdRpcSendRecvInfo));
|
||||
SUdfdRpcSendRecvInfo *msgInfo = taosMemoryCalloc(1, sizeof(SUdfdRpcSendRecvInfo));
|
||||
msgInfo->rpcType = UDFD_RPC_RETRIVE_FUNC;
|
||||
msgInfo->param = udf;
|
||||
uv_sem_init(&msgInfo->resultSem, 0);
|
||||
|
@ -194,7 +195,7 @@ int32_t udfdFillUdfInfoFromMNode(void *clientRpc, char *udfName, SUdf *udf) {
|
|||
int32_t udfdConnectToMnode() {
|
||||
SConnectReq connReq = {0};
|
||||
connReq.connType = CONN_TYPE__UDFD;
|
||||
tstrncpy(connReq.app, "udfd",sizeof(connReq.app));
|
||||
tstrncpy(connReq.app, "udfd", sizeof(connReq.app));
|
||||
tstrncpy(connReq.user, TSDB_DEFAULT_USER, sizeof(connReq.user));
|
||||
char pass[TSDB_PASSWORD_LEN + 1] = {0};
|
||||
taosEncryptPass_c((uint8_t *)(TSDB_DEFAULT_PASS), strlen(TSDB_DEFAULT_PASS), pass);
|
||||
|
@ -203,7 +204,7 @@ int32_t udfdConnectToMnode() {
|
|||
connReq.startTime = htobe64(taosGetTimestampMs());
|
||||
|
||||
int32_t contLen = tSerializeSConnectReq(NULL, 0, &connReq);
|
||||
void* pReq = rpcMallocCont(contLen);
|
||||
void * pReq = rpcMallocCont(contLen);
|
||||
tSerializeSConnectReq(pReq, contLen, &connReq);
|
||||
|
||||
SUdfdRpcSendRecvInfo *msgInfo = taosMemoryCalloc(1, sizeof(SUdfdRpcSendRecvInfo));
|
||||
|
@ -240,17 +241,17 @@ int32_t udfdLoadUdf(char *udfName, SUdf *udf) {
|
|||
return TSDB_CODE_UDF_LOAD_UDF_FAILURE;
|
||||
}
|
||||
|
||||
char initFuncName[TSDB_FUNC_NAME_LEN+5] = {0};
|
||||
char initFuncName[TSDB_FUNC_NAME_LEN + 5] = {0};
|
||||
char *initSuffix = "_init";
|
||||
strcpy(initFuncName, udfName);
|
||||
strncat(initFuncName, initSuffix, strlen(initSuffix));
|
||||
uv_dlsym(&udf->lib, initFuncName, (void**)(&udf->initFunc));
|
||||
uv_dlsym(&udf->lib, initFuncName, (void **)(&udf->initFunc));
|
||||
|
||||
char destroyFuncName[TSDB_FUNC_NAME_LEN+5] = {0};
|
||||
char destroyFuncName[TSDB_FUNC_NAME_LEN + 5] = {0};
|
||||
char *destroySuffix = "_destroy";
|
||||
strcpy(destroyFuncName, udfName);
|
||||
strncat(destroyFuncName, destroySuffix, strlen(destroySuffix));
|
||||
uv_dlsym(&udf->lib, destroyFuncName, (void**)(&udf->destroyFunc));
|
||||
uv_dlsym(&udf->lib, destroyFuncName, (void **)(&udf->destroyFunc));
|
||||
|
||||
if (udf->funcType == TSDB_FUNC_TYPE_SCALAR) {
|
||||
char processFuncName[TSDB_FUNC_NAME_LEN] = {0};
|
||||
|
@ -270,87 +271,86 @@ int32_t udfdLoadUdf(char *udfName, SUdf *udf) {
|
|||
strncpy(finishFuncName, processFuncName, strlen(processFuncName));
|
||||
strncat(finishFuncName, finishSuffix, strlen(finishSuffix));
|
||||
uv_dlsym(&udf->lib, finishFuncName, (void **)(&udf->aggFinishFunc));
|
||||
//TODO: merge
|
||||
// TODO: merge
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void udfdProcessSetupRequest(SUvUdfWork* uvUdf, SUdfRequest* request) {
|
||||
// TODO: tracable id from client. connect, setup, call, teardown
|
||||
fnInfo( "setup request. seq num: %" PRId64 ", udf name: %s", request->seqNum, request->setup.udfName);
|
||||
SUdfSetupRequest *setup = &request->setup;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SUdf *udf = NULL;
|
||||
uv_mutex_lock(&global.udfsMutex);
|
||||
SUdf **udfInHash = taosHashGet(global.udfsHash, request->setup.udfName, strlen(request->setup.udfName));
|
||||
if (udfInHash) {
|
||||
++(*udfInHash)->refCount;
|
||||
udf = *udfInHash;
|
||||
uv_mutex_unlock(&global.udfsMutex);
|
||||
} else {
|
||||
SUdf *udfNew = taosMemoryCalloc(1, sizeof(SUdf));
|
||||
udfNew->refCount = 1;
|
||||
udfNew->state = UDF_STATE_INIT;
|
||||
void udfdProcessSetupRequest(SUvUdfWork *uvUdf, SUdfRequest *request) {
|
||||
// TODO: tracable id from client. connect, setup, call, teardown
|
||||
fnInfo("setup request. seq num: %" PRId64 ", udf name: %s", request->seqNum, request->setup.udfName);
|
||||
SUdfSetupRequest *setup = &request->setup;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SUdf * udf = NULL;
|
||||
uv_mutex_lock(&global.udfsMutex);
|
||||
SUdf **udfInHash = taosHashGet(global.udfsHash, request->setup.udfName, strlen(request->setup.udfName));
|
||||
if (udfInHash) {
|
||||
++(*udfInHash)->refCount;
|
||||
udf = *udfInHash;
|
||||
uv_mutex_unlock(&global.udfsMutex);
|
||||
} else {
|
||||
SUdf *udfNew = taosMemoryCalloc(1, sizeof(SUdf));
|
||||
udfNew->refCount = 1;
|
||||
udfNew->state = UDF_STATE_INIT;
|
||||
|
||||
uv_mutex_init(&udfNew->lock);
|
||||
uv_cond_init(&udfNew->condReady);
|
||||
udf = udfNew;
|
||||
taosHashPut(global.udfsHash, request->setup.udfName, strlen(request->setup.udfName), &udfNew, sizeof(&udfNew));
|
||||
uv_mutex_unlock(&global.udfsMutex);
|
||||
uv_mutex_init(&udfNew->lock);
|
||||
uv_cond_init(&udfNew->condReady);
|
||||
udf = udfNew;
|
||||
taosHashPut(global.udfsHash, request->setup.udfName, strlen(request->setup.udfName), &udfNew, sizeof(&udfNew));
|
||||
uv_mutex_unlock(&global.udfsMutex);
|
||||
}
|
||||
|
||||
uv_mutex_lock(&udf->lock);
|
||||
if (udf->state == UDF_STATE_INIT) {
|
||||
udf->state = UDF_STATE_LOADING;
|
||||
code = udfdLoadUdf(setup->udfName, udf);
|
||||
if (udf->initFunc) {
|
||||
udf->initFunc();
|
||||
}
|
||||
|
||||
uv_mutex_lock(&udf->lock);
|
||||
if (udf->state == UDF_STATE_INIT) {
|
||||
udf->state = UDF_STATE_LOADING;
|
||||
code = udfdLoadUdf(setup->udfName, udf);
|
||||
if (udf->initFunc) {
|
||||
udf->initFunc();
|
||||
}
|
||||
udf->state = UDF_STATE_READY;
|
||||
uv_cond_broadcast(&udf->condReady);
|
||||
uv_mutex_unlock(&udf->lock);
|
||||
} else {
|
||||
while (udf->state != UDF_STATE_READY) {
|
||||
uv_cond_wait(&udf->condReady, &udf->lock);
|
||||
}
|
||||
uv_mutex_unlock(&udf->lock);
|
||||
udf->state = UDF_STATE_READY;
|
||||
uv_cond_broadcast(&udf->condReady);
|
||||
uv_mutex_unlock(&udf->lock);
|
||||
} else {
|
||||
while (udf->state != UDF_STATE_READY) {
|
||||
uv_cond_wait(&udf->condReady, &udf->lock);
|
||||
}
|
||||
SUdfcFuncHandle *handle = taosMemoryMalloc(sizeof(SUdfcFuncHandle));
|
||||
handle->udf = udf;
|
||||
uv_mutex_unlock(&udf->lock);
|
||||
}
|
||||
SUdfcFuncHandle *handle = taosMemoryMalloc(sizeof(SUdfcFuncHandle));
|
||||
handle->udf = udf;
|
||||
|
||||
SUdfResponse rsp;
|
||||
rsp.seqNum = request->seqNum;
|
||||
rsp.type = request->type;
|
||||
rsp.code = code;
|
||||
rsp.setupRsp.udfHandle = (int64_t)(handle);
|
||||
rsp.setupRsp.outputType = udf->outputType;
|
||||
rsp.setupRsp.outputLen = udf->outputLen;
|
||||
rsp.setupRsp.bufSize = udf->bufSize;
|
||||
SUdfResponse rsp;
|
||||
rsp.seqNum = request->seqNum;
|
||||
rsp.type = request->type;
|
||||
rsp.code = code;
|
||||
rsp.setupRsp.udfHandle = (int64_t)(handle);
|
||||
rsp.setupRsp.outputType = udf->outputType;
|
||||
rsp.setupRsp.outputLen = udf->outputLen;
|
||||
rsp.setupRsp.bufSize = udf->bufSize;
|
||||
|
||||
int32_t len = encodeUdfResponse(NULL, &rsp);
|
||||
rsp.msgLen = len;
|
||||
void *bufBegin = taosMemoryMalloc(len);
|
||||
void *buf = bufBegin;
|
||||
encodeUdfResponse(&buf, &rsp);
|
||||
int32_t len = encodeUdfResponse(NULL, &rsp);
|
||||
rsp.msgLen = len;
|
||||
void *bufBegin = taosMemoryMalloc(len);
|
||||
void *buf = bufBegin;
|
||||
encodeUdfResponse(&buf, &rsp);
|
||||
|
||||
uvUdf->output = uv_buf_init(bufBegin, len);
|
||||
uvUdf->output = uv_buf_init(bufBegin, len);
|
||||
|
||||
taosMemoryFree(uvUdf->input.base);
|
||||
return;
|
||||
taosMemoryFree(uvUdf->input.base);
|
||||
return;
|
||||
}
|
||||
|
||||
void udfdProcessCallRequest(SUvUdfWork *uvUdf, SUdfRequest *request) {
|
||||
SUdfCallRequest *call = &request->call;
|
||||
fnDebug("%" PRId64 "call request. call type %d, handle: %" PRIx64, request->seqNum, call->callType,
|
||||
call->udfHandle);
|
||||
SUdfcFuncHandle *handle = (SUdfcFuncHandle *)(call->udfHandle);
|
||||
SUdf *udf = handle->udf;
|
||||
SUdfResponse response = {0};
|
||||
SUdfResponse *rsp = &response;
|
||||
fnDebug("%" PRId64 "call request. call type %d, handle: %" PRIx64, request->seqNum, call->callType, call->udfHandle);
|
||||
SUdfcFuncHandle * handle = (SUdfcFuncHandle *)(call->udfHandle);
|
||||
SUdf * udf = handle->udf;
|
||||
SUdfResponse response = {0};
|
||||
SUdfResponse * rsp = &response;
|
||||
SUdfCallResponse *subRsp = &rsp->callRsp;
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
switch(call->callType) {
|
||||
switch (call->callType) {
|
||||
case TSDB_UDF_CALL_SCALA_PROC: {
|
||||
SUdfColumn output = {0};
|
||||
|
||||
|
@ -363,9 +363,7 @@ void udfdProcessCallRequest(SUvUdfWork *uvUdf, SUdfRequest *request) {
|
|||
break;
|
||||
}
|
||||
case TSDB_UDF_CALL_AGG_INIT: {
|
||||
SUdfInterBuf outBuf = {.buf = taosMemoryMalloc(udf->bufSize),
|
||||
.bufLen= udf->bufSize,
|
||||
.numOfResult = 0};
|
||||
SUdfInterBuf outBuf = {.buf = taosMemoryMalloc(udf->bufSize), .bufLen = udf->bufSize, .numOfResult = 0};
|
||||
udf->aggStartFunc(&outBuf);
|
||||
subRsp->resultBuf = outBuf;
|
||||
break;
|
||||
|
@ -373,9 +371,7 @@ void udfdProcessCallRequest(SUvUdfWork *uvUdf, SUdfRequest *request) {
|
|||
case TSDB_UDF_CALL_AGG_PROC: {
|
||||
SUdfDataBlock input = {0};
|
||||
convertDataBlockToUdfDataBlock(&call->block, &input);
|
||||
SUdfInterBuf outBuf = {.buf = taosMemoryMalloc(udf->bufSize),
|
||||
.bufLen= udf->bufSize,
|
||||
.numOfResult = 0};
|
||||
SUdfInterBuf outBuf = {.buf = taosMemoryMalloc(udf->bufSize), .bufLen = udf->bufSize, .numOfResult = 0};
|
||||
code = udf->aggProcFunc(&input, &call->interBuf, &outBuf);
|
||||
freeUdfInterBuf(&call->interBuf);
|
||||
freeUdfDataDataBlock(&input);
|
||||
|
@ -384,9 +380,7 @@ void udfdProcessCallRequest(SUvUdfWork *uvUdf, SUdfRequest *request) {
|
|||
break;
|
||||
}
|
||||
case TSDB_UDF_CALL_AGG_FIN: {
|
||||
SUdfInterBuf outBuf = {.buf = taosMemoryMalloc(udf->bufSize),
|
||||
.bufLen= udf->bufSize,
|
||||
.numOfResult = 0};
|
||||
SUdfInterBuf outBuf = {.buf = taosMemoryMalloc(udf->bufSize), .bufLen = udf->bufSize, .numOfResult = 0};
|
||||
code = udf->aggFinishFunc(&call->interBuf, &outBuf);
|
||||
freeUdfInterBuf(&call->interBuf);
|
||||
subRsp->resultBuf = outBuf;
|
||||
|
@ -429,20 +423,19 @@ void udfdProcessCallRequest(SUvUdfWork *uvUdf, SUdfRequest *request) {
|
|||
}
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
taosMemoryFree(uvUdf->input.base);
|
||||
return;
|
||||
}
|
||||
|
||||
void udfdProcessTeardownRequest(SUvUdfWork* uvUdf, SUdfRequest* request) {
|
||||
void udfdProcessTeardownRequest(SUvUdfWork *uvUdf, SUdfRequest *request) {
|
||||
SUdfTeardownRequest *teardown = &request->teardown;
|
||||
fnInfo("teardown. seq number: %" PRId64 ", handle:%" PRIx64, request->seqNum, teardown->udfHandle);
|
||||
SUdfcFuncHandle *handle = (SUdfcFuncHandle *)(teardown->udfHandle);
|
||||
SUdf *udf = handle->udf;
|
||||
bool unloadUdf = false;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SUdf * udf = handle->udf;
|
||||
bool unloadUdf = false;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
uv_mutex_lock(&global.udfsMutex);
|
||||
udf->refCount--;
|
||||
|
@ -568,7 +561,7 @@ bool isUdfdUvMsgComplete(SUdfdUvConn *pipe) {
|
|||
}
|
||||
|
||||
void udfdHandleRequest(SUdfdUvConn *conn) {
|
||||
uv_work_t *work = taosMemoryMalloc(sizeof(uv_work_t));
|
||||
uv_work_t * work = taosMemoryMalloc(sizeof(uv_work_t));
|
||||
SUvUdfWork *udfWork = taosMemoryMalloc(sizeof(SUvUdfWork));
|
||||
udfWork->client = conn->client;
|
||||
udfWork->input = uv_buf_init(conn->inputBuf, conn->inputLen);
|
||||
|
@ -653,11 +646,11 @@ static bool udfdRpcRfp(int32_t code) {
|
|||
}
|
||||
}
|
||||
|
||||
int initEpSetFromCfg(const char* firstEp, const char* secondEp, SCorEpSet* pEpSet) {
|
||||
int initEpSetFromCfg(const char *firstEp, const char *secondEp, SCorEpSet *pEpSet) {
|
||||
pEpSet->version = 0;
|
||||
|
||||
// init mnode ip set
|
||||
SEpSet* mgmtEpSet = &(pEpSet->epSet);
|
||||
SEpSet *mgmtEpSet = &(pEpSet->epSet);
|
||||
mgmtEpSet->numOfEps = 0;
|
||||
mgmtEpSet->inUse = 0;
|
||||
|
||||
|
@ -694,7 +687,6 @@ int initEpSetFromCfg(const char* firstEp, const char* secondEp, SCorEpSet* pEpSe
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int32_t udfdOpenClientRpc() {
|
||||
SRpcInit rpcInit = {0};
|
||||
rpcInit.label = "UDFD";
|
||||
|
@ -704,15 +696,9 @@ int32_t udfdOpenClientRpc() {
|
|||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
rpcInit.idleTime = tsShellActivityTimer * 1000;
|
||||
rpcInit.user = TSDB_DEFAULT_USER;
|
||||
rpcInit.ckey = "key";
|
||||
rpcInit.spi = 1;
|
||||
rpcInit.parent = &global;
|
||||
rpcInit.rfp = udfdRpcRfp;
|
||||
|
||||
char pass[TSDB_PASSWORD_LEN + 1] = {0};
|
||||
taosEncryptPass_c((uint8_t *)(TSDB_DEFAULT_PASS), strlen(TSDB_DEFAULT_PASS), pass);
|
||||
rpcInit.secret = pass;
|
||||
|
||||
global.clientRpc = rpcOpen(&rpcInit);
|
||||
if (global.clientRpc == NULL) {
|
||||
fnError("failed to init dnode rpc client");
|
||||
|
@ -823,7 +809,7 @@ static int32_t udfdUvInit() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void udfdCloseWalkCb(uv_handle_t* handle, void* arg) {
|
||||
static void udfdCloseWalkCb(uv_handle_t *handle, void *arg) {
|
||||
if (!uv_is_closing(handle)) {
|
||||
uv_close(handle, NULL);
|
||||
}
|
||||
|
@ -883,7 +869,7 @@ int main(int argc, char *argv[]) {
|
|||
int32_t retryMnodeTimes = 0;
|
||||
int32_t code = 0;
|
||||
while (retryMnodeTimes++ < TSDB_MAX_REPLICA) {
|
||||
uv_sleep(500 * ( 1 << retryMnodeTimes));
|
||||
uv_sleep(500 * (1 << retryMnodeTimes));
|
||||
code = udfdConnectToMnode();
|
||||
if (code == 0) {
|
||||
break;
|
||||
|
|
|
@ -26,7 +26,7 @@ int32_t udf2_start(SUdfInterBuf *buf) {
|
|||
|
||||
int32_t udf2(SUdfDataBlock* block, SUdfInterBuf *interBuf, SUdfInterBuf *newInterBuf) {
|
||||
double sumSquares = *(double*)interBuf->buf;
|
||||
int8_t numOutput = 0;
|
||||
int8_t numNotNull = 0;
|
||||
for (int32_t i = 0; i < block->numOfCols; ++i) {
|
||||
SUdfColumn* col = block->udfCols[i];
|
||||
if (!(col->colMeta.type == TSDB_DATA_TYPE_INT ||
|
||||
|
@ -56,15 +56,14 @@ int32_t udf2(SUdfDataBlock* block, SUdfInterBuf *interBuf, SUdfInterBuf *newInte
|
|||
default:
|
||||
break;
|
||||
}
|
||||
numOutput = 1;
|
||||
++numNotNull;
|
||||
}
|
||||
}
|
||||
|
||||
if (numOutput == 1) {
|
||||
*(double*)(newInterBuf->buf) = sumSquares;
|
||||
newInterBuf->bufLen = sizeof(double);
|
||||
}
|
||||
if (interBuf->numOfResult == 0 && numOutput == 0) {
|
||||
*(double*)(newInterBuf->buf) = sumSquares;
|
||||
newInterBuf->bufLen = sizeof(double);
|
||||
|
||||
if (interBuf->numOfResult == 0 && numNotNull == 0) {
|
||||
newInterBuf->numOfResult = 0;
|
||||
} else {
|
||||
newInterBuf->numOfResult = 1;
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#define MAX_INDEX_KEY_LEN 256 // test only, change later
|
||||
|
||||
#define MEM_TERM_LIMIT 10 * 10000
|
||||
#define MEM_THRESHOLD 1024 * 1024
|
||||
#define MEM_THRESHOLD 64 * 1024
|
||||
#define MEM_ESTIMATE_RADIO 1.5
|
||||
|
||||
static void indexMemRef(MemTable* tbl);
|
||||
|
|
|
@ -99,7 +99,7 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes* nodes, FstSlice bs, Output
|
|||
if (fstSliceIsEmpty(s)) {
|
||||
return;
|
||||
}
|
||||
size_t sz = taosArrayGetSize(nodes->stack) - 1;
|
||||
int32_t sz = taosArrayGetSize(nodes->stack) - 1;
|
||||
FstBuilderNodeUnfinished* un = taosArrayGet(nodes->stack, sz);
|
||||
assert(un->last == NULL);
|
||||
|
||||
|
@ -130,11 +130,11 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes* nodes, FstSlice bs, Output
|
|||
uint64_t fstUnFinishedNodesFindCommPrefix(FstUnFinishedNodes* node, FstSlice bs) {
|
||||
FstSlice* s = &bs;
|
||||
|
||||
size_t ssz = taosArrayGetSize(node->stack); // stack size
|
||||
int32_t ssz = taosArrayGetSize(node->stack); // stack size
|
||||
uint64_t count = 0;
|
||||
int32_t lsz; // data len
|
||||
uint8_t* data = fstSliceData(s, &lsz);
|
||||
for (size_t i = 0; i < ssz && i < lsz; i++) {
|
||||
for (int32_t i = 0; i < ssz && i < lsz; i++) {
|
||||
FstBuilderNodeUnfinished* un = taosArrayGet(node->stack, i);
|
||||
if (un->last->inp == data[i]) {
|
||||
count++;
|
||||
|
@ -147,8 +147,8 @@ uint64_t fstUnFinishedNodesFindCommPrefix(FstUnFinishedNodes* node, FstSlice bs)
|
|||
uint64_t fstUnFinishedNodesFindCommPrefixAndSetOutput(FstUnFinishedNodes* node, FstSlice bs, Output in, Output* out) {
|
||||
FstSlice* s = &bs;
|
||||
|
||||
size_t lsz = (size_t)(s->end - s->start + 1); // data len
|
||||
size_t ssz = taosArrayGetSize(node->stack); // stack size
|
||||
int32_t lsz = (size_t)(s->end - s->start + 1); // data len
|
||||
int32_t ssz = taosArrayGetSize(node->stack); // stack size
|
||||
*out = in;
|
||||
uint64_t i = 0;
|
||||
for (i = 0; i < lsz && i < ssz; i++) {
|
||||
|
@ -245,7 +245,7 @@ void fstStateCompileForOneTrans(FstCountingWriter* w, CompiledAddr addr, FstTran
|
|||
return;
|
||||
}
|
||||
void fstStateCompileForAnyTrans(FstCountingWriter* w, CompiledAddr addr, FstBuilderNode* node) {
|
||||
size_t sz = taosArrayGetSize(node->trans);
|
||||
int32_t sz = taosArrayGetSize(node->trans);
|
||||
assert(sz <= 256);
|
||||
|
||||
uint8_t tSize = 0;
|
||||
|
@ -253,7 +253,7 @@ void fstStateCompileForAnyTrans(FstCountingWriter* w, CompiledAddr addr, FstBuil
|
|||
|
||||
// finalOutput.is_zero()
|
||||
bool anyOuts = (node->finalOutput != 0);
|
||||
for (size_t i = 0; i < sz; i++) {
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
FstTransition* t = taosArrayGet(node->trans, i);
|
||||
tSize = TMAX(tSize, packDeltaSize(addr, t->addr));
|
||||
oSize = TMAX(oSize, packSize(t->out));
|
||||
|
@ -301,7 +301,7 @@ void fstStateCompileForAnyTrans(FstCountingWriter* w, CompiledAddr addr, FstBuil
|
|||
/// for (uint8_t i = 0; i < 256; i++) {
|
||||
// index[i] = 255;
|
||||
///}
|
||||
for (size_t i = 0; i < sz; i++) {
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
FstTransition* t = taosArrayGet(node->trans, i);
|
||||
index[t->inp] = i;
|
||||
// fstPackDeltaIn(w, addr, t->addr, tSize);
|
||||
|
@ -731,7 +731,7 @@ bool fstNodeFindInput(FstNode* node, uint8_t b, uint64_t* res) {
|
|||
}
|
||||
|
||||
bool fstNodeCompile(FstNode* node, void* w, CompiledAddr lastAddr, CompiledAddr addr, FstBuilderNode* builderNode) {
|
||||
size_t sz = taosArrayGetSize(builderNode->trans);
|
||||
int32_t sz = taosArrayGetSize(builderNode->trans);
|
||||
assert(sz < 256);
|
||||
if (sz == 0 && builderNode->isFinal && builderNode->finalOutput == 0) {
|
||||
return true;
|
||||
|
@ -959,8 +959,8 @@ void fstBuilderNodeUnfinishedAddOutputPrefix(FstBuilderNodeUnfinished* unNode, O
|
|||
if (FST_BUILDER_NODE_IS_FINAL(unNode->node)) {
|
||||
unNode->node->finalOutput += out;
|
||||
}
|
||||
size_t sz = taosArrayGetSize(unNode->node->trans);
|
||||
for (size_t i = 0; i < sz; i++) {
|
||||
int32_t sz = taosArrayGetSize(unNode->node->trans);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
FstTransition* trn = taosArrayGet(unNode->node->trans, i);
|
||||
trn->out += out;
|
||||
}
|
||||
|
@ -1077,7 +1077,7 @@ bool fstGet(Fst* fst, FstSlice* b, Output* out) {
|
|||
tOut = tOut + FST_NODE_FINAL_OUTPUT(root);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < taosArrayGetSize(nodes); i++) {
|
||||
for (int32_t i = 0; i < taosArrayGetSize(nodes); i++) {
|
||||
FstNode** node = (FstNode**)taosArrayGet(nodes, i);
|
||||
fstNodeDestroy(*node);
|
||||
}
|
||||
|
@ -1352,7 +1352,7 @@ StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallb
|
|||
StreamState s2 = {.node = nextNode, .trans = 0, .out = {.null = false, .out = out}, .autState = nextState};
|
||||
taosArrayPush(sws->stack, &s2);
|
||||
|
||||
size_t isz = taosArrayGetSize(sws->inp);
|
||||
int32_t isz = taosArrayGetSize(sws->inp);
|
||||
uint8_t* buf = (uint8_t*)taosMemoryMalloc(isz * sizeof(uint8_t));
|
||||
for (uint32_t i = 0; i < isz; i++) {
|
||||
buf[i] = *(uint8_t*)taosArrayGet(sws->inp, i);
|
||||
|
|
|
@ -116,7 +116,7 @@ TFileCache* tfileCacheCreate(const char* path) {
|
|||
continue;
|
||||
}
|
||||
TFileHeader* header = &reader->header;
|
||||
ICacheKey key = {.suid = header->suid, .colName = header->colName, .nColName = strlen(header->colName)};
|
||||
ICacheKey key = {.suid = header->suid, .colName = header->colName, .nColName = (int32_t)strlen(header->colName)};
|
||||
|
||||
char buf[128] = {0};
|
||||
int32_t sz = indexSerialCacheKey(&key, buf);
|
||||
|
@ -230,7 +230,7 @@ static int32_t tfSearchTerm(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
|
|||
indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, found table info in tindex, time cost: %" PRIu64 "us",
|
||||
tem->suid, tem->colName, tem->colVal, cost);
|
||||
|
||||
ret = tfileReaderLoadTableIds((TFileReader*)reader, offset, tr->total);
|
||||
ret = tfileReaderLoadTableIds((TFileReader*)reader, (int32_t)offset, tr->total);
|
||||
cost = taosGetTimestampUs() - et;
|
||||
indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, load all table info, time cost: %" PRIu64 "us", tem->suid,
|
||||
tem->colName, tem->colVal, cost);
|
||||
|
@ -890,7 +890,7 @@ static int tfileWriteFooter(TFileWriter* write) {
|
|||
char buf[sizeof(tfileMagicNumber) + 1] = {0};
|
||||
void* pBuf = (void*)buf;
|
||||
taosEncodeFixedU64((void**)(void*)&pBuf, tfileMagicNumber);
|
||||
int nwrite = write->ctx->write(write->ctx, buf, strlen(buf));
|
||||
int nwrite = write->ctx->write(write->ctx, buf, (int32_t)strlen(buf));
|
||||
|
||||
indexInfo("tfile write footer size: %d", write->ctx->size(write->ctx));
|
||||
assert(nwrite == sizeof(tfileMagicNumber));
|
||||
|
|
|
@ -37,14 +37,14 @@ static int iBinarySearch(SArray *arr, int s, int e, uint64_t k) {
|
|||
}
|
||||
|
||||
void iIntersection(SArray *inters, SArray *final) {
|
||||
int32_t sz = taosArrayGetSize(inters);
|
||||
int32_t sz = (int32_t)taosArrayGetSize(inters);
|
||||
if (sz <= 0) {
|
||||
return;
|
||||
}
|
||||
MergeIndex *mi = taosMemoryCalloc(sz, sizeof(MergeIndex));
|
||||
for (int i = 0; i < sz; i++) {
|
||||
SArray *t = taosArrayGetP(inters, i);
|
||||
mi[i].len = taosArrayGetSize(t);
|
||||
mi[i].len = (int32_t)taosArrayGetSize(t);
|
||||
mi[i].idx = 0;
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ void iIntersection(SArray *inters, SArray *final) {
|
|||
taosMemoryFreeClear(mi);
|
||||
}
|
||||
void iUnion(SArray *inters, SArray *final) {
|
||||
int32_t sz = taosArrayGetSize(inters);
|
||||
int32_t sz = (int32_t)taosArrayGetSize(inters);
|
||||
if (sz <= 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ void iUnion(SArray *inters, SArray *final) {
|
|||
MergeIndex *mi = taosMemoryCalloc(sz, sizeof(MergeIndex));
|
||||
for (int i = 0; i < sz; i++) {
|
||||
SArray *t = taosArrayGetP(inters, i);
|
||||
mi[i].len = taosArrayGetSize(t);
|
||||
mi[i].len = (int32_t)taosArrayGetSize(t);
|
||||
mi[i].idx = 0;
|
||||
}
|
||||
while (1) {
|
||||
|
@ -117,8 +117,8 @@ void iUnion(SArray *inters, SArray *final) {
|
|||
}
|
||||
|
||||
void iExcept(SArray *total, SArray *except) {
|
||||
int32_t tsz = taosArrayGetSize(total);
|
||||
int32_t esz = taosArrayGetSize(except);
|
||||
int32_t tsz = (int32_t)taosArrayGetSize(total);
|
||||
int32_t esz = (int32_t)taosArrayGetSize(except);
|
||||
if (esz == 0 || tsz == 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -141,7 +141,10 @@ int uidCompare(const void *a, const void *b) {
|
|||
// add more version compare
|
||||
uint64_t u1 = *(uint64_t *)a;
|
||||
uint64_t u2 = *(uint64_t *)b;
|
||||
return u1 - u2;
|
||||
if (u1 == u2) {
|
||||
return 0;
|
||||
}
|
||||
return u1 < u2 ? -1 : 1;
|
||||
}
|
||||
int verdataCompare(const void *a, const void *b) {
|
||||
SIdxVerdata *va = (SIdxVerdata *)a;
|
||||
|
|
|
@ -92,7 +92,19 @@ target_link_libraries (jsonUT
|
|||
index
|
||||
)
|
||||
|
||||
#add_test(
|
||||
# NAME index_test
|
||||
# COMMAND indexTest
|
||||
#)
|
||||
add_test(
|
||||
NAME idxtest
|
||||
COMMAND indexTest
|
||||
)
|
||||
add_test(
|
||||
NAME idxJsonUT
|
||||
COMMAND jsonUT
|
||||
)
|
||||
add_test(
|
||||
NAME idxUtilUT
|
||||
COMMAND UtilUT
|
||||
)
|
||||
add_test(
|
||||
NAME idxFstUT
|
||||
COMMAND fstUT
|
||||
)
|
||||
|
|
|
@ -48,7 +48,7 @@ class FstWriter {
|
|||
|
||||
class FstReadMemory {
|
||||
public:
|
||||
FstReadMemory(size_t size, const std::string& fileName = "/tmp/tindex.tindex") {
|
||||
FstReadMemory(int32_t size, const std::string& fileName = "/tmp/tindex.tindex") {
|
||||
_wc = writerCtxCreate(TFile, fileName.c_str(), true, 64 * 1024);
|
||||
_w = fstCountingWriterCreate(_wc);
|
||||
_size = size;
|
||||
|
@ -152,7 +152,7 @@ class FstReadMemory {
|
|||
Fst* _fst;
|
||||
FstSlice _s;
|
||||
WriterCtx* _wc;
|
||||
size_t _size;
|
||||
int32_t _size;
|
||||
};
|
||||
|
||||
#define L 100
|
||||
|
|
|
@ -714,7 +714,7 @@ class IndexObj {
|
|||
return numOfTable;
|
||||
}
|
||||
int ReadMultiMillonData(const std::string& colName, const std::string& colVal = "Hello world",
|
||||
size_t numOfTable = 100 * 10000) {
|
||||
size_t numOfTable = 100) {
|
||||
std::string tColVal = colVal;
|
||||
|
||||
int colValSize = tColVal.size();
|
||||
|
@ -896,7 +896,7 @@ TEST_F(IndexEnv2, testIndex_TrigeFlush) {
|
|||
// r
|
||||
std::cout << "failed to init" << std::endl;
|
||||
}
|
||||
int numOfTable = 100 * 10000;
|
||||
int numOfTable = 100 * 100;
|
||||
index->WriteMillonData("tag1", "Hello Wolrd", numOfTable);
|
||||
int target = index->SearchOne("tag1", "Hello Wolrd");
|
||||
std::cout << "Get Index: " << target << std::endl;
|
||||
|
@ -910,8 +910,8 @@ static void single_write_and_search(IndexObj* idx) {
|
|||
static void multi_write_and_search(IndexObj* idx) {
|
||||
int target = idx->SearchOne("tag1", "Hello");
|
||||
target = idx->SearchOne("tag2", "Test");
|
||||
idx->WriteMultiMillonData("tag1", "hello world test", 100 * 10000);
|
||||
idx->WriteMultiMillonData("tag2", "world test nothing", 100 * 10000);
|
||||
idx->WriteMultiMillonData("tag1", "hello world test", 100 * 100);
|
||||
idx->WriteMultiMillonData("tag2", "world test nothing", 100 * 10);
|
||||
}
|
||||
TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) {
|
||||
std::string path = "/tmp/cache_and_tfile";
|
||||
|
@ -920,8 +920,8 @@ TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) {
|
|||
}
|
||||
index->PutOne("tag1", "Hello");
|
||||
index->PutOne("tag2", "Test");
|
||||
index->WriteMultiMillonData("tag1", "Hello", 100 * 10000);
|
||||
index->WriteMultiMillonData("tag2", "Test", 100 * 10000);
|
||||
index->WriteMultiMillonData("tag1", "Hello", 100 * 100);
|
||||
index->WriteMultiMillonData("tag2", "Test", 100 * 100);
|
||||
std::thread threads[NUM_OF_THREAD];
|
||||
|
||||
for (int i = 0; i < NUM_OF_THREAD; i++) {
|
||||
|
@ -949,49 +949,49 @@ TEST_F(IndexEnv2, testIndex_MultiWrite_and_MultiRead) {
|
|||
}
|
||||
}
|
||||
|
||||
TEST_F(IndexEnv2, testIndex_restart) {
|
||||
std::string path = "/tmp/cache_and_tfile";
|
||||
if (index->Init(path) != 0) {
|
||||
}
|
||||
index->SearchOneTarget("tag1", "Hello", 10);
|
||||
index->SearchOneTarget("tag2", "Test", 10);
|
||||
}
|
||||
TEST_F(IndexEnv2, testIndex_restart1) {
|
||||
std::string path = "/tmp/cache_and_tfile";
|
||||
if (index->Init(path) != 0) {
|
||||
}
|
||||
index->ReadMultiMillonData("tag1", "coding");
|
||||
index->SearchOneTarget("tag1", "Hello", 10);
|
||||
index->SearchOneTarget("tag2", "Test", 10);
|
||||
}
|
||||
// TEST_F(IndexEnv2, testIndex_restart) {
|
||||
// std::string path = "/tmp/cache_and_tfile";
|
||||
// if (index->Init(path) != 0) {
|
||||
// }
|
||||
// index->SearchOneTarget("tag1", "Hello", 10);
|
||||
// index->SearchOneTarget("tag2", "Test", 10);
|
||||
//}
|
||||
// TEST_F(IndexEnv2, testIndex_restart1) {
|
||||
// std::string path = "/tmp/cache_and_tfile";
|
||||
// if (index->Init(path) != 0) {
|
||||
// }
|
||||
// index->ReadMultiMillonData("tag1", "coding");
|
||||
// index->SearchOneTarget("tag1", "Hello", 10);
|
||||
// index->SearchOneTarget("tag2", "Test", 10);
|
||||
//}
|
||||
|
||||
TEST_F(IndexEnv2, testIndex_read_performance) {
|
||||
std::string path = "/tmp/cache_and_tfile";
|
||||
if (index->Init(path) != 0) {
|
||||
}
|
||||
index->PutOneTarge("tag1", "Hello", 12);
|
||||
index->PutOneTarge("tag1", "Hello", 15);
|
||||
index->ReadMultiMillonData("tag1", "Hello");
|
||||
std::cout << "reader sz: " << index->SearchOne("tag1", "Hello") << std::endl;
|
||||
assert(3 == index->SearchOne("tag1", "Hello"));
|
||||
}
|
||||
TEST_F(IndexEnv2, testIndexMultiTag) {
|
||||
std::string path = "/tmp/multi_tag";
|
||||
if (index->Init(path) != 0) {
|
||||
}
|
||||
int64_t st = taosGetTimestampUs();
|
||||
int32_t num = 1000 * 10000;
|
||||
index->WriteMultiMillonData("tag1", "xxxxxxxxxxxxxxx", num);
|
||||
std::cout << "numOfRow: " << num << "\ttime cost:" << taosGetTimestampUs() - st << std::endl;
|
||||
// index->WriteMultiMillonData("tag2", "xxxxxxxxxxxxxxxxxxxxxxxxx", 100 * 10000);
|
||||
}
|
||||
// TEST_F(IndexEnv2, testIndex_read_performance) {
|
||||
// std::string path = "/tmp/cache_and_tfile";
|
||||
// if (index->Init(path) != 0) {
|
||||
// }
|
||||
// index->PutOneTarge("tag1", "Hello", 12);
|
||||
// index->PutOneTarge("tag1", "Hello", 15);
|
||||
// index->ReadMultiMillonData("tag1", "Hello");
|
||||
// std::cout << "reader sz: " << index->SearchOne("tag1", "Hello") << std::endl;
|
||||
// assert(3 == index->SearchOne("tag1", "Hello"));
|
||||
//}
|
||||
// TEST_F(IndexEnv2, testIndexMultiTag) {
|
||||
// std::string path = "/tmp/multi_tag";
|
||||
// if (index->Init(path) != 0) {
|
||||
// }
|
||||
// int64_t st = taosGetTimestampUs();
|
||||
// int32_t num = 1000 * 10000;
|
||||
// index->WriteMultiMillonData("tag1", "xxxxxxxxxxxxxxx", num);
|
||||
// std::cout << "numOfRow: " << num << "\ttime cost:" << taosGetTimestampUs() - st << std::endl;
|
||||
// // index->WriteMultiMillonData("tag2", "xxxxxxxxxxxxxxxxxxxxxxxxx", 100 * 10000);
|
||||
//}
|
||||
TEST_F(IndexEnv2, testLongComVal1) {
|
||||
std::string path = "/tmp/long_colVal";
|
||||
if (index->Init(path) != 0) {
|
||||
}
|
||||
// gen colVal by randstr
|
||||
std::string randstr = "xxxxxxxxxxxxxxxxx";
|
||||
index->WriteMultiMillonData("tag1", randstr, 100 * 10000);
|
||||
index->WriteMultiMillonData("tag1", randstr, 100 * 1000);
|
||||
}
|
||||
|
||||
TEST_F(IndexEnv2, testLongComVal2) {
|
||||
|
@ -1000,7 +1000,7 @@ TEST_F(IndexEnv2, testLongComVal2) {
|
|||
}
|
||||
// gen colVal by randstr
|
||||
std::string randstr = "abcccc fdadfafdafda";
|
||||
index->WriteMultiMillonData("tag1", randstr, 100 * 10000);
|
||||
index->WriteMultiMillonData("tag1", randstr, 100 * 1000);
|
||||
}
|
||||
TEST_F(IndexEnv2, testLongComVal3) {
|
||||
std::string path = "/tmp/long_colVal";
|
||||
|
@ -1008,7 +1008,7 @@ TEST_F(IndexEnv2, testLongComVal3) {
|
|||
}
|
||||
// gen colVal by randstr
|
||||
std::string randstr = "Yes, coding and coding and coding";
|
||||
index->WriteMultiMillonData("tag1", randstr, 100 * 10000);
|
||||
index->WriteMultiMillonData("tag1", randstr, 100 * 1000);
|
||||
}
|
||||
TEST_F(IndexEnv2, testLongComVal4) {
|
||||
std::string path = "/tmp/long_colVal";
|
||||
|
@ -1016,7 +1016,7 @@ TEST_F(IndexEnv2, testLongComVal4) {
|
|||
}
|
||||
// gen colVal by randstr
|
||||
std::string randstr = "111111 bac fdadfa";
|
||||
index->WriteMultiMillonData("tag1", randstr, 100 * 10000);
|
||||
index->WriteMultiMillonData("tag1", randstr, 100 * 100);
|
||||
}
|
||||
TEST_F(IndexEnv2, testIndex_read_performance1) {
|
||||
std::string path = "/tmp/cache_and_tfile";
|
||||
|
@ -1026,7 +1026,7 @@ TEST_F(IndexEnv2, testIndex_read_performance1) {
|
|||
index->PutOneTarge("tag1", "Hello", 15);
|
||||
index->ReadMultiMillonData("tag1", "Hello", 1000);
|
||||
std::cout << "reader sz: " << index->SearchOne("tag1", "Hello") << std::endl;
|
||||
assert(3 == index->SearchOne("tag1", "Hello"));
|
||||
EXPECT_EQ(2, index->SearchOne("tag1", "Hello"));
|
||||
}
|
||||
TEST_F(IndexEnv2, testIndex_read_performance2) {
|
||||
std::string path = "/tmp/cache_and_tfile";
|
||||
|
@ -1034,9 +1034,9 @@ TEST_F(IndexEnv2, testIndex_read_performance2) {
|
|||
}
|
||||
index->PutOneTarge("tag1", "Hello", 12);
|
||||
index->PutOneTarge("tag1", "Hello", 15);
|
||||
index->ReadMultiMillonData("tag1", "Hello", 1000 * 10);
|
||||
index->ReadMultiMillonData("tag1", "Hello", 1000);
|
||||
std::cout << "reader sz: " << index->SearchOne("tag1", "Hello") << std::endl;
|
||||
assert(3 == index->SearchOne("tag1", "Hello"));
|
||||
EXPECT_EQ(2, index->SearchOne("tag1", "Hello"));
|
||||
}
|
||||
TEST_F(IndexEnv2, testIndex_read_performance3) {
|
||||
std::string path = "/tmp/cache_and_tfile";
|
||||
|
@ -1044,9 +1044,9 @@ TEST_F(IndexEnv2, testIndex_read_performance3) {
|
|||
}
|
||||
index->PutOneTarge("tag1", "Hello", 12);
|
||||
index->PutOneTarge("tag1", "Hello", 15);
|
||||
index->ReadMultiMillonData("tag1", "Hello", 1000 * 100);
|
||||
index->ReadMultiMillonData("tag1", "Hello", 1000);
|
||||
std::cout << "reader sz: " << index->SearchOne("tag1", "Hello") << std::endl;
|
||||
assert(3 == index->SearchOne("tag1", "Hello"));
|
||||
EXPECT_EQ(2, index->SearchOne("tag1", "Hello"));
|
||||
}
|
||||
TEST_F(IndexEnv2, testIndex_read_performance4) {
|
||||
std::string path = "/tmp/cache_and_tfile";
|
||||
|
@ -1054,9 +1054,9 @@ TEST_F(IndexEnv2, testIndex_read_performance4) {
|
|||
}
|
||||
index->PutOneTarge("tag10", "Hello", 12);
|
||||
index->PutOneTarge("tag12", "Hello", 15);
|
||||
index->ReadMultiMillonData("tag10", "Hello", 1000 * 100);
|
||||
index->ReadMultiMillonData("tag10", "Hello", 1000);
|
||||
std::cout << "reader sz: " << index->SearchOne("tag1", "Hello") << std::endl;
|
||||
assert(3 == index->SearchOne("tag10", "Hello"));
|
||||
EXPECT_EQ(1, index->SearchOne("tag10", "Hello"));
|
||||
}
|
||||
TEST_F(IndexEnv2, testIndex_cache_del) {
|
||||
std::string path = "/tmp/cache_and_tfile";
|
||||
|
@ -1108,7 +1108,7 @@ TEST_F(IndexEnv2, testIndex_del) {
|
|||
index->Del("tag10", "Hello", 11);
|
||||
EXPECT_EQ(98, index->SearchOne("tag10", "Hello"));
|
||||
|
||||
index->WriteMultiMillonData("tag10", "xxxxxxxxxxxxxx", 100 * 10000);
|
||||
index->WriteMultiMillonData("tag10", "xxxxxxxxxxxxxx", 100 * 100);
|
||||
index->Del("tag10", "Hello", 17);
|
||||
EXPECT_EQ(97, index->SearchOne("tag10", "Hello"));
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ TEST_F(JsonEnv, testWriteMillonData) {
|
|||
|
||||
SIndexMultiTerm* terms = indexMultiTermCreate();
|
||||
indexMultiTermAdd(terms, term);
|
||||
for (size_t i = 0; i < 100; i++) {
|
||||
for (size_t i = 0; i < 10; i++) {
|
||||
tIndexJsonPut(index, terms, i);
|
||||
}
|
||||
indexMultiTermDestroy(terms);
|
||||
|
@ -162,14 +162,14 @@ TEST_F(JsonEnv, testWriteMillonData) {
|
|||
{
|
||||
std::string colName("voltagefdadfa");
|
||||
std::string colVal("abxxxxxxxxxxxx");
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
colVal[i % colVal.size()] = '0' + i % 128;
|
||||
SIndexTerm* term = indexTermCreate(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
|
||||
SIndexMultiTerm* terms = indexMultiTermCreate();
|
||||
indexMultiTermAdd(terms, term);
|
||||
for (size_t i = 0; i < 1000; i++) {
|
||||
for (size_t i = 0; i < 100; i++) {
|
||||
tIndexJsonPut(index, terms, i);
|
||||
}
|
||||
indexMultiTermDestroy(terms);
|
||||
|
@ -199,7 +199,7 @@ TEST_F(JsonEnv, testWriteMillonData) {
|
|||
SArray* result = taosArrayInit(1, sizeof(uint64_t));
|
||||
indexMultiTermQueryAdd(mq, q, QUERY_TERM);
|
||||
tIndexJsonSearch(index, mq, result);
|
||||
assert(100 == taosArrayGetSize(result));
|
||||
EXPECT_EQ(10, taosArrayGetSize(result));
|
||||
indexMultiTermQueryDestroy(mq);
|
||||
}
|
||||
{
|
||||
|
@ -229,7 +229,7 @@ TEST_F(JsonEnv, testWriteMillonData) {
|
|||
SArray* result = taosArrayInit(1, sizeof(uint64_t));
|
||||
indexMultiTermQueryAdd(mq, q, QUERY_GREATER_EQUAL);
|
||||
tIndexJsonSearch(index, mq, result);
|
||||
assert(100 == taosArrayGetSize(result));
|
||||
EXPECT_EQ(10, taosArrayGetSize(result));
|
||||
indexMultiTermQueryDestroy(mq);
|
||||
}
|
||||
}
|
||||
|
@ -385,7 +385,7 @@ TEST_F(JsonEnv, testWriteJsonTfileAndCache_INT) {
|
|||
|
||||
SIndexMultiTerm* terms = indexMultiTermCreate();
|
||||
indexMultiTermAdd(terms, term);
|
||||
for (size_t i = 0; i < 100000; i++) {
|
||||
for (size_t i = 0; i < 1000; i++) {
|
||||
tIndexJsonPut(index, terms, i);
|
||||
}
|
||||
indexMultiTermDestroy(terms);
|
||||
|
@ -523,7 +523,7 @@ TEST_F(JsonEnv, testWriteJsonTfileAndCache_INT2) {
|
|||
{
|
||||
int val = 10;
|
||||
std::string colName("test1");
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
val += 1;
|
||||
WriteData(index, colName, TSDB_DATA_TYPE_INT, &val, sizeof(val), i);
|
||||
}
|
||||
|
@ -532,7 +532,7 @@ TEST_F(JsonEnv, testWriteJsonTfileAndCache_INT2) {
|
|||
int val = 10;
|
||||
std::string colName("test2xxx");
|
||||
std::string colVal("xxxxxxxxxxxxxxx");
|
||||
for (int i = 0; i < 100000; i++) {
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
val += 1;
|
||||
WriteData(index, colName, TSDB_DATA_TYPE_BINARY, (void*)(colVal.c_str()), colVal.size(), i);
|
||||
}
|
||||
|
@ -542,14 +542,14 @@ TEST_F(JsonEnv, testWriteJsonTfileAndCache_INT2) {
|
|||
std::string colName("test1");
|
||||
int val = 9;
|
||||
Search(index, colName, TSDB_DATA_TYPE_INT, &val, sizeof(val), QUERY_GREATER_EQUAL, &res);
|
||||
EXPECT_EQ(10000, taosArrayGetSize(res));
|
||||
EXPECT_EQ(1000, taosArrayGetSize(res));
|
||||
}
|
||||
{
|
||||
SArray* res = NULL;
|
||||
std::string colName("test2xxx");
|
||||
std::string colVal("xxxxxxxxxxxxxxx");
|
||||
Search(index, colName, TSDB_DATA_TYPE_BINARY, (void*)(colVal.c_str()), colVal.size(), QUERY_TERM, &res);
|
||||
EXPECT_EQ(100000, taosArrayGetSize(res));
|
||||
EXPECT_EQ(1000, taosArrayGetSize(res));
|
||||
}
|
||||
}
|
||||
TEST_F(JsonEnv, testWriteJsonTfileAndCache_FLOAT) {
|
||||
|
|
|
@ -1771,6 +1771,7 @@ static const char* jkSubplanId = "Id";
|
|||
static const char* jkSubplanType = "SubplanType";
|
||||
static const char* jkSubplanMsgType = "MsgType";
|
||||
static const char* jkSubplanLevel = "Level";
|
||||
static const char* jkSubplanDbFName = "DbFName";
|
||||
static const char* jkSubplanNodeAddr = "NodeAddr";
|
||||
static const char* jkSubplanRootNode = "RootNode";
|
||||
static const char* jkSubplanDataSink = "DataSink";
|
||||
|
@ -1788,6 +1789,9 @@ static int32_t subplanToJson(const void* pObj, SJson* pJson) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkSubplanLevel, pNode->level);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddStringToObject(pJson, jkSubplanDbFName, pNode->dbFName);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkSubplanNodeAddr, queryNodeAddrToJson, &pNode->execNode);
|
||||
}
|
||||
|
@ -1815,6 +1819,9 @@ static int32_t jsonToSubplan(const SJson* pJson, void* pObj) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetIntValue(pJson, jkSubplanLevel, &pNode->level);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetStringValue(pJson, jkSubplanDbFName, pNode->dbFName);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonToObject(pJson, jkSubplanNodeAddr, jsonToQueryNodeAddr, &pNode->execNode);
|
||||
}
|
||||
|
|
|
@ -1137,10 +1137,6 @@ bool nodesIsRegularOp(const SOperatorNode* pOp) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool nodesIsTimeorderQuery(const SNode* pQuery) { return false; }
|
||||
|
||||
bool nodesIsTimelineQuery(const SNode* pQuery) { return false; }
|
||||
|
||||
typedef struct SCollectColumnsCxt {
|
||||
int32_t errCode;
|
||||
const char* pTableAlias;
|
||||
|
|
|
@ -41,6 +41,13 @@
|
|||
sToken = tStrGetToken(pSql, &index, false); \
|
||||
} while (0)
|
||||
|
||||
#define NEXT_VALID_TOKEN(pSql, sToken) \
|
||||
do { \
|
||||
sToken.n = tGetToken(pSql, &sToken.type); \
|
||||
sToken.z = pSql; \
|
||||
pSql += sToken.n; \
|
||||
} while (TK_NK_SPACE == sToken.type)
|
||||
|
||||
typedef struct SInsertParseContext {
|
||||
SParseContext* pComCxt; // input
|
||||
char* pSql; // input
|
||||
|
@ -482,9 +489,11 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int
|
|||
return buildSyntaxErrMsg(pMsgBuf, "invalid bool data", pToken->z);
|
||||
}
|
||||
} else if (pToken->type == TK_NK_INTEGER) {
|
||||
return func(pMsgBuf, ((taosStr2Int64(pToken->z, NULL, 10) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes, param);
|
||||
return func(pMsgBuf, ((taosStr2Int64(pToken->z, NULL, 10) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes,
|
||||
param);
|
||||
} else if (pToken->type == TK_NK_FLOAT) {
|
||||
return func(pMsgBuf, ((taosStr2Double(pToken->z, NULL) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes, param);
|
||||
return func(pMsgBuf, ((taosStr2Double(pToken->z, NULL) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes,
|
||||
param);
|
||||
} else {
|
||||
return buildSyntaxErrMsg(pMsgBuf, "invalid bool data", pToken->z);
|
||||
}
|
||||
|
@ -685,7 +694,7 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, SParsedDataColInfo*
|
|||
isOrdered = false;
|
||||
}
|
||||
if (index < 0) {
|
||||
return buildSyntaxErrMsg(&pCxt->msg, "invalid column/tag name", sToken.z);
|
||||
return generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_INVALID_COLUMN, sToken.z);
|
||||
}
|
||||
if (pColList->cols[index].valStat == VAL_STAT_HAS) {
|
||||
return buildSyntaxErrMsg(&pCxt->msg, "duplicated column name", sToken.z);
|
||||
|
@ -895,8 +904,10 @@ static int32_t parseUsingClause(SInsertParseContext* pCxt, SName* name, char* tb
|
|||
return buildSyntaxErrMsg(&pCxt->msg, "( is expected", sToken.z);
|
||||
}
|
||||
CHECK_CODE(parseTagsClause(pCxt, pCxt->pTableMeta->schema, getTableInfo(pCxt->pTableMeta).precision, name->tname));
|
||||
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||
if (TK_NK_RP != sToken.type) {
|
||||
NEXT_VALID_TOKEN(pCxt->pSql, sToken);
|
||||
if (TK_NK_COMMA == sToken.type) {
|
||||
return generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_TAGS_NOT_MATCHED);
|
||||
} else if (TK_NK_RP != sToken.type) {
|
||||
return buildSyntaxErrMsg(&pCxt->msg, ") is expected", sToken.z);
|
||||
}
|
||||
|
||||
|
@ -996,8 +1007,10 @@ static int32_t parseValues(SInsertParseContext* pCxt, STableDataBlocks* pDataBlo
|
|||
pDataBlock->size += extendedRowSize; // len;
|
||||
}
|
||||
|
||||
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||
if (TK_NK_RP != sToken.type) {
|
||||
NEXT_VALID_TOKEN(pCxt->pSql, sToken);
|
||||
if (TK_NK_COMMA == sToken.type) {
|
||||
return generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_INVALID_COLUMNS_NUM);
|
||||
} else if (TK_NK_RP != sToken.type) {
|
||||
return buildSyntaxErrMsg(&pCxt->msg, ") expected", sToken.z);
|
||||
}
|
||||
|
||||
|
@ -1057,10 +1070,10 @@ static void destroyInsertParseContext(SInsertParseContext* pCxt) {
|
|||
// VALUES (field1_value, ...) [(field1_value2, ...) ...] | FILE csv_file_path
|
||||
// [...];
|
||||
static int32_t parseInsertBody(SInsertParseContext* pCxt) {
|
||||
int32_t tbNum = 0;
|
||||
char tbFName[TSDB_TABLE_FNAME_LEN];
|
||||
bool autoCreateTbl = false;
|
||||
STableMeta *pMeta = NULL;
|
||||
int32_t tbNum = 0;
|
||||
char tbFName[TSDB_TABLE_FNAME_LEN];
|
||||
bool autoCreateTbl = false;
|
||||
STableMeta* pMeta = NULL;
|
||||
|
||||
// for each table
|
||||
while (1) {
|
||||
|
@ -1110,7 +1123,9 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
|
|||
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||
autoCreateTbl = true;
|
||||
} else {
|
||||
CHECK_CODE(getTableMeta(pCxt, &name, tbFName));
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
tNameGetFullDbName(&name, dbFName);
|
||||
CHECK_CODE(getTableMeta(pCxt, &name, dbFName));
|
||||
}
|
||||
|
||||
STableDataBlocks* dataBuf = NULL;
|
||||
|
@ -1158,7 +1173,8 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
|
|||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
memcpy(tags, &pCxt->tags, sizeof(pCxt->tags));
|
||||
(*pCxt->pStmtCb->setInfoFn)(pCxt->pStmtCb->pStmt, pMeta, tags, tbFName, autoCreateTbl, pCxt->pVgroupsHashObj, pCxt->pTableBlockHashObj);
|
||||
(*pCxt->pStmtCb->setInfoFn)(pCxt->pStmtCb->pStmt, pMeta, tags, tbFName, autoCreateTbl, pCxt->pVgroupsHashObj,
|
||||
pCxt->pTableBlockHashObj);
|
||||
|
||||
memset(&pCxt->tags, 0, sizeof(pCxt->tags));
|
||||
pCxt->pVgroupsHashObj = NULL;
|
||||
|
@ -1236,7 +1252,7 @@ int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = parseInsertBody(&context);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (TSDB_CODE_SUCCESS == code || NEED_CLIENT_HANDLE_ERROR(code)) {
|
||||
SName* pTable = taosHashIterate(context.pTableNameHashObj, NULL);
|
||||
while (NULL != pTable) {
|
||||
taosArrayPush((*pQuery)->pTableList, pTable);
|
||||
|
@ -1577,9 +1593,9 @@ typedef struct SmlExecTableHandle {
|
|||
} SmlExecTableHandle;
|
||||
|
||||
typedef struct SmlExecHandle {
|
||||
SHashObj* pBlockHash;
|
||||
SmlExecTableHandle tableExecHandle;
|
||||
SQuery *pQuery;
|
||||
SHashObj* pBlockHash;
|
||||
SmlExecTableHandle tableExecHandle;
|
||||
SQuery* pQuery;
|
||||
} SSmlExecHandle;
|
||||
|
||||
static void smlDestroyTableHandle(void* pHandle) {
|
||||
|
@ -1671,9 +1687,9 @@ static int32_t smlBuildTagRow(SArray* cols, SKVRowBuilder* tagsBuilder, SParsedD
|
|||
SSchema* pTagSchema = &pSchema[tags->boundColumns[i] - 1]; // colId starts with 1
|
||||
param.schema = pTagSchema;
|
||||
SSmlKv* kv = taosArrayGetP(cols, i);
|
||||
if(IS_VAR_DATA_TYPE(kv->type)){
|
||||
if (IS_VAR_DATA_TYPE(kv->type)) {
|
||||
KvRowAppend(msg, kv->value, kv->length, ¶m);
|
||||
}else{
|
||||
} else {
|
||||
KvRowAppend(msg, &(kv->value), kv->length, ¶m);
|
||||
}
|
||||
}
|
||||
|
@ -1686,13 +1702,13 @@ static int32_t smlBuildTagRow(SArray* cols, SKVRowBuilder* tagsBuilder, SParsedD
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t smlBindData(void *handle, SArray *tags, SArray *colsSchema, SArray *cols, bool format,
|
||||
STableMeta *pTableMeta, char *tableName, char *msgBuf, int16_t msgBufLen) {
|
||||
int32_t smlBindData(void* handle, SArray* tags, SArray* colsSchema, SArray* cols, bool format, STableMeta* pTableMeta,
|
||||
char* tableName, char* msgBuf, int16_t msgBufLen) {
|
||||
SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen};
|
||||
|
||||
SSmlExecHandle* smlHandle = (SSmlExecHandle*)handle;
|
||||
smlDestroyTableHandle(&smlHandle->tableExecHandle); // free for each table
|
||||
SSchema* pTagsSchema = getTableTagSchema(pTableMeta);
|
||||
smlDestroyTableHandle(&smlHandle->tableExecHandle); // free for each table
|
||||
SSchema* pTagsSchema = getTableTagSchema(pTableMeta);
|
||||
setBoundColumnInfo(&smlHandle->tableExecHandle.tags, pTagsSchema, getNumOfTags(pTableMeta));
|
||||
int ret = smlBoundColumnData(tags, &smlHandle->tableExecHandle.tags, pTagsSchema);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
|
@ -1700,7 +1716,8 @@ int32_t smlBindData(void *handle, SArray *tags, SArray *colsSchema, SArray *cols
|
|||
return ret;
|
||||
}
|
||||
SKVRow row = NULL;
|
||||
ret = smlBuildTagRow(tags, &smlHandle->tableExecHandle.tagsBuilder, &smlHandle->tableExecHandle.tags, pTagsSchema, &row, &pBuf);
|
||||
ret = smlBuildTagRow(tags, &smlHandle->tableExecHandle.tagsBuilder, &smlHandle->tableExecHandle.tags, pTagsSchema,
|
||||
&row, &pBuf);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -1731,7 +1748,7 @@ int32_t smlBindData(void *handle, SArray *tags, SArray *colsSchema, SArray *cols
|
|||
initRowBuilder(&pDataBlock->rowBuilder, pDataBlock->pTableMeta->sversion, &pDataBlock->boundColumnInfo);
|
||||
|
||||
int32_t rowNum = taosArrayGetSize(cols);
|
||||
if(rowNum <= 0) {
|
||||
if (rowNum <= 0) {
|
||||
return buildInvalidOperationMsg(&pBuf, "cols size <= 0");
|
||||
}
|
||||
ret = allocateMemForSize(pDataBlock, extendedRowSize * rowNum);
|
||||
|
@ -1742,9 +1759,9 @@ int32_t smlBindData(void *handle, SArray *tags, SArray *colsSchema, SArray *cols
|
|||
for (int32_t r = 0; r < rowNum; ++r) {
|
||||
STSRow* row = (STSRow*)(pDataBlock->pData + pDataBlock->size); // skip the SSubmitBlk header
|
||||
tdSRowResetBuf(pBuilder, row);
|
||||
void *rowData = taosArrayGetP(cols, r);
|
||||
void* rowData = taosArrayGetP(cols, r);
|
||||
size_t rowDataSize = 0;
|
||||
if(format){
|
||||
if (format) {
|
||||
rowDataSize = taosArrayGetSize(rowData);
|
||||
}
|
||||
|
||||
|
@ -1779,9 +1796,9 @@ int32_t smlBindData(void *handle, SArray *tags, SArray *colsSchema, SArray *cols
|
|||
kv->i = convertTimePrecision(kv->i, TSDB_TIME_PRECISION_NANO, pTableMeta->tableInfo.precision);
|
||||
}
|
||||
|
||||
if(IS_VAR_DATA_TYPE(kv->type)){
|
||||
if (IS_VAR_DATA_TYPE(kv->type)) {
|
||||
MemRowAppend(&pBuf, kv->value, colLen, ¶m);
|
||||
}else{
|
||||
} else {
|
||||
MemRowAppend(&pBuf, &(kv->value), colLen, ¶m);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,8 @@ static bool afterGroupBy(ESqlClause clause) { return clause > SQL_CLAUSE_GROUP_B
|
|||
|
||||
static bool beforeHaving(ESqlClause clause) { return clause < SQL_CLAUSE_HAVING; }
|
||||
|
||||
static bool afterHaving(ESqlClause clause) { return clause > SQL_CLAUSE_HAVING; }
|
||||
|
||||
static int32_t addNamespace(STranslateContext* pCxt, void* pTable) {
|
||||
size_t currTotalLevel = taosArrayGetSize(pCxt->pNsLevel);
|
||||
if (currTotalLevel > pCxt->currLevel) {
|
||||
|
@ -118,6 +120,20 @@ static int32_t getTableMeta(STranslateContext* pCxt, const char* pDbName, const
|
|||
return getTableMetaImpl(pCxt, toName(pCxt->pParseCxt->acctId, pDbName, pTableName, &name), pMeta);
|
||||
}
|
||||
|
||||
static int32_t refreshGetTableMeta(STranslateContext* pCxt, const char* pDbName, const char* pTableName,
|
||||
STableMeta** pMeta) {
|
||||
SParseContext* pParCxt = pCxt->pParseCxt;
|
||||
SName name;
|
||||
toName(pCxt->pParseCxt->acctId, pDbName, pTableName, &name);
|
||||
int32_t code =
|
||||
catalogRefreshGetTableMeta(pParCxt->pCatalog, pParCxt->pTransporter, &pParCxt->mgmtEpSet, &name, pMeta, false);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
parserError("catalogRefreshGetTableMeta error, code:%s, dbName:%s, tbName:%s", tstrerror(code), pDbName,
|
||||
pTableName);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t getTableDistVgInfo(STranslateContext* pCxt, const SName* pName, SArray** pVgInfo) {
|
||||
SParseContext* pParCxt = pCxt->pParseCxt;
|
||||
int32_t code = collectUseDatabase(pName, pCxt->pDbs);
|
||||
|
@ -276,6 +292,10 @@ static bool isScanPseudoColumnFunc(const SNode* pNode) {
|
|||
return (QUERY_NODE_FUNCTION == nodeType(pNode) && fmIsScanPseudoColumnFunc(((SFunctionNode*)pNode)->funcId));
|
||||
}
|
||||
|
||||
static bool isNonstandardSQLFunc(const SNode* pNode) {
|
||||
return (QUERY_NODE_FUNCTION == nodeType(pNode) && fmIsNonstandardSQLFunc(((SFunctionNode*)pNode)->funcId));
|
||||
}
|
||||
|
||||
static bool isDistinctOrderBy(STranslateContext* pCxt) {
|
||||
return (SQL_CLAUSE_ORDER_BY == pCxt->currClause && pCxt->pCurrStmt->isDistinct);
|
||||
}
|
||||
|
@ -376,6 +396,35 @@ static bool isInternalPrimaryKey(const SColumnNode* pCol) {
|
|||
return PRIMARYKEY_TIMESTAMP_COL_ID == pCol->colId && 0 == strcmp(pCol->colName, PK_TS_COL_INTERNAL_NAME);
|
||||
}
|
||||
|
||||
static bool isTimeOrderQuery(SNode* pStmt) {
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||
return ((SSelectStmt*)pStmt)->isTimeOrderQuery;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool isPrimaryKeyImpl(STempTableNode* pTable, SNode* pExpr) {
|
||||
if (QUERY_NODE_COLUMN == nodeType(pExpr)) {
|
||||
return (PRIMARYKEY_TIMESTAMP_COL_ID == ((SColumnNode*)pExpr)->colId);
|
||||
} else if (QUERY_NODE_FUNCTION == nodeType(pExpr)) {
|
||||
SFunctionNode* pFunc = (SFunctionNode*)pExpr;
|
||||
if (FUNCTION_TYPE_SELECT_VALUE == pFunc->funcType) {
|
||||
return isPrimaryKeyImpl(pTable, nodesListGetNode(pFunc->pParameterList, 0));
|
||||
} else if (FUNCTION_TYPE_WSTARTTS == pFunc->funcType || FUNCTION_TYPE_WENDTS == pFunc->funcType) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool isPrimaryKey(STempTableNode* pTable, SNode* pExpr) {
|
||||
if (!isTimeOrderQuery(pTable->pSubquery)) {
|
||||
return false;
|
||||
}
|
||||
return isPrimaryKeyImpl(pTable, pExpr);
|
||||
}
|
||||
|
||||
static bool findAndSetColumn(SColumnNode* pCol, const STableNode* pTable) {
|
||||
bool found = false;
|
||||
if (QUERY_NODE_REAL_TABLE == nodeType(pTable)) {
|
||||
|
@ -398,8 +447,7 @@ static bool findAndSetColumn(SColumnNode* pCol, const STableNode* pTable) {
|
|||
FOREACH(pNode, pProjectList) {
|
||||
SExprNode* pExpr = (SExprNode*)pNode;
|
||||
if (0 == strcmp(pCol->colName, pExpr->aliasName) ||
|
||||
((QUERY_NODE_COLUMN == nodeType(pExpr) && PRIMARYKEY_TIMESTAMP_COL_ID == ((SColumnNode*)pExpr)->colId) &&
|
||||
isInternalPrimaryKey(pCol))) {
|
||||
(isPrimaryKey((STempTableNode*)pTable, pNode) && isInternalPrimaryKey(pCol))) {
|
||||
setColumnInfoByExpr(pTable, pExpr, pCol);
|
||||
found = true;
|
||||
break;
|
||||
|
@ -433,6 +481,7 @@ static EDealRes translateColumnWithoutPrefix(STranslateContext* pCxt, SColumnNod
|
|||
SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel);
|
||||
size_t nums = taosArrayGetSize(pTables);
|
||||
bool found = false;
|
||||
bool isInternalPk = isInternalPrimaryKey(pCol);
|
||||
for (size_t i = 0; i < nums; ++i) {
|
||||
STableNode* pTable = taosArrayGetP(pTables, i);
|
||||
if (findAndSetColumn(pCol, pTable)) {
|
||||
|
@ -440,10 +489,16 @@ static EDealRes translateColumnWithoutPrefix(STranslateContext* pCxt, SColumnNod
|
|||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_AMBIGUOUS_COLUMN, pCol->colName);
|
||||
}
|
||||
found = true;
|
||||
if (isInternalPk) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
if (isInternalPrimaryKey(pCol)) {
|
||||
if (isInternalPk) {
|
||||
if (NULL != pCxt->pCurrStmt->pWindow) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY);
|
||||
}
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_INTERNAL_PK);
|
||||
} else {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_COLUMN, pCol->colName);
|
||||
|
@ -703,10 +758,13 @@ static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode* pOp) {
|
|||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static EDealRes haveAggFunction(SNode* pNode, void* pContext) {
|
||||
static EDealRes haveAggOrNonstdFunction(SNode* pNode, void* pContext) {
|
||||
if (isAggFunc(pNode)) {
|
||||
*((bool*)pContext) = true;
|
||||
return DEAL_RES_END;
|
||||
} else if (isNonstandardSQLFunc(pNode)) {
|
||||
*((bool*)pContext) = true;
|
||||
return DEAL_RES_END;
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
@ -743,6 +801,12 @@ static int32_t rewriteCountStar(STranslateContext* pCxt, SFunctionNode* pCount)
|
|||
return code;
|
||||
}
|
||||
|
||||
static bool hasInvalidFuncNesting(SNodeList* pParameterList) {
|
||||
bool hasInvalidFunc = false;
|
||||
nodesWalkExprs(pParameterList, haveAggOrNonstdFunction, &hasInvalidFunc);
|
||||
return hasInvalidFunc;
|
||||
}
|
||||
|
||||
static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
||||
SFmGetFuncInfoParam param = {.pCtg = pCxt->pParseCxt->pCatalog,
|
||||
.pRpc = pCxt->pParseCxt->pTransporter,
|
||||
|
@ -754,14 +818,14 @@ static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc)
|
|||
if (beforeHaving(pCxt->currClause)) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION);
|
||||
}
|
||||
bool haveAggFunc = false;
|
||||
nodesWalkExprs(pFunc->pParameterList, haveAggFunction, &haveAggFunc);
|
||||
if (haveAggFunc) {
|
||||
if (hasInvalidFuncNesting(pFunc->pParameterList)) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_AGG_FUNC_NESTING);
|
||||
}
|
||||
if (pCxt->pCurrStmt->hasNonstdSQLFunc) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_NOT_ALLOWED_FUNC);
|
||||
}
|
||||
|
||||
pCxt->pCurrStmt->hasAggFuncs = true;
|
||||
pCxt->pCurrStmt->isTimeOrderQuery = false;
|
||||
if (isCountStar(pFunc)) {
|
||||
pCxt->errCode = rewriteCountStar(pCxt, pFunc);
|
||||
}
|
||||
|
@ -784,6 +848,15 @@ static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc)
|
|||
}
|
||||
}
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->errCode && fmIsNonstandardSQLFunc(pFunc->funcId)) {
|
||||
if (SQL_CLAUSE_SELECT != pCxt->currClause || pCxt->pCurrStmt->hasNonstdSQLFunc || pCxt->pCurrStmt->hasAggFuncs) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_NOT_ALLOWED_FUNC);
|
||||
}
|
||||
if (hasInvalidFuncNesting(pFunc->pParameterList)) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_AGG_FUNC_NESTING);
|
||||
}
|
||||
pCxt->pCurrStmt->hasNonstdSQLFunc = true;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
|
||||
}
|
||||
|
||||
|
@ -952,6 +1025,7 @@ typedef struct CheckAggColCoexistCxt {
|
|||
STranslateContext* pTranslateCxt;
|
||||
bool existAggFunc;
|
||||
bool existCol;
|
||||
bool existNonstdFunc;
|
||||
int32_t selectFuncNum;
|
||||
} CheckAggColCoexistCxt;
|
||||
|
||||
|
@ -962,6 +1036,10 @@ static EDealRes doCheckAggColCoexist(SNode* pNode, void* pContext) {
|
|||
pCxt->existAggFunc = true;
|
||||
return DEAL_RES_IGNORE_CHILD;
|
||||
}
|
||||
if (isNonstandardSQLFunc(pNode)) {
|
||||
pCxt->existNonstdFunc = true;
|
||||
return DEAL_RES_IGNORE_CHILD;
|
||||
}
|
||||
if (isScanPseudoColumnFunc(pNode) || QUERY_NODE_COLUMN == nodeType(pNode)) {
|
||||
pCxt->existCol = true;
|
||||
}
|
||||
|
@ -972,16 +1050,21 @@ static int32_t checkAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect)
|
|||
if (NULL != pSelect->pGroupByList) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
CheckAggColCoexistCxt cxt = {.pTranslateCxt = pCxt, .existAggFunc = false, .existCol = false};
|
||||
CheckAggColCoexistCxt cxt = {
|
||||
.pTranslateCxt = pCxt, .existAggFunc = false, .existCol = false, .existNonstdFunc = false};
|
||||
nodesWalkExprs(pSelect->pProjectionList, doCheckAggColCoexist, &cxt);
|
||||
if (!pSelect->isDistinct) {
|
||||
nodesWalkExprs(pSelect->pOrderByList, doCheckAggColCoexist, &cxt);
|
||||
}
|
||||
if (1 == cxt.selectFuncNum) {
|
||||
return rewriteColsToSelectValFunc(pCxt, pSelect);
|
||||
} else if ((cxt.selectFuncNum > 1 || cxt.existAggFunc || NULL != pSelect->pWindow) && cxt.existCol) {
|
||||
}
|
||||
if ((cxt.selectFuncNum > 1 || cxt.existAggFunc || NULL != pSelect->pWindow) && cxt.existCol) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_SINGLE_GROUP);
|
||||
}
|
||||
if (cxt.existNonstdFunc && cxt.existCol) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -3132,7 +3215,7 @@ static int32_t translateExplain(STranslateContext* pCxt, SExplainStmt* pStmt) {
|
|||
}
|
||||
|
||||
static int32_t translateDescribe(STranslateContext* pCxt, SDescribeStmt* pStmt) {
|
||||
return getTableMeta(pCxt, pStmt->dbName, pStmt->tableName, &pStmt->pMeta);
|
||||
return refreshGetTableMeta(pCxt, pStmt->dbName, pStmt->tableName, &pStmt->pMeta);
|
||||
}
|
||||
|
||||
static int32_t translateKillConnection(STranslateContext* pCxt, SKillStmt* pStmt) {
|
||||
|
|
|
@ -164,6 +164,11 @@ static char* getSyntaxErrFormat(int32_t errCode) {
|
|||
return "Invalid function name";
|
||||
case TSDB_CODE_PAR_COMMENT_TOO_LONG:
|
||||
return "Comment too long";
|
||||
case TSDB_CODE_PAR_NOT_ALLOWED_FUNC:
|
||||
return "Some functions are allowed only in the SELECT list of a query. "
|
||||
"And, cannot be mixed with other non scalar functions or columns.";
|
||||
case TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY:
|
||||
return "Window query not supported, since the result of subquery not include valid timestamp column";
|
||||
case TSDB_CODE_OUT_OF_MEMORY:
|
||||
return "Out of memory";
|
||||
default:
|
||||
|
@ -362,8 +367,8 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p
|
|||
if (keyLen == 0 || taosHashGet(keyHash, jsonKey, keyLen) != NULL) {
|
||||
continue;
|
||||
}
|
||||
// key: keyLen + VARSTR_HEADER_SIZE, value type: CHAR_BYTES, value reserved: LONG_BYTES
|
||||
tagKV = taosMemoryCalloc(keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES + LONG_BYTES, 1);
|
||||
// key: keyLen + VARSTR_HEADER_SIZE, value type: CHAR_BYTES, value reserved: DOUBLE_BYTES
|
||||
tagKV = taosMemoryCalloc(keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES + DOUBLE_BYTES, 1);
|
||||
if (!tagKV) {
|
||||
retCode = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
|
@ -408,13 +413,9 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p
|
|||
}
|
||||
char* valueType = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE);
|
||||
char* valueData = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES);
|
||||
*valueType =
|
||||
(item->valuedouble - (int64_t)(item->valuedouble) == 0) ? TSDB_DATA_TYPE_BIGINT : TSDB_DATA_TYPE_DOUBLE;
|
||||
if (*valueType == TSDB_DATA_TYPE_DOUBLE)
|
||||
*((double*)valueData) = item->valuedouble;
|
||||
else if (*valueType == TSDB_DATA_TYPE_BIGINT)
|
||||
*((int64_t*)valueData) = item->valueint;
|
||||
tdAddColToKVRow(kvRowBuilder, jsonIndex++, tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES + LONG_BYTES);
|
||||
*valueType = TSDB_DATA_TYPE_DOUBLE;
|
||||
*((double*)valueData) = item->valuedouble;
|
||||
tdAddColToKVRow(kvRowBuilder, jsonIndex++, tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES + DOUBLE_BYTES);
|
||||
} else if (item->type == cJSON_True || item->type == cJSON_False) {
|
||||
char* valueType = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE);
|
||||
char* valueData = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES);
|
||||
|
|
|
@ -121,10 +121,29 @@ TEST_F(ParserSelectTest, selectFunc) {
|
|||
run("SELECT MAX(c1), c2 FROM t1 STATE_WINDOW(c3)");
|
||||
}
|
||||
|
||||
TEST_F(ParserSelectTest, clause) {
|
||||
TEST_F(ParserSelectTest, nonstdFunc) {
|
||||
useDb("root", "test");
|
||||
|
||||
run("SELECT DIFF(c1) FROM t1");
|
||||
}
|
||||
|
||||
TEST_F(ParserSelectTest, nonstdFuncSemanticCheck) {
|
||||
useDb("root", "test");
|
||||
|
||||
run("SELECT DIFF(c1), c2 FROM t1", TSDB_CODE_PAR_NOT_ALLOWED_FUNC, PARSER_STAGE_TRANSLATE);
|
||||
|
||||
run("SELECT DIFF(c1), tbname FROM t1", TSDB_CODE_PAR_NOT_ALLOWED_FUNC, PARSER_STAGE_TRANSLATE);
|
||||
|
||||
run("SELECT DIFF(c1), count(*) FROM t1", TSDB_CODE_PAR_NOT_ALLOWED_FUNC, PARSER_STAGE_TRANSLATE);
|
||||
|
||||
run("SELECT DIFF(c1), CSUM(c1) FROM t1", TSDB_CODE_PAR_NOT_ALLOWED_FUNC, PARSER_STAGE_TRANSLATE);
|
||||
|
||||
// run("SELECT DIFF(c1) FROM t1 INTERVAL(10s)");
|
||||
}
|
||||
|
||||
TEST_F(ParserSelectTest, groupBy) {
|
||||
useDb("root", "test");
|
||||
|
||||
// GROUP BY clause
|
||||
run("SELECT COUNT(*) cnt FROM t1 WHERE c1 > 0");
|
||||
|
||||
run("SELECT COUNT(*), c2 cnt FROM t1 WHERE c1 > 0 GROUP BY c2");
|
||||
|
@ -134,13 +153,19 @@ TEST_F(ParserSelectTest, clause) {
|
|||
run("SELECT COUNT(*), c1, c2 + 10, c1 + c2 cnt FROM t1 WHERE c1 > 0 GROUP BY c2, c1");
|
||||
|
||||
run("SELECT COUNT(*), c1 + 10, c2 cnt FROM t1 WHERE c1 > 0 GROUP BY c1 + 10, c2");
|
||||
}
|
||||
|
||||
TEST_F(ParserSelectTest, orderBy) {
|
||||
useDb("root", "test");
|
||||
|
||||
// order by clause
|
||||
run("SELECT COUNT(*) cnt FROM t1 WHERE c1 > 0 GROUP BY c2 order by cnt");
|
||||
|
||||
run("SELECT COUNT(*) cnt FROM t1 WHERE c1 > 0 GROUP BY c2 order by 1");
|
||||
}
|
||||
|
||||
TEST_F(ParserSelectTest, distinct) {
|
||||
useDb("root", "test");
|
||||
|
||||
// distinct clause
|
||||
// run("SELECT distinct c1, c2 FROM t1 WHERE c1 > 0 order by c1");
|
||||
|
||||
// run("SELECT distinct c1 + 10, c2 FROM t1 WHERE c1 > 0 order by c1 + 10, c2");
|
||||
|
@ -174,6 +199,25 @@ TEST_F(ParserSelectTest, intervalSemanticCheck) {
|
|||
PARSER_STAGE_TRANSLATE);
|
||||
}
|
||||
|
||||
TEST_F(ParserSelectTest, subquery) {
|
||||
useDb("root", "test");
|
||||
|
||||
run("SELECT SUM(a) FROM (SELECT MAX(c1) a, ts FROM st1s1 INTERVAL(1m)) INTERVAL(1n)");
|
||||
|
||||
run("SELECT SUM(a) FROM (SELECT MAX(c1) a, _wstartts FROM st1s1 INTERVAL(1m)) INTERVAL(1n)");
|
||||
|
||||
run("SELECT SUM(a) FROM (SELECT MAX(c1) a, ts FROM st1s1 PARTITION BY TBNAME INTERVAL(1m)) INTERVAL(1n)");
|
||||
|
||||
run("SELECT SUM(a) FROM (SELECT MAX(c1) a, _wstartts FROM st1s1 PARTITION BY TBNAME INTERVAL(1m)) INTERVAL(1n)");
|
||||
}
|
||||
|
||||
TEST_F(ParserSelectTest, subquerySemanticError) {
|
||||
useDb("root", "test");
|
||||
|
||||
run("SELECT SUM(a) FROM (SELECT MAX(c1) a FROM st1s1 INTERVAL(1m)) INTERVAL(1n)", TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY,
|
||||
PARSER_STAGE_TRANSLATE);
|
||||
}
|
||||
|
||||
TEST_F(ParserSelectTest, semanticError) {
|
||||
useDb("root", "test");
|
||||
|
||||
|
|
|
@ -24,9 +24,9 @@
|
|||
#define SPLIT_FLAG_TEST_MASK(val, mask) (((val) & (mask)) != 0)
|
||||
|
||||
typedef struct SSplitContext {
|
||||
int32_t queryId;
|
||||
int32_t groupId;
|
||||
bool split;
|
||||
uint64_t queryId;
|
||||
int32_t groupId;
|
||||
bool split;
|
||||
} SSplitContext;
|
||||
|
||||
typedef int32_t (*FSplit)(SSplitContext* pCxt, SLogicSubplan* pSubplan);
|
||||
|
|
|
@ -47,7 +47,7 @@ int32_t qwBuildAndSendQueryRsp(SRpcHandleInfo *pConn, int32_t code) {
|
|||
SQueryTableRsp rsp = {.code = code};
|
||||
|
||||
int32_t contLen = tSerializeSQueryTableRsp(NULL, 0, &rsp);
|
||||
void *msg = rpcMallocCont(contLen);
|
||||
void * msg = rpcMallocCont(contLen);
|
||||
tSerializeSQueryTableRsp(msg, contLen, &rsp);
|
||||
|
||||
SRpcMsg rpcRsp = {
|
||||
|
@ -85,7 +85,7 @@ int32_t qwBuildAndSendExplainRsp(SRpcHandleInfo *pConn, SExplainExecInfo *execIn
|
|||
SExplainRsp rsp = {.numOfPlans = num, .subplanInfo = execInfo};
|
||||
|
||||
int32_t contLen = tSerializeSExplainRsp(NULL, 0, &rsp);
|
||||
void *pRsp = rpcMallocCont(contLen);
|
||||
void * pRsp = rpcMallocCont(contLen);
|
||||
tSerializeSExplainRsp(pRsp, contLen, &rsp);
|
||||
|
||||
SRpcMsg rpcRsp = {
|
||||
|
@ -104,7 +104,7 @@ int32_t qwBuildAndSendExplainRsp(SRpcHandleInfo *pConn, SExplainExecInfo *execIn
|
|||
|
||||
int32_t qwBuildAndSendHbRsp(SRpcHandleInfo *pConn, SSchedulerHbRsp *pStatus, int32_t code) {
|
||||
int32_t contLen = tSerializeSSchedulerHbRsp(NULL, 0, pStatus);
|
||||
void *pRsp = rpcMallocCont(contLen);
|
||||
void * pRsp = rpcMallocCont(contLen);
|
||||
tSerializeSSchedulerHbRsp(pRsp, contLen, pStatus);
|
||||
|
||||
SRpcMsg rpcRsp = {
|
||||
|
@ -212,7 +212,7 @@ int32_t qwBuildAndSendShowRsp(SRpcMsg *pMsg, int32_t code) {
|
|||
showRsp.tableMeta.numOfColumns = cols;
|
||||
|
||||
int32_t bufLen = tSerializeSShowRsp(NULL, 0, &showRsp);
|
||||
void *pBuf = rpcMallocCont(bufLen);
|
||||
void * pBuf = rpcMallocCont(bufLen);
|
||||
tSerializeSShowRsp(pBuf, bufLen, &showRsp);
|
||||
|
||||
SRpcMsg rpcMsg = {
|
||||
|
@ -287,7 +287,7 @@ int32_t qwRegisterQueryBrokenLinkArg(QW_FPARAMS_DEF, SRpcHandleInfo *pConn) {
|
|||
req->taskId = htobe64(tId);
|
||||
req->refId = htobe64(rId);
|
||||
|
||||
SRpcMsg pMsg = {
|
||||
SRpcMsg brokenMsg = {
|
||||
.msgType = TDMT_VND_DROP_TASK,
|
||||
.pCont = req,
|
||||
.contLen = sizeof(STaskDropReq),
|
||||
|
@ -295,7 +295,7 @@ int32_t qwRegisterQueryBrokenLinkArg(QW_FPARAMS_DEF, SRpcHandleInfo *pConn) {
|
|||
.info = *pConn,
|
||||
};
|
||||
|
||||
tmsgRegisterBrokenLinkArg(&pMsg);
|
||||
tmsgRegisterBrokenLinkArg(&brokenMsg);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -321,7 +321,7 @@ int32_t qwRegisterHbBrokenLinkArg(SQWorker *mgmt, uint64_t sId, SRpcHandleInfo *
|
|||
QW_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SRpcMsg pMsg = {
|
||||
SRpcMsg brokenMsg = {
|
||||
.msgType = TDMT_VND_QUERY_HEARTBEAT,
|
||||
.pCont = msg,
|
||||
.contLen = msgSize,
|
||||
|
@ -329,7 +329,7 @@ int32_t qwRegisterHbBrokenLinkArg(SQWorker *mgmt, uint64_t sId, SRpcHandleInfo *
|
|||
.info = *pConn,
|
||||
};
|
||||
|
||||
tmsgRegisterBrokenLinkArg(&pMsg);
|
||||
tmsgRegisterBrokenLinkArg(&brokenMsg);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -341,7 +341,7 @@ int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
|
|||
|
||||
int32_t code = 0;
|
||||
SSubQueryMsg *msg = pMsg->pCont;
|
||||
SQWorker *mgmt = (SQWorker *)qWorkerMgmt;
|
||||
SQWorker * mgmt = (SQWorker *)qWorkerMgmt;
|
||||
|
||||
if (NULL == msg || pMsg->contLen <= sizeof(*msg)) {
|
||||
QW_ELOG("invalid query msg, msg:%p, msgLen:%d", msg, pMsg->contLen);
|
||||
|
@ -361,7 +361,7 @@ int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
|
|||
int64_t rId = msg->refId;
|
||||
|
||||
SQWMsg qwMsg = {.node = node, .msg = msg->msg + msg->sqlLen, .msgLen = msg->phyLen, .connInfo = pMsg->info};
|
||||
char *sql = strndup(msg->msg, msg->sqlLen);
|
||||
char * sql = strndup(msg->msg, msg->sqlLen);
|
||||
QW_SCH_TASK_DLOG("processQuery start, node:%p, handle:%p, sql:%s", node, pMsg->info.handle, sql);
|
||||
taosMemoryFreeClear(sql);
|
||||
|
||||
|
@ -378,8 +378,8 @@ int32_t qWorkerProcessCQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
|
|||
bool queryDone = false;
|
||||
SQueryContinueReq *msg = (SQueryContinueReq *)pMsg->pCont;
|
||||
bool needStop = false;
|
||||
SQWTaskCtx *handles = NULL;
|
||||
SQWorker *mgmt = (SQWorker *)qWorkerMgmt;
|
||||
SQWTaskCtx * handles = NULL;
|
||||
SQWorker * mgmt = (SQWorker *)qWorkerMgmt;
|
||||
|
||||
if (NULL == msg || pMsg->contLen < sizeof(*msg)) {
|
||||
QW_ELOG("invalid cquery msg, msg:%p, msgLen:%d", msg, pMsg->contLen);
|
||||
|
@ -407,7 +407,7 @@ int32_t qWorkerProcessReadyMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
|
|||
return TSDB_CODE_QRY_INVALID_INPUT;
|
||||
}
|
||||
|
||||
SQWorker *mgmt = (SQWorker *)qWorkerMgmt;
|
||||
SQWorker * mgmt = (SQWorker *)qWorkerMgmt;
|
||||
SResReadyReq *msg = pMsg->pCont;
|
||||
if (NULL == msg || pMsg->contLen < sizeof(*msg)) {
|
||||
QW_ELOG("invalid task ready msg, msg:%p, msgLen:%d", msg, pMsg->contLen);
|
||||
|
@ -467,7 +467,7 @@ int32_t qWorkerProcessFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
SResFetchReq *msg = pMsg->pCont;
|
||||
SQWorker *mgmt = (SQWorker *)qWorkerMgmt;
|
||||
SQWorker * mgmt = (SQWorker *)qWorkerMgmt;
|
||||
|
||||
if (NULL == msg || pMsg->contLen < sizeof(*msg)) {
|
||||
QW_ELOG("invalid fetch msg, msg:%p, msgLen:%d", msg, pMsg->contLen);
|
||||
|
@ -505,7 +505,7 @@ int32_t qWorkerProcessCancelMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
|
|||
return TSDB_CODE_QRY_INVALID_INPUT;
|
||||
}
|
||||
|
||||
SQWorker *mgmt = (SQWorker *)qWorkerMgmt;
|
||||
SQWorker * mgmt = (SQWorker *)qWorkerMgmt;
|
||||
int32_t code = 0;
|
||||
STaskCancelReq *msg = pMsg->pCont;
|
||||
if (NULL == msg || pMsg->contLen < sizeof(*msg)) {
|
||||
|
@ -542,7 +542,7 @@ int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
|
|||
|
||||
int32_t code = 0;
|
||||
STaskDropReq *msg = pMsg->pCont;
|
||||
SQWorker *mgmt = (SQWorker *)qWorkerMgmt;
|
||||
SQWorker * mgmt = (SQWorker *)qWorkerMgmt;
|
||||
|
||||
if (NULL == msg || pMsg->contLen < sizeof(*msg)) {
|
||||
QW_ELOG("invalid task drop msg, msg:%p, msgLen:%d", msg, pMsg->contLen);
|
||||
|
@ -581,7 +581,7 @@ int32_t qWorkerProcessHbMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
|
|||
|
||||
int32_t code = 0;
|
||||
SSchedulerHbReq req = {0};
|
||||
SQWorker *mgmt = (SQWorker *)qWorkerMgmt;
|
||||
SQWorker * mgmt = (SQWorker *)qWorkerMgmt;
|
||||
|
||||
if (NULL == pMsg->pCont) {
|
||||
QW_ELOG("invalid hb msg, msg:%p, msgLen:%d", pMsg->pCont, pMsg->contLen);
|
||||
|
|
|
@ -899,7 +899,7 @@ int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) {
|
|||
}
|
||||
|
||||
int32_t code = 0;
|
||||
SScalarCtx ctx = {.code = 0, .pBlockList = pBlockList, .param = pDst->param};
|
||||
SScalarCtx ctx = {.code = 0, .pBlockList = pBlockList, .param = pDst ? pDst->param : NULL};
|
||||
|
||||
// TODO: OPT performance
|
||||
ctx.pRes = taosHashInit(SCL_DEFAULT_OP_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
|
||||
|
|
|
@ -922,7 +922,8 @@ static void doReleaseVec(SColumnInfoData* pCol, int32_t type) {
|
|||
}
|
||||
}
|
||||
|
||||
char *getJsonValue(char *json, char *key){ //todo
|
||||
char *getJsonValue(char *json, char *key){ //todo
|
||||
json++; // jump type
|
||||
int16_t cols = kvRowNCols(json);
|
||||
for (int i = 0; i < cols; ++i) {
|
||||
SColIdx *pColIdx = kvRowColIdxAt(json, i);
|
||||
|
|
|
@ -1035,7 +1035,7 @@ void makeJsonArrow(SSDataBlock **src, SNode **opNode, void *json, char *key){
|
|||
|
||||
SNode *pLeft = NULL, *pRight = NULL;
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, keyVar);
|
||||
scltMakeColumnNode(&pLeft, src, TSDB_DATA_TYPE_JSON, varDataLen(json), 1, json);
|
||||
scltMakeColumnNode(&pLeft, src, TSDB_DATA_TYPE_JSON, kvRowLen(json), 1, json);
|
||||
scltMakeOpNode(opNode, OP_TYPE_JSON_GET_VALUE, TSDB_DATA_TYPE_JSON, pLeft, pRight);
|
||||
}
|
||||
|
||||
|
@ -1088,18 +1088,17 @@ void makeCalculate(void *json, void *key, int32_t rightType, void *rightData, do
|
|||
|
||||
}else if(opType == OP_TYPE_ADD || opType == OP_TYPE_SUB || opType == OP_TYPE_MULTI || opType == OP_TYPE_DIV ||
|
||||
opType == OP_TYPE_MOD || opType == OP_TYPE_MINUS){
|
||||
double tmp = *((double *)colDataGetData(column, 0));
|
||||
ASSERT_TRUE(tmp == exceptValue);
|
||||
printf("result:%lf\n", tmp);
|
||||
printf("1result:%f,except:%f\n", *((double *)colDataGetData(column, 0)), exceptValue);
|
||||
ASSERT_TRUE(abs(*((double *)colDataGetData(column, 0)) - exceptValue) < 1e-15);
|
||||
}else if(opType == OP_TYPE_BIT_AND || opType == OP_TYPE_BIT_OR){
|
||||
printf("2result:%ld,except:%f\n", *((int64_t *)colDataGetData(column, 0)), exceptValue);
|
||||
ASSERT_EQ(*((int64_t *)colDataGetData(column, 0)), exceptValue);
|
||||
printf("result:%ld\n", *((int64_t *)colDataGetData(column, 0)));
|
||||
}else if(opType == OP_TYPE_GREATER_THAN || opType == OP_TYPE_GREATER_EQUAL || opType == OP_TYPE_LOWER_THAN ||
|
||||
opType == OP_TYPE_LOWER_EQUAL || opType == OP_TYPE_EQUAL || opType == OP_TYPE_NOT_EQUAL ||
|
||||
opType == OP_TYPE_IS_NULL || opType == OP_TYPE_IS_NOT_NULL || opType == OP_TYPE_IS_TRUE ||
|
||||
opType == OP_TYPE_LIKE || opType == OP_TYPE_NOT_LIKE || opType == OP_TYPE_MATCH || opType == OP_TYPE_NMATCH){
|
||||
printf("3result:%d,except:%f\n", *((bool *)colDataGetData(column, 0)), exceptValue);
|
||||
ASSERT_EQ(*((bool *)colDataGetData(column, 0)), exceptValue);
|
||||
printf("result:%d\n", *((bool *)colDataGetData(column, 0)));
|
||||
}
|
||||
|
||||
taosArrayDestroyEx(blockList, scltFreeDataBlock);
|
||||
|
@ -1114,6 +1113,13 @@ TEST(columnTest, json_column_arith_op) {
|
|||
tdInitKVRowBuilder(&kvRowBuilder);
|
||||
parseJsontoTagData(rightv, &kvRowBuilder, NULL, 0);
|
||||
SKVRow row = tdGetKVRowFromBuilder(&kvRowBuilder);
|
||||
char *tmp = (char *)taosMemoryRealloc(row, kvRowLen(row)+1);
|
||||
if(tmp == NULL){
|
||||
ASSERT_TRUE(0);
|
||||
}
|
||||
memmove(tmp+1, tmp, kvRowLen(tmp));
|
||||
*tmp = TSDB_DATA_TYPE_JSON;
|
||||
row = tmp;
|
||||
|
||||
const int32_t len = 8;
|
||||
EOperatorType op[len] = {OP_TYPE_ADD, OP_TYPE_SUB, OP_TYPE_MULTI, OP_TYPE_DIV,
|
||||
|
@ -1166,6 +1172,9 @@ TEST(columnTest, json_column_arith_op) {
|
|||
for(int i = 0; i < len; i++){
|
||||
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes5[i], op[i]);
|
||||
}
|
||||
|
||||
tdDestroyKVRowBuilder(&kvRowBuilder);
|
||||
taosMemoryFree(row);
|
||||
}
|
||||
|
||||
void *prepareNchar(char* rightData){
|
||||
|
@ -1186,6 +1195,13 @@ TEST(columnTest, json_column_logic_op) {
|
|||
tdInitKVRowBuilder(&kvRowBuilder);
|
||||
parseJsontoTagData(rightv, &kvRowBuilder, NULL, 0);
|
||||
SKVRow row = tdGetKVRowFromBuilder(&kvRowBuilder);
|
||||
char *tmp = (char *)taosMemoryRealloc(row, kvRowLen(row)+1);
|
||||
if(tmp == NULL){
|
||||
ASSERT_TRUE(0);
|
||||
}
|
||||
memmove(tmp+1, tmp, kvRowLen(tmp));
|
||||
*tmp = TSDB_DATA_TYPE_JSON;
|
||||
row = tmp;
|
||||
|
||||
const int32_t len = 9;
|
||||
const int32_t len1 = 4;
|
||||
|
@ -1223,7 +1239,7 @@ TEST(columnTest, json_column_logic_op) {
|
|||
printf("--------------------json null---------------------\n");
|
||||
|
||||
key = "k3";
|
||||
double eRes2[len+len1] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, true, false, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX};
|
||||
bool eRes2[len+len1] = {false, false, false, false, false, false, true, false, false, false, false, false, false};
|
||||
for(int i = 0; i < len; i++){
|
||||
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes2[i], op[i]);
|
||||
}
|
||||
|
@ -1262,7 +1278,7 @@ TEST(columnTest, json_column_logic_op) {
|
|||
printf("--------------------json double---------------------\n");
|
||||
|
||||
key = "k6";
|
||||
bool eRes5[len+len1] = {true, false, false, false, false, true, false, true, true, false, false, false, true};
|
||||
bool eRes5[len+len1] = {true, false, false, false, false, true, false, true, true, false, true, false, true};
|
||||
for(int i = 0; i < len; i++){
|
||||
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes5[i], op[i]);
|
||||
}
|
||||
|
@ -1275,7 +1291,7 @@ TEST(columnTest, json_column_logic_op) {
|
|||
printf("---------------------json not exist--------------------\n");
|
||||
|
||||
key = "k10";
|
||||
double eRes10[len+len1] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, true, false, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX};
|
||||
double eRes10[len+len1] = {false, false, false, false, false, false, true, false, false, false, false, false, false};
|
||||
for(int i = 0; i < len; i++){
|
||||
makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes10[i], op[i]);
|
||||
}
|
||||
|
@ -1284,6 +1300,9 @@ TEST(columnTest, json_column_logic_op) {
|
|||
makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes10[i], op[i]);
|
||||
taosMemoryFree(rightData);
|
||||
}
|
||||
|
||||
tdDestroyKVRowBuilder(&kvRowBuilder);
|
||||
taosMemoryFree(row);
|
||||
}
|
||||
|
||||
TEST(columnTest, smallint_value_add_int_column) {
|
||||
|
|
|
@ -68,7 +68,7 @@ static int32_t streamBuildExecMsg(SStreamTask* pTask, SArray* data, SRpcMsg* pMs
|
|||
|
||||
// get groupId, compute hash value
|
||||
uint32_t hashValue = MurmurHash3_32(ctbName, strlen(ctbName));
|
||||
//
|
||||
|
||||
// get node
|
||||
// TODO: optimize search process
|
||||
SArray* vgInfo = pTask->shuffleDispatcher.dbInfo.pVgroupInfos;
|
||||
|
@ -152,13 +152,13 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, void* data, SArray* pRes)
|
|||
|
||||
// exec
|
||||
while (1) {
|
||||
SSDataBlock* output;
|
||||
SSDataBlock* output = NULL;
|
||||
uint64_t ts = 0;
|
||||
if (qExecTask(exec, &output, &ts) < 0) {
|
||||
ASSERT(false);
|
||||
}
|
||||
if (output == NULL) break;
|
||||
taosArrayPush(pRes, &output);
|
||||
taosArrayPush(pRes, output);
|
||||
}
|
||||
|
||||
// destroy
|
||||
|
@ -189,7 +189,7 @@ int32_t streamTaskExec2(SStreamTask* pTask, SMsgCb* pMsgCb) {
|
|||
taosFreeQitem(data);
|
||||
|
||||
if (taosArrayGetSize(pRes) != 0) {
|
||||
SStreamDataBlock* resQ = taosAllocateQitem(sizeof(void**), DEF_QITEM);
|
||||
SStreamDataBlock* resQ = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM);
|
||||
resQ->type = STREAM_INPUT__DATA_BLOCK;
|
||||
resQ->blocks = pRes;
|
||||
taosWriteQitem(pTask->outputQ, resQ);
|
||||
|
@ -209,7 +209,7 @@ int32_t streamTaskExec2(SStreamTask* pTask, SMsgCb* pMsgCb) {
|
|||
taosFreeQitem(data);
|
||||
|
||||
if (taosArrayGetSize(pRes) != 0) {
|
||||
SStreamDataBlock* resQ = taosAllocateQitem(sizeof(void**), DEF_QITEM);
|
||||
SStreamDataBlock* resQ = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM);
|
||||
resQ->type = STREAM_INPUT__DATA_BLOCK;
|
||||
resQ->blocks = pRes;
|
||||
taosWriteQitem(pTask->outputQ, resQ);
|
||||
|
@ -231,7 +231,7 @@ int32_t streamTaskExec2(SStreamTask* pTask, SMsgCb* pMsgCb) {
|
|||
taosFreeQitem(data);
|
||||
|
||||
if (taosArrayGetSize(pRes) != 0) {
|
||||
SStreamDataBlock* resQ = taosAllocateQitem(sizeof(void**), DEF_QITEM);
|
||||
SStreamDataBlock* resQ = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM);
|
||||
resQ->type = STREAM_INPUT__DATA_BLOCK;
|
||||
resQ->blocks = pRes;
|
||||
taosWriteQitem(pTask->outputQ, resQ);
|
||||
|
@ -247,6 +247,19 @@ int32_t streamTaskExec2(SStreamTask* pTask, SMsgCb* pMsgCb) {
|
|||
void* data = NULL;
|
||||
taosGetQitem(pTask->inputQAll, &data);
|
||||
if (data == NULL) break;
|
||||
|
||||
streamTaskExecImpl(pTask, data, pRes);
|
||||
|
||||
taosFreeQitem(data);
|
||||
|
||||
if (taosArrayGetSize(pRes) != 0) {
|
||||
SStreamDataBlock* resQ = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM);
|
||||
resQ->type = STREAM_INPUT__DATA_BLOCK;
|
||||
resQ->blocks = pRes;
|
||||
taosWriteQitem(pTask->outputQ, resQ);
|
||||
pRes = taosArrayInit(0, sizeof(SSDataBlock));
|
||||
if (pRes == NULL) goto FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
atomic_store_8(&pTask->status, TASK_STATUS__IDLE);
|
||||
|
@ -298,62 +311,66 @@ int32_t streamTaskSink(SStreamTask* pTask, SMsgCb* pMsgCb) {
|
|||
}
|
||||
|
||||
// dispatch
|
||||
if (pTask->dispatchType == TASK_DISPATCH__INPLACE) {
|
||||
SRpcMsg dispatchMsg = {0};
|
||||
if (streamBuildExecMsg(pTask, pRes, &dispatchMsg, NULL) < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t qType;
|
||||
if (pTask->dispatchMsgType == TDMT_VND_TASK_PIPE_EXEC || pTask->dispatchMsgType == TDMT_SND_TASK_PIPE_EXEC) {
|
||||
qType = FETCH_QUEUE;
|
||||
} else if (pTask->dispatchMsgType == TDMT_VND_TASK_MERGE_EXEC ||
|
||||
pTask->dispatchMsgType == TDMT_SND_TASK_MERGE_EXEC) {
|
||||
qType = MERGE_QUEUE;
|
||||
} else if (pTask->dispatchMsgType == TDMT_VND_TASK_WRITE_EXEC) {
|
||||
qType = WRITE_QUEUE;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
tmsgPutToQueue(pMsgCb, qType, &dispatchMsg);
|
||||
|
||||
} else if (pTask->dispatchType == TASK_DISPATCH__FIXED) {
|
||||
SRpcMsg dispatchMsg = {0};
|
||||
SEpSet* pEpSet = NULL;
|
||||
if (streamBuildExecMsg(pTask, pRes, &dispatchMsg, &pEpSet) < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tmsgSendReq(pEpSet, &dispatchMsg);
|
||||
|
||||
} else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) {
|
||||
SHashObj* pShuffleRes = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
|
||||
if (pShuffleRes == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t sz = taosArrayGetSize(pRes);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SSDataBlock* pDataBlock = taosArrayGet(pRes, i);
|
||||
SArray* pArray = taosHashGet(pShuffleRes, &pDataBlock->info.groupId, sizeof(int64_t));
|
||||
if (pArray == NULL) {
|
||||
pArray = taosArrayInit(0, sizeof(SSDataBlock));
|
||||
if (pArray == NULL) {
|
||||
return -1;
|
||||
}
|
||||
taosHashPut(pShuffleRes, &pDataBlock->info.groupId, sizeof(int64_t), &pArray, sizeof(void*));
|
||||
// TODO dispatch guard
|
||||
int8_t outputStatus = atomic_load_8(&pTask->outputStatus);
|
||||
if (outputStatus == TASK_OUTPUT_STATUS__NORMAL) {
|
||||
if (pTask->dispatchType == TASK_DISPATCH__INPLACE) {
|
||||
SRpcMsg dispatchMsg = {0};
|
||||
if (streamBuildExecMsg(pTask, pRes, &dispatchMsg, NULL) < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
taosArrayPush(pArray, pDataBlock);
|
||||
}
|
||||
|
||||
if (streamShuffleDispatch(pTask, pMsgCb, pShuffleRes) < 0) {
|
||||
return -1;
|
||||
}
|
||||
int32_t qType;
|
||||
if (pTask->dispatchMsgType == TDMT_VND_TASK_PIPE_EXEC || pTask->dispatchMsgType == TDMT_SND_TASK_PIPE_EXEC) {
|
||||
qType = FETCH_QUEUE;
|
||||
} else if (pTask->dispatchMsgType == TDMT_VND_TASK_MERGE_EXEC ||
|
||||
pTask->dispatchMsgType == TDMT_SND_TASK_MERGE_EXEC) {
|
||||
qType = MERGE_QUEUE;
|
||||
} else if (pTask->dispatchMsgType == TDMT_VND_TASK_WRITE_EXEC) {
|
||||
qType = WRITE_QUEUE;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
tmsgPutToQueue(pMsgCb, qType, &dispatchMsg);
|
||||
|
||||
} else {
|
||||
ASSERT(pTask->dispatchType == TASK_DISPATCH__NONE);
|
||||
} else if (pTask->dispatchType == TASK_DISPATCH__FIXED) {
|
||||
SRpcMsg dispatchMsg = {0};
|
||||
SEpSet* pEpSet = NULL;
|
||||
if (streamBuildExecMsg(pTask, pRes, &dispatchMsg, &pEpSet) < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tmsgSendReq(pEpSet, &dispatchMsg);
|
||||
|
||||
} else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) {
|
||||
SHashObj* pShuffleRes = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
|
||||
if (pShuffleRes == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t sz = taosArrayGetSize(pRes);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SSDataBlock* pDataBlock = taosArrayGet(pRes, i);
|
||||
SArray* pArray = taosHashGet(pShuffleRes, &pDataBlock->info.groupId, sizeof(int64_t));
|
||||
if (pArray == NULL) {
|
||||
pArray = taosArrayInit(0, sizeof(SSDataBlock));
|
||||
if (pArray == NULL) {
|
||||
return -1;
|
||||
}
|
||||
taosHashPut(pShuffleRes, &pDataBlock->info.groupId, sizeof(int64_t), &pArray, sizeof(void*));
|
||||
}
|
||||
taosArrayPush(pArray, pDataBlock);
|
||||
}
|
||||
|
||||
if (streamShuffleDispatch(pTask, pMsgCb, pShuffleRes) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
} else {
|
||||
ASSERT(pTask->dispatchType == TASK_DISPATCH__NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@ -375,12 +392,14 @@ int32_t streamTaskEnqueue(SStreamTask* pTask, SStreamDispatchReq* pReq, SRpcMsg*
|
|||
// 1.2 enqueue
|
||||
pBlock->type = STREAM_DATA_TYPE_SSDATA_BLOCK;
|
||||
pBlock->sourceVg = pReq->sourceVg;
|
||||
pBlock->sourceVer = pReq->sourceVer;
|
||||
/*pBlock->sourceVer = pReq->sourceVer;*/
|
||||
taosWriteQitem(pTask->inputQ, pBlock);
|
||||
|
||||
// 1.3 rsp by input status
|
||||
SStreamDispatchRsp* pCont = rpcMallocCont(sizeof(SStreamDispatchRsp));
|
||||
pCont->inputStatus = status;
|
||||
pCont->streamId = pReq->streamId;
|
||||
pCont->taskId = pReq->sourceTaskId;
|
||||
pRsp->pCont = pCont;
|
||||
pRsp->contLen = sizeof(SStreamDispatchRsp);
|
||||
tmsgSendRsp(pRsp);
|
||||
|
@ -406,7 +425,28 @@ int32_t streamTaskProcessDispatchReq(SStreamTask* pTask, SMsgCb* pMsgCb, SStream
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t streamTaskProcessRecoverReq(SStreamTask* pTask, char* msg) {
|
||||
int32_t streamTaskProcessDispatchRsp(SStreamTask* pTask, SMsgCb* pMsgCb, SStreamDispatchRsp* pRsp) {
|
||||
atomic_store_8(&pTask->inputStatus, pRsp->inputStatus);
|
||||
if (pRsp->inputStatus == TASK_INPUT_STATUS__BLOCKED) {
|
||||
// TODO: init recover timer
|
||||
}
|
||||
// continue dispatch
|
||||
streamTaskSink(pTask, pMsgCb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t streamTaskProcessRunReq(SStreamTask* pTask, SMsgCb* pMsgCb) {
|
||||
streamTaskExec2(pTask, pMsgCb);
|
||||
streamTaskSink(pTask, pMsgCb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t streamTaskProcessRecoverReq(SStreamTask* pTask, SMsgCb* pMsgCb, SStreamTaskRecoverReq* pReq, SRpcMsg* pMsg) {
|
||||
//
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t streamTaskProcessRecoverRsp(SStreamTask* pTask, SStreamTaskRecoverRsp* pRsp) {
|
||||
//
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -36,10 +36,10 @@ typedef struct SSyncIO {
|
|||
STaosQueue *pMsgQ;
|
||||
STaosQset * pQset;
|
||||
TdThread consumerTid;
|
||||
|
||||
void * serverRpc;
|
||||
void * clientRpc;
|
||||
SEpSet myAddr;
|
||||
void *serverRpc;
|
||||
void *clientRpc;
|
||||
SEpSet myAddr;
|
||||
SMsgCb msgcb;
|
||||
|
||||
tmr_h qTimer;
|
||||
int32_t qTimerMS;
|
||||
|
@ -65,8 +65,8 @@ extern SSyncIO *gSyncIO;
|
|||
|
||||
int32_t syncIOStart(char *host, uint16_t port);
|
||||
int32_t syncIOStop();
|
||||
int32_t syncIOSendMsg(void *clientRpc, const SEpSet *pEpSet, SRpcMsg *pMsg);
|
||||
int32_t syncIOEqMsg(void *queue, SRpcMsg *pMsg);
|
||||
int32_t syncIOSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg);
|
||||
int32_t syncIOEqMsg(const SMsgCb *msgcb, SRpcMsg *pMsg);
|
||||
|
||||
int32_t syncIOQTimerStart();
|
||||
int32_t syncIOQTimerStop();
|
||||
|
|
|
@ -20,135 +20,41 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "cJSON.h"
|
||||
#include "sync.h"
|
||||
#include "syncTools.h"
|
||||
#include "taosdef.h"
|
||||
#include "tglobal.h"
|
||||
#include "tlog.h"
|
||||
#include "ttimer.h"
|
||||
|
||||
#define sFatal(...) \
|
||||
{ \
|
||||
if (sDebugFlag & DEBUG_FATAL) { \
|
||||
taosPrintLog("SYN FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
#define sError(...) \
|
||||
{ \
|
||||
if (sDebugFlag & DEBUG_ERROR) { \
|
||||
taosPrintLog("SYN ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
#define sWarn(...) \
|
||||
{ \
|
||||
if (sDebugFlag & DEBUG_WARN) { \
|
||||
taosPrintLog("SYN WARN ", DEBUG_WARN, 255, __VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
#define sInfo(...) \
|
||||
{ \
|
||||
if (sDebugFlag & DEBUG_INFO) { \
|
||||
taosPrintLog("SYN INFO ", DEBUG_INFO, 255, __VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
#define sDebug(...) \
|
||||
{ \
|
||||
if (sDebugFlag & DEBUG_DEBUG) { \
|
||||
taosPrintLog("SYN DEBUG ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
#define sTrace(...) \
|
||||
{ \
|
||||
if (sDebugFlag & DEBUG_TRACE) { \
|
||||
taosPrintLog("SYN TRACE ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
// clang-format off
|
||||
#define sFatal(...) do { if (sDebugFlag & DEBUG_FATAL) { taosPrintLog("SYN FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0)
|
||||
#define sError(...) do { if (sDebugFlag & DEBUG_ERROR) { taosPrintLog("SYN ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0)
|
||||
#define sWarn(...) do { if (sDebugFlag & DEBUG_WARN) { taosPrintLog("SYN WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0)
|
||||
#define sInfo(...) do { if (sDebugFlag & DEBUG_INFO) { taosPrintLog("SYN ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0)
|
||||
#define sDebug(...) do { if (sDebugFlag & DEBUG_DEBUG) { taosPrintLog("SYN ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define sTrace(...) do { if (sDebugFlag & DEBUG_TRACE) { taosPrintLog("SYN ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define sFatalLong(...) do { if (sDebugFlag & DEBUG_FATAL) { taosPrintLongString("SYN FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0)
|
||||
#define sErrorLong(...) do { if (sDebugFlag & DEBUG_ERROR) { taosPrintLongString("SYN ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0)
|
||||
#define sWarnLong(...) do { if (sDebugFlag & DEBUG_WARN) { taosPrintLongString("SYN WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0)
|
||||
#define sInfoLong(...) do { if (sDebugFlag & DEBUG_INFO) { taosPrintLongString("SYN ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0)
|
||||
#define sDebugLong(...) do { if (sDebugFlag & DEBUG_DEBUG) { taosPrintLongString("SYN ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define sTraceLong(...) do { if (sDebugFlag & DEBUG_TRACE) { taosPrintLongString("SYN ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); }} while(0)
|
||||
// clang-format on
|
||||
|
||||
#define sFatalLong(...) \
|
||||
{ \
|
||||
if (sDebugFlag & DEBUG_FATAL) { \
|
||||
taosPrintLongString("SYN FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
#define sErrorLong(...) \
|
||||
{ \
|
||||
if (sDebugFlag & DEBUG_ERROR) { \
|
||||
taosPrintLongString("SYN ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
#define sWarnLong(...) \
|
||||
{ \
|
||||
if (sDebugFlag & DEBUG_WARN) { \
|
||||
taosPrintLongString("SYN WARN ", DEBUG_WARN, 255, __VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
#define sInfoLong(...) \
|
||||
{ \
|
||||
if (sDebugFlag & DEBUG_INFO) { \
|
||||
taosPrintLongString("SYN INFO ", DEBUG_INFO, 255, __VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
#define sDebugLong(...) \
|
||||
{ \
|
||||
if (sDebugFlag & DEBUG_DEBUG) { \
|
||||
taosPrintLongString("SYN DEBUG ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
#define sTraceLong(...) \
|
||||
{ \
|
||||
if (sDebugFlag & DEBUG_TRACE) { \
|
||||
taosPrintLongString("SYN TRACE ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); \
|
||||
} \
|
||||
}
|
||||
|
||||
struct SyncTimeout;
|
||||
typedef struct SyncTimeout SyncTimeout;
|
||||
|
||||
struct SyncClientRequest;
|
||||
typedef struct SyncClientRequest SyncClientRequest;
|
||||
|
||||
struct SyncPing;
|
||||
typedef struct SyncPing SyncPing;
|
||||
|
||||
struct SyncPingReply;
|
||||
typedef struct SyncPingReply SyncPingReply;
|
||||
|
||||
struct SyncRequestVote;
|
||||
typedef struct SyncRequestVote SyncRequestVote;
|
||||
|
||||
struct SyncRequestVoteReply;
|
||||
typedef struct SyncRequestVoteReply SyncRequestVoteReply;
|
||||
|
||||
struct SyncAppendEntries;
|
||||
typedef struct SyncAppendEntries SyncAppendEntries;
|
||||
|
||||
struct SyncAppendEntriesReply;
|
||||
typedef struct SyncTimeout SyncTimeout;
|
||||
typedef struct SyncClientRequest SyncClientRequest;
|
||||
typedef struct SyncPing SyncPing;
|
||||
typedef struct SyncPingReply SyncPingReply;
|
||||
typedef struct SyncRequestVote SyncRequestVote;
|
||||
typedef struct SyncRequestVoteReply SyncRequestVoteReply;
|
||||
typedef struct SyncAppendEntries SyncAppendEntries;
|
||||
typedef struct SyncAppendEntriesReply SyncAppendEntriesReply;
|
||||
|
||||
struct SSyncEnv;
|
||||
typedef struct SSyncEnv SSyncEnv;
|
||||
|
||||
struct SRaftStore;
|
||||
typedef struct SRaftStore SRaftStore;
|
||||
|
||||
struct SVotesGranted;
|
||||
typedef struct SVotesGranted SVotesGranted;
|
||||
|
||||
struct SVotesRespond;
|
||||
typedef struct SVotesRespond SVotesRespond;
|
||||
|
||||
struct SSyncIndexMgr;
|
||||
typedef struct SSyncIndexMgr SSyncIndexMgr;
|
||||
|
||||
struct SRaftCfg;
|
||||
typedef struct SRaftCfg SRaftCfg;
|
||||
|
||||
struct SSyncRespMgr;
|
||||
typedef struct SSyncRespMgr SSyncRespMgr;
|
||||
typedef struct SSyncEnv SSyncEnv;
|
||||
typedef struct SRaftStore SRaftStore;
|
||||
typedef struct SVotesGranted SVotesGranted;
|
||||
typedef struct SVotesRespond SVotesRespond;
|
||||
typedef struct SSyncIndexMgr SSyncIndexMgr;
|
||||
typedef struct SRaftCfg SRaftCfg;
|
||||
typedef struct SSyncRespMgr SSyncRespMgr;
|
||||
|
||||
typedef struct SSyncNode {
|
||||
// init by SSyncInfo
|
||||
|
@ -159,11 +65,10 @@ typedef struct SSyncNode {
|
|||
char configPath[TSDB_FILENAME_LEN * 2];
|
||||
|
||||
// sync io
|
||||
SWal* pWal;
|
||||
void* rpcClient;
|
||||
int32_t (*FpSendMsg)(void* rpcClient, const SEpSet* pEpSet, SRpcMsg* pMsg);
|
||||
void* queue;
|
||||
int32_t (*FpEqMsg)(void* queue, SRpcMsg* pMsg);
|
||||
SWal* pWal;
|
||||
const SMsgCb* msgcb;
|
||||
int32_t (*FpSendMsg)(const SEpSet* pEpSet, SRpcMsg* pMsg);
|
||||
int32_t (*FpEqMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg);
|
||||
|
||||
// init internal
|
||||
SNodeInfo myNodeInfo;
|
||||
|
|
|
@ -66,7 +66,7 @@ int32_t syncIOStop() {
|
|||
return ret;
|
||||
}
|
||||
|
||||
int32_t syncIOSendMsg(void *clientRpc, const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||
int32_t syncIOSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||
assert(pEpSet->inUse == 0);
|
||||
assert(pEpSet->numOfEps == 1);
|
||||
|
||||
|
@ -83,11 +83,11 @@ int32_t syncIOSendMsg(void *clientRpc, const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
|||
|
||||
pMsg->info.handle = NULL;
|
||||
pMsg->info.noResp = 1;
|
||||
rpcSendRequest(clientRpc, pEpSet, pMsg, NULL);
|
||||
rpcSendRequest(gSyncIO->clientRpc, pEpSet, pMsg, NULL);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t syncIOEqMsg(void *queue, SRpcMsg *pMsg) {
|
||||
int32_t syncIOEqMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) {
|
||||
int32_t ret = 0;
|
||||
char logBuf[128];
|
||||
syncRpcMsgLog2((char *)"==syncIOEqMsg==", pMsg);
|
||||
|
@ -96,7 +96,7 @@ int32_t syncIOEqMsg(void *queue, SRpcMsg *pMsg) {
|
|||
pTemp = taosAllocateQitem(sizeof(SRpcMsg), DEF_QITEM);
|
||||
memcpy(pTemp, pMsg, sizeof(SRpcMsg));
|
||||
|
||||
STaosQueue *pMsgQ = queue;
|
||||
STaosQueue *pMsgQ = gSyncIO->pMsgQ;
|
||||
taosWriteQitem(pMsgQ, pTemp);
|
||||
|
||||
return ret;
|
||||
|
@ -183,9 +183,6 @@ static int32_t syncIOStartInternal(SSyncIO *io) {
|
|||
rpcInit.sessions = 100;
|
||||
rpcInit.idleTime = 100;
|
||||
rpcInit.user = "sync-io";
|
||||
rpcInit.secret = "sync-io";
|
||||
rpcInit.ckey = "key";
|
||||
rpcInit.spi = 0;
|
||||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
|
||||
io->clientRpc = rpcOpen(&rpcInit);
|
||||
|
@ -206,7 +203,6 @@ static int32_t syncIOStartInternal(SSyncIO *io) {
|
|||
rpcInit.cfp = syncIOProcessRequest;
|
||||
rpcInit.sessions = 1000;
|
||||
rpcInit.idleTime = 2 * 1500;
|
||||
rpcInit.afp = syncIOAuth;
|
||||
rpcInit.parent = io;
|
||||
rpcInit.connType = TAOS_CONN_SERVER;
|
||||
|
||||
|
|
|
@ -240,26 +240,14 @@ int32_t syncGetAndDelRespRpc(int64_t rid, uint64_t index, SRpcMsg* msg) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
void syncSetQ(int64_t rid, void* queue) {
|
||||
void syncSetMsgCb(int64_t rid, const SMsgCb *msgcb) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
if (pSyncNode == NULL) {
|
||||
sTrace("syncSetQ get pSyncNode is NULL, rid:%ld", rid);
|
||||
return;
|
||||
}
|
||||
assert(rid == pSyncNode->rid);
|
||||
pSyncNode->queue = queue;
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
}
|
||||
|
||||
void syncSetRpc(int64_t rid, void* rpcHandle) {
|
||||
SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid);
|
||||
if (pSyncNode == NULL) {
|
||||
sTrace("syncSetRpc get pSyncNode is NULL, rid:%ld", rid);
|
||||
return;
|
||||
}
|
||||
assert(rid == pSyncNode->rid);
|
||||
pSyncNode->rpcClient = rpcHandle;
|
||||
pSyncNode->msgcb = msgcb;
|
||||
|
||||
taosReleaseRef(tsNodeRefId, pSyncNode->rid);
|
||||
}
|
||||
|
@ -332,7 +320,7 @@ int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak) {
|
|||
SRpcMsg rpcMsg;
|
||||
syncClientRequest2RpcMsg(pSyncMsg, &rpcMsg);
|
||||
if (pSyncNode->FpEqMsg != NULL) {
|
||||
pSyncNode->FpEqMsg(pSyncNode->queue, &rpcMsg);
|
||||
pSyncNode->FpEqMsg(pSyncNode->msgcb, &rpcMsg);
|
||||
} else {
|
||||
sTrace("syncPropose pSyncNode->FpEqMsg is NULL");
|
||||
}
|
||||
|
@ -375,9 +363,8 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) {
|
|||
snprintf(pSyncNode->configPath, sizeof(pSyncNode->configPath), "%s/raft_config.json", pSyncInfo->path);
|
||||
|
||||
pSyncNode->pWal = pSyncInfo->pWal;
|
||||
pSyncNode->rpcClient = pSyncInfo->rpcClient;
|
||||
pSyncNode->msgcb = pSyncInfo->msgcb;
|
||||
pSyncNode->FpSendMsg = pSyncInfo->FpSendMsg;
|
||||
pSyncNode->queue = pSyncInfo->queue;
|
||||
pSyncNode->FpEqMsg = pSyncInfo->FpEqMsg;
|
||||
|
||||
// init raft config
|
||||
|
@ -687,11 +674,11 @@ int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRp
|
|||
SEpSet epSet;
|
||||
syncUtilraftId2EpSet(destRaftId, &epSet);
|
||||
if (pSyncNode->FpSendMsg != NULL) {
|
||||
pMsg->info.noResp = 1;
|
||||
// htonl
|
||||
syncUtilMsgHtoN(pMsg->pCont);
|
||||
|
||||
pSyncNode->FpSendMsg(pSyncNode->rpcClient, &epSet, pMsg);
|
||||
pMsg->info.noResp = 1;
|
||||
pSyncNode->FpSendMsg(&epSet, pMsg);
|
||||
} else {
|
||||
sTrace("syncNodeSendMsgById pSyncNode->FpSendMsg is NULL");
|
||||
}
|
||||
|
@ -702,11 +689,11 @@ int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, S
|
|||
SEpSet epSet;
|
||||
syncUtilnodeInfo2EpSet(nodeInfo, &epSet);
|
||||
if (pSyncNode->FpSendMsg != NULL) {
|
||||
pMsg->info.noResp = 1;
|
||||
// htonl
|
||||
syncUtilMsgHtoN(pMsg->pCont);
|
||||
|
||||
pSyncNode->FpSendMsg(pSyncNode->rpcClient, &epSet, pMsg);
|
||||
pMsg->info.noResp = 1;
|
||||
pSyncNode->FpSendMsg(&epSet, pMsg);
|
||||
} else {
|
||||
sTrace("syncNodeSendMsgByInfo pSyncNode->FpSendMsg is NULL");
|
||||
}
|
||||
|
@ -728,12 +715,12 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
|
|||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pWal);
|
||||
cJSON_AddStringToObject(pRoot, "pWal", u64buf);
|
||||
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->rpcClient);
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->msgcb);
|
||||
cJSON_AddStringToObject(pRoot, "rpcClient", u64buf);
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpSendMsg);
|
||||
cJSON_AddStringToObject(pRoot, "FpSendMsg", u64buf);
|
||||
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->queue);
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->msgcb);
|
||||
cJSON_AddStringToObject(pRoot, "queue", u64buf);
|
||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpEqMsg);
|
||||
cJSON_AddStringToObject(pRoot, "FpEqMsg", u64buf);
|
||||
|
@ -1095,7 +1082,7 @@ static void syncNodeEqPingTimer(void* param, void* tmrId) {
|
|||
syncTimeout2RpcMsg(pSyncMsg, &rpcMsg);
|
||||
syncRpcMsgLog2((char*)"==syncNodeEqPingTimer==", &rpcMsg);
|
||||
if (pSyncNode->FpEqMsg != NULL) {
|
||||
pSyncNode->FpEqMsg(pSyncNode->queue, &rpcMsg);
|
||||
pSyncNode->FpEqMsg(pSyncNode->msgcb, &rpcMsg);
|
||||
} else {
|
||||
sTrace("syncNodeEqPingTimer pSyncNode->FpEqMsg is NULL");
|
||||
}
|
||||
|
@ -1118,7 +1105,7 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) {
|
|||
syncTimeout2RpcMsg(pSyncMsg, &rpcMsg);
|
||||
syncRpcMsgLog2((char*)"==syncNodeEqElectTimer==", &rpcMsg);
|
||||
if (pSyncNode->FpEqMsg != NULL) {
|
||||
pSyncNode->FpEqMsg(pSyncNode->queue, &rpcMsg);
|
||||
pSyncNode->FpEqMsg(pSyncNode->msgcb, &rpcMsg);
|
||||
} else {
|
||||
sTrace("syncNodeEqElectTimer pSyncNode->FpEqMsg is NULL");
|
||||
}
|
||||
|
@ -1145,7 +1132,7 @@ static void syncNodeEqHeartbeatTimer(void* param, void* tmrId) {
|
|||
syncTimeout2RpcMsg(pSyncMsg, &rpcMsg);
|
||||
syncRpcMsgLog2((char*)"==syncNodeEqHeartbeatTimer==", &rpcMsg);
|
||||
if (pSyncNode->FpEqMsg != NULL) {
|
||||
pSyncNode->FpEqMsg(pSyncNode->queue, &rpcMsg);
|
||||
pSyncNode->FpEqMsg(pSyncNode->msgcb, &rpcMsg);
|
||||
} else {
|
||||
sTrace("syncNodeEqHeartbeatTimer pSyncNode->FpEqMsg is NULL");
|
||||
}
|
||||
|
@ -1175,10 +1162,10 @@ static int32_t syncNodeEqNoop(SSyncNode* ths) {
|
|||
assert(pSyncMsg->dataLen == entryLen);
|
||||
memcpy(pSyncMsg->data, serialized, entryLen);
|
||||
|
||||
SRpcMsg rpcMsg;
|
||||
SRpcMsg rpcMsg = {0};
|
||||
syncClientRequest2RpcMsg(pSyncMsg, &rpcMsg);
|
||||
if (ths->FpEqMsg != NULL) {
|
||||
ths->FpEqMsg(ths->queue, &rpcMsg);
|
||||
ths->FpEqMsg(ths->msgcb, &rpcMsg);
|
||||
} else {
|
||||
sTrace("syncNodeEqNoop pSyncNode->FpEqMsg is NULL");
|
||||
}
|
||||
|
|
|
@ -100,9 +100,8 @@ SWal* createWal(char* path, int32_t vgId) {
|
|||
int64_t createSyncNode(int32_t replicaNum, int32_t myIndex, int32_t vgId, SWal* pWal, char* path, bool isStandBy) {
|
||||
SSyncInfo syncInfo;
|
||||
syncInfo.vgId = vgId;
|
||||
syncInfo.rpcClient = gSyncIO->clientRpc;
|
||||
syncInfo.msgcb = &gSyncIO->msgcb;
|
||||
syncInfo.FpSendMsg = syncIOSendMsg;
|
||||
syncInfo.queue = gSyncIO->pMsgQ;
|
||||
syncInfo.FpEqMsg = syncIOEqMsg;
|
||||
syncInfo.pFsm = createFsm();
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s_sync_replica%d_index%d", path, replicaNum, myIndex);
|
||||
|
|
|
@ -44,9 +44,8 @@ SWal* createWal(char* path, int32_t vgId) {
|
|||
SSyncNode* createSyncNode(int32_t replicaNum, int32_t myIndex, int32_t vgId, SWal* pWal, char* path) {
|
||||
SSyncInfo syncInfo;
|
||||
syncInfo.vgId = vgId;
|
||||
syncInfo.rpcClient = gSyncIO->clientRpc;
|
||||
syncInfo.msgcb = &gSyncIO->msgcb;
|
||||
syncInfo.FpSendMsg = syncIOSendMsg;
|
||||
syncInfo.queue = gSyncIO->pMsgQ;
|
||||
syncInfo.FpEqMsg = syncIOEqMsg;
|
||||
syncInfo.pFsm = NULL;
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s_sync_replica%d_index%d", path, replicaNum, myIndex);
|
||||
|
|
|
@ -31,9 +31,8 @@ SSyncNode *pSyncNode;
|
|||
|
||||
SSyncNode *syncNodeInit() {
|
||||
syncInfo.vgId = 1234;
|
||||
syncInfo.rpcClient = gSyncIO->clientRpc;
|
||||
syncInfo.msgcb = &gSyncIO->msgcb;
|
||||
syncInfo.FpSendMsg = syncIOSendMsg;
|
||||
syncInfo.queue = gSyncIO->pMsgQ;
|
||||
syncInfo.FpEqMsg = syncIOEqMsg;
|
||||
syncInfo.pFsm = pFsm;
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./");
|
||||
|
|
|
@ -25,9 +25,7 @@ SSyncFSM* pFsm;
|
|||
|
||||
SSyncNode* syncNodeInit() {
|
||||
syncInfo.vgId = 1234;
|
||||
syncInfo.rpcClient = gSyncIO->clientRpc;
|
||||
syncInfo.FpSendMsg = syncIOSendMsg;
|
||||
syncInfo.queue = gSyncIO->pMsgQ;
|
||||
syncInfo.FpEqMsg = syncIOEqMsg;
|
||||
syncInfo.pFsm = pFsm;
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./");
|
||||
|
@ -99,7 +97,7 @@ int main(int argc, char** argv) {
|
|||
SyncPingReply* pSyncMsg = syncPingReplyBuild2(&pSyncNode->myRaftId, &pSyncNode->myRaftId, 1000, "syncEnqTest");
|
||||
SRpcMsg rpcMsg;
|
||||
syncPingReply2RpcMsg(pSyncMsg, &rpcMsg);
|
||||
pSyncNode->FpEqMsg(pSyncNode->queue, &rpcMsg);
|
||||
pSyncNode->FpEqMsg(pSyncNode->msgcb, &rpcMsg);
|
||||
taosMsleep(1000);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ int main() {
|
|||
SRpcMsg rpcMsg;
|
||||
syncPingReply2RpcMsg(pSyncMsg, &rpcMsg);
|
||||
|
||||
syncIOSendMsg(gSyncIO->clientRpc, &epSet, &rpcMsg);
|
||||
syncIOSendMsg(&epSet, &rpcMsg);
|
||||
taosSsleep(1);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,9 +25,8 @@ SSyncFSM* pFsm;
|
|||
|
||||
SSyncNode* syncNodeInit() {
|
||||
syncInfo.vgId = 1234;
|
||||
syncInfo.rpcClient = gSyncIO->clientRpc;
|
||||
syncInfo.msgcb = &gSyncIO->msgcb;
|
||||
syncInfo.FpSendMsg = syncIOSendMsg;
|
||||
syncInfo.queue = gSyncIO->pMsgQ;
|
||||
syncInfo.FpEqMsg = syncIOEqMsg;
|
||||
syncInfo.pFsm = pFsm;
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./");
|
||||
|
@ -98,12 +97,13 @@ int main(int argc, char** argv) {
|
|||
for (int i = 0; i < 10; ++i) {
|
||||
SyncPingReply* pSyncMsg =
|
||||
syncPingReplyBuild2(&pSyncNode->myRaftId, &pSyncNode->myRaftId, 1000, "syncIOSendMsgTest");
|
||||
SRpcMsg rpcMsg;
|
||||
SRpcMsg rpcMsg = {0};
|
||||
syncPingReply2RpcMsg(pSyncMsg, &rpcMsg);
|
||||
|
||||
SEpSet epSet;
|
||||
syncUtilnodeInfo2EpSet(&pSyncNode->myNodeInfo, &epSet);
|
||||
pSyncNode->FpSendMsg(pSyncNode->rpcClient, &epSet, &rpcMsg);
|
||||
rpcMsg.info.noResp = 1;
|
||||
pSyncNode->FpSendMsg(&epSet, &rpcMsg);
|
||||
|
||||
taosMsleep(1000);
|
||||
}
|
||||
|
|
|
@ -28,9 +28,8 @@ SSyncNode* pSyncNode;
|
|||
|
||||
SSyncNode* syncNodeInit() {
|
||||
syncInfo.vgId = 1234;
|
||||
syncInfo.rpcClient = gSyncIO->clientRpc;
|
||||
syncInfo.msgcb = &gSyncIO->msgcb;
|
||||
syncInfo.FpSendMsg = syncIOSendMsg;
|
||||
syncInfo.queue = gSyncIO->pMsgQ;
|
||||
syncInfo.FpEqMsg = syncIOEqMsg;
|
||||
syncInfo.pFsm = pFsm;
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./");
|
||||
|
|
|
@ -25,9 +25,8 @@ SSyncFSM* pFsm;
|
|||
|
||||
SSyncNode* syncNodeInit() {
|
||||
syncInfo.vgId = 1234;
|
||||
syncInfo.rpcClient = gSyncIO->clientRpc;
|
||||
syncInfo.msgcb = &gSyncIO->msgcb;
|
||||
syncInfo.FpSendMsg = syncIOSendMsg;
|
||||
syncInfo.queue = gSyncIO->pMsgQ;
|
||||
syncInfo.FpEqMsg = syncIOEqMsg;
|
||||
syncInfo.pFsm = pFsm;
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./sync_init_test");
|
||||
|
|
|
@ -25,9 +25,8 @@ SSyncFSM* pFsm;
|
|||
|
||||
SSyncNode* syncNodeInit() {
|
||||
syncInfo.vgId = 1234;
|
||||
syncInfo.rpcClient = gSyncIO->clientRpc;
|
||||
syncInfo.msgcb = &gSyncIO->msgcb;
|
||||
syncInfo.FpSendMsg = syncIOSendMsg;
|
||||
syncInfo.queue = gSyncIO->pMsgQ;
|
||||
syncInfo.FpEqMsg = syncIOEqMsg;
|
||||
syncInfo.pFsm = pFsm;
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./");
|
||||
|
|
|
@ -25,9 +25,8 @@ SSyncFSM* pFsm;
|
|||
|
||||
SSyncNode* syncNodeInit() {
|
||||
syncInfo.vgId = 1234;
|
||||
syncInfo.rpcClient = gSyncIO->clientRpc;
|
||||
syncInfo.msgcb = &gSyncIO->msgcb;
|
||||
syncInfo.FpSendMsg = syncIOSendMsg;
|
||||
syncInfo.queue = gSyncIO->pMsgQ;
|
||||
syncInfo.FpEqMsg = syncIOEqMsg;
|
||||
syncInfo.pFsm = pFsm;
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./");
|
||||
|
|
|
@ -25,9 +25,8 @@ SSyncFSM* pFsm;
|
|||
|
||||
SSyncNode* syncNodeInit() {
|
||||
syncInfo.vgId = 1234;
|
||||
syncInfo.rpcClient = gSyncIO->clientRpc;
|
||||
syncInfo.msgcb = &gSyncIO->msgcb;
|
||||
syncInfo.FpSendMsg = syncIOSendMsg;
|
||||
syncInfo.queue = gSyncIO->pMsgQ;
|
||||
syncInfo.FpEqMsg = syncIOEqMsg;
|
||||
syncInfo.pFsm = pFsm;
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./");
|
||||
|
|
|
@ -97,9 +97,8 @@ SWal* createWal(char* path, int32_t vgId) {
|
|||
int64_t createSyncNode(int32_t replicaNum, int32_t myIndex, int32_t vgId, SWal* pWal, char* path) {
|
||||
SSyncInfo syncInfo;
|
||||
syncInfo.vgId = vgId;
|
||||
syncInfo.rpcClient = gSyncIO->clientRpc;
|
||||
syncInfo.msgcb = &gSyncIO->msgcb;
|
||||
syncInfo.FpSendMsg = syncIOSendMsg;
|
||||
syncInfo.queue = gSyncIO->pMsgQ;
|
||||
syncInfo.FpEqMsg = syncIOEqMsg;
|
||||
syncInfo.pFsm = createFsm();
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s_sync_replica%d_index%d", path, replicaNum, myIndex);
|
||||
|
|
|
@ -83,9 +83,8 @@ void initFsm() {
|
|||
|
||||
SSyncNode *syncNodeInit() {
|
||||
syncInfo.vgId = 1234;
|
||||
syncInfo.rpcClient = gSyncIO->clientRpc;
|
||||
syncInfo.msgcb = &gSyncIO->msgcb;
|
||||
syncInfo.FpSendMsg = syncIOSendMsg;
|
||||
syncInfo.queue = gSyncIO->pMsgQ;
|
||||
syncInfo.FpEqMsg = syncIOEqMsg;
|
||||
syncInfo.pFsm = pFsm;
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", pDir);
|
||||
|
@ -200,7 +199,7 @@ int main(int argc, char **argv) {
|
|||
SyncClientRequest *pSyncClientRequest = pMsg1;
|
||||
SRpcMsg rpcMsg;
|
||||
syncClientRequest2RpcMsg(pSyncClientRequest, &rpcMsg);
|
||||
gSyncNode->FpEqMsg(gSyncNode->queue, &rpcMsg);
|
||||
gSyncNode->FpEqMsg(gSyncNode->msgcb, &rpcMsg);
|
||||
|
||||
taosMsleep(1000);
|
||||
}
|
||||
|
|
|
@ -27,9 +27,8 @@ SSyncNode* pSyncNode;
|
|||
|
||||
SSyncNode* syncNodeInit() {
|
||||
syncInfo.vgId = 1234;
|
||||
syncInfo.rpcClient = gSyncIO->clientRpc;
|
||||
syncInfo.msgcb = &gSyncIO->msgcb;
|
||||
syncInfo.FpSendMsg = syncIOSendMsg;
|
||||
syncInfo.queue = gSyncIO->pMsgQ;
|
||||
syncInfo.FpEqMsg = syncIOEqMsg;
|
||||
syncInfo.pFsm = pFsm;
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./");
|
||||
|
|
|
@ -27,9 +27,8 @@ SSyncNode* pSyncNode;
|
|||
|
||||
SSyncNode* syncNodeInit() {
|
||||
syncInfo.vgId = 1234;
|
||||
syncInfo.rpcClient = gSyncIO->clientRpc;
|
||||
syncInfo.msgcb = &gSyncIO->msgcb;
|
||||
syncInfo.FpSendMsg = syncIOSendMsg;
|
||||
syncInfo.queue = gSyncIO->pMsgQ;
|
||||
syncInfo.FpEqMsg = syncIOEqMsg;
|
||||
syncInfo.pFsm = pFsm;
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./");
|
||||
|
|
|
@ -62,9 +62,8 @@ void initFsm() {
|
|||
|
||||
SSyncNode *syncNodeInit() {
|
||||
syncInfo.vgId = 1234;
|
||||
syncInfo.rpcClient = gSyncIO->clientRpc;
|
||||
syncInfo.msgcb = &gSyncIO->msgcb;
|
||||
syncInfo.FpSendMsg = syncIOSendMsg;
|
||||
syncInfo.queue = gSyncIO->pMsgQ;
|
||||
syncInfo.FpEqMsg = syncIOEqMsg;
|
||||
syncInfo.pFsm = pFsm;
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", pDir);
|
||||
|
@ -178,7 +177,7 @@ int main(int argc, char **argv) {
|
|||
SyncClientRequest *pSyncClientRequest = pMsg1;
|
||||
SRpcMsg rpcMsg;
|
||||
syncClientRequest2RpcMsg(pSyncClientRequest, &rpcMsg);
|
||||
gSyncNode->FpEqMsg(gSyncNode->queue, &rpcMsg);
|
||||
gSyncNode->FpEqMsg(gSyncNode->msgcb, &rpcMsg);
|
||||
|
||||
taosMsleep(1000);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,9 @@
|
|||
*/
|
||||
#include "tdbInt.h"
|
||||
|
||||
// #include <sys/types.h>
|
||||
// #include <unistd.h>
|
||||
|
||||
struct SPCache {
|
||||
int szPage;
|
||||
int nPages;
|
||||
|
@ -32,7 +35,6 @@ static inline uint32_t tdbPCachePageHash(const SPgid *pPgid) {
|
|||
uint32_t *t = (uint32_t *)((pPgid)->fileid);
|
||||
return (uint32_t)(t[0] + t[1] + t[2] + t[3] + t[4] + t[5] + (pPgid)->pgno);
|
||||
}
|
||||
#define PAGE_IS_PINNED(pPage) ((pPage)->pLruNext == NULL)
|
||||
|
||||
static int tdbPCacheOpenImpl(SPCache *pCache);
|
||||
static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, TXN *pTxn);
|
||||
|
@ -80,16 +82,22 @@ int tdbPCacheClose(SPCache *pCache) {
|
|||
|
||||
SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, TXN *pTxn) {
|
||||
SPage *pPage;
|
||||
i32 nRef;
|
||||
|
||||
tdbPCacheLock(pCache);
|
||||
|
||||
pPage = tdbPCacheFetchImpl(pCache, pPgid, pTxn);
|
||||
if (pPage) {
|
||||
tdbRefPage(pPage);
|
||||
nRef = tdbRefPage(pPage);
|
||||
}
|
||||
|
||||
ASSERT(pPage);
|
||||
|
||||
tdbPCacheUnlock(pCache);
|
||||
|
||||
// printf("thread %" PRId64 " fetch page %d pgno %d pPage %p nRef %d\n", taosGetSelfPthreadId(), pPage->id,
|
||||
// TDB_PAGE_PGNO(pPage), pPage, nRef);
|
||||
|
||||
return pPage;
|
||||
}
|
||||
|
||||
|
@ -98,30 +106,31 @@ void tdbPCacheRelease(SPCache *pCache, SPage *pPage, TXN *pTxn) {
|
|||
|
||||
ASSERT(pTxn);
|
||||
|
||||
// nRef = tdbUnrefPage(pPage);
|
||||
// ASSERT(nRef >= 0);
|
||||
|
||||
tdbPCacheLock(pCache);
|
||||
nRef = tdbUnrefPage(pPage);
|
||||
ASSERT(nRef >= 0);
|
||||
|
||||
if (nRef == 0) {
|
||||
tdbPCacheLock(pCache);
|
||||
|
||||
// test the nRef again to make sure
|
||||
// it is safe th handle the page
|
||||
nRef = tdbGetPageRef(pPage);
|
||||
if (nRef == 0) {
|
||||
if (pPage->isLocal) {
|
||||
tdbPCacheUnpinPage(pCache, pPage);
|
||||
} else {
|
||||
if (TDB_TXN_IS_WRITE(pTxn)) {
|
||||
// remove from hash
|
||||
tdbPCacheRemovePageFromHash(pCache, pPage);
|
||||
}
|
||||
|
||||
tdbPageDestroy(pPage, pTxn->xFree, pTxn->xArg);
|
||||
// nRef = tdbGetPageRef(pPage);
|
||||
// if (nRef == 0) {
|
||||
if (pPage->isLocal) {
|
||||
tdbPCacheUnpinPage(pCache, pPage);
|
||||
} else {
|
||||
if (TDB_TXN_IS_WRITE(pTxn)) {
|
||||
// remove from hash
|
||||
tdbPCacheRemovePageFromHash(pCache, pPage);
|
||||
}
|
||||
}
|
||||
|
||||
tdbPCacheUnlock(pCache);
|
||||
tdbPageDestroy(pPage, pTxn->xFree, pTxn->xArg);
|
||||
}
|
||||
// }
|
||||
}
|
||||
tdbPCacheUnlock(pCache);
|
||||
// printf("thread %" PRId64 " relas page %d pgno %d pPage %p nRef %d\n", taosGetSelfPthreadId(), pPage->id,
|
||||
// TDB_PAGE_PGNO(pPage), pPage, nRef);
|
||||
}
|
||||
|
||||
int tdbPCacheGetPageSize(SPCache *pCache) { return pCache->szPage; }
|
||||
|
@ -223,6 +232,7 @@ static void tdbPCachePinPage(SPCache *pCache, SPage *pPage) {
|
|||
|
||||
pCache->nRecyclable--;
|
||||
|
||||
// printf("pin page %d pgno %d pPage %p\n", pPage->id, TDB_PAGE_PGNO(pPage), pPage);
|
||||
tdbTrace("pin page %d", pPage->id);
|
||||
}
|
||||
}
|
||||
|
@ -243,6 +253,7 @@ static void tdbPCacheUnpinPage(SPCache *pCache, SPage *pPage) {
|
|||
|
||||
pCache->nRecyclable++;
|
||||
|
||||
// printf("unpin page %d pgno %d pPage %p\n", pPage->id, TDB_PAGE_PGNO(pPage), pPage);
|
||||
tdbTrace("unpin page %d", pPage->id);
|
||||
}
|
||||
|
||||
|
@ -253,10 +264,12 @@ static void tdbPCacheRemovePageFromHash(SPCache *pCache, SPage *pPage) {
|
|||
h = tdbPCachePageHash(&(pPage->pgid));
|
||||
for (ppPage = &(pCache->pgHash[h % pCache->nHash]); (*ppPage) && *ppPage != pPage; ppPage = &((*ppPage)->pHashNext))
|
||||
;
|
||||
ASSERT(*ppPage == pPage);
|
||||
*ppPage = pPage->pHashNext;
|
||||
|
||||
pCache->nPage--;
|
||||
if (*ppPage) {
|
||||
*ppPage = pPage->pHashNext;
|
||||
pCache->nPage--;
|
||||
// printf("rmv page %d to hash, pgno %d, pPage %p\n", pPage->id, TDB_PAGE_PGNO(pPage), pPage);
|
||||
}
|
||||
|
||||
tdbTrace("remove page %d to hash", pPage->id);
|
||||
}
|
||||
|
@ -271,6 +284,7 @@ static void tdbPCacheAddPageToHash(SPCache *pCache, SPage *pPage) {
|
|||
|
||||
pCache->nPage++;
|
||||
|
||||
// printf("add page %d to hash, pgno %d, pPage %p\n", pPage->id, TDB_PAGE_PGNO(pPage), pPage);
|
||||
tdbTrace("add page %d to hash", pPage->id);
|
||||
}
|
||||
|
||||
|
|
|
@ -265,6 +265,7 @@ int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPa
|
|||
pgid.pgno = pgno;
|
||||
pPage = tdbPCacheFetch(pPager->pCache, &pgid, pTxn);
|
||||
if (pPage == NULL) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -272,10 +273,14 @@ int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPa
|
|||
if (!TDB_PAGE_INITIALIZED(pPage)) {
|
||||
ret = tdbPagerInitPage(pPager, pPage, initPage, arg, loadPage);
|
||||
if (ret < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// printf("thread %" PRId64 " pager fetch page %d pgno %d ppage %p\n", taosGetSelfPthreadId(), pPage->id,
|
||||
// TDB_PAGE_PGNO(pPage), pPage);
|
||||
|
||||
ASSERT(TDB_PAGE_INITIALIZED(pPage));
|
||||
ASSERT(pPage->pPager == pPager);
|
||||
|
||||
|
@ -284,7 +289,11 @@ int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPa
|
|||
return 0;
|
||||
}
|
||||
|
||||
void tdbPagerReturnPage(SPager *pPager, SPage *pPage, TXN *pTxn) { tdbPCacheRelease(pPager->pCache, pPage, pTxn); }
|
||||
void tdbPagerReturnPage(SPager *pPager, SPage *pPage, TXN *pTxn) {
|
||||
tdbPCacheRelease(pPager->pCache, pPage, pTxn);
|
||||
// printf("thread %" PRId64 " pager retun page %d pgno %d ppage %p\n", taosGetSelfPthreadId(), pPage->id,
|
||||
// TDB_PAGE_PGNO(pPage), pPage);
|
||||
}
|
||||
|
||||
static int tdbPagerAllocFreePage(SPager *pPager, SPgno *ppgno) {
|
||||
// TODO: Allocate a page from the free list
|
||||
|
@ -352,6 +361,7 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage
|
|||
|
||||
ret = (*initPage)(pPage, arg, init);
|
||||
if (ret < 0) {
|
||||
ASSERT(0);
|
||||
TDB_UNLOCK_PAGE(pPage);
|
||||
return -1;
|
||||
}
|
||||
|
@ -370,6 +380,7 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage
|
|||
}
|
||||
}
|
||||
} else {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -275,15 +275,15 @@ static inline i32 tdbUnrefPage(SPage *pPage) {
|
|||
#define P_LOCK_FAIL -1
|
||||
|
||||
static inline int tdbTryLockPage(tdb_spinlock_t *pLock) {
|
||||
int ret;
|
||||
if (tdbSpinlockTrylock(pLock) == 0) {
|
||||
ret = P_LOCK_SUCC;
|
||||
} else if (errno == EBUSY) {
|
||||
ret = P_LOCK_BUSY;
|
||||
int ret = tdbSpinlockTrylock(pLock);
|
||||
if (ret == 0) {
|
||||
return P_LOCK_SUCC;
|
||||
} else if (ret == EBUSY) {
|
||||
return P_LOCK_BUSY;
|
||||
} else {
|
||||
ret = P_LOCK_FAIL;
|
||||
ASSERT(0);
|
||||
return P_LOCK_FAIL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define TDB_INIT_PAGE_LOCK(pPage) tdbSpinlockInit(&((pPage)->lock), 0)
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "os.h"
|
||||
#include "tdb.h"
|
||||
|
||||
#include <shared_mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
@ -118,7 +119,7 @@ static int tDefaultKeyCmpr(const void *pKey1, int keyLen1, const void *pKey2, in
|
|||
return cret;
|
||||
}
|
||||
|
||||
TEST(tdb_test, simple_insert1) {
|
||||
TEST(tdb_test, DISABLED_simple_insert1) {
|
||||
int ret;
|
||||
TDB *pEnv;
|
||||
TTB *pDb;
|
||||
|
@ -238,7 +239,7 @@ TEST(tdb_test, simple_insert1) {
|
|||
GTEST_ASSERT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
TEST(tdb_test, simple_insert2) {
|
||||
TEST(tdb_test, DISABLED_simple_insert2) {
|
||||
int ret;
|
||||
TDB *pEnv;
|
||||
TTB *pDb;
|
||||
|
@ -325,7 +326,7 @@ TEST(tdb_test, simple_insert2) {
|
|||
GTEST_ASSERT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
TEST(tdb_test, simple_delete1) {
|
||||
TEST(tdb_test, DISABLED_simple_delete1) {
|
||||
int ret;
|
||||
TTB *pDb;
|
||||
char key[128];
|
||||
|
@ -420,7 +421,7 @@ TEST(tdb_test, simple_delete1) {
|
|||
tdbClose(pEnv);
|
||||
}
|
||||
|
||||
TEST(tdb_test, simple_upsert1) {
|
||||
TEST(tdb_test, DISABLED_simple_upsert1) {
|
||||
int ret;
|
||||
TDB *pEnv;
|
||||
TTB *pDb;
|
||||
|
@ -490,13 +491,13 @@ TEST(tdb_test, multi_thread_query) {
|
|||
TDB *pEnv;
|
||||
TTB *pDb;
|
||||
tdb_cmpr_fn_t compFunc;
|
||||
int nData = 20000;
|
||||
int nData = 1000000;
|
||||
TXN txn;
|
||||
|
||||
taosRemoveDir("tdb");
|
||||
|
||||
// Open Env
|
||||
ret = tdbOpen("tdb", 512, 1, &pEnv);
|
||||
ret = tdbOpen("tdb", 4096, 10, &pEnv);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
|
||||
// Create a database
|
||||
|
@ -506,7 +507,7 @@ TEST(tdb_test, multi_thread_query) {
|
|||
|
||||
char key[64];
|
||||
char val[64];
|
||||
int64_t poolLimit = 4096; // 1M pool limit
|
||||
int64_t poolLimit = 4096 * 20; // 1M pool limit
|
||||
int64_t txnid = 0;
|
||||
SPoolMem *pPool;
|
||||
|
||||
|
@ -598,3 +599,131 @@ TEST(tdb_test, multi_thread_query) {
|
|||
ret = tdbClose(pEnv);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
TEST(tdb_test, DISABLED_multi_thread1) {
|
||||
#if 0
|
||||
int ret;
|
||||
TDB *pDb;
|
||||
TTB *pTb;
|
||||
tdb_cmpr_fn_t compFunc;
|
||||
int nData = 10000000;
|
||||
TXN txn;
|
||||
|
||||
std::shared_timed_mutex mutex;
|
||||
|
||||
taosRemoveDir("tdb");
|
||||
|
||||
// Open Env
|
||||
ret = tdbOpen("tdb", 512, 1, &pDb);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = tdbTbOpen("db.db", -1, -1, NULL, pDb, &pTb);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
|
||||
auto insert = [](TDB *pDb, TTB *pTb, int nData, int *stop, std::shared_timed_mutex *mu) {
|
||||
TXN txn = {0};
|
||||
char key[128];
|
||||
char val[128];
|
||||
SPoolMem *pPool = openPool();
|
||||
|
||||
txn.flags = TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED;
|
||||
txn.txnId = -1;
|
||||
txn.xMalloc = poolMalloc;
|
||||
txn.xFree = poolFree;
|
||||
txn.xArg = pPool;
|
||||
tdbBegin(pDb, &txn);
|
||||
for (int iData = 1; iData <= nData; iData++) {
|
||||
sprintf(key, "key%d", iData);
|
||||
sprintf(val, "value%d", iData);
|
||||
{
|
||||
std::lock_guard<std::shared_timed_mutex> wmutex(*mu);
|
||||
|
||||
int ret = tdbTbInsert(pTb, key, strlen(key), val, strlen(val), &txn);
|
||||
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
if (pPool->size > 1024 * 1024) {
|
||||
tdbCommit(pDb, &txn);
|
||||
|
||||
clearPool(pPool);
|
||||
tdbBegin(pDb, &txn);
|
||||
}
|
||||
}
|
||||
|
||||
tdbCommit(pDb, &txn);
|
||||
closePool(pPool);
|
||||
|
||||
*stop = 1;
|
||||
};
|
||||
|
||||
auto query = [](TTB *pTb, int *stop, std::shared_timed_mutex *mu) {
|
||||
TBC *pDBC;
|
||||
void *pKey = NULL;
|
||||
void *pVal = NULL;
|
||||
int vLen, kLen;
|
||||
int ret;
|
||||
TXN txn;
|
||||
|
||||
SPoolMem *pPool = openPool();
|
||||
txn.flags = 0;
|
||||
txn.txnId = 0;
|
||||
txn.xMalloc = poolMalloc;
|
||||
txn.xFree = poolFree;
|
||||
txn.xArg = pPool;
|
||||
|
||||
for (;;) {
|
||||
if (*stop) break;
|
||||
|
||||
clearPool(pPool);
|
||||
int count = 0;
|
||||
{
|
||||
std::shared_lock<std::shared_timed_mutex> rMutex(*mu);
|
||||
|
||||
ret = tdbTbcOpen(pTb, &pDBC, &txn);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
|
||||
tdbTbcMoveToFirst(pDBC);
|
||||
|
||||
for (;;) {
|
||||
ret = tdbTbcNext(pDBC, &pKey, &kLen, &pVal, &vLen);
|
||||
if (ret < 0) break;
|
||||
count++;
|
||||
}
|
||||
|
||||
std::cout << count << std::endl;
|
||||
|
||||
tdbTbcClose(pDBC);
|
||||
}
|
||||
|
||||
usleep(500000);
|
||||
}
|
||||
|
||||
closePool(pPool);
|
||||
tdbFree(pKey);
|
||||
tdbFree(pVal);
|
||||
};
|
||||
|
||||
std::vector<std::thread> threads;
|
||||
int nThreads = 10;
|
||||
int stop = 0;
|
||||
for (int i = 0; i < nThreads; i++) {
|
||||
if (i == 0) {
|
||||
threads.push_back(std::thread(insert, pDb, pTb, nData, &stop, &mutex));
|
||||
} else {
|
||||
threads.push_back(std::thread(query, pTb, &stop, &mutex));
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &th : threads) {
|
||||
th.join();
|
||||
}
|
||||
|
||||
// Close a database
|
||||
tdbTbClose(pTb);
|
||||
|
||||
// Close Env
|
||||
ret = tdbClose(pDb);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
#endif
|
||||
}
|
|
@ -52,23 +52,15 @@ typedef struct {
|
|||
int idleTime; // milliseconds;
|
||||
uint16_t localPort;
|
||||
int8_t connType;
|
||||
int64_t index;
|
||||
char label[TSDB_LABEL_LEN];
|
||||
|
||||
char user[TSDB_UNI_LEN]; // meter ID
|
||||
char spi; // security parameter index
|
||||
char encrypt; // encrypt algorithm
|
||||
char secret[TSDB_PASSWORD_LEN]; // secret for the link
|
||||
char ckey[TSDB_PASSWORD_LEN]; // ciphering key
|
||||
char user[TSDB_UNI_LEN]; // meter ID
|
||||
|
||||
void (*cfp)(void* parent, SRpcMsg*, SEpSet*);
|
||||
bool (*retry)(int32_t code);
|
||||
int index;
|
||||
|
||||
int32_t refCount;
|
||||
void* parent;
|
||||
void* idPool; // handle to ID pool
|
||||
void* tmrCtrl; // handle to timer
|
||||
SHashObj* hash; // handle returned by hash utility
|
||||
void* tcphandle; // returned handle from TCP initialization
|
||||
TdThreadMutex mutex;
|
||||
} SRpcInfo;
|
||||
|
|
|
@ -69,9 +69,6 @@ void* rpcOpen(const SRpcInit* pInit) {
|
|||
if (pInit->user) {
|
||||
memcpy(pRpc->user, pInit->user, strlen(pInit->user));
|
||||
}
|
||||
if (pInit->secret) {
|
||||
memcpy(pRpc->secret, pInit->secret, strlen(pInit->secret));
|
||||
}
|
||||
return pRpc;
|
||||
}
|
||||
void rpcClose(void* arg) {
|
||||
|
@ -97,7 +94,9 @@ void rpcFreeCont(void* cont) {
|
|||
if (cont == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
taosMemoryFree((char*)cont - TRANS_MSG_OVERHEAD);
|
||||
tTrace("free mem: %p", (char*)cont - TRANS_MSG_OVERHEAD);
|
||||
}
|
||||
void* rpcReallocCont(void* ptr, int contLen) {
|
||||
if (ptr == NULL) {
|
||||
|
|
|
@ -133,6 +133,7 @@ int transAllocBuffer(SConnBuffer* connBuf, uv_buf_t* uvBuf) {
|
|||
} else {
|
||||
p->cap = p->total;
|
||||
p->buf = taosMemoryRealloc(p->buf, p->cap);
|
||||
tTrace("internal malloc mem: %p, size: %d", p->buf, p->cap);
|
||||
|
||||
uvBuf->base = p->buf + p->len;
|
||||
uvBuf->len = p->cap - p->len;
|
||||
|
|
|
@ -469,6 +469,8 @@ static void uvStartSendResp(SSrvMsg* smsg) {
|
|||
|
||||
if (pConn->broken == true) {
|
||||
// persist by
|
||||
transFreeMsg(smsg->msg.pCont);
|
||||
taosMemoryFree(smsg);
|
||||
transUnrefSrvHandle(pConn);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -110,3 +110,13 @@ target_link_libraries (pushServer
|
|||
transport
|
||||
)
|
||||
|
||||
|
||||
add_test(
|
||||
NAME transUT
|
||||
COMMAND transUT
|
||||
)
|
||||
add_test(
|
||||
NAME transUtilUt
|
||||
COMMAND transportTest
|
||||
)
|
||||
|
||||
|
|
|
@ -134,7 +134,6 @@ int main(int argc, char *argv[]) {
|
|||
rpcInit.cfp = processRequestMsg;
|
||||
rpcInit.sessions = 1000;
|
||||
rpcInit.idleTime = 2 * 1500;
|
||||
rpcInit.afp = retrieveAuthInfo;
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (strcmp(argv[i], "-p") == 0 && i < argc - 1) {
|
||||
|
|
|
@ -118,9 +118,6 @@ int main(int argc, char *argv[]) {
|
|||
rpcInit.sessions = 100;
|
||||
rpcInit.idleTime = 100;
|
||||
rpcInit.user = "michael";
|
||||
rpcInit.secret = secret;
|
||||
rpcInit.ckey = "key";
|
||||
rpcInit.spi = 1;
|
||||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
rpcDebugFlag = 131;
|
||||
|
||||
|
@ -144,9 +141,7 @@ int main(int argc, char *argv[]) {
|
|||
} else if (strcmp(argv[i], "-u") == 0 && i < argc - 1) {
|
||||
rpcInit.user = argv[++i];
|
||||
} else if (strcmp(argv[i], "-k") == 0 && i < argc - 1) {
|
||||
rpcInit.secret = argv[++i];
|
||||
} else if (strcmp(argv[i], "-spi") == 0 && i < argc - 1) {
|
||||
rpcInit.spi = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-d") == 0 && i < argc - 1) {
|
||||
rpcDebugFlag = atoi(argv[++i]);
|
||||
} else {
|
||||
|
@ -160,8 +155,6 @@ int main(int argc, char *argv[]) {
|
|||
printf(" [-n requests]: number of requests per thread, default is:%d\n", numOfReqs);
|
||||
printf(" [-o compSize]: compression message size, default is:%d\n", tsCompressMsgSize);
|
||||
printf(" [-u user]: user name for the connection, default is:%s\n", rpcInit.user);
|
||||
printf(" [-k secret]: password for the connection, default is:%s\n", rpcInit.secret);
|
||||
printf(" [-spi SPI]: security parameter index, default is:%d\n", rpcInit.spi);
|
||||
printf(" [-d debugFlag]: debug flag, default:%d\n", rpcDebugFlag);
|
||||
printf(" [-h help]: print out this help\n\n");
|
||||
exit(0);
|
||||
|
|
|
@ -123,7 +123,6 @@ int main(int argc, char *argv[]) {
|
|||
rpcInit.cfp = processRequestMsg;
|
||||
rpcInit.sessions = 1000;
|
||||
rpcInit.idleTime = 2 * 1500;
|
||||
rpcInit.afp = retrieveAuthInfo;
|
||||
|
||||
rpcDebugFlag = 131;
|
||||
|
||||
|
|
|
@ -21,15 +21,15 @@
|
|||
#include "tutil.h"
|
||||
|
||||
typedef struct {
|
||||
int index;
|
||||
SEpSet epSet;
|
||||
int num;
|
||||
int numOfReqs;
|
||||
int msgSize;
|
||||
tsem_t rspSem;
|
||||
tsem_t * pOverSem;
|
||||
int index;
|
||||
SEpSet epSet;
|
||||
int num;
|
||||
int numOfReqs;
|
||||
int msgSize;
|
||||
tsem_t rspSem;
|
||||
tsem_t * pOverSem;
|
||||
TdThread thread;
|
||||
void * pRpc;
|
||||
void * pRpc;
|
||||
} SInfo;
|
||||
static void processResponse(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
SInfo *pInfo = (SInfo *)pMsg->info.ahandle;
|
||||
|
@ -103,7 +103,7 @@ int main(int argc, char *argv[]) {
|
|||
char secret[20] = "mypassword";
|
||||
struct timeval systemTime;
|
||||
int64_t startTime, endTime;
|
||||
TdThreadAttr thattr;
|
||||
TdThreadAttr thattr;
|
||||
|
||||
// server info
|
||||
epSet.inUse = 0;
|
||||
|
@ -119,9 +119,6 @@ int main(int argc, char *argv[]) {
|
|||
rpcInit.sessions = 100;
|
||||
rpcInit.idleTime = 100;
|
||||
rpcInit.user = "michael";
|
||||
rpcInit.secret = secret;
|
||||
rpcInit.ckey = "key";
|
||||
rpcInit.spi = 1;
|
||||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
|
@ -144,9 +141,7 @@ int main(int argc, char *argv[]) {
|
|||
} else if (strcmp(argv[i], "-u") == 0 && i < argc - 1) {
|
||||
rpcInit.user = argv[++i];
|
||||
} else if (strcmp(argv[i], "-k") == 0 && i < argc - 1) {
|
||||
rpcInit.secret = argv[++i];
|
||||
} else if (strcmp(argv[i], "-spi") == 0 && i < argc - 1) {
|
||||
rpcInit.spi = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-d") == 0 && i < argc - 1) {
|
||||
rpcDebugFlag = atoi(argv[++i]);
|
||||
} else {
|
||||
|
@ -160,8 +155,6 @@ int main(int argc, char *argv[]) {
|
|||
printf(" [-n requests]: number of requests per thread, default is:%d\n", numOfReqs);
|
||||
printf(" [-o compSize]: compression message size, default is:%d\n", tsCompressMsgSize);
|
||||
printf(" [-u user]: user name for the connection, default is:%s\n", rpcInit.user);
|
||||
printf(" [-k secret]: password for the connection, default is:%s\n", rpcInit.secret);
|
||||
printf(" [-spi SPI]: security parameter index, default is:%d\n", rpcInit.spi);
|
||||
printf(" [-d debugFlag]: debug flag, default:%d\n", rpcDebugFlag);
|
||||
printf(" [-h help]: print out this help\n\n");
|
||||
exit(0);
|
||||
|
|
|
@ -43,15 +43,13 @@ static void processResp(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet);
|
|||
class Client {
|
||||
public:
|
||||
void Init(int nThread) {
|
||||
memcpy(tsTempDir, "/tmp", strlen("/tmp"));
|
||||
memset(&rpcInit_, 0, sizeof(rpcInit_));
|
||||
rpcInit_.localPort = 0;
|
||||
rpcInit_.label = (char *)label;
|
||||
rpcInit_.numOfThreads = nThread;
|
||||
rpcInit_.cfp = processResp;
|
||||
rpcInit_.user = (char *)user;
|
||||
rpcInit_.secret = (char *)secret;
|
||||
rpcInit_.ckey = (char *)ckey;
|
||||
rpcInit_.spi = 1;
|
||||
rpcInit_.parent = this;
|
||||
rpcInit_.connType = TAOS_CONN_CLIENT;
|
||||
this->transCli = rpcOpen(&rpcInit_);
|
||||
|
@ -107,15 +105,15 @@ class Client {
|
|||
class Server {
|
||||
public:
|
||||
Server() {
|
||||
memcpy(tsTempDir, "/tmp", strlen("/tmp"));
|
||||
memset(&rpcInit_, 0, sizeof(rpcInit_));
|
||||
|
||||
memcpy(rpcInit_.localFqdn, "localhost", strlen("localhost"));
|
||||
rpcInit_.localPort = port;
|
||||
rpcInit_.label = (char *)label;
|
||||
rpcInit_.numOfThreads = 5;
|
||||
rpcInit_.cfp = processReq;
|
||||
rpcInit_.user = (char *)user;
|
||||
rpcInit_.secret = (char *)secret;
|
||||
rpcInit_.ckey = (char *)ckey;
|
||||
rpcInit_.spi = 1;
|
||||
rpcInit_.connType = TAOS_CONN_SERVER;
|
||||
}
|
||||
void Start() {
|
||||
|
@ -300,12 +298,14 @@ TEST_F(TransEnv, 02StopServer) {
|
|||
for (int i = 0; i < 1; i++) {
|
||||
SRpcMsg req = {0}, resp = {0};
|
||||
req.msgType = 0;
|
||||
req.info.ahandle = (void *)0x35;
|
||||
req.pCont = rpcMallocCont(10);
|
||||
req.contLen = 10;
|
||||
tr->cliSendAndRecv(&req, &resp);
|
||||
assert(resp.code == 0);
|
||||
}
|
||||
SRpcMsg req = {0}, resp = {0};
|
||||
req.info.ahandle = (void *)0x35;
|
||||
req.msgType = 1;
|
||||
req.pCont = rpcMallocCont(10);
|
||||
req.contLen = 10;
|
||||
|
@ -388,6 +388,7 @@ TEST_F(TransEnv, cliReleaseHandleExcept) {
|
|||
memset(&req, 0, sizeof(req));
|
||||
req.info = resp.info;
|
||||
req.info.persistHandle = 1;
|
||||
req.info.ahandle = (void *)1234;
|
||||
req.msgType = 1;
|
||||
req.pCont = rpcMallocCont(10);
|
||||
req.contLen = 10;
|
||||
|
@ -406,12 +407,12 @@ TEST_F(TransEnv, srvContinueSend) {
|
|||
tr->SetSrvContinueSend(processContinueSend);
|
||||
SRpcMsg req = {0}, resp = {0};
|
||||
for (int i = 0; i < 10; i++) {
|
||||
memset(&req, 0, sizeof(req));
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
req.msgType = 1;
|
||||
req.pCont = rpcMallocCont(10);
|
||||
req.contLen = 10;
|
||||
tr->cliSendAndRecv(&req, &resp);
|
||||
// memset(&req, 0, sizeof(req));
|
||||
// memset(&resp, 0, sizeof(resp));
|
||||
// req.msgType = 1;
|
||||
// req.pCont = rpcMallocCont(10);
|
||||
// req.contLen = 10;
|
||||
// tr->cliSendAndRecv(&req, &resp);
|
||||
}
|
||||
taosMsleep(1000);
|
||||
}
|
||||
|
@ -422,16 +423,16 @@ TEST_F(TransEnv, srvPersistHandleExcept) {
|
|||
SRpcMsg resp = {0};
|
||||
SRpcMsg req = {0};
|
||||
for (int i = 0; i < 5; i++) {
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.info = resp.info;
|
||||
req.msgType = 1;
|
||||
req.pCont = rpcMallocCont(10);
|
||||
req.contLen = 10;
|
||||
tr->cliSendAndRecv(&req, &resp);
|
||||
if (i > 2) {
|
||||
tr->StopCli();
|
||||
break;
|
||||
}
|
||||
// memset(&req, 0, sizeof(req));
|
||||
// req.info = resp.info;
|
||||
// req.msgType = 1;
|
||||
// req.pCont = rpcMallocCont(10);
|
||||
// req.contLen = 10;
|
||||
// tr->cliSendAndRecv(&req, &resp);
|
||||
// if (i > 2) {
|
||||
// tr->StopCli();
|
||||
// break;
|
||||
//}
|
||||
}
|
||||
taosMsleep(2000);
|
||||
// conn broken
|
||||
|
@ -442,16 +443,16 @@ TEST_F(TransEnv, cliPersistHandleExcept) {
|
|||
SRpcMsg resp = {0};
|
||||
SRpcMsg req = {0};
|
||||
for (int i = 0; i < 5; i++) {
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.info = resp.info;
|
||||
req.msgType = 1;
|
||||
req.pCont = rpcMallocCont(10);
|
||||
req.contLen = 10;
|
||||
tr->cliSendAndRecv(&req, &resp);
|
||||
if (i > 2) {
|
||||
tr->StopSrv();
|
||||
break;
|
||||
}
|
||||
// memset(&req, 0, sizeof(req));
|
||||
// req.info = resp.info;
|
||||
// req.msgType = 1;
|
||||
// req.pCont = rpcMallocCont(10);
|
||||
// req.contLen = 10;
|
||||
// tr->cliSendAndRecv(&req, &resp);
|
||||
// if (i > 2) {
|
||||
// tr->StopSrv();
|
||||
// break;
|
||||
//}
|
||||
}
|
||||
taosMsleep(2000);
|
||||
// conn broken
|
||||
|
@ -465,34 +466,34 @@ TEST_F(TransEnv, queryExcept) {
|
|||
tr->SetSrvContinueSend(processRegisterFailure);
|
||||
SRpcMsg resp = {0};
|
||||
SRpcMsg req = {0};
|
||||
for (int i = 0; i < 5; i++) {
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.info = resp.info;
|
||||
req.info.persistHandle = 1;
|
||||
req.msgType = 1;
|
||||
req.pCont = rpcMallocCont(10);
|
||||
req.contLen = 10;
|
||||
tr->cliSendAndRecv(&req, &resp);
|
||||
if (i == 2) {
|
||||
rpcReleaseHandle(resp.info.handle, TAOS_CONN_CLIENT);
|
||||
tr->StopCli();
|
||||
break;
|
||||
}
|
||||
}
|
||||
// for (int i = 0; i < 5; i++) {
|
||||
// memset(&req, 0, sizeof(req));
|
||||
// req.info = resp.info;
|
||||
// req.info.persistHandle = 1;
|
||||
// req.msgType = 1;
|
||||
// req.pCont = rpcMallocCont(10);
|
||||
// req.contLen = 10;
|
||||
// tr->cliSendAndRecv(&req, &resp);
|
||||
// if (i == 2) {
|
||||
// rpcReleaseHandle(resp.info.handle, TAOS_CONN_CLIENT);
|
||||
// tr->StopCli();
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
taosMsleep(4 * 1000);
|
||||
}
|
||||
TEST_F(TransEnv, noResp) {
|
||||
SRpcMsg resp = {0};
|
||||
SRpcMsg req = {0};
|
||||
for (int i = 0; i < 5; i++) {
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.info.noResp = 1;
|
||||
req.msgType = 1;
|
||||
req.pCont = rpcMallocCont(10);
|
||||
req.contLen = 10;
|
||||
tr->cliSendAndRecv(&req, &resp);
|
||||
}
|
||||
taosMsleep(2000);
|
||||
// for (int i = 0; i < 5; i++) {
|
||||
// memset(&req, 0, sizeof(req));
|
||||
// req.info.noResp = 1;
|
||||
// req.msgType = 1;
|
||||
// req.pCont = rpcMallocCont(10);
|
||||
// req.contLen = 10;
|
||||
// tr->cliSendAndRecv(&req, &resp);
|
||||
//}
|
||||
// taosMsleep(2000);
|
||||
|
||||
// no resp
|
||||
}
|
||||
|
|
|
@ -150,20 +150,26 @@ class TransCtxEnv : public ::testing::Test {
|
|||
STransCtx *ctx;
|
||||
};
|
||||
|
||||
int32_t cloneVal(void *src, void **dst) {
|
||||
int sz = (int)strlen((char *)src);
|
||||
*dst = taosMemoryCalloc(1, sz + 1);
|
||||
memcpy(*dst, src, sz);
|
||||
return 0;
|
||||
}
|
||||
TEST_F(TransCtxEnv, mergeTest) {
|
||||
int key = 1;
|
||||
{
|
||||
STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx));
|
||||
transCtxInit(src);
|
||||
{
|
||||
STransCtxVal val1 = { NULL, NULL, (void (*)(const void*))taosMemoryFree};
|
||||
STransCtxVal val1 = {NULL, NULL, (void (*)(const void *))taosMemoryFree};
|
||||
val1.val = taosMemoryMalloc(12);
|
||||
|
||||
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
key++;
|
||||
}
|
||||
{
|
||||
STransCtxVal val1 = { NULL, NULL, (void (*)(const void*))taosMemoryFree};
|
||||
STransCtxVal val1 = {NULL, NULL, (void (*)(const void *))taosMemoryFree};
|
||||
val1.val = taosMemoryMalloc(12);
|
||||
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
key++;
|
||||
|
@ -176,14 +182,14 @@ TEST_F(TransCtxEnv, mergeTest) {
|
|||
STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx));
|
||||
transCtxInit(src);
|
||||
{
|
||||
STransCtxVal val1 = { NULL, NULL, (void (*)(const void*))taosMemoryFree};
|
||||
STransCtxVal val1 = {NULL, NULL, (void (*)(const void *))taosMemoryFree};
|
||||
val1.val = taosMemoryMalloc(12);
|
||||
|
||||
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
key++;
|
||||
}
|
||||
{
|
||||
STransCtxVal val1 = { NULL, NULL, (void (*)(const void*))taosMemoryFree};
|
||||
STransCtxVal val1 = {NULL, NULL, (void (*)(const void *))taosMemoryFree};
|
||||
val1.val = taosMemoryMalloc(12);
|
||||
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
key++;
|
||||
|
@ -198,16 +204,18 @@ TEST_F(TransCtxEnv, mergeTest) {
|
|||
STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx));
|
||||
transCtxInit(src);
|
||||
{
|
||||
STransCtxVal val1 = { NULL, NULL, (void (*)(const void*))taosMemoryFree};
|
||||
STransCtxVal val1 = {NULL, NULL, (void (*)(const void *))taosMemoryFree};
|
||||
val1.val = taosMemoryCalloc(1, 11);
|
||||
val1.clone = cloneVal;
|
||||
memcpy(val1.val, val.c_str(), val.size());
|
||||
|
||||
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
key++;
|
||||
}
|
||||
{
|
||||
STransCtxVal val1 = { NULL, NULL, (void (*)(const void*))taosMemoryFree};
|
||||
STransCtxVal val1 = {NULL, NULL, (void (*)(const void *))taosMemoryFree};
|
||||
val1.val = taosMemoryCalloc(1, 11);
|
||||
val1.clone = cloneVal;
|
||||
memcpy(val1.val, val.c_str(), val.size());
|
||||
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
key++;
|
||||
|
|
|
@ -1,36 +1,36 @@
|
|||
#include <assert.h>
|
||||
#include <uv.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <uv.h>
|
||||
|
||||
#include "task.h"
|
||||
|
||||
#define NUM_OF_THREAD 1
|
||||
#define TIMEOUT 10000
|
||||
#define TIMEOUT 10000
|
||||
|
||||
typedef struct SThreadObj {
|
||||
TdThread thread;
|
||||
uv_pipe_t *pipe;
|
||||
uv_loop_t *loop;
|
||||
uv_async_t *workerAsync; //
|
||||
int fd;
|
||||
TdThread thread;
|
||||
uv_pipe_t * pipe;
|
||||
uv_loop_t * loop;
|
||||
uv_async_t *workerAsync; //
|
||||
int fd;
|
||||
} SThreadObj;
|
||||
|
||||
typedef struct SServerObj {
|
||||
uv_tcp_t server;
|
||||
uv_loop_t *loop;
|
||||
int workerIdx;
|
||||
int numOfThread;
|
||||
uv_tcp_t server;
|
||||
uv_loop_t * loop;
|
||||
int workerIdx;
|
||||
int numOfThread;
|
||||
SThreadObj **pThreadObj;
|
||||
uv_pipe_t **pipe;
|
||||
uv_pipe_t ** pipe;
|
||||
} SServerObj;
|
||||
|
||||
typedef struct SConnCtx {
|
||||
uv_tcp_t *pClient;
|
||||
uv_tcp_t * pClient;
|
||||
uv_timer_t *pTimer;
|
||||
uv_async_t *pWorkerAsync;
|
||||
int ref;
|
||||
int ref;
|
||||
} SConnCtx;
|
||||
|
||||
void echo_write(uv_write_t *req, int status) {
|
||||
|
@ -42,7 +42,6 @@ void echo_write(uv_write_t *req, int status) {
|
|||
}
|
||||
|
||||
void echo_read(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf) {
|
||||
|
||||
SConnCtx *pConn = container_of(client, SConnCtx, pClient);
|
||||
pConn->ref += 1;
|
||||
printf("read data %d\n", nread, buf->base, buf->len);
|
||||
|
@ -59,8 +58,7 @@ void echo_read(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf) {
|
|||
}
|
||||
|
||||
if (nread < 0) {
|
||||
if (nread != UV_EOF)
|
||||
fprintf(stderr, "Read error %s\n", uv_err_name(nread));
|
||||
if (nread != UV_EOF) fprintf(stderr, "Read error %s\n", uv_err_name(nread));
|
||||
uv_close((uv_handle_t *)client, NULL);
|
||||
}
|
||||
taosMemoryFree(buf->base);
|
||||
|
@ -83,21 +81,19 @@ void on_new_connection(uv_stream_t *s, int status) {
|
|||
uv_tcp_init(pObj->loop, client);
|
||||
if (uv_accept(s, (uv_stream_t *)client) == 0) {
|
||||
uv_write_t *write_req = (uv_write_t *)taosMemoryMalloc(sizeof(uv_write_t));
|
||||
uv_buf_t dummy_buf = uv_buf_init("a", 1);
|
||||
uv_buf_t dummy_buf = uv_buf_init("a", 1);
|
||||
// despatch to worker thread
|
||||
pObj->workerIdx = (pObj->workerIdx + 1) % pObj->numOfThread;
|
||||
uv_write2(write_req, (uv_stream_t *)&(pObj->pipe[pObj->workerIdx][0]),
|
||||
&dummy_buf, 1, (uv_stream_t *)client, echo_write);
|
||||
uv_write2(write_req, (uv_stream_t *)&(pObj->pipe[pObj->workerIdx][0]), &dummy_buf, 1, (uv_stream_t *)client,
|
||||
echo_write);
|
||||
} else {
|
||||
uv_close((uv_handle_t *)client, NULL);
|
||||
}
|
||||
}
|
||||
void child_on_new_connection(uv_stream_t *q, ssize_t nread,
|
||||
const uv_buf_t *buf) {
|
||||
void child_on_new_connection(uv_stream_t *q, ssize_t nread, const uv_buf_t *buf) {
|
||||
printf("x child_on_new_connection \n");
|
||||
if (nread < 0) {
|
||||
if (nread != UV_EOF)
|
||||
fprintf(stderr, "Read error %s\n", uv_err_name(nread));
|
||||
if (nread != UV_EOF) fprintf(stderr, "Read error %s\n", uv_err_name(nread));
|
||||
uv_close((uv_handle_t *)q, NULL);
|
||||
return;
|
||||
}
|
||||
|
@ -119,7 +115,7 @@ void child_on_new_connection(uv_stream_t *q, ssize_t nread,
|
|||
uv_timer_init(pObj->loop, pConn->pTimer);
|
||||
|
||||
pConn->pClient = (uv_tcp_t *)taosMemoryMalloc(sizeof(uv_tcp_t));
|
||||
pConn->pWorkerAsync = pObj->workerAsync; // thread safty
|
||||
pConn->pWorkerAsync = pObj->workerAsync; // thread safty
|
||||
uv_tcp_init(pObj->loop, pConn->pClient);
|
||||
|
||||
if (uv_accept(q, (uv_stream_t *)(pConn->pClient)) == 0) {
|
||||
|
@ -143,7 +139,7 @@ static void workerAsyncCallback(uv_async_t *handle) {
|
|||
}
|
||||
void *worker_thread(void *arg) {
|
||||
SThreadObj *pObj = (SThreadObj *)arg;
|
||||
int fd = pObj->fd;
|
||||
int fd = pObj->fd;
|
||||
pObj->loop = (uv_loop_t *)taosMemoryMalloc(sizeof(uv_loop_t));
|
||||
uv_loop_init(pObj->loop);
|
||||
|
||||
|
@ -152,19 +148,16 @@ void *worker_thread(void *arg) {
|
|||
|
||||
pObj->workerAsync = taosMemoryMalloc(sizeof(uv_async_t));
|
||||
uv_async_init(pObj->loop, pObj->workerAsync, workerAsyncCallback);
|
||||
uv_read_start((uv_stream_t *)pObj->pipe, alloc_buffer,
|
||||
child_on_new_connection);
|
||||
uv_read_start((uv_stream_t *)pObj->pipe, alloc_buffer, child_on_new_connection);
|
||||
|
||||
uv_run(pObj->loop, UV_RUN_DEFAULT);
|
||||
}
|
||||
int main() {
|
||||
|
||||
SServerObj *server = taosMemoryCalloc(1, sizeof(SServerObj));
|
||||
server->loop = (uv_loop_t *)taosMemoryMalloc(sizeof(uv_loop_t));
|
||||
server->numOfThread = NUM_OF_THREAD;
|
||||
server->workerIdx = 0;
|
||||
server->pThreadObj =
|
||||
(SThreadObj **)taosMemoryCalloc(server->numOfThread, sizeof(SThreadObj *));
|
||||
server->pThreadObj = (SThreadObj **)taosMemoryCalloc(server->numOfThread, sizeof(SThreadObj *));
|
||||
server->pipe = (uv_pipe_t **)taosMemoryCalloc(server->numOfThread, sizeof(uv_pipe_t *));
|
||||
|
||||
uv_loop_init(server->loop);
|
||||
|
@ -173,17 +166,15 @@ int main() {
|
|||
server->pThreadObj[i] = (SThreadObj *)taosMemoryCalloc(1, sizeof(SThreadObj));
|
||||
server->pipe[i] = (uv_pipe_t *)taosMemoryCalloc(2, sizeof(uv_pipe_t));
|
||||
int fds[2];
|
||||
if (uv_socketpair(AF_UNIX, SOCK_STREAM, fds, UV_NONBLOCK_PIPE,
|
||||
UV_NONBLOCK_PIPE) != 0) {
|
||||
if (uv_socketpair(AF_UNIX, SOCK_STREAM, fds, UV_NONBLOCK_PIPE, UV_NONBLOCK_PIPE) != 0) {
|
||||
return -1;
|
||||
}
|
||||
uv_pipe_init(server->loop, &(server->pipe[i][0]), 1);
|
||||
uv_pipe_open(&(server->pipe[i][0]), fds[1]); // init write
|
||||
uv_pipe_open(&(server->pipe[i][0]), fds[1]); // init write
|
||||
|
||||
server->pThreadObj[i]->fd = fds[0];
|
||||
server->pThreadObj[i]->pipe = &(server->pipe[i][1]); // init read
|
||||
int err = taosThreadCreate(&(server->pThreadObj[i]->thread), NULL,
|
||||
worker_thread, (void *)(server->pThreadObj[i]));
|
||||
server->pThreadObj[i]->pipe = &(server->pipe[i][1]); // init read
|
||||
int err = taosThreadCreate(&(server->pThreadObj[i]->thread), NULL, worker_thread, (void *)(server->pThreadObj[i]));
|
||||
if (err == 0) {
|
||||
printf("thread %d create\n", i);
|
||||
} else {
|
||||
|
@ -195,8 +186,7 @@ int main() {
|
|||
uv_ip4_addr("0.0.0.0", 7000, &bind_addr);
|
||||
uv_tcp_bind(&server->server, (const struct sockaddr *)&bind_addr, 0);
|
||||
int err = 0;
|
||||
if ((err = uv_listen((uv_stream_t *)&server->server, 128,
|
||||
on_new_connection)) != 0) {
|
||||
if ((err = uv_listen((uv_stream_t *)&server->server, 128, on_new_connection)) != 0) {
|
||||
fprintf(stderr, "Listen error %s\n", uv_err_name(err));
|
||||
return 2;
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue