[td-13039] add null support.
This commit is contained in:
commit
2144b9f283
|
@ -35,6 +35,7 @@ def abort_previous(){
|
||||||
def pre_test(){
|
def pre_test(){
|
||||||
sh'hostname'
|
sh'hostname'
|
||||||
sh '''
|
sh '''
|
||||||
|
date
|
||||||
sudo rmtaos || echo "taosd has not installed"
|
sudo rmtaos || echo "taosd has not installed"
|
||||||
'''
|
'''
|
||||||
sh '''
|
sh '''
|
||||||
|
@ -60,8 +61,9 @@ def pre_test(){
|
||||||
sh '''
|
sh '''
|
||||||
cd ${WKC}
|
cd ${WKC}
|
||||||
git checkout 3.0
|
git checkout 3.0
|
||||||
|
[ -d contrib/bdb ] && cd contrib/bdb && git clean -fxd && cd ../..
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
sh '''
|
sh '''
|
||||||
cd ${WKC}
|
cd ${WKC}
|
||||||
|
@ -98,7 +100,7 @@ pipeline {
|
||||||
}
|
}
|
||||||
stages {
|
stages {
|
||||||
stage('pre_build'){
|
stage('pre_build'){
|
||||||
agent{label 'slave3_0'}
|
agent{label " slave3_0 || slave15 || slave16 || slave17 "}
|
||||||
options { skipDefaultCheckout() }
|
options { skipDefaultCheckout() }
|
||||||
when {
|
when {
|
||||||
changeRequest()
|
changeRequest()
|
||||||
|
|
|
@ -36,7 +36,14 @@ IF (TD_WINDOWS)
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
ELSE ()
|
ELSE ()
|
||||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -fPIC -gdwarf-2 -msse4.2 -mfma -g3")
|
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -fPIC -gdwarf-2 -g3")
|
||||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -fPIC -gdwarf-2 -msse4.2 -mfma -g3")
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -fPIC -gdwarf-2 -g3")
|
||||||
|
|
||||||
|
MESSAGE("System processor ID: ${CMAKE_SYSTEM_PROCESSOR}")
|
||||||
|
IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64")
|
||||||
|
ADD_DEFINITIONS("-D_TD_ARM_")
|
||||||
|
ELSE ()
|
||||||
|
ADD_DEFINITIONS("-msse4.2 -mfma")
|
||||||
|
ENDIF ()
|
||||||
|
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
|
@ -7,31 +7,53 @@ SET(TD_LINUX FALSE)
|
||||||
SET(TD_WINDOWS FALSE)
|
SET(TD_WINDOWS FALSE)
|
||||||
SET(TD_DARWIN FALSE)
|
SET(TD_DARWIN FALSE)
|
||||||
|
|
||||||
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
MESSAGE("Compiler ID: ${CMAKE_CXX_COMPILER_ID}")
|
||||||
|
if(CMAKE_COMPILER_IS_GNUCXX MATCHES 1)
|
||||||
|
set(CXX_COMPILER_IS_GNU TRUE)
|
||||||
|
else()
|
||||||
|
set(CXX_COMPILER_IS_GNU FALSE)
|
||||||
|
endif()
|
||||||
|
|
||||||
SET(TD_LINUX TRUE)
|
MESSAGE("Current system name is ${CMAKE_SYSTEM_NAME}.")
|
||||||
SET(OSTYPE "Linux")
|
|
||||||
ADD_DEFINITIONS("-DLINUX")
|
|
||||||
|
|
||||||
IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
|
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||||
SET(TD_LINUX_64 TRUE)
|
|
||||||
|
IF (${CXX_COMPILER_IS_GNU})
|
||||||
|
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
|
||||||
ELSE ()
|
ELSE ()
|
||||||
SET(TD_LINUX_32 TRUE)
|
ADD_DEFINITIONS("-Wno-tautological-constant-out-of-range-compare -Wno-pointer-sign -Wno-unknown-warning-option")
|
||||||
|
set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS} -undefined dynamic_lookup")
|
||||||
|
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS} -undefined dynamic_lookup")
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||||
|
|
||||||
SET(TD_DARWIN TRUE)
|
SET(TD_LINUX TRUE)
|
||||||
SET(OSTYPE "macOS")
|
SET(OSTYPE "Linux")
|
||||||
ADD_DEFINITIONS("-DDARWIN")
|
ADD_DEFINITIONS("-DLINUX")
|
||||||
IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64")
|
|
||||||
MESSAGE("Current system arch is arm64")
|
IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
|
||||||
SET(TD_DARWIN_64 TRUE)
|
SET(TD_LINUX_64 TRUE)
|
||||||
ADD_DEFINITIONS("-D_TD_DARWIN_64")
|
ELSE ()
|
||||||
|
SET(TD_LINUX_32 TRUE)
|
||||||
|
ENDIF ()
|
||||||
|
|
||||||
|
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||||
|
|
||||||
|
SET(TD_DARWIN TRUE)
|
||||||
|
SET(OSTYPE "macOS")
|
||||||
|
ADD_DEFINITIONS("-DDARWIN -Wno-tautological-pointer-compare -Wno-return-type")
|
||||||
|
|
||||||
|
MESSAGE("Current system processor is ${CMAKE_SYSTEM_PROCESSOR}.")
|
||||||
|
IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
|
||||||
|
MESSAGE("Current system arch is arm64")
|
||||||
|
SET(TD_DARWIN_64 TRUE)
|
||||||
|
ADD_DEFINITIONS("-D_TD_DARWIN_64")
|
||||||
|
ENDIF ()
|
||||||
|
|
||||||
|
ADD_DEFINITIONS("-DHAVE_UNISTD_H")
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
ADD_DEFINITIONS("-DHAVE_UNISTD_H")
|
|
||||||
|
|
||||||
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||||
|
|
||||||
SET(TD_WINDOWS TRUE)
|
SET(TD_WINDOWS TRUE)
|
||||||
|
@ -45,6 +67,7 @@ ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||||
SET(TD_WINDOWS_32 TRUE)
|
SET(TD_WINDOWS_32 TRUE)
|
||||||
ADD_DEFINITIONS("-D_TD_WINDOWS_32")
|
ADD_DEFINITIONS("-D_TD_WINDOWS_32")
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
MESSAGE("C Compiler ID: ${CMAKE_C_COMPILER_ID}")
|
MESSAGE("C Compiler ID: ${CMAKE_C_COMPILER_ID}")
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "thash.h"
|
#include "thash.h"
|
||||||
#include "tlist.h"
|
#include "tlist.h"
|
||||||
#include "trow.h"
|
#include "trow.h"
|
||||||
|
#include "tuuid.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -171,7 +172,7 @@ typedef struct {
|
||||||
char db[TSDB_DB_FNAME_LEN];
|
char db[TSDB_DB_FNAME_LEN];
|
||||||
int64_t dbId;
|
int64_t dbId;
|
||||||
int32_t vgVersion;
|
int32_t vgVersion;
|
||||||
int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT
|
int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT
|
||||||
} SBuildUseDBInput;
|
} SBuildUseDBInput;
|
||||||
|
|
||||||
typedef struct SField {
|
typedef struct SField {
|
||||||
|
@ -427,10 +428,10 @@ typedef struct {
|
||||||
int16_t slotId;
|
int16_t slotId;
|
||||||
};
|
};
|
||||||
|
|
||||||
int16_t type;
|
int16_t type;
|
||||||
int32_t bytes;
|
int32_t bytes;
|
||||||
uint8_t precision;
|
uint8_t precision;
|
||||||
uint8_t scale;
|
uint8_t scale;
|
||||||
} SColumnInfo;
|
} SColumnInfo;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -526,7 +527,7 @@ typedef struct {
|
||||||
char db[TSDB_DB_FNAME_LEN];
|
char db[TSDB_DB_FNAME_LEN];
|
||||||
int64_t dbId;
|
int64_t dbId;
|
||||||
int32_t vgVersion;
|
int32_t vgVersion;
|
||||||
int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT
|
int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT
|
||||||
} SUseDbReq;
|
} SUseDbReq;
|
||||||
|
|
||||||
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
|
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
|
||||||
|
@ -553,15 +554,13 @@ int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
|
||||||
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
|
int32_t tDeserializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SArray *epSetList; // SArray<SEpSet>
|
SArray* epSetList; // SArray<SEpSet>
|
||||||
} SQnodeListRsp;
|
} SQnodeListRsp;
|
||||||
|
|
||||||
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
|
int32_t tSerializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
|
||||||
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
|
int32_t tDeserializeSQnodeListRsp(void* buf, int32_t bufLen, SQnodeListRsp* pRsp);
|
||||||
void tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
|
void tFreeSQnodeListRsp(SQnodeListRsp* pRsp);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SArray* pArray; // Array of SUseDbRsp
|
SArray* pArray; // Array of SUseDbRsp
|
||||||
} SUseDbBatchRsp;
|
} SUseDbBatchRsp;
|
||||||
|
@ -777,7 +776,6 @@ typedef struct SVgroupInfo {
|
||||||
int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT
|
int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT
|
||||||
} SVgroupInfo;
|
} SVgroupInfo;
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t numOfVgroups;
|
int32_t numOfVgroups;
|
||||||
SVgroupInfo vgroups[];
|
SVgroupInfo vgroups[];
|
||||||
|
@ -1062,8 +1060,8 @@ typedef struct {
|
||||||
} STaskStatus;
|
} STaskStatus;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int64_t refId;
|
int64_t refId;
|
||||||
SArray *taskStatus; //SArray<STaskStatus>
|
SArray* taskStatus; // SArray<STaskStatus>
|
||||||
} SSchedulerStatusRsp;
|
} SSchedulerStatusRsp;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -1072,35 +1070,31 @@ typedef struct {
|
||||||
int8_t action;
|
int8_t action;
|
||||||
} STaskAction;
|
} STaskAction;
|
||||||
|
|
||||||
|
|
||||||
typedef struct SQueryNodeEpId {
|
typedef struct SQueryNodeEpId {
|
||||||
int32_t nodeId; // vgId or qnodeId
|
int32_t nodeId; // vgId or qnodeId
|
||||||
SEp ep;
|
SEp ep;
|
||||||
} SQueryNodeEpId;
|
} SQueryNodeEpId;
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SMsgHead header;
|
SMsgHead header;
|
||||||
uint64_t sId;
|
uint64_t sId;
|
||||||
SQueryNodeEpId epId;
|
SQueryNodeEpId epId;
|
||||||
SArray *taskAction; //SArray<STaskAction>
|
SArray* taskAction; // SArray<STaskAction>
|
||||||
} SSchedulerHbReq;
|
} SSchedulerHbReq;
|
||||||
|
|
||||||
int32_t tSerializeSSchedulerHbReq(void *buf, int32_t bufLen, SSchedulerHbReq *pReq);
|
int32_t tSerializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
|
||||||
int32_t tDeserializeSSchedulerHbReq(void *buf, int32_t bufLen, SSchedulerHbReq *pReq);
|
int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq* pReq);
|
||||||
void tFreeSSchedulerHbReq(SSchedulerHbReq *pReq);
|
void tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint64_t seqId;
|
uint64_t seqId;
|
||||||
SQueryNodeEpId epId;
|
SQueryNodeEpId epId;
|
||||||
SArray *taskStatus; //SArray<STaskStatus>
|
SArray* taskStatus; // SArray<STaskStatus>
|
||||||
} SSchedulerHbRsp;
|
} SSchedulerHbRsp;
|
||||||
|
|
||||||
int32_t tSerializeSSchedulerHbRsp(void *buf, int32_t bufLen, SSchedulerHbRsp *pRsp);
|
int32_t tSerializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
|
||||||
int32_t tDeserializeSSchedulerHbRsp(void *buf, int32_t bufLen, SSchedulerHbRsp *pRsp);
|
int32_t tDeserializeSSchedulerHbRsp(void* buf, int32_t bufLen, SSchedulerHbRsp* pRsp);
|
||||||
void tFreeSSchedulerHbRsp(SSchedulerHbRsp *pRsp);
|
void tFreeSSchedulerHbRsp(SSchedulerHbRsp* pRsp);
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SMsgHead header;
|
SMsgHead header;
|
||||||
|
@ -1157,8 +1151,8 @@ typedef struct {
|
||||||
char name[TSDB_TOPIC_FNAME_LEN];
|
char name[TSDB_TOPIC_FNAME_LEN];
|
||||||
int8_t igExists;
|
int8_t igExists;
|
||||||
char* sql;
|
char* sql;
|
||||||
char* physicalPlan;
|
char* ast;
|
||||||
char* logicalPlan;
|
char subscribeDbName[TSDB_DB_NAME_LEN];
|
||||||
} SCMCreateTopicReq;
|
} SCMCreateTopicReq;
|
||||||
|
|
||||||
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
|
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
|
||||||
|
@ -1370,7 +1364,7 @@ typedef struct SVCreateTbReq {
|
||||||
} SVCreateTbReq, SVUpdateTbReq;
|
} SVCreateTbReq, SVUpdateTbReq;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int tmp; // TODO: to avoid compile error
|
int tmp; // TODO: to avoid compile error
|
||||||
} SVCreateTbRsp, SVUpdateTbRsp;
|
} SVCreateTbRsp, SVUpdateTbRsp;
|
||||||
|
|
||||||
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
|
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
|
||||||
|
@ -1382,7 +1376,7 @@ typedef struct {
|
||||||
} SVCreateTbBatchReq;
|
} SVCreateTbBatchReq;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int tmp; // TODO: to avoid compile error
|
int tmp; // TODO: to avoid compile error
|
||||||
} SVCreateTbBatchRsp;
|
} SVCreateTbBatchRsp;
|
||||||
|
|
||||||
int32_t tSerializeSVCreateTbBatchReq(void** buf, SVCreateTbBatchReq* pReq);
|
int32_t tSerializeSVCreateTbBatchReq(void** buf, SVCreateTbBatchReq* pReq);
|
||||||
|
@ -1396,7 +1390,7 @@ typedef struct {
|
||||||
} SVDropTbReq;
|
} SVDropTbReq;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int tmp; // TODO: to avoid compile error
|
int tmp; // TODO: to avoid compile error
|
||||||
} SVDropTbRsp;
|
} SVDropTbRsp;
|
||||||
|
|
||||||
int32_t tSerializeSVDropTbReq(void** buf, SVDropTbReq* pReq);
|
int32_t tSerializeSVDropTbReq(void** buf, SVDropTbReq* pReq);
|
||||||
|
@ -1896,32 +1890,18 @@ static FORCE_INLINE void* tDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pSW)
|
||||||
}
|
}
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
typedef enum {
|
|
||||||
TD_TIME_UNIT_UNKNOWN = -1,
|
|
||||||
TD_TIME_UNIT_YEAR = 0,
|
|
||||||
TD_TIME_UNIT_SEASON = 1,
|
|
||||||
TD_TIME_UNIT_MONTH = 2,
|
|
||||||
TD_TIME_UNIT_WEEK = 3,
|
|
||||||
TD_TIME_UNIT_DAY = 4,
|
|
||||||
TD_TIME_UNIT_HOUR = 5,
|
|
||||||
TD_TIME_UNIT_MINUTE = 6,
|
|
||||||
TD_TIME_UNIT_SEC = 7,
|
|
||||||
TD_TIME_UNIT_MILLISEC = 8,
|
|
||||||
TD_TIME_UNIT_MICROSEC = 9,
|
|
||||||
TD_TIME_UNIT_NANOSEC = 10
|
|
||||||
} ETDTimeUnit;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int8_t version; // for compatibility(default 0)
|
int8_t version; // for compatibility(default 0)
|
||||||
int8_t intervalUnit;
|
int8_t intervalUnit; // MACRO: TIME_UNIT_XXX
|
||||||
int8_t slidingUnit;
|
int8_t slidingUnit; // MACRO: TIME_UNIT_XXX
|
||||||
char indexName[TSDB_INDEX_NAME_LEN];
|
char indexName[TSDB_INDEX_NAME_LEN];
|
||||||
char timezone[TD_TIMEZONE_LEN]; // sma data is invalid if timezone change.
|
char timezone[TD_TIMEZONE_LEN]; // sma data expired if timezone changes.
|
||||||
uint16_t exprLen;
|
int32_t exprLen;
|
||||||
uint16_t tagsFilterLen;
|
int32_t tagsFilterLen;
|
||||||
int64_t indexUid;
|
int64_t indexUid;
|
||||||
tb_uid_t tableUid; // super/child/common table uid
|
tb_uid_t tableUid; // super/child/common table uid
|
||||||
int64_t interval;
|
int64_t interval;
|
||||||
|
int64_t offset; // use unit by precision of DB
|
||||||
int64_t sliding;
|
int64_t sliding;
|
||||||
char* expr; // sma expression
|
char* expr; // sma expression
|
||||||
char* tagsFilter;
|
char* tagsFilter;
|
||||||
|
@ -1933,7 +1913,7 @@ typedef struct {
|
||||||
} SVCreateTSmaReq;
|
} SVCreateTSmaReq;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int8_t type; // 0 status report, 1 update data
|
int8_t type; // 0 status report, 1 update data
|
||||||
char indexName[TSDB_INDEX_NAME_LEN]; //
|
char indexName[TSDB_INDEX_NAME_LEN]; //
|
||||||
STimeWindow windows;
|
STimeWindow windows;
|
||||||
} STSmaMsg;
|
} STSmaMsg;
|
||||||
|
@ -1944,7 +1924,7 @@ typedef struct {
|
||||||
} SVDropTSmaReq;
|
} SVDropTSmaReq;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int tmp; // TODO: to avoid compile error
|
int tmp; // TODO: to avoid compile error
|
||||||
} SVCreateTSmaRsp, SVDropTSmaRsp;
|
} SVCreateTSmaRsp, SVDropTSmaRsp;
|
||||||
|
|
||||||
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
|
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
|
||||||
|
@ -1966,7 +1946,7 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int64_t indexUid;
|
int64_t indexUid;
|
||||||
TSKEY skey; // startTS of one interval/sliding
|
TSKEY skey; // startKey of one interval/sliding window
|
||||||
int64_t interval;
|
int64_t interval;
|
||||||
int32_t dataLen; // not including head
|
int32_t dataLen; // not including head
|
||||||
int8_t intervalUnit;
|
int8_t intervalUnit;
|
||||||
|
@ -2023,13 +2003,14 @@ static FORCE_INLINE int32_t tEncodeTSma(void** buf, const STSma* pSma) {
|
||||||
tlen += taosEncodeFixedI8(buf, pSma->slidingUnit);
|
tlen += taosEncodeFixedI8(buf, pSma->slidingUnit);
|
||||||
tlen += taosEncodeString(buf, pSma->indexName);
|
tlen += taosEncodeString(buf, pSma->indexName);
|
||||||
tlen += taosEncodeString(buf, pSma->timezone);
|
tlen += taosEncodeString(buf, pSma->timezone);
|
||||||
tlen += taosEncodeFixedU16(buf, pSma->exprLen);
|
tlen += taosEncodeFixedI32(buf, pSma->exprLen);
|
||||||
tlen += taosEncodeFixedU16(buf, pSma->tagsFilterLen);
|
tlen += taosEncodeFixedI32(buf, pSma->tagsFilterLen);
|
||||||
tlen += taosEncodeFixedI64(buf, pSma->indexUid);
|
tlen += taosEncodeFixedI64(buf, pSma->indexUid);
|
||||||
tlen += taosEncodeFixedI64(buf, pSma->tableUid);
|
tlen += taosEncodeFixedI64(buf, pSma->tableUid);
|
||||||
tlen += taosEncodeFixedI64(buf, pSma->interval);
|
tlen += taosEncodeFixedI64(buf, pSma->interval);
|
||||||
|
tlen += taosEncodeFixedI64(buf, pSma->offset);
|
||||||
tlen += taosEncodeFixedI64(buf, pSma->sliding);
|
tlen += taosEncodeFixedI64(buf, pSma->sliding);
|
||||||
|
|
||||||
if (pSma->exprLen > 0) {
|
if (pSma->exprLen > 0) {
|
||||||
tlen += taosEncodeString(buf, pSma->expr);
|
tlen += taosEncodeString(buf, pSma->expr);
|
||||||
}
|
}
|
||||||
|
@ -2057,14 +2038,14 @@ static FORCE_INLINE void* tDecodeTSma(void* buf, STSma* pSma) {
|
||||||
buf = taosDecodeFixedI8(buf, &pSma->slidingUnit);
|
buf = taosDecodeFixedI8(buf, &pSma->slidingUnit);
|
||||||
buf = taosDecodeStringTo(buf, pSma->indexName);
|
buf = taosDecodeStringTo(buf, pSma->indexName);
|
||||||
buf = taosDecodeStringTo(buf, pSma->timezone);
|
buf = taosDecodeStringTo(buf, pSma->timezone);
|
||||||
buf = taosDecodeFixedU16(buf, &pSma->exprLen);
|
buf = taosDecodeFixedI32(buf, &pSma->exprLen);
|
||||||
buf = taosDecodeFixedU16(buf, &pSma->tagsFilterLen);
|
buf = taosDecodeFixedI32(buf, &pSma->tagsFilterLen);
|
||||||
buf = taosDecodeFixedI64(buf, &pSma->indexUid);
|
buf = taosDecodeFixedI64(buf, &pSma->indexUid);
|
||||||
buf = taosDecodeFixedI64(buf, &pSma->tableUid);
|
buf = taosDecodeFixedI64(buf, &pSma->tableUid);
|
||||||
buf = taosDecodeFixedI64(buf, &pSma->interval);
|
buf = taosDecodeFixedI64(buf, &pSma->interval);
|
||||||
|
buf = taosDecodeFixedI64(buf, &pSma->offset);
|
||||||
buf = taosDecodeFixedI64(buf, &pSma->sliding);
|
buf = taosDecodeFixedI64(buf, &pSma->sliding);
|
||||||
|
|
||||||
|
|
||||||
if (pSma->exprLen > 0) {
|
if (pSma->exprLen > 0) {
|
||||||
pSma->expr = (char*)calloc(pSma->exprLen, 1);
|
pSma->expr = (char*)calloc(pSma->exprLen, 1);
|
||||||
if (pSma->expr != NULL) {
|
if (pSma->expr != NULL) {
|
||||||
|
@ -2265,6 +2246,55 @@ static FORCE_INLINE void* tDecodeSMqCMGetSubEpRsp(void* buf, SMqCMGetSubEpRsp* p
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum {
|
||||||
|
STREAM_TASK_STATUS__RUNNING = 1,
|
||||||
|
STREAM_TASK_STATUS__STOP,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int64_t streamId;
|
||||||
|
int32_t taskId;
|
||||||
|
int32_t level;
|
||||||
|
int8_t status;
|
||||||
|
char* qmsg;
|
||||||
|
void* executor;
|
||||||
|
// void* stateStore;
|
||||||
|
// storage handle
|
||||||
|
} SStreamTask;
|
||||||
|
|
||||||
|
static FORCE_INLINE SStreamTask* streamTaskNew(int64_t streamId, int32_t level) {
|
||||||
|
SStreamTask* pTask = (SStreamTask*)calloc(1, sizeof(SStreamTask));
|
||||||
|
if (pTask == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
pTask->taskId = tGenIdPI32();
|
||||||
|
pTask->status = STREAM_TASK_STATUS__RUNNING;
|
||||||
|
pTask->qmsg = NULL;
|
||||||
|
return pTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tEncodeSStreamTask(SCoder* pEncoder, const SStreamTask* pTask);
|
||||||
|
int32_t tDecodeSStreamTask(SCoder* pDecoder, SStreamTask* pTask);
|
||||||
|
void tFreeSStreamTask(SStreamTask* pTask);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
SMsgHead head;
|
||||||
|
SStreamTask* task;
|
||||||
|
} SStreamTaskDeployReq;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int32_t reserved;
|
||||||
|
} SStreamTaskDeployRsp;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
SMsgHead head;
|
||||||
|
// TODO: other info needed by task
|
||||||
|
} SStreamTaskExecReq;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int32_t reserved;
|
||||||
|
} SStreamTaskExecRsp;
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -199,6 +199,8 @@ enum {
|
||||||
|
|
||||||
// Requests handled by SNODE
|
// Requests handled by SNODE
|
||||||
TD_NEW_MSG_SEG(TDMT_SND_MSG)
|
TD_NEW_MSG_SEG(TDMT_SND_MSG)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_SND_TASK_DEPLOY, "snode-task-deploy", SStreamTaskDeployReq, SStreamTaskDeployRsp)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_SND_TASK_EXEC, "snode-task-exec", SStreamTaskExecReq, SStreamTaskExecRsp)
|
||||||
|
|
||||||
#if defined(TD_MSG_NUMBER_)
|
#if defined(TD_MSG_NUMBER_)
|
||||||
TDMT_MAX
|
TDMT_MAX
|
||||||
|
|
|
@ -98,13 +98,13 @@ typedef void *SRow;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
TDRowValT valType;
|
TDRowValT valType;
|
||||||
void *val;
|
void * val;
|
||||||
} SCellVal;
|
} SCellVal;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
// TODO
|
// TODO
|
||||||
int tmp; // TODO: to avoid compile error
|
int tmp; // TODO: to avoid compile error
|
||||||
} STpRow; // tuple
|
} STpRow; // tuple
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -158,8 +158,8 @@ typedef struct {
|
||||||
int16_t nBitmaps;
|
int16_t nBitmaps;
|
||||||
int16_t nBoundBitmaps;
|
int16_t nBoundBitmaps;
|
||||||
int32_t offset;
|
int32_t offset;
|
||||||
void *pBitmap;
|
void * pBitmap;
|
||||||
void *pOffset;
|
void * pOffset;
|
||||||
int32_t extendedRowSize;
|
int32_t extendedRowSize;
|
||||||
} SRowBuilder;
|
} SRowBuilder;
|
||||||
|
|
||||||
|
@ -273,7 +273,7 @@ static FORCE_INLINE int32_t tdSetBitmapValType(void *pBitmap, int16_t colIdx, TD
|
||||||
}
|
}
|
||||||
int16_t nBytes = colIdx / TD_VTYPE_PARTS;
|
int16_t nBytes = colIdx / TD_VTYPE_PARTS;
|
||||||
int16_t nOffset = colIdx & TD_VTYPE_OPTR;
|
int16_t nOffset = colIdx & TD_VTYPE_OPTR;
|
||||||
char *pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes);
|
char * pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes);
|
||||||
switch (nOffset) {
|
switch (nOffset) {
|
||||||
case 0:
|
case 0:
|
||||||
*pDestByte = ((*pDestByte) & 0x3F) | (valType << 6);
|
*pDestByte = ((*pDestByte) & 0x3F) | (valType << 6);
|
||||||
|
@ -311,7 +311,7 @@ static FORCE_INLINE int32_t tdGetBitmapValType(void *pBitmap, int16_t colIdx, TD
|
||||||
}
|
}
|
||||||
int16_t nBytes = colIdx / TD_VTYPE_PARTS;
|
int16_t nBytes = colIdx / TD_VTYPE_PARTS;
|
||||||
int16_t nOffset = colIdx & TD_VTYPE_OPTR;
|
int16_t nOffset = colIdx & TD_VTYPE_OPTR;
|
||||||
char *pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes);
|
char * pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes);
|
||||||
switch (nOffset) {
|
switch (nOffset) {
|
||||||
case 0:
|
case 0:
|
||||||
*pValType = (((*pDestByte) & 0xC0) >> 6);
|
*pValType = (((*pDestByte) & 0xC0) >> 6);
|
||||||
|
@ -617,7 +617,7 @@ static FORCE_INLINE int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowVa
|
||||||
if (tdValIsNorm(valType, val, colType)) {
|
if (tdValIsNorm(valType, val, colType)) {
|
||||||
// ts key stored in STSRow.ts
|
// ts key stored in STSRow.ts
|
||||||
SKvRowIdx *pColIdx = (SKvRowIdx *)POINTER_SHIFT(TD_ROW_COL_IDX(row), offset);
|
SKvRowIdx *pColIdx = (SKvRowIdx *)POINTER_SHIFT(TD_ROW_COL_IDX(row), offset);
|
||||||
char *ptr = (char *)POINTER_SHIFT(row, TD_ROW_LEN(row));
|
char * ptr = (char *)POINTER_SHIFT(row, TD_ROW_LEN(row));
|
||||||
pColIdx->colId = colId;
|
pColIdx->colId = colId;
|
||||||
pColIdx->offset = TD_ROW_LEN(row); // the offset include the TD_ROW_HEAD_LEN
|
pColIdx->offset = TD_ROW_LEN(row); // the offset include the TD_ROW_HEAD_LEN
|
||||||
|
|
||||||
|
@ -635,7 +635,7 @@ static FORCE_INLINE int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowVa
|
||||||
// NULL/None value
|
// NULL/None value
|
||||||
else {
|
else {
|
||||||
SKvRowIdx *pColIdx = (SKvRowIdx *)POINTER_SHIFT(TD_ROW_COL_IDX(row), offset);
|
SKvRowIdx *pColIdx = (SKvRowIdx *)POINTER_SHIFT(TD_ROW_COL_IDX(row), offset);
|
||||||
char *ptr = (char *)POINTER_SHIFT(row, TD_ROW_LEN(row));
|
char * ptr = (char *)POINTER_SHIFT(row, TD_ROW_LEN(row));
|
||||||
pColIdx->colId = colId;
|
pColIdx->colId = colId;
|
||||||
pColIdx->offset = TD_ROW_LEN(row); // the offset include the TD_ROW_HEAD_LEN
|
pColIdx->offset = TD_ROW_LEN(row); // the offset include the TD_ROW_HEAD_LEN
|
||||||
const void *nullVal = getNullValue(colType);
|
const void *nullVal = getNullValue(colType);
|
||||||
|
@ -697,9 +697,9 @@ static FORCE_INLINE int32_t tdAppendColValToRow(SRowBuilder *pBuilder, int16_t c
|
||||||
}
|
}
|
||||||
// TODO: We can avoid the type judegement by FP, but would prevent the inline scheme.
|
// TODO: We can avoid the type judegement by FP, but would prevent the inline scheme.
|
||||||
if (TD_IS_TP_ROW(pRow)) {
|
if (TD_IS_TP_ROW(pRow)) {
|
||||||
tdAppendColValToTpRow(pBuilder, valType, val, true, colType, colIdx, offset);
|
tdAppendColValToTpRow(pBuilder, valType, val, isCopyVarData, colType, colIdx, offset);
|
||||||
} else {
|
} else {
|
||||||
tdAppendColValToKvRow(pBuilder, valType, val, true, colType, colIdx, offset, colId);
|
tdAppendColValToKvRow(pBuilder, valType, val, isCopyVarData, colType, colIdx, offset, colId);
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -771,8 +771,8 @@ static FORCE_INLINE int32_t tdGetKvRowValOfCol(SCellVal *output, STSRow *pRow, v
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
STSchema *pSchema;
|
STSchema *pSchema;
|
||||||
STSRow *pRow;
|
STSRow * pRow;
|
||||||
void *pBitmap;
|
void * pBitmap;
|
||||||
uint32_t offset;
|
uint32_t offset;
|
||||||
col_id_t maxColId;
|
col_id_t maxColId;
|
||||||
col_id_t colIdx; // [PRIMARYKEY_TIMESTAMP_COL_ID, nSchemaCols], PRIMARYKEY_TIMESTAMP_COL_ID equals 1
|
col_id_t colIdx; // [PRIMARYKEY_TIMESTAMP_COL_ID, nSchemaCols], PRIMARYKEY_TIMESTAMP_COL_ID equals 1
|
||||||
|
@ -877,7 +877,7 @@ static FORCE_INLINE bool tdGetTpRowDataOfCol(STSRowIter *pIter, col_type_t colTy
|
||||||
// internal
|
// internal
|
||||||
static FORCE_INLINE bool tdGetKvRowValOfColEx(STSRowIter *pIter, col_id_t colId, col_type_t colType, col_id_t *nIdx,
|
static FORCE_INLINE bool tdGetKvRowValOfColEx(STSRowIter *pIter, col_id_t colId, col_type_t colType, col_id_t *nIdx,
|
||||||
SCellVal *pVal) {
|
SCellVal *pVal) {
|
||||||
STSRow *pRow = pIter->pRow;
|
STSRow * pRow = pIter->pRow;
|
||||||
SKvRowIdx *pKvIdx = NULL;
|
SKvRowIdx *pKvIdx = NULL;
|
||||||
bool colFound = false;
|
bool colFound = false;
|
||||||
col_id_t kvNCols = tdRowGetNCols(pRow);
|
col_id_t kvNCols = tdRowGetNCols(pRow);
|
||||||
|
@ -1068,7 +1068,7 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
STSchema *pSchema;
|
STSchema *pSchema;
|
||||||
STSRow *pRow;
|
STSRow * pRow;
|
||||||
} STSRowReader;
|
} STSRowReader;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
@ -25,6 +25,17 @@ extern "C" {
|
||||||
|
|
||||||
#define TIME_IS_VAR_DURATION(_t) ((_t) == 'n' || (_t) == 'y' || (_t) == 'N' || (_t) == 'Y')
|
#define TIME_IS_VAR_DURATION(_t) ((_t) == 'n' || (_t) == 'y' || (_t) == 'N' || (_t) == 'Y')
|
||||||
|
|
||||||
|
#define TIME_UNIT_NANOSECOND 'b'
|
||||||
|
#define TIME_UNIT_MICROSECOND 'u'
|
||||||
|
#define TIME_UNIT_MILLISECOND 'a'
|
||||||
|
#define TIME_UNIT_SECOND 's'
|
||||||
|
#define TIME_UNIT_MINUTE 'm'
|
||||||
|
#define TIME_UNIT_HOUR 'h'
|
||||||
|
#define TIME_UNIT_DAY 'd'
|
||||||
|
#define TIME_UNIT_WEEK 'w'
|
||||||
|
#define TIME_UNIT_MONTH 'n'
|
||||||
|
#define TIME_UNIT_YEAR 'y'
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @return timestamp decided by global conf variable, tsTimePrecision
|
* @return timestamp decided by global conf variable, tsTimePrecision
|
||||||
* if precision == TSDB_TIME_PRECISION_MICRO, it returns timestamp in microsecond.
|
* if precision == TSDB_TIME_PRECISION_MICRO, it returns timestamp in microsecond.
|
||||||
|
|
|
@ -48,108 +48,114 @@
|
||||||
#define TK_DNODES 30
|
#define TK_DNODES 30
|
||||||
#define TK_NK_ID 31
|
#define TK_NK_ID 31
|
||||||
#define TK_NK_IPTOKEN 32
|
#define TK_NK_IPTOKEN 32
|
||||||
#define TK_DATABASE 33
|
#define TK_QNODE 33
|
||||||
#define TK_DATABASES 34
|
#define TK_ON 34
|
||||||
#define TK_USE 35
|
#define TK_QNODES 35
|
||||||
#define TK_IF 36
|
#define TK_DATABASE 36
|
||||||
#define TK_NOT 37
|
#define TK_DATABASES 37
|
||||||
#define TK_EXISTS 38
|
#define TK_USE 38
|
||||||
#define TK_BLOCKS 39
|
#define TK_IF 39
|
||||||
#define TK_CACHE 40
|
#define TK_NOT 40
|
||||||
#define TK_CACHELAST 41
|
#define TK_EXISTS 41
|
||||||
#define TK_COMP 42
|
#define TK_BLOCKS 42
|
||||||
#define TK_DAYS 43
|
#define TK_CACHE 43
|
||||||
#define TK_FSYNC 44
|
#define TK_CACHELAST 44
|
||||||
#define TK_MAXROWS 45
|
#define TK_COMP 45
|
||||||
#define TK_MINROWS 46
|
#define TK_DAYS 46
|
||||||
#define TK_KEEP 47
|
#define TK_FSYNC 47
|
||||||
#define TK_PRECISION 48
|
#define TK_MAXROWS 48
|
||||||
#define TK_QUORUM 49
|
#define TK_MINROWS 49
|
||||||
#define TK_REPLICA 50
|
#define TK_KEEP 50
|
||||||
#define TK_TTL 51
|
#define TK_PRECISION 51
|
||||||
#define TK_WAL 52
|
#define TK_QUORUM 52
|
||||||
#define TK_VGROUPS 53
|
#define TK_REPLICA 53
|
||||||
#define TK_SINGLE_STABLE 54
|
#define TK_TTL 54
|
||||||
#define TK_STREAM_MODE 55
|
#define TK_WAL 55
|
||||||
#define TK_TABLE 56
|
#define TK_VGROUPS 56
|
||||||
#define TK_NK_LP 57
|
#define TK_SINGLE_STABLE 57
|
||||||
#define TK_NK_RP 58
|
#define TK_STREAM_MODE 58
|
||||||
#define TK_STABLE 59
|
#define TK_TABLE 59
|
||||||
#define TK_TABLES 60
|
#define TK_NK_LP 60
|
||||||
#define TK_STABLES 61
|
#define TK_NK_RP 61
|
||||||
#define TK_USING 62
|
#define TK_STABLE 62
|
||||||
#define TK_TAGS 63
|
#define TK_TABLES 63
|
||||||
#define TK_NK_DOT 64
|
#define TK_STABLES 64
|
||||||
#define TK_NK_COMMA 65
|
#define TK_USING 65
|
||||||
#define TK_COMMENT 66
|
#define TK_TAGS 66
|
||||||
#define TK_BOOL 67
|
#define TK_NK_DOT 67
|
||||||
#define TK_TINYINT 68
|
#define TK_NK_COMMA 68
|
||||||
#define TK_SMALLINT 69
|
#define TK_COMMENT 69
|
||||||
#define TK_INT 70
|
#define TK_BOOL 70
|
||||||
#define TK_INTEGER 71
|
#define TK_TINYINT 71
|
||||||
#define TK_BIGINT 72
|
#define TK_SMALLINT 72
|
||||||
#define TK_FLOAT 73
|
#define TK_INT 73
|
||||||
#define TK_DOUBLE 74
|
#define TK_INTEGER 74
|
||||||
#define TK_BINARY 75
|
#define TK_BIGINT 75
|
||||||
#define TK_TIMESTAMP 76
|
#define TK_FLOAT 76
|
||||||
#define TK_NCHAR 77
|
#define TK_DOUBLE 77
|
||||||
#define TK_UNSIGNED 78
|
#define TK_BINARY 78
|
||||||
#define TK_JSON 79
|
#define TK_TIMESTAMP 79
|
||||||
#define TK_VARCHAR 80
|
#define TK_NCHAR 80
|
||||||
#define TK_MEDIUMBLOB 81
|
#define TK_UNSIGNED 81
|
||||||
#define TK_BLOB 82
|
#define TK_JSON 82
|
||||||
#define TK_VARBINARY 83
|
#define TK_VARCHAR 83
|
||||||
#define TK_DECIMAL 84
|
#define TK_MEDIUMBLOB 84
|
||||||
#define TK_SMA 85
|
#define TK_BLOB 85
|
||||||
#define TK_MNODES 86
|
#define TK_VARBINARY 86
|
||||||
#define TK_NK_FLOAT 87
|
#define TK_DECIMAL 87
|
||||||
#define TK_NK_BOOL 88
|
#define TK_SMA 88
|
||||||
#define TK_NK_VARIABLE 89
|
#define TK_INDEX 89
|
||||||
#define TK_BETWEEN 90
|
#define TK_FULLTEXT 90
|
||||||
#define TK_IS 91
|
#define TK_FUNCTION 91
|
||||||
#define TK_NULL 92
|
#define TK_INTERVAL 92
|
||||||
#define TK_NK_LT 93
|
#define TK_TOPIC 93
|
||||||
#define TK_NK_GT 94
|
#define TK_AS 94
|
||||||
#define TK_NK_LE 95
|
#define TK_MNODES 95
|
||||||
#define TK_NK_GE 96
|
#define TK_NK_FLOAT 96
|
||||||
#define TK_NK_NE 97
|
#define TK_NK_BOOL 97
|
||||||
#define TK_NK_EQ 98
|
#define TK_NK_VARIABLE 98
|
||||||
#define TK_LIKE 99
|
#define TK_BETWEEN 99
|
||||||
#define TK_MATCH 100
|
#define TK_IS 100
|
||||||
#define TK_NMATCH 101
|
#define TK_NULL 101
|
||||||
#define TK_IN 102
|
#define TK_NK_LT 102
|
||||||
#define TK_FROM 103
|
#define TK_NK_GT 103
|
||||||
#define TK_AS 104
|
#define TK_NK_LE 104
|
||||||
#define TK_JOIN 105
|
#define TK_NK_GE 105
|
||||||
#define TK_ON 106
|
#define TK_NK_NE 106
|
||||||
#define TK_INNER 107
|
#define TK_NK_EQ 107
|
||||||
#define TK_SELECT 108
|
#define TK_LIKE 108
|
||||||
#define TK_DISTINCT 109
|
#define TK_MATCH 109
|
||||||
#define TK_WHERE 110
|
#define TK_NMATCH 110
|
||||||
#define TK_PARTITION 111
|
#define TK_IN 111
|
||||||
#define TK_BY 112
|
#define TK_FROM 112
|
||||||
#define TK_SESSION 113
|
#define TK_JOIN 113
|
||||||
#define TK_STATE_WINDOW 114
|
#define TK_INNER 114
|
||||||
#define TK_INTERVAL 115
|
#define TK_SELECT 115
|
||||||
#define TK_SLIDING 116
|
#define TK_DISTINCT 116
|
||||||
#define TK_FILL 117
|
#define TK_WHERE 117
|
||||||
#define TK_VALUE 118
|
#define TK_PARTITION 118
|
||||||
#define TK_NONE 119
|
#define TK_BY 119
|
||||||
#define TK_PREV 120
|
#define TK_SESSION 120
|
||||||
#define TK_LINEAR 121
|
#define TK_STATE_WINDOW 121
|
||||||
#define TK_NEXT 122
|
#define TK_SLIDING 122
|
||||||
#define TK_GROUP 123
|
#define TK_FILL 123
|
||||||
#define TK_HAVING 124
|
#define TK_VALUE 124
|
||||||
#define TK_ORDER 125
|
#define TK_NONE 125
|
||||||
#define TK_SLIMIT 126
|
#define TK_PREV 126
|
||||||
#define TK_SOFFSET 127
|
#define TK_LINEAR 127
|
||||||
#define TK_LIMIT 128
|
#define TK_NEXT 128
|
||||||
#define TK_OFFSET 129
|
#define TK_GROUP 129
|
||||||
#define TK_ASC 130
|
#define TK_HAVING 130
|
||||||
#define TK_DESC 131
|
#define TK_ORDER 131
|
||||||
#define TK_NULLS 132
|
#define TK_SLIMIT 132
|
||||||
#define TK_FIRST 133
|
#define TK_SOFFSET 133
|
||||||
#define TK_LAST 134
|
#define TK_LIMIT 134
|
||||||
|
#define TK_OFFSET 135
|
||||||
|
#define TK_ASC 136
|
||||||
|
#define TK_DESC 137
|
||||||
|
#define TK_NULLS 138
|
||||||
|
#define TK_FIRST 139
|
||||||
|
#define TK_LAST 140
|
||||||
|
|
||||||
#define TK_NK_SPACE 300
|
#define TK_NK_SPACE 300
|
||||||
#define TK_NK_COMMENT 301
|
#define TK_NK_COMMENT 301
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#ifndef _TD_SNODE_H_
|
#ifndef _TD_SNODE_H_
|
||||||
#define _TD_SNODE_H_
|
#define _TD_SNODE_H_
|
||||||
|
|
||||||
|
#include "tcommon.h"
|
||||||
#include "tmsg.h"
|
#include "tmsg.h"
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
|
|
||||||
|
@ -23,9 +24,6 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SND_UNIQUE_THREAD_NUM 2
|
|
||||||
#define SND_SHARED_THREAD_NUM 2
|
|
||||||
|
|
||||||
/* ------------------------ TYPES EXPOSED ------------------------ */
|
/* ------------------------ TYPES EXPOSED ------------------------ */
|
||||||
typedef struct SDnode SDnode;
|
typedef struct SDnode SDnode;
|
||||||
typedef struct SSnode SSnode;
|
typedef struct SSnode SSnode;
|
||||||
|
@ -81,7 +79,7 @@ int32_t sndGetLoad(SSnode *pSnode, SSnodeLoad *pLoad);
|
||||||
* @param pRsp The response message
|
* @param pRsp The response message
|
||||||
* @return int32_t 0 for success, -1 for failure
|
* @return int32_t 0 for success, -1 for failure
|
||||||
*/
|
*/
|
||||||
int32_t sndProcessMsg(SSnode *pSnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
// int32_t sndProcessMsg(SSnode *pSnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
||||||
|
|
||||||
int32_t sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg);
|
int32_t sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg);
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ extern "C" {
|
||||||
#include "querynodes.h"
|
#include "querynodes.h"
|
||||||
|
|
||||||
typedef struct SDatabaseOptions {
|
typedef struct SDatabaseOptions {
|
||||||
|
ENodeType type;
|
||||||
int32_t numOfBlocks;
|
int32_t numOfBlocks;
|
||||||
int32_t cacheBlockSize;
|
int32_t cacheBlockSize;
|
||||||
int8_t cachelast;
|
int8_t cachelast;
|
||||||
|
@ -46,7 +47,7 @@ typedef struct SCreateDatabaseStmt {
|
||||||
ENodeType type;
|
ENodeType type;
|
||||||
char dbName[TSDB_DB_NAME_LEN];
|
char dbName[TSDB_DB_NAME_LEN];
|
||||||
bool ignoreExists;
|
bool ignoreExists;
|
||||||
SDatabaseOptions options;
|
SDatabaseOptions* pOptions;
|
||||||
} SCreateDatabaseStmt;
|
} SCreateDatabaseStmt;
|
||||||
|
|
||||||
typedef struct SUseDatabaseStmt {
|
typedef struct SUseDatabaseStmt {
|
||||||
|
@ -60,7 +61,14 @@ typedef struct SDropDatabaseStmt {
|
||||||
bool ignoreNotExists;
|
bool ignoreNotExists;
|
||||||
} SDropDatabaseStmt;
|
} SDropDatabaseStmt;
|
||||||
|
|
||||||
|
typedef struct SAlterDatabaseStmt {
|
||||||
|
ENodeType type;
|
||||||
|
char dbName[TSDB_DB_NAME_LEN];
|
||||||
|
SDatabaseOptions* pOptions;
|
||||||
|
} SAlterDatabaseStmt;
|
||||||
|
|
||||||
typedef struct STableOptions {
|
typedef struct STableOptions {
|
||||||
|
ENodeType type;
|
||||||
int32_t keep;
|
int32_t keep;
|
||||||
int32_t ttl;
|
int32_t ttl;
|
||||||
char comments[TSDB_STB_COMMENT_LEN];
|
char comments[TSDB_STB_COMMENT_LEN];
|
||||||
|
@ -81,7 +89,7 @@ typedef struct SCreateTableStmt {
|
||||||
bool ignoreExists;
|
bool ignoreExists;
|
||||||
SNodeList* pCols;
|
SNodeList* pCols;
|
||||||
SNodeList* pTags;
|
SNodeList* pTags;
|
||||||
STableOptions options;
|
STableOptions* pOptions;
|
||||||
} SCreateTableStmt;
|
} SCreateTableStmt;
|
||||||
|
|
||||||
typedef struct SCreateSubTableClause {
|
typedef struct SCreateSubTableClause {
|
||||||
|
@ -155,6 +163,58 @@ typedef struct SShowStmt {
|
||||||
char dbName[TSDB_DB_NAME_LEN];
|
char dbName[TSDB_DB_NAME_LEN];
|
||||||
} SShowStmt;
|
} SShowStmt;
|
||||||
|
|
||||||
|
typedef enum EIndexType {
|
||||||
|
INDEX_TYPE_SMA = 1,
|
||||||
|
INDEX_TYPE_FULLTEXT
|
||||||
|
} EIndexType;
|
||||||
|
|
||||||
|
typedef struct SIndexOptions {
|
||||||
|
ENodeType type;
|
||||||
|
SNodeList* pFuncs;
|
||||||
|
SNode* pInterval;
|
||||||
|
SNode* pOffset;
|
||||||
|
SNode* pSliding;
|
||||||
|
} SIndexOptions;
|
||||||
|
|
||||||
|
typedef struct SCreateIndexStmt {
|
||||||
|
ENodeType type;
|
||||||
|
EIndexType indexType;
|
||||||
|
char indexName[TSDB_INDEX_NAME_LEN];
|
||||||
|
char tableName[TSDB_TABLE_NAME_LEN];
|
||||||
|
SNodeList* pCols;
|
||||||
|
SIndexOptions* pOptions;
|
||||||
|
} SCreateIndexStmt;
|
||||||
|
|
||||||
|
typedef struct SDropIndexStmt {
|
||||||
|
ENodeType type;
|
||||||
|
char indexName[TSDB_INDEX_NAME_LEN];
|
||||||
|
char tableName[TSDB_TABLE_NAME_LEN];
|
||||||
|
} SDropIndexStmt;
|
||||||
|
|
||||||
|
typedef struct SCreateQnodeStmt {
|
||||||
|
ENodeType type;
|
||||||
|
int32_t dnodeId;
|
||||||
|
} SCreateQnodeStmt;
|
||||||
|
|
||||||
|
typedef struct SDropQnodeStmt {
|
||||||
|
ENodeType type;
|
||||||
|
int32_t dnodeId;
|
||||||
|
} SDropQnodeStmt;
|
||||||
|
|
||||||
|
typedef struct SCreateTopicStmt {
|
||||||
|
ENodeType type;
|
||||||
|
char topicName[TSDB_TABLE_NAME_LEN];
|
||||||
|
char subscribeDbName[TSDB_DB_NAME_LEN];
|
||||||
|
bool ignoreExists;
|
||||||
|
SNode* pQuery;
|
||||||
|
} SCreateTopicStmt;
|
||||||
|
|
||||||
|
typedef struct SDropTopicStmt {
|
||||||
|
ENodeType type;
|
||||||
|
char topicName[TSDB_TABLE_NAME_LEN];
|
||||||
|
bool ignoreNotExists;
|
||||||
|
} SDropTopicStmt;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -67,6 +67,9 @@ typedef enum ENodeType {
|
||||||
QUERY_NODE_SLOT_DESC,
|
QUERY_NODE_SLOT_DESC,
|
||||||
QUERY_NODE_COLUMN_DEF,
|
QUERY_NODE_COLUMN_DEF,
|
||||||
QUERY_NODE_DOWNSTREAM_SOURCE,
|
QUERY_NODE_DOWNSTREAM_SOURCE,
|
||||||
|
QUERY_NODE_DATABASE_OPTIONS,
|
||||||
|
QUERY_NODE_TABLE_OPTIONS,
|
||||||
|
QUERY_NODE_INDEX_OPTIONS,
|
||||||
|
|
||||||
// Statement nodes are used in parser and planner module.
|
// Statement nodes are used in parser and planner module.
|
||||||
QUERY_NODE_SET_OPERATOR,
|
QUERY_NODE_SET_OPERATOR,
|
||||||
|
@ -74,6 +77,7 @@ typedef enum ENodeType {
|
||||||
QUERY_NODE_VNODE_MODIF_STMT,
|
QUERY_NODE_VNODE_MODIF_STMT,
|
||||||
QUERY_NODE_CREATE_DATABASE_STMT,
|
QUERY_NODE_CREATE_DATABASE_STMT,
|
||||||
QUERY_NODE_DROP_DATABASE_STMT,
|
QUERY_NODE_DROP_DATABASE_STMT,
|
||||||
|
QUERY_NODE_ALTER_DATABASE_STMT,
|
||||||
QUERY_NODE_SHOW_DATABASES_STMT, // temp
|
QUERY_NODE_SHOW_DATABASES_STMT, // temp
|
||||||
QUERY_NODE_CREATE_TABLE_STMT,
|
QUERY_NODE_CREATE_TABLE_STMT,
|
||||||
QUERY_NODE_CREATE_SUBTABLE_CLAUSE,
|
QUERY_NODE_CREATE_SUBTABLE_CLAUSE,
|
||||||
|
@ -93,6 +97,13 @@ typedef enum ENodeType {
|
||||||
QUERY_NODE_SHOW_DNODES_STMT,
|
QUERY_NODE_SHOW_DNODES_STMT,
|
||||||
QUERY_NODE_SHOW_VGROUPS_STMT,
|
QUERY_NODE_SHOW_VGROUPS_STMT,
|
||||||
QUERY_NODE_SHOW_MNODES_STMT,
|
QUERY_NODE_SHOW_MNODES_STMT,
|
||||||
|
QUERY_NODE_SHOW_QNODES_STMT,
|
||||||
|
QUERY_NODE_CREATE_INDEX_STMT,
|
||||||
|
QUERY_NODE_DROP_INDEX_STMT,
|
||||||
|
QUERY_NODE_CREATE_QNODE_STMT,
|
||||||
|
QUERY_NODE_DROP_QNODE_STMT,
|
||||||
|
QUERY_NODE_CREATE_TOPIC_STMT,
|
||||||
|
QUERY_NODE_DROP_TOPIC_STMT,
|
||||||
|
|
||||||
// logic plan node
|
// logic plan node
|
||||||
QUERY_NODE_LOGIC_PLAN_SCAN,
|
QUERY_NODE_LOGIC_PLAN_SCAN,
|
||||||
|
@ -185,6 +196,9 @@ const char* nodesNodeName(ENodeType type);
|
||||||
int32_t nodesNodeToString(const SNodeptr pNode, bool format, char** pStr, int32_t* pLen);
|
int32_t nodesNodeToString(const SNodeptr pNode, bool format, char** pStr, int32_t* pLen);
|
||||||
int32_t nodesStringToNode(const char* pStr, SNode** pNode);
|
int32_t nodesStringToNode(const char* pStr, SNode** pNode);
|
||||||
|
|
||||||
|
int32_t nodesListToString(const SNodeList* pList, bool format, char** pStr, int32_t* pLen);
|
||||||
|
int32_t nodesStringToList(const char* pStr, SNodeList** pList);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -82,6 +82,7 @@ typedef struct SValueNode {
|
||||||
double d;
|
double d;
|
||||||
char* p;
|
char* p;
|
||||||
} datum;
|
} datum;
|
||||||
|
char unit;
|
||||||
} SValueNode;
|
} SValueNode;
|
||||||
|
|
||||||
typedef struct SOperatorNode {
|
typedef struct SOperatorNode {
|
||||||
|
|
|
@ -51,6 +51,7 @@ typedef struct SQuery {
|
||||||
SSchema* pResSchema;
|
SSchema* pResSchema;
|
||||||
SCmdMsgInfo* pCmdMsg;
|
SCmdMsgInfo* pCmdMsg;
|
||||||
int32_t msgType;
|
int32_t msgType;
|
||||||
|
bool streamQuery;
|
||||||
} SQuery;
|
} SQuery;
|
||||||
|
|
||||||
int32_t qParseQuerySql(SParseContext* pCxt, SQuery** pQuery);
|
int32_t qParseQuerySql(SParseContext* pCxt, SQuery** pQuery);
|
||||||
|
|
|
@ -26,6 +26,7 @@ typedef struct SPlanContext {
|
||||||
uint64_t queryId;
|
uint64_t queryId;
|
||||||
int32_t acctId;
|
int32_t acctId;
|
||||||
SNode* pAstRoot;
|
SNode* pAstRoot;
|
||||||
|
bool streamQuery;
|
||||||
} SPlanContext;
|
} SPlanContext;
|
||||||
|
|
||||||
// Create the physical plan for the query, according to the AST.
|
// Create the physical plan for the query, according to the AST.
|
||||||
|
|
|
@ -29,7 +29,6 @@ extern "C" {
|
||||||
|
|
||||||
extern int tsRpcHeadSize;
|
extern int tsRpcHeadSize;
|
||||||
|
|
||||||
|
|
||||||
typedef struct SRpcConnInfo {
|
typedef struct SRpcConnInfo {
|
||||||
uint32_t clientIp;
|
uint32_t clientIp;
|
||||||
uint16_t clientPort;
|
uint16_t clientPort;
|
||||||
|
@ -39,13 +38,15 @@ typedef struct SRpcConnInfo {
|
||||||
|
|
||||||
typedef struct SRpcMsg {
|
typedef struct SRpcMsg {
|
||||||
tmsg_t msgType;
|
tmsg_t msgType;
|
||||||
|
tmsg_t expectMsgType;
|
||||||
void * pCont;
|
void * pCont;
|
||||||
int contLen;
|
int contLen;
|
||||||
int32_t code;
|
int32_t code;
|
||||||
void * handle; // rpc handle returned to app
|
void * handle; // rpc handle returned to app
|
||||||
void * ahandle; // app handle set by client
|
void * ahandle; // app handle set by client
|
||||||
} SRpcMsg;
|
int noResp; // has response or not(default 0 indicate resp);
|
||||||
|
|
||||||
|
} SRpcMsg;
|
||||||
|
|
||||||
typedef struct SRpcInit {
|
typedef struct SRpcInit {
|
||||||
uint16_t localPort; // local port
|
uint16_t localPort; // local port
|
||||||
|
@ -71,9 +72,11 @@ typedef struct SRpcInit {
|
||||||
// call back to keep conn or not
|
// call back to keep conn or not
|
||||||
bool (*pfp)(void *parent, tmsg_t msgType);
|
bool (*pfp)(void *parent, tmsg_t msgType);
|
||||||
|
|
||||||
// to support Send messages multiple times on a link
|
// to support Send messages multiple times on a link
|
||||||
//
|
void *(*mfp)(void *parent, tmsg_t msgType);
|
||||||
void* (*mfp)(void *parent, tmsg_t msgType);
|
|
||||||
|
// call back to handle except when query/fetch in progress
|
||||||
|
bool (*efp)(void *parent, tmsg_t msgType);
|
||||||
|
|
||||||
void *parent;
|
void *parent;
|
||||||
} SRpcInit;
|
} SRpcInit;
|
||||||
|
@ -94,7 +97,7 @@ int rpcReportProgress(void *pConn, char *pCont, int contLen);
|
||||||
void rpcCancelRequest(int64_t rid);
|
void rpcCancelRequest(int64_t rid);
|
||||||
|
|
||||||
// just release client conn to rpc instance, no close sock
|
// just release client conn to rpc instance, no close sock
|
||||||
void rpcReleaseHandle(void *handle);
|
void rpcReleaseHandle(void *handle, int8_t type);
|
||||||
|
|
||||||
void rpcRefHandle(void *handle, int8_t type);
|
void rpcRefHandle(void *handle, int8_t type);
|
||||||
void rpcUnrefHandle(void *handle, int8_t type);
|
void rpcUnrefHandle(void *handle, int8_t type);
|
||||||
|
|
|
@ -22,6 +22,8 @@ extern "C" {
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <semaphore.h>
|
||||||
|
|
||||||
#if !defined(WINDOWS)
|
#if !defined(WINDOWS)
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -34,7 +36,12 @@ extern "C" {
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
|
#if defined(DARWIN)
|
||||||
|
#else
|
||||||
#include <sys/prctl.h>
|
#include <sys/prctl.h>
|
||||||
|
#include <argp.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -54,9 +61,12 @@ extern "C" {
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
|
#include <termios.h>
|
||||||
#include <wctype.h>
|
#include <wctype.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TDENGINE_OS_EOK_H
|
||||||
|
#define TDENGINE_OS_EOK_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
|
||||||
|
enum EPOLL_EVENTS
|
||||||
|
{
|
||||||
|
EPOLLIN = 0x001,
|
||||||
|
#define EPOLLIN EPOLLIN
|
||||||
|
EPOLLPRI = 0x002,
|
||||||
|
#define EPOLLPRI EPOLLPRI
|
||||||
|
EPOLLOUT = 0x004,
|
||||||
|
#define EPOLLOUT EPOLLOUT
|
||||||
|
EPOLLRDNORM = 0x040,
|
||||||
|
#define EPOLLRDNORM EPOLLRDNORM
|
||||||
|
EPOLLRDBAND = 0x080,
|
||||||
|
#define EPOLLRDBAND EPOLLRDBAND
|
||||||
|
EPOLLWRNORM = 0x100,
|
||||||
|
#define EPOLLWRNORM EPOLLWRNORM
|
||||||
|
EPOLLWRBAND = 0x200,
|
||||||
|
#define EPOLLWRBAND EPOLLWRBAND
|
||||||
|
EPOLLMSG = 0x400,
|
||||||
|
#define EPOLLMSG EPOLLMSG
|
||||||
|
EPOLLERR = 0x008,
|
||||||
|
#define EPOLLERR EPOLLERR
|
||||||
|
EPOLLHUP = 0x010,
|
||||||
|
#define EPOLLHUP EPOLLHUP
|
||||||
|
EPOLLRDHUP = 0x2000,
|
||||||
|
#define EPOLLRDHUP EPOLLRDHUP
|
||||||
|
EPOLLEXCLUSIVE = 1u << 28,
|
||||||
|
#define EPOLLEXCLUSIVE EPOLLEXCLUSIVE
|
||||||
|
EPOLLWAKEUP = 1u << 29,
|
||||||
|
#define EPOLLWAKEUP EPOLLWAKEUP
|
||||||
|
EPOLLONESHOT = 1u << 30,
|
||||||
|
#define EPOLLONESHOT EPOLLONESHOT
|
||||||
|
EPOLLET = 1u << 31
|
||||||
|
#define EPOLLET EPOLLET
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Valid opcodes ( "op" parameter ) to issue to epoll_ctl(). */
|
||||||
|
#define EPOLL_CTL_ADD 1 /* Add a file descriptor to the interface. */
|
||||||
|
#define EPOLL_CTL_DEL 2 /* Remove a file descriptor from the interface. */
|
||||||
|
#define EPOLL_CTL_MOD 3 /* Change file descriptor epoll_event structure. */
|
||||||
|
|
||||||
|
|
||||||
|
typedef union epoll_data
|
||||||
|
{
|
||||||
|
void *ptr;
|
||||||
|
int fd;
|
||||||
|
uint32_t u32;
|
||||||
|
uint64_t u64;
|
||||||
|
} epoll_data_t;
|
||||||
|
|
||||||
|
struct epoll_event
|
||||||
|
{
|
||||||
|
uint32_t events; /* Epoll events */
|
||||||
|
epoll_data_t data; /* User data variable */
|
||||||
|
};
|
||||||
|
|
||||||
|
int epoll_create(int size);
|
||||||
|
int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);
|
||||||
|
int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout);
|
||||||
|
int epoll_close(int epfd);
|
||||||
|
|
||||||
|
#endif // __APPLE__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // _eok_h_fd274616_996c_400e_9023_ae70be881fa3_
|
||||||
|
|
|
@ -49,6 +49,15 @@ int64_t taosRead(FileFd fd, void *buf, int64_t count);
|
||||||
#define PATH_MAX 256
|
#define PATH_MAX 256
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef int32_t FileFd;
|
||||||
|
|
||||||
|
typedef struct TdFile {
|
||||||
|
pthread_rwlock_t rwlock;
|
||||||
|
int refId;
|
||||||
|
FileFd fd;
|
||||||
|
FILE *fp;
|
||||||
|
} * TdFilePtr, TdFile;
|
||||||
|
|
||||||
typedef struct TdFile *TdFilePtr;
|
typedef struct TdFile *TdFilePtr;
|
||||||
|
|
||||||
#define TD_FILE_CTEATE 0x0001
|
#define TD_FILE_CTEATE 0x0001
|
||||||
|
@ -101,8 +110,16 @@ int64_t taosCopyFile(const char *from, const char *to);
|
||||||
int32_t taosRemoveFile(const char *path);
|
int32_t taosRemoveFile(const char *path);
|
||||||
|
|
||||||
void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, char *dstPath);
|
void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, char *dstPath);
|
||||||
|
|
||||||
|
#if defined(_TD_DARWIN_64)
|
||||||
|
typedef int32_t SocketFd;
|
||||||
|
|
||||||
|
int64_t taosSendFile(SocketFd fdDst, FileFd pFileSrc, int64_t *offset, int64_t size);
|
||||||
|
int64_t taosFSendFile(FILE *pFileOut, FILE *pFileIn, int64_t *offset, int64_t size);
|
||||||
|
#else
|
||||||
|
int64_t taosSendFile(SocketFd fdDst, TdFilePtr pFileSrc, int64_t *offset, int64_t size);
|
||||||
int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, int64_t size);
|
int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, int64_t size);
|
||||||
|
#endif
|
||||||
|
|
||||||
void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length);
|
void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length);
|
||||||
bool taosValidFile(TdFilePtr pFile);
|
bool taosValidFile(TdFilePtr pFile);
|
||||||
|
|
|
@ -38,12 +38,12 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined (_TD_DARWIN_64)
|
#if defined (_TD_DARWIN_64)
|
||||||
#define pthread_rwlock_t pthread_mutex_t
|
// #define pthread_rwlock_t pthread_mutex_t
|
||||||
#define pthread_rwlock_init(lock, NULL) pthread_mutex_init(lock, NULL)
|
// #define pthread_rwlock_init(lock, NULL) pthread_mutex_init(lock, NULL)
|
||||||
#define pthread_rwlock_destroy(lock) pthread_mutex_destroy(lock)
|
// #define pthread_rwlock_destroy(lock) pthread_mutex_destroy(lock)
|
||||||
#define pthread_rwlock_wrlock(lock) pthread_mutex_lock(lock)
|
// #define pthread_rwlock_wrlock(lock) pthread_mutex_lock(lock)
|
||||||
#define pthread_rwlock_rdlock(lock) pthread_mutex_lock(lock)
|
// #define pthread_rwlock_rdlock(lock) pthread_mutex_lock(lock)
|
||||||
#define pthread_rwlock_unlock(lock) pthread_mutex_unlock(lock)
|
// #define pthread_rwlock_unlock(lock) pthread_mutex_unlock(lock)
|
||||||
|
|
||||||
#define pthread_spinlock_t pthread_mutex_t
|
#define pthread_spinlock_t pthread_mutex_t
|
||||||
#define pthread_spin_init(lock, NULL) pthread_mutex_init(lock, NULL)
|
#define pthread_spin_init(lock, NULL) pthread_mutex_init(lock, NULL)
|
||||||
|
|
|
@ -33,8 +33,15 @@
|
||||||
#include <winbase.h>
|
#include <winbase.h>
|
||||||
#include <Winsock2.h>
|
#include <Winsock2.h>
|
||||||
#else
|
#else
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <sys/epoll.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#if defined(_TD_DARWIN_64)
|
||||||
|
#include <osEok.h>
|
||||||
|
#else
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <sys/epoll.h>
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -49,7 +56,29 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_TD_DARWIN_64)
|
#if defined(_TD_DARWIN_64)
|
||||||
#define htobe64 htonll
|
// #define htobe64 htonll
|
||||||
|
|
||||||
|
# include <libkern/OSByteOrder.h>
|
||||||
|
|
||||||
|
# define htobe16(x) OSSwapHostToBigInt16(x)
|
||||||
|
# define htole16(x) OSSwapHostToLittleInt16(x)
|
||||||
|
# define be16toh(x) OSSwapBigToHostInt16(x)
|
||||||
|
# define le16toh(x) OSSwapLittleToHostInt16(x)
|
||||||
|
|
||||||
|
# define htobe32(x) OSSwapHostToBigInt32(x)
|
||||||
|
# define htole32(x) OSSwapHostToLittleInt32(x)
|
||||||
|
# define be32toh(x) OSSwapBigToHostInt32(x)
|
||||||
|
# define le32toh(x) OSSwapLittleToHostInt32(x)
|
||||||
|
|
||||||
|
# define htobe64(x) OSSwapHostToBigInt64(x)
|
||||||
|
# define htole64(x) OSSwapHostToLittleInt64(x)
|
||||||
|
# define be64toh(x) OSSwapBigToHostInt64(x)
|
||||||
|
# define le64toh(x) OSSwapLittleToHostInt64(x)
|
||||||
|
|
||||||
|
# define __BYTE_ORDER BYTE_ORDER
|
||||||
|
# define __BIG_ENDIAN BIG_ENDIAN
|
||||||
|
# define __LITTLE_ENDIAN LITTLE_ENDIAN
|
||||||
|
# define __PDP_ENDIAN PDP_ENDIAN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TAOS_EPOLL_WAIT_TIME 500
|
#define TAOS_EPOLL_WAIT_TIME 500
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#ifndef _TD_OS_SYSINFO_H_
|
#ifndef _TD_OS_SYSINFO_H_
|
||||||
#define _TD_OS_SYSINFO_H_
|
#define _TD_OS_SYSINFO_H_
|
||||||
|
|
||||||
|
#include <sys/statvfs.h>
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -52,7 +53,7 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen);
|
||||||
char *taosGetCmdlineByPID(int32_t pid);
|
char *taosGetCmdlineByPID(int32_t pid);
|
||||||
void taosSetCoreDump(bool enable);
|
void taosSetCoreDump(bool enable);
|
||||||
|
|
||||||
#if defined(WINDOWS)
|
#if !defined(LINUX)
|
||||||
|
|
||||||
#define _UTSNAME_LENGTH 65
|
#define _UTSNAME_LENGTH 65
|
||||||
#define _UTSNAME_MACHINE_LENGTH _UTSNAME_LENGTH
|
#define _UTSNAME_MACHINE_LENGTH _UTSNAME_LENGTH
|
||||||
|
|
|
@ -354,6 +354,7 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_TDB_IVLD_TAG_VAL TAOS_DEF_ERROR_CODE(0, 0x0615)
|
#define TSDB_CODE_TDB_IVLD_TAG_VAL TAOS_DEF_ERROR_CODE(0, 0x0615)
|
||||||
#define TSDB_CODE_TDB_NO_CACHE_LAST_ROW TAOS_DEF_ERROR_CODE(0, 0x0616)
|
#define TSDB_CODE_TDB_NO_CACHE_LAST_ROW TAOS_DEF_ERROR_CODE(0, 0x0616)
|
||||||
#define TSDB_CODE_TDB_NO_SMA_INDEX_IN_META TAOS_DEF_ERROR_CODE(0, 0x0617)
|
#define TSDB_CODE_TDB_NO_SMA_INDEX_IN_META TAOS_DEF_ERROR_CODE(0, 0x0617)
|
||||||
|
#define TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR TAOS_DEF_ERROR_CODE(0, 0x0618)
|
||||||
|
|
||||||
// query
|
// query
|
||||||
#define TSDB_CODE_QRY_INVALID_QHANDLE TAOS_DEF_ERROR_CODE(0, 0x0700)
|
#define TSDB_CODE_QRY_INVALID_QHANDLE TAOS_DEF_ERROR_CODE(0, 0x0700)
|
||||||
|
|
|
@ -345,19 +345,19 @@ typedef enum ELogicConditionType {
|
||||||
#define TSDB_MAX_DB_QUORUM_OPTION 2
|
#define TSDB_MAX_DB_QUORUM_OPTION 2
|
||||||
#define TSDB_DEFAULT_DB_QUORUM_OPTION 1
|
#define TSDB_DEFAULT_DB_QUORUM_OPTION 1
|
||||||
|
|
||||||
#define TSDB_MIN_DB_TTL_OPTION 1
|
#define TSDB_MIN_DB_TTL_OPTION 1
|
||||||
#define TSDB_DEFAULT_DB_TTL_OPTION 0
|
#define TSDB_DEFAULT_DB_TTL_OPTION 0
|
||||||
|
|
||||||
#define TSDB_MIN_DB_SINGLE_STABLE_OPTION 0
|
#define TSDB_MIN_DB_SINGLE_STABLE_OPTION 0
|
||||||
#define TSDB_MAX_DB_SINGLE_STABLE_OPTION 1
|
#define TSDB_MAX_DB_SINGLE_STABLE_OPTION 1
|
||||||
#define TSDB_DEFAULT_DB_SINGLE_STABLE_OPTION 0
|
#define TSDB_DEFAULT_DB_SINGLE_STABLE_OPTION 0
|
||||||
|
|
||||||
#define TSDB_MIN_DB_STREAM_MODE_OPTION 0
|
#define TSDB_MIN_DB_STREAM_MODE_OPTION 0
|
||||||
#define TSDB_MAX_DB_STREAM_MODE_OPTION 1
|
#define TSDB_MAX_DB_STREAM_MODE_OPTION 1
|
||||||
#define TSDB_DEFAULT_DB_STREAM_MODE_OPTION 0
|
#define TSDB_DEFAULT_DB_STREAM_MODE_OPTION 0
|
||||||
|
|
||||||
#define TSDB_MAX_JOIN_TABLE_NUM 10
|
#define TSDB_MAX_JOIN_TABLE_NUM 10
|
||||||
#define TSDB_MAX_UNION_CLAUSE 5
|
#define TSDB_MAX_UNION_CLAUSE 5
|
||||||
|
|
||||||
#define TSDB_MIN_DB_UPDATE 0
|
#define TSDB_MIN_DB_UPDATE 0
|
||||||
#define TSDB_MAX_DB_UPDATE 2
|
#define TSDB_MAX_DB_UPDATE 2
|
||||||
|
@ -445,6 +445,9 @@ typedef struct {
|
||||||
|
|
||||||
#define TMQ_SEPARATOR ':'
|
#define TMQ_SEPARATOR ':'
|
||||||
|
|
||||||
|
#define SND_UNIQUE_THREAD_NUM 2
|
||||||
|
#define SND_SHARED_THREAD_NUM 2
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -402,10 +402,33 @@ static int32_t tDecodeCStrTo(SCoder* pDecoder, char* val) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tDecodeBinaryAlloc(SCoder* pDecoder, void** val, uint64_t* len) {
|
||||||
|
if (tDecodeU64v(pDecoder, len) < 0) return -1;
|
||||||
|
|
||||||
|
if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, *len)) return -1;
|
||||||
|
*val = malloc(*len);
|
||||||
|
if (*val == NULL) return -1;
|
||||||
|
memcpy(*val, TD_CODER_CURRENT(pDecoder), *len);
|
||||||
|
|
||||||
|
TD_CODER_MOVE_POS(pDecoder, *len);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tDecodeCStrAndLenAlloc(SCoder* pDecoder, char** val, uint64_t* len) {
|
||||||
|
if (tDecodeBinaryAlloc(pDecoder, (void**)val, len) < 0) return -1;
|
||||||
|
(*len) -= 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tDecodeCStrAlloc(SCoder* pDecoder, char** val) {
|
||||||
|
uint64_t len;
|
||||||
|
return tDecodeCStrAndLenAlloc(pDecoder, val, &len);
|
||||||
|
}
|
||||||
|
|
||||||
static FORCE_INLINE bool tDecodeIsEnd(SCoder* pCoder) { return (pCoder->size == pCoder->pos); }
|
static FORCE_INLINE bool tDecodeIsEnd(SCoder* pCoder) { return (pCoder->size == pCoder->pos); }
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_ENCODE_H_*/
|
#endif /*_TD_UTIL_ENCODE_H_*/
|
||||||
|
|
|
@ -25,6 +25,7 @@ extern "C" {
|
||||||
typedef void SJson;
|
typedef void SJson;
|
||||||
|
|
||||||
SJson* tjsonCreateObject();
|
SJson* tjsonCreateObject();
|
||||||
|
SJson* tjsonCreateArray();
|
||||||
void tjsonDelete(SJson* pJson);
|
void tjsonDelete(SJson* pJson);
|
||||||
|
|
||||||
SJson* tjsonAddArrayToObject(SJson* pJson, const char* pName);
|
SJson* tjsonAddArrayToObject(SJson* pJson, const char* pName);
|
||||||
|
|
|
@ -21,6 +21,7 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
#include "planner.h"
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
#include "taos.h"
|
#include "taos.h"
|
||||||
#include "tcommon.h"
|
#include "tcommon.h"
|
||||||
|
@ -238,6 +239,7 @@ int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32
|
||||||
int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj** pRequest);
|
int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj** pRequest);
|
||||||
|
|
||||||
int32_t parseSql(SRequestObj* pRequest, SQuery** pQuery);
|
int32_t parseSql(SRequestObj* pRequest, SQuery** pQuery);
|
||||||
|
int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList);
|
||||||
|
|
||||||
// --- heartbeat
|
// --- heartbeat
|
||||||
// global, called by mgmt
|
// global, called by mgmt
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
|
|
||||||
#include "clientInt.h"
|
#include "clientInt.h"
|
||||||
#include "clientLog.h"
|
#include "clientLog.h"
|
||||||
#include "parser.h"
|
|
||||||
#include "planner.h"
|
|
||||||
#include "scheduler.h"
|
#include "scheduler.h"
|
||||||
#include "tdatablock.h"
|
#include "tdatablock.h"
|
||||||
#include "tdef.h"
|
#include "tdef.h"
|
||||||
|
@ -211,7 +209,6 @@ void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList) {
|
int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList) {
|
||||||
void* pTransporter = pRequest->pTscObj->pAppInfo->pTransporter;
|
void* pTransporter = pRequest->pTscObj->pAppInfo->pTransporter;
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ int32_t genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
setErrno(pRequest, code);
|
setErrno(pRequest, code);
|
||||||
|
|
||||||
free(pMsg->pData);
|
free(pMsg->pData);
|
||||||
sem_post(&pRequest->body.rspSem);
|
tsem_post(&pRequest->body.rspSem);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ int32_t processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
free(pMsg->pData);
|
free(pMsg->pData);
|
||||||
setErrno(pRequest, code);
|
setErrno(pRequest, code);
|
||||||
sem_post(&pRequest->body.rspSem);
|
tsem_post(&pRequest->body.rspSem);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ int32_t processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
pTscObj->pAppInfo->numOfConns);
|
pTscObj->pAppInfo->numOfConns);
|
||||||
|
|
||||||
free(pMsg->pData);
|
free(pMsg->pData);
|
||||||
sem_post(&pRequest->body.rspSem);
|
tsem_post(&pRequest->body.rspSem);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -459,7 +459,7 @@ void tmq_conf_set_offset_commit_cb(tmq_conf_t* conf, tmq_commit_cb* cb) { conf->
|
||||||
TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, int sqlLen) {
|
TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, int sqlLen) {
|
||||||
STscObj* pTscObj = (STscObj*)taos;
|
STscObj* pTscObj = (STscObj*)taos;
|
||||||
SRequestObj* pRequest = NULL;
|
SRequestObj* pRequest = NULL;
|
||||||
SQuery* pQueryNode = NULL;
|
SQuery* pQueryNode = NULL;
|
||||||
char* pStr = NULL;
|
char* pStr = NULL;
|
||||||
|
|
||||||
terrno = TSDB_CODE_SUCCESS;
|
terrno = TSDB_CODE_SUCCESS;
|
||||||
|
@ -486,17 +486,15 @@ TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, i
|
||||||
CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return);
|
CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return);
|
||||||
CHECK_CODE_GOTO(parseSql(pRequest, &pQueryNode), _return);
|
CHECK_CODE_GOTO(parseSql(pRequest, &pQueryNode), _return);
|
||||||
|
|
||||||
SQueryStmtInfo* pQueryStmtInfo = (SQueryStmtInfo*)pQueryNode;
|
pQueryNode->streamQuery = true;
|
||||||
pQueryStmtInfo->info.continueQuery = true;
|
|
||||||
|
|
||||||
// todo check for invalid sql statement and return with error code
|
// todo check for invalid sql statement and return with error code
|
||||||
|
|
||||||
SSchema* schema = NULL;
|
SSchema* schema = NULL;
|
||||||
int32_t numOfCols = 0;
|
int32_t numOfCols = 0;
|
||||||
CHECK_CODE_GOTO(qCreateQueryDag(pQueryNode, &pRequest->body.pDag, &schema, &numOfCols, NULL, pRequest->requestId),
|
CHECK_CODE_GOTO(getPlan(pRequest, pQueryNode, &pRequest->body.pDag, NULL), _return);
|
||||||
_return);
|
|
||||||
|
|
||||||
pStr = qDagToString(pRequest->body.pDag);
|
pStr = qQueryPlanToString(pRequest->body.pDag);
|
||||||
if (pStr == NULL) {
|
if (pStr == NULL) {
|
||||||
goto _return;
|
goto _return;
|
||||||
}
|
}
|
||||||
|
@ -506,7 +504,7 @@ TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, i
|
||||||
// The topic should be related to a database that the queried table is belonged to.
|
// The topic should be related to a database that the queried table is belonged to.
|
||||||
SName name = {0};
|
SName name = {0};
|
||||||
char dbName[TSDB_DB_FNAME_LEN] = {0};
|
char dbName[TSDB_DB_FNAME_LEN] = {0};
|
||||||
tNameGetFullDbName(&((SQueryStmtInfo*)pQueryNode)->pTableMetaInfo[0]->name, dbName);
|
// tNameGetFullDbName(&((SQueryStmtInfo*)pQueryNode)->pTableMetaInfo[0]->name, dbName);
|
||||||
|
|
||||||
tNameFromString(&name, dbName, T_NAME_ACCT | T_NAME_DB);
|
tNameFromString(&name, dbName, T_NAME_ACCT | T_NAME_DB);
|
||||||
tNameFromString(&name, topicName, T_NAME_TABLE);
|
tNameFromString(&name, topicName, T_NAME_TABLE);
|
||||||
|
|
|
@ -868,7 +868,7 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirs
|
||||||
qsort(pColInfoData->pData, pDataBlock->info.rows, pColInfoData->info.bytes, fn);
|
qsort(pColInfoData->pData, pDataBlock->info.rows, pColInfoData->info.bytes, fn);
|
||||||
|
|
||||||
int64_t p1 = taosGetTimestampUs();
|
int64_t p1 = taosGetTimestampUs();
|
||||||
printf("sort:%ld, rows:%d\n", p1 - p0, pDataBlock->info.rows);
|
printf("sort:%" PRId64 ", rows:%d\n", p1 - p0, pDataBlock->info.rows);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
} else { // var data type
|
} else { // var data type
|
||||||
|
@ -916,7 +916,7 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirs
|
||||||
copyBackToBlock(pDataBlock, pCols);
|
copyBackToBlock(pDataBlock, pCols);
|
||||||
int64_t p4 = taosGetTimestampUs();
|
int64_t p4 = taosGetTimestampUs();
|
||||||
|
|
||||||
printf("sort:%ld, create:%ld, assign:%ld, copyback:%ld, rows:%d\n", p1-p0, p2 - p1, p3 - p2, p4-p3, rows);
|
printf("sort:%" PRId64 ", create:%" PRId64 ", assign:%" PRId64 ", copyback:%" PRId64 ", rows:%d\n", p1-p0, p2 - p1, p3 - p2, p4-p3, rows);
|
||||||
destroyTupleIndex(index);
|
destroyTupleIndex(index);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -1021,7 +1021,7 @@ int32_t dataBlockCompar_rv(const void* p1, const void* p2, const void* param) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t varColSort(SColumnInfoData* pColumnInfoData, SBlockOrderInfo* pOrder) {
|
int32_t varColSort(SColumnInfoData* pColumnInfoData, SBlockOrderInfo* pOrder) {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirst) {
|
int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirst) {
|
||||||
|
@ -1059,8 +1059,9 @@ int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullF
|
||||||
copyBackToBlock(pDataBlock, pCols);
|
copyBackToBlock(pDataBlock, pCols);
|
||||||
int64_t p4 = taosGetTimestampUs();
|
int64_t p4 = taosGetTimestampUs();
|
||||||
|
|
||||||
printf("sort:%ld, create:%ld, assign:%ld, copyback:%ld, rows:%d\n", p1 - p0, p2 - p1, p3 - p2, p4 - p3, rows);
|
printf("sort:%" PRId64 ", create:%" PRId64", assign:%" PRId64 ", copyback:%" PRId64 ", rows:%d\n", p1 - p0, p2 - p1, p3 - p2, p4 - p3, rows);
|
||||||
// destroyTupleIndex(index);
|
// destroyTupleIndex(index);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void blockDataCleanup(SSDataBlock* pDataBlock) {
|
void blockDataCleanup(SSDataBlock* pDataBlock) {
|
||||||
|
|
|
@ -1467,8 +1467,7 @@ int32_t tDeserializeSUseDbReq(void *buf, int32_t bufLen, SUseDbReq *pReq) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t tSerializeSQnodeListReq(void *buf, int32_t bufLen, SQnodeListReq *pReq) {
|
||||||
int32_t tSerializeSQnodeListReq(void* buf, int32_t bufLen, SQnodeListReq* pReq) {
|
|
||||||
SCoder encoder = {0};
|
SCoder encoder = {0};
|
||||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
||||||
|
|
||||||
|
@ -1499,7 +1498,7 @@ int32_t tSerializeSQnodeListRsp(void *buf, int32_t bufLen, SQnodeListRsp *pRsp)
|
||||||
|
|
||||||
if (tStartEncode(&encoder) < 0) return -1;
|
if (tStartEncode(&encoder) < 0) return -1;
|
||||||
int32_t num = taosArrayGetSize(pRsp->epSetList);
|
int32_t num = taosArrayGetSize(pRsp->epSetList);
|
||||||
if (tEncodeI32(&encoder, num) < 0) return -1;
|
if (tEncodeI32(&encoder, num) < 0) return -1;
|
||||||
for (int32_t i = 0; i < num; ++i) {
|
for (int32_t i = 0; i < num; ++i) {
|
||||||
SEpSet *epSet = taosArrayGet(pRsp->epSetList, i);
|
SEpSet *epSet = taosArrayGet(pRsp->epSetList, i);
|
||||||
if (tEncodeSEpSet(&encoder, epSet) < 0) return -1;
|
if (tEncodeSEpSet(&encoder, epSet) < 0) return -1;
|
||||||
|
@ -1990,11 +1989,9 @@ int32_t tDeserializeSMDropTopicReq(void *buf, int32_t bufLen, SMDropTopicReq *pR
|
||||||
|
|
||||||
int32_t tSerializeSCMCreateTopicReq(void *buf, int32_t bufLen, const SCMCreateTopicReq *pReq) {
|
int32_t tSerializeSCMCreateTopicReq(void *buf, int32_t bufLen, const SCMCreateTopicReq *pReq) {
|
||||||
int32_t sqlLen = 0;
|
int32_t sqlLen = 0;
|
||||||
int32_t physicalPlanLen = 0;
|
int32_t astLen = 0;
|
||||||
int32_t logicalPlanLen = 0;
|
|
||||||
if (pReq->sql != NULL) sqlLen = (int32_t)strlen(pReq->sql);
|
if (pReq->sql != NULL) sqlLen = (int32_t)strlen(pReq->sql);
|
||||||
if (pReq->physicalPlan != NULL) physicalPlanLen = (int32_t)strlen(pReq->physicalPlan);
|
if (pReq->ast != NULL) astLen = (int32_t)strlen(pReq->ast);
|
||||||
if (pReq->logicalPlan != NULL) logicalPlanLen = (int32_t)strlen(pReq->logicalPlan);
|
|
||||||
|
|
||||||
SCoder encoder = {0};
|
SCoder encoder = {0};
|
||||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
||||||
|
@ -2003,11 +2000,9 @@ int32_t tSerializeSCMCreateTopicReq(void *buf, int32_t bufLen, const SCMCreateTo
|
||||||
if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
|
if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
|
||||||
if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1;
|
if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, sqlLen) < 0) return -1;
|
if (tEncodeI32(&encoder, sqlLen) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, physicalPlanLen) < 0) return -1;
|
if (tEncodeI32(&encoder, astLen) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, logicalPlanLen) < 0) return -1;
|
if (sqlLen > 0 && tEncodeCStr(&encoder, pReq->sql) < 0) return -1;
|
||||||
if (tEncodeCStr(&encoder, pReq->sql) < 0) return -1;
|
if (astLen > 0 && tEncodeCStr(&encoder, pReq->ast) < 0) return -1;
|
||||||
if (tEncodeCStr(&encoder, pReq->physicalPlan) < 0) return -1;
|
|
||||||
if (tEncodeCStr(&encoder, pReq->logicalPlan) < 0) return -1;
|
|
||||||
|
|
||||||
tEndEncode(&encoder);
|
tEndEncode(&encoder);
|
||||||
|
|
||||||
|
@ -2018,8 +2013,7 @@ int32_t tSerializeSCMCreateTopicReq(void *buf, int32_t bufLen, const SCMCreateTo
|
||||||
|
|
||||||
int32_t tDeserializeSCMCreateTopicReq(void *buf, int32_t bufLen, SCMCreateTopicReq *pReq) {
|
int32_t tDeserializeSCMCreateTopicReq(void *buf, int32_t bufLen, SCMCreateTopicReq *pReq) {
|
||||||
int32_t sqlLen = 0;
|
int32_t sqlLen = 0;
|
||||||
int32_t physicalPlanLen = 0;
|
int32_t astLen = 0;
|
||||||
int32_t logicalPlanLen = 0;
|
|
||||||
|
|
||||||
SCoder decoder = {0};
|
SCoder decoder = {0};
|
||||||
tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
|
tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
|
||||||
|
@ -2028,17 +2022,20 @@ int32_t tDeserializeSCMCreateTopicReq(void *buf, int32_t bufLen, SCMCreateTopicR
|
||||||
if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
|
if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
|
||||||
if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1;
|
if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &sqlLen) < 0) return -1;
|
if (tDecodeI32(&decoder, &sqlLen) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &physicalPlanLen) < 0) return -1;
|
if (tDecodeI32(&decoder, &astLen) < 0) return -1;
|
||||||
if (tDecodeI32(&decoder, &logicalPlanLen) < 0) return -1;
|
|
||||||
|
|
||||||
pReq->sql = calloc(1, sqlLen + 1);
|
if (sqlLen > 0) {
|
||||||
pReq->physicalPlan = calloc(1, physicalPlanLen + 1);
|
pReq->sql = calloc(1, sqlLen + 1);
|
||||||
pReq->logicalPlan = calloc(1, logicalPlanLen + 1);
|
if (pReq->sql == NULL) return -1;
|
||||||
if (pReq->sql == NULL || pReq->physicalPlan == NULL || pReq->logicalPlan == NULL) return -1;
|
if (tDecodeCStrTo(&decoder, pReq->sql) < 0) return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (astLen > 0) {
|
||||||
|
pReq->ast = calloc(1, astLen + 1);
|
||||||
|
if (pReq->ast == NULL) return -1;
|
||||||
|
if (tDecodeCStrTo(&decoder, pReq->ast) < 0) return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (tDecodeCStrTo(&decoder, pReq->sql) < 0) return -1;
|
|
||||||
if (tDecodeCStrTo(&decoder, pReq->physicalPlan) < 0) return -1;
|
|
||||||
if (tDecodeCStrTo(&decoder, pReq->logicalPlan) < 0) return -1;
|
|
||||||
tEndDecode(&decoder);
|
tEndDecode(&decoder);
|
||||||
|
|
||||||
tCoderClear(&decoder);
|
tCoderClear(&decoder);
|
||||||
|
@ -2047,8 +2044,7 @@ int32_t tDeserializeSCMCreateTopicReq(void *buf, int32_t bufLen, SCMCreateTopicR
|
||||||
|
|
||||||
void tFreeSCMCreateTopicReq(SCMCreateTopicReq *pReq) {
|
void tFreeSCMCreateTopicReq(SCMCreateTopicReq *pReq) {
|
||||||
tfree(pReq->sql);
|
tfree(pReq->sql);
|
||||||
tfree(pReq->physicalPlan);
|
tfree(pReq->ast);
|
||||||
tfree(pReq->logicalPlan);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tSerializeSCMCreateTopicRsp(void *buf, int32_t bufLen, const SCMCreateTopicRsp *pRsp) {
|
int32_t tSerializeSCMCreateTopicRsp(void *buf, int32_t bufLen, const SCMCreateTopicRsp *pRsp) {
|
||||||
|
@ -2491,27 +2487,27 @@ int32_t tSerializeSSchedulerHbReq(void *buf, int32_t bufLen, SSchedulerHbReq *pR
|
||||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
||||||
|
|
||||||
if (tStartEncode(&encoder) < 0) return -1;
|
if (tStartEncode(&encoder) < 0) return -1;
|
||||||
if (tEncodeU64(&encoder, pReq->sId) < 0) return -1;
|
if (tEncodeU64(&encoder, pReq->sId) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pReq->epId.nodeId) < 0) return -1;
|
if (tEncodeI32(&encoder, pReq->epId.nodeId) < 0) return -1;
|
||||||
if (tEncodeU16(&encoder, pReq->epId.ep.port) < 0) return -1;
|
if (tEncodeU16(&encoder, pReq->epId.ep.port) < 0) return -1;
|
||||||
if (tEncodeCStr(&encoder, pReq->epId.ep.fqdn) < 0) return -1;
|
if (tEncodeCStr(&encoder, pReq->epId.ep.fqdn) < 0) return -1;
|
||||||
if (pReq->taskAction) {
|
if (pReq->taskAction) {
|
||||||
int32_t num = taosArrayGetSize(pReq->taskAction);
|
int32_t num = taosArrayGetSize(pReq->taskAction);
|
||||||
if (tEncodeI32(&encoder, num) < 0) return -1;
|
if (tEncodeI32(&encoder, num) < 0) return -1;
|
||||||
for (int32_t i = 0; i < num; ++i) {
|
for (int32_t i = 0; i < num; ++i) {
|
||||||
STaskAction *action = taosArrayGet(pReq->taskAction, i);
|
STaskAction *action = taosArrayGet(pReq->taskAction, i);
|
||||||
if (tEncodeU64(&encoder, action->queryId) < 0) return -1;
|
if (tEncodeU64(&encoder, action->queryId) < 0) return -1;
|
||||||
if (tEncodeU64(&encoder, action->taskId) < 0) return -1;
|
if (tEncodeU64(&encoder, action->taskId) < 0) return -1;
|
||||||
if (tEncodeI8(&encoder, action->action) < 0) return -1;
|
if (tEncodeI8(&encoder, action->action) < 0) return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (tEncodeI32(&encoder, 0) < 0) return -1;
|
if (tEncodeI32(&encoder, 0) < 0) return -1;
|
||||||
}
|
}
|
||||||
tEndEncode(&encoder);
|
tEndEncode(&encoder);
|
||||||
|
|
||||||
int32_t tlen = encoder.pos;
|
int32_t tlen = encoder.pos;
|
||||||
tCoderClear(&encoder);
|
tCoderClear(&encoder);
|
||||||
|
|
||||||
if (buf != NULL) {
|
if (buf != NULL) {
|
||||||
SMsgHead *pHead = (SMsgHead *)((char *)buf - headLen);
|
SMsgHead *pHead = (SMsgHead *)((char *)buf - headLen);
|
||||||
pHead->vgId = htonl(pReq->header.vgId);
|
pHead->vgId = htonl(pReq->header.vgId);
|
||||||
|
@ -2559,29 +2555,27 @@ int32_t tDeserializeSSchedulerHbReq(void *buf, int32_t bufLen, SSchedulerHbReq *
|
||||||
|
|
||||||
void tFreeSSchedulerHbReq(SSchedulerHbReq *pReq) { taosArrayDestroy(pReq->taskAction); }
|
void tFreeSSchedulerHbReq(SSchedulerHbReq *pReq) { taosArrayDestroy(pReq->taskAction); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int32_t tSerializeSSchedulerHbRsp(void *buf, int32_t bufLen, SSchedulerHbRsp *pRsp) {
|
int32_t tSerializeSSchedulerHbRsp(void *buf, int32_t bufLen, SSchedulerHbRsp *pRsp) {
|
||||||
SCoder encoder = {0};
|
SCoder encoder = {0};
|
||||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
||||||
|
|
||||||
if (tStartEncode(&encoder) < 0) return -1;
|
if (tStartEncode(&encoder) < 0) return -1;
|
||||||
if (tEncodeU64(&encoder, pRsp->seqId) < 0) return -1;
|
if (tEncodeU64(&encoder, pRsp->seqId) < 0) return -1;
|
||||||
if (tEncodeI32(&encoder, pRsp->epId.nodeId) < 0) return -1;
|
if (tEncodeI32(&encoder, pRsp->epId.nodeId) < 0) return -1;
|
||||||
if (tEncodeU16(&encoder, pRsp->epId.ep.port) < 0) return -1;
|
if (tEncodeU16(&encoder, pRsp->epId.ep.port) < 0) return -1;
|
||||||
if (tEncodeCStr(&encoder, pRsp->epId.ep.fqdn) < 0) return -1;
|
if (tEncodeCStr(&encoder, pRsp->epId.ep.fqdn) < 0) return -1;
|
||||||
if (pRsp->taskStatus) {
|
if (pRsp->taskStatus) {
|
||||||
int32_t num = taosArrayGetSize(pRsp->taskStatus);
|
int32_t num = taosArrayGetSize(pRsp->taskStatus);
|
||||||
if (tEncodeI32(&encoder, num) < 0) return -1;
|
if (tEncodeI32(&encoder, num) < 0) return -1;
|
||||||
for (int32_t i = 0; i < num; ++i) {
|
for (int32_t i = 0; i < num; ++i) {
|
||||||
STaskStatus *status = taosArrayGet(pRsp->taskStatus, i);
|
STaskStatus *status = taosArrayGet(pRsp->taskStatus, i);
|
||||||
if (tEncodeU64(&encoder, status->queryId) < 0) return -1;
|
if (tEncodeU64(&encoder, status->queryId) < 0) return -1;
|
||||||
if (tEncodeU64(&encoder, status->taskId) < 0) return -1;
|
if (tEncodeU64(&encoder, status->taskId) < 0) return -1;
|
||||||
if (tEncodeI64(&encoder, status->refId) < 0) return -1;
|
if (tEncodeI64(&encoder, status->refId) < 0) return -1;
|
||||||
if (tEncodeI8(&encoder, status->status) < 0) return -1;
|
if (tEncodeI8(&encoder, status->status) < 0) return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (tEncodeI32(&encoder, 0) < 0) return -1;
|
if (tEncodeI32(&encoder, 0) < 0) return -1;
|
||||||
}
|
}
|
||||||
tEndEncode(&encoder);
|
tEndEncode(&encoder);
|
||||||
|
|
||||||
|
@ -2680,9 +2674,9 @@ int32_t tDeserializeSCMCreateStreamReq(void *buf, int32_t bufLen, SCMCreateStrea
|
||||||
if (tStartDecode(&decoder) < 0) return -1;
|
if (tStartDecode(&decoder) < 0) return -1;
|
||||||
if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
|
if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
|
||||||
if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1;
|
if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1;
|
||||||
if (tDecodeCStr(&decoder, (const char **)&pReq->sql) < 0) return -1;
|
if (tDecodeCStrAlloc(&decoder, &pReq->sql) < 0) return -1;
|
||||||
if (tDecodeCStr(&decoder, (const char **)&pReq->physicalPlan) < 0) return -1;
|
if (tDecodeCStrAlloc(&decoder, &pReq->physicalPlan) < 0) return -1;
|
||||||
if (tDecodeCStr(&decoder, (const char **)&pReq->logicalPlan) < 0) return -1;
|
if (tDecodeCStrAlloc(&decoder, &pReq->logicalPlan) < 0) return -1;
|
||||||
tEndDecode(&decoder);
|
tEndDecode(&decoder);
|
||||||
|
|
||||||
tCoderClear(&decoder);
|
tCoderClear(&decoder);
|
||||||
|
@ -2694,3 +2688,32 @@ void tFreeSCMCreateStreamReq(SCMCreateStreamReq *pReq) {
|
||||||
tfree(pReq->physicalPlan);
|
tfree(pReq->physicalPlan);
|
||||||
tfree(pReq->logicalPlan);
|
tfree(pReq->logicalPlan);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t tEncodeSStreamTask(SCoder *pEncoder, const SStreamTask *pTask) {
|
||||||
|
if (tStartEncode(pEncoder) < 0) return -1;
|
||||||
|
if (tEncodeI64(pEncoder, pTask->streamId) < 0) return -1;
|
||||||
|
if (tEncodeI32(pEncoder, pTask->taskId) < 0) return -1;
|
||||||
|
if (tEncodeI32(pEncoder, pTask->level) < 0) return -1;
|
||||||
|
if (tEncodeI8(pEncoder, pTask->status) < 0) return -1;
|
||||||
|
if (tEncodeCStr(pEncoder, pTask->qmsg) < 0) return -1;
|
||||||
|
tEndEncode(pEncoder);
|
||||||
|
return pEncoder->pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tDecodeSStreamTask(SCoder *pDecoder, SStreamTask *pTask) {
|
||||||
|
if (tStartDecode(pDecoder) < 0) return -1;
|
||||||
|
if (tDecodeI64(pDecoder, &pTask->streamId) < 0) return -1;
|
||||||
|
if (tDecodeI32(pDecoder, &pTask->taskId) < 0) return -1;
|
||||||
|
if (tDecodeI32(pDecoder, &pTask->level) < 0) return -1;
|
||||||
|
if (tDecodeI8(pDecoder, &pTask->status) < 0) return -1;
|
||||||
|
if (tDecodeCStrAlloc(pDecoder, &pTask->qmsg) < 0) return -1;
|
||||||
|
tEndDecode(pDecoder);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tFreeSStreamTask(SStreamTask *pTask) {
|
||||||
|
// TODO
|
||||||
|
/*free(pTask->qmsg);*/
|
||||||
|
/*free(pTask->executor);*/
|
||||||
|
/*free(pTask);*/
|
||||||
|
}
|
||||||
|
|
|
@ -353,10 +353,10 @@ static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, i
|
||||||
for (int i = 0; i < src2->numOfCols; i++) {
|
for (int i = 0; i < src2->numOfCols; i++) {
|
||||||
SCellVal sVal = {0};
|
SCellVal sVal = {0};
|
||||||
ASSERT(target->cols[i].type == src2->cols[i].type);
|
ASSERT(target->cols[i].type == src2->cols[i].type);
|
||||||
if (src2->cols[i].len > 0 && !isNull(src2->cols[i].pData, src2->cols[i].type)) {
|
if (tdGetColDataOfRow(&sVal, src2->cols + i, *iter2) < 0) {
|
||||||
if (tdGetColDataOfRow(&sVal, src1->cols + i, *iter1) < 0) {
|
TASSERT(0);
|
||||||
TASSERT(0);
|
}
|
||||||
}
|
if (src2->cols[i].len > 0 && !tdValTypeIsNull(sVal.valType)) {
|
||||||
tdAppendValToDataCol(&(target->cols[i]), sVal.valType, sVal.val, target->numOfRows, target->maxPoints);
|
tdAppendValToDataCol(&(target->cols[i]), sVal.valType, sVal.val, target->numOfRows, target->maxPoints);
|
||||||
} else if (!forceSetNull && key1 == key2 && src1->cols[i].len > 0) {
|
} else if (!forceSetNull && key1 == key2 && src1->cols[i].len > 0) {
|
||||||
if (tdGetColDataOfRow(&sVal, src1->cols + i, *iter1) < 0) {
|
if (tdGetColDataOfRow(&sVal, src1->cols + i, *iter1) < 0) {
|
||||||
|
|
|
@ -845,7 +845,11 @@ int32_t tsBufMerge(STSBuf* pDestBuf, const STSBuf* pSrcBuf) {
|
||||||
|
|
||||||
int64_t offset = getDataStartOffset();
|
int64_t offset = getDataStartOffset();
|
||||||
int32_t size = (int32_t)pSrcBuf->fileSize - (int32_t)offset;
|
int32_t size = (int32_t)pSrcBuf->fileSize - (int32_t)offset;
|
||||||
|
#if defined(_TD_DARWIN_64)
|
||||||
|
int64_t written = taosFSendFile(pDestBuf->pFile->fp, pSrcBuf->pFile->fp, &offset, size);
|
||||||
|
#else
|
||||||
int64_t written = taosFSendFile(pDestBuf->pFile, pSrcBuf->pFile, &offset, size);
|
int64_t written = taosFSendFile(pDestBuf->pFile, pSrcBuf->pFile, &offset, size);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (written == -1 || written != size) {
|
if (written == -1 || written != size) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -323,8 +323,8 @@ int32_t dndProcessDropSnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dndProcessSnodeUniqueQueue(SDnode *pDnode, STaosQall *qall, int32_t numOfMsgs) {
|
static void dndProcessSnodeUniqueQueue(SDnode *pDnode, STaosQall *qall, int32_t numOfMsgs) {
|
||||||
SSnodeMgmt *pMgmt = &pDnode->smgmt;
|
/*SSnodeMgmt *pMgmt = &pDnode->smgmt;*/
|
||||||
int32_t code = TSDB_CODE_DND_SNODE_NOT_DEPLOYED;
|
int32_t code = TSDB_CODE_DND_SNODE_NOT_DEPLOYED;
|
||||||
|
|
||||||
SSnode *pSnode = dndAcquireSnode(pDnode);
|
SSnode *pSnode = dndAcquireSnode(pDnode);
|
||||||
if (pSnode != NULL) {
|
if (pSnode != NULL) {
|
||||||
|
@ -334,22 +334,35 @@ static void dndProcessSnodeUniqueQueue(SDnode *pDnode, STaosQall *qall, int32_t
|
||||||
|
|
||||||
sndProcessUMsg(pSnode, pMsg);
|
sndProcessUMsg(pSnode, pMsg);
|
||||||
|
|
||||||
|
rpcFreeCont(pMsg->pCont);
|
||||||
|
taosFreeQitem(pMsg);
|
||||||
|
}
|
||||||
|
dndReleaseSnode(pDnode, pSnode);
|
||||||
|
} else {
|
||||||
|
for (int32_t i = 0; i < numOfMsgs; i++) {
|
||||||
|
SRpcMsg *pMsg = NULL;
|
||||||
|
taosGetQitem(qall, (void **)&pMsg);
|
||||||
|
SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code};
|
||||||
|
rpcSendResponse(&rpcRsp);
|
||||||
|
|
||||||
rpcFreeCont(pMsg->pCont);
|
rpcFreeCont(pMsg->pCont);
|
||||||
taosFreeQitem(pMsg);
|
taosFreeQitem(pMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dndReleaseSnode(pDnode, pSnode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dndProcessSnodeSharedQueue(SDnode *pDnode, SRpcMsg *pMsg) {
|
static void dndProcessSnodeSharedQueue(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||||
SSnodeMgmt *pMgmt = &pDnode->smgmt;
|
/*SSnodeMgmt *pMgmt = &pDnode->smgmt;*/
|
||||||
int32_t code = TSDB_CODE_DND_SNODE_NOT_DEPLOYED;
|
int32_t code = TSDB_CODE_DND_SNODE_NOT_DEPLOYED;
|
||||||
|
|
||||||
SSnode *pSnode = dndAcquireSnode(pDnode);
|
SSnode *pSnode = dndAcquireSnode(pDnode);
|
||||||
if (pSnode != NULL) {
|
if (pSnode != NULL) {
|
||||||
code = sndProcessSMsg(pSnode, pMsg);
|
sndProcessSMsg(pSnode, pMsg);
|
||||||
|
dndReleaseSnode(pDnode, pSnode);
|
||||||
|
} else {
|
||||||
|
SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code};
|
||||||
|
rpcSendResponse(&rpcRsp);
|
||||||
}
|
}
|
||||||
dndReleaseSnode(pDnode, pSnode);
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
if (pMsg->msgType & 1u) {
|
if (pMsg->msgType & 1u) {
|
||||||
|
|
|
@ -85,6 +85,8 @@ typedef enum {
|
||||||
TRN_TYPE_REBALANCE = 1017,
|
TRN_TYPE_REBALANCE = 1017,
|
||||||
TRN_TYPE_COMMIT_OFFSET = 1018,
|
TRN_TYPE_COMMIT_OFFSET = 1018,
|
||||||
TRN_TYPE_CREATE_STREAM = 1019,
|
TRN_TYPE_CREATE_STREAM = 1019,
|
||||||
|
TRN_TYPE_DROP_STREAM = 1020,
|
||||||
|
TRN_TYPE_ALTER_STREAM = 1021,
|
||||||
TRN_TYPE_BASIC_SCOPE_END,
|
TRN_TYPE_BASIC_SCOPE_END,
|
||||||
TRN_TYPE_GLOBAL_SCOPE = 2000,
|
TRN_TYPE_GLOBAL_SCOPE = 2000,
|
||||||
TRN_TYPE_CREATE_DNODE = 2001,
|
TRN_TYPE_CREATE_DNODE = 2001,
|
||||||
|
@ -687,12 +689,14 @@ typedef struct {
|
||||||
int64_t uid;
|
int64_t uid;
|
||||||
int64_t dbUid;
|
int64_t dbUid;
|
||||||
int32_t version;
|
int32_t version;
|
||||||
|
int32_t vgNum;
|
||||||
SRWLatch lock;
|
SRWLatch lock;
|
||||||
int8_t status;
|
int8_t status;
|
||||||
// int32_t sqlLen;
|
// int32_t sqlLen;
|
||||||
char* sql;
|
char* sql;
|
||||||
char* logicalPlan;
|
char* logicalPlan;
|
||||||
char* physicalPlan;
|
char* physicalPlan;
|
||||||
|
SArray* tasks; // SArray<SArray<SStreamTask>>
|
||||||
} SStreamObj;
|
} SStreamObj;
|
||||||
|
|
||||||
int32_t tEncodeSStreamObj(SCoder* pEncoder, const SStreamObj* pObj);
|
int32_t tEncodeSStreamObj(SCoder* pEncoder, const SStreamObj* pObj);
|
||||||
|
|
|
@ -27,6 +27,8 @@ void mndCleanupScheduler(SMnode* pMnode);
|
||||||
|
|
||||||
int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscribeObj* pSub);
|
int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscribeObj* pSub);
|
||||||
|
|
||||||
|
int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -96,12 +96,12 @@ SSdbRaw *mndConsumerActionEncode(SMqConsumerObj *pConsumer) {
|
||||||
CM_ENCODE_OVER:
|
CM_ENCODE_OVER:
|
||||||
tfree(buf);
|
tfree(buf);
|
||||||
if (terrno != 0) {
|
if (terrno != 0) {
|
||||||
mError("consumer:%ld, failed to encode to raw:%p since %s", pConsumer->consumerId, pRaw, terrstr());
|
mError("consumer:%" PRId64 ", failed to encode to raw:%p since %s", pConsumer->consumerId, pRaw, terrstr());
|
||||||
sdbFreeRaw(pRaw);
|
sdbFreeRaw(pRaw);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
mTrace("consumer:%ld, encode to raw:%p, row:%p", pConsumer->consumerId, pRaw, pConsumer);
|
mTrace("consumer:%" PRId64 ", encode to raw:%p, row:%p", pConsumer->consumerId, pRaw, pConsumer);
|
||||||
return pRaw;
|
return pRaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw) {
|
||||||
CM_DECODE_OVER:
|
CM_DECODE_OVER:
|
||||||
tfree(buf);
|
tfree(buf);
|
||||||
if (terrno != TSDB_CODE_SUCCESS) {
|
if (terrno != TSDB_CODE_SUCCESS) {
|
||||||
mError("consumer:%ld, failed to decode from raw:%p since %s", pConsumer->consumerId, pRaw, terrstr());
|
mError("consumer:%" PRId64 ", failed to decode from raw:%p since %s", pConsumer->consumerId, pRaw, terrstr());
|
||||||
tfree(pRow);
|
tfree(pRow);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -149,17 +149,17 @@ CM_DECODE_OVER:
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndConsumerActionInsert(SSdb *pSdb, SMqConsumerObj *pConsumer) {
|
static int32_t mndConsumerActionInsert(SSdb *pSdb, SMqConsumerObj *pConsumer) {
|
||||||
mTrace("consumer:%ld, perform insert action", pConsumer->consumerId);
|
mTrace("consumer:%" PRId64 ", perform insert action", pConsumer->consumerId);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndConsumerActionDelete(SSdb *pSdb, SMqConsumerObj *pConsumer) {
|
static int32_t mndConsumerActionDelete(SSdb *pSdb, SMqConsumerObj *pConsumer) {
|
||||||
mTrace("consumer:%ld, perform delete action", pConsumer->consumerId);
|
mTrace("consumer:%" PRId64 ", perform delete action", pConsumer->consumerId);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer, SMqConsumerObj *pNewConsumer) {
|
static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer, SMqConsumerObj *pNewConsumer) {
|
||||||
mTrace("consumer:%ld, perform update action", pOldConsumer->consumerId);
|
mTrace("consumer:%" PRId64 ", perform update action", pOldConsumer->consumerId);
|
||||||
|
|
||||||
// TODO handle update
|
// TODO handle update
|
||||||
/*taosWLockLatch(&pOldConsumer->lock);*/
|
/*taosWLockLatch(&pOldConsumer->lock);*/
|
||||||
|
|
|
@ -39,8 +39,8 @@ int32_t tDecodeSStreamObj(SCoder *pDecoder, SStreamObj *pObj) {
|
||||||
if (tDecodeI64(pDecoder, &pObj->dbUid) < 0) return -1;
|
if (tDecodeI64(pDecoder, &pObj->dbUid) < 0) return -1;
|
||||||
if (tDecodeI32(pDecoder, &pObj->version) < 0) return -1;
|
if (tDecodeI32(pDecoder, &pObj->version) < 0) return -1;
|
||||||
if (tDecodeI8(pDecoder, &pObj->status) < 0) return -1;
|
if (tDecodeI8(pDecoder, &pObj->status) < 0) return -1;
|
||||||
if (tDecodeCStr(pDecoder, (const char **)&pObj->sql) < 0) return -1;
|
if (tDecodeCStrAlloc(pDecoder, &pObj->sql) < 0) return -1;
|
||||||
if (tDecodeCStr(pDecoder, (const char **)&pObj->logicalPlan) < 0) return -1;
|
if (tDecodeCStrAlloc(pDecoder, &pObj->logicalPlan) < 0) return -1;
|
||||||
if (tDecodeCStr(pDecoder, (const char **)&pObj->physicalPlan) < 0) return -1;
|
if (tDecodeCStrAlloc(pDecoder, &pObj->physicalPlan) < 0) return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "mndOffset.h"
|
#include "mndOffset.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
#include "mndStb.h"
|
#include "mndStb.h"
|
||||||
|
#include "mndStream.h"
|
||||||
#include "mndSubscribe.h"
|
#include "mndSubscribe.h"
|
||||||
#include "mndTopic.h"
|
#include "mndTopic.h"
|
||||||
#include "mndTrans.h"
|
#include "mndTrans.h"
|
||||||
|
@ -28,10 +29,103 @@
|
||||||
#include "mndVgroup.h"
|
#include "mndVgroup.h"
|
||||||
#include "tcompare.h"
|
#include "tcompare.h"
|
||||||
#include "tname.h"
|
#include "tname.h"
|
||||||
|
#include "tuuid.h"
|
||||||
|
|
||||||
|
int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
||||||
|
SSdb* pSdb = pMnode->pSdb;
|
||||||
|
SVgObj* pVgroup = NULL;
|
||||||
|
SQueryPlan* pPlan = qStringToQueryPlan(pStream->physicalPlan);
|
||||||
|
if (pPlan == NULL) {
|
||||||
|
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
ASSERT(pStream->vgNum == 0);
|
||||||
|
|
||||||
|
int32_t totLevel = LIST_LENGTH(pPlan->pSubplans);
|
||||||
|
pStream->tasks = taosArrayInit(totLevel, sizeof(SArray));
|
||||||
|
|
||||||
|
int32_t msgLen;
|
||||||
|
for (int32_t level = 0; level < totLevel; level++) {
|
||||||
|
SArray* taskOneLevel = taosArrayInit(0, sizeof(SStreamTask));
|
||||||
|
SNodeListNode* inner = nodesListGetNode(pPlan->pSubplans, level);
|
||||||
|
int32_t opNum = LIST_LENGTH(inner->pNodeList);
|
||||||
|
ASSERT(opNum == 1);
|
||||||
|
|
||||||
|
SSubplan* plan = nodesListGetNode(inner->pNodeList, level);
|
||||||
|
if (level == 0) {
|
||||||
|
ASSERT(plan->type == SUBPLAN_TYPE_SCAN);
|
||||||
|
void* pIter = NULL;
|
||||||
|
while (1) {
|
||||||
|
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void**)&pVgroup);
|
||||||
|
if (pIter == NULL) break;
|
||||||
|
if (pVgroup->dbUid != pStream->dbUid) {
|
||||||
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
pStream->vgNum++;
|
||||||
|
// send to vnode
|
||||||
|
|
||||||
|
SStreamTask* pTask = streamTaskNew(pStream->uid, level);
|
||||||
|
|
||||||
|
plan->execNode.nodeId = pVgroup->vgId;
|
||||||
|
plan->execNode.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||||
|
if (qSubPlanToString(plan, &pTask->qmsg, &msgLen) < 0) {
|
||||||
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
qDestroyQueryPlan(pPlan);
|
||||||
|
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
taosArrayPush(taskOneLevel, pTask);
|
||||||
|
}
|
||||||
|
} else if (plan->subplanType == SUBPLAN_TYPE_SCAN) {
|
||||||
|
// duplicatable
|
||||||
|
|
||||||
|
int32_t parallel = 0;
|
||||||
|
// if no snode, parallel set to fetch thread num in vnode
|
||||||
|
|
||||||
|
// if has snode, set to shared thread num in snode
|
||||||
|
parallel = SND_SHARED_THREAD_NUM;
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < parallel; i++) {
|
||||||
|
SStreamTask* pTask = streamTaskNew(pStream->uid, level);
|
||||||
|
|
||||||
|
// TODO:get snode id and ep
|
||||||
|
plan->execNode.nodeId = pVgroup->vgId;
|
||||||
|
plan->execNode.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||||
|
|
||||||
|
if (qSubPlanToString(plan, &pTask->qmsg, &msgLen) < 0) {
|
||||||
|
qDestroyQueryPlan(pPlan);
|
||||||
|
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
taosArrayPush(taskOneLevel, pTask);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// not duplicatable
|
||||||
|
SStreamTask* pTask = streamTaskNew(pStream->uid, level);
|
||||||
|
|
||||||
|
// TODO:get snode id and ep
|
||||||
|
plan->execNode.nodeId = pVgroup->vgId;
|
||||||
|
plan->execNode.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||||
|
|
||||||
|
if (qSubPlanToString(plan, &pTask->qmsg, &msgLen) < 0) {
|
||||||
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
qDestroyQueryPlan(pPlan);
|
||||||
|
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
taosArrayPush(taskOneLevel, pTask);
|
||||||
|
}
|
||||||
|
taosArrayPush(pStream->tasks, taskOneLevel);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscribeObj* pSub) {
|
int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscribeObj* pSub) {
|
||||||
SSdb* pSdb = pMnode->pSdb;
|
SSdb* pSdb = pMnode->pSdb;
|
||||||
SVgObj* pVgroup = NULL;
|
SVgObj* pVgroup = NULL;
|
||||||
SQueryPlan* pPlan = qStringToQueryPlan(pTopic->physicalPlan);
|
SQueryPlan* pPlan = qStringToQueryPlan(pTopic->physicalPlan);
|
||||||
if (pPlan == NULL) {
|
if (pPlan == NULL) {
|
||||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "mndDb.h"
|
#include "mndDb.h"
|
||||||
#include "mndDnode.h"
|
#include "mndDnode.h"
|
||||||
#include "mndMnode.h"
|
#include "mndMnode.h"
|
||||||
|
#include "mndScheduler.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
#include "mndStb.h"
|
#include "mndStb.h"
|
||||||
#include "mndTrans.h"
|
#include "mndTrans.h"
|
||||||
|
@ -237,6 +238,12 @@ static int32_t mndCreateStream(SMnode *pMnode, SMnodeMsg *pReq, SCMCreateStreamR
|
||||||
}
|
}
|
||||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY);
|
sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY);
|
||||||
|
|
||||||
|
if (mndScheduleStream(pMnode, pTrans, &streamObj) < 0) {
|
||||||
|
mError("stream:%ld, schedule stream since %s", streamObj.uid, terrstr());
|
||||||
|
mndTransDrop(pTrans);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
|
|
|
@ -448,7 +448,7 @@ static int32_t mndProcessDoRebalanceMsg(SMnodeMsg *pMsg) {
|
||||||
for (int32_t i = 0; i < taosArrayGetSize(pRebSub->lostConsumers); i++) {
|
for (int32_t i = 0; i < taosArrayGetSize(pRebSub->lostConsumers); i++) {
|
||||||
int64_t lostConsumerId = *(int64_t *)taosArrayGet(pRebSub->lostConsumers, i);
|
int64_t lostConsumerId = *(int64_t *)taosArrayGet(pRebSub->lostConsumers, i);
|
||||||
|
|
||||||
mInfo("mq remove lost consumer %ld", lostConsumerId);
|
mInfo("mq remove lost consumer %" PRId64 "", lostConsumerId);
|
||||||
|
|
||||||
for (int32_t j = 0; j < taosArrayGetSize(pSub->consumers); j++) {
|
for (int32_t j = 0; j < taosArrayGetSize(pSub->consumers); j++) {
|
||||||
SMqSubConsumer *pSubConsumer = taosArrayGet(pSub->consumers, j);
|
SMqSubConsumer *pSubConsumer = taosArrayGet(pSub->consumers, j);
|
||||||
|
@ -479,7 +479,7 @@ static int32_t mndProcessDoRebalanceMsg(SMnodeMsg *pMsg) {
|
||||||
else
|
else
|
||||||
vgThisConsumerAfterRb = vgEachConsumer;
|
vgThisConsumerAfterRb = vgEachConsumer;
|
||||||
|
|
||||||
mInfo("mq consumer:%ld, connectted vgroup number change from %d to %d", pSubConsumer->consumerId,
|
mInfo("mq consumer:%" PRId64 ", connectted vgroup number change from %d to %d", pSubConsumer->consumerId,
|
||||||
vgThisConsumerBeforeRb, vgThisConsumerAfterRb);
|
vgThisConsumerBeforeRb, vgThisConsumerAfterRb);
|
||||||
|
|
||||||
while (taosArrayGetSize(pSubConsumer->vgInfo) > vgThisConsumerAfterRb) {
|
while (taosArrayGetSize(pSubConsumer->vgInfo) > vgThisConsumerAfterRb) {
|
||||||
|
@ -503,7 +503,7 @@ static int32_t mndProcessDoRebalanceMsg(SMnodeMsg *pMsg) {
|
||||||
atomic_store_32(&pRebConsumer->status, MQ_CONSUMER_STATUS__IDLE);
|
atomic_store_32(&pRebConsumer->status, MQ_CONSUMER_STATUS__IDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
mInfo("mq consumer:%ld, status change from %d to %d", pRebConsumer->consumerId, status, pRebConsumer->status);
|
mInfo("mq consumer:%" PRId64 ", status change from %d to %d", pRebConsumer->consumerId, status, pRebConsumer->status);
|
||||||
|
|
||||||
SSdbRaw *pConsumerRaw = mndConsumerActionEncode(pRebConsumer);
|
SSdbRaw *pConsumerRaw = mndConsumerActionEncode(pRebConsumer);
|
||||||
sdbSetRawStatus(pConsumerRaw, SDB_STATUS_READY);
|
sdbSetRawStatus(pConsumerRaw, SDB_STATUS_READY);
|
||||||
|
@ -537,13 +537,13 @@ static int32_t mndProcessDoRebalanceMsg(SMnodeMsg *pMsg) {
|
||||||
mndSplitSubscribeKey(pSub->key, topic, cgroup);
|
mndSplitSubscribeKey(pSub->key, topic, cgroup);
|
||||||
SMqTopicObj *pTopic = mndAcquireTopic(pMnode, topic);
|
SMqTopicObj *pTopic = mndAcquireTopic(pMnode, topic);
|
||||||
|
|
||||||
mInfo("mq set conn: assign vgroup %d of topic %s to consumer %ld", pConsumerEp->vgId, topic,
|
mInfo("mq set conn: assign vgroup %d of topic %s to consumer %" PRId64 "", pConsumerEp->vgId, topic,
|
||||||
pConsumerEp->consumerId);
|
pConsumerEp->consumerId);
|
||||||
|
|
||||||
mndPersistMqSetConnReq(pMnode, pTrans, pTopic, cgroup, pConsumerEp);
|
mndPersistMqSetConnReq(pMnode, pTrans, pTopic, cgroup, pConsumerEp);
|
||||||
mndReleaseTopic(pMnode, pTopic);
|
mndReleaseTopic(pMnode, pTopic);
|
||||||
} else {
|
} else {
|
||||||
mInfo("mq rebalance: assign vgroup %d, from consumer %ld to consumer %ld", pConsumerEp->vgId,
|
mInfo("mq rebalance: assign vgroup %d, from consumer %" PRId64 " to consumer %" PRId64 "", pConsumerEp->vgId,
|
||||||
pConsumerEp->oldConsumerId, pConsumerEp->consumerId);
|
pConsumerEp->oldConsumerId, pConsumerEp->consumerId);
|
||||||
|
|
||||||
mndPersistRebalanceMsg(pMnode, pTrans, pConsumerEp);
|
mndPersistRebalanceMsg(pMnode, pTrans, pConsumerEp);
|
||||||
|
@ -1099,7 +1099,7 @@ static int32_t mndProcessSubscribeReq(SMnodeMsg *pMsg) {
|
||||||
SMqSubscribeObj *pSub = mndAcquireSubscribe(pMnode, cgroup, newTopicName);
|
SMqSubscribeObj *pSub = mndAcquireSubscribe(pMnode, cgroup, newTopicName);
|
||||||
bool createSub = false;
|
bool createSub = false;
|
||||||
if (pSub == NULL) {
|
if (pSub == NULL) {
|
||||||
mDebug("create new subscription by consumer %ld, group: %s, topic %s", consumerId, cgroup, newTopicName);
|
mDebug("create new subscription by consumer %" PRId64 ", group: %s, topic %s", consumerId, cgroup, newTopicName);
|
||||||
pSub = mndCreateSubscription(pMnode, pTopic, cgroup);
|
pSub = mndCreateSubscription(pMnode, pTopic, cgroup);
|
||||||
createSub = true;
|
createSub = true;
|
||||||
|
|
||||||
|
@ -1118,7 +1118,7 @@ static int32_t mndProcessSubscribeReq(SMnodeMsg *pMsg) {
|
||||||
pConsumerEp->consumerId = consumerId;
|
pConsumerEp->consumerId = consumerId;
|
||||||
taosArrayPush(mqSubConsumer.vgInfo, pConsumerEp);
|
taosArrayPush(mqSubConsumer.vgInfo, pConsumerEp);
|
||||||
if (pConsumerEp->oldConsumerId == -1) {
|
if (pConsumerEp->oldConsumerId == -1) {
|
||||||
mInfo("mq set conn: assign vgroup %d of topic %s to consumer %ld", pConsumerEp->vgId, newTopicName,
|
mInfo("mq set conn: assign vgroup %d of topic %s to consumer %" PRId64 "", pConsumerEp->vgId, newTopicName,
|
||||||
pConsumerEp->consumerId);
|
pConsumerEp->consumerId);
|
||||||
mndPersistMqSetConnReq(pMnode, pTrans, pTopic, cgroup, pConsumerEp);
|
mndPersistMqSetConnReq(pMnode, pTrans, pTopic, cgroup, pConsumerEp);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -236,6 +236,29 @@ static int32_t mndCheckCreateTopicReq(SCMCreateTopicReq *pCreate) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t mndGetPlanString(SCMCreateTopicReq *pCreate, char **pStr) {
|
||||||
|
if (NULL == pCreate->ast) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNode* pAst = NULL;
|
||||||
|
int32_t code = nodesStringToNode(pCreate->ast, &pAst);
|
||||||
|
|
||||||
|
SQueryPlan* pPlan = NULL;
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
SPlanContext cxt = { .pAstRoot = pAst, .streamQuery = true };
|
||||||
|
code = qCreateQueryPlan(&cxt, &pPlan, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = nodesNodeToString(pPlan, false, pStr, NULL);
|
||||||
|
}
|
||||||
|
nodesDestroyNode(pAst);
|
||||||
|
nodesDestroyNode(pPlan);
|
||||||
|
terrno = code;
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t mndCreateTopic(SMnode *pMnode, SMnodeMsg *pReq, SCMCreateTopicReq *pCreate, SDbObj *pDb) {
|
static int32_t mndCreateTopic(SMnode *pMnode, SMnodeMsg *pReq, SCMCreateTopicReq *pCreate, SDbObj *pDb) {
|
||||||
mDebug("topic:%s to create", pCreate->name);
|
mDebug("topic:%s to create", pCreate->name);
|
||||||
SMqTopicObj topicObj = {0};
|
SMqTopicObj topicObj = {0};
|
||||||
|
@ -247,13 +270,23 @@ static int32_t mndCreateTopic(SMnode *pMnode, SMnodeMsg *pReq, SCMCreateTopicReq
|
||||||
topicObj.dbUid = pDb->uid;
|
topicObj.dbUid = pDb->uid;
|
||||||
topicObj.version = 1;
|
topicObj.version = 1;
|
||||||
topicObj.sql = pCreate->sql;
|
topicObj.sql = pCreate->sql;
|
||||||
topicObj.physicalPlan = pCreate->physicalPlan;
|
topicObj.physicalPlan = "";
|
||||||
topicObj.logicalPlan = pCreate->logicalPlan;
|
topicObj.logicalPlan = "";
|
||||||
topicObj.sqlLen = strlen(pCreate->sql);
|
topicObj.sqlLen = strlen(pCreate->sql);
|
||||||
|
|
||||||
|
char* pPlanStr = NULL;
|
||||||
|
if (TSDB_CODE_SUCCESS != mndGetPlanString(pCreate, &pPlanStr)) {
|
||||||
|
mError("topic:%s, failed to get plan since %s", pCreate->name, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (NULL != pPlanStr) {
|
||||||
|
topicObj.physicalPlan = pPlanStr;
|
||||||
|
}
|
||||||
|
|
||||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_TOPIC, &pReq->rpcMsg);
|
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_TOPIC, &pReq->rpcMsg);
|
||||||
if (pTrans == NULL) {
|
if (pTrans == NULL) {
|
||||||
mError("topic:%s, failed to create since %s", pCreate->name, terrstr());
|
mError("topic:%s, failed to create since %s", pCreate->name, terrstr());
|
||||||
|
tfree(pPlanStr);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
mDebug("trans:%d, used to create topic:%s", pTrans->id, pCreate->name);
|
mDebug("trans:%d, used to create topic:%s", pTrans->id, pCreate->name);
|
||||||
|
@ -261,6 +294,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SMnodeMsg *pReq, SCMCreateTopicReq
|
||||||
SSdbRaw *pRedoRaw = mndTopicActionEncode(&topicObj);
|
SSdbRaw *pRedoRaw = mndTopicActionEncode(&topicObj);
|
||||||
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) {
|
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) {
|
||||||
mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr());
|
mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr());
|
||||||
|
tfree(pPlanStr);
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -268,10 +302,12 @@ static int32_t mndCreateTopic(SMnode *pMnode, SMnodeMsg *pReq, SCMCreateTopicReq
|
||||||
|
|
||||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||||
|
tfree(pPlanStr);
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tfree(pPlanStr);
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,8 +65,7 @@ void* MndTestTopic::BuildCreateTopicReq(const char* topicName, const char* sql,
|
||||||
strcpy(createReq.name, topicName);
|
strcpy(createReq.name, topicName);
|
||||||
createReq.igExists = 0;
|
createReq.igExists = 0;
|
||||||
createReq.sql = (char*)sql;
|
createReq.sql = (char*)sql;
|
||||||
createReq.physicalPlan = (char*)"physicalPlan";
|
createReq.ast = NULL;
|
||||||
createReq.logicalPlan = (char*)"logicalPlan";
|
|
||||||
|
|
||||||
int32_t contLen = tSerializeSCMCreateTopicReq(NULL, 0, &createReq);
|
int32_t contLen = tSerializeSCMCreateTopicReq(NULL, 0, &createReq);
|
||||||
void* pReq = rpcMallocCont(contLen);
|
void* pReq = rpcMallocCont(contLen);
|
||||||
|
|
|
@ -196,7 +196,7 @@ int32_t sdbReadFile(SSdb *pSdb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t totalLen = sizeof(SSdbRaw) + pRaw->dataLen + sizeof(int32_t);
|
int32_t totalLen = sizeof(SSdbRaw) + pRaw->dataLen + sizeof(int32_t);
|
||||||
if (!taosCheckChecksumWhole((const uint8_t *)pRaw, totalLen) != 0) {
|
if ((!taosCheckChecksumWhole((const uint8_t *)pRaw, totalLen)) != 0) {
|
||||||
code = TSDB_CODE_CHECKSUM_ERROR;
|
code = TSDB_CODE_CHECKSUM_ERROR;
|
||||||
mError("failed to read file:%s since %s", file, tstrerror(code));
|
mError("failed to read file:%s since %s", file, tstrerror(code));
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -7,8 +7,9 @@ target_include_directories(
|
||||||
)
|
)
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
snode
|
snode
|
||||||
|
PRIVATE executor
|
||||||
PRIVATE transport
|
PRIVATE transport
|
||||||
PRIVATE os
|
PRIVATE os
|
||||||
PRIVATE common
|
PRIVATE common
|
||||||
PRIVATE util
|
PRIVATE util
|
||||||
)
|
)
|
||||||
|
|
|
@ -38,13 +38,8 @@ enum {
|
||||||
STREAM_STATUS__DELETING,
|
STREAM_STATUS__DELETING,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
|
||||||
STREAM_TASK_STATUS__RUNNING = 1,
|
|
||||||
STREAM_TASK_STATUS__STOP,
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SHashObj* pHash; // taskId -> streamTask
|
SHashObj* pHash; // taskId -> SStreamTask
|
||||||
} SStreamMeta;
|
} SStreamMeta;
|
||||||
|
|
||||||
typedef struct SSnode {
|
typedef struct SSnode {
|
||||||
|
@ -52,26 +47,17 @@ typedef struct SSnode {
|
||||||
SSnodeOpt cfg;
|
SSnodeOpt cfg;
|
||||||
} SSnode;
|
} SSnode;
|
||||||
|
|
||||||
typedef struct {
|
SStreamMeta* sndMetaNew();
|
||||||
int64_t streamId;
|
void sndMetaDelete(SStreamMeta* pMeta);
|
||||||
int32_t taskId;
|
|
||||||
int32_t IdxInLevel;
|
|
||||||
int32_t level;
|
|
||||||
} SStreamTaskInfo;
|
|
||||||
|
|
||||||
typedef struct {
|
int32_t sndMetaDeployTask(SStreamMeta* pMeta, SStreamTask* pTask);
|
||||||
SStreamTaskInfo meta;
|
SStreamTask* sndMetaGetTask(SStreamMeta* pMeta, int32_t taskId);
|
||||||
int8_t status;
|
int32_t sndMetaRemoveTask(SStreamMeta* pMeta, int32_t taskId);
|
||||||
void* executor;
|
|
||||||
void* stateStore;
|
|
||||||
// storage handle
|
|
||||||
} SStreamTask;
|
|
||||||
|
|
||||||
int32_t sndCreateStream();
|
int32_t sndDropTaskOfStream(SStreamMeta* pMeta, int64_t streamId);
|
||||||
int32_t sndDropStream();
|
|
||||||
|
|
||||||
int32_t sndStopStream();
|
int32_t sndStopTaskOfStream(SStreamMeta* pMeta, int64_t streamId);
|
||||||
int32_t sndResumeStream();
|
int32_t sndResumeTaskOfStream(SStreamMeta* pMeta, int64_t streamId);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,44 +13,116 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "executor.h"
|
||||||
#include "sndInt.h"
|
#include "sndInt.h"
|
||||||
#include "tuuid.h"
|
#include "tuuid.h"
|
||||||
|
|
||||||
SSnode *sndOpen(const char *path, const SSnodeOpt *pOption) {
|
SSnode *sndOpen(const char *path, const SSnodeOpt *pOption) {
|
||||||
SSnode *pSnode = calloc(1, sizeof(SSnode));
|
SSnode *pSnode = calloc(1, sizeof(SSnode));
|
||||||
|
if (pSnode == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
memcpy(&pSnode->cfg, pOption, sizeof(SSnodeOpt));
|
memcpy(&pSnode->cfg, pOption, sizeof(SSnodeOpt));
|
||||||
|
pSnode->pMeta = sndMetaNew();
|
||||||
|
if (pSnode->pMeta == NULL) {
|
||||||
|
free(pSnode);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return pSnode;
|
return pSnode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sndClose(SSnode *pSnode) { free(pSnode); }
|
void sndClose(SSnode *pSnode) {
|
||||||
|
sndMetaDelete(pSnode->pMeta);
|
||||||
|
free(pSnode);
|
||||||
|
}
|
||||||
|
|
||||||
int32_t sndGetLoad(SSnode *pSnode, SSnodeLoad *pLoad) { return 0; }
|
int32_t sndGetLoad(SSnode *pSnode, SSnodeLoad *pLoad) { return 0; }
|
||||||
|
|
||||||
int32_t sndProcessMsg(SSnode *pSnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
/*int32_t sndProcessMsg(SSnode *pSnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {*/
|
||||||
*pRsp = NULL;
|
/**pRsp = NULL;*/
|
||||||
return 0;
|
/*return 0;*/
|
||||||
}
|
/*}*/
|
||||||
|
|
||||||
void sndDestroy(const char *path) {}
|
void sndDestroy(const char *path) {}
|
||||||
|
|
||||||
static int32_t sndDeployTask(SSnode *pSnode, SRpcMsg *pMsg) {
|
SStreamMeta *sndMetaNew() {
|
||||||
SStreamTask *task = malloc(sizeof(SStreamTask));
|
SStreamMeta *pMeta = calloc(1, sizeof(SStreamMeta));
|
||||||
if (task == NULL) {
|
if (pMeta == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
pMeta->pHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||||
|
if (pMeta->pHash == NULL) {
|
||||||
|
free(pMeta);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return pMeta;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sndMetaDelete(SStreamMeta *pMeta) {
|
||||||
|
taosHashCleanup(pMeta->pHash);
|
||||||
|
free(pMeta);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t sndMetaDeployTask(SStreamMeta *pMeta, SStreamTask *pTask) {
|
||||||
|
pTask->executor = qCreateStreamExecTaskInfo(pTask->qmsg, NULL);
|
||||||
|
return taosHashPut(pMeta->pHash, &pTask->taskId, sizeof(int32_t), pTask, sizeof(void *));
|
||||||
|
}
|
||||||
|
|
||||||
|
SStreamTask *sndMetaGetTask(SStreamMeta *pMeta, int32_t taskId) {
|
||||||
|
return taosHashGet(pMeta->pHash, &taskId, sizeof(int32_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t sndMetaRemoveTask(SStreamMeta *pMeta, int32_t taskId) {
|
||||||
|
SStreamTask *pTask = taosHashGet(pMeta->pHash, &taskId, sizeof(int32_t));
|
||||||
|
if (pTask == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
free(pTask->qmsg);
|
||||||
|
// TODO:free executor
|
||||||
|
free(pTask);
|
||||||
|
return taosHashRemove(pMeta->pHash, &taskId, sizeof(int32_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t sndProcessTaskExecReq(SSnode *pSnode, SRpcMsg *pMsg) {
|
||||||
|
SMsgHead *pHead = pMsg->pCont;
|
||||||
|
int32_t taskId = pHead->streamTaskId;
|
||||||
|
SStreamTask *pTask = sndMetaGetTask(pSnode->pMeta, taskId);
|
||||||
|
if (pTask == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
task->meta.taskId = tGenIdPI32();
|
|
||||||
taosHashPut(pSnode->pMeta->pHash, &task->meta.taskId, sizeof(int32_t), &task, sizeof(void *));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg) {
|
int32_t sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg) {
|
||||||
// stream deployment
|
// stream deploy
|
||||||
// stream stop/resume
|
// stream stop/resume
|
||||||
// operator exec
|
// operator exec
|
||||||
|
if (pMsg->msgType == TDMT_SND_TASK_DEPLOY) {
|
||||||
|
void *msg = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
|
||||||
|
SStreamTask *pTask = malloc(sizeof(SStreamTask));
|
||||||
|
if (pTask == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
SCoder decoder;
|
||||||
|
tCoderInit(&decoder, TD_LITTLE_ENDIAN, msg, pMsg->contLen - sizeof(SMsgHead), TD_DECODER);
|
||||||
|
tDecodeSStreamTask(&decoder, pTask);
|
||||||
|
tCoderClear(&decoder);
|
||||||
|
|
||||||
|
sndMetaDeployTask(pSnode->pMeta, pTask);
|
||||||
|
} else if (pMsg->msgType == TDMT_SND_TASK_EXEC) {
|
||||||
|
sndProcessTaskExecReq(pSnode, pMsg);
|
||||||
|
} else {
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sndProcessSMsg(SSnode *pSnode, SRpcMsg *pMsg) {
|
int32_t sndProcessSMsg(SSnode *pSnode, SRpcMsg *pMsg) {
|
||||||
// operator exec
|
// operator exec
|
||||||
|
if (pMsg->msgType == TDMT_SND_TASK_EXEC) {
|
||||||
|
sndProcessTaskExecReq(pSnode, pMsg);
|
||||||
|
} else {
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,10 +107,8 @@ int32_t tsdbUpdateSmaWindow(STsdb *pTsdb, int8_t smaType, char *msg);
|
||||||
int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg);
|
int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg);
|
||||||
|
|
||||||
// TODO: This is the basic params, and should wrap the params to a queryHandle.
|
// TODO: This is the basic params, and should wrap the params to a queryHandle.
|
||||||
int32_t tsdbGetTSmaData(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval,
|
int32_t tsdbGetTSmaData(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval, int8_t intervalUnit,
|
||||||
int8_t intervalUnit, tb_uid_t tableUid, col_id_t colId, TSKEY querySkey,
|
tb_uid_t tableUid, col_id_t colId, TSKEY querySKey, int32_t nMaxResult);
|
||||||
int32_t nMaxResult);
|
|
||||||
|
|
||||||
|
|
||||||
// STsdbCfg
|
// STsdbCfg
|
||||||
int tsdbOptionsInit(STsdbCfg *);
|
int tsdbOptionsInit(STsdbCfg *);
|
||||||
|
|
|
@ -60,10 +60,11 @@ struct STsdb {
|
||||||
SSmaEnv * pRSmaEnv;
|
SSmaEnv * pRSmaEnv;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define REPO_ID(r) ((r)->vgId)
|
#define REPO_ID(r) ((r)->vgId)
|
||||||
#define REPO_CFG(r) (&(r)->config)
|
#define REPO_CFG(r) (&(r)->config)
|
||||||
#define REPO_FS(r) (r)->fs
|
#define REPO_FS(r) (r)->fs
|
||||||
#define IS_REPO_LOCKED(r) (r)->repoLocked
|
#define IS_REPO_LOCKED(r) (r)->repoLocked
|
||||||
|
#define REPO_SMA_ENV(r, t) ((TSDB_SMA_TYPE_ROLLUP == (t)) ? (r)->pRSmaEnv : (r)->pTSmaEnv)
|
||||||
|
|
||||||
int tsdbLockRepo(STsdb *pTsdb);
|
int tsdbLockRepo(STsdb *pTsdb);
|
||||||
int tsdbUnlockRepo(STsdb *pTsdb);
|
int tsdbUnlockRepo(STsdb *pTsdb);
|
||||||
|
|
|
@ -636,7 +636,7 @@ STSma *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode
|
// Decode
|
||||||
pCfg = (STSma *)malloc(sizeof(STSma));
|
pCfg = (STSma *)calloc(1, sizeof(STSma));
|
||||||
if (pCfg == NULL) {
|
if (pCfg == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,8 +68,8 @@ int32_t tsdbOpenBDBEnv(DB_ENV **ppEnv, const char *path) {
|
||||||
|
|
||||||
ret = pEnv->open(pEnv, path, DB_CREATE | DB_INIT_CDB | DB_INIT_MPOOL, 0);
|
ret = pEnv->open(pEnv, path, DB_CREATE | DB_INIT_CDB | DB_INIT_MPOOL, 0);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
// BDB_PERR("Failed to open tsdb env", ret);
|
terrno = TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR;
|
||||||
tsdbWarn("Failed to open tsdb env for path %s since %d", path ? path : "NULL", ret);
|
tsdbWarn("Failed to open tsdb env for path %s since ret %d != 0", path ? path : "NULL", ret);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,8 @@ static const char *TSDB_FNAME_SUFFIX[] = {
|
||||||
"smal", // TSDB_FILE_SMAL
|
"smal", // TSDB_FILE_SMAL
|
||||||
"", // TSDB_FILE_MAX
|
"", // TSDB_FILE_MAX
|
||||||
"meta", // TSDB_FILE_META
|
"meta", // TSDB_FILE_META
|
||||||
"sma", // TSDB_FILE_TSMA(directory name)
|
"tsma", // TSDB_FILE_TSMA
|
||||||
"sma", // TSDB_FILE_RSMA(directory name)
|
"rsma", // TSDB_FILE_RSMA
|
||||||
};
|
};
|
||||||
|
|
||||||
static void tsdbGetFilename(int vid, int fid, uint32_t ver, TSDB_FILE_T ftype, char *fname);
|
static void tsdbGetFilename(int vid, int fid, uint32_t ver, TSDB_FILE_T ftype, char *fname);
|
||||||
|
|
|
@ -15,9 +15,15 @@
|
||||||
|
|
||||||
#include "tsdbDef.h"
|
#include "tsdbDef.h"
|
||||||
|
|
||||||
|
static const char *TSDB_SMA_DNAME[] = {
|
||||||
|
"", // TSDB_SMA_TYPE_BLOCK
|
||||||
|
"tsma", // TSDB_SMA_TYPE_TIME_RANGE
|
||||||
|
"rsma", // TSDB_SMA_TYPE_ROLLUP
|
||||||
|
};
|
||||||
|
#define SMA_CHECK_HASH
|
||||||
#undef SMA_PRINT_DEBUG_LOG
|
#undef SMA_PRINT_DEBUG_LOG
|
||||||
#define SMA_STORAGE_TSDB_DAYS 30
|
#define SMA_STORAGE_TSDB_DAYS 30
|
||||||
#define SMA_STORAGE_TSDB_TIMES 30
|
#define SMA_STORAGE_TSDB_TIMES 10
|
||||||
#define SMA_STORAGE_SPLIT_HOURS 24
|
#define SMA_STORAGE_SPLIT_HOURS 24
|
||||||
#define SMA_KEY_LEN 18 // tableUid_colId_TSKEY 8+2+8
|
#define SMA_KEY_LEN 18 // tableUid_colId_TSKEY 8+2+8
|
||||||
|
|
||||||
|
@ -66,33 +72,46 @@ typedef struct {
|
||||||
|
|
||||||
struct SSmaStat {
|
struct SSmaStat {
|
||||||
SHashObj *smaStatItems; // key: indexName, value: SSmaStatItem
|
SHashObj *smaStatItems; // key: indexName, value: SSmaStatItem
|
||||||
|
T_REF_DECLARE()
|
||||||
};
|
};
|
||||||
|
|
||||||
// declaration of static functions
|
// declaration of static functions
|
||||||
static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg);
|
// expired window
|
||||||
static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg);
|
static int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, ETsdbSmaType smaType, char *msg);
|
||||||
// TODO: This is the basic params, and should wrap the params to a queryHandle.
|
|
||||||
static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval,
|
|
||||||
int8_t intervalUnit, tb_uid_t tableUid, col_id_t colId, TSKEY querySkey,
|
|
||||||
int32_t nMaxResult);
|
|
||||||
static int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, int8_t smaType, char *msg);
|
|
||||||
|
|
||||||
static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat);
|
static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat);
|
||||||
static int32_t tsdbDestroySmaState(SSmaStat *pSmaStat);
|
static int32_t tsdbDestroySmaState(SSmaStat *pSmaStat);
|
||||||
static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path);
|
static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path);
|
||||||
static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SSmaEnv **pEnv);
|
static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SSmaEnv **pEnv);
|
||||||
static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, STSmaDataWrapper *pData);
|
static int32_t tsdbResetExpiredWindow(STsdb *pTsdb, SSmaStat *pStat, int64_t indexUid, TSKEY skey);
|
||||||
static void tsdbDestroyTSmaWriteH(STSmaWriteH *pSmaH);
|
static int32_t tsdbRefSmaStat(STsdb *pTsdb, SSmaStat *pStat);
|
||||||
static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, int64_t interval, int8_t intervalUnit);
|
static int32_t tsdbUnRefSmaStat(STsdb *pTsdb, SSmaStat *pStat);
|
||||||
static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit);
|
|
||||||
static int32_t tsdbInsertTSmaDataSection(STSmaWriteH *pSmaH, STSmaDataWrapper *pData);
|
|
||||||
static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, uint32_t keyLen, void *pData, uint32_t dataLen);
|
|
||||||
|
|
||||||
|
// read data
|
||||||
|
// TODO: This is the basic params, and should wrap the params to a queryHandle.
|
||||||
|
static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval,
|
||||||
|
int8_t intervalUnit, tb_uid_t tableUid, col_id_t colId, TSKEY querySKey,
|
||||||
|
int32_t nMaxResult);
|
||||||
|
|
||||||
|
// insert data
|
||||||
|
static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, STSmaDataWrapper *pData);
|
||||||
|
static void tsdbDestroyTSmaWriteH(STSmaWriteH *pSmaH);
|
||||||
|
static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, int64_t interval, int8_t intervalUnit);
|
||||||
|
static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit);
|
||||||
|
static int32_t tsdbInsertTSmaDataSection(STSmaWriteH *pSmaH, STSmaDataWrapper *pData);
|
||||||
|
static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, uint32_t keyLen, void *pData, uint32_t dataLen);
|
||||||
static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit, int8_t precision);
|
static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit, int8_t precision);
|
||||||
static int32_t tsdbGetTSmaDays(STsdb *pTsdb, int64_t interval, int32_t storageLevel);
|
static int32_t tsdbGetTSmaDays(STsdb *pTsdb, int64_t interval, int32_t storageLevel);
|
||||||
static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData, int32_t storageLevel, int32_t fid);
|
static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData, int32_t storageLevel, int32_t fid);
|
||||||
static int32_t tsdbInitTSmaFile(STSmaReadH *pSmaH, TSKEY skey);
|
static int32_t tsdbInitTSmaFile(STSmaReadH *pSmaH, TSKEY skey);
|
||||||
static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey);
|
static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey);
|
||||||
|
static void tsdbGetSmaDir(int32_t vgId, ETsdbSmaType smaType, char dirName[]);
|
||||||
|
static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg);
|
||||||
|
static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg);
|
||||||
|
|
||||||
|
// implementation
|
||||||
|
static void tsdbGetSmaDir(int32_t vgId, ETsdbSmaType smaType, char dirName[]) {
|
||||||
|
snprintf(dirName, TSDB_FILENAME_LEN, "vnode/vnode%d/tsdb/%s", vgId, TSDB_SMA_DNAME[smaType]);
|
||||||
|
}
|
||||||
|
|
||||||
static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path) {
|
static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path) {
|
||||||
SSmaEnv *pEnv = NULL;
|
SSmaEnv *pEnv = NULL;
|
||||||
|
@ -136,7 +155,7 @@ static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SSmaEnv **pEnv) {
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pEnv && *pEnv) {
|
if (*pEnv) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +163,7 @@ static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SSmaEnv **pEnv) {
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*pEnv == NULL) {
|
if (*pEnv == NULL) { // 2nd phase check
|
||||||
if ((*pEnv = tsdbNewSmaEnv(pTsdb, path)) == NULL) {
|
if ((*pEnv = tsdbNewSmaEnv(pTsdb, path)) == NULL) {
|
||||||
tsdbUnlockRepo(pTsdb);
|
tsdbUnlockRepo(pTsdb);
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
|
@ -152,7 +171,7 @@ static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SSmaEnv **pEnv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tsdbUnlockRepo(pTsdb) != 0) {
|
if (tsdbUnlockRepo(pTsdb) != 0) {
|
||||||
tsdbFreeSmaEnv(*pEnv);
|
*pEnv = tsdbFreeSmaEnv(*pEnv);
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,6 +200,21 @@ void *tsdbFreeSmaEnv(SSmaEnv *pSmaEnv) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t tsdbRefSmaStat(STsdb *pTsdb, SSmaStat *pStat) {
|
||||||
|
if (pStat == NULL) return 0;
|
||||||
|
int ref = T_REF_INC(pStat);
|
||||||
|
tsdbDebug("vgId:%d ref sma stat %p ref %d", REPO_ID(pTsdb), pStat, ref);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tsdbUnRefSmaStat(STsdb *pTsdb, SSmaStat *pStat) {
|
||||||
|
if (pStat == NULL) return 0;
|
||||||
|
|
||||||
|
int ref = T_REF_DEC(pStat);
|
||||||
|
tsdbDebug("vgId:%d unref sma stat %p ref %d", REPO_ID(pTsdb), pStat, ref);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat) {
|
static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat) {
|
||||||
ASSERT(pSmaStat != NULL);
|
ASSERT(pSmaStat != NULL);
|
||||||
|
|
||||||
|
@ -244,6 +278,39 @@ int32_t tsdbDestroySmaState(SSmaStat *pSmaStat) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
|
||||||
|
switch (smaType) {
|
||||||
|
case TSDB_SMA_TYPE_TIME_RANGE:
|
||||||
|
if (pTsdb->pTSmaEnv) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TSDB_SMA_TYPE_ROLLUP:
|
||||||
|
if (pTsdb->pRSmaEnv) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
// SDiskID did = {0};
|
||||||
|
SSmaEnv *pEnv = NULL;
|
||||||
|
char smaPath[TSDB_FILENAME_LEN] = "/proj/.sma/";
|
||||||
|
if (tsdbInitSmaEnv(pTsdb, smaPath, &pEnv) != TSDB_CODE_SUCCESS) {
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (smaType == TSDB_SMA_TYPE_TIME_RANGE) {
|
||||||
|
pTsdb->pTSmaEnv = pEnv;
|
||||||
|
} else {
|
||||||
|
pTsdb->pRSmaEnv = pEnv;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Update expired window according to msg from stream computing module.
|
* @brief Update expired window according to msg from stream computing module.
|
||||||
*
|
*
|
||||||
|
@ -252,47 +319,39 @@ int32_t tsdbDestroySmaState(SSmaStat *pSmaStat) {
|
||||||
* @param msg
|
* @param msg
|
||||||
* @return int32_t
|
* @return int32_t
|
||||||
*/
|
*/
|
||||||
int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, int8_t smaType, char *msg) {
|
int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, ETsdbSmaType smaType, char *msg) {
|
||||||
STsdbCfg *pCfg = REPO_CFG(pTsdb);
|
|
||||||
SSmaEnv * pEnv = NULL;
|
|
||||||
|
|
||||||
if (!msg || !pTsdb->pMeta) {
|
if (!msg || !pTsdb->pMeta) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
terrno = TSDB_CODE_INVALID_PTR;
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
char smaPath[TSDB_FILENAME_LEN] = "/proj/.sma/";
|
if (tsdbCheckAndInitSmaEnv(pTsdb, smaType) != TSDB_CODE_SUCCESS) {
|
||||||
if (tsdbInitSmaEnv(pTsdb, smaPath, &pEnv) != TSDB_CODE_SUCCESS) {
|
terrno = TSDB_CODE_TDB_INIT_FAILED;
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (smaType == TSDB_SMA_TYPE_TIME_RANGE) {
|
// TODO: decode the msg from Stream Computing module => start
|
||||||
pTsdb->pTSmaEnv = pEnv;
|
int64_t indexUid = SMA_TEST_INDEX_UID;
|
||||||
} else if (smaType == TSDB_SMA_TYPE_ROLLUP) {
|
|
||||||
pTsdb->pRSmaEnv = pEnv;
|
|
||||||
} else {
|
|
||||||
ASSERT(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: decode the msg => start
|
|
||||||
int64_t indexUid = SMA_TEST_INDEX_UID;
|
|
||||||
// const char * indexName = SMA_TEST_INDEX_NAME;
|
|
||||||
const int32_t SMA_TEST_EXPIRED_WINDOW_SIZE = 10;
|
const int32_t SMA_TEST_EXPIRED_WINDOW_SIZE = 10;
|
||||||
TSKEY expiredWindows[SMA_TEST_EXPIRED_WINDOW_SIZE];
|
TSKEY expiredWindows[SMA_TEST_EXPIRED_WINDOW_SIZE];
|
||||||
int64_t now = taosGetTimestampMs();
|
TSKEY skey1 = 1646987196 * 1e3;
|
||||||
for (int32_t i = 0; i < SMA_TEST_EXPIRED_WINDOW_SIZE; ++i) {
|
for (int32_t i = 0; i < SMA_TEST_EXPIRED_WINDOW_SIZE; ++i) {
|
||||||
expiredWindows[i] = now + i;
|
expiredWindows[i] = skey1 + i;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: decode the msg <= end
|
// TODO: decode the msg <= end
|
||||||
|
|
||||||
|
SSmaEnv * pEnv = REPO_SMA_ENV(pTsdb, smaType);
|
||||||
|
SSmaStat *pStat = SMA_ENV_STAT(pEnv);
|
||||||
SHashObj *pItemsHash = SMA_ENV_STAT_ITEMS(pEnv);
|
SHashObj *pItemsHash = SMA_ENV_STAT_ITEMS(pEnv);
|
||||||
|
|
||||||
|
tsdbRefSmaStat(pTsdb, pStat);
|
||||||
SSmaStatItem *pItem = (SSmaStatItem *)taosHashGet(pItemsHash, &indexUid, sizeof(indexUid));
|
SSmaStatItem *pItem = (SSmaStatItem *)taosHashGet(pItemsHash, &indexUid, sizeof(indexUid));
|
||||||
if (pItem == NULL) {
|
if (pItem == NULL) {
|
||||||
pItem = tsdbNewSmaStatItem(TSDB_SMA_STAT_EXPIRED); // TODO use the real state
|
pItem = tsdbNewSmaStatItem(TSDB_SMA_STAT_EXPIRED); // TODO use the real state
|
||||||
if (pItem == NULL) {
|
if (pItem == NULL) {
|
||||||
// Response to stream computing: OOM
|
// Response to stream computing: OOM
|
||||||
// For query, if the indexName not found, the TSDB should tell query module to query raw TS data.
|
// For query, if the indexUid not found, the TSDB should tell query module to query raw TS data.
|
||||||
|
tsdbUnRefSmaStat(pTsdb, pStat);
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,29 +361,25 @@ int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, int8_t smaType, char *msg) {
|
||||||
terrno = TSDB_CODE_TDB_NO_SMA_INDEX_IN_META;
|
terrno = TSDB_CODE_TDB_NO_SMA_INDEX_IN_META;
|
||||||
taosHashCleanup(pItem->expiredWindows);
|
taosHashCleanup(pItem->expiredWindows);
|
||||||
free(pItem);
|
free(pItem);
|
||||||
|
tsdbUnRefSmaStat(pTsdb, pStat);
|
||||||
tsdbWarn("vgId:%d update expired window failed for smaIndex %" PRIi64 " since %s", REPO_ID(pTsdb), indexUid,
|
tsdbWarn("vgId:%d update expired window failed for smaIndex %" PRIi64 " since %s", REPO_ID(pTsdb), indexUid,
|
||||||
tstrerror(terrno));
|
tstrerror(terrno));
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
pItem->pSma = pSma;
|
pItem->pSma = pSma;
|
||||||
|
|
||||||
// TODO: change indexName to indexUid
|
|
||||||
if (taosHashPut(pItemsHash, &indexUid, sizeof(indexUid), &pItem, sizeof(pItem)) != 0) {
|
if (taosHashPut(pItemsHash, &indexUid, sizeof(indexUid), &pItem, sizeof(pItem)) != 0) {
|
||||||
// If error occurs during put smaStatItem, free the resources of pItem
|
// If error occurs during put smaStatItem, free the resources of pItem
|
||||||
taosHashCleanup(pItem->expiredWindows);
|
taosHashCleanup(pItem->expiredWindows);
|
||||||
free(pItem);
|
free(pItem);
|
||||||
|
tsdbUnRefSmaStat(pTsdb, pStat);
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
SSmaStatItem *pItem1 = (SSmaStatItem *)taosHashGet(pItemsHash, &indexUid, sizeof(indexUid));
|
|
||||||
int size1 = taosHashGetSize(pItem1->expiredWindows);
|
|
||||||
tsdbWarn("vgId:%d smaIndex %" PRIi64 " size is %d before hashPut", REPO_ID(pTsdb), indexUid, size1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int8_t state = TSDB_SMA_STAT_EXPIRED;
|
int8_t state = TSDB_SMA_STAT_EXPIRED;
|
||||||
for (int32_t i = 0; i < SMA_TEST_EXPIRED_WINDOW_SIZE; ++i) {
|
for (int32_t i = 0; i < SMA_TEST_EXPIRED_WINDOW_SIZE; ++i) {
|
||||||
if (taosHashPut(pItem->expiredWindows, &expiredWindows[i], sizeof(TSKEY), &state, sizeof(state)) != 0) {
|
if (taosHashPut(pItem->expiredWindows, (void *)(expiredWindows + i), sizeof(TSKEY), &state, sizeof(state)) != 0) {
|
||||||
// If error occurs during taosHashPut expired windows, remove the smaIndex from pTsdb->pSmaStat, thus TSDB would
|
// If error occurs during taosHashPut expired windows, remove the smaIndex from pTsdb->pSmaStat, thus TSDB would
|
||||||
// tell query module to query raw TS data.
|
// tell query module to query raw TS data.
|
||||||
// N.B.
|
// N.B.
|
||||||
|
@ -334,37 +389,43 @@ int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, int8_t smaType, char *msg) {
|
||||||
taosHashCleanup(pItem->expiredWindows);
|
taosHashCleanup(pItem->expiredWindows);
|
||||||
tfree(pItem->pSma);
|
tfree(pItem->pSma);
|
||||||
taosHashRemove(pItemsHash, &indexUid, sizeof(indexUid));
|
taosHashRemove(pItemsHash, &indexUid, sizeof(indexUid));
|
||||||
|
tsdbUnRefSmaStat(pTsdb, pStat);
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
tsdbDebug("vgId:%d smaIndex %" PRIi64 " tsKey %" PRIi64 " is put to hash", REPO_ID(pTsdb), indexUid,
|
||||||
|
expiredWindows[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
tsdbUnRefSmaStat(pTsdb, pStat);
|
||||||
SSmaStatItem *pItem2 = (SSmaStatItem *)taosHashGet(pItemsHash, &indexUid, sizeof(indexUid));
|
|
||||||
int size2 = taosHashGetSize(pItem1->expiredWindows);
|
|
||||||
tsdbWarn("vgId:%d smaIndex %" PRIi64 " size is %d after hashPut", REPO_ID(pTsdb), indexUid, size2);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tsdbResetExpiredWindow(SSmaStat *pStat, int64_t indexUid, TSKEY skey) {
|
static int32_t tsdbResetExpiredWindow(STsdb *pTsdb, SSmaStat *pStat, int64_t indexUid, TSKEY skey) {
|
||||||
SSmaStatItem *pItem = NULL;
|
SSmaStatItem *pItem = NULL;
|
||||||
|
|
||||||
// TODO: If HASH_ENTRY_LOCK used, whether rwlock needed to handle cases of removing hashNode?
|
tsdbRefSmaStat(pTsdb, pStat);
|
||||||
|
|
||||||
if (pStat && pStat->smaStatItems) {
|
if (pStat && pStat->smaStatItems) {
|
||||||
pItem = (SSmaStatItem *)taosHashGet(pStat->smaStatItems, &indexUid, sizeof(indexUid));
|
pItem = *(SSmaStatItem **)taosHashGet(pStat->smaStatItems, &indexUid, sizeof(indexUid));
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
if (pItem != NULL) {
|
if (pItem != NULL) {
|
||||||
// TODO: reset time window for the sma data blocks
|
// pItem resides in hash buffer all the time unless drop sma index
|
||||||
|
// TODO: multithread protect
|
||||||
if (taosHashRemove(pItem->expiredWindows, &skey, sizeof(TSKEY)) != 0) {
|
if (taosHashRemove(pItem->expiredWindows, &skey, sizeof(TSKEY)) != 0) {
|
||||||
// error handling
|
// error handling
|
||||||
|
tsdbUnRefSmaStat(pTsdb, pStat);
|
||||||
|
tsdbWarn("vgId:%d remove skey %" PRIi64 " from expired window for sma index %" PRIi64 " failed", REPO_ID(pTsdb),
|
||||||
|
skey, indexUid);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// error handling
|
// error handling
|
||||||
|
tsdbUnRefSmaStat(pTsdb, pStat);
|
||||||
|
tsdbWarn("vgId:%d expired window %" PRIi64 " not exists for sma index %" PRIi64, REPO_ID(pTsdb), skey, indexUid);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
tsdbUnRefSmaStat(pTsdb, pStat);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,32 +439,32 @@ static int32_t tsdbResetExpiredWindow(SSmaStat *pStat, int64_t indexUid, TSKEY s
|
||||||
static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit) {
|
static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit) {
|
||||||
// TODO: configurable for SMA_STORAGE_SPLIT_HOURS?
|
// TODO: configurable for SMA_STORAGE_SPLIT_HOURS?
|
||||||
switch (intervalUnit) {
|
switch (intervalUnit) {
|
||||||
case TD_TIME_UNIT_HOUR:
|
case TIME_UNIT_HOUR:
|
||||||
if (interval < SMA_STORAGE_SPLIT_HOURS) {
|
if (interval < SMA_STORAGE_SPLIT_HOURS) {
|
||||||
return SMA_STORAGE_LEVEL_DFILESET;
|
return SMA_STORAGE_LEVEL_DFILESET;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TD_TIME_UNIT_MINUTE:
|
case TIME_UNIT_MINUTE:
|
||||||
if (interval < 60 * SMA_STORAGE_SPLIT_HOURS) {
|
if (interval < 60 * SMA_STORAGE_SPLIT_HOURS) {
|
||||||
return SMA_STORAGE_LEVEL_DFILESET;
|
return SMA_STORAGE_LEVEL_DFILESET;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TD_TIME_UNIT_SEC:
|
case TIME_UNIT_SECOND:
|
||||||
if (interval < 3600 * SMA_STORAGE_SPLIT_HOURS) {
|
if (interval < 3600 * SMA_STORAGE_SPLIT_HOURS) {
|
||||||
return SMA_STORAGE_LEVEL_DFILESET;
|
return SMA_STORAGE_LEVEL_DFILESET;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TD_TIME_UNIT_MILLISEC:
|
case TIME_UNIT_MILLISECOND:
|
||||||
if (interval < 3600 * 1e3 * SMA_STORAGE_SPLIT_HOURS) {
|
if (interval < 3600 * 1e3 * SMA_STORAGE_SPLIT_HOURS) {
|
||||||
return SMA_STORAGE_LEVEL_DFILESET;
|
return SMA_STORAGE_LEVEL_DFILESET;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TD_TIME_UNIT_MICROSEC:
|
case TIME_UNIT_MICROSECOND:
|
||||||
if (interval < 3600 * 1e6 * SMA_STORAGE_SPLIT_HOURS) {
|
if (interval < 3600 * 1e6 * SMA_STORAGE_SPLIT_HOURS) {
|
||||||
return SMA_STORAGE_LEVEL_DFILESET;
|
return SMA_STORAGE_LEVEL_DFILESET;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TD_TIME_UNIT_NANOSEC:
|
case TIME_UNIT_NANOSECOND:
|
||||||
if (interval < 3600 * 1e9 * SMA_STORAGE_SPLIT_HOURS) {
|
if (interval < 3600 * 1e9 * SMA_STORAGE_SPLIT_HOURS) {
|
||||||
return SMA_STORAGE_LEVEL_DFILESET;
|
return SMA_STORAGE_LEVEL_DFILESET;
|
||||||
}
|
}
|
||||||
|
@ -429,8 +490,8 @@ static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, uint32_t k
|
||||||
|
|
||||||
// TODO: insert sma data blocks into B+Tree
|
// TODO: insert sma data blocks into B+Tree
|
||||||
tsdbDebug("vgId:%d insert sma data blocks into %s: smaKey %" PRIx64 "-%" PRIu16 "-%" PRIx64 ", dataLen %d",
|
tsdbDebug("vgId:%d insert sma data blocks into %s: smaKey %" PRIx64 "-%" PRIu16 "-%" PRIx64 ", dataLen %d",
|
||||||
REPO_ID(pSmaH->pTsdb), pDBFile->path, *(tb_uid_t *)smaKey, *(uint16_t *)POINTER_SHIFT(smaKey, 8),
|
REPO_ID(pSmaH->pTsdb), pDBFile->path, *(tb_uid_t *)smaKey, *(uint16_t *)POINTER_SHIFT(smaKey, 8),
|
||||||
*(int64_t *)POINTER_SHIFT(smaKey, 10), dataLen);
|
*(int64_t *)POINTER_SHIFT(smaKey, 10), dataLen);
|
||||||
|
|
||||||
if (tsdbSaveSmaToDB(pDBFile, smaKey, keyLen, pData, dataLen) != 0) {
|
if (tsdbSaveSmaToDB(pDBFile, smaKey, keyLen, pData, dataLen) != 0) {
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
|
@ -447,66 +508,73 @@ static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, uint32_t k
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Approximate value for week/month/year.
|
||||||
|
*
|
||||||
|
* @param interval
|
||||||
|
* @param intervalUnit
|
||||||
|
* @param precision
|
||||||
|
* @return int64_t
|
||||||
|
*/
|
||||||
static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit, int8_t precision) {
|
static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit, int8_t precision) {
|
||||||
if (intervalUnit < TD_TIME_UNIT_MILLISEC) {
|
switch (intervalUnit) {
|
||||||
switch (intervalUnit) {
|
case TIME_UNIT_YEAR: // approximate value
|
||||||
case TD_TIME_UNIT_YEAR:
|
interval *= 365 * 86400 * 1e3;
|
||||||
case TD_TIME_UNIT_SEASON:
|
break;
|
||||||
case TD_TIME_UNIT_MONTH:
|
case TIME_UNIT_MONTH: // approximate value
|
||||||
case TD_TIME_UNIT_WEEK:
|
interval *= 30 * 86400 * 1e3;
|
||||||
// illegal time unit
|
break;
|
||||||
tsdbError("invalid interval unit: %d\n", intervalUnit);
|
case TIME_UNIT_WEEK: // approximate value
|
||||||
TASSERT(0);
|
interval *= 7 * 86400 * 1e3;
|
||||||
break;
|
break;
|
||||||
case TD_TIME_UNIT_DAY: // the interval for tSma calculation must <= day
|
case TIME_UNIT_DAY: // the interval for tSma calculation must <= day
|
||||||
interval *= 86400 * 1e3;
|
interval *= 86400 * 1e3;
|
||||||
break;
|
break;
|
||||||
case TD_TIME_UNIT_HOUR:
|
case TIME_UNIT_HOUR:
|
||||||
interval *= 3600 * 1e3;
|
interval *= 3600 * 1e3;
|
||||||
break;
|
break;
|
||||||
case TD_TIME_UNIT_MINUTE:
|
case TIME_UNIT_MINUTE:
|
||||||
interval *= 60 * 1e3;
|
interval *= 60 * 1e3;
|
||||||
break;
|
break;
|
||||||
case TD_TIME_UNIT_SEC:
|
case TIME_UNIT_SECOND:
|
||||||
interval *= 1e3;
|
interval *= 1e3;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (precision) {
|
switch (precision) {
|
||||||
case TSDB_TIME_PRECISION_MILLI:
|
case TSDB_TIME_PRECISION_MILLI:
|
||||||
if (TD_TIME_UNIT_MICROSEC == intervalUnit) { // us
|
if (TIME_UNIT_MICROSECOND == intervalUnit) { // us
|
||||||
return interval / 1e3;
|
return interval / 1e3;
|
||||||
} else if (TD_TIME_UNIT_NANOSEC == intervalUnit) { // nano second
|
} else if (TIME_UNIT_NANOSECOND == intervalUnit) { // nano second
|
||||||
return interval / 1e6;
|
return interval / 1e6;
|
||||||
} else {
|
} else {
|
||||||
return interval;
|
return interval;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TSDB_TIME_PRECISION_MICRO:
|
case TSDB_TIME_PRECISION_MICRO:
|
||||||
if (TD_TIME_UNIT_MICROSEC == intervalUnit) { // us
|
if (TIME_UNIT_MICROSECOND == intervalUnit) { // us
|
||||||
return interval;
|
return interval;
|
||||||
} else if (TD_TIME_UNIT_NANOSEC == intervalUnit) { // nano second
|
} else if (TIME_UNIT_NANOSECOND == intervalUnit) { // nano second
|
||||||
return interval / 1e3;
|
return interval / 1e3;
|
||||||
} else {
|
} else {
|
||||||
return interval * 1e3;
|
return interval * 1e3;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TSDB_TIME_PRECISION_NANO:
|
case TSDB_TIME_PRECISION_NANO:
|
||||||
if (TD_TIME_UNIT_MICROSEC == intervalUnit) {
|
if (TIME_UNIT_MICROSECOND == intervalUnit) {
|
||||||
return interval * 1e3;
|
return interval * 1e3;
|
||||||
} else if (TD_TIME_UNIT_NANOSEC == intervalUnit) { // nano second
|
} else if (TIME_UNIT_NANOSECOND == intervalUnit) { // nano second
|
||||||
return interval;
|
return interval;
|
||||||
} else {
|
} else {
|
||||||
return interval * 1e6;
|
return interval * 1e6;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: // ms
|
default: // ms
|
||||||
if (TD_TIME_UNIT_MICROSEC == intervalUnit) { // us
|
if (TIME_UNIT_MICROSECOND == intervalUnit) { // us
|
||||||
return interval / 1e3;
|
return interval / 1e3;
|
||||||
} else if (TD_TIME_UNIT_NANOSEC == intervalUnit) { // nano second
|
} else if (TIME_UNIT_NANOSECOND == intervalUnit) { // nano second
|
||||||
return interval / 1e6;
|
return interval / 1e6;
|
||||||
} else {
|
} else {
|
||||||
return interval;
|
return interval;
|
||||||
|
@ -664,7 +732,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) {
|
||||||
// TODO:tsdbEndTSmaCommit();
|
// TODO:tsdbEndTSmaCommit();
|
||||||
|
|
||||||
// Step 3: reset the SSmaStat
|
// Step 3: reset the SSmaStat
|
||||||
tsdbResetExpiredWindow(SMA_ENV_STAT(pTsdb->pTSmaEnv), pData->indexUid, pData->skey);
|
tsdbResetExpiredWindow(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv), pData->indexUid, pData->skey);
|
||||||
|
|
||||||
tsdbDestroyTSmaWriteH(&tSmaH);
|
tsdbDestroyTSmaWriteH(&tSmaH);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -710,7 +778,7 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) {
|
||||||
// TODO:tsdbEndTSmaCommit();
|
// TODO:tsdbEndTSmaCommit();
|
||||||
|
|
||||||
// reset the SSmaStat
|
// reset the SSmaStat
|
||||||
tsdbResetExpiredWindow(SMA_ENV_STAT(pTsdb->pRSmaEnv), pData->indexUid, pData->skey);
|
tsdbResetExpiredWindow(pTsdb, SMA_ENV_STAT(pTsdb->pRSmaEnv), pData->indexUid, pData->skey);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -798,12 +866,23 @@ static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey) {
|
||||||
* @return int32_t
|
* @return int32_t
|
||||||
*/
|
*/
|
||||||
static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval,
|
static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval,
|
||||||
int8_t intervalUnit, tb_uid_t tableUid, col_id_t colId, TSKEY querySkey,
|
int8_t intervalUnit, tb_uid_t tableUid, col_id_t colId, TSKEY querySKey,
|
||||||
int32_t nMaxResult) {
|
int32_t nMaxResult) {
|
||||||
SSmaStatItem *pItem = (SSmaStatItem *)taosHashGet(SMA_ENV_STAT_ITEMS(pTsdb->pTSmaEnv), &indexUid, sizeof(indexUid));
|
if (!pTsdb->pTSmaEnv) {
|
||||||
|
terrno = TSDB_CODE_INVALID_PTR;
|
||||||
|
tsdbWarn("vgId:%d getTSmaDataImpl failed since pTSmaEnv is NULL", REPO_ID(pTsdb));
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
tsdbRefSmaStat(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv));
|
||||||
|
SSmaStatItem *pItem = *(SSmaStatItem **)taosHashGet(SMA_ENV_STAT_ITEMS(pTsdb->pTSmaEnv), &indexUid, sizeof(indexUid));
|
||||||
if (pItem == NULL) {
|
if (pItem == NULL) {
|
||||||
// mark all window as expired and notify query module to query raw TS data.
|
// Normally pItem should not be NULL, mark all windows as expired and notify query module to fetch raw TS data if
|
||||||
return TSDB_CODE_SUCCESS;
|
// it's NULL.
|
||||||
|
tsdbUnRefSmaStat(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv));
|
||||||
|
terrno = TSDB_CODE_TDB_INVALID_ACTION;
|
||||||
|
tsdbDebug("vgId:%d getTSmaDataImpl failed since no index %" PRIi64, REPO_ID(pTsdb), indexUid);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -815,16 +894,24 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if 0
|
|
||||||
if (taosHashGet(pItem->expiredWindows, &querySkey, sizeof(TSKEY)) != NULL) {
|
#if 1
|
||||||
|
if (taosHashGet(pItem->expiredWindows, &querySKey, sizeof(TSKEY)) != NULL) {
|
||||||
// TODO: mark this window as expired.
|
// TODO: mark this window as expired.
|
||||||
|
tsdbDebug("vgId:%d skey %" PRIi64 " of window exists in expired window for index %" PRIi64, REPO_ID(pTsdb),
|
||||||
|
querySKey, indexUid);
|
||||||
|
} else {
|
||||||
|
tsdbDebug("vgId:%d skey %" PRIi64 " of window not in expired window for index %" PRIi64, REPO_ID(pTsdb), querySKey,
|
||||||
|
indexUid);
|
||||||
}
|
}
|
||||||
|
tsdbUnRefSmaStat(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
STSmaReadH tReadH = {0};
|
STSmaReadH tReadH = {0};
|
||||||
tsdbInitTSmaReadH(&tReadH, pTsdb, interval, intervalUnit);
|
tsdbInitTSmaReadH(&tReadH, pTsdb, interval, intervalUnit);
|
||||||
tsdbCloseDBF(&tReadH.dFile);
|
tsdbCloseDBF(&tReadH.dFile);
|
||||||
|
|
||||||
tsdbInitTSmaFile(&tReadH, querySkey);
|
tsdbInitTSmaFile(&tReadH, querySKey);
|
||||||
if (tsdbOpenDBF(SMA_ENV_ENV(pTsdb->pTSmaEnv), &tReadH.dFile) != 0) {
|
if (tsdbOpenDBF(SMA_ENV_ENV(pTsdb->pTSmaEnv), &tReadH.dFile) != 0) {
|
||||||
tsdbWarn("vgId:%d open DBF %s failed since %s", REPO_ID(pTsdb), tReadH.dFile.path, tstrerror(terrno));
|
tsdbWarn("vgId:%d open DBF %s failed since %s", REPO_ID(pTsdb), tReadH.dFile.path, tstrerror(terrno));
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
|
@ -832,11 +919,11 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_
|
||||||
|
|
||||||
char smaKey[SMA_KEY_LEN] = {0};
|
char smaKey[SMA_KEY_LEN] = {0};
|
||||||
void *pSmaKey = &smaKey;
|
void *pSmaKey = &smaKey;
|
||||||
tsdbEncodeTSmaKey(tableUid, colId, querySkey, (void **)&pSmaKey);
|
tsdbEncodeTSmaKey(tableUid, colId, querySKey, (void **)&pSmaKey);
|
||||||
|
|
||||||
tsdbDebug("vgId:%d get sma data from %s: smaKey %" PRIx64 "-%" PRIu16 "-%" PRIx64 ", keyLen %d", REPO_ID(pTsdb),
|
tsdbDebug("vgId:%d get sma data from %s: smaKey %" PRIx64 "-%" PRIu16 "-%" PRIx64 ", keyLen %d", REPO_ID(pTsdb),
|
||||||
tReadH.dFile.path, *(tb_uid_t *)smaKey, *(uint16_t *)POINTER_SHIFT(smaKey, 8),
|
tReadH.dFile.path, *(tb_uid_t *)smaKey, *(uint16_t *)POINTER_SHIFT(smaKey, 8),
|
||||||
*(int64_t *)POINTER_SHIFT(smaKey, 10), SMA_KEY_LEN);
|
*(int64_t *)POINTER_SHIFT(smaKey, 10), SMA_KEY_LEN);
|
||||||
|
|
||||||
void * result = NULL;
|
void * result = NULL;
|
||||||
uint32_t valueSize = 0;
|
uint32_t valueSize = 0;
|
||||||
|
@ -947,7 +1034,6 @@ int32_t tsdbUpdateSmaWindow(STsdb *pTsdb, int8_t smaType, char *msg) {
|
||||||
* @brief Insert Time-range-wise Rollup Sma(RSma) data
|
* @brief Insert Time-range-wise Rollup Sma(RSma) data
|
||||||
*
|
*
|
||||||
* @param pTsdb
|
* @param pTsdb
|
||||||
* @param param
|
|
||||||
* @param msg
|
* @param msg
|
||||||
* @return int32_t
|
* @return int32_t
|
||||||
*/
|
*/
|
||||||
|
@ -960,9 +1046,9 @@ int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbGetTSmaData(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval, int8_t intervalUnit,
|
int32_t tsdbGetTSmaData(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval, int8_t intervalUnit,
|
||||||
tb_uid_t tableUid, col_id_t colId, TSKEY querySkey, int32_t nMaxResult) {
|
tb_uid_t tableUid, col_id_t colId, TSKEY querySKey, int32_t nMaxResult) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
if ((code = tsdbGetTSmaDataImpl(pTsdb, pData, indexUid, interval, intervalUnit, tableUid, colId, querySkey,
|
if ((code = tsdbGetTSmaDataImpl(pTsdb, pData, indexUid, interval, intervalUnit, tableUid, colId, querySKey,
|
||||||
nMaxResult)) < 0) {
|
nMaxResult)) < 0) {
|
||||||
tsdbWarn("vgId:%d get tSma data failed since %s", REPO_ID(pTsdb), tstrerror(terrno));
|
tsdbWarn("vgId:%d get tSma data failed since %s", REPO_ID(pTsdb), tstrerror(terrno));
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,9 +37,9 @@ TEST(testCase, tSma_Meta_Encode_Decode_Test) {
|
||||||
// encode
|
// encode
|
||||||
STSma tSma = {0};
|
STSma tSma = {0};
|
||||||
tSma.version = 0;
|
tSma.version = 0;
|
||||||
tSma.intervalUnit = TD_TIME_UNIT_DAY;
|
tSma.intervalUnit = TIME_UNIT_DAY;
|
||||||
tSma.interval = 1;
|
tSma.interval = 1;
|
||||||
tSma.slidingUnit = TD_TIME_UNIT_HOUR;
|
tSma.slidingUnit = TIME_UNIT_HOUR;
|
||||||
tSma.sliding = 0;
|
tSma.sliding = 0;
|
||||||
tstrncpy(tSma.indexName, "sma_index_test", TSDB_INDEX_NAME_LEN);
|
tstrncpy(tSma.indexName, "sma_index_test", TSDB_INDEX_NAME_LEN);
|
||||||
tstrncpy(tSma.timezone, "Asia/Shanghai", TD_TIMEZONE_LEN);
|
tstrncpy(tSma.timezone, "Asia/Shanghai", TD_TIMEZONE_LEN);
|
||||||
|
@ -50,37 +50,37 @@ TEST(testCase, tSma_Meta_Encode_Decode_Test) {
|
||||||
uint32_t bufLen = tEncodeTSmaWrapper(NULL, &tSmaWrapper);
|
uint32_t bufLen = tEncodeTSmaWrapper(NULL, &tSmaWrapper);
|
||||||
|
|
||||||
void *buf = calloc(bufLen, 1);
|
void *buf = calloc(bufLen, 1);
|
||||||
assert(buf != NULL);
|
ASSERT_NE(buf, nullptr);
|
||||||
|
|
||||||
STSmaWrapper *pSW = (STSmaWrapper *)buf;
|
STSmaWrapper *pSW = (STSmaWrapper *)buf;
|
||||||
uint32_t len = tEncodeTSmaWrapper(&buf, &tSmaWrapper);
|
uint32_t len = tEncodeTSmaWrapper(&buf, &tSmaWrapper);
|
||||||
|
|
||||||
EXPECT_EQ(len, bufLen);
|
ASSERT_EQ(len, bufLen);
|
||||||
|
|
||||||
// decode
|
// decode
|
||||||
STSmaWrapper dstTSmaWrapper = {0};
|
STSmaWrapper dstTSmaWrapper = {0};
|
||||||
void * result = tDecodeTSmaWrapper(pSW, &dstTSmaWrapper);
|
void * result = tDecodeTSmaWrapper(pSW, &dstTSmaWrapper);
|
||||||
assert(result != NULL);
|
ASSERT_NE(result, nullptr);
|
||||||
|
|
||||||
EXPECT_EQ(tSmaWrapper.number, dstTSmaWrapper.number);
|
ASSERT_EQ(tSmaWrapper.number, dstTSmaWrapper.number);
|
||||||
|
|
||||||
for (int i = 0; i < tSmaWrapper.number; ++i) {
|
for (int i = 0; i < tSmaWrapper.number; ++i) {
|
||||||
STSma *pSma = tSmaWrapper.tSma + i;
|
STSma *pSma = tSmaWrapper.tSma + i;
|
||||||
STSma *qSma = dstTSmaWrapper.tSma + i;
|
STSma *qSma = dstTSmaWrapper.tSma + i;
|
||||||
|
|
||||||
EXPECT_EQ(pSma->version, qSma->version);
|
ASSERT_EQ(pSma->version, qSma->version);
|
||||||
EXPECT_EQ(pSma->intervalUnit, qSma->intervalUnit);
|
ASSERT_EQ(pSma->intervalUnit, qSma->intervalUnit);
|
||||||
EXPECT_EQ(pSma->slidingUnit, qSma->slidingUnit);
|
ASSERT_EQ(pSma->slidingUnit, qSma->slidingUnit);
|
||||||
EXPECT_STRCASEEQ(pSma->indexName, qSma->indexName);
|
ASSERT_STRCASEEQ(pSma->indexName, qSma->indexName);
|
||||||
EXPECT_STRCASEEQ(pSma->timezone, qSma->timezone);
|
ASSERT_STRCASEEQ(pSma->timezone, qSma->timezone);
|
||||||
EXPECT_EQ(pSma->indexUid, qSma->indexUid);
|
ASSERT_EQ(pSma->indexUid, qSma->indexUid);
|
||||||
EXPECT_EQ(pSma->tableUid, qSma->tableUid);
|
ASSERT_EQ(pSma->tableUid, qSma->tableUid);
|
||||||
EXPECT_EQ(pSma->interval, qSma->interval);
|
ASSERT_EQ(pSma->interval, qSma->interval);
|
||||||
EXPECT_EQ(pSma->sliding, qSma->sliding);
|
ASSERT_EQ(pSma->sliding, qSma->sliding);
|
||||||
EXPECT_EQ(pSma->exprLen, qSma->exprLen);
|
ASSERT_EQ(pSma->exprLen, qSma->exprLen);
|
||||||
EXPECT_STRCASEEQ(pSma->expr, qSma->expr);
|
ASSERT_STRCASEEQ(pSma->expr, qSma->expr);
|
||||||
EXPECT_EQ(pSma->tagsFilterLen, qSma->tagsFilterLen);
|
ASSERT_EQ(pSma->tagsFilterLen, qSma->tagsFilterLen);
|
||||||
EXPECT_STRCASEEQ(pSma->tagsFilter, qSma->tagsFilter);
|
ASSERT_STRCASEEQ(pSma->tagsFilter, qSma->tagsFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// resource release
|
// resource release
|
||||||
|
@ -103,9 +103,9 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
||||||
// encode
|
// encode
|
||||||
STSma tSma = {0};
|
STSma tSma = {0};
|
||||||
tSma.version = 0;
|
tSma.version = 0;
|
||||||
tSma.intervalUnit = TD_TIME_UNIT_DAY;
|
tSma.intervalUnit = TIME_UNIT_DAY;
|
||||||
tSma.interval = 1;
|
tSma.interval = 1;
|
||||||
tSma.slidingUnit = TD_TIME_UNIT_HOUR;
|
tSma.slidingUnit = TIME_UNIT_HOUR;
|
||||||
tSma.sliding = 0;
|
tSma.sliding = 0;
|
||||||
tSma.indexUid = indexUid1;
|
tSma.indexUid = indexUid1;
|
||||||
tstrncpy(tSma.indexName, smaIndexName1, TSDB_INDEX_NAME_LEN);
|
tstrncpy(tSma.indexName, smaIndexName1, TSDB_INDEX_NAME_LEN);
|
||||||
|
@ -114,10 +114,12 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
||||||
|
|
||||||
tSma.exprLen = strlen(expr);
|
tSma.exprLen = strlen(expr);
|
||||||
tSma.expr = (char *)calloc(tSma.exprLen + 1, 1);
|
tSma.expr = (char *)calloc(tSma.exprLen + 1, 1);
|
||||||
|
ASSERT_NE(tSma.expr, nullptr);
|
||||||
tstrncpy(tSma.expr, expr, tSma.exprLen + 1);
|
tstrncpy(tSma.expr, expr, tSma.exprLen + 1);
|
||||||
|
|
||||||
tSma.tagsFilterLen = strlen(tagsFilter);
|
tSma.tagsFilterLen = strlen(tagsFilter);
|
||||||
tSma.tagsFilter = (char *)calloc(tSma.tagsFilterLen + 1, 1);
|
tSma.tagsFilter = (char *)calloc(tSma.tagsFilterLen + 1, 1);
|
||||||
|
ASSERT_NE(tSma.tagsFilter, nullptr);
|
||||||
tstrncpy(tSma.tagsFilter, tagsFilter, tSma.tagsFilterLen + 1);
|
tstrncpy(tSma.tagsFilter, tagsFilter, tSma.tagsFilterLen + 1);
|
||||||
|
|
||||||
SMeta * pMeta = NULL;
|
SMeta * pMeta = NULL;
|
||||||
|
@ -129,18 +131,18 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
||||||
pMeta = metaOpen(smaTestDir, pMetaCfg, NULL);
|
pMeta = metaOpen(smaTestDir, pMetaCfg, NULL);
|
||||||
assert(pMeta != NULL);
|
assert(pMeta != NULL);
|
||||||
// save index 1
|
// save index 1
|
||||||
EXPECT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0);
|
ASSERT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0);
|
||||||
|
|
||||||
pSmaCfg->indexUid = indexUid2;
|
pSmaCfg->indexUid = indexUid2;
|
||||||
tstrncpy(pSmaCfg->indexName, smaIndexName2, TSDB_INDEX_NAME_LEN);
|
tstrncpy(pSmaCfg->indexName, smaIndexName2, TSDB_INDEX_NAME_LEN);
|
||||||
pSmaCfg->version = 1;
|
pSmaCfg->version = 1;
|
||||||
pSmaCfg->intervalUnit = TD_TIME_UNIT_HOUR;
|
pSmaCfg->intervalUnit = TIME_UNIT_HOUR;
|
||||||
pSmaCfg->interval = 1;
|
pSmaCfg->interval = 1;
|
||||||
pSmaCfg->slidingUnit = TD_TIME_UNIT_MINUTE;
|
pSmaCfg->slidingUnit = TIME_UNIT_MINUTE;
|
||||||
pSmaCfg->sliding = 5;
|
pSmaCfg->sliding = 5;
|
||||||
|
|
||||||
// save index 2
|
// save index 2
|
||||||
EXPECT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0);
|
ASSERT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0);
|
||||||
|
|
||||||
// get value by indexName
|
// get value by indexName
|
||||||
STSma *qSmaCfg = NULL;
|
STSma *qSmaCfg = NULL;
|
||||||
|
@ -150,8 +152,8 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
||||||
printf("timezone1 = %s\n", qSmaCfg->timezone);
|
printf("timezone1 = %s\n", qSmaCfg->timezone);
|
||||||
printf("expr1 = %s\n", qSmaCfg->expr != NULL ? qSmaCfg->expr : "");
|
printf("expr1 = %s\n", qSmaCfg->expr != NULL ? qSmaCfg->expr : "");
|
||||||
printf("tagsFilter1 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : "");
|
printf("tagsFilter1 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : "");
|
||||||
EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName1);
|
ASSERT_STRCASEEQ(qSmaCfg->indexName, smaIndexName1);
|
||||||
EXPECT_EQ(qSmaCfg->tableUid, tSma.tableUid);
|
ASSERT_EQ(qSmaCfg->tableUid, tSma.tableUid);
|
||||||
tdDestroyTSma(qSmaCfg);
|
tdDestroyTSma(qSmaCfg);
|
||||||
tfree(qSmaCfg);
|
tfree(qSmaCfg);
|
||||||
|
|
||||||
|
@ -161,8 +163,8 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
||||||
printf("timezone2 = %s\n", qSmaCfg->timezone);
|
printf("timezone2 = %s\n", qSmaCfg->timezone);
|
||||||
printf("expr2 = %s\n", qSmaCfg->expr != NULL ? qSmaCfg->expr : "");
|
printf("expr2 = %s\n", qSmaCfg->expr != NULL ? qSmaCfg->expr : "");
|
||||||
printf("tagsFilter2 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : "");
|
printf("tagsFilter2 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : "");
|
||||||
EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName2);
|
ASSERT_STRCASEEQ(qSmaCfg->indexName, smaIndexName2);
|
||||||
EXPECT_EQ(qSmaCfg->interval, tSma.interval);
|
ASSERT_EQ(qSmaCfg->interval, tSma.interval);
|
||||||
tdDestroyTSma(qSmaCfg);
|
tdDestroyTSma(qSmaCfg);
|
||||||
tfree(qSmaCfg);
|
tfree(qSmaCfg);
|
||||||
|
|
||||||
|
@ -178,25 +180,25 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
||||||
printf("indexName = %s\n", indexName);
|
printf("indexName = %s\n", indexName);
|
||||||
++indexCnt;
|
++indexCnt;
|
||||||
}
|
}
|
||||||
EXPECT_EQ(indexCnt, nCntTSma);
|
ASSERT_EQ(indexCnt, nCntTSma);
|
||||||
metaCloseSmaCurosr(pSmaCur);
|
metaCloseSmaCurosr(pSmaCur);
|
||||||
|
|
||||||
// get wrapper by table uid
|
// get wrapper by table uid
|
||||||
STSmaWrapper *pSW = metaGetSmaInfoByTable(pMeta, tbUid);
|
STSmaWrapper *pSW = metaGetSmaInfoByTable(pMeta, tbUid);
|
||||||
assert(pSW != NULL);
|
assert(pSW != NULL);
|
||||||
EXPECT_EQ(pSW->number, nCntTSma);
|
ASSERT_EQ(pSW->number, nCntTSma);
|
||||||
EXPECT_STRCASEEQ(pSW->tSma->indexName, smaIndexName1);
|
ASSERT_STRCASEEQ(pSW->tSma->indexName, smaIndexName1);
|
||||||
EXPECT_STRCASEEQ(pSW->tSma->timezone, timezone);
|
ASSERT_STRCASEEQ(pSW->tSma->timezone, timezone);
|
||||||
EXPECT_STRCASEEQ(pSW->tSma->expr, expr);
|
ASSERT_STRCASEEQ(pSW->tSma->expr, expr);
|
||||||
EXPECT_STRCASEEQ(pSW->tSma->tagsFilter, tagsFilter);
|
ASSERT_STRCASEEQ(pSW->tSma->tagsFilter, tagsFilter);
|
||||||
EXPECT_EQ(pSW->tSma->indexUid, indexUid1);
|
ASSERT_EQ(pSW->tSma->indexUid, indexUid1);
|
||||||
EXPECT_EQ(pSW->tSma->tableUid, tbUid);
|
ASSERT_EQ(pSW->tSma->tableUid, tbUid);
|
||||||
EXPECT_STRCASEEQ((pSW->tSma + 1)->indexName, smaIndexName2);
|
ASSERT_STRCASEEQ((pSW->tSma + 1)->indexName, smaIndexName2);
|
||||||
EXPECT_STRCASEEQ((pSW->tSma + 1)->timezone, timezone);
|
ASSERT_STRCASEEQ((pSW->tSma + 1)->timezone, timezone);
|
||||||
EXPECT_STRCASEEQ((pSW->tSma + 1)->expr, expr);
|
ASSERT_STRCASEEQ((pSW->tSma + 1)->expr, expr);
|
||||||
EXPECT_STRCASEEQ((pSW->tSma + 1)->tagsFilter, tagsFilter);
|
ASSERT_STRCASEEQ((pSW->tSma + 1)->tagsFilter, tagsFilter);
|
||||||
EXPECT_EQ((pSW->tSma + 1)->indexUid, indexUid2);
|
ASSERT_EQ((pSW->tSma + 1)->indexUid, indexUid2);
|
||||||
EXPECT_EQ((pSW->tSma + 1)->tableUid, tbUid);
|
ASSERT_EQ((pSW->tSma + 1)->tableUid, tbUid);
|
||||||
|
|
||||||
tdDestroyTSmaWrapper(pSW);
|
tdDestroyTSmaWrapper(pSW);
|
||||||
tfree(pSW);
|
tfree(pSW);
|
||||||
|
@ -208,7 +210,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
||||||
printf("metaGetSmaTbUids: uid[%" PRIu32 "] = %" PRIi64 "\n", i, *(tb_uid_t *)taosArrayGet(pUids, i));
|
printf("metaGetSmaTbUids: uid[%" PRIu32 "] = %" PRIi64 "\n", i, *(tb_uid_t *)taosArrayGet(pUids, i));
|
||||||
// printf("metaGetSmaTbUids: index[%" PRIu32 "] = %s", i, (char *)taosArrayGet(pUids, i));
|
// printf("metaGetSmaTbUids: index[%" PRIu32 "] = %s", i, (char *)taosArrayGet(pUids, i));
|
||||||
}
|
}
|
||||||
EXPECT_EQ(taosArrayGetSize(pUids), 1);
|
ASSERT_EQ(taosArrayGetSize(pUids), 1);
|
||||||
taosArrayDestroy(pUids);
|
taosArrayDestroy(pUids);
|
||||||
|
|
||||||
// resource release
|
// resource release
|
||||||
|
@ -231,7 +233,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
||||||
const tb_uid_t tbUid = 1234567890;
|
const tb_uid_t tbUid = 1234567890;
|
||||||
const int64_t indexUid1 = 2000000001;
|
const int64_t indexUid1 = 2000000001;
|
||||||
const int64_t interval1 = 1;
|
const int64_t interval1 = 1;
|
||||||
const int8_t intervalUnit1 = TD_TIME_UNIT_DAY;
|
const int8_t intervalUnit1 = TIME_UNIT_DAY;
|
||||||
const uint32_t nCntTSma = 2;
|
const uint32_t nCntTSma = 2;
|
||||||
TSKEY skey1 = 1646987196;
|
TSKEY skey1 = 1646987196;
|
||||||
const int64_t testSmaData1 = 100;
|
const int64_t testSmaData1 = 100;
|
||||||
|
@ -239,9 +241,9 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
||||||
// encode
|
// encode
|
||||||
STSma tSma = {0};
|
STSma tSma = {0};
|
||||||
tSma.version = 0;
|
tSma.version = 0;
|
||||||
tSma.intervalUnit = TD_TIME_UNIT_DAY;
|
tSma.intervalUnit = TIME_UNIT_DAY;
|
||||||
tSma.interval = 1;
|
tSma.interval = 1;
|
||||||
tSma.slidingUnit = TD_TIME_UNIT_HOUR;
|
tSma.slidingUnit = TIME_UNIT_HOUR;
|
||||||
tSma.sliding = 0;
|
tSma.sliding = 0;
|
||||||
tSma.indexUid = indexUid1;
|
tSma.indexUid = indexUid1;
|
||||||
tstrncpy(tSma.indexName, smaIndexName1, TSDB_INDEX_NAME_LEN);
|
tstrncpy(tSma.indexName, smaIndexName1, TSDB_INDEX_NAME_LEN);
|
||||||
|
@ -250,10 +252,12 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
||||||
|
|
||||||
tSma.exprLen = strlen(expr);
|
tSma.exprLen = strlen(expr);
|
||||||
tSma.expr = (char *)calloc(tSma.exprLen + 1, 1);
|
tSma.expr = (char *)calloc(tSma.exprLen + 1, 1);
|
||||||
|
ASSERT_NE(tSma.expr, nullptr);
|
||||||
tstrncpy(tSma.expr, expr, tSma.exprLen + 1);
|
tstrncpy(tSma.expr, expr, tSma.exprLen + 1);
|
||||||
|
|
||||||
tSma.tagsFilterLen = strlen(tagsFilter);
|
tSma.tagsFilterLen = strlen(tagsFilter);
|
||||||
tSma.tagsFilter = (char *)calloc(tSma.tagsFilterLen + 1, 1);
|
tSma.tagsFilter = (char *)calloc(tSma.tagsFilterLen + 1, 1);
|
||||||
|
ASSERT_NE(tSma.tagsFilter, nullptr);
|
||||||
tstrncpy(tSma.tagsFilter, tagsFilter, tSma.tagsFilterLen + 1);
|
tstrncpy(tSma.tagsFilter, tagsFilter, tSma.tagsFilterLen + 1);
|
||||||
|
|
||||||
SMeta * pMeta = NULL;
|
SMeta * pMeta = NULL;
|
||||||
|
@ -265,7 +269,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
||||||
pMeta = metaOpen(smaTestDir, pMetaCfg, NULL);
|
pMeta = metaOpen(smaTestDir, pMetaCfg, NULL);
|
||||||
assert(pMeta != NULL);
|
assert(pMeta != NULL);
|
||||||
// save index 1
|
// save index 1
|
||||||
EXPECT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0);
|
ASSERT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0);
|
||||||
|
|
||||||
// step 2: insert data
|
// step 2: insert data
|
||||||
STSmaDataWrapper *pSmaData = NULL;
|
STSmaDataWrapper *pSmaData = NULL;
|
||||||
|
@ -297,19 +301,20 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *msg = (char *)calloc(100, 1);
|
char *msg = (char *)calloc(1, 100);
|
||||||
EXPECT_EQ(tsdbUpdateSmaWindow(&tsdb, TSDB_SMA_TYPE_TIME_RANGE, msg), 0);
|
assert(msg != NULL);
|
||||||
|
ASSERT_EQ(tsdbUpdateSmaWindow(&tsdb, TSDB_SMA_TYPE_TIME_RANGE, msg), 0);
|
||||||
|
|
||||||
// init
|
// init
|
||||||
int32_t allocCnt = 0;
|
int32_t allocCnt = 0;
|
||||||
int32_t allocStep = 40960;
|
int32_t allocStep = 16384;
|
||||||
int32_t buffer = 4096;
|
int32_t buffer = 1024;
|
||||||
void * buf = NULL;
|
void * buf = NULL;
|
||||||
EXPECT_EQ(tsdbMakeRoom(&buf, allocStep), 0);
|
ASSERT_EQ(tsdbMakeRoom(&buf, allocStep), 0);
|
||||||
int32_t bufSize = taosTSizeof(buf);
|
int32_t bufSize = taosTSizeof(buf);
|
||||||
int32_t numOfTables = 10;
|
int32_t numOfTables = 10;
|
||||||
col_id_t numOfCols = 4096;
|
col_id_t numOfCols = 4096;
|
||||||
EXPECT_GT(numOfCols, 0);
|
ASSERT_GT(numOfCols, 0);
|
||||||
|
|
||||||
pSmaData = (STSmaDataWrapper *)buf;
|
pSmaData = (STSmaDataWrapper *)buf;
|
||||||
printf(">> allocate [%d] time to %d and addr is %p\n", ++allocCnt, bufSize, pSmaData);
|
printf(">> allocate [%d] time to %d and addr is %p\n", ++allocCnt, bufSize, pSmaData);
|
||||||
|
@ -326,7 +331,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
||||||
int32_t tableDataLen = sizeof(STSmaTbData);
|
int32_t tableDataLen = sizeof(STSmaTbData);
|
||||||
for (col_id_t c = 0; c < numOfCols; ++c) {
|
for (col_id_t c = 0; c < numOfCols; ++c) {
|
||||||
if (bufSize - len - tableDataLen < buffer) {
|
if (bufSize - len - tableDataLen < buffer) {
|
||||||
EXPECT_EQ(tsdbMakeRoom(&buf, bufSize + allocStep), 0);
|
ASSERT_EQ(tsdbMakeRoom(&buf, bufSize + allocStep), 0);
|
||||||
pSmaData = (STSmaDataWrapper *)buf;
|
pSmaData = (STSmaDataWrapper *)buf;
|
||||||
pTbData = (STSmaTbData *)POINTER_SHIFT(pSmaData, len);
|
pTbData = (STSmaTbData *)POINTER_SHIFT(pSmaData, len);
|
||||||
bufSize = taosTSizeof(buf);
|
bufSize = taosTSizeof(buf);
|
||||||
|
@ -353,22 +358,22 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
||||||
}
|
}
|
||||||
pSmaData->dataLen = (len - sizeof(STSmaDataWrapper));
|
pSmaData->dataLen = (len - sizeof(STSmaDataWrapper));
|
||||||
|
|
||||||
EXPECT_GE(bufSize, pSmaData->dataLen);
|
ASSERT_GE(bufSize, pSmaData->dataLen);
|
||||||
|
|
||||||
// execute
|
// execute
|
||||||
EXPECT_EQ(tsdbInsertTSmaData(&tsdb, (char *)pSmaData), TSDB_CODE_SUCCESS);
|
ASSERT_EQ(tsdbInsertTSmaData(&tsdb, (char *)pSmaData), TSDB_CODE_SUCCESS);
|
||||||
|
|
||||||
// step 3: query
|
// step 3: query
|
||||||
uint32_t checkDataCnt = 0;
|
uint32_t checkDataCnt = 0;
|
||||||
for (int32_t t = 0; t < numOfTables; ++t) {
|
for (int32_t t = 0; t < numOfTables; ++t) {
|
||||||
for (col_id_t c = 0; c < numOfCols; ++c) {
|
for (col_id_t c = 0; c < numOfCols; ++c) {
|
||||||
EXPECT_EQ(tsdbGetTSmaData(&tsdb, NULL, indexUid1, interval1, intervalUnit1, tbUid + t,
|
ASSERT_EQ(tsdbGetTSmaData(&tsdb, NULL, indexUid1, interval1, intervalUnit1, tbUid + t,
|
||||||
c + PRIMARYKEY_TIMESTAMP_COL_ID, skey1, 1),
|
c + PRIMARYKEY_TIMESTAMP_COL_ID, skey1, 1),
|
||||||
TSDB_CODE_SUCCESS);
|
TSDB_CODE_SUCCESS);
|
||||||
++checkDataCnt;
|
++checkDataCnt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%s:%d The sma data check count for insert and query is %" PRIu32 "\n", __FILE__, __LINE__, checkDataCnt);
|
printf("%s:%d The sma data check count for insert and query is %" PRIu32 "\n", __FILE__, __LINE__, checkDataCnt);
|
||||||
|
|
||||||
// release data
|
// release data
|
||||||
|
|
|
@ -1062,7 +1062,7 @@ int32_t ctgMetaRentInit(SCtgRentMgmt *mgmt, uint32_t rentSec, int8_t type) {
|
||||||
|
|
||||||
|
|
||||||
int32_t ctgMetaRentAdd(SCtgRentMgmt *mgmt, void *meta, int64_t id, int32_t size) {
|
int32_t ctgMetaRentAdd(SCtgRentMgmt *mgmt, void *meta, int64_t id, int32_t size) {
|
||||||
int16_t widx = abs(id % mgmt->slotNum);
|
int16_t widx = abs((int)(id % mgmt->slotNum));
|
||||||
|
|
||||||
SCtgRentSlot *slot = &mgmt->slots[widx];
|
SCtgRentSlot *slot = &mgmt->slots[widx];
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
@ -1092,11 +1092,11 @@ _return:
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ctgMetaRentUpdate(SCtgRentMgmt *mgmt, void *meta, int64_t id, int32_t size, __compar_fn_t sortCompare, __compar_fn_t searchCompare) {
|
int32_t ctgMetaRentUpdate(SCtgRentMgmt *mgmt, void *meta, int64_t id, int32_t size, __compar_fn_t sortCompare, __compar_fn_t searchCompare) {
|
||||||
int16_t widx = abs(id % mgmt->slotNum);
|
int16_t widx = abs((int)(id % mgmt->slotNum));
|
||||||
|
|
||||||
SCtgRentSlot *slot = &mgmt->slots[widx];
|
SCtgRentSlot *slot = &mgmt->slots[widx];
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
CTG_LOCK(CTG_WRITE, &slot->lock);
|
CTG_LOCK(CTG_WRITE, &slot->lock);
|
||||||
if (NULL == slot->meta) {
|
if (NULL == slot->meta) {
|
||||||
qError("empty meta slot, id:%"PRIx64", slot idx:%d, type:%d", id, widx, mgmt->type);
|
qError("empty meta slot, id:%"PRIx64", slot idx:%d, type:%d", id, widx, mgmt->type);
|
||||||
|
@ -1133,7 +1133,7 @@ _return:
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ctgMetaRentRemove(SCtgRentMgmt *mgmt, int64_t id, __compar_fn_t sortCompare, __compar_fn_t searchCompare) {
|
int32_t ctgMetaRentRemove(SCtgRentMgmt *mgmt, int64_t id, __compar_fn_t sortCompare, __compar_fn_t searchCompare) {
|
||||||
int16_t widx = abs(id % mgmt->slotNum);
|
int16_t widx = abs((int)(id % mgmt->slotNum));
|
||||||
|
|
||||||
SCtgRentSlot *slot = &mgmt->slots[widx];
|
SCtgRentSlot *slot = &mgmt->slots[widx];
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
|
@ -23,6 +23,7 @@ static SDataSinkManager gDataSinkManager = {0};
|
||||||
int32_t dsDataSinkMgtInit(SDataSinkMgtCfg *cfg) {
|
int32_t dsDataSinkMgtInit(SDataSinkMgtCfg *cfg) {
|
||||||
gDataSinkManager.cfg = *cfg;
|
gDataSinkManager.cfg = *cfg;
|
||||||
pthread_mutex_init(&gDataSinkManager.mutex, NULL);
|
pthread_mutex_init(&gDataSinkManager.mutex, NULL);
|
||||||
|
return 0; // to avoid compiler eror
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dsCreateDataSinker(const SDataSinkNode *pDataSink, DataSinkHandle* pHandle) {
|
int32_t dsCreateDataSinker(const SDataSinkNode *pDataSink, DataSinkHandle* pHandle) {
|
||||||
|
|
|
@ -413,7 +413,7 @@ int32_t tHashRemove(SLHashObj* pHashObj, const void *key, size_t keyLen) {
|
||||||
|
|
||||||
void tHashPrint(const SLHashObj* pHashObj, int32_t type) {
|
void tHashPrint(const SLHashObj* pHashObj, int32_t type) {
|
||||||
printf("==================== linear hash ====================\n");
|
printf("==================== linear hash ====================\n");
|
||||||
printf("total bucket:%d, size:%ld, ratio:%.2f\n", pHashObj->numOfBuckets, pHashObj->size, LHASH_CAP_RATIO);
|
printf("total bucket:%d, size:%" PRId64 ", ratio:%.2f\n", pHashObj->numOfBuckets, pHashObj->size, LHASH_CAP_RATIO);
|
||||||
|
|
||||||
dBufSetPrintInfo(pHashObj->pBuf);
|
dBufSetPrintInfo(pHashObj->pBuf);
|
||||||
|
|
||||||
|
@ -425,4 +425,4 @@ void tHashPrint(const SLHashObj* pHashObj, int32_t type) {
|
||||||
} else {
|
} else {
|
||||||
dBufPrintStatis(pHashObj->pBuf);
|
dBufPrintStatis(pHashObj->pBuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ SSDataBlock* getDummyBlock(SOperatorInfo* pOperator, bool* newgroup) {
|
||||||
//
|
//
|
||||||
// taosArrayPush(pInfo->pBlock->pDataBlock, &colInfo1);
|
// taosArrayPush(pInfo->pBlock->pDataBlock, &colInfo1);
|
||||||
} else {
|
} else {
|
||||||
blockDataClearup(pInfo->pBlock);
|
blockDataCleanup(pInfo->pBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
SSDataBlock* pBlock = pInfo->pBlock;
|
SSDataBlock* pBlock = pInfo->pBlock;
|
||||||
|
@ -151,7 +151,7 @@ SSDataBlock* get2ColsDummyBlock(SOperatorInfo* pOperator, bool* newgroup) {
|
||||||
|
|
||||||
taosArrayPush(pInfo->pBlock->pDataBlock, &colInfo1);
|
taosArrayPush(pInfo->pBlock->pDataBlock, &colInfo1);
|
||||||
} else {
|
} else {
|
||||||
blockDataClearup(pInfo->pBlock);
|
blockDataCleanup(pInfo->pBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
SSDataBlock* pBlock = pInfo->pBlock;
|
SSDataBlock* pBlock = pInfo->pBlock;
|
||||||
|
|
|
@ -240,6 +240,7 @@ int indexRebuild(SIndex* index, SIndexOpts* opts){
|
||||||
#ifdef USE_INVERTED_INDEX
|
#ifdef USE_INVERTED_INDEX
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SIndexOpts* indexOptsCreate() {
|
SIndexOpts* indexOptsCreate() {
|
||||||
|
|
|
@ -190,7 +190,10 @@ int indexCacheSchedToMerge(IndexCache* pCache) {
|
||||||
schedMsg.msg = NULL;
|
schedMsg.msg = NULL;
|
||||||
|
|
||||||
taosScheduleTask(indexQhandle, &schedMsg);
|
taosScheduleTask(indexQhandle, &schedMsg);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void indexCacheMakeRoomForWrite(IndexCache* cache) {
|
static void indexCacheMakeRoomForWrite(IndexCache* cache) {
|
||||||
while (true) {
|
while (true) {
|
||||||
if (cache->occupiedMem * MEM_ESTIMATE_RADIO < MEM_THRESHOLD) {
|
if (cache->occupiedMem * MEM_ESTIMATE_RADIO < MEM_THRESHOLD) {
|
||||||
|
|
|
@ -571,6 +571,8 @@ uint64_t fstStateFindInput(FstState* s, FstNode* node, uint8_t b, bool* null) {
|
||||||
}
|
}
|
||||||
fstSliceDestroy(&t);
|
fstSliceDestroy(&t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fst node function
|
// fst node function
|
||||||
|
@ -1027,6 +1029,8 @@ Fst* fstCreate(FstSlice* slice) {
|
||||||
FST_CREAT_FAILED:
|
FST_CREAT_FAILED:
|
||||||
free(fst->meta);
|
free(fst->meta);
|
||||||
free(fst);
|
free(fst);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
void fstDestroy(Fst* fst) {
|
void fstDestroy(Fst* fst) {
|
||||||
if (fst) {
|
if (fst) {
|
||||||
|
@ -1286,6 +1290,8 @@ bool streamWithStateSeekMin(StreamWithState* sws, FstBoundWithData* min) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallback callback) {
|
StreamWithStateResult* streamWithStateNextWith(StreamWithState* sws, StreamCallback callback) {
|
||||||
|
|
|
@ -151,8 +151,7 @@ static int32_t nodeListToJson(SJson* pJson, const char* pName, const SNodeList*
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t jsonToNodeList(const SJson* pJson, const char* pName, SNodeList** pList) {
|
static int32_t jsonToNodeListImpl(const SJson* pJsonArray, SNodeList** pList) {
|
||||||
const SJson* pJsonArray = tjsonGetObjectItem(pJson, pName);
|
|
||||||
int32_t size = (NULL == pJsonArray ? 0 : tjsonGetArraySize(pJsonArray));
|
int32_t size = (NULL == pJsonArray ? 0 : tjsonGetArraySize(pJsonArray));
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
*pList = nodesMakeList();
|
*pList = nodesMakeList();
|
||||||
|
@ -176,6 +175,10 @@ static int32_t jsonToNodeList(const SJson* pJson, const char* pName, SNodeList**
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t jsonToNodeList(const SJson* pJson, const char* pName, SNodeList** pList) {
|
||||||
|
return jsonToNodeListImpl(tjsonGetObjectItem(pJson, pName), pList);
|
||||||
|
}
|
||||||
|
|
||||||
static const char* jkTableMetaUid = "TableMetaUid";
|
static const char* jkTableMetaUid = "TableMetaUid";
|
||||||
static const char* jkTableMetaSuid = "TableMetaSuid";
|
static const char* jkTableMetaSuid = "TableMetaSuid";
|
||||||
|
|
||||||
|
@ -1727,7 +1730,7 @@ static int32_t jsonToNodeObject(const SJson* pJson, const char* pName, SNode** p
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t nodesNodeToString(const SNodeptr pNode, bool format, char** pStr, int32_t* pLen) {
|
int32_t nodesNodeToString(const SNodeptr pNode, bool format, char** pStr, int32_t* pLen) {
|
||||||
if (NULL == pNode || NULL == pStr || NULL == pLen) {
|
if (NULL == pNode || NULL == pStr) {
|
||||||
terrno = TSDB_CODE_FAILED;
|
terrno = TSDB_CODE_FAILED;
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
@ -1747,7 +1750,10 @@ int32_t nodesNodeToString(const SNodeptr pNode, bool format, char** pStr, int32_
|
||||||
*pStr = format ? tjsonToString(pJson) : tjsonToUnformattedString(pJson);
|
*pStr = format ? tjsonToString(pJson) : tjsonToUnformattedString(pJson);
|
||||||
tjsonDelete(pJson);
|
tjsonDelete(pJson);
|
||||||
|
|
||||||
*pLen = strlen(*pStr) + 1;
|
if (NULL != pLen) {
|
||||||
|
*pLen = strlen(*pStr) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1767,3 +1773,52 @@ int32_t nodesStringToNode(const char* pStr, SNode** pNode) {
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t nodesListToString(const SNodeList* pList, bool format, char** pStr, int32_t* pLen) {
|
||||||
|
if (NULL == pList || NULL == pStr || NULL == pLen) {
|
||||||
|
terrno = TSDB_CODE_FAILED;
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 == LIST_LENGTH(pList)) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
SJson* pJson = tjsonCreateArray();
|
||||||
|
if (NULL == pJson) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNode* pNode;
|
||||||
|
FOREACH(pNode, pList) {
|
||||||
|
int32_t code = tjsonAddItem(pJson, nodeToJson, pNode);
|
||||||
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
|
terrno = code;
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*pStr = format ? tjsonToString(pJson) : tjsonToUnformattedString(pJson);
|
||||||
|
tjsonDelete(pJson);
|
||||||
|
|
||||||
|
*pLen = strlen(*pStr) + 1;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t nodesStringToList(const char* pStr, SNodeList** pList) {
|
||||||
|
if (NULL == pStr || NULL == pList) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
SJson* pJson = tjsonParse(pStr);
|
||||||
|
if (NULL == pJson) {
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
int32_t code = jsonToNodeListImpl(pJson, pList);
|
||||||
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
|
nodesDestroyList(*pList);
|
||||||
|
terrno = code;
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
|
@ -76,6 +76,12 @@ SNodeptr nodesMakeNode(ENodeType type) {
|
||||||
return makeNode(type, sizeof(SColumnDefNode));
|
return makeNode(type, sizeof(SColumnDefNode));
|
||||||
case QUERY_NODE_DOWNSTREAM_SOURCE:
|
case QUERY_NODE_DOWNSTREAM_SOURCE:
|
||||||
return makeNode(type, sizeof(SDownstreamSourceNode));
|
return makeNode(type, sizeof(SDownstreamSourceNode));
|
||||||
|
case QUERY_NODE_DATABASE_OPTIONS:
|
||||||
|
return makeNode(type, sizeof(SDatabaseOptions));
|
||||||
|
case QUERY_NODE_TABLE_OPTIONS:
|
||||||
|
return makeNode(type, sizeof(STableOptions));
|
||||||
|
case QUERY_NODE_INDEX_OPTIONS:
|
||||||
|
return makeNode(type, sizeof(SIndexOptions));
|
||||||
case QUERY_NODE_SET_OPERATOR:
|
case QUERY_NODE_SET_OPERATOR:
|
||||||
return makeNode(type, sizeof(SSetOperator));
|
return makeNode(type, sizeof(SSetOperator));
|
||||||
case QUERY_NODE_SELECT_STMT:
|
case QUERY_NODE_SELECT_STMT:
|
||||||
|
@ -86,6 +92,8 @@ SNodeptr nodesMakeNode(ENodeType type) {
|
||||||
return makeNode(type, sizeof(SCreateDatabaseStmt));
|
return makeNode(type, sizeof(SCreateDatabaseStmt));
|
||||||
case QUERY_NODE_DROP_DATABASE_STMT:
|
case QUERY_NODE_DROP_DATABASE_STMT:
|
||||||
return makeNode(type, sizeof(SDropDatabaseStmt));
|
return makeNode(type, sizeof(SDropDatabaseStmt));
|
||||||
|
case QUERY_NODE_ALTER_DATABASE_STMT:
|
||||||
|
return makeNode(type, sizeof(SAlterDatabaseStmt));
|
||||||
case QUERY_NODE_SHOW_DATABASES_STMT:
|
case QUERY_NODE_SHOW_DATABASES_STMT:
|
||||||
return makeNode(type, sizeof(SShowStmt));
|
return makeNode(type, sizeof(SShowStmt));
|
||||||
case QUERY_NODE_CREATE_TABLE_STMT:
|
case QUERY_NODE_CREATE_TABLE_STMT:
|
||||||
|
@ -121,7 +129,20 @@ SNodeptr nodesMakeNode(ENodeType type) {
|
||||||
return makeNode(type, sizeof(SShowStmt));
|
return makeNode(type, sizeof(SShowStmt));
|
||||||
case QUERY_NODE_SHOW_VGROUPS_STMT:
|
case QUERY_NODE_SHOW_VGROUPS_STMT:
|
||||||
case QUERY_NODE_SHOW_MNODES_STMT:
|
case QUERY_NODE_SHOW_MNODES_STMT:
|
||||||
|
case QUERY_NODE_SHOW_QNODES_STMT:
|
||||||
return makeNode(type, sizeof(SShowStmt));
|
return makeNode(type, sizeof(SShowStmt));
|
||||||
|
case QUERY_NODE_CREATE_INDEX_STMT:
|
||||||
|
return makeNode(type, sizeof(SCreateIndexStmt));
|
||||||
|
case QUERY_NODE_DROP_INDEX_STMT:
|
||||||
|
return makeNode(type, sizeof(SDropIndexStmt));
|
||||||
|
case QUERY_NODE_CREATE_QNODE_STMT:
|
||||||
|
return makeNode(type, sizeof(SCreateQnodeStmt));
|
||||||
|
case QUERY_NODE_DROP_QNODE_STMT:
|
||||||
|
return makeNode(type, sizeof(SDropQnodeStmt));
|
||||||
|
case QUERY_NODE_CREATE_TOPIC_STMT:
|
||||||
|
return makeNode(type, sizeof(SCreateTopicStmt));
|
||||||
|
case QUERY_NODE_DROP_TOPIC_STMT:
|
||||||
|
return makeNode(type, sizeof(SDropTopicStmt));
|
||||||
case QUERY_NODE_LOGIC_PLAN_SCAN:
|
case QUERY_NODE_LOGIC_PLAN_SCAN:
|
||||||
return makeNode(type, sizeof(SScanLogicNode));
|
return makeNode(type, sizeof(SScanLogicNode));
|
||||||
case QUERY_NODE_LOGIC_PLAN_JOIN:
|
case QUERY_NODE_LOGIC_PLAN_JOIN:
|
||||||
|
@ -208,6 +229,14 @@ static EDealRes destroyNode(SNode** pNode, void* pContext) {
|
||||||
case QUERY_NODE_NODE_LIST:
|
case QUERY_NODE_NODE_LIST:
|
||||||
nodesClearList(((SNodeListNode*)(*pNode))->pNodeList);
|
nodesClearList(((SNodeListNode*)(*pNode))->pNodeList);
|
||||||
break;
|
break;
|
||||||
|
case QUERY_NODE_INDEX_OPTIONS: {
|
||||||
|
SIndexOptions* pStmt = (SIndexOptions*)*pNode;
|
||||||
|
nodesDestroyList(pStmt->pFuncs);
|
||||||
|
nodesDestroyNode(pStmt->pInterval);
|
||||||
|
nodesDestroyNode(pStmt->pOffset);
|
||||||
|
nodesDestroyNode(pStmt->pSliding);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case QUERY_NODE_SELECT_STMT: {
|
case QUERY_NODE_SELECT_STMT: {
|
||||||
SSelectStmt* pStmt = (SSelectStmt*)*pNode;
|
SSelectStmt* pStmt = (SSelectStmt*)*pNode;
|
||||||
nodesDestroyList(pStmt->pProjectionList);
|
nodesDestroyList(pStmt->pProjectionList);
|
||||||
|
@ -248,6 +277,12 @@ static EDealRes destroyNode(SNode** pNode, void* pContext) {
|
||||||
case QUERY_NODE_CREATE_MULTI_TABLE_STMT:
|
case QUERY_NODE_CREATE_MULTI_TABLE_STMT:
|
||||||
nodesDestroyList(((SCreateMultiTableStmt*)(*pNode))->pSubTables);
|
nodesDestroyList(((SCreateMultiTableStmt*)(*pNode))->pSubTables);
|
||||||
break;
|
break;
|
||||||
|
case QUERY_NODE_CREATE_INDEX_STMT: {
|
||||||
|
SCreateIndexStmt* pStmt = (SCreateIndexStmt*)*pNode;
|
||||||
|
nodesDestroyNode(pStmt->pOptions);
|
||||||
|
nodesDestroyList(pStmt->pCols);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,17 +109,18 @@ SNode* addLimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pLimit);
|
||||||
SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable);
|
SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable);
|
||||||
SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight);
|
SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight);
|
||||||
|
|
||||||
SDatabaseOptions* createDefaultDatabaseOptions(SAstCreateContext* pCxt);
|
SNode* createDefaultDatabaseOptions(SAstCreateContext* pCxt);
|
||||||
SDatabaseOptions* setDatabaseOption(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, EDatabaseOptionType type, const SToken* pVal);
|
SNode* setDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, EDatabaseOptionType type, const SToken* pVal);
|
||||||
SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pDbName, SDatabaseOptions* pOptions);
|
SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pDbName, SNode* pOptions);
|
||||||
SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pDbName);
|
SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pDbName);
|
||||||
STableOptions* createDefaultTableOptions(SAstCreateContext* pCxt);
|
SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName, SNode* pOptions);
|
||||||
STableOptions* setTableOption(SAstCreateContext* pCxt, STableOptions* pOptions, ETableOptionType type, const SToken* pVal);
|
SNode* createDefaultTableOptions(SAstCreateContext* pCxt);
|
||||||
STableOptions* setTableSmaOption(SAstCreateContext* pCxt, STableOptions* pOptions, SNodeList* pSma);
|
SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType type, const SToken* pVal);
|
||||||
|
SNode* setTableSmaOption(SAstCreateContext* pCxt, SNode* pOptions, SNodeList* pSma);
|
||||||
SNode* createColumnDefNode(SAstCreateContext* pCxt, const SToken* pColName, SDataType dataType, const SToken* pComment);
|
SNode* createColumnDefNode(SAstCreateContext* pCxt, const SToken* pColName, SDataType dataType, const SToken* pComment);
|
||||||
SDataType createDataType(uint8_t type);
|
SDataType createDataType(uint8_t type);
|
||||||
SDataType createVarLenDataType(uint8_t type, const SToken* pLen);
|
SDataType createVarLenDataType(uint8_t type, const SToken* pLen);
|
||||||
SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNodeList* pCols, SNodeList* pTags, STableOptions* pOptions);
|
SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNodeList* pCols, SNodeList* pTags, SNode* pOptions);
|
||||||
SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable, SNodeList* pSpecificTags, SNodeList* pValsOfTags);
|
SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable, SNodeList* pSpecificTags, SNodeList* pValsOfTags);
|
||||||
SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables);
|
SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables);
|
||||||
SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable);
|
SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable);
|
||||||
|
@ -132,6 +133,13 @@ SNode* createAlterUserStmt(SAstCreateContext* pCxt, const SToken* pUserName, int
|
||||||
SNode* createDropUserStmt(SAstCreateContext* pCxt, const SToken* pUserName);
|
SNode* createDropUserStmt(SAstCreateContext* pCxt, const SToken* pUserName);
|
||||||
SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const SToken* pPort);
|
SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const SToken* pPort);
|
||||||
SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode);
|
SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode);
|
||||||
|
SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, const SToken* pIndexName, const SToken* pTableName, SNodeList* pCols, SNode* pOptions);
|
||||||
|
SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset, SNode* pSliding);
|
||||||
|
SNode* createDropIndexStmt(SAstCreateContext* pCxt, const SToken* pIndexName, const SToken* pTableName);
|
||||||
|
SNode* createCreateQnodeStmt(SAstCreateContext* pCxt, const SToken* pDnodeId);
|
||||||
|
SNode* createDropQnodeStmt(SAstCreateContext* pCxt, const SToken* pDnodeId);
|
||||||
|
SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery, const SToken* pSubscribeDbName);
|
||||||
|
SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pTopicName);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,17 +42,17 @@
|
||||||
//%right NK_BITNOT.
|
//%right NK_BITNOT.
|
||||||
|
|
||||||
/************************************************ create/alter/drop/show user *****************************************/
|
/************************************************ create/alter/drop/show user *****************************************/
|
||||||
cmd ::= CREATE USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createCreateUserStmt(pCxt, &A, &B);}
|
cmd ::= CREATE USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createCreateUserStmt(pCxt, &A, &B); }
|
||||||
cmd ::= ALTER USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PASSWD, &B);}
|
cmd ::= ALTER USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PASSWD, &B); }
|
||||||
cmd ::= ALTER USER user_name(A) PRIVILEGE NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PRIVILEGES, &B);}
|
cmd ::= ALTER USER user_name(A) PRIVILEGE NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PRIVILEGES, &B); }
|
||||||
cmd ::= DROP USER user_name(A). { pCxt->pRootNode = createDropUserStmt(pCxt, &A); }
|
cmd ::= DROP USER user_name(A). { pCxt->pRootNode = createDropUserStmt(pCxt, &A); }
|
||||||
cmd ::= SHOW USERS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT, NULL); }
|
cmd ::= SHOW USERS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT, NULL); }
|
||||||
|
|
||||||
/************************************************ create/drop/show dnode **********************************************/
|
/************************************************ create/drop/show dnode **********************************************/
|
||||||
cmd ::= CREATE DNODE dnode_endpoint(A). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, NULL);}
|
cmd ::= CREATE DNODE dnode_endpoint(A). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, NULL); }
|
||||||
cmd ::= CREATE DNODE dnode_host_name(A) PORT NK_INTEGER(B). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, &B);}
|
cmd ::= CREATE DNODE dnode_host_name(A) PORT NK_INTEGER(B). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, &B); }
|
||||||
cmd ::= DROP DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A);}
|
cmd ::= DROP DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A); }
|
||||||
cmd ::= DROP DNODE dnode_endpoint(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A);}
|
cmd ::= DROP DNODE dnode_endpoint(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A); }
|
||||||
cmd ::= SHOW DNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL); }
|
cmd ::= SHOW DNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL); }
|
||||||
|
|
||||||
%type dnode_endpoint { SToken }
|
%type dnode_endpoint { SToken }
|
||||||
|
@ -64,11 +64,17 @@ dnode_endpoint(A) ::= NK_STRING(B).
|
||||||
dnode_host_name(A) ::= NK_ID(B). { A = B; }
|
dnode_host_name(A) ::= NK_ID(B). { A = B; }
|
||||||
dnode_host_name(A) ::= NK_IPTOKEN(B). { A = B; }
|
dnode_host_name(A) ::= NK_IPTOKEN(B). { A = B; }
|
||||||
|
|
||||||
|
/************************************************ create/drop qnode ***************************************************/
|
||||||
|
cmd ::= CREATE QNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createCreateQnodeStmt(pCxt, &A); }
|
||||||
|
cmd ::= DROP QNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropQnodeStmt(pCxt, &A); }
|
||||||
|
cmd ::= SHOW QNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT, NULL); }
|
||||||
|
|
||||||
/************************************************ create/drop/show/use database ***************************************/
|
/************************************************ create/drop/show/use database ***************************************/
|
||||||
cmd ::= CREATE DATABASE not_exists_opt(A) db_name(B) db_options(C). { pCxt->pRootNode = createCreateDatabaseStmt(pCxt, A, &B, C);}
|
cmd ::= CREATE DATABASE not_exists_opt(A) db_name(B) db_options(C). { pCxt->pRootNode = createCreateDatabaseStmt(pCxt, A, &B, C); }
|
||||||
cmd ::= DROP DATABASE exists_opt(A) db_name(B). { pCxt->pRootNode = createDropDatabaseStmt(pCxt, A, &B); }
|
cmd ::= DROP DATABASE exists_opt(A) db_name(B). { pCxt->pRootNode = createDropDatabaseStmt(pCxt, A, &B); }
|
||||||
cmd ::= SHOW DATABASES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL); }
|
cmd ::= SHOW DATABASES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL); }
|
||||||
cmd ::= USE db_name(A). { pCxt->pRootNode = createUseDatabaseStmt(pCxt, &A);}
|
cmd ::= USE db_name(A). { pCxt->pRootNode = createUseDatabaseStmt(pCxt, &A); }
|
||||||
|
cmd ::= ALTER DATABASE db_name(A) db_options(B). { pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &A, B); }
|
||||||
|
|
||||||
%type not_exists_opt { bool }
|
%type not_exists_opt { bool }
|
||||||
%destructor not_exists_opt { }
|
%destructor not_exists_opt { }
|
||||||
|
@ -80,8 +86,6 @@ not_exists_opt(A) ::= .
|
||||||
exists_opt(A) ::= IF EXISTS. { A = true; }
|
exists_opt(A) ::= IF EXISTS. { A = true; }
|
||||||
exists_opt(A) ::= . { A = false; }
|
exists_opt(A) ::= . { A = false; }
|
||||||
|
|
||||||
%type db_options { SDatabaseOptions* }
|
|
||||||
%destructor db_options { tfree($$); }
|
|
||||||
db_options(A) ::= . { A = createDefaultDatabaseOptions(pCxt); }
|
db_options(A) ::= . { A = createDefaultDatabaseOptions(pCxt); }
|
||||||
db_options(A) ::= db_options(B) BLOCKS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_BLOCKS, &C); }
|
db_options(A) ::= db_options(B) BLOCKS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_BLOCKS, &C); }
|
||||||
db_options(A) ::= db_options(B) CACHE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_CACHE, &C); }
|
db_options(A) ::= db_options(B) CACHE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_CACHE, &C); }
|
||||||
|
@ -179,8 +183,6 @@ tags_def_opt(A) ::= tags_def(B).
|
||||||
%destructor tags_def { nodesDestroyList($$); }
|
%destructor tags_def { nodesDestroyList($$); }
|
||||||
tags_def(A) ::= TAGS NK_LP column_def_list(B) NK_RP. { A = B; }
|
tags_def(A) ::= TAGS NK_LP column_def_list(B) NK_RP. { A = B; }
|
||||||
|
|
||||||
%type table_options { STableOptions* }
|
|
||||||
%destructor table_options { tfree($$); }
|
|
||||||
table_options(A) ::= . { A = createDefaultTableOptions(pCxt);}
|
table_options(A) ::= . { A = createDefaultTableOptions(pCxt);}
|
||||||
table_options(A) ::= table_options(B) COMMENT NK_STRING(C). { A = setTableOption(pCxt, B, TABLE_OPTION_COMMENT, &C); }
|
table_options(A) ::= table_options(B) COMMENT NK_STRING(C). { A = setTableOption(pCxt, B, TABLE_OPTION_COMMENT, &C); }
|
||||||
table_options(A) ::= table_options(B) KEEP NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_KEEP, &C); }
|
table_options(A) ::= table_options(B) KEEP NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_KEEP, &C); }
|
||||||
|
@ -194,6 +196,30 @@ col_name_list(A) ::= col_name_list(B) NK_COMMA col_name(C).
|
||||||
|
|
||||||
col_name(A) ::= column_name(B). { A = createColumnNode(pCxt, NULL, &B); }
|
col_name(A) ::= column_name(B). { A = createColumnNode(pCxt, NULL, &B); }
|
||||||
|
|
||||||
|
/************************************************ create index ********************************************************/
|
||||||
|
cmd ::= CREATE SMA INDEX index_name(A) ON table_name(B) index_options(C). { pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, &A, &B, NULL, C); }
|
||||||
|
cmd ::= CREATE FULLTEXT INDEX
|
||||||
|
index_name(A) ON table_name(B) NK_LP col_name_list(C) NK_RP. { pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, &A, &B, C, NULL); }
|
||||||
|
cmd ::= DROP INDEX index_name(A) ON table_name(B). { pCxt->pRootNode = createDropIndexStmt(pCxt, &A, &B); }
|
||||||
|
|
||||||
|
index_options(A) ::= . { A = NULL; }
|
||||||
|
index_options(A) ::= FUNCTION NK_LP func_list(B) NK_RP INTERVAL
|
||||||
|
NK_LP duration_literal(C) NK_RP sliding_opt(D). { A = createIndexOption(pCxt, B, releaseRawExprNode(pCxt, C), NULL, D); }
|
||||||
|
index_options(A) ::= FUNCTION NK_LP func_list(B) NK_RP INTERVAL
|
||||||
|
NK_LP duration_literal(C) NK_COMMA duration_literal(D) NK_RP sliding_opt(E). { A = createIndexOption(pCxt, B, releaseRawExprNode(pCxt, C), releaseRawExprNode(pCxt, D), E); }
|
||||||
|
|
||||||
|
%type func_list { SNodeList* }
|
||||||
|
%destructor func_list { nodesDestroyList($$); }
|
||||||
|
func_list(A) ::= func(B). { A = createNodeList(pCxt, B); }
|
||||||
|
func_list(A) ::= func_list(B) NK_COMMA func(C). { A = addNodeToList(pCxt, B, C); }
|
||||||
|
|
||||||
|
func(A) ::= function_name(B) NK_LP expression_list(C) NK_RP. { A = createFunctionNode(pCxt, &B, C); }
|
||||||
|
|
||||||
|
/************************************************ create/drop topic ***************************************************/
|
||||||
|
cmd ::= CREATE TOPIC not_exists_opt(A) topic_name(B) AS query_expression(C). { pCxt->pRootNode = createCreateTopicStmt(pCxt, A, &B, C, NULL); }
|
||||||
|
cmd ::= CREATE TOPIC not_exists_opt(A) topic_name(B) AS db_name(C). { pCxt->pRootNode = createCreateTopicStmt(pCxt, A, &B, NULL, &C); }
|
||||||
|
cmd ::= DROP TOPIC exists_opt(A) topic_name(B). { pCxt->pRootNode = createDropTopicStmt(pCxt, A, &B); }
|
||||||
|
|
||||||
/************************************************ show vgroups ********************************************************/
|
/************************************************ show vgroups ********************************************************/
|
||||||
cmd ::= SHOW VGROUPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, NULL); }
|
cmd ::= SHOW VGROUPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, NULL); }
|
||||||
cmd ::= SHOW db_name(B) NK_DOT VGROUPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, &B); }
|
cmd ::= SHOW db_name(B) NK_DOT VGROUPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, &B); }
|
||||||
|
@ -248,6 +274,14 @@ column_alias(A) ::= NK_ID(B).
|
||||||
%destructor user_name { }
|
%destructor user_name { }
|
||||||
user_name(A) ::= NK_ID(B). { A = B; }
|
user_name(A) ::= NK_ID(B). { A = B; }
|
||||||
|
|
||||||
|
%type index_name { SToken }
|
||||||
|
%destructor index_name { }
|
||||||
|
index_name(A) ::= NK_ID(B). { A = B; }
|
||||||
|
|
||||||
|
%type topic_name { SToken }
|
||||||
|
%destructor topic_name { }
|
||||||
|
topic_name(A) ::= NK_ID(B). { A = B; }
|
||||||
|
|
||||||
/************************************************ expression **********************************************************/
|
/************************************************ expression **********************************************************/
|
||||||
expression(A) ::= literal(B). { A = B; }
|
expression(A) ::= literal(B). { A = B; }
|
||||||
//expression(A) ::= NK_QUESTION(B). { A = B; }
|
//expression(A) ::= NK_QUESTION(B). { A = B; }
|
||||||
|
@ -463,13 +497,13 @@ twindow_clause_opt(A) ::=
|
||||||
SESSION NK_LP column_reference(B) NK_COMMA NK_INTEGER(C) NK_RP. { A = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, B), &C); }
|
SESSION NK_LP column_reference(B) NK_COMMA NK_INTEGER(C) NK_RP. { A = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, B), &C); }
|
||||||
twindow_clause_opt(A) ::= STATE_WINDOW NK_LP column_reference(B) NK_RP. { A = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, B)); }
|
twindow_clause_opt(A) ::= STATE_WINDOW NK_LP column_reference(B) NK_RP. { A = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, B)); }
|
||||||
twindow_clause_opt(A) ::=
|
twindow_clause_opt(A) ::=
|
||||||
INTERVAL NK_LP duration_literal(B) NK_RP sliding_opt(C) fill_opt(D). { A = createIntervalWindowNode(pCxt, B, NULL, C, D); }
|
INTERVAL NK_LP duration_literal(B) NK_RP sliding_opt(C) fill_opt(D). { A = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, B), NULL, C, D); }
|
||||||
twindow_clause_opt(A) ::=
|
twindow_clause_opt(A) ::=
|
||||||
INTERVAL NK_LP duration_literal(B) NK_COMMA duration_literal(C) NK_RP
|
INTERVAL NK_LP duration_literal(B) NK_COMMA duration_literal(C) NK_RP
|
||||||
sliding_opt(D) fill_opt(E). { A = createIntervalWindowNode(pCxt, B, C, D, E); }
|
sliding_opt(D) fill_opt(E). { A = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C), D, E); }
|
||||||
|
|
||||||
sliding_opt(A) ::= . { A = NULL; }
|
sliding_opt(A) ::= . { A = NULL; }
|
||||||
sliding_opt(A) ::= SLIDING NK_LP duration_literal(B) NK_RP. { A = B; }
|
sliding_opt(A) ::= SLIDING NK_LP duration_literal(B) NK_RP. { A = releaseRawExprNode(pCxt, B); }
|
||||||
|
|
||||||
fill_opt(A) ::= . { A = NULL; }
|
fill_opt(A) ::= . { A = NULL; }
|
||||||
fill_opt(A) ::= FILL NK_LP fill_mode(B) NK_RP. { A = createFillNode(pCxt, B, NULL); }
|
fill_opt(A) ::= FILL NK_LP fill_mode(B) NK_RP. { A = createFillNode(pCxt, B, NULL); }
|
||||||
|
|
|
@ -420,6 +420,14 @@ static bool checkColumnName(SAstCreateContext* pCxt, const SToken* pColumnName)
|
||||||
return pCxt->valid;
|
return pCxt->valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool checkIndexName(SAstCreateContext* pCxt, const SToken* pIndexName) {
|
||||||
|
if (NULL == pIndexName) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
pCxt->valid = pIndexName->n < TSDB_INDEX_NAME_LEN ? true : false;
|
||||||
|
return pCxt->valid;
|
||||||
|
}
|
||||||
|
|
||||||
SNode* createRawExprNode(SAstCreateContext* pCxt, const SToken* pToken, SNode* pNode) {
|
SNode* createRawExprNode(SAstCreateContext* pCxt, const SToken* pToken, SNode* pNode) {
|
||||||
SRawExprNode* target = (SRawExprNode*)nodesMakeNode(QUERY_NODE_RAW_EXPR);
|
SRawExprNode* target = (SRawExprNode*)nodesMakeNode(QUERY_NODE_RAW_EXPR);
|
||||||
CHECK_OUT_OF_MEM(target);
|
CHECK_OUT_OF_MEM(target);
|
||||||
|
@ -741,8 +749,8 @@ SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode*
|
||||||
return (SNode*)setOp;
|
return (SNode*)setOp;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDatabaseOptions* createDefaultDatabaseOptions(SAstCreateContext* pCxt) {
|
SNode* createDefaultDatabaseOptions(SAstCreateContext* pCxt) {
|
||||||
SDatabaseOptions* pOptions = calloc(1, sizeof(SDatabaseOptions));
|
SDatabaseOptions* pOptions = nodesMakeNode(QUERY_NODE_DATABASE_OPTIONS);
|
||||||
CHECK_OUT_OF_MEM(pOptions);
|
CHECK_OUT_OF_MEM(pOptions);
|
||||||
pOptions->numOfBlocks = TSDB_DEFAULT_TOTAL_BLOCKS;
|
pOptions->numOfBlocks = TSDB_DEFAULT_TOTAL_BLOCKS;
|
||||||
pOptions->cacheBlockSize = TSDB_DEFAULT_CACHE_BLOCK_SIZE;
|
pOptions->cacheBlockSize = TSDB_DEFAULT_CACHE_BLOCK_SIZE;
|
||||||
|
@ -761,14 +769,14 @@ SDatabaseOptions* createDefaultDatabaseOptions(SAstCreateContext* pCxt) {
|
||||||
pOptions->numOfVgroups = TSDB_DEFAULT_VN_PER_DB;
|
pOptions->numOfVgroups = TSDB_DEFAULT_VN_PER_DB;
|
||||||
pOptions->singleStable = TSDB_DEFAULT_DB_SINGLE_STABLE_OPTION;
|
pOptions->singleStable = TSDB_DEFAULT_DB_SINGLE_STABLE_OPTION;
|
||||||
pOptions->streamMode = TSDB_DEFAULT_DB_STREAM_MODE_OPTION;
|
pOptions->streamMode = TSDB_DEFAULT_DB_STREAM_MODE_OPTION;
|
||||||
return pOptions;
|
return (SNode*)pOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDatabaseOptions* setDatabaseOption(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, EDatabaseOptionType type, const SToken* pVal) {
|
SNode* setDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, EDatabaseOptionType type, const SToken* pVal) {
|
||||||
return setDbOptionFuncs[type](pCxt, pOptions, pVal);
|
return (SNode*)setDbOptionFuncs[type](pCxt, (SDatabaseOptions*)pOptions, pVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pDbName, SDatabaseOptions* pOptions) {
|
SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pDbName, SNode* pOptions) {
|
||||||
if (!checkDbName(pCxt, pDbName)) {
|
if (!checkDbName(pCxt, pDbName)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -776,8 +784,7 @@ SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, cons
|
||||||
CHECK_OUT_OF_MEM(pStmt);
|
CHECK_OUT_OF_MEM(pStmt);
|
||||||
strncpy(pStmt->dbName, pDbName->z, pDbName->n);
|
strncpy(pStmt->dbName, pDbName->z, pDbName->n);
|
||||||
pStmt->ignoreExists = ignoreExists;
|
pStmt->ignoreExists = ignoreExists;
|
||||||
pStmt->options = *pOptions;
|
pStmt->pOptions = (SDatabaseOptions*)pOptions;
|
||||||
tfree(pOptions);
|
|
||||||
return (SNode*)pStmt;
|
return (SNode*)pStmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -792,20 +799,31 @@ SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, con
|
||||||
return (SNode*)pStmt;
|
return (SNode*)pStmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
STableOptions* createDefaultTableOptions(SAstCreateContext* pCxt) {
|
SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName, SNode* pOptions) {
|
||||||
STableOptions* pOptions = calloc(1, sizeof(STableOptions));
|
if (!checkDbName(pCxt, pDbName)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
SAlterDatabaseStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_DATABASE_STMT);
|
||||||
|
CHECK_OUT_OF_MEM(pStmt);
|
||||||
|
strncpy(pStmt->dbName, pDbName->z, pDbName->n);
|
||||||
|
pStmt->pOptions = (SDatabaseOptions*)pOptions;
|
||||||
|
return (SNode*)pStmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNode* createDefaultTableOptions(SAstCreateContext* pCxt) {
|
||||||
|
STableOptions* pOptions = nodesMakeNode(QUERY_NODE_TABLE_OPTIONS);
|
||||||
CHECK_OUT_OF_MEM(pOptions);
|
CHECK_OUT_OF_MEM(pOptions);
|
||||||
pOptions->keep = TSDB_DEFAULT_KEEP;
|
pOptions->keep = TSDB_DEFAULT_KEEP;
|
||||||
pOptions->ttl = TSDB_DEFAULT_DB_TTL_OPTION;
|
pOptions->ttl = TSDB_DEFAULT_DB_TTL_OPTION;
|
||||||
return pOptions;
|
return (SNode*)pOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
STableOptions* setTableOption(SAstCreateContext* pCxt, STableOptions* pOptions, ETableOptionType type, const SToken* pVal) {
|
SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType type, const SToken* pVal) {
|
||||||
return setTableOptionFuncs[type](pCxt, pOptions, pVal);
|
return (SNode*)setTableOptionFuncs[type](pCxt, (STableOptions*)pOptions, pVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
STableOptions* setTableSmaOption(SAstCreateContext* pCxt, STableOptions* pOptions, SNodeList* pSma) {
|
SNode* setTableSmaOption(SAstCreateContext* pCxt, SNode* pOptions, SNodeList* pSma) {
|
||||||
pOptions->pSma = pSma;
|
((STableOptions*)pOptions)->pSma = pSma;
|
||||||
return pOptions;
|
return pOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -831,7 +849,7 @@ SDataType createVarLenDataType(uint8_t type, const SToken* pLen) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SNode* createCreateTableStmt(SAstCreateContext* pCxt,
|
SNode* createCreateTableStmt(SAstCreateContext* pCxt,
|
||||||
bool ignoreExists, SNode* pRealTable, SNodeList* pCols, SNodeList* pTags, STableOptions* pOptions) {
|
bool ignoreExists, SNode* pRealTable, SNodeList* pCols, SNodeList* pTags, SNode* pOptions) {
|
||||||
SCreateTableStmt* pStmt = (SCreateTableStmt*)nodesMakeNode(QUERY_NODE_CREATE_TABLE_STMT);
|
SCreateTableStmt* pStmt = (SCreateTableStmt*)nodesMakeNode(QUERY_NODE_CREATE_TABLE_STMT);
|
||||||
CHECK_OUT_OF_MEM(pStmt);
|
CHECK_OUT_OF_MEM(pStmt);
|
||||||
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
|
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
|
||||||
|
@ -839,9 +857,7 @@ SNode* createCreateTableStmt(SAstCreateContext* pCxt,
|
||||||
pStmt->ignoreExists = ignoreExists;
|
pStmt->ignoreExists = ignoreExists;
|
||||||
pStmt->pCols = pCols;
|
pStmt->pCols = pCols;
|
||||||
pStmt->pTags = pTags;
|
pStmt->pTags = pTags;
|
||||||
pStmt->options = *pOptions;
|
pStmt->pOptions = (STableOptions*)pOptions;
|
||||||
nodesDestroyList(pOptions->pSma);
|
|
||||||
tfree(pOptions);
|
|
||||||
nodesDestroyNode(pRealTable);
|
nodesDestroyNode(pRealTable);
|
||||||
return (SNode*)pStmt;
|
return (SNode*)pStmt;
|
||||||
}
|
}
|
||||||
|
@ -992,3 +1008,72 @@ SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode) {
|
||||||
}
|
}
|
||||||
return (SNode*)pStmt;
|
return (SNode*)pStmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, const SToken* pIndexName, const SToken* pTableName, SNodeList* pCols, SNode* pOptions) {
|
||||||
|
if (!checkIndexName(pCxt, pIndexName) || !checkTableName(pCxt, pTableName)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
SCreateIndexStmt* pStmt = nodesMakeNode(QUERY_NODE_CREATE_INDEX_STMT);
|
||||||
|
CHECK_OUT_OF_MEM(pStmt);
|
||||||
|
pStmt->indexType = type;
|
||||||
|
strncpy(pStmt->indexName, pIndexName->z, pIndexName->n);
|
||||||
|
strncpy(pStmt->tableName, pTableName->z, pTableName->n);
|
||||||
|
pStmt->pCols = pCols;
|
||||||
|
pStmt->pOptions = (SIndexOptions*)pOptions;
|
||||||
|
return (SNode*)pStmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset, SNode* pSliding) {
|
||||||
|
SIndexOptions* pOptions = nodesMakeNode(QUERY_NODE_INDEX_OPTIONS);
|
||||||
|
CHECK_OUT_OF_MEM(pOptions);
|
||||||
|
pOptions->pFuncs = pFuncs;
|
||||||
|
pOptions->pInterval = pInterval;
|
||||||
|
pOptions->pOffset = pOffset;
|
||||||
|
pOptions->pSliding = pSliding;
|
||||||
|
return (SNode*)pOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNode* createDropIndexStmt(SAstCreateContext* pCxt, const SToken* pIndexName, const SToken* pTableName) {
|
||||||
|
if (!checkIndexName(pCxt, pIndexName) || !checkTableName(pCxt, pTableName)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
SDropIndexStmt* pStmt = nodesMakeNode(QUERY_NODE_DROP_INDEX_STMT);
|
||||||
|
CHECK_OUT_OF_MEM(pStmt);
|
||||||
|
strncpy(pStmt->indexName, pIndexName->z, pIndexName->n);
|
||||||
|
strncpy(pStmt->tableName, pTableName->z, pTableName->n);
|
||||||
|
return (SNode*)pStmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNode* createCreateQnodeStmt(SAstCreateContext* pCxt, const SToken* pDnodeId) {
|
||||||
|
SCreateQnodeStmt* pStmt = nodesMakeNode(QUERY_NODE_CREATE_QNODE_STMT);
|
||||||
|
CHECK_OUT_OF_MEM(pStmt);
|
||||||
|
pStmt->dnodeId = strtol(pDnodeId->z, NULL, 10);;
|
||||||
|
return (SNode*)pStmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNode* createDropQnodeStmt(SAstCreateContext* pCxt, const SToken* pDnodeId) {
|
||||||
|
SDropQnodeStmt* pStmt = nodesMakeNode(QUERY_NODE_DROP_QNODE_STMT);
|
||||||
|
CHECK_OUT_OF_MEM(pStmt);
|
||||||
|
pStmt->dnodeId = strtol(pDnodeId->z, NULL, 10);;
|
||||||
|
return (SNode*)pStmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery, const SToken* pSubscribeDbName) {
|
||||||
|
SCreateTopicStmt* pStmt = nodesMakeNode(QUERY_NODE_CREATE_TOPIC_STMT);
|
||||||
|
CHECK_OUT_OF_MEM(pStmt);
|
||||||
|
strncpy(pStmt->topicName, pTopicName->z, pTopicName->n);
|
||||||
|
pStmt->ignoreExists = ignoreExists;
|
||||||
|
pStmt->pQuery = pQuery;
|
||||||
|
if (NULL != pSubscribeDbName) {
|
||||||
|
strncpy(pStmt->subscribeDbName, pSubscribeDbName->z, pSubscribeDbName->n);
|
||||||
|
}
|
||||||
|
return (SNode*)pStmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pTopicName) {
|
||||||
|
SDropTopicStmt* pStmt = nodesMakeNode(QUERY_NODE_DROP_TOPIC_STMT);
|
||||||
|
CHECK_OUT_OF_MEM(pStmt);
|
||||||
|
strncpy(pStmt->topicName, pTopicName->z, pTopicName->n);
|
||||||
|
pStmt->ignoreNotExists = ignoreNotExists;
|
||||||
|
return (SNode*)pStmt;
|
||||||
|
}
|
||||||
|
|
|
@ -617,7 +617,7 @@ static FORCE_INLINE int32_t MemRowAppend(const void* value, int32_t len, void* p
|
||||||
if (TSDB_DATA_TYPE_BINARY == pa->schema->type) {
|
if (TSDB_DATA_TYPE_BINARY == pa->schema->type) {
|
||||||
const char* rowEnd = tdRowEnd(rb->pBuf);
|
const char* rowEnd = tdRowEnd(rb->pBuf);
|
||||||
STR_WITH_SIZE_TO_VARSTR(rowEnd, value, len);
|
STR_WITH_SIZE_TO_VARSTR(rowEnd, value, len);
|
||||||
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, rowEnd, false, pa->toffset, pa->colIdx);
|
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, rowEnd, true, pa->toffset, pa->colIdx);
|
||||||
} else if (TSDB_DATA_TYPE_NCHAR == pa->schema->type) {
|
} else if (TSDB_DATA_TYPE_NCHAR == pa->schema->type) {
|
||||||
// if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long'
|
// if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long'
|
||||||
int32_t output = 0;
|
int32_t output = 0;
|
||||||
|
@ -629,9 +629,9 @@ static FORCE_INLINE int32_t MemRowAppend(const void* value, int32_t len, void* p
|
||||||
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, rowEnd, false, pa->toffset, pa->colIdx);
|
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, rowEnd, false, pa->toffset, pa->colIdx);
|
||||||
} else {
|
} else {
|
||||||
if (value == NULL) { // it is a null data
|
if (value == NULL) { // it is a null data
|
||||||
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NULL, value, true, pa->toffset, pa->colIdx);
|
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NULL, value, false, pa->toffset, pa->colIdx);
|
||||||
} else {
|
} else {
|
||||||
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, value, true, pa->toffset, pa->colIdx);
|
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, value, false, pa->toffset, pa->colIdx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -767,6 +767,8 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pTagsSchema,
|
||||||
// todo construct payload
|
// todo construct payload
|
||||||
|
|
||||||
tfree(row);
|
tfree(row);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// pSql -> stb_name [(tag1_name, ...)] TAGS (tag1_value, ...)
|
// pSql -> stb_name [(tag1_name, ...)] TAGS (tag1_value, ...)
|
||||||
|
|
|
@ -59,11 +59,13 @@ static SKeyword keywordTable[] = {
|
||||||
{"FLOAT", TK_FLOAT},
|
{"FLOAT", TK_FLOAT},
|
||||||
{"FROM", TK_FROM},
|
{"FROM", TK_FROM},
|
||||||
{"FSYNC", TK_FSYNC},
|
{"FSYNC", TK_FSYNC},
|
||||||
|
{"FUNCTION", TK_FUNCTION},
|
||||||
{"GROUP", TK_GROUP},
|
{"GROUP", TK_GROUP},
|
||||||
{"HAVING", TK_HAVING},
|
{"HAVING", TK_HAVING},
|
||||||
{"IF", TK_IF},
|
{"IF", TK_IF},
|
||||||
{"IMPORT", TK_IMPORT},
|
{"IMPORT", TK_IMPORT},
|
||||||
{"IN", TK_IN},
|
{"IN", TK_IN},
|
||||||
|
{"INDEX", TK_INDEX},
|
||||||
{"INNER", TK_INNER},
|
{"INNER", TK_INNER},
|
||||||
{"INT", TK_INT},
|
{"INT", TK_INT},
|
||||||
{"INSERT", TK_INSERT},
|
{"INSERT", TK_INSERT},
|
||||||
|
@ -97,6 +99,8 @@ static SKeyword keywordTable[] = {
|
||||||
{"PRECISION", TK_PRECISION},
|
{"PRECISION", TK_PRECISION},
|
||||||
{"PRIVILEGE", TK_PRIVILEGE},
|
{"PRIVILEGE", TK_PRIVILEGE},
|
||||||
{"PREV", TK_PREV},
|
{"PREV", TK_PREV},
|
||||||
|
{"QNODE", TK_QNODE},
|
||||||
|
{"QNODES", TK_QNODES},
|
||||||
{"QUORUM", TK_QUORUM},
|
{"QUORUM", TK_QUORUM},
|
||||||
{"REPLICA", TK_REPLICA},
|
{"REPLICA", TK_REPLICA},
|
||||||
{"SELECT", TK_SELECT},
|
{"SELECT", TK_SELECT},
|
||||||
|
@ -117,6 +121,7 @@ static SKeyword keywordTable[] = {
|
||||||
{"TAGS", TK_TAGS},
|
{"TAGS", TK_TAGS},
|
||||||
{"TIMESTAMP", TK_TIMESTAMP},
|
{"TIMESTAMP", TK_TIMESTAMP},
|
||||||
{"TINYINT", TK_TINYINT},
|
{"TINYINT", TK_TINYINT},
|
||||||
|
{"TOPIC", TK_TOPIC},
|
||||||
{"TTL", TK_TTL},
|
{"TTL", TK_TTL},
|
||||||
{"UNION", TK_UNION},
|
{"UNION", TK_UNION},
|
||||||
{"UNSIGNED", TK_UNSIGNED},
|
{"UNSIGNED", TK_UNSIGNED},
|
||||||
|
@ -226,11 +231,9 @@ static SKeyword keywordTable[] = {
|
||||||
// {"TBNAME", TK_TBNAME},
|
// {"TBNAME", TK_TBNAME},
|
||||||
// {"VNODES", TK_VNODES},
|
// {"VNODES", TK_VNODES},
|
||||||
// {"PARTITIONS", TK_PARTITIONS},
|
// {"PARTITIONS", TK_PARTITIONS},
|
||||||
// {"TOPIC", TK_TOPIC},
|
|
||||||
// {"TOPICS", TK_TOPICS},
|
// {"TOPICS", TK_TOPICS},
|
||||||
// {"COMPACT", TK_COMPACT},
|
// {"COMPACT", TK_COMPACT},
|
||||||
// {"MODIFY", TK_MODIFY},
|
// {"MODIFY", TK_MODIFY},
|
||||||
// {"FUNCTION", TK_FUNCTION},
|
|
||||||
// {"FUNCTIONS", TK_FUNCTIONS},
|
// {"FUNCTIONS", TK_FUNCTIONS},
|
||||||
// {"OUTPUTTYPE", TK_OUTPUTTYPE},
|
// {"OUTPUTTYPE", TK_OUTPUTTYPE},
|
||||||
// {"AGGREGATE", TK_AGGREGATE},
|
// {"AGGREGATE", TK_AGGREGATE},
|
||||||
|
|
|
@ -21,14 +21,6 @@
|
||||||
#include "parUtil.h"
|
#include "parUtil.h"
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
|
|
||||||
static bool afterGroupBy(ESqlClause clause) {
|
|
||||||
return clause > SQL_CLAUSE_GROUP_BY;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool beforeHaving(ESqlClause clause) {
|
|
||||||
return clause < SQL_CLAUSE_HAVING;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct STranslateContext {
|
typedef struct STranslateContext {
|
||||||
SParseContext* pParseCxt;
|
SParseContext* pParseCxt;
|
||||||
int32_t errCode;
|
int32_t errCode;
|
||||||
|
@ -41,6 +33,15 @@ typedef struct STranslateContext {
|
||||||
} STranslateContext;
|
} STranslateContext;
|
||||||
|
|
||||||
static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode);
|
static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode);
|
||||||
|
static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode);
|
||||||
|
|
||||||
|
static bool afterGroupBy(ESqlClause clause) {
|
||||||
|
return clause > SQL_CLAUSE_GROUP_BY;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool beforeHaving(ESqlClause clause) {
|
||||||
|
return clause < SQL_CLAUSE_HAVING;
|
||||||
|
}
|
||||||
|
|
||||||
static EDealRes generateDealNodeErrMsg(STranslateContext* pCxt, int32_t errCode, ...) {
|
static EDealRes generateDealNodeErrMsg(STranslateContext* pCxt, int32_t errCode, ...) {
|
||||||
va_list vArgList;
|
va_list vArgList;
|
||||||
|
@ -254,8 +255,7 @@ static int32_t trimStringWithVarFormat(const char* src, int32_t len, bool format
|
||||||
|
|
||||||
static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) {
|
static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) {
|
||||||
if (pVal->isDuration) {
|
if (pVal->isDuration) {
|
||||||
char unit = 0;
|
if (parseAbsoluteDuration(pVal->literal, strlen(pVal->literal), &pVal->datum.i, &pVal->unit, pVal->node.resType.precision) != TSDB_CODE_SUCCESS) {
|
||||||
if (parseAbsoluteDuration(pVal->literal, strlen(pVal->literal), &pVal->datum.i, &unit, pVal->node.resType.precision) != TSDB_CODE_SUCCESS) {
|
|
||||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, pVal->literal);
|
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, pVal->literal);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -768,26 +768,26 @@ static void buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pStmt
|
||||||
SName name = {0};
|
SName name = {0};
|
||||||
tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName));
|
tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName));
|
||||||
tNameGetFullDbName(&name, pReq->db);
|
tNameGetFullDbName(&name, pReq->db);
|
||||||
pReq->numOfVgroups = pStmt->options.numOfVgroups;
|
pReq->numOfVgroups = pStmt->pOptions->numOfVgroups;
|
||||||
pReq->cacheBlockSize = pStmt->options.cacheBlockSize;
|
pReq->cacheBlockSize = pStmt->pOptions->cacheBlockSize;
|
||||||
pReq->totalBlocks = pStmt->options.numOfBlocks;
|
pReq->totalBlocks = pStmt->pOptions->numOfBlocks;
|
||||||
pReq->daysPerFile = pStmt->options.daysPerFile;
|
pReq->daysPerFile = pStmt->pOptions->daysPerFile;
|
||||||
pReq->daysToKeep0 = pStmt->options.keep;
|
pReq->daysToKeep0 = pStmt->pOptions->keep;
|
||||||
pReq->daysToKeep1 = -1;
|
pReq->daysToKeep1 = -1;
|
||||||
pReq->daysToKeep2 = -1;
|
pReq->daysToKeep2 = -1;
|
||||||
pReq->minRows = pStmt->options.minRowsPerBlock;
|
pReq->minRows = pStmt->pOptions->minRowsPerBlock;
|
||||||
pReq->maxRows = pStmt->options.maxRowsPerBlock;
|
pReq->maxRows = pStmt->pOptions->maxRowsPerBlock;
|
||||||
pReq->commitTime = -1;
|
pReq->commitTime = -1;
|
||||||
pReq->fsyncPeriod = pStmt->options.fsyncPeriod;
|
pReq->fsyncPeriod = pStmt->pOptions->fsyncPeriod;
|
||||||
pReq->walLevel = pStmt->options.walLevel;
|
pReq->walLevel = pStmt->pOptions->walLevel;
|
||||||
pReq->precision = pStmt->options.precision;
|
pReq->precision = pStmt->pOptions->precision;
|
||||||
pReq->compression = pStmt->options.compressionLevel;
|
pReq->compression = pStmt->pOptions->compressionLevel;
|
||||||
pReq->replications = pStmt->options.replica;
|
pReq->replications = pStmt->pOptions->replica;
|
||||||
pReq->quorum = pStmt->options.quorum;
|
pReq->quorum = pStmt->pOptions->quorum;
|
||||||
pReq->update = -1;
|
pReq->update = -1;
|
||||||
pReq->cacheLastRow = pStmt->options.cachelast;
|
pReq->cacheLastRow = pStmt->pOptions->cachelast;
|
||||||
pReq->ignoreExist = pStmt->ignoreExists;
|
pReq->ignoreExist = pStmt->ignoreExists;
|
||||||
pReq->streamMode = pStmt->options.streamMode;
|
pReq->streamMode = pStmt->pOptions->streamMode;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -796,14 +796,14 @@ static int32_t translateCreateDatabase(STranslateContext* pCxt, SCreateDatabaseS
|
||||||
buildCreateDbReq(pCxt, pStmt, &createReq);
|
buildCreateDbReq(pCxt, pStmt, &createReq);
|
||||||
|
|
||||||
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
||||||
if (NULL== pCxt->pCmdMsg) {
|
if (NULL == pCxt->pCmdMsg) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
||||||
pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_DB;
|
pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_DB;
|
||||||
pCxt->pCmdMsg->msgLen = tSerializeSCreateDbReq(NULL, 0, &createReq);
|
pCxt->pCmdMsg->msgLen = tSerializeSCreateDbReq(NULL, 0, &createReq);
|
||||||
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
||||||
if (NULL== pCxt->pCmdMsg->pMsg) {
|
if (NULL == pCxt->pCmdMsg->pMsg) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
tSerializeSCreateDbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq);
|
tSerializeSCreateDbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq);
|
||||||
|
@ -819,14 +819,14 @@ static int32_t translateDropDatabase(STranslateContext* pCxt, SDropDatabaseStmt*
|
||||||
dropReq.ignoreNotExists = pStmt->ignoreNotExists;
|
dropReq.ignoreNotExists = pStmt->ignoreNotExists;
|
||||||
|
|
||||||
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
||||||
if (NULL== pCxt->pCmdMsg) {
|
if (NULL == pCxt->pCmdMsg) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
||||||
pCxt->pCmdMsg->msgType = TDMT_MND_DROP_DB;
|
pCxt->pCmdMsg->msgType = TDMT_MND_DROP_DB;
|
||||||
pCxt->pCmdMsg->msgLen = tSerializeSDropDbReq(NULL, 0, &dropReq);
|
pCxt->pCmdMsg->msgLen = tSerializeSDropDbReq(NULL, 0, &dropReq);
|
||||||
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
||||||
if (NULL== pCxt->pCmdMsg->pMsg) {
|
if (NULL == pCxt->pCmdMsg->pMsg) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
tSerializeSDropDbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq);
|
tSerializeSDropDbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq);
|
||||||
|
@ -834,6 +834,41 @@ static int32_t translateDropDatabase(STranslateContext* pCxt, SDropDatabaseStmt*
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void buildAlterDbReq(STranslateContext* pCxt, SAlterDatabaseStmt* pStmt, SAlterDbReq* pReq) {
|
||||||
|
SName name = {0};
|
||||||
|
tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName));
|
||||||
|
tNameGetFullDbName(&name, pReq->db);
|
||||||
|
pReq->totalBlocks = pStmt->pOptions->numOfBlocks;
|
||||||
|
pReq->daysToKeep0 = pStmt->pOptions->keep;
|
||||||
|
pReq->daysToKeep1 = -1;
|
||||||
|
pReq->daysToKeep2 = -1;
|
||||||
|
pReq->fsyncPeriod = pStmt->pOptions->fsyncPeriod;
|
||||||
|
pReq->walLevel = pStmt->pOptions->walLevel;
|
||||||
|
pReq->quorum = pStmt->pOptions->quorum;
|
||||||
|
pReq->cacheLastRow = pStmt->pOptions->cachelast;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateAlterDatabase(STranslateContext* pCxt, SAlterDatabaseStmt* pStmt) {
|
||||||
|
SAlterDbReq alterReq = {0};
|
||||||
|
buildAlterDbReq(pCxt, pStmt, &alterReq);
|
||||||
|
|
||||||
|
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
||||||
|
if (NULL == pCxt->pCmdMsg) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
||||||
|
pCxt->pCmdMsg->msgType = TDMT_MND_ALTER_DB;
|
||||||
|
pCxt->pCmdMsg->msgLen = tSerializeSAlterDbReq(NULL, 0, &alterReq);
|
||||||
|
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
||||||
|
if (NULL == pCxt->pCmdMsg->pMsg) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
tSerializeSAlterDbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &alterReq);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t columnNodeToField(SNodeList* pList, SArray** pArray) {
|
static int32_t columnNodeToField(SNodeList* pList, SArray** pArray) {
|
||||||
*pArray = taosArrayInit(LIST_LENGTH(pList), sizeof(SField));
|
*pArray = taosArrayInit(LIST_LENGTH(pList), sizeof(SField));
|
||||||
SNode* pNode;
|
SNode* pNode;
|
||||||
|
@ -860,7 +895,7 @@ static int32_t translateCreateSuperTable(STranslateContext* pCxt, SCreateTableSt
|
||||||
tNameExtractFullName(&tableName, createReq.name);
|
tNameExtractFullName(&tableName, createReq.name);
|
||||||
|
|
||||||
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
||||||
if (NULL== pCxt->pCmdMsg) {
|
if (NULL == pCxt->pCmdMsg) {
|
||||||
tFreeSMCreateStbReq(&createReq);
|
tFreeSMCreateStbReq(&createReq);
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -868,7 +903,7 @@ static int32_t translateCreateSuperTable(STranslateContext* pCxt, SCreateTableSt
|
||||||
pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_STB;
|
pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_STB;
|
||||||
pCxt->pCmdMsg->msgLen = tSerializeSMCreateStbReq(NULL, 0, &createReq);
|
pCxt->pCmdMsg->msgLen = tSerializeSMCreateStbReq(NULL, 0, &createReq);
|
||||||
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
||||||
if (NULL== pCxt->pCmdMsg->pMsg) {
|
if (NULL == pCxt->pCmdMsg->pMsg) {
|
||||||
tFreeSMCreateStbReq(&createReq);
|
tFreeSMCreateStbReq(&createReq);
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -884,14 +919,14 @@ static int32_t doTranslateDropSuperTable(STranslateContext* pCxt, const SName* p
|
||||||
dropReq.igNotExists = ignoreNotExists;
|
dropReq.igNotExists = ignoreNotExists;
|
||||||
|
|
||||||
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
||||||
if (NULL== pCxt->pCmdMsg) {
|
if (NULL == pCxt->pCmdMsg) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
||||||
pCxt->pCmdMsg->msgType = TDMT_MND_DROP_STB;
|
pCxt->pCmdMsg->msgType = TDMT_MND_DROP_STB;
|
||||||
pCxt->pCmdMsg->msgLen = tSerializeSMDropStbReq(NULL, 0, &dropReq);
|
pCxt->pCmdMsg->msgLen = tSerializeSMDropStbReq(NULL, 0, &dropReq);
|
||||||
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
||||||
if (NULL== pCxt->pCmdMsg->pMsg) {
|
if (NULL == pCxt->pCmdMsg->pMsg) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
tSerializeSMDropStbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq);
|
tSerializeSMDropStbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq);
|
||||||
|
@ -937,14 +972,14 @@ static int32_t translateUseDatabase(STranslateContext* pCxt, SUseDatabaseStmt* p
|
||||||
catalogGetDBVgVersion(pCxt->pParseCxt->pCatalog, usedbReq.db, &usedbReq.vgVersion, &usedbReq.dbId, &usedbReq.numOfTable);
|
catalogGetDBVgVersion(pCxt->pParseCxt->pCatalog, usedbReq.db, &usedbReq.vgVersion, &usedbReq.dbId, &usedbReq.numOfTable);
|
||||||
|
|
||||||
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
||||||
if (NULL== pCxt->pCmdMsg) {
|
if (NULL == pCxt->pCmdMsg) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
||||||
pCxt->pCmdMsg->msgType = TDMT_MND_USE_DB;
|
pCxt->pCmdMsg->msgType = TDMT_MND_USE_DB;
|
||||||
pCxt->pCmdMsg->msgLen = tSerializeSUseDbReq(NULL, 0, &usedbReq);
|
pCxt->pCmdMsg->msgLen = tSerializeSUseDbReq(NULL, 0, &usedbReq);
|
||||||
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
||||||
if (NULL== pCxt->pCmdMsg->pMsg) {
|
if (NULL == pCxt->pCmdMsg->pMsg) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
tSerializeSUseDbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &usedbReq);
|
tSerializeSUseDbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &usedbReq);
|
||||||
|
@ -960,14 +995,14 @@ static int32_t translateCreateUser(STranslateContext* pCxt, SCreateUserStmt* pSt
|
||||||
strcpy(createReq.pass, pStmt->password);
|
strcpy(createReq.pass, pStmt->password);
|
||||||
|
|
||||||
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
||||||
if (NULL== pCxt->pCmdMsg) {
|
if (NULL == pCxt->pCmdMsg) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
||||||
pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_USER;
|
pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_USER;
|
||||||
pCxt->pCmdMsg->msgLen = tSerializeSCreateUserReq(NULL, 0, &createReq);
|
pCxt->pCmdMsg->msgLen = tSerializeSCreateUserReq(NULL, 0, &createReq);
|
||||||
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
||||||
if (NULL== pCxt->pCmdMsg->pMsg) {
|
if (NULL == pCxt->pCmdMsg->pMsg) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
tSerializeSCreateUserReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq);
|
tSerializeSCreateUserReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq);
|
||||||
|
@ -986,14 +1021,14 @@ static int32_t translateAlterUser(STranslateContext* pCxt, SAlterUserStmt* pStmt
|
||||||
}
|
}
|
||||||
|
|
||||||
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
||||||
if (NULL== pCxt->pCmdMsg) {
|
if (NULL == pCxt->pCmdMsg) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
||||||
pCxt->pCmdMsg->msgType = TDMT_MND_ALTER_USER;
|
pCxt->pCmdMsg->msgType = TDMT_MND_ALTER_USER;
|
||||||
pCxt->pCmdMsg->msgLen = tSerializeSAlterUserReq(NULL, 0, &alterReq);
|
pCxt->pCmdMsg->msgLen = tSerializeSAlterUserReq(NULL, 0, &alterReq);
|
||||||
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
||||||
if (NULL== pCxt->pCmdMsg->pMsg) {
|
if (NULL == pCxt->pCmdMsg->pMsg) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
tSerializeSAlterUserReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &alterReq);
|
tSerializeSAlterUserReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &alterReq);
|
||||||
|
@ -1006,14 +1041,14 @@ static int32_t translateDropUser(STranslateContext* pCxt, SDropUserStmt* pStmt)
|
||||||
strcpy(dropReq.user, pStmt->useName);
|
strcpy(dropReq.user, pStmt->useName);
|
||||||
|
|
||||||
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
||||||
if (NULL== pCxt->pCmdMsg) {
|
if (NULL == pCxt->pCmdMsg) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
||||||
pCxt->pCmdMsg->msgType = TDMT_MND_DROP_USER;
|
pCxt->pCmdMsg->msgType = TDMT_MND_DROP_USER;
|
||||||
pCxt->pCmdMsg->msgLen = tSerializeSDropUserReq(NULL, 0, &dropReq);
|
pCxt->pCmdMsg->msgLen = tSerializeSDropUserReq(NULL, 0, &dropReq);
|
||||||
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
||||||
if (NULL== pCxt->pCmdMsg->pMsg) {
|
if (NULL == pCxt->pCmdMsg->pMsg) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
tSerializeSDropUserReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq);
|
tSerializeSDropUserReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq);
|
||||||
|
@ -1027,14 +1062,14 @@ static int32_t translateCreateDnode(STranslateContext* pCxt, SCreateDnodeStmt* p
|
||||||
createReq.port = pStmt->port;
|
createReq.port = pStmt->port;
|
||||||
|
|
||||||
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
||||||
if (NULL== pCxt->pCmdMsg) {
|
if (NULL == pCxt->pCmdMsg) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
||||||
pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_DNODE;
|
pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_DNODE;
|
||||||
pCxt->pCmdMsg->msgLen = tSerializeSCreateDnodeReq(NULL, 0, &createReq);
|
pCxt->pCmdMsg->msgLen = tSerializeSCreateDnodeReq(NULL, 0, &createReq);
|
||||||
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
||||||
if (NULL== pCxt->pCmdMsg->pMsg) {
|
if (NULL == pCxt->pCmdMsg->pMsg) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
tSerializeSCreateDnodeReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq);
|
tSerializeSCreateDnodeReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq);
|
||||||
|
@ -1049,14 +1084,14 @@ static int32_t translateDropDnode(STranslateContext* pCxt, SDropDnodeStmt* pStmt
|
||||||
dropReq.port = pStmt->port;
|
dropReq.port = pStmt->port;
|
||||||
|
|
||||||
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
||||||
if (NULL== pCxt->pCmdMsg) {
|
if (NULL == pCxt->pCmdMsg) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
||||||
pCxt->pCmdMsg->msgType = TDMT_MND_DROP_DNODE;
|
pCxt->pCmdMsg->msgType = TDMT_MND_DROP_DNODE;
|
||||||
pCxt->pCmdMsg->msgLen = tSerializeSDropDnodeReq(NULL, 0, &dropReq);
|
pCxt->pCmdMsg->msgLen = tSerializeSDropDnodeReq(NULL, 0, &dropReq);
|
||||||
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
||||||
if (NULL== pCxt->pCmdMsg->pMsg) {
|
if (NULL == pCxt->pCmdMsg->pMsg) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
tSerializeSDropDnodeReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq);
|
tSerializeSDropDnodeReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq);
|
||||||
|
@ -1078,6 +1113,8 @@ static int32_t nodeTypeToShowType(ENodeType nt) {
|
||||||
return TSDB_MGMT_TABLE_VGROUP;
|
return TSDB_MGMT_TABLE_VGROUP;
|
||||||
case QUERY_NODE_SHOW_MNODES_STMT:
|
case QUERY_NODE_SHOW_MNODES_STMT:
|
||||||
return TSDB_MGMT_TABLE_MNODE;
|
return TSDB_MGMT_TABLE_MNODE;
|
||||||
|
case QUERY_NODE_SHOW_QNODES_STMT:
|
||||||
|
return TSDB_MGMT_TABLE_QNODE;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1094,14 +1131,14 @@ static int32_t translateShow(STranslateContext* pCxt, SShowStmt* pStmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
||||||
if (NULL== pCxt->pCmdMsg) {
|
if (NULL == pCxt->pCmdMsg) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
||||||
pCxt->pCmdMsg->msgType = TDMT_MND_SHOW;
|
pCxt->pCmdMsg->msgType = TDMT_MND_SHOW;
|
||||||
pCxt->pCmdMsg->msgLen = tSerializeSShowReq(NULL, 0, &showReq);
|
pCxt->pCmdMsg->msgLen = tSerializeSShowReq(NULL, 0, &showReq);
|
||||||
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
||||||
if (NULL== pCxt->pCmdMsg->pMsg) {
|
if (NULL == pCxt->pCmdMsg->pMsg) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
tSerializeSShowReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &showReq);
|
tSerializeSShowReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &showReq);
|
||||||
|
@ -1129,7 +1166,7 @@ static int32_t translateShowTables(STranslateContext* pCxt) {
|
||||||
pShowReq->head.vgId = htonl(info->vgId);
|
pShowReq->head.vgId = htonl(info->vgId);
|
||||||
|
|
||||||
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
||||||
if (NULL== pCxt->pCmdMsg) {
|
if (NULL == pCxt->pCmdMsg) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
pCxt->pCmdMsg->epSet = info->epSet;
|
pCxt->pCmdMsg->epSet = info->epSet;
|
||||||
|
@ -1141,6 +1178,192 @@ static int32_t translateShowTables(STranslateContext* pCxt) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t translateCreateSmaIndex(STranslateContext* pCxt, SCreateIndexStmt* pStmt) {
|
||||||
|
SVCreateTSmaReq createSmaReq = {0};
|
||||||
|
|
||||||
|
if (DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStmt->pOptions->pInterval) ||
|
||||||
|
(NULL != pStmt->pOptions->pOffset && DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStmt->pOptions->pOffset)) ||
|
||||||
|
(NULL != pStmt->pOptions->pSliding && DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStmt->pOptions->pSliding))) {
|
||||||
|
return pCxt->errCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
createSmaReq.tSma.intervalUnit = ((SValueNode*)pStmt->pOptions->pInterval)->unit;
|
||||||
|
createSmaReq.tSma.slidingUnit = (NULL != pStmt->pOptions->pSliding ? ((SValueNode*)pStmt->pOptions->pSliding)->unit : 0);
|
||||||
|
strcpy(createSmaReq.tSma.indexName, pStmt->indexName);
|
||||||
|
|
||||||
|
SName name;
|
||||||
|
name.type = TSDB_TABLE_NAME_T;
|
||||||
|
name.acctId = pCxt->pParseCxt->acctId;
|
||||||
|
strcpy(name.dbname, pCxt->pParseCxt->db);
|
||||||
|
strcpy(name.tname, pStmt->tableName);
|
||||||
|
STableMeta* pMeta = NULL;
|
||||||
|
int32_t code = catalogGetTableMeta(pCxt->pParseCxt->pCatalog, pCxt->pParseCxt->pTransporter, &pCxt->pParseCxt->mgmtEpSet, &name, &pMeta);
|
||||||
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
createSmaReq.tSma.tableUid = pMeta->uid;
|
||||||
|
createSmaReq.tSma.interval = ((SValueNode*)pStmt->pOptions->pInterval)->datum.i;
|
||||||
|
createSmaReq.tSma.sliding = (NULL != pStmt->pOptions->pSliding ? ((SValueNode*)pStmt->pOptions->pSliding)->datum.i : 0);
|
||||||
|
code = nodesListToString(pStmt->pOptions->pFuncs, false, &createSmaReq.tSma.expr, &createSmaReq.tSma.exprLen);
|
||||||
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
||||||
|
if (NULL == pCxt->pCmdMsg) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
||||||
|
pCxt->pCmdMsg->msgType = TDMT_VND_CREATE_SMA;
|
||||||
|
pCxt->pCmdMsg->msgLen = tSerializeSVCreateTSmaReq(NULL, &createSmaReq);
|
||||||
|
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
||||||
|
if (NULL == pCxt->pCmdMsg->pMsg) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
void* pBuf = pCxt->pCmdMsg->pMsg;
|
||||||
|
tSerializeSVCreateTSmaReq(&pBuf, &createSmaReq);
|
||||||
|
tdDestroyTSma(&createSmaReq.tSma);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateCreateIndex(STranslateContext* pCxt, SCreateIndexStmt* pStmt) {
|
||||||
|
if (INDEX_TYPE_SMA == pStmt->indexType) {
|
||||||
|
return translateCreateSmaIndex(pCxt, pStmt);
|
||||||
|
} else {
|
||||||
|
// todo fulltext index
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateDropIndex(STranslateContext* pCxt, SDropIndexStmt* pStmt) {
|
||||||
|
SVDropTSmaReq dropSmaReq = {0};
|
||||||
|
strcpy(dropSmaReq.indexName, pStmt->indexName);
|
||||||
|
|
||||||
|
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
||||||
|
if (NULL == pCxt->pCmdMsg) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
||||||
|
pCxt->pCmdMsg->msgType = TDMT_VND_DROP_SMA;
|
||||||
|
pCxt->pCmdMsg->msgLen = tSerializeSVDropTSmaReq(NULL, &dropSmaReq);
|
||||||
|
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
||||||
|
if (NULL == pCxt->pCmdMsg->pMsg) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
void* pBuf = pCxt->pCmdMsg->pMsg;
|
||||||
|
tSerializeSVDropTSmaReq(&pBuf, &dropSmaReq);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateCreateQnode(STranslateContext* pCxt, SCreateQnodeStmt* pStmt) {
|
||||||
|
SMCreateQnodeReq createReq = { .dnodeId = pStmt->dnodeId };
|
||||||
|
|
||||||
|
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
||||||
|
if (NULL == pCxt->pCmdMsg) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
||||||
|
pCxt->pCmdMsg->msgType = TDMT_DND_CREATE_QNODE;
|
||||||
|
pCxt->pCmdMsg->msgLen = tSerializeSMCreateDropQSBNodeReq(NULL, 0, &createReq);
|
||||||
|
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
||||||
|
if (NULL == pCxt->pCmdMsg->pMsg) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
tSerializeSMCreateDropQSBNodeReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateDropQnode(STranslateContext* pCxt, SDropQnodeStmt* pStmt) {
|
||||||
|
SDDropQnodeReq dropReq = { .dnodeId = pStmt->dnodeId };
|
||||||
|
|
||||||
|
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
||||||
|
if (NULL == pCxt->pCmdMsg) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
||||||
|
pCxt->pCmdMsg->msgType = TDMT_DND_DROP_QNODE;
|
||||||
|
pCxt->pCmdMsg->msgLen = tSerializeSMCreateDropQSBNodeReq(NULL, 0, &dropReq);
|
||||||
|
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
||||||
|
if (NULL == pCxt->pCmdMsg->pMsg) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
tSerializeSMCreateDropQSBNodeReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateCreateTopic(STranslateContext* pCxt, SCreateTopicStmt* pStmt) {
|
||||||
|
SCMCreateTopicReq createReq = {0};
|
||||||
|
|
||||||
|
if (NULL != pStmt->pQuery) {
|
||||||
|
int32_t code = translateQuery(pCxt, pStmt->pQuery);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = nodesNodeToString(pStmt->pQuery, false, &createReq.ast, NULL);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS != code ) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
strcpy(createReq.subscribeDbName, pStmt->subscribeDbName);
|
||||||
|
}
|
||||||
|
|
||||||
|
createReq.sql = strdup(pCxt->pParseCxt->pSql);
|
||||||
|
if (NULL == createReq.sql) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
SName name = { .type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId };
|
||||||
|
strcpy(name.dbname, pCxt->pParseCxt->db);
|
||||||
|
strcpy(name.tname, pStmt->topicName);
|
||||||
|
tNameExtractFullName(&name, createReq.name);
|
||||||
|
createReq.igExists = pStmt->ignoreExists;
|
||||||
|
|
||||||
|
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
||||||
|
if (NULL == pCxt->pCmdMsg) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
||||||
|
pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_TOPIC;
|
||||||
|
pCxt->pCmdMsg->msgLen = tSerializeSCMCreateTopicReq(NULL, 0, &createReq);
|
||||||
|
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
||||||
|
if (NULL == pCxt->pCmdMsg->pMsg) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
tSerializeSCMCreateTopicReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq);
|
||||||
|
tFreeSCMCreateTopicReq(&createReq);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateDropTopic(STranslateContext* pCxt, SDropTopicStmt* pStmt) {
|
||||||
|
SMDropTopicReq dropReq = {0};
|
||||||
|
|
||||||
|
SName name = { .type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId };
|
||||||
|
strcpy(name.dbname, pCxt->pParseCxt->db);
|
||||||
|
strcpy(name.tname, pStmt->topicName);
|
||||||
|
tNameExtractFullName(&name, dropReq.name);
|
||||||
|
dropReq.igNotExists = pStmt->ignoreNotExists;
|
||||||
|
|
||||||
|
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
||||||
|
if (NULL == pCxt->pCmdMsg) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
||||||
|
pCxt->pCmdMsg->msgType = TDMT_MND_DROP_TOPIC;
|
||||||
|
pCxt->pCmdMsg->msgLen = tSerializeSMDropTopicReq(NULL, 0, &dropReq);
|
||||||
|
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
||||||
|
if (NULL == pCxt->pCmdMsg->pMsg) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
tSerializeSMDropTopicReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
switch (nodeType(pNode)) {
|
switch (nodeType(pNode)) {
|
||||||
|
@ -1153,6 +1376,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
||||||
case QUERY_NODE_DROP_DATABASE_STMT:
|
case QUERY_NODE_DROP_DATABASE_STMT:
|
||||||
code = translateDropDatabase(pCxt, (SDropDatabaseStmt*)pNode);
|
code = translateDropDatabase(pCxt, (SDropDatabaseStmt*)pNode);
|
||||||
break;
|
break;
|
||||||
|
case QUERY_NODE_ALTER_DATABASE_STMT:
|
||||||
|
code = translateAlterDatabase(pCxt, (SAlterDatabaseStmt*)pNode);
|
||||||
|
break;
|
||||||
case QUERY_NODE_CREATE_TABLE_STMT:
|
case QUERY_NODE_CREATE_TABLE_STMT:
|
||||||
code = translateCreateSuperTable(pCxt, (SCreateTableStmt*)pNode);
|
code = translateCreateSuperTable(pCxt, (SCreateTableStmt*)pNode);
|
||||||
break;
|
break;
|
||||||
|
@ -1186,11 +1412,30 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
||||||
case QUERY_NODE_SHOW_DNODES_STMT:
|
case QUERY_NODE_SHOW_DNODES_STMT:
|
||||||
case QUERY_NODE_SHOW_VGROUPS_STMT:
|
case QUERY_NODE_SHOW_VGROUPS_STMT:
|
||||||
case QUERY_NODE_SHOW_MNODES_STMT:
|
case QUERY_NODE_SHOW_MNODES_STMT:
|
||||||
|
case QUERY_NODE_SHOW_QNODES_STMT:
|
||||||
code = translateShow(pCxt, (SShowStmt*)pNode);
|
code = translateShow(pCxt, (SShowStmt*)pNode);
|
||||||
break;
|
break;
|
||||||
case QUERY_NODE_SHOW_TABLES_STMT:
|
case QUERY_NODE_SHOW_TABLES_STMT:
|
||||||
code = translateShowTables(pCxt);
|
code = translateShowTables(pCxt);
|
||||||
break;
|
break;
|
||||||
|
case QUERY_NODE_CREATE_INDEX_STMT:
|
||||||
|
code = translateCreateIndex(pCxt, (SCreateIndexStmt*)pNode);
|
||||||
|
break;
|
||||||
|
case QUERY_NODE_DROP_INDEX_STMT:
|
||||||
|
code = translateDropIndex(pCxt, (SDropIndexStmt*)pNode);
|
||||||
|
break;
|
||||||
|
case QUERY_NODE_CREATE_QNODE_STMT:
|
||||||
|
code = translateCreateQnode(pCxt, (SCreateQnodeStmt*)pNode);
|
||||||
|
break;
|
||||||
|
case QUERY_NODE_DROP_QNODE_STMT:
|
||||||
|
code = translateDropQnode(pCxt, (SDropQnodeStmt*)pNode);
|
||||||
|
break;
|
||||||
|
case QUERY_NODE_CREATE_TOPIC_STMT:
|
||||||
|
code = translateCreateTopic(pCxt, (SCreateTopicStmt*)pNode);
|
||||||
|
break;
|
||||||
|
case QUERY_NODE_DROP_TOPIC_STMT:
|
||||||
|
code = translateDropTopic(pCxt, (SDropTopicStmt*)pNode);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -340,6 +340,23 @@ TEST_F(ParserTest, createDatabase) {
|
||||||
ASSERT_TRUE(run());
|
ASSERT_TRUE(run());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ParserTest, alterDatabase) {
|
||||||
|
setDatabase("root", "test");
|
||||||
|
|
||||||
|
bind("alter database wxy_db BLOCKS 200");
|
||||||
|
ASSERT_TRUE(run());
|
||||||
|
|
||||||
|
bind("alter database wxy_db "
|
||||||
|
"BLOCKS 200 "
|
||||||
|
"CACHELAST 1 "
|
||||||
|
"FSYNC 200 "
|
||||||
|
"KEEP 200 "
|
||||||
|
"QUORUM 2 "
|
||||||
|
"WAL 1 "
|
||||||
|
);
|
||||||
|
ASSERT_TRUE(run());
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(ParserTest, showDatabase) {
|
TEST_F(ParserTest, showDatabase) {
|
||||||
setDatabase("root", "test");
|
setDatabase("root", "test");
|
||||||
|
|
||||||
|
@ -398,3 +415,57 @@ TEST_F(ParserTest, createTable) {
|
||||||
);
|
);
|
||||||
ASSERT_TRUE(run());
|
ASSERT_TRUE(run());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ParserTest, createSmaIndex) {
|
||||||
|
setDatabase("root", "test");
|
||||||
|
|
||||||
|
bind("create sma index index1 on t1 function(max(c1), min(c3 + 10), sum(c4)) INTERVAL(10s)");
|
||||||
|
ASSERT_TRUE(run());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ParserTest, dropIndex) {
|
||||||
|
setDatabase("root", "test");
|
||||||
|
|
||||||
|
bind("drop index index1 on t1");
|
||||||
|
ASSERT_TRUE(run());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ParserTest, createQnode) {
|
||||||
|
setDatabase("root", "test");
|
||||||
|
|
||||||
|
bind("create qnode on dnode 1");
|
||||||
|
ASSERT_TRUE(run());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ParserTest, dropQnode) {
|
||||||
|
setDatabase("root", "test");
|
||||||
|
|
||||||
|
bind("drop qnode on dnode 1");
|
||||||
|
ASSERT_TRUE(run());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ParserTest, createTopic) {
|
||||||
|
setDatabase("root", "test");
|
||||||
|
|
||||||
|
bind("create topic tp1 as select * from t1");
|
||||||
|
ASSERT_TRUE(run());
|
||||||
|
|
||||||
|
bind("create topic if not exists tp1 as select * from t1");
|
||||||
|
ASSERT_TRUE(run());
|
||||||
|
|
||||||
|
bind("create topic tp1 as test");
|
||||||
|
ASSERT_TRUE(run());
|
||||||
|
|
||||||
|
bind("create topic if not exists tp1 as test");
|
||||||
|
ASSERT_TRUE(run());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ParserTest, dropTopic) {
|
||||||
|
setDatabase("root", "test");
|
||||||
|
|
||||||
|
bind("drop topic tp1");
|
||||||
|
ASSERT_TRUE(run());
|
||||||
|
|
||||||
|
bind("drop topic if exists tp1");
|
||||||
|
ASSERT_TRUE(run());
|
||||||
|
}
|
||||||
|
|
|
@ -425,6 +425,7 @@ static SLogicNode* createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt) {
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
return NULL; // to avoid compiler error
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t createLogicPlan(SPlanContext* pCxt, SLogicNode** pLogicNode) {
|
int32_t createLogicPlan(SPlanContext* pCxt, SLogicNode** pLogicNode) {
|
||||||
|
|
|
@ -792,7 +792,7 @@ int32_t filterDetachCnfGroups(SArray* group, SArray* left, SArray* right) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SFilterGroup *gp = NULL;
|
SFilterGroup *gp = NULL;
|
||||||
while (gp = (SFilterGroup *)taosArrayPop(right)) {
|
while ((gp = (SFilterGroup *)taosArrayPop(right)) != NULL) {
|
||||||
taosArrayPush(group, gp);
|
taosArrayPush(group, gp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -801,7 +801,7 @@ int32_t filterDetachCnfGroups(SArray* group, SArray* left, SArray* right) {
|
||||||
|
|
||||||
if (taosArrayGetSize(right) <= 0) {
|
if (taosArrayGetSize(right) <= 0) {
|
||||||
SFilterGroup *gp = NULL;
|
SFilterGroup *gp = NULL;
|
||||||
while (gp = (SFilterGroup *)taosArrayPop(left)) {
|
while ((gp = (SFilterGroup *)taosArrayPop(left)) != NULL) {
|
||||||
taosArrayPush(group, gp);
|
taosArrayPush(group, gp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -239,6 +239,9 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param->num > *rowNum) {
|
if (param->num > *rowNum) {
|
||||||
|
|
|
@ -282,8 +282,10 @@ int32_t schLaunchTasksInFlowCtrlList(SSchJob *pJob, SSchTask *pTask) {
|
||||||
SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR);
|
SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
SCH_ERR_RET(schLaunchTasksInFlowCtrlListImpl(pJob, ctrl));
|
int32_t code = schLaunchTasksInFlowCtrlListImpl(pJob, ctrl);;
|
||||||
|
SCH_ERR_RET(code);
|
||||||
|
|
||||||
|
return code; // to avoid compiler error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,10 +31,10 @@ extern "C" {
|
||||||
#define TIMER_MAX_MS 0x7FFFFFFF
|
#define TIMER_MAX_MS 0x7FFFFFFF
|
||||||
#define ENV_TICK_TIMER_MS 1000
|
#define ENV_TICK_TIMER_MS 1000
|
||||||
#define PING_TIMER_MS 1000
|
#define PING_TIMER_MS 1000
|
||||||
#define ELECT_TIMER_MS_MIN 150
|
#define ELECT_TIMER_MS_MIN 1500
|
||||||
#define ELECT_TIMER_MS_MAX 300
|
#define ELECT_TIMER_MS_MAX 3000
|
||||||
#define ELECT_TIMER_MS_RANGE (ELECT_TIMER_MS_MAX - ELECT_TIMER_MS_MIN)
|
#define ELECT_TIMER_MS_RANGE (ELECT_TIMER_MS_MAX - ELECT_TIMER_MS_MIN)
|
||||||
#define HEARTBEAT_TIMER_MS 30
|
#define HEARTBEAT_TIMER_MS 300
|
||||||
|
|
||||||
#define EMPTY_RAFT_ID ((SRaftId){.addr = 0, .vgId = 0})
|
#define EMPTY_RAFT_ID ((SRaftId){.addr = 0, .vgId = 0})
|
||||||
|
|
||||||
|
|
|
@ -34,11 +34,11 @@ extern "C" {
|
||||||
|
|
||||||
typedef struct SSyncIO {
|
typedef struct SSyncIO {
|
||||||
STaosQueue *pMsgQ;
|
STaosQueue *pMsgQ;
|
||||||
STaosQset *pQset;
|
STaosQset * pQset;
|
||||||
pthread_t consumerTid;
|
pthread_t consumerTid;
|
||||||
|
|
||||||
void *serverRpc;
|
void * serverRpc;
|
||||||
void *clientRpc;
|
void * clientRpc;
|
||||||
SEpSet myAddr;
|
SEpSet myAddr;
|
||||||
|
|
||||||
tmr_h qTimer;
|
tmr_h qTimer;
|
||||||
|
|
|
@ -43,11 +43,14 @@ int32_t raftStorePersist(SRaftStore *pRaftStore);
|
||||||
int32_t raftStoreSerialize(SRaftStore *pRaftStore, char *buf, size_t len);
|
int32_t raftStoreSerialize(SRaftStore *pRaftStore, char *buf, size_t len);
|
||||||
int32_t raftStoreDeserialize(SRaftStore *pRaftStore, char *buf, size_t len);
|
int32_t raftStoreDeserialize(SRaftStore *pRaftStore, char *buf, size_t len);
|
||||||
|
|
||||||
bool raftStoreHasVoted(SRaftStore *pRaftStore);
|
bool raftStoreHasVoted(SRaftStore *pRaftStore);
|
||||||
void raftStoreVote(SRaftStore *pRaftStore, SRaftId *pRaftId);
|
void raftStoreVote(SRaftStore *pRaftStore, SRaftId *pRaftId);
|
||||||
void raftStoreClearVote(SRaftStore *pRaftStore);
|
void raftStoreClearVote(SRaftStore *pRaftStore);
|
||||||
void raftStoreNextTerm(SRaftStore *pRaftStore);
|
void raftStoreNextTerm(SRaftStore *pRaftStore);
|
||||||
void raftStoreSetTerm(SRaftStore *pRaftStore, SyncTerm term);
|
void raftStoreSetTerm(SRaftStore *pRaftStore, SyncTerm term);
|
||||||
|
int32_t raftStoreFromJson(SRaftStore *pRaftStore, cJSON *pJson);
|
||||||
|
cJSON * raftStore2Json(SRaftStore *pRaftStore);
|
||||||
|
char * raftStore2Str(SRaftStore *pRaftStore);
|
||||||
|
|
||||||
// for debug -------------------
|
// for debug -------------------
|
||||||
void raftStorePrint(SRaftStore *pObj);
|
void raftStorePrint(SRaftStore *pObj);
|
||||||
|
|
|
@ -102,7 +102,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
||||||
|
|
||||||
SyncTerm localPreLogTerm = 0;
|
SyncTerm localPreLogTerm = 0;
|
||||||
if (pMsg->prevLogTerm >= SYNC_INDEX_BEGIN && pMsg->prevLogTerm <= ths->pLogStore->getLastIndex(ths->pLogStore)) {
|
if (pMsg->prevLogTerm >= SYNC_INDEX_BEGIN && pMsg->prevLogTerm <= ths->pLogStore->getLastIndex(ths->pLogStore)) {
|
||||||
SSyncRaftEntry* pEntry = logStoreGetEntry(ths->pLogStore, pMsg->prevLogTerm);
|
SSyncRaftEntry* pEntry = logStoreGetEntry(ths->pLogStore, pMsg->prevLogIndex);
|
||||||
assert(pEntry != NULL);
|
assert(pEntry != NULL);
|
||||||
localPreLogTerm = pEntry->term;
|
localPreLogTerm = pEntry->term;
|
||||||
syncEntryDestory(pEntry);
|
syncEntryDestory(pEntry);
|
||||||
|
@ -111,9 +111,9 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
||||||
bool logOK =
|
bool logOK =
|
||||||
(pMsg->prevLogIndex == SYNC_INDEX_INVALID) ||
|
(pMsg->prevLogIndex == SYNC_INDEX_INVALID) ||
|
||||||
((pMsg->prevLogIndex >= SYNC_INDEX_BEGIN) &&
|
((pMsg->prevLogIndex >= SYNC_INDEX_BEGIN) &&
|
||||||
(pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)) && (pMsg->prevLogIndex == localPreLogTerm));
|
(pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)) && (pMsg->prevLogTerm == localPreLogTerm));
|
||||||
|
|
||||||
// reject
|
// reject request
|
||||||
if ((pMsg->term < ths->pRaftStore->currentTerm) ||
|
if ((pMsg->term < ths->pRaftStore->currentTerm) ||
|
||||||
((pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && !logOK)) {
|
((pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && !logOK)) {
|
||||||
SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild();
|
SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild();
|
||||||
|
@ -134,6 +134,9 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
||||||
// return to follower state
|
// return to follower state
|
||||||
if (pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_CANDIDATE) {
|
if (pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_CANDIDATE) {
|
||||||
syncNodeBecomeFollower(ths);
|
syncNodeBecomeFollower(ths);
|
||||||
|
|
||||||
|
// need ret?
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// accept request
|
// accept request
|
||||||
|
@ -144,17 +147,17 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
||||||
matchSuccess = true;
|
matchSuccess = true;
|
||||||
}
|
}
|
||||||
if (pMsg->prevLogIndex >= SYNC_INDEX_BEGIN && pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)) {
|
if (pMsg->prevLogIndex >= SYNC_INDEX_BEGIN && pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)) {
|
||||||
SSyncRaftEntry* pEntry = logStoreGetEntry(ths->pLogStore, pMsg->prevLogTerm);
|
SSyncRaftEntry* pPreEntry = logStoreGetEntry(ths->pLogStore, pMsg->prevLogIndex);
|
||||||
assert(pEntry != NULL);
|
assert(pPreEntry != NULL);
|
||||||
if (pMsg->prevLogTerm == pEntry->term) {
|
if (pMsg->prevLogTerm == pPreEntry->term) {
|
||||||
matchSuccess = true;
|
matchSuccess = true;
|
||||||
}
|
}
|
||||||
syncEntryDestory(pEntry);
|
syncEntryDestory(pPreEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matchSuccess) {
|
if (matchSuccess) {
|
||||||
// delete conflict entries
|
// delete conflict entries
|
||||||
if (ths->pLogStore->getLastIndex(ths->pLogStore) > pMsg->prevLogIndex) {
|
if (pMsg->prevLogIndex < ths->pLogStore->getLastIndex(ths->pLogStore)) {
|
||||||
SyncIndex fromIndex = pMsg->prevLogIndex + 1;
|
SyncIndex fromIndex = pMsg->prevLogIndex + 1;
|
||||||
ths->pLogStore->truncate(ths->pLogStore, fromIndex);
|
ths->pLogStore->truncate(ths->pLogStore, fromIndex);
|
||||||
}
|
}
|
||||||
|
@ -178,6 +181,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
||||||
syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg);
|
syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg);
|
||||||
|
|
||||||
syncAppendEntriesReplyDestroy(pReply);
|
syncAppendEntriesReplyDestroy(pReply);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild();
|
SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild();
|
||||||
pReply->srcId = ths->myRaftId;
|
pReply->srcId = ths->myRaftId;
|
||||||
|
|
|
@ -39,7 +39,7 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p
|
||||||
syncAppendEntriesReplyLog2("==syncNodeOnAppendEntriesReplyCb==", pMsg);
|
syncAppendEntriesReplyLog2("==syncNodeOnAppendEntriesReplyCb==", pMsg);
|
||||||
|
|
||||||
if (pMsg->term < ths->pRaftStore->currentTerm) {
|
if (pMsg->term < ths->pRaftStore->currentTerm) {
|
||||||
sTrace("DropStaleResponse, receive term:%lu, current term:%lu", pMsg->term, ths->pRaftStore->currentTerm);
|
sTrace("DropStaleResponse, receive term:%" PRIu64 ", current term:%" PRIu64 "", pMsg->term, ths->pRaftStore->currentTerm);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,10 +51,10 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p
|
||||||
assert(pMsg->term == ths->pRaftStore->currentTerm);
|
assert(pMsg->term == ths->pRaftStore->currentTerm);
|
||||||
|
|
||||||
if (pMsg->success) {
|
if (pMsg->success) {
|
||||||
// nextIndex = reply.matchIndex + 1
|
// nextIndex' = [nextIndex EXCEPT ![i][j] = m.mmatchIndex + 1]
|
||||||
syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), pMsg->matchIndex + 1);
|
syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), pMsg->matchIndex + 1);
|
||||||
|
|
||||||
// matchIndex = reply.matchIndex
|
// matchIndex' = [matchIndex EXCEPT ![i][j] = m.mmatchIndex]
|
||||||
syncIndexMgrSetIndex(ths->pMatchIndex, &(pMsg->srcId), pMsg->matchIndex);
|
syncIndexMgrSetIndex(ths->pMatchIndex, &(pMsg->srcId), pMsg->matchIndex);
|
||||||
|
|
||||||
// maybe commit
|
// maybe commit
|
||||||
|
@ -62,6 +62,8 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
SyncIndex nextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId));
|
SyncIndex nextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId));
|
||||||
|
|
||||||
|
// notice! int64, uint64
|
||||||
if (nextIndex > SYNC_INDEX_BEGIN) {
|
if (nextIndex > SYNC_INDEX_BEGIN) {
|
||||||
--nextIndex;
|
--nextIndex;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "syncIndexMgr.h"
|
||||||
|
#include "syncInt.h"
|
||||||
|
|
||||||
|
// \* Leader i advances its commitIndex.
|
||||||
|
// \* This is done as a separate step from handling AppendEntries responses,
|
||||||
|
// \* in part to minimize atomic regions, and in part so that leaders of
|
||||||
|
// \* single-server clusters are able to mark entries committed.
|
||||||
|
// AdvanceCommitIndex(i) ==
|
||||||
|
// /\ state[i] = Leader
|
||||||
|
// /\ LET \* The set of servers that agree up through index.
|
||||||
|
// Agree(index) == {i} \cup {k \in Server :
|
||||||
|
// matchIndex[i][k] >= index}
|
||||||
|
// \* The maximum indexes for which a quorum agrees
|
||||||
|
// agreeIndexes == {index \in 1..Len(log[i]) :
|
||||||
|
// Agree(index) \in Quorum}
|
||||||
|
// \* New value for commitIndex'[i]
|
||||||
|
// newCommitIndex ==
|
||||||
|
// IF /\ agreeIndexes /= {}
|
||||||
|
// /\ log[i][Max(agreeIndexes)].term = currentTerm[i]
|
||||||
|
// THEN
|
||||||
|
// Max(agreeIndexes)
|
||||||
|
// ELSE
|
||||||
|
// commitIndex[i]
|
||||||
|
// IN commitIndex' = [commitIndex EXCEPT ![i] = newCommitIndex]
|
||||||
|
// /\ UNCHANGED <<messages, serverVars, candidateVars, leaderVars, log>>
|
||||||
|
//
|
||||||
|
void syncNodeMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
|
||||||
|
syncIndexMgrLog2("==syncNodeMaybeAdvanceCommitIndex== pNextIndex", pSyncNode->pNextIndex);
|
||||||
|
syncIndexMgrLog2("==syncNodeMaybeAdvanceCommitIndex== pMatchIndex", pSyncNode->pMatchIndex);
|
||||||
|
}
|
|
@ -50,6 +50,7 @@ int32_t syncNodeRequestVotePeers(SSyncNode* pSyncNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodeElect(SSyncNode* pSyncNode) {
|
int32_t syncNodeElect(SSyncNode* pSyncNode) {
|
||||||
|
int32_t ret = 0;
|
||||||
if (pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER) {
|
if (pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER) {
|
||||||
syncNodeFollower2Candidate(pSyncNode);
|
syncNodeFollower2Candidate(pSyncNode);
|
||||||
}
|
}
|
||||||
|
@ -62,7 +63,15 @@ int32_t syncNodeElect(SSyncNode* pSyncNode) {
|
||||||
votesRespondReset(pSyncNode->pVotesRespond, pSyncNode->pRaftStore->currentTerm);
|
votesRespondReset(pSyncNode->pVotesRespond, pSyncNode->pRaftStore->currentTerm);
|
||||||
|
|
||||||
syncNodeVoteForSelf(pSyncNode);
|
syncNodeVoteForSelf(pSyncNode);
|
||||||
int32_t ret = syncNodeRequestVotePeers(pSyncNode);
|
if (voteGrantedMajority(pSyncNode->pVotesGranted)) {
|
||||||
|
// only myself, to leader
|
||||||
|
assert(!pSyncNode->pVotesGranted->toLeader);
|
||||||
|
syncNodeCandidate2Leader(pSyncNode);
|
||||||
|
pSyncNode->pVotesGranted->toLeader = true;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = syncNodeRequestVotePeers(pSyncNode);
|
||||||
assert(ret == 0);
|
assert(ret == 0);
|
||||||
syncNodeResetElectTimer(pSyncNode);
|
syncNodeResetElectTimer(pSyncNode);
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ static void syncEnvTick(void *param, void *tmrId) {
|
||||||
if (atomic_load_64(&pSyncEnv->envTickTimerLogicClockUser) <= atomic_load_64(&pSyncEnv->envTickTimerLogicClock)) {
|
if (atomic_load_64(&pSyncEnv->envTickTimerLogicClockUser) <= atomic_load_64(&pSyncEnv->envTickTimerLogicClock)) {
|
||||||
++(pSyncEnv->envTickTimerCounter);
|
++(pSyncEnv->envTickTimerCounter);
|
||||||
sTrace(
|
sTrace(
|
||||||
"syncEnvTick do ... envTickTimerLogicClockUser:%lu, envTickTimerLogicClock:%lu, envTickTimerCounter:%lu, "
|
"syncEnvTick do ... envTickTimerLogicClockUser:%" PRIu64 ", envTickTimerLogicClock:%" PRIu64 ", envTickTimerCounter:%" PRIu64 ", "
|
||||||
"envTickTimerMS:%d, tmrId:%p",
|
"envTickTimerMS:%d, tmrId:%p",
|
||||||
pSyncEnv->envTickTimerLogicClockUser, pSyncEnv->envTickTimerLogicClock, pSyncEnv->envTickTimerCounter,
|
pSyncEnv->envTickTimerLogicClockUser, pSyncEnv->envTickTimerLogicClock, pSyncEnv->envTickTimerCounter,
|
||||||
pSyncEnv->envTickTimerMS, tmrId);
|
pSyncEnv->envTickTimerMS, tmrId);
|
||||||
|
@ -64,7 +64,7 @@ static void syncEnvTick(void *param, void *tmrId) {
|
||||||
taosTmrReset(syncEnvTick, pSyncEnv->envTickTimerMS, pSyncEnv, pSyncEnv->pTimerManager, &pSyncEnv->pEnvTickTimer);
|
taosTmrReset(syncEnvTick, pSyncEnv->envTickTimerMS, pSyncEnv, pSyncEnv->pTimerManager, &pSyncEnv->pEnvTickTimer);
|
||||||
} else {
|
} else {
|
||||||
sTrace(
|
sTrace(
|
||||||
"syncEnvTick pass ... envTickTimerLogicClockUser:%lu, envTickTimerLogicClock:%lu, envTickTimerCounter:%lu, "
|
"syncEnvTick pass ... envTickTimerLogicClockUser:%" PRIu64 ", envTickTimerLogicClock:%" PRIu64 ", envTickTimerCounter:%" PRIu64 ", "
|
||||||
"envTickTimerMS:%d, tmrId:%p",
|
"envTickTimerMS:%d, tmrId:%p",
|
||||||
pSyncEnv->envTickTimerLogicClockUser, pSyncEnv->envTickTimerLogicClock, pSyncEnv->envTickTimerCounter,
|
pSyncEnv->envTickTimerLogicClockUser, pSyncEnv->envTickTimerLogicClock, pSyncEnv->envTickTimerCounter,
|
||||||
pSyncEnv->envTickTimerMS, tmrId);
|
pSyncEnv->envTickTimerMS, tmrId);
|
||||||
|
@ -74,7 +74,7 @@ static void syncEnvTick(void *param, void *tmrId) {
|
||||||
static SSyncEnv *doSyncEnvStart() {
|
static SSyncEnv *doSyncEnvStart() {
|
||||||
SSyncEnv *pSyncEnv = (SSyncEnv *)malloc(sizeof(SSyncEnv));
|
SSyncEnv *pSyncEnv = (SSyncEnv *)malloc(sizeof(SSyncEnv));
|
||||||
assert(pSyncEnv != NULL);
|
assert(pSyncEnv != NULL);
|
||||||
memset(pSyncEnv, 0, sizeof(pSyncEnv));
|
memset(pSyncEnv, 0, sizeof(SSyncEnv));
|
||||||
|
|
||||||
pSyncEnv->envTickTimerCounter = 0;
|
pSyncEnv->envTickTimerCounter = 0;
|
||||||
pSyncEnv->envTickTimerMS = ENV_TICK_TIMER_MS;
|
pSyncEnv->envTickTimerMS = ENV_TICK_TIMER_MS;
|
||||||
|
|
|
@ -269,6 +269,7 @@ static void *syncIOConsumerFunc(void *param) {
|
||||||
} else if (pRpcMsg->msgType == SYNC_PING_REPLY) {
|
} else if (pRpcMsg->msgType == SYNC_PING_REPLY) {
|
||||||
if (io->FpOnSyncPingReply != NULL) {
|
if (io->FpOnSyncPingReply != NULL) {
|
||||||
SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pRpcMsg);
|
SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pRpcMsg);
|
||||||
|
assert(pSyncMsg != NULL);
|
||||||
io->FpOnSyncPingReply(io->pSyncNode, pSyncMsg);
|
io->FpOnSyncPingReply(io->pSyncNode, pSyncMsg);
|
||||||
syncPingReplyDestroy(pSyncMsg);
|
syncPingReplyDestroy(pSyncMsg);
|
||||||
}
|
}
|
||||||
|
@ -276,6 +277,7 @@ static void *syncIOConsumerFunc(void *param) {
|
||||||
} else if (pRpcMsg->msgType == SYNC_CLIENT_REQUEST) {
|
} else if (pRpcMsg->msgType == SYNC_CLIENT_REQUEST) {
|
||||||
if (io->FpOnSyncClientRequest != NULL) {
|
if (io->FpOnSyncClientRequest != NULL) {
|
||||||
SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pRpcMsg);
|
SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pRpcMsg);
|
||||||
|
assert(pSyncMsg != NULL);
|
||||||
io->FpOnSyncClientRequest(io->pSyncNode, pSyncMsg);
|
io->FpOnSyncClientRequest(io->pSyncNode, pSyncMsg);
|
||||||
syncClientRequestDestroy(pSyncMsg);
|
syncClientRequestDestroy(pSyncMsg);
|
||||||
}
|
}
|
||||||
|
@ -283,6 +285,7 @@ static void *syncIOConsumerFunc(void *param) {
|
||||||
} else if (pRpcMsg->msgType == SYNC_REQUEST_VOTE) {
|
} else if (pRpcMsg->msgType == SYNC_REQUEST_VOTE) {
|
||||||
if (io->FpOnSyncRequestVote != NULL) {
|
if (io->FpOnSyncRequestVote != NULL) {
|
||||||
SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pRpcMsg);
|
SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pRpcMsg);
|
||||||
|
assert(pSyncMsg != NULL);
|
||||||
io->FpOnSyncRequestVote(io->pSyncNode, pSyncMsg);
|
io->FpOnSyncRequestVote(io->pSyncNode, pSyncMsg);
|
||||||
syncRequestVoteDestroy(pSyncMsg);
|
syncRequestVoteDestroy(pSyncMsg);
|
||||||
}
|
}
|
||||||
|
@ -290,6 +293,7 @@ static void *syncIOConsumerFunc(void *param) {
|
||||||
} else if (pRpcMsg->msgType == SYNC_REQUEST_VOTE_REPLY) {
|
} else if (pRpcMsg->msgType == SYNC_REQUEST_VOTE_REPLY) {
|
||||||
if (io->FpOnSyncRequestVoteReply != NULL) {
|
if (io->FpOnSyncRequestVoteReply != NULL) {
|
||||||
SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pRpcMsg);
|
SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pRpcMsg);
|
||||||
|
assert(pSyncMsg != NULL);
|
||||||
io->FpOnSyncRequestVoteReply(io->pSyncNode, pSyncMsg);
|
io->FpOnSyncRequestVoteReply(io->pSyncNode, pSyncMsg);
|
||||||
syncRequestVoteReplyDestroy(pSyncMsg);
|
syncRequestVoteReplyDestroy(pSyncMsg);
|
||||||
}
|
}
|
||||||
|
@ -297,6 +301,7 @@ static void *syncIOConsumerFunc(void *param) {
|
||||||
} else if (pRpcMsg->msgType == SYNC_APPEND_ENTRIES) {
|
} else if (pRpcMsg->msgType == SYNC_APPEND_ENTRIES) {
|
||||||
if (io->FpOnSyncAppendEntries != NULL) {
|
if (io->FpOnSyncAppendEntries != NULL) {
|
||||||
SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pRpcMsg);
|
SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pRpcMsg);
|
||||||
|
assert(pSyncMsg != NULL);
|
||||||
io->FpOnSyncAppendEntries(io->pSyncNode, pSyncMsg);
|
io->FpOnSyncAppendEntries(io->pSyncNode, pSyncMsg);
|
||||||
syncAppendEntriesDestroy(pSyncMsg);
|
syncAppendEntriesDestroy(pSyncMsg);
|
||||||
}
|
}
|
||||||
|
@ -304,6 +309,7 @@ static void *syncIOConsumerFunc(void *param) {
|
||||||
} else if (pRpcMsg->msgType == SYNC_APPEND_ENTRIES_REPLY) {
|
} else if (pRpcMsg->msgType == SYNC_APPEND_ENTRIES_REPLY) {
|
||||||
if (io->FpOnSyncAppendEntriesReply != NULL) {
|
if (io->FpOnSyncAppendEntriesReply != NULL) {
|
||||||
SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pRpcMsg);
|
SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pRpcMsg);
|
||||||
|
assert(pSyncMsg != NULL);
|
||||||
io->FpOnSyncAppendEntriesReply(io->pSyncNode, pSyncMsg);
|
io->FpOnSyncAppendEntriesReply(io->pSyncNode, pSyncMsg);
|
||||||
syncAppendEntriesReplyDestroy(pSyncMsg);
|
syncAppendEntriesReplyDestroy(pSyncMsg);
|
||||||
}
|
}
|
||||||
|
@ -311,6 +317,7 @@ static void *syncIOConsumerFunc(void *param) {
|
||||||
} else if (pRpcMsg->msgType == SYNC_TIMEOUT) {
|
} else if (pRpcMsg->msgType == SYNC_TIMEOUT) {
|
||||||
if (io->FpOnSyncTimeout != NULL) {
|
if (io->FpOnSyncTimeout != NULL) {
|
||||||
SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pRpcMsg);
|
SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pRpcMsg);
|
||||||
|
assert(pSyncMsg != NULL);
|
||||||
io->FpOnSyncTimeout(io->pSyncNode, pSyncMsg);
|
io->FpOnSyncTimeout(io->pSyncNode, pSyncMsg);
|
||||||
syncTimeoutDestroy(pSyncMsg);
|
syncTimeoutDestroy(pSyncMsg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,22 +70,24 @@ cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) {
|
||||||
char u64buf[128];
|
char u64buf[128];
|
||||||
cJSON *pRoot = cJSON_CreateObject();
|
cJSON *pRoot = cJSON_CreateObject();
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "replicaNum", pSyncIndexMgr->replicaNum);
|
if (pSyncIndexMgr != NULL) {
|
||||||
cJSON *pReplicas = cJSON_CreateArray();
|
cJSON_AddNumberToObject(pRoot, "replicaNum", pSyncIndexMgr->replicaNum);
|
||||||
cJSON_AddItemToObject(pRoot, "replicas", pReplicas);
|
cJSON *pReplicas = cJSON_CreateArray();
|
||||||
for (int i = 0; i < pSyncIndexMgr->replicaNum; ++i) {
|
cJSON_AddItemToObject(pRoot, "replicas", pReplicas);
|
||||||
cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pSyncIndexMgr->replicas))[i]));
|
for (int i = 0; i < pSyncIndexMgr->replicaNum; ++i) {
|
||||||
|
cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pSyncIndexMgr->replicas))[i]));
|
||||||
|
}
|
||||||
|
int respondNum = 0;
|
||||||
|
int *arr = (int *)malloc(sizeof(int) * pSyncIndexMgr->replicaNum);
|
||||||
|
for (int i = 0; i < pSyncIndexMgr->replicaNum; ++i) {
|
||||||
|
arr[i] = pSyncIndexMgr->index[i];
|
||||||
|
}
|
||||||
|
cJSON *pIndex = cJSON_CreateIntArray(arr, pSyncIndexMgr->replicaNum);
|
||||||
|
free(arr);
|
||||||
|
cJSON_AddItemToObject(pRoot, "index", pIndex);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncIndexMgr->pSyncNode);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
||||||
}
|
}
|
||||||
int respondNum = 0;
|
|
||||||
int *arr = (int *)malloc(sizeof(int) * pSyncIndexMgr->replicaNum);
|
|
||||||
for (int i = 0; i < pSyncIndexMgr->replicaNum; ++i) {
|
|
||||||
arr[i] = pSyncIndexMgr->index[i];
|
|
||||||
}
|
|
||||||
cJSON *pIndex = cJSON_CreateIntArray(arr, pSyncIndexMgr->replicaNum);
|
|
||||||
free(arr);
|
|
||||||
cJSON_AddItemToObject(pRoot, "index", pIndex);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncIndexMgr->pSyncNode);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
|
||||||
|
|
||||||
cJSON *pJson = cJSON_CreateObject();
|
cJSON *pJson = cJSON_CreateObject();
|
||||||
cJSON_AddItemToObject(pJson, "pSyncIndexMgr", pRoot);
|
cJSON_AddItemToObject(pJson, "pSyncIndexMgr", pRoot);
|
||||||
|
|
|
@ -103,6 +103,12 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) {
|
||||||
assert(pSyncNode != NULL);
|
assert(pSyncNode != NULL);
|
||||||
memset(pSyncNode, 0, sizeof(SSyncNode));
|
memset(pSyncNode, 0, sizeof(SSyncNode));
|
||||||
|
|
||||||
|
if (taosMkDir(pSyncInfo->path) != 0) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
sError("failed to create dir:%s since %s", pSyncInfo->path, terrstr());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// init by SSyncInfo
|
// init by SSyncInfo
|
||||||
pSyncNode->vgId = pSyncInfo->vgId;
|
pSyncNode->vgId = pSyncInfo->vgId;
|
||||||
pSyncNode->syncCfg = pSyncInfo->syncCfg;
|
pSyncNode->syncCfg = pSyncInfo->syncCfg;
|
||||||
|
@ -200,6 +206,9 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) {
|
||||||
pSyncNode->FpOnAppendEntriesReply = syncNodeOnAppendEntriesReplyCb;
|
pSyncNode->FpOnAppendEntriesReply = syncNodeOnAppendEntriesReplyCb;
|
||||||
pSyncNode->FpOnTimeout = syncNodeOnTimeoutCb;
|
pSyncNode->FpOnTimeout = syncNodeOnTimeoutCb;
|
||||||
|
|
||||||
|
// start raft
|
||||||
|
syncNodeBecomeFollower(pSyncNode);
|
||||||
|
|
||||||
return pSyncNode;
|
return pSyncNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,128 +364,130 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
|
||||||
char u64buf[128];
|
char u64buf[128];
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
|
|
||||||
// init by SSyncInfo
|
if (pSyncNode != NULL) {
|
||||||
cJSON_AddNumberToObject(pRoot, "vgId", pSyncNode->vgId);
|
// init by SSyncInfo
|
||||||
cJSON_AddStringToObject(pRoot, "path", pSyncNode->path);
|
cJSON_AddNumberToObject(pRoot, "vgId", pSyncNode->vgId);
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pWal);
|
cJSON_AddStringToObject(pRoot, "path", pSyncNode->path);
|
||||||
cJSON_AddStringToObject(pRoot, "pWal", u64buf);
|
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->rpcClient);
|
||||||
cJSON_AddStringToObject(pRoot, "rpcClient", u64buf);
|
cJSON_AddStringToObject(pRoot, "rpcClient", u64buf);
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpSendMsg);
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpSendMsg);
|
||||||
cJSON_AddStringToObject(pRoot, "FpSendMsg", u64buf);
|
cJSON_AddStringToObject(pRoot, "FpSendMsg", u64buf);
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->queue);
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->queue);
|
||||||
cJSON_AddStringToObject(pRoot, "queue", u64buf);
|
cJSON_AddStringToObject(pRoot, "queue", u64buf);
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpEqMsg);
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpEqMsg);
|
||||||
cJSON_AddStringToObject(pRoot, "FpEqMsg", u64buf);
|
cJSON_AddStringToObject(pRoot, "FpEqMsg", u64buf);
|
||||||
|
|
||||||
// init internal
|
// init internal
|
||||||
cJSON* pMe = syncUtilNodeInfo2Json(&pSyncNode->myNodeInfo);
|
cJSON* pMe = syncUtilNodeInfo2Json(&pSyncNode->myNodeInfo);
|
||||||
cJSON_AddItemToObject(pRoot, "myNodeInfo", pMe);
|
cJSON_AddItemToObject(pRoot, "myNodeInfo", pMe);
|
||||||
cJSON* pRaftId = syncUtilRaftId2Json(&pSyncNode->myRaftId);
|
cJSON* pRaftId = syncUtilRaftId2Json(&pSyncNode->myRaftId);
|
||||||
cJSON_AddItemToObject(pRoot, "myRaftId", pRaftId);
|
cJSON_AddItemToObject(pRoot, "myRaftId", pRaftId);
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "peersNum", pSyncNode->peersNum);
|
cJSON_AddNumberToObject(pRoot, "peersNum", pSyncNode->peersNum);
|
||||||
cJSON* pPeers = cJSON_CreateArray();
|
cJSON* pPeers = cJSON_CreateArray();
|
||||||
cJSON_AddItemToObject(pRoot, "peersNodeInfo", pPeers);
|
cJSON_AddItemToObject(pRoot, "peersNodeInfo", pPeers);
|
||||||
for (int i = 0; i < pSyncNode->peersNum; ++i) {
|
for (int i = 0; i < pSyncNode->peersNum; ++i) {
|
||||||
cJSON_AddItemToArray(pPeers, syncUtilNodeInfo2Json(&pSyncNode->peersNodeInfo[i]));
|
cJSON_AddItemToArray(pPeers, syncUtilNodeInfo2Json(&pSyncNode->peersNodeInfo[i]));
|
||||||
|
}
|
||||||
|
cJSON* pPeersId = cJSON_CreateArray();
|
||||||
|
cJSON_AddItemToObject(pRoot, "peersId", pPeersId);
|
||||||
|
for (int i = 0; i < pSyncNode->peersNum; ++i) {
|
||||||
|
cJSON_AddItemToArray(pPeersId, syncUtilRaftId2Json(&pSyncNode->peersId[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON_AddNumberToObject(pRoot, "replicaNum", pSyncNode->replicaNum);
|
||||||
|
cJSON* pReplicasId = cJSON_CreateArray();
|
||||||
|
cJSON_AddItemToObject(pRoot, "replicasId", pReplicasId);
|
||||||
|
for (int i = 0; i < pSyncNode->replicaNum; ++i) {
|
||||||
|
cJSON_AddItemToArray(pReplicasId, syncUtilRaftId2Json(&pSyncNode->replicasId[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
// raft algorithm
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pFsm);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pFsm", u64buf);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "quorum", pSyncNode->quorum);
|
||||||
|
cJSON* pLaderCache = syncUtilRaftId2Json(&pSyncNode->leaderCache);
|
||||||
|
cJSON_AddItemToObject(pRoot, "leaderCache", pLaderCache);
|
||||||
|
|
||||||
|
// tla+ server vars
|
||||||
|
cJSON_AddNumberToObject(pRoot, "state", pSyncNode->state);
|
||||||
|
cJSON_AddStringToObject(pRoot, "state_str", syncUtilState2String(pSyncNode->state));
|
||||||
|
char tmpBuf[RAFT_STORE_BLOCK_SIZE];
|
||||||
|
raftStoreSerialize(pSyncNode->pRaftStore, tmpBuf, sizeof(tmpBuf));
|
||||||
|
cJSON_AddStringToObject(pRoot, "pRaftStore", tmpBuf);
|
||||||
|
|
||||||
|
// tla+ candidate vars
|
||||||
|
cJSON_AddItemToObject(pRoot, "pVotesGranted", voteGranted2Json(pSyncNode->pVotesGranted));
|
||||||
|
cJSON_AddItemToObject(pRoot, "pVotesRespond", votesRespond2Json(pSyncNode->pVotesRespond));
|
||||||
|
|
||||||
|
// tla+ leader vars
|
||||||
|
cJSON_AddItemToObject(pRoot, "pNextIndex", syncIndexMgr2Json(pSyncNode->pNextIndex));
|
||||||
|
cJSON_AddItemToObject(pRoot, "pMatchIndex", syncIndexMgr2Json(pSyncNode->pMatchIndex));
|
||||||
|
|
||||||
|
// tla+ log vars
|
||||||
|
cJSON_AddItemToObject(pRoot, "pLogStore", logStore2Json(pSyncNode->pLogStore));
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64 "", pSyncNode->commitIndex);
|
||||||
|
cJSON_AddStringToObject(pRoot, "commitIndex", u64buf);
|
||||||
|
|
||||||
|
// ping timer
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pPingTimer);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pPingTimer", u64buf);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "pingTimerMS", pSyncNode->pingTimerMS);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64 "", pSyncNode->pingTimerLogicClock);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pingTimerLogicClock", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64 "", pSyncNode->pingTimerLogicClockUser);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pingTimerLogicClockUser", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpPingTimerCB);
|
||||||
|
cJSON_AddStringToObject(pRoot, "FpPingTimerCB", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64 "", pSyncNode->pingTimerCounter);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pingTimerCounter", u64buf);
|
||||||
|
|
||||||
|
// elect timer
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pElectTimer);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pElectTimer", u64buf);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "electTimerMS", pSyncNode->electTimerMS);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64 "", pSyncNode->electTimerLogicClock);
|
||||||
|
cJSON_AddStringToObject(pRoot, "electTimerLogicClock", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64 "", pSyncNode->electTimerLogicClockUser);
|
||||||
|
cJSON_AddStringToObject(pRoot, "electTimerLogicClockUser", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpElectTimerCB);
|
||||||
|
cJSON_AddStringToObject(pRoot, "FpElectTimerCB", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64 "", pSyncNode->electTimerCounter);
|
||||||
|
cJSON_AddStringToObject(pRoot, "electTimerCounter", u64buf);
|
||||||
|
|
||||||
|
// heartbeat timer
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pHeartbeatTimer);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pHeartbeatTimer", u64buf);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "heartbeatTimerMS", pSyncNode->heartbeatTimerMS);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64 "", pSyncNode->heartbeatTimerLogicClock);
|
||||||
|
cJSON_AddStringToObject(pRoot, "heartbeatTimerLogicClock", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64 "", pSyncNode->heartbeatTimerLogicClockUser);
|
||||||
|
cJSON_AddStringToObject(pRoot, "heartbeatTimerLogicClockUser", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpHeartbeatTimerCB);
|
||||||
|
cJSON_AddStringToObject(pRoot, "FpHeartbeatTimerCB", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64 "", pSyncNode->heartbeatTimerCounter);
|
||||||
|
cJSON_AddStringToObject(pRoot, "heartbeatTimerCounter", u64buf);
|
||||||
|
|
||||||
|
// callback
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnPing);
|
||||||
|
cJSON_AddStringToObject(pRoot, "FpOnPing", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnPingReply);
|
||||||
|
cJSON_AddStringToObject(pRoot, "FpOnPingReply", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnRequestVote);
|
||||||
|
cJSON_AddStringToObject(pRoot, "FpOnRequestVote", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnRequestVoteReply);
|
||||||
|
cJSON_AddStringToObject(pRoot, "FpOnRequestVoteReply", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnAppendEntries);
|
||||||
|
cJSON_AddStringToObject(pRoot, "FpOnAppendEntries", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnAppendEntriesReply);
|
||||||
|
cJSON_AddStringToObject(pRoot, "FpOnAppendEntriesReply", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnTimeout);
|
||||||
|
cJSON_AddStringToObject(pRoot, "FpOnTimeout", u64buf);
|
||||||
}
|
}
|
||||||
cJSON* pPeersId = cJSON_CreateArray();
|
|
||||||
cJSON_AddItemToObject(pRoot, "peersId", pPeersId);
|
|
||||||
for (int i = 0; i < pSyncNode->peersNum; ++i) {
|
|
||||||
cJSON_AddItemToArray(pPeersId, syncUtilRaftId2Json(&pSyncNode->peersId[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "replicaNum", pSyncNode->replicaNum);
|
|
||||||
cJSON* pReplicasId = cJSON_CreateArray();
|
|
||||||
cJSON_AddItemToObject(pRoot, "replicasId", pReplicasId);
|
|
||||||
for (int i = 0; i < pSyncNode->replicaNum; ++i) {
|
|
||||||
cJSON_AddItemToArray(pReplicasId, syncUtilRaftId2Json(&pSyncNode->replicasId[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
// raft algorithm
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pFsm);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pFsm", u64buf);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "quorum", pSyncNode->quorum);
|
|
||||||
cJSON* pLaderCache = syncUtilRaftId2Json(&pSyncNode->leaderCache);
|
|
||||||
cJSON_AddItemToObject(pRoot, "leaderCache", pLaderCache);
|
|
||||||
|
|
||||||
// tla+ server vars
|
|
||||||
cJSON_AddNumberToObject(pRoot, "state", pSyncNode->state);
|
|
||||||
cJSON_AddStringToObject(pRoot, "state_str", syncUtilState2String(pSyncNode->state));
|
|
||||||
char tmpBuf[RAFT_STORE_BLOCK_SIZE];
|
|
||||||
raftStoreSerialize(pSyncNode->pRaftStore, tmpBuf, sizeof(tmpBuf));
|
|
||||||
cJSON_AddStringToObject(pRoot, "pRaftStore", tmpBuf);
|
|
||||||
|
|
||||||
// tla+ candidate vars
|
|
||||||
cJSON_AddItemToObject(pRoot, "pVotesGranted", voteGranted2Json(pSyncNode->pVotesGranted));
|
|
||||||
cJSON_AddItemToObject(pRoot, "pVotesRespond", votesRespond2Json(pSyncNode->pVotesRespond));
|
|
||||||
|
|
||||||
// tla+ leader vars
|
|
||||||
cJSON_AddItemToObject(pRoot, "pNextIndex", syncIndexMgr2Json(pSyncNode->pNextIndex));
|
|
||||||
cJSON_AddItemToObject(pRoot, "pMatchIndex", syncIndexMgr2Json(pSyncNode->pMatchIndex));
|
|
||||||
|
|
||||||
// tla+ log vars
|
|
||||||
cJSON_AddItemToObject(pRoot, "pLogStore", logStore2Json(pSyncNode->pLogStore));
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%ld", pSyncNode->commitIndex);
|
|
||||||
cJSON_AddStringToObject(pRoot, "commitIndex", u64buf);
|
|
||||||
|
|
||||||
// ping timer
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pPingTimer);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pPingTimer", u64buf);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "pingTimerMS", pSyncNode->pingTimerMS);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->pingTimerLogicClock);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pingTimerLogicClock", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->pingTimerLogicClockUser);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pingTimerLogicClockUser", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpPingTimerCB);
|
|
||||||
cJSON_AddStringToObject(pRoot, "FpPingTimerCB", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->pingTimerCounter);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pingTimerCounter", u64buf);
|
|
||||||
|
|
||||||
// elect timer
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pElectTimer);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pElectTimer", u64buf);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "electTimerMS", pSyncNode->electTimerMS);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->electTimerLogicClock);
|
|
||||||
cJSON_AddStringToObject(pRoot, "electTimerLogicClock", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->electTimerLogicClockUser);
|
|
||||||
cJSON_AddStringToObject(pRoot, "electTimerLogicClockUser", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpElectTimerCB);
|
|
||||||
cJSON_AddStringToObject(pRoot, "FpElectTimerCB", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->electTimerCounter);
|
|
||||||
cJSON_AddStringToObject(pRoot, "electTimerCounter", u64buf);
|
|
||||||
|
|
||||||
// heartbeat timer
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pHeartbeatTimer);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pHeartbeatTimer", u64buf);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "heartbeatTimerMS", pSyncNode->heartbeatTimerMS);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->heartbeatTimerLogicClock);
|
|
||||||
cJSON_AddStringToObject(pRoot, "heartbeatTimerLogicClock", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->heartbeatTimerLogicClockUser);
|
|
||||||
cJSON_AddStringToObject(pRoot, "heartbeatTimerLogicClockUser", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpHeartbeatTimerCB);
|
|
||||||
cJSON_AddStringToObject(pRoot, "FpHeartbeatTimerCB", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pSyncNode->heartbeatTimerCounter);
|
|
||||||
cJSON_AddStringToObject(pRoot, "heartbeatTimerCounter", u64buf);
|
|
||||||
|
|
||||||
// callback
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnPing);
|
|
||||||
cJSON_AddStringToObject(pRoot, "FpOnPing", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnPingReply);
|
|
||||||
cJSON_AddStringToObject(pRoot, "FpOnPingReply", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnRequestVote);
|
|
||||||
cJSON_AddStringToObject(pRoot, "FpOnRequestVote", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnRequestVoteReply);
|
|
||||||
cJSON_AddStringToObject(pRoot, "FpOnRequestVoteReply", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnAppendEntries);
|
|
||||||
cJSON_AddStringToObject(pRoot, "FpOnAppendEntries", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnAppendEntriesReply);
|
|
||||||
cJSON_AddStringToObject(pRoot, "FpOnAppendEntriesReply", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnTimeout);
|
|
||||||
cJSON_AddStringToObject(pRoot, "FpOnTimeout", u64buf);
|
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
cJSON_AddItemToObject(pJson, "SSyncNode", pRoot);
|
cJSON_AddItemToObject(pJson, "SSyncNode", pRoot);
|
||||||
|
@ -500,15 +511,17 @@ void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncNodeBecomeFollower(SSyncNode* pSyncNode) {
|
void syncNodeBecomeFollower(SSyncNode* pSyncNode) {
|
||||||
|
// maybe clear leader cache
|
||||||
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
|
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
|
||||||
pSyncNode->leaderCache = EMPTY_RAFT_ID;
|
pSyncNode->leaderCache = EMPTY_RAFT_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// state change
|
||||||
pSyncNode->state = TAOS_SYNC_STATE_FOLLOWER;
|
pSyncNode->state = TAOS_SYNC_STATE_FOLLOWER;
|
||||||
syncNodeStopHeartbeatTimer(pSyncNode);
|
syncNodeStopHeartbeatTimer(pSyncNode);
|
||||||
|
|
||||||
int32_t electMS = syncUtilElectRandomMS();
|
// reset elect timer
|
||||||
syncNodeRestartElectTimer(pSyncNode, electMS);
|
syncNodeResetElectTimer(pSyncNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TLA+ Spec
|
// TLA+ Spec
|
||||||
|
@ -530,20 +543,32 @@ void syncNodeBecomeFollower(SSyncNode* pSyncNode) {
|
||||||
// /\ UNCHANGED <<messages, currentTerm, votedFor, candidateVars, logVars>>
|
// /\ UNCHANGED <<messages, currentTerm, votedFor, candidateVars, logVars>>
|
||||||
//
|
//
|
||||||
void syncNodeBecomeLeader(SSyncNode* pSyncNode) {
|
void syncNodeBecomeLeader(SSyncNode* pSyncNode) {
|
||||||
|
// state change
|
||||||
pSyncNode->state = TAOS_SYNC_STATE_LEADER;
|
pSyncNode->state = TAOS_SYNC_STATE_LEADER;
|
||||||
|
|
||||||
|
// set leader cache
|
||||||
pSyncNode->leaderCache = pSyncNode->myRaftId;
|
pSyncNode->leaderCache = pSyncNode->myRaftId;
|
||||||
|
|
||||||
for (int i = 0; i < pSyncNode->pNextIndex->replicaNum; ++i) {
|
for (int i = 0; i < pSyncNode->pNextIndex->replicaNum; ++i) {
|
||||||
|
// maybe overwrite myself, no harm
|
||||||
|
// just do it!
|
||||||
pSyncNode->pNextIndex->index[i] = pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore) + 1;
|
pSyncNode->pNextIndex->index[i] = pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < pSyncNode->pMatchIndex->replicaNum; ++i) {
|
for (int i = 0; i < pSyncNode->pMatchIndex->replicaNum; ++i) {
|
||||||
|
// maybe overwrite myself, no harm
|
||||||
|
// just do it!
|
||||||
pSyncNode->pMatchIndex->index[i] = SYNC_INDEX_INVALID;
|
pSyncNode->pMatchIndex->index[i] = SYNC_INDEX_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stop elect timer
|
||||||
syncNodeStopElectTimer(pSyncNode);
|
syncNodeStopElectTimer(pSyncNode);
|
||||||
syncNodeStartHeartbeatTimer(pSyncNode);
|
|
||||||
|
// start replicate right now!
|
||||||
syncNodeReplicate(pSyncNode);
|
syncNodeReplicate(pSyncNode);
|
||||||
|
|
||||||
|
// start heartbeat timer
|
||||||
|
syncNodeStartHeartbeatTimer(pSyncNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncNodeCandidate2Leader(SSyncNode* pSyncNode) {
|
void syncNodeCandidate2Leader(SSyncNode* pSyncNode) {
|
||||||
|
@ -568,6 +593,9 @@ void syncNodeCandidate2Follower(SSyncNode* pSyncNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// raft vote --------------
|
// raft vote --------------
|
||||||
|
|
||||||
|
// just called by syncNodeVoteForSelf
|
||||||
|
// need assert
|
||||||
void syncNodeVoteForTerm(SSyncNode* pSyncNode, SyncTerm term, SRaftId* pRaftId) {
|
void syncNodeVoteForTerm(SSyncNode* pSyncNode, SyncTerm term, SRaftId* pRaftId) {
|
||||||
assert(term == pSyncNode->pRaftStore->currentTerm);
|
assert(term == pSyncNode->pRaftStore->currentTerm);
|
||||||
assert(!raftStoreHasVoted(pSyncNode->pRaftStore));
|
assert(!raftStoreHasVoted(pSyncNode->pRaftStore));
|
||||||
|
@ -575,6 +603,7 @@ void syncNodeVoteForTerm(SSyncNode* pSyncNode, SyncTerm term, SRaftId* pRaftId)
|
||||||
raftStoreVote(pSyncNode->pRaftStore, pRaftId);
|
raftStoreVote(pSyncNode->pRaftStore, pRaftId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// simulate get vote from outside
|
||||||
void syncNodeVoteForSelf(SSyncNode* pSyncNode) {
|
void syncNodeVoteForSelf(SSyncNode* pSyncNode) {
|
||||||
syncNodeVoteForTerm(pSyncNode, pSyncNode->pRaftStore->currentTerm, &(pSyncNode->myRaftId));
|
syncNodeVoteForTerm(pSyncNode, pSyncNode->pRaftStore->currentTerm, &(pSyncNode->myRaftId));
|
||||||
|
|
||||||
|
@ -589,8 +618,6 @@ void syncNodeVoteForSelf(SSyncNode* pSyncNode) {
|
||||||
syncRequestVoteReplyDestroy(pMsg);
|
syncRequestVoteReplyDestroy(pMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncNodeMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {}
|
|
||||||
|
|
||||||
// for debug --------------
|
// for debug --------------
|
||||||
void syncNodePrint(SSyncNode* pObj) {
|
void syncNodePrint(SSyncNode* pObj) {
|
||||||
char* serialized = syncNode2Str(pObj);
|
char* serialized = syncNode2Str(pObj);
|
||||||
|
@ -634,7 +661,7 @@ static void syncNodeEqPingTimer(void* param, void* tmrId) {
|
||||||
taosTmrReset(syncNodeEqPingTimer, pSyncNode->pingTimerMS, pSyncNode, gSyncEnv->pTimerManager,
|
taosTmrReset(syncNodeEqPingTimer, pSyncNode->pingTimerMS, pSyncNode, gSyncEnv->pTimerManager,
|
||||||
&pSyncNode->pPingTimer);
|
&pSyncNode->pPingTimer);
|
||||||
} else {
|
} else {
|
||||||
sTrace("==syncNodeEqPingTimer== pingTimerLogicClock:%lu, pingTimerLogicClockUser:%lu",
|
sTrace("==syncNodeEqPingTimer== pingTimerLogicClock:%" PRIu64 ", pingTimerLogicClockUser:%" PRIu64 "",
|
||||||
pSyncNode->pingTimerLogicClock, pSyncNode->pingTimerLogicClockUser);
|
pSyncNode->pingTimerLogicClock, pSyncNode->pingTimerLogicClockUser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -655,7 +682,7 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) {
|
||||||
taosTmrReset(syncNodeEqPingTimer, pSyncNode->pingTimerMS, pSyncNode, gSyncEnv->pTimerManager,
|
taosTmrReset(syncNodeEqPingTimer, pSyncNode->pingTimerMS, pSyncNode, gSyncEnv->pTimerManager,
|
||||||
&pSyncNode->pPingTimer);
|
&pSyncNode->pPingTimer);
|
||||||
} else {
|
} else {
|
||||||
sTrace("==syncNodeEqElectTimer== electTimerLogicClock:%lu, electTimerLogicClockUser:%lu",
|
sTrace("==syncNodeEqElectTimer== electTimerLogicClock:%" PRIu64 ", electTimerLogicClockUser:%" PRIu64 "",
|
||||||
pSyncNode->electTimerLogicClock, pSyncNode->electTimerLogicClockUser);
|
pSyncNode->electTimerLogicClock, pSyncNode->electTimerLogicClockUser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -676,7 +703,8 @@ static void syncNodeEqHeartbeatTimer(void* param, void* tmrId) {
|
||||||
taosTmrReset(syncNodeEqHeartbeatTimer, pSyncNode->heartbeatTimerMS, pSyncNode, gSyncEnv->pTimerManager,
|
taosTmrReset(syncNodeEqHeartbeatTimer, pSyncNode->heartbeatTimerMS, pSyncNode, gSyncEnv->pTimerManager,
|
||||||
&pSyncNode->pHeartbeatTimer);
|
&pSyncNode->pHeartbeatTimer);
|
||||||
} else {
|
} else {
|
||||||
sTrace("==syncNodeEqHeartbeatTimer== heartbeatTimerLogicClock:%lu, heartbeatTimerLogicClockUser:%lu",
|
sTrace("==syncNodeEqHeartbeatTimer== heartbeatTimerLogicClock:%" PRIu64 ", heartbeatTimerLogicClockUser:%" PRIu64
|
||||||
|
"",
|
||||||
pSyncNode->heartbeatTimerLogicClock, pSyncNode->heartbeatTimerLogicClockUser);
|
pSyncNode->heartbeatTimerLogicClock, pSyncNode->heartbeatTimerLogicClockUser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -713,4 +741,4 @@ static int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -212,17 +212,19 @@ SyncTimeout* syncTimeoutFromRpcMsg2(const SRpcMsg* pRpcMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* syncTimeout2Json(const SyncTimeout* pMsg) {
|
cJSON* syncTimeout2Json(const SyncTimeout* pMsg) {
|
||||||
char u64buf[128];
|
char u64buf[128];
|
||||||
|
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
if (pMsg != NULL) {
|
||||||
cJSON_AddNumberToObject(pRoot, "timeoutType", pMsg->timeoutType);
|
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->logicClock);
|
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
||||||
cJSON_AddStringToObject(pRoot, "logicClock", u64buf);
|
cJSON_AddNumberToObject(pRoot, "timeoutType", pMsg->timeoutType);
|
||||||
cJSON_AddNumberToObject(pRoot, "timerMS", pMsg->timerMS);
|
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->logicClock);
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pMsg->data);
|
cJSON_AddStringToObject(pRoot, "logicClock", u64buf);
|
||||||
cJSON_AddStringToObject(pRoot, "data", u64buf);
|
cJSON_AddNumberToObject(pRoot, "timerMS", pMsg->timerMS);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pMsg->data);
|
||||||
|
cJSON_AddStringToObject(pRoot, "data", u64buf);
|
||||||
|
}
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
cJSON_AddItemToObject(pJson, "SyncTimeout", pRoot);
|
cJSON_AddItemToObject(pJson, "SyncTimeout", pRoot);
|
||||||
|
@ -239,7 +241,7 @@ char* syncTimeout2Str(const SyncTimeout* pMsg) {
|
||||||
// for debug ----------------------
|
// for debug ----------------------
|
||||||
void syncTimeoutPrint(const SyncTimeout* pMsg) {
|
void syncTimeoutPrint(const SyncTimeout* pMsg) {
|
||||||
char* serialized = syncTimeout2Str(pMsg);
|
char* serialized = syncTimeout2Str(pMsg);
|
||||||
printf("syncTimeoutPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("syncTimeoutPrint | len:%zu | %s \n", strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
free(serialized);
|
free(serialized);
|
||||||
}
|
}
|
||||||
|
@ -342,50 +344,52 @@ SyncPing* syncPingFromRpcMsg2(const SRpcMsg* pRpcMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* syncPing2Json(const SyncPing* pMsg) {
|
cJSON* syncPing2Json(const SyncPing* pMsg) {
|
||||||
char u64buf[128];
|
char u64buf[128];
|
||||||
|
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
|
||||||
|
|
||||||
cJSON* pSrcId = cJSON_CreateObject();
|
if (pMsg != NULL) {
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr);
|
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
||||||
cJSON_AddStringToObject(pSrcId, "addr", u64buf);
|
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
||||||
{
|
|
||||||
uint64_t u64 = pMsg->srcId.addr;
|
cJSON* pSrcId = cJSON_CreateObject();
|
||||||
cJSON* pTmp = pSrcId;
|
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr);
|
||||||
char host[128];
|
cJSON_AddStringToObject(pSrcId, "addr", u64buf);
|
||||||
uint16_t port;
|
{
|
||||||
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
uint64_t u64 = pMsg->srcId.addr;
|
||||||
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
cJSON* pTmp = pSrcId;
|
||||||
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
char host[128];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||||
|
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
||||||
|
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
||||||
|
}
|
||||||
|
cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
|
||||||
|
cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
|
||||||
|
|
||||||
|
cJSON* pDestId = cJSON_CreateObject();
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr);
|
||||||
|
cJSON_AddStringToObject(pDestId, "addr", u64buf);
|
||||||
|
{
|
||||||
|
uint64_t u64 = pMsg->destId.addr;
|
||||||
|
cJSON* pTmp = pDestId;
|
||||||
|
char host[128];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||||
|
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
||||||
|
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
||||||
|
}
|
||||||
|
cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
|
||||||
|
cJSON_AddItemToObject(pRoot, "destId", pDestId);
|
||||||
|
|
||||||
|
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
||||||
|
char* s;
|
||||||
|
s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen);
|
||||||
|
cJSON_AddStringToObject(pRoot, "data", s);
|
||||||
|
free(s);
|
||||||
|
s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen);
|
||||||
|
cJSON_AddStringToObject(pRoot, "data2", s);
|
||||||
|
free(s);
|
||||||
}
|
}
|
||||||
cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
|
|
||||||
cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
|
|
||||||
|
|
||||||
cJSON* pDestId = cJSON_CreateObject();
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr);
|
|
||||||
cJSON_AddStringToObject(pDestId, "addr", u64buf);
|
|
||||||
{
|
|
||||||
uint64_t u64 = pMsg->destId.addr;
|
|
||||||
cJSON* pTmp = pDestId;
|
|
||||||
char host[128];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
|
||||||
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
|
||||||
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
|
||||||
}
|
|
||||||
cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
|
|
||||||
cJSON_AddItemToObject(pRoot, "destId", pDestId);
|
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
|
||||||
char* s;
|
|
||||||
s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen);
|
|
||||||
cJSON_AddStringToObject(pRoot, "data", s);
|
|
||||||
free(s);
|
|
||||||
s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen);
|
|
||||||
cJSON_AddStringToObject(pRoot, "data2", s);
|
|
||||||
free(s);
|
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
cJSON_AddItemToObject(pJson, "SyncPing", pRoot);
|
cJSON_AddItemToObject(pJson, "SyncPing", pRoot);
|
||||||
|
@ -505,50 +509,52 @@ SyncPingReply* syncPingReplyFromRpcMsg2(const SRpcMsg* pRpcMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* syncPingReply2Json(const SyncPingReply* pMsg) {
|
cJSON* syncPingReply2Json(const SyncPingReply* pMsg) {
|
||||||
char u64buf[128];
|
char u64buf[128];
|
||||||
|
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
|
||||||
|
|
||||||
cJSON* pSrcId = cJSON_CreateObject();
|
if (pMsg != NULL) {
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr);
|
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
||||||
cJSON_AddStringToObject(pSrcId, "addr", u64buf);
|
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
||||||
{
|
|
||||||
uint64_t u64 = pMsg->srcId.addr;
|
cJSON* pSrcId = cJSON_CreateObject();
|
||||||
cJSON* pTmp = pSrcId;
|
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr);
|
||||||
char host[128];
|
cJSON_AddStringToObject(pSrcId, "addr", u64buf);
|
||||||
uint16_t port;
|
{
|
||||||
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
uint64_t u64 = pMsg->srcId.addr;
|
||||||
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
cJSON* pTmp = pSrcId;
|
||||||
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
char host[128];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||||
|
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
||||||
|
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
||||||
|
}
|
||||||
|
cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
|
||||||
|
cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
|
||||||
|
|
||||||
|
cJSON* pDestId = cJSON_CreateObject();
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr);
|
||||||
|
cJSON_AddStringToObject(pDestId, "addr", u64buf);
|
||||||
|
{
|
||||||
|
uint64_t u64 = pMsg->destId.addr;
|
||||||
|
cJSON* pTmp = pDestId;
|
||||||
|
char host[128];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||||
|
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
||||||
|
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
||||||
|
}
|
||||||
|
cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
|
||||||
|
cJSON_AddItemToObject(pRoot, "destId", pDestId);
|
||||||
|
|
||||||
|
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
||||||
|
char* s;
|
||||||
|
s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen);
|
||||||
|
cJSON_AddStringToObject(pRoot, "data", s);
|
||||||
|
free(s);
|
||||||
|
s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen);
|
||||||
|
cJSON_AddStringToObject(pRoot, "data2", s);
|
||||||
|
free(s);
|
||||||
}
|
}
|
||||||
cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
|
|
||||||
cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
|
|
||||||
|
|
||||||
cJSON* pDestId = cJSON_CreateObject();
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr);
|
|
||||||
cJSON_AddStringToObject(pDestId, "addr", u64buf);
|
|
||||||
{
|
|
||||||
uint64_t u64 = pMsg->destId.addr;
|
|
||||||
cJSON* pTmp = pDestId;
|
|
||||||
char host[128];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
|
||||||
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
|
||||||
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
|
||||||
}
|
|
||||||
cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
|
|
||||||
cJSON_AddItemToObject(pRoot, "destId", pDestId);
|
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
|
||||||
char* s;
|
|
||||||
s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen);
|
|
||||||
cJSON_AddStringToObject(pRoot, "data", s);
|
|
||||||
free(s);
|
|
||||||
s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen);
|
|
||||||
cJSON_AddStringToObject(pRoot, "data2", s);
|
|
||||||
free(s);
|
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
cJSON_AddItemToObject(pJson, "SyncPingReply", pRoot);
|
cJSON_AddItemToObject(pJson, "SyncPingReply", pRoot);
|
||||||
|
@ -565,27 +571,27 @@ char* syncPingReply2Str(const SyncPingReply* pMsg) {
|
||||||
// for debug ----------------------
|
// for debug ----------------------
|
||||||
void syncPingReplyPrint(const SyncPingReply* pMsg) {
|
void syncPingReplyPrint(const SyncPingReply* pMsg) {
|
||||||
char* serialized = syncPingReply2Str(pMsg);
|
char* serialized = syncPingReply2Str(pMsg);
|
||||||
printf("syncPingReplyPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("syncPingReplyPrint | len:%zu | %s \n", strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
free(serialized);
|
free(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncPingReplyPrint2(char* s, const SyncPingReply* pMsg) {
|
void syncPingReplyPrint2(char* s, const SyncPingReply* pMsg) {
|
||||||
char* serialized = syncPingReply2Str(pMsg);
|
char* serialized = syncPingReply2Str(pMsg);
|
||||||
printf("syncPingReplyPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("syncPingReplyPrint2 | len:%zu | %s | %s \n", strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
free(serialized);
|
free(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncPingReplyLog(const SyncPingReply* pMsg) {
|
void syncPingReplyLog(const SyncPingReply* pMsg) {
|
||||||
char* serialized = syncPingReply2Str(pMsg);
|
char* serialized = syncPingReply2Str(pMsg);
|
||||||
sTrace("syncPingReplyLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("syncPingReplyLog | len:%zu | %s", strlen(serialized), serialized);
|
||||||
free(serialized);
|
free(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncPingReplyLog2(char* s, const SyncPingReply* pMsg) {
|
void syncPingReplyLog2(char* s, const SyncPingReply* pMsg) {
|
||||||
char* serialized = syncPingReply2Str(pMsg);
|
char* serialized = syncPingReply2Str(pMsg);
|
||||||
sTrace("syncPingReplyLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("syncPingReplyLog2 | len:%zu | %s | %s", strlen(serialized), s, serialized);
|
||||||
free(serialized);
|
free(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -664,24 +670,26 @@ SyncClientRequest* syncClientRequestFromRpcMsg2(const SRpcMsg* pRpcMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* syncClientRequest2Json(const SyncClientRequest* pMsg) {
|
cJSON* syncClientRequest2Json(const SyncClientRequest* pMsg) {
|
||||||
char u64buf[128];
|
char u64buf[128];
|
||||||
|
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "originalRpcType", pMsg->originalRpcType);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->seqNum);
|
|
||||||
cJSON_AddStringToObject(pRoot, "seqNum", u64buf);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "isWeak", pMsg->isWeak);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
|
||||||
|
|
||||||
char* s;
|
if (pMsg != NULL) {
|
||||||
s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen);
|
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
||||||
cJSON_AddStringToObject(pRoot, "data", s);
|
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
||||||
free(s);
|
cJSON_AddNumberToObject(pRoot, "originalRpcType", pMsg->originalRpcType);
|
||||||
s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen);
|
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->seqNum);
|
||||||
cJSON_AddStringToObject(pRoot, "data2", s);
|
cJSON_AddStringToObject(pRoot, "seqNum", u64buf);
|
||||||
free(s);
|
cJSON_AddNumberToObject(pRoot, "isWeak", pMsg->isWeak);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
||||||
|
|
||||||
|
char* s;
|
||||||
|
s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen);
|
||||||
|
cJSON_AddStringToObject(pRoot, "data", s);
|
||||||
|
free(s);
|
||||||
|
s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen);
|
||||||
|
cJSON_AddStringToObject(pRoot, "data2", s);
|
||||||
|
free(s);
|
||||||
|
}
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
cJSON_AddItemToObject(pJson, "SyncClientRequest", pRoot);
|
cJSON_AddItemToObject(pJson, "SyncClientRequest", pRoot);
|
||||||
|
@ -785,47 +793,49 @@ SyncRequestVote* syncRequestVoteFromRpcMsg2(const SRpcMsg* pRpcMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* syncRequestVote2Json(const SyncRequestVote* pMsg) {
|
cJSON* syncRequestVote2Json(const SyncRequestVote* pMsg) {
|
||||||
char u64buf[128];
|
char u64buf[128];
|
||||||
|
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
|
||||||
|
|
||||||
cJSON* pSrcId = cJSON_CreateObject();
|
if (pMsg != NULL) {
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr);
|
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
||||||
cJSON_AddStringToObject(pSrcId, "addr", u64buf);
|
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
||||||
{
|
|
||||||
uint64_t u64 = pMsg->srcId.addr;
|
cJSON* pSrcId = cJSON_CreateObject();
|
||||||
cJSON* pTmp = pSrcId;
|
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr);
|
||||||
char host[128];
|
cJSON_AddStringToObject(pSrcId, "addr", u64buf);
|
||||||
uint16_t port;
|
{
|
||||||
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
uint64_t u64 = pMsg->srcId.addr;
|
||||||
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
cJSON* pTmp = pSrcId;
|
||||||
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
char host[128];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||||
|
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
||||||
|
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
||||||
|
}
|
||||||
|
cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
|
||||||
|
cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
|
||||||
|
|
||||||
|
cJSON* pDestId = cJSON_CreateObject();
|
||||||
|
cJSON_AddNumberToObject(pDestId, "addr", pMsg->destId.addr);
|
||||||
|
{
|
||||||
|
uint64_t u64 = pMsg->destId.addr;
|
||||||
|
cJSON* pTmp = pDestId;
|
||||||
|
char host[128];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||||
|
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
||||||
|
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
||||||
|
}
|
||||||
|
cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
|
||||||
|
cJSON_AddItemToObject(pRoot, "destId", pDestId);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term);
|
||||||
|
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->lastLogIndex);
|
||||||
|
cJSON_AddStringToObject(pRoot, "lastLogIndex", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->lastLogTerm);
|
||||||
|
cJSON_AddStringToObject(pRoot, "lastLogTerm", u64buf);
|
||||||
}
|
}
|
||||||
cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
|
|
||||||
cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
|
|
||||||
|
|
||||||
cJSON* pDestId = cJSON_CreateObject();
|
|
||||||
cJSON_AddNumberToObject(pDestId, "addr", pMsg->destId.addr);
|
|
||||||
{
|
|
||||||
uint64_t u64 = pMsg->destId.addr;
|
|
||||||
cJSON* pTmp = pDestId;
|
|
||||||
char host[128];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
|
||||||
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
|
||||||
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
|
||||||
}
|
|
||||||
cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
|
|
||||||
cJSON_AddItemToObject(pRoot, "destId", pDestId);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term);
|
|
||||||
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->lastLogIndex);
|
|
||||||
cJSON_AddStringToObject(pRoot, "lastLogIndex", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->lastLogTerm);
|
|
||||||
cJSON_AddStringToObject(pRoot, "lastLogTerm", u64buf);
|
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
cJSON_AddItemToObject(pJson, "SyncRequestVote", pRoot);
|
cJSON_AddItemToObject(pJson, "SyncRequestVote", pRoot);
|
||||||
|
@ -929,44 +939,46 @@ SyncRequestVoteReply* syncRequestVoteReplyFromRpcMsg2(const SRpcMsg* pRpcMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* syncRequestVoteReply2Json(const SyncRequestVoteReply* pMsg) {
|
cJSON* syncRequestVoteReply2Json(const SyncRequestVoteReply* pMsg) {
|
||||||
char u64buf[128];
|
char u64buf[128];
|
||||||
|
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
|
||||||
|
|
||||||
cJSON* pSrcId = cJSON_CreateObject();
|
if (pMsg != NULL) {
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr);
|
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
||||||
cJSON_AddStringToObject(pSrcId, "addr", u64buf);
|
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
||||||
{
|
|
||||||
uint64_t u64 = pMsg->srcId.addr;
|
cJSON* pSrcId = cJSON_CreateObject();
|
||||||
cJSON* pTmp = pSrcId;
|
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr);
|
||||||
char host[128];
|
cJSON_AddStringToObject(pSrcId, "addr", u64buf);
|
||||||
uint16_t port;
|
{
|
||||||
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
uint64_t u64 = pMsg->srcId.addr;
|
||||||
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
cJSON* pTmp = pSrcId;
|
||||||
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
char host[128];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||||
|
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
||||||
|
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
||||||
|
}
|
||||||
|
cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
|
||||||
|
cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
|
||||||
|
|
||||||
|
cJSON* pDestId = cJSON_CreateObject();
|
||||||
|
cJSON_AddNumberToObject(pDestId, "addr", pMsg->destId.addr);
|
||||||
|
{
|
||||||
|
uint64_t u64 = pMsg->destId.addr;
|
||||||
|
cJSON* pTmp = pDestId;
|
||||||
|
char host[128];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||||
|
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
||||||
|
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
||||||
|
}
|
||||||
|
cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
|
||||||
|
cJSON_AddItemToObject(pRoot, "destId", pDestId);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term);
|
||||||
|
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "vote_granted", pMsg->voteGranted);
|
||||||
}
|
}
|
||||||
cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
|
|
||||||
cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
|
|
||||||
|
|
||||||
cJSON* pDestId = cJSON_CreateObject();
|
|
||||||
cJSON_AddNumberToObject(pDestId, "addr", pMsg->destId.addr);
|
|
||||||
{
|
|
||||||
uint64_t u64 = pMsg->destId.addr;
|
|
||||||
cJSON* pTmp = pDestId;
|
|
||||||
char host[128];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
|
||||||
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
|
||||||
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
|
||||||
}
|
|
||||||
cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
|
|
||||||
cJSON_AddItemToObject(pRoot, "destId", pDestId);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term);
|
|
||||||
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "vote_granted", pMsg->voteGranted);
|
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
cJSON_AddItemToObject(pJson, "SyncRequestVoteReply", pRoot);
|
cJSON_AddItemToObject(pJson, "SyncRequestVoteReply", pRoot);
|
||||||
|
@ -1072,62 +1084,64 @@ SyncAppendEntries* syncAppendEntriesFromRpcMsg2(const SRpcMsg* pRpcMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* syncAppendEntries2Json(const SyncAppendEntries* pMsg) {
|
cJSON* syncAppendEntries2Json(const SyncAppendEntries* pMsg) {
|
||||||
char u64buf[128];
|
char u64buf[128];
|
||||||
|
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
|
||||||
|
|
||||||
cJSON* pSrcId = cJSON_CreateObject();
|
if (pMsg != NULL) {
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr);
|
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
||||||
cJSON_AddStringToObject(pSrcId, "addr", u64buf);
|
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
||||||
{
|
|
||||||
uint64_t u64 = pMsg->srcId.addr;
|
cJSON* pSrcId = cJSON_CreateObject();
|
||||||
cJSON* pTmp = pSrcId;
|
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr);
|
||||||
char host[128];
|
cJSON_AddStringToObject(pSrcId, "addr", u64buf);
|
||||||
uint16_t port;
|
{
|
||||||
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
uint64_t u64 = pMsg->srcId.addr;
|
||||||
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
cJSON* pTmp = pSrcId;
|
||||||
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
char host[128];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||||
|
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
||||||
|
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
||||||
|
}
|
||||||
|
cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
|
||||||
|
cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
|
||||||
|
|
||||||
|
cJSON* pDestId = cJSON_CreateObject();
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr);
|
||||||
|
cJSON_AddStringToObject(pDestId, "addr", u64buf);
|
||||||
|
{
|
||||||
|
uint64_t u64 = pMsg->destId.addr;
|
||||||
|
cJSON* pTmp = pDestId;
|
||||||
|
char host[128];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||||
|
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
||||||
|
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
||||||
|
}
|
||||||
|
cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
|
||||||
|
cJSON_AddItemToObject(pRoot, "destId", pDestId);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term);
|
||||||
|
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->prevLogIndex);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pre_log_index", u64buf);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->prevLogTerm);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pre_log_term", u64buf);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->commitIndex);
|
||||||
|
cJSON_AddStringToObject(pRoot, "commit_index", u64buf);
|
||||||
|
|
||||||
|
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
||||||
|
char* s;
|
||||||
|
s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen);
|
||||||
|
cJSON_AddStringToObject(pRoot, "data", s);
|
||||||
|
free(s);
|
||||||
|
s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen);
|
||||||
|
cJSON_AddStringToObject(pRoot, "data2", s);
|
||||||
|
free(s);
|
||||||
}
|
}
|
||||||
cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
|
|
||||||
cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
|
|
||||||
|
|
||||||
cJSON* pDestId = cJSON_CreateObject();
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr);
|
|
||||||
cJSON_AddStringToObject(pDestId, "addr", u64buf);
|
|
||||||
{
|
|
||||||
uint64_t u64 = pMsg->destId.addr;
|
|
||||||
cJSON* pTmp = pDestId;
|
|
||||||
char host[128];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
|
||||||
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
|
||||||
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
|
||||||
}
|
|
||||||
cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
|
|
||||||
cJSON_AddItemToObject(pRoot, "destId", pDestId);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term);
|
|
||||||
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->prevLogIndex);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pre_log_index", u64buf);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->prevLogTerm);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pre_log_term", u64buf);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->commitIndex);
|
|
||||||
cJSON_AddStringToObject(pRoot, "commit_index", u64buf);
|
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
|
||||||
char* s;
|
|
||||||
s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen);
|
|
||||||
cJSON_AddStringToObject(pRoot, "data", s);
|
|
||||||
free(s);
|
|
||||||
s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen);
|
|
||||||
cJSON_AddStringToObject(pRoot, "data2", s);
|
|
||||||
free(s);
|
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
cJSON_AddItemToObject(pJson, "SyncAppendEntries", pRoot);
|
cJSON_AddItemToObject(pJson, "SyncAppendEntries", pRoot);
|
||||||
|
@ -1231,47 +1245,49 @@ SyncAppendEntriesReply* syncAppendEntriesReplyFromRpcMsg2(const SRpcMsg* pRpcMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* syncAppendEntriesReply2Json(const SyncAppendEntriesReply* pMsg) {
|
cJSON* syncAppendEntriesReply2Json(const SyncAppendEntriesReply* pMsg) {
|
||||||
char u64buf[128];
|
char u64buf[128];
|
||||||
|
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
|
||||||
|
|
||||||
cJSON* pSrcId = cJSON_CreateObject();
|
if (pMsg != NULL) {
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr);
|
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
||||||
cJSON_AddStringToObject(pSrcId, "addr", u64buf);
|
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
||||||
{
|
|
||||||
uint64_t u64 = pMsg->srcId.addr;
|
cJSON* pSrcId = cJSON_CreateObject();
|
||||||
cJSON* pTmp = pSrcId;
|
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr);
|
||||||
char host[128];
|
cJSON_AddStringToObject(pSrcId, "addr", u64buf);
|
||||||
uint16_t port;
|
{
|
||||||
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
uint64_t u64 = pMsg->srcId.addr;
|
||||||
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
cJSON* pTmp = pSrcId;
|
||||||
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
char host[128];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||||
|
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
||||||
|
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
||||||
|
}
|
||||||
|
cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
|
||||||
|
cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
|
||||||
|
|
||||||
|
cJSON* pDestId = cJSON_CreateObject();
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr);
|
||||||
|
cJSON_AddStringToObject(pDestId, "addr", u64buf);
|
||||||
|
{
|
||||||
|
uint64_t u64 = pMsg->destId.addr;
|
||||||
|
cJSON* pTmp = pDestId;
|
||||||
|
char host[128];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||||
|
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
||||||
|
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
||||||
|
}
|
||||||
|
cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
|
||||||
|
cJSON_AddItemToObject(pRoot, "destId", pDestId);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term);
|
||||||
|
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "success", pMsg->success);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->matchIndex);
|
||||||
|
cJSON_AddStringToObject(pRoot, "matchIndex", u64buf);
|
||||||
}
|
}
|
||||||
cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
|
|
||||||
cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
|
|
||||||
|
|
||||||
cJSON* pDestId = cJSON_CreateObject();
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr);
|
|
||||||
cJSON_AddStringToObject(pDestId, "addr", u64buf);
|
|
||||||
{
|
|
||||||
uint64_t u64 = pMsg->destId.addr;
|
|
||||||
cJSON* pTmp = pDestId;
|
|
||||||
char host[128];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
|
||||||
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
|
||||||
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
|
||||||
}
|
|
||||||
cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
|
|
||||||
cJSON_AddItemToObject(pRoot, "destId", pDestId);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->term);
|
|
||||||
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "success", pMsg->success);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->matchIndex);
|
|
||||||
cJSON_AddStringToObject(pRoot, "matchIndex", u64buf);
|
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
cJSON_AddItemToObject(pJson, "SyncAppendEntriesReply", pRoot);
|
cJSON_AddItemToObject(pJson, "SyncAppendEntriesReply", pRoot);
|
||||||
|
|
|
@ -68,29 +68,31 @@ SSyncRaftEntry* syncEntryDeserialize(const char* buf, uint32_t len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry) {
|
cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry) {
|
||||||
char u64buf[128];
|
char u64buf[128];
|
||||||
|
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
cJSON_AddNumberToObject(pRoot, "bytes", pEntry->bytes);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "msgType", pEntry->msgType);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "originalRpcType", pEntry->originalRpcType);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pEntry->seqNum);
|
|
||||||
cJSON_AddStringToObject(pRoot, "seqNum", u64buf);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "isWeak", pEntry->isWeak);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pEntry->term);
|
|
||||||
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pEntry->index);
|
|
||||||
cJSON_AddStringToObject(pRoot, "index", u64buf);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "dataLen", pEntry->dataLen);
|
|
||||||
|
|
||||||
char* s;
|
if (pEntry != NULL) {
|
||||||
s = syncUtilprintBin((char*)(pEntry->data), pEntry->dataLen);
|
cJSON_AddNumberToObject(pRoot, "bytes", pEntry->bytes);
|
||||||
cJSON_AddStringToObject(pRoot, "data", s);
|
cJSON_AddNumberToObject(pRoot, "msgType", pEntry->msgType);
|
||||||
free(s);
|
cJSON_AddNumberToObject(pRoot, "originalRpcType", pEntry->originalRpcType);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%lu", pEntry->seqNum);
|
||||||
|
cJSON_AddStringToObject(pRoot, "seqNum", u64buf);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "isWeak", pEntry->isWeak);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%lu", pEntry->term);
|
||||||
|
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%lu", pEntry->index);
|
||||||
|
cJSON_AddStringToObject(pRoot, "index", u64buf);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "dataLen", pEntry->dataLen);
|
||||||
|
|
||||||
s = syncUtilprintBin2((char*)(pEntry->data), pEntry->dataLen);
|
char* s;
|
||||||
cJSON_AddStringToObject(pRoot, "data2", s);
|
s = syncUtilprintBin((char*)(pEntry->data), pEntry->dataLen);
|
||||||
free(s);
|
cJSON_AddStringToObject(pRoot, "data", s);
|
||||||
|
free(s);
|
||||||
|
|
||||||
|
s = syncUtilprintBin2((char*)(pEntry->data), pEntry->dataLen);
|
||||||
|
cJSON_AddStringToObject(pRoot, "data2", s);
|
||||||
|
free(s);
|
||||||
|
}
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
cJSON_AddItemToObject(pJson, "SSyncRaftEntry", pRoot);
|
cJSON_AddItemToObject(pJson, "SSyncRaftEntry", pRoot);
|
||||||
|
@ -107,26 +109,26 @@ char* syncEntry2Str(const SSyncRaftEntry* pEntry) {
|
||||||
// for debug ----------------------
|
// for debug ----------------------
|
||||||
void syncEntryPrint(const SSyncRaftEntry* pObj) {
|
void syncEntryPrint(const SSyncRaftEntry* pObj) {
|
||||||
char* serialized = syncEntry2Str(pObj);
|
char* serialized = syncEntry2Str(pObj);
|
||||||
printf("syncEntryPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("syncEntryPrint | len:%zu | %s \n", strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
free(serialized);
|
free(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncEntryPrint2(char* s, const SSyncRaftEntry* pObj) {
|
void syncEntryPrint2(char* s, const SSyncRaftEntry* pObj) {
|
||||||
char* serialized = syncEntry2Str(pObj);
|
char* serialized = syncEntry2Str(pObj);
|
||||||
printf("syncEntryPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("syncEntryPrint2 | len:%zu | %s | %s \n", strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
free(serialized);
|
free(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncEntryLog(const SSyncRaftEntry* pObj) {
|
void syncEntryLog(const SSyncRaftEntry* pObj) {
|
||||||
char* serialized = syncEntry2Str(pObj);
|
char* serialized = syncEntry2Str(pObj);
|
||||||
sTrace("syncEntryLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("syncEntryLog | len:%zu | %s", strlen(serialized), serialized);
|
||||||
free(serialized);
|
free(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncEntryLog2(char* s, const SSyncRaftEntry* pObj) {
|
void syncEntryLog2(char* s, const SSyncRaftEntry* pObj) {
|
||||||
char* serialized = syncEntry2Str(pObj);
|
char* serialized = syncEntry2Str(pObj);
|
||||||
sTrace("syncEntryLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("syncEntryLog2 | len:%zu | %s | %s", strlen(serialized), s, serialized);
|
||||||
free(serialized);
|
free(serialized);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode) {
|
||||||
pLogStore->getLastTerm = logStoreLastTerm;
|
pLogStore->getLastTerm = logStoreLastTerm;
|
||||||
pLogStore->updateCommitIndex = logStoreUpdateCommitIndex;
|
pLogStore->updateCommitIndex = logStoreUpdateCommitIndex;
|
||||||
pLogStore->getCommitIndex = logStoreGetCommitIndex;
|
pLogStore->getCommitIndex = logStoreGetCommitIndex;
|
||||||
|
return pLogStore; // to avoid compiler error
|
||||||
}
|
}
|
||||||
|
|
||||||
void logStoreDestory(SSyncLogStore* pLogStore) {
|
void logStoreDestory(SSyncLogStore* pLogStore) {
|
||||||
|
@ -58,20 +59,24 @@ int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) {
|
||||||
|
|
||||||
walFsync(pWal, true);
|
walFsync(pWal, true);
|
||||||
free(serialized);
|
free(serialized);
|
||||||
|
return code; // to avoid compiler error
|
||||||
}
|
}
|
||||||
|
|
||||||
SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) {
|
SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) {
|
||||||
SSyncLogStoreData* pData = pLogStore->data;
|
SSyncLogStoreData* pData = pLogStore->data;
|
||||||
SWal* pWal = pData->pWal;
|
SWal* pWal = pData->pWal;
|
||||||
SSyncRaftEntry* pEntry;
|
SSyncRaftEntry* pEntry = NULL;
|
||||||
|
|
||||||
SWalReadHandle* pWalHandle = walOpenReadHandle(pWal);
|
if (index >= SYNC_INDEX_BEGIN && index <= logStoreLastIndex(pLogStore)) {
|
||||||
walReadWithHandle(pWalHandle, index);
|
SWalReadHandle* pWalHandle = walOpenReadHandle(pWal);
|
||||||
pEntry = syncEntryDeserialize(pWalHandle->pHead->head.body, pWalHandle->pHead->head.len);
|
walReadWithHandle(pWalHandle, index);
|
||||||
assert(pEntry != NULL);
|
pEntry = syncEntryDeserialize(pWalHandle->pHead->head.body, pWalHandle->pHead->head.len);
|
||||||
|
assert(pEntry != NULL);
|
||||||
|
|
||||||
|
// need to hold, do not new every time!!
|
||||||
|
walCloseReadHandle(pWalHandle);
|
||||||
|
}
|
||||||
|
|
||||||
// need to hold, do not new every time!!
|
|
||||||
walCloseReadHandle(pWalHandle);
|
|
||||||
return pEntry;
|
return pEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +84,7 @@ int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex) {
|
||||||
SSyncLogStoreData* pData = pLogStore->data;
|
SSyncLogStoreData* pData = pLogStore->data;
|
||||||
SWal* pWal = pData->pWal;
|
SWal* pWal = pData->pWal;
|
||||||
walRollback(pWal, fromIndex);
|
walRollback(pWal, fromIndex);
|
||||||
|
return 0; // to avoid compiler error
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncIndex logStoreLastIndex(SSyncLogStore* pLogStore) {
|
SyncIndex logStoreLastIndex(SSyncLogStore* pLogStore) {
|
||||||
|
@ -102,6 +108,7 @@ int32_t logStoreUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index) {
|
||||||
SSyncLogStoreData* pData = pLogStore->data;
|
SSyncLogStoreData* pData = pLogStore->data;
|
||||||
SWal* pWal = pData->pWal;
|
SWal* pWal = pData->pWal;
|
||||||
walCommit(pWal, index);
|
walCommit(pWal, index);
|
||||||
|
return 0; // to avoid compiler error
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncIndex logStoreGetCommitIndex(SSyncLogStore* pLogStore) {
|
SyncIndex logStoreGetCommitIndex(SSyncLogStore* pLogStore) {
|
||||||
|
@ -122,26 +129,28 @@ SSyncRaftEntry* logStoreGetLastEntry(SSyncLogStore* pLogStore) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* logStore2Json(SSyncLogStore* pLogStore) {
|
cJSON* logStore2Json(SSyncLogStore* pLogStore) {
|
||||||
char u64buf[128];
|
char u64buf[128];
|
||||||
|
|
||||||
SSyncLogStoreData* pData = (SSyncLogStoreData*)pLogStore->data;
|
SSyncLogStoreData* pData = (SSyncLogStoreData*)pLogStore->data;
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pData->pSyncNode);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pData->pWal);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pWal", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%ld", logStoreLastIndex(pLogStore));
|
|
||||||
cJSON_AddStringToObject(pRoot, "LastIndex", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", logStoreLastTerm(pLogStore));
|
|
||||||
cJSON_AddStringToObject(pRoot, "LastTerm", u64buf);
|
|
||||||
|
|
||||||
cJSON* pEntries = cJSON_CreateArray();
|
if (pData != NULL && pData->pWal != NULL) {
|
||||||
cJSON_AddItemToObject(pRoot, "pEntries", pEntries);
|
snprintf(u64buf, sizeof(u64buf), "%p", pData->pSyncNode);
|
||||||
SyncIndex lastIndex = logStoreLastIndex(pLogStore);
|
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
||||||
for (SyncIndex i = 0; i <= lastIndex; ++i) {
|
snprintf(u64buf, sizeof(u64buf), "%p", pData->pWal);
|
||||||
SSyncRaftEntry* pEntry = logStoreGetEntry(pLogStore, i);
|
cJSON_AddStringToObject(pRoot, "pWal", u64buf);
|
||||||
cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry));
|
snprintf(u64buf, sizeof(u64buf), "%ld", logStoreLastIndex(pLogStore));
|
||||||
syncEntryDestory(pEntry);
|
cJSON_AddStringToObject(pRoot, "LastIndex", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%lu", logStoreLastTerm(pLogStore));
|
||||||
|
cJSON_AddStringToObject(pRoot, "LastTerm", u64buf);
|
||||||
|
|
||||||
|
cJSON* pEntries = cJSON_CreateArray();
|
||||||
|
cJSON_AddItemToObject(pRoot, "pEntries", pEntries);
|
||||||
|
SyncIndex lastIndex = logStoreLastIndex(pLogStore);
|
||||||
|
for (SyncIndex i = 0; i <= lastIndex; ++i) {
|
||||||
|
SSyncRaftEntry* pEntry = logStoreGetEntry(pLogStore, i);
|
||||||
|
cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry));
|
||||||
|
syncEntryDestory(pEntry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
|
@ -181,4 +190,4 @@ void logStoreLog2(char* s, SSyncLogStore* pLogStore) {
|
||||||
char* serialized = logStore2Str(pLogStore);
|
char* serialized = logStore2Str(pLogStore);
|
||||||
sTrace("logStorePrint | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("logStorePrint | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
||||||
free(serialized);
|
free(serialized);
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,16 +97,32 @@ int32_t raftStorePersist(SRaftStore *pRaftStore) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool raftStoreFileExist(char *path) { return taosStatFile(path, NULL, NULL) >= 0; }
|
static bool raftStoreFileExist(char *path) {
|
||||||
|
bool b = taosStatFile(path, NULL, NULL) >= 0;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t raftStoreSerialize(SRaftStore *pRaftStore, char *buf, size_t len) {
|
int32_t raftStoreSerialize(SRaftStore *pRaftStore, char *buf, size_t len) {
|
||||||
assert(pRaftStore != NULL);
|
assert(pRaftStore != NULL);
|
||||||
|
|
||||||
cJSON *pRoot = cJSON_CreateObject();
|
cJSON *pRoot = cJSON_CreateObject();
|
||||||
cJSON_AddNumberToObject(pRoot, "current_term", pRaftStore->currentTerm);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "vote_for_addr", pRaftStore->voteFor.addr);
|
char u64Buf[128];
|
||||||
|
snprintf(u64Buf, sizeof(u64Buf), "%lu", pRaftStore->currentTerm);
|
||||||
|
cJSON_AddStringToObject(pRoot, "current_term", u64Buf);
|
||||||
|
|
||||||
|
snprintf(u64Buf, sizeof(u64Buf), "%lu", pRaftStore->voteFor.addr);
|
||||||
|
cJSON_AddStringToObject(pRoot, "vote_for_addr", u64Buf);
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "vote_for_vgid", pRaftStore->voteFor.vgId);
|
cJSON_AddNumberToObject(pRoot, "vote_for_vgid", pRaftStore->voteFor.vgId);
|
||||||
|
|
||||||
|
uint64_t u64 = pRaftStore->voteFor.addr;
|
||||||
|
char host[128];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||||
|
cJSON_AddStringToObject(pRoot, "addr_host", host);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "addr_port", port);
|
||||||
|
|
||||||
char *serialized = cJSON_Print(pRoot);
|
char *serialized = cJSON_Print(pRoot);
|
||||||
int len2 = strlen(serialized);
|
int len2 = strlen(serialized);
|
||||||
assert(len2 < len);
|
assert(len2 < len);
|
||||||
|
@ -125,10 +141,12 @@ int32_t raftStoreDeserialize(SRaftStore *pRaftStore, char *buf, size_t len) {
|
||||||
cJSON *pRoot = cJSON_Parse(buf);
|
cJSON *pRoot = cJSON_Parse(buf);
|
||||||
|
|
||||||
cJSON *pCurrentTerm = cJSON_GetObjectItem(pRoot, "current_term");
|
cJSON *pCurrentTerm = cJSON_GetObjectItem(pRoot, "current_term");
|
||||||
pRaftStore->currentTerm = pCurrentTerm->valueint;
|
assert(cJSON_IsString(pCurrentTerm));
|
||||||
|
sscanf(pCurrentTerm->valuestring, "%lu", &(pRaftStore->currentTerm));
|
||||||
|
|
||||||
cJSON *pVoteForAddr = cJSON_GetObjectItem(pRoot, "vote_for_addr");
|
cJSON *pVoteForAddr = cJSON_GetObjectItem(pRoot, "vote_for_addr");
|
||||||
pRaftStore->voteFor.addr = pVoteForAddr->valueint;
|
assert(cJSON_IsString(pVoteForAddr));
|
||||||
|
sscanf(pVoteForAddr->valuestring, "%lu", &(pRaftStore->voteFor.addr));
|
||||||
|
|
||||||
cJSON *pVoteForVgid = cJSON_GetObjectItem(pRoot, "vote_for_vgid");
|
cJSON *pVoteForVgid = cJSON_GetObjectItem(pRoot, "vote_for_vgid");
|
||||||
pRaftStore->voteFor.vgId = pVoteForVgid->valueint;
|
pRaftStore->voteFor.vgId = pVoteForVgid->valueint;
|
||||||
|
@ -139,11 +157,10 @@ int32_t raftStoreDeserialize(SRaftStore *pRaftStore, char *buf, size_t len) {
|
||||||
|
|
||||||
bool raftStoreHasVoted(SRaftStore *pRaftStore) {
|
bool raftStoreHasVoted(SRaftStore *pRaftStore) {
|
||||||
bool b = syncUtilEmptyId(&(pRaftStore->voteFor));
|
bool b = syncUtilEmptyId(&(pRaftStore->voteFor));
|
||||||
return b;
|
return (!b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void raftStoreVote(SRaftStore *pRaftStore, SRaftId *pRaftId) {
|
void raftStoreVote(SRaftStore *pRaftStore, SRaftId *pRaftId) {
|
||||||
assert(!raftStoreHasVoted(pRaftStore));
|
|
||||||
assert(!syncUtilEmptyId(pRaftId));
|
assert(!syncUtilEmptyId(pRaftId));
|
||||||
pRaftStore->voteFor = *pRaftId;
|
pRaftStore->voteFor = *pRaftId;
|
||||||
raftStorePersist(pRaftStore);
|
raftStorePersist(pRaftStore);
|
||||||
|
@ -164,30 +181,68 @@ void raftStoreSetTerm(SRaftStore *pRaftStore, SyncTerm term) {
|
||||||
raftStorePersist(pRaftStore);
|
raftStorePersist(pRaftStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t raftStoreFromJson(SRaftStore *pRaftStore, cJSON *pJson) { return 0; }
|
||||||
|
|
||||||
|
cJSON *raftStore2Json(SRaftStore *pRaftStore) {
|
||||||
|
char u64buf[128];
|
||||||
|
cJSON *pRoot = cJSON_CreateObject();
|
||||||
|
|
||||||
|
if (pRaftStore != NULL) {
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%lu", pRaftStore->currentTerm);
|
||||||
|
cJSON_AddStringToObject(pRoot, "currentTerm", u64buf);
|
||||||
|
|
||||||
|
cJSON *pVoteFor = cJSON_CreateObject();
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%lu", pRaftStore->voteFor.addr);
|
||||||
|
cJSON_AddStringToObject(pVoteFor, "addr", u64buf);
|
||||||
|
{
|
||||||
|
uint64_t u64 = pRaftStore->voteFor.addr;
|
||||||
|
char host[128];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||||
|
cJSON_AddStringToObject(pVoteFor, "addr_host", host);
|
||||||
|
cJSON_AddNumberToObject(pVoteFor, "addr_port", port);
|
||||||
|
}
|
||||||
|
cJSON_AddNumberToObject(pVoteFor, "vgId", pRaftStore->voteFor.vgId);
|
||||||
|
cJSON_AddItemToObject(pRoot, "voteFor", pVoteFor);
|
||||||
|
|
||||||
|
int hasVoted = raftStoreHasVoted(pRaftStore);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "hasVoted", hasVoted);
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON *pJson = cJSON_CreateObject();
|
||||||
|
cJSON_AddItemToObject(pJson, "SRaftStore", pRoot);
|
||||||
|
return pJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *raftStore2Str(SRaftStore *pRaftStore) {
|
||||||
|
cJSON *pJson = raftStore2Json(pRaftStore);
|
||||||
|
char * serialized = cJSON_Print(pJson);
|
||||||
|
cJSON_Delete(pJson);
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
// for debug -------------------
|
// for debug -------------------
|
||||||
void raftStorePrint(SRaftStore *pObj) {
|
void raftStorePrint(SRaftStore *pObj) {
|
||||||
char serialized[RAFT_STORE_BLOCK_SIZE];
|
char *serialized = raftStore2Str(pObj);
|
||||||
raftStoreSerialize(pObj, serialized, sizeof(serialized));
|
|
||||||
printf("raftStorePrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("raftStorePrint | len:%lu | %s \n", strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
|
free(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void raftStorePrint2(char *s, SRaftStore *pObj) {
|
void raftStorePrint2(char *s, SRaftStore *pObj) {
|
||||||
char serialized[RAFT_STORE_BLOCK_SIZE];
|
char *serialized = raftStore2Str(pObj);
|
||||||
raftStoreSerialize(pObj, serialized, sizeof(serialized));
|
|
||||||
printf("raftStorePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("raftStorePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
|
free(serialized);
|
||||||
}
|
}
|
||||||
void raftStoreLog(SRaftStore *pObj) {
|
void raftStoreLog(SRaftStore *pObj) {
|
||||||
char serialized[RAFT_STORE_BLOCK_SIZE];
|
char *serialized = raftStore2Str(pObj);
|
||||||
raftStoreSerialize(pObj, serialized, sizeof(serialized));
|
|
||||||
sTrace("raftStoreLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("raftStoreLog | len:%lu | %s", strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
free(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void raftStoreLog2(char *s, SRaftStore *pObj) {
|
void raftStoreLog2(char *s, SRaftStore *pObj) {
|
||||||
char serialized[RAFT_STORE_BLOCK_SIZE];
|
char *serialized = raftStore2Str(pObj);
|
||||||
raftStoreSerialize(pObj, serialized, sizeof(serialized));
|
|
||||||
sTrace("raftStoreLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("raftStoreLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
free(serialized);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "syncMessage.h"
|
#include "syncMessage.h"
|
||||||
#include "syncRaftEntry.h"
|
#include "syncRaftEntry.h"
|
||||||
#include "syncRaftLog.h"
|
#include "syncRaftLog.h"
|
||||||
|
#include "syncRaftStore.h"
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
|
|
||||||
// TLA+ Spec
|
// TLA+ Spec
|
||||||
|
@ -50,33 +51,54 @@ int32_t syncNodeAppendEntriesPeers(SSyncNode* pSyncNode) {
|
||||||
|
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
for (int i = 0; i < pSyncNode->peersNum; ++i) {
|
for (int i = 0; i < pSyncNode->peersNum; ++i) {
|
||||||
SRaftId* pDestId = &(pSyncNode->peersId[i]);
|
SRaftId* pDestId = &(pSyncNode->peersId[i]);
|
||||||
SyncIndex nextIndex = syncIndexMgrGetIndex(pSyncNode->pNextIndex, pDestId);
|
|
||||||
|
|
||||||
|
// set prevLogIndex
|
||||||
|
SyncIndex nextIndex = syncIndexMgrGetIndex(pSyncNode->pNextIndex, pDestId);
|
||||||
SyncIndex preLogIndex = nextIndex - 1;
|
SyncIndex preLogIndex = nextIndex - 1;
|
||||||
|
|
||||||
|
// set preLogTerm
|
||||||
SyncTerm preLogTerm = 0;
|
SyncTerm preLogTerm = 0;
|
||||||
if (preLogIndex >= SYNC_INDEX_BEGIN) {
|
if (preLogIndex >= SYNC_INDEX_BEGIN) {
|
||||||
SSyncRaftEntry* pPreEntry = pSyncNode->pLogStore->getEntry(pSyncNode->pLogStore, preLogIndex);
|
SSyncRaftEntry* pPreEntry = pSyncNode->pLogStore->getEntry(pSyncNode->pLogStore, preLogIndex);
|
||||||
|
assert(pPreEntry != NULL);
|
||||||
|
|
||||||
preLogTerm = pPreEntry->term;
|
preLogTerm = pPreEntry->term;
|
||||||
|
syncEntryDestory(pPreEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncIndex lastIndex = syncUtilMinIndex(pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore), nextIndex);
|
// batch optimized
|
||||||
assert(nextIndex == lastIndex);
|
// SyncIndex lastIndex = syncUtilMinIndex(pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore), nextIndex);
|
||||||
|
|
||||||
SSyncRaftEntry* pEntry = logStoreGetEntry(pSyncNode->pLogStore, nextIndex);
|
SyncAppendEntries* pMsg = NULL;
|
||||||
assert(pEntry != NULL);
|
SSyncRaftEntry* pEntry = logStoreGetEntry(pSyncNode->pLogStore, nextIndex);
|
||||||
|
if (pEntry != NULL) {
|
||||||
|
SyncAppendEntries* pMsg = syncAppendEntriesBuild(pEntry->bytes);
|
||||||
|
|
||||||
|
// add pEntry into msg
|
||||||
|
uint32_t len;
|
||||||
|
char* serialized = syncEntrySerialize(pEntry, &len);
|
||||||
|
assert(len == pEntry->bytes);
|
||||||
|
memcpy(pMsg->data, serialized, len);
|
||||||
|
|
||||||
|
free(serialized);
|
||||||
|
syncEntryDestory(pEntry);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// maybe overflow, send empty record
|
||||||
|
SyncAppendEntries* pMsg = syncAppendEntriesBuild(0);
|
||||||
|
}
|
||||||
|
|
||||||
SyncAppendEntries* pMsg = syncAppendEntriesBuild(pEntry->bytes);
|
|
||||||
pMsg->srcId = pSyncNode->myRaftId;
|
pMsg->srcId = pSyncNode->myRaftId;
|
||||||
pMsg->destId = *pDestId;
|
pMsg->destId = *pDestId;
|
||||||
|
pMsg->term = pSyncNode->pRaftStore->currentTerm;
|
||||||
pMsg->prevLogIndex = preLogIndex;
|
pMsg->prevLogIndex = preLogIndex;
|
||||||
pMsg->prevLogTerm = preLogTerm;
|
pMsg->prevLogTerm = preLogTerm;
|
||||||
pMsg->commitIndex = pSyncNode->commitIndex;
|
pMsg->commitIndex = pSyncNode->commitIndex;
|
||||||
pMsg->dataLen = pEntry->bytes;
|
|
||||||
// add pEntry into msg
|
|
||||||
|
|
||||||
|
// send AppendEntries
|
||||||
syncNodeAppendEntries(pSyncNode, pDestId, pMsg);
|
syncNodeAppendEntries(pSyncNode, pDestId, pMsg);
|
||||||
|
syncAppendEntriesDestroy(pMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -56,6 +56,8 @@ int32_t syncNodeOnRequestVoteCb(SSyncNode* ths, SyncRequestVote* pMsg) {
|
||||||
bool grant = (pMsg->term == ths->pRaftStore->currentTerm) && logOK &&
|
bool grant = (pMsg->term == ths->pRaftStore->currentTerm) && logOK &&
|
||||||
((!raftStoreHasVoted(ths->pRaftStore)) || (syncUtilSameId(&(ths->pRaftStore->voteFor), &(pMsg->srcId))));
|
((!raftStoreHasVoted(ths->pRaftStore)) || (syncUtilSameId(&(ths->pRaftStore->voteFor), &(pMsg->srcId))));
|
||||||
if (grant) {
|
if (grant) {
|
||||||
|
// maybe has already voted for pMsg->srcId
|
||||||
|
// vote again, no harm
|
||||||
raftStoreVote(ths->pRaftStore, &(pMsg->srcId));
|
raftStoreVote(ths->pRaftStore, &(pMsg->srcId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,10 +41,11 @@ int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg)
|
||||||
syncRequestVoteReplyLog2("==syncNodeOnRequestVoteReplyCb==", pMsg);
|
syncRequestVoteReplyLog2("==syncNodeOnRequestVoteReplyCb==", pMsg);
|
||||||
|
|
||||||
if (pMsg->term < ths->pRaftStore->currentTerm) {
|
if (pMsg->term < ths->pRaftStore->currentTerm) {
|
||||||
sTrace("DropStaleResponse, receive term:%lu, current term:%lu", pMsg->term, ths->pRaftStore->currentTerm);
|
sTrace("DropStaleResponse, receive term:%" PRIu64 ", current term:%" PRIu64 "", pMsg->term, ths->pRaftStore->currentTerm);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(!(pMsg->term > ths->pRaftStore->currentTerm));
|
||||||
// no need this code, because if I receive reply.term, then I must have sent for that term.
|
// no need this code, because if I receive reply.term, then I must have sent for that term.
|
||||||
// if (pMsg->term > ths->pRaftStore->currentTerm) {
|
// if (pMsg->term > ths->pRaftStore->currentTerm) {
|
||||||
// syncNodeUpdateTerm(ths, pMsg->term);
|
// syncNodeUpdateTerm(ths, pMsg->term);
|
||||||
|
@ -52,17 +53,29 @@ int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg)
|
||||||
|
|
||||||
assert(pMsg->term == ths->pRaftStore->currentTerm);
|
assert(pMsg->term == ths->pRaftStore->currentTerm);
|
||||||
|
|
||||||
|
// This tallies votes even when the current state is not Candidate,
|
||||||
|
// but they won't be looked at, so it doesn't matter.
|
||||||
if (ths->state == TAOS_SYNC_STATE_CANDIDATE) {
|
if (ths->state == TAOS_SYNC_STATE_CANDIDATE) {
|
||||||
votesRespondAdd(ths->pVotesRespond, pMsg);
|
votesRespondAdd(ths->pVotesRespond, pMsg);
|
||||||
if (pMsg->voteGranted) {
|
if (pMsg->voteGranted) {
|
||||||
|
// add vote
|
||||||
voteGrantedVote(ths->pVotesGranted, pMsg);
|
voteGrantedVote(ths->pVotesGranted, pMsg);
|
||||||
|
|
||||||
|
// maybe to leader
|
||||||
if (voteGrantedMajority(ths->pVotesGranted)) {
|
if (voteGrantedMajority(ths->pVotesGranted)) {
|
||||||
if (ths->pVotesGranted->toLeader) {
|
if (!ths->pVotesGranted->toLeader) {
|
||||||
syncNodeCandidate2Leader(ths);
|
syncNodeCandidate2Leader(ths);
|
||||||
|
|
||||||
|
// prevent to leader again!
|
||||||
ths->pVotesGranted->toLeader = true;
|
ths->pVotesGranted->toLeader = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
;
|
||||||
|
// do nothing
|
||||||
|
// UNCHANGED <<votesGranted, voterLog>>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,8 @@ int32_t syncNodeOnTimeoutCb(SSyncNode* ths, SyncTimeout* pMsg) {
|
||||||
if (pMsg->timeoutType == SYNC_TIMEOUT_PING) {
|
if (pMsg->timeoutType == SYNC_TIMEOUT_PING) {
|
||||||
if (atomic_load_64(&ths->pingTimerLogicClockUser) <= pMsg->logicClock) {
|
if (atomic_load_64(&ths->pingTimerLogicClockUser) <= pMsg->logicClock) {
|
||||||
++(ths->pingTimerCounter);
|
++(ths->pingTimerCounter);
|
||||||
syncNodePingAll(ths);
|
// syncNodePingAll(ths);
|
||||||
|
syncNodePingPeers(ths);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (pMsg->timeoutType == SYNC_TIMEOUT_ELECTION) {
|
} else if (pMsg->timeoutType == SYNC_TIMEOUT_ELECTION) {
|
||||||
|
|
|
@ -119,7 +119,7 @@ cJSON* syncUtilRaftId2Json(const SRaftId* p) {
|
||||||
char u64buf[128];
|
char u64buf[128];
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", p->addr);
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64 "", p->addr);
|
||||||
cJSON_AddStringToObject(pRoot, "addr", u64buf);
|
cJSON_AddStringToObject(pRoot, "addr", u64buf);
|
||||||
char host[128];
|
char host[128];
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
|
@ -196,4 +196,4 @@ SyncIndex syncUtilMinIndex(SyncIndex a, SyncIndex b) {
|
||||||
SyncIndex syncUtilMaxIndex(SyncIndex a, SyncIndex b) {
|
SyncIndex syncUtilMaxIndex(SyncIndex a, SyncIndex b) {
|
||||||
SyncIndex r = a > b ? a : b;
|
SyncIndex r = a > b ? a : b;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,30 +82,32 @@ cJSON *voteGranted2Json(SVotesGranted *pVotesGranted) {
|
||||||
char u64buf[128];
|
char u64buf[128];
|
||||||
cJSON *pRoot = cJSON_CreateObject();
|
cJSON *pRoot = cJSON_CreateObject();
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "replicaNum", pVotesGranted->replicaNum);
|
if (pVotesGranted != NULL) {
|
||||||
cJSON *pReplicas = cJSON_CreateArray();
|
cJSON_AddNumberToObject(pRoot, "replicaNum", pVotesGranted->replicaNum);
|
||||||
cJSON_AddItemToObject(pRoot, "replicas", pReplicas);
|
cJSON *pReplicas = cJSON_CreateArray();
|
||||||
for (int i = 0; i < pVotesGranted->replicaNum; ++i) {
|
cJSON_AddItemToObject(pRoot, "replicas", pReplicas);
|
||||||
cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pVotesGranted->replicas))[i]));
|
for (int i = 0; i < pVotesGranted->replicaNum; ++i) {
|
||||||
}
|
cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pVotesGranted->replicas))[i]));
|
||||||
int *arr = (int *)malloc(sizeof(int) * pVotesGranted->replicaNum);
|
}
|
||||||
for (int i = 0; i < pVotesGranted->replicaNum; ++i) {
|
int *arr = (int *)malloc(sizeof(int) * pVotesGranted->replicaNum);
|
||||||
arr[i] = pVotesGranted->isGranted[i];
|
for (int i = 0; i < pVotesGranted->replicaNum; ++i) {
|
||||||
}
|
arr[i] = pVotesGranted->isGranted[i];
|
||||||
cJSON *pIsGranted = cJSON_CreateIntArray(arr, pVotesGranted->replicaNum);
|
}
|
||||||
free(arr);
|
cJSON *pIsGranted = cJSON_CreateIntArray(arr, pVotesGranted->replicaNum);
|
||||||
cJSON_AddItemToObject(pRoot, "isGranted", pIsGranted);
|
free(arr);
|
||||||
|
cJSON_AddItemToObject(pRoot, "isGranted", pIsGranted);
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "votes", pVotesGranted->votes);
|
cJSON_AddNumberToObject(pRoot, "votes", pVotesGranted->votes);
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pVotesGranted->term);
|
snprintf(u64buf, sizeof(u64buf), "%lu", pVotesGranted->term);
|
||||||
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
||||||
cJSON_AddNumberToObject(pRoot, "quorum", pVotesGranted->quorum);
|
cJSON_AddNumberToObject(pRoot, "quorum", pVotesGranted->quorum);
|
||||||
cJSON_AddNumberToObject(pRoot, "toLeader", pVotesGranted->toLeader);
|
cJSON_AddNumberToObject(pRoot, "toLeader", pVotesGranted->toLeader);
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pVotesGranted->pSyncNode);
|
snprintf(u64buf, sizeof(u64buf), "%p", pVotesGranted->pSyncNode);
|
||||||
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
||||||
|
|
||||||
bool majority = voteGrantedMajority(pVotesGranted);
|
bool majority = voteGrantedMajority(pVotesGranted);
|
||||||
cJSON_AddNumberToObject(pRoot, "majority", majority);
|
cJSON_AddNumberToObject(pRoot, "majority", majority);
|
||||||
|
}
|
||||||
|
|
||||||
cJSON *pJson = cJSON_CreateObject();
|
cJSON *pJson = cJSON_CreateObject();
|
||||||
cJSON_AddItemToObject(pJson, "SVotesGranted", pRoot);
|
cJSON_AddItemToObject(pJson, "SVotesGranted", pRoot);
|
||||||
|
@ -203,29 +205,31 @@ cJSON *votesRespond2Json(SVotesRespond *pVotesRespond) {
|
||||||
char u64buf[128];
|
char u64buf[128];
|
||||||
cJSON *pRoot = cJSON_CreateObject();
|
cJSON *pRoot = cJSON_CreateObject();
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "replicaNum", pVotesRespond->replicaNum);
|
if (pVotesRespond != NULL) {
|
||||||
cJSON *pReplicas = cJSON_CreateArray();
|
cJSON_AddNumberToObject(pRoot, "replicaNum", pVotesRespond->replicaNum);
|
||||||
cJSON_AddItemToObject(pRoot, "replicas", pReplicas);
|
cJSON *pReplicas = cJSON_CreateArray();
|
||||||
for (int i = 0; i < pVotesRespond->replicaNum; ++i) {
|
cJSON_AddItemToObject(pRoot, "replicas", pReplicas);
|
||||||
cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pVotesRespond->replicas))[i]));
|
for (int i = 0; i < pVotesRespond->replicaNum; ++i) {
|
||||||
}
|
cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pVotesRespond->replicas))[i]));
|
||||||
int respondNum = 0;
|
|
||||||
int *arr = (int *)malloc(sizeof(int) * pVotesRespond->replicaNum);
|
|
||||||
for (int i = 0; i < pVotesRespond->replicaNum; ++i) {
|
|
||||||
arr[i] = pVotesRespond->isRespond[i];
|
|
||||||
if (pVotesRespond->isRespond[i]) {
|
|
||||||
respondNum++;
|
|
||||||
}
|
}
|
||||||
}
|
int respondNum = 0;
|
||||||
cJSON *pIsRespond = cJSON_CreateIntArray(arr, pVotesRespond->replicaNum);
|
int *arr = (int *)malloc(sizeof(int) * pVotesRespond->replicaNum);
|
||||||
free(arr);
|
for (int i = 0; i < pVotesRespond->replicaNum; ++i) {
|
||||||
cJSON_AddItemToObject(pRoot, "isRespond", pIsRespond);
|
arr[i] = pVotesRespond->isRespond[i];
|
||||||
cJSON_AddNumberToObject(pRoot, "respondNum", respondNum);
|
if (pVotesRespond->isRespond[i]) {
|
||||||
|
respondNum++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cJSON *pIsRespond = cJSON_CreateIntArray(arr, pVotesRespond->replicaNum);
|
||||||
|
free(arr);
|
||||||
|
cJSON_AddItemToObject(pRoot, "isRespond", pIsRespond);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "respondNum", respondNum);
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%lu", pVotesRespond->term);
|
snprintf(u64buf, sizeof(u64buf), "%lu", pVotesRespond->term);
|
||||||
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pVotesRespond->pSyncNode);
|
snprintf(u64buf, sizeof(u64buf), "%p", pVotesRespond->pSyncNode);
|
||||||
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
||||||
|
}
|
||||||
|
|
||||||
cJSON *pJson = cJSON_CreateObject();
|
cJSON *pJson = cJSON_CreateObject();
|
||||||
cJSON_AddItemToObject(pJson, "SVotesRespond", pRoot);
|
cJSON_AddItemToObject(pJson, "SVotesRespond", pRoot);
|
||||||
|
@ -264,4 +268,4 @@ void votesRespondLog2(char *s, SVotesRespond *pObj) {
|
||||||
char *serialized = votesRespond2Str(pObj);
|
char *serialized = votesRespond2Str(pObj);
|
||||||
sTrace("votesRespondLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("votesRespondLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
||||||
free(serialized);
|
free(serialized);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,9 @@ add_executable(syncTimeoutTest "")
|
||||||
add_executable(syncPingTest "")
|
add_executable(syncPingTest "")
|
||||||
add_executable(syncPingReplyTest "")
|
add_executable(syncPingReplyTest "")
|
||||||
add_executable(syncRpcMsgTest "")
|
add_executable(syncRpcMsgTest "")
|
||||||
|
add_executable(syncPingTimerTest2 "")
|
||||||
|
add_executable(syncPingSelfTest "")
|
||||||
|
add_executable(syncElectTest "")
|
||||||
|
|
||||||
|
|
||||||
target_sources(syncTest
|
target_sources(syncTest
|
||||||
|
@ -135,6 +138,18 @@ target_sources(syncRpcMsgTest
|
||||||
PRIVATE
|
PRIVATE
|
||||||
"syncRpcMsgTest.cpp"
|
"syncRpcMsgTest.cpp"
|
||||||
)
|
)
|
||||||
|
target_sources(syncPingTimerTest2
|
||||||
|
PRIVATE
|
||||||
|
"syncPingTimerTest2.cpp"
|
||||||
|
)
|
||||||
|
target_sources(syncPingSelfTest
|
||||||
|
PRIVATE
|
||||||
|
"syncPingSelfTest.cpp"
|
||||||
|
)
|
||||||
|
target_sources(syncElectTest
|
||||||
|
PRIVATE
|
||||||
|
"syncElectTest.cpp"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
target_include_directories(syncTest
|
target_include_directories(syncTest
|
||||||
|
@ -272,6 +287,26 @@ target_include_directories(syncRpcMsgTest
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
|
target_include_directories(syncPingTimerTest2
|
||||||
|
PUBLIC
|
||||||
|
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
|
)
|
||||||
|
target_include_directories(syncPingSelfTest
|
||||||
|
PUBLIC
|
||||||
|
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
|
)
|
||||||
|
target_include_directories(syncElectTest
|
||||||
|
PUBLIC
|
||||||
|
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
|
)
|
||||||
|
target_include_directories(syncElectTest
|
||||||
|
PUBLIC
|
||||||
|
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
target_link_libraries(syncTest
|
target_link_libraries(syncTest
|
||||||
|
@ -382,6 +417,18 @@ target_link_libraries(syncRpcMsgTest
|
||||||
sync
|
sync
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
|
target_link_libraries(syncPingTimerTest2
|
||||||
|
sync
|
||||||
|
gtest_main
|
||||||
|
)
|
||||||
|
target_link_libraries(syncPingSelfTest
|
||||||
|
sync
|
||||||
|
gtest_main
|
||||||
|
)
|
||||||
|
target_link_libraries(syncElectTest
|
||||||
|
sync
|
||||||
|
gtest_main
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
|
@ -0,0 +1,124 @@
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "syncEnv.h"
|
||||||
|
#include "syncIO.h"
|
||||||
|
#include "syncInt.h"
|
||||||
|
#include "syncRaftLog.h"
|
||||||
|
#include "syncRaftStore.h"
|
||||||
|
#include "syncUtil.h"
|
||||||
|
|
||||||
|
void logTest() {
|
||||||
|
sTrace("--- sync log test: trace");
|
||||||
|
sDebug("--- sync log test: debug");
|
||||||
|
sInfo("--- sync log test: info");
|
||||||
|
sWarn("--- sync log test: warn");
|
||||||
|
sError("--- sync log test: error");
|
||||||
|
sFatal("--- sync log test: fatal");
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t ports[] = {7010, 7110, 7210, 7310, 7410};
|
||||||
|
int32_t replicaNum = 3;
|
||||||
|
int32_t myIndex = 0;
|
||||||
|
|
||||||
|
SRaftId ids[TSDB_MAX_REPLICA];
|
||||||
|
SSyncInfo syncInfo;
|
||||||
|
SSyncFSM* pFsm;
|
||||||
|
SWal* pWal;
|
||||||
|
SSyncNode* gSyncNode;
|
||||||
|
|
||||||
|
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), "./elect_test_%d", myIndex);
|
||||||
|
|
||||||
|
int code = walInit();
|
||||||
|
assert(code == 0);
|
||||||
|
SWalCfg walCfg;
|
||||||
|
memset(&walCfg, 0, sizeof(SWalCfg));
|
||||||
|
walCfg.vgId = syncInfo.vgId;
|
||||||
|
walCfg.fsyncPeriod = 1000;
|
||||||
|
walCfg.retentionPeriod = 1000;
|
||||||
|
walCfg.rollPeriod = 1000;
|
||||||
|
walCfg.retentionSize = 1000;
|
||||||
|
walCfg.segSize = 1000;
|
||||||
|
walCfg.level = TAOS_WAL_FSYNC;
|
||||||
|
|
||||||
|
char tmpdir[128];
|
||||||
|
snprintf(tmpdir, sizeof(tmpdir), "./elect_test_wal_%d", myIndex);
|
||||||
|
pWal = walOpen(tmpdir, &walCfg);
|
||||||
|
assert(pWal != NULL);
|
||||||
|
|
||||||
|
syncInfo.pWal = pWal;
|
||||||
|
|
||||||
|
SSyncCfg* pCfg = &syncInfo.syncCfg;
|
||||||
|
pCfg->myIndex = myIndex;
|
||||||
|
pCfg->replicaNum = replicaNum;
|
||||||
|
|
||||||
|
for (int i = 0; i < replicaNum; ++i) {
|
||||||
|
pCfg->nodeInfo[i].nodePort = ports[i];
|
||||||
|
snprintf(pCfg->nodeInfo[i].nodeFqdn, sizeof(pCfg->nodeInfo[i].nodeFqdn), "%s", "127.0.0.1");
|
||||||
|
// taosGetFqdn(pCfg->nodeInfo[0].nodeFqdn);
|
||||||
|
}
|
||||||
|
|
||||||
|
SSyncNode* pSyncNode = syncNodeOpen(&syncInfo);
|
||||||
|
assert(pSyncNode != NULL);
|
||||||
|
|
||||||
|
gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
|
||||||
|
gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
|
||||||
|
gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote;
|
||||||
|
gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply;
|
||||||
|
gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries;
|
||||||
|
gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply;
|
||||||
|
gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
|
||||||
|
gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
|
||||||
|
gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout;
|
||||||
|
gSyncIO->pSyncNode = pSyncNode;
|
||||||
|
|
||||||
|
return pSyncNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSyncNode* syncInitTest() { return syncNodeInit(); }
|
||||||
|
|
||||||
|
void initRaftId(SSyncNode* pSyncNode) {
|
||||||
|
for (int i = 0; i < replicaNum; ++i) {
|
||||||
|
ids[i] = pSyncNode->replicasId[i];
|
||||||
|
char* s = syncUtilRaftId2Str(&ids[i]);
|
||||||
|
printf("raftId[%d] : %s\n", i, s);
|
||||||
|
free(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
// taosInitLog((char *)"syncTest.log", 100000, 10);
|
||||||
|
tsAsyncLog = 0;
|
||||||
|
sDebugFlag = 143 + 64;
|
||||||
|
|
||||||
|
myIndex = 0;
|
||||||
|
if (argc >= 2) {
|
||||||
|
myIndex = atoi(argv[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]);
|
||||||
|
assert(ret == 0);
|
||||||
|
|
||||||
|
ret = syncEnvStart();
|
||||||
|
assert(ret == 0);
|
||||||
|
|
||||||
|
gSyncNode = syncInitTest();
|
||||||
|
assert(gSyncNode != NULL);
|
||||||
|
syncNodePrint2((char*)"", gSyncNode);
|
||||||
|
|
||||||
|
initRaftId(gSyncNode);
|
||||||
|
|
||||||
|
//---------------------------
|
||||||
|
while (1) {
|
||||||
|
sTrace("while 1 sleep, state: %d, %s", gSyncNode->state, syncUtilState2String(gSyncNode->state));
|
||||||
|
taosMsleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -47,12 +47,11 @@ SSyncNode* syncNodeInit() {
|
||||||
|
|
||||||
gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
|
gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
|
||||||
gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
|
gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
|
||||||
|
gSyncIO->FpOnSyncClientRequest = pSyncNode->FpOnClientRequest;
|
||||||
gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote;
|
gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote;
|
||||||
gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply;
|
gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply;
|
||||||
gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries;
|
gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries;
|
||||||
gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply;
|
gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply;
|
||||||
gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
|
|
||||||
gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
|
|
||||||
gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout;
|
gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout;
|
||||||
gSyncIO->pSyncNode = pSyncNode;
|
gSyncIO->pSyncNode = pSyncNode;
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ SSyncNode* syncNodeInit() {
|
||||||
SSyncNode* syncInitTest() { return syncNodeInit(); }
|
SSyncNode* syncInitTest() { return syncNodeInit(); }
|
||||||
|
|
||||||
void logStoreTest() {
|
void logStoreTest() {
|
||||||
logStorePrint2((char*)"logStoreTest2", pSyncNode->pLogStore);
|
logStorePrint2((char*)"logStoreTest", pSyncNode->pLogStore);
|
||||||
|
|
||||||
assert(pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore) == SYNC_INDEX_INVALID);
|
assert(pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore) == SYNC_INDEX_INVALID);
|
||||||
|
|
||||||
|
@ -105,10 +105,10 @@ void logStoreTest() {
|
||||||
assert(pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore) == SYNC_INDEX_BEGIN);
|
assert(pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore) == SYNC_INDEX_BEGIN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logStorePrint(pSyncNode->pLogStore);
|
logStorePrint2((char*)"after appendEntry", pSyncNode->pLogStore);
|
||||||
|
|
||||||
pSyncNode->pLogStore->truncate(pSyncNode->pLogStore, 3);
|
pSyncNode->pLogStore->truncate(pSyncNode->pLogStore, 3);
|
||||||
logStorePrint(pSyncNode->pLogStore);
|
logStorePrint2((char*)"after truncate 3", pSyncNode->pLogStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
void initRaftId(SSyncNode* pSyncNode) {
|
void initRaftId(SSyncNode* pSyncNode) {
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue