未验证 提交 11e28e3d 编写于 作者: sangshuduo's avatar sangshuduo 提交者: GitHub

Hotfix/sangshuduo/td 10530 taosdump inf loop for develop (#8171)

* [TD-10530]<fix>: taosdump infinite loop

query table des fail on normal table.
and value is NULL.

* fix binary string with quote symbol
上级 544f1323
...@@ -1020,25 +1020,25 @@ static void dumpCreateMTableClause( ...@@ -1020,25 +1020,25 @@ static void dumpCreateMTableClause(
strcasecmp(tableDes->cols[counter].type, "nchar") == 0) { strcasecmp(tableDes->cols[counter].type, "nchar") == 0) {
//pstr += sprintf(pstr, ", \'%s\'", tableDes->cols[counter].note); //pstr += sprintf(pstr, ", \'%s\'", tableDes->cols[counter].note);
if (tableDes->cols[counter].var_value) { if (tableDes->cols[counter].var_value) {
pstr += sprintf(pstr, ", %s", pstr += sprintf(pstr, ", \'%s\'",
tableDes->cols[counter].var_value); tableDes->cols[counter].var_value);
} else { } else {
pstr += sprintf(pstr, ", %s", tableDes->cols[counter].value); pstr += sprintf(pstr, ", \'%s\'", tableDes->cols[counter].value);
} }
} else { } else {
pstr += sprintf(pstr, ", %s", tableDes->cols[counter].value); pstr += sprintf(pstr, ", \'%s\'", tableDes->cols[counter].value);
} }
} else { } else {
if (strcasecmp(tableDes->cols[counter].type, "binary") == 0 || if (strcasecmp(tableDes->cols[counter].type, "binary") == 0 ||
strcasecmp(tableDes->cols[counter].type, "nchar") == 0) { strcasecmp(tableDes->cols[counter].type, "nchar") == 0) {
//pstr += sprintf(pstr, "\'%s\'", tableDes->cols[counter].note); //pstr += sprintf(pstr, "\'%s\'", tableDes->cols[counter].note);
if (tableDes->cols[counter].var_value) { if (tableDes->cols[counter].var_value) {
pstr += sprintf(pstr, "%s", tableDes->cols[counter].var_value); pstr += sprintf(pstr, "\'%s\'", tableDes->cols[counter].var_value);
} else { } else {
pstr += sprintf(pstr, "%s", tableDes->cols[counter].value); pstr += sprintf(pstr, "\'%s\'", tableDes->cols[counter].value);
} }
} else { } else {
pstr += sprintf(pstr, "%s", tableDes->cols[counter].value); pstr += sprintf(pstr, "\'%s\'", tableDes->cols[counter].value);
} }
/* pstr += sprintf(pstr, "%s", tableDes->cols[counter].note); */ /* pstr += sprintf(pstr, "%s", tableDes->cols[counter].note); */
} }
...@@ -1149,6 +1149,10 @@ static int64_t dumpNormalTable( ...@@ -1149,6 +1149,10 @@ static int64_t dumpNormalTable(
colCount = getTableDes(dbName, tbName, tableDes, false); colCount = getTableDes(dbName, tbName, tableDes, false);
if (colCount < 0) { if (colCount < 0) {
errorPrint("%s() LN%d, failed to get table[%s] schema\n",
__func__,
__LINE__,
tbName);
free(tableDes); free(tableDes);
return -1; return -1;
} }
...@@ -1160,6 +1164,10 @@ static int64_t dumpNormalTable( ...@@ -1160,6 +1164,10 @@ static int64_t dumpNormalTable(
colCount = getTableDes(dbName, tbName, tableDes, false); colCount = getTableDes(dbName, tbName, tableDes, false);
if (colCount < 0) { if (colCount < 0) {
errorPrint("%s() LN%d, failed to get table[%s] schema\n",
__func__,
__LINE__,
tbName);
free(tableDes); free(tableDes);
return -1; return -1;
} }
...@@ -1172,19 +1180,21 @@ static int64_t dumpNormalTable( ...@@ -1172,19 +1180,21 @@ static int64_t dumpNormalTable(
if (g_args.avro) { if (g_args.avro) {
if (0 != convertTbDesToAvroSchema( if (0 != convertTbDesToAvroSchema(
dbName, tbName, tableDes, colCount, &jsonAvroSchema)) { dbName, tbName, tableDes, colCount, &jsonAvroSchema)) {
errorPrint("%s() LN%d, convertTbDesToAvroSchema failed\n",
__func__,
__LINE__);
freeTbDes(tableDes); freeTbDes(tableDes);
return -1; return -1;
} }
} }
free(tableDes);
int64_t ret = 0; int64_t ret = 0;
if (!g_args.schemaonly) { if (!g_args.schemaonly) {
ret = dumpTableData(fp, tbName, dbName, precision, ret = dumpTableData(fp, tbName, dbName, precision,
jsonAvroSchema); jsonAvroSchema);
} }
freeTbDes(tableDes);
return ret; return ret;
} }
...@@ -1281,20 +1291,23 @@ static void *dumpNtbOfDb(void *arg) { ...@@ -1281,20 +1291,23 @@ static void *dumpNtbOfDb(void *arg) {
return NULL; return NULL;
} }
int64_t count;
for (int64_t i = 0; i < pThreadInfo->tablesOfDumpOut; i++) { for (int64_t i = 0; i < pThreadInfo->tablesOfDumpOut; i++) {
debugPrint("[%d] No.\t%"PRId64" table name: %s\n", debugPrint("[%d] No.\t%"PRId64" table name: %s\n",
pThreadInfo->threadIndex, i, pThreadInfo->threadIndex, i,
((TableInfo *)(g_tablesList + pThreadInfo->tableFrom+i))->name); ((TableInfo *)(g_tablesList + pThreadInfo->tableFrom+i))->name);
dumpNormalTable( count = dumpNormalTable(
pThreadInfo->dbName, pThreadInfo->dbName,
((TableInfo *)(g_tablesList + pThreadInfo->tableFrom+i))->stable, ((TableInfo *)(g_tablesList + pThreadInfo->tableFrom+i))->stable,
((TableInfo *)(g_tablesList + pThreadInfo->tableFrom+i))->name, ((TableInfo *)(g_tablesList + pThreadInfo->tableFrom+i))->name,
pThreadInfo->precision, pThreadInfo->precision,
fp); fp);
if (count < 0) {
break;
}
} }
fclose(fp); fclose(fp);
return NULL; return NULL;
} }
...@@ -1340,16 +1353,20 @@ static void *dumpNormalTablesOfStb(void *arg) { ...@@ -1340,16 +1353,20 @@ static void *dumpNormalTablesOfStb(void *arg) {
TAOS_ROW row = NULL; TAOS_ROW row = NULL;
int64_t i = 0; int64_t i = 0;
int64_t count;
while((row = taos_fetch_row(res)) != NULL) { while((row = taos_fetch_row(res)) != NULL) {
debugPrint("[%d] sub table %"PRId64": name: %s\n", debugPrint("[%d] sub table %"PRId64": name: %s\n",
pThreadInfo->threadIndex, i++, (char *)row[TSDB_SHOW_TABLES_NAME_INDEX]); pThreadInfo->threadIndex, i++, (char *)row[TSDB_SHOW_TABLES_NAME_INDEX]);
dumpNormalTable( count = dumpNormalTable(
pThreadInfo->dbName, pThreadInfo->dbName,
pThreadInfo->stbName, pThreadInfo->stbName,
(char *)row[TSDB_SHOW_TABLES_NAME_INDEX], (char *)row[TSDB_SHOW_TABLES_NAME_INDEX],
pThreadInfo->precision, pThreadInfo->precision,
fp); fp);
if (count < 0) {
break;
}
} }
fclose(fp); fclose(fp);
...@@ -2006,9 +2023,9 @@ static int getTableDes( ...@@ -2006,9 +2023,9 @@ static int getTableDes(
if (row[TSDB_SHOW_TABLES_NAME_INDEX] == NULL) { if (row[TSDB_SHOW_TABLES_NAME_INDEX] == NULL) {
sprintf(tableDes->cols[i].note, "%s", "NUL"); sprintf(tableDes->cols[i].note, "%s", "NUL");
sprintf(tableDes->cols[i].value, "%s", "NULL");
taos_free_result(res); taos_free_result(res);
res = NULL; res = NULL;
taos_close(taos);
continue; continue;
} }
...@@ -2050,26 +2067,22 @@ static int getTableDes( ...@@ -2050,26 +2067,22 @@ static int getTableDes(
int len = strlen((char *)row[0]); int len = strlen((char *)row[0]);
// FIXME for long value // FIXME for long value
if (len < (COL_VALUEBUF_LEN - 2)) { if (len < (COL_VALUEBUF_LEN - 2)) {
tableDes->cols[i].value[0] = '\'';
converStringToReadable( converStringToReadable(
(char *)row[0], (char *)row[0],
length[0], length[0],
tableDes->cols[i].value + 1, tableDes->cols[i].value,
len); len);
tableDes->cols[i].value[len+1] = '\'';
} else { } else {
tableDes->cols[i].var_value = calloc(1, len + 2); tableDes->cols[i].var_value = calloc(1, len * 2);
if (tableDes->cols[i].var_value == NULL) { if (tableDes->cols[i].var_value == NULL) {
errorPrint("%s() LN%d, memory alalocation failed!\n", errorPrint("%s() LN%d, memory alalocation failed!\n",
__func__, __LINE__); __func__, __LINE__);
taos_free_result(res); taos_free_result(res);
return -1; return -1;
} }
tableDes->cols[i].var_value[0] = '\'';
converStringToReadable((char *)row[0], converStringToReadable((char *)row[0],
length[0], length[0],
(char *)(tableDes->cols[i].var_value + 1), len); (char *)(tableDes->cols[i].var_value), len);
tableDes->cols[i].var_value[len+1] = '\'';
} }
break; break;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册