Merge remote-tracking branch 'origin/3.0' into feature/index_complete
This commit is contained in:
commit
a58dc03823
|
@ -6,13 +6,17 @@
|
|||
"dockerfile": "Dockerfile",
|
||||
// Update 'VARIANT' to pick an Debian / Ubuntu OS version: debian-11, debian-10, debian-9, ubuntu-21.04, ubuntu-20.04, ubuntu-18.04
|
||||
// Use Debian 11, Debian 9, Ubuntu 18.04 or Ubuntu 21.04 on local arm64/Apple Silicon
|
||||
"args": { "VARIANT": "ubuntu-21.04" }
|
||||
"args": {
|
||||
"VARIANT": "ubuntu-21.04"
|
||||
}
|
||||
},
|
||||
"runArgs": ["--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"],
|
||||
|
||||
"runArgs": [
|
||||
"--cap-add=SYS_PTRACE",
|
||||
"--security-opt",
|
||||
"seccomp=unconfined"
|
||||
],
|
||||
// Set *default* container specific settings.json values on container create.
|
||||
"settings": {},
|
||||
|
||||
// Add the IDs of extensions you want installed when the container is created.
|
||||
"extensions": [
|
||||
"ms-vscode.cpptools",
|
||||
|
@ -21,15 +25,13 @@
|
|||
"visualstudioexptteam.vscodeintel",
|
||||
"eamodio.gitlens",
|
||||
"matepek.vscode-catch2-test-adapter",
|
||||
"spmeesseman.vscode-taskexplorer"
|
||||
"spmeesseman.vscode-taskexplorer",
|
||||
"cschlosser.doxdocgen"
|
||||
],
|
||||
|
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
// "forwardPorts": [],
|
||||
|
||||
// Use 'postCreateCommand' to run commands after the container is created.
|
||||
// "postCreateCommand": "gcc -v",
|
||||
|
||||
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
|
||||
"remoteUser": "root"
|
||||
}
|
||||
}
|
|
@ -105,232 +105,19 @@ pipeline {
|
|||
abort_previous()
|
||||
abortPreviousBuilds()
|
||||
}
|
||||
pre_test()
|
||||
sh'''
|
||||
cd ${WKC}/tests
|
||||
./test-all.sh b1fq
|
||||
'''
|
||||
timeout(time: 45, unit: 'MINUTES'){
|
||||
pre_test()
|
||||
sh'''
|
||||
cd ${WKC}/tests
|
||||
./test-all.sh b1fq
|
||||
'''
|
||||
sh'''
|
||||
cd ${WKC}/debug
|
||||
ctest
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
// stage('Parallel test stage') {
|
||||
// skip defaultCheckout
|
||||
// options { skipDefaultCheckout() }
|
||||
// when {
|
||||
// allOf{
|
||||
// changeRequest()
|
||||
|
||||
// }
|
||||
// }
|
||||
// parallel {
|
||||
// stage('python_1_s1') {
|
||||
// agent{label " slave1 || slave11 "}
|
||||
// steps {
|
||||
|
||||
// pre_test()
|
||||
// // timeout(time: 55, unit: 'MINUTES'){
|
||||
// // sh '''
|
||||
// // date
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh p1
|
||||
// // date'''
|
||||
// // }
|
||||
|
||||
// }
|
||||
// }
|
||||
// stage('python_2_s5') {
|
||||
// agent{label " slave5 || slave15 "}
|
||||
// steps {
|
||||
|
||||
// pre_test()
|
||||
// // timeout(time: 55, unit: 'MINUTES'){
|
||||
// // sh '''
|
||||
// // date
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh p2
|
||||
// // date'''
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
// stage('python_3_s6') {
|
||||
// agent{label " slave6 || slave16 "}
|
||||
// steps {
|
||||
// pre_test()
|
||||
// // timeout(time: 55, unit: 'MINUTES'){
|
||||
|
||||
// // sh '''
|
||||
// // date
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh p3
|
||||
// // date'''
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
// stage('test_b1_s2') {
|
||||
// agent{label " slave2 || slave12 "}
|
||||
// steps {
|
||||
// pre_test()
|
||||
// // timeout(time: 55, unit: 'MINUTES'){
|
||||
|
||||
// // sh '''
|
||||
// // rm -rf /var/lib/taos/*
|
||||
// // rm -rf /var/log/taos/*
|
||||
// // nohup taosd >/dev/null &
|
||||
// // sleep 10
|
||||
// // '''
|
||||
// // sh '''
|
||||
// // cd ${WKC}/tests/examples/nodejs
|
||||
// // npm install td2.0-connector > /dev/null 2>&1
|
||||
// // node nodejsChecker.js host=localhost
|
||||
// // node test1970.js
|
||||
// // cd ${WKC}/tests/connectorTest/nodejsTest/nanosupport
|
||||
// // npm install td2.0-connector > /dev/null 2>&1
|
||||
// // node nanosecondTest.js
|
||||
|
||||
// // '''
|
||||
// // sh '''
|
||||
// // cd ${WKC}/tests/examples/C#/taosdemo
|
||||
// // mcs -out:taosdemo *.cs > /dev/null 2>&1
|
||||
// // echo '' |./taosdemo -c /etc/taos
|
||||
// // cd ${WKC}/tests/connectorTest/C#Test/nanosupport
|
||||
// // mcs -out:nano *.cs > /dev/null 2>&1
|
||||
// // echo '' |./nano
|
||||
// // '''
|
||||
// // sh '''
|
||||
// // cd ${WKC}/tests/gotest
|
||||
// // bash batchtest.sh
|
||||
// // '''
|
||||
// // sh '''
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh b1fq
|
||||
// // date'''
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
// stage('test_crash_gen_s3') {
|
||||
// agent{label " slave3 || slave13 "}
|
||||
|
||||
// steps {
|
||||
// pre_test()
|
||||
// // timeout(time: 60, unit: 'MINUTES'){
|
||||
// // sh '''
|
||||
// // cd ${WKC}/tests/pytest
|
||||
// // ./crash_gen.sh -a -p -t 4 -s 2000
|
||||
// // '''
|
||||
// // }
|
||||
// // timeout(time: 60, unit: 'MINUTES'){
|
||||
// // // sh '''
|
||||
// // // cd ${WKC}/tests/pytest
|
||||
// // // rm -rf /var/lib/taos/*
|
||||
// // // rm -rf /var/log/taos/*
|
||||
// // // ./handle_crash_gen_val_log.sh
|
||||
// // // '''
|
||||
// // sh '''
|
||||
// // cd ${WKC}/tests/pytest
|
||||
// // rm -rf /var/lib/taos/*
|
||||
// // rm -rf /var/log/taos/*
|
||||
// // ./handle_taosd_val_log.sh
|
||||
// // '''
|
||||
// // }
|
||||
// // timeout(time: 55, unit: 'MINUTES'){
|
||||
// // sh '''
|
||||
// // date
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh b2fq
|
||||
// // date
|
||||
// // '''
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
// stage('test_valgrind_s4') {
|
||||
// agent{label " slave4 || slave14 "}
|
||||
|
||||
// steps {
|
||||
// pre_test()
|
||||
// // catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
|
||||
// // sh '''
|
||||
// // cd ${WKC}/tests/pytest
|
||||
// // ./valgrind-test.sh 2>&1 > mem-error-out.log
|
||||
// // ./handle_val_log.sh
|
||||
// // '''
|
||||
// // }
|
||||
// // timeout(time: 55, unit: 'MINUTES'){
|
||||
// // sh '''
|
||||
// // date
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh b3fq
|
||||
// // date'''
|
||||
// // sh '''
|
||||
// // date
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh full example
|
||||
// // date'''
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
// stage('test_b4_s7') {
|
||||
// agent{label " slave7 || slave17 "}
|
||||
// steps {
|
||||
// pre_test()
|
||||
// // timeout(time: 55, unit: 'MINUTES'){
|
||||
|
||||
// // sh '''
|
||||
// // date
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh b4fq
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh p4
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh full jdbc
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh full unit
|
||||
// // date'''
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
// stage('test_b5_s8') {
|
||||
// agent{label " slave8 || slave18 "}
|
||||
// steps {
|
||||
// pre_test()
|
||||
// // timeout(time: 55, unit: 'MINUTES'){
|
||||
|
||||
// // sh '''
|
||||
// // date
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh b5fq
|
||||
// // date'''
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
// stage('test_b6_s9') {
|
||||
// agent{label " slave9 || slave19 "}
|
||||
// steps {
|
||||
// pre_test()
|
||||
// // timeout(time: 55, unit: 'MINUTES'){
|
||||
|
||||
// // sh '''
|
||||
// // date
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh b6fq
|
||||
// // date'''
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
// stage('test_b7_s10') {
|
||||
// agent{label " slave10 || slave20 "}
|
||||
// steps {
|
||||
// pre_test()
|
||||
// // timeout(time: 55, unit: 'MINUTES'){
|
||||
|
||||
// // sh '''
|
||||
// // date
|
||||
// // cd ${WKC}/tests
|
||||
// // ./test-all.sh b7fq
|
||||
// // date'''
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
post {
|
||||
success {
|
||||
|
|
|
@ -48,10 +48,11 @@ int32_t raftServerInit(SRaftServer *pRaftServer, const SRaftServerConfig *pConf,
|
|||
int32_t raftServerStart(SRaftServer *pRaftServer);
|
||||
void raftServerClose(SRaftServer *pRaftServer);
|
||||
|
||||
|
||||
int initFsm(struct raft_fsm *fsm);
|
||||
|
||||
|
||||
const char* state2String(unsigned short state);
|
||||
void printRaftConfiguration(struct raft_configuration *c);
|
||||
void printRaftState(struct raft *r);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
add_executable(raftMain "")
|
||||
target_sources(raftMain
|
||||
PRIVATE
|
||||
"raftMain.c"
|
||||
"raftServer.c"
|
||||
)
|
||||
target_link_libraries(raftMain PUBLIC traft lz4 uv_a)
|
||||
add_subdirectory(rebalance_leader)
|
||||
add_subdirectory(make_cluster)
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
add_executable(makeCluster "")
|
||||
target_sources(makeCluster
|
||||
PRIVATE
|
||||
"raftMain.c"
|
||||
"raftServer.c"
|
||||
"config.c"
|
||||
"console.c"
|
||||
"simpleHash.c"
|
||||
"util.c"
|
||||
)
|
||||
target_link_libraries(makeCluster PUBLIC traft lz4 uv_a)
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef TRAFT_COMMON_H
|
||||
#define TRAFT_COMMON_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define COMMAND_LEN 512
|
||||
#define MAX_CMD_COUNT 10
|
||||
#define TOKEN_LEN 128
|
||||
#define MAX_PEERS_COUNT 19
|
||||
|
||||
#define HOST_LEN 64
|
||||
#define ADDRESS_LEN (HOST_LEN * 2)
|
||||
#define BASE_DIR_LEN 128
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,64 @@
|
|||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void addrToString(const char *host, uint16_t port, char *addr, int len) { snprintf(addr, len, "%s:%hu", host, port); }
|
||||
|
||||
void parseAddr(const char *addr, char *host, int len, uint16_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, "%hu", port);
|
||||
}
|
||||
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
int parseConf(int argc, char **argv, RaftServerConfig *pConf) {
|
||||
memset(pConf, 0, sizeof(*pConf));
|
||||
|
||||
int option_index, option_value;
|
||||
option_index = 0;
|
||||
static struct option long_options[] = {{"help", no_argument, NULL, 'h'},
|
||||
{"addr", required_argument, NULL, 'a'},
|
||||
{"dir", required_argument, NULL, 'd'},
|
||||
{NULL, 0, NULL, 0}};
|
||||
|
||||
while ((option_value = getopt_long(argc, argv, "ha:d:", long_options, &option_index)) != -1) {
|
||||
switch (option_value) {
|
||||
case 'a': {
|
||||
parseAddr(optarg, pConf->me.host, sizeof(pConf->me.host), &pConf->me.port);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'd': {
|
||||
snprintf(pConf->baseDir, sizeof(pConf->baseDir), "%s", optarg);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'h': {
|
||||
return -2;
|
||||
}
|
||||
|
||||
default: { return -2; }
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void printConf(RaftServerConfig *pConf) {
|
||||
printf("\n---printConf: \n");
|
||||
printf("me: [%s:%hu] \n", pConf->me.host, pConf->me.port);
|
||||
printf("dataDir: [%s] \n\n", pConf->baseDir);
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
#ifndef TRAFT_CONFIG_H
|
||||
#define TRAFT_CONFIG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <getopt.h>
|
||||
#include <stdint.h>
|
||||
#include "common.h"
|
||||
|
||||
typedef struct {
|
||||
char host[HOST_LEN];
|
||||
uint16_t port;
|
||||
} Addr;
|
||||
|
||||
typedef struct {
|
||||
Addr me;
|
||||
char baseDir[BASE_DIR_LEN];
|
||||
} RaftServerConfig;
|
||||
|
||||
void addrToString(const char *host, uint16_t port, char *addr, int len);
|
||||
void parseAddr(const char *addr, char *host, int len, uint16_t *port);
|
||||
int parseConf(int argc, char **argv, RaftServerConfig *pConf);
|
||||
void printConf(RaftServerConfig *pConf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,202 @@
|
|||
#include "console.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "raftServer.h"
|
||||
#include "util.h"
|
||||
|
||||
void printHelp() {
|
||||
printf("---------------------\n");
|
||||
printf("help: \n\n");
|
||||
printf("create a vgroup with 3 replicas: \n");
|
||||
printf("create vnode voter vid 100 peers 127.0.0.1:10001 127.0.0.1:10002 \n");
|
||||
printf("create vnode voter vid 100 peers 127.0.0.1:10000 127.0.0.1:10002 \n");
|
||||
printf("create vnode voter vid 100 peers 127.0.0.1:10000 127.0.0.1:10001 \n");
|
||||
printf("\n");
|
||||
printf("create a vgroup with only one replica: \n");
|
||||
printf("create vnode voter vid 200 \n");
|
||||
printf("\n");
|
||||
printf("add vnode into vgroup: \n");
|
||||
printf("create vnode spare vid 100 ---- run at 127.0.0.1:10003\n");
|
||||
printf("join vnode vid 100 addr 127.0.0.1:10003 ---- run at leader of vgroup 100\n");
|
||||
printf("\n");
|
||||
printf("run \n");
|
||||
printf("put 0 key value \n");
|
||||
printf("get 0 key \n");
|
||||
printf("---------------------\n");
|
||||
}
|
||||
|
||||
void console(RaftServer *pRaftServer) {
|
||||
while (1) {
|
||||
int ret;
|
||||
char cmdBuf[COMMAND_LEN];
|
||||
memset(cmdBuf, 0, sizeof(cmdBuf));
|
||||
printf("(console)> ");
|
||||
char *retp = fgets(cmdBuf, COMMAND_LEN, stdin);
|
||||
if (!retp) {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
int pos = strlen(cmdBuf);
|
||||
if (cmdBuf[pos - 1] == '\n') {
|
||||
cmdBuf[pos - 1] = '\0';
|
||||
}
|
||||
|
||||
if (strncmp(cmdBuf, "", COMMAND_LEN) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char cmds[MAX_CMD_COUNT][TOKEN_LEN];
|
||||
memset(cmds, 0, sizeof(cmds));
|
||||
|
||||
int cmdCount;
|
||||
cmdCount = splitString(cmdBuf, " ", cmds, MAX_CMD_COUNT);
|
||||
|
||||
if (strcmp(cmds[0], "create") == 0 && strcmp(cmds[1], "vnode") == 0 && strcmp(cmds[3], "vid") == 0) {
|
||||
uint16_t vid;
|
||||
sscanf(cmds[4], "%hu", &vid);
|
||||
|
||||
if (strcmp(cmds[2], "voter") == 0) {
|
||||
char peers[MAX_PEERS_COUNT][ADDRESS_LEN];
|
||||
memset(peers, 0, sizeof(peers));
|
||||
uint32_t peersCount = 0;
|
||||
|
||||
if (strcmp(cmds[5], "peers") == 0 && cmdCount > 6) {
|
||||
// create vnode voter vid 100 peers 127.0.0.1:10001 127.0.0.1:10002
|
||||
for (int i = 6; i < cmdCount; ++i) {
|
||||
snprintf(peers[i - 6], ADDRESS_LEN, "%s", cmds[i]);
|
||||
peersCount++;
|
||||
}
|
||||
} else {
|
||||
// create vnode voter vid 200
|
||||
}
|
||||
ret = addRaftVoter(pRaftServer, peers, peersCount, vid);
|
||||
if (ret == 0) {
|
||||
printf("create vnode voter ok \n");
|
||||
} else {
|
||||
printf("create vnode voter error \n");
|
||||
}
|
||||
} else if (strcmp(cmds[2], "spare") == 0) {
|
||||
ret = addRaftSpare(pRaftServer, vid);
|
||||
if (ret == 0) {
|
||||
printf("create vnode spare ok \n");
|
||||
} else {
|
||||
printf("create vnode spare error \n");
|
||||
}
|
||||
} else {
|
||||
printHelp();
|
||||
}
|
||||
|
||||
} else if (strcmp(cmds[0], "join") == 0 && strcmp(cmds[1], "vnode") == 0 && strcmp(cmds[2], "vid") == 0 &&
|
||||
strcmp(cmds[4], "addr") == 0 && cmdCount == 6) {
|
||||
// join vnode vid 100 addr 127.0.0.1:10004
|
||||
|
||||
char * address = cmds[5];
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
parseAddr(address, host, sizeof(host), &port);
|
||||
|
||||
uint16_t vid;
|
||||
sscanf(cmds[3], "%hu", &vid);
|
||||
|
||||
HashNode **pp = pRaftServer->raftInstances.find(&pRaftServer->raftInstances, vid);
|
||||
if (*pp == NULL) {
|
||||
printf("vid:%hu not found \n", vid);
|
||||
break;
|
||||
}
|
||||
RaftInstance *pRaftInstance = (*pp)->data;
|
||||
|
||||
uint64_t destRaftId = encodeRaftId(host, port, vid);
|
||||
|
||||
struct raft_change *req = raft_malloc(sizeof(*req));
|
||||
RaftJoin * pRaftJoin = raft_malloc(sizeof(*pRaftJoin));
|
||||
pRaftJoin->r = &pRaftInstance->raft;
|
||||
pRaftJoin->joinId = destRaftId;
|
||||
req->data = pRaftJoin;
|
||||
ret = raft_add(&pRaftInstance->raft, req, destRaftId, address, raftChangeAddCb);
|
||||
if (ret != 0) {
|
||||
printf("raft_add error: %s \n", raft_errmsg(&pRaftInstance->raft));
|
||||
}
|
||||
|
||||
} else if (strcmp(cmds[0], "dropnode") == 0) {
|
||||
} else if (strcmp(cmds[0], "state") == 0) {
|
||||
pRaftServer->raftInstances.print(&pRaftServer->raftInstances);
|
||||
for (size_t i = 0; i < pRaftServer->raftInstances.length; ++i) {
|
||||
HashNode *ptr = pRaftServer->raftInstances.table[i];
|
||||
if (ptr != NULL) {
|
||||
while (ptr != NULL) {
|
||||
RaftInstance *pRaftInstance = ptr->data;
|
||||
printf("instance vid:%hu raftId:%llu \n", ptr->vgroupId, pRaftInstance->raftId);
|
||||
printRaftState(&pRaftInstance->raft);
|
||||
printf("\n");
|
||||
ptr = ptr->next;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
} else if (strcmp(cmds[0], "put") == 0 && cmdCount == 4) {
|
||||
uint16_t vid;
|
||||
sscanf(cmds[1], "%hu", &vid);
|
||||
char * key = cmds[2];
|
||||
char * value = cmds[3];
|
||||
HashNode **pp = pRaftServer->raftInstances.find(&pRaftServer->raftInstances, vid);
|
||||
if (*pp == NULL) {
|
||||
printf("vid:%hu not found \n", vid);
|
||||
break;
|
||||
}
|
||||
RaftInstance *pRaftInstance = (*pp)->data;
|
||||
|
||||
char *raftValue = malloc(TOKEN_LEN * 2 + 3);
|
||||
snprintf(raftValue, TOKEN_LEN * 2 + 3, "%s--%s", key, value);
|
||||
putValue(&pRaftInstance->raft, raftValue);
|
||||
free(raftValue);
|
||||
|
||||
} else if (strcmp(cmds[0], "run") == 0) {
|
||||
pthread_t tidRaftServer;
|
||||
pthread_create(&tidRaftServer, NULL, startServerFunc, pRaftServer);
|
||||
|
||||
} else if (strcmp(cmds[0], "get") == 0 && cmdCount == 3) {
|
||||
uint16_t vid;
|
||||
sscanf(cmds[1], "%hu", &vid);
|
||||
char * key = cmds[2];
|
||||
HashNode **pp = pRaftServer->raftInstances.find(&pRaftServer->raftInstances, vid);
|
||||
if (*pp == NULL) {
|
||||
printf("vid:%hu not found \n", vid);
|
||||
break;
|
||||
}
|
||||
RaftInstance * pRaftInstance = (*pp)->data;
|
||||
SimpleHash * pKV = pRaftInstance->fsm.data;
|
||||
SimpleHashNode **ppNode = pKV->find_cstr(pKV, key);
|
||||
if (*ppNode == NULL) {
|
||||
printf("key:%s not found \n", key);
|
||||
} else {
|
||||
printf("find key:%s value:%s \n", key, (char *)((*ppNode)->data));
|
||||
}
|
||||
|
||||
} else if (strcmp(cmds[0], "transfer") == 0) {
|
||||
} else if (strcmp(cmds[0], "state") == 0) {
|
||||
} else if (strcmp(cmds[0], "snapshot") == 0) {
|
||||
} else if (strcmp(cmds[0], "exit") == 0) {
|
||||
exit(0);
|
||||
|
||||
} else if (strcmp(cmds[0], "quit") == 0) {
|
||||
exit(0);
|
||||
|
||||
} else if (strcmp(cmds[0], "help") == 0) {
|
||||
printHelp();
|
||||
|
||||
} else {
|
||||
printf("unknown command: %s \n", cmdBuf);
|
||||
printHelp();
|
||||
}
|
||||
|
||||
/*
|
||||
printf("cmdBuf: [%s] \n", cmdBuf);
|
||||
printf("cmdCount : %d \n", cmdCount);
|
||||
for (int i = 0; i < MAX_CMD_COUNT; ++i) {
|
||||
printf("cmd%d : %s \n", i, cmds[i]);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef TRAFT_CONSOLE_H
|
||||
#define TRAFT_CONSOLE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <getopt.h>
|
||||
#include <stdint.h>
|
||||
#include "common.h"
|
||||
#include "raftServer.h"
|
||||
|
||||
void console(RaftServer *pRaftServer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,81 @@
|
|||
#include <assert.h>
|
||||
#include <getopt.h>
|
||||
#include <pthread.h>
|
||||
#include <raft.h>
|
||||
#include <raft/uv.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include "common.h"
|
||||
#include "config.h"
|
||||
#include "console.h"
|
||||
#include "raftServer.h"
|
||||
#include "simpleHash.h"
|
||||
#include "util.h"
|
||||
|
||||
const char *exe_name;
|
||||
|
||||
void *startConsoleFunc(void *param) {
|
||||
RaftServer *pRaftServer = (RaftServer *)param;
|
||||
console(pRaftServer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void usage() {
|
||||
printf("\nusage: \n");
|
||||
printf("%s --addr=127.0.0.1:10000 --dir=./data \n", exe_name);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
RaftServerConfig gConfig;
|
||||
RaftServer gRaftServer;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
srand(time(NULL));
|
||||
int32_t ret;
|
||||
|
||||
exe_name = argv[0];
|
||||
if (argc < 3) {
|
||||
usage();
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
ret = parseConf(argc, argv, &gConfig);
|
||||
if (ret != 0) {
|
||||
usage();
|
||||
exit(-1);
|
||||
}
|
||||
printConf(&gConfig);
|
||||
|
||||
if (!dirOK(gConfig.baseDir)) {
|
||||
ret = mkdir(gConfig.baseDir, 0775);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "mkdir error, %s \n", gConfig.baseDir);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
ret = raftServerInit(&gRaftServer, &gConfig);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "raftServerInit error \n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/*
|
||||
pthread_t tidRaftServer;
|
||||
pthread_create(&tidRaftServer, NULL, startServerFunc, &gRaftServer);
|
||||
*/
|
||||
|
||||
pthread_t tidConsole;
|
||||
pthread_create(&tidConsole, NULL, startConsoleFunc, &gRaftServer);
|
||||
|
||||
while (1) {
|
||||
sleep(10);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,286 @@
|
|||
#include "raftServer.h"
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "common.h"
|
||||
#include "simpleHash.h"
|
||||
#include "util.h"
|
||||
|
||||
void *startServerFunc(void *param) {
|
||||
RaftServer *pRaftServer = (RaftServer *)param;
|
||||
int32_t r = raftServerStart(pRaftServer);
|
||||
assert(r == 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void raftChangeAssignCb(struct raft_change *req, int status) {
|
||||
struct raft *r = req->data;
|
||||
if (status != 0) {
|
||||
printf("raftChangeAssignCb error: %s \n", raft_errmsg(r));
|
||||
} else {
|
||||
printf("raftChangeAssignCb ok \n");
|
||||
}
|
||||
raft_free(req);
|
||||
}
|
||||
|
||||
void raftChangeAddCb(struct raft_change *req, int status) {
|
||||
RaftJoin *pRaftJoin = req->data;
|
||||
if (status != 0) {
|
||||
printf("raftChangeAddCb error: %s \n", raft_errmsg(pRaftJoin->r));
|
||||
} else {
|
||||
struct raft_change *req2 = raft_malloc(sizeof(*req2));
|
||||
req2->data = pRaftJoin->r;
|
||||
int ret = raft_assign(pRaftJoin->r, req2, pRaftJoin->joinId, RAFT_VOTER, raftChangeAssignCb);
|
||||
if (ret != 0) {
|
||||
printf("raftChangeAddCb error: %s \n", raft_errmsg(pRaftJoin->r));
|
||||
}
|
||||
}
|
||||
raft_free(req->data);
|
||||
raft_free(req);
|
||||
}
|
||||
|
||||
int fsmApplyCb(struct raft_fsm *pFsm, const struct raft_buffer *buf, void **result) {
|
||||
// get fsm data
|
||||
SimpleHash *sh = pFsm->data;
|
||||
|
||||
// get commit value
|
||||
char *msg = (char *)buf->base;
|
||||
printf("fsm apply: [%s] \n", msg);
|
||||
char arr[2][TOKEN_LEN];
|
||||
int r = splitString(msg, "--", arr, 2);
|
||||
assert(r == 2);
|
||||
|
||||
// do the value on fsm
|
||||
sh->insert_cstr(sh, arr[0], arr[1]);
|
||||
|
||||
raft_free(buf->base);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void putValueCb(struct raft_apply *req, int status, void *result) {
|
||||
struct raft *r = req->data;
|
||||
if (status != 0) {
|
||||
printf("putValueCb error: %s \n", raft_errmsg(r));
|
||||
} else {
|
||||
printf("putValueCb: %s \n", "ok");
|
||||
}
|
||||
raft_free(req);
|
||||
}
|
||||
|
||||
void putValue(struct raft *r, const char *value) {
|
||||
struct raft_buffer buf;
|
||||
|
||||
buf.len = strlen(value) + 1;
|
||||
buf.base = raft_malloc(buf.len);
|
||||
snprintf(buf.base, buf.len, "%s", value);
|
||||
|
||||
struct raft_apply *req = raft_malloc(sizeof(*req));
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
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 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");
|
||||
}
|
||||
|
||||
int32_t addRaftVoter(RaftServer *pRaftServer, char peers[][ADDRESS_LEN], uint32_t peersCount, uint16_t vid) {
|
||||
int ret;
|
||||
|
||||
RaftInstance *pRaftInstance = malloc(sizeof(*pRaftInstance));
|
||||
assert(pRaftInstance != NULL);
|
||||
|
||||
// init raftId
|
||||
pRaftInstance->raftId = encodeRaftId(pRaftServer->host, pRaftServer->port, vid);
|
||||
|
||||
// init dir
|
||||
snprintf(pRaftInstance->dir, sizeof(pRaftInstance->dir), "%s/%s_%hu_%hu_%llu", pRaftServer->baseDir,
|
||||
pRaftServer->host, pRaftServer->port, vid, pRaftInstance->raftId);
|
||||
|
||||
if (!dirOK(pRaftInstance->dir)) {
|
||||
ret = mkdir(pRaftInstance->dir, 0775);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "mkdir error, %s \n", pRaftInstance->dir);
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
// init fsm
|
||||
pRaftInstance->fsm.data = newSimpleHash(2);
|
||||
pRaftInstance->fsm.apply = fsmApplyCb;
|
||||
|
||||
// init io
|
||||
ret = raft_uv_init(&pRaftInstance->io, &pRaftServer->loop, pRaftInstance->dir, &pRaftServer->transport);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "raft_uv_init error, %s \n", raft_errmsg(&pRaftInstance->raft));
|
||||
assert(0);
|
||||
}
|
||||
|
||||
// init raft
|
||||
ret = raft_init(&pRaftInstance->raft, &pRaftInstance->io, &pRaftInstance->fsm, pRaftInstance->raftId,
|
||||
pRaftServer->address);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "raft_init error, %s \n", raft_errmsg(&pRaftInstance->raft));
|
||||
assert(0);
|
||||
}
|
||||
|
||||
// init raft_configuration
|
||||
struct raft_configuration conf;
|
||||
raft_configuration_init(&conf);
|
||||
raft_configuration_add(&conf, pRaftInstance->raftId, pRaftServer->address, RAFT_VOTER);
|
||||
for (int i = 0; i < peersCount; ++i) {
|
||||
char * peerAddress = peers[i];
|
||||
char host[64];
|
||||
uint16_t port;
|
||||
parseAddr(peerAddress, host, sizeof(host), &port);
|
||||
uint64_t raftId = encodeRaftId(host, port, vid);
|
||||
raft_configuration_add(&conf, raftId, peers[i], RAFT_VOTER);
|
||||
}
|
||||
raft_bootstrap(&pRaftInstance->raft, &conf);
|
||||
|
||||
// start raft
|
||||
ret = raft_start(&pRaftInstance->raft);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "raft_start error, %s \n", raft_errmsg(&pRaftInstance->raft));
|
||||
assert(0);
|
||||
}
|
||||
|
||||
// add raft instance into raft server
|
||||
pRaftServer->raftInstances.insert(&pRaftServer->raftInstances, vid, pRaftInstance);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t addRaftSpare(RaftServer *pRaftServer, uint16_t vid) {
|
||||
int ret;
|
||||
|
||||
RaftInstance *pRaftInstance = malloc(sizeof(*pRaftInstance));
|
||||
assert(pRaftInstance != NULL);
|
||||
|
||||
// init raftId
|
||||
pRaftInstance->raftId = encodeRaftId(pRaftServer->host, pRaftServer->port, vid);
|
||||
|
||||
// init dir
|
||||
snprintf(pRaftInstance->dir, sizeof(pRaftInstance->dir), "%s/%s_%hu_%hu_%llu", pRaftServer->baseDir,
|
||||
pRaftServer->host, pRaftServer->port, vid, pRaftInstance->raftId);
|
||||
ret = mkdir(pRaftInstance->dir, 0775);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "mkdir error, %s \n", pRaftInstance->dir);
|
||||
assert(0);
|
||||
}
|
||||
|
||||
// init fsm
|
||||
pRaftInstance->fsm.data = newSimpleHash(2);
|
||||
pRaftInstance->fsm.apply = fsmApplyCb;
|
||||
|
||||
// init io
|
||||
ret = raft_uv_init(&pRaftInstance->io, &pRaftServer->loop, pRaftInstance->dir, &pRaftServer->transport);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "raft_uv_init error, %s \n", raft_errmsg(&pRaftInstance->raft));
|
||||
assert(0);
|
||||
}
|
||||
|
||||
// init raft
|
||||
ret = raft_init(&pRaftInstance->raft, &pRaftInstance->io, &pRaftInstance->fsm, pRaftInstance->raftId,
|
||||
pRaftServer->address);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "raft_init error, %s \n", raft_errmsg(&pRaftInstance->raft));
|
||||
assert(0);
|
||||
}
|
||||
|
||||
// init raft_configuration
|
||||
struct raft_configuration conf;
|
||||
raft_configuration_init(&conf);
|
||||
raft_configuration_add(&conf, pRaftInstance->raftId, pRaftServer->address, RAFT_SPARE);
|
||||
raft_bootstrap(&pRaftInstance->raft, &conf);
|
||||
|
||||
// start raft
|
||||
ret = raft_start(&pRaftInstance->raft);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "raft_start error, %s \n", raft_errmsg(&pRaftInstance->raft));
|
||||
assert(0);
|
||||
}
|
||||
|
||||
// add raft instance into raft server
|
||||
pRaftServer->raftInstances.insert(&pRaftServer->raftInstances, vid, pRaftInstance);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t raftServerInit(RaftServer *pRaftServer, const RaftServerConfig *pConf) {
|
||||
int ret;
|
||||
|
||||
// init host, port, address, dir
|
||||
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);
|
||||
snprintf(pRaftServer->baseDir, sizeof(pRaftServer->baseDir), "%s", pConf->baseDir);
|
||||
|
||||
// init loop
|
||||
ret = uv_loop_init(&pRaftServer->loop);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "uv_loop_init error: %s \n", uv_strerror(ret));
|
||||
assert(0);
|
||||
}
|
||||
|
||||
// init network
|
||||
ret = raft_uv_tcp_init(&pRaftServer->transport, &pRaftServer->loop);
|
||||
if (ret != 0) {
|
||||
fprintf(stderr, "raft_uv_tcp_init: error %d \n", ret);
|
||||
assert(0);
|
||||
}
|
||||
|
||||
// init raft instance container
|
||||
initIdHash(&pRaftServer->raftInstances, 2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t raftServerStart(RaftServer *pRaftServer) {
|
||||
// start loop
|
||||
uv_run(&pRaftServer->loop, UV_RUN_DEFAULT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void raftServerStop(RaftServer *pRaftServer) {}
|
|
@ -0,0 +1,66 @@
|
|||
#ifndef TDENGINE_RAFT_SERVER_H
|
||||
#define TDENGINE_RAFT_SERVER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <netinet/in.h>
|
||||
#include <string.h>
|
||||
#include "common.h"
|
||||
#include "config.h"
|
||||
#include "raft.h"
|
||||
#include "raft/uv.h"
|
||||
#include "simpleHash.h"
|
||||
|
||||
typedef struct RaftJoin {
|
||||
struct raft *r;
|
||||
raft_id joinId;
|
||||
} RaftJoin;
|
||||
|
||||
typedef struct {
|
||||
raft_id raftId;
|
||||
char dir[BASE_DIR_LEN * 2];
|
||||
struct raft_fsm fsm;
|
||||
struct raft_io io;
|
||||
struct raft raft;
|
||||
} RaftInstance;
|
||||
|
||||
typedef struct {
|
||||
char host[HOST_LEN];
|
||||
uint16_t port;
|
||||
char address[ADDRESS_LEN]; /* Raft instance address */
|
||||
char baseDir[BASE_DIR_LEN]; /* Raft instance address */
|
||||
|
||||
struct uv_loop_s loop; /* UV loop */
|
||||
struct raft_uv_transport transport; /* UV I/O backend transport */
|
||||
|
||||
IdHash raftInstances; /* multi raft instances. traft use IdHash to manager multi vgroup inside, here we can use IdHash
|
||||
too. */
|
||||
} RaftServer;
|
||||
|
||||
void * startServerFunc(void *param);
|
||||
int32_t addRaftVoter(RaftServer *pRaftServer, char peers[][ADDRESS_LEN], uint32_t peersCount, uint16_t vid);
|
||||
int32_t addRaftSpare(RaftServer *pRaftServer, uint16_t vid);
|
||||
|
||||
int32_t raftServerInit(RaftServer *pRaftServer, const RaftServerConfig *pConf);
|
||||
int32_t raftServerStart(RaftServer *pRaftServer);
|
||||
void raftServerStop(RaftServer *pRaftServer);
|
||||
|
||||
int fsmApplyCb(struct raft_fsm *pFsm, const struct raft_buffer *buf, void **result);
|
||||
void putValueCb(struct raft_apply *req, int status, void *result);
|
||||
void putValue(struct raft *r, const char *value);
|
||||
|
||||
void raftChangeAddCb(struct raft_change *req, int status);
|
||||
|
||||
const char *state2String(unsigned short state);
|
||||
void printRaftConfiguration(struct raft_configuration *c);
|
||||
void printRaftState(struct raft *r);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TDENGINE_RAFT_SERVER_H
|
|
@ -0,0 +1,218 @@
|
|||
#include "simpleHash.h"
|
||||
|
||||
uint32_t mySimpleHash(const char* data, size_t n, uint32_t seed) {
|
||||
// Similar to murmur hash
|
||||
const uint32_t m = 0xc6a4a793;
|
||||
const uint32_t r = 24;
|
||||
const char* limit = data + n;
|
||||
uint32_t h = seed ^ (n * m);
|
||||
|
||||
// Pick up four bytes at a time
|
||||
while (data + 4 <= limit) {
|
||||
// uint32_t w = DecodeFixed32(data);
|
||||
uint32_t w;
|
||||
memcpy(&w, data, 4);
|
||||
|
||||
data += 4;
|
||||
h += w;
|
||||
h *= m;
|
||||
h ^= (h >> 16);
|
||||
}
|
||||
|
||||
// Pick up remaining bytes
|
||||
switch (limit - data) {
|
||||
case 3:
|
||||
h += (unsigned char)(data[2]) << 16;
|
||||
do {
|
||||
} while (0);
|
||||
case 2:
|
||||
h += (unsigned char)(data[1]) << 8;
|
||||
do {
|
||||
} while (0);
|
||||
case 1:
|
||||
h += (unsigned char)(data[0]);
|
||||
h *= m;
|
||||
h ^= (h >> r);
|
||||
break;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
int insertCStrSimpleHash(struct SimpleHash* ths, char* key, char* data) {
|
||||
return insertSimpleHash(ths, key, strlen(key) + 1, data, strlen(data) + 1);
|
||||
}
|
||||
|
||||
int removeCStrSimpleHash(struct SimpleHash* ths, char* key) { return removeSimpleHash(ths, key, strlen(key) + 1); }
|
||||
|
||||
SimpleHashNode** findCStrSimpleHash(struct SimpleHash* ths, char* key) {
|
||||
return findSimpleHash(ths, key, strlen(key) + 1);
|
||||
}
|
||||
|
||||
int insertSimpleHash(struct SimpleHash* ths, char* key, size_t keyLen, char* data, size_t dataLen) {
|
||||
SimpleHashNode** pp = ths->find(ths, key, keyLen);
|
||||
if (*pp != NULL) {
|
||||
fprintf(stderr, "insertSimpleHash, already has key \n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
SimpleHashNode* node = malloc(sizeof(*node));
|
||||
node->hashCode = ths->hashFunc(key, keyLen);
|
||||
node->key = malloc(keyLen);
|
||||
node->keyLen = keyLen;
|
||||
memcpy(node->key, key, keyLen);
|
||||
node->data = malloc(dataLen);
|
||||
node->dataLen = dataLen;
|
||||
memcpy(node->data, data, dataLen);
|
||||
node->next = NULL;
|
||||
|
||||
// printf("insertSimpleHash: <%s, %ld, %s, %ld, %u> \n", node->key, node->keyLen, node->data, node->dataLen,
|
||||
// node->hashCode);
|
||||
|
||||
size_t index = node->hashCode & (ths->length - 1);
|
||||
|
||||
SimpleHashNode* ptr = ths->table[index];
|
||||
if (ptr != NULL) {
|
||||
node->next = ptr;
|
||||
ths->table[index] = node;
|
||||
|
||||
} else {
|
||||
ths->table[index] = node;
|
||||
}
|
||||
ths->elems++;
|
||||
if (ths->elems > 2 * ths->length) {
|
||||
ths->resize(ths);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int removeSimpleHash(struct SimpleHash* ths, char* key, size_t keyLen) {
|
||||
SimpleHashNode** pp = ths->find(ths, key, keyLen);
|
||||
if (*pp == NULL) {
|
||||
fprintf(stderr, "removeSimpleHash, key not exist \n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
SimpleHashNode* del = *pp;
|
||||
*pp = del->next;
|
||||
free(del->key);
|
||||
free(del->data);
|
||||
free(del);
|
||||
ths->elems--;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SimpleHashNode** findSimpleHash(struct SimpleHash* ths, char* key, size_t keyLen) {
|
||||
uint32_t hashCode = ths->hashFunc(key, keyLen);
|
||||
// size_t index = hashCode % ths->length;
|
||||
size_t index = hashCode & (ths->length - 1);
|
||||
|
||||
// printf("findSimpleHash: %s %ld %u \n", key, keyLen, hashCode);
|
||||
|
||||
SimpleHashNode** pp = &(ths->table[index]);
|
||||
while (*pp != NULL && ((*pp)->hashCode != hashCode || memcmp(key, (*pp)->key, keyLen) != 0)) {
|
||||
pp = &((*pp)->next);
|
||||
}
|
||||
|
||||
return pp;
|
||||
}
|
||||
|
||||
void printCStrSimpleHash(struct SimpleHash* ths) {
|
||||
printf("\n--- printCStrSimpleHash: elems:%d length:%d \n", ths->elems, ths->length);
|
||||
for (size_t i = 0; i < ths->length; ++i) {
|
||||
SimpleHashNode* ptr = ths->table[i];
|
||||
if (ptr != NULL) {
|
||||
printf("%zu: ", i);
|
||||
while (ptr != NULL) {
|
||||
printf("<%u, %s, %ld, %s, %ld> ", ptr->hashCode, (char*)ptr->key, ptr->keyLen, (char*)ptr->data, ptr->dataLen);
|
||||
ptr = ptr->next;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
printf("---------------\n");
|
||||
}
|
||||
|
||||
void destroySimpleHash(struct SimpleHash* ths) {
|
||||
for (size_t i = 0; i < ths->length; ++i) {
|
||||
SimpleHashNode* ptr = ths->table[i];
|
||||
while (ptr != NULL) {
|
||||
SimpleHashNode* tmp = ptr;
|
||||
ptr = ptr->next;
|
||||
free(tmp->key);
|
||||
free(tmp->data);
|
||||
free(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
ths->length = 0;
|
||||
ths->elems = 0;
|
||||
free(ths->table);
|
||||
free(ths);
|
||||
}
|
||||
|
||||
void resizeSimpleHash(struct SimpleHash* ths) {
|
||||
uint32_t new_length = ths->length;
|
||||
while (new_length < ths->elems) {
|
||||
new_length *= 2;
|
||||
}
|
||||
|
||||
printf("resizeSimpleHash: %p from %u to %u \n", ths, ths->length, new_length);
|
||||
|
||||
SimpleHashNode** new_table = malloc(new_length * sizeof(SimpleHashNode*));
|
||||
memset(new_table, 0, new_length * sizeof(SimpleHashNode*));
|
||||
|
||||
uint32_t count = 0;
|
||||
for (uint32_t i = 0; i < ths->length; i++) {
|
||||
if (ths->table[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SimpleHashNode* it = ths->table[i];
|
||||
while (it != NULL) {
|
||||
SimpleHashNode* move_node = it;
|
||||
it = it->next;
|
||||
|
||||
// move move_node
|
||||
move_node->next = NULL;
|
||||
size_t index = move_node->hashCode & (new_length - 1);
|
||||
|
||||
SimpleHashNode* ptr = new_table[index];
|
||||
if (ptr != NULL) {
|
||||
move_node->next = ptr;
|
||||
new_table[index] = move_node;
|
||||
} else {
|
||||
new_table[index] = move_node;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
assert(ths->elems == count);
|
||||
free(ths->table);
|
||||
ths->table = new_table;
|
||||
ths->length = new_length;
|
||||
}
|
||||
|
||||
uint32_t simpleHashFunc(const char* key, size_t keyLen) { return mySimpleHash(key, keyLen, 1); }
|
||||
|
||||
struct SimpleHash* newSimpleHash(size_t length) {
|
||||
struct SimpleHash* ths = malloc(sizeof(*ths));
|
||||
|
||||
ths->length = length;
|
||||
ths->elems = 0;
|
||||
ths->table = malloc(length * sizeof(SimpleHashNode*));
|
||||
memset(ths->table, 0, length * sizeof(SimpleHashNode*));
|
||||
|
||||
ths->insert = insertSimpleHash;
|
||||
ths->remove = removeSimpleHash;
|
||||
ths->find = findSimpleHash;
|
||||
ths->insert_cstr = insertCStrSimpleHash;
|
||||
ths->remove_cstr = removeCStrSimpleHash;
|
||||
ths->find_cstr = findCStrSimpleHash;
|
||||
ths->print_cstr = printCStrSimpleHash;
|
||||
ths->destroy = destroySimpleHash;
|
||||
ths->resize = resizeSimpleHash;
|
||||
ths->hashFunc = simpleHashFunc;
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
#ifndef __SIMPLE_HASH_H__
|
||||
#define __SIMPLE_HASH_H__
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
uint32_t mySimpleHash(const char* data, size_t n, uint32_t seed);
|
||||
|
||||
typedef struct SimpleHashNode {
|
||||
uint32_t hashCode;
|
||||
void* key;
|
||||
size_t keyLen;
|
||||
void* data;
|
||||
size_t dataLen;
|
||||
struct SimpleHashNode* next;
|
||||
} SimpleHashNode;
|
||||
|
||||
typedef struct SimpleHash {
|
||||
// public:
|
||||
|
||||
int (*insert)(struct SimpleHash* ths, char* key, size_t keyLen, char* data, size_t dataLen);
|
||||
int (*remove)(struct SimpleHash* ths, char* key, size_t keyLen);
|
||||
SimpleHashNode** (*find)(struct SimpleHash* ths, char* key, size_t keyLen);
|
||||
|
||||
// wrapper
|
||||
int (*insert_cstr)(struct SimpleHash* ths, char* key, char* data);
|
||||
int (*remove_cstr)(struct SimpleHash* ths, char* key);
|
||||
SimpleHashNode** (*find_cstr)(struct SimpleHash* ths, char* key);
|
||||
|
||||
void (*print_cstr)(struct SimpleHash* ths);
|
||||
void (*destroy)(struct SimpleHash* ths);
|
||||
|
||||
uint32_t length;
|
||||
uint32_t elems;
|
||||
|
||||
// private:
|
||||
void (*resize)(struct SimpleHash* ths);
|
||||
uint32_t (*hashFunc)(const char* key, size_t keyLen);
|
||||
|
||||
SimpleHashNode** table;
|
||||
|
||||
} SimpleHash;
|
||||
|
||||
int insertCStrSimpleHash(struct SimpleHash* ths, char* key, char* data);
|
||||
int removeCStrSimpleHash(struct SimpleHash* ths, char* key);
|
||||
SimpleHashNode** findCStrSimpleHash(struct SimpleHash* ths, char* key);
|
||||
void printCStrSimpleHash(struct SimpleHash* ths);
|
||||
|
||||
int insertSimpleHash(struct SimpleHash* ths, char* key, size_t keyLen, char* data, size_t dataLen);
|
||||
int removeSimpleHash(struct SimpleHash* ths, char* key, size_t keyLen);
|
||||
SimpleHashNode** findSimpleHash(struct SimpleHash* ths, char* key, size_t keyLen);
|
||||
void destroySimpleHash(struct SimpleHash* ths);
|
||||
void resizeSimpleHash(struct SimpleHash* ths);
|
||||
uint32_t simpleHashFunc(const char* key, size_t keyLen);
|
||||
|
||||
struct SimpleHash* newSimpleHash(size_t length);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,45 @@
|
|||
#include "util.h"
|
||||
#include <dirent.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int dirOK(const char *path) {
|
||||
DIR *dir = opendir(path);
|
||||
if (dir != NULL) {
|
||||
closedir(dir);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int splitString(const char *str, char *separator, char (*arr)[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, TOKEN_LEN);
|
||||
n++;
|
||||
|
||||
while (1) {
|
||||
token = strtok_r(NULL, separator, &context);
|
||||
if (!token || n >= n_arr) {
|
||||
goto ret;
|
||||
}
|
||||
strncpy(arr[n], token, TOKEN_LEN);
|
||||
n++;
|
||||
}
|
||||
|
||||
ret:
|
||||
free(tmp);
|
||||
return n;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef TRAFT_UTIL_H
|
||||
#define TRAFT_UTIL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "common.h"
|
||||
|
||||
int dirOK(const char *path);
|
||||
int splitString(const char *str, char *separator, char (*arr)[TOKEN_LEN], int n_arr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,7 @@
|
|||
add_executable(rebalanceLeader "")
|
||||
target_sources(rebalanceLeader
|
||||
PRIVATE
|
||||
"raftMain.c"
|
||||
"raftServer.c"
|
||||
)
|
||||
target_link_libraries(rebalanceLeader PUBLIC traft lz4 uv_a)
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
|
||||
rm -rf 127.0.0.1*
|
||||
rm -rf ./data
|
|
@ -60,9 +60,9 @@ void raftTransferCb(struct raft_transfer *req) {
|
|||
SRaftServer *pRaftServer = req->data;
|
||||
raft_free(req);
|
||||
|
||||
printf("raftTransferCb: \n");
|
||||
//printf("raftTransferCb: \n");
|
||||
updateLeaderStates(pRaftServer);
|
||||
printLeaderCount();
|
||||
//printLeaderCount();
|
||||
|
||||
int myLeaderCount;
|
||||
for (int i = 0; i < NODE_COUNT; ++i) {
|
||||
|
@ -71,12 +71,13 @@ void raftTransferCb(struct raft_transfer *req) {
|
|||
}
|
||||
}
|
||||
|
||||
printf("myLeaderCount:%d waterLevel:%d \n", myLeaderCount, pRaftServer->instanceCount / NODE_COUNT);
|
||||
//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;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,17 +88,25 @@ void raftTransferCb(struct raft_transfer *req) {
|
|||
int minIndex = -1;
|
||||
int minLeaderCount = myLeaderCount;
|
||||
for (int j = 0; j < NODE_COUNT; ++j) {
|
||||
if (strcmp(leaderStates[j].address, pRaftServer->address) == 0) continue;
|
||||
if (strcmp(leaderStates[j].address, pRaftServer->address) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (leaderStates[j].leaderCount <= minLeaderCount) {
|
||||
minLeaderCount = leaderStates[j].leaderCount;
|
||||
minIndex = j;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char myHost[48];
|
||||
uint16_t myPort;
|
||||
uint16_t myVid;
|
||||
decodeRaftId(r->id, myHost, sizeof(myHost), &myPort, &myVid);
|
||||
|
||||
|
||||
|
||||
//printf("raftTransferCb transfer leader: vid[%u] choose: index:%d, leaderStates[%d].address:%s, leaderStates[%d].leaderCount:%d \n", minIndex, minIndex, leaderStates[minIndex].address, minIndex, leaderStates[minIndex].leaderCount);
|
||||
|
||||
char *destAddress = leaderStates[minIndex].address;
|
||||
|
||||
char tokens[MAX_PEERS][MAX_TOKEN_LEN];
|
||||
|
@ -106,6 +115,9 @@ void raftTransferCb(struct raft_transfer *req) {
|
|||
uint16_t destPort = atoi(tokens[1]);
|
||||
destRaftId = encodeRaftId(destHost, destPort, myVid);
|
||||
|
||||
printf("\nraftTransferCb transfer leader: vgroupId:%u from:%s:%u --> to:%s:%u ", myVid, myHost, myPort, destHost, destPort);
|
||||
fflush(stdout);
|
||||
|
||||
raft_transfer(r, transfer, destRaftId, raftTransferCb);
|
||||
}
|
||||
|
||||
|
@ -252,7 +264,6 @@ const char* state2String(unsigned short state) {
|
|||
|
||||
|
||||
void printRaftState2(struct raft *r) {
|
||||
|
||||
char leaderAddress[128];
|
||||
memset(leaderAddress, 0, sizeof(leaderAddress));
|
||||
|
||||
|
@ -350,6 +361,7 @@ void console(SRaftServer *pRaftServer) {
|
|||
while (1) {
|
||||
char cmd_buf[COMMAND_LEN];
|
||||
memset(cmd_buf, 0, sizeof(cmd_buf));
|
||||
printf("(console)> ");
|
||||
char *ret = fgets(cmd_buf, COMMAND_LEN, stdin);
|
||||
if (!ret) {
|
||||
exit(-1);
|
||||
|
@ -403,7 +415,10 @@ void console(SRaftServer *pRaftServer) {
|
|||
} else if (strcmp(cmd, "dropnode") == 0) {
|
||||
printf("not support \n");
|
||||
|
||||
} else if (strcmp(cmd, "rebalance") == 0) {
|
||||
} else if (strcmp(cmd, "quit") == 0 || strcmp(cmd, "exit") == 0) {
|
||||
exit(0);
|
||||
|
||||
} else if (strcmp(cmd, "rebalance") == 0 && strcmp(param1, "leader") == 0) {
|
||||
|
||||
/*
|
||||
updateLeaderStates(pRaftServer);
|
||||
|
@ -511,10 +526,14 @@ void console(SRaftServer *pRaftServer) {
|
|||
printRaftState(&pRaftServer->instance[i].raft);
|
||||
}
|
||||
|
||||
} else if (strcmp(cmd, "state2") == 0) {
|
||||
} else if (strcmp(cmd, "leader") == 0 && strcmp(param1, "state") == 0) {
|
||||
updateLeaderStates(pRaftServer);
|
||||
printf("\n--------------------------------------------\n");
|
||||
printLeaderCount();
|
||||
for (int i = 0; i < pRaftServer->instanceCount; ++i) {
|
||||
printRaftState2(&pRaftServer->instance[i].raft);
|
||||
}
|
||||
printf("--------------------------------------------\n");
|
||||
|
||||
} else if (strcmp(cmd, "snapshot") == 0) {
|
||||
printf("not support \n");
|
|
@ -3,32 +3,34 @@
|
|||
#include "common.h"
|
||||
#include "raftServer.h"
|
||||
|
||||
char *keys;
|
||||
char *values;
|
||||
//char *keys = malloc(MAX_RECORD_COUNT * MAX_KV_LEN);;
|
||||
//char *values = malloc(MAX_RECORD_COUNT * MAX_KV_LEN);
|
||||
|
||||
|
||||
char keys[MAX_KV_LEN][MAX_RECORD_COUNT];
|
||||
char values[MAX_KV_LEN][MAX_RECORD_COUNT];
|
||||
int writeIndex = 0;
|
||||
|
||||
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);
|
||||
//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);
|
||||
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];
|
||||
if (strcmp(keys[i], key) == 0) {
|
||||
return values[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
|
@ -15,11 +15,13 @@ extern "C" {
|
|||
|
||||
|
||||
// simulate a db store, just for test
|
||||
#define MAX_KV_LEN 100
|
||||
#define MAX_RECORD_COUNT 500
|
||||
char *keys;
|
||||
char *values;
|
||||
int writeIndex;
|
||||
#define MAX_KV_LEN 20
|
||||
#define MAX_RECORD_COUNT 16
|
||||
|
||||
|
||||
//char *keys;
|
||||
//char *values;
|
||||
//int writeIndex;
|
||||
|
||||
void initStore();
|
||||
void destroyStore();
|
|
@ -13,15 +13,23 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_TVK_ROCKSDB_H_
|
||||
#define _TD_TVK_ROCKSDB_H_
|
||||
#ifndef _TD_COMMON_CFG_H_
|
||||
#define _TD_COMMON_CFG_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "tdef.h"
|
||||
|
||||
typedef struct {
|
||||
char dir[TSDB_FILENAME_LEN];
|
||||
int level;
|
||||
int primary;
|
||||
} SDiskCfg;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_TVK_ROCKSDB_H_*/
|
||||
#endif /*_TD_COMMON_CFG_H_*/
|
|
@ -31,13 +31,12 @@ extern "C" {
|
|||
memcpy(varDataVal(x), (str), __len); \
|
||||
} while (0);
|
||||
|
||||
#define STR_TO_NET_VARSTR(x, str) \
|
||||
do { \
|
||||
VarDataLenT __len = (VarDataLenT)strlen(str); \
|
||||
*(VarDataLenT *)(x) = htons(__len); \
|
||||
memcpy(varDataVal(x), (str), __len); \
|
||||
} while (0);
|
||||
|
||||
#define STR_TO_NET_VARSTR(x, str) \
|
||||
do { \
|
||||
VarDataLenT __len = (VarDataLenT)strlen(str); \
|
||||
*(VarDataLenT *)(x) = htons(__len); \
|
||||
memcpy(varDataVal(x), (str), __len); \
|
||||
} while (0);
|
||||
|
||||
#define STR_WITH_MAXSIZE_TO_VARSTR(x, str, _maxs) \
|
||||
do { \
|
||||
|
@ -71,11 +70,12 @@ typedef struct {
|
|||
|
||||
// ----------------- TSDB SCHEMA DEFINITION
|
||||
typedef struct {
|
||||
int version; // version
|
||||
int numOfCols; // Number of columns appended
|
||||
int tlen; // maximum length of a SDataRow without the header part (sizeof(VarDataOffsetT) + sizeof(VarDataLenT) + (bytes))
|
||||
uint16_t flen; // First part length in a SDataRow after the header part
|
||||
uint16_t vlen; // pure value part length, excluded the overhead (bytes only)
|
||||
int version; // version
|
||||
int numOfCols; // Number of columns appended
|
||||
int tlen; // maximum length of a SDataRow without the header part (sizeof(VarDataOffsetT) + sizeof(VarDataLenT) +
|
||||
// (bytes))
|
||||
uint16_t flen; // First part length in a SDataRow after the header part
|
||||
uint16_t vlen; // pure value part length, excluded the overhead (bytes only)
|
||||
STColumn columns[];
|
||||
} STSchema;
|
||||
|
||||
|
@ -202,7 +202,6 @@ void tdFreeDataRow(SDataRow row);
|
|||
void tdInitDataRow(SDataRow row, STSchema *pSchema);
|
||||
SDataRow tdDataRowDup(SDataRow row);
|
||||
|
||||
|
||||
// offset here not include dataRow header length
|
||||
static FORCE_INLINE int tdAppendDataColVal(SDataRow row, const void *value, bool isCopyVarData, int8_t type,
|
||||
int32_t offset) {
|
||||
|
@ -228,7 +227,6 @@ static FORCE_INLINE int tdAppendDataColVal(SDataRow row, const void *value, bool
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// offset here not include dataRow header length
|
||||
static FORCE_INLINE int tdAppendColVal(SDataRow row, const void *value, int8_t type, int32_t offset) {
|
||||
return tdAppendDataColVal(row, value, true, type, offset);
|
||||
|
@ -249,27 +247,28 @@ static FORCE_INLINE void *tdGetPtrToCol(SDataRow row, STSchema *pSchema, int idx
|
|||
|
||||
static FORCE_INLINE void *tdGetColOfRowBySchema(SDataRow row, STSchema *pSchema, int idx) {
|
||||
int16_t offset = TD_DATA_ROW_HEAD_SIZE + pSchema->columns[idx].offset;
|
||||
int8_t type = pSchema->columns[idx].type;
|
||||
int8_t type = pSchema->columns[idx].type;
|
||||
|
||||
return tdGetRowDataOfCol(row, type, offset);
|
||||
}
|
||||
|
||||
static FORCE_INLINE bool tdIsColOfRowNullBySchema(SDataRow row, STSchema *pSchema, int idx) {
|
||||
int16_t offset = TD_DATA_ROW_HEAD_SIZE + pSchema->columns[idx].offset;
|
||||
int8_t type = pSchema->columns[idx].type;
|
||||
int8_t type = pSchema->columns[idx].type;
|
||||
|
||||
return isNull(tdGetRowDataOfCol(row, type, offset), type);
|
||||
}
|
||||
|
||||
static FORCE_INLINE void tdSetColOfRowNullBySchema(SDataRow row, STSchema *pSchema, int idx) {
|
||||
int16_t offset = TD_DATA_ROW_HEAD_SIZE + pSchema->columns[idx].offset;
|
||||
int8_t type = pSchema->columns[idx].type;
|
||||
int8_t type = pSchema->columns[idx].type;
|
||||
int16_t bytes = pSchema->columns[idx].bytes;
|
||||
|
||||
setNull(tdGetRowDataOfCol(row, type, offset), type, bytes);
|
||||
}
|
||||
|
||||
static FORCE_INLINE void tdCopyColOfRowBySchema(SDataRow dst, STSchema *pDstSchema, int dstIdx, SDataRow src, STSchema *pSrcSchema, int srcIdx) {
|
||||
static FORCE_INLINE void tdCopyColOfRowBySchema(SDataRow dst, STSchema *pDstSchema, int dstIdx, SDataRow src,
|
||||
STSchema *pSrcSchema, int srcIdx) {
|
||||
int8_t type = pDstSchema->columns[dstIdx].type;
|
||||
assert(type == pSrcSchema->columns[srcIdx].type);
|
||||
void *pData = tdGetPtrToCol(dst, pDstSchema, dstIdx);
|
||||
|
@ -319,7 +318,6 @@ static FORCE_INLINE void tdCopyColOfRowBySchema(SDataRow dst, STSchema *pDstSche
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// ----------------- Data column structure
|
||||
typedef struct SDataCol {
|
||||
int8_t type; // column type
|
||||
|
@ -339,7 +337,7 @@ static FORCE_INLINE void dataColReset(SDataCol *pDataCol) { pDataCol->len = 0; }
|
|||
int tdAllocMemForCol(SDataCol *pCol, int maxPoints);
|
||||
|
||||
void dataColInit(SDataCol *pDataCol, STColumn *pCol, int maxPoints);
|
||||
int dataColAppendVal(SDataCol *pCol, const void *value, int numOfRows, int maxPoints);
|
||||
int dataColAppendVal(SDataCol *pCol, const void *value, int numOfRows, int maxPoints);
|
||||
void dataColSetOffset(SDataCol *pCol, int nEle);
|
||||
|
||||
bool isNEleNull(SDataCol *pCol, int nEle);
|
||||
|
@ -367,15 +365,15 @@ static FORCE_INLINE int32_t dataColGetNEleLen(SDataCol *pDataCol, int rows) {
|
|||
}
|
||||
|
||||
typedef struct {
|
||||
int maxCols; // max number of columns
|
||||
int maxPoints; // max number of points
|
||||
int numOfRows;
|
||||
int numOfCols; // Total number of cols
|
||||
int sversion; // TODO: set sversion
|
||||
int maxCols; // max number of columns
|
||||
int maxPoints; // max number of points
|
||||
int numOfRows;
|
||||
int numOfCols; // Total number of cols
|
||||
int sversion; // TODO: set sversion
|
||||
SDataCol *cols;
|
||||
} SDataCols;
|
||||
|
||||
#define keyCol(pCols) (&((pCols)->cols[0])) // Key column
|
||||
#define keyCol(pCols) (&((pCols)->cols[0])) // Key column
|
||||
#define dataColsTKeyAt(pCols, idx) ((TKEY *)(keyCol(pCols)->pData))[(idx)] // the idx row of column-wised data
|
||||
#define dataColsKeyAt(pCols, idx) tdGetKey(dataColsTKeyAt(pCols, idx))
|
||||
static FORCE_INLINE TKEY dataColsTKeyFirst(SDataCols *pCols) {
|
||||
|
@ -454,6 +452,7 @@ typedef struct {
|
|||
#define kvRowValLen(r) (kvRowLen(r) - TD_KV_ROW_HEAD_SIZE - sizeof(SColIdx) * kvRowNCols(r))
|
||||
#define kvRowTKey(r) (*(TKEY *)(kvRowValues(r)))
|
||||
#define kvRowKey(r) tdGetKey(kvRowTKey(r))
|
||||
#define kvRowKeys(r) POINTER_SHIFT(r, *(uint16_t *)POINTER_SHIFT(r, TD_KV_ROW_HEAD_SIZE + sizeof(int16_t)))
|
||||
#define kvRowDeleted(r) TKEY_IS_DELETED(kvRowTKey(r))
|
||||
|
||||
SKVRow tdKVRowDup(SKVRow row);
|
||||
|
@ -547,7 +546,7 @@ SKVRow tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder);
|
|||
static FORCE_INLINE int tdAddColToKVRow(SKVRowBuilder *pBuilder, int16_t colId, int8_t type, const void *value) {
|
||||
if (pBuilder->nCols >= pBuilder->tCols) {
|
||||
pBuilder->tCols *= 2;
|
||||
SColIdx* pColIdx = (SColIdx *)realloc((void *)(pBuilder->pColIdx), sizeof(SColIdx) * pBuilder->tCols);
|
||||
SColIdx *pColIdx = (SColIdx *)realloc((void *)(pBuilder->pColIdx), sizeof(SColIdx) * pBuilder->tCols);
|
||||
if (pColIdx == NULL) return -1;
|
||||
pBuilder->pColIdx = pColIdx;
|
||||
}
|
||||
|
@ -562,7 +561,7 @@ static FORCE_INLINE int tdAddColToKVRow(SKVRowBuilder *pBuilder, int16_t colId,
|
|||
while (tlen > pBuilder->alloc - pBuilder->size) {
|
||||
pBuilder->alloc *= 2;
|
||||
}
|
||||
void* buf = realloc(pBuilder->buf, pBuilder->alloc);
|
||||
void *buf = realloc(pBuilder->buf, pBuilder->alloc);
|
||||
if (buf == NULL) return -1;
|
||||
pBuilder->buf = buf;
|
||||
}
|
||||
|
@ -654,6 +653,7 @@ static FORCE_INLINE char *memRowEnd(SMemRow row) {
|
|||
|
||||
#define memRowTKey(r) (isDataRow(r) ? dataRowTKey(memRowDataBody(r)) : kvRowTKey(memRowKvBody(r)))
|
||||
#define memRowKey(r) (isDataRow(r) ? dataRowKey(memRowDataBody(r)) : kvRowKey(memRowKvBody(r)))
|
||||
#define memRowKeys(r) (isDataRow(r) ? dataRowTuple(memRowDataBody(r)) : kvRowKeys(memRowKvBody(r)))
|
||||
#define memRowSetTKey(r, k) \
|
||||
do { \
|
||||
if (isDataRow(r)) { \
|
||||
|
@ -750,10 +750,10 @@ static FORCE_INLINE void tdGetColAppendDeltaLen(const void *value, int8_t colTyp
|
|||
typedef struct {
|
||||
int16_t colId;
|
||||
uint8_t colType;
|
||||
char* colVal;
|
||||
char * colVal;
|
||||
} SColInfo;
|
||||
|
||||
static FORCE_INLINE void setSColInfo(SColInfo* colInfo, int16_t colId, uint8_t colType, char* colVal) {
|
||||
static FORCE_INLINE void setSColInfo(SColInfo *colInfo, int16_t colId, uint8_t colType, char *colVal) {
|
||||
colInfo->colId = colId;
|
||||
colInfo->colType = colType;
|
||||
colInfo->colVal = colVal;
|
||||
|
@ -813,4 +813,4 @@ static FORCE_INLINE char *payloadNextCol(char *pCol) { return (char *)POINTER_SH
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_COMMON_DATA_FORMAT_H_*/
|
||||
#endif /*_TD_COMMON_DATA_FORMAT_H_*/
|
||||
|
|
|
@ -21,6 +21,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "tdef.h"
|
||||
#include "tcfg.h"
|
||||
|
||||
// cluster
|
||||
extern char tsFirst[];
|
||||
|
@ -105,11 +106,6 @@ extern uint32_t tsMaxRange;
|
|||
extern uint32_t tsCurRange;
|
||||
extern char tsCompressor[];
|
||||
|
||||
typedef struct {
|
||||
char dir[TSDB_FILENAME_LEN];
|
||||
int level;
|
||||
int primary;
|
||||
} SDiskCfg;
|
||||
extern int32_t tsDiskCfgNum;
|
||||
extern SDiskCfg tsDiskCfg[];
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -159,6 +159,7 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_VND_MQ_QUERY, "vnode-mq-query", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_MQ_CONNECT, "vnode-mq-connect", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_MQ_DISCONNECT, "vnode-mq-disconnect", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_MQ_SET_CONN, "vnode-mq-set-conn", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_MQ_SET_CUR, "vnode-mq-set-cur", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_RES_READY, "vnode-res-ready", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_TASKS_STATUS, "vnode-tasks-status", NULL, NULL)
|
||||
|
|
|
@ -23,9 +23,9 @@ extern "C" {
|
|||
/* ------------------------ TYPES EXPOSED ------------------------ */
|
||||
typedef struct SDnode SDnode;
|
||||
typedef struct SBnode SBnode;
|
||||
typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
|
||||
typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
|
||||
typedef struct {
|
||||
int64_t numOfErrors;
|
||||
|
@ -40,9 +40,9 @@ typedef struct {
|
|||
int64_t clusterId;
|
||||
SBnodeCfg cfg;
|
||||
SDnode *pDnode;
|
||||
SendMsgToDnodeFp sendMsgToDnodeFp;
|
||||
SendMsgToMnodeFp sendMsgToMnodeFp;
|
||||
SendRedirectMsgFp sendRedirectMsgFp;
|
||||
SendReqToDnodeFp sendReqToDnodeFp;
|
||||
SendReqToMnodeFp sendReqToMnodeFp;
|
||||
SendRedirectRspFp sendRedirectRspFp;
|
||||
} SBnodeOpt;
|
||||
|
||||
/* ------------------------ SBnode ------------------------ */
|
||||
|
|
|
@ -24,9 +24,10 @@ extern "C" {
|
|||
typedef struct SDnode SDnode;
|
||||
typedef struct SMnode SMnode;
|
||||
typedef struct SMnodeMsg SMnodeMsg;
|
||||
typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
|
||||
typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef int32_t (*PutReqToMWriteQFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
|
||||
typedef struct SMnodeLoad {
|
||||
int64_t numOfDnode;
|
||||
|
@ -62,9 +63,10 @@ typedef struct {
|
|||
SReplica replicas[TSDB_MAX_REPLICA];
|
||||
SMnodeCfg cfg;
|
||||
SDnode *pDnode;
|
||||
SendMsgToDnodeFp sendMsgToDnodeFp;
|
||||
SendMsgToMnodeFp sendMsgToMnodeFp;
|
||||
SendRedirectMsgFp sendRedirectMsgFp;
|
||||
PutReqToMWriteQFp putReqToMWriteQFp;
|
||||
SendReqToDnodeFp sendReqToDnodeFp;
|
||||
SendReqToMnodeFp sendReqToMnodeFp;
|
||||
SendRedirectRspFp sendRedirectRspFp;
|
||||
} SMnodeOpt;
|
||||
|
||||
/* ------------------------ SMnode ------------------------ */
|
||||
|
|
|
@ -94,6 +94,7 @@ typedef struct SSdbRaw SSdbRaw;
|
|||
typedef struct SSdbRow SSdbRow;
|
||||
typedef enum { SDB_KEY_BINARY = 1, SDB_KEY_INT32 = 2, SDB_KEY_INT64 = 3 } EKeyType;
|
||||
typedef enum {
|
||||
SDB_STATUS_INIT = 0,
|
||||
SDB_STATUS_CREATING = 1,
|
||||
SDB_STATUS_UPDATING = 2,
|
||||
SDB_STATUS_DROPPING = 3,
|
||||
|
@ -280,6 +281,15 @@ int32_t sdbGetSize(SSdb *pSdb, ESdbType type);
|
|||
*/
|
||||
int32_t sdbGetMaxId(SSdb *pSdb, ESdbType type);
|
||||
|
||||
/**
|
||||
* @brief Get the version of the table
|
||||
*
|
||||
* @param pSdb The sdb object.
|
||||
* @param pIter The type of the table.
|
||||
* @return int32_t The version of the table
|
||||
*/
|
||||
int64_t sdbGetTableVer(SSdb *pSdb, ESdbType type);
|
||||
|
||||
/**
|
||||
* @brief Update the version of sdb
|
||||
*
|
||||
|
|
|
@ -23,9 +23,9 @@ extern "C" {
|
|||
/* ------------------------ TYPES EXPOSED ------------------------ */
|
||||
typedef struct SDnode SDnode;
|
||||
typedef struct SQnode SQnode;
|
||||
typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
|
||||
typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
|
||||
typedef struct {
|
||||
int64_t numOfStartTask;
|
||||
|
@ -47,9 +47,9 @@ typedef struct {
|
|||
int64_t clusterId;
|
||||
SQnodeCfg cfg;
|
||||
SDnode *pDnode;
|
||||
SendMsgToDnodeFp sendMsgToDnodeFp;
|
||||
SendMsgToMnodeFp sendMsgToMnodeFp;
|
||||
SendRedirectMsgFp sendRedirectMsgFp;
|
||||
SendReqToDnodeFp sendReqToDnodeFp;
|
||||
SendReqToMnodeFp sendReqToMnodeFp;
|
||||
SendRedirectRspFp sendRedirectRspFp;
|
||||
} SQnodeOpt;
|
||||
|
||||
/* ------------------------ SQnode ------------------------ */
|
||||
|
|
|
@ -23,9 +23,9 @@ extern "C" {
|
|||
/* ------------------------ TYPES EXPOSED ------------------------ */
|
||||
typedef struct SDnode SDnode;
|
||||
typedef struct SSnode SSnode;
|
||||
typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
|
||||
typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
|
||||
typedef struct {
|
||||
int64_t numOfErrors;
|
||||
|
@ -40,9 +40,9 @@ typedef struct {
|
|||
int64_t clusterId;
|
||||
SSnodeCfg cfg;
|
||||
SDnode *pDnode;
|
||||
SendMsgToDnodeFp sendMsgToDnodeFp;
|
||||
SendMsgToMnodeFp sendMsgToMnodeFp;
|
||||
SendRedirectMsgFp sendRedirectMsgFp;
|
||||
SendReqToDnodeFp sendReqToDnodeFp;
|
||||
SendReqToMnodeFp sendReqToMnodeFp;
|
||||
SendRedirectRspFp sendRedirectRspFp;
|
||||
} SSnodeOpt;
|
||||
|
||||
/* ------------------------ SSnode ------------------------ */
|
||||
|
|
|
@ -58,6 +58,7 @@ int metaCommit(SMeta *pMeta);
|
|||
STbCfg * metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid);
|
||||
STbCfg * metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid);
|
||||
SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline);
|
||||
STSchema * metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver);
|
||||
|
||||
SMTbCursor *metaOpenTbCursor(SMeta *pMeta);
|
||||
void metaCloseTbCursor(SMTbCursor *pTbCur);
|
||||
|
|
|
@ -17,26 +17,52 @@
|
|||
#define _TD_TSDB_H_
|
||||
|
||||
#include "mallocator.h"
|
||||
#include "meta.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SDataStatis {
|
||||
int16_t colId;
|
||||
int64_t sum;
|
||||
int64_t max;
|
||||
int64_t min;
|
||||
int16_t maxIndex;
|
||||
int16_t minIndex;
|
||||
int16_t numOfNull;
|
||||
} SDataStatis;
|
||||
|
||||
typedef struct STable {
|
||||
uint64_t tid;
|
||||
uint64_t uid;
|
||||
STSchema *pSchema;
|
||||
} STable;
|
||||
|
||||
#define TABLE_TID(t) (t)->tid
|
||||
#define TABLE_UID(t) (t)->uid
|
||||
|
||||
// TYPES EXPOSED
|
||||
typedef struct STsdb STsdb;
|
||||
|
||||
typedef struct STsdbCfg {
|
||||
int8_t precision;
|
||||
uint64_t lruCacheSize;
|
||||
uint32_t keep0;
|
||||
uint32_t keep1;
|
||||
uint32_t keep2;
|
||||
int32_t daysPerFile;
|
||||
int32_t minRowsPerFileBlock;
|
||||
int32_t maxRowsPerFileBlock;
|
||||
int32_t keep;
|
||||
int32_t keep1;
|
||||
int32_t keep2;
|
||||
int8_t update;
|
||||
int8_t compression;
|
||||
} STsdbCfg;
|
||||
|
||||
// STsdb
|
||||
STsdb *tsdbOpen(const char *path, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF);
|
||||
STsdb *tsdbOpen(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF, SMeta *pMeta);
|
||||
void tsdbClose(STsdb *);
|
||||
void tsdbRemove(const char *path);
|
||||
int tsdbInsertData(STsdb *pTsdb, SSubmitMsg *pMsg);
|
||||
int tsdbInsertData(STsdb *pTsdb, SSubmitMsg *pMsg, SSubmitRsp *pRsp);
|
||||
int tsdbPrepareCommit(STsdb *pTsdb);
|
||||
int tsdbCommit(STsdb *pTsdb);
|
||||
|
||||
|
|
|
@ -32,6 +32,8 @@ extern "C" {
|
|||
/* ------------------------ TYPES EXPOSED ------------------------ */
|
||||
typedef struct SVnode SVnode;
|
||||
typedef struct SVnodeCfg {
|
||||
int32_t vgId;
|
||||
|
||||
/** vnode buffer pool options */
|
||||
struct {
|
||||
/** write buffer size */
|
||||
|
@ -87,7 +89,7 @@ void vnodeClear();
|
|||
* @param pVnodeCfg options of the vnode
|
||||
* @return SVnode* The vnode object
|
||||
*/
|
||||
SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg);
|
||||
SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg, int32_t vid);
|
||||
|
||||
/**
|
||||
* @brief Close a VNODE
|
||||
|
|
|
@ -48,8 +48,22 @@ typedef struct SMetaData {
|
|||
typedef struct SCatalogCfg {
|
||||
uint32_t maxTblCacheNum;
|
||||
uint32_t maxDBCacheNum;
|
||||
uint32_t dbRentSec;
|
||||
uint32_t stableRentSec;
|
||||
} SCatalogCfg;
|
||||
|
||||
typedef struct SSTableMetaVersion {
|
||||
uint64_t suid;
|
||||
int16_t sversion;
|
||||
int16_t tversion;
|
||||
} SSTableMetaVersion;
|
||||
|
||||
typedef struct SDbVgVersion {
|
||||
int64_t dbId;
|
||||
int32_t vgVersion;
|
||||
} SDbVgVersion;
|
||||
|
||||
|
||||
int32_t catalogInit(SCatalogCfg *cfg);
|
||||
|
||||
/**
|
||||
|
@ -60,19 +74,27 @@ int32_t catalogInit(SCatalogCfg *cfg);
|
|||
*/
|
||||
int32_t catalogGetHandle(uint64_t clusterId, struct SCatalog** catalogHandle);
|
||||
|
||||
/**
|
||||
* Free a cluster's all catalog info, usually it's not necessary, until the application is closing.
|
||||
* no current or future usage should be guaranteed by application
|
||||
* @param pCatalog (input, NO more usage)
|
||||
* @return error code
|
||||
*/
|
||||
void catalogFreeHandle(struct SCatalog* pCatalog);
|
||||
|
||||
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 pTransporter (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 catalogGetDBVgroup(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const char* pDBName, bool forceUpdate, SArray** pVgroupList);
|
||||
|
||||
int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDBVgroupInfo* dbInfo);
|
||||
|
||||
|
@ -87,15 +109,28 @@ int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDB
|
|||
*/
|
||||
int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta);
|
||||
|
||||
/**
|
||||
* Get a super table's meta data.
|
||||
* @param pCatalog (input, got with catalogGetHandle)
|
||||
* @param pTransporter (input, rpc object)
|
||||
* @param pMgmtEps (input, mnode EPs)
|
||||
* @param pTableName (input, table name, NOT including db name)
|
||||
* @param pTableMeta(output, table meta data, NEED to free it by calller)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogGetSTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta);
|
||||
|
||||
|
||||
/**
|
||||
* Force renew a table's local cached meta data.
|
||||
* @param pCatalog (input, got with catalogGetHandle)
|
||||
* @param pTransporter (input, rpc object)
|
||||
* @param pMgmtEps (input, mnode EPs)
|
||||
* @param pTableName (input, table name, NOT including db name)
|
||||
* @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName);
|
||||
int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, int32_t isSTable);
|
||||
|
||||
/**
|
||||
* Force renew a table's local cached meta data and get the new one.
|
||||
|
@ -104,21 +139,23 @@ int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void * pTransporter, co
|
|||
* @param pMgmtEps (input, mnode EPs)
|
||||
* @param pTableName (input, table name, NOT including db name)
|
||||
* @param pTableMeta(output, table meta data, NEED to free it by calller)
|
||||
* @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta);
|
||||
int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta, int32_t isSTable);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get a table's actual vgroup, for stable it's all possible vgroup list.
|
||||
* @param pCatalog (input, got with catalogGetHandle)
|
||||
* @param pRpc (input, rpc object)
|
||||
* @param pTransporter (input, rpc object)
|
||||
* @param pMgmtEps (input, mnode EPs)
|
||||
* @param pTableName (input, table name, NOT including db name)
|
||||
* @param pVgroupList (output, vgroup info list, element is SVgroupInfo, NEED to simply free the array by caller)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgroupList);
|
||||
int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgroupList);
|
||||
|
||||
/**
|
||||
* Get a table's vgroup from its name's hash value.
|
||||
|
@ -135,17 +172,20 @@ int32_t catalogGetTableHashVgroup(struct SCatalog* pCatalog, void * pTransporter
|
|||
/**
|
||||
* Get all meta data required in pReq.
|
||||
* @param pCatalog (input, got with catalogGetHandle)
|
||||
* @param pRpc (input, rpc object)
|
||||
* @param pTransporter (input, rpc object)
|
||||
* @param pMgmtEps (input, mnode EPs)
|
||||
* @param pReq (input, reqest info)
|
||||
* @param pRsp (output, response data)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogGetAllMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SCatalogReq* pReq, SMetaData* pRsp);
|
||||
int32_t catalogGetAllMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SCatalogReq* pReq, SMetaData* pRsp);
|
||||
|
||||
|
||||
int32_t catalogGetQnodeList(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, SArray* pQnodeList);
|
||||
int32_t catalogGetQnodeList(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, SArray* pQnodeList);
|
||||
|
||||
int32_t catalogGetExpiredSTables(struct SCatalog* pCatalog, SSTableMetaVersion **stables, uint32_t *num);
|
||||
|
||||
int32_t catalogGetExpiredDBs(struct SCatalog* pCatalog, SDbVgVersion **dbs, uint32_t *num);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,16 +20,16 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void* qinfo_t;
|
||||
typedef void* qTaskInfo_t;
|
||||
|
||||
/**
|
||||
* create the qinfo object according to QueryTableMsg
|
||||
* @param tsdb
|
||||
* @param pQueryTableMsg
|
||||
* @param qinfo
|
||||
* @param pTaskInfo
|
||||
* @return
|
||||
*/
|
||||
int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableInfo* pQueryTableMsg, qinfo_t* qinfo, uint64_t qId);
|
||||
int32_t qCreateTask(void* tsdb, int32_t vgId, void* pQueryTableMsg, qTaskInfo_t* pTaskInfo, uint64_t qId);
|
||||
|
||||
/**
|
||||
* the main query execution function, including query on both table and multiple tables,
|
||||
|
@ -38,7 +38,7 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableInfo* pQueryTableM
|
|||
* @param qinfo
|
||||
* @return
|
||||
*/
|
||||
bool qTableQuery(qinfo_t qinfo, uint64_t *qId);
|
||||
bool qExecTask(qTaskInfo_t qinfo, uint64_t *qId);
|
||||
|
||||
/**
|
||||
* Retrieve the produced results information, if current query is not paused or completed,
|
||||
|
@ -48,7 +48,7 @@ bool qTableQuery(qinfo_t qinfo, uint64_t *qId);
|
|||
* @param qinfo
|
||||
* @return
|
||||
*/
|
||||
int32_t qRetrieveQueryResultInfo(qinfo_t qinfo, bool* buildRes, void* pRspContext);
|
||||
int32_t qRetrieveQueryResultInfo(qTaskInfo_t qinfo, bool* buildRes, void* pRspContext);
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -60,41 +60,41 @@ int32_t qRetrieveQueryResultInfo(qinfo_t qinfo, bool* buildRes, void* pRspContex
|
|||
* @param contLen payload length
|
||||
* @return
|
||||
*/
|
||||
int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp** pRsp, int32_t* contLen, bool* continueExec);
|
||||
int32_t qDumpRetrieveResult(qTaskInfo_t qinfo, SRetrieveTableRsp** pRsp, int32_t* contLen, bool* continueExec);
|
||||
|
||||
/**
|
||||
* return the transporter context (RPC)
|
||||
* @param qinfo
|
||||
* @return
|
||||
*/
|
||||
void* qGetResultRetrieveMsg(qinfo_t qinfo);
|
||||
void* qGetResultRetrieveMsg(qTaskInfo_t qinfo);
|
||||
|
||||
/**
|
||||
* kill the ongoing query and free the query handle and corresponding resources automatically
|
||||
* @param qinfo qhandle
|
||||
* @return
|
||||
*/
|
||||
int32_t qKillQuery(qinfo_t qinfo);
|
||||
int32_t qKillTask(qTaskInfo_t qinfo);
|
||||
|
||||
/**
|
||||
* return whether query is completed or not
|
||||
* @param qinfo
|
||||
* @return
|
||||
*/
|
||||
int32_t qIsQueryCompleted(qinfo_t qinfo);
|
||||
int32_t qIsQueryCompleted(qTaskInfo_t qinfo);
|
||||
|
||||
/**
|
||||
* destroy query info structure
|
||||
* @param qHandle
|
||||
*/
|
||||
void qDestroyQueryInfo(qinfo_t qHandle);
|
||||
void qDestroyTask(qTaskInfo_t qHandle);
|
||||
|
||||
/**
|
||||
* Get the queried table uid
|
||||
* @param qHandle
|
||||
* @return
|
||||
*/
|
||||
int64_t qGetQueriedTableUid(qinfo_t qHandle);
|
||||
int64_t qGetQueriedTableUid(qTaskInfo_t qHandle);
|
||||
|
||||
/**
|
||||
* Extract the qualified table id list, and than pass them to the TSDB driver to load the required table data blocks.
|
||||
|
@ -121,7 +121,7 @@ int32_t qCreateTableGroupByGroupExpr(SArray* pTableIdList, TSKEY skey, STableGro
|
|||
* @param type operation type: ADD|DROP
|
||||
* @return
|
||||
*/
|
||||
int32_t qUpdateQueriedTableIdList(qinfo_t qinfo, int64_t uid, int32_t type);
|
||||
int32_t qUpdateQueriedTableIdList(qTaskInfo_t qinfo, int64_t uid, int32_t type);
|
||||
|
||||
//================================================================================================
|
||||
// query handle management
|
||||
|
@ -130,13 +130,13 @@ int32_t qUpdateQueriedTableIdList(qinfo_t qinfo, int64_t uid, int32_t type);
|
|||
* @param vgId
|
||||
* @return
|
||||
*/
|
||||
void* qOpenQueryMgmt(int32_t vgId);
|
||||
void* qOpenTaskMgmt(int32_t vgId);
|
||||
|
||||
/**
|
||||
* broadcast the close information and wait for all query stop.
|
||||
* @param pExecutor
|
||||
*/
|
||||
void qQueryMgmtNotifyClosed(void* pExecutor);
|
||||
void qTaskMgmtNotifyClosing(void* pExecutor);
|
||||
|
||||
/**
|
||||
* Re-open the query handle management module when opening the vnode again.
|
||||
|
@ -148,7 +148,7 @@ void qQueryMgmtReOpen(void *pExecutor);
|
|||
* Close query mgmt and clean up resources.
|
||||
* @param pExecutor
|
||||
*/
|
||||
void qCleanupQueryMgmt(void* pExecutor);
|
||||
void qCleanupTaskMgmt(void* pExecutor);
|
||||
|
||||
/**
|
||||
* Add the query into the query mgmt object
|
||||
|
@ -157,7 +157,7 @@ void qCleanupQueryMgmt(void* pExecutor);
|
|||
* @param qInfo
|
||||
* @return
|
||||
*/
|
||||
void** qRegisterQInfo(void* pMgmt, uint64_t qId, void *qInfo);
|
||||
void** qRegisterTask(void* pMgmt, uint64_t qId, void *qInfo);
|
||||
|
||||
/**
|
||||
* acquire the query handle according to the key from query mgmt object.
|
||||
|
@ -165,7 +165,7 @@ void** qRegisterQInfo(void* pMgmt, uint64_t qId, void *qInfo);
|
|||
* @param key
|
||||
* @return
|
||||
*/
|
||||
void** qAcquireQInfo(void* pMgmt, uint64_t key);
|
||||
void** qAcquireTask(void* pMgmt, uint64_t key);
|
||||
|
||||
/**
|
||||
* release the query handle and decrease the reference count in cache
|
||||
|
@ -174,7 +174,7 @@ void** qAcquireQInfo(void* pMgmt, uint64_t key);
|
|||
* @param freeHandle
|
||||
* @return
|
||||
*/
|
||||
void** qReleaseQInfo(void* pMgmt, void* pQInfo);
|
||||
void** qReleaseTask(void* pMgmt, void* pQInfo, bool freeHandle);
|
||||
|
||||
/**
|
||||
* De-register the query handle from the management module and free it immediately.
|
||||
|
|
|
@ -89,7 +89,7 @@ enum {
|
|||
};
|
||||
|
||||
enum {
|
||||
MASTER_SCAN = 0x0u,
|
||||
MAIN_SCAN = 0x0u,
|
||||
REVERSE_SCAN = 0x1u,
|
||||
REPEAT_SCAN = 0x2u, //repeat scan belongs to the master scan
|
||||
MERGE_STAGE = 0x20u,
|
||||
|
@ -183,7 +183,6 @@ typedef struct tExprNode {
|
|||
|
||||
struct {// function node
|
||||
char functionName[FUNCTIONS_NAME_MAX_LENGTH];
|
||||
// int32_t functionId;
|
||||
int32_t num;
|
||||
|
||||
// Note that the attribute of pChild is not the parameter of function, it is the columns that involved in the
|
||||
|
|
|
@ -135,9 +135,8 @@ typedef struct SQueryStmtInfo {
|
|||
SArray *pUdfInfo;
|
||||
|
||||
struct SQueryStmtInfo *sibling; // sibling
|
||||
struct SQueryStmtInfo *pDownstream;
|
||||
SMultiFunctionsDesc info;
|
||||
SArray *pUpstream; // SArray<struct SQueryStmtInfo>
|
||||
SArray *pDownstream; // SArray<struct SQueryStmtInfo>
|
||||
int32_t havingFieldNum;
|
||||
int32_t exprListLevelIndex;
|
||||
} SQueryStmtInfo;
|
||||
|
|
|
@ -24,7 +24,6 @@ extern "C" {
|
|||
|
||||
typedef struct SParseContext {
|
||||
SParseBasicCtx ctx;
|
||||
int8_t schemaAttached; // denote if submit block is built with table schema or not
|
||||
const char *pSql; // sql string
|
||||
size_t sqlLen; // length of the sql string
|
||||
char *pMsg; // extended error message if exists to help identifying the problem in sql statement.
|
||||
|
@ -41,9 +40,18 @@ typedef struct SParseContext {
|
|||
*/
|
||||
int32_t qParseQuerySql(SParseContext* pContext, SQueryNode** pQuery);
|
||||
|
||||
bool qIsDdlQuery(const SQueryNode* pQuery);
|
||||
/**
|
||||
* Return true if it is a ddl/dcl sql statement
|
||||
* @param pQuery
|
||||
* @return
|
||||
*/
|
||||
bool qIsDdlQuery(const SQueryNode* pQueryNode);
|
||||
|
||||
void qDestroyQuery(SQueryNode* pQuery);
|
||||
/**
|
||||
* Destroy logic query plan
|
||||
* @param pQueryNode
|
||||
*/
|
||||
void qDestroyQuery(SQueryNode* pQueryNode);
|
||||
|
||||
/**
|
||||
* Convert a normal sql statement to only query tags information to enable that the subscribe client can be aware quickly of the true vgroup ids that
|
||||
|
@ -62,8 +70,8 @@ void columnListDestroy(SArray* pColumnList);
|
|||
void dropAllExprInfo(SArray** pExprInfo, int32_t numOfLevel);
|
||||
|
||||
typedef struct SSourceParam {
|
||||
SArray *pExprNodeList; //Array<struct tExprNode*>
|
||||
SArray *pColumnList; //Array<struct SColumn>
|
||||
SArray *pExprNodeList; //Array<struct tExprNode*>
|
||||
SArray *pColumnList; //Array<struct SColumn>
|
||||
int32_t num;
|
||||
} SSourceParam;
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ extern "C" {
|
|||
#include "query.h"
|
||||
#include "tmsg.h"
|
||||
#include "tarray.h"
|
||||
#include "trpc.h"
|
||||
|
||||
#define QUERY_TYPE_MERGE 1
|
||||
#define QUERY_TYPE_PARTIAL 2
|
||||
|
@ -50,8 +51,10 @@ struct SQueryStmtInfo;
|
|||
typedef SSchema SSlotSchema;
|
||||
|
||||
typedef struct SDataBlockSchema {
|
||||
SSlotSchema *pSchema;
|
||||
int32_t numOfCols; // number of columns
|
||||
SSlotSchema *pSchema;
|
||||
int32_t numOfCols; // number of columns
|
||||
int32_t resultRowSize;
|
||||
int16_t precision;
|
||||
} SDataBlockSchema;
|
||||
|
||||
typedef struct SQueryNodeBasicInfo {
|
||||
|
@ -61,6 +64,7 @@ typedef struct SQueryNodeBasicInfo {
|
|||
|
||||
typedef struct SDataSink {
|
||||
SQueryNodeBasicInfo info;
|
||||
SDataBlockSchema schema;
|
||||
} SDataSink;
|
||||
|
||||
typedef struct SDataDispatcher {
|
||||
|
@ -110,7 +114,7 @@ typedef struct SProjectPhyNode {
|
|||
typedef struct SExchangePhyNode {
|
||||
SPhyNode node;
|
||||
uint64_t srcTemplateId; // template id of datasource suplans
|
||||
SArray *pSrcEndPoints; // SEpAddrMsg, scheduler fill by calling qSetSuplanExecutionNode
|
||||
SArray *pSrcEndPoints; // SEpAddr, scheduler fill by calling qSetSuplanExecutionNode
|
||||
} SExchangePhyNode;
|
||||
|
||||
typedef struct SSubplanId {
|
||||
|
@ -139,16 +143,20 @@ typedef struct SQueryDag {
|
|||
|
||||
struct SQueryNode;
|
||||
|
||||
/**
|
||||
* Create the physical plan for the query, according to the AST.
|
||||
*/
|
||||
/**
|
||||
* Create the physical plan for the query, according to the AST.
|
||||
* @param pQueryInfo
|
||||
* @param pDag
|
||||
* @param requestId
|
||||
* @return
|
||||
*/
|
||||
int32_t qCreateQueryDag(const struct SQueryNode* pQueryInfo, struct SQueryDag** pDag, uint64_t requestId);
|
||||
|
||||
// Set datasource of this subplan, multiple calls may be made to a subplan.
|
||||
// @subplan subplan to be schedule
|
||||
// @templateId templateId of a group of datasource subplans of this @subplan
|
||||
// @ep one execution location of this group of datasource subplans
|
||||
int32_t qSetSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SQueryNodeAddr* ep);
|
||||
void qSetSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SQueryNodeAddr* ep);
|
||||
|
||||
int32_t qExplainQuery(const struct SQueryNode* pQueryInfo, struct SEpSet* pQnode, char** str);
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ enum {
|
|||
JOB_TASK_STATUS_CANCELLING,
|
||||
JOB_TASK_STATUS_CANCELLED,
|
||||
JOB_TASK_STATUS_DROPPING,
|
||||
JOB_TASK_STATUS_FREEING,
|
||||
};
|
||||
|
||||
typedef struct STableComInfo {
|
||||
|
@ -76,6 +77,7 @@ typedef struct STableMeta {
|
|||
|
||||
typedef struct SDBVgroupInfo {
|
||||
SRWLatch lock;
|
||||
int64_t dbId;
|
||||
int32_t vgVersion;
|
||||
int8_t hashMethod;
|
||||
SHashObj *vgInfo; //key:vgId, value:SVgroupInfo
|
||||
|
@ -86,69 +88,33 @@ typedef struct SUseDbOutput {
|
|||
SDBVgroupInfo dbVgroup;
|
||||
} SUseDbOutput;
|
||||
|
||||
enum {
|
||||
META_TYPE_NON_TABLE = 1,
|
||||
META_TYPE_CTABLE,
|
||||
META_TYPE_TABLE,
|
||||
META_TYPE_BOTH_TABLE
|
||||
};
|
||||
|
||||
|
||||
typedef struct STableMetaOutput {
|
||||
int32_t metaNum;
|
||||
int32_t metaType;
|
||||
char ctbFname[TSDB_TABLE_FNAME_LEN];
|
||||
char tbFname[TSDB_TABLE_FNAME_LEN];
|
||||
SCTableMeta ctbMeta;
|
||||
STableMeta *tbMeta;
|
||||
} STableMetaOutput;
|
||||
|
||||
typedef struct SDataBuf {
|
||||
void *pData;
|
||||
uint32_t len;
|
||||
} SDataBuf;
|
||||
|
||||
typedef int32_t (*__async_send_cb_fn_t)(void* param, const SDataBuf* pMsg, int32_t code);
|
||||
typedef int32_t (*__async_exec_fn_t)(void* param);
|
||||
|
||||
typedef struct SMsgSendInfo {
|
||||
__async_send_cb_fn_t fp; //async callback function
|
||||
void *param;
|
||||
uint64_t requestId;
|
||||
uint64_t requestObjRefId;
|
||||
int32_t msgType;
|
||||
SDataBuf msgInfo;
|
||||
} SMsgSendInfo;
|
||||
|
||||
typedef struct SQueryNodeAddr{
|
||||
int32_t nodeId; //vgId or qnodeId
|
||||
int8_t inUse;
|
||||
int8_t numOfEps;
|
||||
SEpAddrMsg epAddr[TSDB_MAX_REPLICA];
|
||||
} SQueryNodeAddr;
|
||||
|
||||
bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags);
|
||||
|
||||
int32_t initTaskQueue();
|
||||
int32_t cleanupTaskQueue();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param execFn The asynchronously execution function
|
||||
* @param execParam The parameters of the execFn
|
||||
* @param code The response code during execution the execFn
|
||||
* @return
|
||||
*/
|
||||
int32_t taosAsyncExec(__async_exec_fn_t execFn, void* execParam, int32_t* code);
|
||||
|
||||
/**
|
||||
* Asynchronously send message to server, after the response received, the callback will be incured.
|
||||
*
|
||||
* @param pTransporter
|
||||
* @param epSet
|
||||
* @param pTransporterId
|
||||
* @param pInfo
|
||||
* @return
|
||||
*/
|
||||
int32_t asyncSendMsgToServer(void *pTransporter, SEpSet* epSet, int64_t* pTransporterId, const SMsgSendInfo* pInfo);
|
||||
|
||||
const SSchema* tGetTbnameColumnSchema();
|
||||
void initQueryModuleMsgHandle();
|
||||
|
||||
extern int32_t (*queryBuildMsg[TDMT_MAX])(void* input, char **msg, int32_t msgSize, int32_t *msgLen);
|
||||
extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char *msg, int32_t msgSize);
|
||||
|
||||
#define SET_META_TYPE_NONE(t) (t) = META_TYPE_NON_TABLE
|
||||
#define SET_META_TYPE_CTABLE(t) (t) = META_TYPE_CTABLE
|
||||
#define SET_META_TYPE_TABLE(t) (t) = META_TYPE_TABLE
|
||||
#define SET_META_TYPE_BOTH_TABLE(t) (t) = META_TYPE_BOTH_TABLE
|
||||
|
||||
#define qFatal(...) do { if (qDebugFlag & DEBUG_FATAL) { taosPrintLog("QRY FATAL ", qDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define qError(...) do { if (qDebugFlag & DEBUG_ERROR) { taosPrintLog("QRY ERROR ", qDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define qWarn(...) do { if (qDebugFlag & DEBUG_WARN) { taosPrintLog("QRY WARN ", qDebugFlag, __VA_ARGS__); }} while(0)
|
||||
|
|
|
@ -24,7 +24,7 @@ extern "C" {
|
|||
#include "catalog.h"
|
||||
|
||||
typedef struct SSchedulerCfg {
|
||||
int32_t maxJobNum;
|
||||
uint32_t maxJobNum;
|
||||
} SSchedulerCfg;
|
||||
|
||||
typedef struct SQueryProfileSummary {
|
||||
|
@ -75,6 +75,12 @@ int32_t scheduleExecJob(void *transport, SArray *nodeList, SQueryDag* pDag, void
|
|||
*/
|
||||
int32_t scheduleAsyncExecJob(void *transport, SArray *nodeList, SQueryDag* pDag, void** pJob);
|
||||
|
||||
/**
|
||||
* Fetch query result from the remote query executor
|
||||
* @param pJob
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
int32_t scheduleFetchRows(void *pJob, void **data);
|
||||
|
||||
|
||||
|
@ -85,6 +91,10 @@ int32_t scheduleFetchRows(void *pJob, void **data);
|
|||
*/
|
||||
int32_t scheduleCancelJob(void *pJob);
|
||||
|
||||
/**
|
||||
* Free the query job
|
||||
* @param pJob
|
||||
*/
|
||||
void scheduleFreeJob(void *pJob);
|
||||
|
||||
void schedulerDestroy(void);
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* 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_TFS_H
|
||||
#define TD_TFS_H
|
||||
|
||||
#include "tglobal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
int level;
|
||||
int id;
|
||||
} SDiskID;
|
||||
|
||||
#define TFS_UNDECIDED_LEVEL -1
|
||||
#define TFS_UNDECIDED_ID -1
|
||||
#define TFS_PRIMARY_LEVEL 0
|
||||
#define TFS_PRIMARY_ID 0
|
||||
#define TFS_MIN_LEVEL 0
|
||||
#define TFS_MAX_LEVEL (TSDB_MAX_TIERS - 1)
|
||||
|
||||
// FS APIs ====================================
|
||||
typedef struct {
|
||||
int64_t tsize;
|
||||
int64_t used;
|
||||
int64_t avail;
|
||||
} SFSMeta;
|
||||
|
||||
typedef struct {
|
||||
int64_t size;
|
||||
int64_t used;
|
||||
int64_t free;
|
||||
int16_t nAvailDisks; // # of Available disks
|
||||
} STierMeta;
|
||||
|
||||
int tfsInit(SDiskCfg *pDiskCfg, int ndisk);
|
||||
void tfsDestroy();
|
||||
void tfsUpdateInfo(SFSMeta *pFSMeta, STierMeta *tierMetas, int8_t numLevels);
|
||||
void tfsGetMeta(SFSMeta *pMeta);
|
||||
void tfsAllocDisk(int expLevel, int *level, int *id);
|
||||
|
||||
const char *TFS_PRIMARY_PATH();
|
||||
const char *TFS_DISK_PATH(int level, int id);
|
||||
|
||||
// TFILE APIs ====================================
|
||||
typedef struct {
|
||||
int level;
|
||||
int id;
|
||||
char rname[TSDB_FILENAME_LEN]; // REL name
|
||||
char aname[TSDB_FILENAME_LEN]; // ABS name
|
||||
} TFILE;
|
||||
|
||||
#define TFILE_LEVEL(pf) ((pf)->level)
|
||||
#define TFILE_ID(pf) ((pf)->id)
|
||||
#define TFILE_NAME(pf) ((pf)->aname)
|
||||
#define TFILE_REL_NAME(pf) ((pf)->rname)
|
||||
|
||||
#define tfsopen(pf, flags) open(TFILE_NAME(pf), flags)
|
||||
#define tfsclose(fd) close(fd)
|
||||
#define tfsremove(pf) remove(TFILE_NAME(pf))
|
||||
#define tfscopy(sf, df) taosCopyFile(TFILE_NAME(sf), TFILE_NAME(df))
|
||||
#define tfsrename(sf, df) taosRename(TFILE_NAME(sf), TFILE_NAME(df))
|
||||
|
||||
void tfsInitFile(TFILE *pf, int level, int id, const char *bname);
|
||||
bool tfsIsSameFile(const TFILE *pf1, const TFILE *pf2);
|
||||
int tfsEncodeFile(void **buf, TFILE *pf);
|
||||
void *tfsDecodeFile(void *buf, TFILE *pf);
|
||||
void tfsbasename(const TFILE *pf, char *dest);
|
||||
void tfsdirname(const TFILE *pf, char *dest);
|
||||
|
||||
// DIR APIs ====================================
|
||||
int tfsMkdirAt(const char *rname, int level, int id);
|
||||
int tfsMkdirRecurAt(const char *rname, int level, int id);
|
||||
int tfsMkdir(const char *rname);
|
||||
int tfsRmdir(const char *rname);
|
||||
int tfsRename(char *orname, char *nrname);
|
||||
|
||||
typedef struct TDIR TDIR;
|
||||
|
||||
TDIR * tfsOpendir(const char *rname);
|
||||
const TFILE *tfsReaddir(TDIR *tdir);
|
||||
void tfsClosedir(TDIR *tdir);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -16,6 +16,7 @@
|
|||
#ifndef _TD_TKV_H_
|
||||
#define _TD_TKV_H_
|
||||
|
||||
#if 0
|
||||
#include "os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -59,4 +60,5 @@ void tkvWriteOptsDestroy(STkvWriteOpts *);
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif /*_TD_TKV_H_*/
|
|
@ -84,6 +84,55 @@ void rpcSendRecv(void *shandle, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp)
|
|||
int rpcReportProgress(void *pConn, char *pCont, int contLen);
|
||||
void rpcCancelRequest(int64_t rid);
|
||||
|
||||
typedef struct SDataBuf {
|
||||
void *pData;
|
||||
uint32_t len;
|
||||
} SDataBuf;
|
||||
|
||||
typedef int32_t (*__async_send_cb_fn_t)(void* param, const SDataBuf* pMsg, int32_t code);
|
||||
typedef int32_t (*__async_exec_fn_t)(void* param);
|
||||
|
||||
typedef struct SMsgSendInfo {
|
||||
__async_send_cb_fn_t fp; //async callback function
|
||||
void *param;
|
||||
uint64_t requestId;
|
||||
uint64_t requestObjRefId;
|
||||
int32_t msgType;
|
||||
SDataBuf msgInfo;
|
||||
} SMsgSendInfo;
|
||||
|
||||
typedef struct SQueryNodeAddr {
|
||||
int32_t nodeId; // vgId or qnodeId
|
||||
int8_t inUse;
|
||||
int8_t numOfEps;
|
||||
SEpAddr epAddr[TSDB_MAX_REPLICA];
|
||||
} SQueryNodeAddr;
|
||||
|
||||
bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags);
|
||||
|
||||
int32_t initTaskQueue();
|
||||
int32_t cleanupTaskQueue();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param execFn The asynchronously execution function
|
||||
* @param execParam The parameters of the execFn
|
||||
* @param code The response code during execution the execFn
|
||||
* @return
|
||||
*/
|
||||
int32_t taosAsyncExec(__async_exec_fn_t execFn, void* execParam, int32_t* code);
|
||||
|
||||
/**
|
||||
* Asynchronously send message to server, after the response received, the callback will be incured.
|
||||
*
|
||||
* @param pTransporter
|
||||
* @param epSet
|
||||
* @param pTransporterId
|
||||
* @param pInfo
|
||||
* @return
|
||||
*/
|
||||
int32_t asyncSendMsgToServer(void *pTransporter, SEpSet* epSet, int64_t* pTransporterId, const SMsgSendInfo* pInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -24,10 +24,13 @@ extern "C" {
|
|||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <float.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <math.h>
|
||||
#include <regex.h>
|
||||
#include <sched.h>
|
||||
#include <setjmp.h>
|
||||
#include <signal.h>
|
||||
|
@ -44,6 +47,8 @@ extern "C" {
|
|||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
#include <wordexp.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#include <sys/mman.h>
|
||||
|
||||
|
|
|
@ -73,6 +73,12 @@ extern "C" {
|
|||
|
||||
#endif
|
||||
|
||||
#ifndef WINDOWS
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b)))
|
||||
#define POINTER_DISTANCE(p1, p2) ((char *)(p1) - (char *)(p2))
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ int32_t taosFtruncateFile(FileFd fd, int64_t length);
|
|||
int32_t taosFsyncFile(FileFd fd);
|
||||
|
||||
int64_t taosReadFile(FileFd fd, void *buf, int64_t count);
|
||||
int64_t taosWriteFile(FileFd fd, void *buf, int64_t count);
|
||||
int64_t taosWriteFile(FileFd fd, const void *buf, int64_t count);
|
||||
|
||||
void taosCloseFile(FileFd fd);
|
||||
|
||||
|
|
|
@ -253,37 +253,36 @@ int32_t* taosGetErrno();
|
|||
|
||||
// dnode
|
||||
#define TSDB_CODE_DND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0400)
|
||||
#define TSDB_CODE_DND_EXITING TAOS_DEF_ERROR_CODE(0, 0x0401)
|
||||
#define TSDB_CODE_DND_OFFLINE TAOS_DEF_ERROR_CODE(0, 0x0401)
|
||||
#define TSDB_CODE_DND_INVALID_MSG_LEN TAOS_DEF_ERROR_CODE(0, 0x0402)
|
||||
#define TSDB_CODE_DND_DNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0410)
|
||||
#define TSDB_CODE_DND_DNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0411)
|
||||
#define TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0420)
|
||||
#define TSDB_CODE_DND_MNODE_NOT_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0421)
|
||||
#define TSDB_CODE_DND_MNODE_ID_INVALID TAOS_DEF_ERROR_CODE(0, 0x0422)
|
||||
#define TSDB_CODE_DND_MNODE_ID_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x0423)
|
||||
#define TSDB_CODE_DND_MNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0424)
|
||||
#define TSDB_CODE_DND_MNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0425)
|
||||
#define TSDB_CODE_DND_MNODE_INVALID_OPTION TAOS_DEF_ERROR_CODE(0, 0x0422)
|
||||
#define TSDB_CODE_DND_MNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0423)
|
||||
#define TSDB_CODE_DND_MNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0424)
|
||||
#define TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0430)
|
||||
#define TSDB_CODE_DND_QNODE_NOT_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0431)
|
||||
#define TSDB_CODE_DND_QNODE_ID_INVALID TAOS_DEF_ERROR_CODE(0, 0x0432)
|
||||
#define TSDB_CODE_DND_QNODE_ID_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x0433)
|
||||
#define TSDB_CODE_DND_QNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0434)
|
||||
#define TSDB_CODE_DND_QNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0435)
|
||||
#define TSDB_CODE_DND_QNODE_INVALID_OPTION TAOS_DEF_ERROR_CODE(0, 0x0432)
|
||||
#define TSDB_CODE_DND_QNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0433)
|
||||
#define TSDB_CODE_DND_QNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0434)
|
||||
#define TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0440)
|
||||
#define TSDB_CODE_DND_SNODE_NOT_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0441)
|
||||
#define TSDB_CODE_DND_SNODE_ID_INVALID TAOS_DEF_ERROR_CODE(0, 0x0442)
|
||||
#define TSDB_CODE_DND_SNODE_ID_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x0443)
|
||||
#define TSDB_CODE_DND_SNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0444)
|
||||
#define TSDB_CODE_DND_SNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0445)
|
||||
#define TSDB_CODE_DND_SNODE_INVALID_OPTION TAOS_DEF_ERROR_CODE(0, 0x0442)
|
||||
#define TSDB_CODE_DND_SNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0443)
|
||||
#define TSDB_CODE_DND_SNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0444)
|
||||
#define TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0450)
|
||||
#define TSDB_CODE_DND_BNODE_NOT_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0451)
|
||||
#define TSDB_CODE_DND_BNODE_ID_INVALID TAOS_DEF_ERROR_CODE(0, 0x0452)
|
||||
#define TSDB_CODE_DND_BNODE_ID_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x0453)
|
||||
#define TSDB_CODE_DND_BNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0454)
|
||||
#define TSDB_CODE_DND_BNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0455)
|
||||
#define TSDB_CODE_DND_VNODE_TOO_MANY_VNODES TAOS_DEF_ERROR_CODE(0, 0x0460)
|
||||
#define TSDB_CODE_DND_VNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0461)
|
||||
#define TSDB_CODE_DND_VNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0462)
|
||||
#define TSDB_CODE_DND_BNODE_INVALID_OPTION TAOS_DEF_ERROR_CODE(0, 0x0452)
|
||||
#define TSDB_CODE_DND_BNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0453)
|
||||
#define TSDB_CODE_DND_BNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0454)
|
||||
#define TSDB_CODE_DND_VNODE_ALREADY_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0460)
|
||||
#define TSDB_CODE_DND_VNODE_NOT_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x0461)
|
||||
#define TSDB_CODE_DND_VNODE_INVALID_OPTION TAOS_DEF_ERROR_CODE(0, 0x0462)
|
||||
#define TSDB_CODE_DND_VNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0463)
|
||||
#define TSDB_CODE_DND_VNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0464)
|
||||
#define TSDB_CODE_DND_VNODE_TOO_MANY_VNODES TAOS_DEF_ERROR_CODE(0, 0x0465)
|
||||
|
||||
// vnode
|
||||
#define TSDB_CODE_VND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0500) //"Action in progress")
|
||||
|
@ -401,6 +400,8 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_WAL_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x1000) //"Unexpected generic error in wal")
|
||||
#define TSDB_CODE_WAL_FILE_CORRUPTED TAOS_DEF_ERROR_CODE(0, 0x1001) //"WAL file is corrupted")
|
||||
#define TSDB_CODE_WAL_SIZE_LIMIT TAOS_DEF_ERROR_CODE(0, 0x1002) //"WAL size exceeds limit")
|
||||
#define TSDB_CODE_WAL_INVALID_VER TAOS_DEF_ERROR_CODE(0, 0x1003) //"WAL invalid version")
|
||||
#define TSDB_CODE_WAL_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x1004) //"WAL out of memory")
|
||||
|
||||
// tfs
|
||||
#define TSDB_CODE_FS_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x2200) //"tfs out of memory")
|
||||
|
|
|
@ -370,10 +370,33 @@ static FORCE_INLINE void *taosDecodeStringTo(void *buf, char *value) {
|
|||
return POINTER_SHIFT(buf, size);
|
||||
}
|
||||
|
||||
// ---- binary
|
||||
static FORCE_INLINE int taosEncodeBinary(void **buf, const void *value, int valueLen) {
|
||||
int tlen = 0;
|
||||
|
||||
if (buf != NULL) {
|
||||
memcpy(*buf, value, valueLen);
|
||||
*buf = POINTER_SHIFT(*buf, valueLen);
|
||||
}
|
||||
tlen += (int)valueLen;
|
||||
|
||||
return tlen;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void *taosDecodeBinary(void *buf, void **value, int valueLen) {
|
||||
uint64_t size = 0;
|
||||
|
||||
*value = malloc((size_t)valueLen);
|
||||
if (*value == NULL) return NULL;
|
||||
memcpy(*value, buf, (size_t)size);
|
||||
|
||||
return POINTER_SHIFT(buf, size);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_UTIL_CODING_H*/
|
||||
#endif /*_TD_UTIL_CODING_H*/
|
||||
|
|
|
@ -177,6 +177,7 @@ do { \
|
|||
#define TSDB_TYPE_STR_MAX_LEN 32
|
||||
#define TSDB_TABLE_FNAME_LEN (TSDB_DB_FNAME_LEN + TSDB_TABLE_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
|
||||
#define TSDB_TOPIC_FNAME_LEN TSDB_TABLE_FNAME_LEN
|
||||
#define TSDB_CONSUMER_GROUP_LEN 192
|
||||
#define TSDB_COL_NAME_LEN 65
|
||||
#define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 64
|
||||
#define TSDB_MAX_SQL_LEN TSDB_PAYLOAD_SIZE
|
||||
|
|
|
@ -124,6 +124,9 @@ int32_t taosHashGetSize(const SHashObj *pHashObj);
|
|||
*/
|
||||
int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *data, size_t size);
|
||||
|
||||
int32_t taosHashPutExt(SHashObj *pHashObj, const void *key, size_t keyLen, void *data, size_t size, bool *newAdded);
|
||||
|
||||
|
||||
/**
|
||||
* return the payload data with the specified key
|
||||
*
|
||||
|
@ -210,6 +213,32 @@ void taosHashCancelIterate(SHashObj *pHashObj, void *p);
|
|||
*/
|
||||
int32_t taosHashGetKey(void *data, void** key, size_t* keyLen);
|
||||
|
||||
|
||||
/**
|
||||
* Get the corresponding key information for a given data in hash table, using memcpy
|
||||
* @param data
|
||||
* @param dst
|
||||
* @return
|
||||
*/
|
||||
static FORCE_INLINE int32_t taosHashCopyKey(void *data, void* dst) {
|
||||
if (NULL == data || NULL == dst) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SHashNode * node = GET_HASH_PNODE(data);
|
||||
void* key = GET_HASH_NODE_KEY(node);
|
||||
memcpy(dst, key, node->keyLen);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the corresponding data length for a given data in hash table
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
int32_t taosHashGetDataLen(void *data);
|
||||
|
||||
/**
|
||||
* return the payload data with the specified key(reference number added)
|
||||
*
|
||||
|
|
|
@ -44,7 +44,6 @@ extern int32_t tsdbDebugFlag;
|
|||
extern int32_t tqDebugFlag;
|
||||
extern int32_t cqDebugFlag;
|
||||
extern int32_t debugFlag;
|
||||
extern int32_t ctgDebugFlag;
|
||||
|
||||
#define DEBUG_FATAL 1U
|
||||
#define DEBUG_ERROR DEBUG_FATAL
|
||||
|
|
|
@ -26,14 +26,10 @@ extern "C" {
|
|||
#define TD_MOD_UNINITIALIZED 0
|
||||
#define TD_MOD_INITIALIZED 1
|
||||
|
||||
#define TD_MOD_UNCLEARD 0
|
||||
#define TD_MOD_CLEARD 1
|
||||
|
||||
typedef int8_t td_mode_flag_t;
|
||||
|
||||
#define TD_CHECK_AND_SET_MODE_INIT(FLAG) atomic_val_compare_exchange_8((FLAG), TD_MOD_UNINITIALIZED, TD_MOD_INITIALIZED)
|
||||
|
||||
#define TD_CHECK_AND_SET_MOD_CLEAR(FLAG) atomic_val_compare_exchange_8((FLAG), TD_MOD_UNCLEARD, TD_MOD_CLEARD)
|
||||
#define TD_CHECK_AND_SET_MOD_CLEAR(FLAG) atomic_val_compare_exchange_8((FLAG), TD_MOD_INITIALIZED, TD_MOD_UNINITIALIZED)
|
||||
|
||||
#define TD_IS_NULL(PTR) ((PTR) == NULL)
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ void taosFreeQitem(void *pItem);
|
|||
int32_t taosWriteQitem(STaosQueue *queue, void *pItem);
|
||||
int32_t taosReadQitem(STaosQueue *queue, void **ppItem);
|
||||
bool taosQueueEmpty(STaosQueue *queue);
|
||||
int32_t taosQueueSize(STaosQueue *queue);
|
||||
|
||||
STaosQall *taosAllocateQall();
|
||||
void taosFreeQall(STaosQall *qall);
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "os.h"
|
||||
#include "tarray.h"
|
||||
#include "thash.h"
|
||||
#include "tmsg.h"
|
||||
|
||||
#define HEARTBEAT_INTERVAL 1500 // ms
|
||||
|
||||
typedef enum {
|
||||
HEARTBEAT_TYPE_MQ = 0,
|
||||
// types can be added here
|
||||
//
|
||||
HEARTBEAT_TYPE_MAX
|
||||
} EHbType;
|
||||
|
||||
typedef int32_t (*FHbRspHandle)(SClientHbRsp* pReq);
|
||||
|
||||
typedef struct SAppHbMgr {
|
||||
// statistics
|
||||
int32_t reportCnt;
|
||||
int32_t connKeyCnt;
|
||||
int64_t reportBytes; // not implemented
|
||||
int64_t startTime;
|
||||
// ctl
|
||||
SRWLatch lock; // lock is used in serialization
|
||||
// connection
|
||||
void* transporter;
|
||||
SEpSet epSet;
|
||||
// info
|
||||
SHashObj* activeInfo; // hash<SClientHbKey, SClientHbReq>
|
||||
SHashObj* getInfoFuncs; // hash<SClientHbKey, FGetConnInfo>
|
||||
} SAppHbMgr;
|
||||
|
||||
typedef struct SClientHbMgr {
|
||||
int8_t inited;
|
||||
// ctl
|
||||
int8_t threadStop;
|
||||
pthread_t thread;
|
||||
pthread_mutex_t lock; // used when app init and cleanup
|
||||
SArray* appHbMgrs; // SArray<SAppHbMgr*> one for each cluster
|
||||
FHbRspHandle handle[HEARTBEAT_TYPE_MAX];
|
||||
} SClientHbMgr;
|
||||
|
||||
// TODO: embed param into function
|
||||
// return type: SArray<Skv>
|
||||
typedef SArray* (*FGetConnInfo)(SClientHbKey connKey, void* param);
|
||||
|
||||
// global, called by mgmt
|
||||
int hbMgrInit();
|
||||
void hbMgrCleanUp();
|
||||
int hbHandleRsp(SClientHbBatchRsp* hbRsp);
|
||||
|
||||
// cluster level
|
||||
SAppHbMgr* appHbMgrInit(void* transporter, SEpSet epSet);
|
||||
void appHbMgrCleanup(SAppHbMgr* pAppHbMgr);
|
||||
|
||||
// conn level
|
||||
int hbRegisterConn(SAppHbMgr* pAppHbMgr, SClientHbKey connKey, FGetConnInfo func);
|
||||
void hbDeregisterConn(SAppHbMgr* pAppHbMgr, SClientHbKey connKey);
|
||||
|
||||
int hbAddConnInfo(SAppHbMgr* pAppHbMgr, SClientHbKey connKey, void* key, void* value, int32_t keyLen, int32_t valueLen);
|
||||
|
||||
// mq
|
||||
void hbMgrInitMqHbRspHandle();
|
|
@ -62,6 +62,7 @@ typedef struct SAppInstInfo {
|
|||
SList *pConnList; // STscObj linked list
|
||||
int64_t clusterId;
|
||||
void *pTransporter;
|
||||
SHeartBeatInfo hb;
|
||||
} SAppInstInfo;
|
||||
|
||||
typedef struct SAppInfo {
|
||||
|
@ -70,7 +71,7 @@ typedef struct SAppInfo {
|
|||
char *ep;
|
||||
int32_t pid;
|
||||
int32_t numOfThreads;
|
||||
SHeartBeatInfo hb;
|
||||
|
||||
SHashObj *pInstMap;
|
||||
} SAppInfo;
|
||||
|
||||
|
|
|
@ -180,6 +180,14 @@ void* createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t ty
|
|||
return pRequest;
|
||||
}
|
||||
|
||||
static void doFreeReqResultInfo(SReqResultInfo* pResInfo) {
|
||||
tfree(pResInfo->pRspMsg);
|
||||
tfree(pResInfo->length);
|
||||
tfree(pResInfo->row);
|
||||
tfree(pResInfo->pCol);
|
||||
tfree(pResInfo->fields);
|
||||
}
|
||||
|
||||
static void doDestroyRequest(void* p) {
|
||||
assert(p != NULL);
|
||||
SRequestObj* pRequest = (SRequestObj*)p;
|
||||
|
@ -190,7 +198,7 @@ static void doDestroyRequest(void* p) {
|
|||
tfree(pRequest->sqlstr);
|
||||
tfree(pRequest->pInfo);
|
||||
|
||||
tfree(pRequest->body.resInfo.pRspMsg);
|
||||
doFreeReqResultInfo(&pRequest->body.resInfo);
|
||||
|
||||
deregisterRequest(pRequest);
|
||||
tfree(pRequest);
|
||||
|
@ -415,7 +423,7 @@ int taos_options_imp(TSDB_OPTION option, const char *str) {
|
|||
*+------------+-----+-----------+---------------+
|
||||
*| uid|localIp| PId | timestamp | serial number |
|
||||
*+------------+-----+-----------+---------------+
|
||||
*| 16bit |12bit|20bit |16bit |
|
||||
*| 12bit |12bit|24bit |16bit |
|
||||
*+------------+-----+-----------+---------------+
|
||||
* @return
|
||||
*/
|
||||
|
@ -435,11 +443,11 @@ uint64_t generateRequestId() {
|
|||
}
|
||||
}
|
||||
|
||||
int64_t ts = taosGetTimestampUs();
|
||||
int64_t ts = taosGetTimestampMs();
|
||||
uint64_t pid = taosGetPId();
|
||||
int32_t val = atomic_add_fetch_32(&requestSerialId, 1);
|
||||
|
||||
uint64_t id = ((hashId & 0xFFFF) << 48) | ((pid & 0x0FFF) << 36) | ((ts & 0xFFFFF) << 16) | (val & 0xFFFF);
|
||||
uint64_t id = ((hashId & 0x0FFF) << 52) | ((pid & 0x0FFF) << 40) | ((ts & 0xFFFFFF) << 16) | (val & 0xFFFF);
|
||||
return id;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,227 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "clientHb.h"
|
||||
#include "trpc.h"
|
||||
|
||||
static SClientHbMgr clientHbMgr = {0};
|
||||
|
||||
static int32_t hbCreateThread();
|
||||
static void hbStopThread();
|
||||
|
||||
static int32_t hbMqHbRspHandle(SClientHbRsp* pReq) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hbMgrInitMqHbRspHandle() {
|
||||
clientHbMgr.handle[HEARTBEAT_TYPE_MQ] = hbMqHbRspHandle;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void hbMgrInitHandle() {
|
||||
// init all handle
|
||||
hbMgrInitMqHbRspHandle();
|
||||
}
|
||||
|
||||
SClientHbBatchReq* hbGatherAllInfo(SAppHbMgr *pAppHbMgr) {
|
||||
SClientHbBatchReq* pReq = malloc(sizeof(SClientHbBatchReq));
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
int32_t connKeyCnt = atomic_load_32(&pAppHbMgr->connKeyCnt);
|
||||
pReq->reqs = taosArrayInit(connKeyCnt, sizeof(SClientHbReq));
|
||||
|
||||
void *pIter = taosHashIterate(pAppHbMgr->activeInfo, NULL);
|
||||
while (pIter != NULL) {
|
||||
taosArrayPush(pReq->reqs, pIter);
|
||||
SClientHbReq* pOneReq = pIter;
|
||||
taosHashClear(pOneReq->info);
|
||||
|
||||
pIter = taosHashIterate(pAppHbMgr->activeInfo, pIter);
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(pAppHbMgr->getInfoFuncs, NULL);
|
||||
while (pIter != NULL) {
|
||||
FGetConnInfo getConnInfoFp = (FGetConnInfo)pIter;
|
||||
SClientHbKey connKey;
|
||||
taosHashCopyKey(pIter, &connKey);
|
||||
getConnInfoFp(connKey, NULL);
|
||||
|
||||
pIter = taosHashIterate(pAppHbMgr->activeInfo, pIter);
|
||||
}
|
||||
|
||||
return pReq;
|
||||
}
|
||||
|
||||
static void* hbThreadFunc(void* param) {
|
||||
setThreadName("hb");
|
||||
while (1) {
|
||||
int8_t threadStop = atomic_load_8(&clientHbMgr.threadStop);
|
||||
if(threadStop) {
|
||||
break;
|
||||
}
|
||||
|
||||
int sz = taosArrayGetSize(clientHbMgr.appHbMgrs);
|
||||
for(int i = 0; i < sz; i++) {
|
||||
SAppHbMgr* pAppHbMgr = taosArrayGet(clientHbMgr.appHbMgrs, i);
|
||||
SClientHbBatchReq* pReq = hbGatherAllInfo(pAppHbMgr);
|
||||
void* reqStr = NULL;
|
||||
int tlen = tSerializeSClientHbBatchReq(&reqStr, pReq);
|
||||
SMsgSendInfo info;
|
||||
/*info.fp = hbHandleRsp;*/
|
||||
|
||||
int64_t transporterId = 0;
|
||||
asyncSendMsgToServer(pAppHbMgr->transporter, &pAppHbMgr->epSet, &transporterId, &info);
|
||||
tFreeClientHbBatchReq(pReq);
|
||||
|
||||
atomic_add_fetch_32(&pAppHbMgr->reportCnt, 1);
|
||||
taosMsleep(HEARTBEAT_INTERVAL);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int32_t hbCreateThread() {
|
||||
pthread_attr_t thAttr;
|
||||
pthread_attr_init(&thAttr);
|
||||
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
|
||||
if (pthread_create(&clientHbMgr.thread, &thAttr, hbThreadFunc, NULL) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
pthread_attr_destroy(&thAttr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void hbStopThread() {
|
||||
atomic_store_8(&clientHbMgr.threadStop, 1);
|
||||
}
|
||||
|
||||
SAppHbMgr* appHbMgrInit(void* transporter, SEpSet epSet) {
|
||||
SAppHbMgr* pAppHbMgr = malloc(sizeof(SAppHbMgr));
|
||||
if (pAppHbMgr == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
// init stat
|
||||
pAppHbMgr->startTime = taosGetTimestampMs();
|
||||
|
||||
// init connection info
|
||||
pAppHbMgr->transporter = transporter;
|
||||
pAppHbMgr->epSet = epSet;
|
||||
|
||||
// init hash info
|
||||
pAppHbMgr->activeInfo = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK);
|
||||
pAppHbMgr->activeInfo->freeFp = tFreeClientHbReq;
|
||||
// init getInfoFunc
|
||||
pAppHbMgr->getInfoFuncs = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK);
|
||||
|
||||
taosArrayPush(clientHbMgr.appHbMgrs, &pAppHbMgr);
|
||||
return pAppHbMgr;
|
||||
}
|
||||
|
||||
void appHbMgrCleanup(SAppHbMgr* pAppHbMgr) {
|
||||
pthread_mutex_lock(&clientHbMgr.lock);
|
||||
|
||||
int sz = taosArrayGetSize(clientHbMgr.appHbMgrs);
|
||||
for (int i = 0; i < sz; i++) {
|
||||
SAppHbMgr* pTarget = taosArrayGet(clientHbMgr.appHbMgrs, i);
|
||||
if (pAppHbMgr == pTarget) {
|
||||
taosHashCleanup(pTarget->activeInfo);
|
||||
taosHashCleanup(pTarget->getInfoFuncs);
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&clientHbMgr.lock);
|
||||
}
|
||||
|
||||
int hbMgrInit() {
|
||||
// init once
|
||||
int8_t old = atomic_val_compare_exchange_8(&clientHbMgr.inited, 0, 1);
|
||||
if (old == 1) return 0;
|
||||
|
||||
clientHbMgr.appHbMgrs = taosArrayInit(0, sizeof(void*));
|
||||
pthread_mutex_init(&clientHbMgr.lock, NULL);
|
||||
|
||||
// init handle funcs
|
||||
hbMgrInitHandle();
|
||||
|
||||
// init backgroud thread
|
||||
hbCreateThread();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hbMgrCleanUp() {
|
||||
// destroy all appHbMgr
|
||||
int8_t old = atomic_val_compare_exchange_8(&clientHbMgr.inited, 1, 0);
|
||||
if (old == 0) return;
|
||||
|
||||
taosArrayDestroy(clientHbMgr.appHbMgrs);
|
||||
|
||||
}
|
||||
|
||||
int hbHandleRsp(SClientHbBatchRsp* hbRsp) {
|
||||
int64_t reqId = hbRsp->reqId;
|
||||
int64_t rspId = hbRsp->rspId;
|
||||
|
||||
SArray* rsps = hbRsp->rsps;
|
||||
int32_t sz = taosArrayGetSize(rsps);
|
||||
for (int i = 0; i < sz; i++) {
|
||||
SClientHbRsp* pRsp = taosArrayGet(rsps, i);
|
||||
if (pRsp->connKey.hbType < HEARTBEAT_TYPE_MAX) {
|
||||
clientHbMgr.handle[pRsp->connKey.hbType](pRsp);
|
||||
} else {
|
||||
// discard rsp
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hbRegisterConn(SAppHbMgr* pAppHbMgr, SClientHbKey connKey, FGetConnInfo func) {
|
||||
// init hash in activeinfo
|
||||
void* data = taosHashGet(pAppHbMgr->activeInfo, &connKey, sizeof(SClientHbKey));
|
||||
if (data != NULL) {
|
||||
return 0;
|
||||
}
|
||||
SClientHbReq hbReq;
|
||||
hbReq.connKey = connKey;
|
||||
hbReq.info = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK);
|
||||
taosHashPut(pAppHbMgr->activeInfo, &connKey, sizeof(SClientHbKey), &hbReq, sizeof(SClientHbReq));
|
||||
// init hash
|
||||
if (func != NULL) {
|
||||
taosHashPut(pAppHbMgr->getInfoFuncs, &connKey, sizeof(SClientHbKey), func, sizeof(FGetConnInfo));
|
||||
}
|
||||
|
||||
atomic_add_fetch_32(&pAppHbMgr->connKeyCnt, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hbDeregisterConn(SAppHbMgr* pAppHbMgr, SClientHbKey connKey) {
|
||||
taosHashRemove(pAppHbMgr->activeInfo, &connKey, sizeof(SClientHbKey));
|
||||
taosHashRemove(pAppHbMgr->getInfoFuncs, &connKey, sizeof(SClientHbKey));
|
||||
atomic_sub_fetch_32(&pAppHbMgr->connKeyCnt, 1);
|
||||
}
|
||||
|
||||
int hbAddConnInfo(SAppHbMgr *pAppHbMgr, SClientHbKey connKey, void* key, void* value, int32_t keyLen, int32_t valueLen) {
|
||||
// find req by connection id
|
||||
SClientHbReq* pReq = taosHashGet(pAppHbMgr->activeInfo, &connKey, sizeof(SClientHbKey));
|
||||
ASSERT(pReq != NULL);
|
||||
|
||||
taosHashPut(pReq->info, key, keyLen, value, valueLen);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -140,7 +140,7 @@ int32_t buildRequest(STscObj *pTscObj, const char *sql, int sqlLen, SRequestObj*
|
|||
(*pRequest)->sqlstr[sqlLen] = 0;
|
||||
(*pRequest)->sqlLen = sqlLen;
|
||||
|
||||
tscDebugL("0x%"PRIx64" SQL: %s, reqId:0x"PRIx64, (*pRequest)->self, (*pRequest)->sqlstr, (*pRequest)->requestId);
|
||||
tscDebugL("0x%"PRIx64" SQL: %s, reqId:0x%"PRIx64, (*pRequest)->self, (*pRequest)->sqlstr, (*pRequest)->requestId);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -181,7 +181,7 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQueryNode* pQuery) {
|
|||
if (pDcl->msgType == TDMT_VND_SHOW_TABLES) {
|
||||
SShowReqInfo* pShowReqInfo = &pRequest->body.showInfo;
|
||||
if (pShowReqInfo->pArray == NULL) {
|
||||
pShowReqInfo->currentIndex = 0;
|
||||
pShowReqInfo->currentIndex = 0; // set the first vnode/ then iterate the next vnode
|
||||
pShowReqInfo->pArray = pDcl->pExtension;
|
||||
}
|
||||
}
|
||||
|
@ -192,24 +192,32 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQueryNode* pQuery) {
|
|||
}
|
||||
|
||||
tsem_wait(&pRequest->body.rspSem);
|
||||
destroySendMsgInfo(pSendMsg);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t getPlan(SRequestObj* pRequest, SQueryNode* pQuery, SQueryDag** pDag) {
|
||||
pRequest->type = pQuery->type;
|
||||
return qCreateQueryDag(pQuery, pDag, pRequest->requestId);
|
||||
int32_t getPlan(SRequestObj* pRequest, SQueryNode* pQueryNode, SQueryDag** pDag) {
|
||||
pRequest->type = pQueryNode->type;
|
||||
return qCreateQueryDag(pQueryNode, pDag, pRequest->requestId);
|
||||
}
|
||||
|
||||
int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, void** pJob) {
|
||||
if (TSDB_SQL_INSERT == pRequest->type || TSDB_SQL_CREATE_TABLE == pRequest->type) {
|
||||
SQueryResult res = {.code = 0, .numOfRows = 0, .msgSize = ERROR_MSG_BUF_DEFAULT_SIZE, .msg = pRequest->msgBuf};
|
||||
|
||||
int32_t code = scheduleExecJob(pRequest->pTscObj->pTransporter, NULL, pDag, pJob, &res);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
// handle error and retry
|
||||
} else {
|
||||
if (*pJob != NULL) {
|
||||
scheduleFreeJob(*pJob);
|
||||
}
|
||||
}
|
||||
|
||||
pRequest->affectedRows = res.numOfRows;
|
||||
return res.code;
|
||||
}
|
||||
|
||||
return scheduleAsyncExecJob(pRequest->pTscObj->pTransporter, NULL/*todo appInfo.xxx*/, pDag, pJob);
|
||||
return scheduleAsyncExecJob(pRequest->pTscObj->pTransporter, NULL /*todo appInfo.xxx*/, pDag, pJob);
|
||||
}
|
||||
|
||||
TAOS_RES *tmq_create_topic(TAOS* taos, const char* name, const char* sql, int sqlLen) {
|
||||
|
@ -283,10 +291,10 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) {
|
|||
|
||||
nPrintTsc("%s", sql)
|
||||
|
||||
SRequestObj* pRequest = NULL;
|
||||
SQueryNode* pQuery = NULL;
|
||||
SQueryDag* pDag = NULL;
|
||||
void* pJob = NULL;
|
||||
SRequestObj *pRequest = NULL;
|
||||
SQueryNode *pQuery = NULL;
|
||||
SQueryDag *pDag = NULL;
|
||||
void *pJob = NULL;
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return);
|
||||
|
@ -297,6 +305,8 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) {
|
|||
} else {
|
||||
CHECK_CODE_GOTO(getPlan(pRequest, pQuery, &pDag), _return);
|
||||
CHECK_CODE_GOTO(scheduleQuery(pRequest, pDag, &pJob), _return);
|
||||
pRequest->code = terrno;
|
||||
return pRequest;
|
||||
}
|
||||
|
||||
_return:
|
||||
|
@ -364,8 +374,6 @@ STscObj* taosConnectImpl(const char *ip, const char *user, const char *auth, con
|
|||
asyncSendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &transporterId, body);
|
||||
|
||||
tsem_wait(&pRequest->body.rspSem);
|
||||
destroySendMsgInfo(body);
|
||||
|
||||
if (pRequest->code != TSDB_CODE_SUCCESS) {
|
||||
const char *errorMsg = (pRequest->code == TSDB_CODE_RPC_FQDN_ERROR) ? taos_errstr(pRequest) : tstrerror(terrno);
|
||||
printf("failed to connect to server, reason: %s\n\n", errorMsg);
|
||||
|
@ -389,13 +397,13 @@ static SMsgSendInfo* buildConnectMsg(SRequestObj *pRequest) {
|
|||
}
|
||||
|
||||
pMsgSendInfo->msgType = TDMT_MND_CONNECT;
|
||||
pMsgSendInfo->msgInfo.len = sizeof(SConnectMsg);
|
||||
pMsgSendInfo->msgInfo.len = sizeof(SConnectReq);
|
||||
pMsgSendInfo->requestObjRefId = pRequest->self;
|
||||
pMsgSendInfo->requestId = pRequest->requestId;
|
||||
pMsgSendInfo->fp = handleRequestRspFp[TMSG_INDEX(pMsgSendInfo->msgType)];
|
||||
pMsgSendInfo->param = pRequest;
|
||||
|
||||
SConnectMsg *pConnect = calloc(1, sizeof(SConnectMsg));
|
||||
SConnectReq *pConnect = calloc(1, sizeof(SConnectReq));
|
||||
if (pConnect == NULL) {
|
||||
tfree(pMsgSendInfo);
|
||||
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
|
@ -456,17 +464,21 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
|
|||
taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId);
|
||||
}
|
||||
|
||||
SDataBuf buf = {.len = pMsg->contLen};
|
||||
buf.pData = calloc(1, pMsg->contLen);
|
||||
if (buf.pData == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
pMsg->code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
} else {
|
||||
memcpy(buf.pData, pMsg->pCont, pMsg->contLen);
|
||||
SDataBuf buf = {.len = pMsg->contLen, .pData = NULL};
|
||||
|
||||
if (pMsg->contLen > 0) {
|
||||
buf.pData = calloc(1, pMsg->contLen);
|
||||
if (buf.pData == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
pMsg->code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
} else {
|
||||
memcpy(buf.pData, pMsg->pCont, pMsg->contLen);
|
||||
}
|
||||
}
|
||||
|
||||
pSendInfo->fp(pSendInfo->param, &buf, pMsg->code);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
destroySendMsgInfo(pSendInfo);
|
||||
}
|
||||
|
||||
TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port) {
|
||||
|
@ -525,9 +537,7 @@ void* doFetchRow(SRequestObj* 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;
|
||||
}
|
||||
|
@ -539,7 +549,6 @@ void* doFetchRow(SRequestObj* pRequest) {
|
|||
asyncSendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &transporterId, body);
|
||||
|
||||
tsem_wait(&pRequest->body.rspSem);
|
||||
destroySendMsgInfo(body);
|
||||
|
||||
pResultInfo->current = 0;
|
||||
if (pResultInfo->numOfRows <= pResultInfo->current) {
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
#include "os.h"
|
||||
#include "tref.h"
|
||||
#include "trpc.h"
|
||||
#include "clientInt.h"
|
||||
#include "clientLog.h"
|
||||
#include "query.h"
|
||||
#include "tmsg.h"
|
||||
#include "tglobal.h"
|
||||
#include "tref.h"
|
||||
#include "trpc.h"
|
||||
#include "catalog.h"
|
||||
|
||||
#define TSC_VAR_NOT_RELEASE 1
|
||||
#define TSC_VAR_RELEASED 0
|
||||
|
@ -46,6 +47,7 @@ void taos_cleanup(void) {
|
|||
taosCloseRef(id);
|
||||
|
||||
rpcCleanup();
|
||||
catalogDestroy();
|
||||
taosCloseLog();
|
||||
|
||||
tscInfo("all local resources released");
|
||||
|
|
|
@ -30,6 +30,7 @@ int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
SRequestObj* pRequest = param;
|
||||
setErrno(pRequest, code);
|
||||
|
||||
free(pMsg->pData);
|
||||
sem_post(&pRequest->body.rspSem);
|
||||
return code;
|
||||
}
|
||||
|
@ -37,6 +38,7 @@ int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
int processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||
SRequestObj* pRequest = param;
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
free(pMsg->pData);
|
||||
setErrno(pRequest, code);
|
||||
sem_post(&pRequest->body.rspSem);
|
||||
return code;
|
||||
|
@ -73,6 +75,7 @@ int processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
tscDebug("0x%" PRIx64 " clusterId:%" PRId64 ", totalConn:%" PRId64, pRequest->requestId, pConnect->clusterId,
|
||||
pTscObj->pAppInfo->numOfConns);
|
||||
|
||||
free(pMsg->pData);
|
||||
sem_post(&pRequest->body.rspSem);
|
||||
return 0;
|
||||
}
|
||||
|
@ -87,14 +90,14 @@ SMsgSendInfo* buildMsgInfoImpl(SRequestObj *pRequest) {
|
|||
|
||||
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));
|
||||
SRetrieveTableReq* pRetrieveMsg = calloc(1, sizeof(SRetrieveTableReq));
|
||||
if (pRetrieveMsg == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pRetrieveMsg->showId = htobe64(pRequest->body.showInfo.execId);
|
||||
pMsgSendInfo->msgInfo.pData = pRetrieveMsg;
|
||||
pMsgSendInfo->msgInfo.len = sizeof(SRetrieveTableMsg);
|
||||
pMsgSendInfo->msgInfo.len = sizeof(SRetrieveTableReq);
|
||||
} else {
|
||||
SVShowTablesFetchReq* pFetchMsg = calloc(1, sizeof(SVShowTablesFetchReq));
|
||||
if (pFetchMsg == NULL) {
|
||||
|
@ -127,7 +130,7 @@ int32_t processShowRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
SShowRsp* pShow = (SShowRsp *)pMsg->pData;
|
||||
pShow->showId = htobe64(pShow->showId);
|
||||
|
||||
STableMetaMsg *pMetaMsg = &(pShow->tableMeta);
|
||||
STableMetaRsp *pMetaMsg = &(pShow->tableMeta);
|
||||
pMetaMsg->numOfColumns = htonl(pMetaMsg->numOfColumns);
|
||||
|
||||
SSchema* pSchema = pMetaMsg->pSchema;
|
||||
|
@ -238,6 +241,7 @@ int32_t processRetrieveVndRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
int32_t processCreateDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||
// todo rsp with the vnode id list
|
||||
SRequestObj* pRequest = param;
|
||||
free(pMsg->pData);
|
||||
tsem_post(&pRequest->body.rspSem);
|
||||
}
|
||||
|
||||
|
@ -245,6 +249,7 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
SRequestObj* pRequest = param;
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
free(pMsg->pData);
|
||||
setErrno(pRequest, code);
|
||||
tsem_post(&pRequest->body.rspSem);
|
||||
return code;
|
||||
|
@ -258,6 +263,7 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
tNameGetDbName(&name, db);
|
||||
|
||||
setConnectionDB(pRequest->pTscObj, db);
|
||||
free(pMsg->pData);
|
||||
tsem_post(&pRequest->body.rspSem);
|
||||
return 0;
|
||||
}
|
||||
|
@ -266,6 +272,7 @@ int32_t processCreateTableRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
assert(pMsg != NULL && param != NULL);
|
||||
SRequestObj* pRequest = param;
|
||||
|
||||
free(pMsg->pData);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
setErrno(pRequest, code);
|
||||
tsem_post(&pRequest->body.rspSem);
|
||||
|
|
|
@ -101,17 +101,18 @@ TEST(testCase, show_user_Test) {
|
|||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "show users");
|
||||
TAOS_ROW pRow = NULL;
|
||||
TAOS_ROW pRow = NULL;
|
||||
|
||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
|
||||
char str[512] = {0};
|
||||
while((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -130,16 +131,16 @@ TEST(testCase, drop_user_Test) {
|
|||
|
||||
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, "show databases");
|
||||
TAOS_ROW pRow = NULL;
|
||||
TAOS_ROW pRow = NULL;
|
||||
|
||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
|
||||
char str[512] = {0};
|
||||
while((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
while ((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
printf("%s\n", str);
|
||||
}
|
||||
|
@ -151,7 +152,7 @@ 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");
|
||||
TAOS_RES* pRes = taos_query(pConn, "create database abc1 vgroups 2");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in create db, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
|
@ -170,90 +171,90 @@ TEST(testCase, create_db_Test) {
|
|||
}
|
||||
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, drop_db_test) {
|
||||
//// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
//// 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);
|
||||
//}
|
||||
|
||||
TEST(testCase, create_stable_Test) {
|
||||
TEST(testCase, create_dnode_Test) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "create database abc1");
|
||||
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, drop_db_test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// 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);
|
||||
//}
|
||||
|
||||
TEST(testCase, create_stable_Test) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "create database abc1 vgroups 2");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in create db, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
|
@ -280,128 +281,227 @@ TEST(testCase, create_db_Test) {
|
|||
taos_close(pConn);
|
||||
}
|
||||
|
||||
//TEST(testCase, create_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, "create table tm0(ts timestamp, k int)");
|
||||
// // taos_free_result(pRes);
|
||||
// //
|
||||
// // taos_close(pConn);
|
||||
//}
|
||||
//
|
||||
//TEST(testCase, create_ctable_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, "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);
|
||||
//}
|
||||
TEST(testCase, create_table_Test) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
//TEST(testCase, create_topic_Test) {
|
||||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create table tm0(ts timestamp, k int)");
|
||||
taos_free_result(pRes);
|
||||
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, create_ctable_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, "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, create_multiple_tables) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(pConn, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to use db, reason:%s", taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
return;
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create table t_2 using st1 tags(1)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
pRes = taos_query(pConn, "create table t_3 using st1 tags(2)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create multiple tables, 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);
|
||||
|
||||
for (int32_t i = 0; i < 20; ++i) {
|
||||
char sql[512] = {0};
|
||||
snprintf(sql, tListLen(sql),
|
||||
"create table t_x_%d using st1 tags(2) t_x_%d using st1 tags(5) t_x_%d using st1 tags(911)", i,
|
||||
(i + 1) * 30, (i + 2) * 40);
|
||||
TAOS_RES* pres = taos_query(pConn, sql);
|
||||
if (taos_errno(pres) != 0) {
|
||||
printf("failed to create table %d\n, reason:%s", i, taos_errstr(pres));
|
||||
}
|
||||
taos_free_result(pres);
|
||||
}
|
||||
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
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, 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);
|
||||
}
|
||||
|
||||
TEST(testCase, generated_request_id_test) {
|
||||
SHashObj* phash = taosHashInit(10000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
|
||||
|
||||
for (int32_t i = 0; i < 50000; ++i) {
|
||||
uint64_t v = generateRequestId();
|
||||
void* result = taosHashGet(phash, &v, sizeof(v));
|
||||
if (result != nullptr) {
|
||||
printf("0x%lx, index:%d\n", v, i);
|
||||
}
|
||||
assert(result == nullptr);
|
||||
taosHashPut(phash, &v, sizeof(v), NULL, 0);
|
||||
}
|
||||
|
||||
taosHashCleanup(phash);
|
||||
}
|
||||
|
||||
// TEST(testCase, create_topic_Test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
|
@ -434,120 +534,55 @@ TEST(testCase, create_db_Test) {
|
|||
// tmq_create_topic(pConn, "test_topic_1", sql, strlen(sql));
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
|
||||
//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);
|
||||
ASSERT_NE(pConn, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create table t_2 using st1 tags(1)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
pRes = taos_query(pConn, "create table t_3 using st1 tags(2)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create multiple tables, 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);
|
||||
|
||||
// for(int32_t i = 0; i < 10000; ++i) {
|
||||
// char sql[512] = {0};
|
||||
// snprintf(sql, tListLen(sql), "create table t_x_%d using st1 tags(2)", i);
|
||||
// TAOS_RES* pres = taos_query(pConn, sql);
|
||||
// if (taos_errno(pres) != 0) {
|
||||
// printf("failed to create table %d\n, reason:%s", i, taos_errstr(pres));
|
||||
// }
|
||||
// taos_free_result(pres);
|
||||
// }
|
||||
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, generated_request_id_test) {
|
||||
SHashObj *phash = taosHashInit(10000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
|
||||
|
||||
for(int32_t i = 0; i < 1000000; ++i) {
|
||||
uint64_t v = generateRequestId();
|
||||
void* result = taosHashGet(phash, &v, sizeof(v));
|
||||
ASSERT_EQ(result, nullptr);
|
||||
taosHashPut(phash, &v, sizeof(v), NULL, 0);
|
||||
}
|
||||
|
||||
taosHashClear(phash);
|
||||
}
|
||||
|
||||
//TEST(testCase, projection_query_tables) {
|
||||
//TEST(testCase, insert_test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// ASSERT_EQ(pConn, nullptr);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
// taos_free_result(pRes);
|
||||
//
|
||||
// pRes = taos_query(pConn, "select * from t_2");
|
||||
// pRes = taos_query(pConn, "insert into t_2 values(now, 1)");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("failed to create multiple tables, 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);
|
||||
//}
|
||||
//#endif
|
||||
|
||||
TEST(testCase, projection_query_tables) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(pConn, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "use test1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to use db, reason:%s", taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
return;
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "select * from tm0");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create multiple tables, 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);
|
||||
}
|
||||
|
|
|
@ -910,7 +910,7 @@ static void doInitGlobalConfig(void) {
|
|||
cfg.option = "tsdbDebugFlag";
|
||||
cfg.ptr = &tsdbDebugFlag;
|
||||
cfg.valType = TAOS_CFG_VTYPE_INT32;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT;
|
||||
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG;
|
||||
cfg.minValue = 0;
|
||||
cfg.maxValue = 255;
|
||||
cfg.ptrLength = 0;
|
||||
|
|
|
@ -27,6 +27,109 @@
|
|||
#undef TD_MSG_SEG_CODE_
|
||||
#include "tmsgdef.h"
|
||||
|
||||
int tInitSubmitMsgIter(SSubmitMsg *pMsg, SSubmitMsgIter *pIter) {
|
||||
if (pMsg == NULL) {
|
||||
terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pIter->totalLen = pMsg->length;
|
||||
pIter->len = 0;
|
||||
pIter->pMsg = pMsg;
|
||||
if (pMsg->length <= sizeof(SSubmitMsg)) {
|
||||
terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tGetSubmitMsgNext(SSubmitMsgIter *pIter, SSubmitBlk **pPBlock) {
|
||||
if (pIter->len == 0) {
|
||||
pIter->len += sizeof(SSubmitMsg);
|
||||
} else {
|
||||
SSubmitBlk *pSubmitBlk = (SSubmitBlk *)POINTER_SHIFT(pIter->pMsg, pIter->len);
|
||||
pIter->len += (sizeof(SSubmitBlk) + pSubmitBlk->dataLen + pSubmitBlk->schemaLen);
|
||||
}
|
||||
|
||||
if (pIter->len > pIter->totalLen) {
|
||||
terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP;
|
||||
*pPBlock = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
*pPBlock = (pIter->len == pIter->totalLen) ? NULL : (SSubmitBlk *)POINTER_SHIFT(pIter->pMsg, pIter->len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tInitSubmitBlkIter(SSubmitBlk *pBlock, SSubmitBlkIter *pIter) {
|
||||
if (pBlock->dataLen <= 0) return -1;
|
||||
pIter->totalLen = pBlock->dataLen;
|
||||
pIter->len = 0;
|
||||
pIter->row = (SMemRow)(pBlock->data + pBlock->schemaLen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SMemRow tGetSubmitBlkNext(SSubmitBlkIter *pIter) {
|
||||
SMemRow row = pIter->row;
|
||||
|
||||
if (pIter->len >= pIter->totalLen) {
|
||||
return NULL;
|
||||
} else {
|
||||
pIter->len += memRowTLen(row);
|
||||
if (pIter->len < pIter->totalLen) {
|
||||
pIter->row = POINTER_SHIFT(row, memRowTLen(row));
|
||||
}
|
||||
return row;
|
||||
}
|
||||
}
|
||||
|
||||
int tSerializeSClientHbReq(void **buf, const SClientHbReq *pReq) {
|
||||
int tlen = 0;
|
||||
tlen += taosEncodeSClientHbKey(buf, &pReq->connKey);
|
||||
|
||||
int kvNum = taosHashGetSize(pReq->info);
|
||||
tlen += taosEncodeFixedI32(buf, kvNum);
|
||||
SKv kv;
|
||||
void* pIter = taosHashIterate(pReq->info, pIter);
|
||||
while (pIter != NULL) {
|
||||
taosHashGetKey(pIter, &kv.key, (size_t *)&kv.keyLen);
|
||||
kv.valueLen = taosHashGetDataLen(pIter);
|
||||
kv.value = pIter;
|
||||
tlen += taosEncodeSKv(buf, &kv);
|
||||
|
||||
pIter = taosHashIterate(pReq->info, pIter);
|
||||
}
|
||||
return tlen;
|
||||
}
|
||||
|
||||
void *tDeserializeClientHbReq(void *buf, SClientHbReq *pReq) {
|
||||
ASSERT(pReq->info != NULL);
|
||||
buf = taosDecodeSClientHbKey(buf, &pReq->connKey);
|
||||
|
||||
// TODO: error handling
|
||||
int kvNum;
|
||||
taosDecodeFixedI32(buf, &kvNum);
|
||||
pReq->info = taosHashInit(kvNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
for(int i = 0; i < kvNum; i++) {
|
||||
SKv kv;
|
||||
buf = taosDecodeSKv(buf, &kv);
|
||||
taosHashPut(pReq->info, kv.key, kv.keyLen, kv.value, kv.valueLen);
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
int tSerializeSClientHbBatchReq(void** buf, const SClientHbBatchReq* pReq) {
|
||||
int tlen = 0;
|
||||
return tlen;
|
||||
}
|
||||
|
||||
void* tDeserializeClientHbBatchReq(void* buf, SClientHbBatchReq* pReq) {
|
||||
return buf;
|
||||
}
|
||||
|
||||
int tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) {
|
||||
int tlen = 0;
|
||||
|
||||
|
@ -148,4 +251,4 @@ void *tSVCreateTbBatchReqDeserialize(void *buf, SVCreateTbBatchReq *pReq) {
|
|||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,9 +33,9 @@ typedef struct SBnode {
|
|||
int32_t dnodeId;
|
||||
int64_t clusterId;
|
||||
SBnodeCfg cfg;
|
||||
SendMsgToDnodeFp sendMsgToDnodeFp;
|
||||
SendMsgToMnodeFp sendMsgToMnodeFp;
|
||||
SendRedirectMsgFp sendRedirectMsgFp;
|
||||
SendReqToDnodeFp sendReqToDnodeFp;
|
||||
SendReqToMnodeFp sendReqToMnodeFp;
|
||||
SendRedirectRspFp sendRedirectRspFp;
|
||||
} SBnode;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -11,6 +11,7 @@ target_link_libraries(
|
|||
PUBLIC wal
|
||||
PUBLIC sync
|
||||
PUBLIC taos
|
||||
PUBLIC tfs
|
||||
)
|
||||
target_include_directories(
|
||||
dnode
|
||||
|
|
|
@ -80,20 +80,20 @@ typedef struct {
|
|||
} SDnodeDir;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
int32_t dropped;
|
||||
int64_t clusterId;
|
||||
int64_t rebootTime;
|
||||
int64_t updateTime;
|
||||
int8_t statusSent;
|
||||
SEpSet mnodeEpSet;
|
||||
char *file;
|
||||
SHashObj *dnodeHash;
|
||||
SDnodeEps *dnodeEps;
|
||||
pthread_t *threadId;
|
||||
SRWLatch latch;
|
||||
STaosQueue *pMgmtQ;
|
||||
SWorkerPool mgmtPool;
|
||||
int32_t dnodeId;
|
||||
int32_t dropped;
|
||||
int64_t clusterId;
|
||||
int64_t dver;
|
||||
int64_t rebootTime;
|
||||
int64_t updateTime;
|
||||
int8_t statusSent;
|
||||
SEpSet mnodeEpSet;
|
||||
char *file;
|
||||
SHashObj *dnodeHash;
|
||||
SDnodeEps *dnodeEps;
|
||||
pthread_t *threadId;
|
||||
SRWLatch latch;
|
||||
SDnodeWorker mgmtWorker;
|
||||
} SDnodeMgmt;
|
||||
|
||||
typedef struct {
|
||||
|
@ -167,7 +167,7 @@ typedef struct SDnode {
|
|||
SBnodeMgmt bmgmt;
|
||||
SVnodesMgmt vmgmt;
|
||||
STransMgmt tmgmt;
|
||||
SStartupMsg startup;
|
||||
SStartupReq startup;
|
||||
} SDnode;
|
||||
|
||||
EStat dndGetStat(SDnode *pDnode);
|
||||
|
@ -175,7 +175,7 @@ void dndSetStat(SDnode *pDnode, EStat stat);
|
|||
char *dndStatStr(EStat stat);
|
||||
|
||||
void dndReportStartup(SDnode *pDnode, char *pName, char *pDesc);
|
||||
void dndGetStartup(SDnode *pDnode, SStartupMsg *pStartup);
|
||||
void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -21,16 +21,17 @@ extern "C" {
|
|||
#endif
|
||||
#include "dndInt.h"
|
||||
|
||||
int32_t dndInitDnode(SDnode *pDnode);
|
||||
void dndCleanupDnode(SDnode *pDnode);
|
||||
int32_t dndInitMgmt(SDnode *pDnode);
|
||||
void dndStopMgmt(SDnode *pDnode);
|
||||
void dndCleanupMgmt(SDnode *pDnode);
|
||||
|
||||
int32_t dndGetDnodeId(SDnode *pDnode);
|
||||
int64_t dndGetClusterId(SDnode *pDnode);
|
||||
void dndGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort);
|
||||
void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet);
|
||||
|
||||
void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
void dndSendStatusMsg(SDnode *pDnode);
|
||||
void dndSendRedirectRsp(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
void dndSendStatusReq(SDnode *pDnode);
|
||||
void dndProcessMgmtMsg(SDnode *pDnode, SRpcMsg *pRpcMsg, SEpSet *pEpSet);
|
||||
void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
|
|
@ -23,8 +23,8 @@ extern "C" {
|
|||
|
||||
int32_t dndInitTrans(SDnode *pDnode);
|
||||
void dndCleanupTrans(SDnode *pDnode);
|
||||
void dndSendMsgToMnode(SDnode *pDnode, SRpcMsg *pRpcMsg);
|
||||
void dndSendMsgToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pRpcMsg);
|
||||
int32_t dndSendReqToMnode(SDnode *pDnode, SRpcMsg *pRpcMsg);
|
||||
int32_t dndSendReqToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pRpcMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -29,12 +29,12 @@ void dndProcessVnodeSyncMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
|||
void dndProcessVnodeQueryMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dndProcessVnodeFetchMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
|
||||
int32_t dndProcessCreateVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg);
|
||||
int32_t dndProcessAlterVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg);
|
||||
int32_t dndProcessDropVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg);
|
||||
int32_t dndProcessAuthVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg);
|
||||
int32_t dndProcessSyncVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg);
|
||||
int32_t dndProcessCompactVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg);
|
||||
int32_t dndProcessCreateVnodeReq(SDnode *pDnode, SRpcMsg *pReq);
|
||||
int32_t dndProcessAlterVnodeReq(SDnode *pDnode, SRpcMsg *pReq);
|
||||
int32_t dndProcessDropVnodeReq(SDnode *pDnode, SRpcMsg *pReq);
|
||||
int32_t dndProcessAuthVnodeReq(SDnode *pDnode, SRpcMsg *pReq);
|
||||
int32_t dndProcessSyncVnodeReq(SDnode *pDnode, SRpcMsg *pReq);
|
||||
int32_t dndProcessCompactVnodeReq(SDnode *pDnode, SRpcMsg *pReq);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndBnode.h"
|
||||
#include "dndDnode.h"
|
||||
#include "dndMgmt.h"
|
||||
#include "dndTransport.h"
|
||||
#include "dndWorker.h"
|
||||
|
||||
|
@ -27,7 +27,7 @@ static SBnode *dndAcquireBnode(SDnode *pDnode) {
|
|||
int32_t refCount = 0;
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
if (pMgmt->deployed && !pMgmt->dropped) {
|
||||
if (pMgmt->deployed && !pMgmt->dropped && pMgmt->pBnode != NULL) {
|
||||
refCount = atomic_add_fetch_32(&pMgmt->refCount, 1);
|
||||
pBnode = pMgmt->pBnode;
|
||||
} else {
|
||||
|
@ -42,25 +42,20 @@ static SBnode *dndAcquireBnode(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
static void dndReleaseBnode(SDnode *pDnode, SBnode *pBnode) {
|
||||
if (pBnode == NULL) return;
|
||||
|
||||
SBnodeMgmt *pMgmt = &pDnode->bmgmt;
|
||||
int32_t refCount = 0;
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
if (pBnode != NULL) {
|
||||
refCount = atomic_sub_fetch_32(&pMgmt->refCount, 1);
|
||||
}
|
||||
int32_t refCount = atomic_sub_fetch_32(&pMgmt->refCount, 1);
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
||||
if (pBnode != NULL) {
|
||||
dTrace("release bnode, refCount:%d", refCount);
|
||||
}
|
||||
dTrace("release bnode, refCount:%d", refCount);
|
||||
}
|
||||
|
||||
static int32_t dndReadBnodeFile(SDnode *pDnode) {
|
||||
SBnodeMgmt *pMgmt = &pDnode->bmgmt;
|
||||
int32_t code = TSDB_CODE_DND_BNODE_READ_FILE_ERROR;
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 4096;
|
||||
int32_t maxLen = 1024;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
cJSON *root = NULL;
|
||||
|
||||
|
@ -127,7 +122,7 @@ static int32_t dndWriteBnodeFile(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 4096;
|
||||
int32_t maxLen = 1024;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
|
@ -170,7 +165,7 @@ static void dndStopBnodeWorker(SDnode *pDnode) {
|
|||
pMgmt->deployed = 0;
|
||||
taosWUnLockLatch(&pMgmt->latch);
|
||||
|
||||
while (pMgmt->refCount > 1) {
|
||||
while (pMgmt->refCount > 0) {
|
||||
taosMsleep(10);
|
||||
}
|
||||
|
||||
|
@ -179,9 +174,9 @@ static void dndStopBnodeWorker(SDnode *pDnode) {
|
|||
|
||||
static void dndBuildBnodeOption(SDnode *pDnode, SBnodeOpt *pOption) {
|
||||
pOption->pDnode = pDnode;
|
||||
pOption->sendMsgToDnodeFp = dndSendMsgToDnode;
|
||||
pOption->sendMsgToMnodeFp = dndSendMsgToMnode;
|
||||
pOption->sendRedirectMsgFp = dndSendRedirectMsg;
|
||||
pOption->sendReqToDnodeFp = dndSendReqToDnode;
|
||||
pOption->sendReqToMnodeFp = dndSendReqToMnode;
|
||||
pOption->sendRedirectRspFp = dndSendRedirectRsp;
|
||||
pOption->dnodeId = dndGetDnodeId(pDnode);
|
||||
pOption->clusterId = dndGetClusterId(pDnode);
|
||||
pOption->cfg.sver = pDnode->opt.sver;
|
||||
|
@ -189,10 +184,18 @@ static void dndBuildBnodeOption(SDnode *pDnode, SBnodeOpt *pOption) {
|
|||
|
||||
static int32_t dndOpenBnode(SDnode *pDnode) {
|
||||
SBnodeMgmt *pMgmt = &pDnode->bmgmt;
|
||||
SBnodeOpt option = {0};
|
||||
SBnode *pBnode = dndAcquireBnode(pDnode);
|
||||
if (pBnode != NULL) {
|
||||
dndReleaseBnode(pDnode, pBnode);
|
||||
terrno = TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED;
|
||||
dError("failed to create bnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SBnodeOpt option = {0};
|
||||
dndBuildBnodeOption(pDnode, &option);
|
||||
|
||||
SBnode *pBnode = bndOpen(pDnode->dir.bnode, &option);
|
||||
pBnode = bndOpen(pDnode->dir.bnode, &option);
|
||||
if (pBnode == NULL) {
|
||||
dError("failed to open bnode since %s", terrstr());
|
||||
return -1;
|
||||
|
@ -256,11 +259,12 @@ static int32_t dndDropBnode(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
SDCreateBnodeMsg *pMsg = pRpcMsg->pCont;
|
||||
SDCreateBnodeReq *pMsg = pRpcMsg->pCont;
|
||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_BNODE_ID_INVALID;
|
||||
terrno = TSDB_CODE_DND_BNODE_INVALID_OPTION;
|
||||
dError("failed to create bnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
return dndOpenBnode(pDnode);
|
||||
|
@ -268,11 +272,12 @@ int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
|||
}
|
||||
|
||||
int32_t dndProcessDropBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
SDDropBnodeMsg *pMsg = pRpcMsg->pCont;
|
||||
SDDropBnodeReq *pMsg = pRpcMsg->pCont;
|
||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_BNODE_ID_INVALID;
|
||||
terrno = TSDB_CODE_DND_BNODE_INVALID_OPTION;
|
||||
dError("failed to drop bnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
return dndDropBnode(pDnode);
|
||||
|
|
|
@ -14,28 +14,25 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndDnode.h"
|
||||
#include "dndMgmt.h"
|
||||
#include "dndBnode.h"
|
||||
#include "dndMnode.h"
|
||||
#include "dndQnode.h"
|
||||
#include "dndSnode.h"
|
||||
#include "dndTransport.h"
|
||||
#include "dndVnodes.h"
|
||||
#include "dndWorker.h"
|
||||
|
||||
static int32_t dndInitMgmtWorker(SDnode *pDnode);
|
||||
static void dndCleanupMgmtWorker(SDnode *pDnode);
|
||||
static int32_t dndAllocMgmtQueue(SDnode *pDnode);
|
||||
static void dndFreeMgmtQueue(SDnode *pDnode);
|
||||
static void dndProcessMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
static void dndProcessMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
|
||||
static int32_t dndReadDnodes(SDnode *pDnode);
|
||||
static int32_t dndWriteDnodes(SDnode *pDnode);
|
||||
static void *dnodeThreadRoutine(void *param);
|
||||
|
||||
static int32_t dndProcessConfigDnodeReq(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
static void dndProcessAuthRsp(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
static void dndProcessGrantRsp(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
static int32_t dndProcessConfigDnodeReq(SDnode *pDnode, SRpcMsg *pReq);
|
||||
static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pRsp);
|
||||
static void dndProcessAuthRsp(SDnode *pDnode, SRpcMsg *pRsp);
|
||||
static void dndProcessGrantRsp(SDnode *pDnode, SRpcMsg *pRsp);
|
||||
|
||||
int32_t dndGetDnodeId(SDnode *pDnode) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
|
@ -80,13 +77,13 @@ void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) {
|
|||
taosRUnLockLatch(&pMgmt->latch);
|
||||
}
|
||||
|
||||
void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||
tmsg_t msgType = pMsg->msgType;
|
||||
void dndSendRedirectRsp(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
tmsg_t msgType = pReq->msgType;
|
||||
|
||||
SEpSet epSet = {0};
|
||||
dndGetMnodeEpSet(pDnode, &epSet);
|
||||
|
||||
dDebug("RPC %p, msg:%s is redirected, num:%d use:%d", pMsg->handle, TMSG_INFO(msgType), epSet.numOfEps, epSet.inUse);
|
||||
dDebug("RPC %p, req:%s is redirected, num:%d use:%d", pReq->handle, TMSG_INFO(msgType), epSet.numOfEps, epSet.inUse);
|
||||
for (int32_t i = 0; i < epSet.numOfEps; ++i) {
|
||||
dDebug("mnode index:%d %s:%u", i, epSet.fqdn[i], epSet.port[i]);
|
||||
if (strcmp(epSet.fqdn[i], pDnode->opt.localFqdn) == 0 && epSet.port[i] == pDnode->opt.serverPort) {
|
||||
|
@ -96,7 +93,7 @@ void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg) {
|
|||
epSet.port[i] = htons(epSet.port[i]);
|
||||
}
|
||||
|
||||
rpcSendRedirectRsp(pMsg->handle, &epSet);
|
||||
rpcSendRedirectRsp(pReq->handle, &epSet);
|
||||
}
|
||||
|
||||
static void dndUpdateMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) {
|
||||
|
@ -350,14 +347,14 @@ static int32_t dndWriteDnodes(SDnode *pDnode) {
|
|||
terrno = 0;
|
||||
|
||||
pMgmt->updateTime = taosGetTimestampMs();
|
||||
dInfo("successed to write %s", pMgmt->file);
|
||||
dDebug("successed to write %s", pMgmt->file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dndSendStatusMsg(SDnode *pDnode) {
|
||||
int32_t contLen = sizeof(SStatusMsg) + TSDB_MAX_VNODES * sizeof(SVnodeLoad);
|
||||
void dndSendStatusReq(SDnode *pDnode) {
|
||||
int32_t contLen = sizeof(SStatusReq) + TSDB_MAX_VNODES * sizeof(SVnodeLoad);
|
||||
|
||||
SStatusMsg *pStatus = rpcMallocCont(contLen);
|
||||
SStatusReq *pStatus = rpcMallocCont(contLen);
|
||||
if (pStatus == NULL) {
|
||||
dError("failed to malloc status message");
|
||||
return;
|
||||
|
@ -366,6 +363,7 @@ void dndSendStatusMsg(SDnode *pDnode) {
|
|||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
pStatus->sver = htonl(pDnode->opt.sver);
|
||||
pStatus->dver = htobe64(pMgmt->dver);
|
||||
pStatus->dnodeId = htonl(pMgmt->dnodeId);
|
||||
pStatus->clusterId = htobe64(pMgmt->clusterId);
|
||||
pStatus->rebootTime = htobe64(pMgmt->rebootTime);
|
||||
|
@ -385,13 +383,13 @@ void dndSendStatusMsg(SDnode *pDnode) {
|
|||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
||||
dndGetVnodeLoads(pDnode, &pStatus->vnodeLoads);
|
||||
contLen = sizeof(SStatusMsg) + pStatus->vnodeLoads.num * sizeof(SVnodeLoad);
|
||||
contLen = sizeof(SStatusReq) + pStatus->vnodeLoads.num * sizeof(SVnodeLoad);
|
||||
|
||||
SRpcMsg rpcMsg = {.pCont = pStatus, .contLen = contLen, .msgType = TDMT_MND_STATUS, .ahandle = (void *)9527};
|
||||
pMgmt->statusSent = 1;
|
||||
|
||||
dTrace("pDnode:%p, send status msg to mnode", pDnode);
|
||||
dndSendMsgToMnode(pDnode, &rpcMsg);
|
||||
dTrace("pDnode:%p, send status req to mnode", pDnode);
|
||||
dndSendReqToMnode(pDnode, &rpcMsg);
|
||||
}
|
||||
|
||||
static void dndUpdateDnodeCfg(SDnode *pDnode, SDnodeCfg *pCfg) {
|
||||
|
@ -426,12 +424,12 @@ static void dndUpdateDnodeEps(SDnode *pDnode, SDnodeEps *pDnodeEps) {
|
|||
taosWUnLockLatch(&pMgmt->latch);
|
||||
}
|
||||
|
||||
static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||
static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pRsp) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
|
||||
if (pMsg->code != TSDB_CODE_SUCCESS) {
|
||||
if (pRsp->code != TSDB_CODE_SUCCESS) {
|
||||
pMgmt->statusSent = 0;
|
||||
if (pMsg->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pMgmt->dropped && pMgmt->dnodeId > 0) {
|
||||
if (pRsp->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pMgmt->dropped && pMgmt->dnodeId > 0) {
|
||||
dInfo("dnode:%d, set to dropped since not exist in mnode", pMgmt->dnodeId);
|
||||
pMgmt->dropped = 1;
|
||||
dndWriteDnodes(pDnode);
|
||||
|
@ -439,14 +437,16 @@ static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg) {
|
|||
return;
|
||||
}
|
||||
|
||||
SStatusRsp *pRsp = pMsg->pCont;
|
||||
if (pMsg->pCont != NULL && pMsg->contLen != 0) {
|
||||
SDnodeCfg *pCfg = &pRsp->dnodeCfg;
|
||||
if (pRsp->pCont != NULL && pRsp->contLen != 0) {
|
||||
SStatusRsp *pStatus = pRsp->pCont;
|
||||
pMgmt->dver = htobe64(pStatus->dver);
|
||||
|
||||
SDnodeCfg *pCfg = &pStatus->dnodeCfg;
|
||||
pCfg->dnodeId = htonl(pCfg->dnodeId);
|
||||
pCfg->clusterId = htobe64(pCfg->clusterId);
|
||||
dndUpdateDnodeCfg(pDnode, pCfg);
|
||||
|
||||
SDnodeEps *pDnodeEps = &pRsp->dnodeEps;
|
||||
SDnodeEps *pDnodeEps = &pStatus->dnodeEps;
|
||||
pDnodeEps->num = htonl(pDnodeEps->num);
|
||||
for (int32_t i = 0; i < pDnodeEps->num; ++i) {
|
||||
pDnodeEps->eps[i].id = htonl(pDnodeEps->eps[i].id);
|
||||
|
@ -458,26 +458,27 @@ static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg) {
|
|||
pMgmt->statusSent = 0;
|
||||
}
|
||||
|
||||
static void dndProcessAuthRsp(SDnode *pDnode, SRpcMsg *pMsg) { assert(1); }
|
||||
static void dndProcessAuthRsp(SDnode *pDnode, SRpcMsg *pReq) { dError("auth rsp is received, but not supported yet"); }
|
||||
|
||||
static void dndProcessGrantRsp(SDnode *pDnode, SRpcMsg *pMsg) { assert(1); }
|
||||
|
||||
static int32_t dndProcessConfigDnodeReq(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||
dError("config msg is received, but not supported yet");
|
||||
SCfgDnodeMsg *pCfg = pMsg->pCont;
|
||||
static void dndProcessGrantRsp(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
dError("grant rsp is received, but not supported yet");
|
||||
}
|
||||
|
||||
static int32_t dndProcessConfigDnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
dError("config req is received, but not supported yet");
|
||||
SDCfgDnodeReq *pCfg = pReq->pCont;
|
||||
return TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||
dDebug("startup msg is received");
|
||||
void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
dDebug("startup req is received");
|
||||
|
||||
SStartupMsg *pStartup = rpcMallocCont(sizeof(SStartupMsg));
|
||||
SStartupReq *pStartup = rpcMallocCont(sizeof(SStartupReq));
|
||||
dndGetStartup(pDnode, pStartup);
|
||||
|
||||
dDebug("startup msg is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished);
|
||||
dDebug("startup req is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished);
|
||||
|
||||
SRpcMsg rpcRsp = {.handle = pMsg->handle, .pCont = pStartup, .contLen = sizeof(SStartupMsg)};
|
||||
SRpcMsg rpcRsp = {.handle = pReq->handle, .pCont = pStartup, .contLen = sizeof(SStartupReq)};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
}
|
||||
|
||||
|
@ -491,12 +492,12 @@ static void *dnodeThreadRoutine(void *param) {
|
|||
taosMsleep(ms);
|
||||
|
||||
if (dndGetStat(pDnode) == DND_STAT_RUNNING && !pMgmt->statusSent && !pMgmt->dropped) {
|
||||
dndSendStatusMsg(pDnode);
|
||||
dndSendStatusReq(pDnode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t dndInitDnode(SDnode *pDnode) {
|
||||
int32_t dndInitMgmt(SDnode *pDnode) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
|
||||
pMgmt->dnodeId = 0;
|
||||
|
@ -530,13 +531,8 @@ int32_t dndInitDnode(SDnode *pDnode) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (dndInitMgmtWorker(pDnode) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndAllocMgmtQueue(pDnode) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
if (dndInitWorker(pDnode, &pMgmt->mgmtWorker, DND_WORKER_SINGLE, "dnode-mgmt", 1, 1, dndProcessMgmtQueue) != 0) {
|
||||
dError("failed to start dnode mgmt worker since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -547,21 +543,22 @@ int32_t dndInitDnode(SDnode *pDnode) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
dInfo("dnode-dnode is initialized");
|
||||
dInfo("dnode-mgmt is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dndCleanupDnode(SDnode *pDnode) {
|
||||
void dndStopMgmt(SDnode *pDnode) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
|
||||
dndCleanupMgmtWorker(pDnode);
|
||||
dndFreeMgmtQueue(pDnode);
|
||||
dndCleanupWorker(&pMgmt->mgmtWorker);
|
||||
|
||||
if (pMgmt->threadId != NULL) {
|
||||
taosDestoryThread(pMgmt->threadId);
|
||||
pMgmt->threadId = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void dndCleanupMgmt(SDnode *pDnode) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
taosWLockLatch(&pMgmt->latch);
|
||||
|
||||
if (pMgmt->dnodeEps != NULL) {
|
||||
|
@ -580,62 +577,22 @@ void dndCleanupDnode(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
taosWUnLockLatch(&pMgmt->latch);
|
||||
dInfo("dnode-dnode is cleaned up");
|
||||
dInfo("dnode-mgmt is cleaned up");
|
||||
}
|
||||
|
||||
static int32_t dndInitMgmtWorker(SDnode *pDnode) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
SWorkerPool *pPool = &pMgmt->mgmtPool;
|
||||
pPool->name = "dnode-mgmt";
|
||||
pPool->min = 1;
|
||||
pPool->max = 1;
|
||||
if (tWorkerInit(pPool) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("dnode mgmt worker is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndCleanupMgmtWorker(SDnode *pDnode) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
tWorkerCleanup(&pMgmt->mgmtPool);
|
||||
dDebug("dnode mgmt worker is closed");
|
||||
}
|
||||
|
||||
static int32_t dndAllocMgmtQueue(SDnode *pDnode) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
pMgmt->pMgmtQ = tWorkerAllocQueue(&pMgmt->mgmtPool, pDnode, (FProcessItem)dndProcessMgmtQueue);
|
||||
if (pMgmt->pMgmtQ == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndFreeMgmtQueue(SDnode *pDnode) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
tWorkerFreeQueue(&pMgmt->mgmtPool, pMgmt->pMgmtQ);
|
||||
pMgmt->pMgmtQ = NULL;
|
||||
}
|
||||
|
||||
void dndProcessMgmtMsg(SDnode *pDnode, SRpcMsg *pRpcMsg, SEpSet *pEpSet) {
|
||||
void dndProcessMgmtMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
SDnodeMgmt *pMgmt = &pDnode->dmgmt;
|
||||
|
||||
if (pEpSet && pEpSet->numOfEps > 0 && pRpcMsg->msgType == TDMT_MND_STATUS_RSP) {
|
||||
if (pEpSet && pEpSet->numOfEps > 0 && pMsg->msgType == TDMT_MND_STATUS_RSP) {
|
||||
dndUpdateMnodeEpSet(pDnode, pEpSet);
|
||||
}
|
||||
|
||||
SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg));
|
||||
if (pMsg != NULL) *pMsg = *pRpcMsg;
|
||||
|
||||
if (pMsg == NULL || taosWriteQitem(pMgmt->pMgmtQ, pMsg) != 0) {
|
||||
if (pRpcMsg->msgType & 1u) {
|
||||
SRpcMsg rsp = {.handle = pRpcMsg->handle, .code = TSDB_CODE_OUT_OF_MEMORY};
|
||||
if (dndWriteMsgToWorker(&pMgmt->mgmtWorker, pMsg, sizeof(SRpcMsg)) != 0) {
|
||||
if (pMsg->msgType & 1u) {
|
||||
SRpcMsg rsp = {.handle = pMsg->handle, .code = TSDB_CODE_OUT_OF_MEMORY};
|
||||
rpcSendResponse(&rsp);
|
||||
}
|
||||
rpcFreeCont(pRpcMsg->pCont);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
}
|
||||
|
@ -704,7 +661,7 @@ static void dndProcessMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg) {
|
|||
default:
|
||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
code = -1;
|
||||
dError("RPC %p, dnode req:%s not processed", pMsg->handle, TMSG_INFO(pMsg->msgType));
|
||||
dError("RPC %p, dnode msg:%s not processed", pMsg->handle, TMSG_INFO(pMsg->msgType));
|
||||
break;
|
||||
}
|
||||
|
|
@ -15,10 +15,11 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndMnode.h"
|
||||
#include "dndDnode.h"
|
||||
#include "dndMgmt.h"
|
||||
#include "dndTransport.h"
|
||||
#include "dndWorker.h"
|
||||
|
||||
static void dndWriteMnodeMsgToWorker(SDnode *pDnode, SDnodeWorker *pWorker, SRpcMsg *pRpcMsg);
|
||||
static void dndProcessMnodeQueue(SDnode *pDnode, SMnodeMsg *pMsg);
|
||||
|
||||
static SMnode *dndAcquireMnode(SDnode *pDnode) {
|
||||
|
@ -42,18 +43,13 @@ static SMnode *dndAcquireMnode(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
static void dndReleaseMnode(SDnode *pDnode, SMnode *pMnode) {
|
||||
if (pMnode == NULL) return;
|
||||
|
||||
SMnodeMgmt *pMgmt = &pDnode->mmgmt;
|
||||
int32_t refCount = 0;
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
if (pMnode != NULL) {
|
||||
refCount = atomic_sub_fetch_32(&pMgmt->refCount, 1);
|
||||
}
|
||||
int32_t refCount = atomic_sub_fetch_32(&pMgmt->refCount, 1);
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
||||
if (pMnode != NULL) {
|
||||
dTrace("release mnode, refCount:%d", refCount);
|
||||
}
|
||||
dTrace("release mnode, refCount:%d", refCount);
|
||||
}
|
||||
|
||||
static int32_t dndReadMnodeFile(SDnode *pDnode) {
|
||||
|
@ -258,11 +254,16 @@ static bool dndNeedDeployMnode(SDnode *pDnode) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static int32_t dndPutMsgToMWriteQ(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
dndWriteMnodeMsgToWorker(pDnode, &pDnode->mmgmt.writeWorker, pRpcMsg);
|
||||
}
|
||||
|
||||
static void dndInitMnodeOption(SDnode *pDnode, SMnodeOpt *pOption) {
|
||||
pOption->pDnode = pDnode;
|
||||
pOption->sendMsgToDnodeFp = dndSendMsgToDnode;
|
||||
pOption->sendMsgToMnodeFp = dndSendMsgToMnode;
|
||||
pOption->sendRedirectMsgFp = dndSendRedirectMsg;
|
||||
pOption->sendReqToDnodeFp = dndSendReqToDnode;
|
||||
pOption->sendReqToMnodeFp = dndSendReqToMnode;
|
||||
pOption->sendRedirectRspFp = dndSendRedirectRsp;
|
||||
pOption->putReqToMWriteQFp = dndPutMsgToMWriteQ;
|
||||
pOption->dnodeId = dndGetDnodeId(pDnode);
|
||||
pOption->clusterId = dndGetClusterId(pDnode);
|
||||
pOption->cfg.sver = pDnode->opt.sver;
|
||||
|
@ -299,25 +300,24 @@ static void dndBuildMnodeOpenOption(SDnode *pDnode, SMnodeOpt *pOption) {
|
|||
memcpy(&pOption->replicas, pMgmt->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA);
|
||||
}
|
||||
|
||||
static int32_t dndBuildMnodeOptionFromMsg(SDnode *pDnode, SMnodeOpt *pOption, SDCreateMnodeMsg *pMsg) {
|
||||
static int32_t dndBuildMnodeOptionFromReq(SDnode *pDnode, SMnodeOpt *pOption, SDCreateMnodeReq *pCreate) {
|
||||
dndInitMnodeOption(pDnode, pOption);
|
||||
pOption->dnodeId = dndGetDnodeId(pDnode);
|
||||
pOption->clusterId = dndGetClusterId(pDnode);
|
||||
|
||||
pOption->replica = pMsg->replica;
|
||||
pOption->replica = pCreate->replica;
|
||||
pOption->selfIndex = -1;
|
||||
for (int32_t i = 0; i < pMsg->replica; ++i) {
|
||||
for (int32_t i = 0; i < pCreate->replica; ++i) {
|
||||
SReplica *pReplica = &pOption->replicas[i];
|
||||
pReplica->id = pMsg->replicas[i].id;
|
||||
pReplica->port = pMsg->replicas[i].port;
|
||||
memcpy(pReplica->fqdn, pMsg->replicas[i].fqdn, TSDB_FQDN_LEN);
|
||||
pReplica->id = pCreate->replicas[i].id;
|
||||
pReplica->port = pCreate->replicas[i].port;
|
||||
memcpy(pReplica->fqdn, pCreate->replicas[i].fqdn, TSDB_FQDN_LEN);
|
||||
if (pReplica->id == pOption->dnodeId) {
|
||||
pOption->selfIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (pOption->selfIndex == -1) {
|
||||
terrno = TSDB_CODE_DND_MNODE_ID_NOT_FOUND;
|
||||
dError("failed to build mnode options since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
@ -417,63 +417,97 @@ static int32_t dndDropMnode(SDnode *pDnode) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static SDCreateMnodeMsg *dndParseCreateMnodeMsg(SRpcMsg *pRpcMsg) {
|
||||
SDCreateMnodeMsg *pMsg = pRpcMsg->pCont;
|
||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
for (int32_t i = 0; i < pMsg->replica; ++i) {
|
||||
pMsg->replicas[i].id = htonl(pMsg->replicas[i].id);
|
||||
pMsg->replicas[i].port = htons(pMsg->replicas[i].port);
|
||||
static SDCreateMnodeReq *dndParseCreateMnodeReq(SRpcMsg *pReq) {
|
||||
SDCreateMnodeReq *pCreate = pReq->pCont;
|
||||
pCreate->dnodeId = htonl(pCreate->dnodeId);
|
||||
for (int32_t i = 0; i < pCreate->replica; ++i) {
|
||||
pCreate->replicas[i].id = htonl(pCreate->replicas[i].id);
|
||||
pCreate->replicas[i].port = htons(pCreate->replicas[i].port);
|
||||
}
|
||||
|
||||
return pMsg;
|
||||
return pCreate;
|
||||
}
|
||||
|
||||
int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
SDCreateMnodeMsg *pMsg = dndParseCreateMnodeMsg(pRpcMsg);
|
||||
int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
SDCreateMnodeReq *pCreate = dndParseCreateMnodeReq(pReq);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_MNODE_ID_INVALID;
|
||||
return -1;
|
||||
} else {
|
||||
SMnodeOpt option = {0};
|
||||
if (dndBuildMnodeOptionFromMsg(pDnode, &option, pMsg) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return dndOpenMnode(pDnode, &option);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t dndProcessAlterMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
SDAlterMnodeMsg *pMsg = dndParseCreateMnodeMsg(pRpcMsg);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_MNODE_ID_INVALID;
|
||||
if (pCreate->replica <= 1 || pCreate->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_MNODE_INVALID_OPTION;
|
||||
dError("failed to create mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SMnodeOpt option = {0};
|
||||
if (dndBuildMnodeOptionFromMsg(pDnode, &option, pMsg) != 0) {
|
||||
if (dndBuildMnodeOptionFromReq(pDnode, &option, pCreate) != 0) {
|
||||
terrno = TSDB_CODE_DND_MNODE_INVALID_OPTION;
|
||||
dError("failed to create mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndAlterMnode(pDnode, &option) != 0) {
|
||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||
if (pMnode != NULL) {
|
||||
dndReleaseMnode(pDnode, pMnode);
|
||||
terrno = TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED;
|
||||
dError("failed to create mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return dndWriteMnodeFile(pDnode);
|
||||
dDebug("start to create mnode");
|
||||
return dndOpenMnode(pDnode, &option);
|
||||
}
|
||||
|
||||
int32_t dndProcessDropMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
SDDropMnodeMsg *pMsg = pRpcMsg->pCont;
|
||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
int32_t dndProcessAlterMnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
SDAlterMnodeReq *pAlter = dndParseCreateMnodeReq(pReq);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_MNODE_ID_INVALID;
|
||||
if (pAlter->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_MNODE_INVALID_OPTION;
|
||||
dError("failed to alter mnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
return dndDropMnode(pDnode);
|
||||
}
|
||||
|
||||
SMnodeOpt option = {0};
|
||||
if (dndBuildMnodeOptionFromReq(pDnode, &option, pAlter) != 0) {
|
||||
terrno = TSDB_CODE_DND_MNODE_INVALID_OPTION;
|
||||
dError("failed to alter mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||
if (pMnode == NULL) {
|
||||
terrno = TSDB_CODE_DND_MNODE_NOT_DEPLOYED;
|
||||
dError("failed to alter mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("start to alter mnode");
|
||||
int32_t code = dndAlterMnode(pDnode, &option);
|
||||
dndReleaseMnode(pDnode, pMnode);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t dndProcessDropMnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
SDDropMnodeReq *pDrop = pReq->pCont;
|
||||
pDrop->dnodeId = htonl(pDrop->dnodeId);
|
||||
|
||||
if (pDrop->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_MNODE_INVALID_OPTION;
|
||||
dError("failed to drop mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SMnode *pMnode = dndAcquireMnode(pDnode);
|
||||
if (pMnode == NULL) {
|
||||
terrno = TSDB_CODE_DND_MNODE_NOT_DEPLOYED;
|
||||
dError("failed to drop mnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("start to drop mnode");
|
||||
int32_t code = dndDropMnode(pDnode);
|
||||
dndReleaseMnode(pDnode, pMnode);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static void dndProcessMnodeQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
|
||||
|
@ -500,6 +534,7 @@ static void dndWriteMnodeMsgToWorker(SDnode *pDnode, SDnodeWorker *pWorker, SRpc
|
|||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
} else {
|
||||
code = dndWriteMsgToWorker(pWorker, pMsg, 0);
|
||||
if (code != 0) code = terrno;
|
||||
}
|
||||
|
||||
if (code != 0) {
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndQnode.h"
|
||||
#include "dndDnode.h"
|
||||
#include "dndMgmt.h"
|
||||
#include "dndTransport.h"
|
||||
#include "dndWorker.h"
|
||||
|
||||
|
@ -27,7 +27,7 @@ static SQnode *dndAcquireQnode(SDnode *pDnode) {
|
|||
int32_t refCount = 0;
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
if (pMgmt->deployed && !pMgmt->dropped) {
|
||||
if (pMgmt->deployed && !pMgmt->dropped && pMgmt->pQnode != NULL) {
|
||||
refCount = atomic_add_fetch_32(&pMgmt->refCount, 1);
|
||||
pQnode = pMgmt->pQnode;
|
||||
} else {
|
||||
|
@ -42,25 +42,20 @@ static SQnode *dndAcquireQnode(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
static void dndReleaseQnode(SDnode *pDnode, SQnode *pQnode) {
|
||||
if (pQnode == NULL) return;
|
||||
|
||||
SQnodeMgmt *pMgmt = &pDnode->qmgmt;
|
||||
int32_t refCount = 0;
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
if (pQnode != NULL) {
|
||||
refCount = atomic_sub_fetch_32(&pMgmt->refCount, 1);
|
||||
}
|
||||
int32_t refCount = atomic_sub_fetch_32(&pMgmt->refCount, 1);
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
||||
if (pQnode != NULL) {
|
||||
dTrace("release qnode, refCount:%d", refCount);
|
||||
}
|
||||
dTrace("release qnode, refCount:%d", refCount);
|
||||
}
|
||||
|
||||
static int32_t dndReadQnodeFile(SDnode *pDnode) {
|
||||
SQnodeMgmt *pMgmt = &pDnode->qmgmt;
|
||||
int32_t code = TSDB_CODE_DND_QNODE_READ_FILE_ERROR;
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 4096;
|
||||
int32_t maxLen = 1024;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
cJSON *root = NULL;
|
||||
|
||||
|
@ -127,7 +122,7 @@ static int32_t dndWriteQnodeFile(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 4096;
|
||||
int32_t maxLen = 1024;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
|
@ -175,7 +170,7 @@ static void dndStopQnodeWorker(SDnode *pDnode) {
|
|||
pMgmt->deployed = 0;
|
||||
taosWUnLockLatch(&pMgmt->latch);
|
||||
|
||||
while (pMgmt->refCount > 1) {
|
||||
while (pMgmt->refCount > 0) {
|
||||
taosMsleep(10);
|
||||
}
|
||||
|
||||
|
@ -185,9 +180,9 @@ static void dndStopQnodeWorker(SDnode *pDnode) {
|
|||
|
||||
static void dndBuildQnodeOption(SDnode *pDnode, SQnodeOpt *pOption) {
|
||||
pOption->pDnode = pDnode;
|
||||
pOption->sendMsgToDnodeFp = dndSendMsgToDnode;
|
||||
pOption->sendMsgToMnodeFp = dndSendMsgToMnode;
|
||||
pOption->sendRedirectMsgFp = dndSendRedirectMsg;
|
||||
pOption->sendReqToDnodeFp = dndSendReqToDnode;
|
||||
pOption->sendReqToMnodeFp = dndSendReqToMnode;
|
||||
pOption->sendRedirectRspFp = dndSendRedirectRsp;
|
||||
pOption->dnodeId = dndGetDnodeId(pDnode);
|
||||
pOption->clusterId = dndGetClusterId(pDnode);
|
||||
pOption->cfg.sver = pDnode->opt.sver;
|
||||
|
@ -195,10 +190,19 @@ static void dndBuildQnodeOption(SDnode *pDnode, SQnodeOpt *pOption) {
|
|||
|
||||
static int32_t dndOpenQnode(SDnode *pDnode) {
|
||||
SQnodeMgmt *pMgmt = &pDnode->qmgmt;
|
||||
SQnodeOpt option = {0};
|
||||
|
||||
SQnode *pQnode = dndAcquireQnode(pDnode);
|
||||
if (pQnode != NULL) {
|
||||
dndReleaseQnode(pDnode, pQnode);
|
||||
terrno = TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED;
|
||||
dError("failed to create qnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SQnodeOpt option = {0};
|
||||
dndBuildQnodeOption(pDnode, &option);
|
||||
|
||||
SQnode *pQnode = qndOpen(&option);
|
||||
pQnode = qndOpen(&option);
|
||||
if (pQnode == NULL) {
|
||||
dError("failed to open qnode since %s", terrstr());
|
||||
return -1;
|
||||
|
@ -261,11 +265,12 @@ static int32_t dndDropQnode(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
SDCreateQnodeMsg *pMsg = pRpcMsg->pCont;
|
||||
SDCreateQnodeReq *pMsg = pRpcMsg->pCont;
|
||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_QNODE_ID_INVALID;
|
||||
terrno = TSDB_CODE_DND_QNODE_INVALID_OPTION;
|
||||
dError("failed to create qnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
return dndOpenQnode(pDnode);
|
||||
|
@ -273,11 +278,12 @@ int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
|||
}
|
||||
|
||||
int32_t dndProcessDropQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
SDDropQnodeMsg *pMsg = pRpcMsg->pCont;
|
||||
SDDropQnodeReq *pMsg = pRpcMsg->pCont;
|
||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_QNODE_ID_INVALID;
|
||||
terrno = TSDB_CODE_DND_QNODE_INVALID_OPTION;
|
||||
dError("failed to drop qnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
return dndDropQnode(pDnode);
|
||||
|
@ -293,15 +299,18 @@ static void dndProcessQnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) {
|
|||
if (pQnode != NULL) {
|
||||
code = qndProcessMsg(pQnode, pMsg, &pRsp);
|
||||
}
|
||||
dndReleaseQnode(pDnode, pQnode);
|
||||
|
||||
if (pRsp != NULL) {
|
||||
pRsp->ahandle = pMsg->ahandle;
|
||||
rpcSendResponse(pRsp);
|
||||
free(pRsp);
|
||||
} else {
|
||||
if (code != 0) code = terrno;
|
||||
SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
if (pMsg->msgType & 1u) {
|
||||
if (pRsp != NULL) {
|
||||
pRsp->ahandle = pMsg->ahandle;
|
||||
rpcSendResponse(pRsp);
|
||||
free(pRsp);
|
||||
} else {
|
||||
if (code != 0) code = terrno;
|
||||
SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
}
|
||||
}
|
||||
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndSnode.h"
|
||||
#include "dndDnode.h"
|
||||
#include "dndMgmt.h"
|
||||
#include "dndTransport.h"
|
||||
#include "dndWorker.h"
|
||||
|
||||
|
@ -27,7 +27,7 @@ static SSnode *dndAcquireSnode(SDnode *pDnode) {
|
|||
int32_t refCount = 0;
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
if (pMgmt->deployed && !pMgmt->dropped) {
|
||||
if (pMgmt->deployed && !pMgmt->dropped && pMgmt->pSnode != NULL) {
|
||||
refCount = atomic_add_fetch_32(&pMgmt->refCount, 1);
|
||||
pSnode = pMgmt->pSnode;
|
||||
} else {
|
||||
|
@ -42,25 +42,20 @@ static SSnode *dndAcquireSnode(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
static void dndReleaseSnode(SDnode *pDnode, SSnode *pSnode) {
|
||||
if (pSnode == NULL) return;
|
||||
|
||||
SSnodeMgmt *pMgmt = &pDnode->smgmt;
|
||||
int32_t refCount = 0;
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
if (pSnode != NULL) {
|
||||
refCount = atomic_sub_fetch_32(&pMgmt->refCount, 1);
|
||||
}
|
||||
int32_t refCount = atomic_sub_fetch_32(&pMgmt->refCount, 1);
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
||||
if (pSnode != NULL) {
|
||||
dTrace("release snode, refCount:%d", refCount);
|
||||
}
|
||||
dTrace("release snode, refCount:%d", refCount);
|
||||
}
|
||||
|
||||
static int32_t dndReadSnodeFile(SDnode *pDnode) {
|
||||
SSnodeMgmt *pMgmt = &pDnode->smgmt;
|
||||
int32_t code = TSDB_CODE_DND_SNODE_READ_FILE_ERROR;
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 4096;
|
||||
int32_t maxLen = 1024;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
cJSON *root = NULL;
|
||||
|
||||
|
@ -127,7 +122,7 @@ static int32_t dndWriteSnodeFile(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 4096;
|
||||
int32_t maxLen = 1024;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
|
@ -170,18 +165,18 @@ static void dndStopSnodeWorker(SDnode *pDnode) {
|
|||
pMgmt->deployed = 0;
|
||||
taosWUnLockLatch(&pMgmt->latch);
|
||||
|
||||
while (pMgmt->refCount > 1) {
|
||||
while (pMgmt->refCount > 0) {
|
||||
taosMsleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
dndCleanupWorker(&pMgmt->writeWorker);
|
||||
}
|
||||
|
||||
static void dndBuildSnodeOption(SDnode *pDnode, SSnodeOpt *pOption) {
|
||||
pOption->pDnode = pDnode;
|
||||
pOption->sendMsgToDnodeFp = dndSendMsgToDnode;
|
||||
pOption->sendMsgToMnodeFp = dndSendMsgToMnode;
|
||||
pOption->sendRedirectMsgFp = dndSendRedirectMsg;
|
||||
pOption->sendReqToDnodeFp = dndSendReqToDnode;
|
||||
pOption->sendReqToMnodeFp = dndSendReqToMnode;
|
||||
pOption->sendRedirectRspFp = dndSendRedirectRsp;
|
||||
pOption->dnodeId = dndGetDnodeId(pDnode);
|
||||
pOption->clusterId = dndGetClusterId(pDnode);
|
||||
pOption->cfg.sver = pDnode->opt.sver;
|
||||
|
@ -189,10 +184,18 @@ static void dndBuildSnodeOption(SDnode *pDnode, SSnodeOpt *pOption) {
|
|||
|
||||
static int32_t dndOpenSnode(SDnode *pDnode) {
|
||||
SSnodeMgmt *pMgmt = &pDnode->smgmt;
|
||||
SSnodeOpt option = {0};
|
||||
SSnode *pSnode = dndAcquireSnode(pDnode);
|
||||
if (pSnode != NULL) {
|
||||
dndReleaseSnode(pDnode, pSnode);
|
||||
terrno = TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED;
|
||||
dError("failed to create snode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SSnodeOpt option = {0};
|
||||
dndBuildSnodeOption(pDnode, &option);
|
||||
|
||||
SSnode *pSnode = sndOpen(pDnode->dir.snode, &option);
|
||||
pSnode = sndOpen(pDnode->dir.snode, &option);
|
||||
if (pSnode == NULL) {
|
||||
dError("failed to open snode since %s", terrstr());
|
||||
return -1;
|
||||
|
@ -256,11 +259,12 @@ static int32_t dndDropSnode(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
SDCreateSnodeMsg *pMsg = pRpcMsg->pCont;
|
||||
SDCreateSnodeReq *pMsg = pRpcMsg->pCont;
|
||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_SNODE_ID_INVALID;
|
||||
terrno = TSDB_CODE_DND_SNODE_INVALID_OPTION;
|
||||
dError("failed to create snode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
return dndOpenSnode(pDnode);
|
||||
|
@ -268,11 +272,12 @@ int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
|||
}
|
||||
|
||||
int32_t dndProcessDropSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
SDDropSnodeMsg *pMsg = pRpcMsg->pCont;
|
||||
SDDropSnodeReq *pMsg = pRpcMsg->pCont;
|
||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_SNODE_ID_INVALID;
|
||||
terrno = TSDB_CODE_DND_SNODE_INVALID_OPTION;
|
||||
dError("failed to drop snode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
return dndDropSnode(pDnode);
|
||||
|
@ -288,15 +293,18 @@ static void dndProcessSnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) {
|
|||
if (pSnode != NULL) {
|
||||
code = sndProcessMsg(pSnode, pMsg, &pRsp);
|
||||
}
|
||||
dndReleaseSnode(pDnode, pSnode);
|
||||
|
||||
if (pRsp != NULL) {
|
||||
pRsp->ahandle = pMsg->ahandle;
|
||||
rpcSendResponse(pRsp);
|
||||
free(pRsp);
|
||||
} else {
|
||||
if (code != 0) code = terrno;
|
||||
SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
if (pMsg->msgType & 1u) {
|
||||
if (pRsp != NULL) {
|
||||
pRsp->ahandle = pMsg->ahandle;
|
||||
rpcSendResponse(pRsp);
|
||||
free(pRsp);
|
||||
} else {
|
||||
if (code != 0) code = terrno;
|
||||
SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
}
|
||||
}
|
||||
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndTransport.h"
|
||||
#include "dndDnode.h"
|
||||
#include "dndMgmt.h"
|
||||
#include "dndMnode.h"
|
||||
#include "dndVnodes.h"
|
||||
|
||||
|
@ -105,8 +105,6 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
|
|||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_SHOW_RETRIEVE)] = dndProcessMnodeReadMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_STATUS)] = dndProcessMnodeReadMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_STATUS_RSP)] = dndProcessMgmtMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_TRANS)] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_TRANS_RSP)] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_GRANT)] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_GRANT_RSP)] = dndProcessMgmtMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_AUTH)] = dndProcessMnodeReadMsg;
|
||||
|
@ -145,26 +143,26 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
|
|||
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 *pRsp, SEpSet *pEpSet) {
|
||||
SDnode *pDnode = parent;
|
||||
STransMgmt *pMgmt = &pDnode->tmgmt;
|
||||
|
||||
tmsg_t msgType = pMsg->msgType;
|
||||
tmsg_t msgType = pRsp->msgType;
|
||||
|
||||
if (dndGetStat(pDnode) == DND_STAT_STOPPED) {
|
||||
if (pMsg == NULL || pMsg->pCont == NULL) return;
|
||||
dTrace("RPC %p, rsp:%s is ignored since dnode is stopping", pMsg->handle, TMSG_INFO(msgType));
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
if (pRsp == NULL || pRsp->pCont == NULL) return;
|
||||
dTrace("RPC %p, rsp:%s is ignored since dnode is stopping", pRsp->handle, TMSG_INFO(msgType));
|
||||
rpcFreeCont(pRsp->pCont);
|
||||
return;
|
||||
}
|
||||
|
||||
DndMsgFp fp = pMgmt->msgFp[TMSG_INDEX(msgType)];
|
||||
if (fp != NULL) {
|
||||
dTrace("RPC %p, rsp:%s will be processed, code:0x%x", pMsg->handle, TMSG_INFO(msgType), pMsg->code & 0XFFFF);
|
||||
(*fp)(pDnode, pMsg, pEpSet);
|
||||
dTrace("RPC %p, rsp:%s will be processed, code:0x%x", pRsp->handle, TMSG_INFO(msgType), pRsp->code & 0XFFFF);
|
||||
(*fp)(pDnode, pRsp, pEpSet);
|
||||
} else {
|
||||
dError("RPC %p, rsp:%s not processed", pMsg->handle, TMSG_INFO(msgType));
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
dError("RPC %p, rsp:%s not processed", pRsp->handle, TMSG_INFO(msgType));
|
||||
rpcFreeCont(pRsp->pCont);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -203,48 +201,48 @@ static void dndCleanupClient(SDnode *pDnode) {
|
|||
}
|
||||
}
|
||||
|
||||
static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
static void dndProcessRequest(void *param, SRpcMsg *pReq, SEpSet *pEpSet) {
|
||||
SDnode *pDnode = param;
|
||||
STransMgmt *pMgmt = &pDnode->tmgmt;
|
||||
|
||||
tmsg_t msgType = pMsg->msgType;
|
||||
tmsg_t msgType = pReq->msgType;
|
||||
if (msgType == TDMT_DND_NETWORK_TEST) {
|
||||
dTrace("RPC %p, network test req, app:%p will be processed, code:0x%x", pMsg->handle, pMsg->ahandle, pMsg->code);
|
||||
dndProcessStartupReq(pDnode, pMsg);
|
||||
dTrace("RPC %p, network test req, app:%p will be processed, code:0x%x", pReq->handle, pReq->ahandle, pReq->code);
|
||||
dndProcessStartupReq(pDnode, pReq);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dndGetStat(pDnode) == DND_STAT_STOPPED) {
|
||||
dError("RPC %p, req:%s app:%p is ignored since dnode exiting", pMsg->handle, TMSG_INFO(msgType), pMsg->ahandle);
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_EXITING};
|
||||
dError("RPC %p, req:%s app:%p is ignored since dnode exiting", pReq->handle, TMSG_INFO(msgType), pReq->ahandle);
|
||||
SRpcMsg rspMsg = {.handle = pReq->handle, .code = TSDB_CODE_DND_OFFLINE};
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
rpcFreeCont(pReq->pCont);
|
||||
return;
|
||||
} else if (dndGetStat(pDnode) != DND_STAT_RUNNING) {
|
||||
dError("RPC %p, req:%s app:%p is ignored since dnode not running", pMsg->handle, TMSG_INFO(msgType), pMsg->ahandle);
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_APP_NOT_READY};
|
||||
dError("RPC %p, req:%s app:%p is ignored since dnode not running", pReq->handle, TMSG_INFO(msgType), pReq->ahandle);
|
||||
SRpcMsg rspMsg = {.handle = pReq->handle, .code = TSDB_CODE_APP_NOT_READY};
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
rpcFreeCont(pReq->pCont);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pMsg->pCont == NULL) {
|
||||
dTrace("RPC %p, req:%s app:%p not processed since content is null", pMsg->handle, TMSG_INFO(msgType),
|
||||
pMsg->ahandle);
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_INVALID_MSG_LEN};
|
||||
if (pReq->pCont == NULL) {
|
||||
dTrace("RPC %p, req:%s app:%p not processed since content is null", pReq->handle, TMSG_INFO(msgType),
|
||||
pReq->ahandle);
|
||||
SRpcMsg rspMsg = {.handle = pReq->handle, .code = TSDB_CODE_DND_INVALID_MSG_LEN};
|
||||
rpcSendResponse(&rspMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
DndMsgFp fp = pMgmt->msgFp[TMSG_INDEX(msgType)];
|
||||
if (fp != NULL) {
|
||||
dTrace("RPC %p, req:%s app:%p will be processed", pMsg->handle, TMSG_INFO(msgType), pMsg->ahandle);
|
||||
(*fp)(pDnode, pMsg, pEpSet);
|
||||
dTrace("RPC %p, req:%s app:%p will be processed", pReq->handle, TMSG_INFO(msgType), pReq->ahandle);
|
||||
(*fp)(pDnode, pReq, pEpSet);
|
||||
} else {
|
||||
dError("RPC %p, req:%s app:%p is not processed since no handle", pMsg->handle, TMSG_INFO(msgType), pMsg->ahandle);
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_MSG_NOT_PROCESSED};
|
||||
dError("RPC %p, req:%s app:%p is not processed since no handle", pReq->handle, TMSG_INFO(msgType), pReq->ahandle);
|
||||
SRpcMsg rspMsg = {.handle = pReq->handle, .code = TSDB_CODE_MSG_NOT_PROCESSED};
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
rpcFreeCont(pReq->pCont);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -256,7 +254,7 @@ static void dndSendMsgToMnodeRecv(SDnode *pDnode, SRpcMsg *pRpcMsg, SRpcMsg *pRp
|
|||
rpcSendRecv(pMgmt->clientRpc, &epSet, pRpcMsg, pRpcRsp);
|
||||
}
|
||||
|
||||
static int32_t dndAuthInternalMsg(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) {
|
||||
static int32_t dndAuthInternalReq(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) {
|
||||
if (strcmp(user, INTERNAL_USER) == 0) {
|
||||
// A simple temporary implementation
|
||||
char pass[TSDB_PASSWORD_LEN] = {0};
|
||||
|
@ -283,7 +281,7 @@ static int32_t dndAuthInternalMsg(SDnode *pDnode, char *user, char *spi, char *e
|
|||
static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char *encrypt, char *secret, char *ckey) {
|
||||
SDnode *pDnode = parent;
|
||||
|
||||
if (dndAuthInternalMsg(parent, user, spi, encrypt, secret, ckey) == 0) {
|
||||
if (dndAuthInternalReq(parent, user, spi, encrypt, secret, ckey) == 0) {
|
||||
// dTrace("get internal auth success");
|
||||
return 0;
|
||||
}
|
||||
|
@ -300,10 +298,10 @@ static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char
|
|||
|
||||
// dDebug("user:%s, send auth msg to other mnodes", user);
|
||||
|
||||
SAuthMsg *pMsg = rpcMallocCont(sizeof(SAuthMsg));
|
||||
tstrncpy(pMsg->user, user, TSDB_USER_LEN);
|
||||
SAuthReq *pReq = rpcMallocCont(sizeof(SAuthReq));
|
||||
tstrncpy(pReq->user, user, TSDB_USER_LEN);
|
||||
|
||||
SRpcMsg rpcMsg = {.pCont = pMsg, .contLen = sizeof(SAuthMsg), .msgType = TDMT_MND_AUTH};
|
||||
SRpcMsg rpcMsg = {.pCont = pReq, .contLen = sizeof(SAuthReq), .msgType = TDMT_MND_AUTH};
|
||||
SRpcMsg rpcRsp = {0};
|
||||
dndSendMsgToMnodeRecv(pDnode, &rpcMsg, &rpcRsp);
|
||||
|
||||
|
@ -383,14 +381,19 @@ void dndCleanupTrans(SDnode *pDnode) {
|
|||
dInfo("dnode-transport is cleaned up");
|
||||
}
|
||||
|
||||
void dndSendMsgToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||
int32_t dndSendReqToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq) {
|
||||
STransMgmt *pMgmt = &pDnode->tmgmt;
|
||||
if (pMgmt->clientRpc == NULL) return;
|
||||
rpcSendRequest(pMgmt->clientRpc, pEpSet, pMsg, NULL);
|
||||
if (pMgmt->clientRpc == NULL) {
|
||||
terrno = TSDB_CODE_DND_OFFLINE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
rpcSendRequest(pMgmt->clientRpc, pEpSet, pReq, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dndSendMsgToMnode(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||
int32_t dndSendReqToMnode(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
SEpSet epSet = {0};
|
||||
dndGetMnodeEpSet(pDnode, &epSet);
|
||||
dndSendMsgToDnode(pDnode, &epSet, pMsg);
|
||||
return dndSendReqToDnode(pDnode, &epSet, pReq);
|
||||
}
|
||||
|
|
|
@ -33,14 +33,14 @@ typedef struct {
|
|||
int8_t dropped;
|
||||
int8_t accessState;
|
||||
uint64_t dbUid;
|
||||
char *db;
|
||||
char *path;
|
||||
SVnode *pImpl;
|
||||
char * db;
|
||||
char * path;
|
||||
SVnode * pImpl;
|
||||
STaosQueue *pWriteQ;
|
||||
STaosQueue *pSyncQ;
|
||||
STaosQueue *pApplyQ;
|
||||
STaosQueue *pQueryQ;
|
||||
STaosQueue* pFetchQ;
|
||||
STaosQueue *pFetchQ;
|
||||
} SVnodeObj;
|
||||
|
||||
typedef struct {
|
||||
|
@ -49,26 +49,12 @@ typedef struct {
|
|||
int32_t failed;
|
||||
int32_t threadIndex;
|
||||
pthread_t thread;
|
||||
SDnode *pDnode;
|
||||
SDnode * pDnode;
|
||||
SWrapperCfg *pCfgs;
|
||||
} SVnodeThread;
|
||||
|
||||
static int32_t dndInitVnodeReadWorker(SDnode *pDnode);
|
||||
static int32_t dndInitVnodeWriteWorker(SDnode *pDnode);
|
||||
static int32_t dndInitVnodeSyncWorker(SDnode *pDnode);
|
||||
static void dndCleanupVnodeReadWorker(SDnode *pDnode);
|
||||
static void dndCleanupVnodeWriteWorker(SDnode *pDnode);
|
||||
static void dndCleanupVnodeSyncWorker(SDnode *pDnode);
|
||||
static int32_t dndAllocVnodeQueryQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static int32_t dndAllocVnodeFetchQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static int32_t dndAllocVnodeWriteQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static int32_t dndAllocVnodeApplyQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static int32_t dndAllocVnodeSyncQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static void dndFreeVnodeQueryQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static void dndFreeVnodeFetchQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static void dndFreeVnodeWriteQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static void dndFreeVnodeApplyQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static void dndFreeVnodeSyncQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static int32_t dndAllocVnodeQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static void dndFreeVnodeQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
|
||||
static void dndProcessVnodeQueryQueue(SVnodeObj *pVnode, SRpcMsg *pMsg);
|
||||
static void dndProcessVnodeFetchQueue(SVnodeObj *pVnode, SRpcMsg *pMsg);
|
||||
|
@ -81,7 +67,7 @@ void dndProcessVnodeWriteMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pE
|
|||
void dndProcessVnodeSyncMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
static int32_t dndPutMsgIntoVnodeApplyQueue(SDnode *pDnode, int32_t vgId, SRpcMsg *pMsg);
|
||||
|
||||
static SVnodeObj *dndAcquireVnode(SDnode *pDnode, int32_t vgId);
|
||||
static SVnodeObj * dndAcquireVnode(SDnode *pDnode, int32_t vgId);
|
||||
static void dndReleaseVnode(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static int32_t dndOpenVnode(SDnode *pDnode, SWrapperCfg *pCfg, SVnode *pImpl);
|
||||
static void dndCloseVnode(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
|
@ -94,7 +80,7 @@ static void dndCloseVnodes(SDnode *pDnode);
|
|||
|
||||
static SVnodeObj *dndAcquireVnode(SDnode *pDnode, int32_t vgId) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
SVnodeObj *pVnode = NULL;
|
||||
SVnodeObj * pVnode = NULL;
|
||||
int32_t refCount = 0;
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
|
@ -117,24 +103,22 @@ static void dndReleaseVnode(SDnode *pDnode, SVnodeObj *pVnode) {
|
|||
if (pVnode == NULL) return;
|
||||
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
int32_t refCount = atomic_sub_fetch_32(&pVnode->refCount, 1);
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
||||
dTrace("vgId:%d, release vnode, refCount:%d", pVnode->vgId, refCount);
|
||||
}
|
||||
|
||||
static int32_t dndOpenVnode(SDnode *pDnode, SWrapperCfg *pCfg, SVnode *pImpl) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
SVnodeObj *pVnode = calloc(1, sizeof(SVnodeObj));
|
||||
SVnodeObj * pVnode = calloc(1, sizeof(SVnodeObj));
|
||||
if (pVnode == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pVnode->vgId = pCfg->vgId;
|
||||
pVnode->refCount = 1;
|
||||
pVnode->refCount = 0;
|
||||
pVnode->dropped = 0;
|
||||
pVnode->accessState = TSDB_VN_ALL_ACCCESS;
|
||||
pVnode->pImpl = pImpl;
|
||||
|
@ -148,23 +132,8 @@ static int32_t dndOpenVnode(SDnode *pDnode, SWrapperCfg *pCfg, SVnode *pImpl) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (dndAllocVnodeQueryQueue(pDnode, pVnode) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndAllocVnodeFetchQueue(pDnode, pVnode) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndAllocVnodeWriteQueue(pDnode, pVnode) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndAllocVnodeApplyQueue(pDnode, pVnode) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndAllocVnodeSyncQueue(pDnode, pVnode) != 0) {
|
||||
if (dndAllocVnodeQueue(pDnode, pVnode) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -192,11 +161,17 @@ static void dndCloseVnode(SDnode *pDnode, SVnodeObj *pVnode) {
|
|||
while (!taosQueueEmpty(pVnode->pQueryQ)) taosMsleep(10);
|
||||
while (!taosQueueEmpty(pVnode->pFetchQ)) taosMsleep(10);
|
||||
|
||||
dndFreeVnodeQueryQueue(pDnode, pVnode);
|
||||
dndFreeVnodeFetchQueue(pDnode, pVnode);
|
||||
dndFreeVnodeWriteQueue(pDnode, pVnode);
|
||||
dndFreeVnodeApplyQueue(pDnode, pVnode);
|
||||
dndFreeVnodeSyncQueue(pDnode, pVnode);
|
||||
dndFreeVnodeQueue(pDnode, pVnode);
|
||||
vnodeClose(pVnode->pImpl);
|
||||
pVnode->pImpl = NULL;
|
||||
|
||||
dDebug("vgId:%d, vnode is closed", pVnode->vgId);
|
||||
|
||||
if (pVnode->dropped) {
|
||||
dDebug("vgId:%d, vnode is destroyed for dropped:%d", pVnode->vgId, pVnode->dropped);
|
||||
vnodeDestroy(pVnode->path);
|
||||
}
|
||||
|
||||
free(pVnode->path);
|
||||
free(pVnode->db);
|
||||
free(pVnode);
|
||||
|
@ -213,7 +188,7 @@ static SVnodeObj **dndGetVnodesFromHash(SDnode *pDnode, int32_t *numOfVnodes) {
|
|||
void *pIter = taosHashIterate(pMgmt->hash, NULL);
|
||||
while (pIter) {
|
||||
SVnodeObj **ppVnode = pIter;
|
||||
SVnodeObj *pVnode = *ppVnode;
|
||||
SVnodeObj * pVnode = *ppVnode;
|
||||
if (pVnode && num < size) {
|
||||
int32_t refCount = atomic_add_fetch_32(&pVnode->refCount, 1);
|
||||
dTrace("vgId:%d, acquire vnode, refCount:%d", pVnode->vgId, refCount);
|
||||
|
@ -235,9 +210,9 @@ static int32_t dndGetVnodesFromFile(SDnode *pDnode, SWrapperCfg **ppCfgs, int32_
|
|||
int32_t code = TSDB_CODE_DND_VNODE_READ_FILE_ERROR;
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 30000;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
cJSON *root = NULL;
|
||||
FILE *fp = NULL;
|
||||
char * content = calloc(1, maxLen + 1);
|
||||
cJSON * root = NULL;
|
||||
FILE * fp = NULL;
|
||||
char file[PATH_MAX + 20] = {0};
|
||||
SWrapperCfg *pCfgs = NULL;
|
||||
|
||||
|
@ -270,59 +245,57 @@ static int32_t dndGetVnodesFromFile(SDnode *pDnode, SWrapperCfg **ppCfgs, int32_
|
|||
}
|
||||
|
||||
int32_t vnodesNum = cJSON_GetArraySize(vnodes);
|
||||
if (vnodesNum <= 0) {
|
||||
dError("failed to read %s since vnodes size:%d invalid", file, vnodesNum);
|
||||
goto PRASE_VNODE_OVER;
|
||||
if (vnodesNum > 0) {
|
||||
pCfgs = calloc(vnodesNum, sizeof(SWrapperCfg));
|
||||
if (pCfgs == NULL) {
|
||||
dError("failed to read %s since out of memory", file);
|
||||
goto PRASE_VNODE_OVER;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < vnodesNum; ++i) {
|
||||
cJSON *vnode = cJSON_GetArrayItem(vnodes, i);
|
||||
SWrapperCfg *pCfg = &pCfgs[i];
|
||||
|
||||
cJSON *vgId = cJSON_GetObjectItem(vnode, "vgId");
|
||||
if (!vgId || vgId->type != cJSON_Number) {
|
||||
dError("failed to read %s since vgId not found", file);
|
||||
goto PRASE_VNODE_OVER;
|
||||
}
|
||||
pCfg->vgId = vgId->valueint;
|
||||
snprintf(pCfg->path, sizeof(pCfg->path), "%s/vnode%d", pDnode->dir.vnodes, pCfg->vgId);
|
||||
|
||||
cJSON *dropped = cJSON_GetObjectItem(vnode, "dropped");
|
||||
if (!dropped || dropped->type != cJSON_Number) {
|
||||
dError("failed to read %s since dropped not found", file);
|
||||
goto PRASE_VNODE_OVER;
|
||||
}
|
||||
pCfg->dropped = dropped->valueint;
|
||||
|
||||
cJSON *vgVersion = cJSON_GetObjectItem(vnode, "vgVersion");
|
||||
if (!vgVersion || vgVersion->type != cJSON_Number) {
|
||||
dError("failed to read %s since vgVersion not found", file);
|
||||
goto PRASE_VNODE_OVER;
|
||||
}
|
||||
pCfg->vgVersion = vgVersion->valueint;
|
||||
|
||||
cJSON *dbUid = cJSON_GetObjectItem(vnode, "dbUid");
|
||||
if (!dbUid || dbUid->type != cJSON_String) {
|
||||
dError("failed to read %s since dbUid not found", file);
|
||||
goto PRASE_VNODE_OVER;
|
||||
}
|
||||
pCfg->dbUid = atoll(dbUid->valuestring);
|
||||
|
||||
cJSON *db = cJSON_GetObjectItem(vnode, "db");
|
||||
if (!db || db->type != cJSON_String) {
|
||||
dError("failed to read %s since db not found", file);
|
||||
goto PRASE_VNODE_OVER;
|
||||
}
|
||||
tstrncpy(pCfg->db, db->valuestring, TSDB_DB_FNAME_LEN);
|
||||
}
|
||||
|
||||
*ppCfgs = pCfgs;
|
||||
}
|
||||
|
||||
pCfgs = calloc(vnodesNum, sizeof(SWrapperCfg));
|
||||
if (pCfgs == NULL) {
|
||||
dError("failed to read %s since out of memory", file);
|
||||
goto PRASE_VNODE_OVER;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < vnodesNum; ++i) {
|
||||
cJSON *vnode = cJSON_GetArrayItem(vnodes, i);
|
||||
SWrapperCfg *pCfg = &pCfgs[i];
|
||||
|
||||
cJSON *vgId = cJSON_GetObjectItem(vnode, "vgId");
|
||||
if (!vgId || vgId->type != cJSON_Number) {
|
||||
dError("failed to read %s since vgId not found", file);
|
||||
goto PRASE_VNODE_OVER;
|
||||
}
|
||||
pCfg->vgId = vgId->valueint;
|
||||
snprintf(pCfg->path, sizeof(pCfg->path), "%s/vnode%d", pDnode->dir.vnodes, pCfg->vgId);
|
||||
|
||||
cJSON *dropped = cJSON_GetObjectItem(vnode, "dropped");
|
||||
if (!dropped || dropped->type != cJSON_Number) {
|
||||
dError("failed to read %s since dropped not found", file);
|
||||
goto PRASE_VNODE_OVER;
|
||||
}
|
||||
pCfg->dropped = dropped->valueint;
|
||||
|
||||
cJSON *vgVersion = cJSON_GetObjectItem(vnode, "vgVersion");
|
||||
if (!vgVersion || vgVersion->type != cJSON_Number) {
|
||||
dError("failed to read %s since vgVersion not found", file);
|
||||
goto PRASE_VNODE_OVER;
|
||||
}
|
||||
pCfg->vgVersion = vgVersion->valueint;
|
||||
|
||||
cJSON *dbUid = cJSON_GetObjectItem(vnode, "dbUid");
|
||||
if (!dbUid || dbUid->type != cJSON_String) {
|
||||
dError("failed to read %s since dbUid not found", file);
|
||||
goto PRASE_VNODE_OVER;
|
||||
}
|
||||
pCfg->dbUid = atoll(dbUid->valuestring);
|
||||
|
||||
cJSON *db = cJSON_GetObjectItem(vnode, "db");
|
||||
if (!db || db->type != cJSON_String) {
|
||||
dError("failed to read %s since db not found", file);
|
||||
goto PRASE_VNODE_OVER;
|
||||
}
|
||||
tstrncpy(pCfg->db, db->valuestring, TSDB_DB_FNAME_LEN);
|
||||
}
|
||||
|
||||
*ppCfgs = pCfgs;
|
||||
*numOfVnodes = vnodesNum;
|
||||
code = 0;
|
||||
dInfo("succcessed to read file %s", file);
|
||||
|
@ -352,7 +325,7 @@ static int32_t dndWriteVnodesToFile(SDnode *pDnode) {
|
|||
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 65536;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
char * content = calloc(1, maxLen + 1);
|
||||
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
len += snprintf(content + len, maxLen - len, " \"vnodes\": [\n");
|
||||
|
@ -388,14 +361,14 @@ static int32_t dndWriteVnodesToFile(SDnode *pDnode) {
|
|||
free(pVnodes);
|
||||
}
|
||||
|
||||
dInfo("successed to write %s", file);
|
||||
dDebug("successed to write %s", realfile);
|
||||
return taosRenameFile(file, realfile);
|
||||
}
|
||||
|
||||
static void *dnodeOpenVnodeFunc(void *param) {
|
||||
SVnodeThread *pThread = param;
|
||||
SDnode *pDnode = pThread->pDnode;
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
SDnode * pDnode = pThread->pDnode;
|
||||
SVnodesMgmt * pMgmt = &pDnode->vmgmt;
|
||||
|
||||
dDebug("thread:%d, start to open %d vnodes", pThread->threadIndex, pThread->vnodeNum);
|
||||
setThreadName("open-vnodes");
|
||||
|
@ -408,7 +381,7 @@ static void *dnodeOpenVnodeFunc(void *param) {
|
|||
pMgmt->openVnodes, pMgmt->totalVnodes);
|
||||
dndReportStartup(pDnode, "open-vnodes", stepDesc);
|
||||
|
||||
SVnode *pImpl = vnodeOpen(pCfg->path, NULL);
|
||||
SVnode *pImpl = vnodeOpen(pCfg->path, NULL, pCfg->vgId);
|
||||
if (pImpl == NULL) {
|
||||
dError("vgId:%d, failed to open vnode by thread:%d", pCfg->vgId, pThread->threadIndex);
|
||||
pThread->failed++;
|
||||
|
@ -498,13 +471,13 @@ static int32_t dndOpenVnodes(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
static void dndCloseVnodes(SDnode *pDnode) {
|
||||
dInfo("start to close all vnodes");
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
|
||||
int32_t numOfVnodes = 0;
|
||||
SVnodeObj **pVnodes = dndGetVnodesFromHash(pDnode, &numOfVnodes);
|
||||
|
||||
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
||||
dndReleaseVnode(pDnode, pVnodes[i]);
|
||||
dndCloseVnode(pDnode, pVnodes[i]);
|
||||
}
|
||||
|
||||
|
@ -520,8 +493,8 @@ static void dndCloseVnodes(SDnode *pDnode) {
|
|||
dInfo("total vnodes:%d are all closed", numOfVnodes);
|
||||
}
|
||||
|
||||
static SCreateVnodeMsg *dndParseCreateVnodeReq(SRpcMsg *rpcMsg) {
|
||||
SCreateVnodeMsg *pCreate = rpcMsg->pCont;
|
||||
static SCreateVnodeReq *dndParseCreateVnodeReq(SRpcMsg *pReq) {
|
||||
SCreateVnodeReq *pCreate = pReq->pCont;
|
||||
pCreate->vgId = htonl(pCreate->vgId);
|
||||
pCreate->dnodeId = htonl(pCreate->dnodeId);
|
||||
pCreate->dbUid = htobe64(pCreate->dbUid);
|
||||
|
@ -545,7 +518,8 @@ static SCreateVnodeMsg *dndParseCreateVnodeReq(SRpcMsg *rpcMsg) {
|
|||
return pCreate;
|
||||
}
|
||||
|
||||
static void dndGenerateVnodeCfg(SCreateVnodeMsg *pCreate, SVnodeCfg *pCfg) {
|
||||
static void dndGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) {
|
||||
pCfg->vgId = pCreate->vgId;
|
||||
pCfg->wsize = pCreate->cacheBlockSize;
|
||||
pCfg->ssize = pCreate->cacheBlockSize;
|
||||
pCfg->wsize = pCreate->cacheBlockSize;
|
||||
|
@ -554,7 +528,7 @@ static void dndGenerateVnodeCfg(SCreateVnodeMsg *pCreate, SVnodeCfg *pCfg) {
|
|||
pCfg->ttl = 4;
|
||||
pCfg->keep = pCreate->daysToKeep0;
|
||||
pCfg->isWeak = true;
|
||||
pCfg->tsdbCfg.keep0 = pCreate->daysToKeep0;
|
||||
pCfg->tsdbCfg.keep = pCreate->daysToKeep0;
|
||||
pCfg->tsdbCfg.keep1 = pCreate->daysToKeep2;
|
||||
pCfg->tsdbCfg.keep2 = pCreate->daysToKeep0;
|
||||
pCfg->tsdbCfg.lruCacheSize = pCreate->cacheBlockSize;
|
||||
|
@ -568,7 +542,7 @@ static void dndGenerateVnodeCfg(SCreateVnodeMsg *pCreate, SVnodeCfg *pCfg) {
|
|||
pCfg->walCfg.vgId = pCreate->vgId;
|
||||
}
|
||||
|
||||
static void dndGenerateWrapperCfg(SDnode *pDnode, SCreateVnodeMsg *pCreate, SWrapperCfg *pCfg) {
|
||||
static void dndGenerateWrapperCfg(SDnode *pDnode, SCreateVnodeReq *pCreate, SWrapperCfg *pCfg) {
|
||||
memcpy(pCfg->db, pCreate->db, TSDB_DB_FNAME_LEN);
|
||||
pCfg->dbUid = pCreate->dbUid;
|
||||
pCfg->dropped = 0;
|
||||
|
@ -577,20 +551,20 @@ static void dndGenerateWrapperCfg(SDnode *pDnode, SCreateVnodeMsg *pCreate, SWra
|
|||
pCfg->vgVersion = pCreate->vgVersion;
|
||||
}
|
||||
|
||||
static SDropVnodeMsg *vnodeParseDropVnodeReq(SRpcMsg *rpcMsg) {
|
||||
SDropVnodeMsg *pDrop = rpcMsg->pCont;
|
||||
static SDropVnodeReq *dndParseDropVnodeReq(SRpcMsg *pReq) {
|
||||
SDropVnodeReq *pDrop = pReq->pCont;
|
||||
pDrop->vgId = htonl(pDrop->vgId);
|
||||
return pDrop;
|
||||
}
|
||||
|
||||
static SAuthVnodeMsg *vnodeParseAuthVnodeReq(SRpcMsg *rpcMsg) {
|
||||
SAuthVnodeMsg *pAuth = rpcMsg->pCont;
|
||||
static SAuthVnodeReq *dndParseAuthVnodeReq(SRpcMsg *pReq) {
|
||||
SAuthVnodeReq *pAuth = pReq->pCont;
|
||||
pAuth->vgId = htonl(pAuth->vgId);
|
||||
return pAuth;
|
||||
}
|
||||
|
||||
int32_t dndProcessCreateVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
||||
SCreateVnodeMsg *pCreate = dndParseCreateVnodeReq(rpcMsg);
|
||||
int32_t dndProcessCreateVnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
SCreateVnodeReq *pCreate = dndParseCreateVnodeReq(pReq);
|
||||
dDebug("vgId:%d, create vnode req is received", pCreate->vgId);
|
||||
|
||||
SVnodeCfg vnodeCfg = {0};
|
||||
|
@ -601,18 +575,21 @@ int32_t dndProcessCreateVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
|||
|
||||
SVnodeObj *pVnode = dndAcquireVnode(pDnode, pCreate->vgId);
|
||||
if (pVnode != NULL) {
|
||||
dDebug("vgId:%d, already exist, return success", pCreate->vgId);
|
||||
dDebug("vgId:%d, already exist", pCreate->vgId);
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
return 0;
|
||||
terrno = TSDB_CODE_DND_VNODE_ALREADY_DEPLOYED;
|
||||
return -1;
|
||||
}
|
||||
|
||||
SVnode *pImpl = vnodeOpen(wrapperCfg.path, NULL /*pCfg*/);
|
||||
SVnode *pImpl = vnodeOpen(wrapperCfg.path, NULL /*pCfg*/, pCreate->vgId);
|
||||
if (pImpl == NULL) {
|
||||
dError("vgId:%d, failed to create vnode since %s", pCreate->vgId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = dndOpenVnode(pDnode, &wrapperCfg, pImpl);
|
||||
if (code != 0) {
|
||||
dError("vgId:%d, failed to open vnode since %s", pCreate->vgId, terrstr());
|
||||
vnodeClose(pImpl);
|
||||
vnodeDestroy(wrapperCfg.path);
|
||||
terrno = code;
|
||||
|
@ -630,23 +607,20 @@ int32_t dndProcessCreateVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t dndProcessAlterVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
||||
SAlterVnodeMsg *pAlter = (SAlterVnodeMsg *)dndParseCreateVnodeReq(rpcMsg);
|
||||
int32_t dndProcessAlterVnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
SAlterVnodeReq *pAlter = (SAlterVnodeReq *)dndParseCreateVnodeReq(pReq);
|
||||
dDebug("vgId:%d, alter vnode req is received", pAlter->vgId);
|
||||
|
||||
SVnodeCfg vnodeCfg = {0};
|
||||
dndGenerateVnodeCfg(pAlter, &vnodeCfg);
|
||||
|
||||
SWrapperCfg wrapperCfg = {0};
|
||||
dndGenerateWrapperCfg(pDnode, pAlter, &wrapperCfg);
|
||||
|
||||
SVnodeObj *pVnode = dndAcquireVnode(pDnode, pAlter->vgId);
|
||||
if (pVnode == NULL) {
|
||||
dDebug("vgId:%d, failed to alter vnode since %s", pAlter->vgId, terrstr());
|
||||
return terrno;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (wrapperCfg.vgVersion == pVnode->vgVersion) {
|
||||
if (pAlter->vgVersion == pVnode->vgVersion) {
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
dDebug("vgId:%d, no need to alter vnode cfg for version unchanged ", pAlter->vgId);
|
||||
return 0;
|
||||
|
@ -655,11 +629,11 @@ int32_t dndProcessAlterVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
|||
if (vnodeAlter(pVnode->pImpl, &vnodeCfg) != 0) {
|
||||
dError("vgId:%d, failed to alter vnode since %s", pAlter->vgId, terrstr());
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
return terrno;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t oldVersion = pVnode->vgVersion;
|
||||
pVnode->vgVersion = wrapperCfg.vgVersion;
|
||||
pVnode->vgVersion = pAlter->vgVersion;
|
||||
int32_t code = dndWriteVnodesToFile(pDnode);
|
||||
if (code != 0) {
|
||||
pVnode->vgVersion = oldVersion;
|
||||
|
@ -669,8 +643,8 @@ int32_t dndProcessAlterVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t dndProcessDropVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
||||
SDropVnodeMsg *pDrop = vnodeParseDropVnodeReq(rpcMsg);
|
||||
int32_t dndProcessDropVnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
SDropVnodeReq *pDrop = dndParseDropVnodeReq(pReq);
|
||||
|
||||
int32_t vgId = pDrop->vgId;
|
||||
dDebug("vgId:%d, drop vnode req is received", vgId);
|
||||
|
@ -678,35 +652,33 @@ int32_t dndProcessDropVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
|||
SVnodeObj *pVnode = dndAcquireVnode(pDnode, vgId);
|
||||
if (pVnode == NULL) {
|
||||
dDebug("vgId:%d, failed to drop since %s", vgId, terrstr());
|
||||
return 0;
|
||||
terrno = TSDB_CODE_DND_VNODE_NOT_DEPLOYED;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pVnode->dropped = 1;
|
||||
if (dndWriteVnodesToFile(pDnode) != 0) {
|
||||
pVnode->dropped = 0;
|
||||
return terrno;
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
dndCloseVnode(pDnode, pVnode);
|
||||
vnodeClose(pVnode->pImpl);
|
||||
vnodeDestroy(pVnode->path);
|
||||
dndWriteVnodesToFile(pDnode);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dndProcessAuthVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
||||
SAuthVnodeMsg *pAuth = (SAuthVnodeMsg *)vnodeParseAuthVnodeReq(rpcMsg);
|
||||
int32_t dndProcessAuthVnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
SAuthVnodeReq *pAuth = (SAuthVnodeReq *)dndParseAuthVnodeReq(pReq);
|
||||
|
||||
int32_t code = 0;
|
||||
int32_t vgId = pAuth->vgId;
|
||||
dDebug("vgId:%d, auth vnode req is received", vgId);
|
||||
|
||||
SVnodeObj *pVnode = dndAcquireVnode(pDnode, vgId);
|
||||
if (pVnode == NULL) {
|
||||
dDebug("vgId:%d, failed to auth since %s", vgId, terrstr());
|
||||
return terrno;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pVnode->accessState = pAuth->accessState;
|
||||
|
@ -714,30 +686,30 @@ int32_t dndProcessAuthVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t dndProcessSyncVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
||||
SAuthVnodeMsg *pAuth = (SAuthVnodeMsg *)vnodeParseAuthVnodeReq(rpcMsg);
|
||||
int32_t dndProcessSyncVnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
SSyncVnodeReq *pSync = (SSyncVnodeReq *)dndParseDropVnodeReq(pReq);
|
||||
|
||||
int32_t vgId = pAuth->vgId;
|
||||
dDebug("vgId:%d, auth vnode req is received", vgId);
|
||||
int32_t vgId = pSync->vgId;
|
||||
dDebug("vgId:%d, sync vnode req is received", vgId);
|
||||
|
||||
SVnodeObj *pVnode = dndAcquireVnode(pDnode, vgId);
|
||||
if (pVnode == NULL) {
|
||||
dDebug("vgId:%d, failed to auth since %s", vgId, terrstr());
|
||||
return terrno;
|
||||
dDebug("vgId:%d, failed to sync since %s", vgId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (vnodeSync(pVnode->pImpl) != 0) {
|
||||
dError("vgId:%d, failed to auth vnode since %s", vgId, terrstr());
|
||||
dError("vgId:%d, failed to sync vnode since %s", vgId, terrstr());
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
return terrno;
|
||||
return -1;
|
||||
}
|
||||
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dndProcessCompactVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
||||
SCompactVnodeMsg *pCompact = (SCompactVnodeMsg *)vnodeParseDropVnodeReq(rpcMsg);
|
||||
int32_t dndProcessCompactVnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
SCompactVnodeReq *pCompact = (SCompactVnodeReq *)dndParseDropVnodeReq(pReq);
|
||||
|
||||
int32_t vgId = pCompact->vgId;
|
||||
dDebug("vgId:%d, compact vnode req is received", vgId);
|
||||
|
@ -745,13 +717,13 @@ int32_t dndProcessCompactVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
|||
SVnodeObj *pVnode = dndAcquireVnode(pDnode, vgId);
|
||||
if (pVnode == NULL) {
|
||||
dDebug("vgId:%d, failed to compact since %s", vgId, terrstr());
|
||||
return terrno;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (vnodeCompact(pVnode->pImpl) != 0) {
|
||||
dError("vgId:%d, failed to compact vnode since %s", vgId, terrstr());
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
return terrno;
|
||||
return -1;
|
||||
}
|
||||
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
|
@ -810,6 +782,7 @@ static void dndProcessVnodeApplyQueue(SVnodeObj *pVnode, STaosQall *qall, int32_
|
|||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
||||
taosGetQitem(qall, (void **)&pMsg);
|
||||
|
||||
// todo
|
||||
SRpcMsg *pRsp = NULL;
|
||||
(void)vnodeApplyWMsg(pVnode->pImpl, pMsg, &pRsp);
|
||||
}
|
||||
|
@ -821,6 +794,7 @@ static void dndProcessVnodeSyncQueue(SVnodeObj *pVnode, STaosQall *qall, int32_t
|
|||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
||||
taosGetQitem(qall, (void **)&pMsg);
|
||||
|
||||
// todo
|
||||
SRpcMsg *pRsp = NULL;
|
||||
(void)vnodeProcessSyncReq(pVnode->pImpl, pMsg, &pRsp);
|
||||
}
|
||||
|
@ -844,21 +818,25 @@ static int32_t dndWriteRpcMsgToVnodeQueue(STaosQueue *pQueue, SRpcMsg *pRpcMsg)
|
|||
}
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
SRpcMsg rsp = {.handle = pRpcMsg->handle, .code = code};
|
||||
rpcSendResponse(&rsp);
|
||||
if (pRpcMsg->msgType & 1u) {
|
||||
SRpcMsg rsp = {.handle = pRpcMsg->handle, .code = code};
|
||||
rpcSendResponse(&rsp);
|
||||
}
|
||||
rpcFreeCont(pRpcMsg->pCont);
|
||||
}
|
||||
}
|
||||
|
||||
static SVnodeObj *dndAcquireVnodeFromMsg(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||
SMsgHead *pHead = (SMsgHead *)pMsg->pCont;
|
||||
SMsgHead *pHead = pMsg->pCont;
|
||||
pHead->contLen = htonl(pHead->contLen);
|
||||
pHead->vgId = htonl(pHead->vgId);
|
||||
|
||||
SVnodeObj *pVnode = dndAcquireVnode(pDnode, pHead->vgId);
|
||||
if (pVnode == NULL) {
|
||||
SRpcMsg rsp = {.handle = pMsg->handle, .code = TSDB_CODE_VND_INVALID_VGROUP_ID};
|
||||
rpcSendResponse(&rsp);
|
||||
if (pMsg->msgType & 1u) {
|
||||
SRpcMsg rsp = {.handle = pMsg->handle, .code = TSDB_CODE_VND_INVALID_VGROUP_ID};
|
||||
rpcSendResponse(&rsp);
|
||||
}
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
|
||||
|
@ -899,193 +877,96 @@ void dndProcessVnodeFetchMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
|||
|
||||
static int32_t dndPutMsgIntoVnodeApplyQueue(SDnode *pDnode, int32_t vgId, SRpcMsg *pMsg) {
|
||||
SVnodeObj *pVnode = dndAcquireVnode(pDnode, vgId);
|
||||
if (pVnode == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (pVnode == NULL) return -1;
|
||||
|
||||
int32_t code = taosWriteQitem(pVnode->pApplyQ, pMsg);
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t dndAllocVnodeQueryQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
pVnode->pQueryQ = tWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FProcessItem)dndProcessVnodeQueryQueue);
|
||||
if (pVnode->pQueryQ == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndFreeVnodeQueryQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
tWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ);
|
||||
pVnode->pQueryQ = NULL;
|
||||
}
|
||||
|
||||
static int32_t dndAllocVnodeFetchQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
pVnode->pFetchQ = tWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FProcessItem)dndProcessVnodeFetchQueue);
|
||||
if (pVnode->pFetchQ == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndFreeVnodeFetchQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
tWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
|
||||
pVnode->pFetchQ = NULL;
|
||||
}
|
||||
|
||||
static int32_t dndInitVnodeReadWorker(SDnode *pDnode) {
|
||||
static int32_t dndInitVnodeWorkers(SDnode *pDnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
|
||||
int32_t maxFetchThreads = 4;
|
||||
float threadsForQuery = MAX(pDnode->opt.numOfCores * pDnode->opt.ratioOfQueryCores, 1);
|
||||
int32_t minFetchThreads = MIN(maxFetchThreads, pDnode->opt.numOfCores);
|
||||
int32_t minQueryThreads = MAX((int32_t)(pDnode->opt.numOfCores * pDnode->opt.ratioOfQueryCores), 1);
|
||||
int32_t maxQueryThreads = minQueryThreads;
|
||||
int32_t maxWriteThreads = MAX(pDnode->opt.numOfCores, 1);
|
||||
int32_t maxSyncThreads = MAX(pDnode->opt.numOfCores / 2, 1);
|
||||
|
||||
SWorkerPool *pPool = &pMgmt->queryPool;
|
||||
pPool->name = "vnode-query";
|
||||
pPool->min = (int32_t)threadsForQuery;
|
||||
pPool->max = pPool->min;
|
||||
if (tWorkerInit(pPool) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
pPool->min = minQueryThreads;
|
||||
pPool->max = maxQueryThreads;
|
||||
if (tWorkerInit(pPool) != 0) return -1;
|
||||
|
||||
pPool = &pMgmt->fetchPool;
|
||||
pPool->name = "vnode-fetch";
|
||||
pPool->min = MIN(maxFetchThreads, pDnode->opt.numOfCores);
|
||||
pPool->max = pPool->min;
|
||||
if (tWorkerInit(pPool) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
pPool->min = minFetchThreads;
|
||||
pPool->max = maxFetchThreads;
|
||||
if (tWorkerInit(pPool) != 0) return -1;
|
||||
|
||||
dDebug("vnode read worker is initialized");
|
||||
SMWorkerPool *pMPool = &pMgmt->writePool;
|
||||
pMPool->name = "vnode-write";
|
||||
pMPool->max = maxWriteThreads;
|
||||
if (tMWorkerInit(pMPool) != 0) return -1;
|
||||
|
||||
pMPool = &pMgmt->syncPool;
|
||||
pMPool->name = "vnode-sync";
|
||||
pMPool->max = maxSyncThreads;
|
||||
if (tMWorkerInit(pMPool) != 0) return -1;
|
||||
|
||||
dDebug("vnode workers is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndCleanupVnodeReadWorker(SDnode *pDnode) {
|
||||
static void dndCleanupVnodeWorkers(SDnode *pDnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
tWorkerCleanup(&pMgmt->fetchPool);
|
||||
tWorkerCleanup(&pMgmt->queryPool);
|
||||
dDebug("vnode close worker is initialized");
|
||||
}
|
||||
|
||||
static int32_t dndAllocVnodeWriteQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
pVnode->pWriteQ = tMWorkerAllocQueue(&pMgmt->writePool, pVnode, (FProcessItems)dndProcessVnodeWriteQueue);
|
||||
if (pVnode->pWriteQ == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndFreeVnodeWriteQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
tMWorkerFreeQueue(&pMgmt->writePool, pVnode->pWriteQ);
|
||||
pVnode->pWriteQ = NULL;
|
||||
}
|
||||
|
||||
static int32_t dndAllocVnodeApplyQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
pVnode->pApplyQ = tMWorkerAllocQueue(&pMgmt->writePool, pVnode, (FProcessItems)dndProcessVnodeApplyQueue);
|
||||
if (pVnode->pApplyQ == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndFreeVnodeApplyQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
tMWorkerFreeQueue(&pMgmt->writePool, pVnode->pApplyQ);
|
||||
pVnode->pApplyQ = NULL;
|
||||
}
|
||||
|
||||
static int32_t dndInitVnodeWriteWorker(SDnode *pDnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
SMWorkerPool *pPool = &pMgmt->writePool;
|
||||
pPool->name = "vnode-write";
|
||||
pPool->max = pDnode->opt.numOfCores;
|
||||
if (tMWorkerInit(pPool) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("vnode write worker is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndCleanupVnodeWriteWorker(SDnode *pDnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
tMWorkerCleanup(&pMgmt->writePool);
|
||||
dDebug("vnode write worker is closed");
|
||||
}
|
||||
|
||||
static int32_t dndAllocVnodeSyncQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
pVnode->pSyncQ = tMWorkerAllocQueue(&pMgmt->syncPool, pVnode, (FProcessItems)dndProcessVnodeSyncQueue);
|
||||
if (pVnode->pSyncQ == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndFreeVnodeSyncQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
tMWorkerFreeQueue(&pMgmt->syncPool, pVnode->pSyncQ);
|
||||
pVnode->pSyncQ = NULL;
|
||||
}
|
||||
|
||||
static int32_t dndInitVnodeSyncWorker(SDnode *pDnode) {
|
||||
int32_t maxThreads = pDnode->opt.numOfCores / 2;
|
||||
if (maxThreads < 1) maxThreads = 1;
|
||||
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
SMWorkerPool *pPool = &pMgmt->syncPool;
|
||||
pPool->name = "vnode-sync";
|
||||
pPool->max = maxThreads;
|
||||
if (tMWorkerInit(pPool) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("vnode sync worker is initialized");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndCleanupVnodeSyncWorker(SDnode *pDnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
tMWorkerCleanup(&pMgmt->syncPool);
|
||||
dDebug("vnode sync worker is closed");
|
||||
dDebug("vnode workers is closed");
|
||||
}
|
||||
|
||||
static int32_t dndAllocVnodeQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
|
||||
pVnode->pWriteQ = tMWorkerAllocQueue(&pMgmt->writePool, pVnode, (FProcessItems)dndProcessVnodeWriteQueue);
|
||||
pVnode->pApplyQ = tMWorkerAllocQueue(&pMgmt->writePool, pVnode, (FProcessItems)dndProcessVnodeApplyQueue);
|
||||
pVnode->pSyncQ = tMWorkerAllocQueue(&pMgmt->syncPool, pVnode, (FProcessItems)dndProcessVnodeSyncQueue);
|
||||
pVnode->pFetchQ = tWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FProcessItem)dndProcessVnodeFetchQueue);
|
||||
pVnode->pQueryQ = tWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FProcessItem)dndProcessVnodeQueryQueue);
|
||||
|
||||
if (pVnode->pApplyQ == NULL || pVnode->pWriteQ == NULL || pVnode->pSyncQ == NULL || pVnode->pFetchQ == NULL ||
|
||||
pVnode->pQueryQ == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndFreeVnodeQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
tWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ);
|
||||
tWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ);
|
||||
tMWorkerFreeQueue(&pMgmt->writePool, pVnode->pWriteQ);
|
||||
tMWorkerFreeQueue(&pMgmt->writePool, pVnode->pApplyQ);
|
||||
tMWorkerFreeQueue(&pMgmt->syncPool, pVnode->pSyncQ);
|
||||
pVnode->pWriteQ = NULL;
|
||||
pVnode->pApplyQ = NULL;
|
||||
pVnode->pSyncQ = NULL;
|
||||
pVnode->pFetchQ = NULL;
|
||||
pVnode->pQueryQ = NULL;
|
||||
}
|
||||
|
||||
int32_t dndInitVnodes(SDnode *pDnode) {
|
||||
dInfo("dnode-vnodes start to init");
|
||||
|
||||
if (dndInitVnodeReadWorker(pDnode) != 0) {
|
||||
dError("failed to init vnodes read worker since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndInitVnodeWriteWorker(pDnode) != 0) {
|
||||
dError("failed to init vnodes write worker since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dndInitVnodeSyncWorker(pDnode) != 0) {
|
||||
dError("failed to init vnodes sync worker since %s", terrstr());
|
||||
if (dndInitVnodeWorkers(pDnode) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
dError("failed to init vnode workers since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1101,9 +982,7 @@ int32_t dndInitVnodes(SDnode *pDnode) {
|
|||
void dndCleanupVnodes(SDnode *pDnode) {
|
||||
dInfo("dnode-vnodes start to clean up");
|
||||
dndCloseVnodes(pDnode);
|
||||
dndCleanupVnodeReadWorker(pDnode);
|
||||
dndCleanupVnodeWriteWorker(pDnode);
|
||||
dndCleanupVnodeSyncWorker(pDnode);
|
||||
dndCleanupVnodeWorkers(pDnode);
|
||||
dInfo("dnode-vnodes is cleaned up");
|
||||
}
|
||||
|
||||
|
@ -1114,12 +993,12 @@ void dndGetVnodeLoads(SDnode *pDnode, SVnodeLoads *pLoads) {
|
|||
pLoads->num = taosHashGetSize(pMgmt->hash);
|
||||
|
||||
int32_t v = 0;
|
||||
void *pIter = taosHashIterate(pMgmt->hash, NULL);
|
||||
void * pIter = taosHashIterate(pMgmt->hash, NULL);
|
||||
while (pIter) {
|
||||
SVnodeObj **ppVnode = pIter;
|
||||
if (ppVnode == NULL || *ppVnode == NULL) continue;
|
||||
|
||||
SVnodeObj *pVnode = *ppVnode;
|
||||
SVnodeObj * pVnode = *ppVnode;
|
||||
SVnodeLoad *pLoad = &pLoads->data[v++];
|
||||
|
||||
vnodeGetLoad(pVnode->pImpl, pLoad);
|
||||
|
|
|
@ -101,7 +101,9 @@ int32_t dndWriteMsgToWorker(SDnodeWorker *pWorker, void *pCont, int32_t contLen)
|
|||
}
|
||||
|
||||
if (taosWriteQitem(pWorker->queue, pMsg) != 0) {
|
||||
taosFreeQitem(pMsg);
|
||||
if (contLen != 0) {
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -14,12 +14,16 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndDnode.h"
|
||||
#include "dndBnode.h"
|
||||
#include "dndMgmt.h"
|
||||
#include "dndMnode.h"
|
||||
#include "dndQnode.h"
|
||||
#include "dndSnode.h"
|
||||
#include "dndTransport.h"
|
||||
#include "dndVnodes.h"
|
||||
#include "sync.h"
|
||||
#include "wal.h"
|
||||
#include "tfs.h"
|
||||
|
||||
EStat dndGetStat(SDnode *pDnode) { return pDnode->stat; }
|
||||
|
||||
|
@ -42,14 +46,14 @@ char *dndStatStr(EStat stat) {
|
|||
}
|
||||
|
||||
void dndReportStartup(SDnode *pDnode, char *pName, char *pDesc) {
|
||||
SStartupMsg *pStartup = &pDnode->startup;
|
||||
SStartupReq *pStartup = &pDnode->startup;
|
||||
tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN);
|
||||
tstrncpy(pStartup->desc, pDesc, TSDB_STEP_DESC_LEN);
|
||||
pStartup->finished = 0;
|
||||
}
|
||||
|
||||
void dndGetStartup(SDnode *pDnode, SStartupMsg *pStartup) {
|
||||
memcpy(pStartup, &pDnode->startup, sizeof(SStartupMsg));
|
||||
void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup) {
|
||||
memcpy(pStartup, &pDnode->startup, sizeof(SStartupReq));
|
||||
pStartup->finished = (dndGetStat(pDnode) == DND_STAT_RUNNING);
|
||||
}
|
||||
|
||||
|
@ -182,13 +186,23 @@ SDnode *dndInit(SDnodeOpt *pOption) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SDiskCfg dCfg;
|
||||
strcpy(dCfg.dir, pDnode->opt.dataDir);
|
||||
dCfg.level = 0;
|
||||
dCfg.primary = 1;
|
||||
if (tfsInit(&dCfg, 1) != 0) {
|
||||
dError("failed to init tfs env");
|
||||
dndCleanup(pDnode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (vnodeInit(pDnode->opt.numOfCommitThreads) != 0) {
|
||||
dError("failed to init vnode env");
|
||||
dndCleanup(pDnode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (dndInitDnode(pDnode) != 0) {
|
||||
if (dndInitMgmt(pDnode) != 0) {
|
||||
dError("failed to init dnode");
|
||||
dndCleanup(pDnode);
|
||||
return NULL;
|
||||
|
@ -200,6 +214,24 @@ SDnode *dndInit(SDnodeOpt *pOption) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (dndInitQnode(pDnode) != 0) {
|
||||
dError("failed to init qnode");
|
||||
dndCleanup(pDnode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (dndInitSnode(pDnode) != 0) {
|
||||
dError("failed to init snode");
|
||||
dndCleanup(pDnode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (dndInitBnode(pDnode) != 0) {
|
||||
dError("failed to init bnode");
|
||||
dndCleanup(pDnode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (dndInitMnode(pDnode) != 0) {
|
||||
dError("failed to init mnode");
|
||||
dndCleanup(pDnode);
|
||||
|
@ -213,7 +245,7 @@ SDnode *dndInit(SDnodeOpt *pOption) {
|
|||
}
|
||||
|
||||
dndSetStat(pDnode, DND_STAT_RUNNING);
|
||||
dndSendStatusMsg(pDnode);
|
||||
dndSendStatusReq(pDnode);
|
||||
dndReportStartup(pDnode, "TDengine", "initialized successfully");
|
||||
dInfo("TDengine is initialized successfully, pDnode:%p", pDnode);
|
||||
|
||||
|
@ -231,10 +263,15 @@ void dndCleanup(SDnode *pDnode) {
|
|||
dInfo("start to cleanup TDengine");
|
||||
dndSetStat(pDnode, DND_STAT_STOPPED);
|
||||
dndCleanupTrans(pDnode);
|
||||
dndStopMgmt(pDnode);
|
||||
dndCleanupMnode(pDnode);
|
||||
dndCleanupBnode(pDnode);
|
||||
dndCleanupSnode(pDnode);
|
||||
dndCleanupQnode(pDnode);
|
||||
dndCleanupVnodes(pDnode);
|
||||
dndCleanupDnode(pDnode);
|
||||
dndCleanupMgmt(pDnode);
|
||||
vnodeClear();
|
||||
tfsDestroy();
|
||||
walCleanUp();
|
||||
rpcCleanup();
|
||||
|
||||
|
|
|
@ -1,21 +1,8 @@
|
|||
enable_testing()
|
||||
|
||||
# add_subdirectory(auth)
|
||||
# add_subdirectory(balance)
|
||||
add_subdirectory(cluster)
|
||||
add_subdirectory(db)
|
||||
add_subdirectory(dnode)
|
||||
# add_subdirectory(func)
|
||||
add_subdirectory(mnode)
|
||||
add_subdirectory(qnode)
|
||||
add_subdirectory(snode)
|
||||
add_subdirectory(bnode)
|
||||
add_subdirectory(profile)
|
||||
add_subdirectory(show)
|
||||
add_subdirectory(stb)
|
||||
# add_subdirectory(sync)
|
||||
# add_subdirectory(telem)
|
||||
# add_subdirectory(trans)
|
||||
add_subdirectory(vgroup)
|
||||
|
||||
add_subdirectory(snode)
|
||||
add_subdirectory(mnode)
|
||||
add_subdirectory(vnode)
|
||||
add_subdirectory(sut)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
aux_source_directory(. STEST_SRC)
|
||||
add_executable(dnode_test_bnode ${STEST_SRC})
|
||||
aux_source_directory(. BQTEST_SRC)
|
||||
add_executable(dnode_test_bnode ${BQTEST_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_bnode
|
||||
PUBLIC sut
|
||||
|
|
|
@ -1,154 +0,0 @@
|
|||
/**
|
||||
* @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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,133 @@
|
|||
/**
|
||||
* @file dbnode.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module bnode tests
|
||||
* @version 1.0
|
||||
* @date 2022-01-05
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sut.h"
|
||||
|
||||
class DndTestBnode : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_snode", 9112); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
};
|
||||
|
||||
Testbase DndTestBnode::test;
|
||||
|
||||
TEST_F(DndTestBnode, 01_Create_Bnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateBnodeReq);
|
||||
|
||||
SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_INVALID_OPTION);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateBnodeReq);
|
||||
|
||||
SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateBnodeReq);
|
||||
|
||||
SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED);
|
||||
}
|
||||
|
||||
test.Restart();
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateBnodeReq);
|
||||
|
||||
SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestBnode, 01_Drop_Bnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropBnodeReq);
|
||||
|
||||
SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_INVALID_OPTION);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropBnodeReq);
|
||||
|
||||
SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropBnodeReq);
|
||||
|
||||
SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_NOT_DEPLOYED);
|
||||
}
|
||||
|
||||
test.Restart();
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropBnodeReq);
|
||||
|
||||
SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_NOT_DEPLOYED);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateBnodeReq);
|
||||
|
||||
SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
aux_source_directory(. CLUSTER_SRC)
|
||||
add_executable(dnode_test_cluster ${CLUSTER_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_cluster
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME dnode_test_cluster
|
||||
COMMAND dnode_test_cluster
|
||||
)
|
|
@ -1,41 +0,0 @@
|
|||
/**
|
||||
* @file cluster.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module cluster-msg tests
|
||||
* @version 0.1
|
||||
* @date 2021-12-15
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
#include "base.h"
|
||||
|
||||
class DndTestCluster : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_cluster", 9030); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
};
|
||||
|
||||
Testbase DndTestCluster::test;
|
||||
|
||||
TEST_F(DndTestCluster, 01_ShowCluster) {
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_CLUSTER, "");
|
||||
CHECK_META( "show cluster", 3);
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_BIGINT, 8, "id");
|
||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, "name");
|
||||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
IgnoreInt64();
|
||||
IgnoreBinary(TSDB_CLUSTER_ID_LEN);
|
||||
CheckTimestamp();
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
aux_source_directory(. DB_SRC)
|
||||
add_executable(dnode_test_db ${DB_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_db
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME dnode_test_db
|
||||
COMMAND dnode_test_db
|
||||
)
|
|
@ -1,11 +0,0 @@
|
|||
aux_source_directory(. DTEST_SRC)
|
||||
add_executable(dnode_test_dnode ${DTEST_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_dnode
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME dnode_test_dnode
|
||||
COMMAND dnode_test_dnode
|
||||
)
|
|
@ -1,261 +0,0 @@
|
|||
/**
|
||||
* @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 DndTestDnode : public ::testing::Test {
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
public:
|
||||
static void SetUpTestSuite() {
|
||||
test.Init("/tmp/dnode_test_dnode1", 9041);
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9041";
|
||||
|
||||
server2.Start("/tmp/dnode_test_dnode2", fqdn, 9042, firstEp);
|
||||
server3.Start("/tmp/dnode_test_dnode3", fqdn, 9043, firstEp);
|
||||
server4.Start("/tmp/dnode_test_dnode4", fqdn, 9044, firstEp);
|
||||
server5.Start("/tmp/dnode_test_dnode5", fqdn, 9045, firstEp);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
server2.Stop();
|
||||
server3.Stop();
|
||||
server4.Stop();
|
||||
server5.Stop();
|
||||
test.Cleanup();
|
||||
}
|
||||
|
||||
static Testbase test;
|
||||
static TestServer server2;
|
||||
static TestServer server3;
|
||||
static TestServer server4;
|
||||
static TestServer server5;
|
||||
};
|
||||
|
||||
Testbase DndTestDnode::test;
|
||||
TestServer DndTestDnode::server2;
|
||||
TestServer DndTestDnode::server3;
|
||||
TestServer DndTestDnode::server4;
|
||||
TestServer DndTestDnode::server5;
|
||||
|
||||
TEST_F(DndTestDnode, 01_ShowDnode) {
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
|
||||
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_SMALLINT, 2, "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(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
CHECK_SCHEMA(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "offline_reason");
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
||||
CheckInt16(0);
|
||||
CheckInt16(16);
|
||||
CheckBinary("ready", 10);
|
||||
CheckTimestamp();
|
||||
CheckBinary("", 24);
|
||||
}
|
||||
|
||||
TEST_F(DndTestDnode, 02_ConfigDnode) {
|
||||
int32_t contLen = sizeof(SCfgDnodeMsg);
|
||||
|
||||
SCfgDnodeMsg* pReq = (SCfgDnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
strcpy(pReq->config, "ddebugflag 131");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONFIG_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9042);
|
||||
|
||||
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, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckInt16(2);
|
||||
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9042", TSDB_EP_LEN);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(16);
|
||||
CheckInt16(16);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDropDnodeMsg);
|
||||
|
||||
SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
||||
CheckInt16(0);
|
||||
CheckInt16(16);
|
||||
CheckBinary("ready", 10);
|
||||
CheckTimestamp();
|
||||
CheckBinary("", 24);
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9043);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9044);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9045);
|
||||
|
||||
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, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 4);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckInt16(3);
|
||||
CheckInt16(4);
|
||||
CheckInt16(5);
|
||||
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9043", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9044", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9045", TSDB_EP_LEN);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(16);
|
||||
CheckInt16(16);
|
||||
CheckInt16(16);
|
||||
CheckInt16(16);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
|
||||
// restart
|
||||
uInfo("stop all server");
|
||||
test.Restart();
|
||||
server2.Restart();
|
||||
server3.Restart();
|
||||
server4.Restart();
|
||||
server5.Restart();
|
||||
|
||||
taosMsleep(1300);
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 4);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckInt16(3);
|
||||
CheckInt16(4);
|
||||
CheckInt16(5);
|
||||
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9043", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9044", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9045", TSDB_EP_LEN);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(0);
|
||||
CheckInt16(16);
|
||||
CheckInt16(16);
|
||||
CheckInt16(16);
|
||||
CheckInt16(16);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckBinary("ready", 10);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
aux_source_directory(. MTEST_SRC)
|
||||
add_executable(dnode_test_mnode ${MTEST_SRC})
|
||||
aux_source_directory(. DMTEST_SRC)
|
||||
add_executable(dnode_test_mnode ${DMTEST_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_mnode
|
||||
PUBLIC sut
|
||||
|
|
|
@ -0,0 +1,189 @@
|
|||
/**
|
||||
* @file dmnode.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module mnode tests
|
||||
* @version 1.0
|
||||
* @date 2022-01-07
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sut.h"
|
||||
|
||||
class DndTestMnode : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_mnode", 9114); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
};
|
||||
|
||||
Testbase DndTestMnode::test;
|
||||
|
||||
TEST_F(DndTestMnode, 01_Create_Mnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateMnodeReq);
|
||||
|
||||
SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
pReq->replica = 1;
|
||||
pReq->replicas[0].id = htonl(1);
|
||||
pReq->replicas[0].port = htonl(9113);
|
||||
strcpy(pReq->replicas[0].fqdn, "localhost");
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_INVALID_OPTION);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateMnodeReq);
|
||||
|
||||
SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
pReq->replica = 1;
|
||||
pReq->replicas[0].id = htonl(2);
|
||||
pReq->replicas[0].port = htonl(9113);
|
||||
strcpy(pReq->replicas[0].fqdn, "localhost");
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_INVALID_OPTION);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateMnodeReq);
|
||||
|
||||
SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
pReq->replica = 2;
|
||||
pReq->replicas[0].id = htonl(1);
|
||||
pReq->replicas[0].port = htonl(9113);
|
||||
strcpy(pReq->replicas[0].fqdn, "localhost");
|
||||
pReq->replicas[1].id = htonl(1);
|
||||
pReq->replicas[1].port = htonl(9114);
|
||||
strcpy(pReq->replicas[1].fqdn, "localhost");
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestMnode, 02_Alter_Mnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SDAlterMnodeReq);
|
||||
|
||||
SDAlterMnodeReq* pReq = (SDAlterMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
pReq->replica = 1;
|
||||
pReq->replicas[0].id = htonl(1);
|
||||
pReq->replicas[0].port = htonl(9113);
|
||||
strcpy(pReq->replicas[0].fqdn, "localhost");
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_INVALID_OPTION);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDAlterMnodeReq);
|
||||
|
||||
SDAlterMnodeReq* pReq = (SDAlterMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
pReq->replica = 1;
|
||||
pReq->replicas[0].id = htonl(2);
|
||||
pReq->replicas[0].port = htonl(9113);
|
||||
strcpy(pReq->replicas[0].fqdn, "localhost");
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_INVALID_OPTION);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDAlterMnodeReq);
|
||||
|
||||
SDAlterMnodeReq* pReq = (SDAlterMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
pReq->replica = 1;
|
||||
pReq->replicas[0].id = htonl(1);
|
||||
pReq->replicas[0].port = htonl(9113);
|
||||
strcpy(pReq->replicas[0].fqdn, "localhost");
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestMnode, 03_Drop_Mnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropMnodeReq);
|
||||
|
||||
SDDropMnodeReq* pReq = (SDDropMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_INVALID_OPTION);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropMnodeReq);
|
||||
|
||||
SDDropMnodeReq* pReq = (SDDropMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropMnodeReq);
|
||||
|
||||
SDDropMnodeReq* pReq = (SDDropMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_NOT_DEPLOYED);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDAlterMnodeReq);
|
||||
|
||||
SDAlterMnodeReq* pReq = (SDAlterMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
pReq->replica = 1;
|
||||
pReq->replicas[0].id = htonl(1);
|
||||
pReq->replicas[0].port = htonl(9113);
|
||||
strcpy(pReq->replicas[0].fqdn, "localhost");
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_NOT_DEPLOYED);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateMnodeReq);
|
||||
|
||||
SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
pReq->replica = 2;
|
||||
pReq->replicas[0].id = htonl(1);
|
||||
pReq->replicas[0].port = htonl(9113);
|
||||
strcpy(pReq->replicas[0].fqdn, "localhost");
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
}
|
|
@ -1,301 +0,0 @@
|
|||
/**
|
||||
* @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 DndTestMnode : public ::testing::Test {
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
public:
|
||||
static void SetUpTestSuite() {
|
||||
test.Init("/tmp/dnode_test_mnode1", 9061);
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9061";
|
||||
|
||||
server2.Start("/tmp/dnode_test_mnode2", fqdn, 9062, firstEp);
|
||||
server3.Start("/tmp/dnode_test_mnode3", fqdn, 9063, firstEp);
|
||||
server4.Start("/tmp/dnode_test_mnode4", fqdn, 9064, firstEp);
|
||||
server5.Start("/tmp/dnode_test_mnode5", fqdn, 9065, firstEp);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
server2.Stop();
|
||||
server3.Stop();
|
||||
server4.Stop();
|
||||
server5.Stop();
|
||||
test.Cleanup();
|
||||
}
|
||||
|
||||
static Testbase test;
|
||||
static TestServer server2;
|
||||
static TestServer server3;
|
||||
static TestServer server4;
|
||||
static TestServer server5;
|
||||
};
|
||||
|
||||
Testbase DndTestMnode::test;
|
||||
TestServer DndTestMnode::server2;
|
||||
TestServer DndTestMnode::server3;
|
||||
TestServer DndTestMnode::server4;
|
||||
TestServer DndTestMnode::server5;
|
||||
|
||||
TEST_F(DndTestMnode, 01_ShowDnode) {
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_MNODE, "");
|
||||
CHECK_META("show mnodes", 5);
|
||||
|
||||
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_BINARY, 12 + VARSTR_HEADER_SIZE, "role");
|
||||
CHECK_SCHEMA(3, TSDB_DATA_TYPE_TIMESTAMP, 8, "role_time");
|
||||
CHECK_SCHEMA(4, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9061", TSDB_EP_LEN);
|
||||
CheckBinary("master", 12);
|
||||
CheckInt64(0);
|
||||
CheckTimestamp();
|
||||
}
|
||||
|
||||
TEST_F(DndTestMnode, 02_Create_Mnode_Invalid_Id) {
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateMnodeMsg);
|
||||
|
||||
SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MNODE_ALREADY_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestMnode, 03_Create_Mnode_Invalid_Id) {
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateMnodeMsg);
|
||||
|
||||
SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestMnode, 04_Create_Mnode) {
|
||||
{
|
||||
// create dnode
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9062);
|
||||
|
||||
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 mnode
|
||||
int32_t contLen = sizeof(SMCreateMnodeMsg);
|
||||
|
||||
SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_MNODE, "");
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckInt16(2);
|
||||
CheckBinary("localhost:9061", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9062", TSDB_EP_LEN);
|
||||
CheckBinary("master", 12);
|
||||
CheckBinary("slave", 12);
|
||||
CheckInt64(0);
|
||||
CheckInt64(0);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
}
|
||||
|
||||
{
|
||||
// drop mnode
|
||||
int32_t contLen = sizeof(SMDropMnodeMsg);
|
||||
|
||||
SMDropMnodeMsg* pReq = (SMDropMnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_MNODE, "");
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9061", TSDB_EP_LEN);
|
||||
CheckBinary("master", 12);
|
||||
CheckInt64(0);
|
||||
CheckTimestamp();
|
||||
}
|
||||
}
|
||||
// {
|
||||
// int32_t contLen = sizeof(SDropDnodeMsg);
|
||||
|
||||
// SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(contLen);
|
||||
// pReq->dnodeId = htonl(2);
|
||||
|
||||
// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_DNODE, pReq, contLen);
|
||||
// ASSERT_NE(pMsg, nullptr);
|
||||
// ASSERT_EQ(pMsg->code, 0);
|
||||
// }
|
||||
|
||||
// test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||
// CHECK_META("show dnodes", 7);
|
||||
// test.SendShowRetrieveMsg();
|
||||
// EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
// CheckInt16(1);
|
||||
// CheckBinary("localhost:9061", TSDB_EP_LEN);
|
||||
// CheckInt16(0);
|
||||
// CheckInt16(1);
|
||||
// CheckBinary("ready", 10);
|
||||
// CheckTimestamp();
|
||||
// CheckBinary("", 24);
|
||||
|
||||
// {
|
||||
// int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
// SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
// strcpy(pReq->ep, "localhost:9063");
|
||||
|
||||
// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
// ASSERT_NE(pMsg, nullptr);
|
||||
// ASSERT_EQ(pMsg->code, 0);
|
||||
// }
|
||||
|
||||
// {
|
||||
// int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
// SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
// strcpy(pReq->ep, "localhost:9064");
|
||||
|
||||
// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
// ASSERT_NE(pMsg, nullptr);
|
||||
// ASSERT_EQ(pMsg->code, 0);
|
||||
// }
|
||||
|
||||
// {
|
||||
// int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
// SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
// strcpy(pReq->ep, "localhost: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, "");
|
||||
// CHECK_META("show dnodes", 7);
|
||||
// test.SendShowRetrieveMsg();
|
||||
// EXPECT_EQ(test.GetShowRows(), 4);
|
||||
|
||||
// CheckInt16(1);
|
||||
// CheckInt16(3);
|
||||
// CheckInt16(4);
|
||||
// CheckInt16(5);
|
||||
// CheckBinary("localhost:9061", TSDB_EP_LEN);
|
||||
// CheckBinary("localhost:9063", TSDB_EP_LEN);
|
||||
// CheckBinary("localhost:9064", TSDB_EP_LEN);
|
||||
// CheckBinary("localhost:9065", TSDB_EP_LEN);
|
||||
// CheckInt16(0);
|
||||
// CheckInt16(0);
|
||||
// CheckInt16(0);
|
||||
// CheckInt16(0);
|
||||
// CheckInt16(1);
|
||||
// CheckInt16(1);
|
||||
// CheckInt16(1);
|
||||
// CheckInt16(1);
|
||||
// CheckBinary("ready", 10);
|
||||
// CheckBinary("ready", 10);
|
||||
// CheckBinary("ready", 10);
|
||||
// CheckBinary("ready", 10);
|
||||
// CheckTimestamp();
|
||||
// CheckTimestamp();
|
||||
// CheckTimestamp();
|
||||
// CheckTimestamp();
|
||||
// CheckBinary("", 24);
|
||||
// CheckBinary("", 24);
|
||||
// CheckBinary("", 24);
|
||||
// CheckBinary("", 24);
|
||||
|
||||
// // restart
|
||||
// uInfo("stop all server");
|
||||
// test.Restart();
|
||||
// server2.Restart();
|
||||
// server3.Restart();
|
||||
// server4.Restart();
|
||||
// server5.Restart();
|
||||
|
||||
// taosMsleep(1300);
|
||||
// test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||
// CHECK_META("show dnodes", 7);
|
||||
// test.SendShowRetrieveMsg();
|
||||
// EXPECT_EQ(test.GetShowRows(), 4);
|
||||
|
||||
// CheckInt16(1);
|
||||
// CheckInt16(3);
|
||||
// CheckInt16(4);
|
||||
// CheckInt16(5);
|
||||
// CheckBinary("localhost:9061", TSDB_EP_LEN);
|
||||
// CheckBinary("localhost:9063", TSDB_EP_LEN);
|
||||
// CheckBinary("localhost:9064", TSDB_EP_LEN);
|
||||
// CheckBinary("localhost:9065", TSDB_EP_LEN);
|
||||
// CheckInt16(0);
|
||||
// CheckInt16(0);
|
||||
// CheckInt16(0);
|
||||
// CheckInt16(0);
|
||||
// CheckInt16(1);
|
||||
// CheckInt16(1);
|
||||
// CheckInt16(1);
|
||||
// CheckInt16(1);
|
||||
// CheckBinary("ready", 10);
|
||||
// CheckBinary("ready", 10);
|
||||
// CheckBinary("ready", 10);
|
||||
// CheckBinary("ready", 10);
|
||||
// CheckTimestamp();
|
||||
// CheckTimestamp();
|
||||
// CheckTimestamp();
|
||||
// CheckTimestamp();
|
||||
// CheckBinary("", 24);
|
||||
// CheckBinary("", 24);
|
||||
// CheckBinary("", 24);
|
||||
// CheckBinary("", 24);
|
||||
// }
|
|
@ -1,11 +0,0 @@
|
|||
aux_source_directory(. PROFILE_SRC)
|
||||
add_executable(dnode_test_profile ${PROFILE_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_profile
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME dnode_test_profile
|
||||
COMMAND dnode_test_profile
|
||||
)
|
|
@ -1,5 +1,5 @@
|
|||
aux_source_directory(. QTEST_SRC)
|
||||
add_executable(dnode_test_qnode ${QTEST_SRC})
|
||||
aux_source_directory(. DQTEST_SRC)
|
||||
add_executable(dnode_test_qnode ${DQTEST_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_qnode
|
||||
PUBLIC sut
|
||||
|
|
|
@ -0,0 +1,133 @@
|
|||
/**
|
||||
* @file dqnode.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module qnode tests
|
||||
* @version 1.0
|
||||
* @date 2022-01-05
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sut.h"
|
||||
|
||||
class DndTestQnode : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_qnode", 9111); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
};
|
||||
|
||||
Testbase DndTestQnode::test;
|
||||
|
||||
TEST_F(DndTestQnode, 01_Create_Qnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateQnodeReq);
|
||||
|
||||
SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_INVALID_OPTION);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateQnodeReq);
|
||||
|
||||
SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateQnodeReq);
|
||||
|
||||
SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED);
|
||||
}
|
||||
|
||||
test.Restart();
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateQnodeReq);
|
||||
|
||||
SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestQnode, 02_Drop_Qnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropQnodeReq);
|
||||
|
||||
SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_INVALID_OPTION);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropQnodeReq);
|
||||
|
||||
SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropQnodeReq);
|
||||
|
||||
SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_NOT_DEPLOYED);
|
||||
}
|
||||
|
||||
test.Restart();
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropQnodeReq);
|
||||
|
||||
SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_NOT_DEPLOYED);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateQnodeReq);
|
||||
|
||||
SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
}
|
|
@ -1,154 +0,0 @@
|
|||
/**
|
||||
* @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();
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
aux_source_directory(. SHOW_SRC)
|
||||
add_executable(dnode_test_show ${SHOW_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_show
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME dnode_test_show
|
||||
COMMAND dnode_test_show
|
||||
)
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue