merge from 3.0
This commit is contained in:
commit
8938c902de
|
|
@ -18,7 +18,8 @@
|
||||||
"ms-vscode.cpptools",
|
"ms-vscode.cpptools",
|
||||||
"ms-vscode.cmake-tools",
|
"ms-vscode.cmake-tools",
|
||||||
"austin.code-gnu-global",
|
"austin.code-gnu-global",
|
||||||
"visualstudioexptteam.vscodeintel"
|
"visualstudioexptteam.vscodeintel",
|
||||||
|
"eamodio.gitlens"
|
||||||
],
|
],
|
||||||
|
|
||||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,12 @@ option(
|
||||||
OFF
|
OFF
|
||||||
)
|
)
|
||||||
|
|
||||||
|
option(
|
||||||
|
BUILD_WITH_TRAFT
|
||||||
|
"If build with traft"
|
||||||
|
OFF
|
||||||
|
)
|
||||||
|
|
||||||
option(
|
option(
|
||||||
BUILD_DEPENDENCY_TESTS
|
BUILD_DEPENDENCY_TESTS
|
||||||
"If build dependency tests"
|
"If build dependency tests"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
|
||||||
|
# traft
|
||||||
|
ExternalProject_Add(traft
|
||||||
|
GIT_REPOSITORY https://github.com/taosdata/traft.git
|
||||||
|
GIT_TAG for_3.0
|
||||||
|
SOURCE_DIR "${CMAKE_CONTRIB_DIR}/traft"
|
||||||
|
BINARY_DIR "${CMAKE_CONTRIB_DIR}/traft"
|
||||||
|
#BUILD_IN_SOURCE TRUE
|
||||||
|
# https://answers.ros.org/question/333125/how-to-include-external-automakeautoconf-projects-into-ament_cmake/
|
||||||
|
CONFIGURE_COMMAND COMMAND autoreconf -i COMMAND ./configure --enable-example
|
||||||
|
BUILD_COMMAND "$(MAKE)"
|
||||||
|
INSTALL_COMMAND ""
|
||||||
|
TEST_COMMAND ""
|
||||||
|
)
|
||||||
|
|
@ -41,6 +41,12 @@ if(${BUILD_WITH_CRAFT})
|
||||||
SET(BUILD_WITH_UV ON CACHE BOOL "craft need libuv" FORCE)
|
SET(BUILD_WITH_UV ON CACHE BOOL "craft need libuv" FORCE)
|
||||||
endif(${BUILD_WITH_CRAFT})
|
endif(${BUILD_WITH_CRAFT})
|
||||||
|
|
||||||
|
# traft
|
||||||
|
if(${BUILD_WITH_TRAFT})
|
||||||
|
cat("${CMAKE_SUPPORT_DIR}/traft_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||||
|
SET(BUILD_WITH_UV ON CACHE BOOL "traft need libuv" FORCE)
|
||||||
|
endif(${BUILD_WITH_TRAFT})
|
||||||
|
|
||||||
#libuv
|
#libuv
|
||||||
if(${BUILD_WITH_UV})
|
if(${BUILD_WITH_UV})
|
||||||
cat("${CMAKE_SUPPORT_DIR}/libuv_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
cat("${CMAKE_SUPPORT_DIR}/libuv_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||||
|
|
@ -173,6 +179,18 @@ if(${BUILD_WITH_CRAFT})
|
||||||
# )
|
# )
|
||||||
endif(${BUILD_WITH_CRAFT})
|
endif(${BUILD_WITH_CRAFT})
|
||||||
|
|
||||||
|
# TRAFT
|
||||||
|
if(${BUILD_WITH_TRAFT})
|
||||||
|
add_library(traft STATIC IMPORTED GLOBAL)
|
||||||
|
set_target_properties(traft PROPERTIES
|
||||||
|
IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/traft/.libs/libraft.a"
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/traft/include"
|
||||||
|
)
|
||||||
|
# target_link_libraries(craft
|
||||||
|
# INTERFACE pthread
|
||||||
|
# )
|
||||||
|
endif(${BUILD_WITH_TRAFT})
|
||||||
|
|
||||||
# LIBUV
|
# LIBUV
|
||||||
if(${BUILD_WITH_UV})
|
if(${BUILD_WITH_UV})
|
||||||
add_subdirectory(libuv)
|
add_subdirectory(libuv)
|
||||||
|
|
|
||||||
|
|
@ -19,4 +19,8 @@ if(${BUILD_WITH_CRAFT})
|
||||||
add_subdirectory(craft)
|
add_subdirectory(craft)
|
||||||
endif(${BUILD_WITH_CRAFT})
|
endif(${BUILD_WITH_CRAFT})
|
||||||
|
|
||||||
|
if(${BUILD_WITH_TRAFT})
|
||||||
|
add_subdirectory(traft)
|
||||||
|
endif(${BUILD_WITH_TRAFT})
|
||||||
|
|
||||||
add_subdirectory(tdev)
|
add_subdirectory(tdev)
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ typedef struct {
|
||||||
} Addr;
|
} Addr;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
int voter;
|
||||||
Addr me;
|
Addr me;
|
||||||
Addr peers[MAX_PEERS];
|
Addr peers[MAX_PEERS];
|
||||||
int peersCount;
|
int peersCount;
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ const char* state2String(unsigned short state) {
|
||||||
void printRaftConfiguration(struct raft_configuration *c) {
|
void printRaftConfiguration(struct raft_configuration *c) {
|
||||||
printf("configuration: \n");
|
printf("configuration: \n");
|
||||||
for (int i = 0; i < c->n; ++i) {
|
for (int i = 0; i < c->n; ++i) {
|
||||||
printf("%llu -- %d -- %s\n", c->servers->id, c->servers->role, c->servers->address);
|
printf("%llu -- %d -- %s\n", c->servers[i].id, c->servers[i].role, c->servers[i].address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,11 +119,9 @@ void printRaftState(struct raft *r) {
|
||||||
printf("last_applied: %llu \n", r->last_applied);
|
printf("last_applied: %llu \n", r->last_applied);
|
||||||
printf("last_stored: %llu \n", r->last_stored);
|
printf("last_stored: %llu \n", r->last_stored);
|
||||||
|
|
||||||
/*
|
|
||||||
printf("configuration_index: %llu \n", r->configuration_index);
|
printf("configuration_index: %llu \n", r->configuration_index);
|
||||||
printf("configuration_uncommitted_index: %llu \n", r->configuration_uncommitted_index);
|
printf("configuration_uncommitted_index: %llu \n", r->configuration_uncommitted_index);
|
||||||
printRaftConfiguration(&r->configuration);
|
printRaftConfiguration(&r->configuration);
|
||||||
*/
|
|
||||||
|
|
||||||
printf("----------------------------\n");
|
printf("----------------------------\n");
|
||||||
}
|
}
|
||||||
|
|
@ -164,6 +162,18 @@ void getValue(const char *key) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void raft_change_cb_add(struct raft_change *req, int status) {
|
||||||
|
printf("raft_change_cb_add status:%d ... \n", status);
|
||||||
|
}
|
||||||
|
|
||||||
|
void raft_change_cb_assign(struct raft_change *req, int status) {
|
||||||
|
printf("raft_change_cb_assign status:%d ... \n", status);
|
||||||
|
}
|
||||||
|
|
||||||
|
void raft_change_cb_remove(struct raft_change *req, int status) {
|
||||||
|
printf("raft_change_cb_remove status:%d ... \n", status);
|
||||||
|
}
|
||||||
|
|
||||||
void console(SRaftServer *pRaftServer) {
|
void console(SRaftServer *pRaftServer) {
|
||||||
while (1) {
|
while (1) {
|
||||||
char cmd_buf[COMMAND_LEN];
|
char cmd_buf[COMMAND_LEN];
|
||||||
|
|
@ -193,30 +203,59 @@ void console(SRaftServer *pRaftServer) {
|
||||||
|
|
||||||
parseCommand(cmd_buf, cmd, param1, param2, TOKEN_LEN);
|
parseCommand(cmd_buf, cmd, param1, param2, TOKEN_LEN);
|
||||||
if (strcmp(cmd, "addnode") == 0) {
|
if (strcmp(cmd, "addnode") == 0) {
|
||||||
printf("not support \n");
|
//printf("not support \n");
|
||||||
|
|
||||||
/*
|
|
||||||
char host[HOST_LEN];
|
char host[HOST_LEN];
|
||||||
uint32_t port;
|
uint32_t port;
|
||||||
parseAddr(param1, host, HOST_LEN, &port);
|
parseAddr(param1, host, HOST_LEN, &port);
|
||||||
uint64_t rid = raftId(host, port);
|
uint64_t rid = raftId(host, port);
|
||||||
|
|
||||||
struct raft_change *req = raft_malloc(sizeof(*req));
|
struct raft_change *req = raft_malloc(sizeof(*req));
|
||||||
int r = raft_add(&pRaftServer->raft, req, rid, param1, NULL);
|
int r = raft_add(&pRaftServer->raft, req, rid, param1, raft_change_cb_add);
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
printf("raft_add: %s \n", raft_errmsg(&pRaftServer->raft));
|
printf("raft_add error: %s \n", raft_errmsg(&pRaftServer->raft));
|
||||||
}
|
}
|
||||||
printf("add node: %lu %s \n", rid, param1);
|
printf("add node: %lu %s \n", rid, param1);
|
||||||
|
|
||||||
struct raft_change *req2 = raft_malloc(sizeof(*req2));
|
struct raft_change *req2 = raft_malloc(sizeof(*req2));
|
||||||
r = raft_assign(&pRaftServer->raft, req2, rid, RAFT_VOTER, NULL);
|
r = raft_assign(&pRaftServer->raft, req2, rid, RAFT_VOTER, raft_change_cb_assign);
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
printf("raft_assign: %s \n", raft_errmsg(&pRaftServer->raft));
|
printf("raft_assign error: %s \n", raft_errmsg(&pRaftServer->raft));
|
||||||
}
|
}
|
||||||
*/
|
printf("raft_assign: %s %d \n", param1, RAFT_VOTER);
|
||||||
|
|
||||||
|
} else if (strcmp(cmd, "activate") == 0) {
|
||||||
|
char host[HOST_LEN];
|
||||||
|
uint32_t port;
|
||||||
|
parseAddr(param1, host, HOST_LEN, &port);
|
||||||
|
uint64_t rid = raftId(host, port);
|
||||||
|
|
||||||
|
|
||||||
|
struct raft_change *req2 = raft_malloc(sizeof(*req2));
|
||||||
|
int r = raft_assign(&pRaftServer->raft, req2, rid, RAFT_VOTER, raft_change_cb_assign);
|
||||||
|
if (r != 0) {
|
||||||
|
printf("raft_assign error: %s \n", raft_errmsg(&pRaftServer->raft));
|
||||||
|
}
|
||||||
|
printf("raft_assign: %s %d \n", param1, RAFT_VOTER);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} else if (strcmp(cmd, "dropnode") == 0) {
|
} else if (strcmp(cmd, "dropnode") == 0) {
|
||||||
printf("not support \n");
|
char host[HOST_LEN];
|
||||||
|
uint32_t port;
|
||||||
|
parseAddr(param1, host, HOST_LEN, &port);
|
||||||
|
uint64_t rid = raftId(host, port);
|
||||||
|
|
||||||
|
struct raft_change *req = raft_malloc(sizeof(*req));
|
||||||
|
int r = raft_remove(&pRaftServer->raft, req, rid, raft_change_cb_remove);
|
||||||
|
if (r != 0) {
|
||||||
|
printf("raft_remove: %s \n", raft_errmsg(&pRaftServer->raft));
|
||||||
|
}
|
||||||
|
printf("drop node: %lu %s \n", rid, param1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} else if (strcmp(cmd, "put") == 0) {
|
} else if (strcmp(cmd, "put") == 0) {
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
|
@ -234,6 +273,7 @@ void console(SRaftServer *pRaftServer) {
|
||||||
|
|
||||||
} else if (strcmp(cmd, "help") == 0) {
|
} else if (strcmp(cmd, "help") == 0) {
|
||||||
printf("addnode \"127.0.0.1:8888\" \n");
|
printf("addnode \"127.0.0.1:8888\" \n");
|
||||||
|
printf("activate \"127.0.0.1:8888\" \n");
|
||||||
printf("dropnode \"127.0.0.1:8888\" \n");
|
printf("dropnode \"127.0.0.1:8888\" \n");
|
||||||
printf("put key value \n");
|
printf("put key value \n");
|
||||||
printf("get key \n");
|
printf("get key \n");
|
||||||
|
|
@ -256,7 +296,9 @@ void *startConsoleFunc(void *param) {
|
||||||
// Config ---------------------------------
|
// Config ---------------------------------
|
||||||
void usage() {
|
void usage() {
|
||||||
printf("\nusage: \n");
|
printf("\nusage: \n");
|
||||||
printf("%s --me=127.0.0.1:10000 --dir=./data \n", exe_name);
|
printf("%s --me=127.0.0.1:10000 --dir=./data --voter \n", exe_name);
|
||||||
|
printf("%s --me=127.0.0.1:10001 --dir=./data \n", exe_name);
|
||||||
|
printf("%s --me=127.0.0.1:10002 --dir=./data \n", exe_name);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("%s --me=127.0.0.1:10000 --peers=127.0.0.1:10001,127.0.0.1:10002 --dir=./data \n", exe_name);
|
printf("%s --me=127.0.0.1:10000 --peers=127.0.0.1:10001,127.0.0.1:10002 --dir=./data \n", exe_name);
|
||||||
printf("%s --me=127.0.0.1:10001 --peers=127.0.0.1:10000,127.0.0.1:10002 --dir=./data \n", exe_name);
|
printf("%s --me=127.0.0.1:10001 --peers=127.0.0.1:10000,127.0.0.1:10002 --dir=./data \n", exe_name);
|
||||||
|
|
@ -271,13 +313,15 @@ void parseConf(int argc, char **argv, SRaftServerConfig *pConf) {
|
||||||
option_index = 0;
|
option_index = 0;
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"help", no_argument, NULL, 'h'},
|
||||||
|
{"voter", no_argument, NULL, 'v'},
|
||||||
{"peers", required_argument, NULL, 'p'},
|
{"peers", required_argument, NULL, 'p'},
|
||||||
{"me", required_argument, NULL, 'm'},
|
{"me", required_argument, NULL, 'm'},
|
||||||
{"dir", required_argument, NULL, 'd'},
|
{"dir", required_argument, NULL, 'd'},
|
||||||
{NULL, 0, NULL, 0}
|
{NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
while ((option_value = getopt_long(argc, argv, "hp:m:d:", long_options, &option_index)) != -1) {
|
pConf->voter = 0;
|
||||||
|
while ((option_value = getopt_long(argc, argv, "hvp:m:d:", long_options, &option_index)) != -1) {
|
||||||
switch (option_value) {
|
switch (option_value) {
|
||||||
case 'm': {
|
case 'm': {
|
||||||
parseAddr(optarg, pConf->me.host, sizeof(pConf->me.host), &pConf->me.port);
|
parseAddr(optarg, pConf->me.host, sizeof(pConf->me.host), &pConf->me.port);
|
||||||
|
|
@ -295,6 +339,10 @@ void parseConf(int argc, char **argv, SRaftServerConfig *pConf) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 'v': {
|
||||||
|
pConf->voter = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 'd': {
|
case 'd': {
|
||||||
snprintf(pConf->dir, sizeof(pConf->dir), "%s", optarg);
|
snprintf(pConf->dir, sizeof(pConf->dir), "%s", optarg);
|
||||||
|
|
@ -338,6 +386,8 @@ int main(int argc, char **argv) {
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
|
||||||
SRaftServerConfig conf;
|
SRaftServerConfig conf;
|
||||||
parseConf(argc, argv, &conf);
|
parseConf(argc, argv, &conf);
|
||||||
printConf(&conf);
|
printConf(&conf);
|
||||||
|
|
|
||||||
|
|
@ -85,29 +85,45 @@ int32_t raftServerInit(SRaftServer *pRaftServer, const SRaftServerConfig *pConf,
|
||||||
pRaftServer->fsm = pFsm;
|
pRaftServer->fsm = pFsm;
|
||||||
|
|
||||||
ret = uv_loop_init(&pRaftServer->loop);
|
ret = uv_loop_init(&pRaftServer->loop);
|
||||||
if (!ret) {
|
if (ret != 0) {
|
||||||
fprintf(stderr, "%s \n", raft_errmsg(&pRaftServer->raft));
|
fprintf(stderr, "%s \n", raft_errmsg(&pRaftServer->raft));
|
||||||
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = raft_uv_tcp_init(&pRaftServer->transport, &pRaftServer->loop);
|
ret = raft_uv_tcp_init(&pRaftServer->transport, &pRaftServer->loop);
|
||||||
if (!ret) {
|
if (ret != 0) {
|
||||||
fprintf(stderr, "%s \n", raft_errmsg(&pRaftServer->raft));
|
fprintf(stderr, "%s \n", raft_errmsg(&pRaftServer->raft));
|
||||||
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = raft_uv_init(&pRaftServer->io, &pRaftServer->loop, pRaftServer->dir, &pRaftServer->transport);
|
ret = raft_uv_init(&pRaftServer->io, &pRaftServer->loop, pRaftServer->dir, &pRaftServer->transport);
|
||||||
if (!ret) {
|
if (ret != 0) {
|
||||||
fprintf(stderr, "%s \n", raft_errmsg(&pRaftServer->raft));
|
fprintf(stderr, "%s \n", raft_errmsg(&pRaftServer->raft));
|
||||||
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = raft_init(&pRaftServer->raft, &pRaftServer->io, pRaftServer->fsm, pRaftServer->raftId, pRaftServer->address);
|
ret = raft_init(&pRaftServer->raft, &pRaftServer->io, pRaftServer->fsm, pRaftServer->raftId, pRaftServer->address);
|
||||||
if (!ret) {
|
if (ret != 0) {
|
||||||
fprintf(stderr, "%s \n", raft_errmsg(&pRaftServer->raft));
|
fprintf(stderr, "%s \n", raft_errmsg(&pRaftServer->raft));
|
||||||
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct raft_configuration conf;
|
struct raft_configuration conf;
|
||||||
raft_configuration_init(&conf);
|
raft_configuration_init(&conf);
|
||||||
|
|
||||||
|
if (pConf->voter == 0) {
|
||||||
|
raft_configuration_add(&conf, pRaftServer->raftId, pRaftServer->address, RAFT_SPARE);
|
||||||
|
|
||||||
|
} else {
|
||||||
raft_configuration_add(&conf, pRaftServer->raftId, pRaftServer->address, RAFT_VOTER);
|
raft_configuration_add(&conf, pRaftServer->raftId, pRaftServer->address, RAFT_VOTER);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
printf("add myself: %llu - %s \n", pRaftServer->raftId, pRaftServer->address);
|
printf("add myself: %llu - %s \n", pRaftServer->raftId, pRaftServer->address);
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < pConf->peersCount; ++i) {
|
for (int i = 0; i < pConf->peersCount; ++i) {
|
||||||
const Addr *pAddr = &pConf->peers[i];
|
const Addr *pAddr = &pConf->peers[i];
|
||||||
raft_id rid = raftId(pAddr->host, pAddr->port);
|
raft_id rid = raftId(pAddr->host, pAddr->port);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
add_executable(raftMain "")
|
||||||
|
target_sources(raftMain
|
||||||
|
PRIVATE
|
||||||
|
"raftMain.c"
|
||||||
|
"raftServer.c"
|
||||||
|
)
|
||||||
|
target_link_libraries(raftMain PUBLIC traft lz4 uv_a)
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
rm -rf 127.0.0.1*
|
||||||
|
rm -rf ./data
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
#ifndef TDENGINE_COMMON_H
|
||||||
|
#define TDENGINE_COMMON_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define MAX_INSTANCE_NUM 100
|
||||||
|
|
||||||
|
#define MAX_PEERS 10
|
||||||
|
#define COMMAND_LEN 1024
|
||||||
|
#define TOKEN_LEN 128
|
||||||
|
#define DIR_LEN 256
|
||||||
|
#define HOST_LEN 64
|
||||||
|
#define ADDRESS_LEN (HOST_LEN + 16)
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char host[HOST_LEN];
|
||||||
|
uint32_t port;
|
||||||
|
} Addr;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Addr me;
|
||||||
|
Addr peers[MAX_PEERS];
|
||||||
|
int peersCount;
|
||||||
|
char dir[DIR_LEN];
|
||||||
|
char dataDir[DIR_LEN + HOST_LEN * 2];
|
||||||
|
} SRaftServerConfig;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // TDENGINE_COMMON_H
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
|
||||||
|
make raftServer
|
||||||
|
|
||||||
|
all:
|
||||||
|
gcc raftMain.c raftServer.c -I ../../traft/include/ ../../traft/.libs/libraft.a -o raftMain -luv -llz4 -lpthread -g
|
||||||
|
clean:
|
||||||
|
rm -f raftMain
|
||||||
|
sh clear.sh
|
||||||
|
|
||||||
|
|
||||||
|
make traft:
|
||||||
|
|
||||||
|
sudo apt-get install libuv1-dev liblz4-dev
|
||||||
|
autoreconf -i
|
||||||
|
./configure --enable-example
|
||||||
|
make
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,659 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <raft.h>
|
||||||
|
#include <raft/uv.h>
|
||||||
|
#include "raftServer.h"
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
const char *exe_name;
|
||||||
|
|
||||||
|
typedef struct LeaderState {
|
||||||
|
char address[48];
|
||||||
|
int leaderCount;
|
||||||
|
|
||||||
|
} LeaderState;
|
||||||
|
|
||||||
|
#define NODE_COUNT 3
|
||||||
|
LeaderState leaderStates[NODE_COUNT];
|
||||||
|
|
||||||
|
void printLeaderCount() {
|
||||||
|
for (int i = 0; i < NODE_COUNT; ++i) {
|
||||||
|
printf("%s: leaderCount:%d \n", leaderStates[i].address, leaderStates[i].leaderCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateLeaderStates(SRaftServer *pRaftServer) {
|
||||||
|
for (int i = 0; i < pRaftServer->instance[0].raft.configuration.n; ++i) {
|
||||||
|
snprintf(leaderStates[i].address, sizeof(leaderStates[i].address), "%s", pRaftServer->instance[0].raft.configuration.servers[i].address);
|
||||||
|
leaderStates[i].leaderCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < pRaftServer->instanceCount; ++i) {
|
||||||
|
struct raft *r = &pRaftServer->instance[i].raft;
|
||||||
|
|
||||||
|
char leaderAddress[128];
|
||||||
|
memset(leaderAddress, 0, sizeof(leaderAddress));
|
||||||
|
|
||||||
|
if (r->state == RAFT_LEADER) {
|
||||||
|
snprintf(leaderAddress, sizeof(leaderAddress), "%s", r->address);
|
||||||
|
} else if (r->state == RAFT_FOLLOWER) {
|
||||||
|
snprintf(leaderAddress, sizeof(leaderAddress), "%s", r->follower_state.current_leader.address);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < NODE_COUNT; j++) {
|
||||||
|
if (strcmp(leaderAddress, leaderStates[j].address) == 0) {
|
||||||
|
leaderStates[j].leaderCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void raftTransferCb(struct raft_transfer *req) {
|
||||||
|
SRaftServer *pRaftServer = req->data;
|
||||||
|
raft_free(req);
|
||||||
|
|
||||||
|
printf("raftTransferCb: \n");
|
||||||
|
updateLeaderStates(pRaftServer);
|
||||||
|
printLeaderCount();
|
||||||
|
|
||||||
|
int myLeaderCount;
|
||||||
|
for (int i = 0; i < NODE_COUNT; ++i) {
|
||||||
|
if (strcmp(pRaftServer->address, leaderStates[i].address) == 0) {
|
||||||
|
myLeaderCount = leaderStates[i].leaderCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("myLeaderCount:%d waterLevel:%d \n", myLeaderCount, pRaftServer->instanceCount / NODE_COUNT);
|
||||||
|
if (myLeaderCount > pRaftServer->instanceCount / NODE_COUNT) {
|
||||||
|
struct raft *r;
|
||||||
|
for (int j = 0; j < pRaftServer->instanceCount; ++j) {
|
||||||
|
if (pRaftServer->instance[j].raft.state == RAFT_LEADER) {
|
||||||
|
r = &pRaftServer->instance[j].raft;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct raft_transfer *transfer = raft_malloc(sizeof(*transfer));
|
||||||
|
transfer->data = pRaftServer;
|
||||||
|
|
||||||
|
uint64_t destRaftId;
|
||||||
|
int minIndex = -1;
|
||||||
|
int minLeaderCount = myLeaderCount;
|
||||||
|
for (int j = 0; j < NODE_COUNT; ++j) {
|
||||||
|
if (strcmp(leaderStates[j].address, pRaftServer->address) == 0) continue;
|
||||||
|
if (leaderStates[j].leaderCount <= minLeaderCount) {
|
||||||
|
minIndex = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char myHost[48];
|
||||||
|
uint16_t myPort;
|
||||||
|
uint16_t myVid;
|
||||||
|
decodeRaftId(r->id, myHost, sizeof(myHost), &myPort, &myVid);
|
||||||
|
|
||||||
|
char *destAddress = leaderStates[minIndex].address;
|
||||||
|
|
||||||
|
char tokens[MAX_PEERS][MAX_TOKEN_LEN];
|
||||||
|
splitString(destAddress, ":", tokens, 2);
|
||||||
|
char *destHost = tokens[0];
|
||||||
|
uint16_t destPort = atoi(tokens[1]);
|
||||||
|
destRaftId = encodeRaftId(destHost, destPort, myVid);
|
||||||
|
|
||||||
|
raft_transfer(r, transfer, destRaftId, raftTransferCb);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void parseAddr(const char *addr, char *host, int len, uint32_t *port) {
|
||||||
|
char* tmp = (char*)malloc(strlen(addr) + 1);
|
||||||
|
strcpy(tmp, addr);
|
||||||
|
|
||||||
|
char* context;
|
||||||
|
char* separator = ":";
|
||||||
|
char* token = strtok_r(tmp, separator, &context);
|
||||||
|
if (token) {
|
||||||
|
snprintf(host, len, "%s", token);
|
||||||
|
}
|
||||||
|
|
||||||
|
token = strtok_r(NULL, separator, &context);
|
||||||
|
if (token) {
|
||||||
|
sscanf(token, "%u", port);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// only parse 3 tokens
|
||||||
|
int parseCommand3(const char* str, char* token1, char* token2, char* token3, int len)
|
||||||
|
{
|
||||||
|
char* tmp = (char*)malloc(strlen(str) + 1);
|
||||||
|
strcpy(tmp, str);
|
||||||
|
|
||||||
|
char* context;
|
||||||
|
char* separator = " ";
|
||||||
|
int n = 0;
|
||||||
|
|
||||||
|
char* token = strtok_r(tmp, separator, &context);
|
||||||
|
if (!token) {
|
||||||
|
goto ret;
|
||||||
|
}
|
||||||
|
if (strcmp(token, "") != 0) {
|
||||||
|
strncpy(token1, token, len);
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
|
||||||
|
token = strtok_r(NULL, separator, &context);
|
||||||
|
if (!token) {
|
||||||
|
goto ret;
|
||||||
|
}
|
||||||
|
if (strcmp(token, "") != 0) {
|
||||||
|
strncpy(token2, token, len);
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
|
||||||
|
token = strtok_r(NULL, separator, &context);
|
||||||
|
if (!token) {
|
||||||
|
goto ret;
|
||||||
|
}
|
||||||
|
if (strcmp(token, "") != 0) {
|
||||||
|
strncpy(token3, token, len);
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret:
|
||||||
|
return n;
|
||||||
|
free(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// only parse 4 tokens
|
||||||
|
int parseCommand4(const char* str, char* token1, char* token2, char* token3, char *token4, int len)
|
||||||
|
{
|
||||||
|
char* tmp = (char*)malloc(strlen(str) + 1);
|
||||||
|
strcpy(tmp, str);
|
||||||
|
|
||||||
|
char* context;
|
||||||
|
char* separator = " ";
|
||||||
|
int n = 0;
|
||||||
|
|
||||||
|
char* token = strtok_r(tmp, separator, &context);
|
||||||
|
if (!token) {
|
||||||
|
goto ret;
|
||||||
|
}
|
||||||
|
if (strcmp(token, "") != 0) {
|
||||||
|
strncpy(token1, token, len);
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
|
||||||
|
token = strtok_r(NULL, separator, &context);
|
||||||
|
if (!token) {
|
||||||
|
goto ret;
|
||||||
|
}
|
||||||
|
if (strcmp(token, "") != 0) {
|
||||||
|
strncpy(token2, token, len);
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
|
||||||
|
token = strtok_r(NULL, separator, &context);
|
||||||
|
if (!token) {
|
||||||
|
goto ret;
|
||||||
|
}
|
||||||
|
if (strcmp(token, "") != 0) {
|
||||||
|
strncpy(token3, token, len);
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
|
||||||
|
token = strtok_r(NULL, separator, &context);
|
||||||
|
if (!token) {
|
||||||
|
goto ret;
|
||||||
|
}
|
||||||
|
if (strcmp(token, "") != 0) {
|
||||||
|
strncpy(token4, token, len);
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret:
|
||||||
|
return n;
|
||||||
|
free(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *startServerFunc(void *param) {
|
||||||
|
SRaftServer *pServer = (SRaftServer*)param;
|
||||||
|
int32_t r = raftServerStart(pServer);
|
||||||
|
assert(r == 0);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Console ---------------------------------
|
||||||
|
const char* state2String(unsigned short state) {
|
||||||
|
if (state == RAFT_UNAVAILABLE) {
|
||||||
|
return "RAFT_UNAVAILABLE";
|
||||||
|
|
||||||
|
} else if (state == RAFT_FOLLOWER) {
|
||||||
|
return "RAFT_FOLLOWER";
|
||||||
|
|
||||||
|
} else if (state == RAFT_CANDIDATE) {
|
||||||
|
return "RAFT_CANDIDATE";
|
||||||
|
|
||||||
|
} else if (state == RAFT_LEADER) {
|
||||||
|
return "RAFT_LEADER";
|
||||||
|
|
||||||
|
}
|
||||||
|
return "UNKNOWN_RAFT_STATE";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void printRaftState2(struct raft *r) {
|
||||||
|
|
||||||
|
char leaderAddress[128];
|
||||||
|
memset(leaderAddress, 0, sizeof(leaderAddress));
|
||||||
|
|
||||||
|
if (r->state == RAFT_LEADER) {
|
||||||
|
snprintf(leaderAddress, sizeof(leaderAddress), "%s", r->address);
|
||||||
|
} else if (r->state == RAFT_FOLLOWER) {
|
||||||
|
snprintf(leaderAddress, sizeof(leaderAddress), "%s", r->follower_state.current_leader.address);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < r->configuration.n; ++i) {
|
||||||
|
char tmpAddress[128];
|
||||||
|
snprintf(tmpAddress, sizeof(tmpAddress), "%s", r->configuration.servers[i].address);
|
||||||
|
|
||||||
|
uint64_t raftId = r->configuration.servers[i].id;
|
||||||
|
char host[128];
|
||||||
|
uint16_t port;
|
||||||
|
uint16_t vid;
|
||||||
|
decodeRaftId(raftId, host, 128, &port, &vid);
|
||||||
|
|
||||||
|
char buf[512];
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
if (strcmp(tmpAddress, leaderAddress) == 0) {
|
||||||
|
snprintf(buf, sizeof(buf), "<%s:%u-%u-LEADER>\t", host, port, vid);
|
||||||
|
} else {
|
||||||
|
snprintf(buf, sizeof(buf), "<%s:%u-%u-FOLLOWER>\t", host, port, vid);
|
||||||
|
}
|
||||||
|
printf("%s", buf);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void printRaftConfiguration(struct raft_configuration *c) {
|
||||||
|
printf("configuration: \n");
|
||||||
|
for (int i = 0; i < c->n; ++i) {
|
||||||
|
printf("%llu -- %d -- %s\n", c->servers[i].id, c->servers[i].role, c->servers[i].address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void printRaftState(struct raft *r) {
|
||||||
|
printf("----Raft State: -----------\n");
|
||||||
|
printf("mem_addr: %p \n", r);
|
||||||
|
printf("my_id: %llu \n", r->id);
|
||||||
|
printf("address: %s \n", r->address);
|
||||||
|
printf("current_term: %llu \n", r->current_term);
|
||||||
|
printf("voted_for: %llu \n", r->voted_for);
|
||||||
|
printf("role: %s \n", state2String(r->state));
|
||||||
|
printf("commit_index: %llu \n", r->commit_index);
|
||||||
|
printf("last_applied: %llu \n", r->last_applied);
|
||||||
|
printf("last_stored: %llu \n", r->last_stored);
|
||||||
|
|
||||||
|
printf("configuration_index: %llu \n", r->configuration_index);
|
||||||
|
printf("configuration_uncommitted_index: %llu \n", r->configuration_uncommitted_index);
|
||||||
|
printRaftConfiguration(&r->configuration);
|
||||||
|
|
||||||
|
printf("----------------------------\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void putValueCb(struct raft_apply *req, int status, void *result) {
|
||||||
|
raft_free(req);
|
||||||
|
struct raft *r = req->data;
|
||||||
|
if (status != 0) {
|
||||||
|
printf("putValueCb: %s \n", raft_errmsg(r));
|
||||||
|
} else {
|
||||||
|
printf("putValueCb: %s \n", "ok");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void putValue(struct raft *r, const char *value) {
|
||||||
|
struct raft_buffer buf;
|
||||||
|
|
||||||
|
buf.len = TOKEN_LEN;;
|
||||||
|
buf.base = raft_malloc(buf.len);
|
||||||
|
snprintf(buf.base, buf.len, "%s", value);
|
||||||
|
|
||||||
|
struct raft_apply *req = raft_malloc(sizeof(struct raft_apply));
|
||||||
|
req->data = r;
|
||||||
|
int ret = raft_apply(r, req, &buf, 1, putValueCb);
|
||||||
|
if (ret == 0) {
|
||||||
|
printf("put %s \n", (char*)buf.base);
|
||||||
|
} else {
|
||||||
|
printf("put error: %s \n", raft_errmsg(r));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void getValue(const char *key) {
|
||||||
|
char *ptr = getKV(key);
|
||||||
|
if (ptr) {
|
||||||
|
printf("get value: [%s] \n", ptr);
|
||||||
|
} else {
|
||||||
|
printf("value not found for key: [%s] \n", key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void console(SRaftServer *pRaftServer) {
|
||||||
|
while (1) {
|
||||||
|
char cmd_buf[COMMAND_LEN];
|
||||||
|
memset(cmd_buf, 0, sizeof(cmd_buf));
|
||||||
|
char *ret = fgets(cmd_buf, COMMAND_LEN, stdin);
|
||||||
|
if (!ret) {
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int pos = strlen(cmd_buf);
|
||||||
|
if(cmd_buf[pos - 1] == '\n') {
|
||||||
|
cmd_buf[pos - 1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strncmp(cmd_buf, "", COMMAND_LEN) == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
char cmd[TOKEN_LEN];
|
||||||
|
memset(cmd, 0, sizeof(cmd));
|
||||||
|
|
||||||
|
char param1[TOKEN_LEN];
|
||||||
|
memset(param1, 0, sizeof(param1));
|
||||||
|
|
||||||
|
char param2[TOKEN_LEN];
|
||||||
|
memset(param2, 0, sizeof(param2));
|
||||||
|
|
||||||
|
char param3[TOKEN_LEN];
|
||||||
|
memset(param2, 0, sizeof(param2));
|
||||||
|
|
||||||
|
parseCommand4(cmd_buf, cmd, param1, param2, param3, TOKEN_LEN);
|
||||||
|
if (strcmp(cmd, "addnode") == 0) {
|
||||||
|
printf("not support \n");
|
||||||
|
|
||||||
|
/*
|
||||||
|
char host[HOST_LEN];
|
||||||
|
uint32_t port;
|
||||||
|
parseAddr(param1, host, HOST_LEN, &port);
|
||||||
|
uint64_t rid = raftId(host, port);
|
||||||
|
|
||||||
|
struct raft_change *req = raft_malloc(sizeof(*req));
|
||||||
|
int r = raft_add(&pRaftServer->raft, req, rid, param1, NULL);
|
||||||
|
if (r != 0) {
|
||||||
|
printf("raft_add: %s \n", raft_errmsg(&pRaftServer->raft));
|
||||||
|
}
|
||||||
|
printf("add node: %lu %s \n", rid, param1);
|
||||||
|
|
||||||
|
struct raft_change *req2 = raft_malloc(sizeof(*req2));
|
||||||
|
r = raft_assign(&pRaftServer->raft, req2, rid, RAFT_VOTER, NULL);
|
||||||
|
if (r != 0) {
|
||||||
|
printf("raft_assign: %s \n", raft_errmsg(&pRaftServer->raft));
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
} else if (strcmp(cmd, "dropnode") == 0) {
|
||||||
|
printf("not support \n");
|
||||||
|
|
||||||
|
} else if (strcmp(cmd, "rebalance") == 0) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
updateLeaderStates(pRaftServer);
|
||||||
|
|
||||||
|
int myLeaderCount;
|
||||||
|
for (int i = 0; i < NODE_COUNT; ++i) {
|
||||||
|
if (strcmp(pRaftServer->address, leaderStates[i].address) == 0) {
|
||||||
|
myLeaderCount = leaderStates[i].leaderCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (myLeaderCount > pRaftServer->instanceCount / NODE_COUNT) {
|
||||||
|
printf("myLeaderCount:%d waterLevel:%d \n", myLeaderCount, pRaftServer->instanceCount / NODE_COUNT);
|
||||||
|
|
||||||
|
struct raft *r;
|
||||||
|
for (int j = 0; j < pRaftServer->instanceCount; ++j) {
|
||||||
|
if (pRaftServer->instance[j].raft.state == RAFT_LEADER) {
|
||||||
|
r = &pRaftServer->instance[j].raft;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct raft_transfer *transfer = raft_malloc(sizeof(*transfer));
|
||||||
|
transfer->data = pRaftServer;
|
||||||
|
|
||||||
|
uint64_t destRaftId;
|
||||||
|
int minIndex = -1;
|
||||||
|
int minLeaderCount = myLeaderCount;
|
||||||
|
for (int j = 0; j < NODE_COUNT; ++j) {
|
||||||
|
if (strcmp(leaderStates[j].address, pRaftServer->address) == 0) continue;
|
||||||
|
|
||||||
|
printf("-----leaderStates[%d].leaderCount:%d \n", j, leaderStates[j].leaderCount);
|
||||||
|
if (leaderStates[j].leaderCount <= minLeaderCount) {
|
||||||
|
minIndex = j;
|
||||||
|
printf("++++ assign minIndex : %d \n", minIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("minIndex:%d minLeaderCount:%d \n", minIndex, minLeaderCount);
|
||||||
|
|
||||||
|
char myHost[48];
|
||||||
|
uint16_t myPort;
|
||||||
|
uint16_t myVid;
|
||||||
|
decodeRaftId(r->id, myHost, sizeof(myHost), &myPort, &myVid);
|
||||||
|
|
||||||
|
char *destAddress = leaderStates[minIndex].address;
|
||||||
|
|
||||||
|
char tokens[MAX_PEERS][MAX_TOKEN_LEN];
|
||||||
|
splitString(destAddress, ":", tokens, 2);
|
||||||
|
char *destHost = tokens[0];
|
||||||
|
uint16_t destPort = atoi(tokens[1]);
|
||||||
|
destRaftId = encodeRaftId(destHost, destPort, myVid);
|
||||||
|
|
||||||
|
printf("destHost:%s destPort:%u myVid:%u", destHost, destPort, myVid);
|
||||||
|
raft_transfer(r, transfer, destRaftId, raftTransferCb);
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
|
for (int i = 0; i < NODE_COUNT; ++i) {
|
||||||
|
if (strcmp(pRaftServer->address, leaderStates[i].address) == 0) {
|
||||||
|
myLeaderCount = leaderStates[i].leaderCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
int leaderCount = 0;
|
||||||
|
|
||||||
|
struct raft *firstR;
|
||||||
|
for (int i = 0; i < pRaftServer->instanceCount; ++i) {
|
||||||
|
struct raft *r = &pRaftServer->instance[i].raft;
|
||||||
|
if (r->state == RAFT_LEADER) {
|
||||||
|
leaderCount++;
|
||||||
|
firstR = r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (leaderCount > pRaftServer->instanceCount / NODE_COUNT) {
|
||||||
|
struct raft_transfer *transfer = raft_malloc(sizeof(*transfer));
|
||||||
|
transfer->data = pRaftServer;
|
||||||
|
raft_transfer(firstR, transfer, 0, raftTransferCb);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else if (strcmp(cmd, "put") == 0) {
|
||||||
|
char buf[256];
|
||||||
|
uint16_t vid;
|
||||||
|
sscanf(param1, "%hu", &vid);
|
||||||
|
snprintf(buf, sizeof(buf), "%s--%s", param2, param3);
|
||||||
|
putValue(&pRaftServer->instance[vid].raft, buf);
|
||||||
|
|
||||||
|
} else if (strcmp(cmd, "get") == 0) {
|
||||||
|
getValue(param1);
|
||||||
|
|
||||||
|
} else if (strcmp(cmd, "transfer") == 0) {
|
||||||
|
uint16_t vid;
|
||||||
|
sscanf(param1, "%hu", &vid);
|
||||||
|
|
||||||
|
struct raft_transfer transfer;
|
||||||
|
raft_transfer(&pRaftServer->instance[vid].raft, &transfer, 0, NULL);
|
||||||
|
|
||||||
|
|
||||||
|
} else if (strcmp(cmd, "state") == 0) {
|
||||||
|
for (int i = 0; i < pRaftServer->instanceCount; ++i) {
|
||||||
|
printf("instance %d: ", i);
|
||||||
|
printRaftState(&pRaftServer->instance[i].raft);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (strcmp(cmd, "state2") == 0) {
|
||||||
|
for (int i = 0; i < pRaftServer->instanceCount; ++i) {
|
||||||
|
printRaftState2(&pRaftServer->instance[i].raft);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (strcmp(cmd, "snapshot") == 0) {
|
||||||
|
printf("not support \n");
|
||||||
|
|
||||||
|
} else if (strcmp(cmd, "help") == 0) {
|
||||||
|
printf("addnode \"127.0.0.1:8888\" \n");
|
||||||
|
printf("dropnode \"127.0.0.1:8888\" \n");
|
||||||
|
printf("put key value \n");
|
||||||
|
printf("get key \n");
|
||||||
|
printf("state \n");
|
||||||
|
|
||||||
|
} else {
|
||||||
|
printf("unknown command: [%s], type \"help\" to see help \n", cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
//printf("cmd_buf: [%s] \n", cmd_buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void *startConsoleFunc(void *param) {
|
||||||
|
SRaftServer *pServer = (SRaftServer*)param;
|
||||||
|
console(pServer);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config ---------------------------------
|
||||||
|
void usage() {
|
||||||
|
printf("\nusage: \n");
|
||||||
|
printf("%s --me=127.0.0.1:10000 --dir=./data \n", exe_name);
|
||||||
|
printf("\n");
|
||||||
|
printf("%s --me=127.0.0.1:10000 --peers=127.0.0.1:10001,127.0.0.1:10002 --dir=./data \n", exe_name);
|
||||||
|
printf("%s --me=127.0.0.1:10001 --peers=127.0.0.1:10000,127.0.0.1:10002 --dir=./data \n", exe_name);
|
||||||
|
printf("%s --me=127.0.0.1:10002 --peers=127.0.0.1:10000,127.0.0.1:10001 --dir=./data \n", exe_name);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void parseConf(int argc, char **argv, SRaftServerConfig *pConf) {
|
||||||
|
memset(pConf, 0, sizeof(*pConf));
|
||||||
|
|
||||||
|
int option_index, option_value;
|
||||||
|
option_index = 0;
|
||||||
|
static struct option long_options[] = {
|
||||||
|
{"help", no_argument, NULL, 'h'},
|
||||||
|
{"peers", required_argument, NULL, 'p'},
|
||||||
|
{"me", required_argument, NULL, 'm'},
|
||||||
|
{"dir", required_argument, NULL, 'd'},
|
||||||
|
{NULL, 0, NULL, 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
while ((option_value = getopt_long(argc, argv, "hp:m:d:", long_options, &option_index)) != -1) {
|
||||||
|
switch (option_value) {
|
||||||
|
case 'm': {
|
||||||
|
parseAddr(optarg, pConf->me.host, sizeof(pConf->me.host), &pConf->me.port);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'p': {
|
||||||
|
char tokens[MAX_PEERS][MAX_TOKEN_LEN];
|
||||||
|
int peerCount = splitString(optarg, ",", tokens, MAX_PEERS);
|
||||||
|
pConf->peersCount = peerCount;
|
||||||
|
for (int i = 0; i < peerCount; ++i) {
|
||||||
|
Addr *pAddr = &pConf->peers[i];
|
||||||
|
parseAddr(tokens[i], pAddr->host, sizeof(pAddr->host), &pAddr->port);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
case 'd': {
|
||||||
|
snprintf(pConf->dir, sizeof(pConf->dir), "%s", optarg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'h': {
|
||||||
|
usage();
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
|
usage();
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
snprintf(pConf->dataDir, sizeof(pConf->dataDir), "%s/%s_%u", pConf->dir, pConf->me.host, pConf->me.port);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printConf(SRaftServerConfig *pConf) {
|
||||||
|
printf("\nconf: \n");
|
||||||
|
printf("me: %s:%u \n", pConf->me.host, pConf->me.port);
|
||||||
|
printf("peersCount: %d \n", pConf->peersCount);
|
||||||
|
for (int i = 0; i < pConf->peersCount; ++i) {
|
||||||
|
Addr *pAddr = &pConf->peers[i];
|
||||||
|
printf("peer%d: %s:%u \n", i, pAddr->host, pAddr->port);
|
||||||
|
}
|
||||||
|
printf("dataDir: %s \n\n", pConf->dataDir);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
srand(time(NULL));
|
||||||
|
int32_t ret;
|
||||||
|
|
||||||
|
exe_name = argv[0];
|
||||||
|
if (argc < 3) {
|
||||||
|
usage();
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
SRaftServerConfig conf;
|
||||||
|
parseConf(argc, argv, &conf);
|
||||||
|
printConf(&conf);
|
||||||
|
|
||||||
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
|
||||||
|
/*
|
||||||
|
char cmd_buf[COMMAND_LEN];
|
||||||
|
snprintf(cmd_buf, sizeof(cmd_buf), "mkdir -p %s", conf.dataDir);
|
||||||
|
system(cmd_buf);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
struct raft_fsm fsm;
|
||||||
|
initFsm(&fsm);
|
||||||
|
|
||||||
|
SRaftServer raftServer;
|
||||||
|
ret = raftServerInit(&raftServer, &conf, &fsm);
|
||||||
|
assert(ret == 0);
|
||||||
|
|
||||||
|
pthread_t tidRaftServer;
|
||||||
|
pthread_create(&tidRaftServer, NULL, startServerFunc, &raftServer);
|
||||||
|
|
||||||
|
pthread_t tidConsole;
|
||||||
|
pthread_create(&tidConsole, NULL, startConsoleFunc, &raftServer);
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
sleep(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,222 @@
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "common.h"
|
||||||
|
#include "raftServer.h"
|
||||||
|
|
||||||
|
char *keys;
|
||||||
|
char *values;
|
||||||
|
|
||||||
|
void initStore() {
|
||||||
|
keys = malloc(MAX_RECORD_COUNT * MAX_KV_LEN);
|
||||||
|
values = malloc(MAX_RECORD_COUNT * MAX_KV_LEN);
|
||||||
|
writeIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void destroyStore() {
|
||||||
|
free(keys);
|
||||||
|
free(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
void putKV(const char *key, const char *value) {
|
||||||
|
if (writeIndex < MAX_RECORD_COUNT) {
|
||||||
|
strncpy(&keys[writeIndex], key, MAX_KV_LEN);
|
||||||
|
strncpy(&values[writeIndex], value, MAX_KV_LEN);
|
||||||
|
writeIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char *getKV(const char *key) {
|
||||||
|
for (int i = 0; i < MAX_RECORD_COUNT; ++i) {
|
||||||
|
if (strcmp(&keys[i], key) == 0) {
|
||||||
|
return &values[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int splitString(const char* str, char* separator, char (*arr)[MAX_TOKEN_LEN], int n_arr)
|
||||||
|
{
|
||||||
|
if (n_arr <= 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* tmp = (char*)malloc(strlen(str) + 1);
|
||||||
|
strcpy(tmp, str);
|
||||||
|
char* context;
|
||||||
|
int n = 0;
|
||||||
|
|
||||||
|
char* token = strtok_r(tmp, separator, &context);
|
||||||
|
if (!token) {
|
||||||
|
goto ret;
|
||||||
|
}
|
||||||
|
strncpy(arr[n], token, MAX_TOKEN_LEN);
|
||||||
|
n++;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
token = strtok_r(NULL, separator, &context);
|
||||||
|
if (!token || n >= n_arr) {
|
||||||
|
goto ret;
|
||||||
|
}
|
||||||
|
strncpy(arr[n], token, MAX_TOKEN_LEN);
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret:
|
||||||
|
free(tmp);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
uint64_t raftId(const char *host, uint32_t port) {
|
||||||
|
uint32_t host_uint32 = (uint32_t)inet_addr(host);
|
||||||
|
assert(host_uint32 != (uint32_t)-1);
|
||||||
|
uint64_t code = ((uint64_t)host_uint32) << 32 | port;
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
uint64_t encodeRaftId(const char *host, uint16_t port, uint16_t vid) {
|
||||||
|
uint64_t raftId;
|
||||||
|
uint32_t host_uint32 = (uint32_t)inet_addr(host);
|
||||||
|
assert(host_uint32 != (uint32_t)-1);
|
||||||
|
|
||||||
|
raftId = (((uint64_t)host_uint32) << 32) | (((uint32_t)port) << 16) | vid;
|
||||||
|
return raftId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void decodeRaftId(uint64_t raftId, char *host, int32_t len, uint16_t *port, uint16_t *vid) {
|
||||||
|
uint32_t host32 = (uint32_t)((raftId >> 32) & 0x00000000FFFFFFFF);
|
||||||
|
|
||||||
|
struct in_addr addr;
|
||||||
|
addr.s_addr = host32;
|
||||||
|
snprintf(host, len, "%s", inet_ntoa(addr));
|
||||||
|
|
||||||
|
*port = (uint16_t)((raftId & 0x00000000FFFF0000) >> 16);
|
||||||
|
*vid = (uint16_t)(raftId & 0x000000000000FFFF);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int32_t raftServerInit(SRaftServer *pRaftServer, const SRaftServerConfig *pConf, struct raft_fsm *pFsm) {
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
snprintf(pRaftServer->host, sizeof(pRaftServer->host), "%s", pConf->me.host);
|
||||||
|
pRaftServer->port = pConf->me.port;
|
||||||
|
snprintf(pRaftServer->address, sizeof(pRaftServer->address), "%s:%u", pRaftServer->host, pRaftServer->port);
|
||||||
|
//strncpy(pRaftServer->dir, pConf->dataDir, sizeof(pRaftServer->dir));
|
||||||
|
|
||||||
|
ret = uv_loop_init(&pRaftServer->loop);
|
||||||
|
if (ret != 0) {
|
||||||
|
fprintf(stderr, "uv_loop_init error: %s \n", uv_strerror(ret));
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = raft_uv_tcp_init(&pRaftServer->transport, &pRaftServer->loop);
|
||||||
|
if (ret != 0) {
|
||||||
|
fprintf(stderr, "raft_uv_tcp_init: error %d \n", ret);
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t vid;
|
||||||
|
pRaftServer->instanceCount = 20;
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < pRaftServer->instanceCount; ++i)
|
||||||
|
{
|
||||||
|
//vid = 0;
|
||||||
|
vid = i;
|
||||||
|
|
||||||
|
|
||||||
|
pRaftServer->instance[vid].raftId = encodeRaftId(pRaftServer->host, pRaftServer->port, vid);
|
||||||
|
snprintf(pRaftServer->instance[vid].dir, sizeof(pRaftServer->instance[vid].dir), "%s_%llu", pConf->dataDir, pRaftServer->instance[vid].raftId);
|
||||||
|
|
||||||
|
char cmd_buf[COMMAND_LEN];
|
||||||
|
snprintf(cmd_buf, sizeof(cmd_buf), "mkdir -p %s", pRaftServer->instance[vid].dir);
|
||||||
|
system(cmd_buf);
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
|
pRaftServer->instance[vid].fsm = pFsm;
|
||||||
|
|
||||||
|
ret = raft_uv_init(&pRaftServer->instance[vid].io, &pRaftServer->loop, pRaftServer->instance[vid].dir, &pRaftServer->transport);
|
||||||
|
if (ret != 0) {
|
||||||
|
fprintf(stderr, "%s \n", raft_errmsg(&pRaftServer->instance[vid].raft));
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = raft_init(&pRaftServer->instance[vid].raft, &pRaftServer->instance[vid].io, pRaftServer->instance[vid].fsm, pRaftServer->instance[vid].raftId, pRaftServer->address);
|
||||||
|
if (ret != 0) {
|
||||||
|
fprintf(stderr, "%s \n", raft_errmsg(&pRaftServer->instance[vid].raft));
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct raft_configuration conf;
|
||||||
|
raft_configuration_init(&conf);
|
||||||
|
raft_configuration_add(&conf, pRaftServer->instance[vid].raftId, pRaftServer->address, RAFT_VOTER);
|
||||||
|
printf("add myself: %llu - %s \n", pRaftServer->instance[vid].raftId, pRaftServer->address);
|
||||||
|
for (int i = 0; i < pConf->peersCount; ++i) {
|
||||||
|
const Addr *pAddr = &pConf->peers[i];
|
||||||
|
|
||||||
|
raft_id rid = encodeRaftId(pAddr->host, pAddr->port, vid);
|
||||||
|
|
||||||
|
char addrBuf[ADDRESS_LEN];
|
||||||
|
snprintf(addrBuf, sizeof(addrBuf), "%s:%u", pAddr->host, pAddr->port);
|
||||||
|
raft_configuration_add(&conf, rid, addrBuf, RAFT_VOTER);
|
||||||
|
printf("add peers: %llu - %s \n", rid, addrBuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
raft_bootstrap(&pRaftServer->instance[vid].raft, &conf);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t raftServerStart(SRaftServer *pRaftServer) {
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
for (int i = 0; i < pRaftServer->instanceCount; ++i) {
|
||||||
|
ret = raft_start(&pRaftServer->instance[i].raft);
|
||||||
|
if (ret != 0) {
|
||||||
|
fprintf(stderr, "%s \n", raft_errmsg(&pRaftServer->instance[i].raft));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uv_run(&pRaftServer->loop, UV_RUN_DEFAULT);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void raftServerClose(SRaftServer *pRaftServer) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int fsmApplyCb(struct raft_fsm *pFsm, const struct raft_buffer *buf, void **result) {
|
||||||
|
char *msg = (char*)buf->base;
|
||||||
|
printf("fsm apply: %s \n", msg);
|
||||||
|
|
||||||
|
char arr[2][MAX_TOKEN_LEN];
|
||||||
|
splitString(msg, "--", arr, 2);
|
||||||
|
putKV(arr[0], arr[1]);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t initFsm(struct raft_fsm *fsm) {
|
||||||
|
initStore();
|
||||||
|
fsm->apply = fsmApplyCb;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
#ifndef TDENGINE_RAFT_SERVER_H
|
||||||
|
#define TDENGINE_RAFT_SERVER_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "raft.h"
|
||||||
|
#include "raft/uv.h"
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
|
||||||
|
// simulate a db store, just for test
|
||||||
|
#define MAX_KV_LEN 100
|
||||||
|
#define MAX_RECORD_COUNT 500
|
||||||
|
char *keys;
|
||||||
|
char *values;
|
||||||
|
int writeIndex;
|
||||||
|
|
||||||
|
void initStore();
|
||||||
|
void destroyStore();
|
||||||
|
void putKV(const char *key, const char *value);
|
||||||
|
char *getKV(const char *key);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char dir[DIR_LEN + HOST_LEN * 4]; /* Data dir of UV I/O backend */
|
||||||
|
raft_id raftId; /* For vote */
|
||||||
|
struct raft_fsm *fsm; /* Sample application FSM */
|
||||||
|
struct raft raft; /* Raft instance */
|
||||||
|
struct raft_io io; /* UV I/O backend */
|
||||||
|
|
||||||
|
} SInstance;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char host[HOST_LEN];
|
||||||
|
uint32_t port;
|
||||||
|
char address[ADDRESS_LEN]; /* Raft instance address */
|
||||||
|
|
||||||
|
struct uv_loop_s loop; /* UV loop */
|
||||||
|
struct raft_uv_transport transport; /* UV I/O backend transport */
|
||||||
|
|
||||||
|
SInstance instance[MAX_INSTANCE_NUM];
|
||||||
|
int32_t instanceCount;
|
||||||
|
|
||||||
|
} SRaftServer;
|
||||||
|
|
||||||
|
#define MAX_TOKEN_LEN 32
|
||||||
|
int splitString(const char* str, char* separator, char (*arr)[MAX_TOKEN_LEN], int n_arr);
|
||||||
|
|
||||||
|
int32_t raftServerInit(SRaftServer *pRaftServer, const SRaftServerConfig *pConf, struct raft_fsm *pFsm);
|
||||||
|
int32_t raftServerStart(SRaftServer *pRaftServer);
|
||||||
|
void raftServerClose(SRaftServer *pRaftServer);
|
||||||
|
|
||||||
|
|
||||||
|
int initFsm(struct raft_fsm *fsm);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // TDENGINE_RAFT_SERVER_H
|
||||||
|
|
@ -30,6 +30,7 @@ extern char tsLocalEp[];
|
||||||
extern uint16_t tsServerPort;
|
extern uint16_t tsServerPort;
|
||||||
extern int32_t tsStatusInterval;
|
extern int32_t tsStatusInterval;
|
||||||
extern int8_t tsEnableTelemetryReporting;
|
extern int8_t tsEnableTelemetryReporting;
|
||||||
|
extern int32_t tsNumOfSupportVnodes;
|
||||||
|
|
||||||
// common
|
// common
|
||||||
extern int tsRpcTimer;
|
extern int tsRpcTimer;
|
||||||
|
|
@ -48,14 +49,18 @@ extern int32_t tsCompressMsgSize;
|
||||||
extern int32_t tsCompressColData;
|
extern int32_t tsCompressColData;
|
||||||
extern int32_t tsMaxNumOfDistinctResults;
|
extern int32_t tsMaxNumOfDistinctResults;
|
||||||
extern char tsTempDir[];
|
extern char tsTempDir[];
|
||||||
extern int64_t tsMaxVnodeQueuedBytes;
|
|
||||||
extern int tsCompatibleModel; // 2.0 compatible model
|
extern int tsCompatibleModel; // 2.0 compatible model
|
||||||
|
extern int8_t tsEnableSlaveQuery;
|
||||||
|
extern int8_t tsEnableAdjustMaster;
|
||||||
|
extern int8_t tsPrintAuth;
|
||||||
|
extern int64_t tsTickPerDay[3];
|
||||||
|
|
||||||
//query buffer management
|
// query buffer management
|
||||||
extern int32_t tsQueryBufferSize; // maximum allowed usage buffer size in MB for each data node during query processing
|
extern int32_t tsQueryBufferSize; // maximum allowed usage buffer size in MB for each data node during query processing
|
||||||
extern int64_t tsQueryBufferSizeBytes; // maximum allowed usage buffer size in byte for each data node during query processing
|
extern int64_t tsQueryBufferSizeBytes; // maximum allowed usage buffer size in byte for each data node
|
||||||
extern int32_t tsRetrieveBlockingModel;// retrieve threads will be blocked
|
extern int32_t tsRetrieveBlockingModel; // retrieve threads will be blocked
|
||||||
extern int8_t tsKeepOriginalColumnName;
|
extern int8_t tsKeepOriginalColumnName;
|
||||||
|
extern int8_t tsDeadLockKillQuery;
|
||||||
|
|
||||||
// client
|
// client
|
||||||
extern int32_t tsMaxSQLStringLen;
|
extern int32_t tsMaxSQLStringLen;
|
||||||
|
|
@ -72,16 +77,6 @@ extern float tsStreamComputDelayRatio; // the delayed computing ration of the
|
||||||
extern int32_t tsProjectExecInterval;
|
extern int32_t tsProjectExecInterval;
|
||||||
extern int64_t tsMaxRetentWindow;
|
extern int64_t tsMaxRetentWindow;
|
||||||
|
|
||||||
// balance
|
|
||||||
extern int8_t tsEnableSlaveQuery;
|
|
||||||
|
|
||||||
|
|
||||||
// interna
|
|
||||||
extern int8_t tsPrintAuth;
|
|
||||||
extern char tsVnodeDir[];
|
|
||||||
extern char tsMnodeDir[];
|
|
||||||
extern int64_t tsTickPerDay[3];
|
|
||||||
|
|
||||||
// system info
|
// system info
|
||||||
extern float tsTotalLogDirGB;
|
extern float tsTotalLogDirGB;
|
||||||
extern float tsTotalTmpDirGB;
|
extern float tsTotalTmpDirGB;
|
||||||
|
|
@ -102,17 +97,13 @@ extern char gitinfo[];
|
||||||
extern char gitinfoOfInternal[];
|
extern char gitinfoOfInternal[];
|
||||||
extern char buildinfo[];
|
extern char buildinfo[];
|
||||||
|
|
||||||
#ifdef TD_TSZ
|
|
||||||
// lossy
|
// lossy
|
||||||
extern char lossyColumns[];
|
extern char tsLossyColumns[];
|
||||||
extern double fPrecision;
|
extern double tsFPrecision;
|
||||||
extern double dPrecision;
|
extern double tsDPrecision;
|
||||||
extern uint32_t maxRange;
|
extern uint32_t tsMaxRange;
|
||||||
extern uint32_t curRange;
|
extern uint32_t tsCurRange;
|
||||||
extern char Compressor[];
|
extern char tsCompressor[];
|
||||||
#endif
|
|
||||||
// long query
|
|
||||||
extern int8_t tsDeadLockKillQuery;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char dir[TSDB_FILENAME_LEN];
|
char dir[TSDB_FILENAME_LEN];
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,12 @@ extern "C" {
|
||||||
#include "encode.h"
|
#include "encode.h"
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
#include "taoserror.h"
|
#include "taoserror.h"
|
||||||
|
#include "tarray.h"
|
||||||
#include "tcoding.h"
|
#include "tcoding.h"
|
||||||
#include "tdataformat.h"
|
#include "tdataformat.h"
|
||||||
|
#include "tlist.h"
|
||||||
|
|
||||||
|
/* ------------------------ MESSAGE DEFINITIONS ------------------------ */
|
||||||
#define TD_MSG_NUMBER_
|
#define TD_MSG_NUMBER_
|
||||||
#undef TD_MSG_DICT_
|
#undef TD_MSG_DICT_
|
||||||
#undef TD_MSG_INFO_
|
#undef TD_MSG_INFO_
|
||||||
|
|
@ -54,6 +57,7 @@ extern int tMsgDict[];
|
||||||
|
|
||||||
typedef uint16_t tmsg_t;
|
typedef uint16_t tmsg_t;
|
||||||
|
|
||||||
|
/* ------------------------ OTHER DEFINITIONS ------------------------ */
|
||||||
// IE type
|
// IE type
|
||||||
#define TSDB_IE_TYPE_SEC 1
|
#define TSDB_IE_TYPE_SEC 1
|
||||||
#define TSDB_IE_TYPE_META 2
|
#define TSDB_IE_TYPE_META 2
|
||||||
|
|
@ -71,6 +75,9 @@ typedef enum _mgmt_table {
|
||||||
TSDB_MGMT_TABLE_TABLE,
|
TSDB_MGMT_TABLE_TABLE,
|
||||||
TSDB_MGMT_TABLE_DNODE,
|
TSDB_MGMT_TABLE_DNODE,
|
||||||
TSDB_MGMT_TABLE_MNODE,
|
TSDB_MGMT_TABLE_MNODE,
|
||||||
|
TSDB_MGMT_TABLE_QNODE,
|
||||||
|
TSDB_MGMT_TABLE_SNODE,
|
||||||
|
TSDB_MGMT_TABLE_BNODE,
|
||||||
TSDB_MGMT_TABLE_VGROUP,
|
TSDB_MGMT_TABLE_VGROUP,
|
||||||
TSDB_MGMT_TABLE_STB,
|
TSDB_MGMT_TABLE_STB,
|
||||||
TSDB_MGMT_TABLE_MODULE,
|
TSDB_MGMT_TABLE_MODULE,
|
||||||
|
|
@ -127,6 +134,7 @@ typedef enum _mgmt_table {
|
||||||
|
|
||||||
typedef struct SBuildTableMetaInput {
|
typedef struct SBuildTableMetaInput {
|
||||||
int32_t vgId;
|
int32_t vgId;
|
||||||
|
char* dbName;
|
||||||
char* tableFullName;
|
char* tableFullName;
|
||||||
} SBuildTableMetaInput;
|
} SBuildTableMetaInput;
|
||||||
|
|
||||||
|
|
@ -262,19 +270,7 @@ typedef struct {
|
||||||
SMsgHead head;
|
SMsgHead head;
|
||||||
char name[TSDB_TABLE_FNAME_LEN];
|
char name[TSDB_TABLE_FNAME_LEN];
|
||||||
uint64_t suid;
|
uint64_t suid;
|
||||||
int32_t sverson;
|
} SVDropStbReq;
|
||||||
uint32_t ttl;
|
|
||||||
uint32_t keep;
|
|
||||||
int32_t numOfTags;
|
|
||||||
int32_t numOfColumns;
|
|
||||||
SSchema pSchema[];
|
|
||||||
} SCreateStbInternalMsg;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
SMsgHead head;
|
|
||||||
char name[TSDB_TABLE_FNAME_LEN];
|
|
||||||
uint64_t suid;
|
|
||||||
} SDropStbInternalMsg;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SMsgHead head;
|
SMsgHead head;
|
||||||
|
|
@ -521,7 +517,7 @@ typedef struct {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SMsgHead header;
|
SMsgHead header;
|
||||||
union {
|
union {
|
||||||
int32_t showId;
|
int64_t showId;
|
||||||
int64_t qhandle;
|
int64_t qhandle;
|
||||||
int64_t qId;
|
int64_t qId;
|
||||||
}; // query handle
|
}; // query handle
|
||||||
|
|
@ -669,8 +665,8 @@ typedef struct {
|
||||||
int64_t clusterId;
|
int64_t clusterId;
|
||||||
int64_t rebootTime;
|
int64_t rebootTime;
|
||||||
int64_t updateTime;
|
int64_t updateTime;
|
||||||
int16_t numOfCores;
|
int32_t numOfCores;
|
||||||
int16_t numOfSupportVnodes;
|
int32_t numOfSupportVnodes;
|
||||||
char dnodeEp[TSDB_EP_LEN];
|
char dnodeEp[TSDB_EP_LEN];
|
||||||
SClusterCfg clusterCfg;
|
SClusterCfg clusterCfg;
|
||||||
SVnodeLoads vnodeLoads;
|
SVnodeLoads vnodeLoads;
|
||||||
|
|
@ -749,7 +745,8 @@ typedef struct {
|
||||||
} SAuthVnodeMsg;
|
} SAuthVnodeMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t vgId;
|
SMsgHead header;
|
||||||
|
char dbFname[TSDB_DB_FNAME_LEN];
|
||||||
char tableFname[TSDB_TABLE_FNAME_LEN];
|
char tableFname[TSDB_TABLE_FNAME_LEN];
|
||||||
} STableInfoMsg;
|
} STableInfoMsg;
|
||||||
|
|
||||||
|
|
@ -784,6 +781,7 @@ typedef struct {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char tbFname[TSDB_TABLE_FNAME_LEN]; // table full name
|
char tbFname[TSDB_TABLE_FNAME_LEN]; // table full name
|
||||||
char stbFname[TSDB_TABLE_FNAME_LEN];
|
char stbFname[TSDB_TABLE_FNAME_LEN];
|
||||||
|
char dbFname[TSDB_DB_FNAME_LEN];
|
||||||
int32_t numOfTags;
|
int32_t numOfTags;
|
||||||
int32_t numOfColumns;
|
int32_t numOfColumns;
|
||||||
int8_t precision;
|
int8_t precision;
|
||||||
|
|
@ -841,7 +839,7 @@ typedef struct {
|
||||||
} SCompactMsg;
|
} SCompactMsg;
|
||||||
|
|
||||||
typedef struct SShowRsp {
|
typedef struct SShowRsp {
|
||||||
int32_t showId;
|
int64_t showId;
|
||||||
STableMetaMsg tableMeta;
|
STableMetaMsg tableMeta;
|
||||||
} SShowRsp;
|
} SShowRsp;
|
||||||
|
|
||||||
|
|
@ -861,29 +859,25 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t dnodeId;
|
int32_t dnodeId;
|
||||||
} SCreateMnodeMsg, SDropMnodeMsg;
|
} SMCreateMnodeMsg, SMDropMnodeMsg, SDDropMnodeMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t dnodeId;
|
int32_t dnodeId;
|
||||||
int8_t replica;
|
int8_t replica;
|
||||||
SReplica replicas[TSDB_MAX_REPLICA];
|
SReplica replicas[TSDB_MAX_REPLICA];
|
||||||
} SCreateMnodeInMsg, SAlterMnodeInMsg;
|
} SDCreateMnodeMsg, SDAlterMnodeMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t dnodeId;
|
int32_t dnodeId;
|
||||||
} SDropMnodeInMsg;
|
} SMCreateQnodeMsg, SMDropQnodeMsg, SDCreateQnodeMsg, SDDropQnodeMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t dnodeId;
|
int32_t dnodeId;
|
||||||
} SCreateQnodeInMsg, SDropQnodeInMsg;
|
} SMCreateSnodeMsg, SMDropSnodeMsg, SDCreateSnodeMsg, SDDropSnodeMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t dnodeId;
|
int32_t dnodeId;
|
||||||
} SCreateSnodeInMsg, SDropSnodeInMsg;
|
} SMCreateBnodeMsg, SMDropBnodeMsg, SDCreateBnodeMsg, SDDropBnodeMsg;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int32_t dnodeId;
|
|
||||||
} SCreateBnodeInMsg, SDropBnodeInMsg;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t dnodeId;
|
int32_t dnodeId;
|
||||||
|
|
@ -1038,6 +1032,7 @@ typedef struct {
|
||||||
} SUpdateTagValRsp;
|
} SUpdateTagValRsp;
|
||||||
|
|
||||||
typedef struct SSubQueryMsg {
|
typedef struct SSubQueryMsg {
|
||||||
|
SMsgHead header;
|
||||||
uint64_t sId;
|
uint64_t sId;
|
||||||
uint64_t queryId;
|
uint64_t queryId;
|
||||||
uint64_t taskId;
|
uint64_t taskId;
|
||||||
|
|
@ -1046,6 +1041,7 @@ typedef struct SSubQueryMsg {
|
||||||
} SSubQueryMsg;
|
} SSubQueryMsg;
|
||||||
|
|
||||||
typedef struct SResReadyMsg {
|
typedef struct SResReadyMsg {
|
||||||
|
SMsgHead header;
|
||||||
uint64_t sId;
|
uint64_t sId;
|
||||||
uint64_t queryId;
|
uint64_t queryId;
|
||||||
uint64_t taskId;
|
uint64_t taskId;
|
||||||
|
|
@ -1056,6 +1052,7 @@ typedef struct SResReadyRsp {
|
||||||
} SResReadyRsp;
|
} SResReadyRsp;
|
||||||
|
|
||||||
typedef struct SResFetchMsg {
|
typedef struct SResFetchMsg {
|
||||||
|
SMsgHead header;
|
||||||
uint64_t sId;
|
uint64_t sId;
|
||||||
uint64_t queryId;
|
uint64_t queryId;
|
||||||
uint64_t taskId;
|
uint64_t taskId;
|
||||||
|
|
@ -1261,22 +1258,22 @@ typedef struct {
|
||||||
char* executor;
|
char* executor;
|
||||||
int32_t sqlLen;
|
int32_t sqlLen;
|
||||||
char* sql;
|
char* sql;
|
||||||
} SCreateTopicInternalMsg;
|
} SDCreateTopicMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SMsgHead head;
|
SMsgHead head;
|
||||||
char name[TSDB_TABLE_FNAME_LEN];
|
char name[TSDB_TABLE_FNAME_LEN];
|
||||||
uint64_t tuid;
|
uint64_t tuid;
|
||||||
} SDropTopicInternalMsg;
|
} SDDropTopicMsg;
|
||||||
|
|
||||||
typedef struct SVCreateTbReq {
|
typedef struct SVCreateTbReq {
|
||||||
uint64_t ver; // use a general definition
|
uint64_t ver; // use a general definition
|
||||||
char* name;
|
char* name;
|
||||||
uint32_t ttl;
|
uint32_t ttl;
|
||||||
uint32_t keep;
|
uint32_t keep;
|
||||||
#define TD_SUPER_TABLE 0
|
#define TD_SUPER_TABLE TSDB_SUPER_TABLE
|
||||||
#define TD_CHILD_TABLE 1
|
#define TD_CHILD_TABLE TSDB_CHILD_TABLE
|
||||||
#define TD_NORMAL_TABLE 2
|
#define TD_NORMAL_TABLE TSDB_NORMAL_TABLE
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
|
|
@ -1297,100 +1294,16 @@ typedef struct SVCreateTbReq {
|
||||||
};
|
};
|
||||||
} SVCreateTbReq;
|
} SVCreateTbReq;
|
||||||
|
|
||||||
static FORCE_INLINE int tSerializeSVCreateTbReq(void** buf, const SVCreateTbReq* pReq) {
|
typedef struct {
|
||||||
int tlen = 0;
|
uint64_t ver; // use a general definition
|
||||||
|
SArray* pArray;
|
||||||
|
} SVCreateTbBatchReq;
|
||||||
|
|
||||||
tlen += taosEncodeFixedU64(buf, pReq->ver);
|
int tSerializeSVCreateTbReq(void** buf, SVCreateTbReq* pReq);
|
||||||
tlen += taosEncodeString(buf, pReq->name);
|
void* tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq);
|
||||||
tlen += taosEncodeFixedU32(buf, pReq->ttl);
|
int tSVCreateTbBatchReqSerialize(void** buf, SVCreateTbBatchReq* pReq);
|
||||||
tlen += taosEncodeFixedU32(buf, pReq->keep);
|
void* tSVCreateTbBatchReqDeserialize(void* buf, SVCreateTbBatchReq* pReq);
|
||||||
tlen += taosEncodeFixedU8(buf, pReq->type);
|
|
||||||
|
|
||||||
switch (pReq->type) {
|
|
||||||
case TD_SUPER_TABLE:
|
|
||||||
tlen += taosEncodeFixedU64(buf, pReq->stbCfg.suid);
|
|
||||||
tlen += taosEncodeFixedU32(buf, pReq->stbCfg.nCols);
|
|
||||||
for (uint32_t i = 0; i < pReq->stbCfg.nCols; i++) {
|
|
||||||
tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pSchema[i].type);
|
|
||||||
tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pSchema[i].colId);
|
|
||||||
tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pSchema[i].bytes);
|
|
||||||
tlen += taosEncodeString(buf, pReq->stbCfg.pSchema[i].name);
|
|
||||||
}
|
|
||||||
tlen += taosEncodeFixedU32(buf, pReq->stbCfg.nTagCols);
|
|
||||||
for (uint32_t i = 0; i < pReq->stbCfg.nTagCols; i++) {
|
|
||||||
tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pTagSchema[i].type);
|
|
||||||
tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pTagSchema[i].colId);
|
|
||||||
tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pTagSchema[i].bytes);
|
|
||||||
tlen += taosEncodeString(buf, pReq->stbCfg.pTagSchema[i].name);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case TD_CHILD_TABLE:
|
|
||||||
tlen += taosEncodeFixedU64(buf, pReq->ctbCfg.suid);
|
|
||||||
tlen += tdEncodeKVRow(buf, pReq->ctbCfg.pTag);
|
|
||||||
break;
|
|
||||||
case TD_NORMAL_TABLE:
|
|
||||||
tlen += taosEncodeFixedU32(buf, pReq->ntbCfg.nCols);
|
|
||||||
for (uint32_t i = 0; i < pReq->ntbCfg.nCols; i++) {
|
|
||||||
tlen += taosEncodeFixedI8(buf, pReq->ntbCfg.pSchema[i].type);
|
|
||||||
tlen += taosEncodeFixedI32(buf, pReq->ntbCfg.pSchema[i].colId);
|
|
||||||
tlen += taosEncodeFixedI32(buf, pReq->ntbCfg.pSchema[i].bytes);
|
|
||||||
tlen += taosEncodeString(buf, pReq->ntbCfg.pSchema[i].name);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ASSERT(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return tlen;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FORCE_INLINE void* tDeserializeSVCreateTbReq(void* buf, SVCreateTbReq* pReq) {
|
|
||||||
buf = taosDecodeFixedU64(buf, &(pReq->ver));
|
|
||||||
buf = taosDecodeString(buf, &(pReq->name));
|
|
||||||
buf = taosDecodeFixedU32(buf, &(pReq->ttl));
|
|
||||||
buf = taosDecodeFixedU32(buf, &(pReq->keep));
|
|
||||||
buf = taosDecodeFixedU8(buf, &(pReq->type));
|
|
||||||
|
|
||||||
switch (pReq->type) {
|
|
||||||
case TD_SUPER_TABLE:
|
|
||||||
buf = taosDecodeFixedU64(buf, &(pReq->stbCfg.suid));
|
|
||||||
buf = taosDecodeFixedU32(buf, &(pReq->stbCfg.nCols));
|
|
||||||
pReq->stbCfg.pSchema = (SSchema*)malloc(pReq->stbCfg.nCols * sizeof(SSchema));
|
|
||||||
for (uint32_t i = 0; i < pReq->stbCfg.nCols; i++) {
|
|
||||||
buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pSchema[i].type));
|
|
||||||
buf = taosDecodeFixedI32(buf, &(pReq->stbCfg.pSchema[i].colId));
|
|
||||||
buf = taosDecodeFixedI32(buf, &(pReq->stbCfg.pSchema[i].bytes));
|
|
||||||
buf = taosDecodeStringTo(buf, pReq->stbCfg.pSchema[i].name);
|
|
||||||
}
|
|
||||||
buf = taosDecodeFixedU32(buf, &pReq->stbCfg.nTagCols);
|
|
||||||
pReq->stbCfg.pTagSchema = (SSchema*)malloc(pReq->stbCfg.nTagCols * sizeof(SSchema));
|
|
||||||
for (uint32_t i = 0; i < pReq->stbCfg.nTagCols; i++) {
|
|
||||||
buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pTagSchema[i].type));
|
|
||||||
buf = taosDecodeFixedI32(buf, &pReq->stbCfg.pTagSchema[i].colId);
|
|
||||||
buf = taosDecodeFixedI32(buf, &pReq->stbCfg.pTagSchema[i].bytes);
|
|
||||||
buf = taosDecodeStringTo(buf, pReq->stbCfg.pTagSchema[i].name);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case TD_CHILD_TABLE:
|
|
||||||
buf = taosDecodeFixedU64(buf, &pReq->ctbCfg.suid);
|
|
||||||
buf = tdDecodeKVRow(buf, &pReq->ctbCfg.pTag);
|
|
||||||
break;
|
|
||||||
case TD_NORMAL_TABLE:
|
|
||||||
buf = taosDecodeFixedU32(buf, &pReq->ntbCfg.nCols);
|
|
||||||
pReq->ntbCfg.pSchema = (SSchema*)malloc(pReq->ntbCfg.nCols * sizeof(SSchema));
|
|
||||||
for (uint32_t i = 0; i < pReq->ntbCfg.nCols; i++) {
|
|
||||||
buf = taosDecodeFixedI8(buf, &pReq->ntbCfg.pSchema[i].type);
|
|
||||||
buf = taosDecodeFixedI32(buf, &pReq->ntbCfg.pSchema[i].colId);
|
|
||||||
buf = taosDecodeFixedI32(buf, &pReq->ntbCfg.pSchema[i].bytes);
|
|
||||||
buf = taosDecodeStringTo(buf, pReq->ntbCfg.pSchema[i].name);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ASSERT(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
typedef struct SVCreateTbRsp {
|
typedef struct SVCreateTbRsp {
|
||||||
} SVCreateTbRsp;
|
} SVCreateTbRsp;
|
||||||
|
|
||||||
|
|
@ -1405,7 +1318,7 @@ typedef struct SVShowTablesRsp {
|
||||||
|
|
||||||
typedef struct SVShowTablesFetchReq {
|
typedef struct SVShowTablesFetchReq {
|
||||||
SMsgHead head;
|
SMsgHead head;
|
||||||
int64_t id;
|
int32_t id;
|
||||||
} SVShowTablesFetchReq;
|
} SVShowTablesFetchReq;
|
||||||
|
|
||||||
typedef struct SVShowTablesFetchRsp {
|
typedef struct SVShowTablesFetchRsp {
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,15 @@ enum {
|
||||||
TD_DEF_MSG_TYPE(TDMT_DND_CREATE_MNODE, "dnode-create-mnode", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_DND_CREATE_MNODE, "dnode-create-mnode", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_DND_ALTER_MNODE, "dnode-alter-mnode", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_DND_ALTER_MNODE, "dnode-alter-mnode", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_DND_DROP_MNODE, "dnode-drop-mnode", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_DND_DROP_MNODE, "dnode-drop-mnode", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_DND_CREATE_QNODE, "dnode-create-qnode", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_DND_ALTER_QNODE, "dnode-alter-qnode", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_DND_DROP_QNODE, "dnode-drop-qnode", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_DND_CREATE_SNODE, "dnode-create-snode", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_DND_ALTER_SNODE, "dnode-alter-snode", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_DND_DROP_SNODE, "dnode-drop-snode", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_DND_CREATE_BNODE, "dnode-create-bnode", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_DND_ALTER_BNODE, "dnode-alter-bnode", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_DND_DROP_BNODE, "dnode-drop-bnode", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_DND_CREATE_VNODE, "dnode-create-vnode", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_DND_CREATE_VNODE, "dnode-create-vnode", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_DND_ALTER_VNODE, "dnode-alter-vnode", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_DND_ALTER_VNODE, "dnode-alter-vnode", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_DND_DROP_VNODE, "dnode-drop-vnode", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_DND_DROP_VNODE, "dnode-drop-vnode", NULL, NULL)
|
||||||
|
|
@ -90,9 +99,20 @@ enum {
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_USER, "mnode-drop-user", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_DROP_USER, "mnode-drop-user", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_DNODE, "mnode-create-dnode", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_DNODE, "mnode-create-dnode", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_CONFIG_DNODE, "mnode-config-dnode", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_CONFIG_DNODE, "mnode-config-dnode", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_DNODE, "mnode-alter-dnode", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_DNODE, "mnode-drop-dnode", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_DROP_DNODE, "mnode-drop-dnode", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_MNODE, "mnode-create-mnode", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_MNODE, "mnode-create-mnode", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_MNODE, "mnode-alter-mnode", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_MNODE, "mnode-drop-mnode", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_DROP_MNODE, "mnode-drop-mnode", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_QNODE, "mnode-create-qnode", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_QNODE, "mnode-alter-qnode", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_MND_DROP_QNODE, "mnode-drop-qnode", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_SNODE, "mnode-create-snode", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_SNODE, "mnode-alter-snode", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_MND_DROP_SNODE, "mnode-drop-snode", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_BNODE, "mnode-create-bnode", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_BNODE, "mnode-alter-bnode", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_MND_DROP_BNODE, "mnode-drop-bnode", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_DB, "mnode-create-db", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_DB, "mnode-create-db", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_DB, "mnode-drop-db", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_DROP_DB, "mnode-drop-db", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_USE_DB, "mnode-use-db", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_USE_DB, "mnode-use-db", NULL, NULL)
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ enum {
|
||||||
// the SQL below is for mgmt node
|
// the SQL below is for mgmt node
|
||||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_MGMT, "mgmt" )
|
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_MGMT, "mgmt" )
|
||||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CREATE_DB, "create-db" )
|
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CREATE_DB, "create-db" )
|
||||||
|
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CREATE_STABLE, "create-stable" )
|
||||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CREATE_TABLE, "create-table" )
|
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CREATE_TABLE, "create-table" )
|
||||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CREATE_FUNCTION, "create-function" )
|
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CREATE_FUNCTION, "create-function" )
|
||||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_DROP_DB, "drop-db" )
|
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_DROP_DB, "drop-db" )
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
#define TDENGINE_TNAME_H
|
#define TDENGINE_TNAME_H
|
||||||
|
|
||||||
#include "tdef.h"
|
#include "tdef.h"
|
||||||
|
#include "tmsg.h"
|
||||||
|
|
||||||
#define TSDB_DB_NAME_T 1
|
#define TSDB_DB_NAME_T 1
|
||||||
#define TSDB_TABLE_NAME_T 2
|
#define TSDB_TABLE_NAME_T 2
|
||||||
|
|
@ -58,4 +59,6 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type);
|
||||||
|
|
||||||
int32_t tNameSetAcctId(SName* dst, int32_t acctId);
|
int32_t tNameSetAcctId(SName* dst, int32_t acctId);
|
||||||
|
|
||||||
|
SSchema createSchema(uint8_t type, int32_t bytes, int32_t colId, const char* name);
|
||||||
|
|
||||||
#endif // TDENGINE_TNAME_H
|
#endif // TDENGINE_TNAME_H
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,8 @@ typedef struct SDnode SDnode;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t sver;
|
int32_t sver;
|
||||||
int16_t numOfCores;
|
int32_t numOfCores;
|
||||||
int16_t numOfSupportVnodes;
|
int32_t numOfSupportVnodes;
|
||||||
int16_t numOfCommitThreads;
|
int16_t numOfCommitThreads;
|
||||||
int8_t enableTelem;
|
int8_t enableTelem;
|
||||||
int32_t statusInterval;
|
int32_t statusInterval;
|
||||||
|
|
|
||||||
|
|
@ -157,18 +157,21 @@ typedef enum {
|
||||||
SDB_TRANS = 1,
|
SDB_TRANS = 1,
|
||||||
SDB_CLUSTER = 2,
|
SDB_CLUSTER = 2,
|
||||||
SDB_MNODE = 3,
|
SDB_MNODE = 3,
|
||||||
SDB_DNODE = 4,
|
SDB_QNODE = 4,
|
||||||
SDB_USER = 5,
|
SDB_SNODE = 5,
|
||||||
SDB_AUTH = 6,
|
SDB_BNODE = 6,
|
||||||
SDB_ACCT = 7,
|
SDB_DNODE = 7,
|
||||||
SDB_CONSUMER = 8,
|
SDB_USER = 8,
|
||||||
SDB_CGROUP = 9,
|
SDB_AUTH = 9,
|
||||||
SDB_TOPIC = 10,
|
SDB_ACCT = 10,
|
||||||
SDB_VGROUP = 11,
|
SDB_CONSUMER = 11,
|
||||||
SDB_STB = 12,
|
SDB_CGROUP = 12,
|
||||||
SDB_DB = 13,
|
SDB_TOPIC = 13,
|
||||||
SDB_FUNC = 14,
|
SDB_VGROUP = 14,
|
||||||
SDB_MAX = 15
|
SDB_STB = 15,
|
||||||
|
SDB_DB = 16,
|
||||||
|
SDB_FUNC = 17,
|
||||||
|
SDB_MAX = 18
|
||||||
} ESdbType;
|
} ESdbType;
|
||||||
|
|
||||||
typedef struct SSdb SSdb;
|
typedef struct SSdb SSdb;
|
||||||
|
|
@ -178,6 +181,7 @@ typedef int32_t (*SdbDeleteFp)(SSdb *pSdb, void *pObj);
|
||||||
typedef int32_t (*SdbDeployFp)(SMnode *pMnode);
|
typedef int32_t (*SdbDeployFp)(SMnode *pMnode);
|
||||||
typedef SSdbRow *(*SdbDecodeFp)(SSdbRaw *pRaw);
|
typedef SSdbRow *(*SdbDecodeFp)(SSdbRaw *pRaw);
|
||||||
typedef SSdbRaw *(*SdbEncodeFp)(void *pObj);
|
typedef SSdbRaw *(*SdbEncodeFp)(void *pObj);
|
||||||
|
typedef bool (*sdbTraverseFp)(SMnode *pMnode, void *pObj, void *p1, void *p2, void *p3);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
ESdbType sdbType;
|
ESdbType sdbType;
|
||||||
|
|
@ -276,7 +280,7 @@ void sdbRelease(SSdb *pSdb, void *pObj);
|
||||||
*
|
*
|
||||||
* @param pSdb The sdb object.
|
* @param pSdb The sdb object.
|
||||||
* @param type The type of the table.
|
* @param type The type of the table.
|
||||||
* @param type The initial iterator of the table.
|
* @param pIter The initial iterator of the table.
|
||||||
* @param pObj The object of the row just fetched.
|
* @param pObj The object of the row just fetched.
|
||||||
* @return void* The next iterator of the table.
|
* @return void* The next iterator of the table.
|
||||||
*/
|
*/
|
||||||
|
|
@ -286,11 +290,22 @@ void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj);
|
||||||
* @brief Cancel a traversal
|
* @brief Cancel a traversal
|
||||||
*
|
*
|
||||||
* @param pSdb The sdb object.
|
* @param pSdb The sdb object.
|
||||||
* @param pIter The iterator of the table.
|
|
||||||
* @param type The initial iterator of table.
|
* @param type The initial iterator of table.
|
||||||
*/
|
*/
|
||||||
void sdbCancelFetch(SSdb *pSdb, void *pIter);
|
void sdbCancelFetch(SSdb *pSdb, void *pIter);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Traverse a sdb
|
||||||
|
*
|
||||||
|
* @param pSdb The sdb object.
|
||||||
|
* @param type The initial iterator of table.
|
||||||
|
* @param fp The function pointer.
|
||||||
|
* @param p1 The callback param.
|
||||||
|
* @param p2 The callback param.
|
||||||
|
* @param p3 The callback param.
|
||||||
|
*/
|
||||||
|
void sdbTraverse(SSdb *pSdb, ESdbType type, sdbTraverseFp fp, void *p1, void *p2, void *p3);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the number of rows in the table
|
* @brief Get the number of rows in the table
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -25,18 +25,25 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define META_SUPER_TABLE TD_SUPER_TABLE
|
||||||
|
#define META_CHILD_TABLE TD_CHILD_TABLE
|
||||||
|
#define META_NORMAL_TABLE TD_NORMAL_TABLE
|
||||||
|
|
||||||
// Types exported
|
// Types exported
|
||||||
typedef struct SMeta SMeta;
|
typedef struct SMeta SMeta;
|
||||||
|
|
||||||
#define META_SUPER_TABLE 0
|
|
||||||
#define META_CHILD_TABLE 1
|
|
||||||
#define META_NORMAL_TABLE 2
|
|
||||||
|
|
||||||
typedef struct SMetaCfg {
|
typedef struct SMetaCfg {
|
||||||
/// LRU cache size
|
/// LRU cache size
|
||||||
uint64_t lruSize;
|
uint64_t lruSize;
|
||||||
} SMetaCfg;
|
} SMetaCfg;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t nCols;
|
||||||
|
SSchema *pSchema;
|
||||||
|
} SSchemaWrapper;
|
||||||
|
|
||||||
|
typedef struct SMTbCursor SMTbCursor;
|
||||||
|
|
||||||
typedef SVCreateTbReq STbCfg;
|
typedef SVCreateTbReq STbCfg;
|
||||||
|
|
||||||
// SMeta operations
|
// SMeta operations
|
||||||
|
|
@ -48,7 +55,13 @@ int metaDropTable(SMeta *pMeta, tb_uid_t uid);
|
||||||
int metaCommit(SMeta *pMeta);
|
int metaCommit(SMeta *pMeta);
|
||||||
|
|
||||||
// For Query
|
// For Query
|
||||||
int metaGetTableInfo(SMeta *pMeta, char *tbname, STableMetaMsg **ppMsg);
|
STbCfg * metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid);
|
||||||
|
STbCfg * metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid);
|
||||||
|
SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline);
|
||||||
|
|
||||||
|
SMTbCursor *metaOpenTbCursor(SMeta *pMeta);
|
||||||
|
void metaCloseTbCursor(SMTbCursor *pTbCur);
|
||||||
|
char * metaTbCursorNext(SMTbCursor *pTbCur);
|
||||||
|
|
||||||
// Options
|
// Options
|
||||||
void metaOptionsInit(SMetaCfg *pMetaCfg);
|
void metaOptionsInit(SMetaCfg *pMetaCfg);
|
||||||
|
|
|
||||||
|
|
@ -54,14 +54,26 @@ int32_t catalogInit(SCatalogCfg *cfg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a cluster's catalog handle for all later operations.
|
* Get a cluster's catalog handle for all later operations.
|
||||||
* @param clusterId (input, end with \0)
|
* @param clusterId
|
||||||
* @param catalogHandle (output, NO need to free it)
|
* @param catalogHandle (output, NO need to free it)
|
||||||
* @return error code
|
* @return error code
|
||||||
*/
|
*/
|
||||||
int32_t catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle);
|
int32_t catalogGetHandle(uint64_t clusterId, struct SCatalog** catalogHandle);
|
||||||
|
|
||||||
int32_t catalogGetDBVgroupVersion(struct SCatalog* pCatalog, const char* dbName, int32_t* version);
|
int32_t catalogGetDBVgroupVersion(struct SCatalog* pCatalog, const char* dbName, int32_t* version);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a DB's all vgroup info.
|
||||||
|
* @param pCatalog (input, got with catalogGetHandle)
|
||||||
|
* @param pRpc (input, rpc object)
|
||||||
|
* @param pMgmtEps (input, mnode EPs)
|
||||||
|
* @param pDBName (input, full db name)
|
||||||
|
* @param forceUpdate (input, force update db vgroup info from mnode)
|
||||||
|
* @param pVgroupList (output, vgroup info list, element is SVgroupInfo, NEED to simply free the array by caller)
|
||||||
|
* @return error code
|
||||||
|
*/
|
||||||
|
int32_t catalogGetDBVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, int32_t forceUpdate, SArray** pVgroupList);
|
||||||
|
|
||||||
int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDBVgroupInfo* dbInfo);
|
int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDBVgroupInfo* dbInfo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ extern "C" {
|
||||||
#include "tname.h"
|
#include "tname.h"
|
||||||
#include "tvariant.h"
|
#include "tvariant.h"
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* The first field of a node of any type is guaranteed to be the int16_t.
|
* The first field of a node of any type is guaranteed to be the int16_t.
|
||||||
* Hence the type of any node can be gotten by casting it to SQueryNode.
|
* Hence the type of any node can be gotten by casting it to SQueryNode.
|
||||||
*/
|
*/
|
||||||
|
|
@ -169,6 +169,7 @@ typedef struct SDclStmtInfo {
|
||||||
SEpSet epSet;
|
SEpSet epSet;
|
||||||
char* pMsg;
|
char* pMsg;
|
||||||
int32_t msgLen;
|
int32_t msgLen;
|
||||||
|
void* pExtension; // todo remove it soon
|
||||||
} SDclStmtInfo;
|
} SDclStmtInfo;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,6 @@ int32_t getExprFunctionLevel(const SQueryStmtInfo* pQueryInfo);
|
||||||
|
|
||||||
STableMetaInfo* getMetaInfo(const SQueryStmtInfo* pQueryInfo, int32_t tableIndex);
|
STableMetaInfo* getMetaInfo(const SQueryStmtInfo* pQueryInfo, int32_t tableIndex);
|
||||||
SSchema *getOneColumnSchema(const STableMeta* pTableMeta, int32_t colIndex);
|
SSchema *getOneColumnSchema(const STableMeta* pTableMeta, int32_t colIndex);
|
||||||
SSchema createSchema(uint8_t type, int16_t bytes, int16_t colId, const char* name);
|
|
||||||
|
|
||||||
int32_t getNewResColId();
|
int32_t getNewResColId();
|
||||||
void addIntoSourceParam(SSourceParam* pSourceParam, tExprNode* pNode, SColumn* pColumn);
|
void addIntoSourceParam(SSourceParam* pSourceParam, tExprNode* pNode, SColumn* pColumn);
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,7 @@ typedef struct STableMeta {
|
||||||
} STableMeta;
|
} STableMeta;
|
||||||
|
|
||||||
typedef struct SDBVgroupInfo {
|
typedef struct SDBVgroupInfo {
|
||||||
|
SRWLatch lock;
|
||||||
int32_t vgVersion;
|
int32_t vgVersion;
|
||||||
int8_t hashMethod;
|
int8_t hashMethod;
|
||||||
SHashObj *vgInfo; //key:vgId, value:SVgroupInfo
|
SHashObj *vgInfo; //key:vgId, value:SVgroupInfo
|
||||||
|
|
|
||||||
|
|
@ -54,8 +54,11 @@ int32_t qWorkerProcessCancelMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg);
|
||||||
|
|
||||||
int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg);
|
int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg);
|
||||||
|
|
||||||
void qWorkerDestroy(void **qWorkerMgmt);
|
int32_t qWorkerProcessShowMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg);
|
||||||
|
|
||||||
|
int32_t qWorkerProcessShowFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg);
|
||||||
|
|
||||||
|
void qWorkerDestroy(void **qWorkerMgmt);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,23 +50,37 @@ typedef struct SQueryProfileSummary {
|
||||||
uint64_t resultSize; // generated result size in Kb.
|
uint64_t resultSize; // generated result size in Kb.
|
||||||
} SQueryProfileSummary;
|
} SQueryProfileSummary;
|
||||||
|
|
||||||
|
typedef struct SQueryNodeAddr{
|
||||||
|
int32_t nodeId; //vgId or qnodeId
|
||||||
|
int8_t inUse;
|
||||||
|
int8_t numOfEps;
|
||||||
|
SEpAddrMsg epAddr[TSDB_MAX_REPLICA];
|
||||||
|
} SQueryNodeAddr;
|
||||||
|
|
||||||
|
typedef struct SQueryResult {
|
||||||
|
int32_t code;
|
||||||
|
uint64_t numOfRows;
|
||||||
|
int32_t msgSize;
|
||||||
|
char *msg;
|
||||||
|
} SQueryResult;
|
||||||
|
|
||||||
int32_t schedulerInit(SSchedulerCfg *cfg);
|
int32_t schedulerInit(SSchedulerCfg *cfg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process the query job, generated according to the query physical plan.
|
* Process the query job, generated according to the query physical plan.
|
||||||
* This is a synchronized API, and is also thread-safety.
|
* This is a synchronized API, and is also thread-safety.
|
||||||
* @param qnodeList Qnode address list, element is SEpAddr
|
* @param nodeList Qnode/Vnode address list, element is SQueryNodeAddr
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int32_t scheduleExecJob(void *transport, SArray *qnodeList, SQueryDag* pDag, void** pJob, uint64_t *numOfRows);
|
int32_t scheduleExecJob(void *transport, SArray *nodeList, SQueryDag* pDag, void** pJob, SQueryResult *pRes);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process the query job, generated according to the query physical plan.
|
* Process the query job, generated according to the query physical plan.
|
||||||
* This is a asynchronized API, and is also thread-safety.
|
* This is a asynchronized API, and is also thread-safety.
|
||||||
* @param qnodeList Qnode address list, element is SEpAddr
|
* @param nodeList Qnode/Vnode address list, element is SQueryNodeAddr
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int32_t scheduleAsyncExecJob(void *transport, SArray *qnodeList, SQueryDag* pDag, void** pJob);
|
int32_t scheduleAsyncExecJob(void *transport, SArray *nodeList, SQueryDag* pDag, void** pJob);
|
||||||
|
|
||||||
int32_t scheduleFetchRows(void *pJob, void **data);
|
int32_t scheduleFetchRows(void *pJob, void **data);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern char tsOsName[];
|
extern char tsOsName[];
|
||||||
extern char tsDnodeDir[];
|
|
||||||
extern char tsDataDir[];
|
extern char tsDataDir[];
|
||||||
extern char tsLogDir[];
|
extern char tsLogDir[];
|
||||||
extern char tsScriptDir[];
|
extern char tsScriptDir[];
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
#ifndef _TD_UTIL_ENCODE_H_
|
#ifndef _TD_UTIL_ENCODE_H_
|
||||||
#define _TD_UTIL_ENCODE_H_
|
#define _TD_UTIL_ENCODE_H_
|
||||||
|
|
||||||
|
#include "freelist.h"
|
||||||
#include "tcoding.h"
|
#include "tcoding.h"
|
||||||
#include "tmacro.h"
|
#include "tmacro.h"
|
||||||
|
|
||||||
|
|
@ -23,13 +24,6 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
td_endian_t endian;
|
|
||||||
uint8_t* data;
|
|
||||||
int64_t size;
|
|
||||||
int64_t pos;
|
|
||||||
} SEncoder, SDecoder;
|
|
||||||
|
|
||||||
#define tPut(TYPE, BUF, VAL) ((TYPE*)(BUF))[0] = (VAL)
|
#define tPut(TYPE, BUF, VAL) ((TYPE*)(BUF))[0] = (VAL)
|
||||||
#define tGet(TYPE, BUF, VAL) (VAL) = ((TYPE*)(BUF))[0]
|
#define tGet(TYPE, BUF, VAL) (VAL) = ((TYPE*)(BUF))[0]
|
||||||
|
|
||||||
|
|
@ -57,31 +51,157 @@ typedef struct {
|
||||||
#define tRGet32 tRPut32
|
#define tRGet32 tRPut32
|
||||||
#define tRGet64 tRPut64
|
#define tRGet64 tRPut64
|
||||||
|
|
||||||
|
typedef enum { TD_ENCODER, TD_DECODER } td_coder_t;
|
||||||
|
|
||||||
|
#define CODER_NODE_FIELDS \
|
||||||
|
uint8_t* data; \
|
||||||
|
int32_t size; \
|
||||||
|
int32_t pos;
|
||||||
|
|
||||||
|
struct SCoderNode {
|
||||||
|
TD_SLIST_NODE(SCoderNode);
|
||||||
|
CODER_NODE_FIELDS
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
td_coder_t type;
|
||||||
|
td_endian_t endian;
|
||||||
|
SFreeList fl;
|
||||||
|
CODER_NODE_FIELDS
|
||||||
|
TD_SLIST(SCoderNode) stack;
|
||||||
|
} SCoder;
|
||||||
|
|
||||||
|
#define TD_CODER_POS(CODER) ((CODER)->pos)
|
||||||
#define TD_CODER_CURRENT(CODER) ((CODER)->data + (CODER)->pos)
|
#define TD_CODER_CURRENT(CODER) ((CODER)->data + (CODER)->pos)
|
||||||
#define TD_CODER_MOVE_POS(CODER, MOVE) ((CODER)->pos += (MOVE))
|
#define TD_CODER_MOVE_POS(CODER, MOVE) ((CODER)->pos += (MOVE))
|
||||||
#define TD_CHECK_CODER_CAPACITY_FAILED(CODER, EXPSIZE) (((CODER)->size - (CODER)->pos) < (EXPSIZE))
|
#define TD_CODER_CHECK_CAPACITY_FAILED(CODER, EXPSIZE) (((CODER)->size - (CODER)->pos) < (EXPSIZE))
|
||||||
|
#define TCODER_MALLOC(SIZE, CODER) TFL_MALLOC(SIZE, &((CODER)->fl))
|
||||||
|
|
||||||
/* ------------------------ FOR ENCODER ------------------------ */
|
void tCoderInit(SCoder* pCoder, td_endian_t endian, uint8_t* data, int32_t size, td_coder_t type);
|
||||||
static FORCE_INLINE void tInitEncoder(SEncoder* pEncoder, td_endian_t endian, uint8_t* data, int64_t size) {
|
void tCoderClear(SCoder* pCoder);
|
||||||
pEncoder->endian = endian;
|
|
||||||
pEncoder->data = data;
|
/* ------------------------ ENCODE ------------------------ */
|
||||||
pEncoder->size = (data) ? size : 0;
|
int tStartEncode(SCoder* pEncoder);
|
||||||
pEncoder->pos = 0;
|
void tEndEncode(SCoder* pEncoder);
|
||||||
}
|
static int tEncodeU8(SCoder* pEncoder, uint8_t val);
|
||||||
|
static int tEncodeI8(SCoder* pEncoder, int8_t val);
|
||||||
|
static int tEncodeU16(SCoder* pEncoder, uint16_t val);
|
||||||
|
static int tEncodeI16(SCoder* pEncoder, int16_t val);
|
||||||
|
static int tEncodeU32(SCoder* pEncoder, uint32_t val);
|
||||||
|
static int tEncodeI32(SCoder* pEncoder, int32_t val);
|
||||||
|
static int tEncodeU64(SCoder* pEncoder, uint64_t val);
|
||||||
|
static int tEncodeI64(SCoder* pEncoder, int64_t val);
|
||||||
|
static int tEncodeU16v(SCoder* pEncoder, uint16_t val);
|
||||||
|
static int tEncodeI16v(SCoder* pEncoder, int16_t val);
|
||||||
|
static int tEncodeU32v(SCoder* pEncoder, uint32_t val);
|
||||||
|
static int tEncodeI32v(SCoder* pEncoder, int32_t val);
|
||||||
|
static int tEncodeU64v(SCoder* pEncoder, uint64_t val);
|
||||||
|
static int tEncodeI64v(SCoder* pEncoder, int64_t val);
|
||||||
|
static int tEncodeFloat(SCoder* pEncoder, float val);
|
||||||
|
static int tEncodeDouble(SCoder* pEncoder, double val);
|
||||||
|
static int tEncodeBinary(SCoder* pEncoder, const void* val, uint64_t len);
|
||||||
|
static int tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint64_t len);
|
||||||
|
static int tEncodeCStr(SCoder* pEncoder, const char* val);
|
||||||
|
|
||||||
|
/* ------------------------ DECODE ------------------------ */
|
||||||
|
int tStartDecode(SCoder* pDecoder);
|
||||||
|
void tEndDecode(SCoder* pDecoder);
|
||||||
|
static bool tDecodeIsEnd(SCoder* pCoder);
|
||||||
|
static int tDecodeU8(SCoder* pDecoder, uint8_t* val);
|
||||||
|
static int tDecodeI8(SCoder* pDecoder, int8_t* val);
|
||||||
|
static int tDecodeU16(SCoder* pDecoder, uint16_t* val);
|
||||||
|
static int tDecodeI16(SCoder* pDecoder, int16_t* val);
|
||||||
|
static int tDecodeU32(SCoder* pDecoder, uint32_t* val);
|
||||||
|
static int tDecodeI32(SCoder* pDecoder, int32_t* val);
|
||||||
|
static int tDecodeU64(SCoder* pDecoder, uint64_t* val);
|
||||||
|
static int tDecodeI64(SCoder* pDecoder, int64_t* val);
|
||||||
|
static int tDecodeU16v(SCoder* pDecoder, uint16_t* val);
|
||||||
|
static int tDecodeI16v(SCoder* pDecoder, int16_t* val);
|
||||||
|
static int tDecodeU32v(SCoder* pDecoder, uint32_t* val);
|
||||||
|
static int tDecodeI32v(SCoder* pDecoder, int32_t* val);
|
||||||
|
static int tDecodeU64v(SCoder* pDecoder, uint64_t* val);
|
||||||
|
static int tDecodeI64v(SCoder* pDecoder, int64_t* val);
|
||||||
|
static int tDecodeFloat(SCoder* pDecoder, float* val);
|
||||||
|
static int tDecodeDouble(SCoder* pDecoder, double* val);
|
||||||
|
static int tDecodeBinary(SCoder* pDecoder, const void** val, uint64_t* len);
|
||||||
|
static int tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len);
|
||||||
|
static int tDecodeCStr(SCoder* pDecoder, const char** val);
|
||||||
|
static int tDecodeCStrTo(SCoder* pDecoder, char* val);
|
||||||
|
|
||||||
|
/* ------------------------ IMPL ------------------------ */
|
||||||
|
#define TD_ENCODE_MACRO(CODER, VAL, TYPE, BITS) \
|
||||||
|
if ((CODER)->data) { \
|
||||||
|
if (TD_CODER_CHECK_CAPACITY_FAILED(CODER, sizeof(VAL))) return -1; \
|
||||||
|
if (TD_RT_ENDIAN() == (CODER)->endian) { \
|
||||||
|
tPut(TYPE, TD_CODER_CURRENT(CODER), (VAL)); \
|
||||||
|
} else { \
|
||||||
|
tRPut##BITS(TD_CODER_CURRENT(CODER), &(VAL)); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
TD_CODER_MOVE_POS(CODER, sizeof(VAL)); \
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#define TD_ENCODE_VARIANT_MACRO(CODER, VAL) \
|
||||||
|
while ((VAL) >= ENCODE_LIMIT) { \
|
||||||
|
if ((CODER)->data) { \
|
||||||
|
if (TD_CODER_CHECK_CAPACITY_FAILED(CODER, 1)) return -1; \
|
||||||
|
TD_CODER_CURRENT(CODER)[0] = ((VAL) | ENCODE_LIMIT) & 0xff; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
(VAL) >>= 7; \
|
||||||
|
TD_CODER_MOVE_POS(CODER, 1); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
if ((CODER)->data) { \
|
||||||
|
if (TD_CODER_CHECK_CAPACITY_FAILED(CODER, 1)) return -1; \
|
||||||
|
TD_CODER_CURRENT(CODER)[0] = (uint8_t)(VAL); \
|
||||||
|
} \
|
||||||
|
TD_CODER_MOVE_POS(CODER, 1); \
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#define TD_DECODE_MACRO(CODER, PVAL, TYPE, BITS) \
|
||||||
|
if (TD_CODER_CHECK_CAPACITY_FAILED(CODER, sizeof(*(PVAL)))) return -1; \
|
||||||
|
if (TD_RT_ENDIAN() == (CODER)->endian) { \
|
||||||
|
tGet(TYPE, TD_CODER_CURRENT(CODER), *(PVAL)); \
|
||||||
|
} else { \
|
||||||
|
tRGet##BITS(PVAL, TD_CODER_CURRENT(CODER)); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
TD_CODER_MOVE_POS(CODER, sizeof(*(PVAL))); \
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#define TD_DECODE_VARIANT_MACRO(CODER, PVAL, TYPE) \
|
||||||
|
int32_t i = 0; \
|
||||||
|
*(PVAL) = 0; \
|
||||||
|
for (;;) { \
|
||||||
|
if (TD_CODER_CHECK_CAPACITY_FAILED(CODER, 1)) return -1; \
|
||||||
|
TYPE tval = TD_CODER_CURRENT(CODER)[0]; \
|
||||||
|
if (tval < ENCODE_LIMIT) { \
|
||||||
|
*(PVAL) |= (tval << (7 * i)); \
|
||||||
|
TD_CODER_MOVE_POS(pDecoder, 1); \
|
||||||
|
break; \
|
||||||
|
} else { \
|
||||||
|
*(PVAL) |= (((tval) & (ENCODE_LIMIT - 1)) << (7 * i)); \
|
||||||
|
i++; \
|
||||||
|
TD_CODER_MOVE_POS(pDecoder, 1); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
return 0;
|
||||||
|
|
||||||
// 8
|
// 8
|
||||||
static FORCE_INLINE int tEncodeU8(SEncoder* pEncoder, uint8_t val) {
|
static FORCE_INLINE int tEncodeU8(SCoder* pEncoder, uint8_t val) {
|
||||||
if (pEncoder->data) {
|
if (pEncoder->data) {
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1;
|
if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1;
|
||||||
tPut(uint8_t, TD_CODER_CURRENT(pEncoder), val);
|
tPut(uint8_t, TD_CODER_CURRENT(pEncoder), val);
|
||||||
}
|
}
|
||||||
TD_CODER_MOVE_POS(pEncoder, sizeof(val));
|
TD_CODER_MOVE_POS(pEncoder, sizeof(val));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tEncodeI8(SEncoder* pEncoder, int8_t val) {
|
static FORCE_INLINE int tEncodeI8(SCoder* pEncoder, int8_t val) {
|
||||||
if (pEncoder->data) {
|
if (pEncoder->data) {
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1;
|
if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1;
|
||||||
tPut(int8_t, TD_CODER_CURRENT(pEncoder), val);
|
tPut(int8_t, TD_CODER_CURRENT(pEncoder), val);
|
||||||
}
|
}
|
||||||
TD_CODER_MOVE_POS(pEncoder, sizeof(val));
|
TD_CODER_MOVE_POS(pEncoder, sizeof(val));
|
||||||
|
|
@ -89,303 +209,99 @@ static FORCE_INLINE int tEncodeI8(SEncoder* pEncoder, int8_t val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 16
|
// 16
|
||||||
static FORCE_INLINE int tEncodeU16(SEncoder* pEncoder, uint16_t val) {
|
static FORCE_INLINE int tEncodeU16(SCoder* pEncoder, uint16_t val) { TD_ENCODE_MACRO(pEncoder, val, uint16_t, 16); }
|
||||||
if (pEncoder->data) {
|
static FORCE_INLINE int tEncodeI16(SCoder* pEncoder, int16_t val) { TD_ENCODE_MACRO(pEncoder, val, int16_t, 16); }
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1;
|
|
||||||
if (TD_RT_ENDIAN() == pEncoder->endian) {
|
|
||||||
tPut(uint16_t, TD_CODER_CURRENT(pEncoder), val);
|
|
||||||
} else {
|
|
||||||
tRPut16(TD_CODER_CURRENT(pEncoder), &val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TD_CODER_MOVE_POS(pEncoder, sizeof(val));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FORCE_INLINE int tEncodeI16(SEncoder* pEncoder, int16_t val) {
|
|
||||||
if (pEncoder->data) {
|
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1;
|
|
||||||
if (TD_RT_ENDIAN() == pEncoder->endian) {
|
|
||||||
tPut(int16_t, TD_CODER_CURRENT(pEncoder), val);
|
|
||||||
} else {
|
|
||||||
tRPut16(TD_CODER_CURRENT(pEncoder), &val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TD_CODER_MOVE_POS(pEncoder, sizeof(val));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 32
|
// 32
|
||||||
static FORCE_INLINE int tEncodeU32(SEncoder* pEncoder, uint32_t val) {
|
static FORCE_INLINE int tEncodeU32(SCoder* pEncoder, uint32_t val) { TD_ENCODE_MACRO(pEncoder, val, uint32_t, 32); }
|
||||||
if (pEncoder->data) {
|
static FORCE_INLINE int tEncodeI32(SCoder* pEncoder, int32_t val) { TD_ENCODE_MACRO(pEncoder, val, int32_t, 32); }
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1;
|
|
||||||
if (TD_RT_ENDIAN() == pEncoder->endian) {
|
|
||||||
tPut(uint32_t, TD_CODER_CURRENT(pEncoder), val);
|
|
||||||
} else {
|
|
||||||
tRPut32(TD_CODER_CURRENT(pEncoder), &val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TD_CODER_MOVE_POS(pEncoder, sizeof(val));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FORCE_INLINE int tEncodeI32(SEncoder* pEncoder, int32_t val) {
|
|
||||||
if (pEncoder->data) {
|
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1;
|
|
||||||
if (TD_RT_ENDIAN() == pEncoder->endian) {
|
|
||||||
tPut(int32_t, TD_CODER_CURRENT(pEncoder), val);
|
|
||||||
} else {
|
|
||||||
tRPut32(TD_CODER_CURRENT(pEncoder), &val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TD_CODER_MOVE_POS(pEncoder, sizeof(val));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 64
|
// 64
|
||||||
static FORCE_INLINE int tEncodeU64(SEncoder* pEncoder, uint64_t val) {
|
static FORCE_INLINE int tEncodeU64(SCoder* pEncoder, uint64_t val) { TD_ENCODE_MACRO(pEncoder, val, uint64_t, 64); }
|
||||||
if (pEncoder->data) {
|
static FORCE_INLINE int tEncodeI64(SCoder* pEncoder, int64_t val) { TD_ENCODE_MACRO(pEncoder, val, int64_t, 64); }
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1;
|
|
||||||
if (TD_RT_ENDIAN() == pEncoder->endian) {
|
|
||||||
tPut(uint64_t, TD_CODER_CURRENT(pEncoder), val);
|
|
||||||
} else {
|
|
||||||
tRPut64(TD_CODER_CURRENT(pEncoder), &val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TD_CODER_MOVE_POS(pEncoder, sizeof(val));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FORCE_INLINE int tEncodeI64(SEncoder* pEncoder, int64_t val) {
|
|
||||||
if (pEncoder->data) {
|
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, sizeof(val))) return -1;
|
|
||||||
if (TD_RT_ENDIAN() == pEncoder->endian) {
|
|
||||||
tPut(int64_t, TD_CODER_CURRENT(pEncoder), val);
|
|
||||||
} else {
|
|
||||||
tRPut64(TD_CODER_CURRENT(pEncoder), &val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TD_CODER_MOVE_POS(pEncoder, sizeof(val));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 16v
|
// 16v
|
||||||
static FORCE_INLINE int tEncodeU16v(SEncoder* pEncoder, uint16_t val) {
|
static FORCE_INLINE int tEncodeU16v(SCoder* pEncoder, uint16_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); }
|
||||||
int64_t i = 0;
|
static FORCE_INLINE int tEncodeI16v(SCoder* pEncoder, int16_t val) {
|
||||||
while (val >= ENCODE_LIMIT) {
|
|
||||||
if (pEncoder->data) {
|
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, 1)) return -1;
|
|
||||||
TD_CODER_CURRENT(pEncoder)[i] = (val | ENCODE_LIMIT) & 0xff;
|
|
||||||
}
|
|
||||||
|
|
||||||
val >>= 7;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pEncoder->data) {
|
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, 1)) return -1;
|
|
||||||
TD_CODER_CURRENT(pEncoder)[i] = (uint8_t)val;
|
|
||||||
}
|
|
||||||
|
|
||||||
TD_CODER_MOVE_POS(pEncoder, i + 1);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FORCE_INLINE int tEncodeI16v(SEncoder* pEncoder, int16_t val) {
|
|
||||||
return tEncodeU16v(pEncoder, ZIGZAGE(int16_t, val));
|
return tEncodeU16v(pEncoder, ZIGZAGE(int16_t, val));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 32v
|
// 32v
|
||||||
static FORCE_INLINE int tEncodeU32v(SEncoder* pEncoder, uint32_t val) {
|
static FORCE_INLINE int tEncodeU32v(SCoder* pEncoder, uint32_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); }
|
||||||
int64_t i = 0;
|
static FORCE_INLINE int tEncodeI32v(SCoder* pEncoder, int32_t val) {
|
||||||
while (val >= ENCODE_LIMIT) {
|
|
||||||
if (pEncoder->data) {
|
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, 1)) return -1;
|
|
||||||
TD_CODER_CURRENT(pEncoder)[i] = (val | ENCODE_LIMIT) & 0xff;
|
|
||||||
}
|
|
||||||
|
|
||||||
val >>= 7;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pEncoder->data) {
|
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, 1)) return -1;
|
|
||||||
TD_CODER_CURRENT(pEncoder)[i] = (uint8_t)val;
|
|
||||||
}
|
|
||||||
|
|
||||||
TD_CODER_MOVE_POS(pEncoder, i + 1);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FORCE_INLINE int tEncodeI32v(SEncoder* pEncoder, int32_t val) {
|
|
||||||
return tEncodeU32v(pEncoder, ZIGZAGE(int32_t, val));
|
return tEncodeU32v(pEncoder, ZIGZAGE(int32_t, val));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 64v
|
// 64v
|
||||||
static FORCE_INLINE int tEncodeU64v(SEncoder* pEncoder, uint64_t val) {
|
static FORCE_INLINE int tEncodeU64v(SCoder* pEncoder, uint64_t val) { TD_ENCODE_VARIANT_MACRO(pEncoder, val); }
|
||||||
int64_t i = 0;
|
static FORCE_INLINE int tEncodeI64v(SCoder* pEncoder, int64_t val) {
|
||||||
while (val >= ENCODE_LIMIT) {
|
|
||||||
if (pEncoder->data) {
|
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, 1)) return -1;
|
|
||||||
TD_CODER_CURRENT(pEncoder)[i] = (val | ENCODE_LIMIT) & 0xff;
|
|
||||||
}
|
|
||||||
|
|
||||||
val >>= 7;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pEncoder->data) {
|
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pEncoder, 1)) return -1;
|
|
||||||
TD_CODER_CURRENT(pEncoder)[i] = (uint8_t)val;
|
|
||||||
}
|
|
||||||
|
|
||||||
TD_CODER_MOVE_POS(pEncoder, i + 1);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FORCE_INLINE int tEncodeI64v(SEncoder* pEncoder, int64_t val) {
|
|
||||||
return tEncodeU64v(pEncoder, ZIGZAGE(int64_t, val));
|
return tEncodeU64v(pEncoder, ZIGZAGE(int64_t, val));
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tEncodeFloat(SEncoder* pEncoder, float val) {
|
static FORCE_INLINE int tEncodeFloat(SCoder* pEncoder, float val) {
|
||||||
// TODO
|
union {
|
||||||
|
uint32_t ui;
|
||||||
|
float f;
|
||||||
|
} v = {.f = val};
|
||||||
|
|
||||||
|
return tEncodeU32(pEncoder, v.ui);
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int tEncodeDouble(SCoder* pEncoder, double val) {
|
||||||
|
union {
|
||||||
|
uint64_t ui;
|
||||||
|
double d;
|
||||||
|
} v = {.d = val};
|
||||||
|
|
||||||
|
return tEncodeU64(pEncoder, v.ui);
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int tEncodeBinary(SCoder* pEncoder, const void* val, uint64_t len) {
|
||||||
|
if (tEncodeU64v(pEncoder, len) < 0) return -1;
|
||||||
|
if (pEncoder->data) {
|
||||||
|
if (TD_CODER_CHECK_CAPACITY_FAILED(pEncoder, len)) return -1;
|
||||||
|
memcpy(TD_CODER_CURRENT(pEncoder), val, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
TD_CODER_MOVE_POS(pEncoder, len);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tEncodeDouble(SEncoder* pEncoder, double val) {
|
static FORCE_INLINE int tEncodeCStrWithLen(SCoder* pEncoder, const char* val, uint64_t len) {
|
||||||
// TODO
|
return tEncodeBinary(pEncoder, (void*)val, len + 1);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tEncodeCStr(SEncoder* pEncoder, const char* val) {
|
static FORCE_INLINE int tEncodeCStr(SCoder* pEncoder, const char* val) {
|
||||||
// TODO
|
return tEncodeCStrWithLen(pEncoder, val, (uint64_t)strlen(val));
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------ FOR DECODER ------------------------ */
|
/* ------------------------ FOR DECODER ------------------------ */
|
||||||
static FORCE_INLINE void tInitDecoder(SDecoder* pDecoder, td_endian_t endian, uint8_t* data, int64_t size) {
|
|
||||||
ASSERT(!TD_IS_NULL(data));
|
|
||||||
pDecoder->endian = endian;
|
|
||||||
pDecoder->data = data;
|
|
||||||
pDecoder->size = size;
|
|
||||||
pDecoder->pos = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 8
|
// 8
|
||||||
static FORCE_INLINE int tDecodeU8(SDecoder* pDecoder, uint8_t* val) {
|
static FORCE_INLINE int tDecodeU8(SCoder* pDecoder, uint8_t* val) {
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1;
|
if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1;
|
||||||
tGet(uint8_t, TD_CODER_CURRENT(pDecoder), *val);
|
tGet(uint8_t, TD_CODER_CURRENT(pDecoder), *val);
|
||||||
TD_CODER_MOVE_POS(pDecoder, sizeof(*val));
|
TD_CODER_MOVE_POS(pDecoder, sizeof(*val));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tDecodeI8(SDecoder* pDecoder, int8_t* val) {
|
static FORCE_INLINE int tDecodeI8(SCoder* pDecoder, int8_t* val) {
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1;
|
if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1;
|
||||||
tGet(int8_t, TD_CODER_CURRENT(pDecoder), *val);
|
tGet(int8_t, TD_CODER_CURRENT(pDecoder), *val);
|
||||||
TD_CODER_MOVE_POS(pDecoder, sizeof(*val));
|
TD_CODER_MOVE_POS(pDecoder, sizeof(*val));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 16
|
// 16
|
||||||
static FORCE_INLINE int tDecodeU16(SDecoder* pDecoder, uint16_t* val) {
|
static FORCE_INLINE int tDecodeU16(SCoder* pDecoder, uint16_t* val) { TD_DECODE_MACRO(pDecoder, val, uint16_t, 16); }
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1;
|
static FORCE_INLINE int tDecodeI16(SCoder* pDecoder, int16_t* val) { TD_DECODE_MACRO(pDecoder, val, int16_t, 16); }
|
||||||
if (TD_RT_ENDIAN() == pDecoder->endian) {
|
|
||||||
tGet(uint16_t, TD_CODER_CURRENT(pDecoder), *val);
|
|
||||||
} else {
|
|
||||||
tRGet16(val, TD_CODER_CURRENT(pDecoder));
|
|
||||||
}
|
|
||||||
|
|
||||||
TD_CODER_MOVE_POS(pDecoder, sizeof(*val));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FORCE_INLINE int tDecodeI16(SDecoder* pDecoder, int16_t* val) {
|
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1;
|
|
||||||
if (TD_RT_ENDIAN() == pDecoder->endian) {
|
|
||||||
tGet(int16_t, TD_CODER_CURRENT(pDecoder), *val);
|
|
||||||
} else {
|
|
||||||
tRGet16(val, TD_CODER_CURRENT(pDecoder));
|
|
||||||
}
|
|
||||||
|
|
||||||
TD_CODER_MOVE_POS(pDecoder, sizeof(*val));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 32
|
// 32
|
||||||
static FORCE_INLINE int tDecodeU32(SDecoder* pDecoder, uint32_t* val) {
|
static FORCE_INLINE int tDecodeU32(SCoder* pDecoder, uint32_t* val) { TD_DECODE_MACRO(pDecoder, val, uint32_t, 32); }
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1;
|
static FORCE_INLINE int tDecodeI32(SCoder* pDecoder, int32_t* val) { TD_DECODE_MACRO(pDecoder, val, int32_t, 32); }
|
||||||
if (TD_RT_ENDIAN() == pDecoder->endian) {
|
|
||||||
tGet(uint32_t, TD_CODER_CURRENT(pDecoder), *val);
|
|
||||||
} else {
|
|
||||||
tRGet32(val, TD_CODER_CURRENT(pDecoder));
|
|
||||||
}
|
|
||||||
|
|
||||||
TD_CODER_MOVE_POS(pDecoder, sizeof(*val));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FORCE_INLINE int tDecodeI32(SDecoder* pDecoder, int32_t* val) {
|
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1;
|
|
||||||
if (TD_RT_ENDIAN() == pDecoder->endian) {
|
|
||||||
tGet(int32_t, TD_CODER_CURRENT(pDecoder), *val);
|
|
||||||
} else {
|
|
||||||
tRGet32(val, TD_CODER_CURRENT(pDecoder));
|
|
||||||
}
|
|
||||||
|
|
||||||
TD_CODER_MOVE_POS(pDecoder, sizeof(*val));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 64
|
// 64
|
||||||
static FORCE_INLINE int tDecodeU64(SDecoder* pDecoder, uint64_t* val) {
|
static FORCE_INLINE int tDecodeU64(SCoder* pDecoder, uint64_t* val) { TD_DECODE_MACRO(pDecoder, val, uint64_t, 64); }
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1;
|
static FORCE_INLINE int tDecodeI64(SCoder* pDecoder, int64_t* val) { TD_DECODE_MACRO(pDecoder, val, int64_t, 64); }
|
||||||
if (TD_RT_ENDIAN() == pDecoder->endian) {
|
|
||||||
tGet(uint64_t, TD_CODER_CURRENT(pDecoder), *val);
|
|
||||||
} else {
|
|
||||||
tRGet64(val, TD_CODER_CURRENT(pDecoder));
|
|
||||||
}
|
|
||||||
|
|
||||||
TD_CODER_MOVE_POS(pDecoder, sizeof(*val));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FORCE_INLINE int tDecodeI64(SDecoder* pDecoder, int64_t* val) {
|
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, sizeof(*val))) return -1;
|
|
||||||
if (TD_RT_ENDIAN() == pDecoder->endian) {
|
|
||||||
tGet(int64_t, TD_CODER_CURRENT(pDecoder), *val);
|
|
||||||
} else {
|
|
||||||
tRGet64(val, TD_CODER_CURRENT(pDecoder));
|
|
||||||
}
|
|
||||||
|
|
||||||
TD_CODER_MOVE_POS(pDecoder, sizeof(*val));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 16v
|
// 16v
|
||||||
static FORCE_INLINE int tDecodeU16v(SDecoder* pDecoder, uint16_t* val) {
|
static FORCE_INLINE int tDecodeU16v(SCoder* pDecoder, uint16_t* val) {
|
||||||
int64_t i = 0;
|
TD_DECODE_VARIANT_MACRO(pDecoder, val, uint16_t);
|
||||||
*val = 0;
|
|
||||||
for (;;) {
|
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, 1)) return -1;
|
|
||||||
uint16_t tval = TD_CODER_CURRENT(pDecoder)[i];
|
|
||||||
if (tval < ENCODE_LIMIT) {
|
|
||||||
(*val) |= (tval << (7 * i));
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
(*val) |= (((tval) & (ENCODE_LIMIT - 1)) << (7 * i));
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TD_CODER_MOVE_POS(pDecoder, i);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tDecodeI16v(SDecoder* pDecoder, int16_t* val) {
|
static FORCE_INLINE int tDecodeI16v(SCoder* pDecoder, int16_t* val) {
|
||||||
uint16_t tval;
|
uint16_t tval;
|
||||||
if (tDecodeU16v(pDecoder, &tval) < 0) {
|
if (tDecodeU16v(pDecoder, &tval) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -395,27 +311,11 @@ static FORCE_INLINE int tDecodeI16v(SDecoder* pDecoder, int16_t* val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 32v
|
// 32v
|
||||||
static FORCE_INLINE int tDecodeU32v(SDecoder* pDecoder, uint32_t* val) {
|
static FORCE_INLINE int tDecodeU32v(SCoder* pDecoder, uint32_t* val) {
|
||||||
int64_t i = 0;
|
TD_DECODE_VARIANT_MACRO(pDecoder, val, uint32_t);
|
||||||
*val = 0;
|
|
||||||
for (;;) {
|
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, 1)) return -1;
|
|
||||||
uint32_t tval = TD_CODER_CURRENT(pDecoder)[i];
|
|
||||||
if (tval < ENCODE_LIMIT) {
|
|
||||||
(*val) |= (tval << (7 * i));
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
(*val) |= (((tval) & (ENCODE_LIMIT - 1)) << (7 * i));
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TD_CODER_MOVE_POS(pDecoder, i);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tDecodeI32v(SDecoder* pDecoder, int32_t* val) {
|
static FORCE_INLINE int tDecodeI32v(SCoder* pDecoder, int32_t* val) {
|
||||||
uint32_t tval;
|
uint32_t tval;
|
||||||
if (tDecodeU32v(pDecoder, &tval) < 0) {
|
if (tDecodeU32v(pDecoder, &tval) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -425,27 +325,11 @@ static FORCE_INLINE int tDecodeI32v(SDecoder* pDecoder, int32_t* val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 64v
|
// 64v
|
||||||
static FORCE_INLINE int tDecodeU64v(SDecoder* pDecoder, uint64_t* val) {
|
static FORCE_INLINE int tDecodeU64v(SCoder* pDecoder, uint64_t* val) {
|
||||||
int64_t i = 0;
|
TD_DECODE_VARIANT_MACRO(pDecoder, val, uint64_t);
|
||||||
*val = 0;
|
|
||||||
for (;;) {
|
|
||||||
if (TD_CHECK_CODER_CAPACITY_FAILED(pDecoder, 1)) return -1;
|
|
||||||
uint64_t tval = TD_CODER_CURRENT(pDecoder)[i];
|
|
||||||
if (tval < ENCODE_LIMIT) {
|
|
||||||
(*val) |= (tval << (7 * i));
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
(*val) |= (((tval) & (ENCODE_LIMIT - 1)) << (7 * i));
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TD_CODER_MOVE_POS(pDecoder, i);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tDecodeI64v(SDecoder* pDecoder, int64_t* val) {
|
static FORCE_INLINE int tDecodeI64v(SCoder* pDecoder, int64_t* val) {
|
||||||
uint64_t tval;
|
uint64_t tval;
|
||||||
if (tDecodeU64v(pDecoder, &tval) < 0) {
|
if (tDecodeU64v(pDecoder, &tval) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -454,21 +338,66 @@ static FORCE_INLINE int tDecodeI64v(SDecoder* pDecoder, int64_t* val) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tDecodeFloat(SDecoder* pDecoder, float* val) {
|
static FORCE_INLINE int tDecodeFloat(SCoder* pDecoder, float* val) {
|
||||||
// TODO
|
union {
|
||||||
|
uint32_t ui;
|
||||||
|
float f;
|
||||||
|
} v;
|
||||||
|
|
||||||
|
if (tDecodeU32(pDecoder, &(v.ui)) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*val = v.f;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tDecodeDouble(SDecoder* pDecoder, double* val) {
|
static FORCE_INLINE int tDecodeDouble(SCoder* pDecoder, double* val) {
|
||||||
// TODO
|
union {
|
||||||
|
uint64_t ui;
|
||||||
|
double d;
|
||||||
|
} v;
|
||||||
|
|
||||||
|
if (tDecodeU64(pDecoder, &(v.ui)) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*val = v.d;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int tDecodeCStr(SDecoder* pEncoder, const char** val) {
|
static FORCE_INLINE int tDecodeBinary(SCoder* pDecoder, const void** val, uint64_t* len) {
|
||||||
// TODO
|
if (tDecodeU64v(pDecoder, len) < 0) return -1;
|
||||||
|
|
||||||
|
if (TD_CODER_CHECK_CAPACITY_FAILED(pDecoder, *len)) return -1;
|
||||||
|
*val = (void*)TD_CODER_CURRENT(pDecoder);
|
||||||
|
|
||||||
|
TD_CODER_MOVE_POS(pDecoder, *len);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int tDecodeCStrAndLen(SCoder* pDecoder, const char** val, uint64_t* len) {
|
||||||
|
if (tDecodeBinary(pDecoder, (const void**)val, len) < 0) return -1;
|
||||||
|
(*len) -= 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int tDecodeCStr(SCoder* pDecoder, const char** val) {
|
||||||
|
uint64_t len;
|
||||||
|
return tDecodeCStrAndLen(pDecoder, val, &len);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int tDecodeCStrTo(SCoder* pDecoder, char* val) {
|
||||||
|
const char* pStr;
|
||||||
|
uint64_t len;
|
||||||
|
if (tDecodeCStrAndLen(pDecoder, &pStr, &len) < 0) return -1;
|
||||||
|
|
||||||
|
memcpy(val, pStr, len + 1);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE bool tDecodeIsEnd(SCoder* pCoder) { return (pCoder->size == pCoder->pos); }
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* 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_FREELIST_H_
|
||||||
|
#define _TD_UTIL_FREELIST_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
#include "tlist.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct SFreeListNode {
|
||||||
|
TD_SLIST_NODE(SFreeListNode);
|
||||||
|
char payload[];
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef TD_SLIST(SFreeListNode) SFreeList;
|
||||||
|
|
||||||
|
#define TFL_MALLOC(SIZE, LIST) \
|
||||||
|
({ \
|
||||||
|
void *ptr = malloc((SIZE) + sizeof(struct SFreeListNode)); \
|
||||||
|
if (ptr) { \
|
||||||
|
TD_SLIST_PUSH((LIST), (struct SFreeListNode *)ptr); \
|
||||||
|
ptr = ((struct SFreeListNode *)ptr)->payload; \
|
||||||
|
} \
|
||||||
|
ptr; \
|
||||||
|
})
|
||||||
|
|
||||||
|
#define tFreeListInit(pFL) TD_SLIST_INIT(pFL)
|
||||||
|
|
||||||
|
static FORCE_INLINE void tFreeListClear(SFreeList *pFL) {
|
||||||
|
struct SFreeListNode *pNode;
|
||||||
|
for (;;) {
|
||||||
|
pNode = TD_SLIST_HEAD(pFL);
|
||||||
|
if (pNode == NULL) break;
|
||||||
|
TD_SLIST_POP(pFL);
|
||||||
|
free(pNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*_TD_UTIL_FREELIST_H_*/
|
||||||
|
|
@ -172,10 +172,15 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_MND_INVALID_DNODE_EP TAOS_DEF_ERROR_CODE(0, 0x0347)
|
#define TSDB_CODE_MND_INVALID_DNODE_EP TAOS_DEF_ERROR_CODE(0, 0x0347)
|
||||||
#define TSDB_CODE_MND_INVALID_DNODE_ID TAOS_DEF_ERROR_CODE(0, 0x0348)
|
#define TSDB_CODE_MND_INVALID_DNODE_ID TAOS_DEF_ERROR_CODE(0, 0x0348)
|
||||||
|
|
||||||
// mnode-mnode
|
// mnode-node
|
||||||
#define TSDB_CODE_MND_MNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0350)
|
#define TSDB_CODE_MND_MNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0350)
|
||||||
#define TSDB_CODE_MND_MNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0351)
|
#define TSDB_CODE_MND_MNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0351)
|
||||||
#define TSDB_CODE_MND_TOO_MANY_MNODES TAOS_DEF_ERROR_CODE(0, 0x0352)
|
#define TSDB_CODE_MND_QNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0352)
|
||||||
|
#define TSDB_CODE_MND_QNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0353)
|
||||||
|
#define TSDB_CODE_MND_SNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0354)
|
||||||
|
#define TSDB_CODE_MND_SNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0355)
|
||||||
|
#define TSDB_CODE_MND_BNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0356)
|
||||||
|
#define TSDB_CODE_MND_BNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0357)
|
||||||
|
|
||||||
// mnode-acct
|
// mnode-acct
|
||||||
#define TSDB_CODE_MND_ACCT_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0360)
|
#define TSDB_CODE_MND_ACCT_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0360)
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ int64_t tfOpenCreateWriteAppend(const char *pathname);
|
||||||
int64_t tfClose(int64_t tfd);
|
int64_t tfClose(int64_t tfd);
|
||||||
int64_t tfWrite(int64_t tfd, void *buf, int64_t count);
|
int64_t tfWrite(int64_t tfd, void *buf, int64_t count);
|
||||||
int64_t tfRead(int64_t tfd, void *buf, int64_t count);
|
int64_t tfRead(int64_t tfd, void *buf, int64_t count);
|
||||||
|
int64_t tfPread(int64_t tfd, void *buf, int64_t count, int64_t offset);
|
||||||
int32_t tfFsync(int64_t tfd);
|
int32_t tfFsync(int64_t tfd);
|
||||||
bool tfValid(int64_t tfd);
|
bool tfValid(int64_t tfd);
|
||||||
int64_t tfLseek(int64_t tfd, int64_t offset, int32_t whence);
|
int64_t tfLseek(int64_t tfd, int64_t offset, int32_t whence);
|
||||||
|
|
|
||||||
|
|
@ -144,6 +144,16 @@ void *taosHashGet(SHashObj *pHashObj, const void *key, size_t keyLen);
|
||||||
*/
|
*/
|
||||||
void *taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void* destBuf);
|
void *taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void* destBuf);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clone the result to interval allocated buffer
|
||||||
|
* @param pHashObj
|
||||||
|
* @param key
|
||||||
|
* @param keyLen
|
||||||
|
* @param destBuf
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void* taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, void (*fp)(void *), void** d, size_t *sz);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* remove item with the specified key
|
* remove item with the specified key
|
||||||
* @param pHashObj
|
* @param pHashObj
|
||||||
|
|
@ -200,6 +210,26 @@ void taosHashCancelIterate(SHashObj *pHashObj, void *p);
|
||||||
*/
|
*/
|
||||||
int32_t taosHashGetKey(void *data, void** key, size_t* keyLen);
|
int32_t taosHashGetKey(void *data, void** key, size_t* keyLen);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return the payload data with the specified key(reference number added)
|
||||||
|
*
|
||||||
|
* @param pHashObj
|
||||||
|
* @param key
|
||||||
|
* @param keyLen
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void* taosHashAcquire(SHashObj *pHashObj, const void *key, size_t keyLen);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* release the prevous acquired obj
|
||||||
|
*
|
||||||
|
* @param pHashObj
|
||||||
|
* @param data
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void taosHashRelease(SHashObj *pHashObj, void *p);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@ extern int32_t mqttDebugFlag;
|
||||||
extern int32_t monDebugFlag;
|
extern int32_t monDebugFlag;
|
||||||
extern int32_t uDebugFlag;
|
extern int32_t uDebugFlag;
|
||||||
extern int32_t rpcDebugFlag;
|
extern int32_t rpcDebugFlag;
|
||||||
extern int32_t odbcDebugFlag;
|
|
||||||
extern int32_t qDebugFlag;
|
extern int32_t qDebugFlag;
|
||||||
extern int32_t wDebugFlag;
|
extern int32_t wDebugFlag;
|
||||||
extern int32_t sDebugFlag;
|
extern int32_t sDebugFlag;
|
||||||
|
|
|
||||||
|
|
@ -37,44 +37,42 @@ shall be used to set up the protection.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef void *taos_queue;
|
typedef struct STaosQueue STaosQueue;
|
||||||
typedef void *taos_qset;
|
typedef struct STaosQset STaosQset;
|
||||||
typedef void *taos_qall;
|
typedef struct STaosQall STaosQall;
|
||||||
typedef void (*FProcessItem)(void *ahandle, void *pItem);
|
typedef void (*FProcessItem)(void *ahandle, void *pItem);
|
||||||
typedef void (*FProcessItems)(void *ahandle, taos_qall qall, int numOfItems);
|
typedef void (*FProcessItems)(void *ahandle, STaosQall *qall, int32_t numOfItems);
|
||||||
|
|
||||||
taos_queue taosOpenQueue();
|
STaosQueue *taosOpenQueue();
|
||||||
void taosCloseQueue(taos_queue);
|
void taosCloseQueue(STaosQueue *queue);
|
||||||
void taosSetQueueFp(taos_queue, FProcessItem, FProcessItems);
|
void taosSetQueueFp(STaosQueue *queue, FProcessItem itemFp, FProcessItems itemsFp);
|
||||||
void *taosAllocateQitem(int size);
|
void *taosAllocateQitem(int32_t size);
|
||||||
void taosFreeQitem(void *pItem);
|
void taosFreeQitem(void *pItem);
|
||||||
int taosWriteQitem(taos_queue, void *pItem);
|
int32_t taosWriteQitem(STaosQueue *queue, void *pItem);
|
||||||
int taosReadQitem(taos_queue, void **pItem);
|
int32_t taosReadQitem(STaosQueue *queue, void **ppItem);
|
||||||
bool taosQueueEmpty(taos_queue);
|
bool taosQueueEmpty(STaosQueue *queue);
|
||||||
|
|
||||||
taos_qall taosAllocateQall();
|
STaosQall *taosAllocateQall();
|
||||||
void taosFreeQall(taos_qall);
|
void taosFreeQall(STaosQall *qall);
|
||||||
int taosReadAllQitems(taos_queue, taos_qall);
|
int32_t taosReadAllQitems(STaosQueue *queue, STaosQall *qall);
|
||||||
int taosGetQitem(taos_qall, void **pItem);
|
int32_t taosGetQitem(STaosQall *qall, void **ppItem);
|
||||||
void taosResetQitems(taos_qall);
|
void taosResetQitems(STaosQall *qall);
|
||||||
|
|
||||||
taos_qset taosOpenQset();
|
STaosQset *taosOpenQset();
|
||||||
void taosCloseQset();
|
void taosCloseQset(STaosQset *qset);
|
||||||
void taosQsetThreadResume(taos_qset param);
|
void taosQsetThreadResume(STaosQset *qset);
|
||||||
int taosAddIntoQset(taos_qset, taos_queue, void *ahandle);
|
int32_t taosAddIntoQset(STaosQset *qset, STaosQueue *queue, void *ahandle);
|
||||||
void taosRemoveFromQset(taos_qset, taos_queue);
|
void taosRemoveFromQset(STaosQset *qset, STaosQueue *queue);
|
||||||
int taosGetQueueNumber(taos_qset);
|
int32_t taosGetQueueNumber(STaosQset *qset);
|
||||||
|
|
||||||
int taosReadQitemFromQset(taos_qset, void **pItem, void **ahandle, FProcessItem *);
|
int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, void **ahandle, FProcessItem *itemFp);
|
||||||
int taosReadAllQitemsFromQset(taos_qset, taos_qall, void **ahandle, FProcessItems *);
|
int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, void **ahandle, FProcessItems *itemsFp);
|
||||||
|
|
||||||
int taosGetQueueItemsNumber(taos_queue param);
|
int32_t taosGetQueueItemsNumber(STaosQueue *queue);
|
||||||
int taosGetQsetItemsNumber(taos_qset param);
|
int32_t taosGetQsetItemsNumber(STaosQset *qset);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_UTIL_QUEUE_H*/
|
#endif /*_TD_UTIL_QUEUE_H*/
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ typedef struct SWorkerPool {
|
||||||
int32_t max; // max number of workers
|
int32_t max; // max number of workers
|
||||||
int32_t min; // min number of workers
|
int32_t min; // min number of workers
|
||||||
int32_t num; // current number of workers
|
int32_t num; // current number of workers
|
||||||
taos_qset qset;
|
STaosQset *qset;
|
||||||
const char *name;
|
const char *name;
|
||||||
SWorker *workers;
|
SWorker *workers;
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
|
|
@ -44,8 +44,8 @@ typedef struct SWorkerPool {
|
||||||
typedef struct SMWorker {
|
typedef struct SMWorker {
|
||||||
int32_t id; // worker id
|
int32_t id; // worker id
|
||||||
pthread_t thread; // thread
|
pthread_t thread; // thread
|
||||||
taos_qall qall;
|
STaosQall *qall;
|
||||||
taos_qset qset; // queue set
|
STaosQset *qset; // queue set
|
||||||
SMWorkerPool *pool;
|
SMWorkerPool *pool;
|
||||||
} SMWorker;
|
} SMWorker;
|
||||||
|
|
||||||
|
|
@ -59,13 +59,13 @@ typedef struct SMWorkerPool {
|
||||||
|
|
||||||
int32_t tWorkerInit(SWorkerPool *pool);
|
int32_t tWorkerInit(SWorkerPool *pool);
|
||||||
void tWorkerCleanup(SWorkerPool *pool);
|
void tWorkerCleanup(SWorkerPool *pool);
|
||||||
taos_queue tWorkerAllocQueue(SWorkerPool *pool, void *ahandle, FProcessItem fp);
|
STaosQueue *tWorkerAllocQueue(SWorkerPool *pool, void *ahandle, FProcessItem fp);
|
||||||
void tWorkerFreeQueue(SWorkerPool *pool, taos_queue queue);
|
void tWorkerFreeQueue(SWorkerPool *pool, STaosQueue *queue);
|
||||||
|
|
||||||
int32_t tMWorkerInit(SMWorkerPool *pool);
|
int32_t tMWorkerInit(SMWorkerPool *pool);
|
||||||
void tMWorkerCleanup(SMWorkerPool *pool);
|
void tMWorkerCleanup(SMWorkerPool *pool);
|
||||||
taos_queue tMWorkerAllocQueue(SMWorkerPool *pool, void *ahandle, FProcessItems fp);
|
STaosQueue *tMWorkerAllocQueue(SMWorkerPool *pool, void *ahandle, FProcessItems fp);
|
||||||
void tMWorkerFreeQueue(SMWorkerPool *pool, taos_queue queue);
|
void tMWorkerFreeQueue(SMWorkerPool *pool, STaosQueue *queue);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,4 +11,6 @@ target_link_libraries(
|
||||||
PRIVATE os util common transport parser planner catalog scheduler function qcom
|
PRIVATE os util common transport parser planner catalog scheduler function qcom
|
||||||
)
|
)
|
||||||
|
|
||||||
ADD_SUBDIRECTORY(test)
|
if(${BUILD_TEST})
|
||||||
|
ADD_SUBDIRECTORY(test)
|
||||||
|
endif(${BUILD_TEST})
|
||||||
|
|
@ -101,10 +101,17 @@ typedef struct SReqResultInfo {
|
||||||
uint32_t current;
|
uint32_t current;
|
||||||
} SReqResultInfo;
|
} 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 {
|
typedef struct SRequestSendRecvBody {
|
||||||
tsem_t rspSem; // not used now
|
tsem_t rspSem; // not used now
|
||||||
void* fp;
|
void* fp;
|
||||||
int64_t execId; // showId/queryId
|
SShowReqInfo showInfo; // todo this attribute will be removed after the query framework being completed.
|
||||||
SDataBuf requestMsg;
|
SDataBuf requestMsg;
|
||||||
SReqResultInfo resInfo;
|
SReqResultInfo resInfo;
|
||||||
} SRequestSendRecvBody;
|
} SRequestSendRecvBody;
|
||||||
|
|
@ -121,6 +128,7 @@ typedef struct SRequestObj {
|
||||||
char *msgBuf;
|
char *msgBuf;
|
||||||
void *pInfo; // sql parse info, generated by parser module
|
void *pInfo; // sql parse info, generated by parser module
|
||||||
int32_t code;
|
int32_t code;
|
||||||
|
uint64_t affectedRows;
|
||||||
SQueryExecMetric metric;
|
SQueryExecMetric metric;
|
||||||
SRequestSendRecvBody body;
|
SRequestSendRecvBody body;
|
||||||
} SRequestObj;
|
} SRequestObj;
|
||||||
|
|
@ -131,7 +139,7 @@ extern int32_t clientConnRefPool;
|
||||||
|
|
||||||
extern int (*handleRequestRspFp[TDMT_MAX])(void*, const SDataBuf* pMsg, int32_t code);
|
extern int (*handleRequestRspFp[TDMT_MAX])(void*, const SDataBuf* pMsg, int32_t code);
|
||||||
int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code);
|
int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code);
|
||||||
SMsgSendInfo* buildSendMsgInfoImpl(SRequestObj*);
|
SMsgSendInfo* buildMsgInfoImpl(SRequestObj*);
|
||||||
|
|
||||||
int taos_init();
|
int taos_init();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
#include "clientInt.h"
|
#include "clientInt.h"
|
||||||
#include "clientLog.h"
|
#include "clientLog.h"
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
|
#include "scheduler.h"
|
||||||
#include "tmsg.h"
|
#include "tmsg.h"
|
||||||
#include "tcache.h"
|
#include "tcache.h"
|
||||||
#include "tconfig.h"
|
#include "tconfig.h"
|
||||||
|
|
@ -230,6 +231,8 @@ void taos_init_imp(void) {
|
||||||
SCatalogCfg cfg = {.maxDBCacheNum = 100, .maxTblCacheNum = 100};
|
SCatalogCfg cfg = {.maxDBCacheNum = 100, .maxTblCacheNum = 100};
|
||||||
catalogInit(&cfg);
|
catalogInit(&cfg);
|
||||||
|
|
||||||
|
SSchedulerCfg scfg = {.maxJobNum = 100};
|
||||||
|
schedulerInit(&scfg);
|
||||||
tscDebug("starting to initialize TAOS driver, local ep: %s", tsLocalEp);
|
tscDebug("starting to initialize TAOS driver, local ep: %s", tsLocalEp);
|
||||||
|
|
||||||
taosSetCoreDump(true);
|
taosSetCoreDump(true);
|
||||||
|
|
|
||||||
|
|
@ -156,19 +156,12 @@ int32_t parseSql(SRequestObj* pRequest, SQueryNode** pQuery) {
|
||||||
};
|
};
|
||||||
|
|
||||||
cxt.ctx.mgmtEpSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp);
|
cxt.ctx.mgmtEpSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp);
|
||||||
|
int32_t code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &cxt.ctx.pCatalog);
|
||||||
// todo OPT performance
|
|
||||||
char buf[12] = {0};
|
|
||||||
sprintf(buf, "%"PRId64, pTscObj->pAppInfo->clusterId);
|
|
||||||
|
|
||||||
struct SCatalog* pCatalog = NULL;
|
|
||||||
int32_t code = catalogGetHandle(buf, &pCatalog);
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
tfree(cxt.ctx.db);
|
tfree(cxt.ctx.db);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
cxt.ctx.pCatalog = pCatalog;
|
|
||||||
code = qParseQuerySql(&cxt, pQuery);
|
code = qParseQuerySql(&cxt, pQuery);
|
||||||
|
|
||||||
tfree(cxt.ctx.db);
|
tfree(cxt.ctx.db);
|
||||||
|
|
@ -181,10 +174,17 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQueryNode* pQuery) {
|
||||||
pRequest->body.requestMsg = (SDataBuf){.pData = pDcl->pMsg, .len = pDcl->msgLen};
|
pRequest->body.requestMsg = (SDataBuf){.pData = pDcl->pMsg, .len = pDcl->msgLen};
|
||||||
|
|
||||||
STscObj* pTscObj = pRequest->pTscObj;
|
STscObj* pTscObj = pRequest->pTscObj;
|
||||||
SMsgSendInfo* pSendMsg = buildSendMsgInfoImpl(pRequest);
|
SMsgSendInfo* pSendMsg = buildMsgInfoImpl(pRequest);
|
||||||
|
|
||||||
int64_t transporterId = 0;
|
int64_t transporterId = 0;
|
||||||
if (pDcl->msgType == TDMT_VND_CREATE_TABLE) {
|
if (pDcl->msgType == TDMT_VND_CREATE_TABLE || pDcl->msgType == TDMT_VND_SHOW_TABLES) {
|
||||||
|
if (pDcl->msgType == TDMT_VND_SHOW_TABLES) {
|
||||||
|
SShowReqInfo* pShowReqInfo = &pRequest->body.showInfo;
|
||||||
|
if (pShowReqInfo->pArray == NULL) {
|
||||||
|
pShowReqInfo->currentIndex = 0;
|
||||||
|
pShowReqInfo->pArray = pDcl->pExtension;
|
||||||
|
}
|
||||||
|
}
|
||||||
asyncSendMsgToServer(pTscObj->pTransporter, &pDcl->epSet, &transporterId, pSendMsg);
|
asyncSendMsgToServer(pTscObj->pTransporter, &pDcl->epSet, &transporterId, pSendMsg);
|
||||||
} else {
|
} else {
|
||||||
SEpSet* pEpSet = &pTscObj->pAppInfo->mgmtEp.epSet;
|
SEpSet* pEpSet = &pTscObj->pAppInfo->mgmtEp.epSet;
|
||||||
|
|
@ -196,7 +196,15 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQueryNode* pQuery) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t getPlan(SRequestObj* pRequest, SQueryNode* pQuery, SQueryDag** pDag) {
|
||||||
|
pRequest->type = pQuery->type;
|
||||||
|
return qCreateQueryDag(pQuery, pDag);
|
||||||
|
}
|
||||||
|
|
||||||
int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, void** pJob) {
|
int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, void** pJob) {
|
||||||
|
if (TSDB_SQL_INSERT == pRequest->type || TSDB_SQL_CREATE_TABLE == pRequest->type) {
|
||||||
|
return scheduleExecJob(pRequest->pTscObj->pTransporter, NULL/*todo appInfo.xxx*/, pDag, pJob, &pRequest->affectedRows);
|
||||||
|
}
|
||||||
return scheduleAsyncExecJob(pRequest->pTscObj->pTransporter, NULL/*todo appInfo.xxx*/, pDag, pJob);
|
return scheduleAsyncExecJob(pRequest->pTscObj->pTransporter, NULL/*todo appInfo.xxx*/, pDag, pJob);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -243,7 +251,7 @@ TAOS_RES *tmq_create_topic(TAOS* taos, const char* name, const char* sql, int sq
|
||||||
|
|
||||||
pRequest->body.requestMsg = (SDataBuf){ .pData = buf, .len = tlen };
|
pRequest->body.requestMsg = (SDataBuf){ .pData = buf, .len = tlen };
|
||||||
|
|
||||||
SMsgSendInfo* body = buildSendMsgInfoImpl(pRequest);
|
SMsgSendInfo* body = buildMsgInfoImpl(pRequest);
|
||||||
SEpSet* pEpSet = &pTscObj->pAppInfo->mgmtEp.epSet;
|
SEpSet* pEpSet = &pTscObj->pAppInfo->mgmtEp.epSet;
|
||||||
|
|
||||||
int64_t transporterId = 0;
|
int64_t transporterId = 0;
|
||||||
|
|
@ -283,7 +291,7 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) {
|
||||||
if (qIsDdlQuery(pQuery)) {
|
if (qIsDdlQuery(pQuery)) {
|
||||||
CHECK_CODE_GOTO(execDdlQuery(pRequest, pQuery), _return);
|
CHECK_CODE_GOTO(execDdlQuery(pRequest, pQuery), _return);
|
||||||
} else {
|
} else {
|
||||||
CHECK_CODE_GOTO(qCreateQueryDag(pQuery, &pDag), _return);
|
CHECK_CODE_GOTO(getPlan(pRequest, pQuery, &pDag), _return);
|
||||||
CHECK_CODE_GOTO(scheduleQuery(pRequest, pDag, &pJob), _return);
|
CHECK_CODE_GOTO(scheduleQuery(pRequest, pDag, &pJob), _return);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -490,9 +498,38 @@ void* doFetchRow(SRequestObj* pRequest) {
|
||||||
SReqResultInfo* pResultInfo = &pRequest->body.resInfo;
|
SReqResultInfo* pResultInfo = &pRequest->body.resInfo;
|
||||||
|
|
||||||
if (pResultInfo->pData == NULL || pResultInfo->current >= pResultInfo->numOfRows) {
|
if (pResultInfo->pData == NULL || pResultInfo->current >= pResultInfo->numOfRows) {
|
||||||
|
if (pRequest->type == TDMT_MND_SHOW) {
|
||||||
pRequest->type = TDMT_MND_SHOW_RETRIEVE;
|
pRequest->type = TDMT_MND_SHOW_RETRIEVE;
|
||||||
|
} else if (pRequest->type == TDMT_VND_SHOW_TABLES) {
|
||||||
|
pRequest->type = TDMT_VND_SHOW_TABLES_FETCH;
|
||||||
|
} 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;
|
||||||
|
}
|
||||||
|
|
||||||
SMsgSendInfo* body = buildSendMsgInfoImpl(pRequest);
|
SVgroupInfo* pVgroupInfo = taosArrayGet(pShowReqInfo->pArray, pShowReqInfo->currentIndex);
|
||||||
|
SVShowTablesReq* pShowReq = calloc(1, sizeof(SVShowTablesReq));
|
||||||
|
pShowReq->head.vgId = htonl(pVgroupInfo->vgId);
|
||||||
|
|
||||||
|
pRequest->body.requestMsg.len = sizeof(SVShowTablesReq);
|
||||||
|
pRequest->body.requestMsg.pData = pShowReq;
|
||||||
|
|
||||||
|
SMsgSendInfo* body = buildMsgInfoImpl(pRequest);
|
||||||
|
|
||||||
|
int64_t transporterId = 0;
|
||||||
|
STscObj *pTscObj = pRequest->pTscObj;
|
||||||
|
asyncSendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &transporterId, body);
|
||||||
|
|
||||||
|
tsem_wait(&pRequest->body.rspSem);
|
||||||
|
destroySendMsgInfo(body);
|
||||||
|
|
||||||
|
pRequest->type = TDMT_VND_SHOW_TABLES_FETCH;
|
||||||
|
}
|
||||||
|
|
||||||
|
SMsgSendInfo* body = buildMsgInfoImpl(pRequest);
|
||||||
|
|
||||||
int64_t transporterId = 0;
|
int64_t transporterId = 0;
|
||||||
STscObj *pTscObj = pRequest->pTscObj;
|
STscObj *pTscObj = pRequest->pTscObj;
|
||||||
|
|
|
||||||
|
|
@ -18,23 +18,26 @@
|
||||||
#include "tname.h"
|
#include "tname.h"
|
||||||
#include "clientInt.h"
|
#include "clientInt.h"
|
||||||
#include "clientLog.h"
|
#include "clientLog.h"
|
||||||
#include "trpc.h"
|
|
||||||
|
|
||||||
int (*handleRequestRspFp[TDMT_MAX])(void*, const SDataBuf* pMsg, int32_t code);
|
int (*handleRequestRspFp[TDMT_MAX])(void*, const SDataBuf* pMsg, int32_t code);
|
||||||
|
|
||||||
|
static void setErrno(SRequestObj* pRequest, int32_t code) {
|
||||||
|
pRequest->code = code;
|
||||||
|
terrno = code;
|
||||||
|
}
|
||||||
|
|
||||||
int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code) {
|
int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
SRequestObj* pRequest = param;
|
SRequestObj* pRequest = param;
|
||||||
pRequest->code = code;
|
setErrno(pRequest, code);
|
||||||
|
|
||||||
sem_post(&pRequest->body.rspSem);
|
sem_post(&pRequest->body.rspSem);
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
int processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
SRequestObj* pRequest = param;
|
SRequestObj* pRequest = param;
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
pRequest->code = code;
|
setErrno(pRequest, code);
|
||||||
terrno = code;
|
|
||||||
|
|
||||||
sem_post(&pRequest->body.rspSem);
|
sem_post(&pRequest->body.rspSem);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
@ -74,52 +77,55 @@ int processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t buildRetrieveMnodeMsg(SRequestObj *pRequest, SMsgSendInfo* pMsgSendInfo) {
|
SMsgSendInfo* buildMsgInfoImpl(SRequestObj *pRequest) {
|
||||||
pMsgSendInfo->msgType = TDMT_MND_SHOW_RETRIEVE;
|
|
||||||
pMsgSendInfo->msgInfo.len = sizeof(SRetrieveTableMsg);
|
|
||||||
pMsgSendInfo->requestObjRefId = pRequest->self;
|
|
||||||
pMsgSendInfo->param = pRequest;
|
|
||||||
pMsgSendInfo->fp = handleRequestRspFp[TMSG_INDEX(pMsgSendInfo->msgType)];
|
|
||||||
|
|
||||||
SRetrieveTableMsg *pRetrieveMsg = calloc(1, sizeof(SRetrieveTableMsg));
|
|
||||||
if (pRetrieveMsg == NULL) {
|
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
pRetrieveMsg->showId = htonl(pRequest->body.execId);
|
|
||||||
pMsgSendInfo->msgInfo.pData = pRetrieveMsg;
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
SMsgSendInfo* buildSendMsgInfoImpl(SRequestObj *pRequest) {
|
|
||||||
SMsgSendInfo* pMsgSendInfo = calloc(1, sizeof(SMsgSendInfo));
|
SMsgSendInfo* pMsgSendInfo = calloc(1, sizeof(SMsgSendInfo));
|
||||||
|
|
||||||
if (pRequest->type == TDMT_MND_SHOW_RETRIEVE) {
|
|
||||||
buildRetrieveMnodeMsg(pRequest, pMsgSendInfo);
|
|
||||||
} else {
|
|
||||||
assert(pRequest != NULL);
|
|
||||||
pMsgSendInfo->requestObjRefId = pRequest->self;
|
pMsgSendInfo->requestObjRefId = pRequest->self;
|
||||||
pMsgSendInfo->msgInfo = pRequest->body.requestMsg;
|
|
||||||
pMsgSendInfo->msgType = pRequest->type;
|
|
||||||
pMsgSendInfo->requestId = pRequest->requestId;
|
pMsgSendInfo->requestId = pRequest->requestId;
|
||||||
pMsgSendInfo->param = pRequest;
|
pMsgSendInfo->param = pRequest;
|
||||||
|
pMsgSendInfo->msgType = pRequest->type;
|
||||||
|
|
||||||
pMsgSendInfo->fp = (handleRequestRspFp[TMSG_INDEX(pRequest->type)] == NULL)? genericRspCallback:handleRequestRspFp[TMSG_INDEX(pRequest->type)];
|
if (pRequest->type == TDMT_MND_SHOW_RETRIEVE || pRequest->type == TDMT_VND_SHOW_TABLES_FETCH) {
|
||||||
|
if (pRequest->type == TDMT_MND_SHOW_RETRIEVE) {
|
||||||
|
SRetrieveTableMsg* pRetrieveMsg = calloc(1, sizeof(SRetrieveTableMsg));
|
||||||
|
if (pRetrieveMsg == NULL) {
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pRetrieveMsg->showId = htobe64(pRequest->body.showInfo.execId);
|
||||||
|
pMsgSendInfo->msgInfo.pData = pRetrieveMsg;
|
||||||
|
pMsgSendInfo->msgInfo.len = sizeof(SRetrieveTableMsg);
|
||||||
|
} else {
|
||||||
|
SVShowTablesFetchReq* pFetchMsg = calloc(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);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
assert(pRequest != NULL);
|
||||||
|
pMsgSendInfo->msgInfo = pRequest->body.requestMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
pMsgSendInfo->fp = (handleRequestRspFp[TMSG_INDEX(pRequest->type)] == NULL)? genericRspCallback:handleRequestRspFp[TMSG_INDEX(pRequest->type)];
|
||||||
return pMsgSendInfo;
|
return pMsgSendInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t processShowRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
int32_t processShowRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
SRequestObj* pRequest = param;
|
SRequestObj* pRequest = param;
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
pRequest->code = code;
|
setErrno(pRequest, code);
|
||||||
tsem_post(&pRequest->body.rspSem);
|
tsem_post(&pRequest->body.rspSem);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SShowRsp* pShow = (SShowRsp *)pMsg->pData;
|
SShowRsp* pShow = (SShowRsp *)pMsg->pData;
|
||||||
pShow->showId = htonl(pShow->showId);
|
pShow->showId = htobe64(pShow->showId);
|
||||||
|
|
||||||
STableMetaMsg *pMetaMsg = &(pShow->tableMeta);
|
STableMetaMsg *pMetaMsg = &(pShow->tableMeta);
|
||||||
pMetaMsg->numOfColumns = htonl(pMetaMsg->numOfColumns);
|
pMetaMsg->numOfColumns = htonl(pMetaMsg->numOfColumns);
|
||||||
|
|
@ -128,6 +134,7 @@ int32_t processShowRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
pMetaMsg->tuid = htobe64(pMetaMsg->tuid);
|
pMetaMsg->tuid = htobe64(pMetaMsg->tuid);
|
||||||
for (int i = 0; i < pMetaMsg->numOfColumns; ++i) {
|
for (int i = 0; i < pMetaMsg->numOfColumns; ++i) {
|
||||||
pSchema->bytes = htonl(pSchema->bytes);
|
pSchema->bytes = htonl(pSchema->bytes);
|
||||||
|
pSchema->colId = htonl(pSchema->colId);
|
||||||
pSchema++;
|
pSchema++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -148,34 +155,81 @@ int32_t processShowRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
pResInfo->pCol = calloc(pResInfo->numOfCols, POINTER_BYTES);
|
pResInfo->pCol = calloc(pResInfo->numOfCols, POINTER_BYTES);
|
||||||
pResInfo->length = calloc(pResInfo->numOfCols, sizeof(int32_t));
|
pResInfo->length = calloc(pResInfo->numOfCols, sizeof(int32_t));
|
||||||
|
|
||||||
pRequest->body.execId = pShow->showId;
|
pRequest->body.showInfo.execId = pShow->showId;
|
||||||
|
|
||||||
|
// 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);
|
tsem_post(&pRequest->body.rspSem);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t processRetrieveMnodeRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
int32_t processRetrieveMnodeRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
assert(pMsg->len >= sizeof(SRetrieveTableRsp));
|
SRequestObj *pRequest = param;
|
||||||
|
SReqResultInfo *pResInfo = &pRequest->body.resInfo;
|
||||||
|
tfree(pResInfo->pRspMsg);
|
||||||
|
|
||||||
SRequestObj* pRequest = param;
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
// tfree(pRequest->body.resInfo.pRspMsg);
|
setErrno(pRequest, code);
|
||||||
// pRequest->body.resInfo.pRspMsg = pMsg->pData;
|
tsem_post(&pRequest->body.rspSem);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(pMsg->len >= sizeof(SRetrieveTableRsp));
|
||||||
|
|
||||||
SRetrieveTableRsp *pRetrieve = (SRetrieveTableRsp *) pMsg->pData;
|
SRetrieveTableRsp *pRetrieve = (SRetrieveTableRsp *) pMsg->pData;
|
||||||
pRetrieve->numOfRows = htonl(pRetrieve->numOfRows);
|
pRetrieve->numOfRows = htonl(pRetrieve->numOfRows);
|
||||||
pRetrieve->precision = htons(pRetrieve->precision);
|
pRetrieve->precision = htons(pRetrieve->precision);
|
||||||
|
|
||||||
SReqResultInfo* pResInfo = &pRequest->body.resInfo;
|
|
||||||
|
|
||||||
tfree(pResInfo->pRspMsg);
|
|
||||||
pResInfo->pRspMsg = pMsg->pData;
|
pResInfo->pRspMsg = pMsg->pData;
|
||||||
pResInfo->numOfRows = pRetrieve->numOfRows;
|
pResInfo->numOfRows = pRetrieve->numOfRows;
|
||||||
pResInfo->pData = pRetrieve->data; // todo fix this in async model
|
pResInfo->pData = pRetrieve->data;
|
||||||
|
|
||||||
pResInfo->current = 0;
|
pResInfo->current = 0;
|
||||||
setResultDataPtr(pResInfo, pResInfo->fields, pResInfo->numOfCols, pResInfo->numOfRows);
|
setResultDataPtr(pResInfo, pResInfo->fields, pResInfo->numOfCols, pResInfo->numOfRows);
|
||||||
|
|
||||||
tscDebug("0x%"PRIx64" numOfRows:%d, complete:%d, qId:0x%"PRIx64, pRequest->self, pRetrieve->numOfRows,
|
tscDebug("0x%"PRIx64" numOfRows:%d, complete:%d, qId:0x%"PRIx64, pRequest->self, pRetrieve->numOfRows,
|
||||||
pRetrieve->completed, pRequest->body.execId);
|
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;
|
||||||
|
tfree(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);
|
tsem_post(&pRequest->body.rspSem);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -191,34 +245,48 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
SRequestObj* pRequest = param;
|
SRequestObj* pRequest = param;
|
||||||
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
pRequest->code = code;
|
setErrno(pRequest, code);
|
||||||
tsem_post(&pRequest->body.rspSem);
|
tsem_post(&pRequest->body.rspSem);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SUseDbRsp* pUseDbRsp = (SUseDbRsp*)pMsg->pData;
|
SUseDbRsp* pUseDbRsp = (SUseDbRsp*) pMsg->pData;
|
||||||
SName name = {0};
|
SName name = {0};
|
||||||
tNameFromString(&name, pUseDbRsp->db, T_NAME_ACCT | T_NAME_DB);
|
tNameFromString(&name, pUseDbRsp->db, T_NAME_ACCT|T_NAME_DB);
|
||||||
|
|
||||||
char db[TSDB_DB_NAME_LEN] = {0};
|
char db[TSDB_DB_NAME_LEN] = {0};
|
||||||
tNameGetDbName(&name, db);
|
tNameGetDbName(&name, db);
|
||||||
|
|
||||||
setConnectionDB(pRequest->pTscObj, db);
|
setConnectionDB(pRequest->pTscObj, db);
|
||||||
|
|
||||||
tsem_post(&pRequest->body.rspSem);
|
tsem_post(&pRequest->body.rspSem);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t processCreateTableRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
int32_t processCreateTableRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
assert(pMsg != NULL);
|
assert(pMsg != NULL && param != NULL);
|
||||||
SRequestObj* pRequest = param;
|
SRequestObj* pRequest = param;
|
||||||
|
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
setErrno(pRequest, code);
|
||||||
tsem_post(&pRequest->body.rspSem);
|
tsem_post(&pRequest->body.rspSem);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
tsem_post(&pRequest->body.rspSem);
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t processDropDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
int32_t processDropDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
// todo: Remove cache in catalog cache.
|
// todo: Remove cache in catalog cache.
|
||||||
SRequestObj* pRequest = param;
|
SRequestObj* pRequest = param;
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
setErrno(pRequest, code);
|
||||||
tsem_post(&pRequest->body.rspSem);
|
tsem_post(&pRequest->body.rspSem);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
tsem_post(&pRequest->body.rspSem);
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initMsgHandleFp() {
|
void initMsgHandleFp() {
|
||||||
|
|
@ -304,4 +372,7 @@ void initMsgHandleFp() {
|
||||||
handleRequestRspFp[TMSG_INDEX(TDMT_MND_USE_DB)] = processUseDbRsp;
|
handleRequestRspFp[TMSG_INDEX(TDMT_MND_USE_DB)] = processUseDbRsp;
|
||||||
handleRequestRspFp[TMSG_INDEX(TDMT_MND_CREATE_STB)] = processCreateTableRsp;
|
handleRequestRspFp[TMSG_INDEX(TDMT_MND_CREATE_STB)] = processCreateTableRsp;
|
||||||
handleRequestRspFp[TMSG_INDEX(TDMT_MND_DROP_DB)] = processDropDbRsp;
|
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;
|
||||||
}
|
}
|
||||||
|
|
@ -49,357 +49,357 @@ int main(int argc, char** argv) {
|
||||||
|
|
||||||
TEST(testCase, driverInit_Test) { taos_init(); }
|
TEST(testCase, driverInit_Test) { taos_init(); }
|
||||||
|
|
||||||
#if 0
|
|
||||||
TEST(testCase, connect_Test) {
|
TEST(testCase, connect_Test) {
|
||||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
assert(pConn != NULL);
|
if (pConn == NULL) {
|
||||||
taos_close(pConn);
|
printf("failed to connect to server, reason:%s\n", taos_errstr(NULL));
|
||||||
}
|
|
||||||
|
|
||||||
TEST(testCase, create_user_Test) {
|
|
||||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
|
||||||
assert(pConn != NULL);
|
|
||||||
|
|
||||||
TAOS_RES* pRes = taos_query(pConn, "create user abc pass 'abc'");
|
|
||||||
if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
|
||||||
printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
taos_free_result(pRes);
|
|
||||||
taos_close(pConn);
|
taos_close(pConn);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(testCase, create_account_Test) {
|
//TEST(testCase, create_user_Test) {
|
||||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
assert(pConn != NULL);
|
|
||||||
|
|
||||||
TAOS_RES* pRes = taos_query(pConn, "create account aabc pass 'abc'");
|
|
||||||
if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
|
||||||
printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
|
||||||
}
|
|
||||||
|
|
||||||
taos_free_result(pRes);
|
|
||||||
taos_close(pConn);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(testCase, drop_account_Test) {
|
|
||||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
|
||||||
assert(pConn != NULL);
|
|
||||||
|
|
||||||
TAOS_RES* pRes = taos_query(pConn, "drop account aabc");
|
|
||||||
if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
|
||||||
printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
|
||||||
}
|
|
||||||
|
|
||||||
taos_free_result(pRes);
|
|
||||||
taos_close(pConn);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(testCase, show_user_Test) {
|
|
||||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
|
||||||
assert(pConn != NULL);
|
|
||||||
|
|
||||||
TAOS_RES* pRes = taos_query(pConn, "show users");
|
|
||||||
TAOS_ROW pRow = NULL;
|
|
||||||
|
|
||||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
|
||||||
int32_t numOfFields = taos_num_fields(pRes);
|
|
||||||
|
|
||||||
char str[512] = {0};
|
|
||||||
while((pRow = taos_fetch_row(pRes)) != NULL) {
|
|
||||||
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
|
||||||
printf("%s\n", str);
|
|
||||||
}
|
|
||||||
|
|
||||||
taos_close(pConn);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(testCase, drop_user_Test) {
|
|
||||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
|
||||||
assert(pConn != NULL);
|
|
||||||
|
|
||||||
TAOS_RES* pRes = taos_query(pConn, "drop user abc");
|
|
||||||
if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
|
||||||
printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
|
||||||
}
|
|
||||||
|
|
||||||
taos_free_result(pRes);
|
|
||||||
taos_close(pConn);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(testCase, show_db_Test) {
|
|
||||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
|
||||||
// assert(pConn != NULL);
|
// assert(pConn != NULL);
|
||||||
|
//
|
||||||
|
// TAOS_RES* pRes = taos_query(pConn, "create user abc pass 'abc'");
|
||||||
|
// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
||||||
|
// printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// taos_free_result(pRes);
|
||||||
|
// taos_close(pConn);
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//TEST(testCase, create_account_Test) {
|
||||||
|
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
|
// assert(pConn != NULL);
|
||||||
|
//
|
||||||
|
// TAOS_RES* pRes = taos_query(pConn, "create account aabc pass 'abc'");
|
||||||
|
// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
||||||
|
// printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// taos_free_result(pRes);
|
||||||
|
// taos_close(pConn);
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//TEST(testCase, drop_account_Test) {
|
||||||
|
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
|
// assert(pConn != NULL);
|
||||||
|
//
|
||||||
|
// TAOS_RES* pRes = taos_query(pConn, "drop account aabc");
|
||||||
|
// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
||||||
|
// printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// taos_free_result(pRes);
|
||||||
|
// taos_close(pConn);
|
||||||
|
//}
|
||||||
|
|
||||||
TAOS_RES* pRes = taos_query(pConn, "show databases");
|
//TEST(testCase, show_user_Test) {
|
||||||
TAOS_ROW pRow = NULL;
|
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
|
// assert(pConn != NULL);
|
||||||
|
//
|
||||||
|
// TAOS_RES* pRes = taos_query(pConn, "show users");
|
||||||
|
// TAOS_ROW pRow = NULL;
|
||||||
|
//
|
||||||
|
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||||
|
// int32_t numOfFields = taos_num_fields(pRes);
|
||||||
|
//
|
||||||
|
// char str[512] = {0};
|
||||||
|
// while((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||||
|
// int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||||
|
// printf("%s\n", str);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// taos_close(pConn);
|
||||||
|
//}
|
||||||
|
|
||||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
//TEST(testCase, drop_user_Test) {
|
||||||
int32_t numOfFields = taos_num_fields(pRes);
|
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
|
// assert(pConn != NULL);
|
||||||
|
//
|
||||||
|
// TAOS_RES* pRes = taos_query(pConn, "drop user abc");
|
||||||
|
// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
||||||
|
// printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// taos_free_result(pRes);
|
||||||
|
// taos_close(pConn);
|
||||||
|
//}
|
||||||
|
|
||||||
char str[512] = {0};
|
//TEST(testCase, show_db_Test) {
|
||||||
while((pRow = taos_fetch_row(pRes)) != NULL) {
|
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
//// assert(pConn != NULL);
|
||||||
printf("%s\n", str);
|
//
|
||||||
}
|
// TAOS_RES* pRes = taos_query(pConn, "show databases");
|
||||||
|
// TAOS_ROW pRow = NULL;
|
||||||
|
//
|
||||||
|
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||||
|
// int32_t numOfFields = taos_num_fields(pRes);
|
||||||
|
//
|
||||||
|
// char str[512] = {0};
|
||||||
|
// while((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||||
|
// int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||||
|
// printf("%s\n", str);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// taos_close(pConn);
|
||||||
|
//}
|
||||||
|
|
||||||
taos_close(pConn);
|
//TEST(testCase, create_db_Test) {
|
||||||
}
|
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
|
// assert(pConn != NULL);
|
||||||
|
//
|
||||||
|
// TAOS_RES* pRes = taos_query(pConn, "create database abc1");
|
||||||
|
// if (taos_errno(pRes) != 0) {
|
||||||
|
// printf("error in create db, reason:%s\n", taos_errstr(pRes));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||||
|
// ASSERT_TRUE(pFields == NULL);
|
||||||
|
//
|
||||||
|
// int32_t numOfFields = taos_num_fields(pRes);
|
||||||
|
// ASSERT_EQ(numOfFields, 0);
|
||||||
|
//
|
||||||
|
// taos_free_result(pRes);
|
||||||
|
//
|
||||||
|
// pRes = taos_query(pConn, "create database abc1 vgroups 4");
|
||||||
|
// if (taos_errno(pRes) != 0) {
|
||||||
|
// printf("error in create db, reason:%s\n", taos_errstr(pRes));
|
||||||
|
// }
|
||||||
|
// taos_close(pConn);
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//TEST(testCase, create_dnode_Test) {
|
||||||
|
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
|
// assert(pConn != NULL);
|
||||||
|
//
|
||||||
|
// TAOS_RES* pRes = taos_query(pConn, "create dnode abc1 port 7000");
|
||||||
|
// if (taos_errno(pRes) != 0) {
|
||||||
|
// printf("error in create dnode, reason:%s\n", taos_errstr(pRes));
|
||||||
|
// }
|
||||||
|
// taos_free_result(pRes);
|
||||||
|
//
|
||||||
|
// pRes = taos_query(pConn, "create dnode 1.1.1.1 port 9000");
|
||||||
|
// if (taos_errno(pRes) != 0) {
|
||||||
|
// printf("failed to create dnode, reason:%s\n", taos_errstr(pRes));
|
||||||
|
// }
|
||||||
|
// taos_free_result(pRes);
|
||||||
|
//
|
||||||
|
// taos_close(pConn);
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//TEST(testCase, drop_dnode_Test) {
|
||||||
|
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
|
// assert(pConn != NULL);
|
||||||
|
//
|
||||||
|
// TAOS_RES* pRes = taos_query(pConn, "drop dnode 2");
|
||||||
|
// if (taos_errno(pRes) != 0) {
|
||||||
|
// printf("error in drop dnode, reason:%s\n", taos_errstr(pRes));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||||
|
// ASSERT_TRUE(pFields == NULL);
|
||||||
|
//
|
||||||
|
// int32_t numOfFields = taos_num_fields(pRes);
|
||||||
|
// ASSERT_EQ(numOfFields, 0);
|
||||||
|
//
|
||||||
|
// taos_free_result(pRes);
|
||||||
|
// taos_close(pConn);
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//TEST(testCase, use_db_test) {
|
||||||
|
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
|
// assert(pConn != NULL);
|
||||||
|
//
|
||||||
|
// TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||||
|
// if (taos_errno(pRes) != 0) {
|
||||||
|
// printf("error in use db, reason:%s\n", taos_errstr(pRes));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||||
|
// ASSERT_TRUE(pFields == NULL);
|
||||||
|
//
|
||||||
|
// int32_t numOfFields = taos_num_fields(pRes);
|
||||||
|
// ASSERT_EQ(numOfFields, 0);
|
||||||
|
//
|
||||||
|
// taos_close(pConn);
|
||||||
|
//}
|
||||||
|
|
||||||
TEST(testCase, create_db_Test) {
|
//TEST(testCase, drop_db_test) {
|
||||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
//// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
assert(pConn != NULL);
|
//// assert(pConn != NULL);
|
||||||
|
////
|
||||||
|
//// showDB(pConn);
|
||||||
|
////
|
||||||
|
//// TAOS_RES* pRes = taos_query(pConn, "drop database abc1");
|
||||||
|
//// if (taos_errno(pRes) != 0) {
|
||||||
|
//// printf("failed to drop db, reason:%s\n", taos_errstr(pRes));
|
||||||
|
//// }
|
||||||
|
//// taos_free_result(pRes);
|
||||||
|
////
|
||||||
|
//// showDB(pConn);
|
||||||
|
////
|
||||||
|
//// pRes = taos_query(pConn, "create database abc1");
|
||||||
|
//// if (taos_errno(pRes) != 0) {
|
||||||
|
//// printf("create to drop db, reason:%s\n", taos_errstr(pRes));
|
||||||
|
//// }
|
||||||
|
//// taos_free_result(pRes);
|
||||||
|
//// taos_close(pConn);
|
||||||
|
//}
|
||||||
|
|
||||||
TAOS_RES* pRes = taos_query(pConn, "create database abc1");
|
// TEST(testCase, create_stable_Test) {
|
||||||
if (taos_errno(pRes) != 0) {
|
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
printf("error in create db, reason:%s\n", taos_errstr(pRes));
|
// assert(pConn != NULL);
|
||||||
}
|
//
|
||||||
|
// TAOS_RES* pRes = taos_query(pConn, "create database abc1");
|
||||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
// if (taos_errno(pRes) != 0) {
|
||||||
ASSERT_TRUE(pFields == NULL);
|
// printf("error in create db, reason:%s\n", taos_errstr(pRes));
|
||||||
|
// }
|
||||||
int32_t numOfFields = taos_num_fields(pRes);
|
// taos_free_result(pRes);
|
||||||
ASSERT_EQ(numOfFields, 0);
|
//
|
||||||
|
// pRes = taos_query(pConn, "use abc1");
|
||||||
taos_free_result(pRes);
|
// if (taos_errno(pRes) != 0) {
|
||||||
|
// printf("error in use db, reason:%s\n", taos_errstr(pRes));
|
||||||
pRes = taos_query(pConn, "create database abc1 vgroups 4");
|
// }
|
||||||
if (taos_errno(pRes) != 0) {
|
// taos_free_result(pRes);
|
||||||
printf("error in create db, reason:%s\n", taos_errstr(pRes));
|
//
|
||||||
}
|
// pRes = taos_query(pConn, "create stable st1(ts timestamp, k int) tags(a int)");
|
||||||
taos_close(pConn);
|
// if (taos_errno(pRes) != 0) {
|
||||||
}
|
// printf("error in create stable, reason:%s\n", taos_errstr(pRes));
|
||||||
|
// }
|
||||||
TEST(testCase, create_dnode_Test) {
|
//
|
||||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||||
assert(pConn != NULL);
|
// ASSERT_TRUE(pFields == NULL);
|
||||||
|
//
|
||||||
TAOS_RES* pRes = taos_query(pConn, "create dnode abc1 port 7000");
|
// int32_t numOfFields = taos_num_fields(pRes);
|
||||||
if (taos_errno(pRes) != 0) {
|
// ASSERT_EQ(numOfFields, 0);
|
||||||
printf("error in create dnode, reason:%s\n", taos_errstr(pRes));
|
//
|
||||||
}
|
// taos_free_result(pRes);
|
||||||
taos_free_result(pRes);
|
// taos_close(pConn);
|
||||||
|
//}
|
||||||
pRes = taos_query(pConn, "create dnode 1.1.1.1 port 9000");
|
//
|
||||||
if (taos_errno(pRes) != 0) {
|
//TEST(testCase, create_table_Test) {
|
||||||
printf("failed to create dnode, reason:%s\n", taos_errstr(pRes));
|
// // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
}
|
// // assert(pConn != NULL);
|
||||||
taos_free_result(pRes);
|
// //
|
||||||
|
// // TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||||
taos_close(pConn);
|
// // taos_free_result(pRes);
|
||||||
}
|
// //
|
||||||
|
// // pRes = taos_query(pConn, "create table tm0(ts timestamp, k int)");
|
||||||
TEST(testCase, drop_dnode_Test) {
|
// // taos_free_result(pRes);
|
||||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
// //
|
||||||
assert(pConn != NULL);
|
// // taos_close(pConn);
|
||||||
|
//}
|
||||||
TAOS_RES* pRes = taos_query(pConn, "drop dnode 2");
|
//
|
||||||
if (taos_errno(pRes) != 0) {
|
//TEST(testCase, create_ctable_Test) {
|
||||||
printf("error in drop dnode, reason:%s\n", taos_errstr(pRes));
|
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
}
|
// assert(pConn != NULL);
|
||||||
|
//
|
||||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
// TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||||
ASSERT_TRUE(pFields == NULL);
|
// if (taos_errno(pRes) != 0) {
|
||||||
|
// printf("failed to use db, reason:%s\n", taos_errstr(pRes));
|
||||||
int32_t numOfFields = taos_num_fields(pRes);
|
// }
|
||||||
ASSERT_EQ(numOfFields, 0);
|
// taos_free_result(pRes);
|
||||||
|
//
|
||||||
taos_free_result(pRes);
|
//// pRes = taos_query(pConn, "create table tm0 using st1 tags(1)");
|
||||||
taos_close(pConn);
|
//// if (taos_errno(pRes) != 0) {
|
||||||
}
|
//// printf("failed to create child table tm0, reason:%s\n", taos_errstr(pRes));
|
||||||
|
//// }
|
||||||
TEST(testCase, use_db_test) {
|
////
|
||||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
//// taos_free_result(pRes);
|
||||||
assert(pConn != NULL);
|
// taos_close(pConn);
|
||||||
|
//}
|
||||||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
//
|
||||||
if (taos_errno(pRes) != 0) {
|
//TEST(testCase, show_stable_Test) {
|
||||||
printf("error in use db, reason:%s\n", taos_errstr(pRes));
|
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
}
|
// assert(pConn != NULL);
|
||||||
|
//
|
||||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
// TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||||
ASSERT_TRUE(pFields == NULL);
|
// if (taos_errno(pRes) != 0) {
|
||||||
|
// printf("failed to use db, reason:%s\n", taos_errstr(pRes));
|
||||||
int32_t numOfFields = taos_num_fields(pRes);
|
// }
|
||||||
ASSERT_EQ(numOfFields, 0);
|
// taos_free_result(pRes);
|
||||||
|
//
|
||||||
taos_close(pConn);
|
// pRes = taos_query(pConn, "show stables");
|
||||||
}
|
// if (taos_errno(pRes) != 0) {
|
||||||
|
// printf("failed to show stables, reason:%s\n", taos_errstr(pRes));
|
||||||
TEST(testCase, drop_db_test) {
|
// taos_free_result(pRes);
|
||||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
// ASSERT_TRUE(false);
|
||||||
assert(pConn != NULL);
|
// }
|
||||||
|
//
|
||||||
showDB(pConn);
|
// TAOS_ROW pRow = NULL;
|
||||||
|
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||||
TAOS_RES* pRes = taos_query(pConn, "drop database abc1");
|
// int32_t numOfFields = taos_num_fields(pRes);
|
||||||
if (taos_errno(pRes) != 0) {
|
//
|
||||||
printf("failed to drop db, reason:%s\n", taos_errstr(pRes));
|
// char str[512] = {0};
|
||||||
}
|
// while((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||||
taos_free_result(pRes);
|
// int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||||
|
// printf("%s\n", str);
|
||||||
showDB(pConn);
|
// }
|
||||||
|
//
|
||||||
pRes = taos_query(pConn, "create database abc1");
|
// taos_free_result(pRes);
|
||||||
if (taos_errno(pRes) != 0) {
|
// taos_close(pConn);
|
||||||
printf("create to drop db, reason:%s\n", taos_errstr(pRes));
|
//}
|
||||||
}
|
//
|
||||||
taos_free_result(pRes);
|
//TEST(testCase, show_vgroup_Test) {
|
||||||
taos_close(pConn);
|
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
}
|
// assert(pConn != NULL);
|
||||||
|
//
|
||||||
TEST(testCase, create_stable_Test) {
|
// TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
// if (taos_errno(pRes) != 0) {
|
||||||
assert(pConn != NULL);
|
// printf("failed to use db, reason:%s\n", taos_errstr(pRes));
|
||||||
|
// }
|
||||||
TAOS_RES* pRes = taos_query(pConn, "create database abc1");
|
// taos_free_result(pRes);
|
||||||
if (taos_errno(pRes) != 0) {
|
//
|
||||||
printf("error in create db, reason:%s\n", taos_errstr(pRes));
|
// pRes = taos_query(pConn, "show vgroups");
|
||||||
}
|
// if (taos_errno(pRes) != 0) {
|
||||||
taos_free_result(pRes);
|
// printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes));
|
||||||
|
// taos_free_result(pRes);
|
||||||
pRes = taos_query(pConn, "use abc1");
|
// ASSERT_TRUE(false);
|
||||||
if (taos_errno(pRes) != 0) {
|
// }
|
||||||
printf("error in use db, reason:%s\n", taos_errstr(pRes));
|
//
|
||||||
}
|
// TAOS_ROW pRow = NULL;
|
||||||
taos_free_result(pRes);
|
//
|
||||||
|
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||||
pRes = taos_query(pConn, "create stable st1(ts timestamp, k int) tags(a int)");
|
// int32_t numOfFields = taos_num_fields(pRes);
|
||||||
if (taos_errno(pRes) != 0) {
|
//
|
||||||
printf("error in create stable, reason:%s\n", taos_errstr(pRes));
|
// char str[512] = {0};
|
||||||
}
|
// while((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||||
|
// int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
// printf("%s\n", str);
|
||||||
ASSERT_TRUE(pFields == NULL);
|
// }
|
||||||
|
//
|
||||||
int32_t numOfFields = taos_num_fields(pRes);
|
// taos_free_result(pRes);
|
||||||
ASSERT_EQ(numOfFields, 0);
|
//
|
||||||
|
// taos_close(pConn);
|
||||||
taos_free_result(pRes);
|
//}
|
||||||
taos_close(pConn);
|
//
|
||||||
}
|
//TEST(testCase, drop_stable_Test) {
|
||||||
|
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
TEST(testCase, create_table_Test) {
|
// assert(pConn != NULL);
|
||||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
//
|
||||||
// assert(pConn != NULL);
|
// TAOS_RES* pRes = taos_query(pConn, "create database abc1");
|
||||||
//
|
// if (taos_errno(pRes) != 0) {
|
||||||
// TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
// printf("error in creating db, reason:%s\n", taos_errstr(pRes));
|
||||||
// taos_free_result(pRes);
|
// }
|
||||||
//
|
// taos_free_result(pRes);
|
||||||
// pRes = taos_query(pConn, "create table tm0(ts timestamp, k int)");
|
//
|
||||||
// taos_free_result(pRes);
|
// pRes = taos_query(pConn, "use abc1");
|
||||||
//
|
// if (taos_errno(pRes) != 0) {
|
||||||
// taos_close(pConn);
|
// printf("error in using db, reason:%s\n", taos_errstr(pRes));
|
||||||
}
|
// }
|
||||||
|
// taos_free_result(pRes);
|
||||||
TEST(testCase, create_ctable_Test) {
|
//
|
||||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
// pRes = taos_query(pConn, "drop stable st1");
|
||||||
assert(pConn != NULL);
|
// if (taos_errno(pRes) != 0) {
|
||||||
|
// printf("failed to drop stable, reason:%s\n", taos_errstr(pRes));
|
||||||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
// }
|
||||||
if (taos_errno(pRes) != 0) {
|
//
|
||||||
printf("failed to use db, reason:%s\n", taos_errstr(pRes));
|
// taos_free_result(pRes);
|
||||||
}
|
// taos_close(pConn);
|
||||||
taos_free_result(pRes);
|
//}
|
||||||
|
|
||||||
pRes = taos_query(pConn, "create table tm0 using st1 tags(1)");
|
|
||||||
if (taos_errno(pRes) != 0) {
|
|
||||||
printf("failed to create child table tm0, reason:%s\n", taos_errstr(pRes));
|
|
||||||
}
|
|
||||||
|
|
||||||
taos_free_result(pRes);
|
|
||||||
taos_close(pConn);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(testCase, show_stable_Test) {
|
|
||||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
|
||||||
assert(pConn != NULL);
|
|
||||||
|
|
||||||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
|
||||||
if (taos_errno(pRes) != 0) {
|
|
||||||
printf("failed to use db, reason:%s\n", taos_errstr(pRes));
|
|
||||||
}
|
|
||||||
taos_free_result(pRes);
|
|
||||||
|
|
||||||
pRes = taos_query(pConn, "show stables");
|
|
||||||
if (taos_errno(pRes) != 0) {
|
|
||||||
printf("failed to show stables, reason:%s\n", taos_errstr(pRes));
|
|
||||||
taos_free_result(pRes);
|
|
||||||
ASSERT_TRUE(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
TAOS_ROW pRow = NULL;
|
|
||||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
|
||||||
int32_t numOfFields = taos_num_fields(pRes);
|
|
||||||
|
|
||||||
char str[512] = {0};
|
|
||||||
while((pRow = taos_fetch_row(pRes)) != NULL) {
|
|
||||||
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
|
||||||
printf("%s\n", str);
|
|
||||||
}
|
|
||||||
|
|
||||||
taos_free_result(pRes);
|
|
||||||
taos_close(pConn);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(testCase, show_vgroup_Test) {
|
|
||||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
|
||||||
assert(pConn != NULL);
|
|
||||||
|
|
||||||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
|
||||||
if (taos_errno(pRes) != 0) {
|
|
||||||
printf("failed to use db, reason:%s\n", taos_errstr(pRes));
|
|
||||||
}
|
|
||||||
taos_free_result(pRes);
|
|
||||||
|
|
||||||
pRes = taos_query(pConn, "show vgroups");
|
|
||||||
if (taos_errno(pRes) != 0) {
|
|
||||||
printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes));
|
|
||||||
taos_free_result(pRes);
|
|
||||||
ASSERT_TRUE(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
TAOS_ROW pRow = NULL;
|
|
||||||
|
|
||||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
|
||||||
int32_t numOfFields = taos_num_fields(pRes);
|
|
||||||
|
|
||||||
char str[512] = {0};
|
|
||||||
while((pRow = taos_fetch_row(pRes)) != NULL) {
|
|
||||||
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
|
||||||
printf("%s\n", str);
|
|
||||||
}
|
|
||||||
|
|
||||||
taos_free_result(pRes);
|
|
||||||
|
|
||||||
taos_close(pConn);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(testCase, drop_stable_Test) {
|
|
||||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
|
||||||
assert(pConn != NULL);
|
|
||||||
|
|
||||||
TAOS_RES* pRes = taos_query(pConn, "create database abc1");
|
|
||||||
if (taos_errno(pRes) != 0) {
|
|
||||||
printf("error in creating db, reason:%s\n", taos_errstr(pRes));
|
|
||||||
}
|
|
||||||
taos_free_result(pRes);
|
|
||||||
|
|
||||||
pRes = taos_query(pConn, "use abc1");
|
|
||||||
if (taos_errno(pRes) != 0) {
|
|
||||||
printf("error in using db, reason:%s\n", taos_errstr(pRes));
|
|
||||||
}
|
|
||||||
taos_free_result(pRes);
|
|
||||||
|
|
||||||
pRes = taos_query(pConn, "drop stable st1");
|
|
||||||
if (taos_errno(pRes) != 0) {
|
|
||||||
printf("failed to drop stable, reason:%s\n", taos_errstr(pRes));
|
|
||||||
}
|
|
||||||
|
|
||||||
taos_free_result(pRes);
|
|
||||||
taos_close(pConn);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//TEST(testCase, create_topic_Test) {
|
//TEST(testCase, create_topic_Test) {
|
||||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
|
|
@ -435,15 +435,58 @@ TEST(testCase, drop_stable_Test) {
|
||||||
// taos_close(pConn);
|
// taos_close(pConn);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
TEST(testCase, show_table_Test) {
|
//TEST(testCase, show_table_Test) {
|
||||||
|
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
|
// assert(pConn != NULL);
|
||||||
|
//
|
||||||
|
// TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||||
|
// taos_free_result(pRes);
|
||||||
|
//
|
||||||
|
// pRes = taos_query(pConn, "show tables");
|
||||||
|
// if (taos_errno(pRes) != 0) {
|
||||||
|
// printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes));
|
||||||
|
// taos_free_result(pRes);
|
||||||
|
// ASSERT_TRUE(false);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// TAOS_ROW pRow = NULL;
|
||||||
|
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||||
|
// int32_t numOfFields = taos_num_fields(pRes);
|
||||||
|
//
|
||||||
|
// char str[512] = {0};
|
||||||
|
// while((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||||
|
// int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||||
|
// printf("%s\n", str);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// taos_free_result(pRes);
|
||||||
|
// taos_close(pConn);
|
||||||
|
//}
|
||||||
|
|
||||||
|
TEST(testCase, create_multiple_tables) {
|
||||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
assert(pConn != NULL);
|
assert(pConn != NULL);
|
||||||
|
|
||||||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||||
taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
|
|
||||||
pRes = taos_query(pConn, "show tables");
|
pRes = taos_query(pConn, "create table t_2 using st1 tags(1) t_3 using st1 tags(2)");
|
||||||
|
if (taos_errno(pRes) != 0) {
|
||||||
|
printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes));
|
||||||
taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
|
ASSERT_TRUE(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
TAOS_ROW pRow = NULL;
|
||||||
|
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||||
|
int32_t numOfFields = taos_num_fields(pRes);
|
||||||
|
|
||||||
|
char str[512] = {0};
|
||||||
|
while((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||||
|
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||||
|
printf("%s\n", str);
|
||||||
|
}
|
||||||
|
|
||||||
|
taos_free_result(pRes);
|
||||||
taos_close(pConn);
|
taos_close(pConn);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,4 +12,6 @@ target_link_libraries(
|
||||||
INTERFACE api
|
INTERFACE api
|
||||||
)
|
)
|
||||||
|
|
||||||
ADD_SUBDIRECTORY(test)
|
if(${BUILD_TEST})
|
||||||
|
ADD_SUBDIRECTORY(test)
|
||||||
|
endif(${BUILD_TEST})
|
||||||
|
|
|
||||||
|
|
@ -15,17 +15,18 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
#include "taoserror.h"
|
#include "taoserror.h"
|
||||||
#include "ulog.h"
|
|
||||||
#include "tlog.h"
|
|
||||||
#include "tconfig.h"
|
|
||||||
#include "tglobal.h"
|
|
||||||
#include "tcompare.h"
|
#include "tcompare.h"
|
||||||
#include "tutil.h"
|
#include "tconfig.h"
|
||||||
#include "ttimezone.h"
|
|
||||||
#include "tlocale.h"
|
|
||||||
#include "tep.h"
|
#include "tep.h"
|
||||||
|
#include "tglobal.h"
|
||||||
|
#include "tlocale.h"
|
||||||
|
#include "tlog.h"
|
||||||
|
#include "ttimezone.h"
|
||||||
|
#include "tutil.h"
|
||||||
|
#include "ulog.h"
|
||||||
|
|
||||||
// cluster
|
// cluster
|
||||||
char tsFirst[TSDB_EP_LEN] = {0};
|
char tsFirst[TSDB_EP_LEN] = {0};
|
||||||
|
|
@ -36,11 +37,12 @@ uint16_t tsServerPort = 6030;
|
||||||
int32_t tsStatusInterval = 1; // second
|
int32_t tsStatusInterval = 1; // second
|
||||||
int8_t tsEnableTelemetryReporting = 0;
|
int8_t tsEnableTelemetryReporting = 0;
|
||||||
char tsEmail[TSDB_FQDN_LEN] = {0};
|
char tsEmail[TSDB_FQDN_LEN] = {0};
|
||||||
|
int32_t tsNumOfSupportVnodes = 16;
|
||||||
|
|
||||||
// common
|
// common
|
||||||
int32_t tsRpcTimer = 300;
|
int32_t tsRpcTimer = 300;
|
||||||
int32_t tsRpcMaxTime = 600; // seconds;
|
int32_t tsRpcMaxTime = 600; // seconds;
|
||||||
int32_t tsRpcForceTcp = 1; //disable this, means query, show command use udp protocol as default
|
int32_t tsRpcForceTcp = 1; // disable this, means query, show command use udp protocol as default
|
||||||
int32_t tsMaxShellConns = 50000;
|
int32_t tsMaxShellConns = 50000;
|
||||||
int32_t tsMaxConnections = 5000;
|
int32_t tsMaxConnections = 5000;
|
||||||
int32_t tsShellActivityTimer = 3; // second
|
int32_t tsShellActivityTimer = 3; // second
|
||||||
|
|
@ -50,8 +52,9 @@ float tsRatioOfQueryCores = 1.0f;
|
||||||
int8_t tsDaylight = 0;
|
int8_t tsDaylight = 0;
|
||||||
int8_t tsEnableCoreFile = 0;
|
int8_t tsEnableCoreFile = 0;
|
||||||
int32_t tsMaxBinaryDisplayWidth = 30;
|
int32_t tsMaxBinaryDisplayWidth = 30;
|
||||||
int64_t tsMaxVnodeQueuedBytes = 1024*1024*1024; //1GB
|
int8_t tsEnableSlaveQuery = 1;
|
||||||
|
int8_t tsEnableAdjustMaster = 1;
|
||||||
|
int8_t tsPrintAuth = 0;
|
||||||
/*
|
/*
|
||||||
* denote if the server needs to compress response message at the application layer to client, including query rsp,
|
* denote if the server needs to compress response message at the application layer to client, including query rsp,
|
||||||
* metricmeta rsp, and multi-meter query rsp message body. The client compress the submit message to server.
|
* metricmeta rsp, and multi-meter query rsp message body. The client compress the submit message to server.
|
||||||
|
|
@ -101,7 +104,7 @@ int32_t tsMaxStreamComputDelay = 20000;
|
||||||
int32_t tsStreamCompStartDelay = 10000;
|
int32_t tsStreamCompStartDelay = 10000;
|
||||||
|
|
||||||
// the stream computing delay time after executing failed, change accordingly
|
// the stream computing delay time after executing failed, change accordingly
|
||||||
int32_t tsRetryStreamCompDelay = 10*1000;
|
int32_t tsRetryStreamCompDelay = 10 * 1000;
|
||||||
|
|
||||||
// The delayed computing ration. 10% of the whole computing time window by default.
|
// The delayed computing ration. 10% of the whole computing time window by default.
|
||||||
float tsStreamComputDelayRatio = 0.1f;
|
float tsStreamComputDelayRatio = 0.1f;
|
||||||
|
|
@ -122,27 +125,13 @@ int32_t tsRetrieveBlockingModel = 0;
|
||||||
// last_row(*), first(*), last_row(ts, col1, col2) query, the result fields will be the original column name
|
// last_row(*), first(*), last_row(ts, col1, col2) query, the result fields will be the original column name
|
||||||
int8_t tsKeepOriginalColumnName = 0;
|
int8_t tsKeepOriginalColumnName = 0;
|
||||||
|
|
||||||
|
// long query death-lock
|
||||||
|
int8_t tsDeadLockKillQuery = 0;
|
||||||
|
|
||||||
// tsdb config
|
// tsdb config
|
||||||
// For backward compatibility
|
// For backward compatibility
|
||||||
bool tsdbForceKeepFile = false;
|
bool tsdbForceKeepFile = false;
|
||||||
|
|
||||||
// balance
|
|
||||||
int8_t tsEnableFlowCtrl = 1;
|
|
||||||
int8_t tsEnableSlaveQuery = 1;
|
|
||||||
int8_t tsEnableAdjustMaster = 1;
|
|
||||||
|
|
||||||
|
|
||||||
// monitor
|
|
||||||
char tsMonitorDbName[TSDB_DB_NAME_LEN] = "log";
|
|
||||||
char tsInternalPass[] = "secretkey";
|
|
||||||
|
|
||||||
// internal
|
|
||||||
int8_t tsCompactMnodeWal = 0;
|
|
||||||
int8_t tsPrintAuth = 0;
|
|
||||||
char tsVnodeDir[PATH_MAX] = {0};
|
|
||||||
char tsDnodeDir[PATH_MAX] = {0};
|
|
||||||
char tsMnodeDir[PATH_MAX] = {0};
|
|
||||||
|
|
||||||
int32_t tsDiskCfgNum = 0;
|
int32_t tsDiskCfgNum = 0;
|
||||||
|
|
||||||
#ifndef _STORAGE
|
#ifndef _STORAGE
|
||||||
|
|
@ -170,21 +159,18 @@ float tsMinimalDataDirGB = 2.0f;
|
||||||
int32_t tsTotalMemoryMB = 0;
|
int32_t tsTotalMemoryMB = 0;
|
||||||
uint32_t tsVersion = 0;
|
uint32_t tsVersion = 0;
|
||||||
|
|
||||||
#ifdef TD_TSZ
|
|
||||||
//
|
//
|
||||||
// lossy compress 6
|
// lossy compress 6
|
||||||
//
|
//
|
||||||
char lossyColumns[32] = ""; // "float|double" means all float and double columns can be lossy compressed. set empty can close lossy compress.
|
char tsLossyColumns[32] = ""; // "float|double" means all float and double columns can be lossy compressed. set empty
|
||||||
|
// can close lossy compress.
|
||||||
// below option can take effect when tsLossyColumns not empty
|
// below option can take effect when tsLossyColumns not empty
|
||||||
double fPrecision = 1E-8; // float column precision
|
double tsFPrecision = 1E-8; // float column precision
|
||||||
double dPrecision = 1E-16; // double column precision
|
double tsDPrecision = 1E-16; // double column precision
|
||||||
uint32_t maxRange = 500; // max range
|
uint32_t tsMaxRange = 500; // max range
|
||||||
uint32_t curRange = 100; // range
|
uint32_t tsCurRange = 100; // range
|
||||||
char Compressor[32] = "ZSTD_COMPRESSOR"; // ZSTD_COMPRESSOR or GZIP_COMPRESSOR
|
char tsCompressor[32] = "ZSTD_COMPRESSOR"; // ZSTD_COMPRESSOR or GZIP_COMPRESSOR
|
||||||
#endif
|
|
||||||
|
|
||||||
// long query death-lock
|
|
||||||
int8_t tsDeadLockKillQuery = 0;
|
|
||||||
|
|
||||||
int32_t (*monStartSystemFp)() = NULL;
|
int32_t (*monStartSystemFp)() = NULL;
|
||||||
void (*monStopSystemFp)() = NULL;
|
void (*monStopSystemFp)() = NULL;
|
||||||
|
|
@ -200,7 +186,6 @@ void taosSetAllDebugFlag() {
|
||||||
dDebugFlag = debugFlag;
|
dDebugFlag = debugFlag;
|
||||||
vDebugFlag = debugFlag;
|
vDebugFlag = debugFlag;
|
||||||
jniDebugFlag = debugFlag;
|
jniDebugFlag = debugFlag;
|
||||||
odbcDebugFlag = debugFlag;
|
|
||||||
qDebugFlag = debugFlag;
|
qDebugFlag = debugFlag;
|
||||||
rpcDebugFlag = debugFlag;
|
rpcDebugFlag = debugFlag;
|
||||||
uDebugFlag = debugFlag;
|
uDebugFlag = debugFlag;
|
||||||
|
|
@ -218,7 +203,7 @@ int32_t taosCfgDynamicOptions(char *msg) {
|
||||||
int32_t vint = 0;
|
int32_t vint = 0;
|
||||||
|
|
||||||
paGetToken(msg, &option, &olen);
|
paGetToken(msg, &option, &olen);
|
||||||
if (olen == 0) return -1;;
|
if (olen == 0) return -1;
|
||||||
|
|
||||||
paGetToken(option + olen + 1, &value, &vlen);
|
paGetToken(option + olen + 1, &value, &vlen);
|
||||||
if (vlen == 0)
|
if (vlen == 0)
|
||||||
|
|
@ -231,7 +216,7 @@ int32_t taosCfgDynamicOptions(char *msg) {
|
||||||
|
|
||||||
for (int32_t i = 0; i < tsGlobalConfigNum; ++i) {
|
for (int32_t i = 0; i < tsGlobalConfigNum; ++i) {
|
||||||
SGlobalCfg *cfg = tsGlobalConfig + i;
|
SGlobalCfg *cfg = tsGlobalConfig + i;
|
||||||
//if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_LOG)) continue;
|
// if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_LOG)) continue;
|
||||||
if (cfg->valType != TAOS_CFG_VTYPE_INT32 && cfg->valType != TAOS_CFG_VTYPE_INT8) continue;
|
if (cfg->valType != TAOS_CFG_VTYPE_INT32 && cfg->valType != TAOS_CFG_VTYPE_INT8) continue;
|
||||||
|
|
||||||
int32_t cfgLen = (int32_t)strlen(cfg->option);
|
int32_t cfgLen = (int32_t)strlen(cfg->option);
|
||||||
|
|
@ -366,6 +351,16 @@ static void doInitGlobalConfig(void) {
|
||||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||||
taosAddConfigOption(cfg);
|
taosAddConfigOption(cfg);
|
||||||
|
|
||||||
|
cfg.option = "supportVnodes";
|
||||||
|
cfg.ptr = &tsNumOfSupportVnodes;
|
||||||
|
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||||
|
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
||||||
|
cfg.minValue = 0;
|
||||||
|
cfg.maxValue = 65536;
|
||||||
|
cfg.ptrLength = 0;
|
||||||
|
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||||
|
taosAddConfigOption(cfg);
|
||||||
|
|
||||||
// directory
|
// directory
|
||||||
cfg.option = "configDir";
|
cfg.option = "configDir";
|
||||||
cfg.ptr = configDir;
|
cfg.ptr = configDir;
|
||||||
|
|
@ -442,8 +437,8 @@ static void doInitGlobalConfig(void) {
|
||||||
cfg.ptr = &tsMaxNumOfDistinctResults;
|
cfg.ptr = &tsMaxNumOfDistinctResults;
|
||||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
|
||||||
cfg.minValue = 10*10000;
|
cfg.minValue = 10 * 10000;
|
||||||
cfg.maxValue = 10000*10000;
|
cfg.maxValue = 10000 * 10000;
|
||||||
cfg.ptrLength = 0;
|
cfg.ptrLength = 0;
|
||||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||||
taosAddConfigOption(cfg);
|
taosAddConfigOption(cfg);
|
||||||
|
|
@ -749,17 +744,6 @@ static void doInitGlobalConfig(void) {
|
||||||
cfg.maxValue = 10000000;
|
cfg.maxValue = 10000000;
|
||||||
cfg.ptrLength = 0;
|
cfg.ptrLength = 0;
|
||||||
cfg.unitType = TAOS_CFG_UTYPE_GB;
|
cfg.unitType = TAOS_CFG_UTYPE_GB;
|
||||||
taosAddConfigOption(cfg);
|
|
||||||
|
|
||||||
// module configs
|
|
||||||
cfg.option = "flowctrl";
|
|
||||||
cfg.ptr = &tsEnableFlowCtrl;
|
|
||||||
cfg.valType = TAOS_CFG_VTYPE_INT8;
|
|
||||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
|
|
||||||
cfg.minValue = 0;
|
|
||||||
cfg.maxValue = 1;
|
|
||||||
cfg.ptrLength = 0;
|
|
||||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
|
||||||
taosAddConfigOption(cfg);
|
taosAddConfigOption(cfg);
|
||||||
|
|
||||||
cfg.option = "slaveQuery";
|
cfg.option = "slaveQuery";
|
||||||
|
|
@ -893,16 +877,6 @@ static void doInitGlobalConfig(void) {
|
||||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||||
taosAddConfigOption(cfg);
|
taosAddConfigOption(cfg);
|
||||||
|
|
||||||
cfg.option = "odbcDebugFlag";
|
|
||||||
cfg.ptr = &odbcDebugFlag;
|
|
||||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
|
||||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT;
|
|
||||||
cfg.minValue = 0;
|
|
||||||
cfg.maxValue = 255;
|
|
||||||
cfg.ptrLength = 0;
|
|
||||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
|
||||||
taosAddConfigOption(cfg);
|
|
||||||
|
|
||||||
cfg.option = "uDebugFlag";
|
cfg.option = "uDebugFlag";
|
||||||
cfg.ptr = &uDebugFlag;
|
cfg.ptr = &uDebugFlag;
|
||||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||||
|
|
@ -1066,7 +1040,6 @@ static void doInitGlobalConfig(void) {
|
||||||
cfg.ptrLength = 0;
|
cfg.ptrLength = 0;
|
||||||
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
cfg.unitType = TAOS_CFG_UTYPE_NONE;
|
||||||
|
|
||||||
|
|
||||||
taosAddConfigOption(cfg);
|
taosAddConfigOption(cfg);
|
||||||
|
|
||||||
cfg.option = "dPrecision";
|
cfg.option = "dPrecision";
|
||||||
|
|
@ -1100,14 +1073,11 @@ static void doInitGlobalConfig(void) {
|
||||||
taosAddConfigOption(cfg);
|
taosAddConfigOption(cfg);
|
||||||
assert(tsGlobalConfigNum == TSDB_CFG_MAX_NUM);
|
assert(tsGlobalConfigNum == TSDB_CFG_MAX_NUM);
|
||||||
#else
|
#else
|
||||||
//assert(tsGlobalConfigNum == TSDB_CFG_MAX_NUM - 5);
|
// assert(tsGlobalConfigNum == TSDB_CFG_MAX_NUM - 5);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosInitGlobalCfg() {
|
void taosInitGlobalCfg() { pthread_once(&tsInitGlobalCfgOnce, doInitGlobalConfig); }
|
||||||
pthread_once(&tsInitGlobalCfgOnce, doInitGlobalConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t taosCheckAndPrintCfg() {
|
int32_t taosCheckAndPrintCfg() {
|
||||||
char fqdn[TSDB_FQDN_LEN];
|
char fqdn[TSDB_FQDN_LEN];
|
||||||
|
|
|
||||||
|
|
@ -26,3 +26,125 @@
|
||||||
#define TD_MSG_DICT_
|
#define TD_MSG_DICT_
|
||||||
#undef TD_MSG_SEG_CODE_
|
#undef TD_MSG_SEG_CODE_
|
||||||
#include "tmsgdef.h"
|
#include "tmsgdef.h"
|
||||||
|
|
||||||
|
int tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) {
|
||||||
|
int tlen = 0;
|
||||||
|
|
||||||
|
tlen += taosEncodeFixedU64(buf, pReq->ver);
|
||||||
|
tlen += taosEncodeString(buf, pReq->name);
|
||||||
|
tlen += taosEncodeFixedU32(buf, pReq->ttl);
|
||||||
|
tlen += taosEncodeFixedU32(buf, pReq->keep);
|
||||||
|
tlen += taosEncodeFixedU8(buf, pReq->type);
|
||||||
|
|
||||||
|
switch (pReq->type) {
|
||||||
|
case TD_SUPER_TABLE:
|
||||||
|
tlen += taosEncodeFixedU64(buf, pReq->stbCfg.suid);
|
||||||
|
tlen += taosEncodeFixedU32(buf, pReq->stbCfg.nCols);
|
||||||
|
for (uint32_t i = 0; i < pReq->stbCfg.nCols; i++) {
|
||||||
|
tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pSchema[i].type);
|
||||||
|
tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pSchema[i].colId);
|
||||||
|
tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pSchema[i].bytes);
|
||||||
|
tlen += taosEncodeString(buf, pReq->stbCfg.pSchema[i].name);
|
||||||
|
}
|
||||||
|
tlen += taosEncodeFixedU32(buf, pReq->stbCfg.nTagCols);
|
||||||
|
for (uint32_t i = 0; i < pReq->stbCfg.nTagCols; i++) {
|
||||||
|
tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pTagSchema[i].type);
|
||||||
|
tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pTagSchema[i].colId);
|
||||||
|
tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pTagSchema[i].bytes);
|
||||||
|
tlen += taosEncodeString(buf, pReq->stbCfg.pTagSchema[i].name);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TD_CHILD_TABLE:
|
||||||
|
tlen += taosEncodeFixedU64(buf, pReq->ctbCfg.suid);
|
||||||
|
tlen += tdEncodeKVRow(buf, pReq->ctbCfg.pTag);
|
||||||
|
break;
|
||||||
|
case TD_NORMAL_TABLE:
|
||||||
|
tlen += taosEncodeFixedU32(buf, pReq->ntbCfg.nCols);
|
||||||
|
for (uint32_t i = 0; i < pReq->ntbCfg.nCols; i++) {
|
||||||
|
tlen += taosEncodeFixedI8(buf, pReq->ntbCfg.pSchema[i].type);
|
||||||
|
tlen += taosEncodeFixedI32(buf, pReq->ntbCfg.pSchema[i].colId);
|
||||||
|
tlen += taosEncodeFixedI32(buf, pReq->ntbCfg.pSchema[i].bytes);
|
||||||
|
tlen += taosEncodeString(buf, pReq->ntbCfg.pSchema[i].name);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tlen;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) {
|
||||||
|
buf = taosDecodeFixedU64(buf, &(pReq->ver));
|
||||||
|
buf = taosDecodeString(buf, &(pReq->name));
|
||||||
|
buf = taosDecodeFixedU32(buf, &(pReq->ttl));
|
||||||
|
buf = taosDecodeFixedU32(buf, &(pReq->keep));
|
||||||
|
buf = taosDecodeFixedU8(buf, &(pReq->type));
|
||||||
|
|
||||||
|
switch (pReq->type) {
|
||||||
|
case TD_SUPER_TABLE:
|
||||||
|
buf = taosDecodeFixedU64(buf, &(pReq->stbCfg.suid));
|
||||||
|
buf = taosDecodeFixedU32(buf, &(pReq->stbCfg.nCols));
|
||||||
|
pReq->stbCfg.pSchema = (SSchema *)malloc(pReq->stbCfg.nCols * sizeof(SSchema));
|
||||||
|
for (uint32_t i = 0; i < pReq->stbCfg.nCols; i++) {
|
||||||
|
buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pSchema[i].type));
|
||||||
|
buf = taosDecodeFixedI32(buf, &(pReq->stbCfg.pSchema[i].colId));
|
||||||
|
buf = taosDecodeFixedI32(buf, &(pReq->stbCfg.pSchema[i].bytes));
|
||||||
|
buf = taosDecodeStringTo(buf, pReq->stbCfg.pSchema[i].name);
|
||||||
|
}
|
||||||
|
buf = taosDecodeFixedU32(buf, &pReq->stbCfg.nTagCols);
|
||||||
|
pReq->stbCfg.pTagSchema = (SSchema *)malloc(pReq->stbCfg.nTagCols * sizeof(SSchema));
|
||||||
|
for (uint32_t i = 0; i < pReq->stbCfg.nTagCols; i++) {
|
||||||
|
buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pTagSchema[i].type));
|
||||||
|
buf = taosDecodeFixedI32(buf, &pReq->stbCfg.pTagSchema[i].colId);
|
||||||
|
buf = taosDecodeFixedI32(buf, &pReq->stbCfg.pTagSchema[i].bytes);
|
||||||
|
buf = taosDecodeStringTo(buf, pReq->stbCfg.pTagSchema[i].name);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TD_CHILD_TABLE:
|
||||||
|
buf = taosDecodeFixedU64(buf, &pReq->ctbCfg.suid);
|
||||||
|
buf = tdDecodeKVRow(buf, &pReq->ctbCfg.pTag);
|
||||||
|
break;
|
||||||
|
case TD_NORMAL_TABLE:
|
||||||
|
buf = taosDecodeFixedU32(buf, &pReq->ntbCfg.nCols);
|
||||||
|
pReq->ntbCfg.pSchema = (SSchema *)malloc(pReq->ntbCfg.nCols * sizeof(SSchema));
|
||||||
|
for (uint32_t i = 0; i < pReq->ntbCfg.nCols; i++) {
|
||||||
|
buf = taosDecodeFixedI8(buf, &pReq->ntbCfg.pSchema[i].type);
|
||||||
|
buf = taosDecodeFixedI32(buf, &pReq->ntbCfg.pSchema[i].colId);
|
||||||
|
buf = taosDecodeFixedI32(buf, &pReq->ntbCfg.pSchema[i].bytes);
|
||||||
|
buf = taosDecodeStringTo(buf, pReq->ntbCfg.pSchema[i].name);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
int tSVCreateTbBatchReqSerialize(void **buf, SVCreateTbBatchReq *pReq) {
|
||||||
|
int tlen = 0;
|
||||||
|
|
||||||
|
tlen += taosEncodeFixedU64(buf, pReq->ver);
|
||||||
|
tlen += taosEncodeFixedU32(buf, taosArrayGetSize(pReq->pArray));
|
||||||
|
for (size_t i = 0; i < taosArrayGetSize(pReq->pArray); i++) {
|
||||||
|
SVCreateTbReq *pCreateTbReq = taosArrayGet(pReq->pArray, i);
|
||||||
|
tlen += tSerializeSVCreateTbReq(buf, pCreateTbReq);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tlen;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *tSVCreateTbBatchReqDeserialize(void *buf, SVCreateTbBatchReq *pReq) {
|
||||||
|
uint32_t nsize = 0;
|
||||||
|
|
||||||
|
buf = taosDecodeFixedU64(buf, &pReq->ver);
|
||||||
|
buf = taosDecodeFixedU32(buf, &nsize);
|
||||||
|
for (size_t i = 0; i < nsize; i++) {
|
||||||
|
SVCreateTbReq req;
|
||||||
|
buf = tDeserializeSVCreateTbReq(buf, &req);
|
||||||
|
taosArrayPush(pReq->pArray, &req);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
@ -259,3 +259,13 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SSchema createSchema(uint8_t type, int32_t bytes, int32_t colId, const char* name) {
|
||||||
|
SSchema s = {0};
|
||||||
|
s.type = type;
|
||||||
|
s.bytes = bytes;
|
||||||
|
s.colId = colId;
|
||||||
|
|
||||||
|
tstrncpy(s.name, name, tListLen(s.name));
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
@ -18,11 +18,11 @@ TARGET_INCLUDE_DIRECTORIES(
|
||||||
)
|
)
|
||||||
|
|
||||||
# tmsg test
|
# tmsg test
|
||||||
add_executable(tmsgTest "")
|
# add_executable(tmsgTest "")
|
||||||
target_sources(tmsgTest
|
# target_sources(tmsgTest
|
||||||
PRIVATE
|
# PRIVATE
|
||||||
"tmsgTest.cpp"
|
# "tmsgTest.cpp"
|
||||||
"../src/tmsg.c"
|
# "../src/tmsg.c"
|
||||||
)
|
# )
|
||||||
target_include_directories(tmsgTest PUBLIC "${CMAKE_SOURCE_DIR}/include/common/")
|
# target_include_directories(tmsgTest PUBLIC "${CMAKE_SOURCE_DIR}/include/common/")
|
||||||
target_link_libraries(tmsgTest PUBLIC os util gtest gtest_main)
|
# target_link_libraries(tmsgTest PUBLIC os util gtest gtest_main)
|
||||||
|
|
@ -139,8 +139,8 @@ void dmnWaitSignal() {
|
||||||
void dmnInitOption(SDnodeOpt *pOption) {
|
void dmnInitOption(SDnodeOpt *pOption) {
|
||||||
pOption->sver = 30000000; //3.0.0.0
|
pOption->sver = 30000000; //3.0.0.0
|
||||||
pOption->numOfCores = tsNumOfCores;
|
pOption->numOfCores = tsNumOfCores;
|
||||||
pOption->numOfSupportVnodes = 16;
|
pOption->numOfSupportVnodes = tsNumOfSupportVnodes;
|
||||||
pOption->numOfCommitThreads = 1;
|
pOption->numOfCommitThreads = tsNumOfCommitThreads;
|
||||||
pOption->statusInterval = tsStatusInterval;
|
pOption->statusInterval = tsStatusInterval;
|
||||||
pOption->numOfThreadsPerCore = tsNumOfThreadsPerCore;
|
pOption->numOfThreadsPerCore = tsNumOfThreadsPerCore;
|
||||||
pOption->ratioOfQueryCores = tsRatioOfQueryCores;
|
pOption->ratioOfQueryCores = tsRatioOfQueryCores;
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ typedef struct {
|
||||||
int32_t maxNum;
|
int32_t maxNum;
|
||||||
void *queueFp;
|
void *queueFp;
|
||||||
SDnode *pDnode;
|
SDnode *pDnode;
|
||||||
taos_queue queue;
|
STaosQueue *queue;
|
||||||
union {
|
union {
|
||||||
SWorkerPool pool;
|
SWorkerPool pool;
|
||||||
SMWorkerPool mpool;
|
SMWorkerPool mpool;
|
||||||
|
|
@ -92,7 +92,7 @@ typedef struct {
|
||||||
SDnodeEps *dnodeEps;
|
SDnodeEps *dnodeEps;
|
||||||
pthread_t *threadId;
|
pthread_t *threadId;
|
||||||
SRWLatch latch;
|
SRWLatch latch;
|
||||||
taos_queue pMgmtQ;
|
STaosQueue *pMgmtQ;
|
||||||
SWorkerPool mgmtPool;
|
SWorkerPool mgmtPool;
|
||||||
} SDnodeMgmt;
|
} SDnodeMgmt;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
#include "dndTransport.h"
|
#include "dndTransport.h"
|
||||||
#include "dndWorker.h"
|
#include "dndWorker.h"
|
||||||
|
|
||||||
static void dndProcessBnodeQueue(SDnode *pDnode, taos_qall qall, int32_t numOfMsgs);
|
static void dndProcessBnodeQueue(SDnode *pDnode, STaosQall *qall, int32_t numOfMsgs);
|
||||||
|
|
||||||
static SBnode *dndAcquireBnode(SDnode *pDnode) {
|
static SBnode *dndAcquireBnode(SDnode *pDnode) {
|
||||||
SBnodeMgmt *pMgmt = &pDnode->bmgmt;
|
SBnodeMgmt *pMgmt = &pDnode->bmgmt;
|
||||||
|
|
@ -256,7 +256,7 @@ static int32_t dndDropBnode(SDnode *pDnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||||
SCreateBnodeInMsg *pMsg = pRpcMsg->pCont;
|
SDCreateBnodeMsg *pMsg = pRpcMsg->pCont;
|
||||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||||
|
|
||||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||||
|
|
@ -268,7 +268,7 @@ int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dndProcessDropBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
int32_t dndProcessDropBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||||
SDropBnodeInMsg *pMsg = pRpcMsg->pCont;
|
SDDropBnodeMsg *pMsg = pRpcMsg->pCont;
|
||||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||||
|
|
||||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||||
|
|
@ -286,7 +286,7 @@ static void dndSendBnodeErrorRsp(SRpcMsg *pMsg, int32_t code) {
|
||||||
taosFreeQitem(pMsg);
|
taosFreeQitem(pMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dndSendBnodeErrorRsps(taos_qall qall, int32_t numOfMsgs, int32_t code) {
|
static void dndSendBnodeErrorRsps(STaosQall *qall, int32_t numOfMsgs, int32_t code) {
|
||||||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
||||||
SRpcMsg *pMsg = NULL;
|
SRpcMsg *pMsg = NULL;
|
||||||
taosGetQitem(qall, (void **)&pMsg);
|
taosGetQitem(qall, (void **)&pMsg);
|
||||||
|
|
@ -294,7 +294,7 @@ static void dndSendBnodeErrorRsps(taos_qall qall, int32_t numOfMsgs, int32_t cod
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dndProcessBnodeQueue(SDnode *pDnode, taos_qall qall, int32_t numOfMsgs) {
|
static void dndProcessBnodeQueue(SDnode *pDnode, STaosQall *qall, int32_t numOfMsgs) {
|
||||||
SBnode *pBnode = dndAcquireBnode(pDnode);
|
SBnode *pBnode = dndAcquireBnode(pDnode);
|
||||||
if (pBnode == NULL) {
|
if (pBnode == NULL) {
|
||||||
dndSendBnodeErrorRsps(qall, numOfMsgs, TSDB_CODE_OUT_OF_MEMORY);
|
dndSendBnodeErrorRsps(qall, numOfMsgs, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,12 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "dndDnode.h"
|
#include "dndDnode.h"
|
||||||
|
#include "dndBnode.h"
|
||||||
|
#include "dndMnode.h"
|
||||||
|
#include "dndQnode.h"
|
||||||
|
#include "dndSnode.h"
|
||||||
#include "dndTransport.h"
|
#include "dndTransport.h"
|
||||||
#include "dndVnodes.h"
|
#include "dndVnodes.h"
|
||||||
#include "dndMnode.h"
|
|
||||||
|
|
||||||
static int32_t dndInitMgmtWorker(SDnode *pDnode);
|
static int32_t dndInitMgmtWorker(SDnode *pDnode);
|
||||||
static void dndCleanupMgmtWorker(SDnode *pDnode);
|
static void dndCleanupMgmtWorker(SDnode *pDnode);
|
||||||
|
|
@ -367,8 +370,8 @@ void dndSendStatusMsg(SDnode *pDnode) {
|
||||||
pStatus->clusterId = htobe64(pMgmt->clusterId);
|
pStatus->clusterId = htobe64(pMgmt->clusterId);
|
||||||
pStatus->rebootTime = htobe64(pMgmt->rebootTime);
|
pStatus->rebootTime = htobe64(pMgmt->rebootTime);
|
||||||
pStatus->updateTime = htobe64(pMgmt->updateTime);
|
pStatus->updateTime = htobe64(pMgmt->updateTime);
|
||||||
pStatus->numOfCores = htons(pDnode->opt.numOfCores);
|
pStatus->numOfCores = htonl(pDnode->opt.numOfCores);
|
||||||
pStatus->numOfSupportVnodes = htons(pDnode->opt.numOfSupportVnodes);
|
pStatus->numOfSupportVnodes = htonl(pDnode->opt.numOfSupportVnodes);
|
||||||
tstrncpy(pStatus->dnodeEp, pDnode->opt.localEp, TSDB_EP_LEN);
|
tstrncpy(pStatus->dnodeEp, pDnode->opt.localEp, TSDB_EP_LEN);
|
||||||
|
|
||||||
pStatus->clusterCfg.statusInterval = htonl(pDnode->opt.statusInterval);
|
pStatus->clusterCfg.statusInterval = htonl(pDnode->opt.statusInterval);
|
||||||
|
|
@ -394,7 +397,7 @@ void dndSendStatusMsg(SDnode *pDnode) {
|
||||||
static void dndUpdateDnodeCfg(SDnode *pDnode, SDnodeCfg *pCfg) {
|
static void dndUpdateDnodeCfg(SDnode *pDnode, SDnodeCfg *pCfg) {
|
||||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||||
if (pMgmt->dnodeId == 0) {
|
if (pMgmt->dnodeId == 0) {
|
||||||
dInfo("set dnodeId:%d clusterId:% " PRId64, pCfg->dnodeId, pCfg->clusterId);
|
dInfo("set dnodeId:%d clusterId:%" PRId64, pCfg->dnodeId, pCfg->clusterId);
|
||||||
taosWLockLatch(&pMgmt->latch);
|
taosWLockLatch(&pMgmt->latch);
|
||||||
pMgmt->dnodeId = pCfg->dnodeId;
|
pMgmt->dnodeId = pCfg->dnodeId;
|
||||||
pMgmt->clusterId = pCfg->clusterId;
|
pMgmt->clusterId = pCfg->clusterId;
|
||||||
|
|
@ -437,6 +440,7 @@ static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SStatusRsp *pRsp = pMsg->pCont;
|
SStatusRsp *pRsp = pMsg->pCont;
|
||||||
|
if (pMsg->pCont != NULL && pMsg->contLen != 0) {
|
||||||
SDnodeCfg *pCfg = &pRsp->dnodeCfg;
|
SDnodeCfg *pCfg = &pRsp->dnodeCfg;
|
||||||
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
||||||
pCfg->clusterId = htobe64(pCfg->clusterId);
|
pCfg->clusterId = htobe64(pCfg->clusterId);
|
||||||
|
|
@ -450,6 +454,7 @@ static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
dndUpdateDnodeEps(pDnode, pDnodeEps);
|
dndUpdateDnodeEps(pDnode, pDnodeEps);
|
||||||
|
}
|
||||||
pMgmt->statusSent = 0;
|
pMgmt->statusSent = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -648,6 +653,24 @@ static void dndProcessMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||||
case TDMT_DND_DROP_MNODE:
|
case TDMT_DND_DROP_MNODE:
|
||||||
code = dndProcessDropMnodeReq(pDnode, pMsg);
|
code = dndProcessDropMnodeReq(pDnode, pMsg);
|
||||||
break;
|
break;
|
||||||
|
case TDMT_DND_CREATE_QNODE:
|
||||||
|
code = dndProcessCreateQnodeReq(pDnode, pMsg);
|
||||||
|
break;
|
||||||
|
case TDMT_DND_DROP_QNODE:
|
||||||
|
code = dndProcessDropQnodeReq(pDnode, pMsg);
|
||||||
|
break;
|
||||||
|
case TDMT_DND_CREATE_SNODE:
|
||||||
|
code = dndProcessCreateSnodeReq(pDnode, pMsg);
|
||||||
|
break;
|
||||||
|
case TDMT_DND_DROP_SNODE:
|
||||||
|
code = dndProcessDropSnodeReq(pDnode, pMsg);
|
||||||
|
break;
|
||||||
|
case TDMT_DND_CREATE_BNODE:
|
||||||
|
code = dndProcessCreateBnodeReq(pDnode, pMsg);
|
||||||
|
break;
|
||||||
|
case TDMT_DND_DROP_BNODE:
|
||||||
|
code = dndProcessDropBnodeReq(pDnode, pMsg);
|
||||||
|
break;
|
||||||
case TDMT_DND_CONFIG_DNODE:
|
case TDMT_DND_CONFIG_DNODE:
|
||||||
code = dndProcessConfigDnodeReq(pDnode, pMsg);
|
code = dndProcessConfigDnodeReq(pDnode, pMsg);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -299,7 +299,7 @@ static void dndBuildMnodeOpenOption(SDnode *pDnode, SMnodeOpt *pOption) {
|
||||||
memcpy(&pOption->replicas, pMgmt->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA);
|
memcpy(&pOption->replicas, pMgmt->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dndBuildMnodeOptionFromMsg(SDnode *pDnode, SMnodeOpt *pOption, SCreateMnodeInMsg *pMsg) {
|
static int32_t dndBuildMnodeOptionFromMsg(SDnode *pDnode, SMnodeOpt *pOption, SDCreateMnodeMsg *pMsg) {
|
||||||
dndInitMnodeOption(pDnode, pOption);
|
dndInitMnodeOption(pDnode, pOption);
|
||||||
pOption->dnodeId = dndGetDnodeId(pDnode);
|
pOption->dnodeId = dndGetDnodeId(pDnode);
|
||||||
pOption->clusterId = dndGetClusterId(pDnode);
|
pOption->clusterId = dndGetClusterId(pDnode);
|
||||||
|
|
@ -417,8 +417,8 @@ static int32_t dndDropMnode(SDnode *pDnode) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SCreateMnodeInMsg *dndParseCreateMnodeMsg(SRpcMsg *pRpcMsg) {
|
static SDCreateMnodeMsg *dndParseCreateMnodeMsg(SRpcMsg *pRpcMsg) {
|
||||||
SCreateMnodeInMsg *pMsg = pRpcMsg->pCont;
|
SDCreateMnodeMsg *pMsg = pRpcMsg->pCont;
|
||||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||||
for (int32_t i = 0; i < pMsg->replica; ++i) {
|
for (int32_t i = 0; i < pMsg->replica; ++i) {
|
||||||
pMsg->replicas[i].id = htonl(pMsg->replicas[i].id);
|
pMsg->replicas[i].id = htonl(pMsg->replicas[i].id);
|
||||||
|
|
@ -429,7 +429,7 @@ static SCreateMnodeInMsg *dndParseCreateMnodeMsg(SRpcMsg *pRpcMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||||
SCreateMnodeInMsg *pMsg = dndParseCreateMnodeMsg(pRpcMsg);
|
SDCreateMnodeMsg *pMsg = dndParseCreateMnodeMsg(pRpcMsg);
|
||||||
|
|
||||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||||
terrno = TSDB_CODE_DND_MNODE_ID_INVALID;
|
terrno = TSDB_CODE_DND_MNODE_ID_INVALID;
|
||||||
|
|
@ -445,7 +445,7 @@ int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dndProcessAlterMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
int32_t dndProcessAlterMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||||
SAlterMnodeInMsg *pMsg = dndParseCreateMnodeMsg(pRpcMsg);
|
SDAlterMnodeMsg *pMsg = dndParseCreateMnodeMsg(pRpcMsg);
|
||||||
|
|
||||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||||
terrno = TSDB_CODE_DND_MNODE_ID_INVALID;
|
terrno = TSDB_CODE_DND_MNODE_ID_INVALID;
|
||||||
|
|
@ -465,7 +465,7 @@ int32_t dndProcessAlterMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dndProcessDropMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
int32_t dndProcessDropMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||||
SDropMnodeInMsg *pMsg = pRpcMsg->pCont;
|
SDDropMnodeMsg *pMsg = pRpcMsg->pCont;
|
||||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||||
|
|
||||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||||
|
|
|
||||||
|
|
@ -261,7 +261,7 @@ static int32_t dndDropQnode(SDnode *pDnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||||
SCreateQnodeInMsg *pMsg = pRpcMsg->pCont;
|
SDCreateQnodeMsg *pMsg = pRpcMsg->pCont;
|
||||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||||
|
|
||||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||||
|
|
@ -273,7 +273,7 @@ int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dndProcessDropQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
int32_t dndProcessDropQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||||
SDropQnodeInMsg *pMsg = pRpcMsg->pCont;
|
SDDropQnodeMsg *pMsg = pRpcMsg->pCont;
|
||||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||||
|
|
||||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||||
|
|
|
||||||
|
|
@ -256,7 +256,7 @@ static int32_t dndDropSnode(SDnode *pDnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||||
SCreateSnodeInMsg *pMsg = pRpcMsg->pCont;
|
SDCreateSnodeMsg *pMsg = pRpcMsg->pCont;
|
||||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||||
|
|
||||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||||
|
|
@ -268,7 +268,7 @@ int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dndProcessDropSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
int32_t dndProcessDropSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||||
SDropSnodeInMsg *pMsg = pRpcMsg->pCont;
|
SDDropSnodeMsg *pMsg = pRpcMsg->pCont;
|
||||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||||
|
|
||||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,18 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_ALTER_MNODE_RSP)] = dndProcessMnodeWriteMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_ALTER_MNODE_RSP)] = dndProcessMnodeWriteMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_MNODE)] = dndProcessMgmtMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_MNODE)] = dndProcessMgmtMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_MNODE_RSP)] = dndProcessMnodeWriteMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_MNODE_RSP)] = dndProcessMnodeWriteMsg;
|
||||||
|
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_QNODE)] = dndProcessMgmtMsg;
|
||||||
|
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_QNODE_RSP)] = dndProcessMnodeWriteMsg;
|
||||||
|
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_QNODE)] = dndProcessMgmtMsg;
|
||||||
|
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_QNODE_RSP)] = dndProcessMnodeWriteMsg;
|
||||||
|
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_SNODE)] = dndProcessMgmtMsg;
|
||||||
|
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_SNODE_RSP)] = dndProcessMnodeWriteMsg;
|
||||||
|
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_SNODE)] = dndProcessMgmtMsg;
|
||||||
|
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_SNODE_RSP)] = dndProcessMnodeWriteMsg;
|
||||||
|
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_BNODE)] = dndProcessMgmtMsg;
|
||||||
|
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_BNODE_RSP)] = dndProcessMnodeWriteMsg;
|
||||||
|
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_BNODE)] = dndProcessMgmtMsg;
|
||||||
|
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_DROP_BNODE_RSP)] = dndProcessMnodeWriteMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_VNODE)] = dndProcessMgmtMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_VNODE)] = dndProcessMgmtMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_VNODE_RSP)] = dndProcessMnodeWriteMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_CREATE_VNODE_RSP)] = dndProcessMnodeWriteMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_ALTER_VNODE)] = dndProcessMgmtMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_DND_ALTER_VNODE)] = dndProcessMgmtMsg;
|
||||||
|
|
@ -66,6 +78,12 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_DNODE)] = dndProcessMnodeWriteMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_DNODE)] = dndProcessMnodeWriteMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_MNODE)] = dndProcessMnodeWriteMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_MNODE)] = dndProcessMnodeWriteMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_MNODE)] = dndProcessMnodeWriteMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_MNODE)] = dndProcessMnodeWriteMsg;
|
||||||
|
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_QNODE)] = dndProcessMnodeWriteMsg;
|
||||||
|
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_QNODE)] = dndProcessMnodeWriteMsg;
|
||||||
|
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_SNODE)] = dndProcessMnodeWriteMsg;
|
||||||
|
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_SNODE)] = dndProcessMnodeWriteMsg;
|
||||||
|
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_BNODE)] = dndProcessMnodeWriteMsg;
|
||||||
|
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_BNODE)] = dndProcessMnodeWriteMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_DB)] = dndProcessMnodeWriteMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_CREATE_DB)] = dndProcessMnodeWriteMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_DB)] = dndProcessMnodeWriteMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_DROP_DB)] = dndProcessMnodeWriteMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_USE_DB)] = dndProcessMnodeWriteMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_USE_DB)] = dndProcessMnodeWriteMsg;
|
||||||
|
|
@ -85,7 +103,7 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_HEARTBEAT)] = dndProcessMnodeReadMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_HEARTBEAT)] = dndProcessMnodeReadMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_SHOW)] = dndProcessMnodeReadMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_SHOW)] = dndProcessMnodeReadMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_SHOW_RETRIEVE)] = dndProcessMnodeReadMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_SHOW_RETRIEVE)] = dndProcessMnodeReadMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_STATUS)] = dndProcessMnodeWriteMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_STATUS)] = dndProcessMnodeReadMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_STATUS_RSP)] = dndProcessMgmtMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_STATUS_RSP)] = dndProcessMgmtMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_TRANS)] = dndProcessMnodeWriteMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_TRANS)] = dndProcessMnodeWriteMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_TRANS_RSP)] = dndProcessMnodeWriteMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_TRANS_RSP)] = dndProcessMnodeWriteMsg;
|
||||||
|
|
@ -103,8 +121,8 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_FETCH)] = dndProcessVnodeFetchMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_FETCH)] = dndProcessVnodeFetchMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_ALTER_TABLE)] = dndProcessVnodeWriteMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_ALTER_TABLE)] = dndProcessVnodeWriteMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_UPDATE_TAG_VAL)] = dndProcessVnodeWriteMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_UPDATE_TAG_VAL)] = dndProcessVnodeWriteMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_TABLE_META)] = dndProcessVnodeQueryMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_TABLE_META)] = dndProcessVnodeFetchMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_TABLES_META)] = dndProcessVnodeQueryMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_TABLES_META)] = dndProcessVnodeFetchMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_CONSUME)] = dndProcessVnodeQueryMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_CONSUME)] = dndProcessVnodeQueryMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_QUERY)] = dndProcessVnodeQueryMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_QUERY)] = dndProcessVnodeQueryMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_CONNECT)] = dndProcessVnodeWriteMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_MQ_CONNECT)] = dndProcessVnodeWriteMsg;
|
||||||
|
|
@ -123,6 +141,8 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_CREATE_TABLE)] = dndProcessVnodeWriteMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_CREATE_TABLE)] = dndProcessVnodeWriteMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_ALTER_TABLE)] = dndProcessVnodeWriteMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_ALTER_TABLE)] = dndProcessVnodeWriteMsg;
|
||||||
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_DROP_TABLE)] = dndProcessVnodeWriteMsg;
|
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_DROP_TABLE)] = dndProcessVnodeWriteMsg;
|
||||||
|
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_SHOW_TABLES)] = dndProcessVnodeFetchMsg;
|
||||||
|
pMgmt->msgFp[TMSG_INDEX(TDMT_VND_SHOW_TABLES_FETCH)] = dndProcessVnodeFetchMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dndProcessResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
static void dndProcessResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||||
|
|
@ -365,6 +385,7 @@ void dndCleanupTrans(SDnode *pDnode) {
|
||||||
|
|
||||||
void dndSendMsgToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pMsg) {
|
void dndSendMsgToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||||
STransMgmt *pMgmt = &pDnode->tmgmt;
|
STransMgmt *pMgmt = &pDnode->tmgmt;
|
||||||
|
if (pMgmt->clientRpc == NULL) return;
|
||||||
rpcSendRequest(pMgmt->clientRpc, pEpSet, pMsg, NULL);
|
rpcSendRequest(pMgmt->clientRpc, pEpSet, pMsg, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,11 +36,11 @@ typedef struct {
|
||||||
char *db;
|
char *db;
|
||||||
char *path;
|
char *path;
|
||||||
SVnode *pImpl;
|
SVnode *pImpl;
|
||||||
taos_queue pWriteQ;
|
STaosQueue *pWriteQ;
|
||||||
taos_queue pSyncQ;
|
STaosQueue *pSyncQ;
|
||||||
taos_queue pApplyQ;
|
STaosQueue *pApplyQ;
|
||||||
taos_queue pQueryQ;
|
STaosQueue *pQueryQ;
|
||||||
taos_queue pFetchQ;
|
STaosQueue* pFetchQ;
|
||||||
} SVnodeObj;
|
} SVnodeObj;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
@ -72,9 +72,9 @@ static void dndFreeVnodeSyncQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||||
|
|
||||||
static void dndProcessVnodeQueryQueue(SVnodeObj *pVnode, SRpcMsg *pMsg);
|
static void dndProcessVnodeQueryQueue(SVnodeObj *pVnode, SRpcMsg *pMsg);
|
||||||
static void dndProcessVnodeFetchQueue(SVnodeObj *pVnode, SRpcMsg *pMsg);
|
static void dndProcessVnodeFetchQueue(SVnodeObj *pVnode, SRpcMsg *pMsg);
|
||||||
static void dndProcessVnodeWriteQueue(SVnodeObj *pVnode, taos_qall qall, int32_t numOfMsgs);
|
static void dndProcessVnodeWriteQueue(SVnodeObj *pVnode, STaosQall *qall, int32_t numOfMsgs);
|
||||||
static void dndProcessVnodeApplyQueue(SVnodeObj *pVnode, taos_qall qall, int32_t numOfMsgs);
|
static void dndProcessVnodeApplyQueue(SVnodeObj *pVnode, STaosQall *qall, int32_t numOfMsgs);
|
||||||
static void dndProcessVnodeSyncQueue(SVnodeObj *pVnode, taos_qall qall, int32_t numOfMsgs);
|
static void dndProcessVnodeSyncQueue(SVnodeObj *pVnode, STaosQall *qall, int32_t numOfMsgs);
|
||||||
void dndProcessVnodeQueryMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
void dndProcessVnodeQueryMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||||
void dndProcessVnodeFetchMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
void dndProcessVnodeFetchMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||||
void dndProcessVnodeWriteMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
void dndProcessVnodeWriteMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||||
|
|
@ -768,7 +768,7 @@ static void dndProcessVnodeFetchQueue(SVnodeObj *pVnode, SRpcMsg *pMsg) {
|
||||||
vnodeProcessFetchReq(pVnode->pImpl, pMsg, &pRsp);
|
vnodeProcessFetchReq(pVnode->pImpl, pMsg, &pRsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dndProcessVnodeWriteQueue(SVnodeObj *pVnode, taos_qall qall, int32_t numOfMsgs) {
|
static void dndProcessVnodeWriteQueue(SVnodeObj *pVnode, STaosQall *qall, int32_t numOfMsgs) {
|
||||||
SArray *pArray = taosArrayInit(numOfMsgs, sizeof(SRpcMsg *));
|
SArray *pArray = taosArrayInit(numOfMsgs, sizeof(SRpcMsg *));
|
||||||
|
|
||||||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
||||||
|
|
@ -804,7 +804,7 @@ static void dndProcessVnodeWriteQueue(SVnodeObj *pVnode, taos_qall qall, int32_t
|
||||||
taosArrayDestroy(pArray);
|
taosArrayDestroy(pArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dndProcessVnodeApplyQueue(SVnodeObj *pVnode, taos_qall qall, int32_t numOfMsgs) {
|
static void dndProcessVnodeApplyQueue(SVnodeObj *pVnode, STaosQall *qall, int32_t numOfMsgs) {
|
||||||
SRpcMsg *pMsg = NULL;
|
SRpcMsg *pMsg = NULL;
|
||||||
|
|
||||||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
||||||
|
|
@ -815,7 +815,7 @@ static void dndProcessVnodeApplyQueue(SVnodeObj *pVnode, taos_qall qall, int32_t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dndProcessVnodeSyncQueue(SVnodeObj *pVnode, taos_qall qall, int32_t numOfMsgs) {
|
static void dndProcessVnodeSyncQueue(SVnodeObj *pVnode, STaosQall *qall, int32_t numOfMsgs) {
|
||||||
SRpcMsg *pMsg = NULL;
|
SRpcMsg *pMsg = NULL;
|
||||||
|
|
||||||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
||||||
|
|
@ -826,7 +826,7 @@ static void dndProcessVnodeSyncQueue(SVnodeObj *pVnode, taos_qall qall, int32_t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dndWriteRpcMsgToVnodeQueue(taos_queue pQueue, SRpcMsg *pRpcMsg) {
|
static int32_t dndWriteRpcMsgToVnodeQueue(STaosQueue *pQueue, SRpcMsg *pRpcMsg) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
if (pQueue == NULL) {
|
if (pQueue == NULL) {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,9 @@ add_subdirectory(db)
|
||||||
add_subdirectory(dnode)
|
add_subdirectory(dnode)
|
||||||
# add_subdirectory(func)
|
# add_subdirectory(func)
|
||||||
add_subdirectory(mnode)
|
add_subdirectory(mnode)
|
||||||
|
add_subdirectory(qnode)
|
||||||
|
add_subdirectory(snode)
|
||||||
|
add_subdirectory(bnode)
|
||||||
add_subdirectory(profile)
|
add_subdirectory(profile)
|
||||||
add_subdirectory(show)
|
add_subdirectory(show)
|
||||||
add_subdirectory(stb)
|
add_subdirectory(stb)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
aux_source_directory(. STEST_SRC)
|
||||||
|
add_executable(dnode_test_bnode ${STEST_SRC})
|
||||||
|
target_link_libraries(
|
||||||
|
dnode_test_bnode
|
||||||
|
PUBLIC sut
|
||||||
|
)
|
||||||
|
|
||||||
|
add_test(
|
||||||
|
NAME dnode_test_bnode
|
||||||
|
COMMAND dnode_test_bnode
|
||||||
|
)
|
||||||
|
|
@ -0,0 +1,154 @@
|
||||||
|
/**
|
||||||
|
* @file dnode.cpp
|
||||||
|
* @author slguan (slguan@taosdata.com)
|
||||||
|
* @brief DNODE module dnode-msg tests
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2021-12-15
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "base.h"
|
||||||
|
|
||||||
|
class DndTestBnode : public ::testing::Test {
|
||||||
|
public:
|
||||||
|
void SetUp() override {}
|
||||||
|
void TearDown() override {}
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void SetUpTestSuite() {
|
||||||
|
test.Init("/tmp/dnode_test_bnode1", 9068);
|
||||||
|
const char* fqdn = "localhost";
|
||||||
|
const char* firstEp = "localhost:9068";
|
||||||
|
|
||||||
|
server2.Start("/tmp/dnode_test_bnode2", fqdn, 9069, firstEp);
|
||||||
|
taosMsleep(300);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TearDownTestSuite() {
|
||||||
|
server2.Stop();
|
||||||
|
test.Cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
static Testbase test;
|
||||||
|
static TestServer server2;
|
||||||
|
};
|
||||||
|
|
||||||
|
Testbase DndTestBnode::test;
|
||||||
|
TestServer DndTestBnode::server2;
|
||||||
|
|
||||||
|
TEST_F(DndTestBnode, 01_ShowBnode) {
|
||||||
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, "");
|
||||||
|
CHECK_META("show bnodes", 3);
|
||||||
|
|
||||||
|
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||||
|
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
||||||
|
CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||||
|
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DndTestBnode, 02_Create_Bnode_Invalid_Id) {
|
||||||
|
{
|
||||||
|
int32_t contLen = sizeof(SMCreateBnodeMsg);
|
||||||
|
|
||||||
|
SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen);
|
||||||
|
pReq->dnodeId = htonl(1);
|
||||||
|
|
||||||
|
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen);
|
||||||
|
ASSERT_NE(pMsg, nullptr);
|
||||||
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
|
|
||||||
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, "");
|
||||||
|
CHECK_META("show bnodes", 3);
|
||||||
|
|
||||||
|
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||||
|
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
||||||
|
CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||||
|
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 1);
|
||||||
|
|
||||||
|
CheckInt16(1);
|
||||||
|
CheckBinary("localhost:9068", TSDB_EP_LEN);
|
||||||
|
CheckTimestamp();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DndTestBnode, 03_Create_Bnode_Invalid_Id) {
|
||||||
|
{
|
||||||
|
int32_t contLen = sizeof(SMCreateBnodeMsg);
|
||||||
|
|
||||||
|
SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen);
|
||||||
|
pReq->dnodeId = htonl(2);
|
||||||
|
|
||||||
|
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen);
|
||||||
|
ASSERT_NE(pMsg, nullptr);
|
||||||
|
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DndTestBnode, 04_Create_Bnode) {
|
||||||
|
{
|
||||||
|
// create dnode
|
||||||
|
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||||
|
|
||||||
|
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||||
|
strcpy(pReq->fqdn, "localhost");
|
||||||
|
pReq->port = htonl(9069);
|
||||||
|
|
||||||
|
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||||
|
ASSERT_NE(pMsg, nullptr);
|
||||||
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
|
|
||||||
|
taosMsleep(1300);
|
||||||
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// create bnode
|
||||||
|
int32_t contLen = sizeof(SMCreateBnodeMsg);
|
||||||
|
|
||||||
|
SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen);
|
||||||
|
pReq->dnodeId = htonl(2);
|
||||||
|
|
||||||
|
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen);
|
||||||
|
ASSERT_NE(pMsg, nullptr);
|
||||||
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
|
|
||||||
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, "");
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 2);
|
||||||
|
|
||||||
|
CheckInt16(1);
|
||||||
|
CheckInt16(2);
|
||||||
|
CheckBinary("localhost:9068", TSDB_EP_LEN);
|
||||||
|
CheckBinary("localhost:9069", TSDB_EP_LEN);
|
||||||
|
CheckTimestamp();
|
||||||
|
CheckTimestamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// drop bnode
|
||||||
|
int32_t contLen = sizeof(SMDropBnodeMsg);
|
||||||
|
|
||||||
|
SMDropBnodeMsg* pReq = (SMDropBnodeMsg*)rpcMallocCont(contLen);
|
||||||
|
pReq->dnodeId = htonl(2);
|
||||||
|
|
||||||
|
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_BNODE, pReq, contLen);
|
||||||
|
ASSERT_NE(pMsg, nullptr);
|
||||||
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
|
|
||||||
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, "");
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 1);
|
||||||
|
|
||||||
|
CheckInt16(1);
|
||||||
|
CheckBinary("localhost:9068", TSDB_EP_LEN);
|
||||||
|
CheckTimestamp();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -57,7 +57,7 @@ TEST_F(DndTestDnode, 01_ShowDnode) {
|
||||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
||||||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_SMALLINT, 2, "vnodes");
|
CHECK_SCHEMA(2, TSDB_DATA_TYPE_SMALLINT, 2, "vnodes");
|
||||||
CHECK_SCHEMA(3, TSDB_DATA_TYPE_SMALLINT, 2, "max_vnodes");
|
CHECK_SCHEMA(3, TSDB_DATA_TYPE_SMALLINT, 2, "support_vnodes");
|
||||||
CHECK_SCHEMA(4, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "status");
|
CHECK_SCHEMA(4, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "status");
|
||||||
CHECK_SCHEMA(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
CHECK_SCHEMA(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||||
CHECK_SCHEMA(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "offline_reason");
|
CHECK_SCHEMA(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "offline_reason");
|
||||||
|
|
@ -68,7 +68,7 @@ TEST_F(DndTestDnode, 01_ShowDnode) {
|
||||||
CheckInt16(1);
|
CheckInt16(1);
|
||||||
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
||||||
CheckInt16(0);
|
CheckInt16(0);
|
||||||
CheckInt16(1);
|
CheckInt16(16);
|
||||||
CheckBinary("ready", 10);
|
CheckBinary("ready", 10);
|
||||||
CheckTimestamp();
|
CheckTimestamp();
|
||||||
CheckBinary("", 24);
|
CheckBinary("", 24);
|
||||||
|
|
@ -112,8 +112,8 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
|
||||||
CheckBinary("localhost:9042", TSDB_EP_LEN);
|
CheckBinary("localhost:9042", TSDB_EP_LEN);
|
||||||
CheckInt16(0);
|
CheckInt16(0);
|
||||||
CheckInt16(0);
|
CheckInt16(0);
|
||||||
CheckInt16(1);
|
CheckInt16(16);
|
||||||
CheckInt16(1);
|
CheckInt16(16);
|
||||||
CheckBinary("ready", 10);
|
CheckBinary("ready", 10);
|
||||||
CheckBinary("ready", 10);
|
CheckBinary("ready", 10);
|
||||||
CheckTimestamp();
|
CheckTimestamp();
|
||||||
|
|
@ -140,7 +140,7 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
|
||||||
CheckInt16(1);
|
CheckInt16(1);
|
||||||
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
||||||
CheckInt16(0);
|
CheckInt16(0);
|
||||||
CheckInt16(1);
|
CheckInt16(16);
|
||||||
CheckBinary("ready", 10);
|
CheckBinary("ready", 10);
|
||||||
CheckTimestamp();
|
CheckTimestamp();
|
||||||
CheckBinary("", 24);
|
CheckBinary("", 24);
|
||||||
|
|
@ -199,10 +199,10 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
|
||||||
CheckInt16(0);
|
CheckInt16(0);
|
||||||
CheckInt16(0);
|
CheckInt16(0);
|
||||||
CheckInt16(0);
|
CheckInt16(0);
|
||||||
CheckInt16(1);
|
CheckInt16(16);
|
||||||
CheckInt16(1);
|
CheckInt16(16);
|
||||||
CheckInt16(1);
|
CheckInt16(16);
|
||||||
CheckInt16(1);
|
CheckInt16(16);
|
||||||
CheckBinary("ready", 10);
|
CheckBinary("ready", 10);
|
||||||
CheckBinary("ready", 10);
|
CheckBinary("ready", 10);
|
||||||
CheckBinary("ready", 10);
|
CheckBinary("ready", 10);
|
||||||
|
|
@ -242,10 +242,10 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
|
||||||
CheckInt16(0);
|
CheckInt16(0);
|
||||||
CheckInt16(0);
|
CheckInt16(0);
|
||||||
CheckInt16(0);
|
CheckInt16(0);
|
||||||
CheckInt16(1);
|
CheckInt16(16);
|
||||||
CheckInt16(1);
|
CheckInt16(16);
|
||||||
CheckInt16(1);
|
CheckInt16(16);
|
||||||
CheckInt16(1);
|
CheckInt16(16);
|
||||||
CheckBinary("ready", 10);
|
CheckBinary("ready", 10);
|
||||||
CheckBinary("ready", 10);
|
CheckBinary("ready", 10);
|
||||||
CheckBinary("ready", 10);
|
CheckBinary("ready", 10);
|
||||||
|
|
|
||||||
|
|
@ -72,9 +72,9 @@ TEST_F(DndTestMnode, 01_ShowDnode) {
|
||||||
|
|
||||||
TEST_F(DndTestMnode, 02_Create_Mnode_Invalid_Id) {
|
TEST_F(DndTestMnode, 02_Create_Mnode_Invalid_Id) {
|
||||||
{
|
{
|
||||||
int32_t contLen = sizeof(SCreateMnodeMsg);
|
int32_t contLen = sizeof(SMCreateMnodeMsg);
|
||||||
|
|
||||||
SCreateMnodeMsg* pReq = (SCreateMnodeMsg*)rpcMallocCont(contLen);
|
SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen);
|
||||||
pReq->dnodeId = htonl(1);
|
pReq->dnodeId = htonl(1);
|
||||||
|
|
||||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||||
|
|
@ -85,9 +85,9 @@ TEST_F(DndTestMnode, 02_Create_Mnode_Invalid_Id) {
|
||||||
|
|
||||||
TEST_F(DndTestMnode, 03_Create_Mnode_Invalid_Id) {
|
TEST_F(DndTestMnode, 03_Create_Mnode_Invalid_Id) {
|
||||||
{
|
{
|
||||||
int32_t contLen = sizeof(SCreateMnodeMsg);
|
int32_t contLen = sizeof(SMCreateMnodeMsg);
|
||||||
|
|
||||||
SCreateMnodeMsg* pReq = (SCreateMnodeMsg*)rpcMallocCont(contLen);
|
SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen);
|
||||||
pReq->dnodeId = htonl(2);
|
pReq->dnodeId = htonl(2);
|
||||||
|
|
||||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||||
|
|
@ -117,9 +117,9 @@ TEST_F(DndTestMnode, 04_Create_Mnode) {
|
||||||
|
|
||||||
{
|
{
|
||||||
// create mnode
|
// create mnode
|
||||||
int32_t contLen = sizeof(SCreateMnodeMsg);
|
int32_t contLen = sizeof(SMCreateMnodeMsg);
|
||||||
|
|
||||||
SCreateMnodeMsg* pReq = (SCreateMnodeMsg*)rpcMallocCont(contLen);
|
SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen);
|
||||||
pReq->dnodeId = htonl(2);
|
pReq->dnodeId = htonl(2);
|
||||||
|
|
||||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||||
|
|
@ -144,9 +144,9 @@ TEST_F(DndTestMnode, 04_Create_Mnode) {
|
||||||
|
|
||||||
{
|
{
|
||||||
// drop mnode
|
// drop mnode
|
||||||
int32_t contLen = sizeof(SDropMnodeMsg);
|
int32_t contLen = sizeof(SMDropMnodeMsg);
|
||||||
|
|
||||||
SDropMnodeMsg* pReq = (SDropMnodeMsg*)rpcMallocCont(contLen);
|
SMDropMnodeMsg* pReq = (SMDropMnodeMsg*)rpcMallocCont(contLen);
|
||||||
pReq->dnodeId = htonl(2);
|
pReq->dnodeId = htonl(2);
|
||||||
|
|
||||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_MNODE, pReq, contLen);
|
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_MNODE, pReq, contLen);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
aux_source_directory(. QTEST_SRC)
|
||||||
|
add_executable(dnode_test_qnode ${QTEST_SRC})
|
||||||
|
target_link_libraries(
|
||||||
|
dnode_test_qnode
|
||||||
|
PUBLIC sut
|
||||||
|
)
|
||||||
|
|
||||||
|
add_test(
|
||||||
|
NAME dnode_test_qnode
|
||||||
|
COMMAND dnode_test_qnode
|
||||||
|
)
|
||||||
|
|
@ -0,0 +1,154 @@
|
||||||
|
/**
|
||||||
|
* @file dnode.cpp
|
||||||
|
* @author slguan (slguan@taosdata.com)
|
||||||
|
* @brief DNODE module dnode-msg tests
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2021-12-15
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "base.h"
|
||||||
|
|
||||||
|
class DndTestQnode : public ::testing::Test {
|
||||||
|
public:
|
||||||
|
void SetUp() override {}
|
||||||
|
void TearDown() override {}
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void SetUpTestSuite() {
|
||||||
|
test.Init("/tmp/dnode_test_qnode1", 9064);
|
||||||
|
const char* fqdn = "localhost";
|
||||||
|
const char* firstEp = "localhost:9064";
|
||||||
|
|
||||||
|
server2.Start("/tmp/dnode_test_qnode2", fqdn, 9065, firstEp);
|
||||||
|
taosMsleep(300);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TearDownTestSuite() {
|
||||||
|
server2.Stop();
|
||||||
|
test.Cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
static Testbase test;
|
||||||
|
static TestServer server2;
|
||||||
|
};
|
||||||
|
|
||||||
|
Testbase DndTestQnode::test;
|
||||||
|
TestServer DndTestQnode::server2;
|
||||||
|
|
||||||
|
TEST_F(DndTestQnode, 01_ShowQnode) {
|
||||||
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, "");
|
||||||
|
CHECK_META("show qnodes", 3);
|
||||||
|
|
||||||
|
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||||
|
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
||||||
|
CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||||
|
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DndTestQnode, 02_Create_Qnode_Invalid_Id) {
|
||||||
|
{
|
||||||
|
int32_t contLen = sizeof(SMCreateQnodeMsg);
|
||||||
|
|
||||||
|
SMCreateQnodeMsg* pReq = (SMCreateQnodeMsg*)rpcMallocCont(contLen);
|
||||||
|
pReq->dnodeId = htonl(1);
|
||||||
|
|
||||||
|
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen);
|
||||||
|
ASSERT_NE(pMsg, nullptr);
|
||||||
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
|
|
||||||
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, "");
|
||||||
|
CHECK_META("show qnodes", 3);
|
||||||
|
|
||||||
|
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||||
|
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
||||||
|
CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||||
|
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 1);
|
||||||
|
|
||||||
|
CheckInt16(1);
|
||||||
|
CheckBinary("localhost:9064", TSDB_EP_LEN);
|
||||||
|
CheckTimestamp();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DndTestQnode, 03_Create_Qnode_Invalid_Id) {
|
||||||
|
{
|
||||||
|
int32_t contLen = sizeof(SMCreateQnodeMsg);
|
||||||
|
|
||||||
|
SMCreateQnodeMsg* pReq = (SMCreateQnodeMsg*)rpcMallocCont(contLen);
|
||||||
|
pReq->dnodeId = htonl(2);
|
||||||
|
|
||||||
|
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen);
|
||||||
|
ASSERT_NE(pMsg, nullptr);
|
||||||
|
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DndTestQnode, 04_Create_Qnode) {
|
||||||
|
{
|
||||||
|
// create dnode
|
||||||
|
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||||
|
|
||||||
|
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||||
|
strcpy(pReq->fqdn, "localhost");
|
||||||
|
pReq->port = htonl(9065);
|
||||||
|
|
||||||
|
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||||
|
ASSERT_NE(pMsg, nullptr);
|
||||||
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
|
|
||||||
|
taosMsleep(1300);
|
||||||
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// create qnode
|
||||||
|
int32_t contLen = sizeof(SMCreateQnodeMsg);
|
||||||
|
|
||||||
|
SMCreateQnodeMsg* pReq = (SMCreateQnodeMsg*)rpcMallocCont(contLen);
|
||||||
|
pReq->dnodeId = htonl(2);
|
||||||
|
|
||||||
|
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen);
|
||||||
|
ASSERT_NE(pMsg, nullptr);
|
||||||
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
|
|
||||||
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, "");
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 2);
|
||||||
|
|
||||||
|
CheckInt16(1);
|
||||||
|
CheckInt16(2);
|
||||||
|
CheckBinary("localhost:9064", TSDB_EP_LEN);
|
||||||
|
CheckBinary("localhost:9065", TSDB_EP_LEN);
|
||||||
|
CheckTimestamp();
|
||||||
|
CheckTimestamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// drop qnode
|
||||||
|
int32_t contLen = sizeof(SMDropQnodeMsg);
|
||||||
|
|
||||||
|
SMDropQnodeMsg* pReq = (SMDropQnodeMsg*)rpcMallocCont(contLen);
|
||||||
|
pReq->dnodeId = htonl(2);
|
||||||
|
|
||||||
|
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_QNODE, pReq, contLen);
|
||||||
|
ASSERT_NE(pMsg, nullptr);
|
||||||
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
|
|
||||||
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, "");
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 1);
|
||||||
|
|
||||||
|
CheckInt16(1);
|
||||||
|
CheckBinary("localhost:9064", TSDB_EP_LEN);
|
||||||
|
CheckTimestamp();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
aux_source_directory(. STEST_SRC)
|
||||||
|
add_executable(dnode_test_snode ${STEST_SRC})
|
||||||
|
target_link_libraries(
|
||||||
|
dnode_test_snode
|
||||||
|
PUBLIC sut
|
||||||
|
)
|
||||||
|
|
||||||
|
add_test(
|
||||||
|
NAME dnode_test_snode
|
||||||
|
COMMAND dnode_test_snode
|
||||||
|
)
|
||||||
|
|
@ -0,0 +1,154 @@
|
||||||
|
/**
|
||||||
|
* @file dnode.cpp
|
||||||
|
* @author slguan (slguan@taosdata.com)
|
||||||
|
* @brief DNODE module dnode-msg tests
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2021-12-15
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "base.h"
|
||||||
|
|
||||||
|
class DndTestSnode : public ::testing::Test {
|
||||||
|
public:
|
||||||
|
void SetUp() override {}
|
||||||
|
void TearDown() override {}
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void SetUpTestSuite() {
|
||||||
|
test.Init("/tmp/dnode_test_snode1", 9066);
|
||||||
|
const char* fqdn = "localhost";
|
||||||
|
const char* firstEp = "localhost:9066";
|
||||||
|
|
||||||
|
server2.Start("/tmp/dnode_test_snode2", fqdn, 9067, firstEp);
|
||||||
|
taosMsleep(300);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TearDownTestSuite() {
|
||||||
|
server2.Stop();
|
||||||
|
test.Cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
static Testbase test;
|
||||||
|
static TestServer server2;
|
||||||
|
};
|
||||||
|
|
||||||
|
Testbase DndTestSnode::test;
|
||||||
|
TestServer DndTestSnode::server2;
|
||||||
|
|
||||||
|
TEST_F(DndTestSnode, 01_ShowSnode) {
|
||||||
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_SNODE, "");
|
||||||
|
CHECK_META("show snodes", 3);
|
||||||
|
|
||||||
|
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||||
|
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
||||||
|
CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||||
|
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DndTestSnode, 02_Create_Snode_Invalid_Id) {
|
||||||
|
{
|
||||||
|
int32_t contLen = sizeof(SMCreateSnodeMsg);
|
||||||
|
|
||||||
|
SMCreateSnodeMsg* pReq = (SMCreateSnodeMsg*)rpcMallocCont(contLen);
|
||||||
|
pReq->dnodeId = htonl(1);
|
||||||
|
|
||||||
|
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen);
|
||||||
|
ASSERT_NE(pMsg, nullptr);
|
||||||
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
|
|
||||||
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_SNODE, "");
|
||||||
|
CHECK_META("show snodes", 3);
|
||||||
|
|
||||||
|
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||||
|
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
||||||
|
CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||||
|
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 1);
|
||||||
|
|
||||||
|
CheckInt16(1);
|
||||||
|
CheckBinary("localhost:9066", TSDB_EP_LEN);
|
||||||
|
CheckTimestamp();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DndTestSnode, 03_Create_Snode_Invalid_Id) {
|
||||||
|
{
|
||||||
|
int32_t contLen = sizeof(SMCreateSnodeMsg);
|
||||||
|
|
||||||
|
SMCreateSnodeMsg* pReq = (SMCreateSnodeMsg*)rpcMallocCont(contLen);
|
||||||
|
pReq->dnodeId = htonl(2);
|
||||||
|
|
||||||
|
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen);
|
||||||
|
ASSERT_NE(pMsg, nullptr);
|
||||||
|
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(DndTestSnode, 04_Create_Snode) {
|
||||||
|
{
|
||||||
|
// create dnode
|
||||||
|
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||||
|
|
||||||
|
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||||
|
strcpy(pReq->fqdn, "localhost");
|
||||||
|
pReq->port = htonl(9067);
|
||||||
|
|
||||||
|
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||||
|
ASSERT_NE(pMsg, nullptr);
|
||||||
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
|
|
||||||
|
taosMsleep(1300);
|
||||||
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// create snode
|
||||||
|
int32_t contLen = sizeof(SMCreateSnodeMsg);
|
||||||
|
|
||||||
|
SMCreateSnodeMsg* pReq = (SMCreateSnodeMsg*)rpcMallocCont(contLen);
|
||||||
|
pReq->dnodeId = htonl(2);
|
||||||
|
|
||||||
|
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen);
|
||||||
|
ASSERT_NE(pMsg, nullptr);
|
||||||
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
|
|
||||||
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_SNODE, "");
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 2);
|
||||||
|
|
||||||
|
CheckInt16(1);
|
||||||
|
CheckInt16(2);
|
||||||
|
CheckBinary("localhost:9066", TSDB_EP_LEN);
|
||||||
|
CheckBinary("localhost:9067", TSDB_EP_LEN);
|
||||||
|
CheckTimestamp();
|
||||||
|
CheckTimestamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// drop snode
|
||||||
|
int32_t contLen = sizeof(SMDropSnodeMsg);
|
||||||
|
|
||||||
|
SMDropSnodeMsg* pReq = (SMDropSnodeMsg*)rpcMallocCont(contLen);
|
||||||
|
pReq->dnodeId = htonl(2);
|
||||||
|
|
||||||
|
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_SNODE, pReq, contLen);
|
||||||
|
ASSERT_NE(pMsg, nullptr);
|
||||||
|
ASSERT_EQ(pMsg->code, 0);
|
||||||
|
|
||||||
|
test.SendShowMetaMsg(TSDB_MGMT_TABLE_SNODE, "");
|
||||||
|
test.SendShowRetrieveMsg();
|
||||||
|
EXPECT_EQ(test.GetShowRows(), 1);
|
||||||
|
|
||||||
|
CheckInt16(1);
|
||||||
|
CheckBinary("localhost:9066", TSDB_EP_LEN);
|
||||||
|
CheckTimestamp();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -146,8 +146,8 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
||||||
pSchema->bytes = htonl(pSchema->bytes);
|
pSchema->bytes = htonl(pSchema->bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPECT_STREQ(pRsp->tbFname, "");
|
EXPECT_STREQ(pRsp->tbFname, "1.d1.stb");
|
||||||
EXPECT_STREQ(pRsp->stbFname, "1.d1.stb");
|
EXPECT_STREQ(pRsp->stbFname, "");
|
||||||
EXPECT_EQ(pRsp->numOfColumns, 2);
|
EXPECT_EQ(pRsp->numOfColumns, 2);
|
||||||
EXPECT_EQ(pRsp->numOfTags, 3);
|
EXPECT_EQ(pRsp->numOfTags, 3);
|
||||||
EXPECT_EQ(pRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
EXPECT_EQ(pRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ void Testbase::InitLog(const char* path) {
|
||||||
tmrDebugFlag = 0;
|
tmrDebugFlag = 0;
|
||||||
uDebugFlag = 143;
|
uDebugFlag = 143;
|
||||||
rpcDebugFlag = 0;
|
rpcDebugFlag = 0;
|
||||||
odbcDebugFlag = 0;
|
|
||||||
qDebugFlag = 0;
|
qDebugFlag = 0;
|
||||||
wDebugFlag = 0;
|
wDebugFlag = 0;
|
||||||
sDebugFlag = 0;
|
sDebugFlag = 0;
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ SDnodeOpt TestServer::BuildOption(const char* path, const char* fqdn, uint16_t p
|
||||||
SDnodeOpt option = {0};
|
SDnodeOpt option = {0};
|
||||||
option.sver = 1;
|
option.sver = 1;
|
||||||
option.numOfCores = 1;
|
option.numOfCores = 1;
|
||||||
option.numOfSupportVnodes = 1;
|
option.numOfSupportVnodes = 16;
|
||||||
option.numOfCommitThreads = 1;
|
option.numOfCommitThreads = 1;
|
||||||
option.statusInterval = 1;
|
option.statusInterval = 1;
|
||||||
option.numOfThreadsPerCore = 1;
|
option.numOfThreadsPerCore = 1;
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TD_MND_BALANCE_H_
|
#ifndef _TD_MND_BNODE_H_
|
||||||
#define _TD_MND_BALANCE_H_
|
#define _TD_MND_BNODE_H_
|
||||||
|
|
||||||
#include "mndInt.h"
|
#include "mndInt.h"
|
||||||
|
|
||||||
|
|
@ -22,11 +22,11 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int32_t mndInitBalance(SMnode *pMnode);
|
int32_t mndInitBnode(SMnode *pMnode);
|
||||||
void mndCleanupBalance(SMnode *pMnode);
|
void mndCleanupBnode(SMnode *pMnode);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /*_TD_MND_BALANCE_H_*/
|
#endif /*_TD_MND_BNODE_H_*/
|
||||||
|
|
@ -75,13 +75,6 @@ typedef enum {
|
||||||
|
|
||||||
typedef enum { TRN_POLICY_ROLLBACK = 0, TRN_POLICY_RETRY = 1 } ETrnPolicy;
|
typedef enum { TRN_POLICY_ROLLBACK = 0, TRN_POLICY_RETRY = 1 } ETrnPolicy;
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
DND_STATUS_OFFLINE = 0,
|
|
||||||
DND_STATUS_READY = 1,
|
|
||||||
DND_STATUS_CREATING = 2,
|
|
||||||
DND_STATUS_DROPPING = 3
|
|
||||||
} EDndStatus;
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
DND_REASON_ONLINE = 0,
|
DND_REASON_ONLINE = 0,
|
||||||
DND_REASON_STATUS_MSG_TIMEOUT,
|
DND_REASON_STATUS_MSG_TIMEOUT,
|
||||||
|
|
@ -125,10 +118,9 @@ typedef struct {
|
||||||
int64_t rebootTime;
|
int64_t rebootTime;
|
||||||
int64_t lastAccessTime;
|
int64_t lastAccessTime;
|
||||||
int32_t accessTimes;
|
int32_t accessTimes;
|
||||||
int16_t numOfVnodes;
|
int32_t numOfVnodes;
|
||||||
int16_t numOfSupportVnodes;
|
int32_t numOfSupportVnodes;
|
||||||
int16_t numOfCores;
|
int32_t numOfCores;
|
||||||
EDndStatus status;
|
|
||||||
EDndReason offlineReason;
|
EDndReason offlineReason;
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
char fqdn[TSDB_FQDN_LEN];
|
char fqdn[TSDB_FQDN_LEN];
|
||||||
|
|
@ -145,6 +137,27 @@ typedef struct {
|
||||||
SDnodeObj *pDnode;
|
SDnodeObj *pDnode;
|
||||||
} SMnodeObj;
|
} SMnodeObj;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int32_t id;
|
||||||
|
int64_t createdTime;
|
||||||
|
int64_t updateTime;
|
||||||
|
SDnodeObj *pDnode;
|
||||||
|
} SQnodeObj;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int32_t id;
|
||||||
|
int64_t createdTime;
|
||||||
|
int64_t updateTime;
|
||||||
|
SDnodeObj *pDnode;
|
||||||
|
} SSnodeObj;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int32_t id;
|
||||||
|
int64_t createdTime;
|
||||||
|
int64_t updateTime;
|
||||||
|
SDnodeObj *pDnode;
|
||||||
|
} SBnodeObj;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t maxUsers;
|
int32_t maxUsers;
|
||||||
int32_t maxDbs;
|
int32_t maxDbs;
|
||||||
|
|
@ -273,7 +286,7 @@ typedef struct {
|
||||||
} SFuncObj;
|
} SFuncObj;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t id;
|
int64_t id;
|
||||||
int8_t type;
|
int8_t type;
|
||||||
int8_t replica;
|
int8_t replica;
|
||||||
int16_t numOfColumns;
|
int16_t numOfColumns;
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ SDnodeObj *mndAcquireDnode(SMnode *pMnode, int32_t dnodeId);
|
||||||
void mndReleaseDnode(SMnode *pMnode, SDnodeObj *pDnode);
|
void mndReleaseDnode(SMnode *pMnode, SDnodeObj *pDnode);
|
||||||
SEpSet mndGetDnodeEpset(SDnodeObj *pDnode);
|
SEpSet mndGetDnodeEpset(SDnodeObj *pDnode);
|
||||||
int32_t mndGetDnodeSize(SMnode *pMnode);
|
int32_t mndGetDnodeSize(SMnode *pMnode);
|
||||||
bool mndIsDnodeInReadyStatus(SMnode *pMnode, SDnodeObj *pDnode);
|
bool mndIsDnodeOnline(SMnode *pMnode, SDnodeObj *pDnode, int64_t curMs);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ typedef struct {
|
||||||
} SMnodeStep;
|
} SMnodeStep;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t showId;
|
int64_t showId;
|
||||||
ShowMetaFp metaFps[TSDB_MGMT_TABLE_MAX];
|
ShowMetaFp metaFps[TSDB_MGMT_TABLE_MAX];
|
||||||
ShowRetrieveFp retrieveFps[TSDB_MGMT_TABLE_MAX];
|
ShowRetrieveFp retrieveFps[TSDB_MGMT_TABLE_MAX];
|
||||||
ShowFreeIterFp freeIterFps[TSDB_MGMT_TABLE_MAX];
|
ShowFreeIterFp freeIterFps[TSDB_MGMT_TABLE_MAX];
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,20 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#ifndef _TD_MND_QNODE_H_
|
||||||
#include "os.h"
|
#define _TD_MND_QNODE_H_
|
||||||
|
|
||||||
#include "mndInt.h"
|
#include "mndInt.h"
|
||||||
|
|
||||||
int32_t mndInitBalance(SMnode *pMnode) { return 0; }
|
#ifdef __cplusplus
|
||||||
void mndCleanupBalance(SMnode *pMnode) {}
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int32_t mndInitQnode(SMnode *pMnode);
|
||||||
|
void mndCleanupQnode(SMnode *pMnode);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*_TD_MND_QNODE_H_*/
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* 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_MND_SNODE_H_
|
||||||
|
#define _TD_MND_SNODE_H_
|
||||||
|
|
||||||
|
#include "mndInt.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int32_t mndInitSnode(SMnode *pMnode);
|
||||||
|
void mndCleanupSnode(SMnode *pMnode);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*_TD_MND_SNODE_H_*/
|
||||||
|
|
@ -0,0 +1,446 @@
|
||||||
|
/*
|
||||||
|
* 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 "mndBnode.h"
|
||||||
|
#include "mndDnode.h"
|
||||||
|
#include "mndShow.h"
|
||||||
|
#include "mndTrans.h"
|
||||||
|
|
||||||
|
#define TSDB_BNODE_VER_NUMBER 1
|
||||||
|
#define TSDB_BNODE_RESERVE_SIZE 64
|
||||||
|
|
||||||
|
static SSdbRaw *mndBnodeActionEncode(SBnodeObj *pObj);
|
||||||
|
static SSdbRow *mndBnodeActionDecode(SSdbRaw *pRaw);
|
||||||
|
static int32_t mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj);
|
||||||
|
static int32_t mndBnodeActionDelete(SSdb *pSdb, SBnodeObj *pObj);
|
||||||
|
static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOldBnode, SBnodeObj *pNewBnode);
|
||||||
|
static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pMsg);
|
||||||
|
static int32_t mndProcessDropBnodeReq(SMnodeMsg *pMsg);
|
||||||
|
static int32_t mndProcessCreateBnodeRsp(SMnodeMsg *pMsg);
|
||||||
|
static int32_t mndProcessDropBnodeRsp(SMnodeMsg *pMsg);
|
||||||
|
static int32_t mndGetBnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||||
|
static int32_t mndRetrieveBnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows);
|
||||||
|
static void mndCancelGetNextBnode(SMnode *pMnode, void *pIter);
|
||||||
|
|
||||||
|
int32_t mndInitBnode(SMnode *pMnode) {
|
||||||
|
SSdbTable table = {.sdbType = SDB_BNODE,
|
||||||
|
.keyType = SDB_KEY_INT32,
|
||||||
|
.encodeFp = (SdbEncodeFp)mndBnodeActionEncode,
|
||||||
|
.decodeFp = (SdbDecodeFp)mndBnodeActionDecode,
|
||||||
|
.insertFp = (SdbInsertFp)mndBnodeActionInsert,
|
||||||
|
.updateFp = (SdbUpdateFp)mndBnodeActionUpdate,
|
||||||
|
.deleteFp = (SdbDeleteFp)mndBnodeActionDelete};
|
||||||
|
|
||||||
|
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_BNODE, mndProcessCreateBnodeReq);
|
||||||
|
mndSetMsgHandle(pMnode, TDMT_MND_DROP_BNODE, mndProcessDropBnodeReq);
|
||||||
|
mndSetMsgHandle(pMnode, TDMT_DND_CREATE_BNODE_RSP, mndProcessCreateBnodeRsp);
|
||||||
|
mndSetMsgHandle(pMnode, TDMT_DND_DROP_BNODE_RSP, mndProcessDropBnodeRsp);
|
||||||
|
|
||||||
|
mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_BNODE, mndGetBnodeMeta);
|
||||||
|
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_BNODE, mndRetrieveBnodes);
|
||||||
|
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_BNODE, mndCancelGetNextBnode);
|
||||||
|
|
||||||
|
return sdbSetTable(pMnode->pSdb, table);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mndCleanupBnode(SMnode *pMnode) {}
|
||||||
|
|
||||||
|
static SBnodeObj *mndAcquireBnode(SMnode *pMnode, int32_t snodeId) {
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
SBnodeObj *pObj = sdbAcquire(pSdb, SDB_BNODE, &snodeId);
|
||||||
|
if (pObj == NULL) {
|
||||||
|
terrno = TSDB_CODE_MND_BNODE_NOT_EXIST;
|
||||||
|
}
|
||||||
|
return pObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mndReleaseBnode(SMnode *pMnode, SBnodeObj *pObj) {
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
sdbRelease(pSdb, pObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
static SSdbRaw *mndBnodeActionEncode(SBnodeObj *pObj) {
|
||||||
|
SSdbRaw *pRaw = sdbAllocRaw(SDB_BNODE, TSDB_BNODE_VER_NUMBER, sizeof(SBnodeObj) + TSDB_BNODE_RESERVE_SIZE);
|
||||||
|
if (pRaw == NULL) return NULL;
|
||||||
|
|
||||||
|
int32_t dataPos = 0;
|
||||||
|
SDB_SET_INT32(pRaw, dataPos, pObj->id);
|
||||||
|
SDB_SET_INT64(pRaw, dataPos, pObj->createdTime)
|
||||||
|
SDB_SET_INT64(pRaw, dataPos, pObj->updateTime)
|
||||||
|
SDB_SET_RESERVE(pRaw, dataPos, TSDB_BNODE_RESERVE_SIZE)
|
||||||
|
|
||||||
|
return pRaw;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SSdbRow *mndBnodeActionDecode(SSdbRaw *pRaw) {
|
||||||
|
int8_t sver = 0;
|
||||||
|
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||||
|
|
||||||
|
if (sver != TSDB_BNODE_VER_NUMBER) {
|
||||||
|
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||||
|
mError("failed to decode snode since %s", terrstr());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSdbRow *pRow = sdbAllocRow(sizeof(SBnodeObj));
|
||||||
|
SBnodeObj *pObj = sdbGetRowObj(pRow);
|
||||||
|
if (pObj == NULL) return NULL;
|
||||||
|
|
||||||
|
int32_t dataPos = 0;
|
||||||
|
SDB_GET_INT32(pRaw, pRow, dataPos, &pObj->id)
|
||||||
|
SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->createdTime)
|
||||||
|
SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->updateTime)
|
||||||
|
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_BNODE_RESERVE_SIZE)
|
||||||
|
|
||||||
|
return pRow;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj) {
|
||||||
|
mTrace("snode:%d, perform insert action", pObj->id);
|
||||||
|
pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id);
|
||||||
|
if (pObj->pDnode == NULL) {
|
||||||
|
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||||
|
mError("snode:%d, failed to perform insert action since %s", pObj->id, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndBnodeActionDelete(SSdb *pSdb, SBnodeObj *pObj) {
|
||||||
|
mTrace("snode:%d, perform delete action", pObj->id);
|
||||||
|
if (pObj->pDnode != NULL) {
|
||||||
|
sdbRelease(pSdb, pObj->pDnode);
|
||||||
|
pObj->pDnode = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOldBnode, SBnodeObj *pNewBnode) {
|
||||||
|
mTrace("snode:%d, perform update action", pOldBnode->id);
|
||||||
|
pOldBnode->updateTime = pNewBnode->updateTime;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndSetCreateBnodeRedoLogs(STrans *pTrans, SBnodeObj *pObj) {
|
||||||
|
SSdbRaw *pRedoRaw = mndBnodeActionEncode(pObj);
|
||||||
|
if (pRedoRaw == NULL) return -1;
|
||||||
|
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||||
|
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndSetCreateBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) {
|
||||||
|
SSdbRaw *pCommitRaw = mndBnodeActionEncode(pObj);
|
||||||
|
if (pCommitRaw == NULL) return -1;
|
||||||
|
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||||
|
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndSetCreateBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) {
|
||||||
|
SDCreateBnodeMsg *pMsg = malloc(sizeof(SDCreateBnodeMsg));
|
||||||
|
if (pMsg == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
pMsg->dnodeId = htonl(pDnode->id);
|
||||||
|
|
||||||
|
STransAction action = {0};
|
||||||
|
action.epSet = mndGetDnodeEpset(pDnode);
|
||||||
|
action.pCont = pMsg;
|
||||||
|
action.contLen = sizeof(SDCreateBnodeMsg);
|
||||||
|
action.msgType = TDMT_DND_CREATE_BNODE;
|
||||||
|
|
||||||
|
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||||
|
free(pMsg);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndCreateBnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateBnodeMsg *pCreate) {
|
||||||
|
SBnodeObj snodeObj = {0};
|
||||||
|
snodeObj.id = pDnode->id;
|
||||||
|
snodeObj.createdTime = taosGetTimestampMs();
|
||||||
|
snodeObj.updateTime = snodeObj.createdTime;
|
||||||
|
|
||||||
|
int32_t code = -1;
|
||||||
|
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg);
|
||||||
|
if (pTrans == NULL) {
|
||||||
|
mError("snode:%d, failed to create since %s", pCreate->dnodeId, terrstr());
|
||||||
|
goto CREATE_BNODE_OVER;
|
||||||
|
}
|
||||||
|
mDebug("trans:%d, used to create snode:%d", pTrans->id, pCreate->dnodeId);
|
||||||
|
|
||||||
|
if (mndSetCreateBnodeRedoLogs(pTrans, &snodeObj) != 0) {
|
||||||
|
mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr());
|
||||||
|
goto CREATE_BNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mndSetCreateBnodeCommitLogs(pTrans, &snodeObj) != 0) {
|
||||||
|
mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr());
|
||||||
|
goto CREATE_BNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mndSetCreateBnodeRedoActions(pTrans, pDnode, &snodeObj) != 0) {
|
||||||
|
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||||
|
goto CREATE_BNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||||
|
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||||
|
goto CREATE_BNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = 0;
|
||||||
|
|
||||||
|
CREATE_BNODE_OVER:
|
||||||
|
mndTransDrop(pTrans);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pMsg) {
|
||||||
|
SMnode *pMnode = pMsg->pMnode;
|
||||||
|
SMCreateBnodeMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||||
|
|
||||||
|
pCreate->dnodeId = htonl(pCreate->dnodeId);
|
||||||
|
|
||||||
|
mDebug("snode:%d, start to create", pCreate->dnodeId);
|
||||||
|
|
||||||
|
SBnodeObj *pObj = mndAcquireBnode(pMnode, pCreate->dnodeId);
|
||||||
|
if (pObj != NULL) {
|
||||||
|
mError("snode:%d, snode already exist", pObj->id);
|
||||||
|
mndReleaseBnode(pMnode, pObj);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCreate->dnodeId);
|
||||||
|
if (pDnode == NULL) {
|
||||||
|
mError("snode:%d, dnode not exist", pCreate->dnodeId);
|
||||||
|
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t code = mndCreateBnode(pMnode, pMsg, pDnode, pCreate);
|
||||||
|
mndReleaseDnode(pMnode, pDnode);
|
||||||
|
|
||||||
|
if (code != 0) {
|
||||||
|
mError("snode:%d, failed to create since %s", pCreate->dnodeId, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndSetDropBnodeRedoLogs(STrans *pTrans, SBnodeObj *pObj) {
|
||||||
|
SSdbRaw *pRedoRaw = mndBnodeActionEncode(pObj);
|
||||||
|
if (pRedoRaw == NULL) return -1;
|
||||||
|
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||||
|
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndSetDropBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) {
|
||||||
|
SSdbRaw *pCommitRaw = mndBnodeActionEncode(pObj);
|
||||||
|
if (pCommitRaw == NULL) return -1;
|
||||||
|
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||||
|
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndSetDropBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) {
|
||||||
|
SDDropBnodeMsg *pMsg = malloc(sizeof(SDDropBnodeMsg));
|
||||||
|
if (pMsg == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
pMsg->dnodeId = htonl(pDnode->id);
|
||||||
|
|
||||||
|
STransAction action = {0};
|
||||||
|
action.epSet = mndGetDnodeEpset(pDnode);
|
||||||
|
action.pCont = pMsg;
|
||||||
|
action.contLen = sizeof(SDDropBnodeMsg);
|
||||||
|
action.msgType = TDMT_DND_DROP_BNODE;
|
||||||
|
|
||||||
|
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||||
|
free(pMsg);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndDropBnode(SMnode *pMnode, SMnodeMsg *pMsg, SBnodeObj *pObj) {
|
||||||
|
int32_t code = -1;
|
||||||
|
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg);
|
||||||
|
if (pTrans == NULL) {
|
||||||
|
mError("snode:%d, failed to drop since %s", pObj->id, terrstr());
|
||||||
|
goto DROP_BNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
mDebug("trans:%d, used to drop snode:%d", pTrans->id, pObj->id);
|
||||||
|
|
||||||
|
if (mndSetDropBnodeRedoLogs(pTrans, pObj) != 0) {
|
||||||
|
mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr());
|
||||||
|
goto DROP_BNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mndSetDropBnodeCommitLogs(pTrans, pObj) != 0) {
|
||||||
|
mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr());
|
||||||
|
goto DROP_BNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mndSetDropBnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) {
|
||||||
|
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||||
|
goto DROP_BNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||||
|
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||||
|
goto DROP_BNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = 0;
|
||||||
|
|
||||||
|
DROP_BNODE_OVER:
|
||||||
|
mndTransDrop(pTrans);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndProcessDropBnodeReq(SMnodeMsg *pMsg) {
|
||||||
|
SMnode *pMnode = pMsg->pMnode;
|
||||||
|
SMDropBnodeMsg *pDrop = pMsg->rpcMsg.pCont;
|
||||||
|
pDrop->dnodeId = htonl(pDrop->dnodeId);
|
||||||
|
|
||||||
|
mDebug("snode:%d, start to drop", pDrop->dnodeId);
|
||||||
|
|
||||||
|
if (pDrop->dnodeId <= 0) {
|
||||||
|
terrno = TSDB_CODE_SDB_APP_ERROR;
|
||||||
|
mError("snode:%d, failed to drop since %s", pDrop->dnodeId, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SBnodeObj *pObj = mndAcquireBnode(pMnode, pDrop->dnodeId);
|
||||||
|
if (pObj == NULL) {
|
||||||
|
mError("snode:%d, not exist", pDrop->dnodeId);
|
||||||
|
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t code = mndDropBnode(pMnode, pMsg, pObj);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("snode:%d, failed to drop since %s", pMnode->dnodeId, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sdbRelease(pMnode->pSdb, pMnode);
|
||||||
|
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndProcessCreateBnodeRsp(SMnodeMsg *pMsg) {
|
||||||
|
mndTransProcessRsp(pMsg);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndProcessDropBnodeRsp(SMnodeMsg *pMsg) {
|
||||||
|
mndTransProcessRsp(pMsg);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndGetBnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||||
|
SMnode *pMnode = pMsg->pMnode;
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
|
||||||
|
int32_t cols = 0;
|
||||||
|
SSchema *pSchema = pMeta->pSchema;
|
||||||
|
|
||||||
|
pShow->bytes[cols] = 2;
|
||||||
|
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
|
||||||
|
strcpy(pSchema[cols].name, "id");
|
||||||
|
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pShow->bytes[cols] = TSDB_EP_LEN + VARSTR_HEADER_SIZE;
|
||||||
|
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||||
|
strcpy(pSchema[cols].name, "endpoint");
|
||||||
|
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pShow->bytes[cols] = 8;
|
||||||
|
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||||
|
strcpy(pSchema[cols].name, "create_time");
|
||||||
|
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pMeta->numOfColumns = htonl(cols);
|
||||||
|
pShow->numOfColumns = cols;
|
||||||
|
|
||||||
|
pShow->offset[0] = 0;
|
||||||
|
for (int32_t i = 1; i < cols; ++i) {
|
||||||
|
pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
pShow->numOfRows = sdbGetSize(pSdb, SDB_BNODE);
|
||||||
|
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
|
||||||
|
strcpy(pMeta->tbFname, mndShowStr(pShow->type));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndRetrieveBnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) {
|
||||||
|
SMnode *pMnode = pMsg->pMnode;
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
int32_t numOfRows = 0;
|
||||||
|
int32_t cols = 0;
|
||||||
|
SBnodeObj *pObj = NULL;
|
||||||
|
char *pWrite;
|
||||||
|
|
||||||
|
while (numOfRows < rows) {
|
||||||
|
pShow->pIter = sdbFetch(pSdb, SDB_BNODE, pShow->pIter, (void **)&pObj);
|
||||||
|
if (pShow->pIter == NULL) break;
|
||||||
|
|
||||||
|
cols = 0;
|
||||||
|
|
||||||
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
|
*(int16_t *)pWrite = pObj->id;
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
|
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pObj->pDnode->ep, pShow->bytes[cols]);
|
||||||
|
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
|
*(int64_t *)pWrite = pObj->createdTime;
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
numOfRows++;
|
||||||
|
sdbRelease(pSdb, pObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||||
|
pShow->numOfReads += numOfRows;
|
||||||
|
|
||||||
|
return numOfRows;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mndCancelGetNextBnode(SMnode *pMnode, void *pIter) {
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
sdbCancelFetch(pSdb, pIter);
|
||||||
|
}
|
||||||
|
|
@ -725,7 +725,7 @@ static int32_t mndSetDropDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pD
|
||||||
static int32_t mndBuildDropVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup) {
|
static int32_t mndBuildDropVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup) {
|
||||||
for (int32_t vn = 0; vn < pVgroup->replica; ++vn) {
|
for (int32_t vn = 0; vn < pVgroup->replica; ++vn) {
|
||||||
STransAction action = {0};
|
STransAction action = {0};
|
||||||
SVnodeGid * pVgid = pVgroup->vnodeGid + vn;
|
SVnodeGid *pVgid = pVgroup->vnodeGid + vn;
|
||||||
|
|
||||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||||
if (pDnode == NULL) return -1;
|
if (pDnode == NULL) return -1;
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,6 @@ static const char *offlineReason[] = {
|
||||||
"unknown",
|
"unknown",
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *dnodeStatus[] = {"offline", "ready", "creating", "dropping"};
|
|
||||||
|
|
||||||
static int32_t mndCreateDefaultDnode(SMnode *pMnode);
|
static int32_t mndCreateDefaultDnode(SMnode *pMnode);
|
||||||
static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode);
|
static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode);
|
||||||
static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw);
|
static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw);
|
||||||
|
|
@ -198,6 +196,8 @@ static SDnodeObj *mndAcquireDnodeByEp(SMnode *pMnode, char *pEpStr) {
|
||||||
sdbCancelFetch(pSdb, pIter);
|
sdbCancelFetch(pSdb, pIter);
|
||||||
return pDnode;
|
return pDnode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sdbRelease(pSdb, pDnode);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -208,10 +208,12 @@ int32_t mndGetDnodeSize(SMnode *pMnode) {
|
||||||
return sdbGetSize(pSdb, SDB_DNODE);
|
return sdbGetSize(pSdb, SDB_DNODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mndIsDnodeInReadyStatus(SMnode *pMnode, SDnodeObj *pDnode) {
|
bool mndIsDnodeOnline(SMnode *pMnode, SDnodeObj *pDnode, int64_t curMs) {
|
||||||
int64_t ms = taosGetTimestampMs();
|
int64_t interval = ABS(pDnode->lastAccessTime - curMs);
|
||||||
int64_t interval = ABS(pDnode->lastAccessTime - ms);
|
|
||||||
if (interval > 3500 * pMnode->cfg.statusInterval) {
|
if (interval > 3500 * pMnode->cfg.statusInterval) {
|
||||||
|
if (pDnode->rebootTime > 0) {
|
||||||
|
pDnode->offlineReason = DND_REASON_STATUS_MSG_TIMEOUT;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -278,8 +280,8 @@ static void mndParseStatusMsg(SStatusMsg *pStatus) {
|
||||||
pStatus->clusterId = htobe64(pStatus->clusterId);
|
pStatus->clusterId = htobe64(pStatus->clusterId);
|
||||||
pStatus->rebootTime = htobe64(pStatus->rebootTime);
|
pStatus->rebootTime = htobe64(pStatus->rebootTime);
|
||||||
pStatus->updateTime = htobe64(pStatus->updateTime);
|
pStatus->updateTime = htobe64(pStatus->updateTime);
|
||||||
pStatus->numOfCores = htons(pStatus->numOfCores);
|
pStatus->numOfCores = htonl(pStatus->numOfCores);
|
||||||
pStatus->numOfSupportVnodes = htons(pStatus->numOfSupportVnodes);
|
pStatus->numOfSupportVnodes = htonl(pStatus->numOfSupportVnodes);
|
||||||
pStatus->clusterCfg.statusInterval = htonl(pStatus->clusterCfg.statusInterval);
|
pStatus->clusterCfg.statusInterval = htonl(pStatus->clusterCfg.statusInterval);
|
||||||
pStatus->clusterCfg.checkTime = htobe64(pStatus->clusterCfg.checkTime);
|
pStatus->clusterCfg.checkTime = htobe64(pStatus->clusterCfg.checkTime);
|
||||||
}
|
}
|
||||||
|
|
@ -287,85 +289,83 @@ static void mndParseStatusMsg(SStatusMsg *pStatus) {
|
||||||
static int32_t mndProcessStatusMsg(SMnodeMsg *pMsg) {
|
static int32_t mndProcessStatusMsg(SMnodeMsg *pMsg) {
|
||||||
SMnode *pMnode = pMsg->pMnode;
|
SMnode *pMnode = pMsg->pMnode;
|
||||||
SStatusMsg *pStatus = pMsg->rpcMsg.pCont;
|
SStatusMsg *pStatus = pMsg->rpcMsg.pCont;
|
||||||
|
SDnodeObj *pDnode = NULL;
|
||||||
|
int32_t code = -1;
|
||||||
|
|
||||||
mndParseStatusMsg(pStatus);
|
mndParseStatusMsg(pStatus);
|
||||||
|
|
||||||
SDnodeObj *pDnode = NULL;
|
|
||||||
if (pStatus->dnodeId == 0) {
|
if (pStatus->dnodeId == 0) {
|
||||||
pDnode = mndAcquireDnodeByEp(pMnode, pStatus->dnodeEp);
|
pDnode = mndAcquireDnodeByEp(pMnode, pStatus->dnodeEp);
|
||||||
if (pDnode == NULL) {
|
if (pDnode == NULL) {
|
||||||
mDebug("dnode:%s, not created yet", pStatus->dnodeEp);
|
mDebug("dnode:%s, not created yet", pStatus->dnodeEp);
|
||||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||||
return -1;
|
goto PROCESS_STATUS_MSG_OVER;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pDnode = mndAcquireDnode(pMnode, pStatus->dnodeId);
|
pDnode = mndAcquireDnode(pMnode, pStatus->dnodeId);
|
||||||
if (pDnode == NULL) {
|
if (pDnode == NULL) {
|
||||||
pDnode = mndAcquireDnodeByEp(pMnode, pStatus->dnodeEp);
|
pDnode = mndAcquireDnodeByEp(pMnode, pStatus->dnodeEp);
|
||||||
if (pDnode != NULL && pDnode->status != DND_STATUS_READY) {
|
if (pDnode != NULL) {
|
||||||
pDnode->offlineReason = DND_REASON_DNODE_ID_NOT_MATCH;
|
pDnode->offlineReason = DND_REASON_DNODE_ID_NOT_MATCH;
|
||||||
}
|
}
|
||||||
mError("dnode:%d, %s not exist", pStatus->dnodeId, pStatus->dnodeEp);
|
mError("dnode:%d, %s not exist", pStatus->dnodeId, pStatus->dnodeEp);
|
||||||
mndReleaseDnode(pMnode, pDnode);
|
|
||||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||||
return -1;
|
goto PROCESS_STATUS_MSG_OVER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t curMs = taosGetTimestampMs();
|
||||||
|
bool online = mndIsDnodeOnline(pMnode, pDnode, curMs);
|
||||||
|
bool needCheckCfg = !(online && pDnode->rebootTime == pStatus->rebootTime);
|
||||||
|
|
||||||
|
if (needCheckCfg) {
|
||||||
if (pStatus->sver != pMnode->cfg.sver) {
|
if (pStatus->sver != pMnode->cfg.sver) {
|
||||||
if (pDnode != NULL && pDnode->status != DND_STATUS_READY) {
|
if (pDnode != NULL) {
|
||||||
pDnode->offlineReason = DND_REASON_VERSION_NOT_MATCH;
|
pDnode->offlineReason = DND_REASON_VERSION_NOT_MATCH;
|
||||||
}
|
}
|
||||||
mndReleaseDnode(pMnode, pDnode);
|
|
||||||
mError("dnode:%d, status msg version:%d not match cluster:%d", pStatus->dnodeId, pStatus->sver, pMnode->cfg.sver);
|
mError("dnode:%d, status msg version:%d not match cluster:%d", pStatus->dnodeId, pStatus->sver, pMnode->cfg.sver);
|
||||||
terrno = TSDB_CODE_MND_INVALID_MSG_VERSION;
|
terrno = TSDB_CODE_MND_INVALID_MSG_VERSION;
|
||||||
return -1;
|
goto PROCESS_STATUS_MSG_OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pStatus->dnodeId == 0) {
|
if (pStatus->dnodeId == 0) {
|
||||||
mDebug("dnode:%d %s, first access, set clusterId %" PRId64, pDnode->id, pDnode->ep, pMnode->clusterId);
|
mDebug("dnode:%d %s, first access, set clusterId %" PRId64, pDnode->id, pDnode->ep, pMnode->clusterId);
|
||||||
} else {
|
} else {
|
||||||
if (pStatus->clusterId != pMnode->clusterId) {
|
if (pStatus->clusterId != pMnode->clusterId) {
|
||||||
if (pDnode != NULL && pDnode->status != DND_STATUS_READY) {
|
if (pDnode != NULL) {
|
||||||
pDnode->offlineReason = DND_REASON_CLUSTER_ID_NOT_MATCH;
|
pDnode->offlineReason = DND_REASON_CLUSTER_ID_NOT_MATCH;
|
||||||
}
|
}
|
||||||
mError("dnode:%d, clusterId %" PRId64 " not match exist %" PRId64, pDnode->id, pStatus->clusterId,
|
mError("dnode:%d, clusterId %" PRId64 " not match exist %" PRId64, pDnode->id, pStatus->clusterId,
|
||||||
pMnode->clusterId);
|
pMnode->clusterId);
|
||||||
mndReleaseDnode(pMnode, pDnode);
|
terrno = TSDB_CODE_MND_INVALID_CLUSTER_ID;
|
||||||
terrno != TSDB_CODE_MND_INVALID_CLUSTER_ID;
|
goto PROCESS_STATUS_MSG_OVER;
|
||||||
return -1;
|
|
||||||
} else {
|
} else {
|
||||||
pDnode->accessTimes++;
|
pDnode->accessTimes++;
|
||||||
mTrace("dnode:%d, status received, access times %d", pDnode->id, pDnode->accessTimes);
|
mTrace("dnode:%d, status received, access times %d", pDnode->id, pDnode->accessTimes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pDnode->status == DND_STATUS_OFFLINE) {
|
|
||||||
// Verify whether the cluster parameters are consistent when status change from offline to ready
|
// Verify whether the cluster parameters are consistent when status change from offline to ready
|
||||||
int32_t ret = mndCheckClusterCfgPara(pMnode, &pStatus->clusterCfg);
|
int32_t ret = mndCheckClusterCfgPara(pMnode, &pStatus->clusterCfg);
|
||||||
if (0 != ret) {
|
if (0 != ret) {
|
||||||
pDnode->offlineReason = ret;
|
pDnode->offlineReason = ret;
|
||||||
mError("dnode:%d, cluster cfg inconsistent since:%s", pDnode->id, offlineReason[ret]);
|
mError("dnode:%d, cluster cfg inconsistent since:%s", pDnode->id, offlineReason[ret]);
|
||||||
mndReleaseDnode(pMnode, pDnode);
|
|
||||||
terrno = TSDB_CODE_MND_INVALID_CLUSTER_CFG;
|
terrno = TSDB_CODE_MND_INVALID_CLUSTER_CFG;
|
||||||
return -1;
|
goto PROCESS_STATUS_MSG_OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
mInfo("dnode:%d, from offline to online", pDnode->id);
|
mInfo("dnode:%d, from offline to online", pDnode->id);
|
||||||
}
|
|
||||||
|
|
||||||
pDnode->rebootTime = pStatus->rebootTime;
|
pDnode->rebootTime = pStatus->rebootTime;
|
||||||
pDnode->numOfCores = pStatus->numOfCores;
|
pDnode->numOfCores = pStatus->numOfCores;
|
||||||
pDnode->numOfSupportVnodes = pStatus->numOfSupportVnodes;
|
pDnode->numOfSupportVnodes = pStatus->numOfSupportVnodes;
|
||||||
pDnode->lastAccessTime = taosGetTimestampMs();
|
|
||||||
pDnode->status = DND_STATUS_READY;
|
|
||||||
|
|
||||||
int32_t numOfEps = mndGetDnodeSize(pMnode);
|
int32_t numOfEps = mndGetDnodeSize(pMnode);
|
||||||
int32_t contLen = sizeof(SStatusRsp) + numOfEps * sizeof(SDnodeEp);
|
int32_t contLen = sizeof(SStatusRsp) + numOfEps * sizeof(SDnodeEp);
|
||||||
SStatusRsp *pRsp = rpcMallocCont(contLen);
|
SStatusRsp *pRsp = rpcMallocCont(contLen);
|
||||||
if (pRsp == NULL) {
|
if (pRsp == NULL) {
|
||||||
mndReleaseDnode(pMnode, pDnode);
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
goto PROCESS_STATUS_MSG_OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
pRsp->dnodeCfg.dnodeId = htonl(pDnode->id);
|
pRsp->dnodeCfg.dnodeId = htonl(pDnode->id);
|
||||||
|
|
@ -374,9 +374,14 @@ static int32_t mndProcessStatusMsg(SMnodeMsg *pMsg) {
|
||||||
|
|
||||||
pMsg->contLen = contLen;
|
pMsg->contLen = contLen;
|
||||||
pMsg->pCont = pRsp;
|
pMsg->pCont = pRsp;
|
||||||
mndReleaseDnode(pMnode, pDnode);
|
}
|
||||||
|
|
||||||
return 0;
|
pDnode->lastAccessTime = curMs;
|
||||||
|
code = 0;
|
||||||
|
|
||||||
|
PROCESS_STATUS_MSG_OVER:
|
||||||
|
mndReleaseDnode(pMnode, pDnode);
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndCreateDnode(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDnodeMsg *pCreate) {
|
static int32_t mndCreateDnode(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDnodeMsg *pCreate) {
|
||||||
|
|
@ -416,10 +421,9 @@ static int32_t mndCreateDnode(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDnodeMsg *
|
||||||
static int32_t mndProcessCreateDnodeMsg(SMnodeMsg *pMsg) {
|
static int32_t mndProcessCreateDnodeMsg(SMnodeMsg *pMsg) {
|
||||||
SMnode *pMnode = pMsg->pMnode;
|
SMnode *pMnode = pMsg->pMnode;
|
||||||
SCreateDnodeMsg *pCreate = pMsg->rpcMsg.pCont;
|
SCreateDnodeMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||||
|
pCreate->port = htonl(pCreate->port);
|
||||||
mDebug("dnode:%s:%d, start to create", pCreate->fqdn, pCreate->port);
|
mDebug("dnode:%s:%d, start to create", pCreate->fqdn, pCreate->port);
|
||||||
|
|
||||||
pCreate->port = htonl(pCreate->port);
|
|
||||||
if (pCreate->fqdn[0] == 0 || pCreate->port <= 0 || pCreate->port > UINT16_MAX) {
|
if (pCreate->fqdn[0] == 0 || pCreate->port <= 0 || pCreate->port > UINT16_MAX) {
|
||||||
terrno = TSDB_CODE_MND_INVALID_DNODE_EP;
|
terrno = TSDB_CODE_MND_INVALID_DNODE_EP;
|
||||||
mError("dnode:%s:%d, failed to create since %s", pCreate->fqdn, pCreate->port, terrstr());
|
mError("dnode:%s:%d, failed to create since %s", pCreate->fqdn, pCreate->port, terrstr());
|
||||||
|
|
@ -638,7 +642,7 @@ static int32_t mndGetDnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
|
||||||
|
|
||||||
pShow->bytes[cols] = 2;
|
pShow->bytes[cols] = 2;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
|
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
|
||||||
strcpy(pSchema[cols].name, "max_vnodes");
|
strcpy(pSchema[cols].name, "support_vnodes");
|
||||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||||
cols++;
|
cols++;
|
||||||
|
|
||||||
|
|
@ -682,10 +686,12 @@ static int32_t mndRetrieveDnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, i
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
SDnodeObj *pDnode = NULL;
|
SDnodeObj *pDnode = NULL;
|
||||||
char *pWrite;
|
char *pWrite;
|
||||||
|
int64_t curMs = taosGetTimestampMs();
|
||||||
|
|
||||||
while (numOfRows < rows) {
|
while (numOfRows < rows) {
|
||||||
pShow->pIter = sdbFetch(pSdb, SDB_DNODE, pShow->pIter, (void **)&pDnode);
|
pShow->pIter = sdbFetch(pSdb, SDB_DNODE, pShow->pIter, (void **)&pDnode);
|
||||||
if (pShow->pIter == NULL) break;
|
if (pShow->pIter == NULL) break;
|
||||||
|
bool online = mndIsDnodeOnline(pMnode, pDnode, curMs);
|
||||||
|
|
||||||
cols = 0;
|
cols = 0;
|
||||||
|
|
||||||
|
|
@ -706,8 +712,7 @@ static int32_t mndRetrieveDnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, i
|
||||||
cols++;
|
cols++;
|
||||||
|
|
||||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
const char *status = dnodeStatus[pDnode->status];
|
STR_TO_VARSTR(pWrite, online ? "ready" : "offline");
|
||||||
STR_TO_VARSTR(pWrite, status);
|
|
||||||
cols++;
|
cols++;
|
||||||
|
|
||||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
|
|
@ -715,11 +720,7 @@ static int32_t mndRetrieveDnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, i
|
||||||
cols++;
|
cols++;
|
||||||
|
|
||||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
if (pDnode->status == DND_STATUS_READY) {
|
STR_TO_VARSTR(pWrite, online ? "" : offlineReason[pDnode->offlineReason]);
|
||||||
STR_TO_VARSTR(pWrite, "");
|
|
||||||
} else {
|
|
||||||
STR_TO_VARSTR(pWrite, offlineReason[pDnode->offlineReason]);
|
|
||||||
}
|
|
||||||
cols++;
|
cols++;
|
||||||
|
|
||||||
numOfRows++;
|
numOfRows++;
|
||||||
|
|
|
||||||
|
|
@ -219,6 +219,7 @@ void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pEpSet->numOfEps++;
|
pEpSet->numOfEps++;
|
||||||
|
sdbRelease(pSdb, pObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -251,7 +252,7 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
|
||||||
void *pIter = NULL;
|
void *pIter = NULL;
|
||||||
int32_t numOfReplicas = 0;
|
int32_t numOfReplicas = 0;
|
||||||
|
|
||||||
SCreateMnodeInMsg createMsg = {0};
|
SDCreateMnodeMsg createMsg = {0};
|
||||||
while (1) {
|
while (1) {
|
||||||
SMnodeObj *pMObj = NULL;
|
SMnodeObj *pMObj = NULL;
|
||||||
pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pMObj);
|
pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pMObj);
|
||||||
|
|
@ -281,18 +282,18 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
|
||||||
|
|
||||||
STransAction action = {0};
|
STransAction action = {0};
|
||||||
|
|
||||||
SAlterMnodeInMsg *pMsg = malloc(sizeof(SAlterMnodeInMsg));
|
SDAlterMnodeMsg *pMsg = malloc(sizeof(SDAlterMnodeMsg));
|
||||||
if (pMsg == NULL) {
|
if (pMsg == NULL) {
|
||||||
sdbCancelFetch(pSdb, pIter);
|
sdbCancelFetch(pSdb, pIter);
|
||||||
sdbRelease(pSdb, pMObj);
|
sdbRelease(pSdb, pMObj);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memcpy(pMsg, &createMsg, sizeof(SAlterMnodeInMsg));
|
memcpy(pMsg, &createMsg, sizeof(SDAlterMnodeMsg));
|
||||||
|
|
||||||
pMsg->dnodeId = htonl(pMObj->id);
|
pMsg->dnodeId = htonl(pMObj->id);
|
||||||
action.epSet = mndGetDnodeEpset(pMObj->pDnode);
|
action.epSet = mndGetDnodeEpset(pMObj->pDnode);
|
||||||
action.pCont = pMsg;
|
action.pCont = pMsg;
|
||||||
action.contLen = sizeof(SAlterMnodeInMsg);
|
action.contLen = sizeof(SDAlterMnodeMsg);
|
||||||
action.msgType = TDMT_DND_ALTER_MNODE;
|
action.msgType = TDMT_DND_ALTER_MNODE;
|
||||||
|
|
||||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||||
|
|
@ -309,14 +310,14 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
|
||||||
STransAction action = {0};
|
STransAction action = {0};
|
||||||
action.epSet = mndGetDnodeEpset(pDnode);
|
action.epSet = mndGetDnodeEpset(pDnode);
|
||||||
|
|
||||||
SCreateMnodeInMsg *pMsg = malloc(sizeof(SCreateMnodeInMsg));
|
SDCreateMnodeMsg *pMsg = malloc(sizeof(SDCreateMnodeMsg));
|
||||||
if (pMsg == NULL) return -1;
|
if (pMsg == NULL) return -1;
|
||||||
memcpy(pMsg, &createMsg, sizeof(SAlterMnodeInMsg));
|
memcpy(pMsg, &createMsg, sizeof(SDAlterMnodeMsg));
|
||||||
pMsg->dnodeId = htonl(pObj->id);
|
pMsg->dnodeId = htonl(pObj->id);
|
||||||
|
|
||||||
action.epSet = mndGetDnodeEpset(pDnode);
|
action.epSet = mndGetDnodeEpset(pDnode);
|
||||||
action.pCont = pMsg;
|
action.pCont = pMsg;
|
||||||
action.contLen = sizeof(SCreateMnodeInMsg);
|
action.contLen = sizeof(SDCreateMnodeMsg);
|
||||||
action.msgType = TDMT_DND_CREATE_MNODE;
|
action.msgType = TDMT_DND_CREATE_MNODE;
|
||||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||||
free(pMsg);
|
free(pMsg);
|
||||||
|
|
@ -327,9 +328,9 @@ static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDno
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndCreateMnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SCreateMnodeMsg *pCreate) {
|
static int32_t mndCreateMnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateMnodeMsg *pCreate) {
|
||||||
SMnodeObj mnodeObj = {0};
|
SMnodeObj mnodeObj = {0};
|
||||||
mnodeObj.id = sdbGetMaxId(pMnode->pSdb, SDB_MNODE);
|
mnodeObj.id = pDnode->id;
|
||||||
mnodeObj.createdTime = taosGetTimestampMs();
|
mnodeObj.createdTime = taosGetTimestampMs();
|
||||||
mnodeObj.updateTime = mnodeObj.createdTime;
|
mnodeObj.updateTime = mnodeObj.createdTime;
|
||||||
|
|
||||||
|
|
@ -370,7 +371,7 @@ CREATE_MNODE_OVER:
|
||||||
|
|
||||||
static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pMsg) {
|
static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pMsg) {
|
||||||
SMnode *pMnode = pMsg->pMnode;
|
SMnode *pMnode = pMsg->pMnode;
|
||||||
SCreateMnodeMsg *pCreate = pMsg->rpcMsg.pCont;
|
SMCreateMnodeMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||||
|
|
||||||
pCreate->dnodeId = htonl(pCreate->dnodeId);
|
pCreate->dnodeId = htonl(pCreate->dnodeId);
|
||||||
|
|
||||||
|
|
@ -423,7 +424,7 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
|
||||||
void *pIter = NULL;
|
void *pIter = NULL;
|
||||||
int32_t numOfReplicas = 0;
|
int32_t numOfReplicas = 0;
|
||||||
|
|
||||||
SAlterMnodeInMsg alterMsg = {0};
|
SDAlterMnodeMsg alterMsg = {0};
|
||||||
while (1) {
|
while (1) {
|
||||||
SMnodeObj *pMObj = NULL;
|
SMnodeObj *pMObj = NULL;
|
||||||
pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pMObj);
|
pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pMObj);
|
||||||
|
|
@ -449,18 +450,18 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
|
||||||
if (pMObj->id != pObj->id) {
|
if (pMObj->id != pObj->id) {
|
||||||
STransAction action = {0};
|
STransAction action = {0};
|
||||||
|
|
||||||
SAlterMnodeInMsg *pMsg = malloc(sizeof(SAlterMnodeInMsg));
|
SDAlterMnodeMsg *pMsg = malloc(sizeof(SDAlterMnodeMsg));
|
||||||
if (pMsg == NULL) {
|
if (pMsg == NULL) {
|
||||||
sdbCancelFetch(pSdb, pIter);
|
sdbCancelFetch(pSdb, pIter);
|
||||||
sdbRelease(pSdb, pMObj);
|
sdbRelease(pSdb, pMObj);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memcpy(pMsg, &alterMsg, sizeof(SAlterMnodeInMsg));
|
memcpy(pMsg, &alterMsg, sizeof(SDAlterMnodeMsg));
|
||||||
|
|
||||||
pMsg->dnodeId = htonl(pMObj->id);
|
pMsg->dnodeId = htonl(pMObj->id);
|
||||||
action.epSet = mndGetDnodeEpset(pMObj->pDnode);
|
action.epSet = mndGetDnodeEpset(pMObj->pDnode);
|
||||||
action.pCont = pMsg;
|
action.pCont = pMsg;
|
||||||
action.contLen = sizeof(SAlterMnodeInMsg);
|
action.contLen = sizeof(SDAlterMnodeMsg);
|
||||||
action.msgType = TDMT_DND_ALTER_MNODE;
|
action.msgType = TDMT_DND_ALTER_MNODE;
|
||||||
|
|
||||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||||
|
|
@ -478,7 +479,7 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
|
||||||
STransAction action = {0};
|
STransAction action = {0};
|
||||||
action.epSet = mndGetDnodeEpset(pDnode);
|
action.epSet = mndGetDnodeEpset(pDnode);
|
||||||
|
|
||||||
SDropMnodeInMsg *pMsg = malloc(sizeof(SDropMnodeInMsg));
|
SDDropMnodeMsg *pMsg = malloc(sizeof(SDDropMnodeMsg));
|
||||||
if (pMsg == NULL) {
|
if (pMsg == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -487,7 +488,7 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
|
||||||
|
|
||||||
action.epSet = mndGetDnodeEpset(pDnode);
|
action.epSet = mndGetDnodeEpset(pDnode);
|
||||||
action.pCont = pMsg;
|
action.pCont = pMsg;
|
||||||
action.contLen = sizeof(SDropMnodeInMsg);
|
action.contLen = sizeof(SDDropMnodeMsg);
|
||||||
action.msgType = TDMT_DND_DROP_MNODE;
|
action.msgType = TDMT_DND_DROP_MNODE;
|
||||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||||
free(pMsg);
|
free(pMsg);
|
||||||
|
|
@ -537,7 +538,7 @@ DROP_MNODE_OVER:
|
||||||
|
|
||||||
static int32_t mndProcessDropMnodeReq(SMnodeMsg *pMsg) {
|
static int32_t mndProcessDropMnodeReq(SMnodeMsg *pMsg) {
|
||||||
SMnode *pMnode = pMsg->pMnode;
|
SMnode *pMnode = pMsg->pMnode;
|
||||||
SDropMnodeMsg *pDrop = pMsg->rpcMsg.pCont;
|
SMDropMnodeMsg *pDrop = pMsg->rpcMsg.pCont;
|
||||||
pDrop->dnodeId = htonl(pDrop->dnodeId);
|
pDrop->dnodeId = htonl(pDrop->dnodeId);
|
||||||
|
|
||||||
mDebug("mnode:%d, start to drop", pDrop->dnodeId);
|
mDebug("mnode:%d, start to drop", pDrop->dnodeId);
|
||||||
|
|
@ -562,7 +563,7 @@ static int32_t mndProcessDropMnodeReq(SMnodeMsg *pMsg) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sdbRelease(pMnode->pSdb, pMnode);
|
sdbRelease(pMnode->pSdb, pObj);
|
||||||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,446 @@
|
||||||
|
/*
|
||||||
|
* 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 "mndQnode.h"
|
||||||
|
#include "mndDnode.h"
|
||||||
|
#include "mndShow.h"
|
||||||
|
#include "mndTrans.h"
|
||||||
|
|
||||||
|
#define TSDB_QNODE_VER_NUMBER 1
|
||||||
|
#define TSDB_QNODE_RESERVE_SIZE 64
|
||||||
|
|
||||||
|
static SSdbRaw *mndQnodeActionEncode(SQnodeObj *pObj);
|
||||||
|
static SSdbRow *mndQnodeActionDecode(SSdbRaw *pRaw);
|
||||||
|
static int32_t mndQnodeActionInsert(SSdb *pSdb, SQnodeObj *pObj);
|
||||||
|
static int32_t mndQnodeActionDelete(SSdb *pSdb, SQnodeObj *pObj);
|
||||||
|
static int32_t mndQnodeActionUpdate(SSdb *pSdb, SQnodeObj *pOldQnode, SQnodeObj *pNewQnode);
|
||||||
|
static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pMsg);
|
||||||
|
static int32_t mndProcessDropQnodeReq(SMnodeMsg *pMsg);
|
||||||
|
static int32_t mndProcessCreateQnodeRsp(SMnodeMsg *pMsg);
|
||||||
|
static int32_t mndProcessDropQnodeRsp(SMnodeMsg *pMsg);
|
||||||
|
static int32_t mndGetQnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||||
|
static int32_t mndRetrieveQnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows);
|
||||||
|
static void mndCancelGetNextQnode(SMnode *pMnode, void *pIter);
|
||||||
|
|
||||||
|
int32_t mndInitQnode(SMnode *pMnode) {
|
||||||
|
SSdbTable table = {.sdbType = SDB_QNODE,
|
||||||
|
.keyType = SDB_KEY_INT32,
|
||||||
|
.encodeFp = (SdbEncodeFp)mndQnodeActionEncode,
|
||||||
|
.decodeFp = (SdbDecodeFp)mndQnodeActionDecode,
|
||||||
|
.insertFp = (SdbInsertFp)mndQnodeActionInsert,
|
||||||
|
.updateFp = (SdbUpdateFp)mndQnodeActionUpdate,
|
||||||
|
.deleteFp = (SdbDeleteFp)mndQnodeActionDelete};
|
||||||
|
|
||||||
|
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_QNODE, mndProcessCreateQnodeReq);
|
||||||
|
mndSetMsgHandle(pMnode, TDMT_MND_DROP_QNODE, mndProcessDropQnodeReq);
|
||||||
|
mndSetMsgHandle(pMnode, TDMT_DND_CREATE_QNODE_RSP, mndProcessCreateQnodeRsp);
|
||||||
|
mndSetMsgHandle(pMnode, TDMT_DND_DROP_QNODE_RSP, mndProcessDropQnodeRsp);
|
||||||
|
|
||||||
|
mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_QNODE, mndGetQnodeMeta);
|
||||||
|
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_QNODE, mndRetrieveQnodes);
|
||||||
|
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_QNODE, mndCancelGetNextQnode);
|
||||||
|
|
||||||
|
return sdbSetTable(pMnode->pSdb, table);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mndCleanupQnode(SMnode *pMnode) {}
|
||||||
|
|
||||||
|
static SQnodeObj *mndAcquireQnode(SMnode *pMnode, int32_t qnodeId) {
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
SQnodeObj *pObj = sdbAcquire(pSdb, SDB_QNODE, &qnodeId);
|
||||||
|
if (pObj == NULL) {
|
||||||
|
terrno = TSDB_CODE_MND_QNODE_NOT_EXIST;
|
||||||
|
}
|
||||||
|
return pObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mndReleaseQnode(SMnode *pMnode, SQnodeObj *pObj) {
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
sdbRelease(pSdb, pObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
static SSdbRaw *mndQnodeActionEncode(SQnodeObj *pObj) {
|
||||||
|
SSdbRaw *pRaw = sdbAllocRaw(SDB_QNODE, TSDB_QNODE_VER_NUMBER, sizeof(SQnodeObj) + TSDB_QNODE_RESERVE_SIZE);
|
||||||
|
if (pRaw == NULL) return NULL;
|
||||||
|
|
||||||
|
int32_t dataPos = 0;
|
||||||
|
SDB_SET_INT32(pRaw, dataPos, pObj->id);
|
||||||
|
SDB_SET_INT64(pRaw, dataPos, pObj->createdTime)
|
||||||
|
SDB_SET_INT64(pRaw, dataPos, pObj->updateTime)
|
||||||
|
SDB_SET_RESERVE(pRaw, dataPos, TSDB_QNODE_RESERVE_SIZE)
|
||||||
|
|
||||||
|
return pRaw;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SSdbRow *mndQnodeActionDecode(SSdbRaw *pRaw) {
|
||||||
|
int8_t sver = 0;
|
||||||
|
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||||
|
|
||||||
|
if (sver != TSDB_QNODE_VER_NUMBER) {
|
||||||
|
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||||
|
mError("failed to decode qnode since %s", terrstr());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSdbRow *pRow = sdbAllocRow(sizeof(SQnodeObj));
|
||||||
|
SQnodeObj *pObj = sdbGetRowObj(pRow);
|
||||||
|
if (pObj == NULL) return NULL;
|
||||||
|
|
||||||
|
int32_t dataPos = 0;
|
||||||
|
SDB_GET_INT32(pRaw, pRow, dataPos, &pObj->id)
|
||||||
|
SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->createdTime)
|
||||||
|
SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->updateTime)
|
||||||
|
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_QNODE_RESERVE_SIZE)
|
||||||
|
|
||||||
|
return pRow;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndQnodeActionInsert(SSdb *pSdb, SQnodeObj *pObj) {
|
||||||
|
mTrace("qnode:%d, perform insert action", pObj->id);
|
||||||
|
pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id);
|
||||||
|
if (pObj->pDnode == NULL) {
|
||||||
|
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||||
|
mError("qnode:%d, failed to perform insert action since %s", pObj->id, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndQnodeActionDelete(SSdb *pSdb, SQnodeObj *pObj) {
|
||||||
|
mTrace("qnode:%d, perform delete action", pObj->id);
|
||||||
|
if (pObj->pDnode != NULL) {
|
||||||
|
sdbRelease(pSdb, pObj->pDnode);
|
||||||
|
pObj->pDnode = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndQnodeActionUpdate(SSdb *pSdb, SQnodeObj *pOldQnode, SQnodeObj *pNewQnode) {
|
||||||
|
mTrace("qnode:%d, perform update action", pOldQnode->id);
|
||||||
|
pOldQnode->updateTime = pNewQnode->updateTime;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndSetCreateQnodeRedoLogs(STrans *pTrans, SQnodeObj *pObj) {
|
||||||
|
SSdbRaw *pRedoRaw = mndQnodeActionEncode(pObj);
|
||||||
|
if (pRedoRaw == NULL) return -1;
|
||||||
|
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||||
|
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndSetCreateQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) {
|
||||||
|
SSdbRaw *pCommitRaw = mndQnodeActionEncode(pObj);
|
||||||
|
if (pCommitRaw == NULL) return -1;
|
||||||
|
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||||
|
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) {
|
||||||
|
SDCreateQnodeMsg *pMsg = malloc(sizeof(SDCreateQnodeMsg));
|
||||||
|
if (pMsg == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
pMsg->dnodeId = htonl(pDnode->id);
|
||||||
|
|
||||||
|
STransAction action = {0};
|
||||||
|
action.epSet = mndGetDnodeEpset(pDnode);
|
||||||
|
action.pCont = pMsg;
|
||||||
|
action.contLen = sizeof(SDCreateQnodeMsg);
|
||||||
|
action.msgType = TDMT_DND_CREATE_QNODE;
|
||||||
|
|
||||||
|
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||||
|
free(pMsg);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndCreateQnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateQnodeMsg *pCreate) {
|
||||||
|
SQnodeObj qnodeObj = {0};
|
||||||
|
qnodeObj.id = pDnode->id;
|
||||||
|
qnodeObj.createdTime = taosGetTimestampMs();
|
||||||
|
qnodeObj.updateTime = qnodeObj.createdTime;
|
||||||
|
|
||||||
|
int32_t code = -1;
|
||||||
|
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg);
|
||||||
|
if (pTrans == NULL) {
|
||||||
|
mError("qnode:%d, failed to create since %s", pCreate->dnodeId, terrstr());
|
||||||
|
goto CREATE_QNODE_OVER;
|
||||||
|
}
|
||||||
|
mDebug("trans:%d, used to create qnode:%d", pTrans->id, pCreate->dnodeId);
|
||||||
|
|
||||||
|
if (mndSetCreateQnodeRedoLogs(pTrans, &qnodeObj) != 0) {
|
||||||
|
mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr());
|
||||||
|
goto CREATE_QNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mndSetCreateQnodeCommitLogs(pTrans, &qnodeObj) != 0) {
|
||||||
|
mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr());
|
||||||
|
goto CREATE_QNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mndSetCreateQnodeRedoActions(pTrans, pDnode, &qnodeObj) != 0) {
|
||||||
|
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||||
|
goto CREATE_QNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||||
|
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||||
|
goto CREATE_QNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = 0;
|
||||||
|
|
||||||
|
CREATE_QNODE_OVER:
|
||||||
|
mndTransDrop(pTrans);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pMsg) {
|
||||||
|
SMnode *pMnode = pMsg->pMnode;
|
||||||
|
SMCreateQnodeMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||||
|
|
||||||
|
pCreate->dnodeId = htonl(pCreate->dnodeId);
|
||||||
|
|
||||||
|
mDebug("qnode:%d, start to create", pCreate->dnodeId);
|
||||||
|
|
||||||
|
SQnodeObj *pObj = mndAcquireQnode(pMnode, pCreate->dnodeId);
|
||||||
|
if (pObj != NULL) {
|
||||||
|
mError("qnode:%d, qnode already exist", pObj->id);
|
||||||
|
mndReleaseQnode(pMnode, pObj);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCreate->dnodeId);
|
||||||
|
if (pDnode == NULL) {
|
||||||
|
mError("qnode:%d, dnode not exist", pCreate->dnodeId);
|
||||||
|
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t code = mndCreateQnode(pMnode, pMsg, pDnode, pCreate);
|
||||||
|
mndReleaseDnode(pMnode, pDnode);
|
||||||
|
|
||||||
|
if (code != 0) {
|
||||||
|
mError("qnode:%d, failed to create since %s", pCreate->dnodeId, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndSetDropQnodeRedoLogs(STrans *pTrans, SQnodeObj *pObj) {
|
||||||
|
SSdbRaw *pRedoRaw = mndQnodeActionEncode(pObj);
|
||||||
|
if (pRedoRaw == NULL) return -1;
|
||||||
|
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||||
|
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndSetDropQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) {
|
||||||
|
SSdbRaw *pCommitRaw = mndQnodeActionEncode(pObj);
|
||||||
|
if (pCommitRaw == NULL) return -1;
|
||||||
|
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||||
|
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) {
|
||||||
|
SDDropQnodeMsg *pMsg = malloc(sizeof(SDDropQnodeMsg));
|
||||||
|
if (pMsg == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
pMsg->dnodeId = htonl(pDnode->id);
|
||||||
|
|
||||||
|
STransAction action = {0};
|
||||||
|
action.epSet = mndGetDnodeEpset(pDnode);
|
||||||
|
action.pCont = pMsg;
|
||||||
|
action.contLen = sizeof(SDDropQnodeMsg);
|
||||||
|
action.msgType = TDMT_DND_DROP_QNODE;
|
||||||
|
|
||||||
|
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||||
|
free(pMsg);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndDropQnode(SMnode *pMnode, SMnodeMsg *pMsg, SQnodeObj *pObj) {
|
||||||
|
int32_t code = -1;
|
||||||
|
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg);
|
||||||
|
if (pTrans == NULL) {
|
||||||
|
mError("qnode:%d, failed to drop since %s", pObj->id, terrstr());
|
||||||
|
goto DROP_QNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
mDebug("trans:%d, used to drop qnode:%d", pTrans->id, pObj->id);
|
||||||
|
|
||||||
|
if (mndSetDropQnodeRedoLogs(pTrans, pObj) != 0) {
|
||||||
|
mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr());
|
||||||
|
goto DROP_QNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mndSetDropQnodeCommitLogs(pTrans, pObj) != 0) {
|
||||||
|
mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr());
|
||||||
|
goto DROP_QNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mndSetDropQnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) {
|
||||||
|
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||||
|
goto DROP_QNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||||
|
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||||
|
goto DROP_QNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = 0;
|
||||||
|
|
||||||
|
DROP_QNODE_OVER:
|
||||||
|
mndTransDrop(pTrans);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndProcessDropQnodeReq(SMnodeMsg *pMsg) {
|
||||||
|
SMnode *pMnode = pMsg->pMnode;
|
||||||
|
SMDropQnodeMsg *pDrop = pMsg->rpcMsg.pCont;
|
||||||
|
pDrop->dnodeId = htonl(pDrop->dnodeId);
|
||||||
|
|
||||||
|
mDebug("qnode:%d, start to drop", pDrop->dnodeId);
|
||||||
|
|
||||||
|
if (pDrop->dnodeId <= 0) {
|
||||||
|
terrno = TSDB_CODE_SDB_APP_ERROR;
|
||||||
|
mError("qnode:%d, failed to drop since %s", pDrop->dnodeId, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SQnodeObj *pObj = mndAcquireQnode(pMnode, pDrop->dnodeId);
|
||||||
|
if (pObj == NULL) {
|
||||||
|
mError("qnode:%d, not exist", pDrop->dnodeId);
|
||||||
|
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t code = mndDropQnode(pMnode, pMsg, pObj);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("qnode:%d, failed to drop since %s", pMnode->dnodeId, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sdbRelease(pMnode->pSdb, pMnode);
|
||||||
|
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndProcessCreateQnodeRsp(SMnodeMsg *pMsg) {
|
||||||
|
mndTransProcessRsp(pMsg);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndProcessDropQnodeRsp(SMnodeMsg *pMsg) {
|
||||||
|
mndTransProcessRsp(pMsg);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndGetQnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||||
|
SMnode *pMnode = pMsg->pMnode;
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
|
||||||
|
int32_t cols = 0;
|
||||||
|
SSchema *pSchema = pMeta->pSchema;
|
||||||
|
|
||||||
|
pShow->bytes[cols] = 2;
|
||||||
|
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
|
||||||
|
strcpy(pSchema[cols].name, "id");
|
||||||
|
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pShow->bytes[cols] = TSDB_EP_LEN + VARSTR_HEADER_SIZE;
|
||||||
|
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||||
|
strcpy(pSchema[cols].name, "endpoint");
|
||||||
|
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pShow->bytes[cols] = 8;
|
||||||
|
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||||
|
strcpy(pSchema[cols].name, "create_time");
|
||||||
|
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pMeta->numOfColumns = htonl(cols);
|
||||||
|
pShow->numOfColumns = cols;
|
||||||
|
|
||||||
|
pShow->offset[0] = 0;
|
||||||
|
for (int32_t i = 1; i < cols; ++i) {
|
||||||
|
pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
pShow->numOfRows = sdbGetSize(pSdb, SDB_QNODE);
|
||||||
|
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
|
||||||
|
strcpy(pMeta->tbFname, mndShowStr(pShow->type));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndRetrieveQnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) {
|
||||||
|
SMnode *pMnode = pMsg->pMnode;
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
int32_t numOfRows = 0;
|
||||||
|
int32_t cols = 0;
|
||||||
|
SQnodeObj *pObj = NULL;
|
||||||
|
char *pWrite;
|
||||||
|
|
||||||
|
while (numOfRows < rows) {
|
||||||
|
pShow->pIter = sdbFetch(pSdb, SDB_QNODE, pShow->pIter, (void **)&pObj);
|
||||||
|
if (pShow->pIter == NULL) break;
|
||||||
|
|
||||||
|
cols = 0;
|
||||||
|
|
||||||
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
|
*(int16_t *)pWrite = pObj->id;
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
|
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pObj->pDnode->ep, pShow->bytes[cols]);
|
||||||
|
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
|
*(int64_t *)pWrite = pObj->createdTime;
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
numOfRows++;
|
||||||
|
sdbRelease(pSdb, pObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||||
|
pShow->numOfReads += numOfRows;
|
||||||
|
|
||||||
|
return numOfRows;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mndCancelGetNextQnode(SMnode *pMnode, void *pIter) {
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
sdbCancelFetch(pSdb, pIter);
|
||||||
|
}
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowMsg *pMsg);
|
static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowMsg *pMsg);
|
||||||
static void mndFreeShowObj(SShowObj *pShow);
|
static void mndFreeShowObj(SShowObj *pShow);
|
||||||
static SShowObj *mndAcquireShowObj(SMnode *pMnode, int32_t showId);
|
static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId);
|
||||||
static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove);
|
static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove);
|
||||||
static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg);
|
static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg);
|
||||||
static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMsg);
|
static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMsg);
|
||||||
|
|
@ -52,8 +52,8 @@ void mndCleanupShow(SMnode *pMnode) {
|
||||||
static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowMsg *pMsg) {
|
static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowMsg *pMsg) {
|
||||||
SShowMgmt *pMgmt = &pMnode->showMgmt;
|
SShowMgmt *pMgmt = &pMnode->showMgmt;
|
||||||
|
|
||||||
int32_t showId = atomic_add_fetch_32(&pMgmt->showId, 1);
|
int64_t showId = atomic_add_fetch_64(&pMgmt->showId, 1);
|
||||||
if (showId == 0) atomic_add_fetch_32(&pMgmt->showId, 1);
|
if (showId == 0) atomic_add_fetch_64(&pMgmt->showId, 1);
|
||||||
|
|
||||||
int32_t size = sizeof(SShowObj) + pMsg->payloadLen;
|
int32_t size = sizeof(SShowObj) + pMsg->payloadLen;
|
||||||
SShowObj showObj = {0};
|
SShowObj showObj = {0};
|
||||||
|
|
@ -65,14 +65,14 @@ static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowMsg *pMsg) {
|
||||||
memcpy(showObj.payload, pMsg->payload, pMsg->payloadLen);
|
memcpy(showObj.payload, pMsg->payload, pMsg->payloadLen);
|
||||||
|
|
||||||
int32_t keepTime = pMnode->cfg.shellActivityTimer * 6 * 1000;
|
int32_t keepTime = pMnode->cfg.shellActivityTimer * 6 * 1000;
|
||||||
SShowObj *pShow = taosCachePut(pMgmt->cache, &showId, sizeof(int32_t), &showObj, size, keepTime);
|
SShowObj *pShow = taosCachePut(pMgmt->cache, &showId, sizeof(int64_t), &showObj, size, keepTime);
|
||||||
if (pShow == NULL) {
|
if (pShow == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
mError("show:%d, failed to put into cache since %s", showId, terrstr());
|
mError("show:0x%"PRIx64", failed to put into cache since %s", showId, terrstr());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
mTrace("show:%d, is created, data:%p", showId, pShow);
|
mTrace("show:0x%"PRIx64", is created, data:%p", showId, pShow);
|
||||||
return pShow;
|
return pShow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,25 +87,25 @@ static void mndFreeShowObj(SShowObj *pShow) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mTrace("show:%d, is destroyed, data:%p", pShow->id, pShow);
|
mTrace("show:0x%d, is destroyed, data:%p", pShow->id, pShow);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SShowObj *mndAcquireShowObj(SMnode *pMnode, int32_t showId) {
|
static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId) {
|
||||||
SShowMgmt *pMgmt = &pMnode->showMgmt;
|
SShowMgmt *pMgmt = &pMnode->showMgmt;
|
||||||
|
|
||||||
SShowObj *pShow = taosCacheAcquireByKey(pMgmt->cache, &showId, sizeof(int32_t));
|
SShowObj *pShow = taosCacheAcquireByKey(pMgmt->cache, &showId, sizeof(showId));
|
||||||
if (pShow == NULL) {
|
if (pShow == NULL) {
|
||||||
mError("show:%d, already destroyed", showId);
|
mError("show:0x%"PRIx64", already destroyed", showId);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
mTrace("show:%d, acquired from cache, data:%p", pShow->id, pShow);
|
mTrace("show:0x%"PRIx64", acquired from cache, data:%p", pShow->id, pShow);
|
||||||
return pShow;
|
return pShow;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) {
|
static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) {
|
||||||
if (pShow == NULL) return;
|
if (pShow == NULL) return;
|
||||||
mTrace("show:%d, released from cache, data:%p force:%d", pShow->id, pShow, forceRemove);
|
mTrace("show:0x%"PRIx64", released from cache, data:%p force:%d", pShow->id, pShow, forceRemove);
|
||||||
|
|
||||||
// A bug in tcache.c
|
// A bug in tcache.c
|
||||||
forceRemove = 0;
|
forceRemove = 0;
|
||||||
|
|
@ -146,18 +146,18 @@ static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg) {
|
||||||
if (pRsp == NULL) {
|
if (pRsp == NULL) {
|
||||||
mndReleaseShowObj(pShow, true);
|
mndReleaseShowObj(pShow, true);
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
mError("show:%d, failed to process show-meta msg:%s since malloc rsp error", pShow->id, mndShowStr(type));
|
mError("show:0x%"PRIx64", failed to process show-meta msg:%s since malloc rsp error", pShow->id, mndShowStr(type));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = (*metaFp)(pMnodeMsg, pShow, &pRsp->tableMeta);
|
int32_t code = (*metaFp)(pMnodeMsg, pShow, &pRsp->tableMeta);
|
||||||
mDebug("show:%d, get meta finished, numOfRows:%d cols:%d type:%s result:%s", pShow->id, pShow->numOfRows,
|
mDebug("show:0x%"PRIx64", get meta finished, numOfRows:%d cols:%d type:%s result:%s", pShow->id, pShow->numOfRows,
|
||||||
pShow->numOfColumns, mndShowStr(type), tstrerror(code));
|
pShow->numOfColumns, mndShowStr(type), tstrerror(code));
|
||||||
|
|
||||||
if (code == TSDB_CODE_SUCCESS) {
|
if (code == TSDB_CODE_SUCCESS) {
|
||||||
pMnodeMsg->contLen = sizeof(SShowRsp) + sizeof(SSchema) * pShow->numOfColumns;
|
pMnodeMsg->contLen = sizeof(SShowRsp) + sizeof(SSchema) * pShow->numOfColumns;
|
||||||
pMnodeMsg->pCont = pRsp;
|
pMnodeMsg->pCont = pRsp;
|
||||||
pRsp->showId = htonl(pShow->id);
|
pRsp->showId = htobe64(pShow->id);
|
||||||
mndReleaseShowObj(pShow, false);
|
mndReleaseShowObj(pShow, false);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -175,7 +175,7 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) {
|
||||||
int32_t rowsRead = 0;
|
int32_t rowsRead = 0;
|
||||||
|
|
||||||
SRetrieveTableMsg *pRetrieve = pMnodeMsg->rpcMsg.pCont;
|
SRetrieveTableMsg *pRetrieve = pMnodeMsg->rpcMsg.pCont;
|
||||||
int32_t showId = htonl(pRetrieve->showId);
|
int64_t showId = htobe64(pRetrieve->showId);
|
||||||
|
|
||||||
SShowObj *pShow = mndAcquireShowObj(pMnode, showId);
|
SShowObj *pShow = mndAcquireShowObj(pMnode, showId);
|
||||||
if (pShow == NULL) {
|
if (pShow == NULL) {
|
||||||
|
|
@ -188,15 +188,15 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) {
|
||||||
if (retrieveFp == NULL) {
|
if (retrieveFp == NULL) {
|
||||||
mndReleaseShowObj(pShow, false);
|
mndReleaseShowObj(pShow, false);
|
||||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||||
mError("show:%d, failed to retrieve data since %s", pShow->id, terrstr());
|
mError("show:0x%"PRIx64", failed to retrieve data since %s", pShow->id, terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
mDebug("show:%d, start retrieve data, numOfReads:%d numOfRows:%d type:%s", pShow->id, pShow->numOfReads,
|
mDebug("show:0x%"PRIx64", start retrieve data, numOfReads:%d numOfRows:%d type:%s", pShow->id, pShow->numOfReads,
|
||||||
pShow->numOfRows, mndShowStr(pShow->type));
|
pShow->numOfRows, mndShowStr(pShow->type));
|
||||||
|
|
||||||
if (mndCheckRetrieveFinished(pShow)) {
|
if (mndCheckRetrieveFinished(pShow)) {
|
||||||
mDebug("show:%d, read finished, numOfReads:%d numOfRows:%d", pShow->id, pShow->numOfReads, pShow->numOfRows);
|
mDebug("show:0x%"PRIx64", read finished, numOfReads:%d numOfRows:%d", pShow->id, pShow->numOfReads, pShow->numOfRows);
|
||||||
pShow->numOfReads = pShow->numOfRows;
|
pShow->numOfReads = pShow->numOfRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -219,7 +219,7 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) {
|
||||||
if (pRsp == NULL) {
|
if (pRsp == NULL) {
|
||||||
mndReleaseShowObj(pShow, false);
|
mndReleaseShowObj(pShow, false);
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
mError("show:%d, failed to retrieve data since %s", pShow->id, terrstr());
|
mError("show:0x%"PRIx64", failed to retrieve data since %s", pShow->id, terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -228,7 +228,7 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) {
|
||||||
rowsRead = (*retrieveFp)(pMnodeMsg, pShow, pRsp->data, rowsToRead);
|
rowsRead = (*retrieveFp)(pMnodeMsg, pShow, pRsp->data, rowsToRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
mDebug("show:%d, stop retrieve data, rowsRead:%d rowsToRead:%d", pShow->id, rowsRead, rowsToRead);
|
mDebug("show:0x%"PRIx64", stop retrieve data, rowsRead:%d rowsToRead:%d", pShow->id, rowsRead, rowsToRead);
|
||||||
|
|
||||||
pRsp->numOfRows = htonl(rowsRead);
|
pRsp->numOfRows = htonl(rowsRead);
|
||||||
pRsp->precision = TSDB_TIME_PRECISION_MILLI; // millisecond time precision
|
pRsp->precision = TSDB_TIME_PRECISION_MILLI; // millisecond time precision
|
||||||
|
|
@ -238,10 +238,10 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) {
|
||||||
|
|
||||||
if (rowsRead == 0 || rowsToRead == 0 || (rowsRead == rowsToRead && pShow->numOfRows == pShow->numOfReads)) {
|
if (rowsRead == 0 || rowsToRead == 0 || (rowsRead == rowsToRead && pShow->numOfRows == pShow->numOfReads)) {
|
||||||
pRsp->completed = 1;
|
pRsp->completed = 1;
|
||||||
mDebug("show:%d, retrieve completed", pShow->id);
|
mDebug("show:0x%"PRIx64", retrieve completed", pShow->id);
|
||||||
mndReleaseShowObj(pShow, true);
|
mndReleaseShowObj(pShow, true);
|
||||||
} else {
|
} else {
|
||||||
mDebug("show:%d, retrieve not completed yet", pShow->id);
|
mDebug("show:0x%"PRIx64", retrieve not completed yet", pShow->id);
|
||||||
mndReleaseShowObj(pShow, false);
|
mndReleaseShowObj(pShow, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -262,6 +262,12 @@ char *mndShowStr(int32_t showType) {
|
||||||
return "show dnodes";
|
return "show dnodes";
|
||||||
case TSDB_MGMT_TABLE_MNODE:
|
case TSDB_MGMT_TABLE_MNODE:
|
||||||
return "show mnodes";
|
return "show mnodes";
|
||||||
|
case TSDB_MGMT_TABLE_QNODE:
|
||||||
|
return "show qnodes";
|
||||||
|
case TSDB_MGMT_TABLE_SNODE:
|
||||||
|
return "show snodes";
|
||||||
|
case TSDB_MGMT_TABLE_BNODE:
|
||||||
|
return "show bnodes";
|
||||||
case TSDB_MGMT_TABLE_VGROUP:
|
case TSDB_MGMT_TABLE_VGROUP:
|
||||||
return "show vgroups";
|
return "show vgroups";
|
||||||
case TSDB_MGMT_TABLE_STB:
|
case TSDB_MGMT_TABLE_STB:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,446 @@
|
||||||
|
/*
|
||||||
|
* 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 "mndSnode.h"
|
||||||
|
#include "mndDnode.h"
|
||||||
|
#include "mndShow.h"
|
||||||
|
#include "mndTrans.h"
|
||||||
|
|
||||||
|
#define TSDB_SNODE_VER_NUMBER 1
|
||||||
|
#define TSDB_SNODE_RESERVE_SIZE 64
|
||||||
|
|
||||||
|
static SSdbRaw *mndSnodeActionEncode(SSnodeObj *pObj);
|
||||||
|
static SSdbRow *mndSnodeActionDecode(SSdbRaw *pRaw);
|
||||||
|
static int32_t mndSnodeActionInsert(SSdb *pSdb, SSnodeObj *pObj);
|
||||||
|
static int32_t mndSnodeActionDelete(SSdb *pSdb, SSnodeObj *pObj);
|
||||||
|
static int32_t mndSnodeActionUpdate(SSdb *pSdb, SSnodeObj *pOldSnode, SSnodeObj *pNewSnode);
|
||||||
|
static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pMsg);
|
||||||
|
static int32_t mndProcessDropSnodeReq(SMnodeMsg *pMsg);
|
||||||
|
static int32_t mndProcessCreateSnodeRsp(SMnodeMsg *pMsg);
|
||||||
|
static int32_t mndProcessDropSnodeRsp(SMnodeMsg *pMsg);
|
||||||
|
static int32_t mndGetSnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||||
|
static int32_t mndRetrieveSnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows);
|
||||||
|
static void mndCancelGetNextSnode(SMnode *pMnode, void *pIter);
|
||||||
|
|
||||||
|
int32_t mndInitSnode(SMnode *pMnode) {
|
||||||
|
SSdbTable table = {.sdbType = SDB_SNODE,
|
||||||
|
.keyType = SDB_KEY_INT32,
|
||||||
|
.encodeFp = (SdbEncodeFp)mndSnodeActionEncode,
|
||||||
|
.decodeFp = (SdbDecodeFp)mndSnodeActionDecode,
|
||||||
|
.insertFp = (SdbInsertFp)mndSnodeActionInsert,
|
||||||
|
.updateFp = (SdbUpdateFp)mndSnodeActionUpdate,
|
||||||
|
.deleteFp = (SdbDeleteFp)mndSnodeActionDelete};
|
||||||
|
|
||||||
|
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_SNODE, mndProcessCreateSnodeReq);
|
||||||
|
mndSetMsgHandle(pMnode, TDMT_MND_DROP_SNODE, mndProcessDropSnodeReq);
|
||||||
|
mndSetMsgHandle(pMnode, TDMT_DND_CREATE_SNODE_RSP, mndProcessCreateSnodeRsp);
|
||||||
|
mndSetMsgHandle(pMnode, TDMT_DND_DROP_SNODE_RSP, mndProcessDropSnodeRsp);
|
||||||
|
|
||||||
|
mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_SNODE, mndGetSnodeMeta);
|
||||||
|
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_SNODE, mndRetrieveSnodes);
|
||||||
|
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_SNODE, mndCancelGetNextSnode);
|
||||||
|
|
||||||
|
return sdbSetTable(pMnode->pSdb, table);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mndCleanupSnode(SMnode *pMnode) {}
|
||||||
|
|
||||||
|
static SSnodeObj *mndAcquireSnode(SMnode *pMnode, int32_t snodeId) {
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
SSnodeObj *pObj = sdbAcquire(pSdb, SDB_SNODE, &snodeId);
|
||||||
|
if (pObj == NULL) {
|
||||||
|
terrno = TSDB_CODE_MND_SNODE_NOT_EXIST;
|
||||||
|
}
|
||||||
|
return pObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mndReleaseSnode(SMnode *pMnode, SSnodeObj *pObj) {
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
sdbRelease(pSdb, pObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
static SSdbRaw *mndSnodeActionEncode(SSnodeObj *pObj) {
|
||||||
|
SSdbRaw *pRaw = sdbAllocRaw(SDB_SNODE, TSDB_SNODE_VER_NUMBER, sizeof(SSnodeObj) + TSDB_SNODE_RESERVE_SIZE);
|
||||||
|
if (pRaw == NULL) return NULL;
|
||||||
|
|
||||||
|
int32_t dataPos = 0;
|
||||||
|
SDB_SET_INT32(pRaw, dataPos, pObj->id);
|
||||||
|
SDB_SET_INT64(pRaw, dataPos, pObj->createdTime)
|
||||||
|
SDB_SET_INT64(pRaw, dataPos, pObj->updateTime)
|
||||||
|
SDB_SET_RESERVE(pRaw, dataPos, TSDB_SNODE_RESERVE_SIZE)
|
||||||
|
|
||||||
|
return pRaw;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SSdbRow *mndSnodeActionDecode(SSdbRaw *pRaw) {
|
||||||
|
int8_t sver = 0;
|
||||||
|
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||||
|
|
||||||
|
if (sver != TSDB_SNODE_VER_NUMBER) {
|
||||||
|
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||||
|
mError("failed to decode snode since %s", terrstr());
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSdbRow *pRow = sdbAllocRow(sizeof(SSnodeObj));
|
||||||
|
SSnodeObj *pObj = sdbGetRowObj(pRow);
|
||||||
|
if (pObj == NULL) return NULL;
|
||||||
|
|
||||||
|
int32_t dataPos = 0;
|
||||||
|
SDB_GET_INT32(pRaw, pRow, dataPos, &pObj->id)
|
||||||
|
SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->createdTime)
|
||||||
|
SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->updateTime)
|
||||||
|
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_SNODE_RESERVE_SIZE)
|
||||||
|
|
||||||
|
return pRow;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndSnodeActionInsert(SSdb *pSdb, SSnodeObj *pObj) {
|
||||||
|
mTrace("snode:%d, perform insert action", pObj->id);
|
||||||
|
pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id);
|
||||||
|
if (pObj->pDnode == NULL) {
|
||||||
|
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||||
|
mError("snode:%d, failed to perform insert action since %s", pObj->id, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndSnodeActionDelete(SSdb *pSdb, SSnodeObj *pObj) {
|
||||||
|
mTrace("snode:%d, perform delete action", pObj->id);
|
||||||
|
if (pObj->pDnode != NULL) {
|
||||||
|
sdbRelease(pSdb, pObj->pDnode);
|
||||||
|
pObj->pDnode = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndSnodeActionUpdate(SSdb *pSdb, SSnodeObj *pOldSnode, SSnodeObj *pNewSnode) {
|
||||||
|
mTrace("snode:%d, perform update action", pOldSnode->id);
|
||||||
|
pOldSnode->updateTime = pNewSnode->updateTime;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndSetCreateSnodeRedoLogs(STrans *pTrans, SSnodeObj *pObj) {
|
||||||
|
SSdbRaw *pRedoRaw = mndSnodeActionEncode(pObj);
|
||||||
|
if (pRedoRaw == NULL) return -1;
|
||||||
|
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||||
|
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndSetCreateSnodeCommitLogs(STrans *pTrans, SSnodeObj *pObj) {
|
||||||
|
SSdbRaw *pCommitRaw = mndSnodeActionEncode(pObj);
|
||||||
|
if (pCommitRaw == NULL) return -1;
|
||||||
|
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||||
|
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) {
|
||||||
|
SDCreateSnodeMsg *pMsg = malloc(sizeof(SDCreateSnodeMsg));
|
||||||
|
if (pMsg == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
pMsg->dnodeId = htonl(pDnode->id);
|
||||||
|
|
||||||
|
STransAction action = {0};
|
||||||
|
action.epSet = mndGetDnodeEpset(pDnode);
|
||||||
|
action.pCont = pMsg;
|
||||||
|
action.contLen = sizeof(SDCreateSnodeMsg);
|
||||||
|
action.msgType = TDMT_DND_CREATE_SNODE;
|
||||||
|
|
||||||
|
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||||
|
free(pMsg);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndCreateSnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateSnodeMsg *pCreate) {
|
||||||
|
SSnodeObj snodeObj = {0};
|
||||||
|
snodeObj.id = pDnode->id;
|
||||||
|
snodeObj.createdTime = taosGetTimestampMs();
|
||||||
|
snodeObj.updateTime = snodeObj.createdTime;
|
||||||
|
|
||||||
|
int32_t code = -1;
|
||||||
|
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg);
|
||||||
|
if (pTrans == NULL) {
|
||||||
|
mError("snode:%d, failed to create since %s", pCreate->dnodeId, terrstr());
|
||||||
|
goto CREATE_SNODE_OVER;
|
||||||
|
}
|
||||||
|
mDebug("trans:%d, used to create snode:%d", pTrans->id, pCreate->dnodeId);
|
||||||
|
|
||||||
|
if (mndSetCreateSnodeRedoLogs(pTrans, &snodeObj) != 0) {
|
||||||
|
mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr());
|
||||||
|
goto CREATE_SNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mndSetCreateSnodeCommitLogs(pTrans, &snodeObj) != 0) {
|
||||||
|
mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr());
|
||||||
|
goto CREATE_SNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mndSetCreateSnodeRedoActions(pTrans, pDnode, &snodeObj) != 0) {
|
||||||
|
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||||
|
goto CREATE_SNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||||
|
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||||
|
goto CREATE_SNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = 0;
|
||||||
|
|
||||||
|
CREATE_SNODE_OVER:
|
||||||
|
mndTransDrop(pTrans);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pMsg) {
|
||||||
|
SMnode *pMnode = pMsg->pMnode;
|
||||||
|
SMCreateSnodeMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||||
|
|
||||||
|
pCreate->dnodeId = htonl(pCreate->dnodeId);
|
||||||
|
|
||||||
|
mDebug("snode:%d, start to create", pCreate->dnodeId);
|
||||||
|
|
||||||
|
SSnodeObj *pObj = mndAcquireSnode(pMnode, pCreate->dnodeId);
|
||||||
|
if (pObj != NULL) {
|
||||||
|
mError("snode:%d, snode already exist", pObj->id);
|
||||||
|
mndReleaseSnode(pMnode, pObj);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCreate->dnodeId);
|
||||||
|
if (pDnode == NULL) {
|
||||||
|
mError("snode:%d, dnode not exist", pCreate->dnodeId);
|
||||||
|
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t code = mndCreateSnode(pMnode, pMsg, pDnode, pCreate);
|
||||||
|
mndReleaseDnode(pMnode, pDnode);
|
||||||
|
|
||||||
|
if (code != 0) {
|
||||||
|
mError("snode:%d, failed to create since %s", pCreate->dnodeId, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndSetDropSnodeRedoLogs(STrans *pTrans, SSnodeObj *pObj) {
|
||||||
|
SSdbRaw *pRedoRaw = mndSnodeActionEncode(pObj);
|
||||||
|
if (pRedoRaw == NULL) return -1;
|
||||||
|
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||||
|
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndSetDropSnodeCommitLogs(STrans *pTrans, SSnodeObj *pObj) {
|
||||||
|
SSdbRaw *pCommitRaw = mndSnodeActionEncode(pObj);
|
||||||
|
if (pCommitRaw == NULL) return -1;
|
||||||
|
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||||
|
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) {
|
||||||
|
SDDropSnodeMsg *pMsg = malloc(sizeof(SDDropSnodeMsg));
|
||||||
|
if (pMsg == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
pMsg->dnodeId = htonl(pDnode->id);
|
||||||
|
|
||||||
|
STransAction action = {0};
|
||||||
|
action.epSet = mndGetDnodeEpset(pDnode);
|
||||||
|
action.pCont = pMsg;
|
||||||
|
action.contLen = sizeof(SDDropSnodeMsg);
|
||||||
|
action.msgType = TDMT_DND_DROP_SNODE;
|
||||||
|
|
||||||
|
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||||
|
free(pMsg);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndDropSnode(SMnode *pMnode, SMnodeMsg *pMsg, SSnodeObj *pObj) {
|
||||||
|
int32_t code = -1;
|
||||||
|
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg);
|
||||||
|
if (pTrans == NULL) {
|
||||||
|
mError("snode:%d, failed to drop since %s", pObj->id, terrstr());
|
||||||
|
goto DROP_SNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
mDebug("trans:%d, used to drop snode:%d", pTrans->id, pObj->id);
|
||||||
|
|
||||||
|
if (mndSetDropSnodeRedoLogs(pTrans, pObj) != 0) {
|
||||||
|
mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr());
|
||||||
|
goto DROP_SNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mndSetDropSnodeCommitLogs(pTrans, pObj) != 0) {
|
||||||
|
mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr());
|
||||||
|
goto DROP_SNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mndSetDropSnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) {
|
||||||
|
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||||
|
goto DROP_SNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||||
|
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||||
|
goto DROP_SNODE_OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = 0;
|
||||||
|
|
||||||
|
DROP_SNODE_OVER:
|
||||||
|
mndTransDrop(pTrans);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndProcessDropSnodeReq(SMnodeMsg *pMsg) {
|
||||||
|
SMnode *pMnode = pMsg->pMnode;
|
||||||
|
SMDropSnodeMsg *pDrop = pMsg->rpcMsg.pCont;
|
||||||
|
pDrop->dnodeId = htonl(pDrop->dnodeId);
|
||||||
|
|
||||||
|
mDebug("snode:%d, start to drop", pDrop->dnodeId);
|
||||||
|
|
||||||
|
if (pDrop->dnodeId <= 0) {
|
||||||
|
terrno = TSDB_CODE_SDB_APP_ERROR;
|
||||||
|
mError("snode:%d, failed to drop since %s", pDrop->dnodeId, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSnodeObj *pObj = mndAcquireSnode(pMnode, pDrop->dnodeId);
|
||||||
|
if (pObj == NULL) {
|
||||||
|
mError("snode:%d, not exist", pDrop->dnodeId);
|
||||||
|
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t code = mndDropSnode(pMnode, pMsg, pObj);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("snode:%d, failed to drop since %s", pMnode->dnodeId, terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sdbRelease(pMnode->pSdb, pMnode);
|
||||||
|
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndProcessCreateSnodeRsp(SMnodeMsg *pMsg) {
|
||||||
|
mndTransProcessRsp(pMsg);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndProcessDropSnodeRsp(SMnodeMsg *pMsg) {
|
||||||
|
mndTransProcessRsp(pMsg);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndGetSnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||||
|
SMnode *pMnode = pMsg->pMnode;
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
|
||||||
|
int32_t cols = 0;
|
||||||
|
SSchema *pSchema = pMeta->pSchema;
|
||||||
|
|
||||||
|
pShow->bytes[cols] = 2;
|
||||||
|
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
|
||||||
|
strcpy(pSchema[cols].name, "id");
|
||||||
|
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pShow->bytes[cols] = TSDB_EP_LEN + VARSTR_HEADER_SIZE;
|
||||||
|
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||||
|
strcpy(pSchema[cols].name, "endpoint");
|
||||||
|
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pShow->bytes[cols] = 8;
|
||||||
|
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||||
|
strcpy(pSchema[cols].name, "create_time");
|
||||||
|
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pMeta->numOfColumns = htonl(cols);
|
||||||
|
pShow->numOfColumns = cols;
|
||||||
|
|
||||||
|
pShow->offset[0] = 0;
|
||||||
|
for (int32_t i = 1; i < cols; ++i) {
|
||||||
|
pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
pShow->numOfRows = sdbGetSize(pSdb, SDB_SNODE);
|
||||||
|
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
|
||||||
|
strcpy(pMeta->tbFname, mndShowStr(pShow->type));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndRetrieveSnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) {
|
||||||
|
SMnode *pMnode = pMsg->pMnode;
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
int32_t numOfRows = 0;
|
||||||
|
int32_t cols = 0;
|
||||||
|
SSnodeObj *pObj = NULL;
|
||||||
|
char *pWrite;
|
||||||
|
|
||||||
|
while (numOfRows < rows) {
|
||||||
|
pShow->pIter = sdbFetch(pSdb, SDB_SNODE, pShow->pIter, (void **)&pObj);
|
||||||
|
if (pShow->pIter == NULL) break;
|
||||||
|
|
||||||
|
cols = 0;
|
||||||
|
|
||||||
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
|
*(int16_t *)pWrite = pObj->id;
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
|
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pObj->pDnode->ep, pShow->bytes[cols]);
|
||||||
|
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
|
*(int64_t *)pWrite = pObj->createdTime;
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
numOfRows++;
|
||||||
|
sdbRelease(pSdb, pObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||||
|
pShow->numOfReads += numOfRows;
|
||||||
|
|
||||||
|
return numOfRows;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mndCancelGetNextSnode(SMnode *pMnode, void *pIter) {
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
sdbCancelFetch(pSdb, pIter);
|
||||||
|
}
|
||||||
|
|
@ -201,14 +201,16 @@ static SDbObj *mndAcquireDbByStb(SMnode *pMnode, char *stbName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *mndBuildCreateStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, int *pContLen) {
|
static void *mndBuildCreateStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, int *pContLen) {
|
||||||
#if 1
|
|
||||||
SVCreateTbReq req;
|
SVCreateTbReq req;
|
||||||
void * buf;
|
void * buf;
|
||||||
int bsize;
|
int bsize;
|
||||||
SMsgHead * pMsgHead;
|
SMsgHead * pMsgHead;
|
||||||
|
|
||||||
req.ver = 0;
|
req.ver = 0;
|
||||||
req.name = pStb->name;
|
SName name = {0};
|
||||||
|
tNameFromString(&name, pStb->name, T_NAME_ACCT|T_NAME_DB|T_NAME_TABLE);
|
||||||
|
|
||||||
|
req.name = (char*) tNameGetTableName(&name);
|
||||||
req.ttl = 0;
|
req.ttl = 0;
|
||||||
req.keep = 0;
|
req.keep = 0;
|
||||||
req.type = TD_SUPER_TABLE;
|
req.type = TD_SUPER_TABLE;
|
||||||
|
|
@ -235,43 +237,12 @@ static void *mndBuildCreateStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb
|
||||||
|
|
||||||
*pContLen = sizeof(SMsgHead) + bsize;
|
*pContLen = sizeof(SMsgHead) + bsize;
|
||||||
return buf;
|
return buf;
|
||||||
|
|
||||||
#else
|
|
||||||
int32_t totalCols = pStb->numOfTags + pStb->numOfColumns;
|
|
||||||
int32_t contLen = totalCols * sizeof(SSchema) + sizeof(SCreateStbInternalMsg);
|
|
||||||
|
|
||||||
SCreateStbInternalMsg *pCreate = calloc(1, contLen);
|
|
||||||
if (pCreate == NULL) {
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
pCreate->head.contLen = htonl(contLen);
|
|
||||||
pCreate->head.vgId = htonl(pVgroup->vgId);
|
|
||||||
memcpy(pCreate->name, pStb->name, TSDB_TABLE_FNAME_LEN);
|
|
||||||
pCreate->suid = htobe64(pStb->uid);
|
|
||||||
pCreate->sverson = htonl(pStb->version);
|
|
||||||
pCreate->ttl = 0;
|
|
||||||
pCreate->keep = 0;
|
|
||||||
pCreate->numOfTags = htonl(pStb->numOfTags);
|
|
||||||
pCreate->numOfColumns = htonl(pStb->numOfColumns);
|
|
||||||
|
|
||||||
memcpy(pCreate->pSchema, pStb->pSchema, totalCols * sizeof(SSchema));
|
|
||||||
for (int32_t t = 0; t < totalCols; ++t) {
|
|
||||||
SSchema *pSchema = &pCreate->pSchema[t];
|
|
||||||
pSchema->bytes = htonl(pSchema->bytes);
|
|
||||||
pSchema->colId = htonl(pSchema->colId);
|
|
||||||
}
|
|
||||||
|
|
||||||
*pContLen = contLen;
|
|
||||||
return pCreate;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDropStbInternalMsg *mndBuildDropStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb) {
|
static SVDropStbReq *mndBuildDropStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb) {
|
||||||
int32_t contLen = sizeof(SDropStbInternalMsg);
|
int32_t contLen = sizeof(SVDropStbReq);
|
||||||
|
|
||||||
SDropStbInternalMsg *pDrop = calloc(1, contLen);
|
SVDropStbReq *pDrop = calloc(1, contLen);
|
||||||
if (pDrop == NULL) {
|
if (pDrop == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -402,7 +373,7 @@ static int32_t mndSetCreateStbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj
|
||||||
if (pIter == NULL) break;
|
if (pIter == NULL) break;
|
||||||
if (pVgroup->dbUid != pDb->uid) continue;
|
if (pVgroup->dbUid != pDb->uid) continue;
|
||||||
|
|
||||||
SDropStbInternalMsg *pMsg = mndBuildDropStbMsg(pMnode, pVgroup, pStb);
|
SVDropStbReq *pMsg = mndBuildDropStbMsg(pMnode, pVgroup, pStb);
|
||||||
if (pMsg == NULL) {
|
if (pMsg == NULL) {
|
||||||
sdbCancelFetch(pSdb, pIter);
|
sdbCancelFetch(pSdb, pIter);
|
||||||
sdbRelease(pSdb, pVgroup);
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
|
@ -413,7 +384,7 @@ static int32_t mndSetCreateStbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj
|
||||||
STransAction action = {0};
|
STransAction action = {0};
|
||||||
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||||
action.pCont = pMsg;
|
action.pCont = pMsg;
|
||||||
action.contLen = sizeof(SDropStbInternalMsg);
|
action.contLen = sizeof(SVDropStbReq);
|
||||||
action.msgType = TDMT_VND_DROP_STB;
|
action.msgType = TDMT_VND_DROP_STB;
|
||||||
if (mndTransAppendUndoAction(pTrans, &action) != 0) {
|
if (mndTransAppendUndoAction(pTrans, &action) != 0) {
|
||||||
free(pMsg);
|
free(pMsg);
|
||||||
|
|
|
||||||
|
|
@ -162,10 +162,10 @@ static SDbObj *mndAcquireDbByTopic(SMnode *pMnode, char *topicName) {
|
||||||
return mndAcquireDb(pMnode, db);
|
return mndAcquireDb(pMnode, db);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDropTopicInternalMsg *mndBuildDropTopicMsg(SMnode *pMnode, SVgObj *pVgroup, STopicObj *pTopic) {
|
static SDDropTopicMsg *mndBuildDropTopicMsg(SMnode *pMnode, SVgObj *pVgroup, STopicObj *pTopic) {
|
||||||
int32_t contLen = sizeof(SDropTopicInternalMsg);
|
int32_t contLen = sizeof(SDDropTopicMsg);
|
||||||
|
|
||||||
SDropTopicInternalMsg *pDrop = calloc(1, contLen);
|
SDDropTopicMsg *pDrop = calloc(1, contLen);
|
||||||
if (pDrop == NULL) {
|
if (pDrop == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
||||||
|
|
@ -79,17 +79,17 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) {
|
||||||
|
|
||||||
for (int32_t i = 0; i < redoLogNum; ++i) {
|
for (int32_t i = 0; i < redoLogNum; ++i) {
|
||||||
SSdbRaw *pTmp = taosArrayGetP(pTrans->redoLogs, i);
|
SSdbRaw *pTmp = taosArrayGetP(pTrans->redoLogs, i);
|
||||||
rawDataLen += sdbGetRawTotalSize(pTmp);
|
rawDataLen += (sdbGetRawTotalSize(pTmp) + 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < undoLogNum; ++i) {
|
for (int32_t i = 0; i < undoLogNum; ++i) {
|
||||||
SSdbRaw *pTmp = taosArrayGetP(pTrans->undoLogs, i);
|
SSdbRaw *pTmp = taosArrayGetP(pTrans->undoLogs, i);
|
||||||
rawDataLen += sdbGetRawTotalSize(pTmp);
|
rawDataLen += (sdbGetRawTotalSize(pTmp) + 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < commitLogNum; ++i) {
|
for (int32_t i = 0; i < commitLogNum; ++i) {
|
||||||
SSdbRaw *pTmp = taosArrayGetP(pTrans->commitLogs, i);
|
SSdbRaw *pTmp = taosArrayGetP(pTrans->commitLogs, i);
|
||||||
rawDataLen += sdbGetRawTotalSize(pTmp);
|
rawDataLen += (sdbGetRawTotalSize(pTmp) + 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < redoActionNum; ++i) {
|
for (int32_t i = 0; i < redoActionNum; ++i) {
|
||||||
|
|
@ -437,7 +437,7 @@ int32_t mndTransAppendUndoAction(STrans *pTrans, STransAction *pAction) {
|
||||||
static int32_t mndTransSync(SMnode *pMnode, STrans *pTrans) {
|
static int32_t mndTransSync(SMnode *pMnode, STrans *pTrans) {
|
||||||
SSdbRaw *pRaw = mndTransActionEncode(pTrans);
|
SSdbRaw *pRaw = mndTransActionEncode(pTrans);
|
||||||
if (pRaw == NULL) {
|
if (pRaw == NULL) {
|
||||||
mError("trans:%d, failed to decode trans since %s", pTrans->id, terrstr());
|
mError("trans:%d, failed to encode while sync trans since %s", pTrans->id, terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||||
|
|
@ -835,7 +835,7 @@ static bool mndTransPerfromFinishedStage(SMnode *pMnode, STrans *pTrans) {
|
||||||
|
|
||||||
SSdbRaw *pRaw = mndTransActionEncode(pTrans);
|
SSdbRaw *pRaw = mndTransActionEncode(pTrans);
|
||||||
if (pRaw == NULL) {
|
if (pRaw == NULL) {
|
||||||
mError("trans:%d, failed to decode trans since %s", pTrans->id, terrstr());
|
mError("trans:%d, failed to encode while finish trans since %s", pTrans->id, terrstr());
|
||||||
}
|
}
|
||||||
sdbSetRawStatus(pRaw, SDB_STATUS_DROPPED);
|
sdbSetRawStatus(pRaw, SDB_STATUS_DROPPED);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,9 @@ SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) {
|
||||||
for (int8_t i = 0; i < pVgroup->replica; ++i) {
|
for (int8_t i = 0; i < pVgroup->replica; ++i) {
|
||||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[i];
|
SVnodeGid *pVgid = &pVgroup->vnodeGid[i];
|
||||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pVgid->dnodeId)
|
SDB_GET_INT32(pRaw, pRow, dataPos, &pVgid->dnodeId)
|
||||||
|
if (pVgroup->replica == 1) {
|
||||||
|
pVgid->role = TAOS_SYNC_STATE_LEADER;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_VGROUP_RESERVE_SIZE)
|
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_VGROUP_RESERVE_SIZE)
|
||||||
|
|
||||||
|
|
@ -235,45 +238,55 @@ SDropVnodeMsg *mndBuildDropVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *p
|
||||||
return pDrop;
|
return pDrop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool mndResetDnodesArrayFp(SMnode *pMnode, void *pObj, void *p1, void *p2, void *p3) {
|
||||||
|
SDnodeObj *pDnode = pObj;
|
||||||
|
pDnode->numOfVnodes = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool mndBuildDnodesArrayFp(SMnode *pMnode, void *pObj, void *p1, void *p2, void *p3) {
|
||||||
|
SDnodeObj *pDnode = pObj;
|
||||||
|
SArray *pArray = p1;
|
||||||
|
|
||||||
|
pDnode->numOfVnodes = mndGetVnodesNum(pMnode, pDnode->id);
|
||||||
|
|
||||||
|
int64_t curMs = taosGetTimestampMs();
|
||||||
|
bool online = mndIsDnodeOnline(pMnode, pDnode, curMs);
|
||||||
|
if (online && pDnode->numOfSupportVnodes > 0) {
|
||||||
|
taosArrayPush(pArray, pDnode);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isMnode = mndIsMnode(pMnode, pDnode->id);
|
||||||
|
|
||||||
|
mDebug("dnode:%d, vnodes:%d supportVnodes:%d isMnode:%d online:%d", pDnode->id, pDnode->numOfVnodes,
|
||||||
|
pDnode->numOfSupportVnodes, isMnode, online);
|
||||||
|
|
||||||
|
if (isMnode) {
|
||||||
|
pDnode->numOfVnodes++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static SArray *mndBuildDnodesArray(SMnode *pMnode) {
|
static SArray *mndBuildDnodesArray(SMnode *pMnode) {
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
int32_t numOfDnodes = mndGetDnodeSize(pMnode);
|
int32_t numOfDnodes = mndGetDnodeSize(pMnode);
|
||||||
|
|
||||||
SArray *pArray = taosArrayInit(numOfDnodes, sizeof(SDnodeObj));
|
SArray *pArray = taosArrayInit(numOfDnodes, sizeof(SDnodeObj));
|
||||||
if (pArray == NULL) {
|
if (pArray == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *pIter = NULL;
|
sdbTraverse(pSdb, SDB_DNODE, mndResetDnodesArrayFp, NULL, NULL, NULL);
|
||||||
while (1) {
|
sdbTraverse(pSdb, SDB_DNODE, mndBuildDnodesArrayFp, pArray, NULL, NULL);
|
||||||
SDnodeObj *pDnode = NULL;
|
|
||||||
pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
|
|
||||||
if (pIter == NULL) break;
|
|
||||||
|
|
||||||
int32_t numOfVnodes = mndGetVnodesNum(pMnode, pDnode->id);
|
|
||||||
|
|
||||||
bool isMnode = mndIsMnode(pMnode, pDnode->id);
|
|
||||||
if (isMnode) {
|
|
||||||
pDnode->numOfVnodes++;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isReady = mndIsDnodeInReadyStatus(pMnode, pDnode);
|
|
||||||
if (isReady) {
|
|
||||||
taosArrayPush(pArray, pDnode);
|
|
||||||
}
|
|
||||||
|
|
||||||
mDebug("dnode:%d, numOfVnodes:%d numOfSupportVnodes:%d isMnode:%d ready:%d", pDnode->id, numOfVnodes,
|
|
||||||
pDnode->numOfSupportVnodes, isMnode, isReady);
|
|
||||||
sdbRelease(pSdb, pDnode);
|
|
||||||
}
|
|
||||||
|
|
||||||
return pArray;
|
return pArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndCompareDnodeVnodes(SDnodeObj *pDnode1, SDnodeObj *pDnode2) {
|
static int32_t mndCompareDnodeVnodes(SDnodeObj *pDnode1, SDnodeObj *pDnode2) {
|
||||||
float d1Score = (float)pDnode1->numOfVnodes / pDnode1->numOfSupportVnodes;
|
float d1Score = (float)pDnode1->numOfVnodes / pDnode1->numOfSupportVnodes;
|
||||||
float d2Score = (float)pDnode2->numOfVnodes / pDnode2->numOfSupportVnodes;
|
float d2Score = (float)pDnode2->numOfVnodes / pDnode2->numOfSupportVnodes;
|
||||||
return d1Score > d2Score ? 0 : 1;
|
return d1Score > d2Score ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup, SArray *pArray) {
|
static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup, SArray *pArray) {
|
||||||
|
|
@ -298,7 +311,7 @@ static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup, SArray *pAr
|
||||||
pVgid->role = TAOS_SYNC_STATE_FOLLOWER;
|
pVgid->role = TAOS_SYNC_STATE_FOLLOWER;
|
||||||
}
|
}
|
||||||
|
|
||||||
mDebug("db:%s, vgId:%d, vindex:%d dnodeId:%d is alloced", pVgroup->dbName, pVgroup->vgId, v, pVgid->dnodeId);
|
mDebug("db:%s, vgId:%d, vn:%d dnode:%d is alloced", pVgroup->dbName, pVgroup->vgId, v, pVgid->dnodeId);
|
||||||
pDnode->numOfVnodes++;
|
pDnode->numOfVnodes++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -330,6 +343,8 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
|
||||||
uint32_t hashMax = UINT32_MAX;
|
uint32_t hashMax = UINT32_MAX;
|
||||||
uint32_t hashInterval = (hashMax - hashMin) / pDb->cfg.numOfVgroups;
|
uint32_t hashInterval = (hashMax - hashMin) / pDb->cfg.numOfVgroups;
|
||||||
|
|
||||||
|
if (maxVgId < 2) maxVgId = 2;
|
||||||
|
|
||||||
for (uint32_t v = 0; v < pDb->cfg.numOfVgroups; v++) {
|
for (uint32_t v = 0; v < pDb->cfg.numOfVgroups; v++) {
|
||||||
SVgObj *pVgroup = &pVgroups[v];
|
SVgObj *pVgroup = &pVgroups[v];
|
||||||
pVgroup->vgId = maxVgId++;
|
pVgroup->vgId = maxVgId++;
|
||||||
|
|
@ -406,6 +421,20 @@ static int32_t mndProcessSyncVnodeRsp(SMnodeMsg *pMsg) { return 0; }
|
||||||
|
|
||||||
static int32_t mndProcessCompactVnodeRsp(SMnodeMsg *pMsg) { return 0; }
|
static int32_t mndProcessCompactVnodeRsp(SMnodeMsg *pMsg) { return 0; }
|
||||||
|
|
||||||
|
static bool mndGetVgroupMaxReplicaFp(SMnode *pMnode, void *pObj, void *p1, void *p2, void *p3) {
|
||||||
|
SVgObj *pVgroup = pObj;
|
||||||
|
int64_t uid = *(int64_t *)p1;
|
||||||
|
int8_t *pReplica = p2;
|
||||||
|
int32_t *pNumOfVgroups = p3;
|
||||||
|
|
||||||
|
if (pVgroup->dbUid == uid) {
|
||||||
|
*pReplica = MAX(*pReplica, pVgroup->replica);
|
||||||
|
(*pNumOfVgroups)++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t mndGetVgroupMaxReplica(SMnode *pMnode, char *dbName, int8_t *pReplica, int32_t *pNumOfVgroups) {
|
static int32_t mndGetVgroupMaxReplica(SMnode *pMnode, char *dbName, int8_t *pReplica, int32_t *pNumOfVgroups) {
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
SDbObj *pDb = mndAcquireDb(pMnode, dbName);
|
SDbObj *pDb = mndAcquireDb(pMnode, dbName);
|
||||||
|
|
@ -414,25 +443,10 @@ static int32_t mndGetVgroupMaxReplica(SMnode *pMnode, char *dbName, int8_t *pRep
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t replica = 1;
|
*pReplica = 1;
|
||||||
int32_t numOfVgroups = 0;
|
*pNumOfVgroups = 0;
|
||||||
|
sdbTraverse(pSdb, SDB_VGROUP, mndGetVgroupMaxReplicaFp, &pDb->uid, pReplica, pNumOfVgroups);
|
||||||
void *pIter = NULL;
|
mndReleaseDb(pMnode, pDb);
|
||||||
while (1) {
|
|
||||||
SVgObj *pVgroup = NULL;
|
|
||||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
|
||||||
if (pIter == NULL) break;
|
|
||||||
|
|
||||||
if (pVgroup->dbUid == pDb->uid) {
|
|
||||||
replica = MAX(replica, pVgroup->replica);
|
|
||||||
numOfVgroups++;
|
|
||||||
}
|
|
||||||
|
|
||||||
sdbRelease(pSdb, pVgroup);
|
|
||||||
}
|
|
||||||
|
|
||||||
*pReplica = replica;
|
|
||||||
*pNumOfVgroups = numOfVgroups;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -534,25 +548,23 @@ static void mndCancelGetNextVgroup(SMnode *pMnode, void *pIter) {
|
||||||
sdbCancelFetch(pSdb, pIter);
|
sdbCancelFetch(pSdb, pIter);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndGetVnodesNum(SMnode *pMnode, int32_t dnodeId) {
|
static bool mndGetVnodesNumFp(SMnode *pMnode, void *pObj, void *p1, void *p2, void *p3) {
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SVgObj *pVgroup = pObj;
|
||||||
int32_t numOfVnodes = 0;
|
int32_t dnodeId = *(int32_t *)p1;
|
||||||
void *pIter = NULL;
|
int32_t *pNumOfVnodes = (int32_t *)p2;
|
||||||
|
|
||||||
while (1) {
|
|
||||||
SVgObj *pVgroup = NULL;
|
|
||||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
|
||||||
if (pIter == NULL) break;
|
|
||||||
|
|
||||||
for (int32_t v = 0; v < pVgroup->replica; ++v) {
|
for (int32_t v = 0; v < pVgroup->replica; ++v) {
|
||||||
if (pVgroup->vnodeGid[v].dnodeId == dnodeId) {
|
if (pVgroup->vnodeGid[v].dnodeId == dnodeId) {
|
||||||
numOfVnodes++;
|
(*pNumOfVnodes)++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sdbRelease(pSdb, pVgroup);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t mndGetVnodesNum(SMnode *pMnode, int32_t dnodeId) {
|
||||||
|
int32_t numOfVnodes = 0;
|
||||||
|
sdbTraverse(pMnode->pSdb, SDB_VGROUP, mndGetVnodesNumFp, &dnodeId, &numOfVnodes, NULL);
|
||||||
return numOfVnodes;
|
return numOfVnodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,14 +16,16 @@
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndAcct.h"
|
#include "mndAcct.h"
|
||||||
#include "mndAuth.h"
|
#include "mndAuth.h"
|
||||||
#include "mndBalance.h"
|
#include "mndBnode.h"
|
||||||
#include "mndCluster.h"
|
#include "mndCluster.h"
|
||||||
#include "mndDb.h"
|
#include "mndDb.h"
|
||||||
#include "mndDnode.h"
|
#include "mndDnode.h"
|
||||||
#include "mndFunc.h"
|
#include "mndFunc.h"
|
||||||
#include "mndMnode.h"
|
#include "mndMnode.h"
|
||||||
#include "mndProfile.h"
|
#include "mndProfile.h"
|
||||||
|
#include "mndQnode.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
|
#include "mndSnode.h"
|
||||||
#include "mndStb.h"
|
#include "mndStb.h"
|
||||||
#include "mndSync.h"
|
#include "mndSync.h"
|
||||||
#include "mndTelem.h"
|
#include "mndTelem.h"
|
||||||
|
|
@ -147,6 +149,9 @@ static int32_t mndInitSteps(SMnode *pMnode) {
|
||||||
if (mndAllocStep(pMnode, "mnode-trans", mndInitTrans, mndCleanupTrans) != 0) return -1;
|
if (mndAllocStep(pMnode, "mnode-trans", mndInitTrans, mndCleanupTrans) != 0) return -1;
|
||||||
if (mndAllocStep(pMnode, "mnode-cluster", mndInitCluster, mndCleanupCluster) != 0) return -1;
|
if (mndAllocStep(pMnode, "mnode-cluster", mndInitCluster, mndCleanupCluster) != 0) return -1;
|
||||||
if (mndAllocStep(pMnode, "mnode-mnode", mndInitMnode, mndCleanupMnode) != 0) return -1;
|
if (mndAllocStep(pMnode, "mnode-mnode", mndInitMnode, mndCleanupMnode) != 0) return -1;
|
||||||
|
if (mndAllocStep(pMnode, "mnode-qnode", mndInitQnode, mndCleanupQnode) != 0) return -1;
|
||||||
|
if (mndAllocStep(pMnode, "mnode-qnode", mndInitSnode, mndCleanupSnode) != 0) return -1;
|
||||||
|
if (mndAllocStep(pMnode, "mnode-qnode", mndInitBnode, mndCleanupBnode) != 0) return -1;
|
||||||
if (mndAllocStep(pMnode, "mnode-dnode", mndInitDnode, mndCleanupDnode) != 0) return -1;
|
if (mndAllocStep(pMnode, "mnode-dnode", mndInitDnode, mndCleanupDnode) != 0) return -1;
|
||||||
if (mndAllocStep(pMnode, "mnode-user", mndInitUser, mndCleanupUser) != 0) return -1;
|
if (mndAllocStep(pMnode, "mnode-user", mndInitUser, mndCleanupUser) != 0) return -1;
|
||||||
if (mndAllocStep(pMnode, "mnode-auth", mndInitAuth, mndCleanupAuth) != 0) return -1;
|
if (mndAllocStep(pMnode, "mnode-auth", mndInitAuth, mndCleanupAuth) != 0) return -1;
|
||||||
|
|
@ -162,7 +167,6 @@ static int32_t mndInitSteps(SMnode *pMnode) {
|
||||||
if (mndAllocStep(pMnode, "mnode-sdb-read", mndReadSdb, NULL) != 0) return -1;
|
if (mndAllocStep(pMnode, "mnode-sdb-read", mndReadSdb, NULL) != 0) return -1;
|
||||||
}
|
}
|
||||||
if (mndAllocStep(pMnode, "mnode-timer", mndInitTimer, NULL) != 0) return -1;
|
if (mndAllocStep(pMnode, "mnode-timer", mndInitTimer, NULL) != 0) return -1;
|
||||||
if (mndAllocStep(pMnode, "mnode-balance", mndInitBalance, mndCleanupBalance) != 0) return -1;
|
|
||||||
if (mndAllocStep(pMnode, "mnode-profile", mndInitProfile, mndCleanupProfile) != 0) return -1;
|
if (mndAllocStep(pMnode, "mnode-profile", mndInitProfile, mndCleanupProfile) != 0) return -1;
|
||||||
if (mndAllocStep(pMnode, "mnode-show", mndInitShow, mndCleanupShow) != 0) return -1;
|
if (mndAllocStep(pMnode, "mnode-show", mndInitShow, mndCleanupShow) != 0) return -1;
|
||||||
if (mndAllocStep(pMnode, "mnode-sync", mndInitSync, mndCleanupSync) != 0) return -1;
|
if (mndAllocStep(pMnode, "mnode-sync", mndInitSync, mndCleanupSync) != 0) return -1;
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,12 @@ static const char *sdbTableName(ESdbType type) {
|
||||||
return "cluster";
|
return "cluster";
|
||||||
case SDB_MNODE:
|
case SDB_MNODE:
|
||||||
return "mnode";
|
return "mnode";
|
||||||
|
case SDB_QNODE:
|
||||||
|
return "qnode";
|
||||||
|
case SDB_SNODE:
|
||||||
|
return "snode";
|
||||||
|
case SDB_BNODE:
|
||||||
|
return "bnode";
|
||||||
case SDB_DNODE:
|
case SDB_DNODE:
|
||||||
return "dnode";
|
return "dnode";
|
||||||
case SDB_USER:
|
case SDB_USER:
|
||||||
|
|
@ -55,7 +61,8 @@ void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper) {
|
||||||
} else if (keyType == SDB_KEY_INT32) {
|
} else if (keyType == SDB_KEY_INT32) {
|
||||||
mTrace("%s:%d, refCount:%d oper:%s", sdbTableName(pRow->type), *(int32_t *)pRow->pObj, pRow->refCount, oper);
|
mTrace("%s:%d, refCount:%d oper:%s", sdbTableName(pRow->type), *(int32_t *)pRow->pObj, pRow->refCount, oper);
|
||||||
} else if (keyType == SDB_KEY_INT64) {
|
} else if (keyType == SDB_KEY_INT64) {
|
||||||
mTrace("%s:%" PRId64 ", refCount:%d oper:%s", sdbTableName(pRow->type), *(int64_t *)pRow->pObj, pRow->refCount, oper);
|
mTrace("%s:%" PRId64 ", refCount:%d oper:%s", sdbTableName(pRow->type), *(int64_t *)pRow->pObj, pRow->refCount,
|
||||||
|
oper);
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -329,6 +336,30 @@ void sdbCancelFetch(SSdb *pSdb, void *pIter) {
|
||||||
taosRUnLockLatch(pLock);
|
taosRUnLockLatch(pLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sdbTraverse(SSdb *pSdb, ESdbType type, sdbTraverseFp fp, void *p1, void *p2, void *p3) {
|
||||||
|
SHashObj *hash = sdbGetHash(pSdb, type);
|
||||||
|
if (hash == NULL) return;
|
||||||
|
|
||||||
|
SRWLatch *pLock = &pSdb->locks[type];
|
||||||
|
taosRLockLatch(pLock);
|
||||||
|
|
||||||
|
SSdbRow **ppRow = taosHashIterate(hash, NULL);
|
||||||
|
while (ppRow != NULL) {
|
||||||
|
SSdbRow *pRow = *ppRow;
|
||||||
|
if (pRow->status == SDB_STATUS_READY) {
|
||||||
|
bool isContinue = (*fp)(pSdb->pMnode, pRow->pObj, p1, p2, p3);
|
||||||
|
if (!isContinue) {
|
||||||
|
taosHashCancelIterate(hash, ppRow);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ppRow = taosHashIterate(hash, ppRow);
|
||||||
|
}
|
||||||
|
|
||||||
|
taosRUnLockLatch(pLock);
|
||||||
|
}
|
||||||
|
|
||||||
int32_t sdbGetSize(SSdb *pSdb, ESdbType type) {
|
int32_t sdbGetSize(SSdb *pSdb, ESdbType type) {
|
||||||
SHashObj *hash = sdbGetHash(pSdb, type);
|
SHashObj *hash = sdbGetHash(pSdb, type);
|
||||||
if (hash == NULL) return 0;
|
if (hash == NULL) return 0;
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,8 @@ void qndClose(SQnode *pQnode) { free(pQnode); }
|
||||||
|
|
||||||
int32_t qndGetLoad(SQnode *pQnode, SQnodeLoad *pLoad) { return 0; }
|
int32_t qndGetLoad(SQnode *pQnode, SQnodeLoad *pLoad) { return 0; }
|
||||||
|
|
||||||
int32_t qndProcessQueryReq(SQnode *pQnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
int32_t qndProcessMsg(SQnode *pQnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||||
*pRsp = NULL;
|
*pRsp = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qndProcessFetchReq(SQnode *pQnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
|
||||||
*pRsp = NULL;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ void sndClose(SSnode *pSnode) { free(pSnode); }
|
||||||
|
|
||||||
int32_t sndGetLoad(SSnode *pSnode, SSnodeLoad *pLoad) { return 0; }
|
int32_t sndGetLoad(SSnode *pSnode, SSnodeLoad *pLoad) { return 0; }
|
||||||
|
|
||||||
int32_t sndProcessWriteMsg(SSnode *pSnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
int32_t sndProcessMsg(SSnode *pSnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||||
*pRsp = NULL;
|
*pRsp = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,10 @@
|
||||||
#include "vnodeCommit.h"
|
#include "vnodeCommit.h"
|
||||||
#include "vnodeFS.h"
|
#include "vnodeFS.h"
|
||||||
#include "vnodeMemAllocator.h"
|
#include "vnodeMemAllocator.h"
|
||||||
|
#include "vnodeQuery.h"
|
||||||
#include "vnodeRequest.h"
|
#include "vnodeRequest.h"
|
||||||
#include "vnodeStateMgr.h"
|
#include "vnodeStateMgr.h"
|
||||||
#include "vnodeSync.h"
|
#include "vnodeSync.h"
|
||||||
#include "vnodeQuery.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
@ -62,6 +62,7 @@ typedef struct SVnodeMgr {
|
||||||
extern SVnodeMgr vnodeMgr;
|
extern SVnodeMgr vnodeMgr;
|
||||||
|
|
||||||
struct SVnode {
|
struct SVnode {
|
||||||
|
int32_t vgId;
|
||||||
char* path;
|
char* path;
|
||||||
SVnodeCfg config;
|
SVnodeCfg config;
|
||||||
SVState state;
|
SVState state;
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,9 @@
|
||||||
#include "vnodeQuery.h"
|
#include "vnodeQuery.h"
|
||||||
#include "vnodeDef.h"
|
#include "vnodeDef.h"
|
||||||
|
|
||||||
|
static int32_t vnodeGetTableList(SVnode *pVnode, SRpcMsg *pMsg);
|
||||||
|
static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
||||||
|
|
||||||
int vnodeQueryOpen(SVnode *pVnode) { return qWorkerInit(NULL, &pVnode->pQuery); }
|
int vnodeQueryOpen(SVnode *pVnode) { return qWorkerInit(NULL, &pVnode->pQuery); }
|
||||||
|
|
||||||
int vnodeProcessQueryReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
int vnodeProcessQueryReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||||
|
|
@ -36,32 +39,152 @@ int vnodeProcessFetchReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||||
return qWorkerProcessCancelMsg(pVnode, pVnode->pQuery, pMsg);
|
return qWorkerProcessCancelMsg(pVnode, pVnode->pQuery, pMsg);
|
||||||
case TDMT_VND_DROP_TASK:
|
case TDMT_VND_DROP_TASK:
|
||||||
return qWorkerProcessDropMsg(pVnode, pVnode->pQuery, pMsg);
|
return qWorkerProcessDropMsg(pVnode, pVnode->pQuery, pMsg);
|
||||||
|
case TDMT_VND_SHOW_TABLES:
|
||||||
|
return qWorkerProcessShowMsg(pVnode, pVnode->pQuery, pMsg);
|
||||||
|
case TDMT_VND_SHOW_TABLES_FETCH:
|
||||||
|
return vnodeGetTableList(pVnode, pMsg);
|
||||||
|
// return qWorkerProcessShowFetchMsg(pVnode->pMeta, pVnode->pQuery, pMsg);
|
||||||
|
case TDMT_VND_TABLE_META:
|
||||||
|
return vnodeGetTableMeta(pVnode, pMsg, pRsp);
|
||||||
default:
|
default:
|
||||||
vError("unknown msg type:%d in fetch queue", pMsg->msgType);
|
vError("unknown msg type:%d in fetch queue", pMsg->msgType);
|
||||||
return TSDB_CODE_VND_APP_ERROR;
|
return TSDB_CODE_VND_APP_ERROR;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||||
STableInfoMsg *pReq = (STableInfoMsg *)(pMsg->pCont);
|
STableInfoMsg * pReq = (STableInfoMsg *)(pMsg->pCont);
|
||||||
STableMetaMsg *pRspMsg;
|
STbCfg * pTbCfg = NULL;
|
||||||
int ret;
|
STbCfg * pStbCfg = NULL;
|
||||||
|
tb_uid_t uid;
|
||||||
|
int32_t nCols;
|
||||||
|
int32_t nTagCols;
|
||||||
|
SSchemaWrapper *pSW;
|
||||||
|
STableMetaMsg * pTbMetaMsg = NULL;
|
||||||
|
SSchema * pTagSchema;
|
||||||
|
SRpcMsg rpcMsg;
|
||||||
|
int msgLen = 0;
|
||||||
|
int32_t code = TSDB_CODE_VND_APP_ERROR;
|
||||||
|
|
||||||
if (metaGetTableInfo(pVnode->pMeta, pReq->tableFname, &pRspMsg) < 0) {
|
pTbCfg = metaGetTbInfoByName(pVnode->pMeta, pReq->tableFname, &uid);
|
||||||
return -1;
|
if (pTbCfg == NULL) {
|
||||||
|
goto _exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
*pRsp = malloc(sizeof(SRpcMsg));
|
if (pTbCfg->type == META_CHILD_TABLE) {
|
||||||
if (TD_IS_NULL(*pRsp)) {
|
pStbCfg = metaGetTbInfoByUid(pVnode->pMeta, pTbCfg->ctbCfg.suid);
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
if (pStbCfg == NULL) {
|
||||||
free(pMsg);
|
goto _exit;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
pSW = metaGetTableSchema(pVnode->pMeta, pTbCfg->ctbCfg.suid, 0, true);
|
||||||
(*pRsp)->pCont = pRspMsg;
|
} else {
|
||||||
|
pSW = metaGetTableSchema(pVnode->pMeta, uid, 0, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
nCols = pSW->nCols;
|
||||||
|
if (pTbCfg->type == META_SUPER_TABLE) {
|
||||||
|
nTagCols = pTbCfg->stbCfg.nTagCols;
|
||||||
|
pTagSchema = pTbCfg->stbCfg.pTagSchema;
|
||||||
|
} else if (pTbCfg->type == META_SUPER_TABLE) {
|
||||||
|
nTagCols = pStbCfg->stbCfg.nTagCols;
|
||||||
|
pTagSchema = pStbCfg->stbCfg.pTagSchema;
|
||||||
|
} else {
|
||||||
|
nTagCols = 0;
|
||||||
|
pTagSchema = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
msgLen = sizeof(STableMetaMsg) + sizeof(SSchema) * (nCols + nTagCols);
|
||||||
|
pTbMetaMsg = (STableMetaMsg *)rpcMallocCont(msgLen);
|
||||||
|
if (pTbMetaMsg == NULL) {
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(pTbMetaMsg->dbFname, pReq->dbFname, sizeof(pTbMetaMsg->dbFname));
|
||||||
|
strcpy(pTbMetaMsg->tbFname, pTbCfg->name);
|
||||||
|
if (pTbCfg->type == META_CHILD_TABLE) {
|
||||||
|
strcpy(pTbMetaMsg->stbFname, pStbCfg->name);
|
||||||
|
pTbMetaMsg->suid = htobe64(pTbCfg->ctbCfg.suid);
|
||||||
|
}
|
||||||
|
pTbMetaMsg->numOfTags = htonl(nTagCols);
|
||||||
|
pTbMetaMsg->numOfColumns = htonl(nCols);
|
||||||
|
pTbMetaMsg->tableType = pTbCfg->type;
|
||||||
|
pTbMetaMsg->tuid = htobe64(uid);
|
||||||
|
pTbMetaMsg->vgId = htonl(pVnode->vgId);
|
||||||
|
|
||||||
|
memcpy(pTbMetaMsg->pSchema, pSW->pSchema, sizeof(SSchema) * pSW->nCols);
|
||||||
|
if (nTagCols) {
|
||||||
|
memcpy(POINTER_SHIFT(pTbMetaMsg->pSchema, sizeof(SSchema) * pSW->nCols), pTagSchema, sizeof(SSchema) * nTagCols);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < nCols + nTagCols; i++) {
|
||||||
|
SSchema *pSch = pTbMetaMsg->pSchema + i;
|
||||||
|
pSch->colId = htonl(pSch->colId);
|
||||||
|
pSch->bytes = htonl(pSch->bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
code = 0;
|
||||||
|
|
||||||
|
_exit:
|
||||||
|
|
||||||
|
rpcMsg.handle = pMsg->handle;
|
||||||
|
rpcMsg.ahandle = pMsg->ahandle;
|
||||||
|
rpcMsg.pCont = pTbMetaMsg;
|
||||||
|
rpcMsg.contLen = msgLen;
|
||||||
|
rpcMsg.code = code;
|
||||||
|
|
||||||
|
rpcSendResponse(&rpcMsg);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pVnode
|
||||||
|
* @param pMsg
|
||||||
|
* @param pRsp
|
||||||
|
*/
|
||||||
|
static int32_t vnodeGetTableList(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||||
|
SMTbCursor *pCur = metaOpenTbCursor(pVnode->pMeta);
|
||||||
|
SArray * pArray = taosArrayInit(10, POINTER_BYTES);
|
||||||
|
|
||||||
|
char * name = NULL;
|
||||||
|
int32_t totalLen = 0;
|
||||||
|
while ((name = metaTbCursorNext(pCur)) != NULL) {
|
||||||
|
taosArrayPush(pArray, &name);
|
||||||
|
totalLen += strlen(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
metaCloseTbCursor(pCur);
|
||||||
|
|
||||||
|
int32_t rowLen =
|
||||||
|
(TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE) + 8 + 2 + (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE) + 8 + 4;
|
||||||
|
int32_t numOfTables = (int32_t)taosArrayGetSize(pArray);
|
||||||
|
|
||||||
|
int32_t payloadLen = rowLen * numOfTables;
|
||||||
|
// SVShowTablesFetchReq *pFetchReq = pMsg->pCont;
|
||||||
|
|
||||||
|
SVShowTablesFetchRsp *pFetchRsp = (SVShowTablesFetchRsp *)rpcMallocCont(sizeof(SVShowTablesFetchRsp) + payloadLen);
|
||||||
|
memset(pFetchRsp, 0, sizeof(struct SVShowTablesFetchRsp) + payloadLen);
|
||||||
|
|
||||||
|
char *p = pFetchRsp->data;
|
||||||
|
for (int32_t i = 0; i < numOfTables; ++i) {
|
||||||
|
char *n = taosArrayGetP(pArray, i);
|
||||||
|
STR_TO_VARSTR(p, n);
|
||||||
|
|
||||||
|
p += (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
pFetchRsp->numOfRows = htonl(numOfTables);
|
||||||
|
pFetchRsp->precision = 0;
|
||||||
|
|
||||||
|
SRpcMsg rpcMsg = {
|
||||||
|
.handle = pMsg->handle,
|
||||||
|
.ahandle = pMsg->ahandle,
|
||||||
|
.pCont = pFetchRsp,
|
||||||
|
.contLen = sizeof(SVShowTablesFetchRsp) + payloadLen,
|
||||||
|
.code = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
rpcSendResponse(&rpcMsg);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ int vnodeProcessNoWalWMsgs(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) {
|
int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) {
|
||||||
SRpcMsg * pMsg;
|
SRpcMsg *pMsg;
|
||||||
|
|
||||||
for (int i = 0; i < taosArrayGetSize(pMsgs); i++) {
|
for (int i = 0; i < taosArrayGetSize(pMsgs); i++) {
|
||||||
pMsg = *(SRpcMsg **)taosArrayGet(pMsgs, i);
|
pMsg = *(SRpcMsg **)taosArrayGet(pMsgs, i);
|
||||||
|
|
@ -51,6 +51,7 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) {
|
||||||
|
|
||||||
int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||||
SVCreateTbReq vCreateTbReq;
|
SVCreateTbReq vCreateTbReq;
|
||||||
|
SVCreateTbBatchReq vCreateTbBatchReq;
|
||||||
void * ptr = vnodeMalloc(pVnode, pMsg->contLen);
|
void * ptr = vnodeMalloc(pVnode, pMsg->contLen);
|
||||||
if (ptr == NULL) {
|
if (ptr == NULL) {
|
||||||
// TODO: handle error
|
// TODO: handle error
|
||||||
|
|
@ -68,7 +69,6 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||||
|
|
||||||
switch (pMsg->msgType) {
|
switch (pMsg->msgType) {
|
||||||
case TDMT_VND_CREATE_STB:
|
case TDMT_VND_CREATE_STB:
|
||||||
case TDMT_VND_CREATE_TABLE:
|
|
||||||
tDeserializeSVCreateTbReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vCreateTbReq);
|
tDeserializeSVCreateTbReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vCreateTbReq);
|
||||||
if (metaCreateTable(pVnode->pMeta, &(vCreateTbReq)) < 0) {
|
if (metaCreateTable(pVnode->pMeta, &(vCreateTbReq)) < 0) {
|
||||||
// TODO: handle error
|
// TODO: handle error
|
||||||
|
|
@ -76,6 +76,15 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||||
|
|
||||||
// TODO: maybe need to clear the requst struct
|
// TODO: maybe need to clear the requst struct
|
||||||
break;
|
break;
|
||||||
|
case TDMT_VND_CREATE_TABLE:
|
||||||
|
tSVCreateTbBatchReqDeserialize(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vCreateTbBatchReq);
|
||||||
|
for (int i = 0; i < taosArrayGetSize(vCreateTbBatchReq.pArray); i++) {
|
||||||
|
SVCreateTbReq *pCreateTbReq = taosArrayGet(vCreateTbBatchReq.pArray, i);
|
||||||
|
if (metaCreateTable(pVnode->pMeta, pCreateTbReq) < 0) {
|
||||||
|
// TODO: handle error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case TDMT_VND_DROP_STB:
|
case TDMT_VND_DROP_STB:
|
||||||
case TDMT_VND_DROP_TABLE:
|
case TDMT_VND_DROP_TABLE:
|
||||||
// if (metaDropTable(pVnode->pMeta, vReq.dtReq.uid) < 0) {
|
// if (metaDropTable(pVnode->pMeta, vReq.dtReq.uid) < 0) {
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,6 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define META_SUPER_TABLE TD_SUPER_TABLE
|
|
||||||
#define META_CHILD_TABLE TD_CHILD_TABLE
|
|
||||||
#define META_NORMAL_TABLE TD_NORMAL_TABLE
|
|
||||||
|
|
||||||
int metaValidateTbCfg(SMeta *pMeta, const STbCfg *);
|
int metaValidateTbCfg(SMeta *pMeta, const STbCfg *);
|
||||||
size_t metaEncodeTbObjFromTbOptions(const STbCfg *, void *pBuf, size_t bsize);
|
size_t metaEncodeTbObjFromTbOptions(const STbCfg *, void *pBuf, size_t bsize);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
typedef struct {
|
typedef struct {
|
||||||
tb_uid_t uid;
|
tb_uid_t uid;
|
||||||
int32_t sver;
|
int32_t sver;
|
||||||
|
int32_t padding;
|
||||||
} SSchemaKey;
|
} SSchemaKey;
|
||||||
|
|
||||||
struct SMetaDB {
|
struct SMetaDB {
|
||||||
|
|
@ -55,6 +56,8 @@ static int metaCtbIdxCb(DB *pIdx, const DBT *pKey, const DBT *pValue, DBT *
|
||||||
static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg);
|
static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg);
|
||||||
static void * metaDecodeTbInfo(void *buf, STbCfg *pTbCfg);
|
static void * metaDecodeTbInfo(void *buf, STbCfg *pTbCfg);
|
||||||
static void metaClearTbCfg(STbCfg *pTbCfg);
|
static void metaClearTbCfg(STbCfg *pTbCfg);
|
||||||
|
static int metaEncodeSchema(void **buf, SSchemaWrapper *pSW);
|
||||||
|
static void * metaDecodeSchema(void *buf, SSchemaWrapper *pSW);
|
||||||
|
|
||||||
#define BDB_PERR(info, code) fprintf(stderr, info " reason: %s", db_strerror(code))
|
#define BDB_PERR(info, code) fprintf(stderr, info " reason: %s", db_strerror(code))
|
||||||
|
|
||||||
|
|
@ -81,7 +84,7 @@ int metaOpenDB(SMeta *pMeta) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (metaOpenBDBDb(&(pDB->pSchemaDB), pDB->pEvn, "meta.db", false) < 0) {
|
if (metaOpenBDBDb(&(pDB->pSchemaDB), pDB->pEvn, "schema.db", false) < 0) {
|
||||||
metaCloseDB(pMeta);
|
metaCloseDB(pMeta);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -169,18 +172,13 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) {
|
||||||
pBuf = buf;
|
pBuf = buf;
|
||||||
memset(&key, 0, sizeof(key));
|
memset(&key, 0, sizeof(key));
|
||||||
memset(&value, 0, sizeof(key));
|
memset(&value, 0, sizeof(key));
|
||||||
SSchemaKey schemaKey = {uid, 0 /*TODO*/};
|
SSchemaKey schemaKey = {uid, 0 /*TODO*/, 0};
|
||||||
|
|
||||||
key.data = &schemaKey;
|
key.data = &schemaKey;
|
||||||
key.size = sizeof(schemaKey);
|
key.size = sizeof(schemaKey);
|
||||||
|
|
||||||
taosEncodeFixedU32(&pBuf, ncols);
|
SSchemaWrapper sw = {.nCols = ncols, .pSchema = pSchema};
|
||||||
for (size_t i = 0; i < ncols; i++) {
|
metaEncodeSchema(&pBuf, &sw);
|
||||||
taosEncodeFixedI8(&pBuf, pSchema[i].type);
|
|
||||||
taosEncodeFixedI32(&pBuf, pSchema[i].colId);
|
|
||||||
taosEncodeFixedI32(&pBuf, pSchema[i].bytes);
|
|
||||||
taosEncodeString(&pBuf, pSchema[i].name);
|
|
||||||
}
|
|
||||||
|
|
||||||
value.data = buf;
|
value.data = buf;
|
||||||
value.size = POINTER_DISTANCE(pBuf, buf);
|
value.size = POINTER_DISTANCE(pBuf, buf);
|
||||||
|
|
@ -197,6 +195,38 @@ int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------ STATIC METHODS ------------------------ */
|
/* ------------------------ STATIC METHODS ------------------------ */
|
||||||
|
static int metaEncodeSchema(void **buf, SSchemaWrapper *pSW) {
|
||||||
|
int tlen = 0;
|
||||||
|
SSchema *pSchema;
|
||||||
|
|
||||||
|
tlen += taosEncodeFixedU32(buf, pSW->nCols);
|
||||||
|
for (int i = 0; i < pSW->nCols; i++) {
|
||||||
|
pSchema = pSW->pSchema + i;
|
||||||
|
tlen += taosEncodeFixedI8(buf, pSchema->type);
|
||||||
|
tlen += taosEncodeFixedI32(buf, pSchema->colId);
|
||||||
|
tlen += taosEncodeFixedI32(buf, pSchema->bytes);
|
||||||
|
tlen += taosEncodeString(buf, pSchema->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tlen;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *metaDecodeSchema(void *buf, SSchemaWrapper *pSW) {
|
||||||
|
SSchema *pSchema;
|
||||||
|
|
||||||
|
buf = taosDecodeFixedU32(buf, &pSW->nCols);
|
||||||
|
pSW->pSchema = (SSchema *)malloc(sizeof(SSchema) * pSW->nCols);
|
||||||
|
for (int i = 0; i < pSW->nCols; i++) {
|
||||||
|
pSchema = pSW->pSchema + i;
|
||||||
|
buf = taosDecodeFixedI8(buf, &pSchema->type);
|
||||||
|
buf = taosDecodeFixedI32(buf, &pSchema->colId);
|
||||||
|
buf = taosDecodeFixedI32(buf, &pSchema->bytes);
|
||||||
|
buf = taosDecodeStringTo(buf, pSchema->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
static SMetaDB *metaNewDB() {
|
static SMetaDB *metaNewDB() {
|
||||||
SMetaDB *pDB = NULL;
|
SMetaDB *pDB = NULL;
|
||||||
pDB = (SMetaDB *)calloc(1, sizeof(*pDB));
|
pDB = (SMetaDB *)calloc(1, sizeof(*pDB));
|
||||||
|
|
@ -376,15 +406,8 @@ static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg) {
|
||||||
tsize += taosEncodeFixedU8(buf, pTbCfg->type);
|
tsize += taosEncodeFixedU8(buf, pTbCfg->type);
|
||||||
|
|
||||||
if (pTbCfg->type == META_SUPER_TABLE) {
|
if (pTbCfg->type == META_SUPER_TABLE) {
|
||||||
tsize += taosEncodeVariantU32(buf, pTbCfg->stbCfg.nTagCols);
|
SSchemaWrapper sw = {.nCols = pTbCfg->stbCfg.nTagCols, .pSchema = pTbCfg->stbCfg.pTagSchema};
|
||||||
for (uint32_t i = 0; i < pTbCfg->stbCfg.nTagCols; i++) {
|
tsize += metaEncodeSchema(buf, &sw);
|
||||||
tsize += taosEncodeFixedI8(buf, pTbCfg->stbCfg.pSchema[i].type);
|
|
||||||
tsize += taosEncodeFixedI32(buf, pTbCfg->stbCfg.pSchema[i].colId);
|
|
||||||
tsize += taosEncodeFixedI32(buf, pTbCfg->stbCfg.pSchema[i].bytes);
|
|
||||||
tsize += taosEncodeString(buf, pTbCfg->stbCfg.pSchema[i].name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// tsize += tdEncodeSchema(buf, pTbCfg->stbCfg.pTagSchema);
|
|
||||||
} else if (pTbCfg->type == META_CHILD_TABLE) {
|
} else if (pTbCfg->type == META_CHILD_TABLE) {
|
||||||
tsize += taosEncodeFixedU64(buf, pTbCfg->ctbCfg.suid);
|
tsize += taosEncodeFixedU64(buf, pTbCfg->ctbCfg.suid);
|
||||||
tsize += tdEncodeKVRow(buf, pTbCfg->ctbCfg.pTag);
|
tsize += tdEncodeKVRow(buf, pTbCfg->ctbCfg.pTag);
|
||||||
|
|
@ -403,14 +426,10 @@ static void *metaDecodeTbInfo(void *buf, STbCfg *pTbCfg) {
|
||||||
buf = taosDecodeFixedU8(buf, &(pTbCfg->type));
|
buf = taosDecodeFixedU8(buf, &(pTbCfg->type));
|
||||||
|
|
||||||
if (pTbCfg->type == META_SUPER_TABLE) {
|
if (pTbCfg->type == META_SUPER_TABLE) {
|
||||||
buf = taosDecodeVariantU32(buf, &(pTbCfg->stbCfg.nTagCols));
|
SSchemaWrapper sw;
|
||||||
pTbCfg->stbCfg.pTagSchema = (SSchema *)malloc(sizeof(SSchema) * pTbCfg->stbCfg.nTagCols);
|
buf = metaDecodeSchema(buf, &sw);
|
||||||
for (uint32_t i = 0; i < pTbCfg->stbCfg.nTagCols; i++) {
|
pTbCfg->stbCfg.nTagCols = sw.nCols;
|
||||||
buf = taosDecodeFixedI8(buf, &(pTbCfg->stbCfg.pSchema[i].type));
|
pTbCfg->stbCfg.pTagSchema = sw.pSchema;
|
||||||
buf = taosDecodeFixedI32(buf, &pTbCfg->stbCfg.pSchema[i].colId);
|
|
||||||
buf = taosDecodeFixedI32(buf, &pTbCfg->stbCfg.pSchema[i].bytes);
|
|
||||||
buf = taosDecodeStringTo(buf, pTbCfg->stbCfg.pSchema[i].name);
|
|
||||||
}
|
|
||||||
} else if (pTbCfg->type == META_CHILD_TABLE) {
|
} else if (pTbCfg->type == META_CHILD_TABLE) {
|
||||||
buf = taosDecodeFixedU64(buf, &(pTbCfg->ctbCfg.suid));
|
buf = taosDecodeFixedU64(buf, &(pTbCfg->ctbCfg.suid));
|
||||||
buf = tdDecodeKVRow(buf, &(pTbCfg->ctbCfg.pTag));
|
buf = tdDecodeKVRow(buf, &(pTbCfg->ctbCfg.pTag));
|
||||||
|
|
@ -431,79 +450,138 @@ static void metaClearTbCfg(STbCfg *pTbCfg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------ FOR QUERY ------------------------ */
|
/* ------------------------ FOR QUERY ------------------------ */
|
||||||
int metaGetTableInfo(SMeta *pMeta, char *tbname, STableMetaMsg **ppMsg) {
|
STbCfg *metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid) {
|
||||||
|
STbCfg * pTbCfg = NULL;
|
||||||
|
SMetaDB *pDB = pMeta->pDB;
|
||||||
DBT key = {0};
|
DBT key = {0};
|
||||||
DBT value = {0};
|
DBT value = {0};
|
||||||
SMetaDB * pMetaDB = pMeta->pDB;
|
|
||||||
int ret;
|
int ret;
|
||||||
STbCfg tbCfg;
|
|
||||||
SSchemaKey schemaKey;
|
|
||||||
DBT key1 = {0};
|
|
||||||
DBT value1 = {0};
|
|
||||||
uint32_t ncols;
|
|
||||||
void * pBuf;
|
|
||||||
int tlen;
|
|
||||||
STableMetaMsg *pMsg;
|
|
||||||
|
|
||||||
key.data = tbname;
|
// Set key/value
|
||||||
key.size = strlen(tbname) + 1;
|
key.data = &uid;
|
||||||
|
key.size = sizeof(uid);
|
||||||
|
|
||||||
ret = pMetaDB->pNameIdx->get(pMetaDB->pNameIdx, NULL, &key, &value, 0);
|
// Query
|
||||||
|
ret = pDB->pTbDB->get(pDB->pTbDB, NULL, &key, &value, 0);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
// TODO
|
return NULL;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
metaDecodeTbInfo(value.data, &tbCfg);
|
// Decode
|
||||||
|
pTbCfg = (STbCfg *)malloc(sizeof(*pTbCfg));
|
||||||
switch (tbCfg.type) {
|
if (pTbCfg == NULL) {
|
||||||
case META_SUPER_TABLE:
|
return NULL;
|
||||||
schemaKey.uid = tbCfg.stbCfg.suid;
|
|
||||||
schemaKey.sver = 0;
|
|
||||||
|
|
||||||
key1.data = &schemaKey;
|
|
||||||
key1.size = sizeof(schemaKey);
|
|
||||||
|
|
||||||
ret = pMetaDB->pSchemaDB->get(pMetaDB->pSchemaDB, &key1, &value1, NULL, 0);
|
|
||||||
if (ret != 0) {
|
|
||||||
// TODO
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
pBuf = value1.data;
|
|
||||||
pBuf = taosDecodeFixedU32(pBuf, &ncols);
|
|
||||||
|
|
||||||
tlen = sizeof(STableMetaMsg) + (tbCfg.stbCfg.nTagCols + ncols) * sizeof(SSchema);
|
|
||||||
pMsg = calloc(1, tlen);
|
|
||||||
if (pMsg == NULL) {
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(pMsg->tbFname, tbCfg.name);
|
metaDecodeTbInfo(value.data, pTbCfg);
|
||||||
pMsg->numOfTags = tbCfg.stbCfg.nTagCols;
|
|
||||||
pMsg->numOfColumns = ncols;
|
|
||||||
pMsg->tableType = tbCfg.type;
|
|
||||||
pMsg->sversion = 0;
|
|
||||||
pMsg->tversion = 0;
|
|
||||||
pMsg->suid = tbCfg.stbCfg.suid;
|
|
||||||
pMsg->tuid = tbCfg.stbCfg.suid;
|
|
||||||
for (size_t i = 0; i < tbCfg.stbCfg.nTagCols; i++) {
|
|
||||||
|
|
||||||
}
|
return pTbCfg;
|
||||||
|
}
|
||||||
break;
|
|
||||||
case META_CHILD_TABLE:
|
STbCfg *metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid) {
|
||||||
ASSERT(0);
|
STbCfg * pTbCfg = NULL;
|
||||||
break;
|
SMetaDB *pDB = pMeta->pDB;
|
||||||
case META_NORMAL_TABLE:
|
DBT key = {0};
|
||||||
ASSERT(0);
|
DBT pkey = {0};
|
||||||
break;
|
DBT pvalue = {0};
|
||||||
default:
|
int ret;
|
||||||
ASSERT(0);
|
|
||||||
break;
|
// Set key/value
|
||||||
}
|
key.data = tbname;
|
||||||
|
key.size = strlen(tbname);
|
||||||
*ppMsg = pMsg;
|
|
||||||
|
// Query
|
||||||
return 0;
|
ret = pDB->pNameIdx->pget(pDB->pNameIdx, NULL, &key, &pkey, &pvalue, 0);
|
||||||
|
if (ret != 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decode
|
||||||
|
*uid = *(tb_uid_t *)(pkey.data);
|
||||||
|
pTbCfg = (STbCfg *)malloc(sizeof(*pTbCfg));
|
||||||
|
if (pTbCfg == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
metaDecodeTbInfo(pvalue.data, pTbCfg);
|
||||||
|
|
||||||
|
return pTbCfg;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline) {
|
||||||
|
uint32_t nCols;
|
||||||
|
SSchemaWrapper *pSW = NULL;
|
||||||
|
SMetaDB * pDB = pMeta->pDB;
|
||||||
|
int ret;
|
||||||
|
void * pBuf;
|
||||||
|
SSchema * pSchema;
|
||||||
|
SSchemaKey schemaKey = {uid, sver, 0};
|
||||||
|
DBT key = {0};
|
||||||
|
DBT value = {0};
|
||||||
|
|
||||||
|
// Set key/value properties
|
||||||
|
key.data = &schemaKey;
|
||||||
|
key.size = sizeof(schemaKey);
|
||||||
|
|
||||||
|
// Query
|
||||||
|
ret = pDB->pSchemaDB->get(pDB->pSchemaDB, NULL, &key, &value, 0);
|
||||||
|
if (ret != 0) {
|
||||||
|
printf("failed to query schema DB since %s================\n", db_strerror(ret));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decode the schema
|
||||||
|
pBuf = value.data;
|
||||||
|
pSW = malloc(sizeof(*pSW));
|
||||||
|
metaDecodeSchema(pBuf, pSW);
|
||||||
|
|
||||||
|
return pSW;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SMTbCursor {
|
||||||
|
DBC *pCur;
|
||||||
|
};
|
||||||
|
|
||||||
|
SMTbCursor *metaOpenTbCursor(SMeta *pMeta) {
|
||||||
|
SMTbCursor *pTbCur = NULL;
|
||||||
|
SMetaDB * pDB = pMeta->pDB;
|
||||||
|
|
||||||
|
pTbCur = (SMTbCursor *)calloc(1, sizeof(*pTbCur));
|
||||||
|
if (pTbCur == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
pDB->pTbDB->cursor(pDB->pTbDB, NULL, &(pTbCur->pCur), 0);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
DB_BTREE_STAT *sp;
|
||||||
|
pDB->pTbDB->stat(pDB->pTbDB, NULL, &sp, 0);
|
||||||
|
printf("**************** %ld\n", sp->bt_nkeys);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return pTbCur;
|
||||||
|
}
|
||||||
|
|
||||||
|
void metaCloseTbCursor(SMTbCursor *pTbCur) {
|
||||||
|
if (pTbCur) {
|
||||||
|
if (pTbCur->pCur) {
|
||||||
|
pTbCur->pCur->close(pTbCur->pCur);
|
||||||
|
}
|
||||||
|
free(pTbCur);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char *metaTbCursorNext(SMTbCursor *pTbCur) {
|
||||||
|
DBT key = {0};
|
||||||
|
DBT value = {0};
|
||||||
|
STbCfg tbCfg;
|
||||||
|
void * pBuf;
|
||||||
|
|
||||||
|
if (pTbCur->pCur->get(pTbCur->pCur, &key, &value, DB_NEXT) == 0) {
|
||||||
|
pBuf = value.data;
|
||||||
|
metaDecodeTbInfo(pBuf, &tbCfg);
|
||||||
|
return tbCfg.name;
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -11,4 +11,6 @@ target_link_libraries(
|
||||||
PRIVATE os util transport qcom
|
PRIVATE os util transport qcom
|
||||||
)
|
)
|
||||||
|
|
||||||
ADD_SUBDIRECTORY(test)
|
if(${BUILD_TEST})
|
||||||
|
ADD_SUBDIRECTORY(test)
|
||||||
|
endif(${BUILD_TEST})
|
||||||
|
|
@ -31,6 +31,11 @@ extern "C" {
|
||||||
|
|
||||||
#define CTG_DEFAULT_INVALID_VERSION (-1)
|
#define CTG_DEFAULT_INVALID_VERSION (-1)
|
||||||
|
|
||||||
|
enum {
|
||||||
|
CTG_READ = 1,
|
||||||
|
CTG_WRITE,
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct SVgroupListCache {
|
typedef struct SVgroupListCache {
|
||||||
int32_t vgroupVersion;
|
int32_t vgroupVersion;
|
||||||
SHashObj *cache; // key:vgId, value:SVgroupInfo
|
SHashObj *cache; // key:vgId, value:SVgroupInfo
|
||||||
|
|
@ -41,6 +46,7 @@ typedef struct SDBVgroupCache {
|
||||||
} SDBVgroupCache;
|
} SDBVgroupCache;
|
||||||
|
|
||||||
typedef struct STableMetaCache {
|
typedef struct STableMetaCache {
|
||||||
|
SRWLatch stableLock;
|
||||||
SHashObj *cache; //key:fulltablename, value:STableMeta
|
SHashObj *cache; //key:fulltablename, value:STableMeta
|
||||||
SHashObj *stableCache; //key:suid, value:STableMeta*
|
SHashObj *stableCache; //key:suid, value:STableMeta*
|
||||||
} STableMetaCache;
|
} STableMetaCache;
|
||||||
|
|
@ -71,6 +77,41 @@ typedef uint32_t (*tableNameHashFp)(const char *, uint32_t);
|
||||||
#define CTG_ERR_LRET(c,...) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { ctgError(__VA_ARGS__); terrno = _code; return _code; } } while (0)
|
#define CTG_ERR_LRET(c,...) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { ctgError(__VA_ARGS__); terrno = _code; return _code; } } while (0)
|
||||||
#define CTG_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)
|
#define CTG_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)
|
||||||
|
|
||||||
|
#define TD_RWLATCH_WRITE_FLAG_COPY 0x40000000
|
||||||
|
|
||||||
|
#define CTG_LOCK(type, _lock) do { \
|
||||||
|
if (CTG_READ == (type)) { \
|
||||||
|
assert(atomic_load_32((_lock)) >= 0); \
|
||||||
|
ctgDebug("CTG RLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||||
|
taosRLockLatch(_lock); \
|
||||||
|
ctgDebug("CTG RLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||||
|
assert(atomic_load_32((_lock)) > 0); \
|
||||||
|
} else { \
|
||||||
|
assert(atomic_load_32((_lock)) >= 0); \
|
||||||
|
ctgDebug("CTG WLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||||
|
taosWLockLatch(_lock); \
|
||||||
|
ctgDebug("CTG WLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||||
|
assert(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define CTG_UNLOCK(type, _lock) do { \
|
||||||
|
if (CTG_READ == (type)) { \
|
||||||
|
assert(atomic_load_32((_lock)) > 0); \
|
||||||
|
ctgDebug("CTG RULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||||
|
taosRUnLockLatch(_lock); \
|
||||||
|
ctgDebug("CTG RULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||||
|
assert(atomic_load_32((_lock)) >= 0); \
|
||||||
|
} else { \
|
||||||
|
assert(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY); \
|
||||||
|
ctgDebug("CTG WULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||||
|
taosWUnLockLatch(_lock); \
|
||||||
|
ctgDebug("CTG WULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||||
|
assert(atomic_load_32((_lock)) >= 0); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -20,24 +20,38 @@
|
||||||
|
|
||||||
SCatalogMgmt ctgMgmt = {0};
|
SCatalogMgmt ctgMgmt = {0};
|
||||||
|
|
||||||
int32_t ctgGetDBVgroupFromCache(struct SCatalog* pCatalog, const char *dbName, SDBVgroupInfo *dbInfo, int32_t *exist) {
|
int32_t ctgGetDBVgroupFromCache(struct SCatalog* pCatalog, const char *dbName, SDBVgroupInfo **dbInfo, bool *inCache) {
|
||||||
if (NULL == pCatalog->dbCache.cache) {
|
if (NULL == pCatalog->dbCache.cache) {
|
||||||
*exist = 0;
|
*inCache = false;
|
||||||
|
ctgWarn("no db cache");
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDBVgroupInfo *info = taosHashGet(pCatalog->dbCache.cache, dbName, strlen(dbName));
|
SDBVgroupInfo *info = NULL;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
info = taosHashAcquire(pCatalog->dbCache.cache, dbName, strlen(dbName));
|
||||||
|
|
||||||
if (NULL == info) {
|
if (NULL == info) {
|
||||||
*exist = 0;
|
*inCache = false;
|
||||||
|
ctgWarn("no db cache, dbName:%s", dbName);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dbInfo) {
|
CTG_LOCK(CTG_READ, &info->lock);
|
||||||
*dbInfo = *info;
|
if (NULL == info->vgInfo) {
|
||||||
|
CTG_UNLOCK(CTG_READ, &info->lock);
|
||||||
|
taosHashRelease(pCatalog->dbCache.cache, info);
|
||||||
|
ctgWarn("db cache vgInfo is NULL, dbName:%s", dbName);
|
||||||
|
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
*exist = 1;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
*dbInfo = info;
|
||||||
|
*inCache = true;
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
@ -80,46 +94,51 @@ int32_t ctgGetTableMetaFromCache(struct SCatalog* pCatalog, const SName* pTableN
|
||||||
char tbFullName[TSDB_TABLE_FNAME_LEN];
|
char tbFullName[TSDB_TABLE_FNAME_LEN];
|
||||||
tNameExtractFullName(pTableName, tbFullName);
|
tNameExtractFullName(pTableName, tbFullName);
|
||||||
|
|
||||||
STableMeta *tbMeta = taosHashGet(pCatalog->tableCache.cache, tbFullName, strlen(tbFullName));
|
*pTableMeta = NULL;
|
||||||
|
|
||||||
if (NULL == tbMeta) {
|
size_t sz = 0;
|
||||||
|
STableMeta *tbMeta = taosHashGetCloneExt(pCatalog->tableCache.cache, tbFullName, strlen(tbFullName), NULL, (void **)pTableMeta, &sz);
|
||||||
|
|
||||||
|
if (NULL == *pTableMeta) {
|
||||||
*exist = 0;
|
*exist = 0;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tbMeta->tableType == TSDB_CHILD_TABLE) {
|
*exist = 1;
|
||||||
|
|
||||||
|
if (tbMeta->tableType != TSDB_CHILD_TABLE) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
CTG_LOCK(CTG_READ, &pCatalog->tableCache.stableLock);
|
||||||
|
|
||||||
STableMeta **stbMeta = taosHashGet(pCatalog->tableCache.stableCache, &tbMeta->suid, sizeof(tbMeta->suid));
|
STableMeta **stbMeta = taosHashGet(pCatalog->tableCache.stableCache, &tbMeta->suid, sizeof(tbMeta->suid));
|
||||||
if (NULL == stbMeta || NULL == *stbMeta) {
|
if (NULL == stbMeta || NULL == *stbMeta) {
|
||||||
|
CTG_UNLOCK(CTG_READ, &pCatalog->tableCache.stableLock);
|
||||||
|
qError("no stable:%"PRIx64 " meta in cache", tbMeta->suid);
|
||||||
|
tfree(*pTableMeta);
|
||||||
*exist = 0;
|
*exist = 0;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*stbMeta)->suid != tbMeta->suid) {
|
if ((*stbMeta)->suid != tbMeta->suid) {
|
||||||
|
CTG_UNLOCK(CTG_READ, &pCatalog->tableCache.stableLock);
|
||||||
|
tfree(*pTableMeta);
|
||||||
ctgError("stable cache error, expected suid:%"PRId64 ",actual suid:%"PRId64, tbMeta->suid, (*stbMeta)->suid);
|
ctgError("stable cache error, expected suid:%"PRId64 ",actual suid:%"PRId64, tbMeta->suid, (*stbMeta)->suid);
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t metaSize = sizeof(STableMeta) + ((*stbMeta)->tableInfo.numOfTags + (*stbMeta)->tableInfo.numOfColumns) * sizeof(SSchema);
|
int32_t metaSize = sizeof(STableMeta) + ((*stbMeta)->tableInfo.numOfTags + (*stbMeta)->tableInfo.numOfColumns) * sizeof(SSchema);
|
||||||
*pTableMeta = calloc(1, metaSize);
|
*pTableMeta = realloc(*pTableMeta, metaSize);
|
||||||
if (NULL == *pTableMeta) {
|
if (NULL == *pTableMeta) {
|
||||||
|
CTG_UNLOCK(CTG_READ, &pCatalog->tableCache.stableLock);
|
||||||
ctgError("calloc size[%d] failed", metaSize);
|
ctgError("calloc size[%d] failed", metaSize);
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(*pTableMeta, tbMeta, sizeof(SCTableMeta));
|
|
||||||
memcpy(&(*pTableMeta)->sversion, &(*stbMeta)->sversion, metaSize - sizeof(SCTableMeta));
|
memcpy(&(*pTableMeta)->sversion, &(*stbMeta)->sversion, metaSize - sizeof(SCTableMeta));
|
||||||
} else {
|
|
||||||
int32_t metaSize = sizeof(STableMeta) + (tbMeta->tableInfo.numOfTags + tbMeta->tableInfo.numOfColumns) * sizeof(SSchema);
|
|
||||||
*pTableMeta = calloc(1, metaSize);
|
|
||||||
if (NULL == *pTableMeta) {
|
|
||||||
ctgError("calloc size[%d] failed", metaSize);
|
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(*pTableMeta, tbMeta, metaSize);
|
CTG_UNLOCK(CTG_READ, &pCatalog->tableCache.stableLock);
|
||||||
}
|
|
||||||
|
|
||||||
*exist = 1;
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
@ -142,7 +161,7 @@ int32_t ctgGetTableMetaFromMnode(struct SCatalog* pCatalog, void *pRpc, const SE
|
||||||
char tbFullName[TSDB_TABLE_FNAME_LEN];
|
char tbFullName[TSDB_TABLE_FNAME_LEN];
|
||||||
tNameExtractFullName(pTableName, tbFullName);
|
tNameExtractFullName(pTableName, tbFullName);
|
||||||
|
|
||||||
SBuildTableMetaInput bInput = {.vgId = 0, .tableFullName = tbFullName};
|
SBuildTableMetaInput bInput = {.vgId = 0, .dbName = NULL, .tableFullName = tbFullName};
|
||||||
char *msg = NULL;
|
char *msg = NULL;
|
||||||
SEpSet *pVnodeEpSet = NULL;
|
SEpSet *pVnodeEpSet = NULL;
|
||||||
int32_t msgLen = 0;
|
int32_t msgLen = 0;
|
||||||
|
|
@ -170,16 +189,15 @@ int32_t ctgGetTableMetaFromMnode(struct SCatalog* pCatalog, void *pRpc, const SE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t ctgGetTableMetaFromVnode(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char *pDBName, const char* pTableName, SVgroupInfo *vgroupInfo, STableMetaOutput* output) {
|
int32_t ctgGetTableMetaFromVnode(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SVgroupInfo *vgroupInfo, STableMetaOutput* output) {
|
||||||
if (NULL == pCatalog || NULL == pRpc || NULL == pMgmtEps || NULL == pDBName || NULL == pTableName || NULL == vgroupInfo || NULL == output) {
|
if (NULL == pCatalog || NULL == pRpc || NULL == pMgmtEps || NULL == pTableName || NULL == vgroupInfo || NULL == output) {
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT);
|
CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
char tbFullName[TSDB_TABLE_FNAME_LEN];
|
char dbFullName[TSDB_DB_FNAME_LEN];
|
||||||
|
tNameGetFullDbName(pTableName, dbFullName);
|
||||||
|
|
||||||
snprintf(tbFullName, sizeof(tbFullName), "%s.%s", pDBName, pTableName);
|
SBuildTableMetaInput bInput = {.vgId = vgroupInfo->vgId, .dbName = dbFullName, .tableFullName = pTableName->tname};
|
||||||
|
|
||||||
SBuildTableMetaInput bInput = {.vgId = vgroupInfo->vgId, .tableFullName = tbFullName};
|
|
||||||
char *msg = NULL;
|
char *msg = NULL;
|
||||||
SEpSet *pVnodeEpSet = NULL;
|
SEpSet *pVnodeEpSet = NULL;
|
||||||
int32_t msgLen = 0;
|
int32_t msgLen = 0;
|
||||||
|
|
@ -223,9 +241,11 @@ int32_t ctgGetHashFunction(int8_t hashMethod, tableNameHashFp *fp) {
|
||||||
int32_t ctgGetVgInfoFromDB(struct SCatalog *pCatalog, void *pRpc, const SEpSet *pMgmtEps, SDBVgroupInfo *dbInfo, SArray** vgroupList) {
|
int32_t ctgGetVgInfoFromDB(struct SCatalog *pCatalog, void *pRpc, const SEpSet *pMgmtEps, SDBVgroupInfo *dbInfo, SArray** vgroupList) {
|
||||||
SHashObj *vgroupHash = NULL;
|
SHashObj *vgroupHash = NULL;
|
||||||
SVgroupInfo *vgInfo = NULL;
|
SVgroupInfo *vgInfo = NULL;
|
||||||
|
SArray *vgList = NULL;
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
*vgroupList = taosArrayInit(taosHashGetSize(dbInfo->vgInfo), sizeof(SVgroupInfo));
|
vgList = taosArrayInit(taosHashGetSize(dbInfo->vgInfo), sizeof(SVgroupInfo));
|
||||||
if (NULL == *vgroupList) {
|
if (NULL == vgList) {
|
||||||
ctgError("taosArrayInit failed");
|
ctgError("taosArrayInit failed");
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||||
}
|
}
|
||||||
|
|
@ -234,19 +254,32 @@ int32_t ctgGetVgInfoFromDB(struct SCatalog *pCatalog, void *pRpc, const SEpSet *
|
||||||
while (pIter) {
|
while (pIter) {
|
||||||
vgInfo = pIter;
|
vgInfo = pIter;
|
||||||
|
|
||||||
if (NULL == taosArrayPush(*vgroupList, vgInfo)) {
|
if (NULL == taosArrayPush(vgList, vgInfo)) {
|
||||||
ctgError("taosArrayPush failed");
|
ctgError("taosArrayPush failed");
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
pIter = taosHashIterate(dbInfo->vgInfo, pIter);
|
pIter = taosHashIterate(dbInfo->vgInfo, pIter);
|
||||||
vgInfo = NULL;
|
vgInfo = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*vgroupList = vgList;
|
||||||
|
vgList = NULL;
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
|
_return:
|
||||||
|
|
||||||
|
if (vgList) {
|
||||||
|
taosArrayDestroy(vgList);
|
||||||
|
}
|
||||||
|
|
||||||
|
CTG_RET(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ctgGetVgInfoFromHashValue(SDBVgroupInfo *dbInfo, const SName *pTableName, SVgroupInfo *pVgroup) {
|
int32_t ctgGetVgInfoFromHashValue(SDBVgroupInfo *dbInfo, const SName *pTableName, SVgroupInfo *pVgroup) {
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
int32_t vgNum = taosHashGetSize(dbInfo->vgInfo);
|
int32_t vgNum = taosHashGetSize(dbInfo->vgInfo);
|
||||||
char db[TSDB_DB_FNAME_LEN] = {0};
|
char db[TSDB_DB_FNAME_LEN] = {0};
|
||||||
tNameGetFullDbName(pTableName, db);
|
tNameGetFullDbName(pTableName, db);
|
||||||
|
|
@ -259,7 +292,7 @@ int32_t ctgGetVgInfoFromHashValue(SDBVgroupInfo *dbInfo, const SName *pTableName
|
||||||
tableNameHashFp fp = NULL;
|
tableNameHashFp fp = NULL;
|
||||||
SVgroupInfo *vgInfo = NULL;
|
SVgroupInfo *vgInfo = NULL;
|
||||||
|
|
||||||
CTG_ERR_RET(ctgGetHashFunction(dbInfo->hashMethod, &fp));
|
CTG_ERR_JRET(ctgGetHashFunction(dbInfo->hashMethod, &fp));
|
||||||
|
|
||||||
char tbFullName[TSDB_TABLE_FNAME_LEN];
|
char tbFullName[TSDB_TABLE_FNAME_LEN];
|
||||||
tNameExtractFullName(pTableName, tbFullName);
|
tNameExtractFullName(pTableName, tbFullName);
|
||||||
|
|
@ -279,12 +312,14 @@ int32_t ctgGetVgInfoFromHashValue(SDBVgroupInfo *dbInfo, const SName *pTableName
|
||||||
|
|
||||||
if (NULL == vgInfo) {
|
if (NULL == vgInfo) {
|
||||||
ctgError("no hash range found for hashvalue[%u]", hashValue);
|
ctgError("no hash range found for hashvalue[%u]", hashValue);
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
*pVgroup = *vgInfo;
|
*pVgroup = *vgInfo;
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
_return:
|
||||||
|
|
||||||
|
CTG_RET(TSDB_CODE_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ctgGetTableMetaImpl(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, bool forceUpdate, STableMeta** pTableMeta) {
|
int32_t ctgGetTableMetaImpl(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, bool forceUpdate, STableMeta** pTableMeta) {
|
||||||
|
|
@ -316,6 +351,8 @@ int32_t ctgGetTableMetaImpl(struct SCatalog* pCatalog, void *pRpc, const SEpSet*
|
||||||
|
|
||||||
|
|
||||||
int32_t ctgUpdateTableMetaCache(struct SCatalog *pCatalog, STableMetaOutput *output) {
|
int32_t ctgUpdateTableMetaCache(struct SCatalog *pCatalog, STableMetaOutput *output) {
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
if (output->metaNum != 1 && output->metaNum != 2) {
|
if (output->metaNum != 1 && output->metaNum != 2) {
|
||||||
ctgError("invalid table meta number[%d] got from meta rsp", output->metaNum);
|
ctgError("invalid table meta number[%d] got from meta rsp", output->metaNum);
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||||
|
|
@ -355,33 +392,39 @@ int32_t ctgUpdateTableMetaCache(struct SCatalog *pCatalog, STableMetaOutput *out
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tbSize = sizeof(*output->tbMeta) + sizeof(SSchema) * (output->tbMeta->tableInfo.numOfColumns + output->tbMeta->tableInfo.numOfTags);
|
int32_t tbSize = sizeof(*output->tbMeta) + sizeof(SSchema) * (output->tbMeta->tableInfo.numOfColumns + output->tbMeta->tableInfo.numOfTags);
|
||||||
|
|
||||||
|
if (TSDB_SUPER_TABLE == output->tbMeta->tableType) {
|
||||||
|
CTG_LOCK(CTG_WRITE, &pCatalog->tableCache.stableLock);
|
||||||
if (taosHashPut(pCatalog->tableCache.cache, output->tbFname, strlen(output->tbFname), output->tbMeta, tbSize) != 0) {
|
if (taosHashPut(pCatalog->tableCache.cache, output->tbFname, strlen(output->tbFname), output->tbMeta, tbSize) != 0) {
|
||||||
|
CTG_UNLOCK(CTG_WRITE, &pCatalog->tableCache.stableLock);
|
||||||
ctgError("push table[%s] to table cache failed", output->tbFname);
|
ctgError("push table[%s] to table cache failed", output->tbFname);
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_SUPER_TABLE == output->tbMeta->tableType) {
|
STableMeta *tbMeta = taosHashGet(pCatalog->tableCache.cache, output->tbFname, strlen(output->tbFname));
|
||||||
if (taosHashPut(pCatalog->tableCache.stableCache, &output->tbMeta->suid, sizeof(output->tbMeta->suid), &output->tbMeta, POINTER_BYTES) != 0) {
|
if (taosHashPut(pCatalog->tableCache.stableCache, &output->tbMeta->suid, sizeof(output->tbMeta->suid), &tbMeta, POINTER_BYTES) != 0) {
|
||||||
|
CTG_UNLOCK(CTG_WRITE, &pCatalog->tableCache.stableLock);
|
||||||
ctgError("push suid[%"PRIu64"] to stable cache failed", output->tbMeta->suid);
|
ctgError("push suid[%"PRIu64"] to stable cache failed", output->tbMeta->suid);
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||||
}
|
}
|
||||||
|
CTG_UNLOCK(CTG_WRITE, &pCatalog->tableCache.stableLock);
|
||||||
|
} else {
|
||||||
|
if (taosHashPut(pCatalog->tableCache.cache, output->tbFname, strlen(output->tbFname), output->tbMeta, tbSize) != 0) {
|
||||||
|
ctgError("push table[%s] to table cache failed", output->tbFname);
|
||||||
|
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
CTG_RET(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t ctgGetDBVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* dbName, int32_t forceUpdate, SDBVgroupInfo* dbInfo) {
|
int32_t ctgGetDBVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* dbName, int32_t forceUpdate, SDBVgroupInfo** dbInfo) {
|
||||||
if (NULL == pCatalog || NULL == dbName || NULL == pRpc || NULL == pMgmtEps) {
|
bool inCache = false;
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t exist = 0;
|
|
||||||
|
|
||||||
if (0 == forceUpdate) {
|
if (0 == forceUpdate) {
|
||||||
CTG_ERR_RET(ctgGetDBVgroupFromCache(pCatalog, dbName, dbInfo, &exist));
|
CTG_ERR_RET(ctgGetDBVgroupFromCache(pCatalog, dbName, dbInfo, &inCache));
|
||||||
|
|
||||||
if (exist) {
|
if (inCache) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -393,12 +436,46 @@ int32_t ctgGetDBVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgm
|
||||||
input.db[sizeof(input.db) - 1] = 0;
|
input.db[sizeof(input.db) - 1] = 0;
|
||||||
input.vgVersion = CTG_DEFAULT_INVALID_VERSION;
|
input.vgVersion = CTG_DEFAULT_INVALID_VERSION;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
CTG_ERR_RET(ctgGetDBVgroupFromMnode(pCatalog, pRpc, pMgmtEps, &input, &DbOut));
|
CTG_ERR_RET(ctgGetDBVgroupFromMnode(pCatalog, pRpc, pMgmtEps, &input, &DbOut));
|
||||||
|
|
||||||
CTG_ERR_RET(catalogUpdateDBVgroup(pCatalog, dbName, &DbOut.dbVgroup));
|
CTG_ERR_RET(catalogUpdateDBVgroup(pCatalog, dbName, &DbOut.dbVgroup));
|
||||||
|
|
||||||
if (dbInfo) {
|
CTG_ERR_RET(ctgGetDBVgroupFromCache(pCatalog, dbName, dbInfo, &inCache));
|
||||||
*dbInfo = DbOut.dbVgroup;
|
|
||||||
|
if (!inCache) {
|
||||||
|
ctgWarn("get db vgroup from cache failed, db:%s", dbName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32_t ctgValidateAndRemoveDb(struct SCatalog* pCatalog, const char* dbName, SDBVgroupInfo* dbInfo) {
|
||||||
|
SDBVgroupInfo *oldInfo = (SDBVgroupInfo *)taosHashAcquire(pCatalog->dbCache.cache, dbName, strlen(dbName));
|
||||||
|
if (oldInfo) {
|
||||||
|
CTG_LOCK(CTG_WRITE, &oldInfo->lock);
|
||||||
|
if (dbInfo->vgVersion <= oldInfo->vgVersion) {
|
||||||
|
ctgInfo("dbName:%s vg will not update, vgVersion:%d , current:%d", dbName, dbInfo->vgVersion, oldInfo->vgVersion);
|
||||||
|
CTG_UNLOCK(CTG_WRITE, &oldInfo->lock);
|
||||||
|
taosHashRelease(pCatalog->dbCache.cache, oldInfo);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldInfo->vgInfo) {
|
||||||
|
ctgInfo("dbName:%s vg will be cleanup", dbName);
|
||||||
|
taosHashCleanup(oldInfo->vgInfo);
|
||||||
|
oldInfo->vgInfo = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
CTG_UNLOCK(CTG_WRITE, &oldInfo->lock);
|
||||||
|
|
||||||
|
taosHashRelease(pCatalog->dbCache.cache, oldInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
@ -426,7 +503,7 @@ int32_t catalogInit(SCatalogCfg *cfg) {
|
||||||
ctgMgmt.cfg.maxTblCacheNum = CTG_DEFAULT_CACHE_TABLEMETA_NUMBER;
|
ctgMgmt.cfg.maxTblCacheNum = CTG_DEFAULT_CACHE_TABLEMETA_NUMBER;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctgMgmt.pCluster = taosHashInit(CTG_DEFAULT_CACHE_CLUSTER_NUMBER, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
ctgMgmt.pCluster = taosHashInit(CTG_DEFAULT_CACHE_CLUSTER_NUMBER, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK);
|
||||||
if (NULL == ctgMgmt.pCluster) {
|
if (NULL == ctgMgmt.pCluster) {
|
||||||
CTG_ERR_LRET(TSDB_CODE_CTG_INTERNAL_ERROR, "init %d cluster cache failed", CTG_DEFAULT_CACHE_CLUSTER_NUMBER);
|
CTG_ERR_LRET(TSDB_CODE_CTG_INTERNAL_ERROR, "init %d cluster cache failed", CTG_DEFAULT_CACHE_CLUSTER_NUMBER);
|
||||||
}
|
}
|
||||||
|
|
@ -434,8 +511,8 @@ int32_t catalogInit(SCatalogCfg *cfg) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t catalogGetHandle(const char* clusterId , struct SCatalog** catalogHandle) {
|
int32_t catalogGetHandle(uint64_t clusterId, struct SCatalog** catalogHandle) {
|
||||||
if (NULL == clusterId || NULL == catalogHandle) {
|
if (NULL == catalogHandle) {
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT);
|
CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -444,8 +521,7 @@ int32_t catalogGetHandle(const char* clusterId , struct SCatalog** catalogHandle
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_NOT_READY);
|
CTG_ERR_RET(TSDB_CODE_CTG_NOT_READY);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t clen = strlen(clusterId);
|
SCatalog **ctg = (SCatalog **)taosHashGet(ctgMgmt.pCluster, (char*)&clusterId, sizeof(clusterId));
|
||||||
SCatalog **ctg = (SCatalog **)taosHashGet(ctgMgmt.pCluster, clusterId, clen);
|
|
||||||
|
|
||||||
if (ctg && (*ctg)) {
|
if (ctg && (*ctg)) {
|
||||||
*catalogHandle = *ctg;
|
*catalogHandle = *ctg;
|
||||||
|
|
@ -458,8 +534,8 @@ int32_t catalogGetHandle(const char* clusterId , struct SCatalog** catalogHandle
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosHashPut(ctgMgmt.pCluster, clusterId, clen, &clusterCtg, POINTER_BYTES)) {
|
if (taosHashPut(ctgMgmt.pCluster, &clusterId, sizeof(clusterId), &clusterCtg, POINTER_BYTES)) {
|
||||||
ctgError("put cluster %s cache to hash failed", clusterId);
|
ctgError("put cluster %"PRIx64" cache to hash failed", clusterId);
|
||||||
tfree(clusterCtg);
|
tfree(clusterCtg);
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
@ -479,57 +555,120 @@ int32_t catalogGetDBVgroupVersion(struct SCatalog* pCatalog, const char* dbName,
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDBVgroupInfo * dbInfo = taosHashGet(pCatalog->dbCache.cache, dbName, strlen(dbName));
|
SDBVgroupInfo * dbInfo = taosHashAcquire(pCatalog->dbCache.cache, dbName, strlen(dbName));
|
||||||
if (NULL == dbInfo) {
|
if (NULL == dbInfo) {
|
||||||
*version = CTG_DEFAULT_INVALID_VERSION;
|
*version = CTG_DEFAULT_INVALID_VERSION;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
*version = dbInfo->vgVersion;
|
*version = dbInfo->vgVersion;
|
||||||
|
taosHashRelease(pCatalog->dbCache.cache, dbInfo);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDBVgroupInfo* dbInfo) {
|
int32_t catalogGetDBVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* dbName, int32_t forceUpdate, SArray** vgroupList) {
|
||||||
if (NULL == pCatalog || NULL == dbName || NULL == dbInfo) {
|
if (NULL == pCatalog || NULL == dbName || NULL == pRpc || NULL == pMgmtEps || NULL == vgroupList) {
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT);
|
CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dbInfo->vgVersion < 0) {
|
SDBVgroupInfo* db = NULL;
|
||||||
if (pCatalog->dbCache.cache) {
|
int32_t code = 0;
|
||||||
SDBVgroupInfo *oldInfo = taosHashGet(pCatalog->dbCache.cache, dbName, strlen(dbName));
|
SVgroupInfo *vgInfo = NULL;
|
||||||
if (oldInfo && oldInfo->vgInfo) {
|
SArray *vgList = NULL;
|
||||||
taosHashCleanup(oldInfo->vgInfo);
|
|
||||||
oldInfo->vgInfo = NULL;
|
CTG_ERR_JRET(ctgGetDBVgroup(pCatalog, pRpc, pMgmtEps, dbName, forceUpdate, &db));
|
||||||
|
|
||||||
|
vgList = taosArrayInit(taosHashGetSize(db->vgInfo), sizeof(SVgroupInfo));
|
||||||
|
if (NULL == vgList) {
|
||||||
|
ctgError("taosArrayInit failed");
|
||||||
|
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
taosHashRemove(pCatalog->dbCache.cache, dbName, strlen(dbName));
|
void *pIter = taosHashIterate(db->vgInfo, NULL);
|
||||||
|
while (pIter) {
|
||||||
|
vgInfo = pIter;
|
||||||
|
|
||||||
|
if (NULL == taosArrayPush(vgList, vgInfo)) {
|
||||||
|
ctgError("taosArrayPush failed");
|
||||||
|
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
pIter = taosHashIterate(db->vgInfo, pIter);
|
||||||
|
vgInfo = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*vgroupList = vgList;
|
||||||
|
vgList = NULL;
|
||||||
|
|
||||||
|
_return:
|
||||||
|
|
||||||
|
if (db) {
|
||||||
|
CTG_UNLOCK(CTG_READ, &db->lock);
|
||||||
|
taosHashRelease(pCatalog->dbCache.cache, db);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vgList) {
|
||||||
|
taosArrayDestroy(vgList);
|
||||||
|
vgList = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
CTG_RET(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDBVgroupInfo* dbInfo) {
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
|
if (NULL == pCatalog || NULL == dbName || NULL == dbInfo) {
|
||||||
|
CTG_ERR_JRET(TSDB_CODE_CTG_INVALID_INPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NULL == dbInfo->vgInfo || dbInfo->vgVersion < 0 || taosHashGetSize(dbInfo->vgInfo) <= 0) {
|
||||||
|
ctgError("invalid db vg, dbName:%s", dbName);
|
||||||
|
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dbInfo->vgVersion < 0) {
|
||||||
|
ctgWarn("invalid db vgVersion:%d, dbName:%s", dbInfo->vgVersion, dbName);
|
||||||
|
|
||||||
|
if (pCatalog->dbCache.cache) {
|
||||||
|
CTG_ERR_JRET(ctgValidateAndRemoveDb(pCatalog, dbName, dbInfo));
|
||||||
|
|
||||||
|
CTG_ERR_JRET(taosHashRemove(pCatalog->dbCache.cache, dbName, strlen(dbName)));
|
||||||
}
|
}
|
||||||
|
|
||||||
ctgWarn("remove db [%s] from cache", dbName);
|
ctgWarn("remove db [%s] from cache", dbName);
|
||||||
return TSDB_CODE_SUCCESS;
|
goto _return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL == pCatalog->dbCache.cache) {
|
if (NULL == pCatalog->dbCache.cache) {
|
||||||
pCatalog->dbCache.cache = taosHashInit(ctgMgmt.cfg.maxDBCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
pCatalog->dbCache.cache = taosHashInit(ctgMgmt.cfg.maxDBCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||||
if (NULL == pCatalog->dbCache.cache) {
|
if (NULL == pCatalog->dbCache.cache) {
|
||||||
ctgError("init hash[%d] for db cache failed", CTG_DEFAULT_CACHE_DB_NUMBER);
|
ctgError("init hash[%d] for db cache failed", CTG_DEFAULT_CACHE_DB_NUMBER);
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SDBVgroupInfo *oldInfo = taosHashGet(pCatalog->dbCache.cache, dbName, strlen(dbName));
|
CTG_ERR_JRET(ctgValidateAndRemoveDb(pCatalog, dbName, dbInfo));
|
||||||
if (oldInfo && oldInfo->vgInfo) {
|
|
||||||
taosHashCleanup(oldInfo->vgInfo);
|
|
||||||
oldInfo->vgInfo = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosHashPut(pCatalog->dbCache.cache, dbName, strlen(dbName), dbInfo, sizeof(*dbInfo)) != 0) {
|
if (taosHashPut(pCatalog->dbCache.cache, dbName, strlen(dbName), dbInfo, sizeof(*dbInfo)) != 0) {
|
||||||
ctgError("push to vgroup hash cache failed");
|
ctgError("push to vgroup hash cache failed");
|
||||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
ctgDebug("dbName:%s vgroup updated, vgVersion:%d", dbName, dbInfo->vgVersion);
|
||||||
|
|
||||||
|
dbInfo->vgInfo = NULL;
|
||||||
|
|
||||||
|
_return:
|
||||||
|
|
||||||
|
if (dbInfo && dbInfo->vgInfo) {
|
||||||
|
taosHashCleanup(dbInfo->vgInfo);
|
||||||
|
dbInfo->vgInfo = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
CTG_RET(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) {
|
int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) {
|
||||||
|
|
@ -548,9 +687,9 @@ int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSe
|
||||||
|
|
||||||
STableMetaOutput output = {0};
|
STableMetaOutput output = {0};
|
||||||
|
|
||||||
//CTG_ERR_RET(ctgGetTableMetaFromVnode(pCatalog, pRpc, pMgmtEps, pDBName, pTableName, &vgroupInfo, &output));
|
CTG_ERR_RET(ctgGetTableMetaFromVnode(pCatalog, pRpc, pMgmtEps, pTableName, &vgroupInfo, &output));
|
||||||
|
|
||||||
CTG_ERR_RET(ctgGetTableMetaFromMnode(pCatalog, pRpc, pMgmtEps, pTableName, &output));
|
//CTG_ERR_RET(ctgGetTableMetaFromMnode(pCatalog, pRpc, pMgmtEps, pTableName, &output));
|
||||||
|
|
||||||
CTG_ERR_JRET(ctgUpdateTableMetaCache(pCatalog, &output));
|
CTG_ERR_JRET(ctgUpdateTableMetaCache(pCatalog, &output));
|
||||||
|
|
||||||
|
|
@ -573,7 +712,10 @@ int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pRpc, const S
|
||||||
STableMeta *tbMeta = NULL;
|
STableMeta *tbMeta = NULL;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SVgroupInfo vgroupInfo = {0};
|
SVgroupInfo vgroupInfo = {0};
|
||||||
SDBVgroupInfo dbVgroup = {0};
|
SDBVgroupInfo* dbVgroup = NULL;
|
||||||
|
SArray *vgList = NULL;
|
||||||
|
|
||||||
|
*pVgroupList = NULL;
|
||||||
|
|
||||||
CTG_ERR_JRET(catalogGetTableMeta(pCatalog, pRpc, pMgmtEps, pTableName, &tbMeta));
|
CTG_ERR_JRET(catalogGetTableMeta(pCatalog, pRpc, pMgmtEps, pTableName, &tbMeta));
|
||||||
|
|
||||||
|
|
@ -582,38 +724,48 @@ int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pRpc, const S
|
||||||
CTG_ERR_JRET(ctgGetDBVgroup(pCatalog, pRpc, pMgmtEps, db, false, &dbVgroup));
|
CTG_ERR_JRET(ctgGetDBVgroup(pCatalog, pRpc, pMgmtEps, db, false, &dbVgroup));
|
||||||
|
|
||||||
if (tbMeta->tableType == TSDB_SUPER_TABLE) {
|
if (tbMeta->tableType == TSDB_SUPER_TABLE) {
|
||||||
CTG_ERR_JRET(ctgGetVgInfoFromDB(pCatalog, pRpc, pMgmtEps, &dbVgroup, pVgroupList));
|
CTG_ERR_JRET(ctgGetVgInfoFromDB(pCatalog, pRpc, pMgmtEps, dbVgroup, pVgroupList));
|
||||||
} else {
|
} else {
|
||||||
int32_t vgId = tbMeta->vgId;
|
int32_t vgId = tbMeta->vgId;
|
||||||
if (NULL == taosHashGetClone(dbVgroup.vgInfo, &vgId, sizeof(vgId), &vgroupInfo)) {
|
if (NULL == taosHashGetClone(dbVgroup->vgInfo, &vgId, sizeof(vgId), &vgroupInfo)) {
|
||||||
ctgError("vgId[%d] not found in vgroup list", vgId);
|
ctgError("vgId[%d] not found in vgroup list", vgId);
|
||||||
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
*pVgroupList = taosArrayInit(1, sizeof(SVgroupInfo));
|
vgList = taosArrayInit(1, sizeof(SVgroupInfo));
|
||||||
if (NULL == *pVgroupList) {
|
if (NULL == vgList) {
|
||||||
ctgError("taosArrayInit failed");
|
ctgError("taosArrayInit failed");
|
||||||
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL == taosArrayPush(*pVgroupList, &vgroupInfo)) {
|
if (NULL == taosArrayPush(vgList, &vgroupInfo)) {
|
||||||
ctgError("push vgroupInfo to array failed");
|
ctgError("push vgroupInfo to array failed");
|
||||||
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
tfree(tbMeta);
|
*pVgroupList = vgList;
|
||||||
return TSDB_CODE_SUCCESS;
|
vgList = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
_return:
|
_return:
|
||||||
tfree(tbMeta);
|
tfree(tbMeta);
|
||||||
taosArrayDestroy(*pVgroupList);
|
|
||||||
|
if (dbVgroup) {
|
||||||
|
CTG_UNLOCK(CTG_READ, &dbVgroup->lock);
|
||||||
|
taosHashRelease(pCatalog->dbCache.cache, dbVgroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vgList) {
|
||||||
|
taosArrayDestroy(vgList);
|
||||||
|
vgList = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
CTG_RET(code);
|
CTG_RET(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t catalogGetTableHashVgroup(struct SCatalog *pCatalog, void *pTransporter, const SEpSet *pMgmtEps, const SName *pTableName, SVgroupInfo *pVgroup) {
|
int32_t catalogGetTableHashVgroup(struct SCatalog *pCatalog, void *pTransporter, const SEpSet *pMgmtEps, const SName *pTableName, SVgroupInfo *pVgroup) {
|
||||||
SDBVgroupInfo dbInfo = {0};
|
SDBVgroupInfo* dbInfo = NULL;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
char db[TSDB_DB_FNAME_LEN] = {0};
|
char db[TSDB_DB_FNAME_LEN] = {0};
|
||||||
|
|
@ -621,12 +773,14 @@ int32_t catalogGetTableHashVgroup(struct SCatalog *pCatalog, void *pTransporter,
|
||||||
|
|
||||||
CTG_ERR_RET(ctgGetDBVgroup(pCatalog, pTransporter, pMgmtEps, db, false, &dbInfo));
|
CTG_ERR_RET(ctgGetDBVgroup(pCatalog, pTransporter, pMgmtEps, db, false, &dbInfo));
|
||||||
|
|
||||||
if (dbInfo.vgVersion < 0 || NULL == dbInfo.vgInfo) {
|
CTG_ERR_JRET(ctgGetVgInfoFromHashValue(dbInfo, pTableName, pVgroup));
|
||||||
ctgError("db[%s] vgroup cache invalid, vgroup version:%d, vgInfo:%p", db, dbInfo.vgVersion, dbInfo.vgInfo);
|
|
||||||
CTG_ERR_RET(TSDB_CODE_TSC_DB_NOT_SELECTED);
|
|
||||||
}
|
|
||||||
|
|
||||||
CTG_ERR_RET(ctgGetVgInfoFromHashValue(&dbInfo, pTableName, pVgroup));
|
_return:
|
||||||
|
|
||||||
|
if (dbInfo) {
|
||||||
|
CTG_UNLOCK(CTG_READ, &dbInfo->lock);
|
||||||
|
taosHashRelease(pCatalog->dbCache.cache, dbInfo);
|
||||||
|
}
|
||||||
|
|
||||||
CTG_RET(code);
|
CTG_RET(code);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,18 +36,26 @@
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
extern "C" int32_t ctgGetTableMetaFromCache(struct SCatalog* pCatalog, const SName* pTableName, STableMeta** pTableMeta, int32_t *exist);
|
||||||
|
extern "C" int32_t ctgUpdateTableMetaCache(struct SCatalog *pCatalog, STableMetaOutput *output);
|
||||||
|
|
||||||
void ctgTestSetPrepareTableMeta();
|
void ctgTestSetPrepareTableMeta();
|
||||||
void ctgTestSetPrepareCTableMeta();
|
void ctgTestSetPrepareCTableMeta();
|
||||||
void ctgTestSetPrepareSTableMeta();
|
void ctgTestSetPrepareSTableMeta();
|
||||||
|
|
||||||
|
bool ctgTestStop = false;
|
||||||
|
bool ctgTestEnableSleep = false;
|
||||||
|
bool ctgTestDeadLoop = true;
|
||||||
|
|
||||||
|
int32_t ctgTestCurrentVgVersion = 0;
|
||||||
|
int32_t ctgTestVgVersion = 1;
|
||||||
int32_t ctgTestVgNum = 10;
|
int32_t ctgTestVgNum = 10;
|
||||||
int32_t ctgTestColNum = 2;
|
int32_t ctgTestColNum = 2;
|
||||||
int32_t ctgTestTagNum = 1;
|
int32_t ctgTestTagNum = 1;
|
||||||
int32_t ctgTestSVersion = 1;
|
int32_t ctgTestSVersion = 1;
|
||||||
int32_t ctgTestTVersion = 1;
|
int32_t ctgTestTVersion = 1;
|
||||||
|
|
||||||
char *ctgTestClusterId = "cluster1";
|
uint64_t ctgTestClusterId = 0x1;
|
||||||
char *ctgTestDbname = "1.db1";
|
char *ctgTestDbname = "1.db1";
|
||||||
char *ctgTestTablename = "table1";
|
char *ctgTestTablename = "table1";
|
||||||
char *ctgTestCTablename = "ctable1";
|
char *ctgTestCTablename = "ctable1";
|
||||||
|
|
@ -89,6 +97,113 @@ void sendCreateDbMsg(void *shandle, SEpSet *pEpSet) {
|
||||||
ASSERT_EQ(rpcRsp.code, 0);
|
ASSERT_EQ(rpcRsp.code, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ctgTestInitLogFile() {
|
||||||
|
const char *defaultLogFileNamePrefix = "taoslog";
|
||||||
|
const int32_t maxLogFileNum = 10;
|
||||||
|
|
||||||
|
ctgDebugFlag = 159;
|
||||||
|
tsAsyncLog = 0;
|
||||||
|
|
||||||
|
char temp[128] = {0};
|
||||||
|
sprintf(temp, "%s/%s", tsLogDir, defaultLogFileNamePrefix);
|
||||||
|
if (taosInitLog(temp, tsNumOfLogLines, maxLogFileNum) < 0) {
|
||||||
|
printf("failed to open log file in directory:%s\n", tsLogDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t ctgTestGetVgNumFromVgVersion(int32_t vgVersion) {
|
||||||
|
return ((vgVersion % 2) == 0) ? ctgTestVgNum - 2 : ctgTestVgNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ctgTestBuildCTableMetaOutput(STableMetaOutput *output) {
|
||||||
|
SName cn = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
|
||||||
|
strcpy(cn.dbname, "db1");
|
||||||
|
strcpy(cn.tname, ctgTestCTablename);
|
||||||
|
|
||||||
|
SName sn = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
|
||||||
|
strcpy(sn.dbname, "db1");
|
||||||
|
strcpy(sn.tname, ctgTestSTablename);
|
||||||
|
|
||||||
|
char tbFullName[TSDB_TABLE_FNAME_LEN];
|
||||||
|
tNameExtractFullName(&cn, tbFullName);
|
||||||
|
|
||||||
|
output->metaNum = 2;
|
||||||
|
|
||||||
|
strcpy(output->ctbFname, tbFullName);
|
||||||
|
|
||||||
|
tNameExtractFullName(&cn, tbFullName);
|
||||||
|
strcpy(output->tbFname, tbFullName);
|
||||||
|
|
||||||
|
output->ctbMeta.vgId = 9;
|
||||||
|
output->ctbMeta.tableType = TSDB_CHILD_TABLE;
|
||||||
|
output->ctbMeta.uid = 3;
|
||||||
|
output->ctbMeta.suid = 2;
|
||||||
|
|
||||||
|
output->tbMeta = (STableMeta *)calloc(1, sizeof(STableMeta) + sizeof(SSchema) * (ctgTestColNum + ctgTestColNum));
|
||||||
|
output->tbMeta->vgId = 9;
|
||||||
|
output->tbMeta->tableType = TSDB_SUPER_TABLE;
|
||||||
|
output->tbMeta->uid = 2;
|
||||||
|
output->tbMeta->suid = 2;
|
||||||
|
|
||||||
|
output->tbMeta->tableInfo.numOfColumns = ctgTestColNum;
|
||||||
|
output->tbMeta->tableInfo.numOfTags = ctgTestTagNum;
|
||||||
|
|
||||||
|
output->tbMeta->sversion = ctgTestSVersion;
|
||||||
|
output->tbMeta->tversion = ctgTestTVersion;
|
||||||
|
|
||||||
|
SSchema *s = NULL;
|
||||||
|
s = &output->tbMeta->schema[0];
|
||||||
|
s->type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||||
|
s->colId = 1;
|
||||||
|
s->bytes = 8;
|
||||||
|
strcpy(s->name, "ts");
|
||||||
|
|
||||||
|
s = &output->tbMeta->schema[1];
|
||||||
|
s->type = TSDB_DATA_TYPE_INT;
|
||||||
|
s->colId = 2;
|
||||||
|
s->bytes = 4;
|
||||||
|
strcpy(s->name, "col1s");
|
||||||
|
|
||||||
|
s = &output->tbMeta->schema[2];
|
||||||
|
s->type = TSDB_DATA_TYPE_BINARY;
|
||||||
|
s->colId = 3;
|
||||||
|
s->bytes = 12;
|
||||||
|
strcpy(s->name, "tag1s");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ctgTestBuildDBVgroup(SDBVgroupInfo *dbVgroup) {
|
||||||
|
static int32_t vgVersion = ctgTestVgVersion + 1;
|
||||||
|
int32_t vgNum = 0;
|
||||||
|
SVgroupInfo vgInfo = {0};
|
||||||
|
|
||||||
|
dbVgroup->vgVersion = vgVersion++;
|
||||||
|
|
||||||
|
ctgTestCurrentVgVersion = dbVgroup->vgVersion;
|
||||||
|
|
||||||
|
dbVgroup->hashMethod = 0;
|
||||||
|
dbVgroup->vgInfo = taosHashInit(ctgTestVgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
||||||
|
|
||||||
|
vgNum = ctgTestGetVgNumFromVgVersion(dbVgroup->vgVersion);
|
||||||
|
uint32_t hashUnit = UINT32_MAX / vgNum;
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < vgNum; ++i) {
|
||||||
|
vgInfo.vgId = i + 1;
|
||||||
|
vgInfo.hashBegin = i * hashUnit;
|
||||||
|
vgInfo.hashEnd = hashUnit * (i + 1) - 1;
|
||||||
|
vgInfo.numOfEps = i % TSDB_MAX_REPLICA + 1;
|
||||||
|
vgInfo.inUse = i % vgInfo.numOfEps;
|
||||||
|
for (int32_t n = 0; n < vgInfo.numOfEps; ++n) {
|
||||||
|
SEpAddrMsg *addr = &vgInfo.epAddr[n];
|
||||||
|
strcpy(addr->fqdn, "a0");
|
||||||
|
addr->port = htons(n + 22);
|
||||||
|
}
|
||||||
|
|
||||||
|
taosHashPut(dbVgroup->vgInfo, &vgInfo.vgId, sizeof(vgInfo.vgId), &vgInfo, sizeof(vgInfo));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ctgTestPrepareDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
void ctgTestPrepareDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||||
SUseDbRsp *rspMsg = NULL; //todo
|
SUseDbRsp *rspMsg = NULL; //todo
|
||||||
|
|
||||||
|
|
@ -97,7 +212,8 @@ void ctgTestPrepareDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcM
|
||||||
pRsp->pCont = calloc(1, pRsp->contLen);
|
pRsp->pCont = calloc(1, pRsp->contLen);
|
||||||
rspMsg = (SUseDbRsp *)pRsp->pCont;
|
rspMsg = (SUseDbRsp *)pRsp->pCont;
|
||||||
strcpy(rspMsg->db, ctgTestDbname);
|
strcpy(rspMsg->db, ctgTestDbname);
|
||||||
rspMsg->vgVersion = htonl(1);
|
rspMsg->vgVersion = htonl(ctgTestVgVersion);
|
||||||
|
ctgTestCurrentVgVersion = ctgTestVgVersion;
|
||||||
rspMsg->vgNum = htonl(ctgTestVgNum);
|
rspMsg->vgNum = htonl(ctgTestVgNum);
|
||||||
rspMsg->hashMethod = 0;
|
rspMsg->hashMethod = 0;
|
||||||
|
|
||||||
|
|
@ -148,13 +264,13 @@ void ctgTestPrepareTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcM
|
||||||
SSchema *s = NULL;
|
SSchema *s = NULL;
|
||||||
s = &rspMsg->pSchema[0];
|
s = &rspMsg->pSchema[0];
|
||||||
s->type = TSDB_DATA_TYPE_TIMESTAMP;
|
s->type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||||
s->colId = htonl(0);
|
s->colId = htonl(1);
|
||||||
s->bytes = htonl(8);
|
s->bytes = htonl(8);
|
||||||
strcpy(s->name, "ts");
|
strcpy(s->name, "ts");
|
||||||
|
|
||||||
s = &rspMsg->pSchema[1];
|
s = &rspMsg->pSchema[1];
|
||||||
s->type = TSDB_DATA_TYPE_INT;
|
s->type = TSDB_DATA_TYPE_INT;
|
||||||
s->colId = htonl(1);
|
s->colId = htonl(2);
|
||||||
s->bytes = htonl(4);
|
s->bytes = htonl(4);
|
||||||
strcpy(s->name, "col1");
|
strcpy(s->name, "col1");
|
||||||
|
|
||||||
|
|
@ -185,19 +301,19 @@ void ctgTestPrepareCTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpc
|
||||||
SSchema *s = NULL;
|
SSchema *s = NULL;
|
||||||
s = &rspMsg->pSchema[0];
|
s = &rspMsg->pSchema[0];
|
||||||
s->type = TSDB_DATA_TYPE_TIMESTAMP;
|
s->type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||||
s->colId = htonl(0);
|
s->colId = htonl(1);
|
||||||
s->bytes = htonl(8);
|
s->bytes = htonl(8);
|
||||||
strcpy(s->name, "ts");
|
strcpy(s->name, "ts");
|
||||||
|
|
||||||
s = &rspMsg->pSchema[1];
|
s = &rspMsg->pSchema[1];
|
||||||
s->type = TSDB_DATA_TYPE_INT;
|
s->type = TSDB_DATA_TYPE_INT;
|
||||||
s->colId = htonl(1);
|
s->colId = htonl(2);
|
||||||
s->bytes = htonl(4);
|
s->bytes = htonl(4);
|
||||||
strcpy(s->name, "col1s");
|
strcpy(s->name, "col1s");
|
||||||
|
|
||||||
s = &rspMsg->pSchema[2];
|
s = &rspMsg->pSchema[2];
|
||||||
s->type = TSDB_DATA_TYPE_BINARY;
|
s->type = TSDB_DATA_TYPE_BINARY;
|
||||||
s->colId = htonl(2);
|
s->colId = htonl(3);
|
||||||
s->bytes = htonl(12);
|
s->bytes = htonl(12);
|
||||||
strcpy(s->name, "tag1s");
|
strcpy(s->name, "tag1s");
|
||||||
|
|
||||||
|
|
@ -229,19 +345,19 @@ void ctgTestPrepareSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpc
|
||||||
SSchema *s = NULL;
|
SSchema *s = NULL;
|
||||||
s = &rspMsg->pSchema[0];
|
s = &rspMsg->pSchema[0];
|
||||||
s->type = TSDB_DATA_TYPE_TIMESTAMP;
|
s->type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||||
s->colId = htonl(0);
|
s->colId = htonl(1);
|
||||||
s->bytes = htonl(8);
|
s->bytes = htonl(8);
|
||||||
strcpy(s->name, "ts");
|
strcpy(s->name, "ts");
|
||||||
|
|
||||||
s = &rspMsg->pSchema[1];
|
s = &rspMsg->pSchema[1];
|
||||||
s->type = TSDB_DATA_TYPE_INT;
|
s->type = TSDB_DATA_TYPE_INT;
|
||||||
s->colId = htonl(1);
|
s->colId = htonl(2);
|
||||||
s->bytes = htonl(4);
|
s->bytes = htonl(4);
|
||||||
strcpy(s->name, "col1s");
|
strcpy(s->name, "col1s");
|
||||||
|
|
||||||
s = &rspMsg->pSchema[2];
|
s = &rspMsg->pSchema[2];
|
||||||
s->type = TSDB_DATA_TYPE_BINARY;
|
s->type = TSDB_DATA_TYPE_BINARY;
|
||||||
s->colId = htonl(2);
|
s->colId = htonl(3);
|
||||||
s->bytes = htonl(12);
|
s->bytes = htonl(12);
|
||||||
strcpy(s->name, "tag1s");
|
strcpy(s->name, "tag1s");
|
||||||
|
|
||||||
|
|
@ -371,6 +487,121 @@ void ctgTestSetPrepareDbVgroupsAndSuperMeta() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *ctgTestGetDbVgroupThread(void *param) {
|
||||||
|
struct SCatalog* pCtg = (struct SCatalog*)param;
|
||||||
|
int32_t code = 0;
|
||||||
|
void *mockPointer = (void *)0x1;
|
||||||
|
SArray *vgList = NULL;
|
||||||
|
int32_t n = 0;
|
||||||
|
|
||||||
|
while (!ctgTestStop) {
|
||||||
|
code = catalogGetDBVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, ctgTestDbname, false, &vgList);
|
||||||
|
if (code) {
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vgList) {
|
||||||
|
taosArrayDestroy(vgList);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctgTestEnableSleep) {
|
||||||
|
usleep(rand()%5);
|
||||||
|
}
|
||||||
|
if (++n % 50000 == 0) {
|
||||||
|
printf("Get:%d\n", n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *ctgTestSetDbVgroupThread(void *param) {
|
||||||
|
struct SCatalog* pCtg = (struct SCatalog*)param;
|
||||||
|
int32_t code = 0;
|
||||||
|
SDBVgroupInfo dbVgroup = {0};
|
||||||
|
int32_t n = 0;
|
||||||
|
|
||||||
|
while (!ctgTestStop) {
|
||||||
|
ctgTestBuildDBVgroup(&dbVgroup);
|
||||||
|
code = catalogUpdateDBVgroup(pCtg, ctgTestDbname, &dbVgroup);
|
||||||
|
if (code) {
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctgTestEnableSleep) {
|
||||||
|
usleep(rand()%5);
|
||||||
|
}
|
||||||
|
if (++n % 50000 == 0) {
|
||||||
|
printf("Set:%d\n", n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void *ctgTestGetCtableMetaThread(void *param) {
|
||||||
|
struct SCatalog* pCtg = (struct SCatalog*)param;
|
||||||
|
int32_t code = 0;
|
||||||
|
int32_t n = 0;
|
||||||
|
STableMeta* tbMeta = NULL;
|
||||||
|
int32_t exist = 0;
|
||||||
|
|
||||||
|
SName cn = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
|
||||||
|
strcpy(cn.dbname, "db1");
|
||||||
|
strcpy(cn.tname, ctgTestCTablename);
|
||||||
|
|
||||||
|
while (!ctgTestStop) {
|
||||||
|
code = ctgGetTableMetaFromCache(pCtg, &cn, &tbMeta, &exist);
|
||||||
|
if (code || 0 == exist) {
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
tfree(tbMeta);
|
||||||
|
|
||||||
|
if (ctgTestEnableSleep) {
|
||||||
|
usleep(rand()%5);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (++n % 50000 == 0) {
|
||||||
|
printf("Get:%d\n", n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *ctgTestSetCtableMetaThread(void *param) {
|
||||||
|
struct SCatalog* pCtg = (struct SCatalog*)param;
|
||||||
|
int32_t code = 0;
|
||||||
|
SDBVgroupInfo dbVgroup = {0};
|
||||||
|
int32_t n = 0;
|
||||||
|
STableMetaOutput output = {0};
|
||||||
|
|
||||||
|
ctgTestBuildCTableMetaOutput(&output);
|
||||||
|
|
||||||
|
while (!ctgTestStop) {
|
||||||
|
code = ctgUpdateTableMetaCache(pCtg, &output);
|
||||||
|
if (code) {
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctgTestEnableSleep) {
|
||||||
|
usleep(rand()%5);
|
||||||
|
}
|
||||||
|
if (++n % 50000 == 0) {
|
||||||
|
printf("Set:%d\n", n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tfree(output.tbMeta);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
TEST(tableMeta, normalTable) {
|
TEST(tableMeta, normalTable) {
|
||||||
struct SCatalog* pCtg = NULL;
|
struct SCatalog* pCtg = NULL;
|
||||||
void *mockPointer = (void *)0x1;
|
void *mockPointer = (void *)0x1;
|
||||||
|
|
@ -388,7 +619,7 @@ TEST(tableMeta, normalTable) {
|
||||||
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||||
ASSERT_EQ(code, 0);
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
SName n = {.type = T_NAME_TABLE, .acctId = 1};
|
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
|
||||||
strcpy(n.dbname, "db1");
|
strcpy(n.dbname, "db1");
|
||||||
strcpy(n.tname, ctgTestTablename);
|
strcpy(n.tname, ctgTestTablename);
|
||||||
|
|
||||||
|
|
@ -436,11 +667,13 @@ TEST(tableMeta, childTableCase) {
|
||||||
initQueryModuleMsgHandle();
|
initQueryModuleMsgHandle();
|
||||||
|
|
||||||
//sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
|
//sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
|
||||||
|
int32_t code = catalogInit(NULL);
|
||||||
int32_t code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
|
||||||
ASSERT_EQ(code, 0);
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
SName n = {.type = T_NAME_TABLE, .acctId = 1};
|
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
|
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
|
||||||
strcpy(n.dbname, "db1");
|
strcpy(n.dbname, "db1");
|
||||||
strcpy(n.tname, ctgTestCTablename);
|
strcpy(n.tname, ctgTestCTablename);
|
||||||
|
|
||||||
|
|
@ -494,11 +727,14 @@ TEST(tableMeta, superTableCase) {
|
||||||
|
|
||||||
initQueryModuleMsgHandle();
|
initQueryModuleMsgHandle();
|
||||||
|
|
||||||
//sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
|
int32_t code = catalogInit(NULL);
|
||||||
int32_t code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
|
||||||
ASSERT_EQ(code, 0);
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
SName n = {.type = T_NAME_TABLE, .acctId = 1};
|
//sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
|
||||||
|
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
|
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
|
||||||
strcpy(n.dbname, "db1");
|
strcpy(n.dbname, "db1");
|
||||||
strcpy(n.tname, ctgTestSTablename);
|
strcpy(n.tname, ctgTestSTablename);
|
||||||
|
|
||||||
|
|
@ -558,12 +794,15 @@ TEST(tableDistVgroup, normalTable) {
|
||||||
|
|
||||||
initQueryModuleMsgHandle();
|
initQueryModuleMsgHandle();
|
||||||
|
|
||||||
//sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
|
int32_t code = catalogInit(NULL);
|
||||||
|
|
||||||
int32_t code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
|
||||||
ASSERT_EQ(code, 0);
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
SName n = {.type = T_NAME_TABLE, .acctId = 1};
|
//sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
|
||||||
|
|
||||||
|
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
|
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
|
||||||
strcpy(n.dbname, "db1");
|
strcpy(n.dbname, "db1");
|
||||||
strcpy(n.tname, ctgTestTablename);
|
strcpy(n.tname, ctgTestTablename);
|
||||||
|
|
||||||
|
|
@ -595,7 +834,7 @@ TEST(tableDistVgroup, childTableCase) {
|
||||||
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||||
ASSERT_EQ(code, 0);
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
SName n = {.type = T_NAME_TABLE, .acctId = 1};
|
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
|
||||||
strcpy(n.dbname, "db1");
|
strcpy(n.dbname, "db1");
|
||||||
strcpy(n.tname, ctgTestCTablename);
|
strcpy(n.tname, ctgTestCTablename);
|
||||||
|
|
||||||
|
|
@ -620,11 +859,14 @@ TEST(tableDistVgroup, superTableCase) {
|
||||||
|
|
||||||
initQueryModuleMsgHandle();
|
initQueryModuleMsgHandle();
|
||||||
|
|
||||||
//sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
|
int32_t code = catalogInit(NULL);
|
||||||
int32_t code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
|
||||||
ASSERT_EQ(code, 0);
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
SName n = {.type = T_NAME_TABLE, .acctId = 1};
|
//sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
|
||||||
|
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
|
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
|
||||||
strcpy(n.dbname, "db1");
|
strcpy(n.dbname, "db1");
|
||||||
strcpy(n.tname, ctgTestSTablename);
|
strcpy(n.tname, ctgTestSTablename);
|
||||||
|
|
||||||
|
|
@ -645,6 +887,167 @@ TEST(tableDistVgroup, superTableCase) {
|
||||||
catalogDestroy();
|
catalogDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(dbVgroup, getSetDbVgroupCase) {
|
||||||
|
struct SCatalog* pCtg = NULL;
|
||||||
|
void *mockPointer = (void *)0x1;
|
||||||
|
SVgroupInfo vgInfo = {0};
|
||||||
|
SVgroupInfo *pvgInfo = NULL;
|
||||||
|
SDBVgroupInfo dbVgroup = {0};
|
||||||
|
SArray *vgList = NULL;
|
||||||
|
|
||||||
|
ctgTestSetPrepareDbVgroupsAndNormalMeta();
|
||||||
|
|
||||||
|
initQueryModuleMsgHandle();
|
||||||
|
|
||||||
|
//sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
|
||||||
|
|
||||||
|
int32_t code = catalogInit(NULL);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
|
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
|
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
|
||||||
|
strcpy(n.dbname, "db1");
|
||||||
|
strcpy(n.tname, ctgTestTablename);
|
||||||
|
|
||||||
|
code = catalogGetDBVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, ctgTestDbname, false, &vgList);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), ctgTestVgNum);
|
||||||
|
|
||||||
|
code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
ASSERT_EQ(vgInfo.vgId, 8);
|
||||||
|
ASSERT_EQ(vgInfo.numOfEps, 3);
|
||||||
|
|
||||||
|
code = catalogGetTableDistVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgList);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 1);
|
||||||
|
pvgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0);
|
||||||
|
ASSERT_EQ(pvgInfo->vgId, 8);
|
||||||
|
ASSERT_EQ(pvgInfo->numOfEps, 3);
|
||||||
|
taosArrayDestroy(vgList);
|
||||||
|
|
||||||
|
ctgTestBuildDBVgroup(&dbVgroup);
|
||||||
|
code = catalogUpdateDBVgroup(pCtg, ctgTestDbname, &dbVgroup);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
|
code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
ASSERT_EQ(vgInfo.vgId, 7);
|
||||||
|
ASSERT_EQ(vgInfo.numOfEps, 2);
|
||||||
|
|
||||||
|
code = catalogGetTableDistVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgList);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 1);
|
||||||
|
pvgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0);
|
||||||
|
ASSERT_EQ(pvgInfo->vgId, 8);
|
||||||
|
ASSERT_EQ(pvgInfo->numOfEps, 3);
|
||||||
|
taosArrayDestroy(vgList);
|
||||||
|
|
||||||
|
catalogDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(multiThread, getSetDbVgroupCase) {
|
||||||
|
struct SCatalog* pCtg = NULL;
|
||||||
|
void *mockPointer = (void *)0x1;
|
||||||
|
SVgroupInfo vgInfo = {0};
|
||||||
|
SVgroupInfo *pvgInfo = NULL;
|
||||||
|
SDBVgroupInfo dbVgroup = {0};
|
||||||
|
SArray *vgList = NULL;
|
||||||
|
|
||||||
|
ctgTestInitLogFile();
|
||||||
|
|
||||||
|
ctgTestSetPrepareDbVgroups();
|
||||||
|
|
||||||
|
initQueryModuleMsgHandle();
|
||||||
|
|
||||||
|
//sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
|
||||||
|
|
||||||
|
int32_t code = catalogInit(NULL);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
|
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
|
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
|
||||||
|
strcpy(n.dbname, "db1");
|
||||||
|
strcpy(n.tname, ctgTestTablename);
|
||||||
|
|
||||||
|
pthread_attr_t thattr;
|
||||||
|
pthread_attr_init(&thattr);
|
||||||
|
|
||||||
|
pthread_t thread1, thread2;
|
||||||
|
pthread_create(&(thread1), &thattr, ctgTestSetDbVgroupThread, pCtg);
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
pthread_create(&(thread1), &thattr, ctgTestGetDbVgroupThread, pCtg);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
if (ctgTestDeadLoop) {
|
||||||
|
sleep(1);
|
||||||
|
} else {
|
||||||
|
sleep(600);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ctgTestStop = true;
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
|
catalogDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
TEST(multiThread, ctableMeta) {
|
||||||
|
struct SCatalog* pCtg = NULL;
|
||||||
|
void *mockPointer = (void *)0x1;
|
||||||
|
SVgroupInfo vgInfo = {0};
|
||||||
|
SVgroupInfo *pvgInfo = NULL;
|
||||||
|
SDBVgroupInfo dbVgroup = {0};
|
||||||
|
SArray *vgList = NULL;
|
||||||
|
|
||||||
|
ctgTestSetPrepareDbVgroupsAndChildMeta();
|
||||||
|
|
||||||
|
initQueryModuleMsgHandle();
|
||||||
|
|
||||||
|
//sendCreateDbMsg(pConn->pTransporter, &pConn->pAppInfo->mgmtEp.epSet);
|
||||||
|
|
||||||
|
int32_t code = catalogInit(NULL);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
|
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||||
|
ASSERT_EQ(code, 0);
|
||||||
|
|
||||||
|
SName n = {.type = TSDB_TABLE_NAME_T, .acctId = 1};
|
||||||
|
strcpy(n.dbname, "db1");
|
||||||
|
strcpy(n.tname, ctgTestTablename);
|
||||||
|
|
||||||
|
pthread_attr_t thattr;
|
||||||
|
pthread_attr_init(&thattr);
|
||||||
|
|
||||||
|
pthread_t thread1, thread2;
|
||||||
|
pthread_create(&(thread1), &thattr, ctgTestSetCtableMetaThread, pCtg);
|
||||||
|
sleep(1);
|
||||||
|
pthread_create(&(thread1), &thattr, ctgTestGetCtableMetaThread, pCtg);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
if (ctgTestDeadLoop) {
|
||||||
|
sleep(1);
|
||||||
|
} else {
|
||||||
|
sleep(600);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ctgTestStop = true;
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
|
catalogDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue