Merge pull request #882 from taosdata/feature/fangstatic

Feature/fangstatic
This commit is contained in:
plum-lihui 2019-12-10 09:32:02 +08:00 committed by GitHub
commit 0e5886b920
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 44 additions and 35 deletions

View File

@ -75,7 +75,6 @@ static int normalStmtAddPart(SNormalStmt* stmt, bool isParam, char* str, uint32_
if (isParam) { if (isParam) {
++stmt->numParams; ++stmt->numParams;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }

View File

@ -198,7 +198,9 @@ void tscKillStream(STscObj *pObj, uint32_t killId) {
pthread_mutex_unlock(&pObj->mutex); pthread_mutex_unlock(&pObj->mutex);
if (pStream) {
tscTrace("%p stream:%p is killed, streamId:%d", pStream->pSql, pStream, killId); tscTrace("%p stream:%p is killed, streamId:%d", pStream->pSql, pStream, killId);
}
taos_close_stream(pStream); taos_close_stream(pStream);
if (pStream->callback) { if (pStream->callback) {

View File

@ -248,7 +248,6 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} }
case USE_DATABASE: { case USE_DATABASE: {
const char* msg = "db name too long";
pCmd->command = TSDB_SQL_USE_DB; pCmd->command = TSDB_SQL_USE_DB;
SSQLToken* pToken = &pInfo->pDCLInfo->a[0]; SSQLToken* pToken = &pInfo->pDCLInfo->a[0];
@ -258,6 +257,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} }
if (pToken->n > TSDB_DB_NAME_LEN) { if (pToken->n > TSDB_DB_NAME_LEN) {
const char* msg = "db name too long";
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg);
} }
@ -295,8 +295,6 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
case ALTER_DATABASE: case ALTER_DATABASE:
case CREATE_DATABASE: { case CREATE_DATABASE: {
const char* msg2 = "name too long";
const char* msg3 = "invalid db name";
if (pInfo->sqlType == ALTER_DATABASE) { if (pInfo->sqlType == ALTER_DATABASE) {
pCmd->command = TSDB_SQL_ALTER_DB; pCmd->command = TSDB_SQL_ALTER_DB;
@ -307,11 +305,13 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SCreateDBInfo* pCreateDB = &(pInfo->pDCLInfo->dbOpt); SCreateDBInfo* pCreateDB = &(pInfo->pDCLInfo->dbOpt);
if (tscValidateName(&pCreateDB->dbname) != TSDB_CODE_SUCCESS) { if (tscValidateName(&pCreateDB->dbname) != TSDB_CODE_SUCCESS) {
const char* msg3 = "invalid db name";
return invalidSqlErrMsg(pCmd, msg3); return invalidSqlErrMsg(pCmd, msg3);
} }
int32_t ret = setObjFullName(pMeterMetaInfo->name, getAccountId(pSql), &(pCreateDB->dbname), NULL, NULL); int32_t ret = setObjFullName(pMeterMetaInfo->name, getAccountId(pSql), &(pCreateDB->dbname), NULL, NULL);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
const char* msg2 = "name too long";
return invalidSqlErrMsg(pCmd, msg2); return invalidSqlErrMsg(pCmd, msg2);
} }
@ -347,13 +347,8 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
pCmd->command = (pInfo->sqlType == CREATE_USER) ? TSDB_SQL_CREATE_USER : TSDB_SQL_CREATE_ACCT; pCmd->command = (pInfo->sqlType == CREATE_USER) ? TSDB_SQL_CREATE_USER : TSDB_SQL_CREATE_ACCT;
assert(pInfo->pDCLInfo->nTokens >= 2); assert(pInfo->pDCLInfo->nTokens >= 2);
const char* msg = "name or password too long";
const char* msg1 = "password can not be empty";
const char* msg2 = "invalid user/account name";
const char* msg3 = "password needs single quote marks enclosed";
const char* msg4 = "invalid state option, available options[no, r, w, all]";
if (pInfo->pDCLInfo->a[1].type != TK_STRING) { if (pInfo->pDCLInfo->a[1].type != TK_STRING) {
const char* msg3 = "password needs single quote marks enclosed";
return invalidSqlErrMsg(pCmd, msg3); return invalidSqlErrMsg(pCmd, msg3);
} }
@ -362,14 +357,17 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
pInfo->pDCLInfo->a[1].n = strlen(pInfo->pDCLInfo->a[1].z); pInfo->pDCLInfo->a[1].n = strlen(pInfo->pDCLInfo->a[1].z);
if (pInfo->pDCLInfo->a[1].n <= 0) { if (pInfo->pDCLInfo->a[1].n <= 0) {
const char* msg1 = "password can not be empty";
return invalidSqlErrMsg(pCmd, msg1); return invalidSqlErrMsg(pCmd, msg1);
} }
if (pInfo->pDCLInfo->a[0].n > TSDB_USER_LEN || pInfo->pDCLInfo->a[1].n > TSDB_PASSWORD_LEN) { if (pInfo->pDCLInfo->a[0].n > TSDB_USER_LEN || pInfo->pDCLInfo->a[1].n > TSDB_PASSWORD_LEN) {
const char* msg = "name or password too long";
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg);
} }
if (tscValidateName(&pInfo->pDCLInfo->a[0]) != TSDB_CODE_SUCCESS) { if (tscValidateName(&pInfo->pDCLInfo->a[0]) != TSDB_CODE_SUCCESS) {
const char* msg2 = "invalid user/account name";
return invalidSqlErrMsg(pCmd, msg2); return invalidSqlErrMsg(pCmd, msg2);
} }
@ -403,6 +401,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} else if (strncmp(pAcctOpt->stat.z, "no", 2) == 0 && pAcctOpt->stat.n == 2) { } else if (strncmp(pAcctOpt->stat.z, "no", 2) == 0 && pAcctOpt->stat.n == 2) {
pCmd->defaultVal[8] = 0; pCmd->defaultVal[8] = 0;
} else { } else {
const char* msg4 = "invalid state option, available options[no, r, w, all]";
return invalidSqlErrMsg(pCmd, msg4); return invalidSqlErrMsg(pCmd, msg4);
} }
} }
@ -415,13 +414,10 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
assert(num >= 1 && num <= 2); assert(num >= 1 && num <= 2);
const char* msg = "password too long"; const char* msg = "password too long";
const char* msg1 = "password can not be empty";
const char* msg2 = "invalid user/account name";
const char* msg3 = "password needs single quote marks enclosed";
const char* msg4 = "invalid state option, available options[no, r, w, all]";
if (num == 2) { if (num == 2) {
if (pInfo->pDCLInfo->a[1].type != TK_STRING) { if (pInfo->pDCLInfo->a[1].type != TK_STRING) {
const char* msg3 = "password needs single quote marks enclosed";
return invalidSqlErrMsg(pCmd, msg3); return invalidSqlErrMsg(pCmd, msg3);
} }
@ -430,6 +426,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
pInfo->pDCLInfo->a[1].n = strlen(pInfo->pDCLInfo->a[1].z); pInfo->pDCLInfo->a[1].n = strlen(pInfo->pDCLInfo->a[1].z);
if (pInfo->pDCLInfo->a[1].n <= 0) { if (pInfo->pDCLInfo->a[1].n <= 0) {
const char* msg1 = "password can not be empty";
return invalidSqlErrMsg(pCmd, msg1); return invalidSqlErrMsg(pCmd, msg1);
} }
@ -445,6 +442,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} }
if (tscValidateName(&pInfo->pDCLInfo->a[0]) != TSDB_CODE_SUCCESS) { if (tscValidateName(&pInfo->pDCLInfo->a[0]) != TSDB_CODE_SUCCESS) {
const char* msg2 = "invalid user/account name";
return invalidSqlErrMsg(pCmd, msg2); return invalidSqlErrMsg(pCmd, msg2);
} }
@ -475,6 +473,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} else if (strncmp(pAcctOpt->stat.z, "no", 2) == 0 && pAcctOpt->stat.n == 2) { } else if (strncmp(pAcctOpt->stat.z, "no", 2) == 0 && pAcctOpt->stat.n == 2) {
pCmd->defaultVal[8] = 0; pCmd->defaultVal[8] = 0;
} else { } else {
const char* msg4 = "invalid state option, available options[no, r, w, all]";
return invalidSqlErrMsg(pCmd, msg4); return invalidSqlErrMsg(pCmd, msg4);
} }
} }
@ -1868,8 +1867,6 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
SMeterMetaInfo* pMeterMetaInfo = NULL; SMeterMetaInfo* pMeterMetaInfo = NULL;
int32_t optr = pItem->pNode->nSQLOptr; int32_t optr = pItem->pNode->nSQLOptr;
int32_t numOfAddedColumn = 1;
const char* msg1 = "not support column types"; const char* msg1 = "not support column types";
const char* msg2 = "invalid parameters"; const char* msg2 = "invalid parameters";
const char* msg3 = "illegal column name"; const char* msg3 = "illegal column name";
@ -2166,6 +2163,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
int16_t resultSize = pSchema[index.columnIndex].bytes; int16_t resultSize = pSchema[index.columnIndex].bytes;
char val[8] = {0}; char val[8] = {0};
int32_t numOfAddedColumn = 1;
if (optr == TK_PERCENTILE || optr == TK_APERCENTILE) { if (optr == TK_PERCENTILE || optr == TK_APERCENTILE) {
tVariantDump(pVariant, val, TSDB_DATA_TYPE_DOUBLE); tVariantDump(pVariant, val, TSDB_DATA_TYPE_DOUBLE);
@ -2190,6 +2188,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
SSqlExpr* pExpr = tscSqlExprInsert(pCmd, colIdx, functionId, &index, resultType, resultSize, resultSize); SSqlExpr* pExpr = tscSqlExprInsert(pCmd, colIdx, functionId, &index, resultType, resultSize, resultSize);
addExprParams(pExpr, val, TSDB_DATA_TYPE_DOUBLE, sizeof(double), 0); addExprParams(pExpr, val, TSDB_DATA_TYPE_DOUBLE, sizeof(double), 0);
} else { } else {
tVariantDump(pVariant, val, TSDB_DATA_TYPE_BIGINT); tVariantDump(pVariant, val, TSDB_DATA_TYPE_BIGINT);
int64_t nTop = *((int32_t*)val); int64_t nTop = *((int32_t*)val);

View File

@ -1314,8 +1314,10 @@ int32_t tscLocalDoReduce(SSqlObj *pSql) {
tscTrace("%s call the drop local reducer", __FUNCTION__); tscTrace("%s call the drop local reducer", __FUNCTION__);
tscDestroyLocalReducer(pSql); tscDestroyLocalReducer(pSql);
if (pRes) {
pRes->numOfRows = 0; pRes->numOfRows = 0;
pRes->row = 0; pRes->row = 0;
}
return 0; return 0;
} }

View File

@ -2312,6 +2312,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql) {
size = tscEstimateCreateTableMsgLength(pSql); size = tscEstimateCreateTableMsgLength(pSql);
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) { if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) {
tscError("%p failed to malloc for create table msg", pSql); tscError("%p failed to malloc for create table msg", pSql);
free(tmpData);
return -1; return -1;
} }

View File

@ -230,7 +230,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) {
return -1; return -1;
} }
if (cfg && cfg && cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { if (cfg && cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) {
char sep = '.'; char sep = '.';
if (strlen(tsLocale) == 0) { // locale does not set yet if (strlen(tsLocale) == 0) { // locale does not set yet

View File

@ -780,6 +780,7 @@ void source_file(TAOS *con, char *fptr) {
if (wordexp(fptr, &full_path, 0) != 0) { if (wordexp(fptr, &full_path, 0) != 0) {
fprintf(stderr, "ERROR: illegal file name\n"); fprintf(stderr, "ERROR: illegal file name\n");
free(cmd);
return; return;
} }
@ -788,6 +789,7 @@ void source_file(TAOS *con, char *fptr) {
if (access(fname, R_OK) == -1) { if (access(fname, R_OK) == -1) {
fprintf(stderr, "ERROR: file %s is not readable\n", fptr); fprintf(stderr, "ERROR: file %s is not readable\n", fptr);
wordfree(&full_path); wordfree(&full_path);
free(cmd);
return; return;
} }
@ -795,6 +797,7 @@ void source_file(TAOS *con, char *fptr) {
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);
wordfree(&full_path); wordfree(&full_path);
free(cmd);
return; return;
} }

View File

@ -277,7 +277,10 @@ void *shellLoopQuery(void *arg) {
pthread_cleanup_push(cleanup_handler, NULL); pthread_cleanup_push(cleanup_handler, NULL);
char *command = malloc(MAX_COMMAND_SIZE); char *command = malloc(MAX_COMMAND_SIZE);
if (command == NULL){
tscError("failed to malloc command");
return NULL;
}
while (1) { while (1) {
// Read command from shell. // Read command from shell.
@ -286,11 +289,9 @@ void *shellLoopQuery(void *arg) {
shellReadCommand(con, command); shellReadCommand(con, command);
reset_terminal_mode(); reset_terminal_mode();
if (command != NULL) {
// Run the command // Run the command
shellRunCommand(con, command); shellRunCommand(con, command);
} }
}
pthread_cleanup_pop(1); pthread_cleanup_pop(1);

View File

@ -119,7 +119,7 @@ bool gcBuildQueryJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result,
cmd->numOfRows += numOfRows; cmd->numOfRows += numOfRows;
} }
for (int i = 0; i < numOfRows; ++i) { for (int k = 0; k < numOfRows; ++k) {
TAOS_ROW row = taos_fetch_row(result); TAOS_ROW row = taos_fetch_row(result);
// for group by // for group by

View File

@ -94,7 +94,7 @@ bool restBuildSqlJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result,
int num_fields = taos_num_fields(result); int num_fields = taos_num_fields(result);
TAOS_FIELD *fields = taos_fetch_fields(result); TAOS_FIELD *fields = taos_fetch_fields(result);
for (int i = 0; i < numOfRows; ++i) { for (int k = 0; k < numOfRows; ++k) {
TAOS_ROW row = taos_fetch_row(result); TAOS_ROW row = taos_fetch_row(result);
// data row array begin // data row array begin

View File

@ -262,6 +262,8 @@ int tgReadSchema(const char *fileName) {
size_t result = fread(content, 1, contentSize, fp); size_t result = fread(content, 1, contentSize, fp);
if (result != contentSize) { if (result != contentSize) {
httpError("failed to read telegraf schema file:%s", fileName); httpError("failed to read telegraf schema file:%s", fileName);
fclose(fp);
free(content);
return -1; return -1;
} }

View File

@ -124,7 +124,7 @@ bool taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
} }
char cpu[10] = {0}; char cpu[10] = {0};
sscanf(line, "%s %ld %ld %ld %ld", cpu, &cpuInfo->user, &cpuInfo->nice, &cpuInfo->system, &cpuInfo->idle); sscanf(line, "%s %lu %lu %lu %lu", cpu, &cpuInfo->user, &cpuInfo->nice, &cpuInfo->system, &cpuInfo->idle);
tfree(line); tfree(line);
fclose(fp); fclose(fp);
@ -150,7 +150,7 @@ bool taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
for (int i = 0, blank = 0; line[i] != 0; ++i) { for (int i = 0, blank = 0; line[i] != 0; ++i) {
if (line[i] == ' ') blank++; if (line[i] == ' ') blank++;
if (blank == PROCESS_ITEM) { if (blank == PROCESS_ITEM) {
sscanf(line + i + 1, "%ld %ld %ld %ld", &cpuInfo->utime, &cpuInfo->stime, &cpuInfo->cutime, &cpuInfo->cstime); sscanf(line + i + 1, "%lu %lu %lu %lu", &cpuInfo->utime, &cpuInfo->stime, &cpuInfo->cutime, &cpuInfo->cstime);
break; break;
} }
} }

View File

@ -289,6 +289,7 @@ int mgmtRetrieveVgroups(SShowObj *pShow, char *data, int rows, SConnObj *pConn)
SDbObj *pDb = NULL; SDbObj *pDb = NULL;
if (pConn->pDb != NULL) pDb = mgmtGetDb(pConn->pDb->name); if (pConn->pDb != NULL) pDb = mgmtGetDb(pConn->pDb->name);
assert(pDb != NULL);
pVgroup = pDb->pHead; pVgroup = pDb->pHead;
while (pVgroup != NULL) { while (pVgroup != NULL) {

View File

@ -4555,8 +4555,7 @@ static void doMerge(SQueryRuntimeEnv *pRuntimeEnv, int64_t timestamp, tFilePage
} }
static void printBinaryData(int32_t functionId, char *data, int32_t srcDataType) { static void printBinaryData(int32_t functionId, char *data, int32_t srcDataType) {
if (functionId == TSDB_FUNC_FIRST_DST || functionId == TSDB_FUNC_LAST_DST || functionId == TSDB_FUNC_FIRST_DST || if (functionId == TSDB_FUNC_FIRST_DST || functionId == TSDB_FUNC_LAST_DST) {
functionId == TSDB_FUNC_LAST_DST) {
switch (srcDataType) { switch (srcDataType) {
case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_BINARY:
printf("%ld,%s\t", *(TSKEY *)data, (data + TSDB_KEYSIZE + 1)); printf("%ld,%s\t", *(TSKEY *)data, (data + TSDB_KEYSIZE + 1));