merge from 3.0
This commit is contained in:
commit
66b6e1473c
|
@ -0,0 +1,9 @@
|
|||
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.209.3/containers/cpp/.devcontainer/base.Dockerfile
|
||||
|
||||
# [Choice] Debian / Ubuntu version (use Debian 11/9, Ubuntu 18.04/21.04 on local arm64/Apple Silicon): debian-11, debian-10, debian-9, ubuntu-21.04, ubuntu-20.04, ubuntu-18.04
|
||||
ARG VARIANT="bullseye"
|
||||
FROM mcr.microsoft.com/vscode/devcontainers/cpp:0-${VARIANT}
|
||||
|
||||
# [Optional] Uncomment this section to install additional packages.
|
||||
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
||||
# && apt-get -y install --no-install-recommends <your-package-list-here>
|
|
@ -0,0 +1,32 @@
|
|||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
|
||||
// https://github.com/microsoft/vscode-dev-containers/tree/v0.209.3/containers/cpp
|
||||
{
|
||||
"name": "C++",
|
||||
"build": {
|
||||
"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" }
|
||||
},
|
||||
"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",
|
||||
"ms-vscode.cmake-tools",
|
||||
"austin.code-gnu-global",
|
||||
"visualstudioexptteam.vscodeintel"
|
||||
],
|
||||
|
||||
// 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": "vscode"
|
||||
}
|
|
@ -25,8 +25,10 @@ if(${BUILD_TEST})
|
|||
enable_testing()
|
||||
endif(${BUILD_TEST})
|
||||
add_subdirectory(source)
|
||||
add_subdirectory(tools)
|
||||
add_subdirectory(tests)
|
||||
|
||||
# docs
|
||||
add_subdirectory(docs)
|
||||
|
||||
# tests (TODO)
|
||||
# tests (TODO)
|
||||
|
|
|
@ -42,7 +42,6 @@ def pre_test(){
|
|||
killall -9 gdb || echo "no gdb running"
|
||||
killall -9 python3.8 || echo "no python program running"
|
||||
cd ${WKC}
|
||||
git reset --hard HEAD~10 >/dev/null
|
||||
'''
|
||||
script {
|
||||
if (env.CHANGE_TARGET == 'master') {
|
||||
|
@ -75,45 +74,13 @@ def pre_test(){
|
|||
git pull >/dev/null
|
||||
git fetch origin +refs/pull/${CHANGE_ID}/merge
|
||||
git checkout -qf FETCH_HEAD
|
||||
git clean -dfx
|
||||
'''
|
||||
script {
|
||||
if (env.CHANGE_TARGET == 'master') {
|
||||
sh '''
|
||||
cd ${WK}
|
||||
git checkout master
|
||||
'''
|
||||
}
|
||||
else if(env.CHANGE_TARGET == '2.0'){
|
||||
sh '''
|
||||
cd ${WK}
|
||||
git checkout 2.0
|
||||
'''
|
||||
}
|
||||
else if(env.CHANGE_TARGET == '3.0'){
|
||||
sh '''
|
||||
cd ${WK}
|
||||
git checkout 3.0
|
||||
'''
|
||||
}
|
||||
else{
|
||||
sh '''
|
||||
cd ${WK}
|
||||
git checkout develop
|
||||
'''
|
||||
}
|
||||
}
|
||||
sh '''
|
||||
cd ${WK}
|
||||
git pull >/dev/null
|
||||
git clean -dfx
|
||||
export TZ=Asia/Harbin
|
||||
date
|
||||
rm -rf debug
|
||||
mkdir debug
|
||||
cd debug
|
||||
cmake .. > /dev/null
|
||||
make > /dev/null
|
||||
make install > /dev/null
|
||||
make -j4> /dev/null
|
||||
|
||||
'''
|
||||
return 1
|
||||
|
@ -124,11 +91,11 @@ pipeline {
|
|||
options { skipDefaultCheckout() }
|
||||
environment{
|
||||
WK = '/var/lib/jenkins/workspace/TDinternal'
|
||||
WKC= '/var/lib/jenkins/workspace/TDinternal/community'
|
||||
WKC= '/var/lib/jenkins/workspace/TDengine'
|
||||
}
|
||||
stages {
|
||||
stage('pre_build'){
|
||||
agent{label 'master'}
|
||||
agent{label 'slave3_0'}
|
||||
options { skipDefaultCheckout() }
|
||||
when {
|
||||
changeRequest()
|
||||
|
|
|
@ -37,12 +37,25 @@ option(
|
|||
off
|
||||
)
|
||||
|
||||
|
||||
option(
|
||||
BUILD_WITH_NURAFT
|
||||
"If build with NuRaft"
|
||||
OFF
|
||||
)
|
||||
|
||||
option(
|
||||
BUILD_WITH_UV
|
||||
"If build with libuv"
|
||||
OFF
|
||||
)
|
||||
|
||||
option(
|
||||
BUILD_WITH_CRAFT
|
||||
"If build with canonical-raft"
|
||||
OFF
|
||||
)
|
||||
|
||||
option(
|
||||
BUILD_DEPENDENCY_TESTS
|
||||
"If build dependency tests"
|
||||
|
@ -54,3 +67,9 @@ option(
|
|||
"If use doxygen build documents"
|
||||
OFF
|
||||
)
|
||||
|
||||
option(
|
||||
BUILD_WITH_INVERTEDINDEX
|
||||
"If use invertedIndex"
|
||||
ON
|
||||
)
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
# canonical-raft
|
||||
ExternalProject_Add(craft
|
||||
GIT_REPOSITORY https://github.com/canonical/raft.git
|
||||
GIT_TAG v0.11.2
|
||||
SOURCE_DIR "${CMAKE_CONTRIB_DIR}/craft"
|
||||
BINARY_DIR "${CMAKE_CONTRIB_DIR}/craft"
|
||||
#BUILD_IN_SOURCE TRUE
|
||||
# https://answers.ros.org/question/333125/how-to-include-external-automakeautoconf-projects-into-ament_cmake/
|
||||
CONFIGURE_COMMAND COMMAND autoreconf -i COMMAND ./configure --enable-example
|
||||
BUILD_COMMAND "$(MAKE)"
|
||||
INSTALL_COMMAND ""
|
||||
TEST_COMMAND ""
|
||||
)
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
# libuv
|
||||
ExternalProject_Add(libuv
|
||||
GIT_REPOSITORY https://github.com/libuv/libuv.git
|
||||
GIT_TAG v1.42.0
|
||||
SOURCE_DIR "${CMAKE_CONTRIB_DIR}/libuv"
|
||||
BINARY_DIR ""
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
TEST_COMMAND ""
|
||||
)
|
|
@ -34,10 +34,21 @@ if(${BUILD_WITH_ROCKSDB})
|
|||
add_definitions(-DUSE_ROCKSDB)
|
||||
endif(${BUILD_WITH_ROCKSDB})
|
||||
|
||||
# canonical-raft
|
||||
if(${BUILD_WITH_CRAFT})
|
||||
cat("${CMAKE_SUPPORT_DIR}/craft_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
SET(BUILD_WITH_UV ON CACHE BOOL "craft need libuv" FORCE)
|
||||
endif(${BUILD_WITH_CRAFT})
|
||||
|
||||
#libuv
|
||||
if(${BUILD_WITH_UV})
|
||||
cat("${CMAKE_SUPPORT_DIR}/libuv_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
endif(${BUILD_WITH_UV})
|
||||
|
||||
# bdb
|
||||
if(${BUILD_WITH_BDB})
|
||||
cat("${CMAKE_SUPPORT_DIR}/bdb_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
endif(${BUILD_WITH_DBD})
|
||||
endif(${BUILD_WITH_BDB})
|
||||
|
||||
# sqlite
|
||||
if(${BUILD_WITH_SQLITE})
|
||||
|
@ -144,6 +155,23 @@ if(${BUILD_WITH_NURAFT})
|
|||
add_subdirectory(nuraft)
|
||||
endif(${BUILD_WITH_NURAFT})
|
||||
|
||||
# CRAFT
|
||||
if(${BUILD_WITH_CRAFT})
|
||||
add_library(craft STATIC IMPORTED GLOBAL)
|
||||
set_target_properties(craft PROPERTIES
|
||||
IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/craft/.libs/libraft.a"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/craft/include"
|
||||
)
|
||||
# target_link_libraries(craft
|
||||
# INTERFACE pthread
|
||||
# )
|
||||
endif(${BUILD_WITH_CRAFT})
|
||||
|
||||
# LIBUV
|
||||
if(${BUILD_WITH_UV})
|
||||
add_subdirectory(libuv)
|
||||
endif(${BUILD_WITH_UV})
|
||||
|
||||
# BDB
|
||||
if(${BUILD_WITH_BDB})
|
||||
add_library(bdb STATIC IMPORTED GLOBAL)
|
||||
|
|
|
@ -15,4 +15,8 @@ if(${BUILD_WITH_SQLITE})
|
|||
add_subdirectory(sqlite)
|
||||
endif(${BUILD_WITH_SQLITE})
|
||||
|
||||
if(${BUILD_WITH_CRAFT})
|
||||
add_subdirectory(craft)
|
||||
endif(${BUILD_WITH_CRAFT})
|
||||
|
||||
add_subdirectory(tdev)
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
add_executable(simulate_vnode "simulate_vnode.c")
|
||||
target_link_libraries(simulate_vnode PUBLIC craft lz4 uv_a)
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
rm -rf 127.0.0.1*
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
|
||||
make craft:
|
||||
|
||||
sudo apt-get install libuv1-dev liblz4-dev
|
||||
autoreconf -i
|
||||
./configure --enable-example
|
||||
make
|
||||
|
||||
|
||||
start:
|
||||
|
||||
./simulate_vnode 10000 10001 10002
|
||||
./simulate_vnode 10001 10000 10002
|
||||
./simulate_vnode 10002 10000 10001
|
|
@ -0,0 +1,252 @@
|
|||
#include <stdio.h>
|
||||
#include <raft.h>
|
||||
#include <raft/uv.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
|
||||
const char* exe_name;
|
||||
|
||||
// simulate ------------------------
|
||||
typedef struct SVnode {
|
||||
int vid;
|
||||
} SVnode;
|
||||
|
||||
|
||||
#define VNODE_COUNT 10
|
||||
SVnode vnodes[VNODE_COUNT];
|
||||
|
||||
int vnodeApplyWMsg(SVnode *pVnode, char *pMsg, void **pRsp) {
|
||||
printf("put value to tsdb, vid:%d msg:%s \n", pVnode->vid, pMsg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int applyCB(struct raft_fsm *fsm,
|
||||
const struct raft_buffer *buf,
|
||||
void **result) {
|
||||
char *msg = (char*)buf->base;
|
||||
//printf("%s \n", msg);
|
||||
|
||||
// parse msg
|
||||
char* context;
|
||||
char* token = strtok_r(msg, ":", &context);
|
||||
int vid = atoi(token);
|
||||
|
||||
token = strtok_r(NULL, ":", &context);
|
||||
char *value = token;
|
||||
|
||||
SVnode* tmp_vnodes = (SVnode*)(fsm->data);
|
||||
vnodeApplyWMsg(&tmp_vnodes[vid], value, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Config ------------------------
|
||||
#define HOST_LEN 32
|
||||
#define MAX_PEERS 10
|
||||
typedef struct Address {
|
||||
char host[HOST_LEN];
|
||||
uint32_t port;
|
||||
} Address;
|
||||
|
||||
uint64_t raftId(Address *addr) {
|
||||
// test in a single machine, port is unique
|
||||
// if in multi machines, use host and port
|
||||
return addr->port;
|
||||
}
|
||||
|
||||
typedef struct Config {
|
||||
Address me;
|
||||
Address peers[MAX_PEERS];
|
||||
int peer_count;
|
||||
} Config;
|
||||
|
||||
Config gConf;
|
||||
|
||||
void printConf(Config *c) {
|
||||
printf("me: %s:%u \n", c->me.host, c->me.port);
|
||||
for (int i = 0; i < c->peer_count; ++i) {
|
||||
printf("peer%d: %s:%u \n", i, c->peers[i].host, c->peers[i].port);
|
||||
}
|
||||
}
|
||||
|
||||
// RaftServer ------------------------
|
||||
typedef struct RaftServer {
|
||||
struct uv_loop_s loop;
|
||||
struct raft_uv_transport transport;
|
||||
struct raft_io io;
|
||||
struct raft_fsm fsm;
|
||||
struct raft raft;
|
||||
struct raft_configuration conf;
|
||||
} RaftServer;
|
||||
|
||||
RaftServer gRaftServer;
|
||||
|
||||
static void* startRaftServer(void *param) {
|
||||
//RaftServer* rs = (RaftServer*)param;
|
||||
RaftServer* rs = &gRaftServer;
|
||||
raft_start(&rs->raft);
|
||||
uv_run(&rs->loop, UV_RUN_DEFAULT);
|
||||
}
|
||||
|
||||
static 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";
|
||||
}
|
||||
|
||||
static void printRaftState(struct raft *r) {
|
||||
printf("\n");
|
||||
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("\n");
|
||||
}
|
||||
|
||||
// console -----------------------------------------
|
||||
#define PROPOSE_VALUE_LEN 128
|
||||
static void proposeValue(struct raft *r) {
|
||||
struct raft_buffer buf;
|
||||
|
||||
// need free
|
||||
buf.len = PROPOSE_VALUE_LEN;
|
||||
buf.base = raft_malloc(buf.len);
|
||||
|
||||
// mock ts value
|
||||
int vid = rand() % VNODE_COUNT;
|
||||
snprintf(buf.base, buf.len, "%d:value_%ld", vid, time(NULL));
|
||||
|
||||
printf("propose value: %s \n", (char*)buf.base);
|
||||
|
||||
// need free
|
||||
struct raft_apply *req = raft_malloc(sizeof(struct raft_apply));
|
||||
raft_apply(r, req, &buf, 1, NULL);
|
||||
}
|
||||
|
||||
static void* console(void *param) {
|
||||
while (1) {
|
||||
// notice! memory buffer overflow!
|
||||
char buf[128];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
fgets(buf, 128, stdin);
|
||||
if (strlen(buf) == 1) {
|
||||
continue;
|
||||
}
|
||||
buf[strlen(buf)-1] = '\0';
|
||||
|
||||
// do not use strcmp
|
||||
if (strcmp(buf, "state") == 0) {
|
||||
printRaftState(&gRaftServer.raft);
|
||||
|
||||
} else if (strcmp(buf, "put") == 0) {
|
||||
proposeValue(&gRaftServer.raft);
|
||||
|
||||
} else {
|
||||
printf("unknown command: [%s], support command: state, put \n", buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
void usage() {
|
||||
printf("\n");
|
||||
printf("%s my_port peer1_port peer2_port ... \n", exe_name);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
srand(time(NULL));
|
||||
|
||||
exe_name = argv[0];
|
||||
if (argc < 2) {
|
||||
usage();
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// read conf from argv
|
||||
strncpy(gConf.me.host, "127.0.0.1", HOST_LEN);
|
||||
sscanf(argv[1], "%u", &gConf.me.port);
|
||||
|
||||
gConf.peer_count = 0;
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
strncpy(gConf.peers[gConf.peer_count].host, "127.0.0.1", HOST_LEN);
|
||||
sscanf(argv[i], "%u", &gConf.peers[gConf.peer_count].port);
|
||||
gConf.peer_count++;
|
||||
}
|
||||
printConf(&gConf);
|
||||
|
||||
// mkdir
|
||||
char dir[128];
|
||||
snprintf(dir, sizeof(dir), "./%s_%u", gConf.me.host, gConf.me.port);
|
||||
|
||||
char cmd[128];
|
||||
snprintf(cmd, sizeof(cmd), "rm -rf ./%s", dir);
|
||||
system(cmd);
|
||||
snprintf(cmd, sizeof(cmd), "mkdir -p ./%s", dir);
|
||||
system(cmd);
|
||||
|
||||
// init io
|
||||
uv_loop_init(&gRaftServer.loop);
|
||||
raft_uv_tcp_init(&gRaftServer.transport, &gRaftServer.loop);
|
||||
raft_uv_init(&gRaftServer.io, &gRaftServer.loop, dir, &gRaftServer.transport);
|
||||
|
||||
// init fsm
|
||||
gRaftServer.fsm.apply = applyCB;
|
||||
gRaftServer.fsm.data = vnodes;
|
||||
for (int i = 0; i < VNODE_COUNT; ++i) {
|
||||
vnodes[i].vid = i;
|
||||
}
|
||||
|
||||
// init raft instance with io and fsm
|
||||
char address_buf[128];
|
||||
snprintf(address_buf, sizeof(address_buf), "%s:%u", gConf.me.host, gConf.me.port);
|
||||
|
||||
// test in a single machine, port is unique
|
||||
uint64_t raft_id = raftId(&gConf.me);
|
||||
raft_init(&gRaftServer.raft, &gRaftServer.io, &gRaftServer.fsm, raft_id, address_buf);
|
||||
//raft_init(&gRaftServer.raft, &gRaftServer.io, &gRaftServer.fsm, 11, "127.0.0.1:9000");
|
||||
|
||||
// init cluster configuration
|
||||
struct raft_configuration conf;
|
||||
raft_configuration_init(&conf);
|
||||
raft_configuration_add(&conf, raftId(&gConf.me), address_buf, RAFT_VOTER);
|
||||
for (int i = 0; i < gConf.peer_count; ++i) {
|
||||
char address_buf[128];
|
||||
snprintf(address_buf, sizeof(address_buf), "%s:%u", gConf.peers[i].host, gConf.peers[i].port);
|
||||
raft_configuration_add(&conf, raftId(&gConf.peers[i]), address_buf, RAFT_VOTER);
|
||||
}
|
||||
raft_bootstrap(&gRaftServer.raft, &conf);
|
||||
|
||||
// start raft server and loop
|
||||
pthread_t tid;
|
||||
pthread_create(&tid, NULL, startRaftServer, &gRaftServer);
|
||||
|
||||
// simulate console
|
||||
pthread_t tid2;
|
||||
pthread_create(&tid2, NULL, console, NULL);
|
||||
|
||||
while (1) {
|
||||
sleep(10);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -39,7 +39,7 @@ typedef void **TAOS_ROW;
|
|||
#define TSDB_DATA_TYPE_BIGINT 5 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_FLOAT 6 // 4 bytes
|
||||
#define TSDB_DATA_TYPE_DOUBLE 7 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_BINARY 8 // string
|
||||
#define TSDB_DATA_TYPE_BINARY 8 // string, alias for varchar
|
||||
#define TSDB_DATA_TYPE_TIMESTAMP 9 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_NCHAR 10 // unicode string
|
||||
#define TSDB_DATA_TYPE_UTINYINT 11 // 1 byte
|
||||
|
@ -47,10 +47,10 @@ typedef void **TAOS_ROW;
|
|||
#define TSDB_DATA_TYPE_UINT 13 // 4 bytes
|
||||
#define TSDB_DATA_TYPE_UBIGINT 14 // 8 bytes
|
||||
#define TSDB_DATA_TYPE_VARCHAR 15 // string
|
||||
#define TSDB_DATA_TYPE_JSON 16 // json
|
||||
#define TSDB_DATA_TYPE_DECIMAL 17 // decimal
|
||||
#define TSDB_DATA_TYPE_BLOB 18 // binary string
|
||||
#define TSDB_DATA_TYPE_LONGBLOB 19 // long binary string
|
||||
#define TSDB_DATA_TYPE_VARBINARY 16 // binary
|
||||
#define TSDB_DATA_TYPE_JSON 17 // json
|
||||
#define TSDB_DATA_TYPE_DECIMAL 18 // decimal
|
||||
#define TSDB_DATA_TYPE_BLOB 19 // binary
|
||||
|
||||
typedef enum {
|
||||
TSDB_OPTION_LOCALE,
|
||||
|
@ -61,10 +61,27 @@ typedef enum {
|
|||
TSDB_MAX_OPTIONS
|
||||
} TSDB_OPTION;
|
||||
|
||||
typedef enum {
|
||||
TSDB_SML_UNKNOWN_PROTOCOL = 0,
|
||||
TSDB_SML_LINE_PROTOCOL = 1,
|
||||
TSDB_SML_TELNET_PROTOCOL = 2,
|
||||
TSDB_SML_JSON_PROTOCOL = 3,
|
||||
} TSDB_SML_PROTOCOL_TYPE;
|
||||
|
||||
typedef enum {
|
||||
TSDB_SML_TIMESTAMP_NOT_CONFIGURED = 0,
|
||||
TSDB_SML_TIMESTAMP_HOURS,
|
||||
TSDB_SML_TIMESTAMP_MINUTES,
|
||||
TSDB_SML_TIMESTAMP_SECONDS,
|
||||
TSDB_SML_TIMESTAMP_MILLI_SECONDS,
|
||||
TSDB_SML_TIMESTAMP_MICRO_SECONDS,
|
||||
TSDB_SML_TIMESTAMP_NANO_SECONDS,
|
||||
} TSDB_SML_TIMESTAMP_TYPE;
|
||||
|
||||
typedef struct taosField {
|
||||
char name[65];
|
||||
uint8_t type;
|
||||
int16_t bytes;
|
||||
int8_t type;
|
||||
int32_t bytes;
|
||||
} TAOS_FIELD;
|
||||
|
||||
#ifdef _TD_GO_DLL_
|
||||
|
@ -136,37 +153,36 @@ DLL_EXPORT int taos_stmt_close(TAOS_STMT *stmt);
|
|||
DLL_EXPORT char * taos_stmt_errstr(TAOS_STMT *stmt);
|
||||
|
||||
DLL_EXPORT TAOS_RES *taos_query(TAOS *taos, const char *sql);
|
||||
DLL_EXPORT TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen);
|
||||
|
||||
DLL_EXPORT TAOS_ROW taos_fetch_row(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_result_precision(TAOS_RES *res); // get the time precision of result
|
||||
DLL_EXPORT int taos_result_precision(TAOS_RES *res); // get the time precision of result
|
||||
DLL_EXPORT void taos_free_result(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_field_count(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_num_fields(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_affected_rows(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_field_count(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_num_fields(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_affected_rows(TAOS_RES *res);
|
||||
|
||||
DLL_EXPORT TAOS_FIELD *taos_fetch_fields(TAOS_RES *res);
|
||||
DLL_EXPORT int taos_select_db(TAOS *taos, const char *db);
|
||||
DLL_EXPORT int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields);
|
||||
DLL_EXPORT int taos_select_db(TAOS *taos, const char *db);
|
||||
DLL_EXPORT int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields);
|
||||
DLL_EXPORT void taos_stop_query(TAOS_RES *res);
|
||||
DLL_EXPORT bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col);
|
||||
DLL_EXPORT int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows);
|
||||
DLL_EXPORT int taos_validate_sql(TAOS *taos, const char *sql);
|
||||
DLL_EXPORT int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows);
|
||||
DLL_EXPORT int taos_validate_sql(TAOS *taos, const char *sql);
|
||||
|
||||
DLL_EXPORT int* taos_fetch_lengths(TAOS_RES *res);
|
||||
|
||||
// TAOS_RES *taos_list_tables(TAOS *mysql, const char *wild);
|
||||
// TAOS_RES *taos_list_dbs(TAOS *mysql, const char *wild);
|
||||
|
||||
// TODO: the return value should be `const`
|
||||
DLL_EXPORT const char *taos_get_server_info(TAOS *taos);
|
||||
DLL_EXPORT const char *taos_get_client_info();
|
||||
DLL_EXPORT const char *taos_errstr(TAOS_RES *tres);
|
||||
|
||||
DLL_EXPORT int taos_errno(TAOS_RES *tres);
|
||||
DLL_EXPORT const char *taos_errstr(TAOS_RES *tres);
|
||||
DLL_EXPORT int taos_errno(TAOS_RES *tres);
|
||||
|
||||
DLL_EXPORT void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param);
|
||||
DLL_EXPORT void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param);
|
||||
|
||||
typedef void (*TAOS_SUBSCRIBE_CALLBACK)(TAOS_SUB* tsub, TAOS_RES *res, void* param, int code);
|
||||
DLL_EXPORT TAOS_SUB *taos_subscribe(TAOS* taos, int restart, const char* topic, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp, void *param, int interval);
|
||||
typedef void (*__taos_sub_fn_t)(TAOS_SUB* tsub, TAOS_RES *res, void* param, int code);
|
||||
DLL_EXPORT TAOS_SUB *taos_subscribe(TAOS* taos, int restart, const char* topic, const char *sql, __taos_sub_fn_t fp, void *param, int interval);
|
||||
DLL_EXPORT TAOS_RES *taos_consume(TAOS_SUB *tsub);
|
||||
DLL_EXPORT void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress);
|
||||
|
||||
|
@ -175,8 +191,7 @@ DLL_EXPORT TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sql, void (*fp)
|
|||
DLL_EXPORT void taos_close_stream(TAOS_STREAM *tstr);
|
||||
|
||||
DLL_EXPORT int taos_load_table_info(TAOS *taos, const char* tableNameList);
|
||||
|
||||
DLL_EXPORT int taos_insert_lines(TAOS* taos, char* lines[], int numLines);
|
||||
DLL_EXPORT TAOS_RES* taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int protocol, int precision);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_QUERY, "mq-query" )
|
|||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_CONNECT, "mq-connect" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_DISCONNECT, "mq-disconnect" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_SET_CUR, "mq-set-cur" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_RSP_READY, "rsp-ready" )
|
||||
// message from client to mnode
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CONNECT, "connect" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_ACCT, "create-acct" )
|
||||
|
@ -214,8 +215,8 @@ typedef enum _mgmt_table {
|
|||
extern char *taosMsg[];
|
||||
|
||||
typedef struct SBuildTableMetaInput {
|
||||
int32_t vgId;
|
||||
char *tableFullName;
|
||||
int32_t vgId;
|
||||
char *tableFullName;
|
||||
} SBuildTableMetaInput;
|
||||
|
||||
typedef struct SBuildUseDBInput {
|
||||
|
@ -233,9 +234,9 @@ typedef struct {
|
|||
} SEpAddrMsg;
|
||||
|
||||
typedef struct {
|
||||
char* fqdn;
|
||||
char fqdn[TSDB_FQDN_LEN];
|
||||
uint16_t port;
|
||||
} SEpAddr1;
|
||||
} SEpAddr;
|
||||
|
||||
typedef struct {
|
||||
int32_t numOfVnodes;
|
||||
|
@ -260,10 +261,10 @@ typedef struct SSubmitBlk {
|
|||
|
||||
// Submit message for this TSDB
|
||||
typedef struct SSubmitMsg {
|
||||
SMsgHead header;
|
||||
int32_t length;
|
||||
int32_t numOfBlocks;
|
||||
char blocks[];
|
||||
SMsgHead header;
|
||||
int32_t length;
|
||||
int32_t numOfBlocks;
|
||||
char blocks[];
|
||||
} SSubmitMsg;
|
||||
|
||||
typedef struct {
|
||||
|
@ -351,17 +352,17 @@ typedef struct {
|
|||
} SAlterTableMsg;
|
||||
|
||||
typedef struct {
|
||||
SMsgHead head;
|
||||
int64_t uid;
|
||||
int32_t tid;
|
||||
int16_t tversion;
|
||||
int16_t colId;
|
||||
int8_t type;
|
||||
int16_t bytes;
|
||||
int32_t tagValLen;
|
||||
int16_t numOfTags;
|
||||
int32_t schemaLen;
|
||||
char data[];
|
||||
SMsgHead head;
|
||||
int64_t uid;
|
||||
int32_t tid;
|
||||
int16_t tversion;
|
||||
int16_t colId;
|
||||
int8_t type;
|
||||
int16_t bytes;
|
||||
int32_t tagValLen;
|
||||
int16_t numOfTags;
|
||||
int32_t schemaLen;
|
||||
char data[];
|
||||
} SUpdateTableTagValMsg;
|
||||
|
||||
typedef struct {
|
||||
|
@ -405,8 +406,10 @@ typedef struct {
|
|||
} SDropUserMsg, SDropAcctMsg;
|
||||
|
||||
typedef struct {
|
||||
int8_t type;
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_PASSWORD_LEN];
|
||||
int8_t superUser; // denote if it is a super user or not
|
||||
int32_t reserve[8];
|
||||
} SCreateUserMsg, SAlterUserMsg;
|
||||
|
||||
|
@ -422,7 +425,7 @@ typedef struct {
|
|||
int32_t contLen;
|
||||
int32_t vgId;
|
||||
uint64_t uid;
|
||||
char tableFname[TSDB_TABLE_FNAME_LEN];
|
||||
char tableFname[TSDB_TABLE_FNAME_LEN];
|
||||
} SDropSTableMsg;
|
||||
|
||||
typedef struct SColIndex {
|
||||
|
@ -435,7 +438,7 @@ typedef struct SColIndex {
|
|||
typedef struct SColumnFilterInfo {
|
||||
int16_t lowerRelOptr;
|
||||
int16_t upperRelOptr;
|
||||
int16_t filterstr; // denote if current column is char(binary/nchar)
|
||||
int16_t filterstr; // denote if current column is char(binary/nchar)
|
||||
|
||||
union {
|
||||
struct {
|
||||
|
@ -454,9 +457,9 @@ typedef struct SColumnFilterInfo {
|
|||
} SColumnFilterInfo;
|
||||
|
||||
typedef struct SColumnFilterList {
|
||||
int16_t numOfFilters;
|
||||
union{
|
||||
int64_t placeholder;
|
||||
int16_t numOfFilters;
|
||||
union {
|
||||
int64_t placeholder;
|
||||
SColumnFilterInfo *filterInfo;
|
||||
};
|
||||
} SColumnFilterList;
|
||||
|
@ -465,10 +468,10 @@ typedef struct SColumnFilterList {
|
|||
* But for data in vnode side, we need all the following information.
|
||||
*/
|
||||
typedef struct SColumnInfo {
|
||||
int16_t colId;
|
||||
int16_t type;
|
||||
int16_t bytes;
|
||||
SColumnFilterList flist;
|
||||
int16_t colId;
|
||||
int16_t type;
|
||||
int16_t bytes;
|
||||
SColumnFilterList flist;
|
||||
} SColumnInfo;
|
||||
|
||||
typedef struct STableIdInfo {
|
||||
|
@ -482,14 +485,14 @@ typedef struct STimeWindow {
|
|||
} STimeWindow;
|
||||
|
||||
typedef struct {
|
||||
int32_t tsOffset; // offset value in current msg body, NOTE: ts list is compressed
|
||||
int32_t tsLen; // total length of ts comp block
|
||||
int32_t tsNumOfBlocks; // ts comp block numbers
|
||||
int32_t tsOrder; // ts comp block order
|
||||
int32_t tsOffset; // offset value in current msg body, NOTE: ts list is compressed
|
||||
int32_t tsLen; // total length of ts comp block
|
||||
int32_t tsNumOfBlocks; // ts comp block numbers
|
||||
int32_t tsOrder; // ts comp block order
|
||||
} STsBufInfo;
|
||||
|
||||
typedef struct SInterval {
|
||||
int32_t tz; // query client timezone
|
||||
int32_t tz; // query client timezone
|
||||
char intervalUnit;
|
||||
char slidingUnit;
|
||||
char offsetUnit;
|
||||
|
@ -499,48 +502,48 @@ typedef struct SInterval {
|
|||
} SInterval;
|
||||
|
||||
typedef struct {
|
||||
SMsgHead head;
|
||||
char version[TSDB_VERSION_LEN];
|
||||
SMsgHead head;
|
||||
char version[TSDB_VERSION_LEN];
|
||||
|
||||
bool stableQuery; // super table query or not
|
||||
bool topBotQuery; // TODO used bitwise flag
|
||||
bool interpQuery; // interp query or not
|
||||
bool groupbyColumn; // denote if this is a groupby normal column query
|
||||
bool hasTagResults; // if there are tag values in final result or not
|
||||
bool timeWindowInterpo;// if the time window start/end required interpolation
|
||||
bool queryBlockDist; // if query data block distribution
|
||||
bool stabledev; // super table stddev query
|
||||
bool tsCompQuery; // is tscomp query
|
||||
bool simpleAgg;
|
||||
bool pointInterpQuery; // point interpolation query
|
||||
bool needReverseScan; // need reverse scan
|
||||
bool stateWindow; // state window flag
|
||||
bool stableQuery; // super table query or not
|
||||
bool topBotQuery; // TODO used bitwise flag
|
||||
bool interpQuery; // interp query or not
|
||||
bool groupbyColumn; // denote if this is a groupby normal column query
|
||||
bool hasTagResults; // if there are tag values in final result or not
|
||||
bool timeWindowInterpo; // if the time window start/end required interpolation
|
||||
bool queryBlockDist; // if query data block distribution
|
||||
bool stabledev; // super table stddev query
|
||||
bool tsCompQuery; // is tscomp query
|
||||
bool simpleAgg;
|
||||
bool pointInterpQuery; // point interpolation query
|
||||
bool needReverseScan; // need reverse scan
|
||||
bool stateWindow; // state window flag
|
||||
|
||||
STimeWindow window;
|
||||
int32_t numOfTables;
|
||||
int16_t order;
|
||||
int16_t orderColId;
|
||||
int16_t numOfCols; // the number of columns will be load from vnode
|
||||
int16_t numOfCols; // the number of columns will be load from vnode
|
||||
SInterval interval;
|
||||
// SSessionWindow sw; // session window
|
||||
int16_t tagCondLen; // tag length in current query
|
||||
int16_t colCondLen; // column length in current query
|
||||
int16_t numOfGroupCols; // num of group by columns
|
||||
int16_t orderByIdx;
|
||||
int16_t orderType; // used in group by xx order by xxx
|
||||
int64_t vgroupLimit; // limit the number of rows for each table, used in order by + limit in stable projection query.
|
||||
int16_t prjOrder; // global order in super table projection query.
|
||||
int64_t limit;
|
||||
int64_t offset;
|
||||
int32_t queryType; // denote another query process
|
||||
int16_t numOfOutput; // final output columns numbers
|
||||
int16_t fillType; // interpolate type
|
||||
int64_t fillVal; // default value array list
|
||||
int32_t secondStageOutput;
|
||||
STsBufInfo tsBuf; // tsBuf info
|
||||
int32_t numOfTags; // number of tags columns involved
|
||||
int32_t sqlstrLen; // sql query string
|
||||
int32_t prevResultLen; // previous result length
|
||||
// SSessionWindow sw; // session window
|
||||
int16_t tagCondLen; // tag length in current query
|
||||
int16_t colCondLen; // column length in current query
|
||||
int16_t numOfGroupCols; // num of group by columns
|
||||
int16_t orderByIdx;
|
||||
int16_t orderType; // used in group by xx order by xxx
|
||||
int64_t vgroupLimit; // limit the number of rows for each table, used in order by + limit in stable projection query.
|
||||
int16_t prjOrder; // global order in super table projection query.
|
||||
int64_t limit;
|
||||
int64_t offset;
|
||||
int32_t queryType; // denote another query process
|
||||
int16_t numOfOutput; // final output columns numbers
|
||||
int16_t fillType; // interpolate type
|
||||
int64_t fillVal; // default value array list
|
||||
int32_t secondStageOutput;
|
||||
STsBufInfo tsBuf; // tsBuf info
|
||||
int32_t numOfTags; // number of tags columns involved
|
||||
int32_t sqlstrLen; // sql query string
|
||||
int32_t prevResultLen; // previous result length
|
||||
int32_t numOfOperator;
|
||||
int32_t tableScanOperator;// table scan operator. -1 means no scan operator
|
||||
int32_t udfNum; // number of udf function
|
||||
|
@ -569,19 +572,19 @@ typedef struct {
|
|||
} SRetrieveTableMsg;
|
||||
|
||||
typedef struct SRetrieveTableRsp {
|
||||
int32_t numOfRows;
|
||||
int64_t offset; // updated offset value for multi-vnode projection query
|
||||
int64_t useconds;
|
||||
int8_t completed; // all results are returned to client
|
||||
int8_t precision;
|
||||
int8_t compressed;
|
||||
int8_t reserved;
|
||||
int32_t compLen;
|
||||
|
||||
int32_t numOfRows;
|
||||
char data[];
|
||||
} SRetrieveTableRsp;
|
||||
|
||||
typedef struct {
|
||||
char db[TSDB_FULL_DB_NAME_LEN];
|
||||
int32_t numOfVgroups;
|
||||
int32_t cacheBlockSize; // MB
|
||||
int32_t totalBlocks;
|
||||
int32_t daysPerFile;
|
||||
|
@ -624,7 +627,6 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
char db[TSDB_TABLE_FNAME_LEN];
|
||||
int8_t ignoreNotExists;
|
||||
int32_t vgVersion;
|
||||
int32_t reserve[8];
|
||||
} SUseDbMsg;
|
||||
|
@ -750,31 +752,36 @@ typedef struct {
|
|||
} SReplica;
|
||||
|
||||
typedef struct {
|
||||
char db[TSDB_FULL_DB_NAME_LEN];
|
||||
int32_t vgId;
|
||||
int32_t dnodeId;
|
||||
char db[TSDB_FULL_DB_NAME_LEN];
|
||||
uint64_t dbUid;
|
||||
int32_t cacheBlockSize;
|
||||
int32_t totalBlocks;
|
||||
int32_t daysPerFile;
|
||||
int32_t daysToKeep0;
|
||||
int32_t daysToKeep1;
|
||||
int32_t daysToKeep2;
|
||||
int32_t minRowsPerFileBlock;
|
||||
int32_t maxRowsPerFileBlock;
|
||||
int32_t minRows;
|
||||
int32_t maxRows;
|
||||
int32_t commitTime;
|
||||
int32_t fsyncPeriod;
|
||||
int8_t reserved[16];
|
||||
int8_t walLevel;
|
||||
int8_t precision;
|
||||
int8_t compression;
|
||||
int8_t cacheLastRow;
|
||||
int8_t update;
|
||||
int8_t walLevel;
|
||||
int8_t quorum;
|
||||
int8_t update;
|
||||
int8_t cacheLastRow;
|
||||
int8_t replica;
|
||||
int8_t selfIndex;
|
||||
SReplica replicas[TSDB_MAX_REPLICA];
|
||||
} SCreateVnodeMsg, SAlterVnodeMsg;
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
int32_t vgId;
|
||||
int32_t dnodeId;
|
||||
char db[TSDB_FULL_DB_NAME_LEN];
|
||||
uint64_t dbUid;
|
||||
} SDropVnodeMsg, SSyncVnodeMsg, SCompactVnodeMsg;
|
||||
|
||||
typedef struct {
|
||||
|
@ -783,12 +790,8 @@ typedef struct {
|
|||
} SAuthVnodeMsg;
|
||||
|
||||
typedef struct {
|
||||
char name[TSDB_TABLE_FNAME_LEN];
|
||||
} SStbInfoMsg;
|
||||
|
||||
typedef struct {
|
||||
SMsgHead msgHead;
|
||||
char tableFname[TSDB_TABLE_FNAME_LEN];
|
||||
int32_t vgId;
|
||||
char tableFname[TSDB_TABLE_FNAME_LEN];
|
||||
} STableInfoMsg;
|
||||
|
||||
typedef struct {
|
||||
|
@ -799,25 +802,15 @@ typedef struct {
|
|||
char tableNames[];
|
||||
} SMultiTableInfoMsg;
|
||||
|
||||
typedef struct SSTableVgroupMsg {
|
||||
int32_t numOfTables;
|
||||
} SSTableVgroupMsg, SSTableVgroupRspMsg;
|
||||
|
||||
typedef struct SVgroupInfo {
|
||||
int32_t vgId;
|
||||
int32_t hashBegin;
|
||||
int32_t hashEnd;
|
||||
uint32_t hashBegin;
|
||||
uint32_t hashEnd;
|
||||
int8_t inUse;
|
||||
int8_t numOfEps;
|
||||
SEpAddrMsg epAddr[TSDB_MAX_REPLICA];
|
||||
} SVgroupInfo;
|
||||
|
||||
typedef struct SVgroupListRspMsg {
|
||||
int32_t vgroupNum;
|
||||
int32_t vgroupVersion;
|
||||
SVgroupInfo vgroupInfo[];
|
||||
} SVgroupListRspMsg;
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
int8_t numOfEps;
|
||||
|
@ -830,19 +823,19 @@ typedef struct {
|
|||
} SVgroupsMsg, SVgroupsInfo;
|
||||
|
||||
typedef struct {
|
||||
char tbFname[TSDB_TABLE_FNAME_LEN]; // table id
|
||||
char stbFname[TSDB_TABLE_FNAME_LEN];
|
||||
int32_t numOfTags;
|
||||
int32_t numOfColumns;
|
||||
int8_t precision;
|
||||
int8_t tableType;
|
||||
int8_t update;
|
||||
int32_t sversion;
|
||||
int32_t tversion;
|
||||
uint64_t tuid;
|
||||
uint64_t suid;
|
||||
int32_t vgId;
|
||||
SSchema pSchema[];
|
||||
char tbFname[TSDB_TABLE_FNAME_LEN]; // table full name
|
||||
char stbFname[TSDB_TABLE_FNAME_LEN];
|
||||
int32_t numOfTags;
|
||||
int32_t numOfColumns;
|
||||
int8_t precision;
|
||||
int8_t tableType;
|
||||
int8_t update;
|
||||
int32_t sversion;
|
||||
int32_t tversion;
|
||||
uint64_t suid;
|
||||
uint64_t tuid;
|
||||
int32_t vgId;
|
||||
SSchema pSchema[];
|
||||
} STableMetaMsg;
|
||||
|
||||
typedef struct SMultiTableMeta {
|
||||
|
@ -865,13 +858,11 @@ typedef struct {
|
|||
typedef struct {
|
||||
char db[TSDB_FULL_DB_NAME_LEN];
|
||||
int32_t vgVersion;
|
||||
int32_t vgNum;
|
||||
int32_t vgNum;
|
||||
int8_t hashMethod;
|
||||
SVgroupInfo vgroupInfo[];
|
||||
} SUseDbRsp;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* sql: show tables like '%a_%'
|
||||
* payload is the query condition, e.g., '%a_%'
|
||||
|
@ -885,7 +876,7 @@ typedef struct {
|
|||
} SShowMsg;
|
||||
|
||||
typedef struct {
|
||||
char db[TSDB_FULL_DB_NAME_LEN];
|
||||
char db[TSDB_FULL_DB_NAME_LEN];
|
||||
int32_t numOfVgroup;
|
||||
int32_t vgid[];
|
||||
} SCompactMsg;
|
||||
|
@ -1006,10 +997,10 @@ typedef struct {
|
|||
} SAuthMsg, SAuthRsp;
|
||||
|
||||
typedef struct {
|
||||
int8_t finished;
|
||||
int8_t reserved1[7];
|
||||
char name[TSDB_STEP_NAME_LEN];
|
||||
char desc[TSDB_STEP_DESC_LEN];
|
||||
int8_t finished;
|
||||
int8_t reserved1[7];
|
||||
char name[TSDB_STEP_NAME_LEN];
|
||||
char desc[TSDB_STEP_DESC_LEN];
|
||||
} SStartupMsg;
|
||||
|
||||
// mq related
|
||||
|
@ -1044,7 +1035,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
|
||||
} SMqResetRsp;
|
||||
//mq related end
|
||||
// mq related end
|
||||
|
||||
typedef struct {
|
||||
/* data */
|
||||
|
@ -1098,6 +1089,23 @@ typedef struct {
|
|||
/* data */
|
||||
} SUpdateTagValRsp;
|
||||
|
||||
typedef struct SSchedulerQueryMsg {
|
||||
uint64_t queryId;
|
||||
uint64_t taskId;
|
||||
uint32_t contentLen;
|
||||
char msg[];
|
||||
} SSchedulerQueryMsg;
|
||||
|
||||
typedef struct SSchedulerReadyMsg {
|
||||
uint64_t queryId;
|
||||
uint64_t taskId;
|
||||
} SSchedulerReadyMsg;
|
||||
|
||||
typedef struct SSchedulerFetchMsg {
|
||||
uint64_t queryId;
|
||||
uint64_t taskId;
|
||||
} SSchedulerFetchMsg;
|
||||
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ enum {
|
|||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CFG_DNODE, "cfg-dnode" )
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CFG_MNODE, "cfg-mnode" )
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_SHOW, "show" )
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_RETRIEVE, "retrieve" )
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_RETRIEVE_MNODE, "retrieve" )
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_KILL_QUERY, "kill-query" )
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_KILL_STREAM, "kill-stream" )
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_KILL_CONNECTION, "kill-connection" )
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#ifndef TDENGINE_TNAME_H
|
||||
#define TDENGINE_TNAME_H
|
||||
|
||||
#include "taosmsg.h"
|
||||
//#include "taosmsg.h"
|
||||
|
||||
#define TSDB_DB_NAME_T 1
|
||||
#define TSDB_TABLE_NAME_T 2
|
||||
|
@ -27,7 +27,7 @@
|
|||
|
||||
typedef struct SName {
|
||||
uint8_t type; //db_name_t, table_name_t
|
||||
char acctId[TSDB_ACCT_ID_LEN];
|
||||
int32_t acctId;
|
||||
char dbname[TSDB_DB_NAME_LEN];
|
||||
char tname[TSDB_TABLE_NAME_LEN];
|
||||
} SName;
|
||||
|
@ -38,7 +38,7 @@ int32_t tNameLen(const SName* name);
|
|||
|
||||
SName* tNameDup(const SName* name);
|
||||
|
||||
bool tIsValidName(const SName* name);
|
||||
bool tNameIsValid(const SName* name);
|
||||
|
||||
const char* tNameGetTableName(const SName* name);
|
||||
|
||||
|
@ -50,14 +50,10 @@ bool tNameIsEmpty(const SName* name);
|
|||
|
||||
void tNameAssign(SName* dst, const SName* src);
|
||||
|
||||
int32_t tNameSetDbName(SName* dst, int32_t acctId, const char* dbName, size_t nameLen);
|
||||
|
||||
int32_t tNameFromString(SName* dst, const char* str, uint32_t type);
|
||||
|
||||
int32_t tNameSetAcctId(SName* dst, const char* acct);
|
||||
|
||||
SSchema* tGetTbnameColumnSchema();
|
||||
|
||||
#if 0
|
||||
int32_t tNameSetDbName(SName* dst, const char* acct, SToken* dbToken);
|
||||
#endif
|
||||
int32_t tNameSetAcctId(SName* dst, int32_t acctId);
|
||||
|
||||
#endif // TDENGINE_TNAME_H
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#ifndef _TD_META_H_
|
||||
#define _TD_META_H_
|
||||
|
||||
#include "mallocator.h"
|
||||
#include "os.h"
|
||||
#include "trow.h"
|
||||
|
||||
|
@ -71,7 +72,7 @@ typedef struct STbCfg {
|
|||
} STbCfg;
|
||||
|
||||
// SMeta operations
|
||||
SMeta *metaOpen(const char *path, const SMetaCfg *pOptions);
|
||||
SMeta *metaOpen(const char *path, const SMetaCfg *pMetaCfg, SMemAllocatorFactory *pMAF);
|
||||
void metaClose(SMeta *pMeta);
|
||||
void metaRemove(const char *path);
|
||||
int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg);
|
||||
|
@ -79,8 +80,8 @@ int metaDropTable(SMeta *pMeta, tb_uid_t uid);
|
|||
int metaCommit(SMeta *pMeta);
|
||||
|
||||
// Options
|
||||
void metaOptionsInit(SMetaCfg *pOptions);
|
||||
void metaOptionsClear(SMetaCfg *pOptions);
|
||||
void metaOptionsInit(SMetaCfg *pMetaCfg);
|
||||
void metaOptionsClear(SMetaCfg *pMetaCfg);
|
||||
|
||||
// STbCfg
|
||||
#define META_INIT_STB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA, PTAGSCHEMA) \
|
||||
|
|
|
@ -16,31 +16,33 @@
|
|||
#ifndef _TD_TSDB_H_
|
||||
#define _TD_TSDB_H_
|
||||
|
||||
#include "mallocator.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// TYPES EXPOSED
|
||||
typedef struct STsdb STsdb;
|
||||
typedef struct STsdbCfg STsdbCfg;
|
||||
typedef struct STsdb STsdb;
|
||||
|
||||
// STsdb
|
||||
STsdb *tsdbOpen(const char *path, const STsdbCfg *pTsdbCfg);
|
||||
void tsdbClose(STsdb *);
|
||||
void tsdbRemove(const char *path);
|
||||
int tsdbInsertData(STsdb *pTsdb, SSubmitMsg *pMsg);
|
||||
|
||||
// STsdbCfg
|
||||
int tsdbOptionsInit(STsdbCfg *);
|
||||
void tsdbOptionsClear(STsdbCfg *);
|
||||
|
||||
/* ------------------------ STRUCT DEFINITIONS ------------------------ */
|
||||
struct STsdbCfg {
|
||||
typedef struct STsdbCfg {
|
||||
uint64_t lruCacheSize;
|
||||
uint32_t keep0;
|
||||
uint32_t keep1;
|
||||
uint32_t keep2;
|
||||
};
|
||||
} STsdbCfg;
|
||||
|
||||
// STsdb
|
||||
STsdb *tsdbOpen(const char *path, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF);
|
||||
void tsdbClose(STsdb *);
|
||||
void tsdbRemove(const char *path);
|
||||
int tsdbInsertData(STsdb *pTsdb, SSubmitMsg *pMsg);
|
||||
int tsdbPrepareCommit(STsdb *pTsdb);
|
||||
int tsdbCommit(STsdb *pTsdb);
|
||||
|
||||
// STsdbCfg
|
||||
int tsdbOptionsInit(STsdbCfg *);
|
||||
void tsdbOptionsClear(STsdbCfg *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -32,8 +32,7 @@ extern "C" {
|
|||
struct SCatalog;
|
||||
|
||||
typedef struct SCatalogReq {
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
SArray *pTableName; // table full name
|
||||
SArray *pTableName; // element is SNAME
|
||||
SArray *pUdf; // udf name
|
||||
bool qNodeRequired; // valid qnode
|
||||
} SCatalogReq;
|
||||
|
@ -54,10 +53,10 @@ typedef struct SCatalogCfg {
|
|||
int32_t catalogInit(SCatalogCfg *cfg);
|
||||
|
||||
/**
|
||||
* Catalog service object, which is utilized to hold tableMeta (meta/vgroupInfo/udfInfo) at the client-side.
|
||||
* There is ONLY one SCatalog object for one process space, and this function returns a singleton.
|
||||
* @param clusterId
|
||||
* @return
|
||||
* Get a cluster's catalog handle for all later operations.
|
||||
* @param clusterId (input, end with \0)
|
||||
* @param catalogHandle (output, NO need to free it)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle);
|
||||
|
||||
|
@ -65,40 +64,85 @@ int32_t catalogGetDBVgroupVersion(struct SCatalog* pCatalog, const char* dbName,
|
|||
int32_t catalogGetDBVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* dbName, int32_t forceUpdate, SDBVgroupInfo* dbInfo);
|
||||
int32_t catalogUpdateDBVgroupCache(struct SCatalog* pCatalog, const char* dbName, SDBVgroupInfo* dbInfo);
|
||||
|
||||
|
||||
/**
|
||||
* Get a table's meta data.
|
||||
* @param pCatalog (input, got with catalogGetHandle)
|
||||
* @param pRpc (input, rpc object)
|
||||
* @param pMgmtEps (input, mnode EPs)
|
||||
* @param pDBName (input, full db name)
|
||||
* @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 catalogGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, STableMeta** pTableMeta);
|
||||
|
||||
/**
|
||||
* Force renew a table's local cached meta data.
|
||||
* @param pCatalog (input, got with catalogGetHandle)
|
||||
* @param pRpc (input, rpc object)
|
||||
* @param pMgmtEps (input, mnode EPs)
|
||||
* @param pDBName (input, full db name)
|
||||
* @param pTableName (input, table name, NOT including db name)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName);
|
||||
|
||||
/**
|
||||
* Force renew a table's local cached meta data and get the new one.
|
||||
* @param pCatalog (input, got with catalogGetHandle)
|
||||
* @param pRpc (input, rpc object)
|
||||
* @param pMgmtEps (input, mnode EPs)
|
||||
* @param pDBName (input, full db name)
|
||||
* @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 catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, STableMeta** pTableMeta);
|
||||
|
||||
|
||||
/**
|
||||
* get table's vgroup list.
|
||||
* @param clusterId
|
||||
* @pVgroupList - array of SVgroupInfo
|
||||
* @return
|
||||
* 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 pMgmtEps (input, mnode EPs)
|
||||
* @param pDBName (input, full db name)
|
||||
* @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 catalogGetTableVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, SArray* pVgroupList);
|
||||
int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, SArray* pVgroupList);
|
||||
|
||||
/**
|
||||
* Get a table's vgroup from its name's hash value.
|
||||
* @param pCatalog (input, got with catalogGetHandle)
|
||||
* @param pRpc (input, rpc object)
|
||||
* @param pMgmtEps (input, mnode EPs)
|
||||
* @param pDBName (input, full db name)
|
||||
* @param pTableName (input, table name, NOT including db name)
|
||||
* @param vgInfo (output, vgroup info)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogGetTableHashVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const char* pDBName, const char* pTableName, SVgroupInfo* vgInfo);
|
||||
|
||||
|
||||
/**
|
||||
* Get the required meta data from mnode.
|
||||
* Note that this is a synchronized API and is also thread-safety.
|
||||
* @param pCatalog
|
||||
* @param pMgmtEps
|
||||
* @param pMetaReq
|
||||
* @param pMetaData
|
||||
* @return
|
||||
* Get all meta data required in pReq.
|
||||
* @param pCatalog (input, got with catalogGetHandle)
|
||||
* @param pRpc (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 catalogGetQnodeList(struct SCatalog* pCatalog, const SEpSet* pMgmtEps, SEpSet* pQnodeEpSet);
|
||||
int32_t catalogGetQnodeList(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, SEpSet* pQnodeEpSet);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Destroy catalog and relase all resources
|
||||
* @param pCatalog
|
||||
*/
|
||||
void catalogDestroy(void);
|
||||
|
||||
|
|
|
@ -24,10 +24,20 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
typedef struct SIndex SIndex;
|
||||
typedef struct SIndexTerm SIndexTerm;
|
||||
typedef struct SIndexOpts SIndexOpts;
|
||||
typedef struct SIndexMultiTermQuery SIndexMultiTermQuery;
|
||||
typedef struct SArray SIndexMultiTerm;
|
||||
|
||||
typedef enum {
|
||||
ADD_VALUE, // add index colume value
|
||||
DEL_VALUE, // delete index column value
|
||||
UPDATE_VALUE, // update index column value
|
||||
ADD_INDEX, // add index on specify column
|
||||
DROP_INDEX, // drop existed index
|
||||
DROP_SATBLE // drop stable
|
||||
} SIndexOperOnColumn;
|
||||
|
||||
typedef enum { MUST = 0, SHOULD = 1, NOT = 2 } EIndexOperatorType;
|
||||
typedef enum { QUERY_TERM = 0, QUERY_PREFIX = 1, QUERY_SUFFIX = 2,QUERY_REGEX = 3} EIndexQueryType;
|
||||
/*
|
||||
|
@ -36,14 +46,14 @@ typedef enum { QUERY_TERM = 0, QUERY_PREFIX = 1, QUERY_SUFFIX = 2,QUERY_REGEX =
|
|||
*/
|
||||
SIndexMultiTermQuery *indexMultiTermQueryCreate(EIndexOperatorType oper);
|
||||
void indexMultiTermQueryDestroy(SIndexMultiTermQuery *pQuery);
|
||||
int indexMultiTermQueryAdd(SIndexMultiTermQuery *pQuery, const char *field, int32_t nFields, const char *value, int32_t nValue, EIndexQueryType type);
|
||||
int indexMultiTermQueryAdd(SIndexMultiTermQuery *pQuery, SIndexTerm *term, EIndexQueryType type);
|
||||
/*
|
||||
* @param:
|
||||
* @param:
|
||||
*/
|
||||
SIndex* indexOpen(SIndexOpts *opt, const char *path);
|
||||
int indexOpen(SIndexOpts *opt, const char *path, SIndex **index);
|
||||
void indexClose(SIndex *index);
|
||||
int indexPut(SIndex *index, SIndexMultiTerm *terms, int uid);
|
||||
int indexPut(SIndex *index, SIndexMultiTerm *terms, uint64_t uid);
|
||||
int indexDelete(SIndex *index, SIndexMultiTermQuery *query);
|
||||
int indexSearch(SIndex *index, SIndexMultiTermQuery *query, SArray *result);
|
||||
int indexRebuild(SIndex *index, SIndexOpts *opt);
|
||||
|
@ -52,8 +62,8 @@ int indexRebuild(SIndex *index, SIndexOpts *opt);
|
|||
* @param
|
||||
*/
|
||||
SIndexMultiTerm *indexMultiTermCreate();
|
||||
int indexMultiTermAdd(SIndexMultiTerm *terms, const char *field, int32_t nFields, const char *value, int32_t nValue);
|
||||
void indexMultiTermDestroy(SIndexMultiTerm *terms);
|
||||
int indexMultiTermAdd(SIndexMultiTerm *terms, SIndexTerm *term);
|
||||
void indexMultiTermDestroy(SIndexMultiTerm *terms);
|
||||
/*
|
||||
* @param:
|
||||
* @param:
|
||||
|
@ -61,6 +71,16 @@ void indexMultiTermDestroy(SIndexMultiTerm *terms);
|
|||
SIndexOpts *indexOptsCreate();
|
||||
void indexOptsDestroy(SIndexOpts *opts);
|
||||
|
||||
/*
|
||||
* @param:
|
||||
* @param:
|
||||
*/
|
||||
|
||||
SIndexTerm *indexTermCreate(int64_t suid, SIndexOperOnColumn operType, uint8_t colType,
|
||||
const char *colName, int32_t nColName, const char *colVal, int32_t nColVal);
|
||||
void indexTermDestroy(SIndexTerm *p);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -153,7 +153,7 @@ typedef struct SParseContext {
|
|||
* @param msg extended error message if exists.
|
||||
* @return error code
|
||||
*/
|
||||
int32_t qParseQuerySql(const char* pStr, size_t length, struct SQueryStmtInfo** pQueryInfo, int64_t id, char* msg, int32_t msgLen);
|
||||
int32_t qParseQuerySql(const char* pStr, size_t length, int64_t id, int32_t* type, void** pOutput, int32_t* outputLen, char* msg, int32_t msgLen);
|
||||
|
||||
typedef enum {
|
||||
PAYLOAD_TYPE_KV = 0,
|
||||
|
@ -209,6 +209,7 @@ typedef struct SSourceParam {
|
|||
|
||||
SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, const char* funcName, SSourceParam* pSource, SSchema* pResSchema, int16_t interSize);
|
||||
int32_t copyExprInfoList(SArray* dst, const SArray* src, uint64_t uid, bool deepcopy);
|
||||
int32_t copyAllExprInfo(SArray* dst, const SArray* src, bool deepcopy);
|
||||
int32_t getExprFunctionLevel(SQueryStmtInfo* pQueryInfo);
|
||||
|
||||
STableMetaInfo* getMetaInfo(SQueryStmtInfo* pQueryInfo, int32_t tableIndex);
|
||||
|
|
|
@ -34,6 +34,13 @@ enum OPERATOR_TYPE_E {
|
|||
OP_TotalNum
|
||||
};
|
||||
|
||||
enum DATASINK_TYPE_E {
|
||||
DSINK_Unknown,
|
||||
DSINK_Dispatch,
|
||||
DSINK_Insert,
|
||||
DSINK_TotalNum
|
||||
};
|
||||
|
||||
struct SEpSet;
|
||||
struct SQueryStmtInfo;
|
||||
|
||||
|
@ -49,6 +56,22 @@ typedef struct SQueryNodeBasicInfo {
|
|||
const char *name; // operator name
|
||||
} SQueryNodeBasicInfo;
|
||||
|
||||
typedef struct SDataSink {
|
||||
SQueryNodeBasicInfo info;
|
||||
SDataBlockSchema schema;
|
||||
} SDataSink;
|
||||
|
||||
typedef struct SDataDispatcher {
|
||||
SDataSink sink;
|
||||
// todo
|
||||
} SDataDispatcher;
|
||||
|
||||
typedef struct SDataInserter {
|
||||
SDataSink sink;
|
||||
uint64_t uid; // unique id of the table
|
||||
// todo data field
|
||||
} SDataInserter;
|
||||
|
||||
typedef struct SPhyNode {
|
||||
SQueryNodeBasicInfo info;
|
||||
SArray *pTargets; // target list to be computed or scanned at this node
|
||||
|
@ -84,8 +107,8 @@ typedef struct SProjectPhyNode {
|
|||
|
||||
typedef struct SExchangePhyNode {
|
||||
SPhyNode node;
|
||||
uint64_t templateId;
|
||||
SArray *pSourceEpSet; // SEpSet
|
||||
uint64_t srcTemplateId; // template id of datasource suplans
|
||||
SArray *pSrcEndPoints; // SEpAddrMsg, scheduler fill by calling qSetSuplanExecutionNode
|
||||
} SExchangePhyNode;
|
||||
|
||||
typedef struct SSubplanId {
|
||||
|
@ -105,6 +128,8 @@ typedef struct SSubplan {
|
|||
} SSubplan;
|
||||
|
||||
typedef struct SQueryDag {
|
||||
uint64_t queryId;
|
||||
int32_t numOfSubplans;
|
||||
SArray *pSubplans; // Element is SArray*, and nested element is SSubplan. The execution level of subplan, starting from 0.
|
||||
} SQueryDag;
|
||||
|
||||
|
@ -113,20 +138,29 @@ typedef struct SQueryDag {
|
|||
*/
|
||||
int32_t qCreateQueryDag(const struct SQueryStmtInfo* pQueryInfo, struct SEpSet* pQnode, struct SQueryDag** pDag);
|
||||
|
||||
int32_t qExplainQuery(const struct SQueryStmtInfo* pQueryInfo, struct SEpSet* pQnode, char** str);
|
||||
// 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, SEpAddr* ep);
|
||||
|
||||
int32_t qExplainQuery(const struct SQueryStmtInfo* pQueryInfo, struct SEpSet* pQnode, char** str);
|
||||
|
||||
/**
|
||||
* Convert to subplan to string for the scheduler to send to the executor
|
||||
*/
|
||||
int32_t qSubPlanToString(struct SSubplan *pPhyNode, char** str);
|
||||
int32_t qSubPlanToString(const SSubplan* subplan, char** str);
|
||||
|
||||
int32_t qStringToSubplan(const char* str, SSubplan** subplan);
|
||||
|
||||
void qDestroySubplan(SSubplan* pSubplan);
|
||||
|
||||
/**
|
||||
* Destroy the physical plan.
|
||||
* @param pQueryPhyNode
|
||||
* @return
|
||||
*/
|
||||
void* qDestroyQueryDag(struct SQueryDag* pDag);
|
||||
void qDestroyQueryDag(SQueryDag* pDag);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -14,20 +14,20 @@
|
|||
*/
|
||||
|
||||
#if defined(INCLUDE_AS_ENUM) // enum define mode
|
||||
#undef OP_ENUM_MACRO
|
||||
#define OP_ENUM_MACRO(op) OP_##op,
|
||||
#undef OP_ENUM_MACRO
|
||||
#define OP_ENUM_MACRO(op) OP_##op,
|
||||
#elif defined(INCLUDE_AS_NAME) // comment define mode
|
||||
#undef OP_ENUM_MACRO
|
||||
#define OP_ENUM_MACRO(op) #op,
|
||||
#undef OP_ENUM_MACRO
|
||||
#define OP_ENUM_MACRO(op) #op,
|
||||
#else
|
||||
#error To use this include file, first define either INCLUDE_AS_ENUM or INCLUDE_AS_NAME
|
||||
#error To use this include file, first define either INCLUDE_AS_ENUM or INCLUDE_AS_NAME
|
||||
#endif
|
||||
|
||||
OP_ENUM_MACRO(TableScan)
|
||||
OP_ENUM_MACRO(DataBlocksOptScan)
|
||||
OP_ENUM_MACRO(TableSeqScan)
|
||||
OP_ENUM_MACRO(TagScan)
|
||||
OP_ENUM_MACRO(TableBlockInfoScan)
|
||||
OP_ENUM_MACRO(SystemTableScan)
|
||||
OP_ENUM_MACRO(Aggregate)
|
||||
OP_ENUM_MACRO(Project)
|
||||
OP_ENUM_MACRO(Groupby)
|
||||
|
|
|
@ -22,8 +22,7 @@ extern "C" {
|
|||
|
||||
#include "tarray.h"
|
||||
#include "thash.h"
|
||||
|
||||
typedef SVgroupListRspMsg SVgroupListInfo;
|
||||
#include "tlog.h"
|
||||
|
||||
typedef struct STableComInfo {
|
||||
uint8_t numOfTags; // the number of tags in schema
|
||||
|
@ -82,9 +81,24 @@ typedef struct STableMetaOutput {
|
|||
STableMeta *tbMeta;
|
||||
} STableMetaOutput;
|
||||
|
||||
bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags);
|
||||
|
||||
extern int32_t (*queryBuildMsg[TSDB_MSG_TYPE_MAX])(void* input, char **msg, int32_t msgSize, int32_t *msgLen);
|
||||
extern int32_t (*queryProcessMsgRsp[TSDB_MSG_TYPE_MAX])(void* output, char *msg, int32_t msgSize);
|
||||
|
||||
SSchema* tGetTbnameColumnSchema();
|
||||
extern void msgInit();
|
||||
|
||||
extern int32_t qDebugFlag;
|
||||
|
||||
#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)
|
||||
#define qInfo(...) do { if (qDebugFlag & DEBUG_INFO) { taosPrintLog("QRY ", qDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define qDebug(...) do { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLog("QRY ", qDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define qTrace(...) do { if (qDebugFlag & DEBUG_TRACE) { taosPrintLog("QRY ", qDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define qDebugL(...) do { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLongString("QRY ", qDebugFlag, __VA_ARGS__); }} while(0)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
|
@ -20,6 +20,13 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "planner.h"
|
||||
#include "catalog.h"
|
||||
|
||||
typedef struct SSchedulerCfg {
|
||||
int32_t clusterType;
|
||||
} SSchedulerCfg;
|
||||
|
||||
typedef struct SQueryProfileSummary {
|
||||
int64_t startTs; // Object created and added into the message queue
|
||||
int64_t endTs; // the timestamp when the task is completed
|
||||
|
@ -43,43 +50,29 @@ typedef struct SQueryProfileSummary {
|
|||
uint64_t resultSize; // generated result size in Kb.
|
||||
} SQueryProfileSummary;
|
||||
|
||||
typedef struct SQueryTask {
|
||||
uint64_t queryId; // query id
|
||||
uint64_t taskId; // task id
|
||||
char *pSubplan; // operator tree
|
||||
uint64_t status; // task status
|
||||
SQueryProfileSummary summary; // task execution summary
|
||||
void *pOutputHandle; // result buffer handle, to temporarily keep the output result for next stage
|
||||
} SQueryTask;
|
||||
|
||||
typedef struct SQueryJob {
|
||||
SArray **pSubtasks;
|
||||
// todo
|
||||
} SQueryJob;
|
||||
int32_t schedulerInit(SSchedulerCfg *cfg);
|
||||
|
||||
/**
|
||||
* Process the query job, generated according to the query physical plan.
|
||||
* This is a synchronized API, and is also thread-safety.
|
||||
* @param pJob
|
||||
* @param qnodeList Qnode address list, element is SEpAddr
|
||||
* @return
|
||||
*/
|
||||
int32_t qProcessQueryJob(struct SQueryJob* pJob);
|
||||
int32_t scheduleExecJob(void *transport, SArray *qnodeList, SQueryDag* pDag, void** pJob);
|
||||
|
||||
int32_t scheduleFetchRows(void *pJob, void **data);
|
||||
|
||||
/**
|
||||
* The SSqlObj should not be here????
|
||||
* @param pSql
|
||||
* @param pVgroupId
|
||||
* @param pRetVgroupId
|
||||
* @return
|
||||
*/
|
||||
//SArray* qGetInvolvedVgroupIdList(struct SSqlObj* pSql, SArray* pVgroupId, SArray* pRetVgroupId);
|
||||
|
||||
/**
|
||||
* Cancel query job
|
||||
* @param pJob
|
||||
* @return
|
||||
*/
|
||||
int32_t qKillQueryJob(struct SQueryJob* pJob);
|
||||
int32_t scheduleCancelJob(void *pJob);
|
||||
|
||||
void scheduleFreeJob(void *pJob);
|
||||
|
||||
void schedulerDestroy(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ extern "C" {
|
|||
#include <math.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#define TSDB_LOCALE_LEN 64
|
||||
#define TSDB_TIMEZONE_LEN 96
|
||||
|
||||
|
@ -57,11 +59,11 @@ char * taosGetCmdlineByPID(int pid);
|
|||
void taosSetCoreDump(bool enable);
|
||||
|
||||
typedef struct {
|
||||
const char *sysname;
|
||||
const char *nodename;
|
||||
const char *release;
|
||||
const char *version;
|
||||
const char *machine;
|
||||
char sysname[_UTSNAME_MACHINE_LENGTH];
|
||||
char nodename[_UTSNAME_MACHINE_LENGTH];
|
||||
char release[_UTSNAME_MACHINE_LENGTH];
|
||||
char version[_UTSNAME_MACHINE_LENGTH];
|
||||
char machine[_UTSNAME_MACHINE_LENGTH];
|
||||
} SysNameInfo;
|
||||
|
||||
SysNameInfo taosGetSysNameInfo();
|
||||
|
|
|
@ -22,23 +22,31 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SMemAllocator SMemAllocator;
|
||||
typedef struct SMemAllocatorFactory SMemAllocatorFactory;
|
||||
// Memory allocator
|
||||
#define TD_MEM_ALCT(TYPE) \
|
||||
struct { \
|
||||
void *(*malloc_)(struct TYPE *, uint64_t size); \
|
||||
void (*free_)(struct TYPE *, void *ptr); \
|
||||
}
|
||||
#define TD_MA_MALLOC_FUNC(TMA) (TMA)->malloc_
|
||||
#define TD_MA_FREE_FUNC(TMA) (TMA)->free_
|
||||
|
||||
struct SMemAllocator {
|
||||
void *impl;
|
||||
void *(*malloc)(SMemAllocator *, uint64_t size);
|
||||
void *(*calloc)(SMemAllocator *, uint64_t nmemb, uint64_t size);
|
||||
void *(*realloc)(SMemAllocator *, void *ptr, uint64_t size);
|
||||
void (*free)(SMemAllocator *, void *ptr);
|
||||
uint64_t (*usage)(SMemAllocator *);
|
||||
};
|
||||
#define TD_MA_MALLOC(TMA, SIZE) (*((TMA)->malloc_))(TMA, (SIZE))
|
||||
#define TD_MA_FREE(TMA, PTR) (*((TMA)->free_))(TMA, (PTR))
|
||||
|
||||
struct SMemAllocatorFactory {
|
||||
typedef struct SMemAllocator {
|
||||
void *impl;
|
||||
SMemAllocator *(*create)(SMemAllocatorFactory *);
|
||||
void (*destroy)(SMemAllocatorFactory *, SMemAllocator *);
|
||||
};
|
||||
TD_MEM_ALCT(SMemAllocator);
|
||||
} SMemAllocator;
|
||||
|
||||
#define tMalloc(pMA, SIZE) TD_MA_MALLOC(PMA, SIZE)
|
||||
#define tFree(pMA, PTR) TD_MA_FREE(PMA, PTR)
|
||||
|
||||
typedef struct SMemAllocatorFactory {
|
||||
void *impl;
|
||||
SMemAllocator *(*create)(struct SMemAllocatorFactory *);
|
||||
void (*destroy)(struct SMemAllocatorFactory *, SMemAllocator *);
|
||||
} SMemAllocatorFactory;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -120,17 +120,18 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_TSC_INVALID_INPUT TAOS_DEF_ERROR_CODE(0, 0X0224) //"Invalid tsc input")
|
||||
|
||||
// mnode-common
|
||||
#define TSDB_CODE_MND_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0300)
|
||||
#define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0301)
|
||||
#define TSDB_CODE_MND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0302)
|
||||
#define TSDB_CODE_MND_ACTION_NEED_REPROCESSED TAOS_DEF_ERROR_CODE(0, 0x0303)
|
||||
#define TSDB_CODE_MND_NO_RIGHTS TAOS_DEF_ERROR_CODE(0, 0x0304)
|
||||
#define TSDB_CODE_MND_INVALID_OPTIONS TAOS_DEF_ERROR_CODE(0, 0x0305)
|
||||
#define TSDB_CODE_MND_INVALID_CONNECTION TAOS_DEF_ERROR_CODE(0, 0x0306)
|
||||
#define TSDB_CODE_MND_INVALID_MSG_VERSION TAOS_DEF_ERROR_CODE(0, 0x0307)
|
||||
#define TSDB_CODE_MND_INVALID_MSG_LEN TAOS_DEF_ERROR_CODE(0, 0x0308)
|
||||
#define TSDB_CODE_MND_INVALID_MSG_TYPE TAOS_DEF_ERROR_CODE(0, 0x0309)
|
||||
#define TSDB_CODE_MND_TOO_MANY_SHELL_CONNS TAOS_DEF_ERROR_CODE(0, 0x030A)
|
||||
#define TSDB_CODE_MND_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x0300)
|
||||
#define TSDB_CODE_MND_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0301)
|
||||
#define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0302)
|
||||
#define TSDB_CODE_MND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0303)
|
||||
#define TSDB_CODE_MND_ACTION_NEED_REPROCESSED TAOS_DEF_ERROR_CODE(0, 0x0304)
|
||||
#define TSDB_CODE_MND_NO_RIGHTS TAOS_DEF_ERROR_CODE(0, 0x0305)
|
||||
#define TSDB_CODE_MND_INVALID_OPTIONS TAOS_DEF_ERROR_CODE(0, 0x0306)
|
||||
#define TSDB_CODE_MND_INVALID_CONNECTION TAOS_DEF_ERROR_CODE(0, 0x0307)
|
||||
#define TSDB_CODE_MND_INVALID_MSG_VERSION TAOS_DEF_ERROR_CODE(0, 0x0308)
|
||||
#define TSDB_CODE_MND_INVALID_MSG_LEN TAOS_DEF_ERROR_CODE(0, 0x0309)
|
||||
#define TSDB_CODE_MND_INVALID_MSG_TYPE TAOS_DEF_ERROR_CODE(0, 0x030A)
|
||||
#define TSDB_CODE_MND_TOO_MANY_SHELL_CONNS TAOS_DEF_ERROR_CODE(0, 0x030B)
|
||||
|
||||
// mnode-show
|
||||
#define TSDB_CODE_MND_INVALID_SHOWOBJ TAOS_DEF_ERROR_CODE(0, 0x0310)
|
||||
|
@ -206,44 +207,28 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_VGROUP_ALREADY_IN_DNODE TAOS_DEF_ERROR_CODE(0, 0x0392)
|
||||
|
||||
// mnode-stable
|
||||
#define TSDB_CODE_MND_STB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0360)
|
||||
#define TSDB_CODE_MND_STB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0360)
|
||||
#define TSDB_CODE_MND_STB_INVALID_IGEXIST TAOS_DEF_ERROR_CODE(0, 0x0360)
|
||||
#define TSDB_CODE_MND_STB_INVALID_COLS_NUM TAOS_DEF_ERROR_CODE(0, 0x0360)
|
||||
#define TSDB_CODE_MND_STB_INVALID_TAGS_NUM TAOS_DEF_ERROR_CODE(0, 0x0360)
|
||||
#define TSDB_CODE_MND_STB_INVALID_COL_TYPE TAOS_DEF_ERROR_CODE(0, 0x0360)
|
||||
#define TSDB_CODE_MND_STB_INVALID_COL_ID TAOS_DEF_ERROR_CODE(0, 0x0360)
|
||||
#define TSDB_CODE_MND_STB_INVALID_COL_BYTES TAOS_DEF_ERROR_CODE(0, 0x0360)
|
||||
#define TSDB_CODE_MND_STB_INVALID_COL_NAME TAOS_DEF_ERROR_CODE(0, 0x0360)
|
||||
|
||||
|
||||
#define TSDB_CODE_MND_INVALID_TABLE_ID TAOS_DEF_ERROR_CODE(0, 0x0361) //"Table name too long")
|
||||
#define TSDB_CODE_MND_INVALID_TABLE_NAME TAOS_DEF_ERROR_CODE(0, 0x0362) //"Table does not exist")
|
||||
#define TSDB_CODE_MND_INVALID_TABLE_TYPE TAOS_DEF_ERROR_CODE(0, 0x0363) //"Invalid table type in tsdb")
|
||||
#define TSDB_CODE_MND_TOO_MANY_TAGS TAOS_DEF_ERROR_CODE(0, 0x0364) //"Too many tags")
|
||||
#define TSDB_CODE_MND_TOO_MANY_COLUMNS TAOS_DEF_ERROR_CODE(0, 0x0365) //"Too many columns")
|
||||
#define TSDB_CODE_MND_TOO_MANY_TIMESERIES TAOS_DEF_ERROR_CODE(0, 0x0366) //"Too many time series")
|
||||
#define TSDB_CODE_MND_NOT_SUPER_TABLE TAOS_DEF_ERROR_CODE(0, 0x0367) //"Not super table") // operation only available for super table
|
||||
#define TSDB_CODE_MND_COL_NAME_TOO_LONG TAOS_DEF_ERROR_CODE(0, 0x0368) //"Tag name too long")
|
||||
#define TSDB_CODE_MND_TAG_ALREAY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0369) //"Tag already exists")
|
||||
#define TSDB_CODE_MND_TAG_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x036A) //"Tag does not exist")
|
||||
#define TSDB_CODE_MND_FIELD_ALREAY_EXIST TAOS_DEF_ERROR_CODE(0, 0x036B) //"Field already exists")
|
||||
#define TSDB_CODE_MND_FIELD_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x036C) //"Field does not exist")
|
||||
#define TSDB_CODE_MND_INVALID_STABLE_NAME TAOS_DEF_ERROR_CODE(0, 0x036D) //"Super table does not exist")
|
||||
#define TSDB_CODE_MND_INVALID_CREATE_TABLE_MSG TAOS_DEF_ERROR_CODE(0, 0x036E) //"Invalid create table message")
|
||||
#define TSDB_CODE_MND_EXCEED_MAX_ROW_BYTES TAOS_DEF_ERROR_CODE(0, 0x036F) //"Exceed max row bytes")
|
||||
|
||||
#define TSDB_CODE_MND_FUNC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0370)
|
||||
#define TSDB_CODE_MND_FUNC_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0371)
|
||||
#define TSDB_CODE_MND_INVALID_FUNC TAOS_DEF_ERROR_CODE(0, 0x0372)
|
||||
#define TSDB_CODE_MND_INVALID_FUNC_NAME TAOS_DEF_ERROR_CODE(0, 0x0373)
|
||||
#define TSDB_CODE_MND_INVALID_FUNC_COMMENT TAOS_DEF_ERROR_CODE(0, 0x0374)
|
||||
#define TSDB_CODE_MND_INVALID_FUNC_CODE TAOS_DEF_ERROR_CODE(0, 0x0375)
|
||||
#define TSDB_CODE_MND_INVALID_FUNC_BUFSIZE TAOS_DEF_ERROR_CODE(0, 0x0376)
|
||||
|
||||
#define TSDB_CODE_MND_INVALID_TAG_LENGTH TAOS_DEF_ERROR_CODE(0, 0x0376) //"invalid tag length")
|
||||
#define TSDB_CODE_MND_INVALID_COLUMN_LENGTH TAOS_DEF_ERROR_CODE(0, 0x0377) //"invalid column length")
|
||||
#define TSDB_CODE_MND_STB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03A0)
|
||||
#define TSDB_CODE_MND_STB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03A1)
|
||||
#define TSDB_CODE_MND_TOO_MANY_STBS TAOS_DEF_ERROR_CODE(0, 0x03A2)
|
||||
#define TSDB_CODE_MND_INVALID_STB TAOS_DEF_ERROR_CODE(0, 0x03A3)
|
||||
#define TSDB_CODE_MND_INVALID_STB_OPTION TAOS_DEF_ERROR_CODE(0, 0x03A4)
|
||||
#define TSDB_CODE_MND_STB_OPTION_UNCHNAGED TAOS_DEF_ERROR_CODE(0, 0x03A5)
|
||||
#define TSDB_CODE_MND_TOO_MANY_TAGS TAOS_DEF_ERROR_CODE(0, 0x03A6)
|
||||
#define TSDB_CODE_MND_TAG_ALREAY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03A7)
|
||||
#define TSDB_CODE_MND_TAG_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03A8)
|
||||
#define TSDB_CODE_MND_TOO_MANY_COLUMNS TAOS_DEF_ERROR_CODE(0, 0x03A9)
|
||||
#define TSDB_CODE_MND_COLUMN_ALREAY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03AA)
|
||||
#define TSDB_CODE_MND_COLUMN_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03AB)
|
||||
#define TSDB_CODE_MND_EXCEED_MAX_ROW_BYTES TAOS_DEF_ERROR_CODE(0, 0x03AC)
|
||||
|
||||
// mnode-func
|
||||
#define TSDB_CODE_MND_FUNC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03C0)
|
||||
#define TSDB_CODE_MND_FUNC_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03C1)
|
||||
#define TSDB_CODE_MND_INVALID_FUNC TAOS_DEF_ERROR_CODE(0, 0x03C2)
|
||||
#define TSDB_CODE_MND_INVALID_FUNC_NAME TAOS_DEF_ERROR_CODE(0, 0x03C3)
|
||||
#define TSDB_CODE_MND_INVALID_FUNC_COMMENT TAOS_DEF_ERROR_CODE(0, 0x03C4)
|
||||
#define TSDB_CODE_MND_INVALID_FUNC_CODE TAOS_DEF_ERROR_CODE(0, 0x03C5)
|
||||
#define TSDB_CODE_MND_INVALID_FUNC_BUFSIZE TAOS_DEF_ERROR_CODE(0, 0x03C6)
|
||||
|
||||
// dnode
|
||||
#define TSDB_CODE_DND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0400)
|
||||
|
@ -324,6 +309,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_QRY_INCONSISTAN TAOS_DEF_ERROR_CODE(0, 0x070C) //"File inconsistency in replica")
|
||||
#define TSDB_CODE_QRY_INVALID_TIME_CONDITION TAOS_DEF_ERROR_CODE(0, 0x070D) //"invalid time condition")
|
||||
#define TSDB_CODE_QRY_SYS_ERROR TAOS_DEF_ERROR_CODE(0, 0x070E) //"System error")
|
||||
#define TSDB_CODE_QRY_INVALID_INPUT TAOS_DEF_ERROR_CODE(0, 0x070F) //"invalid input")
|
||||
|
||||
|
||||
// grant
|
||||
|
@ -519,6 +505,12 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_CTG_MEM_ERROR TAOS_DEF_ERROR_CODE(0, 0x2403) //catalog memory error
|
||||
#define TSDB_CODE_CTG_SYS_ERROR TAOS_DEF_ERROR_CODE(0, 0x2404) //catalog system error
|
||||
|
||||
//scheduler
|
||||
#define TSDB_CODE_SCH_STATUS_ERROR TAOS_DEF_ERROR_CODE(0, 0x2501) //scheduler status error
|
||||
#define TSDB_CODE_SCH_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2502) //scheduler internal error
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -196,6 +196,7 @@ do { \
|
|||
|
||||
#define TSDB_AUTH_LEN 16
|
||||
#define TSDB_PASSWORD_LEN 32
|
||||
#define TSDB_USET_PASSWORD_LEN 129
|
||||
#define TSDB_VERSION_LEN 12
|
||||
#define TSDB_LABEL_LEN 8
|
||||
|
||||
|
@ -230,10 +231,11 @@ do { \
|
|||
#define TSDB_DEFAULT_PAYLOAD_SIZE 5120 // default payload size, greater than PATH_MAX value
|
||||
#define TSDB_EXTRA_PAYLOAD_SIZE 128 // extra bytes for auth
|
||||
#define TSDB_CQ_SQL_SIZE 1024
|
||||
#define TSDB_MIN_VNODES 64
|
||||
#define TSDB_MIN_VNODES 16
|
||||
#define TSDB_MAX_VNODES 512
|
||||
#define TSDB_MIN_VNODES_PER_DB 2
|
||||
#define TSDB_MAX_VNODES_PER_DB 64
|
||||
#define TSDB_MIN_VNODES_PER_DB 1
|
||||
#define TSDB_MAX_VNODES_PER_DB 4096
|
||||
#define TSDB_DEFAULT_VN_PER_DB 2
|
||||
|
||||
#define TSDB_DNODE_ROLE_ANY 0
|
||||
#define TSDB_DNODE_ROLE_MGMT 1
|
||||
|
@ -246,7 +248,7 @@ do { \
|
|||
#define TSDB_RES_COL_ID (-5000)
|
||||
|
||||
#define TSDB_MULTI_TABLEMETA_MAX_NUM 100000 // maximum batch size allowed to load table meta
|
||||
|
||||
|
||||
#define TSDB_MIN_CACHE_BLOCK_SIZE 1
|
||||
#define TSDB_MAX_CACHE_BLOCK_SIZE 128 // 128MB for each vnode
|
||||
#define TSDB_DEFAULT_CACHE_BLOCK_SIZE 16
|
||||
|
|
|
@ -1,169 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_UTIL_TDLIST_H_
|
||||
#define _TD_UTIL_TDLIST_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Single linked list
|
||||
#define TD_SLIST_NODE(TYPE) \
|
||||
struct { \
|
||||
struct TYPE *sl_next_; \
|
||||
}
|
||||
|
||||
#define TD_SLIST(TYPE) \
|
||||
struct { \
|
||||
struct TYPE *sl_head_; \
|
||||
int sl_neles_; \
|
||||
}
|
||||
|
||||
#define TD_SLIST_HEAD(sl) ((sl)->sl_head_)
|
||||
#define TD_SLIST_NELES(sl) ((sl)->sl_neles_)
|
||||
#define TD_SLIST_NODE_NEXT(sln) ((sln)->sl_next_)
|
||||
|
||||
#define tSListInit(sl) \
|
||||
do { \
|
||||
(sl)->sl_head_ = NULL; \
|
||||
(sl)->sl_neles_ = 0; \
|
||||
} while (0)
|
||||
|
||||
#define tSListPush(sl, sln) \
|
||||
do { \
|
||||
TD_SLIST_NODE_NEXT(sln) = TD_SLIST_HEAD(sl); \
|
||||
TD_SLIST_HEAD(sl) = (sln); \
|
||||
TD_SLIST_NELES(sl) += 1; \
|
||||
} while (0)
|
||||
|
||||
#define tSListPop(sl) \
|
||||
do { \
|
||||
TD_SLIST_HEAD(sl) = TD_SLIST_NODE_NEXT(TD_SLIST_HEAD(sl)); \
|
||||
TD_SLIST_NELES(sl) -= 1; \
|
||||
} while (0)
|
||||
|
||||
// Double linked list
|
||||
#define TD_DLIST_NODE(TYPE) \
|
||||
struct { \
|
||||
struct TYPE *dl_prev_; \
|
||||
struct TYPE *dl_next_; \
|
||||
}
|
||||
|
||||
#define TD_DLIST(TYPE) \
|
||||
struct { \
|
||||
struct TYPE *dl_head_; \
|
||||
struct TYPE *dl_tail_; \
|
||||
int dl_neles_; \
|
||||
}
|
||||
|
||||
#define TD_DLIST_NODE_PREV(dln) ((dln)->dl_prev_)
|
||||
#define TD_DLIST_NODE_NEXT(dln) ((dln)->dl_next_)
|
||||
#define TD_DLIST_HEAD(dl) ((dl)->dl_head_)
|
||||
#define TD_DLIST_TAIL(dl) ((dl)->dl_tail_)
|
||||
#define TD_DLIST_NELES(dl) ((dl)->dl_neles_)
|
||||
|
||||
#define tDListInit(dl) \
|
||||
do { \
|
||||
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = NULL; \
|
||||
TD_DLIST_NELES(dl) = 0; \
|
||||
} while (0)
|
||||
|
||||
#define tDListAppend(dl, dln) \
|
||||
do { \
|
||||
if (TD_DLIST_HEAD(dl) == NULL) { \
|
||||
TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \
|
||||
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = (dln); \
|
||||
} else { \
|
||||
TD_DLIST_NODE_PREV(dln) = TD_DLIST_TAIL(dl); \
|
||||
TD_DLIST_NODE_NEXT(dln) = NULL; \
|
||||
TD_DLIST_NODE_NEXT(TD_DLIST_TAIL(dl)) = (dln); \
|
||||
TD_DLIST_TAIL(dl) = (dln); \
|
||||
} \
|
||||
TD_DLIST_NELES(dl) += 1; \
|
||||
} while (0)
|
||||
|
||||
#define tDListPrepend(dl, dln) \
|
||||
do { \
|
||||
if (TD_DLIST_HEAD(dl) == NULL) { \
|
||||
TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \
|
||||
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = (dln); \
|
||||
} else { \
|
||||
TD_DLIST_NODE_PREV(dln) = NULL; \
|
||||
TD_DLIST_NODE_NEXT(dln) = TD_DLIST_HEAD(dl); \
|
||||
TD_DLIST_NODE_PREV(TD_DLIST_HEAD(dl)) = (dln); \
|
||||
TD_DLIST_HEAD(dl) = (dln); \
|
||||
} \
|
||||
TD_DLIST_NELES(dl) += 1; \
|
||||
} while (0)
|
||||
|
||||
#define tDListPop(dl, dln) \
|
||||
do { \
|
||||
if (TD_DLIST_HEAD(dl) == (dln)) { \
|
||||
TD_DLIST_HEAD(dl) = TD_DLIST_NODE_NEXT(dln); \
|
||||
} \
|
||||
if (TD_DLIST_TAIL(dl) == (dln)) { \
|
||||
TD_DLIST_TAIL(dl) = TD_DLIST_NODE_PREV(dln); \
|
||||
} \
|
||||
if (TD_DLIST_NODE_PREV(dln) != NULL) { \
|
||||
TD_DLIST_NODE_NEXT(TD_DLIST_NODE_PREV(dln)) = TD_DLIST_NODE_NEXT(dln); \
|
||||
} \
|
||||
if (TD_DLIST_NODE_NEXT(dln) != NULL) { \
|
||||
TD_DLIST_NODE_PREV(TD_DLIST_NODE_NEXT(dln)) = TD_DLIST_NODE_PREV(dln); \
|
||||
} \
|
||||
TD_DLIST_NELES(dl) -= 1; \
|
||||
TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \
|
||||
} while (0)
|
||||
|
||||
#if 0
|
||||
// List iterator
|
||||
#define TD_LIST_FITER 0
|
||||
#define TD_LIST_BITER 1
|
||||
#define TD_LIST_ITER(S) \
|
||||
struct { \
|
||||
int it_dir_; \
|
||||
S * it_next_; \
|
||||
S * it_ptr_; \
|
||||
TD_DLIST(S) * it_list_; \
|
||||
}
|
||||
|
||||
#define tlistIterInit(it, l, dir) \
|
||||
(it)->it_dir_ = (dir); \
|
||||
(it)->it_list_ = l; \
|
||||
if ((dir) == TD_LIST_FITER) { \
|
||||
(it)->it_next_ = (l)->dl_head_; \
|
||||
} else { \
|
||||
(it)->it_next_ = (l)->dl_tail_; \
|
||||
}
|
||||
|
||||
#define tlistIterNext(it) \
|
||||
({ \
|
||||
(it)->it_ptr_ = (it)->it_next_; \
|
||||
if ((it)->it_next_ != NULL) { \
|
||||
if ((it)->it_dir_ == TD_LIST_FITER) { \
|
||||
(it)->it_next_ = (it)->it_next_->next_; \
|
||||
} else { \
|
||||
(it)->it_next_ = (it)->it_next_->prev_; \
|
||||
} \
|
||||
} \
|
||||
(it)->it_ptr_; \
|
||||
})
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_UTIL_TDLIST_H_*/
|
|
@ -19,19 +19,124 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Single linked list ================
|
||||
#define TD_SLIST_NODE(TYPE) \
|
||||
struct { \
|
||||
struct TYPE *sl_next_; \
|
||||
}
|
||||
|
||||
#define TD_SLIST(TYPE) \
|
||||
struct { \
|
||||
struct TYPE *sl_head_; \
|
||||
int sl_neles_; \
|
||||
}
|
||||
|
||||
#define TD_SLIST_HEAD(sl) ((sl)->sl_head_)
|
||||
#define TD_SLIST_NELES(sl) ((sl)->sl_neles_)
|
||||
#define TD_SLIST_NODE_NEXT(sln) ((sln)->sl_next_)
|
||||
|
||||
#define TD_SLIST_INIT(sl) \
|
||||
do { \
|
||||
(sl)->sl_head_ = NULL; \
|
||||
(sl)->sl_neles_ = 0; \
|
||||
} while (0)
|
||||
|
||||
#define TD_SLIST_PUSH(sl, sln) \
|
||||
do { \
|
||||
TD_SLIST_NODE_NEXT(sln) = TD_SLIST_HEAD(sl); \
|
||||
TD_SLIST_HEAD(sl) = (sln); \
|
||||
TD_SLIST_NELES(sl) += 1; \
|
||||
} while (0)
|
||||
|
||||
#define TD_SLIST_POP(sl) \
|
||||
do { \
|
||||
TD_SLIST_HEAD(sl) = TD_SLIST_NODE_NEXT(TD_SLIST_HEAD(sl)); \
|
||||
TD_SLIST_NELES(sl) -= 1; \
|
||||
} while (0)
|
||||
|
||||
// Double linked list ================
|
||||
#define TD_DLIST_NODE(TYPE) \
|
||||
struct { \
|
||||
struct TYPE *dl_prev_; \
|
||||
struct TYPE *dl_next_; \
|
||||
}
|
||||
|
||||
#define TD_DLIST(TYPE) \
|
||||
struct { \
|
||||
struct TYPE *dl_head_; \
|
||||
struct TYPE *dl_tail_; \
|
||||
int dl_neles_; \
|
||||
}
|
||||
|
||||
#define TD_DLIST_NODE_PREV(dln) ((dln)->dl_prev_)
|
||||
#define TD_DLIST_NODE_NEXT(dln) ((dln)->dl_next_)
|
||||
#define TD_DLIST_HEAD(dl) ((dl)->dl_head_)
|
||||
#define TD_DLIST_TAIL(dl) ((dl)->dl_tail_)
|
||||
#define TD_DLIST_NELES(dl) ((dl)->dl_neles_)
|
||||
|
||||
#define TD_DLIST_INIT(dl) \
|
||||
do { \
|
||||
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = NULL; \
|
||||
TD_DLIST_NELES(dl) = 0; \
|
||||
} while (0)
|
||||
|
||||
#define TD_DLIST_APPEND(dl, dln) \
|
||||
do { \
|
||||
if (TD_DLIST_HEAD(dl) == NULL) { \
|
||||
TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \
|
||||
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = (dln); \
|
||||
} else { \
|
||||
TD_DLIST_NODE_PREV(dln) = TD_DLIST_TAIL(dl); \
|
||||
TD_DLIST_NODE_NEXT(dln) = NULL; \
|
||||
TD_DLIST_NODE_NEXT(TD_DLIST_TAIL(dl)) = (dln); \
|
||||
TD_DLIST_TAIL(dl) = (dln); \
|
||||
} \
|
||||
TD_DLIST_NELES(dl) += 1; \
|
||||
} while (0)
|
||||
|
||||
#define TD_DLIST_PREPEND(dl, dln) \
|
||||
do { \
|
||||
if (TD_DLIST_HEAD(dl) == NULL) { \
|
||||
TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \
|
||||
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = (dln); \
|
||||
} else { \
|
||||
TD_DLIST_NODE_PREV(dln) = NULL; \
|
||||
TD_DLIST_NODE_NEXT(dln) = TD_DLIST_HEAD(dl); \
|
||||
TD_DLIST_NODE_PREV(TD_DLIST_HEAD(dl)) = (dln); \
|
||||
TD_DLIST_HEAD(dl) = (dln); \
|
||||
} \
|
||||
TD_DLIST_NELES(dl) += 1; \
|
||||
} while (0)
|
||||
|
||||
#define TD_DLIST_POP(dl, dln) \
|
||||
do { \
|
||||
if (TD_DLIST_HEAD(dl) == (dln)) { \
|
||||
TD_DLIST_HEAD(dl) = TD_DLIST_NODE_NEXT(dln); \
|
||||
} \
|
||||
if (TD_DLIST_TAIL(dl) == (dln)) { \
|
||||
TD_DLIST_TAIL(dl) = TD_DLIST_NODE_PREV(dln); \
|
||||
} \
|
||||
if (TD_DLIST_NODE_PREV(dln) != NULL) { \
|
||||
TD_DLIST_NODE_NEXT(TD_DLIST_NODE_PREV(dln)) = TD_DLIST_NODE_NEXT(dln); \
|
||||
} \
|
||||
if (TD_DLIST_NODE_NEXT(dln) != NULL) { \
|
||||
TD_DLIST_NODE_PREV(TD_DLIST_NODE_NEXT(dln)) = TD_DLIST_NODE_PREV(dln); \
|
||||
} \
|
||||
TD_DLIST_NELES(dl) -= 1; \
|
||||
TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \
|
||||
} while (0)
|
||||
|
||||
// General double linked list
|
||||
typedef enum { TD_LIST_FORWARD, TD_LIST_BACKWARD } TD_LIST_DIRECTION_T;
|
||||
|
||||
typedef struct _list_node {
|
||||
struct _list_node *next;
|
||||
struct _list_node *prev;
|
||||
char data[];
|
||||
typedef struct SListNode {
|
||||
TD_DLIST_NODE(SListNode);
|
||||
char data[];
|
||||
} SListNode;
|
||||
|
||||
typedef struct {
|
||||
struct _list_node *head;
|
||||
struct _list_node *tail;
|
||||
int numOfEles;
|
||||
int eleSize;
|
||||
TD_DLIST(SListNode);
|
||||
int eleSize;
|
||||
} SList;
|
||||
|
||||
typedef struct {
|
||||
|
@ -39,11 +144,11 @@ typedef struct {
|
|||
TD_LIST_DIRECTION_T direction;
|
||||
} SListIter;
|
||||
|
||||
#define listHead(l) (l)->head
|
||||
#define listTail(l) (l)->tail
|
||||
#define listNEles(l) (l)->numOfEles
|
||||
#define listEleSize(l) (l)->eleSize
|
||||
#define isListEmpty(l) ((l)->numOfEles == 0)
|
||||
#define listHead(l) TD_DLIST_HEAD(l)
|
||||
#define listTail(l) TD_DLIST_TAIL(l)
|
||||
#define listNEles(l) TD_DLIST_NELES(l)
|
||||
#define listEleSize(l) ((l)->eleSize)
|
||||
#define isListEmpty(l) (TD_DLIST_NELES(l) == 0)
|
||||
#define listNodeFree(n) free(n)
|
||||
|
||||
void tdListInit(SList *list, int eleSize);
|
||||
|
|
|
@ -2,14 +2,13 @@ aux_source_directory(src CLIENT_SRC)
|
|||
add_library(taos ${CLIENT_SRC})
|
||||
target_include_directories(
|
||||
taos
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/client"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/client"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
target_link_libraries(
|
||||
taos
|
||||
PRIVATE common
|
||||
INTERFACE api
|
||||
PRIVATE os util common transport parser
|
||||
PRIVATE os util common transport parser catalog function qcom
|
||||
)
|
||||
|
||||
ADD_SUBDIRECTORY(test)
|
|
@ -21,13 +21,14 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "taos.h"
|
||||
#include "common.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tdef.h"
|
||||
#include "tep.h"
|
||||
#include "thash.h"
|
||||
#include "tlist.h"
|
||||
#include "trpc.h"
|
||||
#include "tdef.h"
|
||||
#include "tmsgtype.h"
|
||||
#include "tep.h"
|
||||
#include "trpc.h"
|
||||
|
||||
typedef struct SQueryExecMetric {
|
||||
int64_t start; // start timestamp
|
||||
|
@ -75,23 +76,39 @@ typedef struct SAppInfo {
|
|||
typedef struct STscObj {
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_PASSWORD_LEN];
|
||||
char acctId[TSDB_ACCT_ID_LEN];
|
||||
char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
|
||||
int32_t acctId;
|
||||
uint32_t connId;
|
||||
uint64_t id; // ref ID returned by taosAddRef
|
||||
// struct SSqlObj *sqlList;
|
||||
void *pTransporter;
|
||||
pthread_mutex_t mutex; // used to protect the operation on db
|
||||
int32_t numOfReqs; // number of sqlObj from this tscObj
|
||||
SAppInstInfo *pAppInfo;
|
||||
} STscObj;
|
||||
|
||||
typedef struct SClientResultInfo {
|
||||
const char *pMsg;
|
||||
const char *pData;
|
||||
TAOS_FIELD *fields;
|
||||
int32_t numOfCols;
|
||||
int32_t numOfRows;
|
||||
int32_t current;
|
||||
int32_t *length;
|
||||
TAOS_ROW row;
|
||||
char **pCol;
|
||||
} SClientResultInfo;
|
||||
|
||||
typedef struct SReqBody {
|
||||
tsem_t rspSem; // not used now
|
||||
void* fp;
|
||||
void* param;
|
||||
int32_t paramLen;
|
||||
int64_t execId; // showId/queryId
|
||||
SClientResultInfo* pResInfo;
|
||||
} SRequestBody;
|
||||
|
||||
#define ERROR_MSG_BUF_DEFAULT_SIZE 512
|
||||
|
||||
typedef struct SRequestObj {
|
||||
uint64_t requestId;
|
||||
int32_t type; // request type
|
||||
|
@ -118,7 +135,7 @@ extern int32_t tscReqRef;
|
|||
extern void *tscQhandle;
|
||||
extern int32_t tscConnRef;
|
||||
|
||||
extern int (*tscBuildMsg[TSDB_SQL_MAX])(SRequestObj *pRequest, SRequestMsgBody *pMsg);
|
||||
extern int (*buildRequestMsgFp[TSDB_SQL_MAX])(SRequestObj *pRequest, SRequestMsgBody *pMsgBody);
|
||||
extern int (*handleRequestRspFp[TSDB_SQL_MAX])(SRequestObj *pRequest, const char* pMsg, int32_t msgLen);
|
||||
|
||||
int taos_init();
|
||||
|
@ -129,8 +146,6 @@ void destroyTscObj(void*pObj);
|
|||
void* createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t type);
|
||||
void destroyRequest(SRequestObj* pRequest);
|
||||
|
||||
TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, const char *auth, const char *db, uint16_t port);
|
||||
|
||||
void taos_init_imp(void);
|
||||
int taos_options_imp(TSDB_OPTION option, const char *str);
|
||||
|
||||
|
@ -139,6 +154,12 @@ void* openTransporter(const char *user, const char *auth);
|
|||
void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet);
|
||||
void initMsgHandleFp();
|
||||
|
||||
TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, const char *auth, const char *db, uint16_t port);
|
||||
TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen);
|
||||
|
||||
void* doFetchRow(SRequestObj* pRequest);
|
||||
void setResultDataPtr(SClientResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TDENGINE_TSCLOG_H
|
||||
#define TDENGINE_TSCLOG_H
|
||||
#ifndef TDENGINE_CLIENTLOG_H
|
||||
#define TDENGINE_CLIENTLOG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "os.h"
|
||||
#include "tdef.h"
|
||||
#include "tglobal.h"
|
||||
#include "clientInt.h"
|
||||
#include "tscLog.h"
|
||||
|
||||
TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) {
|
||||
int32_t p = (port != 0)? port:tsServerPort;
|
||||
|
||||
tscDebug("try to connect to %s:%u, user:%s db:%s", ip, p, user, db);
|
||||
if (user == NULL) {
|
||||
user = TSDB_DEFAULT_USER;
|
||||
}
|
||||
|
||||
if (pass == NULL) {
|
||||
pass = TSDB_DEFAULT_PASS;
|
||||
}
|
||||
|
||||
return taos_connect_internal(ip, user, pass, NULL, db, p);
|
||||
}
|
||||
|
||||
TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port) {
|
||||
tscDebug("try to connect to %s:%u by auth, user:%s db:%s", ip, port, user, db);
|
||||
if (user == NULL) {
|
||||
user = TSDB_DEFAULT_USER;
|
||||
}
|
||||
|
||||
if (auth == NULL) {
|
||||
tscError("No auth info is given, failed to connect to server");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return taos_connect_internal(ip, user, NULL, auth, db, port);
|
||||
}
|
||||
|
||||
TAOS *taos_connect_l(const char *ip, int ipLen, const char *user, int userLen, const char *pass, int passLen, const char *db, int dbLen, uint16_t port) {
|
||||
char ipStr[TSDB_EP_LEN] = {0};
|
||||
char dbStr[TSDB_DB_NAME_LEN] = {0};
|
||||
char userStr[TSDB_USER_LEN] = {0};
|
||||
char passStr[TSDB_PASSWORD_LEN] = {0};
|
||||
|
||||
strncpy(ipStr, ip, MIN(TSDB_EP_LEN - 1, ipLen));
|
||||
strncpy(userStr, user, MIN(TSDB_USER_LEN - 1, userLen));
|
||||
strncpy(passStr, pass, MIN(TSDB_PASSWORD_LEN - 1, passLen));
|
||||
strncpy(dbStr, db, MIN(TSDB_DB_NAME_LEN - 1, dbLen));
|
||||
return taos_connect(ipStr, userStr, passStr, dbStr, port);
|
||||
}
|
||||
|
|
@ -1,15 +1,18 @@
|
|||
#include <tpagedfile.h>
|
||||
|
||||
#include "clientInt.h"
|
||||
#include "clientLog.h"
|
||||
#include "tdef.h"
|
||||
#include "tep.h"
|
||||
#include "tglobal.h"
|
||||
#include "tmsgtype.h"
|
||||
#include "tnote.h"
|
||||
#include "tpagedfile.h"
|
||||
#include "tref.h"
|
||||
#include "tscLog.h"
|
||||
#include "parser.h"
|
||||
|
||||
static int32_t initEpSetFromCfg(const char *firstEp, const char *secondEp, SCorEpSet *pEpSet);
|
||||
static int32_t buildConnectMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody);
|
||||
static void destroyConnectMsg(SRequestMsgBody* pMsgBody);
|
||||
static void destroyRequestMsgBody(SRequestMsgBody* pMsgBody);
|
||||
|
||||
static int32_t sendMsgToServer(void *pTransporter, SEpSet* epSet, const SRequestMsgBody *pBody, int64_t* pTransporterId);
|
||||
|
||||
|
@ -96,17 +99,84 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass,
|
|||
|
||||
char* key = getClusterKey(user, secretEncrypt, ip, port);
|
||||
|
||||
SAppInstInfo* pInst = taosHashGet(appInfo.pInstMap, key, strlen(key));
|
||||
SAppInstInfo** pInst = taosHashGet(appInfo.pInstMap, key, strlen(key));
|
||||
if (pInst == NULL) {
|
||||
pInst = calloc(1, sizeof(struct SAppInstInfo));
|
||||
SAppInstInfo* p = calloc(1, sizeof(struct SAppInstInfo));
|
||||
|
||||
pInst->mgmtEp = epSet;
|
||||
pInst->pTransporter = openTransporter(user, secretEncrypt);
|
||||
p->mgmtEp = epSet;
|
||||
p->pTransporter = openTransporter(user, secretEncrypt);
|
||||
taosHashPut(appInfo.pInstMap, key, strlen(key), &p, POINTER_BYTES);
|
||||
|
||||
taosHashPut(appInfo.pInstMap, key, strlen(key), &pInst, POINTER_BYTES);
|
||||
pInst = &p;
|
||||
}
|
||||
|
||||
return taosConnectImpl(ip, user, &secretEncrypt[0], db, port, NULL, NULL, pInst);
|
||||
tfree(key);
|
||||
return taosConnectImpl(ip, user, &secretEncrypt[0], db, port, NULL, NULL, *pInst);
|
||||
}
|
||||
|
||||
TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) {
|
||||
STscObj *pTscObj = (STscObj *)taos;
|
||||
if (sqlLen > (size_t) tsMaxSQLStringLen) {
|
||||
tscError("sql string exceeds max length:%d", tsMaxSQLStringLen);
|
||||
terrno = TSDB_CODE_TSC_EXCEED_SQL_LIMIT;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nPrintTsc("%s", sql)
|
||||
|
||||
SRequestObj* pRequest = createRequest(pTscObj, NULL, NULL, TSDB_SQL_SELECT);
|
||||
if (pRequest == NULL) {
|
||||
tscError("failed to malloc sqlObj");
|
||||
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pRequest->sqlstr = malloc(sqlLen + 1);
|
||||
if (pRequest->sqlstr == NULL) {
|
||||
tscError("0x%"PRIx64" failed to prepare sql string buffer", pRequest->self);
|
||||
|
||||
pRequest->msgBuf = strdup("failed to prepare sql string buffer");
|
||||
terrno = pRequest->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
return pRequest;
|
||||
}
|
||||
|
||||
strntolower(pRequest->sqlstr, sql, (int32_t)sqlLen);
|
||||
pRequest->sqlstr[sqlLen] = 0;
|
||||
|
||||
tscDebugL("0x%"PRIx64" SQL: %s", pRequest->requestId, pRequest->sqlstr);
|
||||
|
||||
int32_t code = 0;
|
||||
if (qIsInsertSql(pRequest->sqlstr, sqlLen)) {
|
||||
// todo add
|
||||
} else {
|
||||
int32_t type = 0;
|
||||
void* output = NULL;
|
||||
int32_t outputLen = 0;
|
||||
code = qParseQuerySql(pRequest->sqlstr, sqlLen, pRequest->requestId, &type, &output, &outputLen, pRequest->msgBuf, ERROR_MSG_BUF_DEFAULT_SIZE);
|
||||
if (type == TSDB_SQL_CREATE_USER || type == TSDB_SQL_SHOW || type == TSDB_SQL_DROP_USER || type == TSDB_SQL_CREATE_DB) {
|
||||
pRequest->type = type;
|
||||
pRequest->body.param = output;
|
||||
pRequest->body.paramLen = outputLen;
|
||||
|
||||
SRequestMsgBody body = {0};
|
||||
buildRequestMsgFp[type](pRequest, &body);
|
||||
|
||||
int64_t transporterId = 0;
|
||||
sendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &body, &transporterId);
|
||||
|
||||
tsem_wait(&pRequest->body.rspSem);
|
||||
destroyRequestMsgBody(&body);
|
||||
} else {
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
pRequest->code = code;
|
||||
return pRequest;
|
||||
}
|
||||
|
||||
return pRequest;
|
||||
}
|
||||
|
||||
int initEpSetFromCfg(const char *firstEp, const char *secondEp, SCorEpSet *pEpSet) {
|
||||
|
@ -166,7 +236,7 @@ STscObj* taosConnectImpl(const char *ip, const char *user, const char *auth, con
|
|||
sendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &body, &transporterId);
|
||||
|
||||
tsem_wait(&pRequest->body.rspSem);
|
||||
destroyConnectMsg(&body);
|
||||
destroyRequestMsgBody(&body);
|
||||
|
||||
if (pRequest->code != TSDB_CODE_SUCCESS) {
|
||||
const char *errorMsg = (pRequest->code == TSDB_CODE_RPC_FQDN_ERROR) ? taos_errstr(pRequest) : tstrerror(terrno);
|
||||
|
@ -213,7 +283,7 @@ static int32_t buildConnectMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void destroyConnectMsg(SRequestMsgBody* pMsgBody) {
|
||||
static void destroyRequestMsgBody(SRequestMsgBody* pMsgBody) {
|
||||
assert(pMsgBody != NULL);
|
||||
tfree(pMsgBody->pData);
|
||||
}
|
||||
|
@ -269,11 +339,18 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
|
|||
tscDebug("0x%" PRIx64 " message:%s, code:%s rspLen:%d, elapsed:%"PRId64 " ms", pRequest->requestId, taosMsg[pMsg->msgType],
|
||||
tstrerror(pMsg->code), pMsg->contLen, pRequest->metric.rsp - pRequest->metric.start);
|
||||
if (handleRequestRspFp[pRequest->type]) {
|
||||
pMsg->code = (*handleRequestRspFp[pRequest->type])(pRequest, pMsg->pCont, pMsg->contLen);
|
||||
char *p = malloc(pMsg->contLen);
|
||||
if (p == NULL) {
|
||||
pRequest->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
terrno = pRequest->code;
|
||||
} else {
|
||||
memcpy(p, pMsg->pCont, pMsg->contLen);
|
||||
pMsg->code = (*handleRequestRspFp[pRequest->type])(pRequest, p, pMsg->contLen);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tscError("0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d", pRequest->requestId, taosMsg[pMsg->msgType],
|
||||
tstrerror(pMsg->code), pMsg->contLen);
|
||||
tscError("0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d, elapsed time:%"PRId64" ms", pRequest->requestId, taosMsg[pMsg->msgType],
|
||||
tstrerror(pMsg->code), pMsg->contLen, pRequest->metric.rsp - pRequest->metric.start);
|
||||
}
|
||||
|
||||
taosReleaseRef(tscReqRef, requestRefId);
|
||||
|
@ -281,3 +358,86 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
|
|||
|
||||
sem_post(&pRequest->body.rspSem);
|
||||
}
|
||||
|
||||
TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port) {
|
||||
tscDebug("try to connect to %s:%u by auth, user:%s db:%s", ip, port, user, db);
|
||||
if (user == NULL) {
|
||||
user = TSDB_DEFAULT_USER;
|
||||
}
|
||||
|
||||
if (auth == NULL) {
|
||||
tscError("No auth info is given, failed to connect to server");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return taos_connect_internal(ip, user, NULL, auth, db, port);
|
||||
}
|
||||
|
||||
TAOS *taos_connect_l(const char *ip, int ipLen, const char *user, int userLen, const char *pass, int passLen, const char *db, int dbLen, uint16_t port) {
|
||||
char ipStr[TSDB_EP_LEN] = {0};
|
||||
char dbStr[TSDB_DB_NAME_LEN] = {0};
|
||||
char userStr[TSDB_USER_LEN] = {0};
|
||||
char passStr[TSDB_PASSWORD_LEN] = {0};
|
||||
|
||||
strncpy(ipStr, ip, MIN(TSDB_EP_LEN - 1, ipLen));
|
||||
strncpy(userStr, user, MIN(TSDB_USER_LEN - 1, userLen));
|
||||
strncpy(passStr, pass, MIN(TSDB_PASSWORD_LEN - 1, passLen));
|
||||
strncpy(dbStr, db, MIN(TSDB_DB_NAME_LEN - 1, dbLen));
|
||||
return taos_connect(ipStr, userStr, passStr, dbStr, port);
|
||||
}
|
||||
|
||||
void* doFetchRow(SRequestObj* pRequest) {
|
||||
assert(pRequest != NULL);
|
||||
SClientResultInfo* pResultInfo = pRequest->body.pResInfo;
|
||||
|
||||
if (pResultInfo->pData == NULL || pResultInfo->current >= pResultInfo->numOfRows) {
|
||||
pRequest->type = TSDB_SQL_RETRIEVE_MNODE;
|
||||
|
||||
SRequestMsgBody body = {0};
|
||||
buildRequestMsgFp[pRequest->type](pRequest, &body);
|
||||
|
||||
int64_t transporterId = 0;
|
||||
STscObj* pTscObj = pRequest->pTscObj;
|
||||
sendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &body, &transporterId);
|
||||
|
||||
tsem_wait(&pRequest->body.rspSem);
|
||||
destroyRequestMsgBody(&body);
|
||||
|
||||
pResultInfo->current = 0;
|
||||
if (pResultInfo->numOfRows <= pResultInfo->current) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
for(int32_t i = 0; i < pResultInfo->numOfCols; ++i) {
|
||||
pResultInfo->row[i] = pResultInfo->pCol[i] + pResultInfo->fields[i].bytes * pResultInfo->current;
|
||||
if (IS_VAR_DATA_TYPE(pResultInfo->fields[i].type)) {
|
||||
pResultInfo->length[i] = varDataLen(pResultInfo->row[i]);
|
||||
pResultInfo->row[i] = varDataVal(pResultInfo->row[i]);
|
||||
}
|
||||
}
|
||||
|
||||
pResultInfo->current += 1;
|
||||
return pResultInfo->row;
|
||||
}
|
||||
|
||||
void setResultDataPtr(SClientResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows) {
|
||||
assert(numOfCols > 0 && pFields != NULL && pResultInfo != NULL);
|
||||
if (numOfRows == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t offset = 0;
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
pResultInfo->length[i] = pResultInfo->fields[i].bytes;
|
||||
pResultInfo->row[i] = (char*) (pResultInfo->pData + offset * pResultInfo->numOfRows);
|
||||
pResultInfo->pCol[i] = pResultInfo->row[i];
|
||||
offset += pResultInfo->fields[i].bytes;
|
||||
}
|
||||
}
|
||||
|
||||
const char *taos_get_client_info() { return version; }
|
||||
|
||||
int taos_affected_rows(TAOS_RES *res) { return 1; }
|
||||
|
||||
int taos_result_precision(TAOS_RES *res) { return TSDB_TIME_PRECISION_MILLI; }
|
||||
|
|
|
@ -0,0 +1,269 @@
|
|||
#include "clientInt.h"
|
||||
#include "clientLog.h"
|
||||
#include "os.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tcache.h"
|
||||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "tnote.h"
|
||||
#include "tref.h"
|
||||
#include "trpc.h"
|
||||
#include "tsched.h"
|
||||
#include "ttime.h"
|
||||
#include "ttimezone.h"
|
||||
|
||||
#define TSC_VAR_NOT_RELEASE 1
|
||||
#define TSC_VAR_RELEASED 0
|
||||
|
||||
static int32_t sentinel = TSC_VAR_NOT_RELEASE;
|
||||
|
||||
int taos_options(TSDB_OPTION option, const void *arg, ...) {
|
||||
static int32_t lock = 0;
|
||||
|
||||
for (int i = 1; atomic_val_compare_exchange_32(&lock, 0, 1) != 0; ++i) {
|
||||
if (i % 1000 == 0) {
|
||||
tscInfo("haven't acquire lock after spin %d times.", i);
|
||||
sched_yield();
|
||||
}
|
||||
}
|
||||
|
||||
int ret = taos_options_imp(option, (const char*)arg);
|
||||
atomic_store_32(&lock, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// this function may be called by user or system, or by both simultaneously.
|
||||
void taos_cleanup(void) {
|
||||
tscDebug("start to cleanup client environment");
|
||||
|
||||
if (atomic_val_compare_exchange_32(&sentinel, TSC_VAR_NOT_RELEASE, TSC_VAR_RELEASED) != TSC_VAR_NOT_RELEASE) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t id = tscReqRef;
|
||||
tscReqRef = -1;
|
||||
taosCloseRef(id);
|
||||
|
||||
void* p = tscQhandle;
|
||||
tscQhandle = NULL;
|
||||
taosCleanUpScheduler(p);
|
||||
|
||||
id = tscConnRef;
|
||||
tscConnRef = -1;
|
||||
taosCloseRef(id);
|
||||
|
||||
rpcCleanup();
|
||||
taosCloseLog();
|
||||
}
|
||||
|
||||
TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) {
|
||||
int32_t p = (port != 0) ? port : tsServerPort;
|
||||
|
||||
tscDebug("try to connect to %s:%u, user:%s db:%s", ip, p, user, db);
|
||||
if (user == NULL) {
|
||||
user = TSDB_DEFAULT_USER;
|
||||
}
|
||||
|
||||
if (pass == NULL) {
|
||||
pass = TSDB_DEFAULT_PASS;
|
||||
}
|
||||
|
||||
return taos_connect_internal(ip, user, pass, NULL, db, p);
|
||||
}
|
||||
|
||||
void taos_close(TAOS* taos) {
|
||||
if (taos == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
STscObj *pTscObj = (STscObj *)taos;
|
||||
tscDebug("0x%"PRIx64" try to close connection, numOfReq:%d", pTscObj->id, pTscObj->numOfReqs);
|
||||
|
||||
taosRemoveRef(tscConnRef, pTscObj->id);
|
||||
}
|
||||
|
||||
int taos_errno(TAOS_RES *tres) {
|
||||
if (tres == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return ((SRequestObj*) tres)->code;
|
||||
}
|
||||
|
||||
const char *taos_errstr(TAOS_RES *res) {
|
||||
SRequestObj *pRequest = (SRequestObj *) res;
|
||||
|
||||
if (pRequest == NULL) {
|
||||
return (const char*) tstrerror(terrno);
|
||||
}
|
||||
|
||||
if (strlen(pRequest->msgBuf) > 0 || pRequest->code == TSDB_CODE_RPC_FQDN_ERROR) {
|
||||
return pRequest->msgBuf;
|
||||
} else {
|
||||
return (const char*)tstrerror(pRequest->code);
|
||||
}
|
||||
}
|
||||
|
||||
void taos_free_result(TAOS_RES *res) {
|
||||
SRequestObj* pRequest = (SRequestObj*) res;
|
||||
destroyRequest(pRequest);
|
||||
}
|
||||
|
||||
int taos_field_count(TAOS_RES *res) {
|
||||
if (res == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
SRequestObj* pRequest = (SRequestObj*) res;
|
||||
|
||||
SClientResultInfo* pResInfo = pRequest->body.pResInfo;
|
||||
if (pResInfo == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return pResInfo->numOfCols;
|
||||
}
|
||||
|
||||
int taos_num_fields(TAOS_RES *res) {
|
||||
return taos_field_count(res);
|
||||
}
|
||||
|
||||
TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) {
|
||||
if (taos_num_fields(res) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SClientResultInfo* pResInfo = ((SRequestObj*) res)->body.pResInfo;
|
||||
return pResInfo->fields;
|
||||
}
|
||||
|
||||
TAOS_RES *taos_query(TAOS *taos, const char *sql) {
|
||||
if (taos == NULL || sql == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return taos_query_l(taos, sql, strlen(sql));
|
||||
}
|
||||
|
||||
TAOS_ROW taos_fetch_row(TAOS_RES *pRes) {
|
||||
if (pRes == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SRequestObj *pRequest = (SRequestObj *) pRes;
|
||||
if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT ||
|
||||
pRequest->type == TSDB_SQL_INSERT) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return doFetchRow(pRequest);
|
||||
}
|
||||
|
||||
int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) {
|
||||
int32_t len = 0;
|
||||
for (int i = 0; i < num_fields; ++i) {
|
||||
if (i > 0) {
|
||||
str[len++] = ' ';
|
||||
}
|
||||
|
||||
if (row[i] == NULL) {
|
||||
len += sprintf(str + len, "%s", TSDB_DATA_NULL_STR);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (fields[i].type) {
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
len += sprintf(str + len, "%d", *((int8_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
len += sprintf(str + len, "%u", *((uint8_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
len += sprintf(str + len, "%d", *((int16_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
len += sprintf(str + len, "%u", *((uint16_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
len += sprintf(str + len, "%d", *((int32_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
len += sprintf(str + len, "%u", *((uint32_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
len += sprintf(str + len, "%" PRId64, *((int64_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
len += sprintf(str + len, "%" PRIu64, *((uint64_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
float fv = 0;
|
||||
fv = GET_FLOAT_VAL(row[i]);
|
||||
len += sprintf(str + len, "%f", fv);
|
||||
} break;
|
||||
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
double dv = 0;
|
||||
dv = GET_DOUBLE_VAL(row[i]);
|
||||
len += sprintf(str + len, "%lf", dv);
|
||||
} break;
|
||||
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR: {
|
||||
int32_t charLen = varDataLen((char*)row[i] - VARSTR_HEADER_SIZE);
|
||||
if (fields[i].type == TSDB_DATA_TYPE_BINARY) {
|
||||
assert(charLen <= fields[i].bytes && charLen >= 0);
|
||||
} else {
|
||||
assert(charLen <= fields[i].bytes * TSDB_NCHAR_SIZE && charLen >= 0);
|
||||
}
|
||||
|
||||
memcpy(str + len, row[i], charLen);
|
||||
len += charLen;
|
||||
} break;
|
||||
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
len += sprintf(str + len, "%" PRId64, *((int64_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
len += sprintf(str + len, "%d", *((int8_t *)row[i]));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int* taos_fetch_lengths(TAOS_RES *res) {
|
||||
if (res == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ((SRequestObj*) res)->body.pResInfo->length;
|
||||
}
|
||||
|
||||
const char *taos_data_type(int type) {
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_NULL: return "TSDB_DATA_TYPE_NULL";
|
||||
case TSDB_DATA_TYPE_BOOL: return "TSDB_DATA_TYPE_BOOL";
|
||||
case TSDB_DATA_TYPE_TINYINT: return "TSDB_DATA_TYPE_TINYINT";
|
||||
case TSDB_DATA_TYPE_SMALLINT: return "TSDB_DATA_TYPE_SMALLINT";
|
||||
case TSDB_DATA_TYPE_INT: return "TSDB_DATA_TYPE_INT";
|
||||
case TSDB_DATA_TYPE_BIGINT: return "TSDB_DATA_TYPE_BIGINT";
|
||||
case TSDB_DATA_TYPE_FLOAT: return "TSDB_DATA_TYPE_FLOAT";
|
||||
case TSDB_DATA_TYPE_DOUBLE: return "TSDB_DATA_TYPE_DOUBLE";
|
||||
case TSDB_DATA_TYPE_BINARY: return "TSDB_DATA_TYPE_BINARY";
|
||||
case TSDB_DATA_TYPE_TIMESTAMP: return "TSDB_DATA_TYPE_TIMESTAMP";
|
||||
case TSDB_DATA_TYPE_NCHAR: return "TSDB_DATA_TYPE_NCHAR";
|
||||
default: return "UNKNOWN";
|
||||
}
|
||||
}
|
|
@ -13,11 +13,13 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "os.h"
|
||||
#include <catalog.h>
|
||||
#include <tname.h>
|
||||
#include "clientInt.h"
|
||||
#include "clientLog.h"
|
||||
#include "os.h"
|
||||
#include "tmsgtype.h"
|
||||
#include "trpc.h"
|
||||
#include "tscLog.h"
|
||||
|
||||
int (*buildRequestMsgFp[TSDB_SQL_MAX])(SRequestObj *pRequest, SRequestMsgBody *pMsgBody) = {0};
|
||||
int (*handleRequestRspFp[TSDB_SQL_MAX])(SRequestObj *pRequest, const char* pMsg, int32_t msgLen);
|
||||
|
@ -528,7 +530,7 @@ int doBuildAndSendMsg(SSqlObj *pSql) {
|
|||
|
||||
if (pCmd->command == TSDB_SQL_SELECT ||
|
||||
pCmd->command == TSDB_SQL_FETCH ||
|
||||
pCmd->command == TSDB_SQL_RETRIEVE ||
|
||||
pCmd->command == TSDB_SQL_RETRIEVE_MNODE ||
|
||||
pCmd->command == TSDB_SQL_INSERT ||
|
||||
pCmd->command == TSDB_SQL_CONNECT ||
|
||||
pCmd->command == TSDB_SQL_HB ||
|
||||
|
@ -2699,7 +2701,7 @@ int tscProcessRetrieveRspFromNode(SSqlObj *pSql) {
|
|||
}
|
||||
|
||||
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
if ((pCmd->command == TSDB_SQL_RETRIEVE) ||
|
||||
if ((pCmd->command == TSDB_SQL_RETRIEVE_MNODE) ||
|
||||
((UTIL_TABLE_IS_CHILD_TABLE(pTableMetaInfo) || UTIL_TABLE_IS_NORMAL_TABLE(pTableMetaInfo)) &&
|
||||
!TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_SUBQUERY)) ||
|
||||
(tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0) &&
|
||||
|
@ -2884,7 +2886,7 @@ int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVg
|
|||
}
|
||||
|
||||
int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool autocreate, bool onlyLocal) {
|
||||
assert(tIsValidName(&pTableMetaInfo->name));
|
||||
assert(tNameIsValid(&pTableMetaInfo->name));
|
||||
|
||||
char name[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
tNameExtractFullName(&pTableMetaInfo->name, name);
|
||||
|
@ -3091,6 +3093,36 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, SQueryInfo* pQueryInfo) {
|
|||
|
||||
#endif
|
||||
|
||||
int32_t buildConnectMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) {
|
||||
pMsgBody->msgType = TSDB_MSG_TYPE_CONNECT;
|
||||
pMsgBody->msgLen = sizeof(SConnectMsg);
|
||||
pMsgBody->requestObjRefId = pRequest->self;
|
||||
|
||||
SConnectMsg *pConnect = calloc(1, sizeof(SConnectMsg));
|
||||
if (pConnect == NULL) {
|
||||
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// TODO refactor full_name
|
||||
char *db; // ugly code to move the space
|
||||
|
||||
STscObj *pObj = pRequest->pTscObj;
|
||||
pthread_mutex_lock(&pObj->mutex);
|
||||
db = strstr(pObj->db, TS_PATH_DELIMITER);
|
||||
|
||||
db = (db == NULL) ? pObj->db : db + 1;
|
||||
tstrncpy(pConnect->db, db, sizeof(pConnect->db));
|
||||
pthread_mutex_unlock(&pObj->mutex);
|
||||
|
||||
pConnect->pid = htonl(appInfo.pid);
|
||||
pConnect->startTime = htobe64(appInfo.startTime);
|
||||
tstrncpy(pConnect->app, appInfo.appName, tListLen(pConnect->app));
|
||||
|
||||
pMsgBody->pData = pConnect;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int processConnectRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) {
|
||||
STscObj *pTscObj = pRequest->pTscObj;
|
||||
|
||||
|
@ -3099,38 +3131,178 @@ int processConnectRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) {
|
|||
pConnect->connId = htonl(pConnect->connId);
|
||||
pConnect->clusterId = htonl(pConnect->clusterId);
|
||||
|
||||
assert(pConnect->epSet.numOfEps > 0);
|
||||
for(int32_t i = 0; i < pConnect->epSet.numOfEps; ++i) {
|
||||
pConnect->epSet.port[i] = htons(pConnect->epSet.port[i]);
|
||||
}
|
||||
|
||||
// TODO refactor
|
||||
pthread_mutex_lock(&pTscObj->mutex);
|
||||
char temp[TSDB_TABLE_FNAME_LEN * 2] = {0};
|
||||
int32_t len = sprintf(temp, "%s%s%s", pTscObj->acctId, TS_PATH_DELIMITER, pTscObj->db);
|
||||
int32_t len = sprintf(temp, "%d%s%s", pTscObj->acctId, TS_PATH_DELIMITER, pTscObj->db);
|
||||
|
||||
assert(len <= sizeof(pTscObj->db));
|
||||
tstrncpy(pTscObj->db, temp, sizeof(pTscObj->db));
|
||||
pthread_mutex_unlock(&pTscObj->mutex);
|
||||
|
||||
assert(pConnect->epSet.numOfEps > 0);
|
||||
if (!isEpsetEqual(&pTscObj->pAppInfo->mgmtEp.epSet, &pConnect->epSet)) {
|
||||
updateEpSet_s(&pTscObj->pAppInfo->mgmtEp, &pConnect->epSet);
|
||||
}
|
||||
|
||||
for (int i = 0; i < pConnect->epSet.numOfEps; ++i) {
|
||||
tscDebug("0x%" PRIx64 " epSet.fqdn[%d]: %s, connObj:0x%"PRIx64, pRequest->requestId, i, pConnect->epSet.fqdn[i], pTscObj->id);
|
||||
tscDebug("0x%" PRIx64 " epSet.fqdn[%d]:%s port:%d, connObj:0x%"PRIx64, pRequest->requestId, i, pConnect->epSet.fqdn[i], pConnect->epSet.port[i], pTscObj->id);
|
||||
}
|
||||
|
||||
pTscObj->connId = pConnect->connId;
|
||||
pTscObj->acctId = pConnect->acctId;
|
||||
|
||||
// update the appInstInfo
|
||||
pTscObj->pAppInfo->clusterId = pConnect->clusterId;
|
||||
atomic_add_fetch_64(&pTscObj->pAppInfo->numOfConns, 1);
|
||||
|
||||
tscDebug("0x%" PRIx64 " clusterId:%d, totalConn:%"PRId64, pRequest->requestId, pConnect->clusterId, pTscObj->pAppInfo->numOfConns);
|
||||
// createHbObj(pTscObj);
|
||||
pRequest->body.pResInfo = calloc(1, sizeof(SClientResultInfo));
|
||||
pRequest->body.pResInfo->pMsg = pMsg;
|
||||
|
||||
// launch a timer to send heartbeat to maintain the connection and send status to mnode
|
||||
// taosTmrReset(tscProcessActivityTimer, tsShellActivityTimer * 500, (void *)pTscObj->rid, tscTmr, &pTscObj->pTimer);
|
||||
tscDebug("0x%" PRIx64 " clusterId:%d, totalConn:%"PRId64, pRequest->requestId, pConnect->clusterId, pTscObj->pAppInfo->numOfConns);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t doBuildMsgSupp(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) {
|
||||
pMsgBody->requestObjRefId = pRequest->self;
|
||||
pMsgBody->msgLen = pRequest->body.paramLen;
|
||||
pMsgBody->pData = pRequest->body.param;
|
||||
|
||||
switch(pRequest->type) {
|
||||
case TSDB_SQL_CREATE_USER:
|
||||
pMsgBody->msgType = TSDB_MSG_TYPE_CREATE_USER;
|
||||
break;
|
||||
case TSDB_SQL_CREATE_DB: {
|
||||
pMsgBody->msgType = TSDB_MSG_TYPE_CREATE_DB;
|
||||
|
||||
SCreateDbMsg* pCreateMsg = pRequest->body.param;
|
||||
SName name = {0};
|
||||
int32_t ret = tNameSetDbName(&name, pRequest->pTscObj->acctId, pCreateMsg->db, strnlen(pCreateMsg->db, tListLen(pCreateMsg->db)));
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tNameGetFullDbName(&name, pCreateMsg->db);
|
||||
|
||||
break;
|
||||
}
|
||||
case TSDB_SQL_SHOW:
|
||||
pMsgBody->msgType = TSDB_MSG_TYPE_SHOW;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
STableMeta* createTableMetaFromMsg(STableMetaMsg* pTableMetaMsg) {
|
||||
assert(pTableMetaMsg != NULL && pTableMetaMsg->numOfColumns >= 2);
|
||||
|
||||
size_t schemaSize = (pTableMetaMsg->numOfColumns + pTableMetaMsg->numOfTags) * sizeof(SSchema);
|
||||
STableMeta* pTableMeta = calloc(1, sizeof(STableMeta) + schemaSize);
|
||||
|
||||
pTableMeta->tableType = pTableMetaMsg->tableType;
|
||||
pTableMeta->vgId = pTableMetaMsg->vgId;
|
||||
pTableMeta->suid = pTableMetaMsg->suid;
|
||||
pTableMeta->uid = pTableMetaMsg->tuid;
|
||||
|
||||
pTableMeta->tableInfo = (STableComInfo) {
|
||||
.numOfTags = pTableMetaMsg->numOfTags,
|
||||
.precision = pTableMetaMsg->precision,
|
||||
.numOfColumns = pTableMetaMsg->numOfColumns,
|
||||
};
|
||||
|
||||
pTableMeta->sversion = pTableMetaMsg->sversion;
|
||||
pTableMeta->tversion = pTableMetaMsg->tversion;
|
||||
|
||||
memcpy(pTableMeta->schema, pTableMetaMsg->pSchema, schemaSize);
|
||||
|
||||
int32_t numOfTotalCols = pTableMeta->tableInfo.numOfColumns;
|
||||
for(int32_t i = 0; i < numOfTotalCols; ++i) {
|
||||
pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
|
||||
}
|
||||
|
||||
return pTableMeta;
|
||||
}
|
||||
|
||||
int32_t processShowRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) {
|
||||
SShowRsp* pShow = (SShowRsp *)pMsg;
|
||||
pShow->showId = htonl(pShow->showId);
|
||||
|
||||
STableMetaMsg *pMetaMsg = &(pShow->tableMeta);
|
||||
pMetaMsg->numOfColumns = htonl(pMetaMsg->numOfColumns);
|
||||
|
||||
SSchema* pSchema = pMetaMsg->pSchema;
|
||||
pMetaMsg->tuid = htobe64(pMetaMsg->tuid);
|
||||
for (int i = 0; i < pMetaMsg->numOfColumns; ++i) {
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
pSchema++;
|
||||
}
|
||||
|
||||
pSchema = pMetaMsg->pSchema;
|
||||
TAOS_FIELD* pFields = calloc(pMetaMsg->numOfColumns, sizeof(TAOS_FIELD));
|
||||
for (int32_t i = 0; i < pMetaMsg->numOfColumns; ++i) {
|
||||
tstrncpy(pFields[i].name, pSchema[i].name, tListLen(pFields[i].name));
|
||||
pFields[i].type = pSchema[i].type;
|
||||
pFields[i].bytes = pSchema[i].bytes;
|
||||
}
|
||||
|
||||
if (pRequest->body.pResInfo == NULL) {
|
||||
pRequest->body.pResInfo = calloc(1, sizeof(SClientResultInfo));
|
||||
}
|
||||
|
||||
pRequest->body.pResInfo->pMsg = pMsg;
|
||||
SClientResultInfo* pResInfo = pRequest->body.pResInfo;
|
||||
|
||||
pResInfo->fields = pFields;
|
||||
pResInfo->numOfCols = pMetaMsg->numOfColumns;
|
||||
pResInfo->row = calloc(pResInfo->numOfCols, POINTER_BYTES);
|
||||
pResInfo->pCol = calloc(pResInfo->numOfCols, POINTER_BYTES);
|
||||
pResInfo->length = calloc(pResInfo->numOfCols, sizeof(int32_t));
|
||||
|
||||
pRequest->body.execId = pShow->showId;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int buildRetrieveMnodeMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) {
|
||||
pMsgBody->msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
|
||||
pMsgBody->msgLen = sizeof(SRetrieveTableMsg);
|
||||
pMsgBody->requestObjRefId = pRequest->self;
|
||||
|
||||
SRetrieveTableMsg *pRetrieveMsg = calloc(1, sizeof(SRetrieveTableMsg));
|
||||
pRetrieveMsg->showId = htonl(pRequest->body.execId);
|
||||
|
||||
pMsgBody->pData = pRetrieveMsg;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t processRetrieveMnodeRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) {
|
||||
assert(msgLen >= sizeof(SRetrieveTableRsp));
|
||||
|
||||
tfree(pRequest->body.pResInfo->pMsg);
|
||||
pRequest->body.pResInfo->pMsg = pMsg;
|
||||
|
||||
SRetrieveTableRsp *pRetrieve = (SRetrieveTableRsp *) pMsg;
|
||||
pRetrieve->numOfRows = htonl(pRetrieve->numOfRows);
|
||||
pRetrieve->precision = htons(pRetrieve->precision);
|
||||
|
||||
SClientResultInfo* pResInfo = pRequest->body.pResInfo;
|
||||
pResInfo->numOfRows = pRetrieve->numOfRows;
|
||||
pResInfo->pData = pRetrieve->data; // todo fix this in async model
|
||||
|
||||
pResInfo->current = 0;
|
||||
setResultDataPtr(pResInfo, pResInfo->fields, pResInfo->numOfCols, pResInfo->numOfRows);
|
||||
|
||||
tscDebug("0x%"PRIx64" numOfRows:%d, complete:%d, qId:0x%"PRIx64, pRequest->self, pRetrieve->numOfRows,
|
||||
pRetrieve->completed, pRequest->body.execId);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t processCreateDbRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) {
|
||||
// todo rsp with the vnode id list
|
||||
}
|
||||
|
||||
void initMsgHandleFp() {
|
||||
#if 0
|
||||
tscBuildMsg[TSDB_SQL_SELECT] = tscBuildQueryMsg;
|
||||
|
@ -3167,7 +3339,7 @@ void initMsgHandleFp() {
|
|||
|
||||
tscBuildMsg[TSDB_SQL_HB] = tscBuildHeartBeatMsg;
|
||||
tscBuildMsg[TSDB_SQL_SHOW] = tscBuildShowMsg;
|
||||
tscBuildMsg[TSDB_SQL_RETRIEVE] = tscBuildRetrieveFromMgmtMsg;
|
||||
tscBuildMsg[TSDB_SQL_RETRIEVE_MNODE] = tscBuildRetrieveFromMgmtMsg;
|
||||
tscBuildMsg[TSDB_SQL_KILL_QUERY] = tscBuildKillMsg;
|
||||
tscBuildMsg[TSDB_SQL_KILL_STREAM] = tscBuildKillMsg;
|
||||
tscBuildMsg[TSDB_SQL_KILL_CONNECTION] = tscBuildKillMsg;
|
||||
|
@ -3185,7 +3357,7 @@ void initMsgHandleFp() {
|
|||
tscProcessMsgRsp[TSDB_SQL_RETRIEVE_FUNC] = tscProcessRetrieveFuncRsp;
|
||||
|
||||
tscProcessMsgRsp[TSDB_SQL_SHOW] = tscProcessShowRsp;
|
||||
tscProcessMsgRsp[TSDB_SQL_RETRIEVE] = tscProcessRetrieveRspFromNode; // rsp handled by same function.
|
||||
tscProcessMsgRsp[TSDB_SQL_RETRIEVE_MNODE] = tscProcessRetrieveRspFromNode; // rsp handled by same function.
|
||||
tscProcessMsgRsp[TSDB_SQL_DESCRIBE_TABLE] = tscProcessDescribeTableRsp;
|
||||
|
||||
tscProcessMsgRsp[TSDB_SQL_CURRENT_DB] = tscProcessLocalRetrieveRsp;
|
||||
|
@ -3207,6 +3379,17 @@ void initMsgHandleFp() {
|
|||
tscProcessMsgRsp[TSDB_SQL_SHOW_CREATE_DATABASE] = tscProcessShowCreateRsp;
|
||||
#endif
|
||||
|
||||
// buildRequestMsgFp[TSDB_SQL_CONNECT] = tscBuildConnectMsg;
|
||||
buildRequestMsgFp[TSDB_SQL_CONNECT] = buildConnectMsg;
|
||||
handleRequestRspFp[TSDB_SQL_CONNECT] = processConnectRsp;
|
||||
|
||||
buildRequestMsgFp[TSDB_SQL_CREATE_USER] = doBuildMsgSupp;
|
||||
|
||||
buildRequestMsgFp[TSDB_SQL_SHOW] = doBuildMsgSupp;
|
||||
handleRequestRspFp[TSDB_SQL_SHOW] = processShowRsp;
|
||||
|
||||
buildRequestMsgFp[TSDB_SQL_RETRIEVE_MNODE] = buildRetrieveMnodeMsg;
|
||||
handleRequestRspFp[TSDB_SQL_RETRIEVE_MNODE]= processRetrieveMnodeRsp;
|
||||
|
||||
buildRequestMsgFp[TSDB_SQL_CREATE_DB] = doBuildMsgSupp;
|
||||
handleRequestRspFp[TSDB_SQL_CREATE_DB] = processCreateDbRsp;
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
#include "clientInt.h"
|
||||
#include "trpc.h"
|
||||
#include "os.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tcache.h"
|
||||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "tnote.h"
|
||||
#include "tref.h"
|
||||
#include "tscLog.h"
|
||||
#include "tsched.h"
|
||||
#include "ttime.h"
|
||||
#include "ttimezone.h"
|
||||
|
||||
#define TSC_VAR_NOT_RELEASE 1
|
||||
#define TSC_VAR_RELEASED 0
|
||||
|
||||
static int32_t sentinel = TSC_VAR_NOT_RELEASE;
|
||||
static pthread_once_t tscinit = PTHREAD_ONCE_INIT;
|
||||
|
||||
extern int32_t tscInitRes;
|
||||
|
||||
int taos_options(TSDB_OPTION option, const void *arg, ...) {
|
||||
static int32_t lock = 0;
|
||||
|
||||
for (int i = 1; atomic_val_compare_exchange_32(&lock, 0, 1) != 0; ++i) {
|
||||
if (i % 1000 == 0) {
|
||||
tscInfo("haven't acquire lock after spin %d times.", i);
|
||||
sched_yield();
|
||||
}
|
||||
}
|
||||
|
||||
int ret = taos_options_imp(option, (const char*)arg);
|
||||
|
||||
atomic_store_32(&lock, 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int taos_init() {
|
||||
pthread_once(&tscinit, taos_init_imp);
|
||||
return tscInitRes;
|
||||
}
|
||||
|
||||
// this function may be called by user or system, or by both simultaneously.
|
||||
void taos_cleanup(void) {
|
||||
tscDebug("start to cleanup client environment");
|
||||
|
||||
if (atomic_val_compare_exchange_32(&sentinel, TSC_VAR_NOT_RELEASE, TSC_VAR_RELEASED) != TSC_VAR_NOT_RELEASE) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t id = tscReqRef;
|
||||
tscReqRef = -1;
|
||||
taosCloseRef(id);
|
||||
|
||||
void* p = tscQhandle;
|
||||
tscQhandle = NULL;
|
||||
taosCleanUpScheduler(p);
|
||||
|
||||
id = tscConnRef;
|
||||
tscConnRef = -1;
|
||||
taosCloseRef(id);
|
||||
|
||||
rpcCleanup();
|
||||
taosCloseLog();
|
||||
}
|
||||
|
||||
void taos_close(TAOS* taos) {
|
||||
if (taos == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
STscObj *pTscObj = (STscObj *)taos;
|
||||
tscDebug("0x%"PRIx64" try to close connection, numOfReq:%d", pTscObj->id, pTscObj->numOfReqs);
|
||||
|
||||
taosRemoveRef(tscConnRef, pTscObj->id);
|
||||
}
|
||||
|
||||
const char *taos_errstr(TAOS_RES *res) {
|
||||
|
||||
}
|
||||
|
||||
void taos_free_result(TAOS_RES *res) {
|
||||
|
||||
}
|
|
@ -13,6 +13,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "clientInt.h"
|
||||
#include "clientLog.h"
|
||||
#include "os.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tcache.h"
|
||||
|
@ -20,12 +22,10 @@
|
|||
#include "tglobal.h"
|
||||
#include "tnote.h"
|
||||
#include "tref.h"
|
||||
#include "tscLog.h"
|
||||
#include "trpc.h"
|
||||
#include "tsched.h"
|
||||
#include "ttime.h"
|
||||
#include "trpc.h"
|
||||
#include "ttimezone.h"
|
||||
#include "clientInt.h"
|
||||
|
||||
#define TSC_VAR_NOT_RELEASE 1
|
||||
#define TSC_VAR_RELEASED 0
|
||||
|
@ -35,6 +35,7 @@ int32_t tscReqRef = -1;
|
|||
int32_t tscConnRef = -1;
|
||||
void *tscQhandle = NULL;
|
||||
|
||||
static pthread_once_t tscinit = PTHREAD_ONCE_INIT;
|
||||
int32_t tsNumOfThreads = 1;
|
||||
volatile int32_t tscInitRes = 0;
|
||||
|
||||
|
@ -64,7 +65,7 @@ static void deregisterRequest(SRequestObj* pRequest) {
|
|||
SInstanceActivity* pActivity = &pTscObj->pAppInfo->summary;
|
||||
|
||||
int32_t currentInst = atomic_sub_fetch_32(&pActivity->currentRequests, 1);
|
||||
int32_t num = atomic_sub_fetch_32(&pTscObj->numOfReqs, 1);
|
||||
int32_t num = atomic_sub_fetch_32(&pTscObj->numOfReqs, 1);
|
||||
|
||||
tscDebug("0x%"PRIx64" free Request from connObj: 0x%"PRIx64", current:%d, app current:%d", pRequest->self, pTscObj->id, num, currentInst);
|
||||
taosReleaseRef(tscConnRef, pTscObj->id);
|
||||
|
@ -126,8 +127,6 @@ void destroyTscObj(void *pObj) {
|
|||
|
||||
atomic_sub_fetch_64(&pTscObj->pAppInfo->numOfConns, 1);
|
||||
tscDebug("connObj 0x%"PRIx64" destroyed, totalConn:%"PRId64, pTscObj->id, pTscObj->pAppInfo->numOfConns);
|
||||
|
||||
closeTransporter(pTscObj);
|
||||
pthread_mutex_destroy(&pTscObj->mutex);
|
||||
tfree(pTscObj);
|
||||
}
|
||||
|
@ -172,6 +171,7 @@ void* createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t ty
|
|||
pRequest->pTscObj = pObj;
|
||||
pRequest->body.fp = fp;
|
||||
pRequest->body.param = param;
|
||||
pRequest->msgBuf = calloc(1, ERROR_MSG_BUF_DEFAULT_SIZE);
|
||||
tsem_init(&pRequest->body.rspSem, 0, 0);
|
||||
|
||||
registerRequest(pRequest);
|
||||
|
@ -188,6 +188,12 @@ static void doDestroyRequest(void* p) {
|
|||
tfree(pRequest->sqlstr);
|
||||
tfree(pRequest->pInfo);
|
||||
|
||||
if (pRequest->body.pResInfo != NULL) {
|
||||
tfree(pRequest->body.pResInfo->pData);
|
||||
tfree(pRequest->body.pResInfo->pMsg);
|
||||
tfree(pRequest->body.pResInfo);
|
||||
}
|
||||
|
||||
deregisterRequest(pRequest);
|
||||
tfree(pRequest);
|
||||
}
|
||||
|
@ -250,6 +256,11 @@ void taos_init_imp(void) {
|
|||
tscDebug("client is initialized successfully");
|
||||
}
|
||||
|
||||
int taos_init() {
|
||||
pthread_once(&tscinit, taos_init_imp);
|
||||
return tscInitRes;
|
||||
}
|
||||
|
||||
int taos_options_imp(TSDB_OPTION option, const char *str) {
|
||||
SGlobalCfg *cfg = NULL;
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <taoserror.h>
|
||||
#include <iostream>
|
||||
#include "tglobal.h"
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
|
@ -22,6 +23,7 @@
|
|||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
|
||||
#include "../inc/clientInt.h"
|
||||
#include "taos.h"
|
||||
|
||||
namespace {
|
||||
|
@ -33,8 +35,90 @@ int main(int argc, char** argv) {
|
|||
}
|
||||
|
||||
TEST(testCase, driverInit_Test) {
|
||||
taos_init();
|
||||
}
|
||||
|
||||
TEST(testCase, connect_Test) {
|
||||
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, create_user_Test) {
|
||||
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "create user abc pass 'abc'");
|
||||
if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
||||
printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
}
|
||||
|
||||
//TEST(testCase, drop_user_Test) {
|
||||
// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "drop user abc");
|
||||
// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
||||
// printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
//
|
||||
// taos_free_result(pRes);
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
|
||||
TEST(testCase, show_user_Test) {
|
||||
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "show users");
|
||||
TAOS_ROW pRow = NULL;
|
||||
|
||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
|
||||
char str[512] = {0};
|
||||
while((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
printf("%s\n", str);
|
||||
}
|
||||
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, show_db_Test) {
|
||||
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "show databases");
|
||||
TAOS_ROW pRow = NULL;
|
||||
|
||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
|
||||
char str[512] = {0};
|
||||
while((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
printf("%s\n", str);
|
||||
}
|
||||
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, create_db_Test) {
|
||||
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "create database abc");
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -4,9 +4,6 @@
|
|||
#include "tname.h"
|
||||
#include "taosmsg.h"
|
||||
|
||||
#define VALIDNUMOFCOLS(x) ((x) >= TSDB_MIN_COLUMNS && (x) <= TSDB_MAX_COLUMNS)
|
||||
#define VALIDNUMOFTAGS(x) ((x) >= 0 && (x) <= TSDB_MAX_TAGS)
|
||||
|
||||
#define VALID_NAME_TYPE(x) ((x) == TSDB_DB_NAME_T || (x) == TSDB_TABLE_NAME_T)
|
||||
|
||||
char* extractDBName(const char* tableId, char* name) {
|
||||
|
@ -120,84 +117,11 @@ int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, in
|
|||
|
||||
#endif
|
||||
|
||||
static struct SSchema _s = {
|
||||
.colId = TSDB_TBNAME_COLUMN_INDEX,
|
||||
.type = TSDB_DATA_TYPE_BINARY,
|
||||
.bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE,
|
||||
.name = "tbname",
|
||||
};
|
||||
|
||||
SSchema* tGetTbnameColumnSchema() {
|
||||
return &_s;
|
||||
}
|
||||
|
||||
static bool doValidateSchema(SSchema* pSchema, int32_t numOfCols, int32_t maxLen) {
|
||||
int32_t rowLen = 0;
|
||||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
// 1. valid types
|
||||
if (!isValidDataType(pSchema[i].type)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. valid length for each type
|
||||
if (pSchema[i].type == TSDB_DATA_TYPE_BINARY) {
|
||||
if (pSchema[i].bytes > TSDB_MAX_BINARY_LEN) {
|
||||
return false;
|
||||
}
|
||||
} else if (pSchema[i].type == TSDB_DATA_TYPE_NCHAR) {
|
||||
if (pSchema[i].bytes > TSDB_MAX_NCHAR_LEN) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (pSchema[i].bytes != tDataTypes[pSchema[i].type].bytes) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. valid column names
|
||||
for (int32_t j = i + 1; j < numOfCols; ++j) {
|
||||
if (strncasecmp(pSchema[i].name, pSchema[j].name, sizeof(pSchema[i].name) - 1) == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
rowLen += pSchema[i].bytes;
|
||||
}
|
||||
|
||||
return rowLen <= maxLen;
|
||||
}
|
||||
|
||||
bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags) {
|
||||
if (!VALIDNUMOFCOLS(numOfCols)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!VALIDNUMOFTAGS(numOfTags)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* first column must be the timestamp, which is a primary key */
|
||||
if (pSchema[0].type != TSDB_DATA_TYPE_TIMESTAMP) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!doValidateSchema(pSchema, numOfCols, TSDB_MAX_BYTES_PER_ROW)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!doValidateSchema(&pSchema[numOfCols], numOfTags, TSDB_MAX_TAGS_LEN)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t tNameExtractFullName(const SName* name, char* dst) {
|
||||
assert(name != NULL && dst != NULL);
|
||||
|
||||
// invalid full name format, abort
|
||||
if (!tIsValidName(name)) {
|
||||
if (!tNameIsValid(name)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -230,7 +154,7 @@ int32_t tNameLen(const SName* name) {
|
|||
}
|
||||
}
|
||||
|
||||
bool tIsValidName(const SName* name) {
|
||||
bool tNameIsValid(const SName* name) {
|
||||
assert(name != NULL);
|
||||
|
||||
if (!VALID_NAME_TYPE(name->type)) {
|
||||
|
@ -265,13 +189,13 @@ int32_t tNameGetDbName(const SName* name, char* dst) {
|
|||
int32_t tNameGetFullDbName(const SName* name, char* dst) {
|
||||
assert(name != NULL && dst != NULL);
|
||||
snprintf(dst, TSDB_ACCT_ID_LEN + TS_PATH_DELIMITER_LEN + TSDB_DB_NAME_LEN, // there is a over write risk
|
||||
"%s.%s", name->acctId, name->dbname);
|
||||
"%d.%s", name->acctId, name->dbname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool tNameIsEmpty(const SName* name) {
|
||||
assert(name != NULL);
|
||||
return name->type == 0 || strlen(name->acctId) <= 0;
|
||||
return name->type == 0 || name->acctId == 0;
|
||||
}
|
||||
|
||||
const char* tNameGetTableName(const SName* name) {
|
||||
|
@ -283,32 +207,23 @@ void tNameAssign(SName* dst, const SName* src) {
|
|||
memcpy(dst, src, sizeof(SName));
|
||||
}
|
||||
|
||||
//int32_t tNameSetDbName(SName* dst, const char* acct, SStrToken* dbToken) {
|
||||
// assert(dst != NULL && dbToken != NULL && acct != NULL);
|
||||
//
|
||||
// // too long account id or too long db name
|
||||
// if (strlen(acct) >= tListLen(dst->acctId) || dbToken->n >= tListLen(dst->dbname)) {
|
||||
// return -1;
|
||||
// }
|
||||
//
|
||||
// dst->type = TSDB_DB_NAME_T;
|
||||
// tstrncpy(dst->acctId, acct, tListLen(dst->acctId));
|
||||
// tstrncpy(dst->dbname, dbToken->z, dbToken->n + 1);
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
int32_t tNameSetAcctId(SName* dst, const char* acct) {
|
||||
assert(dst != NULL && acct != NULL);
|
||||
int32_t tNameSetDbName(SName* dst, int32_t acct, const char* dbName, size_t nameLen) {
|
||||
assert(dst != NULL && dbName != NULL && nameLen > 0);
|
||||
|
||||
// too long account id or too long db name
|
||||
if (strlen(acct) >= tListLen(dst->acctId)) {
|
||||
if (nameLen >= tListLen(dst->dbname)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tstrncpy(dst->acctId, acct, tListLen(dst->acctId));
|
||||
dst->type = TSDB_DB_NAME_T;
|
||||
dst->acctId = acct;
|
||||
tstrncpy(dst->dbname, dbName, nameLen + 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
assert(strlen(dst->acctId) > 0);
|
||||
|
||||
int32_t tNameSetAcctId(SName* dst, int32_t acctId) {
|
||||
assert(dst != NULL && acct != NULL);
|
||||
dst->acctId = acctId;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -325,14 +240,11 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type) {
|
|||
int32_t len = (int32_t)(p - str);
|
||||
|
||||
// too long account id or too long db name
|
||||
if ((len >= tListLen(dst->acctId)) || (len <= 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy (dst->acctId, str, len);
|
||||
dst->acctId[len] = 0;
|
||||
|
||||
assert(strlen(dst->acctId) > 0);
|
||||
// if ((len >= tListLen(dst->acctId)) || (len <= 0)) {
|
||||
// return -1;
|
||||
// }
|
||||
// memcpy (dst->acctId, str, len);
|
||||
dst->acctId = strtoll(str, NULL, 10);
|
||||
}
|
||||
|
||||
if ((type & T_NAME_DB) == T_NAME_DB) {
|
||||
|
|
|
@ -92,6 +92,7 @@ void dmnPrintVersion() {
|
|||
}
|
||||
|
||||
int dmnReadConfig(const char *path) {
|
||||
tstrncpy(configDir, global.configDir, PATH_MAX);
|
||||
taosInitGlobalCfg();
|
||||
taosReadGlobalLogCfg();
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
|
|||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_TABLE] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_TABLE] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_UPDATE_TAG_VAL] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_TABLE_META] = dndProcessVnodeQueryMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_TABLE_META] = dndProcessMnodeReadMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_TABLES_META] = dndProcessVnodeQueryMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_MQ_QUERY] = dndProcessVnodeQueryMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_MQ_CONSUME] = dndProcessVnodeQueryMsg;
|
||||
|
|
|
@ -95,7 +95,7 @@ static int32_t dndProcessCompactVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg);
|
|||
|
||||
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);
|
||||
|
@ -107,23 +107,23 @@ static SVnodeObj *dndAcquireVnode(SDnode *pDnode, int32_t vgId) {
|
|||
}
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
||||
dTrace("vgId:%d, acquire vnode, refCount:%d", pVnode->vgId, refCount);
|
||||
if (pVnode != NULL) {
|
||||
dTrace("vgId:%d, acquire vnode, refCount:%d", pVnode->vgId, refCount);
|
||||
}
|
||||
|
||||
return pVnode;
|
||||
}
|
||||
|
||||
static void dndReleaseVnode(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
if (pVnode == NULL) return;
|
||||
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
int32_t refCount = 0;
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
if (pVnode != NULL) {
|
||||
refCount = atomic_sub_fetch_32(&pVnode->refCount, 1);
|
||||
}
|
||||
int32_t refCount = atomic_sub_fetch_32(&pVnode->refCount, 1);
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
||||
if (pVnode != NULL) {
|
||||
dTrace("vgId:%d, release vnode, refCount:%d", pVnode->vgId, refCount);
|
||||
}
|
||||
dTrace("vgId:%d, release vnode, refCount:%d", pVnode->vgId, refCount);
|
||||
}
|
||||
|
||||
static int32_t dndCreateVnodeWrapper(SDnode *pDnode, int32_t vgId, char *path, SVnode *pImpl) {
|
||||
|
@ -457,7 +457,7 @@ static int32_t dndOpenVnodes(SDnode *pDnode) {
|
|||
|
||||
pMgmt->totalVnodes = numOfVnodes;
|
||||
|
||||
int32_t threadNum = tsNumOfCores;
|
||||
int32_t threadNum = pDnode->opt.numOfCores;
|
||||
int32_t vnodesPerThread = numOfVnodes / threadNum + 1;
|
||||
|
||||
SVnodeThread *threads = calloc(threadNum, sizeof(SVnodeThread));
|
||||
|
@ -525,33 +525,49 @@ static void dndCloseVnodes(SDnode *pDnode) {
|
|||
|
||||
static int32_t dndParseCreateVnodeReq(SRpcMsg *rpcMsg, int32_t *vgId, SVnodeCfg *pCfg) {
|
||||
SCreateVnodeMsg *pCreate = rpcMsg->pCont;
|
||||
*vgId = htonl(pCreate->vgId);
|
||||
pCreate->vgId = htonl(pCreate->vgId);
|
||||
pCreate->dnodeId = htonl(pCreate->dnodeId);
|
||||
pCreate->dbUid = htobe64(pCreate->dbUid);
|
||||
pCreate->cacheBlockSize = htonl(pCreate->cacheBlockSize);
|
||||
pCreate->totalBlocks = htonl(pCreate->totalBlocks);
|
||||
pCreate->daysPerFile = htonl(pCreate->daysPerFile);
|
||||
pCreate->daysToKeep0 = htonl(pCreate->daysToKeep0);
|
||||
pCreate->daysToKeep1 = htonl(pCreate->daysToKeep1);
|
||||
pCreate->daysToKeep2 = htonl(pCreate->daysToKeep2);
|
||||
pCreate->minRows = htonl(pCreate->minRows);
|
||||
pCreate->maxRows = htonl(pCreate->maxRows);
|
||||
pCreate->commitTime = htonl(pCreate->commitTime);
|
||||
pCreate->fsyncPeriod = htonl(pCreate->fsyncPeriod);
|
||||
for (int r = 0; r < pCreate->replica; ++r) {
|
||||
SReplica *pReplica = &pCreate->replicas[r];
|
||||
pReplica->id = htonl(pReplica->id);
|
||||
pReplica->port = htons(pReplica->port);
|
||||
}
|
||||
|
||||
*vgId = pCreate->vgId;
|
||||
|
||||
#if 0
|
||||
tstrncpy(pCfg->db, pCreate->db, TSDB_FULL_DB_NAME_LEN);
|
||||
pCfg->cacheBlockSize = htonl(pCreate->cacheBlockSize);
|
||||
pCfg->totalBlocks = htonl(pCreate->totalBlocks);
|
||||
pCfg->daysPerFile = htonl(pCreate->daysPerFile);
|
||||
pCfg->daysToKeep0 = htonl(pCreate->daysToKeep0);
|
||||
pCfg->daysToKeep1 = htonl(pCreate->daysToKeep1);
|
||||
pCfg->daysToKeep2 = htonl(pCreate->daysToKeep2);
|
||||
pCfg->minRowsPerFileBlock = htonl(pCreate->minRowsPerFileBlock);
|
||||
pCfg->maxRowsPerFileBlock = htonl(pCreate->maxRowsPerFileBlock);
|
||||
pCfg->precision = pCreate->precision;
|
||||
pCfg->compression = pCreate->compression;
|
||||
pCfg->cacheLastRow = pCreate->cacheLastRow;
|
||||
pCfg->update = pCreate->update;
|
||||
pCfg->quorum = pCreate->quorum;
|
||||
pCfg->replica = pCreate->replica;
|
||||
pCfg->walLevel = pCreate->walLevel;
|
||||
pCfg->fsyncPeriod = htonl(pCreate->fsyncPeriod);
|
||||
|
||||
for (int32_t i = 0; i < pCfg->replica; ++i) {
|
||||
pCfg->replicas[i].port = htons(pCreate->replicas[i].port);
|
||||
tstrncpy(pCfg->replicas[i].fqdn, pCreate->replicas[i].fqdn, TSDB_FQDN_LEN);
|
||||
}
|
||||
pCfg->wsize = pCreate->cacheBlockSize;
|
||||
pCfg->ssize = pCreate->cacheBlockSize;
|
||||
pCfg->wsize = pCreate->cacheBlockSize;
|
||||
pCfg->lsize = pCreate->cacheBlockSize;
|
||||
pCfg->isHeapAllocator = true;
|
||||
pCfg->ttl = 4;
|
||||
pCfg->keep = pCreate->daysToKeep0;
|
||||
pCfg->isWeak = true;
|
||||
pCfg->tsdbCfg.keep0 = pCreate->daysToKeep0;
|
||||
pCfg->tsdbCfg.keep1 = pCreate->daysToKeep2;
|
||||
pCfg->tsdbCfg.keep2 = pCreate->daysToKeep0;
|
||||
pCfg->tsdbCfg.lruCacheSize = pCreate->cacheBlockSize;
|
||||
pCfg->metaCfg.lruSize = pCreate->cacheBlockSize;
|
||||
pCfg->walCfg.fsyncPeriod = pCreate->fsyncPeriod;
|
||||
pCfg->walCfg.level = pCreate->walLevel;
|
||||
pCfg->walCfg.retentionPeriod = 10;
|
||||
pCfg->walCfg.retentionSize = 128;
|
||||
pCfg->walCfg.rollPeriod = 128;
|
||||
pCfg->walCfg.segSize = 128;
|
||||
pCfg->walCfg.vgId = pCreate->vgId;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1016,7 +1032,7 @@ static int32_t dndInitVnodeWriteWorker(SDnode *pDnode) {
|
|||
SVnodesMgmt * pMgmt = &pDnode->vmgmt;
|
||||
SMWorkerPool *pPool = &pMgmt->writePool;
|
||||
pPool->name = "vnode-write";
|
||||
pPool->max = tsNumOfCores;
|
||||
pPool->max = pDnode->opt.numOfCores;
|
||||
if (tMWorkerInit(pPool) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
|
@ -1050,7 +1066,7 @@ static void dndFreeVnodeSyncQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
|||
}
|
||||
|
||||
static int32_t dndInitVnodeSyncWorker(SDnode *pDnode) {
|
||||
int32_t maxThreads = tsNumOfCores / 2;
|
||||
int32_t maxThreads = pDnode->opt.numOfCores / 2;
|
||||
if (maxThreads < 1) maxThreads = 1;
|
||||
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
enable_testing()
|
||||
|
||||
add_subdirectory(acct)
|
||||
# add_subdirectory(auth)
|
||||
# add_subdirectory(balance)
|
||||
# add_subdirectory(cluster)
|
||||
add_subdirectory(cluster)
|
||||
add_subdirectory(db)
|
||||
add_subdirectory(dnode)
|
||||
# add_subdirectory(func)
|
||||
# add_subdirectory(mnode)
|
||||
# add_subdirectory(profile)
|
||||
# add_subdirectory(show)
|
||||
# add_subdirectory(stb)
|
||||
add_subdirectory(stb)
|
||||
# add_subdirectory(sync)
|
||||
# add_subdirectory(telem)
|
||||
# add_subdirectory(trans)
|
||||
add_subdirectory(user)
|
||||
# add_subdirectory(vgroup)
|
||||
add_subdirectory(vgroup)
|
||||
|
||||
# add_subdirectory(common)
|
||||
|
|
|
@ -21,8 +21,6 @@ target_include_directories(dnode_test_acct
|
|||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
||||
)
|
||||
|
||||
enable_testing()
|
||||
|
||||
add_test(
|
||||
NAME dnode_test_acct
|
||||
COMMAND dnode_test_acct
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
/**
|
||||
* @file acct.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module acct-msg tests
|
||||
* @version 0.1
|
||||
* @date 2021-12-15
|
||||
*
|
||||
* 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.
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
* 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 "deploy.h"
|
||||
|
@ -49,7 +45,7 @@ SServer* DndTestAcct::pServer;
|
|||
SClient* DndTestAcct::pClient;
|
||||
int32_t DndTestAcct::connId;
|
||||
|
||||
TEST_F(DndTestAcct, CreateAcct) {
|
||||
TEST_F(DndTestAcct, 01_CreateAcct) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
|
||||
SCreateAcctMsg* pReq = (SCreateAcctMsg*)rpcMallocCont(sizeof(SCreateAcctMsg));
|
||||
|
@ -65,7 +61,7 @@ TEST_F(DndTestAcct, CreateAcct) {
|
|||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED);
|
||||
}
|
||||
|
||||
TEST_F(DndTestAcct, AlterAcct) {
|
||||
TEST_F(DndTestAcct, 02_AlterAcct) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
|
||||
SAlterAcctMsg* pReq = (SAlterAcctMsg*)rpcMallocCont(sizeof(SAlterAcctMsg));
|
||||
|
@ -81,7 +77,7 @@ TEST_F(DndTestAcct, AlterAcct) {
|
|||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED);
|
||||
}
|
||||
|
||||
TEST_F(DndTestAcct, DropAcct) {
|
||||
TEST_F(DndTestAcct, 03_DropAcct) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
|
||||
SDropAcctMsg* pReq = (SDropAcctMsg*)rpcMallocCont(sizeof(SDropAcctMsg));
|
||||
|
@ -97,7 +93,7 @@ TEST_F(DndTestAcct, DropAcct) {
|
|||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED);
|
||||
}
|
||||
|
||||
TEST_F(DndTestAcct, ShowAcct) {
|
||||
TEST_F(DndTestAcct, 04_ShowAcct) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
|
||||
SShowMsg* pReq = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
||||
|
|
|
@ -1,29 +1,27 @@
|
|||
add_executable(dndTestCluster "")
|
||||
add_executable(dnode_test_cluster "")
|
||||
|
||||
target_sources(dndTestCluster
|
||||
target_sources(dnode_test_cluster
|
||||
PRIVATE
|
||||
"cluster.cpp"
|
||||
"../sut/deploy.cpp"
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
dndTestCluster
|
||||
dnode_test_cluster
|
||||
PUBLIC dnode
|
||||
PUBLIC util
|
||||
PUBLIC os
|
||||
PUBLIC gtest_main
|
||||
)
|
||||
|
||||
target_include_directories(dndTestCluster
|
||||
target_include_directories(dnode_test_cluster
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
||||
)
|
||||
|
||||
enable_testing()
|
||||
|
||||
add_test(
|
||||
NAME dndTestCluster
|
||||
COMMAND dndTestCluster
|
||||
NAME dnode_test_cluster
|
||||
COMMAND dnode_test_cluster
|
||||
)
|
||||
|
|
|
@ -1,170 +1,170 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
/**
|
||||
* @file cluster.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module cluster-msg tests
|
||||
* @version 0.1
|
||||
* @date 2021-12-15
|
||||
*
|
||||
* 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.
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
* 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 "deploy.h"
|
||||
|
||||
class DndTestCluster : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
|
||||
SServer* pServer = createServer(path, fqdn, port, firstEp);
|
||||
ASSERT(pServer);
|
||||
return pServer;
|
||||
}
|
||||
|
||||
static void SetUpTestSuite() {
|
||||
const char* user = "root";
|
||||
const char* pass = "taosdata";
|
||||
const char* path = "/tmp/dndTestCluster";
|
||||
const char* fqdn = "localhost";
|
||||
uint16_t port = 9521;
|
||||
initLog("/tmp/tdlog");
|
||||
|
||||
pServer = createServer(path, fqdn, port);
|
||||
ASSERT(pServer);
|
||||
pClient = createClient(user, pass, fqdn, port);
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9030";
|
||||
pServer = CreateServer("/tmp/dnode_test_cluster", fqdn, 9030, firstEp);
|
||||
pClient = createClient("root", "taosdata", fqdn, 9030);
|
||||
taosMsleep(1100);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
stopServer(pServer);
|
||||
dropClient(pClient);
|
||||
pServer = NULL;
|
||||
pClient = NULL;
|
||||
}
|
||||
|
||||
static SServer* pServer;
|
||||
static SClient* pClient;
|
||||
static int32_t connId;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns, const char* db) {
|
||||
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
||||
pShow->type = showType;
|
||||
if (db != NULL) {
|
||||
strcpy(pShow->db, db);
|
||||
}
|
||||
SRpcMsg showRpcMsg = {0};
|
||||
showRpcMsg.pCont = pShow;
|
||||
showRpcMsg.contLen = sizeof(SShowMsg);
|
||||
showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
|
||||
|
||||
sendMsg(pClient, &showRpcMsg);
|
||||
ASSERT_NE(pClient->pRsp, nullptr);
|
||||
ASSERT_EQ(pClient->pRsp->code, 0);
|
||||
ASSERT_NE(pClient->pRsp->pCont, nullptr);
|
||||
|
||||
SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont;
|
||||
ASSERT_NE(pShowRsp, nullptr);
|
||||
pShowRsp->showId = htonl(pShowRsp->showId);
|
||||
pMeta = &pShowRsp->tableMeta;
|
||||
pMeta->numOfTags = htonl(pMeta->numOfTags);
|
||||
pMeta->numOfColumns = htonl(pMeta->numOfColumns);
|
||||
pMeta->sversion = htonl(pMeta->sversion);
|
||||
pMeta->tversion = htonl(pMeta->tversion);
|
||||
pMeta->tuid = htobe64(pMeta->tuid);
|
||||
pMeta->suid = htobe64(pMeta->suid);
|
||||
|
||||
showId = pShowRsp->showId;
|
||||
|
||||
EXPECT_NE(pShowRsp->showId, 0);
|
||||
EXPECT_STREQ(pMeta->tbFname, showName);
|
||||
EXPECT_EQ(pMeta->numOfTags, 0);
|
||||
EXPECT_EQ(pMeta->numOfColumns, columns);
|
||||
EXPECT_EQ(pMeta->precision, 0);
|
||||
EXPECT_EQ(pMeta->tableType, 0);
|
||||
EXPECT_EQ(pMeta->update, 0);
|
||||
EXPECT_EQ(pMeta->sversion, 0);
|
||||
EXPECT_EQ(pMeta->tversion, 0);
|
||||
EXPECT_EQ(pMeta->tuid, 0);
|
||||
EXPECT_EQ(pMeta->suid, 0);
|
||||
}
|
||||
|
||||
void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
|
||||
SSchema* pSchema = &pMeta->pSchema[index];
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, type);
|
||||
EXPECT_EQ(pSchema->bytes, bytes);
|
||||
EXPECT_STREQ(pSchema->name, name);
|
||||
}
|
||||
|
||||
void SendThenCheckShowRetrieveMsg(int32_t rows) {
|
||||
SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
|
||||
pRetrieve->showId = htonl(showId);
|
||||
pRetrieve->free = 0;
|
||||
|
||||
SRpcMsg retrieveRpcMsg = {0};
|
||||
retrieveRpcMsg.pCont = pRetrieve;
|
||||
retrieveRpcMsg.contLen = sizeof(SRetrieveTableMsg);
|
||||
retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
|
||||
|
||||
sendMsg(pClient, &retrieveRpcMsg);
|
||||
|
||||
ASSERT_NE(pClient->pRsp, nullptr);
|
||||
ASSERT_EQ(pClient->pRsp->code, 0);
|
||||
ASSERT_NE(pClient->pRsp->pCont, nullptr);
|
||||
|
||||
pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
|
||||
ASSERT_NE(pRetrieveRsp, nullptr);
|
||||
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
|
||||
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
|
||||
pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen);
|
||||
|
||||
EXPECT_EQ(pRetrieveRsp->numOfRows, rows);
|
||||
EXPECT_EQ(pRetrieveRsp->useconds, 0);
|
||||
// EXPECT_EQ(pRetrieveRsp->completed, completed);
|
||||
EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
||||
EXPECT_EQ(pRetrieveRsp->compressed, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->compLen, 0);
|
||||
|
||||
pData = pRetrieveRsp->data;
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
void CheckInt32() {
|
||||
int32_t data = *((int32_t*)(pData + pos));
|
||||
pos += sizeof(int32_t);
|
||||
EXPECT_GT(data, 0);
|
||||
}
|
||||
|
||||
void CheckTimestamp() {
|
||||
int64_t data = *((int64_t*)(pData + pos));
|
||||
pos += sizeof(int64_t);
|
||||
EXPECT_GT(data, 0);
|
||||
}
|
||||
|
||||
void CheckBinary(int32_t len) {
|
||||
pos += sizeof(VarDataLenT);
|
||||
char* data = (char*)(pData + pos);
|
||||
pos += len;
|
||||
}
|
||||
|
||||
int32_t showId;
|
||||
STableMetaMsg* pMeta;
|
||||
SRetrieveTableRsp* pRetrieveRsp;
|
||||
char* pData;
|
||||
int32_t pos;
|
||||
};
|
||||
|
||||
SServer* DndTestCluster::pServer;
|
||||
SClient* DndTestCluster::pClient;
|
||||
int32_t DndTestCluster::connId;
|
||||
|
||||
TEST_F(DndTestCluster, ShowCluster) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
int32_t showId = 0;
|
||||
TEST_F(DndTestCluster, 01_ShowCluster) {
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_CLUSTER, "show cluster", 3, NULL);
|
||||
CheckSchema(0, TSDB_DATA_TYPE_INT, 4, "id");
|
||||
CheckSchema(1, TSDB_DATA_TYPE_BINARY, TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, "name");
|
||||
CheckSchema(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
|
||||
{
|
||||
SShowMsg* pReq = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
||||
pReq->type = TSDB_MGMT_TABLE_CLUSTER;
|
||||
strcpy(pReq->db, "");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SShowMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
|
||||
SShowRsp* pRsp = (SShowRsp*)pMsg->pCont;
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
pRsp->showId = htonl(pRsp->showId);
|
||||
STableMetaMsg* pMeta = &pRsp->tableMeta;
|
||||
pMeta->contLen = htonl(pMeta->contLen);
|
||||
pMeta->numOfColumns = htons(pMeta->numOfColumns);
|
||||
pMeta->sversion = htons(pMeta->sversion);
|
||||
pMeta->tversion = htons(pMeta->tversion);
|
||||
pMeta->tid = htonl(pMeta->tid);
|
||||
pMeta->uid = htobe64(pMeta->uid);
|
||||
pMeta->suid = htobe64(pMeta->suid);
|
||||
|
||||
showId = pRsp->showId;
|
||||
|
||||
EXPECT_NE(pRsp->showId, 0);
|
||||
EXPECT_EQ(pMeta->contLen, 0);
|
||||
EXPECT_STREQ(pMeta->tbFname, "show cluster");
|
||||
EXPECT_EQ(pMeta->numOfTags, 0);
|
||||
EXPECT_EQ(pMeta->precision, 0);
|
||||
EXPECT_EQ(pMeta->tableType, 0);
|
||||
EXPECT_EQ(pMeta->numOfColumns, 3);
|
||||
EXPECT_EQ(pMeta->sversion, 0);
|
||||
EXPECT_EQ(pMeta->tversion, 0);
|
||||
EXPECT_EQ(pMeta->tid, 0);
|
||||
EXPECT_EQ(pMeta->uid, 0);
|
||||
EXPECT_STREQ(pMeta->sTableName, "");
|
||||
EXPECT_EQ(pMeta->suid, 0);
|
||||
|
||||
SSchema* pSchema = NULL;
|
||||
pSchema = &pMeta->pSchema[0];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT);
|
||||
EXPECT_EQ(pSchema->bytes, 4);
|
||||
EXPECT_STREQ(pSchema->name, "id");
|
||||
|
||||
pSchema = &pMeta->pSchema[1];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
|
||||
EXPECT_EQ(pSchema->bytes, TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE);
|
||||
EXPECT_STREQ(pSchema->name, "name");
|
||||
|
||||
pSchema = &pMeta->pSchema[2];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TIMESTAMP);
|
||||
EXPECT_EQ(pSchema->bytes, 8);
|
||||
EXPECT_STREQ(pSchema->name, "create_time");
|
||||
}
|
||||
|
||||
{
|
||||
SRetrieveTableMsg* pReq = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
|
||||
pReq->showId = htonl(showId);
|
||||
pReq->free = 0;
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SRetrieveTableMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
SRetrieveTableRsp* pRsp = (SRetrieveTableRsp*)pMsg->pCont;
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
pRsp->numOfRows = htonl(pRsp->numOfRows);
|
||||
pRsp->offset = htobe64(pRsp->offset);
|
||||
pRsp->useconds = htobe64(pRsp->useconds);
|
||||
pRsp->compLen = htonl(pRsp->compLen);
|
||||
|
||||
EXPECT_EQ(pRsp->numOfRows, 1);
|
||||
EXPECT_EQ(pRsp->offset, 0);
|
||||
EXPECT_EQ(pRsp->useconds, 0);
|
||||
EXPECT_EQ(pRsp->completed, 1);
|
||||
EXPECT_EQ(pRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
||||
EXPECT_EQ(pRsp->compressed, 0);
|
||||
EXPECT_EQ(pRsp->reserved, 0);
|
||||
EXPECT_EQ(pRsp->compLen, 0);
|
||||
|
||||
char* pData = pRsp->data;
|
||||
int32_t pos = 0;
|
||||
|
||||
int32_t id = *((int32_t*)(pData + pos));
|
||||
pos += sizeof(int32_t);
|
||||
|
||||
int32_t nameLen = varDataLen(pData + pos);
|
||||
pos += sizeof(VarDataLenT);
|
||||
|
||||
char* name = (char*)(pData + pos);
|
||||
pos += TSDB_CLUSTER_ID_LEN;
|
||||
|
||||
int64_t create_time = *((int64_t*)(pData + pos));
|
||||
pos += sizeof(int64_t);
|
||||
|
||||
EXPECT_NE(id, 0);
|
||||
EXPECT_EQ(nameLen, 36);
|
||||
EXPECT_STRNE(name, "");
|
||||
EXPECT_GT(create_time, 0);
|
||||
printf("--- id:%d nameLen:%d name:%s time:%" PRId64 " --- \n", id, nameLen, name, create_time);
|
||||
}
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
CheckInt32();
|
||||
CheckBinary(TSDB_CLUSTER_ID_LEN);
|
||||
CheckTimestamp();
|
||||
}
|
|
@ -21,8 +21,6 @@ target_include_directories(dnode_test_db
|
|||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
||||
)
|
||||
|
||||
enable_testing()
|
||||
|
||||
add_test(
|
||||
NAME dnode_test_db
|
||||
COMMAND dnode_test_db
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
/**
|
||||
* @file db.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module db-msg tests
|
||||
* @version 0.1
|
||||
* @date 2021-12-15
|
||||
*
|
||||
* 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.
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
* 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 "deploy.h"
|
||||
|
@ -30,7 +26,7 @@ class DndTestDb : public ::testing::Test {
|
|||
const char* firstEp = "localhost:9040";
|
||||
pServer = CreateServer("/tmp/dnode_test_db", fqdn, 9040, firstEp);
|
||||
pClient = createClient("root", "taosdata", fqdn, 9040);
|
||||
taosMsleep(300);
|
||||
taosMsleep(1100);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
|
@ -48,11 +44,12 @@ class DndTestDb : public ::testing::Test {
|
|||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns) {
|
||||
void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns, const char* db) {
|
||||
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
||||
pShow->type = showType;
|
||||
strcpy(pShow->db, "");
|
||||
|
||||
if (db != NULL) {
|
||||
strcpy(pShow->db, db);
|
||||
}
|
||||
SRpcMsg showRpcMsg = {0};
|
||||
showRpcMsg.pCont = pShow;
|
||||
showRpcMsg.contLen = sizeof(SShowMsg);
|
||||
|
@ -67,10 +64,10 @@ class DndTestDb : public ::testing::Test {
|
|||
ASSERT_NE(pShowRsp, nullptr);
|
||||
pShowRsp->showId = htonl(pShowRsp->showId);
|
||||
pMeta = &pShowRsp->tableMeta;
|
||||
pMeta->numOfTags = htons(pMeta->numOfTags);
|
||||
pMeta->numOfColumns = htons(pMeta->numOfColumns);
|
||||
pMeta->sversion = htons(pMeta->sversion);
|
||||
pMeta->tversion = htons(pMeta->tversion);
|
||||
pMeta->numOfTags = htonl(pMeta->numOfTags);
|
||||
pMeta->numOfColumns = htonl(pMeta->numOfColumns);
|
||||
pMeta->sversion = htonl(pMeta->sversion);
|
||||
pMeta->tversion = htonl(pMeta->tversion);
|
||||
pMeta->tuid = htobe64(pMeta->tuid);
|
||||
pMeta->suid = htobe64(pMeta->suid);
|
||||
|
||||
|
@ -91,7 +88,7 @@ class DndTestDb : public ::testing::Test {
|
|||
|
||||
void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
|
||||
SSchema* pSchema = &pMeta->pSchema[index];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, type);
|
||||
EXPECT_EQ(pSchema->bytes, bytes);
|
||||
|
@ -117,17 +114,14 @@ class DndTestDb : public ::testing::Test {
|
|||
pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
|
||||
ASSERT_NE(pRetrieveRsp, nullptr);
|
||||
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
|
||||
pRetrieveRsp->offset = htobe64(pRetrieveRsp->offset);
|
||||
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
|
||||
pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen);
|
||||
|
||||
EXPECT_EQ(pRetrieveRsp->numOfRows, rows);
|
||||
EXPECT_EQ(pRetrieveRsp->offset, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->useconds, 0);
|
||||
// EXPECT_EQ(pRetrieveRsp->completed, completed);
|
||||
EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
||||
EXPECT_EQ(pRetrieveRsp->compressed, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->reserved, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->compLen, 0);
|
||||
|
||||
pData = pRetrieveRsp->data;
|
||||
|
@ -183,31 +177,198 @@ SClient* DndTestDb::pClient;
|
|||
int32_t DndTestDb::connId;
|
||||
|
||||
TEST_F(DndTestDb, 01_ShowDb) {
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 16);
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 17, NULL);
|
||||
CheckSchema(0, TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN - 1 + VARSTR_HEADER_SIZE, "name");
|
||||
CheckSchema(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create time");
|
||||
CheckSchema(2, TSDB_DATA_TYPE_SMALLINT, 2, "replica");
|
||||
CheckSchema(3, TSDB_DATA_TYPE_SMALLINT, 2, "quorum");
|
||||
CheckSchema(4, TSDB_DATA_TYPE_SMALLINT, 2, "days");
|
||||
CheckSchema(5, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "keep0,keep1,keep2");
|
||||
CheckSchema(6, TSDB_DATA_TYPE_INT, 4, "cache(MB)");
|
||||
CheckSchema(7, TSDB_DATA_TYPE_INT, 4, "blocks");
|
||||
CheckSchema(8, TSDB_DATA_TYPE_INT, 4, "minrows");
|
||||
CheckSchema(9, TSDB_DATA_TYPE_INT, 4, "maxrows");
|
||||
CheckSchema(10, TSDB_DATA_TYPE_TINYINT, 1, "wallevel");
|
||||
CheckSchema(11, TSDB_DATA_TYPE_INT, 4, "fsync");
|
||||
CheckSchema(12, TSDB_DATA_TYPE_TINYINT, 1, "comp");
|
||||
CheckSchema(13, TSDB_DATA_TYPE_TINYINT, 1, "cachelast");
|
||||
CheckSchema(14, TSDB_DATA_TYPE_BINARY, 3 + VARSTR_HEADER_SIZE, "precision");
|
||||
CheckSchema(15, TSDB_DATA_TYPE_TINYINT, 1, "update");
|
||||
CheckSchema(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
CheckSchema(2, TSDB_DATA_TYPE_SMALLINT, 2, "vgroups");
|
||||
CheckSchema(3, TSDB_DATA_TYPE_SMALLINT, 2, "replica");
|
||||
CheckSchema(4, TSDB_DATA_TYPE_SMALLINT, 2, "quorum");
|
||||
CheckSchema(5, TSDB_DATA_TYPE_SMALLINT, 2, "days");
|
||||
CheckSchema(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "keep0,keep1,keep2");
|
||||
CheckSchema(7, TSDB_DATA_TYPE_INT, 4, "cache");
|
||||
CheckSchema(8, TSDB_DATA_TYPE_INT, 4, "blocks");
|
||||
CheckSchema(9, TSDB_DATA_TYPE_INT, 4, "minrows");
|
||||
CheckSchema(10, TSDB_DATA_TYPE_INT, 4, "maxrows");
|
||||
CheckSchema(11, TSDB_DATA_TYPE_TINYINT, 1, "wallevel");
|
||||
CheckSchema(12, TSDB_DATA_TYPE_INT, 4, "fsync");
|
||||
CheckSchema(13, TSDB_DATA_TYPE_TINYINT, 1, "comp");
|
||||
CheckSchema(14, TSDB_DATA_TYPE_TINYINT, 1, "cachelast");
|
||||
CheckSchema(15, TSDB_DATA_TYPE_BINARY, 3 + VARSTR_HEADER_SIZE, "precision");
|
||||
CheckSchema(16, TSDB_DATA_TYPE_TINYINT, 1, "update");
|
||||
|
||||
SendThenCheckShowRetrieveMsg(0);
|
||||
}
|
||||
|
||||
TEST_F(DndTestDb, 02_CreateDb) {
|
||||
TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) {
|
||||
{
|
||||
SCreateDbMsg* pReq = (SCreateDbMsg*)rpcMallocCont(sizeof(SCreateDbMsg));
|
||||
strcpy(pReq->db, "1.d1");
|
||||
pReq->numOfVgroups = htonl(2);
|
||||
pReq->cacheBlockSize = htonl(16);
|
||||
pReq->totalBlocks = htonl(10);
|
||||
pReq->daysPerFile = htonl(10);
|
||||
pReq->daysToKeep0 = htonl(3650);
|
||||
pReq->daysToKeep1 = htonl(3650);
|
||||
pReq->daysToKeep2 = htonl(3650);
|
||||
pReq->minRowsPerFileBlock = htonl(100);
|
||||
pReq->maxRowsPerFileBlock = htonl(4096);
|
||||
pReq->commitTime = htonl(3600);
|
||||
pReq->fsyncPeriod = htonl(3000);
|
||||
pReq->walLevel = 1;
|
||||
pReq->precision = 0;
|
||||
pReq->compression = 2;
|
||||
pReq->replications = 1;
|
||||
pReq->quorum = 1;
|
||||
pReq->update = 0;
|
||||
pReq->cacheLastRow = 0;
|
||||
pReq->ignoreExist = 1;
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SCreateDbMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DB;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
// taosMsleep(1000000);
|
||||
}
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 17, NULL);
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
CheckBinary("d1", TSDB_DB_NAME_LEN - 1);
|
||||
CheckTimestamp();
|
||||
CheckInt16(2); // vgroups
|
||||
CheckInt16(1); // replica
|
||||
CheckInt16(1); // quorum
|
||||
CheckInt16(10); // days
|
||||
CheckBinary("3650,3650,3650", 24); // days
|
||||
CheckInt32(16); // cache
|
||||
CheckInt32(10); // blocks
|
||||
CheckInt32(100); // minrows
|
||||
CheckInt32(4096); // maxrows
|
||||
CheckInt8(1); // wallevel
|
||||
CheckInt32(3000); // fsync
|
||||
CheckInt8(2); // comp
|
||||
CheckInt8(0); // cachelast
|
||||
CheckBinary("ms", 3); // precision
|
||||
CheckInt8(0); // update
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_VGROUP, "show vgroups", 4, "1.d1");
|
||||
CheckSchema(0, TSDB_DATA_TYPE_INT, 4, "vgId");
|
||||
CheckSchema(1, TSDB_DATA_TYPE_INT, 4, "tables");
|
||||
CheckSchema(2, TSDB_DATA_TYPE_SMALLINT, 2, "v1_dnode");
|
||||
CheckSchema(3, TSDB_DATA_TYPE_BINARY, 9 + VARSTR_HEADER_SIZE, "v1_status");
|
||||
SendThenCheckShowRetrieveMsg(2);
|
||||
CheckInt32(1);
|
||||
CheckInt32(2);
|
||||
CheckInt32(0);
|
||||
CheckInt32(0);
|
||||
CheckInt16(1);
|
||||
CheckInt16(1);
|
||||
CheckBinary("master", 9);
|
||||
CheckBinary("master", 9);
|
||||
|
||||
{
|
||||
SAlterDbMsg* pReq = (SAlterDbMsg*)rpcMallocCont(sizeof(SAlterDbMsg));
|
||||
strcpy(pReq->db, "1.d1");
|
||||
pReq->totalBlocks = htonl(12);
|
||||
pReq->daysToKeep0 = htonl(300);
|
||||
pReq->daysToKeep1 = htonl(400);
|
||||
pReq->daysToKeep2 = htonl(500);
|
||||
pReq->fsyncPeriod = htonl(4000);
|
||||
pReq->walLevel = 2;
|
||||
pReq->quorum = 2;
|
||||
pReq->cacheLastRow = 1;
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SAlterDbMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_ALTER_DB;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 17, NULL);
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
CheckBinary("d1", TSDB_DB_NAME_LEN - 1);
|
||||
CheckTimestamp();
|
||||
CheckInt16(2); // vgroups
|
||||
CheckInt16(1); // replica
|
||||
CheckInt16(2); // quorum
|
||||
CheckInt16(10); // days
|
||||
CheckBinary("300,400,500", 24); // days
|
||||
CheckInt32(16); // cache
|
||||
CheckInt32(12); // blocks
|
||||
CheckInt32(100); // minrows
|
||||
CheckInt32(4096); // maxrows
|
||||
CheckInt8(2); // wallevel
|
||||
CheckInt32(4000); // fsync
|
||||
CheckInt8(2); // comp
|
||||
CheckInt8(1); // cachelast
|
||||
CheckBinary("ms", 3); // precision
|
||||
CheckInt8(0); // update
|
||||
|
||||
// restart
|
||||
stopServer(pServer);
|
||||
pServer = NULL;
|
||||
|
||||
uInfo("start all server");
|
||||
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9040";
|
||||
pServer = startServer("/tmp/dnode_test_db", fqdn, 9040, firstEp);
|
||||
|
||||
uInfo("all server is running");
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 17, NULL);
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
CheckBinary("d1", TSDB_DB_NAME_LEN - 1);
|
||||
CheckTimestamp();
|
||||
CheckInt16(2); // vgroups
|
||||
CheckInt16(1); // replica
|
||||
CheckInt16(2); // quorum
|
||||
CheckInt16(10); // days
|
||||
CheckBinary("300,400,500", 24); // days
|
||||
CheckInt32(16); // cache
|
||||
CheckInt32(12); // blocks
|
||||
CheckInt32(100); // minrows
|
||||
CheckInt32(4096); // maxrows
|
||||
CheckInt8(2); // wallevel
|
||||
CheckInt32(4000); // fsync
|
||||
CheckInt8(2); // comp
|
||||
CheckInt8(1); // cachelast
|
||||
CheckBinary("ms", 3); // precision
|
||||
CheckInt8(0); // update
|
||||
|
||||
{
|
||||
SDropDbMsg* pReq = (SDropDbMsg*)rpcMallocCont(sizeof(SDropDbMsg));
|
||||
strcpy(pReq->db, "1.d1");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SDropDbMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_DROP_DB;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 17, NULL);
|
||||
SendThenCheckShowRetrieveMsg(0);
|
||||
}
|
||||
|
||||
TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) {
|
||||
{
|
||||
SCreateDbMsg* pReq = (SCreateDbMsg*)rpcMallocCont(sizeof(SCreateDbMsg));
|
||||
strcpy(pReq->db, "1.d2");
|
||||
pReq->numOfVgroups = htonl(2);
|
||||
pReq->cacheBlockSize = htonl(16);
|
||||
pReq->totalBlocks = htonl(10);
|
||||
pReq->daysPerFile = htonl(10);
|
||||
|
@ -238,118 +399,64 @@ TEST_F(DndTestDb, 02_CreateDb) {
|
|||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 16);
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 17, NULL);
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
CheckBinary("d1", TSDB_DB_NAME_LEN - 1);
|
||||
CheckTimestamp();
|
||||
CheckInt16(1); // replica
|
||||
CheckInt16(1); // quorum
|
||||
CheckInt16(10); // days
|
||||
CheckBinary("3650,3650,3650", 24); // days
|
||||
CheckInt32(16); // cache
|
||||
CheckInt32(10); // blocks
|
||||
CheckInt32(100); // minrows
|
||||
CheckInt32(4096); // maxrows
|
||||
CheckInt8(1); // wallevel
|
||||
CheckInt32(3000); // fsync
|
||||
CheckInt8(2); // comp
|
||||
CheckInt8(0); // cachelast
|
||||
CheckBinary("ms", 3); // precision
|
||||
CheckInt8(0); // update
|
||||
}
|
||||
CheckBinary("d2", TSDB_DB_NAME_LEN - 1);
|
||||
|
||||
TEST_F(DndTestDb, 03_AlterDb) {
|
||||
{
|
||||
SAlterDbMsg* pReq = (SAlterDbMsg*)rpcMallocCont(sizeof(SAlterDbMsg));
|
||||
strcpy(pReq->db, "1.d1");
|
||||
pReq->totalBlocks = htonl(12);
|
||||
pReq->daysToKeep0 = htonl(300);
|
||||
pReq->daysToKeep1 = htonl(400);
|
||||
pReq->daysToKeep2 = htonl(500);
|
||||
pReq->fsyncPeriod = htonl(4000);
|
||||
pReq->walLevel = 2;
|
||||
pReq->quorum = 2;
|
||||
pReq->cacheLastRow = 1;
|
||||
SUseDbMsg* pReq = (SUseDbMsg*)rpcMallocCont(sizeof(SUseDbMsg));
|
||||
strcpy(pReq->db, "1.d2");
|
||||
pReq->vgVersion = htonl(-1);
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SAlterDbMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_ALTER_DB;
|
||||
rpcMsg.contLen = sizeof(SUseDbMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_USE_DB;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
SUseDbRsp* pRsp = (SUseDbRsp*)pMsg->pCont;
|
||||
EXPECT_STREQ(pRsp->db, "1.d2");
|
||||
pRsp->vgVersion = htonl(pRsp->vgVersion);
|
||||
pRsp->vgNum = htonl(pRsp->vgNum);
|
||||
pRsp->hashMethod = pRsp->hashMethod;
|
||||
EXPECT_EQ(pRsp->vgVersion, 1);
|
||||
EXPECT_EQ(pRsp->vgNum, 2);
|
||||
EXPECT_EQ(pRsp->hashMethod, 1);
|
||||
|
||||
{
|
||||
SVgroupInfo* pInfo = &pRsp->vgroupInfo[0];
|
||||
pInfo->vgId = htonl(pInfo->vgId);
|
||||
pInfo->hashBegin = htonl(pInfo->hashBegin);
|
||||
pInfo->hashEnd = htonl(pInfo->hashEnd);
|
||||
EXPECT_GT(pInfo->vgId, 0);
|
||||
EXPECT_EQ(pInfo->hashBegin, 0);
|
||||
EXPECT_EQ(pInfo->hashEnd, UINT32_MAX / 2 - 1);
|
||||
EXPECT_EQ(pInfo->inUse, 0);
|
||||
EXPECT_EQ(pInfo->numOfEps, 1);
|
||||
SEpAddrMsg* pAddr = &pInfo->epAddr[0];
|
||||
pAddr->port = htons(pAddr->port);
|
||||
EXPECT_EQ(pAddr->port, 9040);
|
||||
EXPECT_STREQ(pAddr->fqdn, "localhost");
|
||||
}
|
||||
|
||||
{
|
||||
SVgroupInfo* pInfo = &pRsp->vgroupInfo[1];
|
||||
pInfo->vgId = htonl(pInfo->vgId);
|
||||
pInfo->hashBegin = htonl(pInfo->hashBegin);
|
||||
pInfo->hashEnd = htonl(pInfo->hashEnd);
|
||||
EXPECT_GT(pInfo->vgId, 0);
|
||||
EXPECT_EQ(pInfo->hashBegin, UINT32_MAX / 2);
|
||||
EXPECT_EQ(pInfo->hashEnd, UINT32_MAX);
|
||||
EXPECT_EQ(pInfo->inUse, 0);
|
||||
EXPECT_EQ(pInfo->numOfEps, 1);
|
||||
SEpAddrMsg* pAddr = &pInfo->epAddr[0];
|
||||
pAddr->port = htons(pAddr->port);
|
||||
EXPECT_EQ(pAddr->port, 9040);
|
||||
EXPECT_STREQ(pAddr->fqdn, "localhost");
|
||||
}
|
||||
}
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 16);
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
CheckBinary("d1", TSDB_DB_NAME_LEN - 1);
|
||||
CheckTimestamp();
|
||||
CheckInt16(1); // replica
|
||||
CheckInt16(2); // quorum
|
||||
CheckInt16(10); // days
|
||||
CheckBinary("300,400,500", 24); // days
|
||||
CheckInt32(16); // cache
|
||||
CheckInt32(12); // blocks
|
||||
CheckInt32(100); // minrows
|
||||
CheckInt32(4096); // maxrows
|
||||
CheckInt8(2); // wallevel
|
||||
CheckInt32(4000); // fsync
|
||||
CheckInt8(2); // comp
|
||||
CheckInt8(1); // cachelast
|
||||
CheckBinary("ms", 3); // precision
|
||||
CheckInt8(0); // update
|
||||
}
|
||||
|
||||
TEST_F(DndTestDb, 04_RestartDnode) {
|
||||
stopServer(pServer);
|
||||
pServer = NULL;
|
||||
|
||||
uInfo("start all server");
|
||||
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9040";
|
||||
pServer = startServer("/tmp/dnode_test_db", fqdn, 9040, firstEp);
|
||||
|
||||
uInfo("all server is running");
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 16);
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
CheckBinary("d1", TSDB_DB_NAME_LEN - 1);
|
||||
CheckTimestamp();
|
||||
CheckInt16(1); // replica
|
||||
CheckInt16(2); // quorum
|
||||
CheckInt16(10); // days
|
||||
CheckBinary("300,400,500", 24); // days
|
||||
CheckInt32(16); // cache
|
||||
CheckInt32(12); // blocks
|
||||
CheckInt32(100); // minrows
|
||||
CheckInt32(4096); // maxrows
|
||||
CheckInt8(2); // wallevel
|
||||
CheckInt32(4000); // fsync
|
||||
CheckInt8(2); // comp
|
||||
CheckInt8(1); // cachelast
|
||||
CheckBinary("ms", 3); // precision
|
||||
CheckInt8(0); // update
|
||||
}
|
||||
|
||||
TEST_F(DndTestDb, 05_DropDb) {
|
||||
{
|
||||
SDropDbMsg* pReq = (SDropDbMsg*)rpcMallocCont(sizeof(SAlterDbMsg));
|
||||
strcpy(pReq->db, "1.d1");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SDropDbMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_DROP_DB;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 16);
|
||||
SendThenCheckShowRetrieveMsg(0);
|
||||
}
|
|
@ -21,8 +21,6 @@ target_include_directories(dnode_test_dnode
|
|||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
||||
)
|
||||
|
||||
enable_testing()
|
||||
|
||||
add_test(
|
||||
NAME dnode_test_dnode
|
||||
COMMAND dnode_test_dnode
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
/**
|
||||
* @file dnode.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module dnode-msg tests
|
||||
* @version 0.1
|
||||
* @date 2021-12-15
|
||||
*
|
||||
* 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.
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
* 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 "deploy.h"
|
||||
|
@ -82,10 +78,10 @@ class DndTestDnode : public ::testing::Test {
|
|||
ASSERT_NE(pShowRsp, nullptr);
|
||||
pShowRsp->showId = htonl(pShowRsp->showId);
|
||||
pMeta = &pShowRsp->tableMeta;
|
||||
pMeta->numOfTags = htons(pMeta->numOfTags);
|
||||
pMeta->numOfColumns = htons(pMeta->numOfColumns);
|
||||
pMeta->sversion = htons(pMeta->sversion);
|
||||
pMeta->tversion = htons(pMeta->tversion);
|
||||
pMeta->numOfTags = htonl(pMeta->numOfTags);
|
||||
pMeta->numOfColumns = htonl(pMeta->numOfColumns);
|
||||
pMeta->sversion = htonl(pMeta->sversion);
|
||||
pMeta->tversion = htonl(pMeta->tversion);
|
||||
pMeta->tuid = htobe64(pMeta->tuid);
|
||||
pMeta->suid = htobe64(pMeta->suid);
|
||||
|
||||
|
@ -106,7 +102,7 @@ class DndTestDnode : public ::testing::Test {
|
|||
|
||||
void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
|
||||
SSchema* pSchema = &pMeta->pSchema[index];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, type);
|
||||
EXPECT_EQ(pSchema->bytes, bytes);
|
||||
|
@ -132,17 +128,14 @@ class DndTestDnode : public ::testing::Test {
|
|||
pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
|
||||
ASSERT_NE(pRetrieveRsp, nullptr);
|
||||
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
|
||||
pRetrieveRsp->offset = htobe64(pRetrieveRsp->offset);
|
||||
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
|
||||
pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen);
|
||||
|
||||
EXPECT_EQ(pRetrieveRsp->numOfRows, rows);
|
||||
EXPECT_EQ(pRetrieveRsp->offset, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->useconds, 0);
|
||||
// EXPECT_EQ(pRetrieveRsp->completed, completed);
|
||||
EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
||||
EXPECT_EQ(pRetrieveRsp->compressed, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->reserved, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->compLen, 0);
|
||||
|
||||
pData = pRetrieveRsp->data;
|
||||
|
@ -191,12 +184,12 @@ SClient* DndTestDnode::pClient;
|
|||
TEST_F(DndTestDnode, 01_ShowDnode) {
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7);
|
||||
CheckSchema(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||
CheckSchema(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "end point");
|
||||
CheckSchema(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
||||
CheckSchema(2, TSDB_DATA_TYPE_SMALLINT, 2, "vnodes");
|
||||
CheckSchema(3, TSDB_DATA_TYPE_SMALLINT, 2, "max vnodes");
|
||||
CheckSchema(3, TSDB_DATA_TYPE_SMALLINT, 2, "max_vnodes");
|
||||
CheckSchema(4, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "status");
|
||||
CheckSchema(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "create time");
|
||||
CheckSchema(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "offline reason");
|
||||
CheckSchema(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
CheckSchema(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "offline_reason");
|
||||
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
CheckInt16(1);
|
||||
|
@ -224,19 +217,21 @@ TEST_F(DndTestDnode, 02_ConfigDnode) {
|
|||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
TEST_F(DndTestDnode, 03_CreateDnode) {
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(sizeof(SCreateDnodeMsg));
|
||||
strcpy(pReq->ep, "localhost:9042");
|
||||
TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
|
||||
{
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(sizeof(SCreateDnodeMsg));
|
||||
strcpy(pReq->ep, "localhost:9042");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SCreateDnodeMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DNODE;
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SCreateDnodeMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DNODE;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
taosMsleep(1300);
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7);
|
||||
|
@ -255,21 +250,21 @@ TEST_F(DndTestDnode, 03_CreateDnode) {
|
|||
CheckTimestamp();
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
}
|
||||
|
||||
TEST_F(DndTestDnode, 04_DropDnode) {
|
||||
SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(sizeof(SDropDnodeMsg));
|
||||
pReq->dnodeId = htonl(2);
|
||||
{
|
||||
SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(sizeof(SDropDnodeMsg));
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SDropDnodeMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_DROP_DNODE;
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SDropDnodeMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_DROP_DNODE;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7);
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
|
@ -280,9 +275,7 @@ TEST_F(DndTestDnode, 04_DropDnode) {
|
|||
CheckBinary("ready", 10);
|
||||
CheckTimestamp();
|
||||
CheckBinary("", 24);
|
||||
}
|
||||
|
||||
TEST_F(DndTestDnode, 05_CreateDnode) {
|
||||
{
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(sizeof(SCreateDnodeMsg));
|
||||
strcpy(pReq->ep, "localhost:9043");
|
||||
|
@ -359,9 +352,8 @@ TEST_F(DndTestDnode, 05_CreateDnode) {
|
|||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
CheckBinary("", 24);
|
||||
}
|
||||
|
||||
TEST_F(DndTestDnode, 06_RestartDnode) {
|
||||
// restart
|
||||
uInfo("stop all server");
|
||||
stopServer(pServer1);
|
||||
stopServer(pServer2);
|
||||
|
|
|
@ -21,8 +21,6 @@ target_include_directories(dndTestProfile
|
|||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
||||
)
|
||||
|
||||
enable_testing()
|
||||
|
||||
add_test(
|
||||
NAME dndTestProfile
|
||||
COMMAND dndTestProfile
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
/**
|
||||
* @file profile.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module profile-msg tests
|
||||
* @version 0.1
|
||||
* @date 2021-12-15
|
||||
*
|
||||
* 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.
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
* 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 "deploy.h"
|
||||
|
@ -220,17 +216,14 @@ TEST_F(DndTestProfile, SConnectMsg_03) {
|
|||
SRetrieveTableRsp* pRsp = (SRetrieveTableRsp*)pMsg->pCont;
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
pRsp->numOfRows = htonl(pRsp->numOfRows);
|
||||
pRsp->offset = htobe64(pRsp->offset);
|
||||
pRsp->useconds = htobe64(pRsp->useconds);
|
||||
pRsp->compLen = htonl(pRsp->compLen);
|
||||
|
||||
EXPECT_EQ(pRsp->numOfRows, 1);
|
||||
EXPECT_EQ(pRsp->offset, 0);
|
||||
EXPECT_EQ(pRsp->useconds, 0);
|
||||
EXPECT_EQ(pRsp->completed, 1);
|
||||
EXPECT_EQ(pRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
||||
EXPECT_EQ(pRsp->compressed, 0);
|
||||
EXPECT_EQ(pRsp->reserved, 0);
|
||||
EXPECT_EQ(pRsp->compLen, 0);
|
||||
}
|
||||
}
|
||||
|
@ -501,7 +494,7 @@ TEST_F(DndTestProfile, SKillQueryMsg_03) {
|
|||
EXPECT_STREQ(pSchema->name, "queryId");
|
||||
|
||||
pSchema = &pMeta->pSchema[1];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT);
|
||||
EXPECT_EQ(pSchema->bytes, 4);
|
||||
|
|
|
@ -1,29 +1,27 @@
|
|||
add_executable(dndTestShow "")
|
||||
add_executable(dnode_test_show "")
|
||||
|
||||
target_sources(dndTestShow
|
||||
target_sources(dnode_test_show
|
||||
PRIVATE
|
||||
"show.cpp"
|
||||
"../sut/deploy.cpp"
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
dndTestShow
|
||||
dnode_test_show
|
||||
PUBLIC dnode
|
||||
PUBLIC util
|
||||
PUBLIC os
|
||||
PUBLIC gtest_main
|
||||
)
|
||||
|
||||
target_include_directories(dndTestShow
|
||||
target_include_directories(dnode_test_show
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
||||
)
|
||||
|
||||
enable_testing()
|
||||
|
||||
add_test(
|
||||
NAME dndTestShow
|
||||
COMMAND dndTestShow
|
||||
NAME dnode_test_show
|
||||
COMMAND dnode_test_show
|
||||
)
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
/**
|
||||
* @file show.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module show-msg tests
|
||||
* @version 0.1
|
||||
* @date 2021-12-15
|
||||
*
|
||||
* 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.
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
* 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 "deploy.h"
|
||||
|
@ -155,49 +151,49 @@ TEST_F(DndTestShow, SShowMsg_04) {
|
|||
|
||||
SSchema* pSchema = NULL;
|
||||
pSchema = &pMeta->pSchema[0];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT);
|
||||
EXPECT_EQ(pSchema->bytes, 4);
|
||||
EXPECT_STREQ(pSchema->name, "connId");
|
||||
|
||||
pSchema = &pMeta->pSchema[1];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
|
||||
EXPECT_EQ(pSchema->bytes, TSDB_USER_LEN + VARSTR_HEADER_SIZE);
|
||||
EXPECT_STREQ(pSchema->name, "user");
|
||||
|
||||
pSchema = &pMeta->pSchema[2];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
|
||||
EXPECT_EQ(pSchema->bytes, TSDB_USER_LEN + VARSTR_HEADER_SIZE);
|
||||
EXPECT_STREQ(pSchema->name, "program");
|
||||
|
||||
pSchema = &pMeta->pSchema[3];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT);
|
||||
EXPECT_EQ(pSchema->bytes, 4);
|
||||
EXPECT_STREQ(pSchema->name, "pid");
|
||||
|
||||
pSchema = &pMeta->pSchema[4];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
|
||||
EXPECT_EQ(pSchema->bytes, TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE);
|
||||
EXPECT_STREQ(pSchema->name, "ip:port");
|
||||
|
||||
pSchema = &pMeta->pSchema[5];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TIMESTAMP);
|
||||
EXPECT_EQ(pSchema->bytes, 8);
|
||||
EXPECT_STREQ(pSchema->name, "login_time");
|
||||
|
||||
pSchema = &pMeta->pSchema[6];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TIMESTAMP);
|
||||
EXPECT_EQ(pSchema->bytes, 8);
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
add_executable(dnode_test_stb "")
|
||||
|
||||
target_sources(dnode_test_stb
|
||||
PRIVATE
|
||||
"stb.cpp"
|
||||
"../sut/deploy.cpp"
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
dnode_test_stb
|
||||
PUBLIC dnode
|
||||
PUBLIC util
|
||||
PUBLIC os
|
||||
PUBLIC gtest_main
|
||||
)
|
||||
|
||||
target_include_directories(dnode_test_stb
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME dnode_test_stb
|
||||
COMMAND dnode_test_stb
|
||||
)
|
|
@ -0,0 +1,374 @@
|
|||
/**
|
||||
* @file stb.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module db-msg tests
|
||||
* @version 0.1
|
||||
* @date 2021-12-17
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
#include "deploy.h"
|
||||
|
||||
class DndTestStb : public ::testing::Test {
|
||||
protected:
|
||||
static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
|
||||
SServer* pServer = createServer(path, fqdn, port, firstEp);
|
||||
ASSERT(pServer);
|
||||
return pServer;
|
||||
}
|
||||
|
||||
static void SetUpTestSuite() {
|
||||
initLog("/tmp/tdlog");
|
||||
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9101";
|
||||
pServer = CreateServer("/tmp/dnode_test_stb", fqdn, 9101, firstEp);
|
||||
pClient = createClient("root", "taosdata", fqdn, 9101);
|
||||
taosMsleep(1100);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
stopServer(pServer);
|
||||
dropClient(pClient);
|
||||
pServer = NULL;
|
||||
pClient = NULL;
|
||||
}
|
||||
|
||||
static SServer* pServer;
|
||||
static SClient* pClient;
|
||||
static int32_t connId;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns, const char* db) {
|
||||
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
||||
pShow->type = showType;
|
||||
if (db != NULL) {
|
||||
strcpy(pShow->db, db);
|
||||
}
|
||||
SRpcMsg showRpcMsg = {0};
|
||||
showRpcMsg.pCont = pShow;
|
||||
showRpcMsg.contLen = sizeof(SShowMsg);
|
||||
showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
|
||||
|
||||
sendMsg(pClient, &showRpcMsg);
|
||||
ASSERT_NE(pClient->pRsp, nullptr);
|
||||
ASSERT_EQ(pClient->pRsp->code, 0);
|
||||
ASSERT_NE(pClient->pRsp->pCont, nullptr);
|
||||
|
||||
SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont;
|
||||
ASSERT_NE(pShowRsp, nullptr);
|
||||
pShowRsp->showId = htonl(pShowRsp->showId);
|
||||
pMeta = &pShowRsp->tableMeta;
|
||||
pMeta->numOfTags = htonl(pMeta->numOfTags);
|
||||
pMeta->numOfColumns = htonl(pMeta->numOfColumns);
|
||||
pMeta->sversion = htonl(pMeta->sversion);
|
||||
pMeta->tversion = htonl(pMeta->tversion);
|
||||
pMeta->tuid = htobe64(pMeta->tuid);
|
||||
pMeta->suid = htobe64(pMeta->suid);
|
||||
|
||||
showId = pShowRsp->showId;
|
||||
|
||||
EXPECT_NE(pShowRsp->showId, 0);
|
||||
EXPECT_STREQ(pMeta->tbFname, showName);
|
||||
EXPECT_EQ(pMeta->numOfTags, 0);
|
||||
EXPECT_EQ(pMeta->numOfColumns, columns);
|
||||
EXPECT_EQ(pMeta->precision, 0);
|
||||
EXPECT_EQ(pMeta->tableType, 0);
|
||||
EXPECT_EQ(pMeta->update, 0);
|
||||
EXPECT_EQ(pMeta->sversion, 0);
|
||||
EXPECT_EQ(pMeta->tversion, 0);
|
||||
EXPECT_EQ(pMeta->tuid, 0);
|
||||
EXPECT_EQ(pMeta->suid, 0);
|
||||
}
|
||||
|
||||
void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
|
||||
SSchema* pSchema = &pMeta->pSchema[index];
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, type);
|
||||
EXPECT_EQ(pSchema->bytes, bytes);
|
||||
EXPECT_STREQ(pSchema->name, name);
|
||||
}
|
||||
|
||||
void SendThenCheckShowRetrieveMsg(int32_t rows) {
|
||||
SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
|
||||
pRetrieve->showId = htonl(showId);
|
||||
pRetrieve->free = 0;
|
||||
|
||||
SRpcMsg retrieveRpcMsg = {0};
|
||||
retrieveRpcMsg.pCont = pRetrieve;
|
||||
retrieveRpcMsg.contLen = sizeof(SRetrieveTableMsg);
|
||||
retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
|
||||
|
||||
sendMsg(pClient, &retrieveRpcMsg);
|
||||
|
||||
ASSERT_NE(pClient->pRsp, nullptr);
|
||||
ASSERT_EQ(pClient->pRsp->code, 0);
|
||||
ASSERT_NE(pClient->pRsp->pCont, nullptr);
|
||||
|
||||
pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
|
||||
ASSERT_NE(pRetrieveRsp, nullptr);
|
||||
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
|
||||
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
|
||||
pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen);
|
||||
|
||||
EXPECT_EQ(pRetrieveRsp->numOfRows, rows);
|
||||
EXPECT_EQ(pRetrieveRsp->useconds, 0);
|
||||
// EXPECT_EQ(pRetrieveRsp->completed, completed);
|
||||
EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
||||
EXPECT_EQ(pRetrieveRsp->compressed, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->compLen, 0);
|
||||
|
||||
pData = pRetrieveRsp->data;
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
void CheckInt8(int8_t val) {
|
||||
int8_t data = *((int8_t*)(pData + pos));
|
||||
pos += sizeof(int8_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckInt16(int16_t val) {
|
||||
int16_t data = *((int16_t*)(pData + pos));
|
||||
pos += sizeof(int16_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckInt32(int32_t val) {
|
||||
int32_t data = *((int32_t*)(pData + pos));
|
||||
pos += sizeof(int32_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckInt64(int64_t val) {
|
||||
int64_t data = *((int64_t*)(pData + pos));
|
||||
pos += sizeof(int64_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckTimestamp() {
|
||||
int64_t data = *((int64_t*)(pData + pos));
|
||||
pos += sizeof(int64_t);
|
||||
EXPECT_GT(data, 0);
|
||||
}
|
||||
|
||||
void CheckBinary(const char* val, int32_t len) {
|
||||
pos += sizeof(VarDataLenT);
|
||||
char* data = (char*)(pData + pos);
|
||||
pos += len;
|
||||
EXPECT_STREQ(data, val);
|
||||
}
|
||||
|
||||
int32_t showId;
|
||||
STableMetaMsg* pMeta;
|
||||
SRetrieveTableRsp* pRetrieveRsp;
|
||||
char* pData;
|
||||
int32_t pos;
|
||||
};
|
||||
|
||||
SServer* DndTestStb::pServer;
|
||||
SClient* DndTestStb::pClient;
|
||||
int32_t DndTestStb::connId;
|
||||
|
||||
TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
||||
{
|
||||
SCreateDbMsg* pReq = (SCreateDbMsg*)rpcMallocCont(sizeof(SCreateDbMsg));
|
||||
strcpy(pReq->db, "1.d1");
|
||||
pReq->numOfVgroups = htonl(2);
|
||||
pReq->cacheBlockSize = htonl(16);
|
||||
pReq->totalBlocks = htonl(10);
|
||||
pReq->daysPerFile = htonl(10);
|
||||
pReq->daysToKeep0 = htonl(3650);
|
||||
pReq->daysToKeep1 = htonl(3650);
|
||||
pReq->daysToKeep2 = htonl(3650);
|
||||
pReq->minRowsPerFileBlock = htonl(100);
|
||||
pReq->maxRowsPerFileBlock = htonl(4096);
|
||||
pReq->commitTime = htonl(3600);
|
||||
pReq->fsyncPeriod = htonl(3000);
|
||||
pReq->walLevel = 1;
|
||||
pReq->precision = 0;
|
||||
pReq->compression = 2;
|
||||
pReq->replications = 1;
|
||||
pReq->quorum = 1;
|
||||
pReq->update = 0;
|
||||
pReq->cacheLastRow = 0;
|
||||
pReq->ignoreExist = 1;
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SCreateDbMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DB;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t cols = 2;
|
||||
int32_t tags = 3;
|
||||
int32_t size = (tags + cols) * sizeof(SSchema) + sizeof(SCreateStbMsg);
|
||||
|
||||
SCreateStbMsg* pReq = (SCreateStbMsg*)rpcMallocCont(size);
|
||||
strcpy(pReq->name, "1.d1.stb");
|
||||
pReq->numOfTags = htonl(tags);
|
||||
pReq->numOfColumns = htonl(cols);
|
||||
|
||||
{
|
||||
SSchema* pSchema = &pReq->pSchema[0];
|
||||
pSchema->colId = htonl(0);
|
||||
pSchema->bytes = htonl(8);
|
||||
pSchema->type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema->name, "ts");
|
||||
}
|
||||
|
||||
{
|
||||
SSchema* pSchema = &pReq->pSchema[1];
|
||||
pSchema->colId = htonl(1);
|
||||
pSchema->bytes = htonl(4);
|
||||
pSchema->type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema->name, "col1");
|
||||
}
|
||||
|
||||
{
|
||||
SSchema* pSchema = &pReq->pSchema[2];
|
||||
pSchema->colId = htonl(2);
|
||||
pSchema->bytes = htonl(2);
|
||||
pSchema->type = TSDB_DATA_TYPE_TINYINT;
|
||||
strcpy(pSchema->name, "tag1");
|
||||
}
|
||||
|
||||
{
|
||||
SSchema* pSchema = &pReq->pSchema[3];
|
||||
pSchema->colId = htonl(3);
|
||||
pSchema->bytes = htonl(8);
|
||||
pSchema->type = TSDB_DATA_TYPE_BIGINT;
|
||||
strcpy(pSchema->name, "tag2");
|
||||
}
|
||||
|
||||
{
|
||||
SSchema* pSchema = &pReq->pSchema[4];
|
||||
pSchema->colId = htonl(4);
|
||||
pSchema->bytes = htonl(16);
|
||||
pSchema->type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema->name, "tag3");
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = size;
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_STB;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_STB, "show stables", 4, "1.d1");
|
||||
CheckSchema(0, TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE, "name");
|
||||
CheckSchema(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
CheckSchema(2, TSDB_DATA_TYPE_INT, 4, "columns");
|
||||
CheckSchema(3, TSDB_DATA_TYPE_INT, 4, "tags");
|
||||
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
CheckBinary("stb", TSDB_TABLE_NAME_LEN);
|
||||
CheckTimestamp();
|
||||
CheckInt32(2);
|
||||
CheckInt32(3);
|
||||
|
||||
// ----- meta ------
|
||||
{
|
||||
STableInfoMsg* pReq = (STableInfoMsg*)rpcMallocCont(sizeof(STableInfoMsg));
|
||||
strcpy(pReq->tableFname, "1.d1.stb");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(STableInfoMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_TABLE_META;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
STableMetaMsg* pRsp = (STableMetaMsg*)pMsg->pCont;
|
||||
pRsp->numOfTags = htonl(pRsp->numOfTags);
|
||||
pRsp->numOfColumns = htonl(pRsp->numOfColumns);
|
||||
pRsp->sversion = htonl(pRsp->sversion);
|
||||
pRsp->tversion = htonl(pRsp->tversion);
|
||||
pRsp->suid = htobe64(pRsp->suid);
|
||||
pRsp->tuid = htobe64(pRsp->tuid);
|
||||
pRsp->vgId = htobe64(pRsp->vgId);
|
||||
for (int32_t i = 0; i < pRsp->numOfTags + pRsp->numOfColumns; ++i) {
|
||||
SSchema* pSchema = &pRsp->pSchema[i];
|
||||
pSchema->colId = htonl(pSchema->colId);
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
}
|
||||
|
||||
EXPECT_STREQ(pRsp->tbFname, "");
|
||||
EXPECT_STREQ(pRsp->stbFname, "1.d1.stb");
|
||||
EXPECT_EQ(pRsp->numOfColumns, 2);
|
||||
EXPECT_EQ(pRsp->numOfTags, 3);
|
||||
EXPECT_EQ(pRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
||||
EXPECT_EQ(pRsp->tableType, TSDB_SUPER_TABLE);
|
||||
EXPECT_EQ(pRsp->update, 0);
|
||||
EXPECT_EQ(pRsp->sversion, 1);
|
||||
EXPECT_EQ(pRsp->tversion, 0);
|
||||
EXPECT_GT(pRsp->suid, 0);
|
||||
EXPECT_EQ(pRsp->tuid, 0);
|
||||
EXPECT_EQ(pRsp->vgId, 0);
|
||||
|
||||
{
|
||||
SSchema* pSchema = &pRsp->pSchema[0];
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TIMESTAMP);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->bytes, 8);
|
||||
EXPECT_STREQ(pSchema->name, "ts");
|
||||
}
|
||||
}
|
||||
|
||||
// restart
|
||||
stopServer(pServer);
|
||||
pServer = NULL;
|
||||
|
||||
uInfo("start all server");
|
||||
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9101";
|
||||
pServer = startServer("/tmp/dnode_test_stb", fqdn, 9101, firstEp);
|
||||
|
||||
uInfo("all server is running");
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_STB, "show stables", 4, "1.d1");
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
CheckBinary("stb", TSDB_TABLE_NAME_LEN);
|
||||
CheckTimestamp();
|
||||
CheckInt32(2);
|
||||
CheckInt32(3);
|
||||
|
||||
{
|
||||
SDropStbMsg* pReq = (SDropStbMsg*)rpcMallocCont(sizeof(SDropStbMsg));
|
||||
strcpy(pReq->name, "1.d1.stb");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SDropStbMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_DROP_STB;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_STB, "show stables", 4, "1.d1");
|
||||
SendThenCheckShowRetrieveMsg(0);
|
||||
}
|
|
@ -21,8 +21,6 @@ target_include_directories(dnode_test_user
|
|||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
||||
)
|
||||
|
||||
enable_testing()
|
||||
|
||||
add_test(
|
||||
NAME dnode_test_user
|
||||
COMMAND dnode_test_user
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
/**
|
||||
* @file user.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module user-msg tests
|
||||
* @version 0.1
|
||||
* @date 2021-12-15
|
||||
*
|
||||
* 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.
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
* 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 "deploy.h"
|
||||
|
@ -67,10 +63,10 @@ class DndTestUser : public ::testing::Test {
|
|||
ASSERT_NE(pShowRsp, nullptr);
|
||||
pShowRsp->showId = htonl(pShowRsp->showId);
|
||||
pMeta = &pShowRsp->tableMeta;
|
||||
pMeta->numOfTags = htons(pMeta->numOfTags);
|
||||
pMeta->numOfColumns = htons(pMeta->numOfColumns);
|
||||
pMeta->sversion = htons(pMeta->sversion);
|
||||
pMeta->tversion = htons(pMeta->tversion);
|
||||
pMeta->numOfTags = htonl(pMeta->numOfTags);
|
||||
pMeta->numOfColumns = htonl(pMeta->numOfColumns);
|
||||
pMeta->sversion = htonl(pMeta->sversion);
|
||||
pMeta->tversion = htonl(pMeta->tversion);
|
||||
pMeta->tuid = htobe64(pMeta->tuid);
|
||||
pMeta->suid = htobe64(pMeta->suid);
|
||||
|
||||
|
@ -91,7 +87,7 @@ class DndTestUser : public ::testing::Test {
|
|||
|
||||
void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
|
||||
SSchema* pSchema = &pMeta->pSchema[index];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, type);
|
||||
EXPECT_EQ(pSchema->bytes, bytes);
|
||||
|
@ -117,17 +113,14 @@ class DndTestUser : public ::testing::Test {
|
|||
pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
|
||||
ASSERT_NE(pRetrieveRsp, nullptr);
|
||||
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
|
||||
pRetrieveRsp->offset = htobe64(pRetrieveRsp->offset);
|
||||
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
|
||||
pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen);
|
||||
|
||||
EXPECT_EQ(pRetrieveRsp->numOfRows, rows);
|
||||
EXPECT_EQ(pRetrieveRsp->offset, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->useconds, 0);
|
||||
// EXPECT_EQ(pRetrieveRsp->completed, completed);
|
||||
EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
||||
EXPECT_EQ(pRetrieveRsp->compressed, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->reserved, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->compLen, 0);
|
||||
|
||||
pData = pRetrieveRsp->data;
|
||||
|
@ -174,7 +167,7 @@ TEST_F(DndTestUser, 01_ShowUser) {
|
|||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4);
|
||||
CheckSchema(0, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "name");
|
||||
CheckSchema(1, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "privilege");
|
||||
CheckSchema(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create time");
|
||||
CheckSchema(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
CheckSchema(3, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "account");
|
||||
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
|
@ -184,7 +177,7 @@ TEST_F(DndTestUser, 01_ShowUser) {
|
|||
CheckBinary("root", TSDB_USER_LEN);
|
||||
}
|
||||
|
||||
TEST_F(DndTestUser, 02_CreateUser) {
|
||||
TEST_F(DndTestUser, 02_Create_Drop_Alter_User) {
|
||||
{
|
||||
SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(sizeof(SCreateUserMsg));
|
||||
strcpy(pReq->user, "u1");
|
||||
|
@ -231,23 +224,22 @@ TEST_F(DndTestUser, 02_CreateUser) {
|
|||
CheckBinary("root", TSDB_USER_LEN);
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
}
|
||||
|
||||
TEST_F(DndTestUser, 03_AlterUser) {
|
||||
SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(sizeof(SAlterUserMsg));
|
||||
strcpy(pReq->user, "u1");
|
||||
strcpy(pReq->pass, "p2");
|
||||
{
|
||||
SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(sizeof(SAlterUserMsg));
|
||||
strcpy(pReq->user, "u1");
|
||||
strcpy(pReq->pass, "p2");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SAlterUserMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_ALTER_USER;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SAlterUserMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_ALTER_USER;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4);
|
||||
SendThenCheckShowRetrieveMsg(3);
|
||||
CheckBinary("u1", TSDB_USER_LEN);
|
||||
|
@ -262,22 +254,21 @@ TEST_F(DndTestUser, 03_AlterUser) {
|
|||
CheckBinary("root", TSDB_USER_LEN);
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
}
|
||||
|
||||
TEST_F(DndTestUser, 04_DropUser) {
|
||||
SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(sizeof(SDropUserMsg));
|
||||
strcpy(pReq->user, "u1");
|
||||
{
|
||||
SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(sizeof(SDropUserMsg));
|
||||
strcpy(pReq->user, "u1");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SDropUserMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_DROP_USER;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SDropUserMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_DROP_USER;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4);
|
||||
SendThenCheckShowRetrieveMsg(2);
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
|
@ -288,9 +279,8 @@ TEST_F(DndTestUser, 04_DropUser) {
|
|||
CheckTimestamp();
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
}
|
||||
|
||||
TEST_F(DndTestUser, 05_RestartDnode) {
|
||||
// restart
|
||||
stopServer(pServer);
|
||||
pServer = NULL;
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
add_executable(dnode_test_vgroup "")
|
||||
|
||||
target_sources(dnode_test_vgroup
|
||||
PRIVATE
|
||||
"vgroup.cpp"
|
||||
"../sut/deploy.cpp"
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
dnode_test_vgroup
|
||||
PUBLIC dnode
|
||||
PUBLIC util
|
||||
PUBLIC os
|
||||
PUBLIC gtest_main
|
||||
)
|
||||
|
||||
target_include_directories(dnode_test_vgroup
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME dnode_test_vgroup
|
||||
COMMAND dnode_test_vgroup
|
||||
)
|
|
@ -0,0 +1,224 @@
|
|||
/**
|
||||
* @file db.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module vgroup-msg tests
|
||||
* @version 0.1
|
||||
* @date 2021-12-20
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
#include "deploy.h"
|
||||
|
||||
class DndTestVgroup : public ::testing::Test {
|
||||
protected:
|
||||
static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
|
||||
SServer* pServer = createServer(path, fqdn, port, firstEp);
|
||||
ASSERT(pServer);
|
||||
return pServer;
|
||||
}
|
||||
|
||||
static void SetUpTestSuite() {
|
||||
initLog("/tmp/tdlog");
|
||||
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9150";
|
||||
pServer = CreateServer("/tmp/dnode_test_vgroup", fqdn, 9150, firstEp);
|
||||
pClient = createClient("root", "taosdata", fqdn, 9150);
|
||||
taosMsleep(1100);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
stopServer(pServer);
|
||||
dropClient(pClient);
|
||||
pServer = NULL;
|
||||
pClient = NULL;
|
||||
}
|
||||
|
||||
static SServer* pServer;
|
||||
static SClient* pClient;
|
||||
static int32_t connId;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns, const char* db) {
|
||||
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
||||
pShow->type = showType;
|
||||
if (db != NULL) {
|
||||
strcpy(pShow->db, db);
|
||||
}
|
||||
SRpcMsg showRpcMsg = {0};
|
||||
showRpcMsg.pCont = pShow;
|
||||
showRpcMsg.contLen = sizeof(SShowMsg);
|
||||
showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
|
||||
|
||||
sendMsg(pClient, &showRpcMsg);
|
||||
ASSERT_NE(pClient->pRsp, nullptr);
|
||||
ASSERT_EQ(pClient->pRsp->code, 0);
|
||||
ASSERT_NE(pClient->pRsp->pCont, nullptr);
|
||||
|
||||
SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont;
|
||||
ASSERT_NE(pShowRsp, nullptr);
|
||||
pShowRsp->showId = htonl(pShowRsp->showId);
|
||||
pMeta = &pShowRsp->tableMeta;
|
||||
pMeta->numOfTags = htonl(pMeta->numOfTags);
|
||||
pMeta->numOfColumns = htonl(pMeta->numOfColumns);
|
||||
pMeta->sversion = htonl(pMeta->sversion);
|
||||
pMeta->tversion = htonl(pMeta->tversion);
|
||||
pMeta->tuid = htobe64(pMeta->tuid);
|
||||
pMeta->suid = htobe64(pMeta->suid);
|
||||
|
||||
showId = pShowRsp->showId;
|
||||
|
||||
EXPECT_NE(pShowRsp->showId, 0);
|
||||
EXPECT_STREQ(pMeta->tbFname, showName);
|
||||
EXPECT_EQ(pMeta->numOfTags, 0);
|
||||
EXPECT_EQ(pMeta->numOfColumns, columns);
|
||||
EXPECT_EQ(pMeta->precision, 0);
|
||||
EXPECT_EQ(pMeta->tableType, 0);
|
||||
EXPECT_EQ(pMeta->update, 0);
|
||||
EXPECT_EQ(pMeta->sversion, 0);
|
||||
EXPECT_EQ(pMeta->tversion, 0);
|
||||
EXPECT_EQ(pMeta->tuid, 0);
|
||||
EXPECT_EQ(pMeta->suid, 0);
|
||||
}
|
||||
|
||||
void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
|
||||
SSchema* pSchema = &pMeta->pSchema[index];
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, type);
|
||||
EXPECT_EQ(pSchema->bytes, bytes);
|
||||
EXPECT_STREQ(pSchema->name, name);
|
||||
}
|
||||
|
||||
void SendThenCheckShowRetrieveMsg(int32_t rows) {
|
||||
SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
|
||||
pRetrieve->showId = htonl(showId);
|
||||
pRetrieve->free = 0;
|
||||
|
||||
SRpcMsg retrieveRpcMsg = {0};
|
||||
retrieveRpcMsg.pCont = pRetrieve;
|
||||
retrieveRpcMsg.contLen = sizeof(SRetrieveTableMsg);
|
||||
retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
|
||||
|
||||
sendMsg(pClient, &retrieveRpcMsg);
|
||||
|
||||
ASSERT_NE(pClient->pRsp, nullptr);
|
||||
ASSERT_EQ(pClient->pRsp->code, 0);
|
||||
ASSERT_NE(pClient->pRsp->pCont, nullptr);
|
||||
|
||||
pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
|
||||
ASSERT_NE(pRetrieveRsp, nullptr);
|
||||
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
|
||||
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
|
||||
pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen);
|
||||
|
||||
EXPECT_EQ(pRetrieveRsp->numOfRows, rows);
|
||||
EXPECT_EQ(pRetrieveRsp->useconds, 0);
|
||||
// EXPECT_EQ(pRetrieveRsp->completed, completed);
|
||||
EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
||||
EXPECT_EQ(pRetrieveRsp->compressed, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->compLen, 0);
|
||||
|
||||
pData = pRetrieveRsp->data;
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
void CheckInt8(int8_t val) {
|
||||
int8_t data = *((int8_t*)(pData + pos));
|
||||
pos += sizeof(int8_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckInt16(int16_t val) {
|
||||
int16_t data = *((int16_t*)(pData + pos));
|
||||
pos += sizeof(int16_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckInt32(int32_t val) {
|
||||
int32_t data = *((int32_t*)(pData + pos));
|
||||
pos += sizeof(int32_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckInt64(int64_t val) {
|
||||
int64_t data = *((int64_t*)(pData + pos));
|
||||
pos += sizeof(int64_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckTimestamp() {
|
||||
int64_t data = *((int64_t*)(pData + pos));
|
||||
pos += sizeof(int64_t);
|
||||
EXPECT_GT(data, 0);
|
||||
}
|
||||
|
||||
void CheckBinary(const char* val, int32_t len) {
|
||||
pos += sizeof(VarDataLenT);
|
||||
char* data = (char*)(pData + pos);
|
||||
pos += len;
|
||||
EXPECT_STREQ(data, val);
|
||||
}
|
||||
|
||||
int32_t showId;
|
||||
STableMetaMsg* pMeta;
|
||||
SRetrieveTableRsp* pRetrieveRsp;
|
||||
char* pData;
|
||||
int32_t pos;
|
||||
};
|
||||
|
||||
SServer* DndTestVgroup::pServer;
|
||||
SClient* DndTestVgroup::pClient;
|
||||
int32_t DndTestVgroup::connId;
|
||||
|
||||
|
||||
TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) {
|
||||
{
|
||||
SCreateVnodeMsg* pReq = (SCreateVnodeMsg*)rpcMallocCont(sizeof(SCreateVnodeMsg));
|
||||
pReq->vgId = htonl(2);
|
||||
pReq->dnodeId = htonl(1);
|
||||
strcpy(pReq->db, "1.d1");
|
||||
pReq->dbUid = htobe64(9527);
|
||||
pReq->cacheBlockSize = htonl(16);
|
||||
pReq->totalBlocks = htonl(10);
|
||||
pReq->daysPerFile = htonl(10);
|
||||
pReq->daysToKeep0 = htonl(3650);
|
||||
pReq->daysToKeep1 = htonl(3650);
|
||||
pReq->daysToKeep2 = htonl(3650);
|
||||
pReq->minRows = htonl(100);
|
||||
pReq->minRows = htonl(4096);
|
||||
pReq->commitTime = htonl(3600);
|
||||
pReq->fsyncPeriod = htonl(3000);
|
||||
pReq->walLevel = 1;
|
||||
pReq->precision = 0;
|
||||
pReq->compression = 2;
|
||||
pReq->replica = 1;
|
||||
pReq->quorum = 1;
|
||||
pReq->update = 0;
|
||||
pReq->cacheLastRow = 0;
|
||||
pReq->selfIndex = 0;
|
||||
for (int r = 0; r < pReq->replica; ++r) {
|
||||
SReplica* pReplica = &pReq->replicas[r];
|
||||
pReplica->id = htonl(1);
|
||||
pReplica->port = htons(9150);
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SCreateVnodeMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_VNODE_IN;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
taosMsleep(1000000);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -42,13 +42,6 @@ extern int32_t mDebugFlag;
|
|||
#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
|
||||
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
|
||||
|
||||
typedef struct SClusterObj SClusterObj;
|
||||
typedef struct SMnodeObj SMnodeObj;
|
||||
typedef struct SAcctObj SAcctObj;
|
||||
typedef struct SVgObj SVgObj;
|
||||
typedef struct SFuncObj SFuncObj;
|
||||
typedef struct SOperObj SOperObj;
|
||||
|
||||
typedef enum {
|
||||
MND_AUTH_ACCT_START = 0,
|
||||
MND_AUTH_ACCT_USER,
|
||||
|
@ -99,7 +92,7 @@ typedef enum {
|
|||
DND_REASON_OTHERS
|
||||
} EDndReason;
|
||||
|
||||
typedef struct STrans {
|
||||
typedef struct {
|
||||
int32_t id;
|
||||
ETrnStage stage;
|
||||
ETrnPolicy policy;
|
||||
|
@ -111,7 +104,7 @@ typedef struct STrans {
|
|||
SArray *undoActions;
|
||||
} STrans;
|
||||
|
||||
typedef struct SClusterObj {
|
||||
typedef struct {
|
||||
int32_t id;
|
||||
char name[TSDB_CLUSTER_ID_LEN];
|
||||
int64_t createdTime;
|
||||
|
@ -139,7 +132,7 @@ typedef struct {
|
|||
char ep[TSDB_EP_LEN];
|
||||
} SDnodeObj;
|
||||
|
||||
typedef struct SMnodeObj {
|
||||
typedef struct {
|
||||
int32_t id;
|
||||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
|
@ -167,7 +160,7 @@ typedef struct {
|
|||
int64_t compStorage; // Compressed storage on disk
|
||||
} SAcctInfo;
|
||||
|
||||
typedef struct SAcctObj {
|
||||
typedef struct {
|
||||
char acct[TSDB_USER_LEN];
|
||||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
|
@ -189,14 +182,15 @@ typedef struct {
|
|||
} SUserObj;
|
||||
|
||||
typedef struct {
|
||||
int32_t numOfVgroups;
|
||||
int32_t cacheBlockSize;
|
||||
int32_t totalBlocks;
|
||||
int32_t daysPerFile;
|
||||
int32_t daysToKeep0;
|
||||
int32_t daysToKeep1;
|
||||
int32_t daysToKeep2;
|
||||
int32_t minRowsPerFileBlock;
|
||||
int32_t maxRowsPerFileBlock;
|
||||
int32_t minRows;
|
||||
int32_t maxRows;
|
||||
int32_t commitTime;
|
||||
int32_t fsyncPeriod;
|
||||
int8_t walLevel;
|
||||
|
@ -214,7 +208,9 @@ typedef struct {
|
|||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
int64_t uid;
|
||||
int32_t version;
|
||||
int32_t cfgVersion;
|
||||
int32_t vgVersion;
|
||||
int8_t hashMethod; // default is 1
|
||||
SDbCfg cfg;
|
||||
} SDbObj;
|
||||
|
||||
|
@ -223,12 +219,15 @@ typedef struct {
|
|||
ESyncState role;
|
||||
} SVnodeGid;
|
||||
|
||||
typedef struct SVgObj {
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
int32_t version;
|
||||
uint32_t hashBegin;
|
||||
uint32_t hashEnd;
|
||||
char dbName[TSDB_FULL_DB_NAME_LEN];
|
||||
int64_t dbUid;
|
||||
int32_t numOfTables;
|
||||
int32_t numOfTimeSeries;
|
||||
int64_t totalStorage;
|
||||
|
@ -245,6 +244,7 @@ typedef struct {
|
|||
int64_t createdTime;
|
||||
int64_t updateTime;
|
||||
uint64_t uid;
|
||||
uint64_t dbUid;
|
||||
int32_t version;
|
||||
int32_t numOfColumns;
|
||||
int32_t numOfTags;
|
||||
|
@ -252,7 +252,7 @@ typedef struct {
|
|||
SSchema *pSchema;
|
||||
} SStbObj;
|
||||
|
||||
typedef struct SFuncObj {
|
||||
typedef struct {
|
||||
char name[TSDB_FUNC_NAME_LEN];
|
||||
int64_t createdTime;
|
||||
int8_t funcType;
|
||||
|
|
|
@ -28,6 +28,7 @@ SDnodeObj *mndAcquireDnode(SMnode *pMnode, int32_t dnodeId);
|
|||
void mndReleaseDnode(SMnode *pMnode, SDnodeObj *pDnode);
|
||||
SEpSet mndGetDnodeEpset(SDnodeObj *pDnode);
|
||||
int32_t mndGetDnodeSize(SMnode *pMnode);
|
||||
bool mndIsDnodeInReadyStatus(SMnode *pMnode, SDnodeObj *pDnode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -30,8 +30,8 @@ void mndTransDrop(STrans *pTrans);
|
|||
int32_t mndTransAppendRedolog(STrans *pTrans, SSdbRaw *pRaw);
|
||||
int32_t mndTransAppendUndolog(STrans *pTrans, SSdbRaw *pRaw);
|
||||
int32_t mndTransAppendCommitlog(STrans *pTrans, SSdbRaw *pRaw);
|
||||
int32_t mndTransAppendRedoAction(STrans *pTrans, SEpSet *, void *pMsg);
|
||||
int32_t mndTransAppendUndoAction(STrans *pTrans, SEpSet *, void *pMsg);
|
||||
int32_t mndTransAppendRedoAction(STrans *pTrans, SEpSet *pEpSet, int8_t msgType, int32_t contLen, void *pCont);
|
||||
int32_t mndTransAppendUndoAction(STrans *pTrans, SEpSet *pEpSet, int8_t msgType, int32_t contLen, void *pCont);
|
||||
int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans);
|
||||
void mndTransApply(SMnode *pMnode, SSdbRaw *pRaw, STransMsg *pMsg, int32_t code);
|
||||
char *mndTransStageStr(ETrnStage stage);
|
||||
|
|
|
@ -22,10 +22,15 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mndInitVgroup(SMnode *pMnode);
|
||||
void mndCleanupVgroup(SMnode *pMnode);
|
||||
SVgObj *mndAcquireVgroup(SMnode *pMnode, int32_t vgId);
|
||||
void mndReleaseVgroup(SMnode *pMnode, SVgObj *pVgroup);
|
||||
int32_t mndInitVgroup(SMnode *pMnode);
|
||||
void mndCleanupVgroup(SMnode *pMnode);
|
||||
SVgObj *mndAcquireVgroup(SMnode *pMnode, int32_t vgId);
|
||||
void mndReleaseVgroup(SMnode *pMnode, SVgObj *pVgroup);
|
||||
int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups);
|
||||
SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup);
|
||||
|
||||
SCreateVnodeMsg *mndBuildCreateVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup);
|
||||
SDropVnodeMsg *mndBuildDropVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -143,22 +143,22 @@ static int32_t mndGetClusterMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg
|
|||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "id");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "name");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "create_time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pMeta->numOfColumns = htons(cols);
|
||||
pMeta->numOfColumns = htonl(cols);
|
||||
strcpy(pMeta->tbFname, mndShowStr(pShow->type));
|
||||
pShow->numOfColumns = cols;
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "mndShow.h"
|
||||
#include "mndTrans.h"
|
||||
#include "mndUser.h"
|
||||
#include "mndVgroup.h"
|
||||
|
||||
#define TSDB_DB_VER_NUM 1
|
||||
#define TSDB_DB_RESERVE_SIZE 64
|
||||
|
@ -74,15 +75,18 @@ static SSdbRaw *mndDbActionEncode(SDbObj *pDb) {
|
|||
SDB_SET_INT64(pRaw, dataPos, pDb->createdTime)
|
||||
SDB_SET_INT64(pRaw, dataPos, pDb->updateTime)
|
||||
SDB_SET_INT64(pRaw, dataPos, pDb->uid)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->version)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfgVersion)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->vgVersion)
|
||||
SDB_SET_INT8(pRaw, dataPos, pDb->hashMethod)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.numOfVgroups)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.cacheBlockSize)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.totalBlocks)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysPerFile)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep0)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep1)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep2)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.minRowsPerFileBlock)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.maxRowsPerFileBlock)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.minRows)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.maxRows)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.commitTime)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.fsyncPeriod)
|
||||
SDB_SET_INT8(pRaw, dataPos, pDb->cfg.walLevel)
|
||||
|
@ -118,15 +122,18 @@ static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) {
|
|||
SDB_GET_INT64(pRaw, pRow, dataPos, &pDb->createdTime)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pDb->updateTime)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pDb->uid)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->version)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfgVersion)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->vgVersion)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->hashMethod)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.numOfVgroups)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.cacheBlockSize)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.totalBlocks)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.daysPerFile)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.daysToKeep0)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.daysToKeep1)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.daysToKeep2)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.minRowsPerFileBlock)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.maxRowsPerFileBlock)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.minRows)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.maxRows)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.commitTime)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.fsyncPeriod)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->cfg.walLevel)
|
||||
|
@ -154,6 +161,8 @@ static int32_t mndDbActionDelete(SSdb *pSdb, SDbObj *pDb) {
|
|||
static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOldDb, SDbObj *pNewDb) {
|
||||
mTrace("db:%s, perform update action", pOldDb->name);
|
||||
pOldDb->updateTime = pNewDb->createdTime;
|
||||
pOldDb->cfgVersion = pNewDb->cfgVersion;
|
||||
pOldDb->vgVersion = pNewDb->vgVersion;
|
||||
memcpy(&pOldDb->cfg, &pNewDb->cfg, sizeof(SDbCfg));
|
||||
return 0;
|
||||
}
|
||||
|
@ -184,145 +193,44 @@ static int32_t mndCheckDbName(char *dbName, SUserObj *pUser) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg, char *errMsg, int32_t len) {
|
||||
if (pCfg->cacheBlockSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCfg->cacheBlockSize > TSDB_MAX_CACHE_BLOCK_SIZE) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database cache block size option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->totalBlocks < TSDB_MIN_TOTAL_BLOCKS || pCfg->totalBlocks > TSDB_MAX_TOTAL_BLOCKS) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database total blocks option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->daysPerFile < TSDB_MIN_DAYS_PER_FILE || pCfg->daysPerFile > TSDB_MAX_DAYS_PER_FILE) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database days option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->daysToKeep0 < pCfg->daysPerFile) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database days option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->daysToKeep0 < TSDB_MIN_KEEP || pCfg->daysToKeep0 > TSDB_MAX_KEEP || pCfg->daysToKeep0 > pCfg->daysToKeep1) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database keep0 option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->daysToKeep1 < TSDB_MIN_KEEP || pCfg->daysToKeep1 > TSDB_MAX_KEEP || pCfg->daysToKeep1 > pCfg->daysToKeep2) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database keep1 option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->daysToKeep2 < TSDB_MIN_KEEP || pCfg->daysToKeep2 > TSDB_MAX_KEEP) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database keep2 option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->minRowsPerFileBlock < TSDB_MIN_MIN_ROW_FBLOCK || pCfg->minRowsPerFileBlock > TSDB_MAX_MIN_ROW_FBLOCK) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database minrows option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->maxRowsPerFileBlock < TSDB_MIN_MAX_ROW_FBLOCK || pCfg->maxRowsPerFileBlock > TSDB_MAX_MAX_ROW_FBLOCK) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database maxrows option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->minRowsPerFileBlock > pCfg->maxRowsPerFileBlock) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database minrows option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->commitTime < TSDB_MIN_COMMIT_TIME || pCfg->commitTime > TSDB_MAX_COMMIT_TIME) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database commit option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->fsyncPeriod < TSDB_MIN_FSYNC_PERIOD || pCfg->fsyncPeriod > TSDB_MAX_FSYNC_PERIOD) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database fsync option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->walLevel < TSDB_MIN_WAL_LEVEL || pCfg->walLevel > TSDB_MAX_WAL_LEVEL) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database wal level option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->precision < TSDB_MIN_PRECISION && pCfg->precision > TSDB_MAX_PRECISION) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid precision option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->compression < TSDB_MIN_COMP_LEVEL || pCfg->compression > TSDB_MAX_COMP_LEVEL) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database compression option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->replications < TSDB_MIN_DB_REPLICA_OPTION || pCfg->replications > TSDB_MAX_DB_REPLICA_OPTION) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database replication option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->replications > mndGetDnodeSize(pMnode)) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database replication option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->quorum < TSDB_MIN_DB_QUORUM_OPTION || pCfg->quorum > TSDB_MAX_DB_QUORUM_OPTION) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database quorum option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->quorum > pCfg->replications) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database quorum option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->update < TSDB_MIN_DB_UPDATE || pCfg->update > TSDB_MAX_DB_UPDATE) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database update option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCfg->cacheLastRow < TSDB_MIN_DB_CACHE_LAST_ROW || pCfg->cacheLastRow > TSDB_MAX_DB_CACHE_LAST_ROW) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
tstrncpy(errMsg, "Invalid database cachelast option", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
|
||||
if (pCfg->numOfVgroups < TSDB_MIN_VNODES_PER_DB || pCfg->numOfVgroups > TSDB_MAX_VNODES_PER_DB) return -1;
|
||||
if (pCfg->cacheBlockSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCfg->cacheBlockSize > TSDB_MAX_CACHE_BLOCK_SIZE) return -1;
|
||||
if (pCfg->totalBlocks < TSDB_MIN_TOTAL_BLOCKS || pCfg->totalBlocks > TSDB_MAX_TOTAL_BLOCKS) return -1;
|
||||
if (pCfg->daysPerFile < TSDB_MIN_DAYS_PER_FILE || pCfg->daysPerFile > TSDB_MAX_DAYS_PER_FILE) return -1;
|
||||
if (pCfg->daysToKeep0 < pCfg->daysPerFile) return -1;
|
||||
if (pCfg->daysToKeep0 < TSDB_MIN_KEEP || pCfg->daysToKeep0 > TSDB_MAX_KEEP) return -1;
|
||||
if (pCfg->daysToKeep1 < TSDB_MIN_KEEP || pCfg->daysToKeep1 > TSDB_MAX_KEEP) return -1;
|
||||
if (pCfg->daysToKeep2 < TSDB_MIN_KEEP || pCfg->daysToKeep2 > TSDB_MAX_KEEP) return -1;
|
||||
if (pCfg->daysToKeep0 > pCfg->daysToKeep1) return -1;
|
||||
if (pCfg->daysToKeep1 > pCfg->daysToKeep2) return -1;
|
||||
if (pCfg->minRows < TSDB_MIN_MIN_ROW_FBLOCK || pCfg->minRows > TSDB_MAX_MIN_ROW_FBLOCK) return -1;
|
||||
if (pCfg->maxRows < TSDB_MIN_MAX_ROW_FBLOCK || pCfg->maxRows > TSDB_MAX_MAX_ROW_FBLOCK) return -1;
|
||||
if (pCfg->minRows > pCfg->maxRows) return -1;
|
||||
if (pCfg->commitTime < TSDB_MIN_COMMIT_TIME || pCfg->commitTime > TSDB_MAX_COMMIT_TIME) return -1;
|
||||
if (pCfg->fsyncPeriod < TSDB_MIN_FSYNC_PERIOD || pCfg->fsyncPeriod > TSDB_MAX_FSYNC_PERIOD) return -1;
|
||||
if (pCfg->walLevel < TSDB_MIN_WAL_LEVEL || pCfg->walLevel > TSDB_MAX_WAL_LEVEL) return -1;
|
||||
if (pCfg->precision < TSDB_MIN_PRECISION && pCfg->precision > TSDB_MAX_PRECISION) return -1;
|
||||
if (pCfg->compression < TSDB_MIN_COMP_LEVEL || pCfg->compression > TSDB_MAX_COMP_LEVEL) return -1;
|
||||
if (pCfg->replications < TSDB_MIN_DB_REPLICA_OPTION || pCfg->replications > TSDB_MAX_DB_REPLICA_OPTION) return -1;
|
||||
if (pCfg->replications > mndGetDnodeSize(pMnode)) return -1;
|
||||
if (pCfg->quorum < TSDB_MIN_DB_QUORUM_OPTION || pCfg->quorum > TSDB_MAX_DB_QUORUM_OPTION) return -1;
|
||||
if (pCfg->quorum > pCfg->replications) return -1;
|
||||
if (pCfg->update < TSDB_MIN_DB_UPDATE || pCfg->update > TSDB_MAX_DB_UPDATE) return -1;
|
||||
if (pCfg->cacheLastRow < TSDB_MIN_DB_CACHE_LAST_ROW || pCfg->cacheLastRow > TSDB_MAX_DB_CACHE_LAST_ROW) return -1;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void mndSetDefaultDbCfg(SDbCfg *pCfg) {
|
||||
if (pCfg->numOfVgroups < 0) pCfg->numOfVgroups = TSDB_DEFAULT_VN_PER_DB;
|
||||
if (pCfg->cacheBlockSize < 0) pCfg->cacheBlockSize = TSDB_DEFAULT_CACHE_BLOCK_SIZE;
|
||||
if (pCfg->totalBlocks < 0) pCfg->totalBlocks = TSDB_DEFAULT_TOTAL_BLOCKS;
|
||||
if (pCfg->daysPerFile < 0) pCfg->daysPerFile = TSDB_DEFAULT_DAYS_PER_FILE;
|
||||
if (pCfg->daysToKeep0 < 0) pCfg->daysToKeep0 = TSDB_DEFAULT_KEEP;
|
||||
if (pCfg->daysToKeep1 < 0) pCfg->daysToKeep1 = TSDB_DEFAULT_KEEP;
|
||||
if (pCfg->daysToKeep2 < 0) pCfg->daysToKeep2 = TSDB_DEFAULT_KEEP;
|
||||
if (pCfg->minRowsPerFileBlock < 0) pCfg->minRowsPerFileBlock = TSDB_DEFAULT_MIN_ROW_FBLOCK;
|
||||
if (pCfg->maxRowsPerFileBlock < 0) pCfg->maxRowsPerFileBlock = TSDB_DEFAULT_MAX_ROW_FBLOCK;
|
||||
if (pCfg->minRows < 0) pCfg->minRows = TSDB_DEFAULT_MIN_ROW_FBLOCK;
|
||||
if (pCfg->maxRows < 0) pCfg->maxRows = TSDB_DEFAULT_MAX_ROW_FBLOCK;
|
||||
if (pCfg->commitTime < 0) pCfg->commitTime = TSDB_DEFAULT_COMMIT_TIME;
|
||||
if (pCfg->fsyncPeriod < 0) pCfg->fsyncPeriod = TSDB_DEFAULT_FSYNC_PERIOD;
|
||||
if (pCfg->walLevel < 0) pCfg->walLevel = TSDB_DEFAULT_WAL_LEVEL;
|
||||
|
@ -334,6 +242,106 @@ static void mndSetDefaultDbCfg(SDbCfg *pCfg) {
|
|||
if (pCfg->cacheLastRow < 0) pCfg->cacheLastRow = TSDB_DEFAULT_CACHE_LAST_ROW;
|
||||
}
|
||||
|
||||
static int32_t mndSetRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) {
|
||||
SSdbRaw *pDbRaw = mndDbActionEncode(pDb);
|
||||
if (pDbRaw == NULL || mndTransAppendRedolog(pTrans, pDbRaw) != 0) return -1;
|
||||
sdbSetRawStatus(pDbRaw, SDB_STATUS_CREATING);
|
||||
|
||||
for (int v = 0; v < pDb->cfg.numOfVgroups; ++v) {
|
||||
SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v);
|
||||
if (pVgRaw == NULL || mndTransAppendRedolog(pTrans, pVgRaw) != 0) return -1;
|
||||
sdbSetRawStatus(pVgRaw, SDB_STATUS_CREATING);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetUndoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) {
|
||||
SSdbRaw *pDbRaw = mndDbActionEncode(pDb);
|
||||
if (pDbRaw == NULL || mndTransAppendUndolog(pTrans, pDbRaw) != 0) return -1;
|
||||
sdbSetRawStatus(pDbRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
for (int v = 0; v < pDb->cfg.numOfVgroups; ++v) {
|
||||
SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v);
|
||||
if (pVgRaw == NULL || mndTransAppendUndolog(pTrans, pVgRaw) != 0) return -1;
|
||||
sdbSetRawStatus(pVgRaw, SDB_STATUS_DROPPED);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) {
|
||||
SSdbRaw *pDbRaw = mndDbActionEncode(pDb);
|
||||
if (pDbRaw == NULL || mndTransAppendCommitlog(pTrans, pDbRaw) != 0) return -1;
|
||||
sdbSetRawStatus(pDbRaw, SDB_STATUS_READY);
|
||||
|
||||
for (int v = 0; v < pDb->cfg.numOfVgroups; ++v) {
|
||||
SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v);
|
||||
if (pVgRaw == NULL || mndTransAppendCommitlog(pTrans, pVgRaw) != 0) return -1;
|
||||
sdbSetRawStatus(pVgRaw, SDB_STATUS_READY);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) {
|
||||
for (int v = 0; v < pDb->cfg.numOfVgroups; ++v) {
|
||||
SVgObj *pVgroup = pVgroups + v;
|
||||
|
||||
for (int32_t vn = 0; vn < pVgroup->replica; ++vn) {
|
||||
SVnodeGid *pVgid = pVgroup->vnodeGid + vn;
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pDnode == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SEpSet epset = mndGetDnodeEpset(pDnode);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
SCreateVnodeMsg *pMsg = mndBuildCreateVnodeMsg(pMnode, pDnode, pDb, pVgroup);
|
||||
if (pMsg == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &epset, TSDB_MSG_TYPE_ALTER_VNODE_IN, sizeof(SCreateVnodeMsg), pMsg) != 0) {
|
||||
free(pMsg);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) {
|
||||
for (int v = 0; v < pDb->cfg.numOfVgroups; ++v) {
|
||||
SVgObj *pVgroup = pVgroups + v;
|
||||
|
||||
for (int32_t vn = 0; vn < pVgroup->replica; ++vn) {
|
||||
SVnodeGid *pVgid = pVgroup->vnodeGid + vn;
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pDnode == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SEpSet epset = mndGetDnodeEpset(pDnode);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
SDropVnodeMsg *pMsg = mndBuildDropVnodeMsg(pMnode, pDnode, pDb, pVgroup);
|
||||
if (pMsg == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mndTransAppendUndoAction(pTrans, &epset, TSDB_MSG_TYPE_DROP_VNODE_IN, sizeof(SDropVnodeMsg), pMsg) != 0) {
|
||||
free(pMsg);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndCreateDb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDbMsg *pCreate, SUserObj *pUser) {
|
||||
SDbObj dbObj = {0};
|
||||
tstrncpy(dbObj.name, pCreate->db, TSDB_FULL_DB_NAME_LEN);
|
||||
|
@ -341,14 +349,18 @@ static int32_t mndCreateDb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDbMsg *pCreat
|
|||
dbObj.createdTime = taosGetTimestampMs();
|
||||
dbObj.updateTime = dbObj.createdTime;
|
||||
dbObj.uid = mndGenerateUid(dbObj.name, TSDB_FULL_DB_NAME_LEN);
|
||||
dbObj.cfg = (SDbCfg){.cacheBlockSize = pCreate->cacheBlockSize,
|
||||
dbObj.hashMethod = 1;
|
||||
dbObj.cfgVersion = 1;
|
||||
dbObj.vgVersion = 1;
|
||||
dbObj.cfg = (SDbCfg){.numOfVgroups = pCreate->numOfVgroups,
|
||||
.cacheBlockSize = pCreate->cacheBlockSize,
|
||||
.totalBlocks = pCreate->totalBlocks,
|
||||
.daysPerFile = pCreate->daysPerFile,
|
||||
.daysToKeep0 = pCreate->daysToKeep0,
|
||||
.daysToKeep1 = pCreate->daysToKeep1,
|
||||
.daysToKeep2 = pCreate->daysToKeep2,
|
||||
.minRowsPerFileBlock = pCreate->minRowsPerFileBlock,
|
||||
.maxRowsPerFileBlock = pCreate->maxRowsPerFileBlock,
|
||||
.minRows = pCreate->minRowsPerFileBlock,
|
||||
.maxRows = pCreate->maxRowsPerFileBlock,
|
||||
.fsyncPeriod = pCreate->fsyncPeriod,
|
||||
.commitTime = pCreate->commitTime,
|
||||
.precision = pCreate->precision,
|
||||
|
@ -366,57 +378,69 @@ static int32_t mndCreateDb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDbMsg *pCreat
|
|||
return -1;
|
||||
}
|
||||
|
||||
char errMsg[TSDB_ERROR_MSG_LEN] = {0};
|
||||
if (mndCheckDbCfg(pMnode, &dbObj.cfg, errMsg, TSDB_ERROR_MSG_LEN) != 0) {
|
||||
if (mndCheckDbCfg(pMnode, &dbObj.cfg) != 0) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
mError("db:%s, failed to create since %s", pCreate->db, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SVgObj *pVgroups = NULL;
|
||||
if (mndAllocVgroup(pMnode, &dbObj, &pVgroups) != 0) {
|
||||
mError("db:%s, failed to create since %s", pCreate->db, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = -1;
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle);
|
||||
if (pTrans == NULL) {
|
||||
mError("db:%s, failed to create since %s", pCreate->db, terrstr());
|
||||
return -1;
|
||||
goto CREATE_DB_OVER;
|
||||
}
|
||||
mDebug("trans:%d, used to create db:%s", pTrans->id, pCreate->db);
|
||||
|
||||
SSdbRaw *pRedoRaw = mndDbActionEncode(&dbObj);
|
||||
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) {
|
||||
mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
if (mndSetRedoLogs(pMnode, pTrans, &dbObj, pVgroups) != 0) {
|
||||
mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr());
|
||||
goto CREATE_DB_OVER;
|
||||
}
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING);
|
||||
|
||||
SSdbRaw *pUndoRaw = mndDbActionEncode(&dbObj);
|
||||
if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) {
|
||||
mError("trans:%d, failed to append undo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
if (mndSetUndoLogs(pMnode, pTrans, &dbObj, pVgroups) != 0) {
|
||||
mError("trans:%d, failed to set undo log since %s", pTrans->id, terrstr());
|
||||
goto CREATE_DB_OVER;
|
||||
}
|
||||
sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
SSdbRaw *pCommitRaw = mndDbActionEncode(&dbObj);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
if (mndSetCommitLogs(pMnode, pTrans, &dbObj, pVgroups) != 0) {
|
||||
mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr());
|
||||
goto CREATE_DB_OVER;
|
||||
}
|
||||
|
||||
if (mndSetRedoActions(pMnode, pTrans, &dbObj, pVgroups) != 0) {
|
||||
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||
goto CREATE_DB_OVER;
|
||||
}
|
||||
|
||||
if (mndSetUndoActions(pMnode, pTrans, &dbObj, pVgroups) != 0) {
|
||||
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||
goto CREATE_DB_OVER;
|
||||
}
|
||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
goto CREATE_DB_OVER;
|
||||
}
|
||||
|
||||
code = 0;
|
||||
|
||||
CREATE_DB_OVER:
|
||||
free(pVgroups);
|
||||
mndTransDrop(pTrans);
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateDbMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SCreateDbMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||
|
||||
pCreate->numOfVgroups = htonl(pCreate->numOfVgroups);
|
||||
pCreate->cacheBlockSize = htonl(pCreate->cacheBlockSize);
|
||||
pCreate->totalBlocks = htonl(pCreate->totalBlocks);
|
||||
pCreate->daysPerFile = htonl(pCreate->daysPerFile);
|
||||
|
@ -573,7 +597,8 @@ static int32_t mndProcessAlterDbMsg(SMnodeMsg *pMsg) {
|
|||
return code;
|
||||
}
|
||||
|
||||
dbObj.version++;
|
||||
dbObj.cfgVersion++;
|
||||
dbObj.updateTime = taosGetTimestampMs();
|
||||
code = mndUpdateDb(pMnode, pMsg, pDb, &dbObj);
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
|
||||
|
@ -658,17 +683,69 @@ static int32_t mndProcessDropDbMsg(SMnodeMsg *pMsg) {
|
|||
|
||||
static int32_t mndProcessUseDbMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SUseDbMsg *pUse = pMsg->rpcMsg.pCont;
|
||||
pUse->vgVersion = htonl(pUse->vgVersion);
|
||||
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, pMsg->db);
|
||||
if (pDb != NULL) {
|
||||
strncpy(pMsg->db, pUse->db, TSDB_FULL_DB_NAME_LEN);
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
return 0;
|
||||
} else {
|
||||
mError("db:%s, failed to process use db msg since %s", pMsg->db, terrstr());
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, pUse->db);
|
||||
if (pDb == NULL) {
|
||||
terrno = TSDB_CODE_MND_DB_NOT_EXIST;
|
||||
mError("db:%s, failed to process use db msg since %s", pUse->db, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t contLen = sizeof(SUseDbRsp) + pDb->cfg.numOfVgroups * sizeof(SVgroupInfo);
|
||||
SUseDbRsp *pRsp = rpcMallocCont(contLen);
|
||||
if (pRsp == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t vindex = 0;
|
||||
|
||||
if (pUse->vgVersion < pDb->vgVersion) {
|
||||
void *pIter = NULL;
|
||||
while (vindex < pDb->cfg.numOfVgroups) {
|
||||
SVgObj *pVgroup = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
if (pVgroup->dbUid == pDb->uid) {
|
||||
SVgroupInfo *pInfo = &pRsp->vgroupInfo[vindex];
|
||||
pInfo->vgId = htonl(pVgroup->vgId);
|
||||
pInfo->hashBegin = htonl(pVgroup->hashBegin);
|
||||
pInfo->hashEnd = htonl(pVgroup->hashEnd);
|
||||
pInfo->numOfEps = pVgroup->replica;
|
||||
for (int32_t gid = 0; gid < pVgroup->replica; ++gid) {
|
||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[gid];
|
||||
SEpAddrMsg *pEpArrr = &pInfo->epAddr[gid];
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pDnode != NULL) {
|
||||
memcpy(pEpArrr->fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
||||
pEpArrr->port = htons(pDnode->port);
|
||||
}
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
if (pVgid->role == TAOS_SYNC_STATE_LEADER) {
|
||||
pInfo->inUse = gid;
|
||||
}
|
||||
}
|
||||
vindex++;
|
||||
}
|
||||
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(pRsp->db, pDb->name, TSDB_FULL_DB_NAME_LEN);
|
||||
pRsp->vgVersion = htonl(pDb->vgVersion);
|
||||
pRsp->vgNum = htonl(vindex);
|
||||
pRsp->hashMethod = pDb->hashMethod;
|
||||
|
||||
pMsg->pCont = pRsp;
|
||||
pMsg->contLen = contLen;
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessSyncDbMsg(SMnodeMsg *pMsg) {
|
||||
|
@ -709,100 +786,106 @@ static int32_t mndGetDbMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMe
|
|||
pShow->bytes[cols] = (TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "name");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "create time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
strcpy(pSchema[cols].name, "create_time");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 2;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
|
||||
strcpy(pSchema[cols].name, "vgroups");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 2;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
|
||||
strcpy(pSchema[cols].name, "replica");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 2;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
|
||||
strcpy(pSchema[cols].name, "quorum");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 2;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
|
||||
strcpy(pSchema[cols].name, "days");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 24 + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "keep0,keep1,keep2");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "cache(MB)");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
strcpy(pSchema[cols].name, "cache");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "blocks");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "minrows");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "maxrows");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 1;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TINYINT;
|
||||
strcpy(pSchema[cols].name, "wallevel");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "fsync");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 1;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TINYINT;
|
||||
strcpy(pSchema[cols].name, "comp");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 1;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TINYINT;
|
||||
strcpy(pSchema[cols].name, "cachelast");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 3 + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "precision");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 1;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TINYINT;
|
||||
strcpy(pSchema[cols].name, "update");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pMeta->numOfColumns = htons(cols);
|
||||
pMeta->numOfColumns = htonl(cols);
|
||||
pShow->numOfColumns = cols;
|
||||
|
||||
pShow->offset[0] = 0;
|
||||
|
@ -855,6 +938,10 @@ static int32_t mndRetrieveDbs(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3
|
|||
*(int64_t *)pWrite = pDb->createdTime;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int16_t *)pWrite = pDb->cfg.numOfVgroups;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int16_t *)pWrite = pDb->cfg.replications;
|
||||
cols++;
|
||||
|
@ -886,11 +973,11 @@ static int32_t mndRetrieveDbs(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3
|
|||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int32_t *)pWrite = pDb->cfg.minRowsPerFileBlock;
|
||||
*(int32_t *)pWrite = pDb->cfg.minRows;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int32_t *)pWrite = pDb->cfg.maxRowsPerFileBlock;
|
||||
*(int32_t *)pWrite = pDb->cfg.maxRows;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
|
|
|
@ -180,8 +180,12 @@ static int32_t mndDnodeActionUpdate(SSdb *pSdb, SDnodeObj *pOldDnode, SDnodeObj
|
|||
}
|
||||
|
||||
SDnodeObj *mndAcquireDnode(SMnode *pMnode, int32_t dnodeId) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
return sdbAcquire(pSdb, SDB_DNODE, &dnodeId);
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SDnodeObj *pDnode = sdbAcquire(pSdb, SDB_DNODE, &dnodeId);
|
||||
if (pDnode == NULL) {
|
||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
}
|
||||
return pDnode;
|
||||
}
|
||||
|
||||
void mndReleaseDnode(SMnode *pMnode, SDnodeObj *pDnode) {
|
||||
|
@ -218,6 +222,15 @@ int32_t mndGetDnodeSize(SMnode *pMnode) {
|
|||
return sdbGetSize(pSdb, SDB_DNODE);
|
||||
}
|
||||
|
||||
bool mndIsDnodeInReadyStatus(SMnode *pMnode, SDnodeObj *pDnode) {
|
||||
int64_t ms = taosGetTimestampMs();
|
||||
int64_t interval = ABS(pDnode->lastAccessTime - ms);
|
||||
if (interval > 3000 * pMnode->cfg.statusInterval) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void mndGetDnodeData(SMnode *pMnode, SDnodeEps *pEps, int32_t numOfEps) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
|
@ -552,16 +565,16 @@ static int32_t mndGetConfigMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg
|
|||
pShow->bytes[cols] = TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
tstrncpy(pSchema[cols].name, "name", sizeof(pSchema[cols].name));
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_CONIIG_VALUE_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
tstrncpy(pSchema[cols].name, "value", sizeof(pSchema[cols].name));
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pMeta->numOfColumns = htons(cols);
|
||||
pMeta->numOfColumns = htonl(cols);
|
||||
pShow->numOfColumns = cols;
|
||||
|
||||
pShow->offset[0] = 0;
|
||||
|
@ -629,46 +642,46 @@ static int32_t mndGetDnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
|
|||
pShow->bytes[cols] = 2;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
|
||||
strcpy(pSchema[cols].name, "id");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_EP_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "end point");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
strcpy(pSchema[cols].name, "endpoint");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 2;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
|
||||
strcpy(pSchema[cols].name, "vnodes");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 2;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
|
||||
strcpy(pSchema[cols].name, "max vnodes");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
strcpy(pSchema[cols].name, "max_vnodes");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 10 + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "status");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "create time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
strcpy(pSchema[cols].name, "create_time");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 24 + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "offline reason");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
strcpy(pSchema[cols].name, "offline_reason");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pMeta->numOfColumns = htons(cols);
|
||||
pMeta->numOfColumns = htonl(cols);
|
||||
pShow->numOfColumns = cols;
|
||||
|
||||
pShow->offset[0] = 0;
|
||||
|
|
|
@ -380,46 +380,46 @@ static int32_t mndGetFuncMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *p
|
|||
pShow->bytes[cols] = TSDB_FUNC_NAME_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "name");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = PATH_MAX + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "comment");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "aggregate");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_TYPE_STR_MAX_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "outputtype");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "create_time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "code_len");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "bufsize");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pMeta->numOfColumns = htons(cols);
|
||||
pMeta->numOfColumns = htonl(cols);
|
||||
pShow->numOfColumns = cols;
|
||||
|
||||
pShow->offset[0] = 0;
|
||||
|
|
|
@ -368,34 +368,34 @@ static int32_t mndGetMnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
|
|||
pShow->bytes[cols] = 2;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
|
||||
strcpy(pSchema[cols].name, "id");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_EP_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "end point");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
strcpy(pSchema[cols].name, "endpoint");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 12 + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "role");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "role time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
strcpy(pSchema[cols].name, "role_time");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "create time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
strcpy(pSchema[cols].name, "create_time");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pMeta->numOfColumns = htons(cols);
|
||||
pMeta->numOfColumns = htonl(cols);
|
||||
pShow->numOfColumns = cols;
|
||||
|
||||
pShow->offset[0] = 0;
|
||||
|
|
|
@ -474,48 +474,48 @@ static int32_t mndGetConnsMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
|
|||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "connId");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "user");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
// app name
|
||||
pShow->bytes[cols] = TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "program");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
// app pid
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "pid");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "ip:port");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "login_time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "last_access");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pMeta->numOfColumns = htons(cols);
|
||||
pMeta->numOfColumns = htonl(cols);
|
||||
pShow->numOfColumns = cols;
|
||||
|
||||
pShow->offset[0] = 0;
|
||||
|
@ -602,88 +602,88 @@ static int32_t mndGetQueryMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
|
|||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "queryId");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "connId");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "user");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "ip:port");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 24;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "qid");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "created_time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BIGINT;
|
||||
strcpy(pSchema[cols].name, "time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = QUERY_OBJ_ID_SIZE + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "sql_obj_id");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "pid");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_EP_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "ep");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 1;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BOOL;
|
||||
strcpy(pSchema[cols].name, "stable_query");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "sub_queries");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_SHOW_SUBQUERY_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "sub_query_info");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "sql");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pMeta->numOfColumns = htons(cols);
|
||||
pMeta->numOfColumns = htonl(cols);
|
||||
pShow->numOfColumns = cols;
|
||||
|
||||
pShow->offset[0] = 0;
|
||||
|
@ -818,64 +818,64 @@ static int32_t mndGetStreamMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg
|
|||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "streamId");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "connId");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "user");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "dest table");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
strcpy(pSchema[cols].name, "destination");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "ip:port");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "created time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
strcpy(pSchema[cols].name, "create_time");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "exec time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
strcpy(pSchema[cols].name, "exec");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BIGINT;
|
||||
strcpy(pSchema[cols].name, "time(us)");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "sql");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "cycles");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pMeta->numOfColumns = htons(cols);
|
||||
pMeta->numOfColumns = htonl(cols);
|
||||
pShow->numOfColumns = cols;
|
||||
|
||||
pShow->offset[0] = 0;
|
||||
|
|
|
@ -291,7 +291,7 @@ char *mndShowStr(int32_t showType) {
|
|||
case TSDB_MGMT_TABLE_VNODES:
|
||||
return "show vnodes";
|
||||
case TSDB_MGMT_TABLE_CLUSTER:
|
||||
return "show clusters";
|
||||
return "show cluster";
|
||||
case TSDB_MGMT_TABLE_STREAMTABLES:
|
||||
return "show streamtables";
|
||||
case TSDB_MGMT_TABLE_TP:
|
||||
|
|
|
@ -74,11 +74,13 @@ static SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
|
|||
if (pRaw == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_BINARY(pRaw, dataPos, pStb->name, TSDB_TABLE_NAME_LEN)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pStb->name, TSDB_TABLE_FNAME_LEN)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pStb->db, TSDB_FULL_DB_NAME_LEN)
|
||||
SDB_SET_INT64(pRaw, dataPos, pStb->createdTime)
|
||||
SDB_SET_INT64(pRaw, dataPos, pStb->updateTime)
|
||||
SDB_SET_INT64(pRaw, dataPos, pStb->uid)
|
||||
SDB_SET_INT64(pRaw, dataPos, pStb->version)
|
||||
SDB_SET_INT64(pRaw, dataPos, pStb->dbUid)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->version)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->numOfTags)
|
||||
|
||||
|
@ -113,10 +115,12 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
|
|||
if (pStb == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pStb->name, TSDB_TABLE_NAME_LEN)
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pStb->name, TSDB_TABLE_FNAME_LEN)
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pStb->db, TSDB_FULL_DB_NAME_LEN)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pStb->createdTime)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pStb->updateTime)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pStb->uid)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pStb->dbUid)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pStb->version)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pStb->numOfColumns)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pStb->numOfTags)
|
||||
|
@ -153,11 +157,17 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOldStb, SStbObj *pNewStb
|
|||
atomic_exchange_32(&pOldStb->version, pNewStb->version);
|
||||
|
||||
taosWLockLatch(&pOldStb->lock);
|
||||
pOldStb->numOfColumns = pNewStb->numOfColumns;
|
||||
pOldStb->numOfTags = pNewStb->numOfTags;
|
||||
int32_t totalCols = pNewStb->numOfTags + pNewStb->numOfColumns;
|
||||
int32_t totalSize = totalCols * sizeof(SSchema);
|
||||
|
||||
if (pOldStb->numOfTags + pOldStb->numOfColumns < totalCols) {
|
||||
pOldStb->pSchema = malloc(totalSize);
|
||||
void *pSchema = malloc(totalSize);
|
||||
if (pSchema != NULL) {
|
||||
free(pOldStb->pSchema);
|
||||
pOldStb->pSchema = pSchema;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(pOldStb->pSchema, pNewStb->pSchema, totalSize);
|
||||
|
@ -196,37 +206,37 @@ static int32_t mndCheckStbMsg(SCreateStbMsg *pCreate) {
|
|||
}
|
||||
|
||||
if (pCreate->igExists < 0 || pCreate->igExists > 1) {
|
||||
terrno = TSDB_CODE_MND_STB_INVALID_IGEXIST;
|
||||
terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCreate->numOfColumns < TSDB_MIN_COLUMNS || pCreate->numOfColumns > TSDB_MAX_COLUMNS) {
|
||||
terrno = TSDB_CODE_MND_STB_INVALID_COLS_NUM;
|
||||
terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCreate->numOfTags <= 0 || pCreate->numOfTags > TSDB_MAX_TAGS) {
|
||||
terrno = TSDB_CODE_MND_STB_INVALID_TAGS_NUM;
|
||||
terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t maxColId = (TSDB_MAX_COLUMNS + TSDB_MAX_TAGS);
|
||||
for (int32_t i = 0; i < totalCols; ++i) {
|
||||
SSchema *pSchema = &pCreate->pSchema[i];
|
||||
if (pSchema->type <= 0) {
|
||||
terrno = TSDB_CODE_MND_STB_INVALID_COL_TYPE;
|
||||
if (pSchema->type < 0) {
|
||||
terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
|
||||
return -1;
|
||||
}
|
||||
if (pSchema->colId < 0 || pSchema->colId >= maxColId) {
|
||||
terrno = TSDB_CODE_MND_STB_INVALID_COL_ID;
|
||||
terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
|
||||
return -1;
|
||||
}
|
||||
if (pSchema->bytes <= 0) {
|
||||
terrno = TSDB_CODE_MND_STB_INVALID_COL_BYTES;
|
||||
terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
|
||||
return -1;
|
||||
}
|
||||
if (pSchema->name[0] == 0) {
|
||||
terrno = TSDB_CODE_MND_STB_INVALID_COL_NAME;
|
||||
terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -241,6 +251,7 @@ static int32_t mndCreateStb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateStbMsg *pCre
|
|||
stbObj.createdTime = taosGetTimestampMs();
|
||||
stbObj.updateTime = stbObj.createdTime;
|
||||
stbObj.uid = mndGenerateUid(pCreate->name, TSDB_TABLE_FNAME_LEN);
|
||||
stbObj.dbUid = pDb->uid;
|
||||
stbObj.version = 1;
|
||||
stbObj.numOfColumns = pCreate->numOfColumns;
|
||||
stbObj.numOfTags = pCreate->numOfTags;
|
||||
|
@ -346,19 +357,19 @@ static int32_t mndCheckAlterStbMsg(SAlterStbMsg *pAlter) {
|
|||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
|
||||
if (pSchema->type <= 0) {
|
||||
terrno = TSDB_CODE_MND_STB_INVALID_COL_TYPE;
|
||||
terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
|
||||
return -1;
|
||||
}
|
||||
if (pSchema->colId < 0 || pSchema->colId >= (TSDB_MAX_COLUMNS + TSDB_MAX_TAGS)) {
|
||||
terrno = TSDB_CODE_MND_STB_INVALID_COL_ID;
|
||||
terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
|
||||
return -1;
|
||||
}
|
||||
if (pSchema->bytes <= 0) {
|
||||
terrno = TSDB_CODE_MND_STB_INVALID_COL_BYTES;
|
||||
terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
|
||||
return -1;
|
||||
}
|
||||
if (pSchema->name[0] == 0) {
|
||||
terrno = TSDB_CODE_MND_STB_INVALID_COL_NAME;
|
||||
terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -476,31 +487,37 @@ static int32_t mndProcessDropStbMsg(SMnodeMsg *pMsg) {
|
|||
static int32_t mndProcessDropStbInRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
|
||||
static int32_t mndProcessStbMetaMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SStbInfoMsg *pInfo = pMsg->rpcMsg.pCont;
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
STableInfoMsg *pInfo = pMsg->rpcMsg.pCont;
|
||||
|
||||
mDebug("stb:%s, start to retrieve meta", pInfo->name);
|
||||
mDebug("stb:%s, start to retrieve meta", pInfo->tableFname);
|
||||
|
||||
SDbObj *pDb = mndAcquireDbByStb(pMnode, pInfo->name);
|
||||
SDbObj *pDb = mndAcquireDbByStb(pMnode, pInfo->tableFname);
|
||||
if (pDb == NULL) {
|
||||
terrno = TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||
mError("stb:%s, failed to retrieve meta since %s", pInfo->name, terrstr());
|
||||
mError("stb:%s, failed to retrieve meta since %s", pInfo->tableFname, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SStbObj *pStb = mndAcquireStb(pMnode, pInfo->name);
|
||||
SStbObj *pStb = mndAcquireStb(pMnode, pInfo->tableFname);
|
||||
if (pStb == NULL) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
terrno = TSDB_CODE_MND_INVALID_TABLE_NAME;
|
||||
mError("stb:%s, failed to get meta since %s", pInfo->name, terrstr());
|
||||
terrno = TSDB_CODE_MND_INVALID_STB;
|
||||
mError("stb:%s, failed to get meta since %s", pInfo->tableFname, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t contLen = sizeof(STableMetaMsg) + (pStb->numOfColumns + pStb->numOfTags) * sizeof(SSchema);
|
||||
taosRLockLatch(&pStb->lock);
|
||||
int32_t totalCols = pStb->numOfColumns + pStb->numOfTags;
|
||||
int32_t contLen = sizeof(STableMetaMsg) + totalCols * sizeof(SSchema);
|
||||
|
||||
STableMetaMsg *pMeta = rpcMallocCont(contLen);
|
||||
if (pMeta == NULL) {
|
||||
taosRUnLockLatch(&pStb->lock);
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
mndReleaseStb(pMnode, pStb);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("stb:%s, failed to get meta since %s", pInfo->name, terrstr());
|
||||
mError("stb:%s, failed to get meta since %s", pInfo->tableFname, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -513,7 +530,7 @@ static int32_t mndProcessStbMetaMsg(SMnodeMsg *pMsg) {
|
|||
pMeta->sversion = htonl(pStb->version);
|
||||
pMeta->suid = htonl(pStb->uid);
|
||||
|
||||
for (int32_t i = 0; i < pStb->numOfColumns; ++i) {
|
||||
for (int32_t i = 0; i < totalCols; ++i) {
|
||||
SSchema *pSchema = &pMeta->pSchema[i];
|
||||
SSchema *pSrcSchema = &pStb->pSchema[i];
|
||||
memcpy(pSchema->name, pSrcSchema->name, TSDB_COL_NAME_LEN);
|
||||
|
@ -521,11 +538,14 @@ static int32_t mndProcessStbMetaMsg(SMnodeMsg *pMsg) {
|
|||
pSchema->colId = htonl(pSrcSchema->colId);
|
||||
pSchema->bytes = htonl(pSrcSchema->bytes);
|
||||
}
|
||||
taosRUnLockLatch(&pStb->lock);
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
mndReleaseStb(pMnode, pStb);
|
||||
|
||||
pMsg->pCont = pMeta;
|
||||
pMsg->contLen = contLen;
|
||||
|
||||
mDebug("stb:%s, meta is retrieved, cols:%d tags:%d", pInfo->name, pStb->numOfColumns, pStb->numOfTags);
|
||||
mDebug("stb:%s, meta is retrieved, cols:%d tags:%d", pInfo->tableFname, pStb->numOfColumns, pStb->numOfTags);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -542,7 +562,7 @@ static int32_t mndGetNumOfStbs(SMnode *pMnode, char *dbName, int32_t *pNumOfStbs
|
|||
void *pIter = NULL;
|
||||
while (1) {
|
||||
SStbObj *pStb = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pStb);
|
||||
pIter = sdbFetch(pSdb, SDB_STB, pIter, (void **)&pStb);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
if (strcmp(pStb->db, dbName) == 0) {
|
||||
|
@ -570,28 +590,28 @@ static int32_t mndGetStbMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pM
|
|||
pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "name");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "create time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
strcpy(pSchema[cols].name, "create_time");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 2;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "columns");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 2;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "tags");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pMeta->numOfColumns = htons(cols);
|
||||
pMeta->numOfColumns = htonl(cols);
|
||||
pShow->numOfColumns = cols;
|
||||
|
||||
pShow->offset[0] = 0;
|
||||
|
@ -599,6 +619,7 @@ static int32_t mndGetStbMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pM
|
|||
pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
|
||||
}
|
||||
|
||||
pShow->numOfRows = sdbGetSize(pSdb, SDB_STB);
|
||||
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
|
||||
strcpy(pMeta->tbFname, mndShowStr(pShow->type));
|
||||
|
||||
|
@ -642,8 +663,8 @@ static int32_t mndRetrieveStb(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3
|
|||
|
||||
cols = 0;
|
||||
|
||||
char stbName[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
memcpy(stbName, pStb->name + prefixLen, TSDB_TABLE_FNAME_LEN - prefixLen);
|
||||
char stbName[TSDB_TABLE_NAME_LEN] = {0};
|
||||
tstrncpy(stbName, pStb->name + prefixLen, TSDB_TABLE_NAME_LEN);
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_TO_VARSTR(pWrite, stbName);
|
||||
cols++;
|
||||
|
@ -653,11 +674,11 @@ static int32_t mndRetrieveStb(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3
|
|||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int16_t *)pWrite = pStb->numOfColumns;
|
||||
*(int32_t *)pWrite = pStb->numOfColumns;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int16_t *)pWrite = pStb->numOfTags;
|
||||
*(int32_t *)pWrite = pStb->numOfTags;
|
||||
cols++;
|
||||
|
||||
numOfRows++;
|
||||
|
|
|
@ -21,6 +21,13 @@
|
|||
#define TSDB_TRN_ARRAY_SIZE 8
|
||||
#define TSDB_TRN_RESERVE_SIZE 64
|
||||
|
||||
typedef struct {
|
||||
SEpSet epSet;
|
||||
int8_t msgType;
|
||||
int32_t contLen;
|
||||
void *pCont;
|
||||
} STransAction;
|
||||
|
||||
static SSdbRaw *mndTransActionEncode(STrans *pTrans);
|
||||
static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw);
|
||||
static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans);
|
||||
|
@ -29,9 +36,12 @@ static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans);
|
|||
|
||||
static void mndTransSetRpcHandle(STrans *pTrans, void *rpcHandle);
|
||||
static void mndTransSendRpcRsp(STrans *pTrans, int32_t code);
|
||||
static int32_t mndTransAppendArray(SArray *pArray, SSdbRaw *pRaw);
|
||||
static void mndTransDropArray(SArray *pArray);
|
||||
static int32_t mndTransExecuteArray(SMnode *pMnode, SArray *pArray);
|
||||
static int32_t mndTransAppendLog(SArray *pArray, SSdbRaw *pRaw);
|
||||
static int32_t mndTransAppendAction(SArray *pArray, SEpSet *pEpSet, int8_t msgType, int32_t contLen, void *pCont);
|
||||
static void mndTransDropLogs(SArray *pArray);
|
||||
static void mndTransDropActions(SArray *pArray);
|
||||
static int32_t mndTransExecuteLogs(SMnode *pMnode, SArray *pArray);
|
||||
static int32_t mndTransExecuteActions(SMnode *pMnode, SArray *pArray);
|
||||
static int32_t mndTransExecuteRedoLogs(SMnode *pMnode, STrans *pTrans);
|
||||
static int32_t mndTransExecuteUndoLogs(SMnode *pMnode, STrans *pTrans);
|
||||
static int32_t mndTransExecuteCommitLogs(SMnode *pMnode, STrans *pTrans);
|
||||
|
@ -58,7 +68,7 @@ int32_t mndInitTrans(SMnode *pMnode) {
|
|||
void mndCleanupTrans(SMnode *pMnode) {}
|
||||
|
||||
static SSdbRaw *mndTransActionEncode(STrans *pTrans) {
|
||||
int32_t rawDataLen = 16 * sizeof(int32_t) + TSDB_TRN_RESERVE_SIZE;
|
||||
int32_t rawDataLen = sizeof(STrans) + TSDB_TRN_RESERVE_SIZE;
|
||||
int32_t redoLogNum = taosArrayGetSize(pTrans->redoLogs);
|
||||
int32_t undoLogNum = taosArrayGetSize(pTrans->undoLogs);
|
||||
int32_t commitLogNum = taosArrayGetSize(pTrans->commitLogs);
|
||||
|
@ -80,6 +90,16 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) {
|
|||
rawDataLen += sdbGetRawTotalSize(pTmp);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < redoActionNum; ++i) {
|
||||
STransAction *pAction = taosArrayGet(pTrans->redoActions, i);
|
||||
rawDataLen += (sizeof(STransAction) + pAction->contLen);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < undoActionNum; ++i) {
|
||||
STransAction *pAction = taosArrayGet(pTrans->undoActions, i);
|
||||
rawDataLen += (sizeof(STransAction) + pAction->contLen);
|
||||
}
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_TRANS, TSDB_TRANS_VER, rawDataLen);
|
||||
if (pRaw == NULL) {
|
||||
mError("trans:%d, failed to alloc raw since %s", pTrans->id, terrstr());
|
||||
|
@ -116,6 +136,22 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) {
|
|||
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len)
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < redoActionNum; ++i) {
|
||||
STransAction *pAction = taosArrayGet(pTrans->redoActions, i);
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet));
|
||||
SDB_SET_INT8(pRaw, dataPos, pAction->msgType)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->contLen)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pAction->pCont, pAction->contLen);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < undoActionNum; ++i) {
|
||||
STransAction *pAction = taosArrayGet(pTrans->undoActions, i);
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet));
|
||||
SDB_SET_INT8(pRaw, dataPos, pAction->msgType)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->contLen)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pAction->pCont, pAction->contLen);
|
||||
}
|
||||
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_TRN_RESERVE_SIZE)
|
||||
SDB_SET_DATALEN(pRaw, dataPos);
|
||||
mTrace("trans:%d, encode to raw:%p, len:%d", pTrans->id, pRaw, dataPos);
|
||||
|
@ -147,8 +183,8 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
|
|||
pTrans->redoLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->undoLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->commitLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->redoActions = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->undoActions = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->redoActions = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(STransAction));
|
||||
pTrans->undoActions = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(STransAction));
|
||||
|
||||
if (pTrans->redoLogs == NULL || pTrans->undoLogs == NULL || pTrans->commitLogs == NULL ||
|
||||
pTrans->redoActions == NULL || pTrans->undoActions == NULL) {
|
||||
|
@ -175,42 +211,77 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
|
|||
for (int32_t i = 0; i < redoLogNum; ++i) {
|
||||
int32_t dataLen = 0;
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &dataLen)
|
||||
|
||||
char *pData = malloc(dataLen);
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pData, dataLen);
|
||||
|
||||
void *ret = taosArrayPush(pTrans->redoLogs, &pData);
|
||||
if (ret == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto TRANS_DECODE_OVER;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < undoLogNum; ++i) {
|
||||
int32_t dataLen = 0;
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &dataLen)
|
||||
|
||||
char *pData = malloc(dataLen);
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pData, dataLen);
|
||||
|
||||
void *ret = taosArrayPush(pTrans->undoLogs, &pData);
|
||||
if (ret == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto TRANS_DECODE_OVER;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < commitLogNum; ++i) {
|
||||
int32_t dataLen = 0;
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &dataLen)
|
||||
|
||||
char *pData = malloc(dataLen);
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pData, dataLen);
|
||||
|
||||
void *ret = taosArrayPush(pTrans->commitLogs, &pData);
|
||||
if (ret == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto TRANS_DECODE_OVER;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < redoActionNum; ++i) {
|
||||
STransAction action = {0};
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, (void *)&action.epSet, sizeof(SEpSet));
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &action.msgType)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &action.contLen)
|
||||
action.pCont = malloc(action.contLen);
|
||||
if (action.pCont == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto TRANS_DECODE_OVER;
|
||||
}
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, action.pCont, action.contLen);
|
||||
|
||||
void *ret = taosArrayPush(pTrans->redoActions, &action);
|
||||
if (ret == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto TRANS_DECODE_OVER;
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < undoActionNum; ++i) {
|
||||
STransAction action = {0};
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, (void *)&action.epSet, sizeof(SEpSet));
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &action.msgType)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &action.contLen)
|
||||
action.pCont = malloc(action.contLen);
|
||||
if (action.pCont == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto TRANS_DECODE_OVER;
|
||||
}
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, action.pCont, action.contLen);
|
||||
|
||||
void *ret = taosArrayPush(pTrans->undoActions, &action);
|
||||
if (ret == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto TRANS_DECODE_OVER;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,11 +308,11 @@ static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans) {
|
|||
static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans) {
|
||||
mTrace("trans:%d, perform delete action, stage:%s", pTrans->id, mndTransStageStr(pTrans->stage));
|
||||
|
||||
mndTransDropArray(pTrans->redoLogs);
|
||||
mndTransDropArray(pTrans->undoLogs);
|
||||
mndTransDropArray(pTrans->commitLogs);
|
||||
mndTransDropArray(pTrans->redoActions);
|
||||
mndTransDropArray(pTrans->undoActions);
|
||||
mndTransDropLogs(pTrans->redoLogs);
|
||||
mndTransDropLogs(pTrans->undoLogs);
|
||||
mndTransDropLogs(pTrans->commitLogs);
|
||||
mndTransDropActions(pTrans->redoActions);
|
||||
mndTransDropActions(pTrans->undoActions);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -274,6 +345,8 @@ char *mndTransStageStr(ETrnStage stage) {
|
|||
return "rollback";
|
||||
case TRN_STAGE_RETRY:
|
||||
return "retry";
|
||||
case TRN_STAGE_OVER:
|
||||
return "stop";
|
||||
default:
|
||||
return "undefined";
|
||||
}
|
||||
|
@ -305,8 +378,8 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) {
|
|||
pTrans->redoLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->undoLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->commitLogs = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->redoActions = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->undoActions = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->redoActions = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(STransAction));
|
||||
pTrans->undoActions = taosArrayInit(TSDB_TRN_ARRAY_SIZE, sizeof(STransAction));
|
||||
|
||||
if (pTrans->redoLogs == NULL || pTrans->undoLogs == NULL || pTrans->commitLogs == NULL ||
|
||||
pTrans->redoActions == NULL || pTrans->undoActions == NULL) {
|
||||
|
@ -319,7 +392,7 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) {
|
|||
return pTrans;
|
||||
}
|
||||
|
||||
static void mndTransDropArray(SArray *pArray) {
|
||||
static void mndTransDropLogs(SArray *pArray) {
|
||||
for (int32_t i = 0; i < pArray->size; ++i) {
|
||||
SSdbRaw *pRaw = taosArrayGetP(pArray, i);
|
||||
tfree(pRaw);
|
||||
|
@ -328,12 +401,21 @@ static void mndTransDropArray(SArray *pArray) {
|
|||
taosArrayDestroy(pArray);
|
||||
}
|
||||
|
||||
static void mndTransDropActions(SArray *pArray) {
|
||||
for (int32_t i = 0; i < pArray->size; ++i) {
|
||||
STransAction *pAction = taosArrayGet(pArray, i);
|
||||
free(pAction->pCont);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pArray);
|
||||
}
|
||||
|
||||
void mndTransDrop(STrans *pTrans) {
|
||||
mndTransDropArray(pTrans->redoLogs);
|
||||
mndTransDropArray(pTrans->undoLogs);
|
||||
mndTransDropArray(pTrans->commitLogs);
|
||||
mndTransDropArray(pTrans->redoActions);
|
||||
mndTransDropArray(pTrans->undoActions);
|
||||
mndTransDropLogs(pTrans->redoLogs);
|
||||
mndTransDropLogs(pTrans->undoLogs);
|
||||
mndTransDropLogs(pTrans->commitLogs);
|
||||
mndTransDropActions(pTrans->redoActions);
|
||||
mndTransDropActions(pTrans->undoActions);
|
||||
|
||||
mDebug("trans:%d, data:%p is dropped", pTrans->id, pTrans);
|
||||
tfree(pTrans);
|
||||
|
@ -344,7 +426,7 @@ static void mndTransSetRpcHandle(STrans *pTrans, void *rpcHandle) {
|
|||
mTrace("trans:%d, set rpc handle:%p", pTrans->id, rpcHandle);
|
||||
}
|
||||
|
||||
static int32_t mndTransAppendArray(SArray *pArray, SSdbRaw *pRaw) {
|
||||
static int32_t mndTransAppendLog(SArray *pArray, SSdbRaw *pRaw) {
|
||||
if (pArray == NULL || pRaw == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
|
@ -360,32 +442,44 @@ static int32_t mndTransAppendArray(SArray *pArray, SSdbRaw *pRaw) {
|
|||
}
|
||||
|
||||
int32_t mndTransAppendRedolog(STrans *pTrans, SSdbRaw *pRaw) {
|
||||
int32_t code = mndTransAppendArray(pTrans->redoLogs, pRaw);
|
||||
int32_t code = mndTransAppendLog(pTrans->redoLogs, pRaw);
|
||||
mTrace("trans:%d, raw:%p append to redo logs, code:0x%x", pTrans->id, pRaw, code);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t mndTransAppendUndolog(STrans *pTrans, SSdbRaw *pRaw) {
|
||||
int32_t code = mndTransAppendArray(pTrans->undoLogs, pRaw);
|
||||
int32_t code = mndTransAppendLog(pTrans->undoLogs, pRaw);
|
||||
mTrace("trans:%d, raw:%p append to undo logs, code:0x%x", pTrans->id, pRaw, code);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t mndTransAppendCommitlog(STrans *pTrans, SSdbRaw *pRaw) {
|
||||
int32_t code = mndTransAppendArray(pTrans->commitLogs, pRaw);
|
||||
int32_t code = mndTransAppendLog(pTrans->commitLogs, pRaw);
|
||||
mTrace("trans:%d, raw:%p append to commit logs, code:0x%x", pTrans->id, pRaw, code);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t mndTransAppendRedoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) {
|
||||
int32_t code = mndTransAppendArray(pTrans->redoActions, pMsg);
|
||||
mTrace("trans:%d, msg:%p append to redo actions", pTrans->id, pMsg);
|
||||
static int32_t mndTransAppendAction(SArray *pArray, SEpSet *pEpSet, int8_t msgType, int32_t contLen, void *pCont) {
|
||||
STransAction action = {.epSet = *pEpSet, .msgType = msgType, .contLen = contLen, .pCont = pCont};
|
||||
|
||||
void *ptr = taosArrayPush(pArray, &action);
|
||||
if (ptr == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndTransAppendRedoAction(STrans *pTrans, SEpSet *pEpSet, int8_t msgType, int32_t contLen, void *pCont) {
|
||||
int32_t code = mndTransAppendAction(pTrans->redoActions, pEpSet, msgType, contLen, pCont);
|
||||
mTrace("trans:%d, msg:%s len:%d append to redo actions", pTrans->id, taosMsg[msgType], contLen);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t mndTransAppendUndoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) {
|
||||
int32_t code = mndTransAppendArray(pTrans->undoActions, pMsg);
|
||||
mTrace("trans:%d, msg:%p append to undo actions", pTrans->id, pMsg);
|
||||
int32_t mndTransAppendUndoAction(STrans *pTrans, SEpSet *pEpSet, int8_t msgType, int32_t contLen, void *pCont) {
|
||||
int32_t code = mndTransAppendAction(pTrans->undoActions, pEpSet, msgType, contLen, pCont);
|
||||
mTrace("trans:%d, msg:%s len:%d append to undo actions", pTrans->id, taosMsg[msgType], contLen);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -502,7 +596,7 @@ void mndTransApply(SMnode *pMnode, SSdbRaw *pRaw, STransMsg *pMsg, int32_t code)
|
|||
// todo
|
||||
}
|
||||
|
||||
static int32_t mndTransExecuteArray(SMnode *pMnode, SArray *pArray) {
|
||||
static int32_t mndTransExecuteLogs(SMnode *pMnode, SArray *pArray) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t arraySize = taosArrayGetSize(pArray);
|
||||
|
||||
|
@ -520,7 +614,7 @@ static int32_t mndTransExecuteArray(SMnode *pMnode, SArray *pArray) {
|
|||
static int32_t mndTransExecuteRedoLogs(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
if (taosArrayGetSize(pTrans->redoLogs) != 0) {
|
||||
code = mndTransExecuteArray(pMnode, pTrans->redoLogs);
|
||||
code = mndTransExecuteLogs(pMnode, pTrans->redoLogs);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to execute redo logs since %s", pTrans->id, terrstr())
|
||||
} else {
|
||||
|
@ -534,7 +628,7 @@ static int32_t mndTransExecuteRedoLogs(SMnode *pMnode, STrans *pTrans) {
|
|||
static int32_t mndTransExecuteUndoLogs(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
if (taosArrayGetSize(pTrans->undoLogs) != 0) {
|
||||
code = mndTransExecuteArray(pMnode, pTrans->undoLogs);
|
||||
code = mndTransExecuteLogs(pMnode, pTrans->undoLogs);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to execute undo logs since %s", pTrans->id, terrstr())
|
||||
} else {
|
||||
|
@ -548,7 +642,7 @@ static int32_t mndTransExecuteUndoLogs(SMnode *pMnode, STrans *pTrans) {
|
|||
static int32_t mndTransExecuteCommitLogs(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
if (taosArrayGetSize(pTrans->commitLogs) != 0) {
|
||||
code = mndTransExecuteArray(pMnode, pTrans->commitLogs);
|
||||
code = mndTransExecuteLogs(pMnode, pTrans->commitLogs);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to execute commit logs since %s", pTrans->id, terrstr())
|
||||
} else {
|
||||
|
@ -559,18 +653,40 @@ static int32_t mndTransExecuteCommitLogs(SMnode *pMnode, STrans *pTrans) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndTransExecuteRedoActions(SMnode *pMnode, STrans *pTrans) {
|
||||
if (taosArrayGetSize(pTrans->redoActions) != 0) {
|
||||
mTrace("trans:%d, execute redo actions finished", pTrans->id);
|
||||
static int32_t mndTransExecuteActions(SMnode *pMnode, SArray *pArray) {
|
||||
#if 0
|
||||
int32_t arraySize = taosArrayGetSize(pArray);
|
||||
for (int32_t i = 0; i < arraySize; ++i) {
|
||||
STransAction *pAction = taosArrayGet(pArray, i);
|
||||
|
||||
SRpcMsg rpcMsg = {.msgType = pAction->msgType, .contLen = pAction->contLen};
|
||||
rpcMsg.pCont = rpcMallocCont(pAction->contLen);
|
||||
if (rpcMsg.pCont == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
memcpy(rpcMsg.pCont, pAction->pCont, pAction->contLen);
|
||||
mndSendMsgToDnode(pMnode, &pAction->epSet, &rpcMsg);
|
||||
}
|
||||
|
||||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int32_t mndTransExecuteRedoActions(SMnode *pMnode, STrans *pTrans) {
|
||||
if (taosArrayGetSize(pTrans->redoActions) <= 0) return 0;
|
||||
|
||||
mTrace("trans:%d, start to execute redo actions", pTrans->id);
|
||||
return mndTransExecuteActions(pMnode, pTrans->redoActions);
|
||||
}
|
||||
|
||||
static int32_t mndTransExecuteUndoActions(SMnode *pMnode, STrans *pTrans) {
|
||||
if (taosArrayGetSize(pTrans->undoActions) != 0) {
|
||||
mTrace("trans:%d, execute undo actions finished", pTrans->id);
|
||||
}
|
||||
return 0;
|
||||
if (taosArrayGetSize(pTrans->undoActions) <= 0) return 0;
|
||||
|
||||
mTrace("trans:%d, start to execute undo actions", pTrans->id);
|
||||
return mndTransExecuteActions(pMnode, pTrans->undoActions);
|
||||
}
|
||||
|
||||
static int32_t mndTransPerformPrepareStage(SMnode *pMnode, STrans *pTrans) {
|
||||
|
|
|
@ -410,28 +410,28 @@ static int32_t mndGetUserMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *p
|
|||
pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "name");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 10 + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "privilege");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "create time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
strcpy(pSchema[cols].name, "create_time");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "account");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pMeta->numOfColumns = htons(cols);
|
||||
pMeta->numOfColumns = htonl(cols);
|
||||
pShow->numOfColumns = cols;
|
||||
|
||||
pShow->offset[0] = 0;
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#define TSDB_VGROUP_VER_NUM 1
|
||||
#define TSDB_VGROUP_RESERVE_SIZE 64
|
||||
|
||||
static SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup);
|
||||
static SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw);
|
||||
static int32_t mndVgroupActionInsert(SSdb *pSdb, SVgObj *pVgroup);
|
||||
static int32_t mndVgroupActionDelete(SSdb *pSdb, SVgObj *pVgroup);
|
||||
|
@ -70,8 +69,8 @@ int32_t mndInitVgroup(SMnode *pMnode) {
|
|||
|
||||
void mndCleanupVgroup(SMnode *pMnode) {}
|
||||
|
||||
static SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup) {
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_DB, TSDB_VGROUP_VER_NUM, sizeof(SVgObj) + TSDB_VGROUP_RESERVE_SIZE);
|
||||
SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup) {
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_VGROUP, TSDB_VGROUP_VER_NUM, sizeof(SVgObj) + TSDB_VGROUP_RESERVE_SIZE);
|
||||
if (pRaw == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
|
@ -79,7 +78,10 @@ static SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup) {
|
|||
SDB_SET_INT64(pRaw, dataPos, pVgroup->createdTime)
|
||||
SDB_SET_INT64(pRaw, dataPos, pVgroup->updateTime)
|
||||
SDB_SET_INT32(pRaw, dataPos, pVgroup->version)
|
||||
SDB_SET_INT32(pRaw, dataPos, pVgroup->hashBegin)
|
||||
SDB_SET_INT32(pRaw, dataPos, pVgroup->hashEnd)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pVgroup->dbName, TSDB_FULL_DB_NAME_LEN)
|
||||
SDB_SET_INT64(pRaw, dataPos, pVgroup->dbUid)
|
||||
SDB_SET_INT8(pRaw, dataPos, pVgroup->replica)
|
||||
for (int8_t i = 0; i < pVgroup->replica; ++i) {
|
||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[i];
|
||||
|
@ -92,7 +94,7 @@ static SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup) {
|
|||
return pRaw;
|
||||
}
|
||||
|
||||
static SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) {
|
||||
SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) {
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
|
||||
|
@ -102,7 +104,7 @@ static SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SDbObj));
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SVgObj));
|
||||
SVgObj *pVgroup = sdbGetRowObj(pRow);
|
||||
if (pVgroup == NULL) return NULL;
|
||||
|
||||
|
@ -111,7 +113,10 @@ static SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) {
|
|||
SDB_GET_INT64(pRaw, pRow, dataPos, &pVgroup->createdTime)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pVgroup->updateTime)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pVgroup->version)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pVgroup->hashBegin)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pVgroup->hashEnd)
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pVgroup->dbName, TSDB_FULL_DB_NAME_LEN)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pVgroup->dbUid)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pVgroup->replica)
|
||||
for (int8_t i = 0; i < pVgroup->replica; ++i) {
|
||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[i];
|
||||
|
@ -133,12 +138,6 @@ static int32_t mndVgroupActionDelete(SSdb *pSdb, SVgObj *pVgroup) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateVnodeRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
static int32_t mndProcessAlterVnodeRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
static int32_t mndProcessDropVnodeRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
static int32_t mndProcessSyncVnodeRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
static int32_t mndProcessCompactVnodeRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
|
||||
static int32_t mndVgroupActionUpdate(SSdb *pSdb, SVgObj *pOldVgroup, SVgObj *pNewVgroup) {
|
||||
mTrace("vgId:%d, perform update action", pOldVgroup->vgId);
|
||||
pOldVgroup->updateTime = pNewVgroup->updateTime;
|
||||
|
@ -158,6 +157,160 @@ void mndReleaseVgroup(SMnode *pMnode, SVgObj *pVgroup) {
|
|||
sdbRelease(pSdb, pVgroup);
|
||||
}
|
||||
|
||||
SCreateVnodeMsg *mndBuildCreateVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup) {
|
||||
SCreateVnodeMsg *pCreate = malloc(sizeof(SCreateVnodeMsg));
|
||||
if (pCreate == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pCreate->dnodeId = htonl(pDnode->id);
|
||||
pCreate->vgId = htonl(pVgroup->vgId);
|
||||
memcpy(pCreate->db, pDb->name, TSDB_FULL_DB_NAME_LEN);
|
||||
pCreate->dbUid = htobe64(pDb->uid);
|
||||
pCreate->cacheBlockSize = htonl(pDb->cfg.cacheBlockSize);
|
||||
pCreate->totalBlocks = htonl(pDb->cfg.totalBlocks);
|
||||
pCreate->daysPerFile = htonl(pDb->cfg.daysPerFile);
|
||||
pCreate->daysToKeep0 = htonl(pDb->cfg.daysToKeep0);
|
||||
pCreate->daysToKeep1 = htonl(pDb->cfg.daysToKeep1);
|
||||
pCreate->daysToKeep2 = htonl(pDb->cfg.daysToKeep2);
|
||||
pCreate->minRows = htonl(pDb->cfg.minRows);
|
||||
pCreate->maxRows = htonl(pDb->cfg.maxRows);
|
||||
pCreate->commitTime = htonl(pDb->cfg.commitTime);
|
||||
pCreate->fsyncPeriod = htonl(pDb->cfg.fsyncPeriod);
|
||||
pCreate->walLevel = pDb->cfg.walLevel;
|
||||
pCreate->precision = pDb->cfg.precision;
|
||||
pCreate->compression = pDb->cfg.compression;
|
||||
pCreate->quorum = pDb->cfg.quorum;
|
||||
pCreate->update = pDb->cfg.update;
|
||||
pCreate->cacheLastRow = pDb->cfg.cacheLastRow;
|
||||
pCreate->replica = pVgroup->replica;
|
||||
pCreate->selfIndex = -1;
|
||||
|
||||
for (int32_t v = 0; v < pVgroup->replica; ++v) {
|
||||
SReplica *pReplica = &pCreate->replicas[v];
|
||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[v];
|
||||
SDnodeObj *pVgidDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pVgidDnode == NULL) {
|
||||
free(pCreate);
|
||||
terrno = TSDB_CODE_MND_APP_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pReplica->id = htonl(pVgidDnode->id);
|
||||
pReplica->port = htons(pVgidDnode->port);
|
||||
memcpy(pReplica->fqdn, pVgidDnode->fqdn, TSDB_FQDN_LEN);
|
||||
mndReleaseDnode(pMnode, pVgidDnode);
|
||||
|
||||
if (pDnode->id == pVgid->dnodeId) {
|
||||
pCreate->selfIndex = v;
|
||||
}
|
||||
}
|
||||
|
||||
if (pCreate->selfIndex == -1) {
|
||||
free(pCreate);
|
||||
terrno = TSDB_CODE_MND_APP_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pCreate;
|
||||
}
|
||||
|
||||
SDropVnodeMsg *mndBuildDropVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup) {
|
||||
SDropVnodeMsg *pDrop = malloc(sizeof(SDropVnodeMsg));
|
||||
if (pDrop == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pDrop->dnodeId = htonl(pDnode->id);
|
||||
pDrop->vgId = htonl(pVgroup->vgId);
|
||||
memcpy(pDrop->db, pDb->name, TSDB_FULL_DB_NAME_LEN);
|
||||
pDrop->dbUid = htobe64(pDb->uid);
|
||||
|
||||
return pDrop;
|
||||
}
|
||||
|
||||
static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t allocedVnodes = 0;
|
||||
void *pIter = NULL;
|
||||
|
||||
while (allocedVnodes < pVgroup->replica) {
|
||||
SDnodeObj *pDnode = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
// todo
|
||||
if (mndIsDnodeInReadyStatus(pMnode, pDnode)) {
|
||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[allocedVnodes];
|
||||
pVgid->dnodeId = pDnode->id;
|
||||
if (pVgroup->replica == 1) {
|
||||
pVgid->role = TAOS_SYNC_STATE_LEADER;
|
||||
} else {
|
||||
pVgid->role = TAOS_SYNC_STATE_FOLLOWER;
|
||||
}
|
||||
allocedVnodes++;
|
||||
}
|
||||
sdbRelease(pSdb, pDnode);
|
||||
}
|
||||
|
||||
if (allocedVnodes != pVgroup->replica) {
|
||||
terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
|
||||
SVgObj *pVgroups = calloc(pDb->cfg.numOfVgroups, sizeof(SVgObj));
|
||||
if (pVgroups == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t alloceVgroups = 0;
|
||||
int32_t maxVgId = sdbGetMaxId(pMnode->pSdb, SDB_VGROUP);
|
||||
uint32_t hashMin = 0;
|
||||
uint32_t hashMax = UINT32_MAX;
|
||||
uint32_t hashInterval = (hashMax - hashMin) / pDb->cfg.numOfVgroups;
|
||||
|
||||
for (uint32_t v = 0; v < pDb->cfg.numOfVgroups; v++) {
|
||||
SVgObj *pVgroup = &pVgroups[v];
|
||||
pVgroup->vgId = maxVgId++;
|
||||
pVgroup->createdTime = taosGetTimestampMs();
|
||||
pVgroup->updateTime = pVgroups->createdTime;
|
||||
pVgroup->version = 1;
|
||||
pVgroup->dbUid = pDb->uid;
|
||||
pVgroup->hashBegin = hashMin + hashInterval * v;
|
||||
if (v == pDb->cfg.numOfVgroups - 1) {
|
||||
pVgroup->hashEnd = hashMax;
|
||||
} else {
|
||||
pVgroup->hashEnd = hashMin + hashInterval * (v + 1) - 1;
|
||||
}
|
||||
|
||||
memcpy(pVgroup->dbName, pDb->name, TSDB_FULL_DB_NAME_LEN);
|
||||
pVgroup->replica = pDb->cfg.replications;
|
||||
|
||||
if (mndGetAvailableDnode(pMnode, pVgroup) != 0) {
|
||||
terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
||||
free(pVgroups);
|
||||
return -1;
|
||||
}
|
||||
|
||||
alloceVgroups++;
|
||||
}
|
||||
|
||||
*ppVgroups = pVgroups;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateVnodeRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
static int32_t mndProcessAlterVnodeRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
static int32_t mndProcessDropVnodeRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
static int32_t mndProcessSyncVnodeRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
static int32_t mndProcessCompactVnodeRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
|
||||
static int32_t mndGetVgroupMaxReplica(SMnode *pMnode, char *dbName, int8_t *pReplica, int32_t *pNumOfVgroups) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
|
@ -203,30 +356,30 @@ static int32_t mndGetVgroupMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg
|
|||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "vgId");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "tables");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
for (int32_t i = 0; i < pShow->replica; ++i) {
|
||||
pShow->bytes[cols] = 4;
|
||||
pShow->bytes[cols] = 2;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
|
||||
snprintf(pSchema[cols].name, TSDB_COL_NAME_LEN, "v%d_dnode", i + 1);
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 9 + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
snprintf(pSchema[cols].name, TSDB_COL_NAME_LEN, "v%d_status", i + 1);
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
}
|
||||
|
||||
pMeta->numOfColumns = htons(cols);
|
||||
pMeta->numOfColumns = htonl(cols);
|
||||
pShow->numOfColumns = cols;
|
||||
|
||||
pShow->offset[0] = 0;
|
||||
|
@ -273,10 +426,6 @@ static int32_t mndRetrieveVgroups(SMnodeMsg *pMsg, SShowObj *pShow, char *data,
|
|||
cols++;
|
||||
}
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int8_t *)pWrite = pVgroup->compact;
|
||||
cols++;
|
||||
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
numOfRows++;
|
||||
}
|
||||
|
@ -309,16 +458,16 @@ static int32_t mndGetVnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
|
|||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "vgId");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 12 + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "status");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pMeta->numOfColumns = htons(cols);
|
||||
pMeta->numOfColumns = htonl(cols);
|
||||
pShow->numOfColumns = cols;
|
||||
|
||||
pShow->offset[0] = 0;
|
||||
|
|
|
@ -32,6 +32,8 @@ int vnodeBufPoolRecycle(SVnode *pVnode);
|
|||
void *vnodeMalloc(SVnode *pVnode, uint64_t size);
|
||||
bool vnodeBufPoolIsFull(SVnode *pVnode);
|
||||
|
||||
SMemAllocatorFactory *vBufPoolGetMAF(SVnode *pVnode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "mallocator.h"
|
||||
#include "sync.h"
|
||||
#include "tcoding.h"
|
||||
#include "tdlist.h"
|
||||
#include "tlist.h"
|
||||
#include "tlockfree.h"
|
||||
#include "tmacro.h"
|
||||
#include "wal.h"
|
||||
|
|
|
@ -13,19 +13,20 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_COMMON_INT_H_
|
||||
#define _TD_COMMON_INT_H_
|
||||
#ifndef _TD_VNODE_MAF_H_
|
||||
#define _TD_VNODE_MAF_H_
|
||||
|
||||
#include "vnode.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags);
|
||||
|
||||
|
||||
int vnodeOpenMAF(SVnode *pVnode);
|
||||
void vnodeCloseMAF(SVnode *pVnode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_COMMON_INT_H_*/
|
||||
#endif /*_TD_VNODE_MAF_H_*/
|
|
@ -27,7 +27,7 @@ SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize) {
|
|||
pVMA->capacity = capacity;
|
||||
pVMA->ssize = ssize;
|
||||
pVMA->lsize = lsize;
|
||||
tSListInit(&(pVMA->nlist));
|
||||
TD_SLIST_INIT(&(pVMA->nlist));
|
||||
|
||||
pVMA->pNode = vArenaNodeNew(capacity);
|
||||
if (pVMA->pNode == NULL) {
|
||||
|
@ -35,7 +35,7 @@ SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
tSListPush(&(pVMA->nlist), pVMA->pNode);
|
||||
TD_SLIST_PUSH(&(pVMA->nlist), pVMA->pNode);
|
||||
|
||||
return pVMA;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ void vmaDestroy(SVMemAllocator *pVMA) {
|
|||
if (pVMA) {
|
||||
while (TD_SLIST_NELES(&(pVMA->nlist)) > 1) {
|
||||
SVArenaNode *pNode = TD_SLIST_HEAD(&(pVMA->nlist));
|
||||
tSListPop(&(pVMA->nlist));
|
||||
TD_SLIST_POP(&(pVMA->nlist));
|
||||
vArenaNodeFree(pNode);
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ void vmaDestroy(SVMemAllocator *pVMA) {
|
|||
void vmaReset(SVMemAllocator *pVMA) {
|
||||
while (TD_SLIST_NELES(&(pVMA->nlist)) > 1) {
|
||||
SVArenaNode *pNode = TD_SLIST_HEAD(&(pVMA->nlist));
|
||||
tSListPop(&(pVMA->nlist));
|
||||
TD_SLIST_POP(&(pVMA->nlist));
|
||||
vArenaNodeFree(pNode);
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ void *vmaMalloc(SVMemAllocator *pVMA, uint64_t size) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
tSListPush(&(pVMA->nlist), pNode);
|
||||
TD_SLIST_PUSH(&(pVMA->nlist), pNode);
|
||||
}
|
||||
|
||||
ptr = pNode->ptr;
|
||||
|
|
|
@ -24,10 +24,13 @@ struct SVBufPool {
|
|||
TD_DLIST(SVMemAllocator) free;
|
||||
TD_DLIST(SVMemAllocator) incycle;
|
||||
SVMemAllocator *inuse;
|
||||
// MAF for submodules
|
||||
// SMemAllocatorFactory maf;
|
||||
// MAF for submodules to use
|
||||
SMemAllocatorFactory *pMAF;
|
||||
};
|
||||
|
||||
static SMemAllocator *vBufPoolCreateMA(SMemAllocatorFactory *pMAF);
|
||||
static void vBufPoolDestroyMA(SMemAllocatorFactory *pMAF, SMemAllocator *pMA);
|
||||
|
||||
int vnodeOpenBufPool(SVnode *pVnode) {
|
||||
uint64_t capacity;
|
||||
|
||||
|
@ -36,8 +39,8 @@ int vnodeOpenBufPool(SVnode *pVnode) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
tDListInit(&(pVnode->pBufPool->free));
|
||||
tDListInit(&(pVnode->pBufPool->incycle));
|
||||
TD_DLIST_INIT(&(pVnode->pBufPool->free));
|
||||
TD_DLIST_INIT(&(pVnode->pBufPool->incycle));
|
||||
|
||||
pVnode->pBufPool->inuse = NULL;
|
||||
|
||||
|
@ -51,9 +54,18 @@ int vnodeOpenBufPool(SVnode *pVnode) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
tDListAppend(&(pVnode->pBufPool->free), pVMA);
|
||||
TD_DLIST_APPEND(&(pVnode->pBufPool->free), pVMA);
|
||||
}
|
||||
|
||||
pVnode->pBufPool->pMAF = (SMemAllocatorFactory *)malloc(sizeof(SMemAllocatorFactory));
|
||||
if (pVnode->pBufPool->pMAF == NULL) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
}
|
||||
pVnode->pBufPool->pMAF->impl = pVnode;
|
||||
pVnode->pBufPool->pMAF->create = vBufPoolCreateMA;
|
||||
pVnode->pBufPool->pMAF->destroy = vBufPoolDestroyMA;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -64,14 +76,14 @@ void vnodeCloseBufPool(SVnode *pVnode) {
|
|||
while (true) {
|
||||
SVMemAllocator *pVMA = TD_DLIST_HEAD(&(pVnode->pBufPool->incycle));
|
||||
if (pVMA == NULL) break;
|
||||
tDListPop(&(pVnode->pBufPool->incycle), pVMA);
|
||||
TD_DLIST_POP(&(pVnode->pBufPool->incycle), pVMA);
|
||||
vmaDestroy(pVMA);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
SVMemAllocator *pVMA = TD_DLIST_HEAD(&(pVnode->pBufPool->free));
|
||||
if (pVMA == NULL) break;
|
||||
tDListPop(&(pVnode->pBufPool->free), pVMA);
|
||||
TD_DLIST_POP(&(pVnode->pBufPool->free), pVMA);
|
||||
vmaDestroy(pVMA);
|
||||
}
|
||||
|
||||
|
@ -85,7 +97,7 @@ int vnodeBufPoolSwitch(SVnode *pVnode) {
|
|||
|
||||
pVnode->pBufPool->inuse = NULL;
|
||||
|
||||
tDListAppend(&(pVnode->pBufPool->incycle), pvma);
|
||||
TD_DLIST_APPEND(&(pVnode->pBufPool->incycle), pvma);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -94,9 +106,9 @@ int vnodeBufPoolRecycle(SVnode *pVnode) {
|
|||
SVMemAllocator *pvma = TD_DLIST_HEAD(&(pBufPool->incycle));
|
||||
ASSERT(pvma != NULL);
|
||||
|
||||
tDListPop(&(pBufPool->incycle), pvma);
|
||||
TD_DLIST_POP(&(pBufPool->incycle), pvma);
|
||||
vmaReset(pvma);
|
||||
tDListAppend(&(pBufPool->free), pvma);
|
||||
TD_DLIST_APPEND(&(pBufPool->free), pvma);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -109,7 +121,7 @@ void *vnodeMalloc(SVnode *pVnode, uint64_t size) {
|
|||
// TODO: add sem_wait and sem_post
|
||||
pBufPool->inuse = TD_DLIST_HEAD(&(pBufPool->free));
|
||||
if (pBufPool->inuse) {
|
||||
tDListPop(&(pBufPool->free), pBufPool->inuse);
|
||||
TD_DLIST_POP(&(pBufPool->free), pBufPool->inuse);
|
||||
break;
|
||||
} else {
|
||||
// tsem_wait(&(pBufPool->hasFree));
|
||||
|
@ -125,195 +137,50 @@ bool vnodeBufPoolIsFull(SVnode *pVnode) {
|
|||
return vmaIsFull(pVnode->pBufPool->inuse);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
typedef enum {
|
||||
// Heap allocator
|
||||
E_V_HEAP_ALLOCATOR = 0,
|
||||
// Arena allocator
|
||||
E_V_ARENA_ALLOCATOR
|
||||
} EVMemAllocatorT;
|
||||
|
||||
typedef struct {
|
||||
/* TODO */
|
||||
} SVHeapAllocator;
|
||||
|
||||
typedef struct SVArenaNode {
|
||||
struct SVArenaNode *prev;
|
||||
uint64_t size;
|
||||
void * ptr;
|
||||
char data[];
|
||||
} SVArenaNode;
|
||||
|
||||
typedef struct {
|
||||
uint64_t ssize; // step size
|
||||
uint64_t lsize; // limit size
|
||||
SVArenaNode *inuse;
|
||||
SVArenaNode node;
|
||||
} SVArenaAllocator;
|
||||
|
||||
typedef struct {
|
||||
SVnode * pVnode;
|
||||
SListNode *pNode;
|
||||
} SVMAWrapper;
|
||||
|
||||
|
||||
static SListNode * vBufPoolNewNode(uint64_t capacity, EVMemAllocatorT type);
|
||||
static void vBufPoolFreeNode(SListNode *pNode);
|
||||
static SMemAllocator *vBufPoolCreateMA(SMemAllocatorFactory *pmaf);
|
||||
static void vBufPoolDestroyMA(SMemAllocatorFactory *pmaf, SMemAllocator *pma);
|
||||
static void * vBufPoolMalloc(SVMemAllocator *pvma, uint64_t size);
|
||||
SMemAllocatorFactory *vBufPoolGetMAF(SVnode *pVnode) { return pVnode->pBufPool->pMAF; }
|
||||
|
||||
/* ------------------------ STATIC METHODS ------------------------ */
|
||||
static SListNode *vBufPoolNewNode(uint64_t capacity, EVMemAllocatorT type) {
|
||||
SListNode * pNode;
|
||||
SVMemAllocator *pvma;
|
||||
uint64_t msize;
|
||||
uint64_t ssize = 4096; // TODO
|
||||
uint64_t lsize = 1024; // TODO
|
||||
|
||||
msize = sizeof(SListNode) + sizeof(SVMemAllocator);
|
||||
if (type == E_V_ARENA_ALLOCATOR) {
|
||||
msize += capacity;
|
||||
}
|
||||
|
||||
pNode = (SListNode *)calloc(1, msize);
|
||||
if (pNode == NULL) {
|
||||
// TODO: handle error
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pvma = (SVMemAllocator *)(pNode->data);
|
||||
pvma->capacity = capacity;
|
||||
pvma->type = type;
|
||||
|
||||
switch (type) {
|
||||
case E_V_ARENA_ALLOCATOR:
|
||||
vArenaAllocatorInit(&(pvma->vaa), capacity, ssize, lsize);
|
||||
break;
|
||||
case E_V_HEAP_ALLOCATOR:
|
||||
// vHeapAllocatorInit(&(pvma->vha));
|
||||
break;
|
||||
default:
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
return pNode;
|
||||
}
|
||||
|
||||
static void vBufPoolFreeNode(SListNode *pNode) {
|
||||
SVMemAllocator *pvma = (SVMemAllocator *)(pNode->data);
|
||||
|
||||
switch (pvma->type) {
|
||||
case E_V_ARENA_ALLOCATOR:
|
||||
vArenaAllocatorClear(&(pvma->vaa));
|
||||
break;
|
||||
case E_V_HEAP_ALLOCATOR:
|
||||
// vHeapAllocatorClear(&(pvma->vha));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
free(pNode);
|
||||
}
|
||||
|
||||
static void *vBufPoolMalloc(SVMemAllocator *pvma, uint64_t size) {
|
||||
void *ptr = NULL;
|
||||
|
||||
if (pvma->type == E_V_ARENA_ALLOCATOR) {
|
||||
SVArenaAllocator *pvaa = &(pvma->vaa);
|
||||
|
||||
if (POINTER_DISTANCE(pvaa->inuse->ptr, pvaa->inuse->data) + size > pvaa->inuse->size) {
|
||||
SVArenaNode *pNode = (SVArenaNode *)malloc(sizeof(*pNode) + MAX(size, pvaa->ssize));
|
||||
if (pNode == NULL) {
|
||||
// TODO: handle error
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pNode->prev = pvaa->inuse;
|
||||
pNode->size = MAX(size, pvaa->ssize);
|
||||
pNode->ptr = pNode->data;
|
||||
|
||||
pvaa->inuse = pNode;
|
||||
}
|
||||
|
||||
ptr = pvaa->inuse->ptr;
|
||||
pvaa->inuse->ptr = POINTER_SHIFT(ptr, size);
|
||||
} else if (pvma->type == E_V_HEAP_ALLOCATOR) {
|
||||
/* TODO */
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static SMemAllocator *vBufPoolCreateMA(SMemAllocatorFactory *pmaf) {
|
||||
typedef struct {
|
||||
SVnode * pVnode;
|
||||
SMemAllocator * pma;
|
||||
SVMemAllocator *pvma;
|
||||
SVMAWrapper * pvmaw;
|
||||
SVMemAllocator *pVMA;
|
||||
} SVMAWrapper;
|
||||
|
||||
pVnode = (SVnode *)(pmaf->impl);
|
||||
pma = (SMemAllocator *)calloc(1, sizeof(*pma) + sizeof(SVMAWrapper));
|
||||
if (pma == NULL) {
|
||||
// TODO: handle error
|
||||
static FORCE_INLINE void *vmaMaloocCb(SMemAllocator *pMA, uint64_t size) {
|
||||
SVMAWrapper *pWrapper = (SVMAWrapper *)(pMA->impl);
|
||||
|
||||
return vmaMalloc(pWrapper->pVMA, size);
|
||||
}
|
||||
|
||||
// TODO: Add atomic operations here
|
||||
static SMemAllocator *vBufPoolCreateMA(SMemAllocatorFactory *pMAF) {
|
||||
SMemAllocator *pMA;
|
||||
SVnode * pVnode = (SVnode *)(pMAF->impl);
|
||||
SVMAWrapper * pWrapper;
|
||||
|
||||
pMA = (SMemAllocator *)calloc(1, sizeof(*pMA) + sizeof(SVMAWrapper));
|
||||
if (pMA == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
pvmaw = (SVMAWrapper *)POINTER_SHIFT(pma, sizeof(*pma));
|
||||
|
||||
// No allocator used currently
|
||||
if (pVnode->pBufPool->inuse == NULL) {
|
||||
while (listNEles(&(pVnode->pBufPool->free)) == 0) {
|
||||
// TODO: wait until all released ro kill query
|
||||
// tsem_wait();
|
||||
ASSERT(0);
|
||||
}
|
||||
pVnode->pBufPool->inuse->_ref.val++;
|
||||
pWrapper = POINTER_SHIFT(pMA, sizeof(*pMA));
|
||||
pWrapper->pVnode = pVnode;
|
||||
pWrapper->pVMA = pVnode->pBufPool->inuse;
|
||||
|
||||
pVnode->pBufPool->inuse = tdListPopHead(&(pVnode->pBufPool->free));
|
||||
pvma = (SVMemAllocator *)(pVnode->pBufPool->inuse->data);
|
||||
T_REF_INIT_VAL(pvma, 1);
|
||||
} else {
|
||||
pvma = (SVMemAllocator *)(pVnode->pBufPool->inuse->data);
|
||||
}
|
||||
pMA->impl = pWrapper;
|
||||
TD_MA_MALLOC_FUNC(pMA) = vmaMaloocCb;
|
||||
|
||||
T_REF_INC(pvma);
|
||||
|
||||
pvmaw->pVnode = pVnode;
|
||||
pvmaw->pNode = pVnode->pBufPool->inuse;
|
||||
|
||||
pma->impl = pvmaw;
|
||||
pma->malloc = NULL;
|
||||
pma->calloc = NULL; /* TODO */
|
||||
pma->realloc = NULL; /* TODO */
|
||||
pma->free = NULL; /* TODO */
|
||||
pma->usage = NULL; /* TODO */
|
||||
|
||||
return pma;
|
||||
return pMA;
|
||||
}
|
||||
|
||||
static void vBufPoolDestroyMA(SMemAllocatorFactory *pmaf, SMemAllocator *pma) { /* TODO */
|
||||
SVnode * pVnode = (SVnode *)(pmaf->impl);
|
||||
SListNode * pNode = ((SVMAWrapper *)(pma->impl))->pNode;
|
||||
SVMemAllocator *pvma = (SVMemAllocator *)(pNode->data);
|
||||
static void vBufPoolDestroyMA(SMemAllocatorFactory *pMAF, SMemAllocator *pMA) {
|
||||
SVMAWrapper * pWrapper = (SVMAWrapper *)(pMA->impl);
|
||||
SVnode * pVnode = pWrapper->pVnode;
|
||||
SVMemAllocator *pVMA = pWrapper->pVMA;
|
||||
|
||||
if (T_REF_DEC(pvma) == 0) {
|
||||
if (pvma->type == E_V_ARENA_ALLOCATOR) {
|
||||
SVArenaAllocator *pvaa = &(pvma->vaa);
|
||||
while (pvaa->inuse != &(pvaa->node)) {
|
||||
SVArenaNode *pNode = pvaa->inuse;
|
||||
pvaa->inuse = pNode->prev;
|
||||
/* code */
|
||||
}
|
||||
|
||||
pvaa->inuse->ptr = pvaa->inuse->data;
|
||||
} else if (pvma->type == E_V_HEAP_ALLOCATOR) {
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
// Move node from incycle to free
|
||||
tdListAppendNode(&(pVnode->pBufPool->free), tdListPopNode(&(pVnode->pBufPool->incycle), pNode));
|
||||
// tsem_post(); todo: sem_post
|
||||
free(pMA);
|
||||
if (--pVMA->_ref.val == 0) {
|
||||
TD_DLIST_POP(&(pVnode->pBufPool->incycle), pVMA);
|
||||
TD_DLIST_APPEND(&(pVnode->pBufPool->free), pVMA);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -25,6 +25,10 @@ int vnodeAsyncCommit(SVnode *pVnode) {
|
|||
pTask->execute = vnodeCommit; // TODO
|
||||
pTask->arg = pVnode; // TODO
|
||||
|
||||
tsdbPrepareCommit(pVnode->pTsdb);
|
||||
// metaPrepareCommit(pVnode->pMeta);
|
||||
// walPreapareCommit(pVnode->pWal);
|
||||
|
||||
vnodeScheduleTask(pTask);
|
||||
return 0;
|
||||
}
|
||||
|
@ -32,6 +36,10 @@ int vnodeAsyncCommit(SVnode *pVnode) {
|
|||
int vnodeCommit(void *arg) {
|
||||
SVnode *pVnode = (SVnode *)arg;
|
||||
|
||||
metaCommit(pVnode->pMeta);
|
||||
tqCommit(pVnode->pTq);
|
||||
tsdbCommit(pVnode->pTq);
|
||||
|
||||
vnodeBufPoolRecycle(pVnode);
|
||||
// TODO
|
||||
return 0;
|
||||
|
|
|
@ -94,7 +94,7 @@ static int vnodeOpenImpl(SVnode *pVnode) {
|
|||
|
||||
// Open meta
|
||||
sprintf(dir, "%s/meta", pVnode->path);
|
||||
pVnode->pMeta = metaOpen(dir, &(pVnode->config.metaCfg));
|
||||
pVnode->pMeta = metaOpen(dir, &(pVnode->config.metaCfg), vBufPoolGetMAF(pVnode));
|
||||
if (pVnode->pMeta == NULL) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
|
@ -102,7 +102,7 @@ static int vnodeOpenImpl(SVnode *pVnode) {
|
|||
|
||||
// Open tsdb
|
||||
sprintf(dir, "%s/tsdb", pVnode->path);
|
||||
pVnode->pTsdb = tsdbOpen(dir, &(pVnode->config.tsdbCfg));
|
||||
pVnode->pTsdb = tsdbOpen(dir, &(pVnode->config.tsdbCfg), vBufPoolGetMAF(pVnode));
|
||||
if (pVnode->pTsdb == NULL) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
|
@ -110,7 +110,7 @@ static int vnodeOpenImpl(SVnode *pVnode) {
|
|||
|
||||
// TODO: Open TQ
|
||||
sprintf(dir, "%s/tq", pVnode->path);
|
||||
pVnode->pTq = tqOpen(dir, &(pVnode->config.tqCfg), NULL, NULL);
|
||||
pVnode->pTq = tqOpen(dir, &(pVnode->config.tqCfg), NULL, vBufPoolGetMAF(pVnode));
|
||||
if (pVnode->pTq == NULL) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
|
@ -131,7 +131,9 @@ static int vnodeOpenImpl(SVnode *pVnode) {
|
|||
static void vnodeCloseImpl(SVnode *pVnode) {
|
||||
if (pVnode) {
|
||||
vnodeCloseBufPool(pVnode);
|
||||
tsdbClose(pVnode->pTsdb);
|
||||
metaClose(pVnode->pMeta);
|
||||
tsdbClose(pVnode->pTsdb);
|
||||
tqClose(pVnode->pTq);
|
||||
walClose(pVnode->pWal);
|
||||
}
|
||||
}
|
|
@ -34,7 +34,7 @@ int vnodeInit(uint16_t nthreads) {
|
|||
|
||||
pthread_mutex_init(&(vnodeMgr.mutex), NULL);
|
||||
pthread_cond_init(&(vnodeMgr.hasTask), NULL);
|
||||
tDListInit(&(vnodeMgr.queue));
|
||||
TD_DLIST_INIT(&(vnodeMgr.queue));
|
||||
|
||||
for (uint16_t i = 0; i < nthreads; i++) {
|
||||
pthread_create(&(vnodeMgr.threads[i]), NULL, loop, NULL);
|
||||
|
@ -77,7 +77,7 @@ void vnodeClear() {
|
|||
int vnodeScheduleTask(SVnodeTask* pTask) {
|
||||
pthread_mutex_lock(&(vnodeMgr.mutex));
|
||||
|
||||
tDListAppend(&(vnodeMgr.queue), pTask);
|
||||
TD_DLIST_APPEND(&(vnodeMgr.queue), pTask);
|
||||
|
||||
pthread_cond_signal(&(vnodeMgr.hasTask));
|
||||
|
||||
|
@ -101,7 +101,7 @@ static void* loop(void* arg) {
|
|||
pthread_cond_wait(&(vnodeMgr.hasTask), &(vnodeMgr.mutex));
|
||||
}
|
||||
} else {
|
||||
tDListPop(&(vnodeMgr.queue), pTask);
|
||||
TD_DLIST_POP(&(vnodeMgr.queue), pTask);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,9 +25,10 @@ int vnodeBuildReq(void **buf, const SVnodeReq *pReq, uint8_t type) {
|
|||
switch (type) {
|
||||
case TSDB_MSG_TYPE_CREATE_TABLE:
|
||||
tsize += vnodeBuildCreateTableReq(buf, &(pReq->ctReq));
|
||||
break;
|
||||
case TSDB_MSG_TYPE_SUBMIT:
|
||||
/* code */
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
// https://stackoverflow.com/questions/8565666/benchmarking-with-googletest
|
||||
// https://github.com/google/benchmark
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
#include "vnode.h"
|
||||
|
||||
static STSchema *createBasicSchema() {
|
||||
static STSchema *vtCreateBasicSchema() {
|
||||
STSchemaBuilder sb;
|
||||
STSchema * pSchema = NULL;
|
||||
|
||||
|
@ -32,7 +32,7 @@ static STSchema *createBasicSchema() {
|
|||
return pSchema;
|
||||
}
|
||||
|
||||
static STSchema *createBasicTagSchema() {
|
||||
static STSchema *vtCreateBasicTagSchema() {
|
||||
STSchemaBuilder sb;
|
||||
STSchema * pSchema = NULL;
|
||||
|
||||
|
@ -50,7 +50,7 @@ static STSchema *createBasicTagSchema() {
|
|||
return pSchema;
|
||||
}
|
||||
|
||||
static SKVRow createBasicTag() {
|
||||
static SKVRow vtCreateBasicTag() {
|
||||
SKVRowBuilder rb;
|
||||
SKVRow pTag;
|
||||
|
||||
|
@ -71,118 +71,203 @@ static SKVRow createBasicTag() {
|
|||
return pTag;
|
||||
}
|
||||
|
||||
#if 0
|
||||
TEST(vnodeApiTest, test_create_table_encode_and_decode_function) {
|
||||
tb_uid_t suid = 1638166374163;
|
||||
STSchema *pSchema = createBasicSchema();
|
||||
STSchema *pTagSchema = createBasicTagSchema();
|
||||
char tbname[128] = "st";
|
||||
char * buffer = new char[1024];
|
||||
void * pBuf = (void *)buffer;
|
||||
static void vtBuildCreateStbReq(tb_uid_t suid, char *tbname, SRpcMsg **ppMsg) {
|
||||
SRpcMsg * pMsg;
|
||||
STSchema *pSchema;
|
||||
STSchema *pTagSchema;
|
||||
int zs;
|
||||
void * pBuf;
|
||||
|
||||
pSchema = vtCreateBasicSchema();
|
||||
pTagSchema = vtCreateBasicTagSchema();
|
||||
|
||||
SVnodeReq vCreateSTbReq = VNODE_INIT_CREATE_STB_REQ(tbname, UINT32_MAX, UINT32_MAX, suid, pSchema, pTagSchema);
|
||||
|
||||
zs = vnodeBuildReq(NULL, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
|
||||
pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + zs);
|
||||
pMsg->msgType = TSDB_MSG_TYPE_CREATE_TABLE;
|
||||
pMsg->contLen = zs;
|
||||
pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(SRpcMsg));
|
||||
|
||||
pBuf = pMsg->pCont;
|
||||
vnodeBuildReq(&pBuf, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
|
||||
META_CLEAR_TB_CFG(&vCreateSTbReq);
|
||||
|
||||
SVnodeReq decoded_req;
|
||||
tdFreeSchema(pSchema);
|
||||
tdFreeSchema(pTagSchema);
|
||||
|
||||
vnodeParseReq(buffer, &decoded_req, TSDB_MSG_TYPE_CREATE_TABLE);
|
||||
|
||||
int k = 10;
|
||||
*ppMsg = pMsg;
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) {
|
||||
static void vtBuildCreateCtbReq(tb_uid_t suid, char *tbname, SRpcMsg **ppMsg) {
|
||||
SRpcMsg *pMsg;
|
||||
int tz;
|
||||
SKVRow pTag = vtCreateBasicTag();
|
||||
|
||||
SVnodeReq vCreateCTbReq = VNODE_INIT_CREATE_CTB_REQ(tbname, UINT32_MAX, UINT32_MAX, suid, pTag);
|
||||
|
||||
tz = vnodeBuildReq(NULL, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
|
||||
pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + tz);
|
||||
pMsg->msgType = TSDB_MSG_TYPE_CREATE_TABLE;
|
||||
pMsg->contLen = tz;
|
||||
pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(*pMsg));
|
||||
void *pBuf = pMsg->pCont;
|
||||
|
||||
vnodeBuildReq(&pBuf, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
|
||||
META_CLEAR_TB_CFG(&vCreateCTbReq);
|
||||
free(pTag);
|
||||
|
||||
*ppMsg = pMsg;
|
||||
}
|
||||
|
||||
static void vtBuildCreateNtbReq(char *tbname, SRpcMsg **ppMsg) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
static void vtBuildSubmitReq(SRpcMsg **ppMsg) {
|
||||
SRpcMsg * pMsg;
|
||||
SSubmitMsg *pSubmitMsg;
|
||||
SSubmitBlk *pSubmitBlk;
|
||||
int tz = 1024; // TODO
|
||||
|
||||
pMsg = (SRpcMsg *)malloc(sizeof(*pMsg) + tz);
|
||||
pMsg->msgType = TSDB_MSG_TYPE_SUBMIT;
|
||||
pMsg->contLen = tz;
|
||||
pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(*pMsg));
|
||||
|
||||
// For submit msg header
|
||||
pSubmitMsg = (SSubmitMsg *)(pMsg->pCont);
|
||||
// pSubmitMsg->header.contLen = 0;
|
||||
// pSubmitMsg->header.vgId = 0;
|
||||
// pSubmitMsg->length = 0;
|
||||
pSubmitMsg->numOfBlocks = 1;
|
||||
|
||||
// For submit blk
|
||||
pSubmitBlk = (SSubmitBlk *)(pSubmitMsg->blocks);
|
||||
pSubmitBlk->uid = 0;
|
||||
pSubmitBlk->tid = 0;
|
||||
pSubmitBlk->padding = 0;
|
||||
pSubmitBlk->sversion = 0;
|
||||
pSubmitBlk->dataLen = 0;
|
||||
pSubmitBlk->numOfRows = 0;
|
||||
|
||||
// For row batch
|
||||
|
||||
*ppMsg = pMsg;
|
||||
}
|
||||
|
||||
static void vtClearMsgBatch(SArray *pMsgArr) {
|
||||
SRpcMsg *pMsg;
|
||||
for (size_t i = 0; i < taosArrayGetSize(pMsgArr); i++) {
|
||||
pMsg = *(SRpcMsg **)taosArrayGet(pMsgArr, i);
|
||||
free(pMsg);
|
||||
}
|
||||
|
||||
taosArrayClear(pMsgArr);
|
||||
}
|
||||
|
||||
TEST(vnodeApiTest, vnode_simple_create_table_test) {
|
||||
tb_uid_t suid = 1638166374163;
|
||||
SRpcMsg *pMsg;
|
||||
SArray * pMsgArr = NULL;
|
||||
SVnode * pVnode;
|
||||
int rcode;
|
||||
int ntables = 1000000;
|
||||
int batch = 10;
|
||||
char tbname[128];
|
||||
|
||||
pMsgArr = (SArray *)taosArrayInit(batch, sizeof(pMsg));
|
||||
|
||||
vnodeDestroy("vnode1");
|
||||
GTEST_ASSERT_GE(vnodeInit(2), 0);
|
||||
|
||||
// CREATE AND OPEN A VNODE
|
||||
pVnode = vnodeOpen("vnode1", NULL);
|
||||
ASSERT_NE(pVnode, nullptr);
|
||||
|
||||
// CREATE A SUPER TABLE
|
||||
sprintf(tbname, "st");
|
||||
vtBuildCreateStbReq(suid, tbname, &pMsg);
|
||||
taosArrayPush(pMsgArr, &pMsg);
|
||||
rcode = vnodeProcessWMsgs(pVnode, pMsgArr);
|
||||
ASSERT_EQ(rcode, 0);
|
||||
vtClearMsgBatch(pMsgArr);
|
||||
|
||||
// CREATE A LOT OF CHILD TABLES
|
||||
for (int i = 0; i < ntables / batch; i++) {
|
||||
// Build request batch
|
||||
for (int j = 0; j < batch; j++) {
|
||||
sprintf(tbname, "ct%d", i * batch + j + 1);
|
||||
vtBuildCreateCtbReq(suid, tbname, &pMsg);
|
||||
taosArrayPush(pMsgArr, &pMsg);
|
||||
}
|
||||
|
||||
// Process request batch
|
||||
rcode = vnodeProcessWMsgs(pVnode, pMsgArr);
|
||||
ASSERT_EQ(rcode, 0);
|
||||
|
||||
// Clear request batch
|
||||
vtClearMsgBatch(pMsgArr);
|
||||
}
|
||||
|
||||
// CLOSE THE VNODE
|
||||
vnodeClose(pVnode);
|
||||
vnodeClear();
|
||||
|
||||
taosArrayDestroy(pMsgArr);
|
||||
}
|
||||
|
||||
TEST(vnodeApiTest, vnode_simple_insert_test) {
|
||||
const char *vname = "vnode2";
|
||||
char tbname[128];
|
||||
tb_uid_t suid = 1638166374163;
|
||||
SRpcMsg * pMsg;
|
||||
SArray * pMsgArr;
|
||||
int rcode;
|
||||
SVnode * pVnode;
|
||||
int batch = 1;
|
||||
int loop = 1000000;
|
||||
|
||||
pMsgArr = (SArray *)taosArrayInit(0, sizeof(pMsg));
|
||||
|
||||
vnodeDestroy(vname);
|
||||
|
||||
GTEST_ASSERT_GE(vnodeInit(2), 0);
|
||||
|
||||
// Create and open a vnode
|
||||
SVnode *pVnode = vnodeOpen("vnode1", NULL);
|
||||
ASSERT_NE(pVnode, nullptr);
|
||||
// Open a vnode
|
||||
pVnode = vnodeOpen(vname, NULL);
|
||||
GTEST_ASSERT_NE(pVnode, nullptr);
|
||||
|
||||
tb_uid_t suid = 1638166374163;
|
||||
{
|
||||
// Create a super table
|
||||
STSchema *pSchema = createBasicSchema();
|
||||
STSchema *pTagSchema = createBasicTagSchema();
|
||||
char tbname[128] = "st";
|
||||
// 1. CREATE A SUPER TABLE
|
||||
sprintf(tbname, "st");
|
||||
vtBuildCreateStbReq(suid, tbname, &pMsg);
|
||||
taosArrayPush(pMsgArr, &pMsg);
|
||||
rcode = vnodeProcessWMsgs(pVnode, pMsgArr);
|
||||
GTEST_ASSERT_EQ(rcode, 0);
|
||||
vtClearMsgBatch(pMsgArr);
|
||||
|
||||
SArray * pMsgs = (SArray *)taosArrayInit(1, sizeof(SRpcMsg *));
|
||||
SVnodeReq vCreateSTbReq = VNODE_INIT_CREATE_STB_REQ(tbname, UINT32_MAX, UINT32_MAX, suid, pSchema, pTagSchema);
|
||||
// 2. CREATE A CHILD TABLE
|
||||
sprintf(tbname, "t0");
|
||||
vtBuildCreateCtbReq(suid, tbname, &pMsg);
|
||||
taosArrayPush(pMsgArr, &pMsg);
|
||||
rcode = vnodeProcessWMsgs(pVnode, pMsgArr);
|
||||
GTEST_ASSERT_EQ(rcode, 0);
|
||||
vtClearMsgBatch(pMsgArr);
|
||||
|
||||
int zs = vnodeBuildReq(NULL, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
|
||||
SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + zs);
|
||||
pMsg->msgType = TSDB_MSG_TYPE_CREATE_TABLE;
|
||||
pMsg->contLen = zs;
|
||||
pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(SRpcMsg));
|
||||
|
||||
void *pBuf = pMsg->pCont;
|
||||
|
||||
vnodeBuildReq(&pBuf, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
|
||||
META_CLEAR_TB_CFG(&vCreateSTbReq);
|
||||
|
||||
taosArrayPush(pMsgs, &(pMsg));
|
||||
|
||||
vnodeProcessWMsgs(pVnode, pMsgs);
|
||||
|
||||
free(pMsg);
|
||||
taosArrayDestroy(pMsgs);
|
||||
tdFreeSchema(pSchema);
|
||||
tdFreeSchema(pTagSchema);
|
||||
}
|
||||
|
||||
{
|
||||
// Create some child tables
|
||||
int ntables = 1000000;
|
||||
int batch = 10;
|
||||
for (int i = 0; i < ntables / batch; i++) {
|
||||
SArray *pMsgs = (SArray *)taosArrayInit(batch, sizeof(SRpcMsg *));
|
||||
for (int j = 0; j < batch; j++) {
|
||||
SKVRow pTag = createBasicTag();
|
||||
char tbname[128];
|
||||
sprintf(tbname, "tb%d", i * batch + j);
|
||||
SVnodeReq vCreateCTbReq = VNODE_INIT_CREATE_CTB_REQ(tbname, UINT32_MAX, UINT32_MAX, suid, pTag);
|
||||
|
||||
int tz = vnodeBuildReq(NULL, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
|
||||
SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + tz);
|
||||
pMsg->msgType = TSDB_MSG_TYPE_CREATE_TABLE;
|
||||
pMsg->contLen = tz;
|
||||
pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(*pMsg));
|
||||
void *pBuf = pMsg->pCont;
|
||||
|
||||
vnodeBuildReq(&pBuf, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
|
||||
META_CLEAR_TB_CFG(&vCreateCTbReq);
|
||||
free(pTag);
|
||||
|
||||
taosArrayPush(pMsgs, &(pMsg));
|
||||
}
|
||||
|
||||
vnodeProcessWMsgs(pVnode, pMsgs);
|
||||
|
||||
for (int j = 0; j < batch; j++) {
|
||||
SRpcMsg *pMsg = *(SRpcMsg **)taosArrayPop(pMsgs);
|
||||
free(pMsg);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pMsgs);
|
||||
|
||||
// std::cout << "the " << i << "th batch is created" << std::endl;
|
||||
// 3. WRITE A LOT OF TIME-SERIES DATA
|
||||
for (int j = 0; j < loop; j++) {
|
||||
for (int i = 0; i < batch; i++) {
|
||||
vtBuildSubmitReq(&pMsg);
|
||||
taosArrayPush(pMsgArr, &pMsg);
|
||||
}
|
||||
rcode = vnodeProcessWMsgs(pVnode, pMsgArr);
|
||||
GTEST_ASSERT_EQ(rcode, 0);
|
||||
vtClearMsgBatch(pMsgArr);
|
||||
}
|
||||
|
||||
// Close the vnode
|
||||
vnodeClose(pVnode);
|
||||
|
||||
vnodeClear();
|
||||
}
|
||||
|
||||
TEST(vnodeApiTest, DISABLED_vnode_process_create_table) {
|
||||
STSchema * pSchema = NULL;
|
||||
STSchema * pTagSchema = NULL;
|
||||
char stname[15];
|
||||
SVCreateTableReq pReq = META_INIT_STB_CFG(stname, UINT32_MAX, UINT32_MAX, 0, pSchema, pTagSchema);
|
||||
|
||||
int k = 10;
|
||||
|
||||
META_CLEAR_TB_CFG(pReq);
|
||||
}
|
||||
taosArrayDestroy(pMsgArr);
|
||||
}
|
|
@ -34,7 +34,7 @@ extern "C" {
|
|||
struct SMeta {
|
||||
char* path;
|
||||
SMetaCfg options;
|
||||
SMetaDB* pDB;
|
||||
SMetaDB* pDB;
|
||||
SMetaIdx* pIdx;
|
||||
SMetaCache* pCache;
|
||||
STbUidGenerator uidGnrt;
|
||||
|
|
|
@ -17,27 +17,27 @@
|
|||
|
||||
#include "metaDef.h"
|
||||
|
||||
static SMeta *metaNew(const char *path, const SMetaCfg *pMetaOptions);
|
||||
static SMeta *metaNew(const char *path, const SMetaCfg *pMetaCfg, SMemAllocatorFactory *pMAF);
|
||||
static void metaFree(SMeta *pMeta);
|
||||
static int metaOpenImpl(SMeta *pMeta);
|
||||
static void metaCloseImpl(SMeta *pMeta);
|
||||
|
||||
SMeta *metaOpen(const char *path, const SMetaCfg *pMetaOptions) {
|
||||
SMeta *metaOpen(const char *path, const SMetaCfg *pMetaCfg, SMemAllocatorFactory *pMAF) {
|
||||
SMeta *pMeta = NULL;
|
||||
|
||||
// Set default options
|
||||
if (pMetaOptions == NULL) {
|
||||
pMetaOptions = &defaultMetaOptions;
|
||||
if (pMetaCfg == NULL) {
|
||||
pMetaCfg = &defaultMetaOptions;
|
||||
}
|
||||
|
||||
// Validate the options
|
||||
if (metaValidateOptions(pMetaOptions) < 0) {
|
||||
if (metaValidateOptions(pMetaCfg) < 0) {
|
||||
// TODO: deal with error
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Allocate handle
|
||||
pMeta = metaNew(path, pMetaOptions);
|
||||
pMeta = metaNew(path, pMetaCfg, pMAF);
|
||||
if (pMeta == NULL) {
|
||||
// TODO: handle error
|
||||
return NULL;
|
||||
|
@ -65,7 +65,7 @@ void metaClose(SMeta *pMeta) {
|
|||
void metaRemove(const char *path) { taosRemoveDir(path); }
|
||||
|
||||
/* ------------------------ STATIC METHODS ------------------------ */
|
||||
static SMeta *metaNew(const char *path, const SMetaCfg *pMetaOptions) {
|
||||
static SMeta *metaNew(const char *path, const SMetaCfg *pMetaCfg, SMemAllocatorFactory *pMAF) {
|
||||
SMeta *pMeta;
|
||||
size_t psize = strlen(path);
|
||||
|
||||
|
@ -80,7 +80,8 @@ static SMeta *metaNew(const char *path, const SMetaCfg *pMetaOptions) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
metaOptionsCopy(&(pMeta->options), pMetaOptions);
|
||||
metaOptionsCopy(&(pMeta->options), pMetaCfg);
|
||||
pMeta->pmaf = pMAF;
|
||||
|
||||
return pMeta;
|
||||
};
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
#include "mallocator.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tdlist.h"
|
||||
#include "tlist.h"
|
||||
#include "thash.h"
|
||||
#include "tskiplist.h"
|
||||
|
||||
|
|
|
@ -15,7 +15,19 @@
|
|||
|
||||
#include "tsdbDef.h"
|
||||
|
||||
int tsdbPrepareCommit(STsdb *pTsdb) {
|
||||
if (pTsdb->mem == NULL) return 0;
|
||||
|
||||
// tsem_wait(&(pTsdb->canCommit));
|
||||
ASSERT(pTsdb->imem == NULL);
|
||||
|
||||
pTsdb->imem = pTsdb->mem;
|
||||
pTsdb->mem = NULL;
|
||||
}
|
||||
|
||||
int tsdbCommit(STsdb *pTsdb) {
|
||||
// TODO
|
||||
pTsdb->imem = NULL;
|
||||
// tsem_post(&(pTsdb->canCommit));
|
||||
return 0;
|
||||
}
|
|
@ -15,27 +15,27 @@
|
|||
|
||||
#include "tsdbDef.h"
|
||||
|
||||
static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbOptions);
|
||||
static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF);
|
||||
static void tsdbFree(STsdb *pTsdb);
|
||||
static int tsdbOpenImpl(STsdb *pTsdb);
|
||||
static void tsdbCloseImpl(STsdb *pTsdb);
|
||||
|
||||
STsdb *tsdbOpen(const char *path, const STsdbCfg *pTsdbOptions) {
|
||||
STsdb *tsdbOpen(const char *path, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF) {
|
||||
STsdb *pTsdb = NULL;
|
||||
|
||||
// Set default TSDB Options
|
||||
if (pTsdbOptions == NULL) {
|
||||
pTsdbOptions = &defautlTsdbOptions;
|
||||
if (pTsdbCfg == NULL) {
|
||||
pTsdbCfg = &defautlTsdbOptions;
|
||||
}
|
||||
|
||||
// Validate the options
|
||||
if (tsdbValidateOptions(pTsdbOptions) < 0) {
|
||||
if (tsdbValidateOptions(pTsdbCfg) < 0) {
|
||||
// TODO: handle error
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Create the handle
|
||||
pTsdb = tsdbNew(path, pTsdbOptions);
|
||||
pTsdb = tsdbNew(path, pTsdbCfg, pMAF);
|
||||
if (pTsdb == NULL) {
|
||||
// TODO: handle error
|
||||
return NULL;
|
||||
|
@ -62,7 +62,7 @@ void tsdbClose(STsdb *pTsdb) {
|
|||
void tsdbRemove(const char *path) { taosRemoveDir(path); }
|
||||
|
||||
/* ------------------------ STATIC METHODS ------------------------ */
|
||||
static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbOptions) {
|
||||
static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF) {
|
||||
STsdb *pTsdb = NULL;
|
||||
|
||||
pTsdb = (STsdb *)calloc(1, sizeof(STsdb));
|
||||
|
@ -72,7 +72,8 @@ static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbOptions) {
|
|||
}
|
||||
|
||||
pTsdb->path = strdup(path);
|
||||
tsdbOptionsCopy(&(pTsdb->options), pTsdbOptions);
|
||||
tsdbOptionsCopy(&(pTsdb->options), pTsdbCfg);
|
||||
pTsdb->pmaf = pMAF;
|
||||
|
||||
return pTsdb;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ STsdbMemTable *tsdbNewMemTable(SMemAllocatorFactory *pMAF) {
|
|||
pMA = (*pMAF->create)(pMAF);
|
||||
ASSERT(pMA != NULL);
|
||||
|
||||
pMemTable = (STsdbMemTable *)((*pMA->malloc)(pMA, sizeof(*pMemTable)));
|
||||
pMemTable = (STsdbMemTable *)TD_MA_MALLOC(pMA, sizeof(*pMemTable));
|
||||
if (pMemTable == NULL) {
|
||||
(*pMAF->destroy)(pMAF, pMA);
|
||||
return NULL;
|
||||
|
@ -62,7 +62,7 @@ STsdbMemTable *tsdbNewMemTable(SMemAllocatorFactory *pMAF) {
|
|||
pMemTable->keyMax = TSKEY_MIN;
|
||||
pMemTable->nRow = 0;
|
||||
pMemTable->pMA = pMA;
|
||||
tSListInit(&(pMemTable->list));
|
||||
TD_SLIST_INIT(&(pMemTable->list));
|
||||
|
||||
// TODO
|
||||
return pMemTable;
|
||||
|
@ -71,7 +71,7 @@ STsdbMemTable *tsdbNewMemTable(SMemAllocatorFactory *pMAF) {
|
|||
void tsdbFreeMemTable(SMemAllocatorFactory *pMAF, STsdbMemTable *pMemTable) {
|
||||
SMemAllocator *pMA = pMemTable->pMA;
|
||||
|
||||
if (pMA->free) {
|
||||
if (TD_MA_FREE_FUNC(pMA) != NULL) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
}
|
||||
|
@ -81,12 +81,12 @@ void tsdbFreeMemTable(SMemAllocatorFactory *pMAF, STsdbMemTable *pMemTable) {
|
|||
|
||||
int tsdbInsertDataToMemTable(STsdbMemTable *pMemTable, SSubmitMsg *pMsg) {
|
||||
SMemAllocator *pMA = pMemTable->pMA;
|
||||
STbData * pTbData = (STbData *)((*pMA->malloc)(pMA, sizeof(*pTbData)));
|
||||
STbData * pTbData = (STbData *)TD_MA_MALLOC(pMA, sizeof(*pTbData));
|
||||
if (pTbData == NULL) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
tSListPush(&(pMemTable->list), pTbData);
|
||||
TD_SLIST_PUSH(&(pMemTable->list), pTbData);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -10,4 +10,4 @@ add_subdirectory(catalog)
|
|||
add_subdirectory(executor)
|
||||
add_subdirectory(planner)
|
||||
add_subdirectory(function)
|
||||
add_subdirectory(query)
|
||||
add_subdirectory(qcom)
|
||||
|
|
|
@ -8,7 +8,7 @@ target_include_directories(
|
|||
|
||||
target_link_libraries(
|
||||
catalog
|
||||
PRIVATE os util common transport query
|
||||
PRIVATE os util transport qcom
|
||||
)
|
||||
|
||||
ADD_SUBDIRECTORY(test)
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue