Merge branch 'develop' into feature/2.0tsdb
This commit is contained in:
commit
5fe9e5864f
|
@ -201,7 +201,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) {
|
||||||
tscPrint("set shellActivityTimer:%d", tsShellActivityTimer);
|
tscPrint("set shellActivityTimer:%d", tsShellActivityTimer);
|
||||||
} else {
|
} else {
|
||||||
tscWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, pStr,
|
tscWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, pStr,
|
||||||
tsCfgStatusStr[cfg->cfgStatus], (int32_t *)cfg->ptr);
|
tsCfgStatusStr[cfg->cfgStatus], *(int32_t *)cfg->ptr);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -727,10 +727,6 @@ void read_history() {
|
||||||
char f_history[TSDB_FILENAME_LEN];
|
char f_history[TSDB_FILENAME_LEN];
|
||||||
get_history_path(f_history);
|
get_history_path(f_history);
|
||||||
|
|
||||||
if (access(f_history, R_OK) == -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
FILE *f = fopen(f_history, "r");
|
FILE *f = fopen(f_history, "r");
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
fprintf(stderr, "Opening file %s\n", f_history);
|
fprintf(stderr, "Opening file %s\n", f_history);
|
||||||
|
@ -809,14 +805,6 @@ void source_file(TAOS *con, char *fptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (access(fname, R_OK) != 0) {
|
|
||||||
fprintf(stderr, "ERROR: file %s is not readable\n", fptr);
|
|
||||||
|
|
||||||
wordfree(&full_path);
|
|
||||||
free(cmd);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
FILE *f = fopen(fname, "r");
|
FILE *f = fopen(fname, "r");
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
fprintf(stderr, "ERROR: failed to open file %s\n", fname);
|
fprintf(stderr, "ERROR: failed to open file %s\n", fname);
|
||||||
|
|
|
@ -646,10 +646,9 @@ int taosDumpDb(SDbInfo *dbInfo, SDumpArguments *arguments, FILE *fp) {
|
||||||
taosDumpTable(tableRecord.name, tableRecord.metric, arguments, fp);
|
taosDumpTable(tableRecord.name, tableRecord.metric, arguments, fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
tclose(fd);
|
close(fd);
|
||||||
remove(".table.tmp");
|
|
||||||
|
|
||||||
return 0;
|
return remove(".table.tmp");
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosDumpCreateTableClause(STableDef *tableDes, int numOfCols, SDumpArguments *arguments, FILE *fp) {
|
void taosDumpCreateTableClause(STableDef *tableDes, int numOfCols, SDumpArguments *arguments, FILE *fp) {
|
||||||
|
|
|
@ -331,66 +331,7 @@ bool taosGetDisk() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool taosGetCardName(char *ip, char *name) {
|
|
||||||
struct ifaddrs *ifaddr, *ifa;
|
|
||||||
int family, s;
|
|
||||||
char host[NI_MAXHOST];
|
|
||||||
bool ret = false;
|
|
||||||
|
|
||||||
if (getifaddrs(&ifaddr) == -1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Walk through linked list, maintaining head pointer so we can free list
|
|
||||||
* later */
|
|
||||||
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
|
|
||||||
if (ifa->ifa_addr == NULL) continue;
|
|
||||||
|
|
||||||
family = ifa->ifa_addr->sa_family;
|
|
||||||
if (family != AF_INET) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
s = getnameinfo(ifa->ifa_addr, (family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6), host,
|
|
||||||
NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
|
|
||||||
if (s != 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(host, "127.0.0.1") == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: the ip not config
|
|
||||||
// if (strcmp(host, ip) == 0) {
|
|
||||||
strcpy(name, ifa->ifa_name);
|
|
||||||
ret = true;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
freeifaddrs(ifaddr);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool taosGetCardInfo(int64_t *bytes) {
|
static bool taosGetCardInfo(int64_t *bytes) {
|
||||||
static char tsPublicCard[1000] = {0};
|
|
||||||
static char tsPrivateIp[40];
|
|
||||||
|
|
||||||
if (tsPublicCard[0] == 0) {
|
|
||||||
if (!taosGetCardName(tsPrivateIp, tsPublicCard)) {
|
|
||||||
uError("can't get card name from ip:%s", tsPrivateIp);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
int cardNameLen = (int)strlen(tsPublicCard);
|
|
||||||
for (int i = 0; i < cardNameLen; ++i) {
|
|
||||||
if (tsPublicCard[i] == ':') {
|
|
||||||
tsPublicCard[i] = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// uTrace("card name of public ip:%s is %s", tsPublicIp, tsPublicCard);
|
|
||||||
}
|
|
||||||
|
|
||||||
FILE *fp = fopen(tsSysNetFile, "r");
|
FILE *fp = fopen(tsSysNetFile, "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
uError("open file:%s failed", tsSysNetFile);
|
uError("open file:%s failed", tsSysNetFile);
|
||||||
|
@ -403,6 +344,7 @@ static bool taosGetCardInfo(int64_t *bytes) {
|
||||||
|
|
||||||
size_t len;
|
size_t len;
|
||||||
char * line = NULL;
|
char * line = NULL;
|
||||||
|
*bytes = 0;
|
||||||
|
|
||||||
while (!feof(fp)) {
|
while (!feof(fp)) {
|
||||||
tfree(line);
|
tfree(line);
|
||||||
|
@ -411,23 +353,20 @@ static bool taosGetCardInfo(int64_t *bytes) {
|
||||||
if (line == NULL) {
|
if (line == NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (strstr(line, tsPublicCard) != NULL) {
|
if (strstr(line, "lo:") != NULL) {
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sscanf(line,
|
||||||
|
"%s %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
|
||||||
|
nouse0, &rbytes, &rpackts, &nouse1, &nouse2, &nouse3, &nouse4, &nouse5, &nouse6, &tbytes, &tpackets);
|
||||||
|
*bytes += (rbytes + tbytes);
|
||||||
}
|
}
|
||||||
if (line != NULL) {
|
|
||||||
sscanf(line, "%s %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64, nouse0, &rbytes, &rpackts, &nouse1, &nouse2, &nouse3,
|
tfree(line);
|
||||||
&nouse4, &nouse5, &nouse6, &tbytes, &tpackets);
|
fclose(fp);
|
||||||
*bytes = rbytes + tbytes;
|
|
||||||
tfree(line);
|
return true;
|
||||||
fclose(fp);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
uWarn("can't get card:%s info from device:%s", tsPublicCard, tsSysNetFile);
|
|
||||||
*bytes = 0;
|
|
||||||
fclose(fp);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool taosGetBandSpeed(float *bandSpeedKb) {
|
bool taosGetBandSpeed(float *bandSpeedKb) {
|
||||||
|
@ -443,13 +382,15 @@ bool taosGetBandSpeed(float *bandSpeedKb) {
|
||||||
if (lastTime == 0 || lastBytes == 0) {
|
if (lastTime == 0 || lastBytes == 0) {
|
||||||
lastTime = curTime;
|
lastTime = curTime;
|
||||||
lastBytes = curBytes;
|
lastBytes = curBytes;
|
||||||
return false;
|
*bandSpeedKb = 0;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastTime >= curTime || lastBytes > curBytes) {
|
if (lastTime >= curTime || lastBytes > curBytes) {
|
||||||
lastTime = curTime;
|
lastTime = curTime;
|
||||||
lastBytes = curBytes;
|
lastBytes = curBytes;
|
||||||
return false;
|
*bandSpeedKb = 0;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
double totalBytes = (double)(curBytes - lastBytes) / 1024 * 8; // Kb
|
double totalBytes = (double)(curBytes - lastBytes) / 1024 * 8; // Kb
|
||||||
|
|
|
@ -22,9 +22,27 @@
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
|
|
||||||
static HttpDecodeMethod gcDecodeMethod = {"grafana", gcProcessRequest};
|
static HttpDecodeMethod gcDecodeMethod = {"grafana", gcProcessRequest};
|
||||||
static HttpEncodeMethod gcHeartBeatMethod = {NULL, gcSendHeartBeatResp, NULL, NULL, NULL, NULL, NULL, NULL};
|
static HttpEncodeMethod gcHeartBeatMethod = {
|
||||||
|
.startJsonFp = NULL,
|
||||||
|
.stopJsonFp = gcSendHeartBeatResp,
|
||||||
|
.buildQueryJsonFp = NULL,
|
||||||
|
.buildAffectRowJsonFp = NULL,
|
||||||
|
.initJsonFp = NULL,
|
||||||
|
.cleanJsonFp = NULL,
|
||||||
|
.checkFinishedFp = NULL,
|
||||||
|
.setNextCmdFp = NULL
|
||||||
|
};
|
||||||
|
|
||||||
static HttpEncodeMethod gcQueryMethod = {
|
static HttpEncodeMethod gcQueryMethod = {
|
||||||
NULL, gcStopQueryJson, gcBuildQueryJson, NULL, gcInitQueryJson, gcCleanQueryJson, NULL, NULL};
|
.startJsonFp = NULL,
|
||||||
|
.stopJsonFp = gcStopQueryJson,
|
||||||
|
.buildQueryJsonFp = gcBuildQueryJson,
|
||||||
|
.buildAffectRowJsonFp = NULL,
|
||||||
|
.initJsonFp = gcInitQueryJson,
|
||||||
|
.cleanJsonFp = gcCleanQueryJson,
|
||||||
|
.checkFinishedFp = NULL,
|
||||||
|
.setNextCmdFp = NULL
|
||||||
|
};
|
||||||
|
|
||||||
void gcInitHandle(HttpServer* pServer) { httpAddMethod(pServer, &gcDecodeMethod); }
|
void gcInitHandle(HttpServer* pServer) { httpAddMethod(pServer, &gcDecodeMethod); }
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,7 @@ void httpProcessMultiSqlCallBack(void *param, TAOS_RES *result, int code) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code < 0) {
|
if (code < 0) {
|
||||||
if (encode->checkFinishedFp != NULL && !encode->checkFinishedFp(pContext, singleCmd, code >= 0 ? 0 : code)) {
|
if (encode->checkFinishedFp != NULL && !encode->checkFinishedFp(pContext, singleCmd, -code)) {
|
||||||
singleCmd->code = code;
|
singleCmd->code = code;
|
||||||
httpTrace("context:%p, fd:%d, ip:%s, user:%s, process pos jump to:%d, last code:%s, last sql:%s",
|
httpTrace("context:%p, fd:%d, ip:%s, user:%s, process pos jump to:%d, last code:%s, last sql:%s",
|
||||||
pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos + 1, tstrerror(code), sql);
|
pContext, pContext->fd, pContext->ipstr, pContext->user, multiCmds->pos + 1, tstrerror(code), sql);
|
||||||
|
|
|
@ -22,11 +22,37 @@
|
||||||
static HttpDecodeMethod restDecodeMethod = {"rest", restProcessRequest};
|
static HttpDecodeMethod restDecodeMethod = {"rest", restProcessRequest};
|
||||||
static HttpDecodeMethod restDecodeMethod2 = {"restful", restProcessRequest};
|
static HttpDecodeMethod restDecodeMethod2 = {"restful", restProcessRequest};
|
||||||
static HttpEncodeMethod restEncodeSqlTimestampMethod = {
|
static HttpEncodeMethod restEncodeSqlTimestampMethod = {
|
||||||
restStartSqlJson, restStopSqlJson, restBuildSqlTimestampJson, restBuildSqlAffectRowsJson, NULL, NULL, NULL, NULL};
|
.startJsonFp = restStartSqlJson,
|
||||||
|
.stopJsonFp = restStopSqlJson,
|
||||||
|
.buildQueryJsonFp = restBuildSqlTimestampJson,
|
||||||
|
.buildAffectRowJsonFp = restBuildSqlAffectRowsJson,
|
||||||
|
.initJsonFp = NULL,
|
||||||
|
.cleanJsonFp = NULL,
|
||||||
|
.checkFinishedFp = NULL,
|
||||||
|
.setNextCmdFp = NULL
|
||||||
|
};
|
||||||
|
|
||||||
static HttpEncodeMethod restEncodeSqlLocalTimeStringMethod = {
|
static HttpEncodeMethod restEncodeSqlLocalTimeStringMethod = {
|
||||||
restStartSqlJson, restStopSqlJson, restBuildSqlLocalTimeStringJson, restBuildSqlAffectRowsJson, NULL, NULL, NULL, NULL};
|
.startJsonFp = restStartSqlJson,
|
||||||
|
.stopJsonFp = restStopSqlJson,
|
||||||
|
.buildQueryJsonFp = restBuildSqlLocalTimeStringJson,
|
||||||
|
.buildAffectRowJsonFp = restBuildSqlAffectRowsJson,
|
||||||
|
.initJsonFp = NULL,
|
||||||
|
.cleanJsonFp = NULL,
|
||||||
|
.checkFinishedFp = NULL,
|
||||||
|
.setNextCmdFp = NULL
|
||||||
|
};
|
||||||
|
|
||||||
static HttpEncodeMethod restEncodeSqlUtcTimeStringMethod = {
|
static HttpEncodeMethod restEncodeSqlUtcTimeStringMethod = {
|
||||||
restStartSqlJson, restStopSqlJson, restBuildSqlUtcTimeStringJson, restBuildSqlAffectRowsJson, NULL, NULL, NULL, NULL};
|
.startJsonFp = restStartSqlJson,
|
||||||
|
.stopJsonFp = restStopSqlJson,
|
||||||
|
.buildQueryJsonFp = restBuildSqlUtcTimeStringJson,
|
||||||
|
.buildAffectRowJsonFp = restBuildSqlAffectRowsJson,
|
||||||
|
.initJsonFp = NULL,
|
||||||
|
.cleanJsonFp = NULL,
|
||||||
|
.checkFinishedFp = NULL,
|
||||||
|
.setNextCmdFp = NULL
|
||||||
|
};
|
||||||
|
|
||||||
void restInitHandle(HttpServer* pServer) {
|
void restInitHandle(HttpServer* pServer) {
|
||||||
httpAddMethod(pServer, &restDecodeMethod);
|
httpAddMethod(pServer, &restDecodeMethod);
|
||||||
|
|
|
@ -62,9 +62,16 @@
|
||||||
#define TG_MAX_SORT_TAG_SIZE 20
|
#define TG_MAX_SORT_TAG_SIZE 20
|
||||||
|
|
||||||
static HttpDecodeMethod tgDecodeMethod = {"telegraf", tgProcessRquest};
|
static HttpDecodeMethod tgDecodeMethod = {"telegraf", tgProcessRquest};
|
||||||
static HttpEncodeMethod tgQueryMethod = {tgStartQueryJson, tgStopQueryJson, NULL,
|
static HttpEncodeMethod tgQueryMethod = {
|
||||||
tgBuildSqlAffectRowsJson, tgInitQueryJson, tgCleanQueryJson,
|
.startJsonFp = tgStartQueryJson,
|
||||||
tgCheckFinished, tgSetNextCmd};
|
.stopJsonFp = tgStopQueryJson,
|
||||||
|
.buildQueryJsonFp = NULL,
|
||||||
|
.buildAffectRowJsonFp = tgBuildSqlAffectRowsJson,
|
||||||
|
.initJsonFp = tgInitQueryJson,
|
||||||
|
.cleanJsonFp = tgCleanQueryJson,
|
||||||
|
.checkFinishedFp = tgCheckFinished,
|
||||||
|
.setNextCmdFp = tgSetNextCmd
|
||||||
|
};
|
||||||
|
|
||||||
static const char DEFAULT_TELEGRAF_CFG[] =
|
static const char DEFAULT_TELEGRAF_CFG[] =
|
||||||
"{\"metrics\":["
|
"{\"metrics\":["
|
||||||
|
@ -303,7 +310,7 @@ bool tgGetUserFromUrl(HttpContext *pContext) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(pContext->user, pParser->path[TG_USER_URL_POS].pos);
|
tstrncpy(pContext->user, pParser->path[TG_USER_URL_POS].pos, TSDB_USER_LEN);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -191,15 +191,14 @@ void taosResetLog() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool taosCheckFileIsOpen(char *logFileName) {
|
static bool taosCheckFileIsOpen(char *logFileName) {
|
||||||
int32_t exist = access(logFileName, F_OK);
|
int32_t fd = open(logFileName, O_WRONLY, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||||
if (exist != 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t fd = open(logFileName, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
printf("\nfailed to open log file:%s, reason:%s\n", logFileName, strerror(errno));
|
if (errno == ENOENT) {
|
||||||
return true;
|
return false;
|
||||||
|
} else {
|
||||||
|
printf("\nfailed to open log file:%s, reason:%s\n", logFileName, strerror(errno));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosLockFile(fd)) {
|
if (taosLockFile(fd)) {
|
||||||
|
|
Loading…
Reference in New Issue