Merge branch '3.0' of https://github.com/taosdata/TDengine into feature/3.0_mhli
This commit is contained in:
commit
23c69aff61
|
@ -7,4 +7,4 @@ FROM mcr.microsoft.com/vscode/devcontainers/cpp:0-${VARIANT}
|
|||
# [Optional] Uncomment this section to install additional packages.
|
||||
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
||||
# && apt-get -y install --no-install-recommends <your-package-list-here>
|
||||
RUN apt-get update && apt-get -y install tree vim tmux
|
||||
RUN apt-get update && apt-get -y install tree vim tmux python3-pip
|
||||
|
|
|
@ -40,6 +40,7 @@ taosdalipu/
|
|||
Target/
|
||||
*.failed
|
||||
*.sql
|
||||
sim
|
||||
sim/
|
||||
psim/
|
||||
pysim/
|
||||
|
@ -107,3 +108,4 @@ TAGS
|
|||
contrib/*
|
||||
!contrib/CMakeLists.txt
|
||||
!contrib/test
|
||||
sql
|
|
@ -14,9 +14,24 @@ if(${BUILD_PTHREAD})
|
|||
cat("${TD_SUPPORT_DIR}/pthread_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
endif()
|
||||
|
||||
# gnu regex
|
||||
if(${BUILD_GNUREGEX})
|
||||
cat("${TD_SUPPORT_DIR}/gnuregex_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
# iconv
|
||||
if(${BUILD_WITH_ICONV})
|
||||
cat("${TD_SUPPORT_DIR}/iconv_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
endif()
|
||||
|
||||
# msvc regex
|
||||
if(${BUILD_MSVCREGEX})
|
||||
cat("${TD_SUPPORT_DIR}/msvcregex_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
endif()
|
||||
|
||||
# wcwidth
|
||||
if(${BUILD_WCWIDTH})
|
||||
cat("${TD_SUPPORT_DIR}/wcwidth_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
endif()
|
||||
|
||||
# wingetopt
|
||||
if(${BUILD_WINGETOPT})
|
||||
cat("${TD_SUPPORT_DIR}/wingetopt_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
endif()
|
||||
|
||||
# googletest
|
||||
|
@ -95,12 +110,31 @@ execute_process(COMMAND "${CMAKE_COMMAND}" --build .
|
|||
# ================================================================================================
|
||||
# googletest
|
||||
if(${BUILD_TEST})
|
||||
add_subdirectory(googletest)
|
||||
add_subdirectory(googletest EXCLUDE_FROM_ALL)
|
||||
target_include_directories(
|
||||
gtest
|
||||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp-stub/src>
|
||||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp-stub/src_linux>
|
||||
)
|
||||
if(${TD_WINDOWS})
|
||||
target_include_directories(
|
||||
gtest
|
||||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp-stub/src_win>
|
||||
)
|
||||
endif(${TD_WINDOWS})
|
||||
if(${TD_LINUX})
|
||||
target_include_directories(
|
||||
gtest
|
||||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp-stub/src_linux>
|
||||
)
|
||||
endif(${TD_LINUX})
|
||||
if(${TD_DARWIN})
|
||||
target_include_directories(
|
||||
gtest
|
||||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp-stub/src_darwin>
|
||||
)
|
||||
endif(${TD_DARWIN})
|
||||
|
||||
|
||||
endif(${BUILD_TEST})
|
||||
|
||||
# cJson
|
||||
|
@ -109,7 +143,7 @@ set(CMAKE_PROJECT_INCLUDE_BEFORE "${TD_SUPPORT_DIR}/EnableCMP0048.txt.in")
|
|||
option(ENABLE_CJSON_TEST "Enable building cJSON test" OFF)
|
||||
option(CJSON_OVERRIDE_BUILD_SHARED_LIBS "Override BUILD_SHARED_LIBS with CJSON_BUILD_SHARED_LIBS" ON)
|
||||
option(CJSON_BUILD_SHARED_LIBS "Overrides BUILD_SHARED_LIBS if CJSON_OVERRIDE_BUILD_SHARED_LIBS is enabled" OFF)
|
||||
add_subdirectory(cJson)
|
||||
add_subdirectory(cJson EXCLUDE_FROM_ALL)
|
||||
target_include_directories(
|
||||
cjson
|
||||
# see https://stackoverflow.com/questions/25676277/cmake-target-include-directories-prints-an-error-when-i-try-to-add-the-source
|
||||
|
@ -118,7 +152,7 @@ target_include_directories(
|
|||
unset(CMAKE_PROJECT_INCLUDE_BEFORE)
|
||||
|
||||
# lz4
|
||||
add_subdirectory(lz4/build/cmake)
|
||||
add_subdirectory(lz4/build/cmake EXCLUDE_FROM_ALL)
|
||||
target_include_directories(
|
||||
lz4_static
|
||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/lz4/lib
|
||||
|
@ -126,7 +160,7 @@ target_include_directories(
|
|||
|
||||
# zlib
|
||||
set(CMAKE_PROJECT_INCLUDE_BEFORE "${TD_SUPPORT_DIR}/EnableCMP0048.txt.in")
|
||||
add_subdirectory(zlib)
|
||||
add_subdirectory(zlib EXCLUDE_FROM_ALL)
|
||||
target_include_directories(
|
||||
zlibstatic
|
||||
PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/zlib
|
||||
|
@ -142,7 +176,7 @@ unset(CMAKE_PROJECT_INCLUDE_BEFORE)
|
|||
# leveldb
|
||||
if(${BUILD_WITH_LEVELDB})
|
||||
option(LEVELDB_BUILD_TESTS "" OFF)
|
||||
add_subdirectory(leveldb)
|
||||
add_subdirectory(leveldb EXCLUDE_FROM_ALL)
|
||||
target_include_directories(
|
||||
leveldb
|
||||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/leveldb/include>
|
||||
|
@ -158,7 +192,7 @@ if(${BUILD_WITH_ROCKSDB})
|
|||
option(WITH_TOOLS "" OFF)
|
||||
option(WITH_LIBURING "" OFF)
|
||||
option(ROCKSDB_BUILD_SHARED "Build shared versions of the RocksDB libraries" OFF)
|
||||
add_subdirectory(rocksdb)
|
||||
add_subdirectory(rocksdb EXCLUDE_FROM_ALL)
|
||||
target_include_directories(
|
||||
rocksdb
|
||||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/rocksdb/include>
|
||||
|
@ -169,7 +203,7 @@ endif(${BUILD_WITH_ROCKSDB})
|
|||
# To support build on ubuntu: sudo apt-get install libboost-all-dev
|
||||
if(${BUILD_WITH_LUCENE})
|
||||
option(ENABLE_TEST "Enable the tests" OFF)
|
||||
add_subdirectory(lucene)
|
||||
add_subdirectory(lucene EXCLUDE_FROM_ALL)
|
||||
target_include_directories(
|
||||
lucene++
|
||||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lucene/include>
|
||||
|
@ -179,9 +213,56 @@ endif(${BUILD_WITH_LUCENE})
|
|||
|
||||
# NuRaft
|
||||
if(${BUILD_WITH_NURAFT})
|
||||
add_subdirectory(nuraft)
|
||||
add_subdirectory(nuraft EXCLUDE_FROM_ALL)
|
||||
endif(${BUILD_WITH_NURAFT})
|
||||
|
||||
# pthread
|
||||
if(${BUILD_PTHREAD})
|
||||
set(CMAKE_BUILD_TYPE release)
|
||||
add_definitions(-DPTW32_STATIC_LIB)
|
||||
add_subdirectory(pthread)
|
||||
set_target_properties(libpthreadVC3 PROPERTIES OUTPUT_NAME pthread)
|
||||
add_library(pthread STATIC IMPORTED GLOBAL)
|
||||
SET_PROPERTY(TARGET pthread PROPERTY IMPORTED_LOCATION ${LIBRARY_OUTPUT_PATH}/pthread.lib)
|
||||
endif()
|
||||
|
||||
# iconv
|
||||
if(${BUILD_WITH_ICONV})
|
||||
add_subdirectory(iconv EXCLUDE_FROM_ALL)
|
||||
endif(${BUILD_WITH_ICONV})
|
||||
|
||||
# wingetopt
|
||||
if(${BUILD_WINGETOPT})
|
||||
add_subdirectory(wingetopt EXCLUDE_FROM_ALL)
|
||||
endif(${BUILD_WINGETOPT})
|
||||
|
||||
# msvcregex
|
||||
if(${BUILD_MSVCREGEX})
|
||||
add_library(msvcregex STATIC "")
|
||||
target_sources(msvcregex
|
||||
PRIVATE "msvcregex/regex.c"
|
||||
)
|
||||
target_include_directories(msvcregex
|
||||
PRIVATE "msvcregex"
|
||||
)
|
||||
target_link_libraries(msvcregex
|
||||
INTERFACE Shell32
|
||||
)
|
||||
SET_TARGET_PROPERTIES(msvcregex PROPERTIES OUTPUT_NAME msvcregex)
|
||||
endif(${BUILD_MSVCREGEX})
|
||||
|
||||
# msvcregex
|
||||
if(${BUILD_WCWIDTH})
|
||||
add_library(wcwidth STATIC "")
|
||||
target_sources(wcwidth
|
||||
PRIVATE "wcwidth/wcwidth.c"
|
||||
)
|
||||
target_include_directories(wcwidth
|
||||
PRIVATE "wcwidth"
|
||||
)
|
||||
SET_TARGET_PROPERTIES(wcwidth PROPERTIES OUTPUT_NAME wcwidth)
|
||||
endif(${BUILD_WCWIDTH})
|
||||
|
||||
# CRAFT
|
||||
if(${BUILD_WITH_CRAFT})
|
||||
add_library(craft STATIC IMPORTED GLOBAL)
|
||||
|
@ -212,7 +293,7 @@ if(${BUILD_WITH_UV})
|
|||
MESSAGE("Windows need set no-sign-compare")
|
||||
add_compile_options(-Wno-sign-compare)
|
||||
endif ()
|
||||
add_subdirectory(libuv)
|
||||
add_subdirectory(libuv EXCLUDE_FROM_ALL)
|
||||
endif(${BUILD_WITH_UV})
|
||||
|
||||
# BDB
|
||||
|
@ -238,8 +319,12 @@ if(${BUILD_WITH_SQLITE})
|
|||
target_link_libraries(sqlite
|
||||
INTERFACE m
|
||||
INTERFACE pthread
|
||||
INTERFACE dl
|
||||
)
|
||||
if(NOT TD_WINDOWS)
|
||||
target_link_libraries(sqlite
|
||||
INTERFACE dl
|
||||
)
|
||||
endif(NOT TD_WINDOWS)
|
||||
endif(${BUILD_WITH_SQLITE})
|
||||
|
||||
# pthread
|
||||
|
@ -249,5 +334,5 @@ endif(${BUILD_WITH_SQLITE})
|
|||
# Build test
|
||||
# ================================================================================================
|
||||
if(${BUILD_DEPENDENCY_TESTS})
|
||||
add_subdirectory(test)
|
||||
add_subdirectory(test EXCLUDE_FROM_ALL)
|
||||
endif(${BUILD_DEPENDENCY_TESTS})
|
||||
|
|
|
@ -1,2 +1,9 @@
|
|||
add_executable(simulate_vnode "simulate_vnode.c")
|
||||
target_link_libraries(simulate_vnode PUBLIC craft lz4 uv_a)
|
||||
target_link_libraries(simulate_vnode PUBLIC craft lz4 uv_a)
|
||||
if(${BUILD_WINGETOPT})
|
||||
target_link_libraries(simulate_vnode PUBLIC wingetopt)
|
||||
target_include_directories(
|
||||
simulate_vnode
|
||||
PUBLIC "${TD_SOURCE_DIR}/contrib/wingetopt/src"
|
||||
)
|
||||
endif()
|
|
@ -6,43 +6,39 @@
|
|||
#define POINTER_SHIFT(ptr, s) ((void *)(((char *)ptr) + (s)))
|
||||
#define POINTER_DISTANCE(pa, pb) ((char *)(pb) - (char *)(pa))
|
||||
|
||||
#define tPutA(buf, val) \
|
||||
({ \
|
||||
memcpy(buf, &val, sizeof(val)); \
|
||||
POINTER_SHIFT(buf, sizeof(val)); \
|
||||
})
|
||||
static inline void tPutA(void **buf, uint64_t val) {
|
||||
memcpy(buf, &val, sizeof(val));
|
||||
*buf = POINTER_SHIFT(buf, sizeof(val));
|
||||
}
|
||||
|
||||
#define tPutB(buf, val) \
|
||||
({ \
|
||||
((uint8_t *)buf)[7] = ((val) >> 56) & 0xff; \
|
||||
((uint8_t *)buf)[6] = ((val) >> 48) & 0xff; \
|
||||
((uint8_t *)buf)[5] = ((val) >> 40) & 0xff; \
|
||||
((uint8_t *)buf)[4] = ((val) >> 32) & 0xff; \
|
||||
((uint8_t *)buf)[3] = ((val) >> 24) & 0xff; \
|
||||
((uint8_t *)buf)[2] = ((val) >> 16) & 0xff; \
|
||||
((uint8_t *)buf)[1] = ((val) >> 8) & 0xff; \
|
||||
((uint8_t *)buf)[0] = (val)&0xff; \
|
||||
POINTER_SHIFT(buf, sizeof(val)); \
|
||||
})
|
||||
static inline void tPutB(void **buf, uint64_t val) {
|
||||
((uint8_t *)buf)[7] = ((val) >> 56) & 0xff;
|
||||
((uint8_t *)buf)[6] = ((val) >> 48) & 0xff;
|
||||
((uint8_t *)buf)[5] = ((val) >> 40) & 0xff;
|
||||
((uint8_t *)buf)[4] = ((val) >> 32) & 0xff;
|
||||
((uint8_t *)buf)[3] = ((val) >> 24) & 0xff;
|
||||
((uint8_t *)buf)[2] = ((val) >> 16) & 0xff;
|
||||
((uint8_t *)buf)[1] = ((val) >> 8) & 0xff;
|
||||
((uint8_t *)buf)[0] = (val)&0xff;
|
||||
*buf = POINTER_SHIFT(buf, sizeof(val));
|
||||
}
|
||||
|
||||
#define tPutC(buf, val) \
|
||||
({ \
|
||||
if (buf) { \
|
||||
((uint64_t *)buf)[0] = (val); \
|
||||
POINTER_SHIFT(buf, sizeof(val)); \
|
||||
} \
|
||||
NULL; \
|
||||
})
|
||||
static inline void tPutC(void **buf, uint64_t val) {
|
||||
if (buf) {
|
||||
((uint64_t *)buf)[0] = (val);
|
||||
POINTER_SHIFT(buf, sizeof(val));
|
||||
}
|
||||
*buf = NULL;
|
||||
}
|
||||
|
||||
#define tPutD(buf, val) \
|
||||
({ \
|
||||
uint64_t tmp = val; \
|
||||
for (size_t i = 0; i < sizeof(val); i++) { \
|
||||
((uint8_t *)buf)[i] = tmp & 0xff; \
|
||||
tmp >>= 8; \
|
||||
} \
|
||||
POINTER_SHIFT(buf, sizeof(val)); \
|
||||
})
|
||||
static inline void tPutD(void **buf, uint64_t val) {
|
||||
uint64_t tmp = val;
|
||||
for (size_t i = 0; i < sizeof(val); i++) {
|
||||
((uint8_t *)buf)[i] = tmp & 0xff;
|
||||
tmp >>= 8;
|
||||
}
|
||||
*buf = POINTER_SHIFT(buf, sizeof(val));
|
||||
}
|
||||
|
||||
static inline void tPutE(void **buf, uint64_t val) {
|
||||
if (buf) {
|
||||
|
@ -61,7 +57,7 @@ static void func(T t) {
|
|||
switch (t) {
|
||||
case A:
|
||||
for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) {
|
||||
pBuf = tPutA(pBuf, val);
|
||||
tPutA(pBuf, val);
|
||||
if (POINTER_DISTANCE(buf, pBuf) == 1024) {
|
||||
pBuf = buf;
|
||||
}
|
||||
|
@ -69,7 +65,7 @@ static void func(T t) {
|
|||
break;
|
||||
case B:
|
||||
for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) {
|
||||
pBuf = tPutB(pBuf, val);
|
||||
tPutB(pBuf, val);
|
||||
if (POINTER_DISTANCE(buf, pBuf) == 1024) {
|
||||
pBuf = buf;
|
||||
}
|
||||
|
@ -77,7 +73,7 @@ static void func(T t) {
|
|||
break;
|
||||
case C:
|
||||
for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) {
|
||||
pBuf = tPutC(pBuf, val);
|
||||
tPutC(pBuf, val);
|
||||
if (POINTER_DISTANCE(buf, pBuf) == 1024) {
|
||||
pBuf = buf;
|
||||
}
|
||||
|
@ -85,7 +81,7 @@ static void func(T t) {
|
|||
break;
|
||||
case D:
|
||||
for (size_t i = 0; i < 10 * 1024l * 1024l * 1024l; i++) {
|
||||
pBuf = tPutD(pBuf, val);
|
||||
tPutD(pBuf, val);
|
||||
if (POINTER_DISTANCE(buf, pBuf) == 1024) {
|
||||
pBuf = buf;
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ target_link_libraries(demoapi
|
|||
)
|
||||
|
||||
target_include_directories(tmq
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/os"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include "taos.h"
|
||||
|
||||
static int running = 1;
|
||||
|
@ -48,7 +47,6 @@ int32_t init_env() {
|
|||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
sleep(1);
|
||||
|
||||
pRes = taos_query(pConn, "use abc1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
|
|
|
@ -27,10 +27,7 @@ typedef void TAOS;
|
|||
typedef void TAOS_STMT;
|
||||
typedef void TAOS_RES;
|
||||
typedef void **TAOS_ROW;
|
||||
#if 0
|
||||
typedef void TAOS_STREAM;
|
||||
#endif
|
||||
typedef void TAOS_SUB;
|
||||
typedef void TAOS_SUB;
|
||||
|
||||
// Data type definition
|
||||
#define TSDB_DATA_TYPE_NULL 0 // 1 bytes
|
||||
|
@ -88,18 +85,22 @@ typedef struct taosField {
|
|||
int32_t bytes;
|
||||
} TAOS_FIELD;
|
||||
|
||||
#define DLL_EXPORT
|
||||
#ifdef WINDOWS
|
||||
#define DLL_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define DLL_EXPORT
|
||||
#endif
|
||||
|
||||
typedef void (*__taos_async_fn_t)(void *param, TAOS_RES *, int code);
|
||||
|
||||
typedef struct TAOS_BIND_v2 {
|
||||
int buffer_type;
|
||||
void *buffer;
|
||||
int32_t buffer_length;
|
||||
int32_t *length;
|
||||
char *is_null;
|
||||
int num;
|
||||
} TAOS_BIND_v2;
|
||||
typedef struct TAOS_MULTI_BIND {
|
||||
int buffer_type;
|
||||
void *buffer;
|
||||
uintptr_t buffer_length;
|
||||
int32_t *length;
|
||||
char *is_null;
|
||||
int num;
|
||||
} TAOS_MULTI_BIND;
|
||||
|
||||
typedef enum {
|
||||
SET_CONF_RET_SUCC = 0,
|
||||
|
@ -120,43 +121,44 @@ typedef struct setConfRet {
|
|||
DLL_EXPORT void taos_cleanup(void);
|
||||
DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...);
|
||||
DLL_EXPORT setConfRet taos_set_config(const char *config);
|
||||
DLL_EXPORT int taos_init(void);
|
||||
DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port);
|
||||
DLL_EXPORT TAOS *taos_connect_l(const char *ip, int ipLen, const char *user, int userLen, const char *pass, int passLen,
|
||||
DLL_EXPORT TAOS *taos_connect_l(const char *ip, int ipLen, const char *user, int userLen, const char *pass, int passLen,
|
||||
const char *db, int dbLen, uint16_t port);
|
||||
DLL_EXPORT TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port);
|
||||
DLL_EXPORT void taos_close(TAOS *taos);
|
||||
DLL_EXPORT TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port);
|
||||
DLL_EXPORT void taos_close(TAOS *taos);
|
||||
|
||||
const char *taos_data_type(int type);
|
||||
const char *taos_data_type(int type);
|
||||
|
||||
DLL_EXPORT TAOS_STMT *taos_stmt_init(TAOS *taos);
|
||||
DLL_EXPORT int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length);
|
||||
DLL_EXPORT int taos_stmt_set_tbname_tags(TAOS_STMT *stmt, const char *name, TAOS_BIND_v2 *tags);
|
||||
DLL_EXPORT int taos_stmt_set_tbname(TAOS_STMT *stmt, const char *name);
|
||||
DLL_EXPORT int taos_stmt_set_sub_tbname(TAOS_STMT *stmt, const char *name);
|
||||
DLL_EXPORT TAOS_STMT *taos_stmt_init(TAOS *taos);
|
||||
DLL_EXPORT int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length);
|
||||
DLL_EXPORT int taos_stmt_set_tbname_tags(TAOS_STMT *stmt, const char *name, TAOS_MULTI_BIND *tags);
|
||||
DLL_EXPORT int taos_stmt_set_tbname(TAOS_STMT *stmt, const char *name);
|
||||
DLL_EXPORT int taos_stmt_set_sub_tbname(TAOS_STMT *stmt, const char *name);
|
||||
|
||||
DLL_EXPORT int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert);
|
||||
DLL_EXPORT int taos_stmt_num_params(TAOS_STMT *stmt, int *nums);
|
||||
DLL_EXPORT int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes);
|
||||
DLL_EXPORT int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_BIND_v2 *bind);
|
||||
DLL_EXPORT int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_BIND_v2 *bind);
|
||||
DLL_EXPORT int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_BIND_v2 *bind, int colIdx);
|
||||
DLL_EXPORT int taos_stmt_add_batch(TAOS_STMT *stmt);
|
||||
DLL_EXPORT int taos_stmt_execute(TAOS_STMT *stmt);
|
||||
DLL_EXPORT TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt);
|
||||
DLL_EXPORT int taos_stmt_close(TAOS_STMT *stmt);
|
||||
DLL_EXPORT char *taos_stmt_errstr(TAOS_STMT *stmt);
|
||||
DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT *stmt);
|
||||
DLL_EXPORT int taos_stmt_affected_rows_once(TAOS_STMT *stmt);
|
||||
DLL_EXPORT int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert);
|
||||
DLL_EXPORT int taos_stmt_num_params(TAOS_STMT *stmt, int *nums);
|
||||
DLL_EXPORT int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes);
|
||||
DLL_EXPORT int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind);
|
||||
DLL_EXPORT int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind);
|
||||
DLL_EXPORT int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int colIdx);
|
||||
DLL_EXPORT int taos_stmt_add_batch(TAOS_STMT *stmt);
|
||||
DLL_EXPORT int taos_stmt_execute(TAOS_STMT *stmt);
|
||||
DLL_EXPORT TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt);
|
||||
DLL_EXPORT int taos_stmt_close(TAOS_STMT *stmt);
|
||||
DLL_EXPORT char *taos_stmt_errstr(TAOS_STMT *stmt);
|
||||
DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT *stmt);
|
||||
DLL_EXPORT int taos_stmt_affected_rows_once(TAOS_STMT *stmt);
|
||||
|
||||
DLL_EXPORT TAOS_RES *taos_query(TAOS *taos, const char *sql);
|
||||
DLL_EXPORT TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen);
|
||||
DLL_EXPORT TAOS_RES *taos_query(TAOS *taos, const char *sql);
|
||||
DLL_EXPORT TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen);
|
||||
|
||||
DLL_EXPORT TAOS_ROW taos_fetch_row(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_result_precision(TAOS_RES *res); // get the time precision of result
|
||||
DLL_EXPORT void taos_free_result(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_field_count(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_num_fields(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_affected_rows(TAOS_RES *res);
|
||||
DLL_EXPORT TAOS_ROW taos_fetch_row(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_result_precision(TAOS_RES *res); // get the time precision of result
|
||||
DLL_EXPORT void taos_free_result(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_field_count(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_num_fields(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_affected_rows(TAOS_RES *res);
|
||||
|
||||
DLL_EXPORT TAOS_FIELD *taos_fetch_fields(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_select_db(TAOS *taos, const char *db);
|
||||
|
@ -192,12 +194,6 @@ DLL_EXPORT TAOS_RES *taos_consume(TAOS_SUB *tsub);
|
|||
DLL_EXPORT void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
DLL_EXPORT TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sql, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row),
|
||||
int64_t stime, void *param, void (*callback)(void *));
|
||||
DLL_EXPORT void taos_close_stream(TAOS_STREAM *tstr);
|
||||
#endif
|
||||
|
||||
DLL_EXPORT int taos_load_table_info(TAOS *taos, const char *tableNameList);
|
||||
DLL_EXPORT TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int protocol, int precision);
|
||||
|
||||
|
@ -237,12 +233,8 @@ DLL_EXPORT const char *tmq_err2str(tmq_resp_err_t);
|
|||
DLL_EXPORT tmq_resp_err_t tmq_subscribe(tmq_t *tmq, const tmq_list_t *topic_list);
|
||||
DLL_EXPORT tmq_resp_err_t tmq_unsubscribe(tmq_t *tmq);
|
||||
DLL_EXPORT tmq_resp_err_t tmq_subscription(tmq_t *tmq, tmq_list_t **topics);
|
||||
DLL_EXPORT TAOS_RES *tmq_consumer_poll(tmq_t *tmq, int64_t blocking_time);
|
||||
DLL_EXPORT TAOS_RES *tmq_consumer_poll(tmq_t *tmq, int64_t wait_time);
|
||||
DLL_EXPORT tmq_resp_err_t tmq_consumer_close(tmq_t *tmq);
|
||||
#if 0
|
||||
DLL_EXPORT tmq_resp_err_t tmq_assign(tmq_t* tmq, const tmq_topic_vgroup_list_t* vgroups);
|
||||
DLL_EXPORT tmq_resp_err_t tmq_assignment(tmq_t* tmq, tmq_topic_vgroup_list_t** vgroups);
|
||||
#endif
|
||||
DLL_EXPORT tmq_resp_err_t tmq_commit(tmq_t *tmq, const tmq_topic_vgroup_list_t *offsets, int32_t async);
|
||||
#if 0
|
||||
DLL_EXPORT tmq_resp_err_t tmq_commit_message(tmq_t* tmq, const tmq_message_t* tmqmessage, int32_t async);
|
||||
|
@ -269,7 +261,7 @@ DLL_EXPORT char *tmq_get_topic_name(TAOS_RES *res);
|
|||
DLL_EXPORT int32_t tmq_get_vgroup_id(TAOS_RES *res);
|
||||
// TODO
|
||||
#if 0
|
||||
DLL_EXPORT char *tmq_get_block_table_name(TAOS_RES *res);
|
||||
DLL_EXPORT char *tmq_get_table_name(TAOS_RES *res);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
|
|
|
@ -66,13 +66,13 @@ typedef struct SDataBlockInfo {
|
|||
int32_t rows;
|
||||
int32_t rowSize;
|
||||
union {
|
||||
int64_t uid; // from which table of uid, comes from this data block
|
||||
int64_t uid; // from which table of uid, comes from this data block
|
||||
int64_t blockId;
|
||||
};
|
||||
uint64_t groupId; // no need to serialize
|
||||
int16_t numOfCols;
|
||||
int16_t hasVarCol;
|
||||
int16_t capacity;
|
||||
uint64_t groupId; // no need to serialize
|
||||
int16_t numOfCols;
|
||||
int16_t hasVarCol;
|
||||
int16_t capacity;
|
||||
} SDataBlockInfo;
|
||||
|
||||
typedef struct SSDataBlock {
|
||||
|
@ -99,6 +99,15 @@ typedef struct SColumnInfoData {
|
|||
};
|
||||
} SColumnInfoData;
|
||||
|
||||
typedef struct SQueryTableDataCond {
|
||||
STimeWindow twindow;
|
||||
int32_t order; // desc|asc order to iterate the data block
|
||||
int32_t numOfCols;
|
||||
SColumnInfo *colList;
|
||||
bool loadExternalRows; // load external rows or not
|
||||
int32_t type; // data block load type:
|
||||
} SQueryTableDataCond;
|
||||
|
||||
void* blockDataDestroy(SSDataBlock* pBlock);
|
||||
int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock);
|
||||
void* tDecodeDataBlock(const void* buf, SSDataBlock* pBlock);
|
||||
|
@ -122,59 +131,6 @@ static FORCE_INLINE void blockDestroyInner(SSDataBlock* pBlock) {
|
|||
|
||||
static FORCE_INLINE void tDeleteSSDataBlock(SSDataBlock* pBlock) { blockDestroyInner(pBlock); }
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSMqPollRsp(void** buf, const SMqPollRsp* pRsp) {
|
||||
int32_t tlen = 0;
|
||||
int32_t sz = 0;
|
||||
// tlen += taosEncodeFixedI64(buf, pRsp->consumerId);
|
||||
tlen += taosEncodeFixedI64(buf, pRsp->reqOffset);
|
||||
tlen += taosEncodeFixedI64(buf, pRsp->rspOffset);
|
||||
tlen += taosEncodeFixedI32(buf, pRsp->skipLogNum);
|
||||
tlen += taosEncodeFixedI32(buf, pRsp->numOfTopics);
|
||||
if (pRsp->numOfTopics == 0) return tlen;
|
||||
tlen += taosEncodeSSchemaWrapper(buf, pRsp->schema);
|
||||
if (pRsp->pBlockData) {
|
||||
sz = taosArrayGetSize(pRsp->pBlockData);
|
||||
}
|
||||
tlen += taosEncodeFixedI32(buf, sz);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SSDataBlock* pBlock = (SSDataBlock*)taosArrayGet(pRsp->pBlockData, i);
|
||||
tlen += tEncodeDataBlock(buf, pBlock);
|
||||
}
|
||||
return tlen;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void* tDecodeSMqPollRsp(void* buf, SMqPollRsp* pRsp) {
|
||||
int32_t sz;
|
||||
// buf = taosDecodeFixedI64(buf, &pRsp->consumerId);
|
||||
buf = taosDecodeFixedI64(buf, &pRsp->reqOffset);
|
||||
buf = taosDecodeFixedI64(buf, &pRsp->rspOffset);
|
||||
buf = taosDecodeFixedI32(buf, &pRsp->skipLogNum);
|
||||
buf = taosDecodeFixedI32(buf, &pRsp->numOfTopics);
|
||||
if (pRsp->numOfTopics == 0) return buf;
|
||||
pRsp->schema = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
|
||||
if (pRsp->schema == NULL) return NULL;
|
||||
buf = taosDecodeSSchemaWrapper(buf, pRsp->schema);
|
||||
buf = taosDecodeFixedI32(buf, &sz);
|
||||
pRsp->pBlockData = taosArrayInit(sz, sizeof(SSDataBlock));
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SSDataBlock block = {0};
|
||||
tDecodeDataBlock(buf, &block);
|
||||
taosArrayPush(pRsp->pBlockData, &block);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void tDeleteSMqConsumeRsp(SMqPollRsp* pRsp) {
|
||||
if (pRsp->schema) {
|
||||
if (pRsp->schema->nCols) {
|
||||
taosMemoryFreeClear(pRsp->schema->pSchema);
|
||||
}
|
||||
taosMemoryFree(pRsp->schema);
|
||||
}
|
||||
taosArrayDestroyEx(pRsp->pBlockData, (void (*)(void*))blockDestroyInner);
|
||||
pRsp->pBlockData = NULL;
|
||||
}
|
||||
|
||||
//======================================================================================================================
|
||||
// the following structure shared by parser and executor
|
||||
typedef struct SColumn {
|
||||
|
@ -195,22 +151,22 @@ typedef struct SColumn {
|
|||
} SColumn;
|
||||
|
||||
typedef struct STableBlockDistInfo {
|
||||
uint16_t rowSize;
|
||||
uint16_t numOfFiles;
|
||||
uint32_t numOfTables;
|
||||
uint64_t totalSize;
|
||||
uint64_t totalRows;
|
||||
int32_t maxRows;
|
||||
int32_t minRows;
|
||||
int32_t firstSeekTimeUs;
|
||||
uint32_t numOfRowsInMemTable;
|
||||
uint32_t numOfSmallBlocks;
|
||||
SArray *dataBlockInfos;
|
||||
uint16_t rowSize;
|
||||
uint16_t numOfFiles;
|
||||
uint32_t numOfTables;
|
||||
uint64_t totalSize;
|
||||
uint64_t totalRows;
|
||||
int32_t maxRows;
|
||||
int32_t minRows;
|
||||
int32_t firstSeekTimeUs;
|
||||
uint32_t numOfRowsInMemTable;
|
||||
uint32_t numOfSmallBlocks;
|
||||
SArray* dataBlockInfos;
|
||||
} STableBlockDistInfo;
|
||||
|
||||
enum {
|
||||
FUNC_PARAM_TYPE_VALUE = 0x1,
|
||||
FUNC_PARAM_TYPE_COLUMN= 0x2,
|
||||
FUNC_PARAM_TYPE_COLUMN = 0x2,
|
||||
};
|
||||
|
||||
typedef struct SFunctParam {
|
||||
|
@ -229,7 +185,6 @@ typedef struct SResSchame {
|
|||
char name[TSDB_COL_NAME_LEN];
|
||||
} SResSchema;
|
||||
|
||||
// TODO move away to executor.h
|
||||
typedef struct SExprBasicInfo {
|
||||
SResSchema resSchema;
|
||||
int16_t numOfParams; // argument value of each function
|
||||
|
@ -241,7 +196,7 @@ typedef struct SExprInfo {
|
|||
struct tExprNode* pExpr;
|
||||
} SExprInfo;
|
||||
|
||||
#define QUERY_ASC_FORWARD_STEP 1
|
||||
#define QUERY_ASC_FORWARD_STEP 1
|
||||
#define QUERY_DESC_FORWARD_STEP -1
|
||||
|
||||
#define GET_FORWARD_DIRECTION_FACTOR(ord) (((ord) == TSDB_ORDER_ASC) ? QUERY_ASC_FORWARD_STEP : QUERY_DESC_FORWARD_STEP)
|
||||
|
|
|
@ -177,6 +177,7 @@ typedef struct SField {
|
|||
char name[TSDB_COL_NAME_LEN];
|
||||
uint8_t type;
|
||||
int32_t bytes;
|
||||
int8_t flags;
|
||||
} SField;
|
||||
|
||||
typedef struct SRetention {
|
||||
|
@ -230,12 +231,12 @@ typedef struct {
|
|||
int32_t totalLen;
|
||||
int32_t len;
|
||||
// head of SSubmitBlk
|
||||
// int64_t uid; // table unique id
|
||||
// int64_t suid; // stable id
|
||||
// int32_t sversion; // data schema version
|
||||
// int32_t dataLen; // data part length, not including the SSubmitBlk head
|
||||
// int32_t schemaLen; // schema length, if length is 0, no schema exists
|
||||
// int16_t numOfRows; // total number of rows in current submit block
|
||||
int64_t uid; // table unique id
|
||||
int64_t suid; // stable id
|
||||
int32_t sversion; // data schema version
|
||||
int32_t dataLen; // data part length, not including the SSubmitBlk head
|
||||
int32_t schemaLen; // schema length, if length is 0, no schema exists
|
||||
int16_t numOfRows; // total number of rows in current submit block
|
||||
// head of SSubmitBlk
|
||||
const void* pMsg;
|
||||
} SSubmitMsgIter;
|
||||
|
@ -249,10 +250,10 @@ STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
|
|||
// 1) use tInitSubmitMsgIterEx firstly as not decrease the merge conflicts
|
||||
// 2) replace tInitSubmitMsgIterEx with tInitSubmitMsgIter later
|
||||
// 3) finally, rename tInitSubmitMsgIterEx to tInitSubmitMsgIter
|
||||
// int32_t tInitSubmitMsgIterEx(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
|
||||
// int32_t tGetSubmitMsgNextEx(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
|
||||
// int32_t tInitSubmitBlkIterEx(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
|
||||
// STSRow* tGetSubmitBlkNextEx(SSubmitBlkIter* pIter);
|
||||
int32_t tInitSubmitMsgIterEx(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
|
||||
int32_t tGetSubmitMsgNextEx(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
|
||||
int32_t tInitSubmitBlkIterEx(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
|
||||
STSRow* tGetSubmitBlkNextEx(SSubmitBlkIter* pIter);
|
||||
|
||||
typedef struct {
|
||||
int32_t index; // index of failed block in submit blocks
|
||||
|
@ -286,6 +287,12 @@ typedef struct SSchema {
|
|||
#define SSCHMEA_BYTES(s) ((s)->bytes)
|
||||
#define SSCHMEA_NAME(s) ((s)->name)
|
||||
|
||||
typedef struct {
|
||||
int32_t nCols;
|
||||
int32_t sver;
|
||||
SSchema* pSchema;
|
||||
} SSchemaWrapper;
|
||||
|
||||
STSchema* tdGetSTSChemaFromSSChema(SSchema** pSchema, int32_t nCols);
|
||||
|
||||
typedef struct {
|
||||
|
@ -296,13 +303,11 @@ typedef struct {
|
|||
int32_t ttl;
|
||||
int32_t numOfColumns;
|
||||
int32_t numOfTags;
|
||||
int32_t numOfSmas;
|
||||
int32_t commentLen;
|
||||
int32_t ast1Len;
|
||||
int32_t ast2Len;
|
||||
SArray* pColumns; // array of SField
|
||||
SArray* pTags; // array of SField
|
||||
SArray* pSmas; // array of SField
|
||||
char* comment;
|
||||
char* pAst1;
|
||||
char* pAst2;
|
||||
|
@ -433,6 +438,7 @@ typedef struct {
|
|||
|
||||
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
|
||||
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
|
||||
void tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
|
||||
|
||||
typedef struct {
|
||||
int16_t colId; // column id
|
||||
|
@ -1327,7 +1333,7 @@ int32_t tDeserializeSCMCreateTopicRsp(void* buf, int32_t bufLen, SCMCreateTopicR
|
|||
|
||||
typedef struct {
|
||||
int64_t consumerId;
|
||||
} SMqConsumerLostMsg;
|
||||
} SMqConsumerLostMsg, SMqConsumerRecoverMsg;
|
||||
|
||||
typedef struct {
|
||||
int64_t consumerId;
|
||||
|
@ -1507,67 +1513,93 @@ typedef struct {
|
|||
} SDDropTopicReq;
|
||||
|
||||
typedef struct {
|
||||
float xFilesFactor;
|
||||
int32_t delay;
|
||||
int32_t qmsg1Len;
|
||||
int32_t qmsg2Len;
|
||||
char* qmsg1; // pAst1:qmsg1:SRetention1 => trigger aggr task1
|
||||
char* qmsg2; // pAst2:qmsg2:SRetention2 => trigger aggr task2
|
||||
float xFilesFactor;
|
||||
int32_t delay;
|
||||
int32_t qmsg1Len;
|
||||
int32_t qmsg2Len;
|
||||
char* qmsg1; // pAst1:qmsg1:SRetention1 => trigger aggr task1
|
||||
char* qmsg2; // pAst2:qmsg2:SRetention2 => trigger aggr task2
|
||||
} SRSmaParam;
|
||||
|
||||
int tEncodeSRSmaParam(SCoder* pCoder, const SRSmaParam* pRSmaParam);
|
||||
int tDecodeSRSmaParam(SCoder* pCoder, SRSmaParam* pRSmaParam);
|
||||
|
||||
typedef struct SVCreateStbReq {
|
||||
const char* name;
|
||||
tb_uid_t suid;
|
||||
int8_t rollup;
|
||||
SSchemaWrapper schema;
|
||||
SSchemaWrapper schemaTag;
|
||||
SRSmaParam pRSmaParam;
|
||||
} SVCreateStbReq;
|
||||
|
||||
int tEncodeSVCreateStbReq(SCoder* pCoder, const SVCreateStbReq* pReq);
|
||||
int tDecodeSVCreateStbReq(SCoder* pCoder, SVCreateStbReq* pReq);
|
||||
|
||||
typedef struct SVDropStbReq {
|
||||
// data
|
||||
#ifdef WINDOWS
|
||||
size_t avoidCompilationErrors;
|
||||
#endif
|
||||
|
||||
} SVDropStbReq;
|
||||
|
||||
typedef struct SVCreateStbRsp {
|
||||
int code;
|
||||
} SVCreateStbRsp;
|
||||
|
||||
typedef struct SVCreateTbReq {
|
||||
char* name;
|
||||
uint32_t ttl;
|
||||
uint32_t keep;
|
||||
union {
|
||||
uint8_t info;
|
||||
struct {
|
||||
uint8_t rollup : 1; // 1 means rollup sma
|
||||
uint8_t type : 7;
|
||||
};
|
||||
};
|
||||
tb_uid_t uid;
|
||||
int64_t ctime;
|
||||
const char* name;
|
||||
int32_t ttl;
|
||||
int8_t type;
|
||||
union {
|
||||
struct {
|
||||
tb_uid_t suid;
|
||||
col_id_t nCols;
|
||||
col_id_t nBSmaCols;
|
||||
SSchema* pSchema;
|
||||
col_id_t nTagCols;
|
||||
SSchema* pTagSchema;
|
||||
SRSmaParam* pRSmaParam;
|
||||
} stbCfg;
|
||||
const void* pTag;
|
||||
} ctb;
|
||||
struct {
|
||||
tb_uid_t suid;
|
||||
SKVRow pTag;
|
||||
} ctbCfg;
|
||||
struct {
|
||||
col_id_t nCols;
|
||||
col_id_t nBSmaCols;
|
||||
SSchema* pSchema;
|
||||
SRSmaParam* pRSmaParam;
|
||||
} ntbCfg;
|
||||
SSchemaWrapper schema;
|
||||
} ntb;
|
||||
};
|
||||
} SVCreateTbReq, SVUpdateTbReq;
|
||||
} SVCreateTbReq;
|
||||
|
||||
int tEncodeSVCreateTbReq(SCoder* pCoder, const SVCreateTbReq* pReq);
|
||||
int tDecodeSVCreateTbReq(SCoder* pCoder, SVCreateTbReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int32_t nReqs;
|
||||
union {
|
||||
SVCreateTbReq* pReqs;
|
||||
SArray* pArray;
|
||||
};
|
||||
} SVCreateTbBatchReq;
|
||||
|
||||
int tEncodeSVCreateTbBatchReq(SCoder* pCoder, const SVCreateTbBatchReq* pReq);
|
||||
int tDecodeSVCreateTbBatchReq(SCoder* pCoder, SVCreateTbBatchReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int32_t code;
|
||||
} SVCreateTbRsp, SVUpdateTbRsp;
|
||||
|
||||
int tEncodeSVCreateTbRsp(SCoder* pCoder, const SVCreateTbRsp* pRsp);
|
||||
int tDecodeSVCreateTbRsp(SCoder* pCoder, SVCreateTbRsp* pRsp);
|
||||
|
||||
int32_t tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
|
||||
void* tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int64_t ver; // use a general definition
|
||||
SArray* pArray;
|
||||
} SVCreateTbBatchReq;
|
||||
|
||||
int32_t tSerializeSVCreateTbBatchReq(void** buf, SVCreateTbBatchReq* pReq);
|
||||
void* tDeserializeSVCreateTbBatchReq(void* buf, SVCreateTbBatchReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
SArray* rspList; // SArray<SVCreateTbRsp>
|
||||
int32_t nRsps;
|
||||
union {
|
||||
SVCreateTbRsp* pRsps;
|
||||
SArray* pArray;
|
||||
};
|
||||
} SVCreateTbBatchRsp;
|
||||
|
||||
int tEncodeSVCreateTbBatchRsp(SCoder* pCoder, const SVCreateTbBatchRsp* pRsp);
|
||||
int tDecodeSVCreateTbBatchRsp(SCoder* pCoder, SVCreateTbBatchRsp* pRsp);
|
||||
|
||||
int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
|
||||
int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
|
||||
|
||||
|
@ -1622,103 +1654,11 @@ typedef struct {
|
|||
char data[];
|
||||
} SVShowTablesFetchRsp;
|
||||
|
||||
typedef struct SMqCMGetSubEpReq {
|
||||
typedef struct {
|
||||
int64_t consumerId;
|
||||
int32_t epoch;
|
||||
char cgroup[TSDB_CGROUP_LEN];
|
||||
} SMqCMGetSubEpReq;
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSMsgHead(void** buf, const SMsgHead* pMsg) {
|
||||
int32_t tlen = 0;
|
||||
tlen += taosEncodeFixedI32(buf, pMsg->contLen);
|
||||
tlen += taosEncodeFixedI32(buf, pMsg->vgId);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
typedef struct SMqHbRsp {
|
||||
int8_t status; // idle or not
|
||||
int8_t vnodeChanged;
|
||||
int8_t epChanged; // should use new epset
|
||||
int8_t reserved;
|
||||
SEpSet epSet;
|
||||
} SMqHbRsp;
|
||||
|
||||
static FORCE_INLINE int32_t taosEncodeSMqHbRsp(void** buf, const SMqHbRsp* pRsp) {
|
||||
int32_t tlen = 0;
|
||||
tlen += taosEncodeFixedI8(buf, pRsp->status);
|
||||
tlen += taosEncodeFixedI8(buf, pRsp->vnodeChanged);
|
||||
tlen += taosEncodeFixedI8(buf, pRsp->epChanged);
|
||||
tlen += taosEncodeSEpSet(buf, &pRsp->epSet);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void* taosDecodeSMqHbRsp(void* buf, SMqHbRsp* pRsp) {
|
||||
buf = taosDecodeFixedI8(buf, &pRsp->status);
|
||||
buf = taosDecodeFixedI8(buf, &pRsp->vnodeChanged);
|
||||
buf = taosDecodeFixedI8(buf, &pRsp->epChanged);
|
||||
buf = taosDecodeSEpSet(buf, &pRsp->epSet);
|
||||
return buf;
|
||||
}
|
||||
|
||||
typedef struct SMqHbOneTopicBatchRsp {
|
||||
char topicName[TSDB_TOPIC_FNAME_LEN];
|
||||
SArray* rsps; // SArray<SMqHbRsp>
|
||||
} SMqHbOneTopicBatchRsp;
|
||||
|
||||
static FORCE_INLINE int32_t taosEncodeSMqHbOneTopicBatchRsp(void** buf, const SMqHbOneTopicBatchRsp* pBatchRsp) {
|
||||
int32_t tlen = 0;
|
||||
tlen += taosEncodeString(buf, pBatchRsp->topicName);
|
||||
int32_t sz = taosArrayGetSize(pBatchRsp->rsps);
|
||||
tlen += taosEncodeFixedI32(buf, sz);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SMqHbRsp* pRsp = (SMqHbRsp*)taosArrayGet(pBatchRsp->rsps, i);
|
||||
tlen += taosEncodeSMqHbRsp(buf, pRsp);
|
||||
}
|
||||
return tlen;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void* taosDecodeSMqHbOneTopicBatchRsp(void* buf, SMqHbOneTopicBatchRsp* pBatchRsp) {
|
||||
int32_t sz;
|
||||
buf = taosDecodeStringTo(buf, pBatchRsp->topicName);
|
||||
buf = taosDecodeFixedI32(buf, &sz);
|
||||
pBatchRsp->rsps = taosArrayInit(sz, sizeof(SMqHbRsp));
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SMqHbRsp rsp;
|
||||
buf = taosDecodeSMqHbRsp(buf, &rsp);
|
||||
buf = taosArrayPush(pBatchRsp->rsps, &rsp);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
typedef struct SMqHbBatchRsp {
|
||||
int64_t consumerId;
|
||||
SArray* batchRsps; // SArray<SMqHbOneTopicBatchRsp>
|
||||
} SMqHbBatchRsp;
|
||||
|
||||
static FORCE_INLINE int32_t taosEncodeSMqHbBatchRsp(void** buf, const SMqHbBatchRsp* pBatchRsp) {
|
||||
int32_t tlen = 0;
|
||||
tlen += taosEncodeFixedI64(buf, pBatchRsp->consumerId);
|
||||
int32_t sz;
|
||||
tlen += taosEncodeFixedI32(buf, sz);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SMqHbOneTopicBatchRsp* pRsp = (SMqHbOneTopicBatchRsp*)taosArrayGet(pBatchRsp->batchRsps, i);
|
||||
tlen += taosEncodeSMqHbOneTopicBatchRsp(buf, pRsp);
|
||||
}
|
||||
return tlen;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void* taosDecodeSMqHbBatchRsp(void* buf, SMqHbBatchRsp* pBatchRsp) {
|
||||
buf = taosDecodeFixedI64(buf, &pBatchRsp->consumerId);
|
||||
int32_t sz;
|
||||
buf = taosDecodeFixedI32(buf, &sz);
|
||||
pBatchRsp->batchRsps = taosArrayInit(sz, sizeof(SMqHbOneTopicBatchRsp));
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SMqHbOneTopicBatchRsp rsp;
|
||||
buf = taosDecodeSMqHbOneTopicBatchRsp(buf, &rsp);
|
||||
buf = taosArrayPush(pBatchRsp->batchRsps, &rsp);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
} SMqAskEpReq;
|
||||
|
||||
typedef struct {
|
||||
int32_t key;
|
||||
|
@ -2087,15 +2027,11 @@ int32_t tDecodeSMqOffset(SCoder* decoder, SMqOffset* pOffset);
|
|||
int32_t tEncodeSMqCMCommitOffsetReq(SCoder* encoder, const SMqCMCommitOffsetReq* pReq);
|
||||
int32_t tDecodeSMqCMCommitOffsetReq(SCoder* decoder, SMqCMCommitOffsetReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
uint32_t nCols;
|
||||
SSchema* pSchema;
|
||||
} SSchemaWrapper;
|
||||
|
||||
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
|
||||
SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
|
||||
if (pSW == NULL) return pSW;
|
||||
pSW->nCols = pSchemaWrapper->nCols;
|
||||
pSW->sver = pSchemaWrapper->sver;
|
||||
pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
|
||||
if (pSW->pSchema == NULL) {
|
||||
taosMemoryFree(pSW);
|
||||
|
@ -2132,8 +2068,8 @@ static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
|
|||
static FORCE_INLINE int32_t tEncodeSSchema(SCoder* pEncoder, const SSchema* pSchema) {
|
||||
if (tEncodeI8(pEncoder, pSchema->type) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pSchema->flags) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, pSchema->bytes) < 0) return -1;
|
||||
if (tEncodeI16(pEncoder, pSchema->colId) < 0) return -1;
|
||||
if (tEncodeI32v(pEncoder, pSchema->bytes) < 0) return -1;
|
||||
if (tEncodeI16v(pEncoder, pSchema->colId) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, pSchema->name) < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
@ -2141,15 +2077,16 @@ static FORCE_INLINE int32_t tEncodeSSchema(SCoder* pEncoder, const SSchema* pSch
|
|||
static FORCE_INLINE int32_t tDecodeSSchema(SCoder* pDecoder, SSchema* pSchema) {
|
||||
if (tDecodeI8(pDecoder, &pSchema->type) < 0) return -1;
|
||||
if (tDecodeI8(pDecoder, &pSchema->flags) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &pSchema->bytes) < 0) return -1;
|
||||
if (tDecodeI16(pDecoder, &pSchema->colId) < 0) return -1;
|
||||
if (tDecodeI32v(pDecoder, &pSchema->bytes) < 0) return -1;
|
||||
if (tDecodeI16v(pDecoder, &pSchema->colId) < 0) return -1;
|
||||
if (tDecodeCStrTo(pDecoder, pSchema->name) < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
|
||||
int32_t tlen = 0;
|
||||
tlen += taosEncodeFixedU32(buf, pSW->nCols);
|
||||
tlen += taosEncodeVariantI32(buf, pSW->nCols);
|
||||
tlen += taosEncodeVariantI32(buf, pSW->sver);
|
||||
for (int32_t i = 0; i < pSW->nCols; i++) {
|
||||
tlen += taosEncodeSSchema(buf, &pSW->pSchema[i]);
|
||||
}
|
||||
|
@ -2157,7 +2094,8 @@ static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWr
|
|||
}
|
||||
|
||||
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
|
||||
buf = taosDecodeFixedU32(buf, &pSW->nCols);
|
||||
buf = taosDecodeVariantI32(buf, &pSW->nCols);
|
||||
buf = taosDecodeVariantI32(buf, &pSW->sver);
|
||||
pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
|
||||
if (pSW->pSchema == NULL) {
|
||||
return NULL;
|
||||
|
@ -2170,23 +2108,25 @@ static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapp
|
|||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SCoder* pEncoder, const SSchemaWrapper* pSW) {
|
||||
if (tEncodeU32(pEncoder, pSW->nCols) < 0) return -1;
|
||||
if (tEncodeI32v(pEncoder, pSW->nCols) < 0) return -1;
|
||||
if (tEncodeI32v(pEncoder, pSW->sver) < 0) return -1;
|
||||
for (int32_t i = 0; i < pSW->nCols; i++) {
|
||||
if (tEncodeSSchema(pEncoder, &pSW->pSchema[i]) < 0) return -1;
|
||||
}
|
||||
return pEncoder->pos;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SCoder* pDecoder, SSchemaWrapper* pSW) {
|
||||
if (tDecodeU32(pDecoder, &pSW->nCols) < 0) return -1;
|
||||
void* ptr = taosMemoryRealloc(pSW->pSchema, pSW->nCols * sizeof(SSchema));
|
||||
if (ptr == NULL) {
|
||||
return -1;
|
||||
}
|
||||
pSW->pSchema = (SSchema*)ptr;
|
||||
if (tDecodeI32v(pDecoder, &pSW->nCols) < 0) return -1;
|
||||
if (tDecodeI32v(pDecoder, &pSW->sver) < 0) return -1;
|
||||
|
||||
pSW->pSchema = (SSchema*)tCoderMalloc(pDecoder, sizeof(SSchema) * pSW->nCols);
|
||||
if (pSW->pSchema == NULL) return -1;
|
||||
for (int32_t i = 0; i < pSW->nCols; i++) {
|
||||
if (tDecodeSSchema(pDecoder, &pSW->pSchema[i]) < 0) return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -2442,31 +2382,15 @@ typedef struct {
|
|||
int64_t consumerId;
|
||||
} SMqRspHead;
|
||||
|
||||
#if 0
|
||||
typedef struct {
|
||||
SMsgHead head;
|
||||
|
||||
int64_t consumerId;
|
||||
int64_t blockingTime;
|
||||
int32_t epoch;
|
||||
int8_t withSchema;
|
||||
char cgroup[TSDB_CGROUP_LEN];
|
||||
|
||||
int64_t currentOffset;
|
||||
uint64_t reqId;
|
||||
char topic[TSDB_TOPIC_FNAME_LEN];
|
||||
} SMqPollReq;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
SMsgHead head;
|
||||
char subKey[TSDB_SUBSCRIBE_KEY_LEN];
|
||||
int32_t epoch;
|
||||
uint64_t reqId;
|
||||
int64_t consumerId;
|
||||
int64_t blockingTime;
|
||||
int64_t waitTime;
|
||||
int64_t currentOffset;
|
||||
} SMqPollReqV2;
|
||||
} SMqPollReq;
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
|
@ -2481,65 +2405,6 @@ typedef struct {
|
|||
SSchemaWrapper schema;
|
||||
} SMqSubTopicEp;
|
||||
|
||||
typedef struct {
|
||||
SMqRspHead head;
|
||||
int64_t reqOffset;
|
||||
int64_t rspOffset;
|
||||
int32_t skipLogNum;
|
||||
// TODO: replace with topic name
|
||||
int32_t numOfTopics;
|
||||
// TODO: remove from msg
|
||||
SSchemaWrapper* schema;
|
||||
SArray* pBlockData; // SArray<SSDataBlock>
|
||||
} SMqPollRsp;
|
||||
|
||||
typedef struct {
|
||||
SMqRspHead head;
|
||||
int64_t reqOffset;
|
||||
int64_t rspOffset;
|
||||
int32_t skipLogNum;
|
||||
int32_t dataLen;
|
||||
SArray* blockPos; // beginning pos for each SRetrieveTableRsp
|
||||
void* blockData; // serialized batched SRetrieveTableRsp
|
||||
} SMqPollRspV2;
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSMqPollRspV2(void** buf, const SMqPollRspV2* pRsp) {
|
||||
int32_t tlen = 0;
|
||||
tlen += taosEncodeFixedI64(buf, pRsp->reqOffset);
|
||||
tlen += taosEncodeFixedI64(buf, pRsp->rspOffset);
|
||||
tlen += taosEncodeFixedI32(buf, pRsp->skipLogNum);
|
||||
tlen += taosEncodeFixedI32(buf, pRsp->dataLen);
|
||||
if (pRsp->dataLen != 0) {
|
||||
int32_t sz = taosArrayGetSize(pRsp->blockPos);
|
||||
tlen += taosEncodeFixedI32(buf, sz);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
int32_t blockPos = *(int32_t*)taosArrayGet(pRsp->blockPos, i);
|
||||
tlen += taosEncodeFixedI32(buf, blockPos);
|
||||
}
|
||||
tlen += taosEncodeBinary(buf, pRsp->blockData, pRsp->dataLen);
|
||||
}
|
||||
return tlen;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void* tDecodeSMqPollRspV2(const void* buf, SMqPollRspV2* pRsp) {
|
||||
buf = taosDecodeFixedI64(buf, &pRsp->reqOffset);
|
||||
buf = taosDecodeFixedI64(buf, &pRsp->rspOffset);
|
||||
buf = taosDecodeFixedI32(buf, &pRsp->skipLogNum);
|
||||
buf = taosDecodeFixedI32(buf, &pRsp->dataLen);
|
||||
if (pRsp->dataLen != 0) {
|
||||
int32_t sz;
|
||||
buf = taosDecodeFixedI32(buf, &sz);
|
||||
pRsp->blockPos = taosArrayInit(sz, sizeof(int32_t));
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
int32_t blockPos;
|
||||
buf = taosDecodeFixedI32(buf, &blockPos);
|
||||
taosArrayPush(pRsp->blockPos, &blockPos);
|
||||
}
|
||||
buf = taosDecodeBinary(buf, &pRsp->blockData, pRsp->dataLen);
|
||||
}
|
||||
return (void*)buf;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
SMqRspHead head;
|
||||
int64_t reqOffset;
|
||||
|
@ -2616,7 +2481,7 @@ typedef struct {
|
|||
SMqRspHead head;
|
||||
char cgroup[TSDB_CGROUP_LEN];
|
||||
SArray* topics; // SArray<SMqSubTopicEp>
|
||||
} SMqCMGetSubEpRsp;
|
||||
} SMqAskEpRsp;
|
||||
|
||||
static FORCE_INLINE void tDeleteSMqSubTopicEp(SMqSubTopicEp* pSubTopicEp) {
|
||||
// taosMemoryFree(pSubTopicEp->schema.pSchema);
|
||||
|
@ -2638,10 +2503,6 @@ static FORCE_INLINE void* tDecodeSMqSubVgEp(void* buf, SMqSubVgEp* pVgEp) {
|
|||
return buf;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void tDeleteSMqCMGetSubEpRsp(SMqCMGetSubEpRsp* pRsp) {
|
||||
taosArrayDestroyEx(pRsp->topics, (void (*)(void*))tDeleteSMqSubTopicEp);
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSMqSubTopicEp(void** buf, const SMqSubTopicEp* pTopicEp) {
|
||||
int32_t tlen = 0;
|
||||
tlen += taosEncodeString(buf, pTopicEp->topic);
|
||||
|
@ -2674,7 +2535,7 @@ static FORCE_INLINE void* tDecodeSMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicE
|
|||
return buf;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSMqCMGetSubEpRsp(void** buf, const SMqCMGetSubEpRsp* pRsp) {
|
||||
static FORCE_INLINE int32_t tEncodeSMqAskEpRsp(void** buf, const SMqAskEpRsp* pRsp) {
|
||||
int32_t tlen = 0;
|
||||
// tlen += taosEncodeString(buf, pRsp->cgroup);
|
||||
int32_t sz = taosArrayGetSize(pRsp->topics);
|
||||
|
@ -2686,7 +2547,7 @@ static FORCE_INLINE int32_t tEncodeSMqCMGetSubEpRsp(void** buf, const SMqCMGetSu
|
|||
return tlen;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void* tDecodeSMqCMGetSubEpRsp(void* buf, SMqCMGetSubEpRsp* pRsp) {
|
||||
static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
|
||||
// buf = taosDecodeStringTo(buf, pRsp->cgroup);
|
||||
int32_t sz;
|
||||
buf = taosDecodeFixedI32(buf, &sz);
|
||||
|
@ -2702,6 +2563,10 @@ static FORCE_INLINE void* tDecodeSMqCMGetSubEpRsp(void* buf, SMqCMGetSubEpRsp* p
|
|||
return buf;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
|
||||
taosArrayDestroyEx(pRsp->topics, (void (*)(void*))tDeleteSMqSubTopicEp);
|
||||
}
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -145,10 +145,11 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_TOPIC, "mnode-alter-topic", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_TOPIC, "mnode-drop-topic", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_SUBSCRIBE, "mnode-subscribe", SCMSubscribeReq, SCMSubscribeRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_GET_SUB_EP, "mnode-mq-ask-ep", SMqCMGetSubEpReq, SMqCMGetSubEpRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_TIMER, "mnode-mq-tmr", SMTimerReq, SMTimerReq)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_CONSUMER_LOST, "mnode-mq-consumer-lost", SMTimerReq, SMTimerReq)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_DO_REBALANCE, "mnode-mq-do-rebalance", SMqDoRebalanceMsg, SMqDoRebalanceMsg)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_ASK_EP, "mnode-mq-ask-ep", SMqAskEpReq, SMqAskEpRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_TIMER, "mnode-mq-tmr", SMTimerReq, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_CONSUMER_LOST, "mnode-mq-consumer-lost", SMqConsumerLostMsg, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_CONSUMER_RECOVER, "mnode-mq-consumer-recover", SMqConsumerRecoverMsg, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_DO_REBALANCE, "mnode-mq-do-rebalance", SMqDoRebalanceMsg, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_COMMIT_OFFSET, "mnode-mq-commit-offset", SMqCMCommitOffsetReq, SMqCMCommitOffsetRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_STREAM, "mnode-create-stream", SCMCreateStreamReq, SCMCreateStreamRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_STREAM, "mnode-alter-stream", NULL, NULL)
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "tbuffer.h"
|
||||
#include "tdataformat.h"
|
||||
#include "tdef.h"
|
||||
#include "tschema.h"
|
||||
#include "ttypes.h"
|
||||
#include "tutil.h"
|
||||
|
||||
|
@ -58,12 +57,12 @@ extern "C" {
|
|||
#define TD_ROWS_ALL_NORM 0x00U
|
||||
#define TD_ROWS_NULL_NORM 0x01U
|
||||
|
||||
#define TD_COL_ROWS_NORM(c) ((c)->bitmap == TD_ROWS_ALL_NORM) // all rows of SDataCol/SBlockCol is NORM
|
||||
#define TD_COL_ROWS_NORM(c) ((c)->bitmap == TD_ROWS_ALL_NORM) // all rows of SDataCol/SBlockCol is NORM
|
||||
#define TD_SET_COL_ROWS_BTIMAP(c, v) ((c)->bitmap = (v))
|
||||
#define TD_SET_COL_ROWS_NORM(c) TD_SET_COL_ROWS_BTIMAP((c), TD_ROWS_ALL_NORM)
|
||||
#define TD_SET_COL_ROWS_MISC(c) TD_SET_COL_ROWS_BTIMAP((c), TD_ROWS_NULL_NORM)
|
||||
#define TD_SET_COL_ROWS_NORM(c) TD_SET_COL_ROWS_BTIMAP((c), TD_ROWS_ALL_NORM)
|
||||
#define TD_SET_COL_ROWS_MISC(c) TD_SET_COL_ROWS_BTIMAP((c), TD_ROWS_NULL_NORM)
|
||||
|
||||
#define KvConvertRatio (0.9f)
|
||||
#define KvConvertRatio (0.9f)
|
||||
#define isSelectKVRow(klen, tlen) ((klen) < ((tlen)*KvConvertRatio))
|
||||
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
|
@ -341,7 +340,8 @@ static FORCE_INLINE bool tdIsBitmapValTypeNorm(const void *pBitmap, int16_t idx,
|
|||
return false;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tdGetBitmapValType(const void *pBitmap, int16_t colIdx, TDRowValT *pValType, int8_t bitmapMode) {
|
||||
static FORCE_INLINE int32_t tdGetBitmapValType(const void *pBitmap, int16_t colIdx, TDRowValT *pValType,
|
||||
int8_t bitmapMode) {
|
||||
switch (bitmapMode) {
|
||||
case 0:
|
||||
tdGetBitmapValTypeII(pBitmap, colIdx, pValType);
|
||||
|
|
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_COMMON_SCHEMA_H_
|
||||
#define _TD_COMMON_SCHEMA_H_
|
||||
|
||||
#include "os.h"
|
||||
#include "tarray.h"
|
||||
#include "ttypes.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
typedef struct STColumn {
|
||||
/// column name
|
||||
char *cname;
|
||||
union {
|
||||
/// for encode purpose
|
||||
uint64_t info;
|
||||
struct {
|
||||
uint64_t sma : 1;
|
||||
/// column data type
|
||||
uint64_t type : 7;
|
||||
/// column id
|
||||
uint64_t cid : 16;
|
||||
/// max bytes of the column
|
||||
uint64_t bytes : 32;
|
||||
/// reserved
|
||||
uint64_t reserve : 8;
|
||||
};
|
||||
};
|
||||
/// comment about the column
|
||||
char *comment;
|
||||
} STColumn;
|
||||
|
||||
typedef struct STSchema {
|
||||
/// schema version
|
||||
uint16_t sver;
|
||||
/// number of columns
|
||||
uint16_t ncols;
|
||||
/// sma attributes
|
||||
struct {
|
||||
bool sma;
|
||||
SArray *smaArray;
|
||||
};
|
||||
/// column info
|
||||
STColumn cols[];
|
||||
} STSchema;
|
||||
|
||||
typedef struct {
|
||||
uint64_t size;
|
||||
STSchema *pSchema;
|
||||
} STShemaBuilder;
|
||||
|
||||
#define tSchemaBuilderInit(target, capacity) \
|
||||
{ .size = (capacity), .pSchema = (target) }
|
||||
void tSchemaBuilderSetSver(STShemaBuilder *pSchemaBuilder, uint16_t sver);
|
||||
void tSchemaBuilderSetSMA(bool sma, SArray *smaArray);
|
||||
int32_t tSchemaBuilderPutColumn(char *cname, bool sma, uint8_t type, col_id_t cid, uint32_t bytes, char *comment);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_COMMON_SCHEMA_H_*/
|
|
@ -18,6 +18,11 @@
|
|||
|
||||
#include "os.h"
|
||||
|
||||
#include "thash.h"
|
||||
#include "tlockfree.h"
|
||||
#include "tlog.h"
|
||||
#include "tmsg.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -135,7 +140,7 @@ typedef enum {
|
|||
typedef struct SSdb SSdb;
|
||||
typedef int32_t (*SdbInsertFp)(SSdb *pSdb, void *pObj);
|
||||
typedef int32_t (*SdbUpdateFp)(SSdb *pSdb, void *pSrcObj, void *pDstObj);
|
||||
typedef int32_t (*SdbDeleteFp)(SSdb *pSdb, void *pObj);
|
||||
typedef int32_t (*SdbDeleteFp)(SSdb *pSdb, void *pObj, bool callFunc);
|
||||
typedef int32_t (*SdbDeployFp)(SMnode *pMnode);
|
||||
typedef SSdbRow *(*SdbDecodeFp)(SSdbRaw *pRaw);
|
||||
typedef SSdbRaw *(*SdbEncodeFp)(void *pObj);
|
||||
|
@ -221,7 +226,7 @@ int32_t sdbWrite(SSdb *pSdb, SSdbRaw *pRaw);
|
|||
* @param pRaw The raw data.
|
||||
* @return int32_t 0 for success, -1 for failure.
|
||||
*/
|
||||
int32_t sdbWriteNotFree(SSdb *pSdb, SSdbRaw *pRaw);
|
||||
int32_t sdbWriteWithoutFree(SSdb *pSdb, SSdbRaw *pRaw);
|
||||
|
||||
/**
|
||||
* @brief Acquire a row from sdb
|
||||
|
@ -326,9 +331,29 @@ int32_t sdbGetRawSoftVer(SSdbRaw *pRaw, int8_t *sver);
|
|||
int32_t sdbGetRawTotalSize(SSdbRaw *pRaw);
|
||||
|
||||
SSdbRow *sdbAllocRow(int32_t objSize);
|
||||
void sdbFreeRow(SSdb *pSdb, SSdbRow *pRow);
|
||||
void sdbFreeRow(SSdb *pSdb, SSdbRow *pRow, bool callFunc);
|
||||
void *sdbGetRowObj(SSdbRow *pRow);
|
||||
|
||||
typedef struct SSdb {
|
||||
SMnode *pMnode;
|
||||
char *currDir;
|
||||
char *syncDir;
|
||||
char *tmpDir;
|
||||
int64_t lastCommitVer;
|
||||
int64_t curVer;
|
||||
int64_t tableVer[SDB_MAX];
|
||||
int64_t maxId[SDB_MAX];
|
||||
EKeyType keyTypes[SDB_MAX];
|
||||
SHashObj *hashObjs[SDB_MAX];
|
||||
SRWLatch locks[SDB_MAX];
|
||||
SdbInsertFp insertFps[SDB_MAX];
|
||||
SdbUpdateFp updateFps[SDB_MAX];
|
||||
SdbDeleteFp deleteFps[SDB_MAX];
|
||||
SdbDeployFp deployFps[SDB_MAX];
|
||||
SdbEncodeFp encodeFps[SDB_MAX];
|
||||
SdbDecodeFp decodeFps[SDB_MAX];
|
||||
} SSdb;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -32,6 +32,7 @@ typedef struct SReadHandle {
|
|||
void* reader;
|
||||
void* meta;
|
||||
void* config;
|
||||
void* vnode;
|
||||
} SReadHandle;
|
||||
|
||||
#define STREAM_DATA_TYPE_SUBMIT_BLOCK 0x1
|
||||
|
|
|
@ -202,7 +202,7 @@ typedef struct SqlFunctionCtx {
|
|||
SPoint1 end;
|
||||
SFuncExecFuncs fpSet;
|
||||
SScalarFuncExecFuncs sfp;
|
||||
SExprInfo *pExpr;
|
||||
struct SExprInfo *pExpr;
|
||||
struct SDiskbasedBuf *pBuf;
|
||||
struct SSDataBlock *pSrcBlock;
|
||||
int32_t curBufPage;
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "querynodes.h"
|
||||
#include "function.h"
|
||||
#include "querynodes.h"
|
||||
|
||||
typedef enum EFunctionType {
|
||||
// aggregate function
|
||||
|
@ -123,10 +123,10 @@ struct SCatalog;
|
|||
|
||||
typedef struct SFmGetFuncInfoParam {
|
||||
struct SCatalog* pCtg;
|
||||
void *pRpc;
|
||||
const SEpSet* pMgmtEps;
|
||||
char* pErrBuf;
|
||||
int32_t errBufLen;
|
||||
void* pRpc;
|
||||
const SEpSet* pMgmtEps;
|
||||
char* pErrBuf;
|
||||
int32_t errBufLen;
|
||||
} SFmGetFuncInfoParam;
|
||||
|
||||
int32_t fmFuncMgtInit();
|
||||
|
@ -143,6 +143,7 @@ bool fmIsDatetimeFunc(int32_t funcId);
|
|||
bool fmIsTimelineFunc(int32_t funcId);
|
||||
bool fmIsTimeorderFunc(int32_t funcId);
|
||||
bool fmIsPseudoColumnFunc(int32_t funcId);
|
||||
bool fmIsScanPseudoColumnFunc(int32_t funcId);
|
||||
bool fmIsWindowPseudoColumnFunc(int32_t funcId);
|
||||
bool fmIsWindowClauseFunc(int32_t funcId);
|
||||
bool fmIsSpecialDataRequiredFunc(int32_t funcId);
|
||||
|
|
|
@ -20,50 +20,46 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "querynodes.h"
|
||||
#include "query.h"
|
||||
#include "querynodes.h"
|
||||
#include "tname.h"
|
||||
|
||||
typedef struct SLogicNode {
|
||||
ENodeType type;
|
||||
SNodeList* pTargets; // SColumnNode
|
||||
SNode* pConditions;
|
||||
SNodeList* pChildren;
|
||||
ENodeType type;
|
||||
SNodeList* pTargets; // SColumnNode
|
||||
SNode* pConditions;
|
||||
SNodeList* pChildren;
|
||||
struct SLogicNode* pParent;
|
||||
int32_t optimizedFlag;
|
||||
int32_t optimizedFlag;
|
||||
} SLogicNode;
|
||||
|
||||
typedef enum EScanType {
|
||||
SCAN_TYPE_TAG,
|
||||
SCAN_TYPE_TABLE,
|
||||
SCAN_TYPE_SYSTEM_TABLE,
|
||||
SCAN_TYPE_STREAM
|
||||
} EScanType;
|
||||
typedef enum EScanType { SCAN_TYPE_TAG = 1, SCAN_TYPE_TABLE, SCAN_TYPE_SYSTEM_TABLE, SCAN_TYPE_STREAM } EScanType;
|
||||
|
||||
typedef struct SScanLogicNode {
|
||||
SLogicNode node;
|
||||
SNodeList* pScanCols;
|
||||
SLogicNode node;
|
||||
SNodeList* pScanCols;
|
||||
SNodeList* pScanPseudoCols;
|
||||
struct STableMeta* pMeta;
|
||||
SVgroupsInfo* pVgroupList;
|
||||
EScanType scanType;
|
||||
uint8_t scanSeq[2]; // first is scan count, and second is reverse scan count
|
||||
STimeWindow scanRange;
|
||||
SName tableName;
|
||||
bool showRewrite;
|
||||
double ratio;
|
||||
SNodeList* pDynamicScanFuncs;
|
||||
int32_t dataRequired;
|
||||
int64_t interval;
|
||||
int64_t offset;
|
||||
int64_t sliding;
|
||||
int8_t intervalUnit;
|
||||
int8_t slidingUnit;
|
||||
SVgroupsInfo* pVgroupList;
|
||||
EScanType scanType;
|
||||
uint8_t scanSeq[2]; // first is scan count, and second is reverse scan count
|
||||
STimeWindow scanRange;
|
||||
SName tableName;
|
||||
bool showRewrite;
|
||||
double ratio;
|
||||
SNodeList* pDynamicScanFuncs;
|
||||
int32_t dataRequired;
|
||||
int64_t interval;
|
||||
int64_t offset;
|
||||
int64_t sliding;
|
||||
int8_t intervalUnit;
|
||||
int8_t slidingUnit;
|
||||
} SScanLogicNode;
|
||||
|
||||
typedef struct SJoinLogicNode {
|
||||
SLogicNode node;
|
||||
EJoinType joinType;
|
||||
SNode* pOnConditions;
|
||||
EJoinType joinType;
|
||||
SNode* pOnConditions;
|
||||
} SJoinLogicNode;
|
||||
|
||||
typedef struct SAggLogicNode {
|
||||
|
@ -75,47 +71,43 @@ typedef struct SAggLogicNode {
|
|||
typedef struct SProjectLogicNode {
|
||||
SLogicNode node;
|
||||
SNodeList* pProjections;
|
||||
char stmtName[TSDB_TABLE_NAME_LEN];
|
||||
int64_t limit;
|
||||
int64_t offset;
|
||||
int64_t slimit;
|
||||
int64_t soffset;
|
||||
char stmtName[TSDB_TABLE_NAME_LEN];
|
||||
int64_t limit;
|
||||
int64_t offset;
|
||||
int64_t slimit;
|
||||
int64_t soffset;
|
||||
} SProjectLogicNode;
|
||||
|
||||
typedef struct SVnodeModifLogicNode {
|
||||
SLogicNode node;
|
||||
int32_t msgType;
|
||||
SArray* pDataBlocks;
|
||||
SLogicNode node;
|
||||
int32_t msgType;
|
||||
SArray* pDataBlocks;
|
||||
SVgDataBlocks* pVgDataBlocks;
|
||||
} SVnodeModifLogicNode;
|
||||
|
||||
typedef struct SExchangeLogicNode {
|
||||
SLogicNode node;
|
||||
int32_t srcGroupId;
|
||||
uint8_t precision;
|
||||
int32_t srcGroupId;
|
||||
uint8_t precision;
|
||||
} SExchangeLogicNode;
|
||||
|
||||
typedef enum EWindowType {
|
||||
WINDOW_TYPE_INTERVAL = 1,
|
||||
WINDOW_TYPE_SESSION,
|
||||
WINDOW_TYPE_STATE
|
||||
} EWindowType;
|
||||
typedef enum EWindowType { WINDOW_TYPE_INTERVAL = 1, WINDOW_TYPE_SESSION, WINDOW_TYPE_STATE } EWindowType;
|
||||
|
||||
typedef struct SWindowLogicNode {
|
||||
SLogicNode node;
|
||||
SLogicNode node;
|
||||
EWindowType winType;
|
||||
SNodeList* pFuncs;
|
||||
int64_t interval;
|
||||
int64_t offset;
|
||||
int64_t sliding;
|
||||
int8_t intervalUnit;
|
||||
int8_t slidingUnit;
|
||||
SFillNode* pFill;
|
||||
int64_t sessionGap;
|
||||
SNode* pTspk;
|
||||
SNode* pStateExpr;
|
||||
int8_t triggerType;
|
||||
int64_t watermark;
|
||||
SNodeList* pFuncs;
|
||||
int64_t interval;
|
||||
int64_t offset;
|
||||
int64_t sliding;
|
||||
int8_t intervalUnit;
|
||||
int8_t slidingUnit;
|
||||
SFillNode* pFill;
|
||||
int64_t sessionGap;
|
||||
SNode* pTspk;
|
||||
SNode* pStateExpr;
|
||||
int8_t triggerType;
|
||||
int64_t watermark;
|
||||
} SWindowLogicNode;
|
||||
|
||||
typedef struct SSortLogicNode {
|
||||
|
@ -137,59 +129,60 @@ typedef enum ESubplanType {
|
|||
|
||||
typedef struct SSubplanId {
|
||||
uint64_t queryId;
|
||||
int32_t groupId;
|
||||
int32_t subplanId;
|
||||
int32_t groupId;
|
||||
int32_t subplanId;
|
||||
} SSubplanId;
|
||||
|
||||
typedef struct SLogicSubplan {
|
||||
ENodeType type;
|
||||
SSubplanId id;
|
||||
SNodeList* pChildren;
|
||||
SNodeList* pParents;
|
||||
SLogicNode* pNode;
|
||||
ESubplanType subplanType;
|
||||
ENodeType type;
|
||||
SSubplanId id;
|
||||
SNodeList* pChildren;
|
||||
SNodeList* pParents;
|
||||
SLogicNode* pNode;
|
||||
ESubplanType subplanType;
|
||||
SVgroupsInfo* pVgroupList;
|
||||
int32_t level;
|
||||
int32_t splitFlag;
|
||||
int32_t level;
|
||||
int32_t splitFlag;
|
||||
} SLogicSubplan;
|
||||
|
||||
typedef struct SQueryLogicPlan {
|
||||
ENodeType type;
|
||||
ENodeType type;
|
||||
SNodeList* pTopSubplans;
|
||||
} SQueryLogicPlan;
|
||||
|
||||
typedef struct SSlotDescNode {
|
||||
ENodeType type;
|
||||
int16_t slotId;
|
||||
int16_t slotId;
|
||||
SDataType dataType;
|
||||
bool reserve;
|
||||
bool output;
|
||||
bool tag;
|
||||
bool reserve;
|
||||
bool output;
|
||||
bool tag;
|
||||
} SSlotDescNode;
|
||||
|
||||
typedef struct SDataBlockDescNode {
|
||||
ENodeType type;
|
||||
int16_t dataBlockId;
|
||||
ENodeType type;
|
||||
int16_t dataBlockId;
|
||||
SNodeList* pSlots;
|
||||
int32_t totalRowSize;
|
||||
int32_t outputRowSize;
|
||||
uint8_t precision;
|
||||
int32_t totalRowSize;
|
||||
int32_t outputRowSize;
|
||||
uint8_t precision;
|
||||
} SDataBlockDescNode;
|
||||
|
||||
typedef struct SPhysiNode {
|
||||
ENodeType type;
|
||||
ENodeType type;
|
||||
SDataBlockDescNode* pOutputDataBlockDesc;
|
||||
SNode* pConditions;
|
||||
SNodeList* pChildren;
|
||||
struct SPhysiNode* pParent;
|
||||
SNode* pConditions;
|
||||
SNodeList* pChildren;
|
||||
struct SPhysiNode* pParent;
|
||||
} SPhysiNode;
|
||||
|
||||
typedef struct SScanPhysiNode {
|
||||
SPhysiNode node;
|
||||
SNodeList* pScanCols;
|
||||
uint64_t uid; // unique id of the table
|
||||
int8_t tableType;
|
||||
SName tableName;
|
||||
SNodeList* pScanPseudoCols;
|
||||
uint64_t uid; // unique id of the table
|
||||
int8_t tableType;
|
||||
SName tableName;
|
||||
} SScanPhysiNode;
|
||||
|
||||
typedef SScanPhysiNode STagScanPhysiNode;
|
||||
|
@ -197,23 +190,23 @@ typedef SScanPhysiNode SStreamScanPhysiNode;
|
|||
|
||||
typedef struct SSystemTableScanPhysiNode {
|
||||
SScanPhysiNode scan;
|
||||
SEpSet mgmtEpSet;
|
||||
bool showRewrite;
|
||||
int32_t accountId;
|
||||
SEpSet mgmtEpSet;
|
||||
bool showRewrite;
|
||||
int32_t accountId;
|
||||
} SSystemTableScanPhysiNode;
|
||||
|
||||
typedef struct STableScanPhysiNode {
|
||||
SScanPhysiNode scan;
|
||||
uint8_t scanSeq[2]; // first is scan count, and second is reverse scan count
|
||||
STimeWindow scanRange;
|
||||
double ratio;
|
||||
int32_t dataRequired;
|
||||
SNodeList* pDynamicScanFuncs;
|
||||
int64_t interval;
|
||||
int64_t offset;
|
||||
int64_t sliding;
|
||||
int8_t intervalUnit;
|
||||
int8_t slidingUnit;
|
||||
uint8_t scanSeq[2]; // first is scan count, and second is reverse scan count
|
||||
STimeWindow scanRange;
|
||||
double ratio;
|
||||
int32_t dataRequired;
|
||||
SNodeList* pDynamicScanFuncs;
|
||||
int64_t interval;
|
||||
int64_t offset;
|
||||
int64_t sliding;
|
||||
int8_t intervalUnit;
|
||||
int8_t slidingUnit;
|
||||
} STableScanPhysiNode;
|
||||
|
||||
typedef STableScanPhysiNode STableSeqScanPhysiNode;
|
||||
|
@ -221,89 +214,89 @@ typedef STableScanPhysiNode STableSeqScanPhysiNode;
|
|||
typedef struct SProjectPhysiNode {
|
||||
SPhysiNode node;
|
||||
SNodeList* pProjections;
|
||||
int64_t limit;
|
||||
int64_t offset;
|
||||
int64_t slimit;
|
||||
int64_t soffset;
|
||||
int64_t limit;
|
||||
int64_t offset;
|
||||
int64_t slimit;
|
||||
int64_t soffset;
|
||||
} SProjectPhysiNode;
|
||||
|
||||
typedef struct SJoinPhysiNode {
|
||||
SPhysiNode node;
|
||||
EJoinType joinType;
|
||||
SNode* pOnConditions; // in or out tuple ?
|
||||
EJoinType joinType;
|
||||
SNode* pOnConditions; // in or out tuple ?
|
||||
SNodeList* pTargets;
|
||||
} SJoinPhysiNode;
|
||||
|
||||
typedef struct SAggPhysiNode {
|
||||
SPhysiNode node;
|
||||
SNodeList* pExprs; // these are expression list of group_by_clause and parameter expression of aggregate function
|
||||
SNodeList* pExprs; // these are expression list of group_by_clause and parameter expression of aggregate function
|
||||
SNodeList* pGroupKeys;
|
||||
SNodeList* pAggFuncs;
|
||||
} SAggPhysiNode;
|
||||
|
||||
typedef struct SDownstreamSourceNode {
|
||||
ENodeType type;
|
||||
ENodeType type;
|
||||
SQueryNodeAddr addr;
|
||||
uint64_t taskId;
|
||||
uint64_t schedId;
|
||||
uint64_t taskId;
|
||||
uint64_t schedId;
|
||||
} SDownstreamSourceNode;
|
||||
|
||||
typedef struct SExchangePhysiNode {
|
||||
SPhysiNode node;
|
||||
int32_t srcGroupId; // group id of datasource suplans
|
||||
int32_t srcGroupId; // group id of datasource suplans
|
||||
SNodeList* pSrcEndPoints; // element is SDownstreamSource, scheduler fill by calling qSetSuplanExecutionNode
|
||||
} SExchangePhysiNode;
|
||||
|
||||
typedef struct SWinodwPhysiNode {
|
||||
SPhysiNode node;
|
||||
SNodeList* pExprs; // these are expression list of parameter expression of function
|
||||
SNodeList* pExprs; // these are expression list of parameter expression of function
|
||||
SNodeList* pFuncs;
|
||||
SNode* pTspk; // timestamp primary key
|
||||
int8_t triggerType;
|
||||
int64_t watermark;
|
||||
SNode* pTspk; // timestamp primary key
|
||||
int8_t triggerType;
|
||||
int64_t watermark;
|
||||
} SWinodwPhysiNode;
|
||||
|
||||
typedef struct SIntervalPhysiNode {
|
||||
SWinodwPhysiNode window;
|
||||
int64_t interval;
|
||||
int64_t offset;
|
||||
int64_t sliding;
|
||||
int8_t intervalUnit;
|
||||
int8_t slidingUnit;
|
||||
SFillNode* pFill;
|
||||
int64_t interval;
|
||||
int64_t offset;
|
||||
int64_t sliding;
|
||||
int8_t intervalUnit;
|
||||
int8_t slidingUnit;
|
||||
SFillNode* pFill;
|
||||
} SIntervalPhysiNode;
|
||||
|
||||
typedef struct SMultiTableIntervalPhysiNode {
|
||||
SIntervalPhysiNode interval;
|
||||
SNodeList* pPartitionKeys;
|
||||
SNodeList* pPartitionKeys;
|
||||
} SMultiTableIntervalPhysiNode;
|
||||
|
||||
typedef struct SSessionWinodwPhysiNode {
|
||||
SWinodwPhysiNode window;
|
||||
int64_t gap;
|
||||
int64_t gap;
|
||||
} SSessionWinodwPhysiNode;
|
||||
|
||||
typedef struct SStateWinodwPhysiNode {
|
||||
SWinodwPhysiNode window;
|
||||
SNode* pStateKey;
|
||||
SNode* pStateKey;
|
||||
} SStateWinodwPhysiNode;
|
||||
|
||||
typedef struct SSortPhysiNode {
|
||||
SPhysiNode node;
|
||||
SNodeList* pExprs; // these are expression list of order_by_clause and parameter expression of aggregate function
|
||||
SNodeList* pSortKeys; // element is SOrderByExprNode, and SOrderByExprNode::pExpr is SColumnNode
|
||||
SNodeList* pExprs; // these are expression list of order_by_clause and parameter expression of aggregate function
|
||||
SNodeList* pSortKeys; // element is SOrderByExprNode, and SOrderByExprNode::pExpr is SColumnNode
|
||||
SNodeList* pTargets;
|
||||
} SSortPhysiNode;
|
||||
|
||||
typedef struct SPartitionPhysiNode {
|
||||
SPhysiNode node;
|
||||
SNodeList* pExprs; // these are expression list of partition_by_clause
|
||||
SNodeList* pExprs; // these are expression list of partition_by_clause
|
||||
SNodeList* pPartitionKeys;
|
||||
SNodeList* pTargets;
|
||||
} SPartitionPhysiNode;
|
||||
|
||||
typedef struct SDataSinkNode {
|
||||
ENodeType type;
|
||||
ENodeType type;
|
||||
SDataBlockDescNode* pInputDataBlockDesc;
|
||||
} SDataSinkNode;
|
||||
|
||||
|
@ -313,45 +306,41 @@ typedef struct SDataDispatcherNode {
|
|||
|
||||
typedef struct SDataInserterNode {
|
||||
SDataSinkNode sink;
|
||||
int32_t numOfTables;
|
||||
uint32_t size;
|
||||
char *pData;
|
||||
int32_t numOfTables;
|
||||
uint32_t size;
|
||||
char* pData;
|
||||
} SDataInserterNode;
|
||||
|
||||
typedef struct SSubplan {
|
||||
ENodeType type;
|
||||
SSubplanId id; // unique id of the subplan
|
||||
ESubplanType subplanType;
|
||||
int32_t msgType; // message type for subplan, used to denote the send message type to vnode.
|
||||
int32_t level; // the execution level of current subplan, starting from 0 in a top-down manner.
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
SQueryNodeAddr execNode; // for the scan/modify subplan, the optional execution node
|
||||
SQueryNodeStat execNodeStat; // only for scan subplan
|
||||
SNodeList* pChildren; // the datasource subplan,from which to fetch the result
|
||||
SNodeList* pParents; // the data destination subplan, get data from current subplan
|
||||
SPhysiNode* pNode; // physical plan of current subplan
|
||||
SDataSinkNode* pDataSink; // data of the subplan flow into the datasink
|
||||
ENodeType type;
|
||||
SSubplanId id; // unique id of the subplan
|
||||
ESubplanType subplanType;
|
||||
int32_t msgType; // message type for subplan, used to denote the send message type to vnode.
|
||||
int32_t level; // the execution level of current subplan, starting from 0 in a top-down manner.
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
SQueryNodeAddr execNode; // for the scan/modify subplan, the optional execution node
|
||||
SQueryNodeStat execNodeStat; // only for scan subplan
|
||||
SNodeList* pChildren; // the datasource subplan,from which to fetch the result
|
||||
SNodeList* pParents; // the data destination subplan, get data from current subplan
|
||||
SPhysiNode* pNode; // physical plan of current subplan
|
||||
SDataSinkNode* pDataSink; // data of the subplan flow into the datasink
|
||||
} SSubplan;
|
||||
|
||||
typedef enum EExplainMode {
|
||||
EXPLAIN_MODE_DISABLE = 1,
|
||||
EXPLAIN_MODE_STATIC,
|
||||
EXPLAIN_MODE_ANALYZE
|
||||
} EExplainMode;
|
||||
typedef enum EExplainMode { EXPLAIN_MODE_DISABLE = 1, EXPLAIN_MODE_STATIC, EXPLAIN_MODE_ANALYZE } EExplainMode;
|
||||
|
||||
typedef struct SExplainInfo {
|
||||
EExplainMode mode;
|
||||
bool verbose;
|
||||
double ratio;
|
||||
bool verbose;
|
||||
double ratio;
|
||||
} SExplainInfo;
|
||||
|
||||
typedef struct SQueryPlan {
|
||||
ENodeType type;
|
||||
uint64_t queryId;
|
||||
int32_t numOfSubplans;
|
||||
SNodeList* pSubplans; // Element is SNodeListNode. The execution level of subplan, starting from 0.
|
||||
ENodeType type;
|
||||
uint64_t queryId;
|
||||
int32_t numOfSubplans;
|
||||
SNodeList* pSubplans; // Element is SNodeListNode. The execution level of subplan, starting from 0.
|
||||
SExplainInfo explainInfo;
|
||||
SNodeList* pPlaceholderValues;
|
||||
SNodeList* pPlaceholderValues;
|
||||
} SQueryPlan;
|
||||
|
||||
void nodesWalkPhysiPlan(SNode* pNode, FNodeWalker walker, void* pContext);
|
||||
|
|
|
@ -25,14 +25,16 @@ extern "C" {
|
|||
#include "tvariant.h"
|
||||
|
||||
#define TABLE_TOTAL_COL_NUM(pMeta) ((pMeta)->tableInfo.numOfColumns + (pMeta)->tableInfo.numOfTags)
|
||||
#define TABLE_META_SIZE(pMeta) (NULL == (pMeta) ? 0 : (sizeof(STableMeta) + TABLE_TOTAL_COL_NUM((pMeta)) * sizeof(SSchema)))
|
||||
#define VGROUPS_INFO_SIZE(pInfo) (NULL == (pInfo) ? 0 : (sizeof(SVgroupsInfo) + (pInfo)->numOfVgroups * sizeof(SVgroupInfo)))
|
||||
#define TABLE_META_SIZE(pMeta) \
|
||||
(NULL == (pMeta) ? 0 : (sizeof(STableMeta) + TABLE_TOTAL_COL_NUM((pMeta)) * sizeof(SSchema)))
|
||||
#define VGROUPS_INFO_SIZE(pInfo) \
|
||||
(NULL == (pInfo) ? 0 : (sizeof(SVgroupsInfo) + (pInfo)->numOfVgroups * sizeof(SVgroupInfo)))
|
||||
|
||||
typedef struct SRawExprNode {
|
||||
ENodeType nodeType;
|
||||
char* p;
|
||||
uint32_t n;
|
||||
SNode* pNode;
|
||||
char* p;
|
||||
uint32_t n;
|
||||
SNode* pNode;
|
||||
} SRawExprNode;
|
||||
|
||||
typedef struct SDataType {
|
||||
|
@ -45,170 +47,155 @@ typedef struct SDataType {
|
|||
typedef struct SExprNode {
|
||||
ENodeType type;
|
||||
SDataType resType;
|
||||
char aliasName[TSDB_COL_NAME_LEN];
|
||||
SArray* pAssociation;
|
||||
char aliasName[TSDB_COL_NAME_LEN];
|
||||
SArray* pAssociation;
|
||||
} SExprNode;
|
||||
|
||||
typedef enum EColumnType {
|
||||
COLUMN_TYPE_COLUMN = 1,
|
||||
COLUMN_TYPE_TAG
|
||||
} EColumnType;
|
||||
typedef enum EColumnType { COLUMN_TYPE_COLUMN = 1, COLUMN_TYPE_TAG } EColumnType;
|
||||
|
||||
typedef struct SColumnNode {
|
||||
SExprNode node; // QUERY_NODE_COLUMN
|
||||
uint64_t tableId;
|
||||
int8_t tableType;
|
||||
col_id_t colId;
|
||||
EColumnType colType; // column or tag
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char tableName[TSDB_TABLE_NAME_LEN];
|
||||
char tableAlias[TSDB_TABLE_NAME_LEN];
|
||||
char colName[TSDB_COL_NAME_LEN];
|
||||
SNode* pProjectRef;
|
||||
int16_t dataBlockId;
|
||||
int16_t slotId;
|
||||
SExprNode node; // QUERY_NODE_COLUMN
|
||||
uint64_t tableId;
|
||||
int8_t tableType;
|
||||
col_id_t colId;
|
||||
EColumnType colType; // column or tag
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char tableName[TSDB_TABLE_NAME_LEN];
|
||||
char tableAlias[TSDB_TABLE_NAME_LEN];
|
||||
char colName[TSDB_COL_NAME_LEN];
|
||||
SNode* pProjectRef;
|
||||
int16_t dataBlockId;
|
||||
int16_t slotId;
|
||||
} SColumnNode;
|
||||
|
||||
typedef struct STargetNode {
|
||||
ENodeType type;
|
||||
int16_t dataBlockId;
|
||||
int16_t slotId;
|
||||
SNode* pExpr;
|
||||
int16_t dataBlockId;
|
||||
int16_t slotId;
|
||||
SNode* pExpr;
|
||||
} STargetNode;
|
||||
|
||||
typedef struct SValueNode {
|
||||
SExprNode node; // QUERY_NODE_VALUE
|
||||
char* literal;
|
||||
bool isDuration;
|
||||
bool translate;
|
||||
int16_t placeholderNo;
|
||||
SExprNode node; // QUERY_NODE_VALUE
|
||||
char* literal;
|
||||
bool isDuration;
|
||||
bool translate;
|
||||
int16_t placeholderNo;
|
||||
union {
|
||||
bool b;
|
||||
int64_t i;
|
||||
bool b;
|
||||
int64_t i;
|
||||
uint64_t u;
|
||||
double d;
|
||||
char* p;
|
||||
double d;
|
||||
char* p;
|
||||
} datum;
|
||||
char unit;
|
||||
} SValueNode;
|
||||
|
||||
typedef struct SOperatorNode {
|
||||
SExprNode node; // QUERY_NODE_OPERATOR
|
||||
SExprNode node; // QUERY_NODE_OPERATOR
|
||||
EOperatorType opType;
|
||||
SNode* pLeft;
|
||||
SNode* pRight;
|
||||
SNode* pLeft;
|
||||
SNode* pRight;
|
||||
} SOperatorNode;
|
||||
|
||||
|
||||
typedef struct SLogicConditionNode {
|
||||
SExprNode node; // QUERY_NODE_LOGIC_CONDITION
|
||||
SExprNode node; // QUERY_NODE_LOGIC_CONDITION
|
||||
ELogicConditionType condType;
|
||||
SNodeList* pParameterList;
|
||||
SNodeList* pParameterList;
|
||||
} SLogicConditionNode;
|
||||
|
||||
typedef struct SNodeListNode {
|
||||
ENodeType type; // QUERY_NODE_NODE_LIST
|
||||
SDataType dataType;
|
||||
ENodeType type; // QUERY_NODE_NODE_LIST
|
||||
SDataType dataType;
|
||||
SNodeList* pNodeList;
|
||||
} SNodeListNode;
|
||||
|
||||
typedef struct SFunctionNode {
|
||||
SExprNode node; // QUERY_NODE_FUNCTION
|
||||
char functionName[TSDB_FUNC_NAME_LEN];
|
||||
int32_t funcId;
|
||||
int32_t funcType;
|
||||
SExprNode node; // QUERY_NODE_FUNCTION
|
||||
char functionName[TSDB_FUNC_NAME_LEN];
|
||||
int32_t funcId;
|
||||
int32_t funcType;
|
||||
SNodeList* pParameterList;
|
||||
int32_t udfBufSize;
|
||||
int32_t udfBufSize;
|
||||
} SFunctionNode;
|
||||
|
||||
typedef struct STableNode {
|
||||
SExprNode node;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char tableName[TSDB_TABLE_NAME_LEN];
|
||||
char tableAlias[TSDB_TABLE_NAME_LEN];
|
||||
uint8_t precision;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char tableName[TSDB_TABLE_NAME_LEN];
|
||||
char tableAlias[TSDB_TABLE_NAME_LEN];
|
||||
uint8_t precision;
|
||||
} STableNode;
|
||||
|
||||
struct STableMeta;
|
||||
|
||||
typedef struct SRealTableNode {
|
||||
STableNode table; // QUERY_NODE_REAL_TABLE
|
||||
STableNode table; // QUERY_NODE_REAL_TABLE
|
||||
struct STableMeta* pMeta;
|
||||
SVgroupsInfo* pVgroupList;
|
||||
char qualDbName[TSDB_DB_NAME_LEN]; // SHOW qualDbName.TABLES
|
||||
double ratio;
|
||||
SVgroupsInfo* pVgroupList;
|
||||
char qualDbName[TSDB_DB_NAME_LEN]; // SHOW qualDbName.TABLES
|
||||
double ratio;
|
||||
} SRealTableNode;
|
||||
|
||||
typedef struct STempTableNode {
|
||||
STableNode table; // QUERY_NODE_TEMP_TABLE
|
||||
SNode* pSubquery;
|
||||
STableNode table; // QUERY_NODE_TEMP_TABLE
|
||||
SNode* pSubquery;
|
||||
} STempTableNode;
|
||||
|
||||
typedef enum EJoinType {
|
||||
JOIN_TYPE_INNER = 1
|
||||
} EJoinType;
|
||||
typedef enum EJoinType { JOIN_TYPE_INNER = 1 } EJoinType;
|
||||
|
||||
typedef struct SJoinTableNode {
|
||||
STableNode table; // QUERY_NODE_JOIN_TABLE
|
||||
EJoinType joinType;
|
||||
SNode* pLeft;
|
||||
SNode* pRight;
|
||||
SNode* pOnCond;
|
||||
STableNode table; // QUERY_NODE_JOIN_TABLE
|
||||
EJoinType joinType;
|
||||
SNode* pLeft;
|
||||
SNode* pRight;
|
||||
SNode* pOnCond;
|
||||
} SJoinTableNode;
|
||||
|
||||
typedef enum EGroupingSetType {
|
||||
GP_TYPE_NORMAL = 1
|
||||
} EGroupingSetType;
|
||||
typedef enum EGroupingSetType { GP_TYPE_NORMAL = 1 } EGroupingSetType;
|
||||
|
||||
typedef struct SGroupingSetNode {
|
||||
ENodeType type; // QUERY_NODE_GROUPING_SET
|
||||
ENodeType type; // QUERY_NODE_GROUPING_SET
|
||||
EGroupingSetType groupingSetType;
|
||||
SNodeList* pParameterList;
|
||||
SNodeList* pParameterList;
|
||||
} SGroupingSetNode;
|
||||
|
||||
typedef enum EOrder {
|
||||
ORDER_ASC = 1,
|
||||
ORDER_DESC
|
||||
} EOrder;
|
||||
typedef enum EOrder { ORDER_ASC = 1, ORDER_DESC } EOrder;
|
||||
|
||||
typedef enum ENullOrder {
|
||||
NULL_ORDER_DEFAULT = 1,
|
||||
NULL_ORDER_FIRST,
|
||||
NULL_ORDER_LAST
|
||||
} ENullOrder;
|
||||
typedef enum ENullOrder { NULL_ORDER_DEFAULT = 1, NULL_ORDER_FIRST, NULL_ORDER_LAST } ENullOrder;
|
||||
|
||||
typedef struct SOrderByExprNode {
|
||||
ENodeType type; // QUERY_NODE_ORDER_BY_EXPR
|
||||
SNode* pExpr;
|
||||
EOrder order;
|
||||
ENodeType type; // QUERY_NODE_ORDER_BY_EXPR
|
||||
SNode* pExpr;
|
||||
EOrder order;
|
||||
ENullOrder nullOrder;
|
||||
} SOrderByExprNode;
|
||||
|
||||
typedef struct SLimitNode {
|
||||
ENodeType type; // QUERY_NODE_LIMIT
|
||||
int64_t limit;
|
||||
int64_t offset;
|
||||
ENodeType type; // QUERY_NODE_LIMIT
|
||||
int64_t limit;
|
||||
int64_t offset;
|
||||
} SLimitNode;
|
||||
|
||||
typedef struct SStateWindowNode {
|
||||
ENodeType type; // QUERY_NODE_STATE_WINDOW
|
||||
SNode* pCol; // timestamp primary key
|
||||
SNode* pExpr;
|
||||
ENodeType type; // QUERY_NODE_STATE_WINDOW
|
||||
SNode* pCol; // timestamp primary key
|
||||
SNode* pExpr;
|
||||
} SStateWindowNode;
|
||||
|
||||
typedef struct SSessionWindowNode {
|
||||
ENodeType type; // QUERY_NODE_SESSION_WINDOW
|
||||
SColumnNode* pCol; // timestamp primary key
|
||||
SValueNode* pGap; // gap between two session window(in microseconds)
|
||||
ENodeType type; // QUERY_NODE_SESSION_WINDOW
|
||||
SColumnNode* pCol; // timestamp primary key
|
||||
SValueNode* pGap; // gap between two session window(in microseconds)
|
||||
} SSessionWindowNode;
|
||||
|
||||
typedef struct SIntervalWindowNode {
|
||||
ENodeType type; // QUERY_NODE_INTERVAL_WINDOW
|
||||
SNode* pCol; // timestamp primary key
|
||||
SNode* pInterval; // SValueNode
|
||||
SNode* pOffset; // SValueNode
|
||||
SNode* pSliding; // SValueNode
|
||||
SNode* pFill;
|
||||
ENodeType type; // QUERY_NODE_INTERVAL_WINDOW
|
||||
SNode* pCol; // timestamp primary key
|
||||
SNode* pInterval; // SValueNode
|
||||
SNode* pOffset; // SValueNode
|
||||
SNode* pSliding; // SValueNode
|
||||
SNode* pFill;
|
||||
} SIntervalWindowNode;
|
||||
|
||||
typedef enum EFillMode {
|
||||
|
@ -221,42 +208,40 @@ typedef enum EFillMode {
|
|||
} EFillMode;
|
||||
|
||||
typedef struct SFillNode {
|
||||
ENodeType type; // QUERY_NODE_FILL
|
||||
ENodeType type; // QUERY_NODE_FILL
|
||||
EFillMode mode;
|
||||
SNode* pValues; // SNodeListNode
|
||||
SNode* pValues; // SNodeListNode
|
||||
} SFillNode;
|
||||
|
||||
typedef struct SSelectStmt {
|
||||
ENodeType type; // QUERY_NODE_SELECT_STMT
|
||||
bool isDistinct;
|
||||
SNodeList* pProjectionList;
|
||||
SNode* pFromTable;
|
||||
SNode* pWhere;
|
||||
SNodeList* pPartitionByList;
|
||||
SNode* pWindow;
|
||||
SNodeList* pGroupByList; // SGroupingSetNode
|
||||
SNode* pHaving;
|
||||
SNodeList* pOrderByList; // SOrderByExprNode
|
||||
ENodeType type; // QUERY_NODE_SELECT_STMT
|
||||
bool isDistinct;
|
||||
SNodeList* pProjectionList;
|
||||
SNode* pFromTable;
|
||||
SNode* pWhere;
|
||||
SNodeList* pPartitionByList;
|
||||
SNode* pWindow;
|
||||
SNodeList* pGroupByList; // SGroupingSetNode
|
||||
SNode* pHaving;
|
||||
SNodeList* pOrderByList; // SOrderByExprNode
|
||||
SLimitNode* pLimit;
|
||||
SLimitNode* pSlimit;
|
||||
char stmtName[TSDB_TABLE_NAME_LEN];
|
||||
uint8_t precision;
|
||||
bool isEmptyResult;
|
||||
char stmtName[TSDB_TABLE_NAME_LEN];
|
||||
uint8_t precision;
|
||||
bool isEmptyResult;
|
||||
bool hasAggFuncs;
|
||||
} SSelectStmt;
|
||||
|
||||
typedef enum ESetOperatorType {
|
||||
SET_OP_TYPE_UNION_ALL = 1,
|
||||
SET_OP_TYPE_UNION
|
||||
} ESetOperatorType;
|
||||
typedef enum ESetOperatorType { SET_OP_TYPE_UNION_ALL = 1, SET_OP_TYPE_UNION } ESetOperatorType;
|
||||
|
||||
typedef struct SSetOperator {
|
||||
ENodeType type; // QUERY_NODE_SET_OPERATOR
|
||||
ENodeType type; // QUERY_NODE_SET_OPERATOR
|
||||
ESetOperatorType opType;
|
||||
SNodeList* pProjectionList;
|
||||
SNode* pLeft;
|
||||
SNode* pRight;
|
||||
SNodeList* pOrderByList; // SOrderByExprNode
|
||||
SNode* pLimit;
|
||||
SNodeList* pProjectionList;
|
||||
SNode* pLeft;
|
||||
SNode* pRight;
|
||||
SNodeList* pOrderByList; // SOrderByExprNode
|
||||
SNode* pLimit;
|
||||
} SSetOperator;
|
||||
|
||||
typedef enum ESqlClause {
|
||||
|
@ -271,7 +256,6 @@ typedef enum ESqlClause {
|
|||
SQL_CLAUSE_ORDER_BY
|
||||
} ESqlClause;
|
||||
|
||||
|
||||
typedef enum {
|
||||
PAYLOAD_TYPE_KV = 0,
|
||||
PAYLOAD_TYPE_RAW = 1,
|
||||
|
@ -281,35 +265,38 @@ typedef struct SVgDataBlocks {
|
|||
SVgroupInfo vg;
|
||||
int32_t numOfTables; // number of tables in current submit block
|
||||
uint32_t size;
|
||||
char *pData; // SMsgDesc + SSubmitReq + SSubmitBlk + ...
|
||||
char* pData; // SMsgDesc + SSubmitReq + SSubmitBlk + ...
|
||||
} SVgDataBlocks;
|
||||
|
||||
typedef struct SVnodeModifOpStmt {
|
||||
ENodeType nodeType;
|
||||
ENodeType sqlNodeType;
|
||||
SArray* pDataBlocks; // data block for each vgroup, SArray<SVgDataBlocks*>.
|
||||
uint8_t payloadType; // EPayloadType. 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert
|
||||
uint32_t insertType; // insert data from [file|sql statement| bound statement]
|
||||
const char* sql; // current sql statement position
|
||||
ENodeType nodeType;
|
||||
ENodeType sqlNodeType;
|
||||
SArray* pDataBlocks; // data block for each vgroup, SArray<SVgDataBlocks*>.
|
||||
uint8_t payloadType; // EPayloadType. 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert
|
||||
uint32_t insertType; // insert data from [file|sql statement| bound statement]
|
||||
const char* sql; // current sql statement position
|
||||
} SVnodeModifOpStmt;
|
||||
|
||||
typedef struct SExplainOptions {
|
||||
ENodeType type;
|
||||
bool verbose;
|
||||
double ratio;
|
||||
bool verbose;
|
||||
double ratio;
|
||||
} SExplainOptions;
|
||||
|
||||
typedef struct SExplainStmt {
|
||||
ENodeType type;
|
||||
bool analyze;
|
||||
ENodeType type;
|
||||
bool analyze;
|
||||
SExplainOptions* pOptions;
|
||||
SNode* pQuery;
|
||||
SNode* pQuery;
|
||||
} SExplainStmt;
|
||||
|
||||
void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker walker, void* pContext);
|
||||
void nodesRewriteSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeRewriter rewriter, void* pContext);
|
||||
|
||||
int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char* pTableAlias, SNodeList** pCols);
|
||||
typedef enum ECollectColType { COLLECT_COL_TYPE_COL = 1, COLLECT_COL_TYPE_TAG, COLLECT_COL_TYPE_ALL } ECollectColType;
|
||||
|
||||
int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char* pTableAlias, ECollectColType type,
|
||||
SNodeList** pCols);
|
||||
|
||||
typedef bool (*FFuncClassifier)(int32_t funcId);
|
||||
int32_t nodesCollectFuncs(SSelectStmt* pSelect, FFuncClassifier classifier, SNodeList** pFuncs);
|
||||
|
@ -324,10 +311,10 @@ bool nodesIsJsonOp(const SOperatorNode* pOp);
|
|||
bool nodesIsTimeorderQuery(const SNode* pQuery);
|
||||
bool nodesIsTimelineQuery(const SNode* pQuery);
|
||||
|
||||
void* nodesGetValueFromNode(SValueNode *pNode);
|
||||
char* nodesGetStrValueFromNode(SValueNode *pNode);
|
||||
char *getFillModeString(EFillMode mode);
|
||||
void valueNodeToVariant(const SValueNode* pNode, SVariant* pVal);
|
||||
void* nodesGetValueFromNode(SValueNode* pNode);
|
||||
char* nodesGetStrValueFromNode(SValueNode* pNode);
|
||||
char* getFillModeString(EFillMode mode);
|
||||
void valueNodeToVariant(const SValueNode* pNode, SVariant* pVal);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -88,11 +88,11 @@ int32_t qCloneStmtDataBlock(void** pDst, void* pSrc);
|
|||
void qFreeStmtDataBlock(void* pDataBlock);
|
||||
int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc);
|
||||
void qDestroyStmtDataBlock(void* pBlock);
|
||||
int32_t qBindStmtColsValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, int32_t msgBufLen);
|
||||
int32_t qBindStmtSingleColValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, int32_t msgBufLen, int32_t colIdx, int32_t rowNum);
|
||||
int32_t qBindStmtColsValue(void *pBlock, TAOS_MULTI_BIND *bind, char *msgBuf, int32_t msgBufLen);
|
||||
int32_t qBindStmtSingleColValue(void *pBlock, TAOS_MULTI_BIND *bind, char *msgBuf, int32_t msgBufLen, int32_t colIdx, int32_t rowNum);
|
||||
int32_t qBuildStmtColFields(void *pDataBlock, int32_t *fieldNum, TAOS_FIELD** fields);
|
||||
int32_t qBuildStmtTagFields(void *pBlock, void *boundTags, int32_t *fieldNum, TAOS_FIELD** fields);
|
||||
int32_t qBindStmtTagsValue(void *pBlock, void *boundTags, int64_t suid, SName *pName, TAOS_BIND_v2 *bind, char *msgBuf, int32_t msgBufLen);
|
||||
int32_t qBindStmtTagsValue(void *pBlock, void *boundTags, int64_t suid, SName *pName, TAOS_MULTI_BIND *bind, char *msgBuf, int32_t msgBufLen);
|
||||
void destroyBoundColumnInfo(void* pBoundInfo);
|
||||
int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char *msgBuf, int32_t msgBufLen);
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ int32_t qCreateQueryPlan(SPlanContext* pCxt, SQueryPlan** pPlan, SArray* pExecNo
|
|||
// @pSource one execution location of this group of datasource subplans
|
||||
int32_t qSetSubplanExecutionNode(SSubplan* pSubplan, int32_t groupId, SDownstreamSourceNode* pSource);
|
||||
|
||||
int32_t qStmtBindParam(SQueryPlan* pPlan, TAOS_BIND_v2* pParams);
|
||||
int32_t qStmtBindParam(SQueryPlan* pPlan, TAOS_MULTI_BIND* pParams, int32_t colIdx);
|
||||
|
||||
// Convert to subplan to string for the scheduler to send to the executor
|
||||
int32_t qSubPlanToString(const SSubplan* pSubplan, char** pStr, int32_t* pLen);
|
||||
|
|
|
@ -59,9 +59,13 @@ typedef struct {
|
|||
void * pNode;
|
||||
} SNodeMsg;
|
||||
|
||||
typedef void (*RpcCfp)(void *parent, SRpcMsg *, SEpSet *);
|
||||
typedef void (*RpcCfp)(void *parent, SRpcMsg *, SEpSet *rf);
|
||||
typedef int (*RpcAfp)(void *parent, char *tableId, char *spi, char *encrypt, char *secret, char *ckey);
|
||||
typedef int (*RpcRfp)(void *parent, SRpcMsg *, SEpSet *);
|
||||
///
|
||||
// // SRpcMsg code
|
||||
// REDIERE,
|
||||
// NOT READY, EpSet
|
||||
typedef bool (*RpcRfp)(int32_t code);
|
||||
|
||||
typedef struct SRpcInit {
|
||||
uint16_t localPort; // local port
|
||||
|
|
|
@ -72,8 +72,6 @@ extern "C" {
|
|||
#define WAL_FILE_LEN (WAL_PATH_LEN + 32)
|
||||
#define WAL_MAGIC 0xFAFBFCFDULL
|
||||
|
||||
#define WAL_CUR_FAILED 1
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef enum {
|
||||
TAOS_WAL_NOLOG = 0,
|
||||
|
|
|
@ -59,6 +59,7 @@ extern "C" {
|
|||
#include <winsock.h>
|
||||
#endif
|
||||
|
||||
#define __typeof(a) auto
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -23,27 +23,21 @@ extern "C" {
|
|||
#define TPOW2(x) ((x) * (x))
|
||||
#define TABS(x) ((x) > 0 ? (x) : -(x))
|
||||
|
||||
#define TSWAP(a, b) \
|
||||
do { \
|
||||
__typeof(a) __tmp = (a); \
|
||||
(a) = (b); \
|
||||
(b) = __tmp; \
|
||||
} while (0)
|
||||
|
||||
#ifdef WINDOWS
|
||||
|
||||
#define TSWAP(a, b, c) \
|
||||
do { \
|
||||
c __tmp = (c)(a); \
|
||||
(a) = (c)(b); \
|
||||
(b) = __tmp; \
|
||||
} while (0)
|
||||
#define TMAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#define TMIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#define TRANGE(aa, bb, cc) ((aa) = TMAX((aa), (bb)),(aa) = TMIN((aa), (cc)))
|
||||
|
||||
#else
|
||||
|
||||
#define TSWAP(a, b, c) \
|
||||
do { \
|
||||
__typeof(a) __tmp = (a); \
|
||||
(a) = (b); \
|
||||
(b) = __tmp; \
|
||||
} while (0)
|
||||
|
||||
#define TMAX(a, b) \
|
||||
({ \
|
||||
__typeof(a) __a = (a); \
|
||||
|
@ -51,12 +45,12 @@ extern "C" {
|
|||
(__a > __b) ? __a : __b; \
|
||||
})
|
||||
|
||||
#define TMIN(a, b) \
|
||||
({ \
|
||||
__typeof(a) __a = (a); \
|
||||
__typeof(b) __b = (b); \
|
||||
(__a < __b) ? __a : __b; \
|
||||
})
|
||||
#define TMIN(a, b) \
|
||||
({ \
|
||||
__typeof(a) __a = (a); \
|
||||
__typeof(b) __b = (b); \
|
||||
(__a < __b) ? __a : __b; \
|
||||
})
|
||||
|
||||
#define TRANGE(a, b, c) \
|
||||
({ \
|
||||
|
|
|
@ -19,53 +19,53 @@
|
|||
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||
// When you want to use this feature, you should find or add the same function in the following section.
|
||||
#ifndef ALLOW_FORBID_FUNC
|
||||
#define socket SOCKET_FUNC_TAOS_FORBID
|
||||
#define bind BIND_FUNC_TAOS_FORBID
|
||||
#define listen LISTEN_FUNC_TAOS_FORBID
|
||||
#define accept ACCEPT_FUNC_TAOS_FORBID
|
||||
#define epoll_create EPOLL_CREATE_FUNC_TAOS_FORBID
|
||||
#define epoll_ctl EPOLL_CTL_FUNC_TAOS_FORBID
|
||||
#define epoll_wait EPOLL_WAIT_FUNC_TAOS_FORBID
|
||||
#define inet_addr INET_ADDR_FUNC_TAOS_FORBID
|
||||
#define inet_ntoa INET_NTOA_FUNC_TAOS_FORBID
|
||||
#define socket SOCKET_FUNC_TAOS_FORBID
|
||||
#define bind BIND_FUNC_TAOS_FORBID
|
||||
#define listen LISTEN_FUNC_TAOS_FORBID
|
||||
#define accept ACCEPT_FUNC_TAOS_FORBID
|
||||
#define epoll_create EPOLL_CREATE_FUNC_TAOS_FORBID
|
||||
#define epoll_ctl EPOLL_CTL_FUNC_TAOS_FORBID
|
||||
#define epoll_wait EPOLL_WAIT_FUNC_TAOS_FORBID
|
||||
#define inet_addr INET_ADDR_FUNC_TAOS_FORBID
|
||||
#define inet_ntoa INET_NTOA_FUNC_TAOS_FORBID
|
||||
#endif
|
||||
|
||||
#if defined(WINDOWS)
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
#include <stdlib.h>
|
||||
#define htobe16(x) _byteswap_ushort(x)
|
||||
#define htole16(x) (x)
|
||||
#define be16toh(x) _byteswap_ushort(x)
|
||||
#define le16toh(x) (x)
|
||||
|
||||
#define htobe32(x) _byteswap_ulong(x)
|
||||
#define htole32(x) (x)
|
||||
#define be32toh(x) _byteswap_ulong(x)
|
||||
#define le32toh(x) (x)
|
||||
|
||||
#define htobe64(x) _byteswap_uint64(x)
|
||||
#define htole64(x) (x)
|
||||
#define be64toh(x) _byteswap_uint64(x)
|
||||
#define le64toh(x) (x)
|
||||
#else
|
||||
#error byte order not supported
|
||||
#endif
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
#include <stdlib.h>
|
||||
#define htobe16(x) _byteswap_ushort(x)
|
||||
#define htole16(x) (x)
|
||||
#define be16toh(x) _byteswap_ushort(x)
|
||||
#define le16toh(x) (x)
|
||||
|
||||
#define __BYTE_ORDER BYTE_ORDER
|
||||
#define __BIG_ENDIAN BIG_ENDIAN
|
||||
#define __LITTLE_ENDIAN LITTLE_ENDIAN
|
||||
#define __PDP_ENDIAN PDP_ENDIAN
|
||||
#define htobe32(x) _byteswap_ulong(x)
|
||||
#define htole32(x) (x)
|
||||
#define be32toh(x) _byteswap_ulong(x)
|
||||
#define le32toh(x) (x)
|
||||
|
||||
#define htobe64(x) _byteswap_uint64(x)
|
||||
#define htole64(x) (x)
|
||||
#define be64toh(x) _byteswap_uint64(x)
|
||||
#define le64toh(x) (x)
|
||||
#else
|
||||
#error byte order not supported
|
||||
#endif
|
||||
|
||||
#define __BYTE_ORDER BYTE_ORDER
|
||||
#define __BIG_ENDIAN BIG_ENDIAN
|
||||
#define __LITTLE_ENDIAN LITTLE_ENDIAN
|
||||
#define __PDP_ENDIAN PDP_ENDIAN
|
||||
|
||||
#else
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#if defined(_TD_DARWIN_64)
|
||||
#include <osEok.h>
|
||||
#else
|
||||
#include <netinet/in.h>
|
||||
#include <sys/epoll.h>
|
||||
#endif
|
||||
#if defined(_TD_DARWIN_64)
|
||||
#include <osEok.h>
|
||||
#else
|
||||
#include <netinet/in.h>
|
||||
#include <sys/epoll.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -73,24 +73,24 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#if defined(WINDOWS)
|
||||
typedef int socklen_t;
|
||||
#define TAOS_EPOLL_WAIT_TIME 100
|
||||
typedef SOCKET eventfd_t;
|
||||
#define eventfd(a, b) -1
|
||||
#define EpollClose(pollFd) epoll_close(pollFd)
|
||||
#ifndef EPOLLWAKEUP
|
||||
#define EPOLLWAKEUP (1u << 29)
|
||||
#endif
|
||||
typedef int socklen_t;
|
||||
#define TAOS_EPOLL_WAIT_TIME 100
|
||||
typedef SOCKET eventfd_t;
|
||||
#define eventfd(a, b) -1
|
||||
#define EpollClose(pollFd) epoll_close(pollFd)
|
||||
#ifndef EPOLLWAKEUP
|
||||
#define EPOLLWAKEUP (1u << 29)
|
||||
#endif
|
||||
#elif defined(_TD_DARWIN_64)
|
||||
#define TAOS_EPOLL_WAIT_TIME 500
|
||||
typedef int32_t SOCKET;
|
||||
typedef SOCKET EpollFd;
|
||||
#define EpollClose(pollFd) epoll_close(pollFd)
|
||||
#define TAOS_EPOLL_WAIT_TIME 500
|
||||
typedef int32_t SOCKET;
|
||||
typedef SOCKET EpollFd;
|
||||
#define EpollClose(pollFd) epoll_close(pollFd)
|
||||
#else
|
||||
#define TAOS_EPOLL_WAIT_TIME 500
|
||||
typedef int32_t SOCKET;
|
||||
typedef SOCKET EpollFd;
|
||||
#define EpollClose(pollFd) taosCloseSocket(pollFd)
|
||||
#define TAOS_EPOLL_WAIT_TIME 500
|
||||
typedef int32_t SOCKET;
|
||||
typedef SOCKET EpollFd;
|
||||
#define EpollClose(pollFd) taosCloseSocket(pollFd)
|
||||
#endif
|
||||
|
||||
#if defined(_TD_DARWIN_64)
|
||||
|
@ -119,8 +119,8 @@ extern "C" {
|
|||
#define __PDP_ENDIAN PDP_ENDIAN
|
||||
#endif
|
||||
|
||||
typedef int32_t SocketFd;
|
||||
typedef SocketFd EpollFd;
|
||||
typedef int32_t SocketFd;
|
||||
typedef SocketFd EpollFd;
|
||||
|
||||
typedef struct TdSocket {
|
||||
#if SOCKET_WITH_LOCK
|
||||
|
@ -128,16 +128,17 @@ typedef struct TdSocket {
|
|||
#endif
|
||||
int refId;
|
||||
SocketFd fd;
|
||||
} *TdSocketPtr, TdSocket;
|
||||
} * TdSocketPtr, TdSocket;
|
||||
|
||||
typedef struct TdSocketServer *TdSocketServerPtr;
|
||||
typedef struct TdSocket *TdSocketPtr;
|
||||
typedef struct TdEpoll *TdEpollPtr;
|
||||
typedef struct TdSocket * TdSocketPtr;
|
||||
typedef struct TdEpoll * TdEpollPtr;
|
||||
|
||||
int32_t taosSendto(TdSocketPtr pSocket, void * msg, int len, unsigned int flags, const struct sockaddr * to, int tolen);
|
||||
int32_t taosSendto(TdSocketPtr pSocket, void *msg, int len, unsigned int flags, const struct sockaddr *to, int tolen);
|
||||
int32_t taosWriteSocket(TdSocketPtr pSocket, void *msg, int len);
|
||||
int32_t taosReadSocket(TdSocketPtr pSocket, void *msg, int len);
|
||||
int32_t taosReadFromSocket(TdSocketPtr pSocket, void *buf, int32_t len, int32_t flags, struct sockaddr *destAddr, int *addrLen);
|
||||
int32_t taosReadFromSocket(TdSocketPtr pSocket, void *buf, int32_t len, int32_t flags, struct sockaddr *destAddr,
|
||||
int *addrLen);
|
||||
int32_t taosCloseSocketNoCheck1(SocketFd fd);
|
||||
int32_t taosCloseSocket(TdSocketPtr *ppSocket);
|
||||
int32_t taosCloseSocketServer(TdSocketServerPtr *ppSocketServer);
|
||||
|
@ -154,30 +155,32 @@ int32_t taosWriteMsg(TdSocketPtr pSocket, void *ptr, int32_t nbytes);
|
|||
int32_t taosReadMsg(TdSocketPtr pSocket, void *ptr, int32_t nbytes);
|
||||
int32_t taosNonblockwrite(TdSocketPtr pSocket, char *ptr, int32_t nbytes);
|
||||
int64_t taosCopyFds(TdSocketPtr pSrcSocket, TdSocketPtr pDestSocket, int64_t len);
|
||||
void taosWinSocketInit();
|
||||
void taosWinSocketInit();
|
||||
|
||||
TdSocketPtr taosOpenUdpSocket(uint32_t localIp, uint16_t localPort);
|
||||
TdSocketPtr taosOpenTcpClientSocket(uint32_t ip, uint16_t port, uint32_t localIp);
|
||||
int taosCreateSocketWithTimeOutOpt(uint32_t conn_timeout_sec);
|
||||
|
||||
TdSocketPtr taosOpenUdpSocket(uint32_t localIp, uint16_t localPort);
|
||||
TdSocketPtr taosOpenTcpClientSocket(uint32_t ip, uint16_t port, uint32_t localIp);
|
||||
TdSocketServerPtr taosOpenTcpServerSocket(uint32_t ip, uint16_t port);
|
||||
int32_t taosKeepTcpAlive(TdSocketPtr pSocket);
|
||||
TdSocketPtr taosAcceptTcpConnectSocket(TdSocketServerPtr pServerSocket, struct sockaddr *destAddr, int *addrLen);
|
||||
int32_t taosKeepTcpAlive(TdSocketPtr pSocket);
|
||||
TdSocketPtr taosAcceptTcpConnectSocket(TdSocketServerPtr pServerSocket, struct sockaddr *destAddr, int *addrLen);
|
||||
|
||||
int32_t taosGetSocketName(TdSocketPtr pSocket,struct sockaddr *destAddr, int *addrLen);
|
||||
int32_t taosGetSocketName(TdSocketPtr pSocket, struct sockaddr *destAddr, int *addrLen);
|
||||
|
||||
void taosBlockSIGPIPE();
|
||||
uint32_t taosGetIpv4FromFqdn(const char *);
|
||||
int32_t taosGetFqdn(char *);
|
||||
void tinet_ntoa(char *ipstr, uint32_t ip);
|
||||
uint32_t ip2uint(const char *const ip_addr);
|
||||
void taosIgnSIGPIPE();
|
||||
void taosSetMaskSIGPIPE();
|
||||
uint32_t taosInetAddr(const char *ipAddr);
|
||||
void taosBlockSIGPIPE();
|
||||
uint32_t taosGetIpv4FromFqdn(const char *);
|
||||
int32_t taosGetFqdn(char *);
|
||||
void tinet_ntoa(char *ipstr, uint32_t ip);
|
||||
uint32_t ip2uint(const char *const ip_addr);
|
||||
void taosIgnSIGPIPE();
|
||||
void taosSetMaskSIGPIPE();
|
||||
uint32_t taosInetAddr(const char *ipAddr);
|
||||
const char *taosInetNtoa(struct in_addr ipInt);
|
||||
|
||||
TdEpollPtr taosCreateEpoll(int32_t size);
|
||||
int32_t taosCtlEpoll(TdEpollPtr pEpoll, int32_t epollOperate, TdSocketPtr pSocket, struct epoll_event *event);
|
||||
int32_t taosWaitEpoll(TdEpollPtr pEpoll, struct epoll_event *event, int32_t maxEvents, int32_t timeout);
|
||||
int32_t taosCloseEpoll(TdEpollPtr *ppEpoll);
|
||||
int32_t taosCtlEpoll(TdEpollPtr pEpoll, int32_t epollOperate, TdSocketPtr pSocket, struct epoll_event *event);
|
||||
int32_t taosWaitEpoll(TdEpollPtr pEpoll, struct epoll_event *event, int32_t maxEvents, int32_t timeout);
|
||||
int32_t taosCloseEpoll(TdEpollPtr *ppEpoll);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_APP_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0014)
|
||||
#define TSDB_CODE_RPC_FQDN_ERROR TAOS_DEF_ERROR_CODE(0, 0x0015)
|
||||
#define TSDB_CODE_RPC_INVALID_VERSION TAOS_DEF_ERROR_CODE(0, 0x0016)
|
||||
#define TSDB_CODE_RPC_PORT_EADDRINUSE TAOS_DEF_ERROR_CODE(0, 0x0017)
|
||||
|
||||
//common & util
|
||||
#define TSDB_CODE_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0100)
|
||||
|
@ -139,16 +140,9 @@ int32_t* taosGetErrno();
|
|||
// mnode-common
|
||||
#define TSDB_CODE_MND_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x0300)
|
||||
#define TSDB_CODE_MND_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0301)
|
||||
#define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0302)
|
||||
#define TSDB_CODE_MND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0303)
|
||||
#define TSDB_CODE_MND_ACTION_NEED_REPROCESSED TAOS_DEF_ERROR_CODE(0, 0x0304)
|
||||
#define TSDB_CODE_MND_NO_RIGHTS TAOS_DEF_ERROR_CODE(0, 0x0305)
|
||||
#define TSDB_CODE_MND_INVALID_OPTIONS TAOS_DEF_ERROR_CODE(0, 0x0306)
|
||||
#define TSDB_CODE_MND_INVALID_CONNECTION TAOS_DEF_ERROR_CODE(0, 0x0307)
|
||||
#define TSDB_CODE_MND_INVALID_MSG_VERSION TAOS_DEF_ERROR_CODE(0, 0x0308)
|
||||
#define TSDB_CODE_MND_INVALID_MSG_LEN TAOS_DEF_ERROR_CODE(0, 0x0309)
|
||||
#define TSDB_CODE_MND_INVALID_MSG_TYPE TAOS_DEF_ERROR_CODE(0, 0x030A)
|
||||
#define TSDB_CODE_MND_TOO_MANY_SHELL_CONNS TAOS_DEF_ERROR_CODE(0, 0x030B)
|
||||
#define TSDB_CODE_MND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0302)
|
||||
#define TSDB_CODE_MND_NO_RIGHTS TAOS_DEF_ERROR_CODE(0, 0x0303)
|
||||
#define TSDB_CODE_MND_INVALID_CONNECTION TAOS_DEF_ERROR_CODE(0, 0x0304)
|
||||
|
||||
// mnode-show
|
||||
#define TSDB_CODE_MND_INVALID_SHOWOBJ TAOS_DEF_ERROR_CODE(0, 0x0310)
|
||||
|
@ -275,14 +269,13 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_TOPIC_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E1)
|
||||
#define TSDB_CODE_MND_TOO_MANY_TOPICS TAOS_DEF_ERROR_CODE(0, 0x03E2)
|
||||
#define TSDB_CODE_MND_INVALID_TOPIC TAOS_DEF_ERROR_CODE(0, 0x03E3)
|
||||
#define TSDB_CODE_MND_INVALID_TOPIC_OPTION TAOS_DEF_ERROR_CODE(0, 0x03E4)
|
||||
#define TSDB_CODE_MND_TOPIC_OPTION_UNCHNAGED TAOS_DEF_ERROR_CODE(0, 0x03E5)
|
||||
#define TSDB_CODE_MND_NAME_CONFLICT_WITH_STB TAOS_DEF_ERROR_CODE(0, 0x03E6)
|
||||
#define TSDB_CODE_MND_CONSUMER_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E7)
|
||||
#define TSDB_CODE_MND_UNSUPPORTED_TOPIC TAOS_DEF_ERROR_CODE(0, 0x03E8)
|
||||
#define TSDB_CODE_MND_SUBSCRIBE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E9)
|
||||
#define TSDB_CODE_MND_OFFSET_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03EA)
|
||||
#define TSDB_CODE_MND_CONSUMER_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x03EB)
|
||||
#define TSDB_CODE_MND_INVALID_TOPIC_QUERY TAOS_DEF_ERROR_CODE(0, 0x03E4)
|
||||
#define TSDB_CODE_MND_INVALID_TOPIC_OPTION TAOS_DEF_ERROR_CODE(0, 0x03E5)
|
||||
#define TSDB_CODE_MND_CONSUMER_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E6)
|
||||
#define TSDB_CODE_MND_TOPIC_OPTION_UNCHNAGED TAOS_DEF_ERROR_CODE(0, 0x03E7)
|
||||
#define TSDB_CODE_MND_SUBSCRIBE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E8)
|
||||
#define TSDB_CODE_MND_OFFSET_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E9)
|
||||
#define TSDB_CODE_MND_CONSUMER_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x03EA)
|
||||
|
||||
// mnode-stream
|
||||
#define TSDB_CODE_MND_STREAM_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03F0)
|
||||
|
|
|
@ -205,7 +205,6 @@ SArray* taosArrayDup(const SArray* pSrc);
|
|||
*/
|
||||
SArray* taosArrayDeepCopy(const SArray* pSrc, FCopy deepCopy);
|
||||
|
||||
|
||||
/**
|
||||
* clear the array (remove all element)
|
||||
* @param pArray
|
||||
|
@ -272,6 +271,8 @@ void taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void* par
|
|||
int32_t taosEncodeArray(void** buf, const SArray* pArray, FEncode encode);
|
||||
void* taosDecodeArray(const void* buf, SArray** pArray, FDecode decode, int32_t dataSz);
|
||||
|
||||
char* taosShowStrArray(const SArray* pArray);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -125,12 +125,13 @@ extern const int32_t TYPE_BYTES[15];
|
|||
#define TSDB_INS_TABLE_QUERIES "queries"
|
||||
#define TSDB_INS_TABLE_VNODES "vnodes"
|
||||
|
||||
#define TSDB_PERFORMANCE_SCHEMA_DB "performance_schema"
|
||||
#define TSDB_PERFS_TABLE_CONNECTIONS "connections"
|
||||
#define TSDB_PERFS_TABLE_QUERIES "queries"
|
||||
#define TSDB_PERFS_TABLE_TOPICS "topics"
|
||||
#define TSDB_PERFS_TABLE_CONSUMERS "consumers"
|
||||
#define TSDB_PERFS_TABLE_SUBSCRIBES "subscribes"
|
||||
#define TSDB_PERFORMANCE_SCHEMA_DB "performance_schema"
|
||||
#define TSDB_PERFS_TABLE_CONNECTIONS "connections"
|
||||
#define TSDB_PERFS_TABLE_QUERIES "queries"
|
||||
#define TSDB_PERFS_TABLE_TOPICS "topics"
|
||||
#define TSDB_PERFS_TABLE_CONSUMERS "consumers"
|
||||
#define TSDB_PERFS_TABLE_SUBSCRIPTIONS "subscriptions"
|
||||
#define TSDB_PERFS_TABLE_OFFSETS "offsets"
|
||||
|
||||
#define TSDB_INDEX_TYPE_SMA "SMA"
|
||||
#define TSDB_INDEX_TYPE_FULLTEXT "FULLTEXT"
|
||||
|
@ -195,6 +196,8 @@ typedef enum EOperatorType {
|
|||
OP_TYPE_JSON_CONTAINS
|
||||
} EOperatorType;
|
||||
|
||||
#define OP_TYPE_CALC_MAX OP_TYPE_BIT_OR
|
||||
|
||||
typedef enum ELogicConditionType {
|
||||
LOGIC_COND_TYPE_AND = 1,
|
||||
LOGIC_COND_TYPE_OR,
|
||||
|
@ -270,7 +273,7 @@ typedef enum ELogicConditionType {
|
|||
#define TSDB_MAX_TAGS 128
|
||||
#define TSDB_MAX_TAG_CONDITIONS 1024
|
||||
|
||||
#define TSDB_MAX_JSON_TAG_LEN 16384
|
||||
#define TSDB_MAX_JSON_TAG_LEN 16384
|
||||
|
||||
#define TSDB_AUTH_LEN 16
|
||||
#define TSDB_PASSWORD_LEN 32
|
||||
|
@ -284,8 +287,9 @@ typedef enum ELogicConditionType {
|
|||
#define TSDB_IPv4ADDR_LEN 16
|
||||
#define TSDB_FILENAME_LEN 128
|
||||
#define TSDB_SHOW_SQL_LEN 512
|
||||
#define TSDB_SHOW_SUBQUERY_LEN 1000
|
||||
#define TSDB_SLOW_QUERY_SQL_LEN 512
|
||||
#define TSDB_SHOW_SUBQUERY_LEN 1000
|
||||
#define TSDB_SHOW_LIST_LEN 1000
|
||||
|
||||
#define TSDB_TRANS_STAGE_LEN 12
|
||||
#define TSDB_TRANS_TYPE_LEN 16
|
||||
|
@ -372,7 +376,7 @@ typedef enum ELogicConditionType {
|
|||
#define TSDB_DB_STREAM_MODE_OFF 0
|
||||
#define TSDB_DB_STREAM_MODE_ON 1
|
||||
#define TSDB_DEFAULT_DB_STREAM_MODE 0
|
||||
#define TSDB_DB_SINGLE_STABLE_ON 0
|
||||
#define TSDB_DB_SINGLE_STABLE_ON 0
|
||||
#define TSDB_DB_SINGLE_STABLE_OFF 1
|
||||
#define TSDB_DEFAULT_DB_SINGLE_STABLE 0
|
||||
|
||||
|
|
|
@ -17,7 +17,8 @@
|
|||
#define _TD_UTIL_ENCODE_H_
|
||||
|
||||
#include "tcoding.h"
|
||||
#include "tfreelist.h"
|
||||
#include "tlist.h"
|
||||
// #include "tfreelist.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -62,10 +63,14 @@ struct SCoderNode {
|
|||
CODER_NODE_FIELDS
|
||||
};
|
||||
|
||||
typedef struct SCoderMem {
|
||||
struct SCoderMem* next;
|
||||
} SCoderMem;
|
||||
|
||||
typedef struct {
|
||||
td_coder_t type;
|
||||
td_endian_t endian;
|
||||
SFreeList fl;
|
||||
SCoderMem* mList;
|
||||
CODER_NODE_FIELDS
|
||||
TD_SLIST(SCoderNode) stack;
|
||||
} SCoder;
|
||||
|
@ -74,7 +79,52 @@ typedef struct {
|
|||
#define TD_CODER_CURRENT(CODER) ((CODER)->data + (CODER)->pos)
|
||||
#define TD_CODER_MOVE_POS(CODER, MOVE) ((CODER)->pos += (MOVE))
|
||||
#define TD_CODER_CHECK_CAPACITY_FAILED(CODER, EXPSIZE) (((CODER)->size - (CODER)->pos) < (EXPSIZE))
|
||||
#define TCODER_MALLOC(PTR, TYPE, SIZE, CODER) TFL_MALLOC(PTR, TYPE, SIZE, &((CODER)->fl))
|
||||
// #define TCODER_MALLOC(PCODER, SIZE) \
|
||||
// ({ \
|
||||
// void* ptr = NULL; \
|
||||
// SCoderMem* pMem = (SCoderMem*)taosMemoryMalloc(sizeof(*pMem) + (SIZE)); \
|
||||
// if (pMem) { \
|
||||
// pMem->next = (PCODER)->mList; \
|
||||
// (PCODER)->mList = pMem; \
|
||||
// ptr = (void*)&pMem[1]; \
|
||||
// } \
|
||||
// ptr; \
|
||||
// })
|
||||
static FORCE_INLINE void* tCoderMalloc(SCoder* pCoder, int32_t size) {
|
||||
void* ptr = NULL;
|
||||
SCoderMem* pMem = (SCoderMem*)taosMemoryMalloc(sizeof(SCoderMem*) + size);
|
||||
if (pMem) {
|
||||
pMem->next = pCoder->mList;
|
||||
pCoder->mList = pMem;
|
||||
ptr = (void*)&pMem[1];
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#define tEncodeSize(E, S, SIZE, RET) \
|
||||
do{ \
|
||||
SCoder coder = {0}; \
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, NULL, 0, TD_ENCODER); \
|
||||
if ((E)(&coder, S) == 0) { \
|
||||
SIZE = coder.pos; \
|
||||
} else { \
|
||||
RET = -1; \
|
||||
} \
|
||||
tCoderClear(&coder); \
|
||||
}while(0)
|
||||
// #define tEncodeSize(E, S, SIZE) \
|
||||
// ({ \
|
||||
// SCoder coder = {0}; \
|
||||
// int ret = 0; \
|
||||
// tCoderInit(&coder, TD_LITTLE_ENDIAN, NULL, 0, TD_ENCODER); \
|
||||
// if ((E)(&coder, S) == 0) { \
|
||||
// SIZE = coder.pos; \
|
||||
// } else { \
|
||||
// ret = -1; \
|
||||
// } \
|
||||
// tCoderClear(&coder); \
|
||||
// ret; \
|
||||
// })
|
||||
|
||||
void tCoderInit(SCoder* pCoder, td_endian_t endian, uint8_t* data, int32_t size, td_coder_t type);
|
||||
void tCoderClear(SCoder* pCoder);
|
||||
|
@ -377,7 +427,9 @@ static FORCE_INLINE int32_t tDecodeBinary(SCoder* pDecoder, const void** val, ui
|
|||
if (tDecodeU64v(pDecoder, len) < 0) return -1;
|
||||
|
||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, *len)) return -1;
|
||||
*val = (void*)TD_CODER_CURRENT(pDecoder);
|
||||
if (val) {
|
||||
*val = (void*)TD_CODER_CURRENT(pDecoder);
|
||||
}
|
||||
|
||||
TD_CODER_MOVE_POS(pDecoder, *len);
|
||||
return 0;
|
||||
|
|
|
@ -59,6 +59,7 @@ extern int32_t sDebugFlag;
|
|||
extern int32_t tsdbDebugFlag;
|
||||
extern int32_t tqDebugFlag;
|
||||
extern int32_t fsDebugFlag;
|
||||
extern int32_t metaDebugFlag;
|
||||
extern int32_t fnDebugFlag;
|
||||
|
||||
int32_t taosInitLog(const char *logName, int32_t maxFiles);
|
||||
|
@ -79,6 +80,7 @@ void taosPrintLongString(const char *flags, ELogLevel level, int32_t dflag, cons
|
|||
#endif
|
||||
;
|
||||
|
||||
// clang-format off
|
||||
#define uFatal(...) { if (uDebugFlag & DEBUG_FATAL) { taosPrintLog("UTL FATAL", DEBUG_FATAL, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||
#define uError(...) { if (uDebugFlag & DEBUG_ERROR) { taosPrintLog("UTL ERROR ", DEBUG_ERROR, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||
#define uWarn(...) { if (uDebugFlag & DEBUG_WARN) { taosPrintLog("UTL WARN ", DEBUG_WARN, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||
|
@ -88,6 +90,7 @@ void taosPrintLongString(const char *flags, ELogLevel level, int32_t dflag, cons
|
|||
|
||||
#define pError(...) { taosPrintLog("APP ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }
|
||||
#define pPrint(...) { taosPrintLog("APP ", DEBUG_INFO, 255, __VA_ARGS__); }
|
||||
// clang-format on
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
aux_source_directory(src CLIENT_SRC)
|
||||
add_library(taos SHARED ${CLIENT_SRC})
|
||||
if(TD_WINDOWS)
|
||||
add_library(taos SHARED ${CLIENT_SRC} ${CMAKE_CURRENT_SOURCE_DIR}/src/taos.rc.in)
|
||||
else()
|
||||
add_library(taos SHARED ${CLIENT_SRC})
|
||||
endif ()
|
||||
target_include_directories(
|
||||
taos
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/client"
|
||||
|
@ -10,6 +14,13 @@ target_link_libraries(
|
|||
INTERFACE api
|
||||
PRIVATE os util common transport nodes parser command planner catalog scheduler function qcom
|
||||
)
|
||||
if(TD_WINDOWS)
|
||||
set_target_properties(taos
|
||||
PROPERTIES
|
||||
LINK_FLAGS
|
||||
/DEF:${CMAKE_CURRENT_SOURCE_DIR}/src/taos.def
|
||||
)
|
||||
endif ()
|
||||
|
||||
set_target_properties(
|
||||
taos
|
||||
|
|
|
@ -254,8 +254,6 @@ extern int (*handleRequestRspFp[TDMT_MAX])(void*, const SDataBuf* pMsg, int32_t
|
|||
int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code);
|
||||
SMsgSendInfo* buildMsgInfoImpl(SRequestObj* pReqObj);
|
||||
|
||||
int taos_init();
|
||||
|
||||
void* createTscObj(const char* user, const char* auth, const char* db, SAppInstInfo* pAppInfo);
|
||||
void destroyTscObj(void* pObj);
|
||||
STscObj* acquireTscObj(int64_t rid);
|
||||
|
@ -310,6 +308,9 @@ int hbAddConnInfo(SAppHbMgr* pAppHbMgr, SClientHbKey connKey, void* key, void* v
|
|||
void hbMgrInitMqHbRspHandle();
|
||||
|
||||
SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, int32_t code, bool keepQuery);
|
||||
int32_t getQueryPlan(SRequestObj* pRequest, SQuery* pQuery, SArray** pNodeList);
|
||||
int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -34,8 +34,7 @@ typedef enum {
|
|||
STMT_PREPARE,
|
||||
STMT_SETTBNAME,
|
||||
STMT_SETTAGS,
|
||||
STMT_FETCH_TAG_FIELDS,
|
||||
STMT_FETCH_COL_FIELDS,
|
||||
STMT_FETCH_FIELDS,
|
||||
STMT_BIND,
|
||||
STMT_BIND_COL,
|
||||
STMT_ADD_BATCH,
|
||||
|
@ -75,6 +74,8 @@ typedef struct SStmtSQLInfo {
|
|||
SQuery* pQuery;
|
||||
char* sqlStr;
|
||||
int32_t sqlLen;
|
||||
SArray* nodeList;
|
||||
SQueryPlan* pQueryPlan;
|
||||
} SStmtSQLInfo;
|
||||
|
||||
typedef struct STscStmt {
|
||||
|
@ -87,6 +88,8 @@ typedef struct STscStmt {
|
|||
SStmtBindInfo bInfo;
|
||||
} STscStmt;
|
||||
|
||||
#define STMT_STATUS_NE(S) (pStmt->sql.status != STMT_##S)
|
||||
#define STMT_STATUS_EQ(S) (pStmt->sql.status == STMT_##S)
|
||||
|
||||
#define STMT_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0)
|
||||
#define STMT_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0)
|
||||
|
@ -97,14 +100,15 @@ int stmtClose(TAOS_STMT *stmt);
|
|||
int stmtExec(TAOS_STMT *stmt);
|
||||
const char *stmtErrstr(TAOS_STMT *stmt);
|
||||
int stmtAffectedRows(TAOS_STMT *stmt);
|
||||
int stmtAffectedRowsOnce(TAOS_STMT *stmt);
|
||||
int stmtPrepare(TAOS_STMT *stmt, const char *sql, unsigned long length);
|
||||
int stmtSetTbName(TAOS_STMT *stmt, const char *tbName);
|
||||
int stmtSetTbTags(TAOS_STMT *stmt, TAOS_BIND_v2 *tags);
|
||||
int stmtSetTbTags(TAOS_STMT *stmt, TAOS_MULTI_BIND *tags);
|
||||
int stmtIsInsert(TAOS_STMT *stmt, int *insert);
|
||||
int stmtGetParamNum(TAOS_STMT *stmt, int *nums);
|
||||
int stmtAddBatch(TAOS_STMT *stmt);
|
||||
TAOS_RES *stmtUseResult(TAOS_STMT *stmt);
|
||||
int stmtBindBatch(TAOS_STMT *stmt, TAOS_BIND_v2 *bind, int32_t colIdx);
|
||||
int stmtBindBatch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int32_t colIdx);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -103,6 +103,7 @@ TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass,
|
|||
|
||||
if (port) {
|
||||
epSet.epSet.eps[0].port = port;
|
||||
epSet.epSet.eps[1].port = port;
|
||||
}
|
||||
|
||||
char* key = getClusterKey(user, secretEncrypt, ip, port);
|
||||
|
@ -187,8 +188,8 @@ int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtC
|
|||
setResPrecision(&pRequest->body.resInfo, (*pQuery)->precision);
|
||||
}
|
||||
|
||||
TSWAP(pRequest->dbList, (*pQuery)->pDbList, SArray*);
|
||||
TSWAP(pRequest->tableList, (*pQuery)->pTableList, SArray*);
|
||||
TSWAP(pRequest->dbList, (*pQuery)->pDbList);
|
||||
TSWAP(pRequest->tableList, (*pQuery)->pTableList);
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -245,7 +246,12 @@ void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t
|
|||
ASSERT(pSchema != NULL && numOfCols > 0);
|
||||
|
||||
pResInfo->numOfCols = numOfCols;
|
||||
// TODO handle memory leak
|
||||
if (pResInfo->fields != NULL) {
|
||||
taosMemoryFree(pResInfo->fields);
|
||||
}
|
||||
if (pResInfo->userFields != NULL) {
|
||||
taosMemoryFree(pResInfo->userFields);
|
||||
}
|
||||
pResInfo->fields = taosMemoryCalloc(numOfCols, sizeof(TAOS_FIELD));
|
||||
pResInfo->userFields = taosMemoryCalloc(numOfCols, sizeof(TAOS_FIELD));
|
||||
|
||||
|
@ -305,6 +311,11 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList
|
|||
return pRequest->code;
|
||||
}
|
||||
|
||||
int32_t getQueryPlan(SRequestObj* pRequest, SQuery* pQuery, SArray** pNodeList) {
|
||||
*pNodeList = taosArrayInit(4, sizeof(struct SQueryNodeAddr));
|
||||
return getPlan(pRequest, pQuery, &pRequest->body.pDag, *pNodeList);
|
||||
}
|
||||
|
||||
SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, int32_t code, bool keepQuery) {
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
switch (pQuery->execMode) {
|
||||
|
@ -347,8 +358,15 @@ SRequestObj* launchQuery(STscObj* pTscObj, const char* sql, int sqlLen) {
|
|||
SQuery* pQuery = NULL;
|
||||
|
||||
int32_t code = buildRequest(pTscObj, sql, sqlLen, &pRequest);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = parseSql(pRequest, false, &pQuery, NULL);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
terrno = code;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
code = parseSql(pRequest, false, &pQuery, NULL);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pRequest->code = code;
|
||||
return pRequest;
|
||||
}
|
||||
|
||||
return launchQueryImpl(pRequest, pQuery, code, false);
|
||||
|
@ -399,7 +417,7 @@ SRequestObj* execQuery(STscObj* pTscObj, const char* sql, int sqlLen) {
|
|||
|
||||
while (retryNum++ < REQUEST_MAX_TRY_TIMES) {
|
||||
pRequest = launchQuery(pTscObj, sql, sqlLen);
|
||||
if (TSDB_CODE_SUCCESS == pRequest->code || !NEED_CLIENT_HANDLE_ERROR(pRequest->code)) {
|
||||
if (pRequest == NULL || TSDB_CODE_SUCCESS == pRequest->code || !NEED_CLIENT_HANDLE_ERROR(pRequest->code)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -603,7 +603,7 @@ int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length) {
|
|||
return stmtPrepare(stmt, sql, length);
|
||||
}
|
||||
|
||||
int taos_stmt_set_tbname_tags(TAOS_STMT *stmt, const char *name, TAOS_BIND_v2 *tags) {
|
||||
int taos_stmt_set_tbname_tags(TAOS_STMT *stmt, const char *name, TAOS_MULTI_BIND *tags) {
|
||||
if (stmt == NULL || name == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNCTION__);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
|
@ -636,7 +636,7 @@ int taos_stmt_set_sub_tbname(TAOS_STMT *stmt, const char *name) {
|
|||
return taos_stmt_set_tbname(stmt, name);
|
||||
}
|
||||
|
||||
int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_BIND_v2 *bind) {
|
||||
int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) {
|
||||
if (stmt == NULL || bind == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNCTION__);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
|
@ -652,7 +652,7 @@ int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_BIND_v2 *bind) {
|
|||
return stmtBindBatch(stmt, bind, -1);
|
||||
}
|
||||
|
||||
int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_BIND_v2 *bind) {
|
||||
int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) {
|
||||
if (stmt == NULL || bind == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNCTION__);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
|
@ -665,10 +665,18 @@ int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_BIND_v2 *bind) {
|
|||
return terrno;
|
||||
}
|
||||
|
||||
int32_t insert = 0;
|
||||
stmtIsInsert(stmt, &insert);
|
||||
if (0 == insert && bind->num > 1) {
|
||||
tscError("only one row data allowed for query");
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return stmtBindBatch(stmt, bind, -1);
|
||||
}
|
||||
|
||||
int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_BIND_v2 *bind, int colIdx) {
|
||||
int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int colIdx) {
|
||||
if (stmt == NULL || bind == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNCTION__);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
|
@ -680,6 +688,14 @@ int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_BIND_v2 *bind, int c
|
|||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
int32_t insert = 0;
|
||||
stmtIsInsert(stmt, &insert);
|
||||
if (0 == insert && bind->num > 1) {
|
||||
tscError("only one row data allowed for query");
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return stmtBindBatch(stmt, bind, colIdx);
|
||||
}
|
||||
|
@ -748,6 +764,16 @@ int taos_stmt_affected_rows(TAOS_STMT *stmt) {
|
|||
return stmtAffectedRows(stmt);
|
||||
}
|
||||
|
||||
int taos_stmt_affected_rows_once(TAOS_STMT *stmt) {
|
||||
if (stmt == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNCTION__);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return stmtAffectedRowsOnce(stmt);
|
||||
}
|
||||
|
||||
int taos_stmt_close(TAOS_STMT *stmt) {
|
||||
if (stmt == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNCTION__);
|
||||
|
|
|
@ -5,14 +5,52 @@
|
|||
#include "tdef.h"
|
||||
|
||||
int32_t stmtSwitchStatus(STscStmt* pStmt, STMT_STATUS newStatus) {
|
||||
int32_t code = 0;
|
||||
|
||||
switch (newStatus) {
|
||||
case STMT_PREPARE:
|
||||
break;
|
||||
case STMT_SETTBNAME:
|
||||
if (STMT_STATUS_EQ(INIT) || STMT_STATUS_EQ(BIND) || STMT_STATUS_EQ(BIND_COL)) {
|
||||
code = TSDB_CODE_TSC_STMT_API_ERROR;
|
||||
}
|
||||
break;
|
||||
case STMT_SETTAGS:
|
||||
if (STMT_STATUS_NE(SETTBNAME)) {
|
||||
code = TSDB_CODE_TSC_STMT_API_ERROR;
|
||||
}
|
||||
break;
|
||||
case STMT_FETCH_FIELDS:
|
||||
if (STMT_STATUS_EQ(INIT)) {
|
||||
code = TSDB_CODE_TSC_STMT_API_ERROR;
|
||||
}
|
||||
break;
|
||||
case STMT_BIND:
|
||||
if (STMT_STATUS_EQ(INIT) || STMT_STATUS_EQ(BIND_COL)) {
|
||||
code = TSDB_CODE_TSC_STMT_API_ERROR;
|
||||
}
|
||||
break;
|
||||
case STMT_BIND_COL:
|
||||
if (STMT_STATUS_EQ(INIT) || STMT_STATUS_EQ(BIND)) {
|
||||
code = TSDB_CODE_TSC_STMT_API_ERROR;
|
||||
}
|
||||
break;
|
||||
case STMT_ADD_BATCH:
|
||||
if (STMT_STATUS_NE(BIND) && STMT_STATUS_NE(BIND_COL) && STMT_STATUS_NE(FETCH_FIELDS)) {
|
||||
code = TSDB_CODE_TSC_STMT_API_ERROR;
|
||||
}
|
||||
break;
|
||||
case STMT_EXECUTE:
|
||||
if (STMT_STATUS_NE(ADD_BATCH) && STMT_STATUS_NE(FETCH_FIELDS)) {
|
||||
code = TSDB_CODE_TSC_STMT_API_ERROR;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
code = TSDB_CODE_TSC_APP_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
//STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR);
|
||||
STMT_ERR_RET(code);
|
||||
|
||||
pStmt->sql.status = newStatus;
|
||||
|
||||
|
@ -69,15 +107,10 @@ int32_t stmtCacheBlock(STscStmt *pStmt) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
uint64_t uid;
|
||||
if (TSDB_CHILD_TABLE == pStmt->bInfo.tbType) {
|
||||
uid = pStmt->bInfo.tbSuid;
|
||||
} else {
|
||||
ASSERT(TSDB_NORMAL_TABLE == pStmt->bInfo.tbType);
|
||||
uid = pStmt->bInfo.tbUid;
|
||||
}
|
||||
uint64_t uid = pStmt->bInfo.tbUid;
|
||||
uint64_t tuid = (TSDB_CHILD_TABLE == pStmt->bInfo.tbType) ? pStmt->bInfo.tbSuid : uid;
|
||||
|
||||
if (taosHashGet(pStmt->sql.pTableCache, &uid, sizeof(uid))) {
|
||||
if (taosHashGet(pStmt->sql.pTableCache, &tuid, sizeof(tuid))) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -91,7 +124,7 @@ int32_t stmtCacheBlock(STscStmt *pStmt) {
|
|||
.boundTags = pStmt->bInfo.boundTags,
|
||||
};
|
||||
|
||||
if (taosHashPut(pStmt->sql.pTableCache, &uid, sizeof(uid), &cache, sizeof(cache))) {
|
||||
if (taosHashPut(pStmt->sql.pTableCache, &tuid, sizeof(tuid), &cache, sizeof(cache))) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
@ -149,9 +182,11 @@ int32_t stmtCleanBindInfo(STscStmt* pStmt) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t stmtCleanExecInfo(STscStmt* pStmt, bool keepTable) {
|
||||
taos_free_result(pStmt->exec.pRequest);
|
||||
pStmt->exec.pRequest = NULL;
|
||||
int32_t stmtCleanExecInfo(STscStmt* pStmt, bool keepTable, bool freeRequest) {
|
||||
if (STMT_TYPE_QUERY != pStmt->sql.type || freeRequest) {
|
||||
taos_free_result(pStmt->exec.pRequest);
|
||||
pStmt->exec.pRequest = NULL;
|
||||
}
|
||||
|
||||
void *pIter = taosHashIterate(pStmt->exec.pBlockHash, NULL);
|
||||
while (pIter) {
|
||||
|
@ -186,7 +221,9 @@ int32_t stmtCleanExecInfo(STscStmt* pStmt, bool keepTable) {
|
|||
int32_t stmtCleanSQLInfo(STscStmt* pStmt) {
|
||||
taosMemoryFree(pStmt->sql.sqlStr);
|
||||
qDestroyQuery(pStmt->sql.pQuery);
|
||||
|
||||
qDestroyQueryPlan(pStmt->sql.pQueryPlan);
|
||||
taosArrayDestroy(pStmt->sql.nodeList);
|
||||
|
||||
void *pIter = taosHashIterate(pStmt->sql.pTableCache, NULL);
|
||||
while (pIter) {
|
||||
SStmtTableCache* pCache = (SStmtTableCache*)pIter;
|
||||
|
@ -201,7 +238,7 @@ int32_t stmtCleanSQLInfo(STscStmt* pStmt) {
|
|||
|
||||
memset(&pStmt->sql, 0, sizeof(pStmt->sql));
|
||||
|
||||
STMT_ERR_RET(stmtCleanExecInfo(pStmt, false));
|
||||
STMT_ERR_RET(stmtCleanExecInfo(pStmt, false, true));
|
||||
STMT_ERR_RET(stmtCleanBindInfo(pStmt));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -333,6 +370,13 @@ int stmtSetTbName(TAOS_STMT *stmt, const char *tbName) {
|
|||
|
||||
STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_SETTBNAME));
|
||||
|
||||
int32_t insert = 0;
|
||||
stmtIsInsert(stmt, &insert);
|
||||
if (0 == insert) {
|
||||
tscError("set tb name not available for none insert statement");
|
||||
STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR);
|
||||
}
|
||||
|
||||
if (NULL == pStmt->exec.pRequest) {
|
||||
STMT_ERR_RET(buildRequest(pStmt->taos, pStmt->sql.sqlStr, pStmt->sql.sqlLen, &pStmt->exec.pRequest));
|
||||
}
|
||||
|
@ -349,7 +393,7 @@ int stmtSetTbName(TAOS_STMT *stmt, const char *tbName) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int stmtSetTbTags(TAOS_STMT *stmt, TAOS_BIND_v2 *tags) {
|
||||
int stmtSetTbTags(TAOS_STMT *stmt, TAOS_MULTI_BIND *tags) {
|
||||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
|
||||
STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_SETTAGS));
|
||||
|
@ -370,15 +414,7 @@ int stmtSetTbTags(TAOS_STMT *stmt, TAOS_BIND_v2 *tags) {
|
|||
}
|
||||
|
||||
|
||||
int32_t stmtFetchTagFields(TAOS_STMT *stmt, int32_t *fieldNum, TAOS_FIELD** fields) {
|
||||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
|
||||
STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_FETCH_TAG_FIELDS));
|
||||
|
||||
if (pStmt->bInfo.needParse) {
|
||||
STMT_ERR_RET(stmtParseSql(pStmt));
|
||||
}
|
||||
|
||||
int32_t stmtFetchTagFields(STscStmt* pStmt, int32_t *fieldNum, TAOS_FIELD** fields) {
|
||||
if (STMT_TYPE_QUERY == pStmt->sql.type) {
|
||||
tscError("invalid operation to get query tag fileds");
|
||||
STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR);
|
||||
|
@ -395,15 +431,7 @@ int32_t stmtFetchTagFields(TAOS_STMT *stmt, int32_t *fieldNum, TAOS_FIELD** fiel
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t stmtFetchColFields(TAOS_STMT *stmt, int32_t *fieldNum, TAOS_FIELD** fields) {
|
||||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
|
||||
STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_FETCH_COL_FIELDS));
|
||||
|
||||
if (pStmt->bInfo.needParse) {
|
||||
STMT_ERR_RET(stmtParseSql(pStmt));
|
||||
}
|
||||
|
||||
int32_t stmtFetchColFields(STscStmt* pStmt, int32_t *fieldNum, TAOS_FIELD** fields) {
|
||||
if (STMT_TYPE_QUERY == pStmt->sql.type) {
|
||||
tscError("invalid operation to get query column fileds");
|
||||
STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR);
|
||||
|
@ -420,7 +448,7 @@ int32_t stmtFetchColFields(TAOS_STMT *stmt, int32_t *fieldNum, TAOS_FIELD** fiel
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int stmtBindBatch(TAOS_STMT *stmt, TAOS_BIND_v2 *bind, int32_t colIdx) {
|
||||
int stmtBindBatch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int32_t colIdx) {
|
||||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
|
||||
STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_BIND));
|
||||
|
@ -429,6 +457,11 @@ int stmtBindBatch(TAOS_STMT *stmt, TAOS_BIND_v2 *bind, int32_t colIdx) {
|
|||
pStmt->bInfo.needParse = false;
|
||||
}
|
||||
|
||||
if (pStmt->exec.pRequest && STMT_TYPE_QUERY == pStmt->sql.type && pStmt->sql.runTimes) {
|
||||
taos_free_result(pStmt->exec.pRequest);
|
||||
pStmt->exec.pRequest = NULL;
|
||||
}
|
||||
|
||||
if (NULL == pStmt->exec.pRequest) {
|
||||
STMT_ERR_RET(buildRequest(pStmt->taos, pStmt->sql.sqlStr, pStmt->sql.sqlLen, &pStmt->exec.pRequest));
|
||||
}
|
||||
|
@ -437,6 +470,16 @@ int stmtBindBatch(TAOS_STMT *stmt, TAOS_BIND_v2 *bind, int32_t colIdx) {
|
|||
STMT_ERR_RET(stmtParseSql(pStmt));
|
||||
}
|
||||
|
||||
if (STMT_TYPE_QUERY == pStmt->sql.type) {
|
||||
if (NULL == pStmt->sql.pQueryPlan) {
|
||||
STMT_ERR_RET(getQueryPlan(pStmt->exec.pRequest, pStmt->sql.pQuery, &pStmt->sql.nodeList));
|
||||
pStmt->sql.pQueryPlan = pStmt->exec.pRequest->body.pDag;
|
||||
pStmt->exec.pRequest->body.pDag = NULL;
|
||||
}
|
||||
|
||||
STMT_RET(qStmtBindParam(pStmt->sql.pQueryPlan, bind, colIdx));
|
||||
}
|
||||
|
||||
STableDataBlocks **pDataBlock = (STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, (const char*)&pStmt->bInfo.tbUid, sizeof(pStmt->bInfo.tbUid));
|
||||
if (NULL == pDataBlock) {
|
||||
tscError("table uid %" PRIx64 "not found in exec blockHash", pStmt->bInfo.tbUid);
|
||||
|
@ -480,10 +523,13 @@ int stmtExec(TAOS_STMT *stmt) {
|
|||
|
||||
STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_EXECUTE));
|
||||
|
||||
STMT_ERR_RET(qBuildStmtOutput(pStmt->sql.pQuery, pStmt->exec.pVgHash, pStmt->exec.pBlockHash));
|
||||
|
||||
launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, TSDB_CODE_SUCCESS, true);
|
||||
|
||||
if (STMT_TYPE_QUERY == pStmt->sql.type) {
|
||||
scheduleQuery(pStmt->exec.pRequest, pStmt->sql.pQueryPlan, pStmt->sql.nodeList);
|
||||
} else {
|
||||
STMT_ERR_RET(qBuildStmtOutput(pStmt->sql.pQuery, pStmt->exec.pVgHash, pStmt->exec.pBlockHash));
|
||||
launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, TSDB_CODE_SUCCESS, true);
|
||||
}
|
||||
|
||||
STMT_ERR_JRET(pStmt->exec.pRequest->code);
|
||||
|
||||
pStmt->exec.affectedRows = taos_affected_rows(pStmt->exec.pRequest);
|
||||
|
@ -491,7 +537,7 @@ int stmtExec(TAOS_STMT *stmt) {
|
|||
|
||||
_return:
|
||||
|
||||
stmtCleanExecInfo(pStmt, (code ? false : true));
|
||||
stmtCleanExecInfo(pStmt, (code ? false : true), false);
|
||||
|
||||
++pStmt->sql.runTimes;
|
||||
|
||||
|
@ -523,6 +569,10 @@ int stmtAffectedRows(TAOS_STMT *stmt) {
|
|||
return ((STscStmt*)stmt)->affectedRows;
|
||||
}
|
||||
|
||||
int stmtAffectedRowsOnce(TAOS_STMT *stmt) {
|
||||
return ((STscStmt*)stmt)->exec.affectedRows;
|
||||
}
|
||||
|
||||
int stmtIsInsert(TAOS_STMT *stmt, int *insert) {
|
||||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
|
||||
|
@ -536,13 +586,38 @@ int stmtIsInsert(TAOS_STMT *stmt, int *insert) {
|
|||
}
|
||||
|
||||
int stmtGetParamNum(TAOS_STMT *stmt, int *nums) {
|
||||
STMT_ERR_RET(stmtFetchColFields(stmt, nums, NULL));
|
||||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
|
||||
STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_FETCH_FIELDS));
|
||||
|
||||
if (pStmt->bInfo.needParse) {
|
||||
STMT_ERR_RET(stmtParseSql(pStmt));
|
||||
}
|
||||
|
||||
if (STMT_TYPE_QUERY == pStmt->sql.type) {
|
||||
if (NULL == pStmt->sql.pQueryPlan) {
|
||||
STMT_ERR_RET(getQueryPlan(pStmt->exec.pRequest, pStmt->sql.pQuery, &pStmt->sql.nodeList));
|
||||
pStmt->sql.pQueryPlan = pStmt->exec.pRequest->body.pDag;
|
||||
pStmt->exec.pRequest->body.pDag = NULL;
|
||||
}
|
||||
|
||||
*nums = (pStmt->sql.pQueryPlan->pPlaceholderValues) ? pStmt->sql.pQueryPlan->pPlaceholderValues->length : 0;
|
||||
} else {
|
||||
STMT_ERR_RET(stmtFetchColFields(stmt, nums, NULL));
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
TAOS_RES *stmtUseResult(TAOS_STMT *stmt) {
|
||||
return NULL;
|
||||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
|
||||
if (STMT_TYPE_QUERY != pStmt->sql.type) {
|
||||
tscError("useResult only for query statement");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pStmt->exec.pRequest;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
taos_cleanup
|
||||
taos_options
|
||||
taos_set_config
|
||||
taos_init
|
||||
taos_connect
|
||||
taos_connect_l
|
||||
taos_connect_auth
|
||||
taos_close
|
||||
taos_data_type
|
||||
taos_stmt_init
|
||||
taos_stmt_prepare
|
||||
taos_stmt_set_tbname_tags
|
||||
taos_stmt_set_tbname
|
||||
taos_stmt_set_sub_tbname
|
||||
taos_stmt_is_insert
|
||||
taos_stmt_num_params
|
||||
taos_stmt_get_param
|
||||
taos_stmt_bind_param
|
||||
taos_stmt_bind_param_batch
|
||||
taos_stmt_bind_single_param_batch
|
||||
taos_stmt_add_batch
|
||||
taos_stmt_execute
|
||||
taos_stmt_use_result
|
||||
taos_stmt_close
|
||||
taos_stmt_errstr
|
||||
taos_stmt_affected_rows
|
||||
taos_stmt_affected_rows_once
|
||||
taos_query
|
||||
taos_query_l
|
||||
taos_fetch_row
|
||||
taos_result_precision
|
||||
taos_free_result
|
||||
taos_field_count
|
||||
taos_num_fields
|
||||
taos_affected_rows
|
||||
taos_fetch_fields
|
||||
taos_select_db
|
||||
taos_print_row
|
||||
taos_stop_query
|
||||
taos_is_null
|
||||
taos_is_update_query
|
||||
taos_fetch_block
|
||||
taos_fetch_block_s
|
||||
taos_fetch_raw_block
|
||||
taos_get_column_data_offset
|
||||
taos_validate_sql
|
||||
taos_reset_current_db
|
||||
taos_fetch_lengths
|
||||
taos_result_block
|
||||
taos_get_server_info
|
||||
taos_get_client_info
|
||||
taos_errstr
|
||||
taos_errno
|
||||
taos_query_a
|
||||
taos_fetch_rows_a
|
||||
taos_subscribe
|
||||
taos_consume
|
||||
taos_unsubscribe
|
||||
taos_load_table_info
|
||||
taos_schemaless_insert
|
||||
tmq_list_new
|
||||
tmq_list_append
|
||||
tmq_list_destroy
|
||||
tmq_list_get_size
|
||||
tmq_list_to_c_array
|
||||
tmq_consumer_new
|
||||
tmq_err2str
|
||||
tmq_subscribe
|
||||
tmq_unsubscribe
|
||||
tmq_subscription
|
||||
tmq_consumer_poll
|
||||
tmq_consumer_close
|
||||
tmq_commit
|
||||
tmq_conf_new
|
||||
tmq_conf_set
|
||||
tmq_conf_destroy
|
||||
tmq_conf_set_offset_commit_cb
|
||||
tmq_get_topic_name
|
||||
tmq_get_vgroup_id
|
||||
tmq_create_stream
|
||||
taos_check_server_status
|
|
@ -0,0 +1,31 @@
|
|||
1 VERSIONINFO
|
||||
FILEVERSION ${TD_VER_NUMBER}
|
||||
PRODUCTVERSION ${TD_VER_NUMBER}
|
||||
FILEFLAGSMASK 0x17L
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x4L
|
||||
FILETYPE 0x0L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "FileDescription", "Native C Driver for TDengine"
|
||||
VALUE "FileVersion", "${TD_VER_NUMBER}"
|
||||
VALUE "InternalName", "taos.dll(${TD_VER_CPUTYPE})"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2020 TAOS Data"
|
||||
VALUE "OriginalFilename", ""
|
||||
VALUE "ProductName", "taos.dll(${TD_VER_CPUTYPE})"
|
||||
VALUE "ProductVersion", "${TD_VER_NUMBER}"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
|
@ -16,7 +16,6 @@
|
|||
#include "clientInt.h"
|
||||
#include "clientLog.h"
|
||||
#include "parser.h"
|
||||
#include "planner.h"
|
||||
#include "tdatablock.h"
|
||||
#include "tdef.h"
|
||||
#include "tglobal.h"
|
||||
|
@ -25,7 +24,14 @@
|
|||
#include "tref.h"
|
||||
#include "ttimer.h"
|
||||
|
||||
int32_t tmqAskEp(tmq_t* tmq, bool sync);
|
||||
int32_t tmqAskEp(tmq_t* tmq, bool async);
|
||||
|
||||
typedef struct {
|
||||
int8_t inited;
|
||||
tmr_h timer;
|
||||
} SMqMgmt;
|
||||
|
||||
static SMqMgmt tmqMgmt = {0};
|
||||
|
||||
typedef struct {
|
||||
int8_t tmqRspType;
|
||||
|
@ -33,9 +39,9 @@ typedef struct {
|
|||
} SMqRspWrapper;
|
||||
|
||||
typedef struct {
|
||||
int8_t tmqRspType;
|
||||
int32_t epoch;
|
||||
SMqCMGetSubEpRsp msg;
|
||||
int8_t tmqRspType;
|
||||
int32_t epoch;
|
||||
SMqAskEpRsp msg;
|
||||
} SMqAskEpRspWrapper;
|
||||
|
||||
struct tmq_list_t {
|
||||
|
@ -56,37 +62,38 @@ struct tmq_conf_t {
|
|||
int8_t autoCommit;
|
||||
int8_t resetOffset;
|
||||
uint16_t port;
|
||||
uint16_t autoCommitInterval;
|
||||
int32_t autoCommitInterval;
|
||||
char* ip;
|
||||
char* user;
|
||||
char* pass;
|
||||
char* db;
|
||||
tmq_commit_cb* commit_cb;
|
||||
tmq_commit_cb* commitCb;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int8_t inited;
|
||||
tmr_h timer;
|
||||
} SMqMgmt;
|
||||
|
||||
static SMqMgmt tmqMgmt = {0};
|
||||
|
||||
struct tmq_t {
|
||||
// conf
|
||||
char groupId[TSDB_CGROUP_LEN];
|
||||
char clientId[256];
|
||||
int8_t autoCommit;
|
||||
int64_t consumerId;
|
||||
int32_t autoCommitInterval;
|
||||
int32_t resetOffsetCfg;
|
||||
int64_t consumerId;
|
||||
tmq_commit_cb* commit_cb;
|
||||
|
||||
// status
|
||||
int8_t status;
|
||||
int8_t epStatus;
|
||||
int32_t epoch;
|
||||
#if 0
|
||||
int8_t epStatus;
|
||||
int32_t epSkipCnt;
|
||||
#endif
|
||||
int64_t pollCnt;
|
||||
|
||||
// timer
|
||||
tmr_h hbTimer;
|
||||
tmr_h reportTimer;
|
||||
tmr_h commitTimer;
|
||||
|
||||
// connection
|
||||
STscObj* pTscObj;
|
||||
|
||||
|
@ -107,8 +114,14 @@ enum {
|
|||
|
||||
enum {
|
||||
TMQ_CONSUMER_STATUS__INIT = 0,
|
||||
TMQ_CONSUMER_STATUS__SUBSCRIBED,
|
||||
TMQ_CONSUMER_STATUS__READY,
|
||||
TMQ_CONSUMER_STATUS__NO_TOPIC,
|
||||
};
|
||||
|
||||
enum {
|
||||
TMQ_DELAYED_TASK__HB = 1,
|
||||
TMQ_DELAYED_TASK__REPORT,
|
||||
TMQ_DELAYED_TASK__COMMIT,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
|
@ -150,7 +163,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
tmq_t* tmq;
|
||||
int32_t code;
|
||||
int32_t sync;
|
||||
int32_t async;
|
||||
tsem_t rspSem;
|
||||
} SMqAskEpCbParam;
|
||||
|
||||
|
@ -161,7 +174,6 @@ typedef struct {
|
|||
int32_t epoch;
|
||||
int32_t vgId;
|
||||
tsem_t rspSem;
|
||||
int32_t sync;
|
||||
} SMqPollCbParam;
|
||||
|
||||
typedef struct {
|
||||
|
@ -174,6 +186,7 @@ typedef struct {
|
|||
tmq_conf_t* tmq_conf_new() {
|
||||
tmq_conf_t* conf = taosMemoryCalloc(1, sizeof(tmq_conf_t));
|
||||
conf->autoCommit = false;
|
||||
conf->autoCommitInterval = 5000;
|
||||
conf->resetOffset = TMQ_CONF__RESET_OFFSET__EARLIEAST;
|
||||
return conf;
|
||||
}
|
||||
|
@ -280,6 +293,53 @@ static int32_t tmqMakeTopicVgKey(char* dst, const char* topicName, int32_t vg) {
|
|||
return sprintf(dst, "%s:%d", topicName, vg);
|
||||
}
|
||||
|
||||
void tmqAssignDelayedHbTask(void* param, void* tmrId) {
|
||||
tmq_t* tmq = (tmq_t*)param;
|
||||
int8_t* pTaskType = taosAllocateQitem(sizeof(int8_t));
|
||||
*pTaskType = TMQ_DELAYED_TASK__HB;
|
||||
taosWriteQitem(tmq->delayedTask, pTaskType);
|
||||
tsem_post(&tmq->rspSem);
|
||||
}
|
||||
|
||||
void tmqAssignDelayedCommitTask(void* param, void* tmrId) {
|
||||
tmq_t* tmq = (tmq_t*)param;
|
||||
int8_t* pTaskType = taosAllocateQitem(sizeof(int8_t));
|
||||
*pTaskType = TMQ_DELAYED_TASK__COMMIT;
|
||||
taosWriteQitem(tmq->delayedTask, pTaskType);
|
||||
tsem_post(&tmq->rspSem);
|
||||
}
|
||||
|
||||
void tmqAssignDelayedReportTask(void* param, void* tmrId) {
|
||||
tmq_t* tmq = (tmq_t*)param;
|
||||
int8_t* pTaskType = taosAllocateQitem(sizeof(int8_t));
|
||||
*pTaskType = TMQ_DELAYED_TASK__REPORT;
|
||||
taosWriteQitem(tmq->delayedTask, pTaskType);
|
||||
tsem_post(&tmq->rspSem);
|
||||
}
|
||||
|
||||
int32_t tmqHandleAllDelayedTask(tmq_t* tmq) {
|
||||
STaosQall* qall = taosAllocateQall();
|
||||
taosReadAllQitems(tmq->delayedTask, qall);
|
||||
while (1) {
|
||||
int8_t* pTaskType = NULL;
|
||||
taosGetQitem(qall, (void**)&pTaskType);
|
||||
if (pTaskType == NULL) break;
|
||||
|
||||
if (*pTaskType == TMQ_DELAYED_TASK__HB) {
|
||||
tmqAskEp(tmq, true);
|
||||
taosTmrReset(tmqAssignDelayedHbTask, 1000, tmq, tmqMgmt.timer, &tmq->hbTimer);
|
||||
} else if (*pTaskType == TMQ_DELAYED_TASK__COMMIT) {
|
||||
tmq_commit(tmq, NULL, true);
|
||||
taosTmrReset(tmqAssignDelayedCommitTask, tmq->autoCommitInterval, tmq, tmqMgmt.timer, &tmq->commitTimer);
|
||||
} else if (*pTaskType == TMQ_DELAYED_TASK__REPORT) {
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
}
|
||||
taosFreeQall(qall);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tmqClearUnhandleMsg(tmq_t* tmq) {
|
||||
SMqRspWrapper* msg = NULL;
|
||||
while (1) {
|
||||
|
@ -305,7 +365,6 @@ int32_t tmqSubscribeCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
SMqSubscribeCbParam* pParam = (SMqSubscribeCbParam*)param;
|
||||
pParam->rspErr = code;
|
||||
tmq_t* tmq = pParam->tmq;
|
||||
atomic_store_8(&tmq->status, TMQ_CONSUMER_STATUS__SUBSCRIBED);
|
||||
tsem_post(&pParam->rspSem);
|
||||
return 0;
|
||||
}
|
||||
|
@ -326,14 +385,16 @@ tmq_resp_err_t tmq_subscription(tmq_t* tmq, tmq_list_t** topics) {
|
|||
}
|
||||
for (int i = 0; i < taosArrayGetSize(tmq->clientTopics); i++) {
|
||||
SMqClientTopic* topic = taosArrayGetP(tmq->clientTopics, i);
|
||||
tmq_list_append(*topics, strdup(topic->topicName));
|
||||
tmq_list_append(*topics, topic->topicName);
|
||||
}
|
||||
return TMQ_RESP_ERR__SUCCESS;
|
||||
}
|
||||
|
||||
tmq_resp_err_t tmq_unsubscribe(tmq_t* tmq) {
|
||||
tmq_list_t* lst = tmq_list_new();
|
||||
return tmq_subscribe(tmq, lst);
|
||||
tmq_list_t* lst = tmq_list_new();
|
||||
tmq_resp_err_t rsp = tmq_subscribe(tmq, lst);
|
||||
tmq_list_destroy(lst);
|
||||
return rsp;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
@ -408,14 +469,15 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
|
|||
pTmq->status = TMQ_CONSUMER_STATUS__INIT;
|
||||
pTmq->pollCnt = 0;
|
||||
pTmq->epoch = 0;
|
||||
pTmq->epStatus = 0;
|
||||
pTmq->epSkipCnt = 0;
|
||||
/*pTmq->epStatus = 0;*/
|
||||
/*pTmq->epSkipCnt = 0;*/
|
||||
|
||||
// set conf
|
||||
strcpy(pTmq->clientId, conf->clientId);
|
||||
strcpy(pTmq->groupId, conf->groupId);
|
||||
pTmq->autoCommit = conf->autoCommit;
|
||||
pTmq->commit_cb = conf->commit_cb;
|
||||
pTmq->autoCommitInterval = conf->autoCommitInterval;
|
||||
pTmq->commit_cb = conf->commitCb;
|
||||
pTmq->resetOffsetCfg = conf->resetOffset;
|
||||
|
||||
// assign consumerId
|
||||
|
@ -595,22 +657,32 @@ tmq_resp_err_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
|
|||
int64_t transporterId = 0;
|
||||
asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo);
|
||||
|
||||
// avoid double free if msg is sent
|
||||
buf = NULL;
|
||||
|
||||
tsem_wait(¶m.rspSem);
|
||||
tsem_destroy(¶m.rspSem);
|
||||
|
||||
code = param.rspErr;
|
||||
if (code != 0) goto FAIL;
|
||||
|
||||
// TODO: add max retry cnt
|
||||
while (TSDB_CODE_MND_CONSUMER_NOT_READY == tmqAskEp(tmq, true)) {
|
||||
tscDebug("not ready, retry\n");
|
||||
while (TSDB_CODE_MND_CONSUMER_NOT_READY == tmqAskEp(tmq, false)) {
|
||||
tscDebug("not ready, retry");
|
||||
taosMsleep(500);
|
||||
}
|
||||
|
||||
// init hb timer
|
||||
tmq->hbTimer = taosTmrStart(tmqAssignDelayedHbTask, 1000, tmq, tmqMgmt.timer);
|
||||
|
||||
// init auto commit timer
|
||||
if (tmq->autoCommit) {
|
||||
tmq->commitTimer = taosTmrStart(tmqAssignDelayedCommitTask, tmq->autoCommitInterval, tmq, tmqMgmt.timer);
|
||||
}
|
||||
|
||||
code = 0;
|
||||
FAIL:
|
||||
if (req.topicNames != NULL) taosArrayDestroyP(req.topicNames, taosMemoryFree);
|
||||
if (code != 0) {
|
||||
if (code != 0 && buf) {
|
||||
taosMemoryFree(buf);
|
||||
}
|
||||
return code;
|
||||
|
@ -618,7 +690,7 @@ FAIL:
|
|||
|
||||
void tmq_conf_set_offset_commit_cb(tmq_conf_t* conf, tmq_commit_cb* cb) {
|
||||
//
|
||||
conf->commit_cb = cb;
|
||||
conf->commitCb = cb;
|
||||
}
|
||||
|
||||
TAOS_RES* tmq_create_stream(TAOS* taos, const char* streamName, const char* tbName, const char* sql) {
|
||||
|
@ -730,7 +802,7 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
// do not write into queue since updating epoch reset
|
||||
tscWarn("msg discard from vg %d since from earlier epoch, rsp epoch %d, current epoch %d", pParam->vgId, msgEpoch,
|
||||
tmqEpoch);
|
||||
/*tsem_post(&tmq->rspSem);*/
|
||||
tsem_post(&tmq->rspSem);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -738,25 +810,6 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
tscWarn("mismatch rsp from vg %d, epoch %d, current epoch %d", pParam->vgId, msgEpoch, tmqEpoch);
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (pParam->sync == 1) {
|
||||
/**pParam->msg = taosMemoryMalloc(sizeof(tmq_message_t));*/
|
||||
*pParam->msg = taosAllocateQitem(sizeof(tmq_message_t));
|
||||
if (*pParam->msg) {
|
||||
memcpy(*pParam->msg, pMsg->pData, sizeof(SMqRspHead));
|
||||
tDecodeSMqConsumeRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &((*pParam->msg)->consumeRsp));
|
||||
if ((*pParam->msg)->consumeRsp.numOfTopics != 0) {
|
||||
pVg->currentOffset = (*pParam->msg)->consumeRsp.rspOffset;
|
||||
}
|
||||
taosWriteQitem(tmq->mqueue, *pParam->msg);
|
||||
tsem_post(&pParam->rspSem);
|
||||
return 0;
|
||||
}
|
||||
tsem_post(&pParam->rspSem);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
SMqPollRspWrapper* pRspWrapper = taosAllocateQitem(sizeof(SMqPollRspWrapper));
|
||||
if (pRspWrapper == NULL) {
|
||||
tscWarn("msg discard from vg %d, epoch %d since out of memory", pParam->vgId, pParam->epoch);
|
||||
|
@ -775,18 +828,18 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
pRspWrapper->msg.reqOffset, pRspWrapper->msg.rspOffset);
|
||||
|
||||
taosWriteQitem(tmq->mqueue, pRspWrapper);
|
||||
/*tsem_post(&tmq->rspSem);*/
|
||||
tsem_post(&tmq->rspSem);
|
||||
|
||||
return 0;
|
||||
CREATE_MSG_FAIL:
|
||||
if (pParam->epoch == tmq->epoch) {
|
||||
atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE);
|
||||
}
|
||||
/*tsem_post(&tmq->rspSem);*/
|
||||
tsem_post(&tmq->rspSem);
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) {
|
||||
bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqAskEpRsp* pRsp) {
|
||||
/*printf("call update ep %d\n", epoch);*/
|
||||
bool set = false;
|
||||
int32_t topicNumGet = taosArrayGetSize(pRsp->topics);
|
||||
|
@ -859,6 +912,12 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) {
|
|||
if (tmq->clientTopics) taosArrayDestroy(tmq->clientTopics);
|
||||
taosHashCleanup(pHash);
|
||||
tmq->clientTopics = newTopics;
|
||||
|
||||
if (taosArrayGetSize(tmq->clientTopics) == 0)
|
||||
atomic_store_8(&tmq->status, TMQ_CONSUMER_STATUS__NO_TOPIC);
|
||||
else
|
||||
atomic_store_8(&tmq->status, TMQ_CONSUMER_STATUS__READY);
|
||||
|
||||
atomic_store_32(&tmq->epoch, epoch);
|
||||
return set;
|
||||
}
|
||||
|
@ -868,7 +927,7 @@ int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
tmq_t* tmq = pParam->tmq;
|
||||
pParam->code = code;
|
||||
if (code != 0) {
|
||||
tscError("consumer %ld get topic endpoint error, not ready, wait:%d", tmq->consumerId, pParam->sync);
|
||||
tscError("consumer %ld get topic endpoint error, not ready, wait:%d", tmq->consumerId, pParam->async);
|
||||
goto END;
|
||||
}
|
||||
|
||||
|
@ -882,15 +941,13 @@ int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
goto END;
|
||||
}
|
||||
|
||||
if (pParam->sync) {
|
||||
SMqCMGetSubEpRsp rsp;
|
||||
tDecodeSMqCMGetSubEpRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &rsp);
|
||||
if (!pParam->async) {
|
||||
SMqAskEpRsp rsp;
|
||||
tDecodeSMqAskEpRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &rsp);
|
||||
/*printf("rsp epoch %ld sz %ld\n", rsp.epoch, rsp.topics->size);*/
|
||||
/*printf("tmq epoch %ld sz %ld\n", tmq->epoch, tmq->clientTopics->size);*/
|
||||
if (tmqUpdateEp(tmq, head->epoch, &rsp)) {
|
||||
atomic_store_8(&tmq->status, TMQ_CONSUMER_STATUS__READY);
|
||||
}
|
||||
tDeleteSMqCMGetSubEpRsp(&rsp);
|
||||
tmqUpdateEp(tmq, head->epoch, &rsp);
|
||||
tDeleteSMqAskEpRsp(&rsp);
|
||||
} else {
|
||||
SMqAskEpRspWrapper* pWrapper = taosAllocateQitem(sizeof(SMqAskEpRspWrapper));
|
||||
if (pWrapper == NULL) {
|
||||
|
@ -901,23 +958,24 @@ int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
pWrapper->tmqRspType = TMQ_MSG_TYPE__EP_RSP;
|
||||
pWrapper->epoch = head->epoch;
|
||||
memcpy(&pWrapper->msg, pMsg->pData, sizeof(SMqRspHead));
|
||||
tDecodeSMqCMGetSubEpRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pWrapper->msg);
|
||||
tDecodeSMqAskEpRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pWrapper->msg);
|
||||
|
||||
taosWriteQitem(tmq->mqueue, pWrapper);
|
||||
/*tsem_post(&tmq->rspSem);*/
|
||||
tsem_post(&tmq->rspSem);
|
||||
taosMemoryFree(pParam);
|
||||
}
|
||||
|
||||
END:
|
||||
atomic_store_8(&tmq->epStatus, 0);
|
||||
if (pParam->sync) {
|
||||
/*atomic_store_8(&tmq->epStatus, 0);*/
|
||||
if (!pParam->async) {
|
||||
tsem_post(&pParam->rspSem);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tmqAskEp(tmq_t* tmq, bool sync) {
|
||||
int32_t tmqAskEp(tmq_t* tmq, bool async) {
|
||||
int32_t code = 0;
|
||||
#if 0
|
||||
int8_t epStatus = atomic_val_compare_exchange_8(&tmq->epStatus, 0, 1);
|
||||
if (epStatus == 1) {
|
||||
int32_t epSkipCnt = atomic_add_fetch_32(&tmq->epSkipCnt, 1);
|
||||
|
@ -925,11 +983,12 @@ int32_t tmqAskEp(tmq_t* tmq, bool sync) {
|
|||
if (epSkipCnt < 5000) return 0;
|
||||
}
|
||||
atomic_store_32(&tmq->epSkipCnt, 0);
|
||||
int32_t tlen = sizeof(SMqCMGetSubEpReq);
|
||||
SMqCMGetSubEpReq* req = taosMemoryMalloc(tlen);
|
||||
#endif
|
||||
int32_t tlen = sizeof(SMqAskEpReq);
|
||||
SMqAskEpReq* req = taosMemoryMalloc(tlen);
|
||||
if (req == NULL) {
|
||||
tscError("failed to malloc get subscribe ep buf");
|
||||
atomic_store_8(&tmq->epStatus, 0);
|
||||
/*atomic_store_8(&tmq->epStatus, 0);*/
|
||||
return -1;
|
||||
}
|
||||
req->consumerId = htobe64(tmq->consumerId);
|
||||
|
@ -940,11 +999,11 @@ int32_t tmqAskEp(tmq_t* tmq, bool sync) {
|
|||
if (pParam == NULL) {
|
||||
tscError("failed to malloc subscribe param");
|
||||
taosMemoryFree(req);
|
||||
atomic_store_8(&tmq->epStatus, 0);
|
||||
/*atomic_store_8(&tmq->epStatus, 0);*/
|
||||
return -1;
|
||||
}
|
||||
pParam->tmq = tmq;
|
||||
pParam->sync = sync;
|
||||
pParam->async = async;
|
||||
tsem_init(&pParam->rspSem, 0, 0);
|
||||
|
||||
SMsgSendInfo* sendInfo = taosMemoryMalloc(sizeof(SMsgSendInfo));
|
||||
|
@ -952,7 +1011,7 @@ int32_t tmqAskEp(tmq_t* tmq, bool sync) {
|
|||
tsem_destroy(&pParam->rspSem);
|
||||
taosMemoryFree(pParam);
|
||||
taosMemoryFree(req);
|
||||
atomic_store_8(&tmq->epStatus, 0);
|
||||
/*atomic_store_8(&tmq->epStatus, 0);*/
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -966,7 +1025,7 @@ int32_t tmqAskEp(tmq_t* tmq, bool sync) {
|
|||
sendInfo->requestObjRefId = 0;
|
||||
sendInfo->param = pParam;
|
||||
sendInfo->fp = tmqAskEpCb;
|
||||
sendInfo->msgType = TDMT_MND_GET_SUB_EP;
|
||||
sendInfo->msgType = TDMT_MND_MQ_ASK_EP;
|
||||
|
||||
SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp);
|
||||
|
||||
|
@ -975,7 +1034,7 @@ int32_t tmqAskEp(tmq_t* tmq, bool sync) {
|
|||
int64_t transporterId = 0;
|
||||
asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo);
|
||||
|
||||
if (sync) {
|
||||
if (!async) {
|
||||
tsem_wait(&pParam->rspSem);
|
||||
code = pParam->code;
|
||||
taosMemoryFree(pParam);
|
||||
|
@ -1006,7 +1065,7 @@ tmq_resp_err_t tmq_seek(tmq_t* tmq, const tmq_topic_vgroup_t* offset) {
|
|||
return TMQ_RESP_ERR__FAIL;
|
||||
}
|
||||
|
||||
SMqPollReqV2* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t blockingTime, SMqClientTopic* pTopic, SMqClientVg* pVg) {
|
||||
SMqPollReq* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t waitTime, SMqClientTopic* pTopic, SMqClientVg* pVg) {
|
||||
int64_t reqOffset;
|
||||
if (pVg->currentOffset >= 0) {
|
||||
reqOffset = pVg->currentOffset;
|
||||
|
@ -1018,7 +1077,7 @@ SMqPollReqV2* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t blockingTime, SMqClient
|
|||
reqOffset = tmq->resetOffsetCfg;
|
||||
}
|
||||
|
||||
SMqPollReqV2* pReq = taosMemoryMalloc(sizeof(SMqPollReqV2));
|
||||
SMqPollReq* pReq = taosMemoryMalloc(sizeof(SMqPollReq));
|
||||
if (pReq == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1031,14 +1090,14 @@ SMqPollReqV2* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t blockingTime, SMqClient
|
|||
pReq->subKey[tlen] = TMQ_SEPARATOR;
|
||||
strcpy(pReq->subKey + tlen + 1, pTopic->topicName);
|
||||
|
||||
pReq->blockingTime = blockingTime;
|
||||
pReq->waitTime = waitTime;
|
||||
pReq->consumerId = tmq->consumerId;
|
||||
pReq->epoch = tmq->epoch;
|
||||
pReq->currentOffset = reqOffset;
|
||||
pReq->reqId = generateRequestId();
|
||||
|
||||
pReq->head.vgId = htonl(pVg->vgId);
|
||||
pReq->head.contLen = htonl(sizeof(SMqPollReqV2));
|
||||
pReq->head.contLen = htonl(sizeof(SMqPollReq));
|
||||
return pReq;
|
||||
}
|
||||
|
||||
|
@ -1060,7 +1119,7 @@ SMqRspObj* tmqBuildRspFromWrapper(SMqPollRspWrapper* pWrapper) {
|
|||
return pRspObj;
|
||||
}
|
||||
|
||||
int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) {
|
||||
int32_t tmqPollImpl(tmq_t* tmq, int64_t waitTime) {
|
||||
/*printf("call poll\n");*/
|
||||
for (int i = 0; i < taosArrayGetSize(tmq->clientTopics); i++) {
|
||||
SMqClientTopic* pTopic = taosArrayGet(tmq->clientTopics, i);
|
||||
|
@ -1081,17 +1140,17 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) {
|
|||
#endif
|
||||
}
|
||||
atomic_store_32(&pVg->vgSkipCnt, 0);
|
||||
SMqPollReqV2* pReq = tmqBuildConsumeReqImpl(tmq, blockingTime, pTopic, pVg);
|
||||
SMqPollReq* pReq = tmqBuildConsumeReqImpl(tmq, waitTime, pTopic, pVg);
|
||||
if (pReq == NULL) {
|
||||
atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE);
|
||||
/*tsem_post(&tmq->rspSem);*/
|
||||
tsem_post(&tmq->rspSem);
|
||||
return -1;
|
||||
}
|
||||
SMqPollCbParam* pParam = taosMemoryMalloc(sizeof(SMqPollCbParam));
|
||||
if (pParam == NULL) {
|
||||
taosMemoryFree(pReq);
|
||||
atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE);
|
||||
/*tsem_post(&tmq->rspSem);*/
|
||||
tsem_post(&tmq->rspSem);
|
||||
return -1;
|
||||
}
|
||||
pParam->tmq = tmq;
|
||||
|
@ -1099,20 +1158,19 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) {
|
|||
pParam->pTopic = pTopic;
|
||||
pParam->vgId = pVg->vgId;
|
||||
pParam->epoch = tmq->epoch;
|
||||
pParam->sync = 0;
|
||||
|
||||
SMsgSendInfo* sendInfo = taosMemoryMalloc(sizeof(SMsgSendInfo));
|
||||
if (sendInfo == NULL) {
|
||||
taosMemoryFree(pReq);
|
||||
taosMemoryFree(pParam);
|
||||
atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE);
|
||||
/*tsem_post(&tmq->rspSem);*/
|
||||
tsem_post(&tmq->rspSem);
|
||||
return -1;
|
||||
}
|
||||
|
||||
sendInfo->msgInfo = (SDataBuf){
|
||||
.pData = pReq,
|
||||
.len = sizeof(SMqPollReqV2),
|
||||
.len = sizeof(SMqPollReq),
|
||||
.handle = NULL,
|
||||
};
|
||||
sendInfo->requestId = pReq->reqId;
|
||||
|
@ -1139,7 +1197,7 @@ int32_t tmqHandleNoPollRsp(tmq_t* tmq, SMqRspWrapper* rspWrapper, bool* pReset)
|
|||
/*printf("ep %d %d\n", rspMsg->head.epoch, tmq->epoch);*/
|
||||
if (rspWrapper->epoch > atomic_load_32(&tmq->epoch)) {
|
||||
SMqAskEpRspWrapper* pEpRspWrapper = (SMqAskEpRspWrapper*)rspWrapper;
|
||||
SMqCMGetSubEpRsp* rspMsg = &pEpRspWrapper->msg;
|
||||
SMqAskEpRsp* rspMsg = &pEpRspWrapper->msg;
|
||||
tmqUpdateEp(tmq, rspWrapper->epoch, rspMsg);
|
||||
/*tmqClearUnhandleMsg(tmq);*/
|
||||
*pReset = true;
|
||||
|
@ -1152,7 +1210,7 @@ int32_t tmqHandleNoPollRsp(tmq_t* tmq, SMqRspWrapper* rspWrapper, bool* pReset)
|
|||
return 0;
|
||||
}
|
||||
|
||||
SMqRspObj* tmqHandleAllRsp(tmq_t* tmq, int64_t blockingTime, bool pollIfReset) {
|
||||
SMqRspObj* tmqHandleAllRsp(tmq_t* tmq, int64_t waitTime, bool pollIfReset) {
|
||||
while (1) {
|
||||
SMqRspWrapper* rspWrapper = NULL;
|
||||
taosGetQitem(tmq->qall, (void**)&rspWrapper);
|
||||
|
@ -1191,46 +1249,45 @@ SMqRspObj* tmqHandleAllRsp(tmq_t* tmq, int64_t blockingTime, bool pollIfReset) {
|
|||
taosFreeQitem(rspWrapper);
|
||||
if (pollIfReset && reset) {
|
||||
tscDebug("consumer %ld reset and repoll", tmq->consumerId);
|
||||
tmqPollImpl(tmq, blockingTime);
|
||||
tmqPollImpl(tmq, waitTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) {
|
||||
TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t wait_time) {
|
||||
SMqRspObj* rspObj;
|
||||
int64_t startTime = taosGetTimestampMs();
|
||||
|
||||
// TODO: put into delayed queue
|
||||
#if 0
|
||||
int8_t status = atomic_load_8(&tmq->status);
|
||||
while (0 != tmqAskEp(tmq, status != TMQ_CONSUMER_STATUS__READY)) {
|
||||
tscDebug("not ready, retry\n");
|
||||
taosSsleep(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
rspObj = tmqHandleAllRsp(tmq, blocking_time, false);
|
||||
rspObj = tmqHandleAllRsp(tmq, wait_time, false);
|
||||
if (rspObj) {
|
||||
return (TAOS_RES*)rspObj;
|
||||
}
|
||||
|
||||
// in no topic status also need process delayed task
|
||||
if (atomic_load_8(&tmq->status) == TMQ_CONSUMER_STATUS__INIT) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
tmqAskEp(tmq, false);
|
||||
tmqPollImpl(tmq, blocking_time);
|
||||
tmqHandleAllDelayedTask(tmq);
|
||||
tmqPollImpl(tmq, wait_time);
|
||||
|
||||
/*tsem_wait(&tmq->rspSem);*/
|
||||
|
||||
rspObj = tmqHandleAllRsp(tmq, blocking_time, false);
|
||||
rspObj = tmqHandleAllRsp(tmq, wait_time, false);
|
||||
if (rspObj) {
|
||||
return (TAOS_RES*)rspObj;
|
||||
}
|
||||
if (blocking_time != 0) {
|
||||
if (wait_time != 0) {
|
||||
int64_t endTime = taosGetTimestampMs();
|
||||
if (endTime - startTime > blocking_time) {
|
||||
int64_t leftTime = endTime - startTime;
|
||||
if (leftTime > wait_time) {
|
||||
tscDebug("consumer %ld (epoch %d) timeout, no rsp", tmq->consumerId, tmq->epoch);
|
||||
return NULL;
|
||||
}
|
||||
tsem_timewait(&tmq->rspSem, leftTime * 1000);
|
||||
} else {
|
||||
// use tsem_timewait instead of tsem_wait to avoid unexpected stuck
|
||||
tsem_timewait(&tmq->rspSem, 500 * 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,7 +79,11 @@ int32_t colDataGetLength(const SColumnInfoData* pColumnInfoData, int32_t numOfRo
|
|||
if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) {
|
||||
return pColumnInfoData->varmeta.length;
|
||||
} else {
|
||||
return pColumnInfoData->info.bytes * numOfRows;
|
||||
if (pColumnInfoData->info.type == TSDB_DATA_TYPE_NULL) {
|
||||
return 0;
|
||||
} else {
|
||||
return pColumnInfoData->info.bytes * numOfRows;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,22 +117,23 @@ int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, con
|
|||
int32_t type = pColumnInfoData->info.type;
|
||||
if (IS_VAR_DATA_TYPE(type)) {
|
||||
int32_t dataLen = varDataTLen(pData);
|
||||
if(type == TSDB_DATA_TYPE_JSON) {
|
||||
if(*pData == TSDB_DATA_TYPE_NULL) {
|
||||
if (type == TSDB_DATA_TYPE_JSON) {
|
||||
if (*pData == TSDB_DATA_TYPE_NULL) {
|
||||
dataLen = 0;
|
||||
}else if(*pData == TSDB_DATA_TYPE_NCHAR) {
|
||||
dataLen = varDataTLen(pData+CHAR_BYTES);
|
||||
}else if(*pData == TSDB_DATA_TYPE_BIGINT || *pData == TSDB_DATA_TYPE_DOUBLE) {
|
||||
} else if (*pData == TSDB_DATA_TYPE_NCHAR) {
|
||||
dataLen = varDataTLen(pData + CHAR_BYTES);
|
||||
} else if (*pData == TSDB_DATA_TYPE_BIGINT || *pData == TSDB_DATA_TYPE_DOUBLE) {
|
||||
dataLen = LONG_BYTES;
|
||||
}else if(*pData == TSDB_DATA_TYPE_BOOL) {
|
||||
} else if (*pData == TSDB_DATA_TYPE_BOOL) {
|
||||
dataLen = CHAR_BYTES;
|
||||
}
|
||||
dataLen += CHAR_BYTES;
|
||||
}
|
||||
|
||||
SVarColAttr* pAttr = &pColumnInfoData->varmeta;
|
||||
if (pAttr->allocLen < pAttr->length + dataLen) {
|
||||
uint32_t newSize = pAttr->allocLen;
|
||||
if (newSize == 0) {
|
||||
if (newSize <= 1) {
|
||||
newSize = 8;
|
||||
}
|
||||
|
||||
|
@ -307,6 +312,8 @@ int32_t colDataAssign(SColumnInfoData* pColumnInfoData, const SColumnInfoData* p
|
|||
memcpy(pColumnInfoData->pData, pSource->pData, pSource->info.bytes * numOfRows);
|
||||
}
|
||||
|
||||
pColumnInfoData->hasNull = pSource->hasNull;
|
||||
pColumnInfoData->info = pSource->info;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ STSRow *tGetSubmitBlkNext(SSubmitBlkIter *pIter) {
|
|||
return row;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
|
||||
// TODO: KEEP one suite of iterator API finally.
|
||||
// 1) use tInitSubmitMsgIterEx firstly as not decrease the merge conflicts
|
||||
// 2) replace tInitSubmitMsgIterEx with tInitSubmitMsgIter later
|
||||
|
@ -173,7 +173,7 @@ STSRow *tGetSubmitBlkNextEx(SSubmitBlkIter *pIter) {
|
|||
return row;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t tEncodeSEpSet(SCoder *pEncoder, const SEpSet *pEp) {
|
||||
if (tEncodeI8(pEncoder, pEp->inUse) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pEp->numOfEps) < 0) return -1;
|
||||
|
@ -490,181 +490,6 @@ int32_t tDeserializeSClientHbBatchRsp(void *buf, int32_t bufLen, SClientHbBatchR
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) {
|
||||
int32_t tlen = 0;
|
||||
|
||||
tlen += taosEncodeString(buf, pReq->name);
|
||||
tlen += taosEncodeFixedU32(buf, pReq->ttl);
|
||||
tlen += taosEncodeFixedU32(buf, pReq->keep);
|
||||
tlen += taosEncodeFixedU8(buf, pReq->info);
|
||||
|
||||
switch (pReq->type) {
|
||||
case TD_SUPER_TABLE:
|
||||
tlen += taosEncodeFixedI64(buf, pReq->stbCfg.suid);
|
||||
tlen += taosEncodeFixedI16(buf, pReq->stbCfg.nCols);
|
||||
tlen += taosEncodeFixedI16(buf, pReq->stbCfg.nBSmaCols);
|
||||
for (col_id_t i = 0; i < pReq->stbCfg.nCols; ++i) {
|
||||
tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pSchema[i].type);
|
||||
tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pSchema[i].flags);
|
||||
tlen += taosEncodeFixedI16(buf, pReq->stbCfg.pSchema[i].colId);
|
||||
tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pSchema[i].bytes);
|
||||
tlen += taosEncodeString(buf, pReq->stbCfg.pSchema[i].name);
|
||||
}
|
||||
tlen += taosEncodeFixedI16(buf, pReq->stbCfg.nTagCols);
|
||||
for (col_id_t i = 0; i < pReq->stbCfg.nTagCols; ++i) {
|
||||
tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pTagSchema[i].type);
|
||||
tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pTagSchema[i].flags);
|
||||
tlen += taosEncodeFixedI16(buf, pReq->stbCfg.pTagSchema[i].colId);
|
||||
tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pTagSchema[i].bytes);
|
||||
tlen += taosEncodeString(buf, pReq->stbCfg.pTagSchema[i].name);
|
||||
}
|
||||
if (pReq->rollup && pReq->stbCfg.pRSmaParam) {
|
||||
SRSmaParam *param = pReq->stbCfg.pRSmaParam;
|
||||
tlen += taosEncodeBinary(buf, (const void *)¶m->xFilesFactor, sizeof(param->xFilesFactor));
|
||||
tlen += taosEncodeFixedI32(buf, param->delay);
|
||||
tlen += taosEncodeFixedI32(buf, param->qmsg1Len);
|
||||
if (param->qmsg1Len > 0) {
|
||||
tlen += taosEncodeString(buf, param->qmsg1);
|
||||
}
|
||||
|
||||
tlen += taosEncodeFixedI32(buf, param->qmsg2Len);
|
||||
if (param->qmsg2Len > 0) {
|
||||
tlen += taosEncodeString(buf, param->qmsg2);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TD_CHILD_TABLE:
|
||||
tlen += taosEncodeFixedI64(buf, pReq->ctbCfg.suid);
|
||||
tlen += tdEncodeKVRow(buf, pReq->ctbCfg.pTag);
|
||||
break;
|
||||
case TD_NORMAL_TABLE:
|
||||
tlen += taosEncodeFixedI16(buf, pReq->ntbCfg.nCols);
|
||||
tlen += taosEncodeFixedI16(buf, pReq->ntbCfg.nBSmaCols);
|
||||
for (col_id_t i = 0; i < pReq->ntbCfg.nCols; ++i) {
|
||||
tlen += taosEncodeFixedI8(buf, pReq->ntbCfg.pSchema[i].type);
|
||||
tlen += taosEncodeFixedI8(buf, pReq->ntbCfg.pSchema[i].flags);
|
||||
tlen += taosEncodeFixedI16(buf, pReq->ntbCfg.pSchema[i].colId);
|
||||
tlen += taosEncodeFixedI32(buf, pReq->ntbCfg.pSchema[i].bytes);
|
||||
tlen += taosEncodeString(buf, pReq->ntbCfg.pSchema[i].name);
|
||||
}
|
||||
if (pReq->rollup && pReq->ntbCfg.pRSmaParam) {
|
||||
SRSmaParam *param = pReq->ntbCfg.pRSmaParam;
|
||||
tlen += taosEncodeBinary(buf, (const void *)¶m->xFilesFactor, sizeof(param->xFilesFactor));
|
||||
tlen += taosEncodeFixedI32(buf, param->delay);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
return tlen;
|
||||
}
|
||||
|
||||
void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) {
|
||||
buf = taosDecodeString(buf, &(pReq->name));
|
||||
buf = taosDecodeFixedU32(buf, &(pReq->ttl));
|
||||
buf = taosDecodeFixedU32(buf, &(pReq->keep));
|
||||
buf = taosDecodeFixedU8(buf, &(pReq->info));
|
||||
|
||||
switch (pReq->type) {
|
||||
case TD_SUPER_TABLE:
|
||||
buf = taosDecodeFixedI64(buf, &(pReq->stbCfg.suid));
|
||||
buf = taosDecodeFixedI16(buf, &(pReq->stbCfg.nCols));
|
||||
buf = taosDecodeFixedI16(buf, &(pReq->stbCfg.nBSmaCols));
|
||||
pReq->stbCfg.pSchema = (SSchema *)taosMemoryMalloc(pReq->stbCfg.nCols * sizeof(SSchema));
|
||||
for (col_id_t i = 0; i < pReq->stbCfg.nCols; ++i) {
|
||||
buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pSchema[i].type));
|
||||
buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pSchema[i].flags));
|
||||
buf = taosDecodeFixedI16(buf, &(pReq->stbCfg.pSchema[i].colId));
|
||||
buf = taosDecodeFixedI32(buf, &(pReq->stbCfg.pSchema[i].bytes));
|
||||
buf = taosDecodeStringTo(buf, pReq->stbCfg.pSchema[i].name);
|
||||
}
|
||||
buf = taosDecodeFixedI16(buf, &pReq->stbCfg.nTagCols);
|
||||
pReq->stbCfg.pTagSchema = (SSchema *)taosMemoryMalloc(pReq->stbCfg.nTagCols * sizeof(SSchema));
|
||||
for (col_id_t i = 0; i < pReq->stbCfg.nTagCols; ++i) {
|
||||
buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pTagSchema[i].type));
|
||||
buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pTagSchema[i].flags));
|
||||
buf = taosDecodeFixedI16(buf, &pReq->stbCfg.pTagSchema[i].colId);
|
||||
buf = taosDecodeFixedI32(buf, &pReq->stbCfg.pTagSchema[i].bytes);
|
||||
buf = taosDecodeStringTo(buf, pReq->stbCfg.pTagSchema[i].name);
|
||||
}
|
||||
if (pReq->rollup) {
|
||||
pReq->stbCfg.pRSmaParam = (SRSmaParam *)taosMemoryCalloc(1, sizeof(SRSmaParam));
|
||||
SRSmaParam *param = pReq->stbCfg.pRSmaParam;
|
||||
buf = taosDecodeBinaryTo(buf, (void *)¶m->xFilesFactor, sizeof(param->xFilesFactor));
|
||||
buf = taosDecodeFixedI32(buf, ¶m->delay);
|
||||
buf = taosDecodeFixedI32(buf, ¶m->qmsg1Len);
|
||||
if (param->qmsg1Len > 0) {
|
||||
buf = taosDecodeString(buf, ¶m->qmsg1);
|
||||
}
|
||||
|
||||
buf = taosDecodeFixedI32(buf, ¶m->qmsg2Len);
|
||||
if (param->qmsg2Len > 0) {
|
||||
buf = taosDecodeString(buf, ¶m->qmsg2);
|
||||
}
|
||||
} else {
|
||||
pReq->stbCfg.pRSmaParam = NULL;
|
||||
}
|
||||
break;
|
||||
case TD_CHILD_TABLE:
|
||||
buf = taosDecodeFixedI64(buf, &pReq->ctbCfg.suid);
|
||||
buf = tdDecodeKVRow(buf, &pReq->ctbCfg.pTag);
|
||||
break;
|
||||
case TD_NORMAL_TABLE:
|
||||
buf = taosDecodeFixedI16(buf, &pReq->ntbCfg.nCols);
|
||||
buf = taosDecodeFixedI16(buf, &(pReq->ntbCfg.nBSmaCols));
|
||||
pReq->ntbCfg.pSchema = (SSchema *)taosMemoryMalloc(pReq->ntbCfg.nCols * sizeof(SSchema));
|
||||
for (col_id_t i = 0; i < pReq->ntbCfg.nCols; ++i) {
|
||||
buf = taosDecodeFixedI8(buf, &pReq->ntbCfg.pSchema[i].type);
|
||||
buf = taosDecodeFixedI8(buf, &pReq->ntbCfg.pSchema[i].flags);
|
||||
buf = taosDecodeFixedI16(buf, &pReq->ntbCfg.pSchema[i].colId);
|
||||
buf = taosDecodeFixedI32(buf, &pReq->ntbCfg.pSchema[i].bytes);
|
||||
buf = taosDecodeStringTo(buf, pReq->ntbCfg.pSchema[i].name);
|
||||
}
|
||||
if (pReq->rollup) {
|
||||
pReq->ntbCfg.pRSmaParam = (SRSmaParam *)taosMemoryMalloc(sizeof(SRSmaParam));
|
||||
SRSmaParam *param = pReq->ntbCfg.pRSmaParam;
|
||||
buf = taosDecodeBinaryTo(buf, (void *)¶m->xFilesFactor, sizeof(param->xFilesFactor));
|
||||
buf = taosDecodeFixedI32(buf, ¶m->delay);
|
||||
} else {
|
||||
pReq->ntbCfg.pRSmaParam = NULL;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
int32_t tSerializeSVCreateTbBatchReq(void **buf, SVCreateTbBatchReq *pReq) {
|
||||
int32_t tlen = 0;
|
||||
|
||||
tlen += taosEncodeFixedI64(buf, pReq->ver);
|
||||
tlen += taosEncodeFixedU32(buf, taosArrayGetSize(pReq->pArray));
|
||||
for (size_t i = 0; i < taosArrayGetSize(pReq->pArray); i++) {
|
||||
SVCreateTbReq *pCreateTbReq = taosArrayGet(pReq->pArray, i);
|
||||
tlen += tSerializeSVCreateTbReq(buf, pCreateTbReq);
|
||||
}
|
||||
|
||||
return tlen;
|
||||
}
|
||||
|
||||
void *tDeserializeSVCreateTbBatchReq(void *buf, SVCreateTbBatchReq *pReq) {
|
||||
uint32_t nsize = 0;
|
||||
|
||||
buf = taosDecodeFixedI64(buf, &pReq->ver);
|
||||
buf = taosDecodeFixedU32(buf, &nsize);
|
||||
pReq->pArray = taosArrayInit(nsize, sizeof(SVCreateTbReq));
|
||||
for (size_t i = 0; i < nsize; i++) {
|
||||
SVCreateTbReq req = {0};
|
||||
buf = tDeserializeSVCreateTbReq(buf, &req);
|
||||
taosArrayPush(pReq->pArray, &req);
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
int32_t tSerializeSVDropTbReq(void **buf, SVDropTbReq *pReq) {
|
||||
int32_t tlen = 0;
|
||||
tlen += taosEncodeFixedI64(buf, pReq->ver);
|
||||
|
@ -692,7 +517,6 @@ int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq
|
|||
if (tEncodeI32(&encoder, pReq->ttl) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->numOfColumns) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->numOfTags) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->numOfSmas) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->commentLen) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->ast1Len) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->ast2Len) < 0) return -1;
|
||||
|
@ -702,6 +526,7 @@ int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq
|
|||
if (tEncodeI8(&encoder, pField->type) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pField->bytes) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pField->name) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pField->flags) < 0) return -1;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pReq->numOfTags; ++i) {
|
||||
|
@ -709,13 +534,7 @@ int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq
|
|||
if (tEncodeI8(&encoder, pField->type) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pField->bytes) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pField->name) < 0) return -1;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pReq->numOfSmas; ++i) {
|
||||
SField *pField = taosArrayGet(pReq->pSmas, i);
|
||||
if (tEncodeI8(&encoder, pField->type) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pField->bytes) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pField->name) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pField->flags) < 0) return -1;
|
||||
}
|
||||
|
||||
if (pReq->commentLen > 0) {
|
||||
|
@ -746,15 +565,13 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR
|
|||
if (tDecodeI32(&decoder, &pReq->ttl) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->numOfColumns) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->numOfTags) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->numOfSmas) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->commentLen) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->ast1Len) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->ast2Len) < 0) return -1;
|
||||
|
||||
pReq->pColumns = taosArrayInit(pReq->numOfColumns, sizeof(SField));
|
||||
pReq->pTags = taosArrayInit(pReq->numOfTags, sizeof(SField));
|
||||
pReq->pSmas = taosArrayInit(pReq->numOfSmas, sizeof(SField));
|
||||
if (pReq->pColumns == NULL || pReq->pTags == NULL || pReq->pSmas == NULL) {
|
||||
if (pReq->pColumns == NULL || pReq->pTags == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
@ -764,6 +581,7 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR
|
|||
if (tDecodeI8(&decoder, &field.type) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &field.bytes) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, field.name) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &field.flags) < 0) return -1;
|
||||
if (taosArrayPush(pReq->pColumns, &field) == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
|
@ -775,23 +593,13 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR
|
|||
if (tDecodeI8(&decoder, &field.type) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &field.bytes) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, field.name) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &field.flags) < 0) return -1;
|
||||
if (taosArrayPush(pReq->pTags, &field) == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pReq->numOfSmas; ++i) {
|
||||
SField field = {0};
|
||||
if (tDecodeI8(&decoder, &field.type) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &field.bytes) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, field.name) < 0) return -1;
|
||||
if (taosArrayPush(pReq->pSmas, &field) == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (pReq->commentLen > 0) {
|
||||
pReq->comment = taosMemoryMalloc(pReq->commentLen);
|
||||
if (pReq->comment == NULL) return -1;
|
||||
|
@ -819,13 +627,11 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR
|
|||
void tFreeSMCreateStbReq(SMCreateStbReq *pReq) {
|
||||
taosArrayDestroy(pReq->pColumns);
|
||||
taosArrayDestroy(pReq->pTags);
|
||||
taosArrayDestroy(pReq->pSmas);
|
||||
taosMemoryFreeClear(pReq->comment);
|
||||
taosMemoryFreeClear(pReq->pAst1);
|
||||
taosMemoryFreeClear(pReq->pAst2);
|
||||
pReq->pColumns = NULL;
|
||||
pReq->pTags = NULL;
|
||||
pReq->pSmas = NULL;
|
||||
}
|
||||
|
||||
int32_t tSerializeSMDropStbReq(void *buf, int32_t bufLen, SMDropStbReq *pReq) {
|
||||
|
@ -1496,6 +1302,11 @@ int32_t tDeserializeSGetUserAuthRsp(void *buf, int32_t bufLen, SGetUserAuthRsp *
|
|||
return 0;
|
||||
}
|
||||
|
||||
void tFreeSGetUserAuthRsp(SGetUserAuthRsp *pRsp) {
|
||||
taosHashCleanup(pRsp->readDbs);
|
||||
taosHashCleanup(pRsp->writeDbs);
|
||||
}
|
||||
|
||||
int32_t tSerializeSCreateDropMQSBNodeReq(void *buf, int32_t bufLen, SMCreateQnodeReq *pReq) {
|
||||
SCoder encoder = {0};
|
||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
||||
|
@ -2141,7 +1952,7 @@ int32_t tDeserializeSQnodeListRsp(void *buf, int32_t bufLen, SQnodeListRsp *pRsp
|
|||
pRsp->addrsList = taosArrayInit(num, sizeof(SQueryNodeAddr));
|
||||
if (NULL == pRsp->addrsList) return -1;
|
||||
}
|
||||
|
||||
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
SQueryNodeAddr addr = {0};
|
||||
if (tDecodeSQueryNodeAddr(&decoder, &addr) < 0) return -1;
|
||||
|
@ -3420,7 +3231,7 @@ int32_t tEncodeSMqCMCommitOffsetReq(SCoder *encoder, const SMqCMCommitOffsetReq
|
|||
int32_t tDecodeSMqCMCommitOffsetReq(SCoder *decoder, SMqCMCommitOffsetReq *pReq) {
|
||||
if (tStartDecode(decoder) < 0) return -1;
|
||||
if (tDecodeI32(decoder, &pReq->num) < 0) return -1;
|
||||
TCODER_MALLOC(pReq->offsets, SMqOffset *, pReq->num * sizeof(SMqOffset), decoder);
|
||||
pReq->offsets = (SMqOffset *)tCoderMalloc(decoder, sizeof(SMqOffset) * pReq->num);
|
||||
if (pReq->offsets == NULL) return -1;
|
||||
for (int32_t i = 0; i < pReq->num; i++) {
|
||||
tDecodeSMqOffset(decoder, &pReq->offsets[i]);
|
||||
|
@ -3636,48 +3447,79 @@ int32_t tDeserializeSQueryTableRsp(void *buf, int32_t bufLen, SQueryTableRsp *pR
|
|||
}
|
||||
|
||||
int32_t tSerializeSVCreateTbBatchRsp(void *buf, int32_t bufLen, SVCreateTbBatchRsp *pRsp) {
|
||||
SCoder encoder = {0};
|
||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
||||
// SCoder encoder = {0};
|
||||
// tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (pRsp->rspList) {
|
||||
int32_t num = taosArrayGetSize(pRsp->rspList);
|
||||
if (tEncodeI32(&encoder, num) < 0) return -1;
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
SVCreateTbRsp *rsp = taosArrayGet(pRsp->rspList, i);
|
||||
if (tEncodeI32(&encoder, rsp->code) < 0) return -1;
|
||||
}
|
||||
} else {
|
||||
if (tEncodeI32(&encoder, 0) < 0) return -1;
|
||||
}
|
||||
tEndEncode(&encoder);
|
||||
// if (tStartEncode(&encoder) < 0) return -1;
|
||||
// if (pRsp->rspList) {
|
||||
// int32_t num = taosArrayGetSize(pRsp->rspList);
|
||||
// if (tEncodeI32(&encoder, num) < 0) return -1;
|
||||
// for (int32_t i = 0; i < num; ++i) {
|
||||
// SVCreateTbRsp *rsp = taosArrayGet(pRsp->rspList, i);
|
||||
// if (tEncodeI32(&encoder, rsp->code) < 0) return -1;
|
||||
// }
|
||||
// } else {
|
||||
// if (tEncodeI32(&encoder, 0) < 0) return -1;
|
||||
// }
|
||||
// tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tCoderClear(&encoder);
|
||||
return tlen;
|
||||
// int32_t tlen = encoder.pos;
|
||||
// tCoderClear(&encoder);
|
||||
// reture tlen;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSVCreateTbBatchRsp(void *buf, int32_t bufLen, SVCreateTbBatchRsp *pRsp) {
|
||||
SCoder decoder = {0};
|
||||
int32_t num = 0;
|
||||
tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
|
||||
// SCoder decoder = {0};
|
||||
// int32_t num = 0;
|
||||
// tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &num) < 0) return -1;
|
||||
if (num > 0) {
|
||||
pRsp->rspList = taosArrayInit(num, sizeof(SVCreateTbRsp));
|
||||
if (NULL == pRsp->rspList) return -1;
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
SVCreateTbRsp rsp = {0};
|
||||
if (tDecodeI32(&decoder, &rsp.code) < 0) return -1;
|
||||
if (NULL == taosArrayPush(pRsp->rspList, &rsp)) return -1;
|
||||
}
|
||||
} else {
|
||||
pRsp->rspList = NULL;
|
||||
// if (tStartDecode(&decoder) < 0) return -1;
|
||||
// if (tDecodeI32(&decoder, &num) < 0) return -1;
|
||||
// if (num > 0) {
|
||||
// pRsp->rspList = taosArrayInit(num, sizeof(SVCreateTbRsp));
|
||||
// if (NULL == pRsp->rspList) return -1;
|
||||
// for (int32_t i = 0; i < num; ++i) {
|
||||
// SVCreateTbRsp rsp = {0};
|
||||
// if (tDecodeI32(&decoder, &rsp.code) < 0) return -1;
|
||||
// if (NULL == taosArrayPush(pRsp->rspList, &rsp)) return -1;
|
||||
// }
|
||||
// } else {
|
||||
// pRsp->rspList = NULL;
|
||||
// }
|
||||
// tEndDecode(&decoder);
|
||||
|
||||
// tCoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tEncodeSVCreateTbBatchRsp(SCoder *pCoder, const SVCreateTbBatchRsp *pRsp) {
|
||||
int32_t nRsps = taosArrayGetSize(pRsp->pArray);
|
||||
SVCreateTbRsp *pCreateRsp;
|
||||
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
if (tEncodeI32v(pCoder, nRsps) < 0) return -1;
|
||||
for (int32_t i = 0; i < nRsps; i++) {
|
||||
pCreateRsp = taosArrayGet(pRsp->pArray, i);
|
||||
if (tEncodeSVCreateTbRsp(pCoder, pCreateRsp) < 0) return -1;
|
||||
}
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tCoderClear(&decoder);
|
||||
tEndEncode(pCoder);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tDecodeSVCreateTbBatchRsp(SCoder *pCoder, SVCreateTbBatchRsp *pRsp) {
|
||||
if (tStartDecode(pCoder) < 0) return -1;
|
||||
|
||||
if (tDecodeI32v(pCoder, &pRsp->nRsps) < 0) return -1;
|
||||
pRsp->pRsps = (SVCreateTbRsp *)tCoderMalloc(pCoder, sizeof(*pRsp->pRsps) * pRsp->nRsps);
|
||||
for (int32_t i = 0; i < pRsp->nRsps; i++) {
|
||||
if (tDecodeSVCreateTbRsp(pCoder, pRsp->pRsps + i) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndDecode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -3779,6 +3621,38 @@ void tFreeSCMCreateStreamReq(SCMCreateStreamReq *pReq) {
|
|||
taosMemoryFreeClear(pReq->ast);
|
||||
}
|
||||
|
||||
int tEncodeSVCreateStbReq(SCoder *pCoder, const SVCreateStbReq *pReq) {
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
if (tEncodeCStr(pCoder, pReq->name) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pReq->suid) < 0) return -1;
|
||||
if (tEncodeI8(pCoder, pReq->rollup) < 0) return -1;
|
||||
if (tEncodeSSchemaWrapper(pCoder, &pReq->schema) < 0) return -1;
|
||||
if (tEncodeSSchemaWrapper(pCoder, &pReq->schemaTag) < 0) return -1;
|
||||
// if (pReq->rollup) {
|
||||
// if (tEncodeSRSmaParam(pCoder, pReq->pRSmaParam) < 0) return -1;
|
||||
// }
|
||||
|
||||
tEndEncode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tDecodeSVCreateStbReq(SCoder *pCoder, SVCreateStbReq *pReq) {
|
||||
if (tStartDecode(pCoder) < 0) return -1;
|
||||
|
||||
if (tDecodeCStr(pCoder, &pReq->name) < 0) return -1;
|
||||
if (tDecodeI64(pCoder, &pReq->suid) < 0) return -1;
|
||||
if (tDecodeI8(pCoder, &pReq->rollup) < 0) return -1;
|
||||
if (tDecodeSSchemaWrapper(pCoder, &pReq->schema) < 0) return -1;
|
||||
if (tDecodeSSchemaWrapper(pCoder, &pReq->schemaTag) < 0) return -1;
|
||||
// if (pReq->rollup) {
|
||||
// if (tDecodeSRSmaParam(pCoder, pReq->pRSmaParam) < 0) return -1;
|
||||
// }
|
||||
|
||||
tEndDecode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
STSchema *tdGetSTSChemaFromSSChema(SSchema **pSchema, int32_t nCols) {
|
||||
STSchemaBuilder schemaBuilder = {0};
|
||||
if (tdInitTSchemaBuilder(&schemaBuilder, 0) < 0) {
|
||||
|
@ -3802,3 +3676,97 @@ STSchema *tdGetSTSChemaFromSSChema(SSchema **pSchema, int32_t nCols) {
|
|||
tdDestroyTSchemaBuilder(&schemaBuilder);
|
||||
return pNSchema;
|
||||
}
|
||||
|
||||
int tEncodeSVCreateTbReq(SCoder *pCoder, const SVCreateTbReq *pReq) {
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
if (tEncodeI64(pCoder, pReq->uid) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pReq->ctime) < 0) return -1;
|
||||
|
||||
if (tEncodeCStr(pCoder, pReq->name) < 0) return -1;
|
||||
if (tEncodeI32(pCoder, pReq->ttl) < 0) return -1;
|
||||
if (tEncodeI8(pCoder, pReq->type) < 0) return -1;
|
||||
|
||||
if (pReq->type == TSDB_CHILD_TABLE) {
|
||||
if (tEncodeI64(pCoder, pReq->ctb.suid) < 0) return -1;
|
||||
if (tEncodeBinary(pCoder, pReq->ctb.pTag, kvRowLen(pReq->ctb.pTag)) < 0) return -1;
|
||||
} else if (pReq->type == TSDB_NORMAL_TABLE) {
|
||||
if (tEncodeSSchemaWrapper(pCoder, &pReq->ntb.schema) < 0) return -1;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
tEndEncode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tDecodeSVCreateTbReq(SCoder *pCoder, SVCreateTbReq *pReq) {
|
||||
uint64_t len;
|
||||
|
||||
if (tStartDecode(pCoder) < 0) return -1;
|
||||
|
||||
if (tDecodeI64(pCoder, &pReq->uid) < 0) return -1;
|
||||
if (tDecodeI64(pCoder, &pReq->ctime) < 0) return -1;
|
||||
|
||||
if (tDecodeCStr(pCoder, &pReq->name) < 0) return -1;
|
||||
if (tDecodeI32(pCoder, &pReq->ttl) < 0) return -1;
|
||||
if (tDecodeI8(pCoder, &pReq->type) < 0) return -1;
|
||||
|
||||
if (pReq->type == TSDB_CHILD_TABLE) {
|
||||
if (tDecodeI64(pCoder, &pReq->ctb.suid) < 0) return -1;
|
||||
if (tDecodeBinary(pCoder, &pReq->ctb.pTag, &len) < 0) return -1;
|
||||
} else if (pReq->type == TSDB_NORMAL_TABLE) {
|
||||
if (tDecodeSSchemaWrapper(pCoder, &pReq->ntb.schema) < 0) return -1;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
tEndDecode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tEncodeSVCreateTbBatchReq(SCoder *pCoder, const SVCreateTbBatchReq *pReq) {
|
||||
int32_t nReq = taosArrayGetSize(pReq->pArray);
|
||||
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
if (tEncodeI32v(pCoder, nReq) < 0) return -1;
|
||||
for (int iReq = 0; iReq < nReq; iReq++) {
|
||||
if (tEncodeSVCreateTbReq(pCoder, (SVCreateTbReq *)taosArrayGet(pReq->pArray, iReq)) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndEncode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tDecodeSVCreateTbBatchReq(SCoder *pCoder, SVCreateTbBatchReq *pReq) {
|
||||
if (tStartDecode(pCoder) < 0) return -1;
|
||||
|
||||
if (tDecodeI32v(pCoder, &pReq->nReqs) < 0) return -1;
|
||||
pReq->pReqs = (SVCreateTbReq *)tCoderMalloc(pCoder, sizeof(SVCreateTbReq) * pReq->nReqs);
|
||||
if (pReq->pReqs == NULL) return -1;
|
||||
for (int iReq = 0; iReq < pReq->nReqs; iReq++) {
|
||||
if (tDecodeSVCreateTbReq(pCoder, pReq->pReqs + iReq) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndDecode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tEncodeSVCreateTbRsp(SCoder *pCoder, const SVCreateTbRsp *pRsp) {
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
if (tEncodeI32(pCoder, pRsp->code) < 0) return -1;
|
||||
|
||||
tEndEncode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tDecodeSVCreateTbRsp(SCoder *pCoder, SVCreateTbRsp *pRsp) {
|
||||
if (tStartDecode(pCoder) < 0) return -1;
|
||||
|
||||
if (tDecodeI32(pCoder, &pRsp->code) < 0) return -1;
|
||||
|
||||
tEndDecode(pCoder);
|
||||
return 0;
|
||||
}
|
|
@ -651,35 +651,35 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void *buf
|
|||
switch (type) {
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
case TSDB_DATA_TYPE_UINT: {
|
||||
TSWAP(*(int32_t *)(pLeft), *(int32_t *)(pRight), int32_t);
|
||||
TSWAP(*(int32_t *)(pLeft), *(int32_t *)(pRight));
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
case TSDB_DATA_TYPE_TIMESTAMP: {
|
||||
TSWAP(*(int64_t *)(pLeft), *(int64_t *)(pRight), int64_t);
|
||||
TSWAP(*(int64_t *)(pLeft), *(int64_t *)(pRight));
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
TSWAP(*(double *)(pLeft), *(double *)(pRight), double);
|
||||
TSWAP(*(double *)(pLeft), *(double *)(pRight));
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDB_DATA_TYPE_USMALLINT: {
|
||||
TSWAP(*(int16_t *)(pLeft), *(int16_t *)(pRight), int16_t);
|
||||
TSWAP(*(int16_t *)(pLeft), *(int16_t *)(pRight));
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
TSWAP(*(float *)(pLeft), *(float *)(pRight), float);
|
||||
TSWAP(*(float *)(pLeft), *(float *)(pRight));
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDB_DATA_TYPE_UTINYINT: {
|
||||
TSWAP(*(int8_t *)(pLeft), *(int8_t *)(pRight), int8_t);
|
||||
TSWAP(*(int8_t *)(pLeft), *(int8_t *)(pRight));
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include "tschema.h"
|
||||
|
||||
TEST(td_schema_test, build_schema_test) {
|
||||
|
||||
}
|
|
@ -17,11 +17,21 @@
|
|||
#include "dmImp.h"
|
||||
#include "tconfig.h"
|
||||
|
||||
#define DM_APOLLO_URL "The apollo string to use when configuring the server, such as: -a 'jsonFile:./tests/cfg.json', cfg.json text can be '{\"fqdn\":\"td1\"}'."
|
||||
#define DM_CFG_DIR "Configuration directory."
|
||||
#define DM_DMP_CFG "Dump configuration."
|
||||
#define DM_ENV_CMD "The env cmd variable string to use when configuring the server, such as: -e 'TAOS_FQDN=td1'."
|
||||
#define DM_ENV_FILE "The env variable file path to use when configuring the server, default is './.env', .env text can be 'TAOS_FQDN=td1'."
|
||||
#define DM_NODE_TYPE "Startup type of the node, default is 0."
|
||||
#define DM_MACHINE_CODE "Get machine code."
|
||||
#define DM_VERSION "Print program version."
|
||||
#define DM_EMAIL "<support@taosdata.com>"
|
||||
static struct {
|
||||
bool dumpConfig;
|
||||
bool generateGrant;
|
||||
bool printAuth;
|
||||
bool printVersion;
|
||||
bool printHelp;
|
||||
char envFile[PATH_MAX];
|
||||
char apolloUrl[PATH_MAX];
|
||||
const char **envCmd;
|
||||
|
@ -58,8 +68,9 @@ static void dmSetSignalHandle() {
|
|||
|
||||
static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
||||
int32_t cmdEnvIndex = 0;
|
||||
global.envCmd = taosMemoryMalloc(argc-1);
|
||||
memset(global.envCmd, 0, argc-1);
|
||||
if (argc < 2) return 0;
|
||||
global.envCmd = taosMemoryMalloc((argc-1)*sizeof(char*));
|
||||
memset(global.envCmd, 0, (argc-1)*sizeof(char*));
|
||||
for (int32_t i = 1; i < argc; ++i) {
|
||||
if (strcmp(argv[i], "-c") == 0) {
|
||||
if (i < argc - 1) {
|
||||
|
@ -91,6 +102,8 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
|||
} else if (strcmp(argv[i], "-e") == 0) {
|
||||
global.envCmd[cmdEnvIndex] = argv[++i];
|
||||
cmdEnvIndex++;
|
||||
} else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "--usage") == 0 || strcmp(argv[i], "-?")) {
|
||||
global.printHelp = true;
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
@ -111,6 +124,21 @@ static void dmPrintVersion() {
|
|||
printf("buildInfo: %s\n", buildinfo);
|
||||
}
|
||||
|
||||
static void dmPrintHelp() {
|
||||
char indent[] = " ";
|
||||
printf("Usage: taosd [OPTION...] \n\n");
|
||||
printf("%s%s%s%s\n", indent, "-a,", indent, DM_APOLLO_URL);
|
||||
printf("%s%s%s%s\n", indent, "-c,", indent, DM_CFG_DIR);
|
||||
printf("%s%s%s%s\n", indent, "-C,", indent, DM_DMP_CFG);
|
||||
printf("%s%s%s%s\n", indent, "-e,", indent, DM_ENV_CMD);
|
||||
printf("%s%s%s%s\n", indent, "-E,", indent, DM_ENV_FILE);
|
||||
printf("%s%s%s%s\n", indent, "-n,", indent, DM_NODE_TYPE);
|
||||
printf("%s%s%s%s\n", indent, "-k,", indent, DM_MACHINE_CODE);
|
||||
printf("%s%s%s%s\n", indent, "-V,", indent, DM_VERSION);
|
||||
|
||||
printf("\n\nReport bugs to %s.\n", DM_EMAIL);
|
||||
}
|
||||
|
||||
static void dmDumpCfg() {
|
||||
SConfig *pCfg = taosGetCfg();
|
||||
cfgDumpCfg(pCfg, 0, true);
|
||||
|
@ -197,6 +225,12 @@ int main(int argc, char const *argv[]) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (global.printHelp) {
|
||||
dmPrintHelp();
|
||||
taosCleanupArgs();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (global.printVersion) {
|
||||
dmPrintVersion();
|
||||
taosCleanupArgs();
|
||||
|
|
|
@ -120,7 +120,7 @@ int32_t dmReadEps(SDnode *pDnode) {
|
|||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
|
||||
dnodeEp.id = dnodeId->valueint;
|
||||
dnodeEp.id = did->valueint;
|
||||
|
||||
cJSON *dnodeFqdn = cJSON_GetObjectItem(node, "fqdn");
|
||||
if (!dnodeFqdn || dnodeFqdn->type != cJSON_String || dnodeFqdn->valuestring == NULL) {
|
||||
|
@ -156,11 +156,6 @@ PRASE_DNODE_OVER:
|
|||
if (root != NULL) cJSON_Delete(root);
|
||||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
|
||||
if (dmIsEpChanged(pDnode, pDnode->data.dnodeId, pDnode->data.localEp)) {
|
||||
dError("localEp %s different with %s and need reconfigured", pDnode->data.localEp, file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosArrayGetSize(pDnode->data.dnodeEps) == 0) {
|
||||
SDnodeEp dnodeEp = {0};
|
||||
dnodeEp.isMnode = 1;
|
||||
|
@ -170,6 +165,11 @@ PRASE_DNODE_OVER:
|
|||
|
||||
dmResetEps(pDnode, pDnode->data.dnodeEps);
|
||||
|
||||
if (dmIsEpChanged(pDnode, pDnode->data.dnodeId, pDnode->data.localEp)) {
|
||||
dError("localEp %s different with %s and need reconfigured", pDnode->data.localEp, file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
@ -291,13 +291,17 @@ static void dmPrintEps(SDnode *pDnode) {
|
|||
|
||||
static bool dmIsEpChanged(SDnode *pDnode, int32_t dnodeId, const char *ep) {
|
||||
bool changed = false;
|
||||
if (dnodeId == 0) return changed;
|
||||
taosRLockLatch(&pDnode->data.latch);
|
||||
|
||||
SDnodeEp *pDnodeEp = taosHashGet(pDnode->data.dnodeHash, &dnodeId, sizeof(int32_t));
|
||||
if (pDnodeEp != NULL) {
|
||||
char epstr[TSDB_EP_LEN + 1];
|
||||
char epstr[TSDB_EP_LEN + 1] = {0};
|
||||
snprintf(epstr, TSDB_EP_LEN, "%s:%u", pDnodeEp->ep.fqdn, pDnodeEp->ep.port);
|
||||
changed = strcmp(ep, epstr) != 0;
|
||||
changed = (strcmp(ep, epstr) != 0);
|
||||
if (changed) {
|
||||
dError("dnode:%d, localEp %s different from %s", dnodeId, ep, epstr);
|
||||
}
|
||||
}
|
||||
|
||||
taosRUnLockLatch(&pDnode->data.latch);
|
||||
|
|
|
@ -211,7 +211,7 @@ void mmInitMsgHandle(SMgmtWrapper *pWrapper) {
|
|||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_SUBSCRIBE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_MQ_COMMIT_OFFSET, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_GET_SUB_EP, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_MQ_ASK_EP, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_MQ_VG_CHANGE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_STREAM, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
|
|
|
@ -107,15 +107,13 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) {
|
|||
|
||||
pCfg->vgId = pCreate->vgId;
|
||||
strcpy(pCfg->dbname, pCreate->db);
|
||||
pCfg->wsize = pCreate->cacheBlockSize * 1024 * 1024;
|
||||
pCfg->ssize = 1024;
|
||||
pCfg->lsize = 1024 * 1024;
|
||||
pCfg->szBuf = pCreate->cacheBlockSize * 1024 * 1024;
|
||||
pCfg->streamMode = pCreate->streamMode;
|
||||
pCfg->isWeak = true;
|
||||
pCfg->tsdbCfg.keep2 = pCreate->daysToKeep0;
|
||||
pCfg->tsdbCfg.keep0 = pCreate->daysToKeep2;
|
||||
pCfg->tsdbCfg.keep1 = pCreate->daysToKeep0;
|
||||
pCfg->tsdbCfg.lruCacheSize = pCreate->cacheBlockSize;
|
||||
pCfg->tsdbCfg.days = 10;
|
||||
pCfg->tsdbCfg.keep2 = 3650; // pCreate->daysToKeep0;
|
||||
pCfg->tsdbCfg.keep0 = 3650; // pCreate->daysToKeep2;
|
||||
pCfg->tsdbCfg.keep1 = 3650; // pCreate->daysToKeep0;
|
||||
pCfg->tsdbCfg.retentions = pCreate->pRetensions;
|
||||
pCfg->walCfg.vgId = pCreate->vgId;
|
||||
pCfg->hashBegin = pCreate->hashBegin;
|
||||
|
@ -212,7 +210,6 @@ int32_t vmProcessCreateVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) {
|
|||
return code;
|
||||
}
|
||||
|
||||
|
||||
code = vmWriteVnodesToFile(pMgmt);
|
||||
if (code != 0) {
|
||||
tFreeSCreateVnodeReq(&createReq);
|
||||
|
|
|
@ -23,10 +23,8 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
enum {
|
||||
// MQ_CONSUMER_STATUS__INIT = 1,
|
||||
MQ_CONSUMER_STATUS__MODIFY = 1,
|
||||
MQ_CONSUMER_STATUS__MODIFY_IN_REB,
|
||||
// MQ_CONSUMER_STATUS__IDLE,
|
||||
MQ_CONSUMER_STATUS__READY,
|
||||
MQ_CONSUMER_STATUS__LOST,
|
||||
MQ_CONSUMER_STATUS__LOST_IN_REB,
|
||||
|
|
|
@ -89,6 +89,7 @@ typedef enum {
|
|||
TRN_TYPE_DROP_STREAM = 1020,
|
||||
TRN_TYPE_ALTER_STREAM = 1021,
|
||||
TRN_TYPE_CONSUMER_LOST = 1022,
|
||||
TRN_TYPE_CONSUMER_RECOVER = 1023,
|
||||
TRN_TYPE_BASIC_SCOPE_END,
|
||||
TRN_TYPE_GLOBAL_SCOPE = 2000,
|
||||
TRN_TYPE_CREATE_DNODE = 2001,
|
||||
|
@ -148,6 +149,10 @@ typedef struct {
|
|||
int64_t dbUid;
|
||||
char dbname[TSDB_DB_FNAME_LEN];
|
||||
char lastError[TSDB_TRANS_ERROR_LEN];
|
||||
int32_t startFunc;
|
||||
int32_t stopFunc;
|
||||
int32_t paramLen;
|
||||
void* param;
|
||||
} STrans;
|
||||
|
||||
typedef struct {
|
||||
|
@ -354,13 +359,11 @@ typedef struct {
|
|||
int32_t ttl;
|
||||
int32_t numOfColumns;
|
||||
int32_t numOfTags;
|
||||
int32_t numOfSmas;
|
||||
int32_t commentLen;
|
||||
int32_t ast1Len;
|
||||
int32_t ast2Len;
|
||||
SSchema* pColumns;
|
||||
SSchema* pTags;
|
||||
SSchema* pSmas;
|
||||
char* comment;
|
||||
char* pAst1;
|
||||
char* pAst2;
|
||||
|
@ -436,14 +439,12 @@ static FORCE_INLINE void* tDecodeSMqOffsetObj(void* buf, SMqOffsetObj* pOffset)
|
|||
}
|
||||
|
||||
typedef struct {
|
||||
char name[TSDB_TOPIC_FNAME_LEN];
|
||||
char db[TSDB_DB_FNAME_LEN];
|
||||
int64_t createTime;
|
||||
int64_t updateTime;
|
||||
int64_t uid;
|
||||
// TODO: use subDbUid
|
||||
char name[TSDB_TOPIC_FNAME_LEN];
|
||||
char db[TSDB_DB_FNAME_LEN];
|
||||
int64_t createTime;
|
||||
int64_t updateTime;
|
||||
int64_t uid;
|
||||
int64_t dbUid;
|
||||
int64_t subDbUid;
|
||||
int32_t version;
|
||||
int8_t subType; // db or table
|
||||
int8_t withTbName;
|
||||
|
@ -463,12 +464,14 @@ enum {
|
|||
CONSUMER_UPDATE__ADD,
|
||||
CONSUMER_UPDATE__REMOVE,
|
||||
CONSUMER_UPDATE__LOST,
|
||||
CONSUMER_UPDATE__RECOVER,
|
||||
CONSUMER_UPDATE__MODIFY,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int64_t consumerId;
|
||||
char cgroup[TSDB_CGROUP_LEN];
|
||||
char appId[TSDB_CGROUP_LEN];
|
||||
int8_t updateType; // used only for update
|
||||
int32_t epoch;
|
||||
int32_t status;
|
||||
|
@ -479,6 +482,17 @@ typedef struct {
|
|||
SArray* currentTopics; // SArray<char*>
|
||||
SArray* rebNewTopics; // SArray<char*>
|
||||
SArray* rebRemovedTopics; // SArray<char*>
|
||||
|
||||
// subscribed by user
|
||||
SArray* assignedTopics; // SArray<char*>
|
||||
|
||||
// data for display
|
||||
int32_t pid;
|
||||
SEpSet ep;
|
||||
int64_t upTime;
|
||||
int64_t subscribeTime;
|
||||
int64_t rebalanceTime;
|
||||
|
||||
} SMqConsumerObj;
|
||||
|
||||
SMqConsumerObj* tNewSMqConsumerObj(int64_t consumerId, char cgroup[TSDB_CGROUP_LEN]);
|
||||
|
|
|
@ -40,12 +40,12 @@ extern "C" {
|
|||
|
||||
#define SYSTABLE_SCH_TABLE_NAME_LEN ((TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
|
||||
#define SYSTABLE_SCH_DB_NAME_LEN ((TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
|
||||
#define SYSTABLE_SCH_COL_NAME_LEN ((TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
|
||||
#define SYSTABLE_SCH_COL_NAME_LEN ((TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
|
||||
|
||||
typedef int32_t (*MndMsgFp)(SNodeMsg *pMsg);
|
||||
typedef int32_t (*MndInitFp)(SMnode *pMnode);
|
||||
typedef void (*MndCleanupFp)(SMnode *pMnode);
|
||||
typedef int32_t (*ShowRetrieveFp)(SNodeMsg *pMsg, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows);
|
||||
typedef int32_t (*ShowRetrieveFp)(SNodeMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
|
||||
typedef void (*ShowFreeIterFp)(SMnode *pMnode, void *pIter);
|
||||
typedef struct SQWorkerMgmt SQHandle;
|
||||
|
||||
|
@ -84,32 +84,32 @@ typedef struct {
|
|||
int64_t timeseriesAllowed;
|
||||
} SGrantInfo;
|
||||
|
||||
struct SMnode {
|
||||
int32_t selfId;
|
||||
int64_t clusterId;
|
||||
int8_t replica;
|
||||
int8_t selfIndex;
|
||||
SReplica replicas[TSDB_MAX_REPLICA];
|
||||
tmr_h timer;
|
||||
tmr_h transTimer;
|
||||
tmr_h mqTimer;
|
||||
tmr_h telemTimer;
|
||||
char *path;
|
||||
int64_t checkTime;
|
||||
SSdb *pSdb;
|
||||
SMgmtWrapper *pWrapper;
|
||||
SArray *pSteps;
|
||||
SQHandle *pQuery;
|
||||
SShowMgmt showMgmt;
|
||||
SProfileMgmt profileMgmt;
|
||||
STelemMgmt telemMgmt;
|
||||
SSyncMgmt syncMgmt;
|
||||
SHashObj *infosMeta;
|
||||
SHashObj *perfsMeta;
|
||||
SGrantInfo grant;
|
||||
MndMsgFp msgFp[TDMT_MAX];
|
||||
SMsgCb msgCb;
|
||||
};
|
||||
typedef struct SMnode {
|
||||
int32_t selfId;
|
||||
int64_t clusterId;
|
||||
int8_t replica;
|
||||
int8_t selfIndex;
|
||||
SReplica replicas[TSDB_MAX_REPLICA];
|
||||
tmr_h timer;
|
||||
tmr_h transTimer;
|
||||
tmr_h mqTimer;
|
||||
tmr_h telemTimer;
|
||||
char *path;
|
||||
int64_t checkTime;
|
||||
SSdb *pSdb;
|
||||
SMgmtWrapper *pWrapper;
|
||||
SArray *pSteps;
|
||||
SQHandle *pQuery;
|
||||
SShowMgmt showMgmt;
|
||||
SProfileMgmt profileMgmt;
|
||||
STelemMgmt telemMgmt;
|
||||
SSyncMgmt syncMgmt;
|
||||
SHashObj *infosMeta;
|
||||
SHashObj *perfsMeta;
|
||||
SGrantInfo grant;
|
||||
MndMsgFp msgFp[TDMT_MAX];
|
||||
SMsgCb msgCb;
|
||||
} SMnode;
|
||||
|
||||
void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp);
|
||||
int64_t mndGenerateUid(char *name, int32_t len);
|
||||
|
|
|
@ -33,6 +33,15 @@ typedef struct {
|
|||
void *pCont;
|
||||
} STransAction;
|
||||
|
||||
typedef enum {
|
||||
TEST_TRANS_START_FUNC = 1,
|
||||
TEST_TRANS_STOP_FUNC = 2,
|
||||
CONSUME_TRANS_START_FUNC = 3,
|
||||
CONSUME_TRANS_STOP_FUNC = 4,
|
||||
} ETrnFuncType;
|
||||
|
||||
typedef void (*TransCbFp)(SMnode *pMnode, void *param, int32_t paramLen);
|
||||
|
||||
int32_t mndInitTrans(SMnode *pMnode);
|
||||
void mndCleanupTrans(SMnode *pMnode);
|
||||
|
||||
|
@ -44,6 +53,7 @@ int32_t mndTransAppendCommitlog(STrans *pTrans, SSdbRaw *pRaw);
|
|||
int32_t mndTransAppendRedoAction(STrans *pTrans, STransAction *pAction);
|
||||
int32_t mndTransAppendUndoAction(STrans *pTrans, STransAction *pAction);
|
||||
void mndTransSetRpcRsp(STrans *pTrans, void *pCont, int32_t contLen);
|
||||
void mndTransSetCb(STrans *pTrans, ETrnFuncType startFunc, ETrnFuncType stopFunc, void *param, int32_t paramLen);
|
||||
void mndTransSetDbInfo(STrans *pTrans, SDbObj *pDb);
|
||||
|
||||
int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans);
|
||||
|
|
|
@ -30,7 +30,6 @@ SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup);
|
|||
int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups);
|
||||
SEpSet mndGetVgroupEpset(SMnode *pMnode, const SVgObj *pVgroup);
|
||||
int32_t mndGetVnodesNum(SMnode *pMnode, int32_t dnodeId);
|
||||
int32_t mndGetGlobalVgroupVersion(int32_t *vgId);
|
||||
|
||||
void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen);
|
||||
void *mndBuildDropVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen);
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
#include "mndAcct.h"
|
||||
#include "mndShow.h"
|
||||
|
||||
#define TSDB_ACCT_VER_NUMBER 1
|
||||
#define TSDB_ACCT_RESERVE_SIZE 128
|
||||
#define ACCT_VER_NUMBER 1
|
||||
#define ACCT_RESERVE_SIZE 128
|
||||
|
||||
static int32_t mndCreateDefaultAcct(SMnode *pMnode);
|
||||
static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct);
|
||||
|
@ -55,6 +55,7 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
|
|||
acctObj.createdTime = taosGetTimestampMs();
|
||||
acctObj.updateTime = acctObj.createdTime;
|
||||
acctObj.acctId = 1;
|
||||
acctObj.status = 0;
|
||||
acctObj.cfg = (SAcctCfg){.maxUsers = INT32_MAX,
|
||||
.maxDbs = INT32_MAX,
|
||||
.maxStbs = INT32_MAX,
|
||||
|
@ -79,7 +80,7 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
|
|||
static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_ACCT, TSDB_ACCT_VER_NUMBER, sizeof(SAcctObj) + TSDB_ACCT_RESERVE_SIZE);
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_ACCT, ACCT_VER_NUMBER, sizeof(SAcctObj) + ACCT_RESERVE_SIZE);
|
||||
if (pRaw == NULL) goto _OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
|
@ -100,7 +101,7 @@ static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct) {
|
|||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTopics, _OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pAcct->cfg.maxStorage, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.accessState, _OVER)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_ACCT_RESERVE_SIZE, _OVER)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, ACCT_RESERVE_SIZE, _OVER)
|
||||
SDB_SET_DATALEN(pRaw, dataPos, _OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
@ -122,7 +123,7 @@ static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw) {
|
|||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
|
||||
|
||||
if (sver != TSDB_ACCT_VER_NUMBER) {
|
||||
if (sver != ACCT_VER_NUMBER) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -151,7 +152,7 @@ static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw) {
|
|||
SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTopics, _OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pAcct->cfg.maxStorage, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.accessState, _OVER)
|
||||
SDB_GET_RESERVE(pRaw, dataPos, TSDB_ACCT_RESERVE_SIZE, _OVER)
|
||||
SDB_GET_RESERVE(pRaw, dataPos, ACCT_RESERVE_SIZE, _OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
|
@ -178,7 +179,6 @@ static int32_t mndAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct) {
|
|||
|
||||
static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOld, SAcctObj *pNew) {
|
||||
mTrace("acct:%s, perform update action, old row:%p new row:%p", pOld->acct, pOld, pNew);
|
||||
|
||||
pOld->updateTime = pNew->updateTime;
|
||||
pOld->status = pNew->status;
|
||||
memcpy(&pOld->cfg, &pNew->cfg, sizeof(SAcctCfg));
|
||||
|
@ -186,19 +186,19 @@ static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOld, SAcctObj *pNew) {
|
|||
}
|
||||
|
||||
static int32_t mndProcessCreateAcctReq(SNodeMsg *pReq) {
|
||||
terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
mError("failed to process create acct request since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int32_t mndProcessAlterAcctReq(SNodeMsg *pReq) {
|
||||
terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
mError("failed to process create acct request since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropAcctReq(SNodeMsg *pReq) {
|
||||
terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
mError("failed to process create acct request since %s", terrstr());
|
||||
return -1;
|
||||
}
|
|
@ -37,6 +37,8 @@
|
|||
|
||||
static int8_t mqInRebFlag = 0;
|
||||
|
||||
static const char *mndConsumerStatusName(int status);
|
||||
|
||||
static int32_t mndConsumerActionInsert(SSdb *pSdb, SMqConsumerObj *pConsumer);
|
||||
static int32_t mndConsumerActionDelete(SSdb *pSdb, SMqConsumerObj *pConsumer);
|
||||
static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pConsumer, SMqConsumerObj *pNewConsumer);
|
||||
|
@ -48,6 +50,7 @@ static int32_t mndProcessSubscribeReq(SNodeMsg *pMsg);
|
|||
static int32_t mndProcessAskEpReq(SNodeMsg *pMsg);
|
||||
static int32_t mndProcessMqTimerMsg(SNodeMsg *pMsg);
|
||||
static int32_t mndProcessConsumerLostMsg(SNodeMsg *pMsg);
|
||||
static int32_t mndProcessConsumerRecoverMsg(SNodeMsg *pMsg);
|
||||
|
||||
int32_t mndInitConsumer(SMnode *pMnode) {
|
||||
SSdbTable table = {.sdbType = SDB_CONSUMER,
|
||||
|
@ -59,9 +62,14 @@ int32_t mndInitConsumer(SMnode *pMnode) {
|
|||
.deleteFp = (SdbDeleteFp)mndConsumerActionDelete};
|
||||
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_SUBSCRIBE, mndProcessSubscribeReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_GET_SUB_EP, mndProcessAskEpReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_MQ_ASK_EP, mndProcessAskEpReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_MQ_TIMER, mndProcessMqTimerMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_MQ_CONSUMER_LOST, mndProcessConsumerLostMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_MQ_CONSUMER_RECOVER, mndProcessConsumerRecoverMsg);
|
||||
|
||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CONSUMERS, mndRetrieveConsumer);
|
||||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_CONSUMERS, mndCancelGetNextConsumer);
|
||||
|
||||
return sdbSetTable(pMnode->pSdb, table);
|
||||
}
|
||||
|
||||
|
@ -86,7 +94,31 @@ static int32_t mndProcessConsumerLostMsg(SNodeMsg *pMsg) {
|
|||
mndTransDrop(pTrans);
|
||||
return 0;
|
||||
FAIL:
|
||||
// TODO delete consumer
|
||||
tDeleteSMqConsumerObj(pConsumerNew);
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int32_t mndProcessConsumerRecoverMsg(SNodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pNode;
|
||||
SMqConsumerRecoverMsg *pRecoverMsg = pMsg->rpcMsg.pCont;
|
||||
SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, pRecoverMsg->consumerId);
|
||||
ASSERT(pConsumer);
|
||||
|
||||
SMqConsumerObj *pConsumerNew = tNewSMqConsumerObj(pConsumer->consumerId, pConsumer->cgroup);
|
||||
pConsumerNew->updateType = CONSUMER_UPDATE__RECOVER;
|
||||
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_TYPE_CONSUMER_RECOVER, &pMsg->rpcMsg);
|
||||
if (pTrans == NULL) goto FAIL;
|
||||
if (mndSetConsumerCommitLogs(pMnode, pTrans, pConsumerNew) != 0) goto FAIL;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto FAIL;
|
||||
|
||||
mndTransDrop(pTrans);
|
||||
return 0;
|
||||
FAIL:
|
||||
tDeleteSMqConsumerObj(pConsumerNew);
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
|
@ -197,11 +229,11 @@ static int32_t mndProcessMqTimerMsg(SNodeMsg *pMsg) {
|
|||
}
|
||||
|
||||
static int32_t mndProcessAskEpReq(SNodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pNode;
|
||||
SMqCMGetSubEpReq *pReq = (SMqCMGetSubEpReq *)pMsg->rpcMsg.pCont;
|
||||
SMqCMGetSubEpRsp rsp = {0};
|
||||
int64_t consumerId = be64toh(pReq->consumerId);
|
||||
int32_t epoch = ntohl(pReq->epoch);
|
||||
SMnode *pMnode = pMsg->pNode;
|
||||
SMqAskEpReq *pReq = (SMqAskEpReq *)pMsg->rpcMsg.pCont;
|
||||
SMqAskEpRsp rsp = {0};
|
||||
int64_t consumerId = be64toh(pReq->consumerId);
|
||||
int32_t epoch = ntohl(pReq->epoch);
|
||||
|
||||
SMqConsumerObj *pConsumer = mndAcquireConsumer(pMsg->pNode, consumerId);
|
||||
if (pConsumer == NULL) {
|
||||
|
@ -216,8 +248,15 @@ static int32_t mndProcessAskEpReq(SNodeMsg *pMsg) {
|
|||
// 1. check consumer status
|
||||
int32_t status = atomic_load_32(&pConsumer->status);
|
||||
|
||||
if (status == MQ_CONSUMER_STATUS__LOST) {
|
||||
// TODO: recover consumer
|
||||
if (status == MQ_CONSUMER_STATUS__LOST_REBD) {
|
||||
SMqConsumerRecoverMsg *pRecoverMsg = rpcMallocCont(sizeof(SMqConsumerRecoverMsg));
|
||||
|
||||
pRecoverMsg->consumerId = consumerId;
|
||||
SRpcMsg *pRpcMsg = taosMemoryCalloc(1, sizeof(SRpcMsg));
|
||||
pRpcMsg->msgType = TDMT_MND_MQ_CONSUMER_RECOVER;
|
||||
pRpcMsg->pCont = pRecoverMsg;
|
||||
pRpcMsg->contLen = sizeof(SMqConsumerRecoverMsg);
|
||||
tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, pRpcMsg);
|
||||
}
|
||||
|
||||
if (status != MQ_CONSUMER_STATUS__READY) {
|
||||
|
@ -300,7 +339,7 @@ static int32_t mndProcessAskEpReq(SNodeMsg *pMsg) {
|
|||
taosRUnLockLatch(&pConsumer->lock);
|
||||
}
|
||||
// encode rsp
|
||||
int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqCMGetSubEpRsp(NULL, &rsp);
|
||||
int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqAskEpRsp(NULL, &rsp);
|
||||
void *buf = rpcMallocCont(tlen);
|
||||
if (buf == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -311,10 +350,10 @@ static int32_t mndProcessAskEpReq(SNodeMsg *pMsg) {
|
|||
((SMqRspHead *)buf)->consumerId = pConsumer->consumerId;
|
||||
|
||||
void *abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
|
||||
tEncodeSMqCMGetSubEpRsp(&abuf, &rsp);
|
||||
tEncodeSMqAskEpRsp(&abuf, &rsp);
|
||||
|
||||
// release consumer and free memory
|
||||
tDeleteSMqCMGetSubEpRsp(&rsp);
|
||||
tDeleteSMqAskEpRsp(&rsp);
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
|
||||
// send rsp
|
||||
|
@ -322,7 +361,7 @@ static int32_t mndProcessAskEpReq(SNodeMsg *pMsg) {
|
|||
pMsg->rspLen = tlen;
|
||||
return 0;
|
||||
FAIL:
|
||||
tDeleteSMqCMGetSubEpRsp(&rsp);
|
||||
tDeleteSMqAskEpRsp(&rsp);
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
return -1;
|
||||
}
|
||||
|
@ -366,10 +405,14 @@ static int32_t mndProcessSubscribeReq(SNodeMsg *pMsg) {
|
|||
if (pConsumerOld == NULL) {
|
||||
pConsumerNew = tNewSMqConsumerObj(consumerId, cgroup);
|
||||
pConsumerNew->updateType = CONSUMER_UPDATE__MODIFY;
|
||||
/*pConsumerNew->waitingRebTopics = newSub;*/
|
||||
pConsumerNew->rebNewTopics = newSub;
|
||||
subscribe.topicNames = NULL;
|
||||
|
||||
for (int32_t i = 0; i < newTopicNum; i++) {
|
||||
char *newTopicCopy = strdup(taosArrayGetP(newSub, i));
|
||||
taosArrayPush(pConsumerNew->assignedTopics, &newTopicCopy);
|
||||
}
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_TYPE_SUBSCRIBE, &pMsg->rpcMsg);
|
||||
if (pTrans == NULL) goto SUBSCRIBE_OVER;
|
||||
if (mndSetConsumerCommitLogs(pMnode, pTrans, pConsumerNew) != 0) goto SUBSCRIBE_OVER;
|
||||
|
@ -389,7 +432,11 @@ static int32_t mndProcessSubscribeReq(SNodeMsg *pMsg) {
|
|||
goto SUBSCRIBE_OVER;
|
||||
}
|
||||
pConsumerNew->updateType = CONSUMER_UPDATE__MODIFY;
|
||||
/*pConsumerOld->waitingRebTopics = newSub;*/
|
||||
|
||||
for (int32_t i = 0; i < newTopicNum; i++) {
|
||||
char *newTopicCopy = strdup(taosArrayGetP(newSub, i));
|
||||
taosArrayPush(pConsumerNew->assignedTopics, &newTopicCopy);
|
||||
}
|
||||
|
||||
int32_t oldTopicNum = 0;
|
||||
if (pConsumerOld->currentTopics) {
|
||||
|
@ -532,6 +579,7 @@ CM_DECODE_OVER:
|
|||
|
||||
static int32_t mndConsumerActionInsert(SSdb *pSdb, SMqConsumerObj *pConsumer) {
|
||||
mTrace("consumer:%" PRId64 ", perform insert action", pConsumer->consumerId);
|
||||
pConsumer->subscribeTime = pConsumer->upTime;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -557,17 +605,45 @@ static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer,
|
|||
pOldConsumer->rebRemovedTopics = pNewConsumer->rebRemovedTopics;
|
||||
pNewConsumer->rebRemovedTopics = tmp;
|
||||
|
||||
tmp = pOldConsumer->assignedTopics;
|
||||
pOldConsumer->assignedTopics = pNewConsumer->assignedTopics;
|
||||
pNewConsumer->assignedTopics = tmp;
|
||||
|
||||
pOldConsumer->subscribeTime = pNewConsumer->upTime;
|
||||
|
||||
pOldConsumer->status = MQ_CONSUMER_STATUS__MODIFY;
|
||||
} else if (pNewConsumer->updateType == CONSUMER_UPDATE__LOST) {
|
||||
ASSERT(taosArrayGetSize(pOldConsumer->rebNewTopics) == 0);
|
||||
ASSERT(taosArrayGetSize(pOldConsumer->rebRemovedTopics) == 0);
|
||||
|
||||
int32_t sz = taosArrayGetSize(pOldConsumer->currentTopics);
|
||||
pOldConsumer->rebRemovedTopics = taosArrayInit(sz, sizeof(void *));
|
||||
/*pOldConsumer->rebRemovedTopics = taosArrayInit(sz, sizeof(void *));*/
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
char *topic = strdup(taosArrayGetP(pOldConsumer->currentTopics, i));
|
||||
taosArrayPush(pNewConsumer->rebRemovedTopics, &topic);
|
||||
taosArrayPush(pOldConsumer->rebRemovedTopics, &topic);
|
||||
}
|
||||
|
||||
pOldConsumer->rebalanceTime = pNewConsumer->upTime;
|
||||
|
||||
pOldConsumer->status = MQ_CONSUMER_STATUS__LOST;
|
||||
} else if (pNewConsumer->updateType == CONSUMER_UPDATE__RECOVER) {
|
||||
ASSERT(taosArrayGetSize(pOldConsumer->currentTopics) == 0);
|
||||
ASSERT(taosArrayGetSize(pOldConsumer->rebNewTopics) == 0);
|
||||
|
||||
int32_t sz = taosArrayGetSize(pOldConsumer->assignedTopics);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
char *topic = strdup(taosArrayGetP(pOldConsumer->assignedTopics, i));
|
||||
taosArrayPush(pOldConsumer->rebNewTopics, &topic);
|
||||
}
|
||||
|
||||
pOldConsumer->rebalanceTime = pNewConsumer->upTime;
|
||||
|
||||
pOldConsumer->status = MQ_CONSUMER_STATUS__MODIFY;
|
||||
} else if (pNewConsumer->updateType == CONSUMER_UPDATE__TOUCH) {
|
||||
atomic_add_fetch_32(&pOldConsumer->epoch, 1);
|
||||
|
||||
pOldConsumer->rebalanceTime = pNewConsumer->upTime;
|
||||
|
||||
} else if (pNewConsumer->updateType == CONSUMER_UPDATE__ADD) {
|
||||
ASSERT(taosArrayGetSize(pNewConsumer->rebNewTopics) == 1);
|
||||
ASSERT(taosArrayGetSize(pNewConsumer->rebRemovedTopics) == 0);
|
||||
|
@ -612,6 +688,9 @@ static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer,
|
|||
pOldConsumer->status = MQ_CONSUMER_STATUS__LOST_IN_REB;
|
||||
}
|
||||
}
|
||||
|
||||
pOldConsumer->rebalanceTime = pNewConsumer->upTime;
|
||||
|
||||
atomic_add_fetch_32(&pOldConsumer->epoch, 1);
|
||||
} else if (pNewConsumer->updateType == CONSUMER_UPDATE__REMOVE) {
|
||||
ASSERT(taosArrayGetSize(pNewConsumer->rebNewTopics) == 0);
|
||||
|
@ -668,6 +747,9 @@ static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer,
|
|||
pOldConsumer->status = MQ_CONSUMER_STATUS__LOST_IN_REB;
|
||||
}
|
||||
}
|
||||
|
||||
pOldConsumer->rebalanceTime = pNewConsumer->upTime;
|
||||
|
||||
atomic_add_fetch_32(&pOldConsumer->epoch, 1);
|
||||
}
|
||||
|
||||
|
@ -688,3 +770,104 @@ void mndReleaseConsumer(SMnode *pMnode, SMqConsumerObj *pConsumer) {
|
|||
SSdb *pSdb = pMnode->pSdb;
|
||||
sdbRelease(pSdb, pConsumer);
|
||||
}
|
||||
|
||||
static int32_t mndRetrieveConsumer(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rowsCapacity) {
|
||||
SMnode *pMnode = pReq->pNode;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t numOfRows = 0;
|
||||
SMqConsumerObj *pConsumer = NULL;
|
||||
|
||||
while (numOfRows < rowsCapacity) {
|
||||
pShow->pIter = sdbFetch(pSdb, SDB_CONSUMER, pShow->pIter, (void **)&pConsumer);
|
||||
if (pShow->pIter == NULL) break;
|
||||
|
||||
SColumnInfoData *pColInfo;
|
||||
int32_t cols = 0;
|
||||
|
||||
taosRLockLatch(&pConsumer->lock);
|
||||
|
||||
// consumer id
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pConsumer->consumerId, false);
|
||||
|
||||
// group id
|
||||
char groupId[TSDB_CGROUP_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
tstrncpy(varDataVal(groupId), pConsumer->cgroup, TSDB_CGROUP_LEN);
|
||||
varDataSetLen(groupId, strlen(varDataVal(groupId)));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)groupId, false);
|
||||
|
||||
// app id
|
||||
char appId[TSDB_CGROUP_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
tstrncpy(varDataVal(appId), pConsumer->appId, TSDB_CGROUP_LEN);
|
||||
varDataSetLen(appId, strlen(varDataVal(appId)));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)appId, false);
|
||||
|
||||
// status
|
||||
char status[20 + VARSTR_HEADER_SIZE] = {0};
|
||||
tstrncpy(varDataVal(status), mndConsumerStatusName(pConsumer->status), 20);
|
||||
varDataSetLen(status, strlen(varDataVal(status)));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)status, false);
|
||||
|
||||
// subscribed topics
|
||||
char topics[TSDB_SHOW_LIST_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
char *showStr = taosShowStrArray(pConsumer->assignedTopics);
|
||||
tstrncpy(varDataVal(topics), showStr, TSDB_SHOW_LIST_LEN);
|
||||
taosMemoryFree(showStr);
|
||||
varDataSetLen(topics, strlen(varDataVal(topics)));
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)topics, false);
|
||||
|
||||
// pid
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pConsumer->pid, true);
|
||||
|
||||
// end point
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pConsumer->ep, true);
|
||||
|
||||
// up time
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pConsumer->upTime, false);
|
||||
|
||||
// subscribe time
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pConsumer->subscribeTime, false);
|
||||
|
||||
// rebalance time
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pConsumer->rebalanceTime, pConsumer->rebalanceTime == 0);
|
||||
|
||||
taosRUnLockLatch(&pConsumer->lock);
|
||||
sdbRelease(pSdb, pConsumer);
|
||||
|
||||
numOfRows++;
|
||||
}
|
||||
|
||||
pShow->numOfRows += numOfRows;
|
||||
return numOfRows;
|
||||
}
|
||||
|
||||
static void mndCancelGetNextConsumer(SMnode *pMnode, void *pIter) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
}
|
||||
|
||||
static const char *mndConsumerStatusName(int status) {
|
||||
switch (status) {
|
||||
case MQ_CONSUMER_STATUS__READY:
|
||||
return "ready";
|
||||
case MQ_CONSUMER_STATUS__LOST:
|
||||
case MQ_CONSUMER_STATUS__LOST_REBD:
|
||||
case MQ_CONSUMER_STATUS__LOST_IN_REB:
|
||||
return "lost";
|
||||
case MQ_CONSUMER_STATUS__MODIFY:
|
||||
case MQ_CONSUMER_STATUS__MODIFY_IN_REB:
|
||||
return "rebalancing";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -234,6 +234,8 @@ static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOld, SDbObj *pNew) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndGetGlobalVgroupVersion(SMnode *pMnode) { return sdbGetTableVer(pMnode->pSdb, SDB_VGROUP); }
|
||||
|
||||
SDbObj *mndAcquireDb(SMnode *pMnode, const char *db) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SDbObj *pDb = sdbAcquire(pSdb, SDB_DB, db);
|
||||
|
@ -618,7 +620,7 @@ static int32_t mndSetAlterDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pOl
|
|||
SSdbRaw *pRedoRaw = mndDbActionEncode(pOld);
|
||||
if (pRedoRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_UPDATING) != 0) return -1;
|
||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY) != 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1191,8 +1193,7 @@ static int32_t mndProcessUseDbReq(SNodeMsg *pReq) {
|
|||
char *p = strchr(usedbReq.db, '.');
|
||||
if (p && 0 == strcmp(p + 1, TSDB_INFORMATION_SCHEMA_DB)) {
|
||||
memcpy(usedbRsp.db, usedbReq.db, TSDB_DB_FNAME_LEN);
|
||||
//mndGetGlobalVgroupVersion(); TODO
|
||||
static int32_t vgVersion = 1;
|
||||
int32_t vgVersion = mndGetGlobalVgroupVersion(pMnode);
|
||||
if (usedbReq.vgVersion < vgVersion) {
|
||||
usedbRsp.pVgroupInfos = taosArrayInit(10, sizeof(SVgroupInfo));
|
||||
if (usedbRsp.pVgroupInfos == NULL) {
|
||||
|
|
|
@ -34,15 +34,20 @@ SMqConsumerObj *tNewSMqConsumerObj(int64_t consumerId, char cgroup[TSDB_CGROUP_L
|
|||
pConsumer->currentTopics = taosArrayInit(0, sizeof(void *));
|
||||
pConsumer->rebNewTopics = taosArrayInit(0, sizeof(void *));
|
||||
pConsumer->rebRemovedTopics = taosArrayInit(0, sizeof(void *));
|
||||
pConsumer->assignedTopics = taosArrayInit(0, sizeof(void *));
|
||||
|
||||
if (pConsumer->currentTopics == NULL || pConsumer->rebNewTopics == NULL || pConsumer->rebRemovedTopics == NULL) {
|
||||
if (pConsumer->currentTopics == NULL || pConsumer->rebNewTopics == NULL || pConsumer->rebRemovedTopics == NULL ||
|
||||
pConsumer->assignedTopics == NULL) {
|
||||
taosArrayDestroy(pConsumer->currentTopics);
|
||||
taosArrayDestroy(pConsumer->rebNewTopics);
|
||||
taosArrayDestroy(pConsumer->rebRemovedTopics);
|
||||
taosArrayDestroy(pConsumer->assignedTopics);
|
||||
taosMemoryFree(pConsumer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pConsumer->upTime = taosGetTimestampMs();
|
||||
|
||||
return pConsumer;
|
||||
}
|
||||
|
||||
|
@ -56,6 +61,9 @@ void tDeleteSMqConsumerObj(SMqConsumerObj *pConsumer) {
|
|||
if (pConsumer->rebRemovedTopics) {
|
||||
taosArrayDestroyP(pConsumer->rebRemovedTopics, (FDelete)taosMemoryFree);
|
||||
}
|
||||
if (pConsumer->assignedTopics) {
|
||||
taosArrayDestroyP(pConsumer->assignedTopics, (FDelete)taosMemoryFree);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t tEncodeSMqConsumerObj(void **buf, const SMqConsumerObj *pConsumer) {
|
||||
|
@ -67,6 +75,12 @@ int32_t tEncodeSMqConsumerObj(void **buf, const SMqConsumerObj *pConsumer) {
|
|||
tlen += taosEncodeFixedI32(buf, pConsumer->epoch);
|
||||
tlen += taosEncodeFixedI32(buf, pConsumer->status);
|
||||
|
||||
tlen += taosEncodeFixedI32(buf, pConsumer->pid);
|
||||
tlen += taosEncodeSEpSet(buf, &pConsumer->ep);
|
||||
tlen += taosEncodeFixedI64(buf, pConsumer->upTime);
|
||||
tlen += taosEncodeFixedI64(buf, pConsumer->subscribeTime);
|
||||
tlen += taosEncodeFixedI64(buf, pConsumer->rebalanceTime);
|
||||
|
||||
// current topics
|
||||
if (pConsumer->currentTopics) {
|
||||
sz = taosArrayGetSize(pConsumer->currentTopics);
|
||||
|
@ -103,6 +117,18 @@ int32_t tEncodeSMqConsumerObj(void **buf, const SMqConsumerObj *pConsumer) {
|
|||
tlen += taosEncodeFixedI32(buf, 0);
|
||||
}
|
||||
|
||||
// lost topics
|
||||
if (pConsumer->assignedTopics) {
|
||||
sz = taosArrayGetSize(pConsumer->assignedTopics);
|
||||
tlen += taosEncodeFixedI32(buf, sz);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
char *topic = taosArrayGetP(pConsumer->assignedTopics, i);
|
||||
tlen += taosEncodeString(buf, topic);
|
||||
}
|
||||
} else {
|
||||
tlen += taosEncodeFixedI32(buf, 0);
|
||||
}
|
||||
|
||||
return tlen;
|
||||
}
|
||||
|
||||
|
@ -114,6 +140,12 @@ void *tDecodeSMqConsumerObj(const void *buf, SMqConsumerObj *pConsumer) {
|
|||
buf = taosDecodeFixedI32(buf, &pConsumer->epoch);
|
||||
buf = taosDecodeFixedI32(buf, &pConsumer->status);
|
||||
|
||||
buf = taosDecodeFixedI32(buf, &pConsumer->pid);
|
||||
buf = taosDecodeSEpSet(buf, &pConsumer->ep);
|
||||
buf = taosDecodeFixedI64(buf, &pConsumer->upTime);
|
||||
buf = taosDecodeFixedI64(buf, &pConsumer->subscribeTime);
|
||||
buf = taosDecodeFixedI64(buf, &pConsumer->rebalanceTime);
|
||||
|
||||
// current topics
|
||||
buf = taosDecodeFixedI32(buf, &sz);
|
||||
pConsumer->currentTopics = taosArrayInit(sz, sizeof(void *));
|
||||
|
@ -141,6 +173,15 @@ void *tDecodeSMqConsumerObj(const void *buf, SMqConsumerObj *pConsumer) {
|
|||
taosArrayPush(pConsumer->rebRemovedTopics, &topic);
|
||||
}
|
||||
|
||||
// reb removed topics
|
||||
buf = taosDecodeFixedI32(buf, &sz);
|
||||
pConsumer->assignedTopics = taosArrayInit(sz, sizeof(void *));
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
char *topic;
|
||||
buf = taosDecodeString(buf, &topic);
|
||||
taosArrayPush(pConsumer->assignedTopics, &topic);
|
||||
}
|
||||
|
||||
return (void *)buf;
|
||||
}
|
||||
|
||||
|
@ -215,7 +256,7 @@ SMqSubscribeObj *tNewSubscribeObj(const char key[TSDB_SUBSCRIBE_KEY_LEN]) {
|
|||
if (pSubNew == NULL) return NULL;
|
||||
memcpy(pSubNew->key, key, TSDB_SUBSCRIBE_KEY_LEN);
|
||||
taosInitRWLatch(&pSubNew->lock);
|
||||
pSubNew->vgNum = -1;
|
||||
pSubNew->vgNum = 0;
|
||||
pSubNew->consumerHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
|
||||
// TODO set free fp
|
||||
SMqConsumerEpInSub epInSub = {
|
||||
|
@ -329,6 +370,7 @@ int32_t tEncodeSMqSubActionLogEntry(void **buf, const SMqSubActionLogEntry *pEnt
|
|||
tlen += taosEncodeArray(buf, pEntry->consumers, (FEncode)tEncodeSMqSubActionLogEntry);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
void *tDecodeSMqSubActionLogEntry(const void *buf, SMqSubActionLogEntry *pEntry) {
|
||||
buf = taosDecodeFixedI32(buf, &pEntry->epoch);
|
||||
buf = taosDecodeArray(buf, &pEntry->consumers, (FDecode)tDecodeSMqSubActionLogEntry, sizeof(SMqSubActionLogEntry));
|
||||
|
|
|
@ -363,7 +363,7 @@ static int32_t mndProcessStatusReq(SNodeMsg *pReq) {
|
|||
pDnode->offlineReason = DND_REASON_VERSION_NOT_MATCH;
|
||||
}
|
||||
mError("dnode:%d, status msg version:%d not match cluster:%d", statusReq.dnodeId, statusReq.sver, tsVersion);
|
||||
terrno = TSDB_CODE_MND_INVALID_MSG_VERSION;
|
||||
terrno = TSDB_CODE_VERSION_NOT_COMPATIBLE;
|
||||
goto PROCESS_STATUS_MSG_OVER;
|
||||
}
|
||||
|
||||
|
|
|
@ -142,6 +142,7 @@ static const SInfosTableSchema userTblsSchema[] = {
|
|||
{.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||
{.name = "ttl", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||
{.name = "table_comment", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||
{.name = "type", .bytes = 20 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
};
|
||||
|
||||
static const SInfosTableSchema userTblDistSchema[] = {
|
||||
|
@ -164,7 +165,6 @@ static const SInfosTableSchema userUsersSchema[] = {
|
|||
{.name = "name", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
{.name = "privilege", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
||||
{.name = "account", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
};
|
||||
|
||||
static const SInfosTableSchema grantsSchema[] = {
|
||||
|
@ -199,23 +199,6 @@ static const SInfosTableSchema vgroupsSchema[] = {
|
|||
{.name = "file_size", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||
};
|
||||
|
||||
static const SInfosTableSchema consumerSchema[] = {
|
||||
{.name = "client_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
{.name = "group_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
{.name = "pid", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||
{.name = "status", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||
// ep
|
||||
// up time
|
||||
// topics
|
||||
};
|
||||
|
||||
static const SInfosTableSchema subscribeSchema[] = {
|
||||
{.name = "topic_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
{.name = "group_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
{.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||
{.name = "client_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
};
|
||||
|
||||
static const SInfosTableSchema smaSchema[] = {
|
||||
{.name = "sma_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR},
|
||||
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
||||
|
@ -282,8 +265,6 @@ static const SInfosTableMeta infosMeta[] = {
|
|||
{TSDB_INS_TABLE_USER_USERS, userUsersSchema, tListLen(userUsersSchema)},
|
||||
{TSDB_INS_TABLE_LICENCES, grantsSchema, tListLen(grantsSchema)},
|
||||
{TSDB_INS_TABLE_VGROUPS, vgroupsSchema, tListLen(vgroupsSchema)},
|
||||
{TSDB_INS_TABLE_CONSUMERS, consumerSchema, tListLen(consumerSchema)},
|
||||
{TSDB_INS_TABLE_SUBSCRIBES, subscribeSchema, tListLen(subscribeSchema)},
|
||||
{TSDB_INS_TABLE_TRANS, transSchema, tListLen(transSchema)},
|
||||
{TSDB_INS_TABLE_SMAS, smaSchema, tListLen(smaSchema)},
|
||||
{TSDB_INS_TABLE_CONFIGS, configSchema, tListLen(configSchema)},
|
||||
|
|
|
@ -41,29 +41,39 @@ static const SPerfsTableSchema queriesSchema[] = {
|
|||
|
||||
static const SPerfsTableSchema topicSchema[] = {
|
||||
{.name = "topic_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||
/*{.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},*/
|
||||
{.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
||||
{.name = "sql", .bytes = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
||||
/*{.name = "row_len", .bytes = 4, .type = TSDB_DATA_TYPE_INT},*/
|
||||
// TODO config
|
||||
};
|
||||
|
||||
static const SPerfsTableSchema consumerSchema[] = {
|
||||
{.name = "client_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "app_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "consumer_id", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT},
|
||||
{.name = "group_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "app_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "status", .bytes = 20 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "topics", .bytes = TSDB_SHOW_LIST_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "pid", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||
{.name = "status", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||
// ep
|
||||
// up time
|
||||
// topics
|
||||
{.name = "end_point", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "up_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
||||
{.name = "subscribe_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
||||
{.name = "rebalance_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
||||
};
|
||||
|
||||
static const SPerfsTableSchema subscribeSchema[] = {
|
||||
static const SPerfsTableSchema subscriptionSchema[] = {
|
||||
{.name = "topic_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "group_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||
{.name = "offset", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT},
|
||||
{.name = "client_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "consumer_id", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT},
|
||||
};
|
||||
|
||||
static const SPerfsTableSchema offsetSchema[] = {
|
||||
{.name = "topic_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "group_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||
{.name = "committed_offset", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT},
|
||||
{.name = "current_offset", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT},
|
||||
{.name = "skip_log_cnt", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT},
|
||||
};
|
||||
|
||||
static const SPerfsTableMeta perfsMeta[] = {
|
||||
|
@ -71,7 +81,8 @@ static const SPerfsTableMeta perfsMeta[] = {
|
|||
{TSDB_PERFS_TABLE_QUERIES, queriesSchema, tListLen(queriesSchema)},
|
||||
{TSDB_PERFS_TABLE_TOPICS, topicSchema, tListLen(topicSchema)},
|
||||
{TSDB_PERFS_TABLE_CONSUMERS, consumerSchema, tListLen(consumerSchema)},
|
||||
{TSDB_PERFS_TABLE_SUBSCRIBES, subscribeSchema, tListLen(subscribeSchema)},
|
||||
{TSDB_PERFS_TABLE_SUBSCRIPTIONS, subscriptionSchema, tListLen(subscriptionSchema)},
|
||||
{TSDB_PERFS_TABLE_OFFSETS, offsetSchema, tListLen(offsetSchema)},
|
||||
};
|
||||
|
||||
// connection/application/
|
||||
|
|
|
@ -196,7 +196,7 @@ static int32_t mndProcessConnectReq(SNodeMsg *pReq) {
|
|||
goto CONN_OVER;
|
||||
}
|
||||
if (0 != strncmp(connReq.passwd, pUser->pass, TSDB_PASSWORD_LEN - 1)) {
|
||||
mError("user:%s, failed to auth while acquire user\n %s \r\n %s", pReq->user, connReq.passwd, pUser->pass);
|
||||
mError("user:%s, failed to auth while acquire user, input:%s saved:%s", pReq->user, connReq.passwd, pUser->pass);
|
||||
code = TSDB_CODE_RPC_AUTH_FAILURE;
|
||||
goto CONN_OVER;
|
||||
}
|
||||
|
|
|
@ -478,6 +478,7 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
|
|||
SVgObj* pVgroup = NULL;
|
||||
SQueryPlan* pPlan = NULL;
|
||||
SSubplan* plan = NULL;
|
||||
|
||||
if (pTopic->subType == TOPIC_SUB_TYPE__TABLE) {
|
||||
pPlan = qStringToQueryPlan(pTopic->physicalPlan);
|
||||
if (pPlan == NULL) {
|
||||
|
@ -485,14 +486,10 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
|
|||
return -1;
|
||||
}
|
||||
|
||||
ASSERT(pSub->vgNum == -1);
|
||||
|
||||
pSub->vgNum = 0;
|
||||
|
||||
int32_t levelNum = LIST_LENGTH(pPlan->pSubplans);
|
||||
if (levelNum != 1) {
|
||||
qDestroyQueryPlan(pPlan);
|
||||
terrno = TSDB_CODE_MND_UNSUPPORTED_TOPIC;
|
||||
terrno = TSDB_CODE_MND_INVALID_TOPIC_QUERY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -501,7 +498,7 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
|
|||
int32_t opNum = LIST_LENGTH(inner->pNodeList);
|
||||
if (opNum != 1) {
|
||||
qDestroyQueryPlan(pPlan);
|
||||
terrno = TSDB_CODE_MND_UNSUPPORTED_TOPIC;
|
||||
terrno = TSDB_CODE_MND_INVALID_TOPIC_QUERY;
|
||||
return -1;
|
||||
}
|
||||
plan = nodesListGetNode(inner->pNodeList, 0);
|
||||
|
@ -529,7 +526,7 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
|
|||
pVgEp->vgId = pVgroup->vgId;
|
||||
taosArrayPush(pEpInSub->vgs, &pVgEp);
|
||||
|
||||
mDebug("init subscribption %s, assign vg: %d", pSub->key, pVgEp->vgId);
|
||||
mDebug("init subscription %s, assign vg: %d", pSub->key, pVgEp->vgId);
|
||||
|
||||
if (pTopic->subType == TOPIC_SUB_TYPE__TABLE) {
|
||||
int32_t msgLen;
|
||||
|
|
|
@ -72,8 +72,8 @@ void mndCleanupStb(SMnode *pMnode) {}
|
|||
SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int32_t size = sizeof(SStbObj) + (pStb->numOfColumns + pStb->numOfTags + pStb->numOfSmas) * sizeof(SSchema) +
|
||||
+ pStb->commentLen + pStb->ast1Len + pStb->ast2Len + TSDB_STB_RESERVE_SIZE;
|
||||
int32_t size = sizeof(SStbObj) + (pStb->numOfColumns + pStb->numOfTags) * sizeof(SSchema) + +pStb->commentLen +
|
||||
pStb->ast1Len + pStb->ast2Len + TSDB_STB_RESERVE_SIZE;
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_STB, TSDB_STB_VER_NUMBER, size);
|
||||
if (pRaw == NULL) goto _OVER;
|
||||
|
||||
|
@ -91,7 +91,6 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
|
|||
SDB_SET_INT32(pRaw, dataPos, pStb->ttl, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->numOfTags, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->numOfSmas, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->commentLen, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->ast1Len, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->ast2Len, _OVER)
|
||||
|
@ -112,14 +111,6 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
|
|||
SDB_SET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, _OVER)
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pStb->numOfSmas; ++i) {
|
||||
SSchema *pSchema = &pStb->pSmas[i];
|
||||
SDB_SET_INT8(pRaw, dataPos, pSchema->type, _OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, pSchema->colId, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pSchema->bytes, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, _OVER)
|
||||
}
|
||||
|
||||
if (pStb->commentLen > 0) {
|
||||
SDB_SET_BINARY(pRaw, dataPos, pStb->comment, pStb->commentLen, _OVER)
|
||||
}
|
||||
|
@ -178,15 +169,13 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
|
|||
SDB_GET_INT32(pRaw, dataPos, &pStb->ttl, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pStb->numOfColumns, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pStb->numOfTags, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pStb->numOfSmas, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pStb->commentLen, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pStb->ast1Len, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pStb->ast2Len, _OVER)
|
||||
|
||||
pStb->pColumns = taosMemoryCalloc(pStb->numOfColumns, sizeof(SSchema));
|
||||
pStb->pTags = taosMemoryCalloc(pStb->numOfTags, sizeof(SSchema));
|
||||
pStb->pSmas = taosMemoryCalloc(pStb->numOfSmas, sizeof(SSchema));
|
||||
if (pStb->pColumns == NULL || pStb->pTags == NULL || pStb->pSmas == NULL) {
|
||||
if (pStb->pColumns == NULL || pStb->pTags == NULL) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -206,14 +195,6 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
|
|||
SDB_GET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, _OVER)
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pStb->numOfSmas; ++i) {
|
||||
SSchema *pSchema = &pStb->pSmas[i];
|
||||
SDB_GET_INT8(pRaw, dataPos, &pSchema->type, _OVER)
|
||||
SDB_GET_INT16(pRaw, dataPos, &pSchema->colId, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pSchema->bytes, _OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, _OVER)
|
||||
}
|
||||
|
||||
if (pStb->commentLen > 0) {
|
||||
pStb->comment = taosMemoryCalloc(pStb->commentLen, 1);
|
||||
if (pStb->comment == NULL) goto _OVER;
|
||||
|
@ -291,18 +272,6 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) {
|
|||
}
|
||||
}
|
||||
|
||||
if (pOld->numOfSmas < pNew->numOfSmas) {
|
||||
void *pSmas = taosMemoryMalloc(pNew->numOfSmas * sizeof(SSchema));
|
||||
if (pSmas != NULL) {
|
||||
taosMemoryFree(pOld->pSmas);
|
||||
pOld->pSmas = pSmas;
|
||||
} else {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mTrace("stb:%s, failed to perform update action since %s", pOld->name, terrstr());
|
||||
taosWUnLockLatch(&pOld->lock);
|
||||
}
|
||||
}
|
||||
|
||||
if (pOld->commentLen < pNew->commentLen) {
|
||||
void *comment = taosMemoryMalloc(pNew->commentLen);
|
||||
if (comment != NULL) {
|
||||
|
@ -393,72 +362,51 @@ static FORCE_INLINE int schemaExColIdCompare(const void *colId, const void *pSch
|
|||
}
|
||||
|
||||
static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, int32_t *pContLen) {
|
||||
SName name = {0};
|
||||
SCoder coder = {0};
|
||||
int32_t contLen;
|
||||
SName name = {0};
|
||||
SVCreateStbReq req = {0};
|
||||
|
||||
tNameFromString(&name, pStb->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
char dbFName[TSDB_DB_FNAME_LEN] = {0};
|
||||
tNameGetFullDbName(&name, dbFName);
|
||||
|
||||
SVCreateTbReq req = {0};
|
||||
req.name = (char *)tNameGetTableName(&name);
|
||||
req.ttl = 0;
|
||||
req.keep = 0;
|
||||
req.rollup = pStb->pAst1 > 0 ? 1 : 0;
|
||||
req.type = TD_SUPER_TABLE;
|
||||
req.stbCfg.suid = pStb->uid;
|
||||
req.stbCfg.nCols = pStb->numOfColumns;
|
||||
req.stbCfg.nTagCols = pStb->numOfTags;
|
||||
req.stbCfg.pTagSchema = pStb->pTags;
|
||||
req.stbCfg.nBSmaCols = pStb->numOfSmas;
|
||||
req.stbCfg.pSchema = (SSchema *)taosMemoryCalloc(pStb->numOfColumns, sizeof(SSchema));
|
||||
if (req.stbCfg.pSchema == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
req.suid = pStb->uid;
|
||||
req.rollup = pStb->ast1Len > 0 ? 1 : 0;
|
||||
req.schema.nCols = pStb->numOfColumns;
|
||||
req.schema.sver = 0;
|
||||
req.schema.pSchema = pStb->pColumns;
|
||||
req.schemaTag.nCols = pStb->numOfTags;
|
||||
req.schemaTag.pSchema = pStb->pTags;
|
||||
|
||||
memcpy(req.stbCfg.pSchema, pStb->pColumns, sizeof(SSchema) * pStb->numOfColumns);
|
||||
for (int i = 0; i < pStb->numOfColumns; i++) {
|
||||
req.stbCfg.pSchema[i].flags = SCHEMA_SMA_ON;
|
||||
}
|
||||
|
||||
SRSmaParam *pRSmaParam = NULL;
|
||||
if (req.rollup) {
|
||||
pRSmaParam = (SRSmaParam *)taosMemoryCalloc(1, sizeof(SRSmaParam));
|
||||
if (pRSmaParam == NULL) {
|
||||
taosMemoryFreeClear(req.stbCfg.pSchema);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pRSmaParam->xFilesFactor = pStb->xFilesFactor;
|
||||
pRSmaParam->delay = pStb->delay;
|
||||
req.pRSmaParam.xFilesFactor = pStb->xFilesFactor;
|
||||
req.pRSmaParam.delay = pStb->delay;
|
||||
if (pStb->ast1Len > 0) {
|
||||
if (mndConvertRSmaTask(pStb->pAst1, 0, 0, &pRSmaParam->qmsg1, &pRSmaParam->qmsg1Len) != TSDB_CODE_SUCCESS) {
|
||||
taosMemoryFreeClear(req.stbCfg.pRSmaParam);
|
||||
taosMemoryFreeClear(req.stbCfg.pSchema);
|
||||
if (mndConvertRSmaTask(pStb->pAst1, 0, 0, &req.pRSmaParam.qmsg1, &req.pRSmaParam.qmsg1Len) != TSDB_CODE_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (pStb->ast2Len > 0) {
|
||||
if (mndConvertRSmaTask(pStb->pAst2, 0, 0, &pRSmaParam->qmsg2, &pRSmaParam->qmsg2Len) != TSDB_CODE_SUCCESS) {
|
||||
taosMemoryFreeClear(pRSmaParam->qmsg1);
|
||||
taosMemoryFreeClear(req.stbCfg.pRSmaParam);
|
||||
taosMemoryFreeClear(req.stbCfg.pSchema);
|
||||
if (mndConvertRSmaTask(pStb->pAst2, 0, 0, &req.pRSmaParam.qmsg2, &req.pRSmaParam.qmsg2Len) != TSDB_CODE_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
req.stbCfg.pRSmaParam = pRSmaParam;
|
||||
}
|
||||
// get length
|
||||
int32_t ret = 0;
|
||||
tEncodeSize(tEncodeSVCreateStbReq, &req, contLen, ret);
|
||||
if (ret < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t contLen = tSerializeSVCreateTbReq(NULL, &req) + sizeof(SMsgHead);
|
||||
contLen += sizeof(SMsgHead);
|
||||
|
||||
SMsgHead *pHead = taosMemoryMalloc(contLen);
|
||||
if (pHead == NULL) {
|
||||
if (pRSmaParam) {
|
||||
taosMemoryFreeClear(pRSmaParam->qmsg1);
|
||||
taosMemoryFreeClear(pRSmaParam->qmsg2);
|
||||
taosMemoryFreeClear(pRSmaParam);
|
||||
}
|
||||
taosMemoryFreeClear(req.stbCfg.pSchema);
|
||||
taosMemoryFreeClear(req.pRSmaParam.qmsg1);
|
||||
taosMemoryFreeClear(req.pRSmaParam.qmsg2);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -467,15 +415,15 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
|
|||
pHead->vgId = htonl(pVgroup->vgId);
|
||||
|
||||
void *pBuf = POINTER_SHIFT(pHead, sizeof(SMsgHead));
|
||||
tSerializeSVCreateTbReq(&pBuf, &req);
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pBuf, contLen - sizeof(SMsgHead), TD_ENCODER);
|
||||
if (tEncodeSVCreateStbReq(&coder, &req) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
tCoderClear(&coder);
|
||||
|
||||
*pContLen = contLen;
|
||||
if (pRSmaParam) {
|
||||
taosMemoryFreeClear(pRSmaParam->qmsg1);
|
||||
taosMemoryFreeClear(pRSmaParam->qmsg2);
|
||||
taosMemoryFreeClear(pRSmaParam);
|
||||
}
|
||||
taosMemoryFreeClear(req.stbCfg.pSchema);
|
||||
taosMemoryFreeClear(req.pRSmaParam.qmsg1);
|
||||
taosMemoryFreeClear(req.pRSmaParam.qmsg2);
|
||||
return pHead;
|
||||
}
|
||||
|
||||
|
@ -692,7 +640,6 @@ static int32_t mndCreateStb(SMnode *pMnode, SNodeMsg *pReq, SMCreateStbReq *pCre
|
|||
stbObj.ttl = pCreate->ttl;
|
||||
stbObj.numOfColumns = pCreate->numOfColumns;
|
||||
stbObj.numOfTags = pCreate->numOfTags;
|
||||
stbObj.numOfSmas = pCreate->numOfSmas;
|
||||
stbObj.commentLen = pCreate->commentLen;
|
||||
if (stbObj.commentLen > 0) {
|
||||
stbObj.comment = taosMemoryCalloc(stbObj.commentLen, 1);
|
||||
|
@ -725,8 +672,7 @@ static int32_t mndCreateStb(SMnode *pMnode, SNodeMsg *pReq, SMCreateStbReq *pCre
|
|||
|
||||
stbObj.pColumns = taosMemoryMalloc(stbObj.numOfColumns * sizeof(SSchema));
|
||||
stbObj.pTags = taosMemoryMalloc(stbObj.numOfTags * sizeof(SSchema));
|
||||
stbObj.pSmas = taosMemoryMalloc(stbObj.numOfSmas * sizeof(SSchema));
|
||||
if (stbObj.pColumns == NULL || stbObj.pTags == NULL || stbObj.pSmas == NULL) {
|
||||
if (stbObj.pColumns == NULL || stbObj.pTags == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
@ -736,6 +682,7 @@ static int32_t mndCreateStb(SMnode *pMnode, SNodeMsg *pReq, SMCreateStbReq *pCre
|
|||
SSchema *pSchema = &stbObj.pColumns[i];
|
||||
pSchema->type = pField->type;
|
||||
pSchema->bytes = pField->bytes;
|
||||
pSchema->flags = pField->flags;
|
||||
memcpy(pSchema->name, pField->name, TSDB_COL_NAME_LEN);
|
||||
pSchema->colId = stbObj.nextColId;
|
||||
stbObj.nextColId++;
|
||||
|
@ -751,18 +698,6 @@ static int32_t mndCreateStb(SMnode *pMnode, SNodeMsg *pReq, SMCreateStbReq *pCre
|
|||
stbObj.nextColId++;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < stbObj.numOfSmas; ++i) {
|
||||
SField *pField = taosArrayGet(pCreate->pSmas, i);
|
||||
SSchema *pSchema = &stbObj.pSmas[i];
|
||||
SSchema *pColSchema = mndFindStbColumns(&stbObj, pField->name);
|
||||
if (pColSchema == NULL) {
|
||||
mError("stb:%s, sma:%s not found in columns", stbObj.name, pField->name);
|
||||
terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
|
||||
return -1;
|
||||
}
|
||||
memcpy(pSchema, pColSchema, sizeof(SSchema));
|
||||
}
|
||||
|
||||
int32_t code = -1;
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_STB, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) goto _OVER;
|
||||
|
|
|
@ -22,13 +22,15 @@ static int32_t mndInitWal(SMnode *pMnode) {
|
|||
|
||||
char path[PATH_MAX] = {0};
|
||||
snprintf(path, sizeof(path), "%s%swal", pMnode->path, TD_DIRSEP);
|
||||
SWalCfg cfg = {.vgId = 1,
|
||||
.fsyncPeriod = 0,
|
||||
.rollPeriod = -1,
|
||||
.segSize = -1,
|
||||
.retentionPeriod = -1,
|
||||
.retentionSize = -1,
|
||||
.level = TAOS_WAL_FSYNC};
|
||||
SWalCfg cfg = {
|
||||
.vgId = 1,
|
||||
.fsyncPeriod = 0,
|
||||
.rollPeriod = -1,
|
||||
.segSize = -1,
|
||||
.retentionPeriod = -1,
|
||||
.retentionSize = -1,
|
||||
.level = TAOS_WAL_FSYNC,
|
||||
};
|
||||
pMgmt->pWal = walOpen(path, &cfg);
|
||||
if (pMgmt->pWal == NULL) return -1;
|
||||
|
||||
|
@ -54,62 +56,62 @@ static int32_t mndRestoreWal(SMnode *pMnode) {
|
|||
|
||||
int64_t first = walGetFirstVer(pWal);
|
||||
int64_t last = walGetLastVer(pWal);
|
||||
mDebug("start to restore sdb wal, sdb ver:%" PRId64 ", wal first:%" PRId64 " last:%" PRId64, lastSdbVer, first, last);
|
||||
mDebug("start to restore wal, sdbver:%" PRId64 ", first:%" PRId64 " last:%" PRId64, lastSdbVer, first, last);
|
||||
|
||||
first = TMAX(lastSdbVer + 1, first);
|
||||
for (int64_t ver = first; ver >= 0 && ver <= last; ++ver) {
|
||||
if (walReadWithHandle(pHandle, ver) < 0) {
|
||||
mError("failed to read by wal handle since %s, ver:%" PRId64, terrstr(), ver);
|
||||
goto WAL_RESTORE_OVER;
|
||||
mError("ver:%" PRId64 ", failed to read from wal since %s", ver, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
SWalHead *pHead = pHandle->pHead;
|
||||
int64_t sdbVer = sdbUpdateVer(pSdb, 0);
|
||||
if (sdbVer + 1 != ver) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_WAl_VER;
|
||||
mError("failed to read wal from sdb, sdbVer:%" PRId64 " inconsistent with ver:%" PRId64, sdbVer, ver);
|
||||
goto WAL_RESTORE_OVER;
|
||||
mError("ver:%" PRId64 ", failed to write to sdb, since inconsistent with sdbver:%" PRId64, ver, sdbVer);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
mTrace("wal:%" PRId64 ", will be restored, content:%p", ver, pHead->head.body);
|
||||
if (sdbWriteNotFree(pSdb, (void *)pHead->head.body) < 0) {
|
||||
mError("failed to read wal from sdb since %s, ver:%" PRId64, terrstr(), ver);
|
||||
goto WAL_RESTORE_OVER;
|
||||
mTrace("ver:%" PRId64 ", will be restored, content:%p", ver, pHead->head.body);
|
||||
if (sdbWriteWithoutFree(pSdb, (void *)pHead->head.body) < 0) {
|
||||
mError("ver:%" PRId64 ", failed to write to sdb since %s", ver, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
sdbUpdateVer(pSdb, 1);
|
||||
mDebug("wal:%" PRId64 ", is restored", ver);
|
||||
mDebug("ver:%" PRId64 ", is restored", ver);
|
||||
}
|
||||
|
||||
int64_t sdbVer = sdbUpdateVer(pSdb, 0);
|
||||
mDebug("restore sdb wal finished, sdb ver:%" PRId64, sdbVer);
|
||||
mDebug("restore wal finished, sdbver:%" PRId64, sdbVer);
|
||||
|
||||
mndTransPullup(pMnode);
|
||||
sdbVer = sdbUpdateVer(pSdb, 0);
|
||||
mDebug("pullup trans finished, sdb ver:%" PRId64, sdbVer);
|
||||
mDebug("pullup trans finished, sdbver:%" PRId64, sdbVer);
|
||||
|
||||
if (sdbVer != lastSdbVer) {
|
||||
mInfo("sdb restored from %" PRId64 " to %" PRId64 ", write file", lastSdbVer, sdbVer);
|
||||
if (sdbWriteFile(pSdb) != 0) {
|
||||
goto WAL_RESTORE_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (walCommit(pWal, sdbVer) != 0) {
|
||||
goto WAL_RESTORE_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (walBeginSnapshot(pWal, sdbVer) < 0) {
|
||||
goto WAL_RESTORE_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (walEndSnapshot(pWal) < 0) {
|
||||
goto WAL_RESTORE_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
}
|
||||
|
||||
code = 0;
|
||||
|
||||
WAL_RESTORE_OVER:
|
||||
_OVER:
|
||||
walCloseReadHandle(pHandle);
|
||||
return code;
|
||||
}
|
||||
|
@ -158,11 +160,11 @@ int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw) {
|
|||
int64_t ver = sdbUpdateVer(pSdb, 1);
|
||||
if (walWrite(pWal, ver, 1, pRaw, sdbGetRawTotalSize(pRaw)) < 0) {
|
||||
sdbUpdateVer(pSdb, -1);
|
||||
mError("failed to write raw:%p since %s, ver:%" PRId64, pRaw, terrstr(), ver);
|
||||
mError("ver:%" PRId64 ", failed to write raw:%p to wal since %s", ver, pRaw, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
mTrace("raw:%p, write to wal, ver:%" PRId64, pRaw, ver);
|
||||
mTrace("ver:%" PRId64 ", write to wal, raw:%p", ver, pRaw);
|
||||
walCommit(pWal, ver);
|
||||
walFsync(pWal, true);
|
||||
|
||||
|
|
|
@ -146,7 +146,6 @@ int32_t mndInitTelem(SMnode* pMnode) {
|
|||
taosGetEmail(pMgmt->email, sizeof(pMgmt->email));
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_TELEM_TIMER, mndProcessTelemTimer);
|
||||
|
||||
mDebug("mnode telemetry is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,6 @@ SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) {
|
|||
SDB_SET_INT64(pRaw, dataPos, pTopic->updateTime, TOPIC_ENCODE_OVER);
|
||||
SDB_SET_INT64(pRaw, dataPos, pTopic->uid, TOPIC_ENCODE_OVER);
|
||||
SDB_SET_INT64(pRaw, dataPos, pTopic->dbUid, TOPIC_ENCODE_OVER);
|
||||
SDB_SET_INT64(pRaw, dataPos, pTopic->subDbUid, TOPIC_ENCODE_OVER);
|
||||
SDB_SET_INT32(pRaw, dataPos, pTopic->version, TOPIC_ENCODE_OVER);
|
||||
SDB_SET_INT8(pRaw, dataPos, pTopic->subType, TOPIC_ENCODE_OVER);
|
||||
SDB_SET_INT8(pRaw, dataPos, pTopic->withTbName, TOPIC_ENCODE_OVER);
|
||||
|
@ -139,7 +138,6 @@ SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) {
|
|||
SDB_GET_INT64(pRaw, dataPos, &pTopic->updateTime, TOPIC_DECODE_OVER);
|
||||
SDB_GET_INT64(pRaw, dataPos, &pTopic->uid, TOPIC_DECODE_OVER);
|
||||
SDB_GET_INT64(pRaw, dataPos, &pTopic->dbUid, TOPIC_DECODE_OVER);
|
||||
SDB_GET_INT64(pRaw, dataPos, &pTopic->subDbUid, TOPIC_DECODE_OVER);
|
||||
SDB_GET_INT32(pRaw, dataPos, &pTopic->version, TOPIC_DECODE_OVER);
|
||||
SDB_GET_INT8(pRaw, dataPos, &pTopic->subType, TOPIC_DECODE_OVER);
|
||||
SDB_GET_INT8(pRaw, dataPos, &pTopic->withTbName, TOPIC_DECODE_OVER);
|
||||
|
@ -263,7 +261,7 @@ static SDDropTopicReq *mndBuildDropTopicMsg(SMnode *pMnode, SVgObj *pVgroup, SMq
|
|||
|
||||
static int32_t mndCheckCreateTopicReq(SCMCreateTopicReq *pCreate) {
|
||||
if (pCreate->name[0] == 0 || pCreate->sql == NULL || pCreate->sql[0] == 0 || pCreate->subscribeDbName[0] == 0) {
|
||||
terrno = TSDB_CODE_MND_INVALID_TOPIC_OPTION;
|
||||
terrno = TSDB_CODE_MND_INVALID_TOPIC;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -520,29 +518,33 @@ static int32_t mndRetrieveTopic(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pB
|
|||
pShow->pIter = sdbFetch(pSdb, SDB_TOPIC, pShow->pIter, (void **)&pTopic);
|
||||
if (pShow->pIter == NULL) break;
|
||||
|
||||
int32_t cols = 0;
|
||||
SColumnInfoData *pColInfo;
|
||||
SName n;
|
||||
int32_t cols = 0;
|
||||
|
||||
char topicName[TSDB_TOPIC_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
|
||||
SName n;
|
||||
tNameFromString(&n, pTopic->name, T_NAME_ACCT|T_NAME_DB);
|
||||
tNameFromString(&n, pTopic->name, T_NAME_ACCT | T_NAME_DB);
|
||||
tNameGetDbName(&n, varDataVal(topicName));
|
||||
varDataSetLen(topicName, strlen(varDataVal(topicName)));
|
||||
|
||||
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)topicName, false);
|
||||
|
||||
char dbName[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
tNameFromString(&n, pTopic->db, T_NAME_ACCT | T_NAME_DB);
|
||||
tNameGetDbName(&n, varDataVal(dbName));
|
||||
varDataSetLen(dbName, strlen(varDataVal(dbName)));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)dbName, false);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pTopic->createTime, false);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
char sql[TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
tstrncpy(&sql[VARSTR_HEADER_SIZE], pTopic->sql, TSDB_SHOW_SQL_LEN);
|
||||
varDataSetLen(sql, strlen(&sql[VARSTR_HEADER_SIZE]));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)sql, false);
|
||||
|
||||
// taosMemoryFree(sql);
|
||||
|
||||
numOfRows++;
|
||||
sdbRelease(pSdb, pTopic);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans);
|
|||
static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw);
|
||||
static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans);
|
||||
static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *OldTrans, STrans *pOld);
|
||||
static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans);
|
||||
static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans, bool callFunc);
|
||||
|
||||
static int32_t mndTransAppendLog(SArray *pArray, SSdbRaw *pRaw);
|
||||
static int32_t mndTransAppendAction(SArray *pArray, STransAction *pAction);
|
||||
|
@ -174,6 +174,13 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) {
|
|||
SDB_SET_BINARY(pRaw, dataPos, (void *)pAction->pCont, pAction->contLen, TRANS_ENCODE_OVER)
|
||||
}
|
||||
|
||||
SDB_SET_INT32(pRaw, dataPos, pTrans->startFunc, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pTrans->stopFunc, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pTrans->paramLen, TRANS_ENCODE_OVER)
|
||||
if (pTrans->param != NULL) {
|
||||
SDB_SET_BINARY(pRaw, dataPos, pTrans->param, pTrans->paramLen, TRANS_ENCODE_OVER)
|
||||
}
|
||||
|
||||
SDB_SET_RESERVE(pRaw, dataPos, MND_TRANS_RESERVE_SIZE, TRANS_ENCODE_OVER)
|
||||
SDB_SET_DATALEN(pRaw, dataPos, TRANS_ENCODE_OVER)
|
||||
|
||||
|
@ -193,9 +200,9 @@ TRANS_ENCODE_OVER:
|
|||
static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
SSdbRow * pRow = NULL;
|
||||
STrans * pTrans = NULL;
|
||||
char * pData = NULL;
|
||||
SSdbRow *pRow = NULL;
|
||||
STrans *pTrans = NULL;
|
||||
char *pData = NULL;
|
||||
int32_t dataLen = 0;
|
||||
int8_t sver = 0;
|
||||
int32_t redoLogNum = 0;
|
||||
|
@ -305,6 +312,14 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
|
|||
action.pCont = NULL;
|
||||
}
|
||||
|
||||
SDB_GET_INT32(pRaw, dataPos, &pTrans->startFunc, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pTrans->stopFunc, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pTrans->paramLen, TRANS_DECODE_OVER)
|
||||
if (pTrans->paramLen != 0) {
|
||||
pTrans->param = taosMemoryMalloc(pTrans->paramLen);
|
||||
SDB_GET_BINARY(pRaw, dataPos, pTrans->param, pTrans->paramLen, TRANS_DECODE_OVER);
|
||||
}
|
||||
|
||||
SDB_GET_RESERVE(pRaw, dataPos, MND_TRANS_RESERVE_SIZE, TRANS_DECODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
@ -413,9 +428,36 @@ static const char *mndTransType(ETrnType type) {
|
|||
}
|
||||
}
|
||||
|
||||
static void mndTransTestStartFunc(SMnode *pMnode, void *param, int32_t paramLen) {
|
||||
mInfo("test trans start, param:%s, len:%d", (char *)param, paramLen);
|
||||
}
|
||||
|
||||
static void mndTransTestStopFunc(SMnode *pMnode, void *param, int32_t paramLen) {
|
||||
mInfo("test trans stop, param:%s, len:%d", (char *)param, paramLen);
|
||||
}
|
||||
|
||||
static TransCbFp mndTransGetCbFp(ETrnFuncType ftype) {
|
||||
switch (ftype) {
|
||||
case TEST_TRANS_START_FUNC:
|
||||
return mndTransTestStartFunc;
|
||||
case TEST_TRANS_STOP_FUNC:
|
||||
return mndTransTestStopFunc;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans) {
|
||||
// pTrans->stage = TRN_STAGE_PREPARE;
|
||||
mTrace("trans:%d, perform insert action, row:%p stage:%s", pTrans->id, pTrans, mndTransStr(pTrans->stage));
|
||||
|
||||
if (pTrans->startFunc > 0) {
|
||||
TransCbFp fp = mndTransGetCbFp(pTrans->startFunc);
|
||||
if (fp) {
|
||||
(*fp)(pSdb->pMnode, pTrans->param, pTrans->paramLen);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -430,10 +472,23 @@ static void mndTransDropData(STrans *pTrans) {
|
|||
pTrans->rpcRsp = NULL;
|
||||
pTrans->rpcRspLen = 0;
|
||||
}
|
||||
if (pTrans->param != NULL) {
|
||||
taosMemoryFree(pTrans->param);
|
||||
pTrans->param = NULL;
|
||||
pTrans->paramLen = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans) {
|
||||
mTrace("trans:%d, perform delete action, row:%p stage:%s", pTrans->id, pTrans, mndTransStr(pTrans->stage));
|
||||
static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans, bool callFunc) {
|
||||
mDebug("trans:%d, perform delete action, row:%p stage:%s callfunc:%d", pTrans->id, pTrans, mndTransStr(pTrans->stage),
|
||||
callFunc);
|
||||
if (pTrans->stopFunc > 0 && callFunc) {
|
||||
TransCbFp fp = mndTransGetCbFp(pTrans->stopFunc);
|
||||
if (fp) {
|
||||
(*fp)(pSdb->pMnode, pTrans->param, pTrans->paramLen);
|
||||
}
|
||||
}
|
||||
|
||||
mndTransDropData(pTrans);
|
||||
return 0;
|
||||
}
|
||||
|
@ -456,7 +511,7 @@ static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pOld, STrans *pNew) {
|
|||
}
|
||||
|
||||
static STrans *mndAcquireTrans(SMnode *pMnode, int32_t transId) {
|
||||
SSdb * pSdb = pMnode->pSdb;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
STrans *pTrans = sdbAcquire(pSdb, SDB_TRANS, &transId);
|
||||
if (pTrans == NULL) {
|
||||
terrno = TSDB_CODE_MND_TRANS_NOT_EXIST;
|
||||
|
@ -498,7 +553,7 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, ETrnType type, const S
|
|||
return NULL;
|
||||
}
|
||||
|
||||
mDebug("trans:%d, is created, data:%p", pTrans->id, pTrans);
|
||||
mDebug("trans:%d, local var is created, data:%p", pTrans->id, pTrans);
|
||||
return pTrans;
|
||||
}
|
||||
|
||||
|
@ -525,7 +580,7 @@ static void mndTransDropActions(SArray *pArray) {
|
|||
void mndTransDrop(STrans *pTrans) {
|
||||
if (pTrans != NULL) {
|
||||
mndTransDropData(pTrans);
|
||||
mDebug("trans:%d, is dropped, data:%p", pTrans->id, pTrans);
|
||||
mDebug("trans:%d, local var is freed, data:%p", pTrans->id, pTrans);
|
||||
taosMemoryFreeClear(pTrans);
|
||||
}
|
||||
}
|
||||
|
@ -574,6 +629,13 @@ void mndTransSetRpcRsp(STrans *pTrans, void *pCont, int32_t contLen) {
|
|||
pTrans->rpcRspLen = contLen;
|
||||
}
|
||||
|
||||
void mndTransSetCb(STrans *pTrans, ETrnFuncType startFunc, ETrnFuncType stopFunc, void *param, int32_t paramLen) {
|
||||
pTrans->startFunc = startFunc;
|
||||
pTrans->stopFunc = stopFunc;
|
||||
pTrans->param = param;
|
||||
pTrans->paramLen = paramLen;
|
||||
}
|
||||
|
||||
void mndTransSetDbInfo(STrans *pTrans, SDbObj *pDb) {
|
||||
pTrans->dbUid = pDb->uid;
|
||||
memcpy(pTrans->dbname, pDb->name, TSDB_DB_FNAME_LEN);
|
||||
|
@ -626,7 +688,7 @@ static int32_t mndCheckTransCanBeStartedInParallel(SMnode *pMnode, STrans *pNewT
|
|||
if (mndIsBasicTrans(pNewTrans)) return 0;
|
||||
|
||||
STrans *pTrans = NULL;
|
||||
void * pIter = NULL;
|
||||
void *pIter = NULL;
|
||||
int32_t code = 0;
|
||||
|
||||
while (1) {
|
||||
|
@ -830,14 +892,14 @@ HANDLE_ACTION_RSP_OVER:
|
|||
}
|
||||
|
||||
static int32_t mndTransExecuteLogs(SMnode *pMnode, SArray *pArray) {
|
||||
SSdb * pSdb = pMnode->pSdb;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t arraySize = taosArrayGetSize(pArray);
|
||||
|
||||
if (arraySize == 0) return 0;
|
||||
|
||||
for (int32_t i = 0; i < arraySize; ++i) {
|
||||
SSdbRaw *pRaw = taosArrayGetP(pArray, i);
|
||||
int32_t code = sdbWriteNotFree(pSdb, pRaw);
|
||||
int32_t code = sdbWriteWithoutFree(pSdb, pRaw);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
|
@ -1117,6 +1179,7 @@ static bool mndTransPerfromFinishedStage(SMnode *pMnode, STrans *pTrans) {
|
|||
}
|
||||
|
||||
mDebug("trans:%d, finished, code:0x%04x, failedTimes:%d", pTrans->id, pTrans->code, pTrans->failedTimes);
|
||||
|
||||
return continueExec;
|
||||
}
|
||||
|
||||
|
@ -1205,11 +1268,11 @@ static int32_t mndKillTrans(SMnode *pMnode, STrans *pTrans) {
|
|||
}
|
||||
|
||||
static int32_t mndProcessKillTransReq(SNodeMsg *pReq) {
|
||||
SMnode * pMnode = pReq->pNode;
|
||||
SMnode *pMnode = pReq->pNode;
|
||||
SKillTransReq killReq = {0};
|
||||
int32_t code = -1;
|
||||
SUserObj * pUser = NULL;
|
||||
STrans * pTrans = NULL;
|
||||
SUserObj *pUser = NULL;
|
||||
STrans *pTrans = NULL;
|
||||
|
||||
if (tDeserializeSKillTransReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &killReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
|
@ -1249,7 +1312,7 @@ KILL_OVER:
|
|||
|
||||
void mndTransPullup(SMnode *pMnode) {
|
||||
STrans *pTrans = NULL;
|
||||
void * pIter = NULL;
|
||||
void *pIter = NULL;
|
||||
|
||||
while (1) {
|
||||
pIter = sdbFetch(pMnode->pSdb, SDB_TRANS, pIter, (void **)&pTrans);
|
||||
|
@ -1264,11 +1327,11 @@ void mndTransPullup(SMnode *pMnode) {
|
|||
|
||||
static int32_t mndRetrieveTrans(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||
SMnode *pMnode = pReq->pNode;
|
||||
SSdb * pSdb = pMnode->pSdb;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t numOfRows = 0;
|
||||
STrans *pTrans = NULL;
|
||||
int32_t cols = 0;
|
||||
char * pWrite;
|
||||
char *pWrite;
|
||||
|
||||
while (numOfRows < rows) {
|
||||
pShow->pIter = sdbFetch(pSdb, SDB_TRANS, pShow->pIter, (void **)&pTrans);
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
#include "mndTrans.h"
|
||||
#include "tbase64.h"
|
||||
|
||||
#define TSDB_USER_VER_NUMBER 1
|
||||
#define TSDB_USER_RESERVE_SIZE 64
|
||||
#define USER_VER_NUMBER 1
|
||||
#define USER_RESERVE_SIZE 64
|
||||
|
||||
static int32_t mndCreateDefaultUsers(SMnode *pMnode);
|
||||
static SSdbRaw *mndUserActionEncode(SUserObj *pUser);
|
||||
|
@ -35,7 +35,7 @@ static int32_t mndProcessCreateUserReq(SNodeMsg *pReq);
|
|||
static int32_t mndProcessAlterUserReq(SNodeMsg *pReq);
|
||||
static int32_t mndProcessDropUserReq(SNodeMsg *pReq);
|
||||
static int32_t mndProcessGetUserAuthReq(SNodeMsg *pReq);
|
||||
static int32_t mndRetrieveUsers(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows);
|
||||
static int32_t mndRetrieveUsers(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
|
||||
static void mndCancelGetNextUser(SMnode *pMnode, void *pIter);
|
||||
|
||||
int32_t mndInitUser(SMnode *pMnode) {
|
||||
|
@ -93,39 +93,39 @@ static SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
|
|||
|
||||
int32_t numOfReadDbs = taosHashGetSize(pUser->readDbs);
|
||||
int32_t numOfWriteDbs = taosHashGetSize(pUser->writeDbs);
|
||||
int32_t size = sizeof(SUserObj) + TSDB_USER_RESERVE_SIZE + (numOfReadDbs + numOfWriteDbs) * TSDB_DB_FNAME_LEN;
|
||||
int32_t size = sizeof(SUserObj) + USER_RESERVE_SIZE + (numOfReadDbs + numOfWriteDbs) * TSDB_DB_FNAME_LEN;
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_USER, TSDB_USER_VER_NUMBER, size);
|
||||
if (pRaw == NULL) goto USER_ENCODE_OVER;
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_USER, USER_VER_NUMBER, size);
|
||||
if (pRaw == NULL) goto _OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_BINARY(pRaw, dataPos, pUser->user, TSDB_USER_LEN, USER_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pUser->pass, TSDB_PASSWORD_LEN, USER_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pUser->acct, TSDB_USER_LEN, USER_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pUser->createdTime, USER_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pUser->updateTime, USER_ENCODE_OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pUser->superUser, USER_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, numOfReadDbs, USER_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, numOfWriteDbs, USER_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pUser->user, TSDB_USER_LEN, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pUser->pass, TSDB_PASSWORD_LEN, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pUser->acct, TSDB_USER_LEN, _OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pUser->createdTime, _OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pUser->updateTime, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pUser->superUser, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, numOfReadDbs, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, numOfWriteDbs, _OVER)
|
||||
|
||||
char *db = taosHashIterate(pUser->readDbs, NULL);
|
||||
while (db != NULL) {
|
||||
SDB_SET_BINARY(pRaw, dataPos, db, TSDB_DB_FNAME_LEN, USER_ENCODE_OVER);
|
||||
SDB_SET_BINARY(pRaw, dataPos, db, TSDB_DB_FNAME_LEN, _OVER);
|
||||
db = taosHashIterate(pUser->readDbs, db);
|
||||
}
|
||||
|
||||
db = taosHashIterate(pUser->writeDbs, NULL);
|
||||
while (db != NULL) {
|
||||
SDB_SET_BINARY(pRaw, dataPos, db, TSDB_DB_FNAME_LEN, USER_ENCODE_OVER);
|
||||
SDB_SET_BINARY(pRaw, dataPos, db, TSDB_DB_FNAME_LEN, _OVER);
|
||||
db = taosHashIterate(pUser->writeDbs, db);
|
||||
}
|
||||
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_USER_RESERVE_SIZE, USER_ENCODE_OVER)
|
||||
SDB_SET_DATALEN(pRaw, dataPos, USER_ENCODE_OVER)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, USER_RESERVE_SIZE, _OVER)
|
||||
SDB_SET_DATALEN(pRaw, dataPos, _OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
USER_ENCODE_OVER:
|
||||
_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("user:%s, failed to encode to raw:%p since %s", pUser->user, pRaw, terrstr());
|
||||
sdbFreeRaw(pRaw);
|
||||
|
@ -140,55 +140,55 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
|
|||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto USER_DECODE_OVER;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
|
||||
|
||||
if (sver != TSDB_USER_VER_NUMBER) {
|
||||
if (sver != USER_VER_NUMBER) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
goto USER_DECODE_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SUserObj));
|
||||
if (pRow == NULL) goto USER_DECODE_OVER;
|
||||
if (pRow == NULL) goto _OVER;
|
||||
|
||||
SUserObj *pUser = sdbGetRowObj(pRow);
|
||||
if (pUser == NULL) goto USER_DECODE_OVER;
|
||||
|
||||
pUser->readDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, true);
|
||||
pUser->writeDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, true);
|
||||
if (pUser->readDbs == NULL || pUser->writeDbs == NULL) goto USER_DECODE_OVER;
|
||||
if (pUser == NULL) goto _OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_BINARY(pRaw, dataPos, pUser->user, TSDB_USER_LEN, USER_DECODE_OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pUser->pass, TSDB_PASSWORD_LEN, USER_DECODE_OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pUser->acct, TSDB_USER_LEN, USER_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pUser->createdTime, USER_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pUser->updateTime, USER_DECODE_OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pUser->superUser, USER_DECODE_OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pUser->user, TSDB_USER_LEN, _OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pUser->pass, TSDB_PASSWORD_LEN, _OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pUser->acct, TSDB_USER_LEN, _OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pUser->createdTime, _OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pUser->updateTime, _OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pUser->superUser, _OVER)
|
||||
|
||||
int32_t numOfReadDbs = 0;
|
||||
int32_t numOfWriteDbs = 0;
|
||||
SDB_GET_INT32(pRaw, dataPos, &numOfReadDbs, USER_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &numOfWriteDbs, USER_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &numOfReadDbs, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &numOfWriteDbs, _OVER)
|
||||
pUser->readDbs = taosHashInit(numOfReadDbs, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
pUser->writeDbs =
|
||||
taosHashInit(numOfWriteDbs, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
if (pUser->readDbs == NULL || pUser->writeDbs == NULL) goto _OVER;
|
||||
|
||||
for (int32_t i = 0; i < numOfReadDbs; ++i) {
|
||||
char db[TSDB_DB_FNAME_LEN] = {0};
|
||||
SDB_GET_BINARY(pRaw, dataPos, db, TSDB_DB_FNAME_LEN, USER_DECODE_OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, db, TSDB_DB_FNAME_LEN, _OVER)
|
||||
int32_t len = strlen(db) + 1;
|
||||
taosHashPut(pUser->readDbs, db, len, db, TSDB_DB_FNAME_LEN);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfWriteDbs; ++i) {
|
||||
char db[TSDB_DB_FNAME_LEN] = {0};
|
||||
SDB_GET_BINARY(pRaw, dataPos, db, TSDB_DB_FNAME_LEN, USER_DECODE_OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, db, TSDB_DB_FNAME_LEN, _OVER)
|
||||
int32_t len = strlen(db) + 1;
|
||||
taosHashPut(pUser->writeDbs, db, len, db, TSDB_DB_FNAME_LEN);
|
||||
}
|
||||
|
||||
SDB_GET_RESERVE(pRaw, dataPos, TSDB_USER_RESERVE_SIZE, USER_DECODE_OVER)
|
||||
SDB_GET_RESERVE(pRaw, dataPos, USER_RESERVE_SIZE, _OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
USER_DECODE_OVER:
|
||||
_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("user:%s, failed to decode from raw:%p since %s", pUser->user, pRaw, terrstr());
|
||||
taosHashCleanup(pUser->readDbs);
|
||||
|
@ -220,6 +220,8 @@ static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) {
|
|||
mTrace("user:%s, perform delete action, row:%p", pUser->user, pUser);
|
||||
taosHashCleanup(pUser->readDbs);
|
||||
taosHashCleanup(pUser->writeDbs);
|
||||
pUser->readDbs = NULL;
|
||||
pUser->writeDbs = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -228,13 +230,8 @@ static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOld, SUserObj *pNew) {
|
|||
memcpy(pOld->pass, pNew->pass, TSDB_PASSWORD_LEN);
|
||||
pOld->updateTime = pNew->updateTime;
|
||||
|
||||
void *tmp1 = pOld->readDbs;
|
||||
pOld->readDbs = pNew->readDbs;
|
||||
pNew->readDbs = tmp1;
|
||||
|
||||
void *tmp2 = pOld->writeDbs;
|
||||
pOld->writeDbs = pNew->writeDbs;
|
||||
pNew->writeDbs = tmp2;
|
||||
TSWAP(pOld->readDbs, pNew->readDbs);
|
||||
TSWAP(pOld->writeDbs, pNew->writeDbs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -277,6 +274,9 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, SCreateUserReq *pCreate
|
|||
}
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY);
|
||||
|
||||
char *param = strdup("====> test code to be deleted later <=====");
|
||||
mndTransSetCb(pTrans, TEST_TRANS_START_FUNC, TEST_TRANS_STOP_FUNC, param, strlen(param) + 1);
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
|
@ -296,41 +296,41 @@ static int32_t mndProcessCreateUserReq(SNodeMsg *pReq) {
|
|||
|
||||
if (tDeserializeSCreateUserReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &createReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto CREATE_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
mDebug("user:%s, start to create", createReq.user);
|
||||
|
||||
if (createReq.user[0] == 0) {
|
||||
terrno = TSDB_CODE_MND_INVALID_USER_FORMAT;
|
||||
goto CREATE_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (createReq.pass[0] == 0) {
|
||||
terrno = TSDB_CODE_MND_INVALID_PASS_FORMAT;
|
||||
goto CREATE_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pUser = mndAcquireUser(pMnode, createReq.user);
|
||||
if (pUser != NULL) {
|
||||
terrno = TSDB_CODE_MND_USER_ALREADY_EXIST;
|
||||
goto CREATE_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pOperUser = mndAcquireUser(pMnode, pReq->user);
|
||||
if (pOperUser == NULL) {
|
||||
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||
goto CREATE_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndCheckCreateUserAuth(pOperUser) != 0) {
|
||||
goto CREATE_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
code = mndCreateUser(pMnode, pOperUser->acct, &createReq, pReq);
|
||||
if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
|
||||
CREATE_USER_OVER:
|
||||
_OVER:
|
||||
if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
||||
mError("user:%s, failed to create since %s", createReq.user, terrstr());
|
||||
}
|
||||
|
@ -341,13 +341,13 @@ CREATE_USER_OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SNodeMsg *pReq) {
|
||||
static int32_t mndAlterUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SNodeMsg *pReq) {
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_ALTER_USER, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) {
|
||||
mError("user:%s, failed to update since %s", pOld->user, terrstr());
|
||||
mError("user:%s, failed to alter since %s", pOld->user, terrstr());
|
||||
return -1;
|
||||
}
|
||||
mDebug("trans:%d, used to update user:%s", pTrans->id, pOld->user);
|
||||
mDebug("trans:%d, used to alter user:%s", pTrans->id, pOld->user);
|
||||
|
||||
SSdbRaw *pRedoRaw = mndUserActionEncode(pNew);
|
||||
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) {
|
||||
|
@ -368,7 +368,8 @@ static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SNo
|
|||
}
|
||||
|
||||
static SHashObj *mndDupDbHash(SHashObj *pOld) {
|
||||
SHashObj *pNew = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, true);
|
||||
SHashObj *pNew =
|
||||
taosHashInit(taosHashGetSize(pOld), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
if (pNew == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
|
@ -379,8 +380,8 @@ static SHashObj *mndDupDbHash(SHashObj *pOld) {
|
|||
int32_t len = strlen(db) + 1;
|
||||
if (taosHashPut(pNew, db, len, db, TSDB_DB_FNAME_LEN) != 0) {
|
||||
taosHashCancelIterate(pOld, db);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosHashCleanup(pNew);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
db = taosHashIterate(pOld, db);
|
||||
|
@ -399,38 +400,38 @@ static int32_t mndProcessAlterUserReq(SNodeMsg *pReq) {
|
|||
|
||||
if (tDeserializeSAlterUserReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &alterReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto ALTER_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
mDebug("user:%s, start to alter", alterReq.user);
|
||||
|
||||
if (alterReq.user[0] == 0) {
|
||||
terrno = TSDB_CODE_MND_INVALID_USER_FORMAT;
|
||||
goto ALTER_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (alterReq.pass[0] == 0) {
|
||||
terrno = TSDB_CODE_MND_INVALID_PASS_FORMAT;
|
||||
goto ALTER_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pUser = mndAcquireUser(pMnode, alterReq.user);
|
||||
if (pUser == NULL) {
|
||||
terrno = TSDB_CODE_MND_USER_NOT_EXIST;
|
||||
goto ALTER_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pOperUser = mndAcquireUser(pMnode, pReq->user);
|
||||
if (pOperUser == NULL) {
|
||||
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||
goto ALTER_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
memcpy(&newUser, pUser, sizeof(SUserObj));
|
||||
newUser.readDbs = mndDupDbHash(pUser->readDbs);
|
||||
newUser.writeDbs = mndDupDbHash(pUser->writeDbs);
|
||||
if (newUser.readDbs == NULL || newUser.writeDbs == NULL) {
|
||||
goto ALTER_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
int32_t len = strlen(alterReq.dbname) + 1;
|
||||
|
@ -440,56 +441,56 @@ static int32_t mndProcessAlterUserReq(SNodeMsg *pReq) {
|
|||
if (alterReq.alterType == TSDB_ALTER_USER_PASSWD) {
|
||||
char pass[TSDB_PASSWORD_LEN + 1] = {0};
|
||||
taosEncryptPass_c((uint8_t *)alterReq.pass, strlen(alterReq.pass), pass);
|
||||
memcpy(pUser->pass, pass, TSDB_PASSWORD_LEN);
|
||||
memcpy(newUser.pass, pass, TSDB_PASSWORD_LEN);
|
||||
} else if (alterReq.alterType == TSDB_ALTER_USER_SUPERUSER) {
|
||||
newUser.superUser = alterReq.superUser;
|
||||
} else if (alterReq.alterType == TSDB_ALTER_USER_ADD_READ_DB) {
|
||||
if (pDb == NULL) {
|
||||
terrno = TSDB_CODE_MND_DB_NOT_EXIST;
|
||||
goto ALTER_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
if (taosHashPut(newUser.readDbs, alterReq.dbname, len, alterReq.dbname, TSDB_DB_FNAME_LEN) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto ALTER_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
} else if (alterReq.alterType == TSDB_ALTER_USER_REMOVE_READ_DB) {
|
||||
if (taosHashRemove(newUser.readDbs, alterReq.dbname, len) != 0) {
|
||||
terrno = TSDB_CODE_MND_DB_NOT_EXIST;
|
||||
goto ALTER_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
} else if (alterReq.alterType == TSDB_ALTER_USER_CLEAR_READ_DB) {
|
||||
taosHashClear(newUser.readDbs);
|
||||
} else if (alterReq.alterType == TSDB_ALTER_USER_ADD_WRITE_DB) {
|
||||
if (pDb == NULL) {
|
||||
terrno = TSDB_CODE_MND_DB_NOT_EXIST;
|
||||
goto ALTER_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
if (taosHashPut(newUser.writeDbs, alterReq.dbname, len, alterReq.dbname, TSDB_DB_FNAME_LEN) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto ALTER_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
} else if (alterReq.alterType == TSDB_ALTER_USER_REMOVE_WRITE_DB) {
|
||||
if (taosHashRemove(newUser.writeDbs, alterReq.dbname, len) != 0) {
|
||||
terrno = TSDB_CODE_MND_DB_NOT_EXIST;
|
||||
goto ALTER_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
} else if (alterReq.alterType == TSDB_ALTER_USER_CLEAR_WRITE_DB) {
|
||||
taosHashClear(newUser.writeDbs);
|
||||
} else {
|
||||
terrno = TSDB_CODE_MND_INVALID_ALTER_OPER;
|
||||
goto ALTER_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
newUser.updateTime = taosGetTimestampMs();
|
||||
|
||||
if (mndCheckAlterUserAuth(pOperUser, pUser, pDb, &alterReq) != 0) {
|
||||
goto ALTER_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
code = mndUpdateUser(pMnode, pUser, &newUser, pReq);
|
||||
code = mndAlterUser(pMnode, pUser, &newUser, pReq);
|
||||
if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
|
||||
ALTER_USER_OVER:
|
||||
_OVER:
|
||||
if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
||||
mError("user:%s, failed to alter since %s", alterReq.user, terrstr());
|
||||
}
|
||||
|
@ -537,36 +538,36 @@ static int32_t mndProcessDropUserReq(SNodeMsg *pReq) {
|
|||
|
||||
if (tDeserializeSDropUserReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &dropReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto DROP_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
mDebug("user:%s, start to drop", dropReq.user);
|
||||
|
||||
if (dropReq.user[0] == 0) {
|
||||
terrno = TSDB_CODE_MND_INVALID_USER_FORMAT;
|
||||
goto DROP_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pUser = mndAcquireUser(pMnode, dropReq.user);
|
||||
if (pUser == NULL) {
|
||||
terrno = TSDB_CODE_MND_USER_NOT_EXIST;
|
||||
goto DROP_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pOperUser = mndAcquireUser(pMnode, pReq->user);
|
||||
if (pOperUser == NULL) {
|
||||
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||
goto DROP_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndCheckDropUserAuth(pOperUser) != 0) {
|
||||
goto DROP_USER_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
code = mndDropUser(pMnode, pReq, pUser);
|
||||
if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
|
||||
DROP_USER_OVER:
|
||||
_OVER:
|
||||
if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
||||
mError("user:%s, failed to drop since %s", dropReq.user, terrstr());
|
||||
}
|
||||
|
@ -586,7 +587,7 @@ static int32_t mndProcessGetUserAuthReq(SNodeMsg *pReq) {
|
|||
|
||||
if (tDeserializeSGetUserAuthReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &authReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto GET_AUTH_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
mTrace("user:%s, start to get auth", authReq.user);
|
||||
|
@ -594,7 +595,7 @@ static int32_t mndProcessGetUserAuthReq(SNodeMsg *pReq) {
|
|||
pUser = mndAcquireUser(pMnode, authReq.user);
|
||||
if (pUser == NULL) {
|
||||
terrno = TSDB_CODE_MND_USER_NOT_EXIST;
|
||||
goto GET_AUTH_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
memcpy(authRsp.user, pUser->user, TSDB_USER_LEN);
|
||||
|
@ -622,7 +623,7 @@ static int32_t mndProcessGetUserAuthReq(SNodeMsg *pReq) {
|
|||
void *pRsp = rpcMallocCont(contLen);
|
||||
if (pRsp == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto GET_AUTH_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
tSerializeSGetUserAuthRsp(pRsp, contLen, &authRsp);
|
||||
|
@ -631,15 +632,14 @@ static int32_t mndProcessGetUserAuthReq(SNodeMsg *pReq) {
|
|||
pReq->rspLen = contLen;
|
||||
code = 0;
|
||||
|
||||
GET_AUTH_OVER:
|
||||
_OVER:
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
taosHashCleanup(authRsp.readDbs);
|
||||
taosHashCleanup(authRsp.writeDbs);
|
||||
tFreeSGetUserAuthRsp(&authRsp);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndRetrieveUsers(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) {
|
||||
static int32_t mndRetrieveUsers(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||
SMnode *pMnode = pReq->pNode;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t numOfRows = 0;
|
||||
|
@ -652,29 +652,24 @@ static int32_t mndRetrieveUsers(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pB
|
|||
if (pShow->pIter == NULL) break;
|
||||
|
||||
cols = 0;
|
||||
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
|
||||
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
|
||||
|
||||
char name[TSDB_USER_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(name, pUser->user, pShow->bytes[cols]);
|
||||
|
||||
colDataAppend(pColInfo, numOfRows, (const char*) name, false);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)name, false);
|
||||
|
||||
cols++;
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
|
||||
|
||||
const char* src = pUser->superUser? "super":"normal";
|
||||
char b[10+VARSTR_HEADER_SIZE] = {0};
|
||||
const char *src = pUser->superUser ? "super" : "normal";
|
||||
char b[10 + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_WITH_SIZE_TO_VARSTR(b, src, strlen(src));
|
||||
colDataAppend(pColInfo, numOfRows, (const char*) b, false);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)b, false);
|
||||
|
||||
cols++;
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
|
||||
colDataAppend(pColInfo, numOfRows, (const char*) &pUser->createdTime, false);
|
||||
|
||||
cols++;
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(name, pUser->acct, pShow->bytes[cols]);
|
||||
colDataAppend(pColInfo, numOfRows, (const char*) name, false);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pUser->createdTime, false);
|
||||
|
||||
numOfRows++;
|
||||
sdbRelease(pSdb, pUser);
|
||||
|
|
|
@ -45,8 +45,8 @@ int32_t mndInitVgroup(SMnode *pMnode) {
|
|||
.encodeFp = (SdbEncodeFp)mndVgroupActionEncode,
|
||||
.decodeFp = (SdbDecodeFp)mndVgroupActionDecode,
|
||||
.insertFp = (SdbInsertFp)mndVgroupActionInsert,
|
||||
.updateFp = (SdbUpdateFp)mndVgroupActionDelete,
|
||||
.deleteFp = (SdbDeleteFp)mndVgroupActionUpdate};
|
||||
.updateFp = (SdbUpdateFp)mndVgroupActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mndVgroupActionDelete};
|
||||
|
||||
mndSetMsgHandle(pMnode, TDMT_DND_CREATE_VNODE_RSP, mndProcessCreateVnodeRsp);
|
||||
mndSetMsgHandle(pMnode, TDMT_VND_ALTER_VNODE_RSP, mndProcessAlterVnodeRsp);
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
#include "mndUser.h"
|
||||
#include "mndVgroup.h"
|
||||
|
||||
#define MQ_TIMER_MS 3000
|
||||
#define MQ_TIMER_MS 2000
|
||||
#define TRNAS_TIMER_MS 6000
|
||||
|
||||
static void *mndBuildTimerMsg(int32_t *pContLen) {
|
||||
|
@ -368,7 +368,7 @@ int32_t mndProcessMsg(SNodeMsg *pMsg) {
|
|||
}
|
||||
|
||||
if (isReq && (pRpc->contLen == 0 || pRpc->pCont == NULL)) {
|
||||
terrno = TSDB_CODE_MND_INVALID_MSG_LEN;
|
||||
terrno = TSDB_CODE_INVALID_MSG_LEN;
|
||||
mError("msg:%p, failed to process since %s, app:%p", pMsg, terrstr(), ahandle);
|
||||
return -1;
|
||||
}
|
||||
|
@ -418,7 +418,6 @@ int64_t mndGenerateUid(char *name, int32_t len) {
|
|||
} while (true);
|
||||
}
|
||||
|
||||
|
||||
int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgroupInfo *pVgroupInfo,
|
||||
SMonGrantInfo *pGrantInfo) {
|
||||
if (!mndIsMaster(pMnode)) return -1;
|
||||
|
@ -528,4 +527,4 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr
|
|||
int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad) {
|
||||
pLoad->syncState = pMnode->syncMgmt.state;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ add_subdirectory(func)
|
|||
add_subdirectory(mnode)
|
||||
add_subdirectory(profile)
|
||||
add_subdirectory(qnode)
|
||||
add_subdirectory(sdb)
|
||||
add_subdirectory(show)
|
||||
add_subdirectory(sma)
|
||||
add_subdirectory(snode)
|
||||
|
|
|
@ -32,7 +32,7 @@ TEST_F(MndTestAcct, 01_Create_Acct) {
|
|||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_ACCT, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MSG_NOT_PROCESSED);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MSG_NOT_PROCESSED);
|
||||
}
|
||||
|
||||
TEST_F(MndTestAcct, 02_Alter_Acct) {
|
||||
|
@ -42,7 +42,7 @@ TEST_F(MndTestAcct, 02_Alter_Acct) {
|
|||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_ACCT, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MSG_NOT_PROCESSED);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MSG_NOT_PROCESSED);
|
||||
}
|
||||
|
||||
TEST_F(MndTestAcct, 03_Drop_Acct) {
|
||||
|
@ -52,5 +52,5 @@ TEST_F(MndTestAcct, 03_Drop_Acct) {
|
|||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_ACCT, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MSG_NOT_PROCESSED);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MSG_NOT_PROCESSED);
|
||||
}
|
||||
|
|
|
@ -89,7 +89,6 @@ TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) {
|
|||
void* pReq = rpcMallocCont(contLen);
|
||||
tSerializeSAlterDbReq(pReq, contLen, &alterdbReq);
|
||||
|
||||
taosMsleep(1000); // Wait for the vnode to become the leader
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_DB, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
aux_source_directory(. MNODE_SDB_TEST_SRC)
|
||||
add_executable(sdbTest ${MNODE_SDB_TEST_SRC})
|
||||
target_link_libraries(
|
||||
sdbTest
|
||||
PUBLIC sut
|
||||
PUBLIC sdb
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME sdbTest
|
||||
COMMAND sdbTest
|
||||
)
|
|
@ -0,0 +1,83 @@
|
|||
/**
|
||||
* @file sdbTest.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief MNODE module sdb tests
|
||||
* @version 1.0
|
||||
* @date 2022-04-27
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sut.h"
|
||||
|
||||
class MndTestShow : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/mnode_test_show", 9021); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
};
|
||||
|
||||
Testbase MndTestShow::test;
|
||||
|
||||
TEST_F(MndTestShow, 01_ShowMsg_InvalidMsgMax) {
|
||||
SShowReq showReq = {0};
|
||||
showReq.type = TSDB_MGMT_TABLE_MAX;
|
||||
|
||||
int32_t contLen = tSerializeSShowReq(NULL, 0, &showReq);
|
||||
void* pReq = rpcMallocCont(contLen);
|
||||
tSerializeSShowReq(pReq, contLen, &showReq);
|
||||
tFreeSShowReq(&showReq);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_SYSTABLE_RETRIEVE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_NE(pRsp->code, 0);
|
||||
}
|
||||
|
||||
TEST_F(MndTestShow, 02_ShowMsg_InvalidMsgStart) {
|
||||
SShowReq showReq = {0};
|
||||
showReq.type = TSDB_MGMT_TABLE_START;
|
||||
|
||||
int32_t contLen = tSerializeSShowReq(NULL, 0, &showReq);
|
||||
void* pReq = rpcMallocCont(contLen);
|
||||
tSerializeSShowReq(pReq, contLen, &showReq);
|
||||
tFreeSShowReq(&showReq);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_SYSTABLE_RETRIEVE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_NE(pRsp->code, 0);
|
||||
}
|
||||
|
||||
TEST_F(MndTestShow, 03_ShowMsg_Conn) {
|
||||
char passwd[] = "taosdata";
|
||||
char secretEncrypt[TSDB_PASSWORD_LEN] = {0};
|
||||
taosEncryptPass_c((uint8_t*)passwd, strlen(passwd), secretEncrypt);
|
||||
|
||||
SConnectReq connectReq = {0};
|
||||
connectReq.pid = 1234;
|
||||
strcpy(connectReq.app, "mnode_test_show");
|
||||
strcpy(connectReq.db, "");
|
||||
strcpy(connectReq.user, "root");
|
||||
strcpy(connectReq.passwd, secretEncrypt);
|
||||
|
||||
int32_t contLen = tSerializeSConnectReq(NULL, 0, &connectReq);
|
||||
void* pReq = rpcMallocCont(contLen);
|
||||
tSerializeSConnectReq(pReq, contLen, &connectReq);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CONNECT, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
test.SendShowReq(TSDB_MGMT_TABLE_CONNS, "connections", "");
|
||||
// EXPECT_EQ(test.GetShowRows(), 1);
|
||||
}
|
||||
|
||||
TEST_F(MndTestShow, 04_ShowMsg_Cluster) {
|
||||
test.SendShowReq(TSDB_MGMT_TABLE_CLUSTER, "cluster", "");
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
}
|
|
@ -114,18 +114,15 @@ void* MndTestSma::BuildCreateBSmaStbReq(const char* stbname, int32_t* pContLen)
|
|||
SMCreateStbReq createReq = {0};
|
||||
createReq.numOfColumns = 3;
|
||||
createReq.numOfTags = 1;
|
||||
createReq.numOfSmas = 1;
|
||||
createReq.igExists = 0;
|
||||
createReq.pColumns = taosArrayInit(createReq.numOfColumns, sizeof(SField));
|
||||
createReq.pTags = taosArrayInit(createReq.numOfTags, sizeof(SField));
|
||||
createReq.pSmas = taosArrayInit(createReq.numOfSmas, sizeof(SField));
|
||||
strcpy(createReq.name, stbname);
|
||||
|
||||
PushField(createReq.pColumns, 8, TSDB_DATA_TYPE_TIMESTAMP, "ts");
|
||||
PushField(createReq.pColumns, 2, TSDB_DATA_TYPE_TINYINT, "col1");
|
||||
PushField(createReq.pColumns, 8, TSDB_DATA_TYPE_BIGINT, "col2");
|
||||
PushField(createReq.pTags, 2, TSDB_DATA_TYPE_TINYINT, "tag1");
|
||||
PushField(createReq.pSmas, 2, TSDB_DATA_TYPE_TINYINT, "col1");
|
||||
|
||||
int32_t tlen = tSerializeSMCreateStbReq(NULL, 0, &createReq);
|
||||
void* pHead = rpcMallocCont(tlen);
|
||||
|
@ -190,7 +187,7 @@ void* MndTestSma::BuildDropTSmaReq(const char* smaname, int8_t igNotExists, int3
|
|||
}
|
||||
|
||||
TEST_F(MndTestSma, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
||||
#if 0
|
||||
#if 0
|
||||
const char* dbname = "1.d1";
|
||||
const char* stbname = "1.d1.stb";
|
||||
const char* smaname = "1.d1.sma";
|
||||
|
@ -244,7 +241,7 @@ TEST_F(MndTestSma, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
|||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 0);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_F(MndTestSma, 02_Create_Show_Meta_Drop_Restart_BSma) {
|
||||
|
@ -258,14 +255,13 @@ TEST_F(MndTestSma, 02_Create_Show_Meta_Drop_Restart_BSma) {
|
|||
pReq = BuildCreateDbReq(dbname, &contLen);
|
||||
pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
taosMsleep(1000); // Wait for the vnode to become the leader
|
||||
}
|
||||
|
||||
{
|
||||
pReq = BuildCreateBSmaStbReq(stbname, &contLen);
|
||||
pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
test.SendShowReq(TSDB_MGMT_TABLE_STB, "user_stables",dbname);
|
||||
test.SendShowReq(TSDB_MGMT_TABLE_STB, "user_stables", dbname);
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
}
|
||||
|
||||
|
@ -281,7 +277,7 @@ TEST_F(MndTestSma, 02_Create_Show_Meta_Drop_Restart_BSma) {
|
|||
pReq = BuildDropStbReq(stbname, &contLen);
|
||||
pRsp = test.SendReq(TDMT_MND_DROP_STB, pReq, contLen);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
test.SendShowReq(TSDB_MGMT_TABLE_STB, "user_stables",dbname);
|
||||
test.SendShowReq(TSDB_MGMT_TABLE_STB, "user_stables", dbname);
|
||||
EXPECT_EQ(test.GetShowRows(), 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -304,7 +304,6 @@ TEST_F(MndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
|||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
taosMsleep(2000); // Wait for the vnode to become the leader
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -439,7 +438,6 @@ TEST_F(MndTestStb, 02_Alter_Stb_AddTag) {
|
|||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
taosMsleep(2000); // Wait for the vnode to become the leader
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -499,7 +497,6 @@ TEST_F(MndTestStb, 03_Alter_Stb_DropTag) {
|
|||
void* pReq = BuildCreateDbReq(dbname, &contLen);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
taosMsleep(2000); // Wait for the vnode to become the leader
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -541,7 +538,6 @@ TEST_F(MndTestStb, 04_Alter_Stb_AlterTagName) {
|
|||
void* pReq = BuildCreateDbReq(dbname, &contLen);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
taosMsleep(2000); // Wait for the vnode to become the leader
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -606,7 +602,6 @@ TEST_F(MndTestStb, 05_Alter_Stb_AlterTagBytes) {
|
|||
void* pReq = BuildCreateDbReq(dbname, &contLen);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
taosMsleep(2000); // Wait for the vnode to become the leader
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -660,7 +655,6 @@ TEST_F(MndTestStb, 06_Alter_Stb_AddColumn) {
|
|||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
taosMsleep(2000); // Wait for the vnode to become the leader
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -721,7 +715,6 @@ TEST_F(MndTestStb, 07_Alter_Stb_DropColumn) {
|
|||
void* pReq = BuildCreateDbReq(dbname, &contLen);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
taosMsleep(2000); // Wait for the vnode to become the leader
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -782,7 +775,6 @@ TEST_F(MndTestStb, 08_Alter_Stb_AlterTagBytes) {
|
|||
void* pReq = BuildCreateDbReq(dbname, &contLen);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
taosMsleep(2000); // Wait for the vnode to become the leader
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
@ -19,10 +19,6 @@
|
|||
#include "os.h"
|
||||
|
||||
#include "sdb.h"
|
||||
#include "thash.h"
|
||||
#include "tlockfree.h"
|
||||
#include "tlog.h"
|
||||
#include "tmsg.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -53,26 +49,6 @@ typedef struct SSdbRow {
|
|||
char pObj[];
|
||||
} SSdbRow;
|
||||
|
||||
typedef struct SSdb {
|
||||
SMnode *pMnode;
|
||||
char *currDir;
|
||||
char *syncDir;
|
||||
char *tmpDir;
|
||||
int64_t lastCommitVer;
|
||||
int64_t curVer;
|
||||
int64_t tableVer[SDB_MAX];
|
||||
int64_t maxId[SDB_MAX];
|
||||
EKeyType keyTypes[SDB_MAX];
|
||||
SHashObj *hashObjs[SDB_MAX];
|
||||
SRWLatch locks[SDB_MAX];
|
||||
SdbInsertFp insertFps[SDB_MAX];
|
||||
SdbUpdateFp updateFps[SDB_MAX];
|
||||
SdbDeleteFp deleteFps[SDB_MAX];
|
||||
SdbDeployFp deployFps[SDB_MAX];
|
||||
SdbEncodeFp encodeFps[SDB_MAX];
|
||||
SdbDecodeFp decodeFps[SDB_MAX];
|
||||
} SSdb;
|
||||
|
||||
const char *sdbTableName(ESdbType type);
|
||||
void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper);
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ void sdbCleanup(SSdb *pSdb) {
|
|||
SSdbRow *pRow = *ppRow;
|
||||
if (pRow == NULL) continue;
|
||||
|
||||
sdbFreeRow(pSdb, pRow);
|
||||
sdbFreeRow(pSdb, pRow, true);
|
||||
ppRow = taosHashIterate(hash, ppRow);
|
||||
}
|
||||
}
|
||||
|
@ -162,7 +162,4 @@ static int32_t sdbCreateDir(SSdb *pSdb) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int64_t sdbUpdateVer(SSdb *pSdb, int32_t val) {
|
||||
pSdb->curVer += val;
|
||||
return pSdb->curVer;
|
||||
}
|
||||
int64_t sdbUpdateVer(SSdb *pSdb, int32_t val) { return atomic_add_fetch_64(&pSdb->curVer, val); }
|
|
@ -28,7 +28,7 @@ static int32_t sdbRunDeployFp(SSdb *pSdb) {
|
|||
if (fp == NULL) continue;
|
||||
|
||||
if ((*fp)(pSdb->pMnode) != 0) {
|
||||
mError("failed to deploy sdb:%d since %s", i, terrstr());
|
||||
mError("failed to deploy sdb:%s since %s", sdbTableName(i), terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ int32_t sdbReadFile(SSdb *pSdb) {
|
|||
break;
|
||||
}
|
||||
|
||||
code = sdbWriteNotFree(pSdb, pRaw);
|
||||
code = sdbWriteWithoutFree(pSdb, pRaw);
|
||||
if (code != 0) {
|
||||
mError("failed to read file:%s since %s", file, terrstr());
|
||||
goto PARSE_SDB_DATA_ERROR;
|
||||
|
@ -263,7 +263,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb) {
|
|||
continue;
|
||||
}
|
||||
|
||||
sdbPrintOper(pSdb, pRow, "writeFile");
|
||||
sdbPrintOper(pSdb, pRow, "write");
|
||||
|
||||
SSdbRaw *pRaw = (*encodeFp)(pRow->pObj);
|
||||
if (pRaw != NULL) {
|
||||
|
|
|
@ -51,7 +51,9 @@ const char *sdbTableName(ESdbType type) {
|
|||
case SDB_TOPIC:
|
||||
return "topic";
|
||||
case SDB_VGROUP:
|
||||
return "vgId";
|
||||
return "vgroup";
|
||||
case SDB_SMA:
|
||||
return "sma";
|
||||
case SDB_STB:
|
||||
return "stb";
|
||||
case SDB_DB:
|
||||
|
@ -86,13 +88,13 @@ void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper) {
|
|||
EKeyType keyType = pSdb->keyTypes[pRow->type];
|
||||
|
||||
if (keyType == SDB_KEY_BINARY) {
|
||||
mTrace("%s:%s, refCount:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), (char *)pRow->pObj, pRow->refCount,
|
||||
oper, pRow->pObj, sdbStatusStr(pRow->status));
|
||||
mTrace("%s:%s, ref:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), (char *)pRow->pObj, pRow->refCount, oper,
|
||||
pRow->pObj, sdbStatusStr(pRow->status));
|
||||
} else if (keyType == SDB_KEY_INT32) {
|
||||
mTrace("%s:%d, refCount:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), *(int32_t *)pRow->pObj,
|
||||
pRow->refCount, oper, pRow->pObj, sdbStatusStr(pRow->status));
|
||||
mTrace("%s:%d, ref:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), *(int32_t *)pRow->pObj, pRow->refCount,
|
||||
oper, pRow->pObj, sdbStatusStr(pRow->status));
|
||||
} else if (keyType == SDB_KEY_INT64) {
|
||||
mTrace("%s:%" PRId64 ", refCount:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), *(int64_t *)pRow->pObj,
|
||||
mTrace("%s:%" PRId64 ", ref:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), *(int64_t *)pRow->pObj,
|
||||
pRow->refCount, oper, pRow->pObj, sdbStatusStr(pRow->status));
|
||||
} else {
|
||||
}
|
||||
|
@ -135,18 +137,18 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
|
|||
SSdbRow *pOldRow = taosHashGet(hash, pRow->pObj, keySize);
|
||||
if (pOldRow != NULL) {
|
||||
taosWUnLockLatch(pLock);
|
||||
sdbFreeRow(pSdb, pRow);
|
||||
sdbFreeRow(pSdb, pRow, false);
|
||||
terrno = TSDB_CODE_SDB_OBJ_ALREADY_THERE;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
pRow->refCount = 0;
|
||||
pRow->status = pRaw->status;
|
||||
sdbPrintOper(pSdb, pRow, "insertRow");
|
||||
sdbPrintOper(pSdb, pRow, "insert");
|
||||
|
||||
if (taosHashPut(hash, pRow->pObj, keySize, &pRow, sizeof(void *)) != 0) {
|
||||
taosWUnLockLatch(pLock);
|
||||
sdbFreeRow(pSdb, pRow);
|
||||
sdbFreeRow(pSdb, pRow, false);
|
||||
terrno = TSDB_CODE_SDB_OBJ_ALREADY_THERE;
|
||||
return terrno;
|
||||
}
|
||||
|
@ -162,7 +164,7 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
|
|||
taosWLockLatch(pLock);
|
||||
taosHashRemove(hash, pRow->pObj, keySize);
|
||||
taosWUnLockLatch(pLock);
|
||||
sdbFreeRow(pSdb, pRow);
|
||||
sdbFreeRow(pSdb, pRow, false);
|
||||
terrno = code;
|
||||
return terrno;
|
||||
}
|
||||
|
@ -191,7 +193,7 @@ static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
|
|||
|
||||
SSdbRow *pOldRow = *ppOldRow;
|
||||
pOldRow->status = pRaw->status;
|
||||
sdbPrintOper(pSdb, pOldRow, "updateRow");
|
||||
sdbPrintOper(pSdb, pOldRow, "update");
|
||||
taosRUnLockLatch(pLock);
|
||||
|
||||
int32_t code = 0;
|
||||
|
@ -200,7 +202,7 @@ static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
|
|||
code = (*updateFp)(pSdb, pOldRow->pObj, pNewRow->pObj);
|
||||
}
|
||||
|
||||
sdbFreeRow(pSdb, pNewRow);
|
||||
sdbFreeRow(pSdb, pNewRow, false);
|
||||
|
||||
pSdb->tableVer[pOldRow->type]++;
|
||||
return code;
|
||||
|
@ -213,27 +215,27 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
|
|||
SSdbRow **ppOldRow = taosHashGet(hash, pRow->pObj, keySize);
|
||||
if (ppOldRow == NULL || *ppOldRow == NULL) {
|
||||
taosWUnLockLatch(pLock);
|
||||
sdbFreeRow(pSdb, pRow);
|
||||
sdbFreeRow(pSdb, pRow, false);
|
||||
terrno = TSDB_CODE_SDB_OBJ_NOT_THERE;
|
||||
return terrno;
|
||||
}
|
||||
SSdbRow *pOldRow = *ppOldRow;
|
||||
|
||||
pOldRow->status = pRaw->status;
|
||||
sdbPrintOper(pSdb, pOldRow, "deleteRow");
|
||||
sdbPrintOper(pSdb, pOldRow, "delete");
|
||||
|
||||
taosHashRemove(hash, pOldRow->pObj, keySize);
|
||||
taosWUnLockLatch(pLock);
|
||||
|
||||
pSdb->tableVer[pOldRow->type]++;
|
||||
sdbFreeRow(pSdb, pRow);
|
||||
sdbFreeRow(pSdb, pRow, false);
|
||||
|
||||
sdbCheck(pSdb, pOldRow);
|
||||
// sdbRelease(pSdb, pOldRow->pObj);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t sdbWriteNotFree(SSdb *pSdb, SSdbRaw *pRaw) {
|
||||
int32_t sdbWriteWithoutFree(SSdb *pSdb, SSdbRaw *pRaw) {
|
||||
SHashObj *hash = sdbGetHash(pSdb, pRaw->type);
|
||||
if (hash == NULL) return terrno;
|
||||
|
||||
|
@ -266,7 +268,7 @@ int32_t sdbWriteNotFree(SSdb *pSdb, SSdbRaw *pRaw) {
|
|||
}
|
||||
|
||||
int32_t sdbWrite(SSdb *pSdb, SSdbRaw *pRaw) {
|
||||
int32_t code = sdbWriteNotFree(pSdb, pRaw);
|
||||
int32_t code = sdbWriteWithoutFree(pSdb, pRaw);
|
||||
sdbFreeRaw(pRaw);
|
||||
return code;
|
||||
}
|
||||
|
@ -296,7 +298,7 @@ void *sdbAcquire(SSdb *pSdb, ESdbType type, const void *pKey) {
|
|||
case SDB_STATUS_UPDATING:
|
||||
atomic_add_fetch_32(&pRow->refCount, 1);
|
||||
pRet = pRow->pObj;
|
||||
sdbPrintOper(pSdb, pRow, "acquireRow");
|
||||
sdbPrintOper(pSdb, pRow, "acquire");
|
||||
break;
|
||||
case SDB_STATUS_CREATING:
|
||||
terrno = TSDB_CODE_SDB_OBJ_CREATING;
|
||||
|
@ -318,9 +320,9 @@ static void sdbCheck(SSdb *pSdb, SSdbRow *pRow) {
|
|||
taosRLockLatch(pLock);
|
||||
|
||||
int32_t ref = atomic_load_32(&pRow->refCount);
|
||||
sdbPrintOper(pSdb, pRow, "checkRow");
|
||||
sdbPrintOper(pSdb, pRow, "check");
|
||||
if (ref <= 0 && pRow->status == SDB_STATUS_DROPPED) {
|
||||
sdbFreeRow(pSdb, pRow);
|
||||
sdbFreeRow(pSdb, pRow, true);
|
||||
}
|
||||
|
||||
taosRUnLockLatch(pLock);
|
||||
|
@ -330,15 +332,15 @@ void sdbRelease(SSdb *pSdb, void *pObj) {
|
|||
if (pObj == NULL) return;
|
||||
|
||||
SSdbRow *pRow = (SSdbRow *)((char *)pObj - sizeof(SSdbRow));
|
||||
if (pRow->type >= SDB_MAX ) return;
|
||||
if (pRow->type >= SDB_MAX) return;
|
||||
|
||||
SRWLatch *pLock = &pSdb->locks[pRow->type];
|
||||
taosRLockLatch(pLock);
|
||||
|
||||
int32_t ref = atomic_sub_fetch_32(&pRow->refCount, 1);
|
||||
sdbPrintOper(pSdb, pRow, "releaseRow");
|
||||
sdbPrintOper(pSdb, pRow, "release");
|
||||
if (ref <= 0 && pRow->status == SDB_STATUS_DROPPED) {
|
||||
sdbFreeRow(pSdb, pRow);
|
||||
sdbFreeRow(pSdb, pRow, true);
|
||||
}
|
||||
|
||||
taosRUnLockLatch(pLock);
|
||||
|
@ -372,7 +374,7 @@ void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) {
|
|||
}
|
||||
|
||||
atomic_add_fetch_32(&pRow->refCount, 1);
|
||||
sdbPrintOper(pSdb, pRow, "fetchRow");
|
||||
sdbPrintOper(pSdb, pRow, "fetch");
|
||||
*ppObj = pRow->pObj;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen) {
|
|||
pRaw->sver = sver;
|
||||
pRaw->dataLen = dataLen;
|
||||
|
||||
mTrace("raw:%p, is created, len:%d", pRaw, dataLen);
|
||||
mTrace("raw:%p, is created, len:%d table:%s", pRaw, dataLen, sdbTableName(type));
|
||||
return pRaw;
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,9 @@ int32_t sdbSetRawBinary(SSdbRaw *pRaw, int32_t dataPos, const char *pVal, int32_
|
|||
return -1;
|
||||
}
|
||||
|
||||
memcpy(pRaw->pData + dataPos, pVal, valLen);
|
||||
if (pVal != NULL) {
|
||||
memcpy(pRaw->pData + dataPos, pVal, valLen);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,14 +36,14 @@ void *sdbGetRowObj(SSdbRow *pRow) {
|
|||
return pRow->pObj;
|
||||
}
|
||||
|
||||
void sdbFreeRow(SSdb *pSdb, SSdbRow *pRow) {
|
||||
void sdbFreeRow(SSdb *pSdb, SSdbRow *pRow, bool callFunc) {
|
||||
// remove attached object such as trans
|
||||
SdbDeleteFp deleteFp = pSdb->deleteFps[pRow->type];
|
||||
if (deleteFp != NULL) {
|
||||
(*deleteFp)(pSdb, pRow->pObj);
|
||||
(*deleteFp)(pSdb, pRow->pObj, callFunc);
|
||||
}
|
||||
|
||||
sdbPrintOper(pSdb, pRow, "freeRow");
|
||||
sdbPrintOper(pSdb, pRow, "free");
|
||||
|
||||
mTrace("row:%p, is freed", pRow->pObj);
|
||||
taosMemoryFreeClear(pRow);
|
||||
|
|
|
@ -5,9 +5,7 @@ target_sources(
|
|||
PRIVATE
|
||||
# vnode
|
||||
"src/vnd/vnodeOpen.c"
|
||||
"src/vnd/vnodeArenaMAImpl.c"
|
||||
"src/vnd/vnodeBufferPool.c"
|
||||
# "src/vnd/vnodeBufferPool2.c"
|
||||
"src/vnd/vnodeBufPool.c"
|
||||
"src/vnd/vnodeCfg.c"
|
||||
"src/vnd/vnodeCommit.c"
|
||||
"src/vnd/vnodeInt.c"
|
||||
|
@ -21,18 +19,18 @@ target_sources(
|
|||
"src/meta/metaOpen.c"
|
||||
"src/meta/metaIdx.c"
|
||||
"src/meta/metaTable.c"
|
||||
"src/meta/metaTDBImpl.c"
|
||||
# "src/meta/metaBDBImpl.c"
|
||||
"src/meta/metaQuery.c"
|
||||
"src/meta/metaCommit.c"
|
||||
"src/meta/metaEntry.c"
|
||||
|
||||
# tsdb
|
||||
"src/tsdb/tsdbTDBImpl.c"
|
||||
"src/tsdb/tsdbCommit.c"
|
||||
"src/tsdb/tsdbCompact.c"
|
||||
"src/tsdb/tsdbCommit2.c"
|
||||
"src/tsdb/tsdbFile.c"
|
||||
"src/tsdb/tsdbFS.c"
|
||||
"src/tsdb/tsdbMain.c"
|
||||
"src/tsdb/tsdbOpen.c"
|
||||
"src/tsdb/tsdbMemTable.c"
|
||||
"src/tsdb/tsdbOptions.c"
|
||||
"src/tsdb/tsdbRead.c"
|
||||
"src/tsdb/tsdbReadImpl.c"
|
||||
"src/tsdb/tsdbScan.c"
|
||||
|
@ -71,6 +69,7 @@ target_link_libraries(
|
|||
PUBLIC transport
|
||||
PUBLIC stream
|
||||
)
|
||||
target_compile_definitions(vnode PUBLIC -DMETA_REFACT)
|
||||
|
||||
if(${BUILD_TEST})
|
||||
add_subdirectory(test)
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
#include "tmsg.h"
|
||||
#include "trow.h"
|
||||
|
||||
#include "tdbInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -59,37 +61,47 @@ int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg);
|
|||
int32_t vnodeCompact(SVnode *pVnode);
|
||||
int32_t vnodeSync(SVnode *pVnode);
|
||||
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad);
|
||||
int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName);
|
||||
int vnodeValidateTableHash(SVnode *pVnode, char *tableFName);
|
||||
|
||||
int32_t vnodeStart(SVnode *pVnode);
|
||||
void vnodeStop(SVnode *pVnode);
|
||||
|
||||
int64_t vnodeGetSyncHandle(SVnode *pVnode);
|
||||
void vnodeGetSnapshot(SVnode *pVnode, SSnapshot *pSnapshot);
|
||||
void vnodeGetInfo(SVnode *pVnode, const char **dbname, int32_t *vgId);
|
||||
|
||||
// meta
|
||||
typedef struct SMeta SMeta; // todo: remove
|
||||
typedef struct SMTbCursor SMTbCursor;
|
||||
typedef struct SMeta SMeta; // todo: remove
|
||||
typedef struct SMetaReader SMetaReader;
|
||||
typedef struct SMetaEntry SMetaEntry;
|
||||
|
||||
void metaReaderInit(SMetaReader *pReader, SMeta *pMeta, int32_t flags);
|
||||
void metaReaderClear(SMetaReader *pReader);
|
||||
int metaGetTableEntryByUid(SMetaReader *pReader, tb_uid_t uid);
|
||||
int metaReadNext(SMetaReader *pReader);
|
||||
|
||||
#if 1 // refact APIs below (TODO)
|
||||
typedef SVCreateTbReq STbCfg;
|
||||
typedef SVCreateTSmaReq SSmaCfg;
|
||||
|
||||
typedef struct SMTbCursor SMTbCursor;
|
||||
|
||||
SMTbCursor *metaOpenTbCursor(SMeta *pMeta);
|
||||
void metaCloseTbCursor(SMTbCursor *pTbCur);
|
||||
char *metaTbCursorNext(SMTbCursor *pTbCur);
|
||||
int metaTbCursorNext(SMTbCursor *pTbCur);
|
||||
#endif
|
||||
|
||||
// tsdb
|
||||
typedef struct STsdb STsdb;
|
||||
typedef struct STsdbQueryCond STsdbQueryCond;
|
||||
typedef void *tsdbReaderT;
|
||||
typedef struct STsdb STsdb;
|
||||
typedef void *tsdbReaderT;
|
||||
|
||||
#define BLOCK_LOAD_OFFSET_SEQ_ORDER 1
|
||||
#define BLOCK_LOAD_TABLE_SEQ_ORDER 2
|
||||
#define BLOCK_LOAD_TABLE_RR_ORDER 3
|
||||
|
||||
tsdbReaderT *tsdbQueryTables(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *tableInfoGroup, uint64_t qId,
|
||||
tsdbReaderT *tsdbQueryTables(STsdb *tsdb, SQueryTableDataCond *pCond, STableGroupInfo *tableInfoGroup, uint64_t qId,
|
||||
uint64_t taskId);
|
||||
tsdbReaderT tsdbQueryCacheLast(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList, uint64_t qId,
|
||||
tsdbReaderT tsdbQueryCacheLast(STsdb *tsdb, SQueryTableDataCond *pCond, STableGroupInfo *groupList, uint64_t qId,
|
||||
void *pMemRef);
|
||||
int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT *pReader, STableBlockDistInfo *pTableBlockInfo);
|
||||
bool isTsdbCacheLastRow(tsdbReaderT *pReader);
|
||||
|
@ -101,6 +113,7 @@ bool tsdbNextDataBlock(tsdbReaderT pTsdbReadHandle);
|
|||
void tsdbRetrieveDataBlockInfo(tsdbReaderT *pTsdbReadHandle, SDataBlockInfo *pBlockInfo);
|
||||
int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT *pTsdbReadHandle, SColumnDataAgg **pBlockStatis);
|
||||
SArray *tsdbRetrieveDataBlock(tsdbReaderT *pTsdbReadHandle, SArray *pColumnIdList);
|
||||
void tsdbResetReadHandle(tsdbReaderT queryHandle, SQueryTableDataCond *pCond);
|
||||
void tsdbDestroyTableGroup(STableGroupInfo *pGroupList);
|
||||
int32_t tsdbGetOneTableGroup(void *pMeta, uint64_t uid, TSKEY startKey, STableGroupInfo *pGroupInfo);
|
||||
int32_t tsdbGetTableGroupFromIdList(STsdb *tsdb, SArray *pTableIdList, STableGroupInfo *pGroupInfo);
|
||||
|
@ -122,34 +135,28 @@ int32_t tqRetrieveDataBlock(SArray **ppCols, STqReadHandle *pHandle, uint64_t *p
|
|||
// need to reposition
|
||||
|
||||
// structs
|
||||
struct SMetaCfg {
|
||||
uint64_t lruSize;
|
||||
};
|
||||
|
||||
struct STsdbCfg {
|
||||
int8_t precision;
|
||||
int8_t update;
|
||||
int8_t compression;
|
||||
int32_t days;
|
||||
int32_t minRows;
|
||||
int32_t maxRows;
|
||||
int32_t keep2;
|
||||
int32_t keep0;
|
||||
int32_t keep1;
|
||||
uint64_t lruCacheSize;
|
||||
SArray *retentions;
|
||||
int8_t precision;
|
||||
int8_t update;
|
||||
int8_t compression;
|
||||
int8_t slLevel;
|
||||
int32_t days;
|
||||
int32_t minRows;
|
||||
int32_t maxRows;
|
||||
int32_t keep0;
|
||||
int32_t keep1;
|
||||
int32_t keep2;
|
||||
SArray *retentions;
|
||||
};
|
||||
|
||||
struct SVnodeCfg {
|
||||
int32_t vgId;
|
||||
char dbname[TSDB_DB_NAME_LEN];
|
||||
uint64_t dbId;
|
||||
uint64_t wsize;
|
||||
uint64_t ssize;
|
||||
uint64_t lsize;
|
||||
bool isHeapAllocator;
|
||||
uint32_t ttl;
|
||||
uint32_t keep;
|
||||
int32_t szPage;
|
||||
int32_t szCache;
|
||||
uint64_t szBuf;
|
||||
bool isHeap;
|
||||
int8_t streamMode;
|
||||
bool isWeak;
|
||||
STsdbCfg tsdbCfg;
|
||||
|
@ -160,20 +167,53 @@ struct SVnodeCfg {
|
|||
int8_t hashMethod;
|
||||
};
|
||||
|
||||
struct STsdbQueryCond {
|
||||
STimeWindow twindow;
|
||||
int32_t order; // desc|asc order to iterate the data block
|
||||
int32_t numOfCols;
|
||||
SColumnInfo *colList;
|
||||
bool loadExternalRows; // load external rows or not
|
||||
int32_t type; // data block load type:
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
TSKEY lastKey;
|
||||
uint64_t uid;
|
||||
} STableKeyInfo;
|
||||
|
||||
struct SMetaEntry {
|
||||
int64_t version;
|
||||
int8_t type;
|
||||
tb_uid_t uid;
|
||||
const char *name;
|
||||
union {
|
||||
struct {
|
||||
SSchemaWrapper schema;
|
||||
SSchemaWrapper schemaTag;
|
||||
} stbEntry;
|
||||
struct {
|
||||
int64_t ctime;
|
||||
int32_t ttlDays;
|
||||
tb_uid_t suid;
|
||||
const void *pTags;
|
||||
} ctbEntry;
|
||||
struct {
|
||||
int64_t ctime;
|
||||
int32_t ttlDays;
|
||||
SSchemaWrapper schema;
|
||||
} ntbEntry;
|
||||
};
|
||||
};
|
||||
|
||||
struct SMetaReader {
|
||||
int32_t flags;
|
||||
SMeta *pMeta;
|
||||
SCoder coder;
|
||||
SMetaEntry me;
|
||||
void *pBuf;
|
||||
int szBuf;
|
||||
};
|
||||
|
||||
struct SMTbCursor {
|
||||
TDBC *pDbc;
|
||||
void *pKey;
|
||||
void *pVal;
|
||||
int kLen;
|
||||
int vLen;
|
||||
SMetaReader mr;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -16,13 +16,14 @@
|
|||
#ifndef _TD_VNODE_META_H_
|
||||
#define _TD_VNODE_META_H_
|
||||
|
||||
#include "vnodeInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SMetaIdx SMetaIdx;
|
||||
typedef struct SMetaDB SMetaDB;
|
||||
typedef struct SMCtbCursor SMCtbCursor;
|
||||
typedef struct SMSmaCursor SMSmaCursor;
|
||||
|
||||
// metaDebug ==================
|
||||
|
@ -36,8 +37,16 @@ typedef struct SMSmaCursor SMSmaCursor;
|
|||
// clang-format on
|
||||
|
||||
// metaOpen ==================
|
||||
int metaOpen(SVnode* pVnode, SMeta** ppMeta);
|
||||
int metaClose(SMeta* pMeta);
|
||||
|
||||
// metaEntry ==================
|
||||
int metaEncodeEntry(SCoder* pCoder, const SMetaEntry* pME);
|
||||
int metaDecodeEntry(SCoder* pCoder, SMetaEntry* pME);
|
||||
|
||||
// metaTable ==================
|
||||
int metaDropSTable(SMeta* pMeta, int64_t verison, SVDropStbReq* pReq);
|
||||
|
||||
// metaQuery ==================
|
||||
int metaGetTableEntryByVersion(SMetaReader* pReader, int64_t version, tb_uid_t uid);
|
||||
|
||||
// metaIdx ==================
|
||||
int metaOpenIdx(SMeta* pMeta);
|
||||
|
@ -45,32 +54,63 @@ void metaCloseIdx(SMeta* pMeta);
|
|||
int metaSaveTableToIdx(SMeta* pMeta, const STbCfg* pTbOptions);
|
||||
int metaRemoveTableFromIdx(SMeta* pMeta, tb_uid_t uid);
|
||||
|
||||
// metaCommit ==================
|
||||
static FORCE_INLINE tb_uid_t metaGenerateUid(SMeta* pMeta) { return tGenIdPI64(); }
|
||||
|
||||
#define META_SUPER_TABLE TD_SUPER_TABLE
|
||||
#define META_CHILD_TABLE TD_CHILD_TABLE
|
||||
#define META_NORMAL_TABLE TD_NORMAL_TABLE
|
||||
struct SMeta {
|
||||
char* path;
|
||||
SVnode* pVnode;
|
||||
TENV* pEnv;
|
||||
TXN txn;
|
||||
TDB* pTbDb;
|
||||
TDB* pSkmDb;
|
||||
TDB* pUidIdx;
|
||||
TDB* pNameIdx;
|
||||
TDB* pCtbIdx;
|
||||
TDB* pTagIdx;
|
||||
TDB* pTtlIdx;
|
||||
SMetaIdx* pIdx;
|
||||
};
|
||||
|
||||
int metaCreateTable(SMeta* pMeta, STbCfg* pTbCfg, STbDdlH* pHandle);
|
||||
int metaDropTable(SMeta* pMeta, tb_uid_t uid);
|
||||
int metaCommit(SMeta* pMeta);
|
||||
int32_t metaCreateTSma(SMeta* pMeta, SSmaCfg* pCfg);
|
||||
int32_t metaDropTSma(SMeta* pMeta, int64_t indexUid);
|
||||
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);
|
||||
void* metaGetSmaInfoByIndex(SMeta* pMeta, int64_t indexUid, bool isDecode);
|
||||
STSmaWrapper* metaGetSmaInfoByTable(SMeta* pMeta, tb_uid_t uid);
|
||||
SArray* metaGetSmaTbUids(SMeta* pMeta, bool isDup);
|
||||
int metaGetTbNum(SMeta* pMeta);
|
||||
SMSmaCursor* metaOpenSmaCursor(SMeta* pMeta, tb_uid_t uid);
|
||||
void metaCloseSmaCursor(SMSmaCursor* pSmaCur);
|
||||
int64_t metaSmaCursorNext(SMSmaCursor* pSmaCur);
|
||||
SMCtbCursor* metaOpenCtbCursor(SMeta* pMeta, tb_uid_t uid);
|
||||
void metaCloseCtbCurosr(SMCtbCursor* pCtbCur);
|
||||
tb_uid_t metaCtbCursorNext(SMCtbCursor* pCtbCur);
|
||||
typedef struct {
|
||||
int64_t version;
|
||||
tb_uid_t uid;
|
||||
} STbDbKey;
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef struct {
|
||||
tb_uid_t uid;
|
||||
int32_t sver;
|
||||
} SSkmDbKey;
|
||||
#pragma pack(pop)
|
||||
|
||||
typedef struct {
|
||||
tb_uid_t suid;
|
||||
tb_uid_t uid;
|
||||
} SCtbIdxKey;
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef struct {
|
||||
tb_uid_t suid;
|
||||
int16_t cid;
|
||||
char data[];
|
||||
} STagIdxKey;
|
||||
#pragma pack(pop)
|
||||
|
||||
typedef struct {
|
||||
int64_t dtime;
|
||||
tb_uid_t uid;
|
||||
} STtlIdxKey;
|
||||
|
||||
#if 1
|
||||
|
||||
// int metaCreateTable(SMeta* pMeta, STbCfg* pTbCfg, STbDdlH* pHandle);
|
||||
int metaDropTable(SMeta* pMeta, tb_uid_t uid);
|
||||
SMSmaCursor* metaOpenSmaCursor(SMeta* pMeta, tb_uid_t uid);
|
||||
void metaCloseSmaCursor(SMSmaCursor* pSmaCur);
|
||||
int64_t metaSmaCursorNext(SMSmaCursor* pSmaCur);
|
||||
|
||||
#ifndef META_REFACT
|
||||
// SMetaDB
|
||||
int metaOpenDB(SMeta* pMeta);
|
||||
void metaCloseDB(SMeta* pMeta);
|
||||
|
@ -78,17 +118,9 @@ int metaSaveTableToDB(SMeta* pMeta, STbCfg* pTbCfg, STbDdlH* pHandle);
|
|||
int metaRemoveTableFromDb(SMeta* pMeta, tb_uid_t uid);
|
||||
int metaSaveSmaToDB(SMeta* pMeta, STSma* pTbCfg);
|
||||
int metaRemoveSmaFromDb(SMeta* pMeta, int64_t indexUid);
|
||||
#endif
|
||||
|
||||
// SMetaIdx
|
||||
|
||||
tb_uid_t metaGenerateUid(SMeta* pMeta);
|
||||
|
||||
struct SMeta {
|
||||
char* path;
|
||||
SVnode* pVnode;
|
||||
SMetaDB* pDB;
|
||||
SMetaIdx* pIdx;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef _TD_VNODE_TQ_H_
|
||||
#define _TD_VNODE_TQ_H_
|
||||
|
||||
#include "vnodeInt.h"
|
||||
|
||||
#include "executor.h"
|
||||
#include "os.h"
|
||||
#include "tcache.h"
|
||||
|
@ -31,12 +33,12 @@ extern "C" {
|
|||
|
||||
// tqDebug ===================
|
||||
// clang-format off
|
||||
#define tqFatal(...) do { if (tqDebugFlag & DEBUG_FATAL) { taosPrintLog("TQ FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0)
|
||||
#define tqError(...) do { if (tqDebugFlag & DEBUG_ERROR) { taosPrintLog("TQ ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0)
|
||||
#define tqWarn(...) do { if (tqDebugFlag & DEBUG_WARN) { taosPrintLog("TQ WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0)
|
||||
#define tqInfo(...) do { if (tqDebugFlag & DEBUG_INFO) { taosPrintLog("TQ ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0)
|
||||
#define tqDebug(...) do { if (tqDebugFlag & DEBUG_DEBUG) { taosPrintLog("TQ ", DEBUG_DEBUG, tqDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define tqTrace(...) do { if (tqDebugFlag & DEBUG_TRACE) { taosPrintLog("TQ ", DEBUG_TRACE, tqDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define tqFatal(...) do { if (tqDebugFlag & DEBUG_FATAL) { taosPrintLog("TQ FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0)
|
||||
#define tqError(...) do { if (tqDebugFlag & DEBUG_ERROR) { taosPrintLog("TQ ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0)
|
||||
#define tqWarn(...) do { if (tqDebugFlag & DEBUG_WARN) { taosPrintLog("TQ WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0)
|
||||
#define tqInfo(...) do { if (tqDebugFlag & DEBUG_INFO) { taosPrintLog("TQ ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0)
|
||||
#define tqDebug(...) do { if (tqDebugFlag & DEBUG_DEBUG) { taosPrintLog("TQ ", DEBUG_DEBUG, tqDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define tqTrace(...) do { if (tqDebugFlag & DEBUG_TRACE) { taosPrintLog("TQ ", DEBUG_TRACE, tqDebugFlag, __VA_ARGS__); }} while(0)
|
||||
// clang-format on
|
||||
|
||||
#define TQ_BUFFER_SIZE 4
|
||||
|
@ -237,17 +239,7 @@ int tqInit();
|
|||
void tqCleanUp();
|
||||
|
||||
// open in each vnode
|
||||
STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal);
|
||||
void tqClose(STQ*);
|
||||
// required by vnode
|
||||
int tqPushMsg(STQ*, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver);
|
||||
int tqCommit(STQ*);
|
||||
|
||||
int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId);
|
||||
int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen);
|
||||
int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen, int32_t workerId);
|
||||
int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen);
|
||||
int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen, int32_t workerId);
|
||||
|
||||
int32_t tqSerializeConsumer(const STqConsumer*, STqSerializedHead**);
|
||||
int32_t tqDeserializeConsumer(STQ*, const STqSerializedHead*, STqConsumer**);
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef _TD_VNODE_TSDB_H_
|
||||
#define _TD_VNODE_TSDB_H_
|
||||
|
||||
#include "vnodeInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -30,33 +32,74 @@ extern "C" {
|
|||
#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSDB ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0)
|
||||
// clang-format on
|
||||
|
||||
typedef struct SSmaStat SSmaStat;
|
||||
// tsdbMemTable ================
|
||||
typedef struct STbData STbData;
|
||||
typedef struct STsdbMemTable STsdbMemTable;
|
||||
typedef struct SMergeInfo SMergeInfo;
|
||||
typedef struct STable STable;
|
||||
|
||||
int tsdbMemTableCreate(STsdb *pTsdb, STsdbMemTable **ppMemTable);
|
||||
void tsdbMemTableDestroy(STsdb *pTsdb, STsdbMemTable *pMemTable);
|
||||
int tsdbInsertTableData(STsdb *pTsdb, SSubmitBlk *pBlock, int32_t *pAffectedRows);
|
||||
int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey, int maxRowsToRead, SDataCols *pCols,
|
||||
TKEY *filterKeys, int nFilterKeys, bool keepDup, SMergeInfo *pMergeInfo);
|
||||
|
||||
// tsdbCommit ================
|
||||
|
||||
// tsdbFS ================
|
||||
typedef struct STsdbFS STsdbFS;
|
||||
|
||||
// tsdbSma ================
|
||||
typedef struct SSmaEnv SSmaEnv;
|
||||
typedef struct SSmaEnvs SSmaEnvs;
|
||||
|
||||
typedef struct STable {
|
||||
// structs
|
||||
typedef struct {
|
||||
int minFid;
|
||||
int midFid;
|
||||
int maxFid;
|
||||
TSKEY minKey;
|
||||
} SRtn;
|
||||
|
||||
struct SSmaEnvs {
|
||||
int16_t nTSma;
|
||||
int16_t nRSma;
|
||||
SSmaEnv *pTSmaEnv;
|
||||
SSmaEnv *pRSmaEnv;
|
||||
};
|
||||
|
||||
struct STsdb {
|
||||
char *path;
|
||||
SVnode *pVnode;
|
||||
bool repoLocked;
|
||||
TdThreadMutex mutex;
|
||||
STsdbCfg config;
|
||||
STsdbMemTable *mem;
|
||||
STsdbMemTable *imem;
|
||||
SRtn rtn;
|
||||
STsdbFS *fs;
|
||||
SSmaEnvs smaEnvs;
|
||||
};
|
||||
|
||||
#if 1 // ======================================
|
||||
|
||||
typedef struct SSmaStat SSmaStat;
|
||||
|
||||
struct STable {
|
||||
uint64_t tid;
|
||||
uint64_t uid;
|
||||
STSchema *pSchema;
|
||||
} STable;
|
||||
};
|
||||
|
||||
#define TABLE_TID(t) (t)->tid
|
||||
#define TABLE_UID(t) (t)->uid
|
||||
|
||||
STsdb *tsdbOpen(const char *path, SVnode *pVnode, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF);
|
||||
void tsdbClose(STsdb *);
|
||||
int tsdbInsertData(STsdb *pTsdb, SSubmitReq *pMsg, SSubmitRsp *pRsp);
|
||||
int tsdbPrepareCommit(STsdb *pTsdb);
|
||||
int tsdbCommit(STsdb *pTsdb);
|
||||
int32_t tsdbInitSma(STsdb *pTsdb);
|
||||
int32_t tsdbCreateTSma(STsdb *pTsdb, char *pMsg);
|
||||
int32_t tsdbDropTSma(STsdb *pTsdb, char *pMsg);
|
||||
int32_t tsdbUpdateSmaWindow(STsdb *pTsdb, SSubmitReq *pMsg, int64_t version);
|
||||
int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg);
|
||||
int32_t tsdbDropTSmaData(STsdb *pTsdb, int64_t indexUid);
|
||||
int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg);
|
||||
void tsdbCleanupReadHandle(tsdbReaderT queryHandle);
|
||||
int32_t tdScanAndConvertSubmitMsg(SSubmitReq *pMsg);
|
||||
typedef enum {
|
||||
TSDB_FILE_HEAD = 0, // .head
|
||||
TSDB_FILE_DATA, // .data
|
||||
|
@ -87,13 +130,6 @@ typedef struct {
|
|||
uint8_t state;
|
||||
} SDFile;
|
||||
|
||||
struct SSmaEnvs {
|
||||
int16_t nTSma;
|
||||
int16_t nRSma;
|
||||
SSmaEnv *pTSmaEnv;
|
||||
SSmaEnv *pRSmaEnv;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int fid;
|
||||
int8_t state; // -128~127
|
||||
|
@ -102,32 +138,28 @@ typedef struct {
|
|||
SDFile files[TSDB_FILE_MAX];
|
||||
} SDFileSet;
|
||||
|
||||
typedef struct {
|
||||
int minFid;
|
||||
int midFid;
|
||||
int maxFid;
|
||||
TSKEY minKey;
|
||||
} SRtn;
|
||||
|
||||
typedef struct STbData {
|
||||
struct STbData {
|
||||
tb_uid_t uid;
|
||||
TSKEY keyMin;
|
||||
TSKEY keyMax;
|
||||
int64_t minVer;
|
||||
int64_t maxVer;
|
||||
int64_t nrows;
|
||||
SSkipList *pData;
|
||||
} STbData;
|
||||
};
|
||||
|
||||
typedef struct STsdbMemTable {
|
||||
struct STsdbMemTable {
|
||||
SVBufPool *pPool;
|
||||
T_REF_DECLARE()
|
||||
SRWLatch latch;
|
||||
TSKEY keyMin;
|
||||
TSKEY keyMax;
|
||||
uint64_t nRow;
|
||||
SMemAllocator *pMA;
|
||||
// Container
|
||||
SRWLatch latch;
|
||||
TSKEY keyMin;
|
||||
TSKEY keyMax;
|
||||
int64_t minVer;
|
||||
int64_t maxVer;
|
||||
int64_t nRow;
|
||||
SSkipList *pSlIdx; // SSkiplist<STbData>
|
||||
SHashObj *pHashIdx;
|
||||
} STsdbMemTable;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint32_t version; // Commit version from 0 to increase
|
||||
|
@ -142,7 +174,7 @@ typedef struct {
|
|||
SArray *sf; // sma data file array v2f1900.index_name_1
|
||||
} SFSStatus;
|
||||
|
||||
typedef struct {
|
||||
struct STsdbFS {
|
||||
TdThreadRwlock lock;
|
||||
|
||||
SFSStatus *cstatus; // current status
|
||||
|
@ -150,24 +182,9 @@ typedef struct {
|
|||
SHashObj *metaCacheComp; // meta cache for compact
|
||||
bool intxn;
|
||||
SFSStatus *nstatus; // new status
|
||||
} STsdbFS;
|
||||
|
||||
struct STsdb {
|
||||
int32_t vgId;
|
||||
SVnode *pVnode;
|
||||
bool repoLocked;
|
||||
TdThreadMutex mutex;
|
||||
char *path;
|
||||
STsdbCfg config;
|
||||
STsdbMemTable *mem;
|
||||
STsdbMemTable *imem;
|
||||
SRtn rtn;
|
||||
SMemAllocatorFactory *pmaf;
|
||||
STsdbFS *fs;
|
||||
SSmaEnvs smaEnvs;
|
||||
};
|
||||
|
||||
#define REPO_ID(r) ((r)->vgId)
|
||||
#define REPO_ID(r) TD_VID((r)->pVnode)
|
||||
#define REPO_CFG(r) (&(r)->config)
|
||||
#define REPO_FS(r) ((r)->fs)
|
||||
#define REPO_META(r) ((r)->pVnode->pMeta)
|
||||
|
@ -186,7 +203,7 @@ static FORCE_INLINE STSchema *tsdbGetTableSchemaImpl(STable *pTable, bool lock,
|
|||
}
|
||||
|
||||
// tsdbMemTable.h
|
||||
typedef struct {
|
||||
struct SMergeInfo {
|
||||
int rowsInserted;
|
||||
int rowsUpdated;
|
||||
int rowsDeleteSucceed;
|
||||
|
@ -194,7 +211,7 @@ typedef struct {
|
|||
int nOperations;
|
||||
TSKEY keyFirst;
|
||||
TSKEY keyLast;
|
||||
} SMergeInfo;
|
||||
};
|
||||
|
||||
static void *taosTMalloc(size_t size);
|
||||
static void *taosTCalloc(size_t nmemb, size_t size);
|
||||
|
@ -203,12 +220,6 @@ static void *taosTZfree(void *ptr);
|
|||
static size_t taosTSizeof(void *ptr);
|
||||
static void taosTMemset(void *ptr, int c);
|
||||
|
||||
STsdbMemTable *tsdbNewMemTable(STsdb *pTsdb);
|
||||
void tsdbFreeMemTable(STsdb *pTsdb, STsdbMemTable *pMemTable);
|
||||
int tsdbMemTableInsert(STsdb *pTsdb, STsdbMemTable *pMemTable, SSubmitReq *pMsg, SSubmitRsp *pRsp);
|
||||
int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey, int maxRowsToRead, SDataCols *pCols,
|
||||
TKEY *filterKeys, int nFilterKeys, bool keepDup, SMergeInfo *pMergeInfo);
|
||||
|
||||
static FORCE_INLINE STSRow *tsdbNextIterRow(SSkipListIterator *pIter) {
|
||||
if (pIter == NULL) return NULL;
|
||||
|
||||
|
@ -225,12 +236,6 @@ static FORCE_INLINE TSKEY tsdbNextIterKey(SSkipListIterator *pIter) {
|
|||
return TD_ROW_KEY(row);
|
||||
}
|
||||
|
||||
// tsdbOptions
|
||||
extern const STsdbCfg defautlTsdbOptions;
|
||||
|
||||
int tsdbValidateOptions(const STsdbCfg *);
|
||||
void tsdbOptionsCopy(STsdbCfg *pDest, const STsdbCfg *pSrc);
|
||||
|
||||
// tsdbReadImpl
|
||||
typedef struct SReadH SReadH;
|
||||
|
||||
|
@ -507,12 +512,6 @@ static FORCE_INLINE void *taosTZfree(void *ptr) {
|
|||
|
||||
// tsdbCommit
|
||||
|
||||
typedef struct {
|
||||
uint64_t uid;
|
||||
int64_t offset;
|
||||
int64_t size;
|
||||
} SKVRecord;
|
||||
|
||||
void tsdbGetRtnSnap(STsdb *pRepo, SRtn *pRtn);
|
||||
|
||||
static FORCE_INLINE int TSDB_KEY_FID(TSKEY key, int32_t days, int8_t precision) {
|
||||
|
@ -891,66 +890,6 @@ static FORCE_INLINE int tsdbUnLockFS(STsdbFS *pFs) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
// tsdbSma
|
||||
// #define TSDB_SMA_TEST // remove after test finished
|
||||
|
||||
// struct SSmaEnv {
|
||||
// TdThreadRwlock lock;
|
||||
// SDiskID did;
|
||||
// TDBEnv dbEnv; // TODO: If it's better to put it in smaIndex level?
|
||||
// char *path; // relative path
|
||||
// SSmaStat *pStat;
|
||||
// };
|
||||
|
||||
// #define SMA_ENV_LOCK(env) ((env)->lock)
|
||||
// #define SMA_ENV_DID(env) ((env)->did)
|
||||
// #define SMA_ENV_ENV(env) ((env)->dbEnv)
|
||||
// #define SMA_ENV_PATH(env) ((env)->path)
|
||||
// #define SMA_ENV_STAT(env) ((env)->pStat)
|
||||
// #define SMA_ENV_STAT_ITEMS(env) ((env)->pStat->smaStatItems)
|
||||
|
||||
// void tsdbDestroySmaEnv(SSmaEnv *pSmaEnv);
|
||||
// void *tsdbFreeSmaEnv(SSmaEnv *pSmaEnv);
|
||||
// #if 0
|
||||
// int32_t tsdbGetTSmaStatus(STsdb *pTsdb, STSma *param, void *result);
|
||||
// int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin);
|
||||
// #endif
|
||||
|
||||
// // internal func
|
||||
// static FORCE_INLINE int32_t tsdbEncodeTSmaKey(int64_t groupId, TSKEY tsKey, void **pData) {
|
||||
// int32_t len = 0;
|
||||
// len += taosEncodeFixedI64(pData, tsKey);
|
||||
// len += taosEncodeFixedI64(pData, groupId);
|
||||
// return len;
|
||||
// }
|
||||
|
||||
// static FORCE_INLINE int32_t tsdbRLockSma(SSmaEnv *pEnv) {
|
||||
// int code = taosThreadRwlockRdlock(&(pEnv->lock));
|
||||
// if (code != 0) {
|
||||
// terrno = TAOS_SYSTEM_ERROR(code);
|
||||
// return -1;
|
||||
// }
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// static FORCE_INLINE int32_t tsdbWLockSma(SSmaEnv *pEnv) {
|
||||
// int code = taosThreadRwlockWrlock(&(pEnv->lock));
|
||||
// if (code != 0) {
|
||||
// terrno = TAOS_SYSTEM_ERROR(code);
|
||||
// return -1;
|
||||
// }
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// static FORCE_INLINE int32_t tsdbUnLockSma(SSmaEnv *pEnv) {
|
||||
// int code = taosThreadRwlockUnlock(&(pEnv->lock));
|
||||
// if (code != 0) {
|
||||
// terrno = TAOS_SYSTEM_ERROR(code);
|
||||
// return -1;
|
||||
// }
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
typedef struct SSmaKey SSmaKey;
|
||||
|
||||
struct SSmaKey {
|
||||
|
@ -988,6 +927,8 @@ static FORCE_INLINE int32_t tsdbEncodeTSmaKey(int64_t groupId, TSKEY tsKey, void
|
|||
return len;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -16,9 +16,7 @@
|
|||
#ifndef _TD_VNODE_TSDB_SMA_H_
|
||||
#define _TD_VNODE_TSDB_SMA_H_
|
||||
|
||||
#include "os.h"
|
||||
#include "thash.h"
|
||||
#include "tmsg.h"
|
||||
#include "tsdb.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -32,12 +30,6 @@ struct STbDdlH {
|
|||
__tb_ddl_fn_t fp;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
tb_uid_t suid;
|
||||
SArray *tbUids;
|
||||
SHashObj *uidHash;
|
||||
} STbUidStore;
|
||||
|
||||
static FORCE_INLINE int32_t tsdbUidStoreInit(STbUidStore **pStore) {
|
||||
ASSERT(*pStore == NULL);
|
||||
*pStore = taosMemoryCalloc(1, sizeof(STbUidStore));
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
#ifndef _TD_VND_H_
|
||||
#define _TD_VND_H_
|
||||
|
||||
#include "sync.h"
|
||||
#include "syncTools.h"
|
||||
#include "vnodeInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -31,69 +35,65 @@ extern "C" {
|
|||
// clang-format on
|
||||
|
||||
// vnodeCfg ====================
|
||||
extern const SVnodeCfg vnodeCfgDefault;
|
||||
|
||||
int vnodeCheckCfg(const SVnodeCfg*);
|
||||
int vnodeEncodeConfig(const void* pObj, SJson* pJson);
|
||||
int vnodeDecodeConfig(const SJson* pJson, void* pObj);
|
||||
|
||||
// vnodeModule ====================
|
||||
int vnodeScheduleTask(int (*execute)(void*), void* arg);
|
||||
|
||||
// vnodeBufPool ====================
|
||||
typedef struct SVBufPoolNode SVBufPoolNode;
|
||||
struct SVBufPoolNode {
|
||||
SVBufPoolNode* prev;
|
||||
SVBufPoolNode** pnext;
|
||||
int64_t size;
|
||||
uint8_t data[];
|
||||
};
|
||||
|
||||
struct SVBufPool {
|
||||
SVBufPool* next;
|
||||
int64_t nRef;
|
||||
int64_t size;
|
||||
uint8_t* ptr;
|
||||
SVBufPoolNode* pTail;
|
||||
SVBufPoolNode node;
|
||||
};
|
||||
|
||||
int vnodeOpenBufPool(SVnode* pVnode, int64_t size);
|
||||
int vnodeCloseBufPool(SVnode* pVnode);
|
||||
void vnodeBufPoolReset(SVBufPool* pPool);
|
||||
|
||||
// vnodeQuery ====================
|
||||
int vnodeQueryOpen(SVnode* pVnode);
|
||||
void vnodeQueryClose(SVnode* pVnode);
|
||||
int vnodeGetTableMeta(SVnode* pVnode, SRpcMsg* pMsg);
|
||||
|
||||
// vnodeCommit ====================
|
||||
int vnodeBegin(SVnode* pVnode);
|
||||
int vnodeShouldCommit(SVnode* pVnode);
|
||||
int vnodeCommit(SVnode* pVnode);
|
||||
int vnodeSaveInfo(const char* dir, const SVnodeInfo* pCfg);
|
||||
int vnodeCommitInfo(const char* dir, const SVnodeInfo* pInfo);
|
||||
int vnodeLoadInfo(const char* dir, SVnodeInfo* pInfo);
|
||||
int vnodeBegin(SVnode* pVnode, int option);
|
||||
int vnodeSyncCommit(SVnode* pVnode);
|
||||
int vnodeAsyncCommit(SVnode* pVnode);
|
||||
|
||||
#define vnodeShouldCommit vnodeBufPoolIsFull
|
||||
|
||||
#if 1
|
||||
// SVBufPool
|
||||
int vnodeOpenBufPool(SVnode* pVnode);
|
||||
void vnodeCloseBufPool(SVnode* pVnode);
|
||||
int vnodeBufPoolSwitch(SVnode* pVnode);
|
||||
int vnodeBufPoolRecycle(SVnode* pVnode);
|
||||
void* vnodeMalloc(SVnode* pVnode, uint64_t size);
|
||||
bool vnodeBufPoolIsFull(SVnode* pVnode);
|
||||
|
||||
SMemAllocatorFactory* vBufPoolGetMAF(SVnode* pVnode);
|
||||
|
||||
// SVMemAllocator
|
||||
typedef struct SVArenaNode {
|
||||
TD_SLIST_NODE(SVArenaNode);
|
||||
uint64_t size; // current node size
|
||||
void* ptr;
|
||||
char data[];
|
||||
} SVArenaNode;
|
||||
|
||||
typedef struct SVMemAllocator {
|
||||
T_REF_DECLARE()
|
||||
TD_DLIST_NODE(SVMemAllocator);
|
||||
uint64_t capacity;
|
||||
uint64_t ssize;
|
||||
uint64_t lsize;
|
||||
SVArenaNode* pNode;
|
||||
TD_SLIST(SVArenaNode) nlist;
|
||||
} SVMemAllocator;
|
||||
|
||||
SVMemAllocator* vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize);
|
||||
void vmaDestroy(SVMemAllocator* pVMA);
|
||||
void vmaReset(SVMemAllocator* pVMA);
|
||||
void* vmaMalloc(SVMemAllocator* pVMA, uint64_t size);
|
||||
void vmaFree(SVMemAllocator* pVMA, void* ptr);
|
||||
bool vmaIsFull(SVMemAllocator* pVMA);
|
||||
|
||||
// vnodeCfg.h
|
||||
extern const SVnodeCfg vnodeCfgDefault;
|
||||
|
||||
int vnodeCheckCfg(const SVnodeCfg*);
|
||||
|
||||
#endif
|
||||
// vnodeCommit ====================
|
||||
int32_t vnodeSyncOpen(SVnode* pVnode, char* path);
|
||||
int32_t vnodeSyncStart(SVnode* pVnode);
|
||||
void vnodeSyncClose(SVnode* pVnode);
|
||||
void vnodeSyncSetQ(SVnode* pVnode, void* qHandle);
|
||||
void vnodeSyncSetRpc(SVnode* pVnode, void* rpcHandle);
|
||||
int32_t vnodeSyncEqMsg(void* qHandle, SRpcMsg* pMsg);
|
||||
int32_t vnodeSendMsg(void* rpcHandle, const SEpSet* pEpSet, SRpcMsg* pMsg);
|
||||
void vnodeSyncCommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta);
|
||||
void vnodeSyncPreCommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta);
|
||||
void vnodeSyncRollBackCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta);
|
||||
int32_t vnodeSyncGetSnapshotCb(struct SSyncFSM* pFsm, SSnapshot* pSnapshot);
|
||||
SSyncFSM* syncVnodeMakeFsm();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -22,9 +22,11 @@
|
|||
#include "sync.h"
|
||||
#include "tchecksum.h"
|
||||
#include "tcoding.h"
|
||||
#include "tcompare.h"
|
||||
#include "tcompression.h"
|
||||
#include "tdatablock.h"
|
||||
#include "tdbInt.h"
|
||||
#include "tencode.h"
|
||||
#include "tfs.h"
|
||||
#include "tglobal.h"
|
||||
#include "tjson.h"
|
||||
|
@ -57,6 +59,54 @@ typedef struct SQWorkerMgmt SQHandle;
|
|||
#define VNODE_TQ_DIR "tq"
|
||||
#define VNODE_WAL_DIR "wal"
|
||||
|
||||
// vnd.h
|
||||
void* vnodeBufPoolMalloc(SVBufPool* pPool, int size);
|
||||
void vnodeBufPoolFree(SVBufPool* pPool, void* p);
|
||||
|
||||
// meta
|
||||
typedef struct SMCtbCursor SMCtbCursor;
|
||||
typedef struct STbUidStore STbUidStore;
|
||||
|
||||
int metaOpen(SVnode* pVnode, SMeta** ppMeta);
|
||||
int metaClose(SMeta* pMeta);
|
||||
int metaBegin(SMeta* pMeta);
|
||||
int metaCommit(SMeta* pMeta);
|
||||
int metaCreateSTable(SMeta* pMeta, int64_t version, SVCreateStbReq* pReq);
|
||||
int metaCreateTable(SMeta* pMeta, int64_t version, SVCreateTbReq* pReq);
|
||||
SSchemaWrapper* metaGetTableSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, bool isinline);
|
||||
STSchema* metaGetTbTSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver);
|
||||
int metaGetTableEntryByName(SMetaReader* pReader, const char* name);
|
||||
int metaGetTbNum(SMeta* pMeta);
|
||||
SMCtbCursor* metaOpenCtbCursor(SMeta* pMeta, tb_uid_t uid);
|
||||
void metaCloseCtbCurosr(SMCtbCursor* pCtbCur);
|
||||
tb_uid_t metaCtbCursorNext(SMCtbCursor* pCtbCur);
|
||||
SArray* metaGetSmaTbUids(SMeta* pMeta, bool isDup);
|
||||
void* metaGetSmaInfoByIndex(SMeta* pMeta, int64_t indexUid, bool isDecode);
|
||||
STSmaWrapper* metaGetSmaInfoByTable(SMeta* pMeta, tb_uid_t uid);
|
||||
int32_t metaCreateTSma(SMeta* pMeta, SSmaCfg* pCfg);
|
||||
int32_t metaDropTSma(SMeta* pMeta, int64_t indexUid);
|
||||
|
||||
// tsdb
|
||||
int tsdbOpen(SVnode* pVnode, STsdb** ppTsdb);
|
||||
int tsdbClose(STsdb* pTsdb);
|
||||
int tsdbBegin(STsdb* pTsdb);
|
||||
int tsdbCommit(STsdb* pTsdb);
|
||||
int32_t tsdbUpdateSmaWindow(STsdb* pTsdb, SSubmitReq* pMsg, int64_t version);
|
||||
int32_t tsdbCreateTSma(STsdb* pTsdb, char* pMsg);
|
||||
int32_t tsdbInsertTSmaData(STsdb* pTsdb, int64_t indexUid, const char* msg);
|
||||
int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq* pMsg, SSubmitRsp* pRsp);
|
||||
|
||||
// tq
|
||||
STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal);
|
||||
void tqClose(STQ*);
|
||||
int tqPushMsg(STQ*, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver);
|
||||
int tqCommit(STQ*);
|
||||
int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen);
|
||||
int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen, int32_t workerId);
|
||||
int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen);
|
||||
int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen, int32_t workerId);
|
||||
int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId);
|
||||
|
||||
typedef struct {
|
||||
int8_t streamType; // sma or other
|
||||
int8_t dstType;
|
||||
|
@ -68,8 +118,8 @@ typedef struct {
|
|||
} SStreamSinkInfo;
|
||||
|
||||
typedef struct {
|
||||
SVnode *pVnode;
|
||||
SHashObj *pHash; // streamId -> SStreamSinkInfo
|
||||
SVnode* pVnode;
|
||||
SHashObj* pHash; // streamId -> SStreamSinkInfo
|
||||
} SSink;
|
||||
|
||||
// SVState
|
||||
|
@ -85,20 +135,29 @@ struct SVnodeInfo {
|
|||
};
|
||||
|
||||
struct SVnode {
|
||||
char *path;
|
||||
char* path;
|
||||
SVnodeCfg config;
|
||||
SVState state;
|
||||
STfs *pTfs;
|
||||
STfs* pTfs;
|
||||
SMsgCb msgCb;
|
||||
SVBufPool *pBufPool;
|
||||
SMeta *pMeta;
|
||||
STsdb *pTsdb;
|
||||
SWal *pWal;
|
||||
STQ *pTq;
|
||||
SSink *pSink;
|
||||
int64_t sync; // sync integration
|
||||
SVBufPool* pPool;
|
||||
SVBufPool* inUse;
|
||||
SVBufPool* onCommit;
|
||||
SVBufPool* onRecycle;
|
||||
SMeta* pMeta;
|
||||
STsdb* pTsdb;
|
||||
SWal* pWal;
|
||||
STQ* pTq;
|
||||
SSink* pSink;
|
||||
int64_t sync;
|
||||
tsem_t canCommit;
|
||||
SQHandle *pQuery;
|
||||
SQHandle* pQuery;
|
||||
};
|
||||
|
||||
struct STbUidStore {
|
||||
tb_uid_t suid;
|
||||
SArray* tbUids;
|
||||
SHashObj* uidHash;
|
||||
};
|
||||
|
||||
#define TD_VID(PVNODE) (PVNODE)->config.vgId
|
||||
|
@ -106,19 +165,7 @@ struct SVnode {
|
|||
typedef struct STbDdlH STbDdlH;
|
||||
|
||||
// sma
|
||||
void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data);
|
||||
|
||||
#include "vnd.h"
|
||||
|
||||
#include "meta.h"
|
||||
|
||||
#include "tsdb.h"
|
||||
|
||||
#include "tq.h"
|
||||
|
||||
#include "vnodeSync.h"
|
||||
|
||||
#include "tsdbSma.h"
|
||||
void smaHandleRes(void* pVnode, int64_t smaId, const SArray* data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_VNODE_SYNC_H_
|
||||
#define _TD_VNODE_SYNC_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t vnodeSyncOpen(SVnode *pVnode, char *path);
|
||||
int32_t vnodeSyncStart(SVnode *pVnode);
|
||||
void vnodeSyncClose(SVnode *pVnode);
|
||||
|
||||
void vnodeSyncSetQ(SVnode *pVnode, void *qHandle);
|
||||
void vnodeSyncSetRpc(SVnode *pVnode, void *rpcHandle);
|
||||
|
||||
int32_t vnodeSyncEqMsg(void *qHandle, SRpcMsg *pMsg);
|
||||
int32_t vnodeSendMsg(void *rpcHandle, const SEpSet *pEpSet, SRpcMsg *pMsg);
|
||||
|
||||
void vnodeSyncCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta);
|
||||
void vnodeSyncPreCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta);
|
||||
void vnodeSyncRollBackCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta);
|
||||
int32_t vnodeSyncGetSnapshotCb(struct SSyncFSM *pFsm, SSnapshot *pSnapshot);
|
||||
|
||||
SSyncFSM *syncVnodeMakeFsm();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_VNODE_SYNC_H_*/
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* 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 "meta.h"
|
||||
|
||||
static FORCE_INLINE void *metaMalloc(void *pPool, size_t size) { return vnodeBufPoolMalloc((SVBufPool *)pPool, size); }
|
||||
static FORCE_INLINE void metaFree(void *pPool, void *p) { vnodeBufPoolFree((SVBufPool *)pPool, p); }
|
||||
|
||||
int metaBegin(SMeta *pMeta) {
|
||||
tdbTxnOpen(&pMeta->txn, 0, metaMalloc, metaFree, pMeta->pVnode->inUse, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
|
||||
|
||||
if (tdbBegin(pMeta->pEnv, &pMeta->txn) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int metaCommit(SMeta *pMeta) { return tdbCommit(pMeta->pEnv, &pMeta->txn); }
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* 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 "meta.h"
|
||||
|
||||
int metaEncodeEntry(SCoder *pCoder, const SMetaEntry *pME) {
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
if (tEncodeI64(pCoder, pME->version) < 0) return -1;
|
||||
if (tEncodeI8(pCoder, pME->type) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pME->uid) < 0) return -1;
|
||||
if (tEncodeCStr(pCoder, pME->name) < 0) return -1;
|
||||
|
||||
if (pME->type == TSDB_SUPER_TABLE) {
|
||||
if (tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schema) < 0) return -1;
|
||||
if (tEncodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag) < 0) return -1;
|
||||
} else if (pME->type == TSDB_CHILD_TABLE) {
|
||||
if (tEncodeI64(pCoder, pME->ctbEntry.ctime) < 0) return -1;
|
||||
if (tEncodeI32(pCoder, pME->ctbEntry.ttlDays) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pME->ctbEntry.suid) < 0) return -1;
|
||||
if (tEncodeBinary(pCoder, pME->ctbEntry.pTags, kvRowLen(pME->ctbEntry.pTags)) < 0) return -1;
|
||||
} else if (pME->type == TSDB_NORMAL_TABLE) {
|
||||
if (tEncodeI64(pCoder, pME->ntbEntry.ctime) < 0) return -1;
|
||||
if (tEncodeI32(pCoder, pME->ntbEntry.ttlDays) < 0) return -1;
|
||||
if (tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schema) < 0) return -1;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
tEndEncode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int metaDecodeEntry(SCoder *pCoder, SMetaEntry *pME) {
|
||||
uint64_t len;
|
||||
if (tStartDecode(pCoder) < 0) return -1;
|
||||
|
||||
if (tDecodeI64(pCoder, &pME->version) < 0) return -1;
|
||||
if (tDecodeI8(pCoder, &pME->type) < 0) return -1;
|
||||
if (tDecodeI64(pCoder, &pME->uid) < 0) return -1;
|
||||
if (tDecodeCStr(pCoder, &pME->name) < 0) return -1;
|
||||
|
||||
if (pME->type == TSDB_SUPER_TABLE) {
|
||||
if (tDecodeSSchemaWrapper(pCoder, &pME->stbEntry.schema) < 0) return -1;
|
||||
if (tDecodeSSchemaWrapper(pCoder, &pME->stbEntry.schemaTag) < 0) return -1;
|
||||
} else if (pME->type == TSDB_CHILD_TABLE) {
|
||||
if (tDecodeI64(pCoder, &pME->ctbEntry.ctime) < 0) return -1;
|
||||
if (tDecodeI32(pCoder, &pME->ctbEntry.ttlDays) < 0) return -1;
|
||||
if (tDecodeI64(pCoder, &pME->ctbEntry.suid) < 0) return -1;
|
||||
if (tDecodeBinary(pCoder, &pME->ctbEntry.pTags, &len) < 0) return -1; // (TODO)
|
||||
} else if (pME->type == TSDB_NORMAL_TABLE) {
|
||||
if (tDecodeI64(pCoder, &pME->ntbEntry.ctime) < 0) return -1;
|
||||
if (tDecodeI32(pCoder, &pME->ntbEntry.ttlDays) < 0) return -1;
|
||||
if (tDecodeSSchemaWrapper(pCoder, &pME->ntbEntry.schema) < 0) return -1;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
tEndDecode(pCoder);
|
||||
return 0;
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
#ifdef USE_INVERTED_INDEX
|
||||
#include "index.h"
|
||||
#endif
|
||||
#include "vnodeInt.h"
|
||||
#include "meta.h"
|
||||
|
||||
struct SMetaIdx {
|
||||
#ifdef USE_INVERTED_INDEX
|
||||
|
@ -54,7 +54,9 @@ int metaOpenIdx(SMeta *pMeta) {
|
|||
|
||||
#ifdef USE_INVERTED_INDEX
|
||||
SIndexOpts opts;
|
||||
if (indexOpen(&opts, pMeta->path, &pMeta->pIdx->pIdx) != 0) { return -1; }
|
||||
if (indexOpen(&opts, pMeta->path, &pMeta->pIdx->pIdx) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
|
@ -70,7 +72,9 @@ void metaCloseIdx(SMeta *pMeta) { /* TODO */
|
|||
|
||||
#ifdef USE_INVERTED_INDEX
|
||||
SIndexOpts opts;
|
||||
if (indexClose(pMeta->pIdx->pIdx) != 0) { return -1; }
|
||||
if (indexClose(pMeta->pIdx->pIdx) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
@ -87,7 +91,7 @@ int metaSaveTableToIdx(SMeta *pMeta, const STbCfg *pTbCfg) {
|
|||
tb_uid_t suid = pTbCfg->ctbCfg.suid; // super id
|
||||
tb_uid_t tuid = 0; // child table uid
|
||||
SIndexMultiTerm *terms = indexMultiTermCreate();
|
||||
SIndexTerm * term =
|
||||
SIndexTerm *term =
|
||||
indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_BINARY, buf, strlen(buf), pTagVal, strlen(pTagVal), tuid);
|
||||
indexMultiTermAdd(terms, term);
|
||||
|
||||
|
@ -117,10 +121,13 @@ int32_t metaCreateTSma(SMeta *pMeta, SSmaCfg *pCfg) {
|
|||
|
||||
// TODO: add atomicity
|
||||
|
||||
#ifdef META_REFACT
|
||||
#else
|
||||
if (metaSaveSmaToDB(pMeta, &pCfg->tSma) < 0) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -128,9 +135,12 @@ int32_t metaDropTSma(SMeta *pMeta, int64_t indexUid) {
|
|||
// TODO: Validate the cfg
|
||||
// TODO: add atomicity
|
||||
|
||||
#ifdef META_REFACT
|
||||
#else
|
||||
if (metaRemoveSmaFromDb(pMeta, indexUid) < 0) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
|
@ -13,10 +13,18 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "vnodeInt.h"
|
||||
#include "meta.h"
|
||||
|
||||
static int tbDbKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||
static int skmDbKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||
static int ctbIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||
static int tagIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||
static int ttlIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||
static int uidIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||
|
||||
int metaOpen(SVnode *pVnode, SMeta **ppMeta) {
|
||||
SMeta *pMeta = NULL;
|
||||
int ret;
|
||||
int slen;
|
||||
|
||||
*ppMeta = NULL;
|
||||
|
@ -36,31 +44,240 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) {
|
|||
// create path if not created yet
|
||||
taosMkDir(pMeta->path);
|
||||
|
||||
// open meta
|
||||
if (metaOpenDB(pMeta) < 0) {
|
||||
// open env
|
||||
ret = tdbEnvOpen(pMeta->path, pVnode->config.szPage, pVnode->config.szCache, &pMeta->pEnv);
|
||||
if (ret < 0) {
|
||||
metaError("vgId: %d failed to open meta env since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
|
||||
if (metaOpenIdx(pMeta) < 0) {
|
||||
// open pTbDb
|
||||
ret = tdbDbOpen("table.db", sizeof(STbDbKey), -1, tbDbKeyCmpr, pMeta->pEnv, &pMeta->pTbDb);
|
||||
if (ret < 0) {
|
||||
metaError("vgId: %d failed to open meta table db since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// open pSkmDb
|
||||
ret = tdbDbOpen("schema.db", sizeof(SSkmDbKey), -1, skmDbKeyCmpr, pMeta->pEnv, &pMeta->pSkmDb);
|
||||
if (ret < 0) {
|
||||
metaError("vgId: %d failed to open meta schema db since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// open pUidIdx
|
||||
ret = tdbDbOpen("uid.idx", sizeof(tb_uid_t), sizeof(int64_t), uidIdxKeyCmpr, pMeta->pEnv, &pMeta->pUidIdx);
|
||||
if (ret < 0) {
|
||||
metaError("vgId: %d failed to open meta uid idx since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// open pNameIdx
|
||||
ret = tdbDbOpen("name.idx", -1, sizeof(tb_uid_t), NULL, pMeta->pEnv, &pMeta->pNameIdx);
|
||||
if (ret < 0) {
|
||||
metaError("vgId: %d failed to open meta name index since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// open pCtbIdx
|
||||
ret = tdbDbOpen("ctb.idx", sizeof(SCtbIdxKey), 0, ctbIdxKeyCmpr, pMeta->pEnv, &pMeta->pCtbIdx);
|
||||
if (ret < 0) {
|
||||
metaError("vgId: %d failed to open meta child table index since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// open pTagIdx
|
||||
ret = tdbDbOpen("tag.idx", -1, 0, tagIdxKeyCmpr, pMeta->pEnv, &pMeta->pTagIdx);
|
||||
if (ret < 0) {
|
||||
metaError("vgId: %d failed to open meta tag index since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// open pTtlIdx
|
||||
ret = tdbDbOpen("ttl.idx", sizeof(STtlIdxKey), 0, ttlIdxKeyCmpr, pMeta->pEnv, &pMeta->pTtlIdx);
|
||||
if (ret < 0) {
|
||||
metaError("vgId: %d failed to open meta ttl index since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// open index
|
||||
if (metaOpenIdx(pMeta) < 0) {
|
||||
metaError("vgId: %d failed to open meta index since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
|
||||
metaDebug("vgId: %d meta is opened", TD_VID(pVnode));
|
||||
|
||||
*ppMeta = pMeta;
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
if (pMeta->pIdx) metaCloseIdx(pMeta);
|
||||
if (pMeta->pDB) metaCloseDB(pMeta);
|
||||
if (pMeta->pTtlIdx) tdbDbClose(pMeta->pTtlIdx);
|
||||
if (pMeta->pTagIdx) tdbDbClose(pMeta->pTagIdx);
|
||||
if (pMeta->pCtbIdx) tdbDbClose(pMeta->pCtbIdx);
|
||||
if (pMeta->pNameIdx) tdbDbClose(pMeta->pNameIdx);
|
||||
if (pMeta->pNameIdx) tdbDbClose(pMeta->pUidIdx);
|
||||
if (pMeta->pSkmDb) tdbDbClose(pMeta->pSkmDb);
|
||||
if (pMeta->pTbDb) tdbDbClose(pMeta->pTbDb);
|
||||
if (pMeta->pEnv) tdbEnvClose(pMeta->pEnv);
|
||||
taosMemoryFree(pMeta);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int metaClose(SMeta *pMeta) {
|
||||
if (pMeta) {
|
||||
metaCloseIdx(pMeta);
|
||||
metaCloseDB(pMeta);
|
||||
if (pMeta->pIdx) metaCloseIdx(pMeta);
|
||||
if (pMeta->pTtlIdx) tdbDbClose(pMeta->pTtlIdx);
|
||||
if (pMeta->pTagIdx) tdbDbClose(pMeta->pTagIdx);
|
||||
if (pMeta->pCtbIdx) tdbDbClose(pMeta->pCtbIdx);
|
||||
if (pMeta->pNameIdx) tdbDbClose(pMeta->pNameIdx);
|
||||
if (pMeta->pNameIdx) tdbDbClose(pMeta->pUidIdx);
|
||||
if (pMeta->pSkmDb) tdbDbClose(pMeta->pSkmDb);
|
||||
if (pMeta->pTbDb) tdbDbClose(pMeta->pTbDb);
|
||||
if (pMeta->pEnv) tdbEnvClose(pMeta->pEnv);
|
||||
taosMemoryFree(pMeta);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int tbDbKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
|
||||
STbDbKey *pTbDbKey1 = (STbDbKey *)pKey1;
|
||||
STbDbKey *pTbDbKey2 = (STbDbKey *)pKey2;
|
||||
|
||||
if (pTbDbKey1->version > pTbDbKey2->version) {
|
||||
return 1;
|
||||
} else if (pTbDbKey1->version < pTbDbKey2->version) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pTbDbKey1->uid > pTbDbKey2->uid) {
|
||||
return 1;
|
||||
} else if (pTbDbKey1->uid < pTbDbKey2->uid) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int skmDbKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
|
||||
SSkmDbKey *pSkmDbKey1 = (SSkmDbKey *)pKey1;
|
||||
SSkmDbKey *pSkmDbKey2 = (SSkmDbKey *)pKey2;
|
||||
|
||||
if (pSkmDbKey1->uid > pSkmDbKey2->uid) {
|
||||
return 1;
|
||||
} else if (pSkmDbKey1->uid < pSkmDbKey2->uid) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pSkmDbKey1->sver > pSkmDbKey2->sver) {
|
||||
return 1;
|
||||
} else if (pSkmDbKey1->sver < pSkmDbKey2->sver) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uidIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
|
||||
tb_uid_t uid1 = *(tb_uid_t *)pKey1;
|
||||
tb_uid_t uid2 = *(tb_uid_t *)pKey2;
|
||||
|
||||
if (uid1 > uid2) {
|
||||
return 1;
|
||||
} else if (uid1 < uid2) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ctbIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
|
||||
SCtbIdxKey *pCtbIdxKey1 = (SCtbIdxKey *)pKey1;
|
||||
SCtbIdxKey *pCtbIdxKey2 = (SCtbIdxKey *)pKey2;
|
||||
|
||||
if (pCtbIdxKey1->suid > pCtbIdxKey2->suid) {
|
||||
return 1;
|
||||
} else if (pCtbIdxKey1->suid < pCtbIdxKey2->suid) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCtbIdxKey1->uid > pCtbIdxKey2->uid) {
|
||||
return 1;
|
||||
} else if (pCtbIdxKey1->uid < pCtbIdxKey2->uid) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tagIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
|
||||
STagIdxKey *pTagIdxKey1 = (STagIdxKey *)pKey1;
|
||||
STagIdxKey *pTagIdxKey2 = (STagIdxKey *)pKey2;
|
||||
int8_t *p1, *p2;
|
||||
int8_t type;
|
||||
int c;
|
||||
|
||||
// compare suid
|
||||
if (pTagIdxKey1->suid > pTagIdxKey2->suid) {
|
||||
return 1;
|
||||
} else if (pTagIdxKey1->suid < pTagIdxKey2->suid) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// compare column id
|
||||
if (pTagIdxKey1->cid > pTagIdxKey2->cid) {
|
||||
return 1;
|
||||
} else if (pTagIdxKey1->cid < pTagIdxKey2->cid) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// compare value
|
||||
p1 = pTagIdxKey1->data;
|
||||
p2 = pTagIdxKey2->data;
|
||||
ASSERT(p1[0] == p2[0]);
|
||||
type = p1[0];
|
||||
|
||||
p1++;
|
||||
p2++;
|
||||
|
||||
c = doCompare(p1, p2, type, 0);
|
||||
if (c) return c;
|
||||
|
||||
if (IS_VAR_DATA_TYPE(type)) {
|
||||
p1 = p1 + varDataTLen(p1);
|
||||
p2 = p2 + varDataTLen(p2);
|
||||
} else {
|
||||
p1 = p1 + tDataTypes[type].bytes;
|
||||
p2 = p2 + tDataTypes[type].bytes;
|
||||
}
|
||||
|
||||
// compare suid
|
||||
if (*(tb_uid_t *)p1 > *(tb_uid_t *)p2) {
|
||||
return 1;
|
||||
} else if (*(tb_uid_t *)p1 < *(tb_uid_t *)p2) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ttlIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
|
||||
STtlIdxKey *pTtlIdxKey1 = (STtlIdxKey *)pKey1;
|
||||
STtlIdxKey *pTtlIdxKey2 = (STtlIdxKey *)pKey2;
|
||||
|
||||
if (pTtlIdxKey1->dtime > pTtlIdxKey2->dtime) {
|
||||
return 1;
|
||||
} else if (pTtlIdxKey1->dtime < pTtlIdxKey2->dtime) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pTtlIdxKey1->uid > pTtlIdxKey2->uid) {
|
||||
return 1;
|
||||
} else if (pTtlIdxKey1->uid < pTtlIdxKey2->uid) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,439 @@
|
|||
/*
|
||||
* 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 "meta.h"
|
||||
|
||||
void metaReaderInit(SMetaReader *pReader, SMeta *pMeta, int32_t flags) {
|
||||
memset(pReader, 0, sizeof(*pReader));
|
||||
pReader->flags = flags;
|
||||
pReader->pMeta = pMeta;
|
||||
}
|
||||
|
||||
void metaReaderClear(SMetaReader *pReader) {
|
||||
tCoderClear(&pReader->coder);
|
||||
TDB_FREE(pReader->pBuf);
|
||||
}
|
||||
|
||||
int metaGetTableEntryByVersion(SMetaReader *pReader, int64_t version, tb_uid_t uid) {
|
||||
SMeta *pMeta = pReader->pMeta;
|
||||
STbDbKey tbDbKey = {.version = version, .uid = uid};
|
||||
|
||||
// query table.db
|
||||
if (tdbDbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pReader->pBuf, &pReader->szBuf) < 0) {
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// decode the entry
|
||||
tCoderInit(&pReader->coder, TD_LITTLE_ENDIAN, pReader->pBuf, pReader->szBuf, TD_DECODER);
|
||||
|
||||
if (metaDecodeEntry(&pReader->coder, &pReader->me) < 0) {
|
||||
goto _err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
return -1;
|
||||
}
|
||||
|
||||
int metaGetTableEntryByUid(SMetaReader *pReader, tb_uid_t uid) {
|
||||
SMeta *pMeta = pReader->pMeta;
|
||||
int64_t version;
|
||||
|
||||
// query uid.idx
|
||||
if (tdbDbGet(pMeta->pUidIdx, &uid, sizeof(uid), &pReader->pBuf, &pReader->szBuf) < 0) {
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
version = *(int64_t *)pReader->pBuf;
|
||||
return metaGetTableEntryByVersion(pReader, version, uid);
|
||||
}
|
||||
|
||||
int metaGetTableEntryByName(SMetaReader *pReader, const char *name) {
|
||||
SMeta *pMeta = pReader->pMeta;
|
||||
tb_uid_t uid;
|
||||
|
||||
// query name.idx
|
||||
if (tdbDbGet(pMeta->pNameIdx, name, strlen(name) + 1, &pReader->pBuf, &pReader->szBuf) < 0) {
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
uid = *(tb_uid_t *)pReader->pBuf;
|
||||
return metaGetTableEntryByUid(pReader, uid);
|
||||
}
|
||||
|
||||
int metaReadNext(SMetaReader *pReader) {
|
||||
SMeta *pMeta = pReader->pMeta;
|
||||
|
||||
// TODO
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 1 // ===================================================
|
||||
SMTbCursor *metaOpenTbCursor(SMeta *pMeta) {
|
||||
SMTbCursor *pTbCur = NULL;
|
||||
|
||||
pTbCur = (SMTbCursor *)taosMemoryCalloc(1, sizeof(*pTbCur));
|
||||
if (pTbCur == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
metaReaderInit(&pTbCur->mr, pMeta, 0);
|
||||
|
||||
tdbDbcOpen(pMeta->pUidIdx, &pTbCur->pDbc);
|
||||
|
||||
return pTbCur;
|
||||
}
|
||||
|
||||
void metaCloseTbCursor(SMTbCursor *pTbCur) {
|
||||
if (pTbCur) {
|
||||
TDB_FREE(pTbCur->pKey);
|
||||
TDB_FREE(pTbCur->pVal);
|
||||
metaReaderClear(&pTbCur->mr);
|
||||
if (pTbCur->pDbc) {
|
||||
tdbDbcClose(pTbCur->pDbc);
|
||||
}
|
||||
taosMemoryFree(pTbCur);
|
||||
}
|
||||
}
|
||||
|
||||
int metaTbCursorNext(SMTbCursor *pTbCur) {
|
||||
int ret;
|
||||
void *pBuf;
|
||||
STbCfg tbCfg;
|
||||
|
||||
for (;;) {
|
||||
ret = tdbDbNext(pTbCur->pDbc, &pTbCur->pKey, &pTbCur->kLen, &pTbCur->pVal, &pTbCur->vLen);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
metaGetTableEntryByVersion(&pTbCur->mr, *(int64_t *)pTbCur->pVal, *(tb_uid_t *)pTbCur->pKey);
|
||||
if (pTbCur->mr.me.type == TSDB_SUPER_TABLE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline) {
|
||||
void *pKey = NULL;
|
||||
void *pVal = NULL;
|
||||
int kLen = 0;
|
||||
int vLen = 0;
|
||||
int ret;
|
||||
SSkmDbKey skmDbKey;
|
||||
SSchemaWrapper *pSW = NULL;
|
||||
SSchema *pSchema = NULL;
|
||||
void *pBuf;
|
||||
SCoder coder = {0};
|
||||
|
||||
// fetch
|
||||
skmDbKey.uid = uid;
|
||||
skmDbKey.sver = sver;
|
||||
pKey = &skmDbKey;
|
||||
kLen = sizeof(skmDbKey);
|
||||
ret = tdbDbGet(pMeta->pSkmDb, pKey, kLen, &pVal, &vLen);
|
||||
if (ret < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// decode
|
||||
pBuf = pVal;
|
||||
pSW = taosMemoryMalloc(sizeof(pSW));
|
||||
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pVal, vLen, TD_DECODER);
|
||||
tDecodeSSchemaWrapper(&coder, pSW);
|
||||
pSchema = taosMemoryMalloc(sizeof(SSchema) * pSW->nCols);
|
||||
memcpy(pSchema, pSW->pSchema, sizeof(SSchema) * pSW->nCols);
|
||||
tCoderClear(&coder);
|
||||
|
||||
pSW->pSchema = pSchema;
|
||||
|
||||
TDB_FREE(pVal);
|
||||
|
||||
return pSW;
|
||||
}
|
||||
|
||||
struct SMCtbCursor {
|
||||
TDBC *pCur;
|
||||
tb_uid_t suid;
|
||||
void *pKey;
|
||||
void *pVal;
|
||||
int kLen;
|
||||
int vLen;
|
||||
};
|
||||
|
||||
SMCtbCursor *metaOpenCtbCursor(SMeta *pMeta, tb_uid_t uid) {
|
||||
SMCtbCursor *pCtbCur = NULL;
|
||||
int ret;
|
||||
|
||||
pCtbCur = (SMCtbCursor *)taosMemoryCalloc(1, sizeof(*pCtbCur));
|
||||
if (pCtbCur == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pCtbCur->suid = uid;
|
||||
ret = tdbDbcOpen(pMeta->pCtbIdx, &pCtbCur->pCur);
|
||||
if (ret < 0) {
|
||||
taosMemoryFree(pCtbCur);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pCtbCur;
|
||||
}
|
||||
|
||||
void metaCloseCtbCurosr(SMCtbCursor *pCtbCur) {
|
||||
if (pCtbCur) {
|
||||
if (pCtbCur->pCur) {
|
||||
tdbDbcClose(pCtbCur->pCur);
|
||||
|
||||
TDB_FREE(pCtbCur->pKey);
|
||||
TDB_FREE(pCtbCur->pVal);
|
||||
}
|
||||
|
||||
taosMemoryFree(pCtbCur);
|
||||
}
|
||||
}
|
||||
|
||||
tb_uid_t metaCtbCursorNext(SMCtbCursor *pCtbCur) {
|
||||
int ret;
|
||||
SCtbIdxKey *pCtbIdxKey;
|
||||
|
||||
ret = tdbDbNext(pCtbCur->pCur, &pCtbCur->pKey, &pCtbCur->kLen, &pCtbCur->pVal, &pCtbCur->vLen);
|
||||
if (ret < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
pCtbIdxKey = pCtbCur->pKey;
|
||||
|
||||
return pCtbIdxKey->uid;
|
||||
}
|
||||
|
||||
STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) {
|
||||
tb_uid_t quid;
|
||||
SMetaReader mr = {0};
|
||||
STSchema *pTSchema = NULL;
|
||||
SSchemaWrapper *pSW = NULL;
|
||||
STSchemaBuilder sb = {0};
|
||||
SSchema *pSchema;
|
||||
|
||||
metaReaderInit(&mr, pMeta, 0);
|
||||
metaGetTableEntryByUid(&mr, uid);
|
||||
|
||||
if (mr.me.type == TSDB_CHILD_TABLE) {
|
||||
quid = mr.me.ctbEntry.suid;
|
||||
} else {
|
||||
quid = uid;
|
||||
}
|
||||
|
||||
metaReaderClear(&mr);
|
||||
|
||||
pSW = metaGetTableSchema(pMeta, quid, sver, 0);
|
||||
tdInitTSchemaBuilder(&sb, 0);
|
||||
for (int i = 0; i < pSW->nCols; i++) {
|
||||
pSchema = pSW->pSchema + i;
|
||||
tdAddColToSchema(&sb, pSchema->type, pSchema->flags, pSchema->colId, pSchema->bytes);
|
||||
}
|
||||
pTSchema = tdGetSchemaFromBuilder(&sb);
|
||||
tdDestroyTSchemaBuilder(&sb);
|
||||
|
||||
taosMemoryFree(pSW->pSchema);
|
||||
taosMemoryFree(pSW);
|
||||
return pTSchema;
|
||||
}
|
||||
|
||||
STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) {
|
||||
#if 0
|
||||
#ifdef META_TDB_SMA_TEST
|
||||
STSmaWrapper *pSW = NULL;
|
||||
|
||||
pSW = taosMemoryCalloc(1, sizeof(*pSW));
|
||||
if (pSW == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SMSmaCursor *pCur = metaOpenSmaCursor(pMeta, uid);
|
||||
if (pCur == NULL) {
|
||||
taosMemoryFree(pSW);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *pBuf = NULL;
|
||||
SSmaIdxKey *pSmaIdxKey = NULL;
|
||||
|
||||
while (true) {
|
||||
// TODO: lock during iterate?
|
||||
if (tdbDbNext(pCur->pCur, &pCur->pKey, &pCur->kLen, NULL, &pCur->vLen) == 0) {
|
||||
pSmaIdxKey = pCur->pKey;
|
||||
ASSERT(pSmaIdxKey != NULL);
|
||||
|
||||
void *pSmaVal = metaGetSmaInfoByIndex(pMeta, pSmaIdxKey->smaUid, false);
|
||||
|
||||
if (pSmaVal == NULL) {
|
||||
tsdbWarn("no tsma exists for indexUid: %" PRIi64, pSmaIdxKey->smaUid);
|
||||
continue;
|
||||
}
|
||||
|
||||
++pSW->number;
|
||||
STSma *tptr = (STSma *)taosMemoryRealloc(pSW->tSma, pSW->number * sizeof(STSma));
|
||||
if (tptr == NULL) {
|
||||
TDB_FREE(pSmaVal);
|
||||
metaCloseSmaCursor(pCur);
|
||||
tdDestroyTSmaWrapper(pSW);
|
||||
taosMemoryFreeClear(pSW);
|
||||
return NULL;
|
||||
}
|
||||
pSW->tSma = tptr;
|
||||
pBuf = pSmaVal;
|
||||
if (tDecodeTSma(pBuf, pSW->tSma + pSW->number - 1) == NULL) {
|
||||
TDB_FREE(pSmaVal);
|
||||
metaCloseSmaCursor(pCur);
|
||||
tdDestroyTSmaWrapper(pSW);
|
||||
taosMemoryFreeClear(pSW);
|
||||
return NULL;
|
||||
}
|
||||
TDB_FREE(pSmaVal);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
metaCloseSmaCursor(pCur);
|
||||
|
||||
return pSW;
|
||||
|
||||
#endif
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int metaGetTbNum(SMeta *pMeta) {
|
||||
// TODO
|
||||
// ASSERT(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SArray *metaGetSmaTbUids(SMeta *pMeta, bool isDup) {
|
||||
#if 0
|
||||
// TODO
|
||||
// ASSERT(0); // comment this line to pass CI
|
||||
// return NULL:
|
||||
#ifdef META_TDB_SMA_TEST
|
||||
SArray *pUids = NULL;
|
||||
SMetaDB *pDB = pMeta->pDB;
|
||||
void *pKey;
|
||||
|
||||
// TODO: lock?
|
||||
SMSmaCursor *pCur = metaOpenSmaCursor(pMeta, 0);
|
||||
if (pCur == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
// TODO: lock?
|
||||
|
||||
SSmaIdxKey *pSmaIdxKey = NULL;
|
||||
tb_uid_t uid = 0;
|
||||
while (true) {
|
||||
// TODO: lock during iterate?
|
||||
if (tdbDbNext(pCur->pCur, &pCur->pKey, &pCur->kLen, NULL, &pCur->vLen) == 0) {
|
||||
ASSERT(pSmaIdxKey != NULL);
|
||||
pSmaIdxKey = pCur->pKey;
|
||||
|
||||
if (pSmaIdxKey->uid == 0 || pSmaIdxKey->uid == uid) {
|
||||
continue;
|
||||
}
|
||||
uid = pSmaIdxKey->uid;
|
||||
|
||||
if (!pUids) {
|
||||
pUids = taosArrayInit(16, sizeof(tb_uid_t));
|
||||
if (!pUids) {
|
||||
metaCloseSmaCursor(pCur);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
taosArrayPush(pUids, &uid);
|
||||
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
metaCloseSmaCursor(pCur);
|
||||
|
||||
return pUids;
|
||||
#endif
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid, bool isDecode) {
|
||||
#if 0
|
||||
// TODO
|
||||
// ASSERT(0);
|
||||
// return NULL;
|
||||
#ifdef META_TDB_SMA_TEST
|
||||
SMetaDB *pDB = pMeta->pDB;
|
||||
void *pKey = NULL;
|
||||
void *pVal = NULL;
|
||||
int kLen = 0;
|
||||
int vLen = 0;
|
||||
int ret = -1;
|
||||
|
||||
// Set key
|
||||
pKey = (void *)&indexUid;
|
||||
kLen = sizeof(indexUid);
|
||||
|
||||
// Query
|
||||
ret = tdbDbGet(pDB->pSmaDB, pKey, kLen, &pVal, &vLen);
|
||||
if (ret != 0 || !pVal) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!isDecode) {
|
||||
// return raw value
|
||||
return pVal;
|
||||
}
|
||||
|
||||
// Decode
|
||||
STSma *pCfg = (STSma *)taosMemoryCalloc(1, sizeof(STSma));
|
||||
if (pCfg == NULL) {
|
||||
taosMemoryFree(pVal);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *pBuf = pVal;
|
||||
if (tDecodeTSma(pBuf, pCfg) == NULL) {
|
||||
tdDestroyTSma(pCfg);
|
||||
taosMemoryFree(pCfg);
|
||||
TDB_FREE(pVal);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TDB_FREE(pVal);
|
||||
return pCfg;
|
||||
#endif
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -15,6 +15,8 @@
|
|||
|
||||
#include "vnodeInt.h"
|
||||
|
||||
#ifndef META_REFACT
|
||||
|
||||
typedef struct SPoolMem {
|
||||
int64_t size;
|
||||
struct SPoolMem *prev;
|
||||
|
@ -45,7 +47,7 @@ struct SMetaDB {
|
|||
#endif
|
||||
};
|
||||
|
||||
#pragma pack(push,1)
|
||||
#pragma pack(push, 1)
|
||||
typedef struct {
|
||||
tb_uid_t uid;
|
||||
int32_t sver;
|
||||
|
@ -379,64 +381,6 @@ int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
STbCfg *metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid) {
|
||||
int ret;
|
||||
SMetaDB *pMetaDb = pMeta->pDB;
|
||||
void *pKey;
|
||||
void *pVal;
|
||||
int kLen;
|
||||
int vLen;
|
||||
STbCfg *pTbCfg;
|
||||
|
||||
// Fetch
|
||||
pKey = &uid;
|
||||
kLen = sizeof(uid);
|
||||
pVal = NULL;
|
||||
ret = tdbDbGet(pMetaDb->pTbDB, pKey, kLen, &pVal, &vLen);
|
||||
if (ret < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Decode
|
||||
pTbCfg = taosMemoryMalloc(sizeof(*pTbCfg));
|
||||
metaDecodeTbInfo(pVal, pTbCfg);
|
||||
|
||||
TDB_FREE(pVal);
|
||||
|
||||
return pTbCfg;
|
||||
}
|
||||
|
||||
STbCfg *metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid) {
|
||||
void *pKey;
|
||||
void *pVal;
|
||||
void *ppKey;
|
||||
int pkLen;
|
||||
int kLen;
|
||||
int vLen;
|
||||
int ret;
|
||||
|
||||
pKey = tbname;
|
||||
kLen = strlen(tbname) + 1;
|
||||
pVal = NULL;
|
||||
ppKey = NULL;
|
||||
ret = tdbDbPGet(pMeta->pDB->pNameIdx, pKey, kLen, &ppKey, &pkLen, &pVal, &vLen);
|
||||
if (ret < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ASSERT(pkLen == kLen + sizeof(uid));
|
||||
|
||||
*uid = *(tb_uid_t *)POINTER_SHIFT(ppKey, kLen);
|
||||
TDB_FREE(ppKey);
|
||||
TDB_FREE(pVal);
|
||||
|
||||
return metaGetTbInfoByUid(pMeta, *uid);
|
||||
}
|
||||
|
||||
SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline) {
|
||||
return metaGetTableSchemaImpl(pMeta, uid, sver, isinline, false);
|
||||
}
|
||||
|
||||
static SSchemaWrapper *metaGetTableSchemaImpl(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline, bool isGetEx) {
|
||||
void *pKey;
|
||||
void *pVal;
|
||||
|
@ -468,156 +412,6 @@ static SSchemaWrapper *metaGetTableSchemaImpl(SMeta *pMeta, tb_uid_t uid, int32_
|
|||
return pSchemaWrapper;
|
||||
}
|
||||
|
||||
STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) {
|
||||
tb_uid_t quid;
|
||||
SSchemaWrapper *pSW;
|
||||
STSchemaBuilder sb;
|
||||
SSchema *pSchema;
|
||||
STSchema *pTSchema;
|
||||
STbCfg *pTbCfg;
|
||||
|
||||
pTbCfg = metaGetTbInfoByUid(pMeta, uid);
|
||||
if (pTbCfg->type == META_CHILD_TABLE) {
|
||||
quid = pTbCfg->ctbCfg.suid;
|
||||
} else {
|
||||
quid = uid;
|
||||
}
|
||||
|
||||
pSW = metaGetTableSchemaImpl(pMeta, quid, sver, true, true);
|
||||
if (pSW == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tdInitTSchemaBuilder(&sb, 0);
|
||||
for (int i = 0; i < pSW->nCols; i++) {
|
||||
pSchema = pSW->pSchema + i;
|
||||
tdAddColToSchema(&sb, pSchema->type, pSchema->flags, pSchema->colId, pSchema->bytes);
|
||||
}
|
||||
pTSchema = tdGetSchemaFromBuilder(&sb);
|
||||
tdDestroyTSchemaBuilder(&sb);
|
||||
|
||||
return pTSchema;
|
||||
}
|
||||
|
||||
struct SMTbCursor {
|
||||
TDBC *pDbc;
|
||||
};
|
||||
|
||||
SMTbCursor *metaOpenTbCursor(SMeta *pMeta) {
|
||||
SMTbCursor *pTbCur = NULL;
|
||||
SMetaDB *pDB = pMeta->pDB;
|
||||
|
||||
pTbCur = (SMTbCursor *)taosMemoryCalloc(1, sizeof(*pTbCur));
|
||||
if (pTbCur == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tdbDbcOpen(pDB->pTbDB, &pTbCur->pDbc);
|
||||
|
||||
return pTbCur;
|
||||
}
|
||||
|
||||
void metaCloseTbCursor(SMTbCursor *pTbCur) {
|
||||
if (pTbCur) {
|
||||
if (pTbCur->pDbc) {
|
||||
tdbDbcClose(pTbCur->pDbc);
|
||||
}
|
||||
taosMemoryFree(pTbCur);
|
||||
}
|
||||
}
|
||||
|
||||
char *metaTbCursorNext(SMTbCursor *pTbCur) {
|
||||
void *pKey = NULL;
|
||||
void *pVal = NULL;
|
||||
int kLen;
|
||||
int vLen;
|
||||
int ret;
|
||||
void *pBuf;
|
||||
STbCfg tbCfg;
|
||||
|
||||
for (;;) {
|
||||
ret = tdbDbNext(pTbCur->pDbc, &pKey, &kLen, &pVal, &vLen);
|
||||
if (ret < 0) break;
|
||||
pBuf = pVal;
|
||||
metaDecodeTbInfo(pBuf, &tbCfg);
|
||||
if (tbCfg.type == META_SUPER_TABLE) {
|
||||
taosMemoryFree(tbCfg.name);
|
||||
taosMemoryFree(tbCfg.stbCfg.pTagSchema);
|
||||
continue;
|
||||
} else if (tbCfg.type == META_CHILD_TABLE) {
|
||||
kvRowFree(tbCfg.ctbCfg.pTag);
|
||||
}
|
||||
|
||||
return tbCfg.name;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct SMCtbCursor {
|
||||
TDBC *pCur;
|
||||
tb_uid_t suid;
|
||||
void *pKey;
|
||||
void *pVal;
|
||||
int kLen;
|
||||
int vLen;
|
||||
};
|
||||
|
||||
SMCtbCursor *metaOpenCtbCursor(SMeta *pMeta, tb_uid_t uid) {
|
||||
SMCtbCursor *pCtbCur = NULL;
|
||||
SMetaDB *pDB = pMeta->pDB;
|
||||
int ret;
|
||||
|
||||
pCtbCur = (SMCtbCursor *)taosMemoryCalloc(1, sizeof(*pCtbCur));
|
||||
if (pCtbCur == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pCtbCur->suid = uid;
|
||||
ret = tdbDbcOpen(pDB->pCtbIdx, &pCtbCur->pCur);
|
||||
if (ret < 0) {
|
||||
taosMemoryFree(pCtbCur);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// TODO: move the cursor to the suid there
|
||||
|
||||
return pCtbCur;
|
||||
}
|
||||
|
||||
void metaCloseCtbCurosr(SMCtbCursor *pCtbCur) {
|
||||
if (pCtbCur) {
|
||||
if (pCtbCur->pCur) {
|
||||
tdbDbcClose(pCtbCur->pCur);
|
||||
|
||||
TDB_FREE(pCtbCur->pKey);
|
||||
TDB_FREE(pCtbCur->pVal);
|
||||
}
|
||||
|
||||
taosMemoryFree(pCtbCur);
|
||||
}
|
||||
}
|
||||
|
||||
tb_uid_t metaCtbCursorNext(SMCtbCursor *pCtbCur) {
|
||||
int ret;
|
||||
SCtbIdxKey *pCtbIdxKey;
|
||||
|
||||
ret = tdbDbNext(pCtbCur->pCur, &pCtbCur->pKey, &pCtbCur->kLen, &pCtbCur->pVal, &pCtbCur->vLen);
|
||||
if (ret < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
pCtbIdxKey = pCtbCur->pKey;
|
||||
|
||||
return pCtbIdxKey->uid;
|
||||
}
|
||||
|
||||
int metaGetTbNum(SMeta *pMeta) {
|
||||
// TODO
|
||||
// ASSERT(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct SMSmaCursor {
|
||||
TDBC *pCur;
|
||||
tb_uid_t uid;
|
||||
|
@ -768,53 +562,6 @@ int metaSaveSmaToDB(SMeta *pMeta, STSma *pSmaCfg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid, bool isDecode) {
|
||||
// TODO
|
||||
// ASSERT(0);
|
||||
// return NULL;
|
||||
#ifdef META_TDB_SMA_TEST
|
||||
SMetaDB *pDB = pMeta->pDB;
|
||||
void *pKey = NULL;
|
||||
void *pVal = NULL;
|
||||
int kLen = 0;
|
||||
int vLen = 0;
|
||||
int ret = -1;
|
||||
|
||||
// Set key
|
||||
pKey = (void *)&indexUid;
|
||||
kLen = sizeof(indexUid);
|
||||
|
||||
// Query
|
||||
ret = tdbDbGet(pDB->pSmaDB, pKey, kLen, &pVal, &vLen);
|
||||
if (ret != 0 || !pVal) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!isDecode) {
|
||||
// return raw value
|
||||
return pVal;
|
||||
}
|
||||
|
||||
// Decode
|
||||
STSma *pCfg = (STSma *)taosMemoryCalloc(1, sizeof(STSma));
|
||||
if (pCfg == NULL) {
|
||||
taosMemoryFree(pVal);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *pBuf = pVal;
|
||||
if (tDecodeTSma(pBuf, pCfg) == NULL) {
|
||||
tdDestroyTSma(pCfg);
|
||||
taosMemoryFree(pCfg);
|
||||
TDB_FREE(pVal);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TDB_FREE(pVal);
|
||||
return pCfg;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
|
@ -889,56 +636,6 @@ void metaCloseSmaCursor(SMSmaCursor *pCur) {
|
|||
#endif
|
||||
}
|
||||
|
||||
SArray *metaGetSmaTbUids(SMeta *pMeta, bool isDup) {
|
||||
// TODO
|
||||
// ASSERT(0); // comment this line to pass CI
|
||||
// return NULL:
|
||||
#ifdef META_TDB_SMA_TEST
|
||||
SArray *pUids = NULL;
|
||||
SMetaDB *pDB = pMeta->pDB;
|
||||
void *pKey;
|
||||
|
||||
// TODO: lock?
|
||||
SMSmaCursor *pCur = metaOpenSmaCursor(pMeta, 0);
|
||||
if (pCur == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
// TODO: lock?
|
||||
|
||||
SSmaIdxKey *pSmaIdxKey = NULL;
|
||||
tb_uid_t uid = 0;
|
||||
while (true) {
|
||||
// TODO: lock during iterate?
|
||||
if (tdbDbNext(pCur->pCur, &pCur->pKey, &pCur->kLen, NULL, &pCur->vLen) == 0) {
|
||||
ASSERT(pSmaIdxKey != NULL);
|
||||
pSmaIdxKey = pCur->pKey;
|
||||
|
||||
if (pSmaIdxKey->uid == 0 || pSmaIdxKey->uid == uid) {
|
||||
continue;
|
||||
}
|
||||
uid = pSmaIdxKey->uid;
|
||||
|
||||
if (!pUids) {
|
||||
pUids = taosArrayInit(16, sizeof(tb_uid_t));
|
||||
if (!pUids) {
|
||||
metaCloseSmaCursor(pCur);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
taosArrayPush(pUids, &uid);
|
||||
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
metaCloseSmaCursor(pCur);
|
||||
|
||||
return pUids;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int metaEncodeSchema(void **buf, SSchemaWrapper *pSW) {
|
||||
int tlen = 0;
|
||||
SSchema *pSchema;
|
||||
|
@ -1142,3 +839,5 @@ static void poolFree(void *arg, void *ptr) {
|
|||
|
||||
tdbOsFree(pMem);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -13,31 +13,122 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "vnodeInt.h"
|
||||
#include "meta.h"
|
||||
|
||||
int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
|
||||
// Validate the tbOptions
|
||||
// if (metaValidateTbCfg(pMeta, pTbCfg) < 0) {
|
||||
// // TODO: handle error
|
||||
// return -1;
|
||||
// }
|
||||
static int metaHandleEntry(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaSaveToTbDb(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaUpdateUidIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaUpdateNameIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
|
||||
// TODO: add atomicity
|
||||
int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
||||
SMetaEntry me = {0};
|
||||
int kLen = 0;
|
||||
int vLen = 0;
|
||||
const void *pKey = NULL;
|
||||
const void *pVal = NULL;
|
||||
void *pBuf = NULL;
|
||||
int32_t szBuf = 0;
|
||||
void *p = NULL;
|
||||
SCoder coder = {0};
|
||||
SMetaReader mr = {0};
|
||||
|
||||
if (metaSaveTableToDB(pMeta, pTbCfg, pHandle) < 0) {
|
||||
// TODO: handle error
|
||||
// validate req
|
||||
metaReaderInit(&mr, pMeta, 0);
|
||||
if (metaGetTableEntryByName(&mr, pReq->name) == 0) {
|
||||
// TODO: just for pass case
|
||||
#if 0
|
||||
terrno = TSDB_CODE_TDB_TABLE_ALREADY_EXIST;
|
||||
metaReaderClear(&mr);
|
||||
return -1;
|
||||
#else
|
||||
metaReaderClear(&mr);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
metaReaderClear(&mr);
|
||||
|
||||
if (metaSaveTableToIdx(pMeta, pTbCfg) < 0) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
}
|
||||
// set structs
|
||||
me.version = version;
|
||||
me.type = TSDB_SUPER_TABLE;
|
||||
me.uid = pReq->suid;
|
||||
me.name = pReq->name;
|
||||
me.stbEntry.schema = pReq->schema;
|
||||
me.stbEntry.schemaTag = pReq->schemaTag;
|
||||
|
||||
if (metaHandleEntry(pMeta, &me) < 0) goto _err;
|
||||
|
||||
metaDebug("vgId: %d super table is created, name:%s uid: %" PRId64, TD_VID(pMeta->pVnode), pReq->name, pReq->suid);
|
||||
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
metaError("vgId: %d failed to create super table: %s uid: %" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name,
|
||||
pReq->suid, tstrerror(terrno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
int metaCreateTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq) {
|
||||
SMetaEntry me = {0};
|
||||
SMetaReader mr = {0};
|
||||
|
||||
// validate message
|
||||
if (pReq->type != TSDB_CHILD_TABLE && pReq->type != TSDB_NORMAL_TABLE) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// preprocess req
|
||||
pReq->uid = tGenIdPI64();
|
||||
pReq->ctime = taosGetTimestampMs();
|
||||
|
||||
// validate req
|
||||
metaReaderInit(&mr, pMeta, 0);
|
||||
if (metaGetTableEntryByName(&mr, pReq->name) == 0) {
|
||||
terrno = TSDB_CODE_TDB_TABLE_ALREADY_EXIST;
|
||||
metaReaderClear(&mr);
|
||||
return -1;
|
||||
}
|
||||
metaReaderClear(&mr);
|
||||
|
||||
// build SMetaEntry
|
||||
me.version = version;
|
||||
me.type = pReq->type;
|
||||
me.uid = pReq->uid;
|
||||
me.name = pReq->name;
|
||||
if (me.type == TSDB_CHILD_TABLE) {
|
||||
me.ctbEntry.ctime = pReq->ctime;
|
||||
me.ctbEntry.ttlDays = pReq->ttl;
|
||||
me.ctbEntry.suid = pReq->ctb.suid;
|
||||
me.ctbEntry.pTags = pReq->ctb.pTag;
|
||||
} else {
|
||||
me.ntbEntry.ctime = pReq->ctime;
|
||||
me.ntbEntry.ttlDays = pReq->ttl;
|
||||
me.ntbEntry.schema = pReq->ntb.schema;
|
||||
}
|
||||
|
||||
if (metaHandleEntry(pMeta, &me) < 0) goto _err;
|
||||
|
||||
metaDebug("vgId:%d table %s uid %" PRId64 " is created, type:%" PRId8, TD_VID(pMeta->pVnode), pReq->name, pReq->uid,
|
||||
pReq->type);
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
metaError("vgId:%d failed to create table:%s type:%s since %s", TD_VID(pMeta->pVnode), pReq->name,
|
||||
pReq->type == TSDB_CHILD_TABLE ? "child table" : "normal table", tstrerror(terrno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int metaDropTable(SMeta *pMeta, tb_uid_t uid) {
|
||||
#if 0
|
||||
if (metaRemoveTableFromIdx(pMeta, uid) < 0) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
|
@ -47,7 +138,168 @@ int metaDropTable(SMeta *pMeta, tb_uid_t uid) {
|
|||
// TODO
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int metaSaveToTbDb(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
STbDbKey tbDbKey;
|
||||
void *pKey = NULL;
|
||||
void *pVal = NULL;
|
||||
int kLen = 0;
|
||||
int vLen = 0;
|
||||
SCoder coder = {0};
|
||||
|
||||
// set key and value
|
||||
tbDbKey.version = pME->version;
|
||||
tbDbKey.uid = pME->uid;
|
||||
|
||||
pKey = &tbDbKey;
|
||||
kLen = sizeof(tbDbKey);
|
||||
|
||||
int32_t ret = 0;
|
||||
tEncodeSize(metaEncodeEntry, pME, vLen, ret);
|
||||
if (ret < 0) {
|
||||
goto _err;
|
||||
}
|
||||
|
||||
pVal = taosMemoryMalloc(vLen);
|
||||
if (pVal == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pVal, vLen, TD_ENCODER);
|
||||
|
||||
if (metaEncodeEntry(&coder, pME) < 0) {
|
||||
goto _err;
|
||||
}
|
||||
|
||||
tCoderClear(&coder);
|
||||
|
||||
// write to table.db
|
||||
if (tdbDbInsert(pMeta->pTbDb, pKey, kLen, pVal, vLen, &pMeta->txn) < 0) {
|
||||
goto _err;
|
||||
}
|
||||
|
||||
taosMemoryFree(pVal);
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
taosMemoryFree(pVal);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int metaUpdateUidIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
return tdbDbInsert(pMeta->pUidIdx, &pME->uid, sizeof(tb_uid_t), &pME->version, sizeof(int64_t), &pMeta->txn);
|
||||
}
|
||||
|
||||
static int metaUpdateNameIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
return tdbDbInsert(pMeta->pNameIdx, pME->name, strlen(pME->name) + 1, &pME->uid, sizeof(tb_uid_t), &pMeta->txn);
|
||||
}
|
||||
|
||||
static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
int32_t ttlDays;
|
||||
int64_t ctime;
|
||||
STtlIdxKey ttlKey;
|
||||
|
||||
if (pME->type == TSDB_CHILD_TABLE) {
|
||||
ctime = pME->ctbEntry.ctime;
|
||||
ttlDays = pME->ctbEntry.ttlDays;
|
||||
} else if (pME->type == TSDB_NORMAL_TABLE) {
|
||||
ctime = pME->ntbEntry.ctime;
|
||||
ttlDays = pME->ntbEntry.ttlDays;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
if (ttlDays <= 0) return 0;
|
||||
|
||||
ttlKey.dtime = ctime + ttlDays * 24 * 60 * 60;
|
||||
ttlKey.uid = pME->uid;
|
||||
|
||||
return tdbDbInsert(pMeta->pTtlIdx, &ttlKey, sizeof(ttlKey), NULL, 0, &pMeta->txn);
|
||||
}
|
||||
|
||||
static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
SCtbIdxKey ctbIdxKey = {.suid = pME->ctbEntry.suid, .uid = pME->uid};
|
||||
return tdbDbInsert(pMeta->pCtbIdx, &ctbIdxKey, sizeof(ctbIdxKey), NULL, 0, &pMeta->txn);
|
||||
}
|
||||
|
||||
static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
SCoder coder = {0};
|
||||
void *pVal = NULL;
|
||||
int vLen = 0;
|
||||
int rcode = 0;
|
||||
SSkmDbKey skmDbKey = {0};
|
||||
const SSchemaWrapper *pSW;
|
||||
|
||||
if (pME->type == TSDB_SUPER_TABLE) {
|
||||
pSW = &pME->stbEntry.schema;
|
||||
} else if (pME->type == TSDB_NORMAL_TABLE) {
|
||||
pSW = &pME->ntbEntry.schema;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
skmDbKey.uid = pME->uid;
|
||||
skmDbKey.sver = pSW->sver;
|
||||
|
||||
// encode schema
|
||||
int32_t ret = 0;
|
||||
tEncodeSize(tEncodeSSchemaWrapper, pSW, vLen, ret);
|
||||
if (ret < 0) return -1;
|
||||
pVal = taosMemoryMalloc(vLen);
|
||||
if (pVal == NULL) {
|
||||
rcode = -1;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pVal, vLen, TD_ENCODER);
|
||||
tEncodeSSchemaWrapper(&coder, pSW);
|
||||
|
||||
if (tdbDbInsert(pMeta->pSkmDb, &skmDbKey, sizeof(skmDbKey), pVal, vLen, &pMeta->txn) < 0) {
|
||||
rcode = -1;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
_exit:
|
||||
taosMemoryFree(pVal);
|
||||
tCoderClear(&coder);
|
||||
return rcode;
|
||||
}
|
||||
|
||||
static int metaHandleEntry(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
// save to table.db
|
||||
if (metaSaveToTbDb(pMeta, pME) < 0) return -1;
|
||||
|
||||
// update uid.idx
|
||||
if (metaUpdateUidIdx(pMeta, pME) < 0) return -1;
|
||||
|
||||
// update name.idx
|
||||
if (metaUpdateNameIdx(pMeta, pME) < 0) return -1;
|
||||
|
||||
if (pME->type == TSDB_CHILD_TABLE) {
|
||||
// update ctb.idx
|
||||
if (metaUpdateCtbIdx(pMeta, pME) < 0) return -1;
|
||||
|
||||
// update tag.idx
|
||||
if (metaUpdateTagIdx(pMeta, pME) < 0) return -1;
|
||||
} else {
|
||||
// update schema.db
|
||||
if (metaSaveToSkmDb(pMeta, pME) < 0) return -1;
|
||||
}
|
||||
|
||||
if (pME->type != TSDB_SUPER_TABLE) {
|
||||
if (metaUpdateTtlIdx(pMeta, pME) < 0) return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue