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

Merge pull request #3018 from taosdata/feature/os

Feature/os
...@@ -1125,7 +1125,7 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t ...@@ -1125,7 +1125,7 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t
int32_t tableIndex = columnList.ids[0].tableIndex; int32_t tableIndex = columnList.ids[0].tableIndex;
// todo potential data overflow // todo potential data overflow
char arithmeticExprStr[1024*12]; char* arithmeticExprStr = malloc(1024*1024);
char* p = arithmeticExprStr; char* p = arithmeticExprStr;
if (arithmeticType == NORMAL_ARITHMETIC) { if (arithmeticType == NORMAL_ARITHMETIC) {
...@@ -1134,11 +1134,13 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t ...@@ -1134,11 +1134,13 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t
// all columns in arithmetic expression must belong to the same table // all columns in arithmetic expression must belong to the same table
for (int32_t f = 1; f < columnList.num; ++f) { for (int32_t f = 1; f < columnList.num; ++f) {
if (columnList.ids[f].tableIndex != tableIndex) { if (columnList.ids[f].tableIndex != tableIndex) {
taosTFree(arithmeticExprStr);
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg4);
} }
} }
if (arithmeticExprToString(pItem->pNode, &p) != TSDB_CODE_SUCCESS) { if (arithmeticExprToString(pItem->pNode, &p) != TSDB_CODE_SUCCESS) {
taosTFree(arithmeticExprStr);
return TSDB_CODE_TSC_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
...@@ -1157,6 +1159,7 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t ...@@ -1157,6 +1159,7 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t
int32_t ret = exprTreeFromSqlExpr(pCmd, &pNode, pItem->pNode, pQueryInfo->exprList, pQueryInfo, colList); int32_t ret = exprTreeFromSqlExpr(pCmd, &pNode, pItem->pNode, pQueryInfo->exprList, pQueryInfo, colList);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
tExprTreeDestroy(&pNode, NULL); tExprTreeDestroy(&pNode, NULL);
taosTFree(arithmeticExprStr);
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
} }
...@@ -1164,6 +1167,7 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t ...@@ -1164,6 +1167,7 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t
for(int32_t k = 0; k < numOfNode; ++k) { for(int32_t k = 0; k < numOfNode; ++k) {
SColIndex* pIndex = taosArrayGet(colList, k); SColIndex* pIndex = taosArrayGet(colList, k);
if (pIndex->flag == 1) { if (pIndex->flag == 1) {
taosTFree(arithmeticExprStr);
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
} }
} }
...@@ -1190,6 +1194,7 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t ...@@ -1190,6 +1194,7 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t
tExprTreeDestroy(&pNode, NULL); tExprTreeDestroy(&pNode, NULL);
} else { } else {
if (arithmeticExprToString(pItem->pNode, &p) != TSDB_CODE_SUCCESS) { if (arithmeticExprToString(pItem->pNode, &p) != TSDB_CODE_SUCCESS) {
taosTFree(arithmeticExprStr);
return TSDB_CODE_TSC_INVALID_SQL; return TSDB_CODE_TSC_INVALID_SQL;
} }
...@@ -1213,6 +1218,7 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t ...@@ -1213,6 +1218,7 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t
int32_t ret = exprTreeFromSqlExpr(pCmd, &pArithExprInfo->pExpr, pItem->pNode, pQueryInfo->exprList, pQueryInfo, NULL); int32_t ret = exprTreeFromSqlExpr(pCmd, &pArithExprInfo->pExpr, pItem->pNode, pQueryInfo->exprList, pQueryInfo, NULL);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
tExprTreeDestroy(&pArithExprInfo->pExpr, NULL); tExprTreeDestroy(&pArithExprInfo->pExpr, NULL);
taosTFree(arithmeticExprStr);
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), "invalid expression in select clause"); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), "invalid expression in select clause");
} }
...@@ -1220,6 +1226,7 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t ...@@ -1220,6 +1226,7 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t
} }
} }
taosTFree(arithmeticExprStr);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
......
...@@ -128,6 +128,9 @@ static int32_t shellRunSingleCommand(TAOS *con, char *command) { ...@@ -128,6 +128,9 @@ static int32_t shellRunSingleCommand(TAOS *con, char *command) {
if (regex_match(command, "^[ \t]*(quit|q|exit)[ \t;]*$", REG_EXTENDED | REG_ICASE)) { if (regex_match(command, "^[ \t]*(quit|q|exit)[ \t;]*$", REG_EXTENDED | REG_ICASE)) {
taos_close(con); taos_close(con);
write_history(); write_history();
#ifdef WINDOWS
exit(EXIT_SUCCESS);
#endif
return -1; return -1;
} }
...@@ -368,6 +371,10 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) { ...@@ -368,6 +371,10 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) {
tt = (time_t)(val / 1000); tt = (time_t)(val / 1000);
} }
if (tt < 0) {
tt = 0;
}
struct tm* ptm = localtime(&tt); struct tm* ptm = localtime(&tt);
size_t pos = strftime(buf, 32, "%Y-%m-%d %H:%M:%S", ptm); size_t pos = strftime(buf, 32, "%Y-%m-%d %H:%M:%S", ptm);
...@@ -736,7 +743,7 @@ void read_history() { ...@@ -736,7 +743,7 @@ void read_history() {
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, "Failed to open file %s\n", f_history);
return; return;
} }
...@@ -761,7 +768,7 @@ void write_history() { ...@@ -761,7 +768,7 @@ void write_history() {
FILE *f = fopen(f_history, "w"); FILE *f = fopen(f_history, "w");
if (f == NULL) { if (f == NULL) {
fprintf(stderr, "Opening file %s\n", f_history); fprintf(stderr, "Failed to open file %s for write\n", f_history);
return; return;
} }
......
...@@ -222,6 +222,6 @@ void *shellLoopQuery(void *arg) { ...@@ -222,6 +222,6 @@ void *shellLoopQuery(void *arg) {
return NULL; return NULL;
} }
void get_history_path(char *history) { sprintf(history, "%s/%s", ".", HISTORY_FILE); } void get_history_path(char *history) { sprintf(history, "C:/TDengine/%s", HISTORY_FILE); }
void exitShell() { exit(EXIT_SUCCESS); } void exitShell() { exit(EXIT_SUCCESS); }
...@@ -306,7 +306,7 @@ typedef struct DemoArguments { ...@@ -306,7 +306,7 @@ typedef struct DemoArguments {
printf("%s%s\n", indent, "-R"); printf("%s%s\n", indent, "-R");
printf("%s%s%s\n", indent, indent, "rate, Out of order data's rate--if order=1 Default 10, min: 0, max: 50."); printf("%s%s%s\n", indent, indent, "rate, Out of order data's rate--if order=1 Default 10, min: 0, max: 50.");
printf("%s%s\n", indent, "-D"); printf("%s%s\n", indent, "-D");
printf("%s%s%s\n", indent, indent, "Delete data methods——0: don't delete, 1: delete by table, 2: delete by stable, 3: delete by database."); printf("%s%s%s\n", indent, indent, "Delete data methods 0: don't delete, 1: delete by table, 2: delete by stable, 3: delete by database.");
} }
void parse_args(int argc, char *argv[], SDemoArguments *arguments) { void parse_args(int argc, char *argv[], SDemoArguments *arguments) {
......
...@@ -43,7 +43,11 @@ long interlocked_add_fetch_32(long volatile* ptr, long val) { ...@@ -43,7 +43,11 @@ long interlocked_add_fetch_32(long volatile* ptr, long val) {
} }
__int64 interlocked_add_fetch_64(__int64 volatile* ptr, __int64 val) { __int64 interlocked_add_fetch_64(__int64 volatile* ptr, __int64 val) {
#ifdef _WIN64
return _InterlockedExchangeAdd64(ptr, val) + val; return _InterlockedExchangeAdd64(ptr, val) + val;
#else
return _InterlockedExchangeAdd(ptr, val) + val;
#endif
} }
// and // and
......
...@@ -23,7 +23,7 @@ void taosRemoveDir(char *rootDir) { ...@@ -23,7 +23,7 @@ void taosRemoveDir(char *rootDir) {
int taosMkDir(const char *path, mode_t mode) { int taosMkDir(const char *path, mode_t mode) {
uError("%s not implemented yet", __FUNCTION__); uError("%s not implemented yet", __FUNCTION__);
return -1; return 0;
} }
void taosMvDir(char* destDir, char *srcDir) { void taosMvDir(char* destDir, char *srcDir) {
......
...@@ -21,9 +21,29 @@ ...@@ -21,9 +21,29 @@
#include "tulog.h" #include "tulog.h"
#include "tutil.h" #include "tutil.h"
unsigned char _MyBitScanForward64(unsigned long *ret, uint64_t x) {
unsigned long x0 = (unsigned long)x, top, bottom;
_BitScanForward(&top, (unsigned long)(x >> 32));
_BitScanForward(&bottom, x0);
*ret = x0 ? bottom : 32 + top;
return x != 0;
}
unsigned char _MyBitScanReverse64(unsigned long *ret, uint64_t x) {
unsigned long x1 = (unsigned long)(x >> 32), top, bottom;
_BitScanReverse(&top, x1);
_BitScanReverse(&bottom, (unsigned long)x);
*ret = x1 ? top + 32 : bottom;
return x != 0;
}
int32_t BUILDIN_CLZL(uint64_t val) { int32_t BUILDIN_CLZL(uint64_t val) {
unsigned long r = 0; unsigned long r = 0;
#ifdef _WIN64
_BitScanReverse64(&r, val); _BitScanReverse64(&r, val);
#else
_MyBitScanReverse64(&r, val);
#endif
return (int)(r >> 3); return (int)(r >> 3);
} }
...@@ -35,7 +55,11 @@ int32_t BUILDIN_CLZ(uint32_t val) { ...@@ -35,7 +55,11 @@ int32_t BUILDIN_CLZ(uint32_t val) {
int32_t BUILDIN_CTZL(uint64_t val) { int32_t BUILDIN_CTZL(uint64_t val) {
unsigned long r = 0; unsigned long r = 0;
#ifdef _WIN64
_BitScanForward64(&r, val); _BitScanForward64(&r, val);
#else
_MyBitScanForward64(&r, val);
#endif
return (int)(r >> 3); return (int)(r >> 3);
} }
...@@ -43,4 +67,4 @@ int32_t BUILDIN_CTZ(uint32_t val) { ...@@ -43,4 +67,4 @@ int32_t BUILDIN_CTZ(uint32_t val) {
unsigned long r = 0; unsigned long r = 0;
_BitScanForward(&r, val); _BitScanForward(&r, val);
return (int)(r >> 3); return (int)(r >> 3);
} }
\ No newline at end of file
...@@ -21,6 +21,15 @@ ...@@ -21,6 +21,15 @@
#include "ttimer.h" #include "ttimer.h"
#include "tulog.h" #include "tulog.h"
#include "tutil.h" #include "tutil.h"
#if (_WIN64)
#include <windows.h>
#include <iphlpapi.h>
#include <psapi.h>
#include <ws2tcpip.h>
#include <stdio.h>
#include <mswsock.h>
#pragma comment(lib, "Mswsock.lib ")
#endif
static void taosGetSystemTimezone() { static void taosGetSystemTimezone() {
// get and set default timezone // get and set default timezone
...@@ -69,11 +78,64 @@ void taosGetSystemInfo() { ...@@ -69,11 +78,64 @@ void taosGetSystemInfo() {
taosGetSystemLocale(); taosGetSystemLocale();
} }
bool taosGetDisk() { return true; } bool taosGetDisk() {
const double unit = 1024 * 1024 * 1024;
BOOL fResult;
unsigned _int64 i64FreeBytesToCaller;
unsigned _int64 i64TotalBytes;
unsigned _int64 i64FreeBytes;
char dir[4] = {'C', ':', '\\', '\0'};
int drive_type;
if (tscEmbedded) {
drive_type = GetDriveTypeA(dir);
if (drive_type == DRIVE_FIXED) {
fResult = GetDiskFreeSpaceExA(dir, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes,
(PULARGE_INTEGER)&i64FreeBytes);
if (fResult) {
tsTotalDataDirGB = tsTotalLogDirGB = tsTotalTmpDirGB = (float)(i64TotalBytes / unit);
tsAvailDataDirGB = tsAvailLogDirGB = tsAvailTmpDirectorySpace = (float)(i64FreeBytes / unit);
}
}
}
return true;
}
bool taosReadProcIO(int64_t *readbyte, int64_t *writebyte) {
IO_COUNTERS io_counter;
if (GetProcessIoCounters(GetCurrentProcess(), &io_counter)) {
if (readbyte) *readbyte = io_counter.ReadTransferCount;
if (writebyte) *writebyte = io_counter.WriteTransferCount;
return true;
}
return false;
}
bool taosGetProcIO(float *readKB, float *writeKB) { bool taosGetProcIO(float *readKB, float *writeKB) {
*readKB = 0; static int64_t lastReadbyte = -1;
*writeKB = 0; static int64_t lastWritebyte = -1;
int64_t curReadbyte = 0;
int64_t curWritebyte = 0;
if (!taosReadProcIO(&curReadbyte, &curWritebyte)) {
return false;
}
if (lastReadbyte == -1 || lastWritebyte == -1) {
lastReadbyte = curReadbyte;
lastWritebyte = curWritebyte;
return false;
}
*readKB = (float)((double)(curReadbyte - lastReadbyte) / 1024);
*writeKB = (float)((double)(curWritebyte - lastWritebyte) / 1024);
if (*readKB < 0) *readKB = 0;
if (*writeKB < 0) *writeKB = 0;
lastReadbyte = curReadbyte;
lastWritebyte = curWritebyte;
return true; return true;
} }
...@@ -89,12 +151,31 @@ bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) { ...@@ -89,12 +151,31 @@ bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) {
} }
bool taosGetProcMemory(float *memoryUsedMB) { bool taosGetProcMemory(float *memoryUsedMB) {
*memoryUsedMB = 0; unsigned bytes_used = 0;
#if defined(_WIN32) && defined(_MSC_VER)
PROCESS_MEMORY_COUNTERS pmc;
HANDLE cur_proc = GetCurrentProcess();
if (GetProcessMemoryInfo(cur_proc, &pmc, sizeof(pmc))) {
bytes_used = (unsigned)(pmc.WorkingSetSize + pmc.PagefileUsage);
}
#endif
*memoryUsedMB = (float)bytes_used / 1024 / 1024;
return true; return true;
} }
bool taosGetSysMemory(float *memoryUsedMB) { bool taosGetSysMemory(float *memoryUsedMB) {
*memoryUsedMB = 0; MEMORYSTATUSEX memsStat;
float nMemFree;
float nMemTotal;
memsStat.dwLength = sizeof(memsStat);
if (!GlobalMemoryStatusEx(&memsStat)) { return false; }
nMemFree = memsStat.ullAvailPhys / (1024.0f * 1024.0f);
nMemTotal = memsStat.ullTotalPhys / (1024.0f * 1024.0f);
*memoryUsedMB = nMemTotal - nMemFree;
return true; return true;
} }
......
...@@ -321,6 +321,63 @@ if $data00 != $totalNum then ...@@ -321,6 +321,63 @@ if $data00 != $totalNum then
goto show5 goto show5
endi endi
print ========== step6
sleep 3000
sql alter database db replica 1
$x = 0
show6:
$x = $x + 1
sleep 3000
if $x == 10 then
return -1
endi
sql show dnodes
print dnode1 freeVnodes $data2_1
print dnode4 freeVnodes $data2_4
if $data2_1 != 2 then
goto show6
endi
if $data2_4 != 2 then
goto show6
endi
sql reset query cache
sleep 1000
sql select count(*) from t10
print select count(*) from t10 $data00 expect $rowNum
if $data00 != $rowNum then
goto show5
endi
sql select count(*) from t1010
print select count(*) from t1010 $data00 expect $rowNum
if $data00 != $rowNum then
goto show5
endi
sql select count(*) from t2010
print select count(*) from t2010 $data00 expect $rowNum
if $data00 != $rowNum then
goto show5
endi
sql select count(*) from t3010
print select count(*) from t3010 $data00 expect $rowNum
if $data00 != $rowNum then
goto show5
endi
sql select count(*) from mt
print select count(*) from mt $data00 expect $rowNum
if $data00 != $totalNum then
goto show5
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT system sh/exec.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT system sh/exec.sh -n dnode3 -s stop -x SIGINT
......
...@@ -69,12 +69,14 @@ if $data00 != @{slop:1.000000, intercept:1.000000}@ then ...@@ -69,12 +69,14 @@ if $data00 != @{slop:1.000000, intercept:1.000000}@ then
endi endi
print =============== step5 print =============== step5
print select leastsquares(tbcol, 1, 1) as b from $tb interval(1d)
sql select leastsquares(tbcol, 1, 1) as b from $tb interval(1m) sql select leastsquares(tbcol, 1, 1) as b from $tb interval(1m)
print ===> $data01 print ===> $data01
if $data01 != @{slop:1.000000, intercept:1.000000}@ then if $data01 != @{slop:1.000000, intercept:1.000000}@ then
return -1 return -1
endi endi
print select leastsquares(tbcol, 1, 1) as b from $tb interval(1d)
sql select leastsquares(tbcol, 1, 1) as b from $tb interval(1d) sql select leastsquares(tbcol, 1, 1) as b from $tb interval(1d)
print ===> $data01 print ===> $data01
if $data01 != @{slop:1.000000, intercept:1.000000}@ then if $data01 != @{slop:1.000000, intercept:1.000000}@ then
......
...@@ -783,10 +783,15 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { ...@@ -783,10 +783,15 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
break; break;
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
tt = *(int64_t *)row[i] / 1000; tt = *(int64_t *)row[i] / 1000;
if (tt < 0) {
tt = 0;
}
tp = localtime(&tt); tp = localtime(&tt);
strftime(timeStr, 64, "%y-%m-%d %H:%M:%S", tp); strftime(timeStr, 64, "%y-%m-%d %H:%M:%S", tp);
sprintf(value, "%s.%03d", timeStr, sprintf(value, "%s.%03d", timeStr,
(int)(*((int64_t *)row[i]) % 1000)); (int)(*((int64_t *)row[i]) % 1000));
break; break;
default: default:
break; break;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册