Merge remote-tracking branch 'origin/3.0' into feature/scheduler
This commit is contained in:
commit
9b0f5df93a
|
@ -6,40 +6,14 @@ project(
|
|||
DESCRIPTION "An open-source big data platform designed and optimized for the Internet of Things(IOT)"
|
||||
)
|
||||
|
||||
IF ("${BUILD_TOOLS}" STREQUAL "")
|
||||
IF (TD_LINUX)
|
||||
IF (TD_ARM_32)
|
||||
SET(BUILD_TOOLS "false")
|
||||
ELSEIF (TD_ARM_64)
|
||||
SET(BUILD_TOOLS "false")
|
||||
ELSE ()
|
||||
SET(BUILD_TOOLS "false")
|
||||
ENDIF ()
|
||||
ELSEIF (TD_DARWIN)
|
||||
SET(BUILD_TOOLS "false")
|
||||
ELSE ()
|
||||
SET(BUILD_TOOLS "false")
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
|
||||
IF ("${BUILD_TOOLS}" MATCHES "false")
|
||||
MESSAGE("${Yellow} Will _not_ build taos_tools! ${ColourReset}")
|
||||
SET(TD_TAOS_TOOLS FALSE)
|
||||
ELSE ()
|
||||
MESSAGE("")
|
||||
MESSAGE("${Green} Will build taos_tools! ${ColourReset}")
|
||||
MESSAGE("")
|
||||
SET(TD_TAOS_TOOLS TRUE)
|
||||
ENDIF ()
|
||||
|
||||
set(CMAKE_SUPPORT_DIR "${CMAKE_SOURCE_DIR}/cmake")
|
||||
set(CMAKE_CONTRIB_DIR "${CMAKE_SOURCE_DIR}/contrib")
|
||||
|
||||
include(${CMAKE_SUPPORT_DIR}/cmake.platform)
|
||||
include(${CMAKE_SUPPORT_DIR}/cmake.define)
|
||||
include(${CMAKE_SUPPORT_DIR}/cmake.options)
|
||||
include(${CMAKE_SUPPORT_DIR}/cmake.version)
|
||||
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -fPIC -gdwarf-2 -msse4.2 -mfma -g3")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -fPIC -gdwarf-2 -msse4.2 -mfma -g3")
|
||||
|
||||
# contrib
|
||||
add_subdirectory(contrib)
|
||||
|
||||
|
@ -52,6 +26,7 @@ if(${BUILD_TEST})
|
|||
include(CTest)
|
||||
enable_testing()
|
||||
endif(${BUILD_TEST})
|
||||
|
||||
add_subdirectory(source)
|
||||
add_subdirectory(tools)
|
||||
add_subdirectory(tests)
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
IF ("${BUILD_TOOLS}" STREQUAL "")
|
||||
IF (TD_LINUX)
|
||||
IF (TD_ARM_32)
|
||||
SET(BUILD_TOOLS "false")
|
||||
ELSEIF (TD_ARM_64)
|
||||
SET(BUILD_TOOLS "false")
|
||||
ELSE ()
|
||||
SET(BUILD_TOOLS "false")
|
||||
ENDIF ()
|
||||
ELSEIF (TD_DARWIN)
|
||||
SET(BUILD_TOOLS "false")
|
||||
ELSE ()
|
||||
SET(BUILD_TOOLS "false")
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
|
||||
IF ("${BUILD_TOOLS}" MATCHES "false")
|
||||
MESSAGE("${Yellow} Will _not_ build taos_tools! ${ColourReset}")
|
||||
SET(TD_TAOS_TOOLS FALSE)
|
||||
ELSE ()
|
||||
MESSAGE("")
|
||||
MESSAGE("${Green} Will build taos_tools! ${ColourReset}")
|
||||
MESSAGE("")
|
||||
SET(TD_TAOS_TOOLS TRUE)
|
||||
ENDIF ()
|
||||
|
||||
IF (TD_WINDOWS)
|
||||
MESSAGE("${Yellow} set compiler flag for Windows! ${ColourReset}")
|
||||
SET(CMAKE_GENERATOR "NMake Makefiles" CACHE INTERNAL "" FORCE)
|
||||
SET(COMMON_FLAGS "/nologo /WX /wd4018 /wd4999 /Oi /Oy- /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Gd /errorReport:prompt /analyze-")
|
||||
|
||||
IF (MSVC AND (MSVC_VERSION GREATER_EQUAL 1900))
|
||||
SET(COMMON_FLAGS "${COMMON_FLAGS} /Wv:18")
|
||||
ENDIF ()
|
||||
|
||||
ELSE ()
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -fPIC -gdwarf-2 -msse4.2 -mfma -g3")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -fPIC -gdwarf-2 -msse4.2 -mfma -g3")
|
||||
|
||||
ENDIF ()
|
|
@ -1,12 +1,35 @@
|
|||
# =========================================================
|
||||
# Deps options
|
||||
# =========================================================
|
||||
|
||||
IF(${TD_WINDOWS})
|
||||
|
||||
MESSAGE("build pthread Win32")
|
||||
option(
|
||||
BUILD_PTHREAD
|
||||
"If build pthread on Windows"
|
||||
ON
|
||||
)
|
||||
|
||||
MESSAGE("build gnu regex for Windows")
|
||||
option(
|
||||
BUILD_GNUREGEX
|
||||
"If build gnu regex on Windows"
|
||||
ON
|
||||
)
|
||||
|
||||
ENDIF ()
|
||||
|
||||
IF(${TD_LINUX} MATCHES TRUE)
|
||||
|
||||
option(
|
||||
BUILD_TEST
|
||||
"If build unit tests using googletest"
|
||||
ON
|
||||
)
|
||||
|
||||
ENDIF ()
|
||||
|
||||
option(
|
||||
BUILD_WITH_LEVELDB
|
||||
"If build with leveldb"
|
||||
|
@ -25,11 +48,16 @@ option(
|
|||
OFF
|
||||
)
|
||||
|
||||
option(
|
||||
BUILD_WITH_BDB
|
||||
"If build with BerkleyDB"
|
||||
ON
|
||||
)
|
||||
IF(${TD_WINDOWS})
|
||||
MESSAGE("Not build BDB on Windows")
|
||||
ELSE ()
|
||||
option(
|
||||
BUILD_WITH_BDB
|
||||
"If build with BerkleyDB"
|
||||
ON
|
||||
)
|
||||
|
||||
ENDIF ()
|
||||
|
||||
option(
|
||||
BUILD_WITH_LUCENE
|
||||
|
@ -68,12 +96,16 @@ option(
|
|||
OFF
|
||||
)
|
||||
|
||||
IF(${TD_LINUX} MATCHES TRUE)
|
||||
|
||||
option(
|
||||
BUILD_DEPENDENCY_TESTS
|
||||
"If build dependency tests"
|
||||
ON
|
||||
)
|
||||
|
||||
ENDIF ()
|
||||
|
||||
option(
|
||||
BUILD_DOCS
|
||||
"If use doxygen build documents"
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
MESSAGE("Current system is ${CMAKE_SYSTEM_NAME}")
|
||||
|
||||
# init
|
||||
SET(TD_LINUX FALSE)
|
||||
SET(TD_WINDOWS FALSE)
|
||||
SET(TD_DARWIN FALSE)
|
||||
|
||||
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
|
||||
SET(TD_LINUX TRUE)
|
||||
SET(OSTYPE "Linux")
|
||||
ADD_DEFINITIONS("-DLINUX")
|
||||
|
||||
IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
|
||||
SET(TD_LINUX_64 TRUE)
|
||||
ELSE ()
|
||||
SET(TD_LINUX_32 TRUE)
|
||||
ENDIF ()
|
||||
|
||||
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
|
||||
SET(TD_DARWIN TRUE)
|
||||
SET(OSTYPE "macOS")
|
||||
ADD_DEFINITIONS("-DDARWIN")
|
||||
IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64")
|
||||
MESSAGE("Current system arch is arm64")
|
||||
SET(TD_DARWIN_64 TRUE)
|
||||
ADD_DEFINITIONS("-D_TD_DARWIN_64")
|
||||
ENDIF ()
|
||||
|
||||
ADD_DEFINITIONS("-DHAVE_UNISTD_H")
|
||||
|
||||
ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||
|
||||
SET(TD_WINDOWS TRUE)
|
||||
SET(OSTYPE "Windows")
|
||||
ADD_DEFINITIONS("-DWINDOWS")
|
||||
|
||||
IF (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
|
||||
SET(TD_WINDOWS_64 TRUE)
|
||||
ADD_DEFINITIONS("-D_TD_WINDOWS_64")
|
||||
ELSE ()
|
||||
SET(TD_WINDOWS_32 TRUE)
|
||||
ADD_DEFINITIONS("-D_TD_WINDOWS_32")
|
||||
ENDIF ()
|
||||
ENDIF()
|
||||
|
||||
MESSAGE("C Compiler ID: ${CMAKE_C_COMPILER_ID}")
|
||||
MESSAGE("CXX Compiler ID: ${CMAKE_CXX_COMPILER_ID}")
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
# gnuregex
|
||||
ExternalProject_Add(gnuregex
|
||||
URL https://launchpad.net/gnuregex/trunk/2.9/+download/libgnurx-src-2.9.zip
|
||||
DOWNLOAD_NAME libgnurx-src.zip
|
||||
SOURCE_DIR "${CMAKE_CONTRIB_DIR}/gnuregex"
|
||||
BINARY_DIR ""
|
||||
#BUILD_IN_SOURCE TRUE
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
TEST_COMMAND ""
|
||||
)
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
# pthread
|
||||
ExternalProject_Add(pthread
|
||||
GIT_REPOSITORY https://github.com/GerHobbelt/pthread-win32
|
||||
GIT_TAG v3.0.3.1
|
||||
SOURCE_DIR "${CMAKE_CONTRIB_DIR}/pthread-win32"
|
||||
BINARY_DIR ""
|
||||
#BUILD_IN_SOURCE TRUE
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
TEST_COMMAND ""
|
||||
)
|
|
@ -9,6 +9,16 @@ endfunction(cat IN_FILE OUT_FILE)
|
|||
set(CONTRIB_TMP_FILE "${CMAKE_BINARY_DIR}/deps_tmp_CMakeLists.txt.in")
|
||||
configure_file("${CMAKE_SUPPORT_DIR}/deps_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
|
||||
# pthread
|
||||
if(${BUILD_PTHREAD})
|
||||
cat("${CMAKE_SUPPORT_DIR}/pthread_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
endif()
|
||||
|
||||
# gnu regex
|
||||
if(${BUILD_GNUREGEX})
|
||||
cat("${CMAKE_SUPPORT_DIR}/gnuregex_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
endif()
|
||||
|
||||
# googletest
|
||||
if(${BUILD_TEST})
|
||||
cat("${CMAKE_SUPPORT_DIR}/gtest_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
|
@ -193,7 +203,10 @@ endif(${BUILD_WITH_TRAFT})
|
|||
|
||||
# LIBUV
|
||||
if(${BUILD_WITH_UV})
|
||||
add_compile_options(-Wno-sign-compare)
|
||||
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||
MESSAGE("Windows need set no-sign-compare")
|
||||
add_compile_options(-Wno-sign-compare)
|
||||
endif ()
|
||||
add_subdirectory(libuv)
|
||||
endif(${BUILD_WITH_UV})
|
||||
|
||||
|
@ -224,6 +237,7 @@ if(${BUILD_WITH_SQLITE})
|
|||
)
|
||||
endif(${BUILD_WITH_SQLITE})
|
||||
|
||||
# pthread
|
||||
|
||||
|
||||
# ================================================================================================
|
||||
|
|
|
@ -31,27 +31,27 @@ typedef void TAOS_SUB;
|
|||
typedef void **TAOS_ROW;
|
||||
|
||||
// Data type definition
|
||||
#define TSDB_DATA_TYPE_NULL 0 // 1 bytes
|
||||
#define TSDB_DATA_TYPE_BOOL 1 // 1 bytes
|
||||
#define TSDB_DATA_TYPE_TINYINT 2 // 1 byte
|
||||
#define TSDB_DATA_TYPE_SMALLINT 3 // 2 bytes
|
||||
#define TSDB_DATA_TYPE_INT 4 // 4 bytes
|
||||
#define TSDB_DATA_TYPE_BIGINT 5 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_FLOAT 6 // 4 bytes
|
||||
#define TSDB_DATA_TYPE_DOUBLE 7 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_BINARY 8 // string, alias for varchar
|
||||
#define TSDB_DATA_TYPE_TIMESTAMP 9 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_NCHAR 10 // unicode string
|
||||
#define TSDB_DATA_TYPE_UTINYINT 11 // 1 byte
|
||||
#define TSDB_DATA_TYPE_USMALLINT 12 // 2 bytes
|
||||
#define TSDB_DATA_TYPE_UINT 13 // 4 bytes
|
||||
#define TSDB_DATA_TYPE_UBIGINT 14 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_VARCHAR 15 // string
|
||||
#define TSDB_DATA_TYPE_VARBINARY 16 // binary
|
||||
#define TSDB_DATA_TYPE_JSON 17 // json
|
||||
#define TSDB_DATA_TYPE_DECIMAL 18 // decimal
|
||||
#define TSDB_DATA_TYPE_BLOB 19 // binary
|
||||
#define TSDB_DATA_TYPE_MEDIUMBLOB 20
|
||||
#define TSDB_DATA_TYPE_NULL 0 // 1 bytes
|
||||
#define TSDB_DATA_TYPE_BOOL 1 // 1 bytes
|
||||
#define TSDB_DATA_TYPE_TINYINT 2 // 1 byte
|
||||
#define TSDB_DATA_TYPE_SMALLINT 3 // 2 bytes
|
||||
#define TSDB_DATA_TYPE_INT 4 // 4 bytes
|
||||
#define TSDB_DATA_TYPE_BIGINT 5 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_FLOAT 6 // 4 bytes
|
||||
#define TSDB_DATA_TYPE_DOUBLE 7 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_VARCHAR 8 // string, alias for varchar
|
||||
#define TSDB_DATA_TYPE_TIMESTAMP 9 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_NCHAR 10 // unicode string
|
||||
#define TSDB_DATA_TYPE_UTINYINT 11 // 1 byte
|
||||
#define TSDB_DATA_TYPE_USMALLINT 12 // 2 bytes
|
||||
#define TSDB_DATA_TYPE_UINT 13 // 4 bytes
|
||||
#define TSDB_DATA_TYPE_UBIGINT 14 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_JSON 15 // json string
|
||||
#define TSDB_DATA_TYPE_VARBINARY 16 // binary
|
||||
#define TSDB_DATA_TYPE_DECIMAL 17 // decimal
|
||||
#define TSDB_DATA_TYPE_BLOB 18 // binary
|
||||
#define TSDB_DATA_TYPE_MEDIUMBLOB 19
|
||||
#define TSDB_DATA_TYPE_BINARY TSDB_DATA_TYPE_VARCHAR // string
|
||||
|
||||
typedef enum {
|
||||
TSDB_OPTION_LOCALE,
|
||||
|
|
|
@ -1365,6 +1365,7 @@ typedef struct SVCreateTbReq {
|
|||
typedef struct {
|
||||
int32_t code;
|
||||
SName tableName;
|
||||
int tmp; // TODO: to avoid compile error
|
||||
} SVCreateTbRsp, SVUpdateTbRsp;
|
||||
|
||||
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
|
||||
|
@ -1380,6 +1381,7 @@ void* tDeserializeSVCreateTbBatchReq(void* buf, SVCreateTbBatchReq* pReq);
|
|||
|
||||
typedef struct {
|
||||
SArray* rspList; // SArray<SVCreateTbRsp>
|
||||
int tmp; // TODO: to avoid compile error
|
||||
} SVCreateTbBatchRsp;
|
||||
|
||||
int32_t tSerializeSVCreateTbBatchRsp(void *buf, int32_t bufLen, SVCreateTbBatchRsp *pRsp);
|
||||
|
@ -1394,6 +1396,7 @@ typedef struct {
|
|||
} SVDropTbReq;
|
||||
|
||||
typedef struct {
|
||||
int tmp; // TODO: to avoid compile error
|
||||
} SVDropTbRsp;
|
||||
|
||||
int32_t tSerializeSVDropTbReq(void** buf, SVDropTbReq* pReq);
|
||||
|
@ -1909,24 +1912,19 @@ typedef enum {
|
|||
} ETDTimeUnit;
|
||||
|
||||
typedef struct {
|
||||
uint16_t funcId;
|
||||
uint16_t nColIds;
|
||||
col_id_t* colIds; // sorted colIds
|
||||
} SFuncColIds;
|
||||
|
||||
typedef struct {
|
||||
uint8_t version; // for compatibility
|
||||
uint8_t intervalUnit;
|
||||
uint8_t slidingUnit;
|
||||
char indexName[TSDB_INDEX_NAME_LEN];
|
||||
char timezone[TD_TIMEZONE_LEN];
|
||||
uint16_t nFuncColIds;
|
||||
uint16_t tagsFilterLen;
|
||||
tb_uid_t tableUid; // super/common table uid
|
||||
int64_t interval;
|
||||
int64_t sliding;
|
||||
SFuncColIds* funcColIds; // sorted funcIds
|
||||
char* tagsFilter;
|
||||
int8_t version; // for compatibility(default 0)
|
||||
int8_t intervalUnit;
|
||||
int8_t slidingUnit;
|
||||
char indexName[TSDB_INDEX_NAME_LEN];
|
||||
char timezone[TD_TIMEZONE_LEN]; // sma data is invalid if timezone change.
|
||||
uint16_t exprLen;
|
||||
uint16_t tagsFilterLen;
|
||||
int64_t indexUid;
|
||||
tb_uid_t tableUid; // super/child/common table uid
|
||||
int64_t interval;
|
||||
int64_t sliding;
|
||||
char* expr; // sma expression
|
||||
char* tagsFilter;
|
||||
} STSma; // Time-range-wise SMA
|
||||
|
||||
typedef struct {
|
||||
|
@ -1944,7 +1942,9 @@ typedef struct {
|
|||
int64_t ver; // use a general definition
|
||||
char indexName[TSDB_INDEX_NAME_LEN];
|
||||
} SVDropTSmaReq;
|
||||
|
||||
typedef struct {
|
||||
int tmp; // TODO: to avoid compile error
|
||||
} SVCreateTSmaRsp, SVDropTSmaRsp;
|
||||
|
||||
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
|
||||
|
@ -1953,24 +1953,30 @@ int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
|
|||
void* tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
STimeWindow tsWindow; // [skey, ekey]
|
||||
uint64_t tableUid; // sub/common table uid
|
||||
int32_t numOfBlocks; // number of sma blocks for each column, total number is numOfBlocks*numOfColId
|
||||
int32_t dataLen; // total data length
|
||||
col_id_t* colIds; // e.g. 2,4,9,10
|
||||
col_id_t numOfColIds; // e.g. 4
|
||||
char data[]; // the sma blocks
|
||||
} STSmaData;
|
||||
col_id_t colId;
|
||||
uint16_t blockSize; // sma data block size
|
||||
char data[];
|
||||
} STSmaColData;
|
||||
|
||||
// TODO: move to the final location afte schema of STSma/STSmaData defined
|
||||
static FORCE_INLINE void tdDestroySmaData(STSmaData* pSmaData) {
|
||||
if (pSmaData) {
|
||||
if (pSmaData->colIds) {
|
||||
tfree(pSmaData->colIds);
|
||||
}
|
||||
tfree(pSmaData);
|
||||
}
|
||||
}
|
||||
typedef struct {
|
||||
tb_uid_t tableUid; // super/child/normal table uid
|
||||
int32_t dataLen; // not including head
|
||||
char data[];
|
||||
} STSmaTbData;
|
||||
|
||||
typedef struct {
|
||||
int64_t indexUid;
|
||||
TSKEY skey; // startTS of one interval/sliding
|
||||
int64_t interval;
|
||||
int32_t dataLen; // not including head
|
||||
int8_t intervalUnit;
|
||||
char data[];
|
||||
} STSmaDataWrapper; // sma data for a interval/sliding window
|
||||
|
||||
// interval/sliding => window
|
||||
|
||||
// => window->table->colId
|
||||
// => 当一个window下所有的表均计算完成时,流计算告知tsdb清除window的过期标记
|
||||
|
||||
// RSma: Rollup SMA
|
||||
typedef struct {
|
||||
|
@ -1993,13 +1999,7 @@ typedef struct {
|
|||
|
||||
static FORCE_INLINE void tdDestroyTSma(STSma* pSma) {
|
||||
if (pSma) {
|
||||
if (pSma->funcColIds != NULL) {
|
||||
for (uint16_t i = 0; i < pSma->nFuncColIds; ++i) {
|
||||
tfree((pSma->funcColIds + i)->colIds);
|
||||
}
|
||||
tfree(pSma->funcColIds);
|
||||
}
|
||||
|
||||
tfree(pSma->expr);
|
||||
tfree(pSma->tagsFilter);
|
||||
}
|
||||
}
|
||||
|
@ -2018,24 +2018,20 @@ static FORCE_INLINE void tdDestroyTSmaWrapper(STSmaWrapper* pSW) {
|
|||
static FORCE_INLINE int32_t tEncodeTSma(void** buf, const STSma* pSma) {
|
||||
int32_t tlen = 0;
|
||||
|
||||
tlen += taosEncodeFixedU8(buf, pSma->version);
|
||||
tlen += taosEncodeFixedU8(buf, pSma->intervalUnit);
|
||||
tlen += taosEncodeFixedU8(buf, pSma->slidingUnit);
|
||||
tlen += taosEncodeFixedI8(buf, pSma->version);
|
||||
tlen += taosEncodeFixedI8(buf, pSma->intervalUnit);
|
||||
tlen += taosEncodeFixedI8(buf, pSma->slidingUnit);
|
||||
tlen += taosEncodeString(buf, pSma->indexName);
|
||||
tlen += taosEncodeString(buf, pSma->timezone);
|
||||
tlen += taosEncodeFixedU16(buf, pSma->nFuncColIds);
|
||||
tlen += taosEncodeFixedU16(buf, pSma->exprLen);
|
||||
tlen += taosEncodeFixedU16(buf, pSma->tagsFilterLen);
|
||||
tlen += taosEncodeFixedI64(buf, pSma->indexUid);
|
||||
tlen += taosEncodeFixedI64(buf, pSma->tableUid);
|
||||
tlen += taosEncodeFixedI64(buf, pSma->interval);
|
||||
tlen += taosEncodeFixedI64(buf, pSma->sliding);
|
||||
|
||||
for (uint16_t i = 0; i < pSma->nFuncColIds; ++i) {
|
||||
SFuncColIds* funcColIds = pSma->funcColIds + i;
|
||||
tlen += taosEncodeFixedU16(buf, funcColIds->funcId);
|
||||
tlen += taosEncodeFixedU16(buf, funcColIds->nColIds);
|
||||
for (uint16_t j = 0; j < funcColIds->nColIds; ++j) {
|
||||
tlen += taosEncodeFixedU16(buf, *(funcColIds->colIds + j));
|
||||
}
|
||||
|
||||
if (pSma->exprLen > 0) {
|
||||
tlen += taosEncodeString(buf, pSma->expr);
|
||||
}
|
||||
|
||||
if (pSma->tagsFilterLen > 0) {
|
||||
|
@ -2056,43 +2052,30 @@ static FORCE_INLINE int32_t tEncodeTSmaWrapper(void** buf, const STSmaWrapper* p
|
|||
}
|
||||
|
||||
static FORCE_INLINE void* tDecodeTSma(void* buf, STSma* pSma) {
|
||||
buf = taosDecodeFixedU8(buf, &pSma->version);
|
||||
buf = taosDecodeFixedU8(buf, &pSma->intervalUnit);
|
||||
buf = taosDecodeFixedU8(buf, &pSma->slidingUnit);
|
||||
buf = taosDecodeFixedI8(buf, &pSma->version);
|
||||
buf = taosDecodeFixedI8(buf, &pSma->intervalUnit);
|
||||
buf = taosDecodeFixedI8(buf, &pSma->slidingUnit);
|
||||
buf = taosDecodeStringTo(buf, pSma->indexName);
|
||||
buf = taosDecodeStringTo(buf, pSma->timezone);
|
||||
buf = taosDecodeFixedU16(buf, &pSma->nFuncColIds);
|
||||
buf = taosDecodeFixedU16(buf, &pSma->exprLen);
|
||||
buf = taosDecodeFixedU16(buf, &pSma->tagsFilterLen);
|
||||
buf = taosDecodeFixedI64(buf, &pSma->indexUid);
|
||||
buf = taosDecodeFixedI64(buf, &pSma->tableUid);
|
||||
buf = taosDecodeFixedI64(buf, &pSma->interval);
|
||||
buf = taosDecodeFixedI64(buf, &pSma->sliding);
|
||||
|
||||
if (pSma->nFuncColIds > 0) {
|
||||
pSma->funcColIds = (SFuncColIds*)calloc(pSma->nFuncColIds, sizeof(SFuncColIds));
|
||||
if (pSma->funcColIds == NULL) {
|
||||
|
||||
if (pSma->exprLen > 0) {
|
||||
pSma->expr = (char*)calloc(pSma->exprLen, 1);
|
||||
if (pSma->expr != NULL) {
|
||||
buf = taosDecodeStringTo(buf, pSma->expr);
|
||||
} else {
|
||||
tdDestroyTSma(pSma);
|
||||
return NULL;
|
||||
}
|
||||
for (uint16_t i = 0; i < pSma->nFuncColIds; ++i) {
|
||||
SFuncColIds* funcColIds = pSma->funcColIds + i;
|
||||
buf = taosDecodeFixedU16(buf, &funcColIds->funcId);
|
||||
buf = taosDecodeFixedU16(buf, &funcColIds->nColIds);
|
||||
if (funcColIds->nColIds > 0) {
|
||||
funcColIds->colIds = (col_id_t*)calloc(funcColIds->nColIds, sizeof(col_id_t));
|
||||
if (funcColIds->colIds != NULL) {
|
||||
for (uint16_t j = 0; j < funcColIds->nColIds; ++j) {
|
||||
buf = taosDecodeFixedU16(buf, funcColIds->colIds + j);
|
||||
}
|
||||
} else {
|
||||
tdDestroyTSma(pSma);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
funcColIds->colIds = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
pSma->funcColIds = NULL;
|
||||
pSma->expr = NULL;
|
||||
}
|
||||
|
||||
if (pSma->tagsFilterLen > 0) {
|
||||
|
|
|
@ -103,6 +103,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
// TODO
|
||||
int tmp; // TODO: to avoid compile error
|
||||
} STpRow; // tuple
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
@ -1098,4 +1099,4 @@ const STSRow *tRowBatchIterNext(STSRowBatchIter *pRowBatchIter);
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_COMMON_ROW_H_*/
|
||||
#endif /*_TD_COMMON_ROW_H_*/
|
||||
|
|
|
@ -41,7 +41,6 @@ int32_t dsDataSinkMgtInit(SDataSinkMgtCfg *cfg);
|
|||
|
||||
typedef struct SInputData {
|
||||
const struct SSDataBlock* pData;
|
||||
SHashObj* pTableRetrieveTsMap;
|
||||
} SInputData;
|
||||
|
||||
typedef struct SOutputData {
|
||||
|
|
|
@ -29,7 +29,6 @@ extern "C" {
|
|||
|
||||
extern int tsRpcHeadSize;
|
||||
|
||||
typedef struct SRpcPush SRpcPush;
|
||||
|
||||
typedef struct SRpcConnInfo {
|
||||
uint32_t clientIp;
|
||||
|
@ -45,16 +44,8 @@ typedef struct SRpcMsg {
|
|||
int32_t code;
|
||||
void * handle; // rpc handle returned to app
|
||||
void * ahandle; // app handle set by client
|
||||
int persist; // keep handle or not, default 0
|
||||
|
||||
SRpcPush *push;
|
||||
|
||||
} SRpcMsg;
|
||||
|
||||
typedef struct SRpcPush {
|
||||
void *arg;
|
||||
int (*callback)(void *arg, SRpcMsg *rpcMsg);
|
||||
} SRpcPush;
|
||||
|
||||
typedef struct SRpcInit {
|
||||
uint16_t localPort; // local port
|
||||
|
@ -64,7 +55,6 @@ typedef struct SRpcInit {
|
|||
int8_t connType; // TAOS_CONN_UDP, TAOS_CONN_TCPC, TAOS_CONN_TCPS
|
||||
int idleTime; // milliseconds, 0 means idle timer is disabled
|
||||
|
||||
bool noPool; // create conn pool or not
|
||||
// the following is for client app ecurity only
|
||||
char *user; // user name
|
||||
char spi; // security parameter index
|
||||
|
@ -86,7 +76,7 @@ typedef struct SRpcInit {
|
|||
|
||||
int32_t rpcInit();
|
||||
void rpcCleanup();
|
||||
void *rpcOpen(const SRpcInit *pRpc);
|
||||
void * rpcOpen(const SRpcInit *pRpc);
|
||||
void rpcClose(void *);
|
||||
void * rpcMallocCont(int contLen);
|
||||
void rpcFreeCont(void *pCont);
|
||||
|
@ -99,6 +89,9 @@ void rpcSendRecv(void *shandle, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp)
|
|||
int rpcReportProgress(void *pConn, char *pCont, int contLen);
|
||||
void rpcCancelRequest(int64_t rid);
|
||||
|
||||
void rpcRefHandle(void *handle, int8_t type);
|
||||
void rpcUnrefHandle(void *handle, int8_t type);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -22,7 +22,22 @@ extern "C" {
|
|||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#if !defined(WINDOWS)
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <regex.h>
|
||||
#include <sched.h>
|
||||
#include <wordexp.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/prctl.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <float.h>
|
||||
|
@ -30,8 +45,6 @@ extern "C" {
|
|||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <math.h>
|
||||
#include <regex.h>
|
||||
#include <sched.h>
|
||||
#include <setjmp.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
|
@ -43,16 +56,9 @@ extern "C" {
|
|||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/param.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
#include <wordexp.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#include <sys/mman.h>
|
||||
#include <sys/prctl.h>
|
||||
|
||||
#include "osAtomic.h"
|
||||
#include "osDef.h"
|
||||
|
|
|
@ -49,7 +49,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
#if defined(WINDOWS)
|
||||
char *stpcpy (char *dest, const char *src);
|
||||
char *stpncpy (char *dest, const char *src, size_t n);
|
||||
|
||||
|
@ -63,16 +63,46 @@ extern "C" {
|
|||
#define strtok_r strtok_s
|
||||
#define snprintf _snprintf
|
||||
#define in_addr_t unsigned long
|
||||
#define socklen_t int
|
||||
// #define socklen_t int
|
||||
|
||||
struct tm *localtime_r(const time_t *timep, struct tm *result);
|
||||
char * strptime(const char *buf, const char *fmt, struct tm *tm);
|
||||
char * strsep(char **stringp, const char *delim);
|
||||
char * getpass(const char *prefix);
|
||||
char * strndup(const char *s, size_t n);
|
||||
|
||||
#endif
|
||||
int gettimeofday(struct timeval *ptv, void *pTimeZone);
|
||||
|
||||
// for send function in tsocket.c
|
||||
#define MSG_NOSIGNAL 0
|
||||
#define SO_NO_CHECK 0x1234
|
||||
#define SOL_TCP 0x1234
|
||||
|
||||
#define SHUT_RDWR SD_BOTH
|
||||
#define SHUT_RD SD_RECEIVE
|
||||
#define SHUT_WR SD_SEND
|
||||
|
||||
#define LOCK_EX 1
|
||||
#define LOCK_NB 2
|
||||
#define LOCK_UN 3
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 256
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
int we_wordc;
|
||||
char *we_wordv[1];
|
||||
int we_offs;
|
||||
char wordPos[1025];
|
||||
} wordexp_t;
|
||||
int wordexp(char *words, wordexp_t *pwordexp, int flags);
|
||||
void wordfree(wordexp_t *pwordexp);
|
||||
|
||||
#define openlog(a, b, c)
|
||||
#define closelog()
|
||||
#define LOG_ERR 0
|
||||
#define LOG_INFO 1
|
||||
void syslog(int unused, const char *format, ...);
|
||||
#endif // WINDOWS
|
||||
|
||||
#ifndef WINDOWS
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
|
@ -166,7 +196,7 @@ extern "C" {
|
|||
#define PRIzu "zu"
|
||||
#endif
|
||||
|
||||
#if defined(_TD_LINUX_64) || defined(_TD_LINUX_32) || defined(_TD_MIPS_64) || defined(_TD_ARM_32) || defined(_TD_ARM_64) || defined(_TD_DARWIN_64)
|
||||
#if !defined(WINDOWS)
|
||||
#if defined(_TD_DARWIN_64)
|
||||
// MacOS
|
||||
#if !defined(_GNU_SOURCE)
|
||||
|
@ -181,8 +211,7 @@ extern "C" {
|
|||
#endif
|
||||
#else
|
||||
// Windows
|
||||
// #define setThreadName(name)
|
||||
#define setThreadName(name) do { prctl(PR_SET_NAME, (name)); } while (0)
|
||||
#define setThreadName(name)
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
@ -199,4 +228,4 @@ extern "C" {
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_OS_DEF_H_*/
|
||||
#endif /*_TD_OS_DEF_H_*/
|
||||
|
|
|
@ -22,6 +22,15 @@ extern "C" {
|
|||
|
||||
#include "osSocket.h"
|
||||
|
||||
#if defined(WINDOWS)
|
||||
typedef int32_t FileFd;
|
||||
typedef SOCKET SocketFd;
|
||||
#else
|
||||
typedef int32_t FileFd;
|
||||
typedef int32_t SocketFd;
|
||||
#endif
|
||||
|
||||
int64_t taosRead(FileFd fd, void *buf, int64_t count);
|
||||
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||
#ifndef ALLOW_FORBID_FUNC
|
||||
#define open OPEN_FUNC_TAOS_FORBID
|
||||
|
@ -76,7 +85,13 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count);
|
|||
int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset);
|
||||
int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count);
|
||||
void taosFprintfFile(TdFilePtr pFile, const char *format, ...);
|
||||
|
||||
#if defined(WINDOWS)
|
||||
#define __restrict__
|
||||
#endif // WINDOWS
|
||||
|
||||
int64_t taosGetLineFile(TdFilePtr pFile, char ** __restrict__ ptrBuf);
|
||||
|
||||
int32_t taosEOFFile(TdFilePtr pFile);
|
||||
|
||||
int64_t taosCloseFile(TdFilePtr *ppFile);
|
||||
|
|
|
@ -16,12 +16,13 @@
|
|||
#ifndef _TD_OS_SEMPHONE_H_
|
||||
#define _TD_OS_SEMPHONE_H_
|
||||
|
||||
#include <semaphore.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
#if defined (_TD_DARWIN_64)
|
||||
typedef struct tsem_s *tsem_t;
|
||||
int tsem_init(tsem_t *sem, int pshared, unsigned int value);
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#define epoll_wait EPOLL_WAIT_FUNC_TAOS_FORBID
|
||||
#endif
|
||||
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
#if defined(WINDOWS)
|
||||
#include "winsock2.h"
|
||||
#include <WS2tcpip.h>
|
||||
#include <winbase.h>
|
||||
|
|
|
@ -52,6 +52,13 @@ int32_t taosGetSystemUUID(char *uid, int32_t uidlen);
|
|||
char *taosGetCmdlineByPID(int32_t pid);
|
||||
void taosSetCoreDump(bool enable);
|
||||
|
||||
#if defined(WINDOWS)
|
||||
|
||||
#define _UTSNAME_LENGTH 65
|
||||
#define _UTSNAME_MACHINE_LENGTH _UTSNAME_LENGTH
|
||||
|
||||
#endif // WINDOWS
|
||||
|
||||
typedef struct {
|
||||
char sysname[_UTSNAME_MACHINE_LENGTH];
|
||||
char nodename[_UTSNAME_MACHINE_LENGTH];
|
||||
|
|
|
@ -20,7 +20,19 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||
#ifndef ALLOW_FORBID_FUNC
|
||||
#define strptime STRPTIME_FUNC_TAOS_FORBID
|
||||
#define gettimeofday GETTIMEOFDAY_FUNC_TAOS_FORBID
|
||||
#define localtime_s LOCALTIMES_FUNC_TAOS_FORBID
|
||||
#define localtime_r LOCALTIMER_FUNC_TAOS_FORBID
|
||||
#define time TIME_FUNC_TAOS_FORBID
|
||||
#endif
|
||||
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
|
||||
#define CLOCK_REALTIME 0
|
||||
|
||||
#ifdef _TD_GO_DLL_
|
||||
#define MILLISECOND_PER_SECOND (1000LL)
|
||||
#else
|
||||
|
@ -61,6 +73,9 @@ static FORCE_INLINE int64_t taosGetTimestampNs() {
|
|||
return (int64_t)systemTime.tv_sec * 1000000000L + (int64_t)systemTime.tv_nsec;
|
||||
}
|
||||
|
||||
char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm);
|
||||
struct tm *taosLocalTime(const time_t *timep, struct tm *result);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -20,6 +20,15 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||
#ifndef ALLOW_FORBID_FUNC
|
||||
#define timer_create TIMER_CREATE_FUNC_TAOS_FORBID
|
||||
#define timer_settime TIMER_SETTIME_FUNC_TAOS_FORBID
|
||||
#define timer_delete TIMER_DELETE_FUNC_TAOS_FORBID
|
||||
#define timeSetEvent TIMESETEVENT_SETTIME_FUNC_TAOS_FORBID
|
||||
#define timeKillEvent TIMEKILLEVENT_SETTIME_FUNC_TAOS_FORBID
|
||||
#endif
|
||||
|
||||
#define MSECONDS_PER_TICK 5
|
||||
|
||||
int32_t taosInitTimer(void (*callback)(int32_t), int32_t ms);
|
||||
|
|
|
@ -72,8 +72,6 @@ static void deregisterRequest(SRequestObj *pRequest) {
|
|||
taosReleaseRef(clientConnRefPool, pTscObj->id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// todo close the transporter properly
|
||||
void closeTransporter(STscObj *pTscObj) {
|
||||
if (pTscObj == NULL || pTscObj->pAppInfo->pTransporter == NULL) {
|
||||
|
@ -241,6 +239,7 @@ void taos_init_imp(void) {
|
|||
clientConnRefPool = taosOpenRef(200, destroyTscObj);
|
||||
clientReqRefPool = taosOpenRef(40960, doDestroyRequest);
|
||||
|
||||
// transDestroyBuffer(&conn->readBuf);
|
||||
taosGetAppName(appInfo.appName, NULL);
|
||||
pthread_mutex_init(&appInfo.mutex, NULL);
|
||||
|
||||
|
|
|
@ -215,8 +215,10 @@ void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList) {
|
||||
void* pTransporter = pRequest->pTscObj->pAppInfo->pTransporter;
|
||||
|
||||
SQueryResult res = {.code = 0, .numOfRows = 0, .msgSize = ERROR_MSG_BUF_DEFAULT_SIZE, .msg = pRequest->msgBuf};
|
||||
int32_t code = schedulerExecJob(pTransporter, pNodeList, pDag, &pRequest->body.queryJob, pRequest->sqlstr, &res);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -232,7 +234,7 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList
|
|||
|
||||
if (TDMT_VND_SUBMIT == pRequest->type || TDMT_VND_CREATE_TABLE == pRequest->type) {
|
||||
pRequest->body.resInfo.numOfRows = res.numOfRows;
|
||||
|
||||
|
||||
if (pRequest->body.queryJob != 0) {
|
||||
schedulerFreeJob(pRequest->body.queryJob);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,10 @@ target_include_directories(
|
|||
common
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/common"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
IF(${TD_WINDOWS})
|
||||
PRIVATE "${CMAKE_SOURCE_DIR}/contrib/pthread-win32"
|
||||
PRIVATE "${CMAKE_SOURCE_DIR}/contrib/gnuregex"
|
||||
ENDIF ()
|
||||
)
|
||||
target_link_libraries(
|
||||
common
|
||||
|
|
|
@ -61,7 +61,7 @@ int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, in
|
|||
}
|
||||
struct tm tm;
|
||||
time_t t = (time_t)start;
|
||||
localtime_r(&t, &tm);
|
||||
taosLocalTime(&t, &tm);
|
||||
tm.tm_sec = 0;
|
||||
tm.tm_min = 0;
|
||||
tm.tm_hour = 0;
|
||||
|
|
|
@ -69,7 +69,7 @@ static int64_t m_deltaUtc = 0;
|
|||
void deltaToUtcInitOnce() {
|
||||
struct tm tm = {0};
|
||||
|
||||
(void)strptime("1970-01-01 00:00:00", (const char*)("%Y-%m-%d %H:%M:%S"), &tm);
|
||||
(void)taosStrpTime("1970-01-01 00:00:00", (const char*)("%Y-%m-%d %H:%M:%S"), &tm);
|
||||
m_deltaUtc = (int64_t)mktime(&tm);
|
||||
// printf("====delta:%lld\n\n", seconds);
|
||||
}
|
||||
|
@ -236,9 +236,9 @@ int32_t parseTimeWithTz(const char* timestr, int64_t* time, int32_t timePrec, ch
|
|||
|
||||
char* str;
|
||||
if (delim == 'T') {
|
||||
str = strptime(timestr, "%Y-%m-%dT%H:%M:%S", &tm);
|
||||
str = taosStrpTime(timestr, "%Y-%m-%dT%H:%M:%S", &tm);
|
||||
} else if (delim == 0) {
|
||||
str = strptime(timestr, "%Y-%m-%d %H:%M:%S", &tm);
|
||||
str = taosStrpTime(timestr, "%Y-%m-%d %H:%M:%S", &tm);
|
||||
} else {
|
||||
str = NULL;
|
||||
}
|
||||
|
@ -303,7 +303,7 @@ int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec) {
|
|||
*time = 0;
|
||||
struct tm tm = {0};
|
||||
|
||||
char* str = strptime(timestr, "%Y-%m-%d %H:%M:%S", &tm);
|
||||
char* str = taosStrpTime(timestr, "%Y-%m-%d %H:%M:%S", &tm);
|
||||
if (str == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -338,7 +338,7 @@ int32_t parseLocaltimeDst(char* timestr, int64_t* time, int32_t timePrec) {
|
|||
struct tm tm = {0};
|
||||
tm.tm_isdst = -1;
|
||||
|
||||
char* str = strptime(timestr, "%Y-%m-%d %H:%M:%S", &tm);
|
||||
char* str = taosStrpTime(timestr, "%Y-%m-%d %H:%M:%S", &tm);
|
||||
if (str == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -466,7 +466,7 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) {
|
|||
|
||||
struct tm tm;
|
||||
time_t tt = (time_t)(t / TSDB_TICK_PER_SECOND(precision));
|
||||
localtime_r(&tt, &tm);
|
||||
taosLocalTime(&tt, &tm);
|
||||
int32_t mon = tm.tm_year * 12 + tm.tm_mon + (int32_t)duration;
|
||||
tm.tm_year = mon / 12;
|
||||
tm.tm_mon = mon % 12;
|
||||
|
@ -489,11 +489,11 @@ int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char
|
|||
|
||||
struct tm tm;
|
||||
time_t t = (time_t)skey;
|
||||
localtime_r(&t, &tm);
|
||||
taosLocalTime(&t, &tm);
|
||||
int32_t smon = tm.tm_year * 12 + tm.tm_mon;
|
||||
|
||||
t = (time_t)ekey;
|
||||
localtime_r(&t, &tm);
|
||||
taosLocalTime(&t, &tm);
|
||||
int32_t emon = tm.tm_year * 12 + tm.tm_mon;
|
||||
|
||||
if (unit == 'y') {
|
||||
|
@ -514,7 +514,7 @@ int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precisio
|
|||
start /= (int64_t)(TSDB_TICK_PER_SECOND(precision));
|
||||
struct tm tm;
|
||||
time_t tt = (time_t)start;
|
||||
localtime_r(&tt, &tm);
|
||||
taosLocalTime(&tt, &tm);
|
||||
tm.tm_sec = 0;
|
||||
tm.tm_min = 0;
|
||||
tm.tm_hour = 0;
|
||||
|
@ -597,13 +597,13 @@ const char* fmtts(int64_t ts) {
|
|||
|
||||
if (ts > -62135625943 && ts < 32503651200) {
|
||||
time_t t = (time_t)ts;
|
||||
localtime_r(&t, &tm);
|
||||
taosLocalTime(&t, &tm);
|
||||
pos += strftime(buf + pos, sizeof(buf), "s=%Y-%m-%d %H:%M:%S", &tm);
|
||||
}
|
||||
|
||||
if (ts > -62135625943000 && ts < 32503651200000) {
|
||||
time_t t = (time_t)(ts / 1000);
|
||||
localtime_r(&t, &tm);
|
||||
taosLocalTime(&t, &tm);
|
||||
if (pos > 0) {
|
||||
buf[pos++] = ' ';
|
||||
buf[pos++] = '|';
|
||||
|
@ -615,7 +615,7 @@ const char* fmtts(int64_t ts) {
|
|||
|
||||
{
|
||||
time_t t = (time_t)(ts / 1000000);
|
||||
localtime_r(&t, &tm);
|
||||
taosLocalTime(&t, &tm);
|
||||
if (pos > 0) {
|
||||
buf[pos++] = ' ';
|
||||
buf[pos++] = '|';
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
#include "dndMnode.h"
|
||||
#include "dndVnodes.h"
|
||||
|
||||
#define INTERNAL_USER "_dnd"
|
||||
#define INTERNAL_CKEY "_key"
|
||||
#define INTERNAL_USER "_dnd"
|
||||
#define INTERNAL_CKEY "_key"
|
||||
#define INTERNAL_SECRET "_pwd"
|
||||
|
||||
static void dndInitMsgFp(STransMgmt *pMgmt) {
|
||||
|
@ -156,7 +156,7 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
|
|||
}
|
||||
|
||||
static void dndProcessResponse(void *parent, SRpcMsg *pRsp, SEpSet *pEpSet) {
|
||||
SDnode *pDnode = parent;
|
||||
SDnode * pDnode = parent;
|
||||
STransMgmt *pMgmt = &pDnode->tmgmt;
|
||||
|
||||
tmsg_t msgType = pRsp->msgType;
|
||||
|
@ -194,7 +194,6 @@ static int32_t dndInitClient(SDnode *pDnode) {
|
|||
rpcInit.ckey = INTERNAL_CKEY;
|
||||
rpcInit.spi = 1;
|
||||
rpcInit.parent = pDnode;
|
||||
rpcInit.noPool = true;
|
||||
|
||||
char pass[TSDB_PASSWORD_LEN + 1] = {0};
|
||||
taosEncryptPass_c((uint8_t *)(INTERNAL_SECRET), strlen(INTERNAL_SECRET), pass);
|
||||
|
@ -220,7 +219,7 @@ static void dndCleanupClient(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
static void dndProcessRequest(void *param, SRpcMsg *pReq, SEpSet *pEpSet) {
|
||||
SDnode *pDnode = param;
|
||||
SDnode * pDnode = param;
|
||||
STransMgmt *pMgmt = &pDnode->tmgmt;
|
||||
|
||||
tmsg_t msgType = pReq->msgType;
|
||||
|
@ -314,7 +313,7 @@ static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char
|
|||
SAuthReq authReq = {0};
|
||||
tstrncpy(authReq.user, user, TSDB_USER_LEN);
|
||||
int32_t contLen = tSerializeSAuthReq(NULL, 0, &authReq);
|
||||
void *pReq = rpcMallocCont(contLen);
|
||||
void * pReq = rpcMallocCont(contLen);
|
||||
tSerializeSAuthReq(pReq, contLen, &authReq);
|
||||
|
||||
SRpcMsg rpcMsg = {.pCont = pReq, .contLen = contLen, .msgType = TDMT_MND_AUTH, .ahandle = (void *)9528};
|
||||
|
|
|
@ -58,8 +58,8 @@ STbCfg * metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid);
|
|||
STbCfg * metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid);
|
||||
SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline);
|
||||
STSchema * metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver);
|
||||
STSma * metaGetSmaInfoByName(SMeta *pMeta, const char *indexName);
|
||||
STSmaWrapper * metaGetSmaInfoByUid(SMeta *pMeta, tb_uid_t uid);
|
||||
STSma * metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid);
|
||||
STSmaWrapper * metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid);
|
||||
SArray * metaGetSmaTbUids(SMeta *pMeta, bool isDup);
|
||||
|
||||
SMTbCursor *metaOpenTbCursor(SMeta *pMeta);
|
||||
|
|
|
@ -89,24 +89,21 @@ int tsdbCommit(STsdb *pTsdb);
|
|||
|
||||
/**
|
||||
* @brief Insert tSma(Time-range-wise SMA) data from stream computing engine
|
||||
*
|
||||
* @param pTsdb
|
||||
* @param param
|
||||
* @param pData
|
||||
* @return int32_t
|
||||
*
|
||||
* @param pTsdb
|
||||
* @param msg
|
||||
* @return int32_t
|
||||
*/
|
||||
int32_t tsdbInsertTSmaData(STsdb *pTsdb, STSma *param, STSmaData *pData);
|
||||
int32_t tsdbInsertTSmaData(STsdb *pTsdb, char *msg);
|
||||
|
||||
/**
|
||||
* @brief Insert RSma(Time-range-wise Rollup SMA) data.
|
||||
*
|
||||
* @param pTsdb
|
||||
* @param param
|
||||
* @param pData
|
||||
* @return int32_t
|
||||
*
|
||||
* @param pTsdb
|
||||
* @param msg
|
||||
* @return int32_t
|
||||
*/
|
||||
int32_t tsdbInsertRSmaData(STsdb *pTsdb, SRSma *param, STSmaData *pData);
|
||||
|
||||
int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg);
|
||||
|
||||
// STsdbCfg
|
||||
int tsdbOptionsInit(STsdbCfg *);
|
||||
|
|
|
@ -42,17 +42,14 @@ typedef struct {
|
|||
typedef struct {
|
||||
STsdbFSMeta meta; // FS meta
|
||||
SArray * df; // data file array
|
||||
|
||||
// SArray * v2t100.index_name
|
||||
|
||||
SArray * smaf; // sma data file array v2t1900.index_name
|
||||
SArray * sf; // sma data file array v2(t|r)1900.index_name_1
|
||||
} SFSStatus;
|
||||
|
||||
/**
|
||||
* @brief Directory structure of .tsma data files.
|
||||
*
|
||||
* root@cary /vnode2/tsdb $ tree .tsma/
|
||||
* .tsma/
|
||||
*
|
||||
* /vnode2/tsdb $ tree .sma/
|
||||
* .sma/
|
||||
* ├── v2t100.index_name_1
|
||||
* ├── v2t101.index_name_1
|
||||
* ├── v2t102.index_name_1
|
||||
|
@ -66,7 +63,7 @@ typedef struct {
|
|||
* 0 directories, 9 files
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
typedef struct {
|
||||
pthread_rwlock_t lock;
|
||||
|
||||
SFSStatus *cstatus; // current status
|
||||
|
|
|
@ -335,6 +335,17 @@ typedef struct {
|
|||
SDFile files[TSDB_FILE_MAX];
|
||||
} SDFileSet;
|
||||
|
||||
typedef struct {
|
||||
int fid;
|
||||
int8_t state;
|
||||
uint8_t ver;
|
||||
#if 0
|
||||
SDFInfo info;
|
||||
#endif
|
||||
STfsFile f;
|
||||
TdFilePtr pFile;
|
||||
} SSFile; // files split by days with fid
|
||||
|
||||
#define TSDB_LATEST_FSET_VER 0
|
||||
|
||||
#define TSDB_FSET_FID(s) ((s)->fid)
|
||||
|
|
|
@ -19,26 +19,28 @@
|
|||
typedef struct SSmaStat SSmaStat;
|
||||
|
||||
// insert/update interface
|
||||
int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, STSma *param, STSmaData *pData);
|
||||
int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, SRSma *param, STSmaData *pData);
|
||||
int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg);
|
||||
int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg);
|
||||
|
||||
|
||||
// query interface
|
||||
// TODO: This is the basic params, and should wrap the params to a queryHandle.
|
||||
int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSma *param, STSmaData *pData, STimeWindow *queryWin, int32_t nMaxResult);
|
||||
int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, STimeWindow *queryWin, int32_t nMaxResult);
|
||||
|
||||
// management interface
|
||||
int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, char *msg);
|
||||
int32_t tsdbDestroySmaState(SSmaStat *pSmaStat);
|
||||
#if 0
|
||||
int32_t tsdbGetTSmaStatus(STsdb *pTsdb, STSma *param, void *result);
|
||||
int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin);
|
||||
int32_t tsdbDestroySmaState(SSmaStat *pSmaStat);
|
||||
#endif
|
||||
|
||||
// internal func
|
||||
|
||||
|
||||
static FORCE_INLINE int32_t tsdbEncodeTSmaKey(uint64_t tableUid, col_id_t colId, TSKEY tsKey, void **pData) {
|
||||
static FORCE_INLINE int32_t tsdbEncodeTSmaKey(tb_uid_t tableUid, col_id_t colId, TSKEY tsKey, void **pData) {
|
||||
int32_t len = 0;
|
||||
len += taosEncodeFixedU64(pData, tableUid);
|
||||
len += taosEncodeFixedI64(pData, tableUid);
|
||||
len += taosEncodeFixedU16(pData, colId);
|
||||
len += taosEncodeFixedI64(pData, tsKey);
|
||||
return len;
|
||||
|
|
|
@ -227,21 +227,27 @@ int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid) {
|
|||
}
|
||||
|
||||
int metaSaveSmaToDB(SMeta *pMeta, STSma *pSmaCfg) {
|
||||
char buf[512] = {0}; // TODO: may overflow
|
||||
void *pBuf = NULL;
|
||||
// char buf[512] = {0}; // TODO: may overflow
|
||||
void *pBuf = NULL, *qBuf = NULL;
|
||||
DBT key1 = {0}, value1 = {0};
|
||||
|
||||
{
|
||||
// save sma info
|
||||
pBuf = buf;
|
||||
int32_t len = tEncodeTSma(NULL, pSmaCfg);
|
||||
pBuf = calloc(len, 1);
|
||||
if (pBuf == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
key1.data = pSmaCfg->indexName;
|
||||
key1.size = strlen(key1.data);
|
||||
key1.data = (void *)&pSmaCfg->indexUid;
|
||||
key1.size = sizeof(pSmaCfg->indexUid);
|
||||
|
||||
tEncodeTSma(&pBuf, pSmaCfg);
|
||||
qBuf = pBuf;
|
||||
tEncodeTSma(&qBuf, pSmaCfg);
|
||||
|
||||
value1.data = buf;
|
||||
value1.size = POINTER_DISTANCE(pBuf, buf);
|
||||
value1.data = pBuf;
|
||||
value1.size = POINTER_DISTANCE(qBuf, pBuf);
|
||||
value1.app_data = pSmaCfg;
|
||||
}
|
||||
|
||||
|
@ -609,7 +615,7 @@ STbCfg *metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid) {
|
|||
return pTbCfg;
|
||||
}
|
||||
|
||||
STSma *metaGetSmaInfoByName(SMeta *pMeta, const char *indexName) {
|
||||
STSma *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid) {
|
||||
STSma * pCfg = NULL;
|
||||
SMetaDB *pDB = pMeta->pDB;
|
||||
DBT key = {0};
|
||||
|
@ -617,8 +623,8 @@ STSma *metaGetSmaInfoByName(SMeta *pMeta, const char *indexName) {
|
|||
int ret;
|
||||
|
||||
// Set key/value
|
||||
key.data = (void *)indexName;
|
||||
key.size = strlen(indexName);
|
||||
key.data = (void *)&indexUid;
|
||||
key.size = sizeof(indexUid);
|
||||
|
||||
// Query
|
||||
metaDBRLock(pDB);
|
||||
|
@ -634,7 +640,10 @@ STSma *metaGetSmaInfoByName(SMeta *pMeta, const char *indexName) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
tDecodeTSma(value.data, pCfg);
|
||||
if (tDecodeTSma(value.data, pCfg) == NULL) {
|
||||
tfree(pCfg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pCfg;
|
||||
}
|
||||
|
@ -871,7 +880,7 @@ const char *metaSmaCursorNext(SMSmaCursor *pCur) {
|
|||
}
|
||||
}
|
||||
|
||||
STSmaWrapper *metaGetSmaInfoByUid(SMeta *pMeta, tb_uid_t uid) {
|
||||
STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) {
|
||||
STSmaWrapper *pSW = NULL;
|
||||
|
||||
pSW = calloc(sizeof(*pSW), 1);
|
||||
|
|
|
@ -19,22 +19,20 @@
|
|||
#define SMA_STORAGE_SPLIT_HOURS 24
|
||||
#define SMA_KEY_LEN 18 // tableUid_colId_TSKEY 8+2+8
|
||||
|
||||
#define SMA_STORE_SINGLE_BLOCKS // store SMA data by single block or multiple blocks
|
||||
|
||||
#define SMA_STATE_HASH_SLOT 4
|
||||
#define SMA_STATE_ITEM_HASH_SLOT 32
|
||||
|
||||
#define SMA_TEST_INDEX_NAME "smaTestIndexName" // TODO: just for test
|
||||
#define SMA_TEST_INDEX_UID 123456 // TODO: just for test
|
||||
typedef enum {
|
||||
SMA_STORAGE_LEVEL_TSDB = 0, // store TSma in dir e.g. vnode${N}/tsdb/.tsma
|
||||
SMA_STORAGE_LEVEL_DFILESET = 1 // store TSma in file e.g. vnode${N}/tsdb/v2f1900.tsma.${sma_index_name}
|
||||
SMA_STORAGE_LEVEL_TSDB = 0, // use days of self-defined e.g. vnode${N}/tsdb/tsma/sma_index_uid/v2t200.dat
|
||||
SMA_STORAGE_LEVEL_DFILESET = 1 // use days of TS data e.g. vnode${N}/tsdb/rsma/sma_index_uid/v2r200.dat
|
||||
} ESmaStorageLevel;
|
||||
|
||||
typedef struct {
|
||||
STsdb * pTsdb;
|
||||
char * pDFile; // TODO: use the real DFile type, not char*
|
||||
int32_t interval; // interval with the precision of DB
|
||||
int32_t blockSize; // size of SMA block item
|
||||
// TODO
|
||||
} STSmaWriteH;
|
||||
|
||||
|
@ -62,6 +60,7 @@ typedef struct {
|
|||
*/
|
||||
int8_t state; // ETsdbSmaStat
|
||||
SHashObj *expiredWindows; // key: skey of time window, value: N/A
|
||||
STSma * pSma;
|
||||
} SSmaStatItem;
|
||||
|
||||
struct SSmaStat {
|
||||
|
@ -69,20 +68,18 @@ struct SSmaStat {
|
|||
};
|
||||
|
||||
// declaration of static functions
|
||||
static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, STSma *param, STSmaData *pData);
|
||||
static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, STSma *param, STSmaData *pData);
|
||||
static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, STSmaDataWrapper *pData);
|
||||
static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, STSmaDataWrapper *pData);
|
||||
static int32_t tsdbJudgeStorageLevel(int64_t interval, int8_t intervalUnit);
|
||||
static int32_t tsdbInsertTSmaDataSection(STSmaWriteH *pSmaH, STSmaData *pData, int32_t sectionDataLen, int32_t nBlocks);
|
||||
static int32_t tsdbInsertTSmaDataSection(STSmaWriteH *pSmaH, STSmaDataWrapper *pData);
|
||||
static int32_t tsdbInsertTSmaBlocks(void *bTree, const char *smaKey, const char *pData, int32_t dataLen);
|
||||
static int32_t tsdbTSmaDataSplit(STSmaWriteH *pSmaH, STSma *param, STSmaData *pData, int32_t days, int32_t nOffset,
|
||||
int32_t fid, int32_t *nSmaBlocks);
|
||||
static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit, int8_t precision);
|
||||
static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, STSma *param, STSmaData *pData, int32_t storageLevel,
|
||||
int32_t fid);
|
||||
|
||||
static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, STSma *param, STSmaData *pData);
|
||||
static int32_t tsdbInitTSmaFile(STSmaReadH *pReadH, STSma *param, STimeWindow *queryWin);
|
||||
static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, STSma *param, STimeWindow *queryWin);
|
||||
static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit, int8_t precision);
|
||||
static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData, int32_t storageLevel, int32_t fid);
|
||||
|
||||
static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, STSmaDataWrapper *pData);
|
||||
static int32_t tsdbInitTSmaFile(STSmaReadH *pReadH, STimeWindow *queryWin);
|
||||
static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, STimeWindow *queryWin);
|
||||
|
||||
static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat) {
|
||||
ASSERT(pSmaStat != NULL);
|
||||
|
@ -133,10 +130,10 @@ int32_t tsdbDestroySmaState(SSmaStat *pSmaStat) {
|
|||
// TODO: use taosHashSetFreeFp when taosHashSetFreeFp is ready.
|
||||
SSmaStatItem *item = taosHashIterate(pSmaStat->smaStatItems, NULL);
|
||||
while (item != NULL) {
|
||||
tfree(item->pSma);
|
||||
taosHashCleanup(item->expiredWindows);
|
||||
item = taosHashIterate(pSmaStat->smaStatItems, item);
|
||||
}
|
||||
|
||||
taosHashCleanup(pSmaStat->smaStatItems);
|
||||
free(pSmaStat);
|
||||
}
|
||||
|
@ -154,9 +151,13 @@ int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, char *msg) {
|
|||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
tsdbInitSmaStat(&pTsdb->pSmaStat); // lazy mode
|
||||
// lazy mode
|
||||
if (tsdbInitSmaStat(&pTsdb->pSmaStat) != TSDB_CODE_SUCCESS) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
// 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;
|
||||
TSKEY expiredWindows[SMA_TEST_EXPIRED_WINDOW_SIZE];
|
||||
|
@ -169,14 +170,24 @@ int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, char *msg) {
|
|||
SHashObj *pItemsHash = pTsdb->pSmaStat->smaStatItems;
|
||||
|
||||
SSmaStatItem *pItem = (SSmaStatItem *)taosHashGet(pItemsHash, indexName, strlen(indexName));
|
||||
if (!pItem) {
|
||||
if (pItem == NULL) {
|
||||
pItem = tsdbNewSmaStatItem(TSDB_SMA_STAT_EXPIRED); // TODO use the real state
|
||||
if (!pItem) {
|
||||
if (pItem == NULL) {
|
||||
// Response to stream computing: OOM
|
||||
// For query, if the indexName not found, the TSDB should tell query module to query raw TS data.
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
// cache smaMeta
|
||||
STSma *pSma = metaGetSmaInfoByIndex(pTsdb->pMeta, indexUid);
|
||||
if (pSma == NULL) {
|
||||
taosHashCleanup(pItem->expiredWindows);
|
||||
free(pItem);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
pItem->pSma = pSma;
|
||||
|
||||
// TODO: change indexName to indexUid
|
||||
if (taosHashPut(pItemsHash, indexName, strnlen(indexName, TSDB_INDEX_NAME_LEN), &pItem, sizeof(pItem)) != 0) {
|
||||
// If error occurs during put smaStatItem, free the resources of pItem
|
||||
taosHashCleanup(pItem->expiredWindows);
|
||||
|
@ -195,6 +206,7 @@ int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, char *msg) {
|
|||
// 2) This would solve the inconsistency to some extent, but not completely, unless we record all expired
|
||||
// windows failed to put into hash table.
|
||||
taosHashCleanup(pItem->expiredWindows);
|
||||
tfree(pItem->pSma);
|
||||
taosHashRemove(pItemsHash, indexName, sizeof(indexName));
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
@ -203,19 +215,21 @@ int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, char *msg) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t tsdbResetExpiredWindow(STsdb *pTsdb, const char *indexName, void *timeWindow) {
|
||||
static int32_t tsdbResetExpiredWindow(STsdb *pTsdb, int64_t indexUid, TSKEY skey) {
|
||||
SSmaStatItem *pItem = NULL;
|
||||
|
||||
if (pTsdb->pSmaStat && pTsdb->pSmaStat->smaStatItems) {
|
||||
pItem = (SSmaStatItem *)taosHashGet(pTsdb->pSmaStat->smaStatItems, indexName, strlen(indexName));
|
||||
pItem = (SSmaStatItem *)taosHashGet(pTsdb->pSmaStat->smaStatItems, &indexUid, sizeof(indexUid));
|
||||
}
|
||||
|
||||
if (pItem != NULL) {
|
||||
// TODO: reset time windows for the sma data blocks
|
||||
while (true) {
|
||||
TSKEY thisWindow = 0;
|
||||
taosHashRemove(pItem->expiredWindows, &thisWindow, sizeof(thisWindow));
|
||||
// TODO: reset time window for the sma data blocks
|
||||
if (taosHashRemove(pItem->expiredWindows, &skey, sizeof(TSKEY)) != 0) {
|
||||
// error handling
|
||||
}
|
||||
|
||||
} else {
|
||||
// error handling
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -277,7 +291,7 @@ static int32_t tsdbJudgeStorageLevel(int64_t interval, int8_t intervalUnit) {
|
|||
*/
|
||||
static int32_t tsdbInsertTSmaBlocks(void *bTree, const char *smaKey, const char *pData, int32_t dataLen) {
|
||||
// TODO: insert sma data blocks into B+Tree
|
||||
printf("insert sma data blocks into B+Tree: smaKey %" PRIx64 "-%" PRIu16 "-%" PRIx64 ", dataLen %d\n",
|
||||
tsdbDebug("insert sma data blocks into B+Tree: smaKey %" PRIx64 "-%" PRIu16 "-%" PRIx64 ", dataLen %d",
|
||||
*(uint64_t *)smaKey, *(uint16_t *)POINTER_SHIFT(smaKey, 8), *(int64_t *)POINTER_SHIFT(smaKey, 10), dataLen);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -360,85 +374,60 @@ static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit
|
|||
* @param nBlocks The nBlocks with the same fid since nOffset.
|
||||
* @return int32_t
|
||||
*/
|
||||
static int32_t tsdbInsertTSmaDataSection(STSmaWriteH *pSmaH, STSmaData *pData, int32_t nOffset, int32_t nBlocks) {
|
||||
static int32_t tsdbInsertTSmaDataSection(STSmaWriteH *pSmaH, STSmaDataWrapper *pData) {
|
||||
STsdb *pTsdb = pSmaH->pTsdb;
|
||||
|
||||
TASSERT(pData->colIds != NULL);
|
||||
tsdbDebug("tsdbInsertTSmaDataSection: index %" PRIi64 ", skey %" PRIi64, pData->indexUid, pData->skey);
|
||||
|
||||
tsdbDebug("tsdbInsertTSmaDataSection: nOffset %d, nBlocks %d", nOffset, nBlocks);
|
||||
printf("tsdbInsertTSmaDataSection: nOffset %d, nBlocks %d\n", nOffset, nBlocks);
|
||||
// TODO: check the data integrity
|
||||
|
||||
int32_t colDataLen = pData->dataLen / pData->numOfColIds;
|
||||
int32_t sectionDataLen = pSmaH->blockSize * nBlocks;
|
||||
void *bTree = pSmaH->pDFile;
|
||||
|
||||
for (col_id_t i = 0; i < pData->numOfColIds; ++i) {
|
||||
// param: pointer of B+Tree, key, value, dataLen
|
||||
void *bTree = pSmaH->pDFile;
|
||||
#ifndef SMA_STORE_SINGLE_BLOCKS
|
||||
// save tSma data blocks as a whole
|
||||
char smaKey[SMA_KEY_LEN] = {0};
|
||||
void *pSmaKey = &smaKey;
|
||||
tsdbEncodeTSmaKey(pData->tableUid, *(pData->colIds + i), pData->tsWindow.skey + nOffset * pSmaH->interval,
|
||||
(void **)&pSmaKey);
|
||||
if (tsdbInsertTSmaBlocks(bTree, smaKey, pData->data + i * colDataLen + nOffset * pSmaH->blockSize, sectionDataLen) <
|
||||
0) {
|
||||
tsdbWarn("vgId:%d insert tSma blocks failed since %s", REPO_ID(pTsdb), tstrerror(terrno));
|
||||
int32_t len = 0;
|
||||
while (true) {
|
||||
if (len >= pData->dataLen) {
|
||||
break;
|
||||
}
|
||||
#else
|
||||
// save tSma data blocks separately
|
||||
for (int32_t n = 0; n < nBlocks; ++n) {
|
||||
char smaKey[SMA_KEY_LEN] = {0};
|
||||
void *pSmaKey = &smaKey;
|
||||
tsdbEncodeTSmaKey(pData->tableUid, *(pData->colIds + i), pData->tsWindow.skey + (nOffset + n) * pSmaH->interval,
|
||||
(void **)&pSmaKey);
|
||||
if (tsdbInsertTSmaBlocks(bTree, smaKey, pData->data + i * colDataLen + (nOffset + n) * pSmaH->blockSize,
|
||||
pSmaH->blockSize) < 0) {
|
||||
assert(pData->dataLen > 0);
|
||||
STSmaTbData *pTbData = (STSmaTbData *)POINTER_SHIFT(pData->data, len);
|
||||
|
||||
int32_t tbLen = 0;
|
||||
while (true) {
|
||||
if (tbLen >= pTbData->dataLen) {
|
||||
break;
|
||||
}
|
||||
assert(pTbData->dataLen > 0);
|
||||
STSmaColData *pColData = (STSmaColData *)POINTER_SHIFT(pTbData->data, tbLen);
|
||||
char smaKey[SMA_KEY_LEN] = {0};
|
||||
void * pSmaKey = &smaKey;
|
||||
#if 0
|
||||
printf("tsdbInsertTSmaDataSection: index %" PRIi64 ", skey %" PRIi64 " table[%" PRIi64 "]col[%" PRIu16 "]\n",
|
||||
pData->indexUid, pData->skey, pTbData->tableUid, pColData->colId);
|
||||
#endif
|
||||
tsdbEncodeTSmaKey(pTbData->tableUid, pColData->colId, pData->skey, (void **)&pSmaKey);
|
||||
if (tsdbInsertTSmaBlocks(bTree, smaKey, pColData->data, pColData->blockSize) < 0) {
|
||||
tsdbWarn("vgId:%d insert tSma blocks failed since %s", REPO_ID(pTsdb), tstrerror(terrno));
|
||||
}
|
||||
tbLen += (sizeof(STSmaColData) + pColData->blockSize);
|
||||
}
|
||||
#endif
|
||||
len += (sizeof(STSmaTbData) + pTbData->dataLen);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, STSma *param, STSmaData *pData) {
|
||||
static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, STSmaDataWrapper *pData) {
|
||||
pSmaH->pTsdb = pTsdb;
|
||||
pSmaH->interval = tsdbGetIntervalByPrecision(param->interval, param->intervalUnit, REPO_CFG(pTsdb)->precision);
|
||||
// pSmaH->blockSize = param->numOfFuncIds * sizeof(int64_t);
|
||||
pSmaH->interval = tsdbGetIntervalByPrecision(pData->interval, pData->intervalUnit, REPO_CFG(pTsdb)->precision);
|
||||
}
|
||||
|
||||
static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, STSma *param, STSmaData *pData, int32_t storageLevel,
|
||||
int32_t fid) {
|
||||
static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData, int32_t storageLevel, int32_t fid) {
|
||||
// TODO
|
||||
pSmaH->pDFile = "tSma_interval_file_name";
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
} /**
|
||||
* @brief Split the sma data blocks by fid.
|
||||
*
|
||||
* @param pSmaH
|
||||
* @param param
|
||||
* @param pData
|
||||
* @param nOffset
|
||||
* @param fid
|
||||
* @param nSmaBlocks
|
||||
* @return int32_t
|
||||
*/
|
||||
static int32_t tsdbTSmaDataSplit(STSmaWriteH *pSmaH, STSma *param, STSmaData *pData, int32_t days, int32_t nOffset,
|
||||
int32_t fid, int32_t *nSmaBlocks) {
|
||||
STsdbCfg *pCfg = REPO_CFG(pSmaH->pTsdb);
|
||||
}
|
||||
|
||||
// TODO: use binary search
|
||||
for (int32_t n = nOffset + 1; n < pData->numOfBlocks; ++n) {
|
||||
// TODO: The tsWindow.skey should use the precision of DB.
|
||||
int32_t tFid = (int32_t)(TSDB_KEY_FID(pData->tsWindow.skey + pSmaH->interval * n, days, pCfg->precision));
|
||||
if (tFid > fid) {
|
||||
*nSmaBlocks = n - nOffset;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Insert/Update Time-range-wise SMA data.
|
||||
|
@ -449,124 +438,81 @@ static int32_t tsdbTSmaDataSplit(STSmaWriteH *pSmaH, STSma *param, STSmaData *pD
|
|||
* - The destination file of one data block for some interval is determined by its start TS key.
|
||||
*
|
||||
* @param pTsdb
|
||||
* @param param
|
||||
* @param pData
|
||||
* @param msg
|
||||
* @return int32_t
|
||||
*/
|
||||
int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, STSma *param, STSmaData *pData) {
|
||||
int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) {
|
||||
STsdbCfg * pCfg = REPO_CFG(pTsdb);
|
||||
STSmaData * curData = pData;
|
||||
STSmaDataWrapper *pData = (STSmaDataWrapper *)msg;
|
||||
STSmaWriteH tSmaH = {0};
|
||||
|
||||
tsdbInitTSmaWriteH(&tSmaH, pTsdb, param, pData);
|
||||
tsdbInitTSmaWriteH(&tSmaH, pTsdb, pData);
|
||||
|
||||
if (pData->numOfBlocks <= 0 || pData->numOfColIds <= 0 || pData->dataLen <= 0) {
|
||||
if (pData->dataLen <= 0) {
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
// Step 1: Judge the storage level
|
||||
int32_t storageLevel = tsdbJudgeStorageLevel(param->interval, param->intervalUnit);
|
||||
int32_t storageLevel = tsdbJudgeStorageLevel(pData->interval, pData->intervalUnit);
|
||||
int32_t daysPerFile = storageLevel == SMA_STORAGE_LEVEL_TSDB ? SMA_STORAGE_TSDB_DAYS : pCfg->daysPerFile;
|
||||
|
||||
// Step 2: Set the DFile for storage of SMA index, and iterate/split the TSma data and store to B+Tree index file
|
||||
// - Set and open the DFile or the B+Tree file
|
||||
|
||||
int32_t minFid = (int32_t)(TSDB_KEY_FID(pData->tsWindow.skey, daysPerFile, pCfg->precision));
|
||||
int32_t maxFid = (int32_t)(TSDB_KEY_FID(pData->tsWindow.ekey, daysPerFile, pCfg->precision));
|
||||
int32_t fid = (int32_t)(TSDB_KEY_FID(pData->skey, daysPerFile, pCfg->precision));
|
||||
|
||||
if (minFid == maxFid) {
|
||||
// Save all the TSma data to one file
|
||||
// TODO: tsdbStartTSmaCommit();
|
||||
tsdbSetTSmaDataFile(&tSmaH, param, pData, storageLevel, minFid);
|
||||
tsdbInsertTSmaDataSection(&tSmaH, pData, 0, pData->numOfBlocks);
|
||||
// TODO:tsdbEndTSmaCommit();
|
||||
} else if (minFid < maxFid) {
|
||||
// Split the TSma data and save to multiple files. As there is limit for the span, it can't span more than 2 files
|
||||
// actually.
|
||||
// TODO: tsdbStartTSmaCommit();
|
||||
int32_t tFid = minFid;
|
||||
int32_t nOffset = 0;
|
||||
int32_t nSmaBlocks = 0;
|
||||
do {
|
||||
tsdbTSmaDataSplit(&tSmaH, param, pData, daysPerFile, nOffset, tFid, &nSmaBlocks);
|
||||
tsdbSetTSmaDataFile(&tSmaH, param, pData, storageLevel, tFid);
|
||||
if (tsdbInsertTSmaDataSection(&tSmaH, pData, nOffset, nSmaBlocks) < 0) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
++tFid;
|
||||
nOffset += nSmaBlocks;
|
||||
|
||||
if (tFid == maxFid) {
|
||||
tsdbSetTSmaDataFile(&tSmaH, param, pData, storageLevel, tFid);
|
||||
tsdbInsertTSmaDataSection(&tSmaH, pData, nOffset, pData->numOfBlocks - nOffset);
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
|
||||
// TODO:tsdbEndTSmaCommit();
|
||||
} else {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
// Save all the TSma data to one file
|
||||
// TODO: tsdbStartTSmaCommit();
|
||||
tsdbSetTSmaDataFile(&tSmaH, pData, storageLevel, fid);
|
||||
tsdbInsertTSmaDataSection(&tSmaH, pData);
|
||||
// TODO:tsdbEndTSmaCommit();
|
||||
|
||||
// reset the SSmaStat
|
||||
tsdbResetExpiredWindow(pTsdb, param->indexName, &pData->tsWindow);
|
||||
tsdbResetExpiredWindow(pTsdb, pData->indexUid, pData->skey);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t tsdbSetRSmaDataFile(STSmaWriteH *pSmaH, SRSma *param, STSmaData *pData, int32_t fid) {
|
||||
static int32_t tsdbSetRSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData, int32_t fid) {
|
||||
// TODO
|
||||
pSmaH->pDFile = "rSma_interval_file_name";
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, SRSma *param, STSmaData *pData) {
|
||||
int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, char *msg) {
|
||||
STsdbCfg * pCfg = REPO_CFG(pTsdb);
|
||||
STSma * tParam = ¶m->tsma;
|
||||
STSmaData * curData = pData;
|
||||
STSmaDataWrapper *pData = (STSmaDataWrapper *)msg;
|
||||
STSmaWriteH tSmaH = {0};
|
||||
|
||||
tsdbInitTSmaWriteH(&tSmaH, pTsdb, tParam, pData);
|
||||
tsdbInitTSmaWriteH(&tSmaH, pTsdb, pData);
|
||||
|
||||
int32_t nSmaBlocks = pData->numOfBlocks;
|
||||
int32_t colDataLen = pData->dataLen / nSmaBlocks;
|
||||
|
||||
// Step 2.2: Storage of SMA_STORAGE_LEVEL_DFILESET
|
||||
// TODO: Use the daysPerFile for rSma data, not for TS data.
|
||||
// TODO: The lifecycle of rSma data should be processed like the TS data files.
|
||||
int32_t minFid = (int32_t)(TSDB_KEY_FID(pData->tsWindow.skey, pCfg->daysPerFile, pCfg->precision));
|
||||
int32_t maxFid = (int32_t)(TSDB_KEY_FID(pData->tsWindow.ekey, pCfg->daysPerFile, pCfg->precision));
|
||||
|
||||
if (minFid == maxFid) {
|
||||
// Save all the TSma data to one file
|
||||
tsdbSetRSmaDataFile(&tSmaH, param, pData, minFid);
|
||||
// TODO: tsdbStartTSmaCommit();
|
||||
tsdbInsertTSmaDataSection(&tSmaH, pData, colDataLen, nSmaBlocks);
|
||||
// TODO:tsdbEndTSmaCommit();
|
||||
} else if (minFid < maxFid) {
|
||||
// Split the TSma data and save to multiple files. As there is limit for the span, it can't span more than 2 files
|
||||
// actually.
|
||||
// TODO: tsdbStartTSmaCommit();
|
||||
int32_t tmpFid = 0;
|
||||
int32_t step = 0;
|
||||
for (int32_t n = 0; n < pData->numOfBlocks; ++n) {
|
||||
}
|
||||
tsdbInsertTSmaDataSection(&tSmaH, pData, colDataLen, nSmaBlocks);
|
||||
// TODO:tsdbEndTSmaCommit();
|
||||
} else {
|
||||
if (pData->dataLen <= 0) {
|
||||
TASSERT(0);
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
// reset the SSmaStat
|
||||
tsdbResetExpiredWindow(pTsdb, param->tsma.indexName, &pData->tsWindow);
|
||||
// Step 1: Judge the storage level
|
||||
int32_t storageLevel = tsdbJudgeStorageLevel(pData->interval, pData->intervalUnit);
|
||||
int32_t daysPerFile = storageLevel == SMA_STORAGE_LEVEL_TSDB ? SMA_STORAGE_TSDB_DAYS : pCfg->daysPerFile;
|
||||
|
||||
// Step 2: Set the DFile for storage of SMA index, and iterate/split the TSma data and store to B+Tree index file
|
||||
// - Set and open the DFile or the B+Tree file
|
||||
|
||||
int32_t fid = (int32_t)(TSDB_KEY_FID(pData->skey, daysPerFile, pCfg->precision));
|
||||
|
||||
// Save all the TSma data to one file
|
||||
// TODO: tsdbStartTSmaCommit();
|
||||
tsdbSetTSmaDataFile(&tSmaH, pData, storageLevel, fid);
|
||||
tsdbInsertTSmaDataSection(&tSmaH, pData);
|
||||
// TODO:tsdbEndTSmaCommit();
|
||||
|
||||
// reset the SSmaStat
|
||||
tsdbResetExpiredWindow(pTsdb, pData->indexUid, pData->skey);
|
||||
|
||||
// Step 4: finish
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -579,9 +525,9 @@ int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, SRSma *param, STSmaData *pData) {
|
|||
* @param pData
|
||||
* @return int32_t
|
||||
*/
|
||||
static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, STSma *param, STSmaData *pData) {
|
||||
static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, STSmaDataWrapper *pData) {
|
||||
pSmaH->pTsdb = pTsdb;
|
||||
pSmaH->interval = tsdbGetIntervalByPrecision(param->interval, param->intervalUnit, REPO_CFG(pTsdb)->precision);
|
||||
pSmaH->interval = tsdbGetIntervalByPrecision(pData->interval, pData->intervalUnit, REPO_CFG(pTsdb)->precision);
|
||||
// pSmaH->blockSize = param->numOfFuncIds * sizeof(int64_t);
|
||||
}
|
||||
|
||||
|
@ -593,8 +539,8 @@ static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, STSma *param,
|
|||
* @param queryWin
|
||||
* @return int32_t
|
||||
*/
|
||||
static int32_t tsdbInitTSmaFile(STSmaReadH *pReadH, STSma *param, STimeWindow *queryWin) {
|
||||
int32_t storageLevel = tsdbJudgeStorageLevel(param->interval, param->intervalUnit);
|
||||
static int32_t tsdbInitTSmaFile(STSmaReadH *pReadH, STimeWindow *queryWin) {
|
||||
int32_t storageLevel = 0; //tsdbJudgeStorageLevel(param->interval, param->intervalUnit);
|
||||
int32_t daysPerFile =
|
||||
storageLevel == SMA_STORAGE_LEVEL_TSDB ? SMA_STORAGE_TSDB_DAYS : REPO_CFG(pReadH->pTsdb)->daysPerFile;
|
||||
pReadH->storageLevel = storageLevel;
|
||||
|
@ -611,8 +557,8 @@ static int32_t tsdbInitTSmaFile(STSmaReadH *pReadH, STSma *param, STimeWindow *q
|
|||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, STSma *param, STimeWindow *queryWin) {
|
||||
SArray *smaFs = pReadH->pTsdb->fs->cstatus->smaf;
|
||||
static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, STimeWindow *queryWin) {
|
||||
SArray *smaFs = pReadH->pTsdb->fs->cstatus->sf;
|
||||
int32_t nSmaFs = taosArrayGetSize(smaFs);
|
||||
|
||||
pReadH->pDFile = NULL;
|
||||
|
@ -646,10 +592,9 @@ static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, STSma *param, STimeWindow
|
|||
* @param nMaxResult The query invoker should control the nMaxResult need to return to avoid OOM.
|
||||
* @return int32_t
|
||||
*/
|
||||
int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSma *param, STSmaData *pData, STimeWindow *queryWin, int32_t nMaxResult) {
|
||||
const char *indexName = param->indexName;
|
||||
|
||||
SSmaStatItem *pItem = (SSmaStatItem *)taosHashGet(pTsdb->pSmaStat->smaStatItems, indexName, strlen(indexName));
|
||||
int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, STimeWindow *queryWin, int32_t nMaxResult) {
|
||||
SSmaStatItem *pItem =
|
||||
(SSmaStatItem *)taosHashGet(pTsdb->pSmaStat->smaStatItems, &pData->indexUid, sizeof(pData->indexUid));
|
||||
if (pItem == NULL) {
|
||||
// mark all window as expired and notify query module to query raw TS data.
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -664,9 +609,9 @@ int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSma *param, STSmaData *pData, STimeW
|
|||
}
|
||||
|
||||
STSmaReadH tReadH = {0};
|
||||
tsdbInitTSmaReadH(&tReadH, pTsdb, param, pData);
|
||||
tsdbInitTSmaReadH(&tReadH, pTsdb, pData);
|
||||
|
||||
tsdbInitTSmaFile(&tReadH, param, queryWin);
|
||||
tsdbInitTSmaFile(&tReadH, queryWin);
|
||||
|
||||
int32_t nResult = 0;
|
||||
int64_t lastKey = 0;
|
||||
|
@ -677,7 +622,7 @@ int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSma *param, STSmaData *pData, STimeW
|
|||
}
|
||||
|
||||
// set and open the file according to the STSma param
|
||||
if (tsdbSetAndOpenTSmaFile(&tReadH, param, queryWin)) {
|
||||
if (tsdbSetAndOpenTSmaFile(&tReadH, queryWin)) {
|
||||
char bTree[100] = "\0";
|
||||
while (strncmp(bTree, "has more nodes", 100) == 0) {
|
||||
if (nResult >= nMaxResult) {
|
||||
|
@ -694,6 +639,7 @@ int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSma *param, STSmaData *pData, STimeW
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* @brief Get the start TS key of the last data block of one interval/sliding.
|
||||
*
|
||||
|
@ -704,7 +650,7 @@ int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSma *param, STSmaData *pData, STimeW
|
|||
* 1) Return 0 and fill the result if the check procedure is normal;
|
||||
* 2) Return -1 if error occurs during the check procedure.
|
||||
*/
|
||||
int32_t tsdbGetTSmaStatus(STsdb *pTsdb, STSma *param, void *result) {
|
||||
int32_t tsdbGetTSmaStatus(STsdb *pTsdb, void *smaIndex, void *result) {
|
||||
const char *procedure = "";
|
||||
if (strncmp(procedure, "get the start TS key of the last data block", 100) != 0) {
|
||||
return -1;
|
||||
|
@ -721,9 +667,10 @@ int32_t tsdbGetTSmaStatus(STsdb *pTsdb, STSma *param, void *result) {
|
|||
* @param pWin
|
||||
* @return int32_t
|
||||
*/
|
||||
int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin) {
|
||||
int32_t tsdbRemoveTSmaData(STsdb *pTsdb, void *smaIndex, STimeWindow *pWin) {
|
||||
// for ("tSmaFiles of param-interval-sliding between pWin") {
|
||||
// // remove the tSmaFile
|
||||
// }
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -39,13 +39,13 @@ int tsdbInsertData(STsdb *pTsdb, SSubmitReq *pMsg, SSubmitRsp *pRsp) {
|
|||
*
|
||||
* @param pTsdb
|
||||
* @param param
|
||||
* @param pData
|
||||
* @param msg
|
||||
* @return int32_t
|
||||
* TODO: Who is responsible for resource allocate and release?
|
||||
*/
|
||||
int32_t tsdbInsertTSmaData(STsdb *pTsdb, STSma *param, STSmaData *pData) {
|
||||
int32_t tsdbInsertTSmaData(STsdb *pTsdb, char *msg) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
if ((code = tsdbInsertTSmaDataImpl(pTsdb, param, pData)) < 0) {
|
||||
if ((code = tsdbInsertTSmaDataImpl(pTsdb, msg)) < 0) {
|
||||
tsdbWarn("vgId:%d insert tSma data failed since %s", REPO_ID(pTsdb), tstrerror(terrno));
|
||||
}
|
||||
return code;
|
||||
|
@ -56,12 +56,12 @@ int32_t tsdbInsertTSmaData(STsdb *pTsdb, STSma *param, STSmaData *pData) {
|
|||
*
|
||||
* @param pTsdb
|
||||
* @param param
|
||||
* @param pData
|
||||
* @param msg
|
||||
* @return int32_t
|
||||
*/
|
||||
int32_t tsdbInsertRSmaData(STsdb *pTsdb, SRSma *param, STSmaData *pData) {
|
||||
int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
if ((code = tsdbInsertRSmaDataImpl(pTsdb, param, pData)) < 0) {
|
||||
if ((code = tsdbInsertRSmaDataImpl(pTsdb, msg)) < 0) {
|
||||
tsdbWarn("vgId:%d insert rSma data failed since %s", REPO_ID(pTsdb), tstrerror(terrno));
|
||||
}
|
||||
return code;
|
||||
|
|
|
@ -43,20 +43,8 @@ TEST(testCase, tSmaEncodeDecodeTest) {
|
|||
tSma.sliding = 0;
|
||||
tstrncpy(tSma.indexName, "sma_index_test", TSDB_INDEX_NAME_LEN);
|
||||
tstrncpy(tSma.timezone, "Asia/Shanghai", TD_TIMEZONE_LEN);
|
||||
tSma.indexUid = 2345678910;
|
||||
tSma.tableUid = 1234567890;
|
||||
tSma.nFuncColIds = 5;
|
||||
tSma.funcColIds = (SFuncColIds *)calloc(tSma.nFuncColIds, sizeof(SFuncColIds));
|
||||
ASSERT(tSma.funcColIds != NULL);
|
||||
for (int32_t n = 0; n < tSma.nFuncColIds; ++n) {
|
||||
SFuncColIds *funcColIds = tSma.funcColIds + n;
|
||||
funcColIds->funcId = n;
|
||||
funcColIds->nColIds = 10;
|
||||
funcColIds->colIds = (col_id_t *)calloc(funcColIds->nColIds, sizeof(col_id_t));
|
||||
ASSERT(funcColIds->colIds != NULL);
|
||||
for (int32_t i = 0; i < funcColIds->nColIds; ++i) {
|
||||
*(funcColIds->colIds + i) = (i + PRIMARYKEY_TIMESTAMP_COL_ID);
|
||||
}
|
||||
}
|
||||
|
||||
STSmaWrapper tSmaWrapper = {.number = 1, .tSma = &tSma};
|
||||
uint32_t bufLen = tEncodeTSmaWrapper(NULL, &tSmaWrapper);
|
||||
|
@ -85,35 +73,31 @@ TEST(testCase, tSmaEncodeDecodeTest) {
|
|||
EXPECT_EQ(pSma->slidingUnit, qSma->slidingUnit);
|
||||
EXPECT_STRCASEEQ(pSma->indexName, qSma->indexName);
|
||||
EXPECT_STRCASEEQ(pSma->timezone, qSma->timezone);
|
||||
EXPECT_EQ(pSma->nFuncColIds, qSma->nFuncColIds);
|
||||
EXPECT_EQ(pSma->indexUid, qSma->indexUid);
|
||||
EXPECT_EQ(pSma->tableUid, qSma->tableUid);
|
||||
EXPECT_EQ(pSma->interval, qSma->interval);
|
||||
EXPECT_EQ(pSma->sliding, qSma->sliding);
|
||||
EXPECT_EQ(pSma->exprLen, qSma->exprLen);
|
||||
EXPECT_STRCASEEQ(pSma->expr, qSma->expr);
|
||||
EXPECT_EQ(pSma->tagsFilterLen, qSma->tagsFilterLen);
|
||||
EXPECT_STRCASEEQ(pSma->tagsFilter, qSma->tagsFilter);
|
||||
for (uint32_t j = 0; j < pSma->nFuncColIds; ++j) {
|
||||
SFuncColIds *pFuncColIds = pSma->funcColIds + j;
|
||||
SFuncColIds *qFuncColIds = qSma->funcColIds + j;
|
||||
EXPECT_EQ(pFuncColIds->funcId, qFuncColIds->funcId);
|
||||
EXPECT_EQ(pFuncColIds->nColIds, qFuncColIds->nColIds);
|
||||
for (uint32_t k = 0; k < pFuncColIds->nColIds; ++k) {
|
||||
EXPECT_EQ(*(pFuncColIds->colIds + k), *(qFuncColIds->colIds + k));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// resource release
|
||||
tdDestroyTSma(&tSma);
|
||||
tdDestroyTSmaWrapper(&dstTSmaWrapper);
|
||||
}
|
||||
|
||||
#if 1
|
||||
TEST(testCase, tSma_DB_Put_Get_Del_Test) {
|
||||
const char * smaIndexName1 = "sma_index_test_1";
|
||||
const char * smaIndexName2 = "sma_index_test_2";
|
||||
const char * timeZone = "Asia/Shanghai";
|
||||
const char * timezone = "Asia/Shanghai";
|
||||
const char * expr = "select count(a,b, top 20), from table interval 1d, sliding 1h;";
|
||||
const char * tagsFilter = "I'm tags filter";
|
||||
const char * smaTestDir = "./smaTest";
|
||||
const uint64_t tbUid = 1234567890;
|
||||
const tb_uid_t tbUid = 1234567890;
|
||||
const int64_t indexUid1 = 2000000001;
|
||||
const int64_t indexUid2 = 2000000002;
|
||||
const uint32_t nCntTSma = 2;
|
||||
// encode
|
||||
STSma tSma = {0};
|
||||
|
@ -122,22 +106,15 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
|
|||
tSma.interval = 1;
|
||||
tSma.slidingUnit = TD_TIME_UNIT_HOUR;
|
||||
tSma.sliding = 0;
|
||||
tSma.indexUid = indexUid1;
|
||||
tstrncpy(tSma.indexName, smaIndexName1, TSDB_INDEX_NAME_LEN);
|
||||
tstrncpy(tSma.timezone, timeZone, TD_TIMEZONE_LEN);
|
||||
tstrncpy(tSma.timezone, timezone, TD_TIMEZONE_LEN);
|
||||
tSma.tableUid = tbUid;
|
||||
tSma.nFuncColIds = 5;
|
||||
tSma.funcColIds = (SFuncColIds *)calloc(tSma.nFuncColIds, sizeof(SFuncColIds));
|
||||
ASSERT(tSma.funcColIds != NULL);
|
||||
for (int32_t n = 0; n < tSma.nFuncColIds; ++n) {
|
||||
SFuncColIds *funcColIds = tSma.funcColIds + n;
|
||||
funcColIds->funcId = n;
|
||||
funcColIds->nColIds = 10;
|
||||
funcColIds->colIds = (col_id_t *)calloc(funcColIds->nColIds, sizeof(col_id_t));
|
||||
ASSERT(funcColIds->colIds != NULL);
|
||||
for (int32_t i = 0; i < funcColIds->nColIds; ++i) {
|
||||
*(funcColIds->colIds + i) = (i + PRIMARYKEY_TIMESTAMP_COL_ID);
|
||||
}
|
||||
}
|
||||
|
||||
tSma.exprLen = strlen(expr);
|
||||
tSma.expr = (char *)calloc(tSma.exprLen + 1, 1);
|
||||
tstrncpy(tSma.expr, expr, tSma.exprLen + 1);
|
||||
|
||||
tSma.tagsFilterLen = strlen(tagsFilter);
|
||||
tSma.tagsFilter = (char *)calloc(tSma.tagsFilterLen + 1, 1);
|
||||
tstrncpy(tSma.tagsFilter, tagsFilter, tSma.tagsFilterLen + 1);
|
||||
|
@ -151,8 +128,9 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
|
|||
pMeta = metaOpen(smaTestDir, pMetaCfg, NULL);
|
||||
assert(pMeta != NULL);
|
||||
// save index 1
|
||||
metaSaveSmaToDB(pMeta, pSmaCfg);
|
||||
EXPECT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0);
|
||||
|
||||
pSmaCfg->indexUid = indexUid2;
|
||||
tstrncpy(pSmaCfg->indexName, smaIndexName2, TSDB_INDEX_NAME_LEN);
|
||||
pSmaCfg->version = 1;
|
||||
pSmaCfg->intervalUnit = TD_TIME_UNIT_HOUR;
|
||||
|
@ -161,24 +139,26 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
|
|||
pSmaCfg->sliding = 5;
|
||||
|
||||
// save index 2
|
||||
metaSaveSmaToDB(pMeta, pSmaCfg);
|
||||
EXPECT_EQ(metaSaveSmaToDB(pMeta, pSmaCfg), 0);
|
||||
|
||||
// get value by indexName
|
||||
STSma *qSmaCfg = NULL;
|
||||
qSmaCfg = metaGetSmaInfoByName(pMeta, smaIndexName1);
|
||||
qSmaCfg = metaGetSmaInfoByIndex(pMeta, indexUid1);
|
||||
assert(qSmaCfg != NULL);
|
||||
printf("name1 = %s\n", qSmaCfg->indexName);
|
||||
printf("timezone1 = %s\n", qSmaCfg->timezone);
|
||||
printf("expr1 = %s\n", qSmaCfg->expr != NULL ? qSmaCfg->expr : "");
|
||||
printf("tagsFilter1 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : "");
|
||||
EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName1);
|
||||
EXPECT_EQ(qSmaCfg->tableUid, tSma.tableUid);
|
||||
tdDestroyTSma(qSmaCfg);
|
||||
tfree(qSmaCfg);
|
||||
|
||||
qSmaCfg = metaGetSmaInfoByName(pMeta, smaIndexName2);
|
||||
qSmaCfg = metaGetSmaInfoByIndex(pMeta, indexUid2);
|
||||
assert(qSmaCfg != NULL);
|
||||
printf("name2 = %s\n", qSmaCfg->indexName);
|
||||
printf("timezone2 = %s\n", qSmaCfg->timezone);
|
||||
printf("expr2 = %s\n", qSmaCfg->expr != NULL ? qSmaCfg->expr : "");
|
||||
printf("tagsFilter2 = %s\n", qSmaCfg->tagsFilter != NULL ? qSmaCfg->tagsFilter : "");
|
||||
EXPECT_STRCASEEQ(qSmaCfg->indexName, smaIndexName2);
|
||||
EXPECT_EQ(qSmaCfg->interval, tSma.interval);
|
||||
|
@ -201,17 +181,21 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
|
|||
metaCloseSmaCurosr(pSmaCur);
|
||||
|
||||
// get wrapper by table uid
|
||||
STSmaWrapper *pSW = metaGetSmaInfoByUid(pMeta, tbUid);
|
||||
STSmaWrapper *pSW = metaGetSmaInfoByTable(pMeta, tbUid);
|
||||
assert(pSW != NULL);
|
||||
EXPECT_EQ(pSW->number, nCntTSma);
|
||||
EXPECT_STRCASEEQ(pSW->tSma->indexName, smaIndexName1);
|
||||
EXPECT_STRCASEEQ(pSW->tSma->timezone, timeZone);
|
||||
EXPECT_STRCASEEQ(pSW->tSma->timezone, timezone);
|
||||
EXPECT_STRCASEEQ(pSW->tSma->expr, expr);
|
||||
EXPECT_STRCASEEQ(pSW->tSma->tagsFilter, tagsFilter);
|
||||
EXPECT_EQ(pSW->tSma->tableUid, tSma.tableUid);
|
||||
EXPECT_EQ(pSW->tSma->indexUid, indexUid1);
|
||||
EXPECT_EQ(pSW->tSma->tableUid, tbUid);
|
||||
EXPECT_STRCASEEQ((pSW->tSma + 1)->indexName, smaIndexName2);
|
||||
EXPECT_STRCASEEQ((pSW->tSma + 1)->timezone, timeZone);
|
||||
EXPECT_STRCASEEQ((pSW->tSma + 1)->timezone, timezone);
|
||||
EXPECT_STRCASEEQ((pSW->tSma + 1)->expr, expr);
|
||||
EXPECT_STRCASEEQ((pSW->tSma + 1)->tagsFilter, tagsFilter);
|
||||
EXPECT_EQ((pSW->tSma + 1)->tableUid, tSma.tableUid);
|
||||
EXPECT_EQ((pSW->tSma + 1)->indexUid, indexUid2);
|
||||
EXPECT_EQ((pSW->tSma + 1)->tableUid, tbUid);
|
||||
|
||||
tdDestroyTSmaWrapper(pSW);
|
||||
tfree(pSW);
|
||||
|
@ -233,44 +217,68 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) {
|
|||
tdDestroyTSma(&tSma);
|
||||
metaClose(pMeta);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
TEST(testCase, tSmaInsertTest) {
|
||||
STSma tSma = {0};
|
||||
STSmaData *pSmaData = NULL;
|
||||
STsdb tsdb = {0};
|
||||
const int64_t indexUid = 2000000002;
|
||||
STSmaDataWrapper *pSmaData = NULL;
|
||||
STsdb tsdb = {0};
|
||||
STsdbCfg * pCfg = &tsdb.config;
|
||||
|
||||
pCfg->daysPerFile = 1;
|
||||
|
||||
// init
|
||||
tSma.intervalUnit = TD_TIME_UNIT_DAY;
|
||||
tSma.interval = 1;
|
||||
tSma.numOfFuncIds = 5; // sum/min/max/avg/last
|
||||
int32_t allocCnt = 0;
|
||||
int32_t allocStep = 40960;
|
||||
int32_t buffer = 4096;
|
||||
void * buf = NULL;
|
||||
EXPECT_EQ(tsdbMakeRoom(&buf, allocStep), 0);
|
||||
int32_t bufSize = taosTSizeof(buf);
|
||||
int32_t numOfTables = 25;
|
||||
col_id_t numOfCols = 4096;
|
||||
EXPECT_GT(numOfCols, 0);
|
||||
|
||||
int32_t blockSize = tSma.numOfFuncIds * sizeof(int64_t);
|
||||
int32_t numOfColIds = 3;
|
||||
int32_t numOfBlocks = 10;
|
||||
pSmaData = (STSmaDataWrapper *)buf;
|
||||
printf(">> allocate [%d] time to %d and addr is %p\n", ++allocCnt, bufSize, pSmaData);
|
||||
pSmaData->skey = 1646987196;
|
||||
pSmaData->interval = 10;
|
||||
pSmaData->intervalUnit = TD_TIME_UNIT_MINUTE;
|
||||
pSmaData->indexUid = indexUid;
|
||||
|
||||
int32_t dataLen = numOfColIds * numOfBlocks * blockSize;
|
||||
int32_t len = sizeof(STSmaDataWrapper);
|
||||
for (int32_t t = 0; t < numOfTables; ++t) {
|
||||
STSmaTbData *pTbData = (STSmaTbData *)POINTER_SHIFT(pSmaData, len);
|
||||
pTbData->tableUid = t;
|
||||
|
||||
pSmaData = (STSmaData *)malloc(sizeof(STSmaData) + dataLen);
|
||||
ASSERT_EQ(pSmaData != NULL, true);
|
||||
pSmaData->tableUid = 3232329230;
|
||||
pSmaData->numOfColIds = numOfColIds;
|
||||
pSmaData->numOfBlocks = numOfBlocks;
|
||||
pSmaData->dataLen = dataLen;
|
||||
pSmaData->tsWindow.skey = 1640000000;
|
||||
pSmaData->tsWindow.ekey = 1645788649;
|
||||
pSmaData->colIds = (col_id_t *)malloc(sizeof(col_id_t) * numOfColIds);
|
||||
ASSERT_EQ(pSmaData->colIds != NULL, true);
|
||||
|
||||
for (int32_t i = 0; i < numOfColIds; ++i) {
|
||||
*(pSmaData->colIds + i) = (i + PRIMARYKEY_TIMESTAMP_COL_ID);
|
||||
int32_t tableDataLen = sizeof(STSmaTbData);
|
||||
for (col_id_t c = 0; c < numOfCols; ++c) {
|
||||
if (bufSize - len - tableDataLen < buffer) {
|
||||
EXPECT_EQ(tsdbMakeRoom(&buf, bufSize + allocStep), 0);
|
||||
pSmaData = (STSmaDataWrapper *)buf;
|
||||
pTbData = (STSmaTbData *)POINTER_SHIFT(pSmaData, len);
|
||||
bufSize = taosTSizeof(buf);
|
||||
printf(">> allocate [%d] time to %d and addr is %p\n", ++allocCnt, bufSize, pSmaData);
|
||||
}
|
||||
STSmaColData *pColData = (STSmaColData *)POINTER_SHIFT(pSmaData, len + tableDataLen);
|
||||
pColData->colId = c + PRIMARYKEY_TIMESTAMP_COL_ID;
|
||||
pColData->blockSize = ((c & 1) == 0) ? 8 : 16;
|
||||
// TODO: fill col data
|
||||
tableDataLen += (sizeof(STSmaColData) + pColData->blockSize);
|
||||
}
|
||||
pTbData->dataLen = (tableDataLen - sizeof(STSmaTbData));
|
||||
len += tableDataLen;
|
||||
// printf("bufSize=%d, len=%d, len of table[%d]=%d\n", bufSize, len, t, tableDataLen);
|
||||
}
|
||||
pSmaData->dataLen = (len - sizeof(STSmaDataWrapper));
|
||||
|
||||
EXPECT_GE(bufSize, pSmaData->dataLen);
|
||||
|
||||
// execute
|
||||
EXPECT_EQ(tsdbInsertTSmaData(&tsdb, &tSma, pSmaData), TSDB_CODE_SUCCESS);
|
||||
EXPECT_EQ(tsdbInsertTSmaData(&tsdb, (char *)pSmaData), TSDB_CODE_SUCCESS);
|
||||
|
||||
// release
|
||||
tdDestroySmaData(pSmaData);
|
||||
taosTZfree(buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -253,6 +253,11 @@ typedef struct STaskIdInfo {
|
|||
char* str;
|
||||
} STaskIdInfo;
|
||||
|
||||
typedef struct STaskBufInfo {
|
||||
int32_t bufSize; // total available buffer size in bytes
|
||||
int32_t remainBuf; // remain buffer size
|
||||
} STaskBufInfo;
|
||||
|
||||
typedef struct SExecTaskInfo {
|
||||
STaskIdInfo id;
|
||||
char* content;
|
||||
|
@ -264,7 +269,8 @@ typedef struct SExecTaskInfo {
|
|||
uint64_t totalRows; // total number of rows
|
||||
STableGroupInfo tableqinfoGroupInfo; // this is a group array list, including SArray<STableQueryInfo*> structure
|
||||
char* sql; // query sql string
|
||||
jmp_buf env; //
|
||||
jmp_buf env; // when error occurs, abort
|
||||
STaskBufInfo bufInfo; // available buffer info this task
|
||||
struct SOperatorInfo* pRoot;
|
||||
} SExecTaskInfo;
|
||||
|
||||
|
@ -307,9 +313,11 @@ typedef struct STaskRuntimeEnv {
|
|||
} STaskRuntimeEnv;
|
||||
|
||||
enum {
|
||||
OP_IN_EXECUTING = 1,
|
||||
OP_RES_TO_RETURN = 2,
|
||||
OP_EXEC_DONE = 3,
|
||||
OP_NOT_OPENED = 0x0,
|
||||
OP_OPENED = 0x1,
|
||||
OP_IN_EXECUTING = 0x3,
|
||||
OP_RES_TO_RETURN = 0x5,
|
||||
OP_EXEC_DONE = 0x9,
|
||||
};
|
||||
|
||||
typedef struct SOperatorInfo {
|
||||
|
@ -322,12 +330,14 @@ typedef struct SOperatorInfo {
|
|||
SExprInfo* pExpr;
|
||||
STaskRuntimeEnv* pRuntimeEnv; // todo remove it
|
||||
SExecTaskInfo* pTaskInfo;
|
||||
SOperatorCostInfo cost;
|
||||
|
||||
struct SOperatorInfo** pDownstream; // downstram pointer list
|
||||
int32_t numOfDownstream; // number of downstream. The value is always ONE expect for join operator
|
||||
__optr_open_fn_t openFn;
|
||||
__optr_fn_t nextDataFn;
|
||||
__optr_fn_t getNextFn;
|
||||
__optr_fn_t cleanupFn;
|
||||
__optr_close_fn_t closeFn;
|
||||
__optr_open_fn_t _openFn; // DO NOT invoke this function directly
|
||||
} SOperatorInfo;
|
||||
|
||||
typedef struct {
|
||||
|
@ -378,9 +388,9 @@ typedef struct STaskParam {
|
|||
} STaskParam;
|
||||
|
||||
enum {
|
||||
DATA_NOT_READY = 0x1,
|
||||
DATA_READY = 0x2,
|
||||
DATA_EXHAUSTED = 0x3,
|
||||
EX_SOURCE_DATA_NOT_READY = 0x1,
|
||||
EX_SOURCE_DATA_READY = 0x2,
|
||||
EX_SOURCE_DATA_EXHAUSTED = 0x3,
|
||||
};
|
||||
|
||||
typedef struct SSourceDataInfo {
|
||||
|
@ -639,12 +649,16 @@ SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntim
|
|||
SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
||||
SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
||||
SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createOrderOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SArray* pOrderVal, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t numOfDownstream, SArray* pExprInfo, SArray* pOrderVal, SArray* pGroupInfo, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, const SArray* pExprInfo, const SSchema* pSchema,
|
||||
int32_t tableType, SEpSet epset, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
SOperatorInfo* createLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream);
|
||||
SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SInterval* pInterval, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
SOperatorInfo* createLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream);
|
||||
|
||||
SOperatorInfo* createAllTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream,
|
||||
SExprInfo* pExpr, int32_t numOfOutput);
|
||||
SOperatorInfo* createSWindowOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr,
|
||||
|
@ -674,10 +688,6 @@ SOperatorInfo* createSLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorI
|
|||
|
||||
SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pdownstream, int32_t numOfDownstream, SSchema* pSchema,
|
||||
int32_t numOfOutput);
|
||||
SOperatorInfo* createOrderOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SArray* pOrderVal, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t numOfDownstream, SArray* pExprInfo, SArray* pOrderVal, SArray* pGroupInfo, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
// SSDataBlock* doSLimit(void* param, bool* newgroup);
|
||||
|
||||
// int32_t doCreateFilterInfo(SColumnInfo* pCols, int32_t numOfCols, int32_t numOfFilterCols, SSingleColumnFilterInfo** pFilterInfo, uint64_t qId);
|
||||
void doSetFilterColumnInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilterCols, SSDataBlock* pBlock);
|
||||
|
@ -691,7 +701,6 @@ void* doDestroyFilterInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFil
|
|||
void setInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t order);
|
||||
void finalizeQueryResult(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SResultRowInfo* pResultRowInfo,
|
||||
int32_t* rowCellInfoOffset);
|
||||
void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t* bufCapacity, int32_t numOfInputRows);
|
||||
void clearOutputBuf(SOptrBasicInfo* pBInfo, int32_t* bufCapacity);
|
||||
void copyTsColoum(SSDataBlock* pRes, SqlFunctionCtx* pCtx, int32_t numOfOutput);
|
||||
|
||||
|
|
|
@ -21,8 +21,6 @@
|
|||
#include "tqueue.h"
|
||||
#include "executorimpl.h"
|
||||
|
||||
#define DATA_META_LENGTH(tables) (sizeof(int32_t) + sizeof(STableIdInfo) * taosHashGetSize(tables) + sizeof(SRetrieveTableRsp))
|
||||
|
||||
typedef struct SDataDispatchBuf {
|
||||
int32_t useSize;
|
||||
int32_t allocSize;
|
||||
|
@ -90,19 +88,6 @@ static void copyData(const SInputData* pInput, const SDataBlockDescNode* pSchema
|
|||
data += pColRes->info.bytes * pInput->pData->info.rows;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t numOfTables = (int32_t) taosHashGetSize(pInput->pTableRetrieveTsMap);
|
||||
*(int32_t*)data = htonl(numOfTables);
|
||||
data += sizeof(int32_t);
|
||||
|
||||
STableIdInfo* item = taosHashIterate(pInput->pTableRetrieveTsMap, NULL);
|
||||
while (item) {
|
||||
STableIdInfo* pDst = (STableIdInfo*)data;
|
||||
pDst->uid = htobe64(item->uid);
|
||||
pDst->key = htobe64(item->key);
|
||||
data += sizeof(STableIdInfo);
|
||||
item = taosHashIterate(pInput->pTableRetrieveTsMap, item);
|
||||
}
|
||||
}
|
||||
|
||||
// data format with compress: SDataCacheEntry | cols_data_offset | col1_data col2_data ... | numOfTables | STableIdInfo STableIdInfo ...
|
||||
|
@ -113,7 +98,7 @@ static void toDataCacheEntry(const SDataDispatchHandle* pHandle, const SInputDat
|
|||
pEntry->numOfRows = pInput->pData->info.rows;
|
||||
pEntry->dataLen = 0;
|
||||
|
||||
pBuf->useSize = DATA_META_LENGTH(pInput->pTableRetrieveTsMap);
|
||||
pBuf->useSize = sizeof(SRetrieveTableRsp);
|
||||
copyData(pInput, pHandle->pSchema, pEntry->data, pEntry->compressed, &pEntry->dataLen);
|
||||
if (0 == pEntry->compressed) {
|
||||
pEntry->dataLen = pHandle->pSchema->resultRowSize * pInput->pData->info.rows;
|
||||
|
@ -130,7 +115,7 @@ static bool allocBuf(SDataDispatchHandle* pDispatcher, const SInputData* pInput,
|
|||
return false;
|
||||
}
|
||||
|
||||
pBuf->allocSize = DATA_META_LENGTH(pInput->pTableRetrieveTsMap) + pDispatcher->pSchema->resultRowSize * pInput->pData->info.rows;
|
||||
pBuf->allocSize = sizeof(SRetrieveTableRsp) + pDispatcher->pSchema->resultRowSize * pInput->pData->info.rows;
|
||||
pBuf->pData = malloc(pBuf->allocSize);
|
||||
if (pBuf->pData == NULL) {
|
||||
qError("SinkNode failed to malloc memory, size:%d, code:%d", pBuf->allocSize, TAOS_SYSTEM_ERROR(errno));
|
||||
|
|
|
@ -158,7 +158,7 @@ int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t *useconds) {
|
|||
int64_t st = 0;
|
||||
|
||||
st = taosGetTimestampUs();
|
||||
*pRes = pTaskInfo->pRoot->nextDataFn(pTaskInfo->pRoot, &newgroup);
|
||||
*pRes = pTaskInfo->pRoot->getNextFn(pTaskInfo->pRoot, &newgroup);
|
||||
|
||||
uint64_t el = (taosGetTimestampUs() - st);
|
||||
pTaskInfo->cost.elapsedTime += el;
|
||||
|
|
|
@ -163,7 +163,7 @@ static void getNextTimeWindow(SInterval* pInterval, int32_t precision, int32_t o
|
|||
|
||||
struct tm tm;
|
||||
time_t t = (time_t)key;
|
||||
localtime_r(&t, &tm);
|
||||
taosLocalTime(&t, &tm);
|
||||
|
||||
int mon = (int)(tm.tm_year * 12 + tm.tm_mon + interval * factor);
|
||||
tm.tm_year = mon / 12;
|
||||
|
@ -211,6 +211,9 @@ static void destroyOrderOperatorInfo(void* param, int32_t numOfOutput);
|
|||
static void destroySWindowOperatorInfo(void* param, int32_t numOfOutput);
|
||||
static void destroyStateWindowOperatorInfo(void* param, int32_t numOfOutput);
|
||||
static void destroyAggOperatorInfo(void* param, int32_t numOfOutput);
|
||||
static void destroyExchangeOperatorInfo(void* param, int32_t numOfOutput);
|
||||
static void destroyConditionOperatorInfo(void* param, int32_t numOfOutput);
|
||||
|
||||
static void destroyOperatorInfo(SOperatorInfo* pOperator);
|
||||
static void destroySysTableScannerOperatorInfo(void* param, int32_t numOfOutput);
|
||||
|
||||
|
@ -221,6 +224,17 @@ static void doSetOperatorCompleted(SOperatorInfo* pOperator) {
|
|||
}
|
||||
}
|
||||
|
||||
#define OPTR_IS_OPENED(_optr) (((_optr)->status & OP_OPENED) == OP_OPENED)
|
||||
#define OPTR_SET_OPENED(_optr) ((_optr)->status |= OP_OPENED)
|
||||
|
||||
static int32_t operatorDummyOpenFn(void* param) {
|
||||
SOperatorInfo* pOperator = (SOperatorInfo*) param;
|
||||
OPTR_SET_OPENED(pOperator);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void operatorDummyCloseFn(void* param, int32_t numOfCols) {}
|
||||
|
||||
static int32_t doCopyToSDataBlock(SDiskbasedBuf *pBuf, SGroupResInfo* pGroupResInfo, int32_t orderType, SSDataBlock* pBlock, int32_t rowCapacity);
|
||||
|
||||
static int32_t getGroupbyColumnIndex(SGroupbyExpr *pGroupbyExpr, SSDataBlock* pDataBlock);
|
||||
|
@ -4723,6 +4737,11 @@ static SSDataBlock* doTableScan(void* param, bool *newgroup) {
|
|||
STableScanInfo *pTableScanInfo = pOperator->info;
|
||||
SExecTaskInfo *pTaskInfo = pOperator->pTaskInfo;
|
||||
|
||||
pTaskInfo->code = pOperator->_openFn(pOperator);
|
||||
if (pTaskInfo->code != TSDB_CODE_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// The read handle is not initialized yet, since no qualified tables exists
|
||||
if (pTableScanInfo->pTsdbReadHandle == NULL) {
|
||||
return NULL;
|
||||
|
@ -4840,6 +4859,11 @@ static SSDataBlock* doStreamBlockScan(void* param, bool* newgroup) {
|
|||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
SStreamBlockScanInfo* pInfo = pOperator->info;
|
||||
|
||||
pTaskInfo->code = pOperator->_openFn(pOperator);
|
||||
if (pTaskInfo->code != TSDB_CODE_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDataBlockInfo* pBlockInfo = &pInfo->pRes->info;
|
||||
pBlockInfo->rows = 0;
|
||||
|
||||
|
@ -4880,7 +4904,7 @@ int32_t loadRemoteDataCallback(void* param, const SDataBuf* pMsg, int32_t code)
|
|||
pRsp->useconds = htobe64(pRsp->useconds);
|
||||
pRsp->compLen = htonl(pRsp->compLen);
|
||||
|
||||
pSourceDataInfo->status = DATA_READY;
|
||||
pSourceDataInfo->status = EX_SOURCE_DATA_READY;
|
||||
tsem_post(&pSourceDataInfo->pEx->ready);
|
||||
}
|
||||
|
||||
|
@ -5008,12 +5032,12 @@ static SSDataBlock* concurrentlyLoadRemoteDataImpl(SOperatorInfo *pOperator, SEx
|
|||
for (int32_t i = 0; i < totalSources; ++i) {
|
||||
SSourceDataInfo* pDataInfo = taosArrayGet(pExchangeInfo->pSourceDataInfo, i);
|
||||
|
||||
if (pDataInfo->status == DATA_EXHAUSTED) {
|
||||
if (pDataInfo->status == EX_SOURCE_DATA_EXHAUSTED) {
|
||||
completed += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pDataInfo->status != DATA_READY) {
|
||||
if (pDataInfo->status != EX_SOURCE_DATA_READY) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -5026,7 +5050,7 @@ static SSDataBlock* concurrentlyLoadRemoteDataImpl(SOperatorInfo *pOperator, SEx
|
|||
qDebug("%s vgId:%d, taskID:0x%" PRIx64 " index:%d completed, rowsOfSource:%" PRIu64 ", totalRows:%" PRIu64 " try next",
|
||||
GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, i + 1, pDataInfo->totalRows,
|
||||
pExchangeInfo->totalRows);
|
||||
pDataInfo->status = DATA_EXHAUSTED;
|
||||
pDataInfo->status = EX_SOURCE_DATA_EXHAUSTED;
|
||||
completed += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -5042,15 +5066,15 @@ static SSDataBlock* concurrentlyLoadRemoteDataImpl(SOperatorInfo *pOperator, SEx
|
|||
GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pRes->info.rows,
|
||||
pDataInfo->totalRows, pExchangeInfo->totalRows, pExchangeInfo->totalSize, i + 1,
|
||||
totalSources);
|
||||
pDataInfo->status = DATA_EXHAUSTED;
|
||||
pDataInfo->status = EX_SOURCE_DATA_EXHAUSTED;
|
||||
} else {
|
||||
qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " numOfRows:%d, totalRows:%" PRIu64 ", totalBytes:%" PRIu64,
|
||||
GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pRes->info.rows, pExchangeInfo->totalRows,
|
||||
pExchangeInfo->totalSize);
|
||||
}
|
||||
|
||||
if (pDataInfo->status != DATA_EXHAUSTED) {
|
||||
pDataInfo->status = DATA_NOT_READY;
|
||||
if (pDataInfo->status != EX_SOURCE_DATA_EXHAUSTED) {
|
||||
pDataInfo->status = EX_SOURCE_DATA_NOT_READY;
|
||||
code = doSendFetchDataRequest(pExchangeInfo, pTaskInfo, i);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
|
@ -5070,13 +5094,9 @@ _error:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static SSDataBlock* concurrentlyLoadRemoteData(SOperatorInfo *pOperator) {
|
||||
static int32_t prepareConcurrentlyLoad(SOperatorInfo *pOperator) {
|
||||
SExchangeInfo *pExchangeInfo = pOperator->info;
|
||||
SExecTaskInfo *pTaskInfo = pOperator->pTaskInfo;
|
||||
|
||||
if (pOperator->status == OP_RES_TO_RETURN) {
|
||||
return concurrentlyLoadRemoteDataImpl(pOperator, pExchangeInfo, pTaskInfo);
|
||||
}
|
||||
|
||||
size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources);
|
||||
int64_t startTs = taosGetTimestampUs();
|
||||
|
@ -5085,7 +5105,8 @@ static SSDataBlock* concurrentlyLoadRemoteData(SOperatorInfo *pOperator) {
|
|||
for(int32_t i = 0; i < totalSources; ++i) {
|
||||
int32_t code = doSendFetchDataRequest(pExchangeInfo, pTaskInfo, i);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return NULL;
|
||||
pTaskInfo->code = code;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5093,9 +5114,9 @@ static SSDataBlock* concurrentlyLoadRemoteData(SOperatorInfo *pOperator) {
|
|||
qDebug("%s send all fetch request to %"PRIzu" sources completed, elapsed:%"PRId64, GET_TASKID(pTaskInfo), totalSources, endTs - startTs);
|
||||
|
||||
tsem_wait(&pExchangeInfo->ready);
|
||||
pOperator->cost.openCost = taosGetTimestampUs() - startTs;
|
||||
|
||||
pOperator->status = OP_RES_TO_RETURN;
|
||||
return concurrentlyLoadRemoteDataImpl(pOperator, pExchangeInfo, pTaskInfo);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static SSDataBlock* seqLoadRemoteData(SOperatorInfo *pOperator) {
|
||||
|
@ -5123,7 +5144,7 @@ static SSDataBlock* seqLoadRemoteData(SOperatorInfo *pOperator) {
|
|||
GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pExchangeInfo->current + 1,
|
||||
pDataInfo->totalRows, pExchangeInfo->totalRows);
|
||||
|
||||
pDataInfo->status = DATA_EXHAUSTED;
|
||||
pDataInfo->status = EX_SOURCE_DATA_EXHAUSTED;
|
||||
pExchangeInfo->current += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -5138,7 +5159,7 @@ static SSDataBlock* seqLoadRemoteData(SOperatorInfo *pOperator) {
|
|||
pDataInfo->totalRows, pExchangeInfo->totalRows, pExchangeInfo->totalSize, pExchangeInfo->current + 1,
|
||||
totalSources);
|
||||
|
||||
pDataInfo->status = DATA_EXHAUSTED;
|
||||
pDataInfo->status = EX_SOURCE_DATA_EXHAUSTED;
|
||||
pExchangeInfo->current += 1;
|
||||
} else {
|
||||
qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " numOfRows:%d, totalRows:%" PRIu64 ", totalBytes:%" PRIu64,
|
||||
|
@ -5149,14 +5170,39 @@ static SSDataBlock* seqLoadRemoteData(SOperatorInfo *pOperator) {
|
|||
}
|
||||
}
|
||||
|
||||
static int32_t prepareLoadRemoteData(void* param) {
|
||||
SOperatorInfo *pOperator = (SOperatorInfo*) param;
|
||||
if (OPTR_IS_OPENED(pOperator)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SExchangeInfo *pExchangeInfo = pOperator->info;
|
||||
if (pExchangeInfo->seqLoadData) {
|
||||
// do nothing for sequentially load data
|
||||
} else {
|
||||
int32_t code = prepareConcurrentlyLoad(pOperator);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
OPTR_SET_OPENED(pOperator);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static SSDataBlock* doLoadRemoteData(void* param, bool* newgroup) {
|
||||
SOperatorInfo *pOperator = (SOperatorInfo*) param;
|
||||
|
||||
SExchangeInfo *pExchangeInfo = pOperator->info;
|
||||
SExecTaskInfo *pTaskInfo = pOperator->pTaskInfo;
|
||||
|
||||
size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources);
|
||||
int32_t code = pOperator->_openFn(pOperator);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pTaskInfo->code = code;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources);
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
qDebug("%s all %"PRIzu" source(s) are exhausted, total rows:%"PRIu64" bytes:%"PRIu64", elapsed:%.2f ms", GET_TASKID(pTaskInfo), totalSources,
|
||||
pExchangeInfo->totalRows, pExchangeInfo->totalSize, pExchangeInfo->totalElapsed/1000.0);
|
||||
|
@ -5164,11 +5210,10 @@ static SSDataBlock* doLoadRemoteData(void* param, bool* newgroup) {
|
|||
}
|
||||
|
||||
*newgroup = false;
|
||||
|
||||
if (pExchangeInfo->seqLoadData) {
|
||||
return seqLoadRemoteData(pOperator);
|
||||
} else {
|
||||
return concurrentlyLoadRemoteData(pOperator);
|
||||
return concurrentlyLoadRemoteDataImpl(pOperator, pExchangeInfo, pTaskInfo);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
@ -5181,16 +5226,35 @@ static SSDataBlock* doLoadRemoteData(void* param, bool* newgroup) {
|
|||
#endif
|
||||
}
|
||||
|
||||
static int32_t initDataSource(int32_t numOfSources, SExchangeInfo* pInfo) {
|
||||
pInfo->pSourceDataInfo = taosArrayInit(numOfSources, sizeof(SSourceDataInfo));
|
||||
if (pInfo->pSourceDataInfo == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
for(int32_t i = 0; i < numOfSources; ++i) {
|
||||
SSourceDataInfo dataInfo = {0};
|
||||
dataInfo.status = EX_SOURCE_DATA_NOT_READY;
|
||||
dataInfo.pEx = pInfo;
|
||||
dataInfo.index = i;
|
||||
|
||||
void* ret = taosArrayPush(pInfo->pSourceDataInfo, &dataInfo);
|
||||
if (ret == NULL) {
|
||||
taosArrayDestroy(pInfo->pSourceDataInfo);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
// TODO handle the error
|
||||
SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo) {
|
||||
SExchangeInfo* pInfo = calloc(1, sizeof(SExchangeInfo));
|
||||
SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo));
|
||||
|
||||
if (pInfo == NULL || pOperator == NULL) {
|
||||
tfree(pInfo);
|
||||
tfree(pOperator);
|
||||
terrno = TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
goto _error;
|
||||
}
|
||||
|
||||
size_t numOfSources = LIST_LENGTH(pSources);
|
||||
|
@ -5217,29 +5281,28 @@ SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock
|
|||
return NULL;
|
||||
}
|
||||
|
||||
for(int32_t i = 0; i < numOfSources; ++i) {
|
||||
SSourceDataInfo dataInfo = {0};
|
||||
dataInfo.status = DATA_NOT_READY;
|
||||
dataInfo.pEx = pInfo;
|
||||
dataInfo.index = i;
|
||||
|
||||
taosArrayPush(pInfo->pSourceDataInfo, &dataInfo);
|
||||
int32_t code = initDataSource(numOfSources, pInfo);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
size_t size = pBlock->info.numOfCols;
|
||||
pInfo->pResult = pBlock;
|
||||
pInfo->seqLoadData = true;
|
||||
|
||||
pInfo->seqLoadData = true; // sequentially load data from the source node
|
||||
tsem_init(&pInfo->ready, 0, 0);
|
||||
|
||||
pOperator->name = "ExchangeOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_EXCHANGE;
|
||||
pOperator->blockingOptr = false;
|
||||
pOperator->status = OP_IN_EXECUTING;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->numOfOutput = size;
|
||||
pOperator->nextDataFn = doLoadRemoteData;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
pOperator->_openFn = prepareLoadRemoteData; // assign a dummy function.
|
||||
pOperator->getNextFn = doLoadRemoteData;
|
||||
pOperator->closeFn = destroyExchangeOperatorInfo;
|
||||
|
||||
#if 1
|
||||
{ // todo refactor
|
||||
|
@ -5265,6 +5328,16 @@ SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock
|
|||
#endif
|
||||
|
||||
return pOperator;
|
||||
|
||||
_error:
|
||||
if (pInfo != NULL) {
|
||||
destroyExchangeOperatorInfo(pInfo, 0);
|
||||
}
|
||||
|
||||
tfree(pInfo);
|
||||
tfree(pOperator);
|
||||
terrno = TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SSDataBlock* createResultDataBlock(const SArray* pExprInfo) {
|
||||
|
@ -5315,10 +5388,12 @@ SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order,
|
|||
pOperator->name = "TableScanOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN;
|
||||
pOperator->blockingOptr = false;
|
||||
pOperator->status = OP_IN_EXECUTING;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->numOfOutput = numOfOutput;
|
||||
pOperator->nextDataFn = doTableScan;
|
||||
pOperator->_openFn = operatorDummyOpenFn;
|
||||
pOperator->getNextFn = doTableScan;
|
||||
pOperator->closeFn = operatorDummyCloseFn;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
return pOperator;
|
||||
|
@ -5339,11 +5414,11 @@ SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntim
|
|||
pOperator->name = "TableSeqScanOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN;
|
||||
pOperator->blockingOptr = false;
|
||||
pOperator->status = OP_IN_EXECUTING;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->numOfOutput = pRuntimeEnv->pQueryAttr->numOfCols;
|
||||
pOperator->pRuntimeEnv = pRuntimeEnv;
|
||||
pOperator->nextDataFn = doTableScanImpl;
|
||||
pOperator->getNextFn = doTableScanImpl;
|
||||
|
||||
return pOperator;
|
||||
}
|
||||
|
@ -5364,10 +5439,10 @@ SOperatorInfo* createTableBlockInfoScanOperator(void* pTsdbReadHandle, STaskRunt
|
|||
pOperator->name = "TableBlockInfoScanOperator";
|
||||
// pOperator->operatorType = OP_TableBlockInfoScan;
|
||||
pOperator->blockingOptr = false;
|
||||
pOperator->status = OP_IN_EXECUTING;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
// pOperator->numOfOutput = pRuntimeEnv->pQueryAttr->numOfCols;
|
||||
pOperator->nextDataFn = doBlockInfoScan;
|
||||
pOperator->getNextFn = doBlockInfoScan;
|
||||
|
||||
return pOperator;
|
||||
}
|
||||
|
@ -5397,10 +5472,13 @@ SOperatorInfo* createStreamScanOperatorInfo(void *streamReadHandle, SSDataBlock*
|
|||
pOperator->name = "StreamBlockScanOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN;
|
||||
pOperator->blockingOptr = false;
|
||||
pOperator->status = OP_IN_EXECUTING;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->numOfOutput = pResBlock->info.numOfCols;
|
||||
pOperator->nextDataFn = doStreamBlockScan;
|
||||
pOperator->_openFn = operatorDummyOpenFn;
|
||||
pOperator->getNextFn = doStreamBlockScan;
|
||||
pOperator->closeFn = operatorDummyCloseFn;
|
||||
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
return pOperator;
|
||||
}
|
||||
|
@ -5415,7 +5493,7 @@ static int32_t loadSysTableContentCb(void* param, const SDataBuf* pMsg, int32_t
|
|||
pRsp->useconds = htobe64(pRsp->useconds);
|
||||
pRsp->compLen = htonl(pRsp->compLen);
|
||||
|
||||
pSourceDataInfo->status = DATA_READY;
|
||||
pSourceDataInfo->status = EX_SOURCE_DATA_READY;
|
||||
tsem_post(&pSourceDataInfo->pEx->ready);
|
||||
}
|
||||
|
||||
|
@ -5513,7 +5591,7 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, const S
|
|||
pOperator->status = OP_IN_EXECUTING;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->numOfOutput = taosArrayGetSize(pExprInfo);
|
||||
pOperator->nextDataFn = doSysTableScan;
|
||||
pOperator->getNextFn = doSysTableScan;
|
||||
pOperator->closeFn = destroySysTableScannerOperatorInfo;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
|
@ -5741,7 +5819,7 @@ SSDataBlock* loadNextDataBlock(void* param) {
|
|||
SOperatorInfo* pOperator = (SOperatorInfo*) param;
|
||||
bool newgroup = false;
|
||||
|
||||
return pOperator->nextDataFn(pOperator, &newgroup);
|
||||
return pOperator->getNextFn(pOperator, &newgroup);
|
||||
}
|
||||
|
||||
static bool needToMerge(SSDataBlock* pBlock, SArray* groupInfo, char **buf, int32_t rowIndex) {
|
||||
|
@ -6055,13 +6133,13 @@ SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t
|
|||
pOperator->name = "SortedMerge";
|
||||
// pOperator->operatorType = OP_SortedMerge;
|
||||
pOperator->blockingOptr = true;
|
||||
pOperator->status = OP_IN_EXECUTING;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->numOfOutput = numOfOutput;
|
||||
pOperator->pExpr = exprArrayDup(pExprInfo);
|
||||
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
pOperator->nextDataFn = doSortedMerge;
|
||||
pOperator->getNextFn = doSortedMerge;
|
||||
pOperator->closeFn = destroySortedMergeOperatorInfo;
|
||||
|
||||
code = appendDownstream(pOperator, downstream, numOfDownstream);
|
||||
|
@ -6153,11 +6231,11 @@ SOperatorInfo *createOrderOperatorInfo(SOperatorInfo* downstream, SArray* pExprI
|
|||
pOperator->name = "Order";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SORT;
|
||||
pOperator->blockingOptr = true;
|
||||
pOperator->status = OP_IN_EXECUTING;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
pOperator->nextDataFn = doSort;
|
||||
pOperator->getNextFn = doSort;
|
||||
pOperator->closeFn = destroyOrderOperatorInfo;
|
||||
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
|
@ -6183,7 +6261,7 @@ static SSDataBlock* doAggregate(void* param, bool* newgroup) {
|
|||
|
||||
while(1) {
|
||||
publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC);
|
||||
SSDataBlock* pBlock = downstream->nextDataFn(downstream, newgroup);
|
||||
SSDataBlock* pBlock = downstream->getNextFn(downstream, newgroup);
|
||||
publishOperatorProfEvent(downstream, QUERY_PROF_AFTER_OPERATOR_EXEC);
|
||||
|
||||
if (pBlock == NULL) {
|
||||
|
@ -6233,7 +6311,7 @@ static SSDataBlock* doMultiTableAggregate(void* param, bool* newgroup) {
|
|||
|
||||
while(1) {
|
||||
publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC);
|
||||
SSDataBlock* pBlock = downstream->nextDataFn(downstream, newgroup);
|
||||
SSDataBlock* pBlock = downstream->getNextFn(downstream, newgroup);
|
||||
publishOperatorProfEvent(downstream, QUERY_PROF_AFTER_OPERATOR_EXEC);
|
||||
|
||||
if (pBlock == NULL) {
|
||||
|
@ -6319,7 +6397,7 @@ static SSDataBlock* doProjectOperation(void* param, bool* newgroup) {
|
|||
|
||||
// The downstream exec may change the value of the newgroup, so use a local variable instead.
|
||||
publishOperatorProfEvent(pOperator->pDownstream[0], QUERY_PROF_BEFORE_OPERATOR_EXEC);
|
||||
SSDataBlock* pBlock = pOperator->pDownstream[0]->nextDataFn(pOperator->pDownstream[0], newgroup);
|
||||
SSDataBlock* pBlock = pOperator->pDownstream[0]->getNextFn(pOperator->pDownstream[0], newgroup);
|
||||
publishOperatorProfEvent(pOperator->pDownstream[0], QUERY_PROF_AFTER_OPERATOR_EXEC);
|
||||
|
||||
if (pBlock == NULL) {
|
||||
|
@ -6377,7 +6455,7 @@ static SSDataBlock* doLimit(void* param, bool* newgroup) {
|
|||
SSDataBlock* pBlock = NULL;
|
||||
while (1) {
|
||||
publishOperatorProfEvent(pOperator->pDownstream[0], QUERY_PROF_BEFORE_OPERATOR_EXEC);
|
||||
pBlock = pOperator->pDownstream[0]->nextDataFn(pOperator->pDownstream[0], newgroup);
|
||||
pBlock = pOperator->pDownstream[0]->getNextFn(pOperator->pDownstream[0], newgroup);
|
||||
publishOperatorProfEvent(pOperator->pDownstream[0], QUERY_PROF_AFTER_OPERATOR_EXEC);
|
||||
|
||||
if (pBlock == NULL) {
|
||||
|
@ -6428,7 +6506,7 @@ static SSDataBlock* doFilter(void* param, bool* newgroup) {
|
|||
|
||||
while (1) {
|
||||
publishOperatorProfEvent(pOperator->pDownstream[0], QUERY_PROF_BEFORE_OPERATOR_EXEC);
|
||||
SSDataBlock *pBlock = pOperator->pDownstream[0]->nextDataFn(pOperator->pDownstream[0], newgroup);
|
||||
SSDataBlock *pBlock = pOperator->pDownstream[0]->getNextFn(pOperator->pDownstream[0], newgroup);
|
||||
publishOperatorProfEvent(pOperator->pDownstream[0], QUERY_PROF_AFTER_OPERATOR_EXEC);
|
||||
|
||||
if (pBlock == NULL) {
|
||||
|
@ -6471,7 +6549,7 @@ static SSDataBlock* doIntervalAgg(void* param, bool* newgroup) {
|
|||
|
||||
while(1) {
|
||||
publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC);
|
||||
SSDataBlock* pBlock = downstream->nextDataFn(downstream, newgroup);
|
||||
SSDataBlock* pBlock = downstream->getNextFn(downstream, newgroup);
|
||||
publishOperatorProfEvent(downstream, QUERY_PROF_AFTER_OPERATOR_EXEC);
|
||||
|
||||
if (pBlock == NULL) {
|
||||
|
@ -6531,7 +6609,7 @@ static SSDataBlock* doAllIntervalAgg(void* param, bool* newgroup) {
|
|||
|
||||
while(1) {
|
||||
publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC);
|
||||
SSDataBlock* pBlock = downstream->nextDataFn(downstream, newgroup);
|
||||
SSDataBlock* pBlock = downstream->getNextFn(downstream, newgroup);
|
||||
publishOperatorProfEvent(downstream, QUERY_PROF_AFTER_OPERATOR_EXEC);
|
||||
|
||||
if (pBlock == NULL) {
|
||||
|
@ -6594,7 +6672,7 @@ static SSDataBlock* doSTableIntervalAgg(void* param, bool* newgroup) {
|
|||
|
||||
while(1) {
|
||||
publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC);
|
||||
SSDataBlock* pBlock = downstream->nextDataFn(downstream, newgroup);
|
||||
SSDataBlock* pBlock = downstream->getNextFn(downstream, newgroup);
|
||||
publishOperatorProfEvent(downstream, QUERY_PROF_AFTER_OPERATOR_EXEC);
|
||||
|
||||
if (pBlock == NULL) {
|
||||
|
@ -6649,7 +6727,7 @@ static SSDataBlock* doAllSTableIntervalAgg(void* param, bool* newgroup) {
|
|||
|
||||
while(1) {
|
||||
publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC);
|
||||
SSDataBlock* pBlock = downstream->nextDataFn(downstream, newgroup);
|
||||
SSDataBlock* pBlock = downstream->getNextFn(downstream, newgroup);
|
||||
publishOperatorProfEvent(downstream, QUERY_PROF_AFTER_OPERATOR_EXEC);
|
||||
|
||||
if (pBlock == NULL) {
|
||||
|
@ -6784,7 +6862,7 @@ static SSDataBlock* doStateWindowAgg(void *param, bool* newgroup) {
|
|||
SOperatorInfo* downstream = pOperator->pDownstream[0];
|
||||
while (1) {
|
||||
publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC);
|
||||
SSDataBlock* pBlock = downstream->nextDataFn(downstream, newgroup);
|
||||
SSDataBlock* pBlock = downstream->getNextFn(downstream, newgroup);
|
||||
publishOperatorProfEvent(downstream, QUERY_PROF_AFTER_OPERATOR_EXEC);
|
||||
|
||||
if (pBlock == NULL) {
|
||||
|
@ -6846,7 +6924,7 @@ static SSDataBlock* doSessionWindowAgg(void* param, bool* newgroup) {
|
|||
|
||||
while(1) {
|
||||
publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC);
|
||||
SSDataBlock* pBlock = downstream->nextDataFn(downstream, newgroup);
|
||||
SSDataBlock* pBlock = downstream->getNextFn(downstream, newgroup);
|
||||
publishOperatorProfEvent(downstream, QUERY_PROF_AFTER_OPERATOR_EXEC);
|
||||
if (pBlock == NULL) {
|
||||
break;
|
||||
|
@ -6899,7 +6977,7 @@ static SSDataBlock* hashGroupbyAggregate(void* param, bool* newgroup) {
|
|||
|
||||
while(1) {
|
||||
publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC);
|
||||
SSDataBlock* pBlock = downstream->nextDataFn(downstream, newgroup);
|
||||
SSDataBlock* pBlock = downstream->getNextFn(downstream, newgroup);
|
||||
publishOperatorProfEvent(downstream, QUERY_PROF_AFTER_OPERATOR_EXEC);
|
||||
if (pBlock == NULL) {
|
||||
break;
|
||||
|
@ -6984,7 +7062,7 @@ static SSDataBlock* doFill(void* param, bool* newgroup) {
|
|||
|
||||
while(1) {
|
||||
publishOperatorProfEvent(pOperator->pDownstream[0], QUERY_PROF_BEFORE_OPERATOR_EXEC);
|
||||
SSDataBlock* pBlock = pOperator->pDownstream[0]->nextDataFn(pOperator->pDownstream[0], newgroup);
|
||||
SSDataBlock* pBlock = pOperator->pDownstream[0]->getNextFn(pOperator->pDownstream[0], newgroup);
|
||||
publishOperatorProfEvent(pOperator->pDownstream[0], QUERY_PROF_AFTER_OPERATOR_EXEC);
|
||||
|
||||
if (*newgroup) {
|
||||
|
@ -7141,13 +7219,13 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SArray* pE
|
|||
pOperator->name = "TableAggregate";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_AGG;
|
||||
pOperator->blockingOptr = true;
|
||||
pOperator->status = OP_IN_EXECUTING;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pExpr = exprArrayDup(pExprInfo);
|
||||
pOperator->numOfOutput = taosArrayGetSize(pExprInfo);
|
||||
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
pOperator->nextDataFn = doAggregate;
|
||||
pOperator->getNextFn = doAggregate;
|
||||
pOperator->closeFn = destroyAggOperatorInfo;
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
|
||||
|
@ -7196,17 +7274,17 @@ static void destroyGroupbyOperatorInfo(void* param, int32_t numOfOutput) {
|
|||
tfree(pInfo->prevData);
|
||||
}
|
||||
|
||||
static void destroyProjectOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
void destroyProjectOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
SProjectOperatorInfo* pInfo = (SProjectOperatorInfo*) param;
|
||||
doDestroyBasicInfo(&pInfo->binfo, numOfOutput);
|
||||
}
|
||||
|
||||
static void destroyTagScanOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
void destroyTagScanOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
STagScanInfo* pInfo = (STagScanInfo*) param;
|
||||
pInfo->pRes = blockDataDestroy(pInfo->pRes);
|
||||
}
|
||||
|
||||
static void destroyOrderOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
void destroyOrderOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
SOrderOperatorInfo* pInfo = (SOrderOperatorInfo*) param;
|
||||
pInfo->pDataBlock = blockDataDestroy(pInfo->pDataBlock);
|
||||
|
||||
|
@ -7236,6 +7314,17 @@ static void destroySysTableScannerOperatorInfo(void* param, int32_t numOfOutput)
|
|||
}
|
||||
}
|
||||
|
||||
void destroyExchangeOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
SExchangeInfo* pExInfo = (SExchangeInfo*) param;
|
||||
taosArrayDestroy(pExInfo->pSources);
|
||||
taosArrayDestroy(pExInfo->pSourceDataInfo);
|
||||
if (pExInfo->pResult != NULL) {
|
||||
blockDataDestroy(pExInfo->pResult);
|
||||
}
|
||||
|
||||
tsem_destroy(&pExInfo->ready);
|
||||
}
|
||||
|
||||
SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo) {
|
||||
SAggOperatorInfo* pInfo = calloc(1, sizeof(SAggOperatorInfo));
|
||||
|
||||
|
@ -7250,13 +7339,13 @@ SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SArray
|
|||
pOperator->name = "MultiTableAggregate";
|
||||
// pOperator->operatorType = OP_MultiTableAggregate;
|
||||
pOperator->blockingOptr = true;
|
||||
pOperator->status = OP_IN_EXECUTING;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pExpr = exprArrayDup(pExprInfo);
|
||||
pOperator->numOfOutput = numOfOutput;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->nextDataFn = doMultiTableAggregate;
|
||||
pOperator->getNextFn = doMultiTableAggregate;
|
||||
pOperator->closeFn = destroyAggOperatorInfo;
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
|
||||
|
@ -7277,12 +7366,12 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SArray* pExp
|
|||
pOperator->name = "ProjectOperator";
|
||||
// pOperator->operatorType = OP_Project;
|
||||
pOperator->blockingOptr = false;
|
||||
pOperator->status = OP_IN_EXECUTING;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pExpr = exprArrayDup(pExprInfo);
|
||||
pOperator->numOfOutput = taosArrayGetSize(pExprInfo);
|
||||
|
||||
pOperator->nextDataFn = doProjectOperation;
|
||||
pOperator->getNextFn = doProjectOperation;
|
||||
pOperator->closeFn = destroyProjectOperatorInfo;
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
|
||||
|
@ -7331,11 +7420,11 @@ SOperatorInfo* createLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorIn
|
|||
pOperator->name = "LimitOperator";
|
||||
// pOperator->operatorType = OP_Limit;
|
||||
pOperator->blockingOptr = false;
|
||||
pOperator->status = OP_IN_EXECUTING;
|
||||
pOperator->nextDataFn = doLimit;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->getNextFn = doLimit;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pRuntimeEnv = pRuntimeEnv;
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
|
||||
return pOperator;
|
||||
}
|
||||
|
@ -7363,13 +7452,13 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SArray* pEx
|
|||
pOperator->name = "TimeIntervalAggOperator";
|
||||
// pOperator->operatorType = OP_TimeWindow;
|
||||
pOperator->blockingOptr = true;
|
||||
pOperator->status = OP_IN_EXECUTING;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->pExpr = exprArrayDup(pExprInfo);
|
||||
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
pOperator->numOfOutput = taosArrayGetSize(pExprInfo);
|
||||
pOperator->info = pInfo;
|
||||
pOperator->nextDataFn = doIntervalAgg;
|
||||
pOperator->getNextFn = doIntervalAgg;
|
||||
pOperator->closeFn = destroyBasicOperatorInfo;
|
||||
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
|
@ -7388,12 +7477,12 @@ SOperatorInfo* createAllTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, S
|
|||
pOperator->name = "AllTimeIntervalAggOperator";
|
||||
// pOperator->operatorType = OP_AllTimeWindow;
|
||||
pOperator->blockingOptr = true;
|
||||
pOperator->status = OP_IN_EXECUTING;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->pExpr = pExpr;
|
||||
pOperator->numOfOutput = numOfOutput;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pRuntimeEnv = pRuntimeEnv;
|
||||
pOperator->nextDataFn = doAllIntervalAgg;
|
||||
pOperator->getNextFn = doAllIntervalAgg;
|
||||
pOperator->closeFn = destroyBasicOperatorInfo;
|
||||
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
|
@ -7412,12 +7501,12 @@ SOperatorInfo* createStatewindowOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOper
|
|||
pOperator->name = "StateWindowOperator";
|
||||
// pOperator->operatorType = OP_StateWindow;
|
||||
pOperator->blockingOptr = true;
|
||||
pOperator->status = OP_IN_EXECUTING;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->pExpr = pExpr;
|
||||
pOperator->numOfOutput = numOfOutput;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pRuntimeEnv = pRuntimeEnv;
|
||||
pOperator->nextDataFn = doStateWindowAgg;
|
||||
pOperator->getNextFn = doStateWindowAgg;
|
||||
pOperator->closeFn = destroyStateWindowOperatorInfo;
|
||||
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
|
@ -7437,12 +7526,12 @@ SOperatorInfo* createSWindowOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperator
|
|||
pOperator->name = "SessionWindowAggOperator";
|
||||
// pOperator->operatorType = OP_SessionWindow;
|
||||
pOperator->blockingOptr = true;
|
||||
pOperator->status = OP_IN_EXECUTING;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->pExpr = pExpr;
|
||||
pOperator->numOfOutput = numOfOutput;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pRuntimeEnv = pRuntimeEnv;
|
||||
pOperator->nextDataFn = doSessionWindowAgg;
|
||||
pOperator->getNextFn = doSessionWindowAgg;
|
||||
pOperator->closeFn = destroySWindowOperatorInfo;
|
||||
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
|
@ -7460,13 +7549,13 @@ SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntim
|
|||
pOperator->name = "MultiTableTimeIntervalOperator";
|
||||
// pOperator->operatorType = OP_MultiTableTimeInterval;
|
||||
pOperator->blockingOptr = true;
|
||||
pOperator->status = OP_IN_EXECUTING;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->pExpr = pExpr;
|
||||
pOperator->numOfOutput = numOfOutput;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pRuntimeEnv = pRuntimeEnv;
|
||||
|
||||
pOperator->nextDataFn = doSTableIntervalAgg;
|
||||
pOperator->getNextFn = doSTableIntervalAgg;
|
||||
pOperator->closeFn = destroyBasicOperatorInfo;
|
||||
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
|
@ -7484,13 +7573,13 @@ SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRun
|
|||
pOperator->name = "AllMultiTableTimeIntervalOperator";
|
||||
// pOperator->operatorType = OP_AllMultiTableTimeInterval;
|
||||
pOperator->blockingOptr = true;
|
||||
pOperator->status = OP_IN_EXECUTING;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->pExpr = pExpr;
|
||||
pOperator->numOfOutput = numOfOutput;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pRuntimeEnv = pRuntimeEnv;
|
||||
|
||||
pOperator->nextDataFn = doAllSTableIntervalAgg;
|
||||
pOperator->getNextFn = doAllSTableIntervalAgg;
|
||||
pOperator->closeFn = destroyBasicOperatorInfo;
|
||||
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
|
@ -7516,13 +7605,13 @@ SOperatorInfo* createGroupbyOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperator
|
|||
SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo));
|
||||
pOperator->name = "GroupbyAggOperator";
|
||||
pOperator->blockingOptr = true;
|
||||
pOperator->status = OP_IN_EXECUTING;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
// pOperator->operatorType = OP_Groupby;
|
||||
pOperator->pExpr = pExpr;
|
||||
pOperator->numOfOutput = numOfOutput;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pRuntimeEnv = pRuntimeEnv;
|
||||
pOperator->nextDataFn = hashGroupbyAggregate;
|
||||
pOperator->getNextFn = hashGroupbyAggregate;
|
||||
pOperator->closeFn = destroyGroupbyOperatorInfo;
|
||||
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
|
@ -7555,13 +7644,13 @@ SOperatorInfo* createFillOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInf
|
|||
|
||||
pOperator->name = "FillOperator";
|
||||
pOperator->blockingOptr = false;
|
||||
pOperator->status = OP_IN_EXECUTING;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
// pOperator->operatorType = OP_Fill;
|
||||
pOperator->pExpr = pExpr;
|
||||
pOperator->numOfOutput = numOfOutput;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pRuntimeEnv = pRuntimeEnv;
|
||||
pOperator->nextDataFn = doFill;
|
||||
pOperator->getNextFn = doFill;
|
||||
pOperator->closeFn = destroySFillOperatorInfo;
|
||||
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
|
@ -7606,13 +7695,12 @@ SOperatorInfo* createSLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorI
|
|||
pOperator->name = "SLimitOperator";
|
||||
// pOperator->operatorType = OP_SLimit;
|
||||
pOperator->blockingOptr = false;
|
||||
pOperator->status = OP_IN_EXECUTING;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
// pOperator->exec = doSLimit;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pRuntimeEnv = pRuntimeEnv;
|
||||
pOperator->closeFn = destroySlimitOperatorInfo;
|
||||
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
return pOperator;
|
||||
}
|
||||
|
||||
|
@ -7746,6 +7834,7 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) {
|
|||
return (pRes->info.rows == 0)? NULL:pInfo->pRes;
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
SOperatorInfo* createTagScanOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SExprInfo* pExpr, int32_t numOfOutput) {
|
||||
|
@ -7762,9 +7851,9 @@ SOperatorInfo* createTagScanOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SExprInfo
|
|||
pOperator->name = "SeqTableTagScan";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN;
|
||||
pOperator->blockingOptr = false;
|
||||
pOperator->status = OP_IN_EXECUTING;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->nextDataFn = doTagScan;
|
||||
pOperator->getNextFn = doTagScan;
|
||||
pOperator->pExpr = pExpr;
|
||||
pOperator->numOfOutput = numOfOutput;
|
||||
pOperator->pRuntimeEnv = pRuntimeEnv;
|
||||
|
@ -7834,7 +7923,7 @@ static SSDataBlock* hashDistinct(void* param, bool* newgroup) {
|
|||
|
||||
while(1) {
|
||||
publishOperatorProfEvent(pOperator->pDownstream[0], QUERY_PROF_BEFORE_OPERATOR_EXEC);
|
||||
pBlock = pOperator->pDownstream[0]->nextDataFn(pOperator->pDownstream[0], newgroup);
|
||||
pBlock = pOperator->pDownstream[0]->getNextFn(pOperator->pDownstream[0], newgroup);
|
||||
publishOperatorProfEvent(pOperator->pDownstream[0], QUERY_PROF_AFTER_OPERATOR_EXEC);
|
||||
|
||||
if (pBlock == NULL) {
|
||||
|
@ -7900,13 +7989,13 @@ SOperatorInfo* createDistinctOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperato
|
|||
SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo));
|
||||
pOperator->name = "DistinctOperator";
|
||||
pOperator->blockingOptr = false;
|
||||
pOperator->status = OP_IN_EXECUTING;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
// pOperator->operatorType = OP_Distinct;
|
||||
pOperator->pExpr = pExpr;
|
||||
pOperator->numOfOutput = numOfOutput;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pRuntimeEnv = pRuntimeEnv;
|
||||
pOperator->nextDataFn = hashDistinct;
|
||||
pOperator->getNextFn = hashDistinct;
|
||||
pOperator->pExpr = pExpr;
|
||||
pOperator->closeFn = destroyDistinctOperatorInfo;
|
||||
|
||||
|
@ -8524,75 +8613,6 @@ void setResultBufSize(STaskAttr* pQueryAttr, SRspResultInfo* pResultInfo) {
|
|||
pResultInfo->total = 0;
|
||||
}
|
||||
|
||||
FORCE_INLINE bool checkQIdEqual(void *qHandle, uint64_t qId) {
|
||||
return ((SQInfo *)qHandle)->qId == qId;
|
||||
}
|
||||
|
||||
int32_t initQInfo(STsBufInfo* pTsBufInfo, void* tsdb, void* sourceOptr, SQInfo* pQInfo, STaskParam* param, char* start,
|
||||
int32_t prevResultLen, void* merger) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
STaskRuntimeEnv* pRuntimeEnv = &pQInfo->runtimeEnv;
|
||||
pRuntimeEnv->qinfo = pQInfo;
|
||||
|
||||
STaskAttr *pQueryAttr = pRuntimeEnv->pQueryAttr;
|
||||
|
||||
STSBuf *pTsBuf = NULL;
|
||||
|
||||
if (pTsBufInfo->tsLen > 0) { // open new file to save the result
|
||||
char* tsBlock = start + pTsBufInfo->tsOffset;
|
||||
pTsBuf = tsBufCreateFromCompBlocks(tsBlock, pTsBufInfo->tsNumOfBlocks, pTsBufInfo->tsLen, pTsBufInfo->tsOrder,
|
||||
pQueryAttr->vgId);
|
||||
|
||||
if (pTsBuf == NULL) {
|
||||
code = TSDB_CODE_QRY_NO_DISKSPACE;
|
||||
goto _error;
|
||||
}
|
||||
tsBufResetPos(pTsBuf);
|
||||
bool ret = tsBufNextPos(pTsBuf);
|
||||
UNUSED(ret);
|
||||
}
|
||||
|
||||
SArray* prevResult = NULL;
|
||||
if (prevResultLen > 0) {
|
||||
prevResult = interResFromBinary(param->prevResult, prevResultLen);
|
||||
pRuntimeEnv->prevResult = prevResult;
|
||||
}
|
||||
|
||||
pRuntimeEnv->currentOffset = pQueryAttr->limit.offset;
|
||||
if (tsdb != NULL) {
|
||||
// pQueryAttr->precision = tsdbGetCfg(tsdb)->precision;
|
||||
}
|
||||
|
||||
if ((QUERY_IS_ASC_QUERY(pQueryAttr) && (pQueryAttr->window.skey > pQueryAttr->window.ekey)) ||
|
||||
(!QUERY_IS_ASC_QUERY(pQueryAttr) && (pQueryAttr->window.ekey > pQueryAttr->window.skey))) {
|
||||
//qDebug("QInfo:0x%"PRIx64" no result in time range %" PRId64 "-%" PRId64 ", order %d", pQInfo->qId, pQueryAttr->window.skey,
|
||||
// pQueryAttr->window.ekey, pQueryAttr->order.order);
|
||||
// setTaskStatus(pOperator->pTaskInfo, QUERY_COMPLETED);
|
||||
pRuntimeEnv->tableqinfoGroupInfo.numOfTables = 0;
|
||||
// todo free memory
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (pRuntimeEnv->tableqinfoGroupInfo.numOfTables == 0) {
|
||||
//qDebug("QInfo:0x%"PRIx64" no table qualified for tag filter, abort query", pQInfo->qId);
|
||||
// setTaskStatus(pOperator->pTaskInfo, QUERY_COMPLETED);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
// filter the qualified
|
||||
if ((code = doInitQInfo(pQInfo, pTsBuf, tsdb, sourceOptr, param->tableScanOperator, param->pOperator, merger)) != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
return code;
|
||||
|
||||
_error:
|
||||
// table query ref will be decrease during error handling
|
||||
// doDestroyTask(pQInfo);
|
||||
return code;
|
||||
}
|
||||
|
||||
//TODO refactor
|
||||
void freeColumnFilterInfo(SColumnFilterInfo* pFilter, int32_t numOfFilters) {
|
||||
if (pFilter == NULL || numOfFilters == 0) {
|
||||
|
|
|
@ -201,9 +201,9 @@ SOperatorInfo* createDummyOperator(int32_t startVal, int32_t numOfBlocks, int32_
|
|||
pOperator->name = "dummyInputOpertor4Test";
|
||||
|
||||
if (numOfCols == 1) {
|
||||
pOperator->nextDataFn = getDummyBlock;
|
||||
pOperator->getNextFn = getDummyBlock;
|
||||
} else {
|
||||
pOperator->nextDataFn = get2ColsDummyBlock;
|
||||
pOperator->getNextFn = get2ColsDummyBlock;
|
||||
}
|
||||
|
||||
SDummyInputInfo *pInfo = (SDummyInputInfo*) calloc(1, sizeof(SDummyInputInfo));
|
||||
|
@ -971,7 +971,7 @@ TEST(testCase, inMem_sort_Test) {
|
|||
SOperatorInfo* pOperator = createOrderOperatorInfo(createDummyOperator(10000, 5, 1000, data_asc, 1), pExprInfo, pOrderVal, NULL);
|
||||
|
||||
bool newgroup = false;
|
||||
SSDataBlock* pRes = pOperator->nextDataFn(pOperator, &newgroup);
|
||||
SSDataBlock* pRes = pOperator->getNextFn(pOperator, &newgroup);
|
||||
|
||||
SColumnInfoData* pCol1 = static_cast<SColumnInfoData*>(taosArrayGet(pRes->pDataBlock, 0));
|
||||
SColumnInfoData* pCol2 = static_cast<SColumnInfoData*>(taosArrayGet(pRes->pDataBlock, 1));
|
||||
|
@ -1019,7 +1019,7 @@ TEST(testCase, external_sort_Test) {
|
|||
return;
|
||||
#endif
|
||||
|
||||
taosSeedRand(time(NULL));
|
||||
taosSeedRand(taosGetTimestampSec());
|
||||
|
||||
SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
|
||||
SOrder o = {0};
|
||||
|
@ -1049,7 +1049,7 @@ TEST(testCase, external_sort_Test) {
|
|||
|
||||
while(1) {
|
||||
int64_t s = taosGetTimestampUs();
|
||||
pRes = pOperator->nextDataFn(pOperator, &newgroup);
|
||||
pRes = pOperator->getNextFn(pOperator, &newgroup);
|
||||
|
||||
int64_t e = taosGetTimestampUs();
|
||||
if (t++ == 1) {
|
||||
|
@ -1080,7 +1080,7 @@ TEST(testCase, external_sort_Test) {
|
|||
}
|
||||
|
||||
TEST(testCase, sorted_merge_Test) {
|
||||
taosSeedRand(time(NULL));
|
||||
taosSeedRand(taosGetTimestampSec());
|
||||
|
||||
SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
|
||||
SOrder o = {0};
|
||||
|
@ -1121,7 +1121,7 @@ TEST(testCase, sorted_merge_Test) {
|
|||
|
||||
while(1) {
|
||||
int64_t s = taosGetTimestampUs();
|
||||
pRes = pOperator->nextDataFn(pOperator, &newgroup);
|
||||
pRes = pOperator->getNextFn(pOperator, &newgroup);
|
||||
|
||||
int64_t e = taosGetTimestampUs();
|
||||
if (t++ == 1) {
|
||||
|
@ -1152,7 +1152,7 @@ TEST(testCase, sorted_merge_Test) {
|
|||
}
|
||||
|
||||
TEST(testCase, time_interval_Operator_Test) {
|
||||
taosSeedRand(time(NULL));
|
||||
taosSeedRand(taosGetTimestampSec());
|
||||
|
||||
SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
|
||||
SOrder o = {0};
|
||||
|
@ -1199,7 +1199,7 @@ TEST(testCase, time_interval_Operator_Test) {
|
|||
|
||||
while(1) {
|
||||
int64_t s = taosGetTimestampUs();
|
||||
pRes = pOperator->nextDataFn(pOperator, &newgroup);
|
||||
pRes = pOperator->getNextFn(pOperator, &newgroup);
|
||||
|
||||
int64_t e = taosGetTimestampUs();
|
||||
if (t++ == 1) {
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
|
||||
TEST(testCase, linear_hash_Tests) {
|
||||
taosSeedRand(time(NULL));
|
||||
taosSeedRand(taosGetTimestampSec());
|
||||
|
||||
_hash_fn_t fn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT);
|
||||
#if 0
|
||||
|
|
|
@ -341,6 +341,8 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result
|
|||
// TODO: iterator mem and tidex
|
||||
STermValueType s = kTypeValue;
|
||||
|
||||
int64_t st = taosGetTimestampUs();
|
||||
|
||||
SIdxTempResult* tr = sIdxTempResultCreate();
|
||||
if (0 == indexCacheSearch(cache, query, tr, &s)) {
|
||||
if (s == kTypeDeletion) {
|
||||
|
@ -348,17 +350,23 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result
|
|||
// coloum already drop by other oper, no need to query tindex
|
||||
return 0;
|
||||
} else {
|
||||
st = taosGetTimestampUs();
|
||||
if (0 != indexTFileSearch(sIdx->tindex, query, tr)) {
|
||||
indexError("corrupt at index(TFile) col:%s val: %s", term->colName, term->colVal);
|
||||
goto END;
|
||||
}
|
||||
int64_t tfCost = taosGetTimestampUs() - st;
|
||||
indexInfo("tfile search cost: %" PRIu64 "us", tfCost);
|
||||
}
|
||||
} else {
|
||||
indexError("corrupt at index(cache) col:%s val: %s", term->colName, term->colVal);
|
||||
goto END;
|
||||
}
|
||||
int64_t cost = taosGetTimestampUs() - st;
|
||||
indexInfo("search cost: %" PRIu64 "us", cost);
|
||||
|
||||
sIdxTempResultMergeTo(*result, tr);
|
||||
|
||||
sIdxTempResultDestroy(tr);
|
||||
return 0;
|
||||
END:
|
||||
|
|
|
@ -276,7 +276,12 @@ static int indexQueryMem(MemTable* mem, CacheTerm* ct, EIndexQueryType qtype, SI
|
|||
} else if (c->operaType == DEL_VALUE) {
|
||||
INDEX_MERGE_ADD_DEL(tr->added, tr->deled, c->uid)
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else if (qtype == QUERY_PREFIX) {
|
||||
} else if (qtype == QUERY_SUFFIX) {
|
||||
} else if (qtype == QUERY_RANGE) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -284,6 +289,7 @@ static int indexQueryMem(MemTable* mem, CacheTerm* ct, EIndexQueryType qtype, SI
|
|||
return 0;
|
||||
}
|
||||
int indexCacheSearch(void* cache, SIndexTermQuery* query, SIdxTempResult* result, STermValueType* s) {
|
||||
int64_t st = taosGetTimestampUs();
|
||||
if (cache == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -312,12 +318,14 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SIdxTempResult* result
|
|||
// continue search in imm
|
||||
ret = indexQueryMem(imm, &ct, qtype, result, s);
|
||||
}
|
||||
|
||||
if (hasJson) {
|
||||
tfree(p);
|
||||
}
|
||||
|
||||
indexMemUnRef(mem);
|
||||
indexMemUnRef(imm);
|
||||
indexInfo("cache search, time cost %" PRIu64 "us", taosGetTimestampUs() - st);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -189,8 +189,8 @@ int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SIdxTempResul
|
|||
bool hasJson = INDEX_TYPE_CONTAIN_EXTERN_TYPE(term->colType, TSDB_DATA_TYPE_JSON);
|
||||
EIndexQueryType qtype = query->qType;
|
||||
|
||||
SArray* result = taosArrayInit(16, sizeof(uint64_t));
|
||||
int ret = -1;
|
||||
// SArray* result = taosArrayInit(16, sizeof(uint64_t));
|
||||
int ret = -1;
|
||||
// refactor to callback later
|
||||
if (qtype == QUERY_TERM) {
|
||||
uint64_t offset;
|
||||
|
@ -200,11 +200,18 @@ int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SIdxTempResul
|
|||
p = indexPackJsonData(term);
|
||||
sz = strlen(p);
|
||||
}
|
||||
int64_t st = taosGetTimestampUs();
|
||||
FstSlice key = fstSliceCreate(p, sz);
|
||||
if (fstGet(reader->fst, &key, &offset)) {
|
||||
indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, found table info in tindex", term->suid, term->colName,
|
||||
term->colVal);
|
||||
ret = tfileReaderLoadTableIds(reader, offset, result);
|
||||
int64_t et = taosGetTimestampUs();
|
||||
int64_t cost = et - st;
|
||||
indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, found table info in tindex, time cost: %" PRIu64 "us",
|
||||
term->suid, term->colName, term->colVal, cost);
|
||||
|
||||
ret = tfileReaderLoadTableIds(reader, offset, tr->total);
|
||||
cost = taosGetTimestampUs() - et;
|
||||
indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, load all table info, time cost: %" PRIu64 "us", term->suid,
|
||||
term->colName, term->colVal, cost);
|
||||
} else {
|
||||
indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, not found table info in tindex", term->suid, term->colName,
|
||||
term->colVal);
|
||||
|
@ -225,8 +232,8 @@ int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SIdxTempResul
|
|||
}
|
||||
tfileReaderUnRef(reader);
|
||||
|
||||
taosArrayAddAll(tr->total, result);
|
||||
taosArrayDestroy(result);
|
||||
// taosArrayAddAll(tr->total, result);
|
||||
// taosArrayDestroy(result);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -391,6 +398,7 @@ int indexTFileSearch(void* tfile, SIndexTermQuery* query, SIdxTempResult* result
|
|||
return ret;
|
||||
}
|
||||
|
||||
int64_t st = taosGetTimestampUs();
|
||||
IndexTFile* pTfile = tfile;
|
||||
|
||||
SIndexTerm* term = query->term;
|
||||
|
@ -399,6 +407,8 @@ int indexTFileSearch(void* tfile, SIndexTermQuery* query, SIdxTempResult* result
|
|||
if (reader == NULL) {
|
||||
return 0;
|
||||
}
|
||||
int64_t cost = taosGetTimestampUs() - st;
|
||||
indexInfo("index tfile stage 1 cost: %" PRId64 "", cost);
|
||||
|
||||
return tfileReaderSearch(reader, query, result);
|
||||
}
|
||||
|
|
|
@ -258,7 +258,7 @@ void checkFstCheckIterator() {
|
|||
// prefix search
|
||||
std::vector<uint64_t> result;
|
||||
|
||||
AutomationCtx* ctx = automCtxCreate((void*)"ab", AUTOMATION_ALWAYS);
|
||||
AutomationCtx* ctx = automCtxCreate((void*)"H", AUTOMATION_PREFIX);
|
||||
m->Search(ctx, result);
|
||||
std::cout << "size: " << result.size() << std::endl;
|
||||
// assert(result.size() == count);
|
||||
|
@ -328,11 +328,11 @@ void iterTFileReader(char* path, char* uid, char* colName, char* ver) {
|
|||
int main(int argc, char* argv[]) {
|
||||
// tool to check all kind of fst test
|
||||
// if (argc > 1) { validateTFile(argv[1]); }
|
||||
if (argc > 4) {
|
||||
// path suid colName ver
|
||||
iterTFileReader(argv[1], argv[2], argv[3], argv[4]);
|
||||
}
|
||||
// checkFstCheckIterator();
|
||||
// if (argc > 4) {
|
||||
// path suid colName ver
|
||||
// iterTFileReader(argv[1], argv[2], argv[3], argv[4]);
|
||||
//}
|
||||
checkFstCheckIterator();
|
||||
// checkFstLongTerm();
|
||||
// checkFstPrefixSearch();
|
||||
|
||||
|
|
|
@ -768,7 +768,7 @@ class IndexObj {
|
|||
int64_t s = taosGetTimestampUs();
|
||||
if (Search(mq, result) == 0) {
|
||||
int64_t e = taosGetTimestampUs();
|
||||
std::cout << "search one successfully and time cost:" << e - s << "\tquery col:" << colName
|
||||
std::cout << "search one successfully and time cost:" << e - s << "us\tquery col:" << colName
|
||||
<< "\t val: " << colVal << "\t size:" << taosArrayGetSize(result) << std::endl;
|
||||
} else {
|
||||
}
|
||||
|
@ -1106,6 +1106,7 @@ TEST_F(IndexEnv2, testIndex_del) {
|
|||
}
|
||||
index->Del("tag10", "Hello", 12);
|
||||
index->Del("tag10", "Hello", 11);
|
||||
EXPECT_EQ(98, index->SearchOne("tag10", "Hello"));
|
||||
|
||||
index->WriteMultiMillonData("tag10", "xxxxxxxxxxxxxx", 100 * 10000);
|
||||
index->Del("tag10", "Hello", 17);
|
||||
|
|
|
@ -131,7 +131,6 @@ static SNode* valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) {
|
|||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
COPY_SCALAR_FIELD(datum.d);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDB_DATA_TYPE_VARCHAR:
|
||||
case TSDB_DATA_TYPE_VARBINARY:
|
||||
|
|
|
@ -978,7 +978,6 @@ static int32_t datumToJson(const void* pObj, SJson* pJson) {
|
|||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
code = tjsonAddDoubleToObject(pJson, jkValueDatum, pNode->datum.d);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDB_DATA_TYPE_VARCHAR:
|
||||
case TSDB_DATA_TYPE_VARBINARY:
|
||||
|
@ -1042,7 +1041,6 @@ static int32_t jsonToDatum(const SJson* pJson, void* pObj) {
|
|||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
code = tjsonGetDoubleValue(pJson, jkValueDatum, &pNode->datum.d);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDB_DATA_TYPE_VARCHAR:
|
||||
case TSDB_DATA_TYPE_VARBINARY:
|
||||
|
|
|
@ -386,7 +386,6 @@ void* nodesGetValueFromNode(SValueNode *pNode) {
|
|||
case TSDB_DATA_TYPE_FLOAT:
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
return (void*)&pNode->datum.d;
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDB_DATA_TYPE_VARCHAR:
|
||||
case TSDB_DATA_TYPE_VARBINARY:
|
||||
|
|
|
@ -287,7 +287,6 @@ static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) {
|
|||
pVal->datum.d = strtold(pVal->literal, &endPtr);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDB_DATA_TYPE_VARCHAR:
|
||||
case TSDB_DATA_TYPE_VARBINARY: {
|
||||
|
@ -601,7 +600,6 @@ static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect, bool
|
|||
static int32_t getPositionValue(const SValueNode* pVal) {
|
||||
switch (pVal->node.resType.type) {
|
||||
case TSDB_DATA_TYPE_NULL:
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDB_DATA_TYPE_VARCHAR:
|
||||
|
@ -1438,7 +1436,6 @@ static void valueNodeToVariant(const SValueNode* pNode, SVariant* pVal) {
|
|||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
pVal->d = pNode->datum.d;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDB_DATA_TYPE_VARCHAR:
|
||||
case TSDB_DATA_TYPE_VARBINARY:
|
||||
|
|
|
@ -56,7 +56,7 @@ protected:
|
|||
const string syntaxTreeStr = toString(query_->pRoot, false);
|
||||
|
||||
SLogicNode* pLogicPlan = nullptr;
|
||||
SPlanContext cxt = { .queryId = 1, .pAstRoot = query_->pRoot };
|
||||
SPlanContext cxt = { .queryId = 1, .acctId = 0, .pAstRoot = query_->pRoot };
|
||||
code = createLogicPlan(&cxt, &pLogicPlan);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
cout << "sql:[" << cxt_.pSql << "] logic plan code:" << code << ", strerror:" << tstrerror(code) << endl;
|
||||
|
|
|
@ -495,7 +495,7 @@ int32_t qwExecTask(QW_FPARAMS_DEF, SQWTaskCtx *ctx, bool *queryEnd) {
|
|||
|
||||
ASSERT(pRes->info.rows > 0);
|
||||
|
||||
SInputData inputData = {.pData = pRes, .pTableRetrieveTsMap = NULL};
|
||||
SInputData inputData = {.pData = pRes};
|
||||
code = dsPutDataBlock(sinkHandle, &inputData, &qcontinue);
|
||||
if (code) {
|
||||
QW_TASK_ELOG("dsPutDataBlock failed, code:%s", tstrerror(code));
|
||||
|
|
|
@ -963,7 +963,7 @@ TEST(seqTest, randCase) {
|
|||
stubSetRpcSendResponse();
|
||||
stubSetCreateExecTask();
|
||||
|
||||
taosSeedRand(time(NULL));
|
||||
taosSeedRand(taosGetTimestampSec());
|
||||
|
||||
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
@ -1025,7 +1025,7 @@ TEST(seqTest, multithreadRand) {
|
|||
stubSetStringToPlan();
|
||||
stubSetRpcSendResponse();
|
||||
|
||||
taosSeedRand(time(NULL));
|
||||
taosSeedRand(taosGetTimestampSec());
|
||||
|
||||
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
@ -1076,7 +1076,7 @@ TEST(rcTest, shortExecshortDelay) {
|
|||
stubSetPutDataBlock();
|
||||
stubSetGetDataBlock();
|
||||
|
||||
taosSeedRand(time(NULL));
|
||||
taosSeedRand(taosGetTimestampSec());
|
||||
qwtTestStop = false;
|
||||
qwtTestQuitThreadNum = 0;
|
||||
|
||||
|
@ -1157,7 +1157,7 @@ TEST(rcTest, longExecshortDelay) {
|
|||
stubSetPutDataBlock();
|
||||
stubSetGetDataBlock();
|
||||
|
||||
taosSeedRand(time(NULL));
|
||||
taosSeedRand(taosGetTimestampSec());
|
||||
qwtTestStop = false;
|
||||
qwtTestQuitThreadNum = 0;
|
||||
|
||||
|
@ -1240,7 +1240,7 @@ TEST(rcTest, shortExeclongDelay) {
|
|||
stubSetPutDataBlock();
|
||||
stubSetGetDataBlock();
|
||||
|
||||
taosSeedRand(time(NULL));
|
||||
taosSeedRand(taosGetTimestampSec());
|
||||
qwtTestStop = false;
|
||||
qwtTestQuitThreadNum = 0;
|
||||
|
||||
|
@ -1324,7 +1324,7 @@ TEST(rcTest, dropTest) {
|
|||
stubSetPutDataBlock();
|
||||
stubSetGetDataBlock();
|
||||
|
||||
taosSeedRand(time(NULL));
|
||||
taosSeedRand(taosGetTimestampSec());
|
||||
|
||||
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
@ -1358,7 +1358,7 @@ TEST(rcTest, dropTest) {
|
|||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
taosSeedRand(time(NULL));
|
||||
taosSeedRand(taosGetTimestampSec());
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
|
|
@ -411,27 +411,26 @@ int32_t vectorConvertImpl(SScalarParam* pIn, SScalarParam* pOut) {
|
|||
}
|
||||
|
||||
int8_t gConvertTypes[TSDB_DATA_TYPE_BLOB+1][TSDB_DATA_TYPE_BLOB+1] = {
|
||||
/* NULL BOOL TINY SMAL INT BIG FLOA DOUB BINA TIME NCHA UTIN USMA UINT UBIG VARC VARB JSON DECI BLOB */
|
||||
/*NULL*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/*BOOL*/ 0, 0, 0, 3, 4, 5, 6, 7, 7, 9, 7, 0, 12, 13, 14, 7, 7, 0, 0, 0,
|
||||
/*TINY*/ 0, 0, 0, 3, 4, 5, 6, 7, 7, 9, 7, 3, 4, 5, 7, 7, 7, 0, 0, 0,
|
||||
/*SMAL*/ 0, 0, 0, 0, 4, 5, 6, 7, 7, 9, 7, 3, 4, 5, 7, 7, 7, 0, 0, 0,
|
||||
/*INT */ 0, 0, 0, 0, 0, 5, 6, 7, 7, 9, 7, 4, 4, 5, 7, 7, 7, 0, 0, 0,
|
||||
/*BIGI*/ 0, 0, 0, 0, 0, 0, 6, 7, 7, 0, 7, 5, 5, 5, 7, 7, 7, 0, 0, 0,
|
||||
/*FLOA*/ 0, 0, 0, 0, 0, 0, 0, 7, 7, 6, 7, 6, 6, 6, 6, 7, 7, 0, 0, 0,
|
||||
/*DOUB*/ 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0,
|
||||
/*BINA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 7, 7, 7, 7, 0, 0, 0, 0, 0,
|
||||
/*TIME*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 9, 7, 7, 7, 0, 0, 0,
|
||||
/*NCHA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 0, 0, 0, 0, 0,
|
||||
/*UTIN*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 14, 7, 7, 0, 0, 0,
|
||||
/*USMA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 14, 7, 7, 0, 0, 0,
|
||||
/*UINT*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 7, 7, 0, 0, 0,
|
||||
/*UBIG*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0,
|
||||
/*VARC*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/*VARB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/*JSON*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/*DECI*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/*BLOB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
/* NULL BOOL TINY SMAL INT BIG FLOA DOUB VARC TIME NCHA UTIN USMA UINT UBIG VARB JSON DECI BLOB */
|
||||
/*NULL*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/*BOOL*/ 0, 0, 0, 3, 4, 5, 6, 7, 7, 9, 7, 0, 12, 13, 14, 7, 0, 0, 0,
|
||||
/*TINY*/ 0, 0, 0, 3, 4, 5, 6, 7, 7, 9, 7, 3, 4, 5, 7, 7, 0, 0, 0,
|
||||
/*SMAL*/ 0, 0, 0, 0, 4, 5, 6, 7, 7, 9, 7, 3, 4, 5, 7, 7, 0, 0, 0,
|
||||
/*INT */ 0, 0, 0, 0, 0, 5, 6, 7, 7, 9, 7, 4, 4, 5, 7, 7, 0, 0, 0,
|
||||
/*BIGI*/ 0, 0, 0, 0, 0, 0, 6, 7, 7, 0, 7, 5, 5, 5, 7, 7, 0, 0, 0,
|
||||
/*FLOA*/ 0, 0, 0, 0, 0, 0, 0, 7, 7, 6, 7, 6, 6, 6, 6, 7, 0, 0, 0,
|
||||
/*DOUB*/ 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0,
|
||||
/*VARC*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 7, 7, 7, 7, 0, 0, 0, 0,
|
||||
/*TIME*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 9, 7, 7, 0, 0, 0,
|
||||
/*NCHA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 0, 0, 0, 0,
|
||||
/*UTIN*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 14, 7, 0, 0, 0,
|
||||
/*USMA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 14, 7, 0, 0, 0,
|
||||
/*UINT*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 7, 0, 0, 0,
|
||||
/*UBIG*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0,
|
||||
/*VARB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/*JSON*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/*DECI*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/*BLOB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
int32_t vectorGetConvertType(int32_t type1, int32_t type2) {
|
||||
|
|
|
@ -1286,7 +1286,7 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) {
|
|||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
taosSeedRand(time(NULL));
|
||||
taosSeedRand(taosGetTimestampSec());
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
|
|
@ -1435,7 +1435,7 @@ TEST(columnTest, greater_and_lower) {
|
|||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
taosSeedRand(time(NULL));
|
||||
taosSeedRand(taosGetTimestampSec());
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
|
|
@ -724,7 +724,7 @@ TEST(queryTest, flowCtrlCase) {
|
|||
|
||||
schtInitLogFile();
|
||||
|
||||
taosSeedRand(time(NULL));
|
||||
taosSeedRand(taosGetTimestampSec());
|
||||
|
||||
SArray *qnodeList = taosArrayInit(1, sizeof(SEp));
|
||||
|
||||
|
@ -873,7 +873,7 @@ TEST(multiThread, forceFree) {
|
|||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
taosSeedRand(time(NULL));
|
||||
taosSeedRand(taosGetTimestampSec());
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
|
|
@ -42,6 +42,12 @@ SyncIndex syncIndexMgrGetIndex(SSyncIndexMgr *pSyncIndexMgr, const SRaftId
|
|||
cJSON * syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr);
|
||||
char * syncIndexMgr2Str(SSyncIndexMgr *pSyncIndexMgr);
|
||||
|
||||
// for debug -------------------
|
||||
void syncIndexMgrPrint(SSyncIndexMgr *pObj);
|
||||
void syncIndexMgrPrint2(char *s, SSyncIndexMgr *pObj);
|
||||
void syncIndexMgrLog(SSyncIndexMgr *pObj);
|
||||
void syncIndexMgrLog2(char *s, SSyncIndexMgr *pObj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -211,11 +211,14 @@ int32_t syncNodeStopElectTimer(SSyncNode* pSyncNode);
|
|||
int32_t syncNodeRestartElectTimer(SSyncNode* pSyncNode, int32_t ms);
|
||||
int32_t syncNodeStartHeartbeatTimer(SSyncNode* pSyncNode);
|
||||
int32_t syncNodeStopHeartbeatTimer(SSyncNode* pSyncNode);
|
||||
cJSON* syncNode2Json(const SSyncNode* pSyncNode);
|
||||
char* syncNode2Str(const SSyncNode* pSyncNode);
|
||||
|
||||
// for debug
|
||||
cJSON* syncNode2Json(const SSyncNode* pSyncNode);
|
||||
char* syncNode2Str(const SSyncNode* pSyncNode);
|
||||
void syncNodePrint(char* s, const SSyncNode* pSyncNode);
|
||||
// for debug --------------
|
||||
void syncNodePrint(SSyncNode* pObj);
|
||||
void syncNodePrint2(char* s, SSyncNode* pObj);
|
||||
void syncNodeLog(SSyncNode* pObj);
|
||||
void syncNodeLog2(char* s, SSyncNode* pObj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -47,6 +47,12 @@ cJSON* syncRpcMsg2Json(SRpcMsg* pRpcMsg);
|
|||
cJSON* syncRpcUnknownMsg2Json();
|
||||
char* syncRpcMsg2Str(SRpcMsg* pRpcMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncRpcMsgPrint(SRpcMsg* pMsg);
|
||||
void syncRpcMsgPrint2(char* s, SRpcMsg* pMsg);
|
||||
void syncRpcMsgLog(SRpcMsg* pMsg);
|
||||
void syncRpcMsgLog2(char* s, SRpcMsg* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef enum ESyncTimeoutType {
|
||||
SYNC_TIMEOUT_PING = 100,
|
||||
|
@ -60,17 +66,27 @@ typedef struct SyncTimeout {
|
|||
ESyncTimeoutType timeoutType;
|
||||
uint64_t logicClock;
|
||||
int32_t timerMS;
|
||||
void* data;
|
||||
void* data; // need optimized
|
||||
} SyncTimeout;
|
||||
|
||||
SyncTimeout* syncTimeoutBuild();
|
||||
SyncTimeout* syncTimeoutBuild2(ESyncTimeoutType timeoutType, uint64_t logicClock, int32_t timerMS, void* data);
|
||||
void syncTimeoutDestroy(SyncTimeout* pMsg);
|
||||
void syncTimeoutSerialize(const SyncTimeout* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncTimeoutDeserialize(const char* buf, uint32_t len, SyncTimeout* pMsg);
|
||||
char* syncTimeoutSerialize2(const SyncTimeout* pMsg, uint32_t* len); //
|
||||
SyncTimeout* syncTimeoutDeserialize2(const char* buf, uint32_t len); //
|
||||
void syncTimeout2RpcMsg(const SyncTimeout* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncTimeoutFromRpcMsg(const SRpcMsg* pRpcMsg, SyncTimeout* pMsg);
|
||||
SyncTimeout* syncTimeoutFromRpcMsg2(const SRpcMsg* pRpcMsg); //
|
||||
cJSON* syncTimeout2Json(const SyncTimeout* pMsg);
|
||||
SyncTimeout* syncTimeoutBuild2(ESyncTimeoutType timeoutType, uint64_t logicClock, int32_t timerMS, void* data);
|
||||
char* syncTimeout2Str(const SyncTimeout* pMsg); //
|
||||
|
||||
// for debug ----------------------
|
||||
void syncTimeoutPrint(const SyncTimeout* pMsg);
|
||||
void syncTimeoutPrint2(char* s, const SyncTimeout* pMsg);
|
||||
void syncTimeoutLog(const SyncTimeout* pMsg);
|
||||
void syncTimeoutLog2(char* s, const SyncTimeout* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncPing {
|
||||
|
@ -83,17 +99,25 @@ typedef struct SyncPing {
|
|||
char data[];
|
||||
} SyncPing;
|
||||
|
||||
#define SYNC_PING_FIX_LEN (sizeof(uint32_t) + sizeof(uint32_t) + sizeof(SRaftId) + sizeof(SRaftId) + sizeof(uint32_t))
|
||||
|
||||
SyncPing* syncPingBuild(uint32_t dataLen);
|
||||
SyncPing* syncPingBuild2(const SRaftId* srcId, const SRaftId* destId, const char* str);
|
||||
SyncPing* syncPingBuild3(const SRaftId* srcId, const SRaftId* destId);
|
||||
void syncPingDestroy(SyncPing* pMsg);
|
||||
void syncPingSerialize(const SyncPing* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncPingDeserialize(const char* buf, uint32_t len, SyncPing* pMsg);
|
||||
char* syncPingSerialize2(const SyncPing* pMsg, uint32_t* len);
|
||||
SyncPing* syncPingDeserialize2(const char* buf, uint32_t len);
|
||||
void syncPing2RpcMsg(const SyncPing* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncPingFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPing* pMsg);
|
||||
SyncPing* syncPingFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncPing2Json(const SyncPing* pMsg);
|
||||
SyncPing* syncPingBuild2(const SRaftId* srcId, const SRaftId* destId, const char* str);
|
||||
SyncPing* syncPingBuild3(const SRaftId* srcId, const SRaftId* destId);
|
||||
char* syncPing2Str(const SyncPing* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncPingPrint(const SyncPing* pMsg);
|
||||
void syncPingPrint2(char* s, const SyncPing* pMsg);
|
||||
void syncPingLog(const SyncPing* pMsg);
|
||||
void syncPingLog2(char* s, const SyncPing* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncPingReply {
|
||||
|
@ -106,18 +130,25 @@ typedef struct SyncPingReply {
|
|||
char data[];
|
||||
} SyncPingReply;
|
||||
|
||||
#define SYNC_PING_REPLY_FIX_LEN \
|
||||
(sizeof(uint32_t) + sizeof(uint32_t) + sizeof(SRaftId) + sizeof(SRaftId) + sizeof(uint32_t))
|
||||
|
||||
SyncPingReply* syncPingReplyBuild(uint32_t dataLen);
|
||||
SyncPingReply* syncPingReplyBuild2(const SRaftId* srcId, const SRaftId* destId, const char* str);
|
||||
SyncPingReply* syncPingReplyBuild3(const SRaftId* srcId, const SRaftId* destId);
|
||||
void syncPingReplyDestroy(SyncPingReply* pMsg);
|
||||
void syncPingReplySerialize(const SyncPingReply* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncPingReplyDeserialize(const char* buf, uint32_t len, SyncPingReply* pMsg);
|
||||
char* syncPingReplySerialize2(const SyncPingReply* pMsg, uint32_t* len); //
|
||||
SyncPingReply* syncPingReplyDeserialize2(const char* buf, uint32_t len); //
|
||||
void syncPingReply2RpcMsg(const SyncPingReply* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncPingReplyFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPingReply* pMsg);
|
||||
SyncPingReply* syncPingReplyFromRpcMsg2(const SRpcMsg* pRpcMsg); //
|
||||
cJSON* syncPingReply2Json(const SyncPingReply* pMsg);
|
||||
SyncPingReply* syncPingReplyBuild2(const SRaftId* srcId, const SRaftId* destId, const char* str);
|
||||
SyncPingReply* syncPingReplyBuild3(const SRaftId* srcId, const SRaftId* destId);
|
||||
char* syncPingReply2Str(const SyncPingReply* pMsg); //
|
||||
|
||||
// for debug ----------------------
|
||||
void syncPingReplyPrint(const SyncPingReply* pMsg);
|
||||
void syncPingReplyPrint2(char* s, const SyncPingReply* pMsg);
|
||||
void syncPingReplyLog(const SyncPingReply* pMsg);
|
||||
void syncPingReplyLog2(char* s, const SyncPingReply* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncClientRequest {
|
||||
|
@ -131,13 +162,23 @@ typedef struct SyncClientRequest {
|
|||
} SyncClientRequest;
|
||||
|
||||
SyncClientRequest* syncClientRequestBuild(uint32_t dataLen);
|
||||
SyncClientRequest* syncClientRequestBuild2(const SRpcMsg* pOriginalRpcMsg, uint64_t seqNum, bool isWeak);
|
||||
void syncClientRequestDestroy(SyncClientRequest* pMsg);
|
||||
void syncClientRequestSerialize(const SyncClientRequest* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncClientRequestDeserialize(const char* buf, uint32_t len, SyncClientRequest* pMsg);
|
||||
char* syncClientRequestSerialize2(const SyncClientRequest* pMsg, uint32_t* len);
|
||||
SyncClientRequest* syncClientRequestDeserialize2(const char* buf, uint32_t len);
|
||||
void syncClientRequest2RpcMsg(const SyncClientRequest* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncClientRequestFromRpcMsg(const SRpcMsg* pRpcMsg, SyncClientRequest* pMsg);
|
||||
SyncClientRequest* syncClientRequestFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncClientRequest2Json(const SyncClientRequest* pMsg);
|
||||
SyncClientRequest* syncClientRequestBuild2(const SRpcMsg* pOriginalRpcMsg, uint64_t seqNum, bool isWeak);
|
||||
char* syncClientRequest2Str(const SyncClientRequest* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncClientRequestPrint(const SyncClientRequest* pMsg);
|
||||
void syncClientRequestPrint2(char* s, const SyncClientRequest* pMsg);
|
||||
void syncClientRequestLog(const SyncClientRequest* pMsg);
|
||||
void syncClientRequestLog2(char* s, const SyncClientRequest* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncClientRequestReply {
|
||||
|
@ -163,9 +204,19 @@ SyncRequestVote* syncRequestVoteBuild();
|
|||
void syncRequestVoteDestroy(SyncRequestVote* pMsg);
|
||||
void syncRequestVoteSerialize(const SyncRequestVote* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncRequestVoteDeserialize(const char* buf, uint32_t len, SyncRequestVote* pMsg);
|
||||
char* syncRequestVoteSerialize2(const SyncRequestVote* pMsg, uint32_t* len);
|
||||
SyncRequestVote* syncRequestVoteDeserialize2(const char* buf, uint32_t len);
|
||||
void syncRequestVote2RpcMsg(const SyncRequestVote* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncRequestVoteFromRpcMsg(const SRpcMsg* pRpcMsg, SyncRequestVote* pMsg);
|
||||
SyncRequestVote* syncRequestVoteFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncRequestVote2Json(const SyncRequestVote* pMsg);
|
||||
char* syncRequestVote2Str(const SyncRequestVote* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncRequestVotePrint(const SyncRequestVote* pMsg);
|
||||
void syncRequestVotePrint2(char* s, const SyncRequestVote* pMsg);
|
||||
void syncRequestVoteLog(const SyncRequestVote* pMsg);
|
||||
void syncRequestVoteLog2(char* s, const SyncRequestVote* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncRequestVoteReply {
|
||||
|
@ -178,13 +229,23 @@ typedef struct SyncRequestVoteReply {
|
|||
bool voteGranted;
|
||||
} SyncRequestVoteReply;
|
||||
|
||||
SyncRequestVoteReply* SyncRequestVoteReplyBuild();
|
||||
SyncRequestVoteReply* syncRequestVoteReplyBuild();
|
||||
void syncRequestVoteReplyDestroy(SyncRequestVoteReply* pMsg);
|
||||
void syncRequestVoteReplySerialize(const SyncRequestVoteReply* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncRequestVoteReplyDeserialize(const char* buf, uint32_t len, SyncRequestVoteReply* pMsg);
|
||||
char* syncRequestVoteReplySerialize2(const SyncRequestVoteReply* pMsg, uint32_t* len);
|
||||
SyncRequestVoteReply* syncRequestVoteReplyDeserialize2(const char* buf, uint32_t len);
|
||||
void syncRequestVoteReply2RpcMsg(const SyncRequestVoteReply* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncRequestVoteReplyFromRpcMsg(const SRpcMsg* pRpcMsg, SyncRequestVoteReply* pMsg);
|
||||
SyncRequestVoteReply* syncRequestVoteReplyFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncRequestVoteReply2Json(const SyncRequestVoteReply* pMsg);
|
||||
char* syncRequestVoteReply2Str(const SyncRequestVoteReply* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncRequestVoteReplyPrint(const SyncRequestVoteReply* pMsg);
|
||||
void syncRequestVoteReplyPrint2(char* s, const SyncRequestVoteReply* pMsg);
|
||||
void syncRequestVoteReplyLog(const SyncRequestVoteReply* pMsg);
|
||||
void syncRequestVoteReplyLog2(char* s, const SyncRequestVoteReply* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncAppendEntries {
|
||||
|
@ -200,17 +261,23 @@ typedef struct SyncAppendEntries {
|
|||
char data[];
|
||||
} SyncAppendEntries;
|
||||
|
||||
#define SYNC_APPEND_ENTRIES_FIX_LEN \
|
||||
(sizeof(uint32_t) + sizeof(uint32_t) + sizeof(SRaftId) + sizeof(SRaftId) + sizeof(SyncIndex) + sizeof(SyncTerm) + \
|
||||
sizeof(SyncIndex) + sizeof(uint32_t))
|
||||
|
||||
SyncAppendEntries* syncAppendEntriesBuild(uint32_t dataLen);
|
||||
void syncAppendEntriesDestroy(SyncAppendEntries* pMsg);
|
||||
void syncAppendEntriesSerialize(const SyncAppendEntries* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncAppendEntriesDeserialize(const char* buf, uint32_t len, SyncAppendEntries* pMsg);
|
||||
char* syncAppendEntriesSerialize2(const SyncAppendEntries* pMsg, uint32_t* len);
|
||||
SyncAppendEntries* syncAppendEntriesDeserialize2(const char* buf, uint32_t len);
|
||||
void syncAppendEntries2RpcMsg(const SyncAppendEntries* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncAppendEntriesFromRpcMsg(const SRpcMsg* pRpcMsg, SyncAppendEntries* pMsg);
|
||||
SyncAppendEntries* syncAppendEntriesFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncAppendEntries2Json(const SyncAppendEntries* pMsg);
|
||||
char* syncAppendEntries2Str(const SyncAppendEntries* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncAppendEntriesPrint(const SyncAppendEntries* pMsg);
|
||||
void syncAppendEntriesPrint2(char* s, const SyncAppendEntries* pMsg);
|
||||
void syncAppendEntriesLog(const SyncAppendEntries* pMsg);
|
||||
void syncAppendEntriesLog2(char* s, const SyncAppendEntries* pMsg);
|
||||
|
||||
// ---------------------------------------------
|
||||
typedef struct SyncAppendEntriesReply {
|
||||
|
@ -227,9 +294,19 @@ SyncAppendEntriesReply* syncAppendEntriesReplyBuild();
|
|||
void syncAppendEntriesReplyDestroy(SyncAppendEntriesReply* pMsg);
|
||||
void syncAppendEntriesReplySerialize(const SyncAppendEntriesReply* pMsg, char* buf, uint32_t bufLen);
|
||||
void syncAppendEntriesReplyDeserialize(const char* buf, uint32_t len, SyncAppendEntriesReply* pMsg);
|
||||
char* syncAppendEntriesReplySerialize2(const SyncAppendEntriesReply* pMsg, uint32_t* len);
|
||||
SyncAppendEntriesReply* syncAppendEntriesReplyDeserialize2(const char* buf, uint32_t len);
|
||||
void syncAppendEntriesReply2RpcMsg(const SyncAppendEntriesReply* pMsg, SRpcMsg* pRpcMsg);
|
||||
void syncAppendEntriesReplyFromRpcMsg(const SRpcMsg* pRpcMsg, SyncAppendEntriesReply* pMsg);
|
||||
SyncAppendEntriesReply* syncAppendEntriesReplyFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||
cJSON* syncAppendEntriesReply2Json(const SyncAppendEntriesReply* pMsg);
|
||||
char* syncAppendEntriesReply2Str(const SyncAppendEntriesReply* pMsg);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncAppendEntriesReplyPrint(const SyncAppendEntriesReply* pMsg);
|
||||
void syncAppendEntriesReplyPrint2(char* s, const SyncAppendEntriesReply* pMsg);
|
||||
void syncAppendEntriesReplyLog(const SyncAppendEntriesReply* pMsg);
|
||||
void syncAppendEntriesReplyLog2(char* s, const SyncAppendEntriesReply* pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -46,8 +46,12 @@ char* syncEntrySerialize(const SSyncRaftEntry* pEntry, uint32_t* len);
|
|||
SSyncRaftEntry* syncEntryDeserialize(const char* buf, uint32_t len);
|
||||
cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry);
|
||||
char* syncEntry2Str(const SSyncRaftEntry* pEntry);
|
||||
void syncEntryPrint(const SSyncRaftEntry* pEntry);
|
||||
void syncEntryPrint2(char *s, const SSyncRaftEntry* pEntry);
|
||||
|
||||
// for debug ----------------------
|
||||
void syncEntryPrint(const SSyncRaftEntry* pObj);
|
||||
void syncEntryPrint2(char* s, const SSyncRaftEntry* pObj);
|
||||
void syncEntryLog(const SSyncRaftEntry* pObj);
|
||||
void syncEntryLog2(char* s, const SSyncRaftEntry* pObj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -32,39 +32,24 @@ typedef struct SSyncLogStoreData {
|
|||
SWal* pWal;
|
||||
} SSyncLogStoreData;
|
||||
|
||||
SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode);
|
||||
|
||||
void logStoreDestory(SSyncLogStore* pLogStore);
|
||||
|
||||
// append one log entry
|
||||
int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry);
|
||||
|
||||
// get one log entry, user need to free pEntry->pCont
|
||||
SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode);
|
||||
void logStoreDestory(SSyncLogStore* pLogStore);
|
||||
int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry);
|
||||
SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index);
|
||||
|
||||
// truncate log with index, entries after the given index (>=index) will be deleted
|
||||
int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex);
|
||||
|
||||
// return index of last entry
|
||||
SyncIndex logStoreLastIndex(SSyncLogStore* pLogStore);
|
||||
|
||||
// return term of last entry
|
||||
SyncTerm logStoreLastTerm(SSyncLogStore* pLogStore);
|
||||
|
||||
// update log store commit index with "index"
|
||||
int32_t logStoreUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index);
|
||||
|
||||
// return commit index of log
|
||||
SyncIndex logStoreGetCommitIndex(SSyncLogStore* pLogStore);
|
||||
|
||||
int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex);
|
||||
SyncIndex logStoreLastIndex(SSyncLogStore* pLogStore);
|
||||
SyncTerm logStoreLastTerm(SSyncLogStore* pLogStore);
|
||||
int32_t logStoreUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index);
|
||||
SyncIndex logStoreGetCommitIndex(SSyncLogStore* pLogStore);
|
||||
SSyncRaftEntry* logStoreGetLastEntry(SSyncLogStore* pLogStore);
|
||||
|
||||
cJSON* logStore2Json(SSyncLogStore* pLogStore);
|
||||
|
||||
char* logStore2Str(SSyncLogStore* pLogStore);
|
||||
cJSON* logStore2Json(SSyncLogStore* pLogStore);
|
||||
char* logStore2Str(SSyncLogStore* pLogStore);
|
||||
|
||||
// for debug
|
||||
void logStorePrint(SSyncLogStore* pLogStore);
|
||||
void logStorePrint2(char* s, SSyncLogStore* pLogStore);
|
||||
void logStoreLog(SSyncLogStore* pLogStore);
|
||||
void logStoreLog2(char* s, SSyncLogStore* pLogStore);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -42,7 +42,12 @@ int32_t raftStoreClose(SRaftStore *pRaftStore);
|
|||
int32_t raftStorePersist(SRaftStore *pRaftStore);
|
||||
int32_t raftStoreSerialize(SRaftStore *pRaftStore, char *buf, size_t len);
|
||||
int32_t raftStoreDeserialize(SRaftStore *pRaftStore, char *buf, size_t len);
|
||||
void raftStorePrint(SRaftStore *pRaftStore);
|
||||
|
||||
// for debug -------------------
|
||||
void raftStorePrint(SRaftStore *pObj);
|
||||
void raftStorePrint2(char *s, SRaftStore *pObj);
|
||||
void raftStoreLog(SRaftStore *pObj);
|
||||
void raftStoreLog2(char *s, SRaftStore *pObj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -48,6 +48,12 @@ void voteGrantedReset(SVotesGranted *pVotesGranted, SyncTerm term);
|
|||
cJSON * voteGranted2Json(SVotesGranted *pVotesGranted);
|
||||
char * voteGranted2Str(SVotesGranted *pVotesGranted);
|
||||
|
||||
// for debug -------------------
|
||||
void voteGrantedPrint(SVotesGranted *pObj);
|
||||
void voteGrantedPrint2(char *s, SVotesGranted *pObj);
|
||||
void voteGrantedLog(SVotesGranted *pObj);
|
||||
void voteGrantedLog2(char *s, SVotesGranted *pObj);
|
||||
|
||||
// SVotesRespond -----------------------------
|
||||
typedef struct SVotesRespond {
|
||||
SRaftId (*replicas)[TSDB_MAX_REPLICA];
|
||||
|
@ -65,6 +71,12 @@ void votesRespondReset(SVotesRespond *pVotesRespond, SyncTerm term);
|
|||
cJSON * votesRespond2Json(SVotesRespond *pVotesRespond);
|
||||
char * votesRespond2Str(SVotesRespond *pVotesRespond);
|
||||
|
||||
// for debug -------------------
|
||||
void votesRespondPrint(SVotesRespond *pObj);
|
||||
void votesRespondPrint2(char *s, SVotesRespond *pObj);
|
||||
void votesRespondLog(SVotesRespond *pObj);
|
||||
void votesRespondLog2(char *s, SVotesRespond *pObj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -28,7 +28,7 @@ static void doSyncEnvStopTimer(SSyncEnv *pSyncEnv, tmr_h *pTimer);
|
|||
|
||||
int32_t syncEnvStart() {
|
||||
int32_t ret;
|
||||
taosSeedRand(time(NULL));
|
||||
taosSeedRand(taosGetTimestampSec());
|
||||
gSyncEnv = (SSyncEnv *)malloc(sizeof(SSyncEnv));
|
||||
assert(gSyncEnv != NULL);
|
||||
ret = doSyncEnvStart(gSyncEnv);
|
||||
|
|
|
@ -44,7 +44,7 @@ int32_t syncIOStart(char *host, uint16_t port) {
|
|||
gSyncIO = syncIOCreate(host, port);
|
||||
assert(gSyncIO != NULL);
|
||||
|
||||
taosSeedRand(time(NULL));
|
||||
taosSeedRand(taosGetTimestampSec());
|
||||
int32_t ret = syncIOStartInternal(gSyncIO);
|
||||
assert(ret == 0);
|
||||
|
||||
|
@ -263,7 +263,7 @@ static void *syncIOConsumerFunc(void *param) {
|
|||
} else if (pRpcMsg->msgType == SYNC_REQUEST_VOTE_REPLY) {
|
||||
if (io->FpOnSyncRequestVoteReply != NULL) {
|
||||
SyncRequestVoteReply *pSyncMsg;
|
||||
pSyncMsg = SyncRequestVoteReplyBuild();
|
||||
pSyncMsg = syncRequestVoteReplyBuild();
|
||||
syncRequestVoteReplyFromRpcMsg(pRpcMsg, pSyncMsg);
|
||||
io->FpOnSyncRequestVoteReply(io->pSyncNode, pSyncMsg);
|
||||
syncRequestVoteReplyDestroy(pSyncMsg);
|
||||
|
|
|
@ -97,4 +97,31 @@ char *syncIndexMgr2Str(SSyncIndexMgr *pSyncIndexMgr) {
|
|||
char * serialized = cJSON_Print(pJson);
|
||||
cJSON_Delete(pJson);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
// for debug -------------------
|
||||
void syncIndexMgrPrint(SSyncIndexMgr *pObj) {
|
||||
char *serialized = syncIndexMgr2Str(pObj);
|
||||
printf("syncIndexMgrPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncIndexMgrPrint2(char *s, SSyncIndexMgr *pObj) {
|
||||
char *serialized = syncIndexMgr2Str(pObj);
|
||||
printf("syncIndexMgrPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncIndexMgrLog(SSyncIndexMgr *pObj) {
|
||||
char *serialized = syncIndexMgr2Str(pObj);
|
||||
sTrace("syncIndexMgrLog | len:%lu | %s", strlen(serialized), serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncIndexMgrLog2(char *s, SSyncIndexMgr *pObj) {
|
||||
char *serialized = syncIndexMgr2Str(pObj);
|
||||
sTrace("syncIndexMgrLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
||||
free(serialized);
|
||||
}
|
|
@ -327,11 +327,31 @@ char* syncNode2Str(const SSyncNode* pSyncNode) {
|
|||
return serialized;
|
||||
}
|
||||
|
||||
void syncNodePrint(char* s, const SSyncNode* pSyncNode) {
|
||||
char* ss = syncNode2Str(pSyncNode);
|
||||
// sTrace("syncNodePrint: %s [len:%lu]| %s", s, strlen(ss), ss);
|
||||
fprintf(stderr, "syncNodePrint: %s [len:%lu]| %s", s, strlen(ss), ss);
|
||||
free(ss);
|
||||
// for debug --------------
|
||||
void syncNodePrint(SSyncNode* pObj) {
|
||||
char* serialized = syncNode2Str(pObj);
|
||||
printf("syncNodePrint | len:%lu | %s \n", strlen(serialized), serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncNodePrint2(char* s, SSyncNode* pObj) {
|
||||
char* serialized = syncNode2Str(pObj);
|
||||
printf("syncNodePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncNodeLog(SSyncNode* pObj) {
|
||||
char* serialized = syncNode2Str(pObj);
|
||||
sTrace("syncNodeLog | len:%lu | %s", strlen(serialized), serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncNodeLog2(char* s, SSyncNode* pObj) {
|
||||
char* serialized = syncNode2Str(pObj);
|
||||
sTrace("syncNodeLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRpcMsg* pMsg) {
|
||||
|
|
|
@ -23,39 +23,47 @@ cJSON* syncRpcMsg2Json(SRpcMsg* pRpcMsg) {
|
|||
|
||||
// in compiler optimization, switch case = if else constants
|
||||
if (pRpcMsg->msgType == SYNC_TIMEOUT) {
|
||||
SyncTimeout* pSyncMsg = (SyncTimeout*)pRpcMsg->pCont;
|
||||
SyncTimeout* pSyncMsg = syncTimeoutDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||
pRoot = syncTimeout2Json(pSyncMsg);
|
||||
syncTimeoutDestroy(pSyncMsg);
|
||||
|
||||
} else if (pRpcMsg->msgType == SYNC_PING) {
|
||||
SyncPing* pSyncMsg = (SyncPing*)pRpcMsg->pCont;
|
||||
SyncPing* pSyncMsg = syncPingDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||
pRoot = syncPing2Json(pSyncMsg);
|
||||
syncPingDestroy(pSyncMsg);
|
||||
|
||||
} else if (pRpcMsg->msgType == SYNC_PING_REPLY) {
|
||||
SyncPingReply* pSyncMsg = (SyncPingReply*)pRpcMsg->pCont;
|
||||
SyncPingReply* pSyncMsg = syncPingReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||
pRoot = syncPingReply2Json(pSyncMsg);
|
||||
syncPingReplyDestroy(pSyncMsg);
|
||||
|
||||
} else if (pRpcMsg->msgType == SYNC_CLIENT_REQUEST) {
|
||||
SyncClientRequest* pSyncMsg = (SyncClientRequest*)pRpcMsg->pCont;
|
||||
SyncClientRequest* pSyncMsg = syncClientRequestDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||
pRoot = syncClientRequest2Json(pSyncMsg);
|
||||
syncClientRequestDestroy(pSyncMsg);
|
||||
|
||||
} else if (pRpcMsg->msgType == SYNC_CLIENT_REQUEST_REPLY) {
|
||||
pRoot = syncRpcUnknownMsg2Json();
|
||||
|
||||
} else if (pRpcMsg->msgType == SYNC_REQUEST_VOTE) {
|
||||
SyncRequestVote* pSyncMsg = (SyncRequestVote*)pRpcMsg->pCont;
|
||||
SyncRequestVote* pSyncMsg = syncRequestVoteDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||
pRoot = syncRequestVote2Json(pSyncMsg);
|
||||
syncRequestVoteDestroy(pSyncMsg);
|
||||
|
||||
} else if (pRpcMsg->msgType == SYNC_REQUEST_VOTE_REPLY) {
|
||||
SyncRequestVoteReply* pSyncMsg = (SyncRequestVoteReply*)pRpcMsg->pCont;
|
||||
SyncRequestVoteReply* pSyncMsg = syncRequestVoteReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||
pRoot = syncRequestVoteReply2Json(pSyncMsg);
|
||||
syncRequestVoteReplyDestroy(pSyncMsg);
|
||||
|
||||
} else if (pRpcMsg->msgType == SYNC_APPEND_ENTRIES) {
|
||||
SyncAppendEntries* pSyncMsg = (SyncAppendEntries*)pRpcMsg->pCont;
|
||||
SyncAppendEntries* pSyncMsg = syncAppendEntriesDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||
pRoot = syncAppendEntries2Json(pSyncMsg);
|
||||
syncAppendEntriesDestroy(pSyncMsg);
|
||||
|
||||
} else if (pRpcMsg->msgType == SYNC_APPEND_ENTRIES_REPLY) {
|
||||
SyncAppendEntriesReply* pSyncMsg = (SyncAppendEntriesReply*)pRpcMsg->pCont;
|
||||
SyncAppendEntriesReply* pSyncMsg = syncAppendEntriesReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||
pRoot = syncAppendEntriesReply2Json(pSyncMsg);
|
||||
syncAppendEntriesReplyDestroy(pSyncMsg);
|
||||
|
||||
} else {
|
||||
pRoot = syncRpcUnknownMsg2Json();
|
||||
|
@ -72,7 +80,7 @@ cJSON* syncRpcUnknownMsg2Json() {
|
|||
cJSON_AddStringToObject(pRoot, "data", "known message");
|
||||
|
||||
cJSON* pJson = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(pJson, "SyncPing", pRoot);
|
||||
cJSON_AddItemToObject(pJson, "SyncUnknown", pRoot);
|
||||
return pJson;
|
||||
}
|
||||
|
||||
|
@ -83,6 +91,33 @@ char* syncRpcMsg2Str(SRpcMsg* pRpcMsg) {
|
|||
return serialized;
|
||||
}
|
||||
|
||||
// for debug ----------------------
|
||||
void syncRpcMsgPrint(SRpcMsg* pMsg) {
|
||||
char* serialized = syncRpcMsg2Str(pMsg);
|
||||
printf("syncRpcMsgPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncRpcMsgPrint2(char* s, SRpcMsg* pMsg) {
|
||||
char* serialized = syncRpcMsg2Str(pMsg);
|
||||
printf("syncRpcMsgPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncRpcMsgLog(SRpcMsg* pMsg) {
|
||||
char* serialized = syncRpcMsg2Str(pMsg);
|
||||
sTrace("syncRpcMsgLog | len:%lu | %s", strlen(serialized), serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncRpcMsgLog2(char* s, SRpcMsg* pMsg) {
|
||||
char* serialized = syncRpcMsg2Str(pMsg);
|
||||
sTrace("syncRpcMsgLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
// ---- message process SyncTimeout----
|
||||
SyncTimeout* syncTimeoutBuild() {
|
||||
uint32_t bytes = sizeof(SyncTimeout);
|
||||
|
@ -93,6 +128,15 @@ SyncTimeout* syncTimeoutBuild() {
|
|||
return pMsg;
|
||||
}
|
||||
|
||||
SyncTimeout* syncTimeoutBuild2(ESyncTimeoutType timeoutType, uint64_t logicClock, int32_t timerMS, void* data) {
|
||||
SyncTimeout* pMsg = syncTimeoutBuild();
|
||||
pMsg->timeoutType = timeoutType;
|
||||
pMsg->logicClock = logicClock;
|
||||
pMsg->timerMS = timerMS;
|
||||
pMsg->data = data;
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void syncTimeoutDestroy(SyncTimeout* pMsg) {
|
||||
if (pMsg != NULL) {
|
||||
free(pMsg);
|
||||
|
@ -109,6 +153,25 @@ void syncTimeoutDeserialize(const char* buf, uint32_t len, SyncTimeout* pMsg) {
|
|||
assert(len == pMsg->bytes);
|
||||
}
|
||||
|
||||
char* syncTimeoutSerialize2(const SyncTimeout* pMsg, uint32_t* len) {
|
||||
char* buf = malloc(pMsg->bytes);
|
||||
assert(buf != NULL);
|
||||
syncTimeoutSerialize(pMsg, buf, pMsg->bytes);
|
||||
if (len != NULL) {
|
||||
*len = pMsg->bytes;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
SyncTimeout* syncTimeoutDeserialize2(const char* buf, uint32_t len) {
|
||||
uint32_t bytes = *((uint32_t*)buf);
|
||||
SyncTimeout* pMsg = malloc(bytes);
|
||||
assert(pMsg != NULL);
|
||||
syncTimeoutDeserialize(buf, len, pMsg);
|
||||
assert(len == pMsg->bytes);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void syncTimeout2RpcMsg(const SyncTimeout* pMsg, SRpcMsg* pRpcMsg) {
|
||||
memset(pRpcMsg, 0, sizeof(*pRpcMsg));
|
||||
pRpcMsg->msgType = pMsg->msgType;
|
||||
|
@ -121,6 +184,11 @@ void syncTimeoutFromRpcMsg(const SRpcMsg* pRpcMsg, SyncTimeout* pMsg) {
|
|||
syncTimeoutDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
|
||||
}
|
||||
|
||||
SyncTimeout* syncTimeoutFromRpcMsg2(const SRpcMsg* pRpcMsg) {
|
||||
SyncTimeout* pMsg = syncTimeoutDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
cJSON* syncTimeout2Json(const SyncTimeout* pMsg) {
|
||||
char u64buf[128];
|
||||
|
||||
|
@ -139,18 +207,43 @@ cJSON* syncTimeout2Json(const SyncTimeout* pMsg) {
|
|||
return pJson;
|
||||
}
|
||||
|
||||
SyncTimeout* syncTimeoutBuild2(ESyncTimeoutType timeoutType, uint64_t logicClock, int32_t timerMS, void* data) {
|
||||
SyncTimeout* pMsg = syncTimeoutBuild();
|
||||
pMsg->timeoutType = timeoutType;
|
||||
pMsg->logicClock = logicClock;
|
||||
pMsg->timerMS = timerMS;
|
||||
pMsg->data = data;
|
||||
return pMsg;
|
||||
char* syncTimeout2Str(const SyncTimeout* pMsg) {
|
||||
cJSON* pJson = syncTimeout2Json(pMsg);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
cJSON_Delete(pJson);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
// for debug ----------------------
|
||||
void syncTimeoutPrint(const SyncTimeout* pMsg) {
|
||||
char* serialized = syncTimeout2Str(pMsg);
|
||||
printf("syncTimeoutPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncTimeoutPrint2(char* s, const SyncTimeout* pMsg) {
|
||||
char* serialized = syncTimeout2Str(pMsg);
|
||||
printf("syncTimeoutPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncTimeoutLog(const SyncTimeout* pMsg) {
|
||||
char* serialized = syncTimeout2Str(pMsg);
|
||||
sTrace("syncTimeoutLog | len:%lu | %s", strlen(serialized), serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncTimeoutLog2(char* s, const SyncTimeout* pMsg) {
|
||||
char* serialized = syncTimeout2Str(pMsg);
|
||||
sTrace("syncTimeoutLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
// ---- message process SyncPing----
|
||||
SyncPing* syncPingBuild(uint32_t dataLen) {
|
||||
uint32_t bytes = SYNC_PING_FIX_LEN + dataLen;
|
||||
uint32_t bytes = sizeof(SyncPing) + dataLen;
|
||||
SyncPing* pMsg = malloc(bytes);
|
||||
memset(pMsg, 0, bytes);
|
||||
pMsg->bytes = bytes;
|
||||
|
@ -159,6 +252,20 @@ SyncPing* syncPingBuild(uint32_t dataLen) {
|
|||
return pMsg;
|
||||
}
|
||||
|
||||
SyncPing* syncPingBuild2(const SRaftId* srcId, const SRaftId* destId, const char* str) {
|
||||
uint32_t dataLen = strlen(str) + 1;
|
||||
SyncPing* pMsg = syncPingBuild(dataLen);
|
||||
pMsg->srcId = *srcId;
|
||||
pMsg->destId = *destId;
|
||||
snprintf(pMsg->data, pMsg->dataLen, "%s", str);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
SyncPing* syncPingBuild3(const SRaftId* srcId, const SRaftId* destId) {
|
||||
SyncPing* pMsg = syncPingBuild2(srcId, destId, "ping");
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void syncPingDestroy(SyncPing* pMsg) {
|
||||
if (pMsg != NULL) {
|
||||
free(pMsg);
|
||||
|
@ -173,7 +280,26 @@ void syncPingSerialize(const SyncPing* pMsg, char* buf, uint32_t bufLen) {
|
|||
void syncPingDeserialize(const char* buf, uint32_t len, SyncPing* pMsg) {
|
||||
memcpy(pMsg, buf, len);
|
||||
assert(len == pMsg->bytes);
|
||||
assert(pMsg->bytes == SYNC_PING_FIX_LEN + pMsg->dataLen);
|
||||
assert(pMsg->bytes == sizeof(SyncPing) + pMsg->dataLen);
|
||||
}
|
||||
|
||||
char* syncPingSerialize2(const SyncPing* pMsg, uint32_t* len) {
|
||||
char* buf = malloc(pMsg->bytes);
|
||||
assert(buf != NULL);
|
||||
syncPingSerialize(pMsg, buf, pMsg->bytes);
|
||||
if (len != NULL) {
|
||||
*len = pMsg->bytes;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
SyncPing* syncPingDeserialize2(const char* buf, uint32_t len) {
|
||||
uint32_t bytes = *((uint32_t*)buf);
|
||||
SyncPing* pMsg = malloc(bytes);
|
||||
assert(pMsg != NULL);
|
||||
syncPingDeserialize(buf, len, pMsg);
|
||||
assert(len == pMsg->bytes);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void syncPing2RpcMsg(const SyncPing* pMsg, SRpcMsg* pRpcMsg) {
|
||||
|
@ -188,6 +314,11 @@ void syncPingFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPing* pMsg) {
|
|||
syncPingDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
|
||||
}
|
||||
|
||||
SyncPing* syncPingFromRpcMsg2(const SRpcMsg* pRpcMsg) {
|
||||
SyncPing* pMsg = syncPingDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
cJSON* syncPing2Json(const SyncPing* pMsg) {
|
||||
char u64buf[128];
|
||||
|
||||
|
@ -226,35 +357,75 @@ cJSON* syncPing2Json(const SyncPing* pMsg) {
|
|||
cJSON_AddItemToObject(pRoot, "destId", pDestId);
|
||||
|
||||
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
||||
cJSON_AddStringToObject(pRoot, "data", pMsg->data);
|
||||
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_AddItemToObject(pJson, "SyncPing", pRoot);
|
||||
return pJson;
|
||||
}
|
||||
|
||||
SyncPing* syncPingBuild2(const SRaftId* srcId, const SRaftId* destId, const char* str) {
|
||||
uint32_t dataLen = strlen(str) + 1;
|
||||
SyncPing* pMsg = syncPingBuild(dataLen);
|
||||
char* syncPing2Str(const SyncPing* pMsg) {
|
||||
cJSON* pJson = syncPing2Json(pMsg);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
cJSON_Delete(pJson);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
// for debug ----------------------
|
||||
void syncPingPrint(const SyncPing* pMsg) {
|
||||
char* serialized = syncPing2Str(pMsg);
|
||||
printf("syncPingPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncPingPrint2(char* s, const SyncPing* pMsg) {
|
||||
char* serialized = syncPing2Str(pMsg);
|
||||
printf("syncPingPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncPingLog(const SyncPing* pMsg) {
|
||||
char* serialized = syncPing2Str(pMsg);
|
||||
sTrace("syncPingLog | len:%lu | %s", strlen(serialized), serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncPingLog2(char* s, const SyncPing* pMsg) {
|
||||
char* serialized = syncPing2Str(pMsg);
|
||||
sTrace("syncPingLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
// ---- message process SyncPingReply----
|
||||
SyncPingReply* syncPingReplyBuild(uint32_t dataLen) {
|
||||
uint32_t bytes = sizeof(SyncPingReply) + dataLen;
|
||||
SyncPingReply* pMsg = malloc(bytes);
|
||||
memset(pMsg, 0, bytes);
|
||||
pMsg->bytes = bytes;
|
||||
pMsg->msgType = SYNC_PING_REPLY;
|
||||
pMsg->dataLen = dataLen;
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
SyncPingReply* syncPingReplyBuild2(const SRaftId* srcId, const SRaftId* destId, const char* str) {
|
||||
uint32_t dataLen = strlen(str) + 1;
|
||||
SyncPingReply* pMsg = syncPingReplyBuild(dataLen);
|
||||
pMsg->srcId = *srcId;
|
||||
pMsg->destId = *destId;
|
||||
snprintf(pMsg->data, pMsg->dataLen, "%s", str);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
SyncPing* syncPingBuild3(const SRaftId* srcId, const SRaftId* destId) {
|
||||
SyncPing* pMsg = syncPingBuild2(srcId, destId, "ping");
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
// ---- message process SyncPingReply----
|
||||
SyncPingReply* syncPingReplyBuild(uint32_t dataLen) {
|
||||
uint32_t bytes = SYNC_PING_REPLY_FIX_LEN + dataLen;
|
||||
SyncPingReply* pMsg = malloc(bytes);
|
||||
memset(pMsg, 0, bytes);
|
||||
pMsg->bytes = bytes;
|
||||
pMsg->msgType = SYNC_PING_REPLY;
|
||||
pMsg->dataLen = dataLen;
|
||||
SyncPingReply* syncPingReplyBuild3(const SRaftId* srcId, const SRaftId* destId) {
|
||||
SyncPingReply* pMsg = syncPingReplyBuild2(srcId, destId, "pang");
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
|
@ -272,7 +443,26 @@ void syncPingReplySerialize(const SyncPingReply* pMsg, char* buf, uint32_t bufLe
|
|||
void syncPingReplyDeserialize(const char* buf, uint32_t len, SyncPingReply* pMsg) {
|
||||
memcpy(pMsg, buf, len);
|
||||
assert(len == pMsg->bytes);
|
||||
assert(pMsg->bytes == SYNC_PING_FIX_LEN + pMsg->dataLen);
|
||||
assert(pMsg->bytes == sizeof(SyncPing) + pMsg->dataLen);
|
||||
}
|
||||
|
||||
char* syncPingReplySerialize2(const SyncPingReply* pMsg, uint32_t* len) {
|
||||
char* buf = malloc(pMsg->bytes);
|
||||
assert(buf != NULL);
|
||||
syncPingReplySerialize(pMsg, buf, pMsg->bytes);
|
||||
if (len != NULL) {
|
||||
*len = pMsg->bytes;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
SyncPingReply* syncPingReplyDeserialize2(const char* buf, uint32_t len) {
|
||||
uint32_t bytes = *((uint32_t*)buf);
|
||||
SyncPingReply* pMsg = malloc(bytes);
|
||||
assert(pMsg != NULL);
|
||||
syncPingReplyDeserialize(buf, len, pMsg);
|
||||
assert(len == pMsg->bytes);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void syncPingReply2RpcMsg(const SyncPingReply* pMsg, SRpcMsg* pRpcMsg) {
|
||||
|
@ -287,6 +477,11 @@ void syncPingReplyFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPingReply* pMsg) {
|
|||
syncPingReplyDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
|
||||
}
|
||||
|
||||
SyncPingReply* syncPingReplyFromRpcMsg2(const SRpcMsg* pRpcMsg) {
|
||||
SyncPingReply* pMsg = syncPingReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
cJSON* syncPingReply2Json(const SyncPingReply* pMsg) {
|
||||
char u64buf[128];
|
||||
|
||||
|
@ -325,25 +520,51 @@ cJSON* syncPingReply2Json(const SyncPingReply* pMsg) {
|
|||
cJSON_AddItemToObject(pRoot, "destId", pDestId);
|
||||
|
||||
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
||||
cJSON_AddStringToObject(pRoot, "data", pMsg->data);
|
||||
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_AddItemToObject(pJson, "SyncPingReply", pRoot);
|
||||
return pJson;
|
||||
}
|
||||
|
||||
SyncPingReply* syncPingReplyBuild2(const SRaftId* srcId, const SRaftId* destId, const char* str) {
|
||||
uint32_t dataLen = strlen(str) + 1;
|
||||
SyncPingReply* pMsg = syncPingReplyBuild(dataLen);
|
||||
pMsg->srcId = *srcId;
|
||||
pMsg->destId = *destId;
|
||||
snprintf(pMsg->data, pMsg->dataLen, "%s", str);
|
||||
return pMsg;
|
||||
char* syncPingReply2Str(const SyncPingReply* pMsg) {
|
||||
cJSON* pJson = syncPingReply2Json(pMsg);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
cJSON_Delete(pJson);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
SyncPingReply* syncPingReplyBuild3(const SRaftId* srcId, const SRaftId* destId) {
|
||||
SyncPingReply* pMsg = syncPingReplyBuild2(srcId, destId, "pang");
|
||||
return pMsg;
|
||||
// for debug ----------------------
|
||||
void syncPingReplyPrint(const SyncPingReply* pMsg) {
|
||||
char* serialized = syncPingReply2Str(pMsg);
|
||||
printf("syncPingReplyPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncPingReplyPrint2(char* s, const SyncPingReply* pMsg) {
|
||||
char* serialized = syncPingReply2Str(pMsg);
|
||||
printf("syncPingReplyPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncPingReplyLog(const SyncPingReply* pMsg) {
|
||||
char* serialized = syncPingReply2Str(pMsg);
|
||||
sTrace("syncPingReplyLog | len:%lu | %s", strlen(serialized), serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncPingReplyLog2(char* s, const SyncPingReply* pMsg) {
|
||||
char* serialized = syncPingReply2Str(pMsg);
|
||||
sTrace("syncPingReplyLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
// ---- message process SyncClientRequest----
|
||||
|
@ -359,6 +580,15 @@ SyncClientRequest* syncClientRequestBuild(uint32_t dataLen) {
|
|||
return pMsg;
|
||||
}
|
||||
|
||||
SyncClientRequest* syncClientRequestBuild2(const SRpcMsg* pOriginalRpcMsg, uint64_t seqNum, bool isWeak) {
|
||||
SyncClientRequest* pMsg = syncClientRequestBuild(pOriginalRpcMsg->contLen);
|
||||
pMsg->originalRpcType = pOriginalRpcMsg->msgType;
|
||||
pMsg->seqNum = seqNum;
|
||||
pMsg->isWeak = isWeak;
|
||||
memcpy(pMsg->data, pOriginalRpcMsg->pCont, pOriginalRpcMsg->contLen);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void syncClientRequestDestroy(SyncClientRequest* pMsg) {
|
||||
if (pMsg != NULL) {
|
||||
free(pMsg);
|
||||
|
@ -375,6 +605,25 @@ void syncClientRequestDeserialize(const char* buf, uint32_t len, SyncClientReque
|
|||
assert(len == pMsg->bytes);
|
||||
}
|
||||
|
||||
char* syncClientRequestSerialize2(const SyncClientRequest* pMsg, uint32_t* len) {
|
||||
char* buf = malloc(pMsg->bytes);
|
||||
assert(buf != NULL);
|
||||
syncClientRequestSerialize(pMsg, buf, pMsg->bytes);
|
||||
if (len != NULL) {
|
||||
*len = pMsg->bytes;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
SyncClientRequest* syncClientRequestDeserialize2(const char* buf, uint32_t len) {
|
||||
uint32_t bytes = *((uint32_t*)buf);
|
||||
SyncClientRequest* pMsg = malloc(bytes);
|
||||
assert(pMsg != NULL);
|
||||
syncClientRequestDeserialize(buf, len, pMsg);
|
||||
assert(len == pMsg->bytes);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void syncClientRequest2RpcMsg(const SyncClientRequest* pMsg, SRpcMsg* pRpcMsg) {
|
||||
memset(pRpcMsg, 0, sizeof(*pRpcMsg));
|
||||
pRpcMsg->msgType = pMsg->msgType;
|
||||
|
@ -387,6 +636,11 @@ void syncClientRequestFromRpcMsg(const SRpcMsg* pRpcMsg, SyncClientRequest* pMsg
|
|||
syncClientRequestDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
|
||||
}
|
||||
|
||||
SyncClientRequest* syncClientRequestFromRpcMsg2(const SRpcMsg* pRpcMsg) {
|
||||
SyncClientRequest* pMsg = syncClientRequestDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
cJSON* syncClientRequest2Json(const SyncClientRequest* pMsg) {
|
||||
char u64buf[128];
|
||||
|
||||
|
@ -399,18 +653,51 @@ cJSON* syncClientRequest2Json(const SyncClientRequest* pMsg) {
|
|||
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_AddItemToObject(pJson, "SyncClientRequest", pRoot);
|
||||
return pJson;
|
||||
}
|
||||
|
||||
SyncClientRequest* syncClientRequestBuild2(const SRpcMsg* pOriginalRpcMsg, uint64_t seqNum, bool isWeak) {
|
||||
SyncClientRequest* pMsg = syncClientRequestBuild(pOriginalRpcMsg->contLen);
|
||||
pMsg->originalRpcType = pOriginalRpcMsg->msgType;
|
||||
pMsg->seqNum = seqNum;
|
||||
pMsg->isWeak = isWeak;
|
||||
memcpy(pMsg->data, pOriginalRpcMsg->pCont, pOriginalRpcMsg->contLen);
|
||||
return pMsg;
|
||||
char* syncClientRequest2Str(const SyncClientRequest* pMsg) {
|
||||
cJSON* pJson = syncClientRequest2Json(pMsg);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
cJSON_Delete(pJson);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
// for debug ----------------------
|
||||
void syncClientRequestPrint(const SyncClientRequest* pMsg) {
|
||||
char* serialized = syncClientRequest2Str(pMsg);
|
||||
printf("syncClientRequestPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncClientRequestPrint2(char* s, const SyncClientRequest* pMsg) {
|
||||
char* serialized = syncClientRequest2Str(pMsg);
|
||||
printf("syncClientRequestPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncClientRequestLog(const SyncClientRequest* pMsg) {
|
||||
char* serialized = syncClientRequest2Str(pMsg);
|
||||
sTrace("syncClientRequestLog | len:%lu | %s", strlen(serialized), serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncClientRequestLog2(char* s, const SyncClientRequest* pMsg) {
|
||||
char* serialized = syncClientRequest2Str(pMsg);
|
||||
sTrace("syncClientRequestLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
// ---- message process SyncRequestVote----
|
||||
|
@ -439,6 +726,25 @@ void syncRequestVoteDeserialize(const char* buf, uint32_t len, SyncRequestVote*
|
|||
assert(len == pMsg->bytes);
|
||||
}
|
||||
|
||||
char* syncRequestVoteSerialize2(const SyncRequestVote* pMsg, uint32_t* len) {
|
||||
char* buf = malloc(pMsg->bytes);
|
||||
assert(buf != NULL);
|
||||
syncRequestVoteSerialize(pMsg, buf, pMsg->bytes);
|
||||
if (len != NULL) {
|
||||
*len = pMsg->bytes;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
SyncRequestVote* syncRequestVoteDeserialize2(const char* buf, uint32_t len) {
|
||||
uint32_t bytes = *((uint32_t*)buf);
|
||||
SyncRequestVote* pMsg = malloc(bytes);
|
||||
assert(pMsg != NULL);
|
||||
syncRequestVoteDeserialize(buf, len, pMsg);
|
||||
assert(len == pMsg->bytes);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void syncRequestVote2RpcMsg(const SyncRequestVote* pMsg, SRpcMsg* pRpcMsg) {
|
||||
memset(pRpcMsg, 0, sizeof(*pRpcMsg));
|
||||
pRpcMsg->msgType = pMsg->msgType;
|
||||
|
@ -451,6 +757,11 @@ void syncRequestVoteFromRpcMsg(const SRpcMsg* pRpcMsg, SyncRequestVote* pMsg) {
|
|||
syncRequestVoteDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
|
||||
}
|
||||
|
||||
SyncRequestVote* syncRequestVoteFromRpcMsg2(const SRpcMsg* pRpcMsg) {
|
||||
SyncRequestVote* pMsg = syncRequestVoteDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
cJSON* syncRequestVote2Json(const SyncRequestVote* pMsg) {
|
||||
char u64buf[128];
|
||||
|
||||
|
@ -499,8 +810,42 @@ cJSON* syncRequestVote2Json(const SyncRequestVote* pMsg) {
|
|||
return pJson;
|
||||
}
|
||||
|
||||
char* syncRequestVote2Str(const SyncRequestVote* pMsg) {
|
||||
cJSON* pJson = syncRequestVote2Json(pMsg);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
cJSON_Delete(pJson);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
// for debug ----------------------
|
||||
void syncRequestVotePrint(const SyncRequestVote* pMsg) {
|
||||
char* serialized = syncRequestVote2Str(pMsg);
|
||||
printf("syncRequestVotePrint | len:%lu | %s \n", strlen(serialized), serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncRequestVotePrint2(char* s, const SyncRequestVote* pMsg) {
|
||||
char* serialized = syncRequestVote2Str(pMsg);
|
||||
printf("syncRequestVotePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncRequestVoteLog(const SyncRequestVote* pMsg) {
|
||||
char* serialized = syncRequestVote2Str(pMsg);
|
||||
sTrace("syncRequestVoteLog | len:%lu | %s", strlen(serialized), serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncRequestVoteLog2(char* s, const SyncRequestVote* pMsg) {
|
||||
char* serialized = syncRequestVote2Str(pMsg);
|
||||
sTrace("syncRequestVoteLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
// ---- message process SyncRequestVoteReply----
|
||||
SyncRequestVoteReply* SyncRequestVoteReplyBuild() {
|
||||
SyncRequestVoteReply* syncRequestVoteReplyBuild() {
|
||||
uint32_t bytes = sizeof(SyncRequestVoteReply);
|
||||
SyncRequestVoteReply* pMsg = malloc(bytes);
|
||||
memset(pMsg, 0, bytes);
|
||||
|
@ -525,6 +870,25 @@ void syncRequestVoteReplyDeserialize(const char* buf, uint32_t len, SyncRequestV
|
|||
assert(len == pMsg->bytes);
|
||||
}
|
||||
|
||||
char* syncRequestVoteReplySerialize2(const SyncRequestVoteReply* pMsg, uint32_t* len) {
|
||||
char* buf = malloc(pMsg->bytes);
|
||||
assert(buf != NULL);
|
||||
syncRequestVoteReplySerialize(pMsg, buf, pMsg->bytes);
|
||||
if (len != NULL) {
|
||||
*len = pMsg->bytes;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
SyncRequestVoteReply* syncRequestVoteReplyDeserialize2(const char* buf, uint32_t len) {
|
||||
uint32_t bytes = *((uint32_t*)buf);
|
||||
SyncRequestVoteReply* pMsg = malloc(bytes);
|
||||
assert(pMsg != NULL);
|
||||
syncRequestVoteReplyDeserialize(buf, len, pMsg);
|
||||
assert(len == pMsg->bytes);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void syncRequestVoteReply2RpcMsg(const SyncRequestVoteReply* pMsg, SRpcMsg* pRpcMsg) {
|
||||
memset(pRpcMsg, 0, sizeof(*pRpcMsg));
|
||||
pRpcMsg->msgType = pMsg->msgType;
|
||||
|
@ -537,6 +901,11 @@ void syncRequestVoteReplyFromRpcMsg(const SRpcMsg* pRpcMsg, SyncRequestVoteReply
|
|||
syncRequestVoteReplyDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
|
||||
}
|
||||
|
||||
SyncRequestVoteReply* syncRequestVoteReplyFromRpcMsg2(const SRpcMsg* pRpcMsg) {
|
||||
SyncRequestVoteReply* pMsg = syncRequestVoteReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
cJSON* syncRequestVoteReply2Json(const SyncRequestVoteReply* pMsg) {
|
||||
char u64buf[128];
|
||||
|
||||
|
@ -582,9 +951,43 @@ cJSON* syncRequestVoteReply2Json(const SyncRequestVoteReply* pMsg) {
|
|||
return pJson;
|
||||
}
|
||||
|
||||
char* syncRequestVoteReply2Str(const SyncRequestVoteReply* pMsg) {
|
||||
cJSON* pJson = syncRequestVoteReply2Json(pMsg);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
cJSON_Delete(pJson);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
// for debug ----------------------
|
||||
void syncRequestVoteReplyPrint(const SyncRequestVoteReply* pMsg) {
|
||||
char* serialized = syncRequestVoteReply2Str(pMsg);
|
||||
printf("syncRequestVoteReplyPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncRequestVoteReplyPrint2(char* s, const SyncRequestVoteReply* pMsg) {
|
||||
char* serialized = syncRequestVoteReply2Str(pMsg);
|
||||
printf("syncRequestVoteReplyPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncRequestVoteReplyLog(const SyncRequestVoteReply* pMsg) {
|
||||
char* serialized = syncRequestVoteReply2Str(pMsg);
|
||||
sTrace("syncRequestVoteReplyLog | len:%lu | %s", strlen(serialized), serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncRequestVoteReplyLog2(char* s, const SyncRequestVoteReply* pMsg) {
|
||||
char* serialized = syncRequestVoteReply2Str(pMsg);
|
||||
sTrace("syncRequestVoteReplyLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
// ---- message process SyncAppendEntries----
|
||||
SyncAppendEntries* syncAppendEntriesBuild(uint32_t dataLen) {
|
||||
uint32_t bytes = SYNC_APPEND_ENTRIES_FIX_LEN + dataLen;
|
||||
uint32_t bytes = sizeof(SyncAppendEntries) + dataLen;
|
||||
SyncAppendEntries* pMsg = malloc(bytes);
|
||||
memset(pMsg, 0, bytes);
|
||||
pMsg->bytes = bytes;
|
||||
|
@ -607,7 +1010,26 @@ void syncAppendEntriesSerialize(const SyncAppendEntries* pMsg, char* buf, uint32
|
|||
void syncAppendEntriesDeserialize(const char* buf, uint32_t len, SyncAppendEntries* pMsg) {
|
||||
memcpy(pMsg, buf, len);
|
||||
assert(len == pMsg->bytes);
|
||||
assert(pMsg->bytes == SYNC_APPEND_ENTRIES_FIX_LEN + pMsg->dataLen);
|
||||
assert(pMsg->bytes == sizeof(SyncAppendEntries) + pMsg->dataLen);
|
||||
}
|
||||
|
||||
char* syncAppendEntriesSerialize2(const SyncAppendEntries* pMsg, uint32_t* len) {
|
||||
char* buf = malloc(pMsg->bytes);
|
||||
assert(buf != NULL);
|
||||
syncAppendEntriesSerialize(pMsg, buf, pMsg->bytes);
|
||||
if (len != NULL) {
|
||||
*len = pMsg->bytes;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
SyncAppendEntries* syncAppendEntriesDeserialize2(const char* buf, uint32_t len) {
|
||||
uint32_t bytes = *((uint32_t*)buf);
|
||||
SyncAppendEntries* pMsg = malloc(bytes);
|
||||
assert(pMsg != NULL);
|
||||
syncAppendEntriesDeserialize(buf, len, pMsg);
|
||||
assert(len == pMsg->bytes);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void syncAppendEntries2RpcMsg(const SyncAppendEntries* pMsg, SRpcMsg* pRpcMsg) {
|
||||
|
@ -622,6 +1044,11 @@ void syncAppendEntriesFromRpcMsg(const SRpcMsg* pRpcMsg, SyncAppendEntries* pMsg
|
|||
syncAppendEntriesDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
|
||||
}
|
||||
|
||||
SyncAppendEntries* syncAppendEntriesFromRpcMsg2(const SRpcMsg* pRpcMsg) {
|
||||
SyncAppendEntries* pMsg = syncAppendEntriesDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
cJSON* syncAppendEntries2Json(const SyncAppendEntries* pMsg) {
|
||||
char u64buf[128];
|
||||
|
||||
|
@ -669,13 +1096,53 @@ cJSON* syncAppendEntries2Json(const SyncAppendEntries* pMsg) {
|
|||
cJSON_AddStringToObject(pRoot, "commit_index", u64buf);
|
||||
|
||||
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
||||
cJSON_AddStringToObject(pRoot, "data", pMsg->data);
|
||||
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_AddItemToObject(pJson, "SyncAppendEntries", pRoot);
|
||||
return pJson;
|
||||
}
|
||||
|
||||
char* syncAppendEntries2Str(const SyncAppendEntries* pMsg) {
|
||||
cJSON* pJson = syncAppendEntries2Json(pMsg);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
cJSON_Delete(pJson);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
// for debug ----------------------
|
||||
void syncAppendEntriesPrint(const SyncAppendEntries* pMsg) {
|
||||
char* serialized = syncAppendEntries2Str(pMsg);
|
||||
printf("syncAppendEntriesPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncAppendEntriesPrint2(char* s, const SyncAppendEntries* pMsg) {
|
||||
char* serialized = syncAppendEntries2Str(pMsg);
|
||||
printf("syncAppendEntriesPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncAppendEntriesLog(const SyncAppendEntries* pMsg) {
|
||||
char* serialized = syncAppendEntries2Str(pMsg);
|
||||
sTrace("syncAppendEntriesLog | len:%lu | %s", strlen(serialized), serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncAppendEntriesLog2(char* s, const SyncAppendEntries* pMsg) {
|
||||
char* serialized = syncAppendEntries2Str(pMsg);
|
||||
sTrace("syncAppendEntriesLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
// ---- message process SyncAppendEntriesReply----
|
||||
SyncAppendEntriesReply* syncAppendEntriesReplyBuild() {
|
||||
uint32_t bytes = sizeof(SyncAppendEntriesReply);
|
||||
|
@ -702,6 +1169,25 @@ void syncAppendEntriesReplyDeserialize(const char* buf, uint32_t len, SyncAppend
|
|||
assert(len == pMsg->bytes);
|
||||
}
|
||||
|
||||
char* syncAppendEntriesReplySerialize2(const SyncAppendEntriesReply* pMsg, uint32_t* len) {
|
||||
char* buf = malloc(pMsg->bytes);
|
||||
assert(buf != NULL);
|
||||
syncAppendEntriesReplySerialize(pMsg, buf, pMsg->bytes);
|
||||
if (len != NULL) {
|
||||
*len = pMsg->bytes;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
SyncAppendEntriesReply* syncAppendEntriesReplyDeserialize2(const char* buf, uint32_t len) {
|
||||
uint32_t bytes = *((uint32_t*)buf);
|
||||
SyncAppendEntriesReply* pMsg = malloc(bytes);
|
||||
assert(pMsg != NULL);
|
||||
syncAppendEntriesReplyDeserialize(buf, len, pMsg);
|
||||
assert(len == pMsg->bytes);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void syncAppendEntriesReply2RpcMsg(const SyncAppendEntriesReply* pMsg, SRpcMsg* pRpcMsg) {
|
||||
memset(pRpcMsg, 0, sizeof(*pRpcMsg));
|
||||
pRpcMsg->msgType = pMsg->msgType;
|
||||
|
@ -714,6 +1200,11 @@ void syncAppendEntriesReplyFromRpcMsg(const SRpcMsg* pRpcMsg, SyncAppendEntriesR
|
|||
syncAppendEntriesReplyDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
|
||||
}
|
||||
|
||||
SyncAppendEntriesReply* syncAppendEntriesReplyFromRpcMsg2(const SRpcMsg* pRpcMsg) {
|
||||
SyncAppendEntriesReply* pMsg = syncAppendEntriesReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
cJSON* syncAppendEntriesReply2Json(const SyncAppendEntriesReply* pMsg) {
|
||||
char u64buf[128];
|
||||
|
||||
|
@ -758,4 +1249,38 @@ cJSON* syncAppendEntriesReply2Json(const SyncAppendEntriesReply* pMsg) {
|
|||
cJSON* pJson = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(pJson, "SyncAppendEntriesReply", pRoot);
|
||||
return pJson;
|
||||
}
|
||||
|
||||
char* syncAppendEntriesReply2Str(const SyncAppendEntriesReply* pMsg) {
|
||||
cJSON* pJson = syncAppendEntriesReply2Json(pMsg);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
cJSON_Delete(pJson);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
// for debug ----------------------
|
||||
void syncAppendEntriesReplyPrint(const SyncAppendEntriesReply* pMsg) {
|
||||
char* serialized = syncAppendEntriesReply2Str(pMsg);
|
||||
printf("syncAppendEntriesReplyPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncAppendEntriesReplyPrint2(char* s, const SyncAppendEntriesReply* pMsg) {
|
||||
char* serialized = syncAppendEntriesReply2Str(pMsg);
|
||||
printf("syncAppendEntriesReplyPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncAppendEntriesReplyLog(const SyncAppendEntriesReply* pMsg) {
|
||||
char* serialized = syncAppendEntriesReply2Str(pMsg);
|
||||
sTrace("syncAppendEntriesReplyLog | len:%lu | %s", strlen(serialized), serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncAppendEntriesReplyLog2(char* s, const SyncAppendEntriesReply* pMsg) {
|
||||
char* serialized = syncAppendEntriesReply2Str(pMsg);
|
||||
sTrace("syncAppendEntriesReplyLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
||||
free(serialized);
|
||||
}
|
|
@ -104,14 +104,29 @@ char* syncEntry2Str(const SSyncRaftEntry* pEntry) {
|
|||
return serialized;
|
||||
}
|
||||
|
||||
void syncEntryPrint(const SSyncRaftEntry* pEntry) {
|
||||
char* s = syncEntry2Str(pEntry);
|
||||
sTrace("%s", s);
|
||||
free(s);
|
||||
// for debug ----------------------
|
||||
void syncEntryPrint(const SSyncRaftEntry* pObj) {
|
||||
char* serialized = syncEntry2Str(pObj);
|
||||
printf("syncEntryPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncEntryPrint2(char* s, const SSyncRaftEntry* pEntry) {
|
||||
char* ss = syncEntry2Str(pEntry);
|
||||
sTrace("%s | %s", s, ss);
|
||||
free(ss);
|
||||
void syncEntryPrint2(char* s, const SSyncRaftEntry* pObj) {
|
||||
char* serialized = syncEntry2Str(pObj);
|
||||
printf("syncEntryPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncEntryLog(const SSyncRaftEntry* pObj) {
|
||||
char* serialized = syncEntry2Str(pObj);
|
||||
sTrace("syncEntryLog | len:%lu | %s", strlen(serialized), serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void syncEntryLog2(char* s, const SSyncRaftEntry* pObj) {
|
||||
char* serialized = syncEntry2Str(pObj);
|
||||
sTrace("syncEntryLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
||||
free(serialized);
|
||||
}
|
|
@ -43,7 +43,6 @@ void logStoreDestory(SSyncLogStore* pLogStore) {
|
|||
}
|
||||
}
|
||||
|
||||
// append one log entry
|
||||
int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) {
|
||||
SSyncLogStoreData* pData = pLogStore->data;
|
||||
SWal* pWal = pData->pWal;
|
||||
|
@ -61,7 +60,6 @@ int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) {
|
|||
free(serialized);
|
||||
}
|
||||
|
||||
// get one log entry, user need to free pEntry->pCont
|
||||
SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) {
|
||||
SSyncLogStoreData* pData = pLogStore->data;
|
||||
SWal* pWal = pData->pWal;
|
||||
|
@ -77,14 +75,12 @@ SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) {
|
|||
return pEntry;
|
||||
}
|
||||
|
||||
// truncate log with index, entries after the given index (>=index) will be deleted
|
||||
int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex) {
|
||||
SSyncLogStoreData* pData = pLogStore->data;
|
||||
SWal* pWal = pData->pWal;
|
||||
walRollback(pWal, fromIndex);
|
||||
}
|
||||
|
||||
// return index of last entry
|
||||
SyncIndex logStoreLastIndex(SSyncLogStore* pLogStore) {
|
||||
SSyncLogStoreData* pData = pLogStore->data;
|
||||
SWal* pWal = pData->pWal;
|
||||
|
@ -92,7 +88,6 @@ SyncIndex logStoreLastIndex(SSyncLogStore* pLogStore) {
|
|||
return lastIndex;
|
||||
}
|
||||
|
||||
// return term of last entry
|
||||
SyncTerm logStoreLastTerm(SSyncLogStore* pLogStore) {
|
||||
SyncTerm lastTerm = 0;
|
||||
SSyncRaftEntry* pLastEntry = logStoreGetLastEntry(pLogStore);
|
||||
|
@ -103,14 +98,12 @@ SyncTerm logStoreLastTerm(SSyncLogStore* pLogStore) {
|
|||
return lastTerm;
|
||||
}
|
||||
|
||||
// update log store commit index with "index"
|
||||
int32_t logStoreUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index) {
|
||||
SSyncLogStoreData* pData = pLogStore->data;
|
||||
SWal* pWal = pData->pWal;
|
||||
walCommit(pWal, index);
|
||||
}
|
||||
|
||||
// return commit index of log
|
||||
SyncIndex logStoreGetCommitIndex(SSyncLogStore* pLogStore) {
|
||||
SSyncLogStoreData* pData = pLogStore->data;
|
||||
return pData->pSyncNode->commitIndex;
|
||||
|
@ -163,11 +156,29 @@ char* logStore2Str(SSyncLogStore* pLogStore) {
|
|||
return serialized;
|
||||
}
|
||||
|
||||
// for debug
|
||||
// for debug -----------------
|
||||
void logStorePrint(SSyncLogStore* pLogStore) {
|
||||
char* s = logStore2Str(pLogStore);
|
||||
// sTrace("%s", s);
|
||||
fprintf(stderr, "logStorePrint: [len:%lu]| %s \n", strlen(s), s);
|
||||
char* serialized = logStore2Str(pLogStore);
|
||||
printf("logStorePrint | len:%lu | %s \n", strlen(serialized), serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
free(s);
|
||||
void logStorePrint2(char* s, SSyncLogStore* pLogStore) {
|
||||
char* serialized = logStore2Str(pLogStore);
|
||||
printf("logStorePrint | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void logStoreLog(SSyncLogStore* pLogStore) {
|
||||
char* serialized = logStore2Str(pLogStore);
|
||||
sTrace("logStorePrint | len:%lu | %s", strlen(serialized), serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void logStoreLog2(char* s, SSyncLogStore* pLogStore) {
|
||||
char* serialized = logStore2Str(pLogStore);
|
||||
sTrace("logStorePrint | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
||||
free(serialized);
|
||||
}
|
|
@ -135,8 +135,30 @@ int32_t raftStoreDeserialize(SRaftStore *pRaftStore, char *buf, size_t len) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void raftStorePrint(SRaftStore *pRaftStore) {
|
||||
char storeBuf[RAFT_STORE_BLOCK_SIZE];
|
||||
raftStoreSerialize(pRaftStore, storeBuf, sizeof(storeBuf));
|
||||
printf("%s\n", storeBuf);
|
||||
// for debug -------------------
|
||||
void raftStorePrint(SRaftStore *pObj) {
|
||||
char serialized[RAFT_STORE_BLOCK_SIZE];
|
||||
raftStoreSerialize(pObj, serialized, sizeof(serialized));
|
||||
printf("raftStorePrint | len:%lu | %s \n", strlen(serialized), serialized);
|
||||
fflush(NULL);
|
||||
}
|
||||
|
||||
void raftStorePrint2(char *s, SRaftStore *pObj) {
|
||||
char serialized[RAFT_STORE_BLOCK_SIZE];
|
||||
raftStoreSerialize(pObj, serialized, sizeof(serialized));
|
||||
printf("raftStorePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
||||
fflush(NULL);
|
||||
}
|
||||
void raftStoreLog(SRaftStore *pObj) {
|
||||
char serialized[RAFT_STORE_BLOCK_SIZE];
|
||||
raftStoreSerialize(pObj, serialized, sizeof(serialized));
|
||||
sTrace("raftStoreLog | len:%lu | %s", strlen(serialized), serialized);
|
||||
fflush(NULL);
|
||||
}
|
||||
|
||||
void raftStoreLog2(char *s, SRaftStore *pObj) {
|
||||
char serialized[RAFT_STORE_BLOCK_SIZE];
|
||||
raftStoreSerialize(pObj, serialized, sizeof(serialized));
|
||||
sTrace("raftStoreLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
||||
fflush(NULL);
|
||||
}
|
||||
|
|
|
@ -119,6 +119,33 @@ char *voteGranted2Str(SVotesGranted *pVotesGranted) {
|
|||
return serialized;
|
||||
}
|
||||
|
||||
// for debug -------------------
|
||||
void voteGrantedPrint(SVotesGranted *pObj) {
|
||||
char *serialized = voteGranted2Str(pObj);
|
||||
printf("voteGrantedPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void voteGrantedPrint2(char *s, SVotesGranted *pObj) {
|
||||
char *serialized = voteGranted2Str(pObj);
|
||||
printf("voteGrantedPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void voteGrantedLog(SVotesGranted *pObj) {
|
||||
char *serialized = voteGranted2Str(pObj);
|
||||
sTrace("voteGrantedLog | len:%lu | %s", strlen(serialized), serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void voteGrantedLog2(char *s, SVotesGranted *pObj) {
|
||||
char *serialized = voteGranted2Str(pObj);
|
||||
sTrace("voteGrantedLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
// SVotesRespond -----------------------------
|
||||
SVotesRespond *votesRespondCreate(SSyncNode *pSyncNode) {
|
||||
SVotesRespond *pVotesRespond = malloc(sizeof(SVotesRespond));
|
||||
|
@ -210,4 +237,31 @@ char *votesRespond2Str(SVotesRespond *pVotesRespond) {
|
|||
char * serialized = cJSON_Print(pJson);
|
||||
cJSON_Delete(pJson);
|
||||
return serialized;
|
||||
}
|
||||
|
||||
// for debug -------------------
|
||||
void votesRespondPrint(SVotesRespond *pObj) {
|
||||
char *serialized = votesRespond2Str(pObj);
|
||||
printf("votesRespondPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void votesRespondPrint2(char *s, SVotesRespond *pObj) {
|
||||
char *serialized = votesRespond2Str(pObj);
|
||||
printf("votesRespondPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
||||
fflush(NULL);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void votesRespondLog(SVotesRespond *pObj) {
|
||||
char *serialized = votesRespond2Str(pObj);
|
||||
sTrace("votesRespondLog | len:%lu | %s", strlen(serialized), serialized);
|
||||
free(serialized);
|
||||
}
|
||||
|
||||
void votesRespondLog2(char *s, SVotesRespond *pObj) {
|
||||
char *serialized = votesRespond2Str(pObj);
|
||||
sTrace("votesRespondLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
||||
free(serialized);
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
add_executable(syncTest "")
|
||||
add_executable(syncEnvTest "")
|
||||
add_executable(syncPingTest "")
|
||||
add_executable(syncEncodeTest "")
|
||||
add_executable(syncPingTimerTest "")
|
||||
add_executable(syncIOTickQTest "")
|
||||
add_executable(syncIOTickPingTest "")
|
||||
add_executable(syncIOSendMsgTest "")
|
||||
|
@ -17,6 +16,15 @@ add_executable(syncVotesRespondTest "")
|
|||
add_executable(syncIndexMgrTest "")
|
||||
add_executable(syncLogStoreTest "")
|
||||
add_executable(syncEntryTest "")
|
||||
add_executable(syncRequestVoteTest "")
|
||||
add_executable(syncRequestVoteReplyTest "")
|
||||
add_executable(syncAppendEntriesTest "")
|
||||
add_executable(syncAppendEntriesReplyTest "")
|
||||
add_executable(syncClientRequestTest "")
|
||||
add_executable(syncTimeoutTest "")
|
||||
add_executable(syncPingTest "")
|
||||
add_executable(syncPingReplyTest "")
|
||||
add_executable(syncRpcMsgTest "")
|
||||
|
||||
|
||||
target_sources(syncTest
|
||||
|
@ -27,13 +35,9 @@ target_sources(syncEnvTest
|
|||
PRIVATE
|
||||
"syncEnvTest.cpp"
|
||||
)
|
||||
target_sources(syncPingTest
|
||||
target_sources(syncPingTimerTest
|
||||
PRIVATE
|
||||
"syncPingTest.cpp"
|
||||
)
|
||||
target_sources(syncEncodeTest
|
||||
PRIVATE
|
||||
"syncEncodeTest.cpp"
|
||||
"syncPingTimerTest.cpp"
|
||||
)
|
||||
target_sources(syncIOTickQTest
|
||||
PRIVATE
|
||||
|
@ -95,6 +99,42 @@ target_sources(syncEntryTest
|
|||
PRIVATE
|
||||
"syncEntryTest.cpp"
|
||||
)
|
||||
target_sources(syncRequestVoteTest
|
||||
PRIVATE
|
||||
"syncRequestVoteTest.cpp"
|
||||
)
|
||||
target_sources(syncRequestVoteReplyTest
|
||||
PRIVATE
|
||||
"syncRequestVoteReplyTest.cpp"
|
||||
)
|
||||
target_sources(syncAppendEntriesTest
|
||||
PRIVATE
|
||||
"syncAppendEntriesTest.cpp"
|
||||
)
|
||||
target_sources(syncAppendEntriesReplyTest
|
||||
PRIVATE
|
||||
"syncAppendEntriesReplyTest.cpp"
|
||||
)
|
||||
target_sources(syncClientRequestTest
|
||||
PRIVATE
|
||||
"syncClientRequestTest.cpp"
|
||||
)
|
||||
target_sources(syncTimeoutTest
|
||||
PRIVATE
|
||||
"syncTimeoutTest.cpp"
|
||||
)
|
||||
target_sources(syncPingTest
|
||||
PRIVATE
|
||||
"syncPingTest.cpp"
|
||||
)
|
||||
target_sources(syncPingReplyTest
|
||||
PRIVATE
|
||||
"syncPingReplyTest.cpp"
|
||||
)
|
||||
target_sources(syncRpcMsgTest
|
||||
PRIVATE
|
||||
"syncRpcMsgTest.cpp"
|
||||
)
|
||||
|
||||
|
||||
target_include_directories(syncTest
|
||||
|
@ -107,12 +147,7 @@ target_include_directories(syncEnvTest
|
|||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncPingTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncEncodeTest
|
||||
target_include_directories(syncPingTimerTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
|
@ -192,6 +227,51 @@ target_include_directories(syncEntryTest
|
|||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncRequestVoteTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncRequestVoteReplyTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncAppendEntriesTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncAppendEntriesReplyTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncClientRequestTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncTimeoutTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncPingTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncPingReplyTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncRpcMsgTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
|
||||
|
||||
target_link_libraries(syncTest
|
||||
|
@ -202,11 +282,7 @@ target_link_libraries(syncEnvTest
|
|||
sync
|
||||
gtest_main
|
||||
)
|
||||
target_link_libraries(syncPingTest
|
||||
sync
|
||||
gtest_main
|
||||
)
|
||||
target_link_libraries(syncEncodeTest
|
||||
target_link_libraries(syncPingTimerTest
|
||||
sync
|
||||
gtest_main
|
||||
)
|
||||
|
@ -270,6 +346,42 @@ target_link_libraries(syncEntryTest
|
|||
sync
|
||||
gtest_main
|
||||
)
|
||||
target_link_libraries(syncRequestVoteTest
|
||||
sync
|
||||
gtest_main
|
||||
)
|
||||
target_link_libraries(syncRequestVoteReplyTest
|
||||
sync
|
||||
gtest_main
|
||||
)
|
||||
target_link_libraries(syncAppendEntriesTest
|
||||
sync
|
||||
gtest_main
|
||||
)
|
||||
target_link_libraries(syncAppendEntriesReplyTest
|
||||
sync
|
||||
gtest_main
|
||||
)
|
||||
target_link_libraries(syncClientRequestTest
|
||||
sync
|
||||
gtest_main
|
||||
)
|
||||
target_link_libraries(syncTimeoutTest
|
||||
sync
|
||||
gtest_main
|
||||
)
|
||||
target_link_libraries(syncPingTest
|
||||
sync
|
||||
gtest_main
|
||||
)
|
||||
target_link_libraries(syncPingReplyTest
|
||||
sync
|
||||
gtest_main
|
||||
)
|
||||
target_link_libraries(syncRpcMsgTest
|
||||
sync
|
||||
gtest_main
|
||||
)
|
||||
|
||||
|
||||
enable_testing()
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <stdio.h>
|
||||
#include "syncIO.h"
|
||||
#include "syncInt.h"
|
||||
#include "syncMessage.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");
|
||||
}
|
||||
|
||||
SyncAppendEntriesReply *createMsg() {
|
||||
SyncAppendEntriesReply *pMsg = syncAppendEntriesReplyBuild();
|
||||
pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234);
|
||||
pMsg->srcId.vgId = 100;
|
||||
pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 5678);
|
||||
pMsg->destId.vgId = 100;
|
||||
pMsg->success = true;
|
||||
pMsg->matchIndex = 77;
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void test1() {
|
||||
SyncAppendEntriesReply *pMsg = createMsg();
|
||||
syncAppendEntriesReplyPrint2((char *)"test1:", pMsg);
|
||||
syncAppendEntriesReplyDestroy(pMsg);
|
||||
}
|
||||
|
||||
void test2() {
|
||||
SyncAppendEntriesReply *pMsg = createMsg();
|
||||
uint32_t len = pMsg->bytes;
|
||||
char * serialized = (char *)malloc(len);
|
||||
syncAppendEntriesReplySerialize(pMsg, serialized, len);
|
||||
SyncAppendEntriesReply *pMsg2 = syncAppendEntriesReplyBuild();
|
||||
syncAppendEntriesReplyDeserialize(serialized, len, pMsg2);
|
||||
syncAppendEntriesReplyPrint2((char *)"test2: syncAppendEntriesReplySerialize -> syncAppendEntriesReplyDeserialize ",
|
||||
pMsg2);
|
||||
|
||||
free(serialized);
|
||||
syncAppendEntriesReplyDestroy(pMsg);
|
||||
syncAppendEntriesReplyDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test3() {
|
||||
SyncAppendEntriesReply *pMsg = createMsg();
|
||||
uint32_t len;
|
||||
char * serialized = syncAppendEntriesReplySerialize2(pMsg, &len);
|
||||
SyncAppendEntriesReply *pMsg2 = syncAppendEntriesReplyDeserialize2(serialized, len);
|
||||
syncAppendEntriesReplyPrint2((char *)"test3: syncAppendEntriesReplySerialize3 -> syncAppendEntriesReplyDeserialize2 ",
|
||||
pMsg2);
|
||||
|
||||
free(serialized);
|
||||
syncAppendEntriesReplyDestroy(pMsg);
|
||||
syncAppendEntriesReplyDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test4() {
|
||||
SyncAppendEntriesReply *pMsg = createMsg();
|
||||
SRpcMsg rpcMsg;
|
||||
syncAppendEntriesReply2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncAppendEntriesReply *pMsg2 = syncAppendEntriesReplyBuild();
|
||||
syncAppendEntriesReplyFromRpcMsg(&rpcMsg, pMsg2);
|
||||
syncAppendEntriesReplyPrint2((char *)"test4: syncAppendEntriesReply2RpcMsg -> syncAppendEntriesReplyFromRpcMsg ",
|
||||
pMsg2);
|
||||
|
||||
syncAppendEntriesReplyDestroy(pMsg);
|
||||
syncAppendEntriesReplyDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test5() {
|
||||
SyncAppendEntriesReply *pMsg = createMsg();
|
||||
SRpcMsg rpcMsg;
|
||||
syncAppendEntriesReply2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncAppendEntriesReply *pMsg2 = syncAppendEntriesReplyFromRpcMsg2(&rpcMsg);
|
||||
syncAppendEntriesReplyPrint2((char *)"test5: syncAppendEntriesReply2RpcMsg -> syncAppendEntriesReplyFromRpcMsg2 ",
|
||||
pMsg2);
|
||||
|
||||
syncAppendEntriesReplyDestroy(pMsg);
|
||||
syncAppendEntriesReplyDestroy(pMsg2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
// taosInitLog((char *)"syncTest.log", 100000, 10);
|
||||
tsAsyncLog = 0;
|
||||
sDebugFlag = 143 + 64;
|
||||
logTest();
|
||||
|
||||
test1();
|
||||
test2();
|
||||
test3();
|
||||
test4();
|
||||
test5();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <stdio.h>
|
||||
#include "syncIO.h"
|
||||
#include "syncInt.h"
|
||||
#include "syncMessage.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");
|
||||
}
|
||||
|
||||
SyncAppendEntries *createMsg() {
|
||||
SyncAppendEntries *pMsg = syncAppendEntriesBuild(20);
|
||||
pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234);
|
||||
pMsg->srcId.vgId = 100;
|
||||
pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 5678);
|
||||
pMsg->destId.vgId = 100;
|
||||
pMsg->prevLogIndex = 11;
|
||||
pMsg->prevLogTerm = 22;
|
||||
pMsg->commitIndex = 33;
|
||||
strcpy(pMsg->data, "hello world");
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void test1() {
|
||||
SyncAppendEntries *pMsg = createMsg();
|
||||
syncAppendEntriesPrint2((char *)"test1:", pMsg);
|
||||
syncAppendEntriesDestroy(pMsg);
|
||||
}
|
||||
|
||||
void test2() {
|
||||
SyncAppendEntries *pMsg = createMsg();
|
||||
uint32_t len = pMsg->bytes;
|
||||
char * serialized = (char *)malloc(len);
|
||||
syncAppendEntriesSerialize(pMsg, serialized, len);
|
||||
SyncAppendEntries *pMsg2 = syncAppendEntriesBuild(pMsg->dataLen);
|
||||
syncAppendEntriesDeserialize(serialized, len, pMsg2);
|
||||
syncAppendEntriesPrint2((char *)"test2: syncAppendEntriesSerialize -> syncAppendEntriesDeserialize ", pMsg2);
|
||||
|
||||
free(serialized);
|
||||
syncAppendEntriesDestroy(pMsg);
|
||||
syncAppendEntriesDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test3() {
|
||||
SyncAppendEntries *pMsg = createMsg();
|
||||
uint32_t len;
|
||||
char * serialized = syncAppendEntriesSerialize2(pMsg, &len);
|
||||
SyncAppendEntries *pMsg2 = syncAppendEntriesDeserialize2(serialized, len);
|
||||
syncAppendEntriesPrint2((char *)"test3: syncAppendEntriesSerialize3 -> syncAppendEntriesDeserialize2 ", pMsg2);
|
||||
|
||||
free(serialized);
|
||||
syncAppendEntriesDestroy(pMsg);
|
||||
syncAppendEntriesDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test4() {
|
||||
SyncAppendEntries *pMsg = createMsg();
|
||||
SRpcMsg rpcMsg;
|
||||
syncAppendEntries2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncAppendEntries *pMsg2 = (SyncAppendEntries *)malloc(rpcMsg.contLen);
|
||||
syncAppendEntriesFromRpcMsg(&rpcMsg, pMsg2);
|
||||
syncAppendEntriesPrint2((char *)"test4: syncAppendEntries2RpcMsg -> syncAppendEntriesFromRpcMsg ", pMsg2);
|
||||
|
||||
syncAppendEntriesDestroy(pMsg);
|
||||
syncAppendEntriesDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test5() {
|
||||
SyncAppendEntries *pMsg = createMsg();
|
||||
SRpcMsg rpcMsg;
|
||||
syncAppendEntries2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncAppendEntries *pMsg2 = syncAppendEntriesFromRpcMsg2(&rpcMsg);
|
||||
syncAppendEntriesPrint2((char *)"test5: syncAppendEntries2RpcMsg -> syncAppendEntriesFromRpcMsg2 ", pMsg2);
|
||||
|
||||
syncAppendEntriesDestroy(pMsg);
|
||||
syncAppendEntriesDestroy(pMsg2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
// taosInitLog((char *)"syncTest.log", 100000, 10);
|
||||
tsAsyncLog = 0;
|
||||
sDebugFlag = 143 + 64;
|
||||
logTest();
|
||||
|
||||
test1();
|
||||
test2();
|
||||
test3();
|
||||
test4();
|
||||
test5();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <stdio.h>
|
||||
#include "syncIO.h"
|
||||
#include "syncInt.h"
|
||||
#include "syncMessage.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");
|
||||
}
|
||||
|
||||
SyncClientRequest *createMsg() {
|
||||
SRpcMsg rpcMsg;
|
||||
memset(&rpcMsg, 0, sizeof(rpcMsg));
|
||||
rpcMsg.msgType = 12345;
|
||||
rpcMsg.contLen = 20;
|
||||
rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen);
|
||||
strcpy((char *)rpcMsg.pCont, "hello rpc");
|
||||
SyncClientRequest *pMsg = syncClientRequestBuild2(&rpcMsg, 123, true);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void test1() {
|
||||
SyncClientRequest *pMsg = createMsg();
|
||||
syncClientRequestPrint2((char *)"test1:", pMsg);
|
||||
syncClientRequestDestroy(pMsg);
|
||||
}
|
||||
|
||||
void test2() {
|
||||
SyncClientRequest *pMsg = createMsg();
|
||||
uint32_t len = pMsg->bytes;
|
||||
char * serialized = (char *)malloc(len);
|
||||
syncClientRequestSerialize(pMsg, serialized, len);
|
||||
SyncClientRequest *pMsg2 = syncClientRequestBuild(pMsg->dataLen);
|
||||
syncClientRequestDeserialize(serialized, len, pMsg2);
|
||||
syncClientRequestPrint2((char *)"test2: syncClientRequestSerialize -> syncClientRequestDeserialize ", pMsg2);
|
||||
|
||||
free(serialized);
|
||||
syncClientRequestDestroy(pMsg);
|
||||
syncClientRequestDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test3() {
|
||||
SyncClientRequest *pMsg = createMsg();
|
||||
uint32_t len;
|
||||
char * serialized = syncClientRequestSerialize2(pMsg, &len);
|
||||
SyncClientRequest *pMsg2 = syncClientRequestDeserialize2(serialized, len);
|
||||
syncClientRequestPrint2((char *)"test3: syncClientRequestSerialize3 -> syncClientRequestDeserialize2 ", pMsg2);
|
||||
|
||||
free(serialized);
|
||||
syncClientRequestDestroy(pMsg);
|
||||
syncClientRequestDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test4() {
|
||||
SyncClientRequest *pMsg = createMsg();
|
||||
SRpcMsg rpcMsg;
|
||||
syncClientRequest2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncClientRequest *pMsg2 = (SyncClientRequest *)malloc(rpcMsg.contLen);
|
||||
syncClientRequestFromRpcMsg(&rpcMsg, pMsg2);
|
||||
syncClientRequestPrint2((char *)"test4: syncClientRequest2RpcMsg -> syncClientRequestFromRpcMsg ", pMsg2);
|
||||
|
||||
syncClientRequestDestroy(pMsg);
|
||||
syncClientRequestDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test5() {
|
||||
SyncClientRequest *pMsg = createMsg();
|
||||
SRpcMsg rpcMsg;
|
||||
syncClientRequest2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncClientRequest *pMsg2 = syncClientRequestFromRpcMsg2(&rpcMsg);
|
||||
syncClientRequestPrint2((char *)"test5: syncClientRequest2RpcMsg -> syncClientRequestFromRpcMsg2 ", pMsg2);
|
||||
|
||||
syncClientRequestDestroy(pMsg);
|
||||
syncClientRequestDestroy(pMsg2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
// taosInitLog((char *)"syncTest.log", 100000, 10);
|
||||
tsAsyncLog = 0;
|
||||
sDebugFlag = 143 + 64;
|
||||
logTest();
|
||||
|
||||
test1();
|
||||
test2();
|
||||
test3();
|
||||
test4();
|
||||
test5();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,509 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include "syncEnv.h"
|
||||
#include "syncIO.h"
|
||||
#include "syncInt.h"
|
||||
#include "syncMessage.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");
|
||||
}
|
||||
|
||||
#define PING_MSG_LEN 20
|
||||
#define APPEND_ENTRIES_VALUE_LEN 32
|
||||
|
||||
void test1() {
|
||||
sTrace("test1: ---- syncPingSerialize, syncPingDeserialize");
|
||||
|
||||
char msg[PING_MSG_LEN];
|
||||
snprintf(msg, sizeof(msg), "%s", "test ping");
|
||||
SyncPing* pMsg = syncPingBuild(PING_MSG_LEN);
|
||||
pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1111);
|
||||
pMsg->srcId.vgId = 100;
|
||||
pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 2222);
|
||||
pMsg->destId.vgId = 100;
|
||||
memcpy(pMsg->data, msg, PING_MSG_LEN);
|
||||
|
||||
{
|
||||
cJSON* pJson = syncPing2Json(pMsg);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
uint32_t bufLen = pMsg->bytes;
|
||||
char* buf = (char*)malloc(bufLen);
|
||||
syncPingSerialize(pMsg, buf, bufLen);
|
||||
|
||||
SyncPing* pMsg2 = (SyncPing*)malloc(pMsg->bytes);
|
||||
syncPingDeserialize(buf, bufLen, pMsg2);
|
||||
|
||||
{
|
||||
cJSON* pJson = syncPing2Json(pMsg2);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
syncPingDestroy(pMsg);
|
||||
syncPingDestroy(pMsg2);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
void test2() {
|
||||
sTrace("test2: ---- syncPing2RpcMsg, syncPingFromRpcMsg");
|
||||
|
||||
char msg[PING_MSG_LEN];
|
||||
snprintf(msg, sizeof(msg), "%s", "hello raft");
|
||||
SyncPing* pMsg = syncPingBuild(PING_MSG_LEN);
|
||||
pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 3333);
|
||||
pMsg->srcId.vgId = 200;
|
||||
pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 4444);
|
||||
pMsg->destId.vgId = 200;
|
||||
memcpy(pMsg->data, msg, PING_MSG_LEN);
|
||||
|
||||
{
|
||||
cJSON* pJson = syncPing2Json(pMsg);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg;
|
||||
syncPing2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncPing* pMsg2 = (SyncPing*)malloc(pMsg->bytes);
|
||||
syncPingFromRpcMsg(&rpcMsg, pMsg2);
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
|
||||
{
|
||||
cJSON* pJson = syncPing2Json(pMsg2);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
syncPingDestroy(pMsg);
|
||||
syncPingDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test3() {
|
||||
sTrace("test3: ---- syncPingReplySerialize, syncPingReplyDeserialize");
|
||||
|
||||
char msg[PING_MSG_LEN];
|
||||
snprintf(msg, sizeof(msg), "%s", "test ping");
|
||||
SyncPingReply* pMsg = syncPingReplyBuild(PING_MSG_LEN);
|
||||
pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 5555);
|
||||
pMsg->srcId.vgId = 100;
|
||||
pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 6666);
|
||||
pMsg->destId.vgId = 100;
|
||||
memcpy(pMsg->data, msg, PING_MSG_LEN);
|
||||
|
||||
{
|
||||
cJSON* pJson = syncPingReply2Json(pMsg);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
uint32_t bufLen = pMsg->bytes;
|
||||
char* buf = (char*)malloc(bufLen);
|
||||
syncPingReplySerialize(pMsg, buf, bufLen);
|
||||
|
||||
SyncPingReply* pMsg2 = (SyncPingReply*)malloc(pMsg->bytes);
|
||||
syncPingReplyDeserialize(buf, bufLen, pMsg2);
|
||||
|
||||
{
|
||||
cJSON* pJson = syncPingReply2Json(pMsg2);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
syncPingReplyDestroy(pMsg);
|
||||
syncPingReplyDestroy(pMsg2);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
void test4() {
|
||||
sTrace("test4: ---- syncPingReply2RpcMsg, syncPingReplyFromRpcMsg");
|
||||
|
||||
char msg[PING_MSG_LEN];
|
||||
snprintf(msg, sizeof(msg), "%s", "hello raft");
|
||||
SyncPingReply* pMsg = syncPingReplyBuild(PING_MSG_LEN);
|
||||
pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 7777);
|
||||
pMsg->srcId.vgId = 100;
|
||||
pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 8888);
|
||||
pMsg->destId.vgId = 100;
|
||||
memcpy(pMsg->data, msg, PING_MSG_LEN);
|
||||
|
||||
{
|
||||
cJSON* pJson = syncPingReply2Json(pMsg);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg;
|
||||
syncPingReply2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncPingReply* pMsg2 = (SyncPingReply*)malloc(pMsg->bytes);
|
||||
syncPingReplyFromRpcMsg(&rpcMsg, pMsg2);
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
|
||||
{
|
||||
cJSON* pJson = syncPingReply2Json(pMsg2);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
syncPingReplyDestroy(pMsg);
|
||||
syncPingReplyDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test5() {
|
||||
sTrace("test5: ---- syncRequestVoteSerialize, syncRequestVoteDeserialize");
|
||||
|
||||
SyncRequestVote* pMsg = syncRequestVoteBuild();
|
||||
pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234);
|
||||
pMsg->srcId.vgId = 100;
|
||||
pMsg->destId.addr = syncUtilAddr2U64("8.8.8.8", 5678);
|
||||
pMsg->destId.vgId = 100;
|
||||
pMsg->currentTerm = 20;
|
||||
pMsg->lastLogIndex = 21;
|
||||
pMsg->lastLogTerm = 22;
|
||||
|
||||
{
|
||||
cJSON* pJson = syncRequestVote2Json(pMsg);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
uint32_t bufLen = pMsg->bytes;
|
||||
char* buf = (char*)malloc(bufLen);
|
||||
syncRequestVoteSerialize(pMsg, buf, bufLen);
|
||||
|
||||
SyncRequestVote* pMsg2 = (SyncRequestVote*)malloc(pMsg->bytes);
|
||||
syncRequestVoteDeserialize(buf, bufLen, pMsg2);
|
||||
|
||||
{
|
||||
cJSON* pJson = syncRequestVote2Json(pMsg2);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
syncRequestVoteDestroy(pMsg);
|
||||
syncRequestVoteDestroy(pMsg2);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
void test6() {
|
||||
sTrace("test6: ---- syncRequestVote2RpcMsg, syncRequestVoteFromRpcMsg");
|
||||
|
||||
SyncRequestVote* pMsg = syncRequestVoteBuild();
|
||||
pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234);
|
||||
pMsg->srcId.vgId = 100;
|
||||
pMsg->destId.addr = syncUtilAddr2U64("8.8.8.8", 5678);
|
||||
pMsg->destId.vgId = 100;
|
||||
pMsg->currentTerm = 20;
|
||||
pMsg->lastLogIndex = 21;
|
||||
pMsg->lastLogTerm = 22;
|
||||
|
||||
{
|
||||
cJSON* pJson = syncRequestVote2Json(pMsg);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg;
|
||||
syncRequestVote2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncRequestVote* pMsg2 = (SyncRequestVote*)malloc(pMsg->bytes);
|
||||
syncRequestVoteFromRpcMsg(&rpcMsg, pMsg2);
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
|
||||
{
|
||||
cJSON* pJson = syncRequestVote2Json(pMsg2);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
syncRequestVoteDestroy(pMsg);
|
||||
syncRequestVoteDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test7() {
|
||||
sTrace("test7: ---- syncRequestVoteReplySerialize, syncRequestVoteReplyDeserialize");
|
||||
|
||||
SyncRequestVoteReply* pMsg = SyncRequestVoteReplyBuild();
|
||||
pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234);
|
||||
pMsg->srcId.vgId = 100;
|
||||
pMsg->destId.addr = syncUtilAddr2U64("8.8.8.8", 5678);
|
||||
pMsg->destId.vgId = 100;
|
||||
pMsg->term = 20;
|
||||
pMsg->voteGranted = 1;
|
||||
|
||||
{
|
||||
cJSON* pJson = syncRequestVoteReply2Json(pMsg);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
uint32_t bufLen = pMsg->bytes;
|
||||
char* buf = (char*)malloc(bufLen);
|
||||
syncRequestVoteReplySerialize(pMsg, buf, bufLen);
|
||||
|
||||
SyncRequestVoteReply* pMsg2 = (SyncRequestVoteReply*)malloc(pMsg->bytes);
|
||||
syncRequestVoteReplyDeserialize(buf, bufLen, pMsg2);
|
||||
|
||||
{
|
||||
cJSON* pJson = syncRequestVoteReply2Json(pMsg2);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
syncRequestVoteReplyDestroy(pMsg);
|
||||
syncRequestVoteReplyDestroy(pMsg2);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
void test8() {
|
||||
sTrace("test8: ---- syncRequestVoteReply2RpcMsg, syncRequestVoteReplyFromRpcMsg");
|
||||
|
||||
SyncRequestVoteReply* pMsg = SyncRequestVoteReplyBuild();
|
||||
pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234);
|
||||
pMsg->srcId.vgId = 100;
|
||||
pMsg->destId.addr = syncUtilAddr2U64("8.8.8.8", 5678);
|
||||
pMsg->destId.vgId = 100;
|
||||
pMsg->term = 20;
|
||||
pMsg->voteGranted = 1;
|
||||
|
||||
{
|
||||
cJSON* pJson = syncRequestVoteReply2Json(pMsg);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg;
|
||||
syncRequestVoteReply2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncRequestVoteReply* pMsg2 = (SyncRequestVoteReply*)malloc(pMsg->bytes);
|
||||
syncRequestVoteReplyFromRpcMsg(&rpcMsg, pMsg2);
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
|
||||
{
|
||||
cJSON* pJson = syncRequestVoteReply2Json(pMsg2);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
syncRequestVoteReplyDestroy(pMsg);
|
||||
syncRequestVoteReplyDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test9() {
|
||||
sTrace("test9: ---- syncAppendEntriesSerialize, syncAppendEntriesDeserialize");
|
||||
|
||||
char msg[APPEND_ENTRIES_VALUE_LEN];
|
||||
snprintf(msg, sizeof(msg), "%s", "test value");
|
||||
SyncAppendEntries* pMsg = syncAppendEntriesBuild(APPEND_ENTRIES_VALUE_LEN);
|
||||
pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1111);
|
||||
pMsg->srcId.vgId = 100;
|
||||
pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 2222);
|
||||
pMsg->destId.vgId = 100;
|
||||
pMsg->prevLogIndex = 55;
|
||||
pMsg->prevLogTerm = 66;
|
||||
pMsg->commitIndex = 77;
|
||||
memcpy(pMsg->data, msg, APPEND_ENTRIES_VALUE_LEN);
|
||||
|
||||
{
|
||||
cJSON* pJson = syncAppendEntries2Json(pMsg);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
uint32_t bufLen = pMsg->bytes;
|
||||
char* buf = (char*)malloc(bufLen);
|
||||
syncAppendEntriesSerialize(pMsg, buf, bufLen);
|
||||
|
||||
SyncAppendEntries* pMsg2 = (SyncAppendEntries*)malloc(pMsg->bytes);
|
||||
syncAppendEntriesDeserialize(buf, bufLen, pMsg2);
|
||||
|
||||
{
|
||||
cJSON* pJson = syncAppendEntries2Json(pMsg2);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
syncAppendEntriesDestroy(pMsg);
|
||||
syncAppendEntriesDestroy(pMsg2);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
void test10() {
|
||||
sTrace("test10: ---- syncAppendEntries2RpcMsg, syncAppendEntriesFromRpcMsg");
|
||||
|
||||
char msg[APPEND_ENTRIES_VALUE_LEN];
|
||||
snprintf(msg, sizeof(msg), "%s", "test value");
|
||||
SyncAppendEntries* pMsg = syncAppendEntriesBuild(APPEND_ENTRIES_VALUE_LEN);
|
||||
pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1111);
|
||||
pMsg->srcId.vgId = 100;
|
||||
pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 2222);
|
||||
pMsg->destId.vgId = 100;
|
||||
pMsg->prevLogIndex = 55;
|
||||
pMsg->prevLogTerm = 66;
|
||||
pMsg->commitIndex = 77;
|
||||
memcpy(pMsg->data, msg, APPEND_ENTRIES_VALUE_LEN);
|
||||
|
||||
{
|
||||
cJSON* pJson = syncAppendEntries2Json(pMsg);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg;
|
||||
syncAppendEntries2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncAppendEntries* pMsg2 = (SyncAppendEntries*)malloc(pMsg->bytes);
|
||||
syncAppendEntriesFromRpcMsg(&rpcMsg, pMsg2);
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
|
||||
{
|
||||
cJSON* pJson = syncAppendEntries2Json(pMsg2);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
syncAppendEntriesDestroy(pMsg);
|
||||
syncAppendEntriesDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test11() {
|
||||
sTrace("test11: ---- syncAppendEntriesReplySerialize, syncAppendEntriesReplyDeserialize");
|
||||
|
||||
SyncAppendEntriesReply* pMsg = syncAppendEntriesReplyBuild();
|
||||
pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1111);
|
||||
pMsg->srcId.vgId = 100;
|
||||
pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 2222);
|
||||
pMsg->destId.vgId = 100;
|
||||
pMsg->success = 1;
|
||||
pMsg->matchIndex = 23;
|
||||
|
||||
{
|
||||
cJSON* pJson = syncAppendEntriesReply2Json(pMsg);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
uint32_t bufLen = pMsg->bytes;
|
||||
char* buf = (char*)malloc(bufLen);
|
||||
syncAppendEntriesReplySerialize(pMsg, buf, bufLen);
|
||||
|
||||
SyncAppendEntriesReply* pMsg2 = (SyncAppendEntriesReply*)malloc(pMsg->bytes);
|
||||
syncAppendEntriesReplyDeserialize(buf, bufLen, pMsg2);
|
||||
|
||||
{
|
||||
cJSON* pJson = syncAppendEntriesReply2Json(pMsg2);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
syncAppendEntriesReplyDestroy(pMsg);
|
||||
syncAppendEntriesReplyDestroy(pMsg2);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
void test12() {
|
||||
sTrace("test12: ---- syncAppendEntriesReply2RpcMsg, syncAppendEntriesReplyFromRpcMsg");
|
||||
|
||||
SyncAppendEntriesReply* pMsg = syncAppendEntriesReplyBuild();
|
||||
pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1111);
|
||||
pMsg->srcId.vgId = 100;
|
||||
pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 2222);
|
||||
pMsg->destId.vgId = 100;
|
||||
pMsg->success = 1;
|
||||
pMsg->matchIndex = 23;
|
||||
|
||||
{
|
||||
cJSON* pJson = syncAppendEntriesReply2Json(pMsg);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg;
|
||||
syncAppendEntriesReply2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncAppendEntriesReply* pMsg2 = (SyncAppendEntriesReply*)malloc(pMsg->bytes);
|
||||
syncAppendEntriesReplyFromRpcMsg(&rpcMsg, pMsg2);
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
|
||||
{
|
||||
cJSON* pJson = syncAppendEntriesReply2Json(pMsg2);
|
||||
char* serialized = cJSON_Print(pJson);
|
||||
printf("\n%s\n\n", serialized);
|
||||
free(serialized);
|
||||
cJSON_Delete(pJson);
|
||||
}
|
||||
|
||||
syncAppendEntriesReplyDestroy(pMsg);
|
||||
syncAppendEntriesReplyDestroy(pMsg2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
// taosInitLog((char*)"syncPingTest.log", 100000, 10);
|
||||
tsAsyncLog = 0;
|
||||
sDebugFlag = 143 + 64;
|
||||
|
||||
test1();
|
||||
test2();
|
||||
test3();
|
||||
test4();
|
||||
test5();
|
||||
test6();
|
||||
test7();
|
||||
test8();
|
||||
test9();
|
||||
test10();
|
||||
test11();
|
||||
test12();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -89,7 +89,7 @@ int main(int argc, char** argv) {
|
|||
SSyncNode* pSyncNode = syncInitTest();
|
||||
assert(pSyncNode != NULL);
|
||||
|
||||
syncNodePrint((char*)"syncInitTest", pSyncNode);
|
||||
syncNodePrint2((char*)"syncInitTest", pSyncNode);
|
||||
|
||||
initRaftId(pSyncNode);
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ SSyncNode* syncInitTest() { return syncNodeInit(); }
|
|||
void logStoreTest() {
|
||||
logStorePrint(pSyncNode->pLogStore);
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
int32_t dataLen = 10;
|
||||
int32_t dataLen = 10;
|
||||
SSyncRaftEntry* pEntry = syncEntryBuild(dataLen);
|
||||
assert(pEntry != NULL);
|
||||
pEntry->msgType = 1;
|
||||
|
@ -94,7 +94,7 @@ void logStoreTest() {
|
|||
pEntry->index = pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore) + 1;
|
||||
snprintf(pEntry->data, dataLen, "value%d", i);
|
||||
|
||||
//syncEntryPrint2((char*)"write entry:", pEntry);
|
||||
// syncEntryPrint2((char*)"write entry:", pEntry);
|
||||
pSyncNode->pLogStore->appendEntry(pSyncNode->pLogStore, pEntry);
|
||||
syncEntryDestory(pEntry);
|
||||
}
|
||||
|
@ -132,8 +132,8 @@ int main(int argc, char** argv) {
|
|||
pSyncNode = syncInitTest();
|
||||
assert(pSyncNode != NULL);
|
||||
|
||||
//syncNodePrint((char*)"syncLogStoreTest", pSyncNode);
|
||||
//initRaftId(pSyncNode);
|
||||
// syncNodePrint((char*)"syncLogStoreTest", pSyncNode);
|
||||
// initRaftId(pSyncNode);
|
||||
|
||||
logStoreTest();
|
||||
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <stdio.h>
|
||||
#include "syncIO.h"
|
||||
#include "syncInt.h"
|
||||
#include "syncMessage.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");
|
||||
}
|
||||
|
||||
SyncPingReply *createMsg() {
|
||||
SRaftId srcId, destId;
|
||||
srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234);
|
||||
srcId.vgId = 100;
|
||||
destId.addr = syncUtilAddr2U64("127.0.0.1", 5678);
|
||||
destId.vgId = 100;
|
||||
SyncPingReply *pMsg = syncPingReplyBuild3(&srcId, &destId);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void test1() {
|
||||
SyncPingReply *pMsg = createMsg();
|
||||
syncPingReplyPrint2((char *)"test1:", pMsg);
|
||||
syncPingReplyDestroy(pMsg);
|
||||
}
|
||||
|
||||
void test2() {
|
||||
SyncPingReply *pMsg = createMsg();
|
||||
uint32_t len = pMsg->bytes;
|
||||
char * serialized = (char *)malloc(len);
|
||||
syncPingReplySerialize(pMsg, serialized, len);
|
||||
SyncPingReply *pMsg2 = syncPingReplyBuild(pMsg->dataLen);
|
||||
syncPingReplyDeserialize(serialized, len, pMsg2);
|
||||
syncPingReplyPrint2((char *)"test2: syncPingReplySerialize -> syncPingReplyDeserialize ", pMsg2);
|
||||
|
||||
free(serialized);
|
||||
syncPingReplyDestroy(pMsg);
|
||||
syncPingReplyDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test3() {
|
||||
SyncPingReply *pMsg = createMsg();
|
||||
uint32_t len;
|
||||
char * serialized = syncPingReplySerialize2(pMsg, &len);
|
||||
SyncPingReply *pMsg2 = syncPingReplyDeserialize2(serialized, len);
|
||||
syncPingReplyPrint2((char *)"test3: syncPingReplySerialize3 -> syncPingReplyDeserialize2 ", pMsg2);
|
||||
|
||||
free(serialized);
|
||||
syncPingReplyDestroy(pMsg);
|
||||
syncPingReplyDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test4() {
|
||||
SyncPingReply *pMsg = createMsg();
|
||||
SRpcMsg rpcMsg;
|
||||
syncPingReply2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncPingReply *pMsg2 = (SyncPingReply *)malloc(rpcMsg.contLen);
|
||||
syncPingReplyFromRpcMsg(&rpcMsg, pMsg2);
|
||||
syncPingReplyPrint2((char *)"test4: syncPingReply2RpcMsg -> syncPingReplyFromRpcMsg ", pMsg2);
|
||||
|
||||
syncPingReplyDestroy(pMsg);
|
||||
syncPingReplyDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test5() {
|
||||
SyncPingReply *pMsg = createMsg();
|
||||
SRpcMsg rpcMsg;
|
||||
syncPingReply2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncPingReply *pMsg2 = syncPingReplyFromRpcMsg2(&rpcMsg);
|
||||
syncPingReplyPrint2((char *)"test5: syncPingReply2RpcMsg -> syncPingReplyFromRpcMsg2 ", pMsg2);
|
||||
|
||||
syncPingReplyDestroy(pMsg);
|
||||
syncPingReplyDestroy(pMsg2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
// taosInitLog((char *)"syncTest.log", 100000, 10);
|
||||
tsAsyncLog = 0;
|
||||
sDebugFlag = 143 + 64;
|
||||
logTest();
|
||||
|
||||
test1();
|
||||
test2();
|
||||
test3();
|
||||
test4();
|
||||
test5();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <stdio.h>
|
||||
#include "syncEnv.h"
|
||||
#include "syncIO.h"
|
||||
#include "syncInt.h"
|
||||
#include "syncRaftStore.h"
|
||||
#include "syncMessage.h"
|
||||
#include "syncUtil.h"
|
||||
|
||||
void logTest() {
|
||||
|
@ -15,116 +14,82 @@ void logTest() {
|
|||
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;
|
||||
|
||||
SSyncNode* syncNodeInit() {
|
||||
syncInfo.vgId = 1234;
|
||||
syncInfo.rpcClient = gSyncIO->clientRpc;
|
||||
syncInfo.FpSendMsg = syncIOSendMsg;
|
||||
syncInfo.queue = gSyncIO->pMsgQ;
|
||||
syncInfo.FpEqMsg = syncIOEqMsg;
|
||||
syncInfo.pFsm = pFsm;
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./");
|
||||
|
||||
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->FpOnSyncTimeout = pSyncNode->FpOnTimeout;
|
||||
gSyncIO->pSyncNode = pSyncNode;
|
||||
|
||||
return pSyncNode;
|
||||
SyncPing *createMsg() {
|
||||
SRaftId srcId, destId;
|
||||
srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234);
|
||||
srcId.vgId = 100;
|
||||
destId.addr = syncUtilAddr2U64("127.0.0.1", 5678);
|
||||
destId.vgId = 100;
|
||||
SyncPing *pMsg = syncPingBuild3(&srcId, &destId);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
void test1() {
|
||||
SyncPing *pMsg = createMsg();
|
||||
syncPingPrint2((char *)"test1:", pMsg);
|
||||
syncPingDestroy(pMsg);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
void test2() {
|
||||
SyncPing *pMsg = createMsg();
|
||||
uint32_t len = pMsg->bytes;
|
||||
char * serialized = (char *)malloc(len);
|
||||
syncPingSerialize(pMsg, serialized, len);
|
||||
SyncPing *pMsg2 = syncPingBuild(pMsg->dataLen);
|
||||
syncPingDeserialize(serialized, len, pMsg2);
|
||||
syncPingPrint2((char *)"test2: syncPingSerialize -> syncPingDeserialize ", pMsg2);
|
||||
|
||||
free(serialized);
|
||||
syncPingDestroy(pMsg);
|
||||
syncPingDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test3() {
|
||||
SyncPing *pMsg = createMsg();
|
||||
uint32_t len;
|
||||
char * serialized = syncPingSerialize2(pMsg, &len);
|
||||
SyncPing *pMsg2 = syncPingDeserialize2(serialized, len);
|
||||
syncPingPrint2((char *)"test3: syncPingSerialize3 -> syncPingDeserialize2 ", pMsg2);
|
||||
|
||||
free(serialized);
|
||||
syncPingDestroy(pMsg);
|
||||
syncPingDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test4() {
|
||||
SyncPing *pMsg = createMsg();
|
||||
SRpcMsg rpcMsg;
|
||||
syncPing2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncPing *pMsg2 = (SyncPing *)malloc(rpcMsg.contLen);
|
||||
syncPingFromRpcMsg(&rpcMsg, pMsg2);
|
||||
syncPingPrint2((char *)"test4: syncPing2RpcMsg -> syncPingFromRpcMsg ", pMsg2);
|
||||
|
||||
syncPingDestroy(pMsg);
|
||||
syncPingDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test5() {
|
||||
SyncPing *pMsg = createMsg();
|
||||
SRpcMsg rpcMsg;
|
||||
syncPing2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncPing *pMsg2 = syncPingFromRpcMsg2(&rpcMsg);
|
||||
syncPingPrint2((char *)"test5: syncPing2RpcMsg -> syncPingFromRpcMsg2 ", pMsg2);
|
||||
|
||||
syncPingDestroy(pMsg);
|
||||
syncPingDestroy(pMsg2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
// taosInitLog((char *)"syncTest.log", 100000, 10);
|
||||
tsAsyncLog = 0;
|
||||
sDebugFlag = 143 + 64;
|
||||
logTest();
|
||||
|
||||
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);
|
||||
|
||||
SSyncNode* pSyncNode = syncInitTest();
|
||||
assert(pSyncNode != NULL);
|
||||
syncNodePrint((char*)"----1", pSyncNode);
|
||||
|
||||
initRaftId(pSyncNode);
|
||||
|
||||
//---------------------------
|
||||
|
||||
sTrace("syncNodeStartPingTimer ...");
|
||||
ret = syncNodeStartPingTimer(pSyncNode);
|
||||
assert(ret == 0);
|
||||
syncNodePrint((char*)"----2", pSyncNode);
|
||||
|
||||
sTrace("sleep ...");
|
||||
taosMsleep(10000);
|
||||
|
||||
sTrace("syncNodeStopPingTimer ...");
|
||||
ret = syncNodeStopPingTimer(pSyncNode);
|
||||
assert(ret == 0);
|
||||
syncNodePrint((char*)"----3", pSyncNode);
|
||||
|
||||
sTrace("sleep ...");
|
||||
taosMsleep(5000);
|
||||
|
||||
sTrace("syncNodeStartPingTimer ...");
|
||||
ret = syncNodeStartPingTimer(pSyncNode);
|
||||
assert(ret == 0);
|
||||
syncNodePrint((char*)"----4", pSyncNode);
|
||||
|
||||
sTrace("sleep ...");
|
||||
taosMsleep(10000);
|
||||
|
||||
sTrace("syncNodeStopPingTimer ...");
|
||||
ret = syncNodeStopPingTimer(pSyncNode);
|
||||
assert(ret == 0);
|
||||
syncNodePrint((char*)"----5", pSyncNode);
|
||||
|
||||
while (1) {
|
||||
sTrace("while 1 sleep ...");
|
||||
taosMsleep(1000);
|
||||
}
|
||||
test1();
|
||||
test2();
|
||||
test3();
|
||||
test4();
|
||||
test5();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,130 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <stdio.h>
|
||||
#include "syncEnv.h"
|
||||
#include "syncIO.h"
|
||||
#include "syncInt.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;
|
||||
|
||||
SSyncNode* syncNodeInit() {
|
||||
syncInfo.vgId = 1234;
|
||||
syncInfo.rpcClient = gSyncIO->clientRpc;
|
||||
syncInfo.FpSendMsg = syncIOSendMsg;
|
||||
syncInfo.queue = gSyncIO->pMsgQ;
|
||||
syncInfo.FpEqMsg = syncIOEqMsg;
|
||||
syncInfo.pFsm = pFsm;
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./");
|
||||
|
||||
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->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);
|
||||
|
||||
SSyncNode* pSyncNode = syncInitTest();
|
||||
assert(pSyncNode != NULL);
|
||||
syncNodePrint2((char*)"----1", pSyncNode);
|
||||
|
||||
initRaftId(pSyncNode);
|
||||
|
||||
//---------------------------
|
||||
|
||||
sTrace("syncNodeStartPingTimer ...");
|
||||
ret = syncNodeStartPingTimer(pSyncNode);
|
||||
assert(ret == 0);
|
||||
syncNodePrint2((char*)"----2", pSyncNode);
|
||||
|
||||
sTrace("sleep ...");
|
||||
taosMsleep(10000);
|
||||
|
||||
sTrace("syncNodeStopPingTimer ...");
|
||||
ret = syncNodeStopPingTimer(pSyncNode);
|
||||
assert(ret == 0);
|
||||
syncNodePrint2((char*)"----3", pSyncNode);
|
||||
|
||||
sTrace("sleep ...");
|
||||
taosMsleep(5000);
|
||||
|
||||
sTrace("syncNodeStartPingTimer ...");
|
||||
ret = syncNodeStartPingTimer(pSyncNode);
|
||||
assert(ret == 0);
|
||||
syncNodePrint2((char*)"----4", pSyncNode);
|
||||
|
||||
sTrace("sleep ...");
|
||||
taosMsleep(10000);
|
||||
|
||||
sTrace("syncNodeStopPingTimer ...");
|
||||
ret = syncNodeStopPingTimer(pSyncNode);
|
||||
assert(ret == 0);
|
||||
syncNodePrint2((char*)"----5", pSyncNode);
|
||||
|
||||
while (1) {
|
||||
sTrace("while 1 sleep ...");
|
||||
taosMsleep(1000);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -22,15 +22,21 @@ int main() {
|
|||
|
||||
SRaftStore *pRaftStore = raftStoreOpen("./raft_store.json");
|
||||
assert(pRaftStore != NULL);
|
||||
|
||||
raftStorePrint(pRaftStore);
|
||||
|
||||
#if 0
|
||||
pRaftStore->currentTerm = 100;
|
||||
pRaftStore->voteFor.addr = 200;
|
||||
pRaftStore->voteFor.vgId = 300;
|
||||
|
||||
raftStorePrint(pRaftStore);
|
||||
raftStorePersist(pRaftStore);
|
||||
raftStorePrint(pRaftStore);
|
||||
#endif
|
||||
|
||||
++(pRaftStore->currentTerm);
|
||||
++(pRaftStore->voteFor.addr);
|
||||
++(pRaftStore->voteFor.vgId);
|
||||
raftStorePersist(pRaftStore);
|
||||
raftStorePrint(pRaftStore);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <stdio.h>
|
||||
#include "syncIO.h"
|
||||
#include "syncInt.h"
|
||||
#include "syncMessage.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");
|
||||
}
|
||||
|
||||
SyncRequestVoteReply *createMsg() {
|
||||
SyncRequestVoteReply *pMsg = syncRequestVoteReplyBuild();
|
||||
pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234);
|
||||
pMsg->srcId.vgId = 100;
|
||||
pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 5678);
|
||||
pMsg->destId.vgId = 100;
|
||||
pMsg->term = 77;
|
||||
pMsg->voteGranted = true;
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void test1() {
|
||||
SyncRequestVoteReply *pMsg = createMsg();
|
||||
syncRequestVoteReplyPrint2((char *)"test1:", pMsg);
|
||||
syncRequestVoteReplyDestroy(pMsg);
|
||||
}
|
||||
|
||||
void test2() {
|
||||
SyncRequestVoteReply *pMsg = createMsg();
|
||||
uint32_t len = pMsg->bytes;
|
||||
char * serialized = (char *)malloc(len);
|
||||
syncRequestVoteReplySerialize(pMsg, serialized, len);
|
||||
SyncRequestVoteReply *pMsg2 = syncRequestVoteReplyBuild();
|
||||
syncRequestVoteReplyDeserialize(serialized, len, pMsg2);
|
||||
syncRequestVoteReplyPrint2((char *)"test2: syncRequestVoteReplySerialize -> syncRequestVoteReplyDeserialize ", pMsg2);
|
||||
|
||||
free(serialized);
|
||||
syncRequestVoteReplyDestroy(pMsg);
|
||||
syncRequestVoteReplyDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test3() {
|
||||
SyncRequestVoteReply *pMsg = createMsg();
|
||||
uint32_t len;
|
||||
char * serialized = syncRequestVoteReplySerialize2(pMsg, &len);
|
||||
SyncRequestVoteReply *pMsg2 = syncRequestVoteReplyDeserialize2(serialized, len);
|
||||
syncRequestVoteReplyPrint2((char *)"test3: syncRequestVoteReplySerialize3 -> syncRequestVoteReplyDeserialize2 ",
|
||||
pMsg2);
|
||||
|
||||
free(serialized);
|
||||
syncRequestVoteReplyDestroy(pMsg);
|
||||
syncRequestVoteReplyDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test4() {
|
||||
SyncRequestVoteReply *pMsg = createMsg();
|
||||
SRpcMsg rpcMsg;
|
||||
syncRequestVoteReply2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncRequestVoteReply *pMsg2 = syncRequestVoteReplyBuild();
|
||||
syncRequestVoteReplyFromRpcMsg(&rpcMsg, pMsg2);
|
||||
syncRequestVoteReplyPrint2((char *)"test4: syncRequestVoteReply2RpcMsg -> syncRequestVoteReplyFromRpcMsg ", pMsg2);
|
||||
|
||||
syncRequestVoteReplyDestroy(pMsg);
|
||||
syncRequestVoteReplyDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test5() {
|
||||
SyncRequestVoteReply *pMsg = createMsg();
|
||||
SRpcMsg rpcMsg;
|
||||
syncRequestVoteReply2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncRequestVoteReply *pMsg2 = syncRequestVoteReplyFromRpcMsg2(&rpcMsg);
|
||||
syncRequestVoteReplyPrint2((char *)"test5: syncRequestVoteReply2RpcMsg -> syncRequestVoteReplyFromRpcMsg2 ", pMsg2);
|
||||
|
||||
syncRequestVoteReplyDestroy(pMsg);
|
||||
syncRequestVoteReplyDestroy(pMsg2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
// taosInitLog((char *)"syncTest.log", 100000, 10);
|
||||
tsAsyncLog = 0;
|
||||
sDebugFlag = 143 + 64;
|
||||
logTest();
|
||||
|
||||
test1();
|
||||
test2();
|
||||
test3();
|
||||
test4();
|
||||
test5();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <stdio.h>
|
||||
#include "syncIO.h"
|
||||
#include "syncInt.h"
|
||||
#include "syncMessage.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");
|
||||
}
|
||||
|
||||
SyncRequestVote *createMsg() {
|
||||
SyncRequestVote *pMsg = syncRequestVoteBuild();
|
||||
pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234);
|
||||
pMsg->srcId.vgId = 100;
|
||||
pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 5678);
|
||||
pMsg->destId.vgId = 100;
|
||||
pMsg->currentTerm = 11;
|
||||
pMsg->lastLogIndex = 22;
|
||||
pMsg->lastLogTerm = 33;
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void test1() {
|
||||
SyncRequestVote *pMsg = createMsg();
|
||||
syncRequestVotePrint2((char *)"test1:", pMsg);
|
||||
syncRequestVoteDestroy(pMsg);
|
||||
}
|
||||
|
||||
void test2() {
|
||||
SyncRequestVote *pMsg = createMsg();
|
||||
uint32_t len = pMsg->bytes;
|
||||
char * serialized = (char *)malloc(len);
|
||||
syncRequestVoteSerialize(pMsg, serialized, len);
|
||||
SyncRequestVote *pMsg2 = syncRequestVoteBuild();
|
||||
syncRequestVoteDeserialize(serialized, len, pMsg2);
|
||||
syncRequestVotePrint2((char *)"test2: syncRequestVoteSerialize -> syncRequestVoteDeserialize ", pMsg2);
|
||||
|
||||
free(serialized);
|
||||
syncRequestVoteDestroy(pMsg);
|
||||
syncRequestVoteDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test3() {
|
||||
SyncRequestVote *pMsg = createMsg();
|
||||
uint32_t len;
|
||||
char * serialized = syncRequestVoteSerialize2(pMsg, &len);
|
||||
SyncRequestVote *pMsg2 = syncRequestVoteDeserialize2(serialized, len);
|
||||
syncRequestVotePrint2((char *)"test3: syncRequestVoteSerialize3 -> syncRequestVoteDeserialize2 ", pMsg2);
|
||||
|
||||
free(serialized);
|
||||
syncRequestVoteDestroy(pMsg);
|
||||
syncRequestVoteDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test4() {
|
||||
SyncRequestVote *pMsg = createMsg();
|
||||
SRpcMsg rpcMsg;
|
||||
syncRequestVote2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncRequestVote *pMsg2 = syncRequestVoteBuild();
|
||||
syncRequestVoteFromRpcMsg(&rpcMsg, pMsg2);
|
||||
syncRequestVotePrint2((char *)"test4: syncRequestVote2RpcMsg -> syncRequestVoteFromRpcMsg ", pMsg2);
|
||||
|
||||
syncRequestVoteDestroy(pMsg);
|
||||
syncRequestVoteDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test5() {
|
||||
SyncRequestVote *pMsg = createMsg();
|
||||
SRpcMsg rpcMsg;
|
||||
syncRequestVote2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncRequestVote *pMsg2 = syncRequestVoteFromRpcMsg2(&rpcMsg);
|
||||
syncRequestVotePrint2((char *)"test5: syncRequestVote2RpcMsg -> syncRequestVoteFromRpcMsg2 ", pMsg2);
|
||||
|
||||
syncRequestVoteDestroy(pMsg);
|
||||
syncRequestVoteDestroy(pMsg2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
// taosInitLog((char *)"syncTest.log", 100000, 10);
|
||||
tsAsyncLog = 0;
|
||||
sDebugFlag = 143 + 64;
|
||||
logTest();
|
||||
|
||||
test1();
|
||||
test2();
|
||||
test3();
|
||||
test4();
|
||||
test5();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,181 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <stdio.h>
|
||||
#include "syncIO.h"
|
||||
#include "syncInt.h"
|
||||
#include "syncMessage.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");
|
||||
}
|
||||
|
||||
int gg = 0;
|
||||
SyncTimeout *createSyncTimeout() {
|
||||
SyncTimeout *pMsg = syncTimeoutBuild2(SYNC_TIMEOUT_PING, 999, 333, &gg);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
SyncPing *createSyncPing() {
|
||||
SRaftId srcId, destId;
|
||||
srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234);
|
||||
srcId.vgId = 100;
|
||||
destId.addr = syncUtilAddr2U64("127.0.0.1", 5678);
|
||||
destId.vgId = 100;
|
||||
SyncPing *pMsg = syncPingBuild3(&srcId, &destId);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
SyncPingReply *createSyncPingReply() {
|
||||
SRaftId srcId, destId;
|
||||
srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234);
|
||||
srcId.vgId = 100;
|
||||
destId.addr = syncUtilAddr2U64("127.0.0.1", 5678);
|
||||
destId.vgId = 100;
|
||||
SyncPingReply *pMsg = syncPingReplyBuild3(&srcId, &destId);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
SyncClientRequest *createSyncClientRequest() {
|
||||
SRpcMsg rpcMsg;
|
||||
memset(&rpcMsg, 0, sizeof(rpcMsg));
|
||||
rpcMsg.msgType = 12345;
|
||||
rpcMsg.contLen = 20;
|
||||
rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen);
|
||||
strcpy((char *)rpcMsg.pCont, "hello rpc");
|
||||
SyncClientRequest *pMsg = syncClientRequestBuild2(&rpcMsg, 123, true);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
SyncRequestVote *createSyncRequestVote() {
|
||||
SyncRequestVote *pMsg = syncRequestVoteBuild();
|
||||
pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234);
|
||||
pMsg->srcId.vgId = 100;
|
||||
pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 5678);
|
||||
pMsg->destId.vgId = 100;
|
||||
pMsg->currentTerm = 11;
|
||||
pMsg->lastLogIndex = 22;
|
||||
pMsg->lastLogTerm = 33;
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
SyncRequestVoteReply *createSyncRequestVoteReply() {
|
||||
SyncRequestVoteReply *pMsg = syncRequestVoteReplyBuild();
|
||||
pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234);
|
||||
pMsg->srcId.vgId = 100;
|
||||
pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 5678);
|
||||
pMsg->destId.vgId = 100;
|
||||
pMsg->term = 77;
|
||||
pMsg->voteGranted = true;
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
SyncAppendEntries *createSyncAppendEntries() {
|
||||
SyncAppendEntries *pMsg = syncAppendEntriesBuild(20);
|
||||
pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234);
|
||||
pMsg->srcId.vgId = 100;
|
||||
pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 5678);
|
||||
pMsg->destId.vgId = 100;
|
||||
pMsg->prevLogIndex = 11;
|
||||
pMsg->prevLogTerm = 22;
|
||||
pMsg->commitIndex = 33;
|
||||
strcpy(pMsg->data, "hello world");
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
SyncAppendEntriesReply *createSyncAppendEntriesReply() {
|
||||
SyncAppendEntriesReply *pMsg = syncAppendEntriesReplyBuild();
|
||||
pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234);
|
||||
pMsg->srcId.vgId = 100;
|
||||
pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 5678);
|
||||
pMsg->destId.vgId = 100;
|
||||
pMsg->success = true;
|
||||
pMsg->matchIndex = 77;
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void test1() {
|
||||
SyncTimeout *pMsg = createSyncTimeout();
|
||||
SRpcMsg rpcMsg;
|
||||
syncTimeout2RpcMsg(pMsg, &rpcMsg);
|
||||
syncRpcMsgPrint2((char *)"test1", &rpcMsg);
|
||||
syncTimeoutDestroy(pMsg);
|
||||
}
|
||||
|
||||
void test2() {
|
||||
SyncPing *pMsg = createSyncPing();
|
||||
SRpcMsg rpcMsg;
|
||||
syncPing2RpcMsg(pMsg, &rpcMsg);
|
||||
syncRpcMsgPrint2((char *)"test2", &rpcMsg);
|
||||
syncPingDestroy(pMsg);
|
||||
}
|
||||
|
||||
void test3() {
|
||||
SyncPingReply *pMsg = createSyncPingReply();
|
||||
SRpcMsg rpcMsg;
|
||||
syncPingReply2RpcMsg(pMsg, &rpcMsg);
|
||||
syncRpcMsgPrint2((char *)"test3", &rpcMsg);
|
||||
syncPingReplyDestroy(pMsg);
|
||||
}
|
||||
|
||||
void test4() {
|
||||
SyncRequestVote *pMsg = createSyncRequestVote();
|
||||
SRpcMsg rpcMsg;
|
||||
syncRequestVote2RpcMsg(pMsg, &rpcMsg);
|
||||
syncRpcMsgPrint2((char *)"test4", &rpcMsg);
|
||||
syncRequestVoteDestroy(pMsg);
|
||||
}
|
||||
|
||||
void test5() {
|
||||
SyncRequestVoteReply *pMsg = createSyncRequestVoteReply();
|
||||
SRpcMsg rpcMsg;
|
||||
syncRequestVoteReply2RpcMsg(pMsg, &rpcMsg);
|
||||
syncRpcMsgPrint2((char *)"test5", &rpcMsg);
|
||||
syncRequestVoteReplyDestroy(pMsg);
|
||||
}
|
||||
|
||||
void test6() {
|
||||
SyncAppendEntries *pMsg = createSyncAppendEntries();
|
||||
SRpcMsg rpcMsg;
|
||||
syncAppendEntries2RpcMsg(pMsg, &rpcMsg);
|
||||
syncRpcMsgPrint2((char *)"test6", &rpcMsg);
|
||||
syncAppendEntriesDestroy(pMsg);
|
||||
}
|
||||
|
||||
void test7() {
|
||||
SyncAppendEntriesReply *pMsg = createSyncAppendEntriesReply();
|
||||
SRpcMsg rpcMsg;
|
||||
syncAppendEntriesReply2RpcMsg(pMsg, &rpcMsg);
|
||||
syncRpcMsgPrint2((char *)"test7", &rpcMsg);
|
||||
syncAppendEntriesReplyDestroy(pMsg);
|
||||
}
|
||||
|
||||
void test8() {
|
||||
SyncClientRequest *pMsg = createSyncClientRequest();
|
||||
SRpcMsg rpcMsg;
|
||||
syncClientRequest2RpcMsg(pMsg, &rpcMsg);
|
||||
syncRpcMsgPrint2((char *)"test8", &rpcMsg);
|
||||
syncClientRequestDestroy(pMsg);
|
||||
}
|
||||
|
||||
int main() {
|
||||
// taosInitLog((char *)"syncTest.log", 100000, 10);
|
||||
tsAsyncLog = 0;
|
||||
sDebugFlag = 143 + 64;
|
||||
logTest();
|
||||
|
||||
test1();
|
||||
test2();
|
||||
test3();
|
||||
test4();
|
||||
test5();
|
||||
test6();
|
||||
test7();
|
||||
test8();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <stdio.h>
|
||||
#include "syncIO.h"
|
||||
#include "syncInt.h"
|
||||
#include "syncMessage.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");
|
||||
}
|
||||
|
||||
int gg = 0;
|
||||
|
||||
SyncTimeout *createMsg() {
|
||||
SyncTimeout *pMsg = syncTimeoutBuild2(SYNC_TIMEOUT_PING, 999, 333, &gg);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void test1() {
|
||||
SyncTimeout *pMsg = createMsg();
|
||||
syncTimeoutPrint2((char *)"test1:", pMsg);
|
||||
syncTimeoutDestroy(pMsg);
|
||||
}
|
||||
|
||||
void test2() {
|
||||
SyncTimeout *pMsg = createMsg();
|
||||
uint32_t len = pMsg->bytes;
|
||||
char * serialized = (char *)malloc(len);
|
||||
syncTimeoutSerialize(pMsg, serialized, len);
|
||||
SyncTimeout *pMsg2 = syncTimeoutBuild();
|
||||
syncTimeoutDeserialize(serialized, len, pMsg2);
|
||||
syncTimeoutPrint2((char *)"test2: syncTimeoutSerialize -> syncTimeoutDeserialize ", pMsg2);
|
||||
|
||||
free(serialized);
|
||||
syncTimeoutDestroy(pMsg);
|
||||
syncTimeoutDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test3() {
|
||||
SyncTimeout *pMsg = createMsg();
|
||||
uint32_t len;
|
||||
char * serialized = syncTimeoutSerialize2(pMsg, &len);
|
||||
SyncTimeout *pMsg2 = syncTimeoutDeserialize2(serialized, len);
|
||||
syncTimeoutPrint2((char *)"test3: syncTimeoutSerialize3 -> syncTimeoutDeserialize2 ", pMsg2);
|
||||
|
||||
free(serialized);
|
||||
syncTimeoutDestroy(pMsg);
|
||||
syncTimeoutDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test4() {
|
||||
SyncTimeout *pMsg = createMsg();
|
||||
SRpcMsg rpcMsg;
|
||||
syncTimeout2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncTimeout *pMsg2 = (SyncTimeout *)malloc(rpcMsg.contLen);
|
||||
syncTimeoutFromRpcMsg(&rpcMsg, pMsg2);
|
||||
syncTimeoutPrint2((char *)"test4: syncTimeout2RpcMsg -> syncTimeoutFromRpcMsg ", pMsg2);
|
||||
|
||||
syncTimeoutDestroy(pMsg);
|
||||
syncTimeoutDestroy(pMsg2);
|
||||
}
|
||||
|
||||
void test5() {
|
||||
SyncTimeout *pMsg = createMsg();
|
||||
SRpcMsg rpcMsg;
|
||||
syncTimeout2RpcMsg(pMsg, &rpcMsg);
|
||||
SyncTimeout *pMsg2 = syncTimeoutFromRpcMsg2(&rpcMsg);
|
||||
syncTimeoutPrint2((char *)"test5: syncTimeout2RpcMsg -> syncTimeoutFromRpcMsg2 ", pMsg2);
|
||||
|
||||
syncTimeoutDestroy(pMsg);
|
||||
syncTimeoutDestroy(pMsg2);
|
||||
}
|
||||
|
||||
int main() {
|
||||
// taosInitLog((char *)"syncTest.log", 100000, 10);
|
||||
tsAsyncLog = 0;
|
||||
sDebugFlag = 143 + 64;
|
||||
logTest();
|
||||
|
||||
test1();
|
||||
test2();
|
||||
test3();
|
||||
test4();
|
||||
test5();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -118,7 +118,7 @@ int main(int argc, char** argv) {
|
|||
}
|
||||
|
||||
for (int i = 0; i < replicaNum; ++i) {
|
||||
SyncRequestVoteReply* reply = SyncRequestVoteReplyBuild();
|
||||
SyncRequestVoteReply* reply = syncRequestVoteReplyBuild();
|
||||
reply->destId = pSyncNode->myRaftId;
|
||||
reply->srcId = ids[i];
|
||||
reply->term = term;
|
||||
|
|
|
@ -118,7 +118,7 @@ int main(int argc, char** argv) {
|
|||
}
|
||||
|
||||
for (int i = 0; i < replicaNum; ++i) {
|
||||
SyncRequestVoteReply* reply = SyncRequestVoteReplyBuild();
|
||||
SyncRequestVoteReply* reply = syncRequestVoteReplyBuild();
|
||||
reply->destId = pSyncNode->myRaftId;
|
||||
reply->srcId = ids[i];
|
||||
reply->term = term;
|
||||
|
|
|
@ -121,9 +121,8 @@ typedef struct {
|
|||
} SRpcReqContext;
|
||||
|
||||
typedef struct {
|
||||
SRpcInfo* pTransInst; // associated SRpcInfo
|
||||
SEpSet epSet; // ip list provided by app
|
||||
void* ahandle; // handle provided by app
|
||||
SEpSet epSet; // ip list provided by app
|
||||
void* ahandle; // handle provided by app
|
||||
// struct SRpcConn* pConn; // pConn allocated
|
||||
tmsg_t msgType; // message type
|
||||
uint8_t* pCont; // content provided by app
|
||||
|
@ -242,8 +241,12 @@ int transDestroyBuffer(SConnBuffer* buf);
|
|||
int transAllocBuffer(SConnBuffer* connBuf, uv_buf_t* uvBuf);
|
||||
bool transReadComplete(SConnBuffer* connBuf);
|
||||
|
||||
// int transPackMsg(SRpcMsg *rpcMsg, bool sercured, bool auth, char **msg, int32_t *msgLen);
|
||||
int transSetConnOption(uv_tcp_t* stream);
|
||||
|
||||
// int transUnpackMsg(char *msg, SRpcMsg *pMsg, bool );
|
||||
void transRefSrvHandle(void* handle);
|
||||
void transUnrefSrvHandle(void* handle);
|
||||
|
||||
void transRefCliHandle(void* handle);
|
||||
void transUnrefCliHandle(void* handle);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -54,7 +54,6 @@ typedef struct {
|
|||
int8_t connType;
|
||||
int64_t index;
|
||||
char label[TSDB_LABEL_LEN];
|
||||
bool noPool; // pool or not
|
||||
|
||||
char user[TSDB_UNI_LEN]; // meter ID
|
||||
char spi; // security parameter index
|
||||
|
|
|
@ -64,7 +64,6 @@ typedef struct {
|
|||
void (*cfp)(void *parent, SRpcMsg *, SEpSet *);
|
||||
int (*afp)(void *parent, char *user, char *spi, char *encrypt, char *secret, char *ckey);
|
||||
|
||||
bool noPool;
|
||||
int32_t refCount;
|
||||
void * parent;
|
||||
void * idPool; // handle to ID pool
|
||||
|
|
|
@ -41,7 +41,6 @@ void* rpcOpen(const SRpcInit* pInit) {
|
|||
pRpc->numOfThreads = pInit->numOfThreads;
|
||||
}
|
||||
|
||||
pRpc->noPool = pInit->noPool;
|
||||
pRpc->connType = pInit->connType;
|
||||
pRpc->idleTime = pInit->idleTime;
|
||||
pRpc->tcphandle = (*taosInitHandle[pRpc->connType])(0, pInit->localPort, pRpc->label, pRpc->numOfThreads, NULL, pRpc);
|
||||
|
@ -122,4 +121,17 @@ void rpcCleanup(void) {
|
|||
//
|
||||
return;
|
||||
}
|
||||
|
||||
void (*taosRefHandle[])(void* handle) = {transRefSrvHandle, transRefCliHandle};
|
||||
void (*taosUnRefHandle[])(void* handle) = {transUnrefSrvHandle, transUnrefCliHandle};
|
||||
|
||||
void rpcRefHandle(void* handle, int8_t type) {
|
||||
assert(type == TAOS_CONN_SERVER || type == TAOS_CONN_CLIENT);
|
||||
(*taosRefHandle[type])(handle);
|
||||
}
|
||||
void rpcUnrefHandle(void* handle, int8_t type) {
|
||||
assert(type == TAOS_CONN_SERVER || type == TAOS_CONN_CLIENT);
|
||||
(*taosUnRefHandle[type])(handle);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -17,30 +17,27 @@
|
|||
|
||||
#include "transComm.h"
|
||||
|
||||
#define CONN_HOST_THREAD_INDEX(conn) (conn ? ((SCliConn*)conn)->hThrdIdx : -1)
|
||||
#define CONN_PERSIST_TIME(para) (para * 1000 * 10)
|
||||
|
||||
typedef struct SCliConn {
|
||||
T_REF_DECLARE()
|
||||
uv_connect_t connReq;
|
||||
uv_stream_t* stream;
|
||||
uv_write_t* writeReq;
|
||||
uv_write_t writeReq;
|
||||
void* hostThrd;
|
||||
SConnBuffer readBuf;
|
||||
void* data;
|
||||
queue conn;
|
||||
uint64_t expireTime;
|
||||
int8_t ctnRdCnt; // continue read count
|
||||
int hThrdIdx;
|
||||
bool broken; // link broken or not
|
||||
|
||||
SRpcPush* push;
|
||||
int persist; //
|
||||
int persist; //
|
||||
// spi configure
|
||||
char spi;
|
||||
char secured;
|
||||
int32_t ref;
|
||||
char spi;
|
||||
char secured;
|
||||
// debug and log info
|
||||
struct sockaddr_in addr;
|
||||
struct sockaddr_in locaddr;
|
||||
|
||||
} SCliConn;
|
||||
|
||||
typedef struct SCliMsg {
|
||||
|
@ -51,25 +48,27 @@ typedef struct SCliMsg {
|
|||
} SCliMsg;
|
||||
|
||||
typedef struct SCliThrdObj {
|
||||
pthread_t thread;
|
||||
uv_loop_t* loop;
|
||||
// uv_async_t* cliAsync; //
|
||||
SAsyncPool* asyncPool;
|
||||
uv_timer_t* timer;
|
||||
void* pool; // conn pool
|
||||
pthread_t thread;
|
||||
uv_loop_t* loop;
|
||||
SAsyncPool* asyncPool;
|
||||
uv_timer_t timer;
|
||||
void* pool; // conn pool
|
||||
|
||||
// msg queue
|
||||
queue msg;
|
||||
pthread_mutex_t msgMtx;
|
||||
uint64_t nextTimeout; // next timeout
|
||||
void* pTransInst; //
|
||||
bool quit;
|
||||
|
||||
uint64_t nextTimeout; // next timeout
|
||||
void* pTransInst; //
|
||||
bool quit;
|
||||
} SCliThrdObj;
|
||||
|
||||
typedef struct SClientObj {
|
||||
typedef struct SCliObj {
|
||||
char label[TSDB_LABEL_LEN];
|
||||
int32_t index;
|
||||
int numOfThreads;
|
||||
SCliThrdObj** pThreadObj;
|
||||
} SClientObj;
|
||||
} SCliObj;
|
||||
|
||||
typedef struct SConnList {
|
||||
queue conn;
|
||||
|
@ -77,48 +76,74 @@ typedef struct SConnList {
|
|||
|
||||
// conn pool
|
||||
// add expire timeout and capacity limit
|
||||
static void* creatConnPool(int size);
|
||||
static void* createConnPool(int size);
|
||||
static void* destroyConnPool(void* pool);
|
||||
static SCliConn* getConnFromPool(void* pool, char* ip, uint32_t port);
|
||||
static void addConnToPool(void* pool, char* ip, uint32_t port, SCliConn* conn);
|
||||
|
||||
// register timer in each thread to clear expire conn
|
||||
static void clientTimeoutCb(uv_timer_t* handle);
|
||||
// alloc buf for read
|
||||
static void clientAllocBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf);
|
||||
// callback after read nbytes from socket
|
||||
static void clientReadCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf);
|
||||
static void cliTimeoutCb(uv_timer_t* handle);
|
||||
// alloc buf for recv
|
||||
static void cliAllocBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf);
|
||||
// callback after read nbytes from socket
|
||||
static void cliRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf);
|
||||
// callback after write data to socket
|
||||
static void clientWriteCb(uv_write_t* req, int status);
|
||||
static void cliSendCb(uv_write_t* req, int status);
|
||||
// callback after conn to server
|
||||
static void clientConnCb(uv_connect_t* req, int status);
|
||||
static void clientAsyncCb(uv_async_t* handle);
|
||||
static void clientDestroy(uv_handle_t* handle);
|
||||
static void clientConnDestroy(SCliConn* pConn, bool clear /*clear tcp handle or not*/);
|
||||
static void cliConnCb(uv_connect_t* req, int status);
|
||||
static void cliAsyncCb(uv_async_t* handle);
|
||||
|
||||
// process data read from server, auth/decompress etc later
|
||||
static void clientHandleResp(SCliConn* conn);
|
||||
static SCliConn* cliCreateConn(SCliThrdObj* thrd);
|
||||
static void cliDestroyConn(SCliConn* pConn, bool clear /*clear tcp handle or not*/);
|
||||
static void cliDestroy(uv_handle_t* handle);
|
||||
|
||||
// process data read from server, add decompress etc later
|
||||
static void cliHandleResp(SCliConn* conn);
|
||||
// handle except about conn
|
||||
static void clientHandleExcept(SCliConn* conn);
|
||||
static void cliHandleExcept(SCliConn* conn);
|
||||
// handle req from app
|
||||
static void clientHandleReq(SCliMsg* pMsg, SCliThrdObj* pThrd);
|
||||
static void clientHandleQuit(SCliMsg* pMsg, SCliThrdObj* pThrd);
|
||||
static void clientSendQuit(SCliThrdObj* thrd);
|
||||
|
||||
static void cliHandleReq(SCliMsg* pMsg, SCliThrdObj* pThrd);
|
||||
static void cliHandleQuit(SCliMsg* pMsg, SCliThrdObj* pThrd);
|
||||
static void cliSendQuit(SCliThrdObj* thrd);
|
||||
static void destroyUserdata(SRpcMsg* userdata);
|
||||
|
||||
static int cliRBChoseIdx(SRpcInfo* pTransInst);
|
||||
|
||||
static void destroyCmsg(SCliMsg* cmsg);
|
||||
static void transDestroyConnCtx(STransConnCtx* ctx);
|
||||
// thread obj
|
||||
static SCliThrdObj* createThrdObj();
|
||||
static void destroyThrdObj(SCliThrdObj* pThrd);
|
||||
// thread
|
||||
static void* clientThread(void* arg);
|
||||
|
||||
static void clientHandleResp(SCliConn* conn) {
|
||||
#define CONN_HOST_THREAD_INDEX(conn) (conn ? ((SCliConn*)conn)->hThrdIdx : -1)
|
||||
#define CONN_PERSIST_TIME(para) (para * 1000 * 10)
|
||||
|
||||
#define CONN_GET_INST_LABEL(conn) (((SRpcInfo*)(((SCliThrdObj*)conn->hostThrd)->pTransInst))->label)
|
||||
#define CONN_HANDLE_THREAD_QUIT(conn, thrd) \
|
||||
do { \
|
||||
if (thrd->quit) { \
|
||||
cliHandleExcept(conn); \
|
||||
goto _RETURE; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CONN_HANDLE_BROKEN(conn) \
|
||||
do { \
|
||||
if (conn->broken) { \
|
||||
cliHandleExcept(conn); \
|
||||
goto _RETURE; \
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
static void* cliWorkThread(void* arg);
|
||||
|
||||
static void* cliNotifyApp() {}
|
||||
static void cliHandleResp(SCliConn* conn) {
|
||||
SCliMsg* pMsg = conn->data;
|
||||
STransConnCtx* pCtx = pMsg->ctx;
|
||||
SRpcInfo* pRpc = pCtx->pTransInst;
|
||||
|
||||
SCliThrdObj* pThrd = conn->hostThrd;
|
||||
SRpcInfo* pTransInst = pThrd->pTransInst;
|
||||
|
||||
STransMsgHead* pHead = (STransMsgHead*)(conn->readBuf.buf);
|
||||
pHead->code = htonl(pHead->code);
|
||||
|
@ -134,56 +159,52 @@ static void clientHandleResp(SCliConn* conn) {
|
|||
rpcMsg.msgType = pHead->msgType;
|
||||
rpcMsg.ahandle = pCtx->ahandle;
|
||||
|
||||
if (pRpc->pfp != NULL && (pRpc->pfp)(pRpc->parent, rpcMsg.msgType)) {
|
||||
if (pTransInst->pfp != NULL && (pTransInst->pfp)(pTransInst->parent, rpcMsg.msgType)) {
|
||||
rpcMsg.handle = conn;
|
||||
transRefCliHandle(conn);
|
||||
|
||||
conn->persist = 1;
|
||||
tDebug("client conn %p persist by app", conn);
|
||||
tDebug("cli conn %p persist by app", conn);
|
||||
}
|
||||
|
||||
tDebug("%s client conn %p %s received from %s:%d, local info: %s:%d, msg size: %d", pRpc->label, conn,
|
||||
tDebug("%s cli conn %p %s received from %s:%d, local info: %s:%d, msg size: %d", pTransInst->label, conn,
|
||||
TMSG_INFO(pHead->msgType), inet_ntoa(conn->addr.sin_addr), ntohs(conn->addr.sin_port),
|
||||
inet_ntoa(conn->locaddr.sin_addr), ntohs(conn->locaddr.sin_port), rpcMsg.contLen);
|
||||
|
||||
conn->secured = pHead->secured;
|
||||
if (conn->push != NULL && conn->ctnRdCnt != 0) {
|
||||
(*conn->push->callback)(conn->push->arg, &rpcMsg);
|
||||
conn->push = NULL;
|
||||
|
||||
if (pCtx->pSem == NULL) {
|
||||
tTrace("%s cli conn %p handle resp", pTransInst->label, conn);
|
||||
(pTransInst->cfp)(pTransInst->parent, &rpcMsg, NULL);
|
||||
} else {
|
||||
if (pCtx->pSem == NULL) {
|
||||
tTrace("%s client conn %p handle resp", pRpc->label, conn);
|
||||
(pRpc->cfp)(pRpc->parent, &rpcMsg, NULL);
|
||||
} else {
|
||||
tTrace("%s client conn(sync) %p handle resp", pRpc->label, conn);
|
||||
memcpy((char*)pCtx->pRsp, (char*)&rpcMsg, sizeof(rpcMsg));
|
||||
tsem_post(pCtx->pSem);
|
||||
}
|
||||
tTrace("%s cli conn(sync) %p handle resp", pTransInst->label, conn);
|
||||
memcpy((char*)pCtx->pRsp, (char*)&rpcMsg, sizeof(rpcMsg));
|
||||
tsem_post(pCtx->pSem);
|
||||
}
|
||||
conn->ctnRdCnt += 1;
|
||||
|
||||
uv_read_start((uv_stream_t*)conn->stream, clientAllocBufferCb, clientReadCb);
|
||||
|
||||
SCliThrdObj* pThrd = conn->hostThrd;
|
||||
uv_read_start((uv_stream_t*)conn->stream, cliAllocBufferCb, cliRecvCb);
|
||||
|
||||
// user owns conn->persist = 1
|
||||
if (conn->push == NULL && conn->persist == 0) {
|
||||
if (pRpc->noPool == true) {
|
||||
} else {
|
||||
addConnToPool(pThrd->pool, pCtx->ip, pCtx->port, conn);
|
||||
}
|
||||
if (conn->persist == 0) {
|
||||
addConnToPool(pThrd->pool, pCtx->ip, pCtx->port, conn);
|
||||
}
|
||||
destroyCmsg(conn->data);
|
||||
conn->data = NULL;
|
||||
|
||||
// start thread's timer of conn pool if not active
|
||||
if (!uv_is_active((uv_handle_t*)pThrd->timer) && pRpc->idleTime > 0) {
|
||||
// uv_timer_start((uv_timer_t*)pThrd->timer, clientTimeoutCb, CONN_PERSIST_TIME(pRpc->idleTime) / 2, 0);
|
||||
if (!uv_is_active((uv_handle_t*)&pThrd->timer) && pTransInst->idleTime > 0) {
|
||||
// uv_timer_start((uv_timer_t*)&pThrd->timer, cliTimeoutCb, CONN_PERSIST_TIME(pRpc->idleTime) / 2, 0);
|
||||
}
|
||||
}
|
||||
static void clientHandleExcept(SCliConn* pConn) {
|
||||
if (pConn->data == NULL && pConn->push == NULL) {
|
||||
static void cliHandleExcept(SCliConn* pConn) {
|
||||
if (pConn->data == NULL) {
|
||||
// handle conn except in conn pool
|
||||
clientConnDestroy(pConn, true);
|
||||
transUnrefCliHandle(pConn);
|
||||
return;
|
||||
}
|
||||
SCliThrdObj* pThrd = pConn->hostThrd;
|
||||
SRpcInfo* pTransInst = pThrd->pTransInst;
|
||||
|
||||
SCliMsg* pMsg = pConn->data;
|
||||
STransConnCtx* pCtx = pMsg->ctx;
|
||||
|
||||
|
@ -192,36 +213,26 @@ static void clientHandleExcept(SCliConn* pConn) {
|
|||
rpcMsg.code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
||||
rpcMsg.msgType = pMsg->msg.msgType + 1;
|
||||
|
||||
if (pConn->push != NULL && pConn->ctnRdCnt != 0) {
|
||||
(*pConn->push->callback)(pConn->push->arg, &rpcMsg);
|
||||
pConn->push = NULL;
|
||||
if (pCtx->pSem == NULL) {
|
||||
tTrace("%s cli conn %p handle resp", pTransInst->label, pConn);
|
||||
(pTransInst->cfp)(pTransInst->parent, &rpcMsg, NULL);
|
||||
} else {
|
||||
if (pCtx->pSem == NULL) {
|
||||
(pCtx->pTransInst->cfp)(pCtx->pTransInst->parent, &rpcMsg, NULL);
|
||||
} else {
|
||||
memcpy((char*)(pCtx->pRsp), (char*)(&rpcMsg), sizeof(rpcMsg));
|
||||
tsem_post(pCtx->pSem);
|
||||
}
|
||||
if (pConn->push != NULL) {
|
||||
(*pConn->push->callback)(pConn->push->arg, &rpcMsg);
|
||||
}
|
||||
pConn->push = NULL;
|
||||
tTrace("%s cli conn(sync) %p handle resp", pTransInst->label, pConn);
|
||||
memcpy((char*)(pCtx->pRsp), (char*)(&rpcMsg), sizeof(rpcMsg));
|
||||
tsem_post(pCtx->pSem);
|
||||
}
|
||||
tTrace("%s client conn %p start to destroy", pCtx->pTransInst->label, pConn);
|
||||
if (pConn->push == NULL) {
|
||||
destroyCmsg(pConn->data);
|
||||
pConn->data = NULL;
|
||||
}
|
||||
// transDestroyConnCtx(pCtx);
|
||||
clientConnDestroy(pConn, true);
|
||||
pConn->ctnRdCnt += 1;
|
||||
destroyCmsg(pConn->data);
|
||||
pConn->data = NULL;
|
||||
|
||||
tTrace("%s cli conn %p start to destroy", CONN_GET_INST_LABEL(pConn), pConn);
|
||||
transUnrefCliHandle(pConn);
|
||||
}
|
||||
|
||||
static void clientTimeoutCb(uv_timer_t* handle) {
|
||||
static void cliTimeoutCb(uv_timer_t* handle) {
|
||||
SCliThrdObj* pThrd = handle->data;
|
||||
SRpcInfo* pRpc = pThrd->pTransInst;
|
||||
int64_t currentTime = pThrd->nextTimeout;
|
||||
tTrace("%s, client conn timeout, try to remove expire conn from conn pool", pRpc->label);
|
||||
tTrace("%s, cli conn timeout, try to remove expire conn from conn pool", pRpc->label);
|
||||
|
||||
SConnList* p = taosHashIterate((SHashObj*)pThrd->pool, NULL);
|
||||
while (p != NULL) {
|
||||
|
@ -230,9 +241,7 @@ static void clientTimeoutCb(uv_timer_t* handle) {
|
|||
SCliConn* c = QUEUE_DATA(h, SCliConn, conn);
|
||||
if (c->expireTime < currentTime) {
|
||||
QUEUE_REMOVE(h);
|
||||
// uv_stream_t stm = *(c->stream);
|
||||
// uv_close((uv_handle_t*)&stm, clientDestroy);
|
||||
clientConnDestroy(c, true);
|
||||
transUnrefCliHandle(c);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
@ -241,9 +250,9 @@ static void clientTimeoutCb(uv_timer_t* handle) {
|
|||
}
|
||||
|
||||
pThrd->nextTimeout = taosGetTimestampMs() + CONN_PERSIST_TIME(pRpc->idleTime);
|
||||
uv_timer_start(handle, clientTimeoutCb, CONN_PERSIST_TIME(pRpc->idleTime) / 2, 0);
|
||||
uv_timer_start(handle, cliTimeoutCb, CONN_PERSIST_TIME(pRpc->idleTime) / 2, 0);
|
||||
}
|
||||
static void* creatConnPool(int size) {
|
||||
static void* createConnPool(int size) {
|
||||
// thread local, no lock
|
||||
return taosHashInit(size, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
|
||||
}
|
||||
|
@ -254,11 +263,11 @@ static void* destroyConnPool(void* pool) {
|
|||
queue* h = QUEUE_HEAD(&connList->conn);
|
||||
QUEUE_REMOVE(h);
|
||||
SCliConn* c = QUEUE_DATA(h, SCliConn, conn);
|
||||
clientConnDestroy(c, true);
|
||||
cliDestroyConn(c, true);
|
||||
}
|
||||
connList = taosHashIterate((SHashObj*)pool, connList);
|
||||
}
|
||||
taosHashClear(pool);
|
||||
taosHashCleanup(pool);
|
||||
}
|
||||
|
||||
static SCliConn* getConnFromPool(void* pool, char* ip, uint32_t port) {
|
||||
|
@ -290,23 +299,22 @@ static void addConnToPool(void* pool, char* ip, uint32_t port, SCliConn* conn) {
|
|||
|
||||
tstrncpy(key, ip, strlen(ip));
|
||||
tstrncpy(key + strlen(key), (char*)(&port), sizeof(port));
|
||||
tTrace("client conn %p added to conn pool, read buf cap: %d", conn, conn->readBuf.cap);
|
||||
tTrace("cli conn %p added to conn pool, read buf cap: %d", conn, conn->readBuf.cap);
|
||||
|
||||
SRpcInfo* pRpc = ((SCliThrdObj*)conn->hostThrd)->pTransInst;
|
||||
|
||||
conn->expireTime = taosGetTimestampMs() + CONN_PERSIST_TIME(pRpc->idleTime);
|
||||
SConnList* plist = taosHashGet((SHashObj*)pool, key, strlen(key));
|
||||
conn->ctnRdCnt = 0;
|
||||
// list already create before
|
||||
assert(plist != NULL);
|
||||
QUEUE_PUSH(&plist->conn, &conn->conn);
|
||||
}
|
||||
static void clientAllocBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) {
|
||||
static void cliAllocBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) {
|
||||
SCliConn* conn = handle->data;
|
||||
SConnBuffer* pBuf = &conn->readBuf;
|
||||
transAllocBuffer(pBuf, buf);
|
||||
}
|
||||
static void clientReadCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) {
|
||||
static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) {
|
||||
// impl later
|
||||
if (handle->data == NULL) {
|
||||
return;
|
||||
|
@ -316,17 +324,14 @@ static void clientReadCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf
|
|||
if (nread > 0) {
|
||||
pBuf->len += nread;
|
||||
if (transReadComplete(pBuf)) {
|
||||
tTrace("client conn %p read complete", conn);
|
||||
clientHandleResp(conn);
|
||||
tTrace("%s cli conn %p read complete", CONN_GET_INST_LABEL(conn), conn);
|
||||
cliHandleResp(conn);
|
||||
} else {
|
||||
tTrace("client conn %p read partial packet, continue to read", conn);
|
||||
tTrace("%s cli conn %p read partial packet, continue to read", CONN_GET_INST_LABEL(conn), conn);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (nread == UV_EOF) {
|
||||
tError("client conn %p read error: %s", conn, uv_err_name(nread));
|
||||
clientHandleExcept(conn);
|
||||
}
|
||||
|
||||
assert(nread <= 0);
|
||||
if (nread == 0) {
|
||||
// ref http://docs.libuv.org/en/v1.x/stream.html?highlight=uv_read_start#c.uv_read_cb
|
||||
|
@ -335,59 +340,69 @@ static void clientReadCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf
|
|||
return;
|
||||
}
|
||||
if (nread < 0) {
|
||||
tError("client conn %p read error: %s", conn, uv_err_name(nread));
|
||||
clientHandleExcept(conn);
|
||||
tError("%s cli conn %p read error: %s", CONN_GET_INST_LABEL(conn), conn, uv_err_name(nread));
|
||||
conn->broken = true;
|
||||
cliHandleExcept(conn);
|
||||
}
|
||||
// tDebug("Read error %s\n", uv_err_name(nread));
|
||||
// uv_close((uv_handle_t*)handle, clientDestroy);
|
||||
}
|
||||
|
||||
static void clientConnDestroy(SCliConn* conn, bool clear) {
|
||||
//
|
||||
conn->ref--;
|
||||
if (conn->ref == 0) {
|
||||
tTrace("client conn %p remove from conn pool", conn);
|
||||
QUEUE_REMOVE(&conn->conn);
|
||||
if (clear) {
|
||||
uv_close((uv_handle_t*)conn->stream, clientDestroy);
|
||||
}
|
||||
static SCliConn* cliCreateConn(SCliThrdObj* pThrd) {
|
||||
SCliConn* conn = calloc(1, sizeof(SCliConn));
|
||||
// read/write stream handle
|
||||
conn->stream = (uv_stream_t*)malloc(sizeof(uv_tcp_t));
|
||||
uv_tcp_init(pThrd->loop, (uv_tcp_t*)(conn->stream));
|
||||
conn->stream->data = conn;
|
||||
|
||||
conn->writeReq.data = conn;
|
||||
conn->connReq.data = conn;
|
||||
|
||||
QUEUE_INIT(&conn->conn);
|
||||
conn->hostThrd = pThrd;
|
||||
conn->broken = false;
|
||||
transRefCliHandle(conn);
|
||||
return conn;
|
||||
}
|
||||
static void cliDestroyConn(SCliConn* conn, bool clear) {
|
||||
tTrace("%s cli conn %p remove from conn pool", CONN_GET_INST_LABEL(conn), conn);
|
||||
QUEUE_REMOVE(&conn->conn);
|
||||
if (clear) {
|
||||
uv_close((uv_handle_t*)conn->stream, cliDestroy);
|
||||
}
|
||||
}
|
||||
static void clientDestroy(uv_handle_t* handle) {
|
||||
static void cliDestroy(uv_handle_t* handle) {
|
||||
SCliConn* conn = handle->data;
|
||||
// transDestroyBuffer(&conn->readBuf);
|
||||
|
||||
free(conn->stream);
|
||||
free(conn->writeReq);
|
||||
tTrace("client conn %p destroy successfully", conn);
|
||||
tTrace("%s cli conn %p destroy successfully", CONN_GET_INST_LABEL(conn), conn);
|
||||
free(conn);
|
||||
|
||||
// clientConnDestroy(conn, false);
|
||||
}
|
||||
|
||||
static void clientWriteCb(uv_write_t* req, int status) {
|
||||
static void cliSendCb(uv_write_t* req, int status) {
|
||||
SCliConn* pConn = req->data;
|
||||
|
||||
if (status == 0) {
|
||||
tTrace("client conn %p data already was written out", pConn);
|
||||
tTrace("%s cli conn %p data already was written out", CONN_GET_INST_LABEL(pConn), pConn);
|
||||
SCliMsg* pMsg = pConn->data;
|
||||
if (pMsg == NULL) {
|
||||
// handle
|
||||
return;
|
||||
}
|
||||
destroyUserdata(&pMsg->msg);
|
||||
} else {
|
||||
tError("client conn %p failed to write: %s", pConn, uv_err_name(status));
|
||||
clientHandleExcept(pConn);
|
||||
tError("%s cli conn %p failed to write: %s", CONN_GET_INST_LABEL(pConn), pConn, uv_err_name(status));
|
||||
cliHandleExcept(pConn);
|
||||
return;
|
||||
}
|
||||
SCliThrdObj* pThrd = pConn->hostThrd;
|
||||
uv_read_start((uv_stream_t*)pConn->stream, clientAllocBufferCb, clientReadCb);
|
||||
uv_read_start((uv_stream_t*)pConn->stream, cliAllocBufferCb, cliRecvCb);
|
||||
}
|
||||
|
||||
static void clientWrite(SCliConn* pConn) {
|
||||
static void cliSend(SCliConn* pConn) {
|
||||
CONN_HANDLE_BROKEN(pConn);
|
||||
|
||||
SCliMsg* pCliMsg = pConn->data;
|
||||
STransConnCtx* pCtx = pCliMsg->ctx;
|
||||
SRpcInfo* pTransInst = pCtx->pTransInst;
|
||||
|
||||
SCliThrdObj* pThrd = pConn->hostThrd;
|
||||
SRpcInfo* pTransInst = pThrd->pTransInst;
|
||||
|
||||
SRpcMsg* pMsg = (SRpcMsg*)(&pCliMsg->msg);
|
||||
|
||||
|
@ -416,21 +431,23 @@ static void clientWrite(SCliConn* pConn) {
|
|||
pHead->msgType = pMsg->msgType;
|
||||
pHead->msgLen = (int32_t)htonl((uint32_t)msgLen);
|
||||
|
||||
// if (pHead->msgType == TDMT_VND_QUERY || pHead->msgType == TDMT_VND_)
|
||||
|
||||
uv_buf_t wb = uv_buf_init((char*)pHead, msgLen);
|
||||
tDebug("client conn %p %s is send to %s:%d, local info %s:%d", pConn, TMSG_INFO(pHead->msgType),
|
||||
inet_ntoa(pConn->addr.sin_addr), ntohs(pConn->addr.sin_port), inet_ntoa(pConn->locaddr.sin_addr),
|
||||
ntohs(pConn->locaddr.sin_port));
|
||||
uv_write(pConn->writeReq, (uv_stream_t*)pConn->stream, &wb, 1, clientWriteCb);
|
||||
tDebug("%s cli conn %p %s is send to %s:%d, local info %s:%d", CONN_GET_INST_LABEL(pConn), pConn,
|
||||
TMSG_INFO(pHead->msgType), inet_ntoa(pConn->addr.sin_addr), ntohs(pConn->addr.sin_port),
|
||||
inet_ntoa(pConn->locaddr.sin_addr), ntohs(pConn->locaddr.sin_port));
|
||||
|
||||
uv_write(&pConn->writeReq, (uv_stream_t*)pConn->stream, &wb, 1, cliSendCb);
|
||||
|
||||
return;
|
||||
_RETURE:
|
||||
return;
|
||||
}
|
||||
static void clientConnCb(uv_connect_t* req, int status) {
|
||||
static void cliConnCb(uv_connect_t* req, int status) {
|
||||
// impl later
|
||||
SCliConn* pConn = req->data;
|
||||
if (status != 0) {
|
||||
// tError("failed to connect server(%s, %d), errmsg: %s", pCtx->ip, pCtx->port, uv_strerror(status));
|
||||
tError("client conn %p failed to connect server: %s", pConn, uv_strerror(status));
|
||||
clientHandleExcept(pConn);
|
||||
tError("%s cli conn %p failed to connect server: %s", CONN_GET_INST_LABEL(pConn), pConn, uv_strerror(status));
|
||||
cliHandleExcept(pConn);
|
||||
return;
|
||||
}
|
||||
int addrlen = sizeof(pConn->addr);
|
||||
|
@ -439,100 +456,73 @@ static void clientConnCb(uv_connect_t* req, int status) {
|
|||
addrlen = sizeof(pConn->locaddr);
|
||||
uv_tcp_getsockname((uv_tcp_t*)pConn->stream, (struct sockaddr*)&pConn->locaddr, &addrlen);
|
||||
|
||||
tTrace("client conn %p connect to server successfully", pConn);
|
||||
tTrace("%s cli conn %p connect to server successfully", CONN_GET_INST_LABEL(pConn), pConn);
|
||||
|
||||
assert(pConn->stream == req->handle);
|
||||
clientWrite(pConn);
|
||||
cliSend(pConn);
|
||||
}
|
||||
|
||||
static void clientHandleQuit(SCliMsg* pMsg, SCliThrdObj* pThrd) {
|
||||
tDebug("client work thread %p start to quit", pThrd);
|
||||
static void cliHandleQuit(SCliMsg* pMsg, SCliThrdObj* pThrd) {
|
||||
tDebug("cli work thread %p start to quit", pThrd);
|
||||
destroyCmsg(pMsg);
|
||||
destroyConnPool(pThrd->pool);
|
||||
// transDestroyAsyncPool(pThr) uv_close((uv_handle_t*)pThrd->cliAsync, NULL);
|
||||
uv_timer_stop(pThrd->timer);
|
||||
|
||||
uv_timer_stop(&pThrd->timer);
|
||||
|
||||
pThrd->quit = true;
|
||||
// uv__async_stop(pThrd->cliAsync);
|
||||
uv_stop(pThrd->loop);
|
||||
}
|
||||
static void clientHandleReq(SCliMsg* pMsg, SCliThrdObj* pThrd) {
|
||||
static SCliConn* cliGetConn(SCliMsg* pMsg, SCliThrdObj* pThrd) {
|
||||
SCliConn* conn = NULL;
|
||||
if (pMsg->msg.handle != NULL) {
|
||||
conn = (SCliConn*)(pMsg->msg.handle);
|
||||
transUnrefCliHandle(conn);
|
||||
if (conn != NULL) {
|
||||
tTrace("%s cli conn %p reused", CONN_GET_INST_LABEL(conn), conn);
|
||||
}
|
||||
} else {
|
||||
STransConnCtx* pCtx = pMsg->ctx;
|
||||
conn = getConnFromPool(pThrd->pool, pCtx->ip, pCtx->port);
|
||||
if (conn != NULL) tTrace("%s cli conn %p get from conn pool", CONN_GET_INST_LABEL(conn), conn);
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
static void cliHandleReq(SCliMsg* pMsg, SCliThrdObj* pThrd) {
|
||||
uint64_t et = taosGetTimestampUs();
|
||||
uint64_t el = et - pMsg->st;
|
||||
tTrace("client msg tran time cost: %" PRIu64 "us", el);
|
||||
et = taosGetTimestampUs();
|
||||
tTrace("%s cli msg tran time cost: %" PRIu64 "us", ((SRpcInfo*)pThrd->pTransInst)->label, el);
|
||||
|
||||
STransConnCtx* pCtx = pMsg->ctx;
|
||||
SRpcInfo* pTransInst = pThrd->pTransInst;
|
||||
|
||||
SCliConn* conn = NULL;
|
||||
if (pMsg->msg.handle == NULL) {
|
||||
if (pCtx->pTransInst->noPool == true) {
|
||||
} else {
|
||||
conn = getConnFromPool(pThrd->pool, pCtx->ip, pCtx->port);
|
||||
}
|
||||
if (conn != NULL) {
|
||||
tTrace("client conn %p get from conn pool", conn);
|
||||
}
|
||||
} else {
|
||||
conn = (SCliConn*)(pMsg->msg.handle);
|
||||
if (conn != NULL) {
|
||||
tTrace("client conn %p reused", conn);
|
||||
}
|
||||
}
|
||||
|
||||
SCliConn* conn = cliGetConn(pMsg, pThrd);
|
||||
if (conn != NULL) {
|
||||
conn->data = pMsg;
|
||||
conn->writeReq->data = conn;
|
||||
transDestroyBuffer(&conn->readBuf);
|
||||
|
||||
if (pThrd->quit) {
|
||||
clientHandleExcept(conn);
|
||||
return;
|
||||
}
|
||||
clientWrite(conn);
|
||||
|
||||
cliSend(conn);
|
||||
} else {
|
||||
conn = calloc(1, sizeof(SCliConn));
|
||||
conn->ref++;
|
||||
// read/write stream handle
|
||||
conn->stream = (uv_stream_t*)malloc(sizeof(uv_tcp_t));
|
||||
uv_tcp_init(pThrd->loop, (uv_tcp_t*)(conn->stream));
|
||||
conn->stream->data = conn;
|
||||
uv_tcp_nodelay((uv_tcp_t*)conn->stream, 1);
|
||||
int ret = uv_tcp_keepalive((uv_tcp_t*)conn->stream, 1, 1);
|
||||
if (ret) {
|
||||
tTrace("client conn %p failed to set keepalive, %s", conn, uv_err_name(ret));
|
||||
}
|
||||
// write req handle
|
||||
conn->writeReq = malloc(sizeof(uv_write_t));
|
||||
conn->writeReq->data = conn;
|
||||
|
||||
QUEUE_INIT(&conn->conn);
|
||||
|
||||
conn->connReq.data = conn;
|
||||
conn = cliCreateConn(pThrd);
|
||||
conn->data = pMsg;
|
||||
conn->hostThrd = pThrd;
|
||||
|
||||
// conn->push = pMsg->msg.push;
|
||||
// conn->ctnRdCnt = 0;
|
||||
|
||||
int ret = transSetConnOption((uv_tcp_t*)conn->stream);
|
||||
if (ret) {
|
||||
tError("%s cli conn %p failed to set conn option, errmsg %s", pTransInst->label, conn, uv_err_name(ret));
|
||||
}
|
||||
struct sockaddr_in addr;
|
||||
uv_ip4_addr(pMsg->ctx->ip, pMsg->ctx->port, &addr);
|
||||
// handle error in callback if fail to connect
|
||||
tTrace("client conn %p try to connect to %s:%d", conn, pMsg->ctx->ip, pMsg->ctx->port);
|
||||
uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, clientConnCb);
|
||||
tTrace("%s cli conn %p try to connect to %s:%d", pTransInst->label, conn, pMsg->ctx->ip, pMsg->ctx->port);
|
||||
uv_tcp_connect(&conn->connReq, (uv_tcp_t*)(conn->stream), (const struct sockaddr*)&addr, cliConnCb);
|
||||
}
|
||||
|
||||
conn->push = pMsg->msg.push;
|
||||
conn->ctnRdCnt = 0;
|
||||
conn->hThrdIdx = pCtx->hThrdIdx;
|
||||
}
|
||||
static void clientAsyncCb(uv_async_t* handle) {
|
||||
static void cliAsyncCb(uv_async_t* handle) {
|
||||
SAsyncItem* item = handle->data;
|
||||
SCliThrdObj* pThrd = item->pThrd;
|
||||
SCliMsg* pMsg = NULL;
|
||||
queue wq;
|
||||
|
||||
// batch process to avoid to lock/unlock frequently
|
||||
queue wq;
|
||||
pthread_mutex_lock(&item->mtx);
|
||||
QUEUE_MOVE(&item->qmsg, &wq);
|
||||
pthread_mutex_unlock(&item->mtx);
|
||||
|
@ -544,26 +534,25 @@ static void clientAsyncCb(uv_async_t* handle) {
|
|||
|
||||
SCliMsg* pMsg = QUEUE_DATA(h, SCliMsg, q);
|
||||
if (pMsg->ctx == NULL) {
|
||||
clientHandleQuit(pMsg, pThrd);
|
||||
cliHandleQuit(pMsg, pThrd);
|
||||
} else {
|
||||
clientHandleReq(pMsg, pThrd);
|
||||
cliHandleReq(pMsg, pThrd);
|
||||
}
|
||||
// clientHandleReq(pMsg, pThrd);
|
||||
count++;
|
||||
}
|
||||
if (count >= 2) {
|
||||
tTrace("client process batch size: %d", count);
|
||||
tTrace("cli process batch size: %d", count);
|
||||
}
|
||||
}
|
||||
|
||||
static void* clientThread(void* arg) {
|
||||
static void* cliWorkThread(void* arg) {
|
||||
SCliThrdObj* pThrd = (SCliThrdObj*)arg;
|
||||
setThreadName("trans-client-work");
|
||||
setThreadName("trans-cli-work");
|
||||
uv_run(pThrd->loop, UV_RUN_DEFAULT);
|
||||
}
|
||||
|
||||
void* taosInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, void* fp, void* shandle) {
|
||||
SClientObj* cli = calloc(1, sizeof(SClientObj));
|
||||
SCliObj* cli = calloc(1, sizeof(SCliObj));
|
||||
|
||||
SRpcInfo* pRpc = shandle;
|
||||
memcpy(cli->label, label, strlen(label));
|
||||
|
@ -575,9 +564,9 @@ void* taosInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
|||
pThrd->nextTimeout = taosGetTimestampMs() + CONN_PERSIST_TIME(pRpc->idleTime);
|
||||
pThrd->pTransInst = shandle;
|
||||
|
||||
int err = pthread_create(&pThrd->thread, NULL, clientThread, (void*)(pThrd));
|
||||
int err = pthread_create(&pThrd->thread, NULL, cliWorkThread, (void*)(pThrd));
|
||||
if (err == 0) {
|
||||
tDebug("success to create tranport-client thread %d", i);
|
||||
tDebug("success to create tranport-cli thread %d", i);
|
||||
}
|
||||
cli->pThreadObj[i] = pThrd;
|
||||
}
|
||||
|
@ -602,19 +591,19 @@ static void destroyCmsg(SCliMsg* pMsg) {
|
|||
|
||||
static SCliThrdObj* createThrdObj() {
|
||||
SCliThrdObj* pThrd = (SCliThrdObj*)calloc(1, sizeof(SCliThrdObj));
|
||||
|
||||
QUEUE_INIT(&pThrd->msg);
|
||||
pthread_mutex_init(&pThrd->msgMtx, NULL);
|
||||
|
||||
pThrd->loop = (uv_loop_t*)malloc(sizeof(uv_loop_t));
|
||||
uv_loop_init(pThrd->loop);
|
||||
|
||||
pThrd->asyncPool = transCreateAsyncPool(pThrd->loop, 5, pThrd, clientAsyncCb);
|
||||
pThrd->asyncPool = transCreateAsyncPool(pThrd->loop, 5, pThrd, cliAsyncCb);
|
||||
|
||||
pThrd->timer = malloc(sizeof(uv_timer_t));
|
||||
uv_timer_init(pThrd->loop, pThrd->timer);
|
||||
pThrd->timer->data = pThrd;
|
||||
uv_timer_init(pThrd->loop, &pThrd->timer);
|
||||
pThrd->timer.data = pThrd;
|
||||
|
||||
pThrd->pool = creatConnPool(4);
|
||||
pThrd->pool = createConnPool(4);
|
||||
|
||||
pThrd->quit = false;
|
||||
return pThrd;
|
||||
|
@ -627,8 +616,8 @@ static void destroyThrdObj(SCliThrdObj* pThrd) {
|
|||
pthread_join(pThrd->thread, NULL);
|
||||
pthread_mutex_destroy(&pThrd->msgMtx);
|
||||
transDestroyAsyncPool(pThrd->asyncPool);
|
||||
// free(pThrd->cliAsync);
|
||||
free(pThrd->timer);
|
||||
|
||||
uv_timer_stop(&pThrd->timer);
|
||||
free(pThrd->loop);
|
||||
free(pThrd);
|
||||
}
|
||||
|
@ -640,53 +629,68 @@ static void transDestroyConnCtx(STransConnCtx* ctx) {
|
|||
free(ctx);
|
||||
}
|
||||
//
|
||||
static void clientSendQuit(SCliThrdObj* thrd) {
|
||||
static void cliSendQuit(SCliThrdObj* thrd) {
|
||||
// cli can stop gracefully
|
||||
SCliMsg* msg = calloc(1, sizeof(SCliMsg));
|
||||
msg->ctx = NULL; //
|
||||
|
||||
transSendAsync(thrd->asyncPool, &msg->q);
|
||||
}
|
||||
void taosCloseClient(void* arg) {
|
||||
SClientObj* cli = arg;
|
||||
SCliObj* cli = arg;
|
||||
for (int i = 0; i < cli->numOfThreads; i++) {
|
||||
clientSendQuit(cli->pThreadObj[i]);
|
||||
cliSendQuit(cli->pThreadObj[i]);
|
||||
destroyThrdObj(cli->pThreadObj[i]);
|
||||
}
|
||||
free(cli->pThreadObj);
|
||||
free(cli);
|
||||
}
|
||||
static int clientRBChoseIdx(SRpcInfo* pRpc) {
|
||||
int64_t index = pRpc->index;
|
||||
if (pRpc->index++ >= pRpc->numOfThreads) {
|
||||
pRpc->index = 0;
|
||||
static int cliRBChoseIdx(SRpcInfo* pTransInst) {
|
||||
int64_t index = pTransInst->index;
|
||||
if (pTransInst->index++ >= pTransInst->numOfThreads) {
|
||||
pTransInst->index = 0;
|
||||
}
|
||||
return index % pRpc->numOfThreads;
|
||||
return index % pTransInst->numOfThreads;
|
||||
}
|
||||
void transRefCliHandle(void* handle) {
|
||||
if (handle == NULL) {
|
||||
return;
|
||||
}
|
||||
int ref = T_REF_INC((SCliConn*)handle);
|
||||
UNUSED(ref);
|
||||
}
|
||||
void transUnrefCliHandle(void* handle) {
|
||||
if (handle == NULL) {
|
||||
return;
|
||||
}
|
||||
int ref = T_REF_DEC((SCliConn*)handle);
|
||||
if (ref == 0) {
|
||||
cliDestroyConn((SCliConn*)handle, true);
|
||||
}
|
||||
|
||||
// unref cli handle
|
||||
}
|
||||
void rpcSendRequest(void* shandle, const SEpSet* pEpSet, SRpcMsg* pMsg, int64_t* pRid) {
|
||||
// impl later
|
||||
char* ip = (char*)(pEpSet->eps[pEpSet->inUse].fqdn);
|
||||
uint32_t port = pEpSet->eps[pEpSet->inUse].port;
|
||||
|
||||
SRpcInfo* pRpc = (SRpcInfo*)shandle;
|
||||
SRpcInfo* pTransInst = (SRpcInfo*)shandle;
|
||||
|
||||
int index = CONN_HOST_THREAD_INDEX(pMsg->handle);
|
||||
if (index == -1) {
|
||||
index = clientRBChoseIdx(pRpc);
|
||||
index = cliRBChoseIdx(pTransInst);
|
||||
}
|
||||
int32_t flen = 0;
|
||||
if (transCompressMsg(pMsg->pCont, pMsg->contLen, &flen)) {
|
||||
// imp later
|
||||
}
|
||||
STransConnCtx* pCtx = calloc(1, sizeof(STransConnCtx));
|
||||
pCtx->pTransInst = (SRpcInfo*)shandle;
|
||||
pCtx->ahandle = pMsg->ahandle;
|
||||
pCtx->msgType = pMsg->msgType;
|
||||
pCtx->ip = strdup(ip);
|
||||
pCtx->port = port;
|
||||
pCtx->hThrdIdx = index;
|
||||
|
||||
assert(pRpc->connType == TAOS_CONN_CLIENT);
|
||||
assert(pTransInst->connType == TAOS_CONN_CLIENT);
|
||||
// atomic or not
|
||||
|
||||
SCliMsg* cliMsg = malloc(sizeof(SCliMsg));
|
||||
|
@ -694,7 +698,7 @@ void rpcSendRequest(void* shandle, const SEpSet* pEpSet, SRpcMsg* pMsg, int64_t*
|
|||
cliMsg->msg = *pMsg;
|
||||
cliMsg->st = taosGetTimestampUs();
|
||||
|
||||
SCliThrdObj* thrd = ((SClientObj*)pRpc->tcphandle)->pThreadObj[index];
|
||||
SCliThrdObj* thrd = ((SCliObj*)pTransInst->tcphandle)->pThreadObj[index];
|
||||
transSendAsync(thrd->asyncPool, &(cliMsg->q));
|
||||
}
|
||||
|
||||
|
@ -702,15 +706,14 @@ void rpcSendRecv(void* shandle, SEpSet* pEpSet, SRpcMsg* pReq, SRpcMsg* pRsp) {
|
|||
char* ip = (char*)(pEpSet->eps[pEpSet->inUse].fqdn);
|
||||
uint32_t port = pEpSet->eps[pEpSet->inUse].port;
|
||||
|
||||
SRpcInfo* pRpc = (SRpcInfo*)shandle;
|
||||
SRpcInfo* pTransInst = (SRpcInfo*)shandle;
|
||||
|
||||
int index = CONN_HOST_THREAD_INDEX(pReq->handle);
|
||||
if (index == -1) {
|
||||
index = clientRBChoseIdx(pRpc);
|
||||
index = cliRBChoseIdx(pTransInst);
|
||||
}
|
||||
|
||||
STransConnCtx* pCtx = calloc(1, sizeof(STransConnCtx));
|
||||
pCtx->pTransInst = (SRpcInfo*)shandle;
|
||||
pCtx->ahandle = pReq->ahandle;
|
||||
pCtx->msgType = pReq->msgType;
|
||||
pCtx->ip = strdup(ip);
|
||||
|
@ -725,7 +728,7 @@ void rpcSendRecv(void* shandle, SEpSet* pEpSet, SRpcMsg* pReq, SRpcMsg* pRsp) {
|
|||
cliMsg->msg = *pReq;
|
||||
cliMsg->st = taosGetTimestampUs();
|
||||
|
||||
SCliThrdObj* thrd = ((SClientObj*)pRpc->tcphandle)->pThreadObj[index];
|
||||
SCliThrdObj* thrd = ((SCliObj*)pTransInst->tcphandle)->pThreadObj[index];
|
||||
transSendAsync(thrd->asyncPool, &(cliMsg->q));
|
||||
tsem_t* pSem = pCtx->pSem;
|
||||
tsem_wait(pSem);
|
||||
|
|
|
@ -226,9 +226,13 @@ int transAllocBuffer(SConnBuffer* connBuf, uv_buf_t* uvBuf) {
|
|||
|
||||
uvBuf->base = p->buf;
|
||||
uvBuf->len = CAPACITY;
|
||||
} else if (p->total == -1 && p->len < CAPACITY) {
|
||||
uvBuf->base = p->buf + p->len;
|
||||
uvBuf->len = CAPACITY - p->len;
|
||||
} else {
|
||||
p->cap = p->total;
|
||||
p->buf = realloc(p->buf, p->cap);
|
||||
|
||||
uvBuf->base = p->buf + p->len;
|
||||
uvBuf->len = p->cap - p->len;
|
||||
}
|
||||
|
@ -257,6 +261,12 @@ int transDestroyBuffer(SConnBuffer* buf) {
|
|||
transClearBuffer(buf);
|
||||
}
|
||||
|
||||
int transSetConnOption(uv_tcp_t* stream) {
|
||||
uv_tcp_nodelay(stream, 1);
|
||||
int ret = uv_tcp_keepalive(stream, 5, 5);
|
||||
return ret;
|
||||
}
|
||||
|
||||
SAsyncPool* transCreateAsyncPool(uv_loop_t* loop, int sz, void* arg, AsyncCB cb) {
|
||||
SAsyncPool* pool = calloc(1, sizeof(SAsyncPool));
|
||||
pool->index = 0;
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
#include "transComm.h"
|
||||
|
||||
typedef struct SSrvConn {
|
||||
uv_tcp_t* pTcp;
|
||||
uv_write_t* pWriter;
|
||||
uv_timer_t* pTimer;
|
||||
T_REF_DECLARE()
|
||||
uv_tcp_t* pTcp;
|
||||
uv_write_t pWriter;
|
||||
uv_timer_t pTimer;
|
||||
|
||||
// uv_async_t* pWorkerAsync;
|
||||
queue queue;
|
||||
int ref;
|
||||
int persist; // persist connection or not
|
||||
|
@ -32,11 +32,11 @@ typedef struct SSrvConn {
|
|||
void* ahandle; //
|
||||
void* hostThrd;
|
||||
SArray* srvMsgs;
|
||||
// void* pSrvMsg;
|
||||
|
||||
bool broken; // conn broken;
|
||||
|
||||
struct sockaddr_in addr;
|
||||
struct sockaddr_in locaddr;
|
||||
|
||||
// SRpcMsg sendMsg;
|
||||
// del later
|
||||
char secured;
|
||||
|
@ -64,19 +64,23 @@ typedef struct SWorkThrdObj {
|
|||
queue conn;
|
||||
pthread_mutex_t msgMtx;
|
||||
void* pTransInst;
|
||||
bool quit;
|
||||
} SWorkThrdObj;
|
||||
|
||||
typedef struct SServerObj {
|
||||
pthread_t thread;
|
||||
uv_tcp_t server;
|
||||
uv_loop_t* loop;
|
||||
pthread_t thread;
|
||||
uv_tcp_t server;
|
||||
uv_loop_t* loop;
|
||||
|
||||
// work thread info
|
||||
int workerIdx;
|
||||
int numOfThreads;
|
||||
SWorkThrdObj** pThreadObj;
|
||||
uv_pipe_t** pipe;
|
||||
uint32_t ip;
|
||||
uint32_t port;
|
||||
uv_async_t* pAcceptAsync; // just to quit from from accept thread
|
||||
|
||||
uv_pipe_t** pipe;
|
||||
uint32_t ip;
|
||||
uint32_t port;
|
||||
uv_async_t* pAcceptAsync; // just to quit from from accept thread
|
||||
} SServerObj;
|
||||
|
||||
static const char* notify = "a";
|
||||
|
@ -88,9 +92,9 @@ static int uvAuthMsg(SSrvConn* pConn, char* msg, int msgLen);
|
|||
|
||||
static void uvAllocConnBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf);
|
||||
static void uvAllocReadBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf);
|
||||
static void uvOnReadCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf);
|
||||
static void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf);
|
||||
static void uvOnTimeoutCb(uv_timer_t* handle);
|
||||
static void uvOnWriteCb(uv_write_t* req, int status);
|
||||
static void uvOnSendCb(uv_write_t* req, int status);
|
||||
static void uvOnPipeWriteCb(uv_write_t* req, int status);
|
||||
static void uvOnAcceptCb(uv_stream_t* stream, int status);
|
||||
static void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf);
|
||||
|
@ -202,7 +206,6 @@ static void uvHandleReq(SSrvConn* pConn) {
|
|||
}
|
||||
|
||||
pConn->inType = pHead->msgType;
|
||||
// assert(transIsReq(pHead->msgType));
|
||||
|
||||
SRpcInfo* pRpc = (SRpcInfo*)p->shandle;
|
||||
pHead->code = htonl(pHead->code);
|
||||
|
@ -226,17 +229,18 @@ static void uvHandleReq(SSrvConn* pConn) {
|
|||
rpcMsg.handle = pConn;
|
||||
|
||||
transClearBuffer(&pConn->readBuf);
|
||||
pConn->ref++;
|
||||
|
||||
transRefSrvHandle(pConn);
|
||||
tDebug("server conn %p %s received from %s:%d, local info: %s:%d, msg size: %d", pConn, TMSG_INFO(rpcMsg.msgType),
|
||||
inet_ntoa(pConn->addr.sin_addr), ntohs(pConn->addr.sin_port), inet_ntoa(pConn->locaddr.sin_addr),
|
||||
ntohs(pConn->locaddr.sin_port), rpcMsg.contLen);
|
||||
(*(pRpc->cfp))(pRpc->parent, &rpcMsg, NULL);
|
||||
// uv_timer_start(pConn->pTimer, uvHandleActivityTimeout, pRpc->idleTime * 10000, 0);
|
||||
// uv_timer_start(&pConn->pTimer, uvHandleActivityTimeout, pRpc->idleTime * 10000, 0);
|
||||
// auth
|
||||
// validate msg type
|
||||
}
|
||||
|
||||
void uvOnReadCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) {
|
||||
void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) {
|
||||
// opt
|
||||
SSrvConn* conn = cli->data;
|
||||
SConnBuffer* pBuf = &conn->readBuf;
|
||||
|
@ -251,23 +255,20 @@ void uvOnReadCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) {
|
|||
}
|
||||
return;
|
||||
}
|
||||
if (nread == UV_EOF) {
|
||||
tError("server conn %p read error: %s", conn, uv_err_name(nread));
|
||||
if (conn->ref > 1) {
|
||||
conn->ref++; // ref > 1 signed that write is in progress
|
||||
}
|
||||
destroyConn(conn, true);
|
||||
return;
|
||||
}
|
||||
if (nread == 0) {
|
||||
return;
|
||||
}
|
||||
if (nread < 0 || nread != UV_EOF) {
|
||||
if (conn->ref > 1) {
|
||||
conn->ref++; // ref > 1 signed that write is in progress
|
||||
}
|
||||
tError("server conn %p read error: %s", conn, uv_err_name(nread));
|
||||
destroyConn(conn, true);
|
||||
|
||||
tError("server conn %p read error: %s", conn, uv_err_name(nread));
|
||||
if (nread < 0 || nread == UV_EOF) {
|
||||
conn->broken = true;
|
||||
transUnrefSrvHandle(conn);
|
||||
|
||||
// if (conn->ref > 1) {
|
||||
// conn->ref++; // ref > 1 signed that write is in progress
|
||||
//}
|
||||
// tError("server conn %p read error: %s", conn, uv_err_name(nread));
|
||||
// destroyConn(conn, true);
|
||||
}
|
||||
}
|
||||
void uvAllocConnBufferCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) {
|
||||
|
@ -281,7 +282,7 @@ void uvOnTimeoutCb(uv_timer_t* handle) {
|
|||
tError("server conn %p time out", pConn);
|
||||
}
|
||||
|
||||
void uvOnWriteCb(uv_write_t* req, int status) {
|
||||
void uvOnSendCb(uv_write_t* req, int status) {
|
||||
SSrvConn* conn = req->data;
|
||||
transClearBuffer(&conn->readBuf);
|
||||
if (status == 0) {
|
||||
|
@ -300,10 +301,9 @@ void uvOnWriteCb(uv_write_t* req, int status) {
|
|||
}
|
||||
} else {
|
||||
tError("server conn %p failed to write data, %s", conn, uv_err_name(status));
|
||||
//
|
||||
destroyConn(conn, true);
|
||||
conn->broken = false;
|
||||
transUnrefSrvHandle(conn);
|
||||
}
|
||||
// opt
|
||||
}
|
||||
static void uvOnPipeWriteCb(uv_write_t* req, int status) {
|
||||
if (status == 0) {
|
||||
|
@ -311,6 +311,7 @@ static void uvOnPipeWriteCb(uv_write_t* req, int status) {
|
|||
} else {
|
||||
tError("fail to dispatch conn to work thread");
|
||||
}
|
||||
free(req);
|
||||
}
|
||||
|
||||
static void uvPrepareSendData(SSrvMsg* smsg, uv_buf_t* wb) {
|
||||
|
@ -348,16 +349,19 @@ static void uvStartSendRespInternal(SSrvMsg* smsg) {
|
|||
uvPrepareSendData(smsg, &wb);
|
||||
|
||||
SSrvConn* pConn = smsg->pConn;
|
||||
uv_timer_stop(pConn->pTimer);
|
||||
|
||||
// pConn->pSrvMsg = smsg;
|
||||
// conn->pWriter->data = smsg;
|
||||
uv_write(pConn->pWriter, (uv_stream_t*)pConn->pTcp, &wb, 1, uvOnWriteCb);
|
||||
uv_timer_stop(&pConn->pTimer);
|
||||
uv_write(&pConn->pWriter, (uv_stream_t*)pConn->pTcp, &wb, 1, uvOnSendCb);
|
||||
}
|
||||
static void uvStartSendResp(SSrvMsg* smsg) {
|
||||
// impl
|
||||
SSrvConn* pConn = smsg->pConn;
|
||||
pConn->ref--; //
|
||||
|
||||
if (pConn->broken == true) {
|
||||
transUnrefSrvHandle(pConn);
|
||||
return;
|
||||
}
|
||||
transUnrefSrvHandle(pConn);
|
||||
|
||||
if (taosArrayGetSize(pConn->srvMsgs) > 0) {
|
||||
tDebug("server conn %p push data to client %s:%d, local info: %s:%d", pConn, inet_ntoa(pConn->addr.sin_addr),
|
||||
ntohs(pConn->addr.sin_port), inet_ntoa(pConn->locaddr.sin_addr), ntohs(pConn->locaddr.sin_port));
|
||||
|
@ -382,7 +386,7 @@ static void destroyAllConn(SWorkThrdObj* pThrd) {
|
|||
QUEUE_INIT(h);
|
||||
|
||||
SSrvConn* c = QUEUE_DATA(h, SSrvConn, queue);
|
||||
destroyConn(c, true);
|
||||
transUnrefSrvHandle(c);
|
||||
}
|
||||
}
|
||||
void uvWorkerAsyncCb(uv_async_t* handle) {
|
||||
|
@ -390,11 +394,11 @@ void uvWorkerAsyncCb(uv_async_t* handle) {
|
|||
SWorkThrdObj* pThrd = item->pThrd;
|
||||
SSrvConn* conn = NULL;
|
||||
queue wq;
|
||||
|
||||
// batch process to avoid to lock/unlock frequently
|
||||
pthread_mutex_lock(&item->mtx);
|
||||
QUEUE_MOVE(&item->qmsg, &wq);
|
||||
pthread_mutex_unlock(&item->mtx);
|
||||
// pthread_mutex_unlock(&mtx);
|
||||
|
||||
while (!QUEUE_IS_EMPTY(&wq)) {
|
||||
queue* head = QUEUE_HEAD(&wq);
|
||||
|
@ -407,11 +411,15 @@ void uvWorkerAsyncCb(uv_async_t* handle) {
|
|||
}
|
||||
if (msg->pConn == NULL) {
|
||||
free(msg);
|
||||
|
||||
destroyAllConn(pThrd);
|
||||
|
||||
uv_loop_close(pThrd->loop);
|
||||
uv_stop(pThrd->loop);
|
||||
bool noConn = QUEUE_IS_EMPTY(&pThrd->conn);
|
||||
if (noConn == true) {
|
||||
uv_loop_close(pThrd->loop);
|
||||
uv_stop(pThrd->loop);
|
||||
} else {
|
||||
destroyAllConn(pThrd);
|
||||
// uv_loop_close(pThrd->loop);
|
||||
pThrd->quit = true;
|
||||
}
|
||||
} else {
|
||||
uvStartSendResp(msg);
|
||||
}
|
||||
|
@ -419,12 +427,15 @@ void uvWorkerAsyncCb(uv_async_t* handle) {
|
|||
}
|
||||
static void uvAcceptAsyncCb(uv_async_t* async) {
|
||||
SServerObj* srv = async->data;
|
||||
tDebug("close server port %d", srv->port);
|
||||
uv_close((uv_handle_t*)&srv->server, NULL);
|
||||
uv_stop(srv->loop);
|
||||
}
|
||||
|
||||
static void uvShutDownCb(uv_shutdown_t* req, int status) {
|
||||
tDebug("conn failed to shut down: %s", uv_err_name(status));
|
||||
if (status != 0) {
|
||||
tDebug("conn failed to shut down: %s", uv_err_name(status));
|
||||
}
|
||||
uv_close((uv_handle_t*)req->handle, uvDestroyConn);
|
||||
free(req);
|
||||
}
|
||||
|
@ -482,9 +493,8 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) {
|
|||
|
||||
pConn->pTransInst = pThrd->pTransInst;
|
||||
/* init conn timer*/
|
||||
pConn->pTimer = malloc(sizeof(uv_timer_t));
|
||||
uv_timer_init(pThrd->loop, pConn->pTimer);
|
||||
pConn->pTimer->data = pConn;
|
||||
uv_timer_init(pThrd->loop, &pConn->pTimer);
|
||||
pConn->pTimer.data = pConn;
|
||||
|
||||
pConn->hostThrd = pThrd;
|
||||
|
||||
|
@ -493,12 +503,9 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) {
|
|||
uv_tcp_init(pThrd->loop, pConn->pTcp);
|
||||
pConn->pTcp->data = pConn;
|
||||
|
||||
// uv_tcp_nodelay(pConn->pTcp, 1);
|
||||
// uv_tcp_keepalive(pConn->pTcp, 1, 1);
|
||||
pConn->pWriter.data = pConn;
|
||||
|
||||
// init write request, just
|
||||
pConn->pWriter = calloc(1, sizeof(uv_write_t));
|
||||
pConn->pWriter->data = pConn;
|
||||
transSetConnOption((uv_tcp_t*)pConn->pTcp);
|
||||
|
||||
if (uv_accept(q, (uv_stream_t*)(pConn->pTcp)) == 0) {
|
||||
uv_os_fd_t fd;
|
||||
|
@ -508,22 +515,22 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) {
|
|||
int addrlen = sizeof(pConn->addr);
|
||||
if (0 != uv_tcp_getpeername(pConn->pTcp, (struct sockaddr*)&pConn->addr, &addrlen)) {
|
||||
tError("server conn %p failed to get peer info", pConn);
|
||||
destroyConn(pConn, true);
|
||||
transUnrefSrvHandle(pConn);
|
||||
return;
|
||||
}
|
||||
|
||||
addrlen = sizeof(pConn->locaddr);
|
||||
if (0 != uv_tcp_getsockname(pConn->pTcp, (struct sockaddr*)&pConn->locaddr, &addrlen)) {
|
||||
tError("server conn %p failed to get local info", pConn);
|
||||
destroyConn(pConn, true);
|
||||
transUnrefSrvHandle(pConn);
|
||||
return;
|
||||
}
|
||||
|
||||
uv_read_start((uv_stream_t*)(pConn->pTcp), uvAllocReadBufferCb, uvOnReadCb);
|
||||
uv_read_start((uv_stream_t*)(pConn->pTcp), uvAllocReadBufferCb, uvOnRecvCb);
|
||||
|
||||
} else {
|
||||
tDebug("failed to create new connection");
|
||||
destroyConn(pConn, true);
|
||||
transUnrefSrvHandle(pConn);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -599,7 +606,10 @@ static SSrvConn* createConn(void* hThrd) {
|
|||
QUEUE_PUSH(&pThrd->conn, &pConn->queue);
|
||||
pConn->srvMsgs = taosArrayInit(2, sizeof(void*)); //
|
||||
tTrace("conn %p created", pConn);
|
||||
++pConn->ref;
|
||||
|
||||
pConn->broken = false;
|
||||
|
||||
transRefSrvHandle(pConn);
|
||||
return pConn;
|
||||
}
|
||||
|
||||
|
@ -607,10 +617,6 @@ static void destroyConn(SSrvConn* conn, bool clear) {
|
|||
if (conn == NULL) {
|
||||
return;
|
||||
}
|
||||
tTrace("server conn %p try to destroy, ref: %d", conn, conn->ref);
|
||||
if (--conn->ref > 0) {
|
||||
return;
|
||||
}
|
||||
transDestroyBuffer(&conn->readBuf);
|
||||
|
||||
for (int i = 0; i < taosArrayGetSize(conn->srvMsgs); i++) {
|
||||
|
@ -618,25 +624,29 @@ static void destroyConn(SSrvConn* conn, bool clear) {
|
|||
destroySmsg(msg);
|
||||
}
|
||||
conn->srvMsgs = taosArrayDestroy(conn->srvMsgs);
|
||||
QUEUE_REMOVE(&conn->queue);
|
||||
|
||||
if (clear) {
|
||||
tTrace("try to destroy conn %p", conn);
|
||||
uv_tcp_close_reset(conn->pTcp, uvDestroyConn);
|
||||
// uv_shutdown_t* req = malloc(sizeof(uv_shutdown_t));
|
||||
// uv_shutdown(req, (uv_stream_t*)conn->pTcp, uvShutDownCb);
|
||||
// uv_unref((uv_handle_t*)conn->pTcp);
|
||||
// uv_close((uv_handle_t*)conn->pTcp, uvDestroyConn);
|
||||
uv_shutdown_t* req = malloc(sizeof(uv_shutdown_t));
|
||||
uv_shutdown(req, (uv_stream_t*)conn->pTcp, uvShutDownCb);
|
||||
}
|
||||
}
|
||||
static void uvDestroyConn(uv_handle_t* handle) {
|
||||
SSrvConn* conn = handle->data;
|
||||
if (conn == NULL) {
|
||||
return;
|
||||
}
|
||||
SWorkThrdObj* thrd = conn->hostThrd;
|
||||
|
||||
tDebug("server conn %p destroy", conn);
|
||||
uv_timer_stop(conn->pTimer);
|
||||
// free(conn->pTimer);
|
||||
uv_timer_stop(&conn->pTimer);
|
||||
QUEUE_REMOVE(&conn->queue);
|
||||
free(conn->pTcp);
|
||||
free(conn->pWriter);
|
||||
free(conn);
|
||||
|
||||
if (thrd->quit && QUEUE_IS_EMPTY(&thrd->conn)) {
|
||||
uv_loop_close(thrd->loop);
|
||||
uv_stop(thrd->loop);
|
||||
}
|
||||
}
|
||||
static int transAddAuthPart(SSrvConn* pConn, char* msg, int msgLen) {
|
||||
STransMsgHead* pHead = (STransMsgHead*)msg;
|
||||
|
@ -671,6 +681,7 @@ void* taosInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
|||
|
||||
for (int i = 0; i < srv->numOfThreads; i++) {
|
||||
SWorkThrdObj* thrd = (SWorkThrdObj*)calloc(1, sizeof(SWorkThrdObj));
|
||||
thrd->quit = false;
|
||||
srv->pThreadObj[i] = thrd;
|
||||
|
||||
srv->pipe[i] = (uv_pipe_t*)calloc(2, sizeof(uv_pipe_t));
|
||||
|
@ -720,8 +731,6 @@ void destroyWorkThrd(SWorkThrdObj* pThrd) {
|
|||
pthread_join(pThrd->thread, NULL);
|
||||
free(pThrd->loop);
|
||||
transDestroyAsyncPool(pThrd->asyncPool);
|
||||
|
||||
// free(pThrd->workerAsync);
|
||||
free(pThrd);
|
||||
}
|
||||
void sendQuitToWorkThrd(SWorkThrdObj* pThrd) {
|
||||
|
@ -755,6 +764,28 @@ void taosCloseServer(void* arg) {
|
|||
free(srv);
|
||||
}
|
||||
|
||||
void transRefSrvHandle(void* handle) {
|
||||
if (handle == NULL) {
|
||||
return;
|
||||
}
|
||||
SSrvConn* conn = handle;
|
||||
|
||||
int ref = T_REF_INC((SSrvConn*)handle);
|
||||
UNUSED(ref);
|
||||
}
|
||||
|
||||
void transUnrefSrvHandle(void* handle) {
|
||||
if (handle == NULL) {
|
||||
return;
|
||||
}
|
||||
int ref = T_REF_DEC((SSrvConn*)handle);
|
||||
tDebug("handle %p ref count: %d", handle, ref);
|
||||
|
||||
if (ref == 0) {
|
||||
destroyConn((SSrvConn*)handle, true);
|
||||
}
|
||||
// unref srv handle
|
||||
}
|
||||
void rpcSendResponse(const SRpcMsg* pMsg) {
|
||||
if (pMsg->handle == NULL) {
|
||||
return;
|
||||
|
|
|
@ -3,7 +3,6 @@ add_executable(client "")
|
|||
add_executable(server "")
|
||||
add_executable(transUT "")
|
||||
add_executable(syncClient "")
|
||||
add_executable(pushClient "")
|
||||
add_executable(pushServer "")
|
||||
|
||||
target_sources(transUT
|
||||
|
@ -27,10 +26,6 @@ target_sources (syncClient
|
|||
"syncClient.c"
|
||||
)
|
||||
|
||||
target_sources(pushClient
|
||||
PRIVATE
|
||||
"pushClient.c"
|
||||
)
|
||||
target_sources(pushServer
|
||||
PRIVATE
|
||||
"pushServer.c"
|
||||
|
@ -102,19 +97,6 @@ target_link_libraries (syncClient
|
|||
transport
|
||||
)
|
||||
|
||||
target_include_directories(pushClient
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/transport"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_link_libraries (pushClient
|
||||
os
|
||||
util
|
||||
common
|
||||
gtest_main
|
||||
transport
|
||||
)
|
||||
|
||||
target_include_directories(pushServer
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/transport"
|
||||
|
|
|
@ -1,242 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <tdatablock.h>
|
||||
#include "os.h"
|
||||
#include "rpcLog.h"
|
||||
#include "taoserror.h"
|
||||
#include "tglobal.h"
|
||||
#include "trpc.h"
|
||||
#include "tutil.h"
|
||||
|
||||
typedef struct {
|
||||
int index;
|
||||
SEpSet epSet;
|
||||
int num;
|
||||
int numOfReqs;
|
||||
int msgSize;
|
||||
tsem_t rspSem;
|
||||
tsem_t * pOverSem;
|
||||
pthread_t thread;
|
||||
void * pRpc;
|
||||
} SInfo;
|
||||
static void processResponse(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
SInfo *pInfo = (SInfo *)pMsg->ahandle;
|
||||
tDebug("thread:%d, response is received, type:%d contLen:%d code:0x%x", pInfo->index, pMsg->msgType, pMsg->contLen,
|
||||
pMsg->code);
|
||||
|
||||
if (pEpSet) pInfo->epSet = *pEpSet;
|
||||
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
// tsem_post(&pInfo->rspSem);
|
||||
tsem_post(&pInfo->rspSem);
|
||||
}
|
||||
|
||||
static int tcount = 0;
|
||||
|
||||
typedef struct SPushArg {
|
||||
tsem_t sem;
|
||||
} SPushArg;
|
||||
// ping
|
||||
int pushCallback(void *arg, SRpcMsg *msg) {
|
||||
SPushArg *push = arg;
|
||||
tsem_post(&push->sem);
|
||||
}
|
||||
SRpcPush *createPushArg() {
|
||||
SRpcPush *push = calloc(1, sizeof(SRpcPush));
|
||||
push->arg = calloc(1, sizeof(SPushArg));
|
||||
|
||||
tsem_init(&(((SPushArg *)push->arg)->sem), 0, 0);
|
||||
push->callback = pushCallback;
|
||||
return push;
|
||||
}
|
||||
static void *sendRequest(void *param) {
|
||||
SInfo * pInfo = (SInfo *)param;
|
||||
SRpcMsg rpcMsg = {0};
|
||||
|
||||
tDebug("thread:%d, start to send request", pInfo->index);
|
||||
|
||||
tDebug("thread:%d, reqs: %d", pInfo->index, pInfo->numOfReqs);
|
||||
int u100 = 0;
|
||||
int u500 = 0;
|
||||
int u1000 = 0;
|
||||
int u10000 = 0;
|
||||
|
||||
while (pInfo->numOfReqs == 0 || pInfo->num < pInfo->numOfReqs) {
|
||||
SRpcPush *push = createPushArg();
|
||||
pInfo->num++;
|
||||
rpcMsg.pCont = rpcMallocCont(pInfo->msgSize);
|
||||
rpcMsg.contLen = pInfo->msgSize;
|
||||
rpcMsg.ahandle = pInfo;
|
||||
rpcMsg.msgType = 1;
|
||||
rpcMsg.push = push;
|
||||
// tDebug("thread:%d, send request, contLen:%d num:%d", pInfo->index, pInfo->msgSize, pInfo->num);
|
||||
int64_t start = taosGetTimestampUs();
|
||||
rpcSendRequest(pInfo->pRpc, &pInfo->epSet, &rpcMsg, NULL);
|
||||
if (pInfo->num % 20000 == 0) tInfo("thread:%d, %d requests have been sent", pInfo->index, pInfo->num);
|
||||
tsem_wait(&pInfo->rspSem); // ping->pong
|
||||
// tsem_wait(&pInfo->rspSem);
|
||||
SPushArg *arg = push->arg;
|
||||
/// e
|
||||
tsem_wait(&arg->sem); // push callback
|
||||
|
||||
// query_fetch(client->h)
|
||||
int64_t end = taosGetTimestampUs() - start;
|
||||
if (end <= 100) {
|
||||
u100++;
|
||||
} else if (end > 100 && end <= 500) {
|
||||
u500++;
|
||||
} else if (end > 500 && end < 1000) {
|
||||
u1000++;
|
||||
} else {
|
||||
u10000++;
|
||||
}
|
||||
|
||||
tDebug("recv response succefully");
|
||||
|
||||
// taosSsleep(100);
|
||||
}
|
||||
|
||||
tError("send and recv sum: %d, %d, %d, %d", u100, u500, u1000, u10000);
|
||||
tDebug("thread:%d, it is over", pInfo->index);
|
||||
tcount++;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
SRpcInit rpcInit;
|
||||
SEpSet epSet;
|
||||
int msgSize = 128;
|
||||
int numOfReqs = 0;
|
||||
int appThreads = 1;
|
||||
char serverIp[40] = "127.0.0.1";
|
||||
char secret[20] = "mypassword";
|
||||
struct timeval systemTime;
|
||||
int64_t startTime, endTime;
|
||||
pthread_attr_t thattr;
|
||||
|
||||
// server info
|
||||
epSet.inUse = 0;
|
||||
addEpIntoEpSet(&epSet, serverIp, 7000);
|
||||
addEpIntoEpSet(&epSet, "192.168.0.1", 7000);
|
||||
|
||||
// client info
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
rpcInit.localPort = 0;
|
||||
rpcInit.label = "APP";
|
||||
rpcInit.numOfThreads = 1;
|
||||
rpcInit.cfp = processResponse;
|
||||
rpcInit.sessions = 100;
|
||||
rpcInit.idleTime = 100;
|
||||
rpcInit.user = "michael";
|
||||
rpcInit.secret = secret;
|
||||
rpcInit.ckey = "key";
|
||||
rpcInit.spi = 1;
|
||||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (strcmp(argv[i], "-p") == 0 && i < argc - 1) {
|
||||
epSet.eps[0].port = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-i") == 0 && i < argc - 1) {
|
||||
tstrncpy(epSet.eps[0].fqdn, argv[++i], sizeof(epSet.eps[0].fqdn));
|
||||
} else if (strcmp(argv[i], "-t") == 0 && i < argc - 1) {
|
||||
rpcInit.numOfThreads = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-m") == 0 && i < argc - 1) {
|
||||
msgSize = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-s") == 0 && i < argc - 1) {
|
||||
rpcInit.sessions = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-n") == 0 && i < argc - 1) {
|
||||
numOfReqs = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-a") == 0 && i < argc - 1) {
|
||||
appThreads = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-o") == 0 && i < argc - 1) {
|
||||
tsCompressMsgSize = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-u") == 0 && i < argc - 1) {
|
||||
rpcInit.user = argv[++i];
|
||||
} else if (strcmp(argv[i], "-k") == 0 && i < argc - 1) {
|
||||
rpcInit.secret = argv[++i];
|
||||
} else if (strcmp(argv[i], "-spi") == 0 && i < argc - 1) {
|
||||
rpcInit.spi = atoi(argv[++i]);
|
||||
} else if (strcmp(argv[i], "-d") == 0 && i < argc - 1) {
|
||||
rpcDebugFlag = atoi(argv[++i]);
|
||||
} else {
|
||||
printf("\nusage: %s [options] \n", argv[0]);
|
||||
printf(" [-i ip]: first server IP address, default is:%s\n", serverIp);
|
||||
printf(" [-p port]: server port number, default is:%d\n", epSet.eps[0].port);
|
||||
printf(" [-t threads]: number of rpc threads, default is:%d\n", rpcInit.numOfThreads);
|
||||
printf(" [-s sessions]: number of rpc sessions, default is:%d\n", rpcInit.sessions);
|
||||
printf(" [-m msgSize]: message body size, default is:%d\n", msgSize);
|
||||
printf(" [-a threads]: number of app threads, default is:%d\n", appThreads);
|
||||
printf(" [-n requests]: number of requests per thread, default is:%d\n", numOfReqs);
|
||||
printf(" [-o compSize]: compression message size, default is:%d\n", tsCompressMsgSize);
|
||||
printf(" [-u user]: user name for the connection, default is:%s\n", rpcInit.user);
|
||||
printf(" [-k secret]: password for the connection, default is:%s\n", rpcInit.secret);
|
||||
printf(" [-spi SPI]: security parameter index, default is:%d\n", rpcInit.spi);
|
||||
printf(" [-d debugFlag]: debug flag, default:%d\n", rpcDebugFlag);
|
||||
printf(" [-h help]: print out this help\n\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
taosInitLog("client.log", 10);
|
||||
|
||||
void *pRpc = rpcOpen(&rpcInit);
|
||||
if (pRpc == NULL) {
|
||||
tError("failed to initialize RPC");
|
||||
return -1;
|
||||
}
|
||||
|
||||
tInfo("client is initialized");
|
||||
tInfo("threads:%d msgSize:%d requests:%d", appThreads, msgSize, numOfReqs);
|
||||
|
||||
gettimeofday(&systemTime, NULL);
|
||||
startTime = systemTime.tv_sec * 1000000 + systemTime.tv_usec;
|
||||
|
||||
SInfo *pInfo = (SInfo *)calloc(1, sizeof(SInfo) * appThreads);
|
||||
|
||||
pthread_attr_init(&thattr);
|
||||
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
for (int i = 0; i < appThreads; ++i) {
|
||||
pInfo->index = i;
|
||||
pInfo->epSet = epSet;
|
||||
pInfo->numOfReqs = numOfReqs;
|
||||
pInfo->msgSize = msgSize;
|
||||
tsem_init(&pInfo->rspSem, 0, 0);
|
||||
pInfo->pRpc = pRpc;
|
||||
pthread_create(&pInfo->thread, &thattr, sendRequest, pInfo);
|
||||
pInfo++;
|
||||
}
|
||||
|
||||
do {
|
||||
taosUsleep(1);
|
||||
} while (tcount < appThreads);
|
||||
|
||||
gettimeofday(&systemTime, NULL);
|
||||
endTime = systemTime.tv_sec * 1000000 + systemTime.tv_usec;
|
||||
float usedTime = (endTime - startTime) / 1000.0f; // mseconds
|
||||
|
||||
tInfo("it takes %.3f mseconds to send %d requests to server", usedTime, numOfReqs * appThreads);
|
||||
tInfo("Performance: %.3f requests per second, msgSize:%d bytes", 1000.0 * numOfReqs * appThreads / usedTime, msgSize);
|
||||
|
||||
int ch = getchar();
|
||||
UNUSED(ch);
|
||||
|
||||
taosCloseLog();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -124,6 +124,7 @@ int main(int argc, char *argv[]) {
|
|||
rpcInit.ckey = "key";
|
||||
rpcInit.spi = 1;
|
||||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
rpcDebugFlag = 143;
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (strcmp(argv[i], "-p") == 0 && i < argc - 1) {
|
||||
|
@ -180,7 +181,7 @@ int main(int argc, char *argv[]) {
|
|||
tInfo("client is initialized");
|
||||
tInfo("threads:%d msgSize:%d requests:%d", appThreads, msgSize, numOfReqs);
|
||||
|
||||
gettimeofday(&systemTime, NULL);
|
||||
taosGetTimeOfDay(&systemTime);
|
||||
startTime = systemTime.tv_sec * 1000000 + systemTime.tv_usec;
|
||||
|
||||
SInfo *pInfo = (SInfo *)calloc(1, sizeof(SInfo) * appThreads);
|
||||
|
@ -203,7 +204,7 @@ int main(int argc, char *argv[]) {
|
|||
taosUsleep(1);
|
||||
} while (tcount < appThreads);
|
||||
|
||||
gettimeofday(&systemTime, NULL);
|
||||
taosGetTimeOfDay(&systemTime);
|
||||
endTime = systemTime.tv_sec * 1000000 + systemTime.tv_usec;
|
||||
float usedTime = (endTime - startTime) / 1000.0f; // mseconds
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue