Merge remote-tracking branch 'origin/3.0' into feature/qnode4
This commit is contained in:
commit
49e0ecdb9b
|
@ -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
|
||||
RUN apt-get update && apt-get -y install tree vim tmux
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
// "forwardPorts": [],
|
||||
// Use 'postCreateCommand' to run commands after the container is created.
|
||||
// "postCreateCommand": "gcc -v",
|
||||
"postCreateCommand": "wget https://raw.githubusercontent.com/hzcheng/config/master/.tmux.conf -P /root",
|
||||
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
|
||||
"remoteUser": "root"
|
||||
}
|
|
@ -5,6 +5,7 @@ compile_commands.json
|
|||
.tasks
|
||||
.vimspector.json
|
||||
.vscode/
|
||||
.vscode
|
||||
.idea/
|
||||
cmake-build-debug/
|
||||
cmake-build-release/
|
||||
|
|
|
@ -179,7 +179,7 @@ typedef struct SQueryCostInfo {
|
|||
uint32_t totalBlocks;
|
||||
uint32_t loadBlocks;
|
||||
uint32_t loadBlockStatis;
|
||||
uint32_t discardBlocks;
|
||||
uint32_t skipBlocks;
|
||||
uint64_t elapsedTime;
|
||||
uint64_t firstStageMergeTime;
|
||||
uint64_t winInfoSize;
|
||||
|
|
|
@ -3144,7 +3144,7 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa
|
|||
if ((*status) == BLK_DATA_NO_NEEDED || (*status) == BLK_DATA_DISCARD) {
|
||||
qDebug("QInfo:0x%"PRIx64" data block discard, brange:%" PRId64 "-%" PRId64 ", rows:%d", pQInfo->qId, pBlockInfo->window.skey,
|
||||
pBlockInfo->window.ekey, pBlockInfo->rows);
|
||||
pCost->discardBlocks += 1;
|
||||
pCost->skipBlocks += 1;
|
||||
} else if ((*status) == BLK_DATA_STATIS_NEEDED) {
|
||||
// this function never returns error?
|
||||
pCost->loadBlockStatis += 1;
|
||||
|
@ -3184,7 +3184,7 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa
|
|||
load = topbot_datablock_filter(&pTableScanInfo->pCtx[i], (char*)&(pBlock->pBlockStatis[i].min),
|
||||
(char*)&(pBlock->pBlockStatis[i].max));
|
||||
if (!load) { // current block has been discard due to filter applied
|
||||
pCost->discardBlocks += 1;
|
||||
pCost->skipBlocks += 1;
|
||||
qDebug("QInfo:0x%"PRIx64" data block discard, brange:%" PRId64 "-%" PRId64 ", rows:%d", pQInfo->qId,
|
||||
pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows);
|
||||
(*status) = BLK_DATA_DISCARD;
|
||||
|
@ -3196,7 +3196,7 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa
|
|||
|
||||
// current block has been discard due to filter applied
|
||||
if (!doFilterByBlockStatistics(pRuntimeEnv, pBlock->pBlockStatis, pTableScanInfo->pCtx, pBlockInfo->rows)) {
|
||||
pCost->discardBlocks += 1;
|
||||
pCost->skipBlocks += 1;
|
||||
qDebug("QInfo:0x%"PRIx64" data block discard, brange:%" PRId64 "-%" PRId64 ", rows:%d", pQInfo->qId, pBlockInfo->window.skey,
|
||||
pBlockInfo->window.ekey, pBlockInfo->rows);
|
||||
(*status) = BLK_DATA_DISCARD;
|
||||
|
|
|
@ -17,6 +17,7 @@ include(${TD_SUPPORT_DIR}/cmake.platform)
|
|||
include(${TD_SUPPORT_DIR}/cmake.define)
|
||||
include(${TD_SUPPORT_DIR}/cmake.options)
|
||||
include(${TD_SUPPORT_DIR}/cmake.version)
|
||||
include(${TD_SUPPORT_DIR}/cmake.install)
|
||||
|
||||
# contrib
|
||||
add_subdirectory(contrib)
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
#set output directory
|
||||
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/lib)
|
||||
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/bin)
|
||||
SET(TD_TESTS_OUTPUT_DIR ${PROJECT_BINARY_DIR}/test)
|
||||
|
||||
MESSAGE(STATUS "Project source directory: " ${PROJECT_SOURCE_DIR})
|
||||
MESSAGE(STATUS "Project binary files output path: " ${PROJECT_BINARY_DIR})
|
||||
MESSAGE(STATUS "Project executable files output path: " ${EXECUTABLE_OUTPUT_PATH})
|
||||
MESSAGE(STATUS "Project library files output path: " ${LIBRARY_OUTPUT_PATH})
|
||||
|
||||
if (NOT DEFINED TD_GRANT)
|
||||
SET(TD_GRANT FALSE)
|
||||
endif()
|
||||
if (NOT DEFINED TD_USB_DONGLE)
|
||||
SET(TD_USB_DONGLE FALSE)
|
||||
endif()
|
||||
IF (TD_GRANT)
|
||||
ADD_DEFINITIONS(-D_GRANT)
|
||||
ENDIF ()
|
||||
|
||||
IF ("${BUILD_TOOLS}" STREQUAL "")
|
||||
IF (TD_LINUX)
|
||||
|
@ -46,16 +50,20 @@ IF (TD_WINDOWS)
|
|||
ENDIF ()
|
||||
|
||||
ELSE ()
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3")
|
||||
#SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3")
|
||||
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3")
|
||||
IF (${SANITIZER} MATCHES "true")
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3")
|
||||
MESSAGE(STATUS "Will compile with Address Sanitizer!")
|
||||
ELSE ()
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3")
|
||||
ENDIF ()
|
||||
|
||||
MESSAGE("System processor ID: ${CMAKE_SYSTEM_PROCESSOR}")
|
||||
IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
|
||||
ADD_DEFINITIONS("-D_TD_ARM_")
|
||||
ELSE ()
|
||||
ADD_DEFINITIONS("-msse4.2 -mfma")
|
||||
ENDIF ()
|
||||
MESSAGE("System processor ID: ${CMAKE_SYSTEM_PROCESSOR}")
|
||||
IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
|
||||
ADD_DEFINITIONS("-D_TD_ARM_")
|
||||
ELSE ()
|
||||
ADD_DEFINITIONS("-msse4.2 -mfma")
|
||||
ENDIF ()
|
||||
|
||||
ENDIF ()
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
IF (TD_LINUX)
|
||||
SET(TD_MAKE_INSTALL_SH "${TD_SOURCE_DIR}/packaging/make_install.sh")
|
||||
INSTALL(CODE "MESSAGE(\"make install script: ${TD_MAKE_INSTALL_SH}\")")
|
||||
INSTALL(CODE "execute_process(COMMAND bash ${TD_MAKE_INSTALL_SH} ${TD_SOURCE_DIR} ${PROJECT_BINARY_DIR} Linux ${TD_VER_NUMBER})")
|
||||
ELSEIF (TD_WINDOWS)
|
||||
SET(CMAKE_INSTALL_PREFIX C:/TDengine)
|
||||
|
||||
INSTALL(DIRECTORY ${TD_SOURCE_DIR}/src/connector/go DESTINATION connector)
|
||||
INSTALL(DIRECTORY ${TD_SOURCE_DIR}/src/connector/nodejs DESTINATION connector)
|
||||
INSTALL(DIRECTORY ${TD_SOURCE_DIR}/src/connector/python DESTINATION connector)
|
||||
INSTALL(DIRECTORY ${TD_SOURCE_DIR}/src/connector/C\# DESTINATION connector)
|
||||
INSTALL(DIRECTORY ${TD_SOURCE_DIR}/examples DESTINATION .)
|
||||
INSTALL(FILES ${TD_SOURCE_DIR}/packaging/cfg/taos.cfg DESTINATION cfg)
|
||||
INSTALL(FILES ${TD_SOURCE_DIR}/src/inc/taos.h DESTINATION include)
|
||||
INSTALL(FILES ${TD_SOURCE_DIR}/src/inc/taoserror.h DESTINATION include)
|
||||
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos.lib DESTINATION driver)
|
||||
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos_static.lib DESTINATION driver)
|
||||
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos.exp DESTINATION driver)
|
||||
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos.dll DESTINATION driver)
|
||||
|
||||
IF (TD_MVN_INSTALLED)
|
||||
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.38-dist.jar DESTINATION connector/jdbc)
|
||||
ENDIF ()
|
||||
ELSEIF (TD_DARWIN)
|
||||
SET(TD_MAKE_INSTALL_SH "${TD_SOURCE_DIR}/packaging/tools/make_install.sh")
|
||||
INSTALL(CODE "MESSAGE(\"make install script: ${TD_MAKE_INSTALL_SH}\")")
|
||||
INSTALL(CODE "execute_process(COMMAND bash ${TD_MAKE_INSTALL_SH} ${TD_SOURCE_DIR} ${PROJECT_BINARY_DIR} Darwin ${TD_VER_NUMBER})")
|
||||
ENDIF ()
|
|
@ -18,15 +18,15 @@ target_sources(demoapi
|
|||
)
|
||||
|
||||
target_link_libraries(tmq
|
||||
taos
|
||||
taos_static
|
||||
)
|
||||
|
||||
target_link_libraries(tstream
|
||||
taos
|
||||
taos_static
|
||||
)
|
||||
|
||||
target_link_libraries(demoapi
|
||||
taos
|
||||
taos_static
|
||||
)
|
||||
|
||||
target_include_directories(tmq
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
fprintf(stderr, "\033[0m"); } while(0)
|
||||
|
||||
int64_t g_num_of_tb = 2;
|
||||
int64_t g_num_of_rec = 2;
|
||||
int64_t g_num_of_rec = 3;
|
||||
|
||||
static struct argp_option options[] = {
|
||||
{"tables", 't', "NUMBER", 0, "Number of child tables, default is 10000."},
|
||||
|
@ -42,10 +42,18 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
|||
switch (key) {
|
||||
case 't':
|
||||
g_num_of_tb = atoll(arg);
|
||||
if (g_num_of_tb < 1) {
|
||||
warnPrint("minimal g_num_of_tb is %d\n", 1);
|
||||
g_num_of_tb = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
g_num_of_rec = atoll(arg);
|
||||
if (g_num_of_rec < 2) {
|
||||
warnPrint("minimal g_num_of_rec is %d\n", 2);
|
||||
g_num_of_rec = 2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -65,22 +73,53 @@ static void prepare_data(TAOS* taos) {
|
|||
usleep(100000);
|
||||
taos_select_db(taos, "test");
|
||||
|
||||
res = taos_query(taos, "create table meters(ts timestamp, f float, n int, b binary(20)) tags(area int, localtion binary(20));");
|
||||
char command[1024] = {0};
|
||||
sprintf(command, "%s", "create table meters(ts timestamp, f float, n int, bin1 binary(20), c nchar(20), bin2 binary(20)) tags(area int, city binary(20), dist nchar(20), street binary(20));");
|
||||
res = taos_query(taos, command);
|
||||
if ((res) && (0 == taos_errno(res))) {
|
||||
okPrint("%s created\n", "meters");
|
||||
} else {
|
||||
errorPrint("%s() LN%d: %s\n",
|
||||
__func__, __LINE__, taos_errstr(res));
|
||||
taos_free_result(res);
|
||||
exit(1);
|
||||
}
|
||||
taos_free_result(res);
|
||||
|
||||
char command[1024] = {0};
|
||||
for (int64_t i = 0; i < g_num_of_tb; i ++) {
|
||||
sprintf(command, "create table t%"PRId64" using meters tags(%"PRId64", '%s');",
|
||||
i, i, (i%2)?"beijing":"shanghai");
|
||||
sprintf(command, "create table t%"PRId64" using meters "
|
||||
"tags(%"PRId64", '%s', '%s', '%s');",
|
||||
i, i, (i%2)?"beijing":"shanghai",
|
||||
(i%2)?"朝阳区":"黄浦区",
|
||||
(i%2)?"长安街":"中山路");
|
||||
/* sprintf(command, "create table t%"PRId64" using meters "
|
||||
"tags(%"PRId64", '%s', '%s', '%s');",
|
||||
i, i,
|
||||
(i%2)?"beijing":"shanghai",
|
||||
(i%2)?"chaoyang":"huangpu",
|
||||
(i%2?"changan street":"jianguo rd"));
|
||||
*/
|
||||
res = taos_query(taos, command);
|
||||
if ((res) && (0 == taos_errno(res))) {
|
||||
okPrint("t%" PRId64 " created\n", i);
|
||||
} else {
|
||||
errorPrint("%s() LN%d: %s\n",
|
||||
__func__, __LINE__, taos_errstr(res));
|
||||
}
|
||||
taos_free_result(res);
|
||||
|
||||
int64_t j = 0;
|
||||
int64_t total = 0;
|
||||
int64_t affected;
|
||||
for (; j < g_num_of_rec -1; j ++) {
|
||||
sprintf(command, "insert into t%"PRId64" values(%" PRId64 ", %f, %"PRId64", '%c%d')",
|
||||
i, 1650000000000+j, (float)j, j, 'a'+(int)j%10, rand());
|
||||
for (; j < g_num_of_rec -2; j ++) {
|
||||
sprintf(command, "insert into t%"PRId64" "
|
||||
"values(%" PRId64 ", %f, %"PRId64", "
|
||||
"'%c%d', '%s%c%d', '%c%d')",
|
||||
i, 1650000000000+j, (float)j, j,
|
||||
'a'+(int)j%25, rand(),
|
||||
"涛思", 'z' - (int)j%25, rand(),
|
||||
'b' - (int)j%25, rand()
|
||||
);
|
||||
res = taos_query(taos, command);
|
||||
if ((res) && (0 == taos_errno(res))) {
|
||||
affected = taos_affected_rows(res);
|
||||
|
@ -91,8 +130,25 @@ static void prepare_data(TAOS* taos) {
|
|||
}
|
||||
taos_free_result(res);
|
||||
}
|
||||
sprintf(command, "insert into t%"PRId64" values(%" PRId64 ", NULL, NULL, NULL)",
|
||||
i, 1650000000000+j+1);
|
||||
sprintf(command, "insert into t%"PRId64" values(%" PRId64 ", "
|
||||
"NULL, NULL, NULL, NULL, NULL)",
|
||||
i, 1650000000000+j);
|
||||
res = taos_query(taos, command);
|
||||
if ((res) && (0 == taos_errno(res))) {
|
||||
affected = taos_affected_rows(res);
|
||||
total += affected;
|
||||
} else {
|
||||
errorPrint("%s() LN%d: %s\n",
|
||||
__func__, __LINE__, taos_errstr(res));
|
||||
}
|
||||
sprintf(command, "insert into t%"PRId64" "
|
||||
"values(%" PRId64 ", %f, %"PRId64", "
|
||||
"'%c%d', '%s%c%d', '%c%d')",
|
||||
i, 1650000000000+j+1, (float)j, j,
|
||||
'a'+(int)j%25, rand(),
|
||||
"数据", 'z' - (int)j%25, rand(),
|
||||
'b' - (int)j%25, rand()
|
||||
);
|
||||
res = taos_query(taos, command);
|
||||
if ((res) && (0 == taos_errno(res))) {
|
||||
affected = taos_affected_rows(res);
|
||||
|
@ -103,28 +159,121 @@ static void prepare_data(TAOS* taos) {
|
|||
}
|
||||
taos_free_result(res);
|
||||
|
||||
printf("insert %"PRId64" records into t%"PRId64", total affected rows: %"PRId64"\n", j, i, total);
|
||||
okPrint("insert %"PRId64" records into t%"PRId64", "
|
||||
"total affected rows: %"PRId64"\n", j, i, total);
|
||||
}
|
||||
}
|
||||
|
||||
static int print_result(TAOS_RES* res, int block) {
|
||||
static int print_result(char *tbname, TAOS_RES* res, int block) {
|
||||
int64_t num_rows = 0;
|
||||
TAOS_ROW row = NULL;
|
||||
int num_fields = taos_num_fields(res);
|
||||
TAOS_FIELD* fields = taos_fetch_fields(res);
|
||||
|
||||
for (int f = 0; f < num_fields; f++) {
|
||||
printf("fields[%d].name=%s, fields[%d].type=%d, fields[%d].bytes=%d\n",
|
||||
f, fields[f].name, f, fields[f].type, f, fields[f].bytes);
|
||||
}
|
||||
|
||||
if (block) {
|
||||
warnPrint("%s() LN%d, call taos_fetch_block()\n", __func__, __LINE__);
|
||||
warnPrint("%s", "call taos_fetch_block()\n");
|
||||
int rows = 0;
|
||||
while ((rows = taos_fetch_block(res, &row))) {
|
||||
int *lengths = taos_fetch_lengths(res);
|
||||
for (int f = 0; f < num_fields; f++) {
|
||||
if ((fields[f].type != TSDB_DATA_TYPE_VARCHAR)
|
||||
&& (fields[f].type != TSDB_DATA_TYPE_NCHAR)
|
||||
&& (fields[f].type != TSDB_DATA_TYPE_JSON)) {
|
||||
printf("col%d type is %d, no need get offset\n",
|
||||
f, fields[f].type);
|
||||
for (int64_t c = 0; c < rows; c++) {
|
||||
switch(fields[f].type) {
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
if (taos_is_null(res, c, f)) {
|
||||
printf("col%d, row: %"PRId64" "
|
||||
"value: NULL\n", f, c);
|
||||
} else {
|
||||
printf("col%d, row: %"PRId64", "
|
||||
"value: %"PRId64"\n",
|
||||
f, c,
|
||||
*(int64_t*)(row[f]+c*sizeof(int64_t)));
|
||||
}
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
if (taos_is_null(res, c, f)) {
|
||||
printf("col%d, row: %"PRId64" "
|
||||
"value: NULL\n", f, c);
|
||||
} else {
|
||||
printf("col%d, row: %"PRId64", "
|
||||
"value: %d\n",
|
||||
f, c,
|
||||
*(int32_t*)(row[f]+c*sizeof(int32_t)));
|
||||
}
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
if (taos_is_null(res, c, f)) {
|
||||
printf("col%d, row: %"PRId64" "
|
||||
"value: NULL\n", f, c);
|
||||
} else {
|
||||
printf("col%d, row: %"PRId64", "
|
||||
"value: %f\n",
|
||||
f, c,
|
||||
*(float*)(row[f]+c*sizeof(float)));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("type: %d is not processed\n",
|
||||
fields[f].type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int *offsets = taos_get_column_data_offset(res, f);
|
||||
if (offsets) {
|
||||
for (int c = 0; c < rows; c++) {
|
||||
if (offsets[c] != -1) {
|
||||
int length = *(int16_t*)(row[f] + offsets[c]);
|
||||
char *buf = calloc(1, length + 1);
|
||||
strncpy(buf, (char *)(row[f] + offsets[c] + 2), length);
|
||||
printf("row: %d, col: %d, offset: %d, length: %d, content: %s\n",
|
||||
c, f, offsets[c], length, buf);
|
||||
free(buf);
|
||||
} else {
|
||||
printf("row: %d, col: %d, offset: -1, means content is NULL\n",
|
||||
c, f);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
errorPrint("%s() LN%d: col%d's offsets is NULL\n",
|
||||
__func__, __LINE__, f);
|
||||
}
|
||||
}
|
||||
}
|
||||
num_rows += rows;
|
||||
}
|
||||
} else {
|
||||
warnPrint("%s() LN%d, call taos_fetch_rows()\n", __func__, __LINE__);
|
||||
warnPrint("%s", "call taos_fetch_rows()\n");
|
||||
while ((row = taos_fetch_row(res))) {
|
||||
char temp[256] = {0};
|
||||
taos_print_row(temp, row, fields, num_fields);
|
||||
puts(temp);
|
||||
|
||||
int* lengths = taos_fetch_lengths(res);
|
||||
if (lengths) {
|
||||
for (int c = 0; c < num_fields; c++) {
|
||||
printf("row: %"PRId64", col: %d, is_null: %s, length of column %d is %d\n",
|
||||
num_rows, c,
|
||||
taos_is_null(res, num_rows, c)?"True":"False",
|
||||
c, lengths[c]);
|
||||
}
|
||||
} else {
|
||||
errorPrint("%s() LN%d: %s's lengths is NULL\n",
|
||||
__func__, __LINE__, tbname);
|
||||
}
|
||||
|
||||
num_rows ++;
|
||||
}
|
||||
}
|
||||
|
@ -134,29 +283,22 @@ static int print_result(TAOS_RES* res, int block) {
|
|||
|
||||
static void verify_query(TAOS* taos) {
|
||||
// TODO: select count(tbname) from stable once stable query work
|
||||
//
|
||||
char tbname[193] = {0};
|
||||
char command[1024] = {0};
|
||||
|
||||
for (int64_t i = 0; i < g_num_of_tb; i++) {
|
||||
sprintf(command, "select * from t%"PRId64"", i);
|
||||
sprintf(tbname, "t%"PRId64"", i);
|
||||
sprintf(command, "select * from %s", tbname);
|
||||
TAOS_RES* res = taos_query(taos, command);
|
||||
|
||||
if (res) {
|
||||
if (0 == taos_errno(res)) {
|
||||
int field_count = taos_field_count(res);
|
||||
printf("field_count: %d\n", field_count);
|
||||
int* lengths = taos_fetch_lengths(res);
|
||||
if (lengths) {
|
||||
for (int c = 0; c < field_count; c++) {
|
||||
printf("length of column %d is %d\n", c, lengths[c]);
|
||||
}
|
||||
} else {
|
||||
errorPrint("%s() LN%d: t%"PRId64"'s lengths is NULL\n",
|
||||
__func__, __LINE__, i);
|
||||
}
|
||||
|
||||
int64_t rows = print_result(res, i % 2);
|
||||
printf("rows is: %"PRId64"\n", rows);
|
||||
|
||||
int64_t rows = print_result(tbname, res, i % 2);
|
||||
okPrint("total query %s result rows is: %"PRId64"\n",
|
||||
tbname, rows);
|
||||
} else {
|
||||
errorPrint("%s() LN%d: %s\n",
|
||||
__func__, __LINE__, taos_errstr(res));
|
||||
|
@ -190,7 +332,7 @@ int main(int argc, char *argv[]) {
|
|||
verify_query(taos);
|
||||
|
||||
taos_close(taos);
|
||||
printf("done\n");
|
||||
okPrint("%s", "done\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -19,8 +19,20 @@
|
|||
#include <time.h>
|
||||
#include "taos.h"
|
||||
|
||||
static int running = 1;
|
||||
/*static void msg_process(tmq_message_t* message) { tmqShowMsg(message); }*/
|
||||
static int running = 1;
|
||||
static void msg_process(TAOS_RES* msg) {
|
||||
char buf[1024];
|
||||
printf("topic: %s\n", tmq_get_topic_name(msg));
|
||||
printf("vg:%d\n", tmq_get_vgroup_id(msg));
|
||||
while (1) {
|
||||
TAOS_ROW row = taos_fetch_row(msg);
|
||||
if (row == NULL) break;
|
||||
TAOS_FIELD* fields = taos_fetch_fields(msg);
|
||||
int32_t numOfFields = taos_field_count(msg);
|
||||
taos_print_row(buf, row, fields, numOfFields);
|
||||
printf("%s\n", buf);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t init_env() {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
|
@ -90,7 +102,7 @@ int32_t create_topic() {
|
|||
|
||||
/*const char* sql = "select * from tu1";*/
|
||||
/*pRes = tmq_create_topic(pConn, "test_stb_topic_1", sql, strlen(sql));*/
|
||||
pRes = taos_query(pConn, "create topic topic_ctb_column as select ts, c1 from ct1");
|
||||
pRes = taos_query(pConn, "create topic topic_ctb_column as select ts, c1, c2, c3 from ct1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create topic topic_ctb_column, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
|
@ -133,6 +145,7 @@ void tmq_commit_cb_print(tmq_t* tmq, tmq_resp_err_t resp, tmq_topic_vgroup_list_
|
|||
}
|
||||
|
||||
tmq_t* build_consumer() {
|
||||
#if 0
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
|
@ -141,11 +154,15 @@ tmq_t* build_consumer() {
|
|||
printf("error in use db, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
#endif
|
||||
|
||||
tmq_conf_t* conf = tmq_conf_new();
|
||||
tmq_conf_set(conf, "group.id", "tg2");
|
||||
tmq_conf_set(conf, "td.connect.user", "root");
|
||||
tmq_conf_set(conf, "td.connect.pass", "taosdata");
|
||||
tmq_conf_set(conf, "td.connect.db", "abc1");
|
||||
tmq_conf_set_offset_commit_cb(conf, tmq_commit_cb_print);
|
||||
tmq_t* tmq = tmq_consumer_new(pConn, conf, NULL, 0);
|
||||
tmq_t* tmq = tmq_consumer_new1(conf, NULL, 0);
|
||||
return tmq;
|
||||
}
|
||||
|
||||
|
@ -200,7 +217,7 @@ void sync_consume_loop(tmq_t* tmq, tmq_list_t* topics) {
|
|||
while (running) {
|
||||
TAOS_RES* tmqmessage = tmq_consumer_poll(tmq, 1000);
|
||||
if (tmqmessage) {
|
||||
/*msg_process(tmqmessage);*/
|
||||
msg_process(tmqmessage);
|
||||
tmq_message_destroy(tmqmessage);
|
||||
|
||||
if ((++msg_count % MIN_COMMIT_COUNT) == 0) tmq_commit(tmq, NULL, 0);
|
||||
|
|
|
@ -4,5 +4,5 @@ if [ "$lua_header_installed" = "0" ]; then
|
|||
sudo apt install -y liblua5.3-dev
|
||||
fi
|
||||
|
||||
gcc -std=c99 lua_connector.c -fPIC -shared -o luaconnector.so -Wall -ltaos -I/usr/include/lua5.3
|
||||
gcc -std=c99 lua_connector.c -fPIC -shared -o luaconnector.so -Wall -ltaos -I/usr/include/lua5.3 -I../../include/client
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include <lauxlib.h>
|
||||
#include <lua.h>
|
||||
#include <lualib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "../../../include/client/taos.h"
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
#include <lualib.h>
|
||||
#include "taos.h"
|
||||
|
||||
struct cb_param{
|
||||
lua_State* state;
|
||||
|
@ -28,14 +28,14 @@ static int l_connect(lua_State *L){
|
|||
|
||||
luaL_checktype(L, 1, LUA_TTABLE);
|
||||
|
||||
lua_getfield(L,1,"host");
|
||||
lua_getfield(L, 1,"host");
|
||||
if (lua_isstring(L,-1)){
|
||||
host = lua_tostring(L, -1);
|
||||
// printf("host = %s\n", host);
|
||||
}
|
||||
|
||||
lua_getfield(L, 1, "port");
|
||||
if (lua_isinteger(L,-1)){
|
||||
if (lua_isinteger(L, -1)){
|
||||
port = lua_tointeger(L, -1);
|
||||
//printf("port = %d\n", port);
|
||||
}
|
||||
|
@ -60,8 +60,6 @@ static int l_connect(lua_State *L){
|
|||
|
||||
lua_settop(L,0);
|
||||
|
||||
taos_init();
|
||||
|
||||
lua_newtable(L);
|
||||
int table_index = lua_gettop(L);
|
||||
|
||||
|
@ -102,7 +100,7 @@ static int l_query(lua_State *L){
|
|||
printf("failed, reason:%s\n", taos_errstr(result));
|
||||
lua_pushinteger(L, -1);
|
||||
lua_setfield(L, table_index, "code");
|
||||
lua_pushstring(L, taos_errstr(taos));
|
||||
lua_pushstring(L, taos_errstr(result));
|
||||
lua_setfield(L, table_index, "error");
|
||||
|
||||
return 1;
|
||||
|
@ -113,7 +111,6 @@ static int l_query(lua_State *L){
|
|||
int rows = 0;
|
||||
int num_fields = taos_field_count(result);
|
||||
const TAOS_FIELD *fields = taos_fetch_fields(result);
|
||||
//char temp[256];
|
||||
|
||||
const int affectRows = taos_affected_rows(result);
|
||||
// printf(" affect rows:%d\r\n", affectRows);
|
||||
|
@ -122,7 +119,7 @@ static int l_query(lua_State *L){
|
|||
lua_pushinteger(L, affectRows);
|
||||
lua_setfield(L, table_index, "affected");
|
||||
lua_newtable(L);
|
||||
|
||||
|
||||
while ((row = taos_fetch_row(result))) {
|
||||
//printf("row index:%d\n",rows);
|
||||
rows++;
|
||||
|
@ -136,17 +133,21 @@ static int l_query(lua_State *L){
|
|||
}
|
||||
|
||||
lua_pushstring(L,fields[i].name);
|
||||
|
||||
int32_t* length = taos_fetch_lengths(result);
|
||||
switch (fields[i].type) {
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
lua_pushinteger(L,*((char *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
lua_pushinteger(L,*((short *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
lua_pushinteger(L,*((int *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
lua_pushinteger(L,*((int64_t *)row[i]));
|
||||
break;
|
||||
|
@ -156,9 +157,11 @@ static int l_query(lua_State *L){
|
|||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
lua_pushnumber(L,*((double *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_JSON:
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
lua_pushstring(L,(char *)row[i]);
|
||||
//printf("type:%d, max len:%d, current len:%d\n",fields[i].type, fields[i].bytes, length[i]);
|
||||
lua_pushlstring(L,(char *)row[i], length[i]);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
lua_pushinteger(L,*((int64_t *)row[i]));
|
||||
|
@ -166,6 +169,7 @@ static int l_query(lua_State *L){
|
|||
case TSDB_DATA_TYPE_BOOL:
|
||||
lua_pushinteger(L,*((char *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_NULL:
|
||||
default:
|
||||
lua_pushnil(L);
|
||||
break;
|
||||
|
@ -235,112 +239,6 @@ static int l_async_query(lua_State *L){
|
|||
return 1;
|
||||
}
|
||||
|
||||
void stream_cb(void *param, TAOS_RES *result, TAOS_ROW row){
|
||||
struct cb_param* p = (struct cb_param*) param;
|
||||
TAOS_FIELD *fields = taos_fetch_fields(result);
|
||||
int numFields = taos_num_fields(result);
|
||||
|
||||
// printf("\nnumfields:%d\n", numFields);
|
||||
//printf("\n\r-----------------------------------------------------------------------------------\n");
|
||||
|
||||
lua_State *L = p->state;
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, p->callback);
|
||||
|
||||
lua_newtable(L);
|
||||
|
||||
for (int i = 0; i < numFields; ++i) {
|
||||
if (row[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
lua_pushstring(L,fields[i].name);
|
||||
|
||||
switch (fields[i].type) {
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
lua_pushinteger(L,*((char *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
lua_pushinteger(L,*((short *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
lua_pushinteger(L,*((int *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
lua_pushinteger(L,*((int64_t *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
lua_pushnumber(L,*((float *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
lua_pushnumber(L,*((double *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
lua_pushstring(L,(char *)row[i]);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
lua_pushinteger(L,*((int64_t *)row[i]));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
lua_pushinteger(L,*((char *)row[i]));
|
||||
break;
|
||||
default:
|
||||
lua_pushnil(L);
|
||||
break;
|
||||
}
|
||||
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
|
||||
lua_call(L, 1, 0);
|
||||
|
||||
// printf("-----------------------------------------------------------------------------------\n\r");
|
||||
}
|
||||
|
||||
static int l_open_stream(lua_State *L){
|
||||
int r = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
TAOS * taos = (TAOS*)lua_topointer(L,1);
|
||||
const char * sqlstr = lua_tostring(L,2);
|
||||
int stime = luaL_checknumber(L,3);
|
||||
|
||||
lua_newtable(L);
|
||||
int table_index = lua_gettop(L);
|
||||
|
||||
struct cb_param *p = malloc(sizeof(struct cb_param));
|
||||
p->state = L;
|
||||
p->callback=r;
|
||||
// printf("r:%d, L:%d\n",r,L);
|
||||
void * s = taos_open_stream(taos,sqlstr,stream_cb,stime,p,NULL);
|
||||
if (s == NULL) {
|
||||
printf("failed to open stream, reason:%s\n", taos_errstr(taos));
|
||||
free(p);
|
||||
lua_pushnumber(L, -1);
|
||||
lua_setfield(L, table_index, "code");
|
||||
lua_pushstring(L, taos_errstr(taos));
|
||||
lua_setfield(L, table_index, "error");
|
||||
lua_pushlightuserdata(L,NULL);
|
||||
lua_setfield(L, table_index, "stream");
|
||||
}else{
|
||||
// printf("success to open stream\n");
|
||||
lua_pushnumber(L, 0);
|
||||
lua_setfield(L, table_index, "code");
|
||||
lua_pushstring(L, taos_errstr(taos));
|
||||
lua_setfield(L, table_index, "error");
|
||||
p->stream = s;
|
||||
lua_pushlightuserdata(L,p);
|
||||
lua_setfield(L, table_index, "stream");//stream has different content in lua and c.
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_close_stream(lua_State *L){
|
||||
//TODO:get stream and free cb_param
|
||||
struct cb_param *p = lua_touserdata(L,1);
|
||||
taos_close_stream(p->stream);
|
||||
free(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_close(lua_State *L){
|
||||
TAOS *taos= (TAOS*)lua_topointer(L,1);
|
||||
|
@ -367,8 +265,6 @@ static const struct luaL_Reg lib[] = {
|
|||
{"query", l_query},
|
||||
{"query_a",l_async_query},
|
||||
{"close", l_close},
|
||||
{"open_stream", l_open_stream},
|
||||
{"close_stream", l_close_stream},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
|
|
@ -223,10 +223,10 @@ DLL_EXPORT tmq_list_t *tmq_list_new();
|
|||
DLL_EXPORT int32_t tmq_list_append(tmq_list_t *, const char *);
|
||||
DLL_EXPORT void tmq_list_destroy(tmq_list_t *);
|
||||
|
||||
// will be removed in 3.0
|
||||
#if 1
|
||||
DLL_EXPORT tmq_t *tmq_consumer_new(void *conn, tmq_conf_t *conf, char *errstr, int32_t errstrLen);
|
||||
#endif
|
||||
|
||||
// will replace last one
|
||||
DLL_EXPORT tmq_t *tmq_consumer_new1(tmq_conf_t *conf, char *errstr, int32_t errstrLen);
|
||||
|
||||
DLL_EXPORT const char *tmq_err2str(tmq_resp_err_t);
|
||||
|
|
|
@ -203,11 +203,10 @@ void colInfoDataCleanup(SColumnInfoData* pColumn, uint32_t numOfRows);
|
|||
void blockDataCleanup(SSDataBlock* pDataBlock);
|
||||
|
||||
size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize);
|
||||
void* blockDataDestroy(SSDataBlock* pBlock);
|
||||
|
||||
int32_t blockDataTrimFirstNRows(SSDataBlock* pBlock, size_t n);
|
||||
|
||||
SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock);
|
||||
SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData);
|
||||
|
||||
void blockDebugShowData(const SArray* dataBlocks);
|
||||
|
||||
|
|
|
@ -70,13 +70,11 @@ typedef uint16_t tmsg_t;
|
|||
#define TSDB_IE_TYPE_DNODE_EXT 6
|
||||
#define TSDB_IE_TYPE_DNODE_STATE 7
|
||||
|
||||
typedef enum {
|
||||
HEARTBEAT_TYPE_MQ = 0,
|
||||
HEARTBEAT_TYPE_QUERY,
|
||||
// types can be added here
|
||||
//
|
||||
HEARTBEAT_TYPE_MAX
|
||||
} EHbType;
|
||||
enum {
|
||||
CONN_TYPE__QUERY = 1,
|
||||
CONN_TYPE__TMQ,
|
||||
CONN_TYPE__MAX
|
||||
};
|
||||
|
||||
enum {
|
||||
HEARTBEAT_KEY_DBINFO = 1,
|
||||
|
@ -86,30 +84,31 @@ enum {
|
|||
|
||||
typedef enum _mgmt_table {
|
||||
TSDB_MGMT_TABLE_START,
|
||||
TSDB_MGMT_TABLE_ACCT,
|
||||
TSDB_MGMT_TABLE_USER,
|
||||
TSDB_MGMT_TABLE_DB,
|
||||
TSDB_MGMT_TABLE_TABLE,
|
||||
TSDB_MGMT_TABLE_DNODE,
|
||||
TSDB_MGMT_TABLE_MNODE,
|
||||
TSDB_MGMT_TABLE_MODULE,
|
||||
TSDB_MGMT_TABLE_QNODE,
|
||||
TSDB_MGMT_TABLE_SNODE,
|
||||
TSDB_MGMT_TABLE_BNODE,
|
||||
TSDB_MGMT_TABLE_VGROUP,
|
||||
TSDB_MGMT_TABLE_STB,
|
||||
TSDB_MGMT_TABLE_MODULE,
|
||||
TSDB_MGMT_TABLE_QUERIES,
|
||||
TSDB_MGMT_TABLE_STREAMS,
|
||||
TSDB_MGMT_TABLE_VARIABLES,
|
||||
TSDB_MGMT_TABLE_CONNS,
|
||||
TSDB_MGMT_TABLE_TRANS,
|
||||
TSDB_MGMT_TABLE_GRANTS,
|
||||
TSDB_MGMT_TABLE_VNODES,
|
||||
TSDB_MGMT_TABLE_CLUSTER,
|
||||
TSDB_MGMT_TABLE_STREAMTABLES,
|
||||
TSDB_MGMT_TABLE_TP,
|
||||
TSDB_MGMT_TABLE_DB,
|
||||
TSDB_MGMT_TABLE_FUNC,
|
||||
TSDB_MGMT_TABLE_INDEX,
|
||||
TSDB_MGMT_TABLE_STB,
|
||||
TSDB_MGMT_TABLE_STREAMS,
|
||||
TSDB_MGMT_TABLE_TABLE,
|
||||
TSDB_MGMT_TABLE_USER,
|
||||
TSDB_MGMT_TABLE_GRANTS,
|
||||
TSDB_MGMT_TABLE_VGROUP,
|
||||
TSDB_MGMT_TABLE_TOPICS,
|
||||
TSDB_MGMT_TABLE_CONSUMERS,
|
||||
TSDB_MGMT_TABLE_SUBSCRIBES,
|
||||
TSDB_MGMT_TABLE_TRANS,
|
||||
TSDB_MGMT_TABLE_SMAS,
|
||||
TSDB_MGMT_TABLE_CONFIGS,
|
||||
TSDB_MGMT_TABLE_CONNS,
|
||||
TSDB_MGMT_TABLE_QUERIES,
|
||||
TSDB_MGMT_TABLE_VNODES,
|
||||
TSDB_MGMT_TABLE_MAX,
|
||||
} EShowType;
|
||||
|
||||
|
@ -332,6 +331,7 @@ int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
|
|||
void* taosDecodeSEpSet(void* buf, SEpSet* pEp);
|
||||
|
||||
typedef struct {
|
||||
int8_t connType;
|
||||
int32_t pid;
|
||||
char app[TSDB_APP_NAME_LEN];
|
||||
char db[TSDB_DB_NAME_LEN];
|
||||
|
@ -342,12 +342,13 @@ int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
|
|||
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int32_t acctId;
|
||||
int64_t clusterId;
|
||||
int32_t acctId;
|
||||
int64_t clusterId;
|
||||
uint32_t connId;
|
||||
int8_t superUser;
|
||||
SEpSet epSet;
|
||||
char sVersion[128];
|
||||
int8_t superUser;
|
||||
int8_t connType;
|
||||
SEpSet epSet;
|
||||
char sVersion[128];
|
||||
} SConnectRsp;
|
||||
|
||||
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
|
||||
|
@ -361,7 +362,7 @@ typedef struct {
|
|||
int32_t maxTimeSeries;
|
||||
int32_t maxStreams;
|
||||
int32_t accessState; // Configured only by command
|
||||
int64_t maxStorage; // In unit of GB
|
||||
int64_t maxStorage;
|
||||
} SCreateAcctReq, SAlterAcctReq;
|
||||
|
||||
int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq);
|
||||
|
@ -745,8 +746,8 @@ typedef struct {
|
|||
} SVnodeLoad;
|
||||
|
||||
typedef struct {
|
||||
int32_t sver; // software version
|
||||
int64_t dver; // dnode table version in sdb
|
||||
int32_t sver; // software version
|
||||
int64_t dnodeVer; // dnode table version in sdb
|
||||
int32_t dnodeId;
|
||||
int64_t clusterId;
|
||||
int64_t rebootTime;
|
||||
|
@ -760,6 +761,7 @@ typedef struct {
|
|||
|
||||
int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
|
||||
int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq);
|
||||
void tFreeSStatusReq(SStatusReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
|
@ -773,7 +775,7 @@ typedef struct {
|
|||
} SDnodeEp;
|
||||
|
||||
typedef struct {
|
||||
int64_t dver;
|
||||
int64_t dnodeVer;
|
||||
SDnodeCfg dnodeCfg;
|
||||
SArray* pDnodeEps; // Array of SDnodeEp
|
||||
} SStatusRsp;
|
||||
|
@ -953,9 +955,14 @@ typedef struct {
|
|||
char db[TSDB_DB_FNAME_LEN];
|
||||
char tb[TSDB_TABLE_NAME_LEN];
|
||||
int64_t showId;
|
||||
int8_t free;
|
||||
} SRetrieveTableReq;
|
||||
|
||||
typedef struct SSysTableSchema {
|
||||
int8_t type;
|
||||
col_id_t colId;
|
||||
int32_t bytes;
|
||||
} SSysTableSchema;
|
||||
|
||||
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
|
||||
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
|
||||
|
||||
|
@ -1202,12 +1209,17 @@ typedef struct {
|
|||
int32_t code;
|
||||
} STaskDropRsp;
|
||||
|
||||
#define STREAM_TRIGGER_AT_ONCE 1
|
||||
#define STREAM_TRIGGER_WINDOW_CLOSE 2
|
||||
|
||||
typedef struct {
|
||||
char name[TSDB_TOPIC_FNAME_LEN];
|
||||
char outputSTbName[TSDB_TABLE_FNAME_LEN];
|
||||
int8_t igExists;
|
||||
char* sql;
|
||||
char* ast;
|
||||
int8_t triggerType;
|
||||
int64_t watermark;
|
||||
} SCMCreateStreamReq;
|
||||
|
||||
typedef struct {
|
||||
|
@ -1642,7 +1654,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
int64_t tscRid;
|
||||
int32_t hbType;
|
||||
int8_t connType;
|
||||
} SClientHbKey;
|
||||
|
||||
typedef struct {
|
||||
|
@ -1789,13 +1801,13 @@ static FORCE_INLINE int32_t tDecodeSKv(SCoder* pDecoder, SKv* pKv) {
|
|||
|
||||
static FORCE_INLINE int32_t tEncodeSClientHbKey(SCoder* pEncoder, const SClientHbKey* pKey) {
|
||||
if (tEncodeI64(pEncoder, pKey->tscRid) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, pKey->hbType) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pKey->connType) < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeSClientHbKey(SCoder* pDecoder, SClientHbKey* pKey) {
|
||||
if (tDecodeI64(pDecoder, &pKey->tscRid) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &pKey->hbType) < 0) return -1;
|
||||
if (tDecodeI8(pDecoder, &pKey->connType) < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1894,7 +1906,6 @@ typedef struct {
|
|||
char topicName[TSDB_TOPIC_FNAME_LEN];
|
||||
char cgroup[TSDB_CGROUP_LEN];
|
||||
char* sql;
|
||||
char* logicalPlan;
|
||||
char* physicalPlan;
|
||||
char* qmsg;
|
||||
} SMqSetCVgReq;
|
||||
|
@ -1908,7 +1919,6 @@ static FORCE_INLINE int32_t tEncodeSMqSetCVgReq(void** buf, const SMqSetCVgReq*
|
|||
tlen += taosEncodeString(buf, pReq->topicName);
|
||||
tlen += taosEncodeString(buf, pReq->cgroup);
|
||||
tlen += taosEncodeString(buf, pReq->sql);
|
||||
tlen += taosEncodeString(buf, pReq->logicalPlan);
|
||||
tlen += taosEncodeString(buf, pReq->physicalPlan);
|
||||
tlen += taosEncodeString(buf, pReq->qmsg);
|
||||
return tlen;
|
||||
|
@ -1922,7 +1932,6 @@ static FORCE_INLINE void* tDecodeSMqSetCVgReq(void* buf, SMqSetCVgReq* pReq) {
|
|||
buf = taosDecodeStringTo(buf, pReq->topicName);
|
||||
buf = taosDecodeStringTo(buf, pReq->cgroup);
|
||||
buf = taosDecodeString(buf, &pReq->sql);
|
||||
buf = taosDecodeString(buf, &pReq->logicalPlan);
|
||||
buf = taosDecodeString(buf, &pReq->physicalPlan);
|
||||
buf = taosDecodeString(buf, &pReq->qmsg);
|
||||
return buf;
|
||||
|
@ -2383,11 +2392,10 @@ typedef struct {
|
|||
} SMqSubVgEp;
|
||||
|
||||
typedef struct {
|
||||
char topic[TSDB_TOPIC_FNAME_LEN];
|
||||
int8_t isSchemaAdaptive;
|
||||
SArray* vgs; // SArray<SMqSubVgEp>
|
||||
int32_t numOfFields;
|
||||
TAOS_FIELD* fields;
|
||||
char topic[TSDB_TOPIC_FNAME_LEN];
|
||||
int8_t isSchemaAdaptive;
|
||||
SArray* vgs; // SArray<SMqSubVgEp>
|
||||
SSchemaWrapper schema;
|
||||
} SMqSubTopicEp;
|
||||
|
||||
typedef struct {
|
||||
|
@ -2486,8 +2494,7 @@ static FORCE_INLINE int32_t tEncodeSMqSubTopicEp(void** buf, const SMqSubTopicEp
|
|||
SMqSubVgEp* pVgEp = (SMqSubVgEp*)taosArrayGet(pTopicEp->vgs, i);
|
||||
tlen += tEncodeSMqSubVgEp(buf, pVgEp);
|
||||
}
|
||||
tlen += taosEncodeFixedI32(buf, pTopicEp->numOfFields);
|
||||
// tlen += taosEncodeBinary(buf, pTopicEp->fields, pTopicEp->numOfFields * sizeof(TAOS_FIELD));
|
||||
tlen += taosEncodeSSchemaWrapper(buf, &pTopicEp->schema);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
|
@ -2505,8 +2512,7 @@ static FORCE_INLINE void* tDecodeSMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicE
|
|||
buf = tDecodeSMqSubVgEp(buf, &vgEp);
|
||||
taosArrayPush(pTopicEp->vgs, &vgEp);
|
||||
}
|
||||
buf = taosDecodeFixedI32(buf, &pTopicEp->numOfFields);
|
||||
// buf = taosDecodeBinary(buf, (void**)&pTopicEp->fields, pTopicEp->numOfFields * sizeof(TAOS_FIELD));
|
||||
buf = taosDecodeSSchemaWrapper(buf, &pTopicEp->schema);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
|
|
@ -136,7 +136,6 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_MND_KILL_CONN, "mnode-kill-conn", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_HEARTBEAT, "mnode-heartbeat", SClientHbBatchReq, SClientHbBatchRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_SHOW, "mnode-show", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_SHOW_RETRIEVE, "mnode-retrieve", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_SYSTABLE_RETRIEVE, "mnode-systable-retrieve", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_STATUS, "mnode-status", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_TRANS_TIMER, "mnode-trans-tmr", NULL, NULL)
|
||||
|
@ -189,8 +188,8 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_VND_CREATE_TOPIC, "vnode-create-topic", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_ALTER_TOPIC, "vnode-alter-topic", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_DROP_TOPIC, "vnode-drop-topic", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_SHOW_TABLES, "vnode-show-tables", SVShowTablesReq, SVShowTablesRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_SHOW_TABLES_FETCH, "vnode-show-tables-fetch", SVShowTablesFetchReq, SVShowTablesFetchRsp)
|
||||
// TD_DEF_MSG_TYPE(TDMT_VND_SHOW_TABLES, "vnode-show-tables", SVShowTablesReq, SVShowTablesRsp)
|
||||
// TD_DEF_MSG_TYPE(TDMT_VND_SHOW_TABLES_FETCH, "vnode-show-tables-fetch", SVShowTablesFetchReq, SVShowTablesFetchRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_QUERY_CONTINUE, "vnode-query-continue", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_QUERY_HEARTBEAT, "vnode-query-heartbeat", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_EXPLAIN, "vnode-explain", NULL, NULL)
|
||||
|
|
|
@ -162,38 +162,39 @@ typedef struct {
|
|||
int32_t extendedRowSize;
|
||||
} SRowBuilder;
|
||||
|
||||
#define TD_ROW_HEAD_LEN (sizeof(STSRow))
|
||||
#define TD_ROW_HEAD_LEN (sizeof(STSRow))
|
||||
#define TD_ROW_NCOLS_LEN (sizeof(col_id_t))
|
||||
|
||||
#define TD_ROW_INFO(r) ((r)->info)
|
||||
#define TD_ROW_TYPE(r) ((r)->type)
|
||||
#define TD_ROW_DELETE(r) ((r)->del)
|
||||
#define TD_ROW_ENDIAN(r) ((r)->endian)
|
||||
#define TD_ROW_SVER(r) ((r)->sver)
|
||||
#define TD_ROW_NCOLS(r) ((r)->data) // only valid for SKvRow
|
||||
#define TD_ROW_DATA(r) ((r)->data)
|
||||
#define TD_ROW_LEN(r) ((r)->len)
|
||||
#define TD_ROW_KEY(r) ((r)->ts)
|
||||
#define TD_ROW_INFO(r) ((r)->info)
|
||||
#define TD_ROW_TYPE(r) ((r)->type)
|
||||
#define TD_ROW_DELETE(r) ((r)->del)
|
||||
#define TD_ROW_ENDIAN(r) ((r)->endian)
|
||||
#define TD_ROW_SVER(r) ((r)->sver)
|
||||
#define TD_ROW_NCOLS(r) ((r)->data) // only valid for SKvRow
|
||||
#define TD_ROW_DATA(r) ((r)->data)
|
||||
#define TD_ROW_LEN(r) ((r)->len)
|
||||
#define TD_ROW_KEY(r) ((r)->ts)
|
||||
#define TD_ROW_VER(r) ((r)->ver)
|
||||
#define TD_ROW_KEY_ADDR(r) (r)
|
||||
|
||||
// N.B. If without STSchema, getExtendedRowSize() is used to get the rowMaxBytes and
|
||||
// (int32_t)ceil((double)nCols/TD_VTYPE_PARTS) should be added if TD_SUPPORT_BITMAP defined.
|
||||
#define TD_ROW_MAX_BYTES_FROM_SCHEMA(s) (schemaTLen(s) + TD_ROW_HEAD_LEN)
|
||||
|
||||
#define TD_ROW_SET_INFO(r, i) (TD_ROW_INFO(r) = (i))
|
||||
#define TD_ROW_SET_TYPE(r, t) (TD_ROW_TYPE(r) = (t))
|
||||
#define TD_ROW_SET_DELETE(r) (TD_ROW_DELETE(r) = 1)
|
||||
#define TD_ROW_SET_SVER(r, v) (TD_ROW_SVER(r) = (v))
|
||||
#define TD_ROW_SET_LEN(r, l) (TD_ROW_LEN(r) = (l))
|
||||
#define TD_ROW_SET_INFO(r, i) (TD_ROW_INFO(r) = (i))
|
||||
#define TD_ROW_SET_TYPE(r, t) (TD_ROW_TYPE(r) = (t))
|
||||
#define TD_ROW_SET_DELETE(r) (TD_ROW_DELETE(r) = 1)
|
||||
#define TD_ROW_SET_SVER(r, v) (TD_ROW_SVER(r) = (v))
|
||||
#define TD_ROW_SET_LEN(r, l) (TD_ROW_LEN(r) = (l))
|
||||
#define TD_ROW_SET_NCOLS(r, n) (*(col_id_t *)TD_ROW_NCOLS(r) = (n))
|
||||
|
||||
#define TD_ROW_IS_DELETED(r) (TD_ROW_DELETE(r) == 1)
|
||||
#define TD_IS_TP_ROW(r) (TD_ROW_TYPE(r) == TD_ROW_TP)
|
||||
#define TD_IS_KV_ROW(r) (TD_ROW_TYPE(r) == TD_ROW_KV)
|
||||
#define TD_IS_TP_ROW_T(t) ((t) == TD_ROW_TP)
|
||||
#define TD_IS_KV_ROW_T(t) ((t) == TD_ROW_KV)
|
||||
#define TD_IS_TP_ROW(r) (TD_ROW_TYPE(r) == TD_ROW_TP)
|
||||
#define TD_IS_KV_ROW(r) (TD_ROW_TYPE(r) == TD_ROW_KV)
|
||||
#define TD_IS_TP_ROW_T(t) ((t) == TD_ROW_TP)
|
||||
#define TD_IS_KV_ROW_T(t) ((t) == TD_ROW_KV)
|
||||
|
||||
#define TD_BOOL_STR(b) ((b) ? "true" : "false")
|
||||
#define TD_BOOL_STR(b) ((b) ? "true" : "false")
|
||||
#define isUtilizeKVRow(k, d) ((k) < ((d)*KVRatioConvert))
|
||||
|
||||
#define TD_ROW_COL_IDX(r) POINTER_SHIFT(TD_ROW_DATA(r), sizeof(col_id_t))
|
||||
|
@ -221,8 +222,10 @@ static FORCE_INLINE int32_t tdSetBitmapValTypeI(void *pBitmap, int16_t colIdx, T
|
|||
static FORCE_INLINE int32_t tdSetBitmapValTypeII(void *pBitmap, int16_t colIdx, TDRowValT valType);
|
||||
static FORCE_INLINE int32_t tdSetBitmapValType(void *pBitmap, int16_t colIdx, TDRowValT valType, int8_t bitmapMode);
|
||||
int32_t tdSetBitmapValTypeN(void *pBitmap, int16_t nEle, TDRowValT valType, int8_t bitmapMode);
|
||||
static FORCE_INLINE int32_t tdGetBitmapValTypeI(void *pBitmap, int16_t colIdx, TDRowValT *pValType);
|
||||
static FORCE_INLINE int32_t tdGetBitmapValTypeII(void *pBitmap, int16_t colIdx, TDRowValT *pValType);
|
||||
static FORCE_INLINE int32_t tdGetBitmapValTypeI(const void *pBitmap, int16_t colIdx, TDRowValT *pValType);
|
||||
static FORCE_INLINE int32_t tdGetBitmapValTypeII(const void *pBitmap, int16_t colIdx, TDRowValT *pValType);
|
||||
static FORCE_INLINE int32_t tdGetBitmapValType(const void *pBitmap, int16_t colIdx, TDRowValT *pValType, int8_t bitmapMode);
|
||||
static FORCE_INLINE bool tdIsBitmapValTypeNormII(const void *pBitmap, int16_t idx);
|
||||
int32_t tdAppendValToDataCol(SDataCol *pCol, TDRowValT valType, const void *val, int32_t numOfRows, int32_t maxPoints,
|
||||
int8_t bitmapMode);
|
||||
static FORCE_INLINE int32_t tdAppendColValToTpRow(SRowBuilder *pBuilder, TDRowValT valType, const void *val,
|
||||
|
@ -324,7 +327,16 @@ static FORCE_INLINE int32_t tdSetBitmapValTypeII(void *pBitmap, int16_t colIdx,
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tdGetBitmapValType(void *pBitmap, int16_t colIdx, TDRowValT *pValType, int8_t bitmapMode) {
|
||||
static FORCE_INLINE bool tdIsBitmapValTypeNormII(const void *pBitmap, int16_t idx) {
|
||||
TDRowValT valType = 0;
|
||||
tdGetBitmapValTypeII(pBitmap, idx, &valType);
|
||||
if (tdValTypeIsNorm(valType)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -349,7 +361,7 @@ static FORCE_INLINE int32_t tdGetBitmapValType(void *pBitmap, int16_t colIdx, TD
|
|||
* @param pValType
|
||||
* @return FORCE_INLINE
|
||||
*/
|
||||
static FORCE_INLINE int32_t tdGetBitmapValTypeII(void *pBitmap, int16_t colIdx, TDRowValT *pValType) {
|
||||
static FORCE_INLINE int32_t tdGetBitmapValTypeII(const void *pBitmap, int16_t colIdx, TDRowValT *pValType) {
|
||||
if (!pBitmap || colIdx < 0) {
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
|
@ -448,7 +460,7 @@ static FORCE_INLINE int32_t tdSetBitmapValTypeI(void *pBitmap, int16_t colIdx, T
|
|||
* @param pValType
|
||||
* @return FORCE_INLINE
|
||||
*/
|
||||
static FORCE_INLINE int32_t tdGetBitmapValTypeI(void *pBitmap, int16_t colIdx, TDRowValT *pValType) {
|
||||
static FORCE_INLINE int32_t tdGetBitmapValTypeI(const void *pBitmap, int16_t colIdx, TDRowValT *pValType) {
|
||||
if (!pBitmap || colIdx < 0) {
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
|
|
|
@ -40,6 +40,7 @@ extern "C" {
|
|||
* @return timestamp decided by global conf variable, tsTimePrecision
|
||||
* if precision == TSDB_TIME_PRECISION_MICRO, it returns timestamp in microsecond.
|
||||
* precision == TSDB_TIME_PRECISION_MILLI, it returns timestamp in millisecond.
|
||||
* precision == TSDB_TIME_PRECISION_NANO, it returns timestamp in nanosecond.
|
||||
*/
|
||||
static FORCE_INLINE int64_t taosGetTimestamp(int32_t precision) {
|
||||
if (precision == TSDB_TIME_PRECISION_MICRO) {
|
||||
|
@ -51,6 +52,24 @@ static FORCE_INLINE int64_t taosGetTimestamp(int32_t precision) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @return timestamp of today at 00:00:00 in given precision
|
||||
* if precision == TSDB_TIME_PRECISION_MICRO, it returns timestamp in microsecond.
|
||||
* precision == TSDB_TIME_PRECISION_MILLI, it returns timestamp in millisecond.
|
||||
* precision == TSDB_TIME_PRECISION_NANO, it returns timestamp in nanosecond.
|
||||
*/
|
||||
static FORCE_INLINE int64_t taosGetTimestampToday(int32_t precision) {
|
||||
int64_t factor = (precision == TSDB_TIME_PRECISION_MILLI) ? 1000 :
|
||||
(precision == TSDB_TIME_PRECISION_MICRO) ? 1000000 : 1000000000;
|
||||
time_t t = taosTime(NULL);
|
||||
struct tm * tm= taosLocalTime(&t, NULL);
|
||||
tm->tm_hour = 0;
|
||||
tm->tm_min = 0;
|
||||
tm->tm_sec = 0;
|
||||
|
||||
return (int64_t)taosMktime(tm) * factor;
|
||||
}
|
||||
|
||||
int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision);
|
||||
int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precision);
|
||||
int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char unit, int32_t precision);
|
||||
|
|
|
@ -171,58 +171,70 @@
|
|||
#define TK_BUFSIZE 153
|
||||
#define TK_STREAM 154
|
||||
#define TK_INTO 155
|
||||
#define TK_KILL 156
|
||||
#define TK_CONNECTION 157
|
||||
#define TK_MERGE 158
|
||||
#define TK_VGROUP 159
|
||||
#define TK_REDISTRIBUTE 160
|
||||
#define TK_SPLIT 161
|
||||
#define TK_SYNCDB 162
|
||||
#define TK_NULL 163
|
||||
#define TK_FIRST 164
|
||||
#define TK_LAST 165
|
||||
#define TK_NOW 166
|
||||
#define TK_ROWTS 167
|
||||
#define TK_TBNAME 168
|
||||
#define TK_QSTARTTS 169
|
||||
#define TK_QENDTS 170
|
||||
#define TK_WSTARTTS 171
|
||||
#define TK_WENDTS 172
|
||||
#define TK_WDURATION 173
|
||||
#define TK_BETWEEN 174
|
||||
#define TK_IS 175
|
||||
#define TK_NK_LT 176
|
||||
#define TK_NK_GT 177
|
||||
#define TK_NK_LE 178
|
||||
#define TK_NK_GE 179
|
||||
#define TK_NK_NE 180
|
||||
#define TK_MATCH 181
|
||||
#define TK_NMATCH 182
|
||||
#define TK_JOIN 183
|
||||
#define TK_INNER 184
|
||||
#define TK_SELECT 185
|
||||
#define TK_DISTINCT 186
|
||||
#define TK_WHERE 187
|
||||
#define TK_PARTITION 188
|
||||
#define TK_BY 189
|
||||
#define TK_SESSION 190
|
||||
#define TK_STATE_WINDOW 191
|
||||
#define TK_SLIDING 192
|
||||
#define TK_FILL 193
|
||||
#define TK_VALUE 194
|
||||
#define TK_NONE 195
|
||||
#define TK_PREV 196
|
||||
#define TK_LINEAR 197
|
||||
#define TK_NEXT 198
|
||||
#define TK_GROUP 199
|
||||
#define TK_HAVING 200
|
||||
#define TK_ORDER 201
|
||||
#define TK_SLIMIT 202
|
||||
#define TK_SOFFSET 203
|
||||
#define TK_LIMIT 204
|
||||
#define TK_OFFSET 205
|
||||
#define TK_ASC 206
|
||||
#define TK_NULLS 207
|
||||
#define TK_TRIGGER 156
|
||||
#define TK_AT_ONCE 157
|
||||
#define TK_WINDOW_CLOSE 158
|
||||
#define TK_WATERMARK 159
|
||||
#define TK_KILL 160
|
||||
#define TK_CONNECTION 161
|
||||
#define TK_MERGE 162
|
||||
#define TK_VGROUP 163
|
||||
#define TK_REDISTRIBUTE 164
|
||||
#define TK_SPLIT 165
|
||||
#define TK_SYNCDB 166
|
||||
#define TK_NULL 167
|
||||
#define TK_NK_QUESTION 168
|
||||
#define TK_NK_ARROW 169
|
||||
#define TK_ROWTS 170
|
||||
#define TK_TBNAME 171
|
||||
#define TK_QSTARTTS 172
|
||||
#define TK_QENDTS 173
|
||||
#define TK_WSTARTTS 174
|
||||
#define TK_WENDTS 175
|
||||
#define TK_WDURATION 176
|
||||
#define TK_CAST 177
|
||||
#define TK_NOW 178
|
||||
#define TK_TODAY 179
|
||||
#define TK_TIMEZONE 180
|
||||
#define TK_COUNT 181
|
||||
#define TK_FIRST 182
|
||||
#define TK_LAST 183
|
||||
#define TK_LAST_ROW 184
|
||||
#define TK_BETWEEN 185
|
||||
#define TK_IS 186
|
||||
#define TK_NK_LT 187
|
||||
#define TK_NK_GT 188
|
||||
#define TK_NK_LE 189
|
||||
#define TK_NK_GE 190
|
||||
#define TK_NK_NE 191
|
||||
#define TK_MATCH 192
|
||||
#define TK_NMATCH 193
|
||||
#define TK_CONTAINS 194
|
||||
#define TK_JOIN 195
|
||||
#define TK_INNER 196
|
||||
#define TK_SELECT 197
|
||||
#define TK_DISTINCT 198
|
||||
#define TK_WHERE 199
|
||||
#define TK_PARTITION 200
|
||||
#define TK_BY 201
|
||||
#define TK_SESSION 202
|
||||
#define TK_STATE_WINDOW 203
|
||||
#define TK_SLIDING 204
|
||||
#define TK_FILL 205
|
||||
#define TK_VALUE 206
|
||||
#define TK_NONE 207
|
||||
#define TK_PREV 208
|
||||
#define TK_LINEAR 209
|
||||
#define TK_NEXT 210
|
||||
#define TK_GROUP 211
|
||||
#define TK_HAVING 212
|
||||
#define TK_ORDER 213
|
||||
#define TK_SLIMIT 214
|
||||
#define TK_SOFFSET 215
|
||||
#define TK_LIMIT 216
|
||||
#define TK_OFFSET 217
|
||||
#define TK_ASC 218
|
||||
#define TK_NULLS 219
|
||||
|
||||
#define TK_NK_SPACE 300
|
||||
#define TK_NK_COMMENT 301
|
||||
|
@ -231,7 +243,6 @@
|
|||
#define TK_NK_OCT 304 // oct number
|
||||
#define TK_NK_BIN 305 // bin format data 0b111
|
||||
#define TK_NK_FILE 306
|
||||
#define TK_NK_QUESTION 307 // denoting the placeholder of "?",when invoking statement bind query
|
||||
|
||||
#define TK_NK_BITNOT 501
|
||||
#define TK_INSERT 502
|
||||
|
|
|
@ -24,7 +24,6 @@ extern "C" {
|
|||
#include "types.h"
|
||||
|
||||
// ----------------- For variable data types such as TSDB_DATA_TYPE_BINARY and TSDB_DATA_TYPE_NCHAR
|
||||
typedef int32_t VarDataOffsetT;
|
||||
typedef uint32_t TDRowLenT;
|
||||
typedef uint8_t TDRowValT;
|
||||
typedef uint64_t TDRowVerT;
|
||||
|
@ -182,6 +181,7 @@ typedef struct {
|
|||
#define IS_SIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_TINYINT && (_t) <= TSDB_DATA_TYPE_BIGINT)
|
||||
#define IS_UNSIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_UTINYINT && (_t) <= TSDB_DATA_TYPE_UBIGINT)
|
||||
#define IS_FLOAT_TYPE(_t) ((_t) == TSDB_DATA_TYPE_FLOAT || (_t) == TSDB_DATA_TYPE_DOUBLE)
|
||||
#define IS_INTEGER_TYPE(_t) ((IS_SIGNED_NUMERIC_TYPE(_t)) || (IS_UNSIGNED_NUMERIC_TYPE(_t)))
|
||||
|
||||
#define IS_NUMERIC_TYPE(_t) ((IS_SIGNED_NUMERIC_TYPE(_t)) || (IS_UNSIGNED_NUMERIC_TYPE(_t)) || (IS_FLOAT_TYPE(_t)))
|
||||
#define IS_MATHABLE_TYPE(_t) (IS_NUMERIC_TYPE(_t) || (_t) == (TSDB_DATA_TYPE_BOOL) || (_t) == (TSDB_DATA_TYPE_TIMESTAMP))
|
||||
|
@ -248,7 +248,7 @@ typedef struct tDataTypeDescriptor {
|
|||
int32_t outputSize, char algorithm, char *const buffer, int32_t bufferSize);
|
||||
int32_t (*decompFunc)(const char *const input, int32_t compressedSize, const int32_t nelements, char *const output,
|
||||
int32_t outputSize, char algorithm, char *const buffer, int32_t bufferSize);
|
||||
void (*statisFunc)(const void *pData, int32_t numofrow, int64_t *min, int64_t *max, int64_t *sum, int16_t *minindex,
|
||||
void (*statisFunc)(const void* pBitmap, const void *pData, int32_t numofrow, int64_t *min, int64_t *max, int64_t *sum, int16_t *minindex,
|
||||
int16_t *maxindex, int16_t *numofnull);
|
||||
} tDataTypeDescriptor;
|
||||
|
||||
|
|
|
@ -30,12 +30,12 @@ typedef struct SDnode SDnode;
|
|||
*
|
||||
* @return int32_t 0 for success and -1 for failure
|
||||
*/
|
||||
int32_t dndInit();
|
||||
int32_t dmInit();
|
||||
|
||||
/**
|
||||
* @brief Clear the environment
|
||||
*/
|
||||
void dndCleanup();
|
||||
void dmCleanup();
|
||||
|
||||
/* ------------------------ SDnode ----------------------- */
|
||||
typedef struct {
|
||||
|
@ -51,7 +51,7 @@ typedef struct {
|
|||
int8_t ntype;
|
||||
} SDnodeOpt;
|
||||
|
||||
typedef enum { DND_EVENT_START, DND_EVENT_STOP = 1, DND_EVENT_CHILD } EDndEvent;
|
||||
typedef enum { DND_EVENT_START = 0, DND_EVENT_STOP = 1, DND_EVENT_CHILD = 2 } EDndEvent;
|
||||
|
||||
/**
|
||||
* @brief Initialize and start the dnode.
|
||||
|
@ -59,21 +59,21 @@ typedef enum { DND_EVENT_START, DND_EVENT_STOP = 1, DND_EVENT_CHILD } EDndEvent;
|
|||
* @param pOption Option of the dnode.
|
||||
* @return SDnode* The dnode object.
|
||||
*/
|
||||
SDnode *dndCreate(const SDnodeOpt *pOption);
|
||||
SDnode *dmCreate(const SDnodeOpt *pOption);
|
||||
|
||||
/**
|
||||
* @brief Stop and cleanup the dnode.
|
||||
*
|
||||
* @param pDnode The dnode object to close.
|
||||
*/
|
||||
void dndClose(SDnode *pDnode);
|
||||
void dmClose(SDnode *pDnode);
|
||||
|
||||
/**
|
||||
* @brief Run dnode until specific event is receive.
|
||||
*
|
||||
* @param pDnode The dnode object to run.
|
||||
*/
|
||||
int32_t dndRun(SDnode *pDnode);
|
||||
int32_t dmRun(SDnode *pDnode);
|
||||
|
||||
/**
|
||||
* @brief Handle event in the dnode.
|
||||
|
@ -81,7 +81,7 @@ int32_t dndRun(SDnode *pDnode);
|
|||
* @param pDnode The dnode object to close.
|
||||
* @param event The event to handle.
|
||||
*/
|
||||
void dndHandleEvent(SDnode *pDnode, EDndEvent event);
|
||||
void dmSetEvent(SDnode *pDnode, EDndEvent event);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -68,31 +68,18 @@ int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption);
|
|||
* @param pMnode The mnode object.
|
||||
*/
|
||||
int32_t mndStart(SMnode *pMnode);
|
||||
void mndStop(SMnode *pMnode);
|
||||
|
||||
/**
|
||||
* @brief Get mnode monitor info.
|
||||
*
|
||||
* @param pMnode The mnode object.
|
||||
* @param pClusterInfo
|
||||
* @param pVgroupInfo
|
||||
* @param pGrantInfo
|
||||
* @param pCluster
|
||||
* @param pVgroup
|
||||
* @param pGrant
|
||||
* @return int32_t 0 for success, -1 for failure.
|
||||
*/
|
||||
int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgroupInfo *pVgroupInfo,
|
||||
SMonGrantInfo *pGrantInfo);
|
||||
|
||||
/**
|
||||
* @brief Get user authentication info.
|
||||
*
|
||||
* @param pMnode The mnode object.
|
||||
* @param user
|
||||
* @param spi
|
||||
* @param encrypt
|
||||
* @param secret
|
||||
* @param ckey
|
||||
* @return int32_t 0 for success, -1 for failure.
|
||||
*/
|
||||
int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey);
|
||||
int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pCluster, SMonVgroupInfo *pVgroup, SMonGrantInfo *pGrant);
|
||||
|
||||
/**
|
||||
* @brief Process the read, write, sync request.
|
||||
|
@ -102,6 +89,11 @@ int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, cha
|
|||
*/
|
||||
int32_t mndProcessMsg(SNodeMsg *pMsg);
|
||||
|
||||
/**
|
||||
* @brief Generate machine code
|
||||
*/
|
||||
void mndGenerateMachineCode();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -110,7 +110,6 @@ typedef struct SFileBlockInfo {
|
|||
#define FUNCTION_COV 38
|
||||
|
||||
typedef struct SResultRowEntryInfo {
|
||||
// int8_t hasResult:6; // result generated, not NULL value
|
||||
bool initialized:1; // output buffer has been initialized
|
||||
bool complete:1; // query has completed
|
||||
uint8_t isNullRes:6; // the result is null
|
||||
|
@ -119,10 +118,10 @@ typedef struct SResultRowEntryInfo {
|
|||
|
||||
// determine the real data need to calculated the result
|
||||
enum {
|
||||
BLK_DATA_NO_NEEDED = 0x0,
|
||||
BLK_DATA_STATIS_NEEDED = 0x1,
|
||||
BLK_DATA_ALL_NEEDED = 0x3,
|
||||
BLK_DATA_DISCARD = 0x4, // discard current data block since it is not qualified for filter
|
||||
BLK_DATA_NOT_LOAD = 0x0,
|
||||
BLK_DATA_SMA_LOAD = 0x1,
|
||||
BLK_DATA_DATA_LOAD = 0x3,
|
||||
BLK_DATA_FILTEROUT = 0x4, // discard current data block since it is not qualified for filter
|
||||
};
|
||||
|
||||
enum {
|
||||
|
|
|
@ -123,7 +123,7 @@ void fmFuncMgtDestroy();
|
|||
|
||||
int32_t fmGetFuncInfo(const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType);
|
||||
|
||||
int32_t fmGetFuncResultType(SFunctionNode* pFunc);
|
||||
int32_t fmGetFuncResultType(SFunctionNode* pFunc, char* pErrBuf, int32_t len);
|
||||
|
||||
bool fmIsAggFunc(int32_t funcId);
|
||||
bool fmIsScalarFunc(int32_t funcId);
|
||||
|
@ -137,12 +137,13 @@ bool fmIsWindowPseudoColumnFunc(int32_t funcId);
|
|||
bool fmIsWindowClauseFunc(int32_t funcId);
|
||||
bool fmIsSpecialDataRequiredFunc(int32_t funcId);
|
||||
bool fmIsDynamicScanOptimizedFunc(int32_t funcId);
|
||||
bool fmIsMultiResFunc(int32_t funcId);
|
||||
|
||||
typedef enum EFuncDataRequired {
|
||||
FUNC_DATA_REQUIRED_ALL_NEEDED = 1,
|
||||
FUNC_DATA_REQUIRED_STATIS_NEEDED,
|
||||
FUNC_DATA_REQUIRED_NO_NEEDED,
|
||||
FUNC_DATA_REQUIRED_DISCARD
|
||||
FUNC_DATA_REQUIRED_DATA_LOAD = 1,
|
||||
FUNC_DATA_REQUIRED_STATIS_LOAD,
|
||||
FUNC_DATA_REQUIRED_NOT_LOAD,
|
||||
FUNC_DATA_REQUIRED_FILTEROUT,
|
||||
} EFuncDataRequired;
|
||||
|
||||
EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow);
|
||||
|
|
|
@ -267,6 +267,33 @@ typedef struct SDescribeStmt {
|
|||
STableMeta* pMeta;
|
||||
} SDescribeStmt;
|
||||
|
||||
typedef struct SKillStmt {
|
||||
ENodeType type;
|
||||
int32_t targetId;
|
||||
} SKillStmt;
|
||||
|
||||
typedef struct SStreamOptions {
|
||||
ENodeType type;
|
||||
int8_t triggerType;
|
||||
SNode* pWatermark;
|
||||
} SStreamOptions;
|
||||
|
||||
typedef struct SCreateStreamStmt {
|
||||
ENodeType type;
|
||||
char streamName[TSDB_TABLE_NAME_LEN];
|
||||
char targetDbName[TSDB_DB_NAME_LEN];
|
||||
char targetTabName[TSDB_TABLE_NAME_LEN];
|
||||
bool ignoreExists;
|
||||
SStreamOptions* pOptions;
|
||||
SNode* pQuery;
|
||||
} SCreateStreamStmt;
|
||||
|
||||
typedef struct SDropStreamStmt {
|
||||
ENodeType type;
|
||||
char streamName[TSDB_TABLE_NAME_LEN];
|
||||
bool ignoreNotExists;
|
||||
} SDropStreamStmt;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -52,7 +52,8 @@ extern "C" {
|
|||
for (SListCell* cell = (NULL != (list) ? (list)->pHead : NULL); (NULL != cell ? (node = &(cell->pNode), true) : (node = NULL, false)); cell = cell->pNext)
|
||||
|
||||
typedef enum ENodeType {
|
||||
// Syntax nodes are used in parser and planner module, and some are also used in executor module, such as COLUMN, VALUE, OPERATOR, FUNCTION and so on.
|
||||
// Syntax nodes are used in parser and planner module, and some are also used in executor module, such as COLUMN,
|
||||
// VALUE, OPERATOR, FUNCTION and so on.
|
||||
QUERY_NODE_COLUMN = 1,
|
||||
QUERY_NODE_VALUE,
|
||||
QUERY_NODE_OPERATOR,
|
||||
|
@ -69,7 +70,7 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_INTERVAL_WINDOW,
|
||||
QUERY_NODE_NODE_LIST,
|
||||
QUERY_NODE_FILL,
|
||||
QUERY_NODE_RAW_EXPR, // Only be used in parser module.
|
||||
QUERY_NODE_RAW_EXPR, // Only be used in parser module.
|
||||
QUERY_NODE_TARGET,
|
||||
QUERY_NODE_DATABLOCK_DESC,
|
||||
QUERY_NODE_SLOT_DESC,
|
||||
|
@ -79,6 +80,7 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_TABLE_OPTIONS,
|
||||
QUERY_NODE_INDEX_OPTIONS,
|
||||
QUERY_NODE_EXPLAIN_OPTIONS,
|
||||
QUERY_NODE_STREAM_OPTIONS,
|
||||
|
||||
// Statement nodes are used in parser and planner module.
|
||||
QUERY_NODE_SET_OPERATOR,
|
||||
|
@ -126,30 +128,36 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_REDISTRIBUTE_VGROUP_STMT,
|
||||
QUERY_NODE_SPLIT_VGROUP_STMT,
|
||||
QUERY_NODE_SYNCDB_STMT,
|
||||
QUERY_NODE_SHOW_DATABASES_STMT,
|
||||
QUERY_NODE_SHOW_TABLES_STMT,
|
||||
QUERY_NODE_SHOW_STABLES_STMT,
|
||||
QUERY_NODE_SHOW_USERS_STMT,
|
||||
QUERY_NODE_SHOW_DNODES_STMT,
|
||||
QUERY_NODE_SHOW_VGROUPS_STMT,
|
||||
QUERY_NODE_SHOW_MNODES_STMT,
|
||||
QUERY_NODE_SHOW_MODULES_STMT,
|
||||
QUERY_NODE_SHOW_QNODES_STMT,
|
||||
QUERY_NODE_SHOW_SNODES_STMT,
|
||||
QUERY_NODE_SHOW_BNODES_STMT,
|
||||
QUERY_NODE_SHOW_DATABASES_STMT,
|
||||
QUERY_NODE_SHOW_FUNCTIONS_STMT,
|
||||
QUERY_NODE_SHOW_INDEXES_STMT,
|
||||
QUERY_NODE_SHOW_STABLES_STMT,
|
||||
QUERY_NODE_SHOW_STREAMS_STMT,
|
||||
QUERY_NODE_SHOW_APPS_STMT,
|
||||
QUERY_NODE_SHOW_CONNECTIONS_STMT,
|
||||
QUERY_NODE_SHOW_TABLES_STMT,
|
||||
QUERY_NODE_SHOW_USERS_STMT,
|
||||
QUERY_NODE_SHOW_LICENCE_STMT,
|
||||
QUERY_NODE_SHOW_VGROUPS_STMT,
|
||||
QUERY_NODE_SHOW_TOPICS_STMT,
|
||||
QUERY_NODE_SHOW_CONSUMERS_STMT,
|
||||
QUERY_NODE_SHOW_SUBSCRIBES_STMT,
|
||||
QUERY_NODE_SHOW_TRANS_STMT,
|
||||
QUERY_NODE_SHOW_SMAS_STMT,
|
||||
QUERY_NODE_SHOW_CONFIGS_STMT,
|
||||
QUERY_NODE_SHOW_CONNECTIONS_STMT,
|
||||
QUERY_NODE_SHOW_QUERIES_STMT,
|
||||
QUERY_NODE_SHOW_VNODES_STMT,
|
||||
QUERY_NODE_SHOW_APPS_STMT,
|
||||
QUERY_NODE_SHOW_SCORES_STMT,
|
||||
QUERY_NODE_SHOW_VARIABLE_STMT,
|
||||
QUERY_NODE_SHOW_CREATE_DATABASE_STMT,
|
||||
QUERY_NODE_SHOW_CREATE_TABLE_STMT,
|
||||
QUERY_NODE_SHOW_CREATE_STABLE_STMT,
|
||||
QUERY_NODE_SHOW_QUERIES_STMT,
|
||||
QUERY_NODE_SHOW_SCORES_STMT,
|
||||
QUERY_NODE_SHOW_TOPICS_STMT,
|
||||
QUERY_NODE_SHOW_VARIABLE_STMT,
|
||||
QUERY_NODE_SHOW_BNODES_STMT,
|
||||
QUERY_NODE_SHOW_SNODES_STMT,
|
||||
QUERY_NODE_SHOW_CREATE_STABLE_STMT,
|
||||
QUERY_NODE_KILL_CONNECTION_STMT,
|
||||
QUERY_NODE_KILL_QUERY_STMT,
|
||||
|
||||
|
@ -231,6 +239,7 @@ typedef enum EDealRes {
|
|||
DEAL_RES_CONTINUE = 1,
|
||||
DEAL_RES_IGNORE_CHILD,
|
||||
DEAL_RES_ERROR,
|
||||
DEAL_RES_END
|
||||
} EDealRes;
|
||||
|
||||
typedef EDealRes (*FNodeWalker)(SNode* pNode, void* pContext);
|
||||
|
|
|
@ -53,6 +53,11 @@ typedef struct SScanLogicNode {
|
|||
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 {
|
||||
|
@ -109,6 +114,8 @@ typedef struct SWindowLogicNode {
|
|||
int64_t sessionGap;
|
||||
SNode* pTspk;
|
||||
SNode* pStateExpr;
|
||||
int8_t triggerType;
|
||||
int64_t watermark;
|
||||
} SWindowLogicNode;
|
||||
|
||||
typedef struct SSortLogicNode {
|
||||
|
@ -206,6 +213,11 @@ typedef struct STableScanPhysiNode {
|
|||
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;
|
||||
|
@ -251,6 +263,8 @@ typedef struct SWinodwPhysiNode {
|
|||
SNodeList* pExprs; // these are expression list of parameter expression of function
|
||||
SNodeList* pFuncs;
|
||||
SNode* pTspk; // timestamp primary key
|
||||
int8_t triggerType;
|
||||
int64_t watermark;
|
||||
} SWinodwPhysiNode;
|
||||
|
||||
typedef struct SIntervalPhysiNode {
|
||||
|
@ -260,7 +274,6 @@ typedef struct SIntervalPhysiNode {
|
|||
int64_t sliding;
|
||||
int8_t intervalUnit;
|
||||
int8_t slidingUnit;
|
||||
uint8_t precision;
|
||||
SFillNode* pFill;
|
||||
} SIntervalPhysiNode;
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ typedef enum 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];
|
||||
|
@ -196,8 +197,8 @@ typedef struct SStateWindowNode {
|
|||
|
||||
typedef struct SSessionWindowNode {
|
||||
ENodeType type; // QUERY_NODE_SESSION_WINDOW
|
||||
SNode* pCol; // timestamp primary key
|
||||
SNode* pGap; // gap between two session window(in microseconds)
|
||||
SColumnNode* pCol; // timestamp primary key
|
||||
SValueNode* pGap; // gap between two session window(in microseconds)
|
||||
} SSessionWindowNode;
|
||||
|
||||
typedef struct SIntervalWindowNode {
|
||||
|
|
|
@ -67,6 +67,7 @@ typedef struct SQuery {
|
|||
SNode* pRoot;
|
||||
int32_t numOfResCols;
|
||||
SSchema* pResSchema;
|
||||
int8_t precision;
|
||||
SCmdMsgInfo* pCmdMsg;
|
||||
int32_t msgType;
|
||||
SArray* pDbList;
|
||||
|
|
|
@ -30,6 +30,8 @@ typedef struct SPlanContext {
|
|||
bool topicQuery;
|
||||
bool streamQuery;
|
||||
bool showRewrite;
|
||||
int8_t triggerType;
|
||||
int64_t watermark;
|
||||
} SPlanContext;
|
||||
|
||||
// Create the physical plan for the query, according to the AST.
|
||||
|
|
|
@ -78,6 +78,9 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *
|
|||
int32_t toUnixtimestampFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
int32_t nowFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
int32_t todayFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
int32_t timezoneFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
|
||||
bool getTimePseudoFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
|
||||
|
|
|
@ -61,16 +61,16 @@ extern "C" {
|
|||
} \
|
||||
}
|
||||
|
||||
#define WAL_HEAD_VER 0
|
||||
#define WAL_HEAD_VER 0
|
||||
#define WAL_NOSUFFIX_LEN 20
|
||||
#define WAL_SUFFIX_AT (WAL_NOSUFFIX_LEN + 1)
|
||||
#define WAL_LOG_SUFFIX "log"
|
||||
#define WAL_SUFFIX_AT (WAL_NOSUFFIX_LEN + 1)
|
||||
#define WAL_LOG_SUFFIX "log"
|
||||
#define WAL_INDEX_SUFFIX "idx"
|
||||
#define WAL_REFRESH_MS 1000
|
||||
#define WAL_MAX_SIZE (TSDB_MAX_WAL_SIZE + sizeof(SWalHead))
|
||||
#define WAL_PATH_LEN (TSDB_FILENAME_LEN + 12)
|
||||
#define WAL_FILE_LEN (WAL_PATH_LEN + 32)
|
||||
#define WAL_MAGIC 0xFAFBFCFDULL
|
||||
#define WAL_REFRESH_MS 1000
|
||||
#define WAL_MAX_SIZE (TSDB_MAX_WAL_SIZE + sizeof(SWalHead))
|
||||
#define WAL_PATH_LEN (TSDB_FILENAME_LEN + 12)
|
||||
#define WAL_FILE_LEN (WAL_PATH_LEN + 32)
|
||||
#define WAL_MAGIC 0xFAFBFCFDULL
|
||||
|
||||
#define WAL_CUR_FAILED 1
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
|
|||
int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count);
|
||||
void taosFprintfFile(TdFilePtr pFile, const char *format, ...);
|
||||
|
||||
int64_t taosGetLineFile(TdFilePtr pFile, char ** __restrict__ ptrBuf);
|
||||
int64_t taosGetLineFile(TdFilePtr pFile, char ** __restrict ptrBuf);
|
||||
|
||||
int32_t taosEOFFile(TdFilePtr pFile);
|
||||
|
||||
|
|
|
@ -33,13 +33,13 @@ void *taosMemoryMalloc(int32_t size);
|
|||
void *taosMemoryCalloc(int32_t num, int32_t size);
|
||||
void *taosMemoryRealloc(void *ptr, int32_t size);
|
||||
void *taosMemoryStrDup(void *ptr);
|
||||
void taosMemoryFree(const void *ptr);
|
||||
void taosMemoryFree(void *ptr);
|
||||
int32_t taosMemorySize(void *ptr);
|
||||
|
||||
#define taosMemoryFreeClear(ptr) \
|
||||
do { \
|
||||
if (ptr) { \
|
||||
taosMemoryFree(ptr); \
|
||||
taosMemoryFree((void*)ptr); \
|
||||
(ptr) = NULL; \
|
||||
} \
|
||||
} while (0)
|
||||
|
|
|
@ -29,6 +29,13 @@ extern "C" {
|
|||
#define tcgetattr TCGETATTR_FUNC_TAOS_FORBID
|
||||
#endif
|
||||
|
||||
typedef struct TdCmd *TdCmdPtr;
|
||||
|
||||
TdCmdPtr taosOpenCmd(const char *cmd);
|
||||
int64_t taosGetLineCmd(TdCmdPtr pCmd, char ** __restrict ptrBuf);
|
||||
int32_t taosEOFCmd(TdCmdPtr pCmd);
|
||||
int64_t taosCloseCmd(TdCmdPtr *ppCmd);
|
||||
|
||||
void* taosLoadDll(const char* filename);
|
||||
void* taosLoadSym(void* handle, char* name);
|
||||
void taosCloseDll(void* handle);
|
||||
|
|
|
@ -27,9 +27,11 @@ extern "C" {
|
|||
#ifndef ALLOW_FORBID_FUNC
|
||||
#define strptime STRPTIME_FUNC_TAOS_FORBID
|
||||
#define gettimeofday GETTIMEOFDAY_FUNC_TAOS_FORBID
|
||||
#define localtime LOCALTIME_FUNC_TAOS_FORBID
|
||||
#define localtime_s LOCALTIMES_FUNC_TAOS_FORBID
|
||||
#define localtime_r LOCALTIMER_FUNC_TAOS_FORBID
|
||||
#define time TIME_FUNC_TAOS_FORBID
|
||||
#define mktime MKTIME_FUNC_TAOS_FORBID
|
||||
#endif
|
||||
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
|
@ -82,6 +84,8 @@ static FORCE_INLINE int64_t taosGetTimestampNs() {
|
|||
|
||||
char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm);
|
||||
struct tm *taosLocalTime(const time_t *timep, struct tm *result);
|
||||
time_t taosTime(time_t *t);
|
||||
time_t taosMktime(struct tm *timep);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -569,8 +569,6 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_PAR_AMBIGUOUS_COLUMN TAOS_DEF_ERROR_CODE(0, 0x2603)
|
||||
#define TSDB_CODE_PAR_WRONG_VALUE_TYPE TAOS_DEF_ERROR_CODE(0, 0x2604)
|
||||
#define TSDB_CODE_PAR_INVALID_FUNTION TAOS_DEF_ERROR_CODE(0, 0x2605)
|
||||
#define TSDB_CODE_PAR_FUNTION_PARA_NUM TAOS_DEF_ERROR_CODE(0, 0x2606)
|
||||
#define TSDB_CODE_PAR_FUNTION_PARA_TYPE TAOS_DEF_ERROR_CODE(0, 0x2607)
|
||||
#define TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION TAOS_DEF_ERROR_CODE(0, 0x2608)
|
||||
#define TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT TAOS_DEF_ERROR_CODE(0, 0x2609)
|
||||
#define TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION TAOS_DEF_ERROR_CODE(0, 0x260A)
|
||||
|
@ -584,7 +582,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_PAR_INVALID_PORT TAOS_DEF_ERROR_CODE(0, 0x2612)
|
||||
#define TSDB_CODE_PAR_INVALID_ENDPOINT TAOS_DEF_ERROR_CODE(0, 0x2613)
|
||||
#define TSDB_CODE_PAR_EXPRIE_STATEMENT TAOS_DEF_ERROR_CODE(0, 0x2614)
|
||||
#define TSDB_CODE_PAR_INTERVAL_VALUE_TOO_SMALL TAOS_DEF_ERROR_CODE(0, 0x2615)
|
||||
#define TSDB_CODE_PAR_INTER_VALUE_TOO_SMALL TAOS_DEF_ERROR_CODE(0, 0x2615)
|
||||
#define TSDB_CODE_PAR_DB_NOT_SPECIFIED TAOS_DEF_ERROR_CODE(0, 0x2616)
|
||||
#define TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME TAOS_DEF_ERROR_CODE(0, 0x2617)
|
||||
#define TSDB_CODE_PAR_CORRESPONDING_STABLE_ERR TAOS_DEF_ERROR_CODE(0, 0x2618)
|
||||
|
@ -602,9 +600,26 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_PAR_GROUPBY_WINDOW_COEXIST TAOS_DEF_ERROR_CODE(0, 0x2624)
|
||||
#define TSDB_CODE_PAR_INVALID_OPTION_UNIT TAOS_DEF_ERROR_CODE(0, 0x2625)
|
||||
#define TSDB_CODE_PAR_INVALID_KEEP_UNIT TAOS_DEF_ERROR_CODE(0, 0x2626)
|
||||
#define TSDB_CODE_PAR_AGG_FUNC_NESTING TAOS_DEF_ERROR_CODE(0, 0x2627)
|
||||
#define TSDB_CODE_PAR_INVALID_STATE_WIN_TYPE TAOS_DEF_ERROR_CODE(0, 0x2628)
|
||||
#define TSDB_CODE_PAR_INVALID_STATE_WIN_COL TAOS_DEF_ERROR_CODE(0, 0x2629)
|
||||
#define TSDB_CODE_PAR_INVALID_STATE_WIN_TABLE TAOS_DEF_ERROR_CODE(0, 0x262A)
|
||||
#define TSDB_CODE_PAR_INTER_SESSION_GAP TAOS_DEF_ERROR_CODE(0, 0x262B)
|
||||
#define TSDB_CODE_PAR_INTER_SESSION_COL TAOS_DEF_ERROR_CODE(0, 0x262C)
|
||||
#define TSDB_CODE_PAR_INTER_OFFSET_NEGATIVE TAOS_DEF_ERROR_CODE(0, 0x262D)
|
||||
#define TSDB_CODE_PAR_INTER_OFFSET_UNIT TAOS_DEF_ERROR_CODE(0, 0x262E)
|
||||
#define TSDB_CODE_PAR_INTER_OFFSET_TOO_BIG TAOS_DEF_ERROR_CODE(0, 0x262F)
|
||||
#define TSDB_CODE_PAR_INTER_SLIDING_UNIT TAOS_DEF_ERROR_CODE(0, 0x2630)
|
||||
#define TSDB_CODE_PAR_INTER_SLIDING_TOO_BIG TAOS_DEF_ERROR_CODE(0, 0x2631)
|
||||
#define TSDB_CODE_PAR_INTER_SLIDING_TOO_SMALL TAOS_DEF_ERROR_CODE(0, 0x2632)
|
||||
|
||||
//planner
|
||||
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
|
||||
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
|
||||
|
||||
//function
|
||||
#define TSDB_CODE_FUNC_FUNTION_ERROR TAOS_DEF_ERROR_CODE(0, 0x2800)
|
||||
#define TSDB_CODE_FUNC_FUNTION_PARA_NUM TAOS_DEF_ERROR_CODE(0, 0x2801)
|
||||
#define TSDB_CODE_FUNC_FUNTION_PARA_TYPE TAOS_DEF_ERROR_CODE(0, 0x2802)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -100,11 +100,13 @@ extern const int32_t TYPE_BYTES[15];
|
|||
#define TSDB_TIME_PRECISION_NANO_DIGITS 19
|
||||
|
||||
#define TSDB_INFORMATION_SCHEMA_DB "information_schema"
|
||||
#define TSDB_PERFORMANCE_SCHEMA_DB "performance_schema"
|
||||
#define TSDB_INS_TABLE_DNODES "dnodes"
|
||||
#define TSDB_INS_TABLE_MNODES "mnodes"
|
||||
#define TSDB_INS_TABLE_MODULES "modules"
|
||||
#define TSDB_INS_TABLE_QNODES "qnodes"
|
||||
#define TSDB_INS_TABLE_BNODES "bnodes"
|
||||
#define TSDB_INS_TABLE_SNODES "snodes"
|
||||
#define TSDB_INS_TABLE_CLUSTER "cluster"
|
||||
#define TSDB_INS_TABLE_USER_DATABASES "user_databases"
|
||||
#define TSDB_INS_TABLE_USER_FUNCTIONS "user_functions"
|
||||
|
@ -114,9 +116,17 @@ extern const int32_t TYPE_BYTES[15];
|
|||
#define TSDB_INS_TABLE_USER_TABLES "user_tables"
|
||||
#define TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED "user_table_distributed"
|
||||
#define TSDB_INS_TABLE_USER_USERS "user_users"
|
||||
#define TSDB_INS_TABLE_LICENCES "grants"
|
||||
#define TSDB_INS_TABLE_VGROUPS "vgroups"
|
||||
#define TSDB_INS_TABLE_BNODES "bnodes"
|
||||
#define TSDB_INS_TABLE_SNODES "snodes"
|
||||
#define TSDB_INS_TABLE_TOPICS "topics"
|
||||
#define TSDB_INS_TABLE_CONSUMERS "consumers"
|
||||
#define TSDB_INS_TABLE_SUBSCRIBES "subscribes"
|
||||
#define TSDB_INS_TABLE_TRANS "trans"
|
||||
#define TSDB_INS_TABLE_SMAS "smas"
|
||||
#define TSDB_INS_TABLE_CONFIGS "configs"
|
||||
#define TSDB_INS_TABLE_CONNS "connections"
|
||||
#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"
|
||||
|
@ -503,6 +513,15 @@ enum {
|
|||
#define QNODE_HANDLE 1
|
||||
#define DEFAULT_HANDLE 0
|
||||
|
||||
#define TSDB_CONFIG_OPTION_LEN 16
|
||||
#define TSDB_CONIIG_VALUE_LEN 48
|
||||
#define TSDB_CONFIG_NUMBER 8
|
||||
|
||||
#define QUERY_ID_SIZE 20
|
||||
#define QUERY_OBJ_ID_SIZE 18
|
||||
#define SUBQUERY_INFO_SIZE 6
|
||||
#define QUERY_SAVE_SIZE 20
|
||||
|
||||
#define MAX_NUM_STR_SIZE 40
|
||||
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
#include "tcoding.h"
|
||||
#include "tfreelist.h"
|
||||
#include "tmacro.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -1,40 +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_UTIL_MACRO_H_
|
||||
#define _TD_UTIL_MACRO_H_
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Module init/clear MACRO definitions
|
||||
#define TD_MOD_UNINITIALIZED 0
|
||||
#define TD_MOD_INITIALIZED 1
|
||||
|
||||
typedef int8_t td_mode_flag_t;
|
||||
|
||||
#define TD_CHECK_AND_SET_MODE_INIT(FLAG) atomic_val_compare_exchange_8((FLAG), TD_MOD_UNINITIALIZED, TD_MOD_INITIALIZED)
|
||||
#define TD_CHECK_AND_SET_MOD_CLEAR(FLAG) atomic_val_compare_exchange_8((FLAG), TD_MOD_INITIALIZED, TD_MOD_UNINITIALIZED)
|
||||
|
||||
#define TD_IS_NULL(PTR) ((PTR) == NULL)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_UTIL_MACRO_H_*/
|
|
@ -22,13 +22,13 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum { PROC_REQ = 1, PROC_RSP, PROC_REGIST, PROC_RELEASE } ProcFuncType;
|
||||
typedef enum { PROC_FUNC_REQ = 1, PROC_FUNC_RSP, PROC_FUNC_REGIST, PROC_FUNC_RELEASE } EProcFuncType;
|
||||
|
||||
typedef struct SProcObj SProcObj;
|
||||
typedef void *(*ProcMallocFp)(int32_t contLen);
|
||||
typedef void *(*ProcFreeFp)(void *pCont);
|
||||
typedef void (*ProcConsumeFp)(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen,
|
||||
ProcFuncType ftype);
|
||||
EProcFuncType ftype);
|
||||
|
||||
typedef struct {
|
||||
ProcConsumeFp childConsumeFp;
|
||||
|
@ -53,11 +53,11 @@ int32_t taosProcRun(SProcObj *pProc);
|
|||
void taosProcStop(SProcObj *pProc);
|
||||
|
||||
int32_t taosProcPutToChildQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen,
|
||||
void *handle, ProcFuncType ftype);
|
||||
void *handle, EProcFuncType ftype);
|
||||
void taosProcRemoveHandle(SProcObj *pProc, void *handle);
|
||||
void taosProcCloseHandles(SProcObj *pProc, void (*HandleFp)(void *handle));
|
||||
void taosProcPutToParentQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen,
|
||||
ProcFuncType ftype);
|
||||
EProcFuncType ftype);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -228,6 +228,12 @@ function install_header() {
|
|||
${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h
|
||||
}
|
||||
|
||||
# temp install taosBenchmark
|
||||
function install_taosTools() {
|
||||
cd ${script_dir}/taos-tools/
|
||||
tar xvf taosTools-1.4.1-Linux-x64.tar.gz && cd taosTools-1.4.1/ && ./install-taostools.sh
|
||||
}
|
||||
|
||||
function add_newHostname_to_hosts() {
|
||||
localIp="127.0.0.1"
|
||||
OLD_IFS="$IFS"
|
||||
|
@ -454,14 +460,14 @@ function install_service_on_systemd() {
|
|||
}
|
||||
|
||||
function install_service() {
|
||||
if ((${service_mod}==0)); then
|
||||
install_service_on_systemd
|
||||
elif ((${service_mod}==1)); then
|
||||
install_service_on_sysvinit
|
||||
else
|
||||
# must manual stop taosd
|
||||
# if ((${service_mod}==0)); then
|
||||
# install_service_on_systemd
|
||||
# elif ((${service_mod}==1)); then
|
||||
# install_service_on_sysvinit
|
||||
# else
|
||||
# # must manual stop taosd
|
||||
kill_process taosd
|
||||
fi
|
||||
# fi
|
||||
}
|
||||
|
||||
function install_TDengine() {
|
||||
|
@ -473,6 +479,7 @@ function install_TDengine() {
|
|||
install_log
|
||||
install_header
|
||||
install_lib
|
||||
install_taosTools
|
||||
|
||||
if [ -z $1 ]; then # install service and client
|
||||
# For installing new
|
||||
|
|
|
@ -0,0 +1,657 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# This file is used to install TAOS time-series database on linux systems. The operating system
|
||||
# is required to use systemd to manage services at boot
|
||||
|
||||
set -e
|
||||
#set -x
|
||||
|
||||
# -----------------------Variables definition
|
||||
source_dir=$1
|
||||
binary_dir=$2
|
||||
osType=$3
|
||||
verNumber=$4
|
||||
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
script_dir=$(dirname $(readlink -f "$0"))
|
||||
else
|
||||
script_dir=${source_dir}/packaging/tools
|
||||
fi
|
||||
|
||||
# Dynamic directory
|
||||
clientName="taos"
|
||||
serverName="taosd"
|
||||
logDir="/var/log/taos"
|
||||
dataDir="/var/lib/taos"
|
||||
configDir="/etc/taos"
|
||||
configFile="taos.cfg"
|
||||
installDir="/usr/local/taos"
|
||||
productName="TDengine"
|
||||
emailName="taosdata.com"
|
||||
uninstallScript="rmtaos"
|
||||
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
data_dir=${dataDir}
|
||||
log_dir=${logDir}
|
||||
|
||||
cfg_install_dir=${configDir}
|
||||
|
||||
bin_link_dir="/usr/bin"
|
||||
lib_link_dir="/usr/lib"
|
||||
lib64_link_dir="/usr/lib64"
|
||||
inc_link_dir="/usr/include"
|
||||
|
||||
install_main_dir=${installDir}
|
||||
|
||||
bin_dir="${installDir}/bin"
|
||||
else
|
||||
data_dir="/usr/local${dataDir}"
|
||||
log_dir="/usr/local${logDir}"
|
||||
|
||||
cfg_install_dir="/usr/local${configDir}"
|
||||
|
||||
bin_link_dir="/usr/local/bin"
|
||||
lib_link_dir="/usr/local/lib"
|
||||
inc_link_dir="/usr/local/include"
|
||||
|
||||
install_main_dir="/usr/local/Cellar/tdengine/${verNumber}"
|
||||
install_main_2_dir="/usr/local/Cellar/tdengine@${verNumber}/${verNumber}"
|
||||
|
||||
bin_dir="/usr/local/Cellar/tdengine/${verNumber}/bin"
|
||||
bin_2_dir="/usr/local/Cellar/tdengine@${verNumber}/${verNumber}/bin"
|
||||
fi
|
||||
|
||||
service_config_dir="/etc/systemd/system"
|
||||
|
||||
# Color setting
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[1;32m'
|
||||
GREEN_DARK='\033[0;32m'
|
||||
GREEN_UNDERLINE='\033[4;32m'
|
||||
NC='\033[0m'
|
||||
|
||||
csudo=""
|
||||
|
||||
service_mod=2
|
||||
os_type=0
|
||||
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
if command -v sudo >/dev/null; then
|
||||
csudo="sudo "
|
||||
fi
|
||||
initd_mod=0
|
||||
if pidof systemd &>/dev/null; then
|
||||
service_mod=0
|
||||
elif $(which service &>/dev/null); then
|
||||
service_mod=1
|
||||
service_config_dir="/etc/init.d"
|
||||
if $(which chkconfig &>/dev/null); then
|
||||
initd_mod=1
|
||||
elif $(which insserv &>/dev/null); then
|
||||
initd_mod=2
|
||||
elif $(which update-rc.d &>/dev/null); then
|
||||
initd_mod=3
|
||||
else
|
||||
service_mod=2
|
||||
fi
|
||||
else
|
||||
service_mod=2
|
||||
fi
|
||||
|
||||
# get the operating system type for using the corresponding init file
|
||||
# ubuntu/debian(deb), centos/fedora(rpm), others: opensuse, redhat, ..., no verification
|
||||
#osinfo=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
|
||||
osinfo=$(cat /etc/os-release | grep "NAME" | cut -d '"' -f2)
|
||||
#echo "osinfo: ${osinfo}"
|
||||
if echo $osinfo | grep -qwi "ubuntu"; then
|
||||
echo "this is ubuntu system"
|
||||
os_type=1
|
||||
elif echo $osinfo | grep -qwi "debian"; then
|
||||
echo "this is debian system"
|
||||
os_type=1
|
||||
elif echo $osinfo | grep -qwi "Kylin"; then
|
||||
echo "this is Kylin system"
|
||||
os_type=1
|
||||
elif echo $osinfo | grep -qwi "centos"; then
|
||||
echo "this is centos system"
|
||||
os_type=2
|
||||
elif echo $osinfo | grep -qwi "fedora"; then
|
||||
echo "this is fedora system"
|
||||
os_type=2
|
||||
else
|
||||
echo "${osinfo}: This is an officially unverified linux system, If there are any problems with the installation and operation, "
|
||||
echo "please feel free to contact ${emailName} for support."
|
||||
os_type=1
|
||||
fi
|
||||
fi
|
||||
|
||||
function kill_taosadapter() {
|
||||
pid=$(ps -ef | grep "taosadapter" | grep -v "grep" | awk '{print $2}')
|
||||
if [ -n "$pid" ]; then
|
||||
${csudo}kill -9 $pid || :
|
||||
fi
|
||||
}
|
||||
|
||||
function kill_taosd() {
|
||||
ps -ef | grep ${serverName}
|
||||
pid=$(ps -ef | grep -w ${serverName} | grep -v "grep" | awk '{print $2}')
|
||||
if [ -n "$pid" ]; then
|
||||
${csudo}kill -9 $pid || :
|
||||
fi
|
||||
}
|
||||
|
||||
function install_main_path() {
|
||||
#create install main dir and all sub dir
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo}rm -rf ${install_main_dir} || :
|
||||
${csudo}mkdir -p ${install_main_dir}
|
||||
${csudo}mkdir -p ${install_main_dir}/cfg
|
||||
${csudo}mkdir -p ${install_main_dir}/bin
|
||||
# ${csudo}mkdir -p ${install_main_dir}/connector
|
||||
${csudo}mkdir -p ${install_main_dir}/driver
|
||||
${csudo}mkdir -p ${install_main_dir}/examples
|
||||
${csudo}mkdir -p ${install_main_dir}/include
|
||||
# ${csudo}mkdir -p ${install_main_dir}/init.d
|
||||
else
|
||||
${csudo}rm -rf ${install_main_dir} || ${csudo}rm -rf ${install_main_2_dir} || :
|
||||
${csudo}mkdir -p ${install_main_dir} || ${csudo}mkdir -p ${install_main_2_dir}
|
||||
${csudo}mkdir -p ${install_main_dir}/cfg || ${csudo}mkdir -p ${install_main_2_dir}/cfg
|
||||
${csudo}mkdir -p ${install_main_dir}/bin || ${csudo}mkdir -p ${install_main_2_dir}/bin
|
||||
# ${csudo}mkdir -p ${install_main_dir}/connector || ${csudo}mkdir -p ${install_main_2_dir}/connector
|
||||
${csudo}mkdir -p ${install_main_dir}/driver || ${csudo}mkdir -p ${install_main_2_dir}/driver
|
||||
${csudo}mkdir -p ${install_main_dir}/examples || ${csudo}mkdir -p ${install_main_2_dir}/examples
|
||||
${csudo}mkdir -p ${install_main_dir}/include || ${csudo}mkdir -p ${install_main_2_dir}/include
|
||||
fi
|
||||
}
|
||||
|
||||
function install_bin() {
|
||||
# Remove links
|
||||
${csudo}rm -f ${bin_link_dir}/${clientName} || :
|
||||
${csudo}rm -f ${bin_link_dir}/${serverName} || :
|
||||
${csudo}rm -f ${bin_link_dir}/taosadapter || :
|
||||
${csudo}rm -f ${bin_link_dir}/taosdemo || :
|
||||
${csudo}rm -f ${bin_link_dir}/taosdump || :
|
||||
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo}rm -f ${bin_link_dir}/perfMonitor || :
|
||||
${csudo}rm -f ${bin_link_dir}/set_core || :
|
||||
${csudo}rm -f ${bin_link_dir}/run_taosd_and_taosadapter.sh || :
|
||||
${csudo}rm -f ${bin_link_dir}/${uninstallScript} || :
|
||||
|
||||
${csudo}cp -r ${binary_dir}/build/bin/${clientName} ${install_main_dir}/bin || :
|
||||
[ -f ${binary_dir}/build/bin/taosBenchmark ] && ${csudo}cp -r ${binary_dir}/build/bin/taosBenchmark ${install_main_dir}/bin || :
|
||||
[ -f ${install_main_dir}/bin/taosBenchmark ] && ${csudo}ln -sf ${install_main_dir}/bin/taosBenchmark ${install_main_dir}/bin/taosdemo || :
|
||||
[ -f ${binary_dir}/build/bin/taosdump ] && ${csudo}cp -r ${binary_dir}/build/bin/taosdump ${install_main_dir}/bin || :
|
||||
[ -f ${binary_dir}/build/bin/taosadapter ] && ${csudo}cp -r ${binary_dir}/build/bin/taosadapter ${install_main_dir}/bin || :
|
||||
${csudo}cp -r ${binary_dir}/build/bin/${serverName} ${install_main_dir}/bin || :
|
||||
${csudo}cp -r ${binary_dir}/build/bin/tarbitrator ${install_main_dir}/bin || :
|
||||
|
||||
${csudo}cp -r ${script_dir}/taosd-dump-cfg.gdb ${install_main_dir}/bin || :
|
||||
${csudo}cp -r ${script_dir}/remove.sh ${install_main_dir}/bin || :
|
||||
${csudo}cp -r ${script_dir}/set_core.sh ${install_main_dir}/bin || :
|
||||
${csudo}cp -r ${script_dir}/run_taosd_and_taosadapter.sh ${install_main_dir}/bin || :
|
||||
${csudo}cp -r ${script_dir}/startPre.sh ${install_main_dir}/bin || :
|
||||
|
||||
${csudo}chmod 0555 ${install_main_dir}/bin/*
|
||||
#Make link
|
||||
[ -x ${install_main_dir}/bin/${clientName} ] && ${csudo}ln -s ${install_main_dir}/bin/${clientName} ${bin_link_dir}/${clientName} || :
|
||||
[ -x ${install_main_dir}/bin/${serverName} ] && ${csudo}ln -s ${install_main_dir}/bin/${serverName} ${bin_link_dir}/${serverName} || :
|
||||
[ -x ${install_main_dir}/bin/taosadapter ] && ${csudo}ln -s ${install_main_dir}/bin/taosadapter ${bin_link_dir}/taosadapter || :
|
||||
[ -x ${install_main_dir}/bin/taosdump ] && ${csudo}ln -s ${install_main_dir}/bin/taosdump ${bin_link_dir}/taosdump || :
|
||||
[ -x ${install_main_dir}/bin/taosdemo ] && ${csudo}ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || :
|
||||
[ -x ${install_main_dir}/bin/perfMonitor ] && ${csudo}ln -s ${install_main_dir}/bin/perfMonitor ${bin_link_dir}/perfMonitor || :
|
||||
[ -x ${install_main_dir}/set_core.sh ] && ${csudo}ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || :
|
||||
[ -x ${install_main_dir}/run_taosd_and_taosadapter.sh ] && ${csudo}ln -s ${install_main_dir}/bin/run_taosd_and_taosadapter.sh ${bin_link_dir}/run_taosd_and_taosadapter.sh || :
|
||||
[ -x ${install_main_dir}/bin/remove.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove.sh ${bin_link_dir}/${uninstallScript} || :
|
||||
else
|
||||
|
||||
${csudo}cp -r ${binary_dir}/build/bin/* ${install_main_dir}/bin || ${csudo}cp -r ${binary_dir}/build/bin/* ${install_main_2_dir}/bin || :
|
||||
${csudo}cp -r ${script_dir}/taosd-dump-cfg.gdb ${install_main_dir}/bin || ${csudo}cp -r ${script_dir}/taosd-dump-cfg.gdb ${install_main_2_dir} || :
|
||||
${csudo}cp -r ${script_dir}/remove_client.sh ${install_main_dir}/bin || ${csudo}cp -r ${script_dir}/remove_client.sh ${install_main_2_dir}/bin || :
|
||||
${csudo}chmod 0555 ${install_main_dir}/bin/* || ${csudo}chmod 0555 ${install_main_2_dir}/bin/*
|
||||
#Make link
|
||||
[ -x ${install_main_dir}/bin/${clientName} ] || [ -x ${install_main_2_dir}/bin/${clientName} ] && ${csudo}ln -s ${install_main_dir}/bin/${clientName} ${bin_link_dir}/${clientName} || ${csudo}ln -s ${install_main_2_dir}/bin/${clientName} || :
|
||||
[ -x ${install_main_dir}/bin/${serverName} ] || [ -x ${install_main_2_dir}/bin/${serverName} ] && ${csudo}ln -s ${install_main_dir}/bin/${serverName} ${bin_link_dir}/${serverName} || ${csudo}ln -s ${install_main_2_dir}/bin/${serverName} || :
|
||||
[ -x ${install_main_dir}/bin/taosadapter ] || [ -x ${install_main_2_dir}/bin/taosadapter ] && ${csudo}ln -s ${install_main_dir}/bin/taosadapter ${bin_link_dir}/taosadapter || ${csudo}ln -s ${install_main_2_dir}/bin/taosadapter || :
|
||||
[ -x ${install_main_dir}/bin/taosdump ] || [ -x ${install_main_2_dir}/bin/taosdump ] && ${csudo}ln -s ${install_main_dir}/bin/taosdump ${bin_link_dir}/taosdump || ln -s ${install_main_2_dir}/bin/taosdump ${bin_link_dir}/taosdump || :
|
||||
[ -x ${install_main_dir}/bin/taosdemo ] || [ -x ${install_main_2_dir}/bin/taosdemo ] && ${csudo}ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || ln -s ${install_main_2_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || :
|
||||
fi
|
||||
}
|
||||
|
||||
function install_jemalloc() {
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
/usr/bin/install -c -d /usr/local/bin
|
||||
|
||||
if [ -f "${binary_dir}/build/bin/jemalloc-config" ]; then
|
||||
${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/bin/jemalloc-config /usr/local/bin
|
||||
fi
|
||||
if [ -f "${binary_dir}/build/bin/jemalloc.sh" ]; then
|
||||
${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/bin/jemalloc.sh /usr/local/bin
|
||||
fi
|
||||
if [ -f "${binary_dir}/build/bin/jeprof" ]; then
|
||||
${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/bin/jeprof /usr/local/bin
|
||||
fi
|
||||
if [ -f "${binary_dir}/build/include/jemalloc/jemalloc.h" ]; then
|
||||
${csudo}/usr/bin/install -c -d /usr/local/include/jemalloc
|
||||
${csudo}/usr/bin/install -c -m 644 ${binary_dir}/build/include/jemalloc/jemalloc.h \
|
||||
/usr/local/include/jemalloc
|
||||
fi
|
||||
if [ -f "${binary_dir}/build/lib/libjemalloc.so.2" ]; then
|
||||
${csudo}/usr/bin/install -c -d /usr/local/lib
|
||||
${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc.so.2 /usr/local/lib
|
||||
${csudo}ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so
|
||||
${csudo}/usr/bin/install -c -d /usr/local/lib
|
||||
[ -f ${binary_dir}/build/lib/libjemalloc.a ] &&
|
||||
${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc.a /usr/local/lib
|
||||
[ -f ${binary_dir}/build/lib/libjemalloc_pic.a ] &&
|
||||
${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc_pic.a /usr/local/lib
|
||||
if [ -f "${binary_dir}/build/lib/pkgconfig/jemalloc.pc" ]; then
|
||||
${csudo}/usr/bin/install -c -d /usr/local/lib/pkgconfig
|
||||
${csudo}/usr/bin/install -c -m 644 ${binary_dir}/build/lib/pkgconfig/jemalloc.pc \
|
||||
/usr/local/lib/pkgconfig
|
||||
fi
|
||||
if [ -d /etc/ld.so.conf.d ]; then
|
||||
echo "/usr/local/lib" | ${csudo}tee /etc/ld.so.conf.d/jemalloc.conf >/dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf"
|
||||
${csudo}ldconfig
|
||||
else
|
||||
echo "/etc/ld.so.conf.d not found!"
|
||||
fi
|
||||
fi
|
||||
if [ -f "${binary_dir}/build/share/doc/jemalloc/jemalloc.html" ]; then
|
||||
${csudo}/usr/bin/install -c -d /usr/local/share/doc/jemalloc
|
||||
${csudo}/usr/bin/install -c -m 644 ${binary_dir}/build/share/doc/jemalloc/jemalloc.html \
|
||||
/usr/local/share/doc/jemalloc
|
||||
fi
|
||||
if [ -f "${binary_dir}/build/share/man/man3/jemalloc.3" ]; then
|
||||
${csudo}/usr/bin/install -c -d /usr/local/share/man/man3
|
||||
${csudo}/usr/bin/install -c -m 644 ${binary_dir}/build/share/man/man3/jemalloc.3 \
|
||||
/usr/local/share/man/man3
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function install_avro() {
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
if [ -f "${binary_dir}/build/$1/libavro.so.23.0.0" ] && [ -d /usr/local/$1 ]; then
|
||||
${csudo}/usr/bin/install -c -d /usr/local/$1
|
||||
${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/$1/libavro.so.23.0.0 /usr/local/$1
|
||||
${csudo}ln -sf libavro.so.23.0.0 /usr/local/$1/libavro.so.23
|
||||
${csudo}ln -sf libavro.so.23 /usr/local/$1/libavro.so
|
||||
${csudo}/usr/bin/install -c -d /usr/local/$1
|
||||
[ -f ${binary_dir}/build/$1/libavro.a ] &&
|
||||
${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/$1/libavro.a /usr/local/$1
|
||||
|
||||
if [ -d /etc/ld.so.conf.d ]; then
|
||||
echo "/usr/local/$1" | ${csudo}tee /etc/ld.so.conf.d/libavro.conf >/dev/null || echo -e "failed to write /etc/ld.so.conf.d/libavro.conf"
|
||||
${csudo}ldconfig
|
||||
else
|
||||
echo "/etc/ld.so.conf.d not found!"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function install_lib() {
|
||||
# Remove links
|
||||
${csudo}rm -f ${lib_link_dir}/libtaos.* || :
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo}rm -f ${lib64_link_dir}/libtaos.* || :
|
||||
fi
|
||||
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo}cp ${binary_dir}/build/lib/libtaos.so.${verNumber} \
|
||||
${install_main_dir}/driver &&
|
||||
${csudo}chmod 777 ${install_main_dir}/driver/*
|
||||
|
||||
${csudo}ln -sf ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1
|
||||
${csudo}ln -sf ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so
|
||||
|
||||
if [ -d "${lib64_link_dir}" ]; then
|
||||
${csudo}ln -sf ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1
|
||||
${csudo}ln -sf ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so
|
||||
fi
|
||||
else
|
||||
${csudo}cp -Rf ${binary_dir}/build/lib/libtaos.${verNumber}.dylib \
|
||||
${install_main_dir}/driver ||
|
||||
${csudo}cp -Rf ${binary_dir}/build/lib/libtaos.${verNumber}.dylib \
|
||||
${install_main_2_dir}/driver &&
|
||||
${csudo}chmod 777 ${install_main_dir}/driver/* ||
|
||||
${csudo}chmod 777 ${install_main_2_dir}/driver/*
|
||||
|
||||
${csudo}ln -sf ${install_main_dir}/driver/libtaos.* \
|
||||
${install_main_dir}/driver/libtaos.1.dylib ||
|
||||
${csudo}ln -sf ${install_main_2_dir}/driver/libtaos.* \
|
||||
${install_main_2_dir}/driver/libtaos.1.dylib || :
|
||||
|
||||
${csudo}ln -sf ${install_main_dir}/driver/libtaos.1.dylib \
|
||||
${install_main_dir}/driver/libtaos.dylib ||
|
||||
${csudo}ln -sf ${install_main_2_dir}/driver/libtaos.1.dylib \
|
||||
${install_main_2_dir}/driver/libtaos.dylib || :
|
||||
|
||||
${csudo}ln -sf ${install_main_dir}/driver/libtaos.${verNumber}.dylib \
|
||||
${lib_link_dir}/libtaos.1.dylib ||
|
||||
${csudo}ln -sf ${install_main_2_dir}/driver/libtaos.${verNumber}.dylib \
|
||||
${lib_link_dir}/libtaos.1.dylib || :
|
||||
|
||||
${csudo}ln -sf ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib || :
|
||||
fi
|
||||
|
||||
install_jemalloc
|
||||
install_avro lib
|
||||
install_avro lib64
|
||||
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo}ldconfig
|
||||
fi
|
||||
}
|
||||
|
||||
function install_header() {
|
||||
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || :
|
||||
${csudo}cp -f ${source_dir}/include/client/taos.h ${source_dir}/include/common/taosdef.h ${source_dir}/include/util/taoserror.h \
|
||||
${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/*
|
||||
${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h
|
||||
${csudo}ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h
|
||||
${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h
|
||||
else
|
||||
${csudo}cp -f ${source_dir}/include/client/taos.h ${source_dir}/include/common/taosdef.h ${source_dir}/include/util/taoserror.h \
|
||||
${install_main_dir}/include ||
|
||||
${csudo}cp -f ${source_dir}/include/client/taos.h ${source_dir}/include/common/taosdef.h ${source_dir}/include/util/taoserror.h \
|
||||
${install_main_2_dir}/include &&
|
||||
${csudo}chmod 644 ${install_main_dir}/include/* ||
|
||||
${csudo}chmod 644 ${install_main_2_dir}/include/*
|
||||
fi
|
||||
}
|
||||
|
||||
function install_config() {
|
||||
if [ ! -f ${cfg_install_dir}/${configFile} ]; then
|
||||
${csudo}mkdir -p ${cfg_install_dir}
|
||||
[ -f ${script_dir}/../cfg/${configFile} ] &&
|
||||
${csudo}cp ${script_dir}/../cfg/${configFile} ${cfg_install_dir} || :
|
||||
${csudo}chmod 644 ${cfg_install_dir}/${configFile}
|
||||
${csudo}cp -f ${script_dir}/../cfg/${configFile} \
|
||||
${cfg_install_dir}/${configFile}.${verNumber} || :
|
||||
${csudo}ln -s ${cfg_install_dir}/${configFile} \
|
||||
${install_main_dir}/cfg/${configFile}
|
||||
else
|
||||
${csudo}cp -f ${script_dir}/../cfg/${configFile} \
|
||||
${cfg_install_dir}/${configFile}.${verNumber} || :
|
||||
fi
|
||||
}
|
||||
|
||||
function install_taosadapter_config() {
|
||||
if [ ! -f "${cfg_install_dir}/taosadapter.toml" ]; then
|
||||
${csudo}mkdir -p ${cfg_install_dir} || :
|
||||
[ -f ${binary_dir}/test/cfg/taosadapter.toml ] &&
|
||||
${csudo}cp ${binary_dir}/test/cfg/taosadapter.toml ${cfg_install_dir} || :
|
||||
[ -f ${cfg_install_dir}/taosadapter.toml ] &&
|
||||
${csudo}chmod 644 ${cfg_install_dir}/taosadapter.toml || :
|
||||
[ -f ${binary_dir}/test/cfg/taosadapter.toml ] &&
|
||||
${csudo}cp -f ${binary_dir}/test/cfg/taosadapter.toml \
|
||||
${cfg_install_dir}/taosadapter.toml.${verNumber} || :
|
||||
[ -f ${cfg_install_dir}/taosadapter.toml ] &&
|
||||
${csudo}ln -s ${cfg_install_dir}/taosadapter.toml \
|
||||
${install_main_dir}/cfg/taosadapter.toml || :
|
||||
else
|
||||
if [ -f "${binary_dir}/test/cfg/taosadapter.toml" ]; then
|
||||
${csudo}cp -f ${binary_dir}/test/cfg/taosadapter.toml \
|
||||
${cfg_install_dir}/taosadapter.toml.${verNumber} || :
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function install_log() {
|
||||
${csudo}rm -rf ${log_dir} || :
|
||||
${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir}
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo}ln -s ${log_dir} ${install_main_dir}/log
|
||||
else
|
||||
${csudo}ln -s ${log_dir} ${install_main_dir}/log || ${csudo}ln -s ${log_dir} ${install_main_2_dir}/log
|
||||
fi
|
||||
}
|
||||
|
||||
function install_data() {
|
||||
${csudo}mkdir -p ${data_dir}
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo}ln -s ${data_dir} ${install_main_dir}/data
|
||||
else
|
||||
${csudo}ln -s ${data_dir} ${install_main_dir}/data || ${csudo}ln -s ${data_dir} ${install_main_2_dir}/data
|
||||
fi
|
||||
}
|
||||
|
||||
function install_connector() {
|
||||
if find ${source_dir}/src/connector/go -mindepth 1 -maxdepth 1 | read; then
|
||||
${csudo}cp -r ${source_dir}/src/connector/go ${install_main_dir}/connector || :
|
||||
else
|
||||
echo "WARNING: go connector not found, please check if want to use it!"
|
||||
fi
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo}cp -rf ${source_dir}/src/connector/python ${install_main_dir}/connector || :
|
||||
${csudo}cp ${binary_dir}/build/lib/*.jar ${install_main_dir}/connector &>/dev/null && ${csudo}chmod 777 ${install_main_dir}/connector/*.jar || echo &>/dev/null || :
|
||||
else
|
||||
${csudo}cp -rf ${source_dir}/src/connector/python ${install_main_dir}/connector || ${csudo}cp -rf ${source_dir}/src/connector/python ${install_main_2_dir}/connector || :
|
||||
${csudo}cp ${binary_dir}/build/lib/*.jar ${install_main_dir}/connector &>/dev/null && ${csudo}chmod 777 ${install_main_dir}/connector/*.jar || echo &>/dev/null || :
|
||||
${csudo}cp ${binary_dir}/build/lib/*.jar ${install_main_2_dir}/connector &>/dev/null && ${csudo}chmod 777 ${install_main_2_dir}/connector/*.jar || echo &>/dev/null || :
|
||||
fi
|
||||
}
|
||||
|
||||
function install_examples() {
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo}cp -rf ${source_dir}/examples/* ${install_main_dir}/examples || :
|
||||
else
|
||||
${csudo}cp -rf ${source_dir}/examples/* ${install_main_dir}/examples || ${csudo}cp -rf ${source_dir}/examples/* ${install_main_2_dir}/examples || :
|
||||
fi
|
||||
}
|
||||
|
||||
function clean_service_on_sysvinit() {
|
||||
if pidof ${serverName} &>/dev/null; then
|
||||
${csudo}service ${serverName} stop || :
|
||||
fi
|
||||
|
||||
if ((${initd_mod} == 1)); then
|
||||
${csudo}chkconfig --del ${serverName} || :
|
||||
elif ((${initd_mod} == 2)); then
|
||||
${csudo}insserv -r ${serverName} || :
|
||||
elif ((${initd_mod} == 3)); then
|
||||
${csudo}update-rc.d -f ${serverName} remove || :
|
||||
fi
|
||||
|
||||
${csudo}rm -f ${service_config_dir}/${serverName} || :
|
||||
|
||||
if $(which init &>/dev/null); then
|
||||
${csudo}init q || :
|
||||
fi
|
||||
}
|
||||
|
||||
function install_service_on_sysvinit() {
|
||||
clean_service_on_sysvinit
|
||||
|
||||
sleep 1
|
||||
|
||||
if ((${os_type} == 1)); then
|
||||
# ${csudo}cp -f ${script_dir}/../deb/${serverName} ${install_main_dir}/init.d
|
||||
${csudo}cp ${script_dir}/../deb/${serverName} ${service_config_dir} && ${csudo}chmod a+x ${service_config_dir}/${serverName} || :
|
||||
elif ((${os_type} == 2)); then
|
||||
# ${csudo}cp -f ${script_dir}/../rpm/${serverName} ${install_main_dir}/init.d
|
||||
${csudo}cp ${script_dir}/../rpm/${serverName} ${service_config_dir} && ${csudo}chmod a+x ${service_config_dir}/${serverName} || :
|
||||
fi
|
||||
|
||||
if ((${initd_mod} == 1)); then
|
||||
${csudo}chkconfig --add ${serverName} || :
|
||||
${csudo}chkconfig --level 2345 ${serverName} on || :
|
||||
elif ((${initd_mod} == 2)); then
|
||||
${csudo}insserv ${serverName} || :
|
||||
${csudo}insserv -d ${serverName} || :
|
||||
elif ((${initd_mod} == 3)); then
|
||||
${csudo}update-rc.d ${serverName} defaults || :
|
||||
fi
|
||||
}
|
||||
|
||||
function clean_service_on_systemd() {
|
||||
taosd_service_config="${service_config_dir}/${serverName}.service"
|
||||
|
||||
if systemctl is-active --quiet ${serverName}; then
|
||||
echo "${productName} is running, stopping it..."
|
||||
${csudo}systemctl stop ${serverName} &>/dev/null || echo &>/dev/null
|
||||
fi
|
||||
${csudo}systemctl disable ${serverName} &>/dev/null || echo &>/dev/null
|
||||
|
||||
${csudo}rm -f ${taosd_service_config}
|
||||
}
|
||||
|
||||
function install_service_on_systemd() {
|
||||
clean_service_on_systemd
|
||||
|
||||
taosd_service_config="${service_config_dir}/${serverName}.service"
|
||||
|
||||
${csudo}bash -c "echo '[Unit]' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'Description=${productName} server service' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'After=network-online.target' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'Wants=network-online.target' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo '[Service]' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'Type=simple' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'ExecStart=/usr/bin/${serverName}' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'ExecStartPre=${installDir}/bin/startPre.sh' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'LimitCORE=infinity' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'StandardOutput=null' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'Restart=always' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'StartLimitBurst=3' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo '[Install]' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${taosd_service_config}"
|
||||
${csudo}systemctl enable ${serverName}
|
||||
}
|
||||
|
||||
function install_taosadapter_service() {
|
||||
if ((${service_mod} == 0)); then
|
||||
[ -f ${binary_dir}/test/cfg/taosadapter.service ] &&
|
||||
${csudo}cp ${binary_dir}/test/cfg/taosadapter.service \
|
||||
${service_config_dir}/ || :
|
||||
${csudo}systemctl daemon-reload
|
||||
fi
|
||||
}
|
||||
|
||||
function install_service() {
|
||||
if ((${service_mod} == 0)); then
|
||||
install_service_on_systemd
|
||||
elif ((${service_mod} == 1)); then
|
||||
install_service_on_sysvinit
|
||||
else
|
||||
kill_taosd
|
||||
fi
|
||||
}
|
||||
|
||||
function update_TDengine() {
|
||||
echo -e "${GREEN}Start to update ${productName}...${NC}"
|
||||
# Stop the service if running
|
||||
|
||||
if pidof ${serverName} &>/dev/null; then
|
||||
if ((${service_mod} == 0)); then
|
||||
${csudo}systemctl stop ${serverName} || :
|
||||
elif ((${service_mod} == 1)); then
|
||||
${csudo}service ${serverName} stop || :
|
||||
else
|
||||
kill_taosadapter
|
||||
kill_taosd
|
||||
fi
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
install_main_path
|
||||
|
||||
install_log
|
||||
install_header
|
||||
install_lib
|
||||
# install_connector
|
||||
install_examples
|
||||
install_bin
|
||||
|
||||
install_service
|
||||
install_taosadapter_service
|
||||
|
||||
install_config
|
||||
install_taosadapter_config
|
||||
|
||||
echo
|
||||
echo -e "\033[44;32;1m${productName} is updated successfully!${NC}"
|
||||
echo
|
||||
|
||||
echo -e "${GREEN_DARK}To configure ${productName} ${NC}: edit ${configDir}/${configFile}"
|
||||
echo -e "${GREEN_DARK}To configure Taos Adapter (if has) ${NC}: edit ${configDir}/taosadapter.toml"
|
||||
if ((${service_mod} == 0)); then
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}systemctl start ${serverName}${NC}"
|
||||
elif ((${service_mod} == 1)); then
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}service ${serverName} start${NC}"
|
||||
else
|
||||
echo -e "${GREEN_DARK}To start Taos Adapter (if has)${NC}: taosadapter &${NC}"
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${serverName}${NC}"
|
||||
fi
|
||||
|
||||
echo -e "${GREEN_DARK}To access ${productName} ${NC}: use ${GREEN_UNDERLINE}${clientName}${NC} in shell${NC}"
|
||||
echo
|
||||
echo -e "\033[44;32;1m${productName} is updated successfully!${NC}"
|
||||
}
|
||||
|
||||
function install_TDengine() {
|
||||
# Start to install
|
||||
echo -e "${GREEN}Start to install ${productName}...${NC}"
|
||||
|
||||
install_main_path
|
||||
|
||||
install_data
|
||||
install_log
|
||||
install_header
|
||||
install_lib
|
||||
# install_connector
|
||||
install_examples
|
||||
install_bin
|
||||
|
||||
install_service
|
||||
install_taosadapter_service
|
||||
|
||||
install_config
|
||||
install_taosadapter_config
|
||||
|
||||
# Ask if to start the service
|
||||
echo
|
||||
echo -e "\033[44;32;1m${productName} is installed successfully!${NC}"
|
||||
echo
|
||||
echo -e "${GREEN_DARK}To configure ${productName} ${NC}: edit ${configDir}/${configFile}"
|
||||
echo -e "${GREEN_DARK}To configure taosadapter (if has) ${NC}: edit ${configDir}/taosadapter.toml"
|
||||
if ((${service_mod} == 0)); then
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}systemctl start ${serverName}${NC}"
|
||||
elif ((${service_mod} == 1)); then
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}service ${serverName} start${NC}"
|
||||
else
|
||||
echo -e "${GREEN_DARK}To start Taos Adapter (if has)${NC}: taosadapter &${NC}"
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ./${serverName}${NC}"
|
||||
fi
|
||||
|
||||
echo -e "${GREEN_DARK}To access ${productName} ${NC}: use ${GREEN_UNDERLINE}${clientName}${NC} in shell${NC}"
|
||||
echo
|
||||
echo -e "\033[44;32;1m${productName} is installed successfully!${NC}"
|
||||
}
|
||||
|
||||
## ==============================Main program starts from here============================
|
||||
echo source directory: $1
|
||||
echo binary directory: $2
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
if [ -x ${bin_dir}/${clientName} ]; then
|
||||
update_TDengine
|
||||
else
|
||||
install_TDengine
|
||||
fi
|
||||
else
|
||||
if [ -x ${bin_dir}/${clientName} ] || [ -x ${bin_2_dir}/${clientName} ]; then
|
||||
update_TDengine
|
||||
else
|
||||
install_TDengine
|
||||
fi
|
||||
fi
|
|
@ -55,6 +55,7 @@ mkdir -p ${install_dir}
|
|||
mkdir -p ${install_dir}/bin
|
||||
mkdir -p ${install_dir}/lib
|
||||
mkdir -p ${install_dir}/inc
|
||||
mkdir -p ${install_dir}/taos-tools
|
||||
|
||||
install_files="${script_dir}/install.sh"
|
||||
chmod a+x ${script_dir}/install.sh || :
|
||||
|
@ -63,11 +64,13 @@ cp ${install_files} ${install_dir}
|
|||
header_files="${top_dir}/include/client/taos.h ${top_dir}/include/util/taoserror.h"
|
||||
cp ${header_files} ${install_dir}/inc
|
||||
|
||||
bin_files="${compile_dir}/source/dnode/mgmt/taosd ${compile_dir}/tools/shell/taos ${compile_dir}/tests/test/c/create_table ${compile_dir}/tests/test/c/tmq_sim ${script_dir}/remove.sh"
|
||||
bin_files="${compile_dir}/build/bin/taosd ${compile_dir}/build/bin/taos ${compile_dir}/build/bin/create_table ${compile_dir}/build/bin/tmq_sim ${script_dir}/remove.sh"
|
||||
cp ${bin_files} ${install_dir}/bin && chmod a+x ${install_dir}/bin/* || :
|
||||
|
||||
cp ${compile_dir}/source/client/libtaos.so ${install_dir}/lib/
|
||||
cp ${compile_dir}/source/libs/tdb/libtdb.so ${install_dir}/lib/
|
||||
cp ${compile_dir}/build/lib/libtaos.so ${install_dir}/lib/
|
||||
cp ${compile_dir}/build/lib/libtdb.so ${install_dir}/lib/
|
||||
taostoolfile="${top_dir}/tools/taosTools-1.4.1-Linux-x64.tar.gz"
|
||||
cp ${taostoolfile} ${install_dir}/taos-tools
|
||||
|
||||
#cp ${compile_dir}/source/dnode/mnode/impl/libmnode.so ${install_dir}/lib/
|
||||
#cp ${compile_dir}/source/dnode/qnode/libqnode.so ${install_dir}/lib/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
aux_source_directory(src CLIENT_SRC)
|
||||
add_library(taos ${CLIENT_SRC})
|
||||
add_library(taos SHARED ${CLIENT_SRC})
|
||||
target_include_directories(
|
||||
taos
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/client"
|
||||
|
@ -11,6 +11,25 @@ target_link_libraries(
|
|||
PRIVATE os util common transport nodes parser command planner catalog scheduler function qcom
|
||||
)
|
||||
|
||||
set_target_properties(
|
||||
taos
|
||||
PROPERTIES
|
||||
VERSION ${TD_VER_NUMBER}
|
||||
SOVERSION ${TD_VER_NUMBER}
|
||||
)
|
||||
|
||||
add_library(taos_static STATIC ${CLIENT_SRC})
|
||||
target_include_directories(
|
||||
taos_static
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/client"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
target_link_libraries(
|
||||
taos_static
|
||||
INTERFACE api
|
||||
PRIVATE os util common transport nodes parser command planner catalog scheduler function qcom
|
||||
)
|
||||
|
||||
if(${BUILD_TEST})
|
||||
ADD_SUBDIRECTORY(test)
|
||||
endif(${BUILD_TEST})
|
|
@ -43,8 +43,17 @@ extern "C" {
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
#define ERROR_MSG_BUF_DEFAULT_SIZE 512
|
||||
#define HEARTBEAT_INTERVAL 1500 // ms
|
||||
|
||||
enum {
|
||||
RES_TYPE__QUERY = 1,
|
||||
RES_TYPE__TMQ,
|
||||
};
|
||||
|
||||
#define TD_RES_QUERY(res) (*(int8_t*)res == RES_TYPE__QUERY)
|
||||
#define TD_RES_TMQ(res) (*(int8_t*)res == RES_TYPE__TMQ)
|
||||
|
||||
typedef struct SAppInstInfo SAppInstInfo;
|
||||
|
||||
typedef struct {
|
||||
|
@ -79,8 +88,8 @@ typedef struct {
|
|||
TdThread thread;
|
||||
TdThreadMutex lock; // used when app init and cleanup
|
||||
SArray* appHbMgrs; // SArray<SAppHbMgr*> one for each cluster
|
||||
FHbReqHandle reqHandle[HEARTBEAT_TYPE_MAX];
|
||||
FHbRspHandle rspHandle[HEARTBEAT_TYPE_MAX];
|
||||
FHbReqHandle reqHandle[CONN_TYPE__MAX];
|
||||
FHbRspHandle rspHandle[CONN_TYPE__MAX];
|
||||
} SClientHbMgr;
|
||||
|
||||
typedef struct SQueryExecMetric {
|
||||
|
@ -132,9 +141,9 @@ typedef struct STscObj {
|
|||
char pass[TSDB_PASSWORD_LEN];
|
||||
char db[TSDB_DB_FNAME_LEN];
|
||||
char ver[128];
|
||||
int8_t connType;
|
||||
int32_t acctId;
|
||||
uint32_t connId;
|
||||
int32_t connType;
|
||||
uint64_t id; // ref ID returned by taosAddRef
|
||||
TdThreadMutex mutex; // used to protect the operation on db
|
||||
int32_t numOfReqs; // number of sqlObj bound to this connection
|
||||
|
@ -168,33 +177,15 @@ typedef struct SReqResultInfo {
|
|||
int32_t payloadLen;
|
||||
} SReqResultInfo;
|
||||
|
||||
typedef struct SShowReqInfo {
|
||||
int64_t execId; // showId/queryId
|
||||
int32_t vgId;
|
||||
SArray* pArray; // SArray<SVgroupInfo>
|
||||
int32_t currentIndex; // current accessed vgroup index.
|
||||
} SShowReqInfo;
|
||||
|
||||
typedef struct SRequestSendRecvBody {
|
||||
tsem_t rspSem; // not used now
|
||||
void* fp;
|
||||
SShowReqInfo showInfo; // todo this attribute will be removed after the query framework being completed.
|
||||
SDataBuf requestMsg;
|
||||
int64_t queryJob; // query job, created according to sql query DAG.
|
||||
struct SQueryPlan* pDag; // the query dag, generated according to the sql statement.
|
||||
SReqResultInfo resInfo;
|
||||
} SRequestSendRecvBody;
|
||||
|
||||
#define ERROR_MSG_BUF_DEFAULT_SIZE 512
|
||||
|
||||
enum {
|
||||
RES_TYPE__QUERY = 1,
|
||||
RES_TYPE__TMQ,
|
||||
};
|
||||
|
||||
#define TD_RES_QUERY(res) (*(int8_t*)res == RES_TYPE__QUERY)
|
||||
#define TD_RES_TMQ(res) (*(int8_t*)res == RES_TYPE__TMQ)
|
||||
|
||||
typedef struct {
|
||||
int8_t resType;
|
||||
char* topic;
|
||||
|
@ -208,13 +199,12 @@ typedef struct SRequestObj {
|
|||
uint64_t requestId;
|
||||
int32_t type; // request type
|
||||
STscObj* pTscObj;
|
||||
char* pDb;
|
||||
char* pDb; // current database string
|
||||
char* sqlstr; // sql string
|
||||
int32_t sqlLen;
|
||||
int64_t self;
|
||||
char* msgBuf;
|
||||
int32_t msgBufLen;
|
||||
void* pInfo; // sql parse info, generated by parser module
|
||||
int32_t code;
|
||||
SArray* dbList;
|
||||
SArray* tableList;
|
||||
|
@ -249,7 +239,7 @@ 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();
|
||||
int taos_init();
|
||||
|
||||
void* createTscObj(const char* user, const char* auth, const char* db, SAppInstInfo* pAppInfo);
|
||||
void destroyTscObj(void* pObj);
|
||||
|
@ -267,7 +257,6 @@ char* getDbOfConnection(STscObj* pObj);
|
|||
void setConnectionDB(STscObj* pTscObj, const char* db);
|
||||
void resetConnectDB(STscObj* pTscObj);
|
||||
|
||||
void taos_init_imp(void);
|
||||
int taos_options_imp(TSDB_OPTION option, const char* str);
|
||||
|
||||
void* openTransporter(const char* user, const char* auth, int32_t numOfThreads);
|
||||
|
@ -278,7 +267,7 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet);
|
|||
void initMsgHandleFp();
|
||||
|
||||
TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db,
|
||||
uint16_t port);
|
||||
uint16_t port, int connType);
|
||||
|
||||
int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtCallback* pStmtCb);
|
||||
|
||||
|
@ -286,11 +275,10 @@ int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArra
|
|||
|
||||
int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj** pRequest);
|
||||
|
||||
void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4);
|
||||
void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4);
|
||||
void doSetOneRowPtr(SReqResultInfo* pResultInfo);
|
||||
int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows,
|
||||
bool convertUcs4);
|
||||
void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t numOfCols);
|
||||
void setResPrecision(SReqResultInfo* pResInfo, int32_t precision);
|
||||
int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp, bool convertUcs4);
|
||||
|
||||
// --- heartbeat
|
||||
|
@ -304,7 +292,7 @@ SAppHbMgr* appHbMgrInit(SAppInstInfo* pAppInstInfo, char* key);
|
|||
void appHbMgrCleanup(void);
|
||||
|
||||
// conn level
|
||||
int hbRegisterConn(SAppHbMgr *pAppHbMgr, int64_t tscRefId, int64_t clusterId, int32_t hbType);
|
||||
int hbRegisterConn(SAppHbMgr *pAppHbMgr, int64_t tscRefId, int64_t clusterId, int8_t connType);
|
||||
void hbDeregisterConn(SAppHbMgr* pAppHbMgr, SClientHbKey connKey);
|
||||
|
||||
int hbAddConnInfo(SAppHbMgr* pAppHbMgr, SClientHbKey connKey, void* key, void* value, int32_t keyLen, int32_t valueLen);
|
||||
|
|
|
@ -27,13 +27,13 @@
|
|||
#include "ttime.h"
|
||||
|
||||
#define TSC_VAR_NOT_RELEASE 1
|
||||
#define TSC_VAR_RELEASED 0
|
||||
#define TSC_VAR_RELEASED 0
|
||||
|
||||
SAppInfo appInfo;
|
||||
int32_t clientReqRefPool = -1;
|
||||
int32_t clientReqRefPool = -1;
|
||||
int32_t clientConnRefPool = -1;
|
||||
|
||||
static TdThreadOnce tscinit = PTHREAD_ONCE_INIT;
|
||||
static TdThreadOnce tscinit = PTHREAD_ONCE_INIT;
|
||||
volatile int32_t tscInitRes = 0;
|
||||
|
||||
static void registerRequest(SRequestObj *pRequest) {
|
||||
|
@ -49,8 +49,8 @@ static void registerRequest(SRequestObj *pRequest) {
|
|||
if (pTscObj->pAppInfo) {
|
||||
SInstanceSummary *pSummary = &pTscObj->pAppInfo->summary;
|
||||
|
||||
int32_t total = atomic_add_fetch_64(&pSummary->totalRequests, 1);
|
||||
int32_t currentInst = atomic_add_fetch_64(&pSummary->currentRequests, 1);
|
||||
int32_t total = atomic_add_fetch_64((int64_t*)&pSummary->totalRequests, 1);
|
||||
int32_t currentInst = atomic_add_fetch_64((int64_t*)&pSummary->currentRequests, 1);
|
||||
tscDebug("0x%" PRIx64 " new Request from connObj:0x%" PRIx64
|
||||
", current:%d, app current:%d, total:%d, reqId:0x%" PRIx64,
|
||||
pRequest->self, pRequest->pTscObj->id, num, currentInst, total, pRequest->requestId);
|
||||
|
@ -63,7 +63,7 @@ static void deregisterRequest(SRequestObj *pRequest) {
|
|||
STscObj * pTscObj = pRequest->pTscObj;
|
||||
SInstanceSummary *pActivity = &pTscObj->pAppInfo->summary;
|
||||
|
||||
int32_t currentInst = atomic_sub_fetch_64(&pActivity->currentRequests, 1);
|
||||
int32_t currentInst = atomic_sub_fetch_64((int64_t*)&pActivity->currentRequests, 1);
|
||||
int32_t num = atomic_sub_fetch_32(&pTscObj->numOfReqs, 1);
|
||||
|
||||
int64_t duration = taosGetTimestampUs() - pRequest->metric.start;
|
||||
|
@ -122,7 +122,7 @@ void closeAllRequests(SHashObj *pRequests) {
|
|||
void destroyTscObj(void *pObj) {
|
||||
STscObj *pTscObj = pObj;
|
||||
|
||||
SClientHbKey connKey = {.tscRid = pTscObj->id, .hbType = pTscObj->connType};
|
||||
SClientHbKey connKey = {.tscRid = pTscObj->id, .connType = pTscObj->connType};
|
||||
hbDeregisterConn(pTscObj->pAppInfo->pAppHbMgr, connKey);
|
||||
atomic_sub_fetch_64(&pTscObj->pAppInfo->numOfConns, 1);
|
||||
closeAllRequests(pTscObj->pRequests);
|
||||
|
@ -220,7 +220,6 @@ static void doDestroyRequest(void *p) {
|
|||
|
||||
taosMemoryFreeClear(pRequest->msgBuf);
|
||||
taosMemoryFreeClear(pRequest->sqlstr);
|
||||
taosMemoryFreeClear(pRequest->pInfo);
|
||||
taosMemoryFreeClear(pRequest->pDb);
|
||||
|
||||
doFreeReqResultInfo(&pRequest->body.resInfo);
|
||||
|
@ -230,10 +229,6 @@ static void doDestroyRequest(void *p) {
|
|||
schedulerFreeJob(pRequest->body.queryJob);
|
||||
}
|
||||
|
||||
if (pRequest->body.showInfo.pArray != NULL) {
|
||||
taosArrayDestroy(pRequest->body.showInfo.pArray);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pRequest->tableList);
|
||||
taosArrayDestroy(pRequest->dbList);
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ static SClientHbMgr clientHbMgr = {0};
|
|||
static int32_t hbCreateThread();
|
||||
static void hbStopThread();
|
||||
|
||||
static int32_t hbMqHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req) { return 0; }
|
||||
|
||||
static int32_t hbMqHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) { return 0; }
|
||||
|
||||
static int32_t hbProcessDBInfoRsp(void *value, int32_t valueLen, struct SCatalog *pCatalog) {
|
||||
|
@ -108,7 +110,7 @@ static int32_t hbProcessStbInfoRsp(void *value, int32_t valueLen, struct SCatalo
|
|||
static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) {
|
||||
SHbConnInfo *info = taosHashGet(pAppHbMgr->connInfo, &pRsp->connKey, sizeof(SClientHbKey));
|
||||
if (NULL == info) {
|
||||
tscWarn("fail to get connInfo, may be dropped, refId:%" PRIx64 ", type:%d", pRsp->connKey.tscRid, pRsp->connKey.hbType);
|
||||
tscWarn("fail to get connInfo, may be dropped, refId:%" PRIx64 ", type:%d", pRsp->connKey.tscRid, pRsp->connKey.connType);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -222,7 +224,7 @@ static int32_t hbAsyncCallBack(void *param, const SDataBuf *pMsg, int32_t code)
|
|||
|
||||
for (int32_t i = 0; i < rspNum; ++i) {
|
||||
SClientHbRsp *rsp = taosArrayGet(pRsp.rsps, i);
|
||||
code = (*clientHbMgr.rspHandle[rsp->connKey.hbType])((*pInst)->pAppHbMgr, rsp);
|
||||
code = (*clientHbMgr.rspHandle[rsp->connKey.connType])((*pInst)->pAppHbMgr, rsp);
|
||||
if (code) {
|
||||
break;
|
||||
}
|
||||
|
@ -417,13 +419,12 @@ int32_t hbQueryHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t hbMqHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req) { return 0; }
|
||||
|
||||
void hbMgrInitMqHbHandle() {
|
||||
clientHbMgr.reqHandle[HEARTBEAT_TYPE_QUERY] = hbQueryHbReqHandle;
|
||||
clientHbMgr.reqHandle[HEARTBEAT_TYPE_MQ] = hbMqHbReqHandle;
|
||||
clientHbMgr.rspHandle[HEARTBEAT_TYPE_QUERY] = hbQueryHbRspHandle;
|
||||
clientHbMgr.rspHandle[HEARTBEAT_TYPE_MQ] = hbMqHbRspHandle;
|
||||
clientHbMgr.reqHandle[CONN_TYPE__QUERY] = hbQueryHbReqHandle;
|
||||
clientHbMgr.reqHandle[CONN_TYPE__TMQ] = hbMqHbReqHandle;
|
||||
|
||||
clientHbMgr.rspHandle[CONN_TYPE__QUERY] = hbQueryHbRspHandle;
|
||||
clientHbMgr.rspHandle[CONN_TYPE__TMQ] = hbMqHbRspHandle;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void hbMgrInitHandle() {
|
||||
|
@ -457,7 +458,7 @@ SClientHbBatchReq *hbGatherAllInfo(SAppHbMgr *pAppHbMgr) {
|
|||
|
||||
SHbConnInfo *info = taosHashGet(pAppHbMgr->connInfo, &pOneReq->connKey, sizeof(SClientHbKey));
|
||||
if (info) {
|
||||
code = (*clientHbMgr.reqHandle[pOneReq->connKey.hbType])(&pOneReq->connKey, info->param, pOneReq);
|
||||
code = (*clientHbMgr.reqHandle[pOneReq->connKey.connType])(&pOneReq->connKey, info->param, pOneReq);
|
||||
if (code) {
|
||||
pIter = taosHashIterate(pAppHbMgr->activeInfo, pIter);
|
||||
continue;
|
||||
|
@ -564,7 +565,7 @@ static int32_t hbCreateThread() {
|
|||
if (taosThreadCreate(&clientHbMgr.thread, &thAttr, hbThreadFunc, NULL) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
taosThreadAttrDestroy(&thAttr);
|
||||
return 0;
|
||||
}
|
||||
|
@ -648,13 +649,13 @@ int hbMgrInit() {
|
|||
hbMgrInitHandle();
|
||||
|
||||
// init backgroud thread
|
||||
hbCreateThread();
|
||||
//hbCreateThread();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hbMgrCleanUp() {
|
||||
hbStopThread();
|
||||
//hbStopThread();
|
||||
|
||||
// destroy all appHbMgr
|
||||
int8_t old = atomic_val_compare_exchange_8(&clientHbMgr.inited, 1, 0);
|
||||
|
@ -691,29 +692,27 @@ int hbRegisterConnImpl(SAppHbMgr *pAppHbMgr, SClientHbKey connKey, SHbConnInfo *
|
|||
return 0;
|
||||
}
|
||||
|
||||
int hbRegisterConn(SAppHbMgr *pAppHbMgr, int64_t tscRefId, int64_t clusterId, int32_t hbType) {
|
||||
int hbRegisterConn(SAppHbMgr *pAppHbMgr, int64_t tscRefId, int64_t clusterId, int8_t connType) {
|
||||
SClientHbKey connKey = {
|
||||
.tscRid = tscRefId,
|
||||
.hbType = HEARTBEAT_TYPE_QUERY,
|
||||
.connType = connType,
|
||||
};
|
||||
SHbConnInfo info = {0};
|
||||
|
||||
switch (hbType) {
|
||||
case HEARTBEAT_TYPE_QUERY: {
|
||||
switch (connType) {
|
||||
case CONN_TYPE__QUERY: {
|
||||
int64_t *pClusterId = taosMemoryMalloc(sizeof(int64_t));
|
||||
*pClusterId = clusterId;
|
||||
|
||||
info.param = pClusterId;
|
||||
break;
|
||||
return hbRegisterConnImpl(pAppHbMgr, connKey, &info);
|
||||
}
|
||||
case HEARTBEAT_TYPE_MQ: {
|
||||
break;
|
||||
case CONN_TYPE__TMQ: {
|
||||
return 0;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return hbRegisterConnImpl(pAppHbMgr, connKey, &info);
|
||||
}
|
||||
|
||||
void hbDeregisterConn(SAppHbMgr *pAppHbMgr, SClientHbKey connKey) {
|
||||
|
|
|
@ -1,3 +1,17 @@
|
|||
/*
|
||||
* 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 "clientInt.h"
|
||||
#include "clientLog.h"
|
||||
|
@ -11,7 +25,7 @@
|
|||
#include "tref.h"
|
||||
|
||||
static int32_t initEpSetFromCfg(const char* firstEp, const char* secondEp, SCorEpSet* pEpSet);
|
||||
static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest);
|
||||
static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest, int8_t connType);
|
||||
static void destroySendMsgInfo(SMsgSendInfo* pMsgBody);
|
||||
|
||||
static bool stringLengthCheck(const char* str, size_t maxsize) {
|
||||
|
@ -40,10 +54,10 @@ static char* getClusterKey(const char* user, const char* auth, const char* ip, i
|
|||
}
|
||||
|
||||
static STscObj* taosConnectImpl(const char* user, const char* auth, const char* db, __taos_async_fn_t fp, void* param,
|
||||
SAppInstInfo* pAppInfo);
|
||||
SAppInstInfo* pAppInfo, int connType);
|
||||
|
||||
TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db,
|
||||
uint16_t port) {
|
||||
uint16_t port, int connType) {
|
||||
if (taos_init() != TSDB_CODE_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -111,7 +125,7 @@ TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass,
|
|||
taosThreadMutexUnlock(&appInfo.mutex);
|
||||
|
||||
taosMemoryFreeClear(key);
|
||||
return taosConnectImpl(user, &secretEncrypt[0], localDb, NULL, NULL, *pInst);
|
||||
return taosConnectImpl(user, &secretEncrypt[0], localDb, NULL, NULL, *pInst, connType);
|
||||
}
|
||||
|
||||
int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj** pRequest) {
|
||||
|
@ -169,6 +183,7 @@ int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtC
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if ((*pQuery)->haveResultSet) {
|
||||
setResSchemaInfo(&pRequest->body.resInfo, (*pQuery)->pResSchema, (*pQuery)->numOfResCols);
|
||||
setResPrecision(&pRequest->body.resInfo, (*pQuery)->precision);
|
||||
}
|
||||
|
||||
TSWAP(pRequest->dbList, (*pQuery)->pDbList, SArray*);
|
||||
|
@ -201,13 +216,6 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) {
|
|||
STscObj* pTscObj = pRequest->pTscObj;
|
||||
SMsgSendInfo* pSendMsg = buildMsgInfoImpl(pRequest);
|
||||
|
||||
if (pMsgInfo->msgType == TDMT_VND_SHOW_TABLES) {
|
||||
SShowReqInfo* pShowReqInfo = &pRequest->body.showInfo;
|
||||
if (pShowReqInfo->pArray == NULL) {
|
||||
pShowReqInfo->currentIndex = 0; // set the first vnode/ then iterate the next vnode
|
||||
pShowReqInfo->pArray = pMsgInfo->pExtension;
|
||||
}
|
||||
}
|
||||
int64_t transporterId = 0;
|
||||
asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &pMsgInfo->epSet, &transporterId, pSendMsg);
|
||||
|
||||
|
@ -230,7 +238,7 @@ int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArra
|
|||
}
|
||||
|
||||
void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t numOfCols) {
|
||||
assert(pSchema != NULL && numOfCols > 0);
|
||||
ASSERT(pSchema != NULL && numOfCols > 0);
|
||||
|
||||
pResInfo->numOfCols = numOfCols;
|
||||
pResInfo->fields = taosMemoryCalloc(numOfCols, sizeof(TAOS_FIELD));
|
||||
|
@ -254,6 +262,14 @@ void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t
|
|||
}
|
||||
}
|
||||
|
||||
void setResPrecision(SReqResultInfo* pResInfo, int32_t precision) {
|
||||
if (precision != TSDB_TIME_PRECISION_MILLI && precision != TSDB_TIME_PRECISION_MICRO && precision != TSDB_TIME_PRECISION_NANO) {
|
||||
return;
|
||||
}
|
||||
|
||||
pResInfo->precision = precision;
|
||||
}
|
||||
|
||||
int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList) {
|
||||
void* pTransporter = pRequest->pTscObj->pAppInfo->pTransporter;
|
||||
|
||||
|
@ -442,7 +458,7 @@ int initEpSetFromCfg(const char* firstEp, const char* secondEp, SCorEpSet* pEpSe
|
|||
}
|
||||
|
||||
STscObj* taosConnectImpl(const char* user, const char* auth, const char* db, __taos_async_fn_t fp, void* param,
|
||||
SAppInstInfo* pAppInfo) {
|
||||
SAppInstInfo* pAppInfo, int connType) {
|
||||
STscObj* pTscObj = createTscObj(user, auth, db, pAppInfo);
|
||||
if (NULL == pTscObj) {
|
||||
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
|
@ -456,7 +472,7 @@ STscObj* taosConnectImpl(const char* user, const char* auth, const char* db, __t
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SMsgSendInfo* body = buildConnectMsg(pRequest);
|
||||
SMsgSendInfo* body = buildConnectMsg(pRequest, connType);
|
||||
|
||||
int64_t transporterId = 0;
|
||||
asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &transporterId, body);
|
||||
|
@ -479,7 +495,7 @@ STscObj* taosConnectImpl(const char* user, const char* auth, const char* db, __t
|
|||
return pTscObj;
|
||||
}
|
||||
|
||||
static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest) {
|
||||
static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest, int8_t connType) {
|
||||
SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
|
||||
if (pMsgSendInfo == NULL) {
|
||||
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
|
@ -502,6 +518,7 @@ static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest) {
|
|||
}
|
||||
taosMemoryFreeClear(db);
|
||||
|
||||
connectReq.connType = connType;
|
||||
connectReq.pid = htonl(appInfo.pid);
|
||||
connectReq.startTime = htobe64(appInfo.startTime);
|
||||
tstrncpy(connectReq.app, appInfo.appName, sizeof(connectReq.app));
|
||||
|
@ -587,7 +604,7 @@ TAOS* taos_connect_auth(const char* ip, const char* user, const char* auth, cons
|
|||
return NULL;
|
||||
}
|
||||
|
||||
return taos_connect_internal(ip, user, NULL, auth, db, port);
|
||||
return taos_connect_internal(ip, user, NULL, auth, db, port, CONN_TYPE__QUERY);
|
||||
}
|
||||
|
||||
TAOS* taos_connect_l(const char* ip, int ipLen, const char* user, int userLen, const char* pass, int passLen,
|
||||
|
@ -619,113 +636,52 @@ void doSetOneRowPtr(SReqResultInfo* pResultInfo) {
|
|||
pResultInfo->row[i] = varDataVal(pStart);
|
||||
} else {
|
||||
pResultInfo->row[i] = NULL;
|
||||
pResultInfo->length[i] = 0;
|
||||
}
|
||||
} else {
|
||||
if (!colDataIsNull_f(pCol->nullbitmap, pResultInfo->current)) {
|
||||
pResultInfo->row[i] = pResultInfo->pCol[i].pData + bytes * pResultInfo->current;
|
||||
pResultInfo->length[i] = bytes;
|
||||
} else {
|
||||
pResultInfo->row[i] = NULL;
|
||||
pResultInfo->length[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4) {
|
||||
void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4) {
|
||||
assert(pRequest != NULL);
|
||||
|
||||
SReqResultInfo* pResultInfo = &pRequest->body.resInfo;
|
||||
|
||||
SEpSet epSet = {0};
|
||||
|
||||
if (pResultInfo->pData == NULL || pResultInfo->current >= pResultInfo->numOfRows) {
|
||||
if (pRequest->type == TDMT_VND_QUERY) {
|
||||
// All data has returned to App already, no need to try again
|
||||
if (pResultInfo->completed) {
|
||||
pResultInfo->numOfRows = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SReqResultInfo* pResInfo = &pRequest->body.resInfo;
|
||||
pRequest->code = schedulerFetchRows(pRequest->body.queryJob, (void**)&pResInfo->pData);
|
||||
if (pRequest->code != TSDB_CODE_SUCCESS) {
|
||||
pResultInfo->numOfRows = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pRequest->code = setQueryResultFromRsp(&pRequest->body.resInfo, (SRetrieveTableRsp*)pResInfo->pData, convertUcs4);
|
||||
if (pRequest->code != TSDB_CODE_SUCCESS) {
|
||||
pResultInfo->numOfRows = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tscDebug("0x%" PRIx64 " fetch results, numOfRows:%d total Rows:%" PRId64 ", complete:%d, reqId:0x%" PRIx64,
|
||||
pRequest->self, pResInfo->numOfRows, pResInfo->totalRows, pResInfo->completed, pRequest->requestId);
|
||||
|
||||
if (pResultInfo->numOfRows == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
goto _return;
|
||||
} else if (pRequest->type == TDMT_MND_SHOW) {
|
||||
pRequest->type = TDMT_MND_SHOW_RETRIEVE;
|
||||
epSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp);
|
||||
} else if (pRequest->type == TDMT_VND_SHOW_TABLES) {
|
||||
pRequest->type = TDMT_VND_SHOW_TABLES_FETCH;
|
||||
SShowReqInfo* pShowReqInfo = &pRequest->body.showInfo;
|
||||
SVgroupInfo* pVgroupInfo = taosArrayGet(pShowReqInfo->pArray, pShowReqInfo->currentIndex);
|
||||
|
||||
epSet = pVgroupInfo->epSet;
|
||||
} else if (pRequest->type == TDMT_VND_SHOW_TABLES_FETCH) {
|
||||
pRequest->type = TDMT_VND_SHOW_TABLES;
|
||||
SShowReqInfo* pShowReqInfo = &pRequest->body.showInfo;
|
||||
pShowReqInfo->currentIndex += 1;
|
||||
if (pShowReqInfo->currentIndex >= taosArrayGetSize(pShowReqInfo->pArray)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SVgroupInfo* pVgroupInfo = taosArrayGet(pShowReqInfo->pArray, pShowReqInfo->currentIndex);
|
||||
SVShowTablesReq* pShowReq = taosMemoryCalloc(1, sizeof(SVShowTablesReq));
|
||||
pShowReq->head.vgId = htonl(pVgroupInfo->vgId);
|
||||
|
||||
pRequest->body.requestMsg.len = sizeof(SVShowTablesReq);
|
||||
pRequest->body.requestMsg.pData = pShowReq;
|
||||
|
||||
SMsgSendInfo* body = buildMsgInfoImpl(pRequest);
|
||||
epSet = pVgroupInfo->epSet;
|
||||
|
||||
int64_t transporterId = 0;
|
||||
STscObj* pTscObj = pRequest->pTscObj;
|
||||
asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, body);
|
||||
tsem_wait(&pRequest->body.rspSem);
|
||||
|
||||
pRequest->type = TDMT_VND_SHOW_TABLES_FETCH;
|
||||
} else if (pRequest->type == TDMT_MND_SHOW_RETRIEVE) {
|
||||
epSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp);
|
||||
|
||||
if (pResultInfo->completed) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// All data has returned to App already, no need to try again
|
||||
if (pResultInfo->completed) {
|
||||
pResultInfo->numOfRows = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SMsgSendInfo* body = buildMsgInfoImpl(pRequest);
|
||||
SReqResultInfo* pResInfo = &pRequest->body.resInfo;
|
||||
pRequest->code = schedulerFetchRows(pRequest->body.queryJob, (void**)&pResInfo->pData);
|
||||
if (pRequest->code != TSDB_CODE_SUCCESS) {
|
||||
pResultInfo->numOfRows = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int64_t transporterId = 0;
|
||||
STscObj* pTscObj = pRequest->pTscObj;
|
||||
asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, body);
|
||||
pRequest->code = setQueryResultFromRsp(&pRequest->body.resInfo, (SRetrieveTableRsp*)pResInfo->pData, convertUcs4);
|
||||
if (pRequest->code != TSDB_CODE_SUCCESS) {
|
||||
pResultInfo->numOfRows = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tsem_wait(&pRequest->body.rspSem);
|
||||
tscDebug("0x%" PRIx64 " fetch results, numOfRows:%d total Rows:%" PRId64 ", complete:%d, reqId:0x%" PRIx64,
|
||||
pRequest->self, pResInfo->numOfRows, pResInfo->totalRows, pResInfo->completed, pRequest->requestId);
|
||||
|
||||
pResultInfo->current = 0;
|
||||
if (pResultInfo->numOfRows <= pResultInfo->current) {
|
||||
if (pResultInfo->numOfRows == 0) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
_return:
|
||||
if (setupOneRowPtr) {
|
||||
doSetOneRowPtr(pResultInfo);
|
||||
pResultInfo->current += 1;
|
||||
|
|
|
@ -90,7 +90,7 @@ TAOS *taos_connect(const char *ip, const char *user, const char *pass, const cha
|
|||
pass = TSDB_DEFAULT_PASS;
|
||||
}
|
||||
|
||||
return taos_connect_internal(ip, user, pass, NULL, db, port);
|
||||
return taos_connect_internal(ip, user, pass, NULL, db, port, CONN_TYPE__QUERY);
|
||||
}
|
||||
|
||||
void taos_close(TAOS *taos) {
|
||||
|
@ -131,8 +131,10 @@ void taos_free_result(TAOS_RES *res) {
|
|||
return;
|
||||
}
|
||||
|
||||
SRequestObj *pRequest = (SRequestObj *)res;
|
||||
destroyRequest(pRequest);
|
||||
if (TD_RES_QUERY(res)) {
|
||||
SRequestObj *pRequest = (SRequestObj *)res;
|
||||
destroyRequest(pRequest);
|
||||
}
|
||||
}
|
||||
|
||||
int taos_field_count(TAOS_RES *res) {
|
||||
|
@ -175,26 +177,30 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
return doFetchRow(pRequest, true, true);
|
||||
return doFetchRows(pRequest, true, true);
|
||||
|
||||
} else if (TD_RES_TMQ(res)) {
|
||||
SMqRspObj *msg = ((SMqRspObj *)res);
|
||||
SMqRspObj *msg = ((SMqRspObj *)res);
|
||||
if (msg->resIter == -1) msg->resIter++;
|
||||
SReqResultInfo *pResultInfo = taosArrayGet(msg->res, msg->resIter);
|
||||
|
||||
doSetOneRowPtr(pResultInfo);
|
||||
pResultInfo->current += 1;
|
||||
|
||||
if (pResultInfo->row == NULL) {
|
||||
msg->resIter++;
|
||||
pResultInfo = taosArrayGet(msg->res, msg->resIter);
|
||||
if (pResultInfo->current < pResultInfo->numOfRows) {
|
||||
doSetOneRowPtr(pResultInfo);
|
||||
pResultInfo->current += 1;
|
||||
return pResultInfo->row;
|
||||
} else {
|
||||
msg->resIter++;
|
||||
if (msg->resIter < taosArrayGetSize(msg->res)) {
|
||||
pResultInfo = taosArrayGet(msg->res, msg->resIter);
|
||||
doSetOneRowPtr(pResultInfo);
|
||||
pResultInfo->current += 1;
|
||||
return pResultInfo->row;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return pResultInfo->row;
|
||||
|
||||
} else {
|
||||
// assert to avoid uninitialization error
|
||||
// assert to avoid un-initialization error
|
||||
ASSERT(0);
|
||||
}
|
||||
return NULL;
|
||||
|
@ -356,6 +362,7 @@ int taos_result_precision(TAOS_RES *res) {
|
|||
if (res == NULL) {
|
||||
return TSDB_TIME_PRECISION_MILLI;
|
||||
}
|
||||
|
||||
if (TD_RES_QUERY(res)) {
|
||||
SRequestObj *pRequest = (SRequestObj *)res;
|
||||
return pRequest->body.resInfo.precision;
|
||||
|
@ -411,7 +418,11 @@ bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col) {
|
|||
}
|
||||
|
||||
SResultColumn *pCol = &pResultInfo->pCol[col];
|
||||
return colDataIsNull_f(pCol->nullbitmap, row);
|
||||
if (IS_VAR_DATA_TYPE(pResultInfo->fields[col].type)) {
|
||||
return (pCol->offset[row] == -1);
|
||||
} else {
|
||||
return colDataIsNull_f(pCol->nullbitmap, row);
|
||||
}
|
||||
}
|
||||
|
||||
bool taos_is_update_query(TAOS_RES *res) { return taos_num_fields(res) == 0; }
|
||||
|
@ -437,7 +448,7 @@ int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
doFetchRow(pRequest, false, true);
|
||||
doFetchRows(pRequest, false, true);
|
||||
|
||||
// TODO refactor
|
||||
SReqResultInfo *pResultInfo = &pRequest->body.resInfo;
|
||||
|
@ -464,37 +475,36 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) {
|
|||
if (res == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (TD_RES_QUERY(res)) {
|
||||
SRequestObj *pRequest = (SRequestObj *)res;
|
||||
|
||||
if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT ||
|
||||
pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) {
|
||||
if (TD_RES_TMQ(res)) {
|
||||
SReqResultInfo *pResultInfo = tmqGetNextResInfo(res);
|
||||
if (pResultInfo == NULL) {
|
||||
(*numOfRows) = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
doFetchRow(pRequest, false, true);
|
||||
|
||||
SReqResultInfo *pResultInfo = &pRequest->body.resInfo;
|
||||
|
||||
pResultInfo->current = pResultInfo->numOfRows;
|
||||
(*numOfRows) = pResultInfo->numOfRows;
|
||||
(*pData) = (void *)pResultInfo->pData;
|
||||
|
||||
return 0;
|
||||
|
||||
} else if (TD_RES_TMQ(res)) {
|
||||
SReqResultInfo *pResultInfo = tmqGetNextResInfo(res);
|
||||
if (pResultInfo == NULL) return -1;
|
||||
|
||||
pResultInfo->current = pResultInfo->numOfRows;
|
||||
(*numOfRows) = pResultInfo->numOfRows;
|
||||
(*pData) = (void *)pResultInfo->pData;
|
||||
return 0;
|
||||
|
||||
} else {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
SRequestObj *pRequest = (SRequestObj *)res;
|
||||
|
||||
if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT ||
|
||||
pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
doFetchRows(pRequest, false, false);
|
||||
|
||||
SReqResultInfo *pResultInfo = &pRequest->body.resInfo;
|
||||
|
||||
pResultInfo->current = pResultInfo->numOfRows;
|
||||
(*numOfRows) = pResultInfo->numOfRows;
|
||||
(*pData) = (void *)pResultInfo->pData;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int *taos_get_column_data_offset(TAOS_RES *res, int columnIndex) {
|
||||
|
|
|
@ -69,9 +69,9 @@ int32_t processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
pTscObj->pAppInfo->clusterId = connectRsp.clusterId;
|
||||
atomic_add_fetch_64(&pTscObj->pAppInfo->numOfConns, 1);
|
||||
|
||||
pTscObj->connType = HEARTBEAT_TYPE_QUERY;
|
||||
pTscObj->connType = connectRsp.connType;
|
||||
|
||||
hbRegisterConn(pTscObj->pAppInfo->pAppHbMgr, pTscObj->id, connectRsp.clusterId, HEARTBEAT_TYPE_QUERY);
|
||||
hbRegisterConn(pTscObj->pAppInfo->pAppHbMgr, pTscObj->id, connectRsp.clusterId, connectRsp.connType);
|
||||
|
||||
// pRequest->body.resInfo.pRspMsg = pMsg->pData;
|
||||
tscDebug("0x%" PRIx64 " clusterId:%" PRId64 ", totalConn:%" PRId64, pRequest->requestId, connectRsp.clusterId,
|
||||
|
@ -90,150 +90,13 @@ SMsgSendInfo* buildMsgInfoImpl(SRequestObj *pRequest) {
|
|||
pMsgSendInfo->param = pRequest;
|
||||
pMsgSendInfo->msgType = pRequest->type;
|
||||
|
||||
if (pRequest->type == TDMT_MND_SHOW_RETRIEVE || pRequest->type == TDMT_VND_SHOW_TABLES_FETCH) {
|
||||
if (pRequest->type == TDMT_MND_SHOW_RETRIEVE) {
|
||||
SRetrieveTableReq retrieveReq = {0};
|
||||
retrieveReq.showId = pRequest->body.showInfo.execId;
|
||||
|
||||
int32_t contLen = tSerializeSRetrieveTableReq(NULL, 0, &retrieveReq);
|
||||
void* pReq = taosMemoryMalloc(contLen);
|
||||
tSerializeSRetrieveTableReq(pReq, contLen, &retrieveReq);
|
||||
pMsgSendInfo->msgInfo.pData = pReq;
|
||||
pMsgSendInfo->msgInfo.len = contLen;
|
||||
pMsgSendInfo->msgInfo.handle = NULL;
|
||||
} else {
|
||||
SVShowTablesFetchReq* pFetchMsg = taosMemoryCalloc(1, sizeof(SVShowTablesFetchReq));
|
||||
if (pFetchMsg == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pFetchMsg->id = htobe64(pRequest->body.showInfo.execId);
|
||||
pFetchMsg->head.vgId = htonl(pRequest->body.showInfo.vgId);
|
||||
|
||||
pMsgSendInfo->msgInfo.pData = pFetchMsg;
|
||||
pMsgSendInfo->msgInfo.len = sizeof(SVShowTablesFetchReq);
|
||||
pMsgSendInfo->msgInfo.handle = NULL;
|
||||
}
|
||||
} else {
|
||||
assert(pRequest != NULL);
|
||||
pMsgSendInfo->msgInfo = pRequest->body.requestMsg;
|
||||
}
|
||||
assert(pRequest != NULL);
|
||||
pMsgSendInfo->msgInfo = pRequest->body.requestMsg;
|
||||
|
||||
pMsgSendInfo->fp = (handleRequestRspFp[TMSG_INDEX(pRequest->type)] == NULL)? genericRspCallback:handleRequestRspFp[TMSG_INDEX(pRequest->type)];
|
||||
return pMsgSendInfo;
|
||||
}
|
||||
|
||||
int32_t processShowRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||
SRequestObj* pRequest = param;
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
setErrno(pRequest, code);
|
||||
tsem_post(&pRequest->body.rspSem);
|
||||
return code;
|
||||
}
|
||||
|
||||
SShowRsp showRsp = {0};
|
||||
tDeserializeSShowRsp(pMsg->pData, pMsg->len, &showRsp);
|
||||
STableMetaRsp *pMetaMsg = &showRsp.tableMeta;
|
||||
|
||||
taosMemoryFreeClear(pRequest->body.resInfo.pRspMsg);
|
||||
pRequest->body.resInfo.pRspMsg = pMsg->pData;
|
||||
SReqResultInfo* pResInfo = &pRequest->body.resInfo;
|
||||
|
||||
if (pResInfo->fields == NULL) {
|
||||
TAOS_FIELD* pFields = taosMemoryCalloc(pMetaMsg->numOfColumns, sizeof(TAOS_FIELD));
|
||||
for (int32_t i = 0; i < pMetaMsg->numOfColumns; ++i) {
|
||||
SSchema* pSchema = &pMetaMsg->pSchemas[i];
|
||||
tstrncpy(pFields[i].name, pSchema->name, tListLen(pFields[i].name));
|
||||
pFields[i].type = pSchema->type;
|
||||
pFields[i].bytes = pSchema->bytes;
|
||||
}
|
||||
|
||||
pResInfo->fields = pFields;
|
||||
}
|
||||
|
||||
pResInfo->numOfCols = pMetaMsg->numOfColumns;
|
||||
pRequest->body.showInfo.execId = showRsp.showId;
|
||||
tFreeSShowRsp(&showRsp);
|
||||
|
||||
// todo
|
||||
if (pRequest->type == TDMT_VND_SHOW_TABLES) {
|
||||
SShowReqInfo* pShowInfo = &pRequest->body.showInfo;
|
||||
|
||||
int32_t index = pShowInfo->currentIndex;
|
||||
SVgroupInfo* pInfo = taosArrayGet(pShowInfo->pArray, index);
|
||||
pShowInfo->vgId = pInfo->vgId;
|
||||
}
|
||||
|
||||
tsem_post(&pRequest->body.rspSem);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t processRetrieveMnodeRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||
SRequestObj *pRequest = param;
|
||||
SReqResultInfo *pResInfo = &pRequest->body.resInfo;
|
||||
taosMemoryFreeClear(pResInfo->pRspMsg);
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
setErrno(pRequest, code);
|
||||
tsem_post(&pRequest->body.rspSem);
|
||||
return code;
|
||||
}
|
||||
|
||||
assert(pMsg->len >= sizeof(SRetrieveTableRsp));
|
||||
|
||||
SRetrieveTableRsp *pRetrieve = (SRetrieveTableRsp *) pMsg->pData;
|
||||
pRetrieve->numOfRows = htonl(pRetrieve->numOfRows);
|
||||
pRetrieve->precision = htons(pRetrieve->precision);
|
||||
|
||||
pResInfo->pRspMsg = pMsg->pData;
|
||||
pResInfo->numOfRows = pRetrieve->numOfRows;
|
||||
pResInfo->pData = pRetrieve->data;
|
||||
pResInfo->completed = pRetrieve->completed;
|
||||
|
||||
pResInfo->current = 0;
|
||||
// setResultDataPtr(pResInfo, pResInfo->fields, pResInfo->numOfCols, pResInfo->numOfRows);
|
||||
|
||||
tscDebug("0x%"PRIx64" numOfRows:%d, complete:%d, qId:0x%"PRIx64, pRequest->self, pRetrieve->numOfRows,
|
||||
pRetrieve->completed, pRequest->body.showInfo.execId);
|
||||
|
||||
tsem_post(&pRequest->body.rspSem);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t processRetrieveVndRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||
SRequestObj* pRequest = param;
|
||||
|
||||
SReqResultInfo* pResInfo = &pRequest->body.resInfo;
|
||||
taosMemoryFreeClear(pResInfo->pRspMsg);
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
setErrno(pRequest, code);
|
||||
tsem_post(&pRequest->body.rspSem);
|
||||
return code;
|
||||
}
|
||||
|
||||
assert(pMsg->len >= sizeof(SRetrieveTableRsp));
|
||||
|
||||
pResInfo->pRspMsg = pMsg->pData;
|
||||
|
||||
SVShowTablesFetchRsp *pFetchRsp = (SVShowTablesFetchRsp *) pMsg->pData;
|
||||
pFetchRsp->numOfRows = htonl(pFetchRsp->numOfRows);
|
||||
pFetchRsp->precision = htons(pFetchRsp->precision);
|
||||
|
||||
pResInfo->pRspMsg = pMsg->pData;
|
||||
pResInfo->numOfRows = pFetchRsp->numOfRows;
|
||||
pResInfo->pData = pFetchRsp->data;
|
||||
|
||||
pResInfo->current = 0;
|
||||
// setResultDataPtr(pResInfo, pResInfo->fields, pResInfo->numOfCols, pResInfo->numOfRows);
|
||||
|
||||
tscDebug("0x%"PRIx64" numOfRows:%d, complete:%d, qId:0x%"PRIx64, pRequest->self, pFetchRsp->numOfRows,
|
||||
pFetchRsp->completed, pRequest->body.showInfo.execId);
|
||||
|
||||
tsem_post(&pRequest->body.rspSem);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t processCreateDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||
// todo rsp with the vnode id list
|
||||
SRequestObj* pRequest = param;
|
||||
|
@ -254,15 +117,16 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
struct SCatalog *pCatalog = NULL;
|
||||
|
||||
if (usedbRsp.vgVersion >= 0) {
|
||||
int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tscWarn("catalogGetHandle failed, clusterId:%"PRIx64", error:%s", pRequest->pTscObj->pAppInfo->clusterId, tstrerror(code));
|
||||
int32_t code1 = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
|
||||
if (code1 != TSDB_CODE_SUCCESS) {
|
||||
tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pRequest->pTscObj->pAppInfo->clusterId,
|
||||
tstrerror(code1));
|
||||
} else {
|
||||
catalogRemoveDB(pCatalog, usedbRsp.db, usedbRsp.uid);
|
||||
}
|
||||
}
|
||||
|
||||
tFreeSUsedbRsp(&usedbRsp);
|
||||
tFreeSUsedbRsp(&usedbRsp);
|
||||
}
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -276,7 +140,7 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp);
|
||||
|
||||
SName name = {0};
|
||||
tNameFromString(&name, usedbRsp.db, T_NAME_ACCT|T_NAME_DB);
|
||||
tNameFromString(&name, usedbRsp.db, T_NAME_ACCT | T_NAME_DB);
|
||||
|
||||
SUseDbOutput output = {0};
|
||||
code = queryBuildUseDbOutput(&output, &usedbRsp);
|
||||
|
@ -288,11 +152,12 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
|
||||
tscError("failed to build use db output since %s", terrstr());
|
||||
} else {
|
||||
struct SCatalog *pCatalog = NULL;
|
||||
|
||||
int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tscWarn("catalogGetHandle failed, clusterId:%"PRIx64", error:%s", pRequest->pTscObj->pAppInfo->clusterId, tstrerror(code));
|
||||
struct SCatalog* pCatalog = NULL;
|
||||
|
||||
int32_t code1 = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
|
||||
if (code1 != TSDB_CODE_SUCCESS) {
|
||||
tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pRequest->pTscObj->pAppInfo->clusterId,
|
||||
tstrerror(code1));
|
||||
} else {
|
||||
catalogUpdateDBVgInfo(pCatalog, output.db, output.dbId, output.dbVgroup);
|
||||
}
|
||||
|
@ -344,89 +209,9 @@ int32_t processDropDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
}
|
||||
|
||||
void initMsgHandleFp() {
|
||||
#if 0
|
||||
tscBuildMsg[TSDB_SQL_SELECT] = tscBuildQueryMsg;
|
||||
tscBuildMsg[TSDB_SQL_INSERT] = tscBuildSubmitMsg;
|
||||
tscBuildMsg[TSDB_SQL_FETCH] = tscBuildFetchMsg;
|
||||
|
||||
tscBuildMsg[TSDB_SQL_CREATE_DB] = tscBuildCreateDbMsg;
|
||||
tscBuildMsg[TSDB_SQL_CREATE_USER] = tscBuildUserMsg;
|
||||
tscBuildMsg[TSDB_SQL_CREATE_FUNCTION] = tscBuildCreateFuncMsg;
|
||||
|
||||
tscBuildMsg[TSDB_SQL_CREATE_ACCT] = tscBuildAcctMsg;
|
||||
tscBuildMsg[TSDB_SQL_ALTER_ACCT] = tscBuildAcctMsg;
|
||||
|
||||
tscBuildMsg[TSDB_SQL_CREATE_TABLE] = tscBuildCreateTableMsg;
|
||||
tscBuildMsg[TSDB_SQL_DROP_USER] = tscBuildDropUserAcctMsg;
|
||||
tscBuildMsg[TSDB_SQL_DROP_ACCT] = tscBuildDropUserAcctMsg;
|
||||
tscBuildMsg[TSDB_SQL_DROP_DB] = tscBuildDropDbMsg;
|
||||
tscBuildMsg[TSDB_SQL_DROP_FUNCTION] = tscBuildDropFuncMsg;
|
||||
tscBuildMsg[TSDB_SQL_SYNC_DB_REPLICA] = tscBuildSyncDbReplicaMsg;
|
||||
tscBuildMsg[TSDB_SQL_DROP_TABLE] = tscBuildDropTableMsg;
|
||||
tscBuildMsg[TSDB_SQL_ALTER_USER] = tscBuildUserMsg;
|
||||
tscBuildMsg[TSDB_SQL_CREATE_DNODE] = tscBuildCreateDnodeMsg;
|
||||
tscBuildMsg[TSDB_SQL_DROP_DNODE] = tscBuildDropDnodeMsg;
|
||||
tscBuildMsg[TSDB_SQL_CFG_DNODE] = tscBuildCfgDnodeMsg;
|
||||
tscBuildMsg[TSDB_SQL_ALTER_TABLE] = tscBuildAlterTableMsg;
|
||||
tscBuildMsg[TSDB_SQL_UPDATE_TAG_VAL] = tscBuildUpdateTagMsg;
|
||||
tscBuildMsg[TSDB_SQL_ALTER_DB] = tscAlterDbMsg;
|
||||
tscBuildMsg[TSDB_SQL_COMPACT_VNODE] = tscBuildCompactMsg;
|
||||
|
||||
|
||||
tscBuildMsg[TSDB_SQL_USE_DB] = tscBuildUseDbMsg;
|
||||
tscBuildMsg[TSDB_SQL_STABLEVGROUP] = tscBuildSTableVgroupMsg;
|
||||
tscBuildMsg[TSDB_SQL_RETRIEVE_FUNC] = tscBuildRetrieveFuncMsg;
|
||||
|
||||
tscBuildMsg[TSDB_SQL_HB] = tscBuildHeartBeatMsg;
|
||||
tscBuildMsg[TSDB_SQL_SHOW] = tscBuildShowMsg;
|
||||
tscBuildMsg[TSDB_SQL_RETRIEVE_MNODE] = tscBuildRetrieveFromMgmtMsg;
|
||||
tscBuildMsg[TSDB_SQL_KILL_QUERY] = tscBuildKillMsg;
|
||||
tscBuildMsg[TSDB_SQL_KILL_STREAM] = tscBuildKillMsg;
|
||||
tscBuildMsg[TSDB_SQL_KILL_CONNECTION] = tscBuildKillMsg;
|
||||
|
||||
tscProcessMsgRsp[TSDB_SQL_SELECT] = tscProcessQueryRsp;
|
||||
tscProcessMsgRsp[TSDB_SQL_FETCH] = tscProcessRetrieveRspFromNode;
|
||||
|
||||
tscProcessMsgRsp[TSDB_SQL_DROP_DB] = tscProcessDropDbRsp;
|
||||
tscProcessMsgRsp[TSDB_SQL_DROP_TABLE] = tscProcessDropTableRsp;
|
||||
|
||||
tscProcessMsgRsp[TSDB_SQL_USE_DB] = tscProcessUseDbRsp;
|
||||
tscProcessMsgRsp[TSDB_SQL_META] = tscProcessTableMetaRsp;
|
||||
tscProcessMsgRsp[TSDB_SQL_STABLEVGROUP] = tscProcessSTableVgroupRsp;
|
||||
tscProcessMsgRsp[TSDB_SQL_MULTI_META] = tscProcessMultiTableMetaRsp;
|
||||
tscProcessMsgRsp[TSDB_SQL_RETRIEVE_FUNC] = tscProcessRetrieveFuncRsp;
|
||||
|
||||
tscProcessMsgRsp[TSDB_SQL_SHOW] = tscProcessShowRsp;
|
||||
tscProcessMsgRsp[TSDB_SQL_RETRIEVE_MNODE] = tscProcessRetrieveRspFromNode; // rsp handled by same function.
|
||||
tscProcessMsgRsp[TSDB_SQL_DESCRIBE_TABLE] = tscProcessDescribeTableRsp;
|
||||
|
||||
tscProcessMsgRsp[TSDB_SQL_CURRENT_DB] = tscProcessLocalRetrieveRsp;
|
||||
tscProcessMsgRsp[TSDB_SQL_CURRENT_USER] = tscProcessLocalRetrieveRsp;
|
||||
tscProcessMsgRsp[TSDB_SQL_SERV_VERSION] = tscProcessLocalRetrieveRsp;
|
||||
tscProcessMsgRsp[TSDB_SQL_CLI_VERSION] = tscProcessLocalRetrieveRsp;
|
||||
tscProcessMsgRsp[TSDB_SQL_SERV_STATUS] = tscProcessLocalRetrieveRsp;
|
||||
|
||||
tscProcessMsgRsp[TSDB_SQL_RETRIEVE_EMPTY_RESULT] = tscProcessEmptyResultRsp;
|
||||
|
||||
tscProcessMsgRsp[TSDB_SQL_RETRIEVE_GLOBALMERGE] = tscProcessRetrieveGlobalMergeRsp;
|
||||
|
||||
tscProcessMsgRsp[TSDB_SQL_ALTER_TABLE] = tscProcessAlterTableMsgRsp;
|
||||
tscProcessMsgRsp[TSDB_SQL_ALTER_DB] = tscProcessAlterDbMsgRsp;
|
||||
tscProcessMsgRsp[TSDB_SQL_COMPACT_VNODE] = tscProcessCompactRsp;
|
||||
|
||||
tscProcessMsgRsp[TSDB_SQL_SHOW_CREATE_TABLE] = tscProcessShowCreateRsp;
|
||||
tscProcessMsgRsp[TSDB_SQL_SHOW_CREATE_STABLE] = tscProcessShowCreateRsp;
|
||||
tscProcessMsgRsp[TSDB_SQL_SHOW_CREATE_DATABASE] = tscProcessShowCreateRsp;
|
||||
#endif
|
||||
|
||||
handleRequestRspFp[TMSG_INDEX(TDMT_MND_CONNECT)] = processConnectRsp;
|
||||
handleRequestRspFp[TMSG_INDEX(TDMT_MND_SHOW)] = processShowRsp;
|
||||
handleRequestRspFp[TMSG_INDEX(TDMT_MND_SHOW_RETRIEVE)] = processRetrieveMnodeRsp;
|
||||
handleRequestRspFp[TMSG_INDEX(TDMT_MND_CREATE_DB)] = processCreateDbRsp;
|
||||
handleRequestRspFp[TMSG_INDEX(TDMT_MND_USE_DB)] = processUseDbRsp;
|
||||
handleRequestRspFp[TMSG_INDEX(TDMT_MND_CREATE_STB)] = processCreateTableRsp;
|
||||
handleRequestRspFp[TMSG_INDEX(TDMT_MND_DROP_DB)] = processDropDbRsp;
|
||||
|
||||
handleRequestRspFp[TMSG_INDEX(TDMT_VND_SHOW_TABLES)] = processShowRsp;
|
||||
handleRequestRspFp[TMSG_INDEX(TDMT_VND_SHOW_TABLES_FETCH)] = processRetrieveVndRsp;
|
||||
handleRequestRspFp[TMSG_INDEX(TDMT_MND_CONNECT)] = processConnectRsp;
|
||||
handleRequestRspFp[TMSG_INDEX(TDMT_MND_CREATE_DB)] = processCreateDbRsp;
|
||||
handleRequestRspFp[TMSG_INDEX(TDMT_MND_USE_DB)] = processUseDbRsp;
|
||||
handleRequestRspFp[TMSG_INDEX(TDMT_MND_CREATE_STB)] = processCreateTableRsp;
|
||||
handleRequestRspFp[TMSG_INDEX(TDMT_MND_DROP_DB)] = processDropDbRsp;
|
||||
}
|
||||
|
|
|
@ -119,14 +119,14 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
// subscribe info
|
||||
int32_t sqlLen;
|
||||
char* sql;
|
||||
char* topicName;
|
||||
int64_t topicId;
|
||||
SArray* vgs; // SArray<SMqClientVg>
|
||||
int8_t isSchemaAdaptive;
|
||||
int32_t numOfFields;
|
||||
TAOS_FIELD* fields;
|
||||
int32_t sqlLen;
|
||||
char* sql;
|
||||
char* topicName;
|
||||
int64_t topicId;
|
||||
SArray* vgs; // SArray<SMqClientVg>
|
||||
int8_t isSchemaAdaptive;
|
||||
int32_t numOfFields;
|
||||
SSchemaWrapper schema;
|
||||
} SMqClientTopic;
|
||||
|
||||
typedef struct {
|
||||
|
@ -357,7 +357,15 @@ tmq_t* tmq_consumer_new1(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
|
|||
if (pTmq == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
pTmq->pTscObj = taos_connect(conf->ip, conf->user, conf->pass, conf->db, conf->port);
|
||||
const char* user = conf->user == NULL ? TSDB_DEFAULT_USER : conf->user;
|
||||
const char* pass = conf->pass == NULL ? TSDB_DEFAULT_PASS : conf->pass;
|
||||
|
||||
ASSERT(user);
|
||||
ASSERT(pass);
|
||||
ASSERT(conf->db);
|
||||
|
||||
pTmq->pTscObj = taos_connect_internal(conf->ip, user, pass, NULL, conf->db, conf->port, CONN_TYPE__TMQ);
|
||||
if (pTmq->pTscObj == NULL) return NULL;
|
||||
|
||||
pTmq->inWaiting = 0;
|
||||
pTmq->status = 0;
|
||||
|
@ -783,7 +791,7 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) {
|
|||
}
|
||||
}
|
||||
|
||||
struct tm* ptm = localtime(&tt);
|
||||
struct tm* ptm = taosLocalTime(&tt, NULL);
|
||||
size_t pos = strftime(buf, 35, "%Y-%m-%d %H:%M:%S", ptm);
|
||||
|
||||
if (precision == TSDB_TIME_PRECISION_NANO) {
|
||||
|
@ -956,6 +964,7 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) {
|
|||
for (int32_t i = 0; i < topicNumGet; i++) {
|
||||
SMqClientTopic topic = {0};
|
||||
SMqSubTopicEp* pTopicEp = taosArrayGet(pRsp->topics, i);
|
||||
topic.schema = pTopicEp->schema;
|
||||
taosHashClear(pHash);
|
||||
topic.topicName = strdup(pTopicEp->topic);
|
||||
|
||||
|
@ -1191,7 +1200,10 @@ SMqRspObj* tmqBuildRspFromWrapper(SMqPollRspWrapper* pWrapper) {
|
|||
for (int32_t i = 0; i < blockNum; i++) {
|
||||
int32_t pos = *(int32_t*)taosArrayGet(pRsp->blockPos, i);
|
||||
SRetrieveTableRsp* pRetrieve = POINTER_SHIFT(pRsp->blockData, pos);
|
||||
SReqResultInfo resInfo;
|
||||
SReqResultInfo resInfo = {0};
|
||||
resInfo.totalRows = 0;
|
||||
resInfo.precision = TSDB_TIME_PRECISION_MILLI;
|
||||
setResSchemaInfo(&resInfo, pWrapper->topicHandle->schema.pSchema, pWrapper->topicHandle->schema.nCols);
|
||||
setQueryResultFromRsp(&resInfo, pRetrieve, true);
|
||||
taosArrayPush(pRspObj->res, &resInfo);
|
||||
}
|
||||
|
@ -1386,7 +1398,7 @@ SMqRspObj* tmqHandleAllRsp(tmq_t* tmq, int64_t blockingTime, bool pollIfReset) {
|
|||
rspWrapper = NULL;
|
||||
continue;
|
||||
}
|
||||
// build msg
|
||||
// build rsp
|
||||
SMqRspObj* pRsp = tmqBuildRspFromWrapper(pollRspWrapper);
|
||||
return pRsp;
|
||||
} else {
|
||||
|
|
|
@ -8,13 +8,13 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
|
|||
ADD_EXECUTABLE(clientTest clientTests.cpp)
|
||||
TARGET_LINK_LIBRARIES(
|
||||
clientTest
|
||||
PUBLIC os util common transport parser catalog scheduler function gtest taos qcom
|
||||
PUBLIC os util common transport parser catalog scheduler function gtest taos_static qcom
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(tmqTest tmqTest.cpp)
|
||||
TARGET_LINK_LIBRARIES(
|
||||
tmqTest
|
||||
PUBLIC os util common transport parser catalog scheduler function gtest taos qcom
|
||||
PUBLIC os util common transport parser catalog scheduler function gtest taos_static qcom
|
||||
)
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(
|
||||
|
|
|
@ -459,11 +459,10 @@ TEST(testCase, create_multiple_tables) {
|
|||
|
||||
taos_free_result(pRes);
|
||||
|
||||
for (int32_t i = 0; i < 25000; ++i) {
|
||||
for (int32_t i = 0; i < 500; i += 2) {
|
||||
char sql[512] = {0};
|
||||
snprintf(sql, tListLen(sql),
|
||||
"create table t_x_%d using st1 tags(2) t_x_%d using st1 tags(5) t_x_%d using st1 tags(911)", i,
|
||||
(i + 1) * 30, (i + 2) * 40);
|
||||
"create table t_x_%d using st1 tags(2) t_x_%d using st1 tags(5)", i, i + 1);
|
||||
TAOS_RES* pres = taos_query(pConn, sql);
|
||||
if (taos_errno(pres) != 0) {
|
||||
printf("failed to create table %d\n, reason:%s", i, taos_errstr(pres));
|
||||
|
@ -653,6 +652,7 @@ TEST(testCase, projection_query_stables) {
|
|||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
TEST(testCase, agg_query_tables) {
|
||||
|
@ -662,7 +662,7 @@ TEST(testCase, agg_query_tables) {
|
|||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "select length('abc') from tu");
|
||||
pRes = taos_query(pConn, "select count(*) from tu");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to select from table, reason:%s\n", taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
|
@ -673,10 +673,18 @@ TEST(testCase, agg_query_tables) {
|
|||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
|
||||
int32_t n = 0;
|
||||
char str[512] = {0};
|
||||
while ((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
int32_t* length = taos_fetch_lengths(pRes);
|
||||
for(int32_t i = 0; i < numOfFields; ++i) {
|
||||
printf("(%d):%d " , i, length[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
printf("%s\n", str);
|
||||
memset(str, 0, sizeof(str));
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
|
|
|
@ -1149,10 +1149,11 @@ void* blockDataDestroy(SSDataBlock* pBlock) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock) {
|
||||
SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData) {
|
||||
if(pDataBlock == NULL){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t numOfCols = pDataBlock->info.numOfCols;
|
||||
|
||||
SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||
|
@ -1160,6 +1161,7 @@ SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock) {
|
|||
|
||||
pBlock->info.numOfCols = numOfCols;
|
||||
pBlock->info.hasVarCol = pDataBlock->info.hasVarCol;
|
||||
pBlock->info.rowSize = pDataBlock->info.rows;
|
||||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData colInfo = {0};
|
||||
|
@ -1168,6 +1170,23 @@ SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock) {
|
|||
taosArrayPush(pBlock->pDataBlock, &colInfo);
|
||||
}
|
||||
|
||||
if (copyData) {
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, i);
|
||||
SColumnInfoData* pSrc = taosArrayGet(pDataBlock->pDataBlock, i);
|
||||
|
||||
int32_t code = colInfoDataEnsureCapacity(pDst, pDataBlock->info.rows);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
colDataAssign(pDst, pSrc, pDataBlock->info.rows);
|
||||
}
|
||||
|
||||
pBlock->info.rows = pDataBlock->info.rows;
|
||||
pBlock->info.capacity = pDataBlock->info.rows;
|
||||
}
|
||||
|
||||
return pBlock;
|
||||
}
|
||||
|
||||
|
@ -1368,7 +1387,7 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) {
|
|||
}
|
||||
}
|
||||
|
||||
struct tm* ptm = localtime(&tt);
|
||||
struct tm* ptm = taosLocalTime(&tt, NULL);
|
||||
size_t pos = strftime(buf, 35, "%Y-%m-%d %H:%M:%S", ptm);
|
||||
|
||||
if (precision == TSDB_TIME_PRECISION_NANO) {
|
||||
|
|
|
@ -189,7 +189,7 @@ static int32_t taosSetTfsCfg(SConfig *pCfg) {
|
|||
tsDiskCfgNum = 1;
|
||||
taosAddDataDir(0, pItem->str, 0, 1);
|
||||
tstrncpy(tsDataDir, pItem->str, PATH_MAX);
|
||||
if (taosMkDir(tsDataDir) != 0) {
|
||||
if (taosMulMkDir(tsDataDir) != 0) {
|
||||
uError("failed to create dataDir:%s since %s", tsDataDir, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
@ -200,12 +200,12 @@ static int32_t taosSetTfsCfg(SConfig *pCfg) {
|
|||
memcpy(&tsDiskCfg[index], pCfg, sizeof(SDiskCfg));
|
||||
if (pCfg->level == 0 && pCfg->primary == 1) {
|
||||
tstrncpy(tsDataDir, pCfg->dir, PATH_MAX);
|
||||
if (taosMkDir(tsDataDir) != 0) {
|
||||
if (taosMulMkDir(tsDataDir) != 0) {
|
||||
uError("failed to create dataDir:%s since %s", tsDataDir, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (taosMkDir(pCfg->dir) != 0) {
|
||||
if (taosMulMkDir(pCfg->dir) != 0) {
|
||||
uError("failed to create tfsDir:%s since %s", tsDataDir, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
@ -486,7 +486,7 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
|
|||
tstrncpy(tsTempDir, cfgGetItem(pCfg, "tempDir")->str, PATH_MAX);
|
||||
taosExpandDir(tsTempDir, tsTempDir, PATH_MAX);
|
||||
tsTempSpace.reserved = cfgGetItem(pCfg, "minimalTempDirGB")->fval;
|
||||
if (taosMkDir(tsTempDir) != 0) {
|
||||
if (taosMulMkDir(tsTempDir) != 0) {
|
||||
uError("failed to create tempDir:%s since %s", tsTempDir, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
@ -495,7 +495,7 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
|
|||
tsRpcTimer = cfgGetItem(pCfg, "rpcTimer")->i32;
|
||||
tsRpcMaxTime = cfgGetItem(pCfg, "rpcMaxTime")->i32;
|
||||
tsRpcForceTcp = cfgGetItem(pCfg, "rpcForceTcp")->i32;
|
||||
tsShellActivityTimer = cfgGetItem(pCfg, "shellActivityTimer")->bval;
|
||||
tsShellActivityTimer = cfgGetItem(pCfg, "shellActivityTimer")->i32;
|
||||
tsCompressMsgSize = cfgGetItem(pCfg, "compressMsgSize")->i32;
|
||||
tsCompressColData = cfgGetItem(pCfg, "compressColData")->i32;
|
||||
tsMaxWildCardsLen = cfgGetItem(pCfg, "maxWildCardsLength")->i32;
|
||||
|
|
|
@ -134,7 +134,7 @@ void *taosDecodeSEpSet(void *buf, SEpSet *pEp) {
|
|||
static int32_t tSerializeSClientHbReq(SCoder *pEncoder, const SClientHbReq *pReq) {
|
||||
if (tEncodeSClientHbKey(pEncoder, &pReq->connKey) < 0) return -1;
|
||||
|
||||
if (pReq->connKey.hbType == HEARTBEAT_TYPE_QUERY) {
|
||||
if (pReq->connKey.connType == CONN_TYPE__QUERY) {
|
||||
int32_t queryNum = 0;
|
||||
if (pReq->query) {
|
||||
queryNum = 1;
|
||||
|
@ -185,7 +185,7 @@ static int32_t tSerializeSClientHbReq(SCoder *pEncoder, const SClientHbReq *pReq
|
|||
static int32_t tDeserializeSClientHbReq(SCoder *pDecoder, SClientHbReq *pReq) {
|
||||
if (tDecodeSClientHbKey(pDecoder, &pReq->connKey) < 0) return -1;
|
||||
|
||||
if (pReq->connKey.hbType == HEARTBEAT_TYPE_QUERY) {
|
||||
if (pReq->connKey.connType == CONN_TYPE__QUERY) {
|
||||
int32_t queryNum = 0;
|
||||
if (tDecodeI32(pDecoder, &queryNum) < 0) return -1;
|
||||
if (queryNum) {
|
||||
|
@ -981,7 +981,7 @@ int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) {
|
|||
|
||||
// status
|
||||
if (tEncodeI32(&encoder, pReq->sver) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pReq->dver) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pReq->dnodeVer) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->dnodeId) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pReq->clusterId) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pReq->rebootTime) < 0) return -1;
|
||||
|
@ -1026,7 +1026,7 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) {
|
|||
|
||||
// status
|
||||
if (tDecodeI32(&decoder, &pReq->sver) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pReq->dver) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pReq->dnodeVer) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->dnodeId) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pReq->clusterId) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pReq->rebootTime) < 0) return -1;
|
||||
|
@ -1071,6 +1071,8 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void tFreeSStatusReq(SStatusReq *pReq) { taosArrayDestroy(pReq->pVloads); }
|
||||
|
||||
int32_t tSerializeSStatusRsp(void *buf, int32_t bufLen, SStatusRsp *pRsp) {
|
||||
SCoder encoder = {0};
|
||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
||||
|
@ -1078,7 +1080,7 @@ int32_t tSerializeSStatusRsp(void *buf, int32_t bufLen, SStatusRsp *pRsp) {
|
|||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
|
||||
// status
|
||||
if (tEncodeI64(&encoder, pRsp->dver) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pRsp->dnodeVer) < 0) return -1;
|
||||
|
||||
// dnode cfg
|
||||
if (tEncodeI32(&encoder, pRsp->dnodeCfg.dnodeId) < 0) return -1;
|
||||
|
@ -1109,7 +1111,7 @@ int32_t tDeserializeSStatusRsp(void *buf, int32_t bufLen, SStatusRsp *pRsp) {
|
|||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
|
||||
// status
|
||||
if (tDecodeI64(&decoder, &pRsp->dver) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pRsp->dnodeVer) < 0) return -1;
|
||||
|
||||
// cluster cfg
|
||||
if (tDecodeI32(&decoder, &pRsp->dnodeCfg.dnodeId) < 0) return -1;
|
||||
|
@ -2293,7 +2295,6 @@ int32_t tSerializeSRetrieveTableReq(void *buf, int32_t bufLen, SRetrieveTableReq
|
|||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pReq->showId) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->type) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pReq->free) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->db) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->tb) < 0) return -1;
|
||||
tEndEncode(&encoder);
|
||||
|
@ -2310,7 +2311,6 @@ int32_t tDeserializeSRetrieveTableReq(void *buf, int32_t bufLen, SRetrieveTableR
|
|||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pReq->showId) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->type) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &pReq->free) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pReq->tb) < 0) return -1;
|
||||
tEndDecode(&decoder);
|
||||
|
@ -2643,6 +2643,7 @@ int32_t tSerializeSConnectReq(void *buf, int32_t bufLen, SConnectReq *pReq) {
|
|||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pReq->connType) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->pid) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->app) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->db) < 0) return -1;
|
||||
|
@ -2659,6 +2660,7 @@ int32_t tDeserializeSConnectReq(void *buf, int32_t bufLen, SConnectReq *pReq) {
|
|||
tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &pReq->connType) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->pid) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pReq->app) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1;
|
||||
|
@ -2678,6 +2680,7 @@ int32_t tSerializeSConnectRsp(void *buf, int32_t bufLen, SConnectRsp *pRsp) {
|
|||
if (tEncodeI64(&encoder, pRsp->clusterId) < 0) return -1;
|
||||
if (tEncodeU32(&encoder, pRsp->connId) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pRsp->superUser) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pRsp->connType) < 0) return -1;
|
||||
if (tEncodeSEpSet(&encoder, &pRsp->epSet) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pRsp->sVersion) < 0) return -1;
|
||||
tEndEncode(&encoder);
|
||||
|
@ -2696,6 +2699,7 @@ int32_t tDeserializeSConnectRsp(void *buf, int32_t bufLen, SConnectRsp *pRsp) {
|
|||
if (tDecodeI64(&decoder, &pRsp->clusterId) < 0) return -1;
|
||||
if (tDecodeU32(&decoder, &pRsp->connId) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &pRsp->superUser) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &pRsp->connType) < 0) return -1;
|
||||
if (tDecodeSEpSet(&decoder, &pRsp->epSet) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pRsp->sVersion) < 0) return -1;
|
||||
tEndDecode(&decoder);
|
||||
|
@ -3377,6 +3381,8 @@ int32_t tSerializeSCMCreateStreamReq(void *buf, int32_t bufLen, const SCMCreateS
|
|||
if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, sqlLen) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, astLen) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pReq->triggerType) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pReq->watermark) < 0) return -1;
|
||||
if (sqlLen > 0 && tEncodeCStr(&encoder, pReq->sql) < 0) return -1;
|
||||
if (astLen > 0 && tEncodeCStr(&encoder, pReq->ast) < 0) return -1;
|
||||
|
||||
|
@ -3400,6 +3406,8 @@ int32_t tDeserializeSCMCreateStreamReq(void *buf, int32_t bufLen, SCMCreateStrea
|
|||
if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &sqlLen) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &astLen) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &pReq->triggerType) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pReq->watermark) < 0) return -1;
|
||||
|
||||
if (sqlLen > 0) {
|
||||
pReq->sql = taosMemoryCalloc(1, sqlLen + 1);
|
||||
|
|
|
@ -70,7 +70,7 @@ void deltaToUtcInitOnce() {
|
|||
struct tm tm = {0};
|
||||
|
||||
(void)taosStrpTime("1970-01-01 00:00:00", (const char*)("%Y-%m-%d %H:%M:%S"), &tm);
|
||||
m_deltaUtc = (int64_t)mktime(&tm);
|
||||
m_deltaUtc = (int64_t)taosMktime(&tm);
|
||||
// printf("====delta:%lld\n\n", seconds);
|
||||
}
|
||||
|
||||
|
@ -344,7 +344,7 @@ int32_t parseLocaltimeDst(char* timestr, int64_t* time, int32_t timePrec) {
|
|||
}
|
||||
|
||||
/* mktime will be affected by TZ, set by using taos_options */
|
||||
int64_t seconds = mktime(&tm);
|
||||
int64_t seconds = taosMktime(&tm);
|
||||
|
||||
int64_t fraction = 0;
|
||||
|
||||
|
@ -539,7 +539,7 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) {
|
|||
tm.tm_year = mon / 12;
|
||||
tm.tm_mon = mon % 12;
|
||||
|
||||
return (int64_t)(mktime(&tm) * TSDB_TICK_PER_SECOND(precision));
|
||||
return (int64_t)(taosMktime(&tm) * TSDB_TICK_PER_SECOND(precision));
|
||||
}
|
||||
|
||||
int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char unit, int32_t precision) {
|
||||
|
@ -598,7 +598,7 @@ int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precisio
|
|||
tm.tm_mon = mon % 12;
|
||||
}
|
||||
|
||||
start = (int64_t)(mktime(&tm) * TSDB_TICK_PER_SECOND(precision));
|
||||
start = (int64_t)(taosMktime(&tm) * TSDB_TICK_PER_SECOND(precision));
|
||||
} else {
|
||||
int64_t delta = t - pInterval->interval;
|
||||
int32_t factor = (delta >= 0) ? 1 : -1;
|
||||
|
@ -745,7 +745,7 @@ void taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precision)
|
|||
assert(false);
|
||||
}
|
||||
|
||||
ptm = localtime(");
|
||||
ptm = taosLocalTime(", NULL);
|
||||
int32_t length = (int32_t)strftime(ts, 40, "%Y-%m-%dT%H:%M:%S", ptm);
|
||||
length += snprintf(ts + length, fractionLen, format, mod);
|
||||
length += (int32_t)strftime(ts + length, 40 - length, "%z", ptm);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "ttypes.h"
|
||||
#include "tcompression.h"
|
||||
#include "trow.h"
|
||||
|
||||
const int32_t TYPE_BYTES[15] = {
|
||||
-1, // TSDB_DATA_TYPE_NULL
|
||||
|
@ -49,7 +50,7 @@ const int32_t TYPE_BYTES[15] = {
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
static void getStatics_bool(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_bool(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
int8_t *data = (int8_t *)pData;
|
||||
*min = INT64_MAX;
|
||||
|
@ -60,7 +61,8 @@ static void getStatics_bool(const void *pData, int32_t numOfRow, int64_t *min, i
|
|||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (data[i] == TSDB_DATA_BOOL_NULL) {
|
||||
// if (data[i] == TSDB_DATA_BOOL_NULL) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -69,7 +71,7 @@ static void getStatics_bool(const void *pData, int32_t numOfRow, int64_t *min, i
|
|||
}
|
||||
}
|
||||
|
||||
static void getStatics_i8(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_i8(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
int8_t *data = (int8_t *)pData;
|
||||
*min = INT64_MAX;
|
||||
|
@ -80,7 +82,8 @@ static void getStatics_i8(const void *pData, int32_t numOfRow, int64_t *min, int
|
|||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (((uint8_t)data[i]) == TSDB_DATA_TINYINT_NULL) {
|
||||
// if (((uint8_t)data[i]) == TSDB_DATA_TINYINT_NULL) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -89,7 +92,7 @@ static void getStatics_i8(const void *pData, int32_t numOfRow, int64_t *min, int
|
|||
}
|
||||
}
|
||||
|
||||
static void getStatics_u8(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_u8(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
uint8_t *data = (uint8_t *)pData;
|
||||
uint64_t _min = UINT64_MAX;
|
||||
|
@ -102,7 +105,8 @@ static void getStatics_u8(const void *pData, int32_t numOfRow, int64_t *min, int
|
|||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (((uint8_t)data[i]) == TSDB_DATA_UTINYINT_NULL) {
|
||||
// if (((uint8_t)data[i]) == TSDB_DATA_UTINYINT_NULL) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -115,7 +119,7 @@ static void getStatics_u8(const void *pData, int32_t numOfRow, int64_t *min, int
|
|||
*sum = _sum;
|
||||
}
|
||||
|
||||
static void getStatics_i16(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_i16(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
int16_t *data = (int16_t *)pData;
|
||||
*min = INT64_MAX;
|
||||
|
@ -126,7 +130,8 @@ static void getStatics_i16(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (((uint16_t)data[i]) == TSDB_DATA_SMALLINT_NULL) {
|
||||
// if (((uint16_t)data[i]) == TSDB_DATA_SMALLINT_NULL) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -135,7 +140,7 @@ static void getStatics_i16(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
}
|
||||
}
|
||||
|
||||
static void getStatics_u16(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_u16(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
uint16_t *data = (uint16_t *)pData;
|
||||
uint64_t _min = UINT64_MAX;
|
||||
|
@ -148,7 +153,8 @@ static void getStatics_u16(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (((uint16_t)data[i]) == TSDB_DATA_USMALLINT_NULL) {
|
||||
// if (((uint16_t)data[i]) == TSDB_DATA_USMALLINT_NULL) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -161,7 +167,7 @@ static void getStatics_u16(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
*sum = _sum;
|
||||
}
|
||||
|
||||
static void getStatics_i32(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_i32(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
int32_t *data = (int32_t *)pData;
|
||||
*min = INT64_MAX;
|
||||
|
@ -172,7 +178,8 @@ static void getStatics_i32(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (((uint32_t)data[i]) == TSDB_DATA_INT_NULL) {
|
||||
// if (((uint32_t)data[i]) == TSDB_DATA_INT_NULL) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -181,7 +188,7 @@ static void getStatics_i32(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
}
|
||||
}
|
||||
|
||||
static void getStatics_u32(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_u32(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
uint32_t *data = (uint32_t *)pData;
|
||||
uint64_t _min = UINT64_MAX;
|
||||
|
@ -194,7 +201,8 @@ static void getStatics_u32(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (((uint32_t)data[i]) == TSDB_DATA_UINT_NULL) {
|
||||
// if (((uint32_t)data[i]) == TSDB_DATA_UINT_NULL) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -207,7 +215,7 @@ static void getStatics_u32(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
*sum = _sum;
|
||||
}
|
||||
|
||||
static void getStatics_i64(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_i64(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
int64_t *data = (int64_t *)pData;
|
||||
*min = INT64_MAX;
|
||||
|
@ -218,7 +226,8 @@ static void getStatics_i64(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (((uint64_t)data[i]) == TSDB_DATA_BIGINT_NULL) {
|
||||
// if (((uint64_t)data[i]) == TSDB_DATA_BIGINT_NULL) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -227,7 +236,7 @@ static void getStatics_i64(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
}
|
||||
}
|
||||
|
||||
static void getStatics_u64(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_u64(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
uint64_t *data = (uint64_t *)pData;
|
||||
uint64_t _min = UINT64_MAX;
|
||||
|
@ -240,7 +249,8 @@ static void getStatics_u64(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (((uint64_t)data[i]) == TSDB_DATA_UBIGINT_NULL) {
|
||||
// if (((uint64_t)data[i]) == TSDB_DATA_UBIGINT_NULL) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -253,7 +263,7 @@ static void getStatics_u64(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
*sum = _sum;
|
||||
}
|
||||
|
||||
static void getStatics_f(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_f(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
float *data = (float *)pData;
|
||||
float fmin = FLT_MAX;
|
||||
|
@ -265,7 +275,8 @@ static void getStatics_f(const void *pData, int32_t numOfRow, int64_t *min, int6
|
|||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if ((*(uint32_t *)&(data[i])) == TSDB_DATA_FLOAT_NULL) {
|
||||
// if ((*(uint32_t *)&(data[i])) == TSDB_DATA_FLOAT_NULL) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -289,7 +300,7 @@ static void getStatics_f(const void *pData, int32_t numOfRow, int64_t *min, int6
|
|||
SET_DOUBLE_VAL(min, fmin);
|
||||
}
|
||||
|
||||
static void getStatics_d(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_d(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
double *data = (double *)pData;
|
||||
double dmin = DBL_MAX;
|
||||
|
@ -301,7 +312,8 @@ static void getStatics_d(const void *pData, int32_t numOfRow, int64_t *min, int6
|
|||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if ((*(uint64_t *)&(data[i])) == TSDB_DATA_DOUBLE_NULL) {
|
||||
// if ((*(uint64_t *)&(data[i])) == TSDB_DATA_DOUBLE_NULL) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -325,13 +337,14 @@ static void getStatics_d(const void *pData, int32_t numOfRow, int64_t *min, int6
|
|||
SET_DOUBLE_PTR(min, &dmin);
|
||||
}
|
||||
|
||||
static void getStatics_bin(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_bin(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
const char *data = pData;
|
||||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (isNull(data, TSDB_DATA_TYPE_BINARY)) {
|
||||
// if (isNull(data, TSDB_DATA_TYPE_BINARY)) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
}
|
||||
|
||||
|
@ -345,13 +358,14 @@ static void getStatics_bin(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
*maxIndex = 0;
|
||||
}
|
||||
|
||||
static void getStatics_nchr(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_nchr(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
const char *data = pData;
|
||||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (isNull(data, TSDB_DATA_TYPE_NCHAR)) {
|
||||
// if (isNull(data, TSDB_DATA_TYPE_NCHAR)) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
}
|
||||
|
||||
|
@ -377,7 +391,7 @@ tDataTypeDescriptor tDataTypes[15] = {
|
|||
getStatics_i64},
|
||||
{TSDB_DATA_TYPE_FLOAT, 5, FLOAT_BYTES, "FLOAT", 0, 0, tsCompressFloat, tsDecompressFloat, getStatics_f},
|
||||
{TSDB_DATA_TYPE_DOUBLE, 6, DOUBLE_BYTES, "DOUBLE", 0, 0, tsCompressDouble, tsDecompressDouble, getStatics_d},
|
||||
{TSDB_DATA_TYPE_BINARY, 6, 0, "BINARY", 0, 0, tsCompressString, tsDecompressString, getStatics_bin},
|
||||
{TSDB_DATA_TYPE_VARCHAR, 6, 0, "VARCHAR", 0, 0, tsCompressString, tsDecompressString, getStatics_bin},
|
||||
{TSDB_DATA_TYPE_TIMESTAMP, 9, LONG_BYTES, "TIMESTAMP", INT64_MIN, INT64_MAX, tsCompressTimestamp,
|
||||
tsDecompressTimestamp, getStatics_i64},
|
||||
{TSDB_DATA_TYPE_NCHAR, 5, 8, "NCHAR", 0, 0, tsCompressString, tsDecompressString, getStatics_nchr},
|
||||
|
@ -402,7 +416,7 @@ char tTokenTypeSwitcher[13] = {
|
|||
TSDB_DATA_TYPE_DOUBLE, // TK_DOUBLE
|
||||
TSDB_DATA_TYPE_BINARY, // TK_STRING
|
||||
TSDB_DATA_TYPE_BIGINT, // TK_TIMESTAMP
|
||||
TSDB_DATA_TYPE_BINARY, // TK_BINARY
|
||||
TSDB_DATA_TYPE_VARCHAR, // TK_BINARY
|
||||
TSDB_DATA_TYPE_NCHAR, // TK_NCHAR
|
||||
};
|
||||
|
||||
|
|
|
@ -1,36 +1,16 @@
|
|||
aux_source_directory(dm DNODE_SRC)
|
||||
aux_source_directory(qm DNODE_SRC)
|
||||
aux_source_directory(bm DNODE_SRC)
|
||||
aux_source_directory(sm DNODE_SRC)
|
||||
aux_source_directory(vm DNODE_SRC)
|
||||
aux_source_directory(mm DNODE_SRC)
|
||||
aux_source_directory(main DNODE_SRC)
|
||||
add_library(dnode STATIC ${DNODE_SRC})
|
||||
target_link_libraries(
|
||||
dnode cjson mnode vnode qnode snode bnode wal sync taos tfs monitor
|
||||
)
|
||||
target_include_directories(
|
||||
dnode
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/dnode/mgmt"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
add_subdirectory(interface)
|
||||
add_subdirectory(implement)
|
||||
add_subdirectory(mgmt_bnode)
|
||||
add_subdirectory(mgmt_mnode)
|
||||
add_subdirectory(mgmt_qnode)
|
||||
add_subdirectory(mgmt_snode)
|
||||
add_subdirectory(mgmt_vnode)
|
||||
add_subdirectory(test)
|
||||
|
||||
aux_source_directory(exe EXEC_SRC)
|
||||
add_executable(taosd ${EXEC_SRC})
|
||||
target_include_directories(
|
||||
taosd
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/implement/inc"
|
||||
)
|
||||
target_link_libraries(taosd dnode)
|
||||
|
||||
IF (TD_GRANT)
|
||||
TARGET_LINK_LIBRARIES(taosd grant)
|
||||
ENDIF ()
|
||||
IF (TD_USB_DONGLE)
|
||||
TARGET_LINK_LIBRARIES(taosd usb_dongle)
|
||||
else()
|
||||
ENDIF ()
|
||||
|
||||
if(${BUILD_TEST})
|
||||
add_subdirectory(test)
|
||||
endif(${BUILD_TEST})
|
||||
|
|
|
@ -1,216 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http:www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dmInt.h"
|
||||
|
||||
void dmSendStatusReq(SDnodeMgmt *pMgmt) {
|
||||
SDnode *pDnode = pMgmt->pDnode;
|
||||
SStatusReq req = {0};
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
req.sver = tsVersion;
|
||||
req.dver = pMgmt->dver;
|
||||
req.dnodeId = pDnode->dnodeId;
|
||||
req.clusterId = pDnode->clusterId;
|
||||
req.rebootTime = pDnode->rebootTime;
|
||||
req.updateTime = pMgmt->updateTime;
|
||||
req.numOfCores = tsNumOfCores;
|
||||
req.numOfSupportVnodes = pDnode->numOfSupportVnodes;
|
||||
tstrncpy(req.dnodeEp, pDnode->localEp, TSDB_EP_LEN);
|
||||
|
||||
req.clusterCfg.statusInterval = tsStatusInterval;
|
||||
req.clusterCfg.checkTime = 0;
|
||||
char timestr[32] = "1970-01-01 00:00:00.00";
|
||||
(void)taosParseTime(timestr, &req.clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0);
|
||||
memcpy(req.clusterCfg.timezone, tsTimezoneStr, TD_TIMEZONE_LEN);
|
||||
memcpy(req.clusterCfg.locale, tsLocale, TD_LOCALE_LEN);
|
||||
memcpy(req.clusterCfg.charset, tsCharset, TD_LOCALE_LEN);
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
||||
SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, VNODES);
|
||||
if (pWrapper != NULL) {
|
||||
SMonVloadInfo info = {0};
|
||||
dmGetVnodeLoads(pWrapper, &info);
|
||||
req.pVloads = info.pVloads;
|
||||
dndReleaseWrapper(pWrapper);
|
||||
}
|
||||
|
||||
int32_t contLen = tSerializeSStatusReq(NULL, 0, &req);
|
||||
void *pHead = rpcMallocCont(contLen);
|
||||
tSerializeSStatusReq(pHead, contLen, &req);
|
||||
taosArrayDestroy(req.pVloads);
|
||||
|
||||
SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_STATUS, .ahandle = (void *)0x9527};
|
||||
pMgmt->statusSent = 1;
|
||||
|
||||
dTrace("send req:%s to mnode, app:%p", TMSG_INFO(rpcMsg.msgType), rpcMsg.ahandle);
|
||||
SEpSet epSet = {0};
|
||||
dmGetMnodeEpSet(pMgmt, &epSet);
|
||||
tmsgSendReq(&pMgmt->msgCb, &epSet, &rpcMsg);
|
||||
}
|
||||
|
||||
static void dmUpdateDnodeCfg(SDnodeMgmt *pMgmt, SDnodeCfg *pCfg) {
|
||||
SDnode *pDnode = pMgmt->pDnode;
|
||||
|
||||
if (pDnode->dnodeId == 0) {
|
||||
dInfo("set dnodeId:%d clusterId:%" PRId64, pCfg->dnodeId, pCfg->clusterId);
|
||||
taosWLockLatch(&pMgmt->latch);
|
||||
pDnode->dnodeId = pCfg->dnodeId;
|
||||
pDnode->clusterId = pCfg->clusterId;
|
||||
dmWriteFile(pMgmt);
|
||||
taosWUnLockLatch(&pMgmt->latch);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t dmProcessStatusRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) {
|
||||
SDnode *pDnode = pMgmt->pDnode;
|
||||
SRpcMsg *pRsp = &pMsg->rpcMsg;
|
||||
|
||||
if (pRsp->code != TSDB_CODE_SUCCESS) {
|
||||
if (pRsp->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pDnode->dropped && pDnode->dnodeId > 0) {
|
||||
dInfo("dnode:%d, set to dropped since not exist in mnode", pDnode->dnodeId);
|
||||
pDnode->dropped = 1;
|
||||
dmWriteFile(pMgmt);
|
||||
}
|
||||
} else {
|
||||
SStatusRsp statusRsp = {0};
|
||||
if (pRsp->pCont != NULL && pRsp->contLen != 0 &&
|
||||
tDeserializeSStatusRsp(pRsp->pCont, pRsp->contLen, &statusRsp) == 0) {
|
||||
pMgmt->dver = statusRsp.dver;
|
||||
dmUpdateDnodeCfg(pMgmt, &statusRsp.dnodeCfg);
|
||||
dmUpdateDnodeEps(pMgmt, statusRsp.pDnodeEps);
|
||||
}
|
||||
tFreeSStatusRsp(&statusRsp);
|
||||
}
|
||||
|
||||
pMgmt->statusSent = 0;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t dmProcessAuthRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) {
|
||||
SRpcMsg *pRsp = &pMsg->rpcMsg;
|
||||
dError("auth rsp is received, but not supported yet");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) {
|
||||
SRpcMsg *pRsp = &pMsg->rpcMsg;
|
||||
dError("grant rsp is received, but not supported yet");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) {
|
||||
SRpcMsg *pReq = &pMsg->rpcMsg;
|
||||
SDCfgDnodeReq *pCfg = pReq->pCont;
|
||||
dError("config req is received, but not supported yet");
|
||||
return TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
static int32_t dmProcessCreateNodeMsg(SDnode *pDnode, EDndType ntype, SNodeMsg *pMsg) {
|
||||
SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, ntype);
|
||||
if (pWrapper != NULL) {
|
||||
dndReleaseWrapper(pWrapper);
|
||||
terrno = TSDB_CODE_NODE_ALREADY_DEPLOYED;
|
||||
dError("failed to create node since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
pWrapper = &pDnode->wrappers[ntype];
|
||||
|
||||
if (taosMkDir(pWrapper->path) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create dir:%s since %s", pWrapper->path, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = (*pWrapper->fp.createMsgFp)(pWrapper, pMsg);
|
||||
if (code != 0) {
|
||||
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
|
||||
} else {
|
||||
dDebug("node:%s, has been opened", pWrapper->name);
|
||||
pWrapper->deployed = true;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t dmProcessDropNodeMsg(SDnode *pDnode, EDndType ntype, SNodeMsg *pMsg) {
|
||||
SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, ntype);
|
||||
if (pWrapper == NULL) {
|
||||
terrno = TSDB_CODE_NODE_NOT_DEPLOYED;
|
||||
dError("failed to drop node since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosWLockLatch(&pWrapper->latch);
|
||||
pWrapper->deployed = false;
|
||||
|
||||
int32_t code = (*pWrapper->fp.dropMsgFp)(pWrapper, pMsg);
|
||||
if (code != 0) {
|
||||
pWrapper->deployed = true;
|
||||
dError("node:%s, failed to drop since %s", pWrapper->name, terrstr());
|
||||
} else {
|
||||
pWrapper->deployed = false;
|
||||
dDebug("node:%s, has been dropped", pWrapper->name);
|
||||
}
|
||||
|
||||
taosWUnLockLatch(&pWrapper->latch);
|
||||
dndReleaseWrapper(pWrapper);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t dmProcessCDnodeReq(SDnode *pDnode, SNodeMsg *pMsg) {
|
||||
switch (pMsg->rpcMsg.msgType) {
|
||||
case TDMT_DND_CREATE_MNODE:
|
||||
return dmProcessCreateNodeMsg(pDnode, MNODE, pMsg);
|
||||
case TDMT_DND_DROP_MNODE:
|
||||
return dmProcessDropNodeMsg(pDnode, MNODE, pMsg);
|
||||
case TDMT_DND_CREATE_QNODE:
|
||||
return dmProcessCreateNodeMsg(pDnode, QNODE, pMsg);
|
||||
case TDMT_DND_DROP_QNODE:
|
||||
return dmProcessDropNodeMsg(pDnode, QNODE, pMsg);
|
||||
case TDMT_DND_CREATE_SNODE:
|
||||
return dmProcessCreateNodeMsg(pDnode, SNODE, pMsg);
|
||||
case TDMT_DND_DROP_SNODE:
|
||||
return dmProcessDropNodeMsg(pDnode, SNODE, pMsg);
|
||||
case TDMT_DND_CREATE_BNODE:
|
||||
return dmProcessCreateNodeMsg(pDnode, BNODE, pMsg);
|
||||
case TDMT_DND_DROP_BNODE:
|
||||
return dmProcessDropNodeMsg(pDnode, BNODE, pMsg);
|
||||
default:
|
||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void dmInitMsgHandle(SMgmtWrapper *pWrapper) {
|
||||
// Requests handled by DNODE
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_DND_NETWORK_TEST, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
|
||||
// Requests handled by MNODE
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_STATUS_RSP, dmProcessMonitorMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_GRANT_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_MND_AUTH_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
}
|
|
@ -1,171 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http:www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dmInt.h"
|
||||
|
||||
void dmGetMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet) {
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
*pEpSet = pMgmt->mnodeEpSet;
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
}
|
||||
|
||||
void dmUpdateMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet) {
|
||||
dInfo("mnode is changed, num:%d use:%d", pEpSet->numOfEps, pEpSet->inUse);
|
||||
|
||||
taosWLockLatch(&pMgmt->latch);
|
||||
pMgmt->mnodeEpSet = *pEpSet;
|
||||
for (int32_t i = 0; i < pEpSet->numOfEps; ++i) {
|
||||
dInfo("mnode index:%d %s:%u", i, pEpSet->eps[i].fqdn, pEpSet->eps[i].port);
|
||||
}
|
||||
|
||||
taosWUnLockLatch(&pMgmt->latch);
|
||||
}
|
||||
|
||||
void dmGetDnodeEp(SMgmtWrapper *pWrapper, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort) {
|
||||
SDnodeMgmt *pMgmt = pWrapper->pMgmt;
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
|
||||
SDnodeEp *pDnodeEp = taosHashGet(pMgmt->dnodeHash, &dnodeId, sizeof(int32_t));
|
||||
if (pDnodeEp != NULL) {
|
||||
if (pPort != NULL) {
|
||||
*pPort = pDnodeEp->ep.port;
|
||||
}
|
||||
if (pFqdn != NULL) {
|
||||
tstrncpy(pFqdn, pDnodeEp->ep.fqdn, TSDB_FQDN_LEN);
|
||||
}
|
||||
if (pEp != NULL) {
|
||||
snprintf(pEp, TSDB_EP_LEN, "%s:%u", pDnodeEp->ep.fqdn, pDnodeEp->ep.port);
|
||||
}
|
||||
}
|
||||
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
}
|
||||
|
||||
void dmSendRedirectRsp(SDnodeMgmt *pMgmt, const SRpcMsg *pReq) {
|
||||
SDnode *pDnode = pMgmt->pDnode;
|
||||
|
||||
SEpSet epSet = {0};
|
||||
dmGetMnodeEpSet(pMgmt, &epSet);
|
||||
|
||||
dDebug("RPC %p, req is redirected, num:%d use:%d", pReq->handle, epSet.numOfEps, epSet.inUse);
|
||||
for (int32_t i = 0; i < epSet.numOfEps; ++i) {
|
||||
dDebug("mnode index:%d %s:%u", i, epSet.eps[i].fqdn, epSet.eps[i].port);
|
||||
if (strcmp(epSet.eps[i].fqdn, pDnode->localFqdn) == 0 && epSet.eps[i].port == pDnode->serverPort) {
|
||||
epSet.inUse = (i + 1) % epSet.numOfEps;
|
||||
}
|
||||
|
||||
epSet.eps[i].port = htons(epSet.eps[i].port);
|
||||
}
|
||||
|
||||
rpcSendRedirectRsp(pReq->handle, &epSet);
|
||||
}
|
||||
|
||||
static int32_t dmStart(SMgmtWrapper *pWrapper) {
|
||||
dDebug("dnode-mgmt start to run");
|
||||
return dmStartThread(pWrapper->pMgmt);
|
||||
}
|
||||
|
||||
static int32_t dmInit(SMgmtWrapper *pWrapper) {
|
||||
SDnode *pDnode = pWrapper->pDnode;
|
||||
SDnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SDnodeMgmt));
|
||||
dInfo("dnode-mgmt start to init");
|
||||
|
||||
pDnode->dnodeId = 0;
|
||||
pDnode->dropped = 0;
|
||||
pDnode->clusterId = 0;
|
||||
pMgmt->path = pWrapper->path;
|
||||
pMgmt->pDnode = pDnode;
|
||||
pMgmt->pWrapper = pWrapper;
|
||||
taosInitRWLatch(&pMgmt->latch);
|
||||
|
||||
pMgmt->dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||
if (pMgmt->dnodeHash == NULL) {
|
||||
dError("failed to init dnode hash");
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dmReadFile(pMgmt) != 0) {
|
||||
dError("failed to read file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pDnode->dropped) {
|
||||
dError("dnode will not start since its already dropped");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dmStartWorker(pMgmt) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndInitTrans(pDnode) != 0) {
|
||||
dError("failed to init transport since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
pWrapper->pMgmt = pMgmt;
|
||||
pMgmt->msgCb = dndCreateMsgcb(pWrapper);
|
||||
|
||||
dInfo("dnode-mgmt is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dmCleanup(SMgmtWrapper *pWrapper) {
|
||||
SDnodeMgmt *pMgmt = pWrapper->pMgmt;
|
||||
if (pMgmt == NULL) return;
|
||||
|
||||
dInfo("dnode-mgmt start to clean up");
|
||||
SDnode *pDnode = pMgmt->pDnode;
|
||||
dmStopWorker(pMgmt);
|
||||
|
||||
taosWLockLatch(&pMgmt->latch);
|
||||
|
||||
if (pMgmt->dnodeEps != NULL) {
|
||||
taosArrayDestroy(pMgmt->dnodeEps);
|
||||
pMgmt->dnodeEps = NULL;
|
||||
}
|
||||
|
||||
if (pMgmt->dnodeHash != NULL) {
|
||||
taosHashCleanup(pMgmt->dnodeHash);
|
||||
pMgmt->dnodeHash = NULL;
|
||||
}
|
||||
|
||||
taosWUnLockLatch(&pMgmt->latch);
|
||||
|
||||
taosMemoryFree(pMgmt);
|
||||
pWrapper->pMgmt = NULL;
|
||||
dndCleanupTrans(pDnode);
|
||||
|
||||
dInfo("dnode-mgmt is cleaned up");
|
||||
}
|
||||
|
||||
static int32_t dmRequire(SMgmtWrapper *pWrapper, bool *required) {
|
||||
*required = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dmSetMgmtFp(SMgmtWrapper *pWrapper) {
|
||||
SMgmtFp mgmtFp = {0};
|
||||
mgmtFp.openFp = dmInit;
|
||||
mgmtFp.closeFp = dmCleanup;
|
||||
mgmtFp.startFp = dmStart;
|
||||
mgmtFp.requiredFp = dmRequire;
|
||||
|
||||
dmInitMsgHandle(pWrapper);
|
||||
pWrapper->name = "dnode";
|
||||
pWrapper->fp = mgmtFp;
|
||||
}
|
|
@ -1,142 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http:www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dmInt.h"
|
||||
|
||||
static void *dmThreadRoutine(void *param) {
|
||||
SDnodeMgmt *pMgmt = param;
|
||||
SDnode *pDnode = pMgmt->pDnode;
|
||||
int64_t lastStatusTime = taosGetTimestampMs();
|
||||
int64_t lastMonitorTime = lastStatusTime;
|
||||
|
||||
setThreadName("dnode-hb");
|
||||
|
||||
while (true) {
|
||||
taosThreadTestCancel();
|
||||
taosMsleep(200);
|
||||
if (dndGetStatus(pDnode) != DND_STAT_RUNNING || pDnode->dropped) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int64_t curTime = taosGetTimestampMs();
|
||||
float statusInterval = (curTime - lastStatusTime) / 1000.0f;
|
||||
if (statusInterval >= tsStatusInterval && !pMgmt->statusSent) {
|
||||
dmSendStatusReq(pMgmt);
|
||||
lastStatusTime = curTime;
|
||||
}
|
||||
|
||||
float monitorInterval = (curTime - lastMonitorTime) / 1000.0f;
|
||||
if (monitorInterval >= tsMonitorInterval) {
|
||||
dmSendMonitorReport(pDnode);
|
||||
lastMonitorTime = curTime;
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t dmStartThread(SDnodeMgmt *pMgmt) {
|
||||
pMgmt->threadId = taosCreateThread(dmThreadRoutine, pMgmt);
|
||||
if (pMgmt->threadId == NULL) {
|
||||
dError("failed to init dnode thread");
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) {
|
||||
SDnodeMgmt *pMgmt = pInfo->ahandle;
|
||||
|
||||
SDnode *pDnode = pMgmt->pDnode;
|
||||
SRpcMsg *pRpc = &pMsg->rpcMsg;
|
||||
int32_t code = -1;
|
||||
dTrace("msg:%p, will be processed in dnode queue", pMsg);
|
||||
|
||||
switch (pRpc->msgType) {
|
||||
case TDMT_DND_CONFIG_DNODE:
|
||||
code = dmProcessConfigReq(pMgmt, pMsg);
|
||||
break;
|
||||
case TDMT_MND_STATUS_RSP:
|
||||
code = dmProcessStatusRsp(pMgmt, pMsg);
|
||||
break;
|
||||
case TDMT_MND_AUTH_RSP:
|
||||
code = dmProcessAuthRsp(pMgmt, pMsg);
|
||||
break;
|
||||
case TDMT_MND_GRANT_RSP:
|
||||
code = dmProcessGrantRsp(pMgmt, pMsg);
|
||||
break;
|
||||
default:
|
||||
code = dmProcessCDnodeReq(pMgmt->pDnode, pMsg);
|
||||
break;
|
||||
}
|
||||
|
||||
if (pRpc->msgType & 1u) {
|
||||
if (code != 0) code = terrno;
|
||||
SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = code};
|
||||
rpcSendResponse(&rsp);
|
||||
}
|
||||
|
||||
dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code));
|
||||
rpcFreeCont(pMsg->rpcMsg.pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
|
||||
int32_t dmStartWorker(SDnodeMgmt *pMgmt) {
|
||||
SSingleWorkerCfg mcfg = {.min = 1, .max = 1, .name = "dnode-mgmt", .fp = (FItem)dmProcessQueue, .param = pMgmt};
|
||||
if (tSingleWorkerInit(&pMgmt->mgmtWorker, &mcfg) != 0) {
|
||||
dError("failed to start dnode mgmt worker since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SSingleWorkerCfg scfg = {.min = 1, .max = 1, .name = "dnode-monitor", .fp = (FItem)dmProcessQueue, .param = pMgmt};
|
||||
if (tSingleWorkerInit(&pMgmt->monitorWorker, &scfg) != 0) {
|
||||
dError("failed to start dnode monitor worker since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("dnode workers are initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dmStopWorker(SDnodeMgmt *pMgmt) {
|
||||
tSingleWorkerCleanup(&pMgmt->mgmtWorker);
|
||||
tSingleWorkerCleanup(&pMgmt->monitorWorker);
|
||||
|
||||
if (pMgmt->threadId != NULL) {
|
||||
taosDestoryThread(pMgmt->threadId);
|
||||
pMgmt->threadId = NULL;
|
||||
}
|
||||
dDebug("dnode workers are closed");
|
||||
}
|
||||
|
||||
int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
||||
SDnodeMgmt *pMgmt = pWrapper->pMgmt;
|
||||
SSingleWorker *pWorker = &pMgmt->mgmtWorker;
|
||||
|
||||
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
||||
taosWriteQitem(pWorker->queue, pMsg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
||||
SDnodeMgmt *pMgmt = pWrapper->pMgmt;
|
||||
SSingleWorker *pWorker = &pMgmt->monitorWorker;
|
||||
|
||||
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
||||
taosWriteQitem(pWorker->queue, pMsg);
|
||||
return 0;
|
||||
}
|
|
@ -14,47 +14,46 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndInt.h"
|
||||
#include "dmImp.h"
|
||||
#include "tconfig.h"
|
||||
#include "tgrant.h"
|
||||
|
||||
static struct {
|
||||
bool dumpConfig;
|
||||
bool generateGrant;
|
||||
bool printAuth;
|
||||
bool printVersion;
|
||||
char envFile[PATH_MAX];
|
||||
char apolloUrl[PATH_MAX];
|
||||
SArray *pArgs; // SConfigPair
|
||||
SDnode *pDnode;
|
||||
EDndType ntype;
|
||||
bool dumpConfig;
|
||||
bool generateGrant;
|
||||
bool printAuth;
|
||||
bool printVersion;
|
||||
char envFile[PATH_MAX];
|
||||
char apolloUrl[PATH_MAX];
|
||||
SArray *pArgs; // SConfigPair
|
||||
SDnode *pDnode;
|
||||
EDndNodeType ntype;
|
||||
} global = {0};
|
||||
|
||||
static void dndStopDnode(int signum, void *info, void *ctx) {
|
||||
static void dmStopDnode(int signum, void *info, void *ctx) {
|
||||
SDnode *pDnode = atomic_val_compare_exchange_ptr(&global.pDnode, 0, global.pDnode);
|
||||
if (pDnode != NULL) {
|
||||
dndHandleEvent(pDnode, DND_EVENT_STOP);
|
||||
dmSetEvent(pDnode, DND_EVENT_STOP);
|
||||
}
|
||||
}
|
||||
|
||||
static void dndSetSignalHandle() {
|
||||
taosSetSignal(SIGTERM, dndStopDnode);
|
||||
taosSetSignal(SIGHUP, dndStopDnode);
|
||||
taosSetSignal(SIGINT, dndStopDnode);
|
||||
taosSetSignal(SIGTSTP, dndStopDnode);
|
||||
taosSetSignal(SIGABRT, dndStopDnode);
|
||||
taosSetSignal(SIGBREAK, dndStopDnode);
|
||||
taosSetSignal(SIGQUIT, dndStopDnode);
|
||||
static void dmSetSignalHandle() {
|
||||
taosSetSignal(SIGTERM, dmStopDnode);
|
||||
taosSetSignal(SIGHUP, dmStopDnode);
|
||||
taosSetSignal(SIGINT, dmStopDnode);
|
||||
taosSetSignal(SIGTSTP, dmStopDnode);
|
||||
taosSetSignal(SIGABRT, dmStopDnode);
|
||||
taosSetSignal(SIGBREAK, dmStopDnode);
|
||||
taosSetSignal(SIGQUIT, dmStopDnode);
|
||||
|
||||
if (!tsMultiProcess) {
|
||||
} else if (global.ntype == DNODE || global.ntype == NODE_MAX) {
|
||||
} else if (global.ntype == DNODE || global.ntype == NODE_END) {
|
||||
taosIgnSignal(SIGCHLD);
|
||||
} else {
|
||||
taosKillChildOnParentStopped();
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t dndParseArgs(int32_t argc, char const *argv[]) {
|
||||
static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
||||
for (int32_t i = 1; i < argc; ++i) {
|
||||
if (strcmp(argv[i], "-c") == 0) {
|
||||
if (i < argc - 1) {
|
||||
|
@ -73,8 +72,8 @@ static int32_t dndParseArgs(int32_t argc, char const *argv[]) {
|
|||
tstrncpy(global.envFile, argv[++i], PATH_MAX);
|
||||
} else if (strcmp(argv[i], "-n") == 0) {
|
||||
global.ntype = atoi(argv[++i]);
|
||||
if (global.ntype <= DNODE || global.ntype > NODE_MAX) {
|
||||
printf("'-n' range is [1 - %d], default is 0\n", NODE_MAX - 1);
|
||||
if (global.ntype <= DNODE || global.ntype > NODE_END) {
|
||||
printf("'-n' range is [1 - %d], default is 0\n", NODE_END - 1);
|
||||
return -1;
|
||||
}
|
||||
} else if (strcmp(argv[i], "-k") == 0) {
|
||||
|
@ -90,11 +89,9 @@ static int32_t dndParseArgs(int32_t argc, char const *argv[]) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void dndGenerateGrant() {
|
||||
grantParseParameter();
|
||||
}
|
||||
static void dmGenerateGrant() { mndGenerateMachineCode(); }
|
||||
|
||||
static void dndPrintVersion() {
|
||||
static void dmPrintVersion() {
|
||||
#ifdef TD_ENTERPRISE
|
||||
char *releaseName = "enterprise";
|
||||
#else
|
||||
|
@ -105,12 +102,12 @@ static void dndPrintVersion() {
|
|||
printf("buildInfo: %s\n", buildinfo);
|
||||
}
|
||||
|
||||
static void dndDumpCfg() {
|
||||
static void dmDumpCfg() {
|
||||
SConfig *pCfg = taosGetCfg();
|
||||
cfgDumpCfg(pCfg, 0, 1);
|
||||
}
|
||||
|
||||
static SDnodeOpt dndGetOpt() {
|
||||
static SDnodeOpt dmGetOpt() {
|
||||
SConfig *pCfg = taosGetCfg();
|
||||
SDnodeOpt option = {0};
|
||||
|
||||
|
@ -127,43 +124,43 @@ static SDnodeOpt dndGetOpt() {
|
|||
return option;
|
||||
}
|
||||
|
||||
static int32_t dndInitLog() {
|
||||
static int32_t dmInitLog() {
|
||||
char logName[12] = {0};
|
||||
snprintf(logName, sizeof(logName), "%slog", dndNodeLogStr(global.ntype));
|
||||
snprintf(logName, sizeof(logName), "%slog", dmLogName(global.ntype));
|
||||
return taosCreateLog(logName, 1, configDir, global.envFile, global.apolloUrl, global.pArgs, 0);
|
||||
}
|
||||
|
||||
static void dndSetProcInfo(int32_t argc, char **argv) {
|
||||
static void dmSetProcInfo(int32_t argc, char **argv) {
|
||||
taosSetProcPath(argc, argv);
|
||||
if (global.ntype != DNODE && global.ntype != NODE_MAX) {
|
||||
const char *name = dndNodeProcStr(global.ntype);
|
||||
if (global.ntype != DNODE && global.ntype != NODE_END) {
|
||||
const char *name = dmProcName(global.ntype);
|
||||
taosSetProcName(argc, argv, name);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t dndRunDnode() {
|
||||
if (dndInit() != 0) {
|
||||
static int32_t dmRunDnode() {
|
||||
if (dmInit() != 0) {
|
||||
dError("failed to init environment since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDnodeOpt option = dndGetOpt();
|
||||
SDnode *pDnode = dndCreate(&option);
|
||||
SDnodeOpt option = dmGetOpt();
|
||||
SDnode *pDnode = dmCreate(&option);
|
||||
if (pDnode == NULL) {
|
||||
dError("failed to to create dnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
global.pDnode = pDnode;
|
||||
dndSetSignalHandle();
|
||||
dmSetSignalHandle();
|
||||
}
|
||||
|
||||
dInfo("start the service");
|
||||
int32_t code = dndRun(pDnode);
|
||||
int32_t code = dmRun(pDnode);
|
||||
dInfo("start shutting down the service");
|
||||
|
||||
global.pDnode = NULL;
|
||||
dndClose(pDnode);
|
||||
dndCleanup();
|
||||
dmClose(pDnode);
|
||||
dmCleanup();
|
||||
taosCloseLog();
|
||||
taosCleanupCfg();
|
||||
return code;
|
||||
|
@ -175,22 +172,22 @@ int main(int argc, char const *argv[]) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (dndParseArgs(argc, argv) != 0) {
|
||||
if (dmParseArgs(argc, argv) != 0) {
|
||||
printf("failed to start since parse args error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (global.generateGrant) {
|
||||
dndGenerateGrant();
|
||||
dmGenerateGrant();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (global.printVersion) {
|
||||
dndPrintVersion();
|
||||
dmPrintVersion();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (dndInitLog() != 0) {
|
||||
if (dmInitLog() != 0) {
|
||||
printf("failed to start since init log error\n");
|
||||
return -1;
|
||||
}
|
||||
|
@ -201,12 +198,12 @@ int main(int argc, char const *argv[]) {
|
|||
}
|
||||
|
||||
if (global.dumpConfig) {
|
||||
dndDumpCfg();
|
||||
dmDumpCfg();
|
||||
taosCleanupCfg();
|
||||
taosCloseLog();
|
||||
return 0;
|
||||
}
|
||||
|
||||
dndSetProcInfo(argc, (char **)argv);
|
||||
return dndRunDnode();
|
||||
dmSetProcInfo(argc, (char **)argv);
|
||||
return dmRunDnode();
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
aux_source_directory(src IMPLEMENT_SRC)
|
||||
add_library(dnode STATIC ${IMPLEMENT_SRC})
|
||||
target_link_libraries(
|
||||
dnode mgmt_bnode mgmt_mnode mgmt_qnode mgmt_snode mgmt_vnode
|
||||
)
|
||||
target_include_directories(
|
||||
dnode
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_DND_IMP_H_
|
||||
#define _TD_DND_IMP_H_
|
||||
|
||||
#include "dmInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t dmOpenNode(SMgmtWrapper *pWrapper);
|
||||
void dmCloseNode(SMgmtWrapper *pWrapper);
|
||||
|
||||
// dmTransport.c
|
||||
int32_t dmInitTrans(SDnode *pDnode);
|
||||
void dmCleanupTrans(SDnode *pDnode);
|
||||
SProcCfg dmGenProcCfg(SMgmtWrapper *pWrapper);
|
||||
SMsgCb dmGetMsgcb(SMgmtWrapper *pWrapper);
|
||||
int32_t dmInitMsgHandle(SDnode *pDnode);
|
||||
void dmSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp);
|
||||
void dmSendToMnodeRecv(SDnode *pDnode, SRpcMsg *pReq, SRpcMsg *pRsp);
|
||||
|
||||
// dmEps.c
|
||||
int32_t dmReadEps(SDnode *pDnode);
|
||||
int32_t dmWriteEps(SDnode *pDnode);
|
||||
void dmUpdateEps(SDnode *pDnode, SArray *pDnodeEps);
|
||||
|
||||
// dmHandle.c
|
||||
void dmSendStatusReq(SDnode *pDnode);
|
||||
int32_t dmProcessConfigReq(SDnode *pDnode, SNodeMsg *pMsg);
|
||||
int32_t dmProcessAuthRsp(SDnode *pDnode, SNodeMsg *pMsg);
|
||||
int32_t dmProcessGrantRsp(SDnode *pDnode, SNodeMsg *pMsg);
|
||||
int32_t dmProcessCreateNodeReq(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg);
|
||||
int32_t dmProcessDropNodeReq(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg);
|
||||
|
||||
// dmMonitor.c
|
||||
void dmGetVnodeLoads(SDnode *pDnode, SMonVloadInfo *pInfo);
|
||||
void dmSendMonitorReport(SDnode *pDnode);
|
||||
|
||||
// dmWorker.c
|
||||
int32_t dmStartStatusThread(SDnode *pDnode);
|
||||
void dmStopStatusThread(SDnode *pDnode);
|
||||
int32_t dmStartMonitorThread(SDnode *pDnode);
|
||||
void dmStopMonitorThread(SDnode *pDnode);
|
||||
int32_t dmStartWorker(SDnode *pDnode);
|
||||
void dmStopWorker(SDnode *pDnode);
|
||||
int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
|
||||
int32_t dmProcessStatusMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
|
||||
|
||||
// mgmt nodes
|
||||
void dmSetMgmtFp(SMgmtWrapper *pWrapper);
|
||||
void bmSetMgmtFp(SMgmtWrapper *pWrapper);
|
||||
void qmSetMgmtFp(SMgmtWrapper *pWrapper);
|
||||
void smSetMgmtFp(SMgmtWrapper *pWrapper);
|
||||
void vmSetMgmtFp(SMgmtWrapper *pWrapper);
|
||||
void mmSetMgmtFp(SMgmtWrapper *pWrapper);
|
||||
|
||||
void vmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo);
|
||||
void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo);
|
||||
void vmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonVmInfo *vmInfo);
|
||||
void qmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonQmInfo *qmInfo);
|
||||
void smGetMonitorInfo(SMgmtWrapper *pWrapper, SMonSmInfo *smInfo);
|
||||
void bmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonBmInfo *bmInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_DND_IMP_H_*/
|
|
@ -14,32 +14,50 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dmInt.h"
|
||||
#include "dmImp.h"
|
||||
|
||||
static void dmPrintDnodes(SDnodeMgmt *pMgmt);
|
||||
static bool dmIsEpChanged(SDnodeMgmt *pMgmt, int32_t dnodeId, const char *ep);
|
||||
static void dmResetDnodes(SDnodeMgmt *pMgmt, SArray *dnodeEps);
|
||||
static void dmPrintEps(SDnode *pDnode);
|
||||
static bool dmIsEpChanged(SDnode *pDnode, int32_t dnodeId, const char *ep);
|
||||
static void dmResetEps(SDnode *pDnode, SArray *dnodeEps);
|
||||
|
||||
int32_t dmReadFile(SDnodeMgmt *pMgmt) {
|
||||
static void dmGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort) {
|
||||
taosRLockLatch(&pDnode->data.latch);
|
||||
|
||||
SDnodeEp *pDnodeEp = taosHashGet(pDnode->data.dnodeHash, &dnodeId, sizeof(int32_t));
|
||||
if (pDnodeEp != NULL) {
|
||||
if (pPort != NULL) {
|
||||
*pPort = pDnodeEp->ep.port;
|
||||
}
|
||||
if (pFqdn != NULL) {
|
||||
tstrncpy(pFqdn, pDnodeEp->ep.fqdn, TSDB_FQDN_LEN);
|
||||
}
|
||||
if (pEp != NULL) {
|
||||
snprintf(pEp, TSDB_EP_LEN, "%s:%u", pDnodeEp->ep.fqdn, pDnodeEp->ep.port);
|
||||
}
|
||||
}
|
||||
|
||||
taosRUnLockLatch(&pDnode->data.latch);
|
||||
}
|
||||
|
||||
int32_t dmReadEps(SDnode *pDnode) {
|
||||
int32_t code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 256 * 1024;
|
||||
char *content = taosMemoryCalloc(1, maxLen + 1);
|
||||
cJSON *root = NULL;
|
||||
char file[PATH_MAX];
|
||||
char file[PATH_MAX] = {0};
|
||||
TdFilePtr pFile = NULL;
|
||||
SDnode *pDnode = pMgmt->pDnode;
|
||||
|
||||
pMgmt->dnodeEps = taosArrayInit(1, sizeof(SDnodeEp));
|
||||
if (pMgmt->dnodeEps == NULL) {
|
||||
pDnode->data.dnodeEps = taosArrayInit(1, sizeof(SDnodeEp));
|
||||
if (pDnode->data.dnodeEps == NULL) {
|
||||
dError("failed to calloc dnodeEp array since %s", strerror(errno));
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
|
||||
snprintf(file, sizeof(file), "%s%sdnode.json", pMgmt->path, TD_DIRSEP);
|
||||
snprintf(file, sizeof(file), "%s%sdnode.json", pDnode->wrappers[DNODE].path, TD_DIRSEP);
|
||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
dDebug("file %s not exist", file);
|
||||
// dDebug("file %s not exist", file);
|
||||
code = 0;
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
|
@ -62,21 +80,21 @@ int32_t dmReadFile(SDnodeMgmt *pMgmt) {
|
|||
dError("failed to read %s since dnodeId not found", file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
pDnode->dnodeId = dnodeId->valueint;
|
||||
pDnode->data.dnodeId = dnodeId->valueint;
|
||||
|
||||
cJSON *clusterId = cJSON_GetObjectItem(root, "clusterId");
|
||||
if (!clusterId || clusterId->type != cJSON_String) {
|
||||
dError("failed to read %s since clusterId not found", file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
pDnode->clusterId = atoll(clusterId->valuestring);
|
||||
pDnode->data.clusterId = atoll(clusterId->valuestring);
|
||||
|
||||
cJSON *dropped = cJSON_GetObjectItem(root, "dropped");
|
||||
if (!dropped || dropped->type != cJSON_Number) {
|
||||
dError("failed to read %s since dropped not found", file);
|
||||
goto PRASE_DNODE_OVER;
|
||||
}
|
||||
pDnode->dropped = dropped->valueint;
|
||||
pDnode->data.dropped = dropped->valueint;
|
||||
|
||||
cJSON *dnodes = cJSON_GetObjectItem(root, "dnodes");
|
||||
if (!dnodes || dnodes->type != cJSON_Array) {
|
||||
|
@ -126,41 +144,41 @@ int32_t dmReadFile(SDnodeMgmt *pMgmt) {
|
|||
}
|
||||
dnodeEp.isMnode = isMnode->valueint;
|
||||
|
||||
taosArrayPush(pMgmt->dnodeEps, &dnodeEp);
|
||||
taosArrayPush(pDnode->data.dnodeEps, &dnodeEp);
|
||||
}
|
||||
|
||||
code = 0;
|
||||
dDebug("succcessed to read file %s", file);
|
||||
dmPrintDnodes(pMgmt);
|
||||
dmPrintEps(pDnode);
|
||||
|
||||
PRASE_DNODE_OVER:
|
||||
if (content != NULL) taosMemoryFree(content);
|
||||
if (root != NULL) cJSON_Delete(root);
|
||||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
|
||||
if (dmIsEpChanged(pMgmt, pDnode->dnodeId, pDnode->localEp)) {
|
||||
dError("localEp %s different with %s and need reconfigured", pDnode->localEp, file);
|
||||
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(pMgmt->dnodeEps) == 0) {
|
||||
if (taosArrayGetSize(pDnode->data.dnodeEps) == 0) {
|
||||
SDnodeEp dnodeEp = {0};
|
||||
dnodeEp.isMnode = 1;
|
||||
taosGetFqdnPortFromEp(pDnode->firstEp, &dnodeEp.ep);
|
||||
taosArrayPush(pMgmt->dnodeEps, &dnodeEp);
|
||||
taosGetFqdnPortFromEp(pDnode->data.firstEp, &dnodeEp.ep);
|
||||
taosArrayPush(pDnode->data.dnodeEps, &dnodeEp);
|
||||
}
|
||||
|
||||
dmResetDnodes(pMgmt, pMgmt->dnodeEps);
|
||||
dmResetEps(pDnode, pDnode->data.dnodeEps);
|
||||
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t dmWriteFile(SDnodeMgmt *pMgmt) {
|
||||
SDnode *pDnode = pMgmt->pDnode;
|
||||
|
||||
char file[PATH_MAX];
|
||||
snprintf(file, sizeof(file), "%s%sdnode.json.bak", pMgmt->path, TD_DIRSEP);
|
||||
int32_t dmWriteEps(SDnode *pDnode) {
|
||||
char file[PATH_MAX] = {0};
|
||||
char realfile[PATH_MAX];
|
||||
snprintf(file, sizeof(file), "%s%sdnode.json.bak", pDnode->wrappers[DNODE].path, TD_DIRSEP);
|
||||
snprintf(realfile, sizeof(realfile), "%s%sdnode.json", pDnode->wrappers[DNODE].path, TD_DIRSEP);
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
|
@ -174,14 +192,14 @@ int32_t dmWriteFile(SDnodeMgmt *pMgmt) {
|
|||
char *content = taosMemoryCalloc(1, maxLen + 1);
|
||||
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", pDnode->dnodeId);
|
||||
len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", pDnode->clusterId);
|
||||
len += snprintf(content + len, maxLen - len, " \"dropped\": %d,\n", pDnode->dropped);
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", pDnode->data.dnodeId);
|
||||
len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", pDnode->data.clusterId);
|
||||
len += snprintf(content + len, maxLen - len, " \"dropped\": %d,\n", pDnode->data.dropped);
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodes\": [{\n");
|
||||
|
||||
int32_t numOfEps = (int32_t)taosArrayGetSize(pMgmt->dnodeEps);
|
||||
int32_t numOfEps = (int32_t)taosArrayGetSize(pDnode->data.dnodeEps);
|
||||
for (int32_t i = 0; i < numOfEps; ++i) {
|
||||
SDnodeEp *pDnodeEp = taosArrayGet(pMgmt->dnodeEps, i);
|
||||
SDnodeEp *pDnodeEp = taosArrayGet(pDnode->data.dnodeEps, i);
|
||||
len += snprintf(content + len, maxLen - len, " \"id\": %d,\n", pDnodeEp->id);
|
||||
len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pDnodeEp->ep.fqdn);
|
||||
len += snprintf(content + len, maxLen - len, " \"port\": %u,\n", pDnodeEp->ep.port);
|
||||
|
@ -199,50 +217,47 @@ int32_t dmWriteFile(SDnodeMgmt *pMgmt) {
|
|||
taosCloseFile(&pFile);
|
||||
taosMemoryFree(content);
|
||||
|
||||
char realfile[PATH_MAX];
|
||||
snprintf(realfile, sizeof(realfile), "%s%sdnode.json", pMgmt->path, TD_DIRSEP);
|
||||
|
||||
if (taosRenameFile(file, realfile) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to rename %s since %s", file, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
pMgmt->updateTime = taosGetTimestampMs();
|
||||
pDnode->data.updateTime = taosGetTimestampMs();
|
||||
dDebug("successed to write %s", realfile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dmUpdateDnodeEps(SDnodeMgmt *pMgmt, SArray *dnodeEps) {
|
||||
int32_t numOfEps = taosArrayGetSize(dnodeEps);
|
||||
void dmUpdateEps(SDnode *pDnode, SArray *eps) {
|
||||
int32_t numOfEps = taosArrayGetSize(eps);
|
||||
if (numOfEps <= 0) return;
|
||||
|
||||
taosWLockLatch(&pMgmt->latch);
|
||||
taosWLockLatch(&pDnode->data.latch);
|
||||
|
||||
int32_t numOfEpsOld = (int32_t)taosArrayGetSize(pMgmt->dnodeEps);
|
||||
int32_t numOfEpsOld = (int32_t)taosArrayGetSize(pDnode->data.dnodeEps);
|
||||
if (numOfEps != numOfEpsOld) {
|
||||
dmResetDnodes(pMgmt, dnodeEps);
|
||||
dmWriteFile(pMgmt);
|
||||
dmResetEps(pDnode, eps);
|
||||
dmWriteEps(pDnode);
|
||||
} else {
|
||||
int32_t size = numOfEps * sizeof(SDnodeEp);
|
||||
if (memcmp(pMgmt->dnodeEps->pData, dnodeEps->pData, size) != 0) {
|
||||
dmResetDnodes(pMgmt, dnodeEps);
|
||||
dmWriteFile(pMgmt);
|
||||
if (memcmp(pDnode->data.dnodeEps->pData, eps->pData, size) != 0) {
|
||||
dmResetEps(pDnode, eps);
|
||||
dmWriteEps(pDnode);
|
||||
}
|
||||
}
|
||||
|
||||
taosWUnLockLatch(&pMgmt->latch);
|
||||
taosWUnLockLatch(&pDnode->data.latch);
|
||||
}
|
||||
|
||||
static void dmResetDnodes(SDnodeMgmt *pMgmt, SArray *dnodeEps) {
|
||||
if (pMgmt->dnodeEps != dnodeEps) {
|
||||
SArray *tmp = pMgmt->dnodeEps;
|
||||
pMgmt->dnodeEps = taosArrayDup(dnodeEps);
|
||||
static void dmResetEps(SDnode *pDnode, SArray *dnodeEps) {
|
||||
if (pDnode->data.dnodeEps != dnodeEps) {
|
||||
SArray *tmp = pDnode->data.dnodeEps;
|
||||
pDnode->data.dnodeEps = taosArrayDup(dnodeEps);
|
||||
taosArrayDestroy(tmp);
|
||||
}
|
||||
|
||||
pMgmt->mnodeEpSet.inUse = 0;
|
||||
pMgmt->mnodeEpSet.numOfEps = 0;
|
||||
pDnode->data.mnodeEps.inUse = 0;
|
||||
pDnode->data.mnodeEps.numOfEps = 0;
|
||||
|
||||
int32_t mIndex = 0;
|
||||
int32_t numOfEps = (int32_t)taosArrayGetSize(dnodeEps);
|
||||
|
@ -251,40 +266,40 @@ static void dmResetDnodes(SDnodeMgmt *pMgmt, SArray *dnodeEps) {
|
|||
SDnodeEp *pDnodeEp = taosArrayGet(dnodeEps, i);
|
||||
if (!pDnodeEp->isMnode) continue;
|
||||
if (mIndex >= TSDB_MAX_REPLICA) continue;
|
||||
pMgmt->mnodeEpSet.numOfEps++;
|
||||
pDnode->data.mnodeEps.numOfEps++;
|
||||
|
||||
pMgmt->mnodeEpSet.eps[mIndex] = pDnodeEp->ep;
|
||||
pDnode->data.mnodeEps.eps[mIndex] = pDnodeEp->ep;
|
||||
mIndex++;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfEps; i++) {
|
||||
SDnodeEp *pDnodeEp = taosArrayGet(dnodeEps, i);
|
||||
taosHashPut(pMgmt->dnodeHash, &pDnodeEp->id, sizeof(int32_t), pDnodeEp, sizeof(SDnodeEp));
|
||||
taosHashPut(pDnode->data.dnodeHash, &pDnodeEp->id, sizeof(int32_t), pDnodeEp, sizeof(SDnodeEp));
|
||||
}
|
||||
|
||||
dmPrintDnodes(pMgmt);
|
||||
dmPrintEps(pDnode);
|
||||
}
|
||||
|
||||
static void dmPrintDnodes(SDnodeMgmt *pMgmt) {
|
||||
int32_t numOfEps = (int32_t)taosArrayGetSize(pMgmt->dnodeEps);
|
||||
static void dmPrintEps(SDnode *pDnode) {
|
||||
int32_t numOfEps = (int32_t)taosArrayGetSize(pDnode->data.dnodeEps);
|
||||
dDebug("print dnode ep list, num:%d", numOfEps);
|
||||
for (int32_t i = 0; i < numOfEps; i++) {
|
||||
SDnodeEp *pEp = taosArrayGet(pMgmt->dnodeEps, i);
|
||||
SDnodeEp *pEp = taosArrayGet(pDnode->data.dnodeEps, i);
|
||||
dDebug("dnode:%d, fqdn:%s port:%u isMnode:%d", pEp->id, pEp->ep.fqdn, pEp->ep.port, pEp->isMnode);
|
||||
}
|
||||
}
|
||||
|
||||
static bool dmIsEpChanged(SDnodeMgmt *pMgmt, int32_t dnodeId, const char *ep) {
|
||||
static bool dmIsEpChanged(SDnode *pDnode, int32_t dnodeId, const char *ep) {
|
||||
bool changed = false;
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
taosRLockLatch(&pDnode->data.latch);
|
||||
|
||||
SDnodeEp *pDnodeEp = taosHashGet(pMgmt->dnodeHash, &dnodeId, sizeof(int32_t));
|
||||
SDnodeEp *pDnodeEp = taosHashGet(pDnode->data.dnodeHash, &dnodeId, sizeof(int32_t));
|
||||
if (pDnodeEp != NULL) {
|
||||
char epstr[TSDB_EP_LEN + 1];
|
||||
snprintf(epstr, TSDB_EP_LEN, "%s:%u", pDnodeEp->ep.fqdn, pDnodeEp->ep.port);
|
||||
changed = strcmp(ep, epstr) != 0;
|
||||
}
|
||||
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
taosRUnLockLatch(&pDnode->data.latch);
|
||||
return changed;
|
||||
}
|
|
@ -0,0 +1,339 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dmImp.h"
|
||||
|
||||
static bool dmRequireNode(SMgmtWrapper *pWrapper) {
|
||||
bool required = false;
|
||||
int32_t code = (*pWrapper->fp.requiredFp)(pWrapper, &required);
|
||||
if (!required) {
|
||||
dDebug("node:%s, does not require startup", pWrapper->name);
|
||||
}
|
||||
return required;
|
||||
}
|
||||
|
||||
static int32_t dmInitParentProc(SMgmtWrapper *pWrapper) {
|
||||
int32_t shmsize = tsMnodeShmSize;
|
||||
if (pWrapper->ntype == VNODE) {
|
||||
shmsize = tsVnodeShmSize;
|
||||
} else if (pWrapper->ntype == QNODE) {
|
||||
shmsize = tsQnodeShmSize;
|
||||
} else if (pWrapper->ntype == SNODE) {
|
||||
shmsize = tsSnodeShmSize;
|
||||
} else if (pWrapper->ntype == MNODE) {
|
||||
shmsize = tsMnodeShmSize;
|
||||
} else if (pWrapper->ntype == BNODE) {
|
||||
shmsize = tsBnodeShmSize;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosCreateShm(&pWrapper->procShm, pWrapper->ntype, shmsize) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(terrno);
|
||||
dError("node:%s, failed to create shm size:%d since %s", pWrapper->name, shmsize, terrstr());
|
||||
return -1;
|
||||
}
|
||||
dInfo("node:%s, shm:%d is created, size:%d", pWrapper->name, pWrapper->procShm.id, shmsize);
|
||||
|
||||
SProcCfg cfg = dmGenProcCfg(pWrapper);
|
||||
cfg.isChild = false;
|
||||
pWrapper->procType = DND_PROC_PARENT;
|
||||
pWrapper->procObj = taosProcInit(&cfg);
|
||||
if (pWrapper->procObj == NULL) {
|
||||
dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dmNewNodeProc(SMgmtWrapper *pWrapper, EDndNodeType n) {
|
||||
char tstr[8] = {0};
|
||||
char *args[6] = {0};
|
||||
snprintf(tstr, sizeof(tstr), "%d", n);
|
||||
args[1] = "-c";
|
||||
args[2] = configDir;
|
||||
args[3] = "-n";
|
||||
args[4] = tstr;
|
||||
args[5] = NULL;
|
||||
|
||||
int32_t pid = taosNewProc(args);
|
||||
if (pid <= 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("node:%s, failed to exec in new process since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
pWrapper->procId = pid;
|
||||
dInfo("node:%s, continue running in new process:%d", pWrapper->name, pid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dmRunParentProc(SMgmtWrapper *pWrapper) {
|
||||
if (pWrapper->pDnode->ntype == NODE_END) {
|
||||
dInfo("node:%s, should be started manually in child process", pWrapper->name);
|
||||
} else {
|
||||
if (dmNewNodeProc(pWrapper, pWrapper->ntype) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (taosProcRun(pWrapper->procObj) != 0) {
|
||||
dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dmInitChildProc(SMgmtWrapper *pWrapper) {
|
||||
SProcCfg cfg = dmGenProcCfg(pWrapper);
|
||||
cfg.isChild = true;
|
||||
pWrapper->procObj = taosProcInit(&cfg);
|
||||
if (pWrapper->procObj == NULL) {
|
||||
dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dmRunChildProc(SMgmtWrapper *pWrapper) {
|
||||
if (taosProcRun(pWrapper->procObj) != 0) {
|
||||
dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dmOpenNode(SMgmtWrapper *pWrapper) {
|
||||
if (taosMkDir(pWrapper->path) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pWrapper->procType == DND_PROC_SINGLE || pWrapper->procType == DND_PROC_CHILD) {
|
||||
if ((*pWrapper->fp.openFp)(pWrapper) != 0) {
|
||||
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
if (pWrapper->procType == DND_PROC_CHILD) {
|
||||
if (dmInitChildProc(pWrapper) != 0) return -1;
|
||||
if (dmRunChildProc(pWrapper) != 0) return -1;
|
||||
}
|
||||
dDebug("node:%s, has been opened", pWrapper->name);
|
||||
pWrapper->deployed = true;
|
||||
} else {
|
||||
if (dmInitParentProc(pWrapper) != 0) return -1;
|
||||
if (dmWriteShmFile(pWrapper) != 0) return -1;
|
||||
if (dmRunParentProc(pWrapper) != 0) return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dmStartNode(SMgmtWrapper *pWrapper) {
|
||||
if (pWrapper->procType == DND_PROC_PARENT) {
|
||||
dInfo("node:%s, not start in parent process", pWrapper->name);
|
||||
} else if (pWrapper->procType == DND_PROC_CHILD) {
|
||||
dInfo("node:%s, start in child process", pWrapper->name);
|
||||
if (pWrapper->ntype != DNODE) {
|
||||
if (pWrapper->fp.startFp != NULL && (*pWrapper->fp.startFp)(pWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (pWrapper->fp.startFp != NULL && (*pWrapper->fp.startFp)(pWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dmStopNode(SMgmtWrapper *pWrapper) {
|
||||
if (pWrapper->fp.stopFp != NULL) {
|
||||
(*pWrapper->fp.stopFp)(pWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
void dmCloseNode(SMgmtWrapper *pWrapper) {
|
||||
dInfo("node:%s, start to close", pWrapper->name);
|
||||
if (pWrapper->procType == DND_PROC_PARENT) {
|
||||
if (pWrapper->procId > 0 && taosProcExist(pWrapper->procId)) {
|
||||
dInfo("node:%s, send kill signal to the child process:%d", pWrapper->name, pWrapper->procId);
|
||||
taosKillProc(pWrapper->procId);
|
||||
dInfo("node:%s, wait for child process:%d to stop", pWrapper->name, pWrapper->procId);
|
||||
taosWaitProc(pWrapper->procId);
|
||||
dInfo("node:%s, child process:%d is stopped", pWrapper->name, pWrapper->procId);
|
||||
}
|
||||
}
|
||||
|
||||
dmStopNode(pWrapper);
|
||||
|
||||
pWrapper->required = false;
|
||||
taosWLockLatch(&pWrapper->latch);
|
||||
if (pWrapper->deployed) {
|
||||
(*pWrapper->fp.closeFp)(pWrapper);
|
||||
pWrapper->deployed = false;
|
||||
}
|
||||
taosWUnLockLatch(&pWrapper->latch);
|
||||
|
||||
while (pWrapper->refCount > 0) {
|
||||
taosMsleep(10);
|
||||
}
|
||||
|
||||
if (pWrapper->procObj) {
|
||||
taosProcCleanup(pWrapper->procObj);
|
||||
pWrapper->procObj = NULL;
|
||||
}
|
||||
|
||||
dInfo("node:%s, has been closed", pWrapper->name);
|
||||
}
|
||||
|
||||
static int32_t dmOpenNodes(SDnode *pDnode) {
|
||||
if (pDnode->ptype == DND_PROC_CHILD) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype];
|
||||
pWrapper->required = dmRequireNode(pWrapper);
|
||||
if (!pWrapper->required) {
|
||||
dError("dnode:%s, failed to open since not required", pWrapper->name);
|
||||
}
|
||||
|
||||
pWrapper->procType = DND_PROC_CHILD;
|
||||
|
||||
SMsgCb msgCb = pDnode->data.msgCb;
|
||||
msgCb.pWrapper = pWrapper;
|
||||
tmsgSetDefaultMsgCb(&msgCb);
|
||||
|
||||
if (dmOpenNode(pWrapper) != 0) {
|
||||
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
for (EDndNodeType n = DNODE; n < NODE_END; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
pWrapper->required = dmRequireNode(pWrapper);
|
||||
if (!pWrapper->required) continue;
|
||||
|
||||
if (pDnode->ptype == DND_PROC_PARENT && n != DNODE) {
|
||||
pWrapper->procType = DND_PROC_PARENT;
|
||||
} else {
|
||||
pWrapper->procType = DND_PROC_SINGLE;
|
||||
}
|
||||
|
||||
if (dmOpenNode(pWrapper) != 0) {
|
||||
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dmSetStatus(pDnode, DND_STAT_RUNNING);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dmStartNodes(SDnode *pDnode) {
|
||||
for (EDndNodeType n = DNODE; n < NODE_END; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
if (!pWrapper->required) continue;
|
||||
if (dmStartNode(pWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
dInfo("TDengine initialized successfully");
|
||||
dmReportStartup(pDnode, "TDengine", "initialized successfully");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dmStopNodes(SDnode *pDnode) {
|
||||
for (EDndNodeType n = DNODE; n < NODE_END; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
dmStopNode(pWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
static void dmCloseNodes(SDnode *pDnode) {
|
||||
for (EDndNodeType n = DNODE; n < NODE_END; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
dmCloseNode(pWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
static void dmProcessProcHandle(void *handle) {
|
||||
dWarn("handle:%p, the child process dies and send an offline rsp", handle);
|
||||
SRpcMsg rpcMsg = {.handle = handle, .code = TSDB_CODE_NODE_OFFLINE};
|
||||
rpcSendResponse(&rpcMsg);
|
||||
}
|
||||
|
||||
static void dmWatchNodes(SDnode *pDnode) {
|
||||
taosThreadMutexLock(&pDnode->mutex);
|
||||
if (pDnode->ptype == DND_PROC_PARENT) {
|
||||
for (EDndNodeType n = DNODE + 1; n < NODE_END; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
if (!pWrapper->required) continue;
|
||||
if (pWrapper->procType != DND_PROC_PARENT) continue;
|
||||
if (pDnode->ntype == NODE_END) continue;
|
||||
|
||||
if (pWrapper->procId <= 0 || !taosProcExist(pWrapper->procId)) {
|
||||
dWarn("node:%s, process:%d is killed and needs to be restarted", pWrapper->name, pWrapper->procId);
|
||||
if (pWrapper->procObj) {
|
||||
taosProcCloseHandles(pWrapper->procObj, dmProcessProcHandle);
|
||||
}
|
||||
dmNewNodeProc(pWrapper, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
taosThreadMutexUnlock(&pDnode->mutex);
|
||||
}
|
||||
|
||||
int32_t dmRun(SDnode *pDnode) {
|
||||
if (!tsMultiProcess) {
|
||||
pDnode->ptype = DND_PROC_SINGLE;
|
||||
dInfo("dnode run in single process");
|
||||
} else if (pDnode->ntype == DNODE || pDnode->ntype == NODE_END) {
|
||||
pDnode->ptype = DND_PROC_PARENT;
|
||||
dInfo("dnode run in parent process");
|
||||
} else {
|
||||
pDnode->ptype = DND_PROC_CHILD;
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype];
|
||||
dInfo("%s run in child process", pWrapper->name);
|
||||
}
|
||||
|
||||
if (dmOpenNodes(pDnode) != 0) {
|
||||
dError("failed to open nodes since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dmStartNodes(pDnode) != 0) {
|
||||
dError("failed to start nodes since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
taosMsleep(100);
|
||||
if (pDnode->event & DND_EVENT_STOP) {
|
||||
dInfo("dnode is about to stop");
|
||||
dmSetStatus(pDnode, DND_STAT_STOPPED);
|
||||
dmStopNodes(pDnode);
|
||||
dmCloseNodes(pDnode);
|
||||
return 0;
|
||||
} else {
|
||||
dmWatchNodes(pDnode);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,274 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http:www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dmImp.h"
|
||||
|
||||
static void dmUpdateDnodeCfg(SDnode *pDnode, SDnodeCfg *pCfg) {
|
||||
if (pDnode->data.dnodeId == 0) {
|
||||
dInfo("set dnodeId:%d clusterId:%" PRId64, pCfg->dnodeId, pCfg->clusterId);
|
||||
taosWLockLatch(&pDnode->data.latch);
|
||||
pDnode->data.dnodeId = pCfg->dnodeId;
|
||||
pDnode->data.clusterId = pCfg->clusterId;
|
||||
dmWriteEps(pDnode);
|
||||
taosWUnLockLatch(&pDnode->data.latch);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t dmProcessStatusRsp(SDnode *pDnode, SRpcMsg *pRsp) {
|
||||
if (pRsp->code != TSDB_CODE_SUCCESS) {
|
||||
if (pRsp->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pDnode->data.dropped && pDnode->data.dnodeId > 0) {
|
||||
dInfo("dnode:%d, set to dropped since not exist in mnode", pDnode->data.dnodeId);
|
||||
pDnode->data.dropped = 1;
|
||||
dmWriteEps(pDnode);
|
||||
}
|
||||
} else {
|
||||
SStatusRsp statusRsp = {0};
|
||||
if (pRsp->pCont != NULL && pRsp->contLen > 0 &&
|
||||
tDeserializeSStatusRsp(pRsp->pCont, pRsp->contLen, &statusRsp) == 0) {
|
||||
pDnode->data.dnodeVer = statusRsp.dnodeVer;
|
||||
dmUpdateDnodeCfg(pDnode, &statusRsp.dnodeCfg);
|
||||
dmUpdateEps(pDnode, statusRsp.pDnodeEps);
|
||||
}
|
||||
tFreeSStatusRsp(&statusRsp);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void dmSendStatusReq(SDnode *pDnode) {
|
||||
SStatusReq req = {0};
|
||||
|
||||
taosRLockLatch(&pDnode->data.latch);
|
||||
req.sver = tsVersion;
|
||||
req.dnodeVer = pDnode->data.dnodeVer;
|
||||
req.dnodeId = pDnode->data.dnodeId;
|
||||
req.clusterId = pDnode->data.clusterId;
|
||||
req.rebootTime = pDnode->data.rebootTime;
|
||||
req.updateTime = pDnode->data.updateTime;
|
||||
req.numOfCores = tsNumOfCores;
|
||||
req.numOfSupportVnodes = pDnode->data.supportVnodes;
|
||||
tstrncpy(req.dnodeEp, pDnode->data.localEp, TSDB_EP_LEN);
|
||||
|
||||
req.clusterCfg.statusInterval = tsStatusInterval;
|
||||
req.clusterCfg.checkTime = 0;
|
||||
char timestr[32] = "1970-01-01 00:00:00.00";
|
||||
(void)taosParseTime(timestr, &req.clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0);
|
||||
memcpy(req.clusterCfg.timezone, tsTimezoneStr, TD_TIMEZONE_LEN);
|
||||
memcpy(req.clusterCfg.locale, tsLocale, TD_LOCALE_LEN);
|
||||
memcpy(req.clusterCfg.charset, tsCharset, TD_LOCALE_LEN);
|
||||
taosRUnLockLatch(&pDnode->data.latch);
|
||||
|
||||
SMonVloadInfo info = {0};
|
||||
dmGetVnodeLoads(pDnode, &info);
|
||||
req.pVloads = info.pVloads;
|
||||
|
||||
int32_t contLen = tSerializeSStatusReq(NULL, 0, &req);
|
||||
void *pHead = rpcMallocCont(contLen);
|
||||
tSerializeSStatusReq(pHead, contLen, &req);
|
||||
tFreeSStatusReq(&req);
|
||||
|
||||
SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_STATUS, .ahandle = (void *)0x9527};
|
||||
SRpcMsg rpcRsp = {0};
|
||||
|
||||
dTrace("send req:%s to mnode, app:%p", TMSG_INFO(rpcMsg.msgType), rpcMsg.ahandle);
|
||||
dmSendToMnodeRecv(pDnode, &rpcMsg, &rpcRsp);
|
||||
dmProcessStatusRsp(pDnode, &rpcRsp);
|
||||
}
|
||||
|
||||
int32_t dmProcessAuthRsp(SDnode *pDnode, SNodeMsg *pMsg) {
|
||||
SRpcMsg *pRsp = &pMsg->rpcMsg;
|
||||
dError("auth rsp is received, but not supported yet");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dmProcessGrantRsp(SDnode *pDnode, SNodeMsg *pMsg) {
|
||||
SRpcMsg *pRsp = &pMsg->rpcMsg;
|
||||
dError("grant rsp is received, but not supported yet");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dmProcessConfigReq(SDnode *pDnode, SNodeMsg *pMsg) {
|
||||
SRpcMsg *pReq = &pMsg->rpcMsg;
|
||||
SDCfgDnodeReq *pCfg = pReq->pCont;
|
||||
dError("config req is received, but not supported yet");
|
||||
return TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
int32_t dmProcessCreateNodeReq(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg) {
|
||||
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
|
||||
if (pWrapper != NULL) {
|
||||
dmReleaseWrapper(pWrapper);
|
||||
terrno = TSDB_CODE_NODE_ALREADY_DEPLOYED;
|
||||
dError("failed to create node since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosThreadMutexLock(&pDnode->mutex);
|
||||
pWrapper = &pDnode->wrappers[ntype];
|
||||
|
||||
if (taosMkDir(pWrapper->path) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create dir:%s since %s", pWrapper->path, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = (*pWrapper->fp.createFp)(pWrapper, pMsg);
|
||||
if (code != 0) {
|
||||
dError("node:%s, failed to create since %s", pWrapper->name, terrstr());
|
||||
} else {
|
||||
dDebug("node:%s, has been created", pWrapper->name);
|
||||
pWrapper->required = true;
|
||||
pWrapper->deployed = true;
|
||||
pWrapper->procType = pDnode->ptype;
|
||||
(void)dmOpenNode(pWrapper);
|
||||
}
|
||||
|
||||
taosThreadMutexUnlock(&pDnode->mutex);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t dmProcessDropNodeReq(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg) {
|
||||
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
|
||||
if (pWrapper == NULL) {
|
||||
terrno = TSDB_CODE_NODE_NOT_DEPLOYED;
|
||||
dError("failed to drop node since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosThreadMutexLock(&pDnode->mutex);
|
||||
|
||||
int32_t code = (*pWrapper->fp.dropFp)(pWrapper, pMsg);
|
||||
if (code != 0) {
|
||||
dError("node:%s, failed to drop since %s", pWrapper->name, terrstr());
|
||||
} else {
|
||||
dDebug("node:%s, has been dropped", pWrapper->name);
|
||||
}
|
||||
|
||||
dmReleaseWrapper(pWrapper);
|
||||
|
||||
if (code == 0) {
|
||||
dmCloseNode(pWrapper);
|
||||
pWrapper->required = false;
|
||||
pWrapper->deployed = false;
|
||||
taosRemoveDir(pWrapper->path);
|
||||
}
|
||||
taosThreadMutexUnlock(&pDnode->mutex);
|
||||
return code;
|
||||
}
|
||||
|
||||
static void dmSetMgmtMsgHandle(SMgmtWrapper *pWrapper) {
|
||||
// Requests handled by DNODE
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
|
||||
// Requests handled by MNODE
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_GRANT_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_AUTH_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE);
|
||||
}
|
||||
|
||||
static int32_t dmStartMgmt(SMgmtWrapper *pWrapper) {
|
||||
if (dmStartStatusThread(pWrapper->pDnode) != 0) {
|
||||
return -1;
|
||||
}
|
||||
if (dmStartMonitorThread(pWrapper->pDnode) != 0) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dmStopMgmt(SMgmtWrapper *pWrapper) {
|
||||
dmStopMonitorThread(pWrapper->pDnode);
|
||||
dmStopStatusThread(pWrapper->pDnode);
|
||||
}
|
||||
|
||||
static int32_t dmInitMgmt(SMgmtWrapper *pWrapper) {
|
||||
dInfo("dnode-mgmt start to init");
|
||||
SDnode *pDnode = pWrapper->pDnode;
|
||||
|
||||
pDnode->data.dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||
if (pDnode->data.dnodeHash == NULL) {
|
||||
dError("failed to init dnode hash");
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dmReadEps(pDnode) != 0) {
|
||||
dError("failed to read file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pDnode->data.dropped) {
|
||||
dError("dnode will not start since its already dropped");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dmStartWorker(pDnode) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dmInitTrans(pDnode) != 0) {
|
||||
dError("failed to init transport since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("dnode-mgmt is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dmCleanupMgmt(SMgmtWrapper *pWrapper) {
|
||||
dInfo("dnode-mgmt start to clean up");
|
||||
SDnode *pDnode = pWrapper->pDnode;
|
||||
dmStopWorker(pDnode);
|
||||
|
||||
taosWLockLatch(&pDnode->data.latch);
|
||||
if (pDnode->data.dnodeEps != NULL) {
|
||||
taosArrayDestroy(pDnode->data.dnodeEps);
|
||||
pDnode->data.dnodeEps = NULL;
|
||||
}
|
||||
if (pDnode->data.dnodeHash != NULL) {
|
||||
taosHashCleanup(pDnode->data.dnodeHash);
|
||||
pDnode->data.dnodeHash = NULL;
|
||||
}
|
||||
taosWUnLockLatch(&pDnode->data.latch);
|
||||
|
||||
dmCleanupTrans(pDnode);
|
||||
dInfo("dnode-mgmt is cleaned up");
|
||||
}
|
||||
|
||||
static int32_t dmRequireMgmt(SMgmtWrapper *pWrapper, bool *required) {
|
||||
*required = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dmSetMgmtFp(SMgmtWrapper *pWrapper) {
|
||||
SMgmtFp mgmtFp = {0};
|
||||
mgmtFp.openFp = dmInitMgmt;
|
||||
mgmtFp.closeFp = dmCleanupMgmt;
|
||||
mgmtFp.startFp = dmStartMgmt;
|
||||
mgmtFp.stopFp = dmStopMgmt;
|
||||
mgmtFp.requiredFp = dmRequireMgmt;
|
||||
|
||||
dmSetMgmtMsgHandle(pWrapper);
|
||||
pWrapper->name = "dnode";
|
||||
pWrapper->fp = mgmtFp;
|
||||
}
|
|
@ -14,17 +14,17 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dmInt.h"
|
||||
#include "dmImp.h"
|
||||
|
||||
static void dmGetMonitorBasicInfo(SDnode *pDnode, SMonBasicInfo *pInfo) {
|
||||
pInfo->protocol = 1;
|
||||
pInfo->dnode_id = pDnode->dnodeId;
|
||||
pInfo->cluster_id = pDnode->clusterId;
|
||||
pInfo->dnode_id = pDnode->data.dnodeId;
|
||||
pInfo->cluster_id = pDnode->data.clusterId;
|
||||
tstrncpy(pInfo->dnode_ep, tsLocalEp, TSDB_EP_LEN);
|
||||
}
|
||||
|
||||
static void dmGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) {
|
||||
pInfo->uptime = (taosGetTimestampMs() - pDnode->rebootTime) / (86400000.0f);
|
||||
pInfo->uptime = (taosGetTimestampMs() - pDnode->data.rebootTime) / (86400000.0f);
|
||||
pInfo->has_mnode = pDnode->wrappers[MNODE].required;
|
||||
pInfo->has_qnode = pDnode->wrappers[QNODE].required;
|
||||
pInfo->has_snode = pDnode->wrappers[SNODE].required;
|
||||
|
@ -55,7 +55,7 @@ void dmSendMonitorReport(SDnode *pDnode) {
|
|||
SRpcMsg req = {0};
|
||||
SRpcMsg rsp;
|
||||
SEpSet epset = {.inUse = 0, .numOfEps = 1};
|
||||
tstrncpy(epset.eps[0].fqdn, tsLocalFqdn, TSDB_FQDN_LEN);
|
||||
tstrncpy(epset.eps[0].fqdn, pDnode->data.localFqdn, TSDB_FQDN_LEN);
|
||||
epset.eps[0].port = tsServerPort;
|
||||
|
||||
SMgmtWrapper *pWrapper = NULL;
|
||||
|
@ -64,14 +64,14 @@ void dmSendMonitorReport(SDnode *pDnode) {
|
|||
bool getFromAPI = !tsMultiProcess;
|
||||
pWrapper = &pDnode->wrappers[MNODE];
|
||||
if (getFromAPI) {
|
||||
if (dndMarkWrapper(pWrapper) == 0) {
|
||||
if (dmMarkWrapper(pWrapper) == 0) {
|
||||
mmGetMonitorInfo(pWrapper, &mmInfo);
|
||||
dndReleaseWrapper(pWrapper);
|
||||
dmReleaseWrapper(pWrapper);
|
||||
}
|
||||
} else {
|
||||
if (pWrapper->required) {
|
||||
req.msgType = TDMT_MON_MM_INFO;
|
||||
dndSendRecv(pDnode, &epset, &req, &rsp);
|
||||
dmSendRecv(pDnode, &epset, &req, &rsp);
|
||||
if (rsp.code == 0 && rsp.contLen > 0) {
|
||||
tDeserializeSMonMmInfo(rsp.pCont, rsp.contLen, &mmInfo);
|
||||
}
|
||||
|
@ -79,16 +79,16 @@ void dmSendMonitorReport(SDnode *pDnode) {
|
|||
}
|
||||
}
|
||||
|
||||
pWrapper = &pDnode->wrappers[VNODES];
|
||||
pWrapper = &pDnode->wrappers[VNODE];
|
||||
if (getFromAPI) {
|
||||
if (dndMarkWrapper(pWrapper) == 0) {
|
||||
if (dmMarkWrapper(pWrapper) == 0) {
|
||||
vmGetMonitorInfo(pWrapper, &vmInfo);
|
||||
dndReleaseWrapper(pWrapper);
|
||||
dmReleaseWrapper(pWrapper);
|
||||
}
|
||||
} else {
|
||||
if (pWrapper->required) {
|
||||
req.msgType = TDMT_MON_VM_INFO;
|
||||
dndSendRecv(pDnode, &epset, &req, &rsp);
|
||||
dmSendRecv(pDnode, &epset, &req, &rsp);
|
||||
if (rsp.code == 0 && rsp.contLen > 0) {
|
||||
tDeserializeSMonVmInfo(rsp.pCont, rsp.contLen, &vmInfo);
|
||||
}
|
||||
|
@ -98,14 +98,14 @@ void dmSendMonitorReport(SDnode *pDnode) {
|
|||
|
||||
pWrapper = &pDnode->wrappers[QNODE];
|
||||
if (getFromAPI) {
|
||||
if (dndMarkWrapper(pWrapper) == 0) {
|
||||
if (dmMarkWrapper(pWrapper) == 0) {
|
||||
qmGetMonitorInfo(pWrapper, &qmInfo);
|
||||
dndReleaseWrapper(pWrapper);
|
||||
dmReleaseWrapper(pWrapper);
|
||||
}
|
||||
} else {
|
||||
if (pWrapper->required) {
|
||||
req.msgType = TDMT_MON_QM_INFO;
|
||||
dndSendRecv(pDnode, &epset, &req, &rsp);
|
||||
dmSendRecv(pDnode, &epset, &req, &rsp);
|
||||
if (rsp.code == 0 && rsp.contLen > 0) {
|
||||
tDeserializeSMonQmInfo(rsp.pCont, rsp.contLen, &qmInfo);
|
||||
}
|
||||
|
@ -115,14 +115,14 @@ void dmSendMonitorReport(SDnode *pDnode) {
|
|||
|
||||
pWrapper = &pDnode->wrappers[SNODE];
|
||||
if (getFromAPI) {
|
||||
if (dndMarkWrapper(pWrapper) == 0) {
|
||||
if (dmMarkWrapper(pWrapper) == 0) {
|
||||
smGetMonitorInfo(pWrapper, &smInfo);
|
||||
dndReleaseWrapper(pWrapper);
|
||||
dmReleaseWrapper(pWrapper);
|
||||
}
|
||||
} else {
|
||||
if (pWrapper->required) {
|
||||
req.msgType = TDMT_MON_SM_INFO;
|
||||
dndSendRecv(pDnode, &epset, &req, &rsp);
|
||||
dmSendRecv(pDnode, &epset, &req, &rsp);
|
||||
if (rsp.code == 0 && rsp.contLen > 0) {
|
||||
tDeserializeSMonSmInfo(rsp.pCont, rsp.contLen, &smInfo);
|
||||
}
|
||||
|
@ -132,14 +132,14 @@ void dmSendMonitorReport(SDnode *pDnode) {
|
|||
|
||||
pWrapper = &pDnode->wrappers[BNODE];
|
||||
if (getFromAPI) {
|
||||
if (dndMarkWrapper(pWrapper) == 0) {
|
||||
if (dmMarkWrapper(pWrapper) == 0) {
|
||||
bmGetMonitorInfo(pWrapper, &bmInfo);
|
||||
dndReleaseWrapper(pWrapper);
|
||||
dmReleaseWrapper(pWrapper);
|
||||
}
|
||||
} else {
|
||||
if (pWrapper->required) {
|
||||
req.msgType = TDMT_MON_BM_INFO;
|
||||
dndSendRecv(pDnode, &epset, &req, &rsp);
|
||||
dmSendRecv(pDnode, &epset, &req, &rsp);
|
||||
if (rsp.code == 0 && rsp.contLen > 0) {
|
||||
tDeserializeSMonBmInfo(rsp.pCont, rsp.contLen, &bmInfo);
|
||||
}
|
||||
|
@ -161,7 +161,10 @@ void dmSendMonitorReport(SDnode *pDnode) {
|
|||
monSendReport();
|
||||
}
|
||||
|
||||
void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo) {
|
||||
void dmGetVnodeLoads(SDnode *pDnode, SMonVloadInfo *pInfo) {
|
||||
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, VNODE);
|
||||
if (pWrapper == NULL) return;
|
||||
|
||||
bool getFromAPI = !tsMultiProcess;
|
||||
if (getFromAPI) {
|
||||
vmGetVnodeLoads(pWrapper, pInfo);
|
||||
|
@ -169,26 +172,14 @@ void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo) {
|
|||
SRpcMsg req = {.msgType = TDMT_MON_VM_LOAD};
|
||||
SRpcMsg rsp = {0};
|
||||
SEpSet epset = {.inUse = 0, .numOfEps = 1};
|
||||
tstrncpy(epset.eps[0].fqdn, tsLocalFqdn, TSDB_FQDN_LEN);
|
||||
tstrncpy(epset.eps[0].fqdn, pDnode->data.localFqdn, TSDB_FQDN_LEN);
|
||||
epset.eps[0].port = tsServerPort;
|
||||
|
||||
dndSendRecv(pWrapper->pDnode, &epset, &req, &rsp);
|
||||
dmSendRecv(pDnode, &epset, &req, &rsp);
|
||||
if (rsp.code == 0 && rsp.contLen > 0) {
|
||||
tDeserializeSMonVloadInfo(rsp.pCont, rsp.contLen, pInfo);
|
||||
}
|
||||
rpcFreeCont(rsp.pCont);
|
||||
}
|
||||
}
|
||||
|
||||
void dmGetMonitorSysInfo(SMonSysInfo *pInfo) {
|
||||
taosGetCpuUsage(&pInfo->cpu_engine, &pInfo->cpu_system);
|
||||
taosGetCpuCores(&pInfo->cpu_cores);
|
||||
taosGetProcMemory(&pInfo->mem_engine);
|
||||
taosGetSysMemory(&pInfo->mem_system);
|
||||
pInfo->mem_total = tsTotalMemoryKB;
|
||||
pInfo->disk_engine = 0;
|
||||
pInfo->disk_used = tsDataSpace.size.used;
|
||||
pInfo->disk_total = tsDataSpace.size.total;
|
||||
taosGetCardInfoDelta(&pInfo->net_in, &pInfo->net_out);
|
||||
taosGetProcIODelta(&pInfo->io_read, &pInfo->io_write, &pInfo->io_read_disk, &pInfo->io_write_disk);
|
||||
dmReleaseWrapper(pWrapper);
|
||||
}
|
|
@ -0,0 +1,147 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dmImp.h"
|
||||
|
||||
static int32_t dmInitVars(SDnode *pDnode, const SDnodeOpt *pOption) {
|
||||
pDnode->data.dnodeId = 0;
|
||||
pDnode->data.clusterId = 0;
|
||||
pDnode->data.dnodeVer = 0;
|
||||
pDnode->data.updateTime = 0;
|
||||
pDnode->data.rebootTime = taosGetTimestampMs();
|
||||
pDnode->data.dropped = 0;
|
||||
pDnode->data.localEp = strdup(pOption->localEp);
|
||||
pDnode->data.localFqdn = strdup(pOption->localFqdn);
|
||||
pDnode->data.firstEp = strdup(pOption->firstEp);
|
||||
pDnode->data.secondEp = strdup(pOption->secondEp);
|
||||
pDnode->data.dataDir = strdup(pOption->dataDir);
|
||||
pDnode->data.disks = pOption->disks;
|
||||
pDnode->data.numOfDisks = pOption->numOfDisks;
|
||||
pDnode->data.supportVnodes = pOption->numOfSupportVnodes;
|
||||
pDnode->data.serverPort = pOption->serverPort;
|
||||
pDnode->ntype = pOption->ntype;
|
||||
|
||||
if (pDnode->data.dataDir == NULL || pDnode->data.localEp == NULL || pDnode->data.localFqdn == NULL ||
|
||||
pDnode->data.firstEp == NULL || pDnode->data.secondEp == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!tsMultiProcess || pDnode->ntype == DNODE || pDnode->ntype == NODE_END) {
|
||||
pDnode->data.lockfile = dmCheckRunning(pDnode->data.dataDir);
|
||||
if (pDnode->data.lockfile == NULL) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
taosInitRWLatch(&pDnode->data.latch);
|
||||
taosThreadMutexInit(&pDnode->mutex, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dmClearVars(SDnode *pDnode) {
|
||||
for (EDndNodeType n = DNODE; n < NODE_END; ++n) {
|
||||
SMgmtWrapper *pMgmt = &pDnode->wrappers[n];
|
||||
taosMemoryFreeClear(pMgmt->path);
|
||||
}
|
||||
if (pDnode->data.lockfile != NULL) {
|
||||
taosUnLockFile(pDnode->data.lockfile);
|
||||
taosCloseFile(&pDnode->data.lockfile);
|
||||
pDnode->data.lockfile = NULL;
|
||||
}
|
||||
taosMemoryFreeClear(pDnode->data.localEp);
|
||||
taosMemoryFreeClear(pDnode->data.localFqdn);
|
||||
taosMemoryFreeClear(pDnode->data.firstEp);
|
||||
taosMemoryFreeClear(pDnode->data.secondEp);
|
||||
taosMemoryFreeClear(pDnode->data.dataDir);
|
||||
taosThreadMutexDestroy(&pDnode->mutex);
|
||||
memset(&pDnode->mutex, 0, sizeof(pDnode->mutex));
|
||||
taosMemoryFree(pDnode);
|
||||
dDebug("dnode memory is cleared, data:%p", pDnode);
|
||||
}
|
||||
|
||||
SDnode *dmCreate(const SDnodeOpt *pOption) {
|
||||
dDebug("start to create dnode");
|
||||
int32_t code = -1;
|
||||
char path[PATH_MAX] = {0};
|
||||
SDnode *pDnode = NULL;
|
||||
|
||||
pDnode = taosMemoryCalloc(1, sizeof(SDnode));
|
||||
if (pDnode == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (dmInitVars(pDnode, pOption) != 0) {
|
||||
dError("failed to init variables since %s", terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
dmSetStatus(pDnode, DND_STAT_INIT);
|
||||
dmSetMgmtFp(&pDnode->wrappers[DNODE]);
|
||||
mmSetMgmtFp(&pDnode->wrappers[MNODE]);
|
||||
vmSetMgmtFp(&pDnode->wrappers[VNODE]);
|
||||
qmSetMgmtFp(&pDnode->wrappers[QNODE]);
|
||||
smSetMgmtFp(&pDnode->wrappers[SNODE]);
|
||||
bmSetMgmtFp(&pDnode->wrappers[BNODE]);
|
||||
|
||||
for (EDndNodeType n = DNODE; n < NODE_END; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
snprintf(path, sizeof(path), "%s%s%s", pDnode->data.dataDir, TD_DIRSEP, pWrapper->name);
|
||||
pWrapper->path = strdup(path);
|
||||
pWrapper->procShm.id = -1;
|
||||
pWrapper->pDnode = pDnode;
|
||||
pWrapper->ntype = n;
|
||||
pWrapper->procType = DND_PROC_SINGLE;
|
||||
taosInitRWLatch(&pWrapper->latch);
|
||||
|
||||
if (pWrapper->path == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (n != DNODE && dmReadShmFile(pWrapper) != 0) {
|
||||
dError("node:%s, failed to read shm file since %s", pWrapper->name, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
}
|
||||
|
||||
if (dmInitMsgHandle(pDnode) != 0) {
|
||||
dError("failed to init msg handles since %s", terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pDnode->data.msgCb = dmGetMsgcb(&pDnode->wrappers[DNODE]);
|
||||
tmsgSetDefaultMsgCb(&pDnode->data.msgCb);
|
||||
|
||||
dInfo("dnode is created, data:%p", pDnode);
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
if (code != 0 && pDnode) {
|
||||
dmClearVars(pDnode);
|
||||
pDnode = NULL;
|
||||
dError("failed to create dnode since %s", terrstr());
|
||||
}
|
||||
|
||||
return pDnode;
|
||||
}
|
||||
|
||||
void dmClose(SDnode *pDnode) {
|
||||
if (pDnode == NULL) return;
|
||||
dmClearVars(pDnode);
|
||||
dInfo("dnode is closed, data:%p", pDnode);
|
||||
}
|
|
@ -14,18 +14,31 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndInt.h"
|
||||
#include "dmImp.h"
|
||||
|
||||
#define INTERNAL_USER "_dnd"
|
||||
#define INTERNAL_CKEY "_key"
|
||||
#define INTERNAL_SECRET "_pwd"
|
||||
|
||||
static void dndUpdateMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[DNODE];
|
||||
dmUpdateMnodeEpSet(pWrapper->pMgmt, pEpSet);
|
||||
static void dmGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) {
|
||||
taosRLockLatch(&pDnode->data.latch);
|
||||
*pEpSet = pDnode->data.mnodeEps;
|
||||
taosRUnLockLatch(&pDnode->data.latch);
|
||||
}
|
||||
|
||||
static inline NodeMsgFp dndGetMsgFp(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) {
|
||||
static void dmSetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) {
|
||||
dInfo("mnode is changed, num:%d use:%d", pEpSet->numOfEps, pEpSet->inUse);
|
||||
|
||||
taosWLockLatch(&pDnode->data.latch);
|
||||
pDnode->data.mnodeEps = *pEpSet;
|
||||
for (int32_t i = 0; i < pEpSet->numOfEps; ++i) {
|
||||
dInfo("mnode index:%d %s:%u", i, pEpSet->eps[i].fqdn, pEpSet->eps[i].port);
|
||||
}
|
||||
|
||||
taosWUnLockLatch(&pDnode->data.latch);
|
||||
}
|
||||
|
||||
static inline NodeMsgFp dmGetMsgFp(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) {
|
||||
NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pRpc->msgType)];
|
||||
if (msgFp == NULL) {
|
||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
|
@ -34,7 +47,7 @@ static inline NodeMsgFp dndGetMsgFp(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) {
|
|||
return msgFp;
|
||||
}
|
||||
|
||||
static inline int32_t dndBuildMsg(SNodeMsg *pMsg, SRpcMsg *pRpc) {
|
||||
static inline int32_t dmBuildMsg(SNodeMsg *pMsg, SRpcMsg *pRpc) {
|
||||
SRpcConnInfo connInfo = {0};
|
||||
if ((pRpc->msgType & 1U) && rpcGetConnInfo(pRpc->handle, &connInfo) != 0) {
|
||||
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||
|
@ -49,28 +62,29 @@ static inline int32_t dndBuildMsg(SNodeMsg *pMsg, SRpcMsg *pRpc) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
||||
static void dmProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
||||
int32_t code = -1;
|
||||
SNodeMsg *pMsg = NULL;
|
||||
NodeMsgFp msgFp = NULL;
|
||||
uint16_t msgType = pRpc->msgType;
|
||||
uint16_t msgType = pRpc->msgType;
|
||||
|
||||
if (pEpSet && pEpSet->numOfEps > 0 && msgType == TDMT_MND_STATUS_RSP) {
|
||||
dndUpdateMnodeEpSet(pWrapper->pDnode, pEpSet);
|
||||
dmSetMnodeEpSet(pWrapper->pDnode, pEpSet);
|
||||
}
|
||||
|
||||
if (dndMarkWrapper(pWrapper) != 0) goto _OVER;
|
||||
if ((msgFp = dndGetMsgFp(pWrapper, pRpc)) == NULL) goto _OVER;
|
||||
if (dmMarkWrapper(pWrapper) != 0) goto _OVER;
|
||||
if ((msgFp = dmGetMsgFp(pWrapper, pRpc)) == NULL) goto _OVER;
|
||||
if ((pMsg = taosAllocateQitem(sizeof(SNodeMsg))) == NULL) goto _OVER;
|
||||
if (dndBuildMsg(pMsg, pRpc) != 0) goto _OVER;
|
||||
if (dmBuildMsg(pMsg, pRpc) != 0) goto _OVER;
|
||||
|
||||
if (pWrapper->procType == PROC_SINGLE) {
|
||||
dTrace("msg:%p, is created, handle:%p user:%s", pMsg, pRpc->handle, pMsg->user);
|
||||
if (pWrapper->procType == DND_PROC_SINGLE) {
|
||||
dTrace("msg:%p, is created, type:%s handle:%p user:%s", pMsg, TMSG_INFO(msgType), pRpc->handle, pMsg->user);
|
||||
code = (*msgFp)(pWrapper, pMsg);
|
||||
} else if (pWrapper->procType == PROC_PARENT) {
|
||||
dTrace("msg:%p, is created and put into child queue, handle:%p user:%s", pMsg, pRpc->handle, pMsg->user);
|
||||
code = taosProcPutToChildQ(pWrapper->pProc, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen, pRpc->handle,
|
||||
PROC_REQ);
|
||||
} else if (pWrapper->procType == DND_PROC_PARENT) {
|
||||
dTrace("msg:%p, is created and put into child queue, type:%s handle:%p user:%s", pMsg, TMSG_INFO(msgType),
|
||||
pRpc->handle, pMsg->user);
|
||||
code = taosProcPutToChildQ(pWrapper->procObj, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen, pRpc->handle,
|
||||
PROC_FUNC_REQ);
|
||||
} else {
|
||||
dTrace("msg:%p, should not processed in child process, handle:%p user:%s", pMsg, pRpc->handle, pMsg->user);
|
||||
ASSERT(1);
|
||||
|
@ -78,13 +92,13 @@ static void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpS
|
|||
|
||||
_OVER:
|
||||
if (code == 0) {
|
||||
if (pWrapper->procType == PROC_PARENT) {
|
||||
if (pWrapper->procType == DND_PROC_PARENT) {
|
||||
dTrace("msg:%p, is freed in parent process", pMsg);
|
||||
taosFreeQitem(pMsg);
|
||||
rpcFreeCont(pRpc->pCont);
|
||||
}
|
||||
} else {
|
||||
dError("msg:%p, failed to process since 0x%04x:%s", pMsg, code & 0XFFFF, terrstr());
|
||||
dError("msg:%p, type:%s failed to process since 0x%04x:%s", pMsg, TMSG_INFO(msgType), code & 0XFFFF, terrstr());
|
||||
if (msgType & 1U) {
|
||||
if (terrno != 0) code = terrno;
|
||||
if (code == TSDB_CODE_NODE_NOT_DEPLOYED || code == TSDB_CODE_NODE_OFFLINE) {
|
||||
|
@ -101,23 +115,23 @@ _OVER:
|
|||
rpcFreeCont(pRpc->pCont);
|
||||
}
|
||||
|
||||
dndReleaseWrapper(pWrapper);
|
||||
dmReleaseWrapper(pWrapper);
|
||||
}
|
||||
|
||||
static void dndProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
STransMgmt *pMgmt = &pDnode->trans;
|
||||
static void dmProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
SDnodeTrans *pTrans = &pDnode->trans;
|
||||
tmsg_t msgType = pMsg->msgType;
|
||||
bool isReq = msgType & 1u;
|
||||
SMsgHandle *pHandle = &pMgmt->msgHandles[TMSG_INDEX(msgType)];
|
||||
SMgmtWrapper *pWrapper = pHandle->pWrapper;
|
||||
SMsgHandle *pHandle = &pTrans->msgHandles[TMSG_INDEX(msgType)];
|
||||
SMgmtWrapper *pWrapper = pHandle->pNdWrapper;
|
||||
|
||||
if (msgType == TDMT_DND_NETWORK_TEST) {
|
||||
dTrace("network test req will be processed, handle:%p, app:%p", pMsg->handle, pMsg->ahandle);
|
||||
dndProcessStartupReq(pDnode, pMsg);
|
||||
dmProcessStartupReq(pDnode, pMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dndGetStatus(pDnode) != DND_STAT_RUNNING) {
|
||||
if (pDnode->status != DND_STAT_RUNNING) {
|
||||
dError("msg:%s ignored since dnode not running, handle:%p app:%p", TMSG_INFO(msgType), pMsg->handle, pMsg->ahandle);
|
||||
if (isReq) {
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_APP_NOT_READY, .ahandle = pMsg->ahandle};
|
||||
|
@ -141,6 +155,7 @@ static void dndProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
|||
rpcSendResponse(&rspMsg);
|
||||
}
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pHandle->pMndWrapper != NULL || pHandle->pQndWrapper != NULL) {
|
||||
|
@ -155,17 +170,215 @@ static void dndProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
|||
}
|
||||
|
||||
dTrace("msg:%s will be processed by %s, app:%p", TMSG_INFO(msgType), pWrapper->name, pMsg->ahandle);
|
||||
dndProcessRpcMsg(pWrapper, pMsg, pEpSet);
|
||||
dmProcessRpcMsg(pWrapper, pMsg, pEpSet);
|
||||
}
|
||||
|
||||
static int32_t dndInitClient(SDnode *pDnode) {
|
||||
STransMgmt *pMgmt = &pDnode->trans;
|
||||
int32_t dmInitMsgHandle(SDnode *pDnode) {
|
||||
SDnodeTrans *pTrans = &pDnode->trans;
|
||||
|
||||
SRpcInit rpcInit;
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
for (EDndNodeType n = DNODE; n < NODE_END; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
|
||||
for (int32_t msgIndex = 0; msgIndex < TDMT_MAX; ++msgIndex) {
|
||||
NodeMsgFp msgFp = pWrapper->msgFps[msgIndex];
|
||||
int8_t vgId = pWrapper->msgVgIds[msgIndex];
|
||||
if (msgFp == NULL) continue;
|
||||
|
||||
SMsgHandle *pHandle = &pTrans->msgHandles[msgIndex];
|
||||
if (vgId == QNODE_HANDLE) {
|
||||
if (pHandle->pQndWrapper != NULL) {
|
||||
dError("msg:%s has multiple process nodes", tMsgInfo[msgIndex]);
|
||||
return -1;
|
||||
}
|
||||
pHandle->pQndWrapper = pWrapper;
|
||||
} else if (vgId == MNODE_HANDLE) {
|
||||
if (pHandle->pMndWrapper != NULL) {
|
||||
dError("msg:%s has multiple process nodes", tMsgInfo[msgIndex]);
|
||||
return -1;
|
||||
}
|
||||
pHandle->pMndWrapper = pWrapper;
|
||||
} else {
|
||||
if (pHandle->pNdWrapper != NULL) {
|
||||
dError("msg:%s has multiple process nodes", tMsgInfo[msgIndex]);
|
||||
return -1;
|
||||
}
|
||||
pHandle->pNdWrapper = pWrapper;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int32_t dmSendRpcReq(SDnode *pDnode, const SEpSet *pEpSet, SRpcMsg *pReq) {
|
||||
if (pDnode->trans.clientRpc == NULL) {
|
||||
terrno = TSDB_CODE_NODE_OFFLINE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
rpcSendRequest(pDnode->trans.clientRpc, pEpSet, pReq, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dmSendRpcRedirectRsp(SDnode *pDnode, const SRpcMsg *pReq) {
|
||||
SEpSet epSet = {0};
|
||||
dmGetMnodeEpSet(pDnode, &epSet);
|
||||
|
||||
dDebug("RPC %p, req is redirected, num:%d use:%d", pReq->handle, epSet.numOfEps, epSet.inUse);
|
||||
for (int32_t i = 0; i < epSet.numOfEps; ++i) {
|
||||
dDebug("mnode index:%d %s:%u", i, epSet.eps[i].fqdn, epSet.eps[i].port);
|
||||
if (strcmp(epSet.eps[i].fqdn, pDnode->data.localFqdn) == 0 && epSet.eps[i].port == pDnode->data.serverPort) {
|
||||
epSet.inUse = (i + 1) % epSet.numOfEps;
|
||||
}
|
||||
|
||||
epSet.eps[i].port = htons(epSet.eps[i].port);
|
||||
}
|
||||
|
||||
rpcSendRedirectRsp(pReq->handle, &epSet);
|
||||
}
|
||||
|
||||
static inline void dmSendRpcRsp(SDnode *pDnode, const SRpcMsg *pRsp) {
|
||||
if (pRsp->code == TSDB_CODE_NODE_REDIRECT) {
|
||||
dmSendRpcRedirectRsp(pDnode, pRsp);
|
||||
} else {
|
||||
rpcSendResponse(pRsp);
|
||||
}
|
||||
}
|
||||
|
||||
void dmSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp) {
|
||||
rpcSendRecv(pDnode->trans.clientRpc, pEpSet, pReq, pRsp);
|
||||
}
|
||||
|
||||
void dmSendToMnodeRecv(SDnode *pDnode, SRpcMsg *pReq, SRpcMsg *pRsp) {
|
||||
SEpSet epSet = {0};
|
||||
dmGetMnodeEpSet(pDnode, &epSet);
|
||||
rpcSendRecv(pDnode->trans.clientRpc, &epSet, pReq, pRsp);
|
||||
}
|
||||
|
||||
static inline int32_t dmSendReq(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pReq) {
|
||||
if (pWrapper->pDnode->status != DND_STAT_RUNNING) {
|
||||
terrno = TSDB_CODE_NODE_OFFLINE;
|
||||
dError("failed to send rpc msg since %s, handle:%p", terrstr(), pReq->handle);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pWrapper->procType != DND_PROC_CHILD) {
|
||||
return dmSendRpcReq(pWrapper->pDnode, pEpSet, pReq);
|
||||
} else {
|
||||
char *pHead = taosMemoryMalloc(sizeof(SRpcMsg) + sizeof(SEpSet));
|
||||
if (pHead == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(pHead, pReq, sizeof(SRpcMsg));
|
||||
memcpy(pHead + sizeof(SRpcMsg), pEpSet, sizeof(SEpSet));
|
||||
taosProcPutToParentQ(pWrapper->procObj, pHead, sizeof(SRpcMsg) + sizeof(SEpSet), pReq->pCont, pReq->contLen,
|
||||
PROC_FUNC_REQ);
|
||||
taosMemoryFree(pHead);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void dmSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) {
|
||||
if (pWrapper->procType != DND_PROC_CHILD) {
|
||||
dmSendRpcRsp(pWrapper->pDnode, pRsp);
|
||||
} else {
|
||||
taosProcPutToParentQ(pWrapper->procObj, pRsp, sizeof(SRpcMsg), pRsp->pCont, pRsp->contLen, PROC_FUNC_RSP);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void dmRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) {
|
||||
if (pWrapper->procType != DND_PROC_CHILD) {
|
||||
rpcRegisterBrokenLinkArg(pMsg);
|
||||
} else {
|
||||
taosProcPutToParentQ(pWrapper->procObj, pMsg, sizeof(SRpcMsg), pMsg->pCont, pMsg->contLen, PROC_FUNC_REGIST);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void dmReleaseHandle(SMgmtWrapper *pWrapper, void *handle, int8_t type) {
|
||||
if (pWrapper->procType != DND_PROC_CHILD) {
|
||||
rpcReleaseHandle(handle, type);
|
||||
} else {
|
||||
SRpcMsg msg = {.handle = handle, .code = type};
|
||||
taosProcPutToParentQ(pWrapper->procObj, &msg, sizeof(SRpcMsg), NULL, 0, PROC_FUNC_RELEASE);
|
||||
}
|
||||
}
|
||||
|
||||
static void dmConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen,
|
||||
EProcFuncType ftype) {
|
||||
SRpcMsg *pRpc = &pMsg->rpcMsg;
|
||||
pRpc->pCont = pCont;
|
||||
dTrace("msg:%p, get from child queue, handle:%p app:%p", pMsg, pRpc->handle, pRpc->ahandle);
|
||||
|
||||
NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pRpc->msgType)];
|
||||
int32_t code = (*msgFp)(pWrapper, pMsg);
|
||||
|
||||
if (code != 0) {
|
||||
dError("msg:%p, failed to process since code:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code));
|
||||
if (pRpc->msgType & 1U) {
|
||||
SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = terrno};
|
||||
dmSendRsp(pWrapper, &rsp);
|
||||
}
|
||||
|
||||
dTrace("msg:%p, is freed", pMsg);
|
||||
taosFreeQitem(pMsg);
|
||||
rpcFreeCont(pCont);
|
||||
}
|
||||
}
|
||||
|
||||
static void dmConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen,
|
||||
EProcFuncType ftype) {
|
||||
pMsg->pCont = pCont;
|
||||
dTrace("msg:%p, get from parent queue, ftype:%d handle:%p code:0x%04x mtype:%d, app:%p", pMsg, ftype, pMsg->handle,
|
||||
pMsg->code & 0xFFFF, pMsg->msgType, pMsg->ahandle);
|
||||
|
||||
switch (ftype) {
|
||||
case PROC_FUNC_REGIST:
|
||||
rpcRegisterBrokenLinkArg(pMsg);
|
||||
break;
|
||||
case PROC_FUNC_RELEASE:
|
||||
taosProcRemoveHandle(pWrapper->procObj, pMsg->handle);
|
||||
rpcReleaseHandle(pMsg->handle, (int8_t)pMsg->code);
|
||||
rpcFreeCont(pCont);
|
||||
break;
|
||||
case PROC_FUNC_REQ:
|
||||
dmSendRpcReq(pWrapper->pDnode, (SEpSet *)((char *)pMsg + sizeof(SRpcMsg)), pMsg);
|
||||
break;
|
||||
case PROC_FUNC_RSP:
|
||||
taosProcRemoveHandle(pWrapper->procObj, pMsg->handle);
|
||||
dmSendRpcRsp(pWrapper->pDnode, pMsg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
taosMemoryFree(pMsg);
|
||||
}
|
||||
|
||||
SProcCfg dmGenProcCfg(SMgmtWrapper *pWrapper) {
|
||||
SProcCfg cfg = {.childConsumeFp = (ProcConsumeFp)dmConsumeChildQueue,
|
||||
.childMallocHeadFp = (ProcMallocFp)taosAllocateQitem,
|
||||
.childFreeHeadFp = (ProcFreeFp)taosFreeQitem,
|
||||
.childMallocBodyFp = (ProcMallocFp)rpcMallocCont,
|
||||
.childFreeBodyFp = (ProcFreeFp)rpcFreeCont,
|
||||
.parentConsumeFp = (ProcConsumeFp)dmConsumeParentQueue,
|
||||
.parentMallocHeadFp = (ProcMallocFp)taosMemoryMalloc,
|
||||
.parentFreeHeadFp = (ProcFreeFp)taosMemoryFree,
|
||||
.parentMallocBodyFp = (ProcMallocFp)rpcMallocCont,
|
||||
.parentFreeBodyFp = (ProcFreeFp)rpcFreeCont,
|
||||
.shm = pWrapper->procShm,
|
||||
.parent = pWrapper,
|
||||
.name = pWrapper->name};
|
||||
return cfg;
|
||||
}
|
||||
|
||||
static int32_t dmInitClient(SDnode *pDnode) {
|
||||
SDnodeTrans *pTrans = &pDnode->trans;
|
||||
|
||||
SRpcInit rpcInit = {0};
|
||||
rpcInit.label = "DND";
|
||||
rpcInit.numOfThreads = 1;
|
||||
rpcInit.cfp = (RpcCfp)dndProcessMsg;
|
||||
rpcInit.cfp = (RpcCfp)dmProcessMsg;
|
||||
rpcInit.sessions = 1024;
|
||||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
rpcInit.idleTime = tsShellActivityTimer * 1000;
|
||||
|
@ -178,8 +391,8 @@ static int32_t dndInitClient(SDnode *pDnode) {
|
|||
taosEncryptPass_c((uint8_t *)(INTERNAL_SECRET), strlen(INTERNAL_SECRET), pass);
|
||||
rpcInit.secret = pass;
|
||||
|
||||
pMgmt->clientRpc = rpcOpen(&rpcInit);
|
||||
if (pMgmt->clientRpc == NULL) {
|
||||
pTrans->clientRpc = rpcOpen(&rpcInit);
|
||||
if (pTrans->clientRpc == NULL) {
|
||||
dError("failed to init dnode rpc client");
|
||||
return -1;
|
||||
}
|
||||
|
@ -188,24 +401,17 @@ static int32_t dndInitClient(SDnode *pDnode) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void dndCleanupClient(SDnode *pDnode) {
|
||||
STransMgmt *pMgmt = &pDnode->trans;
|
||||
if (pMgmt->clientRpc) {
|
||||
rpcClose(pMgmt->clientRpc);
|
||||
pMgmt->clientRpc = NULL;
|
||||
static void dmCleanupClient(SDnode *pDnode) {
|
||||
SDnodeTrans *pTrans = &pDnode->trans;
|
||||
if (pTrans->clientRpc) {
|
||||
rpcClose(pTrans->clientRpc);
|
||||
pTrans->clientRpc = NULL;
|
||||
dDebug("dnode rpc client is closed");
|
||||
}
|
||||
}
|
||||
|
||||
static inline void dndSendMsgToMnodeRecv(SDnode *pDnode, SRpcMsg *pReq, SRpcMsg *pRsp) {
|
||||
SEpSet epSet = {0};
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[DNODE];
|
||||
dmGetMnodeEpSet(pWrapper->pMgmt, &epSet);
|
||||
rpcSendRecv(pDnode->trans.clientRpc, &epSet, pReq, pRsp);
|
||||
}
|
||||
|
||||
static inline int32_t dndGetHideUserAuth(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret,
|
||||
char *ckey) {
|
||||
static inline int32_t dmGetHideUserAuth(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret,
|
||||
char *ckey) {
|
||||
int32_t code = 0;
|
||||
char pass[TSDB_PASSWORD_LEN + 1] = {0};
|
||||
|
||||
|
@ -227,8 +433,9 @@ static inline int32_t dndGetHideUserAuth(SDnode *pDnode, char *user, char *spi,
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t dndRetrieveUserAuthInfo(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) {
|
||||
if (dndGetHideUserAuth(pDnode, user, spi, encrypt, secret, ckey) == 0) {
|
||||
static inline int32_t dmRetrieveUserAuthInfo(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret,
|
||||
char *ckey) {
|
||||
if (dmGetHideUserAuth(pDnode, user, spi, encrypt, secret, ckey) == 0) {
|
||||
dTrace("user:%s, get auth from mnode, spi:%d encrypt:%d", user, *spi, *encrypt);
|
||||
return 0;
|
||||
}
|
||||
|
@ -242,7 +449,7 @@ static int32_t dndRetrieveUserAuthInfo(SDnode *pDnode, char *user, char *spi, ch
|
|||
SRpcMsg rpcMsg = {.pCont = pReq, .contLen = contLen, .msgType = TDMT_MND_AUTH, .ahandle = (void *)9528};
|
||||
SRpcMsg rpcRsp = {0};
|
||||
dTrace("user:%s, send user auth req to other mnodes, spi:%d encrypt:%d", user, authReq.spi, authReq.encrypt);
|
||||
dndSendMsgToMnodeRecv(pDnode, &rpcMsg, &rpcRsp);
|
||||
dmSendToMnodeRecv(pDnode, &rpcMsg, &rpcRsp);
|
||||
|
||||
if (rpcRsp.code != 0) {
|
||||
terrno = rpcRsp.code;
|
||||
|
@ -262,23 +469,22 @@ static int32_t dndRetrieveUserAuthInfo(SDnode *pDnode, char *user, char *spi, ch
|
|||
return rpcRsp.code;
|
||||
}
|
||||
|
||||
static int32_t dndInitServer(SDnode *pDnode) {
|
||||
STransMgmt *pMgmt = &pDnode->trans;
|
||||
static int32_t dmInitServer(SDnode *pDnode) {
|
||||
SDnodeTrans *pTrans = &pDnode->trans;
|
||||
|
||||
SRpcInit rpcInit;
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
rpcInit.localPort = pDnode->serverPort;
|
||||
SRpcInit rpcInit = {0};
|
||||
rpcInit.localPort = pDnode->data.serverPort;
|
||||
rpcInit.label = "DND";
|
||||
rpcInit.numOfThreads = tsNumOfRpcThreads;
|
||||
rpcInit.cfp = (RpcCfp)dndProcessMsg;
|
||||
rpcInit.cfp = (RpcCfp)dmProcessMsg;
|
||||
rpcInit.sessions = tsMaxShellConns;
|
||||
rpcInit.connType = TAOS_CONN_SERVER;
|
||||
rpcInit.idleTime = tsShellActivityTimer * 1000;
|
||||
rpcInit.afp = (RpcAfp)dndRetrieveUserAuthInfo;
|
||||
rpcInit.afp = (RpcAfp)dmRetrieveUserAuthInfo;
|
||||
rpcInit.parent = pDnode;
|
||||
|
||||
pMgmt->serverRpc = rpcOpen(&rpcInit);
|
||||
if (pMgmt->serverRpc == NULL) {
|
||||
pTrans->serverRpc = rpcOpen(&rpcInit);
|
||||
if (pTrans->serverRpc == NULL) {
|
||||
dError("failed to init dnode rpc server");
|
||||
return -1;
|
||||
}
|
||||
|
@ -287,209 +493,33 @@ static int32_t dndInitServer(SDnode *pDnode) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void dndCleanupServer(SDnode *pDnode) {
|
||||
STransMgmt *pMgmt = &pDnode->trans;
|
||||
if (pMgmt->serverRpc) {
|
||||
rpcClose(pMgmt->serverRpc);
|
||||
pMgmt->serverRpc = NULL;
|
||||
static void dmCleanupServer(SDnode *pDnode) {
|
||||
SDnodeTrans *pTrans = &pDnode->trans;
|
||||
if (pTrans->serverRpc) {
|
||||
rpcClose(pTrans->serverRpc);
|
||||
pTrans->serverRpc = NULL;
|
||||
dDebug("dnode rpc server is closed");
|
||||
}
|
||||
}
|
||||
|
||||
int32_t dndInitTrans(SDnode *pDnode) {
|
||||
if (dndInitServer(pDnode) != 0) return -1;
|
||||
if (dndInitClient(pDnode) != 0) return -1;
|
||||
int32_t dmInitTrans(SDnode *pDnode) {
|
||||
if (dmInitServer(pDnode) != 0) return -1;
|
||||
if (dmInitClient(pDnode) != 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dndCleanupTrans(SDnode *pDnode) {
|
||||
dndCleanupServer(pDnode);
|
||||
dndCleanupClient(pDnode);
|
||||
void dmCleanupTrans(SDnode *pDnode) {
|
||||
dmCleanupServer(pDnode);
|
||||
dmCleanupClient(pDnode);
|
||||
}
|
||||
|
||||
int32_t dndInitMsgHandle(SDnode *pDnode) {
|
||||
STransMgmt *pMgmt = &pDnode->trans;
|
||||
|
||||
for (EDndType n = 0; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
|
||||
for (int32_t msgIndex = 0; msgIndex < TDMT_MAX; ++msgIndex) {
|
||||
NodeMsgFp msgFp = pWrapper->msgFps[msgIndex];
|
||||
int8_t vgId = pWrapper->msgVgIds[msgIndex];
|
||||
if (msgFp == NULL) continue;
|
||||
|
||||
SMsgHandle *pHandle = &pMgmt->msgHandles[msgIndex];
|
||||
if (vgId == QNODE_HANDLE) {
|
||||
if (pHandle->pQndWrapper != NULL) {
|
||||
dError("msg:%s has multiple process nodes", tMsgInfo[msgIndex]);
|
||||
return -1;
|
||||
}
|
||||
pHandle->pQndWrapper = pWrapper;
|
||||
} else if (vgId == MNODE_HANDLE) {
|
||||
if (pHandle->pMndWrapper != NULL) {
|
||||
dError("msg:%s has multiple process nodes", tMsgInfo[msgIndex]);
|
||||
return -1;
|
||||
}
|
||||
pHandle->pMndWrapper = pWrapper;
|
||||
} else {
|
||||
if (pHandle->pWrapper != NULL) {
|
||||
dError("msg:%s has multiple process nodes", tMsgInfo[msgIndex]);
|
||||
return -1;
|
||||
}
|
||||
pHandle->pWrapper = pWrapper;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndSendRpcReq(STransMgmt *pMgmt, const SEpSet *pEpSet, SRpcMsg *pReq) {
|
||||
if (pMgmt->clientRpc == NULL) {
|
||||
terrno = TSDB_CODE_NODE_OFFLINE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
rpcSendRequest(pMgmt->clientRpc, pEpSet, pReq, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndSendRpcRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) {
|
||||
if (pRsp->code == TSDB_CODE_NODE_REDIRECT) {
|
||||
dmSendRedirectRsp(pWrapper->pMgmt, pRsp);
|
||||
} else {
|
||||
rpcSendResponse(pRsp);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t dndSendReq(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pReq) {
|
||||
if (dndGetStatus(pWrapper->pDnode) != DND_STAT_RUNNING) {
|
||||
terrno = TSDB_CODE_NODE_OFFLINE;
|
||||
dError("failed to send rpc msg since %s, handle:%p", terrstr(), pReq->handle);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pWrapper->procType != PROC_CHILD) {
|
||||
return dndSendRpcReq(&pWrapper->pDnode->trans, pEpSet, pReq);
|
||||
} else {
|
||||
char *pHead = taosMemoryMalloc(sizeof(SRpcMsg) + sizeof(SEpSet));
|
||||
if (pHead == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(pHead, pReq, sizeof(SRpcMsg));
|
||||
memcpy(pHead + sizeof(SRpcMsg), pEpSet, sizeof(SEpSet));
|
||||
taosProcPutToParentQ(pWrapper->pProc, pHead, sizeof(SRpcMsg) + sizeof(SEpSet), pReq->pCont, pReq->contLen,
|
||||
PROC_REQ);
|
||||
taosMemoryFree(pHead);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void dndSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) {
|
||||
if (pWrapper->procType != PROC_CHILD) {
|
||||
dndSendRpcRsp(pWrapper, pRsp);
|
||||
} else {
|
||||
taosProcPutToParentQ(pWrapper->pProc, pRsp, sizeof(SRpcMsg), pRsp->pCont, pRsp->contLen, PROC_RSP);
|
||||
}
|
||||
}
|
||||
|
||||
static void dndRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) {
|
||||
if (pWrapper->procType != PROC_CHILD) {
|
||||
rpcRegisterBrokenLinkArg(pMsg);
|
||||
} else {
|
||||
taosProcPutToParentQ(pWrapper->pProc, pMsg, sizeof(SRpcMsg), pMsg->pCont, pMsg->contLen, PROC_REGIST);
|
||||
}
|
||||
}
|
||||
|
||||
static void dndReleaseHandle(SMgmtWrapper *pWrapper, void *handle, int8_t type) {
|
||||
if (pWrapper->procType != PROC_CHILD) {
|
||||
rpcReleaseHandle(handle, type);
|
||||
} else {
|
||||
SRpcMsg msg = {.handle = handle, .code = type};
|
||||
taosProcPutToParentQ(pWrapper->pProc, &msg, sizeof(SRpcMsg), NULL, 0, PROC_RELEASE);
|
||||
}
|
||||
}
|
||||
|
||||
SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper) {
|
||||
SMsgCb dmGetMsgcb(SMgmtWrapper *pWrapper) {
|
||||
SMsgCb msgCb = {
|
||||
.sendReqFp = dmSendReq,
|
||||
.sendRspFp = dmSendRsp,
|
||||
.registerBrokenLinkArgFp = dmRegisterBrokenLinkArg,
|
||||
.releaseHandleFp = dmReleaseHandle,
|
||||
.pWrapper = pWrapper,
|
||||
.sendReqFp = dndSendReq,
|
||||
.sendRspFp = dndSendRsp,
|
||||
.registerBrokenLinkArgFp = dndRegisterBrokenLinkArg,
|
||||
.releaseHandleFp = dndReleaseHandle,
|
||||
};
|
||||
return msgCb;
|
||||
}
|
||||
|
||||
static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen,
|
||||
ProcFuncType ftype) {
|
||||
SRpcMsg *pRpc = &pMsg->rpcMsg;
|
||||
pRpc->pCont = pCont;
|
||||
dTrace("msg:%p, get from child queue, handle:%p app:%p", pMsg, pRpc->handle, pRpc->ahandle);
|
||||
|
||||
NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pRpc->msgType)];
|
||||
int32_t code = (*msgFp)(pWrapper, pMsg);
|
||||
|
||||
if (code != 0) {
|
||||
dError("msg:%p, failed to process since code:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code));
|
||||
if (pRpc->msgType & 1U) {
|
||||
SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = terrno};
|
||||
dndSendRsp(pWrapper, &rsp);
|
||||
}
|
||||
|
||||
dTrace("msg:%p, is freed", pMsg);
|
||||
taosFreeQitem(pMsg);
|
||||
rpcFreeCont(pCont);
|
||||
}
|
||||
}
|
||||
|
||||
static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen,
|
||||
ProcFuncType ftype) {
|
||||
pMsg->pCont = pCont;
|
||||
dTrace("msg:%p, get from parent queue, ftype:%d handle:%p code:0x%04x mtype:%d, app:%p", pMsg, ftype, pMsg->handle,
|
||||
pMsg->code & 0xFFFF, pMsg->msgType, pMsg->ahandle);
|
||||
|
||||
switch (ftype) {
|
||||
case PROC_REGIST:
|
||||
rpcRegisterBrokenLinkArg(pMsg);
|
||||
break;
|
||||
case PROC_RELEASE:
|
||||
taosProcRemoveHandle(pWrapper->pProc, pMsg->handle);
|
||||
rpcReleaseHandle(pMsg->handle, (int8_t)pMsg->code);
|
||||
rpcFreeCont(pCont);
|
||||
break;
|
||||
case PROC_REQ:
|
||||
dndSendRpcReq(&pWrapper->pDnode->trans, (SEpSet *)((char *)pMsg + sizeof(SRpcMsg)), pMsg);
|
||||
break;
|
||||
case PROC_RSP:
|
||||
taosProcRemoveHandle(pWrapper->pProc, pMsg->handle);
|
||||
dndSendRpcRsp(pWrapper, pMsg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
taosMemoryFree(pMsg);
|
||||
}
|
||||
|
||||
SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper) {
|
||||
SProcCfg cfg = {.childConsumeFp = (ProcConsumeFp)dndConsumeChildQueue,
|
||||
.childMallocHeadFp = (ProcMallocFp)taosAllocateQitem,
|
||||
.childFreeHeadFp = (ProcFreeFp)taosFreeQitem,
|
||||
.childMallocBodyFp = (ProcMallocFp)rpcMallocCont,
|
||||
.childFreeBodyFp = (ProcFreeFp)rpcFreeCont,
|
||||
.parentConsumeFp = (ProcConsumeFp)dndConsumeParentQueue,
|
||||
.parentMallocHeadFp = (ProcMallocFp)taosMemoryMalloc,
|
||||
.parentFreeHeadFp = (ProcFreeFp)taosMemoryFree,
|
||||
.parentMallocBodyFp = (ProcMallocFp)rpcMallocCont,
|
||||
.parentFreeBodyFp = (ProcFreeFp)rpcFreeCont,
|
||||
.shm = pWrapper->shm,
|
||||
.parent = pWrapper,
|
||||
.name = pWrapper->name};
|
||||
return cfg;
|
||||
}
|
||||
|
||||
void dndSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp) {
|
||||
rpcSendRecv(pDnode->trans.clientRpc, pEpSet, pReq, pRsp);
|
||||
}
|
|
@ -0,0 +1,181 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http:www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dmImp.h"
|
||||
|
||||
static void *dmStatusThreadFp(void *param) {
|
||||
SDnode *pDnode = param;
|
||||
int64_t lastTime = taosGetTimestampMs();
|
||||
|
||||
setThreadName("dnode-status");
|
||||
|
||||
while (1) {
|
||||
taosThreadTestCancel();
|
||||
taosMsleep(200);
|
||||
|
||||
if (pDnode->status != DND_STAT_RUNNING || pDnode->data.dropped) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int64_t curTime = taosGetTimestampMs();
|
||||
float interval = (curTime - lastTime) / 1000.0f;
|
||||
if (interval >= tsStatusInterval) {
|
||||
dmSendStatusReq(pDnode);
|
||||
lastTime = curTime;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *dmMonitorThreadFp(void *param) {
|
||||
SDnode *pDnode = param;
|
||||
int64_t lastTime = taosGetTimestampMs();
|
||||
|
||||
setThreadName("dnode-monitor");
|
||||
|
||||
while (1) {
|
||||
taosThreadTestCancel();
|
||||
taosMsleep(200);
|
||||
|
||||
if (pDnode->status != DND_STAT_RUNNING || pDnode->data.dropped) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int64_t curTime = taosGetTimestampMs();
|
||||
float interval = (curTime - lastTime) / 1000.0f;
|
||||
if (interval >= tsMonitorInterval) {
|
||||
dmSendMonitorReport(pDnode);
|
||||
lastTime = curTime;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t dmStartStatusThread(SDnode *pDnode) {
|
||||
pDnode->data.statusThreadId = taosCreateThread(dmStatusThreadFp, pDnode);
|
||||
if (pDnode->data.statusThreadId == NULL) {
|
||||
dError("failed to init dnode status thread");
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dmStopStatusThread(SDnode *pDnode) {
|
||||
if (pDnode->data.statusThreadId != NULL) {
|
||||
taosDestoryThread(pDnode->data.statusThreadId);
|
||||
pDnode->data.statusThreadId = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t dmStartMonitorThread(SDnode *pDnode) {
|
||||
pDnode->data.monitorThreadId = taosCreateThread(dmMonitorThreadFp, pDnode);
|
||||
if (pDnode->data.monitorThreadId == NULL) {
|
||||
dError("failed to init dnode monitor thread");
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dmStopMonitorThread(SDnode *pDnode) {
|
||||
if (pDnode->data.monitorThreadId != NULL) {
|
||||
taosDestoryThread(pDnode->data.monitorThreadId);
|
||||
pDnode->data.monitorThreadId = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void dmProcessMgmtQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) {
|
||||
SDnode *pDnode = pInfo->ahandle;
|
||||
SRpcMsg *pRpc = &pMsg->rpcMsg;
|
||||
int32_t code = -1;
|
||||
dTrace("msg:%p, will be processed in dnode-mgmt queue", pMsg);
|
||||
|
||||
switch (pRpc->msgType) {
|
||||
case TDMT_DND_CONFIG_DNODE:
|
||||
code = dmProcessConfigReq(pDnode, pMsg);
|
||||
break;
|
||||
case TDMT_MND_AUTH_RSP:
|
||||
code = dmProcessAuthRsp(pDnode, pMsg);
|
||||
break;
|
||||
case TDMT_MND_GRANT_RSP:
|
||||
code = dmProcessGrantRsp(pDnode, pMsg);
|
||||
break;
|
||||
case TDMT_DND_CREATE_MNODE:
|
||||
code = dmProcessCreateNodeReq(pDnode, MNODE, pMsg);
|
||||
break;
|
||||
case TDMT_DND_DROP_MNODE:
|
||||
code = dmProcessDropNodeReq(pDnode, MNODE, pMsg);
|
||||
break;
|
||||
case TDMT_DND_CREATE_QNODE:
|
||||
code = dmProcessCreateNodeReq(pDnode, QNODE, pMsg);
|
||||
break;
|
||||
case TDMT_DND_DROP_QNODE:
|
||||
code = dmProcessDropNodeReq(pDnode, QNODE, pMsg);
|
||||
break;
|
||||
case TDMT_DND_CREATE_SNODE:
|
||||
code = dmProcessCreateNodeReq(pDnode, SNODE, pMsg);
|
||||
break;
|
||||
case TDMT_DND_DROP_SNODE:
|
||||
code = dmProcessDropNodeReq(pDnode, SNODE, pMsg);
|
||||
break;
|
||||
case TDMT_DND_CREATE_BNODE:
|
||||
code = dmProcessCreateNodeReq(pDnode, BNODE, pMsg);
|
||||
break;
|
||||
case TDMT_DND_DROP_BNODE:
|
||||
code = dmProcessDropNodeReq(pDnode, BNODE, pMsg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (pRpc->msgType & 1u) {
|
||||
if (code != 0) code = terrno;
|
||||
SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = code};
|
||||
rpcSendResponse(&rsp);
|
||||
}
|
||||
|
||||
dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code));
|
||||
rpcFreeCont(pMsg->rpcMsg.pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
|
||||
int32_t dmStartWorker(SDnode *pDnode) {
|
||||
SSingleWorkerCfg cfg = {.min = 1, .max = 1, .name = "dnode-mgmt", .fp = (FItem)dmProcessMgmtQueue, .param = pDnode};
|
||||
if (tSingleWorkerInit(&pDnode->data.mgmtWorker, &cfg) != 0) {
|
||||
dError("failed to start dnode-mgmt worker since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("dnode workers are initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dmStopWorker(SDnode *pDnode) {
|
||||
tSingleWorkerCleanup(&pDnode->data.mgmtWorker);
|
||||
dDebug("dnode workers are closed");
|
||||
}
|
||||
|
||||
int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
||||
SSingleWorker *pWorker = &pWrapper->pDnode->data.mgmtWorker;
|
||||
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
||||
taosWriteQitem(pWorker->queue, pMsg);
|
||||
return 0;
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_DND_DNODE_INT_H_
|
||||
#define _TD_DND_DNODE_INT_H_
|
||||
|
||||
#include "dndInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SDnodeMgmt {
|
||||
int64_t dver;
|
||||
int64_t updateTime;
|
||||
int8_t statusSent;
|
||||
SEpSet mnodeEpSet;
|
||||
SHashObj *dnodeHash;
|
||||
SArray *dnodeEps;
|
||||
TdThread *threadId;
|
||||
SRWLatch latch;
|
||||
SSingleWorker mgmtWorker;
|
||||
SSingleWorker monitorWorker;
|
||||
SMsgCb msgCb;
|
||||
const char *path;
|
||||
SDnode *pDnode;
|
||||
SMgmtWrapper *pWrapper;
|
||||
} SDnodeMgmt;
|
||||
|
||||
// dmFile.c
|
||||
int32_t dmReadFile(SDnodeMgmt *pMgmt);
|
||||
int32_t dmWriteFile(SDnodeMgmt *pMgmt);
|
||||
void dmUpdateDnodeEps(SDnodeMgmt *pMgmt, SArray *pDnodeEps);
|
||||
|
||||
// dmHandle.c
|
||||
void dmInitMsgHandle(SMgmtWrapper *pWrapper);
|
||||
void dmSendStatusReq(SDnodeMgmt *pMgmt);
|
||||
int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SNodeMsg *pMsg);
|
||||
int32_t dmProcessStatusRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg);
|
||||
int32_t dmProcessAuthRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg);
|
||||
int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg);
|
||||
int32_t dmProcessCDnodeReq(SDnode *pDnode, SNodeMsg *pMsg);
|
||||
|
||||
// dmMonitor.c
|
||||
void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo);
|
||||
void dmSendMonitorReport(SDnode *pDnode);
|
||||
|
||||
// dmWorker.c
|
||||
int32_t dmStartThread(SDnodeMgmt *pMgmt);
|
||||
int32_t dmStartWorker(SDnodeMgmt *pMgmt);
|
||||
void dmStopWorker(SDnodeMgmt *pMgmt);
|
||||
int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
|
||||
int32_t dmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_DND_DNODE_INT_H_*/
|
|
@ -1,199 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_DND_INT_H_
|
||||
#define _TD_DND_INT_H_
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#include "cJSON.h"
|
||||
#include "tcache.h"
|
||||
#include "tcrc32c.h"
|
||||
#include "tdatablock.h"
|
||||
#include "tglobal.h"
|
||||
#include "thash.h"
|
||||
#include "tlockfree.h"
|
||||
#include "tlog.h"
|
||||
#include "tmsg.h"
|
||||
#include "tmsgcb.h"
|
||||
#include "tprocess.h"
|
||||
#include "tqueue.h"
|
||||
#include "trpc.h"
|
||||
#include "tthread.h"
|
||||
#include "ttime.h"
|
||||
#include "tworker.h"
|
||||
|
||||
#include "dnode.h"
|
||||
#include "monitor.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }}
|
||||
#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }}
|
||||
#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("DND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }}
|
||||
#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("DND ", DEBUG_INFO, 255, __VA_ARGS__); }}
|
||||
#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", DEBUG_DEBUG, dDebugFlag, __VA_ARGS__); }}
|
||||
#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", DEBUG_TRACE, dDebugFlag, __VA_ARGS__); }}
|
||||
|
||||
typedef enum { DNODE, VNODES, QNODE, SNODE, MNODE, BNODE, NODE_MAX } EDndType;
|
||||
typedef enum { DND_STAT_INIT, DND_STAT_RUNNING, DND_STAT_STOPPED } EDndStatus;
|
||||
typedef enum { DND_ENV_INIT, DND_ENV_READY, DND_ENV_CLEANUP } EEnvStatus;
|
||||
typedef enum { PROC_SINGLE, PROC_CHILD, PROC_PARENT } EProcType;
|
||||
|
||||
typedef struct SMgmtFp SMgmtFp;
|
||||
typedef struct SMgmtWrapper SMgmtWrapper;
|
||||
typedef struct SMsgHandle SMsgHandle;
|
||||
typedef struct SDnodeMgmt SDnodeMgmt;
|
||||
typedef struct SVnodesMgmt SVnodesMgmt;
|
||||
typedef struct SMnodeMgmt SMnodeMgmt;
|
||||
typedef struct SQnodeMgmt SQnodeMgmt;
|
||||
typedef struct SSnodeMgmt SSnodeMgmt;
|
||||
typedef struct SBnodeMgmt SBnodeMgmt;
|
||||
|
||||
typedef int32_t (*NodeMsgFp)(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
|
||||
typedef int32_t (*OpenNodeFp)(SMgmtWrapper *pWrapper);
|
||||
typedef void (*CloseNodeFp)(SMgmtWrapper *pWrapper);
|
||||
typedef int32_t (*StartNodeFp)(SMgmtWrapper *pWrapper);
|
||||
typedef int32_t (*CreateNodeFp)(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
|
||||
typedef int32_t (*DropNodeFp)(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
|
||||
typedef int32_t (*RequireNodeFp)(SMgmtWrapper *pWrapper, bool *required);
|
||||
|
||||
typedef struct SMsgHandle {
|
||||
SMgmtWrapper *pQndWrapper;
|
||||
SMgmtWrapper *pMndWrapper;
|
||||
SMgmtWrapper *pWrapper;
|
||||
} SMsgHandle;
|
||||
|
||||
typedef struct SMgmtFp {
|
||||
OpenNodeFp openFp;
|
||||
CloseNodeFp closeFp;
|
||||
StartNodeFp startFp;
|
||||
CreateNodeFp createMsgFp;
|
||||
DropNodeFp dropMsgFp;
|
||||
RequireNodeFp requiredFp;
|
||||
} SMgmtFp;
|
||||
|
||||
typedef struct SMgmtWrapper {
|
||||
const char *name;
|
||||
char *path;
|
||||
int32_t refCount;
|
||||
SRWLatch latch;
|
||||
EDndType ntype;
|
||||
bool deployed;
|
||||
bool required;
|
||||
EProcType procType;
|
||||
int32_t procId;
|
||||
SProcObj *pProc;
|
||||
SShm shm;
|
||||
void *pMgmt;
|
||||
SDnode *pDnode;
|
||||
SMgmtFp fp;
|
||||
int8_t msgVgIds[TDMT_MAX]; // Handle the case where the same message type is distributed to qnode or vnode
|
||||
NodeMsgFp msgFps[TDMT_MAX];
|
||||
} SMgmtWrapper;
|
||||
|
||||
typedef struct {
|
||||
void *serverRpc;
|
||||
void *clientRpc;
|
||||
SMsgHandle msgHandles[TDMT_MAX];
|
||||
} STransMgmt;
|
||||
|
||||
typedef struct SDnode {
|
||||
int64_t clusterId;
|
||||
int32_t dnodeId;
|
||||
int32_t numOfSupportVnodes;
|
||||
int64_t rebootTime;
|
||||
char *localEp;
|
||||
char *localFqdn;
|
||||
char *firstEp;
|
||||
char *secondEp;
|
||||
char *dataDir;
|
||||
SDiskCfg *disks;
|
||||
int32_t numOfDisks;
|
||||
uint16_t serverPort;
|
||||
bool dropped;
|
||||
EProcType procType;
|
||||
EDndType ntype;
|
||||
EDndStatus status;
|
||||
EDndEvent event;
|
||||
SStartupReq startup;
|
||||
TdFilePtr lockfile;
|
||||
STransMgmt trans;
|
||||
SMgmtWrapper wrappers[NODE_MAX];
|
||||
} SDnode;
|
||||
|
||||
// dndEnv.c
|
||||
const char *dndStatStr(EDndStatus stat);
|
||||
const char *dndNodeLogStr(EDndType ntype);
|
||||
const char *dndNodeProcStr(EDndType ntype);
|
||||
const char *dndEventStr(EDndEvent ev);
|
||||
|
||||
// dndExec.c
|
||||
int32_t dndOpenNode(SMgmtWrapper *pWrapper);
|
||||
void dndCloseNode(SMgmtWrapper *pWrapper);
|
||||
|
||||
// dndFile.c
|
||||
int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed);
|
||||
int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed);
|
||||
TdFilePtr dndCheckRunning(const char *dataDir);
|
||||
int32_t dndReadShmFile(SDnode *pDnode);
|
||||
int32_t dndWriteShmFile(SDnode *pDnode);
|
||||
|
||||
// dndInt.c
|
||||
EDndStatus dndGetStatus(SDnode *pDnode);
|
||||
void dndSetStatus(SDnode *pDnode, EDndStatus stat);
|
||||
void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId);
|
||||
SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndType nType);
|
||||
int32_t dndMarkWrapper(SMgmtWrapper *pWrapper);
|
||||
void dndReleaseWrapper(SMgmtWrapper *pWrapper);
|
||||
void dndHandleEvent(SDnode *pDnode, EDndEvent event);
|
||||
void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc);
|
||||
void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
|
||||
// dndTransport.c
|
||||
int32_t dndInitTrans(SDnode *pDnode);
|
||||
void dndCleanupTrans(SDnode *pDnode);
|
||||
SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper);
|
||||
SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper);
|
||||
int32_t dndInitMsgHandle(SDnode *pDnode);
|
||||
void dndSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp);
|
||||
|
||||
// mgmt
|
||||
void dmSetMgmtFp(SMgmtWrapper *pWrapper);
|
||||
void bmSetMgmtFp(SMgmtWrapper *pWrapper);
|
||||
void qmSetMgmtFp(SMgmtWrapper *pMgmt);
|
||||
void smSetMgmtFp(SMgmtWrapper *pWrapper);
|
||||
void vmSetMgmtFp(SMgmtWrapper *pWrapper);
|
||||
void mmSetMgmtFp(SMgmtWrapper *pMgmt);
|
||||
|
||||
void dmGetMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet);
|
||||
void dmUpdateMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet);
|
||||
void dmSendRedirectRsp(SDnodeMgmt *pMgmt, const SRpcMsg *pMsg);
|
||||
|
||||
void dmGetMonitorSysInfo(SMonSysInfo *pInfo);
|
||||
void vmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo);
|
||||
void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo);
|
||||
void vmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonVmInfo *vmInfo);
|
||||
void qmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonQmInfo *qmInfo);
|
||||
void smGetMonitorInfo(SMgmtWrapper *pWrapper, SMonSmInfo *smInfo);
|
||||
void bmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonBmInfo *bmInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_DND_INT_H_*/
|
|
@ -0,0 +1,10 @@
|
|||
aux_source_directory(src DNODE_INTERFACE)
|
||||
add_library(dnode_interface STATIC ${DNODE_INTERFACE})
|
||||
target_include_directories(
|
||||
dnode_interface
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/dnode/mgmt"
|
||||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
target_link_libraries(
|
||||
dnode_interface cjson mnode vnode qnode snode bnode wal sync taos_static tfs monitor
|
||||
)
|
|
@ -0,0 +1,151 @@
|
|||
/*
|
||||
* 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_DM_DEF_H_
|
||||
#define _TD_DM_DEF_H_
|
||||
|
||||
#include "dmLog.h"
|
||||
|
||||
#include "cJSON.h"
|
||||
#include "tcache.h"
|
||||
#include "tcrc32c.h"
|
||||
#include "tdatablock.h"
|
||||
#include "tglobal.h"
|
||||
#include "thash.h"
|
||||
#include "tlockfree.h"
|
||||
#include "tlog.h"
|
||||
#include "tmsg.h"
|
||||
#include "tmsgcb.h"
|
||||
#include "tprocess.h"
|
||||
#include "tqueue.h"
|
||||
#include "trpc.h"
|
||||
#include "tthread.h"
|
||||
#include "ttime.h"
|
||||
#include "tworker.h"
|
||||
|
||||
#include "dnode.h"
|
||||
#include "mnode.h"
|
||||
#include "monitor.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum { DNODE, VNODE, QNODE, SNODE, MNODE, BNODE, NODE_END } EDndNodeType;
|
||||
typedef enum { DND_STAT_INIT, DND_STAT_RUNNING, DND_STAT_STOPPED } EDndRunStatus;
|
||||
typedef enum { DND_ENV_INIT, DND_ENV_READY, DND_ENV_CLEANUP } EDndEnvStatus;
|
||||
typedef enum { DND_PROC_SINGLE, DND_PROC_CHILD, DND_PROC_PARENT } EDndProcType;
|
||||
|
||||
typedef int32_t (*NodeMsgFp)(struct SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
|
||||
typedef int32_t (*OpenNodeFp)(struct SMgmtWrapper *pWrapper);
|
||||
typedef void (*CloseNodeFp)(struct SMgmtWrapper *pWrapper);
|
||||
typedef int32_t (*StartNodeFp)(struct SMgmtWrapper *pWrapper);
|
||||
typedef void (*StopNodeFp)(struct SMgmtWrapper *pWrapper);
|
||||
typedef int32_t (*CreateNodeFp)(struct SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
|
||||
typedef int32_t (*DropNodeFp)(struct SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
|
||||
typedef int32_t (*RequireNodeFp)(struct SMgmtWrapper *pWrapper, bool *required);
|
||||
|
||||
typedef struct {
|
||||
SMgmtWrapper *pQndWrapper;
|
||||
SMgmtWrapper *pMndWrapper;
|
||||
SMgmtWrapper *pNdWrapper;
|
||||
} SMsgHandle;
|
||||
|
||||
typedef struct {
|
||||
OpenNodeFp openFp;
|
||||
CloseNodeFp closeFp;
|
||||
StartNodeFp startFp;
|
||||
StopNodeFp stopFp;
|
||||
CreateNodeFp createFp;
|
||||
DropNodeFp dropFp;
|
||||
RequireNodeFp requiredFp;
|
||||
} SMgmtFp;
|
||||
|
||||
typedef struct SMgmtWrapper {
|
||||
SDnode *pDnode;
|
||||
struct {
|
||||
const char *name;
|
||||
char *path;
|
||||
int32_t refCount;
|
||||
SRWLatch latch;
|
||||
EDndNodeType ntype;
|
||||
bool deployed;
|
||||
bool required;
|
||||
SMgmtFp fp;
|
||||
void *pMgmt;
|
||||
};
|
||||
struct {
|
||||
EDndProcType procType;
|
||||
int32_t procId;
|
||||
SProcObj *procObj;
|
||||
SShm procShm;
|
||||
};
|
||||
struct {
|
||||
int8_t msgVgIds[TDMT_MAX]; // Handle the case where the same message type is distributed to qnode or vnode
|
||||
NodeMsgFp msgFps[TDMT_MAX];
|
||||
};
|
||||
} SMgmtWrapper;
|
||||
|
||||
typedef struct {
|
||||
void *serverRpc;
|
||||
void *clientRpc;
|
||||
SMsgHandle msgHandles[TDMT_MAX];
|
||||
} SDnodeTrans;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
int64_t clusterId;
|
||||
int64_t dnodeVer;
|
||||
int64_t updateTime;
|
||||
int64_t rebootTime;
|
||||
bool dropped;
|
||||
SEpSet mnodeEps;
|
||||
SArray *dnodeEps;
|
||||
SHashObj *dnodeHash;
|
||||
TdThread *statusThreadId;
|
||||
TdThread *monitorThreadId;
|
||||
SRWLatch latch;
|
||||
SSingleWorker mgmtWorker;
|
||||
SMsgCb msgCb;
|
||||
SDnode *pDnode;
|
||||
TdFilePtr lockfile;
|
||||
char *localEp;
|
||||
char *localFqdn;
|
||||
char *firstEp;
|
||||
char *secondEp;
|
||||
char *dataDir;
|
||||
SDiskCfg *disks;
|
||||
int32_t numOfDisks;
|
||||
int32_t supportVnodes;
|
||||
uint16_t serverPort;
|
||||
} SDnodeData;
|
||||
|
||||
typedef struct SDnode {
|
||||
EDndProcType ptype;
|
||||
EDndNodeType ntype;
|
||||
EDndRunStatus status;
|
||||
EDndEvent event;
|
||||
SStartupReq startup;
|
||||
SDnodeTrans trans;
|
||||
SDnodeData data;
|
||||
TdThreadMutex mutex;
|
||||
SMgmtWrapper wrappers[NODE_END];
|
||||
} SDnode;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_DM_DEF_H_*/
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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_DM_INT_H_
|
||||
#define _TD_DM_INT_H_
|
||||
|
||||
#include "dmDef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// dmInt.c
|
||||
SMgmtWrapper *dmAcquireWrapper(SDnode *pDnode, EDndNodeType nType);
|
||||
int32_t dmMarkWrapper(SMgmtWrapper *pWrapper);
|
||||
void dmReleaseWrapper(SMgmtWrapper *pWrapper);
|
||||
const char *dmStatName(EDndRunStatus stat);
|
||||
const char *dmLogName(EDndNodeType ntype);
|
||||
const char *dmProcName(EDndNodeType ntype);
|
||||
const char *dmEventName(EDndEvent ev);
|
||||
|
||||
void dmSetStatus(SDnode *pDnode, EDndRunStatus stat);
|
||||
void dmSetEvent(SDnode *pDnode, EDndEvent event);
|
||||
void dmSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId);
|
||||
void dmReportStartup(SDnode *pDnode, const char *pName, const char *pDesc);
|
||||
void dmProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
void dmGetMonitorSysInfo(SMonSysInfo *pInfo);
|
||||
|
||||
// dmFile.c
|
||||
int32_t dmReadFile(SMgmtWrapper *pWrapper, bool *pDeployed);
|
||||
int32_t dmWriteFile(SMgmtWrapper *pWrapper, bool deployed);
|
||||
TdFilePtr dmCheckRunning(const char *dataDir);
|
||||
int32_t dmReadShmFile(SMgmtWrapper *pWrapper);
|
||||
int32_t dmWriteShmFile(SMgmtWrapper *pWrapper);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_DM_INT_H_*/
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* 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_DM_LOG_H_
|
||||
#define _TD_DM_LOG_H_
|
||||
|
||||
#include "tlog.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }}
|
||||
#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }}
|
||||
#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("DND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }}
|
||||
#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("DND ", DEBUG_INFO, 255, __VA_ARGS__); }}
|
||||
#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", DEBUG_DEBUG, dDebugFlag, __VA_ARGS__); }}
|
||||
#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", DEBUG_TRACE, dDebugFlag, __VA_ARGS__); }}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_DM_LOG_H_*/
|
|
@ -14,12 +14,12 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndInt.h"
|
||||
#include "dmInt.h"
|
||||
#include "wal.h"
|
||||
|
||||
static int8_t once = DND_ENV_INIT;
|
||||
|
||||
int32_t dndInit() {
|
||||
int32_t dmInit() {
|
||||
dDebug("start to init dnode env");
|
||||
if (atomic_val_compare_exchange_8(&once, DND_ENV_INIT, DND_ENV_READY) != DND_ENV_INIT) {
|
||||
terrno = TSDB_CODE_REPEAT_INIT;
|
||||
|
@ -45,7 +45,7 @@ int32_t dndInit() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void dndCleanup() {
|
||||
void dmCleanup() {
|
||||
dDebug("start to cleanup dnode env");
|
||||
if (atomic_val_compare_exchange_8(&once, DND_ENV_READY, DND_ENV_CLEANUP) != DND_ENV_READY) {
|
||||
dError("dnode env is already cleaned up");
|
||||
|
@ -57,63 +57,3 @@ void dndCleanup() {
|
|||
taosStopCacheRefreshWorker();
|
||||
dInfo("dnode env is cleaned up");
|
||||
}
|
||||
|
||||
const char *dndStatStr(EDndStatus status) {
|
||||
switch (status) {
|
||||
case DND_STAT_INIT:
|
||||
return "init";
|
||||
case DND_STAT_RUNNING:
|
||||
return "running";
|
||||
case DND_STAT_STOPPED:
|
||||
return "stopped";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
const char *dndNodeLogStr(EDndType ntype) {
|
||||
switch (ntype) {
|
||||
case VNODES:
|
||||
return "vnode";
|
||||
case QNODE:
|
||||
return "qnode";
|
||||
case SNODE:
|
||||
return "snode";
|
||||
case MNODE:
|
||||
return "mnode";
|
||||
case BNODE:
|
||||
return "bnode";
|
||||
default:
|
||||
return "taosd";
|
||||
}
|
||||
}
|
||||
|
||||
const char *dndNodeProcStr(EDndType ntype) {
|
||||
switch (ntype) {
|
||||
case VNODES:
|
||||
return "taosv";
|
||||
case QNODE:
|
||||
return "taosq";
|
||||
case SNODE:
|
||||
return "taoss";
|
||||
case MNODE:
|
||||
return "taosm";
|
||||
case BNODE:
|
||||
return "taosb";
|
||||
default:
|
||||
return "taosd";
|
||||
}
|
||||
}
|
||||
|
||||
const char *dndEventStr(EDndEvent ev) {
|
||||
switch (ev) {
|
||||
case DND_EVENT_START:
|
||||
return "start";
|
||||
case DND_EVENT_STOP:
|
||||
return "stop";
|
||||
case DND_EVENT_CHILD:
|
||||
return "child";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
|
@ -14,22 +14,22 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndInt.h"
|
||||
#include "dmInt.h"
|
||||
|
||||
#define MAXLEN 1024
|
||||
|
||||
int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed) {
|
||||
int32_t dmReadFile(SMgmtWrapper *pWrapper, bool *pDeployed) {
|
||||
int32_t code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
int64_t len = 0;
|
||||
char content[MAXLEN + 1] = {0};
|
||||
cJSON *root = NULL;
|
||||
char file[PATH_MAX];
|
||||
char file[PATH_MAX] = {0};
|
||||
TdFilePtr pFile = NULL;
|
||||
|
||||
snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name);
|
||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
dDebug("file %s not exist", file);
|
||||
// dDebug("file %s not exist", file);
|
||||
code = 0;
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ _OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed) {
|
||||
int32_t dmWriteFile(SMgmtWrapper *pWrapper, bool deployed) {
|
||||
int32_t code = -1;
|
||||
int32_t len = 0;
|
||||
char content[MAXLEN + 1] = {0};
|
||||
|
@ -117,7 +117,7 @@ _OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
TdFilePtr dndCheckRunning(const char *dataDir) {
|
||||
TdFilePtr dmCheckRunning(const char *dataDir) {
|
||||
char filepath[PATH_MAX] = {0};
|
||||
snprintf(filepath, sizeof(filepath), "%s%s.running", dataDir, TD_DIRSEP);
|
||||
|
||||
|
@ -140,18 +140,17 @@ TdFilePtr dndCheckRunning(const char *dataDir) {
|
|||
return pFile;
|
||||
}
|
||||
|
||||
int32_t dndReadShmFile(SDnode *pDnode) {
|
||||
int32_t dmReadShmFile(SMgmtWrapper *pWrapper) {
|
||||
int32_t code = -1;
|
||||
char itemName[24] = {0};
|
||||
char content[MAXLEN + 1] = {0};
|
||||
char file[PATH_MAX] = {0};
|
||||
cJSON *root = NULL;
|
||||
TdFilePtr pFile = NULL;
|
||||
|
||||
snprintf(file, sizeof(file), "%s%s.shmfile", pDnode->dataDir, TD_DIRSEP);
|
||||
snprintf(file, sizeof(file), "%s%sshmfile", pWrapper->path, TD_DIRSEP);
|
||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
dDebug("file %s not exist", file);
|
||||
// dDebug("node:%s, file %s not exist", pWrapper->name, file);
|
||||
code = 0;
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -160,44 +159,36 @@ int32_t dndReadShmFile(SDnode *pDnode) {
|
|||
root = cJSON_Parse(content);
|
||||
if (root == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
dError("failed to read %s since invalid json format", file);
|
||||
dError("node:%s, failed to read %s since invalid json format", pWrapper->name, file);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
for (EDndType ntype = DNODE + 1; ntype < NODE_MAX; ++ntype) {
|
||||
snprintf(itemName, sizeof(itemName), "%s_shmid", dndNodeProcStr(ntype));
|
||||
cJSON *shmid = cJSON_GetObjectItem(root, itemName);
|
||||
if (shmid && shmid->type == cJSON_Number) {
|
||||
pDnode->wrappers[ntype].shm.id = shmid->valueint;
|
||||
}
|
||||
cJSON *shmid = cJSON_GetObjectItem(root, "shmid");
|
||||
if (shmid && shmid->type == cJSON_Number) {
|
||||
pWrapper->procShm.id = shmid->valueint;
|
||||
}
|
||||
|
||||
snprintf(itemName, sizeof(itemName), "%s_shmsize", dndNodeProcStr(ntype));
|
||||
cJSON *shmsize = cJSON_GetObjectItem(root, itemName);
|
||||
if (shmsize && shmsize->type == cJSON_Number) {
|
||||
pDnode->wrappers[ntype].shm.size = shmsize->valueint;
|
||||
}
|
||||
cJSON *shmsize = cJSON_GetObjectItem(root, "shmsize");
|
||||
if (shmsize && shmsize->type == cJSON_Number) {
|
||||
pWrapper->procShm.size = shmsize->valueint;
|
||||
}
|
||||
}
|
||||
|
||||
if (!tsMultiProcess || pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) {
|
||||
for (EDndType ntype = DNODE; ntype < NODE_MAX; ++ntype) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
|
||||
if (pWrapper->shm.id >= 0) {
|
||||
dDebug("shmid:%d, is closed, size:%d", pWrapper->shm.id, pWrapper->shm.size);
|
||||
taosDropShm(&pWrapper->shm);
|
||||
}
|
||||
if (!tsMultiProcess || pWrapper->pDnode->ntype == DNODE || pWrapper->pDnode->ntype == NODE_END) {
|
||||
if (pWrapper->procShm.id >= 0) {
|
||||
dDebug("node:%s, shmid:%d, is closed, size:%d", pWrapper->name, pWrapper->procShm.id, pWrapper->procShm.size);
|
||||
taosDropShm(&pWrapper->procShm);
|
||||
}
|
||||
} else {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype];
|
||||
if (taosAttachShm(&pWrapper->shm) != 0) {
|
||||
if (taosAttachShm(&pWrapper->procShm) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("shmid:%d, failed to attach shm since %s", pWrapper->shm.id, terrstr());
|
||||
dError("shmid:%d, failed to attach shm since %s", pWrapper->procShm.id, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
dInfo("node:%s, shmid:%d is attached, size:%d", pWrapper->name, pWrapper->shm.id, pWrapper->shm.size);
|
||||
dInfo("node:%s, shmid:%d is attached, size:%d", pWrapper->name, pWrapper->procShm.id, pWrapper->procShm.size);
|
||||
}
|
||||
|
||||
dDebug("successed to load %s", file);
|
||||
dDebug("node:%s, successed to load %s", pWrapper->name, file);
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
|
@ -207,7 +198,7 @@ _OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t dndWriteShmFile(SDnode *pDnode) {
|
||||
int32_t dmWriteShmFile(SMgmtWrapper *pWrapper) {
|
||||
int32_t code = -1;
|
||||
int32_t len = 0;
|
||||
char content[MAXLEN + 1] = {0};
|
||||
|
@ -215,37 +206,30 @@ int32_t dndWriteShmFile(SDnode *pDnode) {
|
|||
char realfile[PATH_MAX] = {0};
|
||||
TdFilePtr pFile = NULL;
|
||||
|
||||
snprintf(file, sizeof(file), "%s%s.shmfile.bak", pDnode->dataDir, TD_DIRSEP);
|
||||
snprintf(realfile, sizeof(realfile), "%s%s.shmfile", pDnode->dataDir, TD_DIRSEP);
|
||||
snprintf(file, sizeof(file), "%s%sshmfile.bak", pWrapper->path, TD_DIRSEP);
|
||||
snprintf(realfile, sizeof(realfile), "%s%sshmfile", pWrapper->path, TD_DIRSEP);
|
||||
|
||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to open file:%s since %s", file, terrstr());
|
||||
dError("node:%s, failed to open file:%s since %s", pWrapper->name, file, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
len += snprintf(content + len, MAXLEN - len, "{\n");
|
||||
for (EDndType ntype = DNODE + 1; ntype < NODE_MAX; ++ntype) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
|
||||
len += snprintf(content + len, MAXLEN - len, " \"%s_shmid\":%d,\n", dndNodeProcStr(ntype), pWrapper->shm.id);
|
||||
if (ntype == NODE_MAX - 1) {
|
||||
len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d\n", dndNodeProcStr(ntype), pWrapper->shm.size);
|
||||
} else {
|
||||
len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d,\n", dndNodeProcStr(ntype), pWrapper->shm.size);
|
||||
}
|
||||
}
|
||||
len += snprintf(content + len, MAXLEN - len, " \"shmid\":%d,\n", pWrapper->procShm.id);
|
||||
len += snprintf(content + len, MAXLEN - len, " \"shmsize\":%d\n", pWrapper->procShm.size);
|
||||
len += snprintf(content + len, MAXLEN - len, "}\n");
|
||||
|
||||
if (taosWriteFile(pFile, content, len) != len) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to write file:%s since %s", file, terrstr());
|
||||
dError("node:%s, failed to write file:%s since %s", pWrapper->name, file, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (taosFsyncFile(pFile) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to fsync file:%s since %s", file, terrstr());
|
||||
dError("node:%s, failed to fsync file:%s since %s", pWrapper->name, file, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -253,11 +237,11 @@ int32_t dndWriteShmFile(SDnode *pDnode) {
|
|||
|
||||
if (taosRenameFile(file, realfile) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to rename %s to %s since %s", file, realfile, terrstr());
|
||||
dError("node:%s, failed to rename %s to %s since %s", pWrapper->name, file, realfile, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("successed to write %s", realfile);
|
||||
dInfo("node:%s, successed to write %s", pWrapper->name, realfile);
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
|
@ -0,0 +1,173 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dmInt.h"
|
||||
|
||||
const char *dmStatName(EDndRunStatus status) {
|
||||
switch (status) {
|
||||
case DND_STAT_INIT:
|
||||
return "init";
|
||||
case DND_STAT_RUNNING:
|
||||
return "running";
|
||||
case DND_STAT_STOPPED:
|
||||
return "stopped";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
const char *dmLogName(EDndNodeType ntype) {
|
||||
switch (ntype) {
|
||||
case VNODE:
|
||||
return "vnode";
|
||||
case QNODE:
|
||||
return "qnode";
|
||||
case SNODE:
|
||||
return "snode";
|
||||
case MNODE:
|
||||
return "mnode";
|
||||
case BNODE:
|
||||
return "bnode";
|
||||
default:
|
||||
return "taosd";
|
||||
}
|
||||
}
|
||||
|
||||
const char *dmProcName(EDndNodeType ntype) {
|
||||
switch (ntype) {
|
||||
case VNODE:
|
||||
return "taosv";
|
||||
case QNODE:
|
||||
return "taosq";
|
||||
case SNODE:
|
||||
return "taoss";
|
||||
case MNODE:
|
||||
return "taosm";
|
||||
case BNODE:
|
||||
return "taosb";
|
||||
default:
|
||||
return "taosd";
|
||||
}
|
||||
}
|
||||
|
||||
const char *dmEventName(EDndEvent ev) {
|
||||
switch (ev) {
|
||||
case DND_EVENT_START:
|
||||
return "start";
|
||||
case DND_EVENT_STOP:
|
||||
return "stop";
|
||||
case DND_EVENT_CHILD:
|
||||
return "child";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
void dmSetStatus(SDnode *pDnode, EDndRunStatus status) {
|
||||
if (pDnode->status != status) {
|
||||
dDebug("dnode status set from %s to %s", dmStatName(pDnode->status), dmStatName(status));
|
||||
pDnode->status = status;
|
||||
}
|
||||
}
|
||||
|
||||
void dmSetEvent(SDnode *pDnode, EDndEvent event) {
|
||||
if (event == DND_EVENT_STOP) {
|
||||
pDnode->event = event;
|
||||
}
|
||||
}
|
||||
|
||||
void dmSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId) {
|
||||
pWrapper->msgFps[TMSG_INDEX(msgType)] = nodeMsgFp;
|
||||
pWrapper->msgVgIds[TMSG_INDEX(msgType)] = vgId;
|
||||
}
|
||||
|
||||
SMgmtWrapper *dmAcquireWrapper(SDnode *pDnode, EDndNodeType ntype) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
|
||||
SMgmtWrapper *pRetWrapper = pWrapper;
|
||||
|
||||
taosRLockLatch(&pWrapper->latch);
|
||||
if (pWrapper->deployed) {
|
||||
int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1);
|
||||
dTrace("node:%s, is acquired, refCount:%d", pWrapper->name, refCount);
|
||||
} else {
|
||||
terrno = TSDB_CODE_NODE_NOT_DEPLOYED;
|
||||
pRetWrapper = NULL;
|
||||
}
|
||||
taosRUnLockLatch(&pWrapper->latch);
|
||||
|
||||
return pRetWrapper;
|
||||
}
|
||||
|
||||
int32_t dmMarkWrapper(SMgmtWrapper *pWrapper) {
|
||||
int32_t code = 0;
|
||||
|
||||
taosRLockLatch(&pWrapper->latch);
|
||||
if (pWrapper->deployed || (pWrapper->procType == DND_PROC_PARENT && pWrapper->required)) {
|
||||
int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1);
|
||||
dTrace("node:%s, is marked, refCount:%d", pWrapper->name, refCount);
|
||||
} else {
|
||||
terrno = TSDB_CODE_NODE_NOT_DEPLOYED;
|
||||
code = -1;
|
||||
}
|
||||
taosRUnLockLatch(&pWrapper->latch);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
void dmReleaseWrapper(SMgmtWrapper *pWrapper) {
|
||||
if (pWrapper == NULL) return;
|
||||
|
||||
taosRLockLatch(&pWrapper->latch);
|
||||
int32_t refCount = atomic_sub_fetch_32(&pWrapper->refCount, 1);
|
||||
taosRUnLockLatch(&pWrapper->latch);
|
||||
dTrace("node:%s, is released, refCount:%d", pWrapper->name, refCount);
|
||||
}
|
||||
|
||||
void dmReportStartup(SDnode *pDnode, const char *pName, const char *pDesc) {
|
||||
SStartupReq *pStartup = &pDnode->startup;
|
||||
tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN);
|
||||
tstrncpy(pStartup->desc, pDesc, TSDB_STEP_DESC_LEN);
|
||||
pStartup->finished = 0;
|
||||
}
|
||||
|
||||
static void dmGetStartup(SDnode *pDnode, SStartupReq *pStartup) {
|
||||
memcpy(pStartup, &pDnode->startup, sizeof(SStartupReq));
|
||||
pStartup->finished = (pDnode->status == DND_STAT_RUNNING);
|
||||
}
|
||||
|
||||
void dmProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
dDebug("startup req is received");
|
||||
SStartupReq *pStartup = rpcMallocCont(sizeof(SStartupReq));
|
||||
dmGetStartup(pDnode, pStartup);
|
||||
|
||||
dDebug("startup req is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished);
|
||||
SRpcMsg rpcRsp = {
|
||||
.handle = pReq->handle, .pCont = pStartup, .contLen = sizeof(SStartupReq), .ahandle = pReq->ahandle};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
}
|
||||
|
||||
void dmGetMonitorSysInfo(SMonSysInfo *pInfo) {
|
||||
taosGetCpuUsage(&pInfo->cpu_engine, &pInfo->cpu_system);
|
||||
taosGetCpuCores(&pInfo->cpu_cores);
|
||||
taosGetProcMemory(&pInfo->mem_engine);
|
||||
taosGetSysMemory(&pInfo->mem_system);
|
||||
pInfo->mem_total = tsTotalMemoryKB;
|
||||
pInfo->disk_engine = 0;
|
||||
pInfo->disk_used = tsDataSpace.size.used;
|
||||
pInfo->disk_total = tsDataSpace.size.total;
|
||||
taosGetCardInfoDelta(&pInfo->net_in, &pInfo->net_out);
|
||||
taosGetProcIODelta(&pInfo->io_read, &pInfo->io_write, &pInfo->io_read_disk, &pInfo->io_write_disk);
|
||||
}
|
|
@ -1,357 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndInt.h"
|
||||
|
||||
static bool dndRequireNode(SMgmtWrapper *pWrapper) {
|
||||
bool required = false;
|
||||
int32_t code = (*pWrapper->fp.requiredFp)(pWrapper, &required);
|
||||
if (!required) {
|
||||
dDebug("node:%s, does not require startup", pWrapper->name);
|
||||
} else {
|
||||
dDebug("node:%s, needs to be started", pWrapper->name);
|
||||
}
|
||||
return required;
|
||||
}
|
||||
|
||||
static int32_t dndInitNodeProc(SMgmtWrapper *pWrapper) {
|
||||
int32_t shmsize = tsMnodeShmSize;
|
||||
if (pWrapper->ntype == VNODES) {
|
||||
shmsize = tsVnodeShmSize;
|
||||
} else if (pWrapper->ntype == QNODE) {
|
||||
shmsize = tsQnodeShmSize;
|
||||
} else if (pWrapper->ntype == SNODE) {
|
||||
shmsize = tsSnodeShmSize;
|
||||
} else if (pWrapper->ntype == MNODE) {
|
||||
shmsize = tsMnodeShmSize;
|
||||
} else if (pWrapper->ntype == BNODE) {
|
||||
shmsize = tsBnodeShmSize;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosCreateShm(&pWrapper->shm, pWrapper->ntype, shmsize) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(terrno);
|
||||
dError("node:%s, failed to create shm size:%d since %s", pWrapper->name, shmsize, terrstr());
|
||||
return -1;
|
||||
}
|
||||
dInfo("node:%s, shm:%d is created, size:%d", pWrapper->name, pWrapper->shm.id, shmsize);
|
||||
|
||||
SProcCfg cfg = dndGenProcCfg(pWrapper);
|
||||
cfg.isChild = false;
|
||||
pWrapper->procType = PROC_PARENT;
|
||||
pWrapper->pProc = taosProcInit(&cfg);
|
||||
if (pWrapper->pProc == NULL) {
|
||||
dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndNewNodeProc(SMgmtWrapper *pWrapper, EDndType n) {
|
||||
char tstr[8] = {0};
|
||||
char *args[6] = {0};
|
||||
snprintf(tstr, sizeof(tstr), "%d", n);
|
||||
args[1] = "-c";
|
||||
args[2] = configDir;
|
||||
args[3] = "-n";
|
||||
args[4] = tstr;
|
||||
args[5] = NULL;
|
||||
|
||||
int32_t pid = taosNewProc(args);
|
||||
if (pid <= 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("node:%s, failed to exec in new process since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
pWrapper->procId = pid;
|
||||
dInfo("node:%s, continue running in new process:%d", pWrapper->name, pid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndRunNodeProc(SMgmtWrapper *pWrapper) {
|
||||
if (pWrapper->pDnode->ntype == NODE_MAX) {
|
||||
dInfo("node:%s, should be started manually", pWrapper->name);
|
||||
} else {
|
||||
if (dndNewNodeProc(pWrapper, pWrapper->ntype) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (taosProcRun(pWrapper->pProc) != 0) {
|
||||
dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndOpenNodeImp(SMgmtWrapper *pWrapper) {
|
||||
if (taosMkDir(pWrapper->path) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((*pWrapper->fp.openFp)(pWrapper) != 0) {
|
||||
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("node:%s, has been opened", pWrapper->name);
|
||||
pWrapper->deployed = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dndOpenNode(SMgmtWrapper *pWrapper) {
|
||||
SDnode *pDnode = pWrapper->pDnode;
|
||||
if (pDnode->procType == PROC_SINGLE) {
|
||||
return dndOpenNodeImp(pWrapper);
|
||||
} else if (pDnode->procType == PROC_PARENT) {
|
||||
if (dndInitNodeProc(pWrapper) != 0) return -1;
|
||||
if (dndWriteShmFile(pDnode) != 0) return -1;
|
||||
if (dndRunNodeProc(pWrapper) != 0) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndCloseNodeImp(SMgmtWrapper *pWrapper) {
|
||||
dDebug("node:%s, mgmt start to close", pWrapper->name);
|
||||
pWrapper->required = false;
|
||||
taosWLockLatch(&pWrapper->latch);
|
||||
if (pWrapper->deployed) {
|
||||
(*pWrapper->fp.closeFp)(pWrapper);
|
||||
pWrapper->deployed = false;
|
||||
}
|
||||
taosWUnLockLatch(&pWrapper->latch);
|
||||
|
||||
while (pWrapper->refCount > 0) {
|
||||
taosMsleep(10);
|
||||
}
|
||||
|
||||
if (pWrapper->pProc) {
|
||||
taosProcCleanup(pWrapper->pProc);
|
||||
pWrapper->pProc = NULL;
|
||||
}
|
||||
dDebug("node:%s, mgmt has been closed", pWrapper->name);
|
||||
}
|
||||
|
||||
void dndCloseNode(SMgmtWrapper *pWrapper) {
|
||||
if (pWrapper->pDnode->procType == PROC_PARENT) {
|
||||
if (pWrapper->procId > 0 && taosProcExist(pWrapper->procId)) {
|
||||
dInfo("node:%s, send kill signal to the child process:%d", pWrapper->name, pWrapper->procId);
|
||||
taosKillProc(pWrapper->procId);
|
||||
dInfo("node:%s, wait for child process:%d to stop", pWrapper->name, pWrapper->procId);
|
||||
taosWaitProc(pWrapper->procId);
|
||||
dInfo("node:%s, child process:%d is stopped", pWrapper->name, pWrapper->procId);
|
||||
}
|
||||
}
|
||||
dndCloseNodeImp(pWrapper);
|
||||
}
|
||||
|
||||
static void dndProcessProcHandle(void *handle) {
|
||||
dWarn("handle:%p, the child process dies and send an offline rsp", handle);
|
||||
SRpcMsg rpcMsg = {.handle = handle, .code = TSDB_CODE_NODE_OFFLINE};
|
||||
rpcSendResponse(&rpcMsg);
|
||||
}
|
||||
|
||||
static int32_t dndRunInSingleProcess(SDnode *pDnode) {
|
||||
dInfo("dnode run in single process");
|
||||
pDnode->procType = PROC_SINGLE;
|
||||
|
||||
for (EDndType n = DNODE; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
pWrapper->required = dndRequireNode(pWrapper);
|
||||
if (!pWrapper->required) continue;
|
||||
|
||||
if (dndOpenNodeImp(pWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
dndSetStatus(pDnode, DND_STAT_RUNNING);
|
||||
|
||||
for (EDndType n = 0; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
if (!pWrapper->required) continue;
|
||||
if (pWrapper->fp.startFp == NULL) continue;
|
||||
if ((*pWrapper->fp.startFp)(pWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
dInfo("TDengine initialized successfully");
|
||||
dndReportStartup(pDnode, "TDengine", "initialized successfully");
|
||||
while (1) {
|
||||
if (pDnode->event == DND_EVENT_STOP) {
|
||||
dInfo("dnode is about to stop");
|
||||
dndSetStatus(pDnode, DND_STAT_STOPPED);
|
||||
break;
|
||||
}
|
||||
taosMsleep(100);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndRunInParentProcess(SDnode *pDnode) {
|
||||
dInfo("dnode run in parent process");
|
||||
pDnode->procType = PROC_PARENT;
|
||||
|
||||
SMgmtWrapper *pDWrapper = &pDnode->wrappers[DNODE];
|
||||
if (dndOpenNodeImp(pDWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pDWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (EDndType n = DNODE + 1; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
pWrapper->required = dndRequireNode(pWrapper);
|
||||
if (!pWrapper->required) continue;
|
||||
if (dndInitNodeProc(pWrapper) != 0) return -1;
|
||||
}
|
||||
|
||||
if (dndWriteShmFile(pDnode) != 0) {
|
||||
dError("failed to write runtime file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (EDndType n = DNODE + 1; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
if (!pWrapper->required) continue;
|
||||
if (dndRunNodeProc(pWrapper) != 0) return -1;
|
||||
}
|
||||
|
||||
dndSetStatus(pDnode, DND_STAT_RUNNING);
|
||||
|
||||
if ((*pDWrapper->fp.startFp)(pDWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pDWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("TDengine initialized successfully");
|
||||
dndReportStartup(pDnode, "TDengine", "initialized successfully");
|
||||
|
||||
while (1) {
|
||||
if (pDnode->event == DND_EVENT_STOP) {
|
||||
dInfo("dnode is about to stop");
|
||||
dndSetStatus(pDnode, DND_STAT_STOPPED);
|
||||
|
||||
for (EDndType n = DNODE + 1; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
if (!pWrapper->required) continue;
|
||||
if (pDnode->ntype == NODE_MAX) continue;
|
||||
|
||||
if (pWrapper->procId > 0 && taosProcExist(pWrapper->procId)) {
|
||||
dInfo("node:%s, send kill signal to the child process:%d", pWrapper->name, pWrapper->procId);
|
||||
taosKillProc(pWrapper->procId);
|
||||
dInfo("node:%s, wait for child process:%d to stop", pWrapper->name, pWrapper->procId);
|
||||
taosWaitProc(pWrapper->procId);
|
||||
dInfo("node:%s, child process:%d is stopped", pWrapper->name, pWrapper->procId);
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
for (EDndType n = DNODE + 1; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
if (!pWrapper->required) continue;
|
||||
if (pDnode->ntype == NODE_MAX) continue;
|
||||
|
||||
if (pWrapper->procId <= 0 || !taosProcExist(pWrapper->procId)) {
|
||||
dWarn("node:%s, process:%d is killed and needs to be restarted", pWrapper->name, pWrapper->procId);
|
||||
taosProcCloseHandles(pWrapper->pProc, dndProcessProcHandle);
|
||||
dndNewNodeProc(pWrapper, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
taosMsleep(100);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndRunInChildProcess(SDnode *pDnode) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype];
|
||||
dInfo("%s run in child process", pWrapper->name);
|
||||
pDnode->procType = PROC_CHILD;
|
||||
|
||||
pWrapper->required = dndRequireNode(pWrapper);
|
||||
if (!pWrapper->required) {
|
||||
dError("%s does not require startup", pWrapper->name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
SMsgCb msgCb = dndCreateMsgcb(pWrapper);
|
||||
tmsgSetDefaultMsgCb(&msgCb);
|
||||
pWrapper->procType = PROC_CHILD;
|
||||
|
||||
if (dndOpenNodeImp(pWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SProcCfg cfg = dndGenProcCfg(pWrapper);
|
||||
cfg.isChild = true;
|
||||
pWrapper->pProc = taosProcInit(&cfg);
|
||||
if (pWrapper->pProc == NULL) {
|
||||
dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pWrapper->fp.startFp != NULL) {
|
||||
if ((*pWrapper->fp.startFp)(pWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
dndSetStatus(pDnode, DND_STAT_RUNNING);
|
||||
|
||||
if (taosProcRun(pWrapper->pProc) != 0) {
|
||||
dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dInfo("TDengine initialized successfully");
|
||||
dndReportStartup(pDnode, "TDengine", "initialized successfully");
|
||||
while (1) {
|
||||
if (pDnode->event == DND_EVENT_STOP) {
|
||||
dInfo("%s is about to stop", pWrapper->name);
|
||||
dndSetStatus(pDnode, DND_STAT_STOPPED);
|
||||
break;
|
||||
}
|
||||
taosMsleep(100);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dndRun(SDnode *pDnode) {
|
||||
if (!tsMultiProcess) {
|
||||
return dndRunInSingleProcess(pDnode);
|
||||
} else if (pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) {
|
||||
return dndRunInParentProcess(pDnode);
|
||||
} else {
|
||||
return dndRunInChildProcess(pDnode);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,229 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndInt.h"
|
||||
|
||||
static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) {
|
||||
pDnode->numOfSupportVnodes = pOption->numOfSupportVnodes;
|
||||
pDnode->serverPort = pOption->serverPort;
|
||||
pDnode->dataDir = strdup(pOption->dataDir);
|
||||
pDnode->localEp = strdup(pOption->localEp);
|
||||
pDnode->localFqdn = strdup(pOption->localFqdn);
|
||||
pDnode->firstEp = strdup(pOption->firstEp);
|
||||
pDnode->secondEp = strdup(pOption->secondEp);
|
||||
pDnode->disks = pOption->disks;
|
||||
pDnode->numOfDisks = pOption->numOfDisks;
|
||||
pDnode->ntype = pOption->ntype;
|
||||
pDnode->rebootTime = taosGetTimestampMs();
|
||||
|
||||
if (pDnode->dataDir == NULL || pDnode->localEp == NULL || pDnode->localFqdn == NULL || pDnode->firstEp == NULL ||
|
||||
pDnode->secondEp == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!tsMultiProcess || pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) {
|
||||
pDnode->lockfile = dndCheckRunning(pDnode->dataDir);
|
||||
if (pDnode->lockfile == NULL) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndClearVars(SDnode *pDnode) {
|
||||
for (EDndType n = 0; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pMgmt = &pDnode->wrappers[n];
|
||||
taosMemoryFreeClear(pMgmt->path);
|
||||
}
|
||||
if (pDnode->lockfile != NULL) {
|
||||
taosUnLockFile(pDnode->lockfile);
|
||||
taosCloseFile(&pDnode->lockfile);
|
||||
pDnode->lockfile = NULL;
|
||||
}
|
||||
taosMemoryFreeClear(pDnode->localEp);
|
||||
taosMemoryFreeClear(pDnode->localFqdn);
|
||||
taosMemoryFreeClear(pDnode->firstEp);
|
||||
taosMemoryFreeClear(pDnode->secondEp);
|
||||
taosMemoryFreeClear(pDnode->dataDir);
|
||||
taosMemoryFree(pDnode);
|
||||
dDebug("dnode memory is cleared, data:%p", pDnode);
|
||||
}
|
||||
|
||||
SDnode *dndCreate(const SDnodeOpt *pOption) {
|
||||
dDebug("start to create dnode object");
|
||||
int32_t code = -1;
|
||||
char path[PATH_MAX] = {0};
|
||||
SDnode *pDnode = NULL;
|
||||
|
||||
pDnode = taosMemoryCalloc(1, sizeof(SDnode));
|
||||
if (pDnode == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (dndInitVars(pDnode, pOption) != 0) {
|
||||
dError("failed to init variables since %s", terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
dndSetStatus(pDnode, DND_STAT_INIT);
|
||||
dmSetMgmtFp(&pDnode->wrappers[DNODE]);
|
||||
mmSetMgmtFp(&pDnode->wrappers[MNODE]);
|
||||
vmSetMgmtFp(&pDnode->wrappers[VNODES]);
|
||||
qmSetMgmtFp(&pDnode->wrappers[QNODE]);
|
||||
smSetMgmtFp(&pDnode->wrappers[SNODE]);
|
||||
bmSetMgmtFp(&pDnode->wrappers[BNODE]);
|
||||
|
||||
for (EDndType n = 0; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
snprintf(path, sizeof(path), "%s%s%s", pDnode->dataDir, TD_DIRSEP, pWrapper->name);
|
||||
pWrapper->path = strdup(path);
|
||||
pWrapper->shm.id = -1;
|
||||
pWrapper->pDnode = pDnode;
|
||||
pWrapper->ntype = n;
|
||||
if (pWrapper->path == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pWrapper->procType = PROC_SINGLE;
|
||||
taosInitRWLatch(&pWrapper->latch);
|
||||
}
|
||||
|
||||
if (dndInitMsgHandle(pDnode) != 0) {
|
||||
dError("failed to init msg handles since %s", terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (dndReadShmFile(pDnode) != 0) {
|
||||
dError("failed to read shm file since %s", terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
SMsgCb msgCb = dndCreateMsgcb(&pDnode->wrappers[0]);
|
||||
tmsgSetDefaultMsgCb(&msgCb);
|
||||
|
||||
dInfo("dnode is created, data:%p", pDnode);
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
if (code != 0 && pDnode) {
|
||||
dndClearVars(pDnode);
|
||||
pDnode = NULL;
|
||||
dError("failed to create dnode since %s", terrstr());
|
||||
}
|
||||
|
||||
return pDnode;
|
||||
}
|
||||
|
||||
void dndClose(SDnode *pDnode) {
|
||||
if (pDnode == NULL) return;
|
||||
|
||||
for (EDndType n = 0; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
dndCloseNode(pWrapper);
|
||||
}
|
||||
|
||||
dndClearVars(pDnode);
|
||||
dInfo("dnode is closed, data:%p", pDnode);
|
||||
}
|
||||
|
||||
void dndHandleEvent(SDnode *pDnode, EDndEvent event) {
|
||||
if (event == DND_EVENT_STOP) {
|
||||
pDnode->event = event;
|
||||
}
|
||||
}
|
||||
|
||||
SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndType ntype) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
|
||||
SMgmtWrapper *pRetWrapper = pWrapper;
|
||||
|
||||
taosRLockLatch(&pWrapper->latch);
|
||||
if (pWrapper->deployed) {
|
||||
int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1);
|
||||
dTrace("node:%s, is acquired, refCount:%d", pWrapper->name, refCount);
|
||||
} else {
|
||||
terrno = TSDB_CODE_NODE_NOT_DEPLOYED;
|
||||
pRetWrapper = NULL;
|
||||
}
|
||||
taosRUnLockLatch(&pWrapper->latch);
|
||||
|
||||
return pRetWrapper;
|
||||
}
|
||||
|
||||
int32_t dndMarkWrapper(SMgmtWrapper *pWrapper) {
|
||||
int32_t code = 0;
|
||||
|
||||
taosRLockLatch(&pWrapper->latch);
|
||||
if (pWrapper->deployed || (pWrapper->procType == PROC_PARENT && pWrapper->required)) {
|
||||
int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1);
|
||||
dTrace("node:%s, is marked, refCount:%d", pWrapper->name, refCount);
|
||||
} else {
|
||||
terrno = TSDB_CODE_NODE_NOT_DEPLOYED;
|
||||
code = -1;
|
||||
}
|
||||
taosRUnLockLatch(&pWrapper->latch);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
void dndReleaseWrapper(SMgmtWrapper *pWrapper) {
|
||||
if (pWrapper == NULL) return;
|
||||
|
||||
taosRLockLatch(&pWrapper->latch);
|
||||
int32_t refCount = atomic_sub_fetch_32(&pWrapper->refCount, 1);
|
||||
taosRUnLockLatch(&pWrapper->latch);
|
||||
dTrace("node:%s, is released, refCount:%d", pWrapper->name, refCount);
|
||||
}
|
||||
|
||||
void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId) {
|
||||
pWrapper->msgFps[TMSG_INDEX(msgType)] = nodeMsgFp;
|
||||
pWrapper->msgVgIds[TMSG_INDEX(msgType)] = vgId;
|
||||
}
|
||||
|
||||
EDndStatus dndGetStatus(SDnode *pDnode) { return pDnode->status; }
|
||||
|
||||
void dndSetStatus(SDnode *pDnode, EDndStatus status) {
|
||||
if (pDnode->status != status) {
|
||||
dDebug("dnode status set from %s to %s", dndStatStr(pDnode->status), dndStatStr(status));
|
||||
pDnode->status = status;
|
||||
}
|
||||
}
|
||||
|
||||
void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc) {
|
||||
SStartupReq *pStartup = &pDnode->startup;
|
||||
tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN);
|
||||
tstrncpy(pStartup->desc, pDesc, TSDB_STEP_DESC_LEN);
|
||||
pStartup->finished = 0;
|
||||
}
|
||||
|
||||
static void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup) {
|
||||
memcpy(pStartup, &pDnode->startup, sizeof(SStartupReq));
|
||||
pStartup->finished = (dndGetStatus(pDnode) == DND_STAT_RUNNING);
|
||||
}
|
||||
|
||||
void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
dDebug("startup req is received");
|
||||
SStartupReq *pStartup = rpcMallocCont(sizeof(SStartupReq));
|
||||
dndGetStartup(pDnode, pStartup);
|
||||
|
||||
dDebug("startup req is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished);
|
||||
SRpcMsg rpcRsp = {
|
||||
.handle = pReq->handle, .pCont = pStartup, .contLen = sizeof(SStartupReq), .ahandle = pReq->ahandle};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
aux_source_directory(src MGMT_BNODE)
|
||||
add_library(mgmt_bnode STATIC ${MGMT_BNODE})
|
||||
target_include_directories(
|
||||
mgmt_bnode
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
target_link_libraries(
|
||||
mgmt_bnode dnode_interface
|
||||
)
|
|
@ -16,7 +16,7 @@
|
|||
#ifndef _TD_DND_BNODE_INT_H_
|
||||
#define _TD_DND_BNODE_INT_H_
|
||||
|
||||
#include "dndInt.h"
|
||||
#include "dmInt.h"
|
||||
|
||||
#include "bnode.h"
|
||||
|
||||
|
@ -33,10 +33,6 @@ typedef struct SBnodeMgmt {
|
|||
SSingleWorker monitorWorker;
|
||||
} SBnodeMgmt;
|
||||
|
||||
// bmInt.c
|
||||
int32_t bmOpen(SMgmtWrapper *pWrapper);
|
||||
int32_t bmDrop(SMgmtWrapper *pWrapper);
|
||||
|
||||
// bmHandle.c
|
||||
void bmInitMsgHandle(SMgmtWrapper *pWrapper);
|
||||
int32_t bmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
|
|
@ -53,13 +53,19 @@ int32_t bmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (createReq.dnodeId != pDnode->dnodeId) {
|
||||
if (createReq.dnodeId != pDnode->data.dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to create bnode since %s, input:%d cur:%d", terrstr(), createReq.dnodeId, pDnode->dnodeId);
|
||||
dError("failed to create bnode since %s, input:%d cur:%d", terrstr(), createReq.dnodeId, pDnode->data.dnodeId);
|
||||
return -1;
|
||||
} else {
|
||||
return dndOpenNode(pWrapper);
|
||||
}
|
||||
|
||||
bool deployed = true;
|
||||
if (dmWriteFile(pWrapper, deployed) != 0) {
|
||||
dError("failed to write bnode file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t bmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
||||
|
@ -72,16 +78,21 @@ int32_t bmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (dropReq.dnodeId != pDnode->dnodeId) {
|
||||
if (dropReq.dnodeId != pDnode->data.dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to drop bnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
// dndCloseNode(pWrapper);
|
||||
return bmDrop(pWrapper);
|
||||
}
|
||||
|
||||
bool deployed = false;
|
||||
if (dmWriteFile(pWrapper, deployed) != 0) {
|
||||
dError("failed to write bnode file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bmInitMsgHandle(SMgmtWrapper *pWrapper) {
|
||||
dndSetMsgHandle(pWrapper, TDMT_MON_BM_INFO, bmProcessMonitorMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MON_BM_INFO, bmProcessMonitorMsg, DEFAULT_HANDLE);
|
||||
}
|
|
@ -16,70 +16,25 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "bmInt.h"
|
||||
|
||||
static int32_t bmRequire(SMgmtWrapper *pWrapper, bool *required) { return dndReadFile(pWrapper, required); }
|
||||
static int32_t bmRequire(SMgmtWrapper *pWrapper, bool *required) { return dmReadFile(pWrapper, required); }
|
||||
|
||||
static void bmInitOption(SBnodeMgmt *pMgmt, SBnodeOpt *pOption) {
|
||||
SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper);
|
||||
SMsgCb msgCb = pMgmt->pDnode->data.msgCb;
|
||||
msgCb.pWrapper = pMgmt->pWrapper;
|
||||
pOption->msgCb = msgCb;
|
||||
}
|
||||
|
||||
static int32_t bmOpenImp(SBnodeMgmt *pMgmt) {
|
||||
SBnodeOpt option = {0};
|
||||
bmInitOption(pMgmt, &option);
|
||||
|
||||
pMgmt->pBnode = bndOpen(pMgmt->path, &option);
|
||||
if (pMgmt->pBnode == NULL) {
|
||||
dError("failed to open bnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (bmStartWorker(pMgmt) != 0) {
|
||||
dError("failed to start bnode worker since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool deployed = true;
|
||||
if (dndWriteFile(pMgmt->pWrapper, deployed) != 0) {
|
||||
dError("failed to write bnode file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void bmCloseImp(SBnodeMgmt *pMgmt) {
|
||||
if (pMgmt->pBnode != NULL) {
|
||||
bmStopWorker(pMgmt);
|
||||
bndClose(pMgmt->pBnode);
|
||||
pMgmt->pBnode = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t bmDrop(SMgmtWrapper *pWrapper) {
|
||||
SBnodeMgmt *pMgmt = pWrapper->pMgmt;
|
||||
if (pMgmt == NULL) return 0;
|
||||
|
||||
dInfo("bnode-mgmt start to drop");
|
||||
bool deployed = false;
|
||||
if (dndWriteFile(pWrapper, deployed) != 0) {
|
||||
dError("failed to drop bnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
bmCloseImp(pMgmt);
|
||||
taosRemoveDir(pMgmt->path);
|
||||
pWrapper->pMgmt = NULL;
|
||||
taosMemoryFree(pMgmt);
|
||||
dInfo("bnode-mgmt is dropped");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void bmClose(SMgmtWrapper *pWrapper) {
|
||||
SBnodeMgmt *pMgmt = pWrapper->pMgmt;
|
||||
if (pMgmt == NULL) return;
|
||||
|
||||
dInfo("bnode-mgmt start to cleanup");
|
||||
bmCloseImp(pMgmt);
|
||||
if (pMgmt->pBnode != NULL) {
|
||||
bmStopWorker(pMgmt);
|
||||
bndClose(pMgmt->pBnode);
|
||||
pMgmt->pBnode = NULL;
|
||||
}
|
||||
|
||||
pWrapper->pMgmt = NULL;
|
||||
taosMemoryFree(pMgmt);
|
||||
dInfo("bnode-mgmt is cleaned up");
|
||||
|
@ -98,23 +53,30 @@ int32_t bmOpen(SMgmtWrapper *pWrapper) {
|
|||
pMgmt->pWrapper = pWrapper;
|
||||
pWrapper->pMgmt = pMgmt;
|
||||
|
||||
int32_t code = bmOpenImp(pMgmt);
|
||||
if (code != 0) {
|
||||
dError("failed to init bnode-mgmt since %s", terrstr());
|
||||
SBnodeOpt option = {0};
|
||||
bmInitOption(pMgmt, &option);
|
||||
pMgmt->pBnode = bndOpen(pMgmt->path, &option);
|
||||
if (pMgmt->pBnode == NULL) {
|
||||
dError("failed to open bnode since %s", terrstr());
|
||||
bmClose(pWrapper);
|
||||
} else {
|
||||
dInfo("bnode-mgmt is initialized");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return code;
|
||||
if (bmStartWorker(pMgmt) != 0) {
|
||||
dError("failed to start bnode worker since %s", terrstr());
|
||||
bmClose(pWrapper);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bmSetMgmtFp(SMgmtWrapper *pWrapper) {
|
||||
SMgmtFp mgmtFp = {0};
|
||||
mgmtFp.openFp = bmOpen;
|
||||
mgmtFp.closeFp = bmClose;
|
||||
mgmtFp.createMsgFp = bmProcessCreateReq;
|
||||
mgmtFp.dropMsgFp = bmProcessDropReq;
|
||||
mgmtFp.createFp = bmProcessCreateReq;
|
||||
mgmtFp.dropFp = bmProcessDropReq;
|
||||
mgmtFp.requiredFp = bmRequire;
|
||||
|
||||
bmInitMsgHandle(pWrapper);
|
|
@ -0,0 +1,9 @@
|
|||
aux_source_directory(src MGMT_MNODE)
|
||||
add_library(mgmt_mnode STATIC ${MGMT_MNODE})
|
||||
target_include_directories(
|
||||
mgmt_mnode
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
target_link_libraries(
|
||||
mgmt_mnode dnode_interface
|
||||
)
|
|
@ -16,7 +16,8 @@
|
|||
#ifndef _TD_DND_MNODE_INT_H_
|
||||
#define _TD_DND_MNODE_INT_H_
|
||||
|
||||
#include "dndInt.h"
|
||||
#include "dmInt.h"
|
||||
|
||||
#include "mnode.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -40,11 +41,9 @@ typedef struct SMnodeMgmt {
|
|||
|
||||
// mmFile.c
|
||||
int32_t mmReadFile(SMnodeMgmt *pMgmt, bool *pDeployed);
|
||||
int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed);
|
||||
int32_t mmWriteFile(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq, bool deployed);
|
||||
|
||||
// mmInt.c
|
||||
int32_t mmOpenFromMsg(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq);
|
||||
int32_t mmDrop(SMgmtWrapper *pWrapper);
|
||||
int32_t mmAlter(SMnodeMgmt *pMgmt, SDAlterMnodeReq *pReq);
|
||||
|
||||
// mmHandle.c
|
|
@ -28,7 +28,7 @@ int32_t mmReadFile(SMnodeMgmt *pMgmt, bool *pDeployed) {
|
|||
snprintf(file, sizeof(file), "%s%smnode.json", pMgmt->path, TD_DIRSEP);
|
||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
dDebug("file %s not exist", file);
|
||||
// dDebug("file %s not exist", file);
|
||||
code = 0;
|
||||
goto PRASE_MNODE_OVER;
|
||||
}
|
||||
|
@ -105,9 +105,11 @@ PRASE_MNODE_OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) {
|
||||
char file[PATH_MAX];
|
||||
snprintf(file, sizeof(file), "%s%smnode.json.bak", pMgmt->path, TD_DIRSEP);
|
||||
int32_t mmWriteFile(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq, bool deployed) {
|
||||
char file[PATH_MAX] = {0};
|
||||
char realfile[PATH_MAX] = {0};
|
||||
snprintf(file, sizeof(file), "%s%smnode.json.bak", pWrapper->path, TD_DIRSEP);
|
||||
snprintf(realfile, sizeof(realfile), "%s%smnode.json", pWrapper->path, TD_DIRSEP);
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
|
@ -119,21 +121,30 @@ int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) {
|
|||
int32_t len = 0;
|
||||
int32_t maxLen = 4096;
|
||||
char *content = taosMemoryCalloc(1, maxLen + 1);
|
||||
|
||||
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
len += snprintf(content + len, maxLen - len, " \"deployed\": %d,\n", deployed);
|
||||
len += snprintf(content + len, maxLen - len, " \"mnodes\": [{\n");
|
||||
for (int32_t i = 0; i < pMgmt->replica; ++i) {
|
||||
SReplica *pReplica = &pMgmt->replicas[i];
|
||||
len += snprintf(content + len, maxLen - len, " \"id\": %d,\n", pReplica->id);
|
||||
len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pReplica->fqdn);
|
||||
len += snprintf(content + len, maxLen - len, " \"port\": %u\n", pReplica->port);
|
||||
if (i < pMgmt->replica - 1) {
|
||||
len += snprintf(content + len, maxLen - len, " },{\n");
|
||||
} else {
|
||||
len += snprintf(content + len, maxLen - len, " }]\n");
|
||||
|
||||
SMnodeMgmt *pMgmt = pWrapper->pMgmt;
|
||||
if (pReq != NULL || pMgmt != NULL) {
|
||||
int8_t replica = (pReq != NULL ? pReq->replica : pMgmt->replica);
|
||||
for (int32_t i = 0; i < replica; ++i) {
|
||||
SReplica *pReplica = &pMgmt->replicas[i];
|
||||
if (pReq != NULL) {
|
||||
pReplica = &pReq->replicas[i];
|
||||
}
|
||||
len += snprintf(content + len, maxLen - len, " \"id\": %d,\n", pReplica->id);
|
||||
len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pReplica->fqdn);
|
||||
len += snprintf(content + len, maxLen - len, " \"port\": %u\n", pReplica->port);
|
||||
if (i < replica - 1) {
|
||||
len += snprintf(content + len, maxLen - len, " },{\n");
|
||||
} else {
|
||||
len += snprintf(content + len, maxLen - len, " }],\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
len += snprintf(content + len, maxLen - len, " \"deployed\": %d\n", deployed);
|
||||
len += snprintf(content + len, maxLen - len, "}\n");
|
||||
|
||||
taosWriteFile(pFile, content, len);
|
||||
|
@ -141,9 +152,6 @@ int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) {
|
|||
taosCloseFile(&pFile);
|
||||
taosMemoryFree(content);
|
||||
|
||||
char realfile[PATH_MAX];
|
||||
snprintf(realfile, sizeof(realfile), "%s%smnode.json", pMgmt->path, TD_DIRSEP);
|
||||
|
||||
if (taosRenameFile(file, realfile) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to rename %s since %s", file, terrstr());
|
|
@ -0,0 +1,209 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http:www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "mmInt.h"
|
||||
|
||||
void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo) {
|
||||
SMnodeMgmt *pMgmt = pWrapper->pMgmt;
|
||||
mndGetMonitorInfo(pMgmt->pMnode, &mmInfo->cluster, &mmInfo->vgroup, &mmInfo->grant);
|
||||
}
|
||||
|
||||
int32_t mmProcessGetMonMmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) {
|
||||
SMonMmInfo mmInfo = {0};
|
||||
mmGetMonitorInfo(pWrapper, &mmInfo);
|
||||
dmGetMonitorSysInfo(&mmInfo.sys);
|
||||
monGetLogs(&mmInfo.log);
|
||||
|
||||
int32_t rspLen = tSerializeSMonMmInfo(NULL, 0, &mmInfo);
|
||||
if (rspLen < 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void *pRsp = rpcMallocCont(rspLen);
|
||||
if (pRsp == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tSerializeSMonMmInfo(pRsp, rspLen, &mmInfo);
|
||||
pReq->pRsp = pRsp;
|
||||
pReq->rspLen = rspLen;
|
||||
tFreeSMonMmInfo(&mmInfo);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
||||
SDnode *pDnode = pWrapper->pDnode;
|
||||
SRpcMsg *pReq = &pMsg->rpcMsg;
|
||||
|
||||
SDCreateMnodeReq createReq = {0};
|
||||
if (tDeserializeSDCreateMnodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (createReq.replica <= 1 || createReq.dnodeId != pDnode->data.dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to create mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool deployed = true;
|
||||
if (mmWriteFile(pWrapper, &createReq, deployed) != 0) {
|
||||
dError("failed to write mnode file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
||||
SDnode *pDnode = pWrapper->pDnode;
|
||||
SRpcMsg *pReq = &pMsg->rpcMsg;
|
||||
|
||||
SDDropMnodeReq dropReq = {0};
|
||||
if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dropReq.dnodeId != pDnode->data.dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to drop mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool deployed = false;
|
||||
if (mmWriteFile(pWrapper, NULL, deployed) != 0) {
|
||||
dError("failed to write mnode file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mmProcessAlterReq(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) {
|
||||
SDnode *pDnode = pMgmt->pDnode;
|
||||
SRpcMsg *pReq = &pMsg->rpcMsg;
|
||||
|
||||
SDAlterMnodeReq alterReq = {0};
|
||||
if (tDeserializeSDCreateMnodeReq(pReq->pCont, pReq->contLen, &alterReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (alterReq.dnodeId != pDnode->data.dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to alter mnode since %s, dnodeId:%d input:%d", terrstr(), pDnode->data.dnodeId, alterReq.dnodeId);
|
||||
return -1;
|
||||
} else {
|
||||
return mmAlter(pMgmt, &alterReq);
|
||||
}
|
||||
}
|
||||
|
||||
void mmInitMsgHandle(SMgmtWrapper *pWrapper) {
|
||||
dmSetMsgHandle(pWrapper, TDMT_MON_MM_INFO, mmProcessMonitorMsg, DEFAULT_HANDLE);
|
||||
|
||||
// Requests handled by DNODE
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
|
||||
// Requests handled by MNODE
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CONNECT, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_USER, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_USER, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_USER, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_GET_USER_AUTH, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CONFIG_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_QNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_QNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_SNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_SNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_BNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_BNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_DB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_DB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_USE_DB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_DB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_SYNC_DB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_COMPACT_DB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_RETRIEVE_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_STB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_STB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_STB, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_SMA, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_DROP_SMA, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_TABLE_META, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_VGROUP_LIST, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_KILL_QUERY, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_KILL_CONN, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_HEARTBEAT, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_SYSTABLE_RETRIEVE, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_STATUS, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_KILL_TRANS, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_GRANT, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_AUTH, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
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_CREATE_STREAM, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_GET_DB_CFG, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MND_GET_INDEX, mmProcessReadMsg, DEFAULT_HANDLE);
|
||||
|
||||
// Requests handled by VNODE
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_MQ_REB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_MQ_CANCEL_CONN_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_DROP_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA_RSP, mmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_QUERY, mmProcessQueryMsg, MNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, mmProcessQueryMsg, MNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_FETCH, mmProcessQueryMsg, MNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, mmProcessQueryMsg, MNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, mmProcessQueryMsg, MNODE_HANDLE);
|
||||
}
|
|
@ -18,9 +18,9 @@
|
|||
#include "wal.h"
|
||||
|
||||
static bool mmDeployRequired(SDnode *pDnode) {
|
||||
if (pDnode->dnodeId > 0) return false;
|
||||
if (pDnode->clusterId > 0) return false;
|
||||
if (strcmp(pDnode->localEp, pDnode->firstEp) != 0) return false;
|
||||
if (pDnode->data.dnodeId > 0) return false;
|
||||
if (pDnode->data.clusterId > 0) return false;
|
||||
if (strcmp(pDnode->data.localEp, pDnode->data.firstEp) != 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,8 @@ static int32_t mmRequire(SMgmtWrapper *pWrapper, bool *required) {
|
|||
}
|
||||
|
||||
static void mmInitOption(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) {
|
||||
SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper);
|
||||
SMsgCb msgCb = pMgmt->pDnode->data.msgCb;
|
||||
msgCb.pWrapper = pMgmt->pWrapper;
|
||||
msgCb.queueFps[QUERY_QUEUE] = mmPutMsgToQueryQueue;
|
||||
msgCb.queueFps[READ_QUEUE] = mmPutMsgToReadQueue;
|
||||
msgCb.queueFps[WRITE_QUEUE] = mmPutMsgToWriteQueue;
|
||||
|
@ -53,8 +54,8 @@ static void mmBuildOptionForDeploy(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) {
|
|||
pOption->selfIndex = 0;
|
||||
SReplica *pReplica = &pOption->replicas[0];
|
||||
pReplica->id = 1;
|
||||
pReplica->port = pMgmt->pDnode->serverPort;
|
||||
tstrncpy(pReplica->fqdn, pMgmt->pDnode->localFqdn, TSDB_FQDN_LEN);
|
||||
pReplica->port = pMgmt->pDnode->data.serverPort;
|
||||
tstrncpy(pReplica->fqdn, pMgmt->pDnode->data.localFqdn, TSDB_FQDN_LEN);
|
||||
pOption->deploy = true;
|
||||
|
||||
pMgmt->selfIndex = pOption->selfIndex;
|
||||
|
@ -80,7 +81,7 @@ static int32_t mmBuildOptionFromReq(SMnodeMgmt *pMgmt, SMnodeOpt *pOption, SDCre
|
|||
pReplica->id = pCreate->replicas[i].id;
|
||||
pReplica->port = pCreate->replicas[i].port;
|
||||
memcpy(pReplica->fqdn, pCreate->replicas[i].fqdn, TSDB_FQDN_LEN);
|
||||
if (pReplica->id == pMgmt->pDnode->dnodeId) {
|
||||
if (pReplica->id == pMgmt->pDnode->data.dnodeId) {
|
||||
pOption->selfIndex = i;
|
||||
}
|
||||
}
|
||||
|
@ -97,83 +98,22 @@ static int32_t mmBuildOptionFromReq(SMnodeMgmt *pMgmt, SMnodeOpt *pOption, SDCre
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mmOpenImp(SMnodeMgmt *pMgmt, SDCreateMnodeReq *pReq) {
|
||||
SMnodeOpt option = {0};
|
||||
if (pReq != NULL) {
|
||||
if (mmBuildOptionFromReq(pMgmt, &option, pReq) != 0) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
bool deployed = false;
|
||||
if (mmReadFile(pMgmt, &deployed) != 0) {
|
||||
dError("failed to read file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!deployed) {
|
||||
dInfo("mnode start to deploy");
|
||||
if (pMgmt->pWrapper->procType == PROC_CHILD) {
|
||||
pMgmt->pDnode->dnodeId = 1;
|
||||
}
|
||||
mmBuildOptionForDeploy(pMgmt, &option);
|
||||
} else {
|
||||
dInfo("mnode start to open");
|
||||
mmBuildOptionForOpen(pMgmt, &option);
|
||||
}
|
||||
}
|
||||
|
||||
pMgmt->pMnode = mndOpen(pMgmt->path, &option);
|
||||
if (pMgmt->pMnode == NULL) {
|
||||
dError("failed to open mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mmStartWorker(pMgmt) != 0) {
|
||||
dError("failed to start mnode worker since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool deployed = true;
|
||||
if (mmWriteFile(pMgmt, deployed) != 0) {
|
||||
dError("failed to write mnode file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mmCloseImp(SMnodeMgmt *pMgmt) {
|
||||
if (pMgmt->pMnode != NULL) {
|
||||
mmStopWorker(pMgmt);
|
||||
mndClose(pMgmt->pMnode);
|
||||
pMgmt->pMnode = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t mmAlter(SMnodeMgmt *pMgmt, SDAlterMnodeReq *pReq) {
|
||||
SMnodeOpt option = {0};
|
||||
if (mmBuildOptionFromReq(pMgmt, &option, pReq) != 0) {
|
||||
return -1;
|
||||
}
|
||||
return mndAlter(pMgmt->pMnode, &option);
|
||||
}
|
||||
|
||||
int32_t mmDrop(SMgmtWrapper *pWrapper) {
|
||||
SMnodeMgmt *pMgmt = pWrapper->pMgmt;
|
||||
if (pMgmt == NULL) return 0;
|
||||
|
||||
dInfo("mnode-mgmt start to drop");
|
||||
bool deployed = false;
|
||||
if (mmWriteFile(pMgmt, deployed) != 0) {
|
||||
dError("failed to drop mnode since %s", terrstr());
|
||||
if (mndAlter(pMgmt->pMnode, &option) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool deployed = true;
|
||||
if (mmWriteFile(pMgmt->pWrapper, pReq, deployed) != 0) {
|
||||
dError("failed to write mnode file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
mmCloseImp(pMgmt);
|
||||
taosRemoveDir(pMgmt->path);
|
||||
pWrapper->pMgmt = NULL;
|
||||
taosMemoryFree(pMgmt);
|
||||
dInfo("mnode-mgmt is dropped");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -182,13 +122,18 @@ static void mmClose(SMgmtWrapper *pWrapper) {
|
|||
if (pMgmt == NULL) return;
|
||||
|
||||
dInfo("mnode-mgmt start to cleanup");
|
||||
mmCloseImp(pMgmt);
|
||||
if (pMgmt->pMnode != NULL) {
|
||||
mmStopWorker(pMgmt);
|
||||
mndClose(pMgmt->pMnode);
|
||||
pMgmt->pMnode = NULL;
|
||||
}
|
||||
|
||||
pWrapper->pMgmt = NULL;
|
||||
taosMemoryFree(pMgmt);
|
||||
dInfo("mnode-mgmt is cleaned up");
|
||||
}
|
||||
|
||||
int32_t mmOpenFromMsg(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq) {
|
||||
static int32_t mmOpen(SMgmtWrapper *pWrapper) {
|
||||
dInfo("mnode-mgmt start to init");
|
||||
if (walInit() != 0) {
|
||||
dError("failed to init wal since %s", terrstr());
|
||||
|
@ -206,18 +151,49 @@ int32_t mmOpenFromMsg(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq) {
|
|||
pMgmt->pWrapper = pWrapper;
|
||||
pWrapper->pMgmt = pMgmt;
|
||||
|
||||
int32_t code = mmOpenImp(pMgmt, pReq);
|
||||
if (code != 0) {
|
||||
dError("failed to init mnode-mgmt since %s", terrstr());
|
||||
bool deployed = false;
|
||||
if (mmReadFile(pMgmt, &deployed) != 0) {
|
||||
dError("failed to read file since %s", terrstr());
|
||||
mmClose(pWrapper);
|
||||
} else {
|
||||
dInfo("mnode-mgmt is initialized");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
SMnodeOpt option = {0};
|
||||
if (!deployed) {
|
||||
dInfo("mnode start to deploy");
|
||||
if (pWrapper->procType == DND_PROC_CHILD) {
|
||||
pWrapper->pDnode->data.dnodeId = 1;
|
||||
}
|
||||
mmBuildOptionForDeploy(pMgmt, &option);
|
||||
} else {
|
||||
dInfo("mnode start to open");
|
||||
mmBuildOptionForOpen(pMgmt, &option);
|
||||
}
|
||||
|
||||
static int32_t mmOpen(SMgmtWrapper *pWrapper) { return mmOpenFromMsg(pWrapper, NULL); }
|
||||
pMgmt->pMnode = mndOpen(pMgmt->path, &option);
|
||||
if (pMgmt->pMnode == NULL) {
|
||||
dError("failed to open mnode since %s", terrstr());
|
||||
mmClose(pWrapper);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mmStartWorker(pMgmt) != 0) {
|
||||
dError("failed to start mnode worker since %s", terrstr());
|
||||
mmClose(pWrapper);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!deployed) {
|
||||
deployed = true;
|
||||
if (mmWriteFile(pWrapper, NULL, deployed) != 0) {
|
||||
dError("failed to write mnode file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
dInfo("mnode-mgmt is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mmStart(SMgmtWrapper *pWrapper) {
|
||||
dDebug("mnode-mgmt start to run");
|
||||
|
@ -225,13 +201,22 @@ static int32_t mmStart(SMgmtWrapper *pWrapper) {
|
|||
return mndStart(pMgmt->pMnode);
|
||||
}
|
||||
|
||||
static void mmStop(SMgmtWrapper *pWrapper) {
|
||||
dDebug("mnode-mgmt start to stop");
|
||||
SMnodeMgmt *pMgmt = pWrapper->pMgmt;
|
||||
if (pMgmt != NULL) {
|
||||
mndStop(pMgmt->pMnode);
|
||||
}
|
||||
}
|
||||
|
||||
void mmSetMgmtFp(SMgmtWrapper *pWrapper) {
|
||||
SMgmtFp mgmtFp = {0};
|
||||
mgmtFp.openFp = mmOpen;
|
||||
mgmtFp.closeFp = mmClose;
|
||||
mgmtFp.startFp = mmStart;
|
||||
mgmtFp.createMsgFp = mmProcessCreateReq;
|
||||
mgmtFp.dropMsgFp = mmProcessDropReq;
|
||||
mgmtFp.stopFp = mmStop;
|
||||
mgmtFp.createFp = mmProcessCreateReq;
|
||||
mgmtFp.dropFp = mmProcessDropReq;
|
||||
mgmtFp.requiredFp = mmRequire;
|
||||
|
||||
mmInitMsgHandle(pWrapper);
|
|
@ -0,0 +1,9 @@
|
|||
aux_source_directory(src MGMT_QNODE)
|
||||
add_library(mgmt_qnode STATIC ${MGMT_QNODE})
|
||||
target_include_directories(
|
||||
mgmt_qnode
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
target_link_libraries(
|
||||
mgmt_qnode dnode_interface
|
||||
)
|
|
@ -16,7 +16,8 @@
|
|||
#ifndef _TD_DND_QNODE_INT_H_
|
||||
#define _TD_DND_QNODE_INT_H_
|
||||
|
||||
#include "dndInt.h"
|
||||
#include "dmInt.h"
|
||||
|
||||
#include "qnode.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -33,10 +34,6 @@ typedef struct SQnodeMgmt {
|
|||
SSingleWorker monitorWorker;
|
||||
} SQnodeMgmt;
|
||||
|
||||
// qmInt.c
|
||||
int32_t qmOpen(SMgmtWrapper *pWrapper);
|
||||
int32_t qmDrop(SMgmtWrapper *pWrapper);
|
||||
|
||||
// qmHandle.c
|
||||
void qmInitMsgHandle(SMgmtWrapper *pWrapper);
|
||||
int32_t qmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg);
|
|
@ -53,13 +53,19 @@ int32_t qmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (createReq.dnodeId != pDnode->dnodeId) {
|
||||
if (createReq.dnodeId != pDnode->data.dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to create qnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
return dndOpenNode(pWrapper);
|
||||
}
|
||||
|
||||
bool deployed = true;
|
||||
if (dmWriteFile(pWrapper, deployed) != 0) {
|
||||
dError("failed to write qnode file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t qmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
||||
|
@ -72,28 +78,32 @@ int32_t qmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (dropReq.dnodeId != pDnode->dnodeId) {
|
||||
if (dropReq.dnodeId != pDnode->data.dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to drop qnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
// dndCloseNode(pWrapper);
|
||||
return qmDrop(pWrapper);
|
||||
}
|
||||
|
||||
bool deployed = false;
|
||||
if (dmWriteFile(pWrapper, deployed) != 0) {
|
||||
dError("failed to write qnode file since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void qmInitMsgHandle(SMgmtWrapper *pWrapper) {
|
||||
dndSetMsgHandle(pWrapper, TDMT_MON_QM_INFO, qmProcessMonitorMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_MON_QM_INFO, qmProcessMonitorMsg, DEFAULT_HANDLE);
|
||||
|
||||
// Requests handled by VNODE
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, qmProcessQueryMsg, QNODE_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, qmProcessQueryMsg, QNODE_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_QUERY, qmProcessQueryMsg, QNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, qmProcessQueryMsg, QNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_FETCH, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_RES_READY, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_RES_READY, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, qmProcessFetchMsg, QNODE_HANDLE);
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue