From 9c910faa3c9bb7a02cea5f1b6253fb00c40481f3 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 13 Sep 2023 14:31:48 +0800 Subject: [PATCH 01/18] feat: support dbname rename during importing --- src/taosdump.c | 188 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 186 insertions(+), 2 deletions(-) diff --git a/src/taosdump.c b/src/taosdump.c index e1de127a..f3ebdc26 100644 --- a/src/taosdump.c +++ b/src/taosdump.c @@ -494,12 +494,20 @@ static struct argp_option options[] = { #endif {"debug", 'g', 0, 0, "Print debug info.", 15}, {"dot-replace", 'Q', 0, 0, "Repalce dot character with underline character in the table name.", 10}, + {"rename-dbname", 'W', 0, 0, "rename database name with new name. format demo: db1=newDB1|db2=newDB2", 10}, {0} }; #define HUMAN_TIME_LEN 28 #define DUMP_DIR_LEN (MAX_DIR_LEN - (TSDB_DB_NAME_LEN + 10)) +// rename db +typedef struct SRenameDB { + char* old; + char* new; + SRenameDB* next; +} + /* Used by main to communicate with parse_opt. */ typedef struct arguments { // connection option @@ -545,9 +553,7 @@ typedef struct arguments { bool verbose_print; bool performance_print; bool dotReplace; - int dumpDbCount; - #ifdef WEBSOCKET bool restful; bool cloud; @@ -557,6 +563,10 @@ typedef struct arguments { int cloudPort; char cloudHost[MAX_HOSTNAME_LEN]; #endif + + // put rename db string + char * renameBuf; + SRenameDB * renameHead; } SArguments; static resultStatistics g_resultStatistics = {0}; @@ -611,6 +621,7 @@ struct arguments g_args = { false, // performance_print false, // dotRepalce 0, // dumpDbCount + #ifdef WEBSOCKET false, // restful false, // cloud @@ -620,6 +631,9 @@ struct arguments g_args = { 0, // cloudPort {0}, // cloudHost #endif // WEBSOCKET + + NULL, // renameBuf + NULL // renameHead }; @@ -781,6 +795,71 @@ int64_t getEndTime(int precision) { return end_time; } +SRenameDB* newNode(char* first, SRenameDB* prev) { + SRenameDB* node = (SRenameDB*) malloc(sizeof(SRenameDB)); + memset(node, 0, sizeof(SRenameDB)); + node->old = first; + // link to list + if(prev) { + prev->next = node; + } + + return node; +} + +void setRenameDbs(char* arg) { + // malloc new + int len = strlen(arg); + if(len <= 2) { + return ; + } + len += 1; // include \0 + + // malloc + char* p = malloc(len); + int j = 0; // j is p pos + for (int i = 0; i < len; i++) { + if (arg[i] == ' ') { + // do nothing + } else if (arg[i] == '=' || arg[i] == '|') { + // set zero + p[j++] = 0; + } else { + // copy + p[j++] = arg[i]; + } + } + + // splite + SRenameDB* node = newNode(p); + g_args.renameHead = node; + for (int k = 0; k < j; k++) { + if(p[k] == 0 && k + 1 != j && k > 0) { + // string end and not last end + char* name = p + (k - 1); + if (node->new == NULL) { + node->new = name; + } else { + node = newNode(name, node); + } + } + } + + // end + g_args.renameBuf = p; +} + +// find newName +char* findNewName(char* oldName) { + SRenameDB* node = g_args.renameHead; + while(node) { + if (strcmp(node->old, oldName) == 0) { + return node->new; + } + node = node->next; + } +} + /* Parse a single option. */ static error_t parse_opt(int key, char *arg, struct argp_state *state) { /* Get the input argument from argp_parse, which we @@ -967,6 +1046,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { } state->next = state->argc; break; + case 'W': + setRenameDbs(arg); + break; default: return ARGP_ERR_UNKNOWN; @@ -7320,6 +7402,13 @@ static int64_t dumpInOneAvroFile( } const char *namespace = avro_schema_namespace((const avro_schema_t)schema); + if(g_args.renameHead) { + char* newDbName = findNewName(namespace); + if(newDbName) { + infoPrint(" ------- rename DB Name %s to %s ------\n", namespace, newDbName); + namespace = newDbName; + } + } debugPrint("%s() LN%d, Namespace: %s\n", __func__, __LINE__, namespace); @@ -10012,6 +10101,71 @@ bool convertDbClauseForV3(char **cmd) { return true; } +// repalce old name with new +char * replaceNewName(char* cmd, int len) { + // database name left char and right char + int nLeftSql = len; + char left = cmd[len]; + char right = "." ; + if(left == '`') { + right = left; + nLeftSql += 1; + } else { + right = "."; + } + + // get old database name + char oldName[TSDB_DB_NAME_LEN]; + char* s = &cmd[len + 1]; + char* e = strstr(s, right); + if(e == NULL) { + return NULL; + } + + int oldLen = e - s; + if(oldLen + 1 > TSDB_DB_NAME_LEN) { + return NULL; + } + memcpy(oldName, s, oldLen); + oldName[oldLen] = 0; + + // macth new database + char* newName = findNewName(oldName); + if(newName == NULL){ + return NULL; + } + + // malloc new buff put new sql with new name + int newLen = strlen(cmd) + (strlen(newName) - oldLen) + 1; + char* newCmd = (char *)malloc(newLen); + memset(newCmd, 0, newLen); + + // copy left + newName + right from cmd + memcpy(newCmd, cmd, nLeftSql); // left sql + strcat(newCmd, newName); // newName + strcat(newCmd, e); // right sql + + return newCmd; +} + +// if have database name rename, return new sql with new database name +// retrn value need call free() to free memory +char * afterRenameSql(char *cmd) { + // match pattern + const char* CREATE_DB = "CREATE DATABASE IF NOT EXISTS "; + const char* CREATE_TB = "CREATE TABLE IF NOT EXISTS "; + + char* pres[] = {CREATE_DB, CREATE_TB}; + for (int i = 0; i < sizeof(pres); i++ ) { + int len = strlen(pres[i]) + if (strncmp(cmd, pres[i], len) == 0) { + // found + return replaceNewName(cmd, len); + } + } + return NULL; +} + // dumpIn support multi threads functions static int64_t dumpInOneDebugFile( void* taos, FILE* fp, @@ -10090,7 +10244,19 @@ static int64_t dumpInOneDebugFile( ret = queryDbImplWS(taos, cmd); } else { #endif + if(g_args.renameHead) { + // have rename database options + char *newSql = afterRenameSql(cmd); + if(newSql) { + ret = queryDbImplNative(taos, newSql); + free(newSql); + } else { + ret = queryDbImplNative(taos, cmd); + } + } else { ret = queryDbImplNative(taos, cmd); + } + #ifdef WEBSOCKET } #endif @@ -13127,6 +13293,24 @@ int main(int argc, char *argv[]) { } else { ret = dumpEntry(); } + + // free buf + if (arguments.renameBuf) { + free(arguments.renameBuf); + arguments.renameBuf = NULL; + } + + // free node + SRenameDB* node = arguments.renameHead; + arguments.renameHead = NULL; + while(node) { + SRenameDB* next = node->next; + free(node); + node = next; + } + + + return ret; } From 67d3eb7b6e3fb7d979e12722d17fe30678ffad81 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 13 Sep 2023 15:13:46 +0800 Subject: [PATCH 02/18] fix: build error --- src/taosdump.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/taosdump.c b/src/taosdump.c index f3ebdc26..e03d778b 100644 --- a/src/taosdump.c +++ b/src/taosdump.c @@ -502,11 +502,12 @@ static struct argp_option options[] = { #define DUMP_DIR_LEN (MAX_DIR_LEN - (TSDB_DB_NAME_LEN + 10)) // rename db +struct SRenameDB; typedef struct SRenameDB { char* old; char* new; - SRenameDB* next; -} + void* next; +}SRenameDB; /* Used by main to communicate with parse_opt. */ typedef struct arguments { @@ -831,7 +832,7 @@ void setRenameDbs(char* arg) { } // splite - SRenameDB* node = newNode(p); + SRenameDB* node = newNode(p, NULL); g_args.renameHead = node; for (int k = 0; k < j; k++) { if(p[k] == 0 && k + 1 != j && k > 0) { @@ -857,7 +858,7 @@ char* findNewName(char* oldName) { return node->new; } node = node->next; - } + }; } /* Parse a single option. */ @@ -7403,7 +7404,7 @@ static int64_t dumpInOneAvroFile( const char *namespace = avro_schema_namespace((const avro_schema_t)schema); if(g_args.renameHead) { - char* newDbName = findNewName(namespace); + char* newDbName = findNewName((char *)namespace); if(newDbName) { infoPrint(" ------- rename DB Name %s to %s ------\n", namespace, newDbName); namespace = newDbName; @@ -10106,18 +10107,16 @@ char * replaceNewName(char* cmd, int len) { // database name left char and right char int nLeftSql = len; char left = cmd[len]; - char right = "." ; + char right = '.'; if(left == '`') { right = left; nLeftSql += 1; - } else { - right = "."; } // get old database name char oldName[TSDB_DB_NAME_LEN]; char* s = &cmd[len + 1]; - char* e = strstr(s, right); + char* e = strchr(s, right); if(e == NULL) { return NULL; } @@ -10155,9 +10154,9 @@ char * afterRenameSql(char *cmd) { const char* CREATE_DB = "CREATE DATABASE IF NOT EXISTS "; const char* CREATE_TB = "CREATE TABLE IF NOT EXISTS "; - char* pres[] = {CREATE_DB, CREATE_TB}; + const char* pres[] = {CREATE_DB, CREATE_TB}; for (int i = 0; i < sizeof(pres); i++ ) { - int len = strlen(pres[i]) + int len = strlen(pres[i]); if (strncmp(cmd, pres[i], len) == 0) { // found return replaceNewName(cmd, len); From ba01746100201537b8f0b331f8b57a6765692748 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 13 Sep 2023 15:16:03 +0800 Subject: [PATCH 03/18] fix: build error1 --- src/taosdump.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/taosdump.c b/src/taosdump.c index e03d778b..a7d6f5f1 100644 --- a/src/taosdump.c +++ b/src/taosdump.c @@ -857,7 +857,7 @@ char* findNewName(char* oldName) { if (strcmp(node->old, oldName) == 0) { return node->new; } - node = node->next; + node = (SRenameDB* )node->next; }; } @@ -13294,16 +13294,16 @@ int main(int argc, char *argv[]) { } // free buf - if (arguments.renameBuf) { - free(arguments.renameBuf); - arguments.renameBuf = NULL; + if (g_args.renameBuf) { + free(g_args.renameBuf); + g_args.renameBuf = NULL; } // free node - SRenameDB* node = arguments.renameHead; - arguments.renameHead = NULL; + SRenameDB* node = g_args.renameHead; + g_args.renameHead = NULL; while(node) { - SRenameDB* next = node->next; + SRenameDB* next = (SRenameDB*)node->next; free(node); node = next; } From 089086b422e108bf00eddfe0cf247a0cbbaade79 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 13 Sep 2023 15:18:55 +0800 Subject: [PATCH 04/18] fix: build error2 --- src/taosdump.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/taosdump.c b/src/taosdump.c index a7d6f5f1..bdfa7e2c 100644 --- a/src/taosdump.c +++ b/src/taosdump.c @@ -858,7 +858,8 @@ char* findNewName(char* oldName) { return node->new; } node = (SRenameDB* )node->next; - }; + } + return NULL; } /* Parse a single option. */ From 09718ff7999f0a52e65780a1d67c2397598e50d6 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 13 Sep 2023 15:46:20 +0800 Subject: [PATCH 05/18] fix: add option name --- src/taosdump.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/taosdump.c b/src/taosdump.c index bdfa7e2c..38506d04 100644 --- a/src/taosdump.c +++ b/src/taosdump.c @@ -494,7 +494,7 @@ static struct argp_option options[] = { #endif {"debug", 'g', 0, 0, "Print debug info.", 15}, {"dot-replace", 'Q', 0, 0, "Repalce dot character with underline character in the table name.", 10}, - {"rename-dbname", 'W', 0, 0, "rename database name with new name. format demo: db1=newDB1|db2=newDB2", 10}, + {"rename-dbname", 'W', "rename", 0, "rename database name with new name. format demo: db1=newDB1|db2=newDB2", 10}, {0} }; @@ -809,6 +809,7 @@ SRenameDB* newNode(char* first, SRenameDB* prev) { } void setRenameDbs(char* arg) { + if (arg == NULL) return ; // malloc new int len = strlen(arg); if(len <= 2) { From 44185a4c0f8319d4b2bfda56a4bc02646d791c9f Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 13 Sep 2023 15:52:27 +0800 Subject: [PATCH 06/18] fix: add option name1 --- src/taosdump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/taosdump.c b/src/taosdump.c index 38506d04..e727cc5f 100644 --- a/src/taosdump.c +++ b/src/taosdump.c @@ -838,7 +838,7 @@ void setRenameDbs(char* arg) { for (int k = 0; k < j; k++) { if(p[k] == 0 && k + 1 != j && k > 0) { // string end and not last end - char* name = p + (k - 1); + char* name = &p[k] + 1; if (node->new == NULL) { node->new = name; } else { From eb3b2c4c5a2190f87a0521f5e861ea8cbaaa3852 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 13 Sep 2023 16:16:02 +0800 Subject: [PATCH 07/18] fix: left sql length --- src/taosdump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/taosdump.c b/src/taosdump.c index e727cc5f..04a5436b 100644 --- a/src/taosdump.c +++ b/src/taosdump.c @@ -10117,7 +10117,7 @@ char * replaceNewName(char* cmd, int len) { // get old database name char oldName[TSDB_DB_NAME_LEN]; - char* s = &cmd[len + 1]; + char* s = &cmd[nLeftSql]; char* e = strchr(s, right); if(e == NULL) { return NULL; From 765e7b0a89b3d870002b2f7c8cd78ee96231d212 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 13 Sep 2023 17:21:04 +0800 Subject: [PATCH 08/18] fix: rename normal table sql --- src/taosdump.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/taosdump.c b/src/taosdump.c index 04a5436b..7a140682 100644 --- a/src/taosdump.c +++ b/src/taosdump.c @@ -6092,6 +6092,13 @@ static int64_t dumpInAvroNtbImpl( __func__, __LINE__); continue; } + + char* newBuf = afterRenameSql(buf); + if(newBuf) { + infoPrint(" rename database name for create normal table sql: \n old=%s\n new=%s\n", buf, newBuf); + buf = newBuf; + } + #ifdef WEBSOCKET if (g_args.cloud || g_args.restful) { WS_RES *ws_res = ws_query_timeout(taos, buf, g_args.ws_timeout); @@ -6111,6 +6118,9 @@ static int64_t dumpInAvroNtbImpl( } else { #endif TAOS_RES *res = taos_query(taos, buf); + if(newBuf) { + free(newBuf); + } int code = taos_errno(res); if (0 != code) { errorPrint("%s() LN%d," @@ -10119,8 +10129,15 @@ char * replaceNewName(char* cmd, int len) { char oldName[TSDB_DB_NAME_LEN]; char* s = &cmd[nLeftSql]; char* e = strchr(s, right); - if(e == NULL) { + char* e1 = strchr(s, ' '); + if(e == NULL && e1 == NULL) { return NULL; + } else if(e == NULL && e1) { + e = e1; + } else if(e && e1 ) { + if (e > e1) { + e = e1; + } } int oldLen = e - s; From bfb822d421b291ac9562133350b7d28546d078c9 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 13 Sep 2023 17:24:47 +0800 Subject: [PATCH 09/18] fix: rename normal table sql --- src/taosdump.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/taosdump.c b/src/taosdump.c index 7a140682..0227e1c0 100644 --- a/src/taosdump.c +++ b/src/taosdump.c @@ -1905,6 +1905,24 @@ bool replaceCopy(char *des, char *src) { return replace; } +// if have database name rename, return new sql with new database name +// retrn value need call free() to free memory +char * afterRenameSql(char *cmd) { + // match pattern + const char* CREATE_DB = "CREATE DATABASE IF NOT EXISTS "; + const char* CREATE_TB = "CREATE TABLE IF NOT EXISTS "; + + const char* pres[] = {CREATE_DB, CREATE_TB}; + for (int i = 0; i < sizeof(pres); i++ ) { + int len = strlen(pres[i]); + if (strncmp(cmd, pres[i], len) == 0) { + // found + return replaceNewName(cmd, len); + } + } + return NULL; +} + static int dumpCreateMTableClause( const char* dbName, const char *stable, @@ -10166,24 +10184,6 @@ char * replaceNewName(char* cmd, int len) { return newCmd; } -// if have database name rename, return new sql with new database name -// retrn value need call free() to free memory -char * afterRenameSql(char *cmd) { - // match pattern - const char* CREATE_DB = "CREATE DATABASE IF NOT EXISTS "; - const char* CREATE_TB = "CREATE TABLE IF NOT EXISTS "; - - const char* pres[] = {CREATE_DB, CREATE_TB}; - for (int i = 0; i < sizeof(pres); i++ ) { - int len = strlen(pres[i]); - if (strncmp(cmd, pres[i], len) == 0) { - // found - return replaceNewName(cmd, len); - } - } - return NULL; -} - // dumpIn support multi threads functions static int64_t dumpInOneDebugFile( void* taos, FILE* fp, From 81563d909a76d042b63f5a1c09a63e287eedbf30 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 13 Sep 2023 17:28:38 +0800 Subject: [PATCH 10/18] fix: adjust new function position --- src/taosdump.c | 170 ++++++++++++++++++++++++------------------------- 1 file changed, 85 insertions(+), 85 deletions(-) diff --git a/src/taosdump.c b/src/taosdump.c index 0227e1c0..bb542b3c 100644 --- a/src/taosdump.c +++ b/src/taosdump.c @@ -863,6 +863,91 @@ char* findNewName(char* oldName) { return NULL; } +bool replaceCopy(char *des, char *src) { + size_t len = strlen(src); + bool replace = false; + for (size_t i = 0; i <= len; i++) { + if (src[i] == '.') { + des[i] = '_'; + replace = true; + } else { + des[i] = src[i]; + } + } + + return replace; +} + +// repalce old name with new +char * replaceNewName(char* cmd, int len) { + // database name left char and right char + int nLeftSql = len; + char left = cmd[len]; + char right = '.'; + if(left == '`') { + right = left; + nLeftSql += 1; + } + + // get old database name + char oldName[TSDB_DB_NAME_LEN]; + char* s = &cmd[nLeftSql]; + char* e = strchr(s, right); + char* e1 = strchr(s, ' '); + if(e == NULL && e1 == NULL) { + return NULL; + } else if(e == NULL && e1) { + e = e1; + } else if(e && e1 ) { + if (e > e1) { + e = e1; + } + } + + int oldLen = e - s; + if(oldLen + 1 > TSDB_DB_NAME_LEN) { + return NULL; + } + memcpy(oldName, s, oldLen); + oldName[oldLen] = 0; + + // macth new database + char* newName = findNewName(oldName); + if(newName == NULL){ + return NULL; + } + + // malloc new buff put new sql with new name + int newLen = strlen(cmd) + (strlen(newName) - oldLen) + 1; + char* newCmd = (char *)malloc(newLen); + memset(newCmd, 0, newLen); + + // copy left + newName + right from cmd + memcpy(newCmd, cmd, nLeftSql); // left sql + strcat(newCmd, newName); // newName + strcat(newCmd, e); // right sql + + return newCmd; +} + +// if have database name rename, return new sql with new database name +// retrn value need call free() to free memory +char * afterRenameSql(char *cmd) { + // match pattern + const char* CREATE_DB = "CREATE DATABASE IF NOT EXISTS "; + const char* CREATE_TB = "CREATE TABLE IF NOT EXISTS "; + + const char* pres[] = {CREATE_DB, CREATE_TB}; + for (int i = 0; i < sizeof(pres); i++ ) { + int len = strlen(pres[i]); + if (strncmp(cmd, pres[i], len) == 0) { + // found + return replaceNewName(cmd, len); + } + } + return NULL; +} + /* Parse a single option. */ static error_t parse_opt(int key, char *arg, struct argp_state *state) { /* Get the input argument from argp_parse, which we @@ -1890,39 +1975,6 @@ static int getDumpDbCount() { return count; } -bool replaceCopy(char *des, char *src) { - size_t len = strlen(src); - bool replace = false; - for (size_t i = 0; i <= len; i++) { - if (src[i] == '.') { - des[i] = '_'; - replace = true; - } else { - des[i] = src[i]; - } - } - - return replace; -} - -// if have database name rename, return new sql with new database name -// retrn value need call free() to free memory -char * afterRenameSql(char *cmd) { - // match pattern - const char* CREATE_DB = "CREATE DATABASE IF NOT EXISTS "; - const char* CREATE_TB = "CREATE TABLE IF NOT EXISTS "; - - const char* pres[] = {CREATE_DB, CREATE_TB}; - for (int i = 0; i < sizeof(pres); i++ ) { - int len = strlen(pres[i]); - if (strncmp(cmd, pres[i], len) == 0) { - // found - return replaceNewName(cmd, len); - } - } - return NULL; -} - static int dumpCreateMTableClause( const char* dbName, const char *stable, @@ -10132,58 +10184,6 @@ bool convertDbClauseForV3(char **cmd) { return true; } -// repalce old name with new -char * replaceNewName(char* cmd, int len) { - // database name left char and right char - int nLeftSql = len; - char left = cmd[len]; - char right = '.'; - if(left == '`') { - right = left; - nLeftSql += 1; - } - - // get old database name - char oldName[TSDB_DB_NAME_LEN]; - char* s = &cmd[nLeftSql]; - char* e = strchr(s, right); - char* e1 = strchr(s, ' '); - if(e == NULL && e1 == NULL) { - return NULL; - } else if(e == NULL && e1) { - e = e1; - } else if(e && e1 ) { - if (e > e1) { - e = e1; - } - } - - int oldLen = e - s; - if(oldLen + 1 > TSDB_DB_NAME_LEN) { - return NULL; - } - memcpy(oldName, s, oldLen); - oldName[oldLen] = 0; - - // macth new database - char* newName = findNewName(oldName); - if(newName == NULL){ - return NULL; - } - - // malloc new buff put new sql with new name - int newLen = strlen(cmd) + (strlen(newName) - oldLen) + 1; - char* newCmd = (char *)malloc(newLen); - memset(newCmd, 0, newLen); - - // copy left + newName + right from cmd - memcpy(newCmd, cmd, nLeftSql); // left sql - strcat(newCmd, newName); // newName - strcat(newCmd, e); // right sql - - return newCmd; -} - // dumpIn support multi threads functions static int64_t dumpInOneDebugFile( void* taos, FILE* fp, From 97542a16a93e790beed2d8d1aea7588841076504 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 13 Sep 2023 17:41:25 +0800 Subject: [PATCH 11/18] fix: support websocket --- src/taosdump.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/taosdump.c b/src/taosdump.c index bb542b3c..e9626260 100644 --- a/src/taosdump.c +++ b/src/taosdump.c @@ -10255,24 +10255,22 @@ static int64_t dumpInOneDebugFile( } int ret; + char *newSql = NULL; + + if(g_args.renameHead) { + // have rename database options + newSql = afterRenameSql(cmd); + } debugPrint("%s() LN%d, cmd: %s\n", __func__, __LINE__, cmd); #ifdef WEBSOCKET if (g_args.cloud || g_args.restful) { - ret = queryDbImplWS(taos, cmd); + ret = queryDbImplWS(taos, newSql?newSql:cmd); } else { #endif - if(g_args.renameHead) { - // have rename database options - char *newSql = afterRenameSql(cmd); - if(newSql) { - ret = queryDbImplNative(taos, newSql); - free(newSql); - } else { - ret = queryDbImplNative(taos, cmd); - } - } else { - ret = queryDbImplNative(taos, cmd); + ret = queryDbImplNative(taos, newSql?newSql:cmd); + if(newSql) { + free(newSql); } #ifdef WEBSOCKET From aa652430f5b76c3853dba4e60e3681909eaa5cc3 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 13 Sep 2023 19:22:10 +0800 Subject: [PATCH 12/18] feat: taosdump add rename database option -W case --- tests/taosdump/native/taosdumpDbNtb.py | 6 +++--- tests/taosdump/native/taosdumpDbStb.py | 6 +++--- tests/taosdump/native/taosdumpDbWithNonRoot.py | 6 +++--- tests/taosdump/native/taosdumpEscapedDb.py | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/taosdump/native/taosdumpDbNtb.py b/tests/taosdump/native/taosdumpDbNtb.py index 99b2922a..d9f149f3 100644 --- a/tests/taosdump/native/taosdumpDbNtb.py +++ b/tests/taosdump/native/taosdumpDbNtb.py @@ -107,7 +107,7 @@ def run(self): tdSql.execute("drop database db") # sys.exit(1) - os.system("%s -i %s -T 1" % (binPath, self.tmpdir)) + os.system("%s -i %s -T 1 -W db=newdb" % (binPath, self.tmpdir)) tdSql.query("show databases") dbresult = tdSql.queryResult @@ -115,13 +115,13 @@ def run(self): found = False for i in range(len(dbresult)): print("Found db: %s" % dbresult[i][0]) - if dbresult[i][0] == "db": + if dbresult[i][0] == "newdb": found = True break assert found == True - tdSql.execute("use db") + tdSql.execute("use newdb") tdSql.query("show stables") tdSql.checkRows(1) tdSql.checkData(0, 0, "st") diff --git a/tests/taosdump/native/taosdumpDbStb.py b/tests/taosdump/native/taosdumpDbStb.py index 025a1a2c..bdc3f89d 100644 --- a/tests/taosdump/native/taosdumpDbStb.py +++ b/tests/taosdump/native/taosdumpDbStb.py @@ -107,7 +107,7 @@ def run(self): tdSql.execute("drop database db") # sys.exit(1) - os.system("%s -i %s -T 1" % (binPath, self.tmpdir)) + os.system("%s -i %s -T 1 -W db=newdb" % (binPath, self.tmpdir)) tdSql.query("show databases") dbresult = tdSql.queryResult @@ -115,13 +115,13 @@ def run(self): found = False for i in range(len(dbresult)): print("Found db: %s" % dbresult[i][0]) - if dbresult[i][0] == "db": + if dbresult[i][0] == "newdb": found = True break assert found == True - tdSql.execute("use db") + tdSql.execute("use newdb") tdSql.query("show stables") tdSql.checkRows(1) tdSql.checkData(0, 0, "st") diff --git a/tests/taosdump/native/taosdumpDbWithNonRoot.py b/tests/taosdump/native/taosdumpDbWithNonRoot.py index bdc74611..6bb7eb1d 100644 --- a/tests/taosdump/native/taosdumpDbWithNonRoot.py +++ b/tests/taosdump/native/taosdumpDbWithNonRoot.py @@ -109,7 +109,7 @@ def run(self): tdSql.execute("drop database db") # sys.exit(1) - os.system("%s -i %s -T 1" % (binPath, self.tmpdir)) + os.system("%s -i %s -T 1 -W db=newdb" % (binPath, self.tmpdir)) tdSql.query("show databases") dbresult = tdSql.queryResult @@ -117,13 +117,13 @@ def run(self): found = False for i in range(len(dbresult)): print("Found db: %s" % dbresult[i][0]) - if dbresult[i][0] == "db": + if dbresult[i][0] == "newdb": found = True break assert found == True - tdSql.execute("use db") + tdSql.execute("use newdb") tdSql.query("show stables") tdSql.checkRows(1) tdSql.checkData(0, 0, "st") diff --git a/tests/taosdump/native/taosdumpEscapedDb.py b/tests/taosdump/native/taosdumpEscapedDb.py index 19fb8df7..f9bb4607 100644 --- a/tests/taosdump/native/taosdumpEscapedDb.py +++ b/tests/taosdump/native/taosdumpEscapedDb.py @@ -93,7 +93,7 @@ def run(self): tdSql.execute("drop database `Db`") # sys.exit(1) - os.system("%s -e -i %s -T 1" % (binPath, self.tmpdir)) + os.system("%s -e -i %s -T 1 -W Db=NewDb" % (binPath, self.tmpdir)) tdSql.query("show databases") dbresult = tdSql.queryResult @@ -101,13 +101,13 @@ def run(self): found = False for i in range(len(dbresult)): print("Found db: %s" % dbresult[i][0]) - if dbresult[i][0] == "Db": + if dbresult[i][0] == "NewDb": found = True break assert found == True - tdSql.execute("use `Db`") + tdSql.execute("use `NewDb`") tdSql.query("show stables") tdSql.checkRows(1) tdSql.checkData(0, 0, "st") From d302253c8603c92d9643047804e4e06b33822d71 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 13 Sep 2023 19:36:55 +0800 Subject: [PATCH 13/18] fix: add old case --- tests/taosdump/old/taosdumpTest.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/taosdump/old/taosdumpTest.py b/tests/taosdump/old/taosdumpTest.py index 3f4dad35..0d2f8f22 100644 --- a/tests/taosdump/old/taosdumpTest.py +++ b/tests/taosdump/old/taosdumpTest.py @@ -107,10 +107,10 @@ def run(self): tdSql.query("select * from information_schema.ins_databases") tdSql.checkRows(2) - os.system("%s -i ./taosdumptest/tmp1" % binPath) - os.system("%s -i ./taosdumptest/tmp2" % binPath) + os.system("%s -W db=newdb -i ./taosdumptest/tmp1" % binPath) + os.system("%s -W \"db=newdb|db1=newdb1\" -i ./taosdumptest/tmp2" % binPath) - tdSql.execute("use db") + tdSql.execute("use newdb") tdSql.query("select * from information_schema.ins_databases") tdSql.checkRows(4) dbresult = tdSql.queryResult @@ -119,7 +119,7 @@ def run(self): isCommunity = self.checkCommunity() print("iscommunity: %d" % isCommunity) for i in range(len(dbresult)): - if dbresult[i][0] == "db": + if dbresult[i][0] == "newdb": print(dbresult[i]) print(type(dbresult[i][6])) print(type(dbresult[i][7])) @@ -127,7 +127,7 @@ def run(self): assert dbresult[i][6] == "15840m" print((dbresult[i][7])) assert dbresult[i][7] == "5254560m,5254560m,5254560m" - if dbresult[i][0] == "db1": + if dbresult[i][0] == "newdb1": print((dbresult[i][6])) assert dbresult[i][6] == "17280m" print((dbresult[i][7])) @@ -158,8 +158,8 @@ def run(self): # drop all databases,boundary value testing. # length(databasename)<=32;length(tablesname)<=192 - tdSql.execute("drop database db") - tdSql.execute("drop database db1") + tdSql.execute("drop database newdb") + tdSql.execute("drop database newdb1") os.system("rm -rf ./taosdumptest/tmp1") os.system("rm -rf ./taosdumptest/tmp2") os.makedirs("./taosdumptest/tmp1") @@ -194,8 +194,8 @@ def run(self): % binPath ) tdSql.execute("drop database db12312313231231321312312312_323") - os.system("%s -i ./taosdumptest/tmp1" % binPath) - tdSql.execute("use db12312313231231321312312312_323") + os.system("%s -W db12312313231231321312312312_323=db12312313231231321312312312_323abc -i ./taosdumptest/tmp1" % binPath) + tdSql.execute("use db12312313231231321312312312_323abc") tdSql.query("show stables") tdSql.checkRows(2) os.system("rm -rf ./taosdumptest/tmp1") From 330f11a42e05fe1c60818ac4a50b3a4ad82d0aea Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 13 Sep 2023 20:09:31 +0800 Subject: [PATCH 14/18] fix: case failed for escapedb.py --- tests/taosdump/native/taosdumpEscapedDb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/taosdump/native/taosdumpEscapedDb.py b/tests/taosdump/native/taosdumpEscapedDb.py index f9bb4607..77a17f76 100644 --- a/tests/taosdump/native/taosdumpEscapedDb.py +++ b/tests/taosdump/native/taosdumpEscapedDb.py @@ -112,7 +112,7 @@ def run(self): tdSql.checkRows(1) tdSql.checkData(0, 0, "st") - tdSql.query("select count(*) from `Db`.st") + tdSql.query("select count(*) from `NewDb`.st") tdSql.checkData(0, 0, 1) def stop(self): From 7360894abf6c8a3be8e87fb73e8e73a95dd90333 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 13 Sep 2023 21:02:53 +0800 Subject: [PATCH 15/18] fix: help information and -p can crash --- src/taosdump.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/taosdump.c b/src/taosdump.c index e9626260..0882cd1b 100644 --- a/src/taosdump.c +++ b/src/taosdump.c @@ -437,7 +437,7 @@ static struct argp_option options[] = { "Server host from which to dump data. Default is localhost.", 0}, {"user", 'u', "USER", 0, "User name used to connect to server. Default is root.", 0}, - {"password", 'p', 0, 0, + {"password", 'p', "PASS", 0, "User password to connect to server. Default is taosdata.", 0}, {"port", 'P', "PORT", 0, "Port to connect", 0}, // input/output file @@ -494,7 +494,7 @@ static struct argp_option options[] = { #endif {"debug", 'g', 0, 0, "Print debug info.", 15}, {"dot-replace", 'Q', 0, 0, "Repalce dot character with underline character in the table name.", 10}, - {"rename-dbname", 'W', "rename", 0, "rename database name with new name. format demo: db1=newDB1|db2=newDB2", 10}, + {"rename-dbname", 'W', "rename", 0, "rename database name with new name. format demo: -W \"db1=newDB1|db2=newDB2\" means rename db1 to newDB1 and rename db2 to newDB2", 10}, {0} }; From 97cca0439257d361c0a947d48fdc98e57e40af7a Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 13 Sep 2023 21:06:25 +0800 Subject: [PATCH 16/18] fix: help information and reset -p --- src/taosdump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/taosdump.c b/src/taosdump.c index 0882cd1b..a12bb6d4 100644 --- a/src/taosdump.c +++ b/src/taosdump.c @@ -437,7 +437,7 @@ static struct argp_option options[] = { "Server host from which to dump data. Default is localhost.", 0}, {"user", 'u', "USER", 0, "User name used to connect to server. Default is root.", 0}, - {"password", 'p', "PASS", 0, + {"password", 'p', 0, 0, "User password to connect to server. Default is taosdata.", 0}, {"port", 'P', "PORT", 0, "Port to connect", 0}, // input/output file From 4106fb74d9774ef27ee7c0a60d0bf2a853481b93 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 13 Sep 2023 21:23:21 +0800 Subject: [PATCH 17/18] fix: help information --- src/taosdump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/taosdump.c b/src/taosdump.c index a12bb6d4..97f5ed99 100644 --- a/src/taosdump.c +++ b/src/taosdump.c @@ -494,7 +494,7 @@ static struct argp_option options[] = { #endif {"debug", 'g', 0, 0, "Print debug info.", 15}, {"dot-replace", 'Q', 0, 0, "Repalce dot character with underline character in the table name.", 10}, - {"rename-dbname", 'W', "rename", 0, "rename database name with new name. format demo: -W \"db1=newDB1|db2=newDB2\" means rename db1 to newDB1 and rename db2 to newDB2", 10}, + {"rename", 'W', "RENAME-LIST", 0, "Rename database name with new name during importing data. RENAME-LIST: \"db1=newDB1|db2=newDB2\" means rename db1 to newDB1 and rename db2 to newDB2", 10}, {0} }; From 4148259f491c3df3531750916a9fc41de63cbe7f Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Thu, 14 Sep 2023 11:09:56 +0800 Subject: [PATCH 18/18] fix: modify version to 2.5.4 --- VERSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 5754c92f..2d9d10b2 100644 --- a/VERSION +++ b/VERSION @@ -1,3 +1,3 @@ taosbenchmark-3.2.3 -taosdump-2.5.3 -2.5.3 +taosdump-2.5.4 +2.5.4