未验证 提交 f2d06f08 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #2406 from taosdata/hotfix/test

Hotfix/test
......@@ -474,7 +474,7 @@ static int dumpResultToFile(const char* fname, TAOS_RES* tres) {
} while( row != NULL);
result = NULL;
taos_free_result(tres);
//taos_free_result(tres);
fclose(fp);
return numOfRows;
......@@ -803,6 +803,7 @@ void source_file(TAOS *con, char *fptr) {
char *fname = full_path.we_wordv[0];
/*
if (access(fname, F_OK) != 0) {
fprintf(stderr, "ERROR: file %s is not exist\n", fptr);
......@@ -810,6 +811,7 @@ void source_file(TAOS *con, char *fptr) {
free(cmd);
return;
}
*/
FILE *f = fopen(fname, "r");
if (f == NULL) {
......@@ -849,7 +851,7 @@ void source_file(TAOS *con, char *fptr) {
void shellGetGrantInfo(void *con) {
return;
#if 0
char sql[] = "show grants";
TAOS_RES* tres = taos_query(con, sql);
......@@ -900,4 +902,5 @@ void shellGetGrantInfo(void *con) {
}
fprintf(stdout, "\n");
#endif
}
......@@ -73,7 +73,7 @@ static void shellParseDirectory(const char *directoryName, const char *prefix, c
}
int fileNum = 0;
while (fscanf(fp, "%s", fileArray[fileNum++])) {
while (fscanf(fp, "%128s", fileArray[fileNum++])) {
if (strcmp(fileArray[fileNum-1], shellTablesSQLFile) == 0) {
fileNum--;
}
......@@ -150,9 +150,11 @@ static void shellSourceFile(TAOS *con, char *fptr) {
char *fname = full_path.we_wordv[0];
if (fname == NULL) {
fprintf(stderr, "ERROR: invalid filename\n");
free(cmd);
return;
}
/*
if (access(fname, F_OK) != 0) {
fprintf(stderr, "ERROR: file %s is not exist\n", fptr);
......@@ -168,6 +170,7 @@ static void shellSourceFile(TAOS *con, char *fptr) {
free(cmd);
return;
}
*/
FILE *f = fopen(fname, "r");
if (f == NULL) {
......
......@@ -162,7 +162,7 @@ void shellReadCommand(TAOS *con, char *command) {
// Read input.
char c;
while (1) {
c = getchar();
c = (char)getchar(); // getchar() return an 'int' value
if (c < 0) { // For UTF-8
int count = countPrefixOnes(c);
......
......@@ -34,6 +34,7 @@
#include <wordexp.h>
#include "taos.h"
#include "tutil.h"
extern char configDir[];
......@@ -82,7 +83,7 @@ typedef struct DemoArguments {
bool insert_only;
char *output_file;
int mode;
char *datatype[MAX_NUM_DATATYPE];
char *datatype[MAX_NUM_DATATYPE+1];
int len_of_binary;
int num_of_CPR;
int num_of_threads;
......@@ -432,7 +433,7 @@ int main(int argc, char *argv[]) {
tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
printf("###################################################################\n\n");
printf("Press enter key to continue");
getchar();
(void)getchar();
fprintf(fp, "###################################################################\n");
fprintf(fp, "# Server IP: %s:%hu\n", ip_addr == NULL ? "localhost" : ip_addr, port);
......@@ -845,10 +846,10 @@ void *syncWrite(void *sarg) {
pstr += sprintf(pstr, "insert into %s.%s%d values", winfo->db_name, winfo->tb_prefix, tID);
int k;
for (k = 0; k < winfo->nrecords_per_request;) {
int rand_num = rand() % 100;
int rand_num = trand() % 100;
int len = -1;
if (winfo->data_of_order ==1 && rand_num < winfo->data_of_rate) {
long d = tmp_time - rand() % 1000000 + rand_num;
long d = tmp_time - trand() % 1000000 + rand_num;
len = generateData(data, data_type, ncols_per_record, d, len_of_binary);
} else {
len = generateData(data, data_type, ncols_per_record, tmp_time += 1000, len_of_binary);
......@@ -940,10 +941,10 @@ void callBack(void *param, TAOS_RES *res, int code) {
pstr += sprintf(pstr, "insert into %s values", tb_info->tb_name);
for (int i = 0; i < tb_info->nrecords_per_request; i++) {
int rand_num = rand() % 100;
int rand_num = trand() % 100;
if (tb_info->data_of_order ==1 && rand_num < tb_info->data_of_rate)
{
long d = tmp_time - rand() % 1000000 + rand_num;
long d = tmp_time - trand() % 1000000 + rand_num;
generateData(data, datatype, ncols_per_record, d, len_of_binary);
} else
{
......@@ -985,22 +986,27 @@ int32_t generateData(char *res, char **data_type, int num_of_cols, int64_t times
}
}
if (0 == c) {
perror("data type error!");
exit(-1);
}
for (int i = 0; i < num_of_cols; i++) {
if (strcasecmp(data_type[i % c], "tinyint") == 0) {
pstr += sprintf(pstr, ", %d", (int)(rand() % 128));
pstr += sprintf(pstr, ", %d", (int)(trand() % 128));
} else if (strcasecmp(data_type[i % c], "smallint") == 0) {
pstr += sprintf(pstr, ", %d", (int)(rand() % 32767));
pstr += sprintf(pstr, ", %d", (int)(trand() % 32767));
} else if (strcasecmp(data_type[i % c], "int") == 0) {
pstr += sprintf(pstr, ", %d", (int)(rand() % 10));
pstr += sprintf(pstr, ", %d", (int)(trand() % 10));
} else if (strcasecmp(data_type[i % c], "bigint") == 0) {
pstr += sprintf(pstr, ", %" PRId64, rand() % 2147483648);
pstr += sprintf(pstr, ", %" PRId64, trand() % 2147483648);
} else if (strcasecmp(data_type[i % c], "float") == 0) {
pstr += sprintf(pstr, ", %10.4f", (float)(rand() / 1000));
pstr += sprintf(pstr, ", %10.4f", (float)(trand() / 1000));
} else if (strcasecmp(data_type[i % c], "double") == 0) {
double t = (double)(rand() / 1000000);
double t = (double)(trand() / 1000000);
pstr += sprintf(pstr, ", %20.8f", t);
} else if (strcasecmp(data_type[i % c], "bool") == 0) {
bool b = rand() & 1;
bool b = trand() & 1;
pstr += sprintf(pstr, ", %s", b ? "true" : "false");
} else if (strcasecmp(data_type[i % c], "binary") == 0) {
char s[len_of_binary];
......@@ -1026,7 +1032,7 @@ void rand_string(char *str, int size) {
--size;
int n;
for (n = 0; n < size; n++) {
int key = rand() % (int)(sizeof charset - 1);
int key = trand() % (int)(sizeof charset - 1);
str[n] = charset[key];
}
str[n] = 0;
......
......@@ -229,7 +229,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
fprintf(stderr, "Invalid path %s\n", arg);
return -1;
}
strcpy(arguments->output, full_path.we_wordv[0]);
tstrncpy(arguments->output, full_path.we_wordv[0], TSDB_FILENAME_LEN);
wordfree(&full_path);
break;
case 'i':
......@@ -411,7 +411,7 @@ int taosGetTableRecordInfo(char *table, STableRecordInfo *pTableRecordInfo) {
if ((row = taos_fetch_row(result)) != NULL) {
isSet = true;
pTableRecordInfo->isMetric = true;
strcpy(pTableRecordInfo->tableRecord.metric, table);
tstrncpy(pTableRecordInfo->tableRecord.metric, table, TSDB_TABLE_NAME_LEN);
}
taos_free_result(result);
......@@ -642,9 +642,12 @@ int taosDumpDb(SDbInfo *dbInfo, SDumpArguments *arguments, FILE *fp) {
taos_free_result(result);
lseek(fd, 0, SEEK_SET);
(void)lseek(fd, 0, SEEK_SET);
while (1) {
ssize_t ret = read(fd, &tableRecord, sizeof(STableRecord));
if (ret <= 0) break;
while (read(fd, &tableRecord, sizeof(STableRecord)) > 0) {
tableRecord.name[sizeof(tableRecord.name) - 1] = 0;
tableRecord.metric[sizeof(tableRecord.metric) - 1] = 0;
taosDumpTable(tableRecord.name, tableRecord.metric, arguments, fp);
......@@ -807,7 +810,7 @@ int taosGetTableDes(char *table, STableDef *tableDes) {
TAOS_FIELD *fields = taos_fetch_fields(result);
strcpy(tableDes->name, table);
tstrncpy(tableDes->name, table, TSDB_COL_NAME_LEN);
while ((row = taos_fetch_row(result)) != NULL) {
strncpy(tableDes->cols[count].field, (char *)row[TSDB_DESCRIBE_METRIC_FIELD_INDEX],
......@@ -903,16 +906,19 @@ int32_t taosDumpMetric(char *metric, SDumpArguments *arguments, FILE *fp) {
taos_free_result(result);
result = NULL;
lseek(fd, 0, SEEK_SET);
(void)lseek(fd, 0, SEEK_SET);
while (1) {
ssize_t ret = read(fd, &tableRecord, sizeof(STableRecord));
if (ret <= 0) break;
while (read(fd, &tableRecord, sizeof(STableRecord)) > 0) {
tableRecord.name[sizeof(tableRecord.name) - 1] = 0;
tableRecord.metric[sizeof(tableRecord.metric) - 1] = 0;
taosDumpTable(tableRecord.name, tableRecord.metric, arguments, fp);
}
tclose(fd);
remove(".table.tmp");
(void)remove(".table.tmp");
return 0;
}
......@@ -1004,7 +1010,7 @@ int taosDumpTableData(FILE *fp, char *tbname, SDumpArguments *arguments) {
break;
}
}
pstr += sprintf(pstr, ")");
sprintf(pstr, ")");
count++;
fprintf(fp, "%s", buffer);
......@@ -1327,7 +1333,7 @@ int convertNCharToReadable(char *str, int size, char *buf, int bufsize) {
if ((int)wc < 256) {
pbuf = stpcpy(pbuf, ascii_literal_list[(int)wc]);
} else {
} else if (byte_width > 0) {
memcpy(pbuf, pstr, byte_width);
pbuf += byte_width;
}
......
......@@ -162,7 +162,7 @@ static void taosGetSystemTimezone() {
FILE *f = fopen("/etc/timezone", "r");
char buf[65] = {0};
if (f != NULL) {
fread(buf, 64, 1, f);
(void)fread(buf, 64, 1, f);
fclose(f);
}
......@@ -547,7 +547,7 @@ void taosSetCoreDump() {
struct rlimit rlim;
struct rlimit rlim_new;
if (getrlimit(RLIMIT_CORE, &rlim) == 0) {
uPrint("the old unlimited para: rlim_cur=%d, rlim_max=%d", rlim.rlim_cur, rlim.rlim_max);
uPrint("the old unlimited para: rlim_cur=%d, rlim_max=%" PRIu64, rlim.rlim_cur, rlim.rlim_max);
rlim_new.rlim_cur = RLIM_INFINITY;
rlim_new.rlim_max = RLIM_INFINITY;
if (setrlimit(RLIMIT_CORE, &rlim_new) != 0) {
......@@ -559,7 +559,7 @@ void taosSetCoreDump() {
}
if (getrlimit(RLIMIT_CORE, &rlim) == 0) {
uPrint("the new unlimited para: rlim_cur=%d, rlim_max=%d", rlim.rlim_cur, rlim.rlim_max);
uPrint("the new unlimited para: rlim_cur=%d, rlim_max=%" PRIu64, rlim.rlim_cur, rlim.rlim_max);
}
#ifndef _TD_ARM_
......@@ -586,7 +586,7 @@ void taosSetCoreDump() {
uPrint("_sysctl(kern_core_uses_pid) set fail: %s", strerror(errno));
}
uPrint("The old core_uses_pid[%d]: %d", old_len, old_usespid);
uPrint("The old core_uses_pid[%" PRIu64 "]: %d", old_len, old_usespid);
old_usespid = 0;
......@@ -603,7 +603,7 @@ void taosSetCoreDump() {
uPrint("_sysctl(kern_core_uses_pid) get fail: %s", strerror(errno));
}
uPrint("The new core_uses_pid[%d]: %d", old_len, old_usespid);
uPrint("The new core_uses_pid[%" PRIu64 "]: %d", old_len, old_usespid);
#endif
#if 0
......
......@@ -119,6 +119,8 @@ extern "C" {
uint32_t taosRand(void);
uint32_t trand(void);
size_t twcslen(const wchar_t *wcs);
int32_t strdequote(char *src);
......
......@@ -128,10 +128,12 @@ int taosOpenNewNote(taosNoteInfo * pNote)
bool taosCheckNoteIsOpen(char *noteName, taosNoteInfo * pNote)
{
/*
int exist = access(noteName, F_OK);
if (exist != 0) {
return false;
}
*/
int fd = open(noteName, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
if (fd < 0) {
......
......@@ -55,6 +55,25 @@ uint32_t taosRand(void)
*/
return rand();
}
uint32_t trand(void)
{
int fd;
int seed;
fd = open("/dev/urandom", 0);
if (fd < 0) {
seed = time(0);
} else {
int len = read(fd, &seed, sizeof(seed));
if (len < 0) {
seed = time(0);
}
close(fd);
}
return (uint32_t)seed;
}
#endif
size_t twcslen(const wchar_t *wcs) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册