Merge pull request #9173 from taosdata/feature/dnode3

shell
This commit is contained in:
Shengliang Guan 2021-12-17 15:51:06 +08:00 committed by GitHub
commit 140de58e10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 140 additions and 131 deletions

View File

@ -435,3 +435,9 @@ void setResultDataPtr(SClientResultInfo* pResultInfo, TAOS_FIELD* pFields, int32
offset += pResultInfo->fields[i].bytes; 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; }

View File

@ -1 +1 @@
#add_subdirectory(shell) add_subdirectory(shell)

View File

@ -1,13 +1,18 @@
aux_source_directory(src SHELL_SRC) aux_source_directory(src SHELL_SRC)
list(REMOVE_ITEM SHELL_SRC ./src/shellWindows.c) list(REMOVE_ITEM SHELL_SRC src/shellWindows.c)
list(REMOVE_ITEM SHELL_SRC ./src/shellDarwin.c) list(REMOVE_ITEM SHELL_SRC src/shellDarwin.c)
add_executable(shell ${SHELL_SRC}) add_executable(shell ${SHELL_SRC})
target_link_libraries( target_link_libraries(
shell shell
PUBLIC taos PUBLIC taos
PUBLIC util PUBLIC util
PUBLIC common
PUBLIC os PUBLIC os
) )
target_include_directories(
shell
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
)
SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos) SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos)

View File

@ -13,13 +13,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __SHELL__ #ifndef _TD_SHELL_H_
#define __SHELL__ #define _TD_SHELL_H_
#include "../../../../include/client/taos.h" #include "os.h"
#include "stdbool.h"
#include "taos.h"
#include "taosdef.h" #include "taosdef.h"
#include "tsclient.h"
#define MAX_USERNAME_SIZE 64 #define MAX_USERNAME_SIZE 64
#define MAX_DBNAME_SIZE 64 #define MAX_DBNAME_SIZE 64

View File

@ -19,6 +19,8 @@
#include "shell.h" #include "shell.h"
#include "shellCommand.h" #include "shellCommand.h"
#include <regex.h>
extern int wcwidth(wchar_t c); extern int wcwidth(wchar_t c);
extern int wcswidth(const wchar_t *s, size_t n); extern int wcswidth(const wchar_t *s, size_t n);
typedef struct { typedef struct {

View File

@ -21,13 +21,14 @@
#include "os.h" #include "os.h"
#include "shell.h" #include "shell.h"
#include "shellCommand.h" #include "shellCommand.h"
#include "tutil.h"
#include "taosdef.h" #include "taosdef.h"
#include "taoserror.h" #include "taoserror.h"
#include "tglobal.h" #include "tglobal.h"
#include "tsclient.h" #include "ttypes.h"
#include "tutil.h"
#include <regex.h> #include <regex.h>
#include <wordexp.h>
/**************** Global variables ****************/ /**************** Global variables ****************/
#ifdef _TD_POWER_ #ifdef _TD_POWER_
@ -89,12 +90,6 @@ TAOS *shellInit(SShellArguments *_args) {
_args->user = TSDB_DEFAULT_USER; _args->user = TSDB_DEFAULT_USER;
} }
if (taos_init()) {
printf("failed to init taos\n");
fflush(stdout);
return NULL;
}
// Connect to the database. // Connect to the database.
TAOS *con = NULL; TAOS *con = NULL;
if (_args->auth == NULL) { if (_args->auth == NULL) {
@ -127,6 +122,7 @@ TAOS *shellInit(SShellArguments *_args) {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
#if 0
#ifndef WINDOWS #ifndef WINDOWS
if (_args->dir[0] != 0) { if (_args->dir[0] != 0) {
source_dir(con, _args); source_dir(con, _args);
@ -139,6 +135,7 @@ TAOS *shellInit(SShellArguments *_args) {
taos_close(con); taos_close(con);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
#endif
#endif #endif
return con; return con;
@ -153,7 +150,6 @@ static bool isEmptyCommand(const char* cmd) {
return true; return true;
} }
static int32_t shellRunSingleCommand(TAOS *con, char *command) { static int32_t shellRunSingleCommand(TAOS *con, char *command) {
/* If command is empty just return */ /* If command is empty just return */
if (isEmptyCommand(command)) { if (isEmptyCommand(command)) {
@ -176,7 +172,8 @@ static int32_t shellRunSingleCommand(TAOS *con, char *command) {
return 0; return 0;
} }
if (regex_match(command, "^[\t ]*set[ \t]+max_binary_display_width[ \t]+(default|[1-9][0-9]*)[ \t;]*$", REG_EXTENDED | REG_ICASE)) { if (regex_match(command, "^[\t ]*set[ \t]+max_binary_display_width[ \t]+(default|[1-9][0-9]*)[ \t;]*$",
REG_EXTENDED | REG_ICASE)) {
strtok(command, " \t"); strtok(command, " \t");
strtok(NULL, " \t"); strtok(NULL, " \t");
char *p = strtok(NULL, " \t"); char *p = strtok(NULL, " \t");
@ -202,7 +199,6 @@ static int32_t shellRunSingleCommand(TAOS *con, char *command) {
return 0; return 0;
} }
int32_t shellRunCommand(TAOS *con, char *command) { int32_t shellRunCommand(TAOS *con, char *command) {
/* If command is empty just return */ /* If command is empty just return */
if (isEmptyCommand(command)) { if (isEmptyCommand(command)) {
@ -284,13 +280,14 @@ int32_t shellRunCommand(TAOS* con, char* command) {
return shellRunSingleCommand(con, cmd); return shellRunSingleCommand(con, cmd);
} }
void freeResultWithRid(int64_t rid) { void freeResultWithRid(int64_t rid) {
#if 0
SSqlObj* pSql = taosAcquireRef(tscObjRef, rid); SSqlObj* pSql = taosAcquireRef(tscObjRef, rid);
if(pSql){ if(pSql){
taos_free_result(pSql); taos_free_result(pSql);
taosReleaseRef(tscObjRef, rid); taosReleaseRef(tscObjRef, rid);
} }
#endif
} }
void shellRunCommandOnServer(TAOS *con, char command[]) { void shellRunCommandOnServer(TAOS *con, char command[]) {
@ -327,7 +324,7 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
st = taosGetTimestampUs(); st = taosGetTimestampUs();
TAOS_RES* pSql = taos_query_h(con, command, &result); TAOS_RES *pSql = taos_query(con, command);
if (taos_errno(pSql)) { if (taos_errno(pSql)) {
taos_error(pSql, st); taos_error(pSql, st);
return; return;
@ -344,7 +341,7 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
return; return;
} }
if (!tscIsUpdateQuery(pSql)) { // select and show kinds of commands if (true /*!tscIsUpdateQuery(pSql)*/) { // select and show kinds of commands
int error_no = 0; int error_no = 0;
int numOfRows = shellDumpResult(pSql, fname, &error_no, printMode); int numOfRows = shellDumpResult(pSql, fname, &error_no, printMode);
@ -405,7 +402,6 @@ int regex_match(const char *s, const char *reg, int cflags) {
return 0; return 0;
} }
static char *formatTimestamp(char *buf, int64_t val, int precision) { static char *formatTimestamp(char *buf, int64_t val, int precision) {
if (args.is_raw_time) { if (args.is_raw_time) {
sprintf(buf, "%" PRId64, val); sprintf(buf, "%" PRId64, val);
@ -461,7 +457,6 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) {
return buf; return buf;
} }
static void dumpFieldToFile(FILE *fp, const char *val, TAOS_FIELD *field, int32_t length, int precision) { static void dumpFieldToFile(FILE *fp, const char *val, TAOS_FIELD *field, int32_t length, int precision) {
if (val == NULL) { if (val == NULL) {
fprintf(fp, "%s", TSDB_DATA_NULL_STR); fprintf(fp, "%s", TSDB_DATA_NULL_STR);
@ -561,7 +556,6 @@ static int dumpResultToFile(const char* fname, TAOS_RES* tres) {
return numOfRows; return numOfRows;
} }
static void shellPrintNChar(const char *str, int length, int width) { static void shellPrintNChar(const char *str, int length, int width) {
wchar_t tail[3]; wchar_t tail[3];
int pos = 0, cols = 0, totalCols = 0, tailLen = 0; int pos = 0, cols = 0, totalCols = 0, tailLen = 0;
@ -625,7 +619,6 @@ static void shellPrintNChar(const char *str, int length, int width) {
} }
} }
static void printField(const char *val, TAOS_FIELD *field, int width, int32_t length, int precision) { static void printField(const char *val, TAOS_FIELD *field, int width, int32_t length, int precision) {
if (val == NULL) { if (val == NULL) {
int w = width; int w = width;
@ -687,18 +680,17 @@ static void printField(const char* val, TAOS_FIELD* field, int width, int32_t le
} }
} }
bool isSelectQuery(TAOS_RES *tres) { bool isSelectQuery(TAOS_RES *tres) {
#if 0
char *sql = tscGetSqlStr(tres); char *sql = tscGetSqlStr(tres);
if (regex_match(sql, "^[\t ]*select[ \t]*", REG_EXTENDED | REG_ICASE)) { if (regex_match(sql, "^[\t ]*select[ \t]*", REG_EXTENDED | REG_ICASE)) {
return true; return true;
} }
#endif
return false; return false;
} }
static int verticalPrintResult(TAOS_RES *tres) { static int verticalPrintResult(TAOS_RES *tres) {
TAOS_ROW row = taos_fetch_row(tres); TAOS_ROW row = taos_fetch_row(tres);
if (row == NULL) { if (row == NULL) {
@ -719,7 +711,7 @@ static int verticalPrintResult(TAOS_RES* tres) {
uint64_t resShowMaxNum = UINT64_MAX; uint64_t resShowMaxNum = UINT64_MAX;
if (args.commands == NULL && args.file[0] == 0 && isSelectQuery(tres) && !tscIsQueryWithLimit(tres)) { if (args.commands == NULL && args.file[0] == 0 && isSelectQuery(tres) /*&& !tscIsQueryWithLimit(tres)*/) {
resShowMaxNum = DEFAULT_RES_SHOW_NUM; resShowMaxNum = DEFAULT_RES_SHOW_NUM;
} }
@ -801,7 +793,8 @@ static int calcColWidth(TAOS_FIELD* field, int precision) {
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
if (args.is_raw_time) { if (args.is_raw_time) {
return MAX(14, width); return MAX(14, width);
} if (precision == TSDB_TIME_PRECISION_NANO) { }
if (precision == TSDB_TIME_PRECISION_NANO) {
return MAX(29, width); return MAX(29, width);
} else if (precision == TSDB_TIME_PRECISION_MICRO) { } else if (precision == TSDB_TIME_PRECISION_MICRO) {
return MAX(26, width); // '2020-01-01 00:00:00.000000' return MAX(26, width); // '2020-01-01 00:00:00.000000'
@ -816,7 +809,6 @@ static int calcColWidth(TAOS_FIELD* field, int precision) {
return 0; return 0;
} }
static void printHeader(TAOS_FIELD *fields, int *width, int num_fields) { static void printHeader(TAOS_FIELD *fields, int *width, int num_fields) {
int rowWidth = 0; int rowWidth = 0;
for (int col = 0; col < num_fields; col++) { for (int col = 0; col < num_fields; col++) {
@ -834,7 +826,6 @@ static void printHeader(TAOS_FIELD* fields, int* width, int num_fields) {
putchar('\n'); putchar('\n');
} }
static int horizontalPrintResult(TAOS_RES *tres) { static int horizontalPrintResult(TAOS_RES *tres) {
TAOS_ROW row = taos_fetch_row(tres); TAOS_ROW row = taos_fetch_row(tres);
if (row == NULL) { if (row == NULL) {
@ -854,7 +845,7 @@ static int horizontalPrintResult(TAOS_RES* tres) {
uint64_t resShowMaxNum = UINT64_MAX; uint64_t resShowMaxNum = UINT64_MAX;
if (args.commands == NULL && args.file[0] == 0 && isSelectQuery(tres) && !tscIsQueryWithLimit(tres)) { if (args.commands == NULL && args.file[0] == 0 && isSelectQuery(tres) /* && !tscIsQueryWithLimit(tres)*/) {
resShowMaxNum = DEFAULT_RES_SHOW_NUM; resShowMaxNum = DEFAULT_RES_SHOW_NUM;
} }
@ -884,7 +875,6 @@ static int horizontalPrintResult(TAOS_RES* tres) {
return numOfRows; return numOfRows;
} }
int shellDumpResult(TAOS_RES *tres, char *fname, int *error_no, bool vertical) { int shellDumpResult(TAOS_RES *tres, char *fname, int *error_no, bool vertical) {
int numOfRows = 0; int numOfRows = 0;
if (fname != NULL) { if (fname != NULL) {
@ -899,7 +889,6 @@ int shellDumpResult(TAOS_RES *tres, char *fname, int *error_no, bool vertical) {
return numOfRows; return numOfRows;
} }
void read_history() { void read_history() {
// Initialize history // Initialize history
memset(history.hist, 0, sizeof(char *) * MAX_HISTORY_SIZE); memset(history.hist, 0, sizeof(char *) * MAX_HISTORY_SIZE);

View File

@ -19,7 +19,11 @@
#include "shell.h" #include "shell.h"
#include "shellCommand.h" #include "shellCommand.h"
#include "tkey.h" #include "tkey.h"
#include "tulog.h" #include "ulog.h"
#include <wordexp.h>
#include <argp.h>
#include <termio.h>
#define OPT_ABORT 1 /* <20>Cabort */ #define OPT_ABORT 1 /* <20>Cabort */
@ -68,7 +72,6 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
break; break;
case 'P': case 'P':
if (arg) { if (arg) {
tsDnodeShellPort = atoi(arg);
arguments->port = atoi(arg); arguments->port = atoi(arg);
} else { } else {
fprintf(stderr, "Invalid port\n"); fprintf(stderr, "Invalid port\n");

View File

@ -16,7 +16,7 @@
#include "os.h" #include "os.h"
#include "shell.h" #include "shell.h"
#include "tconfig.h" #include "tconfig.h"
#include "tnettest.h" #include "tglobal.h"
pthread_t pid; pthread_t pid;
static tsem_t cancelSem; static tsem_t cancelSem;
@ -35,14 +35,18 @@ void *cancelHandler(void *arg) {
} }
#ifdef LINUX #ifdef LINUX
#if 0
int64_t rid = atomic_val_compare_exchange_64(&result, result, 0); int64_t rid = atomic_val_compare_exchange_64(&result, result, 0);
SSqlObj* pSql = taosAcquireRef(tscObjRef, rid); SSqlObj* pSql = taosAcquireRef(tscObjRef, rid);
taos_stop_query(pSql); taos_stop_query(pSql);
taosReleaseRef(tscObjRef, rid); taosReleaseRef(tscObjRef, rid);
#endif
#else #else
printf("\nReceive ctrl+c or other signal, quit shell.\n"); printf("\nReceive ctrl+c or other signal, quit shell.\n");
exit(0); exit(0);
#endif #endif
printf("\nReceive ctrl+c or other signal, quit shell.\n");
exit(0);
} }
return NULL; return NULL;
@ -69,8 +73,7 @@ int checkVersion() {
} }
// Global configurations // Global configurations
SShellArguments args = { SShellArguments args = {.host = NULL,
.host = NULL,
#ifndef TD_WINDOWS #ifndef TD_WINDOWS
.password = NULL, .password = NULL,
#endif #endif
@ -87,8 +90,7 @@ SShellArguments args = {
.pktLen = 1000, .pktLen = 1000,
.pktNum = 100, .pktNum = 100,
.pktType = "TCP", .pktType = "TCP",
.netTestRole = NULL .netTestRole = NULL};
};
/* /*
* Main function. * Main function.
@ -102,6 +104,7 @@ int main(int argc, char* argv[]) {
shellParseArgument(argc, argv, &args); shellParseArgument(argc, argv, &args);
#if 0
if (args.dump_config) { if (args.dump_config) {
taosInitGlobalCfg(); taosInitGlobalCfg();
taosReadGlobalLogCfg(); taosReadGlobalLogCfg();
@ -123,6 +126,7 @@ int main(int argc, char* argv[]) {
taosNetTest(args.netTestRole, args.host, args.port, args.pktLen, args.pktNum, args.pktType); taosNetTest(args.netTestRole, args.host, args.port, args.pktLen, args.pktNum, args.pktType);
exit(0); exit(0);
} }
#endif
/* Initialize the shell */ /* Initialize the shell */
TAOS *con = shellInit(&args); TAOS *con = shellInit(&args);